asc file reader and small log enhancements (#3)

This commit is contained in:
tompzf
2025-12-09 18:37:22 +01:00
committed by GitHub
parent 2fb043b2be
commit f74e494a43
19 changed files with 168 additions and 110 deletions

View File

@@ -6,25 +6,18 @@
#ifndef SIGNAL_NAMES_H
#define SIGNAL_NAMES_H
#ifdef __has_include
#if __has_include("../interfaces/signal_identifier.h")
#include "../interfaces/signal_identifier.h"
#else
namespace doors
{
// Data Dispatch Service signal names to dbc variable names C-type RX/TX vss name space
static std::string dsLeftDoorIsOpen01 = "CAN_Input_L1.Door01LeftIsOpen"; ///< bool RX Vehicle.Chassis.Door.Axle01.Left
static std::string dsRightDoorIsOpen01 = "CAN_Input_R1.Door01RightIs"; ///< bool RX Vehicle.Chassis.Door.Axle01.Right
static std::string dsRightDoorIsOpen01 = "CAN_Input_R1.Door01RightIsOpen"; ///< bool RX Vehicle.Chassis.Door.Axle01.Right
static std::string dsLeftDoorIsOpen02 = "CAN_Input_L2.Door02LeftIsOpen"; ///< bool RX Vehicle.Chassis.Door.Axle02.Left
static std::string dsRightDoorIsOpen02 = "CAN_Input_R2.Door02RightIsOpen"; ///< bool RX Vehicle.Chassis.Door.Axle02.Right
static std::string dsLeftLatch01 = "CAN_Output.LockDoor01Left" ; ///< bool TX Vehicle.Chassis.TX.Door.Axle01.Left
static std::string dsLeftLatch01 = "CAN_Output.LockDoor01Left"; ///< bool TX Vehicle.Chassis.TX.Door.Axle01.Left
static std::string dsRightLatch01 = "CAN_Output.LockDoor01Right"; ///< bool TX Vehicle.Chassis.TX.Door.Axle01.Right
static std::string dsLeftLatch02 = "CAN_Output.LockDoor02Left" ; ///< bool TX Vehicle.Chassis.TX.Door.Axle02.Left
static std::string dsRightLatch02 = "CAN_Output.LockDoor02Right"; ///< bool TX Vehicle.Chassis.TX.Door.Axle02.Right
static std::string dsLeftLatch02 = "CAN_Output.LockDoor02Left"; ///< bool TX Vehicle.Chassis.TX.Door.Axle02.Left
static std::string dsRightLatch02 = "CAN_Output.LockDoor02Right"; ///< bool TX Vehicle.Chassis.TX.Door.Axle02.Left
} // doors
#endif
#endif
#endif // SIGNAL_NAMES_H

View File

@@ -1,6 +1,6 @@
date 08/28/25 19:10:31
base hex timestamps absolute
Begin Triggerblock 08/28/25 19:10:31
Begin TriggerBlock 08/28/25 19:10:31
0.000000 Start of measurement
0.021165 1 1 Rx d 1 02
0.031165 1 2 Rx d 1 08

View File

@@ -14,8 +14,8 @@ namespace Doors2ExampleFMU
// Data Dispatch Service signal names to dbc variable names C-type RX/TX vss name space
static std::string dsDoor01LeftIsOpen = "CAN_Input_L1.Door01LeftIsOpen";
static std::string dsDoor01RightIsOpen = "CAN_Input_R1.Door01RightIsOpen";
static std::string dsLockDoor01Right = "CAN_Output.LockDoor01Right";
static std::string dsLockDoor01Left = "CAN_Output.LockDoor01Left";
static std::string dsLockDoor01Right = "CAN_Output.LockDoor01Right";
} // Doors2ExampleFMU

View File

@@ -16,10 +16,10 @@ namespace Doors4ExampleFMU
static std::string dsDoor01RightIsOpen = "CAN_Input_R1.Door01RightIsOpen";
static std::string dsDoor02LeftIsOpen = "CAN_Input_L2.Door02LeftIsOpen";
static std::string dsDoor02RightIsOpen = "CAN_Input_R2.Door02RightIsOpen";
static std::string dsLockDoor02Right = "CAN_Output.LockDoor02Right";
static std::string dsLockDoor02Left = "CAN_Output.LockDoor02Left";
static std::string dsLockDoor01Right = "CAN_Output.LockDoor01Right";
static std::string dsLockDoor01Left = "CAN_Output.LockDoor01Left";
static std::string dsLockDoor01Right = "CAN_Output.LockDoor01Right";
static std::string dsLockDoor02Left = "CAN_Output.LockDoor02Left";
static std::string dsLockDoor02Right = "CAN_Output.LockDoor02Right";
} // Doors4ExampleFMU

View File

@@ -134,7 +134,7 @@ bool CConsole::PrepareDataConsumers()
basicService->RegisterOnSignalChangeOfVehicleSpeed(dynamic_cast<vss::Vehicle::SpeedService::IVSS_SetSpeed_Event*> (this));
}
// Request the basic service for opening the drunk.
// Request the basic service for opening the trunk.
m_pTrunkSvc = sdv::core::GetObject("Vehicle.Body.Trunk_Service").GetInterface<vss::Vehicle::Body::TrunkService::IVSS_SetOpen>();
if (m_pTrunkSvc)
PrintText(g_sComplexServcie1, "Basic Service available");

View File

@@ -1,6 +1,6 @@
date 08/28/25 19:10:31
base hex timestamps absolute
Begin Triggerblock 08/28/25 19:10:31
Begin TriggerBlock 08/28/25 19:10:31
0.000000 Start of measurement
0.201165 1 0 Rx d 8 00 00 00 00 00 00 00 32
0.401499 1 0 Rx d 8 00 00 00 00 00 00 00 66

View File

@@ -1,6 +1,6 @@
date 08/28/25 19:10:31
base hex timestamps absolute
Begin Triggerblock 08/28/25 19:10:31
Begin TriggerBlock 08/28/25 19:10:31
0.000000 Start of measurement
0.201165 1 0 Rx d 8 00 00 00 00 00 CC 00 32
0.401499 1 0 Rx d 8 00 00 00 00 01 98 00 66

View File

@@ -95,90 +95,68 @@ namespace sdv
{
if (m_bInit) return; // Prevent trying to load again.
m_bInit = true;
bool bRelocFileError = false;
std::string ssRelocFileInfo = "";
std::string ssEnvironmentInfo = "";
// Check for the executable directory
std::filesystem::path pathCoreLib;
if (std::filesystem::exists(GetExecDirectory() / "core_services.sdv"))
pathCoreLib = GetExecDirectory() / "core_services.sdv";
// Check for the local config file
if (pathCoreLib.empty() && std::filesystem::exists(GetExecDirectory() / "sdv_core_reloc.toml"))
{
std::ifstream fstream(GetExecDirectory() / "sdv_core_reloc.toml");
std::string ssLine;
while (std::getline(fstream, ssLine))
{
size_t nPos = 0;
auto fnSkipWhitespace = [&]() { while (std::isspace(ssLine[nPos])) nPos++; };
fnSkipWhitespace();
if (ssLine[nPos] == '#') continue; // Rest of the line is comments
if (ssLine.substr(nPos, 9) != "directory") continue; // not the keq of interest: skip line
nPos += 9;
fnSkipWhitespace();
if (ssLine[nPos] != '=')
{
std::cout << "Error in \"sdv_core_reloc.toml\": expecting assignment character '=' following"
" keyword 'directory'." << std::endl;
break;
}
nPos++;
fnSkipWhitespace();
if (ssLine[nPos] != '\"')
{
std::cout << "Error in \"sdv_core_reloc.toml\": expecting double quote character '\"' indicating"
" a string begin'." << std::endl;
break;
}
nPos++;
size_t nStart = nPos;
while (nPos < ssLine.length() && ssLine[nPos] != '\"')
{
// Check for escape character
if (ssLine[nPos] == '\\') nPos++;
// Skip character
nPos++;
}
if (nPos >= ssLine.length() || ssLine[nPos] != '\"')
if (pathCoreLib.empty())
{
std::cout << "Error in \"sdv_core_reloc.toml\": expecting double quote character '\"' indicating"
" a string end'." << std::endl;
break;
}
std::string ssDirectory = ssLine.substr(nStart, nPos - nStart);
while (ssDirectory.empty())
if (std::filesystem::exists(GetExecDirectory() / "sdv_core_reloc.toml"))
{
std::cout << "Error in \"sdv_core_reloc.toml\": expecting a valid value following the assignment"
" of the 'directory' key." << std::endl;
break;
// Check for the library in the relocation directory
auto relocFolder = GetRelocationPath();
if (!relocFolder.empty())
{
auto coreLibFolder = std::filesystem::path(relocFolder) / "core_services.sdv";
if (coreLibFolder.is_relative())
coreLibFolder = (GetExecDirectory() / coreLibFolder).lexically_normal();
if (std::filesystem::exists(coreLibFolder))
pathCoreLib = coreLibFolder;
}
pathCoreLib = std::filesystem::path(ssDirectory) / "core_services.sdv";
if (pathCoreLib.is_relative())
pathCoreLib = (GetExecDirectory() / pathCoreLib).lexically_normal();
break;
if (pathCoreLib.empty())
{
bRelocFileError = true; // we found the file but not the core library, we must run into an error
ssRelocFileInfo = "Error: Invalid \"sdv_core_reloc.toml\" file found (but no core library), it contains: " + relocFolder;
}
}
// Check for the environment variable
}
if (pathCoreLib.empty())
{
#ifdef _WIN32
std::wstring ssPathCoreTemp(32768, '\0');
GetEnvironmentVariable(L"SDV_FRAMEWORK_RUNTIME", ssPathCoreTemp.data(), static_cast<DWORD>(ssPathCoreTemp.size()));
ssPathCoreTemp.resize(wcsnlen(ssPathCoreTemp.c_str(), ssPathCoreTemp.size()));
if (pathCoreLib.empty() && !ssPathCoreTemp.empty())
if (!ssPathCoreTemp.empty())
{
pathCoreLib = std::filesystem::path(ssPathCoreTemp) / "core_services.sdv";
#else
if (pathCoreLib.empty() && getenv("SDV_FRAMEWORK_RUNTIME"))
std::string ssPathCoreTemp = std::getenv("SDV_FRAMEWORK_RUNTIME") ? std::getenv("SDV_FRAMEWORK_RUNTIME") : "";
if (!ssPathCoreTemp.empty())
{
pathCoreLib = std::filesystem::path(getenv("SDV_FRAMEWORK_RUNTIME")) / "core_services.sdv";
pathCoreLib = std::filesystem::path(ssPathCoreTemp) / "core_services.sdv";
#endif
if (pathCoreLib.is_relative())
pathCoreLib = (GetExecDirectory() / pathCoreLib).lexically_normal();
if (!pathCoreLib.empty())
ssEnvironmentInfo = "System environment path: " + pathCoreLib.generic_string();
}
}
// Depend on system path to find the library
if (pathCoreLib.empty())
pathCoreLib = "core_services.sdv";
// Open the library
// Open the library only if there is no or a valid 'sdv_core_reloc.toml' file
if (!bRelocFileError)
{
#ifdef _WIN32
SetErrorMode(SEM_FAILCRITICALERRORS);
m_tModule = reinterpret_cast<core::TModuleID>(LoadLibraryW(pathCoreLib.native().c_str()));
@@ -187,6 +165,8 @@ namespace sdv
#else
#error OS is not supported!
#endif
}
if (!m_tModule)
{
std::string ssError;
@@ -201,6 +181,13 @@ namespace sdv
#else
#error OS is not supported!
#endif
if (ssRelocFileInfo.empty() && ssEnvironmentInfo.empty())
std::cerr << "No environment variable set and no realocation file found." << std::endl;
if (!ssRelocFileInfo.empty())
std::cerr << ssRelocFileInfo << std::endl;
if (!ssEnvironmentInfo.empty())
std::cerr << ssEnvironmentInfo << std::endl;
std::cerr << "Could not load \"core_services.sdv\" library";
if (!ssError.empty()) std::cerr << ": " << ssError;
std::cerr << std::endl;
@@ -264,6 +251,69 @@ namespace sdv
return std::filesystem::path{ssPath.c_str()}.parent_path() / ""; // To finish the folder path with (back)slash
}
/**
* @brief Get the folder path in the file 'sdv_core_reloc.toml'.
* @return Path content, empty string if not found.
*/
static std::string GetRelocationPath()
{
if (std::filesystem::exists(GetExecDirectory() / "sdv_core_reloc.toml"))
{
std::ifstream fstream(GetExecDirectory() / "sdv_core_reloc.toml");
std::string ssLine;
while (std::getline(fstream, ssLine))
{
size_t nPos = 0;
auto fnSkipWhitespace = [&]() { while (std::isspace(ssLine[nPos])) nPos++; };
fnSkipWhitespace();
if (ssLine[nPos] == '#') continue; // Rest of the line is comments
if (ssLine.substr(nPos, 9) != "directory") continue; // not the keq of interest: skip line
nPos += 9;
fnSkipWhitespace();
if (ssLine[nPos] != '=')
{
std::cout << "Error in \"sdv_core_reloc.toml\": expecting assignment character '=' following"
" keyword 'directory'." << std::endl;
break;
}
nPos++;
fnSkipWhitespace();
if (ssLine[nPos] != '\"')
{
std::cout << "Error in \"sdv_core_reloc.toml\": expecting double quote character '\"' indicating"
" a string begin'." << std::endl;
break;
}
nPos++;
size_t nStart = nPos;
while (nPos < ssLine.length() && ssLine[nPos] != '\"')
{
// Check for escape character
if (ssLine[nPos] == '\\') nPos++;
// Skip character
nPos++;
}
if (nPos >= ssLine.length() || ssLine[nPos] != '\"')
{
std::cout << "Error in \"sdv_core_reloc.toml\": expecting double quote character '\"' indicating"
" a string end'." << std::endl;
break;
}
std::string ssDirectory = ssLine.substr(nStart, nPos - nStart);
while (ssDirectory.empty())
{
std::cout << "Error in \"sdv_core_reloc.toml\": expecting a valid value following the assignment"
" of the 'directory' key." << std::endl;
break;
}
return ssDirectory;
}
}
return "";
}
bool m_bInit = false; ///< Is the loader initialized?
core::TModuleID m_tModule = 0; ///< Module ID
IInterfaceAccess* m_pCore = nullptr; ///< Pointer to the core services.

View File

@@ -43,7 +43,7 @@ namespace asc
switch (eState)
{
case EState::header:
if (ssLine.compare(0, 18, "Begin Triggerblock") == 0)
if (ssLine.compare(0, 18, "Begin TriggerBlock") == 0)
eState = EState::body;
break;
case EState::body:
@@ -72,6 +72,11 @@ namespace asc
return std::make_pair(*m_itCurrent, true);
}
uint32_t CAscReader::GetMessageCount() const
{
return m_lstMessages.size();
}
uint32_t CAscReader::GetLoopCount() const
{
return m_uiLoopCount;

View File

@@ -56,6 +56,12 @@ namespace asc
*/
std::pair<SCanMessage, bool> Get() const;
/**
* @brief Get the number of messages in the asc file
* @return Number of messages which count be read from the asc file.
*/
uint32_t GetMessageCount() const;
/**
* @brief Get the number of loops the data set was sent
* @return Number of loops the data set was sent including the current loop

View File

@@ -53,7 +53,7 @@ namespace asc
fstream << "base hex timestamps absolute" << std::endl;
// Stream trigger block
fstream << "Begin Triggerblock " << std::put_time(std::localtime(&tmSystemTime), "%c") << std::endl;
fstream << "Begin TriggerBlock " << std::put_time(std::localtime(&tmSystemTime), "%c") << std::endl;
fstream << " 0.000000 Start of measurement" << std::endl;
for (const SCanMessage& rsSample : m_lstMessages)
{

View File

@@ -199,9 +199,6 @@ void CVSSBSGenerator::CreateBasicServiceFilesForTXSignal(const SSignalBSDefiniti
}
codingTX.GetKeyWordMap(signal, signalVD, mapKeywords);
mapKeywords["basic_service_h"] = pathBSHeader.filename().generic_u8string();
mapKeywords["basic_service_cpp"] = pathBSClass.filename().generic_u8string();
fstreamBSHeader << ReplaceKeywords(szTXBasicServiceHeaderTemplate, mapKeywords);
fstreamBSClass << ReplaceKeywords(szTXBasicServiceClassTemplate, mapKeywords);
fstreamBSHeader.close();

View File

@@ -237,9 +237,6 @@ void CVSSVDGenerator::CreateVehicleDeviceFilesForTXSignal(const SSignalVDDefinit
CVSSVDCodingTX codingTX(m_ssPrefix);
codingTX.GetKeyWordMap(signal, mapKeywords);
mapKeywords["abstract_device_h"] = pathVDHeader.filename().generic_u8string();
mapKeywords["abstract_device_cpp"] = pathVDClass.filename().generic_u8string();
fstreamVDHeader << ReplaceKeywords(szTXVehicleDeviceHeaderTemplate, mapKeywords);
fstreamVDClass << ReplaceKeywords(szTXVehicleDeviceClassTemplate, mapKeywords);
fstreamVDHeader.close();

View File

@@ -72,6 +72,16 @@ void CCANSimulation::Initialize(const sdv::u8string& rssObjectConfig)
m_eStatus = sdv::EObjectStatus::initialization_failure;
return;
}
if (!m_pathSource.empty() && !m_reader.GetMessageCount())
{
SDV_LOG(sdv::core::ELogSeverity::error,
"No messages in ASC file '" + m_pathSource.generic_u8string() + "' found. File must contain 'Begin TriggerBlock' and 'End TriggerBlock' line.");
m_eStatus = sdv::EObjectStatus::initialization_failure;
return;
}
if (!m_pathSource.empty())
SDV_LOG(sdv::core::ELogSeverity::info,
"CAN simulator ASC file '" + m_pathSource.generic_u8string() + "' contains ", m_reader.GetMessageCount(), " messages.");
// Update the status
m_eStatus = sdv::EObjectStatus::initialized;

View File

@@ -2,7 +2,7 @@ date Wed Jul 28 06:47:19 pm 2010
base hex timestamps absolute
internal events logged
// version 7.0.1
Begin Triggerblock Wed Jul 28 06:47:19 pm 2010
Begin TriggerBlock Wed Jul 28 06:47:19 pm 2010
0.000000 Start of measurement
0.005502 CAN 1 Status:chip status error active
0.005675 CAN 2 Status:chip status error active

View File

@@ -1,7 +1,7 @@
date Dez. 3 2014 16:34:20
base hex timestamps absolute
no internal events logged
Begin Triggerblock
Begin TriggerBlock
3.35516 1 B4323x Rx D 8 72 E4 19 2F 14 00 00 00
3.35522 6 52 Rx D 2 6C 60
3.36716 1 B4323x Rx D 8 73 E5 E9 24 e2 00 00 00

View File

@@ -2,7 +2,7 @@ date Mon Mai 19 15:37:13.000 2014
base hex timestamps absolute
internal events logged
// version 8.5.0
Begin Triggerblock Mon Mai 19 15:37:13.690 2014
Begin TriggerBlock Mon Mai 19 15:37:13.690 2014
0.590000 1 539 Rx d 1 03 Length 108000 BitCount = 58 ID = 1337
0.619000 1 71x Rx d 1 42 Length 152000 BitCount = 80 ID = 113x
0.690000 1 539 Rx d 1 04 Length 106000 BitCount = 57 ID = 1337

View File

@@ -2,7 +2,7 @@ date Wed Jul 28 06:47:19 pm 2010
base hex timestamps absolute
internal events logged
// version 7.0.1
Begin Triggerblock Wed Jul 28 06:47:19 pm 2010
Begin TriggerBlock Wed Jul 28 06:47:19 pm 2010
0.000000 Start of measurement
0.005502 CAN 1 Status:chip status error active
0.005675 CAN 2 Status:chip status error active

View File

@@ -2,7 +2,7 @@ date Wed Jul 28 06:47:19 pm 2010
base hex timestamps absolute
internal events logged
// version 7.0.1
Begin Triggerblock Wed Jul 28 06:47:19 pm 2010
Begin TriggerBlock Wed Jul 28 06:47:19 pm 2010
0.000000 Start of measurement
0.005502 CAN 1 Status:chip status error active
0.005675 CAN 2 Status:chip status error active