working on l452
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import cxxheaderparser.simple
|
||||
|
||||
header_text = open("Core/Inc/packet.hpp","r").read().replace("__inline__", "")
|
||||
|
||||
data = cxxheaderparser.simple.parse_string(header_text)
|
||||
|
||||
work_string = ""
|
||||
|
||||
for class_type in data.namespace.classes:
|
||||
class_name = class_type.class_decl.typename.segments[0].name
|
||||
to_format_string = "%s %d %d"
|
||||
format_args = f'"{class_name}", typecode<{class_name}>(), sizeof({class_name})'
|
||||
for field in class_type.fields:
|
||||
if isinstance(field.type, cxxheaderparser.types.Array):
|
||||
element_type = field.type.array_of.typename.segments[0].name
|
||||
element_num = field.type.size.tokens[0].value
|
||||
element_name = field.name
|
||||
to_format_string += " %s %d %d"
|
||||
format_args += f', "{element_type} {element_name}[{element_num}]", offsetof({class_name}, {element_name}), sizeof({element_type})'
|
||||
elif isinstance(field.type, cxxheaderparser.types.Type):
|
||||
element_type = field.type.typename.segments[0].name
|
||||
element_name = field.name
|
||||
to_format_string += " %s %d %d"
|
||||
format_args += f', "{element_type} {element_name}", offsetof({class_name}, {element_name}), sizeof({element_type})'
|
||||
to_format_string += "\\n\\r"
|
||||
work_string += f' cx = snprintf(buff, sizeof(buff), "{to_format_string}", {format_args});\n'
|
||||
work_string += f' CDC_Transmit_FS((uint8_t*)buff, cx);\n'
|
||||
work_string += f' HAL_Delay(10);\n\n'
|
||||
|
||||
h_file_text = """
|
||||
void data_description();
|
||||
"""
|
||||
|
||||
c_file_text = ("""#include "datadescriptor.hpp"
|
||||
#include <cstddef>
|
||||
#include <cstdio>
|
||||
#include "usbd_cdc_if.h"
|
||||
#include "packet.hpp"
|
||||
|
||||
void data_description() {
|
||||
char buff[200];
|
||||
int cx;
|
||||
|
||||
""" + work_string +
|
||||
"}\n")
|
||||
|
||||
with open("Core/Src/datadescriptor.cpp", "w") as f:
|
||||
f.write(c_file_text)
|
||||
|
||||
with open("Core/Inc/datadescriptor.hpp", "w") as f:
|
||||
f.write(h_file_text)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user