mirror of https://github.com/commaai/panda.git
Macro can trigger Misra violation due redef of var before their use
This commit is contained in:
parent
05487e29d7
commit
65fb5a48e7
|
@ -139,15 +139,15 @@ bool dist_to_meas_check(int val, int val_last, struct sample_t *val_meas,
|
|||
const int MAX_RATE_UP, const int MAX_RATE_DOWN, const int MAX_ERROR) {
|
||||
|
||||
// *** val rate limit check ***
|
||||
int highest_allowed_val = MAX(val_last, 0) + MAX_RATE_UP;
|
||||
int lowest_allowed_val = MIN(val_last, 0) - MAX_RATE_UP;
|
||||
int highest_allowed_rl = MAX(val_last, 0) + MAX_RATE_UP;
|
||||
int lowest_allowed_rl = MIN(val_last, 0) - MAX_RATE_UP;
|
||||
|
||||
// if we've exceeded the meas val, we must start moving toward 0
|
||||
highest_allowed_val = MIN(highest_allowed_val, MAX(val_last - MAX_RATE_DOWN, MAX(val_meas->max, 0) + MAX_ERROR));
|
||||
lowest_allowed_val = MAX(lowest_allowed_val, MIN(val_last + MAX_RATE_DOWN, MIN(val_meas->min, 0) - MAX_ERROR));
|
||||
int highest_allowed = MIN(highest_allowed_rl, MAX(val_last - MAX_RATE_DOWN, MAX(val_meas->max, 0) + MAX_ERROR));
|
||||
int lowest_allowed = MAX(lowest_allowed_rl, MIN(val_last + MAX_RATE_DOWN, MIN(val_meas->min, 0) - MAX_ERROR));
|
||||
|
||||
// check for violation
|
||||
return (val < lowest_allowed_val) || (val > highest_allowed_val);
|
||||
return (val < lowest_allowed) || (val > highest_allowed);
|
||||
}
|
||||
|
||||
// check that commanded value isn't fighting against driver
|
||||
|
@ -155,16 +155,16 @@ bool driver_limit_check(int val, int val_last, struct sample_t *val_driver,
|
|||
const int MAX, const int MAX_RATE_UP, const int MAX_RATE_DOWN,
|
||||
const int MAX_ALLOWANCE, const int DRIVER_FACTOR) {
|
||||
|
||||
int highest_allowed = MAX(val_last, 0) + MAX_RATE_UP;
|
||||
int lowest_allowed = MIN(val_last, 0) - MAX_RATE_UP;
|
||||
int highest_allowed_rl = MAX(val_last, 0) + MAX_RATE_UP;
|
||||
int lowest_allowed_rl = MIN(val_last, 0) - MAX_RATE_UP;
|
||||
|
||||
int driver_max_limit = MAX + (MAX_ALLOWANCE + val_driver->max) * DRIVER_FACTOR;
|
||||
int driver_min_limit = -MAX + (-MAX_ALLOWANCE + val_driver->min) * DRIVER_FACTOR;
|
||||
|
||||
// if we've exceeded the applied torque, we must start moving toward 0
|
||||
highest_allowed = MIN(highest_allowed, MAX(val_last - MAX_RATE_DOWN,
|
||||
int highest_allowed = MIN(highest_allowed_rl, MAX(val_last - MAX_RATE_DOWN,
|
||||
MAX(driver_max_limit, 0)));
|
||||
lowest_allowed = MAX(lowest_allowed, MIN(val_last + MAX_RATE_DOWN,
|
||||
int lowest_allowed = MAX(lowest_allowed_rl, MIN(val_last + MAX_RATE_DOWN,
|
||||
MIN(driver_min_limit, 0)));
|
||||
|
||||
// check for violation
|
||||
|
|
Loading…
Reference in New Issue