Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0301· OpenAIAi2 WildChat-4.8M (AI2)

import tkinter as tk from tkinter import filedialog import struct class…

  1. User

    import tkinter as tk from tkinter import filedialog import struct

    class Application(tk.Frame): def init(self, master): super().init(master) self.master = master self.filename = '' self.initUI()

    def initUI(self):
        menubar = tk.Menu(self.master)
        filemenu = tk.Menu(menubar, tearoff=False)
        filemenu.add_command(label='Open', command=self.opendialog)
        menubar.add_cascade(menu=filemenu, label='File')
        self.master.config(menu=menubar)
    
        self.table = tk.Frame(self.master)
        self.table.pack(fill=tk.BOTH, expand=True)
    
        tk.Label(self.table, text='APID').grid(row=0, column=0, padx=10, pady=5)
        tk.Label(self.table, text='Sequence Count').grid(row=0, column=1, padx=10, pady=5)
        tk.Label(self.table, text='Packet Length').grid(row=0, column=2, padx=10, pady=5)
        tk.Label(self.table, text='Data').grid(row=0, column=3, padx=10, pady=5)
    
    def opendialog(self):
        self.filename = filedialog.askopenfilename(defaultextension='.bin', filetypes=[('Binary Files', '.bin'), ('All Files', '.*')])
        if not self.filename:
            return
        self.process_file()
    
    def process_file(self):
        with open(self.filename, 'rb') as f:
            # Read the entire file contents as bytes
            file_contents = f.read()
    
            # Split the file contents into individual packets
            packet_delimiter = b'\x03' # CCSDS packet delimiter
            packets = file_contents.split(packet_delimiter)
    
            # Process each packet separately
            for index, packet in enumerate(packets):
                # Verify that the packet is a valid packet
                if not self.is_valid_packet(packet):
                    continue
    
                # Decode the packet header fields
                header_size, apid, sequence_count, packet_length = self.decode_packet_header(packet)
    
                # Extract the packet data
                packet_data = packet[header_size:]   # Create a table row for the packet
                row = tk.Frame(self.table)
                row.pack(fill=tk.X, padx=5, pady=5)
    
                tk.Label(row, text=hex(apid)).grid(row=0, column=0, padx=10, pady=5)
                tk.Label(row, text=sequence_count).grid(row=0, column=1, padx=10, pady=5)
                tk.Label(row, text=packet_length).grid(row=0, column=2, padx=10, pady=5)
                tk.Label(row, text=self.format_packet_data(packet_data)).grid(row=0, column=3, padx=10, pady=5)
    
  2. Assistant

    def is_valid_packet(self, packet): """ Determines if a given packet is a valid CCSDS packet """ if len(packet) < 6: return False if packet[:4] != b'\x1a\xcf\xfc\x1d': # CCSDS packet sync marker return False # Perform additional checks if needed return True

    def decode_packet_header(self, packet):
        """
        Decodes the CCSDS packet header fields
        """
        header_size = 6   # Total header is 6 bytes
        apid = struct.unpack('!H', packet[4:6])[0]
        sequence_count = struct.unpack('!H', packet[6:8])[0]
        packet_length = struct.unpack('!H', packet[8:10])[0]
        return (header_size, apid, sequence_count, packet_length)
    
    def format_packet_data(self, packet_data):
        """
        Formats the packet data for display purposes
        """
        # Perform formatting if needed
        return packet_data.hex()
    

    if name == 'main': root = tk.Tk() root.geometry('800x600') root.title('CCSDS Packet Viewer') app = Application(root) app.mainloop()