def show(self):
        """
        This method calls the .show() method of the view and returns
        the packet that the user creates in this window
        :return: The created packet
        """
        code = self.view.show()
        packet_translator = PacketTranslator()
        makoTranslate = MakoTranslate()

        pck_sec_header, src_data = self.view.get_tc_text()
        pck_sec_header = json.loads(makoTranslate.replace(pck_sec_header))
        src_data = json.loads(makoTranslate.replace(src_data))
        self.command["data"]["pck_sec_head"] = pck_sec_header
        self.command["data"]["user_data"]["src_data"] = src_data
        if code == 1:
            packet = packet_translator.json2packet(self.command)
            if self.view.is_svc_19():
                extra_val = self.view.get_event_id()
                try:
                    extra_val = int(extra_val)
                except ValueError as e:
                    extra_val = pb.pus_st05_getEventId(extra_val)
            else:
                extra_val = self.view.get_date_time()
            return packet, extra_val
        else:
            return None, None
    def send_callback(self):
        """
        This method is triggered when the user hits the send button.
        This method creates a packet from the json and validates that
        every field on that json is correct
        """
        mt = MakoTranslate()
        pt = PacketTranslator()
        vj = ValidateJson()

        try:
            pck_sec_header, src_data = self.view.get_tc_text()
            pck_sec_header = json.loads(mt.replace(pck_sec_header))
            src_data = json.loads(mt.replace(src_data))

            self.command["data"]["pck_sec_head"] = pck_sec_header
            self.command["data"]["user_data"]["src_data"] = src_data

            vj.check(self.command)

            packet = pt.json2packet(self.command)
            pb.pus_notify_sendPacket(packet)

            self.model.add_to_table(packet)  # Packet is created from json
            self.view.window.addTcButton.hide()
            self.view.close()
        except (ValidationError, JSONDecodeError) as err:
            msg_box = QtGui.QMessageBox()
            msg_box.setText('Some fields may be incorrect {}'.format(err))
            msg_box.setStandardButtons(QtGui.QMessageBox.Ok | QtGui.QMessageBox.Cancel)
            msg_box.exec_()
Example #3
0
    def add(self, packet: pb.pusPacket_t):
        """
        This method adds a packet in its packet representation and json representation
        to the app packet table
        :param packet: packet
        """
        pt = PacketTranslator()
        elem = pt.packet2json(packet)
        # print(elem)
        self.update_params(elem)
        from datetime import datetime
        list_ = []
        type_ = int(elem["primary_header"]["pck_id"]["pck_type"])
        if elem["primary_header"]["pck_id"]["sec_head_flg"]:
            svc_type_id = int(
                elem["data"]["pck_sec_head"]["msg_type_id"]["service_type_id"])
            msg_subtype_id = int(
                elem["data"]["pck_sec_head"]["msg_type_id"]["msg_subtype_id"])
            if type_ == 0:
                src = None
                dst = int(elem["data"]["pck_sec_head"]["dst_id"])
            else:
                src = int(elem["data"]["pck_sec_head"]["src_id"])
                dst = None
        else:
            svc_type_id = 9
            msg_subtype_id = 2
            src = None
            dst = None

        time_ = str(datetime.now().time().strftime("%H:%M:%S"))

        pck_seq_ctrl = int(elem["primary_header"]["pck_seq_ctrl"]["pck_seq"])
        status = "OK"  # Mirar
        information = self.__create_info_string__(elem)

        list_.append(self.elem_count)
        self.elem_count += 1
        list_.append("TM" if type_ == 0 else "TC")
        list_.append(svc_type_id)
        list_.append(msg_subtype_id)
        list_.append(time_)
        list_.append(src)
        list_.append(dst)
        list_.append(pck_seq_ctrl)
        list_.append(status)
        list_.append(information)
        list_.append(json.dumps(elem))
        list_.append(packet)
        self.table.append(list_)  # QtTable is updated here
 def add_tc_callback(self):
     """
     This method is triggered when the user creates a st19_1 or st11_4 telecommand
     and clicks the plus button to add an activity inside it. This method
     opens an addTcView window to create the telecommand to be embedded.
     """
     packet_translator = PacketTranslator()
     scndpacket, schedule = self.open_add_tc_window(True)
     if scndpacket is not None:
         if schedule is None:
             time_ = pb.pusTime_t()
             pb.pus_now(time_)
         else:
             time_ = pb.pus_posix2time(schedule)
         pb.pus_tc_11_4_setActivity(self.command_packet, scndpacket, time_)
         self.command = packet_translator.packet2json(self.command_packet)
         pck_sec_head = json.dumps(self.command["data"]["pck_sec_head"], indent=2)
         source_data = json.dumps(self.command["data"]["user_data"]["src_data"], indent=2)
         self.view.set_tc_text(pck_sec_head, source_data)
 def open_more_details_window_callback(self, clicked_index):
     """
     This method opens and writes all the information
     of the package selected in the window
     """
     row = clicked_index.row()
     pt = PacketTranslator()
     index = int(self.view.window.packagesTable.item(row, 0).text())
     details_view = DetailsView()
     details_view.write_information(json.dumps(json.loads(self.model.table[index][-2]), indent=8))
     self.opened_windows.append(details_view)
     details_view.show()
    def show_packet_json(self, svc, msg):
        """
        This method writes the packet with the service id and message id
        specified in json format in the textbox of the window.
        :param svc: Service id of the packet
        :param msg: Message id of the packet
        :return: The packet in json format
        """
        packet = pb.pusPacket_t()
        packet_translator = PacketTranslator()

        apid_info = self.model.apid_info
        apid = pb.pus_getInfoApid(apid_info)
        seq = pb.pus_getNextPacketCount(apid_info)

        if (svc, msg) == (8, 1):
            pb.pus_tc_8_1_createPerformFuctionRequest(packet, apid, seq, 0)
        elif (svc, msg) == (9, 1):
            pb.pus_tc_9_1_createSetTimeReportRate(packet, apid, seq, 0)
        elif svc == 11:
            if msg == 1:
                pb.pus_tc_11_1_createEnableTimeBasedSchedule(packet, apid, seq)
            elif msg == 2:
                pb.pus_tc_11_2_createDisableTimeBasedSchedule(
                    packet, apid, seq)
            elif msg == 3:
                pb.pus_tc_11_3_createResetTimeBasedSchedule(packet, apid, seq)
        elif svc == 12:
            if msg == 1:
                pb.pus_tc_12_1_createEnableParameterMonitoringDefinitions(
                    packet, apid, seq, 0)
            elif msg == 2:
                pb.pus_tc_12_2_createDisableParameterMonitoringDefinitions(
                    packet, apid, seq, 0)
            elif msg == 15:
                pb.pus_tc_12_15_createEnableParameterMonitoring(
                    packet, apid, seq)
            elif msg == 16:
                pb.pus_tc_12_16_createDisableParameterMonitoring(
                    packet, apid, seq)
        elif (svc, msg) == (17, 1):
            pb.pus_tc_17_1_createConnectionTestRequest(packet, apid, seq)
        elif svc == 19:
            if msg == 2:
                pb.pus_tc_19_2_createDeleteEventActionDefinitionsRequest(
                    packet, apid, seq, 0)
            elif msg == 4:
                pb.pus_tc_19_4_createEnableEventActionDefinitions(
                    packet, apid, seq, 0)
            elif msg == 5:
                pb.pus_tc_19_5_createDisableEventActionDefinitions(
                    packet, apid, seq, 0)
        elif svc == 20:
            if msg == 1:
                pb.pus_tc_20_1_createParameterValueRequest(
                    packet, apid, seq, 0)
            elif msg == 3:
                pb.pus_tc_20_3_createSetParameterValueRequest(
                    packet, apid, seq, 0, 0)
        elif svc == 23:
            if msg == 1:
                pb.pus_tc_23_1_createCreateFileRequest(packet, apid, seq, "",
                                                       "", 0)
            elif msg == 2:
                pb.pus_tc_23_2_createDeleteFileRequest(packet, apid, seq, "",
                                                       "")
            elif msg == 3:
                pb.pus_tc_23_3_createReportFileAtributesRequest(
                    packet, apid, seq, "", "")
            elif msg == 14:
                pb.pus_tc_23_14_createCopyFileRequest(packet, apid, seq, "",
                                                      "", "", "")
        else:
            pass
        return packet_translator.packet2json(packet)
    def show_packet_json(self, svc, msg):
        """
        This method writes the packet with the service id and message id
        specified in json format in the textbox of the window.
        :param svc: Service id of the packet
        :param msg: Message id of the packet
        :return: The packet in json format
        """
        packet = pb.pusPacket_t()
        packet_translator = PacketTranslator()
        apid_info = self.model.apid_info
        apid = pb.pus_getInfoApid(apid_info)
        seq = pb.pus_getNextPacketCount(apid_info) # REVISAR parece que la secuencia no aumenta

        if (svc, msg) == (8, 1):
            pb.pus_tc_8_1_createPerformFuctionRequest(packet, apid, seq, 0)
        elif (svc, msg) == (9, 1):
            pb.pus_tc_9_1_createSetTimeReportRate(packet, apid, seq, 0)
        elif svc == 11:
            if msg == 1:
                print(pb.pus_tc_11_1_createEnableTimeBasedSchedule(packet, apid, seq))
            elif msg == 2:
                pb.pus_tc_11_2_createDisableTimeBasedSchedule(packet, apid, seq)
            elif msg == 3:
                pb.pus_tc_11_3_createResetTimeBasedSchedule(packet, apid, seq)
            elif msg == 4:
                self.view.window.addTcButton.show()
                pb.pus_tc_11_4_createInsertActivityIntoSchedule(packet, apid, seq)

                scndpacket, schedule = self.open_add_tc_window(True)
                packet_translator.packet2json(scndpacket)
                if scndpacket is None:
                    self.view.window.msgComboBox.setCurrentIndex(0)
                    return None, None
                elif schedule is None:
                    time_ = pb.pusTime_t()
                    pb.pus_now(time_)
                else:
                    time_ = pb.pus_posix2time(schedule)
                    pb.pus_tc_11_4_setActivity(packet, scndpacket, time_)
        elif svc == 12:
            if msg == 1:
                pb.pus_tc_12_1_createEnableParameterMonitoringDefinitions(packet, apid, seq, 0)
            elif msg == 2:
                pb.pus_tc_12_2_createDisableParameterMonitoringDefinitions(packet, apid, seq, 0)
            elif msg == 15:
                pb.pus_tc_12_15_createEnableParameterMonitoring(packet, apid, seq)
            elif msg == 16:
                pb.pus_tc_12_16_createDisableParameterMonitoring(packet, apid, seq)
        elif (svc, msg) == (17, 1):
            pb.pus_tc_17_1_createConnectionTestRequest(packet, apid, seq)
        elif (svc, msg) == (18, 1):
            obcpid, length, obcpcode = self.open_obcp_add_code_window()
            pb.pus_tc_18_1_createLoadObcpDirectRequest(packet, apid, seq, obcpid, obcpcode, length)
        elif (svc, msg) == (18, 2):
            pb.pus_tc_18_2_createUnloadObcpRequest(packet, apid, seq, "")
        elif (svc, msg) == (18, 3):
            pb.pus_tc_18_3_createActivateObcpRequest(packet, apid, seq, "", 0)
        elif (svc, msg) == (18, 4):
            pb.pus_tc_18_4_createStopObcpRequest(packet, apid, seq, "", 0)
        elif (svc, msg) == (18, 5):
            pb.pus_tc_18_5_createSuspendObcpRequest(packet, apid, seq, "", 0)
        elif (svc, msg) == (18, 6):
            pb.pus_tc_18_6_createResumeObcpRequest(packet, apid, seq, "")
        elif (svc, msg) == (18, 12):
            pb.pus_tc_18_12_createAbortObcpRequest(packet, apid, seq, "")
        elif (svc, msg) == (18, 13):
            pb.pus_tc_18_13_createLoadObcpReferenceRequest(packet, apid, seq, "", "", "")
        elif (svc, msg) == (18, 21):
            pb.pus_tc_18_21_createStartObcpEngineRequest(packet, apid, seq,)
        elif (svc, msg) == (18, 22):
            pb.pus_tc_18_22_createStopObcpEngineRequest(packet, apid, seq)
        elif svc == 19:
            if msg == 1:
                scndpacket, event = self.open_add_tc_window(False)
                if scndpacket is None:
                    self.view.window.msgComboBox.setCurrentIndex(0)
                    return None, None
                else:
                    pb.pus_tc_19_1_createAddEventActionDefinitionsRequest(packet, apid, seq, event, scndpacket)
            elif msg == 2:
                pb.pus_tc_19_2_createDeleteEventActionDefinitionsRequest(packet, apid, seq, 0)
            elif msg == 4:
                pb.pus_tc_19_4_createEnableEventActionDefinitions(packet, apid, seq, 0)
            elif msg == 5:
                pb.pus_tc_19_5_createDisableEventActionDefinitions(packet, apid, seq, 0)
        elif svc == 20:
            if msg == 1:
                pb.pus_tc_20_1_createParameterValueRequest(packet, apid, seq, 0)
            elif msg == 3:
                pb.pus_tc_20_3_createSetParameterValueRequest(packet, apid, seq, 0, 0)
        elif svc == 23:
            if msg == 1:
                pb.pus_tc_23_1_createCreateFileRequest(packet, apid, seq, "", "", 0)
            elif msg == 2:
                pb.pus_tc_23_2_createDeleteFileRequest(packet, apid, seq, "", "")
            elif msg == 3:
                pb.pus_tc_23_3_createReportFileAtributesRequest(packet, apid, seq, "", "")
            elif msg == 14:
                pb.pus_tc_23_14_createCopyFileRequest(packet, apid, seq, "", "", "", "")
        else:
            pass
        return packet_translator.packet2json(packet), packet