@@ -72,19 +72,19 @@ using namespace mbed;
72
72
73
73
74
74
LoRaMac::LoRaMac ()
75
- : _lora_time(),
76
- _lora_phy(_lora_time),
77
- _mac_commands(),
78
- _channel_plan(),
79
- _lora_crypto(),
80
- _ev_queue(NULL ),
81
- _mcps_indication(),
82
- _mcps_confirmation(),
83
- _mlme_indication(),
84
- _mlme_confirmation(),
85
- _is_nwk_joined(false ),
86
- _continuous_rx2_window_open(false ),
87
- _device_class(CLASS_A)
75
+ : _lora_time(),
76
+ _lora_phy(_lora_time),
77
+ _mac_commands(),
78
+ _channel_plan(),
79
+ _lora_crypto(),
80
+ _ev_queue(NULL ),
81
+ _mcps_indication(),
82
+ _mcps_confirmation(),
83
+ _mlme_indication(),
84
+ _mlme_confirmation(),
85
+ _is_nwk_joined(false ),
86
+ _continuous_rx2_window_open(false ),
87
+ _device_class(CLASS_A)
88
88
{
89
89
_params.keys .dev_eui = NULL ;
90
90
_params.keys .app_eui = NULL ;
@@ -284,7 +284,7 @@ void LoRaMac::check_frame_size(uint16_t size)
284
284
uint8_t value = _lora_phy.get_max_payload (_mcps_indication.rx_datarate ,
285
285
_params.is_repeater_supported );
286
286
287
- if (MAX (0 , (int16_t ) ((int16_t )size - (int16_t )LORA_MAC_FRMPAYLOAD_OVERHEAD))
287
+ if (MAX (0 , (int16_t )((int16_t )size - (int16_t )LORA_MAC_FRMPAYLOAD_OVERHEAD))
288
288
> (int32_t ) value) {
289
289
tr_error (" Invalid frame size" );
290
290
}
@@ -312,7 +312,7 @@ bool LoRaMac::message_integrity_check(const uint8_t *const payload,
312
312
mic_rx |= ((uint32_t ) payload[size - LORAMAC_MFR_LEN + 2 ] << 16 );
313
313
mic_rx |= ((uint32_t ) payload[size - LORAMAC_MFR_LEN + 3 ] << 24 );
314
314
315
- sequence_counter_prev = (uint16_t ) *downlink_counter;
315
+ sequence_counter_prev = (uint16_t )*downlink_counter;
316
316
sequence_counter_diff = sequence_counter - sequence_counter_prev;
317
317
*downlink_counter += sequence_counter_diff;
318
318
if (sequence_counter < sequence_counter_prev) {
@@ -417,7 +417,7 @@ void LoRaMac::extract_data_and_mac_commands(const uint8_t *payload,
417
417
if (_lora_crypto.decrypt_payload (payload + payload_start_index,
418
418
frame_len,
419
419
app_skey,
420
- sizeof (_params.keys .app_skey )* 8 ,
420
+ sizeof (_params.keys .app_skey ) * 8 ,
421
421
address,
422
422
DOWN_LINK,
423
423
downlink_counter,
@@ -638,7 +638,7 @@ void LoRaMac::on_radio_tx_done(lorawan_time_t timestamp)
638
638
_lora_phy.put_radio_to_sleep ();
639
639
}
640
640
641
- if (_params.is_rx_window_enabled == true ) {
641
+ if (_params.is_rx_window_enabled == true ) {
642
642
lorawan_time_t time_diff = _lora_time.get_current_time () - timestamp;
643
643
// start timer after which rx1_window will get opened
644
644
_lora_time.start (_params.timers .rx_window1_timer ,
@@ -742,12 +742,12 @@ void LoRaMac::on_radio_rx_timeout(bool is_timeout)
742
742
if (_params.rx_slot == RX_SLOT_WIN_1) {
743
743
if (_params.is_node_ack_requested == true ) {
744
744
_mcps_confirmation.status = is_timeout ?
745
- LORAMAC_EVENT_INFO_STATUS_RX1_TIMEOUT :
746
- LORAMAC_EVENT_INFO_STATUS_RX1_ERROR;
745
+ LORAMAC_EVENT_INFO_STATUS_RX1_TIMEOUT :
746
+ LORAMAC_EVENT_INFO_STATUS_RX1_ERROR;
747
747
}
748
748
_mlme_confirmation.status = is_timeout ?
749
- LORAMAC_EVENT_INFO_STATUS_RX1_TIMEOUT :
750
- LORAMAC_EVENT_INFO_STATUS_RX1_ERROR;
749
+ LORAMAC_EVENT_INFO_STATUS_RX1_TIMEOUT :
750
+ LORAMAC_EVENT_INFO_STATUS_RX1_ERROR;
751
751
752
752
if (_device_class != CLASS_C) {
753
753
if (_lora_time.get_elapsed_time (_params.timers .aggregated_last_tx_time ) >= _params.rx_window2_delay ) {
@@ -757,13 +757,13 @@ void LoRaMac::on_radio_rx_timeout(bool is_timeout)
757
757
} else {
758
758
if (_params.is_node_ack_requested == true ) {
759
759
_mcps_confirmation.status = is_timeout ?
760
- LORAMAC_EVENT_INFO_STATUS_RX2_TIMEOUT :
761
- LORAMAC_EVENT_INFO_STATUS_RX2_ERROR;
760
+ LORAMAC_EVENT_INFO_STATUS_RX2_TIMEOUT :
761
+ LORAMAC_EVENT_INFO_STATUS_RX2_ERROR;
762
762
}
763
763
764
764
_mlme_confirmation.status = is_timeout ?
765
- LORAMAC_EVENT_INFO_STATUS_RX2_TIMEOUT :
766
- LORAMAC_EVENT_INFO_STATUS_RX2_ERROR;
765
+ LORAMAC_EVENT_INFO_STATUS_RX2_TIMEOUT :
766
+ LORAMAC_EVENT_INFO_STATUS_RX2_ERROR;
767
767
}
768
768
}
769
769
@@ -800,8 +800,8 @@ lorawan_status_t LoRaMac::send_join_request()
800
800
loramac_mhdr_t mac_hdr;
801
801
loramac_frame_ctrl_t fctrl;
802
802
803
- _params.sys_params .channel_data_rate = _lora_phy. get_alternate_DR (
804
- _params.join_request_trial_counter + 1 );
803
+ _params.sys_params .channel_data_rate =
804
+ _lora_phy. get_alternate_DR ( _params.join_request_trial_counter + 1 );
805
805
806
806
mac_hdr.value = 0 ;
807
807
mac_hdr.bits .mtype = FRAME_TYPE_JOIN_REQ;
@@ -846,7 +846,7 @@ void LoRaMac::on_backoff_timer_expiry(void)
846
846
{
847
847
Lock lock (*this );
848
848
lorawan_status_t status = schedule_tx ();
849
- MBED_ASSERT (status== LORAWAN_STATUS_OK);
849
+ MBED_ASSERT (status == LORAWAN_STATUS_OK);
850
850
(void ) status;
851
851
}
852
852
@@ -888,7 +888,7 @@ void LoRaMac::open_rx2_window()
888
888
_params.rx_window2_config .dl_dwell_time = _params.sys_params .downlink_dwell_time ;
889
889
_params.rx_window2_config .is_repeater_supported = _params.is_repeater_supported ;
890
890
_params.rx_window2_config .rx_slot = _params.rx_window2_config .is_rx_continuous ?
891
- RX_SLOT_WIN_CLASS_C : RX_SLOT_WIN_2;
891
+ RX_SLOT_WIN_CLASS_C : RX_SLOT_WIN_2;
892
892
893
893
if (get_device_class () == CLASS_C) {
894
894
_params.rx_window2_config .is_rx_continuous = true ;
@@ -950,7 +950,7 @@ void LoRaMac::on_ack_timeout_timer_event(void)
950
950
951
951
// now that is a critical failure
952
952
lorawan_status_t status = handle_retransmission ();
953
- MBED_ASSERT (status== LORAWAN_STATUS_OK);
953
+ MBED_ASSERT (status == LORAWAN_STATUS_OK);
954
954
(void ) status;
955
955
}
956
956
@@ -1092,19 +1092,19 @@ lorawan_status_t LoRaMac::schedule_tx()
1092
1092
1093
1093
if (!_is_nwk_joined) {
1094
1094
_params.rx_window1_delay = _params.sys_params .join_accept_delay1
1095
- + _params.rx_window1_config .window_offset ;
1095
+ + _params.rx_window1_config .window_offset ;
1096
1096
_params.rx_window2_delay = _params.sys_params .join_accept_delay2
1097
- + _params.rx_window2_config .window_offset ;
1097
+ + _params.rx_window2_config .window_offset ;
1098
1098
} else {
1099
1099
if (validate_payload_length (_params.tx_buffer_len ,
1100
1100
_params.sys_params .channel_data_rate ,
1101
1101
_mac_commands.get_mac_cmd_length ()) == false ) {
1102
1102
return LORAWAN_STATUS_LENGTH_ERROR;
1103
1103
}
1104
1104
_params.rx_window1_delay = _params.sys_params .recv_delay1
1105
- + _params.rx_window1_config .window_offset ;
1105
+ + _params.rx_window1_config .window_offset ;
1106
1106
_params.rx_window2_delay = _params.sys_params .recv_delay2
1107
- + _params.rx_window2_config .window_offset ;
1107
+ + _params.rx_window2_config .window_offset ;
1108
1108
}
1109
1109
1110
1110
// handle the ack to the server here so that if the sending was cancelled
@@ -1245,9 +1245,9 @@ int16_t LoRaMac::prepare_ongoing_tx(const uint8_t port,
1245
1245
1246
1246
// Handles unconfirmed messages
1247
1247
if (flags & MSG_UNCONFIRMED_FLAG) {
1248
- _ongoing_tx_msg.type = MCPS_UNCONFIRMED;
1249
- _ongoing_tx_msg.fport = port;
1250
- _ongoing_tx_msg.nb_trials = 1 ;
1248
+ _ongoing_tx_msg.type = MCPS_UNCONFIRMED;
1249
+ _ongoing_tx_msg.fport = port;
1250
+ _ongoing_tx_msg.nb_trials = 1 ;
1251
1251
}
1252
1252
1253
1253
// Handles confirmed messages
@@ -1537,7 +1537,7 @@ lorawan_status_t LoRaMac::prepare_frame(loramac_mhdr_t *machdr,
1537
1537
1538
1538
_params.tx_buffer [pkt_header_len++] = _params.ul_frame_counter & 0xFF ;
1539
1539
_params.tx_buffer [pkt_header_len++] = (_params.ul_frame_counter >> 8 )
1540
- & 0xFF ;
1540
+ & 0xFF ;
1541
1541
1542
1542
_mac_commands.copy_repeat_commands_to_buffer ();
1543
1543
@@ -1551,8 +1551,7 @@ lorawan_status_t LoRaMac::prepare_frame(loramac_mhdr_t *machdr,
1551
1551
// Update FCtrl field with new value of OptionsLength
1552
1552
_params.tx_buffer [0x05 ] = fctrl->value ;
1553
1553
1554
- const uint8_t *buffer =
1555
- _mac_commands.get_mac_commands_buffer ();
1554
+ const uint8_t *buffer = _mac_commands.get_mac_commands_buffer ();
1556
1555
for (i = 0 ; i < mac_commands_len; i++) {
1557
1556
_params.tx_buffer [pkt_header_len++] = buffer[i];
1558
1557
}
@@ -1577,13 +1576,13 @@ lorawan_status_t LoRaMac::prepare_frame(loramac_mhdr_t *machdr,
1577
1576
_params.tx_buffer [pkt_header_len++] = frame_port;
1578
1577
1579
1578
uint8_t *key = _params.keys .app_skey ;
1580
- uint32_t key_length = sizeof (_params.keys .app_skey )* 8 ;
1579
+ uint32_t key_length = sizeof (_params.keys .app_skey ) * 8 ;
1581
1580
if (frame_port == 0 ) {
1582
1581
_mac_commands.clear_command_buffer ();
1583
1582
key = _params.keys .nwk_skey ;
1584
- key_length = sizeof (_params.keys .nwk_skey )* 8 ;
1583
+ key_length = sizeof (_params.keys .nwk_skey ) * 8 ;
1585
1584
}
1586
- if (0 != _lora_crypto.encrypt_payload ((uint8_t *) payload, _params.tx_buffer_len ,
1585
+ if (0 != _lora_crypto.encrypt_payload ((uint8_t *) payload, _params.tx_buffer_len ,
1587
1586
key, key_length,
1588
1587
_params.dev_addr , UP_LINK,
1589
1588
_params.ul_frame_counter ,
@@ -1595,7 +1594,7 @@ lorawan_status_t LoRaMac::prepare_frame(loramac_mhdr_t *machdr,
1595
1594
_params.tx_buffer_len = pkt_header_len + _params.tx_buffer_len ;
1596
1595
1597
1596
if (0 != _lora_crypto.compute_mic (_params.tx_buffer , _params.tx_buffer_len ,
1598
- _params.keys .nwk_skey , sizeof (_params.keys .nwk_skey )* 8 ,
1597
+ _params.keys .nwk_skey , sizeof (_params.keys .nwk_skey ) * 8 ,
1599
1598
_params.dev_addr ,
1600
1599
UP_LINK, _params.ul_frame_counter , &mic)) {
1601
1600
status = LORAWAN_STATUS_CRYPTO_FAIL;
@@ -1770,7 +1769,7 @@ uint8_t LoRaMac::get_max_possible_tx_size(uint8_t size)
1770
1769
uint8_t max_possible_payload_size = 0 ;
1771
1770
uint8_t current_payload_size = 0 ;
1772
1771
uint8_t fopt_len = _mac_commands.get_mac_cmd_length ()
1773
- + _mac_commands.get_repeat_commands_length ();
1772
+ + _mac_commands.get_repeat_commands_length ();
1774
1773
1775
1774
if (_params.sys_params .adr_on ) {
1776
1775
_lora_phy.get_next_ADR (false , _params.sys_params .channel_data_rate ,
@@ -1918,16 +1917,16 @@ lorawan_status_t LoRaMac::mlme_request(loramac_mlme_req_t *mlmeRequest)
1918
1917
1919
1918
if (MLME_TXCW == mlmeRequest->type ) {
1920
1919
set_tx_continuous_wave (_params.channel , _params.sys_params .channel_data_rate , _params.sys_params .channel_tx_power ,
1921
- _params.sys_params .max_eirp , _params.sys_params .antenna_gain , mlmeRequest->cw_tx_mode .timeout );
1920
+ _params.sys_params .max_eirp , _params.sys_params .antenna_gain , mlmeRequest->cw_tx_mode .timeout );
1922
1921
_lora_time.start (_params.timers .mac_state_check_timer ,
1923
- MAC_STATE_CHECK_TIMEOUT);
1922
+ MAC_STATE_CHECK_TIMEOUT);
1924
1923
1925
1924
_params.mac_state |= LORAMAC_TX_RUNNING;
1926
1925
status = LORAWAN_STATUS_OK;
1927
1926
} else if (MLME_TXCW_1 == mlmeRequest->type ) {
1928
1927
set_tx_continuous_wave (0 , 0 , mlmeRequest->cw_tx_mode .power , 0 , 0 , mlmeRequest->cw_tx_mode .timeout );
1929
1928
_lora_time.start (_params.timers .mac_state_check_timer ,
1930
- MAC_STATE_CHECK_TIMEOUT);
1929
+ MAC_STATE_CHECK_TIMEOUT);
1931
1930
1932
1931
_params.mac_state |= LORAMAC_TX_RUNNING;
1933
1932
status = LORAWAN_STATUS_OK;
@@ -1941,7 +1940,7 @@ lorawan_status_t LoRaMac::mlme_request(loramac_mlme_req_t *mlmeRequest)
1941
1940
return status;
1942
1941
}
1943
1942
1944
- lorawan_status_t LoRaMac::test_request ( loramac_compliance_test_req_t *mcpsRequest )
1943
+ lorawan_status_t LoRaMac::test_request (loramac_compliance_test_req_t *mcpsRequest)
1945
1944
{
1946
1945
if (_params.mac_state != LORAMAC_IDLE) {
1947
1946
return LORAWAN_STATUS_BUSY;
@@ -1976,7 +1975,7 @@ lorawan_status_t LoRaMac::test_request( loramac_compliance_test_req_t *mcpsReque
1976
1975
break ;
1977
1976
}
1978
1977
default :
1979
- return LORAWAN_STATUS_PARAMETER_INVALID;
1978
+ return LORAWAN_STATUS_PARAMETER_INVALID;
1980
1979
}
1981
1980
1982
1981
// Filter fPorts
@@ -1994,7 +1993,7 @@ lorawan_status_t LoRaMac::test_request( loramac_compliance_test_req_t *mcpsReque
1994
1993
}
1995
1994
1996
1995
lorawan_status_t status = send (&machdr, mcpsRequest->fport , mcpsRequest->f_buffer ,
1997
- mcpsRequest->f_buffer_size );
1996
+ mcpsRequest->f_buffer_size );
1998
1997
if (status == LORAWAN_STATUS_OK) {
1999
1998
_mcps_confirmation.req_type = mcpsRequest->type ;
2000
1999
_params.flags .bits .mcps_req = 1 ;
@@ -2005,38 +2004,37 @@ lorawan_status_t LoRaMac::test_request( loramac_compliance_test_req_t *mcpsReque
2005
2004
return status;
2006
2005
}
2007
2006
2008
- lorawan_status_t LoRaMac::LoRaMacSetTxTimer ( uint32_t TxDutyCycleTime )
2007
+ lorawan_status_t LoRaMac::LoRaMacSetTxTimer (uint32_t TxDutyCycleTime)
2009
2008
{
2010
2009
_lora_time.start (tx_next_packet_timer, TxDutyCycleTime);
2011
2010
return LORAWAN_STATUS_OK;
2012
2011
}
2013
2012
2014
- lorawan_status_t LoRaMac::LoRaMacStopTxTimer ( )
2013
+ lorawan_status_t LoRaMac::LoRaMacStopTxTimer ()
2015
2014
{
2016
2015
_lora_time.stop (tx_next_packet_timer);
2017
2016
return LORAWAN_STATUS_OK;
2018
2017
}
2019
2018
2020
- void LoRaMac::LoRaMacTestRxWindowsOn ( bool enable )
2019
+ void LoRaMac::LoRaMacTestRxWindowsOn (bool enable)
2021
2020
{
2022
2021
_params.is_rx_window_enabled = enable;
2023
2022
}
2024
2023
2025
- void LoRaMac::LoRaMacTestSetMic ( uint16_t txPacketCounter )
2024
+ void LoRaMac::LoRaMacTestSetMic (uint16_t txPacketCounter)
2026
2025
{
2027
2026
_params.ul_frame_counter = txPacketCounter;
2028
2027
_params.is_ul_frame_counter_fixed = true ;
2029
2028
}
2030
2029
2031
- void LoRaMac::LoRaMacTestSetDutyCycleOn ( bool enable )
2030
+ void LoRaMac::LoRaMacTestSetDutyCycleOn (bool enable)
2032
2031
{
2033
- if (_lora_phy.verify_duty_cycle (enable) == true )
2034
- {
2032
+ if (_lora_phy.verify_duty_cycle (enable) == true ) {
2035
2033
_params.is_dutycycle_on = enable;
2036
2034
}
2037
2035
}
2038
2036
2039
- void LoRaMac::LoRaMacTestSetChannel ( uint8_t channel )
2037
+ void LoRaMac::LoRaMacTestSetChannel (uint8_t channel)
2040
2038
{
2041
2039
_params.channel = channel;
2042
2040
}
0 commit comments