MyMessage& MyMessage::set(const char* value) { uint8_t length = min(strlen(value), MAX_PAYLOAD); miSetLength(length); miSetPayloadType(P_STRING); strncpy(data, value, length); return *this; }
MyMessage& MyMessage::set(float value, uint8_t decimals) { miSetLength(5); // 32 bit float + persi miSetPayloadType(P_FLOAT32); fValue=value; fPrecision = decimals; return *this; }
// Set payload MyMessage& MyMessage::set(void* value, uint8_t length) { uint8_t payloadLength = value == NULL ? 0 : min(length, (uint8_t)MAX_PAYLOAD); miSetLength(payloadLength); miSetPayloadType(P_CUSTOM); memcpy(data, value, payloadLength); return *this; }
MyMessage& MyMessage::set(const char* value) { uint8_t length = value == NULL ? 0 : min(strlen(value), MAX_PAYLOAD); miSetLength(length); miSetPayloadType(P_STRING); if (length) { strncpy(data, value, length); } // null terminate string data[length] = 0; return *this; }
MyMessage& MyMessage::set(int value) { miSetPayloadType(P_INT16); miSetLength(2); iValue = value; return *this; }
MyMessage& MyMessage::set(unsigned int value) { miSetPayloadType(P_UINT16); miSetLength(2); uiValue = value; return *this; }
MyMessage& MyMessage::set(long value) { miSetPayloadType(P_LONG32); miSetLength(4); lValue = value; return *this; }
MyMessage& MyMessage::set(unsigned long value) { miSetPayloadType(P_ULONG32); miSetLength(4); ulValue = value; return *this; }
MyMessage& MyMessage::set(uint8_t value) { miSetLength(1); miSetPayloadType(P_BYTE); data[0] = value; return *this; }
// Set payload MyMessage& MyMessage::set(void* value, uint8_t length) { miSetPayloadType(P_CUSTOM); miSetLength(length); memcpy(data, value, min(length, MAX_PAYLOAD)); return *this; }
MyMessage& MyMessage::set(uint32_t value) { miSetPayloadType(P_ULONG32); miSetLength(4); ulValue = value; return *this; }