feat: handleSysMessage checks allows user to overwrite CAN system behavior

This commit is contained in:
CarlWachter
2024-08-23 15:59:35 +02:00
committed by carlwachter
parent d028ecef74
commit dd4c5f34a2
2 changed files with 29 additions and 17 deletions

View File

@@ -63,17 +63,15 @@ namespace sta
sysMsg = *canBusSysQueueBuffer_[i];
canBusSysQueueBuffer_[i] = nullptr;
// Append to the correct thread's queue
for (std::shared_ptr<TacosThread> thread : Manager::instance()->getActiveThreads()){
if (thread->getCanID() == sysMsg.header.sid){
thread->CAN_queue_.put(sysMsg);
break;
}
}
if (!handleSysMessage(sysMsg.header, sysMsg.payload)){
if(sysMsg.header.sid == STA_TACOS_CAN_BUS_SYS_MSG_ID){
// Handle system message
handleSysMessage(sysMsg.header, sysMsg.payload);
// Append to the correct thread's queue
for (std::shared_ptr<TacosThread> thread : Manager::instance()->getActiveThreads()){
if (thread->getCanID() == sysMsg.header.sid){
thread->CAN_queue_.put(sysMsg);
break;
}
}
}
}
}
@@ -148,15 +146,22 @@ namespace sta {
namespace tacos
{
void handleSysMessage(CanMsgHeader & header, uint8_t * payload)
STA_WEAK
bool handleSysMessage(CanMsgHeader & header, uint8_t * payload)
{
// This is a weak function that can be overridden by the user,
// if they want to handle system messages in a different way, i.e. ignore them
STA_ASSERT(header.payloadLength == 2);
if(header.sid == 0x0){
STA_ASSERT(header.payloadLength == 2);
// First byte of payload is the origin state, second byte is the destination state. Transition is forced
tacos::setState(payload[0], payload[1], 0, true);
// First byte of payload is the origin state, second byte is the destination state. Transition is forced
tacos::setState(payload[0], payload[1], 0, true);
return true;
}
return false;
}
} // namespace tacos
} // namespace sta