summaryrefslogtreecommitdiffstats
path: root/gps.py
blob: 37caa4c5e9a8f8f7b46c5123dc368420f5225d4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from random import randint
import sys
import asyncio
from random import randint
from websockets import connect
from websockets.exceptions import ConnectionClosedError
import os
import json
import concurrent
from aglbaseservice import AGLBaseService


class GPSService(AGLBaseService):
    def __init__(self, ip, port):
        super().__init__(api='gps', ip=ip, port=port)

    async def location(self):
        verb = 'location'
        msgid = randint(0, 999999)
        await self.send(f'[2,"{msgid}","{self.api}/{verb}",""]')
        return await self.receive()

    async def subscribe(self, event='location'):
        await super().subscribe(event=event)

    async def unsubscribe(self, event='location'):
        await super().subscribe(event=event)


async def main(loop):
    addr = os.environ.get('AGL_TGT_IP', 'localhost')
    port = os.environ.get('AGL_TGT_PORT', '30011')

    gpss = await GPSService(ip=addr, port=port)

    await gpss.location()
    # listener = loop.create_task(gpss.listener())



if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main(loop))