2021-07-08 17:58:16 +02:00
|
|
|
import argparse
|
2021-07-18 13:45:45 +02:00
|
|
|
from os import write
|
2021-07-08 17:58:16 +02:00
|
|
|
|
|
|
|
parser = argparse.ArgumentParser()
|
2021-07-18 13:45:45 +02:00
|
|
|
parser.add_argument("--INPUT_FILES", nargs='+', help="Path vers le fichier d'entrée")
|
|
|
|
parser.add_argument("--HEADER_NAME", help="Path pour le fichier de sortie")
|
|
|
|
parser.add_argument("--VAR_NAMES", nargs='+', help="Nom de la varriable à crée")
|
2021-07-10 20:58:05 +02:00
|
|
|
|
2021-07-08 17:58:16 +02:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
2021-07-18 13:45:45 +02:00
|
|
|
in_files = args.INPUT_FILES
|
|
|
|
var_names = args.VAR_NAMES
|
|
|
|
|
|
|
|
|
2021-07-10 20:58:05 +02:00
|
|
|
output_file = open(args.HEADER_NAME+".h", "w")
|
|
|
|
|
|
|
|
output_file.write("""#ifndef INC_{}_H_
|
|
|
|
#define INC_{}_H_
|
2021-07-08 17:58:16 +02:00
|
|
|
|
2021-07-10 20:58:05 +02:00
|
|
|
#include "stdint.h"
|
2021-07-18 13:45:45 +02:00
|
|
|
""".format(args.HEADER_NAME.upper(), args.HEADER_NAME.upper()))
|
|
|
|
|
|
|
|
for in_file, var_name in zip(in_files, var_names):
|
|
|
|
input_file = open(in_file, "rb")
|
|
|
|
output_file.write("""uint8_t {}[] = """.format(var_name) + """{
|
2021-07-08 17:58:16 +02:00
|
|
|
""")
|
|
|
|
|
2021-07-18 13:45:45 +02:00
|
|
|
bytes_array = []
|
|
|
|
while input_file.peek(1) != b'' :
|
|
|
|
bytes_array.append("0x" + input_file.read(1).hex())
|
2021-07-08 17:58:16 +02:00
|
|
|
|
2021-07-18 13:45:45 +02:00
|
|
|
print("Il y a {} octets dans le fichier".format(len(bytes_array)))
|
2021-07-08 17:58:16 +02:00
|
|
|
|
2021-07-18 13:45:45 +02:00
|
|
|
data = ""
|
|
|
|
for n, repr in enumerate(bytes_array):
|
|
|
|
data += repr +', '
|
|
|
|
if n%8 == 7:
|
|
|
|
data+= "\n"
|
|
|
|
output_file.write(data)
|
|
|
|
output_file.write("""
|
|
|
|
};
|
2021-07-10 20:58:05 +02:00
|
|
|
|
2021-07-18 13:45:45 +02:00
|
|
|
""")
|
|
|
|
input_file.close()
|
|
|
|
|
|
|
|
output_file.write("""
|
2021-07-10 20:58:05 +02:00
|
|
|
#endif /* INC_{}_H_ */
|
|
|
|
""".format(args.HEADER_NAME.upper()))
|
2021-07-08 17:58:16 +02:00
|
|
|
|
|
|
|
output_file.close()
|