Friday, November 24, 2006

 

Generating drawing for documentation.

There are various ways to generate drawing for documentation. For me things are easier if I do not use GUI and Mouse unnecessarily.Graphviz is open source graphic visualization software developed by AT&T. It runs on multiple platforms, I have used it in Windows and Mac OS X.

It accepts scripts written in dot language and produces a graph/picture. Here is one such drawing for documentation.





The dot file (script) which generates the above drawing.
file: commandstructure.dot


digraph structs
{
node [shape=record];
struct1 [shape=record,
label=" COMMAND| \
COMMAND_TYPE| \
COMMAND_SUB_TYPE|\
PARAMETER"
];
struct2 [shape=record,
label=" {\
{0x1|STRT}| \
{0x2|MONI}| \
{0x3|RPLY}| \
{0x4|PLYD}\
}"
];
struct3 [shape=record,
label=" {\
{0x0|NONE}| \
{0xX|CHNL}| \
{0xX|BUTN} \
}"
];
struct4 [shape=record,
label=" {\
{0x0|OFF}| \
{0x1|ON }| \
{0x2|STP} \
}"
];
struct1:f1 -> struct2;
struct1:f2 -> struct3;
struct1:f3 -> struct4;
}


The command to generate the diagram.
c:\usr\shankar\develop\graphviz>dot -Tpng commandstructure.dot -o command.png
Note the diagram is generated in png format. It can also render it in many other formats like: canon, cmap, cmapx, dia, dot, fig, gd ,gd2, gif, hpgl, imap ,ismap, jpeg, jpg, mif, mp, pcl, pi,ps, ps2, svg, svgz, vrm, vtx, wbmp, xdot. So generate in the format your documentation tool can import.

Graphviz is used by Doxygen to draw C++ class diagrams, dependency graphs etc. of a project. I will cover it some other time.

Labels:


Monday, November 20, 2006

 

A mysterious case of an Hard Drive stopping.

I built an external hard drive based on the FireWire/USB enclosure form CompUSA.



After powering on the hard drive, it use to crash after few minutes. The case used to get too hot to touch. I removed the case and observed that, though the external skin of the case is aluminum the internal is plastic. There was no way to absorb the heat from the hard drive and dissipate, the hard drive used to get too hot and stop. I used aluminum foil to couple the hard drive to external aluminum skin as shown in the photo.




I smeared heat sink compound over the aluminum foil which will now absorb
the heat away from the hard drive.



I have used this external drive from past 2 years without any problem

Labels:


Sunday, November 19, 2006

 

Creating play list for Entempo MP3 Player.



I bought Entempo Spirit 20 GB MP3 player long back. The only criteria for buying this was the price. For $99 you get and 20GB external USB hard drive, which can be used on Mac and PC. I have used this to backup Cannon RAW pictures (CR2) from my Rebel XT digital camera on the road.

The price comes with some shortcomings. Creating play list is difficult. It uses DOS short name inside mp3 play list as shown below:
#EXTM3U
#EXTINF:0,Steve-McConnell-Software-Engineering
#I:/IT_CON~1/STEVE-~1.MP3

Where I: is the entempo drive name it uses internally.

There are no media players which can create the play list in that format. I wrote a Python script to do just that.

#!/usr/bin/python
#Jun 13, 2005 04:51 PM Shankar Chakkere
#This file will create entempo style playlist,
#
#FORMAT
#
#EXTM3U
#EXTINF:0,Steve-McConnell-Software-Engineering
#I:/IT_CON~1/STEVE-~1.MP3
#
import os, re, sys

def dirwalk(dir):
for f in os.listdir(dir):
fullpath = os.path.join(dir,f)
if os.path.isdir(fullpath) and not os.path.islink(fullpath):
for x in dirwalk(fullpath): # recurse into subdir
yield x
else:
yield fullpath

if len(sys.argv) == 1:
print "No file name to match"
print "USAGE:"
print sys.argv[0]+" Pattern"
print "e.g."
print sys.argv[0]+" srenivas > playlist/pbsreenivas.m3u"
sys.exit(1)

print "#EXTM3U"
previous_file_name = ""

for file in dirwalk("."):
file = file.upper()

mp3 = re.match(".*\.MP3",file)

if mp3: #List only filenames with extension .mp3
pattern = ".*"+ sys.argv[1] # make it reqular expression by adding .*at the begining of search string
pattern = pattern.upper()
file_match = re.match(pattern,file)

if file_match:
sfile = file.split("/")
extinfo ="#EXTINF:0," + sfile[-1]
print extinfo
filename = "I:"
pathcount = 1 # 1 because we are skipping 1 in sfile

for mp3file in sfile[1:]: # Dont print the root directory i.e"\.";
mp3file_with_nospace = mp3file.replace(" ","")
pathcount = pathcount + 1
#print "pathcount :",pathcount,"len",len(sfile),"filename :",filename,"mp3file",mp3file_with_nospace,"previous",previous_file_name

if pathcount == len(sfile): # If filename
if mp3file_with_nospace[0:6] == previous_file_name:
count = count + 1
else:
count = 1
previous_file_name = mp3file_with_nospace[0:6]

if len(mp3file_with_nospace) > 8 and pathcount == len(sfile): # If filename
#print "2",len(sfile)," ",pathcount," ",mp3file_with_nospace
if len(mp3file_with_nospace) >12:

filename = filename + "/" + mp3file_with_nospace[0:6] + "~" + str(count)
else:
length = len(mp3file_with_nospace)-4 #.MP3 four bytes
filename = filename + "/" + mp3file_with_nospace[0:length]
else:
if len(mp3file_with_nospace) > 8 and pathcount != len(sfile): # If directory
filename = filename + "/" + mp3file_with_nospace[0:6] + "~1"
else:
#length = len(mp3file_with_nospace)-4 #.MP3 four bytes
#if pathcount == len(sfile):
# filename = filename + "/" + mp3file_with_nospace[0:length]
#else:
filename = filename + "/" + mp3file_with_nospace

filename = filename + ".MP3"
print filename

The DOS command dir /x was used to verify the DOS short name on Windows XP.

I use the script as shown below:

schakkere@shankar ~>cd e:
./playlist.py myselection >PLAYLIST/inter.m3u

myselection is the directory which contains MP3 files.
PLAYLIST is the directory where the play list is stored.

Note: The script is stored in the root directory of ENTEMPO.

Also the player has another shortcoming. It cannot play VBR and bitrates should be less than 48K in mp3.This batch file fixes that: It converts all the mp3 in current directory to fixed rate (48K).
@rem Oct 03, 2005 12:18 PM
@rem Shankar Chakkere
@rem This batch file will convert the mp3s to 48Kb rate so the entempo will
@rem play it. Entempo will not play VBR and higher bit rate mp3
@rem if not exist t echo " directory t does not exists"
@IF NOT EXIST t mkdir t
@for %%f in (*.mp3) do c:\djgpp\bin\lame -b 48 -mj "%%f" "t\%%f"

Note: The converted MP3 files will be in "t" subdirectory.

Labels:


Friday, November 17, 2006

 

Downloading multiple files from a site.

There are multiple extensions which you can add to firefox to select and download multiple files from a site.I like to do this easier way on a command line.

In Windows:
$ dog --links http://blogs.parachute.com/jobtalk/archives/podcasts/index.html |grep mp3|sed -e "s/^/ wget -c /" >gett.bat
In Mac OS X:
$~>echo '#!/bin/sh'  >gett.sh
$~>dog --links http://blogs.parachute.com/jobtalk/archives/podcasts/index.html |grep mp3|sed -e "s/^/ wget -c /" >>gett.sh
$~>chmod +x gett.sh
Explanation:
dog gets the list of links in the URL. dog is better than cat(concantenation)!
grep selects the URL of only the mp3 file.
sed adds wget -c before each line.

For Windows:
wget, grep and sed are available through Cygwin. You can compile dog in Cygwin environment. Double clicking the batch file gett.bat will download all the files you selected.

For Mac OS X:
wget, grep and sed are available through terminal. You can compile dog and install. Issue $~>./gett.sh to download the files selected.

You can download the source for dog from here: http://ftp.kernel.pl/people/baseciq/rpm/src/dog-1.7-1.src.rpm. The source is in the rpm(Redhat package format). I used Total Commander to extract the files in Windows.

Labels:


Wednesday, November 15, 2006

 

Finding a keyword in an encoded file.

While testing a codec I needed to find out how many milliseconds of audio is in the encoded file.I decode this data into Wave format.

The encoded file.
c:\usr\shankar\lib>cat packed.pcm |od -h |head
000000 6b21 0fc5 0457 6f00 065d 58c8 6b21 0dc5
000010 0c3b de36 a172 8a89 6b21 0dc5 cc97 ef2c
000020 8381 bc56 6b21 0b63 849b 300a 4b8c 927b
000030 6b21 0f65 5c3b bb40 c56d 7567 6b21 0dc5
000040 943b a645 8869 94a9 6b21 0d45 143b 7314
000050 8469 f256 6b21 7f75 1c3b 1fa6 e571 22c7
000060 6b21 cb63 5c3a 5708 796c 2a94 6b21 6f75
000070 043b 1d27 1171 2201 6b21 0d45 e43b 9735
000080 7c6f 9e03 6b21 7f75 c43b 1f32 3875 a76c
000090 6b21 0dc5 f437 e5ad f36c b14f 6b21 cb63
Ten millisecond worth of encoded data is delimited by 6b21. So if I count the number of 6b21's in the encoded data, I get the total number of millisecond.

Here is one way to do it.
c:\usr\shankar\lib>cat packed.pcm |od -h |cut -d' ' -f2-| tr `\ ``\n` |grep 6b21 |wc
300 2700 14100
There is 3 Sec (300 *10 millisecond) of audio in this file.

Explanation:
The command cut -d' ' -f2- cuts the first column which is address field
The tr command translates space to linefeed as shown below.
c:\usr\shankar\lib>cat packed.pcm |od  -h |cut -d' ' -f2- |tr '\ ' '\n'|head
6b21
0fc5
0457
6f00
065d
58c8
6b21
0dc5
0c3b
de36
Why in this format?
Because I just have to extract 6b21's using grep as shown below
c:\usr\shankar\lib>cat packed.pcm |od  -h |cut -d' ' -f2- |tr '\ ' '\n'|grep 6b21 |head
6b21
6b21
6b21
6b21
6b21
6b21
6b21
6b21
6b21
6b21
Now wc will only count 6b21's!. All the above unix commands are available for Windows by installing Cygwin or Djgpp.

Labels: ,


Tuesday, November 14, 2006

 

Backup preferences

I use windows and Mac OS X. Most of the applications I use are multiplatform. I save/backup the preferences of these applications in a thumb drive.
Here is the batch file which does that; you can write a shell script based on this.

Batch file backup_my_preferences.bat


rem Mar 06, 2006 10:35 AM
rem This will backup my prefences to a thumb drive
rem
rem TODO use rysnc instead of copy
rem
rem $1 is the drive name provided by totalcommander or as a parameter from command line
rem
rem firefox
IF EXIST "%1\backup" GOTO havebackup
mkdir %1\backup
:havebackup
IF NOT EXIST "%1\backup\firefox" mkdir %1\backup\firefox
@rem echo /v /y "c:\Documents and Settings\name.com\ApplicationData\Mozilla\Firefox\Profiles\i53v54ql.default\bookmarks.html" %1\backup\firefox\
copy /v /y "c:\Documents and Settings\name.com\ApplicationData\Mozilla\Firefox\Profiles\i53v54ql.default\bookmarks.html" %1\backup\firefox\

rem googleearth
IF NOT EXIST "%1\backup\GoogleEarth" mkdir %1\backup\GoogleEarth
copy /v /y "c:\Documents and Settings\name.com\ApplicationData\Google\GoogleEarth\*.*" %1\backup\GoogleEarth\

rem itunes
IF NOT EXIST "%1\backup\itunes" mkdir %1\backup\itunes
copy /v /y "c:\Documents and Settings\name.com\My Documents\My Music\iTunes\*.*" %1\backup\itunes\

rem KeepPass database
IF NOT EXIST "%1\backup\keepass" mkdir %1\backup\keepass
copy /v /y "c:\usr\shankar\doc\Database.kdb" %1\backup\keepass\

rem vim
IF NOT EXIST "%1\backup\vim" mkdir %1\backup\vim
copy /v /y "c:\vim\_vimrc_shankar" %1\backup\vim\
copy /v /y "c:\vim\_vimrc" %1\backup\vim\

rem bash
IF NOT EXIST "%1\backup\bash" mkdir %1\backup\bash
copy /v /y "c:\usr\shankar\.profile" %1\backup\bash\
copy /v /y "c:\usr\shankar\_bashrc" %1\backup\bash\
copy /v /y "c:\usr\shankar\.bashrc" %1\backup\bash\
copy /v /y "c:\usr\shankar\.inputrc" %1\backup\bash\
copy /v /y "c:\usr\shankar\_inputrc" %1\backup\bash\
copy /v /y "c:\usr\shankar\.wgetrc" %1\backup\bash\
copy /v /y "c:\usr\shankar\.gdbinit" %1\backup\bash\

copy /v /y "c:\usr\shankar\README-doxygen" %1\backup\bash\
copy /v /y "c:\usr\shankar\config.doxy" %1\backup\bash\
copy /v /y "c:\usr\shankar\.astylerc" %1\backup\bash\

rem freemind
IF NOT EXIST "%1\backup\freemind" mkdir %1\backup\freemind
xcopy /s /y "c:\usr\shankar\freemind" %1\backup\freemind\

rem Stellarium
IF NOT EXIST "%1\backup\stellarium" mkdir %1\backup\stellarium
copy /v /y "c:\Program Files\utils\Stellarium\config\config.ini" %1\backup\stellarium\
:endd



To run this in a DOS Window
c:\usr\shankar>backup_my_preferences g:

Where g: is the thumb drive. I have assigned a button to this batch file in Totalcommander.

Labels:


Thursday, November 02, 2006

 

Testing TED Input

The GUI I am developing accepts commands as an event generated by an button push or through an TCP/IP port. The reason is the software can work as a standalone module or with an TED (Touch Entry Display) which communicates through TCP/IP (localhost). To test the software I did not had the TED. I had to simulate the command. The following code generates one such command over TCPIP socket on port 49000.

schakkere@shankar ~

$ echo fd 01 00 01 | xxd -r -p |nc localhost 49000 > response.bin

Explanation:

echo feeds in the command "fd 01 00 01" as string to xxd.
xxd converts it into hex.
nc (NetCat) sends the hex command as TCP/IP packets on localhost.

My GUI receives this command on socket 49000.

xxd is a small c program which can be complied on DJGPP or cygwin.

This page is powered by Blogger. Isn't yours?