@@ -91,6 +91,13 @@ static sensorType sensors[sensorsCount] =
91
91
{ " Temperatura podajnika" , 10.0 }
92
92
};
93
93
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
+
94
101
static std::string errors[4 ] =
95
102
{
96
103
" Bledny kod funkcji" ,
@@ -107,7 +114,8 @@ MultiFun::MultiFun(const int ID, const std::string &IPAddress, const unsigned sh
107
114
m_LastAlarms(0 ),
108
115
m_LastWarnings(0 ),
109
116
m_LastDevices(0 ),
110
- m_LastState(0 )
117
+ m_LastState(0 ),
118
+ m_LastQuickAccess(0 )
111
119
{
112
120
_log.Log (LOG_STATUS, " MultiFun: Create instance" );
113
121
m_HwdID = ID;
@@ -157,6 +165,8 @@ void MultiFun::Do_Work()
157
165
158
166
int sec_counter = MULTIFUN_POLL_INTERVAL;
159
167
168
+ bool firstTime = true ;
169
+
160
170
while (!m_stoprequested)
161
171
{
162
172
sleep_seconds (1 );
@@ -171,7 +181,8 @@ void MultiFun::Do_Work()
171
181
if (sec_counter % MULTIFUN_POLL_INTERVAL == 0 )
172
182
{
173
183
GetTemperatures ();
174
- GetRegisters ();
184
+ GetRegisters (firstTime);
185
+ firstTime = false ;
175
186
#ifdef DEBUG_MultiFun
176
187
_log.Log (LOG_STATUS, " MultiFun: fetching changed data" );
177
188
#endif
@@ -183,6 +194,33 @@ bool MultiFun::WriteToHardware(const char *pdata, const unsigned char length)
183
194
{
184
195
const tRBUF *output = reinterpret_cast <const tRBUF*>(pdata);
185
196
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
+
186
224
return false ;
187
225
}
188
226
@@ -229,7 +267,7 @@ void MultiFun::DestroySocket()
229
267
void MultiFun::GetTemperatures ()
230
268
{
231
269
unsigned char buffer[50 ];
232
- char cmd[12 ];
270
+ unsigned char cmd[12 ];
233
271
cmd[0 ] = 0x01 ; // transaction id (2 bytes)
234
272
cmd[1 ] = 0x02 ;
235
273
cmd[2 ] = 0x00 ; // protocol id (2 bytes)
@@ -269,10 +307,10 @@ void MultiFun::GetTemperatures()
269
307
}
270
308
}
271
309
272
- void MultiFun::GetRegisters ()
310
+ void MultiFun::GetRegisters (bool firstTime )
273
311
{
274
312
unsigned char buffer[100 ];
275
- char cmd[12 ];
313
+ unsigned char cmd[12 ];
276
314
cmd[0 ] = 0x01 ; // transaction id (2 bytes)
277
315
cmd[1 ] = 0x02 ;
278
316
cmd[2 ] = 0x00 ; // protocol id (2 bytes)
@@ -343,12 +381,12 @@ void MultiFun::GetRegisters()
343
381
{
344
382
if (((*it).first & value) && !((*it).first & m_LastDevices))
345
383
{
346
- SendGeneralSwitchSensor (1 , 255 , true , (*it).second .c_str (), (*it).first );
384
+ SendGeneralSwitchSensor (2 , 255 , true , (*it).second .c_str (), (*it).first );
347
385
}
348
386
else
349
387
if (!((*it).first & value) && ((*it).first & m_LastDevices))
350
388
{
351
- SendGeneralSwitchSensor (1 , 255 , false , (*it).second .c_str (), (*it).first );
389
+ SendGeneralSwitchSensor (2 , 255 , false , (*it).second .c_str (), (*it).first );
352
390
}
353
391
}
354
392
m_LastDevices = value;
@@ -358,18 +396,18 @@ void MultiFun::GetRegisters()
358
396
break ;
359
397
}
360
398
case 0x03 :
361
- { // TODO - dla ostatnich dwoch urzadzen inaczej, bo to to samo tylko on/off
399
+ {
362
400
dictionary::iterator it = statesType.begin ();
363
401
for (; it != statesType.end (); it++)
364
402
{
365
403
if (((*it).first & value) && !((*it).first & m_LastState))
366
404
{
367
- SendTextSensor (1 , 3 , 255 , (*it).second , " State" );
405
+ SendTextSensor (3 , 1 , 255 , (*it).second , " State" );
368
406
}
369
407
else
370
408
if (!((*it).first & value) && ((*it).first & m_LastState))
371
409
{
372
- SendTextSensor (1 , 3 , 255 , " Koniec - " + (*it).second , " State" );
410
+ SendTextSensor (3 , 1 , 255 , " Koniec - " + (*it).second , " State" );
373
411
}
374
412
}
375
413
m_LastState = value;
@@ -389,13 +427,32 @@ void MultiFun::GetRegisters()
389
427
}
390
428
char name[20 ];
391
429
sprintf (name, " Temperatura CO %d" , i - 0x1C + 1 );
392
- SendSetPointSensor (1 , i , 1 , temp, name);
430
+ SendSetPointSensor (i, 1 , 1 , temp, name);
393
431
break ;
394
432
}
395
433
396
434
case 0x1E :
397
435
{
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;
399
456
break ;
400
457
}
401
458
default : break ;
@@ -410,7 +467,7 @@ void MultiFun::GetRegisters()
410
467
}
411
468
}
412
469
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)
414
471
{
415
472
if (!ConnectToDevice ())
416
473
{
@@ -419,10 +476,10 @@ int MultiFun::SendCommand(const char* cmd, const unsigned int cmdLength, unsigne
419
476
420
477
boost::lock_guard<boost::mutex> lock (m_mutex);
421
478
422
- char databuffer[BUFFER_LENGHT];
479
+ unsigned char databuffer[BUFFER_LENGHT];
423
480
int ret;
424
481
425
- if (m_socket->write (cmd, cmdLength) != cmdLength)
482
+ if (m_socket->write (( char *) cmd, cmdLength) != cmdLength)
426
483
{
427
484
_log.Log (LOG_ERROR, " MultiFun: Send command failed" );
428
485
DestroySocket ();
@@ -435,7 +492,7 @@ int MultiFun::SendCommand(const char* cmd, const unsigned int cmdLength, unsigne
435
492
{
436
493
if (memset (databuffer, 0 , BUFFER_LENGHT) > 0 )
437
494
{
438
- ret = m_socket->read (databuffer, BUFFER_LENGHT, false );
495
+ ret = m_socket->read (( char *) databuffer, BUFFER_LENGHT, false );
439
496
}
440
497
}
441
498
@@ -468,7 +525,7 @@ int MultiFun::SendCommand(const char* cmd, const unsigned int cmdLength, unsigne
468
525
}
469
526
}
470
527
else
471
- if (cmd[0 ] + 0x80 == databuffer[7 ])
528
+ if (cmd[7 ] + 0x80 == databuffer[7 ])
472
529
{
473
530
if (databuffer[8 ] >= 1 && databuffer[8 ] <= 4 )
474
531
{
0 commit comments