From e22ba69819a42c596e3bcb46a533124f5e71afda Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Fri, 5 May 2017 08:48:15 +0200 Subject: [PATCH] Implement the serial communication functions as no-ops For the socket based I/O stream implementations (IrDA and bluetooth) the serial communication specific functions are meaningless. Implementing them as no-ops allows the dive computer backends the call the I/O stream functions unconditionally. This is important for the bluetooth implementation, because bluetooth enabled dive computers will be able to use both the native bluetooth communication and the legacy bluetooth serial port emulation. --- src/bluetooth.c | 20 ++++++++-------- src/irda.c | 20 ++++++++-------- src/socket.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ src/socket.h | 33 ++++++++++++++++++++++++++ 4 files changed, 116 insertions(+), 20 deletions(-) diff --git a/src/bluetooth.c b/src/bluetooth.c index 3399cd2..b139892 100644 --- a/src/bluetooth.c +++ b/src/bluetooth.c @@ -65,19 +65,19 @@ static const dc_iostream_vtable_t dc_bluetooth_vtable = { sizeof(dc_socket_t), dc_socket_set_timeout, /* set_timeout */ - NULL, /* set_latency */ - NULL, /* set_halfduplex */ - NULL, /* set_break */ - NULL, /* set_dtr */ - NULL, /* set_rts */ - NULL, /* get_lines */ + dc_socket_set_latency, /* set_latency */ + dc_socket_set_halfduplex, /* set_halfduplex */ + dc_socket_set_break, /* set_break */ + dc_socket_set_dtr, /* set_dtr */ + dc_socket_set_rts, /* set_rts */ + dc_socket_get_lines, /* get_lines */ dc_socket_get_available, /* get_received */ - NULL, /* configure */ + dc_socket_configure, /* configure */ dc_socket_read, /* read */ dc_socket_write, /* write */ - NULL, /* flush */ - NULL, /* purge */ - NULL, /* sleep */ + dc_socket_flush, /* flush */ + dc_socket_purge, /* purge */ + dc_socket_sleep, /* sleep */ dc_socket_close, /* close */ }; diff --git a/src/irda.c b/src/irda.c index 527e3c0..149808a 100644 --- a/src/irda.c +++ b/src/irda.c @@ -56,19 +56,19 @@ static const dc_iostream_vtable_t dc_irda_vtable = { sizeof(dc_socket_t), dc_socket_set_timeout, /* set_timeout */ - NULL, /* set_latency */ - NULL, /* set_halfduplex */ - NULL, /* set_break */ - NULL, /* set_dtr */ - NULL, /* set_rts */ - NULL, /* get_lines */ + dc_socket_set_latency, /* set_latency */ + dc_socket_set_halfduplex, /* set_halfduplex */ + dc_socket_set_break, /* set_break */ + dc_socket_set_dtr, /* set_dtr */ + dc_socket_set_rts, /* set_rts */ + dc_socket_get_lines, /* get_lines */ dc_socket_get_available, /* get_received */ - NULL, /* configure */ + dc_socket_configure, /* configure */ dc_socket_read, /* read */ dc_socket_write, /* write */ - NULL, /* flush */ - NULL, /* purge */ - NULL, /* sleep */ + dc_socket_flush, /* flush */ + dc_socket_purge, /* purge */ + dc_socket_sleep, /* sleep */ dc_socket_close, /* close */ }; #endif diff --git a/src/socket.c b/src/socket.c index 948aa46..5ce392f 100644 --- a/src/socket.c +++ b/src/socket.c @@ -163,6 +163,45 @@ dc_socket_set_timeout (dc_iostream_t *abstract, int timeout) return DC_STATUS_SUCCESS; } +dc_status_t +dc_socket_set_latency (dc_iostream_t *iostream, unsigned int value) +{ + return DC_STATUS_SUCCESS; +} + +dc_status_t +dc_socket_set_halfduplex (dc_iostream_t *iostream, unsigned int value) +{ + return DC_STATUS_SUCCESS; +} + +dc_status_t +dc_socket_set_break (dc_iostream_t *iostream, unsigned int value) +{ + return DC_STATUS_SUCCESS; +} + +dc_status_t +dc_socket_set_dtr (dc_iostream_t *iostream, unsigned int value) +{ + return DC_STATUS_SUCCESS; +} + +dc_status_t +dc_socket_set_rts (dc_iostream_t *iostream, unsigned int value) +{ + return DC_STATUS_SUCCESS; +} + +dc_status_t +dc_socket_get_lines (dc_iostream_t *iostream, unsigned int *value) +{ + if (value) + *value = 0; + + return DC_STATUS_SUCCESS; +} + dc_status_t dc_socket_get_available (dc_iostream_t *abstract, size_t *value) { @@ -186,6 +225,12 @@ dc_socket_get_available (dc_iostream_t *abstract, size_t *value) return DC_STATUS_SUCCESS; } +dc_status_t +dc_socket_configure (dc_iostream_t *abstract, unsigned int baudrate, unsigned int databits, dc_parity_t parity, dc_stopbits_t stopbits, dc_flowcontrol_t flowcontrol) +{ + return DC_STATUS_SUCCESS; +} + dc_status_t dc_socket_read (dc_iostream_t *abstract, void *data, size_t size, size_t *actual) { @@ -293,3 +338,21 @@ out: return status; } + +dc_status_t +dc_socket_flush (dc_iostream_t *abstract) +{ + return DC_STATUS_SUCCESS; +} + +dc_status_t +dc_socket_purge (dc_iostream_t *abstract, dc_direction_t direction) +{ + return DC_STATUS_SUCCESS; +} + +dc_status_t +dc_socket_sleep (dc_iostream_t *abstract, unsigned int timeout) +{ + return DC_STATUS_SUCCESS; +} diff --git a/src/socket.h b/src/socket.h index 1a8aa18..d612603 100644 --- a/src/socket.h +++ b/src/socket.h @@ -104,15 +104,48 @@ dc_socket_connect (dc_iostream_t *iostream, const struct sockaddr *addr, s_sockl dc_status_t dc_socket_set_timeout (dc_iostream_t *iostream, int timeout); +dc_status_t +dc_socket_set_latency (dc_iostream_t *iostream, unsigned int value); + +dc_status_t +dc_socket_set_halfduplex (dc_iostream_t *iostream, unsigned int value); + +dc_status_t +dc_socket_set_break (dc_iostream_t *iostream, unsigned int value); + +dc_status_t +dc_socket_set_dtr (dc_iostream_t *iostream, unsigned int value); + +dc_status_t +dc_socket_set_rts (dc_iostream_t *iostream, unsigned int value); + +dc_status_t +dc_socket_get_lines (dc_iostream_t *iostream, unsigned int *value); + dc_status_t dc_socket_get_available (dc_iostream_t *iostream, size_t *value); +dc_status_t +dc_socket_configure (dc_iostream_t *iostream, unsigned int baudrate, unsigned int databits, dc_parity_t parity, dc_stopbits_t stopbits, dc_flowcontrol_t flowcontrol); + dc_status_t dc_socket_read (dc_iostream_t *iostream, void *data, size_t size, size_t *actual); dc_status_t dc_socket_write (dc_iostream_t *iostream, const void *data, size_t size, size_t *actual); +dc_status_t +dc_socket_flush (dc_iostream_t *iostream); + +dc_status_t +dc_socket_purge (dc_iostream_t *iostream, dc_direction_t direction); + +dc_status_t +dc_socket_sleep (dc_iostream_t *iostream, unsigned int milliseconds); + +dc_status_t +dc_socket_close (dc_iostream_t *iostream); + #ifdef __cplusplus } #endif /* __cplusplus */