diff --git a/firmware/config/boards/hellen/small-can-board/meta-info-small-can-board.env b/firmware/config/boards/hellen/small-can-board/meta-info-small-can-board.env index f026155432..6d0da745ca 100644 --- a/firmware/config/boards/hellen/small-can-board/meta-info-small-can-board.env +++ b/firmware/config/boards/hellen/small-can-board/meta-info-small-can-board.env @@ -1,5 +1,6 @@ SHORT_BOARD_NAME=small-can-board PROJECT_CPU=ARCH_STM32F4 +# see '*OPENBLT_CAN*' in board.mk for CAN BLT USE_OPENBLT=yes # reminder that 'only:small-can-board' in commit message is the way to definitely build a specific target! SKIP_RATE=50 diff --git a/firmware/config/boards/hellen/small-can-board/prepend.txt b/firmware/config/boards/hellen/small-can-board/prepend.txt index e977cf5dd4..bad86583a0 100644 --- a/firmware/config/boards/hellen/small-can-board/prepend.txt +++ b/firmware/config/boards/hellen/small-can-board/prepend.txt @@ -2,7 +2,8 @@ - +#define CAN_ECU_SERIAL_RX_ID 0x300100 +#define CAN_ECU_SERIAL_TX_ID 0x300102 #define ts_show_egt false #define ts_show_engine_control false @@ -12,4 +13,4 @@ #define show_small_can_board_presets true -!#define LUA_SCRIPT_SIZE 30000 \ No newline at end of file +!#define LUA_SCRIPT_SIZE 30000 diff --git a/firmware/console/binary/serial_can.cpp b/firmware/console/binary/serial_can.cpp index faa0bd8071..7b20fa7e39 100644 --- a/firmware/console/binary/serial_can.cpp +++ b/firmware/console/binary/serial_can.cpp @@ -39,8 +39,8 @@ static CanTsListener listener; int CanStreamerState::sendFrame(const IsoTpFrameHeader & header, const uint8_t *data, int num, can_sysinterval_t timeout) { int dlc = 8; // standard 8 bytes - CanTxMessage txmsg(CanCategory::SERIAL, CAN_ECU_SERIAL_TX_ID, dlc, 0, false); - + CanTxMessage txmsg(CanCategory::SERIAL, CAN_ECU_SERIAL_TX_ID, dlc, /*bus*/0, IS_EXT_RANGE_ID(CAN_ECU_SERIAL_TX_ID)); + // fill the frame data according to the CAN-TP protocol (ISO 15765-2) txmsg[0] = (uint8_t)((header.frameType & 0xf) << 4); int offset, maxNumBytes; @@ -73,7 +73,7 @@ int CanStreamerState::sendFrame(const IsoTpFrameHeader & header, const uint8_t * // bad frame type return 0; } - + int numBytes = minI(maxNumBytes, num); // copy the contents if (data != nullptr) { @@ -141,7 +141,7 @@ int CanStreamerState::receiveFrame(CANRxFrame *rxmsg, uint8_t *buf, int num, can memcpy(tmpRxBuf + sizeof(uint16_t), srcBuf, numBytesAvailable); // copy the crc to the end memcpy(tmpRxBuf + sizeof(uint16_t) + numBytesAvailable, crcBuffer, sizeof(crcBuffer)); - + // use the reconstructed tmp buffer as a source buffer srcBuf = tmpRxBuf; // we added the 16-bit size & 32-bit crc bytes @@ -296,7 +296,7 @@ can_msg_t CanStreamerState::streamAddToTxTimeout(size_t *np, const uint8_t *txbu offset += numBytesToAdd; numBytes -= numBytesToAdd; } - + if (engineConfiguration->verboseIsoTp) { PRINT("*** INFO: streamAddToTxTimeout remaining goes to buffer %d" PRINT_EOL, numBytes); } @@ -318,7 +318,7 @@ can_msg_t CanStreamerState::streamFlushTx(can_sysinterval_t timeout) { //warning(ObdCode::CUSTOM_ERR_CAN_COMMUNICATION, "CAN sendDataTimeout() problems"); } txFifoBuf.clear(); - + return CAN_MSG_OK; } diff --git a/firmware/controllers/can/can.h b/firmware/controllers/can/can.h index 3c9a19a510..e4a3cae0b5 100644 --- a/firmware/controllers/can/can.h +++ b/firmware/controllers/can/can.h @@ -43,6 +43,9 @@ enum class CanInterval : uint16_t { _MAX_Cycle = _1000ms, }; +// 11 bit (CAN 2.0A) +#define IS_EXT_RANGE_ID(id) ((id) >= 2048) + class CanListener; class CanSensorBase;