# nanddump -b -o -f ddd -l 2097152 /dev/mtd3
# nandwrite /dev/mtd3 ddd 0 (I have not test it yet)
Monday, December 15, 2008
nanddump
Here is the command to dump linux kernel, suppose "ddd" is the image name, "2097152" is the digit number of 0x200000 in hex, may not be exactly the same of the actual length, but it works.
Friday, November 21, 2008
Knuth
I was shocked that Knuth was diagnosed with prostate cancel. It is not a news, but I just got know today from this interview.
I like the words "If I should unexpectedly die tomorrow, I’ll have no reason to complain, because my life has been incredibly blessed. ", very inspiring.
Andrew: In late 2006, you were diagnosed with prostate cancer. How is your health today?
Donald: Naturally, the cancer will be a serious concern. I have superb doctors. At the moment I feel as healthy as ever, modulo being 70 years old. Words flow freely as I write TAOCP and as I write the literate programs that precede drafts of TAOCP. I wake up in the morning with ideas that please me, and some of those ideas actually please me also later in the day when I’ve entered them into my computer.
On the other hand, I willingly put myself in God’s hands with respect to how much more I’ll be able to do before cancer or heart disease or senility or whatever strikes. If I should unexpectedly die tomorrow, I’ll have no reason to complain, because my life has been incredibly blessed. Conversely, as long as I’m able to write about computer science, I intend to do my best to organize and expound upon the tens of thousands of technical papers that I’ve collected and made notes on since 1962.
I like the words "If I should unexpectedly die tomorrow, I’ll have no reason to complain, because my life has been incredibly blessed. ", very inspiring.
flash jffs2
Use flash on a arm-linux board always requires jffs2.
Here is the command that do flash erase and copy rootfs to mtdblock4.
Here is the command that do flash erase and copy rootfs to mtdblock4.
# flash_eraseall -j /dev/mtd4
# dd if=rootfs.jffs2 of=/dev/mtd4 bs=4096
# mount -t jffs2 /dev/mtdblock4 /mnt/jffs2
Thursday, November 6, 2008
coding standard (GNU)
I feel I am quite like the coding standard with GNU by reading GTick.
1. variables and variable types are small characters. (add "_t" for types)
2. function names are small characters, and written in this way: (in function name: words are connected by "_", this is my favorite way)
3. comments in this layout.
4. CONSTANTS and MACROES are large characters.
1. variables and variable types are small characters. (add "_t" for types)
dsp_t* dsp;
2. function names are small characters, and written in this way: (in function name: words are connected by "_", this is my favorite way)
dsp_t* dsp_new(comm_t* comm);
3. comments in this layout.
/* headers*/
#include < stdio.h>
#include < stdlib.h>
/*
* brief.
*
* input: from: data source of input
* from_size: the number of frames in [from]
* output: to: the pointer to the allocated data.
*
* NOTE: here is the note. [to] should be free by the caller.
*/
static int foo(short* from, int from_size, unsigned char** to);
4. CONSTANTS and MACROES are large characters.
Wednesday, November 5, 2008
no writing permission on /tmp
I found myself has no writing permission on /tmp with FC5. It caused many troubles, firefox would not launch, because it creates temporary files when it starts... To solve it is quite simple:
$ cd /
$ sudo chmod 777 tmp
Friday, October 24, 2008
remove files in different directories
I used to know how to find files in different directories,
find . -name '*.raw' will list all the raw files, but how to delete them?
Here is the result:
Another usage: I want remove GNU assembly code which is generated by ADS and all the other object files.
or using "-ok" with control by the user (type 'y' or 'n' for each file).
find . -name '*.raw' will list all the raw files, but how to delete them?
Here is the result:
[root@QSLENG13_FC5 xxx]# find . -name '*.raw' -exec ls {} \;
./SP-MIDI/output_midi.raw
./SMAF_MA-5/output_midi.raw
./SMAF_MA-3/output_midi.raw
./SMAF_MA-2/output_midi.raw
./MXMF/output_midi.raw
./MIDI_RIFF_Format_1/output_midi.raw
./MIDI_RIFF_Format_0/output_midi.raw
./MIDI_Format_1/output_midi.raw
./MIDI_Format_0/output_midi.raw
./KAR/output_midi.raw
./JTS/output_midi.raw
./iMelody/output_midi.raw
[root@QSLENG13_FC5 xxx]# find . -name '*.raw' -exec rm {} \;
[root@QSLENG13_FC5 xxx]# find . -name '*.raw' -exec ls {} \;
Another usage: I want remove GNU assembly code which is generated by ADS and all the other object files.
# find . \( -name '*.o.s' -o -name '*.o' \) -exec rm {} \;
or using "-ok" with control by the user (type 'y' or 'n' for each file).
[root@QSLENG13_FC5 linux]# find . \( -name '*.a' -o -name '*.so' \) -ok rm {} \;
< rm ... ./libmqcore32.a > ? n
< rm ... ./libmqcore32.so > ? n
< rm ... ./libq3di32.so > ? n
< rm ... ./libq3di32.a > ? n
Thursday, October 23, 2008
use of scp
My memory is easy to forget, usually I am using tftp and nfs to share files, but I can not do it through ssh. When one door is close, there is another door open, I can use 'scp' from my Linux PC to transfer files.
Wednesday, October 8, 2008
clone jffs2
mount -t jffs2 /dev/mtdblock4 /mnt/nand
mount /dev/mmcblk0p2 /mnt/mmc2
I use mmc card as the media to save the rootfs at nand flash. It is not as easy as type: "tar czvf /mnt/mmc2/target.tar.gz /mnt/nand/". It won't work within busybox from the ARM target, could be the problem of tar.
How ever here is the magic:
tar cf - -C /mnt/nand . | tar xvf - -C /mnt/mmc2/target
Then pull the SD card and connect to the Linux PC, copy the file system with simply "cp -r /tftpboot /mnt/mmc2/target".
Tuesday, October 7, 2008
tftp on FC5
1. edit tftp file in "/etc/xinetd.d"
"/tftpboot" is my directory to be used by tftp. comment out "disable = yes" to enable tftp.
2. restart xinetd service.
service tftp
{
disable = no
socket_type = dgram
protocol = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /tftpboot
# disable = yes
per_source = 11
cps = 100 2
flags = IPv4
}
"/tftpboot" is my directory to be used by tftp. comment out "disable = yes" to enable tftp.
2. restart xinetd service.
$ sudo /sbin/service xinetd restart
Friday, October 3, 2008
compile mplayer with ALSA for ARM
1. download mplayer source code. I am using (MPlay-1.0rc2.tar.bz2)
2. extract it.
3. write a script mybuild.sh for configuring
Here $TGT contains alsa include files and library "libasound.so.2".
4. type "make"
2. extract it.
3. write a script mybuild.sh for configuring
export CROSS_CC=/opt/CodeSourcery/arm-2007q3-51
export PATH=$CROSS_CC/bin:$PATH
export TGT="your target file system"
./configure --enable-cross-compile -cc=arm-none-linux-gnueabi-gcc \
--host-cc=gcc --target=arm-linux --prefix=$TGT \
--disable-network --disable-x11 --disable-gui \
--with-extralibdir=$TGT/lib \
--with-extraincdir=$TGT/include
Here $TGT contains alsa include files and library "libasound.so.2".
4. type "make"
Thursday, September 18, 2008
patch
As I use cvs for code control, I found patch is a good tool that helps to build the actual release. To do actual release, some times I need to make changes on the code such as change the macro of "#define ENABLE_FOO 0" or some thing else, and these change may not be good to commit to cvs, and I also don't want to create branch with cvs, as each branch can be orphan if I forget to update. So the basic way is:
1. cvs tag
2. modify some code and build the release.
3. make patch (I use tortoriseCVS)
When you want to apply the patches, first make sure you can the patch is for what 'tag' version. after that
1. cvs co -r "tag" "module name"
2. go to the directory you just check out the source code.
3. patch -p0 < "your patch file"
1. cvs tag
2. modify some code and build the release.
3. make patch (I use tortoriseCVS)
When you want to apply the patches, first make sure you can the patch is for what 'tag' version. after that
1. cvs co -r "tag" "module name"
2. go to the directory you just check out the source code.
3. patch -p0 < "your patch file"
Thursday, September 11, 2008
Macbook
My Macbook died a week ago, yesterday I got it back from west world who repaired it. The harddrive is changed, but all the data are lost.
I use all the systems (windows, Linux), but feel extremely addicted to Mac OS X. It mainly changed my way of surfing internet. Here is the trick:
1. delicouse2safari: save my delicious bookmarks to safari
2. Launchbar: rescan all the bookmarks, then I am ready to use.
The new Firefox (version 3.01) is released, yesterday I saw the new face on Mac for the first time, I don't feel it looks better than on the PC, but it works fine. I've been using vimperator for quite a while, it gave me quick access with firefox using vim-style key binding, but as the firefox3 pop up, I feel difficulty with vimperator. So I disable this add-on, hope the author of vimperator can improve it. (The most unhappy experience with vimperator, is I did not see tabs on the gui, although I can type "tabs" to show all the tabs in the buffer. I would like to see the tabs bar, not sure where the problem is)
I use all the systems (windows, Linux), but feel extremely addicted to Mac OS X. It mainly changed my way of surfing internet. Here is the trick:
1. delicouse2safari: save my delicious bookmarks to safari
2. Launchbar: rescan all the bookmarks, then I am ready to use.
The new Firefox (version 3.01) is released, yesterday I saw the new face on Mac for the first time, I don't feel it looks better than on the PC, but it works fine. I've been using vimperator for quite a while, it gave me quick access with firefox using vim-style key binding, but as the firefox3 pop up, I feel difficulty with vimperator. So I disable this add-on, hope the author of vimperator can improve it. (The most unhappy experience with vimperator, is I did not see tabs on the gui, although I can type "tabs" to show all the tabs in the buffer. I would like to see the tabs bar, not sure where the problem is)
Monday, August 25, 2008
Thursday, July 31, 2008
ip_local_port_range
The following command modifies the file /proc/sys/net/ipv4/ip_local_port_range.
Some times I can not directly write to the file in proc. But this works:
Some times I can not directly write to the file in proc. But this works:
$ sudo sysctl -w net.ipv4.ip_local_port_range="1024 64000"
Wednesday, July 30, 2008
Windows share folders with vmware Ubuntu
I have trouble to view share folder from Ubuntu 7.0.4. There are several ways to do it. One is through smb4k, the other is with vmware share folder settings. Neither works for me. So with the second way, I found out the solution from the Internet.
Here is the fix:
This fix changes the driver.c in /usr/lib/vmware-tools/modules/source. Make a backup on vmhgfs.tar, untar it (tar xvf vmhgfs.tar), make edit on driver.c, tar it back (tar cvf vmhgfs.tar vmhgfs-only) and re-run vmware-config-tools.pl.
Everything is fine on building hgfs module.
Here is the fix:
/*
#define INODE_SET_II_P(inode, info) do { (inode)->u.generic_ip = (info); } while (0)
#define INODE_GET_II_P(inode) ((HgfsInodeInfo *)(inode)->u.generic_ip)
*/
#define INODE_SET_II_P(inode, info) do { (inode)->i_private = (info); } while (0)
#define INODE_GET_II_P(inode) ((HgfsInodeInfo *)(inode)->i_private)
// inode->i_blksize = HGFS_BLOCKSIZE;
This fix changes the driver.c in /usr/lib/vmware-tools/modules/source. Make a backup on vmhgfs.tar, untar it (tar xvf vmhgfs.tar), make edit on driver.c, tar it back (tar cvf vmhgfs.tar vmhgfs-only) and re-run vmware-config-tools.pl.
Everything is fine on building hgfs module.
Tuesday, July 29, 2008
nyquist - built it on Ubuntu 7.04
I am not really familiar with Ubuntu, usually I use Fedora Core 5 at work, but this time I got a new project which need to install ACCESS Linux platform(ALP), ALP is provided with debian-based packages, so I can only do my job on Ubuntu or Debian.
I install Ubuntu 7.0.4 though vmware on PC at work and MacBook at Home. At work, I have a big trouble, is the amxier & aplay can not be used to play audio file, I do some fix to make amixer work, but aplay still not work. I also got Ubuntu 7.10 installed, it is OK with audio playing. And there's no audio problem on my MacBook with Ubuntu 7.04.
At I am trying to compile nyquist myself. At start, gcc complains it can not find "stdio.h" file. So I install libc-dev, then it complains could not find g++. So I install g++. After that, I got link errors. It could not find readline. The follow command solves the issue:
Then is asound. I use the following command to find libasound.
The last problem is it could not find javac, it is hard to find through "apt-cache search", the following command make it work.
I install Ubuntu 7.0.4 though vmware on PC at work and MacBook at Home. At work, I have a big trouble, is the amxier & aplay can not be used to play audio file, I do some fix to make amixer work, but aplay still not work. I also got Ubuntu 7.10 installed, it is OK with audio playing. And there's no audio problem on my MacBook with Ubuntu 7.04.
At I am trying to compile nyquist myself. At start, gcc complains it can not find "stdio.h" file. So I install libc-dev, then it complains could not find g++. So I install g++. After that, I got link errors. It could not find readline. The follow command solves the issue:
sudo apt-get libreadline5-dev
Then is asound. I use the following command to find libasound.
apt-cache search libasound
..
sudo apt-get install libasound2-dev
The last problem is it could not find javac, it is hard to find through "apt-cache search", the following command make it work.
sudo apt-get install sun-java6-jdk
Friday, July 25, 2008
Wind generation from Audacity-Nyquist
Audacity is a free audio editor for Windows, Linux and Mac OS X. What I found the interesting thing is -- it support writing plugins with Nyquist. Well, Nyquist is a Lisp enhancement for audio/synth based on a common language -- XLISP. XLISP is a very old Lisp Language with support of object-oriented concept such as "class", I print the manual, and the date for the manual is 1988.
So I have the platform to do the following:
1. Experiment writing in Lisp.
2. To Learn the two most common parts in DSP (DFT and Digital filters)
3. Learn audio processing (gain, db etc)
Wow, in my life I am eager to learn all these three parts, but I have not get any benefits even I have put years of time. I just could not understand. I think it may take more years. I am just not smart enough. But any way it is my direction.
Below you will hear wind, I generate it based on David R. Sky's Wind plugin. I am using Audacity 1.3.5, and the wind is a mono audio. It fails when I set it to stereo, not sure what is wrong with it.
note 20080818: I have removed the wind flash link.
So I have the platform to do the following:
1. Experiment writing in Lisp.
2. To Learn the two most common parts in DSP (DFT and Digital filters)
3. Learn audio processing (gain, db etc)
Wow, in my life I am eager to learn all these three parts, but I have not get any benefits even I have put years of time. I just could not understand. I think it may take more years. I am just not smart enough. But any way it is my direction.
Below you will hear wind, I generate it based on David R. Sky's Wind plugin. I am using Audacity 1.3.5, and the wind is a mono audio. It fails when I set it to stereo, not sure what is wrong with it.
note 20080818: I have removed the wind flash link.
Monday, July 21, 2008
audacity - build & install on FC5
The default audacity package does not have mp3 built as default on FC5. So I spend some time to build my own audacity on FC5.
1. Install libmad. This is the mp3 decoder library. I directly found a previous build at here.
2. Install libsndfile. (It is already there).
3. Build wxGTK. Since the default wxGTK is 2.4.2 (audacity 1.2.5) and I am try to build audacity 1.3.5 which needs wxGTK 2.6.1 plus, I have to uninstall the default install package.
Also, make sure gtk is installed. (FC5 default contains these libs). Following is the script to build wxGTK (2.6.4).
And "wx-config --list" is a useful command to list how wxGTK is configured.
4. Build audacity.
5. Fix libwx_gtk shared libary with ldconfig. Since my build shared library is installed at /usr/local/lib. So I have to do some fix with "/etc/ld.so.conf". I creat and edit a file named "audacity-i386.conf" in /etc/ld.so.conf.d directory of FC5, just add a line "/usr/local/lib", and do "/sbin/ldconfig". To check result use "/sbin/ldconfig -v".
6. Launch audacity to open a mp3 file to see is it work.
MISC.
To query a package (for example wxgtk) on FC5. I want to know what the package name is, is it installed on the system, and the version number etc.
I use "yum info wxgtk" to get the package information, but some times I have no idea with the package name, so I use the following command to find out:
1. Install libmad. This is the mp3 decoder library. I directly found a previous build at here.
2. Install libsndfile. (It is already there).
3. Build wxGTK. Since the default wxGTK is 2.4.2 (audacity 1.2.5) and I am try to build audacity 1.3.5 which needs wxGTK 2.6.1 plus, I have to uninstall the default install package.
Also, make sure gtk is installed. (FC5 default contains these libs). Following is the script to build wxGTK (2.6.4).
./configure --with-gtk --enable-gtk2
make
make install
And "wx-config --list" is a useful command to list how wxGTK is configured.
4. Build audacity.
./configure
make
make install
5. Fix libwx_gtk shared libary with ldconfig. Since my build shared library is installed at /usr/local/lib. So I have to do some fix with "/etc/ld.so.conf". I creat and edit a file named "audacity-i386.conf" in /etc/ld.so.conf.d directory of FC5, just add a line "/usr/local/lib", and do "/sbin/ldconfig". To check result use "/sbin/ldconfig -v".
6. Launch audacity to open a mp3 file to see is it work.
MISC.
To query a package (for example wxgtk) on FC5. I want to know what the package name is, is it installed on the system, and the version number etc.
I use "yum info wxgtk" to get the package information, but some times I have no idea with the package name, so I use the following command to find out:
rpm -q -a | grep -i wxgtk
Monday, June 30, 2008
use shell variables in sed
input=abc.wav
i=0
while test $i != 10
do
echo "run case $i
tag=`expr output-foo-$i`
output=`echo $input | sed -e "s/^\(.*\)\.wav$/\1-$tag\.wav"`
./foo.bin -v -e -E $i -o $output $input
done
Here instead of
sed -e 's/^\(.*\)\.wav$/\1-$tag\.wav'
Use
sed -e "s/^\(.*\)\.wav$/\1-$tag\.wav"
Friday, June 20, 2008
Set up for recording audio with Windows
Tuesday, June 17, 2008
nfs client
I got an error when mount NFS disks with my OMAP linux box.
Here is the result. (The reason is I don't have portmap running in the box)
And then, I got another panic message, when I run a program.
Here is the result.
rpcbind: server localhost not responding, timed out
RPC: failed to contact local rpcbind server (errno 5).
Here is the result. (The reason is I don't have portmap running in the box)
mount -t nfs -o nolock 192.168.0.9:/tmp /mnt/mmc
And then, I got another panic message, when I run a program.
nfs: server 192.168.0.9 not responding, still trying
Here is the result.
mount -t nfs 192.168.0.9:/tmp /mnt/mmc -o nolock,hard,rsize=1024,wsize=1024
Monday, June 16, 2008
setup dhcp, nfs on FC5
setup dhcp server
I need to setup dhcp server under my router.
Here is the configuration file (/etc/dhcpd.conf)
Here "trgt" is a linux device which has fixed ip address, and need boot image through NFS from linux host with ip "192.168.2.151".
Start dhcp-server with: `/etc/rc.d/init.d/dhcpd start`
Setup nfs
Edit /etc/exports
Edit /etc/hosts.allow
And edit /etc/hosts.deny
run: `exportfs -ra`
scripts on start nfs
Check nfs status with: `/sbin/service nfs status`
You may need to "/sbin/service iptables stop" sometimes if you can the ip but can not mount while getting "no route and host" message.
I need to setup dhcp server under my router.
Here is the configuration file (/etc/dhcpd.conf)
ddns-updates on;
subnet 192.168.2.0 netmask 255.255.255.0 {
option routers 192.168.2.1;
option subnet-mask 255.255.255.0;
option domain-name "local.net";
option domain-name-servers ns.local.net;
host trgt {
hardware ethernet 08:00:28:01:15:F7;
fixed-address 192.168.2.110;
option root-path "/opt/eldk/ppc_8xx";
option host-name "trgt";
next-server 192.168.2.151;
filename "tftpboot/pImage";
}
}
ddns-update-style ad-hoc;
Here "trgt" is a linux device which has fixed ip address, and need boot image through NFS from linux host with ip "192.168.2.151".
Start dhcp-server with: `/etc/rc.d/init.d/dhcpd start`
Setup nfs
Edit /etc/exports
/tftp 192.168.2.110(rw,no_root_squash,sync)
Edit /etc/hosts.allow
portmap: 10.10.10.20
lockd: 10.10.10.20
mountd: 10.10.10.20
rquotad: 10.10.10.20
statd: 10.10.10.20
And edit /etc/hosts.deny
portmap: ALL
lockd: ALL
mountd: ALL
statd: ALL
run: `exportfs -ra`
scripts on start nfs
/etc/init.d/portmap start
/etc/init.d/nfslock start
/etc/init.d/nfs start
/etc/init.d/netnfs start
Check nfs status with: `/sbin/service nfs status`
rpc.mountd (pid 4181) is running...
nfsd (pid 4183 4182 4181 4180) is running
rpc.rquotead (pid 4170) is running
You may need to "/sbin/service iptables stop" sometimes if you can the ip but can not mount while getting "no route and host" message.
Tuesday, June 10, 2008
use cu
1. install uucp "sudo apt-get install uucp"
2. edit /etc/uucp/sys
3. edit /etc/uucp/port to add serial0_115200
4. Add serial port to VM, otherwise it will not show up.
5. run `cu S0@115200` and get a response "Connected."
To terminate, type `~.`
2. edit /etc/uucp/sys
system S0@115200
port serial0_115200
time any
3. edit /etc/uucp/port to add serial0_115200
port serial0_115200
type direct
device /dev/ttyS0
speed 115200
hardflow false
4. Add serial port to VM, otherwise it will not show up.
5. run `cu S0@115200` and get a response "Connected."
To terminate, type `~.`
Thursday, May 22, 2008
gnu make on win32 shell
1. The version of gnu make that works on win32 is 3.80, while both 3.78 and 3.81 would not work.
2. win32 shell script. The following is a sample which uses cvs to check out foo source code
2. win32 shell script. The following is a sample which uses cvs to check out foo source code
@echo off
set PRJ_DIR=%PRJ_ROOT%\foo-%PRJ_TSTAMP%
set PRJ_NAME=foo
if "%1"=="-D" goto check_out_tstamp;
echo "check out HEAD of %PRJ_NAME%"
cvs co -d %PRJ_DIR% -P %PRJ_NAME%
goto end;
: check_out_tstamp
echo "check out with time stamp"
cvs co -D %PRJ_TIME% "-d" %PRJ_DIR% -P %PRJ_NAME%
:end
Thursday, May 15, 2008
vim - some tips on use cscope and ctags
1. cscope does not work very well on c++, it is hard to search class members. (so don't expect cscope can do everything)
2. don't use "cscope -b -q" to build the database
3. with ctrl-\ and f, open header file in a c/C++ source code
4. add database with specification on ignore charactor case.
5. Here is my build bat file for win32
2. don't use "cscope -b -q" to build the database
3. with ctrl-\ and f, open header file in a c/C++ source code
nmap < C-\>f :cs find f < C-R>=expand("< cword>") . ".h" < CR>< CR>
4. add database with specification on ignore charactor case.
cs add cscope.out . -C
5. Here is my build bat file for win32
rm cscope.* tags
set project=c:\work\foo
find %project% -name "*.cpp" -o -name "*.[ch]" > cscope.files
cscope -b
ctags --extra=+q -L cscope.files
Monday, May 12, 2008
utils - ti memory data conversion
The ccs IDE provides a function to save memory data to a file, here is a saved file:
It is a text file, with the first line, contains the memory address, the data length etc. From the next line, comes the data. Since the output is still the text file, I need to convert it to actual binary data. So I develop a little application to do the conversion. Not good on awk, or with sed, I use c programming language directly. C is such powerful.
I just need to pay attention to the byte order, for example, if it is "0x00004F99" from the input, the output will be "99 4F 00 00". BUT the confusing part is here:
In "if" condition, the evaluating is one by one, the first item "evaluate" first, then is the next, while in function, the "evaluation" of parameters is, the last item first (put on the stack first), and moves on previous items. so that is why the first parameter to my_asc2hex is the latter one. kind of confusing using pointer!
1651 1 10032238 0 300
0x00000000
0x00000000
0x00000000
0x00000000
....
It is a text file, with the first line, contains the memory address, the data length etc. From the next line, comes the data. Since the output is still the text file, I need to convert it to actual binary data. So I develop a little application to do the conversion. Not good on awk, or with sed, I use c programming language directly. C is such powerful.
#include < stdio.h>
#include < string.h>
#define LINE_MAX 256
char my_asc2hex(char a, char b)
{
char o;
if (a >= '0' && a <='9') a = a - '0';
if (a >= 'a' && a <='f') a = a - 'a' + 10;
if (a >= 'A' && a <='F') a = a - 'A' + 10;
if (b >= '0' && b <='9') b = b - '0';
if (b >= 'a' && b <='f') b = b - 'a' + 10;
if (b >= 'A' && b <='F') b = b - 'A' + 10;
o = a + b * 16;
return (o);
}
int main(int argc, char* argv[])
{
char line_buf[LINE_MAX];
char* lp;
FILE* fp, *fp_out;
char aa,bb,cc,dd;
if (argc < 3){
printf("%s ti_input_file output_file", argv[0]);
return 1;
}
fp = fopen(argv[1], "r");
if (fp == NULL) return 1;
fp_out = fopen(argv[2], "w+b");
if (fp_out == NULL) {
fclose(fp);
return 1;
}
for(;;) {
lp = fgets(line_buf, LINE_MAX, fp);
if (lp == NULL) goto main_exit;
if (*lp++ == '0' && *lp++ == 'x' && strlen(lp) >= 8) {
aa = my_asc2hex(*lp++, *lp++);
bb = my_asc2hex(*lp++, *lp++);
cc = my_asc2hex(*lp++, *lp++);
dd = my_asc2hex(*lp++, *lp++);
fwrite(&dd, 1, sizeof(char), fp_out);
fwrite(&cc, 1, sizeof(char), fp_out);
fwrite(&bb, 1, sizeof(char), fp_out);
fwrite(&aa, 1, sizeof(char), fp_out);
}
}
main_exit:
fclose(fp);
fclose(fp_out);
return 0;
}
I just need to pay attention to the byte order, for example, if it is "0x00004F99" from the input, the output will be "99 4F 00 00". BUT the confusing part is here:
if (*lp++ == '0' && *lp++ == 'x'...)
....
my_asc2hex(*lp++, *lp++);
In "if" condition, the evaluating is one by one, the first item "evaluate" first, then is the next, while in function, the "evaluation" of parameters is, the last item first (put on the stack first), and moves on previous items. so that is why the first parameter to my_asc2hex is the latter one. kind of confusing using pointer!
Monday, April 21, 2008
sed programming - commands combination
Sed is a programming language, to me it basically contains two things, one is regexp, the other is the control commands such as "g G H h" which manipulate the hold buffer and pattern buffer. Sed only contains these two buffers, so it is simple. No more.
Although Sed itself is simple, programming with Sed can be complicated. This is like playing chess, to know the rule of each play does not mean you know how to play. You need to know at least some combinations.
Combination of "G h d". Here is an example "1!G;h;$!d" which REVERSE a list of items, typically 3 states control, at start it is "h d", then the second state which can be looped, which is "G h d", and the third state is "G h". Explanation is quite not hard to understand, the hold buffer was used to save the result, so for the first item, it hold it and delete current pattern, for the second, add "\n' on current buffer and append current buffer with the content in hold buffer, save current buffer to hold buffer, so the second item will be ahead of the first item in the hold buffer. it do the same for third, fourth, etc. until the last item, is just "G h", with out "d" means it did not delete current buffer, so at last the current buffer contains the reverse list of items. (My opinion, the last 'h' is not necessary since hold buffer is only for assistant use)
"x;x" combination. A second example:
The five line script find the content of a XML "example" tag. It need a little time to figure out how it works, this script is not using b and n command, remember it and use it in some cases. A altered way may be easy to understand, here the hold buffer contains the content of the example tag.
Here is some of my thought,
1. "n" is alway used "p", thus with "sed -n". And if you use "p", then "p" is always connect with with "d", you don't do "b end" since "d" itself restart a new cycle, -- read a next line to current buffer.
2. using branch is easy to understand the flow, but in some case, the "x;x" command combination can also be considered.
Other thoughts:
3. eol : Use "sed -e 's/\r//' your_file" to convert line ending "dos to unix".
Although Sed itself is simple, programming with Sed can be complicated. This is like playing chess, to know the rule of each play does not mean you know how to play. You need to know at least some combinations.
Combination of "G h d". Here is an example "1!G;h;$!d" which REVERSE a list of items, typically 3 states control, at start it is "h d", then the second state which can be looped, which is "G h d", and the third state is "G h". Explanation is quite not hard to understand, the hold buffer was used to save the result, so for the first item, it hold it and delete current pattern, for the second, add "\n' on current buffer and append current buffer with the content in hold buffer, save current buffer to hold buffer, so the second item will be ahead of the first item in the hold buffer. it do the same for third, fourth, etc. until the last item, is just "G h", with out "d" means it did not delete current buffer, so at last the current buffer contains the reverse list of items. (My opinion, the last 'h' is not necessary since hold buffer is only for assistant use)
"x;x" combination. A second example:
/^<\example>/ { h; }
x
/^< example>/ { x; p; d;}
x
/^< example>/ {h;}
The five line script find the content of a XML "example" tag. It need a little time to figure out how it works, this script is not using b and n command, remember it and use it in some cases. A altered way may be easy to understand, here the hold buffer contains the content of the example tag.
/^< example>/ {
h
: example-loop
n
/^<\/example>/! {
H
b example-loop
}
x
p
d
}
Here is some of my thought,
1. "n" is alway used "p", thus with "sed -n". And if you use "p", then "p" is always connect with with "d", you don't do "b end" since "d" itself restart a new cycle, -- read a next line to current buffer.
2. using branch is easy to understand the flow, but in some case, the "x;x" command combination can also be considered.
Other thoughts:
3. eol : Use "sed -e 's/\r//' your_file" to convert line ending "dos to unix".
Thursday, April 10, 2008
some newsgroup readers
1. Outlook Express. This is the traditional news reader, it works fine on Windows, you never have any problems with it.
2. Pan. This is based on gtk, it is almost as great as Outlook Express, but it need tough build on Mac OS X.
3. slrn. Should we read news on a terminal? maybe that's the one. Terminal can have a lot of brilliant applications, but not do a good job on web browsing, news reading.
4. MT-NewsWatcher. It is free, but it is NOT in a good shape with GUI.
5. Unison. Just download it and get it a try, which is brilliant! It tell me what news server from my ISP I can use, great work! And I have no trouble to startup, love it.
Ususally I would try Pan, because it is free and it can be used on all platforms, just like firefox. And I am not willing to pay a comercial newsreader, such basic tool should be free, but I am considering buy Unison.
2. Pan. This is based on gtk, it is almost as great as Outlook Express, but it need tough build on Mac OS X.
3. slrn. Should we read news on a terminal? maybe that's the one. Terminal can have a lot of brilliant applications, but not do a good job on web browsing, news reading.
4. MT-NewsWatcher. It is free, but it is NOT in a good shape with GUI.
5. Unison. Just download it and get it a try, which is brilliant! It tell me what news server from my ISP I can use, great work! And I have no trouble to startup, love it.
Ususally I would try Pan, because it is free and it can be used on all platforms, just like firefox. And I am not willing to pay a comercial newsreader, such basic tool should be free, but I am considering buy Unison.
Wednesday, March 19, 2008
Understanding Digital Signal Processing - by Richard Lyons
There are a lot of praise on this DSP book, the following is a typical one from Amazon.com:
"We need this Richard Lyons guy in other fields!!"
I got this book 2 days ago, and just read a few chapters, it is really a wonderful study journey presented by Lyons. In my work, I was exposed to the audio processing area, and I feel I have trouble to understand dsp filters... The hard thing on DSP is the DFT or FFT which contains a lot of math, while I only study it at College that was 13 years ago, another difficulty is English is my second language, I have never use a English math book for study; Third, DSP area and math are different, for example "i" is used in math to express the root of -1, while in DSP it uses "j", (Thanks to Steve Smith's online dsp book tell me the difference)
I enjoy reading some classic books, Lyon's book should be one of them, what the book contains is like a great teacher, not feed you the knowledge, but guide you to understand it, this book acts like this!
Other books on DSP, one is jos, this book is quite fit to my area, but I would not choose it, because I am not in the college to spend that time. The other wonderful online book is by Steve Smith, this book is quite interesting, it choose not to expose the mathematics way, so you will not be overwelmed by the equation. But I still think Lyon's approach is the best, avoid math may be ok, but equation can also be a good role, be clean if you understand it.
"We need this Richard Lyons guy in other fields!!"
The last mathematics course I took was Calulus 3 during my senior year in high school... I graduated in 1991. That was my last exposure to mathematics. My undergrad was in biochemistry (no math) and after that I went to medical school (no math). I started my residency in neurology and I became interested in analyzing EEG brain waves. Unfortunately, most work in this field is done in collaboration with engineers, since us docs have minimal knowledge of mathematics and data analysis. I stumbled upon Lyons's book at Borders and decided to give it a shot. Voila!! No more engineers needed!! I now understand sufficiently the concepts of periodic sampling, the Fourier stuff, filters, signal averaging, etc. all the way down to the simple sums of products that they are. Lyons motivated me so much that I picked up Dietel and Dietel's C++ book and now... a month later... I develop my own software to anaylize these EEG signals.
This may not seem as a big deal to the mathematician or engineer... but you have to remember that I'm a neurologist with no math exposure since high school!! If I can learn digital signal processing through Lyons's book... anyone can.
Congratulations, Richard G. Lyons... I wish you would write something on time-series predictions.
I got this book 2 days ago, and just read a few chapters, it is really a wonderful study journey presented by Lyons. In my work, I was exposed to the audio processing area, and I feel I have trouble to understand dsp filters... The hard thing on DSP is the DFT or FFT which contains a lot of math, while I only study it at College that was 13 years ago, another difficulty is English is my second language, I have never use a English math book for study; Third, DSP area and math are different, for example "i" is used in math to express the root of -1, while in DSP it uses "j", (Thanks to Steve Smith's online dsp book tell me the difference)
I enjoy reading some classic books, Lyon's book should be one of them, what the book contains is like a great teacher, not feed you the knowledge, but guide you to understand it, this book acts like this!
Other books on DSP, one is jos, this book is quite fit to my area, but I would not choose it, because I am not in the college to spend that time. The other wonderful online book is by Steve Smith, this book is quite interesting, it choose not to expose the mathematics way, so you will not be overwelmed by the equation. But I still think Lyon's approach is the best, avoid math may be ok, but equation can also be a good role, be clean if you understand it.
Wednesday, February 27, 2008
Use markdown to build - foyep.org
After 15 days, it seems I build nothing on the website, but I have something to talk. My most concern is I have to use a powerful editor such as vim which will make changes on pages more easily and more controllable.
Markdown: Basically it is two things. One, a light-markup language, the syntax is similar to emacs-wiki I have used to write notes before, and I can use the language in vim to write pages. Second, a perl software tool to convert the written markdown to html.
Markup RW plugin: It is a Rapidweaver plugin, it support markdown language, thus I can use markdown in Rapidweaver, also the plugin contains a bash interface, which could be most meaningful to me -- a programmer.
Blocks: fromPaul,it seems that Blocks is a must have plugin with rapidweaver. The price is an issue, compared to RW (36CAD with coupon), it costs 26CAD, is it valuable to spent for just a plugin. Right now, I think it is worth after I bought it online, it provides me a simple way to design my website as I am not a designer, so I feel great although I need to figure out the usage such as use page blocks, html blocks or align images, etc. One good thing to me is Blocks works with the markup plugin. It is obviously that markdown can be used in blocks.
webyep: NOT choosed as a result.
PlusKit: it supports Markdown and bash, but I have difficulty to use it with blocks, don't know why.
accordion: Anthor beautiful plugin from yourhead, I see some nice samples but not got a chance to try, would like to investe the use with it.
Markdown: Basically it is two things. One, a light-markup language, the syntax is similar to emacs-wiki I have used to write notes before, and I can use the language in vim to write pages. Second, a perl software tool to convert the written markdown to html.
Markup RW plugin: It is a Rapidweaver plugin, it support markdown language, thus I can use markdown in Rapidweaver, also the plugin contains a bash interface, which could be most meaningful to me -- a programmer.
Blocks: fromPaul,it seems that Blocks is a must have plugin with rapidweaver. The price is an issue, compared to RW (36CAD with coupon), it costs 26CAD, is it valuable to spent for just a plugin. Right now, I think it is worth after I bought it online, it provides me a simple way to design my website as I am not a designer, so I feel great although I need to figure out the usage such as use page blocks, html blocks or align images, etc. One good thing to me is Blocks works with the markup plugin. It is obviously that markdown can be used in blocks.
webyep: NOT choosed as a result.
PlusKit: it supports Markdown and bash, but I have difficulty to use it with blocks, don't know why.
accordion: Anthor beautiful plugin from yourhead, I see some nice samples but not got a chance to try, would like to investe the use with it.
Wednesday, February 20, 2008
setup a website - foyep.org
I spent a whole night to setup a new website, I feel I need to create a site on Buddhism (in Chinese). To register and setup my host account with Godaddy is so efficient, they are doing a great job.
RapidWeaver - I have fiddling it for a little while, liked or dis-liked, but it should be a top 10 Mac application. I used it to create and weave my pages and publish to my website, it also includes some nice and clean themes. The forum of RapidWeaver is quite good.
Ralf Simple Theme - A quite nice theme I choose when I don't want to use the default themes from RW.
webyep - I may feel sad with RW until I found the Webyep plugin, I have never imagen to use CMS but I like the idea, especially when I found it is developed by the guys who bring LaunchBar, while LaunchBar is so impressive to me and it is my #1 Mac Application.
Still need learning to fill the gap, but here is my website, still in construction.
RapidWeaver - I have fiddling it for a little while, liked or dis-liked, but it should be a top 10 Mac application. I used it to create and weave my pages and publish to my website, it also includes some nice and clean themes. The forum of RapidWeaver is quite good.
Ralf Simple Theme - A quite nice theme I choose when I don't want to use the default themes from RW.
webyep - I may feel sad with RW until I found the Webyep plugin, I have never imagen to use CMS but I like the idea, especially when I found it is developed by the guys who bring LaunchBar, while LaunchBar is so impressive to me and it is my #1 Mac Application.
Still need learning to fill the gap, but here is my website, still in construction.
Thursday, January 31, 2008
Install Gentoo VM on Macbook -1
I use Minimum CD, the installation is more hard than using a liveCD, so I failed a bunch of times. And as my learning, I started installation with stage3, so I don't need to catch stage1 and stage2, but even stage3, is a lot to me. Every time with Minimum CD, I have to get stage3 and portage, so at last I save them to another machine that I can easily get with ssh.
0 startup with Minimum CD
vmware: other linux 2.6.x
connected: NAT
1 check network
- ifconfig => eth0
- dhcpcd => some times need it if eth0 did not show ip address
- ssh => connect with my file server where I save stage3 and portage etc.
/etc/init.d/sshd start
ssh 192.168.0.104
2 prepare disks...
- fdisk /dev/sda
=> /dev/sda1 for boot
=> /dev/sda2 for swap
=> /dev/sda3 for / (the root)
mkfs.ext2 /dev/sda1
mkfs.ext3 /dev/sda3
mkswap /dev/sda2
swapon /dev/sda2
mount /dev/sda3 /mnt/gentoo
mkdir /mnt/gentoo/boot
mount /dev/sda1 /mnt/gentoo/boot
3 install stage3 and portage
scp -p -r 192.168.0.104:/root/gentoo .
cd /mnt/gentoo
tar xjpf stage3-<>.tar.bz2
tar xjf portage-<>.tar.bz2 -C /mnt/gentoo/usr
4. env setup
vi /mnt/gentoo/etc/make.conf
CFLAGS as "-O2 -march=prescott -fomit-frame-pointer -pipe"
mirrorselect -i -o >> /mnt/gentoo/etc/make.conf
cp -L /etc/resolv.conf /mnt/gentoo/etc
mount -t proc none /mnt/gentoo/proc
mount -o bind /dev /mnt/gentoo/dev
chroot /mnt/gentoo /bin/bash
env-update
source /etc/profile
export PS1="{chroot} $PS1"
5. emerge -sync --quiet
emerge vim lilo subversion
6. vi /etc/fstab
7. network
vi /etc/conf.d/hostname => "gentoovm"
vi /etc/conf.d/net => for dhcp: config_eth0="dhcp", but i did not set.
rc-update add net.eth0 default => boot eth0 as default
emerge dhcpcd => MUST
vi /etc/hosts
=> 127.0.0.1 gentoovm.homenetwork gentoovm localhost
8. System
passwd => MUST
useradd
emerge syslog-ng vixie-cron
rc-update add syslog-ng default
rc-update add vixie-cron default
9. lilo
vi /etc/lilo.conf
prepare the default kernel (from ssh) and save to /boot
/sbin/lilo
10 reboot
Friday, January 18, 2008
xwd : capture window on linux
Wednesday, January 16, 2008
gcc - shared library
When I link the shared library in dynamic mode on FC5 (Fedoral Core 5), I got a failure when run my executables: "cannot restore segment prot after reloc: Permission denied", is it only happend on FC5?
Here is the solution:
# make compile
/opt/crosstool/i686-unknown-linux-gnu/gcc-3.4.1-glibc-2.3.3/bin/i686-unknown-linux-gnu-g++ -x c++ -c -Wall -Wno-unknown-pragmas -fno-common -fbounds-check -pipe -g -Wno-deprecated -pipe -o foo.o foo.cpp
/opt/crosstool/i686-unknown-linux-gnu/gcc-3.4.1-glibc-2.3.3/bin/i686-unknown-linux-gnu-g++ -shared -o libfoo.so foo.o -lc
/opt/crosstool/i686-unknown-linux-gnu/gcc-3.4.1-glibc-2.3.3/bin/i686-unknown-linux-gnu-ar -rcs libfoo.a foo.o
/opt/crosstool/i686-unknown-linux-gnu/gcc-3.4.1-glibc-2.3.3/bin/i686-unknown-linux-gnu-g++ -x c++ -c -Wall -Wno-unknown-pragmas -fno-common -fbounds-check -pipe -g -Wno-deprecated -pipe -o test.o test.cpp
/opt/crosstool/i686-unknown-linux-gnu/gcc-3.4.1-glibc-2.3.3/bin/i686-unknown-linux-gnu-g++ -dynamic -L. -lfoo -o test test.o
/opt/crosstool/i686-unknown-linux-gnu/gcc-3.4.1-glibc-2.3.3/bin/i686-unknown-linux-gnu-g++ -static -L. -lfoo -o test.static test.o libfoo.a
# ./test
./test: error while loading shared libraries: ./libfoo.so: cannot restore segment prot after reloc: Permission d[...]
Here is the solution:
# chcon -t textrel_shlib_t ./libfoo.so
Wednesday, January 9, 2008
version controls with cvs
0. I have a simple script to set my working CVSROOT. So when I work on it. I just run the script.
Here is cvs.sh script.(which is just 2 lines)
1. Create a branch with tag.
To create a branch, you first need to check out the source code. here FOO is the module name and foo is the checkout directory.
2. Work on a branch.
3. Merge from a branch
It will merge the branch to where you currently work on (can be main trunk or a branch)
4. Commit your changes
When you merge the code from a branch, it does not commit yet, so you need to commit it.
5. To delete a branch tag. (THIS SHOULD BE VERY CAREFUL!)
. cvs.sh
Here is cvs.sh script.(which is just 2 lines)
#! /bin/sh
export CVSROOT=":pserver:user:192.168.10.7:2401/home/repository"
1. Create a branch with tag.
cvs co -P -d foo FOO
cvs tag -b z_markc_unknown
To create a branch, you first need to check out the source code. here FOO is the module name and foo is the checkout directory.
2. Work on a branch.
cvs co -P -d foo -r z_markc_unknown FOO
3. Merge from a branch
cd foo
cvs update -j z_markc_1
It will merge the branch to where you currently work on (can be main trunk or a branch)
4. Commit your changes
cvs update
cvs diff Makefile
cvs commit Makefile
When you merge the code from a branch, it does not commit yet, so you need to commit it.
5. To delete a branch tag. (THIS SHOULD BE VERY CAREFUL!)
cd foo
cvs tag -dB z_markc_1
Tuesday, January 8, 2008
Work on iPAQ 5550 PocketPC
Use the COM port to connect with PC. On Windows, HyperTerminal is perfact for the connection. In most time, it is desire to work on Linux, here is the way to connect througth ssh on my Linux Host:
you need to get the ip address, user name and password to enter into the system.
To find out the ip address, you can start the terminal in iPAQ (GPE installed), and type ifconfig.
Copy files forth and back with scp on Linux Host:
Right now my iPAQ's ip address is connected to the wireless network, and is associated with an external ip address (NOT 192*), so it can not ping my internel network, but the linux host can ping the external ip address. That is why scp works.
ssh root@192.168.10.177
you need to get the ip address, user name and password to enter into the system.
To find out the ip address, you can start the terminal in iPAQ (GPE installed), and type ifconfig.
Copy files forth and back with scp on Linux Host:
scp foo root@192.168.10.177:/home/root
scp -p -r root@192.168.10.177:/home/root/foo foo
Right now my iPAQ's ip address is connected to the wireless network, and is associated with an external ip address (NOT 192*), so it can not ping my internel network, but the linux host can ping the external ip address. That is why scp works.
Sunday, January 6, 2008
slckware 12.0 - install Bitstream Vera Fonts
1. Download the font package from here.
Extract it
2. Copy the font to ~/.fonts
Now it's ready to use! just open gvim and select the font.
Extract it
cd /tmp
tar xjf ~/Desktop/ttf-bitstream-vera-1.10.tar.bz2
2. Copy the font to ~/.fonts
cp -r ttf-bitstream-vera-vera-1.10 ~/.fonts
fc-cache -f -v ~/.fonts
xset fp rehash
Now it's ready to use! just open gvim and select the font.
Subscribe to:
Posts (Atom)