Lora: send and receive methods return LORAWAN_STATUS_NOT_INITIALIZED if not initialized

In order have a consistent return value for all methods in case of system is uninitialized
now also send and receive methods can return LORAWAN_STATUS_NOT_INITIALIZED.
pull/7719/head
Kimmo Vaisanen 2018-08-14 10:00:24 +03:00
parent 9e74fa5072
commit aa0c61b2b2
2 changed files with 11 additions and 0 deletions

View File

@ -310,6 +310,7 @@ public:
*
* @return The number of bytes sent, or a negative error code on failure:
* LORAWAN_STATUS_NOT_INITIALIZED if system is not initialized with initialize(),
* LORAWAN_STATUS_NO_ACTIVE_SESSIONS if connection is not open,
* LORAWAN_STATUS_WOULD_BLOCK if another TX is ongoing,
* LORAWAN_STATUS_PORT_INVALID if trying to send to an invalid port (e.g. to 0)
* LORAWAN_STATUS_PARAMETER_INVALID if NULL data pointer is given or flags are invalid.
@ -345,6 +346,7 @@ public:
* i) 0 if there is nothing else to read.
* ii) Number of bytes written to user buffer.
* iii) A negative error code on failure:
* LORAWAN_STATUS_NOT_INITIALIZED if system is not initialized with initialize(),
* LORAWAN_STATUS_NO_ACTIVE_SESSIONS if connection is not open,
* LORAWAN_STATUS_WOULD_BLOCK if there is nothing available to read at the moment,
* LORAWAN_STATUS_PARAMETER_INVALID if NULL data or length is given,
@ -370,6 +372,7 @@ public:
* i) 0 if there is nothing else to read.
* ii) Number of bytes written to user buffer.
* iii) A negative error code on failure:
* LORAWAN_STATUS_NOT_INITIALIZED if system is not initialized with initialize(),
* LORAWAN_STATUS_NO_ACTIVE_SESSIONS if connection is not open,
* LORAWAN_STATUS_PARAMETER_INVALID if NULL data or length is given,
* LORAWAN_STATUS_WOULD_BLOCK if there is nothing available to read at the moment.

View File

@ -296,6 +296,10 @@ 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)
{
if (_device_current_state == DEVICE_STATE_NOT_INITIALIZED) {
return LORAWAN_STATUS_NOT_INITIALIZED;
}
if (!null_allowed && !data) {
return LORAWAN_STATUS_PARAMETER_INVALID;
}
@ -356,6 +360,10 @@ int16_t LoRaWANStack::handle_tx(const uint8_t port, const uint8_t *data,
int16_t LoRaWANStack::handle_rx(uint8_t *data, uint16_t length, uint8_t &port, int &flags, bool validate_params)
{
if (_device_current_state == DEVICE_STATE_NOT_INITIALIZED) {
return LORAWAN_STATUS_NOT_INITIALIZED;
}
if (!_lw_session.active) {
return LORAWAN_STATUS_NO_ACTIVE_SESSIONS;
}