MTDOT-BOX-EVB-Factory-Firmware

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

Committer:
Mike Fiore
Date:
Thu Feb 04 12:36:36 2016 -0600
Revision:
1:71125aa00e33
Child:
7:a31236c2e75c
add rest of source - version 2.0.0

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 "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
Mike Fiore 1:71125aa00e33 44 _initial_data_rate = _dot->getTxDataRate();
Mike Fiore 1:71125aa00e33 45 _initial_power = _dot->getTxPower();
Mike Fiore 1:71125aa00e33 46
Mike Fiore 1:71125aa00e33 47 // see if we're supposed to send the data packet after success
Mike Fiore 1:71125aa00e33 48 // that item is stored in the mDot::StartUpMode config field
Mike Fiore 1:71125aa00e33 49 _send_data = _dot->getStartUpMode();
Mike Fiore 1:71125aa00e33 50
Mike Fiore 1:71125aa00e33 51 // see if survey data file exists
Mike Fiore 1:71125aa00e33 52 std::vector<mDot::mdot_file> files = _dot->listUserFiles();
Mike Fiore 1:71125aa00e33 53 for (std::vector<mDot::mdot_file>::iterator it = files.begin(); it != files.end(); it++) {
Mike Fiore 1:71125aa00e33 54 if (strcmp(it->name, file_name) == 0) {
Mike Fiore 1:71125aa00e33 55 logInfo("found survey data file");
Mike Fiore 1:71125aa00e33 56 data_file = true;
Mike Fiore 1:71125aa00e33 57 break;
Mike Fiore 1:71125aa00e33 58 }
Mike Fiore 1:71125aa00e33 59 }
Mike Fiore 1:71125aa00e33 60 if (data_file) {
Mike Fiore 1:71125aa00e33 61 _state = check_file;
Mike Fiore 1:71125aa00e33 62 _file.display();
Mike Fiore 1:71125aa00e33 63 } else {
Mike Fiore 1:71125aa00e33 64 _state = show_help;
Mike Fiore 1:71125aa00e33 65 _index = 0;
Mike Fiore 1:71125aa00e33 66 displayHelp();
Mike Fiore 1:71125aa00e33 67 }
Mike Fiore 1:71125aa00e33 68
Mike Fiore 1:71125aa00e33 69 while (true) {
Mike Fiore 1:71125aa00e33 70 osEvent e = Thread::signal_wait(0, 250);
Mike Fiore 1:71125aa00e33 71 if (e.status == osEventSignal) {
Mike Fiore 1:71125aa00e33 72 if (e.value.signals & buttonSignal) {
Mike Fiore 1:71125aa00e33 73 _be = _buttons->getButtonEvent();
Mike Fiore 1:71125aa00e33 74
Mike Fiore 1:71125aa00e33 75 switch (_be) {
Mike Fiore 1:71125aa00e33 76 case ButtonHandler::sw1_press:
Mike Fiore 1:71125aa00e33 77 switch (_state) {
Mike Fiore 1:71125aa00e33 78 case check_file:
Mike Fiore 1:71125aa00e33 79 _state = show_help;
Mike Fiore 1:71125aa00e33 80 _index = getIndex(single);
Mike Fiore 1:71125aa00e33 81 displayHelp();
Mike Fiore 1:71125aa00e33 82 break;
Mike Fiore 1:71125aa00e33 83 case confirm:
Mike Fiore 1:71125aa00e33 84 _state = check_file;
Mike Fiore 1:71125aa00e33 85 _file.display();
Mike Fiore 1:71125aa00e33 86 break;
Mike Fiore 1:71125aa00e33 87 case show_help:
Mike Fiore 1:71125aa00e33 88 incrementRatePower();
Mike Fiore 1:71125aa00e33 89 _help.updateMsg(formatRatePower());
Mike Fiore 1:71125aa00e33 90 break;
Mike Fiore 1:71125aa00e33 91 case success:
Mike Fiore 1:71125aa00e33 92 incrementRatePower();
Mike Fiore 1:71125aa00e33 93 _success.updateInfo(formatRatePower());
Mike Fiore 1:71125aa00e33 94 break;
Mike Fiore 1:71125aa00e33 95 case failure:
Mike Fiore 1:71125aa00e33 96 incrementRatePower();
Mike Fiore 1:71125aa00e33 97 _failure.updateInfo(formatRatePower());
Mike Fiore 1:71125aa00e33 98 break;
Mike Fiore 1:71125aa00e33 99 }
Mike Fiore 1:71125aa00e33 100 break;
Mike Fiore 1:71125aa00e33 101
Mike Fiore 1:71125aa00e33 102 case ButtonHandler::sw2_press:
Mike Fiore 1:71125aa00e33 103 switch (_state) {
Mike Fiore 1:71125aa00e33 104 case check_file:
Mike Fiore 1:71125aa00e33 105 _state = confirm;
Mike Fiore 1:71125aa00e33 106 _confirm.display();
Mike Fiore 1:71125aa00e33 107 break;
Mike Fiore 1:71125aa00e33 108 case confirm:
Mike Fiore 1:71125aa00e33 109 _state = show_help;
Mike Fiore 1:71125aa00e33 110 logInfo("deleting survey data file");
Mike Fiore 1:71125aa00e33 111 _dot->deleteUserFile(file_name);
Mike Fiore 1:71125aa00e33 112 _index = 0;
Mike Fiore 1:71125aa00e33 113 displayHelp();
Mike Fiore 1:71125aa00e33 114 break;
Mike Fiore 1:71125aa00e33 115 case show_help:
Mike Fiore 1:71125aa00e33 116 _state = in_progress;
Mike Fiore 1:71125aa00e33 117 _progress.display();
Mike Fiore 1:71125aa00e33 118 if (_dot->getNextTxMs() > 0)
Mike Fiore 1:71125aa00e33 119 no_channel_link_check = true;
Mike Fiore 1:71125aa00e33 120 else
Mike Fiore 1:71125aa00e33 121 send_link_check = true;
Mike Fiore 1:71125aa00e33 122 break;
Mike Fiore 1:71125aa00e33 123 case success:
Mike Fiore 1:71125aa00e33 124 _state = in_progress;
Mike Fiore 1:71125aa00e33 125 _progress.display();
Mike Fiore 1:71125aa00e33 126 if (_dot->getNextTxMs() > 0)
Mike Fiore 1:71125aa00e33 127 no_channel_link_check = true;
Mike Fiore 1:71125aa00e33 128 else
Mike Fiore 1:71125aa00e33 129 send_link_check = true;
Mike Fiore 1:71125aa00e33 130 break;
Mike Fiore 1:71125aa00e33 131 case failure:
Mike Fiore 1:71125aa00e33 132 _state = in_progress;
Mike Fiore 1:71125aa00e33 133 _progress.display();
Mike Fiore 1:71125aa00e33 134 if (_dot->getNextTxMs() > 0)
Mike Fiore 1:71125aa00e33 135 no_channel_link_check = true;
Mike Fiore 1:71125aa00e33 136 else
Mike Fiore 1:71125aa00e33 137 send_link_check = true;
Mike Fiore 1:71125aa00e33 138 break;
Mike Fiore 1:71125aa00e33 139 }
Mike Fiore 1:71125aa00e33 140 break;
Mike Fiore 1:71125aa00e33 141 case ButtonHandler::sw1_hold:
Mike Fiore 1:71125aa00e33 142 _dot->setTxDataRate(_initial_data_rate);
Mike Fiore 1:71125aa00e33 143 _dot->setTxPower(_initial_power);
Mike Fiore 1:71125aa00e33 144 return true;
Mike Fiore 1:71125aa00e33 145 }
Mike Fiore 1:71125aa00e33 146 }
Mike Fiore 1:71125aa00e33 147 if (e.value.signals & loraSignal) {
Mike Fiore 1:71125aa00e33 148 _ls = _lora->getStatus();
Mike Fiore 1:71125aa00e33 149 switch (_ls) {
Mike Fiore 1:71125aa00e33 150 case LoRaHandler::link_check_success:
Mike Fiore 1:71125aa00e33 151 switch (_state) {
Mike Fiore 1:71125aa00e33 152 case in_progress:
Mike Fiore 1:71125aa00e33 153 _link_check_result = _lora->getLinkCheckResults();
Mike Fiore 1:71125aa00e33 154 displaySuccess();
Mike Fiore 1:71125aa00e33 155 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 156 updateData(_data, single, true);
Mike Fiore 1:71125aa00e33 157 appendDataFile(_data);
Mike Fiore 1:71125aa00e33 158 if (_send_data) {
Mike Fiore 1:71125aa00e33 159 _state = data;
Mike Fiore 1:71125aa00e33 160 if (_dot->getNextTxMs() > 0)
Mike Fiore 1:71125aa00e33 161 no_channel_data = true;
Mike Fiore 1:71125aa00e33 162 else
Mike Fiore 1:71125aa00e33 163 send_data = true;
Mike Fiore 1:71125aa00e33 164 } else {
Mike Fiore 1:71125aa00e33 165 _state = success;
Mike Fiore 1:71125aa00e33 166 _success.updateSw1(" DR/PWR");
Mike Fiore 1:71125aa00e33 167 _success.updateSw2("Survey");
Mike Fiore 1:71125aa00e33 168 }
Mike Fiore 1:71125aa00e33 169 break;
Mike Fiore 1:71125aa00e33 170 }
Mike Fiore 1:71125aa00e33 171 break;
Mike Fiore 1:71125aa00e33 172
Mike Fiore 1:71125aa00e33 173 case LoRaHandler::link_check_failure:
Mike Fiore 1:71125aa00e33 174 switch (_state) {
Mike Fiore 1:71125aa00e33 175 case in_progress:
Mike Fiore 1:71125aa00e33 176 _state = failure;
Mike Fiore 1:71125aa00e33 177 _failure.display();
Mike Fiore 1:71125aa00e33 178 _failure.updateId(_index);
Mike Fiore 1:71125aa00e33 179 // mDot::DataRateStr returns format SF_XX - we only want to display the XX part
Mike Fiore 1:71125aa00e33 180 _failure.updateRate(_dot->DataRateStr(_data_rate).substr(3));
Mike Fiore 1:71125aa00e33 181 updateData(_data, single, false);
Mike Fiore 1:71125aa00e33 182 appendDataFile(_data);
Mike Fiore 1:71125aa00e33 183 _failure.updatePower(_power);
Mike Fiore 1:71125aa00e33 184 if (_gps_available && _gps->getLockStatus()) {
Mike Fiore 1:71125aa00e33 185 GPSPARSER::latitude lat = _gps->getLatitude();
Mike Fiore 1:71125aa00e33 186 GPSPARSER::longitude lon = _gps->getLongitude();
Mike Fiore 1:71125aa00e33 187 struct tm time = _gps->getTimestamp();
Mike Fiore 1:71125aa00e33 188 _failure.updateGpsLatitude(lat);
Mike Fiore 1:71125aa00e33 189 _failure.updateGpsLongitude(lon);
Mike Fiore 1:71125aa00e33 190 _failure.updateGpsTime(time);
Mike Fiore 1:71125aa00e33 191 } else {
Mike Fiore 1:71125aa00e33 192 _failure.updateGpsLatitude("No GPS Lock");
Mike Fiore 1:71125aa00e33 193 }
Mike Fiore 1:71125aa00e33 194 _failure.updateSw1(" DR/PWR");
Mike Fiore 1:71125aa00e33 195 _failure.updateSw2("Survey");
Mike Fiore 1:71125aa00e33 196 logInfo("link check failed");
Mike Fiore 1:71125aa00e33 197 break;
Mike Fiore 1:71125aa00e33 198 }
Mike Fiore 1:71125aa00e33 199 break;
Mike Fiore 1:71125aa00e33 200
Mike Fiore 1:71125aa00e33 201 case LoRaHandler::send_success:
Mike Fiore 1:71125aa00e33 202 switch (_state) {
Mike Fiore 1:71125aa00e33 203 case data:
Mike Fiore 1:71125aa00e33 204 _state = success;
Mike Fiore 1:71125aa00e33 205 _success.updateInfo(" ");
Mike Fiore 1:71125aa00e33 206 _success.updateSw1(" DR/PWR");
Mike Fiore 1:71125aa00e33 207 _success.updateSw2("Survey");
Mike Fiore 1:71125aa00e33 208 // turn acks and receive windows back on
Mike Fiore 1:71125aa00e33 209 _dot->setAck(1);
Mike Fiore 1:71125aa00e33 210 _dot->setTxWait(true);
Mike Fiore 1:71125aa00e33 211 logInfo("data send success");
Mike Fiore 1:71125aa00e33 212 break;
Mike Fiore 1:71125aa00e33 213 }
Mike Fiore 1:71125aa00e33 214 break;
Mike Fiore 1:71125aa00e33 215
Mike Fiore 1:71125aa00e33 216 case LoRaHandler::send_failure:
Mike Fiore 1:71125aa00e33 217 switch (_state) {
Mike Fiore 1:71125aa00e33 218 case data:
Mike Fiore 1:71125aa00e33 219 _state = success;
Mike Fiore 1:71125aa00e33 220 _success.updateInfo(" ");
Mike Fiore 1:71125aa00e33 221 _success.updateSw1(" DR/PWR");
Mike Fiore 1:71125aa00e33 222 _success.updateSw2("Survey");
Mike Fiore 1:71125aa00e33 223 // turn acks and receive windows back on
Mike Fiore 1:71125aa00e33 224 _dot->setAck(1);
Mike Fiore 1:71125aa00e33 225 _dot->setTxWait(true);
Mike Fiore 1:71125aa00e33 226 logInfo("data send failed");
Mike Fiore 1:71125aa00e33 227 break;
Mike Fiore 1:71125aa00e33 228 }
Mike Fiore 1:71125aa00e33 229 break;
Mike Fiore 1:71125aa00e33 230 }
Mike Fiore 1:71125aa00e33 231 }
Mike Fiore 1:71125aa00e33 232 }
Mike Fiore 1:71125aa00e33 233
Mike Fiore 1:71125aa00e33 234 if (no_channel_link_check) {
Mike Fiore 1:71125aa00e33 235 uint32_t t = _dot->getNextTxMs();
Mike Fiore 1:71125aa00e33 236 if (t > 0) {
Mike Fiore 1:71125aa00e33 237 logInfo("next tx %lu ms", t);
Mike Fiore 1:71125aa00e33 238 _progress.updateCountdown(t / 1000);
Mike Fiore 1:71125aa00e33 239 } else {
Mike Fiore 1:71125aa00e33 240 _progress.display();
Mike Fiore 1:71125aa00e33 241 no_channel_link_check = false;
Mike Fiore 1:71125aa00e33 242 send_link_check = true;
Mike Fiore 1:71125aa00e33 243 }
Mike Fiore 1:71125aa00e33 244 }
Mike Fiore 1:71125aa00e33 245 if (no_channel_data) {
Mike Fiore 1:71125aa00e33 246 uint32_t t = _dot->getNextTxMs();
Mike Fiore 1:71125aa00e33 247 if (t > 0) {
Mike Fiore 1:71125aa00e33 248 logInfo("next tx %lu ms", t);
Mike Fiore 1:71125aa00e33 249 _success.updateCountdown(t / 1000);
Mike Fiore 1:71125aa00e33 250 } else {
Mike Fiore 1:71125aa00e33 251 displaySuccess();
Mike Fiore 1:71125aa00e33 252 no_channel_data = false;
Mike Fiore 1:71125aa00e33 253 send_data = true;
Mike Fiore 1:71125aa00e33 254 }
Mike Fiore 1:71125aa00e33 255 }
Mike Fiore 1:71125aa00e33 256 if (send_link_check) {
Mike Fiore 1:71125aa00e33 257 logInfo("sending link check %s %d", _dot->DataRateStr(_data_rate).c_str(), _power);
Mike Fiore 1:71125aa00e33 258 send_link_check = false;
Mike Fiore 1:71125aa00e33 259 _dot->setTxDataRate(_data_rate);
Mike Fiore 1:71125aa00e33 260 _dot->setTxPower(_power);
Mike Fiore 1:71125aa00e33 261 _lora->linkCheck();
Mike Fiore 1:71125aa00e33 262 _index++;
Mike Fiore 1:71125aa00e33 263 }
Mike Fiore 1:71125aa00e33 264 if (send_data) {
Mike Fiore 1:71125aa00e33 265 std::vector<uint8_t> s_data = formatSurveyData(_data);
Mike Fiore 1:71125aa00e33 266 logInfo("sending data %s %d", _dot->DataRateStr(_data_rate).c_str(), _power);
Mike Fiore 1:71125aa00e33 267 send_data = false;
Mike Fiore 1:71125aa00e33 268 _success.updateInfo("Data Sending...");
Mike Fiore 1:71125aa00e33 269 _dot->setTxDataRate(_data_rate);
Mike Fiore 1:71125aa00e33 270 _dot->setTxPower(_power);
Mike Fiore 1:71125aa00e33 271 // we don't care if the server actually gets this packet or not
Mike Fiore 1:71125aa00e33 272 // we won't retry anyway
Mike Fiore 1:71125aa00e33 273 _dot->setAck(0);
Mike Fiore 1:71125aa00e33 274 _dot->setTxWait(false);
Mike Fiore 1:71125aa00e33 275 _lora->send(s_data);
Mike Fiore 1:71125aa00e33 276 osDelay(500);
Mike Fiore 1:71125aa00e33 277 }
Mike Fiore 1:71125aa00e33 278 }
Mike Fiore 1:71125aa00e33 279 }
Mike Fiore 1:71125aa00e33 280
Mike Fiore 1:71125aa00e33 281 void ModeSingle::displayHelp() {
Mike Fiore 1:71125aa00e33 282 _help.display();
Mike Fiore 1:71125aa00e33 283 _help.updateMode("Survey Single");
Mike Fiore 1:71125aa00e33 284 _help.updateSw1(" DR/PWR");
Mike Fiore 1:71125aa00e33 285 _help.updateSw2("Survey");
Mike Fiore 1:71125aa00e33 286 _help.updateMsg(formatRatePower());
Mike Fiore 1:71125aa00e33 287 }
Mike Fiore 1:71125aa00e33 288
Mike Fiore 1:71125aa00e33 289 void ModeSingle::displaySuccess() {
Mike Fiore 1:71125aa00e33 290 uint8_t fix = _gps->getFixStatus();
Mike Fiore 1:71125aa00e33 291 _success.display();
Mike Fiore 1:71125aa00e33 292 _success.updateId(_index);
Mike Fiore 1:71125aa00e33 293 // mDot::DataRateStr returns format SF_XX - we only want to display the XX part
Mike Fiore 1:71125aa00e33 294 _success.updateRate(_dot->DataRateStr(_data_rate).substr(3));
Mike Fiore 1:71125aa00e33 295 _success.updatePower(_power);
Mike Fiore 1:71125aa00e33 296 _success.updateStats(_link_check_result);
Mike Fiore 1:71125aa00e33 297 if (_gps_available && _gps->getLockStatus()) {
Mike Fiore 1:71125aa00e33 298 GPSPARSER::latitude lat = _gps->getLatitude();
Mike Fiore 1:71125aa00e33 299 GPSPARSER::longitude lon = _gps->getLongitude();
Mike Fiore 1:71125aa00e33 300 struct tm time = _gps->getTimestamp();
Mike Fiore 1:71125aa00e33 301 _success.updateGpsLatitude(lat);
Mike Fiore 1:71125aa00e33 302 _success.updateGpsLongitude(lon);
Mike Fiore 1:71125aa00e33 303 _success.updateGpsTime(time);
Mike Fiore 1:71125aa00e33 304 } else {
Mike Fiore 1:71125aa00e33 305 _success.updateGpsLatitude("No GPS Lock");
Mike Fiore 1:71125aa00e33 306 }
Mike Fiore 1:71125aa00e33 307 }
Mike Fiore 1:71125aa00e33 308
Mike Fiore 1:71125aa00e33 309 std::string ModeSingle::formatRatePower() {
Mike Fiore 1:71125aa00e33 310 std::string msg;
Mike Fiore 1:71125aa00e33 311 char buf[8];
Mike Fiore 1:71125aa00e33 312 size_t size;
Mike Fiore 1:71125aa00e33 313
Mike Fiore 1:71125aa00e33 314 msg += "DR=";
Mike Fiore 1:71125aa00e33 315 msg += _dot->DataRateStr(_data_rate).substr(3);
Mike Fiore 1:71125aa00e33 316 msg += " P=";
Mike Fiore 1:71125aa00e33 317 size = snprintf(buf, sizeof(buf), "%u", _power);
Mike Fiore 1:71125aa00e33 318 msg.append(buf, size);
Mike Fiore 1:71125aa00e33 319
Mike Fiore 1:71125aa00e33 320 return msg;
Mike Fiore 1:71125aa00e33 321 }
Mike Fiore 1:71125aa00e33 322
Mike Fiore 1:71125aa00e33 323 void ModeSingle::incrementRatePower() {
Mike Fiore 1:71125aa00e33 324 if (_power == 20) {
Mike Fiore 1:71125aa00e33 325 _power = 2;
Mike Fiore 1:71125aa00e33 326 switch (_data_rate) {
Mike Fiore 1:71125aa00e33 327 case mDot::SF_7:
Mike Fiore 1:71125aa00e33 328 _data_rate = mDot::SF_8;
Mike Fiore 1:71125aa00e33 329 break;
Mike Fiore 1:71125aa00e33 330 case mDot::SF_8:
Mike Fiore 1:71125aa00e33 331 _data_rate = mDot::SF_9;
Mike Fiore 1:71125aa00e33 332 break;
Mike Fiore 1:71125aa00e33 333 case mDot::SF_9:
Mike Fiore 1:71125aa00e33 334 _data_rate = mDot::SF_10;
Mike Fiore 1:71125aa00e33 335 break;
Mike Fiore 1:71125aa00e33 336 case mDot::SF_10:
Mike Fiore 1:71125aa00e33 337 if (_band == mDot::FB_915)
Mike Fiore 1:71125aa00e33 338 _data_rate = mDot::SF_7;
Mike Fiore 1:71125aa00e33 339 else
Mike Fiore 1:71125aa00e33 340 _data_rate = mDot::SF_11;
Mike Fiore 1:71125aa00e33 341 break;
Mike Fiore 1:71125aa00e33 342 case mDot::SF_11:
Mike Fiore 1:71125aa00e33 343 _data_rate = mDot::SF_12;
Mike Fiore 1:71125aa00e33 344 break;
Mike Fiore 1:71125aa00e33 345 case mDot::SF_12:
Mike Fiore 1:71125aa00e33 346 _data_rate = mDot::SF_7;
Mike Fiore 1:71125aa00e33 347 break;
Mike Fiore 1:71125aa00e33 348 }
Mike Fiore 1:71125aa00e33 349 } else {
Mike Fiore 1:71125aa00e33 350 _power += 3;
Mike Fiore 1:71125aa00e33 351 }
Mike Fiore 1:71125aa00e33 352
Mike Fiore 1:71125aa00e33 353 logInfo("new data rate %s, power %lu", mDot::DataRateStr(_data_rate).c_str(), _power);
Mike Fiore 1:71125aa00e33 354 }
Mike Fiore 1:71125aa00e33 355