Open leijurv opened 7 years ago
Referring to
if (System.currentTimeMillis() - ages[mode] > MAX_AGE) {
throw new InvalidSensorException("CAN data oudated For CAN sensor " + getName() + " with ID " + messageID);
}
It's possible that it will cache the garbage 0 value from the beginning because of this snippet
This is true, although I am concerned about setting lastRead (the new version as of #128) to 0, as that would lead to failure if the first read fails regardless (whereas leaving lastRead as the construction time allows for up to 100ms of bad reads at the beginning). It would be optimal to get an initial sensor value and set lastRead with that. There may be the issue of blocking construction for 100ms while we wait for a dead sensor though, which is not good.
Setting ages[i] to System.currentTimeMillis() ends up caching the value 0 at the current time. This is undesired, because the value 0 is garbage and shouldn't be used. Perhaps ages[i] should be set to 0 so there's no way that it could be close enough to the currentTimeMillis to be cached