Esempio n. 1
0
async def ws_send_loop(sleepsec):
    while 1:
        if len(MESSAGES):
            msg, addr = MESSAGES[-1]
            mid, ts = messages.decodeHeader(msg, addr)
            reset_messages()
            await notify_users(msg)
            print("async update sent.. ts:{} (to {} users before {})".format(ts, len(USERS), datetime.datetime.now()))
        await asyncio.sleep(sleepsec)
Esempio n. 2
0
 def datagram_received(self, data, addr):
     towebsocket = data
     logger.debug("---Incoming UDP---")
     mid, ts = messages.decodeHeader(data, addr)
     logger.debug(f"Data Length: {len(data)}")
     hexmsg = ""
     for i in range(len(data) // 16 + 1):
         hexmsg += "|".join([f"0x{idx:02x}" for idx in data[16 * i:16 * (i + 1)]]) + '\n'
     logger.debug(hexmsg)
     logger.debug("--End Incoming UDP --")
     MESSAGES.append((data, addr))
     if len(MESSAGES):
         logger.debug(f"There are already {len(MESSAGES)} updates waiting to be sent...")
Esempio n. 3
0
    def decodeAgentInputs(cls, packet):
        """ Decodes the states of the agents from an UDP packet, into a list of objects."""
        agentList = []
        mid, ts = messages.decodeHeader(packet)
        ln = np.frombuffer(packet[16:20], np.int32).ravel()

        for i in range(ln[0]):
            agent = cls()

            agent.mid, agent.number = np.frombuffer(
                packet[64 * i + 20:64 * i + 28], np.int32)
            ss = np.frombuffer(packet[64 * i + 28:64 * i + 28 + 7 * 8],
                               np.float64)
            agent.states = ss[:5]
            agent.vleft = ss[5]
            agent.vright = ss[6]
            agentList.append(agent)
        return agentList
Esempio n. 4
0
async def replynewmap(websocket, path):
    register(websocket)
    try:
        async for message in websocket:
            global CNT
            CNT += 1
            CNT = CNT % 256
            logger.debug("Received ws message... Total: {}".format(CNT))
            mid, ts = messages.decodeHeader(message, websocket.remote_address[0])
            if mid == 3:
                try:
                    now = datetime.datetime.now()
                    nowstr = now.strftime("%y%m%d%H%M%S")
                    with open(os.path.join('img', "pngfile{}.png".format(nowstr)), 'wb') as f:
                        read_data = f.write(message[16:])
                    # f.closed
                    logger.info("Screenshot saved.")
                    resolution = int(message)
                except Exception as e:
                    resolution = 100
                    print(e)
            # await websocket.send(tobytes)
    finally:
        unregister(websocket)
Esempio n. 5
0
 async def handle_income_packet(self, data, addr):
     await notify_users(data)
     mid, ts = messages.decodeHeader(data, addr)
     print("async update sent.. ts:{} (to {} users before {})".format(ts, len(USERS), datetime.datetime.now()))