encode function have err
chentyjpm opened this issue · 5 comments
-
maybe encode function shoud input a double value and point of dst struct to process and output result true/false?
-
value should first add offset then * scale now is first scale then offset
for example
result is that
double decode_can_0x203_BattPackVoltage(can_0x203_Batt_Basic_Info_t *record)
{
double rval = (double)(record->BattPackVoltage);
rval *= 0.100000;
rval += -1000.000000;
return rval;
}
double encode_can_0x203_BattPackVoltage(can_0x203_Batt_Basic_Info_t *record)
{
double rval = (double)(record->BattPackVoltage);
rval *= 10.000000;
rval += 1000.000000;
return rval;
}
Hello!
For you first point, do you mean something like:
double decode_can_0x203_BattPackVoltage(can_0x203_Batt_Basic_Info_t *record, double *out)
{
double rval = (double)(record->BattPackVoltage);
rval *= SCALING;
rval += OFFSET;
*out = rval;
return (rval > MAXIMUM || rval < MINIMUM) ? false; true;
}
I'm currently not doing anything the minimum and maximum values available in the DBC file.
For your second point, I'll change that. I also think the encode and decode should be switched? Maybe not in your example but in the DBCC application?
Ah, wait, I see what you mean, I'll make functions that do the following:
bool encode(struct_t *record, double in);
bool decode(struct_t *record, double *out);
I'll also add range checks.
Hello!
first point is that
when decoder function you result is right
double decode_can_0x203_BattPackVoltage(can_0x203_Batt_Basic_Info_t *record, double *out)
{
double rval = (double)(record->BattPackVoltage);
rval *= SCALING;
rval += OFFSET;
*out = rval;
return (rval > MAXIMUM || rval < MINIMUM) ? false; true;
}
but when encode it should be that
double encode_can_0x203_BattPackVoltage(can_0x203_Batt_Basic_Info_t *record, double in)
{
double rval =in;
//first offset
rval += -OFFSET;
//scaling next
rval *= 1/SCALING;
record->BattPackVoltage = rval;
return (rval > MAXIMUM || rval < MINIMUM) ? false; true;
}
so the result is correct
Best wishs ^_^
Can you check this works as expected? Then I will close this issue. Thanks!
checked its right thanks ^_^