Skip to content

Commit b0889f7

Browse files
Kimmo Vaisanentheotherjimmy
authored andcommitted
Move all compliance test code inside compilation flag
All compliance test related codes are now inside LORAWAN_COMPLIANCE_TEST build flag. This will reduce memory usage in when compliance test codes are not needed.
1 parent 97f1680 commit b0889f7

File tree

5 files changed

+70
-34
lines changed

5 files changed

+70
-34
lines changed

features/lorawan/LoRaWANStack.cpp

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,18 @@ static Mcps_t interpret_mcps_confirm_type(const lora_mac_mcps_t& local);
8787
static Mib_t interpret_mib_req_confirm_type(const lora_mac_mib_t& mib_local);
8888
static lora_mac_event_info_status_t interpret_event_info_type(const LoRaMacEventInfoStatus_t& remote);
8989

90-
#if MBED_CONF_LORA_PHY == 0
91-
#include "lorawan/lorastack/mac/LoRaMacTest.h"
92-
#endif
93-
94-
/**
95-
*
96-
* User application data buffer size if compliance test is used
97-
*/
98-
#if (MBED_CONF_LORA_PHY == 0 || MBED_CONF_LORA_PHY == 4 || MBED_CONF_LORA_PHY == 6 || MBED_CONF_LORA_PHY == 7)
99-
#define LORAWAN_COMPLIANCE_TEST_DATA_SIZE 16
100-
#elif (MBED_CONF_LORA_PHY == 1 || MBED_CONF_LORA_PHY == 2 || MBED_CONF_LORA_PHY == 8 || MBED_CONF_LORA_PHY == 9)
101-
#define LORAWAN_COMPLIANCE_TEST_DATA_SIZE 11
102-
#else
103-
#error "Must set LoRa PHY layer parameters."
90+
#if defined(LORAWAN_COMPLIANCE_TEST)
91+
/**
92+
*
93+
* User application data buffer size if compliance test is used
94+
*/
95+
#if (MBED_CONF_LORA_PHY == 0 || MBED_CONF_LORA_PHY == 4 || MBED_CONF_LORA_PHY == 6 || MBED_CONF_LORA_PHY == 7)
96+
#define LORAWAN_COMPLIANCE_TEST_DATA_SIZE 16
97+
#elif (MBED_CONF_LORA_PHY == 1 || MBED_CONF_LORA_PHY == 2 || MBED_CONF_LORA_PHY == 8 || MBED_CONF_LORA_PHY == 9)
98+
#define LORAWAN_COMPLIANCE_TEST_DATA_SIZE 11
99+
#else
100+
#error "Must set LoRa PHY layer parameters."
101+
#endif
104102
#endif
105103

106104
/*****************************************************************************
@@ -186,15 +184,20 @@ lora_mac_status_t LoRaWANStack::initialize_mac_layer(EventQueue *queue)
186184
static LoRaMacPrimitives_t LoRaMacPrimitives;
187185
static LoRaMacCallback_t LoRaMacCallbacks;
188186
static lora_mac_mib_request_confirm_t mib_req;
187+
188+
#if defined(LORAWAN_COMPLIANCE_TEST)
189189
static uint8_t compliance_test_buffer[LORAWAN_TX_MAX_SIZE];
190+
#endif
190191

191192
tr_debug("Initializing MAC layer");
192193

193194
//store a pointer to Event Queue
194195
_queue = queue;
195196

197+
#if defined(LORAWAN_COMPLIANCE_TEST)
196198
// Allocate memory for compliance test
197199
_compliance_test.app_data_buffer = compliance_test_buffer;
200+
#endif
198201

199202
TimerTimeCounterInit( );
200203
LoRaMacPrimitives.MacMcpsConfirm = callback(this, &LoRaWANStack::mcps_confirm);
@@ -219,6 +222,7 @@ lora_mac_status_t LoRaWANStack::initialize_mac_layer(EventQueue *queue)
219222
return lora_state_machine();
220223
}
221224

225+
#if defined(LORAWAN_COMPLIANCE_TEST)
222226
/**
223227
*
224228
* Prepares the upload message to reserved ports
@@ -305,6 +309,7 @@ lora_mac_status_t LoRaWANStack::send_compliance_test_frame_to_mac()
305309

306310
return mcps_request_handler(&mcps_req);
307311
}
312+
#endif
308313

309314
uint16_t LoRaWANStack::check_possible_tx_size(uint16_t size)
310315
{
@@ -803,9 +808,11 @@ int16_t LoRaWANStack::handle_tx(uint8_t port, const uint8_t* data,
803808
return LORA_MAC_STATUS_WOULD_BLOCK;
804809
}
805810

811+
#if defined(LORAWAN_COMPLIANCE_TEST)
806812
if (_compliance_test.running) {
807813
return LORA_MAC_STATUS_COMPLIANCE_TEST_ON;
808814
}
815+
#endif
809816

810817
lora_mac_mib_request_confirm_t mib_req;
811818
lora_mac_status_t status;
@@ -900,9 +907,11 @@ int16_t LoRaWANStack::handle_rx(const uint8_t port, uint8_t* data,
900907
return LORA_MAC_STATUS_WOULD_BLOCK;
901908
}
902909

910+
#if defined(LORAWAN_COMPLIANCE_TEST)
903911
if (_compliance_test.running) {
904912
return LORA_MAC_STATUS_COMPLIANCE_TEST_ON;
905913
}
914+
#endif
906915

907916
if (data == NULL) {
908917
return LORA_MAC_STATUS_PARAMETER_INVALID;
@@ -1035,11 +1044,13 @@ void LoRaWANStack::mlme_confirm_handler(lora_mac_mlme_confirm_t *mlme_confirm)
10351044
if (mlme_confirm->status == LORA_EVENT_INFO_STATUS_OK) {
10361045
// Check DemodMargin
10371046
// Check NbGateways
1047+
#if defined(LORAWAN_COMPLIANCE_TEST)
10381048
if (_compliance_test.running == true) {
10391049
_compliance_test.link_check = true;
10401050
_compliance_test.demod_margin = mlme_confirm->demod_margin;
10411051
_compliance_test.nb_gateways = mlme_confirm->nb_gateways;
10421052
}
1053+
#endif
10431054
}
10441055
break;
10451056
default:
@@ -1189,15 +1200,21 @@ void LoRaWANStack::mcps_indication_handler(lora_mac_mcps_indication_t *mcps_indi
11891200

11901201
_lw_session.downlink_counter++;
11911202

1203+
#if defined(LORAWAN_COMPLIANCE_TEST)
11921204
if (_compliance_test.running == true) {
11931205
_compliance_test.downlink_counter++;
11941206
}
1207+
#endif
11951208

11961209
if (mcps_indication->rx_data == true) {
11971210
switch (mcps_indication->port) {
11981211
case 224:
1212+
#if defined(LORAWAN_COMPLIANCE_TEST)
11991213
tr_debug("Compliance test command received.");
12001214
compliance_test_handler(mcps_indication);
1215+
#else
1216+
tr_debug("Compliance test disabled.");
1217+
#endif
12011218
break;
12021219
default:
12031220
if (is_port_valid(mcps_indication->port) == true ||
@@ -1236,6 +1253,7 @@ void LoRaWANStack::mcps_indication_handler(lora_mac_mcps_indication_t *mcps_indi
12361253
}
12371254
}
12381255

1256+
#if defined(LORAWAN_COMPLIANCE_TEST)
12391257
/** Compliance testing function
12401258
*
12411259
* \param mcps_indication Pointer to the indication structure,
@@ -1369,6 +1387,7 @@ void LoRaWANStack::compliance_test_handler(lora_mac_mcps_indication_t *mcps_indi
13691387
}
13701388
}
13711389
}
1390+
#endif
13721391

13731392
lora_mac_status_t LoRaWANStack::mib_set_request(lora_mac_mib_request_confirm_t *mib_set_params)
13741393
{
@@ -1775,7 +1794,9 @@ lora_mac_status_t LoRaWANStack::lora_state_machine()
17751794
drop_channel_list();
17761795

17771796
// Stop sending messages and set joined status to false.
1778-
LoRaMacStopTxTimer();
1797+
#if defined(LORAWAN_COMPLIANCE_TEST)
1798+
_loramac.LoRaMacStopTxTimer();
1799+
#endif
17791800
mib_req.type = LORA_MIB_NETWORK_JOINED;
17801801
mib_req.param.is_network_joined = false;
17811802
mib_set_request(&mib_req);
@@ -1909,6 +1930,7 @@ lora_mac_status_t LoRaWANStack::lora_state_machine()
19091930
//Do nothing
19101931
status = LORA_MAC_STATUS_IDLE;
19111932
break;
1933+
#if defined(LORAWAN_COMPLIANCE_TEST)
19121934
case DEVICE_STATE_COMPLIANCE_TEST:
19131935
//Device is in compliance test mode
19141936
tr_debug("Device is in compliance test mode.");
@@ -1920,6 +1942,7 @@ lora_mac_status_t LoRaWANStack::lora_state_machine()
19201942
}
19211943
status = LORA_MAC_STATUS_COMPLIANCE_TEST_ON;
19221944
break;
1945+
#endif
19231946
default:
19241947
status = LORA_MAC_STATUS_SERVICE_UNKNOWN;
19251948
break;

features/lorawan/LoRaWANStack.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,10 @@ class LoRaWANStack: private mbed::NonCopyable<LoRaWANStack> {
404404
*/
405405
lora_mac_status_t error_type_converter(LoRaMacStatus_t type);
406406

407+
#if defined(LORAWAN_COMPLIANCE_TEST)
407408
compliance_test_t _compliance_test;
409+
#endif
410+
408411
device_states_t _device_current_state;
409412
lorawan_app_callbacks_t _callbacks;
410413
radio_events_t *_mac_handlers;

features/lorawan/lorastack/mac/LoRaMac.cpp

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ SPDX-License-Identifier: BSD-3-Clause
2323
*/
2424
#include <stdlib.h>
2525
#include "events/EventQueue.h"
26-
#include "rtos/Thread.h"
2726
#include "LoRaMac.h"
2827
#include "LoRaMacCrypto.h"
2928
#include "LoRaMacTest.h"
@@ -1526,21 +1525,6 @@ static void OnMacStateCheckTimerEvent( void )
15261525
}
15271526
}
15281527

1529-
LoRaMacStatus_t LoRaMacSetTxTimer( uint32_t TxDutyCycleTime )
1530-
{
1531-
TimerSetValue(&TxNextPacketTimer, TxDutyCycleTime);
1532-
TimerStart(&TxNextPacketTimer);
1533-
1534-
return LORAMAC_STATUS_OK;
1535-
}
1536-
1537-
LoRaMacStatus_t LoRaMacStopTxTimer( )
1538-
{
1539-
TimerStop(&TxNextPacketTimer);
1540-
1541-
return LORAMAC_STATUS_OK;
1542-
}
1543-
15441528
static void OnTxDelayedTimerEvent( void )
15451529
{
15461530
LoRaMacHeader_t macHdr;
@@ -3474,9 +3458,27 @@ radio_events_t *GetPhyEventHandlers()
34743458
return &RadioEvents;
34753459
}
34763460

3461+
#if defined(LORAWAN_COMPLIANCE_TEST)
34773462
/***************************************************************************
3478-
* TODO: Something related to Testing ? Need to figure out what is it *
3463+
* Compliance testing *
34793464
**************************************************************************/
3465+
3466+
LoRaMacStatus_t LoRaMac::LoRaMacSetTxTimer( uint32_t TxDutyCycleTime )
3467+
{
3468+
TimerSetValue(&TxNextPacketTimer, TxDutyCycleTime);
3469+
TimerStart(&TxNextPacketTimer);
3470+
3471+
return LORAMAC_STATUS_OK;
3472+
}
3473+
3474+
LoRaMacStatus_t LoRaMac::LoRaMacStopTxTimer( )
3475+
3476+
{
3477+
TimerStop(&TxNextPacketTimer);
3478+
3479+
return LORAMAC_STATUS_OK;
3480+
}
3481+
34803482
void LoRaMacTestRxWindowsOn( bool enable )
34813483
{
34823484
IsRxWindowsEnabled = enable;
@@ -3504,3 +3506,4 @@ void LoRaMacTestSetChannel( uint8_t channel )
35043506
{
35053507
Channel = channel;
35063508
}
3509+
#endif

features/lorawan/lorastack/mac/LoRaMac.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ LoRaMacStatus_t LoRaMacMcpsRequest( McpsReq_t *mcpsRequest );
331331
*/
332332
radio_events_t *GetPhyEventHandlers();
333333

334-
334+
#if defined(LORAWAN_COMPLIANCE_TEST)
335335
/**
336336
* \brief LoRaMAC set tx timer.
337337
*
@@ -355,5 +355,6 @@ LoRaMacStatus_t LoRaMacSetTxTimer( uint32_t NextTxTime );
355355
* \ref LORAMAC_STATUS_PARAMETER_INVALID
356356
*/
357357
LoRaMacStatus_t LoRaMacStopTxTimer( );
358+
#endif
358359

359360
#endif // __LORAMAC_H__

features/lorawan/system/lorawan_data_structures.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1822,7 +1822,9 @@ typedef enum device_states {
18221822
DEVICE_STATE_JOINED,
18231823
DEVICE_STATE_SEND,
18241824
DEVICE_STATE_IDLE,
1825+
#if defined(LORAWAN_COMPLIANCE_TEST)
18251826
DEVICE_STATE_COMPLIANCE_TEST,
1827+
#endif
18261828
DEVICE_STATE_SHUTDOWN
18271829
} device_states_t;
18281830

@@ -2066,7 +2068,9 @@ typedef enum lora_mac_status {
20662068
LORA_MAC_STATUS_CONNECT_IN_PROGRESS = -1016, /**< Services started - Connection in progress */
20672069
LORA_MAC_STATUS_NO_ACTIVE_SESSIONS = -1017, /**< Services not started - No active session */
20682070
LORA_MAC_STATUS_IDLE = -1018, /**< Services started - Idle at the moment */
2069-
LORA_MAC_STATUS_COMPLIANCE_TEST_ON = -1019 /**< Compliance test - is on-going */
2071+
#if defined(LORAWAN_COMPLIANCE_TEST)
2072+
LORA_MAC_STATUS_COMPLIANCE_TEST_ON = -1019, /**< Compliance test - is on-going */
2073+
#endif
20702074
} lora_mac_status_t;
20712075

20722076
/**
@@ -2756,6 +2760,7 @@ typedef struct lora_mac_mib_request_confirm {
27562760
lora_mac_mib_param_t param;
27572761
} lora_mac_mib_request_confirm_t;
27582762

2763+
#if defined(LORAWAN_COMPLIANCE_TEST)
27592764
/** LoRaWAN compliance tests support data
27602765
*
27612766
*/
@@ -2801,6 +2806,7 @@ typedef struct compliance_test {
28012806
*/
28022807
uint8_t nb_gateways;
28032808
} compliance_test_t;
2809+
#endif
28042810

28052811
/** Structure containing the uplink status
28062812
*

0 commit comments

Comments
 (0)