MySensors Library & Examples  2.3.2-121-g2834d0f8
Classes | Macros | Enumerations | Functions | Variables
MyMessage.h File Reference

Detailed Description

API and type declarations for MySensors messages.

Definition in file MyMessage.h.

+ This graph shows which files directly or indirectly include this file:

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()
 

Enumerations

enum  mysensors_command_t {
  C_PRESENTATION = 0, C_SET = 1, C_REQ = 2, C_INTERNAL = 3,
  C_STREAM = 4, C_RESERVED_5 = 5, C_RESERVED_6 = 6, C_INVALID_7 = 7
}
 The command field (message-type) defines the overall properties of a message. More...
 
enum  mysensors_internal_t {
  I_BATTERY_LEVEL = 0, I_TIME = 1, I_VERSION = 2, I_ID_REQUEST = 3,
  I_ID_RESPONSE = 4, I_INCLUSION_MODE = 5, I_CONFIG = 6, I_FIND_PARENT_REQUEST = 7,
  I_FIND_PARENT_RESPONSE = 8, I_LOG_MESSAGE = 9, I_CHILDREN = 10, I_SKETCH_NAME = 11,
  I_SKETCH_VERSION = 12, I_REBOOT = 13, I_GATEWAY_READY = 14, I_SIGNING_PRESENTATION = 15,
  I_NONCE_REQUEST = 16, I_NONCE_RESPONSE = 17, I_HEARTBEAT_REQUEST = 18, I_PRESENTATION = 19,
  I_DISCOVER_REQUEST = 20, I_DISCOVER_RESPONSE = 21, I_HEARTBEAT_RESPONSE = 22, I_LOCKED = 23,
  I_PING = 24, I_PONG = 25, I_REGISTRATION_REQUEST = 26, I_REGISTRATION_RESPONSE = 27,
  I_DEBUG = 28, I_SIGNAL_REPORT_REQUEST = 29, I_SIGNAL_REPORT_REVERSE = 30, I_SIGNAL_REPORT_RESPONSE = 31,
  I_PRE_SLEEP_NOTIFICATION = 32, I_POST_SLEEP_NOTIFICATION = 33
}
 Type of internal messages (for internal messages) More...
 
enum  mysensors_stream_t {
  ST_FIRMWARE_CONFIG_REQUEST = 0, ST_FIRMWARE_CONFIG_RESPONSE = 1, ST_FIRMWARE_REQUEST = 2, ST_FIRMWARE_RESPONSE = 3,
  ST_SOUND = 4, ST_IMAGE = 5, ST_FIRMWARE_CONFIRM = 6, ST_FIRMWARE_RESPONSE_RLE = 7
}
 Type of data stream (for streamed message) More...
 
enum  mysensors_payload_t {
  P_STRING = 0, P_BYTE = 1, P_INT16 = 2, P_UINT16 = 3,
  P_LONG32 = 4, P_ULONG32 = 5, P_CUSTOM = 6, P_FLOAT32 = 7
}
 Type of payload. More...
 

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.
 
}; 
 

Function Documentation

◆ getBool()

bool __attribute__::getBool ( void  ) const

Get bool payload.

Returns
a bool with the value of the payload (true/false)

◆ getByte()

uint8_t __attribute__::getByte ( void  ) const

Get unsigned 8-bit integer payload.

Returns
the value of the payload, 0 to 255

◆ getCommand()

mysensors_command_t __attribute__::getCommand ( void  ) const

Getter for command type.

Returns
mysensors_command_t

◆ getCustom()

void* __attribute__::getCustom ( void  ) const

Get custom payload.

Returns
pointer to the raw payload

◆ getDestination()

uint8_t __attribute__::getDestination ( void  ) const

Get destination.

Returns
destinationId

◆ getExpectedMessageSize()

uint8_t __attribute__::getExpectedMessageSize ( void  ) const

getExpectedMessageSize

Returns
the expected message size based on header information

◆ getFloat()

float __attribute__::getFloat ( void  ) const

Get float payload.

Returns
the floating-point value of the payload

◆ getHeaderSize()

uint8_t __attribute__::getHeaderSize ( void  ) const

getHeaderSize

Returns
the size of the header

◆ getInt()

int16_t __attribute__::getInt ( void  ) const

Get signed 16-bit integer payload.

Returns
the value of the payload, –32768 to 32767

◆ getLast()

uint8_t __attribute__::getLast ( void  ) const

Get last ID.

Returns
lastId

◆ getLength()

uint8_t __attribute__::getLength ( void  ) const

Getter for length.

Returns
length

◆ getLong()

int32_t __attribute__::getLong ( void  ) const

Get signed 32-bit integer payload.

Returns
the value of the payload, –2147483648 to 2147483647

◆ getMaxPayloadSize()

uint8_t __attribute__::getMaxPayloadSize ( void  ) const

getMaxPayloadSize

Returns
the max. size of the payload

◆ getPayloadType()

mysensors_payload_t __attribute__::getPayloadType ( void  ) const

Getter for payload type.

Returns
payload type

◆ getRequestEcho()

bool __attribute__::getRequestEcho ( void  ) const

Getter for echo request.

Returns
echo request

◆ getSender()

uint8_t __attribute__::getSender ( void  ) const

Get sender ID.

Returns
sender

◆ getSensor()

uint8_t __attribute__::getSensor ( void  ) const

Get sensor ID of message.

Returns
sensorId

◆ getSigned()

bool __attribute__::getSigned ( void  ) const

Getter for sign field.

Returns
sign field

◆ getStream()

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.

Parameters
bufferpointer to a buffer that's at least 2 * MAX_PAYLOAD_SIZE + 1 bytes large

◆ getString()

const char* __attribute__::getString ( void  ) const

Get payload as string.

Returns
pointer to a char array storing the string

◆ getType()

uint8_t __attribute__::getType ( void  ) const

Get message type.

Returns
messageType

◆ getUInt()

uint16_t __attribute__::getUInt ( void  ) const

Get unsigned 16-bit integer payload.

Returns
the value of the payload, 0 to 65535

◆ getULong()

uint32_t __attribute__::getULong ( void  ) const

Get unsigned 32-bit integer payload.

Returns
the value of the payload, 0 to 4294967295

◆ getVersion()

uint8_t __attribute__::getVersion ( void  ) const

Getter for version.

Returns
version

◆ isAck()

bool __attribute__::isAck ( void  ) const

Getter for echo-flag.

Deprecated:
use isEcho()
Returns
true if this is an echoed message

◆ isEcho()

bool __attribute__::isEcho ( void  ) const

Getter for echo-flag.

Returns
true if this is an echoed message

◆ isProtocolVersionValid()

bool __attribute__::isProtocolVersionValid ( void  ) const

isProtocolVersionValid

Returns
true if the protocol version is valid

◆ MyMessage() [1/2]

__attribute__::MyMessage ( const uint8_t  sensorId,
const mysensors_data_t  dataType 
)

Constructor

Parameters
sensorIdid of the child sensor for this message
dataType

◆ MyMessage() [2/2]

__attribute__::MyMessage ( void  )

Default constructor

◆ set() [1/9]

MyMessage& __attribute__::set ( const bool  value)

Set payload to bool value.

Parameters
valuetrue or false

◆ set() [2/9]

MyMessage & set ( const char *  value)

Set payload to character array.

Set payload to character array from flash.

Parameters
valuepointer to the character array. The array must be null-terminated.

◆ set() [3/9]

MyMessage& __attribute__::set ( const float  value,
const uint8_t  decimals 
)

Set payload to decimal number.

Parameters
valuefloat
decimalsnumber of decimals to include

◆ set() [4/9]

MyMessage& __attribute__::set ( const int16_t  value)

Set payload to signed 16-bit integer value.

Parameters
value(–32768 to 32767)

◆ set() [5/9]

MyMessage& __attribute__::set ( const int32_t  value)

Set payload to signed 32-bit integer value.

Parameters
value(–2147483648 to 2147483647)

◆ set() [6/9]

MyMessage& __attribute__::set ( const uint16_t  value)

Set payload to unsigned 16-bit integer value.

Parameters
value(0 to 65535)

◆ set() [7/9]

MyMessage& __attribute__::set ( const uint32_t  value)

Set payload to unsigned 32-bit integer value.

Parameters
value(0 to 4294967295)

◆ set() [8/9]

MyMessage& __attribute__::set ( const uint8_t  value)

Set payload to unsigned 8-bit integer value.

Parameters
value(0 to 255)

◆ set() [9/9]

MyMessage& __attribute__::set ( const void *  payload,
const size_t  length 
)

Set entire payload.

Parameters
payloadpointer to the buffer where the payload is stored
lengthof the payload

◆ setCommand()

MyMessage& __attribute__::setCommand ( const mysensors_command_t  command)

Setter for command type.

Parameters
command

◆ setDestination()

MyMessage& __attribute__::setDestination ( const uint8_t  destinationId)

Set final destination node id for this message.

Parameters
destinationId

◆ setEcho()

MyMessage& __attribute__::setEcho ( const bool  echo)

Setter for echo-flag.

Parameters
echotrue if this an echo message

◆ setLast()

MyMessage& __attribute__::setLast ( const uint8_t  lastId)

Set last ID.

Parameters
lastId

◆ setLength()

MyMessage& __attribute__::setLength ( const uint8_t  length)

Setter for length.

Parameters
length

◆ setPayloadType()

MyMessage& __attribute__::setPayloadType ( const mysensors_payload_t  payloadType)

Setter for payload type.

Parameters
payloadType

◆ setRequestEcho()

MyMessage& __attribute__::setRequestEcho ( const bool  requestEcho)

Setter for echo request.

Parameters
requestEcho

◆ setSender()

MyMessage& __attribute__::setSender ( const uint8_t  senderId)

Set sender ID.

Parameters
senderId

◆ setSensor()

MyMessage& __attribute__::setSensor ( const uint8_t  sensorId)

Set which child sensor this message belongs to.

Parameters
sensorId

◆ setSigned()

MyMessage& __attribute__::setSigned ( const bool  signedFlag)

Setter for sign field.

Parameters
signedFlag

◆ setType()

MyMessage& __attribute__::setType ( const uint8_t  messageType)

Set message type.

Parameters
messageType

Variable Documentation

◆ command_echo_payload

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.

◆ version_length

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.