MTDOT-BOX-EVB-Factory-Firmware

Dependencies:   NCP5623B GpsParser ISL29011 libmDot-mbed5 MTS-Serial MMA845x DOGS102 MPL3115A2

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?

UserRevisionLine numberNew 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 "ModeSweep.h"
Mike Fiore 1:71125aa00e33 20 #include "MTSLog.h"
Mike Fiore 1:71125aa00e33 21
Mike Fiore 1:71125aa00e33 22 ModeSweep::ModeSweep(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 _complete(lcd)
Mike Fiore 1:71125aa00e33 31 {}
Mike Fiore 1:71125aa00e33 32
Mike Fiore 1:71125aa00e33 33 ModeSweep::~ModeSweep() {}
Mike Fiore 1:71125aa00e33 34
Mike Fiore 1:71125aa00e33 35 bool ModeSweep::start() {
Mike Fiore 1:71125aa00e33 36 bool data_file = false;
Mike Fiore 1:71125aa00e33 37 bool send_link_check = false;
Mike Fiore 1:71125aa00e33 38 bool send_data = false;
Mike Fiore 1:71125aa00e33 39 bool no_channel_link_check = false;
Mike Fiore 1:71125aa00e33 40 bool no_channel_data = false;
Mike Fiore 1:71125aa00e33 41
Mike Fiore 1:71125aa00e33 42 // clear any stale signals
Mike Fiore 1:71125aa00e33 43 osSignalClear(_main_id, buttonSignal | loraSignal);
Mike Fiore 1:71125aa00e33 44
Mike Fiore 1:71125aa00e33 45 _initial_data_rate = _dot->getTxDataRate();
Mike Fiore 1:71125aa00e33 46 _initial_power = _dot->getTxPower();
Mike Fiore 1:71125aa00e33 47
Mike Fiore 1:71125aa00e33 48 // see if we're supposed to send the data packet after success
Mike Fiore 1:71125aa00e33 49 // that item is stored in the mDot::StartUpMode config field
Mike Fiore 1:71125aa00e33 50 _send_data = _dot->getStartUpMode();
Mike Fiore 1:71125aa00e33 51
Mike Fiore 1:71125aa00e33 52 // pull the minimum and maximum payload size out of config
Mike Fiore 1:71125aa00e33 53 // min payload size is wake interval
Mike Fiore 1:71125aa00e33 54 // max payload size is wake delay
Mike Fiore 1:71125aa00e33 55 _min_payload = _dot->getWakeInterval();
Mike Fiore 1:71125aa00e33 56 _max_payload = _dot->getWakeDelay();
Mike Fiore 1:71125aa00e33 57
Mike Fiore 1:71125aa00e33 58 // pull the minimum and maximum power out of config
Mike Fiore 1:71125aa00e33 59 // min power is wake timeout
Mike Fiore 1:71125aa00e33 60 // max power is wake mode
Mike Fiore 1:71125aa00e33 61 _min_power = _dot->getWakeTimeout();
Mike Fiore 1:71125aa00e33 62 _max_power = _dot->getWakeMode();
Mike Fiore 1:71125aa00e33 63
Mike Fiore 1:71125aa00e33 64 // compute the total number of surveys we will do
Mike Fiore 1:71125aa00e33 65 _points = generatePoints();
Mike Fiore 1:71125aa00e33 66 _survey_total = _points.size();
Mike Fiore 1:71125aa00e33 67 _survey_current = 1;
Mike Fiore 1:71125aa00e33 68 _survey_success = 0;
Mike Fiore 1:71125aa00e33 69 _survey_failure = 0;
Mike Fiore 1:71125aa00e33 70
Mike Fiore 1:71125aa00e33 71 // see if survey data file exists
Mike Fiore 1:71125aa00e33 72 std::vector<mDot::mdot_file> files = _dot->listUserFiles();
Mike Fiore 1:71125aa00e33 73 for (std::vector<mDot::mdot_file>::iterator it = files.begin(); it != files.end(); it++) {
Mike Fiore 1:71125aa00e33 74 if (strcmp(it->name, file_name) == 0) {
Mike Fiore 1:71125aa00e33 75 logInfo("found survey data file");
Mike Fiore 1:71125aa00e33 76 data_file = true;
Mike Fiore 1:71125aa00e33 77 break;
Mike Fiore 1:71125aa00e33 78 }
Mike Fiore 1:71125aa00e33 79 }
Mike Fiore 1:71125aa00e33 80 if (data_file) {
Mike Fiore 1:71125aa00e33 81 _state = check_file;
Mike Fiore 1:71125aa00e33 82 _file.display();
Mike Fiore 1:71125aa00e33 83 } else {
Mike Fiore 1:71125aa00e33 84 _state = show_help;
Mike Fiore 1:71125aa00e33 85 _index = 1;
Mike Fiore 1:71125aa00e33 86 displayHelp();
Mike Fiore 1:71125aa00e33 87 }
Mike Fiore 1:71125aa00e33 88
Mike Fiore 1:71125aa00e33 89 _display_timer.reset();
Mike Fiore 1:71125aa00e33 90
Mike Fiore 1:71125aa00e33 91 while (true) {
Mike Fiore 1:71125aa00e33 92 osEvent e = Thread::signal_wait(0, 250);
Mike Fiore 1:71125aa00e33 93 if (e.status == osEventSignal) {
Mike Fiore 1:71125aa00e33 94 if (e.value.signals & buttonSignal) {
Mike Fiore 1:71125aa00e33 95 _be = _buttons->getButtonEvent();
Mike Fiore 1:71125aa00e33 96
Mike Fiore 1:71125aa00e33 97 switch (_be) {
Mike Fiore 1:71125aa00e33 98 case ButtonHandler::sw1_press:
Mike Fiore 1:71125aa00e33 99 switch (_state) {
Mike Fiore 1:71125aa00e33 100 case check_file:
Mike Fiore 1:71125aa00e33 101 _state = show_help;
Mike Fiore 1:71125aa00e33 102 _index = getIndex(sweep) + 1;
Mike Fiore 1:71125aa00e33 103 displayHelp();
Mike Fiore 1:71125aa00e33 104 break;
Mike Fiore 1:71125aa00e33 105 case confirm:
Mike Fiore 1:71125aa00e33 106 _state = check_file;
Mike Fiore 1:71125aa00e33 107 _file.display();
Mike Fiore 1:71125aa00e33 108 break;
Mike Fiore 1:71125aa00e33 109 case success:
Mike Fiore 1:71125aa00e33 110 _state = complete;
Mike Fiore 1:71125aa00e33 111 _display_timer.stop();
Mike Fiore 1:71125aa00e33 112 _display_timer.reset();
Mike Fiore 1:71125aa00e33 113 logInfo("sweep finished");
Mike Fiore 1:71125aa00e33 114 _complete.display();
Mike Fiore 1:71125aa00e33 115 _complete.updateId(_index++);
Mike Fiore 1:71125aa00e33 116 _complete.updatePass(_survey_success);
Mike Fiore 1:71125aa00e33 117 _complete.updateFail(_survey_failure);
Mike Fiore 1:71125aa00e33 118 _survey_success = 0;
Mike Fiore 1:71125aa00e33 119 _survey_failure = 0;
Mike Fiore 1:71125aa00e33 120 break;
Mike Fiore 1:71125aa00e33 121 case failure:
Mike Fiore 1:71125aa00e33 122 _state = complete;
Mike Fiore 1:71125aa00e33 123 _display_timer.stop();
Mike Fiore 1:71125aa00e33 124 _display_timer.reset();
Mike Fiore 1:71125aa00e33 125 logInfo("sweep finished");
Mike Fiore 1:71125aa00e33 126 _complete.display();
Mike Fiore 1:71125aa00e33 127 _complete.updateId(_index++);
Mike Fiore 1:71125aa00e33 128 _complete.updatePass(_survey_success);
Mike Fiore 1:71125aa00e33 129 _complete.updateFail(_survey_failure);
Mike Fiore 1:71125aa00e33 130 _survey_success = 0;
Mike Fiore 1:71125aa00e33 131 _survey_failure = 0;
Mike Fiore 1:71125aa00e33 132 break;
Mike Fiore 1:71125aa00e33 133 }
Mike Fiore 1:71125aa00e33 134 break;
Mike Fiore 1:71125aa00e33 135
Mike Fiore 1:71125aa00e33 136 case ButtonHandler::sw2_press:
Mike Fiore 1:71125aa00e33 137 switch (_state) {
Mike Fiore 1:71125aa00e33 138 case check_file:
Mike Fiore 1:71125aa00e33 139 _state = confirm;
Mike Fiore 1:71125aa00e33 140 _confirm.display();
Mike Fiore 1:71125aa00e33 141 break;
Mike Fiore 1:71125aa00e33 142 case confirm:
Mike Fiore 1:71125aa00e33 143 _state = show_help;
Mike Fiore 1:71125aa00e33 144 logInfo("deleting survey data file");
Mike Fiore 1:71125aa00e33 145 _dot->deleteUserFile(file_name);
Mike Fiore 1:71125aa00e33 146 _index = 1;
Mike Fiore 1:71125aa00e33 147 displayHelp();
Mike Fiore 1:71125aa00e33 148 break;
Mike Fiore 1:71125aa00e33 149 case show_help:
Mike Fiore 1:71125aa00e33 150 _state = in_progress;
Mike Fiore 1:71125aa00e33 151 _progress.display();
Mike Fiore 1:71125aa00e33 152 _progress.updateProgress(_survey_current, _survey_total);
Mike Fiore 1:71125aa00e33 153 if (_dot->getNextTxMs() > 0)
Mike Fiore 1:71125aa00e33 154 no_channel_link_check = true;
Mike Fiore 1:71125aa00e33 155 else
Mike Fiore 1:71125aa00e33 156 send_link_check = true;
Mike Fiore 1:71125aa00e33 157 break;
Mike Fiore 1:71125aa00e33 158 case complete:
Mike Fiore 1:71125aa00e33 159 _state = in_progress;
Mike Fiore 1:71125aa00e33 160 _survey_current = 1;
Mike Fiore 1:71125aa00e33 161 _progress.display();
Mike Fiore 1:71125aa00e33 162 _progress.updateProgress(_survey_current, _survey_total);
Mike Fiore 1:71125aa00e33 163 if (_dot->getNextTxMs() > 0)
Mike Fiore 1:71125aa00e33 164 no_channel_link_check = true;
Mike Fiore 1:71125aa00e33 165 else
Mike Fiore 1:71125aa00e33 166 send_link_check = true;
Mike Fiore 1:71125aa00e33 167 break;
Mike Fiore 1:71125aa00e33 168 }
Mike Fiore 1:71125aa00e33 169 break;
Mike Fiore 1:71125aa00e33 170 case ButtonHandler::sw1_hold:
Mike Fiore 1:71125aa00e33 171 _dot->setTxDataRate(_initial_data_rate);
Mike Fiore 1:71125aa00e33 172 _dot->setTxPower(_initial_power);
Mike Fiore 1:71125aa00e33 173 return true;
Mike Fiore 1:71125aa00e33 174 }
Mike Fiore 1:71125aa00e33 175 }
Mike Fiore 1:71125aa00e33 176 if (e.value.signals & loraSignal) {
Mike Fiore 1:71125aa00e33 177 _ls = _lora->getStatus();
Mike Fiore 1:71125aa00e33 178 switch (_ls) {
Mike Fiore 1:71125aa00e33 179 case LoRaHandler::link_check_success:
Mike Fiore 1:71125aa00e33 180 switch (_state) {
Mike Fiore 1:71125aa00e33 181 case in_progress:
Mike Fiore 1:71125aa00e33 182 _survey_success++;
Mike Fiore 1:71125aa00e33 183 _link_check_result = _lora->getLinkCheckResults();
Mike Fiore 1:71125aa00e33 184 displaySuccess();
Mike Fiore 1:71125aa00e33 185 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 186 updateData(_data, sweep, true);
Mike Fiore 1:71125aa00e33 187 appendDataFile(_data);
Mike Fiore 1:71125aa00e33 188 if (_send_data) {
Mike Fiore 1:71125aa00e33 189 _state = data;
Mike Fiore 1:71125aa00e33 190 if (_dot->getNextTxMs() > 0)
Mike Fiore 1:71125aa00e33 191 no_channel_data = true;
Mike Fiore 1:71125aa00e33 192 else
Mike Fiore 1:71125aa00e33 193 send_data = true;
Mike Fiore 1:71125aa00e33 194 } else {
Mike Fiore 1:71125aa00e33 195 _state = success;
Mike Fiore 1:71125aa00e33 196 _success.updateSw1(" Cancel");
Mike Fiore 1:71125aa00e33 197 _display_timer.start();
Mike Fiore 1:71125aa00e33 198 }
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::link_check_failure:
Mike Fiore 1:71125aa00e33 204 switch (_state) {
Mike Fiore 1:71125aa00e33 205 case in_progress:
Mike Fiore 1:71125aa00e33 206 _survey_failure++;
Mike Fiore 1:71125aa00e33 207 _state = failure;
Mike Fiore 1:71125aa00e33 208 _failure.display();
Mike Fiore 1:71125aa00e33 209 _failure.updateId(_index);
Mike Fiore 7:a31236c2e75c 210 _failure.updateRate(_dot->DataRateStr(_data_rate).substr(2));
Mike Fiore 1:71125aa00e33 211 _failure.updatePower(_power);
Mike Fiore 1:71125aa00e33 212 if (_gps_available && _gps->getLockStatus()) {
Mike Fiore 1:71125aa00e33 213 GPSPARSER::latitude lat = _gps->getLatitude();
Mike Fiore 1:71125aa00e33 214 GPSPARSER::longitude lon = _gps->getLongitude();
Mike Fiore 1:71125aa00e33 215 _failure.updateGpsLatitude(lat);
Mike Fiore 1:71125aa00e33 216 _failure.updateGpsLongitude(lon);
Mike Fiore 1:71125aa00e33 217 } else {
Mike Fiore 1:71125aa00e33 218 _failure.updateGpsLatitude("No GPS Lock");
Mike Fiore 1:71125aa00e33 219 }
Mike Fiore 1:71125aa00e33 220 _failure.updatePassFail(_survey_success, _survey_failure);
Mike Fiore 1:71125aa00e33 221 _failure.updateSw1(" Cancel");
Mike Fiore 1:71125aa00e33 222 updateData(_data, sweep, false);
Mike Fiore 1:71125aa00e33 223 appendDataFile(_data);
Mike Fiore 1:71125aa00e33 224 logInfo("link check failed");
Mike Fiore 1:71125aa00e33 225 _display_timer.start();
Mike Fiore 1:71125aa00e33 226 break;
Mike Fiore 1:71125aa00e33 227 }
Mike Fiore 1:71125aa00e33 228 break;
Mike Fiore 1:71125aa00e33 229
Mike Fiore 1:71125aa00e33 230 case LoRaHandler::send_success:
Mike Fiore 1:71125aa00e33 231 switch (_state) {
Mike Fiore 1:71125aa00e33 232 case data:
Mike Fiore 1:71125aa00e33 233 _state = success;
Mike Fiore 1:71125aa00e33 234 _success.updateInfo(" ");
Mike Fiore 1:71125aa00e33 235 _success.updateSw1(" Cancel");
Mike Fiore 1:71125aa00e33 236 logInfo("data send success");
Mike Fiore 1:71125aa00e33 237 // turn acks and receive windows back on
Mike Fiore 1:71125aa00e33 238 _dot->setAck(1);
Mike Fiore 1:71125aa00e33 239 _dot->setTxWait(true);
Mike Fiore 1:71125aa00e33 240 _display_timer.start();
Mike Fiore 1:71125aa00e33 241 break;
Mike Fiore 1:71125aa00e33 242 }
Mike Fiore 1:71125aa00e33 243 break;
Mike Fiore 1:71125aa00e33 244
Mike Fiore 1:71125aa00e33 245 case LoRaHandler::send_failure:
Mike Fiore 1:71125aa00e33 246 switch (_state) {
Mike Fiore 1:71125aa00e33 247 case data:
Mike Fiore 1:71125aa00e33 248 _state = success;
Mike Fiore 1:71125aa00e33 249 _success.updateInfo(" ");
Mike Fiore 1:71125aa00e33 250 _success.updateSw1(" Cancel");
Mike Fiore 1:71125aa00e33 251 logInfo("data send failed");
Mike Fiore 1:71125aa00e33 252 // turn acks and receive windows back on
Mike Fiore 1:71125aa00e33 253 _dot->setAck(1);
Mike Fiore 1:71125aa00e33 254 _dot->setTxWait(true);
Mike Fiore 1:71125aa00e33 255 _display_timer.start();
Mike Fiore 1:71125aa00e33 256 break;
Mike Fiore 1:71125aa00e33 257 }
Mike Fiore 1:71125aa00e33 258 break;
Mike Fiore 1:71125aa00e33 259 }
Mike Fiore 1:71125aa00e33 260 }
Mike Fiore 1:71125aa00e33 261 }
Mike Fiore 1:71125aa00e33 262
Mike Fiore 1:71125aa00e33 263 // wait 5s in EU mode to compensate for potential "no free channel" situations on server
jenkins@jenkinsdm1 12:05435282f899 264 if ((lora::ChannelPlan::IsPlanDynamic(_band) && _dot->getChannelPlanName() == "EU868" && _display_timer.read_ms() > 2000) || _display_timer.read_ms() > 5000) {
Mike Fiore 1:71125aa00e33 265 _display_timer.stop();
Mike Fiore 1:71125aa00e33 266 _display_timer.reset();
Mike Fiore 1:71125aa00e33 267 if (_survey_current == _survey_total) {
Mike Fiore 1:71125aa00e33 268 logInfo("sweep finished");
Mike Fiore 1:71125aa00e33 269 _state = complete;
Mike Fiore 1:71125aa00e33 270 _complete.display();
Mike Fiore 1:71125aa00e33 271 _complete.updateId(_index++);
Mike Fiore 1:71125aa00e33 272 _complete.updatePass(_survey_success);
Mike Fiore 1:71125aa00e33 273 _complete.updateFail(_survey_failure);
Mike Fiore 1:71125aa00e33 274 _survey_success = 0;
Mike Fiore 1:71125aa00e33 275 _survey_failure = 0;
Mike Fiore 1:71125aa00e33 276 } else {
Mike Fiore 1:71125aa00e33 277 logInfo("starting next link check");
Mike Fiore 1:71125aa00e33 278 _state = in_progress;
Mike Fiore 1:71125aa00e33 279 _survey_current++;
Mike Fiore 1:71125aa00e33 280 _progress.display();
Mike Fiore 1:71125aa00e33 281 _progress.updateProgress(_survey_current, _survey_total);
Mike Fiore 1:71125aa00e33 282 no_channel_link_check = true;
Mike Fiore 1:71125aa00e33 283 }
Mike Fiore 1:71125aa00e33 284 }
Mike Fiore 1:71125aa00e33 285
Mike Fiore 1:71125aa00e33 286 if (no_channel_link_check) {
Mike Fiore 1:71125aa00e33 287 uint32_t t = _dot->getNextTxMs();
Mike Fiore 1:71125aa00e33 288 if (t > 0) {
Mike Fiore 1:71125aa00e33 289 logInfo("next tx %lu ms", t);
Mike Fiore 1:71125aa00e33 290 _progress.updateCountdown(t / 1000);
Mike Fiore 1:71125aa00e33 291 } else {
Mike Fiore 1:71125aa00e33 292 _progress.display();
Mike Fiore 1:71125aa00e33 293 _progress.updateProgress(_survey_current, _survey_total);
Mike Fiore 1:71125aa00e33 294 no_channel_link_check = false;
Mike Fiore 1:71125aa00e33 295 send_link_check = true;
Mike Fiore 1:71125aa00e33 296 }
Mike Fiore 1:71125aa00e33 297 }
Mike Fiore 1:71125aa00e33 298 if (no_channel_data) {
Mike Fiore 1:71125aa00e33 299 uint32_t t = _dot->getNextTxMs();
Mike Fiore 1:71125aa00e33 300 if (t > 0) {
Mike Fiore 1:71125aa00e33 301 logInfo("next tx %lu ms", t);
Mike Fiore 1:71125aa00e33 302 _success.updateCountdown(t / 1000);
Mike Fiore 1:71125aa00e33 303 } else {
Mike Fiore 1:71125aa00e33 304 displaySuccess();
Mike Fiore 1:71125aa00e33 305 no_channel_data = false;
Mike Fiore 1:71125aa00e33 306 send_data = true;
Mike Fiore 1:71125aa00e33 307 }
Mike Fiore 1:71125aa00e33 308 }
Mike Fiore 1:71125aa00e33 309 if (send_link_check) {
Mike Fiore 1:71125aa00e33 310 point p = _points[_survey_current - 1];
Mike Fiore 1:71125aa00e33 311 _data_rate = p.first;
Mike Fiore 1:71125aa00e33 312 _power = p.second;
Mike Fiore 1:71125aa00e33 313 logInfo("sending link check %s %d", _dot->DataRateStr(_data_rate).c_str(), _power);
Mike Fiore 1:71125aa00e33 314 send_link_check = false;
Mike Fiore 1:71125aa00e33 315 _dot->setTxDataRate(_data_rate);
Mike Fiore 1:71125aa00e33 316 _dot->setTxPower(_power);
Mike Fiore 1:71125aa00e33 317 _lora->linkCheck();
Mike Fiore 1:71125aa00e33 318 }
Mike Fiore 1:71125aa00e33 319 if (send_data) {
Mike Fiore 1:71125aa00e33 320 std::vector<uint8_t> s_data = formatSurveyData(_data);
Mike Fiore 1:71125aa00e33 321 logInfo("sending data %s %d", _dot->DataRateStr(_data_rate).c_str(), _power);
Mike Fiore 1:71125aa00e33 322 send_data = false;
Mike Fiore 1:71125aa00e33 323 _success.updateInfo("Data Sending...");
Mike Fiore 1:71125aa00e33 324 _dot->setTxDataRate(_data_rate);
Mike Fiore 1:71125aa00e33 325 _dot->setTxPower(_power);
Mike Fiore 1:71125aa00e33 326 // we don't care if the server actually gets this packet or not
Mike Fiore 1:71125aa00e33 327 // we won't retry anyway
Mike Fiore 1:71125aa00e33 328 _dot->setAck(0);
Mike Fiore 1:71125aa00e33 329 _dot->setTxWait(false);
Mike Fiore 1:71125aa00e33 330 _lora->send(s_data);
Mike Fiore 1:71125aa00e33 331 osDelay(500);
Mike Fiore 1:71125aa00e33 332 }
Mike Fiore 1:71125aa00e33 333 }
Mike Fiore 1:71125aa00e33 334 }
Mike Fiore 1:71125aa00e33 335
Mike Fiore 1:71125aa00e33 336 void ModeSweep::displayHelp() {
Mike Fiore 1:71125aa00e33 337 _help.display();
Mike Fiore 1:71125aa00e33 338 _help.updateMode("Survey Sweep");
Mike Fiore 1:71125aa00e33 339 _help.updateSw2("Sweep");
Mike Fiore 1:71125aa00e33 340 }
Mike Fiore 1:71125aa00e33 341
Mike Fiore 1:71125aa00e33 342 void ModeSweep::displaySuccess() {
Mike Fiore 1:71125aa00e33 343 _success.display();
Mike Fiore 1:71125aa00e33 344 _success.updateId(_index);
Mike Fiore 7:a31236c2e75c 345 _success.updateRate(_dot->DataRateStr(_data_rate).substr(2));
Mike Fiore 1:71125aa00e33 346 _success.updatePower(_power);
Mike Fiore 1:71125aa00e33 347 _success.updateStats(_link_check_result);
Mike Fiore 1:71125aa00e33 348 if (_gps_available && _gps->getLockStatus()) {
Mike Fiore 1:71125aa00e33 349 GPSPARSER::latitude lat = _gps->getLatitude();
Mike Fiore 1:71125aa00e33 350 GPSPARSER::longitude lon = _gps->getLongitude();
Mike Fiore 1:71125aa00e33 351 _success.updateGpsLatitude(lat);
Mike Fiore 1:71125aa00e33 352 _success.updateGpsLongitude(lon);
Mike Fiore 1:71125aa00e33 353 } else {
Mike Fiore 1:71125aa00e33 354 _success.updateGpsLatitude("No GPS Lock");
Mike Fiore 1:71125aa00e33 355 }
Mike Fiore 1:71125aa00e33 356 _success.updatePassFail(_survey_success, _survey_failure);
Mike Fiore 1:71125aa00e33 357 }
Mike Fiore 1:71125aa00e33 358
Mike Fiore 1:71125aa00e33 359 std::vector<point> ModeSweep::generatePoints() {
Mike Fiore 1:71125aa00e33 360 std::vector<point> p;
Mike Fiore 1:71125aa00e33 361 uint8_t min_rate;
Mike Fiore 1:71125aa00e33 362 uint8_t max_rate;
Mike Fiore 1:71125aa00e33 363
jenkins@jenkinsdm1 12:05435282f899 364 max_rate = payloadToRate(_min_payload, false);
jenkins@jenkinsdm1 12:05435282f899 365 min_rate = payloadToRate(_max_payload, true);
Mike Fiore 1:71125aa00e33 366
jenkins@jenkinsdm1 12:05435282f899 367 for (int rate = max_rate; rate <= min_rate; rate++) {
Mike Fiore 1:71125aa00e33 368 if (_max_power - _min_power < 4) {
jenkins@jenkinsdm1 12:05435282f899 369 for (uint32_t power = _max_power; power >= _min_power; power--)
Mike Fiore 1:71125aa00e33 370 p.push_back(std::make_pair(rate, power));
Mike Fiore 1:71125aa00e33 371 } else {
jenkins@jenkinsdm1 12:05435282f899 372 p.push_back(std::make_pair(rate, _max_power));
jenkins@jenkinsdm1 12:05435282f899 373 p.push_back(std::make_pair(rate, (uint32_t)ceil( (float(_max_power) - float(_min_power)) * 0.66 + float(_min_power))));
Mike Fiore 1:71125aa00e33 374 p.push_back(std::make_pair(rate, (uint32_t)ceil( (float(_max_power) - float(_min_power)) * 0.33 + float(_min_power))));
jenkins@jenkinsdm1 12:05435282f899 375 p.push_back(std::make_pair(rate, _min_power));
Mike Fiore 1:71125aa00e33 376 }
Mike Fiore 1:71125aa00e33 377 }
Mike Fiore 1:71125aa00e33 378
Mike Fiore 1:71125aa00e33 379 return p;
Mike Fiore 1:71125aa00e33 380 }
Mike Fiore 1:71125aa00e33 381
jenkins@jenkinsdm1 12:05435282f899 382 uint8_t ModeSweep::payloadToRate(uint8_t payload, bool max) {
jenkins@jenkinsdm1 12:05435282f899 383 uint8_t ret = 0;
jenkins@jenkinsdm1 12:05435282f899 384 uint8_t tmp = 0;
jenkins@jenkinsdm1 12:05435282f899 385 if(!max) {
jenkins@jenkinsdm1 12:05435282f899 386 for(uint8_t i = _dot->getMinDatarate(); i < _dot->getMaxDatarate(); i++) {
jenkins@jenkinsdm1 12:05435282f899 387 _dot->setTxDataRate(i);
jenkins@jenkinsdm1 12:05435282f899 388 if(payload <= _dot->getMaxPacketLength()) {
jenkins@jenkinsdm1 12:05435282f899 389 ret = i;
jenkins@jenkinsdm1 12:05435282f899 390 tmp = _dot->getMaxPacketLength();
jenkins@jenkinsdm1 12:05435282f899 391 i = _dot->getMaxDatarate();
jenkins@jenkinsdm1 12:05435282f899 392 }
jenkins@jenkinsdm1 12:05435282f899 393 }
Mike Fiore 1:71125aa00e33 394 } else {
jenkins@jenkinsdm1 12:05435282f899 395 //This may or may not work for some channel plans
jenkins@jenkinsdm1 12:05435282f899 396 for(uint8_t i = _dot->getMaxDatarate(); i > _dot->getMinDatarate(); i--) {
jenkins@jenkinsdm1 12:05435282f899 397 _dot->setTxDataRate(i);
jenkins@jenkinsdm1 12:05435282f899 398 if(payload <= _dot->getMaxPacketLength()) {
jenkins@jenkinsdm1 12:05435282f899 399 ret = i;
jenkins@jenkinsdm1 12:05435282f899 400 tmp = _dot->getMaxPacketLength();
jenkins@jenkinsdm1 12:05435282f899 401 }
jenkins@jenkinsdm1 12:05435282f899 402 }
jenkins@jenkinsdm1 12:05435282f899 403 _dot->setTxDataRate(_dot->getMaxDatarate());
jenkins@jenkinsdm1 12:05435282f899 404 if(tmp == _dot->getMaxPacketLength()) {
jenkins@jenkinsdm1 12:05435282f899 405 for(uint8_t i = _dot->getMaxDatarate(); i > _dot->getMinDatarate(); i--) {
jenkins@jenkinsdm1 12:05435282f899 406 _dot->setTxDataRate(i);
jenkins@jenkinsdm1 12:05435282f899 407 if(_dot->getChannelPlan()->GetDatarate(i).SpreadingFactor != lora::SF_FSK) {
jenkins@jenkinsdm1 12:05435282f899 408 return i;
jenkins@jenkinsdm1 12:05435282f899 409 }
jenkins@jenkinsdm1 12:05435282f899 410 }
jenkins@jenkinsdm1 12:05435282f899 411 }
Mike Fiore 1:71125aa00e33 412 }
jenkins@jenkinsdm1 12:05435282f899 413 return ret;
Mike Fiore 1:71125aa00e33 414 }
Mike Fiore 1:71125aa00e33 415