diff options
Diffstat (limited to 'Mode')
-rw-r--r-- | Mode/Mode.cpp | 62 | ||||
-rw-r--r-- | Mode/Mode.h | 19 | ||||
-rw-r--r-- | Mode/ModeConfig.cpp | 4 | ||||
-rw-r--r-- | Mode/ModeConfig.h | 4 | ||||
-rw-r--r-- | Mode/ModeDemo.cpp | 23 | ||||
-rw-r--r-- | Mode/ModeDemo.h | 2 | ||||
-rw-r--r-- | Mode/ModeJoin.cpp | 15 | ||||
-rw-r--r-- | Mode/ModeJoin.h | 2 | ||||
-rw-r--r-- | Mode/ModeSingle.cpp | 10 | ||||
-rw-r--r-- | Mode/ModeSingle.h | 2 | ||||
-rw-r--r-- | Mode/ModeSweep.cpp | 9 | ||||
-rw-r--r-- | Mode/ModeSweep.h | 2 |
12 files changed, 117 insertions, 37 deletions
diff --git a/Mode/Mode.cpp b/Mode/Mode.cpp index 2bac839..ef343fd 100644 --- a/Mode/Mode.cpp +++ b/Mode/Mode.cpp @@ -2,6 +2,15 @@ #include "MTSLog.h" /* + * union for converting from 32-bit to 4 8-bit values + */ +union convert32 { + int32_t f_s; // convert from signed 32 bit int + uint32_t f_u; // convert from unsigned 32 bit int + uint8_t t_u[4]; // convert to 8 bit unsigned array +}convertL; + +/* * union for converting from 16- bit to 2 8-bit values */ union convert16 { @@ -11,12 +20,13 @@ union convert16 { } convertS; -Mode::Mode(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora, GPSPARSER* gps) +Mode::Mode(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora, GPSPARSER* gps, SensorHandler* sensors) : _lcd(lcd), _buttons(buttons), _dot(dot), _lora(lora), _gps(gps), + _sensors(sensors), _main_id(Thread::gettid()), _index(0), _band(_dot->getFrequencyBand()), @@ -56,14 +66,6 @@ bool Mode::appendDataFile(const DataItem& data) { char stats_buf[32]; size_t size; - memset(main_buf, 0, sizeof(main_buf)); - memset(id_buf, 0, sizeof(id_buf)); - memset(lat_buf, 0, sizeof(lat_buf)); - memset(lon_buf, 0, sizeof(lon_buf)); - memset(alt_buf, 0, sizeof(alt_buf)); - memset(time_buf, 0, sizeof(time_buf)); - memset(stats_buf, 0, sizeof(stats_buf)); - snprintf(id_buf, sizeof(id_buf), "%c%ld", (data.type == single) ? 'P' : 'S', data.index); // if we had GPS lock, format GPS data @@ -92,7 +94,7 @@ bool Mode::appendDataFile(const DataItem& data) { } if (data.status) { - float down_snr = (float)data.link.down.snr / 4.0; + float down_snr = (float)data.link.down.snr / 10.0; snprintf(stats_buf, sizeof(stats_buf), "%d,%d,%d,%2.1f", data.link.up.gateways, data.link.up.dBm, @@ -142,6 +144,17 @@ void Mode::updateData(DataItem& data, DataType type, bool status) { data.power = _power; } +void Mode::updateSensorData(SensorItem& data) { + data.accel_data = _sensors->getAcceleration(); + data.baro_data = _sensors->getBarometer(); + data.lux_data_raw = _sensors->getLightRaw(); + data.pressure_raw = _sensors->getPressureRaw(); + data.light = _sensors->getLight(); + data.pressure = _sensors->getPressure(); + data.altitude = _sensors->getAltitude(); + data.temperature = _sensors->getTemp(SensorHandler::CELSIUS); +} + uint32_t Mode::getIndex(DataType type) { uint32_t index = 0; mDot::mdot_file file; @@ -236,7 +249,7 @@ std::vector<uint8_t> Mode::formatSurveyData(DataItem& data) { convertS.f_s=data.link.down.rssi; send_data.push_back(convertS.t_u[1]); send_data.push_back(convertS.t_u[0]); - send_data.push_back(data.link.down.snr); + send_data.push_back((data.ping.down.snr/10) & 0xFF); // collect GPS data if GPS device detected if (_gps->gpsDetected() && ((_data_rate != mDot::SF_10) || (_band == mDot::FB_868))){ @@ -244,16 +257,16 @@ std::vector<uint8_t> Mode::formatSurveyData(DataItem& data) { satfix = (_gps->getNumSatellites() << 4 ) | (_gps->getFixStatus() & 0x0F ); send_data.push_back(satfix); - if (_gps->getLockStatus()){ // if gps has a lock + if (_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(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 + 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]); @@ -272,6 +285,27 @@ std::vector<uint8_t> Mode::formatSurveyData(DataItem& data) { std::vector<uint8_t> Mode::formatSensorData(SensorItem& data) { std::vector<uint8_t> send_data; + send_data.clear(); + send_data.push_back(0x0E); // key for Current Acceleration 3-Axis Value + convertS.f_s = data.accel_data._x *4; // shift data 2 bits while retaining sign + send_data.push_back(convertS.t_u[1]); // get 8 MSB of 14 bit value + convertS.f_s = data.accel_data._y * 4; // shift data 2 bits while retaining sign + send_data.push_back(convertS.t_u[1]); // get 8 MSB of 14 bit value + convertS.f_s = data.accel_data._z * 4; // shift data 2 bits while retaining sign + send_data.push_back(convertS.t_u[1]); // get 8 MSB of 14 bit value + send_data.push_back(0x08); // key for Current Pressure Value + convertL.f_u = data.pressure_raw; // pressure data is 20 bits unsigned + send_data.push_back(convertL.t_u[2]); + send_data.push_back(convertL.t_u[1]); + send_data.push_back(convertL.t_u[0]); + send_data.push_back(0x05); // key for Current Ambient Light Value + convertS.f_u = data.lux_data_raw; // data is 16 bits unsigned + send_data.push_back(convertS.t_u[1]); + send_data.push_back(convertS.t_u[0]); + send_data.push_back(0x0B); // key for Current Temperature Value + convertS.f_s = data.baro_data._temp; // temperature is signed 12 bit + send_data.push_back(convertS.t_u[1]); + send_data.push_back(convertS.t_u[0]); return send_data; } diff --git a/Mode/Mode.h b/Mode/Mode.h index bd09cc9..759592a 100644 --- a/Mode/Mode.h +++ b/Mode/Mode.h @@ -6,6 +6,7 @@ #include "mDot.h" #include "LoRaHandler.h" #include "GPSPARSER.h" +#include "SensorHandler.h" #include "ISL29011.h" #include "MMA845x.h" #include "MPL3115A2.h" @@ -36,11 +37,15 @@ class Mode { typedef struct { MMA845x_DATA accel_data; MPL3115A2_DATA baro_data; - uint16_t lux_data; - uint32_t pressure; - } SensorItem; + uint16_t lux_data_raw; + uint32_t pressure_raw; + float light; + float pressure; + float altitude; + float temperature; + } SensorItem; - Mode(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora, GPSPARSER* gps); + Mode(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora, GPSPARSER* gps, SensorHandler* sensors); ~Mode(); virtual bool start() = 0; @@ -49,6 +54,7 @@ class Mode { bool deleteDataFile(); bool appendDataFile(const DataItem& data); void updateData(DataItem& data, DataType type, bool status); + void updateSensorData(SensorItem& data); uint32_t getIndex(DataType type); std::vector<uint8_t> formatSurveyData(DataItem& data); @@ -59,12 +65,13 @@ class Mode { mDot* _dot; LoRaHandler* _lora; GPSPARSER* _gps; + SensorHandler* _sensors; osThreadId _main_id; uint32_t _index; uint8_t _band; uint8_t _sub_band; uint8_t _data_rate; - uint8_t _power; + uint32_t _power; uint32_t _next_tx; ButtonHandler::ButtonEvent _be; LoRaHandler::LoRaStatus _ls; @@ -72,6 +79,8 @@ class Mode { uint8_t _state; bool _send_data; bool _gps_available; + uint8_t _initial_data_rate; + uint8_t _initial_power; }; #endif diff --git a/Mode/ModeConfig.cpp b/Mode/ModeConfig.cpp index babd898..3758e38 100644 --- a/Mode/ModeConfig.cpp +++ b/Mode/ModeConfig.cpp @@ -19,8 +19,8 @@ void ModeConfig::addCommand(Command* cmd) { _commands.push_back(cmd); } -ModeConfig::ModeConfig(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora, GPSPARSER* gps) -: Mode(lcd, buttons, dot, lora, gps), +ModeConfig::ModeConfig(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora, GPSPARSER* gps, SensorHandler* sensors) +: Mode(lcd, buttons, dot, lora, gps, sensors), _lc(lcd), _serial(USBTX, USBRX, 512, 512) { diff --git a/Mode/ModeConfig.h b/Mode/ModeConfig.h index 6c0ac73..d0730c7 100644 --- a/Mode/ModeConfig.h +++ b/Mode/ModeConfig.h @@ -6,14 +6,12 @@ #include "mbed.h" #include "MTSSerial.h" #include "Commands.h" -#include "mDot.h" -#include "ButtonHandler.h" class ModeConfig : public Mode { public: - ModeConfig(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora, GPSPARSER* gps); + ModeConfig(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora, GPSPARSER* gps, SensorHandler* sensors); // Command error text... static const char command_error[]; diff --git a/Mode/ModeDemo.cpp b/Mode/ModeDemo.cpp index e70ccbd..3fc7961 100644 --- a/Mode/ModeDemo.cpp +++ b/Mode/ModeDemo.cpp @@ -4,8 +4,8 @@ // 10 s, 30 s, 1 min, 5 min, 10 min, 15 min, 30 min 1 hour const uint32_t ModeDemo::_intervals[] = { 10, 30, 60, 5 * 60, 10 * 60, 15 * 60, 30 * 60, 60 * 60 }; -ModeDemo::ModeDemo(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora, GPSPARSER* gps) - : Mode(lcd, buttons, dot, lora, gps), +ModeDemo::ModeDemo(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora, GPSPARSER* gps, SensorHandler* sensors) + : Mode(lcd, buttons, dot, lora, gps, sensors), _help(lcd), _sam(lcd), _interval(0) @@ -20,6 +20,14 @@ bool ModeDemo::start() { // clear any stale signals osSignalClear(_main_id, buttonSignal | loraSignal); + _initial_data_rate = _dot->getTxDataRate(); + + // use configured data rate and power if possible + if (_band == mDot::FB_915 && _initial_data_rate == mDot::SF_10) { + logInfo("using SF_9 instead of SF_10 - SF_10 max packet size is too small for data"); + _dot->setTxDataRate(mDot::SF_9); + } + _state = show_help; displayHelp(); @@ -70,6 +78,7 @@ bool ModeDemo::start() { case ButtonHandler::sw1_hold: _send_timer.stop(); _send_timer.reset(); + _dot->setTxDataRate(_initial_data_rate); return true; } } @@ -138,6 +147,16 @@ bool ModeDemo::start() { _lora->send(s_data); osDelay(500); } + if(_state != show_help){ + updateSensorData(_data); + _sam.updateAccelerationX(_data.accel_data._x); + _sam.updateAccelerationY(_data.accel_data._y); + _sam.updateAccelerationZ(_data.accel_data._z); + _sam.updatePressure(_data.pressure); + _sam.updateAltitude(_data.altitude); + _sam.updateTemperature(_data.temperature); + _sam.updateLight(_data.light); + } } } diff --git a/Mode/ModeDemo.h b/Mode/ModeDemo.h index b2aaf21..cf469e0 100644 --- a/Mode/ModeDemo.h +++ b/Mode/ModeDemo.h @@ -7,7 +7,7 @@ class ModeDemo : public Mode { public: - ModeDemo(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora, GPSPARSER* gps); + ModeDemo(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora, GPSPARSER* gps, SensorHandler* sensors); ~ModeDemo(); bool start(); diff --git a/Mode/ModeJoin.cpp b/Mode/ModeJoin.cpp index 5b0a7ed..681147b 100644 --- a/Mode/ModeJoin.cpp +++ b/Mode/ModeJoin.cpp @@ -2,8 +2,8 @@ #include "MTSLog.h" #include "MTSText.h" -ModeJoin::ModeJoin(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora, GPSPARSER* gps) - : Mode(lcd, buttons, dot, lora, gps), +ModeJoin::ModeJoin(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora, GPSPARSER* gps, SensorHandler* sensors) + : Mode(lcd, buttons, dot, lora, gps, sensors), _join(lcd, _band), _joined(false) {} @@ -16,6 +16,9 @@ bool ModeJoin::start() { // clear any stale signals osSignalClear(_main_id, buttonSignal | loraSignal); + _initial_data_rate = _dot->getTxDataRate(); + _initial_power = _dot->getTxPower(); + _data_rate = (_band == mDot::FB_915) ? mDot::SF_10 : mDot::SF_12; _power = 20; _joined = false; @@ -45,10 +48,14 @@ bool ModeJoin::start() { _be = _buttons->getButtonEvent(); switch (_be) { case ButtonHandler::sw1_press: + _dot->setTxDataRate(_initial_data_rate); + _dot->setTxPower(_initial_power); return false; case ButtonHandler::sw2_press: break; case ButtonHandler::sw1_hold: + _dot->setTxDataRate(_initial_data_rate); + _dot->setTxPower(_initial_power); return false; } } @@ -61,6 +68,8 @@ bool ModeJoin::start() { logInfo("joined"); _joined = true; osDelay(2000); + _dot->setTxDataRate(_initial_data_rate); + _dot->setTxPower(_initial_power); return true; case LoRaHandler::join_failure: @@ -72,6 +81,8 @@ bool ModeJoin::start() { } } + _dot->setTxDataRate(_initial_data_rate); + _dot->setTxPower(_initial_power); return false; } diff --git a/Mode/ModeJoin.h b/Mode/ModeJoin.h index cad3f61..88c0cd2 100644 --- a/Mode/ModeJoin.h +++ b/Mode/ModeJoin.h @@ -6,7 +6,7 @@ class ModeJoin : public Mode { public: - ModeJoin(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora, GPSPARSER* gps); + ModeJoin(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora, GPSPARSER* gps, SensorHandler* sensors); ~ModeJoin(); bool start(); diff --git a/Mode/ModeSingle.cpp b/Mode/ModeSingle.cpp index 70d131c..52f7c21 100644 --- a/Mode/ModeSingle.cpp +++ b/Mode/ModeSingle.cpp @@ -1,8 +1,8 @@ #include "ModeSingle.h" #include "MTSLog.h" -ModeSingle::ModeSingle(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora, GPSPARSER* gps) - : Mode(lcd, buttons, dot, lora, gps), +ModeSingle::ModeSingle(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora, GPSPARSER* gps, SensorHandler* sensors) + : Mode(lcd, buttons, dot, lora, gps, sensors), _help(lcd), _file(lcd), _confirm(lcd), @@ -23,6 +23,9 @@ bool ModeSingle::start() { // clear any stale signals osSignalClear(_main_id, buttonSignal | loraSignal); + _initial_data_rate = _dot->getTxDataRate(); + _initial_power = _dot->getTxPower(); + // see if we're supposed to send the data packet after success // that item is stored in the mDot::StartUpMode config field _send_data = _dot->getStartUpMode(); @@ -118,6 +121,8 @@ bool ModeSingle::start() { } break; case ButtonHandler::sw1_hold: + _dot->setTxDataRate(_initial_data_rate); + _dot->setTxPower(_initial_power); return true; } } @@ -290,7 +295,6 @@ std::string ModeSingle::formatRatePower() { char buf[8]; size_t size; - memset(buf, 0, sizeof(buf)); msg += "DR="; msg += _dot->DataRateStr(_data_rate).substr(3); msg += " P="; diff --git a/Mode/ModeSingle.h b/Mode/ModeSingle.h index 1ddfc33..1c48a49 100644 --- a/Mode/ModeSingle.h +++ b/Mode/ModeSingle.h @@ -11,7 +11,7 @@ class ModeSingle : public Mode { public: - ModeSingle(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora, GPSPARSER* gps); + ModeSingle(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora, GPSPARSER* gps, SensorHandler* sensors); ~ModeSingle(); bool start(); diff --git a/Mode/ModeSweep.cpp b/Mode/ModeSweep.cpp index 80c2dde..4ccb05e 100644 --- a/Mode/ModeSweep.cpp +++ b/Mode/ModeSweep.cpp @@ -1,8 +1,8 @@ #include "ModeSweep.h" #include "MTSLog.h" -ModeSweep::ModeSweep(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora, GPSPARSER* gps) - : Mode(lcd, buttons, dot, lora, gps), +ModeSweep::ModeSweep(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora, GPSPARSER* gps, SensorHandler* sensors) + : Mode(lcd, buttons, dot, lora, gps, sensors), _help(lcd), _file(lcd), _confirm(lcd), @@ -24,6 +24,9 @@ bool ModeSweep::start() { // clear any stale signals osSignalClear(_main_id, buttonSignal | loraSignal); + _initial_data_rate = _dot->getTxDataRate(); + _initial_power = _dot->getTxPower(); + // see if we're supposed to send the data packet after success // that item is stored in the mDot::StartUpMode config field _send_data = _dot->getStartUpMode(); @@ -151,6 +154,8 @@ bool ModeSweep::start() { } break; case ButtonHandler::sw1_hold: + _dot->setTxDataRate(_initial_data_rate); + _dot->setTxPower(_initial_power); return true; } } diff --git a/Mode/ModeSweep.h b/Mode/ModeSweep.h index f7522aa..4c95b63 100644 --- a/Mode/ModeSweep.h +++ b/Mode/ModeSweep.h @@ -14,7 +14,7 @@ typedef std::pair<uint8_t, uint32_t> point; class ModeSweep : public Mode { public: - ModeSweep(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora, GPSPARSER* gps); + ModeSweep(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora, GPSPARSER* gps, SensorHandler* sensors); ~ModeSweep(); bool start(); |