Add heuristic to apator162 decoding.

pull/111/head
Fredrik Öhrström 2020-04-30 09:15:01 +02:00
rodzic 5aacdfecf3
commit 3edd661667
3 zmienionych plików z 44 dodań i 2 usunięć

Wyświetl plik

@ -48,3 +48,9 @@ telegram=|6E4401062020202605077AAD0060852F2F|0F0E4442941A000043B502844265594C655
telegram=|6E4401062020202605077AAE0060852F2F|0F0F4442941A000043B50281D87F57D87F570101000010AB4400007B012C440000BE3E00008838000072340000493000009B2C00001D2C0000822B00007428000010250000B7200000261C0000A0A4D9A103FFFFFFFFFFFFFFFFFFFF5F22|
{"media":"water","meter":"apator162","name":"MyTapWatere","id":"26202020","total_m3":17.579,"timestamp":"1111-11-11T11:11:11Z"}
|MyTapWatere;26202020;17.579000;1111-11-11 11:11.11
# Even more apators....
telegram=|6E4401062020202705077A3D0060852F2F|0F151794940A020043040381D87F57D87F570101000010783E00007B01223C00009137000098320000392D000010290000F02600004C2400003422000004220000CB21000017200000C51C0000A09AD9A103FFFFFFFFFFFFFFFFFFFF367E|
{"media":"water","meter":"apator162","name":"MyTapWatere","id":"27202020","total_m3":15.992,"timestamp":"1111-11-11T11:11:11Z"}
|MyTapWatere;27202020;15.992000;1111-11-11 11:11.11

Wyświetl plik

@ -132,8 +132,43 @@ void MeterApator162::processContent(Telegram *t)
return;
}
uint32_t o9 = content[9] | content[9+1] <<8 | content[9+2] << 16 | content[9+3] << 24;
uint32_t o12 = content[12] | content[12+1] <<8 | content[12+2] << 16 | content[12+3] << 24;
uint32_t o20 = content[20] | content[20+1] <<8 | content[20+2] << 16 | content[20+3] << 24;
uint32_t o23 = content[23] | content[23+1] <<8 | content[23+2] << 16 | content[23+3] << 24;
uint32_t guess = content[o] | content[o+1] <<8 | content[o+2] << 16 | content[o+3] << 24;
strprintf(total, "%02x%02x%02x%02x", content[o], content[o+1], content[o+2], content[o+3]);
debug("\n(apator162) Guessing offset to be %d from byte >10=%02x 11=%02x 12=%02x<: total %s\n\n", o, guess10, guess11, guess12, total.c_str());
debug("(apator162) Guessing offset to be %d from byte >10=%02x 11=%02x 12=%02x<: total %s\n",
o, guess10, guess11, guess12, total.c_str());
debug("(apator162) other potential values o9=%u o12=%u o20=%u o23=%u guess=%u\n", o9, o12, o20, o23, guess);
// Ok, the guess might not good enough. Lets do a sanity check and revert to another offset
// that has a reasonable value.....at least it should be less than 58400000 liters.....why?
// Let us assume a 16 year lifetime of the apator meter, 10 m3 per day for 16 years = 16*365*10000 = 58400000
#define MAX 58400000
if (guess > MAX)
{
if (o9 < MAX)
{
o = 9;
}
else if (o12 < MAX)
{
o = 12;
}
else if (o20 < MAX)
{
o = 20;
}
else if (o23 < MAX)
{
o = 23;
}
strprintf(total, "%02x%02x%02x%02x", content[o], content[o+1], content[o+2], content[o+3]);
debug("(apator162) adjusting to offset %d instead\n", o);
}
vendor_values["0413"] = { 25, DVEntry(MeasurementType::Instantaneous, 0x13, 0, 0, 0, total) };
int offset;

Wyświetl plik

@ -14,7 +14,8 @@ METERS="Wasser apator162 20202020 NOKEY
MyTapWaterc apator162 23202020 NOKEY
MyTapWaterd apator162 24202020 NOKEY
MyTapWatere apator162 25202020 NOKEY
MyTapWatere apator162 26202020 NOKEY"
MyTapWatere apator162 26202020 NOKEY
MyTapWatere apator162 27202020 NOKEY"
cat simulations/simulation_apas.txt | grep '^{' > $TEST/test_expected.txt
$PROG --format=json simulations/simulation_apas.txt $METERS > $TEST/test_output.txt