@@ -198,35 +198,41 @@ static int update_cf_length(uint8_t* cf_pdu, uint64_t length)
198
198
}
199
199
200
200
static int prepare_acf_packet (uint8_t * acf_pdu ,
201
- struct canfd_frame frame ) {
201
+ frame_t frame ) {
202
202
203
203
int processedBytes ;
204
204
struct timespec now ;
205
205
Avtp_Can_t * pdu = (Avtp_Can_t * ) acf_pdu ;
206
+ canid_t can_id ;
206
207
207
208
// Clear bits
208
209
memset (pdu , 0 , AVTP_CAN_HEADER_LEN );
209
210
210
211
// Prepare ACF PDU for CAN
211
212
Avtp_Can_Init (pdu );
212
213
clock_gettime (CLOCK_REALTIME , & now );
213
- Avtp_Can_SetField (pdu , AVTP_CAN_FIELD_MESSAGE_TIMESTAMP ,
214
+ Avtp_Can_SetField (pdu , AVTP_CAN_FIELD_MESSAGE_TIMESTAMP ,
214
215
(uint64_t )now .tv_nsec + (uint64_t )(now .tv_sec * 1e9 ));
215
216
Avtp_Can_SetField (pdu , AVTP_CAN_FIELD_MTV , 1U );
216
217
217
218
// Set required CAN Flags
218
- Avtp_Can_SetField (pdu , AVTP_CAN_FIELD_RTR , frame .can_id & CAN_RTR_FLAG );
219
- Avtp_Can_SetField (pdu , AVTP_CAN_FIELD_EFF , frame .can_id & CAN_EFF_FLAG );
219
+ can_id = (can_variant == AVTP_CAN_FD ) ? frame .fd .can_id : frame .cc .can_id ;
220
+ Avtp_Can_SetField (pdu , AVTP_CAN_FIELD_RTR , can_id & CAN_RTR_FLAG );
221
+ Avtp_Can_SetField (pdu , AVTP_CAN_FIELD_EFF , can_id & CAN_EFF_FLAG );
220
222
221
223
if (can_variant == AVTP_CAN_FD ) {
222
- Avtp_Can_SetField (pdu , AVTP_CAN_FIELD_BRS , frame .flags & CANFD_BRS );
223
- Avtp_Can_SetField (pdu , AVTP_CAN_FIELD_FDF , frame .flags & CANFD_FDF );
224
- Avtp_Can_SetField (pdu , AVTP_CAN_FIELD_ESI , frame .flags & CANFD_ESI );
224
+ Avtp_Can_SetField (pdu , AVTP_CAN_FIELD_BRS , frame .fd . flags & CANFD_BRS );
225
+ Avtp_Can_SetField (pdu , AVTP_CAN_FIELD_FDF , frame .fd . flags & CANFD_FDF );
226
+ Avtp_Can_SetField (pdu , AVTP_CAN_FIELD_ESI , frame .fd . flags & CANFD_ESI );
225
227
}
226
228
227
229
// Copy payload to ACF CAN PDU
228
- processedBytes = Avtp_Can_SetPayload (pdu , frame .can_id & CAN_EFF_MASK , frame .data ,
229
- frame .len , can_variant );
230
+ if (can_variant == AVTP_CAN_FD )
231
+ processedBytes = Avtp_Can_SetPayload (pdu , frame .fd .can_id & CAN_EFF_MASK , frame .fd .data ,
232
+ frame .fd .len , can_variant );
233
+ else
234
+ processedBytes = Avtp_Can_SetPayload (pdu , frame .cc .can_id & CAN_EFF_MASK , frame .cc .data ,
235
+ frame .cc .len , can_variant );
230
236
231
237
return processedBytes ;
232
238
}
@@ -239,7 +245,7 @@ int main(int argc, char *argv[])
239
245
struct sockaddr_in sk_udp_addr ;
240
246
uint8_t pdu [MAX_PDU_SIZE ];
241
247
uint16_t pdu_length , cf_length ;
242
- struct canfd_frame can_frame ;
248
+ frame_t can_frame ;
243
249
244
250
argp_parse (& argp , argc , argv , 0 , NULL , NULL );
245
251
@@ -254,7 +260,7 @@ int main(int argc, char *argv[])
254
260
} else {
255
261
fd = create_talker_socket (priority );
256
262
if (fd < 0 ) return fd ;
257
- res = setup_socket_address (fd , ifname , macaddr ,
263
+ res = setup_socket_address (fd , ifname , macaddr ,
258
264
ETH_P_TSN , & sk_ll_addr );
259
265
}
260
266
if (res < 0 ) goto err ;
@@ -271,7 +277,7 @@ int main(int argc, char *argv[])
271
277
pdu_length = 0 ;
272
278
cf_length = 0 ;
273
279
274
- // Usage of UDP means the PDU needs a
280
+ // Usage of UDP means the PDU needs a
275
281
if (use_udp ) {
276
282
Avtp_Udp_t * udp_pdu = (Avtp_Udp_t * ) pdu ;
277
283
Avtp_Udp_SetField (udp_pdu , AVTP_UDP_FIELD_ENCAPSULATION_SEQ_NO ,
@@ -290,7 +296,11 @@ int main(int argc, char *argv[])
290
296
while (i < num_acf_msgs ) {
291
297
// Get payload -- will 'spin' here until we get the requested number
292
298
// of CAN frames.
293
- res = read (can_socket , & can_frame , sizeof (struct canfd_frame ));
299
+ if (can_variant == AVTP_CAN_FD ){
300
+ res = read (can_socket , & can_frame .fd , sizeof (struct canfd_frame ));
301
+ } else {
302
+ res = read (can_socket , & can_frame .cc , sizeof (struct can_frame ));
303
+ }
294
304
if (!res ) continue ;
295
305
296
306
uint8_t * acf_pdu = pdu + pdu_length ;
0 commit comments