EmbLogic's Blog

SHELL SCRIPTING

shell script is powerful and easy to use programming language. They are used for doing multiple jobs at a time. In shell script memory allocation is done on interpreter in the form of byte. shell script are interpreted not complied. shell read commands from the script and search those command in the system . complier convert program into machine readable form

shell is a program that takes command typed by the user and calls operating system to run those commands. Commonly used commands in shell script are—

1. unset —-used to delete variable

2. echo——used for printing

3. read——preform the function of scanf

 

Posted in Uncategorized | Leave a comment

How to set static ip in Fedora

Below is the method to give your machine a static Ip for the fedora.[Next post will contain the method to provide Static ip to Raspberry Pi running raspbian]

1. First stop and disable the gnome network manager from running on boot.

#systemctl stop NetworkManager.service
#systemctl disable NetworkManager.service

2. Now start and enable the network service to run on boot.

#systemctl restart network.service
#systemctl enable network.service

Set the Static Address
1. Check which interface(s) you want to set as static.

# ifconfig
em1: flags=4163 mtu 1500
inet 192.168.1.148 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::dad3:85ff:feae:dd4c prefixlen 64 scopeid 0×20 ether d8:d3:85:ae:dd:4c txqueuelen 1000 (Ethernet)
RX packets 929 bytes 90374 (88.2 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1010 bytes 130252 (127.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 19

lo: flags=73mtu 16436
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0×10
loop txqueuelen 0 (Local Loopback)
RX packets 32 bytes 3210 (3.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 32 bytes 3210 (3.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

2. Next edit the config file for the required interface.

vim /etc/sysconfig/network-scripts/ifcfg-em1

3. Edit the config file to look similar to the following.

Change the BOOTPROTO from “dhcp” to “static”. Also adding IPADDR, NETMASK, BROADCAST and NETWORK variables and make sure ONBOOT is set to yes.

UUID=”e88f1292-1f87-4576-97aa-bb8b2be34bd3″
NM_CONTROLLED=”yes”
HWADDR=”D8:D3:85:AE:DD:4C”
BOOTPROTO=”static”
DEVICE=”em1″
ONBOOT=”yes”
IPADDR=192.168.1.2
NETMASK=255.255.255.0
BROADCAST=192.168.1.255
NETWORK=192.168.1.0
GATEWAY=192.168.1.1

Exit the editor by pressing ‘:wq’ and enter.

4. Restart the network service to apply the settings.

systemctl restart network.service

source : https://fedoraproject.org/

Posted in Project 00: Linux System / Network Administration | Leave a comment

shell

A Unix shell is a command-line interpreter or shell that provides a traditional user interface for the Unix operating system and for Unix-like systems. Users direct the operation of the computer by entering commands as text for a command line interpreter to execute, or by creating text scripts of one or more such commands. Users typically interact with a Unix shell using a terminal emulator, however, direct operation via serial hardware connections, or networking session, are common for server systems.

The most influential Unix shells have been the Bourne shell and the C shell, These shells have both been used as the coding base and model for many derivative and work-alike shells with extended feature sets.

The Bourne shell, sh, was written by Stephen Bourne at AT&T as the original Unix command line interpreter; it introduced the basic features common to all the Unix shells, including piping, here documents, command substitution, variables, control structures for condition-testing and looping and filename wildcarding. The language, including the use of a reversed keyword to mark the end of a block, was influenced by ALGOL 68.[1]

The C shell, csh, was written by Bill Joy while a graduate student at University of California, Berkeley. The language, including the control structures and the expression grammar, was modeled on C. The C shell also introduced a large number of features for interactive work, including the history and editing mechanisms, aliases, directory stacks, tilde notation, cdpath, job control and path hashing.

Posted in Project 9: Embedded Linux on ARM | Leave a comment

bash

Bash is a Unix shell written by Brian Fox for the GNU Project as a free software replacement for the Bourne shell (sh).[3][4] Released in 1989,[5] it has been distributed widely as the shell for the GNU operating system and as a default shell on Linux and Mac OS X. It has been ported to Microsoft Windows and distributed with Cygwin and MinGW, to DOS by the DJGPP project, to Novell NetWare and to Android via various terminal emulation applications.

Bash is a command processor, typically run in a text window, allowing the user to type commands which cause actions. Bash can also read commands from a file, called a script. Like all Unix shells, it supports filename wildcarding, piping, here documents, command substitution, variables and control structures for condition-testing and iteration.[6] The keywords, syntax and other basic features of the language were all copied from sh. Other features, e.g., history, were copied from csh and ksh. Bash is a POSIX shell but with a number of extensions.

The name itself is an acronym, a pun, and a description. As an acronym, it stands for Bourne-again shell, referring to its objective as a free replacement for the Bourne shell.[7] As a pun, it expressed that objective in a phrase that sounds similar to born again, a term for spiritual rebirth.[8][9] The name is also descriptive of what it did, bashing together the features of sh, csh and ksh.

Posted in Project 9: Embedded Linux on ARM | Leave a comment

Difference between Raspberry Pi, Beaglebone, Olinuxino (etc).

You will get the list of all the Soc, Microprocessors, microcontrollers (based on arm) with the key differences between them.

http://socialcompare.com/en/comparison/low-cost-arm-boards

Posted in ARM Embedded Processors, Embedded Controllers | Leave a comment

CONNECTING RASPBERRY PI WITH YOUR LAPTOP/HOST MACHINE

In order to connect your Raspberry Pi and laptop, you could do it in two ways,

router based connection.
peer to peer connection.

Router Based Connection

In this type of connection it is assumed that your laptop is already in the network, lets say your ip to be 192.168.1.3 and you machine has ssh support.Now in Raspberry it is important that it has ssh support as well. Connect your raspberry pi into the router using a network cable, your raspberry will now have an ip address that was provided by the dhcp server. our next step is to find out the ip address of raspberry pi. In order to get the ip address of raspberry pi we could type ifconfig and look for “inet addr: x.x.x.x” if your raspberry is connected to a monitor. else if it is headless ( without a monitor) then we could look at the ip table of your router by seeing who is connected to the network. now that we know the ip address we could do the following from host machine

$ ssh pi@192.168.1.3

where 192.168.1.3 is the ip address of Raspberry provided by dhcp server.

Peer To Peer Connection

In a peer to peer based connection the Raspberry and host machine is directly connected to each other using a network cable. In order to do this we need static ip’s at both the ends. so we need to make the following change in /etc/network/interfaces file host machine, (note: dont forget to take a backup of /etc/network/interfaces file)

$sudo vim /etc/network/interfaces

auto eth0
iface eth0 inet static
address 192.168.10.2
netmask 255.255.255.0

add the above shown line to the file.

do the same in Raspberry pi as well but the only difference is that the ip address should be 192.168.10.3, note that the network id 192.168.10 should remain same.

after doing this restart the network service by typing the command or by restarting the machine.

$sudo /etc/init.d/networking restart.

then do a

$ssh pi@192.168.10.3

and now it will ask for password, provide the password. So you are now logged it to raspberry pi via ssh.

 

Source

www.emblogic.com

Posted in ARM Embedded Processors, Project 00: Linux System / Network Administration | Leave a comment

Hands on raspberry pi(Soc)

The Raspberry Pi is a credit-card-sized single-board computer developed in the UK by the Raspberry Pi Foundation. The Raspberry Pi is manufactured in two board configurations. The Raspberry Pi has a Broadcom BCM2835 system on a chip (SoC), which includes an ARM1176JZF-S 700 MHz processor, VideoCore IV GPU shipped with 512 megabytes of RAM. It does not include a built-in hard disk or solid-state drive, but uses an SD card for booting and persistent storage. The Foundation provides Debian and Arch Linux ARM distributions for download. Tools are available for Python as the main programming language, with support for BBC BASIC (via the RISC OS image or the Brandy Basic clone for Linux), C, Java and Perl.

Specification of Raspberry Pi (Model B)
Target price         : US$ 35
SoC                    : Broadcom BCM2835 (CPU, GPU, DSP, SDRAM, and single USB port)
CPU                    : 700 MHz ARM1176JZF-S core (ARM11 family, ARMv6 instruction set)
GPU                   : Broadcom VideoCore IV @ 250 MHz

OpenGL ES 2.0 (24 GFLOPS)

MPEG-2 and VC-1 (with license), 1080p30 h.264/MPEG-4 AVC high profile decoder and encoder

Memory (SDRAM)    : 512 MB (shared with GPU) as of 15 October 2012
USB 2.0 ports            : 1 (direct from BCM2835 chip) 2 (via the built in integrated 3-port     USB hub)
Video input               : A CSI input connector allows for the connection of a RPF designed     camera module
Video outputs           : Composite RCA (PAL and NTSC), HDMI (rev 1.3 & 1.4), raw             LCD Panels via DSI

14 HDMI resolutions from 640×350 to 1920×1200 plus various                                               PAL and NTSC standards.

Audio outputs           : 3.5 mm jack, HDMI, and, as of revision 2 boards, I²S audio(also potentially for audio input)
Onboard storage       : SD / MMC / SDIO card slot (3.3 V card power support only)
Onboard network     : 10/100 Mbit/s Ethernet (8P8C) USB adapter on the third port of the USB hub
Low-level peripherals: 8 × GPIO, UART, I²C bus, SPI bus with two chip selects, I²S audio +3.3 V, +5 V, ground
Power ratings          : 700 mA (3.5 W)
Power source          : 5 V via MicroUSB or GPIO header
Size                        : 85.60 mm × 56 mm (3.370 in × 2.205 in)
Weight                     : 45 g (1.6 oz)
Operating systems   : Arch Linux ARM, Debian GNU/Linux, Gentoo, Fedora, FreeBSD, NetBSD, Plan 9, Raspbian OS, RISC OS, Slackware Linux, OR your own compiled OS (Toolchain in project 9)

Source

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

www.raspberrypi.org

Posted in ARM Embedded Processors, Project 9: Embedded Linux on ARM | Leave a comment

IPC: Message queue

RCS file: msg.c,v
Working file: msg.c
head: 1.19
branch:
locks: strict
akshat: 1.19
access list:
symbolic names:
keyword substitution: kv
total revisions: 19;    selected revisions: 19
description:
IPC project.
This projectb is client server based project using msg queues.
Server is reading data from 3 clients simultaneously.
Semaphore is still not used for synchronisation.
Lets proceed.
—————————-
revision 1.19    locked by: akshat;
date: 2014/04/02 22:06:23;  author: akshat;  state: Exp;  lines: +6 -6
*** empty log message ***
—————————-
revision 1.18
date: 2014/04/02 21:25:08;  author: akshat;  state: Exp;  lines: +2 -2
semaphore is removed.
now its working better than earlier.
—————————-
revision 1.17
date: 2014/04/02 20:59:21;  author: akshat;  state: Exp;  lines: +3 -9
*** empty log message ***
—————————-
revision 1.16
date: 2014/04/02 19:14:43;  author: akshat;  state: Exp;  lines: +4 -0
Sometimes it works and sometimes it dont.
,
—————————-
revision 1.15
date: 2014/04/02 19:04:52;  author: akshat;  state: Exp;  lines: +0 -6
checking for wrong implementation of some functions.
—————————-
revision 1.14
date: 2014/04/02 19:01:02;  author: akshat;  state: Exp;  lines: +11 -10
in server result found is incorrect.
—————————-
revision 1.13
date: 2014/04/02 17:56:34;  author: akshat;  state: Exp;  lines: +14 -12
checking for errors.
—————————-
revision 1.12
date: 2014/04/02 17:50:06;  author: akshat;  state: Exp;  lines: +5 -5
Now next step is to transmit the result from processing clients back to server.
tryng that.
—————————-
revision 1.11
date: 2014/04/02 17:47:32;  author: akshat;  state: Exp;  lines: +2 -2
Both the semaphores are working.
—————————-
revision 1.10
date: 2014/04/02 17:39:59;  author: akshat;  state: Exp;  lines: +12 -2
This is proper implementation using 2 msg queues.
requesting clients are sending data to server.
server is sending this data to processing cluients using single msg queue.
its working.
—————————-
revision 1.9
date: 2014/04/02 17:22:06;  author: akshat;  state: Exp;  lines: +2 -6
on progress.
—————————-
revision 1.8
date: 2014/04/02 17:13:27;  author: akshat;  state: Exp;  lines: +10 -5
not working properly :(
—————————-
revision 1.7
date: 2014/04/02 16:47:55;  author: akshat;  state: Exp;  lines: +1 -0
Working on sending msgs from server to processing client.
—————————-
revision 1.6
date: 2014/04/02 16:34:43;  author: akshat;  state: Exp;  lines: +0 -6
Semaphore is implemented on requesting clients.
its working now,
Result from server has to be passed to processing clients.
—————————-
revision 1.5
date: 2014/04/02 16:15:19;  author: akshat;  state: Exp;  lines: +6 -5
semaphore implementation done.
checking for correct answers.
—————————-
revision 1.4
date: 2014/04/02 15:48:50;  author: akshat;  state: Exp;  lines: +27 -2
Semaphore is used for passing the results from server to processing clients.
Synchronisation was poor otherwise.
lets see if its working.
—————————-
revision 1.3
date: 2014/04/02 15:24:54;  author: akshat;  state: Exp;  lines: +13 -1
no synchronisation.
checking.
—————————-
revision 1.2
date: 2014/04/02 14:49:24;  author: akshat;  state: Exp;  lines: +1 -1
Now passing the operands to processing clients.
lets see if synchronisation is required or not.
,
—————————-
revision 1.1
date: 2014/04/02 14:48:28;  author: akshat;  state: Exp;
Initial revision
=============================================================================

Posted in Uncategorized | Leave a comment

Initialising the Message Queue

The msgget() function initializes a new message queue:

int msgget(key_t key, int msgflg)

It can also return the message queue ID (msqid) of the queue corresponding to the key argument. The value passed as the msgflg argument must be an octal integer with settings for the queue’s permissions and control flags.

The following code illustrates the msgget() function.

#include <sys/ipc.h>; 
#include <sys/msg.h>; 

... 

key_t key; /* key to be passed to msgget() */ 
int msgflg /* msgflg to be passed to msgget() */ 
int msqid; /* return value from msgget() */ 

...
key = ...
msgflg = ...

if ((msqid = msgget(key, msgflg)) == &ndash;1)
  {
    perror("msgget: msgget failed");
    exit(1);
   } else
    (void) fprintf(stderr, &ldquo;msgget succeeded");
...
Posted in Project 03: Client Server Communication using Linux and IPC | Leave a comment

IPC using MSG QUEUE

head 1.1;
access;
symbols;
locks
arjun:1.1; strict;
comment @ * @;

1.1
date 2014.04.01.15.08.45; author arjun; state Exp;
branches;
next ;

desc
@we are using msg queue in ipc project
@

1.1
log
@Initial revision
@

Posted in Uncategorized | Leave a comment

what is bash ?

Bash is the shell, or command language interpreter, for the GNU operating system. The name is an acronym for the ‘Bourne-Again SHell’, a pun on Stephen Bourne, the author of the direct ancestor of the current Unix shell sh, which appeared in the Seventh Edition Bell Labs Research version of Unix.

Bash is largely compatible with sh and incorporates useful features from the Korn shell ksh and the C shell csh. It is intended to be a conformant implementation of the IEEE POSIX Shell and Tools portion of the IEEE POSIX specification (IEEE Standard 1003.1). It offers functional improvements over sh for both interactive and programming use.

While the GNU operating system provides other shells, including a version of csh, Bash is the default shell. Like other GNU software, Bash is quite portable. It currently runs on nearly every version of Unix and a few other operating systems – independently-supported ports exist for MS-DOS, OS/2, and Windows platforms.

Posted in Uncategorized | Leave a comment

push and pop program implement in stack

head    1.1;
access;
symbols;
locks
root:1.1; strict;
comment    @ * @;

1.1
date    2014.04.01.11.46.19;    author root;    state Exp;
branches;
next    ;

desc
@push and pop in stack .
@

1.1
log
@Initial revision
@
text
@#include<stdio.h>
#include<stdlib.h>
#define MAX 5
int push(void **,int *);
int pop(void **,int *);
void display(void **,int *);
int main()
{
void *astack;
int atop=-1;

int ch;
do
{
printf(“\n1:push”);
printf(“\n2:pop”);
printf(“\n3:display”);
printf(“\n enter the choice”);
scanf(“%d”,&ch);
switch(ch)
{
case 1:push(&astack,&atop);
break;
case 2:pop(&astack,&atop);
break;
case 3:display(&astack,&atop);
break;
default:printf(“\nwrong choice”);
break;

}
}while(ch!=4);
return 0;
}
int push(void **astack,int *atop)
{
static char ch=1;
if(*atop>=MAX-1)
{
printf(“\n overflow”);
return-1;
}
if(*atop==-1)
{
*astack= (char*)malloc(1);
(*atop)++;
*(char*)(*astack+*atop)=ch;
ch++;
return -1;
}
*astack=realloc(*astack,(*atop+2));
(*atop)++;
*(char*)(*astack+*atop)=ch;
ch++;
}
int pop(void **astack,int *atop)
{
if(*atop==-1)
{
printf(“stack underflow\n”);
}
printf(“\n %d element %d delete”,*atop,*(char*)(*astack+*atop));
(*atop)–;

}
void display(void **astack,int *atop)
{
int i=0;
for(i=(*atop);i>=0;i–)
{
printf(“\nstack at %d is %d\n”,i,*(char*)(*astack+i));
}
}
@

Posted in Uncategorized | Leave a comment

Message Queues

Message queue is a circular queue which transfer data by giving a tag,tag is generally the id of the data package to be transfered and it differentiates the data from one another.

Message queuing allows distributed applications to communicate asynchronously by sending messages between the applications.  The messages from the sending application are stored in a queue and are retrieved by the receiving application.  The applications send or receive messages through a queue by sending a request to the message queuing system.  Sending and receiving applications can use the same message queuing system or different ones, allowing the message queuing system to handle the forwarding of the messages from the sender queue to the recipient queue.

Queued messages can be stored at intermediate nodes until the system is ready to forward them to the next node.  At the destination node, the messages are stored in a queue until the receiving application retrieves them from the queue.  Message delivery is guaranteed even if the network or application fails.  This provides for a reliable communication channel between the applications.

The complexity and details of the underlying model (to store and forward messages between different environments) are handled by the message queuing system.  By maintaining this level of abstraction, distributed applications can be developed without the need to worry about the details of how the information is transported.

Because the sending and receiving applications operate independently of one another, the sending application is less dependent on the availability of the remote application, less dependent on the network between them, and less dependent on the computer system on which the receiving application runs.  This leads to a higher level of availability for the participating applications.

Messages and message queue operations can be configured by the applications to operate in specific modes.  For example, a sending application can specify that queued messages should survive system crashes.  As another example, the receiving application can specify a maximum waiting period for a receiving operation from a queue (in case no messages are available yet on the receiving queue).

Posted in Project 03: Client Server Communication using Linux and IPC | Leave a comment

Memory Layout of C Programs

A typical memory representation of C program consists of following sections.

1. Text segment
2. Initialized data segment
3. Uninitialized data segment
4. Stack
5. Heap


A typical memory layout of a running process

1. Text Segment:
A text segment , also known as a code segment or simply as text, is one of the sections of a program in an object file or in memory, which contains executable instructions.

As a memory region, a text segment may be placed below the heap or stack in order to prevent heaps and stack overflows from overwriting it.

Usually, the text segment is sharable so that only a single copy needs to be in memory for frequently executed programs, such as text editors, the C compiler, the shells, and so on. Also, the text segment is often read-only, to prevent a program from accidentally modifying its instructions.

2. Initialized Data Segment:
Initialized data segment, usually called simply the Data Segment. A data segment is a portion of virtual address space of a program, which contains the global variables and static variables that are initialized by the programmer.

Note that, data segment is not read-only, since the values of the variables can be altered at run time.

This segment can be further classified into initialized read-only area and initialized read-write area.

For instance the global string defined by char s[] = “hello world” in C and a C statement like int debug=1 outside the main (i.e. global) would be stored in initialized read-write area. And a global C statement like const char* string = “hello world” makes the string literal “hello world” to be stored in initialized read-only area and the character pointer variable string in initialized read-write area.

Ex: static int i = 10 will be stored in data segment and global int i = 10 will also be stored in data segment

3. Uninitialized Data Segment:
Uninitialized data segment, often called the “bss” segment, named after an ancient assembler operator that stood for “block started by symbol.” Data in this segment is initialized by the kernel to arithmetic 0 before the program starts executing

uninitialized data starts at the end of the data segment and contains all global variables and static variables that are initialized to zero or do not have explicit initialization in source code.

For instance a variable declared static int i; would be contained in the BSS segment.
For instance a global variable declared int j; would be contained in the BSS segment.

4. Stack:
The stack area traditionally adjoined the heap area and grew the opposite direction; when the stack pointer met the heap pointer, free memory was exhausted. (With modern large address spaces and virtual memory techniques they may be placed almost anywhere, but they still typically grow opposite directions.)

The stack area contains the program stack, a LIFO structure, typically located in the higher parts of memory. On the standard PC x86 computer architecture it grows toward address zero; on some other architectures it grows the opposite direction. A “stack pointer” register tracks the top of the stack; it is adjusted each time a value is “pushed” onto the stack. The set of values pushed for one function call is termed a “stack frame”; A stack frame consists at minimum of a return address.

Stack, where automatic variables are stored, along with information that is saved each time a function is called. Each time a function is called, the address of where to return to and certain information about the caller’s environment, such as some of the machine registers, are saved on the stack. The newly called function then allocates room on the stack for its automatic and temporary variables. This is how recursive functions in C can work. Each time a recursive function calls itself, a new stack frame is used, so one set of variables doesn’t interfere with the variables from another instance of the function.

5. Heap:
Heap is the segment where dynamic memory allocation usually takes place.

The heap area begins at the end of the BSS segment and grows to larger addresses from there.The Heap area is managed by malloc, realloc, and free, which may use the brk and sbrk system calls to adjust its size (note that the use of brk/sbrk and a single “heap area” is not required to fulfill the contract of malloc/realloc/free; they may also be implemented using mmap to reserve potentially non-contiguous regions of virtual memory into the process’ virtual address space). The Heap area is shared by all shared libraries and dynamically loaded modules in a process.

Posted in Data Structures with C | Leave a comment

ipc using fifo

RCS file: fifoserver.c,v
3 Working file: fifoserver.c
4 head: 1.4
5 branch:
6 locks: strict
7         root: 1.4
8 access list:
9 symbolic names:
10 keyword substitution: kv
11 total revisions: 4;     selected revisions: 4
12 description:
13 client1 had open the fifo and writes the data and then server had read the data.
14 —————————-
15 revision 1.4    locked by: root;
16 date: 2014/03/29 06:49:06;  author: root;  state: Exp;  lines: +1 -1
17 processing client received the data and no.s are added.
18 —————————-
19 revision 1.3
20 date: 2014/03/28 10:47:55;  author: root;  state: Exp;  lines: +10 -2
21 data is read by server from three requesting clients
22 —————————-
23 revision 1.2
24 date: 2014/03/28 09:46:01;  author: root;  state: Exp;  lines: +20 -2
25 data is read in server from two requesting clients
26 —————————-
27 revision 1.1
28 date: 2014/03/28 06:18:35;  author: root;  state: Exp;
29 Initial revision
30 =============================================================================

Posted in Project 03: Client Server Communication using Linux and IPC | Leave a comment