diff options
-rw-r--r-- | CommandTerminal/CmdFrequencyBand.cpp | 27 | ||||
-rw-r--r-- | CommandTerminal/CmdTxDataRate.cpp | 19 | ||||
-rw-r--r-- | Layout/LayoutData.cpp | 104 | ||||
-rw-r--r-- | Layout/LayoutData.h | 77 | ||||
-rw-r--r-- | Layout/LayoutJoin.cpp | 38 | ||||
-rw-r--r-- | Layout/LayoutJoin.h | 5 | ||||
-rw-r--r-- | Layout/LayoutSurveyGps.cpp | 166 | ||||
-rw-r--r-- | Layout/LayoutSurveyGps.h | 65 | ||||
-rw-r--r-- | Mode/Mode.cpp | 2 | ||||
-rw-r--r-- | Mode/ModeData.cpp | 187 | ||||
-rw-r--r-- | Mode/ModeData.h | 58 | ||||
-rw-r--r-- | Mode/ModeGps.cpp | 356 | ||||
-rw-r--r-- | Mode/ModeGps.h | 77 | ||||
-rw-r--r-- | Mode/ModeJoin.cpp | 3 | ||||
-rw-r--r-- | Mode/ModeSemtech.cpp | 12 | ||||
-rw-r--r-- | Mode/ModeSingle.cpp | 4 | ||||
-rw-r--r-- | main.cpp | 54 | ||||
m--------- | mdot-library | 0 |
18 files changed, 1204 insertions, 50 deletions
diff --git a/CommandTerminal/CmdFrequencyBand.cpp b/CommandTerminal/CmdFrequencyBand.cpp index 26b7831..c3116c9 100644 --- a/CommandTerminal/CmdFrequencyBand.cpp +++ b/CommandTerminal/CmdFrequencyBand.cpp @@ -19,10 +19,10 @@ #include "CmdFrequencyBand.h" CmdFrequencyBand::CmdFrequencyBand(mDot* dot, mts::MTSSerial& serial) : - Command(dot, "Frequency Band", "AT+FREQ", "Configured Frequency Band '868' or '915'"), _serial(serial) + Command(dot, "Frequency Band", "AT+FREQ", "Configured Frequency Band 'EU868', 'AU915' or 'US915'"), _serial(serial) { _help = std::string(text()) + ": " + std::string(desc()); - _usage = "(868,915)"; + _usage = "(EU868,AU915,US915)"; _queryable = true; } @@ -40,12 +40,24 @@ uint32_t CmdFrequencyBand::action(std::vector<std::string> args) else if (args.size() == 2) { int32_t code; + + std::string text = mts::Text::toUpper(args[1]); + uint8_t band = mDot::FB_US915; - if (mDot::FrequencyBandStr(mDot::FB_EU868).find(args[1]) != std::string::npos) { + + if (mDot::FrequencyBandStr(mDot::FB_EU868).find(text) != std::string::npos) { band = mDot::FB_EU868; } + if (mDot::FrequencyBandStr(mDot::FB_AU915).find(text) != std::string::npos) { + band = mDot::FB_AU915; + } + + if (mDot::FrequencyBandStr(mDot::FB_US915).find(text) != std::string::npos) { + band = mDot::FB_US915; + } + if ((code = _dot->setFrequencyBand(band)) != mDot::MDOT_OK) { std::string error = mDot::getReturnCodeString(code) + " - " + _dot->getLastError(); setErrorMessage(error); @@ -65,10 +77,13 @@ bool CmdFrequencyBand::verify(std::vector<std::string> args) #ifdef DEBUG_MAC if (args.size() == 2) { - if (mDot::FrequencyBandStr(mDot::FB_EU868).find(args[1]) == std::string::npos && - mDot::FrequencyBandStr(mDot::FB_US915).find(args[1]) == std::string::npos) + std::string band = mts::Text::toUpper(args[1]); + + if (mDot::FrequencyBandStr(mDot::FB_EU868).find(band) == std::string::npos && + mDot::FrequencyBandStr(mDot::FB_US915).find(band) == std::string::npos && + mDot::FrequencyBandStr(mDot::FB_AU915).find(band) == std::string::npos) { - setErrorMessage("Invalid parameter, expects (868,915)"); + setErrorMessage("Invalid parameter, expects (EU868,AU915,US915)"); return false; } diff --git a/CommandTerminal/CmdTxDataRate.cpp b/CommandTerminal/CmdTxDataRate.cpp index 004ee8e..fefbd69 100644 --- a/CommandTerminal/CmdTxDataRate.cpp +++ b/CommandTerminal/CmdTxDataRate.cpp @@ -26,10 +26,11 @@ CmdTxDataRate::CmdTxDataRate(mDot* dot, mts::MTSSerial& serial) { _help = std::string(text()) + ": " + std::string(desc()); - if (_dot->getFrequencyBand() == mDot::FB_915) - _usage = "(7-10|DR0-DR4|DR8-DR13)"; - else + if (_dot->getFrequencyBand() == mDot::FB_EU868) _usage = "(7-12|DR0-DR7)"; + else + _usage = "(7-10|DR0-DR4|DR8-DR13)"; + _queryable = true; } @@ -58,7 +59,7 @@ uint32_t CmdTxDataRate::action(std::vector<std::string> args) { } else { if (datarate > 6) { // Convert SF to DR - if (_dot->getFrequencyBand() == mDot::FB_915) { + if (_dot->getFrequencyBand() == mDot::FB_US915 || _dot->getFrequencyBand() == mDot::FB_AU915 ) { datarate = 10 - datarate; } else { datarate = 12 - datarate; @@ -96,7 +97,7 @@ bool CmdTxDataRate::verify(std::vector<std::string> args) { if (_dr > 15) { _dr = 12 + (mDot::SF_12 - _dr); - if (_dot->getFrequencyBand() == mDot::FB_868) { + if (_dot->getFrequencyBand() == mDot::FB_EU868) { if (_dr == mDot::SF_7H) { _dr = mDot::DR6; } else if (_dr == mDot::SF_FSK) { @@ -115,13 +116,13 @@ bool CmdTxDataRate::verify(std::vector<std::string> args) { } } } else { - if (_dot->getFrequencyBand() == mDot::FB_915 && datarate > 10) { + if ((_dot->getFrequencyBand() == mDot::FB_US915 || _dot->getFrequencyBand() == mDot::FB_AU915) && datarate > 10) { datarate = -1; - } else if (_dot->getFrequencyBand() == mDot::FB_868 && datarate > 12) { + } else if (_dot->getFrequencyBand() == mDot::FB_EU868 && datarate > 12) { datarate = -1; } else if (datarate > 6) { // Convert SF to DR - if (_dot->getFrequencyBand() == mDot::FB_915) { + if (_dot->getFrequencyBand() == mDot::FB_US915 || _dot->getFrequencyBand() == mDot::FB_AU915 ) { datarate = 10 - datarate; } else { datarate = 12 - datarate; @@ -129,7 +130,7 @@ bool CmdTxDataRate::verify(std::vector<std::string> args) { } } - if (_dot->getFrequencyBand() == mDot::FB_915) { + if (_dot->getFrequencyBand() == mDot::FB_US915 || _dot->getFrequencyBand() == mDot::FB_AU915 ) { // DR8-13 used for P2P modes if (datarate < 0 || datarate > 13 || (datarate >= 5 && datarate <= 7)) { setErrorMessage("Invalid data rate, expects (7-10|DR0-DR4|DR8-DR13)"); diff --git a/Layout/LayoutData.cpp b/Layout/LayoutData.cpp new file mode 100644 index 0000000..02e29fd --- /dev/null +++ b/Layout/LayoutData.cpp @@ -0,0 +1,104 @@ +/* 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 "LayoutData.h" + +LayoutData::LayoutData(DOGS102* lcd) + : Layout(lcd), + _lDr(8, 0, "DR"), + _lPwr(13, 0, "P"), + _lUp(0, 1, "UP Mgn"), + _lGw(10, 1, "Gw"), + _lDown(0, 2, "DWN -"), + _lSurveyFailed(0, 1, "Survey Failed"), + _lDbm(9, 2, "dbm"), + _lAlt(0, 6, "Alt"), + _fId(0, 0, 5), + _fDr(10, 0, 2), + _fPwr(14, 0, 2), + _fUpMargin(7, 1, 2), + _fGw(13, 1, 2), + _fRssiDown(5, 2, 3), + _fSnrDown(13, 2, 4), + _fGpsLat(0, 4, 17), + _fGpsLong(0, 3, 17), + _fGpsTime(0, 5, 17), + _fAlt(4,6,13), + _fSw1(12, 7, 4), + _fSw2(0, 7, 4) +{} + +LayoutData::~LayoutData() {} + +void LayoutData::display(){ + clear(); + startUpdate(); + writeLabel(_lDr); + writeLabel(_lPwr); + endUpdate(); +} + +void LayoutData::noData(){ + clear(); + writeField(_fGpsLong, string(" No Survey Data"), true); +} + +void LayoutData::errorData(){ + clear(); + writeField(_fGpsLong, string(" Error opening,"), true); + writeField(_fGpsLat, string("survey data file."), true); +} + +void LayoutData::updateSw1(string str){ + writeField(_fSw1, str, true); +} + +void LayoutData::updateSw2(string str){ + writeField(_fSw2, str, true); +} + +bool LayoutData::updateAll(singleLine& line){ + clear(); + startUpdate(); + //this data should always exist + writeLabel(_lDr); + writeLabel(_lPwr); + writeField(_fId, line.id, true); + writeField(_fDr, line.dataRate, true); + writeField(_fPwr, line.power, true); + //check if survey pass/fail + if(line.status=="S") { + writeLabel(_lUp); + writeLabel(_lDown); + writeLabel(_lGw); + writeLabel(_lDbm); + writeField(_fGw, line.gateways, true); + writeField(_fUpMargin, line.margin, true); + writeField(_fRssiDown, line.rssiD, true); + writeField(_fSnrDown, line.snrD, true); + } else writeLabel(_lSurveyFailed); + //check if gps data exists + if(line.lock!="0") { + writeLabel(_lAlt); + writeField(_fGpsLat, line.lat, true); + writeField(_fGpsLong, line.lng, true); + writeField(_fGpsTime, line.time, true); + writeField(_fAlt, line.alt + " m", true); + } else writeField(_fGpsLong, string("No GPS Data"), true); + endUpdate(); +} diff --git a/Layout/LayoutData.h b/Layout/LayoutData.h new file mode 100644 index 0000000..ec91583 --- /dev/null +++ b/Layout/LayoutData.h @@ -0,0 +1,77 @@ +/* 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 __LAYOUTDATA_H__ +#define __LAYOUTDATA_H__ + +#include "Layout.h" + +class LayoutData : public Layout{ +public: + LayoutData(DOGS102* lcd); + ~LayoutData(); + + struct singleLine { + string id, + status, + lock, + lat, + lng, + alt, + time, + gateways, + margin, + rssiD, + snrD, + dataRate, + power; + } ; + + void display(); + void noData(); + void noGps(); + void errorData(); + void updateSw1(string str); + void updateSw2(string str); + bool updateAll(singleLine& line); + +private: + Label _lDr; + Label _lPwr; + Label _lUp; + Label _lGw; + Label _lDown; + Label _lDbm; + Label _lSurveyFailed; + Label _lAlt; + + Field _fId; + Field _fDr; + Field _fPwr; + Field _fUpMargin; + Field _fRssiDown; + Field _fSnrDown; + Field _fGpsLat; + Field _fGpsLong; + Field _fGpsTime; + Field _fGw; + Field _fAlt; + Field _fSw1; + Field _fSw2; +}; +#endif diff --git a/Layout/LayoutJoin.cpp b/Layout/LayoutJoin.cpp index e115773..a0ec1ee 100644 --- a/Layout/LayoutJoin.cpp +++ b/Layout/LayoutJoin.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) <2016> <MultiTech Systems>, MIT License +/* /* 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, @@ -75,8 +75,12 @@ void LayoutJoin::updateFsb(uint8_t band) { writeField(_fFsb, buf, size, true); } -void LayoutJoin::updateRate(std::string rate) { - writeField(_fRate, rate, true); +void LayoutJoin::updateRate(uint8_t rate) { + char buf[8]; + size_t size; + + size = snprintf(buf, sizeof(buf), "%u", rate); + writeField(_fRate, buf, size, true); } void LayoutJoin::updatePower(uint32_t power) { @@ -119,3 +123,31 @@ void LayoutJoin::displayCancel(bool display) { writeField(_fCancel, str, true); } +void LayoutJoin::updateJoinFsb(uint8_t band) { + char buf[8]; + size_t size; + + size = snprintf(buf, sizeof(buf), "%u", band); + writeField(_fFsb, buf, size, true); + size = snprintf(buf, sizeof(buf), " %u", band); + writeField(_fCancel, buf, size, true); +} + +void LayoutJoin::displayEditFsb(uint8_t rate, uint32_t power, uint8_t band, string key, string id){ + clear(); + startUpdate(); + + writeLabel(_lId); + writeLabel(_lKey); + writeLabel(_lFsb); + writeLabel(_lRate); + writeLabel(_lPower); + writeField(_fCountdown, string("Join"), true); + updateId(id); + updateKey(key); + updateJoinFsb(band); + updateRate(rate); + updatePower(power); + + endUpdate(); +} diff --git a/Layout/LayoutJoin.h b/Layout/LayoutJoin.h index 56cea3f..c493ce2 100644 --- a/Layout/LayoutJoin.h +++ b/Layout/LayoutJoin.h @@ -28,11 +28,13 @@ class LayoutJoin : public Layout { ~LayoutJoin(); void display(); + void displayEditFsb(uint8_t rate, uint32_t power, uint8_t band, string key, string id); void updateId(std::string id); void updateKey(std::string key); void updateFsb(uint8_t band); - void updateRate(std::string rate); + void updateJoinFsb(uint8_t band); + void updateRate(uint8_t rate); void updatePower(uint32_t power); void updateAttempt(uint32_t attempt); void updateStatus(std::string status); @@ -59,5 +61,4 @@ class LayoutJoin : public Layout { Field _fCancel; uint8_t _band; }; - #endif diff --git a/Layout/LayoutSurveyGps.cpp b/Layout/LayoutSurveyGps.cpp new file mode 100644 index 0000000..2630566 --- /dev/null +++ b/Layout/LayoutSurveyGps.cpp @@ -0,0 +1,166 @@ +/* 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 "LayoutSurveyGps.h" +LayoutSurveyGps::LayoutSurveyGps(DOGS102* lcd, uint8_t band) + : Layout(lcd), + _band(band), + _lDR(8,0,"DR"), + _lFSB(0,0,"FSB"), + _lTemp(8,6,"Temp "), + _lPower(13,0,"P"), + _lPadding(0,6,"Pad"), + _fDr(10,0,2), + _fSw1(13,7,4), + _fSw2(0,7,9), + _fFSB(3,0,1), + _fTemp(13,6,4), + _fPower(14,0,2), + _fNoLink(0,1,17), + _fGpsLat(0,3,17), + _fGpsLon(0,4,17), + _fGpsTime(0,5,17), + _fDownSnr(12,2,5), + _fPadding(4,6,3), + _fDownRssi(0,2,12) +{} + +LayoutSurveyGps::~LayoutSurveyGps() {} + +void LayoutSurveyGps::display() {} + +void LayoutSurveyGps::initial(){ + writeField(_fNoLink, string(" "), true); +} + +void LayoutSurveyGps::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", snr.last / 10.0); + writeField(_fDownSnr, buf, size); + } else { + writeField(_fNoLink,string("Send Failed"),true); + } + + 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 LayoutSurveyGps::updateSw1(string Sw1, string Sw2){ + string temp; + for(int i = Sw1.size(); i<4; i++){ + temp+=" "; + } + temp+=Sw1; + writeField(_fSw1, temp, true); +} + +void LayoutSurveyGps::updateSw2(string Sw2){ + writeField(_fSw2, Sw2, true); +} + +void LayoutSurveyGps::sending(){ + clear(); + writeField(_fGpsLat,string(" Sending..."),true); +} + +void LayoutSurveyGps::sendResult(string str){ + clear(); + writeField(_fGpsLat,str,true); +} + +void LayoutSurveyGps::updateNextCh(int count_down){ + clear(); + size_t size; + char buf[17]; + size = snprintf(buf, sizeof(buf), "Countdown:%d", count_down); + writeField(_fGpsTime, buf, size, true); + writeField(_fGpsLon, string("No Free Channel"), true); +} + +void LayoutSurveyGps::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 { + writeField(_fGpsLon, string("No Gps Lock"), true); + } + memset(buf, 0, sizeof(buf)); + size = snprintf(buf, sizeof(buf), "%.1f", temp); + writeField(_fTemp, buf, size, true); + endUpdate(); +} diff --git a/Layout/LayoutSurveyGps.h b/Layout/LayoutSurveyGps.h new file mode 100644 index 0000000..9e3194f --- /dev/null +++ b/Layout/LayoutSurveyGps.h @@ -0,0 +1,65 @@ +/* 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 __LAYOUTSURVEYGPS_H__ +#define __LAYOUTSURVEYGPS_H__ + +#include "Layout.h" +#include "GPSPARSER.h" +#include "mDot.h" + +class LayoutSurveyGps : public Layout{ +public: + LayoutSurveyGps(DOGS102* lcd, uint8_t band); + ~LayoutSurveyGps(); + + 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); + void updateStats(bool GPS, GPSPARSER::longitude lon, GPSPARSER::latitude lat, struct tm time, float temp); + +private: + uint8_t _band; + + Label _lDR; + Label _lFSB; + Label _lTemp; + Label _lPower; + Label _lPadding; + + Field _fDr; + Field _fSw1; + Field _fSw2; + Field _fFSB; + Field _fTemp; + Field _fPower; + Field _fNoLink; + Field _fGpsLat; + Field _fGpsLon; + Field _fGpsTime; + Field _fDownSnr; + Field _fPadding; + Field _fDownRssi; +}; +#endif diff --git a/Mode/Mode.cpp b/Mode/Mode.cpp index bed78ec..462e145 100644 --- a/Mode/Mode.cpp +++ b/Mode/Mode.cpp @@ -279,7 +279,7 @@ std::vector<uint8_t> Mode::formatSurveyData(DataItem& data) { send_data.push_back((data.link.down.snr/10) & 0xFF); // collect GPS data if GPS device detected - if (_gps->gpsDetected() && ((_data_rate != mDot::SF_10) || (_band == mDot::FB_868))){ + if (_gps->gpsDetected() && ((_data_rate != mDot::SF_10) || (_band == mDot::FB_EU868))){ send_data.push_back(0x19); // key for GPS Lock Status satfix = (_gps->getNumSatellites() << 4 ) | (_gps->getFixStatus() & 0x0F ); send_data.push_back(satfix); diff --git a/Mode/ModeData.cpp b/Mode/ModeData.cpp new file mode 100644 index 0000000..401277e --- /dev/null +++ b/Mode/ModeData.cpp @@ -0,0 +1,187 @@ +/* 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 "ModeData.h" +#include "MTSText.h" +#define ONELINEMAX 93 + +ModeData::ModeData(DOGS102* lcd, ButtonHandler* _buttons, mDot* _dot, LoRaHandler* lora, GPSPARSER* gps, SensorHandler* sensors) + :Mode(lcd,_buttons,_dot,lora,gps,sensors), + _data(lcd), + _help(lcd), + _buf_size(ONELINEMAX) +{} + +ModeData::~ModeData() {} + +bool ModeData::checkFile(){ + bool exists = false; + //get all files and see if file exists + vector<mDot::mdot_file> files = _dot->listUserFiles(); + for (vector<mDot::mdot_file>::iterator it = files.begin(); it != files.end(); it++) { + if (strcmp(file_name,it->name)==0) { + exists = true; + break; + } + } + //if file doesnt exist exit to main menu + if(!exists) { + _data.noData(); + osDelay(3000); + return true; + } + _file = _dot->openUserFile(file_name, mDot::FM_RDONLY); + //if nothing is in file exit to main menu + if (_file.fd < 0) { + _data.errorData(); + osDelay(3000); + _dot->closeUserFile(_file); + return true; + } + return false; +} + +bool ModeData::start(){ + if(checkFile()) + return true; + _help.display(); + osDelay(3000); + readFile(); +} + +void ModeData::displayData(){ + std::vector<std::string> data = mts::Text::split(_str, ','); + _line.id = data.at(0); + _line.status = data.at(1); + _line.lock = data.at(2); + _line.lat = data.at(3); + _line.lng = data.at(4); + _line.alt = data.at(5); + _line.time = data.at(6); + _line.gateways = data.at(7); + _line.margin = data.at(8); + _line.rssiD = data.at(9); + _line.snrD = data.at(10); + _line.dataRate = data.at(11); + _line.power = data.at(12); + _data.updateAll(_line); +} + +//get the current line out of the buffer into str +void ModeData::getLine(){ + _prev = 0; + _indexUpdate = 0; + _str = ""; + _dot->readUserFile(_file, (void*)_buf, _buf_size); + //only gets called when going back + if(_last) { + //-3 puts it back to one before new line + _indexUpdate = _buf_size - 3; + //check from back of buffer for new line + while(_buf[_indexUpdate] != '\n' && _indexUpdate >= 0){ + _indexUpdate--; + } + _indexUpdate++; + } + //go from indexUpdate to new line to ge the line + //prev keeps track of how long line read was + while(_buf[_indexUpdate]!='\n') { + _str += _buf[_indexUpdate]; + _indexUpdate++; + _prev++; + } + //push index past newline + _index += _indexUpdate + 1; + displayData(); +} + +void ModeData::back(){ + if(_index >= (_buf_size + _prev)) { + _index -= (_prev + _buf_size); + } else { + //special case for beginning of file + if(_index > 0){ + _buf_size = _index-1; + } + _buf_size -= _prev; + _index = 0; + } + _last = true; + _dot->seekUserFile(_file, _index, SEEK_SET); + getLine(); +} + +void ModeData::forward(){ + _last = false; + if(_index < _file.size) { + _buf_size = ONELINEMAX; + _dot->seekUserFile(_file, _index, SEEK_SET); + getLine(); + } +} + +//update switch labels +void ModeData::configSw(){ + if(_index - (_prev+1) <= 0){ + _data.updateSw2(""); + } else { + _data.updateSw2("Back"); + } + if(_index<_file.size){ + _data.updateSw1("Next"); + } else { + _data.updateSw1(""); + } +} + +bool ModeData::readFile(){ + _index = 0; + _last = false; + _prev = 0; + _indexUpdate = 0; + //called to start on page one + forward(); + configSw(); + ButtonHandler::ButtonEvent be; + while (true) { + be = _buttons->getButtonEvent(); + switch(be) { + case ButtonHandler::sw1_press: + if(_index!=_file.size) { + forward(); + configSw(); + } + break; + + case ButtonHandler::sw2_press: + if(_index - (_prev+1) > 0) { + back(); + configSw(); + } + break; + + case ButtonHandler::sw1_hold: + _dot->closeUserFile(_file); + return true; + + default: + break; + } + } +} + diff --git a/Mode/ModeData.h b/Mode/ModeData.h new file mode 100644 index 0000000..f9da741 --- /dev/null +++ b/Mode/ModeData.h @@ -0,0 +1,58 @@ +/* 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 __MODEDATA_H__ +#define __MODEDATA_H__ + +#include "Mode.h" +#include "LayoutData.h" +#include "LayoutHelp.h" + +class ModeData : public Mode{ + +public: + ModeData(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora, GPSPARSER* gps, SensorHandler* sensors); + ~ModeData(); + + bool start(); + +private: + bool _last; + string _str; + + int32_t _pos, _buf_size, _indexUpdate, _prev; + uint32_t _index; + + char _buf[93]; + + mDot::mdot_file _file; + + LayoutData _data; + LayoutHelp _help; + LayoutData::singleLine _line; + + bool checkFile(); + bool readFile(); + string parse(); + void getLine(); + void displayData(); + void forward(); + void back(); + void configSw(); +}; +#endif
\ No newline at end of file diff --git a/Mode/ModeGps.cpp b/Mode/ModeGps.cpp new file mode 100644 index 0000000..47053cb --- /dev/null +++ b/Mode/ModeGps.cpp @@ -0,0 +1,356 @@ +/* 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 "ModeGps.h" +#include "MTSLog.h" +#include "rtos.h" +#include "mbed.h" +#include "limits.h" +#define PACKETSIZE 11 + +ModeGps::ModeGps(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora, GPSPARSER* gps, SensorHandler* sensors, ModeJoin* join) + : Mode(lcd, buttons, dot, lora, gps, sensors), + _help(lcd), + _sem(lcd, _band), + _sem_join(lcd, _band), + _join(join) +{} + +string ModeGps::intToString(int num){ + char buf[3]; + snprintf(buf, sizeof(buf), "%d", num); + return buf; +} + +void ModeGps::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::DR0; + _max_padding = _dot->getMaxPacketLength() - PACKETSIZE; + _Sw2 = "Power"; + _Sw1 = intToString(_power); + _help.display(); + osDelay(2000); + + if(_band == mDot::FB_EU868){ + _sem.display(_link_check, _snr, _rssi, _power, _sub_band, _padding, _data_rate); + _sem.initial(); + _state = PARAMETERS; + _send_timer.start(); + } else { _state = BAND_CHANGE; + _sem_join.displayEditFsb(_data_rate, _power, _sub_band, _dot->getNetworkName(), _dot->getNetworkPassphrase()); + } +} + +void ModeGps::drIncrement(){ + _data_rate++; + if (_data_rate > mDot::DR3 && _band == mDot::FB_915 || _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 ModeGps::changeDataRate(){ + if(_drAll) { + _data_rate = -1; + _drAll = false; + } + drIncrement(); +} + +void ModeGps::changeParameter(){ + _parameter++; + if(_band == mDot::FB_EU868 && _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 ModeGps::editParameter(){ + switch(_parameter) { + case POWER: + if(_power<20){ + _power+=3; + } else { + _power = 2; + } + _Sw1 = intToString(_power); + _dot->setTxPower(_power); + break; + + case DATA_RATE: + changeDataRate(); + if(_drAll) { + _Sw1="All"; + } else { + _Sw1 = intToString(_data_rate); + } + break; + + case FSB: + _send_timer.stop(); + _send_timer.reset(); + _state = BAND_CHANGE; + _dot->resetNetworkSession(); + _lora->resetActivityLed(); + _sem_join.displayEditFsb(mDot::DR0, 20, _sub_band, _dot->getNetworkName(), _dot->getNetworkPassphrase()); + 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 ModeGps::formatData(){ + _send_data.clear(); + uint32_t lat = 0; + uint32_t lng = 0; + double degrees = 0; + double minutes = 0; + double seconds = 0; + _temp_C += 0.5; + + if(_GPS) { + degrees = _latitude.degrees; + minutes = _latitude.minutes; + seconds = _latitude.seconds; + if(degrees<0) { + lat = ~(int)((degrees - minutes/60.0 - seconds/600000.0)*(-INT_MAX/90.0 + 1.5)); + } else { + lat = (int)((degrees + minutes/60.0 + seconds/600000.0)*(INT_MAX/90.0 + 0.5)); + } + degrees = _longitude.degrees; + minutes = _longitude.minutes; + seconds = _longitude.seconds; + if(degrees<0) { + lng = ~(int)((degrees - minutes/60.0 - seconds/600000.0)*(-INT_MAX/180.0 + 1.5)); + } else { + lng = (int)((degrees + minutes/60.0 + seconds/600000.0)*(INT_MAX/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 ModeGps::setBand(){ + _sub_band++; + if(_sub_band > mDot::FSB_8) _sub_band = mDot::FSB_ALL; + _dot->setFrequencySubBand(_sub_band); +} + +void ModeGps::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); + _sem.updateSw2(_Sw2); +} + +void ModeGps::send(){ + _state = SENDING; + _send_timer.stop(); + if(_band == mDot::FB_EU868) { + 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 ModeGps::start(){ + init(); + _button_timer.start(); + ButtonHandler::ButtonEvent be; + osSignalClear(_main_id, buttonSignal | loraSignal); + 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(); + _sem_join.updateJoinFsb(_sub_band); + break; + + case PARAMETERS: + editParameter(); + break; + + default: + 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); + _sem.initial(); + _dot->setTxDataRate(_data_rate); + } else _sem_join.displayEditFsb(mDot::DR0, 20, _sub_band, _dot->getNetworkName(), _dot->getNetworkPassphrase()); + break; + + case PARAMETERS: + changeParameter(); + break; + + default: + 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!"); + osDelay(500); + _link_check = true; + _snr = _dot->getSnrStats(); + _rssi = _dot->getRssiStats(); + _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."); + osDelay(500); + _link_check = false; + _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/ModeGps.h b/Mode/ModeGps.h new file mode 100644 index 0000000..39b64ff --- /dev/null +++ b/Mode/ModeGps.h @@ -0,0 +1,77 @@ +/* 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 __MODEGPS_H__ +#define __MODEGPS_H__ + +#include "Mode.h" +#include "ModeJoin.h" +#include "LayoutHelp.h" +#include "LayoutSurveyGps.h" + +class ModeGps : public Mode{ +public: + ModeGps(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora, GPSPARSER* gps, SensorHandler* sensors, ModeJoin* join); + ~ModeGps(); + bool start(); + +private: + enum {DATA_RATE, + FSB, + PADDING, + POWER, + INTERVAL + }; + enum {BAND_CHANGE, + SENDING, + PARAMETERS + }; + + LayoutHelp _help; + LayoutSurveyGps _sem; + LayoutJoin _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; + 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 drIncrement(); + void updateScreen(); + void editParameter(); + void changeDataRate(); + void changeParameter(); + string intToString(int num); +}; +#endif
\ No newline at end of file diff --git a/Mode/ModeJoin.cpp b/Mode/ModeJoin.cpp index 4bdc6cd..3a86dd9 100644 --- a/Mode/ModeJoin.cpp +++ b/Mode/ModeJoin.cpp @@ -123,8 +123,7 @@ void ModeJoin::display() { _sub_band = _dot->getFrequencySubBand(); _join.updateFsb(_sub_band); } - _join.updateRate(_dot->DataRateStr(_data_rate).substr(2)); + _join.updateRate(_dot->getTxDataRate()); _join.updatePower(_power); _join.updateAttempt(_lora->getJoinAttempts()); } - diff --git a/Mode/ModeSemtech.cpp b/Mode/ModeSemtech.cpp index 9de48ad..5c2d180 100644 --- a/Mode/ModeSemtech.cpp +++ b/Mode/ModeSemtech.cpp @@ -58,7 +58,7 @@ void ModeSemtech::init() _Sw1 = intToString(_power); _help.display(); osDelay(2000); - if(_band==mDot::FB_868){ + if(_band==mDot::FB_EU868){ _sem.display(_link_check, _snr, _rssi, _power, _sub_band, _padding, _data_rate); _sem.initial(); _state = PARAMETERS; @@ -84,7 +84,7 @@ void ModeSemtech::drIncrement() void ModeSemtech::changeDataRate() { if(_drAll) { - if(_band == mDot::FB_868) _data_rate = -1; + if(_band == mDot::FB_EU868) _data_rate = -1; else _data_rate = mDot::DR1; _drAll = false; } @@ -94,7 +94,7 @@ void ModeSemtech::changeDataRate() void ModeSemtech::changeParameter() { _parameter++; - if(_band==mDot::FB_868&&_parameter==FSB)_parameter++; + if(_band==mDot::FB_EU868&&_parameter==FSB)_parameter++; if(_parameter>INTERVAL)_parameter=0; switch(_parameter) { case DATA_RATE: @@ -219,7 +219,7 @@ void ModeSemtech::send() { _state = SENDING; _send_timer.stop(); - if(_band==mDot::FB_868) { + if(_band==mDot::FB_EU868) { while(_dot->getNextTxMs()>0) { _sem.updateNextCh((int)(_dot->getNextTxMs()/1000)); osDelay(250); @@ -239,7 +239,9 @@ bool ModeSemtech::start() _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); + + if(_band == mDot::FB_US915 || _band == mDot::FB_AU915) + _join = new ModeJoin(_lcd, _buttons, _dot, _lora, _gps, _sensors); while (true) { if(_state==PARAMETERS)updateScreen(); diff --git a/Mode/ModeSingle.cpp b/Mode/ModeSingle.cpp index 982d8b9..6cc3f4b 100644 --- a/Mode/ModeSingle.cpp +++ b/Mode/ModeSingle.cpp @@ -324,7 +324,9 @@ void ModeSingle::incrementRatePower() { if (_power == 20) { _power = 2; _data_rate++; - if (_band == mDot::FB_915 && _data_rate > mDot::DR4 || _band == mDot::FB_868 && _data_rate > mDot::DR7) { + if ((_band == mDot::FB_US915 && _data_rate > mDot::DR4) || + (_band == mDot::FB_AU915 && _data_rate > mDot::DR4) || + (_band == mDot::FB_EU868 && _data_rate > mDot::DR7)) { _data_rate = mDot::DR0; } } else { @@ -41,7 +41,8 @@ #include "ModeSweep.h" #include "ModeDemo.h" #include "ModeConfig.h" -#include "ModeSemtech.h" +#include "ModeGps.h" +#include "ModeData.h" // misc heders #include "FileName.h" #include <string> @@ -64,7 +65,8 @@ osThreadId main_id; ButtonHandler* buttons; // LoRa controller -LoRaHandler* loraHandler; +LoRaHandler* lora_handler; + mDot* dot; // GPS @@ -80,7 +82,8 @@ ModeSingle* modeSingle; ModeSweep* modeSweep; ModeDemo* modeDemo; ModeConfig* modeConfig; -ModeSemtech* modeSemtech; +ModeGps* modeGps; +ModeData* modeData; // Serial debug port Serial debug(USBTX, USBRX); @@ -102,13 +105,15 @@ int main() { main_id = Thread::gettid(); buttons = new ButtonHandler(main_id); dot = mDot::getInstance(); + lora_handler = new LoRaHandler(main_id); dot->setDisableDutyCycle(DISABLE_DUTY_CYCLE); + dot->setLinkCheckThreshold(0); + dot->setLinkCheckCount(0); // Seed the RNG srand(dot->getRadioRandom()); - loraHandler = new LoRaHandler(main_id); gps = new GPSPARSER(&gps_serial, led_cont); sensors = new SensorHandler(); @@ -116,13 +121,14 @@ int main() { MTSLog::setLogLevel(MTSLog::TRACE_LEVEL); + modeJoin = new ModeJoin(lcd, buttons, dot, lora_handler, gps, sensors); + modeSingle = new ModeSingle(lcd, buttons, dot, lora_handler, gps, sensors); + modeSweep = new ModeSweep(lcd, buttons, dot, lora_handler, gps, sensors); + modeDemo = new ModeDemo(lcd, buttons, dot, lora_handler, gps, sensors); + modeConfig = new ModeConfig(lcd, buttons, dot, lora_handler, gps, sensors); + modeGps = new ModeGps(lcd, buttons, dot, lora_handler, gps, sensors, modeJoin); + modeData = new ModeData(lcd, buttons, dot, lora_handler, gps, sensors); - 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 "); @@ -149,7 +155,9 @@ void mainMenu() { config, single, sweep, - semtech + gps, + data + } menu_items; std::string menu_strings[] = { @@ -158,15 +166,16 @@ void mainMenu() { "Configuration", "Survey Single", "Survey Sweep", - "Semtech" + "Survey GPS", + "View Data" }; - std::vector<std::string> items; items.push_back(menu_strings[demo]); items.push_back(menu_strings[config]); items.push_back(menu_strings[single]); items.push_back(menu_strings[sweep]); - items.push_back(menu_strings[semtech]); + items.push_back(menu_strings[gps]); + items.push_back(menu_strings[data]); while (true) { product = "MTDOT-BOX/EVB "; @@ -174,7 +183,8 @@ void mainMenu() { // reset session between modes dot->resetNetworkSession(); - loraHandler->resetActivityLed(); + lora_handler->resetActivityLed(); + LayoutScrollSelect menu(lcd, items, product, menu_strings[0]); menu.display(); @@ -197,7 +207,6 @@ void mainMenu() { } } } - if (selected == menu_strings[demo]) { if (modeJoin->start()) modeDemo->start(); @@ -209,11 +218,14 @@ void mainMenu() { } else if (selected == menu_strings[sweep]) { if (modeJoin->start()) modeSweep->start(); - } - else if (selected == menu_strings[semtech]) { - if(dot->getFrequencyBand()==mDot::FB_868)modeJoin->start(); - modeSemtech->start(); - } + } else if (selected == menu_strings[gps]) { + if(dot->getFrequencyBand() == mDot::FB_EU868) { + modeJoin->start(); + } + modeGps->start(); + } else if (selected == menu_strings[data]) { + modeData->start(); + } mode_selected = false; } diff --git a/mdot-library b/mdot-library -Subproject aefe95ecaeb883397106170e9f99cea5035c189 +Subproject f3b5de8c7106bfd15ce9dc33bbe3f189319178d |