Added protocol Fuhaote

This commit is contained in:
Micke Prag 2010-08-30 12:34:55 +00:00
parent bbadbf6279
commit f4e248edef
4 changed files with 152 additions and 0 deletions

View file

@ -13,6 +13,7 @@ SET( telldus-core_SRCS
Device.cpp
DeviceBrateck.cpp
DeviceEverflourish.cpp
DeviceFuhaote.cpp
DeviceGroup.cpp
DeviceIkea.cpp
DeviceNexa.cpp

View file

@ -0,0 +1,113 @@
#include "DeviceFuhaote.h"
//#include <string>
//#include <bitset>
//#include <algorithm>
//#include <fstream>
using namespace TelldusCore;
const char S = 19;
const char L = 58;
const char B0[] = {S,L,L,S,0};
const char B1[] = {L,S,L,S,0};
const char OFF[] = {S,L,S,L,S,L,L,S,0};
const char ON[] = {S,L,L,S,S,L,S,L,0};
/*
* Constructor
*/
DeviceFuhaote::DeviceFuhaote(int id, const std::string &model, const std::string &name)
:Device(id, model, name)
{
}
DeviceFuhaote::~DeviceFuhaote(void)
{
}
bool DeviceFuhaote::setCode(const std::string &strNewCode) {
strCode = strNewCode;
return true;
}
bool DeviceFuhaote::setDeviceParameter(const std::string &strName, const std::string &strValue) {
if (strName.compare("code") == 0) {
return setCode(strValue);
}
return false;
}
/*
* Turn on this device
*/
int DeviceFuhaote::turnOn(Controller *controller){
std::string strCode = "S";
strCode.append(getStringCode());
strCode.append(ON);
strCode.append(1, S);
strCode.append("+");
return controller->send(strCode);
}
/*
* Turn off this device
*/
int DeviceFuhaote::turnOff(Controller *controller){
std::string strCode = "S";
strCode.append(getStringCode());
strCode.append(OFF);
strCode.append(1, S);
strCode.append("+");
return controller->send(strCode);
}
bool DeviceFuhaote::parameterMatches( const std::string &name, const std::string &value ) const {
if (name.compare("code") == 0 && value.compare(strCode) == 0) {
return true;
}
return false;
}
/*
* Has the device got the method?
*/
int DeviceFuhaote::methods(){
return (TELLSTICK_TURNON | TELLSTICK_TURNOFF);
}
std::string DeviceFuhaote::getStringCode(void){
std::string strReturn;
//House code
for(size_t i = 0; i < 5; ++i) {
if (strCode[i] == '0') {
strReturn.append(B0);
} else if (strCode[i] == '1') {
strReturn.append(B1);
}
}
//Unit code
for(size_t i = 5; i < 10; ++i) {
if (strCode[i] == '0') {
strReturn.append(B0);
} else if (strCode[i] == '1') {
strReturn.append(1, S);
strReturn.append(1, L);
strReturn.append(1, S);
strReturn.append(1, L);
}
}
return strReturn;
}
std::string DeviceFuhaote::getProtocol() const {
return "fuhaote";
}

View file

@ -0,0 +1,33 @@
#ifndef DEVICEFUHAOTE_H
#define DEVICEFUHAOTE_H
#include "Device.h"
#include <string>
namespace TelldusCore {
class DeviceFuhaote : public Device
{
public:
DeviceFuhaote(int id, const std::string &model, const std::string &name);
virtual ~DeviceFuhaote(void);
virtual int methods();
virtual std::string getProtocol() const;
virtual bool parameterMatches( const std::string &name, const std::string &value ) const;
bool setCode(const std::string &strNewCode);
protected:
virtual bool setDeviceParameter(const std::string &strName, const std::string &strValue);
virtual int turnOn(Controller *controller);
virtual int turnOff(Controller *controller);
std::string getStringCode(void);
std::string strCode;
};
}
#endif //DEVICEFUHAOTE_H

View file

@ -14,6 +14,7 @@
#include "DeviceBrateck.h"
#include "DeviceEverflourish.h"
#include "DeviceFuhaote.h"
#include "DeviceGroup.h"
#include "DeviceNexa.h"
#include "DeviceRisingSun.h"
@ -100,6 +101,10 @@ Device *Manager::getDevice(int intDeviceId){
((DeviceEverflourish*)dev)->setHouse(settings.getDeviceParameter(intDeviceId, "house"));
((DeviceEverflourish*)dev)->setUnit(settings.getDeviceParameter(intDeviceId, "unit"));
} else if (strcasecmp(protocol.c_str(), "fuhaote") == 0) {
dev = new DeviceFuhaote(intDeviceId, strModel, strName);
((DeviceFuhaote*)dev)->setCode(settings.getDeviceParameter(intDeviceId, "code"));
} else if (strcasecmp(protocol.c_str(), "group") == 0) {
dev = new DeviceGroup(intDeviceId, strModel, strName);
((DeviceGroup*)dev)->setDevices(settings.getDeviceParameter(intDeviceId, "devices"));