diff --git a/scripts/eventgen/EventFunctions.cpp.template b/scripts/eventgen/EventStrings.cpp.template similarity index 99% rename from scripts/eventgen/EventFunctions.cpp.template rename to scripts/eventgen/EventStrings.cpp.template index 1611abafb11180cdadeafae5294f45acc4f85f78..ac394d77ae88f40eaf621b4122d3552610f7ac0a 100644 --- a/scripts/eventgen/EventFunctions.cpp.template +++ b/scripts/eventgen/EventStrings.cpp.template @@ -33,6 +33,7 @@ #include "Topics.h" #include <map> +using std::map; string getEventString(uint8_t event) {{ diff --git a/scripts/eventgen/Events.h.template b/scripts/eventgen/Events.h.template index bd9cc25367ec63690cfc588a877778f110f09791..6ba4c21b2157b67e17b18d7ddfcfdcd818cc7225 100644 --- a/scripts/eventgen/Events.h.template +++ b/scripts/eventgen/Events.h.template @@ -32,22 +32,25 @@ #include <cstdint> #include <string> +#include <vector> #include "events/Event.h" #include "events/EventBroker.h" -#include "EventClasses.h" #include "Topics.h" using std::string; -using std::map; /** - * Definition of all events signals. + * Definition of all events in the Homeone Board software + * Refer to section 5.1.1 of the Software Design Document. + */ enum Events : uint8_t {{ {enum_data} }}; +const std::vector<uint8_t> EVENT_LIST {{{event_list}}}; + /** * @brief Returns the name of the provided event * diff --git a/scripts/eventgen/README.md b/scripts/eventgen/README.md index 7bfb1c9b0625ffdfc86794475246b92e6251e586..30ad5fed22324008c5ecd2002357b73c3d818505 100644 --- a/scripts/eventgen/README.md +++ b/scripts/eventgen/README.md @@ -1,6 +1,6 @@ # Events Generator Script -This script generates Events.h, Topics.h and EventFunctions.cpp from a list of +This script generates Events.h, Topics.h and EventStrings.cpp from a list of SCXML files representing the state machines of a project. To execute the script: diff --git a/scripts/eventgen/Topics.h.template b/scripts/eventgen/Topics.h.template index 2ce2c2c536a6ba099b7c72ab2df987ccf9449fd3..ca3f1288407f927b6cc462f22cf4ec1c7bb443fd 100644 --- a/scripts/eventgen/Topics.h.template +++ b/scripts/eventgen/Topics.h.template @@ -32,8 +32,8 @@ #include <stdint.h> #include <string> +#include <vector> -using std::map; using std::string; /** @@ -44,11 +44,12 @@ enum Topics : uint8_t {enum_data} }}; +const std::vector<uint8_t> TOPIC_LIST {{{topic_list}}}; + /** * @brief Returns the name of the provided event * * @param event * @return string */ -string getTopicString(uint8_t topic); - +string getTopicString(uint8_t topic); \ No newline at end of file diff --git a/scripts/eventgen/eventgen.py b/scripts/eventgen/eventgen.py index 9c36223a3266a22a65961776074efcfc0bd14656..7d772986fcd552cfaa99e4da4deba95feb38d7ee 100755 --- a/scripts/eventgen/eventgen.py +++ b/scripts/eventgen/eventgen.py @@ -94,6 +94,7 @@ def parse_scxml(files): def generate_events(events, date): enum_str = "" event_map_str = "" + event_list_str = "" # generate string for e in events: @@ -102,14 +103,14 @@ def generate_events(events, date): (" = EV_FIRST_SIGNAL" if e == events[0] else "") + endl event_map_str += " {{ {event}, {string} }}{endl}".format( event=e, string='"' + e + '"', endl=endl) + event_list_str += e + (", " if e != events[-1] else "") # read template with open('Events.h.template', 'r') as template_file: template = template_file.read() # write template - template = template.format(date=date, enum_data=enum_str) - + template = template.format(date=date, enum_data=enum_str, event_list=event_list_str) with open(join(OUTPUT_FOLDER, 'Events.h'), 'w') as header_file: header_file.write(template) @@ -121,17 +122,19 @@ def generate_events(events, date): def generate_topics(topics, date): enum_str = "" topic_map_str = "" + topic_list_str = "" for t in topics: endl = ",\n" if t != topics[-1] else "" enum_str += " " + t + endl topic_map_str += " {{ {topics}, {string} }}{endl}".format( topics=t, string='"' + t + '"', endl=endl) + topic_list_str += t + (", " if t != topics[-1] else "") with open('Topics.h.template', 'r') as template_file: template = template_file.read() - template = template.format(date=date, enum_data=enum_str) + template = template.format(date=date, enum_data=enum_str, topic_list=topic_list_str) with open(join(OUTPUT_FOLDER, 'Topics.h'), 'w') as header_file: header_file.write(template) @@ -142,12 +145,12 @@ def generate_topics(topics, date): # Generate EventFunctions.cpp # def generate_functions(event_map_str, topic_map_str, date): - with open('EventFunctions.cpp.template', 'r') as cpp_template_file: + with open('EventStrings.cpp.template', 'r') as cpp_template_file: cpp = cpp_template_file.read() cpp = cpp.format(date=date, event_map_data=event_map_str, topic_map_data=topic_map_str) - with open(join(OUTPUT_FOLDER, 'EventFunctions.cpp'), 'w') as cpp_file: + with open(join(OUTPUT_FOLDER, 'EventStrings.cpp'), 'w') as cpp_file: cpp_file.write(cpp) #