mirror of https://github.com/ARMmbed/mbed-os.git
Streamlining connect() API with posix like retcodes
For ABP: First call to connect() or connect(params) will return LORAWAN_STATUS_OK and a CONNECTED event will be sent. Any subsequent call will return LORAWAN_STATUS_ALREADY_CONNECTED (posix EISCONN) and no event is generated. FOR OTAA: First call to connect() or connect(params) will return LORAWAN_STATUS_CONNECT_IN_PROGRESS and a CONNECTED event will be sent whenever the JoinAccept is received. If the application calls connect again before receiving the CONNECTED event, LORAWAN_STATUS_BUSY will be returned. After the CONNECTED event is dispatched, any subsequent call to connect() or connect(params) API will be returned with LORWAN_STATUS_ALREADY_CONNECTED. No new parameters are accepted after the first call. The application must disconnect before making a connect() call with new parameters.pull/7445/head
parent
24db1c81ec
commit
f0844b4cfc
|
@ -41,14 +41,14 @@ public:
|
|||
* Connect by Over The Air Activation or Activation By Personalization.
|
||||
* The connection type is selected at the setup.
|
||||
*
|
||||
* @return For ABP: If everything goes well, LORAWAN_STATUS_OK is returned for first call followed by
|
||||
* a 'CONNECTED' event. Otherwise a negative error code.
|
||||
* Any subsequent call will return LORAWAN_STATUS_ALREADY_CONNECTED and no event follows.
|
||||
* @return For ABP: If everything goes well, LORAWAN_STATUS_OK is returned for first call followed by
|
||||
* a 'CONNECTED' event. Otherwise a negative error code is returned.
|
||||
* Any subsequent call will return LORAWAN_STATUS_ALREADY_CONNECTED and no event follows.
|
||||
*
|
||||
* For OTAA: When a JoinRequest is sent, LORAWAN_STATUS_CONNECT_IN_PROGRESS is returned followed by
|
||||
* a 'CONNECTED' event when the JoinAccept is received. Otherwise a negative error code
|
||||
* is returned. Any subsequent call will return LORAWAN_STATUS_ALREADY_CONNECTED and no
|
||||
* event follows.
|
||||
* For OTAA: When a JoinRequest is sent, LORAWAN_STATUS_CONNECT_IN_PROGRESS is returned for the first call.
|
||||
* Any subsequent call will return either LORAWAN_STATUS_BUSY (if the previous request for connection
|
||||
* is still underway) or LORAWAN_STATUS_ALREADY_CONNECTED (if a network was already joined successfully).
|
||||
* A 'CONNECTED' event is sent to the application when the JoinAccept is received.
|
||||
*/
|
||||
virtual lorawan_status_t connect() = 0;
|
||||
|
||||
|
@ -60,14 +60,14 @@ public:
|
|||
*
|
||||
* @param connect Options how end-device will connect to gateway
|
||||
*
|
||||
* @return For ABP: If everything goes well, LORAWAN_STATUS_OK is returned for first call followed by
|
||||
* a 'CONNECTED' event. Otherwise a negative error code.
|
||||
* Any subsequent call will return LORAWAN_STATUS_ALREADY_CONNECTED and no event follows.
|
||||
* @return For ABP: If everything goes well, LORAWAN_STATUS_OK is returned for first call followed by
|
||||
* a 'CONNECTED' event. Otherwise a negative error code is returned.
|
||||
* Any subsequent call will return LORAWAN_STATUS_ALREADY_CONNECTED and no event follows.
|
||||
*
|
||||
* For OTAA: When a JoinRequest is sent, LORAWAN_STATUS_CONNECT_IN_PROGRESS is returned followed by
|
||||
* a 'CONNECTED' event when the JoinAccept is received. Otherwise a negative error code
|
||||
* is returned. Any subsequent call will return LORAWAN_STATUS_ALREADY_CONNECTED and no
|
||||
* event follows.
|
||||
* For OTAA: When a JoinRequest is sent, LORAWAN_STATUS_CONNECT_IN_PROGRESS is returned for the first call.
|
||||
* Any subsequent call will return either LORAWAN_STATUS_BUSY (if the previous request for connection
|
||||
* is still underway) or LORAWAN_STATUS_ALREADY_CONNECTED (if a network was already joined successfully).
|
||||
* A 'CONNECTED' event is sent to the application when the JoinAccept is received.
|
||||
*/
|
||||
virtual lorawan_status_t connect(const lorawan_connect_t &connect) = 0;
|
||||
|
||||
|
|
|
@ -79,14 +79,14 @@ public:
|
|||
* is important, at least for ABP. That's why we try to restore frame counters from
|
||||
* session information after a disconnection.
|
||||
*
|
||||
* @return For ABP: If everything goes well, LORAWAN_STATUS_OK is returned for first call followed by
|
||||
* a 'CONNECTED' event. Otherwise a negative error code.
|
||||
* Any subsequent call will return LORAWAN_STATUS_ALREADY_CONNECTED and no event follows.
|
||||
* @return For ABP: If everything goes well, LORAWAN_STATUS_OK is returned for first call followed by
|
||||
* a 'CONNECTED' event. Otherwise a negative error code is returned.
|
||||
* Any subsequent call will return LORAWAN_STATUS_ALREADY_CONNECTED and no event follows.
|
||||
*
|
||||
* For OTAA: When a JoinRequest is sent, LORAWAN_STATUS_CONNECT_IN_PROGRESS is returned followed by
|
||||
* a 'CONNECTED' event when the JoinAccept is received. Otherwise a negative error code
|
||||
* is returned. Any subsequent call will return LORAWAN_STATUS_ALREADY_CONNECTED and no
|
||||
* event follows.
|
||||
* For OTAA: When a JoinRequest is sent, LORAWAN_STATUS_CONNECT_IN_PROGRESS is returned for the first call.
|
||||
* Any subsequent call will return either LORAWAN_STATUS_BUSY (if the previous request for connection
|
||||
* is still underway) or LORAWAN_STATUS_ALREADY_CONNECTED (if a network was already joined successfully).
|
||||
* A 'CONNECTED' event is sent to the application when the JoinAccept is received.
|
||||
*/
|
||||
virtual lorawan_status_t connect();
|
||||
|
||||
|
@ -124,14 +124,14 @@ public:
|
|||
*
|
||||
* @param connect Options for an end device connection to the gateway.
|
||||
*
|
||||
* @return For ABP: If everything goes well, LORAWAN_STATUS_OK is returned for first call followed by
|
||||
* a 'CONNECTED' event. Otherwise a negative error code.
|
||||
* Any subsequent call will return LORAWAN_STATUS_ALREADY_CONNECTED and no event follows.
|
||||
* @return For ABP: If everything goes well, LORAWAN_STATUS_OK is returned for first call followed by
|
||||
* a 'CONNECTED' event. Otherwise a negative error code is returned.
|
||||
* Any subsequent call will return LORAWAN_STATUS_ALREADY_CONNECTED and no event follows.
|
||||
*
|
||||
* For OTAA: When a JoinRequest is sent, LORAWAN_STATUS_CONNECT_IN_PROGRESS is returned followed by
|
||||
* a 'CONNECTED' event when the JoinAccept is received. Otherwise a negative error code
|
||||
* is returned. Any subsequent call will return LORAWAN_STATUS_ALREADY_CONNECTED and no
|
||||
* event follows.
|
||||
* For OTAA: When a JoinRequest is sent, LORAWAN_STATUS_CONNECT_IN_PROGRESS is returned for the first call.
|
||||
* Any subsequent call will return either LORAWAN_STATUS_BUSY (if the previous request for connection
|
||||
* is still underway) or LORAWAN_STATUS_ALREADY_CONNECTED (if a network was already joined successfully).
|
||||
* A 'CONNECTED' event is sent to the application when the JoinAccept is received.
|
||||
*/
|
||||
virtual lorawan_status_t connect(const lorawan_connect_t &connect);
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@ SPDX-License-Identifier: BSD-3-Clause
|
|||
#define CONNECTED_FLAG 0x00000004
|
||||
#define USING_OTAA_FLAG 0x00000008
|
||||
#define TX_DONE_FLAG 0x00000010
|
||||
#define CONN_IN_PROGRESS_FLAG 0x00000020
|
||||
|
||||
using namespace mbed;
|
||||
using namespace events;
|
||||
|
@ -155,7 +156,11 @@ lorawan_status_t LoRaWANStack::connect()
|
|||
return LORAWAN_STATUS_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
if (_loramac.nwk_joined()) {
|
||||
if (_ctrl_flags & CONN_IN_PROGRESS_FLAG) {
|
||||
return LORAWAN_STATUS_BUSY;
|
||||
}
|
||||
|
||||
if (_ctrl_flags & CONNECTED_FLAG) {
|
||||
return LORAWAN_STATUS_ALREADY_CONNECTED;
|
||||
}
|
||||
|
||||
|
@ -174,7 +179,11 @@ lorawan_status_t LoRaWANStack::connect(const lorawan_connect_t &connect)
|
|||
return LORAWAN_STATUS_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
if (_loramac.nwk_joined()) {
|
||||
if (_ctrl_flags & CONN_IN_PROGRESS_FLAG) {
|
||||
return LORAWAN_STATUS_BUSY;
|
||||
}
|
||||
|
||||
if (_ctrl_flags & CONNECTED_FLAG) {
|
||||
return LORAWAN_STATUS_ALREADY_CONNECTED;
|
||||
}
|
||||
|
||||
|
@ -832,6 +841,8 @@ int LoRaWANStack::convert_to_msg_flag(const mcps_type_t type)
|
|||
|
||||
lorawan_status_t LoRaWANStack::handle_connect(bool is_otaa)
|
||||
{
|
||||
_ctrl_flags |= CONN_IN_PROGRESS_FLAG;
|
||||
|
||||
if (is_otaa) {
|
||||
tr_debug("Initiating OTAA");
|
||||
|
||||
|
@ -1157,30 +1168,23 @@ void LoRaWANStack::process_joining_state(lorawan_status_t &op_status)
|
|||
|
||||
void LoRaWANStack::process_connected_state()
|
||||
{
|
||||
_ctrl_flags |= CONNECTED_FLAG;
|
||||
_ctrl_flags &= ~CONN_IN_PROGRESS_FLAG;
|
||||
|
||||
if (_ctrl_flags & USING_OTAA_FLAG) {
|
||||
tr_debug("OTAA Connection OK!");
|
||||
}
|
||||
|
||||
_lw_session.active = true;
|
||||
send_event_to_application(CONNECTED);
|
||||
_ctrl_flags |= CONNECTED_FLAG;
|
||||
|
||||
_device_current_state = DEVICE_STATE_IDLE;
|
||||
}
|
||||
|
||||
void LoRaWANStack::process_connecting_state(lorawan_status_t &op_status)
|
||||
{
|
||||
if (_device_current_state != DEVICE_STATE_IDLE
|
||||
&& _device_current_state != DEVICE_STATE_SHUTDOWN) {
|
||||
op_status = LORAWAN_STATUS_BUSY;
|
||||
return;
|
||||
}
|
||||
|
||||
if (_ctrl_flags & CONNECTED_FLAG) {
|
||||
tr_debug("Already connected");
|
||||
op_status = LORAWAN_STATUS_ALREADY_CONNECTED;
|
||||
return;
|
||||
}
|
||||
MBED_ASSERT(_device_current_state == DEVICE_STATE_IDLE ||
|
||||
_device_current_state == DEVICE_STATE_SHUTDOWN);
|
||||
|
||||
_device_current_state = DEVICE_STATE_CONNECTING;
|
||||
|
||||
|
|
|
@ -84,14 +84,14 @@ public:
|
|||
|
||||
/** Connect OTAA or ABP using Mbed-OS config system
|
||||
*
|
||||
* @return For ABP: If everything goes well, LORAWAN_STATUS_OK is returned for first call followed by
|
||||
* a 'CONNECTED' event. Otherwise a negative error code.
|
||||
* Any subsequent call will return LORAWAN_STATUS_ALREADY_CONNECTED and no event follows.
|
||||
* @return For ABP: If everything goes well, LORAWAN_STATUS_OK is returned for first call followed by
|
||||
* a 'CONNECTED' event. Otherwise a negative error code is returned.
|
||||
* Any subsequent call will return LORAWAN_STATUS_ALREADY_CONNECTED and no event follows.
|
||||
*
|
||||
* For OTAA: When a JoinRequest is sent, LORAWAN_STATUS_CONNECT_IN_PROGRESS is returned followed by
|
||||
* a 'CONNECTED' event when the JoinAccept is received. Otherwise a negative error code
|
||||
* is returned. Any subsequent call will return LORAWAN_STATUS_ALREADY_CONNECTED and no
|
||||
* event follows.
|
||||
* For OTAA: When a JoinRequest is sent, LORAWAN_STATUS_CONNECT_IN_PROGRESS is returned for the first call.
|
||||
* Any subsequent call will return either LORAWAN_STATUS_BUSY (if the previous request for connection
|
||||
* is still underway) or LORAWAN_STATUS_ALREADY_CONNECTED (if a network was already joined successfully).
|
||||
* A 'CONNECTED' event is sent to the application when the JoinAccept is received.
|
||||
*/
|
||||
lorawan_status_t connect();
|
||||
|
||||
|
@ -99,14 +99,14 @@ public:
|
|||
*
|
||||
* @param connect Options for an end device connection to the gateway.
|
||||
*
|
||||
* @return For ABP: If everything goes well, LORAWAN_STATUS_OK is returned for first call followed by
|
||||
* a 'CONNECTED' event. Otherwise a negative error code.
|
||||
* Any subsequent call will return LORAWAN_STATUS_ALREADY_CONNECTED and no event follows.
|
||||
* @return For ABP: If everything goes well, LORAWAN_STATUS_OK is returned for first call followed by
|
||||
* a 'CONNECTED' event. Otherwise a negative error code is returned.
|
||||
* Any subsequent call will return LORAWAN_STATUS_ALREADY_CONNECTED and no event follows.
|
||||
*
|
||||
* For OTAA: When a JoinRequest is sent, LORAWAN_STATUS_CONNECT_IN_PROGRESS is returned followed by
|
||||
* a 'CONNECTED' event when the JoinAccept is received. Otherwise a negative error code
|
||||
* is returned. Any subsequent call will return LORAWAN_STATUS_ALREADY_CONNECTED and no
|
||||
* event follows.
|
||||
* For OTAA: When a JoinRequest is sent, LORAWAN_STATUS_CONNECT_IN_PROGRESS is returned for the first call.
|
||||
* Any subsequent call will return either LORAWAN_STATUS_BUSY (if the previous request for connection
|
||||
* is still underway) or LORAWAN_STATUS_ALREADY_CONNECTED (if a network was already joined successfully).
|
||||
* A 'CONNECTED' event is sent to the application when the JoinAccept is received.
|
||||
*/
|
||||
lorawan_status_t connect(const lorawan_connect_t &connect);
|
||||
|
||||
|
|
Loading…
Reference in New Issue