Thursday, May 28, 2015

C language : MULTIPLE LINE PRINTF , FILENAME and LINENUMBER output



It's going pretty busy these days , but lot of new learning's are there. I think that's what they called EXPERIENCE.



One thing I learned that in C , there are some special macros like __FILE__ and __LINE__ which can print the filename and linenumber from which you have called a fucntion.



For example , if you have written a function which get called for a particular event and you want to know from which file this function is called . You can have code like below


#define FILENAME(x) do{ printf("I am called from %s",__FILE__);

For example in below code snippet I have 3 files

main,c

#include"header.h"

int  main()
{
  int a=10;
 printf("I am main file");
FILENAME(a);
main2();

}


main2.c

#include"header.h"

void  main2()
{
  int a=20;
 printf("I am main 2 file");
FILENAME(a);

}

void add2(int x)
{
  printf("%d",x+2);
}

header.h
#include<stdio.h>


#define FILENAME(x) printf("I am called from %s \n",__FILE__);add2(x);


If you compile them and link them
> gcc -c main.c
> gcc -c main2.c
> gcc -o out main.o main2.o
>./out

You can see from the list FILE NAME getting printed .   __L__  is  int value , you have to use %d for it.


Other thing is how to have printf span multiple lines to have code in readable format.

Ex :

printf(" My name is %s number %s address%s college %s email %s",name,number,address,college);

Now suppose there was more information and you don't want to use multiple printf , you can use forwardslash \   

printf("My name is %s \
             number is  %s \
             address is  %s ,\
            name,number,address); 


During the coding of above functions , I also learned that  MACROS needs to be included in the .C files they are getting called.

So for MACROS needed in multiple files we need to have then in  .H file and then include this file.

Tuesday, May 26, 2015

i will do good thing one day like below

only thing I have to increase my efficency



Latha Venkataraman

Madonna

Marlon Brando

Monday, May 25, 2015

Graphs and Trees : Part 3



Yippy  ...I have written a program and that too in java.

The thing I learned is that Java is much better than C for most of the programs we write until and unless we are specifically writing code for machines with memory...like embedded device.


The program is to find outdegree and indegree of Graph.
The input will be stored in 2-D matrix format.


Since the program is in java , we have one class

it will have method to calculate Outdegree and Indegree

The method will be not of Class but of Objects/Instance and since the methods and not STATIC.
We will have variables 2D matrix , size of matrix. Now these will be also not STATIC, since these will be class variables.

Something I learned during debugging is
1) main method is always static, since it will be called once and is not object method , it is class method

2) From the Main method, we can access only static methods and variables. hence we need to instantiate Object to do anything in Object Oriented Class.

3) Good thing about Object is 1) by default all object have their own variables without us specifically mentioning , it provides SAFETY as change in one object variables can't change other Object variable. 2) Object variables act as GLOBAL variables of that object , so we can access any variable of the OBJECT in any method.

4) In case we need some common variable across all objects, we need essentially CLASS variable so just have STATIC in front of that variable of method which is common of all objects.

Below is GD link for the program

https://drive.google.com/file/d/0B6HF3JcgAklvYjN4QmVOVTlkRkU/view?usp=sharing

Sunday, May 24, 2015

Graphs and Trees : Part 2


Whenever we have to make a program , the things will like

1) In which form input will come

2) What will be the data structure needed

3) What will be the algo

For graphs , we can have input like

4
5
1 2
1 3
1 4
2 3
2 4

We can read this as 4 nodes , 5 edges and then nodes of each node are given

For tress the above one can also be used and also the below one

(v1(v2(v3)(v4)))    as shown in previous post.

Also for tress we can use

1 A
   2  B C  D
           3 E
              3 F

A is root node , B C  D are children of A , E is children of C and F of D.

Then we have already seen how we can use struct for directed tress

For graphs I have seen we generally uses 2-d matrix , it wastes memory location but is easy to work with.

For trees also we can use 2-d matrix .


There will be a small theory about how to make a given tree into binary tree : I have to understand that one.


Now to just recap the things ( it may change depending on new things as I learn)

Graph :
           Input Methods
           1) 4
               5
               1 2   2 3   1 3   1 4  3 4
           2) text file has data in 2-D matrix format

Storage in memory : In 2-D format

Operations : Searching a node , finding least distance , finding largest distance , finding total distance of a graph, addition of a node and its path , deletion of a node , Degree of a node ...etc ( will be updated )

Types : Directed / Undirected ; Cyclic / Acyclic ; Simple / Multi


Directed Tree
                  Input Methods
                 1 (v0(v1(v2)))

                 2
                    1 A
                       2 B
                          3 C D E
                       2 F

Strorage : Struct

Operations : Addition , Deletion , traversal , height of tree , Level of a node (distance from root) , Degree of a node

In next post I will try to have some programs written for them.

For directed tree, most of the operations will be limited to Binary tree . ( As for any directed tree, we can obtain a equivalent binary tree as per book) (Still to check this)

Saturday, May 23, 2015

Graphs and Trees : Part 1


I was getting bored ...a day is a very long thing ...I watched movie, played ...but still the day was not ending .

So I picked up one book which was lying on my table about data structures and started reading it.

Book is pretty good, rather than having coded examples it was more on theory.

I directly started with Trees and Graphs , since I don't think apart from embedded devices anywhere else list are used extensively.

The real world data is all in graphs and trees.

Family relations , roads in a city , if you want to categorize your friends in different categories, your wardrobe if you want to pick something based on color, weather and with whom you are going out.

Just imagine if you want to write code for these you can't do that using list. You have need graphs , trees and other complex data types.


So without further ado , lets start it

First with theory in brief  and then programs ...which i highly doubt will be made .


Directed Graph  : having directional edge  . Also known as Digraph.
Undirected Graph : not having directional edge
 Mixed Graph : having combination of above two.

MultiGraph : having more than one edge connection two nodes or in case of directed graph having more than one edge having same direction between two nodes.
Simple Graph : which is not multigraph.

Weights of edges can mean many things , depending on question or scenario.

Outdegree means number of edges going out from a node and Indegree means number of edges coming in.
Total degree =  indegree + outdegree

So we can have

simple directed graph
multi directed graph
simple undirected graph
multi undirected graph


Simple Path : Path in which the edges are distinct
Elementary Path : Path in which the nodes are distinct.

All elementary path are simple, but opposite is not true

Acyclic and cyclic graphs are quite evident from there names.



Directed Tree :  is acyclic simple digraph, in which one node has indegree 0 called as root node.

Other nodes in tree are leaf node and branch nodes.  Leaf node has outdegree 0.

Level of a node is its distance from the root .
Height is distance of root from farthest leaf node
Degree of a node is number of subtrees of it , or simply number of outdegree of that node

M-ary tree :  Directed Tree in which outdegree of each node is equal or less than M.

If outdegree of each node is M , then complete M-ary tree.

Bin-ary Tree which we sees everyday.

Now we will end this post with a diagram of tree and how we represent that in computers .




1st representation Using brackets we can input data

(v0(v7(v8)(v9(v10)))(v1(v2(v5)(v6))(v3)(v4)))

2nd method using intergers 0....M-1  for M-ary tree

v0 0
v7 00
v1 01
v8 000
v9 001
v2 010
v3 011
v4 012
v5 0100
v6 0101

But  there can be some issues as we see for v0 ,v7,v8

3rd one and easy to have algo working   to define struct


typedef struct {
int node_value;
int number of children;
tree **child_trees;
}tree;

here child_trees will have pointer to array of child_tree in which all child nodes will be present.

Note while assigning value we can assign values of child nodes from left to right  or  right to left depending on our preference.


// Below is sample code //

#include<stdio.h>
#include<stdlib.h>



/********************************************

Ex        0
    1     2       3
************************************************/


 struct tree{
int node_value;
int num_child;
struct tree **child;
}tree;

 void print(struct tree*);

int main()
{

struct tree *root_node = (struct tree*)malloc(sizeof(struct tree)*1);

root_node->node_value =0;
root_node->num_child =3;
root_node->child = NULL;


struct tree **child = (struct tree **)malloc(sizeof(struct tree *)*3);
struct tree *child_temp = (struct tree *)malloc(sizeof(struct tree)*1);
child[0] = child_temp;
child_temp = (struct tree *)malloc(sizeof(struct tree)*1);
child[1] = child_temp;
child_temp = (struct tree *)malloc(sizeof(struct tree)*1);
child[2] = child_temp;

child[0]->node_value =1;
child[0]->num_child =0;
child[0]->child = NULL;

child[1]->node_value =2;
child[1]->num_child =0;
child[1]->child = NULL;

child[2]->node_value =3;
child[2]->num_child =0;
child[2]->child = NULL;

root_node->child = child;

struct tree* temp = root_node;

print(temp);
}

void print(struct tree*temp)
{
printf("%d \n",temp->node_value);

for(int i=0;i<temp->num_child;i++)
{
print(temp->child[i]);

}
}





Wednesday, May 20, 2015

Inter/Intra Process Communication Part-2


This is still in draft stage , I have to publish them else I coudn't access my own blogs from my work place.

They are kind of nazi , I can't login into my blog.


There is good article to create  threads

http://www.thegeekstuff.com/2012/04/create-threads-in-linux/

But this has led me to think about fork(), that creates child process . I am under impression that child process is just one more thread, but I have to confirm that now.


Also the code given is in C. I have to parallely work in Java. So have to check that also.

So this post at the end will have all the above things.

In case somone tries to execute code given in the link .

They have to write below command for compile ( provided u have saved file as thread.c)

> gcc -pthread -o output thread.c
>./output


and see how it behaves, for me it first printed second program and then first program

The other things I need to do before I forgot are
1) Code wise  difference between thread creation and child process creation
2) How to post signals to threads of same child and thread of different child
3) In case we want to post some signal to a particular thread of a child, how to do that.

Inter/Intra Process Communication Part-1


I am in love with technology...but this love is difficult.  Technology is so vast , that its hard to get a good grip on something.

Now while going thru the VoLTE post, I realized I need to study something about sockets.

That has led me to study about IPC ( Inter Process Communication)

As per wikipedia there a lot of ways to have IPC.

But I will just focus on those which I see in code or come across my daily life.


They will be

1) Pipes

2) Sockets

3) Message Queue

4) Shared Memory

5) Semaphore

6) Signal

Now what I am looking for is differences between these approaches and simple code for these.

This is nice link on wiki  http://en.wikipedia.org/wiki/Inter-process_communication


A bit knowledge about Operating System , since if things goes as planned :)  then we will need conceptual wise understanding of OS concepts.

Process is a executable code of the program you have written.

Threads are the running instances of you process ( or executable code) . There can be many threads per process, depending on OS support.

Also threads common to same process share the memory and variables.

True multitasking happens in CPU having more than one core or processor.  For single processor, we have time-slice concept where we slice time between different threads to have a feel of multitasking.

Multitasking is a broader term , which means multiple task running at same time. Task are nothing but threads ( IMP POINT is  THEY CAN BE OF SAME PROCESS OR DIFFERENT PROCESS).

So multiprocessing system are nothing but multitasking system.  In most of the books they just use multiprocessing in place of multitasking , even though their meaning might meant  SINGLE PROCESS MULTIPLE THREADS running at the same time.


So given this context, we have to see how can we send data between

1) THREADS OF SAME PROCESS.  Can be term as intra-process communication
2) THREADS OF DIFFERENT PROCESS . in short  inter-process communication.


So now basically we know why we are studying about IPC.

Things to done by me :
1) Making C program which have 2 threads


Some useful links I came across/referred during this post

1) http://www.yendor.com/programming/unix/unp/unp.html

2) http://technotif.com/basic-guide-interprocess-communication-pipes/

3)https://www.google.co.kr/url?sa=t&rct=j&q=&esrc=s&source=web&cd=5&ved=0CDwQFjAE&url=http%3A%2F%2Fwww.cs.unc.edu%2F~dewan%2F734%2Fcurrent%2Flectures%2F6-ipc.pdf&ei=qU5dVduCGsjBmAWv0YD4CQ&usg=AFQjCNFE9VYmu5VPnnr7uxILm8M0Z3yHtA&sig2=KEhqnHdHF9KK7E0NSiK5ig&bvm=bv.93756505,d.dGY
4)


How to make VoLTE device Part 3



Now lets see the involvement of different modules for VoLTE MO call.

Here it may be little difficult for people who have no knowledge of Modem, since we will be using modem as a module using which we will talk with Network.


This is learning for me also , as I am writing this post.


1) We need to register with Network or Server which will provide me with SIP packets for signalling and RTP packets for Voice .

[This is for me : Check in 3gpp which nodes perform these roles ]


A simple diagram will do no harm



So as you can our device has to establish two connection with network, one for signalling message and one for voice data. The voice data connection or RTP connection will be establish only for call and will be broken down once call is done, since afterwards there is no use of that .


IMS stack will send a command to Modem

 AT_IMSATTACH : This will trigger modem to establish default bearer for IMS.

( IMS is the module or stack which make volte call possible) It is present on both device and network side.

Now when this bearer is establish , QoS parameter are important .

[ I have to check for default bearer Qos and other information shared by Network]

Network will provide an IP addres to us , over which IP packets will be sent and receive.


2) Once IP address is obtained , modem sends to IMS stack  indication of default bearer up and IP address obtained.

AT_IMS_RESULT
AT_IMS_IP


I will be stopping here , since I want to have AT cmd shown as structure , maybe I will go with Java and create classes to show them
Also I need to check about socket , because that will put things beautifully, since all of this is packet switch .

There is good link , more for my use

https://docs.oracle.com/javase/tutorial/networking/sockets/readingWriting.html

How to make VoLTE device - Part 2

So if you have seen the first post, it gives a fair idea to someone who has worked on VoLTE, but to new person it might be confusing.


So let me try to explain it in easy manner.

We all use our mobiles for making call, that CALL is known as Circuit Switch call, since in this the it is basically our voice packets which are send or receive .


Whereas when you use SKYPE, whatsapp, facebook for making call, then it is PACKET SWITCHED.  Our voice will be encapsulated inside TCP/IP packets and will be send , the other party should decode this.


Now if you pay attention to the diagram on the previous post, there is a audio engine/ which is shown as speaker  whose input and output will be VOICE PACKETS.

Then comes VCE ( voice engine) which depending on implementation can receive RTP packets or TCP packets will extract VOICE PACKETS from it and send to SPEAKER/AUDIO engine.

Same way it will also encode VOICE PACKETS to RTP packets.

RTP stands for Real Time Transport Protocol.

It is application layer protocol in OSI layer.

Now this RTP has to use transport layer and network layer protocol , since this is PACKET SWITCHED or simply put INTERNET , we will be using  UDP/TCP  and IP layer respectively.

Thats where TCP stack comes into picture.




So what is left now , we need some module for signalling . Makin call, activating voice , deactivating voice once call is on hold, stopping tcp and voice engine once call is ended.

That will be handled by IMS stack.

What is AT CMD . It is simply a interface which can be used to communicated between all these modules .

Programming wise , we can have API for each functionality which each module has to share with others.

But it will limit the porting or make our implementation close-source. If tomorrow you have to use some other TCP stack or VCE , then again you have to implement those API.

API is simply functions provided to access data and method  of a particular module.

Therefore untill you are getting paid :) , have the code as much open source as possible .


Now in the next post we will see a brief flow of flow of MO call and then in subsequent post we will see how to implement ( which I think will be hard , since I don't have experience of writing code of any one of the module involved in my post ).

Tuesday, May 19, 2015

THE G FAMILY : PART 2

2.5 G
2.5G is a stepping stone between 2G and 3G cellular wireless technologies. The term "second and a half generation" is used to describe 2G-systems that have implemented a packet switched domain in addition to the circuit switched domain. 2.5G provides some of the benefits of 3G (e.g. it is packet-switched) and can use some of the existing 2G infrastructure in GSM and CDMA networks. GPRS is a 2.5G technology used by GSM operators
3G
International Mobile Telecommunications-2000 (IMT-2000), better known as 3G or 3rd Generation, is a family of standards for mobile telecommunications defined by the International Telecommunication Union,[1] which includes GSM EDGE, UMTS, and CDMA2000 as well as DECT and WiMAX. Services include wide-area wireless voice telephone, video calls, and wireless data, all in a mobile environment. Compared to 2G and 2.5G services, 3G allows simultaneous use of speech and data services and higher data rates (up to 14.0 Mbit/s on the downlink and 5.8 Mbit/s on the uplink with HSPA+). Thus, 3G networks enable network operators to offer users a wider range of more advanced services while achieving greater network capacity through improved spectral efficiency.

South Korea and India

Recently , I have been checking some articles on the internet. I come across articles by " Unleash The Good Force by E.N. RAMMOHAN". Then also I checked one article on wikipedia "Miracle_on_the_Han_River". As mentioned in the RAMMOHAN article, there are two articles in our consitituion " The 5th Schedule and the 9th Schedule". The details can be checked from the article. But the basis was after independence our constitution writers tried to lay down a strong foundation regarding how land/forest will be divided/used so that the tribals living in those areas will not get affected. But somehow these two articles never come in force, which played a great role in NAXALITE uprising in the country. Compare this with S. KOREA, where after the Korean War, Syngman Rhee administration implemented an important land reform that provided for the redistribution of land, averting a potentially explosive social issue. Treat employees like family" was Park's new motto, which also led to Korea's economic success. Park Chung-hee announced the first 5-year Economic Development Plan to mobilize national resources in establishing a self-supporting industrial economy Where is support for indian companies/ small scale industries in India general park chung lee "Democracy cannot be realized without an economic revolution" Have debate on how true is this Check what happened to our 5-year plans and why our economy didn't develop. At the root of the rapid expansion of the Korean national economy were several factors, some societal and others political. One[who?] acclaimed building block of the "Miracle on the Han" was the importance placed on education Chaebol refers to corporate groups in South Korea, mainly run by families, that exercise monopolistic or oligopolistic control in product lines and industries. Every Korean chaebol business was started by a family group and 70 percent of chaebols[citation needed] are still managed by family members, and in order for the power and standing of these groups to grow stronger, many chaebols form alliances through marriage, with examples including Samsung and Hyundai. Check 1997 financial crisis

Java Learning , if you know C : Part 7 Some Concepts


Classes : It is like skeleton from which we make our objects

Objects : They are real-world examples.

Instance  : The object which is currently in memory .

Inheritance :

Using one class methods and varibales in other classes.

In java , you cannot have two classes inhertied into one unlike C++. Only one class be inherited. But multi-level inheritance is supported .

Ex :

Class A

Class B

Class C  inherits Class A and Class B    This is not supported in Java. Multiple Inheritance

but

Class B inheirts Class A
Class C inherits Class B   this is supported.

Syntax in java

Class A {}

Class B extends Class A{}            Simple :)


Polymorphism : Changing of existing methods to suite new object requirement.

In Java we use

Method Overloading : Number and types of arguments will change
Method Overriding :


Abstraction : This is what common across some objects/class.  Like car, ship , bus  , they all transport people.

So we can define new class having the common characteristic and reuse(inherit) it .

Encapsulation : This is main reason of defining class. To have variables and thier methods bind together of a class. The process of binding variables and methods to an abstract class.

Information hiding : Simply means which variables/methods you want to expose.
Use of Public and private

-----------------------------------------------------------------------------------------------------------

Class Modifiers :
 For Access : Public  > can be accessed from any classes.
                      Private >
                      Protected
                      default
For App method :
                      Final
                      Abstract
                      static

 Member Variable
                   Acess : private, public,protected,default
                   App : final , static

Member Method : Will focus only on those which are defined for Varibales

-----------------------------------------------------------------------------------------------------------------


AaA

Every language has data types, These will be stored into bits . 

Depending on language design and complier we have size of data types.

Ex : with turbo C , borland c : which are 16 bit complier                :  for 32 bit compiler 

          we have int,float,long as 2 bytes : 16 bits                         only int size changes to 4 bytes or 32 bits
                       char as 1 byte : 8 bit
                       float,long int : 32 bits 
                       double as 8 bytes : 64 bits 
                        short int as 2 byte : 16 bits 


Further for each compiler we can use sizeof(datatype) function to find out the size of each data type

Now why are we checking all this ??

     In real life , we need new data types which will be needed for different types , therefore we have in C/C++

typedef to define new data types 
and padding which helps in bits full use.


ex : there is no data type which has 24 bits . So we will define  

typedef struct 3byte {  char[3] a;}

Now if we do sizeof of this struct , we will get size as 3 bytes. 

But we do size of below structure

typedef structure mix{

int a; 
char b;
}

the answer wud be 8 and not 5.

This is because of structure alignment. Structure alignment refers to the ability of the compiler to insert unused memory into a structure so that data members are optimally aligned for better performance. Many processors perform best when fundamental data types are stored at byte-addresses that are multiples of their sizes.

So a 16 bit processor has a address of 16 bit , and 32 bit processor a address size of 32 bits.

Also note that every compiler will have different way of structure alignment. 


Now we will see how we can squeeze datatype to their correct size in various complier.

GCC and MS visual Studio

     we can use the #pragma pack(N)  where N tells the packed size now .

     example for below structure 

typedef struct mix{
int a;
char b;
};

if we use #pragma pack(1)  the struct size wud be 5,  if we use #pragma(4) then 8

See the attached file for more understanding


See the another menthod for packing individual structures 

SS MMI Code Application : C and C++ : Part 2


Designing Phase:

1) Open the application.  It will output a help note , telling what the application does.

2) If user selects input  of  STRING , i.e  he wants to know the MMI code for respective functionality, it will output MMI string for that one

3) If user selects MMI string , it will output the functionality and also proper MMI code.


2a) When user selects STRING, options will be come telling what all are supported.
      then when he selects one particular String, its MMI code will be displayed.

3a) User will type the MMI code, we will match that code at the backend and display the string for that. Also string having full syntax will be displayed.



Coding Phase:

Saturday, May 16, 2015

I got some breather today . It has hectic last week from both the work perspective and health perspective .

 Now I am in pink of health.

So I realized , i am writing a lot ..it simply calms me and reminds what has been done till now and what is still to be done .

But i need to be organized, so I should be redistributing my blogs post . This is the folder hierarchy I am planning to go with.



TECHNOLOGY
    > DOMAIN
    > CODE
    > NETWORK
    > OPERATING SYSTEM
    > DATA STRUCTURES
    > APPLICATION

MOVIES AND SERIES
    > MOVIES
    > SERIES
    > BOOKS

HEALTH

RANDOM WRITINGS

WRETCHED OLD ME


Saturday, May 9, 2015

How to make VoLTE device Part-1


hmmm  I am fortunately working on VoLTE related project for a while.

It's challenging but something new is there for a change.

I simply like GOOGLE, the way they have opened new ways to communicate , make application to people.

TECHNOLOGY is all about sharing.....we can patent things to get monetary benefits, but its very important to keep sharing things, at least which are already there. If we all keep our learning's to ourselves w.r.t to anything ( food, dance , sports) how will we as humans can progress.



Since , I am a modem eng , a lot of things will be from that perspective. Also lots of thing will not be CORRECT :)  , since I myself is learning at the same time, but I have the luxury of devices to test any changes and practically see how things are working.


We will need
1) One  IMS Stack
2) One TCP-IP Stack   ( there is open-source IwIP) TCP stack present, but I am not sure how to use it . ( I am more working as a GUY who make things work, without owning any module)
3) AT CMD Stack or some Other Communication Layer
4) Voice Engine
5) Device which can talk to network , so that our IP packets can be exchanged with Network.
6) CALL application


Now device here can be modem (baseband processor), as I am working on that only.

I will check for any open-source application or processor , which will have IMS stack and CALL app jointly. I will also be checking with application side team to see how to implement their side


So we have to

1) make connection with network to exchange , RTP/RTCP/SIP packets.
 
    Two connection will be needed and are best for easy implementation.
    One over which we will send SIP packets (DEFAULT BEARER)
    One over which we will send RTP/RTCP packets. (DEDICATED BEARER)

2) IMS stack will setup DEFAULT BEARER with Network.

3) When CALL is triggered, IMS stack will send SIP messages.

4) Network will setup DEDICATED BEARER.

5) Once CALL is connected , then RTP/RTCP packets will come to TCP/IP stack.

6) TCP/IP will send AMR packets to VCE.





Randomness and Fear


Not only in my work, but in life also I see how little knowledge we have...We always get surprised by Nature , Stocks, Sports ...........

Its just unbelievable.

Every time we feel that we have reached the stage, where things can't surprise us ..we get shocked.

How to live then , Should we be happy in the limited knowledge we have and try to build life around that ? It will be easy ...no restlessness no pressure ....whatever comes in life taking it as the best you can have. Always looking for opportunities.

I have some friends, who so smoothly can handle multiple things , sometimes it hard to believe.
You meet then one day ..they will say convincing things about some person/job/place   and just next day they will other choice and they will act , like it's the best thing.

We don't know our futures, how can we say what is best and what not ?????

But I don't think this should stop us from trying new things ....If you don't know what is best for you in future ...just see if that thing in present will make you happy .


Is their any long-term or visionary strategy , we have all seen stock markets getting crash many a times.  but sometimes we have also seen , some nation progressing based on long term policy .

So what approach to take.

Is irrespective of human choices, what we get is just random roll of dice.

We are so weak in front of GOD.

Does Hitler would have though he will be defeated. He made lots of strategy.

Nokia went down , they also made strategies.

Roman Civilization is gone.

Sometimes I feel should I leave everything and just stand in middle of some Road. After 2-3 days may be police will come, media will surely come,  they might even make a movie ..if something exciting happens.

Just standing in middle of road for 2-3 days , can change your life..............but will I do it  :) , even though I know something exciting will surely happen .

I think , this last feeling of fear which stops us allows FATE to play his hand. We all dream big , want to be best , rich, famous .......but how many have the HEART to go for it.




Tuesday, May 5, 2015

SS MMI Code Application : C and C++ : Part 1


hmmm .... While working today I got an issue, related to Supplementary Service.


Little Background on Supplementary Service :

Its call forwarding , call waiting , USSD ( to know your balance and activate some features) which we use in everyday lives.

If you want to access, you can go in your call settings , there you will see

call forwarding, call waiting , call line identification


Now we can access all these services using MMI codes.

You can get link to these easily on internet, like below

http://www.geckobeach.com/cellular/secrets/gsmcodes.php



Now as I am NAS engineer, we get lot of issue related to it . Sometimes a particular string has been dialed , but it didn't work.


Sometimes we need to know what is the string to be dialed for some particular functionality.


and since I am trying to work my C leanings in something useful, I thought of making one application for it.

Now I don't know how to designing simple UI interface, and also C++ concepts are not so clear.

So basically what I am going to do , is make one application first on C, it will have terminal to send and get data.

then if it works and is nice , I will try to learn C++ and little UI designing.

One more  thing, my company doesn't allow even my own project code to be uploaded on net, so that I can work easily on this. I have to make designing in my office and also to double-work for some code parts .

Designing of SMS protocol : Part 2




Lots of things can change as we start working

Designing Phase :

The folder will be like below

SMS --->
                RLM ---->
                                     SRC  // This will have .C files
                                     INC  //   This will have .H files


               MLM ----->
                                     SRC  // This will have .C files
                                     INC  //   This will have .H files


Coding Phase :

Below structures will be used , they are bidirectional


Below is Message Transfer for SENDING PART





Below is Message Transfer for RECEIVING PART





Designing of SMS protocol : Working all the C learnings in one small project : Part 1

Well we have seen the important things necessary to write code in C.

I was thinking , how about writing SMS protocol code in C.  But not able to find where i will use this .

But in one of HINDU great books "GITA" ,god has said that not think about the fruit but do the work.
So I will try to see how much I can code it .

One use case which I was thinking and interested in is IoT or connecting devices. Suppose I have two devices and need to pass data between them .


So I will use modified SMS protocol to communicate between devices. But where I get stopped is
AS layers ( Access Stratum in terms of 3gpp ) and (phy and data link layer in TCP/IP).

Since for any protocol to be optmized , what is needed how the data actually get pass.
If I uses TCP/IP stack to pass data , then there are already lots of APP protocol to do the job.

But lets do the code , lets not worry about what will happen.


So how will our modified SMS protocol will work. First let see how currently SMS protocol works.

When we sent some message from our device , it goes to Network node knows as MSC. It will acknowledge that message, if something wrong with message, it will send error.

Then MSC itself forwards message to other network node SMC . This is where Messages are stored.
It will also acknowledge the message. Once device get acknowledge from SMC , then only it knows message is success.


Again at the receiver side, SMC sends message to MSC, waits for the ack. MSC will send message to receiver device and wait for ack. Here receiver will send two ack , one for MSC and one for SMC.
Both will pass thru the MSC.



So we can use this where we have 3 set of devices.  one set of devices are user devices. Other are routers. and then third set is master device.

Maybe we can also trim this down, remove the MSC layer, and use in ROBOTICS.

The layer between device and MSC is known as CP layer and between devices and SMC is RP layer.


1) State Machine and Messages ( later see the contents of Message)

Sender will be referred as MO(Message Originator)  and Receiver as MR ( Message Receiver).

The first set of machines (ROUTERS) will be Router Layer machines(RLM), the last set of machines will be MLM( Master Layer machines).

The layer between MO/MR  and RLM will be  RL. Layer between MO/MR and MLM will be ML






As per above diagram , when MO sends message following will be state at different Layers and machines.

1.

 
After sending message, MO-ML layer will change from IDLE to  WAIT-FOR-MLACK.
Start timer  TMO-ML1 .

AT MO-RL , state will change from IDLE to WAIT-FOR-RLACK.
Start timer TMO-RL1.

Note , TMO-ML1 value should be such that it accounts for TMO-RL1 time and any retry at RL layer.

2a.

 RLM will forward message to MLM and will not for any ACK. Any failure in between will be taken care by the MO device retry.


2b.
 RLM will send back ACK to MO.
 MO will stop its TMO-RL1 timer.  and move back to IDLE state.  TMO-ML1 will be running and it will remain in WAIT-FOR-MLACK.


3.

RLM will send MLM ACK to MO, via RLM
MO will then stop its timer.


Also  below are messages which will be exchanged between all machines .

1.

MO -------->RLM ( MORL-DATA)  // Note this RL-DATA will encapsulate MOML-DATA.

The use will be even though RLM is very thin layer, we can have some intelligence in that to check for RL_DATA fields and if suspect some error based on our use cases, can send by ERROR to MO.

2a

RLM------>ML-DATA  (RLML-DATA) // This will have the MOML-DATA which MO has sent.

Plus we can some extra information in RLML-DATA fields.

2b

RLM----->;MO    //  MORL-ACK   or MORL-ERROR


3)

MLM---->RLM ---->MO   // RLML-ACK ( It will have MOML-ACK).



I will try to make Message Flow Diagram and upload the document for easy understanding.

Further what we learn is how to make  MAKE FILE,  rather than manually compiling each file and then linking them ...which will be very tedious, we will make a MAKE FILE, which will do our job of compiling.

And if I liked the code I have written, possibly I will upload that one on GIT HUB and give a short tutorial on using GIT.


Saturday, May 2, 2015

C language from BaseBand Processor Eng perspective 10 : Usage of GCC compiler

C building works in below stage 

Preprocessing :  At this stage, all the preprocessor will be included in the code file

     To only preprocess a file  >  gcc  -E hello.c  -o hello.i

 Compilation : Code will be changed to assembly code

     To see assembly code    > gcc -S  hello.i  -o  hello.s

 Assembly : assembly  code to executable code

   >  gcc -C  hello.s   -o  hello.o

Linking : This will link all the libs and code and generate output/exe file

 > gcc -o output hello.o


To have more than one file linked

gcc -o  output  file1.o file2.o file3.o


To generate executable in one shot

gcc -o output file.c


C language from BaseBand Processor Eng perspective Part-9 Keywords CONST, EXTERN STATIC



The use of const in C is not much, we can use #define or enum for better result.

But if defining constant pointer , than there will be need for this.

// I WILL CHECK MY CODE, TO SEE WHERE WE ARE USING CONST, AND CAN WE HAVE USED DEFINE IN THAT CASE


Global variables are EXTERN by default. But we need EXTERN when we are using a single variable across files.

If you have defined the global variable in  .H file , and included this across C files.

When after compiling , if you link all files error will be thrown saying multiple declaration present.

So in that case in .H file we have EXTERN , then in one of files we define the variable.


Code Example

1) header.h file

#include

extern int a;

2) first.c file

#include"header.h"

int a=20;

int main()
{
printf("%d",a);
secondtype();
}

3) second.c file

#include"header.h"

void secondtype()
{
a=70;
printf("%d",a);
}


Now if you are using gcc , then

1) We use below cmd to complie files

gcc -c first.c   // this will produce objeect file  first.o
gcc -c second.c  //  second.o

2) Then we can link them to produce output file , which is windows exe equivalent

gcc -o output first.o second.o

3) to run , type below

> ./output


Now the last keyword which is used . STATIC

STATIC is mostly used

1) for defining function as static
2) local variables as static
3) limiting scope of global variable to file level


Ex Code for  1 and 3

If we are using  same function name and global variable in two different C files, then we have to use static so that their visibility is limited to that file.

1) first.c file

#include

static int a=10;

int main()
{

printf("%d",a);
secondtype();
}

2) second.c file

static int a=90;

void static secondtype()
{
printf("%d",a);
}

// This program is fine for global variable a , since in both files they are STATIC.

But since we have static  the  secondtype function , we can't use it in first.c file.

So to use  secondtype   function, we either remove static  or can define different version of secondtype  in first.c  file.


For 2nd use,  below is code .   We use it when to preserve value of a variable across function calls.


1) example.c

#include

int main()
{
  int i=0;
  for(;i<10 data-blogger-escaped-i="" data-blogger-escaped-p="">  {
   printf("number of time exam is held %d", exam());
  }
}

int exam()
{
static int a;
a++;
return a;
}



Friday, May 1, 2015

C language from BaseBand Processor Eng perspective Part-8 Keywords CONST


Some of C keywords

1) const :

const * int a  ; // compilation error , this syntax is not correct.

const int * a;

Read as const to (int *)   that means the value will be const of *a , address can change , which indirectly will change what is inside (*a).


See below codes

int main()
{

int a=10;
const int*b=&a;

*b=20;
}

// This will throw error saying *b is read only memory


int main()
{

int a=10;
int c=20;
const int*b=&a;
b=&c;
}

// No error will be thrown

Also while checking I see that below code worked


void checking(int *a)
{
 *a=50;
}

int main()
{
const int b=20;
checking(&b);
printf("%d",b);
}

// Value of b is changed to 50

NOTE : ALL THESE CODES ARE CHECKED IN GCC compiler.

For the above program, if b is global variable, no compile error, but  segmentation fault at run time.


So I think we can have lot of combination, but what is important from ENG perspective is , when you are writing code their is 2 things you need to make const

1) Either variable
2) Some Pointer

For 1st we basically use
int const a   or   const int a , but if we pass this to some function , with below type

void   func_name(int *)  // then it overwrites our value, even though we might get Warnings
void func_name(const int *) // this will give compilation error

// For compilation we can set some warnings to be converted to error so that program is not build
// I will check with my colleague to see , how it can be done.


I tried one other approach also, but it seems if in passing function you pass int*, rather than const int*  ...you can change value.


The best way to write code using const is  to have int before , and 4 below combination is possible

INT CONST A  // here a value is const ; BUT as seen if we pass address value can be changed

INT CONST * A// This is also same as before, you can cannot change value of *a in local function ,                                   but can change the address it is pointing , so effectively changing the value .
                                I really don' think this one is of any use.

INT* CONST A // This is when we need a to point to const address, the value inside address can be                                   change , but not the address a points to.

But here also not able to understand below function

------------------------------------------------------------------------------------

#include

int e=90;


void checking(int  *a)
{
printf("%d %x\n",*a,a);
a=&e;
printf("%d %x\n",*a,a);
checking2(a);
}



void checking2(int  *a)
{
printf("%d %x\n",*a,a);

}



int main()
{

int b=10;
int * const a=&b;

*a=40;

printf("%d %x\n",*a, a);
checking(a);
printf("%d %x\n",*a , a);

}
----------------------------------------------------------------------------------------------------

But what I realized it , some warnings will come. We usually ignore warnings since they don't stop as from building binary.

But we should take care of them to avoid , unexpected behavior.

If in above function I defined  checking function as

void checking (int* const a)  // it will throw error , once try to change address a points to.




INT * CONST * A;

This i will leave , since I am not able to find any good real life case where we use this. I have not seen this in Modem code.