Tuesday, November 24, 2009

use glib

1. install glib

$ apt-get install libglib2.0-dev


2. write source code to print "hello world!"

#include
int main(int argc, char** argv)
{
g_printf("hello world!\n");
}


3. compile

gcc `pkg-config --libs --cflags glib-2.0` hello.c

Tuesday, September 22, 2009

find/grep command

The following command searches C/C++ source code to find the content of "equalizer".

$ find ~/myspace/git/opencore -type f -name "*.[ch] -o -name "*.cpp" -exec grep -I "equalizer" {} \; -print

Tuesday, September 15, 2009

ubuntu - recording


I use "alsamixer -c 0" to set up my recording with microphone.

Thursday, August 20, 2009

ubuntu 8.04 - wireless network setup

I spent less than 9 hours to setup my wireless card on ubuntu. When use "lspci" command, I get the name of my wireless card, which is "AR2413 802.11bg".

Here is the brief.

1. disable the Atheros proprietary drivers from "system->adminstrator->hardware drivers"
2. unplug the wired ethernet line

3. extract ndiswrapper-1.55.tar.gz, and make & sudo make install

4. extract madwifi-hal-0.10.5.6-r3835-20080801.tar.gz, make & sudo make install

5. extract Wireless_Atheros.zip, use ndisgtk to install the net5211.inf
or
$ sudo ndiswrapper -a XXXX:YYYY ath0 (here XXXX:YYYY is get from lspci -n for Atheros card)

6. setup
add ndiswrapper at the end of /etc/modprobe.d/blacklist
add ath_pci at the end of /etc/modules

$ sudo iwconfig
$ sudo lshw -C network
$ iwlist scan (to find my wireless network)
$ sudo network-admin (which should setup wireless network)

check the following configuration at /etc/network/interfaces
=======================
iface ath0 inet dhcp
wireless-key XXXX
wireless-essid fade

auto ath0
=======================
Here XXXX is my wep password.
call "/etc/init.d/networking restart" to restart


I also installed wpa_supplicant but it does not seem to be needed.

After I reboot the OS, I found the system could not find ath0, so what I did is "sudo modprobe wlan_scan_sta" and reboot again, this time ath0 appears.

Monday, June 22, 2009

fedora 10 - setup i686 environment for android (1)

0. install git ($ sudo yum install git)
1. Download JDK 5.0 (jdk-1_5_0_19-linux-i586-rpm.bin) from sun

$ cd /usr/local
$ /tmp/jdk-1_5_0_19-linux-i586.bin
$ sudo updatedb
$ locate javac | grep bin
/usr/local/jdk1.5.0_19/bin/javac (the result)
$ sudo /usr/sbin/alternatives --install /usr/bin/java java /usr/local/jdk1.5.0_19/bin/java 100
$ sudo /usr/sbin/alternatives --install /usr/bin/jar jar /usr/local/jdk1.5.0_19/bin/jar 100
$ sudo /usr/sbin/alternatives --install /usr/bin/javac javac /usr/local/jdk1.5.0_19/bin/javac 100
$ sudo /usr/sbin/alternatives --config java


2 Play with curl

$ cd ~/bin (make sure ~/bin is in $PATH)
$ curl http:/android.git.kernel.org/repo > ~/bin/repo
$ chmod a+x ~/bin/repo
$ cd ~/myspace/mydroid
$ repo init -u git://android.git.kernel.org/platform/manifest.git -b cupcake
$ repo sync

Wednesday, June 10, 2009

mips - the next example

This example access an array which is a block of buffer.

/* bar initialize input (or 3 to each element)
*/
int bar(int* in, int n)
{
int ret;
__asm__(
".set push \n" // save assembler option
".set noreorder\n" // suppress reordering
"lw $9, %2 \n" // $9 = n (counter end)
"li $8, 0 \n" // $8 = 0
"li $12, 0 \n" // $12 = 0
"move $4, %1\n" // $4 = in
"loop: \n"
"lw $11, ($4) \n" // $11 = *in
"ori $11, $11, 3 \n" // $11 = $11 || 3
"sw $11, ($4) \n" // *in = $11
"addi $4, $4, 4 \n" // in++ (move to next addess)
"addi $8, $8, 1 \n" // move to next sample
"bne $8, $9, loop \n" // loop
"sw $11, %0 \n" // save $12 to ret
".set pop \n" // restore assembler option
: "=m" (ret) // to return
: "r" (in),"m" (n) // the input
);
return ret;
}


Here the use of $8 is not the best, because the move the array element is by $4, soe the $8 is not most necessary, because $4 can be used to check the range for the loop.

Tuesday, June 9, 2009

mips - a first example

In the following sample, it shows how to send the input (val) and the output (ret) to assembly block.


/* foo returns (val | 3)
*/
int foo(int val)
{
int ret;
__asm__(
".set push\n" // save assembler option
".set noreorder\n" // suppress reordering
"ori $2, %1, %2\n"
"sw $2, %0\n" // save $2 to ret
".set pop\n" // pop assembler option
: "=m" (ret) // ret: memory
: "r" (val), "n" (3) // val: read-only register, n: number
);
return ret;
}



The real code by dump is:

08804554 :
8804554: 27bdffd0 addiu sp,sp,-48
8804558: afbe0020 sw s8,32(sp)
880455c: 03a0f021 move s8,sp
8804560: afc40010 sw a0,16(s8)
8804564: 8fc20010 lw v0,16(s8)
8804568: 34420003 ori v0,v0,0x3
880456c: afc20000 sw v0,0(s8)
8804570: 8fc20000 lw v0,0(s8)
8804574: 03c0e821 move sp,s8
8804578: 8fbe0020 lw s8,32(sp)
880457c: 27bd0030 addiu sp,sp,48
8804580: 03e00008 jr ra
8804584: 00000000 nop

Wednesday, May 27, 2009

android notes - the process of development

0 installation and setup
1 create a project

$ android create project --target 1 --path ./demo --activity demo --package com.example.demo

2 edit source code ~/myspace/demo/src/example/demo/demo.java
3 compile with ant

$ ant -debug -verbose

4 run emulator with a script

#! /bin/sh
out/host/linux-x86/bin/emulator -verbose \
-kernel prebuild/android-arm/kernel/kernel-qemu \
-ramdisk out/target/product/generic/ramdisk.img \
-system out/target/product/generic/system.img \
-init-data out/target/product/generic/userdata.img \
-avd myavd -sdcard ./sdcard.img -no-skin -no-boot-anim

5 install the application we have build

$ cd ~/myspace/demo
$ adb install bin/demo-debug.apk
$ adb install -r bin/demo-debug.apk (for reinstall)
$ adb shell
# logcat
# ps a (to get process id to kill)
# kill -9



That's on java side, on the android side,
1 setup

$ cd ~/myspace/mydroid
$ source ./build/envsetup.sh
$ lunch 1

2 build the project in android

$ cd ./frames/base/media/libmediaplayerservice
$ mm (it builds libmediaplayerservice library as an example)
$ cd ~/myspace/mydroid (go back to the root)
$ make snod (build the system image

then you can go back to run emulator with parameters specified in the script.

Wednesday, May 20, 2009

Calculate cpu usage in MCycles/sec

Here is the script to calculate cpu usage in MCycles per second.
The cpu speed is 222MHz as an example, processing data rate is 44100, each block has 8192 samples, and the total calls to foo is 532.

#!/bin/bash

rate=44100
blksize=8192
cpu=222
call=532

# the following val is got from gprof as percentage cpu time, 30.11%.
pcpu_foo=30.11

duration=`echo "scale=4; $blksize * $call / $rate" | bc`
echo "duration: " $duration

secs_foo=`echo "scale=4; $duration * $pcpu_foo /100" | bc`
echo "secs_foo " $secs_foo

blksecs_foo=`echo "scale=4; $secs_foo/$call"|bc`
echo "blocksecs_foo" $blksecs_foo

cpu_foo=`echo "scale=4; $cpu * $rate / $blksize * $blksecs_foo"|bc`
echo "cpu_foo " $cpu_foo " MCycle/sec"

Wednesday, May 13, 2009

u8.04 - build procmeter3

At last, I left Fedora Core 5 which I have used for these 2 years and move to Ubuntu. I am now running Ubuntu 8.04 which is not a very latest version, but at least it is newer than FC5.

But by default to build procmeter3, it prompts "X11/Intristic.h is missing". I have to install the following packages:

$ sudo apt-get install libxt-dev libxaw-headers libxaw7-dev
$ make
$ sudo make install

Thursday, May 7, 2009

android notes - build and test shared library

1. download system.tar.gz from benno and extract it to ~/myspace/tmp.
2. make a link.

cd ~/myspace/tmp/system/lib
ln -s libc.so libc.so.6

Is it necessary? but it fixed the problem to looking for libc.so.6.
3. Here is the Makefile.

CC=arm-none-linux-gnueabi-gcc
LD=arm-none-linux-gnueabi-ld
AR=arm-none-linux-gnueabi-ar
LD_OPTS= --entry=_start \
--dynamic-linker /system/bin/linker -nostdlib \
-rpath /system/lib -rpath ~/myspace/tmp/system/lib \
-L ~/myspace/tmp/system/lib -L .
foo2.a : foo2.c
$(CC) -g -fpic -c foo2.c
$(CC) -g -shared -nostdlib -o libfoo2.so foo2.o
$(AR) -rcs $@ foo2.o
foo2: main.c start.c foo2.a
$(CC) -g -c main.c
$(CC) -g -c start.c
$(LD) $(LD_OPTS) -lc -lfoo2 -o foo2 main.o start.o



when build the library, should set "-nostdlib"

4. run the commands

$ make foo2
$ adb push libfoo2.so /data
$ adb push foo2 /data
$ adb shell
# cd data
# ./trace ./foo2

Thursday, April 30, 2009

ubuntu notes - connect to nfs share folder

I have installed ubuntu 8.04, here is the command to connect to nfs share folder of my FC5.
sudo apt-get install portmap nfs-common
sudo /etc/init.d/portmap restart
sudo /etc/init.d/nfs-common restart
sudo mount -t nfs 192.168.0.9:/tftpboot /mnt -o nolock

Wednesday, April 29, 2009

android notes

To develop on android, I need open four consoles at least:
1. one console to show the log -- ``$ adb logcat''.
2. one console to run the emulator -- ``$ emulator -sdcard sd.img -avd qslavd''.
3. A third console to build the source code, and install the package:

$ ant debug
$ adb install -r .\bin\foo-debug.apk
$ adb push your\file /sdcard

4. A vim gui/console to edit source code

Monday, April 27, 2009

chown and chgrp

When use ``ls -l'' command it shows the owner and group of the directory.

markc@ubuntu-vm:/opt $ls -la
total 16
drwxr-xr-x 4 root root 4096 2009-04-27 11:04 .
drwxr-xr-x 25 root root 4096 2009-02-18 11:04 ..
drwxr-xr-x 7 root root 4096 2008-08-08 11:04 alp-dev
drwxr-xr-x 2 markc markc 4096 2009-04-27 11:04 work
^ ^
| |
chown chgrp


Here is the command (so I don't have to google it again) to change the directory "work"'s owner and group.


$ sudo chown markc work
$ sudo chgrp markc work

Thursday, April 2, 2009

fedora 10 - remove pulseaudio

The only problem with Fedora 10 I have is I have to remove pulseaudio, I am not sure when I installed it, but it cause the player no sound.

$ sudo yum remove pulseaudio

Tuesday, March 24, 2009

setup cygwin

Not fun, but have to make cygwin work.
1. Here is the batch file to start cygwin.

@echo off

SET MAKE_MODE=UNIX
SET PATH=D:\disk\cygwin\bin;%PAtH%
SET HOME=D:\disk\markc
SET CYGWIN=tty binmode
D:
chdir %HOME%
bash


2. A no special .bash_profile in $(HOME).

# source the system wide bashrc if it exists
if [ -e /etc/bash.bashrc ] ; then
source /etc/bash.bashrc
fi

# source the users bashrc if it exists
if [ -e "${HOME}/.bashrc" ] ; then
source "${HOME}/.bashrc"
fi



3. Now, my .bashrc file.

export PATH=/usr/bin:/sbin:/usr/local/bin
export PATH=/usr/local/psp/gcc-2.8.2/bin:$PATH
export PATH=/usr/local/psp/devkit/bin:$PATH:.
export PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$ '


The problem I have is '\r' cause the problem to start cygwin. To make cygwin happy with unix file format, we need set the unix file format in vimrc. The following code is my vimrc.

set autoindent
set softtabstop=4
set tabstop=4
set shiftwidth=4
set showmatch
set ignorecase
set background=dark
set hlsearch
set incsearch
set number
syntax on
set fileformats=unix,dos
set fileformat=unix

Monday, March 23, 2009

generate ssh key for github

It looks to me that github is a good place to host open source. Also git is aimed to replace svn, so I would move to git from svn. (currently googlecode is with svn).


$ git config --global user.name "foo"
$ git config --global user.email "foo@gmail.com"
$ cd sur
$ git init
$ git add sur.w %my source code
$ git commit -m "first commit"
$ git remote add origin git@github.com:dsmarkchen/sur.git
$ git push origin master

I got permission denied error message. It is not very hard for me to figure it out.

1. try to connect to github by ssh (it helps to know the problem)

ssh -v git@github.com


2. generate the public key

$ cd ~/.ssh
$ ssh-keygen -t rsa


3. Add the the content of id_rsa.pub to github, then I am ready to see
the magic.

Friday, January 30, 2009

boilerplate

When I read a blog about boilerplate in Qt, I tried to remember how to write boilerplate code with Gobject. The following code is a frame that I took from 1 year ago I wrote. It is not really hard to understand or write, just need to copy & paste, or use simple tool to auto generate the code. It always need to write more lines in C (GObject) than using C++ for OO. But I don't feel the goodness. I am not feel that is the benifit of C, so I am not sure OO is really good for a Unix developer, so if I can avoid I would avoid the idea of OO in unix platform. (Linux Kernel is not written in OO)


/* macros*/
G_BEGIN_DECLS

#define GST_TYPE_MIDISRC (gst_my_midisrc_get_type())
#define GST_MIDISRC(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_MIDISRC,GstMidisrc))
#define GST_MIDISRC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_MIDISRC,GstMidisrcClass))
#define GST_IS_MIDISRC(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_MIDISRC))
#define GST_IS_MIDISRC_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_MIDISRC))

/* standard function returning type information */
GType gst_my_midisrc_get_type (void);


/* definition a class of this element */
typedef struct _GstMidisrc GstMidisrc;
struct _GstMidisrc
{
GstBaseSrc parent;
[...]
};

typedef struct _GstMidisrcClass GstMidisrcClass;

struct _GstMidisrcClass
{
GstBaseSrcClass parent_class;
};

G_END_DECLS


Now we can make the boilerplate:

GST_BOILERPLATE (GstMidisrc, gst_my_midisrc, GstBaseSrc, GST_TYPE_BASE_SRC);


After that is the element details.


static GstElementDetails midisrc_details = {
"A Gstreamer Plug-in",
"Src/Audio",
"audio src for GStreamer Plug-in",
""
};

/* set detail with _base_init function when register the plugin */
static void
gst_my_midisrc_base_init (gpointer klass)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);

gst_element_class_add_pad_template (element_class, gst_static_pad_template_get (&src_factory));

gst_element_class_set_details (element_class, &midisrc_details);

}


Then implementation:



/* create the class, here we define which function need to be re-implmented from the base class, and add property for the class */
static void
gst_my_midisrc_class_init (GstMidisrcClass *klass)
{

GObjectClass *gobject_class;
GstBaseSrcClass *basesrc_class;
gobject_class = G_OBJECT_CLASS (klass);
basesrc_class = GST_BASE_SRC_CLASS (klass);
gobject_class->set_property = gst_midisrc_set_property;
gobject_class->get_property = gst_midisrc_get_property;


/* basesrc_class->get_caps = gst_midisrc_get_caps;
basesrc_class->set_caps = gst_midisrc_set_caps; */
basesrc_class->start = gst_midisrc_start;
basesrc_class->stop = gst_midisrc_stop;
basesrc_class->create = gst_midisrc_create;

/* install a property for the class as an example */
g_object_class_install_property (
gobject_class, ARG_LOCATION,
g_param_spec_string ("location", "File Location",
"Location of the file to read", NULL, G_PARAM_READWRITE));



}

/* create the object */
static void
gst_my_midisrc_init (GstMidisrc *midisrc, GstMidisrcClass *klass)
{
[...]
}



Now the reset part:


/* set property sample */
static gboolean
gst_midisrc_set_location (GstMidisrc * src, const gchar * location)
{
/* the element must be stopped in order to do this */
GST_STATE_LOCK (src);
{
GstState state;

state = GST_STATE (src);
if (state != GST_STATE_READY && state != GST_STATE_NULL)
goto wrong_state;
}
GST_STATE_UNLOCK (src);

g_free (src->filename);
g_free (src->uri);

/* clear the filename if we get a NULL (is that possible?) */
if (location == NULL) {
src->filename = NULL;
src->uri = NULL;
} else {
src->filename = g_strdup (location);
}
return TRUE;

/* ERROR */
wrong_state:
{
GST_DEBUG_OBJECT (src, "setting location in wrong state");
GST_STATE_UNLOCK (src);
return FALSE;
}
}
static void
gst_midisrc_set_property (GObject * object,
guint prop_id, const GValue * value, GParamSpec * pspec)
{
GstMidisrc *midisrc;
int tmp = 0;
g_return_if_fail (GST_IS_MIDISRC (object));
midisrc = GST_MIDISRC (object);

switch (prop_id) {
case ARG_LOCATION:
gst_midisrc_set_location(midisrc, g_value_get_string (value));
printf("set location done!\n");
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}

static void
gst_midisrc_get_property (GObject * object,
guint prop_id, GValue * value, GParamSpec * pspec)
{
GstMidisrc *midisrc;

g_return_if_fail (GST_IS_MIDISRC (object));
midisrc = GST_MIDISRC (object);

switch (prop_id) {
case ARG_LOCATION:
g_value_set_string(value, midisrc->filename);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}

static gboolean
gst_midisrc_start (GstBaseSrc * src)
{
GstMidisrc *midisrc = GST_MIDISRC (src);
[...]
}

static GstFlowReturn
gst_midisrc_create (GstBaseSrc * src,
guint64 offset,
guint length,
GstBuffer ** buffer)
{
GstMidisrc *midisrc = GST_MIDISRC (src);
if (midisrc->eos_reached)
return GST_FLOW_UNEXPECTED;
return( gst_midisrc_get_read (src, buffer));
}

static GstFlowReturn
gst_midisrc_get_read (GstBaseSrc * basesrc, GstBuffer ** buffer)
{
GstFlowReturn res;
GstMidisrc *midisrc = GST_MIDISRC (basesrc);
[...]

[...]
}


I would like to put my time on learning Git (I was heard git is written by a Unix kernal developer), for desktops, such as gnome or KDE I don't have a lot of interests, I may feel KDE is better since it is written in C++, but who knows.

Wednesday, January 21, 2009

smb4k on Ubuntu

smb4k does not work well on Ubuntu, but it is Ok with Fedora. When I try to mount my Windows share folder, I get this error:

smbmnt must be installed suid root for direct user mount.


I use google to know how to fix. Here is the command:

$ sudo chmod u+s `which smbmnt`
$ sudo chmod u+s `which smbumount`

Tuesday, January 20, 2009

create a patch with cvs

Here is the command from a Linux shell:

$ cvs diff -u8pN /path/foo > markc_20090120.patch

Monday, January 19, 2009

0 Usually I use this blog to take notes on computer programming, and there's not really my thoughts. I would change this style and use the blog to write more my thoughts.

1 Last Friday, my wife and I went to TD bank to sign our new house mortgage paper. Our new house mortgage is $1400 CAD/month, compared to our current town house $600CAD (mortgage) + $200 (condo fees). What a difference! Our current living is convenient, just not luxury. The community is not very good but at least safe. We will move to Kincore in the north west, is it really make a difference? But the pressure in finance is some thing that I started to feel, we currently use the money in three ways. First, the living cost (house mortgage & condo fees, cost for two cars, food & electricity & water & gas etc). Second, some money to my parents in China although they don't need it (the money just gave them some more security feelings). Third, money donated to the monastery or other charity. Now I am starting to think do I have enough money for donation or support my parents? we need to calculate to make the balance.

2 Last Sunday, I did not get up early to go to the monastery for the morning ceremony at 8:00. Instead, I stayed in the bed for resting --. And I decide not go to monastery the day. Now I feel that was a good decision. In the afternoon, we went to the zoo for several hours. The weather was very good with sun shine that we did not feel cold wind, the snow is melting. The boy was happy to see the animals again, and we had really a good time to stay as a family that all of us enjoyed. I think spending the time with family is somewhat better than going to the monastery chanting and bowing to the Buddha & Bodhisattva. The goal is to get rid of the hatred/greed/desire etc in mind no matter what methods to choose.

Thursday, January 15, 2009

Do you remember when?

As a programmer, I have passed my mid of thirties, so I can not be called "young" at this age. As a programmer, am I success or do I feel I was success? I am not quite sure, it is just a career that I've took for the past 13 years. 13 years, that's a long time, I don't have anything that I can be very pride of, (am I not talented or blessed) but I do have a lot of experience and programming skills. Now, I spend more my personal time on Buddhist meditation, I am more consider myself as a Buddhist than a programmer. But to be a programmer, I know I should spent some of my personal time on programming.

I am not cheer up as a programmer right now. The economy or the immigrant life is some reasons. But my attitude need to flesh up, and I need to do some replaning to take the charge of on my programming career.

I like the following video:


A programmer works on beauty of code.
A gymnast works on beauty of body.
A Buddhist works on beauty of mind.
All takes hard work!