summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Fiore <mfiore@multitech.com>2015-11-30 15:50:22 -0600
committerMike Fiore <mfiore@multitech.com>2015-11-30 15:50:22 -0600
commit37260f2ccff2793f54bfd291169d2c8d879bbc15 (patch)
treeb908d697eb6f2d1ba2c305eacc3c7c7bb6203122
parent30b4f15aa70d24ec0a6b6bb1b3f5039c4921cb02 (diff)
downloadmtdot-box-evb-factory-firmware-37260f2ccff2793f54bfd291169d2c8d879bbc15.tar.gz
mtdot-box-evb-factory-firmware-37260f2ccff2793f54bfd291169d2c8d879bbc15.tar.bz2
mtdot-box-evb-factory-firmware-37260f2ccff2793f54bfd291169d2c8d879bbc15.zip
start work on survey sweep - currently determines rates and power levels to use and prints them out
-rw-r--r--Layout/LayoutSweepComplete.cpp55
-rw-r--r--Layout/LayoutSweepComplete.h29
-rw-r--r--Layout/LayoutSweepProgress.cpp53
-rw-r--r--Layout/LayoutSweepProgress.h28
-rw-r--r--Mode/ModeSweep.cpp395
-rw-r--r--Mode/ModeSweep.h60
-rw-r--r--main.cpp37
7 files changed, 624 insertions, 33 deletions
diff --git a/Layout/LayoutSweepComplete.cpp b/Layout/LayoutSweepComplete.cpp
new file mode 100644
index 0000000..ab44b7b
--- /dev/null
+++ b/Layout/LayoutSweepComplete.cpp
@@ -0,0 +1,55 @@
+#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"),
+ _lSw1(11, 7, "Cancel"),
+ _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(_lSw1);
+ 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..82cf008
--- /dev/null
+++ b/Layout/LayoutSweepComplete.h
@@ -0,0 +1,29 @@
+#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 _lSw1;
+ Label _lSw2;
+
+ Field _fId;
+ Field _fPass;
+ Field _fFail;
+};
+
+#endif
diff --git a/Layout/LayoutSweepProgress.cpp b/Layout/LayoutSweepProgress.cpp
new file mode 100644
index 0000000..9ec77cc
--- /dev/null
+++ b/Layout/LayoutSweepProgress.cpp
@@ -0,0 +1,53 @@
+#include "LayoutSweepProgress.h"
+
+LayoutSweepProgress::LayoutSweepProgress(DOGS102* lcd)
+ : Layout(lcd),
+ _lSlash(8, 1, "/"),
+ _lMsg1(5, 2, "Sweep"),
+ _lMsg2(7, 3, "in"),
+ _lMsg3(4, 4, "Progress"),
+ _fComplete(6, 1, 2),
+ _fTotal(9, 1, 2),
+ _fCountdownLabel(0, 6, 17),
+ _fCountdown(0, 7, 9)
+{}
+
+LayoutSweepProgress::~LayoutSweepProgress() {}
+
+void LayoutSweepProgress::display() {
+ clear();
+ startUpdate();
+
+ writeLabel(_lSlash);
+ 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), "%2u", complete);
+ writeField(_fComplete, buf, size, true);
+
+ memset(buf, 0, sizeof(buf));
+ size = snprintf(buf, sizeof(buf), "%u", total);
+ writeField(_fTotal, 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..82c8081
--- /dev/null
+++ b/Layout/LayoutSweepProgress.h
@@ -0,0 +1,28 @@
+#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 _lSlash;
+ Label _lMsg1;
+ Label _lMsg2;
+ Label _lMsg3;
+
+ Field _fComplete;
+ Field _fTotal;
+ Field _fCountdownLabel;
+ Field _fCountdown;
+};
+
+#endif
diff --git a/Mode/ModeSweep.cpp b/Mode/ModeSweep.cpp
new file mode 100644
index 0000000..9b51a52
--- /dev/null
+++ b/Mode/ModeSweep.cpp
@@ -0,0 +1,395 @@
+#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
+ _survey_current = 1;
+ _points = generatePoints();
+ _survey_total = _points.size();
+ _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);
+
+ return true;
+
+ // 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 = 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 = getIndex(sweep);
+ displayHelp();
+ break;
+ case confirm:
+ _state = check_file;
+ _file.display();
+ break;
+ case show_help:
+ break;
+ case in_progress:
+ // do nothing
+ break;
+ case success:
+ break;
+ case data:
+ break;
+ case failure:
+ 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 = 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;
+ case complete:
+ 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:
+ _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");
+ _success.updateSw2("Survey");
+ }
+ 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:
+ _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));
+ updateData(_data, single, false);
+ appendDataFile(_data);
+ _failure.updatePower(_power);
+ logInfo("ping failed");
+ 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");
+ _success.updateSw2("Survey");
+ logInfo("data send success");
+ 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");
+ _success.updateSw2("Survey");
+ logInfo("data send failed");
+ break;
+ case failure:
+ break;
+ case complete:
+ 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 {
+ _progress.display();
+ 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) {
+ logInfo("sending ping %s %d", _dot->DataRateStr(_data_rate).c_str(), _power);
+ send_ping = false;
+ _lora->setDataRate(_data_rate);
+ _lora->setPower(_power);
+ _lora->ping();
+ _index++;
+ }
+ if (send_data) {
+ std::vector<uint8_t> s_data;
+ logInfo("sending data %s %d", _dot->DataRateStr(_data_rate).c_str(), _power);
+ _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.updateInfo("No GPS Lock");
+}
+
+std::vector<point> ModeSweep::generatePoints() {
+ std::vector<point> p;
+ uint8_t min_rate;
+ uint8_t max_rate;
+
+ min_rate = payloadToRate(_min_payload);
+ max_rate = payloadToRate(_max_payload);
+
+ for (uint8_t rate = max_rate; rate >= min_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_11])
+ return mDot::SF_11;
+ else if (payload <= mDot::MaxLengths_868[mDot::SF_10])
+ return mDot::SF_10;
+ else if (payload <= mDot::MaxLengths_868[mDot::SF_9])
+ return mDot::SF_9;
+ else if (payload <= mDot::MaxLengths_868[mDot::SF_8])
+ return mDot::SF_8;
+ 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
diff --git a/main.cpp b/main.cpp
index c63f922..47fbda3 100644
--- a/main.cpp
+++ b/main.cpp
@@ -23,6 +23,7 @@
// mode objects
#include "ModeJoin.h"
#include "ModeSingle.h"
+#include "ModeSweep.h"
#include "ModeConfig.h"
// misc heders
#include <string>
@@ -48,6 +49,7 @@ mDot* dot;
// Modes
ModeJoin* modeJoin;
ModeSingle* modeSingle;
+ModeSweep* modeSweep;
ModeConfig* modeConfig;
// Serial debug port
@@ -73,6 +75,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
@@ -149,7 +152,7 @@ void mainMenu() {
modeSingle->start();
} else if (selected == menu_strings[sweep]) {
if (modeJoin->start())
- surveySweep();
+ modeSweep->start();
}
mode_selected = false;
@@ -189,35 +192,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;
- }
- }
- }
-}
-