Implement sensor Mandolyn, this closes #104

This commit is contained in:
Micke Prag 2011-12-21 15:57:45 +01:00
parent c030185438
commit 16a9b87fb6
4 changed files with 66 additions and 0 deletions

View file

@ -44,6 +44,8 @@ SET( telldus-service_protocol_SRCS
ProtocolHasta.cpp ProtocolHasta.cpp
ProtocolIkea.h ProtocolIkea.h
ProtocolIkea.cpp ProtocolIkea.cpp
ProtocolMandolyn.h
ProtocolMandolyn.cpp
ProtocolNexa.h ProtocolNexa.h
ProtocolNexa.cpp ProtocolNexa.cpp
ProtocolOregon.h ProtocolOregon.h

View file

@ -10,6 +10,7 @@
#include "ProtocolGroup.h" #include "ProtocolGroup.h"
#include "ProtocolHasta.h" #include "ProtocolHasta.h"
#include "ProtocolIkea.h" #include "ProtocolIkea.h"
#include "ProtocolMandolyn.h"
#include "ProtocolNexa.h" #include "ProtocolNexa.h"
#include "ProtocolOregon.h" #include "ProtocolOregon.h"
#include "ProtocolRisingSun.h" #include "ProtocolRisingSun.h"
@ -239,6 +240,12 @@ std::list<std::string> Protocol::decodeData(const std::string &fullData) {
retval.push_back(decoded); retval.push_back(decoded);
} }
} }
else if(TelldusCore::comparei(dataMsg.protocol(), L"mandolyn") ) {
decoded = ProtocolMandolyn::decodeData(dataMsg);
if (decoded != "") {
retval.push_back(decoded);
}
}
else if(TelldusCore::comparei(dataMsg.protocol(), L"oregon") ) { else if(TelldusCore::comparei(dataMsg.protocol(), L"oregon") ) {
decoded = ProtocolOregon::decodeData(dataMsg); decoded = ProtocolOregon::decodeData(dataMsg);
if (decoded != "") { if (decoded != "") {

View file

@ -0,0 +1,44 @@
#include "ProtocolMandolyn.h"
#include <stdlib.h>
#include <sstream>
#include <iomanip>
#ifdef _MSC_VER
typedef unsigned __int8 uint8_t;
typedef unsigned __int32 uint32_t;
#else
#include <stdint.h>
#endif
std::string ProtocolMandolyn::decodeData(ControllerMessage &dataMsg)
{
std::string data = dataMsg.getParameter("data");
uint32_t value = strtol(data.c_str(), NULL, 16);
bool parity = value & 0x1;
value >>= 1;
double temp = (value & 0x7FFF) - 6400;
temp = temp/128.0;
value >>= 15;
uint8_t humidity = (value & 0x7F);
value >>= 7;
bool battOk = value & 0x1;
value >>= 3;
uint8_t channel = (value & 0x3)+1;
value >>= 2;
uint8_t house = value & 0xF;
std::stringstream retString;
retString << "class:sensor;protocol:mandolyn;id:"
<< house*10+channel
<< ";model:temperaturehumidity;"
<< "temp:" << std::fixed << std::setprecision(1) << temp
<< ";humidity:" << (int)humidity << ";";
return retString.str();
}

View file

@ -0,0 +1,13 @@
#ifndef PROTOCOLMANDOLYN_H
#define PROTOCOLMANDOLYN_H
#include "ControllerMessage.h"
#include "Protocol.h"
class ProtocolMandolyn : public Protocol
{
public:
static std::string decodeData(ControllerMessage &dataMsg);
};
#endif //PROTOCOLMANDOLYN_H