CAN w/o isotp

This commit is contained in:
CarlWachter
2024-04-30 15:27:01 +02:00
parent a6704f4c45
commit 21e50a5ed1
2 changed files with 3 additions and 165 deletions

View File

@@ -10,8 +10,6 @@
#include <sta/debug/debug.hpp>
#include <sta/bus/can/subscribable.hpp>
#include <sta/lang.hpp>
#include <sta/proto/isotp/transmitter.hpp>
#include <sta/proto/isotp/receiver.hpp>
#include <sta/rtos/defs.hpp>
#include <sta/rtos/system/events.hpp>
#include <sta/devices/stm32/hal.hpp>
@@ -62,12 +60,9 @@ namespace debug
namespace sta
{
AlpakaCanBus::AlpakaCanBus(CanController * controller, TimeMsFn timeMs, SysMsgHandler sysMsgHandler, DataMsgHandler dataMsgHandler)
: controller_{controller}, tx_{controller, timeMs}, rx_{controller, timeMs}, handleSysMsg_{sysMsgHandler}, handleDataMsg_{dataMsgHandler}
AlpakaCanBus::AlpakaCanBus(CanController * controller, TimeMsFn timeMs)
: controller_{controller}
{
STA_ASSERT(handleSysMsg_ != nullptr);
STA_ASSERT(handleDataMsg_ != nullptr);
setupSubscriptions();
}
@@ -83,91 +78,6 @@ namespace sta
controller_->sendFrame(header, msg.payload);
}
void AlpakaCanBus::send(const CanDataMsg & msg)
{
CanFrameId frameID;
frameID.format = static_cast<CanIdFormat>(msg.header.format);
frameID.sid = msg.header.sid;
frameID.eid = msg.header.eid;
// Start transmission via ISO-TP
tx_.send(frameID, msg.payload, msg.header.payloadLength);
}
void AlpakaCanBus::processTx()
{
tx_.process();
}
void AlpakaCanBus::processRx()
{
for (auto fifo : controller_->getPendingRxFifos())
{
CanRxHeader header;
uint8_t payload[STA_RTOS_CAN_BUS_MAX_PAYLOAD_SIZE];
if (controller_->receiveFrame(fifo, &header, payload))
{
//debug::displayFrameUART(frame);
// Forward frame to callback
switch (fifo)
{
case FIFO_SYS:
handleSysMsg_(header, payload);
break;
case FIFO_DATA:
receiveDataFrame(header, payload);
break;
default:
STA_ASSERT(false);
}
}
}
}
void AlpakaCanBus::showStatistics()
{
STA_DEBUG_PRINTLN();
STA_DEBUG_PRINTLN("# ######################");
STA_DEBUG_PRINTLN("# ## ISOTP statistics ##");
STA_DEBUG_PRINTLN("# ######################");
STA_DEBUG_PRINTLN("#");
const auto & txStats = tx_.stats();
STA_DEBUG_PRINTLN("# Transmitter");
STA_DEBUG_PRINT("# messages: ");
STA_DEBUG_PRINTLN(txStats.messages);
STA_DEBUG_PRINT("# blocks: ");
STA_DEBUG_PRINTLN(txStats.blocks);
STA_DEBUG_PRINT("# frames: ");
STA_DEBUG_PRINTLN(txStats.frames);
STA_DEBUG_PRINT("# timeouts: ");
STA_DEBUG_PRINTLN(txStats.timeouts);
STA_DEBUG_PRINTLN("#");
const auto & rxStats = rx_.stats();
STA_DEBUG_PRINTLN("# Receiver");
STA_DEBUG_PRINT("# messages: ");
STA_DEBUG_PRINTLN(rxStats.messages);
STA_DEBUG_PRINT("# blocks: ");
STA_DEBUG_PRINTLN(rxStats.blocks);
STA_DEBUG_PRINT("# frames: ");
STA_DEBUG_PRINTLN(rxStats.frames);
STA_DEBUG_PRINT("# timeouts: ");
STA_DEBUG_PRINTLN(rxStats.timeouts);
STA_DEBUG_PRINT("# flow control errors: ");
STA_DEBUG_PRINTLN(rxStats.flowErrors);
STA_DEBUG_PRINT("# overflows: ");
STA_DEBUG_PRINTLN(rxStats.overflows);
STA_DEBUG_PRINTLN();
}
void AlpakaCanBus::setupSubscriptions()
{
// Make sure to receive all messages
@@ -192,32 +102,6 @@ namespace sta
filter.fifo = FIFO_DATA;
controller_->configureFilter(FIFO_DATA, filter, true);
}
void AlpakaCanBus::receiveDataFrame(const CanRxHeader & header, const uint8_t * payload)
{
// Write frame payload to DebugSerial
STA_DEBUG_PRINTLN("[event] RX data frame");
debug::printPayloadHex(payload, header.payloadLength);
// Process RX frame
auto handle = rx_.processFrame(header, payload);
if (handle != IsotpReceiver::INVALID_HANDLE)
{
// Get message if completed
IsotpMessage msg;
if (rx_.getMessage(handle, &msg))
{
handleDataMsg_(msg);
}
// Handle FC responses
rx_.processFC(handle);
}
// Process TX frame
tx_.processFrame(header, payload);
}
} // namespace sta
#endif // STA_CAN_BUS_ENABLE