mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/TACOS.git
synced 2025-06-12 01:25:59 +00:00
feat: handleSysMessage checks allows user to overwrite CAN system behavior
This commit is contained in:
parent
d028ecef74
commit
dd4c5f34a2
@ -111,10 +111,17 @@ namespace sta
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Callback function for handling received messages. Intended for state transitions.
|
* @brief Handle system messages received over the CAN bus. Called as soon as a message is received. If
|
||||||
*/
|
* the message is a system message, it will be handled here. If the message is not a system message, it will be
|
||||||
|
* passed to the appropriate thread's queue.
|
||||||
|
*
|
||||||
|
* @param header The header of the received message.
|
||||||
|
* @param payload The payload of the received message.
|
||||||
|
*
|
||||||
|
* @return True if the message was a system message.
|
||||||
|
*/
|
||||||
STA_WEAK
|
STA_WEAK
|
||||||
void handleSysMessage(CanMsgHeader & header, uint8_t * payload);
|
bool handleSysMessage(CanMsgHeader & header, uint8_t * payload);
|
||||||
|
|
||||||
} /* namespace tacos */
|
} /* namespace tacos */
|
||||||
|
|
||||||
|
@ -63,17 +63,15 @@ namespace sta
|
|||||||
sysMsg = *canBusSysQueueBuffer_[i];
|
sysMsg = *canBusSysQueueBuffer_[i];
|
||||||
canBusSysQueueBuffer_[i] = nullptr;
|
canBusSysQueueBuffer_[i] = nullptr;
|
||||||
|
|
||||||
// Append to the correct thread's queue
|
if (!handleSysMessage(sysMsg.header, sysMsg.payload)){
|
||||||
for (std::shared_ptr<TacosThread> thread : Manager::instance()->getActiveThreads()){
|
|
||||||
if (thread->getCanID() == sysMsg.header.sid){
|
|
||||||
thread->CAN_queue_.put(sysMsg);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(sysMsg.header.sid == STA_TACOS_CAN_BUS_SYS_MSG_ID){
|
// Append to the correct thread's queue
|
||||||
// Handle system message
|
for (std::shared_ptr<TacosThread> thread : Manager::instance()->getActiveThreads()){
|
||||||
handleSysMessage(sysMsg.header, sysMsg.payload);
|
if (thread->getCanID() == sysMsg.header.sid){
|
||||||
|
thread->CAN_queue_.put(sysMsg);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -148,15 +146,22 @@ namespace sta {
|
|||||||
|
|
||||||
namespace tacos
|
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,
|
// 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
|
// 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
|
// 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);
|
tacos::setState(payload[0], payload[1], 0, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
} // namespace tacos
|
} // namespace tacos
|
||||||
} // namespace sta
|
} // namespace sta
|
||||||
|
Loading…
x
Reference in New Issue
Block a user