1 #ifndef _LIFXHEADER_H__
2 #define _LIFXHEADER_H__
16 // Frame address variables
38 void setSize(int _size) {
40 cerr << "Header: size cannot be less than 0" << endl;
42 } else if (_size > 65535) {
43 cerr << "Header: size too large" << endl;
50 void setOrigin(int _origin) {
52 cerr << "Header: origin cannot be less than 0" << endl;
54 } else if (_origin > 3) {
55 cerr << "Header: origin too large" << endl;
62 void setTagged(bool _tagged) {
67 void setAddressable(bool _addressable) {
68 addressable = _addressable;
72 void setProtocol(int _protocol) {
74 cerr << "Header: protocol cannot be less than 0" << endl;
76 } else if (_protocol > 4095) {
77 cerr << "Header: protocol too large" << endl;
84 void setSource(int64_t _source) {
86 cerr << "Header: source cannot be less than 0" << endl;
88 } else if (_source > 4294967295) {
89 cerr << "Header: source too large" << endl;
96 void setSequence(int _sequence) {
98 cerr << "Header: sequence cannot be less than 0" << endl;
100 } else if (_sequence > 255) {
101 cerr << "Header: sequence too large" << endl;
104 sequence = _sequence;
108 void setType(int _type) {
110 cerr << "Header: type cannot be less than 0" << endl;
112 } else if (_type > 65535) {
113 cerr << "Header: type too large" << endl;
120 void setAck_required(bool _ack_required) {
121 ack_required = _ack_required;
125 void setRes_required(bool _res_required) {
126 res_required = _res_required;
130 void setMacAddress(char _macAddress[8]) {
131 strcpy(macAddress, _macAddress);
150 bool getAddressable() {
160 int64_t getSource() {
165 int64_t getSequence() {
175 char* getHeaderBytes(char headerBytes[36]) {
177 //char headerBytes[36];
178 headerBytes[0] = (char)(size & 0xFF);
179 headerBytes[1] = (char)((size >> 8) & 0xFF);
182 headerBytes[2] = (char)(protocol & 0xFF);
183 headerBytes[3] = (char)((protocol >> 8) & 0x0F);
185 headerBytes[3] |= (char)((origin & 0x03) << 6);
188 headerBytes[3] |= (1 << 5);
192 headerBytes[3] |= (1 << 4);
195 headerBytes[4] = (char)((source >> 0) & 0xFF);
196 headerBytes[5] = (char)((source >> 8) & 0xFF);
197 headerBytes[6] = (char)((source >> 16) & 0xFF);
198 headerBytes[7] = (char)((source >> 24) & 0xFF);
201 headerBytes[8] = macAddress[0];
202 headerBytes[9] = macAddress[1];
203 headerBytes[10] = macAddress[2];
204 headerBytes[11] = macAddress[3];
205 headerBytes[12] = macAddress[4];
206 headerBytes[13] = macAddress[5];
207 headerBytes[14] = macAddress[6];
208 headerBytes[15] = macAddress[7];
210 // Reserved and set to 0
219 headerBytes[22] = (1 << 1);
223 headerBytes[22] |= (1);
226 headerBytes[23] = (char)(sequence & 0xFF);
228 // Reserved and set to 0
238 headerBytes[32] = (char)((type >> 0) & 0xFF);
239 headerBytes[33] = (char)((type >> 8) & 0xFF);
241 // Reserved and set to 0
249 void setFromBytes(char dataBytes[36]) {
251 size = dataBytes[0] & 0xFF;
252 size |= ((dataBytes[1] & 0xFF) << 8);
255 origin = (dataBytes[3] >> 6) & 0x03;
256 tagged = ((dataBytes[3] >> 5) & 0x01) == 1;
257 addressable = ((dataBytes[3] >> 4) & 0x01) == 1;
260 protocol = (dataBytes[3] & 0x0F) << 8;
261 protocol |= dataBytes[2];
264 source = (dataBytes[7] & 0xFFl) << 24;
265 source |= ((dataBytes[6] & 0xFFl) << 16);
266 source |= ((dataBytes[5] & 0xFFl) << 8);
267 source |= ((dataBytes[4] & 0xFFl));
269 macAddress[0] = dataBytes[8];
270 macAddress[1] = dataBytes[9];
271 macAddress[2] = dataBytes[10];
272 macAddress[3] = dataBytes[11];
273 macAddress[4] = dataBytes[12];
274 macAddress[5] = dataBytes[13];
275 macAddress[6] = dataBytes[14];
276 macAddress[7] = dataBytes[15];
278 ack_required = (dataBytes[22] & 0x02) == 0x02;
279 res_required = (dataBytes[22] & 0x01) == 0x01;
281 sequence = (dataBytes[23] & 0xFF);
283 type = ((dataBytes[33] & 0xFF) << 8);
284 type |= (dataBytes[32] & 0xFF);