Merge pull request #6938 from hasnainvirk/style_and_bug_fixes

LoRaWAN: Style and bug fixes
pull/7151/head
Cruz Monrreal 2018-06-11 08:46:52 -05:00 committed by GitHub
commit b00a91d15b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 641 additions and 608 deletions

View File

@ -217,7 +217,7 @@ public:
* LORAWAN_STATUS_WOULD_BLOCK if another TX is
* ongoing, or a negative error code on failure.
*/
virtual int16_t send(uint8_t port, const uint8_t* data,
virtual int16_t send(uint8_t port, const uint8_t *data,
uint16_t length, int flags) = 0;
/** Receives a message from the Network Server on a specific port.
@ -259,7 +259,7 @@ public:
* nothing available to read at the moment.
* iv) A negative error code on failure.
*/
virtual int16_t receive(uint8_t port, uint8_t* data, uint16_t length, int flags) = 0;
virtual int16_t receive(uint8_t port, uint8_t *data, uint16_t length, int flags) = 0;
/** Receives a message from the Network Server from any port.
*
@ -283,7 +283,7 @@ public:
* nothing available to read at the moment.
* iv) A negative error code on failure.
*/
virtual int16_t receive(uint8_t* data, uint16_t length, uint8_t& port, int& flags) = 0;
virtual int16_t receive(uint8_t *data, uint16_t length, uint8_t &port, int &flags) = 0;
/** Add application callbacks to the stack.
*

View File

@ -23,7 +23,7 @@
using namespace events;
LoRaWANInterface::LoRaWANInterface(LoRaRadio& radio)
LoRaWANInterface::LoRaWANInterface(LoRaRadio &radio)
{
_lw_stack.bind_radio_driver(radio);
}
@ -116,7 +116,7 @@ lorawan_status_t LoRaWANInterface::remove_channel_plan()
return _lw_stack.drop_channel_list();
}
int16_t LoRaWANInterface::send(uint8_t port, const uint8_t* data, uint16_t length, int flags)
int16_t LoRaWANInterface::send(uint8_t port, const uint8_t *data, uint16_t length, int flags)
{
Lock lock(*this);
return _lw_stack.handle_tx(port, data, length, flags);
@ -146,13 +146,13 @@ lorawan_status_t LoRaWANInterface::get_backoff_metadata(int &backoff)
return _lw_stack.acquire_backoff_metadata(backoff);
}
int16_t LoRaWANInterface::receive(uint8_t port, uint8_t* data, uint16_t length, int flags)
int16_t LoRaWANInterface::receive(uint8_t port, uint8_t *data, uint16_t length, int flags)
{
Lock lock(*this);
return _lw_stack.handle_rx(data, length, port, flags, true);
}
int16_t LoRaWANInterface::receive(uint8_t* data, uint16_t length, uint8_t& port, int& flags)
int16_t LoRaWANInterface::receive(uint8_t *data, uint16_t length, uint8_t &port, int &flags)
{
Lock lock(*this);
return _lw_stack.handle_rx(data, length, port, flags, false);

View File

@ -34,7 +34,7 @@ public:
* construct a single instance of LoRaWANInterface.
*
*/
LoRaWANInterface(LoRaRadio& radio);
LoRaWANInterface(LoRaRadio &radio);
virtual ~LoRaWANInterface();
@ -315,7 +315,7 @@ public:
* LORAWAN_STATUS_WOULD_BLOCK if another TX is
* ongoing, or a negative error code on failure.
*/
virtual int16_t send(uint8_t port, const uint8_t* data, uint16_t length,
virtual int16_t send(uint8_t port, const uint8_t *data, uint16_t length,
int flags);
/** Receives a message from the Network Server on a specific port.
@ -357,7 +357,7 @@ public:
* nothing available to read at the moment.
* iv) A negative error code on failure.
*/
virtual int16_t receive(uint8_t port, uint8_t* data, uint16_t length, int flags);
virtual int16_t receive(uint8_t port, uint8_t *data, uint16_t length, int flags);
/** Receives a message from the Network Server on any port.
*
@ -381,7 +381,7 @@ public:
* nothing available to read at the moment.
* iv) A negative error code on failure.
*/
virtual int16_t receive(uint8_t* data, uint16_t length, uint8_t& port, int& flags);
virtual int16_t receive(uint8_t *data, uint16_t length, uint8_t &port, int &flags);
/** Add application callbacks to the stack.
*
@ -502,8 +502,14 @@ public:
*/
virtual lorawan_status_t cancel_sending(void);
void lock(void) { _lw_stack.lock(); }
void unlock(void) { _lw_stack.unlock(); }
void lock(void)
{
_lw_stack.lock();
}
void unlock(void)
{
_lw_stack.unlock();
}
private:

View File

@ -49,14 +49,14 @@ using namespace mbed;
using namespace events;
#if defined(LORAWAN_COMPLIANCE_TEST)
#if (MBED_CONF_LORA_PHY == 0 || MBED_CONF_LORA_PHY == 4 || MBED_CONF_LORA_PHY == 6 || MBED_CONF_LORA_PHY == 7)
#define LORAWAN_COMPLIANCE_TEST_DATA_SIZE 16
#elif (MBED_CONF_LORA_PHY == 1 || MBED_CONF_LORA_PHY == 2 || MBED_CONF_LORA_PHY == 8 || MBED_CONF_LORA_PHY == 9)
#define LORAWAN_COMPLIANCE_TEST_DATA_SIZE 11
#else
#error "Must set LoRa PHY layer parameters."
#endif
#if (MBED_CONF_LORA_PHY == 0 || MBED_CONF_LORA_PHY == 4 || MBED_CONF_LORA_PHY == 6 || MBED_CONF_LORA_PHY == 7)
#define LORAWAN_COMPLIANCE_TEST_DATA_SIZE 16
#elif (MBED_CONF_LORA_PHY == 1 || MBED_CONF_LORA_PHY == 2 || MBED_CONF_LORA_PHY == 8 || MBED_CONF_LORA_PHY == 9)
#define LORAWAN_COMPLIANCE_TEST_DATA_SIZE 11
#else
#error "Must set LoRa PHY layer parameters."
#endif
#endif //defined(LORAWAN_COMPLIANCE_TEST)
/**
* Bit mask for message flags
@ -98,7 +98,7 @@ LoRaWANStack::LoRaWANStack()
/*****************************************************************************
* Public Methods *
****************************************************************************/
void LoRaWANStack::bind_radio_driver(LoRaRadio& radio)
void LoRaWANStack::bind_radio_driver(LoRaRadio &radio)
{
radio_events.tx_done = mbed::callback(this, &LoRaWANStack::tx_interrupt_handler);
radio_events.rx_done = mbed::callback(this, &LoRaWANStack::rx_interrupt_handler);
@ -115,7 +115,7 @@ void LoRaWANStack::bind_radio_driver(LoRaRadio& radio)
lorawan_status_t LoRaWANStack::initialize_mac_layer(EventQueue *queue)
{
if(!queue) {
if (!queue) {
return LORAWAN_STATUS_PARAMETER_INVALID;
}
@ -127,6 +127,10 @@ lorawan_status_t LoRaWANStack::initialize_mac_layer(EventQueue *queue)
lorawan_status_t LoRaWANStack::set_lora_callbacks(const lorawan_app_callbacks_t *callbacks)
{
if (DEVICE_STATE_NOT_INITIALIZED == _device_current_state) {
return LORAWAN_STATUS_NOT_INITIALIZED;
}
if (!callbacks || !callbacks->events) {
return LORAWAN_STATUS_PARAMETER_INVALID;
}
@ -148,7 +152,6 @@ lorawan_status_t LoRaWANStack::set_lora_callbacks(const lorawan_app_callbacks_t
lorawan_status_t LoRaWANStack::connect()
{
if (DEVICE_STATE_NOT_INITIALIZED == _device_current_state) {
tr_error("Stack not initialized!");
return LORAWAN_STATUS_NOT_INITIALIZED;
}
@ -164,14 +167,14 @@ lorawan_status_t LoRaWANStack::connect()
lorawan_status_t LoRaWANStack::connect(const lorawan_connect_t &connect)
{
if (DEVICE_STATE_NOT_INITIALIZED == _device_current_state) {
tr_error("Stack not initialized!");
return LORAWAN_STATUS_NOT_INITIALIZED;
}
if (!(connect.connect_type == LORAWAN_CONNECTION_OTAA) &&
!(connect.connect_type == LORAWAN_CONNECTION_ABP)) {
if (!(connect.connect_type == LORAWAN_CONNECTION_OTAA)
&& !(connect.connect_type == LORAWAN_CONNECTION_ABP)) {
return LORAWAN_STATUS_PARAMETER_INVALID;
}
bool is_otaa = (connect.connect_type == LORAWAN_CONNECTION_OTAA);
lorawan_status_t status = _loramac.prepare_join(&connect, is_otaa);
@ -186,7 +189,6 @@ lorawan_status_t LoRaWANStack::connect(const lorawan_connect_t &connect)
lorawan_status_t LoRaWANStack::add_channels(const lorawan_channelplan_t &channel_plan)
{
if (_device_current_state == DEVICE_STATE_NOT_INITIALIZED) {
tr_error("Stack not initialized!");
return LORAWAN_STATUS_NOT_INITIALIZED;
}
@ -196,7 +198,6 @@ lorawan_status_t LoRaWANStack::add_channels(const lorawan_channelplan_t &channel
lorawan_status_t LoRaWANStack::remove_a_channel(uint8_t channel_id)
{
if (_device_current_state == DEVICE_STATE_NOT_INITIALIZED) {
tr_error("Stack not initialized!");
return LORAWAN_STATUS_NOT_INITIALIZED;
}
@ -206,17 +207,15 @@ lorawan_status_t LoRaWANStack::remove_a_channel(uint8_t channel_id)
lorawan_status_t LoRaWANStack::drop_channel_list()
{
if (_device_current_state == DEVICE_STATE_NOT_INITIALIZED) {
tr_error("Stack not initialized!");
return LORAWAN_STATUS_NOT_INITIALIZED;
}
return _loramac.remove_channel_plan();
}
lorawan_status_t LoRaWANStack::get_enabled_channels(lorawan_channelplan_t& channel_plan)
lorawan_status_t LoRaWANStack::get_enabled_channels(lorawan_channelplan_t &channel_plan)
{
if (_device_current_state == DEVICE_STATE_NOT_INITIALIZED) {
tr_error("Stack not initialized!");
return LORAWAN_STATUS_NOT_INITIALIZED;
}
@ -225,6 +224,10 @@ lorawan_status_t LoRaWANStack::get_enabled_channels(lorawan_channelplan_t& chann
lorawan_status_t LoRaWANStack::set_confirmed_msg_retry(uint8_t count)
{
if (_device_current_state == DEVICE_STATE_NOT_INITIALIZED) {
return LORAWAN_STATUS_NOT_INITIALIZED;
}
if (count >= MAX_CONFIRMED_MSG_RETRIES) {
return LORAWAN_STATUS_PARAMETER_INVALID;
}
@ -236,9 +239,7 @@ lorawan_status_t LoRaWANStack::set_confirmed_msg_retry(uint8_t count)
lorawan_status_t LoRaWANStack::set_channel_data_rate(uint8_t data_rate)
{
if (DEVICE_STATE_NOT_INITIALIZED == _device_current_state)
{
tr_error("Stack not initialized!");
if (DEVICE_STATE_NOT_INITIALIZED == _device_current_state) {
return LORAWAN_STATUS_NOT_INITIALIZED;
}
@ -248,11 +249,10 @@ lorawan_status_t LoRaWANStack::set_channel_data_rate(uint8_t data_rate)
lorawan_status_t LoRaWANStack::enable_adaptive_datarate(bool adr_enabled)
{
if (_device_current_state == DEVICE_STATE_NOT_INITIALIZED)
{
tr_error("Stack not initialized!");
if (_device_current_state == DEVICE_STATE_NOT_INITIALIZED) {
return LORAWAN_STATUS_NOT_INITIALIZED;
}
_loramac.enable_adaptive_datarate(adr_enabled);
return LORAWAN_STATUS_OK;
}
@ -272,7 +272,7 @@ lorawan_status_t LoRaWANStack::stop_sending(void)
return LORAWAN_STATUS_BUSY;
}
int16_t LoRaWANStack::handle_tx(const uint8_t port, const uint8_t* data,
int16_t LoRaWANStack::handle_tx(const uint8_t port, const uint8_t *data,
uint16_t length, uint8_t flags,
bool null_allowed, bool allow_port_0)
{
@ -289,7 +289,7 @@ int16_t LoRaWANStack::handle_tx(const uint8_t port, const uint8_t* data,
return LORAWAN_STATUS_NO_ACTIVE_SESSIONS;
}
if(_loramac.tx_ongoing()) {
if (_loramac.tx_ongoing()) {
return LORAWAN_STATUS_WOULD_BLOCK;
}
@ -334,7 +334,7 @@ int16_t LoRaWANStack::handle_tx(const uint8_t port, const uint8_t* data,
return (status == LORAWAN_STATUS_OK) ? len : (int16_t) status;
}
int16_t LoRaWANStack::handle_rx(uint8_t* data, uint16_t length, uint8_t& port, int& flags, bool validate_params)
int16_t LoRaWANStack::handle_rx(uint8_t *data, uint16_t length, uint8_t &port, int &flags, bool validate_params)
{
if (!_lw_session.active) {
return LORAWAN_STATUS_NO_ACTIVE_SESSIONS;
@ -375,8 +375,8 @@ int16_t LoRaWANStack::handle_rx(uint8_t* data, uint16_t length, uint8_t& port, i
// check the length of received message whether we can fit into user
// buffer completely or not
if (_rx_msg.msg.mcps_indication.buffer_size > length &&
_rx_msg.prev_read_size == 0) {
if (_rx_msg.msg.mcps_indication.buffer_size > length
&& _rx_msg.prev_read_size == 0) {
// we can't fit into user buffer. Invoke counter measures
_rx_msg.pending_size = _rx_msg.msg.mcps_indication.buffer_size - length;
base_size = length;
@ -393,7 +393,7 @@ int16_t LoRaWANStack::handle_rx(uint8_t* data, uint16_t length, uint8_t& port, i
// the buffer. Due to checks above, in case of a pending read, this block
// will be the only one to get invoked
if (_rx_msg.pending_size > 0 && _rx_msg.prev_read_size > 0) {
memcpy(data, base_ptr+_rx_msg.prev_read_size, base_size);
memcpy(data, base_ptr + _rx_msg.prev_read_size, base_size);
}
// we are done handing over received buffer to user. check if there is
@ -410,6 +410,10 @@ int16_t LoRaWANStack::handle_rx(uint8_t* data, uint16_t length, uint8_t& port, i
lorawan_status_t LoRaWANStack::set_link_check_request()
{
if (DEVICE_STATE_NOT_INITIALIZED == _device_current_state) {
return LORAWAN_STATUS_NOT_INITIALIZED;
}
_link_check_requested = true;
if (!_callbacks.link_check_resp) {
tr_error("Must assign a callback function for link check request. ");
@ -427,11 +431,19 @@ void LoRaWANStack::remove_link_check_request()
lorawan_status_t LoRaWANStack::shutdown()
{
if (DEVICE_STATE_NOT_INITIALIZED == _device_current_state) {
return LORAWAN_STATUS_NOT_INITIALIZED;
}
return state_controller(DEVICE_STATE_SHUTDOWN);
}
lorawan_status_t LoRaWANStack::set_device_class(const device_class_t& device_class)
lorawan_status_t LoRaWANStack::set_device_class(const device_class_t &device_class)
{
if (DEVICE_STATE_NOT_INITIALIZED == _device_current_state) {
return LORAWAN_STATUS_NOT_INITIALIZED;
}
if (device_class == CLASS_B) {
return LORAWAN_STATUS_UNSUPPORTED;
}
@ -593,7 +605,7 @@ void LoRaWANStack::handle_ack_expiry_for_class_c(void)
state_controller(DEVICE_STATE_STATUS_CHECK);
}
void LoRaWANStack::process_reception(const uint8_t* const payload, uint16_t size,
void LoRaWANStack::process_reception(const uint8_t *const payload, uint16_t size,
int16_t rssi, int8_t snr)
{
_device_current_state = DEVICE_STATE_RECEIVING;
@ -965,7 +977,7 @@ void LoRaWANStack::mcps_indication_handler()
*/
if ((_loramac.get_device_class() != CLASS_C && mcps_indication->fpending_status)
||
(_loramac.get_device_class() == CLASS_C && mcps_indication->type == MCPS_CONFIRMED)) {
(_loramac.get_device_class() == CLASS_C && mcps_indication->type == MCPS_CONFIRMED)) {
#if (MBED_CONF_LORA_AUTOMATIC_UPLINK_MESSAGE)
tr_debug("Sending empty uplink message...");
_automatic_uplink_ongoing = true;
@ -1012,7 +1024,7 @@ lorawan_status_t LoRaWANStack::state_controller(device_states_t new_state)
return status;
}
void LoRaWANStack::process_shutdown_state(lorawan_status_t& op_status)
void LoRaWANStack::process_shutdown_state(lorawan_status_t &op_status)
{
/**
* Remove channels
@ -1030,7 +1042,7 @@ void LoRaWANStack::process_shutdown_state(lorawan_status_t& op_status)
void LoRaWANStack::process_status_check_state()
{
if (_device_current_state == DEVICE_STATE_SENDING ||
_device_current_state == DEVICE_STATE_AWAITING_ACK) {
_device_current_state == DEVICE_STATE_AWAITING_ACK) {
// this happens after RX2 slot is exhausted
// we may or may not have a successful UNCONFIRMED transmission
// here. In CONFIRMED case this block is invoked only
@ -1070,11 +1082,11 @@ void LoRaWANStack::process_status_check_state()
}
}
void LoRaWANStack::process_scheduling_state(lorawan_status_t& op_status)
void LoRaWANStack::process_scheduling_state(lorawan_status_t &op_status)
{
if (_device_current_state != DEVICE_STATE_IDLE) {
if (_device_current_state != DEVICE_STATE_RECEIVING
&& _loramac.get_device_class() != CLASS_C) {
&& _loramac.get_device_class() != CLASS_C) {
op_status = LORAWAN_STATUS_BUSY;
return;
}
@ -1089,7 +1101,7 @@ void LoRaWANStack::process_scheduling_state(lorawan_status_t& op_status)
}
}
void LoRaWANStack::process_joining_state(lorawan_status_t& op_status)
void LoRaWANStack::process_joining_state(lorawan_status_t &op_status)
{
if (_device_current_state == DEVICE_STATE_CONNECTING) {
_device_current_state = DEVICE_STATE_JOINING;
@ -1124,11 +1136,10 @@ void LoRaWANStack::process_connected_state()
_device_current_state = DEVICE_STATE_IDLE;
}
void LoRaWANStack::process_connecting_state(lorawan_status_t& op_status)
void LoRaWANStack::process_connecting_state(lorawan_status_t &op_status)
{
if (_device_current_state != DEVICE_STATE_IDLE
&&
_device_current_state != DEVICE_STATE_SHUTDOWN) {
&& _device_current_state != DEVICE_STATE_SHUTDOWN) {
op_status = LORAWAN_STATUS_BUSY;
return;
}
@ -1151,7 +1162,7 @@ void LoRaWANStack::process_connecting_state(lorawan_status_t& op_status)
process_connected_state();
}
void LoRaWANStack::process_idle_state(lorawan_status_t& op_status)
void LoRaWANStack::process_idle_state(lorawan_status_t &op_status)
{
if (_device_current_state == DEVICE_STATE_NOT_INITIALIZED) {
_device_current_state = DEVICE_STATE_IDLE;
@ -1163,7 +1174,7 @@ void LoRaWANStack::process_idle_state(lorawan_status_t& op_status)
op_status = LORAWAN_STATUS_OK;
}
void LoRaWANStack::process_uninitialized_state(lorawan_status_t& op_status)
void LoRaWANStack::process_uninitialized_state(lorawan_status_t &op_status)
{
op_status = _loramac.initialize(_queue);
@ -1192,19 +1203,19 @@ lorawan_status_t LoRaWANStack::send_compliance_test_frame_to_mac()
test_req.f_buffer[2] = _compliance_test.nb_gateways;
} else {
switch (_compliance_test.state) {
case 4:
_compliance_test.state = 1;
test_req.f_buffer_size = _compliance_test.app_data_size;
test_req.f_buffer[0] = _compliance_test.app_data_buffer[0];
for(uint8_t i = 1; i < MIN(_compliance_test.app_data_size, MBED_CONF_LORA_TX_MAX_SIZE); ++i) {
test_req.f_buffer[i] = _compliance_test.app_data_buffer[i];
}
break;
case 1:
test_req.f_buffer_size = 2;
test_req.f_buffer[0] = _compliance_test.downlink_counter >> 8;
test_req.f_buffer[1] = _compliance_test.downlink_counter;
break;
case 4:
_compliance_test.state = 1;
test_req.f_buffer_size = _compliance_test.app_data_size;
test_req.f_buffer[0] = _compliance_test.app_data_buffer[0];
for (uint8_t i = 1; i < MIN(_compliance_test.app_data_size, MBED_CONF_LORA_TX_MAX_SIZE); ++i) {
test_req.f_buffer[i] = _compliance_test.app_data_buffer[i];
}
break;
case 1:
test_req.f_buffer_size = 2;
test_req.f_buffer[0] = _compliance_test.downlink_counter >> 8;
test_req.f_buffer[1] = _compliance_test.downlink_counter;
break;
}
}
}
@ -1220,7 +1231,7 @@ lorawan_status_t LoRaWANStack::send_compliance_test_frame_to_mac()
tr_info("Transmit unconfirmed compliance test frame %d bytes.", test_req.f_buffer_size);
for (uint8_t i = 0; i < test_req.f_buffer_size; ++i) {
tr_info("Byte %d, data is 0x%x", i+1, ((uint8_t*)test_req.f_buffer)[i]);
tr_info("Byte %d, data is 0x%x", i + 1, ((uint8_t *)test_req.f_buffer)[i]);
}
} else if (_compliance_test.is_tx_confirmed) {
test_req.type = MCPS_CONFIRMED;
@ -1231,7 +1242,7 @@ lorawan_status_t LoRaWANStack::send_compliance_test_frame_to_mac()
tr_info("Transmit confirmed compliance test frame %d bytes.", test_req.f_buffer_size);
for (uint8_t i = 0; i < test_req.f_buffer_size; ++i) {
tr_info("Byte %d, data is 0x%x", i+1, ((uint8_t*)test_req.f_buffer)[i]);
tr_info("Byte %d, data is 0x%x", i + 1, ((uint8_t *)test_req.f_buffer)[i]);
}
} else {
return LORAWAN_STATUS_SERVICE_UNKNOWN;
@ -1245,10 +1256,10 @@ void LoRaWANStack::compliance_test_handler(loramac_mcps_indication_t *mcps_indic
if (_compliance_test.running == false) {
// Check compliance test enable command (i)
if ((mcps_indication->buffer_size == 4) &&
(mcps_indication->buffer[0] == 0x01) &&
(mcps_indication->buffer[1] == 0x01) &&
(mcps_indication->buffer[2] == 0x01) &&
(mcps_indication->buffer[3] == 0x01)) {
(mcps_indication->buffer[0] == 0x01) &&
(mcps_indication->buffer[1] == 0x01) &&
(mcps_indication->buffer[2] == 0x01) &&
(mcps_indication->buffer[3] == 0x01)) {
_compliance_test.is_tx_confirmed = false;
_compliance_test.app_port = 224;
_compliance_test.app_data_size = 2;
@ -1275,82 +1286,82 @@ void LoRaWANStack::compliance_test_handler(loramac_mcps_indication_t *mcps_indic
} else {
_compliance_test.state = mcps_indication->buffer[0];
switch (_compliance_test.state) {
case 0: // Check compliance test disable command (ii)
_compliance_test.is_tx_confirmed = true;
_compliance_test.app_port = MBED_CONF_LORA_APP_PORT;
_compliance_test.app_data_size = LORAWAN_COMPLIANCE_TEST_DATA_SIZE;
_compliance_test.downlink_counter = 0;
_compliance_test.running = false;
case 0: // Check compliance test disable command (ii)
_compliance_test.is_tx_confirmed = true;
_compliance_test.app_port = MBED_CONF_LORA_APP_PORT;
_compliance_test.app_data_size = LORAWAN_COMPLIANCE_TEST_DATA_SIZE;
_compliance_test.downlink_counter = 0;
_compliance_test.running = false;
_loramac.enable_adaptive_datarate(MBED_CONF_LORA_ADR_ON);
_loramac.enable_adaptive_datarate(MBED_CONF_LORA_ADR_ON);
#if MBED_CONF_LORA_PHY == 0
_loramac.LoRaMacTestSetDutyCycleOn(MBED_CONF_LORA_DUTY_CYCLE_ON);
_loramac.LoRaMacTestSetDutyCycleOn(MBED_CONF_LORA_DUTY_CYCLE_ON);
#endif
// Go to idle state after compliance test mode.
tr_debug("Compliance test disabled.");
_loramac.LoRaMacStopTxTimer();
// Go to idle state after compliance test mode.
tr_debug("Compliance test disabled.");
_loramac.LoRaMacStopTxTimer();
// Clear any compliance test message stuff before going back to normal operation.
_loramac.reset_ongoing_tx();
lora_state_machine(DEVICE_STATE_IDLE);
break;
case 1: // (iii, iv)
_compliance_test.app_data_size = 2;
break;
case 2: // Enable confirmed messages (v)
_compliance_test.is_tx_confirmed = true;
_compliance_test.state = 1;
break;
case 3: // Disable confirmed messages (vi)
_compliance_test.is_tx_confirmed = false;
_compliance_test.state = 1;
break;
case 4: // (vii)
_compliance_test.app_data_size = mcps_indication->buffer_size;
// Clear any compliance test message stuff before going back to normal operation.
_loramac.reset_ongoing_tx();
lora_state_machine(DEVICE_STATE_IDLE);
break;
case 1: // (iii, iv)
_compliance_test.app_data_size = 2;
break;
case 2: // Enable confirmed messages (v)
_compliance_test.is_tx_confirmed = true;
_compliance_test.state = 1;
break;
case 3: // Disable confirmed messages (vi)
_compliance_test.is_tx_confirmed = false;
_compliance_test.state = 1;
break;
case 4: // (vii)
_compliance_test.app_data_size = mcps_indication->buffer_size;
_compliance_test.app_data_buffer[0] = 4;
for(uint8_t i = 1; i < MIN(_compliance_test.app_data_size, LORAMAC_PHY_MAXPAYLOAD); ++i) {
_compliance_test.app_data_buffer[i] = mcps_indication->buffer[i] + 1;
}
_compliance_test.app_data_buffer[0] = 4;
for (uint8_t i = 1; i < MIN(_compliance_test.app_data_size, LORAMAC_PHY_MAXPAYLOAD); ++i) {
_compliance_test.app_data_buffer[i] = mcps_indication->buffer[i] + 1;
}
send_compliance_test_frame_to_mac();
break;
case 5: // (viii)
_loramac.setup_link_check_request();
break;
case 6: // (ix)
// Disable TestMode and revert back to normal operation
_compliance_test.is_tx_confirmed = true;
_compliance_test.app_port = MBED_CONF_LORA_APP_PORT;
_compliance_test.app_data_size = LORAWAN_COMPLIANCE_TEST_DATA_SIZE;
_compliance_test.downlink_counter = 0;
_compliance_test.running = false;
send_compliance_test_frame_to_mac();
break;
case 5: // (viii)
_loramac.setup_link_check_request();
break;
case 6: // (ix)
// Disable TestMode and revert back to normal operation
_compliance_test.is_tx_confirmed = true;
_compliance_test.app_port = MBED_CONF_LORA_APP_PORT;
_compliance_test.app_data_size = LORAWAN_COMPLIANCE_TEST_DATA_SIZE;
_compliance_test.downlink_counter = 0;
_compliance_test.running = false;
_loramac.enable_adaptive_datarate(MBED_CONF_LORA_ADR_ON);
_loramac.enable_adaptive_datarate(MBED_CONF_LORA_ADR_ON);
#if MBED_CONF_LORA_PHY == 0
_loramac.LoRaMacTestSetDutyCycleOn(MBED_CONF_LORA_DUTY_CYCLE_ON);
_loramac.LoRaMacTestSetDutyCycleOn(MBED_CONF_LORA_DUTY_CYCLE_ON);
#endif
_loramac.join(true);
break;
case 7: // (x)
if (mcps_indication->buffer_size == 3) {
loramac_mlme_req_t mlme_req;
mlme_req.type = MLME_TXCW;
mlme_req.cw_tx_mode.timeout = (uint16_t)((mcps_indication->buffer[1] << 8) | mcps_indication->buffer[2]);
_loramac.mlme_request(&mlme_req);
} else if (mcps_indication->buffer_size == 7) {
loramac_mlme_req_t mlme_req;
mlme_req.type = MLME_TXCW_1;
mlme_req.cw_tx_mode.timeout = (uint16_t)((mcps_indication->buffer[1] << 8) | mcps_indication->buffer[2]);
mlme_req.cw_tx_mode.frequency = (uint32_t)((mcps_indication->buffer[3] << 16) | (mcps_indication->buffer[4] << 8)
_loramac.join(true);
break;
case 7: // (x)
if (mcps_indication->buffer_size == 3) {
loramac_mlme_req_t mlme_req;
mlme_req.type = MLME_TXCW;
mlme_req.cw_tx_mode.timeout = (uint16_t)((mcps_indication->buffer[1] << 8) | mcps_indication->buffer[2]);
_loramac.mlme_request(&mlme_req);
} else if (mcps_indication->buffer_size == 7) {
loramac_mlme_req_t mlme_req;
mlme_req.type = MLME_TXCW_1;
mlme_req.cw_tx_mode.timeout = (uint16_t)((mcps_indication->buffer[1] << 8) | mcps_indication->buffer[2]);
mlme_req.cw_tx_mode.frequency = (uint32_t)((mcps_indication->buffer[3] << 16) | (mcps_indication->buffer[4] << 8)
| mcps_indication->buffer[5]) * 100;
mlme_req.cw_tx_mode.power = mcps_indication->buffer[6];
_loramac.mlme_request(&mlme_req);
}
_compliance_test.state = 1;
break;
mlme_req.cw_tx_mode.power = mcps_indication->buffer[6];
_loramac.mlme_request(&mlme_req);
}
_compliance_test.state = 1;
break;
}
}
}

View File

@ -67,7 +67,7 @@ public:
* @param radio LoRaRadio object, i.e., the radio driver
*
*/
void bind_radio_driver(LoRaRadio& radio);
void bind_radio_driver(LoRaRadio &radio);
/** End device initialization.
* @param queue A pointer to an EventQueue passed from the application.
@ -281,7 +281,7 @@ public:
* LORAWAN_STATUS_WOULD_BLOCK if another TX is
* ongoing, or a negative error code on failure.
*/
int16_t handle_tx(uint8_t port, const uint8_t* data,
int16_t handle_tx(uint8_t port, const uint8_t *data,
uint16_t length, uint8_t flags,
bool null_allowed = false, bool allow_port_0 = false);
@ -334,7 +334,7 @@ public:
* nothing available to read at the moment.
* iv) A negative error code on failure.
*/
int16_t handle_rx(uint8_t* data, uint16_t length, uint8_t& port, int& flags, bool validate_params);
int16_t handle_rx(uint8_t *data, uint16_t length, uint8_t &port, int &flags, bool validate_params);
/** Send Link Check Request MAC command.
*
@ -377,7 +377,7 @@ public:
* LORAWAN_STATUS_UNSUPPORTED is requested class is not supported,
* or other negative error code if request failed.
*/
lorawan_status_t set_device_class(const device_class_t& device_class);
lorawan_status_t set_device_class(const device_class_t &device_class);
/** Acquire TX meta-data
*
@ -425,8 +425,14 @@ public:
*/
lorawan_status_t stop_sending(void);
void lock(void) { _loramac.lock(); }
void unlock(void) { _loramac.unlock(); }
void lock(void)
{
_loramac.lock();
}
void unlock(void)
{
_loramac.unlock();
}
private:
typedef mbed::ScopedLock<LoRaWANStack> Lock;
@ -443,14 +449,14 @@ private:
/**
* Helpers for state controller
*/
void process_uninitialized_state(lorawan_status_t& op_status);
void process_idle_state(lorawan_status_t& op_status);
void process_uninitialized_state(lorawan_status_t &op_status);
void process_idle_state(lorawan_status_t &op_status);
void process_connected_state();
void process_connecting_state(lorawan_status_t& op_status);
void process_joining_state(lorawan_status_t& op_status);
void process_scheduling_state(lorawan_status_t& op_status);
void process_connecting_state(lorawan_status_t &op_status);
void process_joining_state(lorawan_status_t &op_status);
void process_scheduling_state(lorawan_status_t &op_status);
void process_status_check_state();
void process_shutdown_state(lorawan_status_t& op_status);
void process_shutdown_state(lorawan_status_t &op_status);
void state_machine_run_to_completion(void);
/**

View File

@ -72,19 +72,19 @@ using namespace mbed;
LoRaMac::LoRaMac()
: _lora_time(),
_lora_phy(_lora_time),
_mac_commands(),
_channel_plan(),
_lora_crypto(),
_ev_queue(NULL),
_mcps_indication(),
_mcps_confirmation(),
_mlme_indication(),
_mlme_confirmation(),
_is_nwk_joined(false),
_continuous_rx2_window_open(false),
_device_class(CLASS_A)
: _lora_time(),
_lora_phy(_lora_time),
_mac_commands(),
_channel_plan(),
_lora_crypto(),
_ev_queue(NULL),
_mcps_indication(),
_mcps_confirmation(),
_mlme_indication(),
_mlme_confirmation(),
_is_nwk_joined(false),
_continuous_rx2_window_open(false),
_device_class(CLASS_A)
{
_params.keys.dev_eui = NULL;
_params.keys.app_eui = NULL;
@ -202,7 +202,7 @@ void LoRaMac::on_radio_tx_done(void)
}
}
if(_params.is_rx_window_enabled == true) {
if (_params.is_rx_window_enabled == true) {
// start timer after which rx1_window will get opened
_lora_time.start(_params.timers.rx_window1_timer, _params.rx_window1_delay);
@ -237,8 +237,8 @@ void LoRaMac::handle_join_accept_frame(const uint8_t *payload, uint16_t size)
_mlme_confirmation.nb_retries = _params.join_request_trial_counter;
if (0 != _lora_crypto.decrypt_join_frame(payload + 1, size - 1,
_params.keys.app_key, APPKEY_KEY_LENGTH,
_params.rx_buffer + 1)) {
_params.keys.app_key, APPKEY_KEY_LENGTH,
_params.rx_buffer + 1)) {
_mlme_confirmation.status = LORAMAC_EVENT_INFO_STATUS_CRYPTO_FAIL;
return;
}
@ -317,11 +317,11 @@ void LoRaMac::check_frame_size(uint16_t size)
}
}
bool LoRaMac::message_integrity_check(const uint8_t * const payload,
bool LoRaMac::message_integrity_check(const uint8_t *const payload,
const uint16_t size,
uint8_t * const ptr_pos,
uint8_t *const ptr_pos,
uint32_t address,
uint32_t* downlink_counter,
uint32_t *downlink_counter,
const uint8_t *nwk_skey)
{
uint32_t mic = 0;
@ -349,7 +349,7 @@ bool LoRaMac::message_integrity_check(const uint8_t * const payload,
// sizeof nws_skey must be the same as _params.keys.nwk_skey,
_lora_crypto.compute_mic(payload, size - LORAMAC_MFR_LEN,
nwk_skey,
sizeof(_params.keys.nwk_skey)*8,
sizeof(_params.keys.nwk_skey) * 8,
address, DOWN_LINK, *downlink_counter, &mic);
if (mic_rx != mic) {
@ -367,14 +367,14 @@ bool LoRaMac::message_integrity_check(const uint8_t * const payload,
}
void LoRaMac::extract_data_and_mac_commands(const uint8_t *payload,
uint16_t size,
uint8_t fopts_len,
uint8_t *nwk_skey,
uint8_t *app_skey,
uint32_t address,
uint32_t downlink_counter,
int16_t rssi,
int8_t snr)
uint16_t size,
uint8_t fopts_len,
uint8_t *nwk_skey,
uint8_t *app_skey,
uint32_t address,
uint32_t downlink_counter,
int16_t rssi,
int8_t snr)
{
uint8_t frame_len = 0;
uint8_t payload_start_index = 8 + fopts_len;
@ -390,7 +390,7 @@ void LoRaMac::extract_data_and_mac_commands(const uint8_t *payload,
if (_lora_crypto.decrypt_payload(payload + payload_start_index,
frame_len,
nwk_skey,
sizeof(_params.keys.nwk_skey)*8,
sizeof(_params.keys.nwk_skey) * 8,
address,
DOWN_LINK,
downlink_counter,
@ -399,8 +399,8 @@ void LoRaMac::extract_data_and_mac_commands(const uint8_t *payload,
}
if (_mac_commands.process_mac_commands(_params.rx_buffer, 0, frame_len,
snr, _mlme_confirmation,
_params.sys_params, _lora_phy)
snr, _mlme_confirmation,
_params.sys_params, _lora_phy)
!= LORAWAN_STATUS_OK) {
_mcps_indication.status = LORAMAC_EVENT_INFO_STATUS_ERROR;
return;
@ -425,10 +425,11 @@ void LoRaMac::extract_data_and_mac_commands(const uint8_t *payload,
if (fopts_len > 0) {
// Decode Options field MAC commands. Omit the fPort.
if (_mac_commands.process_mac_commands(payload, 8,
payload_start_index - 1, snr,
_mlme_confirmation,
_params.sys_params, _lora_phy)
!= LORAWAN_STATUS_OK) {
payload_start_index - 1,
snr,
_mlme_confirmation,
_params.sys_params,
_lora_phy) != LORAWAN_STATUS_OK) {
_mcps_indication.status = LORAMAC_EVENT_INFO_STATUS_ERROR;
return;
}
@ -463,8 +464,8 @@ void LoRaMac::extract_mac_commands_only(const uint8_t *payload,
uint8_t payload_start_index = 8 + fopts_len;
if (fopts_len > 0) {
if (_mac_commands.process_mac_commands(payload, 8, payload_start_index,
snr, _mlme_confirmation,
_params.sys_params, _lora_phy)
snr, _mlme_confirmation,
_params.sys_params, _lora_phy)
!= LORAWAN_STATUS_OK) {
_mcps_indication.status = LORAMAC_EVENT_INFO_STATUS_ERROR;
return;
@ -477,7 +478,7 @@ void LoRaMac::extract_mac_commands_only(const uint8_t *payload,
}
}
void LoRaMac::handle_data_frame(const uint8_t* const payload,
void LoRaMac::handle_data_frame(const uint8_t *const payload,
const uint16_t size,
uint8_t ptr_pos,
uint8_t msg_type,
@ -655,7 +656,7 @@ void LoRaMac::set_batterylevel_callback(mbed::Callback<uint8_t(void)> battery_le
_mac_commands.set_batterylevel_callback(battery_level);
}
void LoRaMac::on_radio_rx_done(const uint8_t* const payload, uint16_t size,
void LoRaMac::on_radio_rx_done(const uint8_t *const payload, uint16_t size,
int16_t rssi, int8_t snr)
{
// stop the RX1 timer here if its the first RX slot.
@ -706,7 +707,7 @@ void LoRaMac::on_radio_rx_done(const uint8_t* const payload, uint16_t size,
}
}
void LoRaMac::on_radio_tx_timeout( void )
void LoRaMac::on_radio_tx_timeout(void)
{
_lora_time.stop(_params.timers.rx_window1_timer);
_lora_time.stop(_params.timers.rx_window2_timer);
@ -738,29 +739,33 @@ rx_slot_t LoRaMac::on_radio_rx_timeout(bool is_timeout)
if (_params.rx_slot == RX_SLOT_WIN_1) {
if (_params.is_node_ack_requested == true) {
_mcps_confirmation.status = is_timeout ? LORAMAC_EVENT_INFO_STATUS_RX1_TIMEOUT
: LORAMAC_EVENT_INFO_STATUS_RX1_ERROR;
_mcps_confirmation.status = is_timeout ?
LORAMAC_EVENT_INFO_STATUS_RX1_TIMEOUT :
LORAMAC_EVENT_INFO_STATUS_RX1_ERROR;
}
_mlme_confirmation.status = is_timeout ? LORAMAC_EVENT_INFO_STATUS_RX1_TIMEOUT
: LORAMAC_EVENT_INFO_STATUS_RX1_ERROR;
_mlme_confirmation.status = is_timeout ?
LORAMAC_EVENT_INFO_STATUS_RX1_TIMEOUT :
LORAMAC_EVENT_INFO_STATUS_RX1_ERROR;
if (_device_class != CLASS_C) {
if (_lora_time.get_elapsed_time(_params.timers.aggregated_last_tx_time ) >= _params.rx_window2_delay) {
if (_lora_time.get_elapsed_time(_params.timers.aggregated_last_tx_time) >= _params.rx_window2_delay) {
_lora_time.stop(_params.timers.rx_window2_timer);
}
}
} else {
if (_params.is_node_ack_requested == true) {
_mcps_confirmation.status = is_timeout ? LORAMAC_EVENT_INFO_STATUS_RX2_TIMEOUT
: LORAMAC_EVENT_INFO_STATUS_RX2_ERROR;
_mcps_confirmation.status = is_timeout ?
LORAMAC_EVENT_INFO_STATUS_RX2_TIMEOUT :
LORAMAC_EVENT_INFO_STATUS_RX2_ERROR;
}
_mlme_confirmation.status = is_timeout ? LORAMAC_EVENT_INFO_STATUS_RX2_TIMEOUT
: LORAMAC_EVENT_INFO_STATUS_RX2_ERROR;
_mlme_confirmation.status = is_timeout ?
LORAMAC_EVENT_INFO_STATUS_RX2_TIMEOUT :
LORAMAC_EVENT_INFO_STATUS_RX2_ERROR;
}
if (_device_class == CLASS_C) {
open_rx2_window();
open_rx2_window();
}
return _params.rx_slot;
@ -929,8 +934,7 @@ void LoRaMac::on_ack_timeout_timer_event(void)
if ((_params.ack_timeout_retry_counter % 2)
&& (_params.sys_params.adr_on)) {
tr_debug("Trading datarate for range");
_params.sys_params.channel_data_rate = _lora_phy.get_next_lower_tx_datarate(
_params.sys_params.channel_data_rate);
_params.sys_params.channel_data_rate = _lora_phy.get_next_lower_tx_datarate(_params.sys_params.channel_data_rate);
}
_mcps_confirmation.nb_retries = _params.ack_timeout_retry_counter;
@ -945,6 +949,7 @@ void LoRaMac::on_ack_timeout_timer_event(void)
_mac_commands.clear_command_buffer();
_params.is_node_ack_requested = false;
_mcps_confirmation.ack_received = false;
_mcps_confirmation.nb_retries = _params.ack_timeout_retry_counter;
// now that is a critical failure
lorawan_status_t status = handle_retransmission();
@ -969,7 +974,7 @@ bool LoRaMac::validate_payload_length(uint16_t length,
// Validation of the application payload size
if ((payloadSize <= max_value) &&
(payloadSize <= LORAMAC_PHY_MAXPAYLOAD)) {
(payloadSize <= LORAMAC_PHY_MAXPAYLOAD)) {
return true;
}
return false;
@ -978,7 +983,7 @@ bool LoRaMac::validate_payload_length(uint16_t length,
void LoRaMac::set_mlme_schedule_ul_indication(void)
{
_mlme_indication.indication_type = MLME_SCHEDULE_UPLINK;
_mlme_indication.pending= true;
_mlme_indication.pending = true;
}
// This is not actual transmission. It just schedules a message in response
@ -1213,7 +1218,7 @@ void LoRaMac::reset_ongoing_tx(bool reset_pending)
}
int16_t LoRaMac::prepare_ongoing_tx(const uint8_t port,
const uint8_t* const data,
const uint8_t *const data,
uint16_t length,
uint8_t flags,
uint8_t num_retries)
@ -1306,7 +1311,7 @@ lorawan_status_t LoRaMac::send_ongoing_tx()
}
status = send(&machdr, _ongoing_tx_msg.fport, _ongoing_tx_msg.f_buffer,
_ongoing_tx_msg.f_buffer_size);
_ongoing_tx_msg.f_buffer_size);
if (status == LORAWAN_STATUS_OK) {
_mcps_confirmation.req_type = _ongoing_tx_msg.type;
}
@ -1319,7 +1324,7 @@ device_class_t LoRaMac::get_device_class() const
return _device_class;
}
void LoRaMac::set_device_class(const device_class_t& device_class,
void LoRaMac::set_device_class(const device_class_t &device_class,
mbed::Callback<void(void)>ack_expiry_handler)
{
_device_class = device_class;
@ -1331,12 +1336,12 @@ void LoRaMac::set_device_class(const device_class_t& device_class,
} else if (CLASS_C == _device_class) {
_params.is_node_ack_requested = false;
_lora_phy.put_radio_to_sleep();
_lora_phy.compute_rx_win_params(
_params.sys_params.rx2_channel.datarate,
_params.sys_params.min_rx_symb,
_params.sys_params.max_sys_rx_error,
&_params.rx_window2_config);
_lora_phy.compute_rx_win_params(_params.sys_params.rx2_channel.datarate,
_params.sys_params.min_rx_symb,
_params.sys_params.max_sys_rx_error,
&_params.rx_window2_config);
}
if (CLASS_C == _device_class) {
tr_debug("Changing device class to -> CLASS_C");
open_rx2_window();
@ -1358,10 +1363,10 @@ lorawan_status_t LoRaMac::prepare_join(const lorawan_connect_t *params, bool is_
{
if (params) {
if (is_otaa) {
if ((params->connection_u.otaa.dev_eui == NULL) ||
(params->connection_u.otaa.app_eui == NULL) ||
(params->connection_u.otaa.app_key == NULL) ||
(params->connection_u.otaa.nb_trials == 0)) {
if ((params->connection_u.otaa.dev_eui == NULL)
|| (params->connection_u.otaa.app_eui == NULL)
|| (params->connection_u.otaa.app_key == NULL)
|| (params->connection_u.otaa.nb_trials == 0)) {
return LORAWAN_STATUS_PARAMETER_INVALID;
}
_params.keys.dev_eui = params->connection_u.otaa.dev_eui;
@ -1376,6 +1381,13 @@ lorawan_status_t LoRaMac::prepare_join(const lorawan_connect_t *params, bool is_
// Reset variable JoinRequestTrials
_params.join_request_trial_counter = 0;
} else {
if ((params->connection_u.abp.dev_addr == 0)
|| (params->connection_u.abp.nwk_id == 0)
|| (params->connection_u.abp.nwk_skey == NULL)
|| (params->connection_u.abp.app_skey == NULL)) {
return LORAWAN_STATUS_PARAMETER_INVALID;
}
_params.net_id = params->connection_u.abp.nwk_id;
_params.dev_addr = params->connection_u.abp.dev_addr;
@ -1387,37 +1399,36 @@ lorawan_status_t LoRaMac::prepare_join(const lorawan_connect_t *params, bool is_
}
} else {
#if MBED_CONF_LORA_OVER_THE_AIR_ACTIVATION
const static uint8_t dev_eui[] = MBED_CONF_LORA_DEVICE_EUI;
const static uint8_t app_eui[] = MBED_CONF_LORA_APPLICATION_EUI;
const static uint8_t app_key[] = MBED_CONF_LORA_APPLICATION_KEY;
const static uint8_t dev_eui[] = MBED_CONF_LORA_DEVICE_EUI;
const static uint8_t app_eui[] = MBED_CONF_LORA_APPLICATION_EUI;
const static uint8_t app_key[] = MBED_CONF_LORA_APPLICATION_KEY;
_params.keys.app_eui = const_cast<uint8_t *>(app_eui);
_params.keys.dev_eui = const_cast<uint8_t *>(dev_eui);
_params.keys.app_key = const_cast<uint8_t *>(app_key);
_params.max_join_request_trials = MBED_CONF_LORA_NB_TRIALS;
_params.keys.app_eui = const_cast<uint8_t *>(app_eui);
_params.keys.dev_eui = const_cast<uint8_t *>(dev_eui);
_params.keys.app_key = const_cast<uint8_t *>(app_key);
_params.max_join_request_trials = MBED_CONF_LORA_NB_TRIALS;
// Reset variable JoinRequestTrials
_params.join_request_trial_counter = 0;
// Reset variable JoinRequestTrials
_params.join_request_trial_counter = 0;
reset_mac_parameters();
reset_mac_parameters();
_params.sys_params.channel_data_rate =
_params.sys_params.channel_data_rate =
_lora_phy.get_alternate_DR(_params.join_request_trial_counter + 1);
#else
const static uint8_t nwk_skey[] = MBED_CONF_LORA_NWKSKEY;
const static uint8_t app_skey[] = MBED_CONF_LORA_APPSKEY;
const static uint8_t nwk_skey[] = MBED_CONF_LORA_NWKSKEY;
const static uint8_t app_skey[] = MBED_CONF_LORA_APPSKEY;
_params.net_id = (MBED_CONF_LORA_DEVICE_ADDRESS & LORAWAN_NETWORK_ID_MASK);
_params.dev_addr = MBED_CONF_LORA_DEVICE_ADDRESS;
_params.net_id = (MBED_CONF_LORA_DEVICE_ADDRESS & LORAWAN_NETWORK_ID_MASK);
_params.dev_addr = MBED_CONF_LORA_DEVICE_ADDRESS;
memcpy(_params.keys.nwk_skey, nwk_skey,
sizeof(_params.keys.nwk_skey));
memcpy(_params.keys.nwk_skey, nwk_skey, sizeof(_params.keys.nwk_skey));
memcpy(_params.keys.app_skey, app_skey,
sizeof(_params.keys.app_skey));
memcpy(_params.keys.app_skey, app_skey, sizeof(_params.keys.app_skey));
#endif
}
return LORAWAN_STATUS_OK;
}
@ -1453,7 +1464,7 @@ lorawan_status_t LoRaMac::prepare_frame(loramac_mhdr_t *machdr,
uint16_t i;
uint8_t pkt_header_len = 0;
uint32_t mic = 0;
const void* payload = fbuffer;
const void *payload = fbuffer;
uint8_t frame_port = fport;
lorawan_status_t status = LORAWAN_STATUS_OK;
@ -1502,7 +1513,7 @@ lorawan_status_t LoRaMac::prepare_frame(loramac_mhdr_t *machdr,
break;
case FRAME_TYPE_DATA_CONFIRMED_UP:
_params.is_node_ack_requested = true;
//Intentional fallthrough
//Intentional fallthrough
case FRAME_TYPE_DATA_UNCONFIRMED_UP: {
if (!_is_nwk_joined) {
return LORAWAN_STATUS_NO_NETWORK_JOINED;
@ -1605,7 +1616,7 @@ lorawan_status_t LoRaMac::prepare_frame(loramac_mhdr_t *machdr,
break;
case FRAME_TYPE_PROPRIETARY:
if ((fbuffer != NULL) && (_params.tx_buffer_len > 0)) {
memcpy(_params.tx_buffer + pkt_header_len, (uint8_t*) fbuffer,
memcpy(_params.tx_buffer + pkt_header_len, (uint8_t *) fbuffer,
_params.tx_buffer_len);
_params.tx_buffer_len = pkt_header_len + _params.tx_buffer_len;
}
@ -1654,19 +1665,19 @@ lorawan_status_t LoRaMac::send_frame_on_channel(uint8_t channel)
void LoRaMac::reset_mcps_confirmation()
{
memset((uint8_t*) &_mcps_confirmation, 0, sizeof(_mcps_confirmation));
memset((uint8_t *) &_mcps_confirmation, 0, sizeof(_mcps_confirmation));
_mcps_confirmation.status = LORAMAC_EVENT_INFO_STATUS_ERROR;
}
void LoRaMac::reset_mlme_confirmation()
{
memset((uint8_t*) &_mlme_confirmation, 0, sizeof(_mlme_confirmation));
memset((uint8_t *) &_mlme_confirmation, 0, sizeof(_mlme_confirmation));
_mlme_confirmation.status = LORAMAC_EVENT_INFO_STATUS_ERROR;
}
void LoRaMac::reset_mcps_indication()
{
memset((uint8_t*) &_mcps_indication, 0, sizeof(_mcps_indication));
memset((uint8_t *) &_mcps_indication, 0, sizeof(_mcps_indication));
_mcps_indication.status = LORAMAC_EVENT_INFO_STATUS_ERROR;
}
@ -1800,7 +1811,7 @@ void LoRaMac::set_nwk_joined(bool joined)
_is_nwk_joined = joined;
}
lorawan_status_t LoRaMac::add_channel_plan(const lorawan_channelplan_t& plan)
lorawan_status_t LoRaMac::add_channel_plan(const lorawan_channelplan_t &plan)
{
if (tx_ongoing()) {
return LORAWAN_STATUS_BUSY;
@ -1818,7 +1829,7 @@ lorawan_status_t LoRaMac::remove_channel_plan()
return _channel_plan.remove_plan();
}
lorawan_status_t LoRaMac::get_channel_plan(lorawan_channelplan_t& plan)
lorawan_status_t LoRaMac::get_channel_plan(lorawan_channelplan_t &plan)
{
return _channel_plan.get_plan(plan, _lora_phy.get_phy_channels());
}
@ -1856,8 +1867,7 @@ lorawan_status_t LoRaMac::multicast_channel_link(multicast_params_t *channel_par
return LORAWAN_STATUS_OK;
}
lorawan_status_t LoRaMac::multicast_channel_unlink(
multicast_params_t *channel_param)
lorawan_status_t LoRaMac::multicast_channel_unlink(multicast_params_t *channel_param)
{
if (channel_param == NULL) {
return LORAWAN_STATUS_PARAMETER_INVALID;
@ -1887,7 +1897,7 @@ lorawan_status_t LoRaMac::multicast_channel_unlink(
return LORAWAN_STATUS_OK;
}
void LoRaMac::bind_radio_driver(LoRaRadio& radio)
void LoRaMac::bind_radio_driver(LoRaRadio &radio)
{
_lora_phy.set_radio_instance(radio);
}
@ -1898,7 +1908,7 @@ void LoRaMac::bind_radio_driver(LoRaRadio& radio)
**************************************************************************/
lorawan_status_t LoRaMac::mlme_request( loramac_mlme_req_t *mlmeRequest )
lorawan_status_t LoRaMac::mlme_request(loramac_mlme_req_t *mlmeRequest)
{
if (LORAMAC_IDLE != _params.mac_state) {
return LORAWAN_STATUS_BUSY;
@ -1913,16 +1923,16 @@ lorawan_status_t LoRaMac::mlme_request( loramac_mlme_req_t *mlmeRequest )
if (MLME_TXCW == mlmeRequest->type) {
set_tx_continuous_wave(_params.channel, _params.sys_params.channel_data_rate, _params.sys_params.channel_tx_power,
_params.sys_params.max_eirp, _params.sys_params.antenna_gain, mlmeRequest->cw_tx_mode.timeout);
_params.sys_params.max_eirp, _params.sys_params.antenna_gain, mlmeRequest->cw_tx_mode.timeout);
_lora_time.start(_params.timers.mac_state_check_timer,
MAC_STATE_CHECK_TIMEOUT);
MAC_STATE_CHECK_TIMEOUT);
_params.mac_state |= LORAMAC_TX_RUNNING;
status = LORAWAN_STATUS_OK;
} else if (MLME_TXCW_1 == mlmeRequest->type) {
set_tx_continuous_wave(0, 0, mlmeRequest->cw_tx_mode.power, 0, 0, mlmeRequest->cw_tx_mode.timeout);
_lora_time.start(_params.timers.mac_state_check_timer,
MAC_STATE_CHECK_TIMEOUT);
MAC_STATE_CHECK_TIMEOUT);
_params.mac_state |= LORAMAC_TX_RUNNING;
status = LORAWAN_STATUS_OK;
@ -1933,7 +1943,6 @@ lorawan_status_t LoRaMac::mlme_request( loramac_mlme_req_t *mlmeRequest )
_params.flags.bits.mlme_req = 0;
}
return status;
}
@ -1972,7 +1981,7 @@ lorawan_status_t LoRaMac::test_request( loramac_compliance_test_req_t *mcpsReque
break;
}
default:
return LORAWAN_STATUS_PARAMETER_INVALID;
return LORAWAN_STATUS_PARAMETER_INVALID;
}
// Filter fPorts
@ -1990,7 +1999,7 @@ lorawan_status_t LoRaMac::test_request( loramac_compliance_test_req_t *mcpsReque
}
lorawan_status_t status = send(&machdr, mcpsRequest->fport, mcpsRequest->f_buffer,
mcpsRequest->f_buffer_size);
mcpsRequest->f_buffer_size);
if (status == LORAWAN_STATUS_OK) {
_mcps_confirmation.req_type = mcpsRequest->type;
_params.flags.bits.mcps_req = 1;
@ -2007,7 +2016,7 @@ lorawan_status_t LoRaMac::LoRaMacSetTxTimer( uint32_t TxDutyCycleTime )
return LORAWAN_STATUS_OK;
}
lorawan_status_t LoRaMac::LoRaMacStopTxTimer( )
lorawan_status_t LoRaMac::LoRaMacStopTxTimer( )
{
_lora_time.stop(tx_next_packet_timer);
return LORAWAN_STATUS_OK;

View File

@ -135,7 +135,7 @@ public:
* \ref LORAWAN_STATUS_BUSY
* \ref LORAWAN_STATUS_PARAMETER_INVALID
*/
lorawan_status_t add_channel_plan(const lorawan_channelplan_t& plan);
lorawan_status_t add_channel_plan(const lorawan_channelplan_t &plan);
/**
* @brief Removes a channel plan from the system.
@ -166,7 +166,7 @@ public:
* \ref LORAWAN_STATUS_BUSY
* \ref LORAWAN_STATUS_PARAMETER_INVALID
*/
lorawan_status_t get_channel_plan(lorawan_channelplan_t& plan);
lorawan_status_t get_channel_plan(lorawan_channelplan_t &plan);
/**
* @brief Remove a given channel from the active plan.
@ -221,7 +221,7 @@ public:
* @param radio LoRaRadio object, i.e., the radio driver
*
*/
void bind_radio_driver(LoRaRadio& radio);
void bind_radio_driver(LoRaRadio &radio);
/**
* @brief Configures the events to trigger an MLME-Indication with
@ -333,7 +333,7 @@ public:
* @param num_retries Number of retries for a confirmed type message
* @return The number of bytes prepared for sending.
*/
int16_t prepare_ongoing_tx(const uint8_t port, const uint8_t* data,
int16_t prepare_ongoing_tx(const uint8_t port, const uint8_t *data,
uint16_t length, uint8_t flags, uint8_t num_retries);
/**
@ -353,7 +353,7 @@ public:
* @param device_class Device class to use.
* @param ack_expiry_handler callback function to inform about ack expiry
*/
void set_device_class(const device_class_t& device_class,
void set_device_class(const device_class_t &device_class,
mbed::Callback<void(void)>ack_expiry_handler);
/**
@ -391,7 +391,7 @@ public:
/**
* MAC operations upon reception
*/
void on_radio_rx_done(const uint8_t* const payload, uint16_t size,
void on_radio_rx_done(const uint8_t *const payload, uint16_t size,
int16_t rssi, int8_t snr);
/**
@ -460,8 +460,16 @@ public:
* the stack thread safe.
*/
#if MBED_CONF_RTOS_PRESENT
void lock(void) { osStatus status = _mutex.lock(); MBED_ASSERT(status == osOK); }
void unlock(void) { osStatus status = _mutex.unlock(); MBED_ASSERT(status == osOK); }
void lock(void)
{
osStatus status = _mutex.lock();
MBED_ASSERT(status == osOK);
}
void unlock(void)
{
osStatus status = _mutex.unlock();
MBED_ASSERT(status == osOK);
}
#else
void lock(void) { }
void unlock(void) { }
@ -511,10 +519,10 @@ private:
* payload
*/
void extract_data_and_mac_commands(const uint8_t *payload, uint16_t size,
uint8_t fopts_len, uint8_t *nwk_skey,
uint8_t *app_skey, uint32_t address,
uint32_t downlink_frame_counter,
int16_t rssi, int8_t snr);
uint8_t fopts_len, uint8_t *nwk_skey,
uint8_t *app_skey, uint32_t address,
uint32_t downlink_frame_counter,
int16_t rssi, int8_t snr);
/**
* Decrypts and extracts MAC commands from the received encrypted
* payload if there is no data

View File

@ -65,261 +65,6 @@
*/
#define LC( channelIndex ) ( uint16_t )( 1 << ( channelIndex - 1 ) )
/*!
* Region | SF
* ------------ | :-----:
* AS923 | SF12 - BW125
* AU915 | SF10 - BW125
* CN470 | SF12 - BW125
* CN779 | SF12 - BW125
* EU433 | SF12 - BW125
* EU868 | SF12 - BW125
* IN865 | SF12 - BW125
* KR920 | SF12 - BW125
* US915 | SF10 - BW125
* US915_HYBRID | SF10 - BW125
*/
#define DR_0 0
/*!
* Region | SF
* ------------ | :-----:
* AS923 | SF11 - BW125
* AU915 | SF9 - BW125
* CN470 | SF11 - BW125
* CN779 | SF11 - BW125
* EU433 | SF11 - BW125
* EU868 | SF11 - BW125
* IN865 | SF11 - BW125
* KR920 | SF11 - BW125
* US915 | SF9 - BW125
* US915_HYBRID | SF9 - BW125
*/
#define DR_1 1
/*!
* Region | SF
* ------------ | :-----:
* AS923 | SF10 - BW125
* AU915 | SF8 - BW125
* CN470 | SF10 - BW125
* CN779 | SF10 - BW125
* EU433 | SF10 - BW125
* EU868 | SF10 - BW125
* IN865 | SF10 - BW125
* KR920 | SF10 - BW125
* US915 | SF8 - BW125
* US915_HYBRID | SF8 - BW125
*/
#define DR_2 2
/*!
* Region | SF
* ------------ | :-----:
* AS923 | SF9 - BW125
* AU915 | SF7 - BW125
* CN470 | SF9 - BW125
* CN779 | SF9 - BW125
* EU433 | SF9 - BW125
* EU868 | SF9 - BW125
* IN865 | SF9 - BW125
* KR920 | SF9 - BW125
* US915 | SF7 - BW125
* US915_HYBRID | SF7 - BW125
*/
#define DR_3 3
/*!
* Region | SF
* ------------ | :-----:
* AS923 | SF8 - BW125
* AU915 | SF8 - BW500
* CN470 | SF8 - BW125
* CN779 | SF8 - BW125
* EU433 | SF8 - BW125
* EU868 | SF8 - BW125
* IN865 | SF8 - BW125
* KR920 | SF8 - BW125
* US915 | SF8 - BW500
* US915_HYBRID | SF8 - BW500
*/
#define DR_4 4
/*!
* Region | SF
* ------------ | :-----:
* AS923 | SF7 - BW125
* AU915 | RFU
* CN470 | SF7 - BW125
* CN779 | SF7 - BW125
* EU433 | SF7 - BW125
* EU868 | SF7 - BW125
* IN865 | SF7 - BW125
* KR920 | SF7 - BW125
* US915 | RFU
* US915_HYBRID | RFU
*/
#define DR_5 5
/*!
* Region | SF
* ------------ | :-----:
* AS923 | SF7 - BW250
* AU915 | RFU
* CN470 | SF12 - BW125
* CN779 | SF7 - BW250
* EU433 | SF7 - BW250
* EU868 | SF7 - BW250
* IN865 | SF7 - BW250
* KR920 | RFU
* US915 | RFU
* US915_HYBRID | RFU
*/
#define DR_6 6
/*!
* Region | SF
* ------------ | :-----:
* AS923 | FSK
* AU915 | RFU
* CN470 | SF12 - BW125
* CN779 | FSK
* EU433 | FSK
* EU868 | FSK
* IN865 | FSK
* KR920 | RFU
* US915 | RFU
* US915_HYBRID | RFU
*/
#define DR_7 7
/*!
* Region | SF
* ------------ | :-----:
* AS923 | RFU
* AU915 | SF12 - BW500
* CN470 | RFU
* CN779 | RFU
* EU433 | RFU
* EU868 | RFU
* IN865 | RFU
* KR920 | RFU
* US915 | SF12 - BW500
* US915_HYBRID | SF12 - BW500
*/
#define DR_8 8
/*!
* Region | SF
* ------------ | :-----:
* AS923 | RFU
* AU915 | SF11 - BW500
* CN470 | RFU
* CN779 | RFU
* EU433 | RFU
* EU868 | RFU
* IN865 | RFU
* KR920 | RFU
* US915 | SF11 - BW500
* US915_HYBRID | SF11 - BW500
*/
#define DR_9 9
/*!
* Region | SF
* ------------ | :-----:
* AS923 | RFU
* AU915 | SF10 - BW500
* CN470 | RFU
* CN779 | RFU
* EU433 | RFU
* EU868 | RFU
* IN865 | RFU
* KR920 | RFU
* US915 | SF10 - BW500
* US915_HYBRID | SF10 - BW500
*/
#define DR_10 10
/*!
* Region | SF
* ------------ | :-----:
* AS923 | RFU
* AU915 | SF9 - BW500
* CN470 | RFU
* CN779 | RFU
* EU433 | RFU
* EU868 | RFU
* IN865 | RFU
* KR920 | RFU
* US915 | SF9 - BW500
* US915_HYBRID | SF9 - BW500
*/
#define DR_11 11
/*!
* Region | SF
* ------------ | :-----:
* AS923 | RFU
* AU915 | SF8 - BW500
* CN470 | RFU
* CN779 | RFU
* EU433 | RFU
* EU868 | RFU
* IN865 | RFU
* KR920 | RFU
* US915 | SF8 - BW500
* US915_HYBRID | SF8 - BW500
*/
#define DR_12 12
/*!
* Region | SF
* ------------ | :-----:
* AS923 | RFU
* AU915 | SF7 - BW500
* CN470 | RFU
* CN779 | RFU
* EU433 | RFU
* EU868 | RFU
* IN865 | RFU
* KR920 | RFU
* US915 | SF7 - BW500
* US915_HYBRID | SF7 - BW500
*/
#define DR_13 13
/*!
* Region | SF
* ------------ | :-----:
* AS923 | RFU
* AU915 | RFU
* CN470 | RFU
* CN779 | RFU
* EU433 | RFU
* EU868 | RFU
* IN865 | RFU
* KR920 | RFU
* US915 | RFU
* US915_HYBRID | RFU
*/
#define DR_14 14
/*!
* Region | SF
* ------------ | :-----:
* AS923 | RFU
* AU915 | RFU
* CN470 | RFU
* CN779 | RFU
* EU433 | RFU
* EU868 | RFU
* IN865 | RFU
* KR920 | RFU
* US915 | RFU
* US915_HYBRID | RFU
*/
#define DR_15 15
@ -527,8 +272,7 @@
/**
* TX configuration parameters.
*/
typedef struct
{
typedef struct {
/**
* The TX channel.
*/
@ -559,8 +303,7 @@ typedef struct
* This structure contains parameters for ADR request coming from
* network server.
*/
typedef struct
{
typedef struct {
/*!
* A pointer to the payload containing the MAC commands.
*/
@ -594,8 +337,7 @@ typedef struct
/**
* Structure containing data for local ADR settings
*/
typedef struct link_adr_params_s
{
typedef struct link_adr_params_s {
/**
* The number of repetitions.
*/
@ -622,8 +364,7 @@ typedef struct link_adr_params_s
* Structure used to store ADR values received from network
* for verification (legality) purposes.
*/
typedef struct verify_adr_params_s
{
typedef struct verify_adr_params_s {
/*!
* The current status of the AdrLinkRequest.
*/
@ -667,8 +408,7 @@ typedef struct verify_adr_params_s
* Contains rx parameter setup request coming from
* network server.
*/
typedef struct rx_param_setup_req_s
{
typedef struct rx_param_setup_req_s {
/**
* The datarate to set up.
*/
@ -686,8 +426,7 @@ typedef struct rx_param_setup_req_s
/**
* The parameter structure for the function RegionNextChannel.
*/
typedef struct channel_selection_params_s
{
typedef struct channel_selection_params_s {
/**
* The aggregated time-off time.
*/
@ -713,8 +452,7 @@ typedef struct channel_selection_params_s
/*!
* The parameter structure for the function RegionContinuousWave.
*/
typedef struct continuous_wave_mode_params_s
{
typedef struct continuous_wave_mode_params_s {
/*!
* The current channel index.
*/

View File

@ -204,7 +204,7 @@ typedef struct lorawan_connect {
*
*/
typedef enum lora_events {
CONNECTED=0,
CONNECTED = 0,
DISCONNECTED,
TX_DONE,
TX_TIMEOUT,
@ -244,26 +244,26 @@ typedef enum lora_events {
* the stack about the battery level by calling a function provided
* by the upper layers.
*/
typedef struct {
/**
* Mandatory. Event Callback must be provided
*/
mbed::Callback<void(lorawan_event_t)> events;
typedef struct {
/**
* Mandatory. Event Callback must be provided
*/
mbed::Callback<void(lorawan_event_t)> events;
/**
* Optional
*/
mbed::Callback<void(uint8_t, uint8_t)> link_check_resp;
/**
* Optional
*/
mbed::Callback<void(uint8_t, uint8_t)> link_check_resp;
/**
* Battery level return value must follow the specification
* for DevStatusAns MAC command:
*
* 0 The end-device is connected to an external power source
* 1 - 254 The battery level, 1 being at minimum and 254 being at maximum
* 255 The end-device was not able to measure the battery level.
*/
mbed::Callback<uint8_t(void)> battery_level;
/**
* Battery level return value must follow the specification
* for DevStatusAns MAC command:
*
* 0 The end-device is connected to an external power source
* 1 - 254 The battery level, 1 being at minimum and 254 being at maximum
* 255 The end-device was not able to measure the battery level.
*/
mbed::Callback<uint8_t(void)> battery_level;
} lorawan_app_callbacks_t;
/**
@ -275,7 +275,7 @@ typedef union {
/**
* Byte-access to the bits.
*/
int8_t value;
uint8_t value;
/**
* The structure to store the minimum and the maximum datarate.
*/
@ -288,7 +288,7 @@ typedef union {
* The allowed ranges are region-specific.
* Please refer to \ref DR_0 to \ref DR_15 for details.
*/
int8_t min :4;
uint8_t min : 4;
/**
* The maximum data rate.
*
@ -297,7 +297,7 @@ typedef union {
* The allowed ranges are region-specific.
* Please refer to \ref DR_0 to \ref DR_15 for details.
*/
int8_t max :4;
uint8_t max : 4;
} fields;
} dr_range_t;
@ -346,6 +346,271 @@ typedef struct lora_channelplan {
loramac_channel_t *channels;
} lorawan_channelplan_t;
/*!
* Region | SF
* ------------ | :-----:
* AS923 | SF12 - BW125
* AU915 | SF10 - BW125
* CN470 | SF12 - BW125
* CN779 | SF12 - BW125
* EU433 | SF12 - BW125
* EU868 | SF12 - BW125
* IN865 | SF12 - BW125
* KR920 | SF12 - BW125
* US915 | SF10 - BW125
* US915_HYBRID | SF10 - BW125
*/
#define DR_0 0
/*!
* Region | SF
* ------------ | :-----:
* AS923 | SF11 - BW125
* AU915 | SF9 - BW125
* CN470 | SF11 - BW125
* CN779 | SF11 - BW125
* EU433 | SF11 - BW125
* EU868 | SF11 - BW125
* IN865 | SF11 - BW125
* KR920 | SF11 - BW125
* US915 | SF9 - BW125
* US915_HYBRID | SF9 - BW125
*/
#define DR_1 1
/*!
* Region | SF
* ------------ | :-----:
* AS923 | SF10 - BW125
* AU915 | SF8 - BW125
* CN470 | SF10 - BW125
* CN779 | SF10 - BW125
* EU433 | SF10 - BW125
* EU868 | SF10 - BW125
* IN865 | SF10 - BW125
* KR920 | SF10 - BW125
* US915 | SF8 - BW125
* US915_HYBRID | SF8 - BW125
*/
#define DR_2 2
/*!
* Region | SF
* ------------ | :-----:
* AS923 | SF9 - BW125
* AU915 | SF7 - BW125
* CN470 | SF9 - BW125
* CN779 | SF9 - BW125
* EU433 | SF9 - BW125
* EU868 | SF9 - BW125
* IN865 | SF9 - BW125
* KR920 | SF9 - BW125
* US915 | SF7 - BW125
* US915_HYBRID | SF7 - BW125
*/
#define DR_3 3
/*!
* Region | SF
* ------------ | :-----:
* AS923 | SF8 - BW125
* AU915 | SF8 - BW500
* CN470 | SF8 - BW125
* CN779 | SF8 - BW125
* EU433 | SF8 - BW125
* EU868 | SF8 - BW125
* IN865 | SF8 - BW125
* KR920 | SF8 - BW125
* US915 | SF8 - BW500
* US915_HYBRID | SF8 - BW500
*/
#define DR_4 4
/*!
* Region | SF
* ------------ | :-----:
* AS923 | SF7 - BW125
* AU915 | RFU
* CN470 | SF7 - BW125
* CN779 | SF7 - BW125
* EU433 | SF7 - BW125
* EU868 | SF7 - BW125
* IN865 | SF7 - BW125
* KR920 | SF7 - BW125
* US915 | RFU
* US915_HYBRID | RFU
*/
#define DR_5 5
/*!
* Region | SF
* ------------ | :-----:
* AS923 | SF7 - BW250
* AU915 | RFU
* CN470 | SF12 - BW125
* CN779 | SF7 - BW250
* EU433 | SF7 - BW250
* EU868 | SF7 - BW250
* IN865 | SF7 - BW250
* KR920 | RFU
* US915 | RFU
* US915_HYBRID | RFU
*/
#define DR_6 6
/*!
* Region | SF
* ------------ | :-----:
* AS923 | FSK
* AU915 | RFU
* CN470 | SF12 - BW125
* CN779 | FSK
* EU433 | FSK
* EU868 | FSK
* IN865 | FSK
* KR920 | RFU
* US915 | RFU
* US915_HYBRID | RFU
*/
#define DR_7 7
/*!
* Region | SF
* ------------ | :-----:
* AS923 | RFU
* AU915 | SF12 - BW500
* CN470 | RFU
* CN779 | RFU
* EU433 | RFU
* EU868 | RFU
* IN865 | RFU
* KR920 | RFU
* US915 | SF12 - BW500
* US915_HYBRID | SF12 - BW500
*/
#define DR_8 8
/*!
* Region | SF
* ------------ | :-----:
* AS923 | RFU
* AU915 | SF11 - BW500
* CN470 | RFU
* CN779 | RFU
* EU433 | RFU
* EU868 | RFU
* IN865 | RFU
* KR920 | RFU
* US915 | SF11 - BW500
* US915_HYBRID | SF11 - BW500
*/
#define DR_9 9
/*!
* Region | SF
* ------------ | :-----:
* AS923 | RFU
* AU915 | SF10 - BW500
* CN470 | RFU
* CN779 | RFU
* EU433 | RFU
* EU868 | RFU
* IN865 | RFU
* KR920 | RFU
* US915 | SF10 - BW500
* US915_HYBRID | SF10 - BW500
*/
#define DR_10 10
/*!
* Region | SF
* ------------ | :-----:
* AS923 | RFU
* AU915 | SF9 - BW500
* CN470 | RFU
* CN779 | RFU
* EU433 | RFU
* EU868 | RFU
* IN865 | RFU
* KR920 | RFU
* US915 | SF9 - BW500
* US915_HYBRID | SF9 - BW500
*/
#define DR_11 11
/*!
* Region | SF
* ------------ | :-----:
* AS923 | RFU
* AU915 | SF8 - BW500
* CN470 | RFU
* CN779 | RFU
* EU433 | RFU
* EU868 | RFU
* IN865 | RFU
* KR920 | RFU
* US915 | SF8 - BW500
* US915_HYBRID | SF8 - BW500
*/
#define DR_12 12
/*!
* Region | SF
* ------------ | :-----:
* AS923 | RFU
* AU915 | SF7 - BW500
* CN470 | RFU
* CN779 | RFU
* EU433 | RFU
* EU868 | RFU
* IN865 | RFU
* KR920 | RFU
* US915 | SF7 - BW500
* US915_HYBRID | SF7 - BW500
*/
#define DR_13 13
/*!
* Region | SF
* ------------ | :-----:
* AS923 | RFU
* AU915 | RFU
* CN470 | RFU
* CN779 | RFU
* EU433 | RFU
* EU868 | RFU
* IN865 | RFU
* KR920 | RFU
* US915 | RFU
* US915_HYBRID | RFU
*/
#define DR_14 14
/*!
* Region | SF
* ------------ | :-----:
* AS923 | RFU
* AU915 | RFU
* CN470 | RFU
* CN779 | RFU
* EU433 | RFU
* EU868 | RFU
* IN865 | RFU
* KR920 | RFU
* US915 | RFU
* US915_HYBRID | RFU
*/
#define DR_15 15
/**
* Enumeration for LoRaWAN connection type.
*/
typedef enum lorawan_connect_type {
LORAWAN_CONNECTION_OTAA = 0, /**< Over The Air Activation */
LORAWAN_CONNECTION_ABP /**< Activation By Personalization */
} lorawan_connect_type_t;
/**
* Meta-data collection for a transmission
*/

View File

@ -431,20 +431,19 @@ typedef union {
/*!
* The structure containing single access to header bits.
*/
struct hdr_bits_s
{
struct hdr_bits_s {
/*!
* Major version.
*/
uint8_t major : 2;
uint8_t major : 2;
/*!
* RFU
*/
uint8_t RFU : 3;
uint8_t RFU : 3;
/*!
* Message type
*/
uint8_t mtype : 3;
uint8_t mtype : 3;
} bits;
} loramac_mhdr_t;
@ -461,28 +460,27 @@ typedef union {
/*!
* The structure containing single access to bits.
*/
struct ctrl_bits_s
{
struct ctrl_bits_s {
/*!
* Frame options length.
*/
uint8_t fopts_len : 4;
uint8_t fopts_len : 4;
/*!
* Frame pending bit.
*/
uint8_t fpending : 1;
uint8_t fpending : 1;
/*!
* Message acknowledge bit.
*/
uint8_t ack : 1;
uint8_t ack : 1;
/*!
* ADR acknowledgment request bit.
*/
uint8_t adr_ack_req : 1;
uint8_t adr_ack_req : 1;
/*!
* ADR control in the frame header.
*/
uint8_t adr : 1;
uint8_t adr : 1;
} bits;
} loramac_frame_ctrl_t;
@ -857,14 +855,6 @@ typedef enum device_states {
DEVICE_STATE_SHUTDOWN
} device_states_t;
/**
* Enumeration for LoRaWAN connection type.
*/
typedef enum lorawan_connect_type {
LORAWAN_CONNECTION_OTAA = 0, /**< Over The Air Activation */
LORAWAN_CONNECTION_ABP /**< Activation By Personalization */
} lorawan_connect_type_t;
/**
* Stack level TX message structure
*/
@ -1023,7 +1013,7 @@ typedef struct {
/*!
* The RX window timeout
*/
uint32_t window_timeout;
uint32_t window_timeout;
/*!
* The RX window offset
*/
@ -1085,39 +1075,39 @@ typedef struct {
} loramac_keys;
typedef struct {
/*!
* Aggregated duty cycle management
*/
lorawan_time_t aggregated_last_tx_time;
lorawan_time_t aggregated_timeoff;
/*!
* Aggregated duty cycle management
*/
lorawan_time_t aggregated_last_tx_time;
lorawan_time_t aggregated_timeoff;
/*!
* Stores the time at LoRaMac initialization.
*
* \remark Used for the BACKOFF_DC computation.
*/
lorawan_time_t mac_init_time;
/*!
* Stores the time at LoRaMac initialization.
*
* \remark Used for the BACKOFF_DC computation.
*/
lorawan_time_t mac_init_time;
/*!
* Last transmission time on air
*/
lorawan_time_t tx_toa;
/*!
* Last transmission time on air
*/
lorawan_time_t tx_toa;
/*!
* LoRaMac duty cycle backoff timer
*/
timer_event_t backoff_timer;
/*!
* LoRaMac duty cycle backoff timer
*/
timer_event_t backoff_timer;
/*!
* LoRaMac reception windows timers
*/
timer_event_t rx_window1_timer;
timer_event_t rx_window2_timer;
/*!
* LoRaMac reception windows timers
*/
timer_event_t rx_window1_timer;
timer_event_t rx_window2_timer;
/*!
* Acknowledge timeout timer. Used for packet retransmissions.
*/
timer_event_t ack_timeout_timer;
/*!
* Acknowledge timeout timer. Used for packet retransmissions.
*/
timer_event_t ack_timeout_timer;
} lorawan_timers;
@ -1126,7 +1116,7 @@ typedef struct {
/*!
* Holds the type of current Receive window slot
*/
rx_slot_t rx_slot;
rx_slot_t rx_slot;
/*!
* Indicates if the node is connected to a private or public network