forked from KONNEKTING/EnOceanGateway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EnOceanDevice_NodOn_2Ch.h
185 lines (159 loc) · 4.53 KB
/
EnOceanDevice_NodOn_2Ch.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#ifndef ENOCEANDEVICE_NODON_2CH_H_
#define ENOCEANDEVICE_NODON_2CH_H_
#include "EnOcean.h"
class EnOceanDevice_NodOn_2Ch: public IEnOceanDevice
{
private:
uint32_t actorId = 0;
uint8_t actorId_Arr[4] = { 0, 0, 0, 0 };
uint32_t nextPollTime = 0;
uint32_t pollFrequencyMillis = (uint32_t)600000; // 10 minutes
bool status_request = false;
public:
EnOceanDevice_NodOn_2Ch()
{
numberOfComObjects = 2;
numberOfParameters = 2;
}
// pre-configure device, set sender-id etc.
void init(uint8_t startAtComObj, uint8_t startAtParameter)
{
firstComObj = startAtComObj;
firstParameter = startAtParameter;
// we only store the first comObj as this information is sufficient to identify all the com-objects
// regarding configuration:
actorId = ((uint32_t) Konnekting.getUINT32Param(startAtParameter));
actorId_Arr[0] = actorId >> 24;
actorId_Arr[1] = actorId >> 16;
actorId_Arr[2] = actorId >> 8;
actorId_Arr[3] = actorId;
#ifdef KDEBUG
Debug.print(F("I am: "));
for (int i = 0; i < BASEID_BYTES; i++)
{
Debug.print(F("%X"), actorId_Arr[i]);
}
Debug.println(F(""));
#endif
// ignore second config-item for the moment
}
void getStatusActors(uint8_t* mySenderId)
{
PACKET_SERIAL_TYPE lRdBaseIDPkt_st;
uint8_t lu8SndBuf[15];
lRdBaseIDPkt_st.u16DataLength = 0x0008;
lRdBaseIDPkt_st.u8OptionLength = 0x07;
lRdBaseIDPkt_st.u8Type = u8RADIO_ERP1;
lRdBaseIDPkt_st.u8DataBuffer = &lu8SndBuf[0];
lu8SndBuf[0] = u8RORG_VLD;
lu8SndBuf[1] = VLD_CMD_ID_03;
lu8SndBuf[2] = 0x1e;
lu8SndBuf[3] = mySenderId[0];
lu8SndBuf[4] = mySenderId[1];
lu8SndBuf[5] = mySenderId[2];
lu8SndBuf[6] = mySenderId[3];
lu8SndBuf[7] = 0x00;
// optional data
lu8SndBuf[8] = 0x03;
lu8SndBuf[9] = 0xFF;
lu8SndBuf[10] = 0xFF;
lu8SndBuf[11] = 0xFF;
lu8SndBuf[12] = 0xFF;
lu8SndBuf[13] = 0x00;
lu8SndBuf[14] = 0x00;
if (!enOcean.sendPacket(&lRdBaseIDPkt_st))
{
#ifdef KDEBUG
DEBUGSERIAL.println("Sending telegram failed.");
#endif
}
else
{
#ifdef KDEBUG
Debug.println(F("Requested status from NodOn %X"), actorId);
#endif
}
nextPollTime = millis() + pollFrequencyMillis;
}
// things that need to be done regularly
void task()
{
if (status_request == false)
{
status_request = true;
getStatusActors(enOcean.getBaseId());
}
if (millis() > nextPollTime)
getStatusActors(enOcean.getBaseId());
}
// something happened on the bus, let's react
#pragma GCC diagnostic push // I don't want a warning, just because we don't do anything here
#pragma GCC diagnostic ignored "-Wunused-parameter"
void handleKnxEvents(byte index)
{
// nothing to listen for from Knx
return;
}
#pragma GCC diagnostic pop
// decode EnOcean message. Fail fast!
bool handleEnOceanPacket(PACKET_SERIAL_TYPE* f_Pkt_st)
{
if (f_Pkt_st->u8DataBuffer[0] != u8RORG_VLD)
return false;
if (f_Pkt_st->u8DataBuffer[1] != VLD_CMD_ID_04)
{
#ifdef KDEBUG
DEBUGSERIAL.println("Command ID not implemented yet.");
#endif
return false;
}
{
// swap two bytes
uint8_t temp;
temp = f_Pkt_st->u8DataBuffer[2];
f_Pkt_st->u8DataBuffer[2] = f_Pkt_st->u8DataBuffer[3];
f_Pkt_st->u8DataBuffer[3] = temp;
}
VLD_D2_01_TELEGRAM_CMD_04_TYPE* ActStatResp = (VLD_D2_01_TELEGRAM_CMD_04_TYPE*) &(f_Pkt_st->u8DataBuffer[2]);
// Get rid of messages not intended for us
if (ActStatResp->u8SenderId_p[0] != actorId_Arr[0])
return false;
if (ActStatResp->u8SenderId_p[1] != actorId_Arr[1])
return false;
if (ActStatResp->u8SenderId_p[2] != actorId_Arr[2])
return false;
if (ActStatResp->u8SenderId_p[3] != actorId_Arr[3])
return false;
#ifdef KDEBUG
DEBUGSERIAL.print("detect: Aktor_");
DEBUGSERIAL.println(actorId);
#endif
if (ActStatResp->u16VldTelActResp.IOChannel == 0) // Abfrage ob CH1
{
if (ActStatResp->u16VldTelActResp.outputValue == 0) // Abfrage ob CH1 = OFF
{
Knx.write(firstComObj, 0);
}
else
if (ActStatResp->u16VldTelActResp.outputValue > 0) // Abfrage ob CH1 = ON
{
Knx.write(firstComObj, 1);
}
}
else
if (ActStatResp->u16VldTelActResp.IOChannel == 1) // Abfrage ob CH2
{
if (ActStatResp->u16VldTelActResp.outputValue == 0) // Abfrage ob CH2 = OFF
{
Knx.write(firstComObj + 1, 0);
}
else
if (ActStatResp->u16VldTelActResp.outputValue > 0) // Abfrage ob CH2 = ON
{
Knx.write(firstComObj + 1, 1);
}
}
return false;
}
};
#endif /* ENOCEANDEVICE_NODON_2CH_H_ */