26 #include "xcp_config.h" 28 #if XCP_TRANSPORT_LAYER == XCP_ON_CAN 39 static bool connected =
false;
41 void XcpTl_Init(
void) {
46 Serial.println(
"Starting Blueparrot XCP...");
49 if (!CAN.begin(250E3)) {
50 Serial.println(
"Starting CAN failed!");
57 void XcpTl_DeInit(
void) {}
59 void *XcpTl_Thread(
void *param) {
60 XCP_FOREVER { XcpTl_MainFunction(); }
64 void XcpTl_MainFunction(
void) {
65 if (XcpTl_FrameAvailable(0, 1000) > 0) {
70 void XcpTl_RxHandler(
void) {
71 static byte buffer[64];
74 digitalWrite(LED_BUILTIN, HIGH);
75 Serial.print(
"Received ");
77 dlc = CAN.packetDlc();
78 if (CAN.packetExtended()) {
79 Serial.print(
"extended ");
82 if (CAN.packetRtr()) {
87 Serial.print(
"packet with id 0x");
88 Serial.print(CAN.packetId(), HEX);
90 if (CAN.packetRtr()) {
91 Serial.print(
" and requested length ");
95 Serial.print(
" and length ");
98 int actual = CAN.readBytes(buffer, dlc);
99 Serial.print(
"actual length: ");
100 Serial.print(actual);
106 XcpUtl_MemCopy(Xcp_CtoIn.data, &buffer, dlc);
108 Xcp_DispatchCommand(&Xcp_CtoIn);
117 digitalWrite(LED_BUILTIN, LOW);
120 void XcpTl_TxHandler(
void) {}
122 int16_t XcpTl_FrameAvailable(uint32_t sec, uint32_t usec) {
124 XCP_UNREFERENCED_PARAMETER(sec);
125 XCP_UNREFERENCED_PARAMETER(usec);
127 res = CAN.parsePacket();
129 Serial.print(
"Frames avail!!!");
136 void XcpTl_Send(uint8_t
const *buf, uint16_t len) {
139 can_id = XCP_ON_CAN_STRIP_IDENTIFIER(XCP_ON_CAN_OUTBOUND_IDENTIFIER);
141 if (XCP_ON_CAN_IS_EXTENDED_IDENTIFIER(XCP_ON_CAN_OUTBOUND_IDENTIFIER)) {
142 CAN.beginExtendedPacket(can_id, len);
144 CAN.beginPacket(can_id);
151 void XcpTl_SaveConnection(
void) { connected = XCP_TRUE; }
153 void XcpTl_ReleaseConnection(
void) { connected = XCP_FALSE; }
155 bool XcpTl_VerifyConnection(
void) {
return connected; }
157 void XcpTl_PrintConnectionInformation(
void) {}