fplayer
C99 Falcon Sequence (fseq) file player for Light-O-Rama hardware (like xLights)
Loading...
Searching...
No Matches
serial.c File Reference

Serial port communication implementation. More...

#include "serial.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <libserialport.h>
#include "std2/errcode.h"
Include dependency graph for serial.c:

Data Structures

struct  serialdev_s
 Serial port communication device. More...
 

Functions

static void Serial_printError (const enum sp_return err)
 Prints an error message to stderr for the given error code, including the libserialport error message if available.
 
static int Serial_openPort (struct serialdev_s **sdev, const char *const devName, const int baudRate)
 Opens the serial port with the given device name and baud rate.
 
int Serial_init (struct serialdev_s **const sdev, const char *const devName, const int baudRate)
 Initializes a write-mode serial port with the provided device name and baud rate pre-configured for use as a LOR network connection.
 
static void Serial_writeVirtual (struct serialdev_s *const sdev, const uint8_t *const b, const unsigned long size)
 Writes the binary data to the virtual file handle within the virtual serial device structure.
 
static void Serial_writeReal (struct serialdev_s *const sdev, const uint8_t *const b, const unsigned long size)
 Writes the binary data to the "real" opened serial port handle within the virtual serial device structure.
 
void Serial_write (struct serialdev_s *const sdev, const uint8_t *const b, const unsigned long size)
 Writes the binary data to the open serial port. The data is copied to an internal buffer and written to the serial port asynchronously.
 
void Serial_drain (struct serialdev_s *const sdev)
 Waits for all data to be written to the serial device.
 
void Serial_close (struct serialdev_s *const sdev)
 Closes the open serial device and frees all resources.
 
slist_t * Serial_getPorts (void)
 Retrieves a list of available serial ports. The caller is responsible for freeing the list with slfree.
 

Detailed Description

Serial port communication implementation.

Function Documentation

◆ Serial_close()

void Serial_close ( struct serialdev_s * sdev)

Closes the open serial device and frees all resources.

Parameters
sdevserial device to close, may be NULL
Here is the caller graph for this function:

◆ Serial_drain()

void Serial_drain ( struct serialdev_s * sdev)

Waits for all data to be written to the serial device.

Parameters
sdevserial device to drain, must not be NULL
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Serial_getPorts()

slist_t * Serial_getPorts ( void )

Retrieves a list of available serial ports. The caller is responsible for freeing the list with slfree.

Returns
list of available serial ports, or NULL on failure or no ports found
Here is the caller graph for this function:

◆ Serial_init()

int Serial_init ( struct serialdev_s ** sdev,
const char * devName,
int baudRate )

Initializes a write-mode serial port with the provided device name and baud rate pre-configured for use as a LOR network connection.

Parameters
sdevserial device to initialize, must not be NULL
devNamedevice name of the serial port
baudRatebaud rate of the serial port
Returns
0 on success, a negative error code on failure
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Serial_openPort()

static int Serial_openPort ( struct serialdev_s ** sdev,
const char *const devName,
const int baudRate )
static

Opens the serial port with the given device name and baud rate.

Parameters
sdevthe serial device structure to populate
devNamethe device name to open
baudRatethe baud rate to configure the device connection with
Returns
0 on success, a negative error code on failure
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Serial_printError()

static void Serial_printError ( const enum sp_return err)
static

Prints an error message to stderr for the given error code, including the libserialport error message if available.

Parameters
errthe error code to print the message for
Here is the caller graph for this function:

◆ Serial_write()

void Serial_write ( struct serialdev_s * sdev,
const uint8_t * b,
unsigned long size )

Writes the binary data to the open serial port. The data is copied to an internal buffer and written to the serial port asynchronously.

Parameters
sdevserial device to write to, must not be NULL
bbinary data to write
sizesize of the binary data
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Serial_writeReal()

static void Serial_writeReal ( struct serialdev_s *const sdev,
const uint8_t *const b,
const unsigned long size )
inlinestatic

Writes the binary data to the "real" opened serial port handle within the virtual serial device structure.

Parameters
sdevthe virtual serial device structure
bbinary data to write
sizesize of the binary data to write
Note
This function is only called if the virtual device is ->real.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Serial_writeVirtual()

static void Serial_writeVirtual ( struct serialdev_s *const sdev,
const uint8_t *const b,
const unsigned long size )
inlinestatic

Writes the binary data to the virtual file handle within the virtual serial device structure.

Parameters
sdevthe virtual serial device structure
bbinary data to write
sizesize of the binary data to write
Note
This function is only called if the virtual device is ->virtual.
Here is the caller graph for this function: