kopia lustrzana https://github.com/weetmuts/wmbusmeters
In logged telegrams, separate header from body with # instead of |, this makes it easier to double-click select copy and paste telegrams to the command line for decoding using wmbusmeters.
rodzic
27dd42101d
commit
c20a63e5b7
|
@ -246,7 +246,7 @@ void handleResetAfter(Configuration *c, string s)
|
|||
bool handleDeviceOrHex(Configuration *c, string devicefilehex)
|
||||
{
|
||||
bool invalid_hex = false;
|
||||
bool is_hex = isHexString(devicefilehex, &invalid_hex);
|
||||
bool is_hex = isHexStringFlex(devicefilehex, &invalid_hex);
|
||||
if (is_hex)
|
||||
{
|
||||
if (invalid_hex)
|
||||
|
|
|
@ -988,10 +988,12 @@ void test_aes()
|
|||
}
|
||||
}
|
||||
|
||||
void test_is_hex(const char *hex, bool expected_ok, bool expected_invalid)
|
||||
void test_is_hex(const char *hex, bool expected_ok, bool expected_invalid, bool strict)
|
||||
{
|
||||
bool got_invalid;
|
||||
bool got_ok = isHexString(hex, &got_invalid);
|
||||
bool got_ok;
|
||||
if (strict) got_ok = isHexStringStrict(hex, &got_invalid);
|
||||
else got_ok = isHexStringFlex(hex, &got_invalid);
|
||||
|
||||
if (got_ok != expected_ok || got_invalid != expected_invalid)
|
||||
{
|
||||
|
@ -1000,12 +1002,16 @@ void test_is_hex(const char *hex, bool expected_ok, bool expected_invalid)
|
|||
expected_ok, expected_invalid, got_ok, got_invalid);
|
||||
}
|
||||
}
|
||||
|
||||
void test_hex()
|
||||
{
|
||||
test_is_hex("00112233445566778899aabbccddeeff", true, false);
|
||||
test_is_hex("00112233445566778899AABBCCDDEEFF", true, false);
|
||||
test_is_hex("00112233445566778899AABBCCDDEEF", true, true);
|
||||
test_is_hex("00112233445566778899AABBCCDDEEFG", false, false);
|
||||
test_is_hex("00112233445566778899aabbccddeeff", true, false, true);
|
||||
test_is_hex("00112233445566778899AABBCCDDEEFF", true, false, true);
|
||||
test_is_hex("00112233445566778899AABBCCDDEEF", true, true, true);
|
||||
test_is_hex("00112233445566778899AABBCCDDEEFG", false, false, true);
|
||||
|
||||
test_is_hex("00 11 22 33#44|55#66 778899aabbccddeeff", true, false, false);
|
||||
test_is_hex("00 11 22 33#4|55#66 778899aabbccddeeff", true, true, false);
|
||||
}
|
||||
|
||||
void test_translate()
|
||||
|
|
37
src/util.cc
37
src/util.cc
|
@ -163,12 +163,8 @@ uchar reverse(uchar c)
|
|||
return ((c&15)<<4) | (c>>4);
|
||||
}
|
||||
|
||||
bool isHexString(const string &txt, bool *invalid)
|
||||
{
|
||||
return isHexString(txt.c_str(), invalid);
|
||||
}
|
||||
|
||||
bool isHexString(const char* txt, bool *invalid)
|
||||
bool isHexString(const char* txt, bool *invalid, bool strict)
|
||||
{
|
||||
*invalid = false;
|
||||
// An empty string is not an hex string.
|
||||
|
@ -179,19 +175,46 @@ bool isHexString(const char* txt, bool *invalid)
|
|||
for (;;)
|
||||
{
|
||||
char c = *i++;
|
||||
if (!strict && c == '#') continue; // Ignore hashes if not strict
|
||||
if (!strict && c == ' ') continue; // Ignore hashes if not strict
|
||||
if (!strict && c == '|') continue; // Ignore hashes if not strict
|
||||
if (c == 0) break;
|
||||
n++;
|
||||
if (char2int(c) == -1) return false;
|
||||
}
|
||||
// An empty string is not an hex string.
|
||||
if (n == 0) return false;
|
||||
if (n%2 == 1) *invalid = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool isHexStringFlex(const char* txt, bool *invalid)
|
||||
{
|
||||
return isHexString(txt, invalid, false);
|
||||
}
|
||||
|
||||
bool isHexStringFlex(const std::string &txt, bool *invalid)
|
||||
{
|
||||
return isHexString(txt.c_str(), invalid, false);
|
||||
}
|
||||
|
||||
bool isHexStringStrict(const char* txt, bool *invalid)
|
||||
{
|
||||
return isHexString(txt, invalid, true);
|
||||
}
|
||||
|
||||
bool isHexStringStrict(const std::string &txt, bool *invalid)
|
||||
{
|
||||
return isHexString(txt.c_str(), invalid, true);
|
||||
}
|
||||
|
||||
bool hex2bin(const char* src, vector<uchar> *target)
|
||||
{
|
||||
if (!src) return false;
|
||||
while(*src && src[1]) {
|
||||
if (*src == ' ') {
|
||||
if (*src == ' ' || *src == '#' || *src == '|') {
|
||||
// Ignore space and hashes and pipes.
|
||||
src++;
|
||||
} else {
|
||||
int hi = char2int(*src);
|
||||
|
@ -989,7 +1012,7 @@ void logTelegram(vector<uchar> &original, vector<uchar> &parsed, int header_size
|
|||
string content = parsed_hex.substr(header_size*2);
|
||||
if (suffix_size == 0)
|
||||
{
|
||||
notice("telegram=|%s|%s|+%ld\n",
|
||||
notice("telegram=|%s#%s|+%ld\n",
|
||||
header.c_str(), content.c_str(), diff);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -42,8 +42,12 @@ uchar reverse(uchar c);
|
|||
|
||||
bool isHexChar(uchar c);
|
||||
|
||||
bool isHexString(const char* txt, bool *invalid);
|
||||
bool isHexString(const std::string &txt, bool *invalid);
|
||||
// Flex strings contain hexadecimal digits and permit # | and whitespace.
|
||||
bool isHexStringFlex(const char* txt, bool *invalid);
|
||||
bool isHexStringFlex(const std::string &txt, bool *invalid);
|
||||
// Strict strings contain only hexadecimal digits.
|
||||
bool isHexStringStrict(const char* txt, bool *invalid);
|
||||
bool isHexStringStrict(const std::string &txt, bool *invalid);
|
||||
bool hex2bin(const char* src, std::vector<uchar> *target);
|
||||
bool hex2bin(std::string &src, std::vector<uchar> *target);
|
||||
bool hex2bin(std::vector<uchar> &src, std::vector<uchar> *target);
|
||||
|
|
|
@ -4625,7 +4625,7 @@ bool check_file(string f, bool *is_tty, bool *is_stdin, bool *is_file, bool *is_
|
|||
}
|
||||
// A hex string becomes a simulation file with a single line containing a telegram defined by the hex string.
|
||||
bool invalid_hex = false;
|
||||
if (isHexString(f.c_str(), &invalid_hex))
|
||||
if (isHexStringFlex(f.c_str(), &invalid_hex))
|
||||
{
|
||||
*is_simulation = true;
|
||||
*is_hex_simulation = true;
|
||||
|
|
|
@ -53,7 +53,7 @@ fi
|
|||
|
||||
RES=$(cat $TEST/thelog2.txt | tr '\n' ' ' | tr -d ' ')
|
||||
|
||||
EXP=$(printf 'telegram=|A244EE4D785634123C067A8F000000|0C1348550000426CE1F14C130000000082046C21298C0413330000008D04931E3A3CFE3300000033000000330000003300000033000000330000003300000033000000330000003300000033000000330000004300000034180000046D0D0B5C2B03FD6C5E150082206C5C290BFD0F0200018C4079678885238310FD3100000082106C01018110FD610002FD66020002FD170000|+0 telegram=|A244EE4D111111113C077AAC000000|0C1389490000426CE1F14C130000000082046C21298C0413010000008D04931E3A3CFE0100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000001600000031130000046D0A0C5C2B03FD6C60150082206C5C290BFD0F0200018C4079629885238310FD3100000082106C01018110FD610002FD66020002FD170000|+0 telegram=|1E44AE4C9956341268077A36001000|2F2F0413181E0000023B00002F2F2F2F|+0 telegram=|1844AE4C4455223368077A55000000|041389E20100023B0000|+0' | tr '\n' ' ' | tr -d ' ')
|
||||
EXP=$(printf 'telegram=|A244EE4D785634123C067A8F000000#0C1348550000426CE1F14C130000000082046C21298C0413330000008D04931E3A3CFE3300000033000000330000003300000033000000330000003300000033000000330000003300000033000000330000004300000034180000046D0D0B5C2B03FD6C5E150082206C5C290BFD0F0200018C4079678885238310FD3100000082106C01018110FD610002FD66020002FD170000|+0 telegram=|A244EE4D111111113C077AAC000000#0C1389490000426CE1F14C130000000082046C21298C0413010000008D04931E3A3CFE0100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000001600000031130000046D0A0C5C2B03FD6C60150082206C5C290BFD0F0200018C4079629885238310FD3100000082106C01018110FD610002FD66020002FD170000|+0 telegram=|1E44AE4C9956341268077A36001000#2F2F0413181E0000023B00002F2F2F2F|+0 telegram=|1844AE4C4455223368077A55000000#041389E20100023B0000|+0' | tr '\n' ' ' | tr -d ' ')
|
||||
|
||||
if [ "$RES" != "$EXP" ]
|
||||
then
|
||||
|
|
Ładowanie…
Reference in New Issue