def json_sensor_information_packet(self, packet): tmp = packet.read(4) tmp_buf = ByteBuffer(tmp, 0, 4) robot_length = tmp_buf.get_SLInt32() robot = str(packet.read(robot_length)) tmp = packet.read(4) tmp_buf = ByteBuffer(tmp, 0, 4) json_length = tmp_buf.get_SLInt32() json = str(packet.read(json_length)) info = json2obj(json) if robot in self.sensor_callbacks: for callback in self.sensor_callbacks[robot]: callback(robot, info) print packet
def event_packet(self, packet): ignore = packet.read(4) event_id = packet.read(1)[0] tmp = packet.read(8) tmp_buf = ByteBuffer(tmp, 0, 8) owner_length = tmp_buf.get_SLInt32() event_length = tmp_buf.get_SLInt32() owner = str(packet.read(owner_length)) event_json = str(packet.read(event_length)) print "Got event #" + str( event_id) + " from " + owner + ". Data: " + event_json event_data = json2obj(event_json) if event_id in self.event_callbacks: for callback in self.event_callbacks[event_id]: callback(event_data, owner)