diff --git a/telldus-core/service/CMakeLists.txt b/telldus-core/service/CMakeLists.txt index 4955600b..e52da87b 100644 --- a/telldus-core/service/CMakeLists.txt +++ b/telldus-core/service/CMakeLists.txt @@ -16,6 +16,8 @@ SET( telldus-service_SRCS SET( telldus-service_protocol_SRCS Protocol.h Protocol.cpp + ProtocolBrateck.h + ProtocolBrateck.cpp ProtocolNexa.h ProtocolNexa.cpp ) diff --git a/telldus-core/service/Protocol.cpp b/telldus-core/service/Protocol.cpp index 896035bb..b2a51498 100644 --- a/telldus-core/service/Protocol.cpp +++ b/telldus-core/service/Protocol.cpp @@ -1,7 +1,9 @@ #include "Protocol.h" #include "../client/telldus-core.h" +#include "ProtocolBrateck.h" #include "ProtocolNexa.h" + #include #include #include @@ -82,15 +84,11 @@ Protocol *Protocol::getProtocolInstance(std::wstring &protocolname){ if(comparei(protocolname, L"arctech")){ return new ProtocolNexa(); - //((ProtocolNexa*)prot)->setHouse(settings.getDeviceParameter(deviceId, "house")); - //((ProtocolNexa*)prot)->setUnit(settings.getDeviceParameter(deviceId, "unit")); - } - /*else if (wcscasecmp(protocolname.c_str(), L"brateck") == 0) { - prot = new ProtocolBrateck(deviceId, modelname); - ((ProtocolBrateck*)prot)->setHouse(settings.getDeviceParameter(deviceId, "house")); + } else if (comparei(protocolname, L"brateck")) { + return new ProtocolBrateck(); - } else if (wcscasecmp(protocolname.c_str(), L"everflourish") == 0){ + } /*else if (wcscasecmp(protocolname.c_str(), L"everflourish") == 0){ prot = new ProtocolEverflourish(deviceId, modelname); ((ProtocolEverflourish*)prot)->setHouse(settings.getDeviceParameter(deviceId, "house")); ((ProtocolEverflourish*)prot)->setUnit(settings.getDeviceParameter(deviceId, "unit")); diff --git a/telldus-core/service/ProtocolBrateck.cpp b/telldus-core/service/ProtocolBrateck.cpp new file mode 100644 index 00000000..4d8662d7 --- /dev/null +++ b/telldus-core/service/ProtocolBrateck.cpp @@ -0,0 +1,40 @@ +#include "ProtocolBrateck.h" + +std::string ProtocolBrateck::getStringForMethod(int method, const std::string &, Controller *) { + const char S = '!'; + const char L = 'V'; + const char B1[] = {L,S,L,S,0}; + const char BX[] = {S,L,L,S,0}; + const char B0[] = {S,L,S,L,0}; + const char BUP[] = {L,S,L,S,S,L,S,L,S,L,S,L,S,L,S,L,S,0}; + const char BSTOP[] = {S,L,S,L,L,S,L,S,S,L,S,L,S,L,S,L,S,0}; + const char BDOWN[] = {S,L,S,L,S,L,S,L,S,L,S,L,L,S,L,S,S,0}; + + std::string strReturn; + std::wstring strHouse = this->getStringParameter(L"house", L""); + if (strHouse == L"") { + return ""; + } + + for( size_t i = 0; i < strHouse.length(); ++i ) { + if (strHouse[i] == '1') { + strReturn.insert(0, B1); + } else if (strHouse[i] == '-') { + strReturn.insert(0, BX); + } else if (strHouse[i] == '0') { + strReturn.insert(0, B0); + } + } + + strReturn.insert(0, "S"); + if (method == TELLSTICK_TURNON) { + strReturn.append(BUP); + } else if (method == TELLSTICK_TURNOFF) { + strReturn.append(BDOWN); + } else { + return ""; + } + strReturn.append("+"); + + return strReturn; +} diff --git a/telldus-core/service/ProtocolBrateck.h b/telldus-core/service/ProtocolBrateck.h new file mode 100644 index 00000000..02985e93 --- /dev/null +++ b/telldus-core/service/ProtocolBrateck.h @@ -0,0 +1,12 @@ +#ifndef PROTOCOLBRATECK_H +#define PROTOCOLBRATECK_H + +#include "Protocol.h" + +class ProtocolBrateck : public Protocol +{ +public: + virtual std::string getStringForMethod(int method, const std::string &data, Controller *controller); +}; + +#endif //PROTOCOLBRATECK_H \ No newline at end of file