import sys


print("Build mode:",sys.argv[1])



if sys.argv[1] == "debug":


    # Open the binary file
    f = open("antaris_exo_core_vfb.bin", mode="rb")

    # Read the binary data
    data = f.read()

    # Print the type and content of the data
    print(type(data))
    #print(data)


    varname = 'volatile uint8_t __attribute__((section(".merge_vfb"))) vfb_bin_bytestream[] = {\n'

    data_hex = '0x'            
    data_hex += ',0x'.join(format(x, '02x') for x in data)
    endbrace = '\n};'
            #print(data_hex)

    data_hex_with_newline = '\n'

    counter_32_ = 0
    for x in data_hex:
        #print(x)
        data_hex_with_newline += x
        if(x == ','):
            counter_32_ += 1
        if (counter_32_ == 12):
            counter_32_ = 0
            data_hex_with_newline += '\n'



    binary_file_3 = open("../../../exo_sat_bus_btlr/merge_vfb/merge_vfb_.c", "w")

    binary_file_3.write("// <<< Auto generated file >>>\n\n\n\n")        
    binary_file_3.write("#include \"merge_vfb.h\"\n\n")        
    binary_file_3.write("#ifdef FLASH_VFB_BY_BTLR\n\n")        
    binary_file_3.write(str(varname))
    binary_file_3.write(str(data_hex_with_newline))
    binary_file_3.write(str(endbrace))
    binary_file_3.write("\n\nvoid vfb_merge_init(void)\n{\n")        
    binary_file_3.write("	if(vfb_bin_bytestream[0])\n")        
    binary_file_3.write("	{\n")        
    binary_file_3.write("	}\n")        
    binary_file_3.write("}\n\n#else\n")        
    binary_file_3.write("\nvoid vfb_merge_init(void)\n{\n")        
    binary_file_3.write("}\n\n#endif\n")        

    binary_file_3.close()

    print("FILE: ../../../exo_sat_bus_btlr/merge_vfb/merge_vfb_.c has been updtaed !!!")
    print("### Success!!! Copied exo_sat_bus_ctlr binary to exo_sat_bus_btlr ###\n")




    # Close the file
    f.close()

else:



        
    binary_file_3 = open("../../../exo_sat_bus_btlr/merge_vfb/merge_vfb_.c", "w")

    binary_file_3.write("\n// <<< Auto generated file >>>\n\n")

    binary_file_3.write("#include \"merge_vfb.h\"\n\n")

    binary_file_3.write("#ifdef FLASH_VFB_BY_BTLR\n")        
    binary_file_3.write("\nvoid vfb_merge_init(void)\n{\n")        
    binary_file_3.write("}\n\n#else\n")        
    binary_file_3.write("\nvoid vfb_merge_init(void)\n{\n")        
    binary_file_3.write("}\n\n#endif\n")

    binary_file_3.close()


    print("FILE: ../../../exo_sat_bus_btlr/merge_vfb/merge_vfb_.c has been cleared !!!")
    print("### Success!!! Erased exo_sat_bus_ctlr binary from exo_sat_bus_btlr ###\n")




