From 16a9b87fb6b5854a5f5d03b98cb7393a367399ef Mon Sep 17 00:00:00 2001 From: Micke Prag Date: Wed, 21 Dec 2011 15:57:45 +0100 Subject: [PATCH] Implement sensor Mandolyn, this closes #104 --- telldus-core/service/CMakeLists.txt | 2 ++ telldus-core/service/Protocol.cpp | 7 ++++ telldus-core/service/ProtocolMandolyn.cpp | 44 +++++++++++++++++++++++ telldus-core/service/ProtocolMandolyn.h | 13 +++++++ 4 files changed, 66 insertions(+) create mode 100644 telldus-core/service/ProtocolMandolyn.cpp create mode 100644 telldus-core/service/ProtocolMandolyn.h diff --git a/telldus-core/service/CMakeLists.txt b/telldus-core/service/CMakeLists.txt index d402eb11..f50c8334 100644 --- a/telldus-core/service/CMakeLists.txt +++ b/telldus-core/service/CMakeLists.txt @@ -44,6 +44,8 @@ SET( telldus-service_protocol_SRCS ProtocolHasta.cpp ProtocolIkea.h ProtocolIkea.cpp + ProtocolMandolyn.h + ProtocolMandolyn.cpp ProtocolNexa.h ProtocolNexa.cpp ProtocolOregon.h diff --git a/telldus-core/service/Protocol.cpp b/telldus-core/service/Protocol.cpp index 26740f6f..0a2be23c 100644 --- a/telldus-core/service/Protocol.cpp +++ b/telldus-core/service/Protocol.cpp @@ -10,6 +10,7 @@ #include "ProtocolGroup.h" #include "ProtocolHasta.h" #include "ProtocolIkea.h" +#include "ProtocolMandolyn.h" #include "ProtocolNexa.h" #include "ProtocolOregon.h" #include "ProtocolRisingSun.h" @@ -239,6 +240,12 @@ std::list Protocol::decodeData(const std::string &fullData) { 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") ) { decoded = ProtocolOregon::decodeData(dataMsg); if (decoded != "") { diff --git a/telldus-core/service/ProtocolMandolyn.cpp b/telldus-core/service/ProtocolMandolyn.cpp new file mode 100644 index 00000000..420d6bdb --- /dev/null +++ b/telldus-core/service/ProtocolMandolyn.cpp @@ -0,0 +1,44 @@ +#include "ProtocolMandolyn.h" +#include +#include +#include + +#ifdef _MSC_VER +typedef unsigned __int8 uint8_t; +typedef unsigned __int32 uint32_t; +#else +#include +#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(); +} diff --git a/telldus-core/service/ProtocolMandolyn.h b/telldus-core/service/ProtocolMandolyn.h new file mode 100644 index 00000000..a3ff0700 --- /dev/null +++ b/telldus-core/service/ProtocolMandolyn.h @@ -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