Skip to content

Commit bc9d54b

Browse files
committed
Added command line option to turn on or off the code generation based on multiplexor master signal values for multiplexed signals.
By default it is off so this new code has no affect.
1 parent 5df33a0 commit bc9d54b

File tree

5 files changed

+29
-17
lines changed

5 files changed

+29
-17
lines changed

src/app.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ void CoderApp::GenerateCode()
145145

146146
if (ret)
147147
{
148-
cigen.Generate(scanner.dblist, fscreator.FS);
148+
cigen.Generate(scanner.dblist, fscreator.FS, Params.is_multiplex_enabled);
149149
}
150150
else
151151
{
@@ -283,8 +283,8 @@ void CoderApp::PrintHelp()
283283
std::cout << " -nofmon:\t no ***-fmon.c generation" << std::endl;
284284
std::cout << std::endl;
285285
std::cout << " -driverdir\t the output path (-out) will be appended by driver name" << std::endl;
286-
std::cout << " -gendate\t the generation date will be included in the header comment section of the source file." <<
287-
std::endl;
286+
std::cout << " -gendate\t the generation date will be included in the header comment section of the source file." << std::endl;
287+
std::cout << " -multiplex or -muxgen\t enable multiplex signal packing/unpacking code generation based on multiplexor master signal values for multiplexed signals." << std::endl;
288288
std::cout << std::endl;
289289

290290
std::cout << "examples:" << std::endl;
@@ -295,10 +295,7 @@ void CoderApp::PrintHelp()
295295
<< std::endl;
296296
std::cout << "./dbccoder -dbc /home/user/docs/driveshaft.dbc -out /home/user/docs/gen/ -drvname drivedb -nodeutils -rw"
297297
<< std::endl;
298-
299-
std::cout <<
300-
"./dbccoder -dbc /home/user/docs/driveshaft.dbc -out /home/user/docs/gen/ -drvname drivedb -nodeutils" << std::endl;
301-
298+
std::cout << "./dbccoder -dbc /home/user/docs/driveshaft.dbc -out /home/user/docs/gen/ -drvname drivedb -nodeutils" << std::endl;
302299
std::cout << "./dbccoder -dbc /home/user/docs/driveshaft.dbc -out /home/user/docs/gen/ -drvname drivedb" << std::endl;
303300
std::cout << std::endl;
304301
}

src/codegen/c-main-generator.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@ const char* extend_func_body =
3131
" return ((val ^ m) - m);\n"
3232
"}\n\n";
3333

34-
void CiMainGenerator::Generate(DbcMessageList_t& dlist, const AppSettings_t& fsd)
34+
void CiMainGenerator::Generate(DbcMessageList_t& dlist, const AppSettings_t& fsd, bool mux_enabled)
3535
{
36+
// set multiplexor master signal values is enabled for multiplexed signals
37+
is_multiplex_enabled = mux_enabled;
38+
3639
// Load income messages to sig printer
3740
sigprt.LoadMessages(dlist.msgs);
3841

@@ -714,13 +717,15 @@ void CiMainGenerator::WriteUnpackBody(const CiExpr_t* sgs)
714717

715718
// Check if the signal is multiplexed
716719
bool isMultiplexed = (signal.Multiplex == MultiplexType::kMulValue);
717-
if (isMultiplexed)
720+
721+
// Generate the if statement only if multiplex is enabled
722+
if (is_multiplex_enabled && isMultiplexed)
718723
{
719724
fwriter.Append(" if (_m->%s == %d) {", masterSignal->Name.c_str(), signal.MultiplexValue);
720725
}
721726

722727
// Set the indentation level based on whether the signal is multiplexed
723-
const char* indent = isMultiplexed ? " " : " ";
728+
const char* indent = (is_multiplex_enabled && isMultiplexed) ? " " : " ";
724729

725730
// Unpack the signal
726731
if (signal.Signed)
@@ -757,8 +762,8 @@ void CiMainGenerator::WriteUnpackBody(const CiExpr_t* sgs)
757762
fwriter.Append("");
758763
}
759764

760-
// Close the if statement if the signal was multiplexed
761-
if (isMultiplexed)
765+
// Close the if statement if the signal was multiplexed and if multiplexing is enabled
766+
if (is_multiplex_enabled && isMultiplexed)
762767
{
763768
fwriter.Append(" }");
764769
}
@@ -811,6 +816,7 @@ void CiMainGenerator::WriteUnpackBody(const CiExpr_t* sgs)
811816
fwriter.Append(" return %s_CANID;", sgs->msg.Name.c_str());
812817
}
813818

819+
814820
void CiMainGenerator::WritePackStructBody(const CiExpr_t* sgs)
815821
{
816822
fwriter.Append("{");
@@ -836,7 +842,7 @@ void CiMainGenerator::WritePackArrayBody(const CiExpr_t* sgs)
836842

837843
void CiMainGenerator::PrintPackCommonText(const std::string& arrtxt, const CiExpr_t* sgs)
838844
{
839-
// this function will print body of packing function
845+
// this function will print the body of the packing function
840846

841847
// print array content clearing loop
842848
fwriter.Append(" uint8_t i; for (i = 0u; i < %s(%s_DLC); %s[i++] = %s);",
@@ -900,8 +906,7 @@ void CiMainGenerator::PrintPackCommonText(const std::string& arrtxt, const CiExp
900906
// Generate packing code for each byte in the CAN message
901907
for (size_t i = 0; i < sgs->to_bytes.size(); i++)
902908
{
903-
904-
if (masterSignal)
909+
if (is_multiplex_enabled && masterSignal)
905910
{
906911
bool first = true;
907912
// Handle the case where only a master multiplexor signal exists and there are no other kMulValue signal types in the CAN msg.
@@ -949,7 +954,8 @@ void CiMainGenerator::PrintPackCommonText(const std::string& arrtxt, const CiExp
949954
}
950955
else
951956
{
952-
// Handle for when there is no master multiplexor signal. Just pack the signal values from all signals making up this byte.
957+
// Handle for when there is no master multiplexor signal or when multiplexing is disabled.
958+
// Just pack the signal values from all signals making up this byte.
953959
if ( !sgs->to_bytes[i].empty() )
954960
{
955961
fwriter.Append(" %s[%d] |= (uint8_t) ( %s );", arrtxt.c_str(), i, sgs->to_bytes[i].c_str());

src/codegen/c-main-generator.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class CiMainGenerator {
1212
public:
13-
void Generate(DbcMessageList_t& dlist, const AppSettings_t& fsd);
13+
void Generate(DbcMessageList_t& dlist, const AppSettings_t& fsd, bool mux_enabled);
1414

1515
private:
1616

@@ -39,4 +39,6 @@ class CiMainGenerator {
3939
// Macro for frame DLC validation
4040
std::string prt_dlcValidateMacroName;
4141
const AppSettings_t* fdesc;
42+
// Bool to turn on or off code generation based on multiplexor master signal values is enabled for multiplexed signals.
43+
bool is_multiplex_enabled;
4244
};

src/options-parser.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ OptionsParser::GenOptions OptionsParser::GetOptions(int argc, char** argv)
8686
{
8787
retpairs.add_gen_date = true;
8888
}
89+
else if (temppairs[i].first.compare("-multiplex") == 0 || temppairs[i].first.compare("-muxgen") == 0)
90+
{
91+
retpairs.is_multiplex_enabled = true;
92+
}
8993
}
9094

9195
return retpairs;

src/options-parser.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ class OptionsParser {
4848

4949
/// @brief help is requested
5050
bool is_help{false};
51+
52+
/// @brief Code generation based on multiplexor master signal values is enabled for multiplexed signals.
53+
bool is_multiplex_enabled{false};
5154
};
5255

5356
/// @brief Parses arguments and theirs optional values

0 commit comments

Comments
 (0)