Hi,

 

     Even after I am done with my basic demo long back, I am writing this blog post which I wanted to write before only. Anyway, in this blog post I am giving insight about how did I implement MGC3130 side software. In fact, what I did is written on top of SDK demo code that can be found with SDK called "console". This demo code gives all gesture related data on console. E.g. x,y,z co-ordinates, circle gesture detection, left-right,top-bottom vice versa. Means, In order to use the gesture output to control Google earth, I could use the same console data. But here the main question was how can I control Google earth, obviously using Google API's. I preferred to use Google's Python APIs for same. Now, In this case, I need to send these data whatever I get on console to the program which will control Google earth using Python APIs. Now there can be two options to send this data from C program to Python is to use socket programming or using shared memory. I preferred socket programming and thought to transfer this data on TCP socket over local IP to Python program. So I need to write TCP client which sends  the data from TCP client which is implemented in C within SDK provided to TCP Server which is basically python program running.

 

gestic.png

 

 

Code snippets -

     Here, I am just going to give details about add on codes which I did to make this application, rather than providing complete code.

 

Following is the TCP Client implemented in C (You can find lot of examples online about TCP client implementation in C),

 

/*
    Create a TCP socket
*/

#include<stdio.h>
#include<winsock2.h>
#include "console.h"


#pragma comment(lib,"ws2_32.lib") //Winsock Library

 WSADATA wsa;
 SOCKET s;
 struct sockaddr_in server;
 char *message;


int tcpInit(void)
{
       printf("\nInitialising Winsock...");
    if (WSAStartup(MAKEWORD(2,2),&wsa) != 0)
    {
        printf("Failed. Error Code : %d",WSAGetLastError());
        return 1;
    }
     
    printf("Initialised.\n");
     
    //Create a socket
    if((s = socket(AF_INET , SOCK_STREAM , 0 )) == INVALID_SOCKET)
    {
        printf("Could not create socket : %d" , WSAGetLastError());
    }

    printf("Socket created.\n");
    server.sin_addr.s_addr = inet_addr("127.0.0.1");
    server.sin_family = AF_INET;
    server.sin_port = htons(5005 );

    //Connect to remote server
    if (connect(s , (struct sockaddr *)&server , sizeof(server)) < 0)
    {
        puts("connect error");
        return 1;
    }
  return 0;
}
int tcpSendData(char *uData)
{
     //while (1)
     //{
  //puts("Connected");


  retry:  
  //Send some data
  //message = "GET / HTTP/1.1\r\n\r\n";
  if( send(s , uData , strlen(uData) , 0) < 0)
  {
  puts("Send failed");
  return 1;
  goto retry;
  }
  Sleep(1);
  puts("Data Send\n");
    //}
  return 0;
}
 //   closesocket(s);
   // WSACleanup();
  //  return 0;
//}

 

          As you can see the function tcpSendData is used to send data over TCP socket to local Ip over 5005 port. This function is called in gestic.c file, when gesture is detected. Following is the code snippet for same.

 

       if(data->gestic_gesture != NULL) {
            /* Remember last gesture and reset it after 1s = 200 updates */
            if(data->gestic_gesture->gesture > 0 && data->gestic_gesture->gesture <= 6)
                data->last_gesture = data->gestic_gesture->gesture;
            else if(data->gestic_gesture->last_event > 1) //Shrenik
                data->last_gesture = 0;


            printf("Gesture:          %s \n", gestures[data->last_gesture]);
  
if(strcmp(gestures[data->last_gesture],"DNULL"))
  {
  tcpSendData(gestures[data->last_gesture]);
}


  }

 

 

I am attaching the modified console project from SDK, with this blog for reference which can be used to do such application. In Next blog I will talk about Python side program. Let me know if anyone have queries about same.

 

 

Thanks,

Shrenik.