Skip to content

Commit c198357

Browse files
author
Kimmo Vaisanen
committed
Fix compilance test compilation
Fix compilation of compilance test and at the same time refactor compliance test handler. Renamed mcps_request as test_request as it is only used for compliance test. Also fixed a bug with null buffer in send_compliance_test_frame_to_mac.
1 parent cbdeb7d commit c198357

File tree

5 files changed

+43
-69
lines changed

5 files changed

+43
-69
lines changed

features/lorawan/LoRaWANStack.cpp

Lines changed: 27 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,6 @@ lorawan_status_t LoRaWANStack::initialize_mac_layer(EventQueue *queue)
189189
tr_debug("Initializing MAC layer");
190190
_queue = queue;
191191

192-
#if defined(LORAWAN_COMPLIANCE_TEST)
193-
_compliance_test.app_data_buffer = compliance_test_buffer;
194-
#endif
195-
196192
_loramac.initialize(&LoRaMacPrimitives, queue);
197193

198194
// Reset counters to zero. Will change in future with 1.1 support.
@@ -876,36 +872,34 @@ lorawan_status_t LoRaWANStack::lora_state_machine(device_states_t new_state)
876872

877873
lorawan_status_t LoRaWANStack::send_compliance_test_frame_to_mac()
878874
{
879-
loramac_mcps_req_t mcps_req;
875+
loramac_compliance_test_req_t test_req;
880876

881-
// prepare_special_tx_frame(_compliance_test.app_port);
882877
//TODO: What if the port is not 224 ???
883878
if (_compliance_test.app_port == 224) {
884879
// Clear any normal message stuff before compliance test.
885-
memset(&mcps_req, 0, sizeof(mcps_req));
880+
memset(&test_req, 0, sizeof(test_req));
886881

887882
if (_compliance_test.link_check == true) {
888883
_compliance_test.link_check = false;
889884
_compliance_test.state = 1;
890-
mcps_req.f_buffer_size = 3;
891-
mcps_req.f_buffer[0] = 5;
892-
mcps_req.f_buffer[1] = _compliance_test.demod_margin;
893-
mcps_req.f_buffer[2] = _compliance_test.nb_gateways;
885+
test_req.f_buffer_size = 3;
886+
test_req.f_buffer[0] = 5;
887+
test_req.f_buffer[1] = _compliance_test.demod_margin;
888+
test_req.f_buffer[2] = _compliance_test.nb_gateways;
894889
} else {
895890
switch (_compliance_test.state) {
896891
case 4:
897892
_compliance_test.state = 1;
898-
mcps_req.f_buffer_size = _compliance_test.app_data_size;
899-
900-
mcps_req.f_buffer[0] = _compliance_test.app_data_buffer[0];
893+
test_req.f_buffer_size = _compliance_test.app_data_size;
894+
test_req.f_buffer[0] = _compliance_test.app_data_buffer[0];
901895
for(uint8_t i = 1; i < MIN(_compliance_test.app_data_size, MBED_CONF_LORA_TX_MAX_SIZE); ++i) {
902-
mcps_req.f_buffer[i] = _compliance_test.app_data_buffer[i];
896+
test_req.f_buffer[i] = _compliance_test.app_data_buffer[i];
903897
}
904898
break;
905899
case 1:
906-
mcps_req.f_buffer_size = 2;
907-
mcps_req.f_buffer[0] = _compliance_test.downlink_counter >> 8;
908-
mcps_req.f_buffer[1] = _compliance_test.downlink_counter;
900+
test_req.f_buffer_size = 2;
901+
test_req.f_buffer[0] = _compliance_test.downlink_counter >> 8;
902+
test_req.f_buffer[1] = _compliance_test.downlink_counter;
909903
break;
910904
}
911905
}
@@ -914,45 +908,32 @@ lorawan_status_t LoRaWANStack::send_compliance_test_frame_to_mac()
914908
//TODO: If port is not 224, this might not work!
915909
//Is there a test case where same _tx_msg's buffer would be used, when port is not 224???
916910
if (!_compliance_test.is_tx_confirmed) {
917-
mcps_req.type = MCPS_UNCONFIRMED;
918-
// mcps_req.f_buffer = _tx_msg.f_buffer;
919-
// mcps_req.f_buffer_size = _tx_msg.f_buffer_size;
920-
mcps_req.fport = _compliance_test.app_port;
921-
mcps_req.nb_trials = 1;
922-
mcps_req.data_rate = _loramac.get_default_tx_datarate();
911+
test_req.type = MCPS_UNCONFIRMED;
912+
test_req.fport = _compliance_test.app_port;
913+
test_req.nb_trials = 1;
914+
test_req.data_rate = _loramac.get_default_tx_datarate();
923915

924-
tr_info("Transmit unconfirmed compliance test frame %d bytes.", mcps_req.f_buffer_size);
916+
tr_info("Transmit unconfirmed compliance test frame %d bytes.", test_req.f_buffer_size);
925917

926-
for (uint8_t i = 0; i < mcps_req.f_buffer_size; ++i) {
927-
tr_info("Byte %d, data is 0x%x", i+1, ((uint8_t*)mcps_req.f_buffer)[i]);
918+
for (uint8_t i = 0; i < test_req.f_buffer_size; ++i) {
919+
tr_info("Byte %d, data is 0x%x", i+1, ((uint8_t*)test_req.f_buffer)[i]);
928920
}
929921
} else if (_compliance_test.is_tx_confirmed) {
930-
mcps_req.type = MCPS_CONFIRMED;
931-
// mcps_req.f_buffer = _tx_msg.f_buffer;
932-
// mcps_req.f_buffer_size = _tx_msg.f_buffer_size;
933-
mcps_req.fport = _compliance_test.app_port;
934-
mcps_req.nb_trials = _num_retry;
935-
mcps_req.data_rate = _loramac.get_default_tx_datarate();
922+
test_req.type = MCPS_CONFIRMED;
923+
test_req.fport = _compliance_test.app_port;
924+
test_req.nb_trials = _num_retry;
925+
test_req.data_rate = _loramac.get_default_tx_datarate();
936926

937-
tr_info("Transmit confirmed compliance test frame %d bytes.", mcps_req.f_buffer_size);
927+
tr_info("Transmit confirmed compliance test frame %d bytes.", test_req.f_buffer_size);
938928

939-
for (uint8_t i = 0; i < mcps_req.f_buffer_size; ++i) {
940-
tr_info("Byte %d, data is 0x%x", i+1, ((uint8_t*)mcps_req.f_buffer)[i]);
929+
for (uint8_t i = 0; i < test_req.f_buffer_size; ++i) {
930+
tr_info("Byte %d, data is 0x%x", i+1, ((uint8_t*)test_req.f_buffer)[i]);
941931
}
942932
} else {
943933
return LORAWAN_STATUS_SERVICE_UNKNOWN;
944934
}
945935

946-
return mcps_request_handler(&mcps_req);
947-
}
948-
949-
lorawan_status_t LoRaWANStack::mcps_request_handler(loramac_mcps_req_t *mcps_request)
950-
{
951-
if (mcps_request == NULL) {
952-
return LORAWAN_STATUS_PARAMETER_INVALID;
953-
}
954-
955-
return _loramac.mcps_request(mcps_request);
936+
return _loramac.test_request(&test_req);
956937
}
957938

958939
void LoRaWANStack::compliance_test_handler(loramac_mcps_indication_t *mcps_indication)
@@ -1035,8 +1016,6 @@ void LoRaWANStack::compliance_test_handler(loramac_mcps_indication_t *mcps_indic
10351016
_loramac.setup_link_check_request();
10361017
break;
10371018
case 6: // (ix)
1038-
loramac_mlme_req_t mlme_req;
1039-
10401019
// Disable TestMode and revert back to normal operation
10411020
_compliance_test.is_tx_confirmed = true;
10421021
_compliance_test.app_port = MBED_CONF_LORA_APP_PORT;

features/lorawan/LoRaWANStack.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -471,17 +471,11 @@ class LoRaWANStack: private mbed::NonCopyable<LoRaWANStack> {
471471
*/
472472
void compliance_test_handler(loramac_mcps_indication_t *mcps_indication);
473473

474-
/**
475-
* Used only for compliance testing
476-
*/
477-
lorawan_status_t mcps_request_handler(loramac_mcps_req_t *mcps_request);
478-
479474
/**
480475
* Used only for compliance testing
481476
*/
482477
lorawan_status_t send_compliance_test_frame_to_mac();
483478

484-
uint8_t compliance_test_buffer[MBED_CONF_LORA_TX_MAX_SIZE];
485479
compliance_test_t _compliance_test;
486480
#endif
487481
};

features/lorawan/lorastack/mac/LoRaMac.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1995,7 +1995,7 @@ lorawan_status_t LoRaMac::mlme_request( loramac_mlme_req_t *mlmeRequest )
19951995
return status;
19961996
}
19971997

1998-
lorawan_status_t LoRaMac::mcps_request( loramac_mcps_req_t *mcpsRequest )
1998+
lorawan_status_t LoRaMac::test_request( loramac_compliance_test_req_t *mcpsRequest )
19991999
{
20002000
if (_params.mac_state != LORAMAC_IDLE) {
20012001
return LORAWAN_STATUS_BUSY;

features/lorawan/lorastack/mac/LoRaMac.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -621,20 +621,20 @@ class LoRaMac {
621621
*
622622
* uint8_t buffer[] = {1, 2, 3};
623623
*
624-
* loramac_mcps_req_t request;
624+
* loramac_compliance_test_req_t request;
625625
* request.type = MCPS_UNCONFIRMED;
626626
* request.fport = 1;
627627
* request.f_buffer = buffer;
628628
* request.f_buffer_size = sizeof(buffer);
629629
*
630-
* if (mcps_request(&request) == LORAWAN_STATUS_OK) {
630+
* if (test_request(&request) == LORAWAN_STATUS_OK) {
631631
* // Service started successfully. Waiting for the MCPS-Confirm event
632632
* }
633633
*
634634
* @endcode
635635
*
636-
* @param [in] request The MCPS request to perform.
637-
* Refer to \ref loramac_mcps_req_t.
636+
* @param [in] request The test request to perform.
637+
* Refer to \ref loramac_compliance_test_req_t.
638638
*
639639
* @return `lorawan_status_t` The status of the operation. The possible values are:
640640
* \ref LORAWAN_STATUS_OK
@@ -645,7 +645,7 @@ class LoRaMac {
645645
* \ref LORAWAN_STATUS_LENGTH_ERROR
646646
* \ref LORAWAN_STATUS_DEVICE_OFF
647647
*/
648-
lorawan_status_t mcps_request(loramac_mcps_req_t *request);
648+
lorawan_status_t test_request(loramac_compliance_test_req_t *request);
649649

650650
/**
651651
* \brief LoRaMAC set tx timer.

features/lorawan/system/lorawan_data_structures.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,7 +1744,7 @@ typedef struct {
17441744

17451745
typedef struct {
17461746
/*!
1747-
* MCPS-Request type.
1747+
* Compiliance test request
17481748
*/
17491749
mcps_type_t type;
17501750

@@ -1786,14 +1786,15 @@ typedef struct {
17861786
*
17871787
* A pointer to the buffer of the frame payload.
17881788
*/
1789-
void *f_buffer;
1790-
/** Payload size
1791-
*
1792-
* The size of the frame payload.
1793-
*/
1794-
uint16_t f_buffer_size;
1789+
uint8_t f_buffer[LORAMAC_PHY_MAXPAYLOAD];
1790+
1791+
/** Payload size
1792+
*
1793+
* The size of the frame payload.
1794+
*/
1795+
uint16_t f_buffer_size;
17951796

1796-
} loramac_mcps_req_t;
1797+
} loramac_compliance_test_req_t;
17971798

17981799
/** LoRaWAN compliance tests support data
17991800
*
@@ -1822,7 +1823,7 @@ typedef struct compliance_test {
18221823
/** Data provided by application
18231824
*
18241825
*/
1825-
uint8_t *app_data_buffer;
1826+
uint8_t app_data_buffer[MBED_CONF_LORA_TX_MAX_SIZE];
18261827
/** Downlink counter
18271828
*
18281829
*/

0 commit comments

Comments
 (0)