kopia lustrzana https://github.com/weetmuts/wmbusmeters
Improved cul driver.
rodzic
418b2fd298
commit
b42c3f3af4
22
src/wmbus.cc
22
src/wmbus.cc
|
@ -1255,7 +1255,7 @@ bool Telegram::parseTPLConfig(std::vector<uchar>::iterator &pos)
|
|||
info += " ";
|
||||
has_cfg_ext = true;
|
||||
}
|
||||
addExplanationAndIncrementPos(pos, 2, "%02x%02x tpl-cfg (%s)", cfg1, cfg2, info.c_str());
|
||||
addExplanationAndIncrementPos(pos, 2, "%02x%02x tpl-cfg %04x (%s)", cfg1, cfg2, tpl_cfg, info.c_str());
|
||||
|
||||
if (has_cfg_ext)
|
||||
{
|
||||
|
@ -3531,15 +3531,9 @@ bool trimCRCsFrameFormatA(std::vector<uchar> &payload)
|
|||
debug("(wmbus) not enough bytes! expected at least 12 but got (%zu)!\n", payload.size());
|
||||
return false;
|
||||
}
|
||||
size_t len = payload[0];
|
||||
size_t len = payload.size();
|
||||
debugPayload("(wmbus) trimming frame A", payload);
|
||||
|
||||
if (len+1 > payload.size())
|
||||
{
|
||||
debug("(wmbus) not enough bytes! expected at least (%zu+1) but got (%zu)!\n", len, payload.size());
|
||||
return false;
|
||||
}
|
||||
|
||||
vector<uchar> out;
|
||||
|
||||
uint16_t calc_crc = crc16_EN13757(&payload[0], 10);
|
||||
|
@ -3589,6 +3583,7 @@ bool trimCRCsFrameFormatA(std::vector<uchar> &payload)
|
|||
size_t new_size = payload.size();
|
||||
|
||||
debug("(wmbus) trimmed %zu crc bytes from frame a and ignored %zu suffix bytes.\n", (len-new_len), (old_size-new_size)-(len-new_len));
|
||||
debugPayload("(wmbus) trimmed frame A", payload);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -3599,15 +3594,9 @@ bool trimCRCsFrameFormatB(std::vector<uchar> &payload)
|
|||
debug("(wmbus) not enough bytes! expected at least 12 but got (%zu)!\n", payload.size());
|
||||
return false;
|
||||
}
|
||||
size_t len = payload[0]+1;
|
||||
size_t len = payload.size();
|
||||
debugPayload("(wmbus) trimming frame B", payload);
|
||||
|
||||
if (len > payload.size())
|
||||
{
|
||||
debug("(wmbus) not enough bytes! expected at least (%zu+1) but got (%zu)!\n", len, payload.size());
|
||||
return false;
|
||||
}
|
||||
|
||||
vector<uchar> out;
|
||||
size_t crc1_pos, crc2_pos;
|
||||
if (len <= 128)
|
||||
|
@ -3631,6 +3620,7 @@ bool trimCRCsFrameFormatB(std::vector<uchar> &payload)
|
|||
}
|
||||
|
||||
out.insert(out.end(), payload.begin(), payload.begin()+crc1_pos);
|
||||
debug("(wmbus) ff b dll crc first 0-%zu %04x ok\n", crc1_pos, calc_crc);
|
||||
|
||||
if (crc2_pos > 0)
|
||||
{
|
||||
|
@ -3645,6 +3635,7 @@ bool trimCRCsFrameFormatB(std::vector<uchar> &payload)
|
|||
}
|
||||
|
||||
out.insert(out.end(), payload.begin()+crc1_pos+2, payload.begin()+crc2_pos);
|
||||
debug("(wmbus) ff b dll crc final %zu-%zu %04x ok\n", crc1_pos+2, crc2_pos, calc_crc);
|
||||
}
|
||||
|
||||
out[0] = out.size()-1;
|
||||
|
@ -3654,6 +3645,7 @@ bool trimCRCsFrameFormatB(std::vector<uchar> &payload)
|
|||
size_t new_size = payload.size();
|
||||
|
||||
debug("(wmbus) trimmed %zu crc bytes from frame b and ignored %zu suffix bytes.\n", (len-new_len), (old_size-new_size)-(len-new_len));
|
||||
debugPayload("(wmbus) trimmed frame B", payload);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -285,6 +285,9 @@ FrameStatus WMBusCUL::checkCULFrame(vector<uchar> &data,
|
|||
return PartialFrame;
|
||||
}
|
||||
eolp++; // Point to byte after CRLF.
|
||||
// Normally it is CRLF, but enable code to handle single LF as well.
|
||||
int eof_len = data[eolp-2] == '\r' ? 2 : 1;
|
||||
// If it was a CRLF then eof_len == 2, else it is 1.
|
||||
if (data[0] != 'b')
|
||||
{
|
||||
// C1 and T1 telegrams should start with a 'b'
|
||||
|
@ -298,11 +301,16 @@ FrameStatus WMBusCUL::checkCULFrame(vector<uchar> &data,
|
|||
// bY..44............<CR><LF>
|
||||
*hex_frame_length = eolp;
|
||||
vector<uchar> hex;
|
||||
hex.insert(hex.end(), data.begin()+2, data.begin()+eolp-2); // Remove CRLF
|
||||
// Why on earth do we need to remove the 4 hex chars (2 binary bytes)
|
||||
// from the end of the bY C1 telegrams, but there are no such 4 hex chars
|
||||
// to be removed for plain b T1 telegrams?????
|
||||
hex.insert(hex.end(), data.begin()+2, data.begin()+eolp-eof_len-4); // Remove CRLF
|
||||
payload.clear();
|
||||
bool ok = hex2bin(hex, &payload);
|
||||
if (!ok)
|
||||
{
|
||||
string s = safeString(hex);
|
||||
debug("(cul) bad hex \"%s\"\n", s.c_str());
|
||||
warning("(cul) warning: the hex string is not proper! Ignoring telegram!\n");
|
||||
return ErrorInFrame;
|
||||
}
|
||||
|
@ -321,11 +329,13 @@ FrameStatus WMBusCUL::checkCULFrame(vector<uchar> &data,
|
|||
// b..44..............<CR><LF>
|
||||
*hex_frame_length = eolp;
|
||||
vector<uchar> hex;
|
||||
hex.insert(hex.end(), data.begin()+1, data.begin()+eolp-2-4); // Remove CUL specific 16 bit crc and CRLF
|
||||
hex.insert(hex.end(), data.begin()+1, data.begin()+eolp-eof_len); // Remove CRLF
|
||||
payload.clear();
|
||||
bool ok = hex2bin(hex, &payload);
|
||||
if (!ok)
|
||||
{
|
||||
string s = safeString(hex);
|
||||
debug("(cul) bad hex \"%s\"\n", s.c_str());
|
||||
warning("(cul) warning: the hex string is not proper! Ignoring telegram!\n");
|
||||
return ErrorInFrame;
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue