Electronics > Microcontrollers

CANdb++ .dbc to C/C++ .h converter

<< < (4/5) > >>

mikelev:
Thanks a lot for your work!!

Maybe I am not using this converter correctly...
I can see it correctly generates the structures corresponding to CAN signals, but not sure about CAN message structures.
I thought CAN Message structures are supposed to contain all the signals within them (signals as bitfields and also a set of signal_positioned structures). Am I wrong?

Here is a part of .h file generated from your test_fd.dbc:
/**
 * ""
 *
 * ###Parameters###
 * | Name    |   Value      |
 * | ------   |   --------   |
 * | ID:   |   0x64   |
 * | IDE:    |   STD       |
 * | DLC:    |   15         |
 *
 * ###Signals###
 * | Position (Bit)   |   Signal (Bitlength)   |
 * | -------------   |   ------------------   |
 * | [0]         |    @ref DBC_TEST_FD_SIG_test1    "test1 (64)"    |
 *
 */
static struct DBC_TEST_FD_MSG_Mes_CAN_FD_Std {
   const uint32_t ID;
   const uint8_t IDE;
   const uint8_t DLC;
    const struct {
      signal_positioned test1;
   } sigParms;
    struct __attribute__((packed)) DBC_TEST_FD_MSG_Mes_CAN_FD_Std_sigVals {
      int64_t test1   : 64;
   } *sigVals;
} DBC_TEST_FD_MSG_Mes_CAN_FD_Std __attribute__((unused)) = {
   .ID = 0x64,
   .IDE = CAN_ID_STD,
   .DLC = 15,
   .sigParms  = {
      {0,    &DBC_TEST_FD_SIG_test1}
   },
   .sigVals = 0
};


The only signal I see here is "DBC_TEST_FD_SIG_test1", but I expected 8 signals.


I am also attaching my dbc and generated .h files.

Thanks again!
Mikhail

gnasirator:
Hmm jeah seems like there's still something wrong. hang on ...

edit: fixed. had another hard-coded 64 somewhere else in the code :)


--- Code: ---/**
 * ""
 *
 * ###Parameters###
 * | Name | Value |
 * | ------ | -------- |
 * | ID: | 0x64 |
 * | IDE: | STD |
 * | DLC: | 15 |
 *
 * ###Signals###
 * | Position (Bit) | Signal (Bitlength) |
 * | ------------- | ------------------ |
 * | [0] | @ref DBC_TEST_FD_SIG_test1 "test1 (64)" |
 * | [64] | @ref DBC_TEST_FD_SIG_test1_Copy_1 "test1_Copy_1 (64)" |
 * | [128] | @ref DBC_TEST_FD_SIG_test1_Copy_2 "test1_Copy_2 (64)" |
 * | [192] | @ref DBC_TEST_FD_SIG_test1_Copy_3 "test1_Copy_3 (64)" |
 * | [256] | @ref DBC_TEST_FD_SIG_test1_Copy_4 "test1_Copy_4 (64)" |
 * | [320] | @ref DBC_TEST_FD_SIG_test1_Copy_6 "test1_Copy_6 (64)" |
 * | [448] | @ref DBC_TEST_FD_SIG_test1_Copy_7 "test1_Copy_7 (64)" |
 *
 */
static struct DBC_TEST_FD_MSG_Mes_CAN_FD_Std {
const uint32_t ID;
const uint8_t IDE;
const uint8_t DLC;
const struct {
signal_positioned test1;
signal_positioned test1_Copy_1;
signal_positioned test1_Copy_2;
signal_positioned test1_Copy_3;
signal_positioned test1_Copy_4;
signal_positioned test1_Copy_6;
signal_positioned test1_Copy_7;
} sigParms;
struct __attribute__((packed)) DBC_TEST_FD_MSG_Mes_CAN_FD_Std_sigVals {
int64_t test1 : 64;
int64_t test1_Copy_1 : 64;
int64_t test1_Copy_2 : 64;
int64_t test1_Copy_3 : 64;
int64_t test1_Copy_4 : 64;
int64_t test1_Copy_6 : 64;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
void : 1;
int64_t test1_Copy_7 : 64;
} *sigVals;
} DBC_TEST_FD_MSG_Mes_CAN_FD_Std __attribute__((unused)) = {
.ID = 0x64,
.IDE = CAN_ID_STD,
.DLC = 15,
.sigParms  = {
{0, &DBC_TEST_FD_SIG_test1},
{64, &DBC_TEST_FD_SIG_test1_Copy_1},
{128, &DBC_TEST_FD_SIG_test1_Copy_2},
{192, &DBC_TEST_FD_SIG_test1_Copy_3},
{256, &DBC_TEST_FD_SIG_test1_Copy_4},
{320, &DBC_TEST_FD_SIG_test1_Copy_6},
{448, &DBC_TEST_FD_SIG_test1_Copy_7}
},
.sigVals = 0
};
--- End code ---

mikelev:
Wow! The output looks great. I will try to use it within a few days.

I am not sure if I can use the bitfields in "sigValues" to access signals correctly. Also my compiler does not like "void" bitfields and I might have to remove the "sigValues" from the code.
However, "sigParams" is good enough for me. I can use a function to extract signal values as long as I have a full list of them (with start and length) in one place. And "sigParams" is exactly the list I need.

Thanks!
Mikhail

mikelev:
Also, field "position" in in "signal_positioned" should be bigger than uint8_t. But that is easy to change in generated .h file.

gnasirator:
The thing about functions is that they require known types which is why I had to come up with the accessor macro, as you can see in post #1:


--- Code: ---{
uint8_t uid;
uint8_t RxMessage[8];
DBC_setup(DBC_IME_AI_MSG_CAN_IMED_MSG_PA_SP, RxMessage);
DBC_makeSignalAccessor(DBC_IME_AI_MSG_CAN_IMED_MSG_PA_SP, RxMessage, msg_access);
uid = msg_access->UID;
msg_access->AssignedID = 42;
}
--- End code ---

This has worked great for me, using gcc. it took care of all masks and shifts to spit out just the signal I wanted.

you can also replace the void bitfileds with u_08 unused:1; for example. But I think they will then pop up in your autocompletion list, cluttering the results which is why I was happy to see that void worked with gcc.

about signal_positioned: good spot. yes that now has to be u_16. will change that. changed.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod