From 09f6e4196700d409ad06e1b425a90aa57eab5beb Mon Sep 17 00:00:00 2001 From: Alex Robenko Date: Wed, 22 Mar 2023 18:06:16 +1000 Subject: [PATCH 1/2] Updating next version to be v5.1.2 --- include/comms/version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/comms/version.h b/include/comms/version.h index 4e73458..15722db 100644 --- a/include/comms/version.h +++ b/include/comms/version.h @@ -17,7 +17,7 @@ #define COMMS_MINOR_VERSION 1U /// @brief Patch level of the library -#define COMMS_PATCH_VERSION 1U +#define COMMS_PATCH_VERSION 2U /// @brief Macro to create numeric version as single unsigned number #define COMMS_MAKE_VERSION(major_, minor_, patch_) \ From f8cdb39b6b30529486f3bf72d0a8d25907c8d7b9 Mon Sep 17 00:00:00 2001 From: Alex Robenko Date: Wed, 22 Mar 2023 18:26:57 +1000 Subject: [PATCH 2/2] Fixing serialization of int fields with reduced length and sign extension disabled. --- include/comms/field/adapter/FixedLength.h | 16 +++++++++++++-- test/Fields2.th | 25 +++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/include/comms/field/adapter/FixedLength.h b/include/comms/field/adapter/FixedLength.h index cbe1d87..a930d13 100644 --- a/include/comms/field/adapter/FixedLength.h +++ b/include/comms/field/adapter/FixedLength.h @@ -193,14 +193,14 @@ class FixedLength : public TBase template static constexpr BaseSerialisedType adjustFromSerialised(SerialisedType val, JustCastTag) { - return static_cast(val); + return castToBaseSerializedType(val, HasSignTag<>()); } template static BaseSerialisedType adjustFromSerialised(SerialisedType val, SignExtendTag) { auto valueTmp = static_cast(val) & UnsignedValueMask; - return static_cast(signExtUnsignedSerialised(valueTmp, HasSignTag<>())); + return castToBaseSerializedType(signExtUnsignedSerialised(valueTmp, HasSignTag<>()), HasSignTag<>()); } template @@ -222,6 +222,18 @@ class FixedLength : public TBase return static_cast(val); } + template + static constexpr BaseSerialisedType castToBaseSerializedType(SerialisedType val, UnsignedTag) + { + return static_cast(static_cast(val)); + } + + template + static constexpr BaseSerialisedType castToBaseSerializedType(SerialisedType val, SignedTag) + { + return static_cast(val); + } + static const std::size_t Length = TLen; static const std::size_t BitsInByte = std::numeric_limits::digits; static const std::size_t BitLength = Length * BitsInByte; diff --git a/test/Fields2.th b/test/Fields2.th index 2572fcc..58dc0aa 100644 --- a/test/Fields2.th +++ b/test/Fields2.th @@ -54,6 +54,7 @@ public: void test26(); void test27(); void test28(); + void test29(); private: template @@ -1882,6 +1883,30 @@ void FieldsTestSuite2::test28() } while (false); } +void FieldsTestSuite2::test29() +{ + using Field = + comms::field::IntValue< + BeFieldBase, + std::int16_t, + comms::option::def::FixedLength<1U, false>, + comms::option::def::NumValueSerOffset<128>, + comms::option::def::ValidNumValueRange<-128, 127> + >; + + do { + Field field; + field.value() = 10; + + static const char Buf[] = { + static_cast(0x8a), + }; + static const std::size_t BufSize = std::extent::value; + + writeReadField(field, &Buf[0], BufSize); + } while (false); +} + template void FieldsTestSuite2::writeField( const TField& field,