Skip to content

Commit aa0c61b

Browse files
author
Kimmo Vaisanen
committed
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.
1 parent 9e74fa5 commit aa0c61b

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

features/lorawan/LoRaWANBase.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ class LoRaWANBase {
310310
*
311311
* @return The number of bytes sent, or a negative error code on failure:
312312
* LORAWAN_STATUS_NOT_INITIALIZED if system is not initialized with initialize(),
313+
* LORAWAN_STATUS_NO_ACTIVE_SESSIONS if connection is not open,
313314
* LORAWAN_STATUS_WOULD_BLOCK if another TX is ongoing,
314315
* LORAWAN_STATUS_PORT_INVALID if trying to send to an invalid port (e.g. to 0)
315316
* LORAWAN_STATUS_PARAMETER_INVALID if NULL data pointer is given or flags are invalid.
@@ -345,6 +346,7 @@ class LoRaWANBase {
345346
* i) 0 if there is nothing else to read.
346347
* ii) Number of bytes written to user buffer.
347348
* iii) A negative error code on failure:
349+
* LORAWAN_STATUS_NOT_INITIALIZED if system is not initialized with initialize(),
348350
* LORAWAN_STATUS_NO_ACTIVE_SESSIONS if connection is not open,
349351
* LORAWAN_STATUS_WOULD_BLOCK if there is nothing available to read at the moment,
350352
* LORAWAN_STATUS_PARAMETER_INVALID if NULL data or length is given,
@@ -370,6 +372,7 @@ class LoRaWANBase {
370372
* i) 0 if there is nothing else to read.
371373
* ii) Number of bytes written to user buffer.
372374
* iii) A negative error code on failure:
375+
* LORAWAN_STATUS_NOT_INITIALIZED if system is not initialized with initialize(),
373376
* LORAWAN_STATUS_NO_ACTIVE_SESSIONS if connection is not open,
374377
* LORAWAN_STATUS_PARAMETER_INVALID if NULL data or length is given,
375378
* LORAWAN_STATUS_WOULD_BLOCK if there is nothing available to read at the moment.

features/lorawan/LoRaWANStack.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,10 @@ int16_t LoRaWANStack::handle_tx(const uint8_t port, const uint8_t *data,
296296
uint16_t length, uint8_t flags,
297297
bool null_allowed, bool allow_port_0)
298298
{
299+
if (_device_current_state == DEVICE_STATE_NOT_INITIALIZED) {
300+
return LORAWAN_STATUS_NOT_INITIALIZED;
301+
}
302+
299303
if (!null_allowed && !data) {
300304
return LORAWAN_STATUS_PARAMETER_INVALID;
301305
}
@@ -356,6 +360,10 @@ int16_t LoRaWANStack::handle_tx(const uint8_t port, const uint8_t *data,
356360

357361
int16_t LoRaWANStack::handle_rx(uint8_t *data, uint16_t length, uint8_t &port, int &flags, bool validate_params)
358362
{
363+
if (_device_current_state == DEVICE_STATE_NOT_INITIALIZED) {
364+
return LORAWAN_STATUS_NOT_INITIALIZED;
365+
}
366+
359367
if (!_lw_session.active) {
360368
return LORAWAN_STATUS_NO_ACTIVE_SESSIONS;
361369
}

0 commit comments

Comments
 (0)