51 lines
1.0 KiB
C++
51 lines
1.0 KiB
C++
#pragma once
|
|
#include "mcp2521_toplevel.hpp"
|
|
|
|
typedef void (*rx_handler)(uint8_t *data, uint8_t length, void *arg);
|
|
|
|
enum CANTP_FRAME_TYPE {
|
|
SINGLE_FRAME = 0b00,
|
|
FIRST_FRAME = 0b01,
|
|
CONSECUTIVE_FRAME = 0b10,
|
|
FLOW_CONTROL = 0b11
|
|
};
|
|
|
|
enum CANTP_FLOW_STATUS {
|
|
CLEAR_TO_SEND = 0b0000,
|
|
WAIT = 0b0001,
|
|
OVERLOAD = 0b0010
|
|
};
|
|
|
|
enum CAN_MULTI_FRAME_STATES {
|
|
WAITING_FOR_FIRST_FRAME,
|
|
WAITING_FOR_CONSECUTIVE_FRAME,
|
|
}
|
|
|
|
class SocketCANTP {
|
|
private:
|
|
rx_handler userHandler;
|
|
void *userArg;
|
|
|
|
MCP2521 *mcp2521;
|
|
uint32_t address;
|
|
bool is_extended;
|
|
|
|
uint8_t rxBuffer[4096];
|
|
uint8_t txBuffer[4096];
|
|
|
|
size_t rxLength;
|
|
|
|
int consecitonFrameCounter;
|
|
uint8_t blockSizes;
|
|
|
|
protected:
|
|
void sendFlowControl(CANTP_FLOW_STATUS status, uint8_t blockSize, uint8_t separationTime);
|
|
|
|
public:
|
|
SocketCANTP(MCP2521 *mcp2521, uint32_t address, bool is_extended, uint8_t blockSizes);
|
|
|
|
void send(uint8_t *data, uint8_t length);
|
|
void register_rx_handler(rx_handler handler, void *arg);
|
|
|
|
void onRxHandler();
|
|
} |