Add set_device_class API to change active device class

This API can be used to runtime change device class.

Please note that only class A and C are supported at the moment.
Trying to set class B will return LORAWAN_STATUS_UNSUPPORTED.

Fix set_device_class documentation

fix documentation
pull/6411/head
Kimmo Vaisanen 2018-02-20 15:48:08 +02:00 committed by Antti Kauppila
parent 4aba3434f4
commit a26fca8bf5
6 changed files with 53 additions and 3 deletions

View File

@ -331,6 +331,18 @@ public:
* 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(const device_class_t device_class) = 0;
};
#endif /* LORAWAN_BASE_H_ */

View File

@ -121,6 +121,11 @@ int16_t LoRaWANInterface::receive(uint8_t port, uint8_t* data, uint16_t length,
}
lorawan_status_t LoRaWANInterface::add_app_callbacks(lorawan_app_callbacks_t *callbacks)
{
return stk_obj().set_lora_callbacks(callbacks);
}
{
return stk_obj().set_lora_callbacks(callbacks);
}
lorawan_status_t LoRaWANInterface::set_device_class(const device_class_t device_class)
{
return stk_obj().set_device_class(device_class);
}

View File

@ -428,6 +428,18 @@ public:
* callbacks.
*/
virtual lorawan_status_t add_app_callbacks(lorawan_app_callbacks_t *callbacks);
/** 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_ */

View File

@ -1093,6 +1093,14 @@ lorawan_status_t LoRaWANStack::shutdown()
return lora_state_machine(DEVICE_STATE_SHUTDOWN);
}
lorawan_status_t LoRaWANStack::set_device_class(const device_class_t device_class)
{
loramac_mib_req_confirm_t mib_req;
mib_req.type = MIB_DEVICE_CLASS;
mib_req.param.dev_class = device_class;
return mib_set_request(&mib_req);
}
lorawan_status_t LoRaWANStack::lora_state_machine(device_states_t new_state)
{
loramac_mib_req_confirm_t mib_req;

View File

@ -360,6 +360,18 @@ public:
*/
lorawan_status_t shutdown();
/** 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.
*/
lorawan_status_t set_device_class(const device_class_t device_class);
private:
LoRaWANStack();
~LoRaWANStack();

View File

@ -59,6 +59,7 @@ lorawan_status_t LoRaMacMib::set_request(loramac_mib_req_confirm_t *mibSet,
break;
}
case CLASS_B: {
status = LORAWAN_STATUS_UNSUPPORTED;
break;
}
case CLASS_C: {