ASCII Serial Com
Serial communication library between computers, microcontrollers, FPGAs, etc. Uses only ASCII. Not the most efficient protocol, but meant to be easy to read
Loading...
Searching...
No Matches
ascii_serial_com_encode_decode_profiler.c
1#include <errno.h>
2#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5#include <unistd.h>
6
7#include "asc_exception.h"
8#include "ascii_serial_com.h"
9#include "circular_buffer.h"
10
12circular_buffer_uint8 *asc_in_buf;
13circular_buffer_uint8 *asc_out_buf;
14
15CEXCEPTION_T e;
16char ascVersion, appVersion, command;
17size_t dataLen;
18char dataBuffer[MAXDATALEN];
19unsigned long iIteration;
20
21char usage[] = "\n ascii_serial_com_encode_decode_profiler [-h] <N>\n\n"
22 " where N is the number of iterations to run\n"
23 " -h: show this help then exit\n"
24 "\n\0";
25
26int main(int argc, char *argv[]) {
27
28 if (argc < 2) {
29 fprintf(stderr,
30 "ascii_serial_com_encode_decode_profiler not enough arguments\n");
31 fprintf(stderr, "%s", usage);
32 return 1;
33 }
34 if (strncmp("-h", argv[1], 2) == 0) {
35 fprintf(stderr, "%s", usage);
36 return 0;
37 }
38 const unsigned long nIterations = strtoul(argv[1], NULL, 10);
39 fprintf(stdout, "Running with %lu iterations.\n", nIterations);
40
41 Try {
43 asc_in_buf = ascii_serial_com_get_input_buffer(&asc);
44 asc_out_buf = ascii_serial_com_get_output_buffer(&asc);
45 }
46 Catch(e) {
47 fprintf(stderr, "Uncaught exception: %u, during init, exiting.\n", e);
48 return 1;
49 }
50
51 for (iIteration = 0; iIteration < nIterations; iIteration++) {
52 Try {
53 // fprintf(stdout,"Iteration %lu\n",iIteration);
54 ascii_serial_com_put_message_in_output_buffer(&asc, '0', '0', 'z', NULL,
55 0);
56 const size_t messageLen = circular_buffer_get_size_uint8(asc_out_buf);
57 for (size_t iChar = 0; iChar < messageLen; iChar++) {
59 asc_in_buf, circular_buffer_pop_front_uint8(asc_out_buf));
60 }
62 &asc, &ascVersion, &appVersion, &command, dataBuffer, &dataLen);
63 }
64 Catch(e) { fprintf(stderr, "Uncaught exception: %u, continuing.\n", e); }
65 }
66
67 fprintf(stdout, "Finished %lu iterations.\n", nIterations);
68 return 0;
69}
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.
size_t circular_buffer_get_size_uint8(const circular_buffer_uint8 *circ_buf)
circular buffer get number of elements
uint8_t circular_buffer_pop_front_uint8(circular_buffer_uint8 *circ_buf)
circular buffer pop front
void circular_buffer_push_back_uint8(circular_buffer_uint8 *circ_buf, const uint8_t element)
circular buffer push back
ASCII Serial Com Interface State struct.
circular buffer struct