diff options
author | Mike Fiore <mfiore@multitech.com> | 2015-12-01 15:15:47 -0600 |
---|---|---|
committer | Mike Fiore <mfiore@multitech.com> | 2015-12-01 15:15:47 -0600 |
commit | ab6c90739bc2efb5eaf94474be8916fe0f990707 (patch) | |
tree | 345177a64b8ef13d1a6c89b3d2aceb0e7c83e3df | |
parent | 4a7ab715f7115460892927b998b2c45828f275d6 (diff) | |
parent | 96fd7995d2d2ae16c2be7ed30b1e4aacc79d3a61 (diff) | |
download | mtdot-box-evb-factory-firmware-ab6c90739bc2efb5eaf94474be8916fe0f990707.tar.gz mtdot-box-evb-factory-firmware-ab6c90739bc2efb5eaf94474be8916fe0f990707.tar.bz2 mtdot-box-evb-factory-firmware-ab6c90739bc2efb5eaf94474be8916fe0f990707.zip |
Merge branch 'modeDemo'
Conflicts:
Mode/Mode.cpp
-rw-r--r-- | Mode/Mode.cpp | 75 | ||||
-rw-r--r-- | Mode/Mode.h | 15 | ||||
-rw-r--r-- | main.cpp | 5 |
3 files changed, 88 insertions, 7 deletions
diff --git a/Mode/Mode.cpp b/Mode/Mode.cpp index e7181fe..f049e33 100644 --- a/Mode/Mode.cpp +++ b/Mode/Mode.cpp @@ -3,6 +3,16 @@ const char* Mode::_file_name = "SurveyData.txt"; +/* + * union for converting from 16- bit to 2 8-bit values + */ +union convert16 { + int16_t f_s; // convert from signed 16 bit int + uint16_t f_u; // convert from unsigned 16 bit int + uint8_t t_u[2]; // convert to 8 bit unsigned array +} convertS; + + Mode::Mode(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora) : _lcd(lcd), _buttons(buttons), @@ -15,7 +25,9 @@ Mode::Mode(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora) _data_rate(mDot::SF_7), _power(2), _next_tx(0), - _send_data(false) + _send_data(false), + _gpsUART(PA_2, PA_3), + _mdot_gps(&_gpsUART) {} Mode::~Mode() {} @@ -123,7 +135,9 @@ void Mode::updateData(DataItem& data, DataType type, bool status) { data.index = _index; data.status = status; data.lock = 0; - // TODO add GPS info + data.gps_longitude = _mdot_gps.getLongitude(); + data.gps_latitude = _mdot_gps.getLatitude(); + data.gps_altitude = _mdot_gps.getAltitude(); data.ping = _ping_result; data.data_rate = _data_rate; data.power = _power; @@ -204,3 +218,60 @@ uint32_t Mode::getIndex(DataType type) { return index; } +std::vector<uint8_t> Mode::formatSurveyData(DataItem& data) { + std::vector<uint8_t> send_data; + uint8_t satfix; + + send_data.clear(); + send_data.push_back(0x1D); // key for start of data structure + send_data.push_back(0x1A); // key for uplink QOS + RF Pwr + convertS.f_s = data.ping.up.rssi; + send_data.push_back(convertS.t_u[1]); + send_data.push_back(convertS.t_u[0]); + send_data.push_back((data.ping.up.snr/10) & 0xFF); + send_data.push_back(data.power); + + send_data.push_back(0x1B); // key for downlink QOS + convertS.f_s=data.ping.down.rssi; + send_data.push_back(convertS.t_u[1]); + send_data.push_back(convertS.t_u[0]); + send_data.push_back(data.ping.down.snr); + + // collect GPS data if GPS device detected + if (_mdot_gps.gpsDetected() && ((_data_rate != mDot::SF_10) || (_band == mDot::FB_868))){ + send_data.push_back(0x19); // key for GPS Lock Status + satfix = (_mdot_gps.getNumSatellites() << 4 ) | (_mdot_gps.getFixStatus() & 0x0F ); + send_data.push_back(satfix); + + if (_mdot_gps.getLockStatus()){ // if gps has a lock + // Send GPS data if GPS device locked + send_data.push_back(0x15); // key for GPS Latitude + send_data.push_back(data.gps_latitude.degrees); + send_data.push_back(data.gps_latitude.minutes); + convertS.f_s = data.gps_latitude.seconds; + send_data.push_back(convertS.t_u[1]); + send_data.push_back(convertS.t_u[0]); + + send_data.push_back(0x16); // key for GPS Longitude + convertS.f_s = data.gps_longitude.degrees; + send_data.push_back(convertS.t_u[1]); + send_data.push_back(convertS.t_u[0]); + + send_data.push_back(data.gps_longitude.minutes); + convertS.f_s = data.gps_longitude.seconds; + send_data.push_back(convertS.t_u[1]); + send_data.push_back(convertS.t_u[0]); + } + } + // key for end of data structure + send_data.push_back(0x1D); + + return send_data; +} + +std::vector<uint8_t> Mode::formatSensorData(SensorItem& data) { + std::vector<uint8_t> send_data; + + return send_data; +} + diff --git a/Mode/Mode.h b/Mode/Mode.h index ca8fd19..5d41ed1 100644 --- a/Mode/Mode.h +++ b/Mode/Mode.h @@ -6,6 +6,9 @@ #include "mDot.h" #include "LoRaHandler.h" #include "GPSPARSER.h" +#include "ISL29011.h" +#include "MMA845x.h" +#include "MPL3115A2.h" class Mode { public: @@ -28,6 +31,13 @@ class Mode { uint32_t power; } DataItem; + typedef struct { + MMA845x_DATA accel_data; + MPL3115A2_DATA baro_data; + uint16_t lux_data; + uint32_t pressure; + } SensorItem; + Mode(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora); ~Mode(); @@ -39,6 +49,9 @@ class Mode { void updateData(DataItem& data, DataType type, bool status); uint32_t getIndex(DataType type); + std::vector<uint8_t> formatSurveyData(DataItem& data); + std::vector<uint8_t> formatSensorData(SensorItem& data); + DOGS102* _lcd; ButtonHandler* _buttons; mDot* _dot; @@ -56,6 +69,8 @@ class Mode { LoRaHandler::LoRaPing _ping_result; uint8_t _state; bool _send_data; + mts::MTSSerial _gpsUART; + GPSPARSER _mdot_gps; }; #endif @@ -4,11 +4,6 @@ // MTS headers #include "mDot.h" #include "MTSLog.h" -// sensor headers -#include "ISL29011.h" -#include "MMA845x.h" -#include "MPL3115A2.h" -#include "GPSPARSER.h" // display headers #include "DOGS102.h" #include "NCP5623B.h" |