Friday, March 6, 2009

4 - Variable and Constant

Variable Declaration
The syntax for attribute declaration is exactly the same with what we have done when we declare methods. The syntax is like this :
[modifiers] type name_of_variable or [modifiers] type name_of_variable = [value].
  1. This form : [modifiers] type name_of_variable is only for declaring a variable without giving the the initial value of the variable.
  2. The other form is : [modifiers] type name_of_variable = [value] is for declaring a variable and GIVING it the initial value.
  3. [] (square bracket means anything inside this bracket is optional). Modifiers can be any java keywords. The most common are private, public, and static that we have encounter before.

In terms of its visibility a variable can be local if it is declared inside a method, it can only be seen inside the method where it is declared. But there is a slight difference if we compare that with the rules listed above. The syntax for declaring such variable is very short :
  1. type name_of_variable if you only want to declare a variable without initializing a value for it.
  2. type name_of_variable = valueif you need to declare an initial value.
    In fact WE ARE NOT ALLOWED to place a modifier (such as public, private, etc) when declaring a local variable.
So what is the type. Type represents the data type that can be stored in a memory are reserved for that variable. There are several types that will be of our interest :
  1. byte : the range of value is from -128 to 127 (8 bits long)
  2. short : the range of value is from -32,768 to 32,767 (16 bits long)
  3. int : the range of value is -2,147,483,648 to 2,147,483,647 (32 bits long)
  4. long : the range of value is -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (64 bits long).
  5. float : 32 bits floating point or real number point number.
  6. double : 64 bits floating point or real number point number.
  7. char : 8 bits long it holds a character value. At one point of time it store one only character.
  8. boolean : a variable of type boolean can only store a logical value true or false.
Before using any variables you have to declare them, then you can assign any value that matches to their type.
  • Examples for declaration of several variables without initialization :
float floatHeight;
int intStudentNumber;
char charGrade;

  • Examples for declaration of several variables WITH initialization :float
floatWeight = 100.24F;
int intMarbleCount = 20;
char charStudentGrade = 'A';
boolean boolIStillAlive = true;

A variable can only store one value at a time, but we can change it. We can change what is stored inside a variable by assigning a legal value to it. There are 4 ways to assign a value to a variable :

  • Assigning a value directly to a variable. Suppose a Grade of a student is F (fails he never studies) : charGrade = 'F';
  • The other way is by giving a value of another variable to one variable
charStudentGrade = 'F';
charGrade = charStudentGrade;

  • We can also assign the result of an arithmetic operation to a variable :
float floatUnitPrice = 100.12F;
float floatKgOrdered = 210.01F;
float floatTotalPrice = (floatUnitPrice * floatKgOrdered);

  • We can assign the result of a function execution to a variable. WE DO NOT HAVE ANY EXAMPLE FOR THIS YET.
Constant
Do we have another type of “variable” ? Yes it is called constant. A constant represents a value in a memory area that can not be changed at all. A constant is named with capital letters. Here is an example of a constant declaration :
final char TOP_GRADE = 'A';

A constant's value can not be changed forever and ever. Its value stays happily ever after.

Heap Memory and Stack Memory
Variables that are declared inside a method, known as local variables, are stored inside stack memory area, while attributes reside inside heap memory area. Heap memory stores any information about objects while they are needed by a program, while stack memory stores memory that are suitable for a short period of time.

Saturday, February 28, 2009

3 - Class Structure

Lets begin our discussion by refreshing our memory with hello world application. A simple one class program :
public class HelloJava // The class declaration
{

public static void main(String args[]) //The main method declaration
{
System.out.println("Hello Java : a cup of arabica and robusta blend");
}

}

Inside the program we have :
1.class declaration.
2.method declaration
3.Some comments

Every class inside our application must be declared. A Declaration is like telling the world that this class exists. By convention, class names begin with a capital letter, and usually I use uppercase letter for every word that is part of a class name. Lets disect our HelloJava class :
1.syntax for class declaration is [access_modifier] class class_identifier
2.access_modifier determines the accessibility of other classes to this class. Our access modifier is public so that this class is visible and accessible to other class
3.class identifier or better known as class name is HelloJava. Our class name is HelloJava.
4.Every java program must have one main() method. Our method is declared inside HelloJava class. Our main method comprises only one statement : System.out.println("Hello Java : a cup of arabica and robusta blend"). This statement will be executed during runtime.
5.In HelloJava we haven't got any variables yet.

Comments is good for documenting our logic of programming. Comments inside a java program takes the form of :
1.//. This type of comment may spans only one line of comments
2.Traditional comment just like in c language : begin with /* end with */. This type of comments may span several lines of comments.

Until now we haven't got any variable declaration. Now lets have a look at another examples : Triangle. We have two variables, which are public. base and height are public. It means they can be accessed and manipulated by another class.

public class Triangle
{
public float base = 0;
public float height = 0;

public void showTriangle()
{
System.out.println("Base : " + base);
System.out.println("Height : " + height);
System.out.println("Area : " + base*height/2);
}

}

Another interesting declaration is the method : showTriangle. It is public but it has a key word void. It means ON COMPLETION IT DOES NOT RETURN ANY VALUE. It has 3 statements that will be executed during run time.

2 - Multiclass Java Program

Now it is time for us to write application (simple one) with more than one class. The specification for our application is that we have a class that create an instance of another class. Our main class is called TriangleCreator, and the other class is called Triangle. TriangleCreator will create an instance of a Triangle.

The scenario for building such program is that we need to have a class that will be used by another class. The first class we need to write is Triangle class, the class that creates another class is called TriangleCreator. Now we have class Triangle that is depicted bellow :

public class Triangle

{


public float base = 0;
public float height = 0;

public void showTriangle()
{
System.out.println("Base : " + base);
System.out.println("Height : " + height);
System.out.println("Area : " + base*height/2);
}

}

what you have to do is the same with the other exercises we have done before :
1.Copy the source code.
2.Paste it into your text editor.
3.Save the program as Triangle.java IN YOUR WORKING DIRECTORY.

Next we need to have TriangleCreator class.

public class TriangleCreator
{

public static void main(String args[])
{
Triangle oTriangle;
oTriangle = new Triangle();
oTriangle.base = 10;
oTriangle.height = 10;
oTriangle.showTriangle();
}

}

Here is a list of action you need to do :
1.Copy the source code.
2.Paste it into your text editor.
3.Save the program as TriangleCreator.java IN YOUR WORKING DIRECTORY.
4.Compile the program using this command :javac TriangleCreator.java
5.After completing compilation process, a bytecode is produced : TriangleCreator.class
6.You run your program by executing this command : java TriangleCreator

In the next section we are going to discuss what we have done, discussing the syntax of making class.

Tuesday, February 24, 2009

1 - Introduction to Java Programming

Java is Object Oriented Programming Language. You can find many explanation of java environment and architecture somewhere else. This page is focusing on the programming example. If you see the examples in this page you will notice that a java program at least consist of a class declaration, method declaration, comments (if required/optional), and variable declaration (usually a class has several variables).

Our first program is hello java. The source code is presented below. All you have to do is copying and pasting it into your text editor, compile, and run the program :

public class HelloJava // The class declaration
{

public static void main(String args[]) //The main method declaration
{
System.out.println("Hello Java : a cup of arabica and robusta blend");
}

}


1. Copy the source code.
2. Paste it into your text editor.
3. Save the program as HelloJava.java IN YOUR WORKING DIRECTORY.
4. Compile the program using this command :javac HelloJava.java
5. After completing compilation process, a bytecode is produced : HelloJava.class
6. You run your program by executing this command : java HelloJava

We have more programming work to do. We are going to have another program that will print multiple lines of output. The source code is presented below. In case you are wondering what kopi luwak is Kopi luwak is coffe beans fermented inside the digestion system of a weasel like animal called luwak.

public class HelloKopiLuwak
{

public static void main(String args[])
{
System.out.println("Kopi Luwak : Exquisite Coffe produced by digestive system of ");
System.out.println("Paradoxurus hermaphroditusa, raccon-like animal." );
System.out.println("Perhaps it costs 300 or 400 dollars per kilo ");
}

}

1. Copy the source code.
2. Paste it into your text editor.
3. Save the program as HelloKopiLuwak.java IN YOUR WORKING DIRECTORY.
4. Compile the program using this command :javac HelloKopiLuwak.java
5. After completing compilation process, a bytecode is produced : HelloJavaKopiLuwak.class
6. You run the program by executing this command : java HelloKopiLuwak

We can also modify the program so that instead of having 3 println statements. We only need one.

public class HelloKopiLuwakModified
{

public static void main(String args[])
{
System.out.println("Kopi Luwak : Exquisite Coffe produced by digestive system of\nParadoxurus hermaphroditusa, raccon-like animal\nPerhaps it costs 300 or 400 dollars per kilo ");
}

}

Then what you have to do is :
1. Copy the source code.
2. Paste it into your text editor.
3. Save the program as HelloKopiLuwakModified.java IN YOUR WORKING DIRECTORY.
4. Compile the program using this command :javac HelloKopiLuwakModified.java
5. After completing compilation process, a bytecode is produced : HelloKopiLuwakModified.class
6. You run the program by executing this command : java HelloKopiLuwakModified

Until now, we only have one class. A one class program is fine inside classroom. But in actual world you need to have several classes. How to make such construct will be discussed on the next section of Java Programming.

Sunday, February 8, 2009

Serial Port Programming : Sender and Receiver

The required equipment required consists of :
1. DB-9 null modem. The null modem that you need to use is loop type null modem.
2. USB to serial port converter.

Now we are going to write a program that act as a data sender. Data is sent through the serial port. Basically program consists of several activities :
1.turning on a null modem.
2.setting up program's action on incoming package.
3.setting up program's output mode.
4.setting up program's connection control flag :
1.Baudrate is 4800 BPS (B4800) .
2.Enable RTS/CTS (hardware) flow control (CRTSCTS) .
3.Ignore modem control lines (CLOCAL) .
4.Character size mask is 8 (CS8).
5.flushing the modem line.
6.initiating the modem.
7.sending data through the modem line. the data is system's time.

Of course you need to have a receiver. wich is also a program. What makes the receiver different from the sender is the loop that reads data input :
for(;;)
{
read(fd,&c,1); /* reads the null modem */
write(1, &c,1); /* prints input to the screen */
}

before running any program you really need to alter the status of your null modem device (after you plug in it)), so that it can be read and written on. REMEMBER ALL SERIAL COMMUNICATION DEVICES IS TREATED AS FILE. You have to make it readable and writable. Beside that you need to have a null modem :
1. For changing the permission of ttyS0 you need to execute : #sudo chmod 777 /dev/ttyS0
2. For changing the permission of ttyUSB0 you need to execute : #sudo chmod 777 /dev/ttyUSB0

Now first we have a sender's source code. We assume program below uses Serial Port 0.

#include "termios.h" /*this file contains declaration of required functions and types*/
#include "stdio.h" /*you know what this is*/
#include "fcntl.h" /*this file constains declaration for O_RDWR and O_NOCTTY)*/
#include "time.h" /*this file contains time's operatives*/


int main(void)
{
int i, j, s;
char t[9];
time_t ttrs;
struct tm *ti;
int fd; /*variable of type integer used as descriptor to a serial port*/
char c;
struct termios termiosA; /*declaring a variable of type termios*/
/* Turn on the null modem */
fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY); /* I have done : sudo chmod 777 /dev/ttyS0 */


/* We don't care about incoming bytes with parity on data input */
termiosA.c_iflag = IGNPAR;

/*
Raw output.
*/
termiosA.c_oflag = CR0; /* output modes */

/*
we are going to set a connection with serial port to the receiver (this computer is a sender)
1. Baudrate is 4800 BPS (B9600)
2. Enable RTS/CTS (hardware) flow control (CRTSCTS)
3. Ignore modem control lines (CLOCAL)
4. Character size mask is 8 (CS8)
*/
termiosA.c_cflag = B4800 | CRTSCTS | CLOCAL | CS8; /* control flags */


/* flush the modem line */
tcflush(fd, TCIFLUSH);

/* initiate the modem */
tcsetattr(fd,TCSANOW,&termiosA);

/* Now its time to send something. */
i = 0;
for (;;)
{
time(&ttrs);
ti=localtime(&ttrs);
if (s != ti->tm_sec)
{
printf("Sending time data : %s", t);
sprintf(t, "%d:%d:%d\n", ti->tm_hour, ti->tm_min, ti->tm_sec);
s = ti->tm_sec;
for (j = 0; j < 9;j++)
{
write(fd, t[j], 1);
}
return 0;
}

Next we have a receiver program. The receiver uses USB port 0. :

#include "termios.h" /*this file contains declaration of required functions and types*/
#include "stdio.h" /*you know what this is*/
#include "fcntl.h" /*this file constains declaration for O_RDWR and O_NOCTTY)*/

int main()
{
int fd; /*variable of type integer used as descriptor to a serial port*/
char c;
struct termios termiosA; /*declaring a variable of type termios*/
/* Turn on the null modem */
fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY); /* I have done : sudo chmod 777 /dev/ttyUSB0 */


/* We don't care about incoming bytes with parity on data input */
termiosA.c_iflag = IGNPAR;

/*
Raw output.
*/
termiosA.c_oflag = CR0; /* output modes */

/*
we are going to set a connection with serial port to the sender (this computer is a receiver)
1. Baudrate is 4800 BPS (B4800)
2. Enable RTS/CTS (hardware) flow control (CRTSCTS)
3. Ignore modem control lines (CLOCAL)
4. Character size mask is 8 (CS8)
*/

termiosA.c_cflag = B4800 | CRTSCTS | CLOCAL | CS8; /* control flags */

/*The change to the line's state takes effect straight away*/
/* flush the modem line and initiate the modem */
tcflush(fd, TCIFLUSH);
tcsetattr(fd,TCSANOW,&termiosA);
/* input is handled by the loop below */

for(;;)
{
read(fd,&c,1); /* reads the null modem */
write(1, &c,1); /* prints input to the screen */
}

}

Now what you need to do is to compile and run each program and see the result. Good luck

Wednesday, January 21, 2009

errno : C Error Handling

Whatever programming you are doing. It's nice to have a feedback if something goes wrong in your program. Basically a c program would capture error message value generated by system's environment. Bellow is a rudimentary function that capture error handling.
#include "error.h"
#include "errno.h"
#include "stdio.h"

void errordisplay(int error)
{
switch (error)
{
case E2BIG : printf("E2BIG");break;
case EACCES : printf("EACCES");break;
case EADDRINUSE : printf("EADDRINUSE");break;
case EADDRNOTAVAIL : printf("EADDRNOTAVAIL");break;
case EAFNOSUPPORT : printf("EAFNOSUPPORT");break;
/*case EAGAIN : printf("EAGAIN");break;*/
case EALREADY : printf("EALREADY");break;
case EBADE : printf("EBADE");break;
case EBADF : printf("EBADF");break;
case EBADFD : printf("EBADFD");break;
case EBADMSG : printf("EBADMSG");break;
case EBADR : printf("EBADR");break;
case EBADRQC : printf("EBADRQC");break;
case EBADSLT : printf("EBADSLT");break;
case EBUSY : printf("EBUSY");break;
case ECANCELED : printf("ECANCELED");break;
case ECHILD : printf("ECHILD");break;
case ECHRNG : printf("ECHRNG");break;
case ECOMM : printf("ECOMM");break;
case ECONNABORTED : printf("ECONNABORTED");break;
case ECONNREFUSED : printf("ECONNREFUSED");break;
case ECONNRESET : printf("ECONNRESET");break;
/*case EDEADLK : printf("EDEADLK");break;*/
case EDEADLOCK : printf("EDEADLOCK");break;
case EDESTADDRREQ : printf("EDESTADDRREQ");break;
case EDOM : printf("EDOM");break;
case EDQUOT : printf("EDQUOT");break;
case EEXIST : printf("EEXIST");break;
case EFAULT : printf("EFAULT");break;
case EFBIG : printf("EFBIG");break;
case EHOSTDOWN : printf("EHOSTDOWN");break;
case EHOSTUNREACH : printf("EHOSTUNREACH");break;
case EIDRM : printf("EIDRM");break;
case EILSEQ : printf("EILSEQ");break;
case EINPROGRESS : printf("EINPROGRESS");break;
case EINTR : printf("EINTR");break;
case EINVAL : printf("EINVAL");break;
case EIO : printf("EIO");break;
case EISCONN : printf("EISCONN");break;
case EISDIR : printf("EISDIR");break;
case EISNAM : printf("EISNAM");break;
case EKEYEXPIRED : printf("EKEYEXPIRED");break;
case EKEYREJECTED : printf("EKEYREJECTED");break;
case EKEYREVOKED : printf("EKEYREVOKED");break;
case EL2HLT : printf("EL2HLT");break;
case EL2NSYNC : printf("EL2NSYNC");break;
case EL3HLT : printf("EL3HLT");break;
case EL3RST : printf("EL3RST");break;
case ELIBACC : printf("ELIBACC");break;
case ELIBBAD : printf("ELIBBAD");break;
case ELIBMAX : printf("ELIBMAX");break;
case ELIBSCN : printf("ELIBSCN");break;
case ELIBEXEC : printf("ELIBEXEC");break;
case ELOOP : printf("ELOOP");break;
case EMEDIUMTYPE : printf("EMEDIUMTYPE");break;
case EMFILE : printf("EMFILE");break;
case EMLINK : printf("EMLINK");break;
case EMSGSIZE : printf("EMSGSIZE");break;
case EMULTIHOP : printf("EMULTIHOP");break;
case ENAMETOOLONG : printf("ENAMETOOLONG");break;
case ENETDOWN : printf("ENETDOWN");break;
case ENETRESET : printf("ENETRESET");break;
case ENETUNREACH : printf("ENETUNREACH");break;
case ENFILE : printf("ENFILE");break;
case ENOBUFS : printf("ENOBUFS");break;
case ENODATA : printf("ENODATA");break;
case ENODEV : printf("ENODEV");break;
case ENOENT : printf("ENOENT");break;
case ENOEXEC : printf("ENOEXEC");break;
case ENOKEY : printf("ENOKEY");break;
case ENOLCK : printf("ENOLCK");break;
case ENOLINK : printf("ENOLINK");break;
case ENOMEDIUM : printf("ENOMEDIUM");break;
case ENOMEM : printf("ENOMEM");break;
case ENOMSG : printf("ENOMSG");break;
case ENONET : printf("ENONET");break;
case ENOPKG : printf("ENOPKG");break;
case ENOPROTOOPT : printf("ENOPROTOOPT");break;
case ENOSPC : printf("ENOSPC");break;
case ENOSR : printf("ENOSR");break;
case ENOSTR : printf("ENOSTR");break;
case ENOSYS : printf("ENOSYS");break;
case ENOTBLK : printf("ENOTBLK");break;
case ENOTCONN : printf("ENOTCONN");break;
case ENOTDIR : printf("ENOTDIR");break;
case ENOTEMPTY : printf("ENOTEMPTY");break;
case ENOTSOCK : printf("ENOTSOCK");break;
/*case ENOTSUP : printf("ENOTSUP");break;*/
case ENOTTY : printf("ENOTTY");break;
case ENOTUNIQ : printf("ENOTUNIQ");break;
case ENXIO : printf("ENXIO");break;
case EOPNOTSUPP : printf("EOPNOTSUPP");break;
case EOVERFLOW : printf("EOVERFLOW");break;
case EPERM : printf("EPERM");break;
case EPFNOSUPPORT : printf("EPFNOSUPPORT");break;
case EPIPE : printf("EPIPE");break;
case EPROTO : printf("EPROTO");break;
case EPROTONOSUPPORT : printf("EPROTONOSUPPORT");break;
case EPROTOTYPE : printf("EPROTOTYPE");break;
case ERANGE : printf("ERANGE");break;
case EREMCHG : printf("EREMCHG");break;
case EREMOTE : printf("EREMOTE");break;
case EREMOTEIO : printf("EREMOTEIO");break;
case ERESTART : printf("ERESTART");break;
case EROFS : printf("EROFS");break;
case ESHUTDOWN : printf("ESHUTDOWN");break;
case ESPIPE : printf("ESPIPE");break;
case ESOCKTNOSUPPORT : printf("ESOCKTNOSUPPORT");break;
case ESRCH : printf("ESRCH");break;
case ESTALE : printf("ESTALE");break;
case ESTRPIPE : printf("ESTRPIPE");break;
case ETIME : printf("ETIME");break;
case ETIMEDOUT : printf("ETIMEDOUT");break;
case ETXTBSY : printf("ETXTBSY");break;
case EUCLEAN : printf("EUCLEAN");break;
case EUNATCH : printf("EUNATCH");break;
case EUSERS : printf("EUSERS");break;
case EWOULDBLOCK : printf("EWOULDBLOCK");break;
case EXDEV : printf("EXDEV");break;
case EXFULL : printf("EXFULL");break;
}
}

int main(void)
{
int err;
FILE *fp = NULL;
if (fp=fopen("SSS","r")==NULL)
{
err = errno;
}
errordisplay(err);
return 0;
}

After compiling and running this program you notice that it will display the error message, wich is originally is an integer value. I copied, pasted and edited that error messages from errno.h header file (/usr/include/errno.h) :

browse@joko-desktop:~/Desktop$ gcc -o errprog.o errprog.c
errprog.c: In function ‘main’:
errprog.c:135: warning: assignment makes pointer from integer without a cast
browse@joko-desktop:~/Desktop$ ./errprog.o
ENOENTbrowse@joko-desktop:~/Desktop$

Hopefully this will help you in catching logical error in long programs that have many interfaces to another entities. WISH YOU LUCK

Tuesday, January 20, 2009

termios : a prelude to serial port programming

If you like to make a serial port program, you need to use functions and structures declared inside /usr/include/termios.h (be aware it uses another header file /usr/include/bits/termios.h). The first thing that you need to understand is a data structure declared inside /usr/include/bits/termios.h :
struct termios
{
tcflag_t c_iflag; /* input mode flags */
tcflag_t c_oflag; /* output mode flags */
tcflag_t c_cflag; /* control mode flags */
tcflag_t c_lflag; /* local mode flags */
cc_t c_line; /* line discipline */
cc_t c_cc[NCCS]; /* control characters */
speed_t c_ispeed; /* input speed */
speed_t c_ospeed; /* output speed */
#define _HAVE_STRUCT_TERMIOS_C_ISPEED 1
#define _HAVE_STRUCT_TERMIOS_C_OSPEED 1
};

Inside that structure we see the names of other types : tcflag_t, cc_t, and speed_t. What they really are of type char and unsigned int :
1.typedef unsigned char cc_t;
2.typedef unsigned int speed_t;
3.typedef unsigned int tcflag_t;

Now lets disect what are inside the termios (These values are declared inside /usr/include/bits/termios.h) :
1. The posibble values for c_iflag
/* c_iflag bits */
#define IGNBRK 0000001
#define BRKINT 0000002
#define IGNPAR 0000004
#define PARMRK 0000010
#define INPCK 0000020
#define ISTRIP 0000040
#define INLCR 0000100
#define IGNCR 0000200
#define ICRNL 0000400
#define IUCLC 0001000
#define IXON 0002000
#define IXANY 0004000
#define IXOFF 0010000
#define IMAXBEL 0020000
#define IUTF8 0040000

2. The possible values for c_oflag :
/* c_oflag bits */
#define OPOST 0000001
#define OLCUC 0000002
#define ONLCR 0000004
#define OCRNL 0000010
#define ONOCR 0000020
#define ONLRET 0000040
#define OFILL 0000100
#define OFDEL 0000200
#if defined __USE_MISC || defined __USE_XOPEN
# define NLDLY 0000400
# define NL0 0000000
# define NL1 0000400
# define CRDLY 0003000
# define CR0 0000000
# define CR1 0001000
# define CR2 0002000
# define CR3 0003000
# define TABDLY 0014000
# define TAB0 0000000
# define TAB1 0004000
# define TAB2 0010000
# define TAB3 0014000
# define BSDLY 0020000
# define BS0 0000000
# define BS1 0020000
# define FFDLY 0100000
# define FF0 0000000
# define FF1 0100000
#endif
#define VTDLY 0040000
#define VT0 0000000
#define VT1 0040000
#ifdef __USE_MISC
# define XTABS 0014000
#endif

3. The possible values for c_cflag :
/* c_cflag bit meaning */
#ifdef __USE_MISC
# define CBAUD 0010017
#endif
#define B0 0000000 /* hang up */
#define B50 0000001
#define B75 0000002
#define B110 0000003
#define B134 0000004
#define B150 0000005
#define B200 0000006
#define B300 0000007
#define B600 0000010
#define B1200 0000011
#define B1800 0000012
#define B2400 0000013
#define B4800 0000014
#define B9600 0000015
#define B19200 0000016
#define B38400 0000017
#ifdef __USE_MISC
# define EXTA B19200
# define EXTB B38400
#endif
#define CSIZE 0000060
#define CS5 0000000
#define CS6 0000020
#define CS7 0000040
#define CS8 0000060
#define CSTOPB 0000100
#define CREAD 0000200
#define PARENB 0000400
#define PARODD 0001000
#define HUPCL 0002000
#define CLOCAL 0004000
#ifdef __USE_MISC
# define CBAUDEX 0010000
#endif
#define B57600 0010001
#define B115200 0010002
#define B230400 0010003
#define B460800 0010004
#define B500000 0010005
#define B576000 0010006
#define B921600 0010007
#define B1000000 0010010
#define B1152000 0010011
#define B1500000 0010012
#define B2000000 0010013
#define B2500000 0010014
#define B3000000 0010015
#define B3500000 0010016
#define B4000000 0010017
#define __MAX_BAUD B4000000
#ifdef __USE_MISC
# define CIBAUD 002003600000 /* input baud rate (not used) */
# define CMSPAR 010000000000 /* mark or space (stick) parity */
# define CRTSCTS 020000000000 /* flow control */
#endif


4. The possible values for c_lflag :
/* c_lflag bits */
#define ISIG 0000001
#define ICANON 0000002
#if defined __USE_MISC || defined __USE_XOPEN
# define XCASE 0000004
#endif
#define ECHO 0000010
#define ECHOE 0000020
#define ECHOK 0000040
#define ECHONL 0000100
#define NOFLSH 0000200
#define TOSTOP 0000400
#ifdef __USE_MISC
# define ECHOCTL 0001000
# define ECHOPRT 0002000
# define ECHOKE 0004000
# define FLUSHO 0010000
# define PENDIN 0040000
#endif
#define IEXTEN 0100000