Updated ref
Dependencies: FXOS8700Q-driver MODSERIAL
Fork of AAT_LWM2M_K64F by
Diff: resources.h
- Revision:
- 58:8c8679a77b7c
- Parent:
- 57:c8acc7c16cbd
- Child:
- 59:66ddd5bfd1b5
diff -r c8acc7c16cbd -r 8c8679a77b7c resources.h --- a/resources.h Mon Jan 23 06:52:03 2017 +0000 +++ b/resources.h Mon Jan 23 07:13:35 2017 +0000 @@ -432,10 +432,10 @@ // Global Positioning System Fix Data if(strncmp(cmd,"$GPGGA", 6) == 0) { - sscanf(cmd, "$GPGGA,%f,%f,%c,%f,%c,%d,%d,%*f,%f", &timefix, &latitude, &ns, &longitude, &ew, &fq, &nst, &altitude); - output.printf("GPGGA Fix taken at: %f, Latitude: %f %c, Longitude: %f %c, Fix quality: %d, Number of sat: %d, Altitude: %f M\n", timefix, latitude, ns, longitude, ew, fq, nst, altitude); - gnss_scan.latitude = latitude; - gnss_scan.longitude = longitude; + sscanf(cmd, "$GPGGA,%f,%f,%c,%f,%c,%d,%d,%*f,%f", &timefix, &latitude, &ns, &longitude, &ew, &fq, &nst, &altitude); + output.printf("GPGGA Fix taken at: %f, Latitude: %f %c, Longitude: %f %c, Fix quality: %d, Number of sat: %d, Altitude: %f M\n", timefix, latitude/100, ns, longitude/100, ew, fq, nst, altitude); + gnss_scan.latitude = latitude/100; + gnss_scan.longitude = longitude/100; //gnss_scan.date = date; // gnss_scan.time = timefix; gnss_scan.altitude = altitude; @@ -541,170 +541,6 @@ int size; }; -const uint8_t STATIC_VALUE[] = "Cellular Antenna Alignment"; -/* - * The GNSS custom object - */ -/* - * The GNSS custom object - */ -class GnssCustomResource { -public: - GnssCustomResource() { - // create ObjectID with metadata custom tag - gnss_object = M2MInterfaceFactory::create_object("CustomGNSScompass"); - M2MObjectInstance* gnss_inst = gnss_object->create_object_instance(); - - - M2MResource* lat_res = gnss_inst->create_dynamic_resource("E", - "CustomLatitude", - M2MResourceInstance::FLOAT, - true); - // we can read this value - lat_res->set_operation(M2MBase::GET_ALLOWED); - // set initial value (all values in mbed Client are buffers) - // to be able to read this data easily in the Connector console, we'll use a string - lat_res->set_value(0.0); - - M2MResource* app_res = gnss_inst->create_static_resource("N", - "CustomAppType", - M2MResourceInstance::STRING, - STATIC_VALUE, - sizeof(STATIC_VALUE)-1); - // we can read this value - app_res->set_operation(M2MBase::GET_ALLOWED); - // set initial value (all values in mbed Client are buffers) - // to be able to read this data easily in the Connector console, we'll use a string - size = sprintf(buffer,"%s","AntennaAlignment"); - app_res->set_value((const uint8_t*)buffer, size); - - - } - - ~GnssCustomResource() { - } - - M2MObject* get_object() { - return gnss_object; - } - - /* - * When you press the button, we read the current value of the click azimuth - * from mbed Device Connector, then up the value with one. - */ - void gps_scan(void) - { - char c; - PSTI32 = false; GPGGA = false; - Timer timeout; - timeout.start(); - - while((!PSTI32 || !GPGGA) && (timeout.read() < 10)) - { - if(gps.readable()) - { - if(gps.getc() == '$'); // wait for a $ - { - for(int i=0; i<sizeof(cDataBuffer); i++) - { - c = gps.getc(); - if( c == '\r' ) - { - //pc.printf("%s\n", cDataBuffer); - parse(cDataBuffer, i); - i = sizeof(cDataBuffer); - } - else - { - cDataBuffer[i] = c; - } - } - } - } - else break; - } - timeout.stop(); - } - - void parse(char *cmd, int n) - { - char ns, ew, tf, status, mode; - int fq, nst, fix, date, timefix, pstino; // fix quality, Number of satellites being tracked, 3D fix - double latitude, longitude, speed, altitude, eastprj, northprj, upprj, blength, bcourse; - - // Global Positioning System Fix Data - if(strncmp(cmd,"$GPGGA", 6) == 0) - { - sscanf(cmd, "$GPGGA,%f,%f,%c,%f,%c,%d,%d,%*f,%f", &timefix, &latitude, &ns, &longitude, &ew, &fq, &nst, &altitude); - //output.printf("GPGGA Fix taken at: %d, Latitude: %f %c, Longitude: %f %c, Fix quality: %d, Number of sat: %d, Altitude: %f M\n", timefix, latitude, ns, longitude, ew, fq, nst, altitude); - gnss_scan.latitude = latitude; - gnss_scan.longitude = longitude; - //gnss_scan.date = date; - gnss_scan.time = timefix; - gnss_scan.altitude = altitude; - gnss_scan.fix_quality = fq; - gnss_scan.numsat = nst; - GPGGA = true; - } - - // Baseline length, Azimuth - if(strncmp(cmd,"$PSTI", 5) == 0) - { - sscanf(cmd, "$PSTI,%d,%d,%d,%c,%c,%f,%f,%f,%f,%f", &pstino, &timefix, &date, &status, &mode, &eastprj, &northprj, &upprj, &blength, &bcourse); - if(32 == pstino) - { - //output.printf("PSTI32 Fix taken at: %d, Date: %d, Status: %c, Mode: %c, Baseline length: %f m, Azimuth: %f degrees\n", timefix, date, status, mode, blength, bcourse); - gnss_scan.heading = bcourse; gnss_scan.date = date; gnss_scan.time = timefix; - gnss_scan.baselineLen = blength; //BaseLine Length - PSTI32 = true; - } - } -#if 0 - // Satellite status - if(strncmp(cmd,"$GPGSA", 6) == 0) - { - sscanf(cmd, "$GPGSA,%c,%d,%d", &tf, &fix, &nst); - pc.printf("GPGSA Type fix: %c, 3D fix: %d, number of sat: %d\r\n", tf, fix, nst); - } - - // Geographic position, Latitude and Longitude - if(strncmp(cmd,"$GPGLL", 6) == 0) - { - sscanf(cmd, "$GPGLL,%f,%c,%f,%c,%f", &latitude, &ns, &longitude, &ew, &timefix); - pc.printf("GPGLL Latitude: %f %c, Longitude: %f %c, Fix taken at: %f\n", latitude, ns, longitude, ew, timefix); - } - - // Geographic position, Latitude and Longitude - if(strncmp(cmd,"$GPRMC", 6) == 0) - { - sscanf(cmd, "$GPRMC,%f,%c,%f,%c,%f,%c,%f,,%d", &timefix, &status, &latitude, &ns, &longitude, &ew, &speed, &date); - pc.printf("GPRMC Fix taken at: %f, Status: %c, Latitude: %f %c, Longitude: %f %c, Speed: %f, Date: %d\n", timefix, status, latitude, ns, longitude, ew, speed, date); - } -#endif - } - void handle_gnss_update() { - M2MObjectInstance* inst = gnss_object->object_instance(); - M2MResource* latituderes = inst->resource("E"); - M2MResource* appres = inst->resource("N"); - - gps_scan(); - - size = sprintf(buffer,"%f",gnss_scan.latitude); - latituderes->set_value((const uint8_t*)buffer, size); - - - output.printf("GNSS data updated\n"); - } - -private: - M2MObject* gnss_object; - uint16_t azimuth; - bool PSTI32; - bool GPGGA; - gnss_params gnss_scan; - char buffer[20]; - int size; -}; class AccelResource { public: