Convert sscanf in ProtocolNexa and ProtocolWaveman to a faster and platform independent implementation
This commit is contained in:
parent
818ae8abed
commit
7b82e529cc
3 changed files with 7 additions and 11 deletions
|
@ -165,10 +165,7 @@ std::string ProtocolNexa::getStringSelflearningForCode(int intHouse, int intCode
|
|||
}
|
||||
|
||||
std::string ProtocolNexa::decodeData(const ControllerMessage& dataMsg) {
|
||||
uint32_t allData = 0;
|
||||
|
||||
// TODO(micke): Convert sscanf. This is slow and can overflow buffers!
|
||||
sscanf(dataMsg.getParameter("data").c_str(), "%lx", reinterpret_cast<long*>(&allData)); // NOLINT
|
||||
uint64_t allData = dataMsg.getInt64Parameter("data");
|
||||
|
||||
if(TelldusCore::comparei(dataMsg.model(), L"selflearning")) {
|
||||
// selflearning
|
||||
|
@ -179,7 +176,7 @@ std::string ProtocolNexa::decodeData(const ControllerMessage& dataMsg) {
|
|||
}
|
||||
}
|
||||
|
||||
std::string ProtocolNexa::decodeDataSelfLearning(uint32_t allData) {
|
||||
std::string ProtocolNexa::decodeDataSelfLearning(uint64_t allData) {
|
||||
unsigned int house = 0;
|
||||
unsigned int unit = 0;
|
||||
unsigned int group = 0;
|
||||
|
@ -216,7 +213,7 @@ std::string ProtocolNexa::decodeDataSelfLearning(uint32_t allData) {
|
|||
return retString.str();
|
||||
}
|
||||
|
||||
std::string ProtocolNexa::decodeDataCodeSwitch(uint32_t allData) {
|
||||
std::string ProtocolNexa::decodeDataCodeSwitch(uint64_t allData) {
|
||||
unsigned int house = 0;
|
||||
unsigned int unit = 0;
|
||||
unsigned int method = 0;
|
||||
|
|
|
@ -28,8 +28,8 @@ protected:
|
|||
|
||||
private:
|
||||
static int lastArctecCodeSwitchWasTurnOff;
|
||||
static std::string decodeDataCodeSwitch(uint32_t allData);
|
||||
static std::string decodeDataSelfLearning(uint32_t allData);
|
||||
static std::string decodeDataCodeSwitch(uint64_t allData);
|
||||
static std::string decodeDataSelfLearning(uint64_t allData);
|
||||
};
|
||||
|
||||
#endif // TELLDUS_CORE_SERVICE_PROTOCOLNEXA_H_
|
||||
|
|
|
@ -25,13 +25,12 @@ std::string ProtocolWaveman::getOffCode() const {
|
|||
}
|
||||
|
||||
std::string ProtocolWaveman::decodeData(const ControllerMessage& dataMsg) {
|
||||
uint32_t allData = 0;
|
||||
uint64_t allData = 0;
|
||||
unsigned int house = 0;
|
||||
unsigned int unit = 0;
|
||||
unsigned int method = 0;
|
||||
|
||||
// TODO(micke): Convert sscanf. This is slow and can overflow buffers!
|
||||
sscanf(dataMsg.getParameter("data").c_str(), "%lx", reinterpret_cast<long*>(&allData)); // NOLINT
|
||||
allData = dataMsg.getInt64Parameter("data");
|
||||
|
||||
method = allData & 0xF00;
|
||||
method >>= 8;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue