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
test_ascii_serial_com_register_block.c
1#include "asc_exception.h"
3#include "externals/unity.h"
4#include <inttypes.h>
5#include <stdio.h>
6#include <string.h>
7
8CEXCEPTION_T e1;
9// CEXCEPTION_T e2;
10
11#if REGWIDTHBYTES == 1
12#define zerohex "00"
13#define onehex "01"
14#define maxhex "FF"
15#define regFmtStr "%02zX"
16#elif REGWIDTHBYTES == 2
17#define zerohex "0000"
18#define onehex "0001"
19#define maxhex "FFFF"
20#define regFmtStr "%04zX"
21#elif REGWIDTHBYTES == 4
22#define zerohex "00000000"
23#define onehex "00000001"
24#define maxhex "FFFFFFFF"
25#define regFmtStr "%08zX"
26#endif
27
28#define nRegs 256
29REGTYPE regs[nRegs];
30
31void setUp(void) {
32 // set stuff up here
33 for (size_t i = 0; i < nRegs; i++) {
34 regs[i] = 0;
35 }
36}
37
38void tearDown(void) {
39 // clean stuff up here
40}
41
42void test_ascii_serial_com_register_block_write(void) {
43 Try {
47
49 ascii_serial_com_register_block_init(&ascrb, regs, nRegs);
50
51 char ascVersion, appVersion, command, data[MAXDATALEN + 1];
52 size_t dataLen;
53
54 char validationStr[MAXMESSAGELEN + 1];
55 for (size_t iReg = 0; iReg < 0x100; iReg++) {
56 for (size_t iVal = 0; iVal < 0x100; iVal += 0x5) {
57 // printf("iReg: %02zX iVal: %02zX\n",iReg,iVal);
58 ascVersion = '0';
59 appVersion = '0';
60 command = 'w';
61 sprintf(data, "%04zX," regFmtStr, iReg, iVal);
62 dataLen = 5 + REGWIDTHBYTES * 2;
63 sprintf(validationStr, ">%c%c%c%04zX.", ascVersion, appVersion, command,
64 iReg);
66 &asc, ascVersion, appVersion, command, data, dataLen, &ascrb);
67 TEST_ASSERT_EQUAL_size_t(10 + 4,
69 TEST_ASSERT_EQUAL_CHAR_ARRAY(validationStr, out_buf->buffer, 5 + 4);
71
72 TEST_ASSERT_EQUAL_MESSAGE(iVal, regs[iReg],
73 "Register didn't get set to correct value!");
74
75 command = 'r';
76 sprintf(data, "%04zX", iReg);
77 dataLen = 4;
78 sprintf(validationStr, ">%c%c%c%04zX," regFmtStr ".", ascVersion,
79 appVersion, command, iReg, iVal);
81 &asc, ascVersion, appVersion, command, data, dataLen, &ascrb);
82 TEST_ASSERT_EQUAL_size_t(15 + REGWIDTHBYTES * 2,
84 TEST_ASSERT_EQUAL_CHAR_ARRAY(validationStr, out_buf->buffer,
85 10 + REGWIDTHBYTES * 2);
87 }
88 }
89 }
90 Catch(e1) {
91 printf("Uncaught exception: %u\n", e1);
92 TEST_FAIL_MESSAGE("Uncaught exception!");
93 }
94}
95
96int main(void) {
97 UNITY_BEGIN();
98 RUN_TEST(test_ascii_serial_com_register_block_write);
99 return UNITY_END();
100}
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_register_block_handle_message(ascii_serial_com *asc, char ascVersion, char appVersion, char command, char *data, size_t dataLen, void *register_block_state_vp)
ASCII Serial Com Register Block handle message.
void ascii_serial_com_register_block_init(ascii_serial_com_register_block *register_block_state, REGTYPE *block, uint16_t n_regs)
ASCII Serial Com Register Block init.
ASCII Serial Com Register Block.
size_t circular_buffer_get_size_uint8(const circular_buffer_uint8 *circ_buf)
circular buffer get number of elements
void circular_buffer_clear_uint8(circular_buffer_uint8 *circ_buf)
circular buffer clear
ASCII Serial Com Interface State struct.
ASCII Serial Com Register Block State struct.
circular buffer struct