@@ -64,6 +64,7 @@ void test_lin_sleep() {
64
64
TEST_ASSERT_EQUAL_MEMORY (bus_transmitted.data (), linDriver->txBuffer .data (), bus_transmitted.size ());
65
65
}
66
66
67
+ // / @brief Node Identification: Read by identifier (Spec LIN 2.2A, Page 78, Chap. 4.2.6.1)
67
68
void test_lin_getID () {
68
69
std::cout << " \n\n\n Running test: " << __FUNCTION__ << std::endl;
69
70
@@ -72,15 +73,16 @@ void test_lin_getID() {
72
73
constexpr uint16_t request_FunctionId = 0x3FFF ; // Wildcard
73
74
74
75
std::vector<uint8_t > bus_transmitted = {
75
- 0x00 , 0x55 , 0x3C , // Master Request
76
+ // Master
77
+ 0x00 , 0x55 , 0x3C , // Frame: Master Request
76
78
request_NAD, // NAD
77
- 0x06 , // 6 Byte
78
- 0xB2 , // SID
79
- 0x00 , // Cmd Identifier
79
+ 0x06 , // PCI: Single frame, 6 Byte
80
+ 0xB2 , // SID: Read by ID
81
+ 0x00 , // Identifier: Lin Product Identification
80
82
lowerByte (request_SupplierId), upperByte (request_SupplierId), // Supplier ID LSB, MSB
81
83
lowerByte (request_FunctionId), upperByte (request_FunctionId), // Function ID LSB, MSB
82
- 0x09 , // chksum
83
-
84
+ 0x09 , // Frame: Checksum
85
+ // Slave
84
86
0x00 , 0x55 , 0x7d // Request for Slave Response
85
87
};
86
88
@@ -89,32 +91,25 @@ void test_lin_getID() {
89
91
constexpr uint16_t response_supplierId = 0x2E06 ;
90
92
constexpr uint16_t response_functionId = 0x1080 ;
91
93
constexpr uint8_t response_variant = 0x56 ;
92
- struct Response {
93
- std::vector<uint8_t > head {
94
- response_NAD, // NAD
95
- 0x06 // Single Frame, 6 Bytes
96
- };
97
- std::vector<uint8_t > payload {
98
- 0xF2 , // RSID
99
- lowerByte (response_supplierId), upperByte (response_supplierId), // supplier ID, LSB MSB
100
- lowerByte (response_functionId), upperByte (response_functionId), // function ID, LSB MSB
101
- response_variant // variant
102
- };
103
- uint8_t checksum {
104
- 0xe1 // Frame Checksum
105
- };
106
- } response;
107
- linDriver->mock_Input (response.head );
108
- linDriver->mock_Input (response.payload );
109
- // no fillbytes required
110
- linDriver->mock_Input (response.checksum );
94
+ std::vector<uint8_t > response {
95
+ response_NAD, // NAD
96
+ 0x06 , // PCI: Single Frame, 6 Bytes
97
+ 0xF2 , // RSID
98
+ lowerByte (response_supplierId), upperByte (response_supplierId), // supplier ID, LSB MSB
99
+ lowerByte (response_functionId), upperByte (response_functionId), // function ID, LSB MSB
100
+ response_variant, // variant
101
+ 0xE1 // Frame Checksum
102
+ };
103
+ linDriver->mock_Input (response);
111
104
112
105
uint8_t NAD = request_NAD;
113
106
uint16_t supplierId = request_SupplierId;
114
107
uint16_t functionId = request_FunctionId;
115
108
uint8_t variant = 0 ;
116
109
bool result = linNodeConfig->readProductId (NAD, supplierId, functionId, variant);
117
110
111
+ TEST_ASSERT_TRUE (result);
112
+
118
113
TEST_ASSERT_EQUAL (response_NAD, NAD);
119
114
TEST_ASSERT_EQUAL (response_supplierId, supplierId);
120
115
TEST_ASSERT_EQUAL (response_functionId, functionId);
@@ -124,6 +119,56 @@ void test_lin_getID() {
124
119
TEST_ASSERT_EQUAL_MEMORY (bus_transmitted.data (), linDriver->txBuffer .data (), bus_transmitted.size ());
125
120
}
126
121
122
+ // / @brief Node Identification: Read by identifier (Spec LIN 2.2A, Page 78, Chap. 4.2.6.1)
123
+ void test_lin_serialNumber ()
124
+ {
125
+ std::cout << " \n\n\n Running test: " << __FUNCTION__ << std::endl;
126
+
127
+ constexpr uint8_t request_NAD = 0x7F ; // wildcard
128
+ constexpr uint16_t request_SupplierId = 0x7FFF ; // wildcard
129
+ constexpr uint16_t request_FunctionId = 0x3FFF ; // wildcard
130
+
131
+ std::vector<uint8_t > bus_transmitted = {
132
+ // Master
133
+ 0x00 , 0x55 , 0x3C , // Frame Head: Master Request
134
+ request_NAD, // NAD Wildcard
135
+ 0x06 , // PID: Single Frame, 6 Byte
136
+ 0xB2 , // SID: Read by identifier
137
+ 0x00 , // Identifier: Serial number
138
+ lowerByte (request_SupplierId), upperByte (request_SupplierId), // Supplier ID LSB, MSB
139
+ lowerByte (request_FunctionId), upperByte (request_FunctionId), // Function ID LSB, MSB
140
+ 0x09 , // Frame: Checksum
141
+
142
+ 0x00 , 0x55 , 0x7D // Frame Head: Slave Response
143
+ };
144
+
145
+ // Slave Response
146
+ constexpr uint8_t response_NAD = 0x0A ;
147
+ constexpr uint32_t response_SN = 0x76543210 ;
148
+ std::vector<uint8_t > response {
149
+ response_NAD, // <-- according to spec initial NAD will be used
150
+ 0x05 , // PCI: Single Frame, 5 Byte
151
+ 0xF2 , // RSID
152
+ 0x10 , 0x32 , 0x54 , 0x76 , // Srial Number LSB...MSB
153
+ 0xFF , // unused
154
+ 0xF0 // Frame: Checksum
155
+ };
156
+ linDriver->mock_Input (response);
157
+
158
+ uint8_t NAD = request_NAD;
159
+ uint16_t supplierId = request_SupplierId;
160
+ uint16_t functionId = request_FunctionId;
161
+ auto result = linNodeConfig->readSerialNumber (NAD, supplierId, functionId);
162
+
163
+ TEST_ASSERT_EQUAL (response_NAD, NAD); // <-- answer will follow on old NAD
164
+
165
+ TEST_ASSERT_TRUE (result);
166
+ TEST_ASSERT_EQUAL_UINT32 (response_SN, result.value ());
167
+
168
+ TEST_ASSERT_EQUAL (bus_transmitted.size (), linDriver->txBuffer .size ());
169
+ TEST_ASSERT_EQUAL_MEMORY (bus_transmitted.data (), linDriver->txBuffer .data (), bus_transmitted.size ());
170
+ }
171
+
127
172
// / @brief Node Configuration Service: Assign NAD (Spec LIN 2.2A, Page 74, Chap. 4.2.5.1)
128
173
void test_lin_assignNAD_ok ()
129
174
{
@@ -151,7 +196,7 @@ void test_lin_assignNAD_ok()
151
196
// Slave Response
152
197
std::vector<uint8_t > response {
153
198
request_NAD, // initial NAD <-- according to spec initial NAD will be used
154
- 0x01 , // PCI: Single Frame, 1 Bytes
199
+ 0x01 , // PCI: Single Frame, 1 Byte
155
200
0xF0 , // RSID
156
201
0xFF , 0xFF , 0xFF , 0xFF , 0xFF , // 5x unused
157
202
0x8E // Frame Checksum
@@ -200,7 +245,7 @@ void test_lin_conditionalChangeNAD_ok()
200
245
// Slave Response
201
246
std::vector<uint8_t > response {
202
247
request_NAD_new, // NAD <-- according to spec: new NAD will be used
203
- 0x01 , // PCI: Single Frame, 1 Bytes
248
+ 0x01 , // PCI: Single Frame, 1 Byte
204
249
0xF3 , // RSID
205
250
0xFF , 0xFF , 0xFF , 0xFF , 0xFF , // 5x unused
206
251
0xEF // Frame Checksum
@@ -240,7 +285,7 @@ void test_lin_saveConfig_ok()
240
285
// Slave Response
241
286
std::vector<uint8_t > response {
242
287
request_NAD, // NAD
243
- 0x01 , // Single Frame, 1 Bytes
288
+ 0x01 , // Single Frame, 1 Byte
244
289
0xF6 , // RSID = Save Config
245
290
0xFF , 0xFF , 0xFF , 0xFF , 0xFF , // 5x unused
246
291
0xA1 // Frame Checksum
@@ -289,7 +334,7 @@ void test_lin_AssignFrameIdRange_ok()
289
334
// Slave Response
290
335
std::vector<uint8_t > response {
291
336
request_NAD, // NAD
292
- 0x01 , // PID: Single Frame, 1 Bytes
337
+ 0x01 , // PID: Single Frame, 1 Byte
293
338
0xF7 , // RSID: Assign Frame ID Range
294
339
0xFF , 0xFF , 0xFF , 0xFF , 0xFF , // 5x unused
295
340
0xA0 // Frame Checksum
@@ -313,6 +358,7 @@ int main() {
313
358
RUN_TEST (test_lin_wakeup);
314
359
RUN_TEST (test_lin_sleep);
315
360
RUN_TEST (test_lin_getID);
361
+ RUN_TEST (test_lin_serialNumber);
316
362
RUN_TEST (test_lin_assignNAD_ok);
317
363
RUN_TEST (test_lin_conditionalChangeNAD_ok);
318
364
RUN_TEST (test_lin_saveConfig_ok);
0 commit comments