Illustrated C/C++ source sheets, symbol index, API relationship graph, compiler console and debug trace

LIVE AI / FLEXIBLE SENSING / FLIGHT CONTEXT

Sensoraia API

Live AI and sensing, connected to the flight.
See, listen, inspect and return supported results while airborne.

Loading...
Searching...
No Matches
serial_tx.h
Go to the documentation of this file.
1/*
2 * Copyright 2026 OpenUAS
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef USHER_SERIAL_TX_H
19#define USHER_SERIAL_TX_H
20
21/**
22 * @file serial_tx.h
23 * @brief Thread-safe, non-blocking framed UART transmission for USHER.
24 * @details Worker threads may finish camera jobs concurrently. This API serializes
25 * complete USHER frames through a bounded ring buffer so a slow UART cannot intermix
26 * bytes from independent messages or block a capture worker.
27 */
28
29#include <stdbool.h>
30#include <stddef.h>
31#include <stdint.h>
32
33/** @brief Attach an already-open non-blocking UART descriptor.
34 * @param descriptor Descriptor configured with @c O_NONBLOCK.
35 * @return 0 on success, or -1 with errno describing an invalid/busy descriptor. */
37
38/** @brief Discard pending output and detach the UART during shutdown/restart. */
39void serial_tx_stop(void);
40
41/** @brief Queue and opportunistically flush one complete USHER frame.
42 * @param message Protocol message ID.
43 * @param payload Payload bytes, or NULL when @p length is zero.
44 * @param length Payload size, limited by the one-byte protocol length field.
45 * @return 0 if queued/flushed, or -1 when the buffer or transport cannot accept it. */
46int serial_tx_send(uint8_t message, const uint8_t *payload, size_t length);
47
48/** @brief Send only when no earlier frame is queued, for low-priority probes.
49 * @details Avoids delaying flight-critical status traffic with a clock probe.
50 * @return 0 on acceptance, or -1 with EAGAIN when output is busy. */
51int serial_tx_send_if_idle(uint8_t message, const uint8_t *payload, size_t length);
52
53/** @brief Continue writing queued bytes after POLLOUT reports readiness.
54 * @return 0 when output remains usable, or -1 for a terminal transport failure. */
55int serial_tx_flush(void);
56
57/** @brief Report queued data or a latched output error needing event-loop handling.
58 * @return True while the event loop should request POLLOUT and call serial_tx_flush(). */
59bool serial_tx_pending(void);
60
61#endif
int descriptor
Definition chdk_pipe.c:142
int serial_tx_start(int descriptor)
Attach an already-open non-blocking UART descriptor.
Definition serial_tx.c:71
int serial_tx_send(uint8_t message, const uint8_t *payload, size_t length)
Queue and opportunistically flush one complete USHER frame.
Definition serial_tx.c:156
void serial_tx_stop(void)
Discard pending output and detach the UART during shutdown/restart.
Definition serial_tx.c:92
int serial_tx_flush(void)
Continue writing queued bytes after POLLOUT reports readiness.
Definition serial_tx.c:166
int serial_tx_send_if_idle(uint8_t message, const uint8_t *payload, size_t length)
Send only when no earlier frame is queued, for low-priority probes.
Definition serial_tx.c:161
bool serial_tx_pending(void)
Report queued data or a latched output error needing event-loop handling.
Definition serial_tx.c:174