Exemple #1
0
    def data_in(self, vcdu):
        """
        Takes in VCDUs for the channel handler to process
        :param packet: Parsed VCDU object
        """

        # Check VCDU continuity
        self.VCDU_continuity(vcdu)

        # Parse M_PDU
        mpdu = CCSDS.M_PDU(vcdu.MPDU)

        # If M_PDU contains CP_PDU header
        if mpdu.HEADER:
            # If data preceeds header
            if mpdu.POINTER != 0:
                # Finish previous CP_PDU
                preptr = mpdu.PACKET[:mpdu.POINTER]

                try:
                    lenok, crcok = self.cCPPDU.finish(preptr, self.crclut)
                    if self.verbose: self.check_CPPDU(lenok, crcok)

                    # Handle finished CP_PDU
                    self.handle_CPPDU(self.cCPPDU)
                except AttributeError:
                    if self.verbose:
                        print("  NO CP_PDU TO FINISH (DROPPED PACKETS?)")

                #TODO: Check CP_PDU continuity

                # Create new CP_PDU
                postptr = mpdu.PACKET[mpdu.POINTER:]
                self.cCPPDU = CCSDS.CP_PDU(postptr)

            else:
                # First CP_PDU in TP_File
                # Create new CP_PDU
                self.cCPPDU = CCSDS.CP_PDU(mpdu.PACKET)

            #TODO: Finish SEQ LAST CP_PDU before going to FILL

            # Handle special EOF CP_PDU
            if self.cCPPDU.is_EOF():
                self.cCPPDU = None
            else:
                if self.verbose:
                    self.cCPPDU.print_info()
                    print("    HEADER:     0x{}".format(
                        hex(mpdu.POINTER)[2:].upper()))
        else:
            # Append packet to current CP_PDU
            try:
                self.cCPPDU.append(mpdu.PACKET)
            except AttributeError:
                if self.verbose:
                    print("  NO CP_PDU TO APPEND M_PDU TO (DROPPED PACKETS?)")
Exemple #2
0
    def data_in(self, vcdu):
        """
        Takes in VCDUs for the channel handler to process
        :param packet: Parsed VCDU object
        """

        # Check VCDU continuity counter
        self.continuity(vcdu)

        # Parse M_PDU
        mpdu = CCSDS.M_PDU(vcdu.MPDU)

        # If M_PDU contains CP_PDU header
        if mpdu.HEADER:
            # If data preceeds header
            if mpdu.POINTER != 0:
                # Finish previous CP_PDU
                preptr = mpdu.PACKET[:mpdu.POINTER]

                try:
                    lenok, crcok = self.cCPPDU.finish(preptr, self.crclut)
                    if self.verbose: self.check_CPPDU(lenok, crcok)

                    # Handle finished CP_PDU
                    self.handle_CPPDU(self.cCPPDU)
                except AttributeError:
                    if self.verbose:
                        print("  NO CP_PDU TO FINISH (DROPPED PACKETS?)")

                #TODO: Check CP_PDU continuity

                # Create new CP_PDU
                postptr = mpdu.PACKET[mpdu.POINTER:]
                self.cCPPDU = CCSDS.CP_PDU(postptr)

                # Need more data to parse CP_PDU header
                if not self.cCPPDU.PARSED:
                    return

                # Handle CP_PDUs less than one M_PDU in length
                if 1 < self.cCPPDU.LENGTH < 886 and len(
                        self.cCPPDU.PAYLOAD) > self.cCPPDU.LENGTH:
                    # Remove trailing null bytes (M_PDU padding)
                    self.cCPPDU.PAYLOAD = self.cCPPDU.PAYLOAD[:self.cCPPDU.
                                                              LENGTH]

                    try:
                        lenok, crcok = self.cCPPDU.finish(b'', self.crclut)
                        if self.verbose: self.check_CPPDU(lenok, crcok)

                        # Handle finished CP_PDU
                        self.handle_CPPDU(self.cCPPDU)
                    except AttributeError:
                        if self.verbose:
                            print("  NO CP_PDU TO FINISH (DROPPED PACKETS?)")

            else:
                # First CP_PDU in TP_File
                # Create new CP_PDU
                self.cCPPDU = CCSDS.CP_PDU(mpdu.PACKET)

            # Handle special EOF CP_PDU
            if self.cCPPDU.is_EOF():
                self.cCPPDU = None
                if self.verbose: print("  [CP_PDU] EOF MARKER")
            else:
                if self.verbose:
                    self.cCPPDU.print_info()
                    print("    HEADER:     0x{}".format(
                        self.cCPPDU.header.hex().upper()))
                    print("    OFFSET:     0x{}\n    ".format(
                        hex(mpdu.POINTER)[2:].upper()),
                          end="")
        else:
            # Append packet to current CP_PDU
            try:
                wasparsed = self.cCPPDU.PARSED
                self.cCPPDU.append(mpdu.PACKET)
                if wasparsed != self.cCPPDU.PARSED and self.verbose:
                    self.cCPPDU.print_info()
                    print("    HEADER:     0x{}".format(
                        self.cCPPDU.header.hex().upper()))
                    print("    OFFSET:     SPANS MULTIPLE M_PDUs\n", end="")
            except AttributeError:
                if self.verbose:
                    print("  NO CP_PDU TO APPEND M_PDU TO (DROPPED PACKETS?)")

        # VCDU indicator
        if self.verbose: print(".", end="")
        sys.stdout.flush()
Exemple #3
0
    def data_in(self, vcdu):
        """
        Takes in VCDUs for the channel handler to process
        :param packet: Parsed VCDU object
        """

        # Check VCDU continuity counter
        self.continuity(vcdu)

        # Parse M_PDU
        mpdu = CCSDS.M_PDU(vcdu.MPDU)

        # If M_PDU contains CP_PDU header
        if mpdu.HEADER:
            # No current TP_File and CP_PDU header is at the start of M_PDU
            if self.cTPFile == None and mpdu.POINTER == 0:
                # Create CP_PDU for new TP_File
                self.cCPPDU = CCSDS.CP_PDU(mpdu.PACKET)

            # Continue unfinished TP_File
            else:
                # If M_PDU contains data from previous CP_PDU
                if mpdu.POINTER != 0:
                    # Finish previous CP_PDU
                    preptr = mpdu.PACKET[:mpdu.POINTER]
                else:
                    # No data to append
                    preptr = b''

                try:
                    lenok, crcok = self.cCPPDU.finish(preptr, self.config.lut)
                    if self.config.verbose: self.check_CPPDU(lenok, crcok)

                    # Handle finished CP_PDU
                    self.handle_CPPDU(self.cCPPDU)
                except AttributeError:
                    if self.config.verbose:
                        print("  " + Fore.WHITE + Back.RED + Style.BRIGHT +
                              "NO CP_PDU TO FINISH (DROPPED PACKETS?)")

                # Create new CP_PDU
                postptr = mpdu.PACKET[mpdu.POINTER:]
                self.cCPPDU = CCSDS.CP_PDU(postptr)

                # Need more data to parse CP_PDU header
                if not self.cCPPDU.PARSED:
                    return

                # Handle CP_PDUs less than one M_PDU in length
                if 1 < self.cCPPDU.LENGTH < 886 and len(
                        self.cCPPDU.PAYLOAD) > self.cCPPDU.LENGTH:
                    # Remove trailing null bytes (M_PDU padding)
                    self.cCPPDU.PAYLOAD = self.cCPPDU.PAYLOAD[:self.cCPPDU.
                                                              LENGTH]

                    try:
                        lenok, crcok = self.cCPPDU.finish(b'', self.config.lut)
                        if self.config.verbose: self.check_CPPDU(lenok, crcok)

                        # Handle finished CP_PDU
                        self.handle_CPPDU(self.cCPPDU)
                    except AttributeError:
                        if self.config.verbose:
                            print("  " + Fore.WHITE + Back.RED + Style.BRIGHT +
                                  "NO CP_PDU TO FINISH (DROPPED PACKETS?)")

            # Handle special EOF CP_PDU (by ignoring it)
            if self.cCPPDU.is_EOF():
                self.cCPPDU = None
                if self.config.verbose:
                    print("   " + Fore.GREEN + Style.BRIGHT +
                          "[CP_PDU] EOF MARKER\n")
            else:
                if self.config.verbose:
                    self.cCPPDU.print_info()
                    print("    HEADER:     0x{}".format(
                        self.cCPPDU.header.hex().upper()))
                    print("    OFFSET:     0x{}\n    ".format(
                        hex(mpdu.POINTER)[2:].upper()),
                          end="")
        else:
            # Append M_PDU payload to current CP_PDU
            try:
                # Check if CP_PDU header has been parsed
                wasparsed = self.cCPPDU.PARSED

                # Add data from current M_PDU
                self.cCPPDU.append(mpdu.PACKET)

                # If CP_PDU header was just parsed, print CP_PDU header info
                if wasparsed != self.cCPPDU.PARSED and self.config.verbose:
                    self.cCPPDU.print_info()
                    print("    HEADER:     0x{}".format(
                        self.cCPPDU.header.hex().upper()))
                    print("    OFFSET:     SPANS MULTIPLE M_PDUs\n", end="")
            except AttributeError:
                if self.config.verbose:
                    print("  " + Fore.WHITE + Back.RED + Style.BRIGHT +
                          "NO CP_PDU TO APPEND M_PDU TO (DROPPED PACKETS?)")

        # VCDU indicator
        if self.config.verbose: print(".", end="")
        sys.stdout.flush()