@@ -54,7 +54,7 @@ void test_ok_request() {
54
54
TEST_ASSERT_EQUAL_UINT8 (0x02 , parser.packet ().dataLength ());
55
55
}
56
56
57
- void test_ok_response () {
57
+ void test_ok_readresponse () {
58
58
const uint8_t stream[] = {
59
59
0x41 , // start byte
60
60
0x07 , // length
@@ -81,7 +81,7 @@ void test_ok_response() {
81
81
}
82
82
}
83
83
84
- TEST_ASSERT_EQUAL (ParserResult::COMPLETE, result);
84
+ TEST_ASSERT_EQUAL (ParserResult::COMPLETE, result);
85
85
TEST_ASSERT_EQUAL_UINT (length, bytesRead);
86
86
TEST_ASSERT_EQUAL_UINT8 (packetLength, parser.packet ().length ());
87
87
TEST_ASSERT_EQUAL_UINT8 (PacketType::RESPONSE, parser.packet ().packetType ());
@@ -92,6 +92,41 @@ void test_ok_response() {
92
92
TEST_ASSERT_EQUAL_UINT8_ARRAY (data, parser.packet ().data (), 2 );
93
93
}
94
94
95
+ void test_ok_writeresponse () {
96
+ const uint8_t stream[] = {
97
+ 0x41 , // start byte
98
+ 0x05 , // length
99
+ 0x01 , // packet type (response)
100
+ 0x02 , // flags: id + function code (0 + write)
101
+ 0x23 , // address 1
102
+ 0x23 , // address 2
103
+ 0x01 , // payload length
104
+ 0x4F // cs
105
+ };
106
+ const std::size_t length = 8 ;
107
+ const std::size_t packetLength = 6 ;
108
+
109
+ std::size_t bytesRead = 0 ;
110
+ ParserResult result = ParserResult::ERROR;
111
+
112
+ while (bytesRead < length) {
113
+ result = parser.parse (stream[bytesRead++]);
114
+ if (result != ParserResult::CONTINUE) {
115
+ break ;
116
+ }
117
+ }
118
+
119
+ TEST_ASSERT_EQUAL (ParserResult::COMPLETE, result);
120
+ TEST_ASSERT_EQUAL_UINT (length, bytesRead);
121
+ TEST_ASSERT_EQUAL_UINT8 (packetLength, parser.packet ().length ());
122
+ TEST_ASSERT_EQUAL_UINT8 (PacketType::RESPONSE, parser.packet ().packetType ());
123
+ TEST_ASSERT_EQUAL_UINT8 (0x00 , parser.packet ().id ());
124
+ TEST_ASSERT_EQUAL_UINT8 (FunctionCode::WRITE, parser.packet ().functionCode ());
125
+ TEST_ASSERT_EQUAL_UINT16 (0x2323 , parser.packet ().address ());
126
+ TEST_ASSERT_EQUAL_UINT8 (0x01 , parser.packet ().dataLength ());
127
+ TEST_ASSERT_NULL (parser.packet ().data ());
128
+ }
129
+
95
130
void test_spuriousbytes () {
96
131
const uint8_t stream[] = {
97
132
0x05 ,
@@ -251,7 +286,8 @@ void test_invalidChecksum() {
251
286
int main () {
252
287
UNITY_BEGIN ();
253
288
RUN_TEST (test_ok_request);
254
- RUN_TEST (test_ok_response);
289
+ RUN_TEST (test_ok_readresponse);
290
+ RUN_TEST (test_ok_writeresponse);
255
291
RUN_TEST (test_spuriousbytes);
256
292
RUN_TEST (test_invalidLength);
257
293
RUN_TEST (test_invalidPacketType);
0 commit comments