Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multiplex signal Unpack functions #33

Open
calumroy opened this issue Aug 15, 2024 · 0 comments
Open

Fix multiplex signal Unpack functions #33

calumroy opened this issue Aug 15, 2024 · 0 comments

Comments

@calumroy
Copy link

calumroy commented Aug 15, 2024

Hello,

This is similar to issue #31 but instead is to do the Unpack functions with multiplexed signals.

So currently the Unpack functions will decode all the signals in the CAN message structure regardless of whether they are multiplexed signals and what the multiplex master signal value is.

An example CAN message in a dbc file format is shown below:

BO_ 1096 MUX_SIG_TEST1: 8 MCU
 SG_ mux8_sig1 m8 : 8|8@1+ (1,0) [1|3] ""  VMU
 SG_ mux8_sig2 m8 : 16|15@1+ (0.125,0) [0|4090] "V"  VMU
 SG_ mux7_sig1 m7 : 8|8@1+ (1,0) [1|3] ""  VMU
 SG_ mux7_sig2 m7 : 16|15@1+ (0.125,0) [0|4090] "V"  VMU
 SG_ mux6_sig1 m6 : 8|48@1+ (1,0) [0|0] ""  VMU
 SG_ mux0_sig1 m0 : 32|8@1+ (1,0) [0|0] ""  VMU
 SG_ mux0_sig2 m0 : 24|8@1+ (1,0) [0|0] ""  VMU
 SG_ mux5_sig1 m5 : 8|48@1+ (1,0) [0|0] ""  VMU
 SG_ mux4_sig4 m4 : 8|32@1+ (1,0) [0|0] ""  VMU
 SG_ mux4_sig3 m3 : 24|16@1+ (1,0) [0|0] ""  VMU
 SG_ mux0_sig3 m0 : 16|8@1+ (1,0) [0|0] ""  VMU
 SG_ mux0_sig4 m0 : 8|8@1+ (1,0) [0|0] ""  VMU
 SG_ mux2_sig1 m2 : 8|16@1+ (1,-32767) [0|32760] "RPM"  VMU
 SG_ mux1_sig1 m1 : 8|15@1+ (0.125,0) [0|4090] "Nm"  VMU
 SG_ mux3_sig1 m3 : 16|8@1+ (1,0) [0|0] ""  VMU
 SG_ mux3_sig2 m3 : 8|8@1+ (1,0) [0|0] ""  VMU
 SG_ mux_master M : 0|7@1+ (1,0) [0|0] ""  VMU
 SG_ signal1 : 7|1@1+ (1,0) [0|0] ""  VMU

Currently c-coderdbc will generate the following Unpack_ function which just decodes all the signals.

uint32_t Unpack_MUX_SIG_TEST1_testdb(MUX_SIG_TEST1_t* _m, const uint8_t* _d, uint8_t dlc_)
{
  (void)dlc_;
  _m->mux_master = (uint8_t) ( (_d[0] & (0x7FU)) );
  _m->signal1 = (uint8_t) ( ((_d[0] >> 7U) & (0x01U)) );
  _m->mux8_sig1 = (uint8_t) ( (_d[1] & (0xFFU)) );
  _m->mux7_sig1 = (uint8_t) ( (_d[1] & (0xFFU)) );
  _m->mux6_sig1 = (uint64_t) ( ((uint64_t)(_d[6] & (0xFFU)) << 40U) | ((uint64_t)(_d[5] & (0xFFU)) << 32U) | ((_d[4] & (0xFFU)) << 24U) | ((_d[3] & (0xFFU)) << 16U) | ((_d[2] & (0xFFU)) << 8U) | (_d[1] & (0xFFU)) );
  _m->mux3_sig2 = (uint8_t) ( (_d[1] & (0xFFU)) );
  _m->mux5_sig1 = (uint64_t) ( ((uint64_t)(_d[6] & (0xFFU)) << 40U) | ((uint64_t)(_d[5] & (0xFFU)) << 32U) | ((_d[4] & (0xFFU)) << 24U) | ((_d[3] & (0xFFU)) << 16U) | ((_d[2] & (0xFFU)) << 8U) | (_d[1] & (0xFFU)) );
  _m->mux4_sig4 = (uint32_t) ( ((_d[4] & (0xFFU)) << 24U) | ((_d[3] & (0xFFU)) << 16U) | ((_d[2] & (0xFFU)) << 8U) | (_d[1] & (0xFFU)) );
  _m->mux1_sig1_ro = (uint16_t) ( ((_d[2] & (0x7FU)) << 8U) | (_d[1] & (0xFFU)) );
#ifdef TESTDB_USE_SIGFLOAT
  _m->mux1_sig1_phys = (sigfloat_t)(TESTDB_mux1_sig1_ro_fromS(_m->mux1_sig1_ro));
#endif // TESTDB_USE_SIGFLOAT

  _m->mux0_sig4 = (uint8_t) ( (_d[1] & (0xFFU)) );
  _m->mux2_sig1_ro = (uint16_t) ( ((_d[2] & (0xFFU)) << 8U) | (_d[1] & (0xFFU)) );
#ifdef TESTDB_USE_SIGFLOAT
  _m->mux2_sig1_phys = (int32_t) TESTDB_mux2_sig1_ro_fromS(_m->mux2_sig1_ro);
#endif // TESTDB_USE_SIGFLOAT

  _m->mux8_sig2_ro = (uint16_t) ( ((_d[3] & (0x7FU)) << 8U) | (_d[2] & (0xFFU)) );
#ifdef TESTDB_USE_SIGFLOAT
  _m->mux8_sig2_phys = (sigfloat_t)(TESTDB_mux8_sig2_ro_fromS(_m->mux8_sig2_ro));
#endif // TESTDB_USE_SIGFLOAT

  _m->mux3_sig1 = (uint8_t) ( (_d[2] & (0xFFU)) );
  _m->mux0_sig3 = (uint8_t) ( (_d[2] & (0xFFU)) );
  _m->mux7_sig2_ro = (uint16_t) ( ((_d[3] & (0x7FU)) << 8U) | (_d[2] & (0xFFU)) );
#ifdef TESTDB_USE_SIGFLOAT
  _m->mux7_sig2_phys = (sigfloat_t)(TESTDB_mux7_sig2_ro_fromS(_m->mux7_sig2_ro));
#endif // TESTDB_USE_SIGFLOAT

  _m->mux4_sig3 = (uint16_t) ( ((_d[4] & (0xFFU)) << 8U) | (_d[3] & (0xFFU)) );
  _m->mux0_sig2 = (uint8_t) ( (_d[3] & (0xFFU)) );
  _m->mux0_sig1 = (uint8_t) ( (_d[4] & (0xFFU)) );

#ifdef TESTDB_USE_DIAG_MONITORS
  _m->mon1.dlc_error = (dlc_ < MUX_SIG_TEST1_DLC);
  _m->mon1.last_cycle = GetSystemTick();
  _m->mon1.frame_cnt++;

  FMon_MUX_SIG_TEST1_testdb(&_m->mon1, MUX_SIG_TEST1_CANID);
#endif // TESTDB_USE_DIAG_MONITORS

  return MUX_SIG_TEST1_CANID;
}

So for example when decoding this message if the mux_master signal equals 1 then only the signals
mux1_sig1, mux_master and signal1 should be decoded in the Unpack function and placed in the output MUX_SIG_TEST1_t* _m.

The above code will unfortunetly also incorrectly decode the signals mux2_sig1, mux3_sig1, mux0_sig4, mux0_sig3, mux5_sig1, mux7_sig1, mux7_sig2 , mux8_sig1, mux8_sig2 and put this incorrect decoded values in the output structure MUX_SIG_TEST1_t* _m.

This means you have to manually loop over the structure to find the mux_master value and then only look at the signals associated with the mux_master equalling 1, which is very cumbersome.

A better solution would be to generate if statements around the unpacking of each signal so only the signals associated with the mux_master value are decoded.

This was referenced Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant