MTDOT-BOX-EVB-Factory-Firmware
Dependencies: NCP5623B GpsParser ISL29011 libmDot-mbed5 MTS-Serial MMA845x DOGS102 MPL3115A2
Diff: Mode/ModeGps.cpp
- Revision:
- 12:05435282f899
- Parent:
- 7:a31236c2e75c
--- a/Mode/ModeGps.cpp Thu Nov 10 22:10:58 2016 +0000 +++ b/Mode/ModeGps.cpp Tue Oct 09 13:49:30 2018 -0500 @@ -32,7 +32,7 @@ {} string ModeGps::intToString(int num){ - char buf[3]; + char buf[4]; snprintf(buf, sizeof(buf), "%d", num); return buf; } @@ -48,14 +48,15 @@ _link_check = false; _GPS = false; _sub_band = _dot->getFrequencySubBand(); - _data_rate = mDot::DR0; + _data_rate = _dot->getMinDatarate(); + _dot->setTxDataRate(_data_rate); _max_padding = _dot->getMaxPacketLength() - PACKETSIZE; _Sw2 = "Power"; _Sw1 = intToString(_power); _help.display(); osDelay(2000); - if(_band == mDot::FB_EU868){ + if (lora::ChannelPlan::IsPlanDynamic(_band)) { _sem.display(_link_check, _snr, _rssi, _power, _sub_band, _padding, _data_rate); _sem.initial(); _state = PARAMETERS; @@ -67,9 +68,10 @@ void ModeGps::drIncrement(){ _data_rate++; - if ((_data_rate > mDot::DR4 && (_band == mDot::FB_US915 || _band == mDot::FB_AU915)) || _data_rate > mDot::DR6) { + //no fsk and japan data rates are different + if (_data_rate > _dot->getMaxDatarate() || _data_rate > mDot::DR6) { _drAll = true; - _data_rate = 0; + _data_rate = _dot->getMinDatarate(); } _dot->setTxDataRate(_data_rate); logInfo("new data rate %s, POWER %lu", mDot::DataRateStr(_data_rate).c_str(), _power); @@ -78,7 +80,7 @@ void ModeGps::changeDataRate(){ if(_drAll) { - _data_rate = -1; + _data_rate = _dot->getMinDatarate() - 1; _drAll = false; } drIncrement(); @@ -86,7 +88,7 @@ void ModeGps::changeParameter(){ _parameter++; - if(_band == mDot::FB_EU868 && _parameter == FSB){ + if(lora::ChannelPlan::IsPlanDynamic(_band) && _parameter == FSB){ _parameter++; } if(_parameter>INTERVAL){ @@ -239,12 +241,10 @@ void ModeGps::send(){ _state = SENDING; _send_timer.stop(); - if(_band == mDot::FB_EU868) { - while(_dot->getNextTxMs()>0) { - _sem.updateNextCh((int)(_dot->getNextTxMs()/1000)); - osDelay(250); - } - } + while(_dot->getNextTxMs()>0) { + _sem.updateNextCh((int)(_dot->getNextTxMs()/1000)); + osDelay(250); + } formatData(); _sem.sending(); _send_timer.reset(); @@ -257,21 +257,19 @@ init(); _button_timer.start(); ButtonHandler::ButtonEvent be; - osSignalClear(_main_id, buttonSignal | loraSignal); + uint32_t e; while (true) { if(_state==PARAMETERS){ updateScreen(); } - osEvent e = Thread::signal_wait(0, 250); - if (e.status == osEventSignal) { - if (e.value.signals & buttonSignal) { - _button_timer.reset(); - be = _buttons->getButtonEvent(); + e = osThreadFlagsWait(loraSignal | buttonSignal, osFlagsWaitAny, 250); + if (e == buttonSignal) { + be = _buttons->getButtonEvent(); - switch(be) { - case ButtonHandler::sw1_press: - switch(_state) { - case BAND_CHANGE: + switch(be) { + case ButtonHandler::sw1_press: + switch(_state) { + case BAND_CHANGE: setBand(); _sem_join.updateJoinFsb(_sub_band); break; @@ -313,9 +311,8 @@ default: break; } - } } - if (e.value.signals & loraSignal) { + if (e == loraSignal) { _ls = _lora->getStatus(); switch (_ls) { @@ -344,7 +341,21 @@ drIncrement(); } break; - + + case LoRaHandler::send_failure_payload: + _sem.sendResult("Payload too large"); + osDelay(1000); + _sem.sendResult("Change Datarate"); + osDelay(1000); + _link_check = false; + _button_timer.reset(); + _state = PARAMETERS; + _sem.display(_link_check, _snr, _rssi, _power, _sub_band, _padding, _data_rate); + if(_drAll){ + drIncrement(); + } + break; + default: break; }