def notify(self, vcid): """ Notifies virtual channel handler of change in VCID """ # No longer the active channel handler if vcid != self.VCID: # Channel has unfinished TP_File if self.cTPFile != None: # Handle S_PDU (decryption) spdu = CCSDS.S_PDU(self.cTPFile.PAYLOAD, self.keys) # Create new xRIT file xrit = CCSDS.xRIT(spdu.PLAINTEXT) xrit.save(self.outputPath) xrit.print_info() if len(self.cTPFile.PAYLOAD) < self.cTPFile.LENGTH: print( " FILE IS INCOMPLETE (Known issue with COMSFOG / COMSIR images)" ) ac = len(self.cTPFile.PAYLOAD) ex = self.cTPFile.LENGTH p = round((ac / ex) * 100) print(" {}% OF EXPECTED LENGTH".format(p)) # Clear finished TP_File self.cTPFile = None
def notify(self, vcid): """ Notifies virtual channel handler of change in VCID """ # No longer the active channel handler if vcid != self.config.VCID: # Channel has unfinished TP_File if self.cTPFile != None: # Handle S_PDU (decryption) spdu = CCSDS.S_PDU(self.cTPFile.PAYLOAD, self.config.keys) # Handle xRIT file self.handle_xRIT(spdu) if len(self.cTPFile.PAYLOAD) < self.cTPFile.LENGTH: print( " " + Fore.WHITE + Back.RED + Style.BRIGHT + "FILE IS INCOMPLETE (Known issue with COMSFOG / COMSIR images)" ) ac = len(self.cTPFile.PAYLOAD) ex = self.cTPFile.LENGTH p = round((ac / ex) * 100) print(" " + Fore.WHITE + Back.RED + Style.BRIGHT + "{}% OF EXPECTED LENGTH".format(p)) # Clear finished TP_File self.cTPFile = None elif self.cProduct != None: # Save and clear current product self.cProduct.save() self.cProduct = None
def handle_CPPDU(self, cppdu): """ Processes complete CP_PDUs to build a TP_File """ if cppdu.SEQ == cppdu.Sequence.FIRST: # Create new TP_File self.cTPFile = CCSDS.TP_File(cppdu.PAYLOAD[:-2]) elif cppdu.SEQ == cppdu.Sequence.CONTINUE: # Add data to TP_File self.cTPFile.append(cppdu.PAYLOAD[:-2]) elif cppdu.SEQ == cppdu.Sequence.LAST: # Close current TP_File lenok = self.cTPFile.finish(cppdu.PAYLOAD[:-2]) if self.config.verbose: self.cTPFile.print_info() if lenok: if self.config.verbose: print(" " + Fore.GREEN + Style.BRIGHT + "LENGTH: OK\n") # Handle S_PDU (decryption) spdu = CCSDS.S_PDU(self.cTPFile.PAYLOAD, self.config.keys) # Handle xRIT file self.handle_xRIT(spdu) # Print key index if self.config.verbose: print(" KEY INDEX: 0x{}\n".format( hex(int.from_bytes(spdu.index, byteorder="big"))[2:].upper())) elif not lenok: ex = self.cTPFile.LENGTH ac = len(self.cTPFile.PAYLOAD) diff = ac - ex if self.config.verbose: print( " " + Fore.WHITE + Back.RED + Style.BRIGHT + "LENGTH: ERROR (EXPECTED: {}, ACTUAL: {}, DIFF: {})" .format(ex, ac, diff)) print(" " + Fore.WHITE + Back.RED + Style.BRIGHT + "SKIPPING FILE DUE TO DROPPED PACKETS") # Clear finished TP_File self.cTPFile = None if self.config.verbose: ac = len(self.cTPFile.PAYLOAD) ex = self.cTPFile.LENGTH p = round((ac / ex) * 100) diff = ex - ac print( " [TP_File] CURRENT LEN: {} ({}%) EXPECTED LEN: {} DIFF: {}\n\n\n" .format(ac, p, ex, diff))
def handle_CPPDU(self, cppdu): """ Processes complete CP_PDUs to build a TP_File """ if cppdu.SEQ == cppdu.Sequence.FIRST: # Create new TP_File self.cTPFile = CCSDS.TP_File(cppdu.PAYLOAD[:-2]) elif cppdu.SEQ == cppdu.Sequence.CONTINUE: # Add data to TP_File self.cTPFile.append(cppdu.PAYLOAD[:-2]) elif cppdu.SEQ == cppdu.Sequence.LAST: # Close current TP_File lenok = self.cTPFile.finish(cppdu.PAYLOAD[:-2]) if self.verbose: self.cTPFile.print_info() if lenok: if self.verbose: print(" LENGTH: OK\n") # Handle S_PDU (decryption) spdu = CCSDS.S_PDU(self.cTPFile.PAYLOAD, self.keys) # Create new xRIT file xrit = CCSDS.xRIT(spdu.PLAINTEXT) xrit.save(self.outputPath) xrit.print_info() elif not lenok: ex = self.cTPFile.LENGTH ac = len(self.cTPFile.PAYLOAD) diff = ac - ex if self.verbose: print( " LENGTH: ERROR (EXPECTED: {}, ACTUAL: {}, DIFF: {})" .format(ex, ac, diff)) print(" SKIPPING FILE (DROPPED PACKETS?)") # Clear finished TP_File self.cTPFile = None if self.verbose: ac = len(self.cTPFile.PAYLOAD) ex = self.cTPFile.LENGTH p = round((ac / ex) * 100) diff = ex - ac print( " [TP_File] CURRENT LEN: {} ({}%) EXPECTED LEN: {} DIFF: {}\n\n\n" .format(ac, p, ex, diff))
def handle_CPPDU(self, cppdu): """ Processes complete CP_PDUs to build a TP_File """ if cppdu.SEQ == "FIRST": # Create new TP_File self.cTPFile = CCSDS.TP_File(cppdu.PAYLOAD[:-2]) elif cppdu.SEQ == "CONTINUE": # Add data to TP_File self.cTPFile.append(cppdu.PAYLOAD[:-2]) elif cppdu.SEQ == "LAST": # Close current TP_File lenok = self.cTPFile.finish(cppdu.PAYLOAD[:-2]) if self.verbose: self.cTPFile.print_info() if lenok: if self.verbose: print(" LENGTH: OK\n") # Handle S_PDU (decryption) spdu = CCSDS.S_PDU(self.cTPFile.PAYLOAD, self.keys) # Create new xRIT file xrit = CCSDS.xRIT(spdu.PLAINTEXT) xrit.save(self.outputPath) xrit.print_info() elif not lenok: ex = self.cTPFile.LENGTH ac = len(self.cTPFile.PAYLOAD) diff = ac - ex if self.verbose: print( " LENGTH: ERROR (EXPECTED: {}, ACTUAL: {}, DIFF: {})" .format(ex, ac, diff)) print(" SKIPPING FILE (DROPPED PACKETS?)")