Skip to content

Commit 5e6eb2d

Browse files
committed
Release v3.4.1
2 parents c9e7154 + 987e4f4 commit 5e6eb2d

File tree

12 files changed

+531
-64
lines changed

12 files changed

+531
-64
lines changed

.github/workflows/actions_build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ name: Github Actions Build
33
on: [push]
44

55
jobs:
6-
build_gcc_ubuntu_16_04:
7-
runs-on: ubuntu-16.04
6+
build_gcc_ubuntu_18_04:
7+
runs-on: ubuntu-18.04
88
strategy:
99
fail-fast: false
1010
matrix:

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ option (CC_BUILD_DEMO_PROTOCOL "Build demo protocol plugin." OFF)
1414
option (CC_INSTALL_DEMO_PROTOCOL "Install demo protocol plugin." ${CC_BUILD_DEMO_PROTOCOL})
1515
option (CC_WARN_AS_ERR "Treat warning as error" ON)
1616
option (CC_USE_CCACHE "Use ccache on UNIX systems if it's available" ON)
17-
option (CC_SKIP_CXX_STANDARD_FORCING "Use ccache on UNIX systems if it's available" ON)
17+
option (CC_SKIP_CXX_STANDARD_FORCING "Do NOT force C++ standard to C++11, use compiler's default one." ON)
1818
option (CC_STATIC_RUNTIME "Enable/Disable static runtime" OFF)
1919

2020
# Extra variables

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ or **cc_dump.exe**), which resides in
169169
**${CMAKE_ISNTALL_PREFIX}/bin** directory. If the execution fails due to missing **Qt5** dlls,
170170
either set your **%PATH%** variable accordingly or try to execute generated **.bat**
171171
files (**cc_view.bat** or **cc_dump.bat**) residing in the same directory. Another
172-
option is to build **deploy_qt** target to deploy Qt5 libraries into installation directory, whill will allow execution of any **.exe** file without and extra manupulations.
172+
option is to build **deploy_qt** target to deploy Qt5 libraries into installation directory, which will allow execution of any **.exe** file without any extra manipulations.
173173

174174
On Linux platforms use the appropriate shell script
175175
(**cc_view.sh** or **cc_dump.sh**), which also resides in

cmake/CC_External.cmake

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
# [REPO <repo>]
2525
# [CMAKE_ARGS <arg1> <arg2> ...]
2626
# [NO_DEFAULT_CMAKE_ARGS]
27+
# [NO_REPO]
2728
# )
2829
# - SRC_DIR - A directory where comms_champion sources will end up.
2930
# - BUILD_DIR - A build directory, defaults to ${PROJECT_BINARY_DIR}/comms_champion
@@ -41,6 +42,8 @@
4142
# * CMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}
4243
# The default values are passed before ones specified in CMAKE_ARGS, which can overwrite
4344
# some of the default values.
45+
# - NO_REPO - Don't checkout sources, SRC_DIR must contain checkout out sources, suitable
46+
# for this repo being a submodule.
4447
#
4548
# ******************************************************
4649
# - Build comms_champion as external project during normal build process.
@@ -68,7 +71,8 @@
6871
# - CMAKE_ARGS - Extra cmake arguments to be passed to the comms_champion project.
6972
# - QT_DIR - Path to external Qt5 libraries, will be passed to the comms_champion
7073
# build process using CC_QT_DIR variable.
71-
# - NO_REPO - Don't checkout sources, SRC_DIR must contain checkout out sources, suitable for this repo being a submodule.
74+
# - NO_REPO - Don't checkout sources, SRC_DIR must contain checkout out sources,
75+
# suitable for this repo being a submodule.
7276
# - NO_TOOLS - Will disable build of the CommsChampion Tools, will result in
7377
# having CC_BUILD_TOOLS_LIBRARY=OFF option being passed to the build process.
7478
# - NO_DEPLOY_QT - Don't generate "deploy_qt" build target when applicable.
@@ -155,7 +159,7 @@ endfunction ()
155159

156160
function (cc_build_during_config)
157161
set (_prefix CC_BUILD)
158-
set (_options NO_DEFAULT_CMAKE_ARGS)
162+
set (_options NO_DEFAULT_CMAKE_ARGS NO_REPO)
159163
set (_oneValueArgs SRC_DIR BUILD_DIR REPO TAG)
160164
set (_mutiValueArgs CMAKE_ARGS)
161165
cmake_parse_arguments(${_prefix} "${_options}" "${_oneValueArgs}" "${_mutiValueArgs}" ${ARGN})
@@ -176,7 +180,9 @@ function (cc_build_during_config)
176180
set (CC_BUILD_TAG ${CC_EXTERNAL_DEFAULT_TAG})
177181
endif ()
178182

179-
cc_pull_sources(SRC_DIR ${CC_BUILD_SRC_DIR} REPO ${CC_BUILD_REPO} TAG ${CC_BUILD_TAG})
183+
if (NOT CC_BUILD_NO_REPO)
184+
cc_pull_sources(SRC_DIR ${CC_BUILD_SRC_DIR} REPO ${CC_BUILD_REPO} TAG ${CC_BUILD_TAG})
185+
endif ()
180186

181187
execute_process (
182188
COMMAND ${CMAKE_COMMAND} -E make_directory "${CC_BUILD_BUILD_DIR}"

comms/doc/page_custom_checksum_layer.dox

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,10 @@
267267
/// function that is invoked to calculate serialization length of the field.
268268
/// @li @ref comms::protocol::ChecksumLayer::calculateChecksum() "calculateChecksum()" -
269269
/// Member function that is responsible to calculate a checksum on provided range.
270+
/// @li @ref comms::protocol::ChecksumLayer::getChecksumFromField() "getChecksumFromField()" -
271+
/// Retrieve value of the checksum from the field.
272+
/// @li @ref comms::protocol::ChecksumLayer::prepareFieldForWrite() "prepareFieldForWrite()" -
273+
/// Assign the calculated checksum value to the field's value.
270274
///
271275
/// The newly defined custom protocol stack layer can be used instead of
272276
/// @ref comms::protocol::ChecksumLayer when defining

comms/include/comms/protocol/ChecksumLayer.h

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "comms/protocol/details/ProtocolLayerExtendingClassHelper.h"
2121
#include "comms/util/type_traits.h"
2222
#include "comms/details/tag.h"
23+
#include "comms/cast.h"
2324

2425
COMMS_MSVC_WARNING_PUSH
2526
COMMS_MSVC_WARNING_DISABLE(4189) // Disable erroneous initialized but not referenced variable warning
@@ -42,8 +43,8 @@ namespace protocol
4243
/// ResultType operator()(TIter& iter, std::size_t len) const;
4344
/// @endcode
4445
/// It is up to the checksum calculator to choose the "ResultType" it
45-
/// returns. The falue is going to be casted to Field::ValueType before
46-
/// assigning it as a value of the check field being read and/or written.@n
46+
/// returns. The falue is going to be casted to @b Field::ValueType before
47+
/// assigning it as a value of the checksum field being read and/or written.@n
4748
/// Available checksum algorithms provided by the COMMS library reside in
4849
/// @ref comms::protocol::checksum namespace (`comms/protocol/checkum` folder).
4950
/// @tparam TNextLayer Next transport layer in protocol stack.
@@ -318,15 +319,39 @@ class ChecksumLayer : public
318319
static_cast<void>(msg);
319320
checksumValid = true;
320321
return TCalc()(iter, len);
321-
}
322+
}
322323

323-
private:
324-
static_assert(comms::field::isIntValue<Field>(),
325-
"The checksum field is expected to be of IntValue type");
324+
/// @brief Retrieve checksum value from the field.
325+
/// @details May be overridden by the extending class.
326+
/// Default implementation is
327+
/// @code
328+
/// return field.value();
329+
/// @endcode
330+
/// @param[in] field Field for this layer.
331+
static auto getChecksumFromField(const Field& field) -> typename Field::ValueType
332+
{
333+
return field.value();
334+
}
326335

327-
static_assert(Field::minLength() == Field::maxLength(),
328-
"The checksum field is expected to be of fixed length");
336+
/// @brief Prepare field for writing
337+
/// @details Must assign provided checksum value.
338+
/// May be overridden by the extending class if some complex functionality is required.
339+
/// The default implementation is:
340+
/// @code
341+
/// comms::cast_assign(field.value()) = checksum;
342+
/// @endcode
343+
/// @param[in] checksum Checksum value to assign
344+
/// @param[in] msg Pointer to message object being written, may be nullptr.
345+
/// @param[out] field Field, value of which needs to be populated
346+
/// @note May be non-static in the extending class. In case of non-static must be const.
347+
template <typename TChecksum, typename TMsg>
348+
static void prepareFieldForWrite(TChecksum checksum, const TMsg* msg, Field& field)
349+
{
350+
static_cast<void>(msg);
351+
comms::cast_assign(field.value()) = checksum;
352+
}
329353

354+
private:
330355
template <typename... TParams>
331356
using VerifyBeforeReadTag = comms::details::tag::Tag1<>;
332357

@@ -369,7 +394,7 @@ class ChecksumLayer : public
369394
return comms::ErrorStatus::ProtocolError;
370395
}
371396

372-
auto expectedValue = field.value();
397+
auto expectedValue = thisObj.getChecksumFromField(field);
373398

374399
if (expectedValue != static_cast<decltype(expectedValue)>(checksum)) {
375400
BaseImpl::resetMsg(msg);
@@ -428,7 +453,7 @@ class ChecksumLayer : public
428453
return comms::ErrorStatus::ProtocolError;
429454
}
430455

431-
auto expectedValue = field.value();
456+
auto expectedValue = thisObj.getChecksumFromField(field);
432457

433458
if (expectedValue != static_cast<decltype(expectedValue)>(checksum)) {
434459
BaseImpl::resetMsg(msg);
@@ -499,6 +524,7 @@ class ChecksumLayer : public
499524
auto& thisObj = BaseImpl::thisLayer();
500525

501526
if (es == comms::ErrorStatus::UpdateRequired) {
527+
thisObj.prepareFieldForWrite(0, &msg, field);
502528
auto esTmp = thisObj.writeField(&msg, field, iter, remSize);
503529
if (esTmp != comms::ErrorStatus::Success) {
504530
return esTmp;
@@ -519,8 +545,7 @@ class ChecksumLayer : public
519545
return comms::ErrorStatus::ProtocolError;
520546
}
521547

522-
using FieldValueType = typename Field::ValueType;
523-
field.value() = static_cast<FieldValueType>(checksum);
548+
thisObj.prepareFieldForWrite(checksum, &msg, field);
524549
return thisObj.writeField(&msg, field, iter, remSize);
525550
}
526551

@@ -596,8 +621,7 @@ class ChecksumLayer : public
596621
return comms::ErrorStatus::ProtocolError;
597622
}
598623

599-
using FieldValueType = typename Field::ValueType;
600-
field.value() = static_cast<FieldValueType>(checksum);
624+
thisObj.prepareFieldForWrite(checksum, msgPtr, field);
601625
return thisObj.writeField(msgPtr, field, to, remSize);
602626
}
603627
};

comms/include/comms/protocol/ChecksumPrefixLayer.h

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@ class ChecksumPrefixLayer : public
225225
using IterType = typename std::decay<decltype(iter)>::type;
226226
using Tag = typename std::iterator_traits<IterType>::iterator_category;
227227

228-
field.value() = 0;
229228
return writeInternal(field, msg, iter, size, std::forward<TNextLayerWriter>(nextLayerWriter), Tag());
230229
}
231230

@@ -347,12 +346,37 @@ class ChecksumPrefixLayer : public
347346
return TCalc()(iter, len);
348347
}
349348

350-
private:
351-
static_assert(comms::field::isIntValue<Field>(),
352-
"The checksum field is expected to be of IntValue type");
349+
/// @brief Retrieve checksum value from the field.
350+
/// @details May be overridden by the extending class.
351+
/// Default implementation is
352+
/// @code
353+
/// return field.value();
354+
/// @endcode
355+
/// @param[in] field Field for this layer.
356+
static auto getChecksumFromField(const Field& field) -> typename Field::ValueType
357+
{
358+
return field.value();
359+
}
360+
361+
/// @brief Prepare field for writing
362+
/// @details Must assign provided checksum value.
363+
/// May be overridden by the extending class if some complex functionality is required.
364+
/// The default implementation is:
365+
/// @code
366+
/// comms::cast_assign(field.value()) = checksum;
367+
/// @endcode
368+
/// @param[in] checksum Checksum value to assign
369+
/// @param[in] msg Pointer to message object being written, may be nullptr.
370+
/// @param[out] field Field, value of which needs to be populated
371+
/// @note May be non-static in the extending class. In case of non-static, must be const
372+
template <typename TChecksum, typename TMsg>
373+
static void prepareFieldForWrite(TChecksum checksum, const TMsg* msg, Field& field)
374+
{
375+
static_cast<void>(msg);
376+
comms::cast_assign(field.value()) = checksum;
377+
}
353378

354-
static_assert(Field::minLength() == Field::maxLength(),
355-
"The checksum field is expected to be of fixed length");
379+
private:
356380

357381
template <typename... TParams>
358382
using VerifyBeforeReadTag = comms::details::tag::Tag1<>;
@@ -385,8 +409,7 @@ class ChecksumPrefixLayer : public
385409
return comms::ErrorStatus::ProtocolError;
386410
}
387411

388-
auto expectedValue = field.value();
389-
412+
auto expectedValue = thisObj.getChecksumFromField(field);
390413
if (expectedValue != static_cast<decltype(expectedValue)>(checksum)) {
391414
BaseImpl::resetMsg(msg);
392415
return ErrorStatus::ProtocolError;
@@ -427,8 +450,7 @@ class ChecksumPrefixLayer : public
427450
return comms::ErrorStatus::ProtocolError;
428451
}
429452

430-
auto expectedValue = field.value();
431-
453+
auto expectedValue = thisObj.getChecksumFromField(field);
432454
if (expectedValue != static_cast<decltype(expectedValue)>(checksum)) {
433455
BaseImpl::resetMsg(msg);
434456
return ErrorStatus::ProtocolError;
@@ -487,6 +509,7 @@ class ChecksumPrefixLayer : public
487509
{
488510
auto& thisObj = BaseImpl::thisLayer();
489511
auto checksumIter = iter;
512+
thisObj.prepareFieldForWrite(0U, &msg, field);
490513
auto es = thisObj.writeField(&msg, field, iter, size);
491514
if (es != comms::ErrorStatus::Success) {
492515
return es;
@@ -504,7 +527,6 @@ class ChecksumPrefixLayer : public
504527
COMMS_ASSERT(fromIter <= iter);
505528
auto len = static_cast<std::size_t>(std::distance(fromIter, iter));
506529

507-
using FieldValueType = typename Field::ValueType;
508530
bool checksumValid = false;
509531
auto checksum =
510532
thisObj.calculateChecksum(
@@ -517,7 +539,7 @@ class ChecksumPrefixLayer : public
517539
return comms::ErrorStatus::ProtocolError;
518540
}
519541

520-
field.value() = static_cast<FieldValueType>(checksum);
542+
thisObj.prepareFieldForWrite(checksum, &msg, field);
521543
auto checksumEs = thisObj.writeField(&msg, field, checksumIter, checksumLen);
522544
static_cast<void>(checksumEs);
523545
COMMS_ASSERT(checksumEs == comms::ErrorStatus::Success);
@@ -533,6 +555,7 @@ class ChecksumPrefixLayer : public
533555
TWriter&& nextLayerWriter) const
534556
{
535557
auto& thisObj = BaseImpl::thisLayer();
558+
thisObj.prepareFieldForWrite(0U, &msg, field);
536559
auto es = thisObj.writeField(&msg, field, iter, size);
537560
if (es != comms::ErrorStatus::Success) {
538561
return es;
@@ -602,9 +625,8 @@ class ChecksumPrefixLayer : public
602625
return comms::ErrorStatus::ProtocolError;
603626
}
604627

605-
using FieldValueType = typename Field::ValueType;
606-
field.value() = static_cast<FieldValueType>(checksum);
607-
return field.write(checksumIter, fieldLen);
628+
thisObj.prepareFieldForWrite(checksum, msgPtr, field);
629+
return thisObj.doWriteField(msgPtr, field, checksumIter, fieldLen);
608630
}
609631
};
610632

comms/include/comms/protocol/MsgSizeLayer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ class MsgSizeLayer : public
316316
/// @details Must assign provided size (length) value.
317317
/// May be overridden by the extending class if some complex functionality is required.
318318
/// @param[in] size Size value to assign
319-
/// @param[in] msg Pointer to message object being written, maybe nullptr (in case invoked
319+
/// @param[in] msg Pointer to message object being written, may be nullptr (in case invoked
320320
/// from @ref comms::protocol::MsgSizeLayer::doUpdate "doUpdate()")
321321
/// @param[out] field Field, value of which needs to be populated
322322
/// @note May be non-static in the extending class

comms/include/comms/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#define COMMS_MINOR_VERSION 4U
1818

1919
/// @brief Patch level of the library
20-
#define COMMS_PATCH_VERSION 0U
20+
#define COMMS_PATCH_VERSION 1U
2121

2222
/// @brief Macro to create numeric version as single unsigned number
2323
#define COMMS_MAKE_VERSION(major_, minor_, patch_) \

comms/test/ChecksumPrefixLayer.th

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,12 @@ void ChecksumPrefixLayerTestSuite::test7()
458458
void ChecksumPrefixLayerTestSuite::test8()
459459
{
460460
static const char Buf[] = {
461-
static_cast<char>(0xab), static_cast<char>(0xcd), 0x06, 0x0, 0x3, MessageType1, 0x01, 0x02, static_cast<char>(0x3f)
461+
static_cast<char>(0xab), static_cast<char>(0xcd), // sync
462+
0x06, // checksum
463+
0x0, 0x3, // size
464+
MessageType1, // id
465+
0x01, 0x02, //data
466+
static_cast<char>(0x3f) // garbage
462467
};
463468

464469
static const std::size_t BufSize = std::extent<decltype(Buf)>::value;

0 commit comments

Comments
 (0)