diff options
-rw-r--r-- | CommandTerminal/CmdDisplayConfig.cpp | 3 | ||||
-rw-r--r-- | CommandTerminal/CmdFactoryDefault.cpp | 4 | ||||
-rw-r--r-- | Layout/LayoutSingleHelp.cpp | 26 | ||||
-rw-r--r-- | Layout/LayoutSingleHelp.h | 21 | ||||
-rw-r--r-- | Layout/LayoutStartup.cpp | 2 | ||||
-rw-r--r-- | Layout/LayoutSurveyFailure.cpp | 40 | ||||
-rw-r--r-- | Layout/LayoutSurveyFailure.h | 13 | ||||
-rw-r--r-- | Layout/LayoutSurveySuccess.cpp | 20 | ||||
-rw-r--r-- | Layout/LayoutSurveySuccess.h | 2 | ||||
-rw-r--r-- | Layout/LayoutSweepComplete.cpp | 53 | ||||
-rw-r--r-- | Layout/LayoutSweepComplete.h | 28 | ||||
-rw-r--r-- | Layout/LayoutSweepHelp.cpp | 26 | ||||
-rw-r--r-- | Layout/LayoutSweepHelp.h | 21 | ||||
-rw-r--r-- | Layout/LayoutSweepProgress.cpp | 46 | ||||
-rw-r--r-- | Layout/LayoutSweepProgress.h | 26 | ||||
-rw-r--r-- | Mode/Mode.cpp | 189 | ||||
-rw-r--r-- | Mode/Mode.h | 1 | ||||
-rw-r--r-- | Mode/ModeSingle.cpp | 22 | ||||
-rw-r--r-- | Mode/ModeSweep.cpp | 436 | ||||
-rw-r--r-- | Mode/ModeSweep.h | 60 | ||||
-rw-r--r-- | main.cpp | 37 |
21 files changed, 868 insertions, 208 deletions
diff --git a/CommandTerminal/CmdDisplayConfig.cpp b/CommandTerminal/CmdDisplayConfig.cpp index edea277..05fe37e 100644 --- a/CommandTerminal/CmdDisplayConfig.cpp +++ b/CommandTerminal/CmdDisplayConfig.cpp @@ -20,7 +20,8 @@ uint32_t CmdDisplayConfig::action(std::vector<std::string> args) { _serial.writef("%s\r\n", mts::Text::bin2hexString(_dot->getDeviceId(), ":").c_str()); _serial.writef("Frequency Band:\t\t%s\r\n", mDot::FrequencyBandStr(_dot->getFrequencyBand()).c_str()); - _serial.writef("Frequency Sub Band:\t%u\r\n", _dot->getFrequencySubBand()); + if (_dot->getFrequencyBand() == mDot::FB_915) + _serial.writef("Frequency Sub Band:\t%u\r\n", _dot->getFrequencySubBand()); _serial.writef("Public Network:\t\t%s\r\n", _dot->getPublicNetwork() ? "on" : "off"); diff --git a/CommandTerminal/CmdFactoryDefault.cpp b/CommandTerminal/CmdFactoryDefault.cpp index e2645cd..86a3c0f 100644 --- a/CommandTerminal/CmdFactoryDefault.cpp +++ b/CommandTerminal/CmdFactoryDefault.cpp @@ -20,6 +20,10 @@ uint32_t CmdFactoryDefault::action(std::vector<std::string> args) _dot->setStartUpMode(0); //DotBox +Data is stored here. Default is 0. _dot->setVerbose(1); _dot->setEcho(1); + _dot->setAck(1); + _dot->setJoinMode(mDot::OTA); + _dot->setNetworkName("MultiTech"); + _dot->setNetworkPassphrase("MultiTech"); _dot->resetNetworkSession(); return 0; diff --git a/Layout/LayoutSingleHelp.cpp b/Layout/LayoutSingleHelp.cpp deleted file mode 100644 index 82c4270..0000000 --- a/Layout/LayoutSingleHelp.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "LayoutSingleHelp.h" - -LayoutSingleHelp::LayoutSingleHelp(DOGS102* lcd) - : Layout(lcd), - _lMode(0, 0, "Survey Single"), - _lIns1(0, 4, "Hold SW1 any time"), - _lIns2(0, 5, "for Main Menu"), - _lSw1(11, 7, "DR/PWR"), - _lSw2(0, 7, "Survey") -{} - -LayoutSingleHelp::~LayoutSingleHelp() {} - -void LayoutSingleHelp::display() { - clear(); - startUpdate(); - - writeLabel(_lMode); - writeLabel(_lIns1); - writeLabel(_lIns2); - writeLabel(_lSw1); - writeLabel(_lSw2); - - endUpdate(); -} - diff --git a/Layout/LayoutSingleHelp.h b/Layout/LayoutSingleHelp.h deleted file mode 100644 index 421bc1c..0000000 --- a/Layout/LayoutSingleHelp.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef __LAYOUTSINGLEHELP_H__ -#define __LAYOUTSINGLEHELP_H__ - -#include "Layout.h" - -class LayoutSingleHelp : public Layout { - public: - LayoutSingleHelp(DOGS102* lcd); - ~LayoutSingleHelp(); - - void display(); - - private: - Label _lMode; - Label _lIns1; - Label _lIns2; - Label _lSw1; - Label _lSw2; -}; - -#endif diff --git a/Layout/LayoutStartup.cpp b/Layout/LayoutStartup.cpp index 2922035..c317a7f 100644 --- a/Layout/LayoutStartup.cpp +++ b/Layout/LayoutStartup.cpp @@ -10,7 +10,7 @@ LayoutStartup::LayoutStartup(DOGS102* lcd, mDot* dot) _lInfo(0, 4, "Factory Firmware"), _lVersion(0, 5, "Version"), _fVersion(8, 5, 9), - _fId(0, 6, 17), + _fId(0, 7, 17), _iLogo(0, 0, MultiTech_Logo) {} diff --git a/Layout/LayoutSurveyFailure.cpp b/Layout/LayoutSurveyFailure.cpp index d443098..aa2ce7c 100644 --- a/Layout/LayoutSurveyFailure.cpp +++ b/Layout/LayoutSurveyFailure.cpp @@ -2,18 +2,19 @@ LayoutSurveyFailure::LayoutSurveyFailure(DOGS102* lcd) : Layout(lcd), - _lTitle(0, 2, "Survey Failed"), + _lTitle(0, 1, "Survey Failed"), _lId(0, 0, "ID"), _lDr(8, 0, "DR"), _lPwr(13, 0, "P"), - _lSw1(12, 7, "Power"), - _lSw2(0, 7, "Survey"), _fId(2, 0, 5), _fDr(10, 0, 2), _fPwr(14, 0, 2), - _fMsg1(0, 4, 17), - _fMsg2(0, 5, 17), - _fInfo(0, 6, 17) + _fMsg1(0, 2, 17), + _fMsg2(0, 3, 17), + _fInfo1(0, 5, 17), + _fInfo2(0, 6, 17), + _fSw1(9, 7, 8), + _fSw2(0, 7, 8) {} LayoutSurveyFailure::~LayoutSurveyFailure() {} @@ -26,8 +27,6 @@ void LayoutSurveyFailure::display() { writeLabel(_lId); writeLabel(_lDr); writeLabel(_lPwr); - writeLabel(_lSw1); - writeLabel(_lSw2); endUpdate(); } @@ -52,7 +51,28 @@ void LayoutSurveyFailure::updatePower(uint32_t power) { writeField(_fPwr, buf, size, true); } -void LayoutSurveyFailure::updateInfo(std::string info) { - writeField(_fInfo, info, true); +void LayoutSurveyFailure::updateInfo1(std::string info) { + writeField(_fInfo1, info, true); +} + +void LayoutSurveyFailure::updateInfo2(std::string info) { + writeField(_fInfo2, info, true); +} + +void LayoutSurveyFailure::updatePassFail(uint8_t pass, uint8_t fail) { + char buf[32]; + size_t size; + + memset(buf, 0, sizeof(buf)); + size = snprintf(buf, sizeof(buf), "Pass %u Fail %u", pass, fail); + writeField(_fInfo1, buf, size, true); +} + +void LayoutSurveyFailure::updateSw1(std::string sw1) { + writeField(_fSw1, sw1, true); +} + +void LayoutSurveyFailure::updateSw2(std::string sw2) { + writeField(_fSw2, sw2, true); } diff --git a/Layout/LayoutSurveyFailure.h b/Layout/LayoutSurveyFailure.h index 473fd9f..ca6aebd 100644 --- a/Layout/LayoutSurveyFailure.h +++ b/Layout/LayoutSurveyFailure.h @@ -12,22 +12,27 @@ class LayoutSurveyFailure : public Layout { void updateId(uint32_t id); void updateRate(std::string rate); void updatePower(uint32_t power); - void updateInfo(std::string msg); + void updateInfo1(std::string msg); + void updateInfo2(std::string msg); + void updatePassFail(uint8_t pass, uint8_t fail); + void updateSw1(std::string sw1); + void updateSw2(std::string sw2); private: Label _lTitle; Label _lId; Label _lDr; Label _lPwr; - Label _lSw1; - Label _lSw2; Field _fId; Field _fDr; Field _fPwr; Field _fMsg1; Field _fMsg2; - Field _fInfo; + Field _fInfo1; + Field _fInfo2; + Field _fSw1; + Field _fSw2; }; #endif diff --git a/Layout/LayoutSurveySuccess.cpp b/Layout/LayoutSurveySuccess.cpp index 02dd197..38edb5c 100644 --- a/Layout/LayoutSurveySuccess.cpp +++ b/Layout/LayoutSurveySuccess.cpp @@ -1,4 +1,5 @@ #include "LayoutSurveySuccess.h" +#include "MTSLog.h" LayoutSurveySuccess::LayoutSurveySuccess(DOGS102* lcd) : Layout(lcd), @@ -67,7 +68,7 @@ void LayoutSurveySuccess::updateStats(LoRaHandler::LoRaPing ping) { writeField(_fUpRssi, buf, size); memset(buf, 0, sizeof(buf)); - size = snprintf(buf, sizeof(buf), "%2d.%1d", ping.up.snr / 10, abs(ping.up.snr) % 10); + size = snprintf(buf, sizeof(buf), "%2.1f", (float)ping.up.snr / 10.0); writeField(_fUpSnr, buf, size); memset(buf, 0, sizeof(buf)); @@ -75,7 +76,7 @@ void LayoutSurveySuccess::updateStats(LoRaHandler::LoRaPing ping) { writeField(_fDownRssi, buf, size); memset(buf, 0, sizeof(buf)); - size = snprintf(buf, sizeof(buf), "%2d.%1d", ping.down.snr / 4, abs(ping.down.snr) % 10 * 25); + size = snprintf(buf, sizeof(buf), "%2.1f", (float)ping.down.snr / 4.0); writeField(_fDownSnr, buf, size); endUpdate(); @@ -84,6 +85,10 @@ void LayoutSurveySuccess::updateStats(LoRaHandler::LoRaPing ping) { void LayoutSurveySuccess::updateGpsLatitude(GPSPARSER::latitude lat) { } +void LayoutSurveySuccess::updateGpsLatitude(std::string msg) { + writeField(_fGpsLat, msg, true); +} + void LayoutSurveySuccess::updateGpsLongitude(GPSPARSER::longitude lon) { } @@ -103,7 +108,7 @@ void LayoutSurveySuccess::updateSw2(std::string sw2) { } void LayoutSurveySuccess::updateCountdown(uint32_t seconds) { - char buf[16]; + char buf[32]; size_t size; memset(buf, 0, sizeof(buf)); @@ -114,3 +119,12 @@ void LayoutSurveySuccess::updateCountdown(uint32_t seconds) { writeField(_fSw2, buf, size, true); } +void LayoutSurveySuccess::updatePassFail(uint8_t pass, uint8_t fail) { + char buf[32]; + size_t size; + + memset(buf, 0, sizeof(buf)); + size = snprintf(buf, sizeof(buf), "Pass %u Fail %u", pass, fail); + writeField(_fGpsTime, buf, size, true); +} + diff --git a/Layout/LayoutSurveySuccess.h b/Layout/LayoutSurveySuccess.h index dd7e740..49113cb 100644 --- a/Layout/LayoutSurveySuccess.h +++ b/Layout/LayoutSurveySuccess.h @@ -16,12 +16,14 @@ class LayoutSurveySuccess : public Layout { void updatePower(uint32_t power); void updateStats(LoRaHandler::LoRaPing ping); void updateGpsLatitude(GPSPARSER::latitude lat); + void updateGpsLatitude(std::string msg); void updateGpsLongitude(GPSPARSER::longitude lon); void updateGpsTime(struct tm time); void updateInfo(std::string info); void updateSw1(std::string sw1); void updateSw2(std::string sw2); void updateCountdown(uint32_t seconds); + void updatePassFail(uint8_t pass, uint8_t fail); private: Label _lId; diff --git a/Layout/LayoutSweepComplete.cpp b/Layout/LayoutSweepComplete.cpp new file mode 100644 index 0000000..f921b3c --- /dev/null +++ b/Layout/LayoutSweepComplete.cpp @@ -0,0 +1,53 @@ +#include "LayoutSweepComplete.h" + +LayoutSweepComplete::LayoutSweepComplete(DOGS102* lcd) + : Layout(lcd), + _lId(0, 0, "ID"), + _lInfo(0, 1, "Sweep Finished"), + _lPass(0, 5, "Pass"), + _lFail(9, 5, "Fail"), + _lSw2(0, 7, "Sweep"), + _fId(2, 0, 5), + _fPass(5, 5, 2), + _fFail(14, 5, 2) +{} + +LayoutSweepComplete::~LayoutSweepComplete() {} + +void LayoutSweepComplete::display() { + clear(); + startUpdate(); + + writeLabel(_lId); + writeLabel(_lInfo); + writeLabel(_lPass); + writeLabel(_lFail); + writeLabel(_lSw2); + + endUpdate(); +} + +void LayoutSweepComplete::updateId(uint32_t id) { + char buf[16]; + size_t size; + + size = snprintf(buf, sizeof(buf), "%lu", id); + writeField(_fId, buf, size, true); +} + +void LayoutSweepComplete::updatePass(uint8_t pass) { + char buf[8]; + size_t size; + + size = snprintf(buf, sizeof(buf), "%u", pass); + writeField(_fPass, buf, size, true); +} + +void LayoutSweepComplete::updateFail(uint8_t fail) { + char buf[8]; + size_t size; + + size = snprintf(buf, sizeof(buf), "%u", fail); + writeField(_fFail, buf, size, true); +} + diff --git a/Layout/LayoutSweepComplete.h b/Layout/LayoutSweepComplete.h new file mode 100644 index 0000000..221201d --- /dev/null +++ b/Layout/LayoutSweepComplete.h @@ -0,0 +1,28 @@ +#ifndef __LAYOUTSWEEPCOMPLETE_H__ +#define __LAYOUTSWEEPCOMPLETE_H__ + +#include "Layout.h" + +class LayoutSweepComplete : public Layout { + public: + LayoutSweepComplete(DOGS102* lcd); + ~LayoutSweepComplete(); + + void display(); + void updateId(uint32_t id); + void updatePass(uint8_t pass); + void updateFail(uint8_t fail); + + private: + Label _lId; + Label _lInfo; + Label _lPass; + Label _lFail; + Label _lSw2; + + Field _fId; + Field _fPass; + Field _fFail; +}; + +#endif diff --git a/Layout/LayoutSweepHelp.cpp b/Layout/LayoutSweepHelp.cpp deleted file mode 100644 index eb40013..0000000 --- a/Layout/LayoutSweepHelp.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "LayoutSweepHelp.h" - -LayoutSweepHelp::LayoutSweepHelp(DOGS102* lcd) - : Layout(lcd), - _lMode(0, 0, "Survey Sweep"), - _lIns1(0, 4, "Hold SW1 any time"), - _lIns2(0, 5, "for Main Menu"), - _lSw1(11, 7, "Cancel"), - _lSw2(0, 7, "Sweep") -{} - -LayoutSweepHelp::~LayoutSweepHelp() {} - -void LayoutSweepHelp::display() { - clear(); - startUpdate(); - - writeLabel(_lMode); - writeLabel(_lIns1); - writeLabel(_lIns2); - writeLabel(_lSw1); - writeLabel(_lSw2); - - endUpdate(); -} - diff --git a/Layout/LayoutSweepHelp.h b/Layout/LayoutSweepHelp.h deleted file mode 100644 index 0ec0e45..0000000 --- a/Layout/LayoutSweepHelp.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef __LAYOUTSWEEPHELP_H__ -#define __LAYOUTSWEEPHELP_H__ - -#include "Layout.h" - -class LayoutSweepHelp : public Layout { - public: - LayoutSweepHelp(DOGS102* lcd); - ~LayoutSweepHelp(); - - void display(); - - private: - Label _lMode; - Label _lIns1; - Label _lIns2; - Label _lSw1; - Label _lSw2; -}; - -#endif diff --git a/Layout/LayoutSweepProgress.cpp b/Layout/LayoutSweepProgress.cpp new file mode 100644 index 0000000..ec4bbc9 --- /dev/null +++ b/Layout/LayoutSweepProgress.cpp @@ -0,0 +1,46 @@ +#include "LayoutSweepProgress.h" + +LayoutSweepProgress::LayoutSweepProgress(DOGS102* lcd) + : Layout(lcd), + _lMsg1(6, 2, "Sweep"), + _lMsg2(7, 3, "in"), + _lMsg3(4, 4, "Progress"), + _fProgress(6, 1, 5), + _fCountdownLabel(0, 6, 17), + _fCountdown(0, 7, 9) +{} + +LayoutSweepProgress::~LayoutSweepProgress() {} + +void LayoutSweepProgress::display() { + clear(); + startUpdate(); + + writeLabel(_lMsg1); + writeLabel(_lMsg2); + writeLabel(_lMsg3); + + endUpdate(); +} + +void LayoutSweepProgress::updateProgress(uint8_t complete, uint8_t total) { + char buf[8]; + size_t size; + + memset(buf, 0, sizeof(buf)); + size = snprintf(buf, sizeof(buf), "%u/%u", complete, total); + writeField(_fProgress, buf, size, true); +} + +void LayoutSweepProgress::updateCountdown(uint32_t seconds) { + char buf[16]; + size_t size; + + memset(buf, 0, sizeof(buf)); + // for some reason, there's a % character that gets displayed in the last column + // add the extra spaces to wipe it out + writeField(_fCountdownLabel, "No Free Channel ", true); + size = snprintf(buf, sizeof(buf), "%lu s", seconds); + writeField(_fCountdown, buf, size, true); +} + diff --git a/Layout/LayoutSweepProgress.h b/Layout/LayoutSweepProgress.h new file mode 100644 index 0000000..d8e8720 --- /dev/null +++ b/Layout/LayoutSweepProgress.h @@ -0,0 +1,26 @@ +#ifndef __LAYOUTSWEEPPROGRESS_H__ +#define __LAYOUTSWEEPPROGRESS_H__ + +#include "Layout.h" + +class LayoutSweepProgress : public Layout { + public: + LayoutSweepProgress(DOGS102* lcd); + ~LayoutSweepProgress(); + + void display(); + + void updateProgress(uint8_t complete, uint8_t total); + void updateCountdown(uint32_t seconds); + + private: + Label _lMsg1; + Label _lMsg2; + Label _lMsg3; + + Field _fProgress; + Field _fCountdownLabel; + Field _fCountdown; +}; + +#endif diff --git a/Mode/Mode.cpp b/Mode/Mode.cpp index a30ac6e..f049e33 100644 --- a/Mode/Mode.cpp +++ b/Mode/Mode.cpp @@ -70,13 +70,13 @@ bool Mode::appendDataFile(const DataItem& data) { // if we had GPS lock, format GPS data if (data.lock > 0) { - snprintf(lat_buf, sizeof(lat_buf), "%d %d %d.%03d %c", + snprintf(lat_buf, sizeof(lat_buf), "%3d %2d %2d.%03d %c", abs(data.gps_latitude.degrees), data.gps_latitude.minutes, (data.gps_latitude.seconds * 6) / 1000, (data.gps_latitude.seconds % 6) / 1000, (data.gps_latitude.degrees > 0) ? 'N' : 'S'); - snprintf(lon_buf, sizeof(lon_buf), "%d %d %d.%03d %c", + snprintf(lon_buf, sizeof(lon_buf), "%3d %2d %2d.%03d %c", abs(data.gps_longitude.degrees), data.gps_longitude.minutes, (data.gps_longitude.seconds * 6) / 1000, @@ -94,11 +94,13 @@ bool Mode::appendDataFile(const DataItem& data) { } if (data.status) { - snprintf(stats_buf, sizeof(stats_buf), "%d,%d.%ld,%d,%d.%ld", - data.ping.up.rssi, - data.ping.up.snr / 10, abs(data.ping.up.snr) % 10, - data.ping.down.rssi, - data.ping.down.snr / 4, (abs(data.ping.down.snr) % 10) * 25); + float up_snr = (float)data.ping.up.snr / 10.0; + float down_snr = (float)data.ping.down.snr / 4.0; + snprintf(stats_buf, sizeof(stats_buf), "%3d,%2.1f,%3d,%2.1f", + abs(data.ping.up.rssi), + up_snr, + abs(data.ping.down.rssi), + down_snr); } size = snprintf(main_buf, sizeof(main_buf), "%s,%c,%ld,%s,%s,%s,%s,%s,%s,%lu\n", @@ -122,7 +124,7 @@ bool Mode::appendDataFile(const DataItem& data) { logError("failed to write survey data to file"); return false; } else { - logInfo("successfully wrote survey data to file"); + logInfo("successfully wrote survey data to file\r\n\t%s", main_buf); } return true; @@ -133,61 +135,136 @@ void Mode::updateData(DataItem& data, DataType type, bool status) { data.index = _index; data.status = status; data.lock = 0; - data.gps_longitude = _mdot_gps.getLongitude(); - data.gps_latitude = _mdot_gps.getLatitude(); - data.gps_altitude = _mdot_gps.getAltitude(); + 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; } +uint32_t Mode::getIndex(DataType type) { + uint32_t index = 0; + mDot::mdot_file file; + size_t buf_size = 128; + char buf[buf_size]; + bool done = false; + char search; + + int read_offset; + int read_size; + int reduce = buf_size - 32; + int bytes_read; + int ret; + int current; + + if (type == single) + search = 'P'; + else + search = 'S'; + + file = _dot->openUserFile(_file_name, mDot::FM_RDONLY); + if (file.fd < 0) { + logError("failed to open survey data file"); + } else { + logInfo("file size %d", file.size); + if (file.size > buf_size) { + read_offset = file.size - buf_size - 1; + read_size = buf_size; + } else { + read_offset = 0; + read_size = file.size; + } + + while (! done) { + if (read_offset == 0) + done = true; + + logInfo("reading from index %d, %d bytes", read_offset, read_size); + + if (! _dot->seekUserFile(file, read_offset, SEEK_SET)) { + logError("failed to seek %d/%d", read_offset, file.size); + return 0; + } + memset(buf, 0, buf_size); + ret = _dot->readUserFile(file, (void*)buf, read_size); + if (ret != read_size) { + logError("failed to read"); + return 0; + } + logInfo("read %d bytes [%s]", ret, buf); + + // read_size - 1 is the last byte in the buffer + for (current = read_size - 1; current >= 0; current--) { + if ((buf[current] == '\n' && current != read_size - 1) || current == 0) { + int test = current; + logInfo("found potential %d, %c", read_offset + current, buf[test + 1]); + if (buf[test + 1] == search) { + logInfo("reading index"); + sscanf(&buf[test + 2], "%ld", &index); + done = true; + break; + } + } + } + + read_offset = (read_offset - reduce > 0) ? read_offset - reduce : 0; + } + _dot->closeUserFile(file); + } + + logInfo("returning index %d", index); + + 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); + 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; } diff --git a/Mode/Mode.h b/Mode/Mode.h index 8c7b0d9..5d41ed1 100644 --- a/Mode/Mode.h +++ b/Mode/Mode.h @@ -47,6 +47,7 @@ class Mode { bool deleteDataFile(); bool appendDataFile(const DataItem& data); 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); diff --git a/Mode/ModeSingle.cpp b/Mode/ModeSingle.cpp index 77f789a..083b72d 100644 --- a/Mode/ModeSingle.cpp +++ b/Mode/ModeSingle.cpp @@ -56,7 +56,7 @@ bool ModeSingle::start() { switch (_state) { case check_file: _state = show_help; - _index = 0; // need to get index from NVM + _index = getIndex(single); displayHelp(); break; case confirm: @@ -66,6 +66,7 @@ bool ModeSingle::start() { case show_help: incrementRatePower(); _help.updateMsg(formatNewRatePower()); + logInfo("new data rate %u, power %lu", _data_rate, _power); break; case in_progress: // do nothing @@ -73,12 +74,14 @@ bool ModeSingle::start() { case success: incrementRatePower(); _success.updateInfo(formatNewRatePower()); + logInfo("new data rate %u, power %lu", _data_rate, _power); break; case data: break; case failure: incrementRatePower(); - _failure.updateInfo(formatNewRatePower()); + _failure.updateInfo2(formatNewRatePower()); + logInfo("new data rate %u, power %lu", _data_rate, _power); break; } break; @@ -145,6 +148,7 @@ bool ModeSingle::start() { case in_progress: _ping_result = _lora->getPingResults(); displaySuccess(); + logInfo("ping successful"); updateData(_data, single, true); appendDataFile(_data); if (_send_data) { @@ -181,10 +185,13 @@ bool ModeSingle::start() { _failure.display(); _failure.updateId(_index); // mDot::DataRateStr returns format SF_XX - we only want to display the XX part - _success.updateRate(_dot->DataRateStr(_data_rate).substr(3)); + _failure.updateRate(_dot->DataRateStr(_data_rate).substr(3)); updateData(_data, single, false); appendDataFile(_data); _failure.updatePower(_power); + _failure.updateSw1(" Power"); + _failure.updateSw2("Survey"); + logInfo("ping failed"); break; case success: break; @@ -212,6 +219,7 @@ bool ModeSingle::start() { _success.updateInfo("Data Send Success"); _success.updateSw1(" Power"); _success.updateSw2("Survey"); + logInfo("data send success"); break; case failure: break; @@ -235,6 +243,7 @@ bool ModeSingle::start() { _success.updateInfo("Data Send Failure"); _success.updateSw1(" Power"); _success.updateSw2("Survey"); + logInfo("data send failed"); break; case failure: break; @@ -267,7 +276,7 @@ bool ModeSingle::start() { } } if (send_ping) { - logInfo("sending ping"); + logInfo("sending ping %s %d", _dot->DataRateStr(_data_rate).c_str(), _power); send_ping = false; _lora->setDataRate(_data_rate); _lora->setPower(_power); @@ -276,7 +285,8 @@ bool ModeSingle::start() { } if (send_data) { std::vector<uint8_t> s_data; - logInfo("sending data"); + logInfo("sending data %s %d", _dot->DataRateStr(_data_rate).c_str(), _power); + send_data = false; _success.updateInfo("Data Sending..."); _lora->setDataRate(_data_rate); _lora->setPower(_power); @@ -303,7 +313,7 @@ void ModeSingle::displaySuccess() { // display GPS latitude, longitude, and time // else // display "no lock" - _success.updateInfo("No GPS Lock"); + _success.updateGpsLatitude("No GPS Lock"); } std::string ModeSingle::formatNewRatePower() { diff --git a/Mode/ModeSweep.cpp b/Mode/ModeSweep.cpp new file mode 100644 index 0000000..938ec83 --- /dev/null +++ b/Mode/ModeSweep.cpp @@ -0,0 +1,436 @@ +#include "ModeSweep.h" +#include "MTSLog.h" + +ModeSweep::ModeSweep(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora) + : Mode(lcd, buttons, dot, lora), + _help(lcd), + _file(lcd), + _confirm(lcd), + _progress(lcd), + _success(lcd), + _failure(lcd), + _complete(lcd) +{} + +ModeSweep::~ModeSweep() {} + +bool ModeSweep::start() { + bool data_file = false; + bool send_ping = false; + bool send_data = false; + bool no_channel_ping = false; + bool no_channel_data = false; + + // clear any stale signals + osSignalClear(_main_id, buttonSignal | loraSignal); + + // 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(); + + // pull the minimum and maximum payload size out of config + // min payload size is wake interval + // max payload size is wake delay + _min_payload = _dot->getWakeInterval(); + _max_payload = _dot->getWakeDelay(); + + // pull the minimum and maximum power out of config + // min power is wake timeout + // max power is wake mode + _min_power = _dot->getWakeTimeout(); + _max_power = _dot->getWakeMode(); + + // compute the total number of surveys we will do + _points = generatePoints(); + _survey_total = _points.size(); + _survey_current = 1; + _survey_success = 0; + _survey_failure = 0; + + logInfo("%u points", _survey_total); + for (std::vector<point>::iterator it = _points.begin(); it != _points.end(); it++) + logInfo("%s,%lu", _dot->DataRateStr(it->first).substr(3).c_str(), it->second); + + // see if survey data file exists + std::vector<mDot::mdot_file> files = _dot->listUserFiles(); + for (std::vector<mDot::mdot_file>::iterator it = files.begin(); it != files.end(); it++) { + if (strcmp(it->name, _file_name) == 0) { + logInfo("found survey data file"); + data_file = true; + break; + } + } + if (data_file) { + _state = check_file; + _file.display(); + } else { + _state = show_help; + _index = 1; + displayHelp(); + } + + _display_timer.reset(); + + while (true) { + osEvent e = Thread::signal_wait(0, 250); + if (e.status == osEventSignal) { + if (e.value.signals & buttonSignal) { + _be = _buttons->getButtonEvent(); + + switch (_be) { + case ButtonHandler::sw1_press: + switch (_state) { + case check_file: + _state = show_help; + _index = getIndex(sweep) + 1; + displayHelp(); + break; + case confirm: + _state = check_file; + _file.display(); + break; + case show_help: + break; + case in_progress: + break; + case success: + _state = complete; + _display_timer.stop(); + _display_timer.reset(); + logInfo("sweep finished"); + _complete.display(); + _complete.updateId(_index++); + _complete.updatePass(_survey_success); + _complete.updateFail(_survey_failure); + _survey_success = 0; + _survey_failure = 0; + break; + case data: + break; + case failure: + _state = complete; + _display_timer.stop(); + _display_timer.reset(); + logInfo("sweep finished"); + _complete.display(); + _complete.updateId(_index++); + _complete.updatePass(_survey_success); + _complete.updateFail(_survey_failure); + _survey_success = 0; + _survey_failure = 0; + break; + case complete: + break; + } + break; + + case ButtonHandler::sw2_press: + switch (_state) { + case check_file: + _state = confirm; + _confirm.display(); + break; + case confirm: + _state = show_help; + logInfo("deleting survey data file"); + _dot->deleteUserFile(_file_name); + _index = 1; + displayHelp(); + break; + case show_help: + _state = in_progress; + _progress.display(); + _progress.updateProgress(_survey_current, _survey_total); + if (_lora->getNextTx() > 0) + no_channel_ping = true; + else + send_ping = true; + break; + case in_progress: + break; + case success: + break; + case data: + break; + case failure: + break; + case complete: + _state = in_progress; + _survey_current = 1; + _progress.display(); + _progress.updateProgress(_survey_current, _survey_total); + if (_lora->getNextTx() > 0) + no_channel_ping = true; + else + send_ping = true; + break; + } + break; + case ButtonHandler::sw1_hold: + return true; + } + } + if (e.value.signals & loraSignal) { + _ls = _lora->getStatus(); + switch (_ls) { + case LoRaHandler::ping_success: + switch (_state) { + case check_file: + break; + case confirm: + break; + case show_help: + break; + case in_progress: + _survey_success++; + _ping_result = _lora->getPingResults(); + displaySuccess(); + logInfo("ping successful"); + updateData(_data, sweep, true); + appendDataFile(_data); + if (_send_data) { + _state = data; + if (_lora->getNextTx() > 0) + no_channel_data = true; + else + send_data = true; + } else { + _state = success; + _success.updateSw1(" Cancel"); + _display_timer.start(); + } + break; + case success: + break; + case data: + break; + case failure: + break; + case complete: + break; + } + break; + + case LoRaHandler::ping_failure: + switch (_state) { + case check_file: + break; + case confirm: + break; + case show_help: + break; + case in_progress: + _survey_failure++; + _state = failure; + _failure.display(); + _failure.updateId(_index); + // mDot::DataRateStr returns format SF_XX - we only want to display the XX part + _failure.updateRate(_dot->DataRateStr(_data_rate).substr(3)); + _failure.updatePower(_power); + _failure.updatePassFail(_survey_success, _survey_failure); + _failure.updateSw1(" Cancel"); + updateData(_data, sweep, false); + appendDataFile(_data); + logInfo("ping failed"); + _display_timer.start(); + break; + case success: + break; + case data: + break; + case failure: + break; + case complete: + break; + } + break; + + case LoRaHandler::send_success: + switch (_state) { + case check_file: + break; + case confirm: + break; + case show_help: + break; + case in_progress: + break; + case success: + break; + case data: + _state = success; + _success.updateInfo("Data Send Success"); + _success.updateSw1(" Cancel"); + logInfo("data send success"); + _display_timer.start(); + break; + case failure: + break; + case complete: + break; + } + break; + + case LoRaHandler::send_failure: + switch (_state) { + case check_file: + break; + case confirm: + break; + case show_help: + break; + case in_progress: + break; + case success: + break; + case data: + _state = success; + _success.updateInfo("Data Send Failure"); + _success.updateSw1(" Cancel"); + logInfo("data send failed"); + _display_timer.start(); + break; + case failure: + break; + case complete: + break; + } + break; + } + } + } + + if (_display_timer.read_ms() > 2000) { + _display_timer.stop(); + _display_timer.reset(); + if (_survey_current == _survey_total) { + logInfo("sweep finished"); + _state = complete; + _complete.display(); + _complete.updateId(_index++); + _complete.updatePass(_survey_success); + _complete.updateFail(_survey_failure); + _survey_success = 0; + _survey_failure = 0; + } else { + logInfo("starting next ping"); + _state = in_progress; + _survey_current++; + _progress.display(); + _progress.updateProgress(_survey_current, _survey_total); + no_channel_ping = true; + } + } + + if (no_channel_ping) { + uint32_t t = _lora->getNextTx(); + if (t > 0) { + logInfo("next tx %lu ms", t); + _progress.updateCountdown(t / 1000); + } else { + _progress.display(); + _progress.updateProgress(_survey_current, _survey_total); + no_channel_ping = false; + send_ping = true; + } + } + if (no_channel_data) { + uint32_t t = _lora->getNextTx(); + if (t > 0) { + logInfo("next tx %lu ms", t); + _success.updateCountdown(t / 1000); + } else { + displaySuccess(); + no_channel_data = false; + send_data = true; + } + } + if (send_ping) { + point p = _points[_survey_current - 1]; + _data_rate = p.first; + _power = p.second; + logInfo("sending ping %s %d", _dot->DataRateStr(_data_rate).c_str(), _power); + send_ping = false; + _lora->setDataRate(_data_rate); + _lora->setPower(_power); + _lora->ping(); + } + if (send_data) { + std::vector<uint8_t> s_data; + logInfo("sending data %s %d", _dot->DataRateStr(_data_rate).c_str(), _power); + send_data = false; + _success.updateInfo("Data Sending..."); + _lora->setDataRate(_data_rate); + _lora->setPower(_power); + _lora->send(s_data); + } + } +} + +void ModeSweep::displayHelp() { + _help.display(); + _help.updateMode("Survey Sweep"); + _help.updateSw1(" Cancel"); + _help.updateSw2("Sweep"); +} + +void ModeSweep::displaySuccess() { + _success.display(); + _success.updateId(_index); + // mDot::DataRateStr returns format SF_XX - we only want to display the XX part + _success.updateRate(_dot->DataRateStr(_data_rate).substr(3)); + _success.updatePower(_power); + _success.updateStats(_ping_result); + // if GPS lock + // display GPS latitude, longitude, and time + // else + // display "no lock" + _success.updateGpsLatitude("No GPS Lock"); + _success.updatePassFail(_survey_success, _survey_failure); +} + +std::vector<point> ModeSweep::generatePoints() { + std::vector<point> p; + uint8_t min_rate; + uint8_t max_rate; + + max_rate = payloadToRate(_min_payload); + min_rate = payloadToRate(_max_payload); + + for (int rate = min_rate; rate >= max_rate; rate--) { + if (_max_power - _min_power < 4) { + for (uint32_t power = _min_power; power <= _max_power; power++) + p.push_back(std::make_pair(rate, power)); + } else { + p.push_back(std::make_pair(rate, _min_power)); + p.push_back(std::make_pair(rate, (uint32_t)ceil( (float(_max_power) - float(_min_power)) * 0.33 + float(_min_power)))); + p.push_back(std::make_pair(rate, (uint32_t)ceil( (float(_max_power) - float(_min_power)) * 0.66 + float(_min_power)))); + p.push_back(std::make_pair(rate, _max_power)); + } + } + + return p; +} + +uint8_t ModeSweep::payloadToRate(uint8_t payload) { + if (_band == mDot::FB_915) { + if (payload <= mDot::MaxLengths_915[mDot::SF_10]) + return mDot::SF_10; + else if (payload <= mDot::MaxLengths_915[mDot::SF_9]) + return mDot::SF_9; + else if (payload <= mDot::MaxLengths_915[mDot::SF_8]) + return mDot::SF_8; + else + return mDot::SF_7; + } else { + if (payload <= mDot::MaxLengths_868[mDot::SF_12]) + return mDot::SF_12; + else if (payload <= mDot::MaxLengths_868[mDot::SF_9]) + return mDot::SF_9; + else + return mDot::SF_7; + } + + return mDot::SF_7; +} + diff --git a/Mode/ModeSweep.h b/Mode/ModeSweep.h new file mode 100644 index 0000000..5eebda1 --- /dev/null +++ b/Mode/ModeSweep.h @@ -0,0 +1,60 @@ +#ifndef __MODESWEEP_H__ +#define __MODESWEEP_H__ + +#include "Mode.h" +#include "LayoutHelp.h" +#include "LayoutFile.h" +#include "LayoutConfirm.h" +#include "LayoutSweepProgress.h" +#include "LayoutSurveySuccess.h" +#include "LayoutSurveyFailure.h" +#include "LayoutSweepComplete.h" + +typedef std::pair<uint8_t, uint32_t> point; + +class ModeSweep : public Mode { + public: + ModeSweep(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora); + ~ModeSweep(); + + bool start(); + + private: + void displayHelp(); + void displaySuccess(); + std::vector<point> generatePoints(); + uint8_t payloadToRate(uint8_t payload); + + typedef enum { + check_file = 0, + confirm, + show_help, + in_progress, + success, + data, + failure, + complete + } state; + + LayoutHelp _help; + LayoutFile _file; + LayoutConfirm _confirm; + LayoutSweepProgress _progress; + LayoutSurveySuccess _success; + LayoutSurveyFailure _failure; + LayoutSweepComplete _complete; + DataItem _data; + + uint8_t _min_payload; + uint8_t _max_payload; + uint32_t _min_power; + uint32_t _max_power; + uint8_t _survey_current; + uint8_t _survey_total; + uint8_t _survey_success; + uint8_t _survey_failure; + std::vector<point> _points; + Timer _display_timer; +}; + +#endif @@ -18,6 +18,7 @@ // mode objects #include "ModeJoin.h" #include "ModeSingle.h" +#include "ModeSweep.h" #include "ModeConfig.h" // misc heders #include <string> @@ -43,6 +44,7 @@ mDot* dot; // Modes ModeJoin* modeJoin; ModeSingle* modeSingle; +ModeSweep* modeSweep; ModeConfig* modeConfig; // Serial debug port @@ -68,6 +70,7 @@ int main() { modeJoin = new ModeJoin(lcd, buttons, dot, lora); modeSingle = new ModeSingle(lcd, buttons, dot, lora); + modeSweep = new ModeSweep(lcd, buttons, dot, lora); modeConfig = new ModeConfig(lcd, buttons, dot, lora); // display startup screen for 3 seconds @@ -144,7 +147,7 @@ void mainMenu() { modeSingle->start(); } else if (selected == menu_strings[sweep]) { if (modeJoin->start()) - surveySweep(); + modeSweep->start(); } mode_selected = false; @@ -184,35 +187,3 @@ void loraDemo() { } } -void surveySweep() { - LayoutHelp lh(lcd); - lh.display(); - lh.updateMode("Survey Sweep"); - lh.updateSw1(" Cancel"); - lh.updateSw2("Sweep"); - - // clear any stale signals - osSignalClear(main_id, buttonSignal | loraSignal); - - logInfo("survey sweep mode"); - - while (true) { - osEvent e = Thread::signal_wait(buttonSignal); - if (e.status == osEventSignal) { - ButtonHandler::ButtonEvent ev = buttons->getButtonEvent(); - switch (ev) { - case ButtonHandler::sw1_press: - logInfo("cancel"); - break; - case ButtonHandler::sw2_press: - logInfo("start sweep"); - break; - case ButtonHandler::sw1_hold: - return; - default: - break; - } - } - } -} - |