Skip to content

Commit 3c22ff3

Browse files
committed
Added defined constant values for Cyphal data specifier
1 parent 067d687 commit 3c22ff3

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

libudpard/udpard.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ IRNR - Is Request, Not Response
9595
#define UDPARD_SERVICE_NOT_MESSAGE_DATA_SPECIFIER_OFFSET 15U
9696
#define UDPARD_IRNR_DATA_SPECIFIER_OFFSET 14U
9797
#define UDPARD_SERVICE_ID_MASK 16383U /// 0x3FFF
98+
#define UPDARD_DATA_SPECIFIER_MESSAGE (0xFFFF >> 1) // SNM (0) + SubjectID
99+
#define UDPARD_DATA_SPECIFIER_SERVICE_RESPONSE (2U << UDPARD_IRNR_DATA_SPECIFIER_OFFSET) // Set SNM in Cyphal data specifier - SNM (1) + IRNR (0) + ServiceID
100+
#define UDPARD_DATA_SPECIFIER_SERVICE_REQUEST (3U << UDPARD_IRNR_DATA_SPECIFIER_OFFSET) // Set SNM and IRNR in Cyphal data specifier - SNM (1) + IRNR (1) + ServiceID
98101

99102
/// Ports align with subject and service ids
100103
/// Subjects use multicast and always use port 16383
@@ -335,13 +338,13 @@ UDPARD_PRIVATE void txMakeFrameHeader(UdpardFrameHeader* const header,
335338
header->destination_node_id = dst_node_id;
336339
if (transfer_kind == UdpardTransferKindMessage)
337340
{
338-
header->data_specifier = (uint16_t) (0xFFFF >> 1) & port_id; // SNM (0) + Subject ID
341+
header->data_specifier = (uint16_t) UPDARD_DATA_SPECIFIER_MESSAGE & port_id; // SNM (0) + Subject ID
339342
}
340343
else
341344
{
342345
header->data_specifier =
343-
(transfer_kind == UdpardTransferKindRequest) ? (3U << UDPARD_IRNR_DATA_SPECIFIER_OFFSET) | port_id
344-
: (2U << UDPARD_IRNR_DATA_SPECIFIER_OFFSET) | port_id; // SNM (1) + IRNR + ServiceID
346+
(transfer_kind == UdpardTransferKindRequest) ? UDPARD_DATA_SPECIFIER_SERVICE_REQUEST | port_id
347+
: UDPARD_DATA_SPECIFIER_SERVICE_RESPONSE | port_id; // SNM (1) + IRNR + ServiceID
345348
}
346349
}
347350

0 commit comments

Comments
 (0)