INFM HIL Interface
Interface between Artery simulation and DuTs
CANConnector.h
1
26#ifndef SIM_TO_DUT_INTERFACE_CANCONNECTOR_H
27#define SIM_TO_DUT_INTERFACE_CANCONNECTOR_H
28
29// Project includes
30#include "../DuTConnector.h"
31#include "InterfaceIndexIO.h"
32#include "CANConnectorCodec.h"
33#include "CANConnectorConfig.h"
34#include "CANConnectorCodecFactory.h"
35#include "../../Interface_Logger/InterfaceLogger.h"
36
37// System includes
38#include <thread>
39#include <iostream>
40#include <linux/can.h>
41#include <linux/can/bcm.h>
42#include <boost/asio.hpp>
43#include <boost/make_shared.hpp>
44#include <boost/system/error_code.hpp>
45
51#define MAXFRAMES 256
52
59 struct bcm_msg_head msg_head;
60 struct can_frame canFrame[1];
61};
62
69 struct bcm_msg_head msg_head;
70 struct canfd_frame canfdFrame[1];
71};
72
79 struct bcm_msg_head msg_head;
80 struct can_frame canFrames[MAXFRAMES];
81};
82
89 struct bcm_msg_head msg_head;
90 struct canfd_frame canfdFrames[MAXFRAMES];
91};
92
94
101 class CANConnector : public DuTConnector {
102
103 public:
104
113 CANConnector(std::shared_ptr<SharedQueue<SimEvent>> queueDuTToSim, const CANConnectorConfig &config);
114
120
127
133 void handleEventSingle(const SimEvent &event) override;
134
135 private:
136
143 boost::asio::generic::datagram_protocol::socket createBcmSocket(const CANConnectorConfig &canConfig);
144
149 void startProcessing();
150
154 void stopProcessing();
155
159 void ioContextThreadFunction(const boost::shared_ptr<boost::asio::io_context> &context);
160
166 void receiveOnSocket();
167
176 void handleReceivedData(const bcm_msg_head *head, void *frames, uint32_t nframes, bool isCANFD);
177
185 void handleRxChanged(const bcm_msg_head *head, void *frames, bool isCANFD);
186
193 void txSendSingleFrame(struct canfd_frame frame, bool isCANFD);
194
202 void txSendMultipleFrames(struct canfd_frame frames[], int nframes, bool isCANFD);
203
214 void txSetupSingleFrame(struct canfd_frame frame, uint32_t count, struct bcm_timeval ival1,
215 struct bcm_timeval ival2, bool isCANFD);
216
234 void txSetupMultipleFrames(struct canfd_frame frames[], int nframes, uint32_t count[],
235 struct bcm_timeval ival1[], struct bcm_timeval ival2[], bool isCANFD);
236
253 void txSetupSequence(struct canfd_frame frames[], int nframes, uint32_t count, struct bcm_timeval ival1,
254 struct bcm_timeval ival2, bool isCANFD);
255
264 void txSetupUpdateSingleFrame(struct canfd_frame frame, bool isCANFD, bool announce);
265
274 void txSetupUpdateMultipleFrames(struct canfd_frame frames[], int nframes, bool isCANFD, bool announce);
275
284 void txDelete(canid_t canID, bool isCANFD);
285
293 void rxSetupCanID(canid_t canID, bool isCANFD);
294
303 void rxSetupMask(canid_t canID, struct canfd_frame mask, bool isCANFD);
304
311 void rxDelete(canid_t canID, bool isCANFD);
312
319 static std::string convertCanIdToHex(canid_t canID);
320
321 boost::shared_ptr<boost::asio::io_context> ioContext;
322 boost::asio::generic::datagram_protocol::socket bcmSocket;
323 std::array<std::uint8_t, sizeof(struct bcmMsgMultipleFramesCanFD)> rxBuffer{0};
324 std::thread ioContextThread;
325 CANConnectorConfig config;
326 CANConnectorCodec *codec;
327 std::map<std::string, bool> isSetup;
328 };
329
330}
331
332#endif //SIM_TO_DUT_INTERFACE_CANCONNECTOR_H
A thread save shared queue to communicate between multiple threads. The queue is a FIFO queue.
Definition: SharedQueue.h:40
Event object used to communicate between simulation and DuTs.
Definition: SimEvent.h:47
Some basic information about the connector device.
Definition: ConnectorInfo.h:37
Connector implementing all kinds of DuT devices.
Definition: DuTConnector.h:48
The CAN Connector Codec defines the interface that each codec implementation must fulfill.
Definition: CANConnectorCodec.h:44
The config for the CAN Connector.
Definition: CANConnectorConfig.h:47
The Connector enables the communication over a CAN/CANFD interface. It builds upon the socketCAN BCM ...
Definition: CANConnector.h:101
ConnectorInfo getConnectorInfo() override
Definition: CANConnector.cpp:172
~CANConnector()
Definition: CANConnector.cpp:89
CANConnector(std::shared_ptr< SharedQueue< SimEvent > > queueDuTToSim, const CANConnectorConfig &config)
Definition: CANConnector.cpp:31
void handleEventSingle(const SimEvent &event) override
Definition: CANConnector.cpp:878
Definition: CANConnector.cpp:29
Struct for a BCM message with multiple CANFD frames.
Definition: CANConnector.h:88
Struct for a BCM message with multiple CAN frames.
Definition: CANConnector.h:78
Struct for a BCM message with a single CANFD frame.
Definition: CANConnector.h:68
Struct for a BCM message with a single CAN frame.
Definition: CANConnector.h:58