-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlifx.h
162 lines (125 loc) · 4.26 KB
/
lifx.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#ifndef LIFX_H
#define LIFX_H
#include "application.h"
// struct LifxPacket {
// uint16_t size; //little endian
// uint16_t protocol; //little endian
// uint32_t reserved1;
// byte bulbAddress[6];
// uint16_t reserved2;
// byte site[6];
// uint16_t reserved3;
// uint64_t timestamp;
// uint16_t packet_type; //little endian
// uint16_t reserved4;
// byte data[128];
// int data_size;
// };
#pragma pack(push, 1)
struct LifxPacketHeader{
/* frame */
uint16_t size;
uint16_t protocol:12;
uint8_t addressable:1;
uint8_t tagged:1;
uint8_t origin:2;
uint32_t source;
/* frame address */
uint8_t target[8];
uint8_t reserved[6];
uint8_t res_required:1;
uint8_t ack_required:1;
uint8_t :6;
uint8_t sequence;
/* protocol header */
uint64_t :64;
uint16_t type;
uint16_t :16;
/* variable length payload follows */
};
#pragma pack(pop)
const unsigned int LifxProtocol_AllBulbsResponse = 21504; // 0x5400
const unsigned int LifxProtocol_AllBulbsRequest = 13312; // 0x3400
const unsigned int LifxProtocol_BulbCommand = 5120; // 0x1400
const unsigned int LifxPacketSize = 36;
const unsigned int LifxPort = 56700; // local port to listen on
const unsigned int LifxBulbLabelLength = 32;
const unsigned int LifxBulbTagsLength = 8;
const unsigned int LifxBulbTagLabelsLength = 32;
const unsigned int LifxBulbLocationIDLength = 16;
const unsigned int LifxBulbLocationLabelLength = 32;
const unsigned int LifxBulbLocationUpdatedAtLength = 8;
const unsigned int LifxBulbGroupIDLength = 16;
const unsigned int LifxBulbGroupLabelLength = 32;
const unsigned int LifxBulbGroupUpdatedAtLength = 8;
// firmware versions, etc
const unsigned int LifxBulbVendor = 1;
const unsigned int LifxBulbProduct = 1;
const unsigned int LifxBulbVersion = 1;
const unsigned int LifxFirmwareVersionMajor = 1;
const unsigned int LifxFirmwareVersionMinor = 5;
const byte SERVICE_UDP = 0x01;
const byte SERVICE_TCP = 0x02;
// packet types
const byte GET_PAN_GATEWAY = 0x02;
const byte PAN_GATEWAY = 0x03;
const byte GET_WIFI_FIRMWARE_STATE = 0x12;
const byte WIFI_FIRMWARE_STATE = 0x13;
const byte GET_POWER_STATE = 0x14;
const byte GET_POWER_STATE2 = 0x74;
const byte SET_POWER_STATE = 0x75;
const byte SET_POWER_STATE2 = 0x15;
const byte POWER_STATE = 0x16;
const byte POWER_STATE2 = 0x76;
const byte GET_BULB_LABEL = 0x17;
const byte SET_BULB_LABEL = 0x18;
const byte BULB_LABEL = 0x19;
const byte GET_VERSION_STATE = 0x20;
const byte VERSION_STATE = 0x21;
const byte GET_BULB_TAGS = 0x1a;
const byte SET_BULB_TAGS = 0x1b;
const byte BULB_TAGS = 0x1c;
const byte GET_BULB_TAG_LABELS = 0x1d;
const byte SET_BULB_TAG_LABELS = 0x1e;
const byte BULB_TAG_LABELS = 0x1f;
const byte DEVICE_GET_LOCATION = 0x30;
const byte DEVICE_SET_LOCATION = 0x31;
const byte DEVICE_STATE_LOCATION = 0x32;
const byte DEVICE_GET_GROUP = 0x33;
const byte DEVICE_SET_GROUP = 0x34;
const byte DEVICE_STATE_GROUP = 0x35;
const byte GET_LIGHT_STATE = 0x65;
const byte SET_LIGHT_STATE = 0x66;
const byte LIGHT_STATUS = 0x6b;
const byte GET_MESH_FIRMWARE_STATE = 0x0e;
const byte MESH_FIRMWARE_STATE = 0x0f;
#define EEPROM_BULB_LABEL_START 0 // 32 bytes long
#define EEPROM_BULB_TAGS_START 32 // 8 bytes long
#define EEPROM_BULB_TAG_LABELS_START 40 // 32 bytes long
#define EEPROM_LOCATION_START 72 // 56 bytes long
#define EEPROM_GROUP_START 128 // 56 bytes long
// future data for EEPROM will start at 184...
#define EEPROM_CONFIG "AL1" // 3 byte identifier for this sketch's EEPROM settings
#define EEPROM_CONFIG_START 253 // store EEPROM_CONFIG at the end of EEPROM
// helpers
#define SPACE " "
class LifxPacket {
public:
LifxPacket(uint8_t* rawData, int dataLen);
LifxPacket(byte type, byte* data, int dataLen, uint32_t source=0, uint8_t sequence=0);
LifxPacket() {}; // SMR REMOVE
~LifxPacket() {};
LifxPacketHeader getHeader() { return mHeader; }
byte* getPayload() { return mPayload; }
int getPayloadSize() { return mPayloadSize; }
byte getPacketType() { return mHeader.type; }
uint32_t getHeaderSource() { return mHeader.source; }
uint8_t getHeaderSequence() { return mHeader.sequence; }
void setTarget(byte* mac);
void print();
private:
LifxPacketHeader mHeader;
byte mPayload[256];
int mPayloadSize;
};
#endif