Skip to content

Commit

Permalink
[Logger]: Made it possible to compile out the logger
Browse files Browse the repository at this point in the history
Added a cmake option for disabling the logger to save ROM space.
Disabling the logger was accomplished by adding a macro to remove the
content of logging operations when the cmake option is set.
  • Loading branch information
ad3154 committed Feb 8, 2024
1 parent 867d2c0 commit 65daf3b
Show file tree
Hide file tree
Showing 37 changed files with 772 additions and 675 deletions.
34 changes: 17 additions & 17 deletions hardware_integration/src/can_hardware_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace isobus

if (threadsStarted)
{
isobus::CANStackLogger::error("[HardwareInterface] Cannot set number of channels after interface is started.");
LOG_ERROR("[HardwareInterface] Cannot set number of channels after interface is started.");
return false;
}

Expand All @@ -72,21 +72,21 @@ namespace isobus

if (threadsStarted)
{
isobus::CANStackLogger::error("[HardwareInterface] Cannot assign frame handlers after interface is started.");
LOG_ERROR("[HardwareInterface] Cannot assign frame handlers after interface is started.");
return false;
}

if (channelIndex >= hardwareChannels.size())
{
isobus::CANStackLogger::error("[HardwareInterface] Unable to set frame handler at channel " + isobus::to_string(channelIndex) +
", because there are only " + isobus::to_string(hardwareChannels.size()) + " channels set. " +
"Use set_number_of_can_channels() to increase the number of channels before assigning frame handlers.");
LOG_ERROR("[HardwareInterface] Unable to set frame handler at channel " + isobus::to_string(channelIndex) +
", because there are only " + isobus::to_string(hardwareChannels.size()) + " channels set. " +
"Use set_number_of_can_channels() to increase the number of channels before assigning frame handlers.");
return false;
}

if (nullptr != hardwareChannels[channelIndex]->frameHandler)
{
isobus::CANStackLogger::error("[HardwareInterface] Unable to set frame handler at channel " + isobus::to_string(channelIndex) + ", because it is already assigned.");
LOG_ERROR("[HardwareInterface] Unable to set frame handler at channel " + isobus::to_string(channelIndex) + ", because it is already assigned.");
return false;
}

Expand All @@ -105,20 +105,20 @@ namespace isobus

if (threadsStarted)
{
isobus::CANStackLogger::error("[HardwareInterface] Cannot remove frame handlers after interface is started.");
LOG_ERROR("[HardwareInterface] Cannot remove frame handlers after interface is started.");
return false;
}

if (channelIndex >= hardwareChannels.size())
{
isobus::CANStackLogger::error("[HardwareInterface] Unable to remove frame handler at channel " + isobus::to_string(channelIndex) +
", because there are only " + isobus::to_string(hardwareChannels.size()) + " channels set.");
LOG_ERROR("[HardwareInterface] Unable to remove frame handler at channel " + isobus::to_string(channelIndex) +
", because there are only " + isobus::to_string(hardwareChannels.size()) + " channels set.");
return false;
}

if (nullptr == hardwareChannels[channelIndex]->frameHandler)
{
isobus::CANStackLogger::error("[HardwareInterface] Unable to remove frame handler at channel " + isobus::to_string(channelIndex) + ", because it is not assigned.");
LOG_ERROR("[HardwareInterface] Unable to remove frame handler at channel " + isobus::to_string(channelIndex) + ", because it is not assigned.");
return false;
}

Expand All @@ -143,7 +143,7 @@ namespace isobus

if (threadsStarted)
{
isobus::CANStackLogger::error("[HardwareInterface] Cannot start interface more than once.");
LOG_ERROR("[HardwareInterface] Cannot start interface more than once.");
return false;
}

Expand Down Expand Up @@ -172,7 +172,7 @@ namespace isobus
{
if (!threadsStarted)
{
isobus::CANStackLogger::error("[HardwareInterface] Cannot stop interface before it is started.");
LOG_ERROR("[HardwareInterface] Cannot stop interface before it is started.");
return false;
}
stop_threads();
Expand Down Expand Up @@ -205,21 +205,21 @@ namespace isobus
{
if (!threadsStarted)
{
isobus::CANStackLogger::error("[HardwareInterface] Cannot transmit message before interface is started.");
LOG_ERROR("[HardwareInterface] Cannot transmit message before interface is started.");
return false;
}

if (frame.channel >= hardwareChannels.size())
{
isobus::CANStackLogger::error("[HardwareInterface] Cannot transmit message on channel " + isobus::to_string(frame.channel) +
", because there are only " + isobus::to_string(hardwareChannels.size()) + " channels set.");
LOG_ERROR("[HardwareInterface] Cannot transmit message on channel " + isobus::to_string(frame.channel) +
", because there are only " + isobus::to_string(hardwareChannels.size()) + " channels set.");
return false;
}

const std::unique_ptr<CANHardware> &channel = hardwareChannels[frame.channel];
if (nullptr == channel->frameHandler)
{
isobus::CANStackLogger::error("[HardwareInterface] Cannot transmit message on channel " + isobus::to_string(frame.channel) + ", because it is not assigned.");
LOG_ERROR("[HardwareInterface] Cannot transmit message on channel " + isobus::to_string(frame.channel) + ", because it is not assigned.");
return false;
}

Expand Down Expand Up @@ -345,7 +345,7 @@ namespace isobus
}
else
{
isobus::CANStackLogger::critical("[CAN Rx Thread]: CAN Channel " + isobus::to_string(channelIndex) + " appears to be invalid.");
LOG_CRITICAL("[CAN Rx Thread]: CAN Channel " + isobus::to_string(channelIndex) + " appears to be invalid.");
std::this_thread::sleep_for(std::chrono::milliseconds(1000)); // Arbitrary, but don't want to infinite loop on the validity check.
}
}
Expand Down
32 changes: 16 additions & 16 deletions hardware_integration/src/can_hardware_interface_single_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace isobus
{
if (started)
{
isobus::CANStackLogger::error("[HardwareInterface] Cannot set number of channels after interface is started.");
LOG_ERROR("[HardwareInterface] Cannot set number of channels after interface is started.");
return false;
}

Expand All @@ -53,21 +53,21 @@ namespace isobus
{
if (started)
{
isobus::CANStackLogger::error("[HardwareInterface] Cannot assign frame handlers after interface is started.");
LOG_ERROR("[HardwareInterface] Cannot assign frame handlers after interface is started.");
return false;
}

if (channelIndex >= hardwareChannels.size())
{
isobus::CANStackLogger::error("[HardwareInterface] Unable to set frame handler at channel " + isobus::to_string(channelIndex) +
", because there are only " + isobus::to_string(hardwareChannels.size()) + " channels set. " +
"Use set_number_of_can_channels() to increase the number of channels before assigning frame handlers.");
LOG_ERROR("[HardwareInterface] Unable to set frame handler at channel " + isobus::to_string(channelIndex) +
", because there are only " + isobus::to_string(hardwareChannels.size()) + " channels set. " +
"Use set_number_of_can_channels() to increase the number of channels before assigning frame handlers.");
return false;
}

if (nullptr != hardwareChannels[channelIndex]->frameHandler)
{
isobus::CANStackLogger::error("[HardwareInterface] Unable to set frame handler at channel " + isobus::to_string(channelIndex) + ", because it is already assigned.");
LOG_ERROR("[HardwareInterface] Unable to set frame handler at channel " + isobus::to_string(channelIndex) + ", because it is already assigned.");
return false;
}

Expand All @@ -84,20 +84,20 @@ namespace isobus
{
if (started)
{
isobus::CANStackLogger::error("[HardwareInterface] Cannot remove frame handlers after interface is started.");
LOG_ERROR("[HardwareInterface] Cannot remove frame handlers after interface is started.");
return false;
}

if (channelIndex >= hardwareChannels.size())
{
isobus::CANStackLogger::error("[HardwareInterface] Unable to remove frame handler at channel " + isobus::to_string(channelIndex) +
", because there are only " + isobus::to_string(hardwareChannels.size()) + " channels set.");
LOG_ERROR("[HardwareInterface] Unable to remove frame handler at channel " + isobus::to_string(channelIndex) +
", because there are only " + isobus::to_string(hardwareChannels.size()) + " channels set.");
return false;
}

if (nullptr == hardwareChannels[channelIndex]->frameHandler)
{
isobus::CANStackLogger::error("[HardwareInterface] Unable to remove frame handler at channel " + isobus::to_string(channelIndex) + ", because it is not assigned.");
LOG_ERROR("[HardwareInterface] Unable to remove frame handler at channel " + isobus::to_string(channelIndex) + ", because it is not assigned.");
return false;
}

Expand All @@ -109,7 +109,7 @@ namespace isobus
{
if (started)
{
isobus::CANStackLogger::error("[HardwareInterface] Cannot start interface more than once.");
LOG_ERROR("[HardwareInterface] Cannot start interface more than once.");
return false;
}

Expand All @@ -130,7 +130,7 @@ namespace isobus
{
if (!started)
{
isobus::CANStackLogger::error("[HardwareInterface] Cannot stop interface before it is started.");
LOG_ERROR("[HardwareInterface] Cannot stop interface before it is started.");
return false;
}

Expand All @@ -153,20 +153,20 @@ namespace isobus
{
if (!started)
{
isobus::CANStackLogger::error("[HardwareInterface] Cannot transmit message before interface is started.");
LOG_ERROR("[HardwareInterface] Cannot transmit message before interface is started.");
return false;
}

if (frame.channel >= hardwareChannels.size())
{
isobus::CANStackLogger::error("[HardwareInterface] Cannot transmit message on channel %u, because there are only %u channels set.", frame.channel, hardwareChannels.size());
LOG_ERROR("[HardwareInterface] Cannot transmit message on channel %u, because there are only %u channels set.", frame.channel, hardwareChannels.size());
return false;
}

const std::unique_ptr<CANHardware> &channel = hardwareChannels[frame.channel];
if (nullptr == channel->frameHandler)
{
isobus::CANStackLogger::error("[HardwareInterface] Cannot transmit message on channel %u, because it is not assigned.", frame.channel);
LOG_ERROR("[HardwareInterface] Cannot transmit message on channel %u, because it is not assigned.", frame.channel);
return false;
}

Expand Down Expand Up @@ -248,7 +248,7 @@ namespace isobus
}
else
{
isobus::CANStackLogger::critical("[CAN Rx Thread]: CAN Channel " + isobus::to_string(channelIndex) + " appears to be invalid.");
LOG_CRITICAL("[CAN Rx Thread]: CAN Channel " + isobus::to_string(channelIndex) + " appears to be invalid.");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion hardware_integration/src/flex_can_t4_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace isobus
#endif
else
{
isobus::CANStackLogger::critical("[FlexCAN]: Invalid Channel Selected");
LOG_CRITICAL("[FlexCAN]: Invalid Channel Selected");
}
}

Expand Down
12 changes: 6 additions & 6 deletions hardware_integration/src/innomaker_usb2can_windows_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace isobus
}
if (allChannelsClosed)
{
isobus::CANStackLogger::info("[InnoMaker-Windows] All channels closed, closing driver instance");
LOG_INFO("[InnoMaker-Windows] All channels closed, closing driver instance");
driverInstance->setdown();
driverInstance = nullptr;
}
Expand Down Expand Up @@ -238,7 +238,7 @@ namespace isobus

default:
{
isobus::CANStackLogger::error("[InnoMaker-Windows] Unsupported baudrate with index " + isobus::to_string(baudrate) + " in InnoMakerUSB2CANWindowsPlugin::Baudrate enum.");
LOG_ERROR("[InnoMaker-Windows] Unsupported baudrate with index " + isobus::to_string(baudrate) + " in InnoMakerUSB2CANWindowsPlugin::Baudrate enum.");
return;
}
break;
Expand All @@ -248,7 +248,7 @@ namespace isobus
}
else
{
isobus::CANStackLogger::error("[InnoMaker-Windows] No device found on channel " + isobus::to_string(channel));
LOG_ERROR("[InnoMaker-Windows] No device found on channel " + isobus::to_string(channel));
}
}

Expand All @@ -275,7 +275,7 @@ namespace isobus
InnoMakerUsb2CanLib::innomaker_tx_context *txc = driverInstance->innomaker_get_tx_context(txContexts.get(), frame.echo_id);
if (nullptr == txc)
{
isobus::CANStackLogger::warn("[InnoMaker-Windows] Received frame with bad echo ID: " + isobus::to_string(static_cast<int>(frame.echo_id)));
LOG_WARNING("[InnoMaker-Windows] Received frame with bad echo ID: " + isobus::to_string(static_cast<int>(frame.echo_id)));
return false;
}
driverInstance->innomaker_free_tx_context(txc);
Expand Down Expand Up @@ -310,7 +310,7 @@ namespace isobus
InnoMakerUsb2CanLib::innomaker_tx_context *txc = driverInstance->innomaker_alloc_tx_context(txContexts.get());
if (0xFF == txc->echo_id)
{
isobus::CANStackLogger::debug("[InnoMaker-Windows] No free transmission context");
LOG_DEBUG("[InnoMaker-Windows] No free transmission context");
return false;
}

Expand All @@ -333,7 +333,7 @@ namespace isobus
bool success = driverInstance->sendInnoMakerDeviceBuf(device, sendBuffer, sizeof(InnoMakerUsb2CanLib::innomaker_host_frame), 10);
if (!success)
{
isobus::CANStackLogger::warn("[InnoMaker-Windows] Failed to send frame");
LOG_WARNING("[InnoMaker-Windows] Failed to send frame");
driverInstance->innomaker_free_tx_context(txc);
}
return success;
Expand Down
2 changes: 1 addition & 1 deletion hardware_integration/src/mac_can_pcan_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace isobus

if (PCAN_ERROR_OK != openResult)
{
isobus::CANStackLogger::critical("[MacCAN]: Error trying to connect to PCAN probe");
LOG_CRITICAL("[MacCAN]: Error trying to connect to PCAN probe");
}
}

Expand Down
10 changes: 5 additions & 5 deletions hardware_integration/src/mcp2515_can_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,14 @@ namespace isobus
// Check if last message was sent successfully
if (0 != (ctrl & (0x40 | 0x10)))
{
isobus::CANStackLogger::error("[MCP2515] Failed to send last message, please verify your connection/setup:");
LOG_ERROR("[MCP2515] Failed to send last message, please verify your connection/setup:");
if (0 != (ctrl & 0x40))
{
isobus::CANStackLogger::error("\t- Message was aborted.");
LOG_ERROR("\t- Message was aborted.");
}
if (0 != (ctrl & 0x10))
{
isobus::CANStackLogger::error("\t- A bus error occurred while the message was being transmitted.");
LOG_ERROR("\t- A bus error occurred while the message was being transmitted.");
}
}

Expand Down Expand Up @@ -349,7 +349,7 @@ namespace isobus
}
else
{
isobus::CANStackLogger::warn("[MCP2515] Failed to send message, buffer is not empty.");
LOG_WARNING("[MCP2515] Failed to send message, buffer is not empty.");
}
}

Expand Down Expand Up @@ -407,7 +407,7 @@ namespace isobus

if (!retVal)
{
isobus::CANStackLogger::error("[MCP2515] Failed to send message, buffer has been full for too long.");
LOG_ERROR("[MCP2515] Failed to send message, buffer has been full for too long.");
}
return retVal;
}
Expand Down
2 changes: 1 addition & 1 deletion hardware_integration/src/pcan_basic_windows_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace isobus

if (PCAN_ERROR_OK != openResult)
{
isobus::CANStackLogger::critical("[PCAN]: Error trying to connect to PCAN probe");
LOG_CRITICAL("[PCAN]: Error trying to connect to PCAN probe");
}
}

Expand Down
4 changes: 2 additions & 2 deletions hardware_integration/src/socket_can_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ namespace isobus
}
else if (errno == ENETDOWN)
{
isobus::CANStackLogger::critical("[SocketCAN] " + get_device_name() + " interface is down.");
LOG_CRITICAL("[SocketCAN] " + get_device_name() + " interface is down.");
close();
}
}
Expand Down Expand Up @@ -211,7 +211,7 @@ namespace isobus
}
else if (errno == ENETDOWN)
{
isobus::CANStackLogger::critical("[SocketCAN] " + get_device_name() + " interface is down.");
LOG_CRITICAL("[SocketCAN] " + get_device_name() + " interface is down.");
close();
}
return retVal;
Expand Down
Loading

0 comments on commit 65daf3b

Please sign in to comment.