flexstack.utils Module
The flexstack.utils package provides location and timing infrastructure.
LocationService & Position
- class flexstack.utils.location_service.LocationService[source]
Bases:
objectLocation Service
This class is used to get the location.
- Variables:
callbacks (List[Callable[[dict], None]]) – The callbacks to call when a new location is received.
- send_to_callbacks(location)[source]
Send the location to all callbacks.
- Parameters:
location (dict) – The location to send. (In TPV format)
- Return type:
None
GPSDLocationService
Location Service Module
This module contains the LocationService class, which is used to get the current location from a GPSD server.
- Usage:
from location_service import LocationService
# Initialize a new LocationService instance location_service = LocationService(gpsd_host=’localhost’, gpsd_port=2947)
# Add a callback function to be called when a new location is received def my_callback(location):
print(f’New location received: {location}’)
location_service.add_callback(my_callback)
- ivar gpsd_host:
The hostname or IP address of the GPSD server.
- vartype gpsd_host:
str
- ivar gpsd_port:
The port number of the GPSD server.
- vartype gpsd_port:
int
- ivar socket:
The socket object used to communicate with the GPSD server.
- vartype socket:
socket.socket
- ivar callbacks:
A list of callback functions to be called when a new location is received.
- vartype callbacks:
List[Callable[[dict], None]]
- ivar Classes:
- ivar ——-:
- ivar LocationService:
A class that connects to a GPSD server and provides current location data.
- class flexstack.utils.gpsd_location_service.GPSDLocationService(gpsd_host='localhost', gpsd_port=2947)[source]
Bases:
LocationServiceLocation Service
This class is used to get the location.
- Variables:
gpsd_host (str) – The host of the gpsd server.
gpsd_port (int) – The port of the gpsd server.
socket (socket.socket) – The socket to the gpsd server.
callbacks (List[Callable[[dict], None]]) – The callbacks to call when a new location is received.
- Parameters:
gpsd_host (str) –
gpsd_port (int) –
ThreadStaticLocationService
- flexstack.utils.static_location_service.generate_tpv_dict(current_utc_timestamp, latitude, longitude)[source]
Generate a TPV dictionary with the given UTC timestamp, latitude, and longitude.
- Parameters:
current_utc_timestamp (float) – The current UTC timestamp.
latitude (float) – The latitude of the location.
longitude (float) – The longitude of the location.
- Returns:
A dictionary containing the TPV data.
- Return type:
dict
- flexstack.utils.static_location_service.generate_tpv_dict_with_current_timestamp(latitude, longitude)[source]
Generate a TPV dictionary with the current UTC timestamp, latitude, and longitude.
- Parameters:
latitude (float) – The latitude of the location.
longitude (float) – The longitude of the location.
- Returns:
A dictionary containing the TPV data.
- Return type:
dict
- class flexstack.utils.static_location_service.AsyncStaticLocationService(period=1000, latitude=41.387304, longitude=2.112485)[source]
Bases:
LocationServiceLocation Servie that just provides an static position.
- Variables:
period (int) – Periodicity of the location update in ms.
latitude (float) – Latitude of the static location.
longitude (float) – Longitude of the static location.
- Parameters:
period (int) –
latitude (float) –
longitude (float) –
- __init__(period=1000, latitude=41.387304, longitude=2.112485)[source]
Initialize the Static Location Service. period : int
Periodicity of the location update in ms.
- static_locationdict
The static location to provide. (In TPV format)
- Parameters:
period (int) –
latitude (float) –
longitude (float) –
- Return type:
None
- class flexstack.utils.static_location_service.ThreadStaticLocationService(period=1000, latitude=41.387304, longitude=2.112485)[source]
Bases:
LocationServiceLocation Servie that just provides an static position.
- Variables:
period (int) – Periodicity of the location update in ms.
latitude (float) – Latitude of the static location.
longitude (float) – Longitude of the static location.
location_service_thread (threading.Thread) – The thread of the location service.
- Parameters:
period (int) –
latitude (float) –
longitude (float) –
- __init__(period=1000, latitude=41.387304, longitude=2.112485)[source]
Initialize the Static Location Service. period : int
Periodicity of the location update in ms.
- latitudefloat
Latitude of the static location.
- longitudefloat
Longitude of the static location.
- Parameters:
period (int) –
latitude (float) –
longitude (float) –
- Return type:
None
TimeService
- class flexstack.utils.time_service.TimeService[source]
Bases:
objectTime Service that provides the current time.
This class serves as a blueprint in implementations where the time comes from other devices or services different from the system time.