Skip to content

Commit

Permalink
demos: CanWriter: Always send CAN FD; ApplicationBase: Fix command li…
Browse files Browse the repository at this point in the history
…ne help
  • Loading branch information
KonradBkd committed Nov 19, 2024
1 parent 29520d4 commit 4f4b179
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Demos/Can/CanDemoCommon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void FrameHandler(const CanFrameEvent& canFrameEvent, ILogger* logger)
// Log
std::string payloadStr(canFrameEvent.frame.dataField.begin(), canFrameEvent.frame.dataField.end());
std::stringstream buffer;
buffer << "Receive CAN " << frameTypeHint << "frame, canId=" << canFrameEvent.frame.canId << ", data ='"
buffer << "Receive CAN " << frameTypeHint << "frame, canId=" << canFrameEvent.frame.canId << ", data='"
<< payloadStr << "'";
logger->Info(buffer.str());
}
Expand Down
14 changes: 5 additions & 9 deletions Demos/Can/CanWriterDemo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,21 @@ class CanWriter: public ApplicationBase
canFrame.canId = 3;

// Cycle between normal and FD frames
std::string frameTypeHint = "";
if (messageId % 2 == 1)
{
canFrame.flags = static_cast<CanFrameFlagMask>(CanFrameFlag::Fdf) // FD Format Indicator
| static_cast<CanFrameFlagMask>(CanFrameFlag::Brs); // Bit Rate Switch (for FD Format only)
frameTypeHint = "FD ";
}
canFrame.flags = static_cast<CanFrameFlagMask>(CanFrameFlag::Fdf) // FD Format Indicator
| static_cast<CanFrameFlagMask>(CanFrameFlag::Brs); // Bit Rate Switch (for FD Format only)


// Build a payload with the message Id
std::stringstream payloadBuilder;
payloadBuilder << "Hello CAN Bus, this is frame #" << messageId;
payloadBuilder << "CAN " << messageId;
auto payloadStr = payloadBuilder.str();
std::vector<uint8_t> payloadBytes(payloadStr.begin(), payloadStr.end());
canFrame.dataField = payloadBytes;
canFrame.dlc = static_cast<uint16_t>(canFrame.dataField.size());

// Log
std::stringstream buffer;
buffer << "Send CAN " << frameTypeHint << "frame, canId = " << canFrame.canId << ", data = '" << payloadStr
buffer << "Send CAN FD frame, canId=" << canFrame.canId << ", data='" << payloadStr
<< "' ";
GetLogger()->Info(buffer.str());

Expand Down
2 changes: 1 addition & 1 deletion Demos/include/ApplicationBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class ApplicationBase

auto ToLowerCase(std::string s) -> std::string
{
std::for_each(s.begin(), s.end(), [](char& c) { c = std::tolower(c); });
std::for_each(s.begin(), s.end(), [](char& c) { c = static_cast<char>(std::tolower(c)); });
return s;
}
auto IsValidLogLevel(const std::string& levelStr) -> bool
Expand Down

0 comments on commit 4f4b179

Please sign in to comment.