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.
pull/6059/head
Hasnain Virk 2018-01-16 16:58:18 +02:00
parent 5d98839092
commit 4432ad9ae7
33 changed files with 4116 additions and 12927 deletions

View File

@ -224,9 +224,9 @@ lorawan_status_t LoRaWANStack::send_compliance_test_frame_to_mac()
{
loramac_mcps_req_t mcps_req;
GetPhyParams_t phy_params;
PhyParam_t default_datarate;
phy_params.Attribute = PHY_DEF_TX_DR;
get_phy_params_t phy_params;
phy_param_t default_datarate;
phy_params.attribute = PHY_DEF_TX_DR;
default_datarate = _lora_phy.get_phy_params(&phy_params);
prepare_special_tx_frame(_compliance_test.app_port);
@ -236,7 +236,7 @@ lorawan_status_t LoRaWANStack::send_compliance_test_frame_to_mac()
mcps_req.req.unconfirmed.fport = _compliance_test.app_port;
mcps_req.f_buffer = _tx_msg.f_buffer;
mcps_req.f_buffer_size = _tx_msg.f_buffer_size;
mcps_req.req.unconfirmed.data_rate = default_datarate.Value;
mcps_req.req.unconfirmed.data_rate = default_datarate.value;
tr_info("Transmit unconfirmed compliance test frame %d bytes.", mcps_req.f_buffer_size);
@ -249,7 +249,7 @@ lorawan_status_t LoRaWANStack::send_compliance_test_frame_to_mac()
mcps_req.f_buffer = _tx_msg.f_buffer;
mcps_req.f_buffer_size = _tx_msg.f_buffer_size;
mcps_req.req.confirmed.nb_trials = _num_retry;
mcps_req.req.confirmed.data_rate = default_datarate.Value;
mcps_req.req.confirmed.data_rate = default_datarate.value;
tr_info("Transmit confirmed compliance test frame %d bytes.", mcps_req.f_buffer_size);
@ -286,9 +286,9 @@ lorawan_status_t LoRaWANStack::send_frame_to_mac()
lorawan_status_t status;
loramac_mib_req_confirm_t mib_get_params;
GetPhyParams_t phy_params;
PhyParam_t default_datarate;
phy_params.Attribute = PHY_DEF_TX_DR;
get_phy_params_t phy_params;
phy_param_t default_datarate;
phy_params.attribute = PHY_DEF_TX_DR;
default_datarate = _lora_phy.get_phy_params(&phy_params);
mcps_req.type = _tx_msg.type;
@ -302,7 +302,7 @@ lorawan_status_t LoRaWANStack::send_frame_to_mac()
mib_get_params.type = MIB_CHANNELS_DATARATE;
if(mib_get_request(&mib_get_params) != LORAWAN_STATUS_OK) {
tr_debug("Couldn't get MIB parameters: Using default data rate");
mcps_req.req.unconfirmed.data_rate = default_datarate.Value;
mcps_req.req.unconfirmed.data_rate = default_datarate.value;
} else {
mcps_req.req.unconfirmed.data_rate = mib_get_params.param.channel_data_rate;
}
@ -316,7 +316,7 @@ lorawan_status_t LoRaWANStack::send_frame_to_mac()
mib_get_params.type = MIB_CHANNELS_DATARATE;
if(mib_get_request(&mib_get_params) != LORAWAN_STATUS_OK) {
tr_debug("Couldn't get MIB parameters: Using default data rate");
mcps_req.req.confirmed.data_rate = default_datarate.Value;
mcps_req.req.confirmed.data_rate = default_datarate.value;
} else {
mcps_req.req.confirmed.data_rate = mib_get_params.param.channel_data_rate;
}
@ -328,7 +328,7 @@ lorawan_status_t LoRaWANStack::send_frame_to_mac()
mib_get_params.type = MIB_CHANNELS_DATARATE;
if(mib_get_request(&mib_get_params) != LORAWAN_STATUS_OK) {
tr_debug("Couldn't get MIB parameters: Using default data rate");
mcps_req.req.proprietary.data_rate = default_datarate.Value;
mcps_req.req.proprietary.data_rate = default_datarate.value;
} else {
mcps_req.req.proprietary.data_rate = mib_get_params.param.channel_data_rate;
}
@ -977,32 +977,21 @@ void LoRaWANStack::mcps_indication_handler(loramac_mcps_indication_t *mcps_indic
break;
default:
if (is_port_valid(mcps_indication->port) == true ||
mcps_indication->type == MCPS_PROPRIETARY) {
mcps_indication->type == MCPS_PROPRIETARY) {
// Valid message arrived.
// Save message to buffer with session information.
if (_rx_msg.msg.mcps_indication.buffer_size > LORAMAC_PHY_MAXPAYLOAD) {
// This may never happen as both radio and MAC are limited
// to the size 255 bytes
tr_debug("Cannot receive more than buffer capacity!");
if (_callbacks.events) {
const int ret = _queue->call(_callbacks.events, RX_ERROR);
MBED_ASSERT(ret != 0);
(void)ret;
}
return;
} else {
_rx_msg.type = LORAMAC_RX_MCPS_INDICATION;
_rx_msg.msg.mcps_indication.buffer_size = mcps_indication->buffer_size;
_rx_msg.msg.mcps_indication.port = mcps_indication->port;
_rx_msg.type = LORAMAC_RX_MCPS_INDICATION;
_rx_msg.msg.mcps_indication.buffer_size = mcps_indication->buffer_size;
_rx_msg.msg.mcps_indication.port = mcps_indication->port;
// no copy, just set the pointer for the user
_rx_msg.msg.mcps_indication.buffer = mcps_indication->buffer;
}
// no copy, just set the pointer for the user
_rx_msg.msg.mcps_indication.buffer =
mcps_indication->buffer;
// Notify application about received frame..
tr_debug("Received %d bytes", _rx_msg.msg.mcps_indication.buffer_size);
_rx_msg.receive_ready = true;
if (_callbacks.events) {
const int ret = _queue->call(_callbacks.events, RX_DONE);
MBED_ASSERT(ret != 0);

View File

@ -117,6 +117,7 @@ LoRaMac::LoRaMac(LoRaWANTimeHandler &lora_time)
_params.sys_params.max_duty_cycle = 0;
LoRaMacPrimitives = NULL;
ev_queue = NULL;
}
LoRaMac::~LoRaMac()
@ -218,9 +219,9 @@ void LoRaMac::handle_rx2_timer_event(void)
**************************************************************************/
void LoRaMac::OnRadioTxDone( void )
{
GetPhyParams_t getPhy;
PhyParam_t phyParam;
SetBandTxDoneParams_t txDone;
get_phy_params_t getPhy;
phy_param_t phyParam;
set_band_txdone_params_t txDone;
lorawan_time_t curTime = _lora_time.TimerGetCurrentTime( );
loramac_mlme_confirm_t mlme_confirm = mlme.get_confirmation();
@ -243,9 +244,9 @@ void LoRaMac::OnRadioTxDone( void )
}
if( ( _params.dev_class == CLASS_C ) || ( _params.is_node_ack_requested == true ) )
{
getPhy.Attribute = PHY_ACK_TIMEOUT;
getPhy.attribute = PHY_ACK_TIMEOUT;
phyParam = lora_phy->get_phy_params(&getPhy);
_lora_time.TimerStart( _params.timers.ack_timeout_timer, _params.rx_window2_delay + phyParam.Value );
_lora_time.TimerStart( _params.timers.ack_timeout_timer, _params.rx_window2_delay + phyParam.value );
}
}
else
@ -273,10 +274,10 @@ void LoRaMac::OnRadioTxDone( void )
// Store last Tx channel
_params.last_channel_idx = _params.channel;
// Update last tx done time for the current channel
txDone.Channel = _params.channel;
txDone.Joined = _params.is_nwk_joined;
txDone.LastTxDoneTime = curTime;
lora_phy->set_band_tx_done(&txDone);
txDone.channel = _params.channel;
txDone.joined = _params.is_nwk_joined;
txDone.last_tx_done_time = curTime;
lora_phy->set_last_tx_done(&txDone);
// Update Aggregated last tx done time
_params.timers.aggregated_last_tx_time = curTime;
@ -307,9 +308,9 @@ void LoRaMac::OnRadioRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8
{
loramac_mhdr_t macHdr;
loramac_frame_ctrl_t fCtrl;
ApplyCFListParams_t applyCFList;
GetPhyParams_t getPhy;
PhyParam_t phyParam;
cflist_params_t applyCFList;
get_phy_params_t getPhy;
phy_param_t phyParam;
bool skipIndication = false;
uint8_t pktHeaderLen = 0;
@ -416,9 +417,9 @@ void LoRaMac::OnRadioRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8
_params.sys_params.recv_delay2 = _params.sys_params.recv_delay1 + 1000;
// Apply CF list
applyCFList.Payload = &_params.payload[13];
applyCFList.payload = &_params.payload[13];
// Size of the regular payload is 12. Plus 1 byte MHDR and 4 bytes MIC
applyCFList.Size = size - 17;
applyCFList.size = size - 17;
lora_phy->apply_cf_list(&applyCFList);
@ -434,17 +435,16 @@ void LoRaMac::OnRadioRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8
case FRAME_TYPE_DATA_UNCONFIRMED_DOWN:
{
// Check if the received payload size is valid
getPhy.UplinkDwellTime = _params.sys_params.downlink_dwell_time;
getPhy.Datarate = mcps.get_indication().rx_datarate;
getPhy.Attribute = PHY_MAX_PAYLOAD;
getPhy.datarate = mcps.get_indication().rx_datarate;
getPhy.attribute = PHY_MAX_PAYLOAD;
// Get the maximum payload length
if( _params.is_repeater_supported == true )
{
getPhy.Attribute = PHY_MAX_PAYLOAD_REPEATER;
getPhy.attribute = PHY_MAX_PAYLOAD_REPEATER;
}
phyParam = lora_phy->get_phy_params(&getPhy);
if( MAX( 0, ( int16_t )( ( int16_t )size - ( int16_t )LORA_MAC_FRMPAYLOAD_OVERHEAD ) ) > (int32_t)phyParam.Value )
if( MAX( 0, ( int16_t )( ( int16_t )size - ( int16_t )LORA_MAC_FRMPAYLOAD_OVERHEAD ) ) > (int32_t)phyParam.value )
{
mcps.get_indication().status = LORAMAC_EVENT_INFO_STATUS_ERROR;
PrepareRxDoneAbort( );
@ -524,9 +524,9 @@ void LoRaMac::OnRadioRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8
}
// Check for a the maximum allowed counter difference
getPhy.Attribute = PHY_MAX_FCNT_GAP;
getPhy.attribute = PHY_MAX_FCNT_GAP;
phyParam = lora_phy->get_phy_params( &getPhy );
if( sequenceCounterDiff >= phyParam.Value )
if( sequenceCounterDiff >= phyParam.value )
{
mcps.get_indication().status = LORAMAC_EVENT_INFO_STATUS_DOWNLINK_TOO_MANY_FRAMES_LOSS;
mcps.get_indication().dl_frame_counter = downLinkCounter;
@ -856,8 +856,8 @@ void LoRaMac::OnRadioRxTimeout( void )
**************************************************************************/
void LoRaMac::OnMacStateCheckTimerEvent( void )
{
GetPhyParams_t getPhy;
PhyParam_t phyParam;
get_phy_params_t getPhy;
phy_param_t phyParam;
bool txTimeout = false;
_lora_time.TimerStop( _params.timers.mac_state_check_timer );
@ -970,11 +970,10 @@ void LoRaMac::OnMacStateCheckTimerEvent( void )
if( ( _params.ack_timeout_retry_counter % 2 ) == 1 )
{
getPhy.Attribute = PHY_NEXT_LOWER_TX_DR;
getPhy.UplinkDwellTime = _params.sys_params.uplink_dwell_time;
getPhy.Datarate = _params.sys_params.channel_data_rate;
getPhy.attribute = PHY_NEXT_LOWER_TX_DR;
getPhy.datarate = _params.sys_params.channel_data_rate;
phyParam = lora_phy->get_phy_params( &getPhy );
_params.sys_params.channel_data_rate = phyParam.Value;
_params.sys_params.channel_data_rate = phyParam.value;
}
// Try to send the frame again
if( ScheduleTx( ) == LORAWAN_STATUS_OK )
@ -1000,7 +999,7 @@ void LoRaMac::OnMacStateCheckTimerEvent( void )
}
else
{
lora_phy->load_defaults(INIT_TYPE_RESTORE);
lora_phy->restore_default_channels();
_params.mac_state &= ~LORAMAC_TX_RUNNING;
@ -1076,7 +1075,6 @@ void LoRaMac::OnTxDelayedTimerEvent( void )
{
loramac_mhdr_t macHdr;
loramac_frame_ctrl_t fCtrl;
AlternateDrParams_t altDr;
lorawan_status_t status = LORAWAN_STATUS_OK;
@ -1087,8 +1085,7 @@ void LoRaMac::OnTxDelayedTimerEvent( void )
{
ResetMacParameters( );
altDr.NbTrials = _params.join_request_trial_counter + 1;
_params.sys_params.channel_data_rate = lora_phy->get_alternate_DR(&altDr);
_params.sys_params.channel_data_rate = lora_phy->get_alternate_DR(_params.join_request_trial_counter + 1);
macHdr.value = 0;
macHdr.bits.mtype = FRAME_TYPE_JOIN_REQ;
@ -1179,23 +1176,22 @@ void LoRaMac::RxWindowSetup( bool rxContinuous, uint32_t maxRxWindow )
bool LoRaMac::ValidatePayloadLength( uint8_t lenN, int8_t datarate, uint8_t fOptsLen )
{
GetPhyParams_t getPhy;
PhyParam_t phyParam;
get_phy_params_t getPhy;
phy_param_t phyParam;
uint16_t maxN = 0;
uint16_t payloadSize = 0;
// Setup PHY request
getPhy.UplinkDwellTime = _params.sys_params.uplink_dwell_time;
getPhy.Datarate = datarate;
getPhy.Attribute = PHY_MAX_PAYLOAD;
getPhy.datarate = datarate;
getPhy.attribute = PHY_MAX_PAYLOAD;
// Get the maximum payload length
if( _params.is_repeater_supported == true )
{
getPhy.Attribute = PHY_MAX_PAYLOAD_REPEATER;
getPhy.attribute = PHY_MAX_PAYLOAD_REPEATER;
}
phyParam = lora_phy->get_phy_params(&getPhy);
maxN = phyParam.Value;
maxN = phyParam.value;
// Calculate the resulting payload size
payloadSize = ( lenN + fOptsLen );
@ -1249,9 +1245,9 @@ lorawan_status_t LoRaMac::Send( loramac_mhdr_t *macHdr, uint8_t fPort, void *fBu
lorawan_status_t LoRaMac::ScheduleTx( void )
{
lorawan_time_t dutyCycleTimeOff = 0;
NextChanParams_t nextChan;
GetPhyParams_t getPhy;
PhyParam_t phyParam;
channel_selection_params_t nextChan;
get_phy_params_t getPhy;
phy_param_t phyParam;
// Check if the device is off
if( _params.sys_params.max_duty_cycle == 255 )
@ -1266,31 +1262,30 @@ lorawan_status_t LoRaMac::ScheduleTx( void )
// Update Backoff
CalculateBackOff( _params.last_channel_idx );
nextChan.AggrTimeOff = _params.timers.aggregated_timeoff;
nextChan.Datarate = _params.sys_params.channel_data_rate;
nextChan.aggregate_timeoff = _params.timers.aggregated_timeoff;
nextChan.current_datarate = _params.sys_params.channel_data_rate;
_params.is_dutycycle_on = MBED_CONF_LORA_DUTY_CYCLE_ON;
nextChan.DutyCycleEnabled = _params.is_dutycycle_on;
nextChan.Joined = _params.is_nwk_joined;
nextChan.LastAggrTx = _params.timers.aggregated_last_tx_time;
nextChan.dc_enabled = _params.is_dutycycle_on;
nextChan.joined = _params.is_nwk_joined;
nextChan.last_aggregate_tx_time = _params.timers.aggregated_last_tx_time;
// Select channel
while( lora_phy->set_next_channel(&nextChan, &_params.channel, &dutyCycleTimeOff,
&_params.timers.aggregated_timeoff ) == false )
{
// Set the default datarate
getPhy.Attribute = PHY_DEF_TX_DR;
getPhy.attribute = PHY_DEF_TX_DR;
phyParam = lora_phy->get_phy_params( &getPhy );
_params.sys_params.channel_data_rate = phyParam.Value;
_params.sys_params.channel_data_rate = phyParam.value;
// Update datarate in the function parameters
nextChan.Datarate = _params.sys_params.channel_data_rate;
nextChan.current_datarate = _params.sys_params.channel_data_rate;
}
tr_debug("Next Channel Idx=%d, DR=%d", _params.channel, nextChan.Datarate);
tr_debug("Next Channel Idx=%d, DR=%d", _params.channel, nextChan.current_datarate);
// Compute Rx1 windows parameters
uint8_t dr_offset = lora_phy->apply_DR_offset(_params.sys_params.downlink_dwell_time,
_params.sys_params.channel_data_rate,
_params.sys_params.rx1_dr_offset);
uint8_t dr_offset = lora_phy->apply_DR_offset(_params.sys_params.channel_data_rate,
_params.sys_params.rx1_dr_offset);
lora_phy->compute_rx_win_params(dr_offset, _params.sys_params.min_rx_symb,
_params.sys_params.max_sys_rx_error,
@ -1338,15 +1333,15 @@ lorawan_status_t LoRaMac::ScheduleTx( void )
void LoRaMac::CalculateBackOff( uint8_t channel )
{
CalcBackOffParams_t calcBackOff;
backoff_params_t calcBackOff;
calcBackOff.Joined = _params.is_nwk_joined;
calcBackOff.joined = _params.is_nwk_joined;
_params.is_dutycycle_on = MBED_CONF_LORA_DUTY_CYCLE_ON;
calcBackOff.DutyCycleEnabled = _params.is_dutycycle_on;
calcBackOff.Channel = channel;
calcBackOff.ElapsedTime = _lora_time.TimerGetElapsedTime( _params.timers.mac_init_time );
calcBackOff.TxTimeOnAir = _params.timers.tx_toa;
calcBackOff.LastTxIsJoinRequest = _params.is_last_tx_join_request;
calcBackOff.dc_enabled = _params.is_dutycycle_on;
calcBackOff.channel = channel;
calcBackOff.elapsed_time = _lora_time.TimerGetElapsedTime( _params.timers.mac_init_time );
calcBackOff.tx_toa = _params.timers.tx_toa;
calcBackOff.last_tx_was_join_req = _params.is_last_tx_join_request;
// Update regional back-off
lora_phy->calculate_backoff(&calcBackOff);
@ -1358,8 +1353,8 @@ void LoRaMac::CalculateBackOff( uint8_t channel )
void LoRaMac::ResetMacParameters( void )
{
GetPhyParams_t getPhy;
PhyParam_t phyParam;
get_phy_params_t getPhy;
phy_param_t phyParam;
_params.is_nwk_joined = false;
@ -1383,37 +1378,37 @@ void LoRaMac::ResetMacParameters( void )
_params.is_rx_window_enabled = true;
getPhy.Attribute = PHY_DEF_TX_POWER;
getPhy.attribute = PHY_DEF_TX_POWER;
phyParam = lora_phy->get_phy_params( &getPhy );
_params.sys_params.channel_tx_power = phyParam.Value;
_params.sys_params.channel_tx_power = phyParam.value;
getPhy.Attribute = PHY_DEF_TX_DR;
getPhy.attribute = PHY_DEF_TX_DR;
phyParam = lora_phy->get_phy_params( &getPhy );
_params.sys_params.channel_data_rate = phyParam.Value;
_params.sys_params.channel_data_rate = phyParam.value;
getPhy.Attribute = PHY_DEF_DR1_OFFSET;
getPhy.attribute = PHY_DEF_DR1_OFFSET;
phyParam = lora_phy->get_phy_params( &getPhy );
_params.sys_params.rx1_dr_offset = phyParam.Value;
_params.sys_params.rx1_dr_offset = phyParam.value;
getPhy.Attribute = PHY_DEF_RX2_FREQUENCY;
getPhy.attribute = PHY_DEF_RX2_FREQUENCY;
phyParam = lora_phy->get_phy_params( &getPhy );
_params.sys_params.rx2_channel.frequency = phyParam.Value;
getPhy.Attribute = PHY_DEF_RX2_DR;
_params.sys_params.rx2_channel.frequency = phyParam.value;
getPhy.attribute = PHY_DEF_RX2_DR;
phyParam = lora_phy->get_phy_params( &getPhy );
_params.sys_params.rx2_channel.datarate = phyParam.Value;
_params.sys_params.rx2_channel.datarate = phyParam.value;
getPhy.Attribute = PHY_DEF_UPLINK_DWELL_TIME;
getPhy.attribute = PHY_DEF_UPLINK_DWELL_TIME;
phyParam = lora_phy->get_phy_params( &getPhy );
_params.sys_params.uplink_dwell_time = phyParam.Value;
_params.sys_params.uplink_dwell_time = phyParam.value;
getPhy.Attribute = PHY_DEF_MAX_EIRP;
getPhy.attribute = PHY_DEF_MAX_EIRP;
phyParam = lora_phy->get_phy_params( &getPhy );
_params.sys_params.max_eirp = phyParam.Value;
_params.sys_params.max_eirp = phyParam.value;
getPhy.Attribute = PHY_DEF_ANTENNA_GAIN;
getPhy.attribute = PHY_DEF_ANTENNA_GAIN;
phyParam = lora_phy->get_phy_params( &getPhy );
_params.sys_params.antenna_gain = phyParam.Value;
_params.sys_params.antenna_gain = phyParam.value;
_params.is_node_ack_requested = false;
_params.is_srv_ack_requested = false;
@ -1457,7 +1452,6 @@ static void memcpy_convert_endianess( uint8_t *dst, const uint8_t *src, uint16_t
lorawan_status_t LoRaMac::PrepareFrame( loramac_mhdr_t *macHdr, loramac_frame_ctrl_t *fCtrl, uint8_t fPort, void *fBuffer, uint16_t fBufferSize )
{
AdrNextParams_t adrNext;
uint16_t i;
uint8_t pktHeaderLen = 0;
uint32_t mic = 0;
@ -1517,18 +1511,14 @@ lorawan_status_t LoRaMac::PrepareFrame( loramac_mhdr_t *macHdr, loramac_frame_ct
return LORAWAN_STATUS_NO_NETWORK_JOINED; // No network has been joined yet
}
// Adr next request
adrNext.UpdateChanMask = true;
adrNext.AdrEnabled = fCtrl->bits.adr;
adrNext.AdrAckCounter = _params.adr_ack_counter;
adrNext.Datarate = _params.sys_params.channel_data_rate;
adrNext.TxPower = _params.sys_params.channel_tx_power;
adrNext.UplinkDwellTime = _params.sys_params.uplink_dwell_time;
fCtrl->bits.adr_ack_req = lora_phy->get_next_ADR(&adrNext,
&_params.sys_params.channel_data_rate,
&_params.sys_params.channel_tx_power,
&_params.adr_ack_counter);
if (_params.sys_params.adr_on) {
if (lora_phy->get_next_ADR(true,
_params.sys_params.channel_data_rate,
_params.sys_params.channel_tx_power,
_params.adr_ack_counter)) {
fCtrl->bits.adr_ack_req = 1;
}
}
if( _params.is_srv_ack_requested == true )
{
@ -1655,17 +1645,17 @@ lorawan_status_t LoRaMac::PrepareFrame( loramac_mhdr_t *macHdr, loramac_frame_ct
lorawan_status_t LoRaMac::SendFrameOnChannel( uint8_t channel )
{
TxConfigParams_t txConfig;
tx_config_params_t tx_config;
int8_t txPower = 0;
txConfig.Channel = channel;
txConfig.Datarate = _params.sys_params.channel_data_rate;
txConfig.TxPower = _params.sys_params.channel_tx_power;
txConfig.MaxEirp = _params.sys_params.max_eirp;
txConfig.AntennaGain = _params.sys_params.antenna_gain;
txConfig.PktLen = _params.buffer_pkt_len;
tx_config.channel = channel;
tx_config.datarate = _params.sys_params.channel_data_rate;
tx_config.tx_power = _params.sys_params.channel_tx_power;
tx_config.max_eirp = _params.sys_params.max_eirp;
tx_config.antenna_gain = _params.sys_params.antenna_gain;
tx_config.pkt_len = _params.buffer_pkt_len;
lora_phy->tx_config(&txConfig, &txPower, &_params.timers.tx_toa);
lora_phy->tx_config(&tx_config, &txPower, &_params.timers.tx_toa);
mlme.get_confirmation().status = LORAMAC_EVENT_INFO_STATUS_ERROR;
@ -1695,14 +1685,14 @@ lorawan_status_t LoRaMac::SendFrameOnChannel( uint8_t channel )
lorawan_status_t LoRaMac::SetTxContinuousWave( uint16_t timeout )
{
ContinuousWaveParams_t continuousWave;
cw_mode_params_t continuousWave;
continuousWave.Channel = _params.channel;
continuousWave.Datarate = _params.sys_params.channel_data_rate;
continuousWave.TxPower = _params.sys_params.channel_tx_power;
continuousWave.MaxEirp = _params.sys_params.max_eirp;
continuousWave.AntennaGain = _params.sys_params.antenna_gain;
continuousWave.Timeout = timeout;
continuousWave.channel = _params.channel;
continuousWave.datarate = _params.sys_params.channel_data_rate;
continuousWave.tx_power = _params.sys_params.channel_tx_power;
continuousWave.max_eirp = _params.sys_params.max_eirp;
continuousWave.antenna_gain = _params.sys_params.antenna_gain;
continuousWave.timeout = timeout;
lora_phy->set_tx_cont_mode(&continuousWave);
@ -1716,7 +1706,16 @@ lorawan_status_t LoRaMac::SetTxContinuousWave( uint16_t timeout )
lorawan_status_t LoRaMac::SetTxContinuousWave1( uint16_t timeout, uint32_t frequency, uint8_t power )
{
lora_phy->setup_tx_cont_wave_mode(frequency, power, timeout);
cw_mode_params_t continuousWave;
continuousWave.channel = 0;
continuousWave.datarate = 0;
continuousWave.tx_power = power;
continuousWave.max_eirp = 0;
continuousWave.antenna_gain = 0;
continuousWave.timeout = timeout;
lora_phy->set_tx_cont_mode(&continuousWave);
// Starts the MAC layer status check timer
_lora_time.TimerStart( _params.timers.mac_state_check_timer, MAC_STATE_CHECK_TIMEOUT );
@ -1730,8 +1729,8 @@ lorawan_status_t LoRaMac::LoRaMacInitialization(loramac_primitives_t *primitives
LoRaPHY *phy,
EventQueue *queue)
{
GetPhyParams_t getPhy;
PhyParam_t phyParam;
get_phy_params_t getPhy;
phy_param_t phyParam;
//store event queue pointer
ev_queue = queue;
@ -1771,68 +1770,66 @@ lorawan_status_t LoRaMac::LoRaMacInitialization(loramac_primitives_t *primitives
_params.timers.aggregated_timeoff = 0;
// Reset to defaults
getPhy.Attribute = PHY_DUTY_CYCLE;
getPhy.attribute = PHY_DUTY_CYCLE;
phyParam = lora_phy->get_phy_params(&getPhy);
// load default at this moment. Later can be changed using json
_params.is_dutycycle_on = ( bool ) phyParam.Value;
_params.is_dutycycle_on = ( bool ) phyParam.value;
getPhy.Attribute = PHY_DEF_TX_POWER;
getPhy.attribute = PHY_DEF_TX_POWER;
phyParam = lora_phy->get_phy_params( &getPhy );
_params.sys_params.channel_tx_power = phyParam.Value;
_params.sys_params.channel_tx_power = phyParam.value;
getPhy.Attribute = PHY_DEF_TX_DR;
getPhy.attribute = PHY_DEF_TX_DR;
phyParam = lora_phy->get_phy_params( &getPhy );
_params.sys_params.channel_data_rate = phyParam.Value;
_params.sys_params.channel_data_rate = phyParam.value;
getPhy.Attribute = PHY_MAX_RX_WINDOW;
getPhy.attribute = PHY_MAX_RX_WINDOW;
phyParam = lora_phy->get_phy_params( &getPhy );
_params.sys_params.max_rx_win_time = phyParam.Value;
_params.sys_params.max_rx_win_time = phyParam.value;
getPhy.Attribute = PHY_RECEIVE_DELAY1;
getPhy.attribute = PHY_RECEIVE_DELAY1;
phyParam = lora_phy->get_phy_params( &getPhy );
_params.sys_params.recv_delay1 = phyParam.Value;
_params.sys_params.recv_delay1 = phyParam.value;
getPhy.Attribute = PHY_RECEIVE_DELAY2;
getPhy.attribute = PHY_RECEIVE_DELAY2;
phyParam = lora_phy->get_phy_params( &getPhy );
_params.sys_params.recv_delay2 = phyParam.Value;
_params.sys_params.recv_delay2 = phyParam.value;
getPhy.Attribute = PHY_JOIN_ACCEPT_DELAY1;
getPhy.attribute = PHY_JOIN_ACCEPT_DELAY1;
phyParam = lora_phy->get_phy_params( &getPhy );
_params.sys_params.join_accept_delay1 = phyParam.Value;
_params.sys_params.join_accept_delay1 = phyParam.value;
getPhy.Attribute = PHY_JOIN_ACCEPT_DELAY2;
getPhy.attribute = PHY_JOIN_ACCEPT_DELAY2;
phyParam = lora_phy->get_phy_params( &getPhy );
_params.sys_params.join_accept_delay2 = phyParam.Value;
_params.sys_params.join_accept_delay2 = phyParam.value;
getPhy.Attribute = PHY_DEF_DR1_OFFSET;
getPhy.attribute = PHY_DEF_DR1_OFFSET;
phyParam = lora_phy->get_phy_params( &getPhy );
_params.sys_params.rx1_dr_offset = phyParam.Value;
_params.sys_params.rx1_dr_offset = phyParam.value;
getPhy.Attribute = PHY_DEF_RX2_FREQUENCY;
getPhy.attribute = PHY_DEF_RX2_FREQUENCY;
phyParam = lora_phy->get_phy_params( &getPhy );
_params.sys_params.rx2_channel.frequency = phyParam.Value;
_params.sys_params.rx2_channel.frequency = phyParam.value;
getPhy.Attribute = PHY_DEF_RX2_DR;
getPhy.attribute = PHY_DEF_RX2_DR;
phyParam = lora_phy->get_phy_params( &getPhy );
_params.sys_params.rx2_channel.datarate = phyParam.Value;
_params.sys_params.rx2_channel.datarate = phyParam.value;
getPhy.Attribute = PHY_DEF_UPLINK_DWELL_TIME;
getPhy.attribute = PHY_DEF_UPLINK_DWELL_TIME;
phyParam = lora_phy->get_phy_params( &getPhy );
_params.sys_params.uplink_dwell_time = phyParam.Value;
_params.sys_params.uplink_dwell_time = phyParam.value;
getPhy.Attribute = PHY_DEF_DOWNLINK_DWELL_TIME;
getPhy.attribute = PHY_DEF_DOWNLINK_DWELL_TIME;
phyParam = lora_phy->get_phy_params( &getPhy );
_params.sys_params.downlink_dwell_time = phyParam.Value;
_params.sys_params.downlink_dwell_time = phyParam.value;
getPhy.Attribute = PHY_DEF_MAX_EIRP;
getPhy.attribute = PHY_DEF_MAX_EIRP;
phyParam = lora_phy->get_phy_params( &getPhy );
_params.sys_params.max_eirp = phyParam.fValue;
_params.sys_params.max_eirp = phyParam.f_value;
getPhy.Attribute = PHY_DEF_ANTENNA_GAIN;
getPhy.attribute = PHY_DEF_ANTENNA_GAIN;
phyParam = lora_phy->get_phy_params( &getPhy );
_params.sys_params.antenna_gain = phyParam.fValue;
lora_phy->load_defaults(INIT_TYPE_INIT);
_params.sys_params.antenna_gain = phyParam.f_value;
// Init parameters which are not set in function ResetMacParameters
_params.sys_params.max_sys_rx_error = 10;
@ -1898,11 +1895,9 @@ void LoRaMac::disconnect()
lorawan_status_t LoRaMac::LoRaMacQueryTxPossible( uint8_t size, loramac_tx_info_t* txInfo )
{
AdrNextParams_t adrNext;
GetPhyParams_t getPhy;
PhyParam_t phyParam;
int8_t datarate = _params.sys_params.channel_data_rate;
int8_t txPower = _params.sys_params.channel_tx_power;
get_phy_params_t getPhy;
phy_param_t phyParam;
uint8_t fOptLen = mac_commands.GetLength() + mac_commands.GetRepeatLength();
if( txInfo == NULL )
@ -1910,30 +1905,24 @@ lorawan_status_t LoRaMac::LoRaMacQueryTxPossible( uint8_t size, loramac_tx_info_
return LORAWAN_STATUS_PARAMETER_INVALID;
}
// Setup ADR request
adrNext.UpdateChanMask = false;
adrNext.AdrEnabled = _params.sys_params.adr_on;
adrNext.AdrAckCounter = _params.adr_ack_counter;
adrNext.Datarate = _params.sys_params.channel_data_rate;
adrNext.TxPower = _params.sys_params.channel_tx_power;
adrNext.UplinkDwellTime = _params.sys_params.uplink_dwell_time;
// We call the function for information purposes only. We don't want to
// apply the datarate, the tx power and the ADR ack counter.
lora_phy->get_next_ADR(&adrNext, &datarate, &txPower, &_params.adr_ack_counter);
// if applicaion has turned on ADR, we want to opt it out
if (_params.sys_params.adr_on) {
lora_phy->get_next_ADR(false, _params.sys_params.channel_data_rate,
_params.sys_params.channel_tx_power,
_params.adr_ack_counter);
}
// Setup PHY request
getPhy.UplinkDwellTime = _params.sys_params.uplink_dwell_time;
getPhy.Datarate = datarate;
getPhy.Attribute = PHY_MAX_PAYLOAD;
getPhy.datarate = _params.sys_params.channel_data_rate;
getPhy.attribute = PHY_MAX_PAYLOAD;
// Change request in case repeater is supported
if( _params.is_repeater_supported == true )
{
getPhy.Attribute = PHY_MAX_PAYLOAD_REPEATER;
getPhy.attribute = PHY_MAX_PAYLOAD_REPEATER;
}
phyParam = lora_phy->get_phy_params( &getPhy );
txInfo->current_payload_size = phyParam.Value;
txInfo->current_payload_size = phyParam.value;
// Verify if the fOpts fit into the maximum payload
if( txInfo->current_payload_size >= fOptLen )
@ -1951,7 +1940,8 @@ lorawan_status_t LoRaMac::LoRaMacQueryTxPossible( uint8_t size, loramac_tx_info_
}
// Verify if the fOpts and the payload fit into the maximum payload
if( ValidatePayloadLength( size, datarate, fOptLen ) == false )
if( ValidatePayloadLength( size, _params.sys_params.channel_data_rate,
fOptLen ) == false )
{
return LORAWAN_STATUS_LENGTH_ERROR;
}

View File

@ -41,7 +41,6 @@
#define __LORAMAC_H__
#include "lorawan/system/LoRaWANTimer.h"
#include "netsocket/LoRaRadio.h"
#include "lorastack/phy/LoRaPHY.h"
#include "lorawan/system/lorawan_data_structures.h"
#include "lorastack/mac/LoRaMacCommand.h"

View File

@ -41,18 +41,17 @@ void LoRaMacChannelPlan::activate_channelplan_subsystem(LoRaPHY *phy, LoRaMacMib
lorawan_status_t LoRaMacChannelPlan::set_plan(const lorawan_channelplan_t& plan)
{
ChannelAddParams_t channelAdd;
channel_params_t mac_layer_ch_params;
lorawan_status_t status;
GetPhyParams_t get_phy;
PhyParam_t phy_param;
get_phy_params_t get_phy;
phy_param_t phy_param;
uint8_t max_num_channels;
// Check first how many channels the selected PHY layer supports
get_phy.Attribute = PHY_MAX_NB_CHANNELS;
get_phy.attribute = PHY_MAX_NB_CHANNELS;
phy_param = _lora_phy->get_phy_params(&get_phy);
max_num_channels = (uint8_t) phy_param.Value;
max_num_channels = (uint8_t) phy_param.value;
// check if user is setting more channels than supported
if (plan.nb_channels > max_num_channels) {
@ -60,22 +59,16 @@ lorawan_status_t LoRaMacChannelPlan::set_plan(const lorawan_channelplan_t& plan)
}
for (uint8_t i = 0; i < plan.nb_channels; i++) {
mac_layer_ch_params.band = plan.channels[i].ch_param.band;
mac_layer_ch_params.dr_range.fields.max =
plan.channels[i].ch_param.dr_range.fields.max;
mac_layer_ch_params.dr_range.fields.min =
plan.channels[i].ch_param.dr_range.fields.min;
mac_layer_ch_params.dr_range.value =
plan.channels[i].ch_param.dr_range.value;
mac_layer_ch_params.frequency =
plan.channels[i].ch_param.frequency;
mac_layer_ch_params.rx1_frequency =
plan.channels[i].ch_param.rx1_frequency;
channelAdd.ChannelId = plan.channels[i].id;
channelAdd.NewChannel = &mac_layer_ch_params;
mac_layer_ch_params.dr_range.fields.max = plan.channels[i].ch_param.dr_range.fields.max;
mac_layer_ch_params.dr_range.fields.min = plan.channels[i].ch_param.dr_range.fields.min;
mac_layer_ch_params.dr_range.value = plan.channels[i].ch_param.dr_range.value;
mac_layer_ch_params.frequency = plan.channels[i].ch_param.frequency;
mac_layer_ch_params.rx1_frequency = plan.channels[i].ch_param.rx1_frequency;
status = _lora_phy->add_channel(&channelAdd);
status = _lora_phy->add_channel(&mac_layer_ch_params, plan.channels[i].id);
if (status != LORAWAN_STATUS_OK) {
return status;
@ -95,21 +88,21 @@ lorawan_status_t LoRaMacChannelPlan::get_plan(lorawan_channelplan_t& plan,
loramac_mib_req_confirm_t mib_confirm;
lorawan_status_t status;
GetPhyParams_t get_phy;
PhyParam_t phy_param;
get_phy_params_t get_phy;
phy_param_t phy_param;
uint8_t max_num_channels;
uint16_t *channel_masks;
uint8_t count = 0;
// Check first how many channels the selected PHY layer supports
get_phy.Attribute = PHY_MAX_NB_CHANNELS;
get_phy.attribute = PHY_MAX_NB_CHANNELS;
phy_param = _lora_phy->get_phy_params(&get_phy);
max_num_channels = (uint8_t) phy_param.Value;
max_num_channels = (uint8_t) phy_param.value;
// Now check the Default channel mask
get_phy.Attribute = PHY_CHANNELS_MASK;
get_phy.attribute = PHY_CHANNELS_MASK;
phy_param = _lora_phy->get_phy_params(&get_phy);
channel_masks = phy_param.ChannelsMask;
channel_masks = phy_param.channel_mask;
// Request Mib to get channels
memset(&mib_confirm, 0, sizeof(mib_confirm));
@ -147,26 +140,26 @@ lorawan_status_t LoRaMacChannelPlan::remove_plan()
{
lorawan_status_t status = LORAWAN_STATUS_OK;
GetPhyParams_t get_phy;
PhyParam_t phy_param;
get_phy_params_t get_phy;
phy_param_t phy_param;
uint8_t max_num_channels;
uint16_t *channel_masks;
uint16_t *default_channel_masks;
// Check first how many channels the selected PHY layer supports
get_phy.Attribute = PHY_MAX_NB_CHANNELS;
get_phy.attribute = PHY_MAX_NB_CHANNELS;
phy_param = _lora_phy->get_phy_params(&get_phy);
max_num_channels = (uint8_t) phy_param.Value;
max_num_channels = (uint8_t) phy_param.value;
// Now check the channel mask for enabled channels
get_phy.Attribute = PHY_CHANNELS_MASK;
get_phy.attribute = PHY_CHANNELS_MASK;
phy_param = _lora_phy->get_phy_params(&get_phy);
channel_masks = phy_param.ChannelsMask;
channel_masks = phy_param.channel_mask;
// Now check the channel mask for default channels
get_phy.Attribute = PHY_CHANNELS_DEFAULT_MASK;
get_phy.attribute = PHY_CHANNELS_DEFAULT_MASK;
phy_param = _lora_phy->get_phy_params(&get_phy);
default_channel_masks = phy_param.ChannelsMask;
default_channel_masks = phy_param.channel_mask;
for (uint8_t i = 0; i < max_num_channels; i++) {
// skip any default channels
@ -191,16 +184,15 @@ lorawan_status_t LoRaMacChannelPlan::remove_plan()
lorawan_status_t LoRaMacChannelPlan::remove_single_channel(uint8_t channel_id)
{
GetPhyParams_t get_phy;
PhyParam_t phy_param;
get_phy_params_t get_phy;
phy_param_t phy_param;
uint8_t max_num_channels;
uint16_t *channel_masks;
ChannelRemoveParams_t channelRemove;
// Check first how many channels the selected PHY layer supports
get_phy.Attribute = PHY_MAX_NB_CHANNELS;
get_phy.attribute = PHY_MAX_NB_CHANNELS;
phy_param = _lora_phy->get_phy_params(&get_phy);
max_num_channels = (uint8_t) phy_param.Value;
max_num_channels = (uint8_t) phy_param.value;
// According to specification channel IDs start from 0 and last valid
// channel ID is N-1 where N=MAX_NUM_CHANNELS.
@ -210,9 +202,9 @@ lorawan_status_t LoRaMacChannelPlan::remove_single_channel(uint8_t channel_id)
}
// Now check the Default channel mask
get_phy.Attribute = PHY_CHANNELS_DEFAULT_MASK;
get_phy.attribute = PHY_CHANNELS_DEFAULT_MASK;
phy_param = _lora_phy->get_phy_params(&get_phy);
channel_masks = phy_param.ChannelsMask;
channel_masks = phy_param.channel_mask;
// check if the channel ID give belongs to a default channel
// Mostly the default channels are in the first mask if the region
@ -222,9 +214,7 @@ lorawan_status_t LoRaMacChannelPlan::remove_single_channel(uint8_t channel_id)
return LORAWAN_STATUS_PARAMETER_INVALID;
}
channelRemove.ChannelId = channel_id;
if(_lora_phy->remove_channel(&channelRemove) == false)
if(_lora_phy->remove_channel(channel_id) == false)
{
return LORAWAN_STATUS_PARAMETER_INVALID;
}

View File

@ -273,20 +273,20 @@ lorawan_status_t LoRaMacCommand::ProcessMacCommands(uint8_t *payload, uint8_t ma
break;
case SRV_MAC_LINK_ADR_REQ:
{
LinkAdrReqParams_t linkAdrReq;
adr_req_params_t linkAdrReq;
int8_t linkAdrDatarate = DR_0;
int8_t linkAdrTxPower = TX_POWER_0;
uint8_t linkAdrNbRep = 0;
uint8_t linkAdrNbBytesParsed = 0;
// Fill parameter structure
linkAdrReq.Payload = &payload[macIndex - 1];
linkAdrReq.PayloadSize = commandsSize - ( macIndex - 1 );
linkAdrReq.AdrEnabled = LoRaMacParams.adr_on;
linkAdrReq.UplinkDwellTime = LoRaMacParams.uplink_dwell_time;
linkAdrReq.CurrentDatarate = LoRaMacParams.channel_data_rate;
linkAdrReq.CurrentTxPower = LoRaMacParams.channel_tx_power;
linkAdrReq.CurrentNbRep = LoRaMacParams.retry_num;
linkAdrReq.payload = &payload[macIndex - 1];
linkAdrReq.payload_size = commandsSize - ( macIndex - 1 );
linkAdrReq.adr_enabled = LoRaMacParams.adr_on;
linkAdrReq.ul_dwell_time = LoRaMacParams.uplink_dwell_time;
linkAdrReq.current_datarate = LoRaMacParams.channel_data_rate;
linkAdrReq.current_tx_power = LoRaMacParams.channel_tx_power;
linkAdrReq.current_nb_rep = LoRaMacParams.retry_num;
// Process the ADR requests
status = lora_phy.link_ADR_request(&linkAdrReq, &linkAdrDatarate,
@ -316,25 +316,25 @@ lorawan_status_t LoRaMacCommand::ProcessMacCommands(uint8_t *payload, uint8_t ma
break;
case SRV_MAC_RX_PARAM_SETUP_REQ:
{
RxParamSetupReqParams_t rxParamSetupReq;
rx_param_setup_req_t rxParamSetupReq;
rxParamSetupReq.DrOffset = ( payload[macIndex] >> 4 ) & 0x07;
rxParamSetupReq.Datarate = payload[macIndex] & 0x0F;
rxParamSetupReq.dr_offset = ( payload[macIndex] >> 4 ) & 0x07;
rxParamSetupReq.datarate = payload[macIndex] & 0x0F;
macIndex++;
rxParamSetupReq.Frequency = ( uint32_t )payload[macIndex++];
rxParamSetupReq.Frequency |= ( uint32_t )payload[macIndex++] << 8;
rxParamSetupReq.Frequency |= ( uint32_t )payload[macIndex++] << 16;
rxParamSetupReq.Frequency *= 100;
rxParamSetupReq.frequency = ( uint32_t )payload[macIndex++];
rxParamSetupReq.frequency |= ( uint32_t )payload[macIndex++] << 8;
rxParamSetupReq.frequency |= ( uint32_t )payload[macIndex++] << 16;
rxParamSetupReq.frequency *= 100;
// Perform request on region
status = lora_phy.setup_rx_params(&rxParamSetupReq);
status = lora_phy.accept_rx_param_setup_req(&rxParamSetupReq);
if( ( status & 0x07 ) == 0x07 )
{
LoRaMacParams.rx2_channel.datarate = rxParamSetupReq.Datarate;
LoRaMacParams.rx2_channel.frequency = rxParamSetupReq.Frequency;
LoRaMacParams.rx1_dr_offset = rxParamSetupReq.DrOffset;
LoRaMacParams.rx2_channel.datarate = rxParamSetupReq.datarate;
LoRaMacParams.rx2_channel.frequency = rxParamSetupReq.frequency;
LoRaMacParams.rx1_dr_offset = rxParamSetupReq.dr_offset;
}
ret_value = AddMacCommand( MOTE_MAC_RX_PARAM_SETUP_ANS, status, 0 );
}
@ -349,11 +349,11 @@ lorawan_status_t LoRaMacCommand::ProcessMacCommands(uint8_t *payload, uint8_t ma
}
case SRV_MAC_NEW_CHANNEL_REQ:
{
NewChannelReqParams_t newChannelReq;
new_channel_req_params_t newChannelReq;
channel_params_t chParam;
newChannelReq.ChannelId = payload[macIndex++];
newChannelReq.NewChannel = &chParam;
newChannelReq.channel_id = payload[macIndex++];
newChannelReq.new_channel = &chParam;
chParam.frequency = ( uint32_t )payload[macIndex++];
chParam.frequency |= ( uint32_t )payload[macIndex++] << 8;
@ -382,29 +382,29 @@ lorawan_status_t LoRaMacCommand::ProcessMacCommands(uint8_t *payload, uint8_t ma
break;
case SRV_MAC_TX_PARAM_SETUP_REQ:
{
TxParamSetupReqParams_t txParamSetupReq;
tx_param_setup_req_t txParamSetupReq;
uint8_t eirpDwellTime = payload[macIndex++];
txParamSetupReq.UplinkDwellTime = 0;
txParamSetupReq.DownlinkDwellTime = 0;
txParamSetupReq.ul_dwell_time = 0;
txParamSetupReq.dl_dwell_time = 0;
if( ( eirpDwellTime & 0x20 ) == 0x20 )
{
txParamSetupReq.DownlinkDwellTime = 1;
txParamSetupReq.dl_dwell_time = 1;
}
if( ( eirpDwellTime & 0x10 ) == 0x10 )
{
txParamSetupReq.UplinkDwellTime = 1;
txParamSetupReq.ul_dwell_time = 1;
}
txParamSetupReq.MaxEirp = eirpDwellTime & 0x0F;
txParamSetupReq.max_eirp = eirpDwellTime & 0x0F;
// Check the status for correctness
if( lora_phy.setup_tx_params(&txParamSetupReq ) != -1 )
if(lora_phy.accept_tx_param_setup_req(&txParamSetupReq))
{
// Accept command
LoRaMacParams.uplink_dwell_time = txParamSetupReq.UplinkDwellTime;
LoRaMacParams.downlink_dwell_time = txParamSetupReq.DownlinkDwellTime;
LoRaMacParams.max_eirp = LoRaMacMaxEirpTable[txParamSetupReq.MaxEirp];
LoRaMacParams.uplink_dwell_time = txParamSetupReq.ul_dwell_time;
LoRaMacParams.downlink_dwell_time = txParamSetupReq.dl_dwell_time;
LoRaMacParams.max_eirp = LoRaMacMaxEirpTable[txParamSetupReq.max_eirp];
// Add command response
ret_value = AddMacCommand( MOTE_MAC_TX_PARAM_SETUP_ANS, 0, 0 );
}
@ -412,13 +412,13 @@ lorawan_status_t LoRaMacCommand::ProcessMacCommands(uint8_t *payload, uint8_t ma
break;
case SRV_MAC_DL_CHANNEL_REQ:
{
DlChannelReqParams_t dlChannelReq;
dl_channel_req_params_t dlChannelReq;
dlChannelReq.ChannelId = payload[macIndex++];
dlChannelReq.Rx1Frequency = ( uint32_t )payload[macIndex++];
dlChannelReq.Rx1Frequency |= ( uint32_t )payload[macIndex++] << 8;
dlChannelReq.Rx1Frequency |= ( uint32_t )payload[macIndex++] << 16;
dlChannelReq.Rx1Frequency *= 100;
dlChannelReq.channel_id = payload[macIndex++];
dlChannelReq.rx1_frequency = ( uint32_t )payload[macIndex++];
dlChannelReq.rx1_frequency |= ( uint32_t )payload[macIndex++] << 8;
dlChannelReq.rx1_frequency |= ( uint32_t )payload[macIndex++] << 16;
dlChannelReq.rx1_frequency *= 100;
status = lora_phy.dl_channel_request(&dlChannelReq);

View File

@ -49,11 +49,11 @@ lorawan_status_t LoRaMacMcps::set_request(loramac_mcps_req_t *mcpsRequest,
return LORAWAN_STATUS_PARAMETER_INVALID;
}
GetPhyParams_t getPhy;
PhyParam_t phyParam;
get_phy_params_t get_phy;
phy_param_t phyParam;
lorawan_status_t status = LORAWAN_STATUS_SERVICE_UNKNOWN;
loramac_mhdr_t macHdr;
VerifyParams_t verify;
verification_params_t verify;
uint8_t fPort = 0;
void *fBuffer;
uint16_t fBufferSize;
@ -115,23 +115,19 @@ lorawan_status_t LoRaMacMcps::set_request(loramac_mcps_req_t *mcpsRequest,
// }
// Get the minimum possible datarate
getPhy.Attribute = PHY_MIN_TX_DR;
getPhy.UplinkDwellTime = params->sys_params.uplink_dwell_time;
phyParam = _lora_phy->get_phy_params(&getPhy);
get_phy.attribute = PHY_MIN_TX_DR;
phyParam = _lora_phy->get_phy_params(&get_phy);
// Apply the minimum possible datarate.
// Some regions have limitations for the minimum datarate.
datarate = MAX(datarate, (int8_t)phyParam.Value);
datarate = MAX(datarate, (int8_t)phyParam.value);
if (readyToSend == true) {
if (params->sys_params.adr_on == false) {
verify.DatarateParams.Datarate = datarate;
verify.DatarateParams.UplinkDwellTime =
params->sys_params.uplink_dwell_time;
verify.datarate = datarate;
if (_lora_phy->verify(&verify, PHY_TX_DR) == true) {
params->sys_params.channel_data_rate =
verify.DatarateParams.Datarate;
params->sys_params.channel_data_rate = verify.datarate;
} else {
return LORAWAN_STATUS_PARAMETER_INVALID;
}

View File

@ -49,8 +49,7 @@ lorawan_status_t LoRaMacMib::set_request(loramac_mib_req_confirm_t *mibSet,
}
lorawan_status_t status = LORAWAN_STATUS_OK;
ChanMaskSetParams_t chanMaskSet;
VerifyParams_t verify;
verification_params_t verify;
switch (mibSet->type) {
@ -126,8 +125,7 @@ lorawan_status_t LoRaMacMib::set_request(loramac_mib_req_confirm_t *mibSet,
break;
}
case MIB_RX2_CHANNEL: {
verify.DatarateParams.Datarate = mibSet->param.rx2_channel.datarate;
verify.DatarateParams.DownlinkDwellTime = params->sys_params.downlink_dwell_time;
verify.datarate = mibSet->param.rx2_channel.datarate;
if (_lora_phy->verify(&verify, PHY_RX_DR) == true) {
params->sys_params.rx2_channel = mibSet->param.rx2_channel;
@ -154,8 +152,7 @@ lorawan_status_t LoRaMacMib::set_request(loramac_mib_req_confirm_t *mibSet,
break;
}
case MIB_RX2_DEFAULT_CHANNEL: {
verify.DatarateParams.Datarate = mibSet->param.rx2_channel.datarate;
verify.DatarateParams.DownlinkDwellTime = params->sys_params.downlink_dwell_time;
verify.datarate = mibSet->param.rx2_channel.datarate;
if (_lora_phy->verify(&verify, PHY_RX_DR) == true) {
params->sys_params.rx2_channel = mibSet->param.default_rx2_channel;
@ -164,22 +161,13 @@ lorawan_status_t LoRaMacMib::set_request(loramac_mib_req_confirm_t *mibSet,
}
break;
}
case MIB_CHANNELS_DEFAULT_MASK: {
chanMaskSet.ChannelsMaskIn = mibSet->param.channel_mask;
chanMaskSet.ChannelsMaskType = CHANNELS_DEFAULT_MASK;
if (_lora_phy->set_channel_mask(&chanMaskSet) == false) {
status = LORAWAN_STATUS_PARAMETER_INVALID;
}
break;
}
case MIB_CHANNELS_DEFAULT_MASK:
case MIB_CHANNELS_MASK: {
chanMaskSet.ChannelsMaskIn = mibSet->param.channel_mask;
chanMaskSet.ChannelsMaskType = CHANNELS_MASK;
if (_lora_phy->set_channel_mask(&chanMaskSet) == false) {
status = LORAWAN_STATUS_PARAMETER_INVALID;
}
// channel masks must not be tempered with.
// They should be manipulated only on request with certain
// APIs like add_channel() and remove_channel()
// You should be able to get these MIB parameters, not set
status = LORAWAN_STATUS_SERVICE_UNKNOWN;
break;
}
case MIB_CHANNELS_NB_REP: {
@ -212,41 +200,40 @@ lorawan_status_t LoRaMacMib::set_request(loramac_mib_req_confirm_t *mibSet,
break;
}
case MIB_CHANNELS_DEFAULT_DATARATE: {
verify.DatarateParams.Datarate = mibSet->param.default_channel_data_rate;
verify.datarate = mibSet->param.default_channel_data_rate;
if (_lora_phy->verify(&verify, PHY_DEF_TX_DR) == true) {
params->sys_params.channel_data_rate = verify.DatarateParams.Datarate;
params->sys_params.channel_data_rate = verify.datarate;
} else {
status = LORAWAN_STATUS_PARAMETER_INVALID;
}
break;
}
case MIB_CHANNELS_DATARATE: {
verify.DatarateParams.Datarate = mibSet->param.channel_data_rate;
verify.DatarateParams.UplinkDwellTime = params->sys_params.uplink_dwell_time;
verify.datarate = mibSet->param.channel_data_rate;
if (_lora_phy->verify(&verify, PHY_TX_DR) == true) {
params->sys_params.channel_data_rate = verify.DatarateParams.Datarate;
params->sys_params.channel_data_rate = verify.datarate;
} else {
status = LORAWAN_STATUS_PARAMETER_INVALID;
}
break;
}
case MIB_CHANNELS_DEFAULT_TX_POWER: {
verify.TxPower = mibSet->param.default_channel_tx_pwr;
verify.tx_power = mibSet->param.default_channel_tx_pwr;
if (_lora_phy->verify(&verify, PHY_DEF_TX_POWER) == true) {
params->sys_params.channel_tx_power = verify.TxPower;
params->sys_params.channel_tx_power = verify.tx_power;
} else {
status = LORAWAN_STATUS_PARAMETER_INVALID;
}
break;
}
case MIB_CHANNELS_TX_POWER: {
verify.TxPower = mibSet->param.channel_tx_pwr;
verify.tx_power = mibSet->param.channel_tx_pwr;
if (_lora_phy->verify(&verify, PHY_TX_POWER) == true) {
params->sys_params.channel_tx_power = verify.TxPower;
params->sys_params.channel_tx_power = verify.tx_power;
} else {
status = LORAWAN_STATUS_PARAMETER_INVALID;
}
@ -284,8 +271,8 @@ lorawan_status_t LoRaMacMib::get_request(loramac_mib_req_confirm_t *mibGet,
loramac_protocol_params *params)
{
lorawan_status_t status = LORAWAN_STATUS_OK;
GetPhyParams_t getPhy;
PhyParam_t phyParam;
get_phy_params_t get_phy;
phy_param_t phyParam;
rx2_channel_params rx2_channel;
if( mibGet == NULL )
@ -342,10 +329,10 @@ lorawan_status_t LoRaMacMib::get_request(loramac_mib_req_confirm_t *mibGet,
}
case MIB_CHANNELS:
{
getPhy.Attribute = PHY_CHANNELS;
phyParam = _lora_phy->get_phy_params( &getPhy );
get_phy.attribute = PHY_CHANNELS;
phyParam = _lora_phy->get_phy_params( &get_phy );
mibGet->param.channel_list = phyParam.Channels;
mibGet->param.channel_list = phyParam.channel_params;
break;
}
case MIB_RX2_CHANNEL:
@ -355,31 +342,31 @@ lorawan_status_t LoRaMacMib::get_request(loramac_mib_req_confirm_t *mibGet,
}
case MIB_RX2_DEFAULT_CHANNEL:
{
getPhy.Attribute = PHY_DEF_RX2_DR;
phyParam = _lora_phy->get_phy_params( &getPhy );
rx2_channel.datarate = phyParam.Value;
get_phy.attribute = PHY_DEF_RX2_DR;
phyParam = _lora_phy->get_phy_params( &get_phy );
rx2_channel.datarate = phyParam.value;
getPhy.Attribute = PHY_DEF_RX2_FREQUENCY;
phyParam = _lora_phy->get_phy_params( &getPhy );
rx2_channel.frequency = phyParam.Value;
get_phy.attribute = PHY_DEF_RX2_FREQUENCY;
phyParam = _lora_phy->get_phy_params( &get_phy );
rx2_channel.frequency = phyParam.value;
mibGet->param.rx2_channel = rx2_channel;
break;
}
case MIB_CHANNELS_DEFAULT_MASK:
{
getPhy.Attribute = PHY_CHANNELS_DEFAULT_MASK;
phyParam = _lora_phy->get_phy_params( &getPhy );
get_phy.attribute = PHY_CHANNELS_DEFAULT_MASK;
phyParam = _lora_phy->get_phy_params( &get_phy );
mibGet->param.default_channel_mask = phyParam.ChannelsMask;
mibGet->param.default_channel_mask = phyParam.channel_mask;
break;
}
case MIB_CHANNELS_MASK:
{
getPhy.Attribute = PHY_CHANNELS_MASK;
phyParam = _lora_phy->get_phy_params( &getPhy );
get_phy.attribute = PHY_CHANNELS_MASK;
phyParam = _lora_phy->get_phy_params( &get_phy );
mibGet->param.channel_mask = phyParam.ChannelsMask;
mibGet->param.channel_mask = phyParam.channel_mask;
break;
}
case MIB_CHANNELS_NB_REP:
@ -414,9 +401,9 @@ lorawan_status_t LoRaMacMib::get_request(loramac_mib_req_confirm_t *mibGet,
}
case MIB_CHANNELS_DEFAULT_DATARATE:
{
getPhy.Attribute = PHY_DEF_TX_DR;
phyParam = _lora_phy->get_phy_params( &getPhy );
mibGet->param.default_channel_data_rate = phyParam.Value;
get_phy.attribute = PHY_DEF_TX_DR;
phyParam = _lora_phy->get_phy_params( &get_phy );
mibGet->param.default_channel_data_rate = phyParam.value;
break;
}
case MIB_CHANNELS_DATARATE:
@ -426,9 +413,9 @@ lorawan_status_t LoRaMacMib::get_request(loramac_mib_req_confirm_t *mibGet,
}
case MIB_CHANNELS_DEFAULT_TX_POWER:
{
getPhy.Attribute = PHY_DEF_TX_POWER;
phyParam = _lora_phy->get_phy_params( &getPhy );
mibGet->param.default_channel_tx_pwr = phyParam.Value;
get_phy.attribute = PHY_DEF_TX_POWER;
phyParam = _lora_phy->get_phy_params( &get_phy );
mibGet->param.default_channel_tx_pwr = phyParam.value;
break;
}
case MIB_CHANNELS_TX_POWER:

View File

@ -50,10 +50,10 @@ lorawan_status_t LoRaMacMlme::set_request(loramac_mlme_req_t *mlmeRequest,
lorawan_status_t status = LORAWAN_STATUS_SERVICE_UNKNOWN;
loramac_mhdr_t macHdr;
AlternateDrParams_t altDr;
VerifyParams_t verify;
GetPhyParams_t getPhy;
PhyParam_t phyParam;
verification_params_t verify;
get_phy_params_t get_phy;
phy_param_t phyParam;
if (params->mac_state != LORAMAC_IDLE) {
@ -81,13 +81,13 @@ lorawan_status_t LoRaMacMlme::set_request(loramac_mlme_req_t *mlmeRequest,
}
// Verify the parameter NbTrials for the join procedure
verify.NbJoinTrials = mlmeRequest->req.join.nb_trials;
verify.nb_join_trials = mlmeRequest->req.join.nb_trials;
if (_lora_phy->verify(&verify, PHY_NB_JOIN_TRIALS) == false) {
// Value not supported, get default
getPhy.Attribute = PHY_DEF_NB_JOIN_TRIALS;
phyParam = _lora_phy->get_phy_params(&getPhy);
mlmeRequest->req.join.nb_trials = (uint8_t) phyParam.Value;
get_phy.attribute = PHY_DEF_NB_JOIN_TRIALS;
phyParam = _lora_phy->get_phy_params(&get_phy);
mlmeRequest->req.join.nb_trials = (uint8_t) phyParam.value;
}
params->flags.bits.mlme_req = 1;
@ -107,10 +107,8 @@ lorawan_status_t LoRaMacMlme::set_request(loramac_mlme_req_t *mlmeRequest,
_lora_mac->ResetMacParameters();
altDr.NbTrials = params->join_request_trial_counter + 1;
params->sys_params.channel_data_rate =
_lora_phy->get_alternate_DR(&altDr);
_lora_phy->get_alternate_DR(params->join_request_trial_counter + 1);
status = _lora_mac->Send(&macHdr, 0, NULL, 0);
break;

File diff suppressed because it is too large Load Diff

View File

@ -37,109 +37,168 @@
#include "lorawan/system/LoRaWANTimer.h"
#include "lorawan/lorastack/phy/lora_phy_ds.h"
#include "netsocket/LoRaRadio.h"
#include "platform/NonCopyable.h"
class LoRaPHY {
class LoRaPHY : private mbed::NonCopyable<LoRaPHY> {
public:
LoRaPHY(LoRaWANTimeHandler &lora_time);
virtual ~LoRaPHY();
/** Stores a reference to Radio object.
*
* Application is responsible for constructing a 'LoRaRadio' object
* which is passed down to the PHY layer.
*
* @param radio a reference to radio driver object
*/
void set_radio_instance(LoRaRadio& radio);
/** Puts radio in sleep mode.
*
* Requests the radio driver to enter sleep mode.
*/
void put_radio_to_sleep(void);
/** Puts radio in standby mode.
*
* Requests the radio driver to enter standby mode.
*/
void put_radio_to_standby(void);
/** Puts radio in receive mode.
*
* Requests the radio driver to enter receive mode for a given time or to
* enter continuous reception mode.
*
* @param is_rx_continuous if true, sets the radio to enter continuous
* reception mode.
*
* @param max_rx_window duration of receive window
*/
void setup_rx_window(bool is_rx_continuous, uint32_t max_rx_window);
void setup_tx_cont_wave_mode(uint16_t timeout, uint32_t frequency,
uint8_t power);
/** Delegates MAC layer request to transmit packet.
*
* @param buf a pointer to the data which needs to be transmitted
*
* @param size size of the data in bytes
*/
void handle_send(uint8_t *buf, uint8_t size);
/** Enables/Disables public network mode.
*
* Public and private LoRaWAN network constitute different preambles and
* Net IDs. This API isused to tell the radio which network mode is in use.
*
* @param set true or false
*/
void setup_public_network_mode(bool set);
/** Provides a random number from radio.
*
* Returns a 32-bit random unsigned integer value based upon RSSI
* measurements.
*
* @return a 32-bit long random number
*
*/
uint32_t get_radio_rng();
/*!
* \brief The function gets a value of a specific PHY attribute.
/** Calculates and applies duty cycle back-off time.
*
* \param [in] getPhy A pointer to the function parameters.
* Explicitly updates the band time-off.
*
* \retval A structure containing the PHY parameter.
* @param [in] backoff_params A pointer to backoff parameters.
*/
virtual PhyParam_t get_phy_params(GetPhyParams_t* getPhy ) = 0;
void calculate_backoff(backoff_params_t* backoff_params);
/*!
* \brief Updates the last TX done parameters of the current channel.
/** Entertain a new channel request MAC command.
*
* \param [in] txDone A pointer to the function parameters.
* MAC command subsystem processes the new channel request coming form
* the network server and then MAC layer asks the PHY layer to entertain
* the request.
*
* @param [in] new_channel_req A pointer to the new_channel_req_params_t.
*
* @return bit mask, according to the LoRaWAN spec 1.0.2.
*/
virtual void set_band_tx_done(SetBandTxDoneParams_t* txDone ) = 0;
virtual uint8_t request_new_channel(new_channel_req_params_t* new_channel_req);
/*!
* \brief Initializes the channels masks and the channels.
/** Grants access to PHY layer parameters.
*
* \param [in] type Sets the initialization type.
* This is essentially a PHY layer parameter retrieval system.
* A request is made for a certain parameter by setting an appropriate
* attribute.
*
* @param [in] get_phy A pointer to get_phy_params_t
*
* @return A structure containing the requested PHY parameter value.
*/
virtual void load_defaults(InitType_t type ) = 0;
virtual phy_param_t get_phy_params(get_phy_params_t* get_phy);
/*!
* \brief Verifies a parameter.
/** Process PHY layer state after a successful transmission.
*
* \param [in] verify A pointer to the function parameters.
* Updates times of the last transmission for the particular channel and
* band upon which last transmission took place.
*
* \param [in] phyAttribute The attribute for which the verification is needed.
*
* \retval True, if the parameter is valid.
* @param [in] tx_done A pointer to set_band_txdone_params_t
*/
virtual bool verify(VerifyParams_t* verify, PhyAttribute_t phyAttribute ) = 0;
virtual void set_last_tx_done(set_band_txdone_params_t* tx_done);
/*!
* \brief The function parses the input buffer and sets up the channels of the CF list.
/** Enables default channels only.
*
* \param [in] applyCFList A pointer to the function parameters.
* Falls back to a channel mask where only default channels are enabled, all
* other channels are disabled.
*/
virtual void apply_cf_list(ApplyCFListParams_t* applyCFList ) = 0;
virtual void restore_default_channels();
/*!
* \brief Sets a channels mask.
/** Verify if a parameter is eligible.
*
* \param [in] chanMaskSet A pointer to the function parameters.
* @param verify A pointer to the verification_params_t that contains
* parameters which we need to check for validity.
*
* \retval True, if the channels mask could be set.
* @param phy_attr The attribute for which the verification is needed.
*
* @return True, if the parameter is valid.
*/
virtual bool set_channel_mask(ChanMaskSetParams_t* chanMaskSet ) = 0;
virtual bool verify(verification_params_t* verify, phy_attributes_t phy_attr);
/*!
* \brief Calculates the next datarate to set, when ADR is on or off.
/** Processes the incoming CF-list.
*
* \param [in] adrNext A pointer to the function parameters.
* Handles the payload containing CF-list and enables channels defined
* therein.
*
* \param [out] drOut The calculated datarate for the next TX.
*
* \param [out] txPowOut The TX power for the next TX.
*
* \param [out] adrAckCounter The calculated ADR acknowledgement counter.
*
* \retval True, if an ADR request should be performed.
* @param cflist_params A pointer to cflist_params_t.
*/
virtual bool get_next_ADR(AdrNextParams_t* adrNext, int8_t* drOut,
int8_t* txPowOut, uint32_t* adrAckCounter ) = 0;
virtual void apply_cf_list(cflist_params_t* cflist_params);
/*!
* \brief Configuration of the RX windows.
/** Calculates the next datarate to set, when ADR is on or off.
*
* \param [in] rxConfig A pointer to the function parameters.
* @param restore_channel_mask A boolean set restore channel mask in case
* of failure.
*
* \param [out] datarate The datarate index set.
* @param dr_out The calculated datarate for the next TX.
*
* \retval True, if the configuration was applied successfully.
* @param tx_power_out The TX power for the next TX.
*
* @param adr_ack_counter The calculated ADR acknowledgement counter.
*
* @return True, if an ADR request should be performed.
*/
virtual bool rx_config(rx_config_params_t* rxConfig, int8_t* datarate ) = 0;
bool get_next_ADR(bool restore_channel_mask, int8_t& dr_out,
int8_t& tx_power_out, uint32_t& adr_ack_counter);
/*
* RX window precise timing
/** Configure radio reception.
*
* @param [in] config A pointer to the RX configuration.
*
* @param [out] datarate The datarate index set.
*
* @return True, if the configuration was applied successfully.
*/
virtual bool rx_config(rx_config_params_t* config, int8_t* datarate);
/** Computing Receive Windows
*
* For more details please consult the following document, chapter 3.1.2.
* http://www.semtech.com/images/datasheet/SX1272_settings_for_LoRaWAN_v2.0.pdf
@ -179,500 +238,257 @@ public:
/*!
* Computes the RX window timeout and offset.
*
* \param [in] datarate The RX window datarate index to be used.
* @param [in] datarate The RX window datarate index to be used.
*
* \param [in] minRxSymbols The minimum number of symbols required to detect an RX frame.
* @param [in] min_rx_symbols The minimum number of symbols required to
* detect an RX frame.
*
* \param [in] rxError The maximum timing error of the receiver in milliseconds.
* The receiver will turn on in a [-rxError : +rxError] ms
* interval around RxOffset.
* @param [in] rx_error The maximum timing error of the receiver
* in milliseconds. The receiver will turn on
* in a [-rxError : +rxError] ms interval around
* RxOffset.
*
* \param [out] rxConfigParams Returns the updated WindowTimeout and WindowOffset fields.
* @param [out] rx_conf_params Pointer to the structure that needs to be
* filled with receive window parameters.
*
*/
virtual void compute_rx_win_params(int8_t datarate,
uint8_t minRxSymbols,
uint32_t rxError,
rx_config_params_t *rxConfigParams) = 0;
/*!
* \brief TX configuration.
*
* \param [in] txConfig A pointer to the function parameters.
*
* \param [out] txPower The TX power index set.
*
* \param [out] txTimeOnAir The time-on-air of the frame.
*
* \retval True, if the configuration was applied successfully.
*/
virtual bool tx_config(TxConfigParams_t* txConfig, int8_t* txPower,
lorawan_time_t* txTimeOnAir ) = 0;
virtual void compute_rx_win_params(int8_t datarate, uint8_t min_rx_symbols,
uint32_t rx_error,
rx_config_params_t *rx_conf_params);
/*!
* \brief The function processes a Link ADR Request.
/** Configure radio transmission.
*
* \param [in] linkAdrReq A pointer to the function parameters.
* @param [in] tx_config Structure containing tx parameters.
*
* \param [out] drOut The datarate applied.
* @param [out] tx_power The TX power which will be set.
*
* \param [out] txPowOut The TX power applied.
* @param [out] tx_toa The time-on-air of the frame.
*
* \param [out] nbRepOut The number of repetitions to apply.
*
* \param [out] nbBytesParsed The number of bytes parsed.
*
* \retval The status of the operation, according to the LoRaMAC specification.
* @return True, if the configuration was applied successfully.
*/
virtual uint8_t link_ADR_request(LinkAdrReqParams_t* linkAdrReq,
int8_t* drOut, int8_t* txPowOut,
uint8_t* nbRepOut,
uint8_t* nbBytesParsed ) = 0;
virtual bool tx_config(tx_config_params_t* tx_config, int8_t* tx_power,
lorawan_time_t* tx_toa);
/*!
* \brief The function processes a RX Parameter Setup Request.
/** Processes a Link ADR Request.
*
* \param [in] rxParamSetupReq A pointer to the function parameters.
* @param [in] params A pointer ADR request parameters.
*
* \retval The status of the operation, according to the LoRaMAC specification.
* @param [out] dr_out The datarate applied.
*
* @param [out] tx_power_out The TX power applied.
*
* @param [out] nb_rep_out The number of repetitions to apply.
*
* @param [out] nb_bytes_parsed The number of bytes parsed.
*
* @return The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t setup_rx_params(RxParamSetupReqParams_t* rxParamSetupReq ) = 0;
virtual uint8_t link_ADR_request(adr_req_params_t* params,
int8_t* dr_out, int8_t* tx_power_out,
uint8_t* nb_rep_out,
uint8_t* nb_bytes_parsed);
/*!
* \brief The function processes a New Channel Request.
/** Accept or rejects RxParamSetupReq MAC command
*
* \param [in] newChannelReq A pointer to the function parameters.
* The function processes a RX parameter setup request in response to
* server MAC command for RX setup.
*
* \retval The status of the operation, according to the LoRaMAC specification.
* @param [in] params A pointer to rx parameter setup request.
*
* @return The status of the operation, according to the LoRaWAN specification.
*/
virtual uint8_t request_new_channel(NewChannelReqParams_t* newChannelReq ) = 0;
virtual uint8_t accept_rx_param_setup_req(rx_param_setup_req_t* params);
/*!
* \brief The function processes a TX ParamSetup Request.
/** Makes decision whether to accept or reject TxParamSetupReq MAC command
*
* \param [in] txParamSetupReq A pointer to the function parameters.
* @param [in] params A pointer to tx parameter setup request.
*
* \retval The status of the operation, according to the LoRaMAC specification.
* Returns -1, if the functionality is not implemented. In this case, the end node
* shall ignore the command.
* @return True to let the MAC know that the request is
* accepted and MAC can apply TX parameters received
* form Network Server. Otherwise false is returned.
*/
virtual int8_t setup_tx_params(TxParamSetupReqParams_t* txParamSetupReq ) = 0;
virtual bool accept_tx_param_setup_req(tx_param_setup_req_t* params);
/*!
* \brief The function processes a DlChannel Request.
/** Processes a DlChannelReq MAC command.
*
* \param [in] dlChannelReq A pointer to the function parameters.
* @param [in] params A pointer to downlink channel request.
*
* \retval The status of the operation, according to the LoRaMAC specification.
* @return The status of the operation, according to the LoRaWAN specification.
*/
virtual uint8_t dl_channel_request(DlChannelReqParams_t* dlChannelReq ) = 0;
virtual uint8_t dl_channel_request(dl_channel_req_params_t* params);
/*!
* \brief Alternates the datarate of the channel for the join request.
/** Alternates the datarate of the channel for the join request.
*
* \param [in] alternateDr A pointer to the function parameters.
* @param nb_trials Number of trials to be made on one given data rate.
*
* \retval The datarate to apply.
* @return The datarate to apply .
*/
virtual int8_t get_alternate_DR(AlternateDrParams_t* alternateDr ) = 0;
virtual int8_t get_alternate_DR(uint8_t nb_trials);
/*!
* \brief Calculates the back-off time.
/** Searches and sets the next available channel.
*
* \param [in] calcBackOff A pointer to the function parameters.
* If there are multiple channels found available, one of them is selected
* randomly.
*
* @param [in] nextChanParams Parameters for the next channel.
*
* @param [out] channel The next channel to use for TX.
*
* @param [out] time The time to wait for the next transmission according to the duty cycle.
*
* @param [out] aggregatedTimeOff Updates the aggregated time off.
*
* @return Function status [1: OK, 0: Unable to find a channel on the current datarate].
*/
virtual void calculate_backoff(CalcBackOffParams_t* calcBackOff ) = 0;
/*!
* \brief Searches and sets the next random available channel.
*
* \param [in] nextChanParams Parameters for the next channel.
*
* \param [out] channel The next channel to use for TX.
*
* \param [out] time The time to wait for the next transmission according to the duty cycle.
*
* \param [out] aggregatedTimeOff Updates the aggregated time off.
*
* \retval Function status [1: OK, 0: Unable to find a channel on the current datarate].
*/
virtual bool set_next_channel(NextChanParams_t* nextChanParams,
virtual bool set_next_channel(channel_selection_params_t* nextChanParams,
uint8_t* channel, lorawan_time_t* time,
lorawan_time_t* aggregatedTimeOff ) = 0;
lorawan_time_t* aggregatedTimeOff);
/*!
* \brief Adds a channel.
/** Adds a channel to the channel list.
*
* \param [in] channelAdd A pointer to the function parameters.
* Verifies the channel parameters and if everything is found legitimate,
* adds that particular channel to the channel list and updates the channel
* mask.
*
* \retval The status of the operation.
* @param [in] new_channel A pointer to the parameters for the new channel.
* @param [in] id Channel ID
*
* @return LORAWAN_STATUS_OK if everything goes fine, negative error code
* otherwise.
*/
virtual lorawan_status_t add_channel(ChannelAddParams_t* channelAdd ) = 0;
virtual lorawan_status_t add_channel(channel_params_t* new_channel, uint8_t id);
/*!
* \brief Removes a channel.
/** Removes a channel from the channel list.
*
* \param [in] channelRemove A pointer to the function parameters.
* @param [in] channel_id Index of the channel to be removed
*
* \retval True, if the channel was removed successfully.
* @return True, if the channel was removed successfully.
*/
virtual bool remove_channel(ChannelRemoveParams_t* channelRemove ) = 0;
virtual bool remove_channel(uint8_t channel_id);
/*!
* \brief Sets the radio into continuous wave mode.
/** Puts the radio into continuous wave mode.
*
* \param [in] continuousWave A pointer to the function parameters.
* @param [in] continuous_wave A pointer to the function parameters.
*
* @param [in] frequency Frequency to transmit at
*/
virtual void set_tx_cont_mode(ContinuousWaveParams_t* continuousWave ) = 0;
virtual void set_tx_cont_mode(cw_mode_params_t* continuous_wave,
uint32_t frequency = 0);
/*!
* \brief Computes new datarate according to the given offset
/** Computes new data rate according to the given offset
*
* \param [in] downlinkDwellTime The downlink dwell time configuration. 0: No limit, 1: 400ms
* @param [in] dr The current datarate.
*
* \param [in] dr The current datarate.
* @param [in] dr_offset The offset to be applied.
*
* \param [in] drOffset The offset to be applied.
*
* \retval newDr The computed datarate.
* @return The computed datarate.
*/
virtual uint8_t apply_DR_offset(uint8_t downlinkDwellTime, int8_t dr, int8_t drOffset ) = 0;
virtual uint8_t apply_DR_offset(int8_t dr, int8_t dr_offset);
protected:
LoRaRadio *_radio;
LoRaWANTimeHandler &_lora_time;
loraphy_params_t phy_params;
typedef struct sRegionCommonLinkAdrParams
{
/*!
* The number of repetitions.
*/
uint8_t NbRep;
/*!
* Datarate.
*/
int8_t Datarate;
/*!
* TX power.
*/
int8_t TxPower;
/*!
* Channels mask control field.
*/
uint8_t ChMaskCtrl;
/*!
* Channels mask field.
*/
uint16_t ChMask;
}RegionCommonLinkAdrParams_t;
LoRaPHY(LoRaWANTimeHandler &lora_time);
typedef struct sRegionCommonLinkAdrReqVerifyParams
{
/*!
* The current status of the AdrLinkRequest.
*/
uint8_t Status;
/*!
* Set to true, if ADR is enabled.
*/
bool AdrEnabled;
/*!
* The datarate the AdrLinkRequest wants to set.
*/
int8_t Datarate;
/*!
* The TX power the AdrLinkRequest wants to set.
*/
int8_t TxPower;
/*!
* The number of repetitions the AdrLinkRequest wants to set.
*/
uint8_t NbRep;
/*!
* The current datarate the node is using.
*/
int8_t CurrentDatarate;
/*!
* The current TX power the node is using.
*/
int8_t CurrentTxPower;
/*!
* The current number of repetitions the node is using.
*/
int8_t CurrentNbRep;
/*!
* The number of channels.
*/
uint8_t NbChannels;
/*!
* A pointer to the first element of the channels mask.
*/
uint16_t* ChannelsMask;
/*!
* The minimum possible datarate.
*/
int8_t MinDatarate;
/*!
* The maximum possible datarate.
*/
int8_t MaxDatarate;
/*!
* A pointer to the channels.
*/
channel_params_t* Channels;
/*!
* The minimum possible TX power.
*/
int8_t MinTxPower;
/*!
* The maximum possible TX power.
*/
int8_t MaxTxPower;
}RegionCommonLinkAdrReqVerifyParams_t;
typedef struct sRegionCommonCalcBackOffParams
{
/*!
* A pointer to region specific channels.
*/
channel_params_t* Channels;
/*!
* A pointer to region specific bands.
*/
band_t* Bands;
/*!
* Set to true, if the last uplink was a join request.
*/
bool LastTxIsJoinRequest;
/*!
* Set to true, if the node is joined.
*/
bool Joined;
/*!
* Set to true, if the duty cycle is enabled.
*/
bool DutyCycleEnabled;
/*!
* The current channel.
*/
uint8_t Channel;
/*!
* The elapsed time since initialization.
*/
lorawan_time_t ElapsedTime;
/*!
* The time on air of the last TX frame.
*/
lorawan_time_t TxTimeOnAir;
}RegionCommonCalcBackOffParams_t;
/*!
* \brief Calculates the join duty cycle.
* This is a generic function and valid for all regions.
*
* \param [in] elapsedTime The time elapsed since starting the device.
*
* \retval Duty cycle restriction.
/**
* Verifies the given frequency.
*/
uint16_t get_join_DC( lorawan_time_t elapsedTime );
virtual bool verify_frequency(uint32_t freq);
/*!
* \brief Verifies, if a value is in a given range.
* This is a generic function and valid for all regions.
*
* \param [in] value The value to verify, if it is in range.
*
* \param [in] min The minimum possible value.
*
* \param [in] max The maximum possible value.
*
* \retval 1 if the value is in range, otherwise 0.
/**
* Verifies, if a value is in a given range.
*/
uint8_t val_in_range( int8_t value, int8_t min, int8_t max );
uint8_t val_in_range(int8_t value, int8_t min, int8_t max);
/*!
* \brief Verifies, if a datarate is available on an active channel.
* This is a generic function and valid for all regions.
*
* \param [in] nbChannels The number of channels.
*
* \param [in] channelsMask The channels mask of the region.
*
* \param [in] dr The datarate to verify.
*
* \param [in] minDr The minimum datarate.
*
* \param [in] maxDr The maximum datarate.
*
* \param [in] channels The channels of the region.
*
* \retval True if the datarate is supported, false if not.
/**
* Verifies, if a datarate is available on an active channel.
*/
bool verify_channel_DR( uint8_t nbChannels, uint16_t* channelsMask, int8_t dr,
int8_t minDr, int8_t maxDr, channel_params_t* channels );
bool verify_channel_DR(uint8_t nbChannels, uint16_t* channelsMask, int8_t dr,
int8_t minDr, int8_t maxDr, channel_params_t* channels );
/*!
* \brief Disables a channel in a given channels mask.
* This is a generic function and valid for all regions.
*
* \param [in] channelsMask The channels mask of the region.
*
* \param [in] id The ID of the channels mask to disable.
*
* \param [in] maxChannels The maximum number of channels.
*
* \retval True if the channel could be disabled, false if not.
/**
* Disables a channel in a given channels mask.
*/
bool disable_channel( uint16_t* channelsMask, uint8_t id, uint8_t maxChannels );
/*!
* \brief Counts the number of active channels in a given channels mask.
* This is a generic function and valid for all regions.
*
* \param [in] channelsMask The channels mask of the region.
*
* \param [in] startIdx The start index.
*
* \param [in] stopIdx The stop index (the channels of this index will not be counted).
*
* \retval The number of active channels.
/**
* Counts number of bits on in a given mask
*/
uint8_t num_active_channels( uint16_t* channelsMask, uint8_t startIdx, uint8_t stopIdx );
uint8_t count_bits(uint16_t mask, uint8_t nbBits);
/*!
* \brief Copy a channels mask.
* This is a generic function and valid for all regions.
*
* \param [in] channelsMaskDest The destination channels mask.
*
* \param [in] channelsMaskSrc The source channels mask.
*
* \param [in] len The index length to copy.
/**
* Counts the number of active channels in a given channels mask.
*/
void copy_channel_mask( uint16_t* channelsMaskDest, uint16_t* channelsMaskSrc, uint8_t len );
uint8_t num_active_channels(uint16_t* channelsMask, uint8_t startIdx,
uint8_t stopIdx);
/*!
* \brief Sets the last TX done property.
* This is a generic function and valid for all regions.
*
* \param [in] joined Set to true, if the node has joined the network
*
* \param [in] band The band to be updated.
*
* \param [in] lastTxDone The time of the last TX done.
/**
* Copy channel masks.
*/
void set_last_tx_done( bool joined, band_t* band, lorawan_time_t lastTxDone );
void copy_channel_mask(uint16_t* channelsMaskDest, uint16_t* channelsMaskSrc,
uint8_t len );
/*!
* \brief Updates the time-offs of the bands.
* This is a generic function and valid for all regions.
*
* \param [in] joined Set to true, if the node has joined the network
*
* \param [in] dutyCycle Set to true, if the duty cycle is enabled.
*
* \param [in] bands A pointer to the bands.
*
* \param [in] nbBands The number of bands available.
*
* \retval The time which must be waited to perform the next uplink.
/**
* Updates the time-offs of the bands.
*/
lorawan_time_t update_band_timeoff( bool joined, bool dutyCycle, band_t* bands, uint8_t nbBands );
lorawan_time_t update_band_timeoff(bool joined, bool dutyCycle, band_t* bands,
uint8_t nbBands);
/*!
* \brief Parses the parameter of an LinkAdrRequest.
* This is a generic function and valid for all regions.
*
* \param [in] payload A pointer to the payload containing the MAC commands. The payload
* must contain the CMD identifier, followed by the parameters.
*
* \param [out] parseLinkAdr The function fills the structure with the ADR parameters.
*
* \retval The length of the ADR request, if a request was found. Otherwise, the
* function returns 0.
/**
* Parses the parameter of an LinkAdrRequest.
*/
uint8_t parse_link_ADR_req( uint8_t* payload, RegionCommonLinkAdrParams_t* parseLinkAdr );
uint8_t parse_link_ADR_req(uint8_t* payload, link_adr_params_t* parseLinkAdr );
/*!
* \brief Verifies and updates the datarate, the TX power and the number of repetitions
* of a LinkAdrRequest. This also depends on the ADR configuration.
*
* \param [in] verifyParams A pointer to a structure containing the input parameters.
*
* \param [out] dr The updated datarate.
*
* \param [out] txPow The updated TX power.
*
* \param [out] nbRep The updated number of repetitions.
*
* \retval The status according to the LinkAdrRequest definition.
/**
* Verifies and updates the datarate, the TX power and the number of repetitions
* of a LinkAdrRequest.
*/
uint8_t verify_link_ADR_req( RegionCommonLinkAdrReqVerifyParams_t* verifyParams, int8_t* dr, int8_t* txPow, uint8_t* nbRep );
uint8_t verify_link_ADR_req( verify_adr_params_t* verifyParams, int8_t* dr, int8_t* txPow, uint8_t* nbRep );
/*!
* \brief Computes the symbol time for LoRa modulation.
*
* \param [in] phyDr The physical datarate to use.
*
* \param [in] bandwidth The bandwidth to use.
*
* \retval The symbol time.
/**
* Computes the symbol time for LoRa modulation.
*/
double compute_symb_timeout_lora( uint8_t phyDr, uint32_t bandwidth );
/*!
* \brief Computes the symbol time for FSK modulation.
*
* \param [in] phyDr The physical datarate to use.
*
* \retval The symbol time.
/**
* Computes the symbol time for FSK modulation.
*/
double compute_symb_timeout_fsk( uint8_t phyDr );
/*!
* \brief Computes the RX window timeout and the RX window offset.
*
* \param [in] tSymbol The symbol timeout.
*
* \param [in] minRxSymbols The minimum required number of symbols to detect an RX frame.
*
* \param [in] rxError The system maximum timing error of the receiver in milliseconds
* The receiver will turn on in a [-rxError : +rxError] ms interval around RxOffset.
*
* \param [in] wakeUpTime The wakeup time of the system.
*
* \param [out] windowTimeout The RX window timeout.
*
* \param [out] windowOffset The RX window time offset to be applied to the RX delay.
/**
* Computes the RX window timeout and the RX window offset.
*/
void get_rx_window_params( double tSymbol, uint8_t minRxSymbols, uint32_t rxError, uint32_t wakeUpTime, uint32_t* windowTimeout, int32_t* windowOffset );
/*!
* \brief Computes the txPower, based on the max EIRP and the antenna gain.
*
* \param [in] txPowerIndex The TX power index.
*
* \param [in] maxEirp The maximum EIRP.
*
* \param [in] antennaGain The antenna gain.
*
* \retval The physical TX power.
/**
* Computes the txPower, based on the max EIRP and the antenna gain.
*/
int8_t compute_tx_power( int8_t txPowerIndex, float maxEirp, float antennaGain );
/*!
* \brief Provides a random number in the range provided.
*
* \param [in] min lower boundary
* \param [in] max upper boundary
/**
* Provides a random number in the range provided.
*/
int32_t get_random(int32_t min, int32_t max);
/*!
* \brief Calculates the duty cycle for the current band.
*
* \param [in] calcBackOffParams A pointer to the input parameters.
/**
* Get next lower data rate
*/
void get_DC_backoff( RegionCommonCalcBackOffParams_t* calcBackOffParams );
int8_t get_next_lower_dr(int8_t dr, int8_t min_dr);
/**
* Get channel bandwidth depending upon data rate table index
*/
uint8_t get_bandwidth(uint8_t dr_index);
uint8_t enabled_channel_count(bool joined, uint8_t datarate,
uint16_t *mask_list, uint8_t mask_list_size,
uint8_t* enabledChannels,
uint8_t* delayTx);
};
#endif /* MBED_OS_LORAPHY_BASE_ */

File diff suppressed because it is too large Load Diff

View File

@ -33,7 +33,6 @@
#define MBED_OS_LORAPHY_AS923_H_
#include "LoRaPHY.h"
#include "netsocket/LoRaRadio.h"
/*!
* LoRaMac maximum number of channels
@ -51,313 +50,22 @@
class LoRaPHYAS923 : public LoRaPHY {
public:
LoRaPHYAS923(LoRaWANTimeHandler &lora_time);
virtual ~LoRaPHYAS923();
/*!
* \brief The function gets a value of a specific PHY attribute.
*
* \param [in] getPhy A pointer to the function parameters.
*
* \retval A structure containing the PHY parameter.
*/
virtual PhyParam_t get_phy_params(GetPhyParams_t* getPhy );
virtual int8_t get_alternate_DR(uint8_t nb_trials);
/*!
* \brief Updates the last TX done parameters of the current channel.
*
* \param [in] txDone A pointer to the function parameters.
*/
virtual void set_band_tx_done(SetBandTxDoneParams_t* txDone );
/*!
* \brief Initializes the channels masks and the channels.
*
* \param [in] type Sets the initialization type.
*/
virtual void load_defaults(InitType_t type );
/*!
* \brief Verifies a parameter.
*
* \param [in] verify A pointer to the function parameters.
*
* \param [in] phyAttribute The attribute to be verified.
*
* \retval True, if the parameter is valid.
*/
virtual bool verify(VerifyParams_t* verify, PhyAttribute_t phyAttribute );
/*!
* \brief The function parses the input buffer and sets up the channels of the
* CF list.
*
* \param [in] applyCFList A pointer to the function parameters.
*/
virtual void apply_cf_list(ApplyCFListParams_t* applyCFList );
/*!
* \brief Sets a channels mask.
*
* \param [in] chanMaskSet A pointer to the function parameters.
*
* \retval True, if the channels mask could be set.
*/
virtual bool set_channel_mask(ChanMaskSetParams_t* chanMaskSet );
/*!
* \brief Calculates the next datarate to set, when ADR is on or off.
*
* \param [in] adrNext A pointer to the function parameters.
*
* \param [out] drOut The calculated datarate for the next TX.
*
* \param [out] txPowOut The TX power for the next TX.
*
* \param [out] adrAckCounter The calculated ADR acknowledgement counter.
*
* \retval True, if an ADR request should be performed.
*/
virtual bool get_next_ADR(AdrNextParams_t* adrNext, int8_t* drOut,
int8_t* txPowOut, uint32_t* adrAckCounter );
/*!
* \brief Configuration of the RX windows.
*
* \param [in] rxConfig A pointer to the function parameters.
*
* \param [out] datarate The datarate index set.
*
* \retval True, if the configuration was applied successfully.
*/
virtual bool rx_config(rx_config_params_t* rxConfig, int8_t* datarate );
/*
* RX window precise timing.
*
* For more details please consult the following document, chapter 3.1.2.
* http://www.semtech.com/images/datasheet/SX1272_settings_for_LoRaWAN_v2.0.pdf
* or
* http://www.semtech.com/images/datasheet/SX1276_settings_for_LoRaWAN_v2.0.pdf
*
* Downlink start: T = Tx + 1s (+/- 20 us)
* |
* TRxEarly | TRxLate
* | | |
* | | +---+---+---+---+---+---+---+---+
* | | | Latest Rx window |
* | | +---+---+---+---+---+---+---+---+
* | | |
* +---+---+---+---+---+---+---+---+
* | Earliest Rx window |
* +---+---+---+---+---+---+---+---+
* |
* +---+---+---+---+---+---+---+---+
*Downlink preamble 8 symbols | | | | | | | | |
* +---+---+---+---+---+---+---+---+
*
* Worst case Rx window timings
*
* TRxLate = DEFAULT_MIN_RX_SYMBOLS * tSymbol - RADIO_WAKEUP_TIME
* TRxEarly = 8 - DEFAULT_MIN_RX_SYMBOLS * tSymbol - RxWindowTimeout - RADIO_WAKEUP_TIME
*
* TRxLate - TRxEarly = 2 * DEFAULT_SYSTEM_MAX_RX_ERROR
*
* RxOffset = ( TRxLate + TRxEarly ) / 2
*
* RxWindowTimeout = ( 2 * DEFAULT_MIN_RX_SYMBOLS - 8 ) * tSymbol + 2 * DEFAULT_SYSTEM_MAX_RX_ERROR
* RxOffset = 4 * tSymbol - RxWindowTimeout / 2 - RADIO_WAKE_UP_TIME
*
* The minimum value of RxWindowTimeout must be 5 symbols which implies that the system always tolerates at least an error of 1.5 * tSymbol
*/
/*!
* Computes the RX window timeout and offset.
*
* \param [in] datarate The RX window datarate index to be used.
*
* \param [in] minRxSymbols The minimum required number of symbols to detect an RX frame.
*
* \param [in] rxError The system maximum timing error of the receiver in milliseconds.
* The receiver will turn on in a [-rxError : +rxError] ms
* interval around RxOffset.
*
* \param [out] rxConfigParams The updated WindowTimeout and WindowOffset fields.
*/
virtual void compute_rx_win_params(int8_t datarate,
uint8_t minRxSymbols,
uint32_t rxError,
rx_config_params_t *rxConfigParams);
/*!
* \brief TX configuration.
*
* \param [in] txConfig A pointer to the function parameters.
*
* \param [out] txPower The TX power index set.
*
* \param [out] txTimeOnAir The time-on-air of the frame.
*
* \retval True, if the configuration was applied successfully.
*/
virtual bool tx_config(TxConfigParams_t* txConfig, int8_t* txPower,
lorawan_time_t* txTimeOnAir );
/*!
* \brief The function processes a Link ADR Request.
*
* \param [in] linkAdrReq A pointer to the function parameters.
*
* \param [out] drOut The datarate applied.
*
* \param [out] txPowOut The TX power applied.
*
* \param [out] nbRepOut The number of repetitions to apply.
*
* \param [out] nbBytesParsed The number of bytes parsed.
*
* \retval The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t link_ADR_request(LinkAdrReqParams_t* linkAdrReq,
int8_t* drOut, int8_t* txPowOut,
uint8_t* nbRepOut,
uint8_t* nbBytesParsed );
/*!
* \brief The function processes a RX parameter setup request.
*
* \param [in] rxParamSetupReq A pointer to the function parameters.
*
* \retval The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t setup_rx_params(RxParamSetupReqParams_t* rxParamSetupReq );
/*!
* \brief The function processes a new channel request.
*
* \param [in] newChannelReq A pointer to the function parameters.
*
* \retval The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t request_new_channel(NewChannelReqParams_t* newChannelReq );
/*!
* \brief The function processes a TX ParamSetup request.
*
* \param [in] txParamSetupReq A pointer to the function parameters.
*
* \retval The status of the operation, according to the LoRaMAC specification.
* Returns -1, if the functionality is not implemented. In this case, the end node
* shall ignore the command.
*/
virtual int8_t setup_tx_params(TxParamSetupReqParams_t* txParamSetupReq );
/*!
* \brief The function processes a DlChannel request.
*
* \param [in] dlChannelReq A pointer to the function parameters.
*
* \retval The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t dl_channel_request(DlChannelReqParams_t* dlChannelReq );
/*!
* \brief Alternates the datarate of the channel for the join request.
*
* \param [in] alternateDr A pointer to the function parameters.
*
* \retval The datarate to apply.
*/
virtual int8_t get_alternate_DR(AlternateDrParams_t* alternateDr );
/*!
* \brief Calculates the back-off time.
*
* \param [in] calcBackOff A pointer to the function parameters.
*/
virtual void calculate_backoff(CalcBackOffParams_t* calcBackOff );
/*!
* \brief Searches and sets the next random available channel.
*
* \param [in] nextChanParams The parameters for the next channel
*
* \param [out] channel The next channel to use for TX.
*
* \param [out] time The time to wait for the next transmission according to the duty cycle.
*
* \param [out] aggregatedTimeOff Updates the aggregated time off.
*
* \retval Function status [1: OK, 0: Unable to find a channel on the current datarate].
*/
virtual bool set_next_channel(NextChanParams_t* nextChanParams,
virtual bool set_next_channel(channel_selection_params_t* nextChanParams,
uint8_t* channel, lorawan_time_t* time,
lorawan_time_t* aggregatedTimeOff );
/*!
* \brief Adds a channel.
*
* \param [in] channelAdd A pointer to the function parameters.
*
* \retval The status of the operation.
*/
virtual lorawan_status_t add_channel(ChannelAddParams_t* channelAdd );
/*!
* \brief Removes a channel.
*
* \param [in] channelRemove A pointer to the function parameters.
*
* \retval True, if the channel was removed successfully.
*/
virtual bool remove_channel(ChannelRemoveParams_t* channelRemove );
/*!
* \brief Sets the radio into continuous wave mode.
*
* \param [in] continuousWave A pointer to the function parameters.
*/
virtual void set_tx_cont_mode(ContinuousWaveParams_t* continuousWave );
/*!
* \brief Computes a new datarate according to the given offset.
*
* \param [in] downlinkDwellTime The downlink dwell time configuration. 0: No limit, 1: 400ms
*
* \param [in] dr The current datarate.
*
* \param [in] drOffset The offset to be applied.
*
* \retval newDr The computed datarate.
*/
virtual uint8_t apply_DR_offset(uint8_t downlinkDwellTime, int8_t dr, int8_t drOffset );
virtual uint8_t apply_DR_offset(int8_t dr, int8_t drOffset );
private:
uint8_t CountNbOfEnabledChannels(bool joined, uint8_t datarate,
uint16_t* channelsMask,
channel_params_t* channels, band_t* bands,
uint8_t* enabledChannels, uint8_t* delayTx);
// Global attributes
/*!
* LoRaMAC channels
*/
channel_params_t Channels[AS923_MAX_NB_CHANNELS];
/*!
* LoRaMac bands
*/
band_t Bands[AS923_MAX_NB_BANDS];
/*!
* LoRaMac channels mask
*/
uint16_t ChannelsMask[AS923_CHANNELS_MASK_SIZE];
/*!
* LoRaMac channels default mask
*/
uint16_t ChannelsDefaultMask[AS923_CHANNELS_MASK_SIZE];
channel_params_t channels[AS923_MAX_NB_CHANNELS];
band_t bands[AS923_MAX_NB_BANDS];
uint16_t channel_masks[AS923_CHANNELS_MASK_SIZE];
uint16_t default_channel_masks[AS923_CHANNELS_MASK_SIZE];
};
#endif /* MBED_OS_LORAPHY_AS923_H_ */

File diff suppressed because it is too large Load Diff

View File

@ -34,7 +34,6 @@
#define MBED_OS_LORAPHY_AU915_H_
#include "LoRaPHY.h"
#include "netsocket/LoRaRadio.h"
// Definitions
/*!
@ -47,7 +46,7 @@
*/
#define AU915_MAX_NB_BANDS 1
#define AU915_CHANNELS_MASK_SIZE 6
#define AU915_CHANNELS_MASK_SIZE 5
class LoRaPHYAU915 : public LoRaPHY{
@ -57,317 +56,52 @@ public:
LoRaPHYAU915(LoRaWANTimeHandler &lora_time);
virtual ~LoRaPHYAU915();
/*!
* \brief The function gets a value of a specific PHY attribute.
*
* \param [in] getPhy A pointer to the function parameters.
*
* \retval A structure containing the PHY parameter.
*/
virtual PhyParam_t get_phy_params(GetPhyParams_t* getPhy );
virtual bool rx_config(rx_config_params_t* config, int8_t* datarate);
/*!
* \brief Updates the last TX done parameters of the current channel.
*
* \param [in] txDone A pointer to the function parameters.
*/
virtual void set_band_tx_done(SetBandTxDoneParams_t* txDone );
virtual bool tx_config(tx_config_params_t* config, int8_t* txPower,
lorawan_time_t* txTimeOnAir);
/*!
* \brief Initializes the channels masks and the channels.
*
* \param [in] type Sets the initialization type.
*/
virtual void load_defaults(InitType_t type );
/*!
* \brief Verifies a parameter.
*
* \param [in] verify A pointer to the function parameters.
*
* \param [in] phyAttribute The attribute to be verified.
*
* \retval True, if the parameter is valid.
*/
virtual bool verify(VerifyParams_t* verify, PhyAttribute_t phyAttribute );
/*!
* \brief The function parses the input buffer and sets up the channels of the
* CF list.
*
* \param [in] applyCFList A pointer to the function parameters.
*/
virtual void apply_cf_list(ApplyCFListParams_t* applyCFList );
/*!
* \brief Sets a channels mask.
*
* \param [in] chanMaskSet A pointer to the function parameters.
*
* \retval True, if the channels mask could be set.
*/
virtual bool set_channel_mask(ChanMaskSetParams_t* chanMaskSet );
/*!
* \brief Calculates the next datarate to set, when ADR is on or off.
*
* \param [in] adrNext A pointer to the function parameters.
*
* \param [out] drOut The calculated datarate for the next TX.
*
* \param [out] txPowOut The TX power for the next TX.
*
* \param [out] adrAckCounter The calculated ADR acknowledgement counter.
*
* \retval True, if an ADR request should be performed.
*/
virtual bool get_next_ADR(AdrNextParams_t* adrNext, int8_t* drOut,
int8_t* txPowOut, uint32_t* adrAckCounter );
/*!
* \brief Configuration of the RX windows.
*
* \param [in] rxConfig A pointer to the function parameters.
*
* \param [out] datarate The datarate index set.
*
* \retval True, if the configuration was applied successfully.
*/
virtual bool rx_config(rx_config_params_t* rxConfig, int8_t* datarate );
/*
* RX window precise timing
*
* For more details please consult the following document, chapter 3.1.2.
* http://www.semtech.com/images/datasheet/SX1272_settings_for_LoRaWAN_v2.0.pdf
* or
* http://www.semtech.com/images/datasheet/SX1276_settings_for_LoRaWAN_v2.0.pdf
*
* Downlink start: T = Tx + 1s (+/- 20 us)
* |
* TRxEarly | TRxLate
* | | |
* | | +---+---+---+---+---+---+---+---+
* | | | Latest Rx window |
* | | +---+---+---+---+---+---+---+---+
* | | |
* +---+---+---+---+---+---+---+---+
* | Earliest Rx window |
* +---+---+---+---+---+---+---+---+
* |
* +---+---+---+---+---+---+---+---+
*Downlink preamble 8 symbols | | | | | | | | |
* +---+---+---+---+---+---+---+---+
*
* Worst case Rx window timings
*
* TRxLate = DEFAULT_MIN_RX_SYMBOLS * tSymbol - RADIO_WAKEUP_TIME
* TRxEarly = 8 - DEFAULT_MIN_RX_SYMBOLS * tSymbol - RxWindowTimeout - RADIO_WAKEUP_TIME
*
* TRxLate - TRxEarly = 2 * DEFAULT_SYSTEM_MAX_RX_ERROR
*
* RxOffset = ( TRxLate + TRxEarly ) / 2
*
* RxWindowTimeout = ( 2 * DEFAULT_MIN_RX_SYMBOLS - 8 ) * tSymbol + 2 * DEFAULT_SYSTEM_MAX_RX_ERROR
* RxOffset = 4 * tSymbol - RxWindowTimeout / 2 - RADIO_WAKE_UP_TIME
*
* The minimum value of RxWindowTimeout must be 5 symbols which implies that the system always tolerates at least an error of 1.5 * tSymbol
*/
/*!
* Computes the Rx window timeout and offset.
*
* \param [in] datarate The RX window datarate index to be used.
*
* \param [in] minRxSymbols The minimum number of symbols required to detect an RX frame.
*
* \param [in] rxError The system maximum timing error of the receiver in milliseconds.
* The receiver will turn on in a [-rxError : +rxError] ms
* interval around RxOffset.
*
* \param [out] rxConfigParams The updated WindowTimeout and WindowOffset fields.
*/
virtual void compute_rx_win_params(int8_t datarate,
uint8_t minRxSymbols,
uint32_t rxError,
rx_config_params_t *rxConfigParams);
/*!
* \brief TX configuration.
*
* \param [in] txConfig A pointer to the function parameters.
*
* \param [out] txPower The TX power index set.
*
* \param [out] txTimeOnAir The time-on-air of the frame.
*
* \retval True, if the configuration was applied successfully.
*/
virtual bool tx_config(TxConfigParams_t* txConfig, int8_t* txPower,
lorawan_time_t* txTimeOnAir );
/*!
* \brief The function processes a Link ADR Request.
*
* \param [in] linkAdrReq A pointer to the function parameters.
*
* \param [out] drOut The datarate applied.
*
* \param [out] txPowOut The TX power applied.
*
* \param [out] nbRepOut The number of repetitions to apply.
*
* \param [out] nbBytesParsed The number bytes parsed.
*
* \retval The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t link_ADR_request(LinkAdrReqParams_t* linkAdrReq,
virtual uint8_t link_ADR_request(adr_req_params_t* params,
int8_t* drOut, int8_t* txPowOut,
uint8_t* nbRepOut,
uint8_t* nbBytesParsed );
uint8_t* nbBytesParsed);
/*!
* \brief The function processes a RX parameter setup request.
*
* \param [in] rxParamSetupReq A pointer to the function parameters.
*
* \retval The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t setup_rx_params(RxParamSetupReqParams_t* rxParamSetupReq );
virtual uint8_t accept_rx_param_setup_req(rx_param_setup_req_t* params);
/*!
* \brief The function processes a new channel request.
*
* \param [in] newChannelReq A pointer to the function parameters.
*
* \retval The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t request_new_channel(NewChannelReqParams_t* newChannelReq );
virtual int8_t get_alternate_DR(uint8_t nb_trials);
/*!
* \brief The function processes a TX ParamSetup request.
*
* \param [in] txParamSetupReq A pointer to the function parameters.
*
* \retval The status of the operation, according to the LoRaMAC specification.
* Returns -1, if the functionality is not implemented. In this case, the end node
* shall ignore the command.
*/
virtual int8_t setup_tx_params(TxParamSetupReqParams_t* txParamSetupReq );
virtual bool set_next_channel(channel_selection_params_t* next_chan_params,
uint8_t* channel, lorawan_time_t* time,
lorawan_time_t* aggregate_timeoff);
/*!
* \brief The function processes a DlChannel request.
*
* \param [in] dlChannelReq A pointer to the function parameters.
*
* \retval The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t dl_channel_request(DlChannelReqParams_t* dlChannelReq );
/*!
* \brief Alternates the datarate of the channel for the join request.
*
* \param [in] alternateDr A pointer to the function parameters.
*
* \retval The datarate to apply.
*/
virtual int8_t get_alternate_DR(AlternateDrParams_t* alternateDr );
/*!
* \brief Calculates the back-off time.
*
* \param [in] calcBackOff A pointer to the function parameters.
*/
virtual void calculate_backoff(CalcBackOffParams_t* calcBackOff );
/*!
* \brief Searches and sets the next random available channel.
*
* \param [in] nextChanParams The parameters for the next channel.
*
* \param [out] channel The next channel to use for TX.
*
* \param [out] time The time to wait for the next transmission according to the duty
* cycle.
*
* \param [out] aggregatedTimeOff Updates the aggregated time off.
*
* \retval The function status [1: OK, 0: Unable to find a channel on the current datarate].
*/
virtual bool set_next_channel(NextChanParams_t* nextChanParams,
uint8_t* channel, lorawan_time_t* time,
lorawan_time_t* aggregatedTimeOff );
/*!
* \brief Adds a channel.
*
* \param [in] channelAdd A pointer to the function parameters.
*
* \retval The status of the operation.
*/
virtual lorawan_status_t add_channel(ChannelAddParams_t* channelAdd );
/*!
* \brief Removes a channel.
*
* \param [in] channelRemove A pointer to the function parameters.
*
* \retval True, if the channel was removed successfully.
*/
virtual bool remove_channel(ChannelRemoveParams_t* channelRemove );
/*!
* \brief Sets the radio into continuous wave mode.
*
* \param [in] continuousWave A pointer to the function parameters.
*/
virtual void set_tx_cont_mode(ContinuousWaveParams_t* continuousWave );
/*!
* \brief Computes a new datarate according to the given offset.
*
* \param [in] downlinkDwellTime The downlink dwell time configuration. 0: No limit, 1: 400ms
*
* \param [in] dr The current datarate.
*
* \param [in] drOffset The offset to be applied.
*
* \retval newDr The computed datarate.
*/
virtual uint8_t apply_DR_offset(uint8_t downlinkDwellTime, int8_t dr, int8_t drOffset );
virtual uint8_t apply_DR_offset(int8_t dr, int8_t dr_offset);
private:
uint8_t CountNbOfEnabledChannels(uint8_t datarate,
uint16_t* channelsMask,
channel_params_t* channels,
band_t* bands, uint8_t* enabledChannels,
uint8_t* delayTx);
// Global attributes
/*!
* LoRaMAC channels
*/
channel_params_t Channels[AU915_MAX_NB_CHANNELS];
channel_params_t channels[AU915_MAX_NB_CHANNELS];
/*!
* LoRaMac bands
*/
band_t Bands[AU915_MAX_NB_BANDS];
band_t bands[AU915_MAX_NB_BANDS];
/*!
* LoRaMac channels mask
*/
uint16_t ChannelsMask[AU915_CHANNELS_MASK_SIZE];
uint16_t channel_masks[AU915_CHANNELS_MASK_SIZE];
/*!
* LoRaMac channels remaining
*/
uint16_t ChannelsMaskRemaining[AU915_CHANNELS_MASK_SIZE];
uint16_t current_channel_masks[AU915_CHANNELS_MASK_SIZE];
/*!
* LoRaMac channels default mask
*/
uint16_t ChannelsDefaultMask[AU915_CHANNELS_MASK_SIZE];
uint16_t default_channel_masks[AU915_CHANNELS_MASK_SIZE];
};
#endif /* MBED_OS_LORAPHY_AU915_H_ */

File diff suppressed because it is too large Load Diff

View File

@ -33,7 +33,6 @@
#define MBED_OS_LORAPHY_CN470_H_
#include "LoRaPHY.h"
#include "netsocket/LoRaRadio.h"
// Definitions
/*!
@ -57,309 +56,38 @@ public:
LoRaPHYCN470(LoRaWANTimeHandler &lora_time);
virtual ~LoRaPHYCN470();
/*!
* \brief The function gets a value of a specific PHY attribute.
*
* \param [in] getPhy A pointer to the function parameters.
*
* \retval A structure containing the PHY parameter.
*/
virtual PhyParam_t get_phy_params(GetPhyParams_t* getPhy );
virtual bool rx_config(rx_config_params_t* config, int8_t* datarate );
/*!
* \brief Updates the last TX done parameters of the current channel.
*
* \param [in] txDone A pointer to the function parameters.
*/
virtual void set_band_tx_done(SetBandTxDoneParams_t* txDone );
virtual bool tx_config(tx_config_params_t* config, int8_t* tx_power,
lorawan_time_t* tx_toa);
/*!
* \brief Initializes the channels masks and the channels.
*
* \param [in] type Sets the initialization type.
*/
virtual void load_defaults(InitType_t type );
virtual uint8_t link_ADR_request(adr_req_params_t* params, int8_t* dr_out,
int8_t* tx_power_out, uint8_t* nb_rep_out,
uint8_t* nb_bytes_parsed);
/*!
* \brief Verifies a parameter.
*
* \param [in] verify A pointer to the function parameters.
*
* \param [in] phyAttribute The attribute to be verified.
*
* \retval True, if the parameter is valid.
*/
virtual bool verify(VerifyParams_t* verify, PhyAttribute_t phyAttribute );
/*!
* \brief The function parses the input buffer and sets up the channels of the
* CF list.
*
* \param [in] applyCFList A pointer to the function parameters.
*/
virtual void apply_cf_list(ApplyCFListParams_t* applyCFList );
/*!
* \brief Sets a channels mask.
*
* \param [in] chanMaskSet A pointer to the function parameters.
*
* \retval True, if the channels mask could be set.
*/
virtual bool set_channel_mask(ChanMaskSetParams_t* chanMaskSet );
/*!
* \brief Calculates the next datarate to set, when ADR is on or off.
*
* \param [in] adrNext A pointer to the function parameters.
*
* \param [out] drOut The calculated datarate for the next TX.
*
* \param [out] txPowOut The TX power for the next TX.
*
* \param [out] adrAckCounter The calculated ADR acknowledgement counter.
*
* \retval True, if an ADR request should be performed.
*/
virtual bool get_next_ADR(AdrNextParams_t* adrNext, int8_t* drOut,
int8_t* txPowOut, uint32_t* adrAckCounter );
/*!
* \brief Configuration of the RX windows.
*
* \param [in] rxConfig A pointer to the function parameters.
*
* \param [out] datarate The datarate index set.
*
* \retval True, if the configuration was applied successfully.
*/
virtual bool rx_config(rx_config_params_t* rxConfig, int8_t* datarate );
/*
* RX window precise timing
*
* For more details please consult the following document, chapter 3.1.2.
* http://www.semtech.com/images/datasheet/SX1272_settings_for_LoRaWAN_v2.0.pdf
* or
* http://www.semtech.com/images/datasheet/SX1276_settings_for_LoRaWAN_v2.0.pdf
*
* Downlink start: T = Tx + 1s (+/- 20 us)
* |
* TRxEarly | TRxLate
* | | |
* | | +---+---+---+---+---+---+---+---+
* | | | Latest Rx window |
* | | +---+---+---+---+---+---+---+---+
* | | |
* +---+---+---+---+---+---+---+---+
* | Earliest Rx window |
* +---+---+---+---+---+---+---+---+
* |
* +---+---+---+---+---+---+---+---+
*Downlink preamble 8 symbols | | | | | | | | |
* +---+---+---+---+---+---+---+---+
*
* Worst case Rx window timings
*
* TRxLate = DEFAULT_MIN_RX_SYMBOLS * tSymbol - RADIO_WAKEUP_TIME
* TRxEarly = 8 - DEFAULT_MIN_RX_SYMBOLS * tSymbol - RxWindowTimeout - RADIO_WAKEUP_TIME
*
* TRxLate - TRxEarly = 2 * DEFAULT_SYSTEM_MAX_RX_ERROR
*
* RxOffset = ( TRxLate + TRxEarly ) / 2
*
* RxWindowTimeout = ( 2 * DEFAULT_MIN_RX_SYMBOLS - 8 ) * tSymbol + 2 * DEFAULT_SYSTEM_MAX_RX_ERROR
* RxOffset = 4 * tSymbol - RxWindowTimeout / 2 - RADIO_WAKE_UP_TIME
*
* The minimum value of RxWindowTimeout must be 5 symbols which implies that the system always tolerates at least an error of 1.5 * tSymbol
*/
/*!
* Computes the RX window timeout and offset.
*
* \param [in] datarate The RX window datarate index to be used.
*
* \param [in] minRxSymbols The minimum number of symbols required to detect an RX frame.
*
* \param [in] rxError The system maximum timing error of the receiver in milliseconds.
* The receiver will turn on in a [-rxError : +rxError] ms
* interval around RxOffset.
*
* \param [out] rxConfigParams The updated WindowTimeout and WindowOffset fields.
*/
virtual void compute_rx_win_params(int8_t datarate,
uint8_t minRxSymbols,
uint32_t rxError,
rx_config_params_t *rxConfigParams);
/*!
* \brief TX configuration.
*
* \param [in] txConfig A pointer to the function parameters.
*
* \param [out] txPower The TX power index set.
*
* \param [out] txTimeOnAir The time-on-air of the frame.
*
* \retval True, if the configuration was applied successfully.
*/
virtual bool tx_config(TxConfigParams_t* txConfig, int8_t* txPower,
lorawan_time_t* txTimeOnAir );
/*!
* \brief The function processes a Link ADR request.
*
* \param [in] linkAdrReq A pointer to the function parameters.
*
* \param [out] drOut The datarate applied.
*
* \param [out] txPowOut The TX power applied.
*
* \param [out] nbRepOut The number of repetitions to apply.
*
* \param [out] nbBytesParsed The number of bytes parsed.
*
* \retval The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t link_ADR_request(LinkAdrReqParams_t* linkAdrReq,
int8_t* drOut, int8_t* txPowOut,
uint8_t* nbRepOut,
uint8_t* nbBytesParsed );
/*!
* \brief The function processes a RX parameter setup request.
*
* \param [in] rxParamSetupReq A pointer to the function parameters.
*
* \retval The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t setup_rx_params(RxParamSetupReqParams_t* rxParamSetupReq );
/*!
* \brief The function processes a new channel request.
*
* \param [in] newChannelReq A pointer to the function parameters.
*
* \retval The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t request_new_channel(NewChannelReqParams_t* newChannelReq );
/*!
* \brief The function processes a TX ParamSetup request.
*
* \param [in] txParamSetupReq A pointer to the function parameters.
*
* \retval The status of the operation, according to the LoRaMAC specification.
* Returns -1, if the functionality is not implemented. In this case, the end node
* shall ignore the command.
*/
virtual int8_t setup_tx_params(TxParamSetupReqParams_t* txParamSetupReq );
/*!
* \brief The function processes a DlChannel request.
*
* \param [in] dlChannelReq A pointer to the function parameters.
*
* \retval The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t dl_channel_request(DlChannelReqParams_t* dlChannelReq );
/*!
* \brief Alternates the datarate of the channel for the join request.
*
* \param [in] alternateDr A pointer to the function parameters.
*
* \retval The datarate to apply.
*/
virtual int8_t get_alternate_DR(AlternateDrParams_t* alternateDr );
/*!
* \brief Calculates the back-off time.
*
* \param [in] calcBackOff A pointer to the function parameters.
*/
virtual void calculate_backoff(CalcBackOffParams_t* calcBackOff );
/*!
* \brief Searches and sets the next random available channel.
*
* \param [in] nextChanParams The parameters for the next channel
*
* \param [out] channel The next channel to use for TX.
*
* \param [out] time The time to wait for the next transmission according to the duty
* cycle.
*
* \param [out] aggregatedTimeOff Updates the aggregated time off.
*
* \retval Function status [1: OK, 0: Unable to find a channel on the current datarate].
*/
virtual bool set_next_channel(NextChanParams_t* nextChanParams,
uint8_t* channel, lorawan_time_t* time,
lorawan_time_t* aggregatedTimeOff );
/*!
* \brief Adds a channel.
*
* \param [in] channelAdd A pointer to the function parameters.
*
* \retval The status of the operation.
*/
virtual lorawan_status_t add_channel(ChannelAddParams_t* channelAdd );
/*!
* \brief Removes a channel.
*
* \param [in] channelRemove A pointer to the function parameters.
*
* \retval True, if the channel was removed successfully.
*/
virtual bool remove_channel(ChannelRemoveParams_t* channelRemove );
/*!
* \brief Sets the radio into continuous wave mode.
*
* \param [in] continuousWave A pointer to the function parameters.
*/
virtual void set_tx_cont_mode(ContinuousWaveParams_t* continuousWave );
/*!
* \brief Computes a new datarate according to the given offset.
*
* \param [in] downlinkDwellTime The downlink dwell time configuration. 0: No limit, 1: 400ms
*
* \param [in] dr The current datarate.
*
* \param [in] drOffset The offset to be applied.
*
* \retval newDr The computed datarate.
*/
virtual uint8_t apply_DR_offset(uint8_t downlinkDwellTime, int8_t dr, int8_t drOffset );
virtual uint8_t accept_rx_param_setup_req(rx_param_setup_req_t* params);
private:
uint8_t CountNbOfEnabledChannels( uint8_t datarate, uint16_t* channelsMask, channel_params_t* channels, band_t* bands, uint8_t* enabledChannels, uint8_t* delayTx );
bool RegionCN470ChanMaskSet( ChanMaskSetParams_t* chanMaskSet );
// Global attributes
/*!
* LoRaMAC channels
*/
channel_params_t Channels[CN470_MAX_NB_CHANNELS];
channel_params_t channels[CN470_MAX_NB_CHANNELS];
/*!
* LoRaMac bands
*/
band_t Bands[CN470_MAX_NB_BANDS];
band_t bands[CN470_MAX_NB_BANDS];
/*!
* LoRaMac channels mask
*/
uint16_t ChannelsMask[CN470_CHANNELS_MASK_SIZE];
uint16_t channel_masks[CN470_CHANNELS_MASK_SIZE];
/*!
* LoRaMac channels default mask
*/
uint16_t ChannelsDefaultMask[CN470_CHANNELS_MASK_SIZE];
uint16_t default_channel_masks[CN470_CHANNELS_MASK_SIZE];
};
#endif /* MBED_OS_LORAPHY_CN470_H_ */

File diff suppressed because it is too large Load Diff

View File

@ -33,7 +33,6 @@
#define MBED_OS_LORAPHY_CN779_H_
#include "LoRaPHY.h"
#include "netsocket/LoRaRadio.h"
#define CN779_MAX_NB_CHANNELS 16
@ -49,306 +48,26 @@ public:
LoRaPHYCN779(LoRaWANTimeHandler &lora_time);
virtual ~LoRaPHYCN779();
/*!
* \brief The function gets a value of a specific PHY attribute.
*
* \param [in] getPhy A pointer to the function parameters.
*
* \retval The structure containing the PHY parameter.
*/
virtual PhyParam_t get_phy_params(GetPhyParams_t* getPhy );
/*!
* \brief Updates the last TX done parameters of the current channel.
*
* \param [in] txDone A pointer to the function parameters.
*/
virtual void set_band_tx_done(SetBandTxDoneParams_t* txDone );
/*!
* \brief Initializes the channels masks and the channels.
*
* \param [in] type Sets the initialization type.
*/
virtual void load_defaults(InitType_t type );
/*!
* \brief Verifies a parameter.
*
* \param [in] verify A pointer to the function parameters.
*
* \param [in] phyAttribute The attribute to verify.
*
* \retval True, if the parameter is valid.
*/
virtual bool verify(VerifyParams_t* verify, PhyAttribute_t phyAttribute );
/*!
* \brief The function parses the input buffer and sets up the channels of the CF list.
*
* \param [in] applyCFList A pointer to the function parameters.
*/
virtual void apply_cf_list(ApplyCFListParams_t* applyCFList );
/*!
* \brief Sets a channels mask.
*
* \param [in] chanMaskSet A pointer to the function parameters.
*
* \retval True, if the channels mask could be set.
*/
virtual bool set_channel_mask(ChanMaskSetParams_t* chanMaskSet );
/*!
* \brief Calculates the next datarate to set, when ADR is on or off.
*
* \param [in] adrNext A pointer to the function parameters.
*
* \param [out] drOut The calculated datarate for the next TX.
*
* \param [out] txPowOut The TX power for the next TX.
*
* \param [out] adrAckCounter The calculated ADR acknowledgement counter.
*
* \retval True, if an ADR request should be performed.
*/
virtual bool get_next_ADR(AdrNextParams_t* adrNext, int8_t* drOut,
int8_t* txPowOut, uint32_t* adrAckCounter );
/*!
* \brief Configuration of the RX windows.
*
* \param [in] rxConfig A pointer to the function parameters.
*
* \param [out] datarate The datarate index set.
*
* \retval True, if the configuration was applied successfully.
*/
virtual bool rx_config(rx_config_params_t* rxConfig, int8_t* datarate );
/*
* RX window precise timing
*
* For more details please consult the following document, chapter 3.1.2.
* http://www.semtech.com/images/datasheet/SX1272_settings_for_LoRaWAN_v2.0.pdf
* or
* http://www.semtech.com/images/datasheet/SX1276_settings_for_LoRaWAN_v2.0.pdf
*
* Downlink start: T = Tx + 1s (+/- 20 us)
* |
* TRxEarly | TRxLate
* | | |
* | | +---+---+---+---+---+---+---+---+
* | | | Latest Rx window |
* | | +---+---+---+---+---+---+---+---+
* | | |
* +---+---+---+---+---+---+---+---+
* | Earliest Rx window |
* +---+---+---+---+---+---+---+---+
* |
* +---+---+---+---+---+---+---+---+
*Downlink preamble 8 symbols | | | | | | | | |
* +---+---+---+---+---+---+---+---+
*
* Worst case Rx window timings
*
* TRxLate = DEFAULT_MIN_RX_SYMBOLS * tSymbol - RADIO_WAKEUP_TIME
* TRxEarly = 8 - DEFAULT_MIN_RX_SYMBOLS * tSymbol - RxWindowTimeout - RADIO_WAKEUP_TIME
*
* TRxLate - TRxEarly = 2 * DEFAULT_SYSTEM_MAX_RX_ERROR
*
* RxOffset = ( TRxLate + TRxEarly ) / 2
*
* RxWindowTimeout = ( 2 * DEFAULT_MIN_RX_SYMBOLS - 8 ) * tSymbol + 2 * DEFAULT_SYSTEM_MAX_RX_ERROR
* RxOffset = 4 * tSymbol - RxWindowTimeout / 2 - RADIO_WAKE_UP_TIME
*
* The minimum value of RxWindowTimeout must be 5 symbols which implies that the system always tolerates at least an error of 1.5 * tSymbol
*/
/*!
* Computes the RX window timeout and offset.
*
* \param [in] datarate The RX window datarate index to be used.
*
* \param [in] minRxSymbols The minimum required number of symbols to detect an RX frame.
*
* \param [in] rxError The system maximum timing error of the receiver in milliseconds.
* The receiver will turn on in a [-rxError : +rxError] ms
* interval around RxOffset.
*
* \param [out] rxConfigParams Returns the updated WindowTimeout and WindowOffset fields.
*/
virtual void compute_rx_win_params(int8_t datarate,
uint8_t minRxSymbols,
uint32_t rxError,
rx_config_params_t *rxConfigParams);
/*!
* \brief TX configuration.
*
* \param [in] txConfig A pointer to the function parameters.
*
* \param [out] txPower The TX power index set.
*
* \param [out] txTimeOnAir The time-on-air of the frame.
*
* \retval True, if the configuration was applied successfully.
*/
virtual bool tx_config(TxConfigParams_t* txConfig, int8_t* txPower,
lorawan_time_t* txTimeOnAir );
/*!
* \brief The function processes a Link ADR request.
*
* \param [in] linkAdrReq A pointer to the function parameters.
*
* \param [out] drOut The datarate applied.
*
* \param [out] txPowOut The TX power applied.
*
* \param [out] nbRepOut The number of repetitions to apply.
*
* \param [out] nbBytesParsed The number of bytes parsed.
*
* \retval The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t link_ADR_request(LinkAdrReqParams_t* linkAdrReq,
int8_t* drOut, int8_t* txPowOut,
uint8_t* nbRepOut,
uint8_t* nbBytesParsed );
/*!
* \brief The function processes a RX parameter setup request.
*
* \param [in] rxParamSetupReq A pointer to the function parameters.
*
* \retval The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t setup_rx_params(RxParamSetupReqParams_t* rxParamSetupReq );
/*!
* \brief The function processes a new channel request.
*
* \param [in] newChannelReq A pointer to the function parameters.
*
* \retval The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t request_new_channel(NewChannelReqParams_t* newChannelReq );
/*!
* \brief The function processes a TX ParamSetup request.
*
* \param [in] txParamSetupReq A pointer to the function parameters.
*
* \retval The status of the operation, according to the LoRaMAC specification.
* Returns -1, if the functionality is not implemented. In this case, the end node
* shall ignore the command.
*/
virtual int8_t setup_tx_params(TxParamSetupReqParams_t* txParamSetupReq );
/*!
* \brief The function processes a DlChannel request.
*
* \param [in] dlChannelReq A pointer to the function parameters.
*
* \retval The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t dl_channel_request(DlChannelReqParams_t* dlChannelReq );
/*!
* \brief Alternates the datarate of the channel for the join request.
*
* \param [in] alternateDr A pointer to the function parameters.
*
* \retval The datarate to apply.
*/
virtual int8_t get_alternate_DR(AlternateDrParams_t* alternateDr );
/*!
* \brief Calculates the back-off time.
*
* \param [in] calcBackOff A pointer to the function parameters.
*/
virtual void calculate_backoff(CalcBackOffParams_t* calcBackOff );
/*!
* \brief Searches and sets the next random available channel.
*
* \param [in] nextChanParams The parameters for the next channel.
*
* \param [out] channel The next channel to use for TX.
*
* \param [out] time The time to wait for the next transmission according to the duty
* cycle.
*
* \param [out] aggregatedTimeOff Updates the aggregated time off.
*
* \retval Function status [1: OK, 0: Unable to find a channel on the current datarate].
*/
virtual bool set_next_channel(NextChanParams_t* nextChanParams,
uint8_t* channel, lorawan_time_t* time,
lorawan_time_t* aggregatedTimeOff );
/*!
* \brief Adds a channel.
*
* \param [in] channelAdd A pointer to the function parameters.
*
* \retval The status of the operation.
*/
virtual lorawan_status_t add_channel(ChannelAddParams_t* channelAdd );
/*!
* \brief Removes a channel.
*
* \param [in] channelRemove A pointer to the function parameters.
*
* \retval True, if the channel was removed successfully.
*/
virtual bool remove_channel(ChannelRemoveParams_t* channelRemove );
/*!
* \brief Sets the radio into continuous wave mode.
*
* \param [in] continuousWave A pointer to the function parameters.
*/
virtual void set_tx_cont_mode(ContinuousWaveParams_t* continuousWave );
/*!
* \brief Computes a new datarate according to the given offset.
*
* \param [in] downlinkDwellTime The downlink dwell time configuration. 0: No limit, 1: 400ms
*
* \param [in] dr The current datarate.
*
* \param [in] drOffset The offset to be applied.
*
* \retval newDr The computed datarate.
*/
virtual uint8_t apply_DR_offset(uint8_t downlinkDwellTime, int8_t dr, int8_t drOffset );
private:
uint8_t CountNbOfEnabledChannels( bool joined, uint8_t datarate, uint16_t* channelsMask, channel_params_t* channels, band_t* bands, uint8_t* enabledChannels, uint8_t* delayTx );
// Global attributes
/*!
* LoRaMAC channels
*/
channel_params_t Channels[CN779_MAX_NB_CHANNELS];
channel_params_t channels[CN779_MAX_NB_CHANNELS];
/*!
* LoRaMac bands
*/
band_t Bands[CN779_MAX_NB_BANDS];
band_t bands[CN779_MAX_NB_BANDS];
/*!
* LoRaMac channels mask
*/
uint16_t ChannelsMask[CN779_CHANNELS_MASK_SIZE];
uint16_t channel_masks[CN779_CHANNELS_MASK_SIZE];
/*!
* LoRaMac channels default mask
*/
uint16_t ChannelsDefaultMask[CN779_CHANNELS_MASK_SIZE];
uint16_t default_channel_masks[CN779_CHANNELS_MASK_SIZE];
};
#endif /* MBED_OS_LORAPHY_CN779_H_ */

File diff suppressed because it is too large Load Diff

View File

@ -33,7 +33,6 @@
#define MBED_OS_LORAPHY_EU433_H_
#include "LoRaPHY.h"
#include "netsocket/LoRaRadio.h"
/*!
* LoRaMac maximum number of channels
@ -55,306 +54,26 @@ public:
LoRaPHYEU433(LoRaWANTimeHandler &lora_time);
virtual ~LoRaPHYEU433();
/*!
* \brief The function gets a value of a specific PHY attribute.
*
* \param [in] getPhy A pointer to the function parameters.
*
* \retval The structure containing the PHY parameter.
*/
virtual PhyParam_t get_phy_params(GetPhyParams_t* getPhy );
/*!
* \brief Updates the last TX done parameters of the current channel.
*
* \param [in] txDone A pointer to the function parameters.
*/
virtual void set_band_tx_done(SetBandTxDoneParams_t* txDone );
/*!
* \brief Initializes the channels masks and the channels.
*
* \param [in] type Sets the initialization type.
*/
virtual void load_defaults(InitType_t type );
/*!
* \brief Verifies a parameter.
*
* \param [in] verify A pointer to the function parameters.
*
* \param [in] phyAttribute The attribute to verify.
*
* \retval True, if the parameter is valid.
*/
virtual bool verify(VerifyParams_t* verify, PhyAttribute_t phyAttribute );
/*!
* \brief The function parses the input buffer and sets up the channels of the CF list.
*
* \param [in] applyCFList A pointer to the function parameters.
*/
virtual void apply_cf_list(ApplyCFListParams_t* applyCFList );
/*!
* \brief Sets a channels mask.
*
* \param [in] chanMaskSet A pointer to the function parameters.
*
* \retval True, if the channels mask could be set.
*/
virtual bool set_channel_mask(ChanMaskSetParams_t* chanMaskSet );
/*!
* \brief Calculates the next datarate to set, when ADR is on or off.
*
* \param [in] adrNext A pointer to the function parameters.
*
* \param [out] drOut The calculated datarate for the next TX.
*
* \param [out] txPowOut The TX power for the next TX.
*
* \param [out] adrAckCounter The calculated ADR acknowledgement counter.
*
* \retval True, if an ADR request should be performed.
*/
virtual bool get_next_ADR(AdrNextParams_t* adrNext, int8_t* drOut,
int8_t* txPowOut, uint32_t* adrAckCounter );
/*!
* \brief Configuration of the RX windows.
*
* \param [in] rxConfig A pointer to the function parameters.
*
* \param [out] datarate The datarate index set.
*
* \retval True, if the configuration was applied successfully.
*/
virtual bool rx_config(rx_config_params_t* rxConfig, int8_t* datarate );
/*
* RX window precise timing
*
* For more details please consult the following document, chapter 3.1.2.
* http://www.semtech.com/images/datasheet/SX1272_settings_for_LoRaWAN_v2.0.pdf
* or
* http://www.semtech.com/images/datasheet/SX1276_settings_for_LoRaWAN_v2.0.pdf
*
* Downlink start: T = Tx + 1s (+/- 20 us)
* |
* TRxEarly | TRxLate
* | | |
* | | +---+---+---+---+---+---+---+---+
* | | | Latest Rx window |
* | | +---+---+---+---+---+---+---+---+
* | | |
* +---+---+---+---+---+---+---+---+
* | Earliest Rx window |
* +---+---+---+---+---+---+---+---+
* |
* +---+---+---+---+---+---+---+---+
*Downlink preamble 8 symbols | | | | | | | | |
* +---+---+---+---+---+---+---+---+
*
* Worst case Rx window timings
*
* TRxLate = DEFAULT_MIN_RX_SYMBOLS * tSymbol - RADIO_WAKEUP_TIME
* TRxEarly = 8 - DEFAULT_MIN_RX_SYMBOLS * tSymbol - RxWindowTimeout - RADIO_WAKEUP_TIME
*
* TRxLate - TRxEarly = 2 * DEFAULT_SYSTEM_MAX_RX_ERROR
*
* RxOffset = ( TRxLate + TRxEarly ) / 2
*
* RxWindowTimeout = ( 2 * DEFAULT_MIN_RX_SYMBOLS - 8 ) * tSymbol + 2 * DEFAULT_SYSTEM_MAX_RX_ERROR
* RxOffset = 4 * tSymbol - RxWindowTimeout / 2 - RADIO_WAKE_UP_TIME
*
* The minimum value of RxWindowTimeout must be 5 symbols which implies that the system always tolerates at least an error of 1.5 * tSymbol
*/
/*!
* Computes the RX window timeout and offset.
*
* \param [in] datarate The RX window datarate index to be used.
*
* \param [in] minRxSymbols The minimum number of symbols required to detect an RX frame.
*
* \param [in] rxError The system maximum timing error of the receiver in milliseconds.
* The receiver will turn on in a [-rxError : +rxError] ms
* interval around RxOffset.
*
* \param [out] rxConfigParams Returns the updated WindowTimeout and WindowOffset fields.
*/
virtual void compute_rx_win_params(int8_t datarate,
uint8_t minRxSymbols,
uint32_t rxError,
rx_config_params_t *rxConfigParams);
/*!
* \brief TX configuration.
*
* \param [in] txConfig A pointer to the function parameters.
*
* \param [out] txPower The TX power index set.
*
* \param [out] txTimeOnAir The time-on-air of the frame.
*
* \retval True, if the configuration was applied successfully.
*/
virtual bool tx_config(TxConfigParams_t* txConfig, int8_t* txPower,
lorawan_time_t* txTimeOnAir );
/*!
* \brief The function processes a Link ADR request.
*
* \param [in] linkAdrReq A pointer to the function parameters.
*
* \param [out] drOut The datarate applied.
*
* \param [out] txPowOut The TX power applied.
*
* \param [out] nbRepOut The number of repetitions to apply.
*
* \param [out] nbBytesParsed The number of bytes parsed.
*
* \retval The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t link_ADR_request(LinkAdrReqParams_t* linkAdrReq,
int8_t* drOut, int8_t* txPowOut,
uint8_t* nbRepOut,
uint8_t* nbBytesParsed );
/*!
* \brief The function processes a RX parameter setup request.
*
* \param [in] rxParamSetupReq A pointer to the function parameters.
*
* \retval The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t setup_rx_params(RxParamSetupReqParams_t* rxParamSetupReq );
/*!
* \brief The function processes a new channel request.
*
* \param [in] newChannelReq A pointer to the function parameters.
*
* \retval The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t request_new_channel(NewChannelReqParams_t* newChannelReq );
/*!
* \brief The function processes a TX ParamSetup request.
*
* \param [in] txParamSetupReq A pointer to the function parameters.
*
* \retval The status of the operation, according to the LoRaMAC specification.
* Returns -1, if the functionality is not implemented. In this case, the end node
* shall ignore the command.
*/
virtual int8_t setup_tx_params(TxParamSetupReqParams_t* txParamSetupReq );
/*!
* \brief The function processes a DlChannel request.
*
* \param [in] dlChannelReq A pointer to the function parameters.
*
* \retval The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t dl_channel_request(DlChannelReqParams_t* dlChannelReq );
/*!
* \brief Alternates the datarate of the channel for the join request.
*
* \param [in] alternateDr A pointer to the function parameters.
*
* \retval The datarate to apply.
*/
virtual int8_t get_alternate_DR(AlternateDrParams_t* alternateDr );
/*!
* \brief Calculates the back-off time.
*
* \param [in] calcBackOff A pointer to the function parameters.
*/
virtual void calculate_backoff(CalcBackOffParams_t* calcBackOff );
/*!
* \brief Searches and sets the next random available channel.
*
* \param [in] nextChanParams The parameters for the next channel
*
* \param [out] channel The next channel to use for TX.
*
* \param [out] time The time to wait for the next transmission according to the duty
* cycle.
*
* \param [out] aggregatedTimeOff Updates the aggregated time off.
*
* \retval Function status [1: OK, 0: Unable to find a channel on the current datarate].
*/
virtual bool set_next_channel(NextChanParams_t* nextChanParams,
uint8_t* channel, lorawan_time_t* time,
lorawan_time_t* aggregatedTimeOff );
/*!
* \brief Adds a channel.
*
* \param [in] channelAdd A pointer to the function parameters.
*
* \retval The status of the operation.
*/
virtual lorawan_status_t add_channel(ChannelAddParams_t* channelAdd );
/*!
* \brief Removes a channel.
*
* \param [in] channelRemove A pointer to the function parameters.
*
* \retval True, if the channel was removed successfully.
*/
virtual bool remove_channel(ChannelRemoveParams_t* channelRemove );
/*!
* \brief Sets the radio into continuous wave mode.
*
* \param [in] continuousWave A pointer to the function parameters.
*/
virtual void set_tx_cont_mode(ContinuousWaveParams_t* continuousWave );
/*!
* \brief Computes new datarate according to the given offset.
*
* \param [in] downlinkDwellTime The downlink dwell time configuration. 0: No limit, 1: 400ms
*
* \param [in] dr The current datarate.
*
* \param [in] drOffset The offset to be applied.
*
* \retval newDr The computed datarate.
*/
virtual uint8_t apply_DR_offset(uint8_t downlinkDwellTime, int8_t dr, int8_t drOffset );
private:
uint8_t CountNbOfEnabledChannels( bool joined, uint8_t datarate, uint16_t* channelsMask, channel_params_t* channels, band_t* bands, uint8_t* enabledChannels, uint8_t* delayTx );
// Global attributes
/*!
* LoRaMAC channels
*/
channel_params_t Channels[EU433_MAX_NB_CHANNELS];
channel_params_t channels[EU433_MAX_NB_CHANNELS];
/*!
* LoRaMac bands
*/
band_t Bands[EU433_MAX_NB_BANDS];
band_t bands[EU433_MAX_NB_BANDS];
/*!
* LoRaMac channels mask
*/
uint16_t ChannelsMask[EU433_CHANNELS_MASK_SIZE];
uint16_t channel_masks[EU433_CHANNELS_MASK_SIZE];
/*!
* LoRaMac channels default mask
*/
uint16_t ChannelsDefaultMask[EU433_CHANNELS_MASK_SIZE];
uint16_t default_channel_masks[EU433_CHANNELS_MASK_SIZE];
};

File diff suppressed because it is too large Load Diff

View File

@ -33,7 +33,6 @@
#define MBED_OS_LORAPHY_EU868_H_
#include "LoRaPHY.h"
#include "netsocket/LoRaRadio.h"
/*!
* LoRaMac maximum number of channels
@ -42,317 +41,42 @@
/*!
* Maximum number of bands
*
* We have broken down EU-868 MHz BAND 2 into two parts. That's why
* total number of sub-bands is 6.
* from 863 MHz to 865 MHz region is part of BAND 2, however
* we call it Band-5 here. Duty cycle limit is 0.1 % in this sub band.
*/
#define EU868_MAX_NB_BANDS 5
#define EU868_MAX_NB_BANDS 6
#define EU868_CHANNELS_MASK_SIZE 1
class LoRaPHYEU868 : public LoRaPHY {
public:
LoRaPHYEU868(LoRaWANTimeHandler &lora_time);
virtual ~LoRaPHYEU868();
/*!
* \brief The function gets a value of a specific PHY attribute.
*
* \param [in] getPhy A pointer to the function parameters.
*
* \retval The structure containing the PHY parameter.
*/
virtual PhyParam_t get_phy_params(GetPhyParams_t* getPhy );
/*!
* \brief Updates the last TX done parameters of the current channel.
*
* \param [in] txDone A pointer to the function parameters.
*/
virtual void set_band_tx_done(SetBandTxDoneParams_t* txDone );
/*!
* \brief Initializes the channels masks and the channels.
*
* \param [in] type Sets the initialization type.
*/
virtual void load_defaults(InitType_t type );
/*!
* \brief Verifies a parameter.
*
* \param [in] verify A pointer to the function parameters.
*
* \param [in] phyAttribute The attribute to verify.
*
* \retval True, if the parameter is valid.
*/
virtual bool verify(VerifyParams_t* verify, PhyAttribute_t phyAttribute );
/*!
* \brief The function parses the input buffer and sets up the channels of the CF list.
*
* \param [in] applyCFList A pointer to the function parameters.
*/
virtual void apply_cf_list(ApplyCFListParams_t* applyCFList );
/*!
* \brief Sets a channels mask.
*
* \param [in] chanMaskSet A pointer to the function parameters.
*
* \retval True, if the channels mask could be set.
*/
virtual bool set_channel_mask(ChanMaskSetParams_t* chanMaskSet );
/*!
* \brief Calculates the next datarate to set, when ADR is on or off.
*
* \param [in] adrNext A pointer to the function parameters.
*
* \param [out] drOut The calculated datarate for the next TX.
*
* \param [out] txPowOut The TX power for the next TX.
*
* \param [out] adrAckCounter The calculated ADR acknowledgement counter.
*
* \retval True, if an ADR request should be performed.
*/
virtual bool get_next_ADR(AdrNextParams_t* adrNext, int8_t* drOut,
int8_t* txPowOut, uint32_t* adrAckCounter );
/*!
* \brief Configuration of the RX windows.
*
* \param [in] rxConfig A pointer to the function parameters.
*
* \param [out] datarate The datarate index set.
*
* \retval True, if the configuration was applied successfully.
*/
virtual bool rx_config(rx_config_params_t* rxConfig, int8_t* datarate );
/*
* RX window precise timing
*
* For more details please consult the following document, chapter 3.1.2.
* http://www.semtech.com/images/datasheet/SX1272_settings_for_LoRaWAN_v2.0.pdf
* or
* http://www.semtech.com/images/datasheet/SX1276_settings_for_LoRaWAN_v2.0.pdf
*
* Downlink start: T = Tx + 1s (+/- 20 us)
* |
* TRxEarly | TRxLate
* | | |
* | | +---+---+---+---+---+---+---+---+
* | | | Latest Rx window |
* | | +---+---+---+---+---+---+---+---+
* | | |
* +---+---+---+---+---+---+---+---+
* | Earliest Rx window |
* +---+---+---+---+---+---+---+---+
* |
* +---+---+---+---+---+---+---+---+
*Downlink preamble 8 symbols | | | | | | | | |
* +---+---+---+---+---+---+---+---+
*
* Worst case Rx window timings
*
* TRxLate = DEFAULT_MIN_RX_SYMBOLS * tSymbol - RADIO_WAKEUP_TIME
* TRxEarly = 8 - DEFAULT_MIN_RX_SYMBOLS * tSymbol - RxWindowTimeout - RADIO_WAKEUP_TIME
*
* TRxLate - TRxEarly = 2 * DEFAULT_SYSTEM_MAX_RX_ERROR
*
* RxOffset = ( TRxLate + TRxEarly ) / 2
*
* RxWindowTimeout = ( 2 * DEFAULT_MIN_RX_SYMBOLS - 8 ) * tSymbol + 2 * DEFAULT_SYSTEM_MAX_RX_ERROR
* RxOffset = 4 * tSymbol - RxWindowTimeout / 2 - RADIO_WAKE_UP_TIME
*
* The minimum value of RxWindowTimeout must be 5 symbols which implies that the system always tolerates at least an error of 1.5 * tSymbol
*/
/*!
* Computes the RX window timeout and offset.
*
* \param [in] datarate The RX window datarate index to be used.
*
* \param [in] minRxSymbols The minimum number of symbols required to detect an RX frame.
*
* \param [in] rxError The system maximum timing error of the receiver in milliseconds.
* The receiver will turn on in a [-rxError : +rxError] ms
* interval around RxOffset.
*
* \param [out] rxConfigParams Returns the updated WindowTimeout and WindowOffset fields.
*/
virtual void compute_rx_win_params(int8_t datarate,
uint8_t minRxSymbols,
uint32_t rxError,
rx_config_params_t *rxConfigParams);
/*!
* \brief TX configuration.
*
* \param [in] txConfig A pointer to the function parameters.
*
* \param [out] txPower The TX power index set.
*
* \param [out] txTimeOnAir The time-on-air of the frame.
*
* \retval True, if the configuration was applied successfully.
*/
virtual bool tx_config(TxConfigParams_t* txConfig, int8_t* txPower,
lorawan_time_t* txTimeOnAir );
/*!
* \brief The function processes a Link ADR request.
*
* \param [in] linkAdrReq A pointer to the function parameters.
*
* \param [out] drOut The datarate applied.
*
* \param [out] txPowOut The TX power applied.
*
* \param [out] nbRepOut The number of repetitions to apply.
*
* \param [out] nbBytesParsed The number of bytes parsed.
*
* \retval The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t link_ADR_request(LinkAdrReqParams_t* linkAdrReq,
int8_t* drOut, int8_t* txPowOut,
uint8_t* nbRepOut,
uint8_t* nbBytesParsed );
/*!
* \brief The function processes a RX parameter setup request.
*
* \param [in] rxParamSetupReq A pointer to the function parameters.
*
* \retval The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t setup_rx_params(RxParamSetupReqParams_t* rxParamSetupReq );
/*!
* \brief The function processes a new channel request.
*
* \param [in] newChannelReq A pointer to the function parameters.
*
* \retval The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t request_new_channel(NewChannelReqParams_t* newChannelReq );
/*!
* \brief The function processes a TX ParamSetup request.
*
* \param [in] txParamSetupReq A pointer to the function parameters.
*
* \retval The status of the operation, according to the LoRaMAC specification.
* Returns -1, if the functionality is not implemented. In this case, the end node
* shall ignore the command.
*/
virtual int8_t setup_tx_params(TxParamSetupReqParams_t* txParamSetupReq );
/*!
* \brief The function processes a DlChannel request.
*
* \param [in] dlChannelReq A pointer to the function parameters.
*
* \retval The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t dl_channel_request(DlChannelReqParams_t* dlChannelReq );
/*!
* \brief Alternates the datarate of the channel for the join request.
*
* \param [in] alternateDr A pointer to the function parameters.
*
* \retval The datarate to apply.
*/
virtual int8_t get_alternate_DR(AlternateDrParams_t* alternateDr );
/*!
* \brief Calculates the back-off time.
*
* \param [in] calcBackOff A pointer to the function parameters.
*/
virtual void calculate_backoff(CalcBackOffParams_t* calcBackOff );
/*!
* \brief Searches and sets the next random available channel.
*
* \param [in] nextChanParams The parameters for the next channel.
*
* \param [out] channel The next channel to use for TX.
*
* \param [out] time The time to wait for the next transmission according to the duty cycle.
*
* \param [out] aggregatedTimeOff Updates the aggregated time off.
*
* \retval The function status [1: OK, 0: Unable to find a channel on the current datarate].
*/
virtual bool set_next_channel(NextChanParams_t* nextChanParams,
uint8_t* channel, lorawan_time_t* time,
lorawan_time_t* aggregatedTimeOff );
/*!
* \brief Adds a channel.
*
* \param [in] channelAdd A pointer to the function parameters.
*
* \retval The status of the operation.
*/
virtual lorawan_status_t add_channel(ChannelAddParams_t* channelAdd );
/*!
* \brief Removes a channel.
*
* \param [in] channelRemove A pointer to the function parameters.
*
* \retval True, if the channel was removed successfully.
*/
virtual bool remove_channel(ChannelRemoveParams_t* channelRemove );
/*!
* \brief Sets the radio into continuous wave mode.
*
* \param [in] continuousWave A pointer to the function parameters.
*/
virtual void set_tx_cont_mode(ContinuousWaveParams_t* continuousWave );
/*!
* \brief Computes a new datarate according to the given offset.
*
* \param [in] downlinkDwellTime The downlink dwell time configuration. 0: No limit, 1: 400ms
*
* \param [in] dr The current datarate.
*
* \param [in] drOffset The offset to be applied.
*
* \retval newDr The computed datarate.
*/
virtual uint8_t apply_DR_offset(uint8_t downlinkDwellTime, int8_t dr, int8_t drOffset );
private:
uint8_t CountNbOfEnabledChannels( bool joined, uint8_t datarate, uint16_t* channelsMask, channel_params_t* channels, band_t* bands, uint8_t* enabledChannels, uint8_t* delayTx );
// Global attributes
/*!
* LoRaMAC channels
*/
channel_params_t Channels[EU868_MAX_NB_CHANNELS];
channel_params_t channels[EU868_MAX_NB_CHANNELS];
/*!
* LoRaMac bands
*/
band_t Bands[EU868_MAX_NB_BANDS];
band_t bands[EU868_MAX_NB_BANDS];
/*!
* LoRaMac channels mask
*/
uint16_t ChannelsMask[EU868_CHANNELS_MASK_SIZE];
uint16_t channel_masks[EU868_CHANNELS_MASK_SIZE];
/*!
* LoRaMac channels default mask
*/
uint16_t ChannelsDefaultMask[EU868_CHANNELS_MASK_SIZE];
uint16_t default_channel_masks[EU868_CHANNELS_MASK_SIZE];
};
#endif /* MBED_OS_LORAPHY_EU868_H_ */

File diff suppressed because it is too large Load Diff

View File

@ -33,7 +33,6 @@
#define MBED_OS_LORAPHY_IN865_H_
#include "LoRaPHY.h"
#include "netsocket/LoRaRadio.h"
/*!
@ -57,305 +56,28 @@ public:
LoRaPHYIN865(LoRaWANTimeHandler &lora_time);
virtual ~LoRaPHYIN865();
/*!
* \brief The function gets a value of a specific PHY attribute.
*
* \param [in] getPhy A pointer to the function parameters.
*
* \retval The structure containing the PHY parameter.
*/
virtual PhyParam_t get_phy_params(GetPhyParams_t* getPhy );
/*!
* \brief Updates the last TX done parameters of the current channel.
*
* \param [in] txDone A pointer to the function parameters.
*/
virtual void set_band_tx_done(SetBandTxDoneParams_t* txDone );
/*!
* \brief Initializes the channels masks and the channels.
*
* \param [in] type Sets the initialization type.
*/
virtual void load_defaults(InitType_t type );
/*!
* \brief Verifies a parameter.
*
* \param [in] verify A pointer to the function parameters.
*
* \param [in] phyAttribute The attribute to verify.
*
* \retval True, if the parameter is valid.
*/
virtual bool verify(VerifyParams_t* verify, PhyAttribute_t phyAttribute );
/*!
* \brief The function parses the input buffer and sets up the channels of the CF list.
*
* \param [in] applyCFList A pointer to the function parameters.
*/
virtual void apply_cf_list(ApplyCFListParams_t* applyCFList );
/*!
* \brief Sets a channels mask.
*
* \param [in] chanMaskSet A pointer to the function parameters.
*
* \retval True, if the channels mask could be set.
*/
virtual bool set_channel_mask(ChanMaskSetParams_t* chanMaskSet );
/*!
* \brief Calculates the next datarate to set, when ADR is on or off.
*
* \param [in] adrNext A pointer to the function parameters.
*
* \param [out] drOut The calculated datarate for the next TX.
*
* \param [out] txPowOut The TX power for the next TX.
*
* \param [out] adrAckCounter The calculated ADR acknowledgement counter.
*
* \retval True, if an ADR request should be performed.
*/
virtual bool get_next_ADR(AdrNextParams_t* adrNext, int8_t* drOut,
int8_t* txPowOut, uint32_t* adrAckCounter );
/*!
* \brief Configuration of the RX windows.
*
* \param [in] rxConfig A pointer to the function parameters.
*
* \param [out] datarate The datarate index set.
*
* \retval True, if the configuration was applied successfully.
*/
virtual bool rx_config(rx_config_params_t* rxConfig, int8_t* datarate );
/*
* RX window precise timing
*
* For more details, please consult the following document, chapter 3.1.2.
* http://www.semtech.com/images/datasheet/SX1272_settings_for_LoRaWAN_v2.0.pdf
* or
* http://www.semtech.com/images/datasheet/SX1276_settings_for_LoRaWAN_v2.0.pdf
*
* Downlink start: T = Tx + 1s (+/- 20 us)
* |
* TRxEarly | TRxLate
* | | |
* | | +---+---+---+---+---+---+---+---+
* | | | Latest Rx window |
* | | +---+---+---+---+---+---+---+---+
* | | |
* +---+---+---+---+---+---+---+---+
* | Earliest Rx window |
* +---+---+---+---+---+---+---+---+
* |
* +---+---+---+---+---+---+---+---+
*Downlink preamble 8 symbols | | | | | | | | |
* +---+---+---+---+---+---+---+---+
*
* Worst case Rx window timings
*
* TRxLate = DEFAULT_MIN_RX_SYMBOLS * tSymbol - RADIO_WAKEUP_TIME
* TRxEarly = 8 - DEFAULT_MIN_RX_SYMBOLS * tSymbol - RxWindowTimeout - RADIO_WAKEUP_TIME
*
* TRxLate - TRxEarly = 2 * DEFAULT_SYSTEM_MAX_RX_ERROR
*
* RxOffset = ( TRxLate + TRxEarly ) / 2
*
* RxWindowTimeout = ( 2 * DEFAULT_MIN_RX_SYMBOLS - 8 ) * tSymbol + 2 * DEFAULT_SYSTEM_MAX_RX_ERROR
* RxOffset = 4 * tSymbol - RxWindowTimeout / 2 - RADIO_WAKE_UP_TIME
*
* The minimum value of RxWindowTimeout must be 5 symbols which implies that the system always tolerates at least an error of 1.5 * tSymbol
*/
/*!
* Computes the RX window timeout and offset.
*
* \param [in] datarate The RX window datarate index to be used.
*
* \param [in] minRxSymbols The minimum number of symbols required to detect an RX frame.
*
* \param [in] rxError The system maximum timing error of the receiver in milliseconds.
* The receiver will turn on in a [-rxError : +rxError] ms
* interval around RxOffset.
*
* \param [out] rxConfigParams Returns the updated WindowTimeout and WindowOffset fields.
*/
virtual void compute_rx_win_params(int8_t datarate,
uint8_t minRxSymbols,
uint32_t rxError,
rx_config_params_t *rxConfigParams);
/*!
* \brief TX configuration.
*
* \param [in] txConfig A pointer to the function parameters.
*
* \param [out] txPower The TX power index set.
*
* \param [out] txTimeOnAir The time-on-air of the frame.
*
* \retval True, if the configuration was applied successfully.
*/
virtual bool tx_config(TxConfigParams_t* txConfig, int8_t* txPower,
lorawan_time_t* txTimeOnAir );
/*!
* \brief The function processes a Link ADR request.
*
* \param [in] linkAdrReq A pointer to the function parameters.
*
* \param [out] drOut The datarate applied.
*
* \param [out] txPowOut The TX power applied.
*
* \param [out] nbRepOut The number of repetitions to apply.
*
* \param [out] nbBytesParsed The number of bytes parsed.
*
* \retval The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t link_ADR_request(LinkAdrReqParams_t* linkAdrReq,
int8_t* drOut, int8_t* txPowOut,
uint8_t* nbRepOut,
uint8_t* nbBytesParsed );
/*!
* \brief The function processes a RX parameter setup request.
*
* \param [in] rxParamSetupReq A pointer to the function parameters.
*
* \retval The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t setup_rx_params(RxParamSetupReqParams_t* rxParamSetupReq );
/*!
* \brief The function processes a new channel request.
*
* \param [in] newChannelReq A pointer to the function parameters.
*
* \retval The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t request_new_channel(NewChannelReqParams_t* newChannelReq );
/*!
* \brief The function processes a TX ParamSetup request.
*
* \param [in] txParamSetupReq A pointer to the function parameters.
*
* \retval The status of the operation, according to the LoRaMAC specification.
* Returns -1, if the functionality is not implemented. In this case, the end node
* shall ignore the command.
*/
virtual int8_t setup_tx_params(TxParamSetupReqParams_t* txParamSetupReq );
/*!
* \brief The function processes a DlChannel request.
*
* \param [in] dlChannelReq A pointer to the function parameters.
*
* \retval The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t dl_channel_request(DlChannelReqParams_t* dlChannelReq );
/*!
* \brief Alternates the datarate of the channel for the join request.
*
* \param [in] alternateDr A pointer to the function parameters.
*
* \retval The datarate to apply.
*/
virtual int8_t get_alternate_DR(AlternateDrParams_t* alternateDr );
/*!
* \brief Calculates the back-off time.
*
* \param [in] calcBackOff A pointer to the function parameters.
*/
virtual void calculate_backoff(CalcBackOffParams_t* calcBackOff );
/*!
* \brief Searches and sets the next random available channel.
*
* \param [in] nextChanParams The parameters for the next channel.
*
* \param [out] channel The next channel to use for TX.
*
* \param [out] time The time to wait for the next transmission according to the duty cycle.
*
* \param [out] aggregatedTimeOff Updates the aggregated time off.
*
* \retval The function status [1: OK, 0: Unable to find a channel on the current datarate].
*/
virtual bool set_next_channel(NextChanParams_t* nextChanParams,
uint8_t* channel, lorawan_time_t* time,
lorawan_time_t* aggregatedTimeOff );
/*!
* \brief Adds a channel.
*
* \param [in] channelAdd A pPointer to the function parameters.
*
* \retval The status of the operation.
*/
virtual lorawan_status_t add_channel(ChannelAddParams_t* channelAdd );
/*!
* \brief Removes a channel.
*
* \param [in] channelRemove A pointer to the function parameters.
*
* \retval True, if the channel was removed successfully.
*/
virtual bool remove_channel(ChannelRemoveParams_t* channelRemove );
/*!
* \brief Sets the radio into continuous wave mode.
*
* \param [in] continuousWave A pointer to the function parameters.
*/
virtual void set_tx_cont_mode(ContinuousWaveParams_t* continuousWave );
/*!
* \brief Computes a new datarate according to the given offset.
*
* \param [in] downlinkDwellTime The downlink dwell time configuration. 0: No limit, 1: 400ms
*
* \param [in] dr The current datarate.
*
* \param [in] drOffset The offset to be applied.
*
* \retval newDr The computed datarate.
*/
virtual uint8_t apply_DR_offset(uint8_t downlinkDwellTime, int8_t dr, int8_t drOffset );
virtual uint8_t apply_DR_offset(int8_t dr, int8_t dr_offset );
private:
uint8_t CountNbOfEnabledChannels( bool joined, uint8_t datarate, uint16_t* channelsMask, channel_params_t* channels, band_t* bands, uint8_t* enabledChannels, uint8_t* delayTx );
// Global attributes
/*!
* LoRaMAC channels
*/
channel_params_t Channels[IN865_MAX_NB_CHANNELS];
channel_params_t channels[IN865_MAX_NB_CHANNELS];
/*!
* LoRaMac bands
*/
band_t Bands[IN865_MAX_NB_BANDS];
band_t bands[IN865_MAX_NB_BANDS];
/*!
* LoRaMac channels mask
*/
uint16_t ChannelsMask[IN865_CHANNELS_MASK_SIZE];
uint16_t channel_masks[IN865_CHANNELS_MASK_SIZE];
/*!
* LoRaMac channels default mask
*/
uint16_t ChannelsDefaultMask[IN865_CHANNELS_MASK_SIZE];
uint16_t default_channel_masks[IN865_CHANNELS_MASK_SIZE];
};
#endif /* MBED_OS_LORAPHY_IN865_H_ */

File diff suppressed because it is too large Load Diff

View File

@ -33,7 +33,6 @@
#define MBED_OS_LORAPHY_KR920_H_
#include "LoRaPHY.h"
#include "netsocket/LoRaRadio.h"
/*!
* LoRaMac maximum number of channels
@ -55,304 +54,42 @@ public:
LoRaPHYKR920(LoRaWANTimeHandler &lora_time);
virtual ~LoRaPHYKR920();
/*!
* \brief The function gets a value of a specific PHY attribute.
*
* \param [in] getPhy A pointer to the function parameters.
*
* \retval The structure containing the PHY parameter.
*/
virtual PhyParam_t get_phy_params(GetPhyParams_t* getPhy );
virtual bool verify_frequency(uint32_t freq);
/*!
* \brief Updates the last TX done parameters of the current channel.
*
* \param [in] txDone A pointer to the function parameters.
*/
virtual void set_band_tx_done(SetBandTxDoneParams_t* txDone );
virtual bool tx_config(tx_config_params_t* config, int8_t* tx_power,
lorawan_time_t* tx_toa);
/*!
* \brief Initializes the channels masks and the channels.
*
* \param [in] type Sets the initialization type.
*/
virtual void load_defaults(InitType_t type );
virtual bool set_next_channel(channel_selection_params_t* params, uint8_t* channel,
lorawan_time_t* time,
lorawan_time_t* aggregate_timeOff);
/*!
* \brief Verifies a parameter.
*
* \param [in] verify A pointer to the function parameters.
*
* \param [in] phyAttribute The attribute to verify.
*
* \retval True, if the parameter is valid.
*/
virtual bool verify(VerifyParams_t* verify, PhyAttribute_t phyAttribute );
virtual void set_tx_cont_mode(cw_mode_params_t* continuousWave,
uint32_t frequency = 0);
/*!
* \brief The function parses the input buffer and sets up the channels of the CF list.
*
* \param [in] applyCFList A pointer to the function parameters.
*/
virtual void apply_cf_list(ApplyCFListParams_t* applyCFList );
/*!
* \brief Sets a channels mask.
*
* \param [in] chanMaskSet A pointer to the function parameters.
*
* \retval True, if the channels mask could be set.
*/
virtual bool set_channel_mask(ChanMaskSetParams_t* chanMaskSet );
private:
/*!
* \brief Calculates the next datarate to set, when ADR is on or off.
*
* \param [in] adrNext A pointer to the function parameters.
*
* \param [out] drOut The calculated datarate for the next TX.
*
* \param [out] txPowOut The TX power for the next TX.
*
* \param [out] adrAckCounter The calculated ADR acknowledgement counter.
*
* \retval True, if an ADR request should be performed.
*/
virtual bool get_next_ADR(AdrNextParams_t* adrNext, int8_t* drOut,
int8_t* txPowOut, uint32_t* adrAckCounter );
int8_t get_max_eirp(uint32_t freq);
/*!
* \brief Configuration of the RX windows.
*
* \param [in] rxConfig A pointer to the function parameters.
*
* \param [out] datarate The datarate index set.
*
* \retval True, if the configuration was applied successfully.
*/
virtual bool rx_config(rx_config_params_t* rxConfig, int8_t* datarate );
/*
* RX window precise timing
*
* For more details, please consult the following document, chapter 3.1.2.
* http://www.semtech.com/images/datasheet/SX1272_settings_for_LoRaWAN_v2.0.pdf
* or
* http://www.semtech.com/images/datasheet/SX1276_settings_for_LoRaWAN_v2.0.pdf
*
* Downlink start: T = Tx + 1s (+/- 20 us)
* |
* TRxEarly | TRxLate
* | | |
* | | +---+---+---+---+---+---+---+---+
* | | | Latest Rx window |
* | | +---+---+---+---+---+---+---+---+
* | | |
* +---+---+---+---+---+---+---+---+
* | Earliest Rx window |
* +---+---+---+---+---+---+---+---+
* |
* +---+---+---+---+---+---+---+---+
*Downlink preamble 8 symbols | | | | | | | | |
* +---+---+---+---+---+---+---+---+
*
* Worst case Rx window timings
*
* TRxLate = DEFAULT_MIN_RX_SYMBOLS * tSymbol - RADIO_WAKEUP_TIME
* TRxEarly = 8 - DEFAULT_MIN_RX_SYMBOLS * tSymbol - RxWindowTimeout - RADIO_WAKEUP_TIME
*
* TRxLate - TRxEarly = 2 * DEFAULT_SYSTEM_MAX_RX_ERROR
*
* RxOffset = ( TRxLate + TRxEarly ) / 2
*
* RxWindowTimeout = ( 2 * DEFAULT_MIN_RX_SYMBOLS - 8 ) * tSymbol + 2 * DEFAULT_SYSTEM_MAX_RX_ERROR
* RxOffset = 4 * tSymbol - RxWindowTimeout / 2 - RADIO_WAKE_UP_TIME
*
* The minimum value of RxWindowTimeout must be 5 symbols which implies that the system always tolerates at least an error of 1.5 * tSymbol
*/
/*!
* Computes the RX window timeout and offset.
*
* \param [in] datarate The RX window datarate index to be used.
*
* \param [in] minRxSymbols The minimum number of symbols required to detect an RX frame.
*
* \param [in] rxError The system maximum timing error of the receiver in milliseconds.
* The receiver will turn on in a [-rxError : +rxError] ms
* interval around RxOffset.
*
* \param [out] rxConfigParams Returns the updated WindowTimeout and WindowOffset fields.
*/
virtual void compute_rx_win_params(int8_t datarate,
uint8_t minRxSymbols,
uint32_t rxError,
rx_config_params_t *rxConfigParams);
/*!
* \brief TX configuration.
*
* \param [in] txConfig A pointer to the function parameters.
*
* \param [out] txPower The TX power index set.
*
* \param [out] txTimeOnAir The time-on-air of the frame.
*
* \retval True, if the configuration was applied successfully.
*/
virtual bool tx_config(TxConfigParams_t* txConfig, int8_t* txPower,
lorawan_time_t* txTimeOnAir );
/*!
* \brief The function processes a Link ADR request.
*
* \param [in] linkAdrReq A pointer to the function parameters.
*
* \param [out] drOut The datarate applied.
*
* \param [out] txPowOut The TX power applied.
*
* \param [out] nbRepOut The number of repetitions to apply.
*
* \param [out] nbBytesParsed The number of bytes parsed.
*
* \retval The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t link_ADR_request(LinkAdrReqParams_t* linkAdrReq,
int8_t* drOut, int8_t* txPowOut,
uint8_t* nbRepOut,
uint8_t* nbBytesParsed );
/*!
* \brief The function processes a RX parameter setup request.
*
* \param [in] rxParamSetupReq A pointer to the function parameters.
*
* \retval The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t setup_rx_params(RxParamSetupReqParams_t* rxParamSetupReq );
/*!
* \brief The function processes a new channel request.
*
* \param [in] newChannelReq A pointer to the function parameters.
*
* \retval The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t request_new_channel(NewChannelReqParams_t* newChannelReq );
/*!
* \brief The function processes a TX ParamSetup request.
*
* \param [in] txParamSetupReq A pointer to the function parameters.
*
* \retval The status of the operation, according to the LoRaMAC specification.
* Returns -1, if the functionality is not implemented. In this case, the end node
* shall ignore the command.
*/
virtual int8_t setup_tx_params(TxParamSetupReqParams_t* txParamSetupReq );
/*!
* \brief The function processes a DlChannel request.
*
* \param [in] dlChannelReq A pointer to the function parameters.
*
* \retval The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t dl_channel_request(DlChannelReqParams_t* dlChannelReq );
/*!
* \brief Alternates the datarate of the channel for the join request.
*
* \param [in] alternateDr A pointer to the function parameters.
*
* \retval The datarate to apply.
*/
virtual int8_t get_alternate_DR(AlternateDrParams_t* alternateDr );
/*!
* \brief Calculates the back-off time.
*
* \param [in] calcBackOff A pointer to the function parameters.
*/
virtual void calculate_backoff(CalcBackOffParams_t* calcBackOff );
/*!
* \brief Searches and sets the next random available channel.
*
* \param [in] nextChanParams The parameters for the next channel.
*
* \param [out] channel The next channel to use for TX.
*
* \param [out] time The time to wait for the next transmission according to the duty cycle.
*
* \param [out] aggregatedTimeOff Updates the aggregated time off.
*
* \retval The function status [1: OK, 0: Unable to find a channel on the current datarate].
*/
virtual bool set_next_channel(NextChanParams_t* nextChanParams,
uint8_t* channel, lorawan_time_t* time,
lorawan_time_t* aggregatedTimeOff );
/*!
* \brief Adds a channel.
*
* \param [in] channelAdd A pointer to the function parameters.
*
* \retval The status of the operation.
*/
virtual lorawan_status_t add_channel(ChannelAddParams_t* channelAdd );
/*!
* \brief Removes a channel.
*
* \param [in] channelRemove A pointer to the function parameters.
*
* \retval True, if the channel was removed successfully.
*/
virtual bool remove_channel(ChannelRemoveParams_t* channelRemove );
/*!
* \brief Sets the radio into continuous wave mode.
*
* \param [in] continuousWave A pointer to the function parameters.
*/
virtual void set_tx_cont_mode(ContinuousWaveParams_t* continuousWave );
/*!
* \brief Computes new datarate according to the given offset.
*
* \param [in] downlinkDwellTime The downlink dwell time configuration. 0: No limit, 1: 400ms
*
* \param [in] dr The current datarate.
*
* \param [in] drOffset The offset to be applied.
*
* \retval newDr The computed datarate.
*/
virtual uint8_t apply_DR_offset(uint8_t downlinkDwellTime, int8_t dr, int8_t drOffset );
uint8_t CountNbOfEnabledChannels( bool joined, uint8_t datarate, uint16_t* channelsMask, channel_params_t* channels, band_t* bands, uint8_t* enabledChannels, uint8_t* delayTx );
// Global attributes
/*!
/**
* LoRaMAC channels
*/
channel_params_t Channels[KR920_MAX_NB_CHANNELS];
channel_params_t channels[KR920_MAX_NB_CHANNELS];
/*!
/**
* LoRaMac bands
*/
band_t Bands[KR920_MAX_NB_BANDS];
band_t bands[KR920_MAX_NB_BANDS];
/*!
/**
* LoRaMac channels mask
*/
uint16_t ChannelsMask[KR920_CHANNELS_MASK_SIZE];
uint16_t channel_masks[KR920_CHANNELS_MASK_SIZE];
/*!
/**
* LoRaMac channels default mask
*/
uint16_t ChannelsDefaultMask[KR920_CHANNELS_MASK_SIZE];
uint16_t default_channel_masks[KR920_CHANNELS_MASK_SIZE];
};
#endif // MBED_OS_LORAPHY_KR920_H_

File diff suppressed because it is too large Load Diff

View File

@ -33,7 +33,6 @@
#define MBED_OS_LORAPHYUS_915_H_
#include "LoRaPHY.h"
#include "netsocket/LoRaRadio.h"
/*!
* LoRaMac maximum number of channels
@ -45,7 +44,7 @@
*/
#define US915_MAX_NB_BANDS 1
#define US915_CHANNELS_MASK_SIZE 6
#define US915_CHANNELS_MASK_SIZE 5
class LoRaPHYUS915 : public LoRaPHY {
@ -55,311 +54,59 @@ public:
LoRaPHYUS915(LoRaWANTimeHandler &lora_time);
virtual ~LoRaPHYUS915();
/*!
* \brief The function gets a value of a specific PHY attribute.
*
* \param [in] getPhy A pointer to the function parameters.
*
* \retval The structure containing the PHY parameter.
*/
virtual PhyParam_t get_phy_params(GetPhyParams_t* getPhy );
virtual void restore_default_channels();
/*!
* \brief Updates the last TX done parameters of the current channel.
*
* \param [in] txDone A pointer to the function parameters.
*/
virtual void set_band_tx_done(SetBandTxDoneParams_t* txDone );
virtual bool rx_config(rx_config_params_t* config, int8_t* datarate);
/*!
* \brief Initializes the channels masks and the channels.
*
* \param [in] type Sets the initialization type.
*/
virtual void load_defaults(InitType_t type );
virtual bool tx_config(tx_config_params_t* config, int8_t* tx_power,
lorawan_time_t* tx_toa);
/*!
* \brief Verifies a parameter.
*
* \param [in] verify A pointer to the function parameters.
*
* \param [in] phyAttribute The attribute to verify.
*
* \retval True, if the parameter is valid.
*/
virtual bool verify(VerifyParams_t* verify, PhyAttribute_t phyAttribute );
virtual uint8_t link_ADR_request(adr_req_params_t* params,
int8_t* dr_out, int8_t* tx_power_out,
uint8_t* nb_rep_out,
uint8_t* nb_bytes_parsed);
/*!
* \brief The function parses the input buffer and sets up the channels of the CF list.
*
* \param [in] applyCFList A pointer to the function parameters.
*/
virtual void apply_cf_list(ApplyCFListParams_t* applyCFList );
virtual uint8_t accept_rx_param_setup_req(rx_param_setup_req_t* params);
/*!
* \brief Sets a channels mask.
*
* \param [in] chanMaskSet A pointer to the function parameters.
*
* \retval True, if the channels mask could be set.
*/
virtual bool set_channel_mask(ChanMaskSetParams_t* chanMaskSet );
virtual int8_t get_alternate_DR(uint8_t nb_trials);
/*!
* \brief Calculates the next datarate to set, when ADR is on or off.
*
* \param [in] adrNext A pointer to the function parameters.
*
* \param [out] drOut The calculated datarate for the next TX.
*
* \param [out] txPowOut The TX power for the next TX.
*
* \param [out] adrAckCounter The calculated ADR acknowledgement counter.
*
* \retval True, if an ADR request should be performed.
*/
virtual bool get_next_ADR(AdrNextParams_t* adrNext, int8_t* drOut,
int8_t* txPowOut, uint32_t* adrAckCounter );
virtual bool set_next_channel(channel_selection_params_t* params, uint8_t* channel,
lorawan_time_t* time, lorawan_time_t* aggregate_timeOff);
/*!
* \brief Configuration of the RX windows.
*
* \param [in] rxConfig A pointer to the function parameters.
*
* \param [out] datarate The datarate index set.
*
* \retval True, if the configuration was applied successfully.
*/
virtual bool rx_config(rx_config_params_t* rxConfig, int8_t* datarate );
virtual void set_tx_cont_mode(cw_mode_params_t* continuousWave,
uint32_t frequency = 0);
/*
* RX window precise timing
*
* For more details, please consult the following document, chapter 3.1.2.
* http://www.semtech.com/images/datasheet/SX1272_settings_for_LoRaWAN_v2.0.pdf
* or
* http://www.semtech.com/images/datasheet/SX1276_settings_for_LoRaWAN_v2.0.pdf
*
* Downlink start: T = Tx + 1s (+/- 20 us)
* |
* TRxEarly | TRxLate
* | | |
* | | +---+---+---+---+---+---+---+---+
* | | | Latest Rx window |
* | | +---+---+---+---+---+---+---+---+
* | | |
* +---+---+---+---+---+---+---+---+
* | Earliest Rx window |
* +---+---+---+---+---+---+---+---+
* |
* +---+---+---+---+---+---+---+---+
*Downlink preamble 8 symbols | | | | | | | | |
* +---+---+---+---+---+---+---+---+
*
* Worst case Rx window timings
*
* TRxLate = DEFAULT_MIN_RX_SYMBOLS * tSymbol - RADIO_WAKEUP_TIME
* TRxEarly = 8 - DEFAULT_MIN_RX_SYMBOLS * tSymbol - RxWindowTimeout - RADIO_WAKEUP_TIME
*
* TRxLate - TRxEarly = 2 * DEFAULT_SYSTEM_MAX_RX_ERROR
*
* RxOffset = ( TRxLate + TRxEarly ) / 2
*
* RxWindowTimeout = ( 2 * DEFAULT_MIN_RX_SYMBOLS - 8 ) * tSymbol + 2 * DEFAULT_SYSTEM_MAX_RX_ERROR
* RxOffset = 4 * tSymbol - RxWindowTimeout / 2 - RADIO_WAKE_UP_TIME
*
* The minimum value of RxWindowTimeout must be 5 symbols which implies that the system always tolerates at least an error of 1.5 * tSymbol
*/
/*!
* Computes the RX window timeout and offset.
*
* \param [in] datarate The RX window datarate index to be used.
*
* \param [in] minRxSymbols The minimum number of symbols required to detect an RX frame.
*
* \param [in] rxError The system maximum timing error of the receiver in milliseconds.
* The receiver will turn on in a [-rxError : +rxError] ms
* interval around RxOffset.
*
* \param [out] rxConfigParams Returns the updated WindowTimeout and WindowOffset fields.
*/
virtual void compute_rx_win_params(int8_t datarate,
uint8_t minRxSymbols,
uint32_t rxError,
rx_config_params_t *rxConfigParams);
/*!
* \brief TX configuration.
*
* \param [in] txConfig A pointer to the function parameters.
*
* \param [out] txPower The TX power index set.
*
* \param [out] txTimeOnAir The time-on-air of the frame.
*
* \retval True, if the configuration was applied successfully.
*/
virtual bool tx_config(TxConfigParams_t* txConfig, int8_t* txPower,
lorawan_time_t* txTimeOnAir );
/*!
* \brief The function processes a Link ADR request.
*
* \param [in] linkAdrReq A pointer to the function parameters.
*
* \param [out] drOut The datarate applied.
*
* \param [out] txPowOut The TX power applied.
*
* \param [out] nbRepOut The number of repetitions to apply.
*
* \param [out] nbBytesParsed The number of bytes parsed.
*
* \retval The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t link_ADR_request(LinkAdrReqParams_t* linkAdrReq,
int8_t* drOut, int8_t* txPowOut,
uint8_t* nbRepOut,
uint8_t* nbBytesParsed );
/*!
* \brief The function processes a RX parameter setup request.
*
* \param [in] rxParamSetupReq A pointer to the function parameters.
*
* \retval The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t setup_rx_params(RxParamSetupReqParams_t* rxParamSetupReq );
/*!
* \brief The function processes a new channel request.
*
* \param [in] newChannelReq A pointer to the function parameters.
*
* \retval The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t request_new_channel(NewChannelReqParams_t* newChannelReq );
/*!
* \brief The function processes a TX ParamSetup request.
*
* \param [in] txParamSetupReq A pointer to the function parameters.
*
* \retval The status of the operation, according to the LoRaMAC specification.
* Returns -1, if the functionality is not implemented. In this case, the end node
* shall ignore the command.
*/
virtual int8_t setup_tx_params(TxParamSetupReqParams_t* txParamSetupReq );
/*!
* \brief The function processes a DlChannel request.
*
* \param [in] dlChannelReq A pointer to the function parameters.
*
* \retval The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t dl_channel_request(DlChannelReqParams_t* dlChannelReq );
/*!
* \brief Alternates the datarate of the channel for the join request.
*
* \param [in] alternateDr A pointer to the function parameters.
*
* \retval The datarate to apply.
*/
virtual int8_t get_alternate_DR(AlternateDrParams_t* alternateDr );
/*!
* \brief Calculates the back-off time.
*
* \param [in] calcBackOff A pointer to the function parameters.
*/
virtual void calculate_backoff(CalcBackOffParams_t* calcBackOff );
/*!
* \brief Searches and sets the next random available channel.
*
* \param [in] nextChanParams The parameters for the next channel.
*
* \param [out] channel The next channel to use for TX.
*
* \param [out] time The time to wait for the next transmission according to the duty cycle.
*
* \param [out] aggregatedTimeOff Updates the aggregated time off.
*
* \retval The function status [1: OK, 0: Unable to find a channel on the current datarate].
*/
virtual bool set_next_channel(NextChanParams_t* nextChanParams,
uint8_t* channel, lorawan_time_t* time,
lorawan_time_t* aggregatedTimeOff );
/*!
* \brief Adds a channel.
*
* \param [in] channelAdd A pointer to the function parameters.
*
* \retval The status of the operation.
*/
virtual lorawan_status_t add_channel(ChannelAddParams_t* channelAdd );
/*!
* \brief Removes a channel.
*
* \param [in] channelRemove A pointer to the function parameters.
*
* \retval True, if the channel was removed successfully.
*/
virtual bool remove_channel(ChannelRemoveParams_t* channelRemove );
/*!
* \brief Sets the radio into continuous wave mode.
*
* \param [in] continuousWave A pointer to the function parameters.
*/
virtual void set_tx_cont_mode(ContinuousWaveParams_t* continuousWave );
/*!
* \brief Computes a new datarate according to the given offset
*
* \param [in] downlinkDwellTime The downlink dwell time configuration. 0: No limit, 1: 400ms
*
* \param [in] dr The current datarate.
*
* \param [in] drOffset The offset to be applied.
*
* \retval newDr The computed datarate.
*/
virtual uint8_t apply_DR_offset(uint8_t downlinkDwellTime, int8_t dr, int8_t drOffset );
virtual uint8_t apply_DR_offset(int8_t dr, int8_t dr_offset);
private:
int8_t LimitTxPower( int8_t txPower, int8_t maxBandTxPower, int8_t datarate, uint16_t* channelsMask );
uint8_t CountNbOfEnabledChannels( uint8_t datarate, uint16_t* channelsMask, channel_params_t* channels, band_t* bands, uint8_t* enabledChannels, uint8_t* delayTx );
// Global attributes
int8_t limit_tx_power(int8_t tx_power, int8_t max_band_tx_power,
int8_t datarate);
/*!
* LoRaMAC channels
*/
channel_params_t Channels[US915_MAX_NB_CHANNELS];
channel_params_t channels[US915_MAX_NB_CHANNELS];
/*!
* LoRaMac bands
*/
band_t Bands[US915_MAX_NB_BANDS];
band_t bands[US915_MAX_NB_BANDS];
/*!
* LoRaMac channels mask
*/
uint16_t ChannelsMask[US915_CHANNELS_MASK_SIZE];
uint16_t channel_masks[US915_CHANNELS_MASK_SIZE];
/*!
* LoRaMac channels remaining
*/
uint16_t ChannelsMaskRemaining[US915_CHANNELS_MASK_SIZE];
uint16_t current_channel_masks[US915_CHANNELS_MASK_SIZE];
/*!
* LoRaMac channels default mask
*/
uint16_t ChannelsDefaultMask[US915_CHANNELS_MASK_SIZE];
uint16_t default_channel_masks[US915_CHANNELS_MASK_SIZE];
};
#endif /* MBED_OS_LORAPHY_US915_H_ */

File diff suppressed because it is too large Load Diff

View File

@ -29,11 +29,10 @@
*
*/
#ifndef MBED_OS_LORAPHY_US915HYBRID_H_
#ifndef MBED_OS_LORAPHY_US915_HYBRID_H_
#define MBED_OS_LORAPHY_US915_HYBRID_H_
#include "LoRaPHY.h"
#include "netsocket/LoRaRadio.h"
/*!
@ -46,7 +45,7 @@
*/
#define US915_HYBRID_MAX_NB_BANDS 1
#define US915_HYBRID_CHANNELS_MASK_SIZE 6
#define US915_HYBRID_CHANNELS_MASK_SIZE 5
class LoRaPHYUS915Hybrid : public LoRaPHY {
@ -56,311 +55,63 @@ public:
LoRaPHYUS915Hybrid(LoRaWANTimeHandler &lora_time);
virtual ~LoRaPHYUS915Hybrid();
/*!
* \brief The function gets a value of a specific PHY attribute.
*
* \param [in] getPhy A pointer to the function parameters.
*
* \retval The structure containing the PHY parameter.
*/
virtual PhyParam_t get_phy_params(GetPhyParams_t* getPhy );
virtual void restore_default_channels();
/*!
* \brief Updates the last TX done parameters of the current channel.
*
* \param [in] txDone A pointer to the function parameters.
*/
virtual void set_band_tx_done(SetBandTxDoneParams_t* txDone );
virtual bool get_next_ADR(bool restore_channel_mask, int8_t& dr_out,
int8_t& tx_power_out, uint32_t& adr_ack_cnt);
/*!
* \brief Initializes the channels masks and the channels.
*
* \param [in] type Sets the initialization type.
*/
virtual void load_defaults(InitType_t type );
virtual bool rx_config(rx_config_params_t* rxConfig, int8_t* datarate);
/*!
* \brief Verifies a parameter.
*
* \param [in] verify A pointer to the function parameters.
*
* \param [in] phyAttribute The attribute to verify.
*
* \retval True, if the parameter is valid.
*/
virtual bool verify(VerifyParams_t* verify, PhyAttribute_t phyAttribute );
virtual bool tx_config(tx_config_params_t* tx_config, int8_t* tx_power,
lorawan_time_t* tx_toa);
/*!
* \brief The function parses the input buffer and sets up the channels of the CF list.
*
* \param [in] applyCFList A pointer to the function parameters.
*/
virtual void apply_cf_list(ApplyCFListParams_t* applyCFList );
virtual uint8_t link_ADR_request(adr_req_params_t* params,
int8_t* dr_out, int8_t* tx_power_out,
uint8_t* nb_rep_out,
uint8_t* nb_bytes_parsed);
/*!
* \brief Sets a channels mask.
*
* \param [in] chanMaskSet A pointer to the function parameters.
*
* \retval True, if the channels mask could be set.
*/
virtual bool set_channel_mask(ChanMaskSetParams_t* chanMaskSet );
virtual uint8_t accept_rx_param_setup_req(rx_param_setup_req_t* params);
/*!
* \brief Calculates the next datarate to set, when ADR is on or off.
*
* \param [in] adrNext A pointer to the function parameters.
*
* \param [out] drOut The calculated datarate for the next TX.
*
* \param [out] txPowOut The TX power for the next TX.
*
* \param [out] adrAckCounter The calculated ADR acknowledgement counter.
*
* \retval True, if an ADR request should be performed.
*/
virtual bool get_next_ADR(AdrNextParams_t* adrNext, int8_t* drOut,
int8_t* txPowOut, uint32_t* adrAckCounter );
virtual int8_t get_alternate_DR(uint8_t nb_trials);
/*!
* \brief Configuration of the RX windows.
*
* \param [in] rxConfig A pointer to the function parameters.
*
* \param [out] datarate The datarate index set.
*
* \retval True, if the configuration was applied successfully.
*/
virtual bool rx_config(rx_config_params_t* rxConfig, int8_t* datarate );
/*
* RX window precise timing
*
* For more details, please consult the following document, chapter 3.1.2.
* http://www.semtech.com/images/datasheet/SX1272_settings_for_LoRaWAN_v2.0.pdf
* or
* http://www.semtech.com/images/datasheet/SX1276_settings_for_LoRaWAN_v2.0.pdf
*
* Downlink start: T = Tx + 1s (+/- 20 us)
* |
* TRxEarly | TRxLate
* | | |
* | | +---+---+---+---+---+---+---+---+
* | | | Latest Rx window |
* | | +---+---+---+---+---+---+---+---+
* | | |
* +---+---+---+---+---+---+---+---+
* | Earliest Rx window |
* +---+---+---+---+---+---+---+---+
* |
* +---+---+---+---+---+---+---+---+
*Downlink preamble 8 symbols | | | | | | | | |
* +---+---+---+---+---+---+---+---+
*
* Worst case Rx window timings
*
* TRxLate = DEFAULT_MIN_RX_SYMBOLS * tSymbol - RADIO_WAKEUP_TIME
* TRxEarly = 8 - DEFAULT_MIN_RX_SYMBOLS * tSymbol - RxWindowTimeout - RADIO_WAKEUP_TIME
*
* TRxLate - TRxEarly = 2 * DEFAULT_SYSTEM_MAX_RX_ERROR
*
* RxOffset = ( TRxLate + TRxEarly ) / 2
*
* RxWindowTimeout = ( 2 * DEFAULT_MIN_RX_SYMBOLS - 8 ) * tSymbol + 2 * DEFAULT_SYSTEM_MAX_RX_ERROR
* RxOffset = 4 * tSymbol - RxWindowTimeout / 2 - RADIO_WAKE_UP_TIME
*
* The minimum value of RxWindowTimeout must be 5 symbols which implies that the system always tolerates at least an error of 1.5 * tSymbol
*/
/*!
* Computes the RX window timeout and offset.
*
* \param [in] datarate The RX window datarate index to be used.
*
* \param [in] minRxSymbols The minimum number of symbols required to detect an RX frame.
*
* \param [in] rxError The system maximum timing error of the receiver in milliseconds.
* The receiver will turn on in a [-rxError : +rxError] ms
* interval around RxOffset.
*
* \param [out] rxConfigParams Returns the updated WindowTimeout and WindowOffset fields.
*/
virtual void compute_rx_win_params(int8_t datarate,
uint8_t minRxSymbols,
uint32_t rxError,
rx_config_params_t *rxConfigParams);
/*!
* \brief TX configuration.
*
* \param [in] txConfig A pointer to the function parameters.
*
* \param [out] txPower The TX power index set.
*
* \param [out] txTimeOnAir The time-on-air of the frame.
*
* \retval True, if the configuration was applied successfully.
*/
virtual bool tx_config(TxConfigParams_t* txConfig, int8_t* txPower,
lorawan_time_t* txTimeOnAir );
/*!
* \brief The function processes a Link ADR request.
*
* \param [in] linkAdrReq A pointer to the function parameters.
*
* \param [out] drOut The datarate applied.
*
* \param [out] txPowOut The TX power applied.
*
* \param [out] nbRepOut The number of repetitions to apply.
*
* \param [out] nbBytesParsed The number of bytes parsed.
*
* \retval The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t link_ADR_request(LinkAdrReqParams_t* linkAdrReq,
int8_t* drOut, int8_t* txPowOut,
uint8_t* nbRepOut,
uint8_t* nbBytesParsed );
/*!
* \brief The function processes a RX parameter setup request.
*
* \param [in] rxParamSetupReq A pointer to the function parameters.
*
* \retval The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t setup_rx_params(RxParamSetupReqParams_t* rxParamSetupReq );
/*!
* \brief The function processes a new channel request.
*
* \param [in] newChannelReq A pointer to the function parameters.
*
* \retval The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t request_new_channel(NewChannelReqParams_t* newChannelReq );
/*!
* \brief The function processes a TX ParamSetup request.
*
* \param [in] txParamSetupReq A pointer to the function parameters.
*
* \retval The status of the operation, according to the LoRaMAC specification.
* Returns -1, if the functionality is not implemented. In this case, the end node
* shall ignore the command.
*/
virtual int8_t setup_tx_params(TxParamSetupReqParams_t* txParamSetupReq );
/*!
* \brief The function processes a DlChannel request.
*
* \param [in] dlChannelReq A pointer to the function parameters.
*
* \retval The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t dl_channel_request(DlChannelReqParams_t* dlChannelReq );
/*!
* \brief Alternates the datarate of the channel for the join request.
*
* \param [in] alternateDr A pointer to the function parameters.
*
* \retval The datarate to apply.
*/
virtual int8_t get_alternate_DR(AlternateDrParams_t* alternateDr );
/*!
* \brief Calculates the back-off time.
*
* \param [in] calcBackOff A pointer to the function parameters.
*/
virtual void calculate_backoff(CalcBackOffParams_t* calcBackOff );
/*!
* \brief Searches and sets the next random available channel.
*
* \param [in] nextChanParams The parameters for the next channel.
*
* \param [out] channel The next channel to use for TX.
*
* \param [out] time The time to wait for the next transmission according to the duty cycle.
*
* \param [out] aggregatedTimeOff Updates the aggregated time off.
*
* \retval The function status [1: OK, 0: Unable to find a channel on the current datarate].
*/
virtual bool set_next_channel(NextChanParams_t* nextChanParams,
virtual bool set_next_channel(channel_selection_params_t* params,
uint8_t* channel, lorawan_time_t* time,
lorawan_time_t* aggregatedTimeOff );
lorawan_time_t* aggregate_timeoff);
/*!
* \brief Adds a channel.
*
* \param [in] channelAdd A pointer to the function parameters.
*
* \retval The status of the operation.
*/
virtual lorawan_status_t add_channel(ChannelAddParams_t* channelAdd );
virtual void set_tx_cont_mode(cw_mode_params_t* continuousWave,
uint32_t frequency = 0);
/*!
* \brief Removes a channel.
*
* \param [in] channelRemove A pointer to the function parameters.
*
* \retval True, if the channel was removed successfully.
*/
virtual bool remove_channel(ChannelRemoveParams_t* channelRemove );
/*!
* \brief Sets the radio into continuous wave mode.
*
* \param [in] continuousWave A pointer to the function parameters.
*/
virtual void set_tx_cont_mode(ContinuousWaveParams_t* continuousWave );
/*!
* \brief Computes a new datarate according to the given offset.
*
* \param [in] downlinkDwellTime The downlink dwell time configuration. 0: No limit, 1: 400ms
*
* \param [in] dr The current datarate.
*
* \param [in] drOffset The offset to be applied.
*
* \retval newDr The computed datarate.
*/
virtual uint8_t apply_DR_offset(uint8_t downlinkDwellTime, int8_t dr, int8_t drOffset );
virtual uint8_t apply_DR_offset(int8_t dr, int8_t dr_offset);
private:
int8_t LimitTxPower( int8_t txPower, int8_t maxBandTxPower, int8_t datarate, uint16_t* channelsMask );
uint8_t CountNbOfEnabledChannels( uint8_t datarate, uint16_t* channelsMask, channel_params_t* channels, band_t* bands, uint8_t* enabledChannels, uint8_t* delayTx );
int8_t limit_tx_power(int8_t tx_power, int8_t max_band_tx_power, int8_t datarate);
bool validate_channel_mask(uint16_t* channel_mask);
void reenable_500khz_channels(uint16_t mask, uint16_t* channel_mask);
// Global attributes
/*!
* LoRaMAC channels
*/
channel_params_t Channels[US915_HYBRID_MAX_NB_CHANNELS];
channel_params_t channels[US915_HYBRID_MAX_NB_CHANNELS];
/*!
* LoRaMac bands
*/
band_t Bands[US915_HYBRID_MAX_NB_BANDS];
band_t bands[US915_HYBRID_MAX_NB_BANDS];
/*!
* LoRaMac channels mask
*/
uint16_t ChannelsMask[US915_HYBRID_CHANNELS_MASK_SIZE];
uint16_t channel_masks[US915_HYBRID_CHANNELS_MASK_SIZE];
/*!
* LoRaMac channels remaining
*/
uint16_t ChannelsMaskRemaining[US915_HYBRID_CHANNELS_MASK_SIZE];
uint16_t current_channel_masks[US915_HYBRID_CHANNELS_MASK_SIZE];
/*!
* LoRaMac channels default mask
*/
uint16_t ChannelsDefaultMask[US915_HYBRID_CHANNELS_MASK_SIZE];
uint16_t default_channel_masks[US915_HYBRID_CHANNELS_MASK_SIZE];
};
#endif /* MBED_OS_LORAPHY_US915HYBRID_H_ */

View File

@ -527,7 +527,7 @@
/*!
* Enumeration of PHY attributes.
*/
typedef enum ePhyAttribute
typedef enum phy_attributes__e
{
/*!
* The minimum RX datarate.
@ -661,466 +661,481 @@ typedef enum ePhyAttribute
* The next lower datarate.
*/
PHY_NEXT_LOWER_TX_DR
}PhyAttribute_t;
} phy_attributes_t;
/*!
* Enumeration of initialization types.
* Keeps value in response to a call to
* get_phy_params() API.
*/
typedef enum eInitType
{
/*!
* Performs an initialization and overwrites all existing data.
*/
INIT_TYPE_INIT,
/*!
* Restores default channels only.
*/
INIT_TYPE_RESTORE
}InitType_t;
/*!
* Selects a given or a default channel mask.
*/
typedef enum eChannelsMask
{
/*!
* The channels mask.
*/
CHANNELS_MASK,
/*!
* The channels default mask.
*/
CHANNELS_DEFAULT_MASK
}ChannelsMask_t;
/*!
* The union for the structure uGetPhyParams.
*/
typedef union uPhyParam
typedef union phy_param_u
{
/*!
* A parameter value.
*/
uint32_t Value;
uint32_t value;
/*!
* A floating point value.
*/
float fValue;
float f_value;
/*!
* A pointer to the channels mask.
*/
uint16_t* ChannelsMask;
uint16_t* channel_mask;
/*!
* A pointer to the channels.
*/
channel_params_t* Channels;
}PhyParam_t;
channel_params_t* channel_params;
} phy_param_t;
/*!
/**
* The parameter structure for the function RegionGetPhyParam.
*/
typedef struct sGetPhyParams
typedef struct
{
/*!
/**
* Set up the parameter to get.
*/
PhyAttribute_t Attribute;
/*!
* Datarate.
phy_attributes_t attribute;
/**
* The parameter is needed for the following queries:
* PHY_MAX_PAYLOAD, PHY_MAX_PAYLOAD_REPEATER, PHY_NEXT_LOWER_TX_DR.
*/
int8_t Datarate;
/*!
* Uplink dwell time.
* The parameter is needed for the following queries:
* PHY_MIN_TX_DR, PHY_MAX_PAYLOAD, PHY_MAX_PAYLOAD_REPEATER, PHY_NEXT_LOWER_TX_DR.
*/
uint8_t UplinkDwellTime;
/*!
* Downlink dwell time.
* The parameter is needed for the following queries:
* PHY_MIN_RX_DR, PHY_MAX_PAYLOAD, PHY_MAX_PAYLOAD_REPEATER.
*/
uint8_t DownlinkDwellTime;
}GetPhyParams_t;
int8_t datarate;
/*!
} get_phy_params_t;
/**
* The parameter structure for the function RegionSetBandTxDone.
*/
typedef struct sSetBandTxDoneParams
typedef struct
{
/*!
/**
* The channel to update.
*/
uint8_t Channel;
/*!
uint8_t channel;
/**
* Joined set to true, if the node has joined the network.
*/
bool Joined;
/*!
bool joined;
/**
* The last TX done time.
*/
lorawan_time_t LastTxDoneTime;
}SetBandTxDoneParams_t;
lorawan_time_t last_tx_done_time;
} set_band_txdone_params_t;
/*!
* The parameter structure for the function RegionVerify.
/**
* The parameter verification structure.
*/
typedef union uVerifyParams
typedef union
{
/*!
/**
* The TX power to verify.
*/
int8_t TxPower;
/*!
int8_t tx_power;
/**
* Set to true, if the duty cycle is enabled, otherwise false.
*/
bool DutyCycle;
/*!
bool duty_cycle;
/**
* The number of join trials.
*/
uint8_t NbJoinTrials;
/*!
uint8_t nb_join_trials;
/**
* The datarate to verify.
*/
struct sDatarateParams
{
/*!
* The datarate to verify.
*/
int8_t Datarate;
/*!
* The downlink dwell time.
*/
uint8_t DownlinkDwellTime;
/*!
* The uplink dwell time.
*/
uint8_t UplinkDwellTime;
}DatarateParams;
}VerifyParams_t;
int8_t datarate;
/*!
} verification_params_t;
/**
* The parameter structure for the function RegionApplyCFList.
*/
typedef struct sApplyCFListParams
typedef struct
{
/*!
/**
* The payload containing the CF list.
*/
uint8_t* Payload;
/*!
uint8_t* payload;
/**
* The size of the payload.
*/
uint8_t Size;
}ApplyCFListParams_t;
uint8_t size;
} cflist_params_t;
/*!
* The parameter structure for the function RegionChanMaskSet.
/**
* TX configuration parameters.
*/
typedef struct sChanMaskSetParams
typedef struct
{
/*!
* A pointer to the channels mask which should be set.
*/
uint16_t* ChannelsMaskIn;
/*!
* A pointer to the channels mask which should be set.
*/
ChannelsMask_t ChannelsMaskType;
}ChanMaskSetParams_t;
/*!
* The parameter structure for the function RegionAdrNext.
*/
typedef struct sAdrNextParams
{
/*!
* Set to true, if the function should update the channels mask.
*/
bool UpdateChanMask;
/*!
* Set to true, if ADR is enabled.
*/
bool AdrEnabled;
/*!
* The ADR ack counter.
*/
uint32_t AdrAckCounter;
/*!
* The datarate used currently.
*/
int8_t Datarate;
/*!
* The TX power used currently.
*/
int8_t TxPower;
/*!
* UplinkDwellTime
*/
uint8_t UplinkDwellTime;
}AdrNextParams_t;
/*!
* The parameter structure for the function RegionTxConfig.
*/
typedef struct sTxConfigParams
{
/*!
/**
* The TX channel.
*/
uint8_t Channel;
/*!
uint8_t channel;
/**
* The TX datarate.
*/
int8_t Datarate;
/*!
int8_t datarate;
/**
* The TX power.
*/
int8_t TxPower;
/*!
int8_t tx_power;
/**
* The Max EIRP, if applicable.
*/
float MaxEirp;
/*!
float max_eirp;
/**
* The antenna gain, if applicable.
*/
float AntennaGain;
/*!
float antenna_gain;
/**
* The frame length to set up.
*/
uint16_t PktLen;
}TxConfigParams_t;
uint16_t pkt_len;
} tx_config_params_t;
/*!
* The parameter structure for the function RegionLinkAdrReq.
/**
* This structure contains parameters for ADR request coming from
* network server.
*/
typedef struct sLinkAdrReqParams
typedef struct
{
/*!
* A pointer to the payload containing the MAC commands.
*/
uint8_t* Payload;
uint8_t* payload;
/*!
* The size of the payload.
*/
uint8_t PayloadSize;
uint8_t payload_size;
/*!
* The uplink dwell time.
*/
uint8_t UplinkDwellTime;
uint8_t ul_dwell_time;
/*!
* Set to true, if ADR is enabled.
*/
bool AdrEnabled;
bool adr_enabled;
/*!
* The current datarate.
*/
int8_t CurrentDatarate;
int8_t current_datarate;
/*!
* The current TX power.
*/
int8_t CurrentTxPower;
int8_t current_tx_power;
/*!
* The current number of repetitions.
*/
uint8_t CurrentNbRep;
}LinkAdrReqParams_t;
uint8_t current_nb_rep;
} adr_req_params_t;
/*!
* The parameter structure for the function RegionRxParamSetupReq.
/**
* Structure containing data for local ADR settings
*/
typedef struct sRxParamSetupReqParams
typedef struct link_adr_params_s
{
/**
* The number of repetitions.
*/
uint8_t nb_rep;
/**
* Datarate.
*/
int8_t datarate;
/**
* TX power.
*/
int8_t tx_power;
/**
* Channels mask control field.
*/
uint8_t ch_mask_ctrl;
/**
* Channels mask field.
*/
uint16_t channel_mask;
} link_adr_params_t;
/**
* Structure used to store ADR values received from network
* for verification (legality) purposes.
*/
typedef struct verify_adr_params_s
{
/*!
* The current status of the AdrLinkRequest.
*/
uint8_t status;
/*!
* Set to true, if ADR is enabled.
*/
bool adr_enabled;
/*!
* The datarate the AdrLinkRequest wants to set.
*/
int8_t datarate;
/*!
* The TX power the AdrLinkRequest wants to set.
*/
int8_t tx_power;
/*!
* The number of repetitions the AdrLinkRequest wants to set.
*/
uint8_t nb_rep;
/*!
* The current datarate the node is using.
*/
int8_t current_datarate;
/*!
* The current TX power the node is using.
*/
int8_t current_tx_power;
/*!
* The current number of repetitions the node is using.
*/
int8_t current_nb_rep;
/*!
* A pointer to the first element of the channels mask.
*/
uint16_t* channel_mask;
} verify_adr_params_t;
/**
* Contains rx parameter setup request coming from
* network server.
*/
typedef struct rx_param_setup_req_s
{
/**
* The datarate to set up.
*/
int8_t Datarate;
/*!
int8_t datarate;
/**
* The datarate offset.
*/
int8_t DrOffset;
/*!
int8_t dr_offset;
/**
* The frequency to set up.
*/
uint32_t Frequency;
}RxParamSetupReqParams_t;
uint32_t frequency;
} rx_param_setup_req_t;
/*!
* The parameter structure for the function RegionNewChannelReq.
/**
* Contains tx parameter setup request coming from
* network server.
*/
typedef struct sNewChannelReqParams
typedef struct tx_param_setup_req_s
{
/*!
* A pointer to the new channels.
*/
channel_params_t* NewChannel;
/*!
* The channel ID.
*/
int8_t ChannelId;
}NewChannelReqParams_t;
/*!
* The parameter structure for the function RegionTxParamSetupReq.
*/
typedef struct sTxParamSetupReqParams
{
/*!
/**
* The uplink dwell time.
*/
uint8_t UplinkDwellTime;
/*!
uint8_t ul_dwell_time;
/**
* The downlink dwell time.
*/
uint8_t DownlinkDwellTime;
/*!
uint8_t dl_dwell_time;
/**
* The max EIRP.
*/
uint8_t MaxEirp;
}TxParamSetupReqParams_t;
uint8_t max_eirp;
} tx_param_setup_req_t;
/*!
/**
* A structure that holds new channel parameters coming
* from the network server.
*/
typedef struct new_channel_req_params_s
{
/**
* A pointer to the new channel's parameters.
*/
channel_params_t* new_channel;
/**
* The channel ID.
*/
int8_t channel_id;
} new_channel_req_params_t;
/**
* The parameter structure for the function RegionDlChannelReq.
*/
typedef struct sDlChannelReqParams
typedef struct dl_channel_req_params_s
{
/*!
/**
* The channel ID to add the frequency.
*/
uint8_t ChannelId;
/*!
uint8_t channel_id;
/**
* The alternative frequency for the Rx1 window.
*/
uint32_t Rx1Frequency;
}DlChannelReqParams_t;
/*!
* The parameter structure for the function RegionAlternateDr.
*/
typedef struct sAlternateDrParams
{
/*!
* The number of trials.
*/
uint16_t NbTrials;
}AlternateDrParams_t;
uint32_t rx1_frequency;
} dl_channel_req_params_t;
/*!
* The parameter structure for the function RegionCalcBackOff.
*/
typedef struct sCalcBackOffParams
typedef struct backoff_params_s
{
/*!
/**
* Set to true, if the node has already joined a network, otherwise false.
*/
bool Joined;
/*!
* Joined set to true, if the last uplink was a join request.
bool joined;
/**
* set to true, if the last uplink was a join request.
*/
bool LastTxIsJoinRequest;
/*!
bool last_tx_was_join_req;
/**
* Set to true, if the duty cycle is enabled, otherwise false.
*/
bool DutyCycleEnabled;
/*!
bool dc_enabled;
/**
* The current channel index.
*/
uint8_t Channel;
/*!
uint8_t channel;
/**
* Elapsed time since the start of the node.
*/
lorawan_time_t ElapsedTime;
/*!
lorawan_time_t elapsed_time;
/**
* Time-on-air of the last transmission.
*/
lorawan_time_t TxTimeOnAir;
}CalcBackOffParams_t;
lorawan_time_t tx_toa;
/*!
} backoff_params_t;
/**
* The parameter structure for the function RegionNextChannel.
*/
typedef struct sNextChanParams
typedef struct channel_selection_params_s
{
/*!
/**
* The aggregated time-off time.
*/
lorawan_time_t AggrTimeOff;
/*!
lorawan_time_t aggregate_timeoff;
/**
* The time of the last aggregated TX.
*/
lorawan_time_t LastAggrTx;
/*!
lorawan_time_t last_aggregate_tx_time;
/**
* The current datarate.
*/
int8_t Datarate;
/*!
int8_t current_datarate;
/**
* Set to true, if the node has already joined a network, otherwise false.
*/
bool Joined;
/*!
bool joined;
/**
* Set to true, if the duty cycle is enabled, otherwise false.
*/
bool DutyCycleEnabled;
}NextChanParams_t;
/*!
* The parameter structure for the function RegionChannelsAdd.
*/
typedef struct sChannelAddParams
{
/*!
* A pointer to the new channel to add.
*/
channel_params_t* NewChannel;
/*!
* The channel ID to add.
*/
uint8_t ChannelId;
}ChannelAddParams_t;
/*!
* The parameter structure for the function RegionChannelsRemove.
*/
typedef struct sChannelRemoveParams
{
/*!
* The channel ID to remove.
*/
uint8_t ChannelId;
}ChannelRemoveParams_t;
bool dc_enabled;
} channel_selection_params_t;
/*!
* The parameter structure for the function RegionContinuousWave.
*/
typedef struct sContinuousWaveParams
typedef struct continuous_wave_mode_params_s
{
/*!
* The current channel index.
*/
uint8_t Channel;
uint8_t channel;
/*!
* The datarate. Used to limit the TX power.
*/
int8_t Datarate;
int8_t datarate;
/*!
* The TX power to set up.
*/
int8_t TxPower;
int8_t tx_power;
/*!
* The max EIRP, if applicable.
*/
float MaxEirp;
float max_eirp;
/*!
* The antenna gain, if applicable.
*/
float AntennaGain;
float antenna_gain;
/*!
* Specifies the time the radio will stay in CW mode.
*/
uint16_t Timeout;
}ContinuousWaveParams_t;
uint16_t timeout;
} cw_mode_params_t;
typedef struct {
void *table;
uint8_t size;
} loraphy_table_t;
typedef struct {
channel_params_t *channel_list;
uint8_t channel_list_size;
uint16_t *mask_list;
uint16_t *default_mask_list;
uint8_t mask_list_size;
} loraphy_channels_t;
typedef struct {
bool duty_cycle_enabled;
bool accept_tx_param_setup_req;
bool fsk_supported;
bool cflist_supported;
bool custom_channelplans_supported;
bool dl_channel_req_supported;
uint8_t default_channel_cnt;
uint8_t cflist_channel_cnt;
uint8_t max_channel_cnt;
uint8_t min_tx_power;
uint8_t max_tx_power;
uint8_t default_tx_power;
uint8_t adr_ack_limit;
uint8_t adr_ack_delay;
uint8_t min_tx_datarate;
uint8_t max_tx_datarate;
uint8_t min_rx_datarate;
uint8_t max_rx_datarate;
uint8_t default_datarate;
uint8_t default_max_datarate;
uint8_t min_rx1_dr_offset;
uint8_t max_rx1_dr_offset;
uint8_t default_rx1_dr_offset;
uint8_t dwell_limit_datarate;
uint16_t max_rx_window;
uint16_t recv_delay1;
uint16_t recv_delay2;
uint16_t join_accept_delay1;
uint16_t join_accept_delay2;
uint16_t join_channel_mask;
uint16_t max_fcnt_gap;
uint16_t ack_timeout;
uint16_t ack_timeout_rnd;
float default_max_eirp;
float default_antenna_gain;
uint8_t rx_window2_datarate;
uint32_t rx_window2_frequency;
loraphy_table_t bands;
loraphy_table_t bandwidths;
loraphy_table_t datarates;
loraphy_table_t payloads;
loraphy_table_t payloads_with_repeater;
loraphy_channels_t channels;
unsigned ul_dwell_time_setting : 1;
unsigned dl_dwell_time_setting : 1;
} loraphy_params_t;
#endif /* MBED_OS_LORA_PHY_DATASTRUCTURES_ */

View File

@ -10,8 +10,8 @@
"value": true
},
"nb-trials": {
"help": "Indicates how many times join can be tried, default: 8",
"value": 8
"help": "Indicates how many times join can be tried, default: 12",
"value": 12
},
"device-eui": {
"help": "Mote device IEEE EUI",

View File

@ -207,6 +207,14 @@ typedef struct {
* The device off time.
*/
lorawan_time_t off_time;
/*!
* Lower band boundry
*/
uint32_t lower_band_freq;
/*!
* Higher band boundry
*/
uint32_t higher_band_freq;
} band_t;
/*!
@ -2007,7 +2015,7 @@ typedef struct {
/*!
* The RX datarate.
*/
int8_t datarate;
uint8_t datarate;
/*!
* The RX bandwidth.
*/