EmbLogic's Blog

article on c

PROJECT01(C-PROGRAMMING BASED PROJECT)

Project01-c based programming language,basically to articulate concepts regarding “C Programming”.It is basically a middle level language.Being an electronics engineer,it is one of the basic and important language as far as my career is concerned.It mainly comprises the information about the following:

1.Basics: declaration of variables,data types,arithmetic operations,operators ,

2.Control statements:(if-else statements,switch statements).

3.Loops: (for loop,do-while loop,while loop).

4.Functions.

5.Pointer

6.Arrays &strings.

With the help this project Pointer, is my favourite topic in “c”,as I used to scare and run away about studying it.But after having the basic knowledge of “C”and dwelling myself on the basics of “c”, but now I’m able to understand  it and tries to implement every program with pointer.This project focus on each and every basic of the c-programming.

Pointer is a variable which holds the address of another variable.

Syntax:

Data type*p;

“*” denotes it’s a pointer.

We can access the address the address of another variable and can manipulate the value of that variable.The base address of any string or array or any variable can be assigned to it.

Ex:

Char *p;

p=”hello”;//the base address of the string is assigned to it

Besides this,I have covered about the following:

1.About  the operators(arithmetic,logical operators).

2.control statements

  • Ø If-else statements and switch case : it checks the particular expression and execute the block of statements respectively.
  • Ø The merit of it is, we can run the application in user defined mode.
  • Ø In switch case ,particularly provides the number of case and if the user or programmer values match with its case,then it executes its respective case.

3.Loop:

  • Ø For loop : it basically used,when we know how many times a particular block of statements have to execute.

Syntax:  for(initialization;condition;updation);

  • Ø While loop: its known as the entry-controlled loop,means condition must be true to execute the block of statements.

Syntax:  while(condition)

  • Ø Do-while loop: it’s a exit controlled loop.That is it execute the block of statements for the 1st time irrespective of the condition.

4. File IO: file input output. It is of two types: low level and high level.

  • Ø Low level is ued at Application level.

5. Array: it’s a collection of elements of same data type which has continous memory location.

6.link-list: it’s a linear data structure.

7. Searching and sorting:

  • Ø Linear search: it is more complex ,as number of comparison is more.
  • Ø Binary search: it has less number of comparison.

7.MDC: Multiple data compression,which is the main objective of this project. In this storage space for the data is being compressed.

  • Ø It basically eliminate repeated characters and make the array of unique characters.
  • Ø By which we have the code length,which denotes the number of bits for a character to be stored in the memory.

Hence,by this project ,we will be able to compress the data.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

PROJECT01(C-PROGRAMMING BASED PROJECT)

Project01-c based programming language,basically to articulate concepts regarding “C Programming”.It is basically a middle level language.Being an electronics engineer,it is one of the basic and important language as far as my career is concerned.It mainly comprises the information about the following:

1.Basics: declaration of variables,data types,arithmetic operations,operators ,

2.Control statements:(if-else statements,switch statements).

3.Loops: (for loop,do-while loop,while loop).

4.Functions.

5.Pointer

6.Arrays &strings.

With the help this project Pointer, is my favourite topic in “c”,as I used to scare and run away about studying it.But after having the basic knowledge of “C”and dwelling myself on the basics of “c”, but now I’m able to understand  it and tries to implement every program with pointer.This project focus on each and every basic of the c-programming.

Pointer is a variable which holds the address of another variable.

Syntax:

Data type*p;

“*” denotes it’s a pointer.

We can access the address the address of another variable and can manipulate the value of that variable.The base address of any string or array or any variable can be assigned to it.

Ex:

Char *p;

p=”hello”;//the base address of the string is assigned to it

Besides this,I have covered about the following:

1.About  the operators(arithmetic,logical operators).

2.control statements

  • Ø If-else statements and switch case : it checks the particular expression and execute the block of statements respectively.
  • Ø The merit of it is, we can run the application in user defined mode.
  • Ø In switch case ,particularly provides the number of case and if the user or programmer values match with its case,then it executes its respective case.

3.Loop:

  • Ø For loop : it basically used,when we know how many times a particular block of statements have to execute.

Syntax:  for(initialization;condition;updation);

  • Ø While loop: its known as the entry-controlled loop,means condition must be true to execute the block of statements.

Syntax:  while(condition)

  • Ø Do-while loop: it’s a exit controlled loop.That is it execute the block of statements for the 1st time irrespective of the condition.

4. File IO: file input output. It is of two types: low level and high level.

  • Ø Low level is ued at Application level.

5. Array: it’s a collection of elements of same data type which has continous memory location.

6.link-list: it’s a linear data structure.

7. Searching and sorting:

  • Ø Linear search: it is more complex ,as number of comparison is more.
  • Ø Binary search: it has less number of comparison.

7.MDC: Multiple data compression,which is the main objective of this project. In this storage space for the data is being compressed.

  • Ø It basically eliminate repeated characters and make the array of unique characters.
  • Ø By which we have the code length,which denotes the number of bits for a character to be stored in the memory.

Hence,by this project ,we will be able to compress the data.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Posted in Uncategorized | Leave a comment

E-30.01.30:Embedded OS Porting on Olinuxino Board

Porting of Embedded OS on Olinuxino Board

Embedded OS:

Embedded Operating System is simply a light version of complete OS ,means in embedded OS we reduce some functionality from the OS according to the our requirement like if we don’t want to use the USB camera then we disable it. We can put applications according to the requirement which decrease the overhead of OS.

Porting:

Porting is the process in which we put compiled software in the target machine (in my case arm based olinuxino board )after developing it on the host machine like x86.

Note: I have used x86 machine for development because it is faster than the ARM based system.

Why Olinuxino Board???

Many boards are used for development purpose but i have used Olinuxino board ( by Olimex )due to below positive points:

Open source

Open hardware

Complete documentation is freely available on the network.

Some main features:

1.Ghz Processor(A13 Cortex A8 by Allwinner Technologies China) speed.

2.3D mali 400 GPU.

3.VGA video output.

4.Touch screen interface.

5.512 MB RAM

6.GPIO pins.

7.SD card slot.

Primary Requirements for Board Bring Up:

For standing up our system we need below softwares.

1.Tool chain

2.Secound stage boot loader(u-boot)

3.Kernel Image(uImage)

4.Debian Root file system.

*All the above packages are free available on the internet to download.

Brief Note On development Process:

Tool chain is used to cross compile all the packages on the x86 machine according to the ARM based system.

So I cross compiled firstly kernel before selecting required functionalitie by menuconfig.

After that I cross compile U-boot which is second stage boot loader and required to load the kernel image on the RAM for execution.

Card Partitioning:

Card partitioning is essential in the board bringing up to partition the card and making appropriate file system because at the initial stage of the system boot up ,system can’t support the heavy file system like ext 2 or ext3 due to absence of kernel.

So we make first partition of 16MB of vfat file system and rest memory of ext3 file system.

I partitioned the card using “fdisk” utility.

Porting On MMC Card:

1.Using “dd” command i placed the sunxi-spl.bin and u-boot.bin from the u-boot to the unpartitioned space which is after the 8kb and before 1MB respectively.

2.Now I simply copied the uImage and script.bin to the first partition of 16MB

3.At last in the secound partition i uncompressed the archive image of debian root file system.

After this my card was ready to boot up on the olinuxino board

 

Thanks

Avtar Singh

Posted in Uncategorized | Leave a comment

ipc mechanism using pipes

PROJECT-03(IPC USING PIPES)

As per the project-03 class from “IPC”  using “PIPES”.This process is based on IPC technique.It is inter process communication which is create a client server setup.It is a client server programming.

There are four types of IPC’s
>>Pipes
>>Fifo’s
>>MesageQueues
>>Shared Memory

Here it is a low level programming language which it is define as:

>>can operate in resource constraint enviroment
>>run time library
>>It is very efficient
>>memory access and control flow
>>debugging can be difficult it can not be possible to run the program.

PIPES:It use the term pipe when it connect the data flow one  process to another.Generally it attach pipe the output of the process  to the input of the another.

In this mechanism limitd facilities are available.Here should be a server program one client shoud be a send request and the other server would find the client to process the request to server after it invokes the new client so as to process the request.There should be a new client then send a result back to the server,which after it sends data forward to the requesting client.In this process we must use the low level these are file descriptor[fd] so read and write call to access the data rather than fread and fwrite.

In IPC here can be use two methods in pipes:

>>Fork
>>Execl

FORK:It is a function fork()which is used to generate the process and it is used in inter process communication as ret=fork().When we get fork then fork is made two process named “parent id” and ‘child id’ which has same address.

EXECL:Execl() is used to invoke the pipe program through which server will get the client.the argument to execl are:

>>The program to invoke
>>argv[0],which takes the program name
>>aggv[1],which contains the file discriptor number we want the program to read from
>>(char *)0,which terminates the parameters.

Posted in Uncategorized | Leave a comment

Article on C

PROJECT 01(C-Programming based project)

This project is totally based on C language as the name suggests .It is a middle level language , basically it is a compiler dependent. Being an engineer this C language is a very paramount part of a technical skills of an engineer. Moreover there is a C based project i.e. “Multiple Data Compression” in data is compressed and prepared it in encrypted form. This project teaches how to

use C and how to execute it at an industry level projects.

MULTIPLE DATA COMPRESSION(MDC): Main aim of this project is to encode data to take up less storage space and less bandwidth for transmission. Digital data are compressed by finding repeatable patterns of binary 0s and 1s.

Data compression is particularly useful in communications because it enables devices to transmit or store the same amount of data in fewer bits. There are a variety of data compression techniques, but only a few have been standardized.

Encryption is the conversion of data into a form, called a cipher text, that cannot be easily understood by unauthorized people. Decryption is the process of converting encrypted data back into its original form, so it can be understood.

In Project 01, we started from scratch. We covered all individuals topics in C one by one and went through almost all aspects of every topics. We also interrelate different topics with each other such as

pointers with structures, array with pointers etc.

We covered all these topics one by one:

  1. First of all, we come to know about all basics syntax and semantics , keywords, constants of C languages . Memory allocation in C language . We come to know how memory is allocated to different data types? Mainly we come to know the style of programming , value of indentation, value of memory, how to write big and big programmes in lesser lines.

  2. We covered many topics:

    • Conditional statements: it is used when we want to execute a particular set of statements followed by a particular condition. There are basically three types of conditional statements:

      • IF ,IF-ELSE

      • SWITCH

      • USING RELATIONAL OPERATORS

  • Control structures: loops – It is basically using a particular set of statements for a number of times iteratively. There are basically three types of control structures:

    • FOR- for(initilization, condition,increment/decrement)

    • WHILE- initilization

      while(condition)

      { set of statements

      increment/decrement}

  • DO-WHILE- do{ set of statements}

    while(condition);

  • Arrays and Strings: Array is a collection of same data type stored in a continuous memory locations.

    String is collection of same data type i.e. Character data type stored in a continuous memory location and strings are stored in stack memory.

  • Pointers: It is a variable which holds the address of another variable . It always occupies 4 bytes of memory irrespective of its mentioned data type. Mentioned data type just indicate about the type of variable whose address is stored in pointer type variable.

  • Another topics related to C are FILE IO: File input output system. It is of two types: Low level and high level

    STRUCTURES AND UNIONS, LINKED LIST, STACKS AND QUEUES , FUNCTIONS , SEARCHING AND SORTING TECHNIQUES.

  • There are various project management tools:

    CVS- Concurrent Version System

RCS- Revision Control System

MAKE FILE- multiple targets in one file

GDB-GNU Debugger

Posted in Project 2: Multiple Data Compression and Encryption | Leave a comment

Serial Communication:

Serial Interface is one of the most commonly used interface in Embedded Systems, during development and in field also. Almost every machine have a serial port over it. So that it could be connected to some peripheral or another Embedded System.

Types of Serial Communication:

1)Synchronous: In Master/Slave interface, both master and slave are driven with same clock(master clock). So this interface is termed as synchronous.
2)Asynchronous: In Point to Point or peer interfaces clock need not to be synchronized between DTE(Data Terminal Equipment) and DCE(Data Communication Equipment). Most of the peer interfaces are asynchronous.

Why Serial???

As every Embedded System has to communicate with external world, it could be some peripheral device or another system for debugging purpose. And Serial interface serves as the best due to many reasons.

1)Small number of pins needed (2 or 3).
2)Availability of different protocols for different interfaces.
3)Good for long distance communication.
4)High Speed.

Protocols:

There are many different serial protocols for different interfaces. Most popular ones are,
RS232, SPI, I2C CAN. Depending upon the application we can select the most appropriate one.
RS232 is commonly used for debugging purpose. Max possible speed is 115.2 kbps.
SPI(Serial Peripheral Interface) is as its name suggest used to interface peripherals. It is a Mater/Slave Synchronous protocol.
I2C(Inter IC) is commonly used to interface, on board peripherals(IC). It is a multi master synchronous protocol.
CAN is used for Inter MCU(micro controller unit) communication in a System. For example it is used in vehicle where number of MCUs are used to serve different purposes.

Posted in Uncategorized | Leave a comment

Character Device Driver

Character Driver

 

Device drivers are building blocks of a OS. In Linux there are three types of device driver i.e.

  • Character Driver

  • Block Driver

  • Pipes Driver

Device driver are used to make hardware do a specific job with some defined set of rules and they hide the working procedure of hardware from the outside world. Device drivers as implemented as loadable kernel module means you can add a drive at any instance of time.

Character drivers are used to access streams of byte at one by one. Some example of char driver are text console, serial port, USB keyboard etc. Before working with driver, driver must be registered with kernel so that driver can be inserted as lkm module. Driver communicate using node in file-system.

For using the char device, there should be one entry point which will start the driver and there should be one exit point which will be used to remove the driver from the list of installed modules. For this there are two macro’s defined in kernel for char driver. They are module_init() and module_exit(). They take the __init and __exit functions as there arguments. After this the lkm is inserted using the insmod command and lkm is removed using the rmmod command.

To access the device using node,system provides the Major and Minor numbers. To get the Major and Minor numbers, the driver for lkm is registered with kernel using alloc_chrdev_region(if no major number is allocated) and register_chrdev_region(if major number for the device driver is already obtained). It takes the dev_t type variable, no of device, module name and starting minor number as argument and fills the dev_t type variable with the major number allocated to the device. dev_t is a 32 bit variable who’s upper 12 bit represents the major number and lower 20 bits represents the minor number. To get major and minor number separately kernel symbol table provides the two macro’s i.e. MAJOR() and MINOR() which takes the dev_t as argument. The major number is number provided to the device driver and the minor number is used to specify the specific device using the the driver. Device can be freed using the unregistered_chrdev_region which take the dev_t type as argument.

Char device memory is accessed using the scull. Scull stands for simply character utility for loading localities. Scull is implemented as a link list. Scull is represents as

struct scullqset

{

void **;

struct scullqset *next

};

struct sculldev

{

struct scullqset *qset;

//data

};

Sculldev contains the attribute of the devices like quantum size, qset size, device size, date size and some flag etc where as scullqset contains the data present in device. It has a void ** which is used to save data.

Scull device is added to the modules using the cdev_init and cdev_add. cdev_init initialize the file operation that are gonna work on the device and cdev_add adds them into the module. cdev_add creates the node in file-system for the device. Every device, who uses driver is registered and added to kernel modules before any other operations. Modules are removed using cdev_del.

Every device provides some basic operations like open, close, read, write etc… these function are mapped to the standard functions in file_operation structure and are already added at the time cdev_add.

When a device is opened, a special micro is used called CONTAINER_OF which creates a mapping for the outside memory device in form of scull. The obtained scull pointer is stored into private_data variable of the file_operation structure. After that the mode of open is checked, if opened in write-only mode, then previous mapping of the device is removed and cleaned.

In write operation, sculldev is loaded from the file stream’s private_data. memory is allocated for the amount of data to be written. The write function uses the micro provided by the kernel to copy data from the user application using copy_from_user function. This function copies the data from user space to kernel space and put it into the device memory using scull. copy_from_user return the numbers of bytes not copied. After successful copy, the device attributes is updated.

Read operation is also similar like write operation with difference is it uses copy_to_user function for reading the data from scull memory to user application.

llseek operation is used to set the offset from where read or write operation is to be performed by updating the f_pos value.

Posted in Character Driver, Device Drivers | Leave a comment

VIRTUAL MEMORY(NIRAJ KUMAR)

Virtual memory

 

 

lets an operating system needs 120mb of memory in order to hold the running program

but there is only 50mb of available physical memory stored on RAM chips. The operating system will then setup 120mb of virtual memory and will use a program called the virtual memory manager(VMM) to manage that 120mb. The VMM will create a file

on the hard disk that is 70mb in size to account for the extra memory that is needed. The

operating system will now proceed to address memory as if there were actually 120mb of real memory stored on the RAM. Even though there is really only 50mb. So to the operating system it now appears as if the full 120mb actually exists. It is the responsibility of the VMM to deal with the fact that there is only 50mb of real memory.

 

The paging file and RAM:

 

The virtual memory manager creates a file on the hard disk to hold the extra memory that is needed by operating system this file is called a paging file (also known as swap file).

 

If the size of virtual memory is quite larger than real memory then more swapping to and from the hard disk will occur as a result. Accessing the hard disk is far slower than using system memory.

 

 

With virtual memory multitasking is passible even when there is not enough memory to hold all executing program at once.

 

 

 

Posted in Uncategorized | Leave a comment

Article on multiple data compression and expansion using iterative technique by sumit sharma(E-34)

MULTIPLE DATA COMPRESSION AND EXPANSION USING ITERATIVE TECHNIQUE

Since we know that in almost all embedded devices there is memory constraint. So there should be judicious use of the available memory. So here i am discussing how to compress and expand the compressed data using iterative technique and save memory.

Since the size of char is 1 byte so it could be used to represent 256 different characters. But in how many of our files do we actually have 256 different characters . So taking the advantage over this fact we could actually compress our data.

The first step towards compressing data is to create a master array which contains the different characters that exists in our file. So if for example in our 100 character file there are only 15 different characters then master array would be of size 15. Then taking a step further in order to compress data we need to assign an index to each of the member of master array with minimum number of bits required to represent all of the members of the master array. In our case of 15 characters we could represent each member with only with 4bits rather than 8bits which were used earlier.

So after providing each member of the master array with a unique index of 4 bits each we move on to the next step. We then need to access each element of our text file and map that element with the master array and find out its unique index value. The value which we provided is of 4 bits so we could actually combine the index values of two elements and form an compressed byte which actually contains two of characters from the file in the space of 1 character. Thus effective we are saving 50% of our memory.

For example:

Data to compress: helo to linux.

Master array :helo tinux.

So here we need 4 bits to represent each member of masater array.

Elements : unique index

h : 0000

e : 0001

l : 0010

o : 0011

: 0100

t : 0101

i : 0110

n : 0111

u : 1000

x : 1001

. : 1010

Now while accessing each element of in order to compress it first we access ‘h’ it has index of 0000 but in order to represent it in character form we need 8 bits so we access another character ‘e’ with index 0001 and combine both 0000 and 0001 in order to form 8 bit character.

Actually it will be implemented like this:

we will assign h with 0 and e with 1 in unsigned char form.

so

h=00000000

e=00000001

Since we know that only lower 4 bits of h are significant and so are of e ,so we left shift the bits of h by 4(though there is no significance of this step but if it would not have been 0 then it is a must step) and OR both h and e.

We get 00000001 where upper 4 bits represent ‘h’ and lower 4 bits represent ‘e’.

For the next two elements :

l : assigned with 3 i.e 00000011

o : assigned with 4 i.e 00000100

On left shifting ‘l’ and Oring both we get 00110100

On the left index value of ‘l’ that we as assigned and on right index value of ‘o’.

So using this technique we could compress all our data. Now after compressing you actually generated a file that occupies 50% less space than your original file without even losing any of its content.

Now in order to revive back the uncompressed data the process is just the vice-versa. You just have to access each byte of the compressed data and separate out the lower 4 and upper 4 nibbles by masking or shifting , and compare with the indexes of the master array to look out for the character what that nibble meant and save that character in another file in order to create an uncompressed file from your compressed file.

Taking the same example:

For our first byte of the compressed i.e. 00000001

first we AND it with 11110000 to get the upper nibble since we know that upper nibble represents the index of first character and then compare that obtained nibble with the index of the master array and the element with the corresponding index is the first character , save it in another file that represents your uncompressed file .Then for the second character AND that byte from compressed file with 00001111

in order to get the lower nibble since it represented the index of the second character . As done for the first character look for the index in the master array and save that character in the same uncompressed file .

First byte of compressed data :00000001

multiply with 1111000 we get 00000000 i.e 0 which is the index of ‘h’ . So we get h as the first character of our expanded file that is same as the original first character.

Similarly

on multiplying with 00001111 we get 00000001 i.e 1 which is the index of ‘e’ . So we get e as the second character of our expanded file that is same as the original second character.

So following this procedure we could revive all our original data from the compressed data using the key i.e. The master array which we have created earlier.

In this way we can use our storage device with small storage capability to store large amount of data.

Posted in Uncategorized | Leave a comment

C  programming

In this article i have written that what i have done during on my embedded engineering training till now.

During these days I have done in project 00 introduction of linux, fedora installation, configuration of ftp(file transfer protocol ) server, tftp(terival file transfer protocol) server, telnet server, ssh(secure shell) server,& configuration of raid( redendent array of inexpensive disk).

In a c programming based project i started with basicof c language .in this project i learn that  introduction of c ,syntex and semantics, control structure(loop and conditional), array and strings,project management tool ,pointer, fileio, functions , linklist etc..

now a days i have knowledge about the many operator.& how to use conditional & loop control structure ie. If -else statement ,case statement,while loop, for loop. I learn that many data types ie. Int ,float, char, double& structure etc. I learn that how to initialize array ,pointer, structure,link list and what are the application of that.I implemented the linklist , stacks, queue also; I used the project management tool ie. Make, make file rcs cvs during to the implementation of many programs. after this i have implemented the debugging tool ie. Gdb.& know the application of gdb debugging.

I have used searching and sorting techniques during to the implementation of the assignment programs. now a days i implemented a program whose name is multi data compression & encryption in which a long array is decompress in a master array with the help of find out the code length while encryption is remain left.

Posted in Uncategorized | Leave a comment

Socket Programming with threads

Socket Programming with threads

 

In this project , I have work over sockets in which I create an project. My project is over how multiple clients send requests to the server and server send the solution to the respective clients. For this project I use tcp/ip protocol and POSIX Threads. In This project I transfer file from server to client. The purpose of using thread is so that many client can access the server simultaneously. So that no client is wait for server request. Because Threads can executes parallel so many clients can access the server same time continuosly.

 

This done by both using INET and UNIX. In UNIX it is within the network and in INET it is over the network.

 

 

Firstly, I created server. The system calls use for creating the server are:

  1. Socket: This is to create socket for communication. This returns the socket descriptor.
  2. Bind: This is to basically give name to socket & assign port to socket.
  3. Listen: This creates queue in which clients wait for there connection. In this we can select the size of our server,s wait queue. It can defines how many client can wait in the queue.
  4. Accept: This provide another socket descriptor through which server can chat with its clients.

 

Then, I created several clients. The system call for client are:

  1. Socket:To create socket.
  2. Connect:This to provide socket descriptor through which it can chat with server.

 

In this project, the server accept the connections from different clients and do work as per there request. This project is basically for transfer of file from server to client. client ask for a file from server . Server first check whether the client is legal or not. Because first server ask for the password from the client . If it type the write right password, then server follow the further proceedings .After that clients demand for file . Then server check for that file by opening in read only mode. If file exits,then server send the confirmation to the client. Then client creates that file and open write only mode.

Here server reads data from that file and write into client socket descriptor .On the other hand, clients reads the data through the socket descriptor and write it into the file descriptor of the file.

In this way, I can able to transfer the file from one system to another using the INET. This is the file transfer over the network.

I also use thread for connecting multiple clients to the server. When the server receive accept call from any client it creates thread. This Thread runs the functions which reads the data from the file and write the data in the socket descriptor.

For this project, I use TCP protocol for the transmission of data between client and server. Because TCP is more secure than UDP. In TCP, before transferring the data over the network there is secure connection is created between client and server. After the connection is created then data is start transferring between client and server.

 

Posted in Uncategorized | Leave a comment

Compilation Process(Neeraj Mishra)E-25

Compilation Process in C

 

The compilation in c is to compile the program by using a compiler, the compiler which we are using is gcc. There are different process involves in compile a program. The following process are:

  1. Pre-processor
  2. Compilation a. Lexical analysisb. Syntax analysis

    c. Symentic analysis

    d. Intermediate code generation

    e. Optimization

    f. Conversion to assembly language

  3. Assembler
  4. Linker/loader

 

Let suppose we have been taken a program program.c

Pre-processor: In program.c the preprocessor expand all the things which are written with # sign including all header files macros etc… and ignore the things which are written with in /* */ this. Then after this process the compilation process is started.

 

Compilation:In compilation process there are several steps involves

Lexical analysis: In lexical analysis the compiler changes or broken every statement in different tokens like int a = 20,so int is taken in 1st token a in 2nd token and so on.

Syntax analysis:In syntax analysis every statement is checked that any syntax error is there or not.

Symentic analysis:In symentic analysis every token is checked that it is written properly like int..

Intermediate code generation:In this compiler changes the code in its form..

Optimization: In this compiler changes changes the code very short form,make it very small..

Conversion to assembly language:In this the compiler changes the code in assembly language which is machine level language, then the extension of program is ‘.s ‘ in which the memory usage and some other information is given.

Assembler:In this .s extension of program is changes to .o extension which is in binary form and this is also called object file of program.

Linker/Loader:The linker links the header files to .o extension of program and make the executable a.out and save in hard disk, when we run run the program loader loads the program in RAM and execute it…

Posted in Uncategorized | Leave a comment

Article on C programming based Project

A C programming based Project

C language is the general purpose programming language developed by Dennis Ritchie. C language is the base of many other languages like C#, Java, Python, Perl, PHP. C has facilities like structure programming, functional programming. There are some standard made for C programming. C also allows the most precise control of input and output

In C Programming based Project I started with basic of C programming that is how a code or source file is compiled by gcc compiler and then how it will run. After that i learn in C language is their data types, ranges of various data types, how they will access in the program, libraries used in C program, how to write a simple program in C.

After the basic knowledge of C programming, I studied about the operator used in C programming. How to use control structure like conditional statements (if, if-else, nested if, switch) and then looping statement (for, while, do-while). Then I studied array that is collection of elements  of same data types in contiguous memory allocation and string that is collection of character ending with a null character (”).

Then I started with pointers which stores address of a variable. I implement various program which clears my concept of pointer and reference because it is most important thing in C programming. After the pointer I studied structure that is the collection of variable of different data types in contiguous memory location. By using structure I implement link list, stacks, queues and circular queues.

After the structure I studied file IO that is used to open a file and perform reading writing operation through programming. In file IO, I learn both low level and high file IO. Then i started with the various sorting and searching techniques like linear and binary searching, bubble, selection, insertion, quick, heap sorting. I also perform their practical implementation.

Then i started with the project management tools which i also implement during my practical implementation of C programs. There are various project management tools which I studied like make file (which is used to compile multiple targets), rcs (Revision Control System-which is used to save our work when we make some changes and helps in retrieving the previous version of source code in which I made changes), cvs(Concurrent Version System- is comes over the disadvantages of rcsand is done over internet). Also I studied the debugging tool that is gdb which helps in checking the error in the program during execution.

I implement various programs and assignment related to the C Programming. I also did a project whose name is “Multiple Data Compression and Encryption using Iterative techniques”. The basic concept of this project is to compress a text file and encrypt it so that unauthorized person cannot understand it. This project compress a text file and reduce the size of the text file. While making the source code for this program I implement all the concept of C language and project management tools.

Posted in Project 2: Multiple Data Compression and Encryption | Leave a comment

Article on socket programming

Socket Programming with threads

In this Article I have written what I have done in my project i.e. Client server communication using posix threads and socket.

In this project i made a server which can accept connections from more then one clients. As soon as the clients connect to the server they are able to send or /and receive files from the server and communicate with them. In this i use two protocols that are UNIX which is used to communicate within a system means two process on the same system can communicate with each other , Second one is INET which is used to communicate between two or more than two process over the network.

We use tcp/ip in the socket as it is the secure method of file transfer as in this ,first the secure connection is established and then data is transferred.

In this project I also used threads so that process can worked concurrently independent of each other.If we dont have network,then also we can check whether our socket for over the network will work or not,with the help of loop back address (127.0.0.1).

 

Process of creating Server side:

I am explaining here System calls for creating server:

1.Socket: This system call is used to create a socket and return a file descriptor on success.In the socket call we also specify type of socket,whether its is for UNIX or whether for INET.

We also specify here which type is used, SOCK_STREAM, which is a used to reliable,two way connections and another one is SOCK_DGRAM which is not reliable as it is connection less.

In this we also give the protocol by which the file is going to transfer (tcp / udp).

2.bind: This is usually for giving name and assigning port to the socket.

3.listen:It creates a queue for upcoming clients listen(sockfd,backlog).

4.accept:In accept the most important work is done that is to connect with a client and assign him a dedicated fd so that it can work on it.

Process of client side:

1.Socket;Same work as of server side.

2Connect: This is used to request to the server to connect so that communication is made between two.

Between this we also have to give port and address on which this socket will work.

Now,after the connection is established , we are ready to communicate,i use read and write system calls to communicate between two. Using threads i made two process one for read and another for write so that both server and client run concurrently,without the interference of each other,I just pass the file descriptor as the argument there.

After this i made a project in which 2 clients used to communicate each other with the help of server , means first data from one client goes to server and then server write it to another client and it will read that.
I made an another project where first authentication is requires ,when authenticate then server will able to connect with another client. In this server asked for a password ,if matches then it will work.

 

Posted in Uncategorized | Leave a comment

Character Device Driver

The kernel runs as a single process. In Linux kernel (modular kernel) there is a facility to insert and remove “loadable kernel module” at run time. These loadable kernel modules are called device drivers if they provide the mechanism to access a device from the user space application. The most of the part of the Linux kernel is the device drivers.

 

There are 3 types of drivers – character driver, block driver and pipe driver. In character drivers one byte of the data is accessed at a instant of time.

 

One most important part of the driver is the Major and Minor numbers. The kernel distinguishes between various driver through their Major numbers and the Driver distinguishes between various devices (those are using the same driver) by a assigning a unique Minor number to it. The Major Minor combination is used to represent a unique device into a system.

Whenever we have to insert a loadable kernel module in the kernel we can use the “insmod” command. As the “insmod” command executes the initialization routine of the driver executes. And when the “rmmod” mode command runs the cleanup routine of the module executes.

 

To write a kernel code we generally use the kernel objects which are already present in the kernel symbol table. These symbols are exported by the other routines of the kernel code which is already present in the kernel.

 

In writing of a character driver, we first have to write the initialization function and the cleanup function. These functions provide the facilities to insert the module into the Linux kernel and to remove the module from the Linux kernel. While writing the driver whatever the functionality we want that “This should run when the module will be inserted in the Linux kernel”, we have to include those in the initialization function e.g.- registration of driver. And whatever we want that “This should run when the module will be removed from the Linux kernel”, we have to include those in the cleanup function.

 

To access a device through the driver we first has to open that device. The open driver routine is written for this purpose. To write the data on the memory of the device the write driver routine is used and to read the data present on the memory of the device the read driver routine is written.

 

These driver routines are mapped to the system calls. System calls are used by the application to access the device. Although system calls have some by default routines but in the driver we defines the system call according to the requirement of the device. These driver routines and the system calls of the user level interacts with each others via node present in the virtual filesystem. The driver routines uses various kernel data structures for various representations and uses various kernel macros for different operations and finally various logics implemented according to the requirement of the device. These logics defines the functionality of the device and hence the complete driver provides the mechanism

to access the device.

Posted in Uncategorized | Leave a comment

Article on Client Server Communication

Project Name: Client Server Communication Using Threads And Sockets.

Scope: This project is used to setup communication between server and client. With the help of this we can send and receive data from one client to another or between server and client.

Description: We have done this project in phases -

Phase – I: One server One client

At the server end we have created one socket which will help to communicate with the client. After creating the socket using command “socket()”, we named it using command “bind()”. Naming the socket will give the easy access to the client as this socket will be visible to the client.

If we are performing this communication within the system/computer, then we will use AF_UNIX to name the socket.(Here we can give any alpha or alphanumeric name). Other wise, if we are establishing between two networks the we use AF_INET. In this we have to mention the port number and IP address of the server). We have used TCP/IP protocol for our project.

Note: we will never give name to the socket of client, we always give name to the socket of server which is visible to all the client.

Simultaneously, at the client end we have created a socket through which it will communicate with the server. After that client sent a request to the server to get connected using command “connect()”. At the server end, server will listen the request sent from the client using command “listen()” and it will create a queue. (Note: If in the mean time another client wants to connect with the server, the 2nd client request will go to the queue.) After getting the request from the client , server will accept the request using command “accept()”and this command will return a file descriptor (a stream) through which client will send and receive data to and from the server respectively.

At end of data transfer client will close the socket and simultaneously server will delete the stream connected to the particular client.

Phase – II: One server several clients

The procedure for this second phase is almost same as phase I. In the same way as mentioned above, we will create many clients which will send requests to the server to communicate simultaneously. Server will create a queue to manage the request .

Phase – III: One server several clients using threads

In this phase we have many clients who wants to communicate with the server. Every client will send request to the server, and at the server end queue is created (as explained above). One by one server will except the request and will assign the work to different functions. Here instead of calling different functions we have used concept of threads. Server will create threads on every receipt of request from the client end.

With the help of these threads the process time of the server is reduced as it is distributing its workload within threads.

Functionality:

1. This basic project will help to reduce the process timing of client. If client wants to process some data, it will send the raw data to the server and server will send back the processed output to the client.

2. Planning for phase IV. In this phase we will establish the link between different clients through one server. In this project clients will communicate with themselves or we can say these clients will share data with each other.

Posted in Uncategorized | Leave a comment