Esempio n. 1
0
import a0

a0.InitGlobalTopicManager('''{
    "container": "controller",
    "subscriber_maps": {
        "where_am_I": {
            "container": "localizer",
            "topic": "location"
        }
    }
}''')

sub = a0.SubscriberSync('where_am_I', a0.INIT_OLDEST, a0.ITER_NEXT)
print('Starting iteration')
while sub.has_next():
    print('I am', sub.next().payload)
print('Done!')
Esempio n. 2
0
import a0
import time

a0.InitGlobalTopicManager('''{
    "container": "bar",
    "rpc_client_maps": {
        "drive_in_circles": {
            "container": "stuff_doer",
            "topic": "navigate"
        }
    }
}''')

client = a0.RpcClient('drive_in_circles')


def callback(pkt):
    print('Recieved reply:', pkt.payload)


print('Awaiting for 0.01 sec')
client.send('Please do!', callback)
time.sleep(0.01)
print('Done!')
Esempio n. 3
0
import a0
import time

a0.InitGlobalTopicManager('''{
    "container": "stuff_doer"
}''')


def onrequest(req):
    print('Request (id={}):'.format(req.pkt.id), req.pkt.payload)
    req.reply('No path found. Try again later')


def oncancel(id):
    print('Cancel req:', id)


print('Listening for 60 sec')
server = a0.RpcServer('navigate', onrequest, oncancel)
time.sleep(60)
print('Done!')
Esempio n. 4
0
        pkt, done = await ns.q.get()
        await ws.send_json({
            "headers":
            pkt.headers,
            "payload":
            base64.b64encode(pkt.payload).decode("utf-8"),
        })
        if done:
            break
        if scheduler == "IMMEDIATE":
            pass
        elif scheduler == "ON_ACK":
            await ws.receive()


a0.InitGlobalTopicManager({"container": "api"})
heartbeat = a0.Heartbeat()

app = aiohttp.web.Application()
app.add_routes([
    aiohttp.web.get("/api/ls", ls_handler),
    aiohttp.web.post("/api/pub", pub_handler),
    aiohttp.web.post("/api/rpc", rpc_handler),
    aiohttp.web.get("/wsapi/pub", pub_wshandler),
    aiohttp.web.get("/wsapi/sub", sub_wshandler),
    aiohttp.web.get("/wsapi/prpc", prpc_wshandler),
])
cors = aiohttp_cors.setup(
    app,
    defaults={
        "*":
Esempio n. 5
0
import a0
import time

a0.InitGlobalTopicManager('''{
    "container": "localizer"
}''')

p = a0.Publisher('location')
for i in range(10):
    payload = 'here (ts={})'.format(i)
    print('publishing:', payload)
    p.pub(payload)
    time.sleep(1)

print('Done!')