Monday, December 22, 2008

..*~'"*..*"`'*..."~`*..Merry Christmas..*~'"*..*"`'*..."~`*..

My favorite Christmas songs/videos: (although I do not celebrate Christmas because I am a Buddhist, but let's have fun!!)



Thursday, December 18, 2008

Automate graph drawing with Grapviz



The picture shows an example of using Graphviz to draw a graph for Traffic Information module. The arrows depict the objects's communication using Observer Pattern.


digraph TIComponent {

graph [ label = "\nTraffic Infomation's communication",
size = "11",
fontsize = 20,

fontcolor=blue4];


node [ //shape = box,

color = darkslateblue,

style = filled,

fillcolor = deepskyblue1];

edge [ decorate = false ]

rankdir=TB

subgraph cluster_TI {
style=filled;
color=lightblue1;
l
abel="TI Kernel";

ranke=source

Tuner;

Receiver;
Cache;

Database;
}

subgraph cluster_Device {
//node [shape = box]

style=filled;

color=khaki;

label="HAL";


Device;
}

subgraph cluster_App {
style=filled;

color=plum1;

label="Application";

"Client 1";
"Client 2";
}

Tuner->"Client 1" [label="new station", labelfloat=false, color=darkgreen, fontcolor=darkgreen];
Tuner->Receiver [label="status of band scan",color=magenta, fontcolor=magenta];
Receiver->Cache [label="TrafficData", color=firebrick3, fontcolor=firebrick3];
Receiver->Tuner [label="search next station", color=gold2, fontcolor=gold2];
Cache->"Client 2" [label="message update", color=violet, fontcolor=violet];
Cache->"Client 1" [label="message update", color=violet, fontcolor=violet];
Database->Cache [arrowhead="dot", minlen=2];
Device->Receiver [arrowhead="dot", minlen=0];
Device->Tuner [headlabel="new station", labelfloat=true, color=darkgreen, minlen=2, labeldistance=2, fontcolor=darkgreen];
Tuner->Device [label="search next station", labelfloat=true, color=gold2, minlen=1, fontcolor=gold2];

}


To generate output as png from the dot, type

$ dot -Tpng -ooutput.png inputfile.dot

Tuesday, December 16, 2008

File browser application for S60 developer: "Y Browser"

It is designed for S60 3rd edition devices (Symbian OS 9.x) similar to FileBrowser in RnD Tools from mobile phone manufacture, which you can change files in private directory on C drive.

You can get it directly from Dr.Jukka's website: http://www.drjukka.com/YBrowser.html

Programming fiasco :: "static" initialization

You write two applications using same library, you end up in sudden crash in the library in one application but not another. You expect your compiler might give you a hint lead to that failure but it doesn't.

Check out the following topics from C++ FAQ Lite:

Friday, December 12, 2008

Automate self-extraction file using Rar (WinRar)

Purpose: We have several directories and we want to automate packing process for all of directories specified in configuation file to be each self-extraction.
Script:
To make the self extraction file for DVD installer using Rar.exe (console version of WinRar)

%dirZipNames is the hash which contains the list of input directories and output file names.
$rarPath is the executable "Rar.exe" and its path.
$inputDir is the directory which contains the input directories for packing.


--------------

## Start packing..
for $_ (keys %dirZipNames) {
my $dir = $inputDir . "\\" . $_;
my $zipExe = $inputDir . "\\" . $dirZipNames{$_} . ".exe";
if ( -d $dir && ! -e $zipExe) {
my $dirAll = $dir . "\\*.*";
print "Start packing $dirAll ...proceeding...\n";
print "Or check the progress in make_exe.log...";
system (qq{"$rarPath" a -r -m5 -sfx "$zipExe" "$dirAll" >> "$inputDir\\make_exe.log"});
print "\nOK: $zipExe is done!\n";
}
else {
print "\nError: Directory $dir does not exist \n\tor the $zipExe is already created!\n";
}
}

A sample to employ "epocrc" for automatic resource file creation

Example of using "epocrc" from SDK 3rd Edition FP1

> epocrc -I\symbian\epoc32\include\ -u ex.rss -oex.rsc -hex.rsg

What we want to do here is to generate any "oemid" any time when requested without recompiling the whole resources.

In the example, I have default setting of oemid 1000 and I will replace 1000 with any new id for the resource file which passed to the makeResource function, whereas the output has the same name appended with its new id.

sub makeResource {

my $baseRssFile = "oempid_0x2000AAAA";

chdir($rssPath);

my $pid = $_[0];
my $rssFile = $baseRssFile . ".rss";
my $newRssFile = $baseRssFile . "_" . $pid . ".rss";
open(RSSFILE, $rssFile) or die "Error: Cannot open $1 : $!\n";

my @file = ;
close(RSSFILE);

open(NEWRSSFILE, ">$newRssFile") or die "Error: Cannot open $1 : $!\n";
foreach $_ (@file) {
if ( $_ =~ m/1000/ && $_ =~ /buf/) {
$_ =~ s/1000/$pid/g;

}
print NEWRSSFILE $_;
}
close(NEWRSSFILE);

my $rscFile = $baseRssFile . "_" . $pid . ".rsc";
system("epocrc -I$symbPath -u $newRssFile -o$rscFile");
system("del $newRssFile");
print "$rscFile is done\n";
}

The following part is to read the arguments which may be passed as range of integer or non range integer seperated each entries by comma.

my @num = split(/,/, $args{i});

foreach $_ (@num) { // Input may look like 1,4,7-10,200
my $pid = "";
if ( $_ =~ /(.+)-(.+)/ ) { //search if the input is in range
foreach( $1 .. $2 ) {
&makeResource( $_ );
}
}

else { // non-range argument
&makeResource( $_ );
}

---------------------------


Thursday, December 11, 2008

Wrap around the text with double quote using sed

Purpose: To convert a resource file from excel to be readable by Symbian resource compiler.
Tools: sed
Input: file exported from excel
Output: file with double quotes wraped around the 2nd column text

Format of the file exported from excel with 2 columns separated by tab may look like this:

....
///////////////////////////////////

//Description of this group xxxxxxxxxxxxx
///////////////////////////////////
// String : Message group
// Max length: 256

#define qtn_app_update_message \nUpdateMessage
#define qtn_app_cancel_message Cancel Message
////////////////

...


Here, I would like to wrap the 2nd column with double quote just for the texts which start with #define, but do not insert the quote otherwise.

$ sed -e '/^#/ s/\t/&"/g' -e '/^#/ s/$/"&/' input > output

We try with the combination of two substitions. The first is to insert the double quote after the tab found, the later is to insert
double quote before the line ending. Both substitions are executed only when the lines started with hash.

Obligatory Perforce commands

I am used to with P4V or P4Win but from time to time, I need the "p4" from command line to pass the output to the script.
I found the following p4 commands are obligatory.

To view the current p4 setting, type:
>p4 info

To view it from windows environment:
>set

You can see P4CLIENT and other P4's setting parameters.

To remove p4 client :
>p4 client -d client_name

Otherwise try to create a new one or edit the default one with :
>p4 client

it will give you a temp file to be edited. You can then change to any new client's names
which map to your mapping directories. We usually simply change the "client" and "view" entries where the client can be new name while views are your mappings.
(mind you, take care not to put the new line ending at the end of your views entries otherwise you will get the error message)

Or set it with:
>set P4CLIENT=new_client_name

Now, check if the P4CLIENT is set properly
>echo %P4CLIENT%

Normally, we just need the setting to P4USER (default is automatic set from windows's login account), P4EDITOR (default is notepad for Windows) and P4PORT (it must be manually set). However under Linux, we might need to explicitly export the P4USER in .bashrc if it is not set.
This is my case, I simply added the following lines in my .bashrc:

export P4USER=pattreeya
export P4EDITOR=vim
export P4PORT=scm-srv:1666


To list all p4 environment variables used by Perforce:
>p4 help environment

To diff the local files and the ones in depot, type:
>p4 diff -du20 > diff.txt
The option -du is the unified different and contain 20 lines prior each difference.

To diff between two branches, try:
>p4 diff2 -dub20 -u //work/dev_01/... //work/dev_02/... > diffs.txt

To list the current workspace owned by a user:
>p4 clients -u username

For more detail of p4 commands, type "p4" or "p4 help simple" or "p4 help commands".

Friday, November 28, 2008

Symbian application panic with ucmp 0

In my case, this problem had encountered when I tried to read the data stream to the buffer. The error was occured after second iteration of passing data stream. So how could it be?
Of course, data stream is about data to/from disk. So, I removed the file which previously written to the disk and it solved the problem.

Friday, October 31, 2008

Symbian S60 emulator: ncnlist KERN-EXEC 3

Yesterday I installed new 3rd FP1 SDK and after the simulation started, I got this "ncnlist KERN-EXEC 3". Googled, strange enough, I found only one answer on NewLc (http://www.newlc.com/forum/ncnlist-kern-exec-3-error) which gave the link to Nokia forum about this kernel panic, however the link has been broken!

Searched on Nokia forum and I finally got this :
http://wiki.forum.nokia.com/index.php/TSS000651_-_NCNList_KERN-EXEC_3_panic_when_starting_the_S60_3rd_Edition,_FP1_emulator

There is a link to get the patch file to fix this problem.

Yippie!

Thursday, October 30, 2008

Generating resource file for Symbian S60

How many of less-than-a-year Symbian developer really know about generating of resource file but the abld resource command ?

Yesteday evening I was asked to make a sample of 5 resource files for varies oem's id for 5 customers. That means I need to change the rss file by replacing the existing rss with new customer id, save it, then call the abld command, rename it and store it to its place. Afterward I must repeat the same procedures 5 times!! No, no, no. We planed to support 40 customers at the first release! So, I asked Stephane, my colleague who is symbian expert what tool behind the abld, he said rcomp but he never uses it directly.

So I checked the SDK, yeah, it seemed to be what I wanted. But what were the differences of baseinputfile and the sourcefile and what was RPP, how could we get that? Googled, googled, no answer!! There were few people asked for the rcomp but no answer. Ahhh.. not so many entries met my search string either "symbian rcomp" or "symbian rpp". Hmm...no answer also for rpp. Hence I read and read again every detail of rcomp and this rpp from SDK and experiment, experiment. What the rcomp gave back to me was "BANG!! RCOMP Crash!!", again and again and again. More than 1 hour passed, although I had really believed I understood every single parameters required from rcomp. Something came to my mind..or the rcomp was broken under my PC?? Well, if so, how the abld worked then? Hmm.. ok, let's check the perl package called by abld. Any news? ...Bad.....Sh_____! It still gave me with "BANG, Crash!!!",Crash, Crasssssh!!!

Hey, wait a second!! SDK mentioned another command for generating rsc resource file which again it was kind of wrapper of this rcomp! What was it called ? Right, "epocrc". Hey..there was an example at the end of the help, hmm....the sample looked quite simple, no suspicious parameters nor strange unknown params required Let 's give it a try!

anddddd...BINGO!!

The rest (of the story) is just a piece of cake, a simple perl to take any kind of id and replace it in new rss file and pass the file to "epocrc".