diff --git a/telldus-core/service/Controller.cpp b/telldus-core/service/Controller.cpp index 4737a63d..ca4bc4e7 100644 --- a/telldus-core/service/Controller.cpp +++ b/telldus-core/service/Controller.cpp @@ -1,4 +1,7 @@ #include "Controller.h" +#include "Protocol.h" +#include "ControllerMessage.h" +#include //TODO DEBUG class Controller::PrivateData { public: @@ -22,3 +25,15 @@ void Controller::publishData(const std::string &msg) const { data->controllerId = d->id; d->event->signal(data); } + +void Controller::decodePublishData(const std::string &data) const { + + ControllerMessage dataMsg(data); + std::wstring protocolName = dataMsg.protocol(); + std::string dataParam = dataMsg.getParameter("data"); + std::list msgList = Protocol::decodeData(protocolName, dataParam); + + for (std::list::iterator msgIt = msgList.begin(); msgIt != msgList.end(); ++msgIt){ + this->publishData(*msgIt); + } +} \ No newline at end of file diff --git a/telldus-core/service/Controller.h b/telldus-core/service/Controller.h index 5d0cbd0b..a1b92e74 100644 --- a/telldus-core/service/Controller.h +++ b/telldus-core/service/Controller.h @@ -1,4 +1,4 @@ -#ifndef CONTROLLER_H +#ifndef CONTROLLER_H #define CONTROLLER_H #include "Event.h" @@ -20,10 +20,11 @@ public: protected: Controller(int id, Event *event); void publishData(const std::string &data) const; + void decodePublishData(const std::string &data) const; private: class PrivateData; PrivateData *d; }; -#endif //CONTROLLER_H +#endif //CONTROLLER_H diff --git a/telldus-core/service/Protocol.cpp b/telldus-core/service/Protocol.cpp index e2552032..e2699eff 100644 --- a/telldus-core/service/Protocol.cpp +++ b/telldus-core/service/Protocol.cpp @@ -191,3 +191,17 @@ std::list Protocol::getParametersForProtocol(const std::wstring &pr return parameters; } + +std::list Protocol::decodeData(const std::wstring &protocolName, const std::string &data) { + std::list retval; + std::string decoded = ""; + + if( protocolName == L"everflourish" ) { + decoded = ProtocolEverflourish::decodeData(data); + if (decoded != "") { + retval.push_back(decoded); + } + } + + return retval; +} diff --git a/telldus-core/service/Protocol.h b/telldus-core/service/Protocol.h index 69b645b5..12bf37f9 100644 --- a/telldus-core/service/Protocol.h +++ b/telldus-core/service/Protocol.h @@ -1,4 +1,4 @@ -#ifndef PROTOCOL_H +#ifndef PROTOCOL_H #define PROTOCOL_H #include @@ -18,6 +18,7 @@ public: static Protocol *getProtocolInstance(const std::wstring &protocolname); static std::list getParametersForProtocol(const std::wstring &protocolName); + static std::list decodeData(const std::wstring &protocolname, const std::string &data); virtual int methods() const = 0; std::wstring model() const; @@ -35,4 +36,4 @@ private: PrivateData *d; }; -#endif //PROTOCOL_H +#endif //PROTOCOL_H diff --git a/telldus-core/service/ProtocolEverflourish.cpp b/telldus-core/service/ProtocolEverflourish.cpp index eb2022c1..d7081beb 100644 --- a/telldus-core/service/ProtocolEverflourish.cpp +++ b/telldus-core/service/ProtocolEverflourish.cpp @@ -1,4 +1,6 @@ #include "ProtocolEverflourish.h" +#include +#include int ProtocolEverflourish::methods() const { return TELLSTICK_TURNON | TELLSTICK_TURNOFF | TELLSTICK_LEARN; @@ -83,3 +85,39 @@ unsigned int ProtocolEverflourish::calculateChecksum(unsigned int x) { return res; } + +std::string ProtocolEverflourish::decodeData(const std::string& data) +{ + unsigned int allData; + unsigned int house = 0; + unsigned int unit = 0; + unsigned int method = 0; + + sscanf(data.c_str(), "%X", &allData); + + house = allData & 0xFFFC00; + house >>= 10; + + unit = allData & 0x300; + unit >>= 8; + + method = allData & 0xF; + + std::stringstream retString; + retString << "class:command;protocol:everflourish;model:selflearning;house:0x" << std::hex << house << std::dec << ";unit:0x" << std::hex << unit << std::dec << ";method:"; + if(method == 0){ + retString << "turnoff;"; + } + else if(method == 15){ + retString << "turnon;"; + } + else if(method == 10){ + retString << "learn;"; + } + else { + //not everflourish + return ""; + } + + return retString.str(); +} \ No newline at end of file diff --git a/telldus-core/service/ProtocolEverflourish.h b/telldus-core/service/ProtocolEverflourish.h index 6007b7ce..23f1f72b 100644 --- a/telldus-core/service/ProtocolEverflourish.h +++ b/telldus-core/service/ProtocolEverflourish.h @@ -8,6 +8,7 @@ class ProtocolEverflourish : public Protocol public: int methods() const; virtual std::string getStringForMethod(int method, unsigned char data, Controller *controller); + static std::string decodeData(const std::string &data); private: static unsigned int calculateChecksum(unsigned int x); diff --git a/telldus-core/service/TellStick_libftdi.cpp b/telldus-core/service/TellStick_libftdi.cpp index b2496421..1642e273 100644 --- a/telldus-core/service/TellStick_libftdi.cpp +++ b/telldus-core/service/TellStick_libftdi.cpp @@ -120,6 +120,8 @@ void TellStick::processData( const std::string &data ) { d->fwVersion = TelldusCore::charToInteger(d->message.substr(2).c_str()); } else if (d->message.substr(0,2).compare("+R") == 0) { this->publishData(d->message.substr(2)); + } else if(d->message.substr(0,2).compare("+W") == 0) { + this->decodePublishData(d->message.substr(2)); } d->message.clear(); } else { // Append the character