Skip to content

Commit

Permalink
[HW]: Add a way to get the current TouCAN serial number
Browse files Browse the repository at this point in the history
(cherry picked from commit 47ca087)
  • Loading branch information
ad3154 committed Dec 28, 2023
1 parent d996aab commit e978b85
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ namespace isobus
/// @returns True if the configuration was changed, otherwise false (if the device is open false will be returned)
bool reconfigure(std::int16_t deviceID, std::uint32_t serialNumber, std::uint16_t baudRate = 250);

/// @brief Returns the currently configured serial number of the device which will be used to connect to the hardware
/// @returns The currently configured serial number of the device
std::uint32_t get_serial_number() const;

private:
/// @brief Generates a device name string for the TouCAN device
/// @param[in] deviceID The id to use for this device
Expand All @@ -80,6 +84,7 @@ namespace isobus
std::string name; ///< A configuration string that is used to connect to the hardware through the CANAL api
std::uint32_t handle = 0; ///< The handle that the driver returns to us for the open hardware
std::uint32_t openResult = CANAL_ERROR_NOT_OPEN; ///< Stores the result of the call to begin CAN communication. Used for is_valid check later.
std::uint32_t currentlyConfiguredSerialNumber = 0; ///< The serial number of the device that is being used
};
}
#endif // TOUCAN_VSCP_CANAL_PLUGIN_HPP
6 changes: 6 additions & 0 deletions hardware_integration/src/toucan_vscp_canal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ namespace isobus
return retVal;
}

std::uint32_t TouCANPlugin::get_serial_number() const
{
return currentlyConfiguredSerialNumber;
}

void TouCANPlugin::generate_device_name(std::int16_t deviceID, std::uint32_t serialNumber, std::uint16_t baudRate)
{
std::string deviceConfigString;
Expand All @@ -118,6 +123,7 @@ namespace isobus
isobus::CANStackLogger::critical("[TouCAN]: Invalid serial number. Must be 8 digits max.");
serialNumber = 0;
}
currentlyConfiguredSerialNumber = serialNumber;
serialString = isobus::to_string(serialNumber);

if (SERIAL_NUMBER_CHARACTER_REQUIREMENT > serialString.length())
Expand Down

0 comments on commit e978b85

Please sign in to comment.