#!/usr/bin/python3.8
"""
@brief      Binary Uploader Module
@details
This module will be used to upload binaries to the OBC via a communication port, given
a supplied binary. The binary will be sent via the specified communication interface.
It will be possible to encode the data (for example using DLE encoding)
"""
import tkinter as tk
from tkinter import filedialog

import config.obsw_config as g


def perform_binary_upload():
    print("Please select file to upload")
    root = tk.Tk()
    root.withdraw()
    root.wm_attributes('-topmost', 1)
    file_path = filedialog.askopenfilename(parent=root)
    print("File select: " + str(file_path))
    calc_hamming_code = input("Calculate and send hamming code? [y/n]")
    if calc_hamming_code in ['y', 'yes', 1]:
        calc_hamming_code = True
        print("Hamming code will be calculated and sent in tail packet")
    else:
        calc_hamming_code = False
        print("Hamming code will not be calculated")

    # Right now, the size of PUS packets is limited to 1024 bytes. Therefore, we split up the
    # binary in 1000 byte packets
    frame_length = g.G_MAX_BINARY_FRAME_LENGTH

    if calc_hamming_code:
        # now we calculate the hamming code
        pass

    # We have to split the binary here first