15uint8_t buffer_raw[bufCap];
16uint8_t little_buffer[littleBufCap];
18char dataBuffer[MAXDATALEN];
28char ascVersion, appVersion, command;
33int main(
int argc,
char *argv[]) {
37 if (strncmp(
"-h", argv[1], 2) == 0) {
39 "\n ascii_serial_com_dummy_loopback_device [-h] [-l] <infile> "
42 " If no filenames are provided, then stdin and stdout are used\n"
43 " -h: show help and exit\n"
44 " -l: Raw loopback mode, ASCII Serial Com will not be used\n"
48 if (strncmp(
"-l", argv[1], 2) == 0) {
50 "\nRaw loopback mode enabled, ASCII Serial Com will not be "
55 if (argc == 2 && !rawLoopback) {
56 fprintf(stderr,
"Error: either 0 or 2 arguments required:\n");
58 "\n ascii_serial_com_dummy_loopback_device [-h] [-l] <infile> "
61 " If no filenames are provided, then stdin and stdout are used\n"
62 " -h: show help and exit\n"
63 " -l: Raw loopback mode, ASCII Serial Com will not be used\n"
73 const char *infilename = argv[1];
74 const char *outfilename = argv[2];
75 fprintf(stdout,
"infile: %s\noutfile: %s\n", infilename, outfilename);
77 infile = fopen(infilename,
"r");
79 perror(
"Error opening input file");
80 fprintf(stderr,
"Exiting.\n");
83 infileno = fileno(infile);
85 perror(
"Error getting infile descriptor");
86 fprintf(stderr,
"Exiting.\n");
89 outfile = fopen(outfilename,
"a+");
91 perror(
"Error opening output file");
92 fprintf(stderr,
"Exiting.\n");
95 outfileno = fileno(outfile);
97 perror(
"Error getting infile descriptor");
98 fprintf(stderr,
"Exiting.\n");
103 fprintf(stderr,
"infile: stdin\noutfile: stdout\n");
106 infileno = STDIN_FILENO;
107 outfileno = STDOUT_FILENO;
126 fprintf(stderr,
"Uncaught exception: %u, during init, exiting.\n", e);
133 if (poll_ret_code != 0) {
145 &asc, &ascVersion, &appVersion, &command, dataBuffer, &dataLen);
146 if (command !=
'\0') {
149 "Received message:\n asc and app versions: %c %c\n command: "
150 "%c dataLen: %zu\n data: ",
151 ascVersion, appVersion, command, dataLen);
152 for (
size_t iData = 0; iData < dataLen; iData++) {
153 fprintf(stderr,
"%c", dataBuffer[iData]);
155 fprintf(stderr,
"\n");
158 &asc, ascVersion, appVersion, command, dataBuffer, dataLen);
177 Catch(e) { fprintf(stderr,
"Uncaught exception: %u, continuing.\n", e); }
circular_buffer_uint8 * ascii_serial_com_get_output_buffer(ascii_serial_com *asc)
ASCII Serial Com get output buffer.
void ascii_serial_com_init(ascii_serial_com *asc)
ASCII Serial Com Interface init method.
void ascii_serial_com_put_message_in_output_buffer(ascii_serial_com *asc, char ascVersion, char appVersion, char command, const char *data, size_t dataLen)
ASCII Serial Com Pack and put message in output buffer.
void ascii_serial_com_get_message_from_input_buffer(ascii_serial_com *asc, char *ascVersion, char *appVersion, char *command, char *data, size_t *dataLen)
ASCII Serial Com pop message from input buffer and unpack.
circular_buffer_uint8 * ascii_serial_com_get_input_buffer(ascii_serial_com *asc)
ASCII Serial Com get input buffer.
void circular_buffer_init_uint8(circular_buffer_uint8 *circ_buf, const size_t capacity, uint8_t *buffer)
circular buffer init method
bool circular_buffer_is_empty_uint8(const circular_buffer_uint8 *circ_buf)
circular buffer get if empty
uint8_t circular_buffer_io_fd_poll_do_poll(circular_buffer_io_fd_poll *cb_io, int timeout)
poll circular buffer IO with file descriptor polling object
void circular_buffer_io_fd_poll_init(circular_buffer_io_fd_poll *cb_io, circular_buffer_uint8 *in_buf, circular_buffer_uint8 *out_buf, int fd_in, int fd_out)
Initialize circular buffer IO with file descriptor polling object.
size_t circular_buffer_io_fd_poll_do_input(circular_buffer_io_fd_poll *cb_io)
circular buffer IO with file descriptor polling object: read from input fd
size_t circular_buffer_io_fd_poll_do_output(circular_buffer_io_fd_poll *cb_io)
circular buffer IO with file descriptor polling object: write to output fd
Circular buffer IO with file descriptor polling.
ASCII Serial Com Interface State struct.
Circular buffer IO with file descriptor polling struct.