diff --git a/components/i_feed/devices/vehicle.py b/components/i_feed/devices/vehicle.py index c34318e..41d3bc1 100644 --- a/components/i_feed/devices/vehicle.py +++ b/components/i_feed/devices/vehicle.py @@ -223,15 +223,16 @@ class Vehicle: def check_reset(self): """ Checks if end of route is reached and resets vehicle to starting conditions. + It also resets on malicious coordinates. + Afterwards, the vehicle is still driving, but again from start. """ if self._driven_kms >= RESET_KM: - print('\n\nEnd of route reached ... resetting and restarting vehicle') - self._gps_location = self._starting_point - self._driven_kms = 0 - self.last_update = datetime.now() - self.nce = False - self.velocity = STARTING_VELOCITY + self._reset() + + if self._gps_location.latitude < self._starting_point.latitude or \ + self._gps_location.longitude < self._starting_point.longitude: + self._reset() @circuit(failure_threshold=10, expected_exception=AMQPConnectionError) def send_status_update(self): @@ -256,6 +257,14 @@ class Vehicle: else: print('We are still recovering ... ignoring new target velocity.') + def _reset(self): + print('\n\nEnd of route reached ... resetting and restarting vehicle') + self._gps_location = self._starting_point + self._driven_kms = 0 + self.last_update = datetime.now() + self.nce = False + self.velocity = STARTING_VELOCITY + if __name__ == "__main__": ...