Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce that CANMessage.m_dataSize won't be larger than 8 bytes #40

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ CANStatus CandleWinUSBDevice::ReceiveCANMessage(std::shared_ptr<CANMessage>& msg
// Assume timeout
CANStatus status = CANStatus::kTimeout;

// parse through the keys, find the messges the match, and return it
// parse through the keys, find the messages that match, and return it
// The first in the message id, then the messages
std::map<uint32_t, std::shared_ptr<CANMessage>> messages;
m_thread.ReceiveMessage(messages);
Expand Down
7 changes: 4 additions & 3 deletions src/main/native/include/rev/CANMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,12 @@ class CANMessage {
public:
CANMessage() : m_data{0}, m_size(0), m_messageId(0) { }
CANMessage(uint32_t messageId, const uint8_t* data, uint8_t dataSize, uint32_t timestampUs = 0) :
m_size(dataSize), m_messageId(messageId) {

m_messageId(messageId) {
// TODO: Support CAN FD
m_dataSize = dataSize > 8 ? 8 : dataSize
m_timestamp = (timestampUs != 0) ? timestampUs : std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now()).time_since_epoch().count();
std::memset(m_data, 0, 8);
std::memcpy(m_data, data, dataSize > 8 ? 8 : dataSize);
std::memcpy(m_data, data, m_dataSize);
}

~CANMessage() = default;
Expand Down
Loading