summaryrefslogtreecommitdiff
path: root/Mode
diff options
context:
space:
mode:
authorMike Fiore <mfiore@multitech.com>2015-11-18 15:10:35 -0600
committerMike Fiore <mfiore@multitech.com>2015-11-18 15:10:35 -0600
commit94990163d2b694373eb5b2b8ccc4d002aad4ecd9 (patch)
tree15a37d6c14b0742b5aa3c2555448bb2b392d7e2c /Mode
parenta17ec37a0c96a7d204c52ab4f24b11852cdb7f66 (diff)
downloadmtdot-box-evb-factory-firmware-94990163d2b694373eb5b2b8ccc4d002aad4ecd9.tar.gz
mtdot-box-evb-factory-firmware-94990163d2b694373eb5b2b8ccc4d002aad4ecd9.tar.bz2
mtdot-box-evb-factory-firmware-94990163d2b694373eb5b2b8ccc4d002aad4ecd9.zip
create Mode base class for modes - implement join as a mode and update main accordingly
Diffstat (limited to 'Mode')
-rw-r--r--Mode/Mode.cpp19
-rw-r--r--Mode/Mode.h47
-rw-r--r--Mode/ModeJoin.cpp86
-rw-r--r--Mode/ModeJoin.h30
4 files changed, 182 insertions, 0 deletions
diff --git a/Mode/Mode.cpp b/Mode/Mode.cpp
new file mode 100644
index 0000000..eea6d3c
--- /dev/null
+++ b/Mode/Mode.cpp
@@ -0,0 +1,19 @@
+#include "Mode.h"
+
+Mode::Mode(DOGS102* lcd, ButtonHandler* buttons)
+ : _lcd(lcd),
+ _buttons(buttons),
+ _index(0),
+ _main_id(Thread::gettid())
+{}
+
+Mode::~Mode() {}
+
+bool Mode::deleteDataFile() {
+ return true;
+}
+
+bool Mode::appendDataFile(const DataItem& data) {
+ return true;
+}
+
diff --git a/Mode/Mode.h b/Mode/Mode.h
new file mode 100644
index 0000000..1254a9e
--- /dev/null
+++ b/Mode/Mode.h
@@ -0,0 +1,47 @@
+#ifndef __MODE_H__
+#define __MODE_H__
+
+#include "DOGS102.h"
+#include "ButtonHandler.h"
+#include "GPSPARSER.h"
+
+class Mode {
+ public:
+ typedef enum {
+ single = 0,
+ sweep
+ } DataType;
+
+ typedef struct {
+ DataType type;
+ int32_t index;
+ bool status;
+ int32_t lock;
+ GPSPARSER::longitude gps_longitude;
+ GPSPARSER::latitude gps_latitude;
+ int16_t gps_altitude;
+ struct tm gps_time;
+ int16_t rssi_up;
+ int16_t snr_up;
+ int16_t rssi_down;
+ int16_t snr_down;
+ uint8_t data_rate;
+ uint8_t power;
+ } DataItem;
+
+ Mode(DOGS102* lcd, ButtonHandler* buttons);
+ ~Mode();
+
+ virtual bool start() = 0;
+
+ protected:
+ bool deleteDataFile();
+ bool appendDataFile(const DataItem& data);
+
+ DOGS102* _lcd;
+ ButtonHandler* _buttons;
+ uint32_t _index;
+ osThreadId _main_id;
+};
+
+#endif
diff --git a/Mode/ModeJoin.cpp b/Mode/ModeJoin.cpp
new file mode 100644
index 0000000..f1f0e9a
--- /dev/null
+++ b/Mode/ModeJoin.cpp
@@ -0,0 +1,86 @@
+#include "ModeJoin.h"
+#include "MTSLog.h"
+#include "MTSText.h"
+
+ModeJoin::ModeJoin(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora, uint8_t band)
+ : Mode(lcd, buttons),
+ _lj(lcd, band),
+ _dot(dot),
+ _lora(lora),
+ _band(band),
+ _data_rate(band == mDot::FB_915 ? mDot::SF_10 : mDot::SF_12),
+ _power(20),
+ _next_tx(0),
+ _joined(false)
+{}
+
+ModeJoin::~ModeJoin() {}
+
+bool ModeJoin::start() {
+ // clear any stale signals
+ osSignalClear(_main_id, buttonSignal | loraSignal);
+
+ _lj.display();
+ _lj.updateStatus("Joining...");
+ if (_dot->getJoinMode() == mDot::MANUAL) {
+ _lj.updateId(mts::Text::bin2hexString(_dot->getNetworkId()));
+ _lj.updateKey(mts::Text::bin2hexString(_dot->getNetworkKey()));
+ } else {
+ _lj.updateId(_dot->getNetworkName());
+ _lj.updateKey(_dot->getNetworkPassphrase());
+ }
+ if (_band == mDot::FB_915) {
+ _sub_band = _dot->getFrequencySubBand();
+ _lj.updateFsb(_sub_band);
+ }
+ // mDot::DataRateStr returns format SF_XX - we only want to display the XX part
+ _lj.updateRate(_dot->DataRateStr(_data_rate).substr(3));
+ _lj.updatePower(_power);
+
+ _lora->setDataRate(_data_rate);
+ _lora->setPower(_power);
+
+ while (! _joined) {
+ _next_tx = _lora->getNextTx();
+ if (_next_tx) {
+ _lj.updateCountdown(_next_tx * 1000);
+ } else {
+ _lj.updateAttempt(++_index);
+ _lj.updateStatus("Joining...");
+ _lora->join();
+ }
+
+ osEvent e = Thread::signal_wait(0);
+ if (e.status == osEventSignal) {
+ if (e.value.signals & buttonSignal) {
+ _be = _buttons->getButtonEvent();
+ switch (_be) {
+ case ButtonHandler::sw1_press:
+ return false;
+ case ButtonHandler::sw2_press:
+ break;
+ case ButtonHandler::sw1_hold:
+ return false;
+ }
+ }
+ if (e.value.signals & loraSignal) {
+ _ls = _lora->getStatus();
+ switch (_ls) {
+ case LoRaHandler::join_success:
+ _lj.updateStatus("Join Success!");
+ _lj.displayCancel(false);
+ logInfo("joined");
+ _joined = true;
+ osDelay(2000);
+ return true;
+
+ case LoRaHandler::join_failure:
+ logInfo("failed to join");
+ break;
+ }
+ }
+ }
+ }
+
+ return false;
+}
diff --git a/Mode/ModeJoin.h b/Mode/ModeJoin.h
new file mode 100644
index 0000000..5b88e25
--- /dev/null
+++ b/Mode/ModeJoin.h
@@ -0,0 +1,30 @@
+#ifndef __MODEJOIN_H__
+#define __MODEJOIN_H__
+
+#include "Mode.h"
+#include "LayoutJoin.h"
+#include "mDot.h"
+#include "LoRaHandler.h"
+
+class ModeJoin : public Mode {
+ public:
+ ModeJoin(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora, uint8_t band);
+ ~ModeJoin();
+
+ bool start();
+
+ private:
+ LayoutJoin _lj;
+ mDot* _dot;
+ LoRaHandler* _lora;
+ uint8_t _band;
+ uint8_t _sub_band;
+ uint8_t _data_rate;
+ uint8_t _power;
+ uint32_t _next_tx;
+ bool _joined;
+ ButtonHandler::ButtonEvent _be;
+ LoRaHandler::LoRaStatus _ls;
+};
+
+#endif