MySensors Library & Examples
2.3.2
|
API and type declarations for MySensors messages.
Definition in file MyMessage.h.
Go to the source code of this file.
Classes | |
class | MyMessage |
MyMessage is used to create, manipulate, send and read MySensors messages. More... | |
Macros | |
#define | V2_MYS_HEADER_PROTOCOL_VERSION (2u) |
Protocol version. | |
#define | V2_MYS_HEADER_SIZE (7u) |
Header size. | |
#define | V2_MYS_HEADER_MAX_MESSAGE_SIZE (32u) |
Max payload size. | |
#define | V2_MYS_HEADER_VSL_VERSION_POS (0) |
bitfield position version | |
#define | V2_MYS_HEADER_VSL_VERSION_SIZE (2u) |
size version field | |
#define | V2_MYS_HEADER_VSL_SIGNED_POS (2u) |
bitfield position signed field | |
#define | V2_MYS_HEADER_VSL_SIGNED_SIZE (1u) |
size signed field | |
#define | V2_MYS_HEADER_VSL_LENGTH_POS (3u) |
bitfield position length field | |
#define | V2_MYS_HEADER_VSL_LENGTH_SIZE (5u) |
size length field | |
#define | V2_MYS_HEADER_CEP_COMMAND_POS (0) |
bitfield position command field | |
#define | V2_MYS_HEADER_CEP_COMMAND_SIZE (3u) |
size command field | |
#define | V2_MYS_HEADER_CEP_ECHOREQUEST_POS (3u) |
bitfield position echo request field | |
#define | V2_MYS_HEADER_CEP_ECHOREQUEST_SIZE (1u) |
size echo request field | |
#define | V2_MYS_HEADER_CEP_ECHO_POS (4u) |
bitfield position echo field | |
#define | V2_MYS_HEADER_CEP_ECHO_SIZE (1u) |
size echo field | |
#define | V2_MYS_HEADER_CEP_PAYLOADTYPE_POS (5u) |
bitfield position payload type field | |
#define | V2_MYS_HEADER_CEP_PAYLOADTYPE_SIZE (3u) |
size payload type field | |
#define | MAX_MESSAGE_SIZE V2_MYS_HEADER_MAX_MESSAGE_SIZE |
The maximum size of a message (including header) | |
#define | HEADER_SIZE V2_MYS_HEADER_SIZE |
The size of the header. | |
#define | MAX_PAYLOAD_SIZE (MAX_MESSAGE_SIZE - HEADER_SIZE) |
The maximum size of a payload depends on MAX_MESSAGE_SIZE and HEADER_SIZE. | |
#define | MAX_PAYLOAD MAX_PAYLOAD_SIZE |
#define | BIT(n) ( 1<<(n) ) |
Bit indexing macro. | |
#define | BIT_MASK(len) ( BIT(len)-1 ) |
Create a bitmask of length 'len'. | |
#define | BF_MASK(start, len) ( BIT_MASK(len)<<(start) ) |
Create a bitfield mask of length starting at bit 'start'. | |
#define | BF_PREP(x, start, len) ( ((x)&BIT_MASK(len)) << (start) ) |
Prepare a bitmask for insertion or combining. | |
#define | BF_GET(y, start, len) ( ((y)>>(start)) & BIT_MASK(len) ) |
Extract a bitfield of length 'len' starting at bit 'start' from 'y'. | |
#define | BF_SET(y, x, start, len) ( y= ((y) &~ BF_MASK(start, len)) | BF_PREP(x, start, len) ) |
Insert a new bitfield value 'x' into 'y'. | |
#define | mSetVersion(_message, _version) _message.setVersion(_version) |
#define | mGetVersion(_message) _message.getVersion() |
#define | mSetSigned(_message, _signed) _message.setSigned(_signed) |
#define | mGetSigned(_message) _message.getSigned() |
#define | mSetLength(_message, _length) _message.setLength(_length) |
#define | mGetLength(_message) _message.getLength() |
#define | mSetCommand(_message, _command) _message.setCommand(_command) |
#define | mGetCommand(_message) _message.getCommand() |
#define | mSetRequestEcho(_message, _requestEcho) _message.setRequestEcho(_requestEcho) |
#define | mGetRequestEcho(_message) _message.getRequestEcho() |
#define | mSetEcho(_message, _echo) _message.setEcho(_echo) |
#define | mGetEcho(_message) _message.getEcho() |
#define | mSetPayloadType(_message, _payloadType) _message.setPayloadType(_payloadType) |
#define | mGetPayloadType(_message) _message.getPayloadType() |
Functions | |
class MyMessage | __attribute__ ((packed)) |
Doxygen will complain without this comment. | |
MyMessage (void) | |
MyMessage (const uint8_t sensorId, const mysensors_data_t dataType) | |
void | clear (void) |
Clear message contents. | |
char * | getStream (char *buffer) const |
char * | getString (char *buffer) const |
Copy the payload into the supplied buffer. | |
const char * | getString (void) const |
Get payload as string. More... | |
void * | getCustom (void) const |
Get custom payload. More... | |
bool | getBool (void) const |
Get bool payload. More... | |
uint8_t | getByte (void) const |
Get unsigned 8-bit integer payload. More... | |
float | getFloat (void) const |
Get float payload. More... | |
int16_t | getInt (void) const |
Get signed 16-bit integer payload. More... | |
uint16_t | getUInt (void) const |
Get unsigned 16-bit integer payload. More... | |
int32_t | getLong (void) const |
Get signed 32-bit integer payload. More... | |
uint32_t | getULong (void) const |
Get unsigned 32-bit integer payload. More... | |
uint8_t | getHeaderSize (void) const |
getHeaderSize More... | |
uint8_t | getMaxPayloadSize (void) const |
getMaxPayloadSize More... | |
uint8_t | getExpectedMessageSize (void) const |
getExpectedMessageSize More... | |
bool | isProtocolVersionValid (void) const |
isProtocolVersionValid More... | |
bool | getRequestEcho (void) const |
Getter for echo request. More... | |
MyMessage & | setRequestEcho (const bool requestEcho) |
Setter for echo request. More... | |
uint8_t | getVersion (void) const |
Getter for version. More... | |
MyMessage & | setVersion (void) |
Setter for version. | |
uint8_t | getLength (void) const |
Getter for length. More... | |
MyMessage & | setLength (const uint8_t length) |
Setter for length. More... | |
mysensors_command_t | getCommand (void) const |
Getter for command type. More... | |
MyMessage & | setCommand (const mysensors_command_t command) |
Setter for command type. More... | |
mysensors_payload_t | getPayloadType (void) const |
Getter for payload type. More... | |
MyMessage & | setPayloadType (const mysensors_payload_t payloadType) |
Setter for payload type. More... | |
bool | getSigned (void) const |
Getter for sign field. More... | |
MyMessage & | setSigned (const bool signedFlag) |
Setter for sign field. More... | |
bool | isAck (void) const |
Getter for echo-flag. More... | |
bool | isEcho (void) const |
Getter for echo-flag. More... | |
MyMessage & | setEcho (const bool echo) |
Setter for echo-flag. More... | |
uint8_t | getType (void) const |
Get message type. More... | |
MyMessage & | setType (const uint8_t messageType) |
Set message type. More... | |
uint8_t | getLast (void) const |
Get last ID. More... | |
MyMessage & | setLast (const uint8_t lastId) |
Set last ID. More... | |
uint8_t | getSender (void) const |
Get sender ID. More... | |
MyMessage & | setSender (const uint8_t senderId) |
Set sender ID. More... | |
uint8_t | getSensor (void) const |
Get sensor ID of message. More... | |
MyMessage & | setSensor (const uint8_t sensorId) |
Set which child sensor this message belongs to. More... | |
uint8_t | getDestination (void) const |
Get destination. More... | |
MyMessage & | setDestination (const uint8_t destinationId) |
Set final destination node id for this message. More... | |
MyMessage & | set (const void *payload, const size_t length) |
Set entire payload. More... | |
MyMessage & | set (const char *value) |
Set payload to character array. More... | |
MyMessage & | set (const float value, const uint8_t decimals) |
Set payload to decimal number. More... | |
MyMessage & | set (const bool value) |
Set payload to bool value. More... | |
MyMessage & | set (const uint8_t value) |
Set payload to unsigned 8-bit integer value. More... | |
MyMessage & | set (const uint32_t value) |
Set payload to unsigned 32-bit integer value. More... | |
MyMessage & | set (const int32_t value) |
Set payload to signed 32-bit integer value. More... | |
MyMessage & | set (const uint16_t value) |
Set payload to unsigned 16-bit integer value. More... | |
MyMessage & | set (const int16_t value) |
Set payload to signed 16-bit integer value. More... | |
Variables | |
uint8_t | bValue |
unsigned byte value (8-bit) | |
uint16_t | uiValue |
unsigned integer value (16-bit) | |
int16_t | iValue |
signed integer value (16-bit) | |
uint32_t | ulValue |
unsigned long value (32-bit) | |
int32_t | lValue |
signed long value (32-bit) | |
struct { | |
float fValue | |
< Float messages | |
uint8_t fPrecision | |
Number of decimals when serializing. | |
}; | |
char | data [MAX_PAYLOAD_SIZE+1] |
Buffer for raw payload data. | |
uint8_t | last |
8 bit - Id of last node this message passed | |
uint8_t | sender |
8 bit - Id of sender node (origin) | |
uint8_t | destination |
8 bit - Id of destination node | |
uint8_t | version_length |
uint8_t | command_echo_payload |
uint8_t | type |
8 bit - Type varies depending on command | |
uint8_t | sensor |
8 bit - Id of sensor that this message concerns. | |
struct { | |
float fValue | |
< Float messages | |
uint8_t fPrecision | |
Number of decimals when serializing. | |
}; | |
bool __attribute__::getBool | ( | void | ) | const |
Get bool payload.
uint8_t __attribute__::getByte | ( | void | ) | const |
Get unsigned 8-bit integer payload.
mysensors_command_t __attribute__::getCommand | ( | void | ) | const |
Getter for command type.
void* __attribute__::getCustom | ( | void | ) | const |
Get custom payload.
uint8_t __attribute__::getDestination | ( | void | ) | const |
Get destination.
uint8_t __attribute__::getExpectedMessageSize | ( | void | ) | const |
getExpectedMessageSize
float __attribute__::getFloat | ( | void | ) | const |
Get float payload.
uint8_t __attribute__::getHeaderSize | ( | void | ) | const |
getHeaderSize
int16_t __attribute__::getInt | ( | void | ) | const |
Get signed 16-bit integer payload.
uint8_t __attribute__::getLast | ( | void | ) | const |
Get last ID.
uint8_t __attribute__::getLength | ( | void | ) | const |
Getter for length.
int32_t __attribute__::getLong | ( | void | ) | const |
Get signed 32-bit integer payload.
uint8_t __attribute__::getMaxPayloadSize | ( | void | ) | const |
getMaxPayloadSize
mysensors_payload_t __attribute__::getPayloadType | ( | void | ) | const |
Getter for payload type.
bool __attribute__::getRequestEcho | ( | void | ) | const |
Getter for echo request.
uint8_t __attribute__::getSender | ( | void | ) | const |
Get sender ID.
uint8_t __attribute__::getSensor | ( | void | ) | const |
Get sensor ID of message.
bool __attribute__::getSigned | ( | void | ) | const |
Getter for sign field.
char* __attribute__::getStream | ( | char * | buffer | ) | const |
If payload is something else than P_STRING you can have the payload value converted into string representation by supplying a buffer with the minimum size of 2 * MAX_PAYLOAD_SIZE + 1. This is to be able to fit hex-conversion of a full binary payload.
buffer | pointer to a buffer that's at least 2 * MAX_PAYLOAD_SIZE + 1 bytes large |
const char* __attribute__::getString | ( | void | ) | const |
Get payload as string.
uint8_t __attribute__::getType | ( | void | ) | const |
Get message type.
uint16_t __attribute__::getUInt | ( | void | ) | const |
Get unsigned 16-bit integer payload.
uint32_t __attribute__::getULong | ( | void | ) | const |
Get unsigned 32-bit integer payload.
uint8_t __attribute__::getVersion | ( | void | ) | const |
Getter for version.
bool __attribute__::isAck | ( | void | ) | const |
bool __attribute__::isEcho | ( | void | ) | const |
Getter for echo-flag.
bool __attribute__::isProtocolVersionValid | ( | void | ) | const |
isProtocolVersionValid
__attribute__::MyMessage | ( | const uint8_t | sensorId, |
const mysensors_data_t | dataType | ||
) |
Constructor
sensorId | id of the child sensor for this message |
dataType |
__attribute__::MyMessage | ( | void | ) |
Default constructor
MyMessage& __attribute__::set | ( | const bool | value | ) |
Set payload to bool value.
value | true or false |
MyMessage & set | ( | const char * | value | ) |
Set payload to character array.
Set payload to character array from flash.
value | pointer to the character array. The array must be null-terminated. |
MyMessage& __attribute__::set | ( | const float | value, |
const uint8_t | decimals | ||
) |
Set payload to decimal number.
value | float |
decimals | number of decimals to include |
MyMessage& __attribute__::set | ( | const int16_t | value | ) |
Set payload to signed 16-bit integer value.
value | (–32768 to 32767) |
MyMessage& __attribute__::set | ( | const int32_t | value | ) |
Set payload to signed 32-bit integer value.
value | (–2147483648 to 2147483647) |
MyMessage& __attribute__::set | ( | const uint16_t | value | ) |
Set payload to unsigned 16-bit integer value.
value | (0 to 65535) |
MyMessage& __attribute__::set | ( | const uint32_t | value | ) |
Set payload to unsigned 32-bit integer value.
value | (0 to 4294967295) |
MyMessage& __attribute__::set | ( | const uint8_t | value | ) |
Set payload to unsigned 8-bit integer value.
value | (0 to 255) |
MyMessage& __attribute__::set | ( | const void * | payload, |
const size_t | length | ||
) |
Set entire payload.
payload | pointer to the buffer where the payload is stored |
length | of the payload |
MyMessage& __attribute__::setCommand | ( | const mysensors_command_t | command | ) |
Setter for command type.
command |
MyMessage& __attribute__::setDestination | ( | const uint8_t | destinationId | ) |
Set final destination node id for this message.
destinationId |
MyMessage& __attribute__::setEcho | ( | const bool | echo | ) |
Setter for echo-flag.
echo | true if this an echo message |
MyMessage& __attribute__::setLast | ( | const uint8_t | lastId | ) |
Set last ID.
lastId |
MyMessage& __attribute__::setLength | ( | const uint8_t | length | ) |
Setter for length.
length |
MyMessage& __attribute__::setPayloadType | ( | const mysensors_payload_t | payloadType | ) |
Setter for payload type.
payloadType |
MyMessage& __attribute__::setRequestEcho | ( | const bool | requestEcho | ) |
Setter for echo request.
requestEcho |
MyMessage& __attribute__::setSender | ( | const uint8_t | senderId | ) |
Set sender ID.
senderId |
MyMessage& __attribute__::setSensor | ( | const uint8_t | sensorId | ) |
Set which child sensor this message belongs to.
sensorId |
MyMessage& __attribute__::setSigned | ( | const bool | signedFlag | ) |
Setter for sign field.
signedFlag |
MyMessage& __attribute__::setType | ( | const uint8_t | messageType | ) |
Set message type.
messageType |
uint8_t command_echo_payload |
3 bit - Command type
1 bit - Request an echo - Indicator that receiver should echo the message back to the sender
1 bit - Is echo message - Indicator that this is the echoed message
3 bit - Payload data type
Definition at line 351 of file MyMessage.h.
uint8_t version_length |
2 bit - Protocol version
1 bit - Signed flag
5 bit - Length of payload
Definition at line 343 of file MyMessage.h.