Giung Kim
/
WIZnet-IoTShield-WM-N400MSE-GPS
Init project for GPS
Diff: main.cpp
- Revision:
- 2:6fc697f1ebbd
- Parent:
- 1:d6226d2bb0b8
- Child:
- 3:3fed3b61771e
--- a/main.cpp Mon Sep 16 08:17:57 2019 +0000 +++ b/main.cpp Tue Sep 17 03:29:18 2019 +0000 @@ -100,6 +100,9 @@ int8_t setGpsOnOff_WM01(bool onoff); int8_t getGpsInfo_WM01(gps_data *gps_info); +// Functions: String seperation +char *strsep(char **stringp, const char * delim); + Serial pc(USBTX, USBRX); // USB debug UARTSerial *_serial; // Cat.M1 module @@ -203,6 +206,7 @@ myprintf("gps_info - satinfo1 : %s", gps_info.satinfo1); // satellites infomation ID-signal strength myprintf("gps_info - satinfo2 : %s", gps_info.satinfo2); // satellites infomation ID-signal strength myprintf("gps_info - satinfo3 : %s", gps_info.satinfo3); // satellites infomation ID-signal strength + myprintf("gps_info - satinfo4 : %s\r\n", gps_info.satinfo4); // satellites infomation ID-signal strength } } } @@ -349,8 +353,12 @@ int8_t getGpsInfo_WM01(gps_data *gps_info) { int8_t ret = RET_NOK; + //char _buf[] = "20190910,111720,3737831,12711294,1,175,A,2,255,255,-31,7,1-32,255-255,11-100,17-22"; char _buf[100] = {0, }; - //char _buf[] = "20190910,111720,3737831,12711294,1,175,A,2,255,255,-31,7,1-32,255-255,11-100,17-22"; + char *_tmp[20] = {0, }; + char *gp; + char *sp; + int i = 0; // structure init : GPS info gps_info->date = gps_info->utc = gps_info->lte = gps_info->emm = gps_info->esm = gps_info->ss = gps_info->nsat = 0; @@ -365,14 +373,64 @@ if(_parser->recv("$$GPS,%s\n", _buf)) { - devlog("%s", _buf); + sp = _buf; + + while((gp = strsep(&sp, ",")) != NULL) + { + _tmp[i] = gp; + + i++; + } - sscanf(_buf, "%d,%d,%f,%f,%f,%f,%c,%d,%d,%d,%d,%d,%[^,],%[^,],%[^,],%s", - &gps_info->date, &gps_info->utc, &gps_info->lat, &gps_info->lon, &gps_info->spkm, &gps_info->cog, &gps_info->reli, &gps_info->lte, - &gps_info->emm, &gps_info->esm, &gps_info->ss, &gps_info->nsat, gps_info->satinfo1, gps_info->satinfo2, gps_info->satinfo3, gps_info->satinfo4); + // convert data and store + gps_info->date = atoi(_tmp[0]); + gps_info->utc = atoi(_tmp[1]); + gps_info->lat = atof(_tmp[2]); + gps_info->lon = atof(_tmp[3]); + gps_info->spkm = atof(_tmp[4]); + gps_info->cog = atof(_tmp[5]); + gps_info->reli = *_tmp[6]; + gps_info->lte = atoi(_tmp[7]); + gps_info->emm = atoi(_tmp[8]); + gps_info->esm = atoi(_tmp[9]); + gps_info->ss = atoi(_tmp[10]); + gps_info->nsat = atoi(_tmp[11]); + memcpy(gps_info->satinfo1, (char *)_tmp[12], strlen(_tmp[12])); + memcpy(gps_info->satinfo2, (char *)_tmp[13], strlen(_tmp[13])); + memcpy(gps_info->satinfo3, (char *)_tmp[14], strlen(_tmp[14])); + memcpy(gps_info->satinfo4, (char *)_tmp[15], strlen(_tmp[15])); ret = RET_OK; } return ret; +} + +// ---------------------------------------------------------------- +// Functions: String seperation +// ---------------------------------------------------------------- + +char *strsep(char **stringp, const char * delim) +{ + char *ptr = *stringp; + + if (ptr == NULL) + { + return NULL; + } + + while (**stringp) + { + if (strchr(delim, **stringp) != NULL) + { + **stringp = 0x00; + (*stringp)++; + + return ptr; + } + (*stringp)++; + } + *stringp = NULL; + + return ptr; } \ No newline at end of file