Skip to content

Commit c7a357b

Browse files
committed
Merge branch 'master' of https://github.com/EddyK69/domoticz
Conflicts: .gitignore
2 parents 1b2f613 + 3ab53b9 commit c7a357b

14 files changed

+241
-39
lines changed

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1+
<<<<<<< HEAD
12
*.orig
23
msbuild
34
domoticz.db
45
appversion.h
56

7+
=======
8+
Makefile
9+
CMakeFiles
10+
*.cmake
11+
*.a
12+
CMakeCache.txt
13+
appversion.h*
14+
domoticz
15+
stdafx.h.gch
16+
>>>>>>> 3ab53b90264f7c67ca31b683bfdfa166847a23d9

CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ hardware/TCPProxy/tcpproxy_server.cpp
239239
hardware/TE923.cpp
240240
hardware/TE923Tool.cpp
241241
hardware/Teleinfo.cpp
242+
hardware/Tellstick.cpp
242243
hardware/Thermosmart.cpp
243244
hardware/ToonThermostat.cpp
244245
hardware/VolcraftCO20.cpp
@@ -430,6 +431,15 @@ else()
430431
message(STATUS "Not building on Raspberry Pi. GPIO support disabled.")
431432
ENDIF(RaspberryPi)
432433

434+
find_path(TELLDUSCORE_INCLUDE NAMES telldus-core.h)
435+
if (TELLDUSCORE_INCLUDE)
436+
message(STATUS "Found telldus-core (telldus-core.h), adding tellstick support")
437+
target_link_libraries (domoticz telldus-core)
438+
add_definitions(-DWITH_TELLDUSCORE)
439+
else()
440+
message(STATUS "Not found telldus-core (telldus-core.h), not adding tellstick support")
441+
endif (TELLDUSCORE_INCLUDE)
442+
433443
target_link_libraries(domoticz -lrt ${Boost_LIBRARIES} ${ZLIB_LIBRARIES} ${CURL_LIBRARIES} pthread lua mqtt sqlite ${CMAKE_DL_LIBS})
434444

435445
ADD_PRECOMPILED_HEADER(domoticz "main/stdafx.h")

INSTALL.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ you need to compile open zwave
3636
svn co http://open-zwave.googlecode.com/svn/trunk/ open-zwave-read-only
3737
cd open-zwave-read-only
3838

39+
[Tellstick support]
40+
If you need support for Tellstick or Tellstic Duo (http://www.telldus.se/products/range) you need to install telldus-core before compileing.
41+
On systems with apt package manger (like ubuntu and Raspbian) telldus-core can be installed by doing the following:
42+
* Add "deb http://download.telldus.com/debian/ stable main" to the file /etc/apt/sources.list
43+
* Run:
44+
* wget -q http://download.telldus.se/debian/telldus-public.key -O- | sudo apt-key add -
45+
* sudo apt-get update
46+
* sudo apt-get install libtelldus-core-dev
47+
48+
3949
|* Darwin (Mac)
4050
|There is a problem in the MakeFile, change the DEBUG/RELEASE defines with:
4151
|DEBUG_CFLAGS := -Wall -Wno-unknown-pragmas -Wno-inline -Werror -Wno-self-assign -Wno-unused-private-field -Wno-format -g -DDEBUG -DLOG_STDERR -fPIC

hardware/DomoticzHardware.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class CDomoticzHardwareBase
4040
private:
4141
friend class C1Wire;
4242
friend class CDummy;
43+
friend class CTellstick;
4344
friend class CEvohome;
4445
friend class DomoticzTCP;
4546
friend class P1MeterBase;

hardware/Tellstick.cpp

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
#include "stdafx.h"
2+
#ifdef WITH_TELLDUSCORE
3+
#include "Tellstick.h"
4+
5+
#include "../main/Helper.h"
6+
#include "../main/Logger.h"
7+
#include "../main/SQLHelper.h"
8+
#include "../main/mainworker.h"
9+
#include "../main/WebServer.h"
10+
#include "../webserver/cWebem.h"
11+
#include "../json/json.h"
12+
#include "hardwaretypes.h"
13+
#include <telldus-core.h>
14+
15+
CTellstick::CTellstick(const int ID)
16+
{
17+
m_HwdID=ID;
18+
m_bSkipReceiveCheck = true;
19+
}
20+
21+
CTellstick::~CTellstick(void)
22+
{
23+
m_bIsStarted=false;
24+
}
25+
26+
bool CTellstick::AddSwitchIfNotExits(const int id, const char* devname, bool isDimmer)
27+
{
28+
char sid[16];
29+
sprintf(sid, "%08X", id);
30+
31+
std::vector<std::vector<std::string> > result;
32+
result = m_sql.safe_query("SELECT ID FROM DeviceStatus WHERE (HardwareID==%d) AND (DeviceID=='%q') AND (Type==%d) AND (SubType==%d)", m_HwdID, sid, pTypeGeneralSwitch, sSwitchTypeAC);
33+
if (result.size()<1)
34+
{
35+
_log.Log(LOG_NORM, "Tellstick: device %d %s: %s", id, sid ,devname);
36+
m_sql.safe_query(
37+
"INSERT INTO DeviceStatus (HardwareID, DeviceID, Unit, Type, SubType, SwitchType, SignalLevel, BatteryLevel, Name, nValue, sValue) "
38+
"VALUES (%d,'%q',%d,%d,%d,%d,12,255,'%q',0,' ')",
39+
m_HwdID, sid, 3, pTypeGeneralSwitch, sSwitchTypeAC, isDimmer ? STYPE_Dimmer : STYPE_OnOff, devname);
40+
return true;
41+
}
42+
return false;
43+
}
44+
45+
void CTellstick::deviceEvent(int deviceId, int method, const char *data) {
46+
_log.Log(LOG_NORM, "Tellstick: deviceEvent %d %d: %s", deviceId, method, data);
47+
48+
char sid[16];
49+
sprintf(sid, "%08d", deviceId);
50+
51+
_tGeneralSwitch gswitch;
52+
// TODO pTypeGeneralSwitch
53+
gswitch.subtype = sSwitchTypeAC;
54+
gswitch.id = deviceId;
55+
gswitch.unitcode = 3;
56+
gswitch.level = 0;
57+
gswitch.battery_level = 255;
58+
gswitch.rssi = 12;
59+
gswitch.seqnbr = 0;
60+
61+
if (method == TELLSTICK_TURNON) {
62+
gswitch.cmnd = gswitch_sOn;
63+
sDecodeRXMessage(this, (const unsigned char *)&gswitch);
64+
} else if (method == TELLSTICK_TURNOFF) {
65+
gswitch.cmnd = gswitch_sOff;
66+
sDecodeRXMessage(this, (const unsigned char *)&gswitch);
67+
} else if (method == TELLSTICK_DIM) {
68+
gswitch.cmnd = gswitch_sSetLevel;
69+
gswitch.level = atoi(data)*99/255;
70+
sDecodeRXMessage(this, (const unsigned char *)&gswitch);
71+
} else {
72+
_log.Log(LOG_NORM, "Unknown event from device %i\n", deviceId);
73+
}
74+
}
75+
void CTellstick::deviceEventCallback(int deviceId, int method, const char *data, int callbackId, void *context) {
76+
CTellstick *t = reinterpret_cast<CTellstick *>(context);
77+
if (t) {
78+
/** Please note!
79+
* We are here in another thread than the main. Some measures to syncronize
80+
* this must be taken!
81+
**/
82+
t->deviceEvent(deviceId, method, data);
83+
}
84+
}
85+
86+
void CTellstick::Init()
87+
{
88+
tdInit();
89+
tdRegisterDeviceEvent( reinterpret_cast<TDDeviceEvent>(&CTellstick::deviceEventCallback), this );
90+
int intNumberOfDevices = tdGetNumberOfDevices();
91+
for (int i = 0; i < intNumberOfDevices; i++) {
92+
int id = tdGetDeviceId(i);
93+
char *name = tdGetName(id);
94+
_log.Log(LOG_NORM, "Tellstick: %s method %d", name, tdMethods(id, TELLSTICK_TURNON | TELLSTICK_TURNOFF | TELLSTICK_DIM) & TELLSTICK_DIM);
95+
bool isDimmer = tdMethods(id, TELLSTICK_TURNON | TELLSTICK_TURNOFF | TELLSTICK_DIM) & TELLSTICK_DIM;
96+
AddSwitchIfNotExits(id, name, isDimmer);
97+
tdReleaseString(name);
98+
}
99+
100+
}
101+
102+
bool CTellstick::StartHardware()
103+
{
104+
Init();
105+
m_bIsStarted=true;
106+
sOnConnected(this);
107+
_log.Log(LOG_NORM, "Tellstick: StartHardware");
108+
return true;
109+
}
110+
111+
bool CTellstick::StopHardware()
112+
{
113+
tdClose();
114+
m_bIsStarted=false;
115+
return true;
116+
}
117+
118+
bool CTellstick::WriteToHardware(const char *pdata, const unsigned char length)
119+
{
120+
_tGeneralSwitch *pSwitch = (_tGeneralSwitch*)pdata;
121+
//tRBUF *pCmd=(tRBUF*) pdata;
122+
_log.Log(LOG_NORM, "Tellstick: WriteToHardware %d id: %d cmd: %d", pSwitch->type, pSwitch->id, pSwitch->cmnd);
123+
124+
if (pSwitch->type != pTypeGeneralSwitch)
125+
return false; //only allowed to control switches
126+
127+
if (pSwitch->cmnd == gswitch_sOn)
128+
{
129+
_log.Log(LOG_NORM, "Tellstick: Switch ON");
130+
tdTurnOn(pSwitch->id);
131+
}
132+
else if(pSwitch->cmnd == gswitch_sOff)
133+
{
134+
_log.Log(LOG_NORM, "Tellstick: Switch OFF");
135+
tdTurnOff(pSwitch->id);
136+
}
137+
else if(pSwitch->cmnd == gswitch_sSetLevel)
138+
{
139+
_log.Log(LOG_NORM, "Tellstick: Dim level %d %d", pSwitch->level, pSwitch->level * 255 / 99);
140+
tdDim(pSwitch->id, pSwitch->level * 255 / 99);
141+
}
142+
143+
return true;
144+
}
145+
void CTellstick::SendCommand(const int ID, const std::string &command)
146+
{
147+
_log.Log(LOG_NORM, "Tellstick: SendCommand");
148+
}
149+
#endif //WITH_TELLDUSCORE

hardware/Tellstick.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#pragma once
2+
3+
#ifdef WITH_TELLDUSCORE
4+
5+
#include "DomoticzHardware.h"
6+
#include <iostream>
7+
8+
class CTellstick : public CDomoticzHardwareBase
9+
{
10+
public:
11+
CTellstick(const int ID);
12+
~CTellstick(void);
13+
bool WriteToHardware(const char *pdata, const unsigned char length);
14+
void SendCommand(const int ID, const std::string &command);
15+
16+
void deviceEvent(int deviceId, int method, const char *data);
17+
static void deviceEventCallback(int deviceId, int method, const char *data, int callbackId, void *context);
18+
private:
19+
bool AddSwitchIfNotExits(const int id, const char* devname, bool isDimmer);
20+
void Init();
21+
bool StartHardware();
22+
bool StopHardware();
23+
};
24+
25+
#endif //WITH_TELLSTICK

main/RFXNames.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ const char *Hardware_Type_Desc(int hType)
154154
{ HTYPE_Wunderground, "Weather Underground" },
155155
{ HTYPE_ForecastIO, "Forecast IO (Weather Lookup)" },
156156
{ HTYPE_Dummy, "Dummy (Does nothing, use for virtual switches only)" },
157+
{ HTYPE_Tellstick, "Tellstick" },
157158
{ HTYPE_PiFace, "PiFace - Raspberry Pi IO expansion board" },
158159
{ HTYPE_S0SmartMeter, "S0 Meter USB" },
159160
{ HTYPE_OpenThermGateway, "OpenTherm Gateway USB" },

main/RFXNames.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ enum _eHardwareTypes {
126126
HTYPE_ANNATHERMOSTAT, //56
127127
HTYPE_WINDDELEN, //57
128128
HTYPE_SatelIntegra, //58
129+
HTYPE_Tellstick, //59
129130
HTYPE_END
130131
};
131132

main/WebServer.cpp

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,9 @@ namespace http {
955955
else if (htype == HTYPE_Dummy) {
956956
//all fine here!
957957
}
958+
else if (htype == HTYPE_Tellstick) {
959+
//all fine here!
960+
}
958961
else if (htype == HTYPE_EVOHOME_SCRIPT || htype == HTYPE_EVOHOME_SERIAL) {
959962
//all fine here!
960963
}
@@ -2710,36 +2713,20 @@ namespace http {
27102713
std::string rState = (command == 1) ? "On" : "Off";
27112714

27122715
//first check if this device is not the scene code!
2713-
result = m_sql.safe_query("SELECT HardwareID, DeviceID, Unit, Type, SubType, SwitchType FROM DeviceStatus WHERE (ID=='%q')",
2714-
devidx.c_str());
2716+
result = m_sql.safe_query("SELECT Activators FROM Scenes WHERE (ID=='%q')", idx.c_str());
27152717
if (result.size() > 0)
27162718
{
2717-
int dType = atoi(result[0][3].c_str());
2718-
int sType = atoi(result[0][4].c_str());
2719-
_eSwitchType switchtype = (_eSwitchType)atoi(result[0][5].c_str());
2720-
unsigned char scommand;
2721-
if (GetLightCommand(dType, sType, switchtype, rState, scommand))
2719+
std::vector<std::string> arrayActivators;
2720+
StringSplit(result[0][0], ";", arrayActivators);
2721+
std::vector<std::string>::const_iterator ittAct;
2722+
for (ittAct = arrayActivators.begin(); ittAct != arrayActivators.end(); ++ittAct)
27222723
{
2723-
command = scommand;
2724-
}
2725-
2726-
result2 = m_sql.safe_query("SELECT HardwareID, DeviceID, Unit, Type, SubType FROM Scenes WHERE (ID=='%q')",
2727-
idx.c_str());
2728-
if (result2.size() > 0)
2729-
{
2730-
if (
2731-
(result[0][0] == result2[0][0]) &&
2732-
(result[0][1] == result2[0][1]) &&
2733-
(result[0][2] == result2[0][2]) &&
2734-
(result[0][3] == result2[0][3]) &&
2735-
(result[0][4] == result2[0][4])
2736-
)
2724+
std::string sDevice = *ittAct;
2725+
if (sDevice == devidx)
27372726
{
2738-
//This is not allowed!
2739-
return;
2727+
return; //not allowed
27402728
}
27412729
}
2742-
27432730
}
27442731
//first check if it is not already a part of this scene/group (with the same OnDelay)
27452732
result = m_sql.safe_query("SELECT ID FROM SceneDevices WHERE (DeviceRowID=='%q') AND (SceneRowID =='%q') AND (OnDelay == %d)",
@@ -3075,6 +3062,7 @@ namespace http {
30753062
case HTYPE_EnOceanESP2:
30763063
case HTYPE_EnOceanESP3:
30773064
case HTYPE_Dummy:
3065+
case HTYPE_Tellstick:
30783066
case HTYPE_EVOHOME_SCRIPT:
30793067
case HTYPE_EVOHOME_SERIAL:
30803068
case HTYPE_RaspberryGPIO:

main/mainworker.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "../hardware/Wunderground.h"
3636
#include "../hardware/ForecastIO.h"
3737
#include "../hardware/Dummy.h"
38+
#include "../hardware/Tellstick.h"
3839
#include "../hardware/PiFace.h"
3940
#include "../hardware/S0MeterSerial.h"
4041
#include "../hardware/OTGWSerial.h"
@@ -793,6 +794,11 @@ bool MainWorker::AddHardwareFromParams(
793794
case HTYPE_Dummy:
794795
pHardware = new CDummy(ID);
795796
break;
797+
#ifdef WITH_TELLDUSCORE
798+
case HTYPE_Tellstick:
799+
pHardware = new CTellstick(ID);
800+
break;
801+
#endif //WITH_TELLDUSCORE
796802
case HTYPE_EVOHOME_SCRIPT:
797803
pHardware = new CEvohome(ID,"");
798804
break;

0 commit comments

Comments
 (0)