summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Layout/LayoutSemtech.cpp200
-rw-r--r--Layout/LayoutSemtech.h78
-rw-r--r--Layout/LayoutSemtechJoin.cpp91
-rw-r--r--Layout/LayoutSemtechJoin.h59
-rw-r--r--LoRaHandler/LoRaHandler.cpp11
-rw-r--r--Mode/ModeSemtech.cpp337
-rw-r--r--Mode/ModeSemtech.h76
-rw-r--r--main.cpp17
8 files changed, 864 insertions, 5 deletions
diff --git a/Layout/LayoutSemtech.cpp b/Layout/LayoutSemtech.cpp
new file mode 100644
index 0000000..e31d149
--- /dev/null
+++ b/Layout/LayoutSemtech.cpp
@@ -0,0 +1,200 @@
+/* Copyright (c) <2016> <MultiTech Systems>, MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute,
+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or
+ * substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+ * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "LayoutSemtech.h"
+
+
+LayoutSemtech::LayoutSemtech(DOGS102* lcd, uint8_t band)
+ : Layout(lcd),
+ _band(band),
+ _lDr(8,0,"DR"),
+ _lFSB(0,0,"FSB"),
+ _lSend(3,3,"Sending..."),
+ _lTemp(8,6,"Temp "),
+ _lNoGps(0,4,"No Gps Lock"),
+ _lPower(13,0,"P"),
+ _lBlank(0,1," "),
+ _lNoLink(0,1,"Send Failed"),
+ _lPadding(0,6,"Pad"),
+ _lNoChannel(0,3,"No Free Channel"),
+ _fDr(10,0,2),
+ _fSw1(13,7,4),
+ _fSw2(0,7,9),
+ _fFSB(3,0,1),
+ _fTemp(13,6,4),
+ _fPower(14,0,2),
+ _fNextCh(0,5,17),
+ _fGpsLat(0,3,17),
+ _fGpsLon(0,4,17),
+ _fResult(3,3,16),
+ _fGpsTime(0,5,16),
+ _fDownSnr(12,2,5),
+ _fPadding(4,6,3),
+ _fDownRssi(0,2,11)
+{}
+
+LayoutSemtech::~LayoutSemtech() {}
+
+void LayoutSemtech::display() {}
+
+void LayoutSemtech::initial()
+{
+ writeLabel(_lBlank);
+}
+
+void LayoutSemtech::display(bool success, mDot::snr_stats snr, mDot::rssi_stats rssi, int power, int fsb, int padding, int dr)
+{
+ char buf[17];
+ size_t size;
+
+ clear();
+ startUpdate();
+
+ writeLabel(_lDr);
+ writeLabel(_lTemp);
+ writeLabel(_lPower);
+ writeLabel(_lPadding);
+ if (_band == mDot::FB_915) {
+ writeLabel(_lFSB);
+ }
+ if(success) {
+ size = snprintf(buf, sizeof(buf), "DWN %3d dbm", rssi.last);
+ writeField(_fDownRssi, buf, size);
+
+ memset(buf, 0, sizeof(buf));
+ size = snprintf(buf, sizeof(buf), " %2.1f", (float)snr.last / 10.0);
+ writeField(_fDownSnr, buf, size);
+ } else writeLabel(_lNoLink);
+
+ memset(buf, 0, sizeof(buf));
+ size = snprintf(buf, sizeof(buf), "%d",dr);
+ writeField(_fDr, buf, size, true);
+
+ memset(buf, 0, sizeof(buf));
+ size = snprintf(buf, sizeof(buf), "%d",power);
+ writeField(_fPower, buf, size, true);
+
+ if (_band == mDot::FB_915) {
+ memset(buf, 0, sizeof(buf));
+ size = snprintf(buf, sizeof(buf), "%d",fsb);
+ writeField(_fFSB, buf, size, true);
+ }
+
+ memset(buf, 0, sizeof(buf));
+ size = snprintf(buf, sizeof(buf), "%d",padding);
+ writeField(_fPadding, buf, size, true);
+
+ endUpdate();
+}
+
+void LayoutSemtech::updateSw1(string Sw1, string Sw2, int dr, int power, int padding)
+{
+ size_t size;
+ char buf[17];
+ string temp;
+ for(int i = Sw1.size(); i<4; i++) temp+=" ";
+ temp+=Sw1;
+ writeField(_fSw1, temp, true);
+ startUpdate();
+ if(Sw2=="Data Rate") {
+ memset(buf, 0, sizeof(buf));
+ size = snprintf(buf, sizeof(buf), "%d",dr);
+ writeField(_fDr, buf, size, true);
+ } else if(Sw2=="Power") {
+ memset(buf, 0, sizeof(buf));
+ size = snprintf(buf, sizeof(buf), "%d",power);
+ writeField(_fPower, buf, size, true);
+ } else if(Sw2=="Padding") {
+ memset(buf, 0, sizeof(buf));
+ size = snprintf(buf, sizeof(buf), "%d",padding);
+ writeField(_fPadding, buf, size, true);
+ }
+ endUpdate();
+}
+
+void LayoutSemtech::updateSw2(string Sw2)
+{
+ writeField(_fSw2, Sw2, true);
+}
+
+void LayoutSemtech::sending()
+{
+ clear();
+ writeLabel(_lSend);
+}
+
+void LayoutSemtech::sendResult(string str)
+{
+ clear();
+ writeField(_fResult,str,true);
+}
+
+
+void LayoutSemtech::updateNextCh(int count_down)
+{
+ clear();
+ size_t size;
+ char buf[17];
+ size = snprintf(buf, sizeof(buf), "Countdown:%d",count_down);
+ writeField(_fNextCh, buf, size, true);
+ writeLabel(_lNoChannel);
+}
+
+void LayoutSemtech::updateStats(bool GPS, GPSPARSER::longitude lon, GPSPARSER::latitude lat, struct tm time, float temp)
+{
+ char buf[17];
+ size_t size;
+
+ startUpdate();
+
+ if(GPS) {
+ size = snprintf(buf, sizeof(buf), "%d %d %d.%03d %c",
+ abs(lon.degrees),
+ lon.minutes,
+ (lon.seconds * 6) / 1000,
+ (lon.seconds * 6) % 1000,
+ (lon.degrees > 0) ? 'E' : 'W');
+ writeField(_fGpsLon, buf, size, true);
+
+ memset(buf, 0, sizeof(buf));
+ size = snprintf(buf, sizeof(buf), "%d %d %d.%03d %c",
+ abs(lat.degrees),
+ lat.minutes,
+ (lat.seconds * 6) / 1000,
+ (lat.seconds * 6) % 1000,
+ (lat.degrees > 0) ? 'N' : 'S');
+ writeField(_fGpsLat, buf, size, true);
+
+ memset(buf, 0, sizeof(buf));
+ size = snprintf(buf, sizeof(buf), "%02d:%02d %02d/%02d/%04d",
+ time.tm_hour,
+ time.tm_min,
+ time.tm_mon + 1,
+ time.tm_mday,
+ time.tm_year + 1900);
+ writeField(_fGpsTime, buf, size, true);
+
+ } else writeLabel(_lNoGps);
+
+ memset(buf, 0, sizeof(buf));
+ size = snprintf(buf, sizeof(buf), "%.1f",temp);
+ writeField(_fTemp, buf, size, true);
+
+ endUpdate();
+}
+
diff --git a/Layout/LayoutSemtech.h b/Layout/LayoutSemtech.h
new file mode 100644
index 0000000..dd62fd6
--- /dev/null
+++ b/Layout/LayoutSemtech.h
@@ -0,0 +1,78 @@
+/* Copyright (c) <2016> <MultiTech Systems>, MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute,
+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or
+ * substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+ * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __LAYOUTSEMTECH_H__
+#define __LAYOUTSEMTECH_H__
+
+#include "Layout.h"
+#include "GPSPARSER.h"
+#include "LoRaHandler.h"
+
+class LayoutSemtech : public Layout
+{
+public:
+ LayoutSemtech(DOGS102* lcd, uint8_t band);
+ ~LayoutSemtech();
+
+ void display();
+ void display(bool success, mDot::snr_stats snr, mDot::rssi_stats rssi,int power, int fsb, int padding, int dr);
+
+ void sending();
+ void initial();
+ void updateSw2(string str);
+ void sendResult(string str);
+ void updateNextCh(int count_down);
+ void updateSw1(string Sw1, string Sw2, int dr, int power, int padding);
+ void updateStats(bool GPS, GPSPARSER::longitude lon, GPSPARSER::latitude lat, struct tm time, float temp);
+
+private:
+ uint8_t _band;
+
+ Label _lDr;
+ Label _lFSB;
+ Label _lSend;
+ Label _lTemp;
+ Label _lNoGps;
+ Label _lPower;
+ Label _lBlank;
+ Label _lNoLink;
+ Label _lPadding;
+ Label _lNoChannel;
+
+ Field _fDr;
+ Field _fSw1;
+ Field _fSw2;
+ Field _fFSB;
+ Field _fTemp;
+ Field _fPower;
+ Field _fNextCh;
+ Field _fGpsLat;
+ Field _fGpsLon;
+ Field _fResult;
+ Field _fGpsTime;
+ Field _fDownSnr;
+ Field _fPadding;
+ Field _fDownRssi;
+};
+
+#endif
+
+
+
+
+
diff --git a/Layout/LayoutSemtechJoin.cpp b/Layout/LayoutSemtechJoin.cpp
new file mode 100644
index 0000000..7bb7ac0
--- /dev/null
+++ b/Layout/LayoutSemtechJoin.cpp
@@ -0,0 +1,91 @@
+/* Copyright (c) <2016> <MultiTech Systems>, MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute,
+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or
+ * substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+ * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "LayoutSemtechJoin.h"
+
+LayoutSemtechJoin::LayoutSemtechJoin(DOGS102* lcd, uint8_t band)
+ : Layout(lcd),
+ _band(band),
+ _lId(0, 1, "NI="),
+ _lKey(0, 2, "NK="),
+ _lFsb(0, 3, "FSB="),
+ _lRate(0, 5, "DR="),
+ _lPower(6, 5, "P="),
+ _lJoin(0, 7, "Join"),
+ _fId(3, 1, 14),
+ _fKey(3, 2, 14),
+ _fFsb(4, 3, 2),
+ _fRate(3, 5, 2),
+ _fPower(8, 5, 2),
+ _fStatus(0, 0, 17),
+ _fSubBand(16,7,1)
+{}
+
+LayoutSemtechJoin::~LayoutSemtechJoin() {}
+
+void LayoutSemtechJoin::display()
+{
+ clear();
+ startUpdate();
+
+ writeLabel(_lId);
+ writeLabel(_lKey);
+ if (_band == mDot::FB_915) {
+ writeLabel(_lFsb);
+ }
+ writeLabel(_lRate);
+ writeLabel(_lPower);
+ writeLabel(_lJoin);
+
+ endUpdate();
+}
+
+void LayoutSemtechJoin::updateId(std::string id)
+{
+ writeField(_fId, id, true);
+}
+
+void LayoutSemtechJoin::updateKey(std::string key)
+{
+ writeField(_fKey, key, true);
+}
+
+void LayoutSemtechJoin::updateFsb(uint8_t band)
+{
+ if (_band == mDot::FB_915) {
+ char buf[8];
+ size_t size;
+ size = snprintf(buf, sizeof(buf), "%u", band);
+ writeField(_fFsb, buf, size, true);
+ writeField(_fSubBand, buf, size, true);
+ }
+}
+
+void LayoutSemtechJoin::updateRate(std::string rate)
+{
+ writeField(_fRate, rate, true);
+}
+
+void LayoutSemtechJoin::updatePower(uint32_t power)
+{
+ char buf[16];
+ size_t size;
+
+ size = snprintf(buf, sizeof(buf), "%lu", power);
+ writeField(_fPower, buf, size, true);
+}
diff --git a/Layout/LayoutSemtechJoin.h b/Layout/LayoutSemtechJoin.h
new file mode 100644
index 0000000..f848334
--- /dev/null
+++ b/Layout/LayoutSemtechJoin.h
@@ -0,0 +1,59 @@
+/* Copyright (c) <2016> <MultiTech Systems>, MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute,
+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or
+ * substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+ * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __LAYOUTSEMTECHJOIN_H__
+#define __LAYOUTSEMTECHJOIN_H__
+
+#include "Layout.h"
+#include "mDot.h"
+
+class LayoutSemtechJoin : public Layout {
+ public:
+ LayoutSemtechJoin(DOGS102* lcd, uint8_t band);
+ ~LayoutSemtechJoin();
+
+ void display();
+
+ void updateId(std::string id);
+ void updateKey(std::string key);
+ void updateFsb(uint8_t band);
+ void updateRate(std::string rate);
+ void updatePower(uint32_t power);
+
+ private:
+ uint8_t _band;
+
+ Label _lId;
+ Label _lKey;
+ Label _lFsb;
+ Label _lRate;
+ Label _lPower;
+ Label _lJoin;
+
+ Field _fId;
+ Field _fKey;
+ Field _fFsb;
+ Field _fRate;
+ Field _fPower;
+ Field _fStatus;
+ Field _fSubBand;
+};
+
+#endif
+
+
diff --git a/LoRaHandler/LoRaHandler.cpp b/LoRaHandler/LoRaHandler.cpp
index de9f0b1..d52ca54 100644
--- a/LoRaHandler/LoRaHandler.cpp
+++ b/LoRaHandler/LoRaHandler.cpp
@@ -87,12 +87,16 @@ void l_worker(void const* argument) {
l->_mutex.unlock();
if (ret == mDot::MDOT_OK) {
l->_status = LoRaHandler::join_success;
+ osSignalSet(l->_main, loraSignal);
+ l->_tick.detach();
+ l->_activity_led = LoRaHandler::green;
} else {
l->_status = LoRaHandler::join_failure;
+ osSignalSet(l->_main, loraSignal);
+ l->_tick.detach();
+ l->_activity_led = LoRaHandler::red;
}
- osSignalSet(l->_main, loraSignal);
- l->_tick.detach();
- l->_activity_led = LoRaHandler::green;
+
break;
default:
@@ -180,3 +184,4 @@ void LoRaHandler::resetActivityLed() {
_activity_led = red;
}
+
diff --git a/Mode/ModeSemtech.cpp b/Mode/ModeSemtech.cpp
new file mode 100644
index 0000000..9de48ad
--- /dev/null
+++ b/Mode/ModeSemtech.cpp
@@ -0,0 +1,337 @@
+/* Copyright (c) <2016> <MultiTech Systems>, MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute,
+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or
+ * substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+ * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "ModeSemtech.h"
+#include "MTSLog.h"
+#include "rtos.h"
+#include "mbed.h"
+#include <sstream>
+//this is exactly what it sounds like
+#define TWO_TO_THE_THIRTY_ONE_MINUS_ONE 2147483647
+#define PACKETSIZE 11
+
+
+
+
+ModeSemtech::ModeSemtech(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora, GPSPARSER* gps, SensorHandler* sensors)
+ : Mode(lcd, buttons, dot, lora, gps, sensors),
+ _help(lcd),
+ _sem(lcd,_band),
+ _sem_join(lcd,_band)
+{}
+
+string ModeSemtech::intToString(int num)
+{
+ return static_cast<ostringstream*>(&(ostringstream() << num))->str();
+}
+
+void ModeSemtech::init()
+{
+ //resets all parameters when re-entering mode
+ _interval = 5;
+ _padding = 0;
+ _power = 20;
+ _band = _dot->getFrequencyBand();
+ _parameter = POWER;
+ _drAll=false;
+ _link_check = false;
+ _GPS = false;
+ _sub_band = _dot->getFrequencySubBand();
+ _data_rate = mDot::DR4;
+ _max_padding = _dot->getMaxPacketLength()-PACKETSIZE;
+ _Sw2 = "Power";
+ _Sw1 = intToString(_power);
+ _help.display();
+ osDelay(2000);
+ if(_band==mDot::FB_868){
+ _sem.display(_link_check, _snr, _rssi, _power, _sub_band, _padding, _data_rate);
+ _sem.initial();
+ _state = PARAMETERS;
+ _send_timer.start();
+ }
+ else { _state = BAND_CHANGE;
+ changeBand();
+ }
+}
+
+void ModeSemtech::drIncrement()
+{
+ _data_rate++;
+ if (_data_rate > mDot::DR5) {
+ _drAll = true;
+ _data_rate=0;
+ }
+ _dot->setTxDataRate(_data_rate);
+ logInfo("new data rate %s, POWER %lu", mDot::DataRateStr(_data_rate).c_str(), _power);
+ _max_padding = _dot->getMaxPacketLength()-PACKETSIZE;
+}
+
+void ModeSemtech::changeDataRate()
+{
+ if(_drAll) {
+ if(_band == mDot::FB_868) _data_rate = -1;
+ else _data_rate = mDot::DR1;
+ _drAll = false;
+ }
+ drIncrement();
+}
+
+void ModeSemtech::changeParameter()
+{
+ _parameter++;
+ if(_band==mDot::FB_868&&_parameter==FSB)_parameter++;
+ if(_parameter>INTERVAL)_parameter=0;
+ switch(_parameter) {
+ case DATA_RATE:
+ _Sw2 = "Data Rate";
+ _Sw1 = intToString(_data_rate);
+ if(_drAll)_Sw1 = "All";
+ break;
+ case FSB:
+ _Sw2 = "FSB";
+ _Sw1 = intToString(_sub_band);
+ break;
+ case PADDING:
+ _Sw2 = "Padding";
+ _Sw1 = intToString(_padding);
+ break;
+ case POWER:
+ _Sw2 = "Power";
+ _Sw1 = intToString(_power);
+ break;
+ case INTERVAL:
+ _Sw2 = "Interval";
+ _Sw1 = intToString(_interval);
+ break;
+ default:
+ break;
+ }
+}
+
+void ModeSemtech::editParameter()
+{
+ switch(_parameter) {
+ case POWER:
+ if(_power<20)_power+=3;
+ else _power = 2;
+ _Sw1 = intToString(_power);
+ _dot->setTxPower(_power);
+ break;
+
+ case DATA_RATE:
+ changeDataRate();
+ _Sw1 = intToString(_data_rate);
+ if(_drAll)_Sw1="All";
+ break;
+
+ case FSB:
+ _send_timer.stop();
+ _send_timer.reset();
+ _state = BAND_CHANGE;
+ _dot->resetNetworkSession();
+ _lora->resetActivityLed();
+ changeBand();
+ break;
+
+ case PADDING:
+ if(_padding<_max_padding)_padding +=10 - (_padding%10);
+ else _padding = 0;
+ if(_padding>_max_padding)_padding = _max_padding;
+ _Sw1 = intToString(_padding);
+ break;
+
+ default:
+ if(_interval<60)_interval += 5;
+ else _interval = 5;
+ _Sw1 = intToString(_interval);
+ break;
+ }
+}
+
+void ModeSemtech::formatData()
+{
+ _send_data.clear();
+ uint32_t lat = 0;
+ uint32_t lng = 0;
+ _temp_C+=0.5;
+
+ if(_GPS) {
+ if(_latitude.degrees<0) lat = ~(int)((_latitude.degrees - ((double)_latitude.minutes/60.0) - ((double)_latitude.seconds/600000.0))*((double)-TWO_TO_THE_THIRTY_ONE_MINUS_ONE/90.0)+1.5);
+ else lat = (int)((_latitude.degrees + ((double)_latitude.minutes/60.0) + ((double)_latitude.seconds/600000.0))*((double)TWO_TO_THE_THIRTY_ONE_MINUS_ONE/90.0)+0.5);
+ if(_longitude.degrees<0) lng = ~(int)((_longitude.degrees - ((double)_longitude.minutes/60.0) - ((double)_longitude.seconds/600000.0))*((double)-TWO_TO_THE_THIRTY_ONE_MINUS_ONE/180.0)+1.5);
+ else lng = (int)((_longitude.degrees + ((double)_longitude.minutes/60.0) + ((double)_longitude.seconds/600000.0))*((double)TWO_TO_THE_THIRTY_ONE_MINUS_ONE/180.0)+0.5);
+ }
+ _send_data.push_back(0);
+ _send_data.push_back((int8_t) _temp_C);
+ _send_data.push_back(0);
+ for(int i=24; i>=0; i-=8)_send_data.push_back((lat>>i)&0xFF);
+ for(int i=24; i>=0; i-=8)_send_data.push_back((lng>>i)&0xFF);
+ for(int i=0; i<(_padding>_max_padding ? _max_padding : _padding); i++) _send_data.push_back(0);
+}
+
+void ModeSemtech::setBand()
+{
+ _sub_band++;
+ if(_sub_band > mDot::FSB_8) _sub_band = mDot::FSB_ALL;
+ _dot->setFrequencySubBand(_sub_band);
+}
+
+void ModeSemtech::changeBand()
+{
+ _sem_join.display();
+ _sem_join.updatePower(_power);
+ _sem_join.updateFsb(_sub_band);
+ _sem_join.updateId(_dot->getNetworkName());
+ _sem_join.updateRate(intToString(_data_rate));
+ _sem_join.updateKey(_dot->getNetworkPassphrase());
+}
+
+void ModeSemtech::updateScreen()
+{
+ _temp_C = _sensors->getTemp(SensorHandler::CELSIUS);
+ if(_gps->getLockStatus()&& _gps_available) {
+ _GPS = true;
+ _latitude = _gps->getLatitude();
+ _longitude = _gps->getLongitude();
+ _time = _gps->getTimestamp();
+ } else _GPS = false;
+ _sem.updateStats( _GPS, _longitude, _latitude, _time, _temp_C);
+ _sem.updateSw1(_Sw1,_Sw2,_data_rate,_power,_padding);
+ _sem.updateSw2(_Sw2);
+}
+
+void ModeSemtech::send()
+{
+ _state = SENDING;
+ _send_timer.stop();
+ if(_band==mDot::FB_868) {
+ while(_dot->getNextTxMs()>0) {
+ _sem.updateNextCh((int)(_dot->getNextTxMs()/1000));
+ osDelay(250);
+ }
+ }
+ formatData();
+ _sem.sending();
+ _send_timer.reset();
+ _send_timer.start();
+ _lora->send(_send_data);
+ osDelay(500);
+}
+
+bool ModeSemtech::start()
+{
+ init();
+ _button_timer.start();
+ ButtonHandler::ButtonEvent be;
+ osSignalClear(_main_id, buttonSignal | loraSignal);
+ if(_band==mDot::FB_915)_join = new ModeJoin(_lcd, _buttons, _dot, _lora, _gps, _sensors);
+
+ while (true) {
+ if(_state==PARAMETERS)updateScreen();
+
+ osEvent e = Thread::signal_wait(0, 250);
+ if (e.status == osEventSignal) {
+ if (e.value.signals & buttonSignal) {
+ _button_timer.reset();
+ be = _buttons->getButtonEvent();
+
+ switch(be) {
+ case ButtonHandler::sw1_press:
+ switch(_state) {
+ case BAND_CHANGE:
+ setBand();
+ changeBand();
+ break;
+
+ case SENDING:
+ break;
+
+ case PARAMETERS:
+ editParameter();
+ break;
+ }
+ break;
+ case ButtonHandler::sw2_press:
+ switch(_state) {
+ case BAND_CHANGE:
+ if(_join->start()){
+ _state = PARAMETERS;
+ _send_timer.start();
+ _sem.display(_link_check, _snr, _rssi, _power, _sub_band, _padding, DATA_RATE);
+ _dot->setTxDataRate(_data_rate);
+ } else changeBand();
+ break;
+
+ case SENDING:
+ break;
+
+ case PARAMETERS:
+ changeParameter();
+ break;
+ }
+ break;
+ case ButtonHandler::sw1_hold:
+ _send_timer.stop();
+ _send_timer.reset();
+ return true;
+
+ default:
+ break;
+ }
+
+ }
+ }
+ if (e.value.signals & loraSignal) {
+ _ls = _lora->getStatus();
+ switch (_ls) {
+
+ case LoRaHandler::send_success:
+ _sem.sendResult("Send Sucess!");
+ _link_check = true;
+ _snr = _dot->getSnrStats();
+ _rssi = _dot->getRssiStats();
+ osDelay(500);
+ _button_timer.reset();
+ _state = PARAMETERS;
+ _sem.display(_link_check, _snr, _rssi, _power, _sub_band, _padding, _data_rate);
+ if(_drAll)drIncrement();
+ break;
+
+ case LoRaHandler::send_failure:
+ _sem.sendResult("Send Failed.");
+ _link_check = false;
+ osDelay(500);
+ _button_timer.reset();
+ _state = PARAMETERS;
+ _sem.display(_link_check, _snr, _rssi, _power, _sub_band, _padding, _data_rate);
+ if(_drAll)drIncrement();
+ break;
+
+ default:
+ break;
+ }
+
+ }
+
+ if(_send_timer.read_ms()>_interval*1000&&_button_timer.read_ms()>3000) send();
+
+ }
+}
+
+
+
diff --git a/Mode/ModeSemtech.h b/Mode/ModeSemtech.h
new file mode 100644
index 0000000..4812ec4
--- /dev/null
+++ b/Mode/ModeSemtech.h
@@ -0,0 +1,76 @@
+/* Copyright (c) <2016> <MultiTech Systems>, MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute,
+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or
+ * substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+ * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __MODESEMTECH_H__
+#define __MODESEMTECH_H__
+
+#include "Mode.h"
+#include "ModeJoin.h"
+#include "LayoutHelp.h"
+#include "LayoutSemtech.h"
+#include "LayoutSemtechJoin.h"
+
+class ModeSemtech : public Mode
+{
+public:
+ ModeSemtech(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora, GPSPARSER* gps, SensorHandler* sensors);
+ ~ModeSemtech();
+
+ bool start();
+
+private:
+ enum {DATA_RATE, FSB, PADDING, POWER, INTERVAL};
+ enum {BAND_CHANGE, SENDING, PARAMETERS};
+
+ LayoutHelp _help;
+ LayoutSemtech _sem;
+ LayoutSemtechJoin _sem_join;
+
+ ModeJoin* _join;
+
+ Timer _send_timer, _button_timer;
+
+ float _temp_C;
+ std::vector<uint8_t> _send_data;
+ uint8_t _parameter, _padding, _interval,_max_padding, _band;
+ bool _drAll, _link_check, _GPS;
+ string _Sw1, _Sw2;
+
+ struct tm _time;
+ mDot::snr_stats _snr;
+ mDot::rssi_stats _rssi;
+ GPSPARSER::latitude _latitude;
+ GPSPARSER::longitude _longitude;
+
+ void init();
+ void send();
+ void setBand();
+ void sendData();
+ void formatData();
+ void changeBand();
+ void drIncrement();
+ void updateScreen();
+ void editParameter();
+ void changeDataRate();
+ void changeParameter();
+ string intToString(int num);
+
+};
+
+#endif
+
diff --git a/main.cpp b/main.cpp
index 464b00a..4810095 100644
--- a/main.cpp
+++ b/main.cpp
@@ -41,6 +41,7 @@
#include "ModeSweep.h"
#include "ModeDemo.h"
#include "ModeConfig.h"
+#include "ModeSemtech.h"
// misc heders
#include "FileName.h"
#include <string>
@@ -79,6 +80,7 @@ ModeSingle* modeSingle;
ModeSweep* modeSweep;
ModeDemo* modeDemo;
ModeConfig* modeConfig;
+ModeSemtech* modeSemtech;
// Serial debug port
Serial debug(USBTX, USBRX);
@@ -114,11 +116,13 @@ int main() {
MTSLog::setLogLevel(MTSLog::TRACE_LEVEL);
+
modeJoin = new ModeJoin(lcd, buttons, dot, loraHandler, gps, sensors);
modeSingle = new ModeSingle(lcd, buttons, dot, loraHandler, gps, sensors);
modeSweep = new ModeSweep(lcd, buttons, dot, loraHandler, gps, sensors);
modeDemo = new ModeDemo(lcd, buttons, dot, loraHandler, gps, sensors);
modeConfig = new ModeConfig(lcd, buttons, dot, loraHandler, gps, sensors);
+ modeSemtech = new ModeSemtech(lcd, buttons, dot, loraHandler, gps, sensors);
osDelay(1000);
logInfo("%sGPS detected", gps->gpsDetected() ? "" : "no ");
@@ -144,7 +148,8 @@ void mainMenu() {
demo = 1,
config,
single,
- sweep
+ sweep,
+ semtech
} menu_items;
std::string menu_strings[] = {
@@ -152,7 +157,8 @@ void mainMenu() {
"LoRa Demo",
"Configuration",
"Survey Single",
- "Survey Sweep"
+ "Survey Sweep",
+ "Semtech"
};
std::vector<std::string> items;
@@ -160,6 +166,7 @@ void mainMenu() {
items.push_back(menu_strings[config]);
items.push_back(menu_strings[single]);
items.push_back(menu_strings[sweep]);
+ items.push_back(menu_strings[semtech]);
while (true) {
product = "MTDOT-BOX/EVB ";
@@ -203,8 +210,14 @@ void mainMenu() {
if (modeJoin->start())
modeSweep->start();
}
+ else if (selected == menu_strings[semtech]) {
+ if(dot->getFrequencyBand()==mDot::FB_868)modeJoin->start();
+ modeSemtech->start();
+ }
mode_selected = false;
}
}
+
+