Skip to content

Commit 1229bd9

Browse files
committed
Changed include files quatation (quotes instead of angle brackets)
Added empty frame to be remove from driver in next commit Frames with no signals are almost fully ignored New features regarding DLC handling, initial byte value Added more explicit type casting
1 parent cc7b413 commit 1229bd9

19 files changed

+384
-238
lines changed

docs/RELEASES.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,33 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

77
## [Unreleased]
88

9+
## [v3.0] - 2023-10-09
10+
11+
### Added
12+
13+
- Added explicit type casting on:
14+
* Writing data bytes, IDE, DLC and MsgId on pack step
15+
* Explicit unsigned nature ('U') to message CANID macro value
16+
- ```-Wpedantic``` doesn't complain anymore on generated code (tested on test.dbc only)
17+
- Added 'define' with value for filling initial value in frame's bytes before packing signals.
18+
The value can be set in the user scope configuration file (driver-config)
19+
- Added enhanced DLC handling:
20+
* Added max detected DLC value (as a macro in main driver)
21+
* User can specify its own max DLC value if necessary (by setting corresponding macro in driver-config file)
22+
* Functions use new 'VALIDATE_DLC' test when checks the limit of frame data bytes count
23+
924
### Changed
1025

26+
- Include files in quotes instead of angle brackets
1127
- This changelog file format has been changed
1228
- Added style option file
1329
- Changed git flow
1430
- README.md changed
1531

1632
### Fixed
1733

18-
- Fixed an issue in findversion function
34+
- No more struct, pack and unpack for frames with no signals (empty frames). IDs and frame related info is left
35+
- Fixed an issue in 'findversion' function
1936
- Fixed issue on appending new string which is empty
2037

2138
## [v2.9] - 2023-01-27
@@ -197,7 +214,8 @@ network node defined in DBC
197214
- Fixed some warnings
198215

199216

200-
[Unreleased]: https://github.com/astand/c-coderdbc/compare/v2.9...HEAD
217+
[Unreleased]: https://github.com/astand/c-coderdbc/compare/v3.0...HEAD
218+
[v3.0]: https://github.com/astand/c-coderdbc/compare/v2.9...v3.0
201219
[v2.9]: https://github.com/astand/c-coderdbc/compare/v2.8...v2.9
202220
[v2.8]: https://github.com/astand/c-coderdbc/compare/v2.7...v2.8
203221
[v2.7]: https://github.com/astand/c-coderdbc/compare/v2.6...v2.7

src/codegen/c-main-generator.cpp

Lines changed: 87 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ void CiMainGenerator::Generate(DbcMessageList_t& dlist, const AppSettings_t& fsd
3636
// Load income messages to sig printer
3737
sigprt.LoadMessages(dlist.msgs);
3838

39+
// save max dlc value from message list for printing on the following generation steps
40+
val_maxDlcValueFromDbcList = dlist.maxDlcValue;
41+
3942
// save pointer to output file descriptor struct to
4043
// enable using this information inside class member functions
4144
fdesc = &fsd;
@@ -101,22 +104,56 @@ void CiMainGenerator::Gen_MainHeader()
101104
fwriter.Append();
102105

103106
fwriter.Append("// include current dbc-driver compilation config");
104-
fwriter.Append("#include <%s-config.h>", fdesc->gen.drvname.c_str());
107+
fwriter.Append("#include \"%s-config.h\"", fdesc->gen.drvname.c_str());
105108
fwriter.Append();
106109

107110
fwriter.Append("#ifdef %s", fdesc->gen.usemon_def.c_str());
108111

109112
fwriter.Append(
110113
"// This file must define:\n"
111114
"// base monitor struct\n"
112-
"#include <canmonitorutil.h>\n"
115+
"#include \"canmonitorutil.h\"\n"
113116
"\n"
114117
);
115118

116119
fwriter.Append("#endif // %s", fdesc->gen.usemon_def.c_str());
117120
fwriter.Append(2);
118121

119-
for (size_t num = 0; num < sigprt.sigs_expr.size(); num++)
122+
// set macro name for max dlc value based on driver name
123+
std::string maxDlcMacroName = fdesc->gen.DRVNAME + "_MAX_DLC_VALUE";
124+
125+
// set macro name for dlc validation
126+
prt_dlcValidateMacroName = fdesc->gen.DRVNAME + "_VALIDATE_DLC";
127+
128+
// set macro name for initial data byte value based on driver name
129+
prt_initialDataByteValueName = fdesc->gen.DRVNAME + "_INITIAL_BYTE_VALUE";
130+
131+
// print part with max DLC macro
132+
fwriter.Append("// DLC maximum value which is used as the limit for frame's data buffer size.");
133+
fwriter.Append("// Client can set its own value (not sure why) in driver-config");
134+
fwriter.Append("// or can test it on some limit specified by application");
135+
fwriter.Append("// e.g.: static_assert(TESTDB_MAX_DLC_VALUE <= APPLICATION_FRAME_DATA_SIZE, \"Max DLC value in the driver is too big\")");
136+
fwriter.Append("#ifndef %s", maxDlcMacroName.c_str());
137+
fwriter.Append("// The value which was found out by generator (real max value)");
138+
fwriter.Append("#define %s %uU", maxDlcMacroName.c_str(), val_maxDlcValueFromDbcList);
139+
fwriter.Append("#endif");
140+
fwriter.Append(1);
141+
142+
// actual macro for final DLC validation in the driver
143+
fwriter.Append("// The limit is used for setting frame's data bytes");
144+
fwriter.Append("#define %s(msgDlc) (((msgDlc) <= (%s)) ? (msgDlc) : (%s))",
145+
prt_dlcValidateMacroName.c_str(), maxDlcMacroName.c_str(), maxDlcMacroName.c_str());
146+
147+
// print initial data byte section
148+
fwriter.Append(1);
149+
fwriter.Append("// Initial byte value to be filles in data bytes of the frame before pack signals");
150+
fwriter.Append("// User can define its own custom value in driver-config file");
151+
fwriter.Append("#ifndef %s", prt_initialDataByteValueName.c_str());
152+
fwriter.Append("#define %s 0U", prt_initialDataByteValueName.c_str());
153+
fwriter.Append("#endif");
154+
fwriter.Append(2);
155+
156+
for (size_t num = 0u; num < sigprt.sigs_expr.size(); num++)
120157
{
121158
// write message typedef s and additional expressions
122159
MessageDescriptor_t& m = sigprt.sigs_expr[num]->msg;
@@ -130,7 +167,7 @@ void CiMainGenerator::Gen_MainHeader()
130167
fwriter.Append("// def @%s CAN Message (%-4d %#x)", m.Name.c_str(), m.MsgID, m.MsgID);
131168
fwriter.Append("#define %s_IDE (%uU)", m.Name.c_str(), m.IsExt);
132169
fwriter.Append("#define %s_DLC (%uU)", m.Name.c_str(), m.DLC);
133-
fwriter.Append("#define %s_CANID (%#x)", m.Name.c_str(), m.MsgID);
170+
fwriter.Append("#define %s_CANID (%#xU)", m.Name.c_str(), m.MsgID);
134171

135172
if (m.Cycle > 0)
136173
{
@@ -139,6 +176,13 @@ void CiMainGenerator::Gen_MainHeader()
139176

140177
size_t max_sig_name_len = 27;
141178

179+
if (!m.frameNotEmpty)
180+
{
181+
// do nothing with empty frame, leave only id other relevant constants
182+
fwriter.Append();
183+
continue;
184+
}
185+
142186
for (size_t signum = 0; signum < m.Signals.size(); signum++)
143187
{
144188
SignalDescriptor_t& s = m.Signals[signum];
@@ -261,6 +305,12 @@ void CiMainGenerator::Gen_MainHeader()
261305
// write message typedef s and additional expressions
262306
MessageDescriptor_t& m = sigprt.sigs_expr[num]->msg;
263307

308+
if (!m.frameNotEmpty)
309+
{
310+
// do nothing with empty frame
311+
continue;
312+
}
313+
264314
fwriter.Append("uint32_t Unpack_%s_%s(%s_t* _m, const uint8_t* _d, uint8_t dlc_);",
265315
m.Name.c_str(), fdesc->gen.DrvName_orig.c_str(), m.Name.c_str());
266316

@@ -312,7 +362,7 @@ void CiMainGenerator::Gen_MainSource()
312362
"// Function prototypes to be called each time CAN frame is unpacked\n"
313363
"// FMon function may detect RC, CRC or DLC violation\n");
314364

315-
fwriter.Append("#include <%s-fmon.h>", fdesc->gen.drvname.c_str());
365+
fwriter.Append("#include \"%s-fmon.h\"", fdesc->gen.drvname.c_str());
316366
fwriter.Append();
317367

318368
fwriter.Append("#endif // %s", fdesc->gen.usemon_def.c_str());
@@ -345,6 +395,12 @@ void CiMainGenerator::Gen_MainSource()
345395
// write message typedef s and additional expressions
346396
MessageDescriptor_t& m = sigprt.sigs_expr[num]->msg;
347397

398+
if (!m.frameNotEmpty)
399+
{
400+
// do nothing, no pack and unpack functions for empty frames
401+
continue;
402+
}
403+
348404
// first function
349405
fwriter.Append("uint32_t Unpack_%s_%s(%s_t* _m, const uint8_t* _d, uint8_t dlc_)\n{",
350406
m.Name.c_str(), fdesc->gen.DrvName_orig.c_str(), m.Name.c_str());
@@ -641,12 +697,14 @@ void CiMainGenerator::WriteUnpackBody(const CiExpr_t* sgs)
641697

642698
if (sgs->msg.Signals[num].Signed)
643699
{
644-
fwriter.Append(" _m->%s = %s(( %s ), %d);",
645-
sname, ext_sig_func_name, expr.c_str(), (int32_t)sgs->msg.Signals[num].LengthBit);
700+
fwriter.Append(" _m->%s = (%s) %s(( %s ), %d);",
701+
sname, PrintType((int)sgs->msg.Signals[num].TypeRo).c_str(),
702+
ext_sig_func_name, expr.c_str(), (int32_t)sgs->msg.Signals[num].LengthBit);
646703
}
647704
else
648705
{
649-
fwriter.Append(" _m->%s = %s;", sname, expr.c_str());
706+
fwriter.Append(" _m->%s = (%s) ( %s );", sname,
707+
PrintType((int)sgs->msg.Signals[num].TypeRo).c_str(), expr.c_str());
650708
}
651709

652710
// print sigfloat conversion
@@ -662,8 +720,10 @@ void CiMainGenerator::WriteUnpackBody(const CiExpr_t* sgs)
662720
}
663721
else
664722
{
665-
fwriter.Append(" _m->%s = %s_%s_fromS(_m->%s);",
666-
sgs->msg.Signals[num].NameFloat.c_str(), fdesc->gen.DRVNAME.c_str(), sname, sname);
723+
fwriter.Append(" _m->%s = (%s) %s_%s_fromS(_m->%s);",
724+
sgs->msg.Signals[num].NameFloat.c_str(),
725+
PrintType((int)sgs->msg.Signals[num].TypePhys).c_str(),
726+
fdesc->gen.DRVNAME.c_str(), sname, sname);
667727
}
668728

669729
fwriter.Append("#endif // %s", fdesc->gen.usesigfloat_def.c_str());
@@ -721,9 +781,9 @@ void CiMainGenerator::WritePackStructBody(const CiExpr_t* sgs)
721781
{
722782
fwriter.Append("{");
723783
PrintPackCommonText("cframe->Data", sgs);
724-
fwriter.Append(" cframe->MsgId = %s_CANID;", sgs->msg.Name.c_str());
725-
fwriter.Append(" cframe->DLC = %s_DLC;", sgs->msg.Name.c_str());
726-
fwriter.Append(" cframe->IDE = %s_IDE;", sgs->msg.Name.c_str());
784+
fwriter.Append(" cframe->MsgId = (uint32_t) %s_CANID;", sgs->msg.Name.c_str());
785+
fwriter.Append(" cframe->DLC = (uint8_t) %s_DLC;", sgs->msg.Name.c_str());
786+
fwriter.Append(" cframe->IDE = (uint8_t) %s_IDE;", sgs->msg.Name.c_str());
727787
fwriter.Append(" return %s_CANID;", sgs->msg.Name.c_str());
728788
fwriter.Append("}");
729789
fwriter.Append();
@@ -733,21 +793,22 @@ void CiMainGenerator::WritePackArrayBody(const CiExpr_t* sgs)
733793
{
734794
fwriter.Append("{");
735795
PrintPackCommonText("_d", sgs);
736-
fwriter.Append(" *_len = %s_DLC;", sgs->msg.Name.c_str());
737-
fwriter.Append(" *_ide = %s_IDE;", sgs->msg.Name.c_str());
796+
fwriter.Append(" *_len = (uint8_t) %s_DLC;", sgs->msg.Name.c_str());
797+
fwriter.Append(" *_ide = (uint8_t) %s_IDE;", sgs->msg.Name.c_str());
738798
fwriter.Append(" return %s_CANID;", sgs->msg.Name.c_str());
739799
fwriter.Append("}");
740800
fwriter.Append();
741801
}
742802

743803
void CiMainGenerator::PrintPackCommonText(const std::string& arrtxt, const CiExpr_t* sgs)
744804
{
745-
// this function will print part of pack function
746-
// which is differs only by arra var name
805+
// this function will print body of packing function
747806

748807
// pring array content clearin loop
749-
fwriter.Append(" uint8_t i; for (i = 0; (i < %s_DLC) && (i < 8); %s[i++] = 0);",
750-
sgs->msg.Name.c_str(), arrtxt.c_str());
808+
fwriter.Append(" uint8_t i; for (i = 0u; i < %s(%s_DLC); %s[i++] = %s);",
809+
prt_dlcValidateMacroName.c_str(),
810+
sgs->msg.Name.c_str(), arrtxt.c_str(),
811+
prt_initialDataByteValueName.c_str());
751812
fwriter.Append();
752813

753814
if (sgs->msg.RollSig != nullptr)
@@ -763,7 +824,7 @@ void CiMainGenerator::PrintPackCommonText(const std::string& arrtxt, const CiExp
763824
{
764825
// code for clearing checksum
765826
fwriter.Append("#ifdef %s", fdesc->gen.usecsm_def.c_str());
766-
fwriter.Append(" _m->%s = 0U;", sgs->msg.CsmSig->Name.c_str());
827+
fwriter.Append(" _m->%s = (%s) 0;", sgs->msg.CsmSig->Name.c_str(), PrintType((int)sgs->msg.CsmSig->TypeRo).c_str());
767828
fwriter.Append("#endif // %s", fdesc->gen.usecsm_def.c_str());
768829
fwriter.Append();
769830
}
@@ -779,8 +840,10 @@ void CiMainGenerator::PrintPackCommonText(const std::string& arrtxt, const CiExp
779840
if (sgs->msg.Signals[n].IsSimpleSig == false)
780841
{
781842
// print toS from *_phys to original named sigint (integer duplicate of signal)
782-
fwriter.Append(" _m->%s = %s_%s_toS(_m->%s);",
783-
sgs->msg.Signals[n].Name.c_str(), fdesc->gen.DRVNAME.c_str(),
843+
fwriter.Append(" _m->%s = (%s) %s_%s_toS(_m->%s);",
844+
sgs->msg.Signals[n].Name.c_str(),
845+
PrintType((int) sgs->msg.Signals[n].TypeRo).c_str(),
846+
fdesc->gen.DRVNAME.c_str(),
784847
sgs->msg.Signals[n].Name.c_str(), sgs->msg.Signals[n].NameFloat.c_str());
785848
}
786849
}
@@ -796,7 +859,7 @@ void CiMainGenerator::PrintPackCommonText(const std::string& arrtxt, const CiExp
796859
continue;
797860
}
798861

799-
fwriter.Append(" %s[%d] |= %s;", arrtxt.c_str(), i, sgs->to_bytes[i].c_str());
862+
fwriter.Append(" %s[%d] |= (uint8_t) ( %s );", arrtxt.c_str(), i, sgs->to_bytes[i].c_str());
800863
}
801864

802865
fwriter.Append("");
@@ -810,7 +873,7 @@ void CiMainGenerator::PrintPackCommonText(const std::string& arrtxt, const CiExp
810873
sgs->msg.CsmSig->Name.c_str(), arrtxt.c_str(), sgs->msg.Name.c_str(),
811874
sgs->msg.Name.c_str(), sgs->msg.CsmMethod.c_str(), sgs->msg.CsmOp);
812875

813-
fwriter.Append(" %s[%d] |= %s;", arrtxt.c_str(), sgs->msg.CsmByteNum, sgs->msg.CsmToByteExpr.c_str());
876+
fwriter.Append(" %s[%d] |= (uint8_t) ( %s );", arrtxt.c_str(), sgs->msg.CsmByteNum, sgs->msg.CsmToByteExpr.c_str());
814877

815878
fwriter.Append("#endif // %s", fdesc->gen.usecsm_def.c_str());
816879
fwriter.Append();

src/codegen/c-main-generator.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,11 @@ class CiMainGenerator {
3232
private:
3333
CSigPrinter sigprt;
3434
FileWriter fwriter;
35+
// Actual max DLC value from dbc list instance
36+
size_t val_maxDlcValueFromDbcList;
37+
// Macro for default initial frame's data bytes value
38+
std::string prt_initialDataByteValueName;
39+
// Macro for frame DLC validation
40+
std::string prt_dlcValidateMacroName;
3541
const AppSettings_t* fdesc;
3642
};

src/codegen/c-sigprinter.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ std::string CSigPrinter::PrintPhysicalToRaw(const SignalDescriptor_t* sig, const
6969
}
7070

7171
retstr += StrPrint("#define %s_%s_toS(x) ( (%s) ", drvname.c_str(), sig->Name.c_str(),
72-
PrintType((uint8_t)sig->TypeRo).c_str());
72+
PrintType((uint8_t)sig->TypeRo).c_str());
7373

7474
if (sig->IsDoubleSig)
7575
{
@@ -188,7 +188,7 @@ std::string CSigPrinter::PrintSignalExpr(const SignalDescriptor_t* sig, std::vec
188188
}
189189

190190
uint16_t startb = (uint16_t)((sig->Order == BitLayout::kIntel) ?
191-
(sig->StartBit + (sig->LengthBit - 1)) : (sig->StartBit));
191+
(sig->StartBit + (sig->LengthBit - 1)) : (sig->StartBit));
192192

193193
if (startb > 63)
194194
{
@@ -211,10 +211,10 @@ std::string CSigPrinter::PrintSignalExpr(const SignalDescriptor_t* sig, std::vec
211211

212212
if (bbc > slen)
213213
{
214-
snprintf(workbuff, WBUFF_LEN, "((_d[%d] >> %d) & (%s))", bn, bbc - slen, msk[slen].c_str());
214+
snprintf(workbuff, WBUFF_LEN, "((_d[%d] >> %dU) & (%s))", bn, bbc - slen, msk[slen].c_str());
215215
tosigexpr += workbuff;
216216

217-
snprintf(workbuff, WBUFF_LEN, "((_m->%s & (%s)) << %d)", sig->Name.c_str(), msk[slen].c_str(), bbc - slen);
217+
snprintf(workbuff, WBUFF_LEN, "((_m->%s & (%s)) << %dU)", sig->Name.c_str(), msk[slen].c_str(), bbc - slen);
218218
AppendToByteLine(to_bytes[bn], workbuff);
219219
}
220220
else if (bbc == slen)
@@ -236,10 +236,10 @@ std::string CSigPrinter::PrintSignalExpr(const SignalDescriptor_t* sig, std::vec
236236
t64 = "(uint64_t)";
237237
}
238238

239-
snprintf(workbuff, WBUFF_LEN, "(%s(_d[%d] & (%s)) << %d)", t64.c_str(), bn, msk[bbc].c_str(), slen);
239+
snprintf(workbuff, WBUFF_LEN, "(%s(_d[%d] & (%s)) << %dU)", t64.c_str(), bn, msk[bbc].c_str(), slen);
240240
tosigexpr += workbuff;
241241

242-
snprintf(workbuff, WBUFF_LEN, "((_m->%s >> %d) & (%s))", sig->Name.c_str(), slen, msk[bbc].c_str());
242+
snprintf(workbuff, WBUFF_LEN, "((_m->%s >> %dU) & (%s))", sig->Name.c_str(), slen, msk[bbc].c_str());
243243
AppendToByteLine(to_bytes[bn], workbuff);
244244

245245
while ((slen - 8) >= 0)
@@ -277,10 +277,10 @@ std::string CSigPrinter::PrintSignalExpr(const SignalDescriptor_t* sig, std::vec
277277
t64 = "(uint64_t)";
278278
}
279279

280-
snprintf(workbuff, WBUFF_LEN, "(%s(_d[%d] & (%s)) << %d)", t64.c_str(), bn, msk[8].c_str(), slen);
280+
snprintf(workbuff, WBUFF_LEN, "(%s(_d[%d] & (%s)) << %dU)", t64.c_str(), bn, msk[8].c_str(), slen);
281281
tosigexpr += workbuff;
282282

283-
snprintf(workbuff, WBUFF_LEN, "((_m->%s >> %d) & (%s))", sig->Name.c_str(), slen, msk[8].c_str());
283+
snprintf(workbuff, WBUFF_LEN, "((_m->%s >> %dU) & (%s))", sig->Name.c_str(), slen, msk[8].c_str());
284284
AppendToByteLine(to_bytes[bn], workbuff);
285285
}
286286
}
@@ -289,10 +289,10 @@ std::string CSigPrinter::PrintSignalExpr(const SignalDescriptor_t* sig, std::vec
289289
{
290290
bn = ShiftByte(sig, bn);
291291

292-
snprintf(workbuff, WBUFF_LEN, " | ((_d[%d] >> %d) & (%s))", bn, 8 - slen, msk[slen].c_str());
292+
snprintf(workbuff, WBUFF_LEN, " | ((_d[%d] >> %dU) & (%s))", bn, 8 - slen, msk[slen].c_str());
293293
tosigexpr += workbuff;
294294

295-
snprintf(workbuff, WBUFF_LEN, "((_m->%s & (%s)) << %d)", sig->Name.c_str(), msk[slen].c_str(),
295+
snprintf(workbuff, WBUFF_LEN, "((_m->%s & (%s)) << %dU)", sig->Name.c_str(), msk[slen].c_str(),
296296
8 - slen);
297297
AppendToByteLine(to_bytes[bn], workbuff);
298298
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy