Skip to content

Commit eeac2e3

Browse files
committed
Revert the update to catch itself and instead changed how catch was
accessed by test files.
1 parent 3fddf42 commit eeac2e3

File tree

9 files changed

+59
-21
lines changed

9 files changed

+59
-21
lines changed

libudpard/udpard.c

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ static const uint16_t UPDARD_DATA_SPECIFIER_MESSAGE = 0x7FFFU; // SNM (0) + Subj
9999
static const uint16_t UDPARD_DATA_SPECIFIER_SERVICE_RESPONSE = 0x8000; // (2U << UDPARD_IRNR_DATA_SPECIFIER_OFFSET) // Set SNM in Cyphal data specifier - SNM (1) + IRNR (0) + ServiceID
100100
static const uint16_t UDPARD_DATA_SPECIFIER_SERVICE_REQUEST = 0xC000; // (3U << UDPARD_IRNR_DATA_SPECIFIER_OFFSET) // Set SNM and IRNR in Cyphal data specifier - SNM (1) + IRNR (1) + ServiceID
101101

102+
/// Ports align with subject and service ids
103+
/// Subjects use multicast and always use port 16383
104+
/// Services use unicast and start with port 16384
105+
/// Unique service id request / response are identified by initial port + (service * 2) (+1 for response)
106+
/// A service response will always be > 16384 and will always be odd (port > initial && port % 2 == 1)
107+
static const uint16_t UDPARD_SUBJECT_ID_PORT = 16383U;
108+
static const uint16_t UDPARD_SERVICE_ID_INITIAL_PORT = 16384U;
109+
102110
static const uint16_t UDPARD_UDP_PORT = 9382U;
103111

104112
/// Used for inserting new items into AVL trees.
@@ -350,7 +358,7 @@ UDPARD_PRIVATE void txMakeFrameHeader(UdpardFrameHeader* const header,
350358
header->cyphal_header_checksum = cyphalHeaderCrcAdd(CYPHAL_HEADER_CRC_INITIAL, cyphal_header_size_without_crc, header);
351359
if (transfer_kind == UdpardTransferKindMessage)
352360
{
353-
header->data_specifier = (uint16_t)(port_id & UDPARD_SUBJECT_ID_MASK) & UPDARD_DATA_SPECIFIER_MESSAGE; // SNM (0) + Subject ID
361+
header->data_specifier = port_id & UDPARD_SUBJECT_ID_MASK & UPDARD_DATA_SPECIFIER_MESSAGE; // SNM (0) + Subject ID
354362
}
355363
else
356364
{
@@ -450,15 +458,17 @@ UDPARD_PRIVATE int32_t txPushSingleFrame(UdpardTxQueue* const que
450458
txMakeFrameHeader(&tqi->base.frame.udp_cyphal_header, src_node_id, dst_node_id, port_id, transfer_kind, priority, transfer_id, true, 1);
451459
// Clang-Tidy raises an error recommending the use of memcpy_s() instead.
452460
// We ignore it because the safe functions are poorly supported; reliance on them may limit the portability.
453-
(void) memcpy(&tqi->payload_buffer[0], &tqi->base.frame.udp_cyphal_header, sizeof(UdpardFrameHeader)); // NOLINT
461+
(void) memcpy(&tqi->payload_buffer[0],
462+
&tqi->base.frame.udp_cyphal_header,
463+
sizeof(UdpardFrameHeader)); // NOLINT
454464

455465
// Insert CRC
456466
size_t frame_offset = payload_size + sizeof(UdpardFrameHeader);
457467
TransferCRC crc = crcValue(crcAdd(CRC_INITIAL, payload_size, payload));
458468
uint8_t crc_as_byte[] = {(uint8_t)(crc & BYTE_MAX & CRC_BYTE_MASK),
459-
(uint8_t)(crc >> (BITS_PER_BYTE * 1U) & CRC_BYTE_MASK),
460-
(uint8_t)(crc >> (BITS_PER_BYTE * 2U) & CRC_BYTE_MASK),
461-
(uint8_t)(crc >> (BITS_PER_BYTE * 3U) & CRC_BYTE_MASK)};
469+
(uint8_t)(crc >> (BITS_PER_BYTE * 1) & CRC_BYTE_MASK),
470+
(uint8_t)(crc >> (BITS_PER_BYTE * 2) & CRC_BYTE_MASK),
471+
(uint8_t)(crc >> (BITS_PER_BYTE * 3) & CRC_BYTE_MASK)};
462472
for (unsigned int i = 0; i < sizeof(crc_as_byte); i++)
463473
{
464474
tqi->payload_buffer[frame_offset++] = crc_as_byte[i];
@@ -509,9 +519,9 @@ UDPARD_PRIVATE TxChain txGenerateMultiFrameChain(UdpardInstance* const in
509519
const uint8_t* payload_ptr = (const uint8_t*) payload;
510520
uint32_t frame_index = 0U;
511521
uint8_t crc_as_byte[] = {(uint8_t)(crc & BYTE_MAX & CRC_BYTE_MASK),
512-
(uint8_t)(crc >> (BITS_PER_BYTE * 1U) & CRC_BYTE_MASK),
513-
(uint8_t)(crc >> (BITS_PER_BYTE * 2U) & CRC_BYTE_MASK),
514-
(uint8_t)(crc >> (BITS_PER_BYTE * 3U) & CRC_BYTE_MASK)};
522+
(uint8_t)(crc >> (BITS_PER_BYTE * 1) & CRC_BYTE_MASK),
523+
(uint8_t)(crc >> (BITS_PER_BYTE * 2) & CRC_BYTE_MASK),
524+
(uint8_t)(crc >> (BITS_PER_BYTE * 3) & CRC_BYTE_MASK)};
515525
size_t last_crc_index = 0U;
516526
size_t inserted_crc_amount = 0;
517527
while (offset < payload_size_with_crc)
@@ -723,6 +733,35 @@ typedef struct
723733
uint32_t frame_index;
724734
} RxFrameModel;
725735

736+
UDPARD_PRIVATE UdpardNodeID getNodeIdFromRouteSpecifier(UdpardIPv4Addr src_ip_addr)
737+
{
738+
UdpardNodeID out = (UdpardNodeID) (src_ip_addr & UDPARD_NODE_ID_MASK);
739+
return out;
740+
}
741+
742+
UDPARD_PRIVATE UdpardNodeID getNodeIdFromRouteAndDataSpecifiers(UdpardIPv4Addr route_specifier,
743+
UdpardUdpPortID data_specifier)
744+
{
745+
UdpardNodeID out = UDPARD_NODE_ID_UNSET;
746+
if (data_specifier > UDPARD_SUBJECT_ID_PORT)
747+
{
748+
out = getNodeIdFromRouteSpecifier(route_specifier);
749+
}
750+
return out;
751+
}
752+
753+
UDPARD_PRIVATE UdpardPortID getPortIdFromRouteAndDataSpecifiers(UdpardIPv4Addr route_specifier,
754+
UdpardUdpPortID data_specifier)
755+
{
756+
UDPARD_ASSERT(data_specifier >= UDPARD_SUBJECT_ID_PORT);
757+
if (data_specifier == UDPARD_SUBJECT_ID_PORT)
758+
{
759+
return (UdpardPortID) (route_specifier & UDPARD_SUBJECT_ID_MASK);
760+
}
761+
return (data_specifier % 2 == 1) ? (UdpardPortID) ((data_specifier - UDPARD_SERVICE_ID_INITIAL_PORT - 1) / 2)
762+
: (UdpardPortID) ((data_specifier - UDPARD_SERVICE_ID_INITIAL_PORT) / 2);
763+
}
764+
726765
UDPARD_PRIVATE UdpardPortID getPortIdFromDataSpecifiers(UdpardUdpPortID data_specifier)
727766
{
728767
if ((uint16_t)(data_specifier >> UDPARD_SERVICE_NOT_MESSAGE_DATA_SPECIFIER_OFFSET) & 1U)

tests/test_private_cavl.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
// These tests have been adapted from the Cavl test suite that you can find at https://github.com/pavel-kirienko/cavl
44

55
//#include <cavl.h>
6-
//#include "catch.hpp"
6+
#include "catch.hpp"
77
#include "../libudpard/cavl.h"
8-
#include "catch/catch.hpp"
98
#include <algorithm>
109
#include <array>
1110
#include <cstdint>

tests/test_private_crc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ TEST_CASE("CyphalHeaderCRC")
3131
// Standard use case. Header size = 24; CRC is calculated from the first 22 bytes.
3232
// The last two bytes (CRC) are ignored in the calculation.
3333
std::uint16_t crc = 0xFFFFU;
34-
const auto* header = reinterpret_cast<const uint8_t*>("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x20\x21\x22\x23\x24");
34+
const uint8_t* header = reinterpret_cast<const uint8_t*>("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x20\x21\x22\x23\x24");
3535
crc = cyphalHeaderCrcAdd(crc, 22, header);
3636
REQUIRE(0xB731 == crc);
3737

tests/test_private_rx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#include "exposed.hpp"
66
#include "helpers.hpp"
7-
#include "catch/catch.hpp"
7+
#include "catch.hpp"
88
#include <cstring>
99

1010
TEST_CASE("rxTryParseFrame")

tests/test_private_tx.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
#include "exposed.hpp"
66
#include "helpers.hpp"
7-
#include "catch/catch.hpp"
7+
#include "catch.hpp"
88

9-
constexpr uint16_t UDPARD_SUBJECT_ID_PORT = 16383U;
10-
constexpr uint16_t UDPARD_UDP_PORT = 9382U;
9+
#define UDPARD_SUBJECT_ID_PORT 16383U
10+
#define UDPARD_UDP_PORT 9382U
1111

1212
TEST_CASE("SessionSpecifier")
1313
{

tests/test_public_roundtrip.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#include "helpers.hpp"
66
#include "exposed.hpp"
7-
#include "catch/catch.hpp"
7+
#include "catch.hpp"
88
#include <array>
99
#include <atomic>
1010
#include <chrono>

tests/test_public_rx.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
#include "exposed.hpp"
66
#include "helpers.hpp"
7-
#include "catch/catch.hpp"
7+
#include "catch.hpp"
88
#include <cstring>
99

10-
constexpr uint16_t UDPARD_SUBJECT_ID_PORT = 16383U;
11-
constexpr uint16_t UDPARD_UDP_PORT = 9382U;
10+
#define UDPARD_SUBJECT_ID_PORT 16383U
11+
#define UDPARD_UDP_PORT 9382U
1212

1313
// clang-tidy mistakenly suggests to avoid C arrays here, which is clearly an error
1414
template <typename P, std::size_t N>

tests/test_public_tx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#include "exposed.hpp"
66
#include "helpers.hpp"
7-
#include "catch/catch.hpp"
7+
#include "catch.hpp"
88
#include <cstring>
99

1010
TEST_CASE("TxBasic0")

tests/test_self.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include "exposed.hpp"
55
#include "helpers.hpp"
6-
#include "catch/catch.hpp"
6+
#include "catch.hpp"
77

88
TEST_CASE("TestAllocator")
99
{

0 commit comments

Comments
 (0)