From 20b9c8006310c250e102ef5b5a267f9d7d0f9d43 Mon Sep 17 00:00:00 2001 From: Robert Brenick Date: Fri, 14 Jul 2023 13:20:34 +0200 Subject: [PATCH 1/9] Missing define.h in grem.c makes linking to le16toh fail This was not caught when when building on a Ubuntu machine but failed to build with an alpine Dockerfile. --- include/grem.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/grem.h b/include/grem.h index 0ba2508..3ebda7c 100644 --- a/include/grem.h +++ b/include/grem.h @@ -3,6 +3,7 @@ #include #include "iso22133.h" +#include "defines.h" #include "header.h" #include "footer.h" From b42b3d902d0829f1f7758590998d5ceec9ae1e93 Mon Sep 17 00:00:00 2001 From: Robert Brenick Date: Fri, 14 Jul 2023 14:51:15 +0200 Subject: [PATCH 2/9] Fix broken traj test --- tests/traj.cpp | 52 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/tests/traj.cpp b/tests/traj.cpp index af2bfa1..988c7ac 100644 --- a/tests/traj.cpp +++ b/tests/traj.cpp @@ -453,48 +453,57 @@ class EncodeTRAJFooter : public ::testing::Test } void SetUp() override { + auto trajectoryID = 0x123; + auto trajectoryVersion = TRAJECTORY_INFO_RELATIVE_TO_OBJECT; + auto trajectoryName = "some description"; + auto nameLength = strlen(trajectoryName)-1; + auto numberOfPointsInTraj = 3; memset(encodeBuffer, 0, sizeof(encodeBuffer)); - auto p = encodeBuffer; + auto points = encodeBuffer; + auto bufferLength = sizeof(encodeBuffer); + bool debug = false; + auto offset = encodeTRAJMessageHeader( - 0x123, + trajectoryID, TRAJECTORY_INFO_RELATIVE_TO_OBJECT, - "some description", - 17, - 3, - p, + trajectoryName, + nameLength, + numberOfPointsInTraj, + points, sizeof(encodeBuffer), false); ASSERT_GT(offset, 0); - p += offset; + points += offset; for (int i = 0; i < 3; i++) { struct timeval tv = {1,2}; CartesianPosition pos = {1,2,3,4,true,true,true,true,true}; SpeedType spd = {1,2,true,true}; AccelerationType acc = {1,2,true,true}; + float curvature = 12.34; offset = encodeTRAJMessagePoint( &tv, pos, spd, acc, - 12.34, - p, - sizeof(encodeBuffer) - (p-encodeBuffer), + curvature, + points, + sizeof(encodeBuffer) - (points-encodeBuffer), false); ASSERT_GT(offset, 0); - p += offset; + points += offset; } offset = encodeTRAJMessageFooter( - p, - sizeof(encodeBuffer) - (p - encodeBuffer), + points, + sizeof(encodeBuffer) - (points - encodeBuffer), false ); ASSERT_GT(offset, 0); - p += offset; - // Run this to view raw data for which to generate CRC - // for (int i = 0; i < p - encodeBuffer; ++i) { - // printf("%02x ",(uint8_t)encodeBuffer[i]); - // } - // printf("\n"); + points += offset; + printf("Raw data for CRC:\n"); + for (int i = 0; i < points - encodeBuffer - 2; ++i) { + printf("%02x ",(uint8_t)encodeBuffer[i]); + } + printf("\n"); } char encodeBuffer[1024]; @@ -511,7 +520,8 @@ TEST_F(EncodeTRAJFooter, EndOfTransmission) { } // https://crccalc.com/?crc=7f 7e ba 00 00 00 02 ff 00 00 00 00 00 00 00 00 01 00 01 01 02 00 23 01 04 01 01 00 01 02 01 40 00 73 6f 6d 65 20 64 65 73 63 72 69 70 74 69 6f 6e 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 1e 00 e8 03 00 00 e8 03 00 00 d0 07 00 00 b8 0b 00 00 86 59 64 00 c8 00 e8 03 d0 07 a4 70 45 41 01 00 1e 00 e8 03 00 00 e8 03 00 00 d0 07 00 00 b8 0b 00 00 86 59 64 00 c8 00 e8 03 d0 07 a4 70 45 41 01 00 1e 00 e8 03 00 00 e8 03 00 00 d0 07 00 00 b8 0b 00 00 86 59 64 00 c8 00 e8 03 d0 07 a4 70 45 41 53 00 01 00 04&method=crc16&datatype=hex&outtype=0 +// CRC-16/XMODEM TEST_F(EncodeTRAJFooter, Crc) { - EXPECT_EQ(crc[0], '\x34'); - EXPECT_EQ(crc[1], '\x21'); + EXPECT_EQ(crc[0], '\x55'); + EXPECT_EQ(crc[1], '\x52'); } From aaa7f67eadca3b3616d80cb359febe1848e01790 Mon Sep 17 00:00:00 2001 From: Robert Brenick Date: Fri, 14 Jul 2023 15:03:22 +0200 Subject: [PATCH 3/9] Remove print in traj test --- tests/traj.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/traj.cpp b/tests/traj.cpp index 988c7ac..5442ed1 100644 --- a/tests/traj.cpp +++ b/tests/traj.cpp @@ -499,11 +499,11 @@ class EncodeTRAJFooter : public ::testing::Test ); ASSERT_GT(offset, 0); points += offset; - printf("Raw data for CRC:\n"); - for (int i = 0; i < points - encodeBuffer - 2; ++i) { - printf("%02x ",(uint8_t)encodeBuffer[i]); - } - printf("\n"); + // printf("Raw data for CRC:\n"); + // for (int i = 0; i < points - encodeBuffer - 2; ++i) { + // printf("%02x ",(uint8_t)encodeBuffer[i]); + // } + // printf("\n"); } char encodeBuffer[1024]; From b2283ced07d79605d1afecf13cc77f8189a5d962 Mon Sep 17 00:00:00 2001 From: Robert Brenick Date: Fri, 14 Jul 2023 16:21:00 +0200 Subject: [PATCH 4/9] Fix none teardowned value in osem test --- tests/osem.cpp | 5 +++++ tests/traj.cpp | 7 +++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/osem.cpp b/tests/osem.cpp index 6b6da23..83eaae0 100644 --- a/tests/osem.cpp +++ b/tests/osem.cpp @@ -48,6 +48,11 @@ class EncodeOSEM : public ::testing::Test sizeof(encodeBuffer), false); ASSERT_GT(res, 0); } + void TearDown() override + { + setTransmitterID(0xFFFF); + } + ObjectSettingsType settings; char encodeBuffer[1024]; char* id = encodeBuffer + 18; // skip header diff --git a/tests/traj.cpp b/tests/traj.cpp index 5442ed1..4d2caf1 100644 --- a/tests/traj.cpp +++ b/tests/traj.cpp @@ -519,9 +519,8 @@ TEST_F(EncodeTRAJFooter, EndOfTransmission) { EXPECT_EQ(lineInfo[4], '\x04'); } -// https://crccalc.com/?crc=7f 7e ba 00 00 00 02 ff 00 00 00 00 00 00 00 00 01 00 01 01 02 00 23 01 04 01 01 00 01 02 01 40 00 73 6f 6d 65 20 64 65 73 63 72 69 70 74 69 6f 6e 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 1e 00 e8 03 00 00 e8 03 00 00 d0 07 00 00 b8 0b 00 00 86 59 64 00 c8 00 e8 03 d0 07 a4 70 45 41 01 00 1e 00 e8 03 00 00 e8 03 00 00 d0 07 00 00 b8 0b 00 00 86 59 64 00 c8 00 e8 03 d0 07 a4 70 45 41 01 00 1e 00 e8 03 00 00 e8 03 00 00 d0 07 00 00 b8 0b 00 00 86 59 64 00 c8 00 e8 03 d0 07 a4 70 45 41 53 00 01 00 04&method=crc16&datatype=hex&outtype=0 -// CRC-16/XMODEM +// https://crccalc.com/?crc=7f 7e ba 00 00 00 02 ff ff ff ff 00 00 00 00 00 01 00 01 01 02 00 23 01 04 01 01 00 01 02 01 40 00 73 6f 6d 65 20 64 65 73 63 72 69 70 74 69 6f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 1e 00 e8 03 00 00 e8 03 00 00 d0 07 00 00 b8 0b 00 00 86 59 64 00 c8 00 e8 03 d0 07 a4 70 45 41 01 00 1e 00 e8 03 00 00 e8 03 00 00 d0 07 00 00 b8 0b 00 00 86 59 64 00 c8 00 e8 03 d0 07 a4 70 45 41 01 00 1e 00 e8 03 00 00 e8 03 00 00 d0 07 00 00 b8 0b 00 00 86 59 64 00 c8 00 e8 03 d0 07 a4 70 45 41 53 00 01 00 04&method=crc16&datatype=hex&outtype=0// CRC-16/XMODEM TEST_F(EncodeTRAJFooter, Crc) { - EXPECT_EQ(crc[0], '\x55'); - EXPECT_EQ(crc[1], '\x52'); + EXPECT_EQ(crc[0], '\x3D'); + EXPECT_EQ(crc[1], '\xB5'); } From ae4a605d8ebd45f675b41a346f4a3493c6abf0d9 Mon Sep 17 00:00:00 2001 From: Robert Brenick Date: Mon, 23 Oct 2023 11:19:32 +0200 Subject: [PATCH 5/9] Add missing header offset to message length --- src/traj.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/traj.c b/src/traj.c index 24b8053..a70ebd1 100644 --- a/src/traj.c +++ b/src/traj.c @@ -219,7 +219,7 @@ ssize_t decodeTRAJMessageHeader( printf("\tTrajectory name: %s\n", TRAJHeaderData.trajectoryName); printf("\tTrajectory info: %u\n", TRAJHeaderData.trajectoryInfo); printf("\tTRAJ length: %ld bytes\n", TRAJHeaderData.header.messageLength - - sizeof(TRAJHeaderType) - sizeof(TRAJFooterType) + sizeof(FooterType)); + - sizeof(TRAJHeaderType) + sizeof(HeaderType) - sizeof(TRAJFooterType) + sizeof(FooterType)); } // Fill output struct with parsed data @@ -244,7 +244,7 @@ enum ISOMessageReturnValue convertTRAJHeaderToHostRepresentation(TRAJHeaderType* trajectoryHeaderData->trajectoryID = TRAJHeaderData->trajectoryID; memcpy(trajectoryHeaderData->trajectoryName, TRAJHeaderData->trajectoryName, sizeof(TRAJHeaderData->trajectoryName)); trajectoryHeaderData->trajectoryInfo = TRAJHeaderData->trajectoryInfo; - trajectoryHeaderData->trajectoryLength = trajectoryLength - sizeof(TRAJHeaderType) - sizeof(TRAJFooterType) + sizeof(FooterType); + trajectoryHeaderData->trajectoryLength = trajectoryLength - sizeof(TRAJHeaderType) + sizeof(HeaderType) - sizeof(TRAJFooterType) + sizeof(FooterType); trajectoryHeaderData->nWaypoints = trajectoryHeaderData->trajectoryLength/sizeof(TRAJPointType); return MESSAGE_OK; From b92f93e5fe93d51c3f5f1b99388f5ca0ec63269b Mon Sep 17 00:00:00 2001 From: Robert Brenick Date: Mon, 23 Oct 2023 11:19:53 +0200 Subject: [PATCH 6/9] Improve debug prints --- src/header.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/header.c b/src/header.c index 7b0f809..9a247c4 100644 --- a/src/header.c +++ b/src/header.c @@ -130,12 +130,12 @@ enum ISOMessageReturnValue decodeISOHeader( if (debug) { printf("syncWord = 0x%x\n", HeaderData->syncWord); - printf("messageLength = 0x%x\n", HeaderData->messageLength); - printf("ackReqProtVer = 0x%x\n", HeaderData->ackReqProtVer); - printf("transmitterID = 0x%x\n", HeaderData->transmitterID); - printf("receiverID = 0x%x\n", HeaderData->receiverID); - printf("messageCounter = 0x%x\n", HeaderData->messageCounter); - printf("messageID = 0x%x\n", HeaderData->messageID); + printf("messageLength = %d bytes, [0x%x]\n", HeaderData->messageLength, HeaderData->messageLength); + printf("ackReqProtVer = %d, [0x%x]\n", HeaderData->ackReqProtVer, HeaderData->ackReqProtVer); + printf("transmitterID = %d, [0x%x]\n", HeaderData->transmitterID, HeaderData->transmitterID); + printf("receiverID = %d, [0x%x]\n", HeaderData->receiverID, HeaderData->receiverID); + printf("messageCounter = %d, [0x%x]\n", HeaderData->messageCounter, HeaderData->messageCounter); + printf("messageID = %d, [0x%x]\n", HeaderData->messageID, HeaderData->messageID); } return retval; From 48357623915c457e32b3acd537bce69a75eb5219 Mon Sep 17 00:00:00 2001 From: Robert Brenick Date: Mon, 23 Oct 2023 11:21:25 +0200 Subject: [PATCH 7/9] Remove message length constants --- iso22133.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/iso22133.h b/iso22133.h index 081b3e4..e4720d8 100644 --- a/iso22133.h +++ b/iso22133.h @@ -63,12 +63,6 @@ typedef struct { } timeServer; } ObjectSettingsType; -/*! ISO message constants */ -enum ISOConstantsType { - ISO_TRAJ_HEADER_SIZE = 91, - ISO_TRAJ_WAYPOINT_SIZE = 70 -}; - typedef enum { TRAJECTORY_INFO_RELATIVE_TO_OBJECT = 1, TRAJECTORY_INFO_RELATIVE_TO_ORIGIN = 2, From 13afa57870bd6fee549376ed39f108bfa66b18bb Mon Sep 17 00:00:00 2001 From: Robert Brenick Date: Mon, 23 Oct 2023 13:40:06 +0200 Subject: [PATCH 8/9] Fix iso22133 test as welll --- tests/traj.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/traj.cpp b/tests/traj.cpp index 4d2caf1..d336942 100644 --- a/tests/traj.cpp +++ b/tests/traj.cpp @@ -82,10 +82,10 @@ class DecodeTRAJHeader : public ::testing::Test DecodeTRAJHeader() { decodeBuffer[0] = 0x7F; decodeBuffer[1] = 0x7E; // preamble - decodeBuffer[2] = 0x52; - decodeBuffer[3] = 0x00; + decodeBuffer[2] = 0x1E; + decodeBuffer[3] = 0x03; decodeBuffer[4] = 0x00; - decodeBuffer[5] = 0x00; // TODO Message length + decodeBuffer[5] = 0x00; // Message length 0x31E (sizeof(TRAJHeaderType) + sizeof(TRAJPointType) * 21 + sizeof(TRAJFooterType)) - (sizeof(TRAJHeaderType) + sizeof(HeaderType)) - (sizeof(TRAJFooterType) + sizeof(FooterType)); decodeBuffer[6] = 0x02; // Acknowledge protocol version decodeBuffer[7] = 0x34; decodeBuffer[8] = 0x12; @@ -145,7 +145,7 @@ class DecodeTRAJHeader : public ::testing::Test &header, decodeBuffer, sizeof(decodeBuffer), - false); + true); ASSERT_GT(res, 0); } @@ -171,6 +171,11 @@ TEST_F(DecodeTRAJHeader, Name) } } +TEST_F(DecodeTRAJHeader, nWaypoints) +{ + EXPECT_EQ(header.nWaypoints, 21); +} + class EncodeTRAJPoint : public ::testing::Test { protected: From a49f38fc4dc8ff5cb11e7721bd0ed920c43bd725 Mon Sep 17 00:00:00 2001 From: Robert Brenick Date: Mon, 23 Oct 2023 15:04:20 +0200 Subject: [PATCH 9/9] Fix failing TRAJ test due to faulty TearDown in OSEM --- tests/osem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/osem.cpp b/tests/osem.cpp index 83eaae0..3b5b22c 100644 --- a/tests/osem.cpp +++ b/tests/osem.cpp @@ -50,7 +50,7 @@ class EncodeOSEM : public ::testing::Test } void TearDown() override { - setTransmitterID(0xFFFF); + setTransmitterID(0xFFFFFFFF); } ObjectSettingsType settings;