Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 677efdf

Browse files
authored
Merge pull request #12 from astand/fix-opt
Structural refactoring and changes in fmon-* source code for making fmon-* driver's support a bit easier.
2 parents f986286 + 322becf commit 677efdf

25 files changed

+1161
-816
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
**/build*
22
loc-test*
3+
.vscode

docs/RELEASES.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Changelog
22

3+
## v2.3 19.07.2022
4+
5+
### Changed
6+
- The gGeneration and the file configurations are splitted to different structs
7+
- Specific generators moved to separated files (fmon, config)
8+
- FileWriter API more simple
9+
10+
### Added
11+
- FMon driver can be configured for using MONO function approach or
12+
dedicated function (how it was before) by setting _USE_MONO_FMON macro
13+
14+
---
15+
316
## v2.2 2022-05-07
417

518
### Fixed

src/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
88

99
add_executable(coderdbc
1010
${CMAKE_CURRENT_SOURCE_DIR}/codegen/c-main-generator.cpp
11+
${CMAKE_CURRENT_SOURCE_DIR}/codegen/mon-generator.cpp
12+
${CMAKE_CURRENT_SOURCE_DIR}/codegen/config-generator.cpp
1113
${CMAKE_CURRENT_SOURCE_DIR}/codegen/c-util-generator.cpp
1214
${CMAKE_CURRENT_SOURCE_DIR}/codegen/conditional-tree.cpp
1315
${CMAKE_CURRENT_SOURCE_DIR}/codegen/c-sigprinter.cpp
@@ -16,5 +18,6 @@ add_executable(coderdbc
1618
${CMAKE_CURRENT_SOURCE_DIR}/helpers/formatter.cpp
1719
${CMAKE_CURRENT_SOURCE_DIR}/parser/dbclineparser.cpp
1820
${CMAKE_CURRENT_SOURCE_DIR}/parser/dbcscanner.cpp
21+
${CMAKE_CURRENT_SOURCE_DIR}/app.cpp
1922
${CMAKE_CURRENT_SOURCE_DIR}/maincli.cpp
2023
)

src/app.cpp

Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
#include "app.h"
2+
#include <iostream>
3+
#include <memory>
4+
#include <fstream>
5+
#include <filesystem>
6+
#include <algorithm>
7+
#include <stdlib.h>
8+
#include "app.h"
9+
#include "parser/dbcscanner.h"
10+
#include "codegen/c-main-generator.h"
11+
#include "codegen/c-util-generator.h"
12+
#include "codegen/fs-creator.h"
13+
#include "codegen/version.h"
14+
#include <codegen/version.h>
15+
#include <helpers/formatter.h>
16+
17+
void CoderApp::Run()
18+
{
19+
if (ParseParams())
20+
{
21+
GenerateCode();
22+
}
23+
else
24+
{
25+
PrintHelp();
26+
}
27+
}
28+
29+
bool CoderApp::ParseParams()
30+
{
31+
for (size_t i = 0; i < Params.size(); i++)
32+
{
33+
if (Params[i].first.compare("-dbc") == 0)
34+
{
35+
dbc.value = Params[i].second;
36+
dbc.ok = true;
37+
}
38+
else if (Params[i].first.compare("-out") == 0)
39+
{
40+
outdir.value = Params[i].second;
41+
outdir.ok = true;
42+
}
43+
else if (Params[i].first.compare("-drvname") == 0)
44+
{
45+
drvname.value = make_c_name(Params[i].second);
46+
drvname.ok = true;
47+
48+
if (drvname.value.length() == 0)
49+
{
50+
drvname.ok = false;
51+
}
52+
}
53+
else if (Params[i].first.compare("-rw") == 0)
54+
{
55+
rewrite_src = true;
56+
}
57+
else if (Params[i].first.compare("-nodeutils") == 0)
58+
{
59+
gen_nodeutils = true;
60+
}
61+
else if (Params[i].first.compare("-help") == 0)
62+
{
63+
return false;
64+
}
65+
}
66+
67+
return (dbc.ok && outdir.ok && drvname.ok);
68+
}
69+
70+
void CoderApp::GenerateCode()
71+
{
72+
auto scanner = std::make_unique<DbcScanner>();
73+
auto cigen = std::make_unique<CiMainGenerator>();
74+
auto ciugen = std::make_unique<CiUtilGenerator>();
75+
auto fscreator = std::make_unique<FsCreator>();
76+
77+
std::ifstream reader;
78+
79+
std::cout << "dbc file : " << dbc.value << std::endl;
80+
std::cout << "gen path : " << outdir.value << std::endl;
81+
std::cout << "drv name : " << drvname.value << std::endl;
82+
83+
if (std::filesystem::exists(dbc.value) == false)
84+
{
85+
std::cout << "DBC file is not exists!" << std::endl;
86+
return;
87+
}
88+
89+
reader.open(dbc.value);
90+
91+
std::istream& s = reader;
92+
93+
scanner->TrimDbcText(s);
94+
95+
std::string info("");
96+
97+
// create main destination directory
98+
auto ret = fscreator->PrepareDirectory(drvname.value.c_str(), outdir.value.c_str(), rewrite_src, info);
99+
100+
if (ret)
101+
{
102+
cigen->Generate(scanner->dblist, fscreator->FS);
103+
}
104+
else
105+
{
106+
std::cout << "One or both are invalid\n";
107+
}
108+
109+
// check if option --node-utils is requested, when requested binutil generation
110+
// wiil be performed on each node from DBC file in accordance to its RX / TX subscription
111+
if (gen_nodeutils)
112+
{
113+
std::vector<std::string> nodes;
114+
115+
for (size_t num = 0; num < scanner->dblist.msgs.size(); num++)
116+
{
117+
// iterate all messages and collect All nodes assign to at least one message
118+
auto m = scanner->dblist.msgs[num];
119+
120+
for (size_t txs = 0; txs < m->TranS.size(); txs++)
121+
{
122+
std::string tx_node_name = m->TranS[txs];
123+
124+
if (std::find(nodes.begin(), nodes.end(), tx_node_name) == nodes.end())
125+
{
126+
// New node name. put it in the node collection
127+
nodes.push_back(tx_node_name);
128+
}
129+
}
130+
131+
for (size_t recs = 0; recs < m->RecS.size(); recs++)
132+
{
133+
std::string rx_node_name = m->RecS[recs];
134+
135+
// test all recs
136+
if (std::find(nodes.begin(), nodes.end(), rx_node_name) == nodes.end())
137+
{
138+
// New node name, put it in the node collection
139+
nodes.push_back(rx_node_name);
140+
}
141+
}
142+
}
143+
144+
// for each node in collection perform specific bin-util generation
145+
for (size_t node = 0; node < nodes.size(); node++)
146+
{
147+
std::string util_name = nodes[node] + "_" + drvname.value;
148+
149+
// set new driver name for current node
150+
fscreator->FS.gen.drvname = str_tolower(util_name);
151+
fscreator->FS.gen.DRVNAME = str_toupper(fscreator->FS.gen.drvname);
152+
fscreator->FS.file.util_c.dir = fscreator->FS.file.utildir;
153+
fscreator->FS.file.util_h.dir = fscreator->FS.file.utildir;
154+
155+
fscreator->FS.file.util_h.fname = str_tolower(fscreator->FS.gen.drvname + "-binutil.h");
156+
fscreator->FS.file.util_h.fpath = fscreator->FS.file.utildir + "/" + fscreator->FS.file.util_h.fname;
157+
158+
fscreator->FS.file.util_c.fname = str_tolower(fscreator->FS.gen.drvname + "-binutil.c");
159+
fscreator->FS.file.util_c.fpath = fscreator->FS.file.utildir + "/" + fscreator->FS.file.util_c.fname;
160+
161+
MsgsClassification groups;
162+
163+
for (size_t i = 0; i < scanner->dblist.msgs.size(); i++)
164+
{
165+
auto m = scanner->dblist.msgs[i];
166+
167+
bool found = (std::find(m->TranS.begin(), m->TranS.end(), nodes[node]) != m->TranS.end());
168+
169+
if (found)
170+
{
171+
// Message is in Tx array of current node
172+
groups.Tx.push_back(m->MsgID);
173+
}
174+
175+
found = (std::find(m->RecS.begin(), m->RecS.end(), nodes[node]) != m->RecS.end());
176+
177+
if (found)
178+
{
179+
// Message is in Rx array of current node
180+
groups.Rx.push_back(m->MsgID);
181+
}
182+
}
183+
184+
if (ret)
185+
{
186+
ciugen->Generate(scanner->dblist, fscreator->FS, groups, drvname.value);
187+
}
188+
}
189+
}
190+
else
191+
{
192+
MsgsClassification groups;
193+
194+
for (size_t i = 0; i < scanner->dblist.msgs.size(); i++)
195+
{
196+
groups.Rx.push_back(scanner->dblist.msgs[i]->MsgID);
197+
}
198+
199+
if (ret)
200+
{
201+
ciugen->Generate(scanner->dblist, fscreator->FS, groups, drvname.value);
202+
}
203+
}
204+
}
205+
206+
207+
void CoderApp::PrintHelp()
208+
{
209+
std::cout << "coderdbc v" << CODEGEN_LIB_VERSION_MAJ << "." << CODEGEN_LIB_VERSION_MIN << std::endl << std::endl;
210+
std::cout << "project source code:\thttps://github.com/astand/c-coderdbc\t\t" << std::endl;
211+
std::cout << "free web application:\thttps://coderdbc.com" << std::endl;
212+
std::cout << std::endl;
213+
std::cout << "required parameters:" << std::endl;
214+
215+
std::cout << " -dbc\t\t path to dbc file" << std::endl;
216+
std::cout << " -out\t\t directory for generated source files (must be pre-created)" << std::endl;
217+
std::cout << " -drvname\t driver name - will be used for naming driver parts" << std::endl;
218+
std::cout << std::endl;
219+
std::cout << "optional parameters:" << std::endl;
220+
std::cout << " -nodeutils\t will generate specific pairs of binutils drivers for each node" << std::endl;
221+
std::cout << " -rw\t\t by default each new generation with previously used params" << std::endl;
222+
std::cout << " \t\t will create new sud-directory with source files (000, 001, ... etc)" << std::endl;
223+
std::cout << " \t\t '-rw' option enables rewriting: all source files previously generated" << std::endl;
224+
std::cout << " \t\t will be replaced by new ones" << std::endl;
225+
std::cout << std::endl;
226+
227+
std::cout << "examples:" << std::endl;
228+
std::cout << std::endl;
229+
230+
std::cout <<
231+
"./dbccoder -dbc /home/user/docs/driveshaft.dbc -out /home/user/docs/gen/ -drvname drivedb -nodeutils -rw" << std::endl;
232+
233+
std::cout <<
234+
"./dbccoder -dbc /home/user/docs/driveshaft.dbc -out /home/user/docs/gen/ -drvname drivedb -nodeutils" << std::endl;
235+
236+
std::cout << "./dbccoder -dbc /home/user/docs/driveshaft.dbc -out /home/user/docs/gen/ -drvname drivedb" << std::endl;
237+
std::cout << std::endl;
238+
}

src/app.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#pragma once
2+
3+
#include <stdint.h>
4+
#include <vector>
5+
#include <string>
6+
7+
class CoderApp {
8+
public:
9+
CoderApp(const std::vector<std::pair<std::string, std::string>>& params) : Params(params) {}
10+
11+
void Run();
12+
13+
private:
14+
bool ParseParams();
15+
void GenerateCode();
16+
void PrintHelp();
17+
18+
typedef struct app
19+
{
20+
std::string value;
21+
bool ok{false};
22+
} StrParam_t;
23+
24+
const std::vector<std::pair<std::string, std::string>>& Params;
25+
26+
StrParam_t dbc{};
27+
StrParam_t outdir{};
28+
StrParam_t drvname{};
29+
30+
bool rewrite_src{false};
31+
bool gen_nodeutils{false};
32+
};

0 commit comments

Comments
 (0)