MTDOT-BOX-EVB-Factory-Firmware
Dependencies: NCP5623B GpsParser ISL29011 libmDot-mbed5 MTS-Serial MMA845x DOGS102 MPL3115A2
Mode/ModeSingle.cpp@12:05435282f899, 2018-10-09 (annotated)
- Committer:
- jenkins@jenkinsdm1
- Date:
- Tue Oct 09 13:49:30 2018 -0500
- Revision:
- 12:05435282f899
- Parent:
- 7:a31236c2e75c
dotbox-firmware revision 3.1.1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Mike Fiore |
1:71125aa00e33 | 1 | /* Copyright (c) <2016> <MultiTech Systems>, MIT License |
Mike Fiore |
1:71125aa00e33 | 2 | * |
Mike Fiore |
1:71125aa00e33 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
Mike Fiore |
1:71125aa00e33 | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
Mike Fiore |
1:71125aa00e33 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
Mike Fiore |
1:71125aa00e33 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
Mike Fiore |
1:71125aa00e33 | 7 | * furnished to do so, subject to the following conditions: |
Mike Fiore |
1:71125aa00e33 | 8 | * |
Mike Fiore |
1:71125aa00e33 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
Mike Fiore |
1:71125aa00e33 | 10 | * substantial portions of the Software. |
Mike Fiore |
1:71125aa00e33 | 11 | * |
Mike Fiore |
1:71125aa00e33 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
Mike Fiore |
1:71125aa00e33 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
Mike Fiore |
1:71125aa00e33 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
Mike Fiore |
1:71125aa00e33 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
Mike Fiore |
1:71125aa00e33 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
Mike Fiore |
1:71125aa00e33 | 17 | */ |
Mike Fiore |
1:71125aa00e33 | 18 | |
Mike Fiore |
1:71125aa00e33 | 19 | #include "ModeSingle.h" |
Mike Fiore |
1:71125aa00e33 | 20 | #include "MTSLog.h" |
Mike Fiore |
1:71125aa00e33 | 21 | |
Mike Fiore |
1:71125aa00e33 | 22 | ModeSingle::ModeSingle(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora, GPSPARSER* gps, SensorHandler* sensors) |
Mike Fiore |
1:71125aa00e33 | 23 | : Mode(lcd, buttons, dot, lora, gps, sensors), |
Mike Fiore |
1:71125aa00e33 | 24 | _help(lcd), |
Mike Fiore |
1:71125aa00e33 | 25 | _file(lcd), |
Mike Fiore |
1:71125aa00e33 | 26 | _confirm(lcd), |
Mike Fiore |
1:71125aa00e33 | 27 | _progress(lcd), |
Mike Fiore |
1:71125aa00e33 | 28 | _success(lcd), |
Mike Fiore |
1:71125aa00e33 | 29 | _failure(lcd) |
Mike Fiore |
1:71125aa00e33 | 30 | {} |
Mike Fiore |
1:71125aa00e33 | 31 | |
Mike Fiore |
1:71125aa00e33 | 32 | ModeSingle::~ModeSingle() {} |
Mike Fiore |
1:71125aa00e33 | 33 | |
Mike Fiore |
1:71125aa00e33 | 34 | bool ModeSingle::start() { |
Mike Fiore |
1:71125aa00e33 | 35 | bool data_file = false; |
Mike Fiore |
1:71125aa00e33 | 36 | bool send_link_check = false; |
Mike Fiore |
1:71125aa00e33 | 37 | bool send_data = false; |
Mike Fiore |
1:71125aa00e33 | 38 | bool no_channel_link_check = false; |
Mike Fiore |
1:71125aa00e33 | 39 | bool no_channel_data = false; |
Mike Fiore |
1:71125aa00e33 | 40 | |
Mike Fiore |
1:71125aa00e33 | 41 | // clear any stale signals |
Mike Fiore |
1:71125aa00e33 | 42 | osSignalClear(_main_id, buttonSignal | loraSignal); |
Mike Fiore |
1:71125aa00e33 | 43 | |
jenkins@jenkinsdm1 | 12:05435282f899 | 44 | _initial_data_rate = _dot->getTxDataRate() < _dot->getMinDatarate() ? _dot->getMinDatarate() : _dot->getTxDataRate(); |
Mike Fiore |
1:71125aa00e33 | 45 | _initial_power = _dot->getTxPower(); |
jenkins@jenkinsdm1 | 12:05435282f899 | 46 | _data_rate = _dot->getMinDatarate(); |
jenkins@jenkinsdm1 | 12:05435282f899 | 47 | |
Mike Fiore |
1:71125aa00e33 | 48 | |
Mike Fiore |
1:71125aa00e33 | 49 | // see if we're supposed to send the data packet after success |
Mike Fiore |
1:71125aa00e33 | 50 | // that item is stored in the mDot::StartUpMode config field |
Mike Fiore |
1:71125aa00e33 | 51 | _send_data = _dot->getStartUpMode(); |
Mike Fiore |
1:71125aa00e33 | 52 | |
Mike Fiore |
1:71125aa00e33 | 53 | // see if survey data file exists |
Mike Fiore |
1:71125aa00e33 | 54 | std::vector<mDot::mdot_file> files = _dot->listUserFiles(); |
Mike Fiore |
1:71125aa00e33 | 55 | for (std::vector<mDot::mdot_file>::iterator it = files.begin(); it != files.end(); it++) { |
Mike Fiore |
1:71125aa00e33 | 56 | if (strcmp(it->name, file_name) == 0) { |
Mike Fiore |
1:71125aa00e33 | 57 | logInfo("found survey data file"); |
Mike Fiore |
1:71125aa00e33 | 58 | data_file = true; |
Mike Fiore |
1:71125aa00e33 | 59 | break; |
Mike Fiore |
1:71125aa00e33 | 60 | } |
Mike Fiore |
1:71125aa00e33 | 61 | } |
Mike Fiore |
1:71125aa00e33 | 62 | if (data_file) { |
Mike Fiore |
1:71125aa00e33 | 63 | _state = check_file; |
Mike Fiore |
1:71125aa00e33 | 64 | _file.display(); |
Mike Fiore |
1:71125aa00e33 | 65 | } else { |
Mike Fiore |
1:71125aa00e33 | 66 | _state = show_help; |
Mike Fiore |
1:71125aa00e33 | 67 | _index = 0; |
Mike Fiore |
1:71125aa00e33 | 68 | displayHelp(); |
Mike Fiore |
1:71125aa00e33 | 69 | } |
Mike Fiore |
1:71125aa00e33 | 70 | |
Mike Fiore |
1:71125aa00e33 | 71 | while (true) { |
Mike Fiore |
1:71125aa00e33 | 72 | osEvent e = Thread::signal_wait(0, 250); |
Mike Fiore |
1:71125aa00e33 | 73 | if (e.status == osEventSignal) { |
Mike Fiore |
1:71125aa00e33 | 74 | if (e.value.signals & buttonSignal) { |
Mike Fiore |
1:71125aa00e33 | 75 | _be = _buttons->getButtonEvent(); |
Mike Fiore |
1:71125aa00e33 | 76 | |
Mike Fiore |
1:71125aa00e33 | 77 | switch (_be) { |
Mike Fiore |
1:71125aa00e33 | 78 | case ButtonHandler::sw1_press: |
Mike Fiore |
1:71125aa00e33 | 79 | switch (_state) { |
Mike Fiore |
1:71125aa00e33 | 80 | case check_file: |
Mike Fiore |
1:71125aa00e33 | 81 | _state = show_help; |
Mike Fiore |
1:71125aa00e33 | 82 | _index = getIndex(single); |
Mike Fiore |
1:71125aa00e33 | 83 | displayHelp(); |
Mike Fiore |
1:71125aa00e33 | 84 | break; |
Mike Fiore |
1:71125aa00e33 | 85 | case confirm: |
Mike Fiore |
1:71125aa00e33 | 86 | _state = check_file; |
Mike Fiore |
1:71125aa00e33 | 87 | _file.display(); |
Mike Fiore |
1:71125aa00e33 | 88 | break; |
Mike Fiore |
1:71125aa00e33 | 89 | case show_help: |
Mike Fiore |
1:71125aa00e33 | 90 | incrementRatePower(); |
Mike Fiore |
1:71125aa00e33 | 91 | _help.updateMsg(formatRatePower()); |
Mike Fiore |
1:71125aa00e33 | 92 | break; |
Mike Fiore |
1:71125aa00e33 | 93 | case success: |
Mike Fiore |
1:71125aa00e33 | 94 | incrementRatePower(); |
Mike Fiore |
1:71125aa00e33 | 95 | _success.updateInfo(formatRatePower()); |
Mike Fiore |
1:71125aa00e33 | 96 | break; |
Mike Fiore |
1:71125aa00e33 | 97 | case failure: |
Mike Fiore |
1:71125aa00e33 | 98 | incrementRatePower(); |
Mike Fiore |
1:71125aa00e33 | 99 | _failure.updateInfo(formatRatePower()); |
Mike Fiore |
1:71125aa00e33 | 100 | break; |
Mike Fiore |
1:71125aa00e33 | 101 | } |
Mike Fiore |
1:71125aa00e33 | 102 | break; |
Mike Fiore |
1:71125aa00e33 | 103 | |
Mike Fiore |
1:71125aa00e33 | 104 | case ButtonHandler::sw2_press: |
Mike Fiore |
1:71125aa00e33 | 105 | switch (_state) { |
Mike Fiore |
1:71125aa00e33 | 106 | case check_file: |
Mike Fiore |
1:71125aa00e33 | 107 | _state = confirm; |
Mike Fiore |
1:71125aa00e33 | 108 | _confirm.display(); |
Mike Fiore |
1:71125aa00e33 | 109 | break; |
Mike Fiore |
1:71125aa00e33 | 110 | case confirm: |
Mike Fiore |
1:71125aa00e33 | 111 | _state = show_help; |
Mike Fiore |
1:71125aa00e33 | 112 | logInfo("deleting survey data file"); |
Mike Fiore |
1:71125aa00e33 | 113 | _dot->deleteUserFile(file_name); |
Mike Fiore |
1:71125aa00e33 | 114 | _index = 0; |
Mike Fiore |
1:71125aa00e33 | 115 | displayHelp(); |
Mike Fiore |
1:71125aa00e33 | 116 | break; |
Mike Fiore |
1:71125aa00e33 | 117 | case show_help: |
Mike Fiore |
1:71125aa00e33 | 118 | _state = in_progress; |
Mike Fiore |
1:71125aa00e33 | 119 | _progress.display(); |
Mike Fiore |
1:71125aa00e33 | 120 | if (_dot->getNextTxMs() > 0) |
Mike Fiore |
1:71125aa00e33 | 121 | no_channel_link_check = true; |
Mike Fiore |
1:71125aa00e33 | 122 | else |
Mike Fiore |
1:71125aa00e33 | 123 | send_link_check = true; |
Mike Fiore |
1:71125aa00e33 | 124 | break; |
Mike Fiore |
1:71125aa00e33 | 125 | case success: |
Mike Fiore |
1:71125aa00e33 | 126 | _state = in_progress; |
Mike Fiore |
1:71125aa00e33 | 127 | _progress.display(); |
Mike Fiore |
1:71125aa00e33 | 128 | if (_dot->getNextTxMs() > 0) |
Mike Fiore |
1:71125aa00e33 | 129 | no_channel_link_check = true; |
Mike Fiore |
1:71125aa00e33 | 130 | else |
Mike Fiore |
1:71125aa00e33 | 131 | send_link_check = true; |
Mike Fiore |
1:71125aa00e33 | 132 | break; |
Mike Fiore |
1:71125aa00e33 | 133 | case failure: |
Mike Fiore |
1:71125aa00e33 | 134 | _state = in_progress; |
Mike Fiore |
1:71125aa00e33 | 135 | _progress.display(); |
Mike Fiore |
1:71125aa00e33 | 136 | if (_dot->getNextTxMs() > 0) |
Mike Fiore |
1:71125aa00e33 | 137 | no_channel_link_check = true; |
Mike Fiore |
1:71125aa00e33 | 138 | else |
Mike Fiore |
1:71125aa00e33 | 139 | send_link_check = true; |
Mike Fiore |
1:71125aa00e33 | 140 | break; |
Mike Fiore |
1:71125aa00e33 | 141 | } |
Mike Fiore |
1:71125aa00e33 | 142 | break; |
Mike Fiore |
1:71125aa00e33 | 143 | case ButtonHandler::sw1_hold: |
Mike Fiore |
1:71125aa00e33 | 144 | _dot->setTxDataRate(_initial_data_rate); |
Mike Fiore |
1:71125aa00e33 | 145 | _dot->setTxPower(_initial_power); |
Mike Fiore |
1:71125aa00e33 | 146 | return true; |
Mike Fiore |
1:71125aa00e33 | 147 | } |
Mike Fiore |
1:71125aa00e33 | 148 | } |
Mike Fiore |
1:71125aa00e33 | 149 | if (e.value.signals & loraSignal) { |
Mike Fiore |
1:71125aa00e33 | 150 | _ls = _lora->getStatus(); |
Mike Fiore |
1:71125aa00e33 | 151 | switch (_ls) { |
Mike Fiore |
1:71125aa00e33 | 152 | case LoRaHandler::link_check_success: |
Mike Fiore |
1:71125aa00e33 | 153 | switch (_state) { |
Mike Fiore |
1:71125aa00e33 | 154 | case in_progress: |
Mike Fiore |
1:71125aa00e33 | 155 | _link_check_result = _lora->getLinkCheckResults(); |
Mike Fiore |
1:71125aa00e33 | 156 | displaySuccess(); |
Mike Fiore |
1:71125aa00e33 | 157 | logInfo("link check successful\tMargin %ld\tRSSI %d dBm\tSNR %2.3f", _link_check_result.up.dBm, _link_check_result.down.rssi, (float)_link_check_result.down.snr / 10.0); |
Mike Fiore |
1:71125aa00e33 | 158 | updateData(_data, single, true); |
Mike Fiore |
1:71125aa00e33 | 159 | appendDataFile(_data); |
Mike Fiore |
1:71125aa00e33 | 160 | if (_send_data) { |
Mike Fiore |
1:71125aa00e33 | 161 | _state = data; |
Mike Fiore |
1:71125aa00e33 | 162 | if (_dot->getNextTxMs() > 0) |
Mike Fiore |
1:71125aa00e33 | 163 | no_channel_data = true; |
Mike Fiore |
1:71125aa00e33 | 164 | else |
Mike Fiore |
1:71125aa00e33 | 165 | send_data = true; |
Mike Fiore |
1:71125aa00e33 | 166 | } else { |
Mike Fiore |
1:71125aa00e33 | 167 | _state = success; |
Mike Fiore |
1:71125aa00e33 | 168 | _success.updateSw1(" DR/PWR"); |
Mike Fiore |
1:71125aa00e33 | 169 | _success.updateSw2("Survey"); |
Mike Fiore |
1:71125aa00e33 | 170 | } |
Mike Fiore |
1:71125aa00e33 | 171 | break; |
Mike Fiore |
1:71125aa00e33 | 172 | } |
Mike Fiore |
1:71125aa00e33 | 173 | break; |
Mike Fiore |
1:71125aa00e33 | 174 | |
Mike Fiore |
1:71125aa00e33 | 175 | case LoRaHandler::link_check_failure: |
Mike Fiore |
1:71125aa00e33 | 176 | switch (_state) { |
Mike Fiore |
1:71125aa00e33 | 177 | case in_progress: |
Mike Fiore |
1:71125aa00e33 | 178 | _state = failure; |
Mike Fiore |
1:71125aa00e33 | 179 | _failure.display(); |
Mike Fiore |
1:71125aa00e33 | 180 | _failure.updateId(_index); |
Mike Fiore |
7:a31236c2e75c | 181 | // mDot::DataRateStr returns format DRXX - we only want to display the XX part |
Mike Fiore |
7:a31236c2e75c | 182 | _failure.updateRate(_dot->DataRateStr(_data_rate).substr(2)); |
Mike Fiore |
1:71125aa00e33 | 183 | updateData(_data, single, false); |
Mike Fiore |
1:71125aa00e33 | 184 | appendDataFile(_data); |
Mike Fiore |
1:71125aa00e33 | 185 | _failure.updatePower(_power); |
Mike Fiore |
1:71125aa00e33 | 186 | if (_gps_available && _gps->getLockStatus()) { |
Mike Fiore |
1:71125aa00e33 | 187 | GPSPARSER::latitude lat = _gps->getLatitude(); |
Mike Fiore |
1:71125aa00e33 | 188 | GPSPARSER::longitude lon = _gps->getLongitude(); |
Mike Fiore |
1:71125aa00e33 | 189 | struct tm time = _gps->getTimestamp(); |
Mike Fiore |
1:71125aa00e33 | 190 | _failure.updateGpsLatitude(lat); |
Mike Fiore |
1:71125aa00e33 | 191 | _failure.updateGpsLongitude(lon); |
Mike Fiore |
1:71125aa00e33 | 192 | _failure.updateGpsTime(time); |
Mike Fiore |
1:71125aa00e33 | 193 | } else { |
Mike Fiore |
1:71125aa00e33 | 194 | _failure.updateGpsLatitude("No GPS Lock"); |
Mike Fiore |
1:71125aa00e33 | 195 | } |
Mike Fiore |
1:71125aa00e33 | 196 | _failure.updateSw1(" DR/PWR"); |
Mike Fiore |
1:71125aa00e33 | 197 | _failure.updateSw2("Survey"); |
Mike Fiore |
1:71125aa00e33 | 198 | logInfo("link check failed"); |
Mike Fiore |
1:71125aa00e33 | 199 | break; |
Mike Fiore |
1:71125aa00e33 | 200 | } |
Mike Fiore |
1:71125aa00e33 | 201 | break; |
Mike Fiore |
1:71125aa00e33 | 202 | |
Mike Fiore |
1:71125aa00e33 | 203 | case LoRaHandler::send_success: |
Mike Fiore |
1:71125aa00e33 | 204 | switch (_state) { |
Mike Fiore |
1:71125aa00e33 | 205 | case data: |
Mike Fiore |
1:71125aa00e33 | 206 | _state = success; |
Mike Fiore |
1:71125aa00e33 | 207 | _success.updateInfo(" "); |
Mike Fiore |
1:71125aa00e33 | 208 | _success.updateSw1(" DR/PWR"); |
Mike Fiore |
1:71125aa00e33 | 209 | _success.updateSw2("Survey"); |
Mike Fiore |
1:71125aa00e33 | 210 | // turn acks and receive windows back on |
Mike Fiore |
1:71125aa00e33 | 211 | _dot->setAck(1); |
Mike Fiore |
1:71125aa00e33 | 212 | _dot->setTxWait(true); |
Mike Fiore |
1:71125aa00e33 | 213 | logInfo("data send success"); |
Mike Fiore |
1:71125aa00e33 | 214 | break; |
Mike Fiore |
1:71125aa00e33 | 215 | } |
Mike Fiore |
1:71125aa00e33 | 216 | break; |
Mike Fiore |
1:71125aa00e33 | 217 | |
Mike Fiore |
1:71125aa00e33 | 218 | case LoRaHandler::send_failure: |
Mike Fiore |
1:71125aa00e33 | 219 | switch (_state) { |
Mike Fiore |
1:71125aa00e33 | 220 | case data: |
Mike Fiore |
1:71125aa00e33 | 221 | _state = success; |
Mike Fiore |
1:71125aa00e33 | 222 | _success.updateInfo(" "); |
Mike Fiore |
1:71125aa00e33 | 223 | _success.updateSw1(" DR/PWR"); |
Mike Fiore |
1:71125aa00e33 | 224 | _success.updateSw2("Survey"); |
Mike Fiore |
1:71125aa00e33 | 225 | // turn acks and receive windows back on |
Mike Fiore |
1:71125aa00e33 | 226 | _dot->setAck(1); |
Mike Fiore |
1:71125aa00e33 | 227 | _dot->setTxWait(true); |
Mike Fiore |
1:71125aa00e33 | 228 | logInfo("data send failed"); |
Mike Fiore |
1:71125aa00e33 | 229 | break; |
Mike Fiore |
1:71125aa00e33 | 230 | } |
Mike Fiore |
1:71125aa00e33 | 231 | break; |
Mike Fiore |
1:71125aa00e33 | 232 | } |
Mike Fiore |
1:71125aa00e33 | 233 | } |
Mike Fiore |
1:71125aa00e33 | 234 | } |
Mike Fiore |
1:71125aa00e33 | 235 | |
Mike Fiore |
1:71125aa00e33 | 236 | if (no_channel_link_check) { |
Mike Fiore |
1:71125aa00e33 | 237 | uint32_t t = _dot->getNextTxMs(); |
Mike Fiore |
1:71125aa00e33 | 238 | if (t > 0) { |
Mike Fiore |
1:71125aa00e33 | 239 | logInfo("next tx %lu ms", t); |
Mike Fiore |
1:71125aa00e33 | 240 | _progress.updateCountdown(t / 1000); |
Mike Fiore |
1:71125aa00e33 | 241 | } else { |
Mike Fiore |
1:71125aa00e33 | 242 | _progress.display(); |
Mike Fiore |
1:71125aa00e33 | 243 | no_channel_link_check = false; |
Mike Fiore |
1:71125aa00e33 | 244 | send_link_check = true; |
Mike Fiore |
1:71125aa00e33 | 245 | } |
Mike Fiore |
1:71125aa00e33 | 246 | } |
Mike Fiore |
1:71125aa00e33 | 247 | if (no_channel_data) { |
Mike Fiore |
1:71125aa00e33 | 248 | uint32_t t = _dot->getNextTxMs(); |
Mike Fiore |
1:71125aa00e33 | 249 | if (t > 0) { |
Mike Fiore |
1:71125aa00e33 | 250 | logInfo("next tx %lu ms", t); |
Mike Fiore |
1:71125aa00e33 | 251 | _success.updateCountdown(t / 1000); |
Mike Fiore |
1:71125aa00e33 | 252 | } else { |
Mike Fiore |
1:71125aa00e33 | 253 | displaySuccess(); |
Mike Fiore |
1:71125aa00e33 | 254 | no_channel_data = false; |
Mike Fiore |
1:71125aa00e33 | 255 | send_data = true; |
Mike Fiore |
1:71125aa00e33 | 256 | } |
Mike Fiore |
1:71125aa00e33 | 257 | } |
Mike Fiore |
1:71125aa00e33 | 258 | if (send_link_check) { |
Mike Fiore |
1:71125aa00e33 | 259 | logInfo("sending link check %s %d", _dot->DataRateStr(_data_rate).c_str(), _power); |
Mike Fiore |
1:71125aa00e33 | 260 | send_link_check = false; |
Mike Fiore |
1:71125aa00e33 | 261 | _dot->setTxDataRate(_data_rate); |
Mike Fiore |
1:71125aa00e33 | 262 | _dot->setTxPower(_power); |
Mike Fiore |
1:71125aa00e33 | 263 | _lora->linkCheck(); |
Mike Fiore |
1:71125aa00e33 | 264 | _index++; |
Mike Fiore |
1:71125aa00e33 | 265 | } |
Mike Fiore |
1:71125aa00e33 | 266 | if (send_data) { |
Mike Fiore |
1:71125aa00e33 | 267 | std::vector<uint8_t> s_data = formatSurveyData(_data); |
Mike Fiore |
1:71125aa00e33 | 268 | logInfo("sending data %s %d", _dot->DataRateStr(_data_rate).c_str(), _power); |
Mike Fiore |
1:71125aa00e33 | 269 | send_data = false; |
Mike Fiore |
1:71125aa00e33 | 270 | _success.updateInfo("Data Sending..."); |
Mike Fiore |
1:71125aa00e33 | 271 | _dot->setTxDataRate(_data_rate); |
Mike Fiore |
1:71125aa00e33 | 272 | _dot->setTxPower(_power); |
Mike Fiore |
1:71125aa00e33 | 273 | // we don't care if the server actually gets this packet or not |
Mike Fiore |
1:71125aa00e33 | 274 | // we won't retry anyway |
Mike Fiore |
1:71125aa00e33 | 275 | _dot->setAck(0); |
Mike Fiore |
1:71125aa00e33 | 276 | _dot->setTxWait(false); |
Mike Fiore |
1:71125aa00e33 | 277 | _lora->send(s_data); |
Mike Fiore |
1:71125aa00e33 | 278 | osDelay(500); |
Mike Fiore |
1:71125aa00e33 | 279 | } |
Mike Fiore |
1:71125aa00e33 | 280 | } |
Mike Fiore |
1:71125aa00e33 | 281 | } |
Mike Fiore |
1:71125aa00e33 | 282 | |
Mike Fiore |
1:71125aa00e33 | 283 | void ModeSingle::displayHelp() { |
Mike Fiore |
1:71125aa00e33 | 284 | _help.display(); |
Mike Fiore |
1:71125aa00e33 | 285 | _help.updateMode("Survey Single"); |
Mike Fiore |
1:71125aa00e33 | 286 | _help.updateSw1(" DR/PWR"); |
Mike Fiore |
1:71125aa00e33 | 287 | _help.updateSw2("Survey"); |
Mike Fiore |
1:71125aa00e33 | 288 | _help.updateMsg(formatRatePower()); |
Mike Fiore |
1:71125aa00e33 | 289 | } |
Mike Fiore |
1:71125aa00e33 | 290 | |
Mike Fiore |
1:71125aa00e33 | 291 | void ModeSingle::displaySuccess() { |
Mike Fiore |
1:71125aa00e33 | 292 | uint8_t fix = _gps->getFixStatus(); |
Mike Fiore |
1:71125aa00e33 | 293 | _success.display(); |
Mike Fiore |
1:71125aa00e33 | 294 | _success.updateId(_index); |
Mike Fiore |
1:71125aa00e33 | 295 | // mDot::DataRateStr returns format SF_XX - we only want to display the XX part |
Mike Fiore |
7:a31236c2e75c | 296 | _success.updateRate(_dot->DataRateStr(_data_rate).substr(2)); |
Mike Fiore |
1:71125aa00e33 | 297 | _success.updatePower(_power); |
Mike Fiore |
1:71125aa00e33 | 298 | _success.updateStats(_link_check_result); |
Mike Fiore |
1:71125aa00e33 | 299 | if (_gps_available && _gps->getLockStatus()) { |
Mike Fiore |
1:71125aa00e33 | 300 | GPSPARSER::latitude lat = _gps->getLatitude(); |
Mike Fiore |
1:71125aa00e33 | 301 | GPSPARSER::longitude lon = _gps->getLongitude(); |
Mike Fiore |
1:71125aa00e33 | 302 | struct tm time = _gps->getTimestamp(); |
Mike Fiore |
1:71125aa00e33 | 303 | _success.updateGpsLatitude(lat); |
Mike Fiore |
1:71125aa00e33 | 304 | _success.updateGpsLongitude(lon); |
Mike Fiore |
1:71125aa00e33 | 305 | _success.updateGpsTime(time); |
Mike Fiore |
1:71125aa00e33 | 306 | } else { |
Mike Fiore |
1:71125aa00e33 | 307 | _success.updateGpsLatitude("No GPS Lock"); |
Mike Fiore |
1:71125aa00e33 | 308 | } |
Mike Fiore |
1:71125aa00e33 | 309 | } |
Mike Fiore |
1:71125aa00e33 | 310 | |
Mike Fiore |
1:71125aa00e33 | 311 | std::string ModeSingle::formatRatePower() { |
Mike Fiore |
1:71125aa00e33 | 312 | std::string msg; |
Mike Fiore |
1:71125aa00e33 | 313 | char buf[8]; |
Mike Fiore |
1:71125aa00e33 | 314 | size_t size; |
Mike Fiore |
1:71125aa00e33 | 315 | |
Mike Fiore |
1:71125aa00e33 | 316 | msg += "DR="; |
Mike Fiore |
7:a31236c2e75c | 317 | msg += _dot->DataRateStr(_data_rate).substr(2); |
Mike Fiore |
1:71125aa00e33 | 318 | msg += " P="; |
Mike Fiore |
1:71125aa00e33 | 319 | size = snprintf(buf, sizeof(buf), "%u", _power); |
Mike Fiore |
1:71125aa00e33 | 320 | msg.append(buf, size); |
Mike Fiore |
1:71125aa00e33 | 321 | |
Mike Fiore |
1:71125aa00e33 | 322 | return msg; |
Mike Fiore |
1:71125aa00e33 | 323 | } |
Mike Fiore |
1:71125aa00e33 | 324 | |
Mike Fiore |
1:71125aa00e33 | 325 | void ModeSingle::incrementRatePower() { |
jenkins@jenkinsdm1 | 12:05435282f899 | 326 | if (_power <= 2) { |
jenkins@jenkinsdm1 | 12:05435282f899 | 327 | _power = 20; |
Mike Fiore |
7:a31236c2e75c | 328 | _data_rate++; |
jenkins@jenkinsdm1 | 12:05435282f899 | 329 | if (_data_rate > _dot->getMaxDatarate()) { |
jenkins@jenkinsdm1 | 12:05435282f899 | 330 | _data_rate = _dot->getMinDatarate(); |
Mike Fiore |
1:71125aa00e33 | 331 | } |
Mike Fiore |
1:71125aa00e33 | 332 | } else { |
jenkins@jenkinsdm1 | 12:05435282f899 | 333 | _power -= 3; |
Mike Fiore |
1:71125aa00e33 | 334 | } |
Mike Fiore |
1:71125aa00e33 | 335 | |
Mike Fiore |
1:71125aa00e33 | 336 | logInfo("new data rate %s, power %lu", mDot::DataRateStr(_data_rate).c_str(), _power); |
Mike Fiore |
1:71125aa00e33 | 337 | } |
Mike Fiore |
1:71125aa00e33 | 338 |