Auto commit at 2025-06-12 15:29:22
This commit is contained in:
parent
f019bef882
commit
50f316a5f2
@ -167,6 +167,13 @@ void CANDriver::receiveThreadFunc()
|
|||||||
frame.ext = rec[i].ExternFlag != 0;
|
frame.ext = rec[i].ExternFlag != 0;
|
||||||
frame.rtr = rec[i].RemoteFlag != 0;
|
frame.rtr = rec[i].RemoteFlag != 0;
|
||||||
frame.dlc = rec[i].DataLen;
|
frame.dlc = rec[i].DataLen;
|
||||||
|
|
||||||
|
if (frame.dlc > 8)
|
||||||
|
{
|
||||||
|
std::cerr << "Invalid CAN data length: " << (int)frame.dlc << std::endl;
|
||||||
|
frame.dlc = 8; // 或跳过此帧
|
||||||
|
}
|
||||||
|
|
||||||
std::memcpy(frame.data, rec[i].Data, frame.dlc);
|
std::memcpy(frame.data, rec[i].Data, frame.dlc);
|
||||||
callback(frame, userData);
|
callback(frame, userData);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -95,7 +95,9 @@ void receiveHandler(const CANFrame &frame, void *userData)
|
|||||||
auto msg = sweeperMsg::CanFrame();
|
auto msg = sweeperMsg::CanFrame();
|
||||||
msg.id = frame.id;
|
msg.id = frame.id;
|
||||||
msg.dlc = frame.dlc;
|
msg.dlc = frame.dlc;
|
||||||
msg.data.assign(frame.data, frame.data + frame.dlc);
|
size_t len = frame.dlc <= 8 ? frame.dlc : 8;
|
||||||
|
msg.data.assign(frame.data, frame.data + len);
|
||||||
|
|
||||||
publisher->publish(msg);
|
publisher->publish(msg);
|
||||||
|
|
||||||
// 根据开关决定是否打印 CAN 消息
|
// 根据开关决定是否打印 CAN 消息
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user