Skip to content

Commit 42ea9d6

Browse files
committed
Revert "Revert the update to catch itself and instead changed how catch was"
This reverts commit eeac2e3.
1 parent eeac2e3 commit 42ea9d6

File tree

9 files changed

+21
-59
lines changed

9 files changed

+21
-59
lines changed

libudpard/udpard.c

Lines changed: 8 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,6 @@ 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-
110102
static const uint16_t UDPARD_UDP_PORT = 9382U;
111103

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

465455
// Insert CRC
466456
size_t frame_offset = payload_size + sizeof(UdpardFrameHeader);
467457
TransferCRC crc = crcValue(crcAdd(CRC_INITIAL, payload_size, payload));
468458
uint8_t crc_as_byte[] = {(uint8_t)(crc & BYTE_MAX & 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)};
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)};
472462
for (unsigned int i = 0; i < sizeof(crc_as_byte); i++)
473463
{
474464
tqi->payload_buffer[frame_offset++] = crc_as_byte[i];
@@ -519,9 +509,9 @@ UDPARD_PRIVATE TxChain txGenerateMultiFrameChain(UdpardInstance* const in
519509
const uint8_t* payload_ptr = (const uint8_t*) payload;
520510
uint32_t frame_index = 0U;
521511
uint8_t crc_as_byte[] = {(uint8_t)(crc & BYTE_MAX & 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)};
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)};
525515
size_t last_crc_index = 0U;
526516
size_t inserted_crc_amount = 0;
527517
while (offset < payload_size_with_crc)
@@ -733,35 +723,6 @@ typedef struct
733723
uint32_t frame_index;
734724
} RxFrameModel;
735725

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-
765726
UDPARD_PRIVATE UdpardPortID getPortIdFromDataSpecifiers(UdpardUdpPortID data_specifier)
766727
{
767728
if ((uint16_t)(data_specifier >> UDPARD_SERVICE_NOT_MESSAGE_DATA_SPECIFIER_OFFSET) & 1U)

tests/test_private_cavl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
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"
89
#include <algorithm>
910
#include <array>
1011
#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 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");
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");
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.hpp"
7+
#include "catch/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.hpp"
7+
#include "catch/catch.hpp"
88

9-
#define UDPARD_SUBJECT_ID_PORT 16383U
10-
#define UDPARD_UDP_PORT 9382U
9+
constexpr uint16_t UDPARD_SUBJECT_ID_PORT = 16383U;
10+
constexpr uint16_t 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.hpp"
7+
#include "catch/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.hpp"
7+
#include "catch/catch.hpp"
88
#include <cstring>
99

10-
#define UDPARD_SUBJECT_ID_PORT 16383U
11-
#define UDPARD_UDP_PORT 9382U
10+
constexpr uint16_t UDPARD_SUBJECT_ID_PORT = 16383U;
11+
constexpr uint16_t 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.hpp"
7+
#include "catch/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.hpp"
6+
#include "catch/catch.hpp"
77

88
TEST_CASE("TestAllocator")
99
{

0 commit comments

Comments
 (0)