Skip to content

Stack refactoring #6411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Apr 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a294aa0
LoRa: LoRaWANInterface refactored.
Mar 12, 2018
339306e
Ensure DR_6 cannot be selected for IN865 region
Feb 15, 2018
e206c1e
Changed RegionNextChannel function in order to return LoRaMacStatus_t…
Feb 16, 2018
6114f2b
Fix an issue with sequence calls.
Feb 16, 2018
fc1696b
Do only set the MacDone if the MAC is not in class c
Feb 16, 2018
c1ea418
Fix rx slot handling
Feb 16, 2018
256a3a5
Fix calculation of the aggregated time-off.
Feb 16, 2018
591bc7d
Add the possibility to set the default antenna gain.
Feb 16, 2018
a9e1076
Bug fix in RX timeout and RX error handling for class c nodes.
Feb 19, 2018
e097429
Remove unused is_fPort_allowed method
Feb 19, 2018
6c165e0
Changed mcps confirmation ul_frequency to channel
Feb 19, 2018
e1fff2e
Update handling for functions OnRadioRxError and OnRadioRxTimout.
Feb 19, 2018
65b2dbc
Update DevStatusAnd format
Feb 19, 2018
4aba343
Change minimum required channels from 6 to 2 (US915Hybrid)
Feb 19, 2018
a26fca8
Add set_device_class API to change active device class
Feb 20, 2018
32075b9
Fix reception of class C messages
Feb 22, 2018
c6eee4f
Simplify check for pending bit
Feb 28, 2018
fe225a8
Remove redundant event from timer callbacks
Mar 1, 2018
b63c98e
LoRa: LoRaPHY dependency removed from LoRaMacStack
Mar 15, 2018
6b54478
LoRaWANStack is made independent of MAC sublayers
Mar 16, 2018
489eecf
LoRa: LoRaMAC class refactored
Mar 16, 2018
dc98228
LoRa: Struct cleanups
Mar 20, 2018
cbdeb7d
LoRa: Added API break warnings for lorawan_channelplan_t struct and i…
Mar 20, 2018
c198357
Fix compilance test compilation
Mar 21, 2018
fd9a6af
Merge pull request #3 from AnttiKauppila/fix_compliance_test
Mar 22, 2018
10ad173
LoRa: Small fixes
Apr 3, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions features/lorawan/LoRaWANBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,18 @@ class LoRaWANBase {
* callbacks.
*/
virtual lorawan_status_t add_app_callbacks(lorawan_app_callbacks_t *callbacks) = 0;

/** Change device class
*
* Change current device class.
*
* @param device_class The device class
*
* @return LORAWAN_STATUS_OK on success,
* LORAWAN_STATUS_UNSUPPORTED is requested class is not supported,
* or other negative error code if request failed.
*/
virtual lorawan_status_t set_device_class(device_class_t device_class) = 0;
};

#endif /* LORAWAN_BASE_H_ */
103 changes: 14 additions & 89 deletions features/lorawan/LoRaWANInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,9 @@ inline LoRaWANStack& stk_obj()
return LoRaWANStack::get_lorawan_stack();
}

LoRaWANInterface::LoRaWANInterface(LoRaRadio& radio) : _link_check_requested(false)
LoRaWANInterface::LoRaWANInterface(LoRaRadio& radio)
{
// Pass mac_handlers to radio to the radio driver after
// binding radio driver to PHY layer
radio_events_t *events = stk_obj().bind_radio_driver(radio);
radio.lock();
radio.init_radio(events);
radio.unlock();
stk_obj().bind_radio_driver(radio);
}

LoRaWANInterface::~LoRaWANInterface()
Expand All @@ -44,71 +39,17 @@ LoRaWANInterface::~LoRaWANInterface()

lorawan_status_t LoRaWANInterface::initialize(EventQueue *queue)
{
if(!queue) {
return LORAWAN_STATUS_PARAMETER_INVALID;
}

return stk_obj().initialize_mac_layer(queue);
}

lorawan_status_t LoRaWANInterface::connect()
{
// connection attempt without parameters.
// System tries to look for configuration in mbed_lib.json that can be
// overridden by mbed_app.json. However, if none of the json files are
// available (highly unlikely), we still fallback to some default parameters.
// Check lorawan_data_structure for fallback defaults.

lorawan_connect_t connection_params;

if (MBED_CONF_LORA_OVER_THE_AIR_ACTIVATION) {
static uint8_t dev_eui[] = MBED_CONF_LORA_DEVICE_EUI;
static uint8_t app_eui[] = MBED_CONF_LORA_APPLICATION_EUI;
static uint8_t app_key[] = MBED_CONF_LORA_APPLICATION_KEY;
/**
*
* OTAA join
*/
connection_params.connect_type = LORAWAN_CONNECTION_OTAA;
connection_params.connection_u.otaa.app_eui = app_eui;
connection_params.connection_u.otaa.dev_eui = dev_eui;
connection_params.connection_u.otaa.app_key = app_key;
connection_params.connection_u.otaa.nb_trials = MBED_CONF_LORA_NB_TRIALS;

return connect(connection_params);
} else {
static uint8_t nwk_skey[] = MBED_CONF_LORA_NWKSKEY;
static uint8_t app_skey[] = MBED_CONF_LORA_APPSKEY;
static uint32_t dev_addr = MBED_CONF_LORA_DEVICE_ADDRESS;
static uint32_t nwk_id = (MBED_CONF_LORA_DEVICE_ADDRESS & LORAWAN_NETWORK_ID_MASK);

/**
*
* ABP connection
*/
connection_params.connect_type = LORAWAN_CONNECTION_ABP;
connection_params.connection_u.abp.nwk_id = nwk_id;
connection_params.connection_u.abp.dev_addr = dev_addr;
connection_params.connection_u.abp.nwk_skey = nwk_skey;
connection_params.connection_u.abp.app_skey = app_skey;

return connect(connection_params);
}
return stk_obj().connect();
}

lorawan_status_t LoRaWANInterface::connect(const lorawan_connect_t &connect)
{
lorawan_status_t mac_status;

if (connect.connect_type == LORAWAN_CONNECTION_OTAA) {
mac_status = stk_obj().join_request_by_otaa(connect);
} else if (connect.connect_type == LORAWAN_CONNECTION_ABP) {
mac_status = stk_obj().activation_by_personalization(connect);
} else {
return LORAWAN_STATUS_PARAMETER_INVALID;
}

return mac_status;
return stk_obj().connect(connect);
}

lorawan_status_t LoRaWANInterface::disconnect()
Expand All @@ -118,13 +59,12 @@ lorawan_status_t LoRaWANInterface::disconnect()

lorawan_status_t LoRaWANInterface::add_link_check_request()
{
_link_check_requested = true;
return stk_obj().set_link_check_request();
}

void LoRaWANInterface::remove_link_check_request()
{
_link_check_requested = false;
stk_obj().remove_link_check_request();
}

lorawan_status_t LoRaWANInterface::set_datarate(uint8_t data_rate)
Expand Down Expand Up @@ -170,37 +110,22 @@ lorawan_status_t LoRaWANInterface::remove_channel_plan()
int16_t LoRaWANInterface::send(uint8_t port, const uint8_t* data,
uint16_t length, int flags)
{
if (_link_check_requested) {
// add a link check request with normal data, until the application
// explicitly removes it.
add_link_check_request();
}
return stk_obj().handle_tx(port, data, length, flags);

if (data) {
return stk_obj().handle_tx(port, data, length, flags);
} else {
return LORAWAN_STATUS_PARAMETER_INVALID;
}
}

int16_t LoRaWANInterface::receive(uint8_t port, uint8_t* data, uint16_t length,
int flags)
{
if (data && length > 0) {
return stk_obj().handle_rx(port, data, length, flags);
} else {
return LORAWAN_STATUS_PARAMETER_INVALID;
}
return stk_obj().handle_rx(port, data, length, flags);
}

lorawan_status_t LoRaWANInterface::add_app_callbacks(lorawan_app_callbacks_t *callbacks)
{

if (!callbacks || !callbacks->events) {
// Event Callback is mandatory
return LORAWAN_STATUS_PARAMETER_INVALID;
}
{
return stk_obj().set_lora_callbacks(callbacks);
}

stk_obj().set_lora_callbacks(callbacks);
return LORAWAN_STATUS_OK;
}
lorawan_status_t LoRaWANInterface::set_device_class(const device_class_t device_class)
Copy link
Contributor

@kjbracey kjbracey Apr 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(You could keep the const here though, meaning "I don't change device_class after function entry" - just doesn't need to be in the prototype).

{
return stk_obj().set_device_class(device_class);
}
13 changes: 11 additions & 2 deletions features/lorawan/LoRaWANInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,17 @@ class LoRaWANInterface: public LoRaWANBase {
*/
virtual lorawan_status_t add_app_callbacks(lorawan_app_callbacks_t *callbacks);

private:
bool _link_check_requested;
/** Change device class
*
* Change current device class.
*
* @param device_class The device class
*
* @return LORAWAN_STATUS_OK on success,
* LORAWAN_STATUS_UNSUPPORTED is requested class is not supported,
* or other negative error code if request failed.
*/
virtual lorawan_status_t set_device_class(const device_class_t device_class);
};

#endif /* LORAWANINTERFACE_H_ */
Loading