@@ -835,6 +835,28 @@ void COpenWebNetTCP::UpdateCenPlus(const int who, const int where, const int Com
835
835
SendSwitch (NodeID, iInterface, BatteryLevel, (bool )Command, 0 , devname);
836
836
}
837
837
838
+ /* *
839
+ Insert/Update sound diffusion device
840
+ **/
841
+ void COpenWebNetTCP::UpdateSoundDiffusion (const int who, const int where, const int what, const int iInterface, const int BatteryLevel, const char * devname)
842
+ {
843
+ // NOTE: interface id (bus identifier) go in 'Unit' field
844
+ // make device ID
845
+ int NodeID = (((int )who << 16 ) & 0xFFFF0000 ) | (((int )where) & 0x0000FFFF );
846
+
847
+ /* insert switch type */
848
+ char szIdx[10 ];
849
+ sprintf (szIdx, " %07X" , NodeID);
850
+ std::vector<std::vector<std::string> > result;
851
+ result = m_sql.safe_query (" SELECT ID,SwitchType FROM DeviceStatus WHERE (HardwareID==%d) AND (DeviceID=='%s') AND (Unit==%d)" , m_HwdID, szIdx, iInterface);
852
+ if (result.empty ())
853
+ {
854
+ // m_sql.InsertDevice(m_HwdID, szIdx, iInterface, pTypeLighting2, sTypeAC, STYPE_Media, 0, "Unavailable", "OpenWebNet Media", 12, 255, 1);
855
+ }
856
+
857
+ // TODO: manage SoundDiffusion device like dimmer (on, off and set volume) or like media device (check how to do it)
858
+ }
859
+
838
860
/* *
839
861
Insert/Update switch device
840
862
**/
@@ -1267,6 +1289,15 @@ void COpenWebNetTCP::UpdateDeviceValue(std::vector<bt_openwebnet>::iterator iter
1267
1289
break ;
1268
1290
}
1269
1291
break ;
1292
+
1293
+ case WHO_SOUND_DIFFUSION: // 22
1294
+ // iAppValue = atoi(what.c_str());
1295
+ // iWhere = atoi(where.c_str());
1296
+ // devname = OPENWEBNET_SOUND_DIFFUSION;
1297
+ // devname += " " + where;
1298
+ // UpdateSoundDiffusion(WHO_SOUND_DIFFUSION, iWhere, iAppValue, atoi(sInterface.c_str()), 255, devname.c_str());
1299
+ // break;
1300
+
1270
1301
case WHO_SCENARIO: // 0
1271
1302
case WHO_LOAD_CONTROL: // 3
1272
1303
case WHO_DOOR_ENTRY_SYSTEM: // 6
@@ -1276,7 +1307,6 @@ void COpenWebNetTCP::UpdateDeviceValue(std::vector<bt_openwebnet>::iterator iter
1276
1307
case WHO_SCENARIO_SCHEDULER_SWITCH: // 15
1277
1308
case WHO_AUDIO: // 16
1278
1309
case WHO_SCENARIO_PROGRAMMING: // 17
1279
- case WHO_SOUND_DIFFUSION: // 22
1280
1310
case WHO_LIHGTING_MANAGEMENT: // 24
1281
1311
case WHO_ZIGBEE_DIAGNOSTIC: // 1000
1282
1312
case WHO_AUTOMATIC_DIAGNOSTIC: // 1001
@@ -1327,7 +1357,6 @@ bool COpenWebNetTCP::WriteToHardware(const char *pdata, const unsigned char leng
1327
1357
case WHO_AUTOMATION:
1328
1358
// Blinds/Window command
1329
1359
sprintf (szIdx, " %07X" , ((who << 16 ) & 0xffff0000 ) | (where & 0x0000ffff ));
1330
-
1331
1360
result = m_sql.safe_query (" SELECT nValue FROM DeviceStatus WHERE (HardwareID==%d) AND (DeviceID=='%s') AND (SwitchType==%d)" , // *******is there a better method for get
1332
1361
m_HwdID, szIdx, STYPE_BlindsPercentageInverted); // *******SUBtype (STYPE_BlindsPercentageInverted) ??
1333
1362
@@ -1401,16 +1430,27 @@ bool COpenWebNetTCP::WriteToHardware(const char *pdata, const unsigned char leng
1401
1430
what = AUXILIARY_WHAT_ON;
1402
1431
}
1403
1432
break ;
1433
+
1434
+ case 0xF00 : // Custom command, fake who..
1435
+ sprintf (szIdx, " %07X" , ((who << 16 ) & 0xffff0000 ) | (where & 0x0000ffff ));
1436
+ result = m_sql.safe_query (" SELECT StrParam1 FROM DeviceStatus WHERE (HardwareID==%d) AND (DeviceID=='%s')" , m_HwdID, szIdx);
1437
+ if (!result.empty ())
1438
+ {
1439
+ // Custom command fount, send it!
1440
+ _log.Log (LOG_STATUS, " COpenWebNetTCP: send custom command: '%s'" , result[0 ][0 ].c_str ());
1441
+ std::vector<bt_openwebnet> responses;
1442
+ bt_openwebnet request (result[0 ][0 ]);
1443
+ if (sendCommand (request, responses))
1444
+ {
1445
+ // if (responses.size() > 0) return responses.at(0).IsOKFrame();
1446
+ return true ; // if send ok, return always ok without check the response..
1447
+ }
1448
+ }
1449
+ _log.Log (LOG_ERROR, " COpenWebNetTCP: custom command error: '%s'" , result[0 ][0 ].c_str ());
1450
+ return false ; // error
1404
1451
default :
1405
1452
break ;
1406
1453
}
1407
-
1408
- // int used = 1;
1409
- if (!FindDevice (who, where, iInterface, NULL )) {
1410
- _log.Log (LOG_ERROR, " COpenWebNetTCP: command received for unknown device : %d/%d" , who, where);
1411
- return false ;
1412
- }
1413
-
1414
1454
break ;
1415
1455
default :
1416
1456
_log.Log (LOG_STATUS, " COpenWebNetTCP unknown command: packettype=%d subtype=%d" , packettype, subtype);
@@ -1611,6 +1651,21 @@ void COpenWebNetTCP::scan_automation_lighting(const int cen_area)
1611
1651
sendCommand (request, responses, 0 , false );
1612
1652
}
1613
1653
1654
+ /* *
1655
+ automatic scan of sound diffusion device
1656
+ **/
1657
+ void COpenWebNetTCP::scan_sound_diffusion ()
1658
+ {
1659
+ bt_openwebnet request;
1660
+ std::vector<bt_openwebnet> responses;
1661
+ std::stringstream whoStr;
1662
+ std::stringstream whereStr;
1663
+ whoStr << WHO_SOUND_DIFFUSION;
1664
+ whereStr << 0 ;
1665
+ request.CreateStateMsgOpen (whoStr.str (), whereStr.str ());
1666
+ sendCommand (request, responses, 0 , false );
1667
+ }
1668
+
1614
1669
/* *
1615
1670
automatic scan of temperature control device
1616
1671
**/
@@ -1761,6 +1816,9 @@ void COpenWebNetTCP::scan_device()
1761
1816
// _log.Log(LOG_STATUS, "COpenWebNetTCP: scanning temperature control...");
1762
1817
// scan_temperature_control();
1763
1818
1819
+ // Scan of sound diffusion device
1820
+ // scan_sound_diffusion();
1821
+
1764
1822
_log.Log (LOG_STATUS, " COpenWebNetTCP: scan device complete, wait all the update data.." );
1765
1823
1766
1824
/* Update complete scan time*/
@@ -1831,72 +1889,3 @@ void COpenWebNetTCP::Do_Work()
1831
1889
}
1832
1890
_log.Log (LOG_STATUS, " COpenWebNetTCP: Heartbeat worker stopped..." );
1833
1891
}
1834
-
1835
- /* *
1836
- Find OpenWebNetDevice in DB
1837
- **/
1838
- bool COpenWebNetTCP::FindDevice (const int who, const int where, const int iInterface, int * used)
1839
- {
1840
- std::vector<std::vector<std::string> > result;
1841
- int devType = -1 ;
1842
-
1843
- // make device ID
1844
- int NodeID = (((int )who << 16 ) & 0xFFFF0000 ) | (((int )where) & 0x0000FFFF );
1845
-
1846
- switch (who) {
1847
- case WHO_LIGHTING: // 1
1848
- case WHO_AUTOMATION: // 2
1849
- case WHO_AUXILIARY: // 9
1850
- case WHO_CEN_PLUS_DRY_CONTACT_IR_DETECTION: // 25
1851
- // devType = pTypeGeneralSwitch;
1852
- devType = pTypeLighting2;
1853
- break ;
1854
- case WHO_TEMPERATURE_CONTROL: // 4
1855
- return true ; // device always present
1856
- case WHO_SCENARIO: // 0
1857
- case WHO_LOAD_CONTROL: // 3
1858
- case WHO_BURGLAR_ALARM: // 5
1859
- case WHO_DOOR_ENTRY_SYSTEM: // 6
1860
- case WHO_MULTIMEDIA: // 7
1861
- case WHO_GATEWAY_INTERFACES_MANAGEMENT: // 13
1862
- case WHO_LIGHT_SHUTTER_ACTUATOR_LOCK: // 14
1863
- case WHO_SCENARIO_SCHEDULER_SWITCH: // 15
1864
- case WHO_AUDIO: // 16
1865
- case WHO_SCENARIO_PROGRAMMING: // 17
1866
- case WHO_ENERGY_MANAGEMENT: // 18
1867
- case WHO_LIHGTING_MANAGEMENT: // 24
1868
- case WHO_ZIGBEE_DIAGNOSTIC: // 1000
1869
- case WHO_AUTOMATIC_DIAGNOSTIC: // 1001
1870
- case WHO_THERMOREGULATION_DIAGNOSTIC_FAILURES: // 1004
1871
- case WHO_DEVICE_DIAGNOSTIC: // 1013
1872
- default :
1873
- return false ;
1874
- }
1875
-
1876
- if (devType >= 0 )
1877
- {
1878
- char szIdx[10 ];
1879
- sprintf (szIdx, " %07X" , NodeID);
1880
-
1881
- if (used != NULL )
1882
- {
1883
- result = m_sql.safe_query (" SELECT ID FROM DeviceStatus WHERE (HardwareID==%d) AND (DeviceID=='%q') AND (Unit == %d) AND (Type==%d) AND Used == %d" ,
1884
- m_HwdID, szIdx, iInterface, devType, *used);
1885
- }
1886
- else
1887
- {
1888
- result = m_sql.safe_query (" SELECT ID FROM DeviceStatus WHERE (HardwareID==%d) AND (DeviceID=='%q') AND (Unit == %d) AND (Type==%d)" ,
1889
- m_HwdID, szIdx, iInterface, devType);
1890
- }
1891
- }
1892
- else
1893
- return false ;
1894
-
1895
-
1896
- if (!result.empty ())
1897
- {
1898
- return true ;
1899
- }
1900
-
1901
- return false ;
1902
- }
0 commit comments