Justin Edwards / Mbed 2 deprecated BLIRQ

Dependencies:   TextLCD mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers parse.cpp Source File

parse.cpp

00001 #include "parse.h"
00002 #include <string.h>
00003 #include <stdlib.h>
00004 /*Packet Structure:
00005 [,Data,HR,Temp,time,humidity,]*/
00006 int parse(char* str,info* currInfo){
00007     if(str[0] == '[')
00008         ;
00009     else
00010         return -1;
00011     char* temp = strtok(str,",");
00012     temp = strtok(NULL,",");
00013     if(!strcmp(temp,"Data")){
00014         temp = strtok(NULL,",");
00015         currInfo->hr = atoi(temp);
00016         temp = strtok(NULL,",");
00017         currInfo->temp = atoi(temp);
00018         temp = strtok(NULL,",");
00019         currInfo->humidity = atoi(temp);
00020         return 0;
00021     }
00022     else if(!strcmp(temp,"HRALERT"))
00023         return 1;
00024     else if(!strcmp(temp,"CRASH"))
00025         return 2;
00026     else if(!strcmp(temp,"FORWARD"))
00027         return 3;
00028     else if(!strcmp(temp,"BACK"))
00029         return 4;
00030     else if(!strcmp(temp,"GPS")){
00031         temp = strtok(NULL,",");
00032         currInfo->x = atof(temp);
00033         temp = strtok(NULL,",");
00034         currInfo->y = atof(temp);
00035         temp = strtok(NULL,",");
00036         currInfo->speed = atof(temp);
00037         return 0;
00038     }
00039     else if(!strcmp(temp,"WIFI")){ //[,WIFI,hr,temp,humidity,x,y,speed,lean,accel,gear,]
00040         temp = strtok(NULL,",");
00041         currInfo->hr = atoi(temp);
00042         temp = strtok(NULL,",");
00043         currInfo->temp = atoi(temp);
00044         temp = strtok(NULL,",");
00045         currInfo->humidity = atoi(temp);
00046          temp = strtok(NULL,",");
00047         currInfo->x = atof(temp);
00048         temp = strtok(NULL,",");
00049         currInfo->y = atof(temp);
00050         temp = strtok(NULL,",");
00051         currInfo->speed = atof(temp);
00052         temp = strtok(NULL,",");
00053         currInfo->lean = atof(temp);
00054         temp = strtok(NULL,",");
00055         currInfo->accel = atoi(temp);
00056         temp = strtok(NULL,",");
00057         currInfo->gear = atoi(temp);
00058         return 0;
00059         }       
00060     else
00061         return -1;
00062 }
00063 void initializeStruct(info* a){
00064     a->accel = 0;
00065     a->x = 0;
00066     a->y = 0;
00067     a->temp = 0;
00068     a->lean = 0;
00069     a->speed = 0;
00070     a->humidity = 0;
00071     a->hr = 0;
00072     a->crash = 0;
00073 }