Added hasta version 2

This commit is contained in:
Stefan Persson 2013-05-08 13:44:25 +02:00
parent a912ee2872
commit b0d3d2af30
4 changed files with 151 additions and 2 deletions

View file

@ -256,6 +256,11 @@ std::list<std::string> Protocol::decodeData(const std::string &fullData) {
if (decoded != "") {
retval.push_back(decoded);
}
} else if(TelldusCore::comparei(dataMsg.protocol(), L"hasta") ) {
decoded = ProtocolHasta::decodeData(dataMsg);
if (decoded != "") {
retval.push_back(decoded);
}
}
return retval;

View file

@ -8,12 +8,20 @@
#include <stdio.h>
#include <sstream>
#include <string>
#include "common/Strings.h"
int ProtocolHasta::methods() const {
return TELLSTICK_UP | TELLSTICK_DOWN | TELLSTICK_STOP | TELLSTICK_LEARN;
}
std::string ProtocolHasta::getStringForMethod(int method, unsigned char, Controller *) {
if (TelldusCore::comparei(model(), L"selflearningv2")) {
return getStringForMethodv2(method);
}
return getStringForMethodv1(method);
}
std::string ProtocolHasta::getStringForMethodv1(int method) {
int house = this->getIntParameter(L"house", 1, 65536);
int unit = this->getIntParameter(L"unit", 1, 15);
std::string strReturn;
@ -21,10 +29,10 @@ std::string ProtocolHasta::getStringForMethod(int method, unsigned char, Control
std::string preamble;
strReturn.append(1, 190);
strReturn.append(1, 1);
strReturn.append(1, 190);
strReturn.append(1, 107);
strReturn.append(1, 1);
strReturn.append(1, 190);
strReturn.append(1, 190);
strReturn.append(1, 165);
strReturn.append(convertByte( (house & 0xFF) ));
strReturn.append(convertByte( (house>>8) & 0xFF ));
@ -71,3 +79,133 @@ std::string ProtocolHasta::convertByte(unsigned char byte) {
}
return retval;
}
std::string ProtocolHasta::getStringForMethodv2(int method) {
int house = this->getIntParameter(L"house", 1, 65536);
int unit = this->getIntParameter(L"unit", 1, 15);
int sum = 0;
std::string strReturn;
std::string preamble;
strReturn.append(1, 190);
strReturn.append(1, 1);
strReturn.append(1, 107);
strReturn.append(1, 1);
strReturn.append(1, 190);
strReturn.append(1, 190);
strReturn.append(1, 1);
strReturn.append(1, 60);
strReturn.append(1, 160);
strReturn.append(1, 40);
strReturn.append(convertBytev2( (house>>8) & 0xFF ));
sum = ((house>>8)&0xFF);
strReturn.append(convertBytev2( (house & 0xFF) ));
sum += (house & 0xFF);
int byte = unit&0x0F;
if (method == TELLSTICK_UP) {
byte |= 0xC0;
} else if (method == TELLSTICK_DOWN) {
byte |= 0x10;
} else if (method == TELLSTICK_STOP) {
byte |= 0x50;
} else if (method == TELLSTICK_LEARN) {
byte |= 0x40;
} else {
return "";
}
strReturn.append(convertBytev2(byte));
sum += byte;
strReturn.append(convertBytev2(0x01));
sum += 0x01;
int checksum = (((int)(sum/256)+1)*256+1) - sum;
strReturn.append(convertBytev2(checksum));
strReturn.append(1, 68);
strReturn.append(1, 36);
return strReturn;
}
std::string ProtocolHasta::convertBytev2(unsigned char byte) {
std::string retval;
for(int i = 0; i < 8; ++i) {
if (byte & 1) {
retval.append(1, 68);
retval.append(1, 36);
} else {
retval.append(1, 36);
retval.append(1, 68);
}
byte >>= 1;
}
return retval;
}
std::string ProtocolHasta::decodeData(const ControllerMessage& dataMsg) {
uint64_t allData = dataMsg.getInt64Parameter("data");
unsigned int house = 0;
unsigned int unit = 0;
unsigned int method = 0;
std::string model;
std::string methodstring;
allData >>= 8;
unit = allData & 0xF;
allData >>= 4;
method = allData & 0xF;
allData >>= 4;
if(TelldusCore::comparei(dataMsg.model(), L"selflearning")) {
//version1
house = allData & 0xFFFF;
house = ((house << 8) | (house >> 8)) & 0xFFFF;
model = "selflearning";
if(method == 0){
methodstring = "up";
}
else if(method == 1){
methodstring = "down";
}
else if(method == 5){
methodstring = "stop";
}
else{
return "";
}
}
else{
//version2
house = allData & 0xFFFF;
model = "selflearningv2";
if(method == 12){
methodstring = "up";
}
else if(method == 1 or method == 8){ //is method 8 correct?
methodstring = "down";
}
else if(method == 5){
methodstring = "stop";
}
else{
return "";
}
}
if(house < 1 || house > 65535 || unit < 1 || unit > 16) {
// not hasta
return "";
}
std::stringstream retString;
retString << "class:command;protocol:hasta;model:" << model << ";house:" << house << ";unit:" << unit << ";method:" << methodstring << ";";
return retString.str();
}

View file

@ -8,15 +8,20 @@
#define TELLDUS_CORE_SERVICE_PROTOCOLHASTA_H_
#include <string>
#include "service/ControllerMessage.h"
#include "service/Protocol.h"
class ProtocolHasta : public Protocol {
public:
int methods() const;
virtual std::string getStringForMethod(int method, unsigned char data, Controller *controller);
static std::string decodeData(const ControllerMessage &dataMsg);
protected:
static std::string convertByte(unsigned char byte);
static std::string convertBytev2(unsigned char byte);
std::string getStringForMethodv1(int method);
std::string getStringForMethodv2(int method);
};
#endif // TELLDUS_CORE_SERVICE_PROTOCOLHASTA_H_

View file

@ -124,6 +124,7 @@
<type name="Projector screens and blinds" expanded="true">
<vendor name="Hasta" image="hasta">
<device model="selflearning:hasta" protocol="hasta" widget="16" image="hasta">Blinds</device>
<device model="selflearningv2:hasta" protocol="hasta" widget="16" image="hasta">Blinds (version 2)</device>
</vendor>
<vendor name="Roxcore" image="roxcore">
<device model="codeswitch:roxcore" protocol="brateck" widget="6" image="projectorscreen">Projector screen</device>