示例#1
0
def update_gps(rocket_data: RocketData, device: DeviceType) -> str:
    latitude = rocket_data.last_value_by_device(device, DataEntryIds.LATITUDE)
    longitude = rocket_data.last_value_by_device(device,
                                                 DataEntryIds.LONGITUDE)
    if latitude is not None and longitude is not None:
        return f'{latitude:.5f}\xb0, {longitude:.5f}\xb0'
    else:
        return VALUE_NOT_AVAILABLE
示例#2
0
def update_acceleration(rocket_data: RocketData, device: DeviceType) -> str:
    x = rocket_data.last_value_by_device(device, DataEntryIds.ACCELERATION_X)
    y = rocket_data.last_value_by_device(device, DataEntryIds.ACCELERATION_Y)
    z = rocket_data.last_value_by_device(device, DataEntryIds.ACCELERATION_Z)

    if all([val is not None for val in (x, y, z)]):
        accel = math.sqrt(x**2 + y**2 + z**2)
        return f'{accel:.2f} g'
    else:
        return VALUE_NOT_AVAILABLE
示例#3
0
def update_altitude(rocket_data: RocketData, device: DeviceType) -> str:
    altitude = rocket_data.last_value_by_device(
        device, DataEntryIds.CALCULATED_ALTITUDE)
    if altitude is not None:
        return f'{altitude:.2f} m'
    else:
        return VALUE_NOT_AVAILABLE
def update_state(rocket_data: RocketData, device: DeviceType) -> str:
    state: Union[DataEntryValues, None] = rocket_data.last_value_by_device(
        device, DataEntryIds.STATE)
    if state is not None:
        return state.name
    else:
        return VALUE_NOT_AVAILABLE
    def __init__(self, connections: Dict[str, Connection],
                 rocket_profile: RocketProfile) -> None:
        """

        :param connection:
        :type connection: Connection
        :param rocket_profile:
        :type rocket_profile: RocketProfile
        """
        # Prints constructor arguments, leave at top of constructor
        LOGGER.debug(f"Starting MainApp with {locals()}")

        if connections is None:
            raise Exception("Invalid connections provided")

        QtWidgets.QMainWindow.__init__(self)
        self.setupUi(self)

        self.connections = connections
        self.rocket_profile = rocket_profile
        self.device_manager = DeviceManager(
            self.rocket_profile.expected_devices,
            self.rocket_profile.required_device_versions,
            strict_versions=False)
        self.rocket_data = RocketData(self.device_manager)
        self.command_parser = CommandParser(self.device_manager)

        packet_parser = self.rocket_profile.construct_packet_parser()

        # Init and connection of ReadThread
        self.ReadThread = ReadThread(self.connections, self.rocket_data,
                                     packet_parser, self.device_manager)
        self.ReadThread.sig_received.connect(self.receive_data)
        self.ReadThread.start()

        # Init and connection of SendThread
        self.SendThread = SendThread(self.connections, self.device_manager,
                                     self.command_parser)
        self.sig_send.connect(self.SendThread.queueMessage)
        self.SendThread.start()
class MainApp(QtWidgets.QMainWindow):
    sig_send = pyqtSignal(str)

    def __init__(self, connections: Dict[str, Connection],
                 rocket_profile: RocketProfile) -> None:
        """

        :param connection:
        :type connection: Connection
        :param rocket_profile:
        :type rocket_profile: RocketProfile
        """
        # Prints constructor arguments, leave at top of constructor
        LOGGER.debug(f"Starting MainApp with {locals()}")

        if connections is None:
            raise Exception("Invalid connections provided")

        QtWidgets.QMainWindow.__init__(self)
        self.setupUi(self)

        self.connections = connections
        self.rocket_profile = rocket_profile
        self.device_manager = DeviceManager(
            self.rocket_profile.expected_devices,
            self.rocket_profile.required_device_versions,
            strict_versions=False)
        self.rocket_data = RocketData(self.device_manager)
        self.command_parser = CommandParser(self.device_manager)

        packet_parser = self.rocket_profile.construct_packet_parser()

        # Init and connection of ReadThread
        self.ReadThread = ReadThread(self.connections, self.rocket_data,
                                     packet_parser, self.device_manager)
        self.ReadThread.sig_received.connect(self.receive_data)
        self.ReadThread.start()

        # Init and connection of SendThread
        self.SendThread = SendThread(self.connections, self.device_manager,
                                     self.command_parser)
        self.sig_send.connect(self.SendThread.queueMessage)
        self.SendThread.start()

    def closeEvent(self, event) -> None:
        """
        This is called when application is closing
        :param event:
        :type event:
        """
        self.shutdown()

    def shutdown(self):
        """
        This is called when the app is being requested to shut down
        :return:
        :rtype:
        """
        LOGGER.debug(f"MainApp shutting down")
        self.ReadThread.shutdown()
        self.SendThread.shutdown()
        self.rocket_data.shutdown()
        for connection in self.connections.values():
            connection.shutdown()
        LOGGER.debug(
            f"All threads shut down, remaining threads: {threading.enumerate()}"
        )

        LOGGER.info("Saving...")
        self.rocket_data.save(
            os.path.join(LOGS_DIR, "finalsave_" + SESSION_ID + ".csv"))
        LOGGER.info("Saved!")

    def receive_data(self) -> None:
        """
        This is called when new data is available to be displayed.
        :return:
        :rtype:
        """
        pass

    def send_command(self, command) -> None:
        """
        Call this to send a command
        :param command:
        :type command:
        """
        self.sig_send.emit(command)
示例#7
0
def rocket_data_with_bulk_added(full_device_manager, bulk_sensor_bundle):
    rocket_data = RocketData(full_device_manager)
    bulk_address = full_device_manager.get_full_address(
        bulk_sensor_bundle[DataEntryIds.DEVICE_TYPE])
    rocket_data.add_bundle(bulk_address, bulk_sensor_bundle)
    return rocket_data, bulk_address
示例#8
0
def update_pressure(rocket_data: RocketData, device: DeviceType) -> str:
    pressure = rocket_data.last_value_by_device(device, DataEntryIds.PRESSURE)
    if pressure is not None:
        return f'{pressure:.2f} mbar'
    else:
        return VALUE_NOT_AVAILABLE
示例#9
0
def update_max_altitude(rocket_data: RocketData, device: DeviceType) -> str:
    altitude = rocket_data.highest_altitude_by_device(device)
    if altitude is not None:
        return f'{altitude:.2f} m'
    else:
        return VALUE_NOT_AVAILABLE