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.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/**
19 * @file serial.h
20 * @brief UART descriptor setup and byte-oriented compatibility helpers.
21 * @details New USHER code should use serial_tx.h for output because it preserves
22 * frame boundaries under concurrent worker activity. These helpers remain for platform
23 * compatibility with the historic transport interface.
24 */
25
26#include <stdbool.h>
27#include <unistd.h>
28
29extern int fd;
30
31/**
32 * @brief Configure the shared non-blocking USHER UART descriptor.
33 * @param port_name UART device path.
34 * @return 0 on success or a negative setup error.
35 * @details The descriptor is set to raw 115200-bit/s 8-bit mode so line discipline cannot
36 * translate binary USHER framing bytes. This module owns descriptor setup only; concurrent
37 * transmission must use @c serial_tx.h.
38 */
39int serial_init(const char *port_name);
40
41/**
42 * @brief Preserve the legacy "character available" transport API contract.
43 * @return Always false because USHER receives through the parser's nonblocking descriptor.
44 * @details Retained solely for platform compatibility. New code must not use this predicate to
45 * gate UART reads; it would permanently suppress them.
46 */
47static inline int ttyUSB0ChAvailable(void)
48{
49 return false;
50}
51
52/**
53 * @brief Attempt a single-byte write through the legacy UART interface.
54 * @param value Byte to send.
55 * @details The compatibility API cannot report a short write or a busy
56 * descriptor. Use the frame-aware interface in serial_tx.h for USHER output.
57 */
58static inline void ttyUSB0Transmit(char value)
59{
60 (void)write(fd, &value, 1);
61}
62
63/**
64 * @brief Attempt a single-byte read through the legacy UART interface.
65 * @return Received byte, or zero when no byte was read.
66 * @details The return value cannot distinguish a received NUL from an empty
67 * read; binary protocol parsers must check the descriptor read result instead.
68 */
69static inline char ttyUSB0Getch(void)
70{
71 char value = 0;
72 (void)read(fd, &value, 1);
73 return value;
74}
int fd
Definition serial.c:39
static void ttyUSB0Transmit(char value)
Attempt a single-byte write through the legacy UART interface.
Definition serial.h:58
static int ttyUSB0ChAvailable(void)
Preserve the legacy "character available" transport API contract.
Definition serial.h:47
int serial_init(const char *port_name)
Configure the shared non-blocking USHER UART descriptor.
Definition serial.c:41
static char ttyUSB0Getch(void)
Attempt a single-byte read through the legacy UART interface.
Definition serial.h:69