Skip to content

Commit 77739cc

Browse files
committed
[MultiFun] implemented next registers
1 parent 64a1678 commit 77739cc

File tree

2 files changed

+77
-19
lines changed

2 files changed

+77
-19
lines changed

hardware/MultiFun.cpp

Lines changed: 74 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ static sensorType sensors[sensorsCount] =
9191
{ "Temperatura podajnika", 10.0 }
9292
};
9393

94+
static dictionary quickAccessType = boost::assign::map_list_of
95+
(0x0001, "Prysznic")
96+
(0x0002, "Party")
97+
(0x0004, "Komfort")
98+
(0x0008, "Wietrzenie")
99+
(0x0010, "Antyzamarzanie");
100+
94101
static std::string errors[4] =
95102
{
96103
"Bledny kod funkcji",
@@ -107,7 +114,8 @@ MultiFun::MultiFun(const int ID, const std::string &IPAddress, const unsigned sh
107114
m_LastAlarms(0),
108115
m_LastWarnings(0),
109116
m_LastDevices(0),
110-
m_LastState(0)
117+
m_LastState(0),
118+
m_LastQuickAccess(0)
111119
{
112120
_log.Log(LOG_STATUS, "MultiFun: Create instance");
113121
m_HwdID = ID;
@@ -157,6 +165,8 @@ void MultiFun::Do_Work()
157165

158166
int sec_counter = MULTIFUN_POLL_INTERVAL;
159167

168+
bool firstTime = true;
169+
160170
while (!m_stoprequested)
161171
{
162172
sleep_seconds(1);
@@ -171,7 +181,8 @@ void MultiFun::Do_Work()
171181
if (sec_counter % MULTIFUN_POLL_INTERVAL == 0)
172182
{
173183
GetTemperatures();
174-
GetRegisters();
184+
GetRegisters(firstTime);
185+
firstTime = false;
175186
#ifdef DEBUG_MultiFun
176187
_log.Log(LOG_STATUS, "MultiFun: fetching changed data");
177188
#endif
@@ -183,6 +194,33 @@ bool MultiFun::WriteToHardware(const char *pdata, const unsigned char length)
183194
{
184195
const tRBUF *output = reinterpret_cast<const tRBUF*>(pdata);
185196

197+
if (output->ICMND.packettype == pTypeGeneralSwitch && output->LIGHTING2.subtype == sSwitchTypeAC)
198+
{
199+
const _tGeneralSwitch *general = reinterpret_cast<const _tGeneralSwitch*>(pdata);
200+
201+
if (general->id == 0x21)
202+
{
203+
unsigned char buffer[100];
204+
unsigned char cmd[20];
205+
cmd[0] = 0x01; // transaction id (2 bytes)
206+
cmd[1] = 0x02;
207+
cmd[2] = 0x00; // protocol id (2 bytes)
208+
cmd[3] = 0x00;
209+
cmd[4] = 0x00; // length (2 bytes)
210+
cmd[5] = 0x08;
211+
cmd[6] = 0xFF; // unit id
212+
cmd[7] = 0x10; // function code
213+
cmd[8] = 0x00; // start address (2 bytes)
214+
cmd[9] = 0x21;
215+
cmd[10] = 0x00; // number of sensor (2 bytes)
216+
cmd[11] = 0x01;
217+
cmd[12] = 0x02;
218+
cmd[13] = 0xFF & general->unitcode;
219+
220+
int ret = SendCommand(cmd, 14, buffer);
221+
}
222+
}
223+
186224
return false;
187225
}
188226

@@ -229,7 +267,7 @@ void MultiFun::DestroySocket()
229267
void MultiFun::GetTemperatures()
230268
{
231269
unsigned char buffer[50];
232-
char cmd[12];
270+
unsigned char cmd[12];
233271
cmd[0] = 0x01; // transaction id (2 bytes)
234272
cmd[1] = 0x02;
235273
cmd[2] = 0x00; // protocol id (2 bytes)
@@ -269,10 +307,10 @@ void MultiFun::GetTemperatures()
269307
}
270308
}
271309

272-
void MultiFun::GetRegisters()
310+
void MultiFun::GetRegisters(bool firstTime)
273311
{
274312
unsigned char buffer[100];
275-
char cmd[12];
313+
unsigned char cmd[12];
276314
cmd[0] = 0x01; // transaction id (2 bytes)
277315
cmd[1] = 0x02;
278316
cmd[2] = 0x00; // protocol id (2 bytes)
@@ -343,12 +381,12 @@ void MultiFun::GetRegisters()
343381
{
344382
if (((*it).first & value) && !((*it).first & m_LastDevices))
345383
{
346-
SendGeneralSwitchSensor(1, 255, true, (*it).second.c_str(), (*it).first);
384+
SendGeneralSwitchSensor(2, 255, true, (*it).second.c_str(), (*it).first);
347385
}
348386
else
349387
if (!((*it).first & value) && ((*it).first & m_LastDevices))
350388
{
351-
SendGeneralSwitchSensor(1, 255, false, (*it).second.c_str(), (*it).first);
389+
SendGeneralSwitchSensor(2, 255, false, (*it).second.c_str(), (*it).first);
352390
}
353391
}
354392
m_LastDevices = value;
@@ -358,18 +396,18 @@ void MultiFun::GetRegisters()
358396
break;
359397
}
360398
case 0x03:
361-
{ // TODO - dla ostatnich dwoch urzadzen inaczej, bo to to samo tylko on/off
399+
{
362400
dictionary::iterator it = statesType.begin();
363401
for (; it != statesType.end(); it++)
364402
{
365403
if (((*it).first & value) && !((*it).first & m_LastState))
366404
{
367-
SendTextSensor(1, 3, 255, (*it).second, "State");
405+
SendTextSensor(3, 1, 255, (*it).second, "State");
368406
}
369407
else
370408
if (!((*it).first & value) && ((*it).first & m_LastState))
371409
{
372-
SendTextSensor(1, 3, 255, "Koniec - " + (*it).second, "State");
410+
SendTextSensor(3, 1, 255, "Koniec - " + (*it).second, "State");
373411
}
374412
}
375413
m_LastState = value;
@@ -389,13 +427,32 @@ void MultiFun::GetRegisters()
389427
}
390428
char name[20];
391429
sprintf(name, "Temperatura CO %d", i - 0x1C + 1);
392-
SendSetPointSensor(1, i, 1, temp, name);
430+
SendSetPointSensor(i, 1, 1, temp, name);
393431
break;
394432
}
395433

396434
case 0x1E:
397435
{
398-
SendSetPointSensor(1, 0x1E, 1, value, "Temperatura CWU");
436+
SendSetPointSensor(0x1E, 1, 1, value, "Temperatura CWU");
437+
break;
438+
}
439+
440+
case 0x21:
441+
{
442+
dictionary::iterator it = quickAccessType.begin();
443+
for (; it != quickAccessType.end(); it++)
444+
{
445+
if (((*it).first & value) && !((*it).first & m_LastQuickAccess))
446+
{
447+
SendGeneralSwitchSensor(0x21, 255, true, (*it).second.c_str(), (*it).first);
448+
}
449+
else
450+
if ((!((*it).first & value) && ((*it).first & m_LastQuickAccess)) || firstTime)
451+
{
452+
SendGeneralSwitchSensor(0x21, 255, false, (*it).second.c_str(), (*it).first);
453+
}
454+
}
455+
m_LastQuickAccess = value;
399456
break;
400457
}
401458
default: break;
@@ -410,7 +467,7 @@ void MultiFun::GetRegisters()
410467
}
411468
}
412469

413-
int MultiFun::SendCommand(const char* cmd, const unsigned int cmdLength, unsigned char *answer)
470+
int MultiFun::SendCommand(const unsigned char* cmd, const unsigned int cmdLength, unsigned char *answer)
414471
{
415472
if (!ConnectToDevice())
416473
{
@@ -419,10 +476,10 @@ int MultiFun::SendCommand(const char* cmd, const unsigned int cmdLength, unsigne
419476

420477
boost::lock_guard<boost::mutex> lock(m_mutex);
421478

422-
char databuffer[BUFFER_LENGHT];
479+
unsigned char databuffer[BUFFER_LENGHT];
423480
int ret;
424481

425-
if (m_socket->write(cmd, cmdLength) != cmdLength)
482+
if (m_socket->write((char*)cmd, cmdLength) != cmdLength)
426483
{
427484
_log.Log(LOG_ERROR, "MultiFun: Send command failed");
428485
DestroySocket();
@@ -435,7 +492,7 @@ int MultiFun::SendCommand(const char* cmd, const unsigned int cmdLength, unsigne
435492
{
436493
if (memset(databuffer, 0, BUFFER_LENGHT) > 0)
437494
{
438-
ret = m_socket->read(databuffer, BUFFER_LENGHT, false);
495+
ret = m_socket->read((char*)databuffer, BUFFER_LENGHT, false);
439496
}
440497
}
441498

@@ -468,7 +525,7 @@ int MultiFun::SendCommand(const char* cmd, const unsigned int cmdLength, unsigne
468525
}
469526
}
470527
else
471-
if (cmd[0] + 0x80 == databuffer[7])
528+
if (cmd[7] + 0x80 == databuffer[7])
472529
{
473530
if (databuffer[8] >= 1 && databuffer[8] <= 4)
474531
{

hardware/MultiFun.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class MultiFun : public CDomoticzHardwareBase
3030
int m_LastWarnings;
3131
int m_LastDevices;
3232
int m_LastState;
33+
int m_LastQuickAccess;
3334

3435
bool StartHardware();
3536
bool StopHardware();
@@ -38,8 +39,8 @@ class MultiFun : public CDomoticzHardwareBase
3839
bool ConnectToDevice();
3940
void DestroySocket();
4041

41-
int SendCommand(const char* cmd, const unsigned int cmdLength, unsigned char *answer);
42+
int SendCommand(const unsigned char* cmd, const unsigned int cmdLength, unsigned char *answer);
4243

4344
void GetTemperatures();
44-
void GetRegisters();
45+
void GetRegisters(bool FirstTime);
4546
};

0 commit comments

Comments
 (0)