diff options
author | Mike Fiore <mfiore@multitech.com> | 2015-11-20 08:13:35 -0600 |
---|---|---|
committer | Mike Fiore <mfiore@multitech.com> | 2015-11-20 08:13:35 -0600 |
commit | 674cdb5c13bad3598381b81d843b5aeee5798d1f (patch) | |
tree | 1d18d592b5df2513036838bc94530648ad36631e | |
parent | 11412cbac7021dd8aee14ac4f1dc25994c9ab45b (diff) | |
download | mtdot-box-evb-factory-firmware-674cdb5c13bad3598381b81d843b5aeee5798d1f.tar.gz mtdot-box-evb-factory-firmware-674cdb5c13bad3598381b81d843b5aeee5798d1f.tar.bz2 mtdot-box-evb-factory-firmware-674cdb5c13bad3598381b81d843b5aeee5798d1f.zip |
implement basic single survey mode - still needs sending data packet and data survey file
-rw-r--r-- | Layout/LayoutConfirm.cpp | 28 | ||||
-rw-r--r-- | Layout/LayoutConfirm.h | 22 | ||||
-rw-r--r-- | Layout/LayoutFile.cpp | 30 | ||||
-rw-r--r-- | Layout/LayoutFile.h | 23 | ||||
-rw-r--r-- | Layout/LayoutJoin.cpp | 13 | ||||
-rw-r--r-- | Layout/LayoutJoin.h | 1 | ||||
-rw-r--r-- | Layout/LayoutSurveyFailure.cpp | 58 | ||||
-rw-r--r-- | Layout/LayoutSurveyFailure.h | 33 | ||||
-rw-r--r-- | Layout/LayoutSurveyProgress.cpp | 34 | ||||
-rw-r--r-- | Layout/LayoutSurveyProgress.h | 24 | ||||
-rw-r--r-- | Layout/LayoutSurveySuccess.cpp | 101 | ||||
-rw-r--r-- | Layout/LayoutSurveySuccess.h | 46 | ||||
-rw-r--r-- | LoRaHandler/LoRaHandler.cpp | 20 | ||||
-rw-r--r-- | LoRaHandler/LoRaHandler.h | 3 | ||||
-rw-r--r-- | Mode/ModeJoin.cpp | 51 | ||||
-rw-r--r-- | Mode/ModeJoin.h | 2 | ||||
-rw-r--r-- | Mode/ModeSingle.cpp | 282 | ||||
-rw-r--r-- | Mode/ModeSingle.h | 55 | ||||
-rw-r--r-- | main.cpp | 56 |
19 files changed, 810 insertions, 72 deletions
diff --git a/Layout/LayoutConfirm.cpp b/Layout/LayoutConfirm.cpp new file mode 100644 index 0000000..93fe85c --- /dev/null +++ b/Layout/LayoutConfirm.cpp @@ -0,0 +1,28 @@ +#include "LayoutConfirm.h" + +LayoutConfirm::LayoutConfirm(DOGS102* lcd) + : Layout(lcd), + _lMsg1(0, 0, "Are You Sure You"), + _lMsg2(0, 1, "Want to Erase It?"), + _lIns1(0, 4, "Hold SW1 any time"), + _lIns2(0, 5, "for Main Menu"), + _lSw1(14, 7, "No"), + _lSw2(1, 7, "Yes") +{} + +LayoutConfirm::~LayoutConfirm() {} + +void LayoutConfirm::display() { + clear(); + startUpdate(); + + writeLabel(_lMsg1); + writeLabel(_lMsg2); + writeLabel(_lIns1); + writeLabel(_lIns2); + writeLabel(_lSw1); + writeLabel(_lSw2); + + endUpdate(); +} + diff --git a/Layout/LayoutConfirm.h b/Layout/LayoutConfirm.h new file mode 100644 index 0000000..891094e --- /dev/null +++ b/Layout/LayoutConfirm.h @@ -0,0 +1,22 @@ +#ifndef __LAYOUTCONFIRM_H__ +#define __LAYOUTCONFIRM_H__ + +#include "Layout.h" + +class LayoutConfirm : public Layout { + public: + LayoutConfirm(DOGS102* lcd); + ~LayoutConfirm(); + + void display(); + + private: + Label _lMsg1; + Label _lMsg2; + Label _lIns1; + Label _lIns2; + Label _lSw1; + Label _lSw2; +}; + +#endif diff --git a/Layout/LayoutFile.cpp b/Layout/LayoutFile.cpp new file mode 100644 index 0000000..fd54ff1 --- /dev/null +++ b/Layout/LayoutFile.cpp @@ -0,0 +1,30 @@ +#include "LayoutFile.h" + +LayoutFile::LayoutFile(DOGS102* lcd) + : Layout(lcd), + _lMsg1(0, 0, "Erase or Append"), + _lMsg2(0, 1, "to Existing"), + _lMsg3(0, 2, "Survey Data File?"), + _lIns1(0, 4, "Hold SW1 any time"), + _lIns2(0, 5, "for Main Menu"), + _lSw1(11, 7, "Append"), + _lSw2(0, 7, "Erase") +{} + +LayoutFile::~LayoutFile() {} + +void LayoutFile::display() { + clear(); + startUpdate(); + + writeLabel(_lMsg1); + writeLabel(_lMsg2); + writeLabel(_lMsg3); + writeLabel(_lIns1); + writeLabel(_lIns2); + writeLabel(_lSw1); + writeLabel(_lSw2); + + endUpdate(); +} + diff --git a/Layout/LayoutFile.h b/Layout/LayoutFile.h new file mode 100644 index 0000000..640249f --- /dev/null +++ b/Layout/LayoutFile.h @@ -0,0 +1,23 @@ +#ifndef __LAYOUTFILE_H__ +#define __LAYOUTFILE_H__ + +#include "Layout.h" + +class LayoutFile : public Layout { + public: + LayoutFile(DOGS102* lcd); + ~LayoutFile(); + + void display(); + + private: + Label _lMsg1; + Label _lMsg2; + Label _lMsg3; + Label _lIns1; + Label _lIns2; + Label _lSw1; + Label _lSw2; +}; + +#endif diff --git a/Layout/LayoutJoin.cpp b/Layout/LayoutJoin.cpp index 5ff93d7..83e8551 100644 --- a/Layout/LayoutJoin.cpp +++ b/Layout/LayoutJoin.cpp @@ -53,6 +53,7 @@ void LayoutJoin::updateFsb(uint8_t band) { char buf[8]; size_t size; + memset(buf, 0, sizeof(buf)); size = snprintf(buf, sizeof(buf), "%u", band); writeField(_fFsb, buf, size, true); } @@ -65,6 +66,7 @@ void LayoutJoin::updatePower(uint32_t power) { char buf[16]; size_t size; + memset(buf, 0, sizeof(buf)); size = snprintf(buf, sizeof(buf), "%lu", power); writeField(_fPower, buf, size, true); } @@ -73,6 +75,7 @@ void LayoutJoin::updateAttempt(uint32_t attempt) { char buf[16]; size_t size; + memset(buf, 0, sizeof(buf)); size = snprintf(buf, sizeof(buf), "%lu", attempt); writeField(_fAttempt, buf, size, true); } @@ -85,14 +88,10 @@ void LayoutJoin::updateCountdown(uint32_t seconds) { char buf[16]; size_t size; + memset(buf, 0, sizeof(buf)); writeField(_fCountdownLabel, "No Free Channel", true); - size = snprintf(buf, sizeof(buf), "%lu", seconds); - writeField(_fPower, buf, size, true); -} - -void LayoutJoin::removeCountdown() { - removeField(_fCountdownLabel); - removeField(_fCountdown); + size = snprintf(buf, sizeof(buf), "%lu s", seconds); + writeField(_fCountdown, buf, size, true); } void LayoutJoin::displayCancel(bool display) { diff --git a/Layout/LayoutJoin.h b/Layout/LayoutJoin.h index 2f71aec..0f8e4f0 100644 --- a/Layout/LayoutJoin.h +++ b/Layout/LayoutJoin.h @@ -19,7 +19,6 @@ class LayoutJoin : public Layout { void updateAttempt(uint32_t attempt); void updateStatus(std::string status); void updateCountdown(uint32_t seconds); - void removeCountdown(); void displayCancel(bool display = true); private: diff --git a/Layout/LayoutSurveyFailure.cpp b/Layout/LayoutSurveyFailure.cpp new file mode 100644 index 0000000..d443098 --- /dev/null +++ b/Layout/LayoutSurveyFailure.cpp @@ -0,0 +1,58 @@ +#include "LayoutSurveyFailure.h" + +LayoutSurveyFailure::LayoutSurveyFailure(DOGS102* lcd) + : Layout(lcd), + _lTitle(0, 2, "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) +{} + +LayoutSurveyFailure::~LayoutSurveyFailure() {} + +void LayoutSurveyFailure::display() { + clear(); + startUpdate(); + + writeLabel(_lTitle); + writeLabel(_lId); + writeLabel(_lDr); + writeLabel(_lPwr); + writeLabel(_lSw1); + writeLabel(_lSw2); + + endUpdate(); +} + +void LayoutSurveyFailure::updateId(uint32_t id) { + char buf[16]; + size_t size; + + size = snprintf(buf, sizeof(buf), "%lu", id); + writeField(_fId, buf, size, true); +} + +void LayoutSurveyFailure::updateRate(std::string rate) { + writeField(_fDr, rate, true); +} + +void LayoutSurveyFailure::updatePower(uint32_t power) { + char buf[16]; + size_t size; + + size = snprintf(buf, sizeof(buf), "%lu", power); + writeField(_fPwr, buf, size, true); +} + +void LayoutSurveyFailure::updateInfo(std::string info) { + writeField(_fInfo, info, true); +} + diff --git a/Layout/LayoutSurveyFailure.h b/Layout/LayoutSurveyFailure.h new file mode 100644 index 0000000..473fd9f --- /dev/null +++ b/Layout/LayoutSurveyFailure.h @@ -0,0 +1,33 @@ +#ifndef __LAYOUTSURVEYFAILURE_H__ +#define __LAYOUTSURVEYFAILURE_H__ + +#include "Layout.h" + +class LayoutSurveyFailure : public Layout { + public: + LayoutSurveyFailure(DOGS102* lcd); + ~LayoutSurveyFailure(); + + void display(); + void updateId(uint32_t id); + void updateRate(std::string rate); + void updatePower(uint32_t power); + void updateInfo(std::string msg); + + 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; +}; + +#endif diff --git a/Layout/LayoutSurveyProgress.cpp b/Layout/LayoutSurveyProgress.cpp new file mode 100644 index 0000000..c0434f7 --- /dev/null +++ b/Layout/LayoutSurveyProgress.cpp @@ -0,0 +1,34 @@ +#include "LayoutSurveyProgress.h" + +LayoutSurveyProgress::LayoutSurveyProgress(DOGS102* lcd) + : Layout(lcd), + _lMsg1(5, 2, "Survey"), + _lMsg2(7, 3, "in"), + _lMsg3(4, 4, "Progress"), + _fCountdownLabel(0, 6, 17), + _fCountdown(0, 7, 9) +{} + +LayoutSurveyProgress::~LayoutSurveyProgress() {} + +void LayoutSurveyProgress::display() { + clear(); + startUpdate(); + + writeLabel(_lMsg1); + writeLabel(_lMsg2); + writeLabel(_lMsg3); + + endUpdate(); +} + +void LayoutSurveyProgress::updateCountdown(uint32_t seconds) { + char buf[16]; + size_t size; + + memset(buf, 0, sizeof(buf)); + writeField(_fCountdownLabel, "No Free Channel", true); + size = snprintf(buf, sizeof(buf), "%lu s", seconds); + writeField(_fCountdown, buf, size, true); +} + diff --git a/Layout/LayoutSurveyProgress.h b/Layout/LayoutSurveyProgress.h new file mode 100644 index 0000000..85a029b --- /dev/null +++ b/Layout/LayoutSurveyProgress.h @@ -0,0 +1,24 @@ +#ifndef __LAYOUTSURVEYPROGRESS_H__ +#define __LAYOUTSURVEYPROGRESS_H__ + +#include "Layout.h" + +class LayoutSurveyProgress : public Layout { + public: + LayoutSurveyProgress(DOGS102* lcd); + ~LayoutSurveyProgress(); + + void display(); + + void updateCountdown(uint32_t seconds); + + private: + Label _lMsg1; + Label _lMsg2; + Label _lMsg3; + + Field _fCountdownLabel; + Field _fCountdown; +}; + +#endif diff --git a/Layout/LayoutSurveySuccess.cpp b/Layout/LayoutSurveySuccess.cpp new file mode 100644 index 0000000..7bcc56b --- /dev/null +++ b/Layout/LayoutSurveySuccess.cpp @@ -0,0 +1,101 @@ +#include "LayoutSurveySuccess.h" + +LayoutSurveySuccess::LayoutSurveySuccess(DOGS102* lcd) + : Layout(lcd), + _lId(0, 0, "ID"), + _lDr(8, 0, "DR"), + _lPwr(13, 0, "P"), + _lUp(0, 1, "UP"), + _lDown(0, 2, "DWN"), + _lSw1(12, 7, "Power"), + _fId(2, 0, 5), + _fDr(10, 0, 2), + _fPwr(14, 0, 2), + _fUpRssi(3, 1, 7), + _fUpSnr(11, 1, 5), + _fDownRssi(4, 2, 7), + _fDownSnr(12, 2, 5), + _fGpsLat(0, 4, 17), + _fGpsLon(0, 3, 17), + _fGpsTime(0, 5, 17), + _fInfo(0, 6, 17), + _fSw2(0, 7, 8) +{} + +LayoutSurveySuccess::~LayoutSurveySuccess() {} + +void LayoutSurveySuccess::display() { + clear(); + startUpdate(); + + writeLabel(_lId); + writeLabel(_lDr); + writeLabel(_lPwr); + writeLabel(_lUp); + writeLabel(_lDown); + writeLabel(_lSw1); + + endUpdate(); +} + +void LayoutSurveySuccess::updateId(uint32_t id) { + char buf[16]; + size_t size; + + size = snprintf(buf, sizeof(buf), "%lu", id); + writeField(_fId, buf, size, true); +} + +void LayoutSurveySuccess::updateRate(std::string rate) { + writeField(_fDr, rate, true); +} + +void LayoutSurveySuccess::updatePower(uint32_t power) { + char buf[16]; + size_t size; + + size = snprintf(buf, sizeof(buf), "%lu", power); + writeField(_fPwr, buf, size, true); +} + +void LayoutSurveySuccess::updateStats(LoRaHandler::LoRaPing ping) { + char buf[16]; + size_t size; + + startUpdate(); + + size = snprintf(buf, sizeof(buf), "%3d dbm", ping.up.rssi); + 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); + writeField(_fUpSnr, buf, size); + + memset(buf, 0, sizeof(buf)); + size = snprintf(buf, sizeof(buf), "%3d dbm", ping.down.rssi); + writeField(_fDownRssi, buf, size); + + memset(buf, 0, sizeof(buf)); + size = snprintf(buf, sizeof(buf), "%2d.%1d", ping.down.snr / 4, abs(ping.up.snr) % 10 * 25); + writeField(_fDownSnr, buf, size); + + endUpdate(); +} + +void LayoutSurveySuccess::updateGpsLatitude(GPSPARSER::latitude lat) { +} + +void LayoutSurveySuccess::updateGpsLongitude(GPSPARSER::longitude lon) { +} + +void LayoutSurveySuccess::updateGpsTime(struct tm time) { +} + +void LayoutSurveySuccess::updateInfo(std::string info) { + writeField(_fInfo, info, true); +} + +void LayoutSurveySuccess::updateSw2(std::string sw2) { + writeField(_fSw2, sw2, true); +} + diff --git a/Layout/LayoutSurveySuccess.h b/Layout/LayoutSurveySuccess.h new file mode 100644 index 0000000..d5fe1af --- /dev/null +++ b/Layout/LayoutSurveySuccess.h @@ -0,0 +1,46 @@ +#ifndef __LAYOUTSURVEYSUCCESS_H__ +#define __LAYOUTSURVEYSUCCESS_H__ + +#include "Layout.h" +#include "LoRaHandler.h" +#include "GPSPARSER.h" + +class LayoutSurveySuccess : public Layout { + public: + LayoutSurveySuccess(DOGS102* lcd); + ~LayoutSurveySuccess(); + + void display(); + void updateId(uint32_t id); + void updateRate(std::string rate); + void updatePower(uint32_t power); + void updateStats(LoRaHandler::LoRaPing ping); + void updateGpsLatitude(GPSPARSER::latitude lat); + void updateGpsLongitude(GPSPARSER::longitude lon); + void updateGpsTime(struct tm time); + void updateInfo(std::string info); + void updateSw2(std::string sw2); + + private: + Label _lId; + Label _lDr; + Label _lPwr; + Label _lUp; + Label _lDown; + Label _lSw1; + + Field _fId; + Field _fDr; + Field _fPwr; + Field _fUpRssi; + Field _fUpSnr; + Field _fDownRssi; + Field _fDownSnr; + Field _fGpsLat; + Field _fGpsLon; + Field _fGpsTime; + Field _fInfo; + Field _fSw2; +}; + +#endif diff --git a/LoRaHandler/LoRaHandler.cpp b/LoRaHandler/LoRaHandler.cpp index 27eb266..7ba05f5 100644 --- a/LoRaHandler/LoRaHandler.cpp +++ b/LoRaHandler/LoRaHandler.cpp @@ -60,6 +60,7 @@ void l_worker(void const* argument) { case l_join: l->_mutex.lock(); ret = l->_dot->joinNetworkOnce(); + l->_join_attempts++; l->_mutex.unlock(); if (ret == mDot::MDOT_OK) { l->_status = LoRaHandler::join_success; @@ -80,7 +81,8 @@ void l_worker(void const* argument) { LoRaHandler::LoRaHandler(osThreadId main) : _main(main), _thread(l_worker, (void*)this), - _status(none) + _status(none), + _join_attempts(1) { _ping.status = false; } @@ -158,3 +160,19 @@ uint32_t LoRaHandler::getNextTx() { return ms; } +uint32_t LoRaHandler::getJoinAttempts() { + uint32_t val; + + _mutex.lock(); + val = _join_attempts; + _mutex.unlock(); + + return val; +} + +void LoRaHandler::resetJoinAttempts() { + _mutex.lock(); + _join_attempts = 1; + _mutex.unlock(); +} + diff --git a/LoRaHandler/LoRaHandler.h b/LoRaHandler/LoRaHandler.h index 20f9d6f..1a68668 100644 --- a/LoRaHandler/LoRaHandler.h +++ b/LoRaHandler/LoRaHandler.h @@ -36,6 +36,8 @@ class LoRaHandler { LoRaStatus getStatus(); LoRaPing getPingResults(); uint32_t getNextTx(); + uint32_t getJoinAttempts(); + void resetJoinAttempts(); osThreadId _main; @@ -44,6 +46,7 @@ class LoRaHandler { LoRaPing _ping; mDot* _dot; Mutex _mutex; + uint32_t _join_attempts; }; #endif diff --git a/Mode/ModeJoin.cpp b/Mode/ModeJoin.cpp index 5af4dcd..a39643f 100644 --- a/Mode/ModeJoin.cpp +++ b/Mode/ModeJoin.cpp @@ -17,42 +17,31 @@ ModeJoin::ModeJoin(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* ModeJoin::~ModeJoin() {} bool ModeJoin::start() { + bool joining = false; + // clear any stale signals osSignalClear(_main_id, buttonSignal | loraSignal); _joined = false; - _index = 1; - _join.display(); - _join.updateStatus("Joining..."); - if (_dot->getJoinMode() == mDot::MANUAL) { - _join.updateId(mts::Text::bin2hexString(_dot->getNetworkId())); - _join.updateKey(mts::Text::bin2hexString(_dot->getNetworkKey())); - } else { - _join.updateId(_dot->getNetworkName()); - _join.updateKey(_dot->getNetworkPassphrase()); - } - if (_band == mDot::FB_915) { - _sub_band = _dot->getFrequencySubBand(); - _join.updateFsb(_sub_band); - } - // mDot::DataRateStr returns format SF_XX - we only want to display the XX part - _join.updateRate(_dot->DataRateStr(_data_rate).substr(3)); - _join.updatePower(_power); + display(); _lora->setDataRate(_data_rate); _lora->setPower(_power); + _lora->resetJoinAttempts(); while (! _joined) { _next_tx = _lora->getNextTx(); if (_next_tx) { + logInfo("next tx %lu ms", _next_tx); _join.updateCountdown(_next_tx / 1000); - } else { - _join.updateStatus("Joining..."); - if (_lora->join()) - _join.updateAttempt(_index++); + } else if (! joining) { + logInfo("attempting to join"); + joining = true; + display(); + _lora->join(); } - osEvent e = Thread::signal_wait(0, 500); + osEvent e = Thread::signal_wait(0, 250); if (e.status == osEventSignal) { if (e.value.signals & buttonSignal) { _be = _buttons->getButtonEvent(); @@ -78,6 +67,7 @@ bool ModeJoin::start() { case LoRaHandler::join_failure: logInfo("failed to join"); + joining = false; break; } } @@ -86,3 +76,20 @@ bool ModeJoin::start() { return false; } + +void ModeJoin::display() { + _join.display(); + _join.updateStatus("Joining..."); + if (_dot->getJoinMode() == mDot::MANUAL) { + _join.updateId(mts::Text::bin2hexString(_dot->getNetworkId())); + _join.updateKey(mts::Text::bin2hexString(_dot->getNetworkKey())); + } else { + _join.updateId(_dot->getNetworkName()); + _join.updateKey(_dot->getNetworkPassphrase()); + } + // mDot::DataRateStr returns format SF_XX - we only want to display the XX part + _join.updateRate(_dot->DataRateStr(_data_rate).substr(3)); + _join.updatePower(_power); + _join.updateAttempt(_lora->getJoinAttempts()); +} + diff --git a/Mode/ModeJoin.h b/Mode/ModeJoin.h index 6669ad4..6ab6622 100644 --- a/Mode/ModeJoin.h +++ b/Mode/ModeJoin.h @@ -14,6 +14,8 @@ class ModeJoin : public Mode { bool start(); private: + void display(); + LayoutJoin _join; mDot* _dot; LoRaHandler* _lora; diff --git a/Mode/ModeSingle.cpp b/Mode/ModeSingle.cpp new file mode 100644 index 0000000..f49f120 --- /dev/null +++ b/Mode/ModeSingle.cpp @@ -0,0 +1,282 @@ +#include "ModeSingle.h" +#include "MTSLog.h" + +ModeSingle::ModeSingle(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora) + : Mode(lcd, buttons), + _help(lcd), + _file(lcd), + _confirm(lcd), + _progress(lcd), + _success(lcd), + _failure(lcd), + _dot(dot), + _data_rate(mDot::SF_7), + _power(2), + _lora(lora), + _send_data(false) +{} + +ModeSingle::~ModeSingle() {} + +bool ModeSingle::start() { + bool data_file = false; + bool send_ping = false; + bool send_data = false; + bool no_channel_ping = false; + bool no_channel_data = false; + LoRaHandler::LoRaPing ping_result; + + // clear any stale signals + osSignalClear(_main_id, buttonSignal | loraSignal); + + _band = _dot->getFrequencyBand(); + _sub_band = _dot->getFrequencySubBand(); + + // 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(); + + // 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 (it->name == _file_name) { + logInfo("found survey data file"); + data_file = true; + break; + } + } + if (data_file) { + _state = check_file; + _file.display(); + } else { + _state = show_help; + _index = 0; + displayHelp(); + } + + 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 = 0; // need to get index from NVM + displayHelp(); + break; + case confirm: + _state = check_file; + _file.display(); + break; + case show_help: + incrementRatePower(); + _help.updateMsg(formatNewRatePower()); + break; + case in_progress: + // do nothing + break; + case success: + incrementRatePower(); + _success.updateInfo(formatNewRatePower()); + break; + case data: + break; + case failure: + incrementRatePower(); + _failure.updateInfo(formatNewRatePower()); + break; + } + break; + + case ButtonHandler::sw2_press: + switch (_state) { + case check_file: + _state = confirm; + _confirm.display(); + break; + case confirm: + _state = show_help; + _dot->deleteUserFile(_file_name); + _index = 0; + displayHelp(); + break; + case show_help: + _state = in_progress; + _progress.display(); + if (_lora->getNextTx() > 0) + no_channel_ping = true; + else + send_ping = true; + break; + case in_progress: + // do nothing + break; + case success: + _state = in_progress; + _progress.display(); + if (_lora->getNextTx() > 0) + no_channel_ping = true; + else + send_ping = true; + break; + case data: + break; + case failure: + _state = in_progress; + _progress.display(); + 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: + _state = success; + ping_result = _lora->getPingResults(); + _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); + _success.updateInfo("No GPS Lock"); + _success.updateSw2("Survey"); + break; + case success: + break; + case data: + break; + case failure: + break; + } + break; + + case LoRaHandler::ping_failure: + switch (_state) { + case check_file: + break; + case confirm: + break; + case show_help: + break; + case in_progress: + _state = failure; + _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.updatePower(_power); + break; + case success: + break; + case data: + break; + case failure: + break; + } + break; + } + } + } + + if (no_channel_ping) { + uint32_t t = _lora->getNextTx(); + if (t > 0) { + logInfo("next tx %lu ms", t); + _progress.updateCountdown(t / 1000); + } else { + logInfo("ready to transmit"); + _progress.display(); + logInfo("countdown removed"); + no_channel_ping = false; + send_ping = true; + } + } + if (no_channel_data) { + } + if (send_ping) { + logInfo("sending ping"); + send_ping = false; + _lora->setDataRate(_data_rate); + _lora->setPower(_power); + _lora->ping(); + _index++; + } + if (send_data) { + } + } +} + +void ModeSingle::displayHelp() { + _help.display(); + _help.updateMode("Survey Single"); + _help.updateSw1(" DR/PWR"); + _help.updateSw2("Survey"); +} + +std::string ModeSingle::formatNewRatePower() { + std::string msg; + char buf[8]; + size_t size; + + memset(buf, 0, sizeof(buf)); + msg += "New DR="; + msg += _dot->DataRateStr(_data_rate).substr(3); + msg += " P="; + size = snprintf(buf, sizeof(buf), "%u", _power); + msg.append(buf, size); + + return msg; +} + +void ModeSingle::incrementRatePower() { + if (_power == 20) { + _power = 2; + switch (_data_rate) { + case mDot::SF_7: + _data_rate = mDot::SF_8; + break; + case mDot::SF_8: + _data_rate = mDot::SF_9; + break; + case mDot::SF_9: + _data_rate = mDot::SF_10; + break; + case mDot::SF_10: + if (_band == mDot::FB_915) + _data_rate = mDot::SF_7; + else + _data_rate = mDot::SF_11; + break; + case mDot::SF_11: + _data_rate = mDot::SF_12; + break; + case mDot::SF_12: + _data_rate = mDot::SF_7; + break; + } + } else { + _power += 3; + } +} + diff --git a/Mode/ModeSingle.h b/Mode/ModeSingle.h new file mode 100644 index 0000000..976c8eb --- /dev/null +++ b/Mode/ModeSingle.h @@ -0,0 +1,55 @@ +#ifndef __MODESINGLE_H__ +#define __MODESINGLE_H__ + +#include "Mode.h" +#include "mDot.h" +#include "LoRaHandler.h" +#include "LayoutHelp.h" +#include "LayoutFile.h" +#include "LayoutConfirm.h" +#include "LayoutSurveyProgress.h" +#include "LayoutSurveySuccess.h" +#include "LayoutSurveyFailure.h" + +class ModeSingle : public Mode { + public: + ModeSingle(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora); + ~ModeSingle(); + + bool start(); + + private: + void displayHelp(); + std::string formatNewRatePower(); + void incrementRatePower(); + + typedef enum { + check_file = 0, + confirm, + show_help, + in_progress, + success, + data, + failure + } state; + + LayoutHelp _help; + LayoutFile _file; + LayoutConfirm _confirm; + LayoutSurveyProgress _progress; + LayoutSurveySuccess _success; + LayoutSurveyFailure _failure; + mDot* _dot; + LoRaHandler* _lora; + uint8_t _band; + uint8_t _sub_band; + uint8_t _data_rate; + uint8_t _power; + uint32_t _next_tx; + ButtonHandler::ButtonEvent _be; + LoRaHandler::LoRaStatus _ls; + uint8_t _state; + bool _send_data; +}; + +#endif @@ -22,6 +22,7 @@ #include "LoRaHandler.h" // mode objects #include "ModeJoin.h" +#include "ModeSingle.h" // misc heders #include <string> @@ -45,6 +46,7 @@ mDot* dot; // Modes ModeJoin* modeJoin; +ModeSingle* modeSingle; // Serial debug port Serial debug(USBTX, USBRX); @@ -59,7 +61,7 @@ void surveySingle(); void surveySweep(); int main() { - debug.baud(115200); + debug.baud(460800); lcd = new DOGS102(lcd_spi, lcd_spi_cs, lcd_cd); lcd_backlight = new NCP5623B(backlight_i2c); @@ -69,14 +71,8 @@ int main() { dot = mDot::getInstance(); lora = new LoRaHandler(main_id); - modeJoin = new ModeJoin(lcd, buttons, dot, lora, dot->getFrequencyBand()); - - // display startup screen for 3 seconds - LayoutStartup ls(lcd); - ls.display(); - osDelay(3000); - // start of temporary stuff! + dot->setFrequencyBand(mDot::FB_868); if (dot->getFrequencyBand() == mDot::FB_915) dot->setFrequencySubBand(mDot::FSB_7); dot->setJoinMode(mDot::OTA); @@ -85,6 +81,14 @@ int main() { dot->setAck(1); // end of temporary stuff! + modeJoin = new ModeJoin(lcd, buttons, dot, lora, dot->getFrequencyBand()); + modeSingle = new ModeSingle(lcd, buttons, dot, lora); + + // display startup screen for 3 seconds + LayoutStartup ls(lcd); + ls.display(); + osDelay(3000); + //MTSLog::setLogLevel(MTSLog::TRACE_LEVEL); MTSLog::setLogLevel(MTSLog::INFO_LEVEL); logInfo("displaying main menu"); @@ -120,6 +124,8 @@ void mainMenu() { items.push_back(menu_strings[sweep]); while (true) { + // reset session between modes + dot->resetNetworkSession(); LayoutScrollSelect menu(lcd, items, menu_strings[0], menu_strings[1]); menu.display(); @@ -150,7 +156,7 @@ void mainMenu() { configuration(); } else if (selected == menu_strings[single]) { if (modeJoin->start()) - surveySingle(); + modeSingle->start(); } else if (selected == menu_strings[sweep]) { if (modeJoin->start()) surveySweep(); @@ -220,38 +226,6 @@ void loraDemo() { } } -void surveySingle() { - LayoutHelp lh(lcd); - lh.display(); - lh.updateMode("Survey Single"); - lh.updateSw1(" DR/PWR"); - lh.updateSw2("Survey"); - - // clear any stale signals - osSignalClear(main_id, buttonSignal | loraSignal); - - logInfo("survey single 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("datarate/power"); - break; - case ButtonHandler::sw2_press: - logInfo("start survey"); - break; - case ButtonHandler::sw1_hold: - return; - default: - break; - } - } - } -} - void surveySweep() { LayoutHelp lh(lcd); lh.display(); |