added reset on malicious coordinates

This commit is contained in:
Marco Zeisler 2021-06-17 21:52:47 +02:00
parent 8d89b569ba
commit a3183ade07

View File

@ -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__":
...