MySensors Library & Examples  2.3.2-62-ge298769
Public Member Functions | Public Attributes | List of all members

Detailed Description

MyMessage is used to create, manipulate, send and read MySensors messages.

Examples
SecureActuator.ino.

Definition at line 290 of file MyMessage.h.

#include <MyMessage.h>

+ Collaboration diagram for MyMessage:

Public Member Functions

 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...
 
MyMessagesetRequestEcho (const bool requestEcho)
 Setter for echo request. More...
 
uint8_t getVersion (void) const
 Getter for version. More...
 
MyMessagesetVersion (void)
 Setter for version.
 
uint8_t getLength (void) const
 Getter for length. More...
 
MyMessagesetLength (const uint8_t length)
 Setter for length. More...
 
mysensors_command_t getCommand (void) const
 Getter for command type. More...
 
MyMessagesetCommand (const mysensors_command_t command)
 Setter for command type. More...
 
mysensors_payload_t getPayloadType (void) const
 Getter for payload type. More...
 
MyMessagesetPayloadType (const mysensors_payload_t payloadType)
 Setter for payload type. More...
 
bool getSigned (void) const
 Getter for sign field. More...
 
MyMessagesetSigned (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...
 
MyMessagesetEcho (const bool echo)
 Setter for echo-flag. More...
 
uint8_t getType (void) const
 Get message type. More...
 
MyMessagesetType (const uint8_t messageType)
 Set message type. More...
 
uint8_t getLast (void) const
 Get last ID. More...
 
MyMessagesetLast (const uint8_t lastId)
 Set last ID. More...
 
uint8_t getSender (void) const
 Get sender ID. More...
 
MyMessagesetSender (const uint8_t senderId)
 Set sender ID. More...
 
uint8_t getSensor (void) const
 Get sensor ID of message. More...
 
MyMessagesetSensor (const uint8_t sensorId)
 Set which child sensor this message belongs to. More...
 
uint8_t getDestination (void) const
 Get destination. More...
 
MyMessagesetDestination (const uint8_t destinationId)
 Set final destination node id for this message. More...
 
MyMessageset (const void *payload, const size_t length)
 Set entire payload. More...
 
MyMessageset (const char *value)
 Set payload to character array. More...
 
MyMessageset (const __FlashStringHelper *value)
 Set payload to character array from flash. More...
 
MyMessageset (const float value, const uint8_t decimals)
 Set payload to decimal number. More...
 
MyMessageset (const bool value)
 Set payload to bool value. More...
 
MyMessageset (const uint8_t value)
 Set payload to unsigned 8-bit integer value. More...
 
MyMessageset (const uint32_t value)
 Set payload to unsigned 32-bit integer value. More...
 
MyMessageset (const int32_t value)
 Set payload to signed 32-bit integer value. More...
 
MyMessageset (const uint16_t value)
 Set payload to unsigned 16-bit integer value. More...
 
MyMessageset (const int16_t value)
 Set payload to signed 16-bit integer value. More...
 
union {
   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.
 
   }   __attribute__
 
   char   data [MAX_PAYLOAD_SIZE+1]
 Buffer for raw payload data.
 
__attribute__ ((packed))
 Doxygen will complain without this comment.
 

Public Attributes

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.
 

Constructor & Destructor Documentation

◆ MyMessage() [1/2]

MyMessage::MyMessage ( void  )

Default constructor

◆ MyMessage() [2/2]

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

Constructor

Parameters
sensorIdid of the child sensor for this message
dataType

Member Function Documentation

◆ getBool()

bool MyMessage::getBool ( void  ) const

Get bool payload.

Returns
a bool with the value of the payload (true/false)
Examples
SecureActuator.ino.

◆ getByte()

uint8_t MyMessage::getByte ( void  ) const

Get unsigned 8-bit integer payload.

Returns
the value of the payload, 0 to 255

◆ getCommand()

mysensors_command_t MyMessage::getCommand ( void  ) const

Getter for command type.

Returns
mysensors_command_t

◆ getCustom()

void* MyMessage::getCustom ( void  ) const

Get custom payload.

Returns
pointer to the raw payload

◆ getDestination()

uint8_t MyMessage::getDestination ( void  ) const

Get destination.

Returns
destinationId

◆ getExpectedMessageSize()

uint8_t MyMessage::getExpectedMessageSize ( void  ) const

getExpectedMessageSize

Returns
the expected message size based on header information

◆ getFloat()

float MyMessage::getFloat ( void  ) const

Get float payload.

Returns
the floating-point value of the payload

◆ getHeaderSize()

uint8_t MyMessage::getHeaderSize ( void  ) const

getHeaderSize

Returns
the size of the header

◆ getInt()

int16_t MyMessage::getInt ( void  ) const

Get signed 16-bit integer payload.

Returns
the value of the payload, –32768 to 32767

◆ getLast()

uint8_t MyMessage::getLast ( void  ) const

Get last ID.

Returns
lastId

◆ getLength()

uint8_t MyMessage::getLength ( void  ) const

Getter for length.

Returns
length

◆ getLong()

int32_t MyMessage::getLong ( void  ) const

Get signed 32-bit integer payload.

Returns
the value of the payload, –2147483648 to 2147483647

◆ getMaxPayloadSize()

uint8_t MyMessage::getMaxPayloadSize ( void  ) const

getMaxPayloadSize

Returns
the max. size of the payload

◆ getPayloadType()

mysensors_payload_t MyMessage::getPayloadType ( void  ) const

Getter for payload type.

Returns
payload type

◆ getRequestEcho()

bool MyMessage::getRequestEcho ( void  ) const

Getter for echo request.

Returns
echo request

◆ getSender()

uint8_t MyMessage::getSender ( void  ) const

Get sender ID.

Returns
sender

◆ getSensor()

uint8_t MyMessage::getSensor ( void  ) const

Get sensor ID of message.

Returns
sensorId
Examples
SecureActuator.ino.

◆ getSigned()

bool MyMessage::getSigned ( void  ) const

Getter for sign field.

Returns
sign field

◆ getStream()

char* MyMessage::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* MyMessage::getString ( void  ) const

Get payload as string.

Returns
pointer to a char array storing the string

◆ getType()

uint8_t MyMessage::getType ( void  ) const

Get message type.

Returns
messageType
Examples
SecureActuator.ino.

◆ getUInt()

uint16_t MyMessage::getUInt ( void  ) const

Get unsigned 16-bit integer payload.

Returns
the value of the payload, 0 to 65535

◆ getULong()

uint32_t MyMessage::getULong ( void  ) const

Get unsigned 32-bit integer payload.

Returns
the value of the payload, 0 to 4294967295

◆ getVersion()

uint8_t MyMessage::getVersion ( void  ) const

Getter for version.

Returns
version

◆ isAck()

bool MyMessage::isAck ( void  ) const

Getter for echo-flag.

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

◆ isEcho()

bool MyMessage::isEcho ( void  ) const

Getter for echo-flag.

Returns
true if this is an echoed message
Examples
SecureActuator.ino.

◆ isProtocolVersionValid()

bool MyMessage::isProtocolVersionValid ( void  ) const

isProtocolVersionValid

Returns
true if the protocol version is valid

◆ set() [1/10]

MyMessage& MyMessage::set ( const __FlashStringHelper *  value)

Set payload to character array from flash.

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

◆ set() [2/10]

MyMessage& MyMessage::set ( const bool  value)

Set payload to bool value.

Parameters
valuetrue or false

◆ set() [3/10]

MyMessage& MyMessage::set ( const char *  value)

Set payload to character array.

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

◆ set() [4/10]

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

Set payload to decimal number.

Parameters
valuefloat
decimalsnumber of decimals to include

◆ set() [5/10]

MyMessage& MyMessage::set ( const int16_t  value)

Set payload to signed 16-bit integer value.

Parameters
value(–32768 to 32767)

◆ set() [6/10]

MyMessage& MyMessage::set ( const int32_t  value)

Set payload to signed 32-bit integer value.

Parameters
value(–2147483648 to 2147483647)

◆ set() [7/10]

MyMessage& MyMessage::set ( const uint16_t  value)

Set payload to unsigned 16-bit integer value.

Parameters
value(0 to 65535)

◆ set() [8/10]

MyMessage& MyMessage::set ( const uint32_t  value)

Set payload to unsigned 32-bit integer value.

Parameters
value(0 to 4294967295)

◆ set() [9/10]

MyMessage& MyMessage::set ( const uint8_t  value)

Set payload to unsigned 8-bit integer value.

Parameters
value(0 to 255)

◆ set() [10/10]

MyMessage& MyMessage::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& MyMessage::setCommand ( const mysensors_command_t  command)

Setter for command type.

Parameters
command

◆ setDestination()

MyMessage& MyMessage::setDestination ( const uint8_t  destinationId)

Set final destination node id for this message.

Parameters
destinationId

◆ setEcho()

MyMessage& MyMessage::setEcho ( const bool  echo)

Setter for echo-flag.

Parameters
echotrue if this an echo message

◆ setLast()

MyMessage& MyMessage::setLast ( const uint8_t  lastId)

Set last ID.

Parameters
lastId

◆ setLength()

MyMessage& MyMessage::setLength ( const uint8_t  length)

Setter for length.

Parameters
length

◆ setPayloadType()

MyMessage& MyMessage::setPayloadType ( const mysensors_payload_t  payloadType)

Setter for payload type.

Parameters
payloadType

◆ setRequestEcho()

MyMessage& MyMessage::setRequestEcho ( const bool  requestEcho)

Setter for echo request.

Parameters
requestEcho

◆ setSender()

MyMessage& MyMessage::setSender ( const uint8_t  senderId)

Set sender ID.

Parameters
senderId

◆ setSensor()

MyMessage& MyMessage::setSensor ( const uint8_t  sensorId)

Set which child sensor this message belongs to.

Parameters
sensorId

◆ setSigned()

MyMessage& MyMessage::setSigned ( const bool  signedFlag)

Setter for sign field.

Parameters
signedFlag

◆ setType()

MyMessage& MyMessage::setType ( const uint8_t  messageType)

Set message type.

Parameters
messageType

Member Data Documentation

◆ command_echo_payload

uint8_t MyMessage::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 641 of file MyMessage.h.

◆ version_length

uint8_t MyMessage::version_length

2 bit - Protocol version
1 bit - Signed flag
5 bit - Length of payload

Definition at line 633 of file MyMessage.h.


The documentation for this class was generated from the following file: