Xbee Arduino
Arduino Driver for Xbee
Loading...
Searching...
No Matches
xbee_lr.c File Reference

Implementation of XBee LR (LoRaWAN) subclass. More...

#include "xbee_lr.h"
#include "xbee_api_frames.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
Include dependency graph for xbee_lr.c:

Functions

bool XBeeLRConnected (XBee *self)
 Checks if the XBee LR module is connected to the LoRaWAN network. More...
 
bool XBeeLRInit (XBee *self, uint32_t baudRate, void *device)
 Initializes the XBee LR module for communication. More...
 
void XBeeLRProcess (XBee *self)
 Processes incoming data and events for the XBee LR module. More...
 
bool XBeeLRConnect (XBee *self)
 Attempts to connect to the LoRaWAN network using the XBee LR module. More...
 
bool XBeeLRDisconnect (XBee *self)
 Disconnects from the LoRaWAN network using the XBee LR module. More...
 
uint8_t XBeeLRSendData (XBee *self, const void *data)
 Sends data over the network using the XBee LR module. More...
 
bool XBeeLRSoftReset (XBee *self)
 
void XBeeLRHardReset (XBee *self)
 
bool XBeeLRSetAppEUI (XBee *self, const char *value)
 Sends the AT_AE command to set the LoRaWAN AppEUI on the XBee LR module. More...
 
bool XBeeLRSetAppKey (XBee *self, const char *value)
 Sends the AT_AK command to set the LoRaWAN AppKey on the XBee LR module. More...
 
bool XBeeLRSetNwkKey (XBee *self, const char *value)
 Sends the AT_NK command to set the LoRaWAN NwkKey on the XBee LR module. More...
 
bool XBeeLRSetClass (XBee *self, const char value)
 Sends the AT_LC command to set the LoRaWAN Class on the XBee LR module. More...
 
bool XBeeLRSetActivationMode (XBee *self, const uint8_t value)
 Sends the AT_AM command to set the LoRaWAN Activation Mode on the XBee LR module. More...
 
bool XBeeLRSetADR (XBee *self, const uint8_t value)
 Sends the AT_AD command to set the LoRaWAN ADR on the XBee LR module. More...
 
bool XBeeLRSetDataRate (XBee *self, const uint8_t value)
 Sends the AT_DR command to set the LoRaWAN DataRate on the XBee LR module. More...
 
bool XBeeLRSetRegion (XBee *self, const uint8_t value)
 Sends the AT_LR command to set the LoRaWAN Region on the XBee LR module. More...
 
bool XBeeLRSetDutyCycle (XBee *self, const uint8_t value)
 Sends the AT_DC command to set the LoRaWAN Duty Cycle on the XBee LR module. More...
 
bool XBeeLRSetJoinRX1Delay (XBee *self, const uint32_t value)
 Sends the AT_J1 command to set the LoRaWAN Join RX1 Delay on the XBee LR module. More...
 
bool XBeeLRSetJoinRX2Delay (XBee *self, const uint32_t value)
 Sends the AT_J2 command to set the LoRaWAN Join RX2 Delay on the XBee LR module. More...
 
bool XBeeLRSetRX1Delay (XBee *self, const uint32_t value)
 Sends the AT_D1 command to set the LoRaWAN RX1 Delay on the XBee LR module. More...
 
bool XBeeLRSetRX2Delay (XBee *self, const uint32_t value)
 Sends the AT_D2 command to set the LoRaWAN RX2 Delay on the XBee LR module. More...
 
bool XBeeLRSetRX2DataRate (XBee *self, const uint8_t value)
 Sends the AT_XD command to set the LoRaWAN RX2 Data Rate on the XBee LR module. More...
 
bool XBeeLRSetRX2Frequency (XBee *self, const uint32_t value)
 Sends the AT_XF command to set the LoRaWAN RX2 Frequency on the XBee LR module. More...
 
bool XBeeLRSetTransmitPower (XBee *self, const uint8_t value)
 Sends the AT_PO command to set the LoRaWAN Transmit Power on the XBee LR module. More...
 
bool XBeeLRGetDevEUI (XBee *self, uint8_t *responseBuffer, uint8_t buffer_size)
 Sends the AT_DE command to read the LoRaWAN DevEUI from the XBee LR module. More...
 
bool XBeeLRSetChannelsMask (XBee *self, const char *value)
 Sends the AT_CM command to set the LoRaWAN Channels Mask on the XBee LR module. More...
 
void XBeeLRHandleTransmitStatus (XBee *self, void *param)
 
XBeeLRXBeeLRCreate (const XBeeCTable *cTable, const XBeeHTable *hTable)
 Constructor for creating an XBeeLR instance. More...
 
void XBeeLRDestroy (XBeeLR *self)
 

Variables

const XBeeVTable XBeeLRVTable
 

Detailed Description

Implementation of XBee LR (LoRaWAN) subclass.

This file contains the implementation of functions specific to the XBee LR module. It includes methods for initializing, sending join requests, and handling other operations unique to the XBee LR subclass.

Version
1.0
Date
2024-08-08

@license MIT Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Author
Felix Galindo @contact felix.nosp@m..gal.nosp@m.indo@.nosp@m.digi.nosp@m..com

Function Documentation

◆ XBeeLRConnect()

bool XBeeLRConnect ( XBee self)

Attempts to connect to the LoRaWAN network using the XBee LR module.

This function initiates the connection process to a LoRaWAN network by sending a join request. The function is currently blocking, meaning it waits until the connection attempt is completed before returning. A future enhancement (

Todo:
) could add support for non-blocking operation.
Parameters
[in]selfPointer to the XBee instance.
Returns
bool Returns true if the connection process was initiated

◆ XBeeLRConnected()

bool XBeeLRConnected ( XBee self)

Checks if the XBee LR module is connected to the LoRaWAN network.

This function sends an AT command (AT_JS) to the XBee LR module to query the Join Status, determining whether the module is currently connected to the LoRaWAN network. It returns true if the module is connected (i.e., has joined the network) and false otherwise. The function also handles the communication with the module and provides debug output in case of communication errors.

Parameters
[in]selfPointer to the XBee instance.
Returns
bool Returns true if the XBee LR module is connected to the network, otherwise false.

◆ XBeeLRCreate()

XBeeLR * XBeeLRCreate ( const XBeeCTable cTable,
const XBeeHTable hTable 
)

Constructor for creating an XBeeLR instance.

This function allocates memory for a new XBeeLR instance and initializes it with the provided callback table (cTable) and handler table (hTable). The function sets up the virtual table (vtable) for XBee LR-specific operations and assigns the callback and handler tables to the instance. The newly created instance is then returned to the caller.

Parameters
[in]cTablePointer to the callback table containing function pointers for handling XBee events.
[in]hTablePointer to the handler table containing platform-specific function implementations.
Returns
XBeeLR* Pointer to the newly created XBeeLR instance.

◆ XBeeLRDestroy()

void XBeeLRDestroy ( XBeeLR self)

◆ XBeeLRDisconnect()

bool XBeeLRDisconnect ( XBee self)

Disconnects from the LoRaWAN network using the XBee LR module.

This function handles the disconnection process from a LoRaWAN network. It ensures that the XBee LR module is properly disconnected and that any necessary cleanup is performed. The function is currently blocking.

Parameters
[in]selfPointer to the XBee instance.
Returns
bool Returns true if the disconnection process was initiated.

◆ XBeeLRGetDevEUI()

bool XBeeLRGetDevEUI ( XBee self,
uint8_t *  responseBuffer,
uint8_t  buffer_size 
)

Sends the AT_DE command to read the LoRaWAN DevEUI from the XBee LR module.

This function retrieves the LoRaWAN DevEUI (Device Extended Unique Identifier) from the XBee LR module by sending the AT command AT_DE. The function is blocking, meaning it waits for a response from the module or until a timeout occurs. If the command fails to send or the module does not respond, a debug message is printed. The DevEUI is stored in the provided response buffer.

Parameters
[in]selfPointer to the XBee instance.
[out]responseBufferBuffer to store the retrieved DevEUI.
[in]buffer_sizeSize of the response buffer (should be at least 17 bytes).
Returns
bool Returns true if the DevEUI was successfully retrieved, otherwise false.

◆ XBeeLRHandleTransmitStatus()

void XBeeLRHandleTransmitStatus ( XBee self,
void *  param 
)

◆ XBeeLRHardReset()

void XBeeLRHardReset ( XBee self)

◆ XBeeLRInit()

bool XBeeLRInit ( XBee self,
uint32_t  baudRate,
void *  device 
)

Initializes the XBee LR module for communication.

This function initializes the XBee LR module by setting up the necessary serial communication parameters, such as the baud rate and device path. It relies on platform-specific UART initialization provided by the hardware abstraction layer. The function returns true if initialization is successful.

Parameters
[in]selfPointer to the XBee instance.
[in]baudrateThe baud rate for serial communication.
[in]deviceThe path to the serial device (e.g., "/dev/ttyUSB0").
Returns
bool Returns true if the initialization is successful, otherwise false.

◆ XBeeLRProcess()

void XBeeLRProcess ( XBee self)

Processes incoming data and events for the XBee LR module.

This function must be called continuously in the main loop of the application. It handles the reception and processing of API frames from the XBee LR module. The function checks for incoming frames, and if a frame is successfully received, it is processed accordingly.

Parameters
[in]selfPointer to the XBee instance.
Returns
void This function does not return a value.

◆ XBeeLRSendData()

uint8_t XBeeLRSendData ( XBee self,
const void *  data 
)

Sends data over the network using the XBee LR module.

This function constructs and sends a data packet over the network using an XBee LR module. The function is currently blocking, meaning it waits until the data is fully transmitted before returning. A future enhancement (

Todo:
) could add support for non-blocking operation.
Parameters
[in]selfPointer to the XBee instance.
[in]dataPointer to the data to be sent, encapsulated in an XBeeLRPacket_t structure.
Returns
xbee_deliveryStatus_t, 0 if successful

◆ XBeeLRSetActivationMode()

bool XBeeLRSetActivationMode ( XBee self,
const uint8_t  value 
)

Sends the AT_AM command to set the LoRaWAN Activation Mode on the XBee LR module.

Parameters
[in]selfPointer to the XBee instance.
[in]valueThe Activation Mode to be set.
Returns
bool Returns true if the Activation Mode was successfully set, otherwise false.

◆ XBeeLRSetADR()

bool XBeeLRSetADR ( XBee self,
const uint8_t  value 
)

Sends the AT_AD command to set the LoRaWAN ADR on the XBee LR module.

Parameters
[in]selfPointer to the XBee instance.
[in]valueThe ADR setting to be set.
Returns
bool Returns true if the ADR was successfully set, otherwise false.

◆ XBeeLRSetAppEUI()

bool XBeeLRSetAppEUI ( XBee self,
const char *  value 
)

Sends the AT_AE command to set the LoRaWAN AppEUI on the XBee LR module.

This function configures the LoRaWAN AppEUI (Application Identifier) on the XBee LR module by sending the AT command AT_AE with the specified AppEUI value. The function is blocking, meaning it waits for a response from the module or until a timeout occurs. If the command fails to send or the module does not respond, a debug message is printed.

Parameters
[in]selfPointer to the XBee instance.
[in]valueThe AppEUI to be set, provided as a string.
Returns
bool Returns true if the AppEUI was successfully set, otherwise false.

◆ XBeeLRSetAppKey()

bool XBeeLRSetAppKey ( XBee self,
const char *  value 
)

Sends the AT_AK command to set the LoRaWAN AppKey on the XBee LR module.

This function configures the LoRaWAN AppKey (Application Key) on the XBee LR module by sending the AT command AT_AK with the specified AppKey value. The function is blocking, meaning it waits for a response from the module or until a timeout occurs. If the command fails to send or the module does not respond, a debug message is printed.

Parameters
[in]selfPointer to the XBee instance.
[in]valueThe AppKey to be set, provided as a string.
Returns
bool Returns true if the AppKey was successfully set, otherwise false.

◆ XBeeLRSetChannelsMask()

bool XBeeLRSetChannelsMask ( XBee self,
const char *  value 
)

Sends the AT_CM command to set the LoRaWAN Channels Mask on the XBee LR module.

This function configures the Channels Mask for the LoRaWAN network on the XBee LR module by sending the AT_CM command. The Channels Mask specifies the sub-bands that are enabled for communication. The function checks the command response to verify if the mask was successfully set.

Parameters
[in]selfPointer to the XBee instance.
[in]valuePointer to a null-terminated string representing the Channels Mask in hexadecimal format.
Returns
bool Returns true if the Channels Mask was successfully set; otherwise, false.

◆ XBeeLRSetClass()

bool XBeeLRSetClass ( XBee self,
const char  value 
)

Sends the AT_LC command to set the LoRaWAN Class on the XBee LR module.

This function configures the LoRaWAN Class on the XBee LR module by sending the AT command AT_LC with the specified Class value. The function is blocking, meaning it waits for a response from the module or until a timeout occurs. If the command fails to send or the module does not respond, a debug message is printed.

Parameters
[in]selfPointer to the XBee instance.
[in]valueThe Class to be set, provided as a char. 'A','B','C'
Returns
bool Returns true if the Class was successfully set, otherwise false.

◆ XBeeLRSetDataRate()

bool XBeeLRSetDataRate ( XBee self,
const uint8_t  value 
)

Sends the AT_DR command to set the LoRaWAN DataRate on the XBee LR module.

Parameters
[in]selfPointer to the XBee instance.
[in]valueThe DataRate to be set.
Returns
bool Returns true if the DataRate was successfully set, otherwise false.

◆ XBeeLRSetDutyCycle()

bool XBeeLRSetDutyCycle ( XBee self,
const uint8_t  value 
)

Sends the AT_DC command to set the LoRaWAN Duty Cycle on the XBee LR module.

Parameters
[in]selfPointer to the XBee instance.
[in]valueThe Duty Cycle to be set.
Returns
bool Returns true if the Duty Cycle was successfully set, otherwise false.

◆ XBeeLRSetJoinRX1Delay()

bool XBeeLRSetJoinRX1Delay ( XBee self,
const uint32_t  value 
)

Sends the AT_J1 command to set the LoRaWAN Join RX1 Delay on the XBee LR module.

Parameters
[in]selfPointer to the XBee instance.
[in]valueThe Join RX1 Delay to be set.
Returns
bool Returns true if the Join RX1 Delay was successfully set, otherwise false.

◆ XBeeLRSetJoinRX2Delay()

bool XBeeLRSetJoinRX2Delay ( XBee self,
const uint32_t  value 
)

Sends the AT_J2 command to set the LoRaWAN Join RX2 Delay on the XBee LR module.

Parameters
[in]selfPointer to the XBee instance.
[in]valueThe Join RX2 Delay to be set.
Returns
bool Returns true if the Join RX2 Delay was successfully set, otherwise false.

◆ XBeeLRSetNwkKey()

bool XBeeLRSetNwkKey ( XBee self,
const char *  value 
)

Sends the AT_NK command to set the LoRaWAN NwkKey on the XBee LR module.

This function configures the LoRaWAN NwkKey (Network Key) on the XBee LR module by sending the AT command AT_NK with the specified NwkKey value. The function is blocking, meaning it waits for a response from the module or until a timeout occurs. If the command fails to send or the module does not respond, a debug message is printed.

Parameters
[in]selfPointer to the XBee instance.
[in]valueThe NwkKey to be set, provided as a string.
Returns
bool Returns true if the NwkKey was successfully set, otherwise false.

◆ XBeeLRSetRegion()

bool XBeeLRSetRegion ( XBee self,
const uint8_t  value 
)

Sends the AT_LR command to set the LoRaWAN Region on the XBee LR module.

Parameters
[in]selfPointer to the XBee instance.
[in]valueThe Region to be set.
Returns
bool Returns true if the Region was successfully set, otherwise false.

◆ XBeeLRSetRX1Delay()

bool XBeeLRSetRX1Delay ( XBee self,
const uint32_t  value 
)

Sends the AT_D1 command to set the LoRaWAN RX1 Delay on the XBee LR module.

Parameters
[in]selfPointer to the XBee instance.
[in]valueThe RX1 Delay to be set.
Returns
bool Returns true if the RX1 Delay was successfully set, otherwise false.

◆ XBeeLRSetRX2DataRate()

bool XBeeLRSetRX2DataRate ( XBee self,
const uint8_t  value 
)

Sends the AT_XD command to set the LoRaWAN RX2 Data Rate on the XBee LR module.

Parameters
[in]selfPointer to the XBee instance.
[in]valueThe RX2 Data Rate to be set.
Returns
bool Returns true if the RX2 Data Rate was successfully set, otherwise false.

◆ XBeeLRSetRX2Delay()

bool XBeeLRSetRX2Delay ( XBee self,
const uint32_t  value 
)

Sends the AT_D2 command to set the LoRaWAN RX2 Delay on the XBee LR module.

Parameters
[in]selfPointer to the XBee instance.
[in]valueThe RX2 Delay to be set.
Returns
bool Returns true if the RX2 Delay was successfully set, otherwise false.

◆ XBeeLRSetRX2Frequency()

bool XBeeLRSetRX2Frequency ( XBee self,
const uint32_t  value 
)

Sends the AT_XF command to set the LoRaWAN RX2 Frequency on the XBee LR module.

Parameters
[in]selfPointer to the XBee instance.
[in]valueThe RX2 Frequency to be set.
Returns
bool Returns true if the RX2 Frequency was successfully set, otherwise false.

◆ XBeeLRSetTransmitPower()

bool XBeeLRSetTransmitPower ( XBee self,
const uint8_t  value 
)

Sends the AT_PO command to set the LoRaWAN Transmit Power on the XBee LR module.

Parameters
[in]selfPointer to the XBee instance.
[in]valueThe Transmit Power to be set.
Returns
bool Returns true if the Transmit Power was successfully set, otherwise false.

◆ XBeeLRSoftReset()

bool XBeeLRSoftReset ( XBee self)

Variable Documentation

◆ XBeeLRVTable

const XBeeVTable XBeeLRVTable
Initial value:
= {
.init = XBeeLRInit,
.process = XBeeLRProcess,
.connect = XBeeLRConnect,
.disconnect = XBeeLRDisconnect,
.sendData = XBeeLRSendData,
.softReset = XBeeLRSoftReset,
.hardReset = XBeeLRHardReset,
.connected = XBeeLRConnected,
.handleRxPacketFrame = XBeeLRHandleRxPacket,
.handleTransmitStatusFrame = XBeeLRHandleTransmitStatus,
}
bool XBeeLRConnected(XBee *self)
Checks if the XBee LR module is connected to the LoRaWAN network.
Definition: xbee_lr.c:59
bool XBeeLRConnect(XBee *self)
Attempts to connect to the LoRaWAN network using the XBee LR module.
Definition: xbee_lr.c:134
uint8_t XBeeLRSendData(XBee *self, const void *data)
Sends data over the network using the XBee LR module.
Definition: xbee_lr.c:183
void XBeeLRHardReset(XBee *self)
Definition: xbee_lr.c:231
void XBeeLRHandleTransmitStatus(XBee *self, void *param)
Definition: xbee_lr.c:765
void XBeeLRProcess(XBee *self)
Processes incoming data and events for the XBee LR module.
Definition: xbee_lr.c:109
bool XBeeLRSoftReset(XBee *self)
Definition: xbee_lr.c:226
bool XBeeLRInit(XBee *self, uint32_t baudRate, void *device)
Initializes the XBee LR module for communication.
Definition: xbee_lr.c:92
bool XBeeLRDisconnect(XBee *self)
Disconnects from the LoRaWAN network using the XBee LR module.
Definition: xbee_lr.c:165