31 #define ASCII_SOH 0x01
32 #define ASCII_STX 0x02
33 #define ASCII_ETX 0x03
34 #define ASCII_EOT 0x04
35 #define ASCII_ENQ 0x05
36 #define ASCII_ACK 0x06
38 #define ASCII_TAB 0x09
41 #define ASCII_XON 0x11
42 #define ASCII_XOFF 0x13
43 #define ASCII_NAK 0x15
44 #define ASCII_EOF 0x1A
45 #define ASCII_CAN 0x18
47 #define ASCII_ESC 0x1B
48 #define ASCII_DEL 0x7F
49 #define ASCII_EOL "\r\n"
51 #ifndef RX_BUFFER_SIZE
52 #define RX_BUFFER_SIZE 1024
55 #ifndef TX_BUFFER_SIZE
56 #define TX_BUFFER_SIZE 512
59 #ifndef BLOCK_TX_BUFFER_SIZE
60 #define BLOCK_TX_BUFFER_SIZE 256
65 #define BAUD_RATE 115200
69 #ifndef SERIAL_NO_DATA
70 #define SERIAL_NO_DATA -1
73 #define BUFNEXT(ptr, buffer) ((ptr + 1) & (sizeof(buffer.data) - 1))
74 #define BUFCOUNT(head, tail, size) ((head >= tail) ? (head - tail) : (size - tail + head))
443 #if defined(DEBUG) || defined(DEBUGOUT)
444 #define DEBUG_PRINT 1
446 void debug_write (
const char *s);
447 void debug_writeln (
const char *s);
448 bool debug_stream_init (
void);
451 #define DEBUG_PRINT 0
454 #define debug_print(fmt, ...) \
455 do { if(DEBUG_PRINT) debug_printf(fmt, __VA_ARGS__); } while(0)
uint8_t instance
Definition: stream.c:449
uint32_t baud_rate
Definition: stream.c:450
stream_write_char_ptr write_char
Definition: stream.c:80
bool stream_connected(void)
Definition: stream.c:211
serial_stopbits_t
Definition: stream.h:105
@ Serial_StopBits0_5
Definition: stream.h:109
@ Serial_StopBits1
Definition: stream.h:106
@ Serial_StopBits2
Definition: stream.h:108
@ Serial_StopBits1_5
Definition: stream.h:107
void stream_disconnect(const io_stream_t *stream)
Definition: stream.c:471
bool(* stream_release_ptr)(uint8_t instance)
Definition: stream.h:325
stream_suspend_state_t
Definition: stream.h:94
@ StreamSuspend_Pending
Definition: stream.h:96
@ StreamSuspend_Active
Definition: stream.h:97
@ StreamSuspend_Off
Definition: stream.h:95
uint16_t(* get_stream_buffer_count_ptr)(void)
Pointer to function for getting number of characters available or free in a stream buffer.
Definition: stream.h:147
bool(* stream_is_connected_ptr)(void)
Pointer to function for getting stream connected status.
Definition: stream.h:142
void(* stream_write_ptr)(const char *s)
Pointer to function for writing a null terminated string to the output stream.
Definition: stream.h:159
bool stream_enqueue_realtime_command(uint8_t c)
Definition: stream.c:199
bool stream_enumerate_streams(stream_enumerate_callback_ptr callback)
Definition: stream.c:92
bool(* stream_enumerate_callback_ptr)(io_stream_properties_t const *properties)
Definition: stream.h:337
bool(* set_format_ptr)(serial_format_t format)
Pointer to function for setting the stream format.
Definition: stream.h:209
bool stream_mpg_check_enable(char c)
Definition: stream.c:541
void stream_mpg_set_mode(void *data)
Definition: stream.c:536
const io_stream_status_t * stream_get_uart_status(uint8_t instance)
Definition: stream.c:128
bool stream_tx_blocking(void)
Definition: stream.c:113
bool(* stream_write_char_ptr)(const uint8_t c)
Pointer to function for writing a single character to the output stream.
Definition: stream.h:171
void(* on_linestate_changed_ptr)(serial_linestate_t state)
Pointer to function for handling line state changed events.
Definition: stream.h:262
void stream_set_defaults(const io_stream_t *stream, uint32_t baud_rate)
Definition: stream.c:516
io_stream_t const * stream_open_instance(uint8_t instance, uint32_t baud_rate, stream_write_char_ptr rx_handler, const char *description)
Definition: stream.c:477
void(* cancel_read_buffer_ptr)(void)
Pointer to function for flushing the input buffer and inserting an ASCII_CAN character.
Definition: stream.h:225
bool(* enqueue_realtime_command_ptr)(uint8_t c)
Pointer to function for extracting real-time commands from the input stream and enqueue them for proc...
Definition: stream.h:178
int32_t stream_get_null(void)
Dummy function for reading data from a virtual empty input buffer.
Definition: stream.c:123
void stream_register_streams(io_stream_details_t *details)
Definition: stream.c:84
io_stream_flags_t stream_get_flags(io_stream_t stream)
Definition: stream.c:407
int32_t(* stream_read_ptr)(void)
Pointer to function for reading a single character from a input stream.
Definition: stream.h:152
bool stream_mpg_enable(bool on)
Function for enabling/disabling input from a secondary input stream.
Definition: stream.c:606
#define RX_BUFFER_SIZE
Definition: stream.h:52
bool stream_connect_instance(uint8_t instance, uint32_t baud_rate)
Definition: stream.c:462
const io_stream_t * stream_null_init(uint32_t baud_rate)
Definition: stream.c:713
void(* stream_write_n_ptr)(const uint8_t *s, uint16_t len)
Pointer to function for writing a n character long string to the output stream.
Definition: stream.h:165
void debug_printf(const char *fmt,...)
Definition: stream.c:867
bool stream_connect(const io_stream_t *stream)
Definition: stream.c:438
bool stream_mpg_register(const io_stream_t *stream, bool rx_only, stream_write_char_ptr write_char)
Definition: stream.c:554
void(* flush_stream_buffer_ptr)(void)
Pointer to function for flushing a stream buffer.
Definition: stream.h:218
stream_suspend_state_t stream_is_rx_suspended(void)
Definition: stream.c:166
#define TX_BUFFER_SIZE
Definition: stream.h:56
bool stream_set_description(const io_stream_t *stream, const char *description)
Definition: stream.c:426
bool(* set_baud_rate_ptr)(uint32_t baud_rate)
Pointer to function for setting the stream baud rate.
Definition: stream.h:215
struct io_stream_details io_stream_details_t
const io_stream_t *(* stream_claim_ptr)(uint32_t baud_rate)
Definition: stream.h:324
serial_parity_t
Definition: stream.h:112
@ Serial_ParitySpace
Definition: stream.h:117
@ Serial_ParityNone
Definition: stream.h:113
@ Serial_ParityMark
Definition: stream.h:116
@ Serial_ParityEven
Definition: stream.h:114
@ Serial_ParityOdd
Definition: stream.h:115
bool stream_rx_suspend(stream_rx_buffer_t *rxbuffer, bool suspend)
Function for blocking reads from or restoring an input buffer.
Definition: stream.c:171
#define BLOCK_TX_BUFFER_SIZE
Definition: stream.h:60
bool(* disable_rx_stream_ptr)(bool disable)
Pointer to function for disabling/enabling stream input.
Definition: stream.h:256
bool stream_buffer_all(uint8_t c)
Definition: stream.c:194
const io_stream_status_t *(* stream_get_status_ptr)(uint8_t instance)
Definition: stream.h:326
enqueue_realtime_command_ptr(* set_enqueue_rt_handler_ptr)(enqueue_realtime_command_ptr handler)
Pointer to function for setting the enqueue realtime commands handler.
Definition: stream.h:203
bool stream_close(io_stream_t const *stream)
Definition: stream.c:492
void(* stream_set_direction_ptr)(bool tx)
Pointer to function for setting the transfer direction control signal for half-duplex connections (RS...
Definition: stream.h:183
stream_type_t
Definition: stream.h:82
@ StreamType_Bluetooth
Definition: stream.h:85
@ StreamType_Telnet
Definition: stream.h:86
@ StreamType_SDCard
Definition: stream.h:88
@ StreamType_MPG
Definition: stream.h:84
@ StreamType_WebSocket
Definition: stream.h:87
@ StreamType_File
Definition: stream.h:89
@ StreamType_Null
Definition: stream.h:91
@ StreamType_Serial
Definition: stream.h:83
@ StreamType_Redirected
Definition: stream.h:90
serial_width_t
Definition: stream.h:100
@ Serial_8bit
Definition: stream.h:101
@ Serial_7bit
Definition: stream.h:102
bool(* suspend_read_ptr)(bool await)
Pointer to function for blocking reads from and restoring a input buffer.
Definition: stream.h:245
const io_stream_t * stream_get_base(void)
Definition: stream.c:402
bool(* enqueue_realtime_command2_ptr)(uint8_t c)
Optional, but recommended, pointer to function for enqueueing realtime command characters.
Definition: stream.h:193
struct io_stream_details * next
Definition: stream.h:342
io_stream_properties_t * streams
Definition: stream.h:341
uint8_t n_streams
Definition: stream.h:340
uint8_t instance
Instance of stream type, starts from 0.
Definition: stream.h:330
stream_release_ptr release
Definition: stream.h:333
stream_get_status_ptr get_status
Optional handler for getting stream status, for UART streams only.
Definition: stream.h:334
stream_type_t type
Type of stream.
Definition: stream.h:329
stream_claim_ptr claim
Definition: stream.h:332
io_stream_flags_t flags
Definition: stream.h:331
uint32_t baud_rate
Definition: stream.h:320
serial_format_t format
Definition: stream.h:321
io_stream_state_t state
Optional status flags such as connected status.
Definition: stream.h:318
io_stream_flags_t flags
Stream capability flags.
Definition: stream.h:319
Properties and handlers for stream I/O.
Definition: stream.h:290
uint8_t instance
Instance of stream type, starts from 0.
Definition: stream.h:292
flush_stream_buffer_ptr reset_read_buffer
Handler for flushing the input buffer.
Definition: stream.h:301
stream_write_char_ptr write_char
Handler for writing a single character to current stream only.
Definition: stream.h:298
set_enqueue_rt_handler_ptr set_enqueue_rt_handler
Handler for setting the enqueue realtime command character handler.
Definition: stream.h:303
set_format_ptr set_format
Optional handler for setting the stream format.
Definition: stream.h:311
stream_write_ptr write
Handler for writing string to current output stream only.
Definition: stream.h:296
enqueue_realtime_command2_ptr enqueue_rt_command
(Optional) handler for enqueueing a realtime command character.
Definition: stream.h:299
io_stream_state_t state
Optional status flags such as connected status.
Definition: stream.h:293
get_stream_buffer_count_ptr get_rx_buffer_count
Optional handler for getting number of characters in the input buffer.
Definition: stream.h:307
stream_type_t type
Type of stream.
Definition: stream.h:291
on_linestate_changed_ptr on_linestate_changed
Optional handler to be called when line state changes. Set by client.
Definition: stream.h:313
stream_write_n_ptr write_n
Optional handler for writing n characters to current output stream only. Required for Modbus support.
Definition: stream.h:305
get_stream_buffer_count_ptr get_tx_buffer_count
Optional handler for getting number of characters in the output buffer(s). Count shall include any un...
Definition: stream.h:308
disable_rx_stream_ptr disable_rx
Optional handler for disabling/enabling a stream. Recommended?
Definition: stream.h:306
stream_set_direction_ptr set_direction
Optional handler for setting the transfer direction for half-duplex communication.
Definition: stream.h:312
set_baud_rate_ptr set_baud_rate
Optional handler for setting the stream baud rate. Required for Modbus/RS-485 support,...
Definition: stream.h:310
stream_is_connected_ptr is_connected
Handler for getting stream connected status.
Definition: stream.h:294
cancel_read_buffer_ptr cancel_read_buffer
Handler for flushing the input buffer and inserting an ASCII_CAN character.
Definition: stream.h:302
stream_write_ptr write_all
Handler for writing string to all active output streams.
Definition: stream.h:297
vfs_file_t * file
File handle, non-null if streaming from a file.
Definition: stream.h:314
stream_read_ptr read
Handler for reading a single character from the input stream.
Definition: stream.h:300
flush_stream_buffer_ptr reset_write_buffer
Optional handler for flushing the output buffer. Any transmit FIFO shall be flushed as well....
Definition: stream.h:309
get_stream_buffer_count_ptr get_rx_buffer_free
Handler for getting number of free characters in the input buffer.
Definition: stream.h:295
suspend_read_ptr suspend_read
Optional handler for saving away and restoring the current input buffer.
Definition: stream.h:304
bool use_tx2data
Definition: stream.h:374
uint_fast16_t length
Definition: stream.h:371
uint8_t * s
Definition: stream.h:373
uint_fast16_t max_length
Definition: stream.h:372
uint_fast16_t length
Definition: stream.h:363
uint8_t * s
Definition: stream.h:365
uint_fast16_t max_length
Definition: stream.h:364
bool overflow
Definition: stream.h:351
volatile uint_fast16_t head
Definition: stream.h:348
volatile bool rts_state
Definition: stream.h:350
bool backup
Definition: stream.h:352
volatile uint_fast16_t tail
Definition: stream.h:349
volatile uint_fast16_t head
Definition: stream.h:357
volatile uint_fast16_t tail
Definition: stream.h:358
uint8_t can_set_baud
Definition: stream.h:269
uint8_t claimed
Definition: stream.h:268
uint8_t value
Definition: stream.h:265
uint8_t init_ok
Definition: stream.h:273
uint8_t rx_only
Definition: stream.h:270
uint8_t modbus_ready
Definition: stream.h:271
uint8_t rts_handshake
Definition: stream.h:272
uint8_t claimable
Definition: stream.h:267
uint8_t unused
Definition: stream.h:274
uint8_t is_usb
Definition: stream.h:282
uint8_t value
Definition: stream.h:279
uint8_t passthru
Set when stream is in passthru mode.
Definition: stream.h:284
uint8_t webui_connected
Definition: stream.h:281
uint8_t linestate_event
Set when driver supports on_linestate_changed event.
Definition: stream.h:283
uint8_t unused
Definition: stream.h:285
uint8_t rts
Definition: stream.h:134
uint8_t dtr
Definition: stream.h:133
uint8_t value
Definition: stream.h:131
uint8_t unused
Definition: stream.h:135