Allwize Library
|
Public Member Functions | |
Allwize (Stream &stream, uint8_t reset_gpio=0xFF) | |
Allwize object constructor. More... | |
void | begin () |
Inits the module communications. | |
bool | reset () |
Resets the radio module. You must reset the serial connection after the reset: Serial1.end(); Serial1.begin(19200); delay(200);. More... | |
bool | factoryReset () |
Resets the module to factory settings You must reset the serial connection after the factoryReset: Serial1.end(); Serial1.begin(19200); delay(200);. More... | |
void | sleep () |
Sets the radio module in sleep mode. | |
void | wakeup () |
Wakes up the radio from sleep mode. | |
bool | ready () |
Test whether the radio module is ready or not. | |
void | dump (Stream &debug) |
Dumps the current memory configuration to the given stream. 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 incomming messages. 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. | |
void | slave () |
Sets the module in slave mode. | |
void | repeater () |
Sets the module in repeater mode. | |
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 | setPreamble (uint8_t preamble) |
Sets the RSSI mode value. More... | |
void | setTimeout (uint8_t timeout) |
Sets the timeout 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 | setControlField (uint8_t value, bool persist=false) |
Sets the data interface for receiving packets. 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 | setDefaultKey (uint8_t *key) |
Sets the default encryption key. 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 | getControlField () |
Gets the control field value stored in non-volatile memory. More... | |
uint8_t | getTimeout () |
Gets the current timeout 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 | getTemperature () |
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... | |
uint16_t | getVoltage () |
Returns the internal voltage of the module. More... | |
String | getMID () |
Returns the Manufacturer ID string. More... | |
String | getUID () |
Returns the Unique ID string. More... | |
uint8_t | getVersion () |
Returns the module version from non-volatile memory. More... | |
uint8_t | getDevice () |
Returns the device version from non-volatile memory. More... | |
String | getPartNumber () |
Returns the module part number. More... | |
String | getRequiredHardwareVersion () |
Returns the module hardware revision. More... | |
String | getFirmwareVersion () |
Returns the module firmware revision. More... | |
String | getSerialNumber () |
Returns the module serial number. More... | |
Protected Member Functions | |
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 | _setMemory (uint8_t address, uint8_t *data, uint8_t len) |
Sets non-volatile memory contents starting from given address. More... | |
bool | _setMemory (uint8_t address, uint8_t data) |
Sets non-volatile memory contents starting from given address. More... | |
uint8_t | _getMemory (uint8_t address, uint8_t *buffer, uint8_t len) |
Returns the contents of consecutive memory addresses. More... | |
uint8_t | _getMemory (uint8_t address) |
Returns the contents of single memory addresses. More... | |
String | _getMemoryAsHexString (uint8_t address, uint8_t len) |
Returns the contents of the memory from a certain address as an HEX String. More... | |
String | _getMemoryAsString (uint8_t address, uint8_t len) |
Returns the contents of the memory from a certain address as a String object. More... | |
void | _readModel () |
Reads and caches the module model & version. | |
bool | _decode () |
Decodes the current RX buffer contents. More... | |
void | _flush () |
Flushes the serial line to the module. | |
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 incomming data from the module until timeout or END_OF_RESPONSE. Returns the number of bytes received and stored in the internal _buffer. 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... | |
Protected Attributes | |
Stream & | _stream |
uint8_t | _reset_gpio = 0xFF |
bool | _config = false |
uint32_t | _timeout = DEFAULT_TIMEOUT |
uint8_t | _ci = CONTROL_INFORMATION |
String | _model |
String | _fw |
String | _hw |
allwize_message_t | _message |
uint8_t | _buffer [RX_BUFFER_SIZE] |
uint8_t | _pointer |
Allwize::Allwize | ( | Stream & | stream, |
uint8_t | reset_gpio = 0xFF |
||
) |
Allwize object constructor.
stream | Serial stream to communicate with the module |
Definition at line 33 of file Allwize.cpp.
|
protected |
Converts a binary buffer to an hex c-string.
{uint8_t | *} bin Buffer to read the values from |
{char | *} hex C-string to store the hex values |
{uint8_t} | len Length of the input buffer |
Definition at line 1066 of file Allwize.cpp.
|
protected |
Decodes the current RX buffer contents.
Message format depending current configuration
0. Start byte (0x68) | | | | * | | * |
Data Interface is hardcoded to 0x04 for this version and RSSI enabled
Definition at line 892 of file Allwize.cpp.
|
protected |
Returns the contents of consecutive memory addresses.
{uint8_t} | address Address to start from |
{uint8_t | *} buffer Buffer with at least 'len' position to store data to |
{uint8_t} | len Number of positions to read |
Definition at line 780 of file Allwize.cpp.
|
protected |
Returns the contents of single memory addresses.
{uint8_t} | address Address to start from |
Definition at line 800 of file Allwize.cpp.
|
protected |
Returns the contents of the memory from a certain address as an HEX String.
{uint8_t} | address Address to start from |
{uint8_t} | len Number of bytes to read |
Definition at line 813 of file Allwize.cpp.
|
protected |
Returns the contents of the memory from a certain address as a String object.
{uint8_t} | address Address to start from |
{uint8_t} | len Number of bytes to read |
Definition at line 830 of file Allwize.cpp.
|
protected |
Converts a hex c-string to a binary buffer.
{char | *} hex C-string with the hex values |
{uint8_t | *} bin Buffer to store the converted values in |
{uint8_t} | len Length of the hex c-string |
Definition at line 1053 of file Allwize.cpp.
|
protected |
Reads the stream buffer up to a number of bytes.
{char | *} buffer Buffer to store the values to |
{uint16_t} | len Max number of bytes to read |
Definition at line 1013 of file Allwize.cpp.
|
protected |
Reads the stream buffer up to a certain char or times out.
{char} | terminator Terminating char |
{char | *} buffer Buffer to store the values to |
{uint16_t} | len Max number of bytes to read |
Definition at line 1033 of file Allwize.cpp.
|
protected |
Listens to incomming data from the module until timeout or END_OF_RESPONSE. Returns the number of bytes received and stored in the internal _buffer.
Definition at line 958 of file Allwize.cpp.
|
protected |
Sends a binary buffer to the module UART. Returns the number of bytes actually sent.
{uint8_t | *} buffer Binary data to send |
{uint8_t} | len Length of the binary data |
Definition at line 945 of file Allwize.cpp.
|
protected |
Sends a single byte to the module UART. Returns the number of bytes actually sent.
{uint8_t} | ch Byte to send |
Definition at line 934 of file Allwize.cpp.
|
protected |
Sends a binary buffer and waits for response. Returns the number of bytes received and stored in the internal _buffer.
{uint8_t | *} buffer Binary data to send |
{uint8_t} | len Length of the binary data |
Definition at line 969 of file Allwize.cpp.
|
protected |
Sends a byte and waits for response. Returns the number of bytes received and stored in the internal _buffer.
{uint8_t} | ch Byte to send (-1 if timed out) |
Definition at line 980 of file Allwize.cpp.
|
protected |
Sends a command with the given data.
{uint8_t} | command Command key |
{uint8_t | *} data Binary data to send |
{uint8_t} | len Length of the binary data |
Definition at line 701 of file Allwize.cpp.
|
protected |
Sends a command with the given data.
{uint8_t} | command Command key |
{uint8_t} | data Single byte |
Definition at line 718 of file Allwize.cpp.
|
protected |
Sends a command with no data.
{uint8_t} | command Command key |
Definition at line 734 of file Allwize.cpp.
|
protected |
Sets or unsets config mode.
{bool} | value True to enter config mode |
Definition at line 677 of file Allwize.cpp.
|
protected |
Sets non-volatile memory contents starting from given address.
{uint8_t} | address Command key |
{uint8_t | *} data Binary data to store |
{uint8_t} | len Length of the binary data |
Definition at line 750 of file Allwize.cpp.
|
protected |
Sets non-volatile memory contents starting from given address.
{uint8_t} | address Command key |
{uint8_t} | data Single byte to store at given address |
Definition at line 767 of file Allwize.cpp.
|
protected |
Reads a byte from the stream with a timeout.
Definition at line 994 of file Allwize.cpp.
bool Allwize::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 incomming messages.
Definition at line 234 of file Allwize.cpp.
void Allwize::dump | ( | Stream & | debug | ) |
Dumps the current memory configuration to the given stream.
debug | Data stream to dump the data to |
Definition at line 158 of file Allwize.cpp.
bool Allwize::factoryReset | ( | ) |
Resets the module to factory settings You must reset the serial connection after the factoryReset: Serial1.end(); Serial1.begin(19200); delay(200);.
Definition at line 87 of file Allwize.cpp.
uint8_t Allwize::getChannel | ( | ) |
Gets the channel stored in non-volatile memory.
Definition at line 305 of file Allwize.cpp.
uint8_t Allwize::getControlField | ( | ) |
Gets the control field value stored in non-volatile memory.
Definition at line 495 of file Allwize.cpp.
uint8_t Allwize::getControlInformation | ( | ) |
Gets the control information byte.
Definition at line 287 of file Allwize.cpp.
uint8_t Allwize::getDataRate | ( | ) |
Gets the data rate stored in non-volatile memory.
Definition at line 343 of file Allwize.cpp.
uint8_t Allwize::getDecryptFlag | ( | ) |
Gets the decrypt flag setting.
Definition at line 545 of file Allwize.cpp.
void Allwize::getDefaultKey | ( | uint8_t * | key | ) |
Gets the default encryption key.
{uint8_t | *} key A binary buffer to store the key (16 bytes) |
Definition at line 561 of file Allwize.cpp.
uint8_t Allwize::getDevice | ( | ) |
Returns the device version from non-volatile memory.
Definition at line 628 of file Allwize.cpp.
uint8_t Allwize::getEncryptFlag | ( | ) |
Gets the encrypt flag setting.
Definition at line 529 of file Allwize.cpp.
String Allwize::getFirmwareVersion | ( | ) |
Returns the module firmware revision.
Definition at line 654 of file Allwize.cpp.
String Allwize::getRequiredHardwareVersion | ( | ) |
Returns the module hardware revision.
Definition at line 645 of file Allwize.cpp.
uint8_t Allwize::getInstallMode | ( | ) |
Gets the install modevalue stored in non-volatile memory.
Definition at line 513 of file Allwize.cpp.
uint8_t Allwize::getLEDControl | ( | ) |
Gets the current LED control.
Definition at line 459 of file Allwize.cpp.
uint8_t Allwize::getMode | ( | ) |
Gets the MBus mode stored in non-volatile memory.
Definition at line 361 of file Allwize.cpp.
String Allwize::getMID | ( | ) |
Returns the Manufacturer ID string.
Definition at line 604 of file Allwize.cpp.
uint8_t Allwize::getNetworkRole | ( | ) |
Gets the current network role.
Definition at line 443 of file Allwize.cpp.
String Allwize::getPartNumber | ( | ) |
Returns the module part number.
Definition at line 636 of file Allwize.cpp.
uint8_t Allwize::getPower | ( | ) |
Gets the RF power stored in non-volatile memory.
Definition at line 325 of file Allwize.cpp.
uint8_t Allwize::getPreamble | ( | ) |
Gets the preamble length frame format.
Definition at line 411 of file Allwize.cpp.
String Allwize::getSerialNumber | ( | ) |
Returns the module serial number.
Definition at line 663 of file Allwize.cpp.
uint8_t Allwize::getSleepMode | ( | ) |
Gets the sleep mode stored in non-volatile memory.
Definition at line 377 of file Allwize.cpp.
uint8_t Allwize::getTemperature | ( | ) |
Returns the RSSI of the last valid packet received TODO: values do not seem right and are not the same as in the packet.
Definition at line 584 of file Allwize.cpp.
uint8_t Allwize::getTimeout | ( | ) |
Gets the current timeout for auto sleep modes.
Definition at line 427 of file Allwize.cpp.
String Allwize::getUID | ( | ) |
Returns the Unique ID string.
Definition at line 612 of file Allwize.cpp.
uint8_t Allwize::getVersion | ( | ) |
Returns the module version from non-volatile memory.
Definition at line 620 of file Allwize.cpp.
uint16_t Allwize::getVoltage | ( | ) |
Returns the internal voltage of the module.
Definition at line 594 of file Allwize.cpp.
allwize_message_t Allwize::read | ( | ) |
Returns latest received message.
Definition at line 267 of file Allwize.cpp.
bool Allwize::reset | ( | ) |
Resets the radio module. You must reset the serial connection after the reset: Serial1.end(); Serial1.begin(19200); delay(200);.
Definition at line 56 of file Allwize.cpp.
bool Allwize::send | ( | uint8_t * | buffer, |
uint8_t | len | ||
) |
Sends a byte array.
buffer | Byte array with the application payload |
len | Length of the payload |
Definition at line 211 of file Allwize.cpp.
bool Allwize::send | ( | const char * | buffer | ) |
Sends c-string.
buffer | C-string with the application payload |
Definition at line 225 of file Allwize.cpp.
void Allwize::setChannel | ( | uint8_t | channel, |
bool | persist = false |
||
) |
Sets the communications channel (for MBUS_MODE_R2 only)
channel | Channel number |
persist | Persist the changes in non-volatile memory (defaults to False) |
Definition at line 296 of file Allwize.cpp.
void Allwize::setControlField | ( | uint8_t | value, |
bool | persist = false |
||
) |
Sets the data interface for receiving packets.
{uint8_t} | value Value from 0x00 to 0x0CGets the data interface for receiving packets |
{uint8_t} | value Control field |
{bool} | persist Persist the changes in non-volatile memory (defaults to False) |
Definition at line 486 of file Allwize.cpp.
void Allwize::setControlInformation | ( | uint8_t | ci | ) |
Sets the control information byte.
ci | CI byte value |
Definition at line 279 of file Allwize.cpp.
void Allwize::setDataRate | ( | uint8_t | dr | ) |
void Allwize::setDecryptFlag | ( | uint8_t | flag | ) |
Sets the decrypt flag setting.
{uint8_t} | flag Decrypt flag |
Definition at line 537 of file Allwize.cpp.
void Allwize::setDefaultKey | ( | uint8_t * | key | ) |
Sets the default encryption key.
{uint8_t | *} key A 16-byte encryption key as binary array |
Definition at line 553 of file Allwize.cpp.
void Allwize::setEncryptFlag | ( | uint8_t | flag | ) |
Sets the encrypt flag setting.
{uint8_t} | flag Encrypt flag |
Definition at line 521 of file Allwize.cpp.
void Allwize::setInstallMode | ( | uint8_t | mode, |
bool | persist = false |
||
) |
Sets the module in one of the available operations modes.
{allwize_install_mode_t} | mode Operation mode |
{bool} | persist Persist the changes in non-volatile memory (defaults to False) |
Definition at line 504 of file Allwize.cpp.
void Allwize::setLEDControl | ( | uint8_t | value | ) |
void Allwize::setMode | ( | uint8_t | mode, |
bool | persist = false |
||
) |
Sets the module in one of the available MBus modes.
mode | MBus mode (MBUS_MODE_*) |
persist | Persist the changes in non-volatile memory (defaults to False) |
Definition at line 352 of file Allwize.cpp.
void Allwize::setNetworkRole | ( | uint8_t | role | ) |
Sets the network role.
role | Network role (NETWORK_ROLE_*) |
Definition at line 435 of file Allwize.cpp.
void Allwize::setPower | ( | uint8_t | power, |
bool | persist = false |
||
) |
Sets the RF power.
power | Value from 1 to 5 |
persist | Persist the changes in non-volatile memory (defaults to False) |
Definition at line 314 of file Allwize.cpp.
void Allwize::setPreamble | ( | uint8_t | preamble | ) |
Sets the RSSI mode value.
value | Set to true to append RSSI value to received dataGets the current RSSI mode value |
preamble | 0 or 2 |
Definition at line 401 of file Allwize.cpp.
void Allwize::setSleepMode | ( | uint8_t | mode | ) |
void Allwize::setTimeout | ( | uint8_t | timeout | ) |
Sets the timeout for auto sleep modes.
timeout | Timeout value (defaults to 1s) |
Definition at line 419 of file Allwize.cpp.