AllWize Library
|
#include <AllWize_LoRaWAN.h>
Public Member Functions | |
AllWize_LoRaWAN (HardwareSerial *serial, uint8_t reset_gpio=GPIO_NONE, uint8_t config_gpio=GPIO_NONE) | |
AllWize_LoRaWAN (uint8_t rx, uint8_t tx, uint8_t reset_gpio=GPIO_NONE, uint8_t config_gpio=GPIO_NONE) | |
allwize_message_t | read () |
Returns latest received message (rebuilds LoRaWan header if necessary) More... | |
bool | joinABP (uint8_t *DevAddr, uint8_t *AppSKey, uint8_t *NwkSKey) |
Stores the application and network keys for ABP activation. More... | |
bool | send (uint8_t *Data, uint8_t Data_Length, uint8_t Frame_Port=0x01) |
Function to assemble and send a LoRaWAN package. More... | |
uint16_t | getFrameCounter () |
void | setFrameCounter (uint16_t value) |
![]() | |
AllWize (HardwareSerial *serial, uint8_t reset_gpio=GPIO_NONE, uint8_t config_gpio=GPIO_NONE) | |
AllWize object constructor. More... | |
AllWize (uint8_t rx, uint8_t tx, uint8_t reset_gpio=GPIO_NONE, uint8_t config_gpio=GPIO_NONE) | |
AllWize object constructor. More... | |
void | begin (uint8_t baudrate=MODEM_DEFAULT_BAUDRATE) |
Inits the module communications. More... | |
bool | reset () |
Resets the radio module. More... | |
void | softReset () |
Cleans the RX/TX line. More... | |
bool | factoryReset () |
Resets the module to factory settings. More... | |
void | sleep () |
Sets the radio module in sleep mode. More... | |
void | wakeup () |
Wakes up the radio from sleep mode. More... | |
bool | ready () |
Test whether the radio module is ready or not. More... | |
bool | waitForReady (uint32_t timeout=DEFAULT_TIMEOUT) |
Waits for timeout millis for the module to be ready. More... | |
void | dump (Stream &debug) |
Dumps the current memory configuration to the given stream. More... | |
bool | ack () |
Sends an ACK. More... | |
bool | send (uint8_t *buffer, uint8_t len) |
Sends a byte array. More... | |
bool | send (const char *buffer) |
Sends c-string. More... | |
bool | available () |
Returns true if a new message has been received and decoded This method has to be called in the main loop to monitor for incoming messages. More... | |
bool | enableRX (bool enable) |
Enables or disables RF recever. More... | |
allwize_message_t | read () |
Returns latest received message. More... | |
void | setControlInformation (uint8_t ci) |
Sets the control information byte. More... | |
uint8_t | getControlInformation () |
Gets the control information byte. More... | |
void | master () |
Sets the module in master mode. More... | |
void | slave () |
Sets the module in slave mode. More... | |
void | repeater () |
Sets the module in repeater mode. More... | |
void | setChannel (uint8_t channel, bool persist=false) |
Sets the communications channel (for MBUS_MODE_R2 only) More... | |
void | setPower (uint8_t power, bool persist=false) |
Sets the RF power. More... | |
void | setDataRate (uint8_t dr) |
Sets the data rate. More... | |
void | setMode (uint8_t mode, bool persist=false) |
Sets the module in one of the available MBus modes. More... | |
void | setSleepMode (uint8_t mode) |
Sets the sleep mode. More... | |
void | setAppendRSSI (bool value) |
Sets the RSSI mode value. More... | |
void | setPreamble (uint8_t preamble) |
Sets the preamble length frame format. More... | |
void | setTimeout (uint16_t ms) |
Sets the buffer timeout (also used for auto sleep modes) More... | |
void | setNetworkRole (uint8_t role) |
Sets the network role. More... | |
void | setLEDControl (uint8_t value) |
Sets the LED control. More... | |
void | setDataInterface (uint8_t value) |
Sets the data interface for receiving packets. More... | |
void | setControlField (uint8_t value, bool persist=false) |
Sets the control field value. More... | |
void | setInstallMode (uint8_t mode, bool persist=false) |
Sets the module in one of the available operations modes. More... | |
void | setEncryptFlag (uint8_t flag) |
Sets the encrypt flag setting. More... | |
void | setDecryptFlag (uint8_t flag) |
Sets the decrypt flag setting. More... | |
void | setKey (uint8_t reg, const uint8_t *key) |
Sets the default encryption key. More... | |
void | setDefaultKey (const uint8_t *key) |
Sets the default encryption key. More... | |
void | setAccessNumber (uint8_t value) |
Sets new/specific access number. More... | |
void | setBaudRate (uint8_t baudrate) |
Sets the UART baud rate, requires reset to take effect. More... | |
uint8_t | getChannel () |
Gets the channel stored in non-volatile memory. More... | |
uint8_t | getPower () |
Gets the RF power stored in non-volatile memory. More... | |
uint8_t | getDataRate () |
Gets the data rate stored in non-volatile memory. More... | |
uint8_t | getMode () |
Gets the MBus mode stored in non-volatile memory. More... | |
uint8_t | getSleepMode () |
Gets the sleep mode stored in non-volatile memory. More... | |
uint8_t | getPreamble () |
Gets the preamble length frame format. More... | |
uint8_t | getDataInterface () |
Gets the data interface for receiving packets. More... | |
uint8_t | getControlField () |
Gets the control field value stored in non-volatile memory. More... | |
bool | getAppendRSSI () |
Gets the current RSSI mode value. More... | |
uint16_t | getTimeout () |
Gets the current buffer timeout (also used for auto sleep modes) More... | |
uint8_t | getNetworkRole () |
Gets the current network role. More... | |
uint8_t | getLEDControl () |
Gets the current LED control. More... | |
uint8_t | getInstallMode () |
Gets the install modevalue stored in non-volatile memory. More... | |
uint8_t | getEncryptFlag () |
Gets the encrypt flag setting. More... | |
uint8_t | getDecryptFlag () |
Gets the decrypt flag setting. More... | |
void | getDefaultKey (uint8_t *key) |
Gets the default encryption key. More... | |
uint8_t | getBaudRate () |
Gets the UART baud rate. More... | |
uint32_t | getBaudRateSpeed (uint8_t value) |
Gets the UART baud rate speed in bps. More... | |
float | getRSSI () |
Returns the RSSI of the last valid packet received TODO: values do not seem right and are not the same as in the packet. More... | |
uint8_t | getTemperature () |
Returns the internal temperature of the module. More... | |
uint16_t | getVoltage () |
Returns the internal voltage of the module. More... | |
String | getMID () |
Returns the Manufacturer ID. More... | |
bool | setMID (uint16_t mid) |
Sets the Manufacturer ID. More... | |
String | getUID () |
Returns the Unique ID string. More... | |
bool | setUID (uint32_t uid) |
Saved the UID into the module memory. More... | |
uint8_t | getVersion () |
Returns the device version from non-volatile memory. More... | |
void | setVersion (uint8_t version) |
Sets the device version. More... | |
uint8_t | getDevice () |
Returns the device type from non-volatile memory. More... | |
void | setDevice (uint8_t type) |
Sets the device type. More... | |
String | getPartNumber () |
Returns the module part number. More... | |
String | getRequiredHardwareVersion () |
Returns the minimum required hardware version to run the current firmware. More... | |
String | getFirmwareVersion () |
Returns the module firmware revision. More... | |
String | getSerialNumber () |
Returns the module serial number. More... | |
double | getFrequency (uint8_t channel) |
Returns the frequency for the given channel. More... | |
uint16_t | getDataRateSpeed (uint8_t dr) |
Returns the speed for te given datarate. More... | |
uint8_t | getModuleType () |
Returns the module type. More... | |
String | getModuleTypeName () |
Returns the module type. More... | |
bool | setWizeControl (uint8_t wize_control) |
Sets the wize control field in the transpoprt layer. More... | |
void | setWizeOperatorId (uint16_t wize_network_id) |
Use AllWize::setWizeNetworkId instead. More... | |
void | setWizeNetworkId (uint16_t wize_network_id) |
Sets the wize network ID field in the transpoprt layer. More... | |
void | setWizeApplication (uint8_t wize_application) |
Sets the wize applicaton field in the transpoprt layer. More... | |
void | setCounter (uint16_t counter) |
Sets the wize couonter field in the transpoprt layer. More... | |
uint16_t | getCounter () |
Gets the current wize counter. More... | |
Protected Member Functions | |
void | Encrypt_Payload (uint8_t *Data, uint8_t Data_Length, uint16_t Frame_Counter, uint8_t Direction) |
Function used to encrypt and decrypt the data in a LoRaWAN data packet. More... | |
void | Calculate_MIC (uint8_t *Data, uint8_t *Final_MIC, uint8_t Data_Length, uint16_t Frame_Counter, uint8_t Direction) |
Function used to calculate the validity of data messages. More... | |
void | Generate_Keys (uint8_t *K1, uint8_t *K2) |
Function used to generate keys for the MIC calculation. More... | |
void | Shift_Left (uint8_t *Data) |
Round-shifts data to the left. More... | |
void | XOR (uint8_t *New_Data, uint8_t *Old_Data) |
Function to XOR two character arrays. More... | |
void | AES_Encrypt (uint8_t *Data, const uint8_t *Key) |
Function used to perform AES encryption. More... | |
void | AES_Add_Round_Key (uint8_t *Round_Key, uint8_t(*State)[4]) |
Function performs AES AddRoundKey step. More... | |
uint8_t | AES_Sub_Byte (uint8_t Byte) |
Function performs AES SubBytes step. More... | |
void | AES_Shift_Rows (uint8_t(*State)[4]) |
Function performs AES ShiftRows step. More... | |
void | AES_Mix_Collums (uint8_t(*State)[4]) |
Function performs AES MixColumns step. More... | |
void | AES_Calculate_Round_Key (uint8_t Round, uint8_t *Round_Key) |
Function performs AES Round Key Calculation. More... | |
![]() | |
void | _init () |
uint8_t | _getAddress (uint8_t slot) |
Return the physical memory address for the given slot. More... | |
bool | _setConfig (bool value) |
Sets or unsets config mode. More... | |
int8_t | _sendCommand (uint8_t command, uint8_t *data, uint8_t len) |
Sends a command with the given data. More... | |
int8_t | _sendCommand (uint8_t command, uint8_t data) |
Sends a command with the given data. More... | |
int8_t | _sendCommand (uint8_t command) |
Sends a command with no data. More... | |
bool | _cacheMemory (uint8_t *buffer) |
Reads and caches the module memory. More... | |
uint8_t | _getMemory (uint8_t address) |
Returns the contents of memory address. More... | |
uint8_t | _getMemory (uint8_t address, uint8_t *buffer, uint8_t len) |
Returns the contents of consecutive memory addresses. More... | |
bool | _setMemory (uint8_t address, uint8_t data) |
Sets non-volatile memory contents starting from given address. More... | |
bool | _setMemory (uint8_t address, uint8_t *data, uint8_t len) |
Sets non-volatile memory contents starting from given address. More... | |
bool | _setSlot (uint8_t slot, uint8_t data) |
Sets non-volatile memory contents starting from given address. More... | |
bool | _setSlot (uint8_t slot, uint8_t *data, uint8_t len) |
Sets non-volatile memory contents starting from given address. More... | |
uint8_t | _getSlot (uint8_t slot) |
Returns the contents of single-byte memory slot. More... | |
uint8_t | _getSlot (uint8_t slot, uint8_t *buffer, uint8_t len) |
Returns the contents of consecutive memory addresses. More... | |
String | _getSlotAsHexString (uint8_t slot, uint8_t len) |
Returns the contents of the memory from a certain address as an HEX String. More... | |
String | _getSlotAsString (uint8_t slot, uint8_t len) |
Returns the contents of the memory from a certain address as a String object. More... | |
void | _readModel () |
Searches for the module model. More... | |
bool | _decode () |
Decodes the current RX buffer contents. More... | |
void | _flush () |
Flushes the serial line to the module. More... | |
void | _resetSerial () |
Resets the serial object. More... | |
uint8_t | _send (uint8_t *buffer, uint8_t len) |
Sends a binary buffer to the module UART. Returns the number of bytes actually sent. More... | |
uint8_t | _send (uint8_t ch) |
Sends a single byte to the module UART. Returns the number of bytes actually sent. More... | |
int8_t | _receive () |
Listens to incoming data from the module until timeout or END_OF_RESPONSE. More... | |
int8_t | _sendAndReceive (uint8_t *buffer, uint8_t len) |
Sends a binary buffer and waits for response. Returns the number of bytes received and stored in the internal _buffer. More... | |
int8_t | _sendAndReceive (uint8_t ch) |
Sends a byte and waits for response. Returns the number of bytes received and stored in the internal _buffer. More... | |
int | _timedRead () |
Reads a byte from the stream with a timeout. More... | |
int | _readBytes (char *buffer, uint16_t len) |
Reads the stream buffer up to a number of bytes. More... | |
int | _readBytesUntil (char terminator, char *buffer, uint16_t len) |
Reads the stream buffer up to a certain char or times out. More... | |
void | _hex2bin (char *hex, uint8_t *bin, uint8_t len) |
Converts a hex c-string to a binary buffer. More... | |
void | _bin2hex (uint8_t *bin, char *hex, uint8_t len) |
Converts a binary buffer to an hex c-string. More... | |
void | _niceDelay (uint32_t ms) |
Does a non-blocking delay. More... | |
Protected Attributes | |
uint8_t | _devaddr [4] |
uint8_t | _appskey [16] |
uint8_t | _nwkskey [16] |
![]() | |
int8_t | _rx = -1 |
int8_t | _tx = -1 |
Stream * | _stream = NULL |
HardwareSerial * | _hw_serial = NULL |
SoftwareSerial * | _sw_serial = NULL |
uint8_t | _reset_gpio = GPIO_NONE |
uint8_t | _config_gpio = GPIO_NONE |
bool | _config = false |
uint32_t | _timeout = DEFAULT_TIMEOUT |
uint32_t | _baudrate = 19200 |
uint8_t | _ci = CI_APP_RESPONSE_UP_SHORT |
uint8_t | _mbus_mode = 0xFF |
uint8_t | _data_interface = 0xFF |
bool | _append_rssi = false |
uint8_t | _access_number = 0 |
uint8_t | _module = MODULE_UNKNOWN |
bool | _ready = false |
uint8_t | _memory [0x100] = {0xFF} |
String | _model |
String | _hw |
String | _fw |
uint8_t | _wize_control = 0x00 |
uint16_t | _wize_network_id = 0 |
uint8_t | _wize_application = 0xFE |
uint16_t | _counter = 0 |
allwize_message_t | _message |
uint8_t | _buffer [RX_BUFFER_SIZE] |
uint8_t | _pointer = 0 |
Static Protected Attributes | |
static const uint8_t | S_Table [16][16] |
Definition at line 66 of file AllWize_LoRaWAN.h.
|
protected |
Function performs AES AddRoundKey step.
Round_Key | Pointer to the round subkey. |
*State | Pointer to bytes of the states-to-be-xor'd. |
Definition at line 606 of file AllWize_LoRaWAN.cpp.
|
protected |
Function performs AES Round Key Calculation.
Round | Number of rounds to perform (depends on key size). |
Round_Key | Pointer to round key. |
Definition at line 704 of file AllWize_LoRaWAN.cpp.
|
protected |
Function used to perform AES encryption.
Data | Pointer to the data to decrypt or encrypt. |
Key | Pointer to AES encryption key. |
Definition at line 532 of file AllWize_LoRaWAN.cpp.
|
protected |
Function performs AES MixColumns step.
*State | Pointer to state array. |
Definition at line 675 of file AllWize_LoRaWAN.cpp.
|
protected |
Function performs AES ShiftRows step.
*State | Pointer to state array. |
Definition at line 643 of file AllWize_LoRaWAN.cpp.
|
protected |
Function performs AES SubBytes step.
Byte | Individual byte, from state array. |
Definition at line 624 of file AllWize_LoRaWAN.cpp.
|
protected |
Function used to calculate the validity of data messages.
Data | Data Pointer to the data to decrypt or encrypt. |
Final_MIC | Pointer to MIC array (4 bytes). |
Data_Length | Number of bytes to be transmitted. |
Frame_Counter | Frame counter of upstream frames. |
Direction | Direction of message (is up?). |
Definition at line 250 of file AllWize_LoRaWAN.cpp.
|
protected |
Function used to encrypt and decrypt the data in a LoRaWAN data packet.
Data | Data Pointer to the data to decrypt or encrypt. |
Data_Length | Number of bytes to be transmitted. |
Frame_Counter | Frame_Counter. Counts upstream frames. |
Direction | Direction of message (is up). |
Definition at line 179 of file AllWize_LoRaWAN.cpp.
|
protected |
Function used to generate keys for the MIC calculation.
K1 | Pointer to Key1. |
K2 | Pointer to Key2. |
Definition at line 407 of file AllWize_LoRaWAN.cpp.
uint16_t AllWize_LoRaWAN::getFrameCounter | ( | ) |
bool AllWize_LoRaWAN::joinABP | ( | uint8_t * | DevAddr, |
uint8_t * | AppSKey, | ||
uint8_t * | NwkSKey | ||
) |
Stores the application and network keys for ABP activation.
DevAddr | Device addres |
AppSKey | Application Session Key |
NwkSKey | Network Session Key |
Definition at line 40 of file AllWize_LoRaWAN.cpp.
allwize_message_t AllWize_LoRaWAN::read | ( | ) |
Returns latest received message (rebuilds LoRaWan header if necessary)
Definition at line 64 of file AllWize_LoRaWAN.cpp.
bool AllWize_LoRaWAN::send | ( | uint8_t * | Data, |
uint8_t | Data_Length, | ||
uint8_t | Frame_Port = 0x01 |
||
) |
Function to assemble and send a LoRaWAN package.
Data | Pointer to the array of data to be transmitted. |
Data_Length | Length of data to be sent. |
Frame_Port | Frame Port (defaults to 0x01) |
Definition at line 97 of file AllWize_LoRaWAN.cpp.
void AllWize_LoRaWAN::setFrameCounter | ( | uint16_t | value | ) |
|
protected |
Round-shifts data to the left.
Data | Data buffer |
Definition at line 458 of file AllWize_LoRaWAN.cpp.
|
protected |
Function to XOR two character arrays.
New_Data | A pointer to the calculated data. |
Old_Data | A pointer to the data to be xor'd. |
Definition at line 491 of file AllWize_LoRaWAN.cpp.
|
protected |
Definition at line 85 of file AllWize_LoRaWAN.h.
|
protected |
Definition at line 84 of file AllWize_LoRaWAN.h.
|
protected |
Definition at line 86 of file AllWize_LoRaWAN.h.
|
staticprotected |
Definition at line 87 of file AllWize_LoRaWAN.h.