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.c
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.c
20 * @brief Configure USHER's non-blocking flight-controller UART.
21 * @details This module owns only the receive-side descriptor setup. Transmit
22 * buffering and concurrent writers are handled by serial_tx.c. Raw 8-bit mode is
23 * necessary because USHER frames are binary and can contain bytes that terminal
24 * line discipline would otherwise translate or consume.
25 */
26
27#include <errno.h>
28#include <fcntl.h>
29#include <stdio.h>
30#include <string.h>
31#include <termios.h>
32#include <unistd.h>
33
34/****************************************************************************/
35/* Open serial device for requested protocoll */
36/****************************************************************************/
37
38/** Shared UART descriptor used by legacy receive/transmit integration code. */
39int fd = -1;
40
41int serial_init(const char *port_name)
42{
43 struct termios orig_termios, cur_termios;
44 int failure = -1;
45
46 const speed_t baud_rate = B115200;
47
48 if (!port_name || !port_name[0]) { errno = EINVAL; return -1; }
49 fd = open(port_name, O_RDWR | O_NOCTTY | O_NONBLOCK | O_CLOEXEC);
50
51 if (fd == -1) {
52 fprintf(stderr, "USHER:\tfailed to open serial device %s: %s\n", port_name, strerror(errno));
53 return -1;
54 }
55
56 if (tcgetattr(fd, &orig_termios)) {
57 failure = -2;
58 goto failed;
59 }
60 cur_termios = orig_termios;
61
62 /* input modes - turn off input processing */
63 cur_termios.c_iflag &= ~(IGNBRK | BRKINT | IGNPAR | PARMRK | INPCK | ISTRIP | INLCR | IGNCR
64 | ICRNL | IXON | IXANY | IXOFF | IMAXBEL);
65 /* pas IGNCR sinon il vire les 0x0D */
66 cur_termios.c_iflag |= BRKINT;
67
68 /* output_flags - turn off output processing */
69 cur_termios.c_oflag &= ~(OPOST | ONLCR | OCRNL | ONOCR | ONLRET);
70
71 /* control modes */
72 cur_termios.c_cflag &= ~(CSIZE | CSTOPB | CREAD | PARENB | PARODD | HUPCL | CLOCAL);
73 cur_termios.c_cflag |= CREAD | CS8 | CLOCAL;
74
75 /* local modes */
76 cur_termios.c_lflag &= ~(ISIG | ICANON | IEXTEN | ECHO);
77 cur_termios.c_lflag |= NOFLSH;
78 cur_termios.c_cc[VMIN] = 1;
79 cur_termios.c_cc[VTIME] = 0;
80
81 if (cfsetispeed(&cur_termios, baud_rate) || cfsetospeed(&cur_termios, baud_rate)) {
82 failure = -3;
83 goto failed;
84 }
85
86 if (tcsetattr(fd, TCSANOW, &cur_termios)) {
87 failure = -4;
88 goto failed;
89 }
90
91 return 0;
92failed:
93 {
94 const int error = errno;
95 close(fd);
96 fd = -1;
97 fprintf(stderr, "USHER:\tfailed to configure serial device %s: %s\n", port_name, strerror(error));
98 errno = error;
99 return failure;
100 }
101}
102
103
void(* close)(struct usbfs_handle *)
Definition chdkbridge.c:57
int(* open)(const struct usbfs_device *, struct usbfs_handle *)
Definition chdkbridge.c:56
struct jpeg_error_mgr error
Definition lwir_image.c:60
int fd
Definition serial.c:39
int serial_init(const char *port_name)
Configure the shared non-blocking USHER UART descriptor.
Definition serial.c:41