O2S C Library 1.8.2
Provide high-level data-structures and other fundamental tools for C projects
Loading...
Searching...
No Matches
open.c
1/* ************************************************************************** */
2/* ____ _ _____ ____ _ _ _ _____ _ _ ____ ____ */
3/* / ___| / \ | ___| _ \ / \ | \ | | |_ _| || | | _ \/ ___| */
4/* \___ \ / _ \ | |_ | |_) | / _ \ | \| | | | | || |_| | | \___ \ */
5/* ___) / ___ \| _| | _ < / ___ \| |\ | | | |__ _| |_| |___) | */
6/* |____/_/ \_|_| |_| \_/_/ \_|_| \_| |_| |_| |____/|____/ */
7/* */
8/* Copyright 2023, SAFRAN T4DS, ALL RIGHTS RESERVED */
9/* */
10/* @file open.c */
11/* @author Antoine GAGNIERE */
12/* */
13/* ************************************************************************** */
14
16#include "o2s/serial.h"
17
18#include <fcntl.h> // O_*
19
20#include <stdlib.h> // malloc
21
25serial_port_t serial_open_readonly(const char* port_name)
26{
27 serial_port_t port = {.file = file_open(port_name, O_RDONLY | O_NOCTTY)};
28 port.file.stream.accumulate = (bool (*)(istream_t*, size_t))file_accumulate_infinite;
29 return port;
30}
31
35serial_port_t serial_open_readwrite(const char* port_name)
36{
37 serial_port_t port = {.file = file_open(port_name, O_RDWR | O_NOCTTY)};
38 port.file.stream.accumulate = (bool (*)(istream_t*, size_t))file_accumulate_infinite;
39 return port;
40}
41
43serial_port_t* serial_new_readwrite(const char* port_name)
44{
45 serial_port_t* port = malloc(sizeof(serial_port_t));
46
47 *port = serial_open_readwrite(port_name);
48 return port;
49}
ifstream_t file_open(const char *file_name, int flags)
Construct a file input stream : Open the file and allocate the buffer.
Definition open.c:35
Buffered file reader.
bool file_accumulate_infinite(ifstream_t *file, size_t count)
If possible, accumulate count bytes before returning.
Definition read.c:69
Configure and read from serial ports as buffered input streams.
serial_port_t * serial_new_readwrite(const char *port_name)
Allocates a serial port and opens it.
Definition open.c:43
Input Stream.