Tuesday 6 February 2018

UTF8 decocoding of 7-bit encoded Fast messages, in My way

Unicode encoding and Decoding has become very common now a days.As a developer who uses Object oriented programming ,it is easy to find Unicode encoding decoding inbuilt methods.Most of the current High-level programming have those incorporated into them by default.But when I was working on a project using C which required to parse binary data and show the ASCII/Unicode value I found little bit challenging.We were parsing some  FAST encoded messages . We were converting them to a binary string like "10001010010......" and partitioning them with Stop-bit.All was going fine until we encounter Unicode character which had a variable length encoding unlike ASCII.
 so to solve this issue I studied about overview of Unicode and code-point . Here is a YouTube link that also help me to understand the concept :
Characters in a computer - Unicode Tutorial UTF-8
I also asked the question in stackoverflow  :
Binary to UTF-8 in C    
I found that I had to represent the binary char array in the following way i.e considering the Leading and Continuation  Bytes and converting Binary Code-point to decimal code-point.
"
UTF-8 is a specific scheme for mapping a sequence of 1-4 bytes to a number from 0x000000 to 0x10FFFF:
00000000 -- 0000007F:  0xxxxxxx
00000080 -- 000007FF:  110xxxxx 10xxxxxx
00000800 -- 0000FFFF:  1110xxxx 10xxxxxx 10xxxxxx
00010000 -- 001FFFFF:  11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
" ---Source https://www.cprogramming.com/tutorial/unicode.html

so I wrote a function like this which would take character array and Unicode char array(which will be filled with the resulting Unicode character ) and calculate the decimal code point and get the utf-8 value :

void processBinaryData(char* pBinaryData,int32_t n,char *unicodeString){
    char arr[n*8],i=1,offset=0;
    int m =0;
    if(n>1){
        size_t len = strlen((char *)pBinaryData);
        while(len>0){
            len = len-8;
            if(i==1){
                offset= n+1;
                memset(arr, 0, n*8);
                for( m=0;m<8-(n+1);m++){
                    arr[m] = pBinaryData[offset+m];
                }
                offset = 10;//offset+8-(n+1)+2;
            }else{
                int j = 0;
                for( j=0;j<6;j++){//i*8-2
                    arr[m] = pBinaryData[offset];
                    m++;
                    offset++;
                }
                offset=i*8+2;

            }
            i++;
        }
        GetUnicodeChar(bin2dec(arr),unicodeString);
///////////////////
    }
    else{
        GetUnicodeChar(bin2dec(pBinaryData),unicodeString);
        return;
    }

}

Friday 11 September 2015

iBeacon Overviews ( iBeacons:Let us track you for your benefit )

 1.What is  iBeacon:
"iBeacon is a protocol standardized by Apple and introduced at the Apple Worldwide Developers Conference in 2013.Various vendors have since made iBeacon-compatible hardware transmitters - typically called beacons- a class of Bluetooth low energy (LE) devices that broadcast their identifier to nearby portable electronic devices. The technology enables smartphones, tablets and other devices to perform actions when in close proximity to an iBeacon."--- Source Wikipedia
iBeacons are actually broadcaster,which broadcast few information(Programmable),packets of data stored inside them and mobile apps receiving those data take action accordingly.  They are generally small computers with 32-bit ARM® Cortex M0 CPU.Every iBeacon ID is 20 bytes long and is divided into three sections.Three main information they broadcast are UUID (universally unique identifier) ,major value,minor value.We will discuss about these later. 
 2.Where can we use iBeacon
 There are vast area where we can use iBeacon.For example we can use it as Automated museum Guide.If a user with a app capable of detecting iBecaon residing inside the museum and Receiving data from it then it can show information about the artifacts nearby the user on user app  .Similarly we can use it for Hospital or zoo or shopping Mall.It can be used for Indoor positioning system too as GPS does not perform well in short distance positioning.

3.UUID,Major value,Minor value
UUID:- A UUID is simply a 128-bit value,It may be in canonical format like :
de305d54-75b4-431b-adb2-eb6b9e546014
For Estimote iBeacon(Estiome is an iBeacon Production Company and as I am going to use Estimote beacons for my app,I mentioned its name)it is like:
B9407F30-F5F8-466E-AFF9-25556B57FE6D
For shopping mall Example we can use UUID to distinguish between stores.
Major:- Major value is a 2 byte  or 16 bit value.
For shopping mall example we can use it to identify section in a store with specific UUID and major value.
Minor:- Minor is also 2 byte value.
For shopping mall it can be used to identify subsection of a store with specific UUID,Major and Minor value.
These examples are just to explain how those values(UUID,Major,Minor) can be used.There are lots of other ways to combine those values to make the app to produce desired output.
4.What is Region  Ranging And monitoring
Mobile apps need to interact and receive values from iBeacons.And it can be done in two ways.One is Region Monitoring and another is Ranging.But before we start this topic,we need to know what is Region.Region is individual or group of beacons identified by UUID,or UUID with Major value or UUID with Major,Minor value.
      Monitoring:-It is the process where app keep Monitoring a specific region identified by UUID or UUID and other values.Actually it set a listener or Observer so that it can detect that user has entered into the region or user has left the region and notify the app to take decision accordingly .Region monitoring can be done when app is in background or in foreground and most surprisingly it can be monitored even if the app is not running or get killed by system. It will wake up the app if  any region change detected .But it can not get proximity of individual iBeacons and app can only monitor 20 region at once.
     Ranging :-In ranging we can get list of  ibeacons in range.We can get Individual beacons proximity and calculate distance from them and other parameters like UUID,major,minor values for individual nearby beacon .Ranging generally works if the app is in foreground.Though It is Possible to Range iBeacons  in Background by using some simple tricks But it is not recommended as it will consume more battery power.In iOS the proximity distance can have various range Far,immediate,Near or Unknown.
Immediate:- strong signal; usually up to a few centimeters.
Near :-medium signal; usually up to a few meters
Far:- weak signal; more than a few meters
Unknown:-usually when the signal is very, very weak
 
So far these are the Basic characteristic of iBeacon.We will Dive into detail and we will see how to work with iBeacon and iOS and Objective c in the Next Post.We will be Working with Estiomte ibeacon and their sdk.
5.why Estimote Beacons
Because It is the Only beacon I was provided with.There are lots of other company who also manufacture beacons like kontakt,cubeacon etc.



In next post we will be discussing about implementation of Estimote sdk. Also we will detect beacons without using that sdk.We will make iOS device to work as virtual iBeacon.
sources used :-Wikipedia,Estimote