Using the mDot to receive data.
Dependencies: libmDot-dev-mbed5-deprecated ISL29011
Fork of mdot-examples by
Revision 4:ee3739e513a9, committed 2018-04-14
- Comitter:
- SDesign2018
- Date:
- Sat Apr 14 17:47:26 2018 +0000
- Parent:
- 3:6bd9904f6c3e
- Commit message:
- Parsing data packet is working fine, need to add the rest of the GPS location and dates.
Changed in this revision
receive_main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/receive_main.cpp Mon Apr 02 03:13:35 2018 +0000 +++ b/receive_main.cpp Sat Apr 14 17:47:26 2018 +0000 @@ -6,6 +6,7 @@ #include "RadioEvent.h" #include <string.h> #include <cstdlib> +#include <stdlib.h> #if ACTIVE_EXAMPLE == PEER_TO_PEER_EXAMPLE @@ -41,12 +42,34 @@ unsigned int i_Y; unsigned int i_Z; +// Storage for GPS +float f_longitude; +float f_latitude; +int hour; +int minutes; +int seconds; +int milliseconds; +int day; +int month; +int year; + // Storage for twos complement unsigned int i2s_Temperature; unsigned int i2s_X; unsigned int i2s_Y; unsigned int i2s_Z; +// Variables to receiving data +std::string whatData = ""; +int i_whatData = 0; +std::string typeData = ""; +unsigned int i_typeData = 0; +int whereDataTypeFlag = 0; +std::string s_temperature = ""; +std::string s_XData = ""; +std::string s_YData = ""; +std::string s_ZData = ""; + unsigned int twosComplement(unsigned int value, unsigned int resolutionMask,unsigned int bitMask); @@ -73,13 +96,7 @@ //logDebug("Rx %d bytes", info->RxBufferSize); if (info->RxBufferSize > 0) { - std::string whatData = ""; - int whereDataTypeFlag = 0; - std::string s_temperature = ""; - std::string s_XData = ""; - std::string s_YData = ""; - std::string s_ZData = ""; - + std::string data = mts::Text::bin2hexString(info->RxBuffer, info->RxBufferSize).c_str(); @@ -89,23 +106,102 @@ pc.printf("Receive data: %s [%s]\r\n", rx.c_str(), data.c_str()); pc.printf("Data is of length: %d\n\r", data.length()); - whereDataTypeFlag = data.find("01"); - s_temperature = data.substr(whereDataTypeFlag + 2, 4); - data.erase(0,6); + // whereDataTypeFlag = data.find("01"); + // s_temperature = data.substr(whereDataTypeFlag + 2, 4); + // data.erase(0,6); - whereDataTypeFlag = data.find("02"); - s_XData = data.substr(whereDataTypeFlag + 2, 4); + // whereDataTypeFlag = data.find("02"); + // s_XData = data.substr(whereDataTypeFlag + 2, 4); + + // whereDataTypeFlag = data.find("03"); + // s_YData = data.substr(whereDataTypeFlag + 2, 4); + + // whereDataTypeFlag = data.find("04"); + // s_ZData = data.substr(whereDataTypeFlag + 2, 4); - whereDataTypeFlag = data.find("03"); - s_YData = data.substr(whereDataTypeFlag + 2, 4); + while(data != "") + { + typeData = data.substr(0,2); + data.erase(0,2); + //whatData = data.substr(0,4); + //data.erase(0,4); + //i_whatData = atoi(typeData.c_str()); + + i_typeData = strtoul(typeData.c_str(), NULL, 16); + switch(i_typeData) + { + // Temperature + case 1: + whatData = data.substr(0,4); + data.erase(0,4); + s_temperature = whatData; + i_Temperature = strtoul(whatData.c_str(),NULL, 16); + + break; + + // X Data + case 2: + whatData = data.substr(0,4); + data.erase(0,4); + s_XData = whatData; + i_X = strtoul(whatData.c_str(), NULL, 16); + break; + + // Y Data + case 3: + whatData = data.substr(0,4); + data.erase(0,4); + s_YData = whatData; + i_Y = strtoul(whatData.c_str(), NULL, 16); + break; + + // Z Data + case 4: + whatData = data.substr(0,4); + data.erase(0,4); + s_ZData = whatData; + i_Z = strtoul(whatData.c_str(), NULL, 16); + break; + // Longitude + case 5: + whatData = data.substr(0,4); + data.erase(0,4); + f_longitude = atof(whatData.c_str()); + break; + + // Latitude + case 6: + whatData = data.substr(0,4); + data.erase(0,4); + f_longitude = atof(whatData.c_str()); + break; + + // Hour + case 7: + whatData = data.substr(0,4); + data.erase(0,4); + hour = strtoul(whatData.c_str(), NULL, 16); + break; + + // minutes + case 8: + whatData = data.substr(0,4); + data.erase(0,4); + minutes = atoi(whatData.c_str()); + break; + + default: + break; + + + } + + } - whereDataTypeFlag = data.find("04"); - s_ZData = data.substr(whereDataTypeFlag + 2, 4); - - i_Temperature = strtoul(s_temperature.c_str(), NULL, 16); - i_X = strtoul(s_XData.c_str(), NULL, 16); - i_Y = strtoul(s_YData.c_str(), NULL, 16); - i_Z = strtoul(s_ZData.c_str(), NULL, 16); + // i_Temperature = strtoul(s_temperature.c_str(), NULL, 16); + // i_X = strtoul(s_XData.c_str(), NULL, 16); + // i_Y = strtoul(s_YData.c_str(), NULL, 16); + // i_Z = strtoul(s_ZData.c_str(), NULL, 16); // 0x1FFF->only needs 13bits, 0x1000->13th bit is sign bit i2s_Temperature = twosComplement(i_Temperature, 0x1FFF, 0x1000);