Added decoding of receiving protocol everflourish
This commit is contained in:
parent
8565682ad8
commit
99f0b133a8
7 changed files with 76 additions and 4 deletions
|
@ -1,4 +1,7 @@
|
||||||
#include "Controller.h"
|
#include "Controller.h"
|
||||||
|
#include "Protocol.h"
|
||||||
|
#include "ControllerMessage.h"
|
||||||
|
#include <stdio.h> //TODO DEBUG
|
||||||
|
|
||||||
class Controller::PrivateData {
|
class Controller::PrivateData {
|
||||||
public:
|
public:
|
||||||
|
@ -22,3 +25,15 @@ void Controller::publishData(const std::string &msg) const {
|
||||||
data->controllerId = d->id;
|
data->controllerId = d->id;
|
||||||
d->event->signal(data);
|
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<std::string> msgList = Protocol::decodeData(protocolName, dataParam);
|
||||||
|
|
||||||
|
for (std::list<std::string>::iterator msgIt = msgList.begin(); msgIt != msgList.end(); ++msgIt){
|
||||||
|
this->publishData(*msgIt);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
#ifndef CONTROLLER_H
|
#ifndef CONTROLLER_H
|
||||||
#define CONTROLLER_H
|
#define CONTROLLER_H
|
||||||
|
|
||||||
#include "Event.h"
|
#include "Event.h"
|
||||||
|
@ -20,10 +20,11 @@ public:
|
||||||
protected:
|
protected:
|
||||||
Controller(int id, Event *event);
|
Controller(int id, Event *event);
|
||||||
void publishData(const std::string &data) const;
|
void publishData(const std::string &data) const;
|
||||||
|
void decodePublishData(const std::string &data) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class PrivateData;
|
class PrivateData;
|
||||||
PrivateData *d;
|
PrivateData *d;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //CONTROLLER_H
|
#endif //CONTROLLER_H
|
||||||
|
|
|
@ -191,3 +191,17 @@ std::list<std::string> Protocol::getParametersForProtocol(const std::wstring &pr
|
||||||
|
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::list<std::string> Protocol::decodeData(const std::wstring &protocolName, const std::string &data) {
|
||||||
|
std::list<std::string> retval;
|
||||||
|
std::string decoded = "";
|
||||||
|
|
||||||
|
if( protocolName == L"everflourish" ) {
|
||||||
|
decoded = ProtocolEverflourish::decodeData(data);
|
||||||
|
if (decoded != "") {
|
||||||
|
retval.push_back(decoded);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#ifndef PROTOCOL_H
|
#ifndef PROTOCOL_H
|
||||||
#define PROTOCOL_H
|
#define PROTOCOL_H
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -18,6 +18,7 @@ public:
|
||||||
|
|
||||||
static Protocol *getProtocolInstance(const std::wstring &protocolname);
|
static Protocol *getProtocolInstance(const std::wstring &protocolname);
|
||||||
static std::list<std::string> getParametersForProtocol(const std::wstring &protocolName);
|
static std::list<std::string> getParametersForProtocol(const std::wstring &protocolName);
|
||||||
|
static std::list<std::string> decodeData(const std::wstring &protocolname, const std::string &data);
|
||||||
|
|
||||||
virtual int methods() const = 0;
|
virtual int methods() const = 0;
|
||||||
std::wstring model() const;
|
std::wstring model() const;
|
||||||
|
@ -35,4 +36,4 @@ private:
|
||||||
PrivateData *d;
|
PrivateData *d;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //PROTOCOL_H
|
#endif //PROTOCOL_H
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
#include "ProtocolEverflourish.h"
|
#include "ProtocolEverflourish.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
int ProtocolEverflourish::methods() const {
|
int ProtocolEverflourish::methods() const {
|
||||||
return TELLSTICK_TURNON | TELLSTICK_TURNOFF | TELLSTICK_LEARN;
|
return TELLSTICK_TURNON | TELLSTICK_TURNOFF | TELLSTICK_LEARN;
|
||||||
|
@ -83,3 +85,39 @@ unsigned int ProtocolEverflourish::calculateChecksum(unsigned int x) {
|
||||||
|
|
||||||
return res;
|
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();
|
||||||
|
}
|
|
@ -8,6 +8,7 @@ class ProtocolEverflourish : public Protocol
|
||||||
public:
|
public:
|
||||||
int methods() const;
|
int methods() const;
|
||||||
virtual std::string getStringForMethod(int method, unsigned char data, Controller *controller);
|
virtual std::string getStringForMethod(int method, unsigned char data, Controller *controller);
|
||||||
|
static std::string decodeData(const std::string &data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static unsigned int calculateChecksum(unsigned int x);
|
static unsigned int calculateChecksum(unsigned int x);
|
||||||
|
|
|
@ -120,6 +120,8 @@ void TellStick::processData( const std::string &data ) {
|
||||||
d->fwVersion = TelldusCore::charToInteger(d->message.substr(2).c_str());
|
d->fwVersion = TelldusCore::charToInteger(d->message.substr(2).c_str());
|
||||||
} else if (d->message.substr(0,2).compare("+R") == 0) {
|
} else if (d->message.substr(0,2).compare("+R") == 0) {
|
||||||
this->publishData(d->message.substr(2));
|
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();
|
d->message.clear();
|
||||||
} else { // Append the character
|
} else { // Append the character
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue