Dawn Framework 1.0
Universal data acquisition framework for embedded systems
isotp.hxx
1// dawn/include/dawn/proto/can/isotp.hxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#pragma once
7
8#include <cstddef>
9#include <cstdint>
10
11namespace dawn
12{
13namespace porting
14{
15struct canmsg_s;
16} // namespace porting
17} // namespace dawn
18
19namespace dawn
20{
31class CIsoTp
32{
33public:
34 // ISO-TP frame type masks.
35 static constexpr uint8_t FRAME_TYPE_MASK = 0xF0;
36 static constexpr uint8_t FRAME_SF = 0x00;
37 static constexpr uint8_t FRAME_FF = 0x10;
38 static constexpr uint8_t FRAME_CF = 0x20;
39 static constexpr uint8_t FRAME_FC = 0x30;
41 // ISO-TP sequence number mask and limit.
42
43 static constexpr uint8_t SEQ_MASK = 0x0F;
44 static constexpr uint8_t SEQ_MAX = 0x10;
45
46 struct State
47 {
48 size_t offset;
49 uint8_t seq_next;
50 size_t total_len;
51 bool active;
52 uint64_t timestamp;
53 };
54
55 static void initState(State &state);
56 static void resetState(State &state);
57 static uint8_t getFrameType(uint8_t pci);
58 static uint8_t getSequence(uint8_t pci);
59 static uint8_t nextSequence(uint8_t seq);
60
61 static int handleFirstFrame(const porting::canmsg_s &msg,
62 State &state,
63 void *data_buf,
64 size_t buf_size);
65
66 static int handleConsecutiveFrame(const porting::canmsg_s &msg,
67 State &state,
68 void *data_buf,
69 size_t buf_size);
70
71 static bool isComplete(const State &state);
72 static bool isTimeout(const State &state, uint64_t now, uint64_t timeout);
73
80 static int receive(const porting::canmsg_s &msg,
81 State &state,
82 void *data_buf,
83 size_t buf_size,
84 uint64_t now,
85 uint64_t timeout);
86
93 static int receiveCustom(const porting::canmsg_s &msg,
94 State &state,
95 void *data_buf,
96 size_t buf_size,
97 uint8_t seg_no,
98 bool seg_last,
99 uint64_t now,
100 uint64_t timeout);
101};
102
103} // namespace dawn
ISO-TP (ISO 15765-2) transport protocol helper.
Definition isotp.hxx:32
static uint8_t FRAME_FC
Flow Control (0x3N)
Definition isotp.hxx:39
static int receiveCustom(const porting::canmsg_s &msg, State &state, void *data_buf, size_t buf_size, uint8_t seg_no, bool seg_last, uint64_t now, uint64_t timeout)
Process incoming Custom Segmented frame (Dawn specific).
Definition isotp.cxx:242
static uint8_t FRAME_SF
Single Frame (0x0N)
Definition isotp.hxx:36
static int receive(const porting::canmsg_s &msg, State &state, void *data_buf, size_t buf_size, uint64_t now, uint64_t timeout)
Process incoming ISO-TP frame.
Definition isotp.cxx:178
static uint8_t FRAME_CF
Consecutive Frame (0x2N)
Definition isotp.hxx:38
static uint8_t FRAME_FF
First Frame (0x1N)
Definition isotp.hxx:37
Out-of-tree user-extension hooks for Dawn.
Definition bindable.hxx:13
Common CAN message format for chardev and socketCAN.
Definition can.hxx:20