summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Layout/LayoutData.cpp104
-rw-r--r--Layout/LayoutData.h77
-rw-r--r--Mode/ModeData.cpp187
-rw-r--r--Mode/ModeData.h58
-rw-r--r--main.cpp15
5 files changed, 438 insertions, 3 deletions
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/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/main.cpp b/main.cpp
index 9166354..3a35c8f 100644
--- a/main.cpp
+++ b/main.cpp
@@ -41,6 +41,7 @@
#include "ModeSweep.h"
#include "ModeDemo.h"
#include "ModeConfig.h"
+#include "ModeData.h"
// misc heders
#include "FileName.h"
#include <string>
@@ -76,6 +77,7 @@ ModeSingle* modeSingle;
ModeSweep* modeSweep;
ModeDemo* modeDemo;
ModeConfig* modeConfig;
+ModeData* modeData;
// Serial debug port
Serial debug(USBTX, USBRX);
@@ -111,6 +113,7 @@ int main() {
modeSweep = new ModeSweep(lcd, buttons, dot, lora, gps, sensors);
modeDemo = new ModeDemo(lcd, buttons, dot, lora, gps, sensors);
modeConfig = new ModeConfig(lcd, buttons, dot, lora, gps, sensors);
+ modeData = new ModeData(lcd, buttons, dot, lora, gps, sensors);
osDelay(1000);
logInfo("%sGPS detected", gps->gpsDetected() ? "" : "no ");
@@ -136,7 +139,8 @@ void mainMenu() {
demo = 1,
config,
single,
- sweep
+ sweep,
+ data
} menu_items;
std::string menu_strings[] = {
@@ -144,7 +148,8 @@ void mainMenu() {
"LoRa Demo",
"Configuration",
"Survey Single",
- "Survey Sweep"
+ "Survey Sweep",
+ "Survey Data"
};
std::vector<std::string> items;
@@ -152,6 +157,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[data]);
while (true) {
product = "MTDOT-BOX/EVB ";
@@ -194,9 +200,12 @@ void mainMenu() {
} else if (selected == menu_strings[sweep]) {
if (modeJoin->start())
modeSweep->start();
- }
+ }else if (selected == menu_strings[data]) {
+ modeData->start();
+ }
mode_selected = false;
}
}
+