Skip to content

Commit fa76f07

Browse files
authored
inject data in response
1 parent f985aca commit fa76f07

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/VS2/PacketVS2.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ uint8_t PacketVS2::dataLength() const {
128128
}
129129

130130
const uint8_t* PacketVS2::data() const {
131-
if (functionCode() == FunctionCode::WRITE) return nullptr;
132131
return &_buffer[VS2_DATA];
133132
}
134133

test/test_ParserVS2/test_ParserVS2.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ void test_ok_writeresponse() {
100100
0x02, // flags: id + function code (0 + write)
101101
0x23, // address 1
102102
0x23, // address 2
103-
0x01, // payload length
104-
0x4F // cs
103+
0x02, // payload length
104+
0x50 // cs
105105
};
106106
const std::size_t length = 8;
107107
const std::size_t packetLength = 6;
@@ -116,6 +116,11 @@ void test_ok_writeresponse() {
116116
}
117117
}
118118

119+
// inject data into packet
120+
const uint8_t data[2] = {0x01, 0x02};
121+
TEST_ASSERT(_parser.packet().setLength(_parser.packet().length() + _parser.packet().dataLength()));
122+
std::memcpy(&_parser.packet()[VS2_DATA], data, _parser.packet().dataLength());
123+
119124
TEST_ASSERT_EQUAL(ParserResult::COMPLETE, result);
120125
TEST_ASSERT_EQUAL_UINT(length, bytesRead);
121126
TEST_ASSERT_EQUAL_UINT8(packetLength, parser.packet().length());
@@ -124,7 +129,7 @@ void test_ok_writeresponse() {
124129
TEST_ASSERT_EQUAL_UINT8(FunctionCode::WRITE, parser.packet().functionCode());
125130
TEST_ASSERT_EQUAL_UINT16(0x2323, parser.packet().address());
126131
TEST_ASSERT_EQUAL_UINT8(0x01, parser.packet().dataLength());
127-
TEST_ASSERT_NULL(parser.packet().data());
132+
TEST_ASSERT_EQUAL_UINT8_ARRAY(data, parser.packet().data(), 2);
128133
}
129134

130135
void test_spuriousbytes() {

0 commit comments

Comments
 (0)