From fc7fffe6a45e98e34ae012f61dd36fa0a54f0454 Mon Sep 17 00:00:00 2001 From: Jerry Mailloux Date: Sun, 21 Apr 2024 17:24:19 -0400 Subject: [PATCH 1/4] Fix memory corruption (marker was getting overflowed because some strings are 8 characters. With the null chararacter, it needed to be 9 chars. It was only 8. Also, fixed the non rw option. --- src/app.cpp | 14 ++++++- src/codegen/fs-creator.cpp | 77 +++++++++++++------------------------- src/codegen/fs-creator.h | 5 +-- src/parser/dbcscanner.cpp | 25 +++++-------- 4 files changed, 49 insertions(+), 72 deletions(-) diff --git a/src/app.cpp b/src/app.cpp index f5a57c3..634ce0b 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -35,6 +35,7 @@ void CoderApp::GenerateCode() CiMainGenerator cigen; CiUtilGenerator ciugen; FsCreator fscreator; + std::string path; std::ifstream reader; @@ -57,9 +58,18 @@ void CoderApp::GenerateCode() std::string info(""); // create main destination directory - fscreator.Configure(Params.drvname.first, Params.outdir.first, info, scanner.dblist.ver.hi, scanner.dblist.ver.low); + if (!Params.is_rewrite) + { + path = fscreator.FindPath(Params.outdir.first); + } + else + { + path = Params.outdir.first; + } + + fscreator.Configure(Params.drvname.first, path, info, scanner.dblist.ver.hi, scanner.dblist.ver.low); - auto ret = fscreator.PrepareDirectory(Params.is_rewrite); + auto ret = fscreator.PrepareDirectory(); fscreator.FS.gen.no_config = Params.is_noconfig; fscreator.FS.gen.no_inc = Params.is_nocanmon; diff --git a/src/codegen/fs-creator.cpp b/src/codegen/fs-creator.cpp index 15e08f2..2e87577 100644 --- a/src/codegen/fs-creator.cpp +++ b/src/codegen/fs-creator.cpp @@ -1,4 +1,5 @@ #include +#include #include #include "fs-creator.h" #include "helpers/formatter.h" @@ -17,6 +18,23 @@ FsCreator::FsCreator() { } +std::string FsCreator::FindPath(const std::string& outpath) +{ + std::string work_dir_path; + std::string separator = work_dir_path.back() == '/' ? "" : "/"; + + for (uint32_t dirnum = 0; dirnum < 1000; dirnum++) + { + snprintf(_tmpb, kTmpLen, "%03d", dirnum); + work_dir_path = outpath + separator + _tmpb; + + if (!std::filesystem::exists(work_dir_path)) + { + break; + } + } + return work_dir_path; +} void FsCreator::Configure(const std::string& drvname, const std::string& outpath, const std::string& info, uint32_t h, uint32_t l) @@ -94,61 +112,18 @@ void FsCreator::Configure(const std::string& drvname, const std::string& outpath FS.gen.lowver = l; } -bool FsCreator::PrepareDirectory(bool rw) +bool FsCreator::PrepareDirectory() { bool ret = false; - - // find free directory - struct stat info; - - std::string work_dir_path; + std::error_code ec; const auto& basepath = FS.file.core_h.dir; - if (rw) - { - work_dir_path = basepath; - ret = true; - - // for this case check only if directory exists - if (stat(work_dir_path.c_str(), &info) != 0) - { - if (!std::filesystem::create_directory(work_dir_path)) - { - ret = false; - } - } - } - else + std::filesystem::create_directories(basepath, ec); + if (ec) { - std::string separator = basepath.back() == '/' ? "" : "/"; - - for (int32_t dirnum = 0; dirnum < 1000; dirnum++) - { - snprintf(_tmpb, kTmpLen, "%03d", dirnum); - work_dir_path = basepath + separator + _tmpb; - - if (stat(work_dir_path.c_str(), &info) != 0) - { - if (std::filesystem::create_directory(work_dir_path)) - { - ret = true; - break; - } - } - else if (info.st_mode & S_IFDIR) - { - // directory exists, try next num - continue; - } - else - { - if (std::filesystem::create_directory(work_dir_path) != 0) - { - ret = false; - break; - } - } - } + // If there is an error, ec will evaluate to true + std::cerr << "Error creating directories: " << ec.message() << std::endl; + return false; } std::filesystem::create_directory(FS.file.libdir); @@ -157,7 +132,7 @@ bool FsCreator::PrepareDirectory(bool rw) std::filesystem::create_directory(FS.file.confdir); std::filesystem::create_directory(FS.file.utildir); - return ret; + return true; } std::string FsCreator::CreateSubDir(std::string basepath, std::string sub, bool rw) diff --git a/src/codegen/fs-creator.h b/src/codegen/fs-creator.h index 4bf649f..aa3fc87 100644 --- a/src/codegen/fs-creator.h +++ b/src/codegen/fs-creator.h @@ -68,13 +68,12 @@ typedef struct class FsCreator { public: FsCreator(); - + std::string FindPath(const std::string& outpath); void Configure(const std::string& drvname, const std::string& outpath, const std::string& info, uint32_t h, uint32_t l); - bool PrepareDirectory(bool rw); + bool PrepareDirectory(); std::string CreateSubDir(std::string basepath, std::string subdir, bool rm = true); AppSettings_t FS; }; - diff --git a/src/parser/dbcscanner.cpp b/src/parser/dbcscanner.cpp index e9e9e13..0c694b1 100644 --- a/src/parser/dbcscanner.cpp +++ b/src/parser/dbcscanner.cpp @@ -1,5 +1,6 @@ #include "dbcscanner.h" #include +#include #include #include #include "../helpers/formatter.h" @@ -341,23 +342,15 @@ void DbcScanner::SetDefualtMessage(MessageDescriptor_t* message) void DbcScanner::FindVersion(const std::string& instr) { // try to find version string which looks like: VERSION "x.x" - static constexpr char* versionAttr = (char*)"VERSION"; - static constexpr size_t VER_MIN_LENGTH = strlen(versionAttr); - + std::istringstream iss(instr); + std::string marker; + char token; uint32_t h = 0, l = 0; - char marker[VER_MIN_LENGTH + 1u]; - - if (instr.size() < VER_MIN_LENGTH) - { - return; - } - auto ret = std::sscanf(instr.c_str(), "%8s \"%u.%u\"", marker, &h, &l); - - if ((ret == 3) && (std::strcmp(marker, versionAttr) == 0)) - { - // versions have been found, save numeric values - dblist.ver.hi = h; - dblist.ver.low = l; + if (iss >> marker >> token && token == '"' && marker == "VERSION") { + if (iss >> h >> token && token == '.' && iss >> l) { + dblist.ver.hi = h; + dblist.ver.low = l; + } } } From a58dfbe59304ef204115407a15e85fb7c574fcaa Mon Sep 17 00:00:00 2001 From: Jerry Mailloux Date: Mon, 19 Aug 2024 15:28:05 -0400 Subject: [PATCH 2/4] Fix bug where maxDlcValue wouldn't be updated if the last message in the list was the biggest message --- src/codegen/c-main-generator.cpp | 1 - src/parser/dbcscanner.cpp | 12 ++++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/codegen/c-main-generator.cpp b/src/codegen/c-main-generator.cpp index 0bcec02..377c6b7 100644 --- a/src/codegen/c-main-generator.cpp +++ b/src/codegen/c-main-generator.cpp @@ -879,4 +879,3 @@ void CiMainGenerator::PrintPackCommonText(const std::string& arrtxt, const CiExp fwriter.Append(); } } - diff --git a/src/parser/dbcscanner.cpp b/src/parser/dbcscanner.cpp index 0c694b1..e99c281 100644 --- a/src/parser/dbcscanner.cpp +++ b/src/parser/dbcscanner.cpp @@ -79,12 +79,6 @@ void DbcScanner::ParseMessageInfo(istream& readstrm) // New message line has been found if (lparser.IsMessageLine(sline)) { - // if actual message, check DLC value for being max - if ((pMsg != nullptr) && (pMsg->DLC > dblist.maxDlcValue)) - { - dblist.maxDlcValue = pMsg->DLC; - } - // the message will be added only if pMsg is not nullptr AddMessage(pMsg); @@ -99,6 +93,12 @@ void DbcScanner::ParseMessageInfo(istream& readstrm) delete pMsg; pMsg = nullptr; } + + // if actual message, check DLC value for being max + if ((pMsg != nullptr) && (pMsg->DLC > dblist.maxDlcValue)) + { + dblist.maxDlcValue = pMsg->DLC; + } } if (pMsg != nullptr && lparser.IsSignalLine(sline)) From b787230cffbab9e86dcc39dd73a7adc7d35637e5 Mon Sep 17 00:00:00 2001 From: Jerry Mailloux Date: Sun, 15 Dec 2024 20:58:27 -0500 Subject: [PATCH 3/4] Files generated are now .cpp, .hpp in a flat folder structure _CYC defines are generated even if cycle time is 0 f suffix is used in number constants to specify float --- src/app.cpp | 8 +++---- src/codegen/c-main-generator.cpp | 37 +++++++++---------------------- src/codegen/c-util-generator.cpp | 9 ++------ src/codegen/c-util-generator.h | 2 +- src/codegen/config-generator.cpp | 14 ++++++------ src/codegen/fs-creator.cpp | 22 +++++++++--------- src/codegen/mon-generator.cpp | 11 +++------ src/helpers/formatter.cpp | 2 ++ test/gencode/conf/testdb-config.h | 16 ++++++------- 9 files changed, 49 insertions(+), 72 deletions(-) diff --git a/src/app.cpp b/src/app.cpp index 634ce0b..9dbf30f 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -130,10 +130,10 @@ void CoderApp::GenerateCode() fscreator.FS.file.util_c.dir = fscreator.FS.file.utildir; fscreator.FS.file.util_h.dir = fscreator.FS.file.utildir; - fscreator.FS.file.util_h.fname = str_tolower(fscreator.FS.gen.drvname + "-binutil.h"); + fscreator.FS.file.util_h.fname = str_tolower(fscreator.FS.gen.drvname + "-binutil.hpp"); fscreator.FS.file.util_h.fpath = fscreator.FS.file.utildir + "/" + fscreator.FS.file.util_h.fname; - fscreator.FS.file.util_c.fname = str_tolower(fscreator.FS.gen.drvname + "-binutil.c"); + fscreator.FS.file.util_c.fname = str_tolower(fscreator.FS.gen.drvname + "-binutil.cpp"); fscreator.FS.file.util_c.fpath = fscreator.FS.file.utildir + "/" + fscreator.FS.file.util_c.fname; MsgsClassification groups; @@ -207,8 +207,8 @@ void CoderApp::PrintHelp() std::cout << " \t\t '-rw' option enables rewriting: all source files previously generated" << std::endl; std::cout << " \t\t will be replaced by new ones" << std::endl; std::cout << " -noconfig:\t no {drivername}-config and dbccodeconfig generation" << std::endl; - std::cout << " -noinc:\t no canmonitorutil.h generation" << std::endl; - std::cout << " -nofmon:\t no ***-fmon.c generation" << std::endl; + std::cout << " -noinc:\t no canmonitorutil.hpp generation" << std::endl; + std::cout << " -nofmon:\t no ***-fmon.cpp generation" << std::endl; std::cout << std::endl; std::cout << "examples:" << std::endl; diff --git a/src/codegen/c-main-generator.cpp b/src/codegen/c-main-generator.cpp index 377c6b7..a2cbd98 100644 --- a/src/codegen/c-main-generator.cpp +++ b/src/codegen/c-main-generator.cpp @@ -24,7 +24,7 @@ const char* extend_func_body = "// n+1 bits where n is the largest signed signal width. For example if\n" "// the most wide signed signal has a width of 31 bits you need to set\n" "// bitext_t as int32_t and ubitext_t as uint32_t\n" - "// Defined these typedefs in @dbccodeconf.h or locally in 'dbcdrvname'-config.h\n" + "// Defined these typedefs in @dbccodeconf.hpp or locally in 'dbcdrvname'-config.hpp\n" "static bitext_t %s(ubitext_t val, uint8_t bits)\n" "{\n" " ubitext_t const m = 1u << (bits - 1);\n" @@ -66,10 +66,10 @@ void CiMainGenerator::Generate(DbcMessageList_t& dlist, const AppSettings_t& fsd if (!fsd.gen.no_config) { - // 6 step is to print template for drv-config.h + // 6 step is to print template for drv-config.hpp Gen_ConfigHeader(); - // 8 step is to print dbccodeconf.h template + // 8 step is to print dbccodeconf.hpp template Gen_DbcCodeConf(); } @@ -93,8 +93,6 @@ void CiMainGenerator::Gen_MainHeader() fwriter.Append("#pragma once"); fwriter.Append(); - fwriter.Append("#ifdef __cplusplus\nextern \"C\" {\n#endif"); - fwriter.Append(); fwriter.Append("#include "); fwriter.Append(); @@ -104,7 +102,7 @@ void CiMainGenerator::Gen_MainHeader() fwriter.Append(); fwriter.Append("// include current dbc-driver compilation config"); - fwriter.Append("#include \"%s-config.h\"", fdesc->gen.drvname.c_str()); + fwriter.Append("#include \"%s-config.hpp\"", fdesc->gen.drvname.c_str()); fwriter.Append(); fwriter.Append("#ifdef %s", fdesc->gen.usemon_def.c_str()); @@ -112,7 +110,7 @@ void CiMainGenerator::Gen_MainHeader() fwriter.Append( "// This file must define:\n" "// base monitor struct\n" - "#include \"canmonitorutil.h\"\n" + "#include \"canmonitorutil.hpp\"\n" "\n" ); @@ -169,10 +167,7 @@ void CiMainGenerator::Gen_MainHeader() fwriter.Append("#define %s_DLC (%uU)", m.Name.c_str(), m.DLC); fwriter.Append("#define %s_CANID (%#xU)", m.Name.c_str(), m.MsgID); - if (m.Cycle > 0) - { - fwriter.Append("#define %s_CYC (%dU)", m.Name.c_str(), m.Cycle); - } + fwriter.Append("#define %s_CYC (%dU)", m.Name.c_str(), m.Cycle); size_t max_sig_name_len = 27; @@ -328,8 +323,6 @@ void CiMainGenerator::Gen_MainHeader() fwriter.Append(); } - fwriter.Append("#ifdef __cplusplus\n}\n#endif"); - // save fwrite cached text to file fwriter.Flush(fdesc->file.core_h.fpath); } @@ -362,7 +355,7 @@ void CiMainGenerator::Gen_MainSource() "// Function prototypes to be called each time CAN frame is unpacked\n" "// FMon function may detect RC, CRC or DLC violation\n"); - fwriter.Append("#include \"%s-fmon.h\"", fdesc->gen.drvname.c_str()); + fwriter.Append("#include \"%s-fmon.hpp\"", fdesc->gen.drvname.c_str()); fwriter.Append(); fwriter.Append("#endif // %s", fdesc->gen.usemon_def.c_str()); @@ -370,7 +363,7 @@ void CiMainGenerator::Gen_MainSource() fwriter.Append("// This macro guard for the case when you need to enable"); fwriter.Append("// using diag monitors but there is no necessity in proper"); fwriter.Append("// SysTick provider. For providing one you need define macro"); - fwriter.Append("// before this line - in dbccodeconf.h"); + fwriter.Append("// before this line - in dbccodeconf.hpp"); fwriter.Append(""); fwriter.Append("#ifndef GetSystemTick"); fwriter.Append("#define GetSystemTick() (0u)"); @@ -452,7 +445,7 @@ void CiMainGenerator::Gen_ConfigHeader() ConfigGenerator confgen; confgen.FillHeader(fwriter, fdesc->gen); - fwriter.Flush(fdesc->file.confdir + '/' + fdesc->gen.drvname + "-config.h"); + fwriter.Flush(fdesc->file.confdir + '/' + fdesc->gen.drvname + "-config.hpp"); } void CiMainGenerator::Gen_FMonHeader() @@ -475,10 +468,6 @@ void CiMainGenerator::Gen_CanMonUtil() fwriter.Append(""); fwriter.Append("#include "); fwriter.Append(""); - fwriter.Append("#ifdef __cplusplus"); - fwriter.Append("extern \"C\" {"); - fwriter.Append("#endif"); - fwriter.Append(""); fwriter.Append("// declare here all availible checksum algorithms"); fwriter.Append("typedef enum"); fwriter.Append("{"); @@ -520,12 +509,8 @@ void CiMainGenerator::Gen_CanMonUtil() fwriter.Append(""); fwriter.Append("} FrameMonitor_t;"); fwriter.Append(""); - fwriter.Append("#ifdef __cplusplus"); - fwriter.Append("}"); - fwriter.Append("#endif"); - fwriter.Append(""); - fwriter.Flush(fdesc->file.incdir + '/' + "canmonitorutil.h"); + fwriter.Flush(fdesc->file.incdir + '/' + "canmonitorutil.hpp"); } void CiMainGenerator::Gen_DbcCodeConf() @@ -562,7 +547,7 @@ void CiMainGenerator::Gen_DbcCodeConf() fwriter.Append("// #define GetFrameHash(a,b,c,d,e) __get_hash__(a,b,c,d,e)"); fwriter.Append(""); - fwriter.Flush(fdesc->file.confdir + '/' + "dbccodeconf.h"); + fwriter.Flush(fdesc->file.confdir + '/' + "dbccodeconf.hpp"); } void CiMainGenerator::WriteSigStructField(const SignalDescriptor_t& sig, bool bits, size_t padwidth) diff --git a/src/codegen/c-util-generator.cpp b/src/codegen/c-util-generator.cpp index 8d3c2c3..9e2f8db 100644 --- a/src/codegen/c-util-generator.cpp +++ b/src/codegen/c-util-generator.cpp @@ -110,15 +110,12 @@ void CiUtilGenerator::PrintHeader() tof.Append("#pragma once"); tof.Append(); - tof.Append(openguard); - tof.Append(); - // include common dbc code config header - tof.Append("#include \"dbccodeconf.h\""); + tof.Append("#include "); tof.Append(); // include c-main driver header - tof.Append("#include \"%s.h\"", file_drvname.c_str()); + tof.Append("#include \"%s.hpp\"", file_drvname.c_str()); tof.Append(); @@ -190,8 +187,6 @@ void CiUtilGenerator::PrintHeader() tof.Append(); } - tof.Append(closeguard); - tof.Flush(fdesc->util_h.fpath); } diff --git a/src/codegen/c-util-generator.h b/src/codegen/c-util-generator.h index adce69f..ff33a42 100644 --- a/src/codegen/c-util-generator.h +++ b/src/codegen/c-util-generator.h @@ -19,7 +19,7 @@ class CiUtilGenerator { // the output of this function source files which contain: // - global TX and RX typedefs message struct // - function to Unpack incoming frame to dedicated RX message struct field - // - optional (through define in global "dbccodeconf.h") variable allocation in source files + // - optional (through define in global "dbccodeconf.hpp") variable allocation in source files // void Generate(DbcMessageList_t& dlist, const AppSettings_t& fsd, const MsgsClassification& groups, const std::string& drvname); diff --git a/src/codegen/config-generator.cpp b/src/codegen/config-generator.cpp index a50f44a..e4ca0f9 100644 --- a/src/codegen/config-generator.cpp +++ b/src/codegen/config-generator.cpp @@ -5,7 +5,7 @@ void ConfigGenerator::FillHeader(FileWriter& wr, const GenDescriptor_t& gsett) wr.Append("#pragma once"); wr.Append(""); wr.Append("/* include common dbccode configurations */"); - wr.Append("#include \"dbccodeconf.h\""); + wr.Append("#include "); wr.Append(""); wr.Append(""); wr.Append("/* ------------------------------------------------------------------------- *"); @@ -28,7 +28,7 @@ void ConfigGenerator::FillHeader(FileWriter& wr, const GenDescriptor_t& gsett) wr.Append(" u8 Data[8] (CAN Frame payload data)"); wr.Append(" u8 IDE (CAN Frame Extended (1) / Standard (0) ID type)"); wr.Append(""); - wr.Append(" This struct definition have to be placed (or be included) in dbccodeconf.h */"); + wr.Append(" This struct definition have to be placed (or be included) in dbccodeconf.hpp */"); wr.Append(""); wr.Append("/* #define %s */", gsett.usesruct_def.c_str()); wr.Append(2); @@ -43,7 +43,7 @@ void ConfigGenerator::FillHeader(FileWriter& wr, const GenDescriptor_t& gsett) wr.Append(" 1. All the '_ro' fields will have a pair field with '_phys' postfix."); wr.Append(" If only offset != 0 is true then the type of '_phys' signal is the same"); wr.Append(" as '_ro' signal. In other case the type will be @sigfloat_t which"); - wr.Append(" have to be defined in user dbccodeconf.h"); + wr.Append(" have to be defined in user dbccodeconf.hpp"); wr.Append(""); wr.Append(" 2. In pack function '_ro' signal will be rewritten by '_phys' signal, which"); wr.Append(" requires from user to use ONLY '_phys' signal for packing frame"); @@ -55,7 +55,7 @@ void ConfigGenerator::FillHeader(FileWriter& wr, const GenDescriptor_t& gsett) wr.Append(2); wr.Append("/* ------------------------------------------------------------------------- *"); - wr.Append(" Note(!) that the \"canmonitorutil.h\" must be accessed in include path:"); + wr.Append(" Note(!) that the \"canmonitorutil.hpp\" must be accessed in include path:"); wr.Append(""); wr.Append(" This macro adds:"); wr.Append(""); @@ -63,7 +63,7 @@ void ConfigGenerator::FillHeader(FileWriter& wr, const GenDescriptor_t& gsett) wr.Append(""); wr.Append(" - capture system tick in unpack function and save value to mon1 field"); wr.Append(" to provide to user better missing frame detection code. For this case"); - wr.Append(" user must provide function declared in canmonitorutil.h - GetSysTick()"); + wr.Append(" user must provide function declared in canmonitorutil.hpp - GetSysTick()"); wr.Append(" which may return 1ms uptime."); wr.Append(""); wr.Append(" - calling function FMon_*** (from 'fmon' driver) inside unpack function"); @@ -95,8 +95,8 @@ void ConfigGenerator::FillHeader(FileWriter& wr, const GenDescriptor_t& gsett) wr.Append(" - \"Checksum\": constant marker word"); wr.Append(""); wr.Append(" - \"XOR8\": type of method, this text will be passed to GetFrameHash"); - wr.Append(" (canmonitorutil.h) function as is, the best use case is to define 'enum"); - wr.Append(" DbcCanCrcMethods' in canmonitorutil.h file with all possible"); + wr.Append(" (canmonitorutil.hpp) function as is, the best use case is to define 'enum"); + wr.Append(" DbcCanCrcMethods' in canmonitorutil.hpp file with all possible"); wr.Append(" checksum algorithms (e.g. XOR8, XOR4 etc)"); wr.Append(""); wr.Append(" - \"3\": optional value that will be passed to GetFrameHash as integer value"); diff --git a/src/codegen/fs-creator.cpp b/src/codegen/fs-creator.cpp index 2e87577..d3216a7 100644 --- a/src/codegen/fs-creator.cpp +++ b/src/codegen/fs-creator.cpp @@ -8,11 +8,11 @@ static const int32_t kTmpLen = 1024; static char _tmpb[kTmpLen]; -static const char* kLibDir = "/lib"; -static const char* kUsrDir = "/usr"; -static const char* kIncDir = "/inc"; -static const char* kConfDir = "/conf"; -static const char* kUtilDir = "/butl"; +static const char* kLibDir = "/"; +static const char* kUsrDir = "/"; +static const char* kIncDir = "/"; +static const char* kConfDir = "/"; +static const char* kUtilDir = "/"; FsCreator::FsCreator() { @@ -50,27 +50,27 @@ void FsCreator::Configure(const std::string& drvname, const std::string& outpath FS.gen.drvname = str_tolower(drvname); FS.file.core_h.dir = outpath; - FS.file.core_h.fname = FS.gen.drvname + ".h"; + FS.file.core_h.fname = FS.gen.drvname + ".hpp"; FS.file.core_h.fpath = FS.file.libdir + "/" + FS.file.core_h.fname; FS.file.core_c.dir = outpath; - FS.file.core_c.fname = FS.gen.drvname + ".c"; + FS.file.core_c.fname = FS.gen.drvname + ".cpp"; FS.file.core_c.fpath = FS.file.libdir + "/" + FS.file.core_c.fname; FS.file.util_h.dir = outpath; - FS.file.util_h.fname = FS.gen.drvname + "-binutil" + ".h"; + FS.file.util_h.fname = FS.gen.drvname + "-binutil" + ".hpp"; FS.file.util_h.fpath = FS.file.utildir + "/" + FS.file.util_h.fname; FS.file.util_c.dir = outpath; - FS.file.util_c.fname = FS.gen.drvname + "-binutil" + ".c"; + FS.file.util_c.fname = FS.gen.drvname + "-binutil" + ".cpp"; FS.file.util_c.fpath = FS.file.utildir + "/" + FS.file.util_c.fname; FS.file.fmon_h.dir = outpath; - FS.file.fmon_h.fname = FS.gen.drvname + "-fmon.h"; + FS.file.fmon_h.fname = FS.gen.drvname + "-fmon.hpp"; FS.file.fmon_h.fpath = FS.file.libdir + "/" + FS.file.fmon_h.fname; FS.file.fmon_c.dir = outpath; - FS.file.fmon_c.fname = FS.gen.drvname + "-fmon.c"; + FS.file.fmon_c.fname = FS.gen.drvname + "-fmon.cpp"; FS.file.fmon_c.fpath = FS.file.usrdir + "/" + FS.file.fmon_c.fname; snprintf(_tmpb, kTmpLen, "%s_USE_BITS_SIGNAL", FS.gen.DRVNAME.c_str()); diff --git a/src/codegen/mon-generator.cpp b/src/codegen/mon-generator.cpp index ea84195..d92697a 100644 --- a/src/codegen/mon-generator.cpp +++ b/src/codegen/mon-generator.cpp @@ -12,27 +12,24 @@ uint32_t MonGenerator::FillHeader(FileWriter& wr, std::vector& sigs, wr.Append("#pragma once"); wr.Append(); - wr.Append("#ifdef __cplusplus\nextern \"C\" {\n#endif"); - wr.Append(); - wr.Append("// DBC file version"); wr.Append("#define %s_FMON (%uU)", aset.gen.verhigh_def.c_str(), aset.gen.hiver); wr.Append("#define %s_FMON (%uU)", aset.gen.verlow_def.c_str(), aset.gen.lowver); wr.Append(); - wr.Append("#include \"%s-config.h\"", aset.gen.drvname.c_str()); + wr.Append("#include \"%s-config.hpp\"", aset.gen.drvname.c_str()); wr.Append(); // put diagmonitor ifdef selection for including @drv-fmon header // with FMon_* signatures to call from unpack function wr.Append("#ifdef %s", aset.gen.usemon_def.c_str()); wr.Append(); - wr.Append("#include \"canmonitorutil.h\""); + wr.Append("#include \"canmonitorutil.hpp\""); wr.Append("/*\n\ This file contains the prototypes of all the functions that will be called\n\ from each Unpack_*name* function to detect DBC related errors\n\ It is the user responsibility to defined these functions in the\n\ -separated .c file. If it won't be done the linkage error will happen\n*/"); +separated .cpp file. If it won't be done the linkage error will happen\n*/"); wr.Append(); wr.Append("#ifdef %s_USE_MONO_FMON", aset.gen.DRVNAME.c_str()); @@ -78,8 +75,6 @@ separated .c file. If it won't be done the linkage error will happen\n*/"); wr.Append("#endif // %s", aset.gen.usemon_def.c_str()); wr.Append(); - wr.Append("#ifdef __cplusplus\n}\n#endif"); - return 0; } diff --git a/src/helpers/formatter.cpp b/src/helpers/formatter.cpp index fd45a22..27b4be6 100644 --- a/src/helpers/formatter.cpp +++ b/src/helpers/formatter.cpp @@ -164,6 +164,7 @@ std::string prt_double(double value, size_t precision, bool usedot) { s += ".0"; } + s += "f"; return s; } @@ -197,6 +198,7 @@ std::string prt_double(double value, size_t precision, bool usedot) // xxx.x(x) s.resize(dotpos + addtail + 1); } + s += "f"; return s; } diff --git a/test/gencode/conf/testdb-config.h b/test/gencode/conf/testdb-config.h index cf92cef..9419168 100644 --- a/test/gencode/conf/testdb-config.h +++ b/test/gencode/conf/testdb-config.h @@ -51,7 +51,7 @@ /* ------------------------------------------------------------------------- * - Note(!) that the "canmonitorutil.h" must be accessed in include path: + Note(!) that the "canmonitorutil.hpp" must be accessed in include path: This macro adds: @@ -59,7 +59,7 @@ - capture system tick in unpack function and save value to mon1 field to provide to user better missing frame detection code. For this case - user must provide function declared in canmonitorutil.h - GetSysTick() + user must provide function declared in canmonitorutil.hpp - GetSysTick() which may return 1ms uptime. - calling function FMon_*** (from 'fmon' driver) inside unpack function @@ -91,8 +91,8 @@ - "Checksum": constant marker word - "XOR8": type of method, this text will be passed to GetFrameHash - (canmonitorutil.h) function as is, the best use case is to define 'enum - DbcCanCrcMethods' in canmonitorutil.h file with all possible + (canmonitorutil.hpp) function as is, the best use case is to define 'enum + DbcCanCrcMethods' in canmonitorutil.hpp file with all possible checksum algorithms (e.g. XOR8, XOR4 etc) - "3": optional value that will be passed to GetFrameHash as integer value @@ -109,18 +109,18 @@ /* ------------------------------------------------------------------------- * - FMon handling model can be build in two ways: + FMon handling model can be build in two ways: - 1 - Default. In this case when specific frame unpack is called the + 1 - Default. In this case when specific frame unpack is called the specific FMon_{Frame name}_{driver name} functoin will be called. User's code scope has to define each of these functions. Each function is responsible for the error handling of one frame - 2 - MONO. In this case there is only one function to perform any frame + 2 - MONO. In this case there is only one function to perform any frame monitoring. This function has to be implemented in the user's code scope. This function is named as FMon_MONO_{driver name}. It takes frame id which can be used for selection of the logic for a frame monitoring. - This mode costs a bit more in runtime but when you often edit you DBC and you + This mode costs a bit more in runtime but when you often edit you DBC and you have more than one project it could be more maintanable (there is no necessity to replace source code) From c18bd0538eeac2f4d7882e490697fa216842ea80 Mon Sep 17 00:00:00 2001 From: Jerry Mailloux Date: Mon, 16 Dec 2024 11:11:34 -0500 Subject: [PATCH 4/4] Update how canmonitorutil is included. --- src/codegen/c-main-generator.cpp | 2 +- src/codegen/mon-generator.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/codegen/c-main-generator.cpp b/src/codegen/c-main-generator.cpp index a2cbd98..cc86376 100644 --- a/src/codegen/c-main-generator.cpp +++ b/src/codegen/c-main-generator.cpp @@ -110,7 +110,7 @@ void CiMainGenerator::Gen_MainHeader() fwriter.Append( "// This file must define:\n" "// base monitor struct\n" - "#include \"canmonitorutil.hpp\"\n" + "#include \n" "\n" ); diff --git a/src/codegen/mon-generator.cpp b/src/codegen/mon-generator.cpp index d92697a..4549d64 100644 --- a/src/codegen/mon-generator.cpp +++ b/src/codegen/mon-generator.cpp @@ -24,7 +24,7 @@ uint32_t MonGenerator::FillHeader(FileWriter& wr, std::vector& sigs, // with FMon_* signatures to call from unpack function wr.Append("#ifdef %s", aset.gen.usemon_def.c_str()); wr.Append(); - wr.Append("#include \"canmonitorutil.hpp\""); + wr.Append("#include "); wr.Append("/*\n\ This file contains the prototypes of all the functions that will be called\n\ from each Unpack_*name* function to detect DBC related errors\n\