Skip spurious bytes when testing for amb8465.

pull/303/head
Fredrik Öhrström 2021-06-09 12:51:37 +02:00
rodzic ab76ea9788
commit 08b9153167
3 zmienionych plików z 26 dodań i 0 usunięć

Wyświetl plik

@ -1933,3 +1933,19 @@ bool isValidBps(string b)
if (b == "115200") return true;
return false;
}
size_t findBytes(vector<uchar> &v, uchar a, uchar b, uchar c)
{
size_t p = 0;
while (p+2 < v.size())
{
if (v[p+0] == a &&
v[p+1] == b &&
v[p+2] == c)
{
return p;
}
p++;
}
return 0;
}

Wyświetl plik

@ -214,4 +214,6 @@ std::string lookForExecutable(std::string prog, std::string bin_dir, std::string
bool parseExtras(std::string s, std::map<std::string,std::string> *extras);
void checkIfMultipleWmbusMetersRunning();
size_t findBytes(std::vector<uchar> &v, uchar a, uchar b, uchar c);
#endif

Wyświetl plik

@ -592,6 +592,14 @@ AccessCheck detectAMB8465(Detected *detected, shared_ptr<SerialCommunicationMana
// FF8A7A00780080710200000000FFFFFA00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF003200021400FFFFFFFFFF010004000000FFFFFF01440000000000000000FFFF0B040100FFFFFFFFFF00030000FFFFFFFFFFFFFF0000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF17
size_t skip = findBytes(response, 0xff, 0x8A, 0x7A);
while (skip > 0)
{
// Sometimes there seems to be a leading 00 noise byte. Skip those.
response.erase(response.begin());
skip--;
}
if (response.size() < 8 ||
response[0] != 0xff ||
response[1] != (0x80 | request[1]) ||