Added support for Oregon Scientific C844 (pool thermometer)

This commit is contained in:
Stefan Persson 2014-01-13 14:39:15 +01:00
parent 4b181e30e3
commit c9567f3698
2 changed files with 49 additions and 0 deletions

View file

@ -25,6 +25,9 @@ std::string ProtocolOregon::decodeData(const ControllerMessage &dataMsg) {
return decode1984(data, model);
} else if (model.compare(L"0x2914") == 0) {
return decode2914(data);
} else if (model.compare(L"0xC844") == 0 || model.compare(L"0xEC40") == 0) {
// C844 - pool thermometer
return decodeC844(data, model);
}
return "";
@ -297,3 +300,48 @@ std::string ProtocolOregon::decodeF824(const std::string &data) {
return retString.str();
}
std::string ProtocolOregon::decodeC844(const std::string &data, const std::wstring &model) {
uint64_t value = TelldusCore::hexTo64l(data);
uint8_t messageChecksum1 = value & 0xF;
value >>= 4;
uint8_t messageChecksum2 = value & 0xF;
value >>= 4;
uint8_t neg = value & 0xF;
value >>= 4;
uint8_t temp1 = value & 0xF;
value >>= 4;
uint8_t temp2 = value & 0xF;
value >>= 4;
uint8_t temp3 = value & 0xF;
value >>= 4;
uint8_t battery = value & 0xF; // PROBABLY battery
value >>= 4;
uint8_t rollingcode = ((value >> 4) & 0xF) + (value & 0xF);
uint8_t checksum = ((value >> 4) & 0xF) + (value & 0xF);
value >>= 8;
uint8_t channel = value & 0xF;
checksum += neg + temp1 + temp2 + temp3 + battery + channel;
if (model.compare(L"0xC844") == 0) {
checksum += 0xC + 0x8 + 0x4 + 0x4;
} else {
checksum += 0xE + 0xC + 0x4 + 0x0;
}
if (((checksum >> 4) & 0xF) != messageChecksum1 || (checksum & 0xF) != messageChecksum2) {
// checksum error
return "";
}
double temperature = ((temp1 * 100) + (temp2 * 10) + temp3)/10.0;
if (neg) {
temperature = -temperature;
}
std::stringstream retString;
retString << "class:sensor;protocol:oregon;model:C844;id:" << static_cast<int>(rollingcode)
<< ";temp:" << std::fixed << std::setprecision(1) << temperature << ";";
return retString.str();
}

View file

@ -21,6 +21,7 @@ protected:
static std::string decodeF824(const std::string &data);
static std::string decode1984(const std::string &data, const std::wstring &model);
static std::string decode2914(const std::string &data);
static std::string decodeC844(const std::string &data, const std::wstring &model);
};
#endif // TELLDUS_CORE_SERVICE_PROTOCOLOREGON_H_