O2S C Library 1.8.2
Provide high-level data-structures and other fundamental tools for C projects
Loading...
Searching...
No Matches
serial.h
Go to the documentation of this file.
1#pragma once
2
3/* ************************************************************************** */
4/* ____ _ _____ ____ _ _ _ _____ _ _ ____ ____ */
5/* / ___| / \ | ___| _ \ / \ | \ | | |_ _| || | | _ \/ ___| */
6/* \___ \ / _ \ | |_ | |_) | / _ \ | \| | | | | || |_| | | \___ \ */
7/* ___) / ___ \| _| | _ < / ___ \| |\ | | | |__ _| |_| |___) | */
8/* |____/_/ \_|_| |_| \_/_/ \_|_| \_| |_| |_| |____/|____/ */
9/* */
16/* ************************************************************************** */
17
19#include "o2s/serial_options.h"
20
21#include <stdbool.h>
22#include <stdint.h> // uint*_t
23
25typedef struct serial_port serial_port_t;
26
29{
31 serial_options_t options;
33};
34
37serial_port_t serial_open_readonly(const char* port_name);
38serial_port_t serial_open_readwrite(const char* port_name);
39void serial_close(serial_port_t* port);
40serial_port_t* serial_new_readwrite(const char* port_name);
41void serial_free(serial_port_t** port);
43
46bool serial_get_options(serial_port_t* port);
47bool serial_apply_options(serial_port_t* port);
48
49bool serial_set_options_raw(serial_port_t* port);
50bool serial_set_options_speed(serial_port_t* port, int64_t speed_bps);
51bool serial_make_raw(serial_port_t* port, int64_t speed_bps);
53
56int64_t serial_decode_baudrate(speed_t flag);
57speed_t serial_encode_baudrate(int64_t speed_in_bps);
59
76#define Serial __attribute__((cleanup(serial_close))) serial_port_t
Buffered file reader.
bool serial_make_raw(serial_port_t *port, int64_t speed_bps)
General configuration for non-canonical mode.
Definition make_raw.c:88
speed_t serial_encode_baudrate(int64_t speed_in_bps)
Convert the baudrate to a system specific enum.
Definition baudrate.c:74
bool serial_set_options_speed(serial_port_t *port, int64_t speed_bps)
Modify the copy of the options about speed, but do not apply them.
Definition make_raw.c:62
int64_t serial_decode_baudrate(speed_t flag)
Convert the baudrate from termios to bits per second.
Definition baudrate.c:28
serial_port_t serial_open_readwrite(const char *port_name)
Open the port in read and write, and allocate the buffer.
Definition open.c:35
serial_port_t serial_open_readonly(const char *port_name)
Open the port in read-only, and allocate the buffer.
Definition open.c:25
void serial_free(serial_port_t **port)
Close and free a serial port created with serial_new_readwrite.
Definition close.c:27
bool serial_set_options_raw(serial_port_t *port)
Modify the copy of the options, but do not apply them.
Definition make_raw.c:29
void serial_close(serial_port_t *port)
Closes the specified serial port.
Definition close.c:21
bool serial_apply_options(serial_port_t *port)
Apply the options immediatly.
serial_port_t * serial_new_readwrite(const char *port_name)
Allocates a serial port and opens it.
Definition open.c:43
bool serial_get_options(serial_port_t *port)
Ask the port for its configuration.
Definition get_options.c:27
Verbose alternative to the termios structure.
File Input Stream.
Serial port handler, includes a buffer.
Definition serial.h:29
serial_options_t options
Terminal options.
Definition serial.h:31
bool got_options
Is options filled ?
Definition serial.h:32
ifstream_t file
Input file buffered stream.
Definition serial.h:30