From 8396a893b56d9dfd41203aec501f057b6456be57 Mon Sep 17 00:00:00 2001 From: Ryan Klaassen Date: Mon, 8 Aug 2016 12:49:28 -0500 Subject: Upload new file --- Layout/LayoutData.h | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 Layout/LayoutData.h diff --git a/Layout/LayoutData.h b/Layout/LayoutData.h new file mode 100644 index 0000000..78c74dd --- /dev/null +++ b/Layout/LayoutData.h @@ -0,0 +1,90 @@ +/* Copyright (c) <2016> , 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 _lNoData; + Label _lSurveyFailed; + Label _lErrorData1; + Label _lErrorData2; + Label _lNoGps; + 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 + + + + -- cgit v1.2.3 From 298b3da1c5ed0c807936069bc1b2a067bb0c4394 Mon Sep 17 00:00:00 2001 From: Ryan Klaassen Date: Mon, 8 Aug 2016 12:49:41 -0500 Subject: Upload new file --- Layout/LayoutData.cpp | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 Layout/LayoutData.cpp diff --git a/Layout/LayoutData.cpp b/Layout/LayoutData.cpp new file mode 100644 index 0000000..7cfb2ac --- /dev/null +++ b/Layout/LayoutData.cpp @@ -0,0 +1,120 @@ +/* Copyright (c) <2016> , 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 -"), + _lNoData(1,3,"No Survey Data"), + _lErrorData1(1,3,"Error opening,"), + _lErrorData2(0,4,"survey data file."), + _lSurveyFailed(0,1,"Survey Failed"), + _lNoGps(0,3,"No GPS Data"), + _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(); + writeLabel(_lNoData); +} + +void LayoutData::errorData() +{ + clear(); + writeLabel(_lErrorData1); + writeLabel(_lErrorData2); +} + +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.gateways!="") { + 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.lat!="") { + writeLabel(_lAlt); + writeField(_fGpsLat,line.lat,true); + writeField(_fGpsLong,line.lng,true); + writeField(_fGpsTime,line.time,true); + writeField(_fAlt,line.alt + " m",true); + } else writeLabel(_lNoGps); + + endUpdate(); +} + + + + -- cgit v1.2.3 From b43d86da0f46cd00ba846684170fde50f168ec4c Mon Sep 17 00:00:00 2001 From: Ryan Klaassen Date: Mon, 8 Aug 2016 12:50:07 -0500 Subject: Upload new file --- ModeData.cpp | 187 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 187 insertions(+) create mode 100644 ModeData.cpp diff --git a/ModeData.cpp b/ModeData.cpp new file mode 100644 index 0000000..53b0bc5 --- /dev/null +++ b/ModeData.cpp @@ -0,0 +1,187 @@ +/* Copyright (c) <2016> , 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" + +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 files = _dot->listUserFiles(); + for (vector::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(4000); + 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(4000); + _dot->closeUserFile(_file); + return true; + } + return false; +} + +bool ModeData::start() +{ + if(checkFile()) + return true; + _help.display(); + osDelay(3000); + readFile(); +} + +void ModeData::displayData() +{ + std::vector 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; + } + } +} + + -- cgit v1.2.3 From ba7827cbda3cc77ac28dc933978f3d97a0c05369 Mon Sep 17 00:00:00 2001 From: Ryan Klaassen Date: Mon, 8 Aug 2016 12:51:00 -0500 Subject: Upload new file --- Mode/ModeData.h | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 Mode/ModeData.h diff --git a/Mode/ModeData.h b/Mode/ModeData.h new file mode 100644 index 0000000..2fe5239 --- /dev/null +++ b/Mode/ModeData.h @@ -0,0 +1,69 @@ +/* Copyright (c) <2016> , 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" +//max size of line plus one +#define ONELINEMAX 93 + + +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[ONELINEMAX]; + + 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 -- cgit v1.2.3 From 6daf6494b712f2034755f31e7e69b87b055cf551 Mon Sep 17 00:00:00 2001 From: Ryan Klaassen Date: Mon, 8 Aug 2016 12:52:48 -0500 Subject: Delete ModeData.cpp --- ModeData.cpp | 187 ----------------------------------------------------------- 1 file changed, 187 deletions(-) delete mode 100644 ModeData.cpp diff --git a/ModeData.cpp b/ModeData.cpp deleted file mode 100644 index 53b0bc5..0000000 --- a/ModeData.cpp +++ /dev/null @@ -1,187 +0,0 @@ -/* Copyright (c) <2016> , 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" - -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 files = _dot->listUserFiles(); - for (vector::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(4000); - 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(4000); - _dot->closeUserFile(_file); - return true; - } - return false; -} - -bool ModeData::start() -{ - if(checkFile()) - return true; - _help.display(); - osDelay(3000); - readFile(); -} - -void ModeData::displayData() -{ - std::vector 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; - } - } -} - - -- cgit v1.2.3 From eae9590d687a9a748d8a47eee28e0ccec5f85ede Mon Sep 17 00:00:00 2001 From: Ryan Klaassen Date: Mon, 8 Aug 2016 12:53:01 -0500 Subject: Upload new file --- Mode/ModeData.cpp | 187 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 187 insertions(+) create mode 100644 Mode/ModeData.cpp diff --git a/Mode/ModeData.cpp b/Mode/ModeData.cpp new file mode 100644 index 0000000..53b0bc5 --- /dev/null +++ b/Mode/ModeData.cpp @@ -0,0 +1,187 @@ +/* Copyright (c) <2016> , 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" + +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 files = _dot->listUserFiles(); + for (vector::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(4000); + 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(4000); + _dot->closeUserFile(_file); + return true; + } + return false; +} + +bool ModeData::start() +{ + if(checkFile()) + return true; + _help.display(); + osDelay(3000); + readFile(); +} + +void ModeData::displayData() +{ + std::vector 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; + } + } +} + + -- cgit v1.2.3 From 2d07be2d5f27e9b4cda490035dc9daa1538aefd1 Mon Sep 17 00:00:00 2001 From: Ryan Klaassen Date: Mon, 8 Aug 2016 12:53:36 -0500 Subject: Replace main.cpp --- main.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) 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 @@ -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 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; } } + -- cgit v1.2.3 -- cgit v1.2.3 From fb0d1cd298f03ab83dd86b92b7bb1fd2ac40151a Mon Sep 17 00:00:00 2001 From: Ryan Klaassen Date: Wed, 10 Aug 2016 13:03:56 -0500 Subject: Replace LayoutData.cpp --- Layout/LayoutData.cpp | 72 ++++++++++++++++++++------------------------------- 1 file changed, 28 insertions(+), 44 deletions(-) diff --git a/Layout/LayoutData.cpp b/Layout/LayoutData.cpp index 7cfb2ac..02e29fd 100644 --- a/Layout/LayoutData.cpp +++ b/Layout/LayoutData.cpp @@ -18,7 +18,6 @@ #include "LayoutData.h" - LayoutData::LayoutData(DOGS102* lcd) : Layout(lcd), _lDr(8, 0, "DR"), @@ -26,13 +25,9 @@ LayoutData::LayoutData(DOGS102* lcd) _lUp(0, 1, "UP Mgn"), _lGw(10, 1, "Gw"), _lDown(0, 2, "DWN -"), - _lNoData(1,3,"No Survey Data"), - _lErrorData1(1,3,"Error opening,"), - _lErrorData2(0,4,"survey data file."), - _lSurveyFailed(0,1,"Survey Failed"), - _lNoGps(0,3,"No GPS Data"), - _lDbm(9,2,"dbm"), - _lAlt(0,6,"Alt"), + _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), @@ -50,8 +45,7 @@ LayoutData::LayoutData(DOGS102* lcd) LayoutData::~LayoutData() {} -void LayoutData::display() -{ +void LayoutData::display(){ clear(); startUpdate(); writeLabel(_lDr); @@ -59,62 +53,52 @@ void LayoutData::display() endUpdate(); } -void LayoutData::noData() -{ +void LayoutData::noData(){ clear(); - writeLabel(_lNoData); + writeField(_fGpsLong, string(" No Survey Data"), true); } -void LayoutData::errorData() -{ +void LayoutData::errorData(){ clear(); - writeLabel(_lErrorData1); - writeLabel(_lErrorData2); + writeField(_fGpsLong, string(" Error opening,"), true); + writeField(_fGpsLat, string("survey data file."), true); } -void LayoutData::updateSw1(string str) -{ - writeField(_fSw1,str,true); +void LayoutData::updateSw1(string str){ + writeField(_fSw1, str, true); } -void LayoutData::updateSw2(string str) -{ - writeField(_fSw2,str,true); +void LayoutData::updateSw2(string str){ + writeField(_fSw2, str, true); } -bool LayoutData::updateAll(singleLine& line) -{ +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); + writeField(_fId, line.id, true); + writeField(_fDr, line.dataRate, true); + writeField(_fPwr, line.power, true); //check if survey pass/fail - if(line.gateways!="") { + 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); + 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.lat!="") { + 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 writeLabel(_lNoGps); - + 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(); } - - - - -- cgit v1.2.3 From 38c0e732ecb32968a91e7eef2b0c42d3062f231e Mon Sep 17 00:00:00 2001 From: Ryan Klaassen Date: Wed, 10 Aug 2016 13:04:17 -0500 Subject: Replace LayoutData.h --- Layout/LayoutData.h | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/Layout/LayoutData.h b/Layout/LayoutData.h index 78c74dd..ec91583 100644 --- a/Layout/LayoutData.h +++ b/Layout/LayoutData.h @@ -21,9 +21,7 @@ #include "Layout.h" - -class LayoutData : public Layout -{ +class LayoutData : public Layout{ public: LayoutData(DOGS102* lcd); ~LayoutData(); @@ -48,7 +46,6 @@ public: void noData(); void noGps(); void errorData(); - void updateSw1(string str); void updateSw2(string str); bool updateAll(singleLine& line); @@ -60,11 +57,7 @@ private: Label _lGw; Label _lDown; Label _lDbm; - Label _lNoData; Label _lSurveyFailed; - Label _lErrorData1; - Label _lErrorData2; - Label _lNoGps; Label _lAlt; Field _fId; @@ -80,11 +73,5 @@ private: Field _fAlt; Field _fSw1; Field _fSw2; - }; - #endif - - - - -- cgit v1.2.3 From d4fe469db33a60931015e721ec851bf7f7856f37 Mon Sep 17 00:00:00 2001 From: Ryan Klaassen Date: Wed, 10 Aug 2016 13:04:35 -0500 Subject: Replace ModeData.cpp --- Mode/ModeData.cpp | 74 +++++++++++++++++++++++++++---------------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/Mode/ModeData.cpp b/Mode/ModeData.cpp index 53b0bc5..401277e 100644 --- a/Mode/ModeData.cpp +++ b/Mode/ModeData.cpp @@ -18,6 +18,7 @@ #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), @@ -28,8 +29,7 @@ ModeData::ModeData(DOGS102* lcd, ButtonHandler* _buttons, mDot* _dot, LoRaHandle ModeData::~ModeData() {} -bool ModeData::checkFile() -{ +bool ModeData::checkFile(){ bool exists = false; //get all files and see if file exists vector files = _dot->listUserFiles(); @@ -42,22 +42,21 @@ bool ModeData::checkFile() //if file doesnt exist exit to main menu if(!exists) { _data.noData(); - osDelay(4000); + 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(4000); + osDelay(3000); _dot->closeUserFile(_file); return true; } return false; } -bool ModeData::start() -{ +bool ModeData::start(){ if(checkFile()) return true; _help.display(); @@ -65,8 +64,7 @@ bool ModeData::start() readFile(); } -void ModeData::displayData() -{ +void ModeData::displayData(){ std::vector data = mts::Text::split(_str, ','); _line.id = data.at(0); _line.status = data.at(1); @@ -85,8 +83,7 @@ void ModeData::displayData() } //get the current line out of the buffer into str -void ModeData::getLine() -{ +void ModeData::getLine(){ _prev = 0; _indexUpdate = 0; _str = ""; @@ -96,7 +93,9 @@ void ModeData::getLine() //-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--; + while(_buf[_indexUpdate] != '\n' && _indexUpdate >= 0){ + _indexUpdate--; + } _indexUpdate++; } //go from indexUpdate to new line to ge the line @@ -107,29 +106,29 @@ void ModeData::getLine() _prev++; } //push index past newline - _index += _indexUpdate+1; + _index += _indexUpdate + 1; displayData(); } -void ModeData::back() -{ - if(_index>=(_buf_size+_prev)) { - _index -= (_prev+_buf_size); +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; + if(_index > 0){ + _buf_size = _index-1; + } _buf_size -= _prev; _index = 0; } _last = true; - _dot->seekUserFile(_file,_index, SEEK_SET); + _dot->seekUserFile(_file, _index, SEEK_SET); getLine(); } -void ModeData::forward() -{ +void ModeData::forward(){ _last = false; - if(_index<_file.size) { + if(_index < _file.size) { _buf_size = ONELINEMAX; _dot->seekUserFile(_file, _index, SEEK_SET); getLine(); @@ -137,17 +136,20 @@ void ModeData::forward() } //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(""); +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() -{ +bool ModeData::readFile(){ _index = 0; _last = false; _prev = 0; @@ -156,22 +158,21 @@ bool ModeData::readFile() forward(); configSw(); ButtonHandler::ButtonEvent be; - while (true) { - be = _buttons->getButtonEvent(); - switch(be) { case ButtonHandler::sw1_press: if(_index!=_file.size) { forward(); - configSw();} + configSw(); + } break; case ButtonHandler::sw2_press: - if(_index-(_prev+1)>0) { + if(_index - (_prev+1) > 0) { back(); - configSw();} + configSw(); + } break; case ButtonHandler::sw1_hold: @@ -184,4 +185,3 @@ bool ModeData::readFile() } } - -- cgit v1.2.3 From 5d9f1f7f1863c7c92d7aa29c37ced672b2946118 Mon Sep 17 00:00:00 2001 From: Ryan Klaassen Date: Wed, 10 Aug 2016 13:04:52 -0500 Subject: Replace ModeData.h --- Mode/ModeData.h | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/Mode/ModeData.h b/Mode/ModeData.h index 2fe5239..f9da741 100644 --- a/Mode/ModeData.h +++ b/Mode/ModeData.h @@ -22,12 +22,8 @@ #include "Mode.h" #include "LayoutData.h" #include "LayoutHelp.h" -//max size of line plus one -#define ONELINEMAX 93 - -class ModeData : public Mode -{ +class ModeData : public Mode{ public: ModeData(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora, GPSPARSER* gps, SensorHandler* sensors); @@ -35,18 +31,14 @@ public: bool start(); - private: - - - bool _last; string _str; int32_t _pos, _buf_size, _indexUpdate, _prev; uint32_t _index; - char _buf[ONELINEMAX]; + char _buf[93]; mDot::mdot_file _file; @@ -62,8 +54,5 @@ private: void forward(); void back(); void configSw(); - - }; - #endif \ No newline at end of file -- cgit v1.2.3