def unpackage(data): """Function that takes a packaged proto and unpackages the item Parses through the python pseudo-class created by the protobuf and stores it into a dictionary. All of the axes data and the button data, enumerates each value to follow a mapping shared by dawn, and stores it in the dictionary with the gamepad index as a key. Student code status is also stored in this dictionary. This dictionary is added to the overall state through the update method implemented in state manager. """ unpackaged_data = {} received_proto = ansible_pb2.DawnData() received_proto.ParseFromString(data) new_state = received_proto.student_code_status unpackaged_data["student_code_status"] = [new_state, time.time()] if self.pipe.poll(): self.control_state = self.pipe.recv() if self.control_state is None or new_state != self.control_state: self.control_state = received_proto.student_code_status sm_state_command = self.sm_mapping[new_state] self.state_queue.put([sm_state_command, []]) all_gamepad_dict = {} for gamepad in received_proto.gamepads: gamepad_dict = {} gamepad_dict["axes"] = dict(enumerate(gamepad.axes)) gamepad_dict["buttons"] = dict(enumerate(gamepad.buttons)) all_gamepad_dict[gamepad.index] = gamepad_dict unpackaged_data["gamepads"] = [all_gamepad_dict, time.time()] if received_proto.team_color != ansible_pb2.DawnData.NONE: self.state_queue.put([ SM_COMMANDS.SET_TEAM, [self.team_color_mapping[received_proto.team_color]] ]) return unpackaged_data
def unpackage(data): """Function that takes a packaged proto and unpackages the item Parses through the python pseudo-class created by the protobuf and stores it into a dictionary. All of the axes data and the button data, enumerates each value to follow a mapping shared by dawn, and stores it in the dictionary with the gamepad index as a key. student code status is also stored in this dictionary. This dictionary is added to the overall state through the update method implemented in state manager. """ unpackaged_data = {} received_proto = ansible_pb2.DawnData() received_proto.ParseFromString(data) unpackaged_data["student_code_status"] = [ received_proto.student_code_status, time.time() ] all_gamepad_dict = {} for gamepad in received_proto.gamepads: gamepad_dict = {} gamepad_dict["axes"] = dict(enumerate(gamepad.axes)) gamepad_dict["buttons"] = dict(enumerate(gamepad.buttons)) all_gamepad_dict[gamepad.index] = gamepad_dict unpackaged_data["gamepads"] = [all_gamepad_dict, time.time()] return unpackaged_data
def dawn_packager(): proto_message = ansible_pb2.DawnData() proto_message.student_code_status = ansible_pb2.DawnData.TELEOP test_gamepad = proto_message.gamepads.add() test_gamepad.index = 0 test_gamepad.axes.append(.5) test_gamepad.buttons.append(True) return proto_message.SerializeToString()