flexstack.utils Module

The flexstack.utils package provides location and timing infrastructure.

LocationService & Position

class flexstack.utils.location_service.LocationService[source]

Bases: object

Location 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.

__init__()[source]

Initialize the Location Service.

Return type:

None

send_to_callbacks(location)[source]

Send the location to all callbacks.

Parameters:

location (dict) – The location to send. (In TPV format)

Return type:

None

add_callback(callback)[source]

Add a callback to the Location Service.

Parameters:

callback (Callable[[dict], None]) – The callback to add.

Return type:

None

remove_callback(callback)[source]

Remove a callback from the Location Service.

Parameters:

callback (Callable[[dict], None]) – The callback to remove.

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: LocationService

Location 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) –

__init__(gpsd_host='localhost', gpsd_port=2947)[source]

Initialize the Location Service.

Parameters:
  • gpsd_host (str) – The host of the gpsd server.

  • gpsd_port (int) – The port of the gpsd server.

Return type:

None

reconnect()[source]

Reconnect the Location Service.

Return type:

None

start()[source]

Starts the Location Service Thread.

Return type:

None

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: LocationService

Location 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

async start_async()[source]

Start the Static Location Service.

Return type:

None

class flexstack.utils.static_location_service.ThreadStaticLocationService(period=1000, latitude=41.387304, longitude=2.112485)[source]

Bases: LocationService

Location 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

start()[source]

Start the Static Location Service.

Return type:

None

TimeService

class flexstack.utils.time_service.TimeService[source]

Bases: object

Time 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.

static time()[source]

Get the current UTC Timestamp in Seconds.

Returns:

UTC Timestamp in Seconds.

Return type:

float

static timestamp_its()[source]

Get the current ITS Timestamp in Milliseconds.

Returns:

ITS Timestamp in Milliseconds(with leap seconds added).

Return type:

int