O2S C Library 1.8.2
Provide high-level data-structures and other fundamental tools for C projects
Loading...
Searching...
No Matches
make_raw.c
1/* ************************************************************************** */
2/* ____ _ _____ ____ _ _ _ _____ _ _ ____ ____ */
3/* / ___| / \ | ___| _ \ / \ | \ | | |_ _| || | | _ \/ ___| */
4/* \___ \ / _ \ | |_ | |_) | / _ \ | \| | | | | || |_| | | \___ \ */
5/* ___) / ___ \| _| | _ < / ___ \| |\ | | | |__ _| |_| |___) | */
6/* |____/_/ \_|_| |_| \_/_/ \_|_| \_| |_| |_| |____/|____/ */
7/* */
8/* Copyright 2023, SAFRAN T4DS, ALL RIGHTS RESERVED */
9/* */
10/* @file make_raw.c */
11/* @author Antoine GAGNIERE */
12/* */
13/* ************************************************************************** */
14
15#include "o2s/log.h"
16#include "o2s/serial.h"
17
18#include <termios.h> // tcsetattr
19
20#include <errno.h>
21#include <inttypes.h> // PRIi64
22#include <iso646.h> // not
23#include <string.h> // strerror
24
29bool serial_set_options_raw(serial_port_t* port)
30{
31 if (not serial_get_options(port))
32 return false;
33
34 port->options.input.ignore_break = false;
35 port->options.input.signal_break = false;
36 port->options.input.mark_errors = false;
37 port->options.input.strip_8th_bit = false;
38 port->options.input.map_nl_to_cr = false;
39 port->options.input.ignore_cr = false;
40 port->options.input.map_cr_to_nl = false;
41 port->options.input.enable_start_stop_out = false;
42
43 port->options.output.enable_processing = false;
44
45 port->options.control.character_size = character_size_8;
46 port->options.control.enable_parity = false;
47
48 port->options.local.enable_signals = false;
49 port->options.local.canonical = false;
50 port->options.local.echo = false;
51 port->options.local.echo_nl = false;
52 port->options.local.enable_processing = false;
53
54 /* Not mentionned in documentation */
55 port->options.control_characters.timeout = 0;
56 port->options.control_characters.minimum = 1;
57
58 return true;
59}
60
62bool serial_set_options_speed(serial_port_t* port, int64_t speed_bps)
63{
64 speed_t speed = serial_encode_baudrate(speed_bps);
65
66 if (speed == 0)
67 {
68 log_error("%" PRIi64 " is not a valid baudrate, refer to termios(3) for further details", speed_bps);
69 return false;
70 }
71 if (not serial_get_options(port))
72 return false;
73 port->options.input_speed = speed;
74 port->options.output_speed = speed;
75 port->options.input._dont_modify_speed = false;
76 port->options.control._speed_4lsb = speed;
77 port->options.control._speed_is_extra = speed >> 12;
78 return true;
79}
80
88bool serial_make_raw(serial_port_t* port, int64_t speed_bps)
89{
90 if (not(serial_set_options_raw(port) and serial_set_options_speed(port, speed_bps)
91 and serial_apply_options(port)))
92 return false;
93 return true;
94}
bool serial_apply_options(serial_port_t *port)
Apply the options immediatly.
Simplistic logging utilities.
#define log_error(...)
Report a condition causing the current operation to abort.
Definition log.h:83
Configure and read from serial ports as buffered input streams.
@ character_size_8
for most kinds of data
Dynamic string implementation.