-
-
Notifications
You must be signed in to change notification settings - Fork 895
Message.h
Henrik Ekblad edited this page Apr 17, 2014
·
2 revisions
#ifndef Message_h
#define Message_h
#include <Arduino.h>
#define PROTOCOL_VERSION 2
// Message types
typedef enum {
M_SET = 0,
M_REQUEST = 1,
M_INTERNAL = 2,
M_PRESENTATION
} commandType;
// Sensor variables that can be used in sketches
typedef enum {
V_TEMP,V_HUM, V_LIGHT, V_DIMMER, V_PRESSURE, V_FORECAST, V_RAIN,
V_RAINRATE, V_WIND, V_GUST, V_DIRECTION, V_UV, V_WEIGHT, V_DISTANCE,
V_IMPEDANCE, V_ARMED, V_TRIPPED, V_WATT, V_KWH, V_SCENE_ON, V_SCENE_OFF,
V_HEATER, V_HEATER_SW, V_LIGHT_LEVEL, V_VAR1, V_VAR2, V_VAR3, V_VAR4, V_VAR5,
V_UP, V_DOWN, V_STOP, V_IR_SEND, V_IR_RECEIVE, V_FLOW, V_VOLUME, V_LOCK_STATUS
} variableType;
// Internal messages
// Remove I_BATTERY_DATE, I_LAST_TRIP, I_LAST_UPDATE
typedef enum {
I_BATTERY_LEVEL, I_TIME, I_VERSION, I_REQUEST_ID,
I_INCLUSION_MODE, I_RELAY_NODE, I_PING, I_PING_ACK,
I_LOG_MESSAGE, I_CHILDREN, I_UNIT, I_SKETCH_NAME, I_SKETCH_VERSION
} internalMessageType;
// Sensor types
typedef enum {
S_DOOR, S_MOTION, S_SMOKE, S_LIGHT, S_DIMMER, S_COVER, S_TEMP, S_HUM, S_BARO, S_WIND,
S_RAIN, S_UV, S_WEIGHT, S_POWER, S_HEATER, S_DISTANCE, S_LIGHT_LEVEL, S_ARDUINO_NODE,
S_ARDUINO_RELAY, S_LOCK, S_IR, S_WATER
} sensor;
// Possible return values by validate() when doing crc check of received message.
enum {
VALIDATE_OK, VALIDATE_BAD_CRC, VALIDATE_BAD_VERSION
};
#define MAX_MESSAGE_LENGTH 32
// The message structure
typedef struct {
uint8_t crc : 8; // 8 bits crc
uint8_t version : 3; // 3 bits protocol version
uint8_t requestAck : 1; // Set to 1 if this message should be acked
uint8_t isAck : 1; // Set to 1 if this is the actual ack message
uint8_t binary : 1; // 1 bit. Data is binary and should be encoded when sent to sensor net gateway
uint8_t commandType : 2; // 4 bits. Type of message. See commandType
uint8_t type : 8; // 8 bits. variableType or deviceType depending on messageType
uint8_t from : 8; // 8 bits. RadioId of sender node
uint8_t to : 8; // 8 bits. RadioId of destination node
uint8_t last : 8; // 8 bits. RadioId of last node this message passed
uint8_t childId : 8; // 1 byte. Up to MAX_CHILD_DEVICES child sensors per radioId
} header_s;
typedef struct {
header_s header;
char data[MAX_MESSAGE_LENGTH - sizeof(header_s) + 1]; // Each message can transfer a payload. Add one extra byte for \0
} message_s;
class Message
{
public:
Message(boolean ack=false);
void setDestination(uint8_t destination);
void setAck(boolean enableAck);
void setString();
void setIntValue()
void setLongValue()
void getStringValue();
void getIntValue();
void getLongValue();
private:
message_s msg;
bool ack;
int intValue;
float floatValue;
};
#endif