Skip to content

Commit 665113c

Browse files
fixes
1 parent 38a962c commit 665113c

12 files changed

+1448
-7065
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ standards-compliant C99 compiler is available.
6868

6969
### v3.0 -- WORK IN PROGRESS
7070

71-
The library has been redesigned from scratch to support Cyphal v1.1, named topics, and reliable transfers.
71+
The library has been redesigned from scratch to support Cyphal v1.1 and named topics.
7272
No porting guide is provided since the changes are too significant;
7373
please refer to the new API docs in `libudpard/udpard.h`.
7474

libudpard/udpard.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1672,7 +1672,10 @@ static void rx_session_update(rx_session_t* const self,
16721672
UDPARD_ASSERT(upd_res == rx_slot_incomplete);
16731673
}
16741674
}
1675-
} // Here we used to have ACK retransmission, which has been removed -- no more reliable transfers.
1675+
} else {
1676+
// The transfer has been seen before, so just release this duplicate payload.
1677+
mem_free_payload(payload_deleter, frame->base.origin);
1678+
}
16761679
}
16771680

16781681
/// The stateful strategy maintains a dedicated session per remote node, indexed in a fast AVL tree.

tests/src/helpers.h

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,111 @@ static inline udpard_bytes_scattered_t make_scattered(const void* const data, co
6464
return out;
6565
}
6666

67-
// Wraps an application pointer for user context plumbing.
67+
// Legacy compatibility user context (removed from public API).
68+
typedef union
69+
{
70+
void* ptr[2];
71+
unsigned char bytes[sizeof(void*) * 2];
72+
} udpard_user_context_t;
73+
#ifdef __cplusplus
74+
#define UDPARD_USER_CONTEXT_NULL \
75+
udpard_user_context_t {}
76+
#else
77+
#define UDPARD_USER_CONTEXT_NULL ((udpard_user_context_t){ .ptr = { NULL } })
78+
#endif
79+
80+
// Legacy compatibility feedback payload (reliable TX removed from public API).
81+
typedef struct
82+
{
83+
udpard_user_context_t user;
84+
uint16_t acknowledgements;
85+
} udpard_tx_feedback_t;
86+
87+
// Wraps an application pointer for legacy user context plumbing.
6888
static inline udpard_user_context_t make_user_context(void* const obj)
6989
{
7090
udpard_user_context_t out = UDPARD_USER_CONTEXT_NULL;
7191
out.ptr[0] = obj;
7292
return out;
7393
}
7494

95+
// Calls the current public TX push API directly.
96+
static inline bool udpard_tx_push_native(udpard_tx_t* const self,
97+
const udpard_us_t now,
98+
const udpard_us_t deadline,
99+
const uint16_t iface_bitmap,
100+
const udpard_prio_t priority,
101+
const uint64_t transfer_id,
102+
const udpard_udpip_ep_t endpoint,
103+
const udpard_bytes_scattered_t payload,
104+
void* const user)
105+
{
106+
return udpard_tx_push(self, now, deadline, iface_bitmap, priority, transfer_id, endpoint, payload, user);
107+
}
108+
109+
// Calls the current public TX P2P push API directly.
110+
static inline bool udpard_tx_push_p2p_native(udpard_tx_t* const self,
111+
const udpard_us_t now,
112+
const udpard_us_t deadline,
113+
const udpard_prio_t priority,
114+
const udpard_udpip_ep_t endpoints[UDPARD_IFACE_COUNT_MAX],
115+
const udpard_bytes_scattered_t payload,
116+
void* const user)
117+
{
118+
return udpard_tx_push_p2p(self, now, deadline, priority, endpoints, payload, user);
119+
}
120+
121+
// Calls the current public RX constructor directly.
122+
static inline void udpard_rx_new_native(udpard_rx_t* const self) { udpard_rx_new(self); }
123+
124+
// Maps legacy subject push API to the new endpoint-based API.
125+
static inline bool udpard_tx_push_compat(udpard_tx_t* const self,
126+
const udpard_us_t now,
127+
const udpard_us_t deadline,
128+
const uint16_t iface_bitmap,
129+
const udpard_prio_t priority,
130+
const uint64_t transfer_id,
131+
const udpard_bytes_scattered_t payload,
132+
void (*const feedback)(udpard_tx_t*, udpard_tx_feedback_t),
133+
const udpard_user_context_t user)
134+
{
135+
(void)feedback;
136+
return udpard_tx_push_native(
137+
self, now, deadline, iface_bitmap, priority, transfer_id, udpard_make_subject_endpoint(0U), payload, user.ptr[0]);
138+
}
139+
140+
// Maps legacy P2P push API to the new endpoint-array API.
141+
static inline bool udpard_tx_push_p2p_compat(udpard_tx_t* const self,
142+
const udpard_us_t now,
143+
const udpard_us_t deadline,
144+
const udpard_prio_t priority,
145+
const udpard_remote_t remote,
146+
const udpard_bytes_scattered_t payload,
147+
void (*const feedback)(udpard_tx_t*, udpard_tx_feedback_t),
148+
const udpard_user_context_t user,
149+
uint64_t* const out_transfer_id)
150+
{
151+
(void)feedback;
152+
const uint64_t tid = (self != NULL) ? self->p2p_transfer_id : 0U;
153+
const bool ok = udpard_tx_push_p2p_native(self, now, deadline, priority, remote.endpoints, payload, user.ptr[0]);
154+
if (ok && (out_transfer_id != NULL)) {
155+
*out_transfer_id = tid;
156+
}
157+
return ok;
158+
}
159+
160+
// Maps legacy RX constructor API to the new standalone constructor.
161+
static inline void udpard_rx_new_compat(udpard_rx_t* const self, udpard_tx_t* const tx)
162+
{
163+
(void)tx;
164+
udpard_rx_new_native(self);
165+
}
166+
167+
// Remap legacy symbol names used by old tests.
168+
#define udpard_tx_push udpard_tx_push_compat
169+
#define udpard_tx_push_p2p udpard_tx_push_p2p_compat
170+
#define udpard_rx_new udpard_rx_new_compat
171+
75172
/// The instrumented allocator tracks memory consumption, checks for heap corruption, and can be configured to fail
76173
/// allocations above a certain threshold.
77174
#define INSTRUMENTED_ALLOCATOR_CANARY_SIZE 1024U

0 commit comments

Comments
 (0)