Tuesday, October 21, 2008

GCC Options and GDB notes

gcc example.c [options]

-S - Compiles and stops. Output is assembler code (suffix .S).
-o [name] - Gives executable as 'name'.
-E - Preprocess source file only.
    Comments will be discared unless -C is also specified.
    Creates #line directives unless -P is also specified.
-M - The preprocessor outputs one make rule containing the object file name for that source file, a colon, and the names of all the included files,including those coming from -include or -imacros command line options.
-W - Print extra warning messages.
    -Wall print all warnings


Example:
cat > example.c << EOF
#include <stdio.h>
#include <string.h>

int main()
{
printf("Hello world");
}
EOF
#


GDB notes:

Compile C code with -g option and run 'gdb a.out'
In gdb prompt set the break point as 'break main' or any function.
To run 'run '
To watch the particular variable set 'watch ' and if the variable get modified then it will get notified
To see the local variables 'info local'
To proceed next line 'n or next'
list to display the source code

Wednesday, July 23, 2008

Intel hex code Format

The Intel hex record looks like:
:090160001204283119740280E236

Intel hex data record: ':nnaaaattddddddd...dcc'
where:
: == start of data record
nn == number of bytes in record in ascii hex
aaaa == address to load data record at in memory
tt == type of record; 00=data; 01=end of file
ddd...d == data bytes of record in ascii hex (two chars per byte)
cc == checksum of record

checksum is two's complement of eight bit sum of all data from 'nn'
to end of data '...d'
end of file record (00) has zero number of bytes

So the above record would be decoded as :

:090160001204283119740280E236
start of record :
length of record 09
address to store record at 0160
record type 00
actual data of record 1204283119740280E2
checksum of record 36

Wednesday, July 16, 2008

Find error number in C

Refer : http://www.xinotes.net/notes/note/1793/  for getsockopt case

/usr/include/asm/error.h

#ifndef _I386_ERRNO_H
#define _I386_ERRNO_H

#define EPERM 1 /* Operation not permitted */
#define ENOENT 2 /* No such file or directory */
#define ESRCH 3 /* No such process */
#define EINTR 4 /* Interrupted system call */
#define EIO 5 /* I/O error */
#define ENXIO 6 /* No such device or address */
#define E2BIG 7 /* Arg list too long */
#define ENOEXEC 8 /* Exec format error */
#define EBADF 9 /* Bad file number */
#define ECHILD 10 /* No child processes */
#define EAGAIN 11 /* Try again */
#define ENOMEM 12 /* Out of memory */
#define EACCES 13 /* Permission denied */
#define EFAULT 14 /* Bad address */
#define ENOTBLK 15 /* Block device required */
#define EBUSY 16 /* Device or resource busy */
#define EEXIST 17 /* File exists */
#define EXDEV 18 /* Cross-device link */
#define ENODEV 19 /* No such device */
#define ENOTDIR 20 /* Not a directory */
#define EISDIR 21 /* Is a directory */
#define EINVAL 22 /* Invalid argument */
#define ENFILE 23 /* File table overflow */
#define EMFILE 24 /* Too many open files */
#define ENOTTY 25 /* Not a typewriter */
#define ETXTBSY 26 /* Text file busy */
#define EFBIG 27 /* File too large */
#define ENOSPC 28 /* No space left on device */
#define ESPIPE 29 /* Illegal seek */
#define EROFS 30 /* Read-only file system */
#define EMLINK 31 /* Too many links */
#define EPIPE 32 /* Broken pipe */
#define EDOM 33 /* Math argument out of domain of func */
#define ERANGE 34 /* Math result not representable */
#define EDEADLK 35 /* Resource deadlock would occur */
#define ENAMETOOLONG 36 /* File name too long */
#define ENOLCK 37 /* No record locks available */
#define ENOSYS 38 /* Function not implemented */
#define ENOTEMPTY 39 /* Directory not empty */
#define ELOOP 40 /* Too many symbolic links encountered */
#define EWOULDBLOCK EAGAIN /* Operation would block */
#define ENOMSG 42 /* No message of desired type */
#define EIDRM 43 /* Identifier removed */
#define ECHRNG 44 /* Channel number out of range */
#define EL2NSYNC 45 /* Level 2 not synchronized */
#define EL3HLT 46 /* Level 3 halted */
#define EL3RST 47 /* Level 3 reset */
#define ELNRNG 48 /* Link number out of range */
#define EUNATCH 49 /* Protocol driver not attached */
#define ENOCSI 50 /* No CSI structure available */
#define EL2HLT 51 /* Level 2 halted */
#define EBADE 52 /* Invalid exchange */
#define EBADR 53 /* Invalid request descriptor */
#define EXFULL 54 /* Exchange full */
#define ENOANO 55 /* No anode */
#define EBADRQC 56 /* Invalid request code */
#define EBADSLT 57 /* Invalid slot */

#define EDEADLOCK EDEADLK

#define EBFONT 59 /* Bad font file format */
#define ENOSTR 60 /* Device not a stream */
#define ENODATA 61 /* No data available */
#define ETIME 62 /* Timer expired */
#define ENOSR 63 /* Out of streams resources */
#define ENONET 64 /* Machine is not on the network */
#define ENOPKG 65 /* Package not installed */
#define EREMOTE 66 /* Object is remote */
#define ENOLINK 67 /* Link has been severed */
#define EADV 68 /* Advertise error */
#define ESRMNT 69 /* Srmount error */
#define ECOMM 70 /* Communication error on send */
#define EPROTO 71 /* Protocol error */
#define EMULTIHOP 72 /* Multihop attempted */
#define EDOTDOT 73 /* RFS specific error */
#define EBADMSG 74 /* Not a data message */
#define EOVERFLOW 75 /* Value too large for defined data type */
#define ENOTUNIQ 76 /* Name not unique on network */
#define EBADFD 77 /* File descriptor in bad state */
#define EREMCHG 78 /* Remote address changed */
#define ELIBACC 79 /* Can not access a needed shared library */
#define ELIBBAD 80 /* Accessing a corrupted shared library */
#define ELIBSCN 81 /* .lib section in a.out corrupted */
#define ELIBMAX 82 /* Attempting to link in too many shared libraries */
#define ELIBEXEC 83 /* Cannot exec a shared library directly */
#define EILSEQ 84 /* Illegal byte sequence */
#define ERESTART 85 /* Interrupted system call should be restarted */
#define ESTRPIPE 86 /* Streams pipe error */
#define EUSERS 87 /* Too many users */
#define ENOTSOCK 88 /* Socket operation on non-socket */
#define EDESTADDRREQ 89 /* Destination address required */
#define EMSGSIZE 90 /* Message too long */
#define EPROTOTYPE 91 /* Protocol wrong type for socket */
#define ENOPROTOOPT 92 /* Protocol not available */
#define EPROTONOSUPPORT 93 /* Protocol not supported */
#define ESOCKTNOSUPPORT 94 /* Socket type not supported */
#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
#define EPFNOSUPPORT 96 /* Protocol family not supported */
#define EAFNOSUPPORT 97 /* Address family not supported by protocol */
#define EADDRINUSE 98 /* Address already in use */
#define EADDRNOTAVAIL 99 /* Cannot assign requested address */
#define ENETDOWN 100 /* Network is down */
#define ENETUNREACH 101 /* Network is unreachable */
#define ENETRESET 102 /* Network dropped connection because of reset */
#define ECONNABORTED 103 /* Software caused connection abort */
#define ECONNRESET 104 /* Connection reset by peer */
#define ENOBUFS 105 /* No buffer space available */
#define EISCONN 106 /* Transport endpoint is already connected */
#define ENOTCONN 107 /* Transport endpoint is not connected */
#define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */
#define ETOOMANYREFS 109 /* Too many references: cannot splice */
#define ETIMEDOUT 110 /* Connection timed out */
#define ECONNREFUSED 111 /* Connection refused */
#define EHOSTDOWN 112 /* Host is down */
#define EHOSTUNREACH 113 /* No route to host */
#define EALREADY 114 /* Operation already in progress */
#define EINPROGRESS 115 /* Operation now in progress */
#define ESTALE 116 /* Stale NFS file handle */
#define EUCLEAN 117 /* Structure needs cleaning */
#define ENOTNAM 118 /* Not a XENIX named type file */
#define ENAVAIL 119 /* No XENIX semaphores available */
#define EISNAM 120 /* Is a named type file */
#define EREMOTEIO 121 /* Remote I/O error */
#define EDQUOT 122 /* Quota exceeded */

#define ENOMEDIUM 123 /* No medium found */
#define EMEDIUMTYPE 124 /* Wrong medium type */

#endif

Monday, June 9, 2008

Telnet command with port number.

Telnet command will helps to peep in to the remote server's application port. And we can have response from the remote server if you sent appropriate packets or data.

Syntax: telnet [IP address] [Application port num]
eg:
#telnet 192.168.1.2 8000
[ type here to send the appropriate data which remote server can recognize ]
Use Crtl + ] to get command mode prompt.
telnet> ? Enter
Gives some commad
telnet>close -->to exit

If you want to send Http response from command ..
Use ethereal to capture the data to be sent.
[Hint Right click the request and select TCP Streams ,You will get the Http response packet , Just Copy and paste it after telnet.]
Procedure
---------

Below packet is the capture of the HTTP get method ,since
assuming httpd is running in the server at port 8080.

#telnet 192.168.1.2 8080



If application is HTTP server below code capture will help full.
---This is what HTTP GET method request packet looks----
GET /index.html HTTP/1.1
Accept: */*
Accept-Language: en-us
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)
Host: 192.168.1.1:8080
Connection: Keep-Alive
Cache-Control: no-cache
------------------------Ends-----------------

---This is what HTTP POST method request packet looks----
POST /line_sip.htm?l=1 HTTP/1.1
Content-Length: 312
Connection: Keep-Alive

user_moh1=&user_alert_info1=&user_pic1=&user_dp_str1= &user_dp_exp1_0=off&user_dper_expiry1=3600&user_auto_connect1=off &user_descr_contact1=on&user_sipusername_and_local_name1=off& Settings=Save
------------------------Ends-----------------
user_moh1,user_alert_info1 .. are variables getting update values by POST request.

Telephone Recorder Circuit



This is simple telephone Recorder circuit.
T1 = Audio Transformer
(available in old modem or phone set)
R1 = 5.6K ohms
R2 = 10K ohms
R3 = 4.4K ohms
C1 = Disc Capacitor 203
D1 =D2 = 1N4148

Friday, June 6, 2008

Test Operator Usage



Example
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup <== This check for Exec permision
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources <== this will check exists and a file

Ascii Table

Thursday, April 3, 2008

Linux Commad ctags with find

catgs:
ctags -w `find $(SUBDIRS) include common \( -name CVS -prune \) -o \( -name '*.[ch]' -print \)`

find [options]
-name '*.[ch]' => This option restricts *.c and *.h files only
-prune -o -print => use to display and cut out subdirectories

This will search only .c and .h files with argument as search pattern"
alias f "find . -name '*.[c,h]' -print | xargs grep -n --color $1 "
eg: f pattern

Saturday, March 22, 2008

VoIP-H.323

The Media Gateway (MGW) table holds information about each media gateway managed by the Call Agent. The media gateway can be uniquely addressed by domain name, an IP address, or the TSAP address.


Megaco/H.248 protocol: history


The Media Gateway table has two associated commands: RGW and TGW. The RGW command provisions a gateway as only a Residential GateWay, with the type token automatically set to RGW. The TGW command provisions a gateway as a Trunking GateWay only, with the type token automatically set to TGW. Both of these commands provision the Media Gateway table, but a service provider can use these commands to provide user security to certain individuals based on their roles.

H.323
------
H.225 also for RAS( Registration ,admission,Status)
H.225/Q.931 can be defined as signaling (eg.call setup)
H.245 can be defined as control signaling (eg .Terminal cabability setup )
H.320 can be defined as multimedia service over ISDN
H.321 or H.310 can be defined as multimedia service over B-ISDN
H.322 can be defined as multimedia service over QoS Garenteed networks
H.323 can be defined as multimedia service over packet networks
H.323 can be defined as multimedia service over SCN

Sunday, March 9, 2008

Badminton Central Guide to choosing Badminton Equipment


I have wanted to write a guide on what equipment badminton should focus on. By nature, badminton requires the player to have a few pieces of equipment to engage in the sports, items such as a racket and a shuttlecock are a must for a badminton player. However, often I see many player places the wrong focus on how they spend their money on equipment. A smart badminton player will spend money effectively to maximize their badminton playing experience.

However, before I start, I would like to point out that no badminton equipment can replace proper badminton skills. If you think you can spend US$200 on a racket and you can instantly play better, you are 105% wrong. A good set of equipment can only bring out the potential of a player with good skills. No equipment can fix your bad skills. Instead, I recommend you spend your money on some good coaching lessons. It will make much more difference in your badminton game than a shiny new racket.

I chose to list the equipment in decreasing order of important, in other words, I reckon that the badminton shoes is the most important equipment that a badminton player has, while their clothing is the least important.

Shoes:
======
Contrary to popular belief, a good set of badminton shoes are the most important piece of equipment a badminton player can have. Badminton players move around the badminton court at an amazing pace, dashes and changes directions on every stroke of the rally, twisting and turning and lunging. All these movements are supported and made possible by the biggest unsung hero, the badminton shoes.

Badminton shoes are designed for badminton movements; a thin but well supported sole with good lateral support keep the player's feet close to the ground, this allows for fast and ankle bending directional changes with lower chance of injury; light weight for faster feet movement; surface hugging gummy soles to grip the indoor surface without slipping.

The amount of torture we subject our lower body to can clearly be seen in people's badminton shoes. A good pair of badminton shoes used by a decent player sometimes last only 3-6 months. At the end of its short life, you will find soles that are worn to the inner support, insoles that are worn through, strong upper leather that gave up and split due to the immense force exerted at it.

Pick your badminton shoes with care, make sure you choose the pair that fits the shape of your feet and thus the most comfortable.

And whatever you do, do not wear running shoes or any other thick soled shoes. They keep your feet too high up in the ground and all it will take is one deep lunge to have your ankle sprained. From then on, you will be in excruciating pain for days and the injury will affect your badminton game for years to come.

Good badminton shoes brands include
Asics,
Hi-Tec,
Mizuno, and
Yonex. Other smaller brands are starting to catching up as well.

String:
=======

The number two unsung hero of the badminton equipment is the badminton string. Afterall, it is the string that is in contact with the shuttle on every stroke. How the string interacts with the shuttle is crucial to the feel of each stroke. Depending on your skill level and the style of your game, you should pick a string and tension that is suitable for your game. String manufacturers usually have ratings of different string characteristics at the back of the string package. Pick the items that are most important for your game.

String tension affects the playability of the string as much as the string itself. The general rule of thumb is that the harder you can hit, the tighter your tension can be. A higher tension rewards a hard hitting while robs power from a light hitter. On the opposite end, a lower tensioned string helps light hitter with a better timed trampoline effect.

There is always the temptation to go higher in tension, but this is a case of bigger is not always better. Higher tension does not give you more power as mentioned above, beginners should always start with lower tension of around 20lbs, adjust it to 22-23lbs when you progress to intermediate and only go up to 25+lbs if you are gain more power in your technique. Using the inappropriate high tension will make the racket unresponsive, decreased power, and will easily cause injury.

Good brands for badminton strings are: Ashaway, Gosen, Mizuno, Yonex.

Recommended tensions:
beginners: 19-20lbs .(i.e. 2.2 lbs == 1 kg)
intermediate players: 21-24lbs.
advance players: 25+ lbs.

Grip:
=====

The number three unsung hero of badminton equipment is the badminton grip. Similar to the string being the interface to the shuttle, the grip is the interface to the badminton players finger and hand. The game of badminton comprises of many very delicate movements and fine control from the players€™s finger and wrist. A proper grip ensure that there is proper actuation and feedback to and from the racket.

Three major factors affects the characteristics of the grip: type, size and tackiness.

Badminton grips falls into two different type, towel and synthetic. The choice of which are personal preference. Towel grip are softer, provides good sweat absorption, but at the same time, is more prone to germ accumulation and needs to be changed often. Synthetic grips are less messy and less prone to accumulation of germs, however, they are not as good as towel grips when it comes to sweat absorption.

The proper grip size to use depends greatly on the player. Obviously a player with larger hands will prefer a larger grip and vice versa. It is often tempting to use a large grip, a large grip gives the false feeling that the racket is lighter and more maneuverable. However, one must again understand that badminton is comprised of subtle, agile and delicate movements in the fingers and wrist, a smaller (but not too small) grip will allow for higher agility and maneuverability of the racket.

Racquet:
=======

Often times badminton players give the racket the most emphasis. If you go into http://www.badmintoncentral.com and you will find that most of the discussion centers on the racket. While the racket is certainly an important equipment, the importance of which is often overrated, and that is the reason why I put the Racket almost next to last in our recommendation list.

The badminton racket is the middleman when transferring force from the player to the shuttle, sitting right between the grip and the string. A badminton racket can be categorized by a few characteristics: shape, stiffness, weight, balance.

Virtually all badminton rackets are made of carbon fiber or graphite. Some manufacturers choose to put in extra ingredients into the racket material like titanium or recently nanocarbon. I want to emphasis that they are only addictives, the 99% of the racket is still graphite and the extra benefits of the additives are very marginal.

Badminton rackets comes in two major head shapes:
1) Isometric/square and
2) Oval.
Oval is the traditional racket shape, it is a slightly bottom heavy oval, almost the shape of an egg. Oval rackets in general have a small but more concentrated sweet spot. Oval fans like the concentration of power around the sweetspot of the racket.
The shape is the Isometric or square which became more popular after the early 1990̢۪s. The Isometric head has a wider and more squared top half of the racket head. The advantage of the isometric is an enlarged sweetspot which give off-centered hit a better response.

The effective stiffness of a badminton racket is similar to the effective of string tension. So I will refer you back to that section. A stiffer racket has the similar effect as a higher tensioned string, while a flexible racket is similar to the lower tension string.

Rackets comes in different weights. Normally the racket alone weighs between 80-95g. Different manufacturers have different rating system, the most popular of which is Yonex̢۪s U system,

Weight SizeWeight (g)Main Use
1U95-99.9Training Racquets
2U90-94.9Attacking Singles
3U85-89.9Singles/Attacking Doubles
4U80-84.9Doubles/Defensive Singles
5U75-79.9Defensive Doubles

a racket's weight determines how fast one can swing a racket, the lighter a racket, the faster one can swing it with the same force. In general, a lighter racket is more maneuverable than a heavy one. However, before everybody goes out and buy the lightest racket, I also want to point out that lighter isn̢۪t always better. A light racket is less stable than a heavier racket, more force is necessary to keep its path, furthermore, a heavier racket has a larger momentum and thus more effective in transferring its speed and power to the shuttle.
The final racket characteristic is the balance of the racket. Head balanced racket is becoming more popular recently. Head balanced rackets have more mass near the head of the racket. A head balanced racket is more stable and have higher angular momentum when swung. On the contrary, a even balanced racket is more maneuverable.

As you can see, none of the different properties of the above characteristics are strictly better than other. Some players prefers slightly heavier rackets, some prefer slightly lighter, some like even balanced, some like head balanced. What I want to point out is that ultimately, it is a person̢۪s skill level and style that determines what racket is suitable, go try them out if you can to see what fits.

Clothing
======

Badminton clothing is quite simple to choose. Aside from one personal fashion preference, badminton clothing is better kept light and unrestrictive. Shirts needs to be slightly loose and comfortable to allow for arm and body movements. Badminton is a game of sweat, very often we see a badminton player walks out of the court like he just came out of a shower. As it is always uncomfortable to have sweat stuck to one̢۪s skin, sweat absorption and dissipation is thus important. There are many fancy sweat-wicking clothing out there, but from my personal experience, a good cotton t-shirt works well in most situation. If one gets really wet during a game, they are cheap enough so you can have a few spares ones to change into.

Shorts are the preference for most badminton players. Again, choose something that is light and not restrictive to movement, jumps and lunges are done often in badminton.

Again, clothing is mostly personal fashion preference, as long as the clothing allows for the extreme movements in badminton, it is usually quite ok.


I have mentioned it once and I will do it again here, while equipment is essential in badminton, the most important factor in badminton is still one̢۪s badminton skills. Equipment will only have marginal effect on one̢۪s game.

Source: Badminton Central

Guide for Shuttle rules:

http://www.annandale.k12.mn.us/AHS/faculty/pamfliegel/webpage/Badminton%20Study%20Guide1.htm

Compare Yonex Strings

Now let's discuss the string. There are many different brand of string. But Yonex is more widely used. The following is mainly translated from a post by someone who have strung more than 20,000 racquets for professional teams in China. Unfortunately, the original post has been copied too many times. I cannot find his name or contact. Anyway, I strongly appreciate his detailed and professional comment on almost all Yonex strings.

I focus on those available on US market. For those I used, I may add some of my own comment. I may also skip some details I think less important.
=====================================================================

First of all. I don't recommend Ti65 and Ti68 string. Except for a more crispy sound, there is nothing good about it. More importantly, the Ti skin on the surface of the string change the consistency of elasticiy of the string. That makes it fragile. The Ti skin also covers up the texture of the string. That reduced the control. Due to the sound, it makes you feel more powerful when you smash. But that is mostly hallucination only.(Normally this is used by professional players. They will restring after the game. If you can afford to do that. Ti string may still be a good choice for you.)

BG65 is most widely used. Mainly because it is the one used by National team for training purpose. But the BG65 used by national team is not the one in seperate bag we found on the market. It is the big reel version. 
(I guess the 200m Reel)The bag version is softer and smoother. Overall, it is very durable. It provides a good balance between quality and economy

I prefer BG66. It is a very thin string. Only 0.66mm.Extrodinary recillience. Good for beginer or players with relative less power. Cons: It is too thin. So it is easy to break. Also the control is not quite good.

In my opinion, BG70 is not a successful product. Yonex want to make it omnipotent: good recillience, good control and durable. Finally, nothing is very good.

BG80 is a .68mm string. Very good recillience. It is excellent for offensive plan. You can combine it with offensive racquets like NanoSpeed 9000, AT700, Ti10, MP100, etc. Strongly recommended for offensive player. One unqiue feature of BG80 is that you can get the feeling of a string setup at higher tension. (I use BG80 with my Ti10 at 24lb. It is a pretty powerful combination.)

BG85 is relative soft. It has a higher thread count. Its control is excellent, with the recillience second to only BG66. It is good for defensive player.
 
BGN95. This is not reviewed by the original post. But I used it with my NS9000 at 24lb. Recillience is not as good as BG80. But it is still pretty good overall. Good control and durability. It break only once when my racquet collide with partner's.

ModelRecillienceFeelShock AbsorptionControlDurability
BG-65BMediumAAA
BG-65TiAStiffBAA
BG-66A+StiffA+BB
BG-68TiA+Verfy StiffA+A+B
BG-70ProAMediumBAA
BG-80A+StiffAAA
BG-85A+Very StiffAAC
BG-95AStiffA+A+A
Hello

Shuttle cork:
Following are the Key Benefits of YONEX Mavis Series of Nylon Shuttlecock:
•Economical and durable Shuttlecock performance.
•Best Shuttle Flight and Characteristics (Close to Feather Shuttle).
•Better Flight pattern (Better then other Nylon shuttles and close to feather shuttlecocks).
•YONEX Mavis shuttlecock recovers in .02 secs (This fast shuttle recovery is better then other brand (.008 sec faster) , while its only .005 sec slower then feather shuttlecock)

Flight Pattern of YONEX Mavis Shuttlecock

YONEX Mavis Shuttlecock Options

Thursday, March 6, 2008

Pthread Creation and Termination

Example: Pthread Creation and Termination
gcc example.c -pthread

#include pthread.h
#include stdio.h
#define NUM_THREADS 5

void *PrintHello(void *threadid)
{
int tid;
tid = (int)threadid;
printf("Hello World! It's me, thread #%d!\n", tid);
pthread_exit(NULL);
}

int main (int argc, char *argv[])
{
pthread_t threads[NUM_THREADS];
int rc, t;
for(t=0; t<= NUM_THREADS; t++){
printf("In main: creating thread %d\n", t);
rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t);
if (rc){
printf("ERROR; return code from pthread_create() is %d\n", rc);
exit(-1);
}
}
pthread_exit(NULL);
}

Thursday, February 21, 2008

Audio Companding technique : G.711- A-Law

A-Law and u-law is meant for 8-bit raw linear data only.
Supported by G.711 format.

To Know more
http://en.wikipedia.org/wiki/G.711


Sampling frequency 8 kHz

Enabling interupt in LPC2212

/* This hold entire Application notes */
http://www.nxp.com/pip/LPC2212_2214_4.html

/* Manual : http://www.keil.com/dd/chip/3649.htm */
TN06002_LPC2000_EINT.pdf contains Below Code
int main (void)
{
IODIR1 = 0x00010000; // P1.16 defined as GPO
PINSEL1 |= 0x00000001; // P0.16 as EINT0 interrupt pin
VPBDIV = 0;
EXTMODE = 0x01; // EINT0 is (falling) edge-sensitive
// VPBDIV = 0x01; // additional step see errata
// VPB clock = CPU clock
VICVectAddr0 = (unsigned int) &EINT0_Isr;
EXTINT = 0x01; // Clear the peripheral interrupt flag
VICVectCntl0 = 0x2E; // Channel0 on Source# 14 == 0xE... enabled
/* Channel0 - high priority
Channel15 - low priority */
VICIntEnable = 0x4000; // 14th bit is EINT0
while (1) ;
}
void EINT0_Isr(void) __irq // for external interrupt 0
{
VICIntEnClr = 0x00004000; // Disable EINT0 in the VIC
/*.............
Our code
....*/
EXTINT = 0x01; // Clear the peripheral interrupt flag
VICIntEnable = 0x00004000; // Enable EINT0 in the VIC I.e 14 bit ==VIC# 14
VICVectAddr = 0; // reset VIC
}

Friday, February 15, 2008

Linux Rare Comands

wget http_proxy=http://url:port --proxy-user=xxxxxx --proxy-password=xxxxxxx http://in2.php.net/distributions/php-5.2.6.tar.gz


To trace the process currently running ........
]# strace -p


To see the currently ports open
]# netstat -an

Tuesday, January 22, 2008

Introduction to network functions in C

Introduction to network functions in C


http://shoe.bocks.com/net/


http://shoe.bocks.com/net/source/examples/chat.c

Monday, January 21, 2008

kbhit() for Linux

/*
Well I would just use ncurses, but you could possibly use below? Chances are you problly don't need either unless you're making a crappy console game, or a password program.
*/

#include stdio.h>
#include termios.h>
#include unistd.h>
#include sys/types.h>
#include sys/time.h>

/* This id to hide the character we type and suspend any
prints after dir 1 , displayed ony when dir 0 */
void changemode ( int dir )
{
static struct termios oldt, newt;
if ( dir == 1 )
{
tcgetattr ( STDIN_FILENO, &oldt );
newt = oldt;
newt.c_lflag &= ~ ( ICANON | ECHO );
tcsetattr ( STDIN_FILENO, TCSANOW, &newt );
}
else
tcsetattr ( STDIN_FILENO, TCSANOW, &oldt );
}
int kbhit ( void )
{
struct timeval tv;
fd_set rdfs;

tv.tv_sec = 0;
tv.tv_usec = 0;

FD_ZERO ( &rdfs );
FD_SET ( STDIN_FILENO, &rdfs );
// select ( STDIN_FILENO + 1, &rdfs, NULL, NULL, &tv );
select ( STDIN_FILENO + 1, &rdfs, NULL, NULL, NULL );
printf(" After ");
return FD_ISSET ( STDIN_FILENO, &rdfs );

}

int main ( void )
{
int ch;
printf(" Press any Key to continue\n ");
changemode ( 1 );

while ( !kbhit() )
{
// putchar ( '.' );
}
ch = getchar();
printf ( "\nGot %c\n", ch );
changemode ( 0 );
return 0;
}

Monday, January 7, 2008

getche() equivalent in Linux

]# echo -n "Press any key to continue..." && read -n 1
or
]# read -sn1 -p " Press any key to continue "
Also :
]$ echo -n "Press any key to continue..." && /sbin/getkey


##test.sh
if /sbin/getkey -i -c 5 -m "Press Y within %d sec to continue " y;
then
echo You pressed y
else
echo You pressed Wrong
fi
echo

/sbin/getkey i && touch /var/run/confirm
if pressed key is 'i' return 1 else 0.
&& fail if 0 .

http://www.webservertalk.com/archive200-2005-7-1138374.html

Friday, January 4, 2008

Advanced Macro Tricks (Tokenizer )

Pasting Tokens
================
Each argument passed to a macro is a token, and sometimes it might be expedient to paste arguments together to form a new token. This could come in handy if you have a complicated structure and you'd like to debug your program by printing out different fields. Instead of writing out the whole structure each time, you might use a macro to pass in the field of the structure to print.

To paste tokens in a macro, use ## between the two things to paste together.

For instance

#define BUILD_FIELD(field) my_struct.inner_struct.union_a.##field

Now, when used with a particular field name, it will expand to something like

my_struct.inner_struct.union_a.field1

The tokens are literally pasted together.

String-izing Tokens
====================
Another potentially useful macro option is to turn a token into a string containing the literal text of the token. This might be useful for printing out the token. The syntax is simple--simply prefix the token with a pound sign (#).

#define PRINT_TOKEN(token) printf(#token " is %d", token)

For instance, PRINT_TOKEN(foo) would expand to

printf("foo" " is %d" foo)

(Note that in C, string literals next to each other are concatenated, so something like "token" " is " " this " will effectively become "token is this". This can be useful for formatting printf statements.)

For instance, you might use it to print the value of an expression as well as the expression itself (for debugging purposes).

PRINT_TOKEN(x + y);



http://www.cprogramming.com/tutorial/cpreprocessor.html

Thursday, January 3, 2008

Vb Script to automate the mail

Vb Script to automate the mail
------------------------------

SeeGood.vbs
-----------
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "Outlook"
WScript.Sleep 2500 ' Comment : Give Notepad some time to load
WshShell.SendKeys "^{n}" ' Ctrl+N
WScript.Sleep 1000
WshShell.SendKeys "test@mailid.com"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{TAB}"
WScript.Sleep 100
WshShell.SendKeys " Hi,I would have checked out the code first! ....."
WshShell.SendKeys "{ENTER}"
WScript.Sleep 5000
WshShell.SendKeys "%{s}" 'Alt+s

'For
'SHIFT = +
'CTRL = ^
'ALT = %

Tuesday, December 25, 2007

Java Simple thread program

/* Example for thread in java .
* Two types of thread creation can be done
* One- by extend the thread class
* two- by implement runnable
* below I used runnable.
*/
/* Class 1*/
public class TcpServer implements Runnable {

public static void main(String[] args) {
/* Creating instances for Class 1 and class 2 */
TcpServer ser1=new TcpServer();
TcpServer ser2=new TcpServer();
arun an=new arun();

/* Declaring thread for instance */
Thread t1=new Thread(ser1);
Thread t2=new Thread(ser2);
Thread t3=new Thread(an);
/*
* Thread can be created for any number of instances
*Thread t2=new Thread(ser2);
*/
/*thread started */
t1.start();
t2.start();
t3.start();
}
public void run() {

first();
}
public void first(){
for (int i = 0; i < 100; i++) {
System.out.println("Thread First "+i );
}
}
}/* end of class 1 */

/* Class 2 */
class arun implements Runnable{
public void run() {
second();
}
public void second(){
for (int i = 0; i < 100; i++) {
System.out.println("Thread Second "+i);
}
}
}/* End of class 2 */

Java Server /Client Chat program

/* This is an Client to Server One way comm. program
i.e client (writes) send data ,server keep on (read )listen and recv.

For two way communication between server and client we should go for thread.
How can be acheived by thread ?
In both server and client two threads should be created and one for read() and another for write().since read is blocking call.
For thread reference see my next post "Java Thread Simple program ".

Server.Java */

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
ServerSocket serverSocket=null;
Socket socket=null;
InputStream in=null;
OutputStream out=null;

Server() throws IOException{
serverSocket=new ServerSocket(500);
System.out.println("Server Started");
/* server will blocked here till client connects */
socket=serverSocket.accept();
System.out.println("Connected.........");
/* Any in coming dada we stored in this stream */
in=socket.getInputStream();
out=socket.getOutputStream();
}

void read() throws IOException{
int c=0;
/* printing the incoming message from input stream obj */
while((c=in.read())!=-1){
System.out.print((char)c);
}
in.close();
out.close();
socket.close();
}


public static void main(String[] args) throws IOException {
Server ser=new Server();
ser.read();
/*
Test code for string to byte conversion
String str="arun kumar";
Here we reading array string so we used byte array stream
ByteArrayInputStream by=new ByteArrayInputStream(str.getBytes());
int c=0;
while((c=by.read())!=-1){
System.out.println((char)c);
*/
}
}

/********* End of server *****************/

/*Client.Java */

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.io.DataInputStream;
public class Client {

Socket socket=null;
InputStream in=null;
OutputStream out=null;

Client() throws UnknownHostException, IOException{
socket=new Socket("localhost",500);
in=socket.getInputStream();
out=socket.getOutputStream();
}

void write() throws IOException{
/* Buffered input Stream will blocked till Enter key pressed. System.in is used get input from console (kbd) */
BufferedInputStream input=new BufferedInputStream(System.in);
while(true){
/* but here we converting buffer data to stream of bytes since buffer stream will store a block of characters*/
int c=input.read();
System.out.print((char)c);
out.write(c);

}
}
public static void main(String[] args) {
try {
Client client=new Client();
client.write();
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

}

}

/********** End of Client *******************/

Monday, December 10, 2007

CreateGUI and Click Event Handler in Java

/* AddressBookDemo.java
Website: java-swing-tutorial.html
Topic: A basic Java Address Book
Conventions Used in Source code
---------------------------------
1. All JLabel components start with jlb*

2. All JPanel components start with jpl*

3. All JMenu components start with jmenu*

4. All JMenuItem components start with jmenuItem*

5. All JDialog components start with jdlg*

6. All JButton components start with jbn*

*/
import java.awt.Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

public class AddressBookDemo implements ActionListener {

ArrayList personsList;
//PersonDAO pDAO;
JFrame appFrame;
JLabel jlbName, jlbAddress, jlbPhone, jlbEmail;
JTextField jtfName, jtfAddress, jtfPhone, jtfEmail;
JButton jbbSave, jbnDelete, jbnUpdate,
jbnBack, jbnSearch, jbnForward,
jbnClear, jbnExit;
String name, address, email;
int phone;
int recordNumber; // used to naviagate using >> and buttons
Container cPane;
public static void main(String args[]) {
new AddressBookDemo();
}
public AddressBookDemo() {
name = "";
address = "";
email = "";
phone = -1; //Stores 0 to indicate no Phone Number
recordNumber = -1;
createGUI();
//personsList = new ArrayList();
// creating PersonDAO object
//pDAO = new PersonDAO();
}
public void createGUI(){

/*Create a frame, get its contentpane and set layout*/
appFrame = new JFrame("Address Book");
cPane = appFrame.getContentPane();
cPane.setLayout(new GridBagLayout());
//Arrange components on contentPane and set Action Listeners to each JButton

arrangeComponents();
appFrame.setSize(260,300);
appFrame.setResizable(false);
appFrame.setVisible(true);

}
public void arrangeComponents() {
jlbName = new JLabel("Name");
jlbAddress = new JLabel("Address");
jlbPhone = new JLabel("Phone");
jlbEmail = new JLabel("Email");
jtfName = new JTextField(20);
jtfAddress = new JTextField(20);
jtfPhone = new JTextField(20);
jtfEmail = new JTextField(20);
jbbSave = new JButton("Save");
jbnDelete = new JButton("Delete");
jbnClear = new JButton("Clear");
jbnUpdate = new JButton("Update");
jbnSearch = new JButton("Search");
jbnForward = new JButton(">>");
jbnBack = new JButton("<<");
jbnExit = new JButton("Exit");

/*add all initialized components to the container*/
/* Name field */
GridBagConstraints gridBagConstraintsx01 = new GridBagConstraints();
gridBagConstraintsx01.gridx = 0;
gridBagConstraintsx01.gridy = 0;
gridBagConstraintsx01.insets = new Insets(5, 5, 5, 5);
cPane.add(jlbName, gridBagConstraintsx01);
GridBagConstraints gridBagConstraintsx02 = new GridBagConstraints();
gridBagConstraintsx02.gridx = 1;
gridBagConstraintsx02.insets = new Insets(5, 5, 5, 5);
gridBagConstraintsx02.gridy = 0;
gridBagConstraintsx02.gridwidth = 2;
gridBagConstraintsx02.fill = GridBagConstraints.BOTH;
cPane.add(jtfName, gridBagConstraintsx02);

/* Address field */
GridBagConstraints gridBagConstraintsx03 = new GridBagConstraints();
gridBagConstraintsx03.gridx = 0;
gridBagConstraintsx03.insets = new Insets(5, 5, 5, 5);
gridBagConstraintsx03.gridy = 1;
cPane.add(jlbAddress, gridBagConstraintsx03);
GridBagConstraints gridBagConstraintsx04 = new GridBagConstraints();
gridBagConstraintsx04.gridx = 1;
gridBagConstraintsx04.insets = new Insets(5, 5, 5, 5);
gridBagConstraintsx04.gridy = 1;
gridBagConstraintsx04.gridwidth = 2;
gridBagConstraintsx04.fill = GridBagConstraints.BOTH;
cPane.add(jtfAddress, gridBagConstraintsx04);

/* Phone Feild */
GridBagConstraints gridBagConstraintsx05 = new GridBagConstraints();
gridBagConstraintsx05.gridx = 0;
gridBagConstraintsx05.insets = new Insets(5, 5, 5, 5);
gridBagConstraintsx05.gridy = 2;
cPane.add(jlbPhone, gridBagConstraintsx05);
GridBagConstraints gridBagConstraintsx06 = new GridBagConstraints();
gridBagConstraintsx06.gridx = 1;
gridBagConstraintsx06.gridy = 2;
gridBagConstraintsx06.insets = new Insets(5, 5, 5, 5);
gridBagConstraintsx06.gridwidth = 2;
gridBagConstraintsx06.fill = GridBagConstraints.BOTH;
cPane.add(jtfPhone, gridBagConstraintsx06);

/* Email field */
GridBagConstraints gridBagConstraintsx07 = new GridBagConstraints();
gridBagConstraintsx07.gridx = 0;
gridBagConstraintsx07.insets = new Insets(5, 5, 5, 5);
gridBagConstraintsx07.gridy = 3;
cPane.add(jlbEmail, gridBagConstraintsx07);
GridBagConstraints gridBagConstraintsx08 = new GridBagConstraints();
gridBagConstraintsx08.gridx = 1;
gridBagConstraintsx08.gridy = 3;
gridBagConstraintsx08.gridwidth = 2;
gridBagConstraintsx08.insets = new Insets(5, 5, 5, 5);
gridBagConstraintsx08.fill = GridBagConstraints.BOTH;
cPane.add(jtfEmail, gridBagConstraintsx08);

/* Save - Delete - Update */
GridBagConstraints gridBagConstraintsx09 = new GridBagConstraints();
gridBagConstraintsx09.gridx = 0;
gridBagConstraintsx09.gridy = 4;
gridBagConstraintsx09.insets = new Insets(5, 5, 5, 5);
cPane.add(jbbSave, gridBagConstraintsx09);
GridBagConstraints gridBagConstraintsx10 = new GridBagConstraints();
gridBagConstraintsx10.gridx = 1;
gridBagConstraintsx10.gridy = 4;
gridBagConstraintsx10.insets = new Insets(5, 5, 5, 5);
cPane.add(jbnDelete, gridBagConstraintsx10);
GridBagConstraints gridBagConstraintsx11 = new GridBagConstraints();
gridBagConstraintsx11.gridx = 2;
gridBagConstraintsx11.gridy = 4;
gridBagConstraintsx11.insets = new Insets(5, 5, 5, 5);
cPane.add(jbnUpdate, gridBagConstraintsx11);

/* << - Search - >> */
GridBagConstraints gridBagConstraintsx12 = new GridBagConstraints();
gridBagConstraintsx12.gridx = 0;
gridBagConstraintsx12.gridy = 5;
gridBagConstraintsx12.insets = new Insets(5, 5, 5, 5);
cPane.add(jbnBack, gridBagConstraintsx12);
GridBagConstraints gridBagConstraintsx13 = new GridBagConstraints();
gridBagConstraintsx13.gridx = 1;
gridBagConstraintsx13.gridy = 5;
gridBagConstraintsx13.insets = new Insets(5, 5, 5, 5);
cPane.add(jbnSearch, gridBagConstraintsx13);
GridBagConstraints gridBagConstraintsx14 = new GridBagConstraints();
gridBagConstraintsx14.gridx = 2;
gridBagConstraintsx14.gridy = 5;
gridBagConstraintsx14.insets = new Insets(5, 5, 5, 5);
cPane.add(jbnForward, gridBagConstraintsx14);

/* - - Clear - Exit */
GridBagConstraints gridBagConstraintsx15 = new GridBagConstraints();
gridBagConstraintsx15.gridx = 1;
gridBagConstraintsx15.insets = new Insets(5, 5, 5, 5);
gridBagConstraintsx15.gridy = 6;
cPane.add(jbnClear, gridBagConstraintsx15);
GridBagConstraints gridBagConstraintsx16 = new GridBagConstraints();
gridBagConstraintsx16.gridx = 2;
gridBagConstraintsx16.gridy = 6;
gridBagConstraintsx16.insets = new Insets(5, 5, 5, 5);
cPane.add(jbnExit, gridBagConstraintsx16);

/* Listen Action */
jbbSave.addActionListener(this);
jbnDelete.addActionListener(this);
jbnClear.addActionListener(this);
jbnUpdate.addActionListener(this);
jbnSearch.addActionListener(this);
jbnForward.addActionListener(this);
jbnBack.addActionListener(this);
jbnExit.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == jbbSave) {
//savePerson();
System.out.println(" Save");
clear();
} else if (e.getSource() == jbnDelete) {
//deletePerson();
clear();
} else if (e.getSource() == jbnUpdate) {
//updatePerson();
clear();
} else if (e.getSource() == jbnSearch) {
//searchPerson();
} else if (e.getSource() == jbnForward) {
//displayNextRecord();
} else if (e.getSource() == jbnBack) {
//displayPreviousRecord();
} else if (e.getSource() == jbnClear) {
System.out.println(" Clear");
clear();
} else if (e.getSource() == jbnExit) {
System.exit(0);
}
}

public void clear() {
jtfName.setText("");
jtfAddress.setText("");
jtfPhone.setText("");
jtfEmail.setText("");
/*clear contents of arraylist*/
/* recordNumber = -1; */
//personsList.clear();
jbnForward.setEnabled(true);
jbnBack.setEnabled(true);
}
}

Wednesday, December 5, 2007

Simple Swing in java

/* First.java */

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class First {

public static void main(String args[])
{
new First();
/* Opening Frame */
JFrame frame = new JFrame("Hello");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 150);
/* This resize to components inside the frame */
//frame.pack();
Container content = frame.getContentPane();
content.setBackground(Color.white);
content.setLayout(new FlowLayout());
content.add(new JTextArea("Welcome to My Java World !"));
content.add(new JTextField("Enetr text "));
content.add(new JButton("Click"));
//frame.addWindowListener(new ExitListener());
frame.setVisible(true);

}
//Constructor
public void First()
{
System.out.println(" Constructor hello ");
}
}

/*compile */
javac First.java && java First

/* creating exec jar.
copy con mainClass.txt
"Main-Class: First
*/
jar cmfv mainClass.txt FistSwing.jar *.class *.java

/* execute jar */
java -jar FirstSwing.jar

/* Excute using Browser by adding below code in body*/
LessThan applet code="First" archive="FirstSwing.jar" GreaterThan
Lessthan Slash applet GreaterThan



http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-JFrame.html
http://www.javabeginner.com/java-addressbook.htm
http://www.beginner-java-tutorial.com/jtextarea.html

How to Use va_args in C

#include stdio.h>
#include stdarg.h>
void LogMsg(int lvl, char *fmt,...)
{
va_list vList ;
char msg[256] ;
char debugmsg[500] ;
printf(" Size %d\n",sizeof(debugmsg));
if(lvl ==1)
{
va_start(vList,fmt) ;
vsnprintf(msg, 256, fmt, vList) ;
sprintf(debugmsg, " %s\n", msg) ;
printf("debugmsg : %s msg : %s\n", debugmsg, msg) ;
va_end(vList);
}
}

int main()
{

printf(" \n");
LogMsg(1,"%s %d Test Message \n",__func__,__LINE__);
return 0;
}
~

Monday, December 3, 2007

How to use mmap

#include sys/mman.h
#include stdio.h
#include sys/types.h
#include sys/stat.h
#include fcntl.h
#include unistd.h

int fd_wd;
void *wd_addr = NULL;
unsigned char *temp;
volatile unsigned int *addr;

#define BASE 0xF0010000

int main (int argc, char *argv[])
{
char dat[4096] = "12345678";
unsigned int i, base_addr, read;
unsigned int store;
unsigned int value;
unsigned short page_size;

page_size = getpagesize ();
if(argc == 1)
{
printf ("Usage : ./mapper [options] \n");
printf (" Options 1 - to mmap local array \n");
printf (" 2 - to map fixed addr 0xF0010000 \n");
printf (" 3 - to map new address and new file eg: ./mapper 3 /dev/mem\n");
return 1;
}
if (atoi(argv[1]) != 1)
{
if(argc == 3)
{
printf("Openning file %s \n",argv[2]);
fd_wd = open (argv[2], O_RDWR | O_SYNC);
if (fd_wd == -1)
{
perror("Open ");
return 1;
}

}
else
{
fd_wd = open ("/dev/mem", O_RDWR | O_SYNC);
printf (" Opening file /dev/mem file \n");
if (fd_wd == -1)
{
perror("While Open ");
return 1;
}
}
if(atoi(argv[1]) == 3 )
{
printf(" Enter 32bit addr eg 0xF0010000 \n Hex 0x");
scanf("%X",&base_addr);
}
else
{
base_addr = BASE;

}
/* mmap() will read only page by page , so BASE should be multiple of Page Size */
if ((base_addr % page_size) != 0)
{
printf (" Base address is not multiple of pagesize ");
return 1;
}
/*page_size will length ,since 0-(lenght-1) = length eg: if size 4096 ...start 0-4095 */
wd_addr = mmap (0, (page_size - 1), PROT_READ | PROT_WRITE, MAP_SHARED, fd_wd, base_addr);
perror (" Memory mapping ");
if (wd_addr == (void *) -1)
{
printf ("Unable to map mem file \n");
perror (" Failed: ");
close (fd_wd);
return 1;
}
}
else
{
printf (" Local mapping to Array \n");
wd_addr = dat;
}

/* Printing the Address */
printf (" wd_addr = %X ", wd_addr);

/*Reading Byte by Byte */
temp = (unsigned char *) wd_addr;
printf ("\n\n Enter Offset [0-%d] : ", (page_size - 1));
scanf ("%d", &read);
/* Moving the pointer to Entered offset */
store = *(temp);
temp = temp + read;
printf (" Reading 4 bytes : \n");
for (i = 0; i < 4; i++)
{
printf (" Addr[%02d] : %X = %02X \n", i, temp, *(temp));
temp++;
}

/*Reading Word by Word */
addr = (unsigned int *) wd_addr;
value = *(addr);
value = *(addr);
printf ("\n Base Addr: %X by Word 0x%08X \n", addr, value);
printf ("\n Enter offset [0-4095] to read word : ");
scanf ("%x", &read);

addr = addr + ((unsigned int) read / 4); /* Asuming 4byte == one word length
it is an 32 it processor */
printf (" Enter no. of words to Read:");
scanf ("%d", &read);
/*In big endian format first readed byte is will not match with truncated byte from Word */
if (store != (unsigned char) value)
printf ("\n Big-endian platform Lsb....Msb \n");
else
printf ("\n Little-endian plat Msb....Lsb \n");
for (i = 0; i < read; i++)
{
value = 0;
value = *(addr);
printf (" Addr[%d] : %X 0x%08X \n", i, addr, value);
addr++;
}
printf ("\n");

if (atoi(argv[1]) != 1)
printf (" Munmap : %d\n", munmap (wd_addr, page_size));
return 0;
}

Function pointer in C

#include stdio.h


void func (int);
void one (int, float);
void two (int, float);
void three (int, float);
void four (int, float);
void five (int, float);

int main ()
{
char findex;

/* Function pointer Declaration */
void (*fp) (int); /* single argum,ent */
void (*fptr) (int, float); /* two argument */

/* Function array pointer Declaration */
void (*fparr[]) (int, float) =
{
one, two, three, four, five}; /* initializers */

printf (" Ordinary function calling five(1,3.4)\n");
five (1, 3.4);

printf (" Calling by function pointer fptr(1,3.4); \n");
fptr = five;
fptr (1, 3.4);

printf (" Calling by fun. array ptr (*fparr[findex]) (1, 3.4) \n");
findex = 4; /* To call five(arg1,arg2) fun. index is 4 */
(*fparr[findex]) (1, 3.4); /* passing argument 1, 3.4 */

printf (" Calling func by single argument function pointer \n");
fp = func;
(*fp) (2); /* Mtd 1 */
fp (2); /* Mtd 2 */

exit (EXIT_SUCCESS);
}

void func (int arg)
{
printf ("func arg: %d\n", arg);
}

void one (int arg, float arg2)
{
printf ("Four %f\n", arg2);
printf (" %d\n", arg);
}

/* Similerly define of thwo three...four*/

void five (int arg, float arg2)
{
printf ("Five %f\n", arg2);
printf (" %d\n", arg);
}

Indent for C Program in linux

/*indent with 3 space */
alias in3='indent -bls -bli0 -cli3 -cbi3 -i3 -di5 -bad -nut -l120 -npsl -sob -sai -saf '

/*Indent With 4 space */
alias in4='indent -bls -bli0 -cli4 -cbi4 -i4 -di5 -bad -nut -l120 -npsl -sob -sai -saf '

see man indent above

Friday, November 23, 2007

Moto Rokr E6 Blue tooth features

I can only answer how to use the phone with Linux.

For USB Mass storage, you just plug the phone to PC and the phone will be recognized as /dev/sdb1 (in Ubuntu) and you can mount it. Of course don't forget to set it as Mass storage in the setup.

For synchronising see this link:
http://www.motorolafans.com/forums/v...ic.php?t=12152

For send a file to phone with bluetooth, use ussp-push:
ussp-push @3

Local and remote file name can be different. "3" is channel for Object Push.
Here is the list of bluetooth channel for E6:
1: Headset Voice Gateway
2: Hands-Free Voice Gateway
3: Object Push
4: Basic Printing
5: Bluetooth Serial Port
6: Dial-Up Networking

Hope it helps.

http://www.motorolafans.com/forums/showthread.php?t=11830

Monday, May 14, 2007

SIP: Session Initiation Protocol



http://en.wikipedia.org/wiki/SIP_Requests

http://tools.ietf.org/html/rfc3261

Simple Example:



atlanta.com . . . biloxi.com
. proxy proxy .
. .
Alice's . . . . . . . . . . . . . . . . . . . . Bob's
softphone SIP Phone
| | | |
| INVITE F1 | | |
|--------------->| INVITE F2 | |
| 100 Trying F3 |--------------->| INVITE F4 |
|<---------------| 100 Trying F5 |--------------->|
| |<-------------- | 180 Ringing F6 |
| | 180 Ringing F7 |<---------------|
| 180 Ringing F8 |<---------------| 200 OK F9 |
|<---------------| 200 OK F10 |<---------------|
| 200 OK F11 |<---------------| |
|<---------------| | |
| ACK F12 |
|------------------------------------------------->|
| Media Session |
|<================================================>|
| BYE F13 |
|<-------------------------------------------------|
| 200 OK F14 |
|------------------------------------------------->|
| |

Figure 1: SIP session setup example with SIP trapezoid

INVITE sip:bob@biloxi.com SIP/2.0
Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bK776asdhds
Max-Forwards: 70
To: Bob <sip:bob@biloxi.com>
From: Alice <sip:alice@atlanta.com>;tag=1928301774
Call-ID: a84b4c76e66710@pc33.atlanta.com
CSeq: 314159 INVITE
Contact: <sip:alice@pc33.atlanta.com>
Content-Type: application/sdp
Content-Length: 142

(Alice's SDP not shown)

7 SIP Messages



SIP is a text-based protocol and uses the UTF-8 charset (RFC 2279
[7]).


A SIP message is either a request from a client to a server, or a
response from a server to a client.

Both Request (section 7.1) and Response (section 7.2) messages use
the basic format of RFC 2822 [3], even though the syntax differs in
character set and syntax specifics. (SIP allows header fields that
would not be valid RFC 2822 header fields, for example.) Both types
of messages consist of a start-line, one or more header fields, an
empty line indicating the end of the header fields, and an optional
message-body.

generic-message = start-line
*message-header
CRLF
[ message-body ]
start-line = Request-Line / Status-Line

The start-line, each message-header line, and the empty line MUST be
terminated by a carriage-return line-feed sequence (CRLF). Note that
the empty line MUST be present even if the message-body is not.

Except for the above difference in character sets, much of SIP's
message and header field syntax is identical to HTTP/1.1. Rather
than repeating the syntax and semantics here, we use [HX.Y] to refer
to Section X.Y of the current HTTP/1.1 specification (RFC 2616 [8]).

However, SIP is not an extension of HTTP.

7.1 Requests


SIP requests are distinguished by having a Request-Line for a start-
line. A Request-Line contains a method name, a Request-URI, and the
protocol version separated by a single space (SP) character.

The Request-Line ends with CRLF. No CR or LF are allowed except in
the end-of-line CRLF sequence. No linear whitespace (LWS) is allowed
in any of the elements.

Request-Line = Method SP Request-URI SP SIP-Version CRLF

Method: This specification defines six methods: REGISTER for
registering contact information, INVITE, ACK, and CANCEL for
setting up sessions, BYE for terminating sessions, and
OPTIONS for querying servers about their capabilities. SIP
extensions, documented in standards track RFCs, may define
additional methods.

Request-URI: The Request-URI is a SIP or SIPS URI as described in
Section 19.1 or a general URI (RFC 2396 [5]). It indicates
the user or service to which this request is being addressed.
The Request-URI MUST NOT contain unescaped spaces or control
characters and MUST NOT be enclosed in "<>".

SIP elements MAY support Request-URIs with schemes other than
"sip" and "sips", for example the "tel" URI scheme of RFC
2806 [9]. SIP elements MAY translate non-SIP URIs using any
mechanism at their disposal, resulting in SIP URI, SIPS URI,
or some other scheme.

SIP-Version: Both request and response messages include the
version of SIP in use, and follow [H3.1] (with HTTP replaced
by SIP, and HTTP/1.1 replaced by SIP/2.0) regarding version
ordering, compliance requirements, and upgrading of version
numbers. To be compliant with this specification,
applications sending SIP messages MUST include a SIP-Version
of "SIP/2.0". The SIP-Version string is case-insensitive,
but implementations MUST send upper-case.

Unlike HTTP/1.1, SIP treats the version number as a literal
string. In practice, this should make no difference.

7.2 Responses

SIP responses are distinguished from requests by having a Status-Line
as their start-line. A Status-Line consists of the protocol version
followed by a numeric Status-Code and its associated textual phrase,
with each element separated by a single SP character.

No CR or LF is allowed except in the final CRLF sequence.

Status-Line = SIP-Version SP Status-Code SP Reason-Phrase CRLF

The Status-Code is a 3-digit integer result code that indicates the
outcome of an attempt to understand and satisfy a request. The
Reason-Phrase is intended to give a short textual description of the
Status-Code. The Status-Code is intended for use by automata,
whereas the Reason-Phrase is intended for the human user. A client
is not required to examine or display the Reason-Phrase.

While this specification suggests specific wording for the reason
phrase, implementations MAY choose other text, for example, in the
language indicated in the Accept-Language header field of the
request.

The first digit of the Status-Code defines the class of response.
The last two digits do not have any categorization role. For this
reason, any response with a status code between 100 and 199 is
referred to as a "1xx response", any response with a status code
between 200 and 299 as a "2xx response", and so on. SIP/2.0 allows
six values for the first digit:

1xx: Provisional -- request received, continuing to process the
request;

2xx: Success -- the action was successfully received, understood,
and accepted;

3xx: Redirection -- further action needs to be taken in order to
complete the request;

4xx: Client Error -- the request contains bad syntax or cannot be
fulfilled at this server;

5xx: Server Error -- the server failed to fulfill an apparently
valid request;

6xx: Global Failure -- the request cannot be fulfilled at any
server.


21 Response Codes ...................................... 182
21.1 Provisional 1xx ..................................... 182
21.1.1 100 Trying .......................................... 183
21.1.2 180 Ringing ......................................... 183
21.1.3 181 Call Is Being Forwarded ......................... 183
21.1.4 182 Queued .......................................... 183
21.1.5 183 Session Progress ................................ 183
21.2 Successful 2xx ...................................... 183
21.2.1 200 OK .............................................. 183
21.3 Redirection 3xx ..................................... 184
21.3.1 300 Multiple Choices ................................ 184
21.3.2 301 Moved Permanently ............................... 184
21.3.3 302 Moved Temporarily ............................... 184
21.3.4 305 Use Proxy ....................................... 185
21.3.5 380 Alternative Service ............................. 185
21.4 Request Failure 4xx ................................. 185
21.4.1 400 Bad Request ..................................... 185
21.4.2 401 Unauthorized .................................... 185
21.4.3 402 Payment Required ................................ 186
21.4.4 403 Forbidden ....................................... 186
21.4.5 404 Not Found ....................................... 186
21.4.6 405 Method Not Allowed .............................. 186
21.4.7 406 Not Acceptable .................................. 186
21.4.8 407 Proxy Authentication Required ................... 186
21.4.9 408 Request Timeout ................................. 186
21.4.10 410 Gone ............................................ 187
21.4.11 413 Request Entity Too Large ........................ 187
21.4.12 414 Request-URI Too Long ............................ 187
21.4.13 415 Unsupported Media Type .......................... 187
21.4.14 416 Unsupported URI Scheme .......................... 187
21.4.15 420 Bad Extension ................................... 187
21.4.16 421 Extension Required .............................. 188
21.4.17 423 Interval Too Brief .............................. 188
21.4.18 480 Temporarily Unavailable ......................... 188
21.4.19 481 Call/Transaction Does Not Exist ................. 188
21.4.20 482 Loop Detected ................................... 188
21.4.21 483 Too Many Hops ................................... 189
21.4.22 484 Address Incomplete .............................. 189
21.4.23 485 Ambiguous ....................................... 189
21.4.24 486 Busy Here ....................................... 189
21.4.25 487 Request Terminated .............................. 190
21.4.26 488 Not Acceptable Here ............................. 190
21.4.27 491 Request Pending ................................. 190
21.4.28 493 Undecipherable .................................. 190
21.5 Server Failure 5xx .................................. 190
21.5.1 500 Server Internal Error ........................... 190
21.5.2 501 Not Implemented ................................. 191
21.5.3 502 Bad Gateway ..................................... 191
21.5.4 503 Service Unavailable ............................. 191
21.5.5 504 Server Time-out ................................. 191
21.5.6 505 Version Not Supported ........................... 192
21.5.7 513 Message Too Large ............................... 192
21.6 Global Failures 6xx ................................. 192
21.6.1 600 Busy Everywhere ................................. 192
21.6.2 603 Decline ......................................... 192
21.6.3 604 Does Not Exist Anywhere ......................... 192
21.6.4 606 Not Acceptable .................................. 192



Wednesday, May 2, 2007

Electronic tutorial and Embedded

http://www.cecs.csulb.edu/~brewer/

Keil related:
--------------
http://www.cecs.csulb.edu/~brewer/347/lpc-ARM-book_srn.pdf

Orcad Student version....
and so...on...