-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlifx.cpp
72 lines (59 loc) · 2.45 KB
/
lifx.cpp
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
#include "lifx.h"
LifxPacket::LifxPacket(uint8_t* rawData, int dataLen) {
if (dataLen >= sizeof(LifxPacketHeader)) {
LifxPacketHeader header;
memcpy((void*)&mHeader, rawData, sizeof(LifxPacketHeader));
mPayloadSize = (dataLen-sizeof(LifxPacketHeader));
memcpy(mPayload, rawData+sizeof(LifxPacketHeader), mPayloadSize);
print();
}
}
LifxPacket::LifxPacket(byte type, byte* data, int dataLen, uint32_t source, uint8_t sequence){
mHeader.size = sizeof(mHeader) + dataLen;
mHeader.protocol = LifxProtocol_AllBulbsResponse;
mHeader.addressable = 0;
mHeader.tagged = 0;
mHeader.origin = 1; // WHAT SHOULD THIS BE
mHeader.source = source; // COULD NEED TO CHANGE THIS BASED ON PREVIOUS PACKET
mHeader.res_required = 0;
mHeader.ack_required = 0;
mHeader.sequence = sequence; // COULD NEED TO CHANGE THIS BASED ON PREVIOUS PACKET
mHeader.type = type;
for (int i=0; i < 8; ++i) {
mHeader.target[i] = 0;
}
for (int i=0; i < dataLen; ++i) {
mPayload[i] = data[i];
}
mPayloadSize = dataLen;
}
void LifxPacket::print() {
// commented post-debugging
// Serial1.printf(" header.size = %d\r\n", mHeader.size);
// Serial1.printf(" header.protocol = %d\r\n", mHeader.protocol);
// Serial1.printf(" header.addressable = %d\r\n", mHeader.addressable);
// Serial1.printf(" header.tagged = %d\r\n", mHeader.tagged);
// Serial1.printf(" header.origin = %d\r\n", mHeader.origin);
// Serial1.printf(" header.source = %d\r\n", mHeader.source);
// Serial1.printf(" header.target = ");
// for(int i = 0; i < 8; i++) {
// Serial1.printf(" %.2X", mHeader.target[i]);
// }
// Serial1.printf("\r\n");
// Serial1.printf(" header.res_required = %d\r\n", mHeader.res_required);
// Serial1.printf(" header.ack_required = %d\r\n", mHeader.ack_required);
// Serial1.printf(" header.sequence = %d\r\n", mHeader.sequence);
// Serial1.printf(" header.type = %X\r\n", mHeader.type);
// Serial1.printf(" payload\(%.2d\) = ", mPayloadSize);
// for(int i = 0; i < mPayloadSize; i++) {
// if (!(i % 8)) { Serial1.printf("\r\n "); }
// Serial1.printf(" %.2X", mPayload[i]);
// }
// Serial1.printf("\r\n");
// Serial1.printf("\r\n");
}
void LifxPacket::setTarget(byte* mac){
for(int i=0;i<6;i++) {
mHeader.target[i] = mac[i];
}
}