def onMessage(self, msg): msg = json.loads(msg) if msg['cmd'] == common_protocol.ServerCommands.DROP_TO_CONFIG: # wrong state, drop # flush IO io_clss = interface.get_interface_desc() for cls in io_clss['read']: cls.flush() for cls in io_clss['write']: cls.flush() self.protocol.pop_state() resp_msg = {'cmd': common_protocol.RPIClientCommands.DROP_TO_CONFIG_OK} self.sendJsonMessage(resp_msg) return elif msg['cmd'] == common_protocol.ServerCommands.ACK_DATA: server_ackcount = msg['ack_count'] self.ackcount += server_ackcount if self.ackcount > -10: self.poll_and_send() elif msg['cmd'] == common_protocol.ServerCommands.RESUME_STREAMING: self.resume_streaming() elif msg['cmd'] == common_protocol.ServerCommands.PAUSE_STREAMING: self.pause_streaming() elif msg['cmd'] == common_protocol.ServerCommands.WRITE_DATA: key = msg['inter_face_port'] value = msg['value'] self.write_to_inter_face(key, value)
def onMessage(self, msg): msg = json.loads(msg) if msg['cmd'] == common_protocol.ServerCommands.DROP_TO_CONFIG: # wrong state, drop # flush IO io_clss = interface.get_interface_desc() for cls in io_clss['read']: cls.flush() for cls in io_clss['write']: cls.flush() self.protocol.pop_state() resp_msg = {'cmd':common_protocol.RPIClientCommands.DROP_TO_CONFIG_OK} self.protocol.sendMessage(json.dumps(resp_msg)) return elif msg['cmd'] == common_protocol.ServerCommands.ACK_DATA: server_ackcount = msg['ack_count'] self.ackcount += server_ackcount if self.ackcount > -10: self.poll_and_send() elif msg['cmd'] == common_protocol.ServerCommands.RESUME_STREAMING: self.resume_streaming() elif msg['cmd'] == common_protocol.ServerCommands.PAUSE_STREAMING: self.pause_streaming() elif msg['cmd'] == common_protocol.ServerCommands.WRITE_DATA: key = msg['iface_port'] value = msg['value'] self.write_to_iface(key, value)
def __init__(self): common_protocol.ProtocolState.__init__(self) self.mac = rpi_data.utility.get_mac() self.interfaces = interface.get_interface_desc()