Skip to content

Commit 4432ad9

Browse files
author
Hasnain Virk
committed
Major PHY layer modifications
The PHY layer had a lot of duplicated code in various geographic regions. In this commit we have tried to concentrate all common functionaliy into one single class which LoRaPHY that provides three kind of methods: i) Non virtual base methods which are there for upper layer use, e.g., providing access to driver or generic PHY layer functionality which needs to be exposed to upper layers. ii) Virtual methods (no hard limit on implementation) that can be overriden in derived classes. Some PHY implementations will need that as they may come with very peculiar channel schemes, e.g., dynamic channel schemes in US bands. iii) Protected methods which are only available for the derived PHYs We have adopted a mechanism for the dervied PHYs to announce their differenmtiating parameters in their constructors by filling up a data structure known as lora_phy_params_t which exists at base level. Access modifier for this data structure is protected so it can only be used by the base or derived classes, i.e., no exposure to upper layers. For extra functionality and differentiating controls, a derived PHY can override any virual method as necessary. In addition to that we have adopted the Mbed-OS style guide and have changed data structures and code to reflect that. Some data structures are removed. * Algorithm to get alternate DR is modified. Current scheme, works as multiples of 6 as EU and EU like PHYs provide 6 datarates. We make sure that we try a datarate at least once. If nuber of join retries is a multiple of 6, we may try multiple times on each data rate. * Most of the PHYs with dynamic channel plans, always override the above mentioned algorithm as the rules governing this algorithm do not hild in their case. * band_t data structure is enhanced with lower band frequency and higher band frequency. That enables us to validate frequency based upon the band and hence we can have a single function for all PHYs to validate frequency. * In some PHYs, there were some extra channel masks were defined which were not being used. Hence removed. * EIRP table corrected in some PHYs based upon spec. * PHY functions in response to Mac commands are renamed to reflect what they exactly do. for example accept_rx_param_setup_req() because that's what they do. they can either accept the mac command or reject it.# Please enter the commit message for your changes.
1 parent 5d98839 commit 4432ad9

33 files changed

+4079
-12890
lines changed

features/lorawan/LoRaWANStack.cpp

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,9 @@ lorawan_status_t LoRaWANStack::send_compliance_test_frame_to_mac()
224224
{
225225
loramac_mcps_req_t mcps_req;
226226

227-
GetPhyParams_t phy_params;
228-
PhyParam_t default_datarate;
229-
phy_params.Attribute = PHY_DEF_TX_DR;
227+
get_phy_params_t phy_params;
228+
phy_param_t default_datarate;
229+
phy_params.attribute = PHY_DEF_TX_DR;
230230
default_datarate = _lora_phy.get_phy_params(&phy_params);
231231

232232
prepare_special_tx_frame(_compliance_test.app_port);
@@ -236,7 +236,7 @@ lorawan_status_t LoRaWANStack::send_compliance_test_frame_to_mac()
236236
mcps_req.req.unconfirmed.fport = _compliance_test.app_port;
237237
mcps_req.f_buffer = _tx_msg.f_buffer;
238238
mcps_req.f_buffer_size = _tx_msg.f_buffer_size;
239-
mcps_req.req.unconfirmed.data_rate = default_datarate.Value;
239+
mcps_req.req.unconfirmed.data_rate = default_datarate.value;
240240

241241
tr_info("Transmit unconfirmed compliance test frame %d bytes.", mcps_req.f_buffer_size);
242242

@@ -249,7 +249,7 @@ lorawan_status_t LoRaWANStack::send_compliance_test_frame_to_mac()
249249
mcps_req.f_buffer = _tx_msg.f_buffer;
250250
mcps_req.f_buffer_size = _tx_msg.f_buffer_size;
251251
mcps_req.req.confirmed.nb_trials = _num_retry;
252-
mcps_req.req.confirmed.data_rate = default_datarate.Value;
252+
mcps_req.req.confirmed.data_rate = default_datarate.value;
253253

254254
tr_info("Transmit confirmed compliance test frame %d bytes.", mcps_req.f_buffer_size);
255255

@@ -286,9 +286,9 @@ lorawan_status_t LoRaWANStack::send_frame_to_mac()
286286
lorawan_status_t status;
287287
loramac_mib_req_confirm_t mib_get_params;
288288

289-
GetPhyParams_t phy_params;
290-
PhyParam_t default_datarate;
291-
phy_params.Attribute = PHY_DEF_TX_DR;
289+
get_phy_params_t phy_params;
290+
phy_param_t default_datarate;
291+
phy_params.attribute = PHY_DEF_TX_DR;
292292
default_datarate = _lora_phy.get_phy_params(&phy_params);
293293

294294
mcps_req.type = _tx_msg.type;
@@ -302,7 +302,7 @@ lorawan_status_t LoRaWANStack::send_frame_to_mac()
302302
mib_get_params.type = MIB_CHANNELS_DATARATE;
303303
if(mib_get_request(&mib_get_params) != LORAWAN_STATUS_OK) {
304304
tr_debug("Couldn't get MIB parameters: Using default data rate");
305-
mcps_req.req.unconfirmed.data_rate = default_datarate.Value;
305+
mcps_req.req.unconfirmed.data_rate = default_datarate.value;
306306
} else {
307307
mcps_req.req.unconfirmed.data_rate = mib_get_params.param.channel_data_rate;
308308
}
@@ -316,7 +316,7 @@ lorawan_status_t LoRaWANStack::send_frame_to_mac()
316316
mib_get_params.type = MIB_CHANNELS_DATARATE;
317317
if(mib_get_request(&mib_get_params) != LORAWAN_STATUS_OK) {
318318
tr_debug("Couldn't get MIB parameters: Using default data rate");
319-
mcps_req.req.confirmed.data_rate = default_datarate.Value;
319+
mcps_req.req.confirmed.data_rate = default_datarate.value;
320320
} else {
321321
mcps_req.req.confirmed.data_rate = mib_get_params.param.channel_data_rate;
322322
}
@@ -328,7 +328,7 @@ lorawan_status_t LoRaWANStack::send_frame_to_mac()
328328
mib_get_params.type = MIB_CHANNELS_DATARATE;
329329
if(mib_get_request(&mib_get_params) != LORAWAN_STATUS_OK) {
330330
tr_debug("Couldn't get MIB parameters: Using default data rate");
331-
mcps_req.req.proprietary.data_rate = default_datarate.Value;
331+
mcps_req.req.proprietary.data_rate = default_datarate.value;
332332
} else {
333333
mcps_req.req.proprietary.data_rate = mib_get_params.param.channel_data_rate;
334334
}
@@ -977,32 +977,21 @@ void LoRaWANStack::mcps_indication_handler(loramac_mcps_indication_t *mcps_indic
977977
break;
978978
default:
979979
if (is_port_valid(mcps_indication->port) == true ||
980-
mcps_indication->type == MCPS_PROPRIETARY) {
980+
mcps_indication->type == MCPS_PROPRIETARY) {
981981

982982
// Valid message arrived.
983-
// Save message to buffer with session information.
984-
if (_rx_msg.msg.mcps_indication.buffer_size > LORAMAC_PHY_MAXPAYLOAD) {
985-
// This may never happen as both radio and MAC are limited
986-
// to the size 255 bytes
987-
tr_debug("Cannot receive more than buffer capacity!");
988-
if (_callbacks.events) {
989-
const int ret = _queue->call(_callbacks.events, RX_ERROR);
990-
MBED_ASSERT(ret != 0);
991-
(void)ret;
992-
}
993-
return;
994-
} else {
995-
_rx_msg.type = LORAMAC_RX_MCPS_INDICATION;
996-
_rx_msg.msg.mcps_indication.buffer_size = mcps_indication->buffer_size;
997-
_rx_msg.msg.mcps_indication.port = mcps_indication->port;
998-
999-
// no copy, just set the pointer for the user
1000-
_rx_msg.msg.mcps_indication.buffer = mcps_indication->buffer;
1001-
}
983+
_rx_msg.type = LORAMAC_RX_MCPS_INDICATION;
984+
_rx_msg.msg.mcps_indication.buffer_size = mcps_indication->buffer_size;
985+
_rx_msg.msg.mcps_indication.port = mcps_indication->port;
986+
987+
// no copy, just set the pointer for the user
988+
_rx_msg.msg.mcps_indication.buffer =
989+
mcps_indication->buffer;
1002990

1003991
// Notify application about received frame..
1004992
tr_debug("Received %d bytes", _rx_msg.msg.mcps_indication.buffer_size);
1005993
_rx_msg.receive_ready = true;
994+
1006995
if (_callbacks.events) {
1007996
const int ret = _queue->call(_callbacks.events, RX_DONE);
1008997
MBED_ASSERT(ret != 0);

0 commit comments

Comments
 (0)