From abd9a26f05771b7d9038e38146b0771a22475b2d Mon Sep 17 00:00:00 2001 From: proddy Date: Sun, 21 Jun 2020 17:00:56 +0200 Subject: [PATCH] fix to testing int16_t --- src/helpers.cpp | 5 ++--- src/telegram.h | 2 +- src/test/test.cpp | 27 +++++++++++++++++++++++---- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/helpers.cpp b/src/helpers.cpp index 644db4b6c..f2112ada9 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -358,13 +358,12 @@ bool Helpers::hasValue(const int8_t v) { } // for short these are typically 0x8300, 0x7D00 and sometimes 0x8000 -// so we just check for anything > 0x70 bool Helpers::hasValue(const int16_t v) { - return ((v >> 8) < 0x70); + return (abs(v) < EMS_VALUE_USHORT_NOTSET); } bool Helpers::hasValue(const uint16_t v) { - return ((v >> 8) < 0x70); + return (v < EMS_VALUE_USHORT_NOTSET); } bool Helpers::hasValue(const uint32_t v) { diff --git a/src/telegram.h b/src/telegram.h index 613f0c027..b779899d7 100644 --- a/src/telegram.h +++ b/src/telegram.h @@ -44,8 +44,8 @@ static constexpr uint8_t EMS_VALUE_BOOL_OFF = 0x00; // boolean false. True can b static constexpr uint8_t EMS_VALUE_BOOL_NOTSET = 0xFE; // random number for booleans, that's not 0, 1 or FF static constexpr uint8_t EMS_VALUE_UINT_NOTSET = 0xFF; // for 8-bit unsigned ints/bytes static constexpr int8_t EMS_VALUE_INT_NOTSET = 0x7F; // for signed 8-bit ints/bytes -static constexpr int16_t EMS_VALUE_SHORT_NOTSET = 0x8300; // -32000: for 2-byte signed shorts static constexpr uint16_t EMS_VALUE_USHORT_NOTSET = 0x7D00; // 32000: for 2-byte unsigned shorts +static constexpr int16_t EMS_VALUE_SHORT_NOTSET = 0x7D00; // 32000: for 2-byte signed shorts static constexpr uint32_t EMS_VALUE_ULONG_NOTSET = 0xFFFFFFFF; // for 3-byte and 4-byte longs static constexpr uint8_t EMS_MAX_TELEGRAM_LENGTH = 32; // max length of a complete EMS telegram diff --git a/src/test/test.cpp b/src/test/test.cpp index db3287b10..395201372 100644 --- a/src/test/test.cpp +++ b/src/test/test.cpp @@ -34,13 +34,17 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & command) { uint32_t test6 = 305419896; float test7 = 89.43; - uint8_t test1u = EMS_VALUE_UINT_NOTSET; - int8_t test2u = EMS_VALUE_INT_NOTSET; - uint16_t test3u = EMS_VALUE_USHORT_NOTSET; - int16_t test4u = EMS_VALUE_USHORT_NOTSET; + uint8_t test1u = EMS_VALUE_UINT_NOTSET; + int8_t test2u = EMS_VALUE_INT_NOTSET; + uint8_t test5u = EMS_VALUE_BOOL_NOTSET; uint32_t test6u = EMS_VALUE_ULONG_NOTSET; + uint16_t test3u = EMS_VALUE_USHORT_NOTSET; + int16_t test4u = EMS_VALUE_SHORT_NOTSET; + + // TODO set to 7D00 for both + EMSdevice::print_value(shell, 2, F("Selected flow temperature1"), test1, F_(degrees), 1); // 12 EMSdevice::print_value(shell, 2, F("Selected flow temperature2"), test2, F_(degrees), 1); // -12 EMSdevice::print_value(shell, 2, F("Selected flow temperature3"), test3, F_(degrees), 10); // 45.6 @@ -62,6 +66,21 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & command) { EMSdevice::print_value(shell, 2, F("Selected flow temperature5u"), test5u, F_(degrees), EMS_VALUE_BOOL); EMSdevice::print_value(shell, 2, F("Selected flow temperature6u"), test6u, F_(degrees), 100); + shell.printfln("int16 unset = %d, [%0X] %0X %0X", test4u, test4u, (test4u >> 8), ((test4u >> 8) & 0xFF)); + shell.printfln("uint16 unset = %d, [%0X] %0X %0X", test3u, test3u, (test3u >> 8), ((test3u >> 8) & 0xFF)); + + test3u = 456; + test4u = -456; + + shell.printfln("int16 set = %d, [%0X] %0X %0X", test4u, test4u, (test4u >> 8), ((test4u >> 8) & 0xFF)); + + shell.printfln("uint16 set = %d, [%0X] %0X %0X", test3u, test3u, (test3u >> 8), ((test3u >> 8) & 0xFF)); + + test4u = 0x7D00; + + // test4u = abs(0x7D00); + shell.printfln("int16 invalid= %d, [%0X] %0X %0X", test4u, test4u, (test4u >> 8), ((test4u >> 8) & 0xFF)); + shell.println(); // check read_value to make sure it handles all the data type correctly