Archive

Posts Tagged ‘programming’

Learn How to Write a Driver for Linux 3.x With The Linux Driver Template

November 14th, 2012 No comments

A Linux Driver Template (LDT) has been published to help new Linux kernel developers writing hardware device drivers.

Constantine Shulyupin posted the Linux Driver Template (LDT) on the Linux mailing list in order to merge it into the mainline Linux kernel. The code can be used as as a starting point for new drivers, and shows how to use several Linux facilities such as  module, platform driver, file operations (read/write, mmap, ioctl, blocking and nonblocking mode, polling), kfifo, completion, interrupt, tasklet, work, kthread, timer, simple misc device,
multiple char devices, Device Model, configfs, UART, hardware loopback, software loopback and  ftracer.

This sample has been added to other device drivers samples in eLinux.org. And if you want to learn further there’s always the Linux driver bible: “Linux Device Drivers, Third Edition” which can be downloaded for free as PDF, although it’s for 2.6.10 kernel and many parts may not be up-to date.

Via: Phoronix

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter

Debian is Worth a Lot (Yet it’s Free) and C/C++ Language Still Rules

February 16th, 2012 No comments

James E. Bromberger (JEB) , a contributor to Perl CPAN and Debian, has estimated the cost of developing Debian Wheezy (7.0) from scratch based on the the number of lines of code (LOC) counted with SLOCCount tool, the Constructive Cost Model (COCOMO) and the average wage of a developer of 72,533 USD (using median estimates from Salary.com and PayScale.com for 2011).

He found 419,776,604 lines of code in 31 programming languages giving an estimated cost of producing Debian Wheezy in February 2012 of 19 billion US dollar (14.4 Billion Euros), making each package source code (out of the 17,141 packages) worth an average of 1,112,547.56 USD to produce.

He also estimated the cost of Linux 3.1.8 Kernel with almost 10 millions lines of source code would be worth 540 million USD at standard complexity, or 1.877 billions USD when rated as ‘complex’.

I don’t know which tool he used for the calculation (maybe his own), but there are two simple COCOMO calculators on the internet in order to estimate the number of man hours required for a particular project based on the LOC and the code complexity:

Bromberger also estimated the cost of several individual projects used in Debian and found that developing Apache 2.2.9 would cost 33.5 million USD and MySQL 64.2 million USD with today’s salary.

Of course, there are some caveats to such cost estimation. First, those costs assume software engineers based in the US. Taking into account outsourcing would significantly reduce those cost estimations. Second, he also tried another source code analysis tool (Ohcount) which found much less lines of code in Debian Wheezy. Finally, you also need to estimate the code complexity in the COCOMO model which may lead to great variation in the final costs.

In the last section of his post, Bromberger also analyzed the 31 programming languages that were used to develop the Debian software (See his chart below). It shows C and C++ still rule the (programming) world with respectively 40% and 20% of code written in those 2 programming languages. Java comes a distant third at 8%.

C/C++ Rules the World !!!

Top 11 Programming Languages of Debian Wheezy

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter

Android Training & Tutorials

December 16th, 2011 No comments

The Android team just announced the launch of Android Training a collection of classes aimed at helping developers to build better Android applications.

Each class explains the steps required to solve a problem, or implement a feature, with code snippets and sample code.

They’ll add more materials over time, but right now developers can already learn (more) about the following Android Graduatetopics:

  • Designing for Multiple Screens
  • Improving Layout Performance
  • Managing Audio Playback
  • Optimizing Battery Life
  • Remembering Users
  • Sharing Content
  • Capturing Photos
  • Maintaining Multiple APKs
  • Developing for Enterprise
  • Monetizing Your App
  • Designing Effective Navigation

There are currently 34 lessons on all those topics, and most include code samples such as the News Reader  (Designing for Multiple Screens).

You can get started immediately by visiting Android Training page.

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter

Qt Quick QML Digital Signage Demo Part 2

December 12th, 2011 4 comments

Following up on Qt Quick QML Digital Signage Demo Part 1, I’ve updated the digital signage demo to support the following:

  • Play 5 videos in a loop
  • Display 5 pictures in a loop where the picture is changed every 5 seconds
  • Use a (twitter) RSS feed for the scrolling text
Digital Signage Programmed with QtQuick/QML

QML Digital Signage Demo Screenshot

I initially planned to use QML to list the media files, but it is apparently not possible without using C/C++ and I may do it later on. So instead, I hard-coded the video and picture playlists in the QML files with the ListModel element. Videos are located in the video directory and pictures in the pic folder.

An index is needed to scroll thru the playlist, but QML does not support global variables, so I created a JavaScript file (globals.js) to store the video and picture index:

// Global variables in JavaScript file
var iVideoIndex = 0
var iPicIndex = 0

Then imported the script at the top of main.qml:

import "globals.js" as GlobalScript

Now the code to play 5 videos in a loop looks like:

Rectangle {
            id: video;
            width: 600;
            height: 432

            ListModel {
                    id: videoFiles
                     ListElement {
                             file: "video/video1.wmv"
                     }
                     ...
            }

            Video {
                id: videofile
                playing: true
                source: videoFiles.get(GlobalScript.iVideoIndex).file
                width: 600
                height: 432
                opacity: 0.9
                focus: true
                onStopped: { // To loop the video
                    source = videoFiles.get(GlobalScript.iVideoIndex).file
                    console.debug("Video: " + videoFiles.get(GlobalScript.iVideoIndex).file)
                    videofile.play()
                    GlobalScript.iVideoIndex =  (GlobalScript.iVideoIndex + 1) % 5;
                }

            }

I only used Windows Media (wmv), WebM and Mpeg video, as it seems the AVI and MP4 video I used made the emulator crash.

The picture zone uses a 5 files list (pic/pic1.jpg to pic/pic5.jpg) with a 5 second timer:

Rectangle {
            id: picture; width: 200; height: 432
            anchors.left: video.right
            ListModel {
                    id: picFiles
                     ListElement {
                             file: "pic/pic1.jpg"
                     }
                     ...
            }

            Image {
                source: picFiles.get(GlobalScript.iPicIndex).file
                Timer {
                    interval: 5000; // 5 Seconds
                    running: true;
                    repeat: true
                    onTriggered: {
                        parent.visible = false
                        parent.source = picFiles.get(GlobalScript.iPicIndex).file
                        parent.visible = true
                        console.debug("Picture: " + picFiles.get(GlobalScript.iPicIndex).file)
                        GlobalScript.iPicIndex =  (GlobalScript.iPicIndex + 1) % 5;
                    }
                }
            }

In the code above, I had to switch parent.visible between false and true or the picture would not be updated.

In the scrolling text zone, I used cnxsoft twitter feed, retrieved it, parsed it and displayed it with QML XmlListModel and ListView:

Rectangle {
            id: text
            width: 800; height: 48
            color: "blue"
            XmlListModel {
                 id: feedModel
                 source: "http://twitter.com/statuses/user_timeline/114751985.rss"
                 query: "/rss/channel/item"
                 XmlRole { name: "title"; query: "title/string()" }
            }
            ListView {
                 id: rss
                 width: 800; height: 48
                 model: feedModel
                 delegate: ScrollingText {
                     id:scrolltext
                     width: 800
                     height: 48
                     text: title // "Qt Quick Digital Signage Demo"
                 }
            }

Here’s what the Qt QML Digital Signage demo looks like when running in Qt Simulator (Nokia N900):

You can also download the source code (main.qml, ScrollingText.qml and global.js). You’ll need to create the video and pic directories in your project and add 5 videos and 5 pictures to test it.
The full QtQuick project is also available on Gitorious.

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter

Qt Quick QML Digital Signage Demo Part 1

December 10th, 2011 No comments

I’ve recently started to play around with Qt and since I’d like to do a digital signage player running on Raspberry Pi, I’ve decided to try to make a simple digital signage demo application to evaluate the development platform.

Raspberry Pi Digital Signage

Screenshot of Digital Signage Demo Written with Qt Creator/QML

In Part 1, my goal was to make a 3 zones layout with a video zone, a picture zone and a scrolling text zone. I would just play one hard-coded media in each zone and the video and scrolling text would have to continuously loop.

I used Qt Creator to create  a “Pigital Signage” application (or should it be Πgital Signage ?).

To create the 3 zones I used the Gridview Element with 3 rectangles:

  • Video zone: 600×432
  • Picture zone: 200×432
  • Text zone: 800×48

Displaying the image is very easy with the Image Element:

Image {
    source: "pic/phone.jpg"
}

The video playback was also supposed to be easy with the Video Element but it can not work on Desktop, so I had to revert to used the Nokia N900 emulator to be able to play a short video (hence the 800×480 resolution of the demo).  It works fine but there is a transparency issue with the emulator (in my PC), so if I want to clearly see the video I have to open a black picture and move the emulator on top. Here’s the video playback code:

Video {
       id: videofile
       playing: true
       source: "video/Bear.wmv"
       width: 600
       height: 432
       opacity: 0.9
       focus: true
       onStopped: { /* To loop the video */
              videofile.play()
       }
}

The scrolling text should also have been easy since we can use  Webview  Element and html marquee, but I could not solve a problem with left and top margins that always left white border to the text zone.  Finally, I wrote the scrolling text code based on sample code provided by Kunal. I added a new file called ScrollingText.qml to the project:

import QtQuick 1.0

Item {
    id:marqueeText
    height: scrollingText.height
    clip: true
    property int tempX: marqueeText.width
    property alias text: scrollingText.text
    Text {
        x: tempX
        id:scrollingText
        color: "Yellow" /* Hard code text color for now */
        font.pixelSize: marqueeText.height - 6;
    }
    Timer {
        id:timer
        interval: 200; running: true; repeat: true
        onTriggered:{
            tempX = tempX - 5
            scrollingText.x = tempX;
            console.debug("Tempx = " + tempX + "Text Width = " + scrollingText.width, " Height = " + marqueeText.height)

            if( tempX < -scrollingText.width) {
                tempX = marqueeText.width;
                console.debug("Restart Scrolling Text")
            }
        }
    }
}

The code is modified to start scrolling the text from the right until it fully disappears on the left and continuously repeat it.

Here’s the full main.qml with the code for the 3 zones:

import QtQuick 1.0
import QtMultimediaKit 1.1
import QtWebKit 1.0

Rectangle {
    id: screen
    width: 800
    height: 480
    Grid {
        columns: 2
        spacing: 0

        Rectangle {
            id: video;
            color: "black";
            width: 600;
            height: 432
            Video {
                id: videofile
                playing: true
                source: "video/Bear.wmv"
                width: 600
                height: 432
                opacity: 0.9
                focus: true
                onStopped: { /* To loop the video */
                    videofile.play()
                }
            }
        }
        Rectangle {
            id: picture; width: 200; height: 432
            anchors.left: video.right
            Image {
                source: "pic/phone.jpg"
            }
        }
        Rectangle {
            id: text
            width: 800; height: 48
            color: "blue"
            ScrollingText {
                id:scrolltext
                width: 800
                height: 48
                text: "Qt Quick Digital Signage Demo"
            }
/* Method 2: Webview (issue with white border)
            WebView {
                    width: 800; height: 48
                    preferredWidth: 800; preferredHeight: 46
                    anchors.top: video.bottom
                    // Marquee code generated with http://www.quackit.com/html/html_generators/html_marquee_generator.cfm
                    html: "<style type=\"text/css\">
                    .html-marquee {height:48px;width:800px;background-color:3333FF;font-family:Verdana;font-size:24pt;color:FFFF33;font-weight:bold;}
                    </style>
                    <marquee class=\"html-marquee\" direction=\"left\" behavior=\"scroll\" scrollamount=\"6\" >Qt Quick Digital Signage Demo</marquee>"
             } */
        }
    }
}

In order for QtMultimediaKit to work properly, you also need to modify PigitalSignage.Pro since it is part of QtMobility:

CONFIG += mobility
MOBILITY += multimedia

Developing with Qt Creator and QML language seems relatively straightforward as this short demo could be written in one afternoon.

I’m not sure Qt 5 Video Element will be supported for the Raspberry Pi so QML Binding Element may have to be used to call an external video player that support R-Pi GPU.

In Part 2, I plan to list video and pictures file in a directory and play them continuously. For the scrolling text, the plan is to use a (twitter) RSS feed, scroll it and reload it each time the scroll is finished. I may also try to play online video (e.g. YouTube) and parse a config file to configure things like picture display duration, text color and scrolling speed etc…

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter

Nokia Developer Day 2: Qt QML Workshop – Chiang Mai

December 8th, 2011 No comments

I’ve just attended Nokia Developer Day  on 6-7 December 2011 in Chiang Mai.

I’ve already written a summary about the first day dealing with Series 40 Java and Web Apps Workshop.

The second day was focused on Qt/QML (Qt Meta-Language) software development for Nokia’s Symbian phones. Nokia will phase out Symbian operating system in 2016, but they’ll still support it until that time. Nokia will also port  Qt to lower end phones (e.g. Series 40) on a new operating system based on Linux called Meltemi.

Overall Business Direction & Strategy

The first 45-minutes for was presentation given by Grant Aaron McBeath, Managing Director, Nokia Thailand and Emerging Asia, about Nokia business direction: focus on Windows Phone for smartphones, Java/Web Apps for feature phones and future disruption. He also showed the progress of Nokia Ovi Store with 10 million downloads a day and 177 publishers with more than 1 million downloads. The new Nokia Lumia 710 and 800 (WP7) and Nokia Asha 300 & 303 were also showcased.

Some other interesting fact during the presentation:

  • Once operator billing is enabled, you can get 20 times more purchase than with payment requiring a credit card.
  • The best business model for app developers (at least in Thailand) is to provide freemium: try before you buy.

Finally, he talked about expected NFC growth in the next few years and different ways an application can be monetized:

  • directly: paid download, subscriptions, in-app purchases…
  • Indirectly: advertizing, sponsors…

Introduction to Qt Quick (QML) in Qt 4.7

The rest of the day 10:00 till 16:00 was devoted to Qt QML for Symbian workshop animated by Manikantan Krishnamurthy, Technical Manager, Nokia, Southeast Asia & Pacific.

The first thing to do is to download Nokia Qt SDK Windows offline (Qt_SDK_Win_offline_v1_1_3_en.exe)   and follow the installation procedure given at http://www.forum.nokia.com/Develop/Qt/Getting_started/

You can also download the Qt QML Workshop Presentation Slides.

There was first a quick introduction about Qt, Symbian and the Ovi Store. An overview of Qt Creator, Qt SDK and QML was then provided. Mani also quickly explained it was possible to use Remote Device Access to test your application on real phones remotely.

Then the worskhop started and only involved QML programming (similar to javascript in some respects). We basically followed what’s inside the slides above and learnt the following:

  • Create a new Qt project for Symbian and run the hello world application in the Emulator.
  • Create an application to display an image that can be moved to a new location by pressing the mouse button.
  • States, Transition and Timer: Updating the application above by adding code that fades-in / fades-out the image.
  • How to create an animation, list view, grid view etc… with QML
  • Introduction to Qt Quick Components for Symbian.
  • Create an application that converts degree Celsius to Kelvin with a text field, button (with image) and text showing the result. (cnxsoft: This was one of the most interesting part, as the source code was not available and we add to code ourselves and look for relevant API in Qt help, not just type the code in the PDF…).
  • Create a MAP application using QtMobility.location 1.2 API where we were able to display the map, create a map circle, pan the map and zoom in/out with a slider.
  • Create a multimedia application (Jukebox) that play/pauses and stop a MP3 file.

To conclude the workshop, mani explained how we could submit Qt applications to the Ovi Store.

This was followed by the Q&A session without any questions asked…

The day was concluded with a lucky draw for a Nokia C601 (and I was kindly explained it would not be my turn this time…), distribution of a certificate participation and a group picture.

All in all the workshop was quite interesting, but this was quite a rush (especially I was unable to copy /past the code in the PDF slides and had to type everything). But that’s fine as it gives good starting point to start developing your app. I may start playing around more with Qt once I receive my Nokia C601 and/or the Raspberry Pi becomes available.

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter

Nokia Developer Day 1 Summary – Chiang Mai

December 6th, 2011 1 comment

I’ve just attended the first day of Nokia Developer Day (6-7 December 2011).

The focus was on software development for Nokia’s feature phones with Java or Web Apps (HTML/CSS/Javascript) and most of the time was spent on workshops to get started for developing for Nokia feature phones such as the S40 series.

Introduction to Ecosystem Business Updates

During the first 15 minutes, an “Introduction to Ecosystem Business Updates” was given by Jirapat Janjerdask, Head of the Ecosystem Developer Experience at Nokia Thailand. He gave an overview of the ecosystem for features phones including the brand, developer & publisher, mobile brand, mobile operator and consumer.

One interesting statistics was that there are 10 millions app downloads every single day. He also talked about the new Nokia Asha 300 and 303 features phones available for 3000 to 4000 Thai Baht (100 to 130 USD)  that are capable of running applications that usually run in smartphones such as Angry Bird and a Web Browser.

Development Possibilities on Nokia Platforms

After that another short 20 minutes talk was given about the “Development Possibilities on Nokia Platforms” by Nicholas Foo, Lead of Technical Services & Consultancy SEAP. He talked about the different development platforms used by Nokia:

  • Series 40 Java
  • Symbian
  • Meego
  • Qt
  • Windows Phone

Meego and Symbian operating systems will be phased out and the focus on mid to high end phones will be on Windows Phone and low end phones will use Series 40 Java, Web Apps and Qt.

Prerequisites, tools installation

The next part was the workshop showing how to use the new features of S40 Series Java and develop Web Apps.  First, you had to configure your development machine and install the relevant tools:

  1. Java tools for S40 Series Java development. Refer to Java Tools Installation Instructions.pdf for links and instructions to install Java JDK, Nokia SDK 1.0 for Java and Netbeans.
  2. Nokia Web Tools 1.5 for Web Apps development at http://www.developer.nokia.com/info/sw.nokia.com/id/e22963ec-3d9e-43f2-a220-3ef4c4092cc7/Nokia_Web_Tools.html

Most of the resources and documentation for Nokia software development can be found at http://library.developer.nokia.com.

Introduction of Series 40 Java – Touch & Type

The presentation slides and source code samples for the 2 day workshop are currently available at http://www.developer.nokia.com/Events/invitation/nddcmkk/download.

Basically, you’d use Java for games and where you need to access the phone hardware (e.g. camera) and Web Apps for applications that focuses on content as would be the case for a news application.

In that part, we’ve learnt how to use the gesture and frame animation APIs.

 The two documents for this part:

The instructions are very clear, simply follow “S40 Java slides” and it will take you to other PDF files explaining how to use the demo apps for Gesture and FrameAnim.

After the workshop, further details were given on how to sign your application to avoid too many user security confirmations among other things.

That session took an awful amount of time (about 4h30)…

Series 40 Web Apps for the next billion

In that part, we’ve learnt how Nokia Cloud-based Browser works and how to create a Google Moderator app using HTML/CSS/ javascript code and the Mobile Web Library (MWL).

The two documents for this part:

Here again, follow “S40 Web Apps slides” as the instructions are pretty clear.
Finally, we were explained how to publish Web Apps to Nokia store.

Social Media Marketing Training

The last session was a presentation focusing on marketing your product / services on social media such as Facebook, Twitter and Linkedin. It was in Thai and I pretty much lost all of my focus at that time, so I did not get much of the details…

At the end of the day, there was a lucky draw for a Nokia C601 and amazingly it seems I’m the one who got lucky…

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter

11 Recommendations for Optimizing Mobile Apps Power Efficiency

November 11th, 2011 No comments

Following an AT&T Labs Research and corresponding paper entitled “Profiling Resource Usage for Mobile Applications: A Cross-layer Approach“,  AT&T found that a few simple design approaches could significantly improve mobile application responsiveness and reduce battery drain by lowering your application power consumption.

They analyzed PANDORA internet radio and  discovered that the streaming music was delivered efficiently, but periodic audience measurements were draining battery life. Here is an excerpt of the PANDORA Case Study:

While the music itself was sent simply and efficiently as a single file, the periodic audience measurements—each constituting only 2KBs or so—were being transmitted at regular 62.5-second intervals. The constant cycle of ramping up to full power (2 seconds to ramp up, 1 second to download 2KB) and back to idle (17 seconds for the two tail times, the first down from full-power mode and the second down from half-power mode) was extremely wasteful. Of the total amount of device battery energy consumed, 46% was expended on these periodic measurements, less than .2% of the data transmitted.

Once the initial problem was diagnosed—a scatter-burst transmission of small packets—the solution was obvious: bundle the packets into a single transmission. Doing so would result in an easy 40% energy savings.

The result of their research is a series of 11 best practices recommendations in order to reduce power consumption and improve application responsiveness namely:

  • Understand Mobile Networks: Higher latency than Wi-fi and Broadband. Limit the number of connections to save battery life and decrease your app latency.
  • Handle Multiple Simultaneous TCP Connections:  Group multiple simultaneous connections from the same server. Efficiently managing multiple persistent connections saves energy, plus it can sometimes improve response time and reduce bandwidth.
  • Reduce Inefficient Connections with Periodic Transfers: The shortest TCP timeout amongst the four major US carriers is four minutes and AT&T’s timeout is actually 30 minutes. Keep that in mind to reduce the number of periodic messages (e.g. keep-alive) as much as possible and save battery life.
  • Deal with Connection Opening Problems:  Try to download all the content your app will need as quickly as possible. By grouping all data together, your user’s content will download faster, making your application appear faster as well as reducing the amount of energy consumed by the device radio.
  • Close Connections As Soon As Possible: Closing all connections as soon as possible once data is transmitted. However, there are situations where a persistent connection needs to be kept open so it can be reused. The issue is pinpointing connections that don’t truly need to be kept open—and closing them.
  • Offload to Wi-Fi: Wi-Fi connections are much more efficient than 2G or 3G connections from a battery and network perspective, make use of this as much as possible.
  • Handle Duplicate Content and Caching: Make sure the server properly set the caching information and that it returns HTTP 304 instead of transferring the whole object. On the client side, use a cache, make sure you’re properly handling HTTP caching and that you don’t download objects that are already cached.
  • Utilize Pre-fetching: Pre-fetching means grabbing chunks of data in anticipation of what your user will want to see in order to reduces the number of connections. This can however be overdone (downloading too much data), so you’d have to find the right balance.
  • Manage Peripherals: Turn off unused hardware such as Bluetooth, GPS and other features to save battery life in your apps. cnxsoft: I’m not sure how they’d do in a multitask environment like Android.Your application may not use a particular hardware features but what about other apps?
  • Upgrade from HTTP 1.0: Make sure your application uses HTTP 1.1 as it can support persistent TCP connections and HTTP pipelining.
  • Handle Screen Rotations: Do not contact the server each time the screen rotates, but instead track the orientation change in the app and send the information at scheduled intervals with other data.

For further information, you can read the full AT&T Labs Research article.

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter