Remaining style fixes

pull/7191/head
Hasnain Virk 2018-06-12 15:11:09 +03:00
parent 27290bb12f
commit d335f82440
4 changed files with 172 additions and 172 deletions

View File

@ -68,7 +68,7 @@ using namespace events;
* Constructor * * Constructor *
****************************************************************************/ ****************************************************************************/
LoRaWANStack::LoRaWANStack() LoRaWANStack::LoRaWANStack()
: _loramac(), : _loramac(),
_device_current_state(DEVICE_STATE_NOT_INITIALIZED), _device_current_state(DEVICE_STATE_NOT_INITIALIZED),
_lw_session(), _lw_session(),
_tx_msg(), _tx_msg(),
@ -481,7 +481,7 @@ lorawan_status_t LoRaWANStack::acquire_rx_metadata(lorawan_rx_metadata &metadata
return LORAWAN_STATUS_METADATA_NOT_AVAILABLE; return LORAWAN_STATUS_METADATA_NOT_AVAILABLE;
} }
lorawan_status_t LoRaWANStack::acquire_backoff_metadata(int& backoff) lorawan_status_t LoRaWANStack::acquire_backoff_metadata(int &backoff)
{ {
if (DEVICE_STATE_NOT_INITIALIZED == _device_current_state) { if (DEVICE_STATE_NOT_INITIALIZED == _device_current_state) {
return LORAWAN_STATUS_NOT_INITIALIZED; return LORAWAN_STATUS_NOT_INITIALIZED;
@ -1362,8 +1362,10 @@ void LoRaWANStack::compliance_test_handler(loramac_mcps_indication_t *mcps_indic
} else if (mcps_indication->buffer_size == 7) { } else if (mcps_indication->buffer_size == 7) {
loramac_mlme_req_t mlme_req; loramac_mlme_req_t mlme_req;
mlme_req.type = MLME_TXCW_1; mlme_req.type = MLME_TXCW_1;
mlme_req.cw_tx_mode.timeout = (uint16_t)((mcps_indication->buffer[1] << 8) | mcps_indication->buffer[2]); mlme_req.cw_tx_mode.timeout = (uint16_t)((mcps_indication->buffer[1] << 8)
mlme_req.cw_tx_mode.frequency = (uint32_t)((mcps_indication->buffer[3] << 16) | (mcps_indication->buffer[4] << 8) | mcps_indication->buffer[2]);
mlme_req.cw_tx_mode.frequency = (uint32_t)((mcps_indication->buffer[3] << 16)
| (mcps_indication->buffer[4] << 8)
| mcps_indication->buffer[5]) * 100; | mcps_indication->buffer[5]) * 100;
mlme_req.cw_tx_mode.power = mcps_indication->buffer[6]; mlme_req.cw_tx_mode.power = mcps_indication->buffer[6];
_loramac.mlme_request(&mlme_req); _loramac.mlme_request(&mlme_req);

View File

@ -284,7 +284,7 @@ void LoRaMac::check_frame_size(uint16_t size)
uint8_t value = _lora_phy.get_max_payload(_mcps_indication.rx_datarate, uint8_t value = _lora_phy.get_max_payload(_mcps_indication.rx_datarate,
_params.is_repeater_supported); _params.is_repeater_supported);
if (MAX(0, (int16_t) ((int16_t)size - (int16_t)LORA_MAC_FRMPAYLOAD_OVERHEAD)) if (MAX(0, (int16_t)((int16_t)size - (int16_t)LORA_MAC_FRMPAYLOAD_OVERHEAD))
> (int32_t) value) { > (int32_t) value) {
tr_error("Invalid frame size"); tr_error("Invalid frame size");
} }
@ -312,7 +312,7 @@ bool LoRaMac::message_integrity_check(const uint8_t *const payload,
mic_rx |= ((uint32_t) payload[size - LORAMAC_MFR_LEN + 2] << 16); mic_rx |= ((uint32_t) payload[size - LORAMAC_MFR_LEN + 2] << 16);
mic_rx |= ((uint32_t) payload[size - LORAMAC_MFR_LEN + 3] << 24); mic_rx |= ((uint32_t) payload[size - LORAMAC_MFR_LEN + 3] << 24);
sequence_counter_prev = (uint16_t) *downlink_counter; sequence_counter_prev = (uint16_t)*downlink_counter;
sequence_counter_diff = sequence_counter - sequence_counter_prev; sequence_counter_diff = sequence_counter - sequence_counter_prev;
*downlink_counter += sequence_counter_diff; *downlink_counter += sequence_counter_diff;
if (sequence_counter < sequence_counter_prev) { if (sequence_counter < sequence_counter_prev) {
@ -417,7 +417,7 @@ void LoRaMac::extract_data_and_mac_commands(const uint8_t *payload,
if (_lora_crypto.decrypt_payload(payload + payload_start_index, if (_lora_crypto.decrypt_payload(payload + payload_start_index,
frame_len, frame_len,
app_skey, app_skey,
sizeof(_params.keys.app_skey)*8, sizeof(_params.keys.app_skey) * 8,
address, address,
DOWN_LINK, DOWN_LINK,
downlink_counter, downlink_counter,
@ -638,7 +638,7 @@ void LoRaMac::on_radio_tx_done(lorawan_time_t timestamp)
_lora_phy.put_radio_to_sleep(); _lora_phy.put_radio_to_sleep();
} }
if(_params.is_rx_window_enabled == true) { if (_params.is_rx_window_enabled == true) {
lorawan_time_t time_diff = _lora_time.get_current_time() - timestamp; lorawan_time_t time_diff = _lora_time.get_current_time() - timestamp;
// start timer after which rx1_window will get opened // start timer after which rx1_window will get opened
_lora_time.start(_params.timers.rx_window1_timer, _lora_time.start(_params.timers.rx_window1_timer,
@ -800,8 +800,8 @@ lorawan_status_t LoRaMac::send_join_request()
loramac_mhdr_t mac_hdr; loramac_mhdr_t mac_hdr;
loramac_frame_ctrl_t fctrl; loramac_frame_ctrl_t fctrl;
_params.sys_params.channel_data_rate = _lora_phy.get_alternate_DR( _params.sys_params.channel_data_rate =
_params.join_request_trial_counter + 1); _lora_phy.get_alternate_DR(_params.join_request_trial_counter + 1);
mac_hdr.value = 0; mac_hdr.value = 0;
mac_hdr.bits.mtype = FRAME_TYPE_JOIN_REQ; mac_hdr.bits.mtype = FRAME_TYPE_JOIN_REQ;
@ -846,7 +846,7 @@ void LoRaMac::on_backoff_timer_expiry(void)
{ {
Lock lock(*this); Lock lock(*this);
lorawan_status_t status = schedule_tx(); lorawan_status_t status = schedule_tx();
MBED_ASSERT(status==LORAWAN_STATUS_OK); MBED_ASSERT(status == LORAWAN_STATUS_OK);
(void) status; (void) status;
} }
@ -950,7 +950,7 @@ void LoRaMac::on_ack_timeout_timer_event(void)
// now that is a critical failure // now that is a critical failure
lorawan_status_t status = handle_retransmission(); lorawan_status_t status = handle_retransmission();
MBED_ASSERT(status==LORAWAN_STATUS_OK); MBED_ASSERT(status == LORAWAN_STATUS_OK);
(void) status; (void) status;
} }
@ -1551,8 +1551,7 @@ lorawan_status_t LoRaMac::prepare_frame(loramac_mhdr_t *machdr,
// Update FCtrl field with new value of OptionsLength // Update FCtrl field with new value of OptionsLength
_params.tx_buffer[0x05] = fctrl->value; _params.tx_buffer[0x05] = fctrl->value;
const uint8_t *buffer = const uint8_t *buffer = _mac_commands.get_mac_commands_buffer();
_mac_commands.get_mac_commands_buffer();
for (i = 0; i < mac_commands_len; i++) { for (i = 0; i < mac_commands_len; i++) {
_params.tx_buffer[pkt_header_len++] = buffer[i]; _params.tx_buffer[pkt_header_len++] = buffer[i];
} }
@ -1577,13 +1576,13 @@ lorawan_status_t LoRaMac::prepare_frame(loramac_mhdr_t *machdr,
_params.tx_buffer[pkt_header_len++] = frame_port; _params.tx_buffer[pkt_header_len++] = frame_port;
uint8_t *key = _params.keys.app_skey; uint8_t *key = _params.keys.app_skey;
uint32_t key_length = sizeof(_params.keys.app_skey)*8; uint32_t key_length = sizeof(_params.keys.app_skey) * 8;
if (frame_port == 0) { if (frame_port == 0) {
_mac_commands.clear_command_buffer(); _mac_commands.clear_command_buffer();
key = _params.keys.nwk_skey; key = _params.keys.nwk_skey;
key_length = sizeof(_params.keys.nwk_skey)*8; key_length = sizeof(_params.keys.nwk_skey) * 8;
} }
if (0 != _lora_crypto.encrypt_payload((uint8_t*) payload, _params.tx_buffer_len, if (0 != _lora_crypto.encrypt_payload((uint8_t *) payload, _params.tx_buffer_len,
key, key_length, key, key_length,
_params.dev_addr, UP_LINK, _params.dev_addr, UP_LINK,
_params.ul_frame_counter, _params.ul_frame_counter,
@ -1595,7 +1594,7 @@ lorawan_status_t LoRaMac::prepare_frame(loramac_mhdr_t *machdr,
_params.tx_buffer_len = pkt_header_len + _params.tx_buffer_len; _params.tx_buffer_len = pkt_header_len + _params.tx_buffer_len;
if (0 != _lora_crypto.compute_mic(_params.tx_buffer, _params.tx_buffer_len, if (0 != _lora_crypto.compute_mic(_params.tx_buffer, _params.tx_buffer_len,
_params.keys.nwk_skey, sizeof(_params.keys.nwk_skey)*8, _params.keys.nwk_skey, sizeof(_params.keys.nwk_skey) * 8,
_params.dev_addr, _params.dev_addr,
UP_LINK, _params.ul_frame_counter, &mic)) { UP_LINK, _params.ul_frame_counter, &mic)) {
status = LORAWAN_STATUS_CRYPTO_FAIL; status = LORAWAN_STATUS_CRYPTO_FAIL;
@ -1941,7 +1940,7 @@ lorawan_status_t LoRaMac::mlme_request(loramac_mlme_req_t *mlmeRequest)
return status; return status;
} }
lorawan_status_t LoRaMac::test_request( loramac_compliance_test_req_t *mcpsRequest ) lorawan_status_t LoRaMac::test_request(loramac_compliance_test_req_t *mcpsRequest)
{ {
if (_params.mac_state != LORAMAC_IDLE) { if (_params.mac_state != LORAMAC_IDLE) {
return LORAWAN_STATUS_BUSY; return LORAWAN_STATUS_BUSY;
@ -2005,38 +2004,37 @@ lorawan_status_t LoRaMac::test_request( loramac_compliance_test_req_t *mcpsReque
return status; return status;
} }
lorawan_status_t LoRaMac::LoRaMacSetTxTimer( uint32_t TxDutyCycleTime ) lorawan_status_t LoRaMac::LoRaMacSetTxTimer(uint32_t TxDutyCycleTime)
{ {
_lora_time.start(tx_next_packet_timer, TxDutyCycleTime); _lora_time.start(tx_next_packet_timer, TxDutyCycleTime);
return LORAWAN_STATUS_OK; return LORAWAN_STATUS_OK;
} }
lorawan_status_t LoRaMac::LoRaMacStopTxTimer( ) lorawan_status_t LoRaMac::LoRaMacStopTxTimer()
{ {
_lora_time.stop(tx_next_packet_timer); _lora_time.stop(tx_next_packet_timer);
return LORAWAN_STATUS_OK; return LORAWAN_STATUS_OK;
} }
void LoRaMac::LoRaMacTestRxWindowsOn( bool enable ) void LoRaMac::LoRaMacTestRxWindowsOn(bool enable)
{ {
_params.is_rx_window_enabled = enable; _params.is_rx_window_enabled = enable;
} }
void LoRaMac::LoRaMacTestSetMic( uint16_t txPacketCounter ) void LoRaMac::LoRaMacTestSetMic(uint16_t txPacketCounter)
{ {
_params.ul_frame_counter = txPacketCounter; _params.ul_frame_counter = txPacketCounter;
_params.is_ul_frame_counter_fixed = true; _params.is_ul_frame_counter_fixed = true;
} }
void LoRaMac::LoRaMacTestSetDutyCycleOn( bool enable ) void LoRaMac::LoRaMacTestSetDutyCycleOn(bool enable)
{ {
if(_lora_phy.verify_duty_cycle(enable) == true) if (_lora_phy.verify_duty_cycle(enable) == true) {
{
_params.is_dutycycle_on = enable; _params.is_dutycycle_on = enable;
} }
} }
void LoRaMac::LoRaMacTestSetChannel( uint8_t channel ) void LoRaMac::LoRaMacTestSetChannel(uint8_t channel)
{ {
_params.channel = channel; _params.channel = channel;
} }

View File

@ -767,7 +767,7 @@ public: // Test interface
* \ref LORAWAN_STATUS_OK * \ref LORAWAN_STATUS_OK
* \ref LORAWAN_STATUS_PARAMETER_INVALID * \ref LORAWAN_STATUS_PARAMETER_INVALID
*/ */
lorawan_status_t LoRaMacSetTxTimer( uint32_t NextTxTime ); lorawan_status_t LoRaMacSetTxTimer(uint32_t NextTxTime);
/** /**
* \brief LoRaMAC stop tx timer. * \brief LoRaMAC stop tx timer.
@ -778,7 +778,7 @@ public: // Test interface
* \ref LORAWAN_STATUS_OK * \ref LORAWAN_STATUS_OK
* \ref LORAWAN_STATUS_PARAMETER_INVALID * \ref LORAWAN_STATUS_PARAMETER_INVALID
*/ */
lorawan_status_t LoRaMacStopTxTimer( ); lorawan_status_t LoRaMacStopTxTimer();
/** /**
* \brief Enabled or disables the reception windows * \brief Enabled or disables the reception windows
@ -788,7 +788,7 @@ public: // Test interface
* *
* \param [in] enable - Enabled or disables the reception windows * \param [in] enable - Enabled or disables the reception windows
*/ */
void LoRaMacTestRxWindowsOn( bool enable ); void LoRaMacTestRxWindowsOn(bool enable);
/** /**
* \brief Enables the MIC field test * \brief Enables the MIC field test
@ -798,7 +798,7 @@ public: // Test interface
* *
* \param [in] txPacketCounter - Fixed Tx packet counter value * \param [in] txPacketCounter - Fixed Tx packet counter value
*/ */
void LoRaMacTestSetMic( uint16_t txPacketCounter ); void LoRaMacTestSetMic(uint16_t txPacketCounter);
/** /**
* \brief Enabled or disables the duty cycle * \brief Enabled or disables the duty cycle
@ -808,7 +808,7 @@ public: // Test interface
* *
* \param [in] enable - Enabled or disables the duty cycle * \param [in] enable - Enabled or disables the duty cycle
*/ */
void LoRaMacTestSetDutyCycleOn( bool enable ); void LoRaMacTestSetDutyCycleOn(bool enable);
/** /**
* \brief Sets the channel index * \brief Sets the channel index
@ -818,7 +818,7 @@ public: // Test interface
* *
* \param [in] channel - Channel index * \param [in] channel - Channel index
*/ */
void LoRaMacTestSetChannel( uint8_t channel ); void LoRaMacTestSetChannel(uint8_t channel);
private: private:
/** /**

View File

@ -47,30 +47,35 @@ LoRaPHY::~LoRaPHY()
_radio = NULL; _radio = NULL;
} }
bool LoRaPHY::mask_bit_test(const uint16_t *mask, unsigned bit) { bool LoRaPHY::mask_bit_test(const uint16_t *mask, unsigned bit)
return mask[bit/16] & (1U << (bit % 16)); {
return mask[bit / 16] & (1U << (bit % 16));
} }
void LoRaPHY::mask_bit_set(uint16_t *mask, unsigned bit) { void LoRaPHY::mask_bit_set(uint16_t *mask, unsigned bit)
mask[bit/16] |= (1U << (bit % 16)); {
mask[bit / 16] |= (1U << (bit % 16));
} }
void LoRaPHY::mask_bit_clear(uint16_t *mask, unsigned bit) { void LoRaPHY::mask_bit_clear(uint16_t *mask, unsigned bit)
mask[bit/16] &= ~(1U << (bit % 16)); {
mask[bit / 16] &= ~(1U << (bit % 16));
} }
void LoRaPHY::set_radio_instance(LoRaRadio& radio) void LoRaPHY::set_radio_instance(LoRaRadio &radio)
{ {
_radio = &radio; _radio = &radio;
} }
void LoRaPHY::put_radio_to_sleep() { void LoRaPHY::put_radio_to_sleep()
{
_radio->lock(); _radio->lock();
_radio->sleep(); _radio->sleep();
_radio->unlock(); _radio->unlock();
} }
void LoRaPHY::put_radio_to_standby() { void LoRaPHY::put_radio_to_standby()
{
_radio->lock(); _radio->lock();
_radio->standby(); _radio->standby();
_radio->unlock(); _radio->unlock();
@ -100,7 +105,7 @@ uint32_t LoRaPHY::get_radio_rng()
uint32_t rand; uint32_t rand;
_radio->lock(); _radio->lock();
rand =_radio->random(); rand = _radio->random();
_radio->unlock(); _radio->unlock();
return rand; return rand;
@ -113,7 +118,7 @@ void LoRaPHY::handle_send(uint8_t *buf, uint8_t size)
_radio->unlock(); _radio->unlock();
} }
uint8_t LoRaPHY::request_new_channel(int8_t channel_id, channel_params_t* new_channel) uint8_t LoRaPHY::request_new_channel(int8_t channel_id, channel_params_t *new_channel)
{ {
if (!phy_params.custom_channelplans_supported) { if (!phy_params.custom_channelplans_supported) {
return 0; return 0;
@ -129,27 +134,22 @@ uint8_t LoRaPHY::request_new_channel(int8_t channel_id, channel_params_t* new_ch
} else { } else {
new_channel->band = lookup_band_for_frequency(new_channel->frequency); new_channel->band = lookup_band_for_frequency(new_channel->frequency);
switch (add_channel(new_channel, channel_id)) { switch (add_channel(new_channel, channel_id)) {
case LORAWAN_STATUS_OK: case LORAWAN_STATUS_OK: {
{
break; break;
} }
case LORAWAN_STATUS_FREQUENCY_INVALID: case LORAWAN_STATUS_FREQUENCY_INVALID: {
{
status &= 0xFE; status &= 0xFE;
break; break;
} }
case LORAWAN_STATUS_DATARATE_INVALID: case LORAWAN_STATUS_DATARATE_INVALID: {
{
status &= 0xFD; status &= 0xFD;
break; break;
} }
case LORAWAN_STATUS_FREQ_AND_DR_INVALID: case LORAWAN_STATUS_FREQ_AND_DR_INVALID: {
{
status &= 0xFC; status &= 0xFC;
break; break;
} }
default: default: {
{
status &= 0xFC; status &= 0xFC;
break; break;
} }
@ -164,9 +164,9 @@ int32_t LoRaPHY::get_random(int32_t min, int32_t max)
return (int32_t) rand() % (max - min + 1) + min; return (int32_t) rand() % (max - min + 1) + min;
} }
bool LoRaPHY::verify_channel_DR(uint8_t nb_channels, uint16_t* channel_mask, bool LoRaPHY::verify_channel_DR(uint8_t nb_channels, uint16_t *channel_mask,
int8_t dr, int8_t min_dr, int8_t max_dr, int8_t dr, int8_t min_dr, int8_t max_dr,
channel_params_t* channels) channel_params_t *channels)
{ {
if (val_in_range(dr, min_dr, max_dr) == 0) { if (val_in_range(dr, min_dr, max_dr) == 0) {
return false; return false;
@ -186,7 +186,7 @@ bool LoRaPHY::verify_channel_DR(uint8_t nb_channels, uint16_t* channel_mask,
return false; return false;
} }
bool LoRaPHY::val_in_range( int8_t value, int8_t min, int8_t max ) bool LoRaPHY::val_in_range(int8_t value, int8_t min, int8_t max)
{ {
if ((value >= min) && (value <= max)) { if ((value >= min) && (value <= max)) {
return true; return true;
@ -195,7 +195,7 @@ bool LoRaPHY::val_in_range( int8_t value, int8_t min, int8_t max )
return false; return false;
} }
bool LoRaPHY::disable_channel(uint16_t* channel_mask, uint8_t id, bool LoRaPHY::disable_channel(uint16_t *channel_mask, uint8_t id,
uint8_t max_channels_num) uint8_t max_channels_num)
{ {
uint8_t index = id / 16; uint8_t index = id / 16;
@ -214,7 +214,7 @@ uint8_t LoRaPHY::count_bits(uint16_t mask, uint8_t nbBits)
{ {
uint8_t nbActiveBits = 0; uint8_t nbActiveBits = 0;
for(uint8_t j = 0; j < nbBits; j++) { for (uint8_t j = 0; j < nbBits; j++) {
if (mask_bit_test(&mask, j)) { if (mask_bit_test(&mask, j)) {
nbActiveBits++; nbActiveBits++;
} }
@ -223,7 +223,7 @@ uint8_t LoRaPHY::count_bits(uint16_t mask, uint8_t nbBits)
return nbActiveBits; return nbActiveBits;
} }
uint8_t LoRaPHY::num_active_channels(uint16_t* channel_mask, uint8_t start_idx, uint8_t LoRaPHY::num_active_channels(uint16_t *channel_mask, uint8_t start_idx,
uint8_t stop_idx) uint8_t stop_idx)
{ {
uint8_t nb_channels = 0; uint8_t nb_channels = 0;
@ -239,10 +239,10 @@ uint8_t LoRaPHY::num_active_channels(uint16_t* channel_mask, uint8_t start_idx,
return nb_channels; return nb_channels;
} }
void LoRaPHY::copy_channel_mask(uint16_t* dest_mask, uint16_t* src_mask, uint8_t len) void LoRaPHY::copy_channel_mask(uint16_t *dest_mask, uint16_t *src_mask, uint8_t len)
{ {
if ((dest_mask != NULL) && (src_mask != NULL)) { if ((dest_mask != NULL) && (src_mask != NULL)) {
for( uint8_t i = 0; i < len; i++ ) { for (uint8_t i = 0; i < len; i++) {
dest_mask[i] = src_mask[i]; dest_mask[i] = src_mask[i];
} }
} }
@ -264,9 +264,9 @@ void LoRaPHY::set_last_tx_done(uint8_t channel, bool joined, lorawan_time_t last
} }
lorawan_time_t LoRaPHY::update_band_timeoff(bool joined, bool duty_cycle, lorawan_time_t LoRaPHY::update_band_timeoff(bool joined, bool duty_cycle,
band_t* bands, uint8_t nb_bands) band_t *bands, uint8_t nb_bands)
{ {
lorawan_time_t next_tx_delay = (lorawan_time_t) (-1); lorawan_time_t next_tx_delay = (lorawan_time_t)(-1);
// Update bands Time OFF // Update bands Time OFF
for (uint8_t i = 0; i < nb_bands; i++) { for (uint8_t i = 0; i < nb_bands; i++) {
@ -281,18 +281,18 @@ lorawan_time_t LoRaPHY::update_band_timeoff(bool joined, bool duty_cycle,
} }
if (bands[i].off_time != 0) { if (bands[i].off_time != 0) {
next_tx_delay = MIN( bands[i].off_time - txDoneTime, next_tx_delay ); next_tx_delay = MIN(bands[i].off_time - txDoneTime, next_tx_delay);
} }
} else { } else {
// if network has been joined // if network has been joined
if (duty_cycle == true) { if (duty_cycle == true) {
if( bands[i].off_time <= _lora_time.get_elapsed_time(bands[i].last_tx_time)) { if (bands[i].off_time <= _lora_time.get_elapsed_time(bands[i].last_tx_time)) {
bands[i].off_time = 0; bands[i].off_time = 0;
} }
if(bands[i].off_time != 0 ) { if (bands[i].off_time != 0) {
next_tx_delay = MIN(bands[i].off_time - _lora_time.get_elapsed_time(bands[i].last_tx_time), next_tx_delay = MIN(bands[i].off_time - _lora_time.get_elapsed_time(bands[i].last_tx_time),
next_tx_delay); next_tx_delay);
} }
@ -307,7 +307,8 @@ lorawan_time_t LoRaPHY::update_band_timeoff(bool joined, bool duty_cycle,
return next_tx_delay; return next_tx_delay;
} }
uint8_t LoRaPHY::parse_link_ADR_req(const uint8_t* payload, link_adr_params_t* params) uint8_t LoRaPHY::parse_link_ADR_req(const uint8_t *payload,
link_adr_params_t *params)
{ {
uint8_t ret_index = 0; uint8_t ret_index = 0;
@ -324,7 +325,7 @@ uint8_t LoRaPHY::parse_link_ADR_req(const uint8_t* payload, link_adr_params_t* p
// Parse ChMaskCtrl and nbRep // Parse ChMaskCtrl and nbRep
params->nb_rep = payload[4]; params->nb_rep = payload[4];
params->ch_mask_ctrl = ( params->nb_rep >> 4 ) & 0x07; params->ch_mask_ctrl = (params->nb_rep >> 4) & 0x07;
params->nb_rep &= 0x0F; params->nb_rep &= 0x0F;
// LinkAdrReq has 4 bytes length + 1 byte CMD // LinkAdrReq has 4 bytes length + 1 byte CMD
@ -334,8 +335,8 @@ uint8_t LoRaPHY::parse_link_ADR_req(const uint8_t* payload, link_adr_params_t* p
return ret_index; return ret_index;
} }
uint8_t LoRaPHY::verify_link_ADR_req(verify_adr_params_t* verify_params, uint8_t LoRaPHY::verify_link_ADR_req(verify_adr_params_t *verify_params,
int8_t* dr, int8_t* tx_pow, uint8_t* nb_rep) int8_t *dr, int8_t *tx_pow, uint8_t *nb_rep)
{ {
uint8_t status = verify_params->status; uint8_t status = verify_params->status;
int8_t datarate = verify_params->datarate; int8_t datarate = verify_params->datarate;
@ -404,10 +405,10 @@ double LoRaPHY::compute_symb_timeout_fsk(uint8_t phy_dr)
void LoRaPHY::get_rx_window_params(double t_symb, uint8_t min_rx_symb, void LoRaPHY::get_rx_window_params(double t_symb, uint8_t min_rx_symb,
uint32_t rx_error, uint32_t wakeup_time, uint32_t rx_error, uint32_t wakeup_time,
uint32_t* window_timeout, int32_t* window_offset) uint32_t *window_timeout, int32_t *window_offset)
{ {
// Computed number of symbols // Computed number of symbols
*window_timeout = MAX ((uint32_t) ceil(((2 * min_rx_symb - 8) * t_symb + 2 * rx_error) / t_symb), min_rx_symb ); *window_timeout = MAX((uint32_t) ceil(((2 * min_rx_symb - 8) * t_symb + 2 * rx_error) / t_symb), min_rx_symb);
*window_offset = (int32_t) ceil((4.0 * t_symb) - ((*window_timeout * t_symb) / 2.0 ) - wakeup_time); *window_offset = (int32_t) ceil((4.0 * t_symb) - ((*window_timeout * t_symb) / 2.0 ) - wakeup_time);
} }
@ -430,7 +431,7 @@ int8_t LoRaPHY::get_next_lower_dr(int8_t dr, int8_t min_dr)
if (next_lower_dr != min_dr) { if (next_lower_dr != min_dr) {
next_lower_dr -= 1; next_lower_dr -= 1;
} }
} while((next_lower_dr != min_dr) && !is_datarate_supported(next_lower_dr)); } while ((next_lower_dr != min_dr) && !is_datarate_supported(next_lower_dr));
return next_lower_dr; return next_lower_dr;
} }
@ -439,7 +440,7 @@ uint8_t LoRaPHY::get_bandwidth(uint8_t dr)
{ {
uint32_t *bandwidths = (uint32_t *) phy_params.bandwidths.table; uint32_t *bandwidths = (uint32_t *) phy_params.bandwidths.table;
switch(bandwidths[dr]) { switch (bandwidths[dr]) {
default: default:
case 125000: case 125000:
return 0; return 0;
@ -462,7 +463,7 @@ uint8_t LoRaPHY::enabled_channel_count(bool joined, uint8_t datarate,
if (mask_bit_test(channel_mask, i)) { if (mask_bit_test(channel_mask, i)) {
if (val_in_range(datarate, phy_params.channels.channel_list[i].dr_range.fields.min, if (val_in_range(datarate, phy_params.channels.channel_list[i].dr_range.fields.min,
phy_params.channels.channel_list[i].dr_range.fields.max ) == 0) { phy_params.channels.channel_list[i].dr_range.fields.max) == 0) {
// data rate range invalid for this channel // data rate range invalid for this channel
continue; continue;
} }
@ -602,7 +603,7 @@ uint8_t LoRaPHY::get_default_rx2_datarate()
return phy_params.rx_window2_datarate; return phy_params.rx_window2_datarate;
} }
uint16_t* LoRaPHY::get_channel_mask(bool get_default) uint16_t *LoRaPHY::get_channel_mask(bool get_default)
{ {
if (get_default) { if (get_default) {
return phy_params.channels.default_mask; return phy_params.channels.default_mask;
@ -615,7 +616,7 @@ uint8_t LoRaPHY::get_max_nb_channels()
return phy_params.max_channel_cnt; return phy_params.max_channel_cnt;
} }
channel_params_t* LoRaPHY::get_phy_channels() channel_params_t *LoRaPHY::get_phy_channels()
{ {
return phy_params.channels.channel_list; return phy_params.channels.channel_list;
} }
@ -628,7 +629,7 @@ bool LoRaPHY::is_custom_channel_plan_supported()
void LoRaPHY::restore_default_channels() void LoRaPHY::restore_default_channels()
{ {
// Restore channels default mask // Restore channels default mask
for (uint8_t i=0; i < phy_params.channels.mask_size; i++) { for (uint8_t i = 0; i < phy_params.channels.mask_size; i++) {
phy_params.channels.mask[i] |= phy_params.channels.default_mask[i]; phy_params.channels.mask[i] |= phy_params.channels.default_mask[i];
} }
} }
@ -644,7 +645,7 @@ bool LoRaPHY::verify_rx_datarate(uint8_t datarate)
} else { } else {
return val_in_range(datarate, return val_in_range(datarate,
phy_params.dwell_limit_datarate, phy_params.dwell_limit_datarate,
phy_params.max_rx_datarate ); phy_params.max_rx_datarate);
} }
} }
return false; return false;
@ -690,7 +691,7 @@ bool LoRaPHY::verify_nb_join_trials(uint8_t nb_join_trials)
return true; return true;
} }
void LoRaPHY::apply_cf_list(const uint8_t* payload, uint8_t size) void LoRaPHY::apply_cf_list(const uint8_t *payload, uint8_t size)
{ {
// if the underlying PHY doesn't support CF-List, ignore the request // if the underlying PHY doesn't support CF-List, ignore the request
if (!phy_params.cflist_supported) { if (!phy_params.cflist_supported) {
@ -700,8 +701,8 @@ void LoRaPHY::apply_cf_list(const uint8_t* payload, uint8_t size)
channel_params_t new_channel; channel_params_t new_channel;
// Setup default datarate range // Setup default datarate range
new_channel.dr_range.value = (phy_params.default_max_datarate << 4) new_channel.dr_range.value = (phy_params.default_max_datarate << 4) |
| phy_params.default_datarate; phy_params.default_datarate;
// Size of the optional CF list // Size of the optional CF list
if (size != 16) { if (size != 16) {
@ -716,7 +717,7 @@ void LoRaPHY::apply_cf_list(const uint8_t* payload, uint8_t size)
// should override this function in the implementation of that particular // should override this function in the implementation of that particular
// PHY. // PHY.
for (uint8_t i = 0, channel_id = phy_params.default_channel_cnt; for (uint8_t i = 0, channel_id = phy_params.default_channel_cnt;
channel_id < phy_params.max_channel_cnt; i+=3, channel_id++) { channel_id < phy_params.max_channel_cnt; i += 3, channel_id++) {
if (channel_id < (phy_params.cflist_channel_cnt + phy_params.default_channel_cnt)) { if (channel_id < (phy_params.cflist_channel_cnt + phy_params.default_channel_cnt)) {
// Channel frequency // Channel frequency
new_channel.frequency = (uint32_t) payload[i]; new_channel.frequency = (uint32_t) payload[i];
@ -745,8 +746,8 @@ void LoRaPHY::apply_cf_list(const uint8_t* payload, uint8_t size)
} }
bool LoRaPHY::get_next_ADR(bool restore_channel_mask, int8_t& dr_out, bool LoRaPHY::get_next_ADR(bool restore_channel_mask, int8_t &dr_out,
int8_t& tx_power_out, uint32_t& adr_ack_cnt) int8_t &tx_power_out, uint32_t &adr_ack_cnt)
{ {
bool set_adr_ack_bit = false; bool set_adr_ack_bit = false;
@ -791,7 +792,7 @@ void LoRaPHY::compute_rx_win_params(int8_t datarate, uint8_t min_rx_symbols,
double t_symbol = 0.0; double t_symbol = 0.0;
// Get the datarate, perform a boundary check // Get the datarate, perform a boundary check
rx_conf_params->datarate = MIN( datarate, phy_params.max_rx_datarate); rx_conf_params->datarate = MIN(datarate, phy_params.max_rx_datarate);
rx_conf_params->bandwidth = get_bandwidth(rx_conf_params->datarate); rx_conf_params->bandwidth = get_bandwidth(rx_conf_params->datarate);
@ -808,7 +809,7 @@ void LoRaPHY::compute_rx_win_params(int8_t datarate, uint8_t min_rx_symbols,
&rx_conf_params->window_timeout, &rx_conf_params->window_offset); &rx_conf_params->window_timeout, &rx_conf_params->window_offset);
} }
bool LoRaPHY::rx_config(rx_config_params_t* rx_conf) bool LoRaPHY::rx_config(rx_config_params_t *rx_conf)
{ {
radio_modems_t modem; radio_modems_t modem;
uint8_t dr = rx_conf->datarate; uint8_t dr = rx_conf->datarate;
@ -871,8 +872,8 @@ bool LoRaPHY::rx_config(rx_config_params_t* rx_conf)
return true; return true;
} }
bool LoRaPHY::tx_config(tx_config_params_t* tx_conf, int8_t* tx_power, bool LoRaPHY::tx_config(tx_config_params_t *tx_conf, int8_t *tx_power,
lorawan_time_t* tx_toa) lorawan_time_t *tx_toa)
{ {
radio_modems_t modem; radio_modems_t modem;
int8_t phy_dr = ((uint8_t *)phy_params.datarates.table)[tx_conf->datarate]; int8_t phy_dr = ((uint8_t *)phy_params.datarates.table)[tx_conf->datarate];
@ -895,7 +896,7 @@ bool LoRaPHY::tx_config(tx_config_params_t* tx_conf, int8_t* tx_power,
// Setup the radio frequency // Setup the radio frequency
_radio->set_channel(list[tx_conf->channel].frequency); _radio->set_channel(list[tx_conf->channel].frequency);
if( tx_conf->datarate == phy_params.max_tx_datarate ) { if (tx_conf->datarate == phy_params.max_tx_datarate) {
// High Speed FSK channel // High Speed FSK channel
modem = MODEM_FSK; modem = MODEM_FSK;
_radio->set_tx_config(modem, phy_tx_power, 25000, bandwidth, _radio->set_tx_config(modem, phy_tx_power, 25000, bandwidth,
@ -904,11 +905,11 @@ bool LoRaPHY::tx_config(tx_config_params_t* tx_conf, int8_t* tx_power,
} else { } else {
modem = MODEM_LORA; modem = MODEM_LORA;
_radio->set_tx_config(modem, phy_tx_power, 0, bandwidth, phy_dr, 1, 8, _radio->set_tx_config(modem, phy_tx_power, 0, bandwidth, phy_dr, 1, 8,
false, true, 0, 0, false, 3000 ); false, true, 0, 0, false, 3000);
} }
// Setup maximum payload lenght of the radio driver // Setup maximum payload lenght of the radio driver
_radio->set_max_payload_length( modem, tx_conf->pkt_len); _radio->set_max_payload_length(modem, tx_conf->pkt_len);
// Get the time-on-air of the next tx frame // Get the time-on-air of the next tx frame
*tx_toa = _radio->time_on_air(modem, tx_conf->pkt_len); *tx_toa = _radio->time_on_air(modem, tx_conf->pkt_len);
@ -919,9 +920,9 @@ bool LoRaPHY::tx_config(tx_config_params_t* tx_conf, int8_t* tx_power,
return true; return true;
} }
uint8_t LoRaPHY::link_ADR_request(adr_req_params_t* link_adr_req, uint8_t LoRaPHY::link_ADR_request(adr_req_params_t *link_adr_req,
int8_t* dr_out, int8_t* tx_power_out, int8_t *dr_out, int8_t *tx_power_out,
uint8_t* nb_rep_out, uint8_t* nb_bytes_processed) uint8_t *nb_rep_out, uint8_t *nb_bytes_processed)
{ {
uint8_t status = 0x07; uint8_t status = 0x07;
link_adr_params_t adr_settings; link_adr_params_t adr_settings;
@ -960,8 +961,7 @@ uint8_t LoRaPHY::link_ADR_request(adr_req_params_t* link_adr_req,
} }
// channel mask applies to first 16 channels // channel mask applies to first 16 channels
if (adr_settings.ch_mask_ctrl == 0 || if (adr_settings.ch_mask_ctrl == 0 || adr_settings.ch_mask_ctrl == 6) {
adr_settings.ch_mask_ctrl == 6) {
for (uint8_t i = 0; i < phy_params.max_channel_cnt; i++) { for (uint8_t i = 0; i < phy_params.max_channel_cnt; i++) {
@ -1030,7 +1030,7 @@ uint8_t LoRaPHY::link_ADR_request(adr_req_params_t* link_adr_req,
return status; return status;
} }
uint8_t LoRaPHY::accept_rx_param_setup_req(rx_param_setup_req_t* params) uint8_t LoRaPHY::accept_rx_param_setup_req(rx_param_setup_req_t *params)
{ {
uint8_t status = 0x07; uint8_t status = 0x07;
@ -1073,7 +1073,7 @@ int LoRaPHY::lookup_band_for_frequency(uint32_t freq) const
// check all sub bands (if there are sub-bands) to check if the given // check all sub bands (if there are sub-bands) to check if the given
// frequency falls into any of the frequency ranges // frequency falls into any of the frequency ranges
for (int band=0; band<phy_params.bands.size; band++) { for (int band = 0; band < phy_params.bands.size; band++) {
if (verify_frequency_for_band(freq, band)) { if (verify_frequency_for_band(freq, band)) {
return band; return band;
} }
@ -1198,8 +1198,7 @@ void LoRaPHY::calculate_backoff(bool joined, bool last_tx_was_join_req, bool dc_
// No back-off if the last frame was not a join request and when the // No back-off if the last frame was not a join request and when the
// duty cycle is not enabled // duty cycle is not enabled
if (dc_enabled == false && if (dc_enabled == false && last_tx_was_join_req == false) {
last_tx_was_join_req == false) {
band_table[band_idx].off_time = 0; band_table[band_idx].off_time = 0;
} else { } else {
// Apply band time-off. // Apply band time-off.
@ -1207,9 +1206,9 @@ void LoRaPHY::calculate_backoff(bool joined, bool last_tx_was_join_req, bool dc_
} }
} }
lorawan_status_t LoRaPHY::set_next_channel(channel_selection_params_t* params, lorawan_status_t LoRaPHY::set_next_channel(channel_selection_params_t *params,
uint8_t* channel, lorawan_time_t* time, uint8_t *channel, lorawan_time_t *time,
lorawan_time_t* aggregate_timeoff) lorawan_time_t *aggregate_timeoff)
{ {
uint8_t channel_count = 0; uint8_t channel_count = 0;
uint8_t delay_tx = 0; uint8_t delay_tx = 0;
@ -1221,7 +1220,7 @@ lorawan_status_t LoRaPHY::set_next_channel(channel_selection_params_t* params,
// memory we chose to use a magic number of 16 // memory we chose to use a magic number of 16
uint8_t enabled_channels[16]; uint8_t enabled_channels[16];
memset(enabled_channels, 0xFF, sizeof(uint8_t)*16); memset(enabled_channels, 0xFF, sizeof(uint8_t) * 16);
lorawan_time_t next_tx_delay = 0; lorawan_time_t next_tx_delay = 0;
band_t *band_table = (band_t *) phy_params.bands.table; band_t *band_table = (band_t *) phy_params.bands.table;
@ -1251,8 +1250,8 @@ lorawan_status_t LoRaPHY::set_next_channel(channel_selection_params_t* params,
enabled_channels, &delay_tx); enabled_channels, &delay_tx);
} else { } else {
delay_tx++; delay_tx++;
next_tx_delay = params->aggregate_timeoff next_tx_delay = params->aggregate_timeoff -
- _lora_time.get_elapsed_time(params->last_aggregate_tx_time); _lora_time.get_elapsed_time(params->last_aggregate_tx_time);
} }
if (channel_count > 0) { if (channel_count > 0) {
@ -1276,7 +1275,8 @@ lorawan_status_t LoRaPHY::set_next_channel(channel_selection_params_t* params,
return LORAWAN_STATUS_NO_CHANNEL_FOUND; return LORAWAN_STATUS_NO_CHANNEL_FOUND;
} }
lorawan_status_t LoRaPHY::add_channel(const channel_params_t* new_channel, uint8_t id) lorawan_status_t LoRaPHY::add_channel(const channel_params_t *new_channel,
uint8_t id)
{ {
bool dr_invalid = false; bool dr_invalid = false;
bool freq_invalid = false; bool freq_invalid = false;
@ -1371,7 +1371,7 @@ bool LoRaPHY::remove_channel(uint8_t channel_id)
phy_params.max_channel_cnt); phy_params.max_channel_cnt);
} }
void LoRaPHY::set_tx_cont_mode(cw_mode_params_t* params, uint32_t given_frequency) void LoRaPHY::set_tx_cont_mode(cw_mode_params_t *params, uint32_t given_frequency)
{ {
band_t *bands_table = (band_t *) phy_params.bands.table; band_t *bands_table = (band_t *) phy_params.bands.table;
channel_params_t *channels = phy_params.channels.channel_list; channel_params_t *channels = phy_params.channels.channel_list;
@ -1392,7 +1392,7 @@ void LoRaPHY::set_tx_cont_mode(cw_mode_params_t* params, uint32_t given_frequenc
// Calculate physical TX power // Calculate physical TX power
if (params->max_eirp > 0 && params->antenna_gain > 0) { if (params->max_eirp > 0 && params->antenna_gain > 0) {
phy_tx_power = compute_tx_power(params->tx_power, params->max_eirp, phy_tx_power = compute_tx_power(params->tx_power, params->max_eirp,
params->antenna_gain ); params->antenna_gain);
} else { } else {
phy_tx_power = params->tx_power; phy_tx_power = params->tx_power;
} }