This commit is contained in:
parent
bf72debefb
commit
afa1e88e62
5 changed files with 28 additions and 27 deletions
|
@ -144,6 +144,14 @@ std::wstring TelldusCore::intToWStringSafe(int value){
|
|||
}
|
||||
*/
|
||||
|
||||
uint64_t TelldusCore::hexTo64l(const std::string data){
|
||||
#ifdef _WINDOWS
|
||||
return _strtoui64(data.c_str(), NULL, 16);
|
||||
#else
|
||||
return strtol(data.c_str(), NULL, 16);
|
||||
#endif
|
||||
}
|
||||
|
||||
int TelldusCore::wideToInteger(const std::wstring &input){
|
||||
std::wstringstream inputstream;
|
||||
inputstream << input;
|
||||
|
|
|
@ -3,6 +3,14 @@
|
|||
|
||||
#include <string>
|
||||
#include <stdarg.h>
|
||||
#ifdef _MSC_VER
|
||||
typedef unsigned __int8 uint8_t;
|
||||
typedef unsigned __int16 uint16_t;
|
||||
typedef unsigned __int32 uint32_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
namespace TelldusCore {
|
||||
std::wstring charToWstring(const char *value);
|
||||
|
@ -13,6 +21,7 @@ namespace TelldusCore {
|
|||
std::wstring intToWstring(int value);
|
||||
//std::wstring intToWStringSafe(int value);
|
||||
std::string intToString(int value);
|
||||
uint64_t hexTo64l(const std::string data);
|
||||
std::string wideToString(const std::wstring &input);
|
||||
|
||||
int wideToInteger(const std::wstring &input);
|
||||
|
|
|
@ -1,13 +1,8 @@
|
|||
#include "ProtocolFineoffset.h"
|
||||
#include "Strings.h"
|
||||
#include <stdlib.h>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#ifdef _MSC_VER
|
||||
typedef unsigned __int8 uint8_t;
|
||||
typedef unsigned __int16 uint16_t;
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
std::string ProtocolFineoffset::decodeData(ControllerMessage &dataMsg)
|
||||
{
|
||||
|
@ -16,13 +11,13 @@ std::string ProtocolFineoffset::decodeData(ControllerMessage &dataMsg)
|
|||
return "";
|
||||
}
|
||||
|
||||
uint8_t checksum = strtol(data.substr(data.length()-2).c_str(), NULL, 16);
|
||||
uint8_t checksum = (uint8_t)TelldusCore::hexTo64l(data.substr(data.length()-2));
|
||||
data = data.substr(0, data.length()-2);
|
||||
|
||||
uint8_t humidity = strtol(data.substr(data.length()-2).c_str(), NULL, 16);
|
||||
uint8_t humidity = (uint8_t)TelldusCore::hexTo64l(data.substr(data.length()-2));
|
||||
data = data.substr(0, data.length()-2);
|
||||
|
||||
uint16_t value = strtol(data.substr(data.length()-3).c_str(), NULL, 16);
|
||||
uint16_t value = (uint16_t)TelldusCore::hexTo64l(data.substr(data.length()-3));
|
||||
double temperature = (value & 0x7FF)/10.0;
|
||||
|
||||
value >>= 11;
|
||||
|
@ -31,7 +26,7 @@ std::string ProtocolFineoffset::decodeData(ControllerMessage &dataMsg)
|
|||
}
|
||||
data = data.substr(0, data.length()-3);
|
||||
|
||||
uint16_t id = strtol(data.c_str(), NULL, 16) & 0xFF;
|
||||
uint16_t id = (uint16_t)TelldusCore::hexTo64l(data) & 0xFF;
|
||||
|
||||
std::stringstream retString;
|
||||
retString << "class:sensor;protocol:fineoffset;id:" << id << ";model:";
|
||||
|
|
|
@ -1,19 +1,13 @@
|
|||
#include "ProtocolMandolyn.h"
|
||||
#include "Strings.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);
|
||||
uint32_t value = (uint32_t)TelldusCore::hexTo64l(data);
|
||||
|
||||
bool parity = value & 0x1;
|
||||
value >>= 1;
|
||||
|
|
|
@ -1,13 +1,8 @@
|
|||
#include "ProtocolOregon.h"
|
||||
#include "Strings.h"
|
||||
#include <stdlib.h>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#ifdef _MSC_VER
|
||||
typedef unsigned __int8 uint8_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
std::string ProtocolOregon::decodeData(ControllerMessage &dataMsg)
|
||||
{
|
||||
|
@ -24,8 +19,8 @@ std::string ProtocolOregon::decodeData(ControllerMessage &dataMsg)
|
|||
}
|
||||
|
||||
std::string ProtocolOregon::decodeEA4C(const std::string &data) {
|
||||
uint64_t value = strtol(data.c_str(), NULL, 16);
|
||||
|
||||
uint64_t value = TelldusCore::hexTo64l(data);
|
||||
|
||||
uint8_t checksum = 0xE + 0xA + 0x4 + 0xC;
|
||||
checksum -= (value & 0xF) * 0x10;
|
||||
checksum -= 0xA;
|
||||
|
@ -69,7 +64,7 @@ std::string ProtocolOregon::decodeEA4C(const std::string &data) {
|
|||
}
|
||||
|
||||
std::string ProtocolOregon::decode1A2D(const std::string &data) {
|
||||
uint64_t value = strtol(data.c_str(), NULL, 16);
|
||||
uint64_t value = TelldusCore::hexTo64l(data);
|
||||
uint8_t checksum2 = value & 0xFF;
|
||||
value >>= 8;
|
||||
uint8_t checksum1 = value & 0xFF;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue