Verified Commit debe9406 authored by Clayton Craft's avatar Clayton Craft
Browse files

main: fix sending sentences to clients

The connection handler will now 'sleep' in a loop (since clients aren't
expected to send data..), and sentences to send to clients will now
happen in the main application loop. So all clients will receive the
same sentences, and they'll receive them quickly.
parent 538129fb
......@@ -32,8 +32,6 @@ class GnssShare:
self._open_connections = []
# Reference to open device/driver
self._active_driver = None
# Holds the last NMEA location sentence retrieved from the device
self._sentence = b""
# Set by signal handler to indicate AGPS data should be stored
self._signal_store = False
self._socket_path = config['gnss_share'].get('socket')
......@@ -72,26 +70,16 @@ class GnssShare:
async with self._driver(self._device_path) as driver:
async def _get_sentence(self):
""" Returns last received sentence from gnss driver, or None """
if not self._active_driver:
self.__log.warn("Tried to read from inactive device!")
return b""
return self._sentence
async def _handle_socket_connection(self, conn):
""" Handler for client connections over a socket """"Got new connection from client on "
while True:
sentence = await self._get_sentence()
if sentence:
await conn.send_all(sentence)
# Send data to clients at this rate.
# TODO: is this too fast or too slow?
await trio.sleep(1)
# loop on connection until it's closed. sending data is handled
# elsewhere
async for _ in conn:
except trio.BrokenResourceError:"A socket client disconnected")
......@@ -137,11 +125,9 @@ class GnssShare:
self._active_driver = self._driver(self._device_path,
self._sentence = await self._active_driver.readline()
# polling loop delay when clients are connected
# TODO: is this adequate? Any faster and CPU utilization
# climbs...
await trio.sleep(.2)
sentence = await self._active_driver.readline()
for conn in self._open_connections:
await conn.send_all(sentence)
if self._active_driver is not None:"No more clients connected, closing "
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment