added - basic flatUSB_config.h concept added - example JSONs added - CDC request replies fixed
70 lines
2.0 KiB
Python
70 lines
2.0 KiB
Python
import json
|
|
from sys import argv
|
|
|
|
import Descriptor as desc
|
|
|
|
import StructGenerator as sg
|
|
from itertools import chain
|
|
|
|
from ConfigGenerator import ConfigGenerator
|
|
|
|
# print welcome message
|
|
print("----\nflatUSB descriptor generator by Epagris\n----\n")
|
|
|
|
# check number of parameters
|
|
if len(argv) < 3:
|
|
print("Insufficient parameters!\nCorrect usage: `main.py <input json> <target directory>`\nExiting.")
|
|
exit(0)
|
|
|
|
# fetch USB settings
|
|
usb_config_file_name = argv[1]
|
|
usb_target_dir = argv[2]
|
|
|
|
# print input and output parameters
|
|
print("Input JSON: ", usb_config_file_name)
|
|
print("Target directory: ", usb_target_dir)
|
|
|
|
#usb_config_file_name = "/home/epagris/VCSDEV/usbt1/stws/USB-T1/Modules/flatUSB/desc/usb_config_cdc.json"
|
|
with open(usb_config_file_name, 'r') as usb_config_file:
|
|
usb_config_data = usb_config_file.read()
|
|
usb_config = json.loads(usb_config_data)
|
|
|
|
# process "misc"
|
|
if "misc" in usb_config:
|
|
misc = usb_config["misc"]
|
|
|
|
# mutable descriptors
|
|
if "mutable_descriptors" in misc:
|
|
if misc["mutable_descriptors"]:
|
|
desc.Descriptor.QUALIFIERS = ""
|
|
|
|
# generate config
|
|
cfggen = ConfigGenerator(usb_config)
|
|
cfggen.generate(usb_target_dir)
|
|
|
|
# devDesc = desc.DeviceDescriptor(usb_config)
|
|
# print(devDesc.print_assigment())
|
|
#
|
|
# strDesc = desc.StringDescriptor("Testdevice", "StrDevice")
|
|
# print(strDesc.print_assigment())
|
|
|
|
#intrec = sg.RecordFactory.create("num", "u32", 127)
|
|
#print(intrec.print_typedef("INT"))
|
|
# intrec = sg.RecordFactory.create([ "num", "u32", 127, ])
|
|
# print(intrec.print_typedef("INTINT"))
|
|
# #
|
|
# strrec = sg.RecordFactory.create("some_string", "str", "Some string")
|
|
# print(strrec.print_typedef("STR"))
|
|
#print(strrec.print_content())
|
|
#
|
|
# recs = [ intrec, strrec ]
|
|
#
|
|
# struct1 = sg.StructRecord("struct1", "struct struct 1", recs)
|
|
# struct2 = sg.StructRecord("struct2", "struct struct2", recs)
|
|
# print(struct2.print_typedef("struct2"))
|
|
#
|
|
# structrec = sg.StructRecord("object", "struct compound", [ struct1, struct2, *recs ])
|
|
# print(structrec.print_content())
|
|
|
|
# print complete message
|
|
print("Descriptor generation complete!") |