From e16f97f82fc9bceb6bb58549e1f8bbe92225f546 Mon Sep 17 00:00:00 2001 From: Michal Reiser Date: Tue, 6 Aug 2024 16:29:20 +0200 Subject: [PATCH 01/16] added enumeration for topics in the file --- umsg_gen/umsg_gen/templates/msg.h.j2 | 11 +++++++++++ umsg_gen/umsg_gen/templates/msg_enum.h.j2 | 0 umsg_lib/CMakeLists.txt | 6 +++--- umsg_lib/inc/umsg_battery.h | 11 ++++++++++- umsg_lib/inc/umsg_control.h | 11 ++++++++++- umsg_lib/inc/umsg_example.h | 12 +++++++++++- umsg_lib/inc/umsg_sensors.h | 12 +++++++++++- umsg_lib/inc/umsg_test.h | 17 ++++++++++++++++- umsg_lib/inc/umsg_unused.h | 12 +++++++++++- umsg_lib/src/battery.c | 2 +- umsg_lib/src/control.c | 2 +- umsg_lib/src/example.c | 2 +- umsg_lib/src/sensors.c | 2 +- umsg_lib/src/test.c | 2 +- umsg_lib/src/unused.c | 2 +- 15 files changed, 89 insertions(+), 15 deletions(-) create mode 100644 umsg_gen/umsg_gen/templates/msg_enum.h.j2 diff --git a/umsg_gen/umsg_gen/templates/msg.h.j2 b/umsg_gen/umsg_gen/templates/msg.h.j2 index 30e09ff..56ec3fd 100644 --- a/umsg_gen/umsg_gen/templates/msg.h.j2 +++ b/umsg_gen/umsg_gen/templates/msg.h.j2 @@ -49,6 +49,17 @@ typedef enum {%endfor%} {% endif %} + +//enumeration of topics +typedef enum +{ +{% for msg_dict in topic_dict.msgs %} + {{topic_dict.name.upper()}}_{{msg_dict.name.upper()}}{{', ' if not loop.last else ''}} +{% endfor -%} +} umsg_enum_{{topic_dict.name}}_t; + + + {% for msg_dict in topic_dict.msgs %} typedef struct { diff --git a/umsg_gen/umsg_gen/templates/msg_enum.h.j2 b/umsg_gen/umsg_gen/templates/msg_enum.h.j2 new file mode 100644 index 0000000..e69de29 diff --git a/umsg_lib/CMakeLists.txt b/umsg_lib/CMakeLists.txt index 590c420..ee95138 100644 --- a/umsg_lib/CMakeLists.txt +++ b/umsg_lib/CMakeLists.txt @@ -4,10 +4,10 @@ add_library(uMsgLib STATIC # generated files src/battery.c src/control.c - src/example.c - src/sensors.c - src/test.c src/unused.c + src/test.c + src/sensors.c + src/example.c ) # select port if(NOT DEFINED UMSG_PORT) diff --git a/umsg_lib/inc/umsg_battery.h b/umsg_lib/inc/umsg_battery.h index ebafa11..cfa6bbb 100644 --- a/umsg_lib/inc/umsg_battery.h +++ b/umsg_lib/inc/umsg_battery.h @@ -1,4 +1,4 @@ -// Generated with umsg_gen on 2024-08-05 +// Generated with umsg_gen on 2024-08-06 #pragma once #ifdef __cplusplus @@ -16,6 +16,15 @@ typedef enum BATTERY_DEAD } umsg_battery_battery_state_t; + +//enumeration of topics +typedef enum +{ + BATTERY_STATE +} umsg_enum_battery_t; + + + typedef struct { umsg_battery_battery_state_t state; diff --git a/umsg_lib/inc/umsg_control.h b/umsg_lib/inc/umsg_control.h index 316025f..36144fb 100644 --- a/umsg_lib/inc/umsg_control.h +++ b/umsg_lib/inc/umsg_control.h @@ -1,4 +1,4 @@ -// Generated with umsg_gen on 2024-08-05 +// Generated with umsg_gen on 2024-08-06 #pragma once #ifdef __cplusplus @@ -8,6 +8,15 @@ extern "C" { #include // msg structure typedefs + +//enumeration of topics +typedef enum +{ + CONTROL_SETPOINTS +} umsg_enum_control_t; + + + typedef struct { float w[3]; diff --git a/umsg_lib/inc/umsg_example.h b/umsg_lib/inc/umsg_example.h index 14a919c..5c858af 100644 --- a/umsg_lib/inc/umsg_example.h +++ b/umsg_lib/inc/umsg_example.h @@ -1,4 +1,4 @@ -// Generated with umsg_gen on 2024-08-05 +// Generated with umsg_gen on 2024-08-06 #pragma once #ifdef __cplusplus @@ -16,6 +16,16 @@ typedef enum READ } umsg_example_colors_t; + +//enumeration of topics +typedef enum +{ + EXAMPLE_COLOR_SELECTION, + EXAMPLE_SIMPLE_MSG +} umsg_enum_example_t; + + + typedef struct { umsg_example_colors_t chosen_color; diff --git a/umsg_lib/inc/umsg_sensors.h b/umsg_lib/inc/umsg_sensors.h index 069f0ad..941f091 100644 --- a/umsg_lib/inc/umsg_sensors.h +++ b/umsg_lib/inc/umsg_sensors.h @@ -1,4 +1,4 @@ -// Generated with umsg_gen on 2024-08-05 +// Generated with umsg_gen on 2024-08-06 #pragma once #ifdef __cplusplus @@ -8,6 +8,16 @@ extern "C" { #include // msg structure typedefs + +//enumeration of topics +typedef enum +{ + SENSORS_IMU, + SENSORS_BARO +} umsg_enum_sensors_t; + + + typedef struct { float gyro[3]; diff --git a/umsg_lib/inc/umsg_test.h b/umsg_lib/inc/umsg_test.h index 2351e41..2544b7d 100644 --- a/umsg_lib/inc/umsg_test.h +++ b/umsg_lib/inc/umsg_test.h @@ -1,4 +1,4 @@ -// Generated with umsg_gen on 2024-08-05 +// Generated with umsg_gen on 2024-08-06 #pragma once #ifdef __cplusplus @@ -16,6 +16,21 @@ typedef enum ENUM_C } umsg_test_enum_test_t; + +//enumeration of topics +typedef enum +{ + TEST_FLOATS, + TEST_UINTS, + TEST_INTS, + TEST_STRINGS, + TEST_BOOLS, + TEST_ENUMS, + TEST_BITFIELD +} umsg_enum_test_t; + + + typedef struct { float single; diff --git a/umsg_lib/inc/umsg_unused.h b/umsg_lib/inc/umsg_unused.h index a50276d..d137907 100644 --- a/umsg_lib/inc/umsg_unused.h +++ b/umsg_lib/inc/umsg_unused.h @@ -1,4 +1,4 @@ -// Generated with umsg_gen on 2024-08-05 +// Generated with umsg_gen on 2024-08-06 #pragma once #ifdef __cplusplus @@ -8,6 +8,16 @@ extern "C" { #include // msg structure typedefs + +//enumeration of topics +typedef enum +{ + UNUSED_USED_VAR, + UNUSED_UNUSED_VAR +} umsg_enum_unused_t; + + + typedef struct { uint8_t a; diff --git a/umsg_lib/src/battery.c b/umsg_lib/src/battery.c index a24fd83..b4491a9 100644 --- a/umsg_lib/src/battery.c +++ b/umsg_lib/src/battery.c @@ -1,4 +1,4 @@ -// Generated with umsg_gen on 2024-08-05 +// Generated with umsg_gen on 2024-08-06 #include #include diff --git a/umsg_lib/src/control.c b/umsg_lib/src/control.c index ba562a0..b9eda83 100644 --- a/umsg_lib/src/control.c +++ b/umsg_lib/src/control.c @@ -1,4 +1,4 @@ -// Generated with umsg_gen on 2024-08-05 +// Generated with umsg_gen on 2024-08-06 #include #include diff --git a/umsg_lib/src/example.c b/umsg_lib/src/example.c index 186fcc5..5687afa 100644 --- a/umsg_lib/src/example.c +++ b/umsg_lib/src/example.c @@ -1,4 +1,4 @@ -// Generated with umsg_gen on 2024-08-05 +// Generated with umsg_gen on 2024-08-06 #include #include diff --git a/umsg_lib/src/sensors.c b/umsg_lib/src/sensors.c index 352d42d..25e8a4c 100644 --- a/umsg_lib/src/sensors.c +++ b/umsg_lib/src/sensors.c @@ -1,4 +1,4 @@ -// Generated with umsg_gen on 2024-08-05 +// Generated with umsg_gen on 2024-08-06 #include #include diff --git a/umsg_lib/src/test.c b/umsg_lib/src/test.c index f184098..ed5fa37 100644 --- a/umsg_lib/src/test.c +++ b/umsg_lib/src/test.c @@ -1,4 +1,4 @@ -// Generated with umsg_gen on 2024-08-05 +// Generated with umsg_gen on 2024-08-06 #include #include diff --git a/umsg_lib/src/unused.c b/umsg_lib/src/unused.c index e87fbc8..03ea303 100644 --- a/umsg_lib/src/unused.c +++ b/umsg_lib/src/unused.c @@ -1,4 +1,4 @@ -// Generated with umsg_gen on 2024-08-05 +// Generated with umsg_gen on 2024-08-06 #include #include From e4236a5b15433825c5e74fea627f979409661657 Mon Sep 17 00:00:00 2001 From: Michal Reiser Date: Wed, 7 Aug 2024 10:00:30 +0200 Subject: [PATCH 02/16] added class enum --- umsg_gen/umsg_gen/templates/msg_classes.h.j2 | 27 ++++++++++++++++++ umsg_gen/umsg_gen/templates/msg_enum.h.j2 | 0 umsg_gen/umsg_gen/umsg_gen.py | 12 ++++++-- umsg_lib/msg_classes.h | 30 ++++++++++++++++++++ 4 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 umsg_gen/umsg_gen/templates/msg_classes.h.j2 delete mode 100644 umsg_gen/umsg_gen/templates/msg_enum.h.j2 create mode 100644 umsg_lib/msg_classes.h diff --git a/umsg_gen/umsg_gen/templates/msg_classes.h.j2 b/umsg_gen/umsg_gen/templates/msg_classes.h.j2 new file mode 100644 index 0000000..49f4abb --- /dev/null +++ b/umsg_gen/umsg_gen/templates/msg_classes.h.j2 @@ -0,0 +1,27 @@ +// Generated with umsg_gen on {{ date }} +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +{%for head in headers%} +#include <{{head}}.h> +{% endfor -%} + + +typedef enum +{ +{% for val in headers%} +{{val.upper()}}{{ "," if not loop.last else "" }} +{%endfor%} +} umsg_classes_t; + +#ifdef __cplusplus +} +#endif + + + diff --git a/umsg_gen/umsg_gen/templates/msg_enum.h.j2 b/umsg_gen/umsg_gen/templates/msg_enum.h.j2 deleted file mode 100644 index e69de29..0000000 diff --git a/umsg_gen/umsg_gen/umsg_gen.py b/umsg_gen/umsg_gen/umsg_gen.py index 3589eae..0cfbe9b 100644 --- a/umsg_gen/umsg_gen/umsg_gen.py +++ b/umsg_gen/umsg_gen/umsg_gen.py @@ -22,6 +22,8 @@ def main(): env = Environment(loader=FileSystemLoader(templates_path)) env.trim_blocks = True env.lstrip_blocks = True + + msg_class_inc_template = env.get_template(name='msg_classes.h.j2') inc_template = env.get_template(name='msg.h.j2') src_template = env.get_template(name='msg.c.j2') cmake_template = env.get_template(name='CMakeLists.txt.j2') @@ -33,18 +35,18 @@ def main(): if not files: print('No files found') exit(1) - + print(files) # generate source and header files for each topic json file # delete output directory if it exists if output_path.exists(): shutil.rmtree(output_path) sources = [] + headers = [] for file in files: # load topic json file f = open(file) topic_dict = json.load(f) - # add name field to topic dict topic_dict['name'] = Path(file).stem @@ -64,6 +66,12 @@ def main(): # add file name to list sources.append(Path(filename).name) + headers.append(f'umsg_{topic_dict["name"]}') + # Generate the msg_classes header file + content = msg_class_inc_template.render(headers=headers, date=datetime.date.today()) + filename = f'{output_path}/inc/msg_classes.h' + with open(filename, mode="w", encoding="utf-8") as message: + message.write(content) # Gereate cmake file content = cmake_template.render(sources=sources, date=datetime.date.today()) diff --git a/umsg_lib/msg_classes.h b/umsg_lib/msg_classes.h new file mode 100644 index 0000000..969d88c --- /dev/null +++ b/umsg_lib/msg_classes.h @@ -0,0 +1,30 @@ +// Generated with umsg_gen on 2024-08-06 +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#include +#include +#include +#include +#include +#include +typedef enum +{ +UMSG_BATTERY, +UMSG_CONTROL, +UMSG_UNUSED, +UMSG_TEST, +UMSG_SENSORS, +UMSG_EXAMPLE +} umsg_classes_t; + +#ifdef __cplusplus +} +#endif + + From ddba6b84b1956ba5e44291a80c568a67699b2217 Mon Sep 17 00:00:00 2001 From: Michal Reiser Date: Wed, 7 Aug 2024 17:27:17 +0200 Subject: [PATCH 03/16] added ability to binary log messages and added a logfile parser template --- README.md | 25 +- .../templates/CMakeLists_log_parser.txt.j2 | 27 ++ umsg_gen/umsg_gen/templates/log_parser.cpp.j2 | 192 +++++++++++++ umsg_gen/umsg_gen/templates/msg.c.j2 | 38 ++- umsg_gen/umsg_gen/templates/msg.h.j2 | 12 + umsg_gen/umsg_gen/templates/msg_classes.h.j2 | 5 - umsg_gen/umsg_gen/umsg_gen.py | 38 ++- umsg_lib/inc/umsg_battery.h | 11 +- .../{msg_classes.h => inc/umsg_classes.h} | 8 +- umsg_lib/inc/umsg_control.h | 11 +- umsg_lib/inc/umsg_example.h | 17 +- umsg_lib/inc/umsg_sensors.h | 17 +- umsg_lib/inc/umsg_test.h | 47 +++- umsg_lib/inc/umsg_unused.h | 17 +- umsg_lib/src/battery.c | 38 ++- umsg_lib/src/control.c | 38 ++- umsg_lib/src/example.c | 74 ++++- umsg_lib/src/sensors.c | 75 +++++- umsg_lib/src/test.c | 254 +++++++++++++++++- umsg_lib/src/unused.c | 74 ++++- 20 files changed, 987 insertions(+), 31 deletions(-) create mode 100644 umsg_gen/umsg_gen/templates/CMakeLists_log_parser.txt.j2 create mode 100644 umsg_gen/umsg_gen/templates/log_parser.cpp.j2 rename umsg_lib/{msg_classes.h => inc/umsg_classes.h} (53%) diff --git a/README.md b/README.md index 634dcc3..47c43b8 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ Prepare your topic .json file (see [topic definition]#Defining-messages) with yo Run: ``` -umsg-gen -d '\messages' -o '\umsg_lib' +umsg-gen -d '\messages' -o '\umsg_lib' -l ``` ## Add to CMake Project @@ -237,6 +237,29 @@ typedef struct { All of the topic.json files should be grouped in a single directory. which are then passed to the umsg-gen generator. +# Logging support +The library has a logging support that can be enabled by -l, if you use this, you will get two new types of functions: + +```c +uint32_t umsg_sensors_imu_serialize(umsg_sensors_imu_t* data, uint8_t* buffer); +``` +This function will put the message into a buffer and will tell you how many bytes from the buffer were used, so you can log in onto an SD card or some other storage system. +The message will be stored as (message class enum, message type enum, message). eg. (UMSG_SENSORS, SENSORS_IMU, struct umsg_sensors_imu_t). The endianity if dependent on the processor for now. + +```c +uint8_t umsg_sensors_imu_deserialize(umsg_sensors_imu_t* data,uint8_t* buffer); +``` +This function will put the message from a buffer back into struct and it will check if the message class and message type are correct for this type of message, it will also be indicated by the return value of the function. + +For now, it is assumed that there are no more than 256 message classes and no more than 256 types of message in a class, this constaint will be fixed in the future. + +This option also generated log_parser folder that contains cpp code and CMakeLists that when compiled is able to read the stored messages and write them to .csv files, the structure of the generated files is given as: + +``` +logfilename/message_class/message_type.csv; +``` + + # uMsg-Graph (Work in Progress) diff --git a/umsg_gen/umsg_gen/templates/CMakeLists_log_parser.txt.j2 b/umsg_gen/umsg_gen/templates/CMakeLists_log_parser.txt.j2 new file mode 100644 index 0000000..1538369 --- /dev/null +++ b/umsg_gen/umsg_gen/templates/CMakeLists_log_parser.txt.j2 @@ -0,0 +1,27 @@ +cmake_minimum_required(VERSION 3.13) + + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +project(log_decompiler CXX C) + +set(UMSG_PORT "POSIX") + +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/umsg_lib) + + +target_link_libraries(uMsgLib +) + +add_executable(log_parser +log_parser.cpp +) + + + +target_link_libraries(log_parser +uMsgLib +) + diff --git a/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 b/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 new file mode 100644 index 0000000..b60b40f --- /dev/null +++ b/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 @@ -0,0 +1,192 @@ +// Generated with umsg_gen on {{ date }} + +#include +#include +#include +#include +#include +#include + + +#include"umsg_classes.h" + +{% for val in topic_dict_list%} +#include +{%endfor%} + + + + +//globally defined streams for topic files + +{% for dict in topic_dict_list%} +{% for msg_dict in dict.msgs%} +std::ofstream file_{{dict.name}}_{{msg_dict.name}}; +{%endfor%} +{%endfor%} + + + + + +{% for dict in topic_dict_list%} +void sort_{{dict.name}}_type(std::ifstream &file) +{ + uint8_t msg_type; + file.read((char *)&msg_type, 1); + if (!file) { + std::cerr << std::endl << "Error reading file" << std::endl; + exit(2); + } + + switch(msg_type) + { +{% for msg_dict in dict.msgs%} + case {{dict.name.upper()}}_{{msg_dict.name.upper()}}: + { + char buffer[sizeof(umsg_{{dict.name}}_{{msg_dict.name}}_t)]; + file.read(buffer,sizeof(umsg_{{dict.name}}_{{msg_dict.name}}_t)); + umsg_{{dict.name}}_{{msg_dict.name}}_t* message = reinterpret_cast (buffer); + + {% for field in msg_dict.fields %} + {% if not field.bitfield %} + {% if field.length %} + for(uint32_t i=0;i<{{field.length}}; i++){ file_{{dict.name}}_{{msg_dict.name}} << message->{{field.name}}[i] << ", " ;} + {% endif %} + {% if not field.length %} + file_{{dict.name}}_{{msg_dict.name}} << message->{{field.name}}{% if not loop.last%} << ", "{% endif %}; + {% endif %} + {% endif %} + {% if field.bitfield %} + {%for bitfield in field.bitfield %} + file_{{dict.name}}_{{msg_dict.name}} << message->{{bitfield.name}}{% if not loop.last%} << ", "{% endif %}; + {%endfor%} + {% endif %} + {% endfor %} + + file_{{dict.name}}_{{msg_dict.name}} << std::endl; + } + break; +{%endfor%} + default: + std::cerr << std::endl << "ERROR UNKNOWN MESSAGE TYPE: " << static_cast(msg_type) << std::endl; + exit(1); + break; + } +} +{%endfor%} + + +void sort_msg(std::ifstream &file) +{ + if (!file.is_open()) { + std::cerr << std::endl << "Error opening logfile" << std::endl; + return; + } + + uint8_t msg_class; + file.read((char *)&msg_class, 1); + if (!file) { + std::cerr << std::endl << "Error reading file" << std::endl; + return; + } + + switch(msg_class) + { +{% for dict in topic_dict_list%} + case UMSG_{{dict.name.upper()}}: + { + sort_{{dict.name}}_type(file); + } + break; +{%endfor%} + + default: + { + std::cerr << std::endl << "ERROR UNKNOWN MESSAGE CLASS: " << static_cast(msg_class) << std::endl; + exit(1); + } + break; + } +} + + + + +std::string split_by_last_dot(const std::string &str) { + size_t last_dot_pos = str.find_last_of('.'); + if (last_dot_pos == std::string::npos) { + return str; // No dot found, return the whole string + } + return str.substr(0, last_dot_pos); +} + + +int main(int argc, char *argv[]) { + if (argc != 2) { + std::cerr << std::endl << "Usage: " << argv[0] << " " << std::endl; + return 1; + } + + //proceed to open the file + const std::string file_path = argv[1]; + std::ifstream file(file_path,std::ios::binary); + if(!file || !file.is_open()) + { + std::cerr << std::endl << "Could not open the logfile, aborting" << std::endl; + return 2; + } + std::cout << "file size is: " << std::filesystem::file_size(file_path) << " bytes" << std::endl; + + //create directories based on the log name and open the files for all of the possible log messages + + std::string logname = split_by_last_dot(file_path); + std::filesystem::create_directory(logname); + // here we will generate the subdirectories and open files for the messages + std::string fpath; + std::string dirpath; +{% for dict in topic_dict_list%} + dirpath= logname + "/" + "{{dict.name}}"; + std::filesystem::create_directory(dirpath); +{% for msg_dict in dict.msgs%} + fpath = logname + "/{{dict.name}}/{{msg_dict.name}}.csv"; + file_{{dict.name}}_{{msg_dict.name}} = std::ofstream(fpath); + {% for field in msg_dict.fields %} + {% if not field.bitfield %} + {% if field.length %} + for(uint32_t i=0;i<{{field.length}}; i++){ file_{{dict.name}}_{{msg_dict.name}} <<"{{field.name}}" << i << ", ";} + {% endif %} + {% if not field.length %} + file_{{dict.name}}_{{msg_dict.name}} << "{{field.name}}"{% if not loop.last%} << ", "{% endif %}; + {% endif %} + {% endif %} + {% if field.bitfield %} + {%for bitfield in field.bitfield %} + file_{{dict.name}}_{{msg_dict.name}} << "{{bitfield.name}}"{% if not loop.last%} << ", "{% endif %}; + {%endfor%} + {% endif %} + {% endfor %} + + file_{{dict.name}}_{{msg_dict.name}} << std::endl; +{%endfor%} +{%endfor%} + while(file.tellg()!= std::filesystem::file_size(file_path)) + { + std::cout << "cursor at: " << file.tellg() << " from " << std::filesystem::file_size(file_path) << "\r"; + sort_msg(file); + } + + // close all the files +{% for dict in topic_dict_list%} +{% for msg_dict in dict.msgs%} + file_{{dict.name}}_{{msg_dict.name}}.close(); +{%endfor%} +{%endfor%} + + + //close the logfile + file.close(); + std::cout < +#include "umsg_classes.h" // msg structure typedefs {%if topic_dict.enums %} @@ -81,8 +82,19 @@ void umsg_{{prefix}}_publish_ch(umsg_{{prefix}}_t* data, uint8_t channel); uint8_t umsg_{{prefix}}_receive(umsg_sub_handle_t queue, umsg_{{prefix}}_t* data, uint32_t timeout); uint8_t umsg_{{prefix}}_peek(umsg_{{prefix}}_t* data); + +{%if log == "do_log"%} +//function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class and type +//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +//please take care that the messages are build properly to avoid padding issues if the messages are opened on different system +uint32_t umsg_{{prefix}}_serialize(umsg_{{prefix}}_t* data, uint8_t* buffer); +uint8_t umsg_{{prefix}}_deserialize(umsg_{{prefix}}_t* data,uint8_t* buffer); // this function includes check that the message type is correct +{% endif %} + {% endfor %} + + #ifdef __cplusplus } #endif diff --git a/umsg_gen/umsg_gen/templates/msg_classes.h.j2 b/umsg_gen/umsg_gen/templates/msg_classes.h.j2 index 49f4abb..315bbb1 100644 --- a/umsg_gen/umsg_gen/templates/msg_classes.h.j2 +++ b/umsg_gen/umsg_gen/templates/msg_classes.h.j2 @@ -7,11 +7,6 @@ extern "C" { #include -{%for head in headers%} -#include <{{head}}.h> -{% endfor -%} - - typedef enum { {% for val in headers%} diff --git a/umsg_gen/umsg_gen/umsg_gen.py b/umsg_gen/umsg_gen/umsg_gen.py index 0cfbe9b..da8b154 100644 --- a/umsg_gen/umsg_gen/umsg_gen.py +++ b/umsg_gen/umsg_gen/umsg_gen.py @@ -10,13 +10,20 @@ def main(): parser = argparse.ArgumentParser() parser.add_argument('-d', dest='msgs_directory', required=True) parser.add_argument('-o', dest='output_directory', required=True) + parser.add_argument('-l', '--logging', action='store_true') args = parser.parse_args() - # create full paths msg_def_path = Path().resolve() / args.msgs_directory output_path = Path().resolve() / args.output_directory + logger_output_path = Path().resolve() / args.output_directory / 'log_parser' templates_path = Path(__file__).resolve().parent / 'templates' core_path = Path(__file__).resolve().parent / 'core' + + if args.logging ==True: + log = "do_log" + else: + log = "no_log" + # setup jinja2 environment & templates env = Environment(loader=FileSystemLoader(templates_path)) @@ -24,6 +31,8 @@ def main(): env.lstrip_blocks = True msg_class_inc_template = env.get_template(name='msg_classes.h.j2') + log_parser_template = env.get_template(name='log_parser.cpp.j2') + cmake_log_parser_template = env.get_template(name='CMakeLists_log_parser.txt.j2') inc_template = env.get_template(name='msg.h.j2') src_template = env.get_template(name='msg.c.j2') cmake_template = env.get_template(name='CMakeLists.txt.j2') @@ -35,7 +44,6 @@ def main(): if not files: print('No files found') exit(1) - print(files) # generate source and header files for each topic json file # delete output directory if it exists @@ -43,36 +51,56 @@ def main(): shutil.rmtree(output_path) sources = [] headers = [] + topic_dict_list = [] for file in files: # load topic json file f = open(file) topic_dict = json.load(f) + topic_dict_list.append(topic_dict) # add name field to topic dict topic_dict['name'] = Path(file).stem # generate header filename = f'{output_path}/inc/umsg_{topic_dict["name"]}.h' Path(filename).parent.mkdir(parents=True, exist_ok=True) - content = inc_template.render(topic_dict=topic_dict,date=datetime.date.today()) + content = inc_template.render(topic_dict=topic_dict,date=datetime.date.today(),log=log) with open(filename, mode="w", encoding="utf-8") as message: message.write(content) #generate source filename = f'{output_path}/src/{topic_dict["name"]}.c' Path(filename).parent.mkdir(parents=True, exist_ok=True) - content = src_template.render(topic_dict=topic_dict, date=datetime.date.today()) + content = src_template.render(topic_dict=topic_dict, date=datetime.date.today(),log=log) with open(filename, mode="w", encoding="utf-8") as message: message.write(content) # add file name to list sources.append(Path(filename).name) headers.append(f'umsg_{topic_dict["name"]}') + + # Generate the msg_classes header file content = msg_class_inc_template.render(headers=headers, date=datetime.date.today()) - filename = f'{output_path}/inc/msg_classes.h' + filename = f'{output_path}/inc/umsg_classes.h' with open(filename, mode="w", encoding="utf-8") as message: message.write(content) + if log == "do_log": + #Generate the logfile parser + filename = f'{output_path}/log_parser/log_parser.cpp' + Path(filename).parent.mkdir(parents=True, exist_ok=True) + content = log_parser_template.render(topic_dict_list=topic_dict_list, date=datetime.date.today()) + with open(filename, mode="w", encoding="utf-8") as message: + message.write(content) + #Generate the Cmake for the logfile parser + filename = f'{output_path}/log_parser/CMakeLists.txt' + Path(filename).parent.mkdir(parents=True, exist_ok=True) + content = cmake_log_parser_template.render(topic_dict_list=topic_dict_list, date=datetime.date.today()) + with open(filename, mode="w", encoding="utf-8") as message: + message.write(content) + + + # Gereate cmake file content = cmake_template.render(sources=sources, date=datetime.date.today()) filename = f'{output_path}/CMakeLists.txt' diff --git a/umsg_lib/inc/umsg_battery.h b/umsg_lib/inc/umsg_battery.h index cfa6bbb..746c636 100644 --- a/umsg_lib/inc/umsg_battery.h +++ b/umsg_lib/inc/umsg_battery.h @@ -1,4 +1,4 @@ -// Generated with umsg_gen on 2024-08-06 +// Generated with umsg_gen on 2024-08-07 #pragma once #ifdef __cplusplus @@ -7,6 +7,7 @@ extern "C" { #include +#include "umsg_classes.h" // msg structure typedefs typedef enum @@ -39,6 +40,14 @@ void umsg_battery_state_publish_ch(umsg_battery_state_t* data, uint8_t channel); uint8_t umsg_battery_state_receive(umsg_sub_handle_t queue, umsg_battery_state_t* data, uint32_t timeout); uint8_t umsg_battery_state_peek(umsg_battery_state_t* data); +//function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class and type +//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +//please take care that the messages are build properly to avoid padding issues if the messages are opened on different system +uint32_t umsg_battery_state_serialize(umsg_battery_state_t* data, uint8_t* buffer); +uint8_t umsg_battery_state_deserialize(umsg_battery_state_t* data,uint8_t* buffer); // this function includes check that the message type is correct + + + #ifdef __cplusplus } diff --git a/umsg_lib/msg_classes.h b/umsg_lib/inc/umsg_classes.h similarity index 53% rename from umsg_lib/msg_classes.h rename to umsg_lib/inc/umsg_classes.h index 969d88c..6ccc875 100644 --- a/umsg_lib/msg_classes.h +++ b/umsg_lib/inc/umsg_classes.h @@ -1,4 +1,4 @@ -// Generated with umsg_gen on 2024-08-06 +// Generated with umsg_gen on 2024-08-07 #pragma once #ifdef __cplusplus @@ -7,12 +7,6 @@ extern "C" { #include -#include -#include -#include -#include -#include -#include typedef enum { UMSG_BATTERY, diff --git a/umsg_lib/inc/umsg_control.h b/umsg_lib/inc/umsg_control.h index 36144fb..fa15838 100644 --- a/umsg_lib/inc/umsg_control.h +++ b/umsg_lib/inc/umsg_control.h @@ -1,4 +1,4 @@ -// Generated with umsg_gen on 2024-08-06 +// Generated with umsg_gen on 2024-08-07 #pragma once #ifdef __cplusplus @@ -7,6 +7,7 @@ extern "C" { #include +#include "umsg_classes.h" // msg structure typedefs //enumeration of topics @@ -32,6 +33,14 @@ void umsg_control_setpoints_publish_ch(umsg_control_setpoints_t* data, uint8_t c uint8_t umsg_control_setpoints_receive(umsg_sub_handle_t queue, umsg_control_setpoints_t* data, uint32_t timeout); uint8_t umsg_control_setpoints_peek(umsg_control_setpoints_t* data); +//function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class and type +//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +//please take care that the messages are build properly to avoid padding issues if the messages are opened on different system +uint32_t umsg_control_setpoints_serialize(umsg_control_setpoints_t* data, uint8_t* buffer); +uint8_t umsg_control_setpoints_deserialize(umsg_control_setpoints_t* data,uint8_t* buffer); // this function includes check that the message type is correct + + + #ifdef __cplusplus } diff --git a/umsg_lib/inc/umsg_example.h b/umsg_lib/inc/umsg_example.h index 5c858af..5ee11be 100644 --- a/umsg_lib/inc/umsg_example.h +++ b/umsg_lib/inc/umsg_example.h @@ -1,4 +1,4 @@ -// Generated with umsg_gen on 2024-08-06 +// Generated with umsg_gen on 2024-08-07 #pragma once #ifdef __cplusplus @@ -7,6 +7,7 @@ extern "C" { #include +#include "umsg_classes.h" // msg structure typedefs typedef enum @@ -47,6 +48,12 @@ void umsg_example_color_selection_publish_ch(umsg_example_color_selection_t* dat uint8_t umsg_example_color_selection_receive(umsg_sub_handle_t queue, umsg_example_color_selection_t* data, uint32_t timeout); uint8_t umsg_example_color_selection_peek(umsg_example_color_selection_t* data); +//function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class and type +//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +//please take care that the messages are build properly to avoid padding issues if the messages are opened on different system +uint32_t umsg_example_color_selection_serialize(umsg_example_color_selection_t* data, uint8_t* buffer); +uint8_t umsg_example_color_selection_deserialize(umsg_example_color_selection_t* data,uint8_t* buffer); // this function includes check that the message type is correct + umsg_sub_handle_t umsg_example_simple_msg_subscribe(uint32_t prescaler, uint8_t length); umsg_sub_handle_t umsg_example_simple_msg_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel); void umsg_example_simple_msg_publish(umsg_example_simple_msg_t* data); @@ -54,6 +61,14 @@ void umsg_example_simple_msg_publish_ch(umsg_example_simple_msg_t* data, uint8_t uint8_t umsg_example_simple_msg_receive(umsg_sub_handle_t queue, umsg_example_simple_msg_t* data, uint32_t timeout); uint8_t umsg_example_simple_msg_peek(umsg_example_simple_msg_t* data); +//function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class and type +//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +//please take care that the messages are build properly to avoid padding issues if the messages are opened on different system +uint32_t umsg_example_simple_msg_serialize(umsg_example_simple_msg_t* data, uint8_t* buffer); +uint8_t umsg_example_simple_msg_deserialize(umsg_example_simple_msg_t* data,uint8_t* buffer); // this function includes check that the message type is correct + + + #ifdef __cplusplus } diff --git a/umsg_lib/inc/umsg_sensors.h b/umsg_lib/inc/umsg_sensors.h index 941f091..13f1a07 100644 --- a/umsg_lib/inc/umsg_sensors.h +++ b/umsg_lib/inc/umsg_sensors.h @@ -1,4 +1,4 @@ -// Generated with umsg_gen on 2024-08-06 +// Generated with umsg_gen on 2024-08-07 #pragma once #ifdef __cplusplus @@ -7,6 +7,7 @@ extern "C" { #include +#include "umsg_classes.h" // msg structure typedefs //enumeration of topics @@ -39,6 +40,12 @@ void umsg_sensors_imu_publish_ch(umsg_sensors_imu_t* data, uint8_t channel); uint8_t umsg_sensors_imu_receive(umsg_sub_handle_t queue, umsg_sensors_imu_t* data, uint32_t timeout); uint8_t umsg_sensors_imu_peek(umsg_sensors_imu_t* data); +//function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class and type +//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +//please take care that the messages are build properly to avoid padding issues if the messages are opened on different system +uint32_t umsg_sensors_imu_serialize(umsg_sensors_imu_t* data, uint8_t* buffer); +uint8_t umsg_sensors_imu_deserialize(umsg_sensors_imu_t* data,uint8_t* buffer); // this function includes check that the message type is correct + umsg_sub_handle_t umsg_sensors_baro_subscribe(uint32_t prescaler, uint8_t length); umsg_sub_handle_t umsg_sensors_baro_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel); void umsg_sensors_baro_publish(umsg_sensors_baro_t* data); @@ -46,6 +53,14 @@ void umsg_sensors_baro_publish_ch(umsg_sensors_baro_t* data, uint8_t channel); uint8_t umsg_sensors_baro_receive(umsg_sub_handle_t queue, umsg_sensors_baro_t* data, uint32_t timeout); uint8_t umsg_sensors_baro_peek(umsg_sensors_baro_t* data); +//function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class and type +//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +//please take care that the messages are build properly to avoid padding issues if the messages are opened on different system +uint32_t umsg_sensors_baro_serialize(umsg_sensors_baro_t* data, uint8_t* buffer); +uint8_t umsg_sensors_baro_deserialize(umsg_sensors_baro_t* data,uint8_t* buffer); // this function includes check that the message type is correct + + + #ifdef __cplusplus } diff --git a/umsg_lib/inc/umsg_test.h b/umsg_lib/inc/umsg_test.h index 2544b7d..755baeb 100644 --- a/umsg_lib/inc/umsg_test.h +++ b/umsg_lib/inc/umsg_test.h @@ -1,4 +1,4 @@ -// Generated with umsg_gen on 2024-08-06 +// Generated with umsg_gen on 2024-08-07 #pragma once #ifdef __cplusplus @@ -7,6 +7,7 @@ extern "C" { #include +#include "umsg_classes.h" // msg structure typedefs typedef enum @@ -94,6 +95,12 @@ void umsg_test_floats_publish_ch(umsg_test_floats_t* data, uint8_t channel); uint8_t umsg_test_floats_receive(umsg_sub_handle_t queue, umsg_test_floats_t* data, uint32_t timeout); uint8_t umsg_test_floats_peek(umsg_test_floats_t* data); +//function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class and type +//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +//please take care that the messages are build properly to avoid padding issues if the messages are opened on different system +uint32_t umsg_test_floats_serialize(umsg_test_floats_t* data, uint8_t* buffer); +uint8_t umsg_test_floats_deserialize(umsg_test_floats_t* data,uint8_t* buffer); // this function includes check that the message type is correct + umsg_sub_handle_t umsg_test_uints_subscribe(uint32_t prescaler, uint8_t length); umsg_sub_handle_t umsg_test_uints_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel); void umsg_test_uints_publish(umsg_test_uints_t* data); @@ -101,6 +108,12 @@ void umsg_test_uints_publish_ch(umsg_test_uints_t* data, uint8_t channel); uint8_t umsg_test_uints_receive(umsg_sub_handle_t queue, umsg_test_uints_t* data, uint32_t timeout); uint8_t umsg_test_uints_peek(umsg_test_uints_t* data); +//function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class and type +//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +//please take care that the messages are build properly to avoid padding issues if the messages are opened on different system +uint32_t umsg_test_uints_serialize(umsg_test_uints_t* data, uint8_t* buffer); +uint8_t umsg_test_uints_deserialize(umsg_test_uints_t* data,uint8_t* buffer); // this function includes check that the message type is correct + umsg_sub_handle_t umsg_test_ints_subscribe(uint32_t prescaler, uint8_t length); umsg_sub_handle_t umsg_test_ints_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel); void umsg_test_ints_publish(umsg_test_ints_t* data); @@ -108,6 +121,12 @@ void umsg_test_ints_publish_ch(umsg_test_ints_t* data, uint8_t channel); uint8_t umsg_test_ints_receive(umsg_sub_handle_t queue, umsg_test_ints_t* data, uint32_t timeout); uint8_t umsg_test_ints_peek(umsg_test_ints_t* data); +//function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class and type +//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +//please take care that the messages are build properly to avoid padding issues if the messages are opened on different system +uint32_t umsg_test_ints_serialize(umsg_test_ints_t* data, uint8_t* buffer); +uint8_t umsg_test_ints_deserialize(umsg_test_ints_t* data,uint8_t* buffer); // this function includes check that the message type is correct + umsg_sub_handle_t umsg_test_strings_subscribe(uint32_t prescaler, uint8_t length); umsg_sub_handle_t umsg_test_strings_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel); void umsg_test_strings_publish(umsg_test_strings_t* data); @@ -115,6 +134,12 @@ void umsg_test_strings_publish_ch(umsg_test_strings_t* data, uint8_t channel); uint8_t umsg_test_strings_receive(umsg_sub_handle_t queue, umsg_test_strings_t* data, uint32_t timeout); uint8_t umsg_test_strings_peek(umsg_test_strings_t* data); +//function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class and type +//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +//please take care that the messages are build properly to avoid padding issues if the messages are opened on different system +uint32_t umsg_test_strings_serialize(umsg_test_strings_t* data, uint8_t* buffer); +uint8_t umsg_test_strings_deserialize(umsg_test_strings_t* data,uint8_t* buffer); // this function includes check that the message type is correct + umsg_sub_handle_t umsg_test_bools_subscribe(uint32_t prescaler, uint8_t length); umsg_sub_handle_t umsg_test_bools_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel); void umsg_test_bools_publish(umsg_test_bools_t* data); @@ -122,6 +147,12 @@ void umsg_test_bools_publish_ch(umsg_test_bools_t* data, uint8_t channel); uint8_t umsg_test_bools_receive(umsg_sub_handle_t queue, umsg_test_bools_t* data, uint32_t timeout); uint8_t umsg_test_bools_peek(umsg_test_bools_t* data); +//function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class and type +//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +//please take care that the messages are build properly to avoid padding issues if the messages are opened on different system +uint32_t umsg_test_bools_serialize(umsg_test_bools_t* data, uint8_t* buffer); +uint8_t umsg_test_bools_deserialize(umsg_test_bools_t* data,uint8_t* buffer); // this function includes check that the message type is correct + umsg_sub_handle_t umsg_test_enums_subscribe(uint32_t prescaler, uint8_t length); umsg_sub_handle_t umsg_test_enums_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel); void umsg_test_enums_publish(umsg_test_enums_t* data); @@ -129,6 +160,12 @@ void umsg_test_enums_publish_ch(umsg_test_enums_t* data, uint8_t channel); uint8_t umsg_test_enums_receive(umsg_sub_handle_t queue, umsg_test_enums_t* data, uint32_t timeout); uint8_t umsg_test_enums_peek(umsg_test_enums_t* data); +//function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class and type +//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +//please take care that the messages are build properly to avoid padding issues if the messages are opened on different system +uint32_t umsg_test_enums_serialize(umsg_test_enums_t* data, uint8_t* buffer); +uint8_t umsg_test_enums_deserialize(umsg_test_enums_t* data,uint8_t* buffer); // this function includes check that the message type is correct + umsg_sub_handle_t umsg_test_bitfield_subscribe(uint32_t prescaler, uint8_t length); umsg_sub_handle_t umsg_test_bitfield_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel); void umsg_test_bitfield_publish(umsg_test_bitfield_t* data); @@ -136,6 +173,14 @@ void umsg_test_bitfield_publish_ch(umsg_test_bitfield_t* data, uint8_t channel); uint8_t umsg_test_bitfield_receive(umsg_sub_handle_t queue, umsg_test_bitfield_t* data, uint32_t timeout); uint8_t umsg_test_bitfield_peek(umsg_test_bitfield_t* data); +//function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class and type +//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +//please take care that the messages are build properly to avoid padding issues if the messages are opened on different system +uint32_t umsg_test_bitfield_serialize(umsg_test_bitfield_t* data, uint8_t* buffer); +uint8_t umsg_test_bitfield_deserialize(umsg_test_bitfield_t* data,uint8_t* buffer); // this function includes check that the message type is correct + + + #ifdef __cplusplus } diff --git a/umsg_lib/inc/umsg_unused.h b/umsg_lib/inc/umsg_unused.h index d137907..6dc2c7a 100644 --- a/umsg_lib/inc/umsg_unused.h +++ b/umsg_lib/inc/umsg_unused.h @@ -1,4 +1,4 @@ -// Generated with umsg_gen on 2024-08-06 +// Generated with umsg_gen on 2024-08-07 #pragma once #ifdef __cplusplus @@ -7,6 +7,7 @@ extern "C" { #include +#include "umsg_classes.h" // msg structure typedefs //enumeration of topics @@ -38,6 +39,12 @@ void umsg_unused_used_var_publish_ch(umsg_unused_used_var_t* data, uint8_t chann uint8_t umsg_unused_used_var_receive(umsg_sub_handle_t queue, umsg_unused_used_var_t* data, uint32_t timeout); uint8_t umsg_unused_used_var_peek(umsg_unused_used_var_t* data); +//function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class and type +//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +//please take care that the messages are build properly to avoid padding issues if the messages are opened on different system +uint32_t umsg_unused_used_var_serialize(umsg_unused_used_var_t* data, uint8_t* buffer); +uint8_t umsg_unused_used_var_deserialize(umsg_unused_used_var_t* data,uint8_t* buffer); // this function includes check that the message type is correct + umsg_sub_handle_t umsg_unused_unused_var_subscribe(uint32_t prescaler, uint8_t length); umsg_sub_handle_t umsg_unused_unused_var_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel); void umsg_unused_unused_var_publish(umsg_unused_unused_var_t* data); @@ -45,6 +52,14 @@ void umsg_unused_unused_var_publish_ch(umsg_unused_unused_var_t* data, uint8_t c uint8_t umsg_unused_unused_var_receive(umsg_sub_handle_t queue, umsg_unused_unused_var_t* data, uint32_t timeout); uint8_t umsg_unused_unused_var_peek(umsg_unused_unused_var_t* data); +//function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class and type +//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +//please take care that the messages are build properly to avoid padding issues if the messages are opened on different system +uint32_t umsg_unused_unused_var_serialize(umsg_unused_unused_var_t* data, uint8_t* buffer); +uint8_t umsg_unused_unused_var_deserialize(umsg_unused_unused_var_t* data,uint8_t* buffer); // this function includes check that the message type is correct + + + #ifdef __cplusplus } diff --git a/umsg_lib/src/battery.c b/umsg_lib/src/battery.c index b4491a9..824fb85 100644 --- a/umsg_lib/src/battery.c +++ b/umsg_lib/src/battery.c @@ -1,4 +1,4 @@ -// Generated with umsg_gen on 2024-08-06 +// Generated with umsg_gen on 2024-08-07 #include #include @@ -32,3 +32,39 @@ uint8_t umsg_battery_state_peek(umsg_battery_state_t* data) return umsg_peek(&msg_battery_state, data, sizeof(umsg_battery_state_t)); } + + + +uint32_t umsg_battery_state_serialize(umsg_battery_state_t* data, uint8_t* buffer) +{ + uint32_t len = 2; + buffer[0] = UMSG_BATTERY; + buffer[1] = BATTERY_STATE; + char *flattened_data = (char *)data; + for(uint32_t i = 0; i < sizeof(umsg_battery_state_t);i++) + { + buffer[len] = flattened_data[i]; + len++; + } + return len; +} + + +//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +uint8_t umsg_battery_state_deserialize(umsg_battery_state_t* data,uint8_t* buffer) +{ + if(buffer[0]!=UMSG_BATTERY || buffer[1] !=BATTERY_STATE) + { + return 0; + } + + uint32_t offset = 2; + char *flattened_data = (char *)data; + for(uint32_t i = 0; i < sizeof(umsg_battery_state_t);i++) + { + flattened_data[i] = buffer[offset]; + offset++; + } + + return 1; +} diff --git a/umsg_lib/src/control.c b/umsg_lib/src/control.c index b9eda83..931c6d6 100644 --- a/umsg_lib/src/control.c +++ b/umsg_lib/src/control.c @@ -1,4 +1,4 @@ -// Generated with umsg_gen on 2024-08-06 +// Generated with umsg_gen on 2024-08-07 #include #include @@ -32,3 +32,39 @@ uint8_t umsg_control_setpoints_peek(umsg_control_setpoints_t* data) return umsg_peek(&msg_control_setpoints, data, sizeof(umsg_control_setpoints_t)); } + + + +uint32_t umsg_control_setpoints_serialize(umsg_control_setpoints_t* data, uint8_t* buffer) +{ + uint32_t len = 2; + buffer[0] = UMSG_CONTROL; + buffer[1] = CONTROL_SETPOINTS; + char *flattened_data = (char *)data; + for(uint32_t i = 0; i < sizeof(umsg_control_setpoints_t);i++) + { + buffer[len] = flattened_data[i]; + len++; + } + return len; +} + + +//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +uint8_t umsg_control_setpoints_deserialize(umsg_control_setpoints_t* data,uint8_t* buffer) +{ + if(buffer[0]!=UMSG_CONTROL || buffer[1] !=CONTROL_SETPOINTS) + { + return 0; + } + + uint32_t offset = 2; + char *flattened_data = (char *)data; + for(uint32_t i = 0; i < sizeof(umsg_control_setpoints_t);i++) + { + flattened_data[i] = buffer[offset]; + offset++; + } + + return 1; +} diff --git a/umsg_lib/src/example.c b/umsg_lib/src/example.c index 5687afa..869c507 100644 --- a/umsg_lib/src/example.c +++ b/umsg_lib/src/example.c @@ -1,4 +1,4 @@ -// Generated with umsg_gen on 2024-08-06 +// Generated with umsg_gen on 2024-08-07 #include #include @@ -33,6 +33,42 @@ uint8_t umsg_example_color_selection_peek(umsg_example_color_selection_t* data) return umsg_peek(&msg_example_color_selection, data, sizeof(umsg_example_color_selection_t)); } + + + +uint32_t umsg_example_color_selection_serialize(umsg_example_color_selection_t* data, uint8_t* buffer) +{ + uint32_t len = 2; + buffer[0] = UMSG_EXAMPLE; + buffer[1] = EXAMPLE_COLOR_SELECTION; + char *flattened_data = (char *)data; + for(uint32_t i = 0; i < sizeof(umsg_example_color_selection_t);i++) + { + buffer[len] = flattened_data[i]; + len++; + } + return len; +} + + +//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +uint8_t umsg_example_color_selection_deserialize(umsg_example_color_selection_t* data,uint8_t* buffer) +{ + if(buffer[0]!=UMSG_EXAMPLE || buffer[1] !=EXAMPLE_COLOR_SELECTION) + { + return 0; + } + + uint32_t offset = 2; + char *flattened_data = (char *)data; + for(uint32_t i = 0; i < sizeof(umsg_example_color_selection_t);i++) + { + flattened_data[i] = buffer[offset]; + offset++; + } + + return 1; +} // example_simple_msg umsg_sub_handle_t umsg_example_simple_msg_subscribe(uint32_t prescaler, uint8_t length) { @@ -59,3 +95,39 @@ uint8_t umsg_example_simple_msg_peek(umsg_example_simple_msg_t* data) return umsg_peek(&msg_example_simple_msg, data, sizeof(umsg_example_simple_msg_t)); } + + + +uint32_t umsg_example_simple_msg_serialize(umsg_example_simple_msg_t* data, uint8_t* buffer) +{ + uint32_t len = 2; + buffer[0] = UMSG_EXAMPLE; + buffer[1] = EXAMPLE_SIMPLE_MSG; + char *flattened_data = (char *)data; + for(uint32_t i = 0; i < sizeof(umsg_example_simple_msg_t);i++) + { + buffer[len] = flattened_data[i]; + len++; + } + return len; +} + + +//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +uint8_t umsg_example_simple_msg_deserialize(umsg_example_simple_msg_t* data,uint8_t* buffer) +{ + if(buffer[0]!=UMSG_EXAMPLE || buffer[1] !=EXAMPLE_SIMPLE_MSG) + { + return 0; + } + + uint32_t offset = 2; + char *flattened_data = (char *)data; + for(uint32_t i = 0; i < sizeof(umsg_example_simple_msg_t);i++) + { + flattened_data[i] = buffer[offset]; + offset++; + } + + return 1; +} diff --git a/umsg_lib/src/sensors.c b/umsg_lib/src/sensors.c index 25e8a4c..7d884ce 100644 --- a/umsg_lib/src/sensors.c +++ b/umsg_lib/src/sensors.c @@ -1,5 +1,6 @@ -// Generated with umsg_gen on 2024-08-06 +// Generated with umsg_gen on 2024-08-07 #include + #include // msg instances @@ -33,6 +34,42 @@ uint8_t umsg_sensors_imu_peek(umsg_sensors_imu_t* data) return umsg_peek(&msg_sensors_imu, data, sizeof(umsg_sensors_imu_t)); } + + + +uint32_t umsg_sensors_imu_serialize(umsg_sensors_imu_t* data, uint8_t* buffer) +{ + uint32_t len = 2; + buffer[0] = UMSG_SENSORS; + buffer[1] = SENSORS_IMU; + char *flattened_data = (char *)data; + for(uint32_t i = 0; i < sizeof(umsg_sensors_imu_t);i++) + { + buffer[len] = flattened_data[i]; + len++; + } + return len; +} + + +//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +uint8_t umsg_sensors_imu_deserialize(umsg_sensors_imu_t* data,uint8_t* buffer) +{ + if(buffer[0]!=UMSG_SENSORS || buffer[1] !=SENSORS_IMU) + { + return 0; + } + + uint32_t offset = 2; + char *flattened_data = (char *)data; + for(uint32_t i = 0; i < sizeof(umsg_sensors_imu_t);i++) + { + flattened_data[i] = buffer[offset]; + offset++; + } + + return 1; +} // sensors_baro umsg_sub_handle_t umsg_sensors_baro_subscribe(uint32_t prescaler, uint8_t length) { @@ -59,3 +96,39 @@ uint8_t umsg_sensors_baro_peek(umsg_sensors_baro_t* data) return umsg_peek(&msg_sensors_baro, data, sizeof(umsg_sensors_baro_t)); } + + + +uint32_t umsg_sensors_baro_serialize(umsg_sensors_baro_t* data, uint8_t* buffer) +{ + uint32_t len = 2; + buffer[0] = UMSG_SENSORS; + buffer[1] = SENSORS_BARO; + char *flattened_data = (char *)data; + for(uint32_t i = 0; i < sizeof(umsg_sensors_baro_t);i++) + { + buffer[len] = flattened_data[i]; + len++; + } + return len; +} + + +//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +uint8_t umsg_sensors_baro_deserialize(umsg_sensors_baro_t* data,uint8_t* buffer) +{ + if(buffer[0]!=UMSG_SENSORS || buffer[1] !=SENSORS_BARO) + { + return 0; + } + + uint32_t offset = 2; + char *flattened_data = (char *)data; + for(uint32_t i = 0; i < sizeof(umsg_sensors_baro_t);i++) + { + flattened_data[i] = buffer[offset]; + offset++; + } + + return 1; +} diff --git a/umsg_lib/src/test.c b/umsg_lib/src/test.c index ed5fa37..e1f5aae 100644 --- a/umsg_lib/src/test.c +++ b/umsg_lib/src/test.c @@ -1,4 +1,4 @@ -// Generated with umsg_gen on 2024-08-06 +// Generated with umsg_gen on 2024-08-07 #include #include @@ -38,6 +38,42 @@ uint8_t umsg_test_floats_peek(umsg_test_floats_t* data) return umsg_peek(&msg_test_floats, data, sizeof(umsg_test_floats_t)); } + + + +uint32_t umsg_test_floats_serialize(umsg_test_floats_t* data, uint8_t* buffer) +{ + uint32_t len = 2; + buffer[0] = UMSG_TEST; + buffer[1] = TEST_FLOATS; + char *flattened_data = (char *)data; + for(uint32_t i = 0; i < sizeof(umsg_test_floats_t);i++) + { + buffer[len] = flattened_data[i]; + len++; + } + return len; +} + + +//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +uint8_t umsg_test_floats_deserialize(umsg_test_floats_t* data,uint8_t* buffer) +{ + if(buffer[0]!=UMSG_TEST || buffer[1] !=TEST_FLOATS) + { + return 0; + } + + uint32_t offset = 2; + char *flattened_data = (char *)data; + for(uint32_t i = 0; i < sizeof(umsg_test_floats_t);i++) + { + flattened_data[i] = buffer[offset]; + offset++; + } + + return 1; +} // test_uints umsg_sub_handle_t umsg_test_uints_subscribe(uint32_t prescaler, uint8_t length) { @@ -64,6 +100,42 @@ uint8_t umsg_test_uints_peek(umsg_test_uints_t* data) return umsg_peek(&msg_test_uints, data, sizeof(umsg_test_uints_t)); } + + + +uint32_t umsg_test_uints_serialize(umsg_test_uints_t* data, uint8_t* buffer) +{ + uint32_t len = 2; + buffer[0] = UMSG_TEST; + buffer[1] = TEST_UINTS; + char *flattened_data = (char *)data; + for(uint32_t i = 0; i < sizeof(umsg_test_uints_t);i++) + { + buffer[len] = flattened_data[i]; + len++; + } + return len; +} + + +//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +uint8_t umsg_test_uints_deserialize(umsg_test_uints_t* data,uint8_t* buffer) +{ + if(buffer[0]!=UMSG_TEST || buffer[1] !=TEST_UINTS) + { + return 0; + } + + uint32_t offset = 2; + char *flattened_data = (char *)data; + for(uint32_t i = 0; i < sizeof(umsg_test_uints_t);i++) + { + flattened_data[i] = buffer[offset]; + offset++; + } + + return 1; +} // test_ints umsg_sub_handle_t umsg_test_ints_subscribe(uint32_t prescaler, uint8_t length) { @@ -90,6 +162,42 @@ uint8_t umsg_test_ints_peek(umsg_test_ints_t* data) return umsg_peek(&msg_test_ints, data, sizeof(umsg_test_ints_t)); } + + + +uint32_t umsg_test_ints_serialize(umsg_test_ints_t* data, uint8_t* buffer) +{ + uint32_t len = 2; + buffer[0] = UMSG_TEST; + buffer[1] = TEST_INTS; + char *flattened_data = (char *)data; + for(uint32_t i = 0; i < sizeof(umsg_test_ints_t);i++) + { + buffer[len] = flattened_data[i]; + len++; + } + return len; +} + + +//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +uint8_t umsg_test_ints_deserialize(umsg_test_ints_t* data,uint8_t* buffer) +{ + if(buffer[0]!=UMSG_TEST || buffer[1] !=TEST_INTS) + { + return 0; + } + + uint32_t offset = 2; + char *flattened_data = (char *)data; + for(uint32_t i = 0; i < sizeof(umsg_test_ints_t);i++) + { + flattened_data[i] = buffer[offset]; + offset++; + } + + return 1; +} // test_strings umsg_sub_handle_t umsg_test_strings_subscribe(uint32_t prescaler, uint8_t length) { @@ -116,6 +224,42 @@ uint8_t umsg_test_strings_peek(umsg_test_strings_t* data) return umsg_peek(&msg_test_strings, data, sizeof(umsg_test_strings_t)); } + + + +uint32_t umsg_test_strings_serialize(umsg_test_strings_t* data, uint8_t* buffer) +{ + uint32_t len = 2; + buffer[0] = UMSG_TEST; + buffer[1] = TEST_STRINGS; + char *flattened_data = (char *)data; + for(uint32_t i = 0; i < sizeof(umsg_test_strings_t);i++) + { + buffer[len] = flattened_data[i]; + len++; + } + return len; +} + + +//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +uint8_t umsg_test_strings_deserialize(umsg_test_strings_t* data,uint8_t* buffer) +{ + if(buffer[0]!=UMSG_TEST || buffer[1] !=TEST_STRINGS) + { + return 0; + } + + uint32_t offset = 2; + char *flattened_data = (char *)data; + for(uint32_t i = 0; i < sizeof(umsg_test_strings_t);i++) + { + flattened_data[i] = buffer[offset]; + offset++; + } + + return 1; +} // test_bools umsg_sub_handle_t umsg_test_bools_subscribe(uint32_t prescaler, uint8_t length) { @@ -142,6 +286,42 @@ uint8_t umsg_test_bools_peek(umsg_test_bools_t* data) return umsg_peek(&msg_test_bools, data, sizeof(umsg_test_bools_t)); } + + + +uint32_t umsg_test_bools_serialize(umsg_test_bools_t* data, uint8_t* buffer) +{ + uint32_t len = 2; + buffer[0] = UMSG_TEST; + buffer[1] = TEST_BOOLS; + char *flattened_data = (char *)data; + for(uint32_t i = 0; i < sizeof(umsg_test_bools_t);i++) + { + buffer[len] = flattened_data[i]; + len++; + } + return len; +} + + +//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +uint8_t umsg_test_bools_deserialize(umsg_test_bools_t* data,uint8_t* buffer) +{ + if(buffer[0]!=UMSG_TEST || buffer[1] !=TEST_BOOLS) + { + return 0; + } + + uint32_t offset = 2; + char *flattened_data = (char *)data; + for(uint32_t i = 0; i < sizeof(umsg_test_bools_t);i++) + { + flattened_data[i] = buffer[offset]; + offset++; + } + + return 1; +} // test_enums umsg_sub_handle_t umsg_test_enums_subscribe(uint32_t prescaler, uint8_t length) { @@ -168,6 +348,42 @@ uint8_t umsg_test_enums_peek(umsg_test_enums_t* data) return umsg_peek(&msg_test_enums, data, sizeof(umsg_test_enums_t)); } + + + +uint32_t umsg_test_enums_serialize(umsg_test_enums_t* data, uint8_t* buffer) +{ + uint32_t len = 2; + buffer[0] = UMSG_TEST; + buffer[1] = TEST_ENUMS; + char *flattened_data = (char *)data; + for(uint32_t i = 0; i < sizeof(umsg_test_enums_t);i++) + { + buffer[len] = flattened_data[i]; + len++; + } + return len; +} + + +//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +uint8_t umsg_test_enums_deserialize(umsg_test_enums_t* data,uint8_t* buffer) +{ + if(buffer[0]!=UMSG_TEST || buffer[1] !=TEST_ENUMS) + { + return 0; + } + + uint32_t offset = 2; + char *flattened_data = (char *)data; + for(uint32_t i = 0; i < sizeof(umsg_test_enums_t);i++) + { + flattened_data[i] = buffer[offset]; + offset++; + } + + return 1; +} // test_bitfield umsg_sub_handle_t umsg_test_bitfield_subscribe(uint32_t prescaler, uint8_t length) { @@ -194,3 +410,39 @@ uint8_t umsg_test_bitfield_peek(umsg_test_bitfield_t* data) return umsg_peek(&msg_test_bitfield, data, sizeof(umsg_test_bitfield_t)); } + + + +uint32_t umsg_test_bitfield_serialize(umsg_test_bitfield_t* data, uint8_t* buffer) +{ + uint32_t len = 2; + buffer[0] = UMSG_TEST; + buffer[1] = TEST_BITFIELD; + char *flattened_data = (char *)data; + for(uint32_t i = 0; i < sizeof(umsg_test_bitfield_t);i++) + { + buffer[len] = flattened_data[i]; + len++; + } + return len; +} + + +//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +uint8_t umsg_test_bitfield_deserialize(umsg_test_bitfield_t* data,uint8_t* buffer) +{ + if(buffer[0]!=UMSG_TEST || buffer[1] !=TEST_BITFIELD) + { + return 0; + } + + uint32_t offset = 2; + char *flattened_data = (char *)data; + for(uint32_t i = 0; i < sizeof(umsg_test_bitfield_t);i++) + { + flattened_data[i] = buffer[offset]; + offset++; + } + + return 1; +} diff --git a/umsg_lib/src/unused.c b/umsg_lib/src/unused.c index 03ea303..97bc29f 100644 --- a/umsg_lib/src/unused.c +++ b/umsg_lib/src/unused.c @@ -1,4 +1,4 @@ -// Generated with umsg_gen on 2024-08-06 +// Generated with umsg_gen on 2024-08-07 #include #include @@ -33,6 +33,42 @@ uint8_t umsg_unused_used_var_peek(umsg_unused_used_var_t* data) return umsg_peek(&msg_unused_used_var, data, sizeof(umsg_unused_used_var_t)); } + + + +uint32_t umsg_unused_used_var_serialize(umsg_unused_used_var_t* data, uint8_t* buffer) +{ + uint32_t len = 2; + buffer[0] = UMSG_UNUSED; + buffer[1] = UNUSED_USED_VAR; + char *flattened_data = (char *)data; + for(uint32_t i = 0; i < sizeof(umsg_unused_used_var_t);i++) + { + buffer[len] = flattened_data[i]; + len++; + } + return len; +} + + +//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +uint8_t umsg_unused_used_var_deserialize(umsg_unused_used_var_t* data,uint8_t* buffer) +{ + if(buffer[0]!=UMSG_UNUSED || buffer[1] !=UNUSED_USED_VAR) + { + return 0; + } + + uint32_t offset = 2; + char *flattened_data = (char *)data; + for(uint32_t i = 0; i < sizeof(umsg_unused_used_var_t);i++) + { + flattened_data[i] = buffer[offset]; + offset++; + } + + return 1; +} // unused_unused_var umsg_sub_handle_t umsg_unused_unused_var_subscribe(uint32_t prescaler, uint8_t length) { @@ -59,3 +95,39 @@ uint8_t umsg_unused_unused_var_peek(umsg_unused_unused_var_t* data) return umsg_peek(&msg_unused_unused_var, data, sizeof(umsg_unused_unused_var_t)); } + + + +uint32_t umsg_unused_unused_var_serialize(umsg_unused_unused_var_t* data, uint8_t* buffer) +{ + uint32_t len = 2; + buffer[0] = UMSG_UNUSED; + buffer[1] = UNUSED_UNUSED_VAR; + char *flattened_data = (char *)data; + for(uint32_t i = 0; i < sizeof(umsg_unused_unused_var_t);i++) + { + buffer[len] = flattened_data[i]; + len++; + } + return len; +} + + +//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +uint8_t umsg_unused_unused_var_deserialize(umsg_unused_unused_var_t* data,uint8_t* buffer) +{ + if(buffer[0]!=UMSG_UNUSED || buffer[1] !=UNUSED_UNUSED_VAR) + { + return 0; + } + + uint32_t offset = 2; + char *flattened_data = (char *)data; + for(uint32_t i = 0; i < sizeof(umsg_unused_unused_var_t);i++) + { + flattened_data[i] = buffer[offset]; + offset++; + } + + return 1; +} From 03d8bd8c805ba277e26b436d30b58ca4e57e76b5 Mon Sep 17 00:00:00 2001 From: Michal Reiser Date: Thu, 8 Aug 2024 13:42:30 +0200 Subject: [PATCH 04/16] tested the logfile passing --- umsg_gen/umsg_gen/templates/log_parser.cpp.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 b/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 index b60b40f..a8187b9 100644 --- a/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 +++ b/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 @@ -172,8 +172,8 @@ int main(int argc, char *argv[]) { {%endfor%} while(file.tellg()!= std::filesystem::file_size(file_path)) { - std::cout << "cursor at: " << file.tellg() << " from " << std::filesystem::file_size(file_path) << "\r"; sort_msg(file); + std::cout << "cursor at: " << file.tellg() << " from " << std::filesystem::file_size(file_path) << "\r"; } // close all the files From b23898d7f177942d2a04257f879d079a9feec9e6 Mon Sep 17 00:00:00 2001 From: Michal Reiser Date: Thu, 8 Aug 2024 17:18:53 +0200 Subject: [PATCH 05/16] fixed bug with printing of type uint8_t to csv --- umsg_gen/umsg_gen/templates/log_parser.cpp.j2 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 b/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 index a8187b9..1bfc7e8 100644 --- a/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 +++ b/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 @@ -51,10 +51,10 @@ void sort_{{dict.name}}_type(std::ifstream &file) {% for field in msg_dict.fields %} {% if not field.bitfield %} {% if field.length %} - for(uint32_t i=0;i<{{field.length}}; i++){ file_{{dict.name}}_{{msg_dict.name}} << message->{{field.name}}[i] << ", " ;} + for(uint32_t i=0;i<{{field.length}}; i++){ file_{{dict.name}}_{{msg_dict.name}} << {% if field.type =="uint8"%} static_cast(message->{{field.name}}[i]) {% else %}message->{{field.name}}[i] {% endif %}<< ", " ;} {% endif %} {% if not field.length %} - file_{{dict.name}}_{{msg_dict.name}} << message->{{field.name}}{% if not loop.last%} << ", "{% endif %}; + file_{{dict.name}}_{{msg_dict.name}} << {% if field.type =="uint8"%} static_cast(message->{{field.name}}) {% else %}message->{{field.name}}{% endif %}{% if not loop.last%} << ", "{% endif %}; {% endif %} {% endif %} {% if field.bitfield %} From 43af4c7f2f3a45e9bb5e403582bb4614af5d7fea Mon Sep 17 00:00:00 2001 From: Michal Reiser Date: Tue, 13 Aug 2024 17:17:44 +0200 Subject: [PATCH 06/16] fixed bitfield and enm printing problem --- umsg_gen/umsg_gen/templates/log_parser.cpp.j2 | 2 +- umsg_gen/umsg_gen/templates/msg.h.j2 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 b/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 index 1bfc7e8..d88a80c 100644 --- a/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 +++ b/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 @@ -59,7 +59,7 @@ void sort_{{dict.name}}_type(std::ifstream &file) {% endif %} {% if field.bitfield %} {%for bitfield in field.bitfield %} - file_{{dict.name}}_{{msg_dict.name}} << message->{{bitfield.name}}{% if not loop.last%} << ", "{% endif %}; + file_{{dict.name}}_{{msg_dict.name}} << static_cast(message->{{bitfield.name}}){% if not loop.last%} << ", "{% endif %}; {%endfor%} {% endif %} {% endfor %} diff --git a/umsg_gen/umsg_gen/templates/msg.h.j2 b/umsg_gen/umsg_gen/templates/msg.h.j2 index 26af5b6..b4beb96 100644 --- a/umsg_gen/umsg_gen/templates/msg.h.j2 +++ b/umsg_gen/umsg_gen/templates/msg.h.j2 @@ -41,7 +41,7 @@ extern "C" { {%if topic_dict.enums %} {% for enum in topic_dict.enums%} -typedef enum +typedef enum __attribute__((__packed__)) { {%for val in enum.enumerators%} {{val.upper()}}{{ "," if not loop.last else "" }} From f99ecf5360b4ead7e75b853f0c31bffc15321f4e Mon Sep 17 00:00:00 2001 From: Michal Reiser Date: Thu, 22 Aug 2024 17:19:28 +0200 Subject: [PATCH 07/16] fixed csv bug that prevended loading of the file to python --- umsg_gen/umsg_gen/templates/log_parser.cpp.j2 | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 b/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 index d88a80c..c09b904 100644 --- a/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 +++ b/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 @@ -51,7 +51,14 @@ void sort_{{dict.name}}_type(std::ifstream &file) {% for field in msg_dict.fields %} {% if not field.bitfield %} {% if field.length %} - for(uint32_t i=0;i<{{field.length}}; i++){ file_{{dict.name}}_{{msg_dict.name}} << {% if field.type =="uint8"%} static_cast(message->{{field.name}}[i]) {% else %}message->{{field.name}}[i] {% endif %}<< ", " ;} + for(uint32_t i=0;i<{{field.length}}; i++){ + file_{{dict.name}}_{{msg_dict.name}} << {% if field.type =="uint8"%} static_cast(message->{{field.name}}[i]) + {% else %}message->{{field.name}}[i] {% endif %} ; + {%if loop.last%} + if(i<{{field.length}} - 1) + {%endif%} + file_{{dict.name}}_{{msg_dict.name}} << ", "; + } {% endif %} {% if not field.length %} file_{{dict.name}}_{{msg_dict.name}} << {% if field.type =="uint8"%} static_cast(message->{{field.name}}) {% else %}message->{{field.name}}{% endif %}{% if not loop.last%} << ", "{% endif %}; From abad9f33581708d4a8bb0362effb1f5d5431969b Mon Sep 17 00:00:00 2001 From: Michal Reiser Date: Thu, 24 Oct 2024 11:50:28 +0200 Subject: [PATCH 08/16] increased the precision of printed doubles and floats --- umsg_gen/umsg_gen/templates/log_parser.cpp.j2 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 b/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 index c09b904..99dc4e9 100644 --- a/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 +++ b/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 @@ -53,6 +53,8 @@ void sort_{{dict.name}}_type(std::ifstream &file) {% if field.length %} for(uint32_t i=0;i<{{field.length}}; i++){ file_{{dict.name}}_{{msg_dict.name}} << {% if field.type =="uint8"%} static_cast(message->{{field.name}}[i]) + {% elif field.type == "float"%} std::setprecision(std::numeric_limits::max_digits10) << message->{{field.name}}[i] + {%elif field.type == "double"%} std::setprecision(std::numeric_limits::max_digits10) << message->{{field.name}}[i] {% else %}message->{{field.name}}[i] {% endif %} ; {%if loop.last%} if(i<{{field.length}} - 1) @@ -61,7 +63,10 @@ void sort_{{dict.name}}_type(std::ifstream &file) } {% endif %} {% if not field.length %} - file_{{dict.name}}_{{msg_dict.name}} << {% if field.type =="uint8"%} static_cast(message->{{field.name}}) {% else %}message->{{field.name}}{% endif %}{% if not loop.last%} << ", "{% endif %}; + file_{{dict.name}}_{{msg_dict.name}} << {% if field.type =="uint8"%} static_cast(message->{{field.name}}) + {% elif field.type == "float"%} std::setprecision(std::numeric_limits::max_digits10) << message->{{field.name}} + {%elif field.type == "double"%} std::setprecision(std::numeric_limits::max_digits10) << message->{{field.name}} + {% else %}message->{{field.name}}{% endif %}{% if not loop.last%} << ", "{% endif %}; {% endif %} {% endif %} {% if field.bitfield %} From 612d2d2a49c732861bf1ae0bc33c2f32146abce7 Mon Sep 17 00:00:00 2001 From: Michal Reiser Date: Tue, 29 Oct 2024 19:44:12 +0100 Subject: [PATCH 09/16] added checksum calculation --- umsg_gen/umsg_gen/core/inc/umsg.h | 7 ++ umsg_gen/umsg_gen/core/src/umsg.c | 56 +++++++++++++++ umsg_gen/umsg_gen/templates/log_parser.cpp.j2 | 37 ++++++---- umsg_gen/umsg_gen/templates/msg.c.j2 | 23 +++++-- umsg_gen/umsg_gen/templates/msg.h.j2 | 5 ++ umsg_lib/core/src/umsg.c | 69 ------------------- 6 files changed, 109 insertions(+), 88 deletions(-) delete mode 100644 umsg_lib/core/src/umsg.c diff --git a/umsg_gen/umsg_gen/core/inc/umsg.h b/umsg_gen/umsg_gen/core/inc/umsg.h index b263042..2109976 100644 --- a/umsg_gen/umsg_gen/core/inc/umsg.h +++ b/umsg_gen/umsg_gen/core/inc/umsg.h @@ -33,6 +33,13 @@ void umsg_publish(umsg_msg_metadata_t* msg, void* data, uint8_t ch_id); uint8_t umsg_receive(umsg_sub_handle_t queue, void* data, uint32_t timeout); uint8_t umsg_peek(umsg_msg_metadata_t* msg, void* data, uint32_t size); + +void umsg_CRCInit(); +uint8_t umsg_checkCRC(uint8_t* buffer, uint32_t len); +uint8_t umsg_calcCRC(uint8_t* buffer, uint32_t len); + + + #ifdef __cplusplus } #endif diff --git a/umsg_gen/umsg_gen/core/src/umsg.c b/umsg_gen/umsg_gen/core/src/umsg.c index 4fb8d8b..db845d6 100644 --- a/umsg_gen/umsg_gen/core/src/umsg.c +++ b/umsg_gen/umsg_gen/core/src/umsg.c @@ -6,6 +6,11 @@ #include #include +uint8_t CRCresults[256]; + +const uint8_t remainder_len = 8; +const uint16_t POLYNOMIAL = 0x2F; // this is a CRC8 polynomial + umsg_sub_handle_t umsg_subscribe(umsg_msg_metadata_t* msg, uint16_t prescaler, uint32_t size, uint8_t length, uint8_t ch_id) { if(msg->sub_list == NULL) @@ -66,4 +71,55 @@ uint8_t umsg_peek(umsg_msg_metadata_t* msg, void* data, uint32_t size) return 1; } return 0; +} + + +void umsg_CRCInit(){ + + uint8_t top_bit = (1 << (remainder_len - 1)); + uint8_t remainder = 0; + for(int i = 0; i < 256; i++){ + remainder = i; + for (uint8_t bit = 8; bit > 0; --bit) + { + /* + * Try to divide the current data bit. + */ + if (remainder & top_bit) + { + remainder = (remainder << 1) ^ POLYNOMIAL; + } + else + { + remainder = (remainder << 1); + } + } + CRCresults[i] = remainder; + } + + +} + + +uint8_t umsg_checkCRC(uint8_t* buffer, uint32_t len){ + uint8_t remainder = umsg_calcCRC(buffer,len); + if(remainder == 0) + return 0; + return 1; +} + + +uint8_t umsg_calcCRC(uint8_t* buffer, uint32_t len){ + uint8_t data; + uint8_t remainder = 0; + + /* + * Divide the message by the polynomial, a byte at a time. + */ + for (int byte = 0; byte < len; ++byte) + { + data = buffer[byte] ^ (remainder); + remainder = CRCresults[data] ^ (remainder << 8); + } + return remainder; } \ No newline at end of file diff --git a/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 b/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 index 99dc4e9..940075c 100644 --- a/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 +++ b/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 @@ -7,7 +7,7 @@ #include #include - +#include "umsg.h" #include"umsg_classes.h" {% for val in topic_dict_list%} @@ -19,6 +19,9 @@ //globally defined streams for topic files +char buffer[1000]; + + {% for dict in topic_dict_list%} {% for msg_dict in dict.msgs%} std::ofstream file_{{dict.name}}_{{msg_dict.name}}; @@ -39,23 +42,27 @@ void sort_{{dict.name}}_type(std::ifstream &file) exit(2); } + buffer[0] = UMSG_{{dict.name.upper()}}; + buffer[1] = msg_type; switch(msg_type) { {% for msg_dict in dict.msgs%} case {{dict.name.upper()}}_{{msg_dict.name.upper()}}: { - char buffer[sizeof(umsg_{{dict.name}}_{{msg_dict.name}}_t)]; - file.read(buffer,sizeof(umsg_{{dict.name}}_{{msg_dict.name}}_t)); - umsg_{{dict.name}}_{{msg_dict.name}}_t* message = reinterpret_cast (buffer); - + file.read(buffer + 2,sizeof(umsg_{{dict.name}}_{{msg_dict.name}}_t) + 1); //read including the crc byte + umsg_{{dict.name}}_{{msg_dict.name}}_t message; + uint8_t retval = umsg_{{dict.name}}_{{msg_dict.name}}_deserialize_CRC(&message,(uint8_t *)buffer); + if(retval){ + std::cout << "retval for message {{dict.name.upper()}}_{{msg_dict.name.upper()}} failed with value: " << static_cast(retval) << std::endl; + } {% for field in msg_dict.fields %} {% if not field.bitfield %} {% if field.length %} for(uint32_t i=0;i<{{field.length}}; i++){ - file_{{dict.name}}_{{msg_dict.name}} << {% if field.type =="uint8"%} static_cast(message->{{field.name}}[i]) - {% elif field.type == "float"%} std::setprecision(std::numeric_limits::max_digits10) << message->{{field.name}}[i] - {%elif field.type == "double"%} std::setprecision(std::numeric_limits::max_digits10) << message->{{field.name}}[i] - {% else %}message->{{field.name}}[i] {% endif %} ; + file_{{dict.name}}_{{msg_dict.name}} << {% if field.type =="uint8"%} static_cast(message.{{field.name}}[i]) + {% elif field.type == "float"%} std::setprecision(std::numeric_limits::max_digits10) << message.{{field.name}}[i] + {%elif field.type == "double"%} std::setprecision(std::numeric_limits::max_digits10) << message.{{field.name}}[i] + {% else %}message.{{field.name}}[i] {% endif %} ; {%if loop.last%} if(i<{{field.length}} - 1) {%endif%} @@ -63,15 +70,15 @@ void sort_{{dict.name}}_type(std::ifstream &file) } {% endif %} {% if not field.length %} - file_{{dict.name}}_{{msg_dict.name}} << {% if field.type =="uint8"%} static_cast(message->{{field.name}}) - {% elif field.type == "float"%} std::setprecision(std::numeric_limits::max_digits10) << message->{{field.name}} - {%elif field.type == "double"%} std::setprecision(std::numeric_limits::max_digits10) << message->{{field.name}} - {% else %}message->{{field.name}}{% endif %}{% if not loop.last%} << ", "{% endif %}; + file_{{dict.name}}_{{msg_dict.name}} << {% if field.type =="uint8"%} static_cast(message.{{field.name}}) + {% elif field.type == "float"%} std::setprecision(std::numeric_limits::max_digits10) << message.{{field.name}} + {%elif field.type == "double"%} std::setprecision(std::numeric_limits::max_digits10) << message.{{field.name}} + {% else %}message.{{field.name}}{% endif %}{% if not loop.last%} << ", "{% endif %}; {% endif %} {% endif %} {% if field.bitfield %} {%for bitfield in field.bitfield %} - file_{{dict.name}}_{{msg_dict.name}} << static_cast(message->{{bitfield.name}}){% if not loop.last%} << ", "{% endif %}; + file_{{dict.name}}_{{msg_dict.name}} << static_cast(message.{{bitfield.name}}){% if not loop.last%} << ", "{% endif %}; {%endfor%} {% endif %} {% endfor %} @@ -139,7 +146,7 @@ int main(int argc, char *argv[]) { std::cerr << std::endl << "Usage: " << argv[0] << " " << std::endl; return 1; } - + umsg_CRCInit(); //proceed to open the file const std::string file_path = argv[1]; std::ifstream file(file_path,std::ios::binary); diff --git a/umsg_gen/umsg_gen/templates/msg.c.j2 b/umsg_gen/umsg_gen/templates/msg.c.j2 index 480419b..a67c9ff 100644 --- a/umsg_gen/umsg_gen/templates/msg.c.j2 +++ b/umsg_gen/umsg_gen/templates/msg.c.j2 @@ -42,7 +42,7 @@ uint32_t umsg_{{prefix}}_serialize(umsg_{{prefix}}_t* data, uint8_t* buffer) uint32_t len = 2; buffer[0] = UMSG_{{topic_dict.name.upper()}}; buffer[1] = {{topic_dict.name.upper()}}_{{msg_dict.name.upper()}}; - char *flattened_data = (char *)data; + uint8_t *flattened_data = (uint8_t *)data; //this can probably be replaced by memcpy but it is done like this for now just to be safe for(uint32_t i = 0; i < sizeof(umsg_{{prefix}}_t);i++) { @@ -57,11 +57,11 @@ uint8_t umsg_{{prefix}}_deserialize(umsg_{{prefix}}_t* data,uint8_t* buffer) { if(buffer[0]!=UMSG_{{topic_dict.name.upper()}} || buffer[1] !={{topic_dict.name.upper()}}_{{msg_dict.name.upper()}}) { - return 0; + return 1; } uint32_t offset = 2; - char *flattened_data = (char *)data; + uint8_t *flattened_data = (uint8_t *)data; //this can probably be replaced by memcpy but it is done like this for now just to be safe for(uint32_t i = 0; i < sizeof(umsg_{{prefix}}_t);i++) { @@ -69,8 +69,23 @@ uint8_t umsg_{{prefix}}_deserialize(umsg_{{prefix}}_t* data,uint8_t* buffer) offset++; } - return 1; + return 0; } + +uint32_t umsg_{{prefix}}_serialize_CRC(umsg_{{prefix}}_t* data, uint8_t* buffer){ + uint32_t len = umsg_{{prefix}}_serialize(data,buffer); + uint8_t crc = umsg_calcCRC(buffer, len); + buffer[len] = crc; + len++; + return len; +} +uint8_t umsg_{{prefix}}_deserialize_CRC(umsg_{{prefix}}_t* data,uint8_t* buffer){ + uint8_t invalidcrc = umsg_checkCRC(buffer, sizeof(umsg_{{prefix}}_t) + 3); + uint8_t retval = umsg_{{prefix}}_deserialize(data,buffer); + return invalidcrc | (retval << 1); +} + + {% endif %} {% endfor %} diff --git a/umsg_gen/umsg_gen/templates/msg.h.j2 b/umsg_gen/umsg_gen/templates/msg.h.j2 index b4beb96..e59d765 100644 --- a/umsg_gen/umsg_gen/templates/msg.h.j2 +++ b/umsg_gen/umsg_gen/templates/msg.h.j2 @@ -89,6 +89,11 @@ uint8_t umsg_{{prefix}}_peek(umsg_{{prefix}}_t* data); //please take care that the messages are build properly to avoid padding issues if the messages are opened on different system uint32_t umsg_{{prefix}}_serialize(umsg_{{prefix}}_t* data, uint8_t* buffer); uint8_t umsg_{{prefix}}_deserialize(umsg_{{prefix}}_t* data,uint8_t* buffer); // this function includes check that the message type is correct + +uint32_t umsg_{{prefix}}_serialize_CRC(umsg_{{prefix}}_t* data, uint8_t* buffer); +uint8_t umsg_{{prefix}}_deserialize_CRC(umsg_{{prefix}}_t* data,uint8_t* buffer); // this function includes check that the message type is correct + + {% endif %} {% endfor %} diff --git a/umsg_lib/core/src/umsg.c b/umsg_lib/core/src/umsg.c deleted file mode 100644 index 4fb8d8b..0000000 --- a/umsg_lib/core/src/umsg.c +++ /dev/null @@ -1,69 +0,0 @@ -// -// Created by A.Pabouctsidis on 9/6/2022. -// - -#include -#include -#include - -umsg_sub_handle_t umsg_subscribe(umsg_msg_metadata_t* msg, uint16_t prescaler, uint32_t size, uint8_t length, uint8_t ch_id) -{ - if(msg->sub_list == NULL) - { - msg->msg_value = umsg_port_malloc(size); - - msg->sub_list = umsg_port_malloc(sizeof(umsg_sub_t)); - msg->sub_list->sub_handle = umsg_port_create(size,length); - msg->sub_list->prescaler = prescaler; - msg->sub_list->length = length; - msg->sub_list->channel = ch_id; - msg->sub_list->next_sub = NULL; - return msg->sub_list->sub_handle; - } - else - { - umsg_sub_t* sub = msg->sub_list; - while(sub->next_sub != NULL) - { - sub = sub->next_sub; - } - sub->next_sub = umsg_port_malloc(sizeof(umsg_sub_t)); - sub = sub->next_sub; - sub->sub_handle = umsg_port_create(size,length); - sub->prescaler = prescaler; - sub->length = length; - sub->channel = ch_id; - sub->next_sub = NULL; - return sub->sub_handle; - } -} - -void umsg_publish(umsg_msg_metadata_t* msg, void* data, uint8_t ch_id) -{ - msg->msg_value = data; - msg->counter++; - umsg_sub_t* sub = msg->sub_list; - while(sub != NULL) - { - if(msg->counter % sub->prescaler == 0 && sub->channel == ch_id) - { - umsg_port_send(sub, data); - } - sub = sub->next_sub; - } -} - -uint8_t umsg_receive(umsg_sub_handle_t queue, void* data, uint32_t timeout) -{ - return umsg_port_receive(queue, data, timeout); -} - -uint8_t umsg_peek(umsg_msg_metadata_t* msg, void* data, uint32_t size) -{ - if(msg->counter > 0) - { - memcpy(data, msg->msg_value, size); - return 1; - } - return 0; -} \ No newline at end of file From 43ddd126e3d034dbbded01a7b1c491472f6e3262 Mon Sep 17 00:00:00 2001 From: Michal Reiser Date: Tue, 26 Nov 2024 13:40:31 +0100 Subject: [PATCH 10/16] added structure to conversion of messages to serialized and not serialized form --- FreeRTOSConfig.h | 133 ++-- tests/freertos/test_length.c | 91 ++- tests/freertos/test_multi_channels.c | 91 ++- tests/freertos/test_peek.c | 78 ++- tests/freertos/test_prescaler.c | 82 ++- tests/freertos/test_single_pub_multi_sub.c | 72 +-- tests/freertos/test_single_pub_sub.c | 42 +- tests/freertos/test_types.c | 392 ++++++------ tests/freertos/test_unused_messages.c | 42 +- tests/graph/application/communication.c | 87 ++- tests/graph/application/robot_control.c | 70 +-- tests/graph/drivers/actuators/motor_driver.c | 52 +- tests/graph/drivers/actuators/servo_driver.c | 34 +- tests/graph/drivers/other/lighting_driver.c | 40 +- .../graph/drivers/sensors/barometer_driver.c | 26 +- tests/graph/drivers/sensors/imu_driver.c | 26 +- tests/graph/drivers/sensors/sonar_sensor.c | 26 +- tests/graph/modules/attitude_estimation.c | 38 +- umsg_gen/umsg_gen/core/inc/umsg.h | 29 +- umsg_gen/umsg_gen/core/inc/umsg_port.h | 10 +- umsg_gen/umsg_gen/core/inc/umsg_types.h | 2 +- umsg_gen/umsg_gen/core/src/port_freertos.c | 76 +-- umsg_gen/umsg_gen/core/src/port_posix.c | 19 +- umsg_gen/umsg_gen/core/src/umsg.c | 172 +++--- umsg_gen/umsg_gen/templates/log_parser.cpp.j2 | 35 +- umsg_gen/umsg_gen/templates/msg.c.j2 | 47 +- umsg_gen/umsg_gen/templates/msg.h.j2 | 73 +-- umsg_gen/umsg_gen/templates/msg_classes.c.j2 | 1 + umsg_gen/umsg_gen/templates/msg_classes.h.j2 | 110 +++- umsg_gen/umsg_gen/umsg_gen.py | 8 +- umsg_lib/core/inc/umsg.h | 26 +- umsg_lib/core/inc/umsg_port.h | 10 +- umsg_lib/core/inc/umsg_types.h | 2 +- umsg_lib/core/src/port_freertos.c | 76 +-- umsg_lib/core/src/port_posix.c | 19 +- umsg_lib/inc/umsg_battery.h | 36 +- umsg_lib/inc/umsg_classes.h | 14 +- umsg_lib/inc/umsg_control.h | 32 +- umsg_lib/inc/umsg_example.h | 63 +- umsg_lib/inc/umsg_sensors.h | 56 +- umsg_lib/inc/umsg_test.h | 206 +++---- umsg_lib/inc/umsg_unused.h | 54 +- umsg_lib/src/battery.c | 81 +-- umsg_lib/src/control.c | 81 +-- umsg_lib/src/example.c | 164 +++-- umsg_lib/src/sensors.c | 164 +++-- umsg_lib/src/test.c | 579 ++++++++---------- umsg_lib/src/unused.c | 164 +++-- 48 files changed, 1740 insertions(+), 2091 deletions(-) create mode 100644 umsg_gen/umsg_gen/templates/msg_classes.c.j2 diff --git a/FreeRTOSConfig.h b/FreeRTOSConfig.h index dc3b0bb..16d4b55 100644 --- a/FreeRTOSConfig.h +++ b/FreeRTOSConfig.h @@ -37,52 +37,55 @@ * https://www.FreeRTOS.org/a00110.html *----------------------------------------------------------*/ -#define configUSE_PREEMPTION 1 -#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 -#define configUSE_IDLE_HOOK 0 -#define configUSE_TICK_HOOK 0 -#define configUSE_DAEMON_TASK_STARTUP_HOOK 1 -#define configTICK_RATE_HZ ( 100 ) /* In this non-real time simulated environment the tick frequency has to be at least a multiple of the Win32 tick frequency, and therefore very slow. */ -#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 70 ) /* In this simulated case, the stack only has to hold one small structure as the real stack is part of the win32 thread. */ -#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 65 * 1024 ) ) -#define configMAX_TASK_NAME_LEN ( 12 ) -#define configUSE_TRACE_FACILITY 0 -#define configUSE_16_BIT_TICKS 0 -#define configIDLE_SHOULD_YIELD 1 -#define configUSE_MUTEXES 1 -#define configCHECK_FOR_STACK_OVERFLOW 0 -#define configUSE_RECURSIVE_MUTEXES 1 -#define configQUEUE_REGISTRY_SIZE 20 -#define configUSE_APPLICATION_TASK_TAG 1 -#define configUSE_COUNTING_SEMAPHORES 1 -#define configUSE_ALTERNATIVE_API 0 -#define configUSE_QUEUE_SETS 1 -#define configUSE_TASK_NOTIFICATIONS 1 -#define configSUPPORT_STATIC_ALLOCATION 0 +#define configUSE_PREEMPTION 1 +#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 +#define configUSE_IDLE_HOOK 0 +#define configUSE_TICK_HOOK 0 +#define configUSE_DAEMON_TASK_STARTUP_HOOK 1 +#define configTICK_RATE_HZ \ + (100) /* In this non-real time simulated environment the tick frequency has to be at least a multiple of the Win32 tick frequency, and therefore very slow. \ + */ +#define configMINIMAL_STACK_SIZE \ + ((unsigned short)70) /* In this simulated case, the stack only has to hold one small structure as the real stack is part of the win32 thread. */ +#define configTOTAL_HEAP_SIZE ((size_t)(65 * 1024)) +#define configMAX_TASK_NAME_LEN (12) +#define configUSE_TRACE_FACILITY 0 +#define configUSE_16_BIT_TICKS 0 +#define configIDLE_SHOULD_YIELD 1 +#define configUSE_MUTEXES 1 +#define configCHECK_FOR_STACK_OVERFLOW 0 +#define configUSE_RECURSIVE_MUTEXES 1 +#define configQUEUE_REGISTRY_SIZE 20 +#define configUSE_APPLICATION_TASK_TAG 1 +#define configUSE_COUNTING_SEMAPHORES 1 +#define configUSE_ALTERNATIVE_API 0 +#define configUSE_QUEUE_SETS 1 +#define configUSE_TASK_NOTIFICATIONS 1 +#define configSUPPORT_STATIC_ALLOCATION 0 /* Software timer related configuration options. The maximum possible task priority is configMAX_PRIORITIES - 1. The priority of the timer task is deliberately set higher to ensure it is correctly capped back to configMAX_PRIORITIES - 1. */ -#define configUSE_TIMERS 0 -#define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) -#define configTIMER_QUEUE_LENGTH 20 -#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 ) +#define configUSE_TIMERS 0 +#define configTIMER_TASK_PRIORITY (configMAX_PRIORITIES - 1) +#define configTIMER_QUEUE_LENGTH 20 +#define configTIMER_TASK_STACK_DEPTH (configMINIMAL_STACK_SIZE * 2) -#define configMAX_PRIORITIES ( 7 ) +#define configMAX_PRIORITIES (7) /* Run time stats gathering configuration options. */ -#define configGENERATE_RUN_TIME_STATS 0 +#define configGENERATE_RUN_TIME_STATS 0 /* Co-routine related configuration options. */ -#define configUSE_CO_ROUTINES 0 -#define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) +#define configUSE_CO_ROUTINES 0 +#define configMAX_CO_ROUTINE_PRIORITIES (2) /* This demo can use of one or more example stats formatting functions. These format the raw data provided by the uxTaskGetSystemState() function in to human readable ASCII form. See the notes in the implementation of vTaskList() within FreeRTOS/Source/tasks.c for limitations. */ -#define configUSE_STATS_FORMATTING_FUNCTIONS 0 +#define configUSE_STATS_FORMATTING_FUNCTIONS 0 /* Enables the test whereby a stack larger than the total heap size is requested. */ @@ -91,31 +94,31 @@ requested. */ /* Set the following definitions to 1 to include the API function, or zero to exclude the API function. In most cases the linker will remove unused functions anyway. */ -#define INCLUDE_vTaskPrioritySet 1 -#define INCLUDE_uxTaskPriorityGet 1 -#define INCLUDE_vTaskDelete 1 -#define INCLUDE_vTaskCleanUpResources 0 -#define INCLUDE_vTaskSuspend 1 -#define INCLUDE_vTaskDelayUntil 1 -#define INCLUDE_vTaskDelay 1 -#define INCLUDE_uxTaskGetStackHighWaterMark 1 -#define INCLUDE_uxTaskGetStackHighWaterMark2 1 -#define INCLUDE_xTaskGetSchedulerState 1 -#define INCLUDE_xTimerGetTimerDaemonTaskHandle 1 -#define INCLUDE_xTaskGetIdleTaskHandle 1 -#define INCLUDE_xTaskGetHandle 1 -#define INCLUDE_eTaskGetState 1 -#define INCLUDE_xSemaphoreGetMutexHolder 1 -#define INCLUDE_xTimerPendFunctionCall 0 -#define INCLUDE_xTaskAbortDelay 1 - -#define configINCLUDE_MESSAGE_BUFFER_AMP_DEMO 0 -#if ( configINCLUDE_MESSAGE_BUFFER_AMP_DEMO == 1 ) -extern void vGenerateCoreBInterrupt( void * xUpdatedMessageBuffer ); - #define sbSEND_COMPLETED( pxStreamBuffer ) vGenerateCoreBInterrupt( pxStreamBuffer ) +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskCleanUpResources 0 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 1 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_uxTaskGetStackHighWaterMark 1 +#define INCLUDE_uxTaskGetStackHighWaterMark2 1 +#define INCLUDE_xTaskGetSchedulerState 1 +#define INCLUDE_xTimerGetTimerDaemonTaskHandle 1 +#define INCLUDE_xTaskGetIdleTaskHandle 1 +#define INCLUDE_xTaskGetHandle 1 +#define INCLUDE_eTaskGetState 1 +#define INCLUDE_xSemaphoreGetMutexHolder 1 +#define INCLUDE_xTimerPendFunctionCall 0 +#define INCLUDE_xTaskAbortDelay 1 + +#define configINCLUDE_MESSAGE_BUFFER_AMP_DEMO 0 +#if (configINCLUDE_MESSAGE_BUFFER_AMP_DEMO == 1) +extern void vGenerateCoreBInterrupt(void* xUpdatedMessageBuffer); +#define sbSEND_COMPLETED(pxStreamBuffer) vGenerateCoreBInterrupt(pxStreamBuffer) #endif /* configINCLUDE_MESSAGE_BUFFER_AMP_DEMO */ -extern void vAssertCalled( unsigned long ulLine, const char * const pcFileName ); +extern void vAssertCalled(unsigned long ulLine, const char* const pcFileName); /* projCOVERAGE_TEST should be defined on the command line so this file can be used with multiple project configurations. If it is @@ -125,28 +128,28 @@ used with multiple project configurations. If it is #error projCOVERAGE_TEST should be defined to 1 or 0 on the command line. #endif -#if( projCOVERAGE_TEST == 1 ) +#if (projCOVERAGE_TEST == 1) /* Insert NOPs in empty decision paths to ensure both true and false paths - are being tested. */ - #define mtCOVERAGE_TEST_MARKER() __asm volatile( "NOP" ) + are being tested. */ +#define mtCOVERAGE_TEST_MARKER() __asm volatile("NOP") - /* Ensure the tick count overflows during the coverage test. */ - #define configINITIAL_TICK_COUNT 0xffffd800UL +/* Ensure the tick count overflows during the coverage test. */ +#define configINITIAL_TICK_COUNT 0xffffd800UL - /* Allows tests of trying to allocate more than the heap has free. */ - #define configUSE_MALLOC_FAILED_HOOK 0 +/* Allows tests of trying to allocate more than the heap has free. */ +#define configUSE_MALLOC_FAILED_HOOK 0 - /* To test builds that remove the static qualifier for debug builds. */ - #define portREMOVE_STATIC_QUALIFIER +/* To test builds that remove the static qualifier for debug builds. */ +#define portREMOVE_STATIC_QUALIFIER #else /* It is a good idea to define configASSERT() while developing. configASSERT() uses the same semantics as the standard C assert() macro. Don't define configASSERT() when performing code coverage tests though, as it is not intended to asserts() to fail, some some code is intended not to run if no errors are present. */ -#define configASSERT( x ) if( ( x ) == 0 ) +#define configASSERT(x) if ((x) == 0) -#define configUSE_MALLOC_FAILED_HOOK 0 +#define configUSE_MALLOC_FAILED_HOOK 0 /* Include the FreeRTOS+Trace FreeRTOS trace macro definitions. */ #endif diff --git a/tests/freertos/test_length.c b/tests/freertos/test_length.c index c1fa3ff..e4f6af8 100644 --- a/tests/freertos/test_length.c +++ b/tests/freertos/test_length.c @@ -4,60 +4,53 @@ #include #include -#define QUEUE_LENGTH 5 +#define QUEUE_LENGTH 5 static void main_task(void* params); -int main( void ) -{ - // single task which will publish messages and then read them back - xTaskCreate(main_task, "main_task", 1000, NULL, 1, NULL); - vTaskStartScheduler(); +int main(void) { + // single task which will publish messages and then read them back + xTaskCreate(main_task, "main_task", 1000, NULL, 1, NULL); + vTaskStartScheduler(); - return 0; + return 0; } -static void main_task(void* params) -{ - umsg_sub_handle_t sub_1 = umsg_test_uints_subscribe(1,1); // queue size of 1 (always latest message) - umsg_sub_handle_t sub_5 = umsg_test_uints_subscribe(1,QUEUE_LENGTH); // queue size of 5 (keeps 5 earliest messages) - umsg_test_uints_t msg_tx; - umsg_test_uints_t msg_rx; - while(1) { - // publish message 10 times - for(uint8_t counter = 1; counter <= 10; counter++) - { - msg_tx.u8 = counter; - umsg_test_uints_publish(&msg_tx); - vTaskDelay(pdMS_TO_TICKS(10)); - } - - // receive messages of sub1 untill timeout - while(umsg_test_uints_receive(sub_1,&msg_rx,0) == pdTRUE) - { - printf("Received message from queue size of 1: %d\n",msg_rx.u8); - } - - // value should be equal to last sent message - if(msg_rx.u8 != msg_tx.u8) - { - printf("Received message does not match last sent message!\n"); - exit(1); - } - - // receive messages of sub 5 untill timeout - while(umsg_test_uints_receive(sub_5,&msg_rx, pdMS_TO_TICKS(10)) == pdTRUE) - { - printf("Received message from queue size of 5: %d\n",msg_rx.u8); - } - - // counter should on reach to the size of queue. messages sent after are lost. - if(msg_rx.u8 != QUEUE_LENGTH) - { - printf("Received message does not match queue length!\n"); - exit(1); - } - - exit(0); +static void main_task(void* params) { + umsg_sub_handle_t sub_1 = umsg_test_uints_subscribe(1, 1); // queue size of 1 (always latest message) + umsg_sub_handle_t sub_5 = umsg_test_uints_subscribe(1, QUEUE_LENGTH); // queue size of 5 (keeps 5 earliest messages) + umsg_test_uints_t msg_tx; + umsg_test_uints_t msg_rx; + while (1) { + // publish message 10 times + for (uint8_t counter = 1; counter <= 10; counter++) { + msg_tx.u8 = counter; + umsg_test_uints_publish(&msg_tx); + vTaskDelay(pdMS_TO_TICKS(10)); } + + // receive messages of sub1 untill timeout + while (umsg_test_uints_receive(sub_1, &msg_rx, 0) == pdTRUE) { + printf("Received message from queue size of 1: %d\n", msg_rx.u8); + } + + // value should be equal to last sent message + if (msg_rx.u8 != msg_tx.u8) { + printf("Received message does not match last sent message!\n"); + exit(1); + } + + // receive messages of sub 5 untill timeout + while (umsg_test_uints_receive(sub_5, &msg_rx, pdMS_TO_TICKS(10)) == pdTRUE) { + printf("Received message from queue size of 5: %d\n", msg_rx.u8); + } + + // counter should on reach to the size of queue. messages sent after are lost. + if (msg_rx.u8 != QUEUE_LENGTH) { + printf("Received message does not match queue length!\n"); + exit(1); + } + + exit(0); + } } diff --git a/tests/freertos/test_multi_channels.c b/tests/freertos/test_multi_channels.c index 45dc051..5fd0ea0 100644 --- a/tests/freertos/test_multi_channels.c +++ b/tests/freertos/test_multi_channels.c @@ -4,59 +4,54 @@ #include #include -#define QUEUE_LENGTH 5 +#define QUEUE_LENGTH 5 static void main_task(void* params); -int main( void ) -{ - // single task which will publish messages and then read them back - xTaskCreate(main_task, "main_task", 1000, NULL, 1, NULL); - vTaskStartScheduler(); +int main(void) { + // single task which will publish messages and then read them back + xTaskCreate(main_task, "main_task", 1000, NULL, 1, NULL); + vTaskStartScheduler(); - return 0; + return 0; } -static void main_task(void* params) -{ - umsg_sub_handle_t sub_0 = umsg_test_uints_subscribe_ch(1,1,0); // subscribe ch 0 - umsg_sub_handle_t sub_1 = umsg_test_uints_subscribe_ch(1,1,1); // subscribe ch 1 - umsg_sub_handle_t sub_2 = umsg_test_uints_subscribe_ch(1,1,2); // subscribe ch 2 - umsg_test_uints_t msg_tx; - umsg_test_uints_t msg_rx; - while(1) { - - // send a message to each channel - msg_tx.u8 = 0x10; - umsg_test_uints_publish_ch(&msg_tx,0); - msg_tx.u8 = 0x20; - umsg_test_uints_publish_ch(&msg_tx,1); - msg_tx.u8 = 0x30; - umsg_test_uints_publish_ch(&msg_tx,2); - - // reach each channel and check if value matches - umsg_test_uints_receive(sub_0,&msg_rx,portMAX_DELAY); - if(msg_rx.u8 != 0x10) - { - printf("Received message does not match expected value!\n"); - exit(1); - } - - umsg_test_uints_receive(sub_1,&msg_rx,portMAX_DELAY); - if(msg_rx.u8 != 0x20) - { - printf("Received message does not match expected value!\n"); - exit(1); - } - - umsg_test_uints_receive(sub_2,&msg_rx,portMAX_DELAY); - if(msg_rx.u8 != 0x30) - { - printf("Received message does not match expected value!\n"); - exit(1); - } - - printf("All tasks received the message!\n"); - exit(0); +static void main_task(void* params) { + umsg_sub_handle_t sub_0 = umsg_test_uints_subscribe_ch(1, 1, 0); // subscribe ch 0 + umsg_sub_handle_t sub_1 = umsg_test_uints_subscribe_ch(1, 1, 1); // subscribe ch 1 + umsg_sub_handle_t sub_2 = umsg_test_uints_subscribe_ch(1, 1, 2); // subscribe ch 2 + umsg_test_uints_t msg_tx; + umsg_test_uints_t msg_rx; + while (1) { + + // send a message to each channel + msg_tx.u8 = 0x10; + umsg_test_uints_publish_ch(&msg_tx, 0); + msg_tx.u8 = 0x20; + umsg_test_uints_publish_ch(&msg_tx, 1); + msg_tx.u8 = 0x30; + umsg_test_uints_publish_ch(&msg_tx, 2); + + // reach each channel and check if value matches + umsg_test_uints_receive(sub_0, &msg_rx, portMAX_DELAY); + if (msg_rx.u8 != 0x10) { + printf("Received message does not match expected value!\n"); + exit(1); } + + umsg_test_uints_receive(sub_1, &msg_rx, portMAX_DELAY); + if (msg_rx.u8 != 0x20) { + printf("Received message does not match expected value!\n"); + exit(1); + } + + umsg_test_uints_receive(sub_2, &msg_rx, portMAX_DELAY); + if (msg_rx.u8 != 0x30) { + printf("Received message does not match expected value!\n"); + exit(1); + } + + printf("All tasks received the message!\n"); + exit(0); + } } diff --git a/tests/freertos/test_peek.c b/tests/freertos/test_peek.c index 496bebe..67fee3b 100644 --- a/tests/freertos/test_peek.c +++ b/tests/freertos/test_peek.c @@ -9,56 +9,50 @@ static void pub_task(void* params); static void sub_task(void* params); -int main( void ) -{ - xTaskCreate(pub_task, "pub_task", 1000, NULL, 2, NULL); - xTaskCreate(sub_task, "sub_task", 1000, NULL, 1, NULL); - vTaskStartScheduler(); +int main(void) { + xTaskCreate(pub_task, "pub_task", 1000, NULL, 2, NULL); + xTaskCreate(sub_task, "sub_task", 1000, NULL, 1, NULL); + vTaskStartScheduler(); - return 0; + return 0; } -static void sub_task(void* params) -{ - umsg_sub_handle_t sub = umsg_sensors_imu_subscribe(1,1); - umsg_sensors_imu_t msg; - umsg_test_bools_t msg_bools; - while(1) { - umsg_sensors_imu_receive(sub,&msg,portMAX_DELAY); +static void sub_task(void* params) { + umsg_sub_handle_t sub = umsg_sensors_imu_subscribe(1, 1); + umsg_sensors_imu_t msg; + umsg_test_bools_t msg_bools; + while (1) { + umsg_sensors_imu_receive(sub, &msg, portMAX_DELAY); - // peek imu data and check it matches - umsg_sensors_imu_t peek_msg; - umsg_sensors_imu_peek(&peek_msg); + // peek imu data and check it matches + umsg_sensors_imu_t peek_msg; + umsg_sensors_imu_peek(&peek_msg); - // empty peek - umsg_test_bools_peek(&msg_bools); - - if(memcmp(&msg,&peek_msg,sizeof(umsg_sensors_imu_t)) != 0) - { - printf("Peeked message does not match received message!"); - exit(1); - } + // empty peek + umsg_test_bools_peek(&msg_bools); - exit(0); + if (memcmp(&msg, &peek_msg, sizeof(umsg_sensors_imu_t)) != 0) { + printf("Peeked message does not match received message!"); + exit(1); } -} - -static void pub_task(void* params) -{ - umsg_sensors_imu_t imu_data = {.accel= {1,2,3}, .gyro = {4,5,6}, .temperature = 66}; - while(1) - { - umsg_sensors_imu_publish(&imu_data); - // peek from subscriber and check it matches - umsg_sensors_imu_t peeked_msg; - umsg_sensors_imu_peek(&peeked_msg); - if(memcmp(&imu_data,&peeked_msg,sizeof(umsg_sensors_imu_t)) != 0) - { - printf("Peeked message does not match published message!"); - exit(1); - } + exit(0); + } +} - vTaskDelay(pdMS_TO_TICKS(10)); +static void pub_task(void* params) { + umsg_sensors_imu_t imu_data = {.accel = {1, 2, 3}, .gyro = {4, 5, 6}, .temperature = 66}; + while (1) { + umsg_sensors_imu_publish(&imu_data); + + // peek from subscriber and check it matches + umsg_sensors_imu_t peeked_msg; + umsg_sensors_imu_peek(&peeked_msg); + if (memcmp(&imu_data, &peeked_msg, sizeof(umsg_sensors_imu_t)) != 0) { + printf("Peeked message does not match published message!"); + exit(1); } + + vTaskDelay(pdMS_TO_TICKS(10)); + } } diff --git a/tests/freertos/test_prescaler.c b/tests/freertos/test_prescaler.c index 080f2de..401116b 100644 --- a/tests/freertos/test_prescaler.c +++ b/tests/freertos/test_prescaler.c @@ -7,57 +7,51 @@ static void pub_task(void* params); static void sub_task(void* params); -const uint8_t PRESCALERS[] = {1,5,10}; -uint8_t received_msgs; -int main( void ) -{ - // publisher task lower priority than subscriber task to make they receive the first message - xTaskCreate(pub_task, "pub_task", 1000, NULL, 1, NULL); - xTaskCreate(sub_task, "sub_task_prescaler_1", 1000, (void*)&PRESCALERS[0], 2, NULL); - xTaskCreate(sub_task, "sub_task_prescaler_2", 1000, (void*)&PRESCALERS[1], 2, NULL); - xTaskCreate(sub_task, "sub_task_prescaler_5", 1000, (void*)&PRESCALERS[2], 2, NULL); - vTaskStartScheduler(); +const uint8_t PRESCALERS[] = {1, 5, 10}; +uint8_t received_msgs; +int main(void) { + // publisher task lower priority than subscriber task to make they receive the first message + xTaskCreate(pub_task, "pub_task", 1000, NULL, 1, NULL); + xTaskCreate(sub_task, "sub_task_prescaler_1", 1000, (void*)&PRESCALERS[0], 2, NULL); + xTaskCreate(sub_task, "sub_task_prescaler_2", 1000, (void*)&PRESCALERS[1], 2, NULL); + xTaskCreate(sub_task, "sub_task_prescaler_5", 1000, (void*)&PRESCALERS[2], 2, NULL); + vTaskStartScheduler(); - return 0; + return 0; } -static void sub_task(void* params) -{ - uint8_t prescaler = *(uint8_t*)params; - umsg_sub_handle_t sub = umsg_test_uints_subscribe(prescaler,1); - umsg_test_uints_t msg; - while(1) { - // receive first msg - umsg_test_uints_receive(sub,&msg,portMAX_DELAY); +static void sub_task(void* params) { + uint8_t prescaler = *(uint8_t*)params; + umsg_sub_handle_t sub = umsg_test_uints_subscribe(prescaler, 1); + umsg_test_uints_t msg; + while (1) { + // receive first msg + umsg_test_uints_receive(sub, &msg, portMAX_DELAY); - // check u8 value matches prescaler - if(msg.u8 != prescaler) - { - printf("Received message does not match prescaler!\n"); - exit(1); - } - printf("Received message matches prescaler! Prescaler: %d\n",prescaler); - received_msgs++; - vTaskSuspend(NULL); + // check u8 value matches prescaler + if (msg.u8 != prescaler) { + printf("Received message does not match prescaler!\n"); + exit(1); } + printf("Received message matches prescaler! Prescaler: %d\n", prescaler); + received_msgs++; + vTaskSuspend(NULL); + } } -static void pub_task(void* params) -{ - umsg_test_uints_t msg = {0}; - uint8_t counter = 0; - while(1) - { - counter++; - // store message counter in u8 field - msg.u8 = counter; - umsg_test_uints_publish(&msg); - vTaskDelay(pdMS_TO_TICKS(10)); +static void pub_task(void* params) { + umsg_test_uints_t msg = {0}; + uint8_t counter = 0; + while (1) { + counter++; + // store message counter in u8 field + msg.u8 = counter; + umsg_test_uints_publish(&msg); + vTaskDelay(pdMS_TO_TICKS(10)); - if(received_msgs == 3) - { - printf("All tasks received the message!\n"); - exit(0); - } + if (received_msgs == 3) { + printf("All tasks received the message!\n"); + exit(0); } + } } diff --git a/tests/freertos/test_single_pub_multi_sub.c b/tests/freertos/test_single_pub_multi_sub.c index 33e2ea2..ca20b97 100644 --- a/tests/freertos/test_single_pub_multi_sub.c +++ b/tests/freertos/test_single_pub_multi_sub.c @@ -9,49 +9,41 @@ static void sub_task(void* params); static uint8_t received_flags[3]; -int main( void ) -{ - xTaskCreate(pub_task, "pub_task", 1000, NULL, 1, NULL); - xTaskCreate(sub_task, "sub_task1", 1000, "1", 2, NULL); - xTaskCreate(sub_task, "sub_task2", 1000, "2", 2, NULL); - xTaskCreate(sub_task, "sub_task3", 1000, "3", 2, NULL); - vTaskStartScheduler(); - - return 0; +int main(void) { + xTaskCreate(pub_task, "pub_task", 1000, NULL, 1, NULL); + xTaskCreate(sub_task, "sub_task1", 1000, "1", 2, NULL); + xTaskCreate(sub_task, "sub_task2", 1000, "2", 2, NULL); + xTaskCreate(sub_task, "sub_task3", 1000, "3", 2, NULL); + vTaskStartScheduler(); + + return 0; } -static void sub_task(void* params) -{ - umsg_sub_handle_t sub = umsg_sensors_imu_subscribe(1,1); - umsg_sensors_imu_t msg; - while(1) { - umsg_sensors_imu_receive(sub,&msg,portMAX_DELAY); - printf("Received IMU Data! Task # %s \n", (char*)params); - received_flags[atoi((char*)params)-1] = 1; - } +static void sub_task(void* params) { + umsg_sub_handle_t sub = umsg_sensors_imu_subscribe(1, 1); + umsg_sensors_imu_t msg; + while (1) { + umsg_sensors_imu_receive(sub, &msg, portMAX_DELAY); + printf("Received IMU Data! Task # %s \n", (char*)params); + received_flags[atoi((char*)params) - 1] = 1; + } } -static void pub_task(void* params) -{ - umsg_sensors_imu_t imu_data = {.accel= {1,2,3}, .gyro = {4,5,6}, .temperature = 66}; - uint8_t send_count = 0; - while(1) - { - umsg_sensors_imu_publish(&imu_data); - send_count++; - vTaskDelay(pdMS_TO_TICKS(5)); - - // check if all tasks received the message - if(received_flags[0] && received_flags[1] && received_flags[2]) - { - printf("All tasks received the message!"); - exit(0); - } - else - { - printf("Not all tasks received the message!"); - exit(1); - } +static void pub_task(void* params) { + umsg_sensors_imu_t imu_data = {.accel = {1, 2, 3}, .gyro = {4, 5, 6}, .temperature = 66}; + uint8_t send_count = 0; + while (1) { + umsg_sensors_imu_publish(&imu_data); + send_count++; + vTaskDelay(pdMS_TO_TICKS(5)); + + // check if all tasks received the message + if (received_flags[0] && received_flags[1] && received_flags[2]) { + printf("All tasks received the message!"); + exit(0); + } else { + printf("Not all tasks received the message!"); + exit(1); } + } } - diff --git a/tests/freertos/test_single_pub_sub.c b/tests/freertos/test_single_pub_sub.c index ef4dcb1..da3c2fb 100644 --- a/tests/freertos/test_single_pub_sub.c +++ b/tests/freertos/test_single_pub_sub.c @@ -7,32 +7,28 @@ static void pub_task(void* params); static void sub_task(void* params); -int main( void ) -{ - xTaskCreate(pub_task, "pub_task", 1000, NULL, 1, NULL); - xTaskCreate(sub_task, "sub_task", 1000, NULL, 1, NULL); - vTaskStartScheduler(); +int main(void) { + xTaskCreate(pub_task, "pub_task", 1000, NULL, 1, NULL); + xTaskCreate(sub_task, "sub_task", 1000, NULL, 1, NULL); + vTaskStartScheduler(); - return 0; + return 0; } -static void sub_task(void* params) -{ - umsg_sub_handle_t sub = umsg_sensors_imu_subscribe(1,1); - umsg_sensors_imu_t msg; - while(1) { - umsg_sensors_imu_receive(sub,&msg,portMAX_DELAY); - printf("Received IMU Data!"); - exit(0); - } +static void sub_task(void* params) { + umsg_sub_handle_t sub = umsg_sensors_imu_subscribe(1, 1); + umsg_sensors_imu_t msg; + while (1) { + umsg_sensors_imu_receive(sub, &msg, portMAX_DELAY); + printf("Received IMU Data!"); + exit(0); + } } -static void pub_task(void* params) -{ - umsg_sensors_imu_t imu_data = {.accel= {1,2,3}, .gyro = {4,5,6}, .temperature = 66}; - while(1) - { - umsg_sensors_imu_publish(&imu_data); - vTaskDelay(pdMS_TO_TICKS(10)); - } +static void pub_task(void* params) { + umsg_sensors_imu_t imu_data = {.accel = {1, 2, 3}, .gyro = {4, 5, 6}, .temperature = 66}; + while (1) { + umsg_sensors_imu_publish(&imu_data); + vTaskDelay(pdMS_TO_TICKS(10)); + } } diff --git a/tests/freertos/test_types.c b/tests/freertos/test_types.c index f4949ae..fc57f2b 100644 --- a/tests/freertos/test_types.c +++ b/tests/freertos/test_types.c @@ -6,236 +6,202 @@ #include static umsg_test_ints_t msg_ints_ref = { - .i8 = -1, - .i16 = -2, - .i32 = -3, - .i64 = -4, - .i8array = {-5,-6,-7}, - .i16array = {-8,-9,-10}, - .i32array = {-11,-12,-13}, - .i64array = {-14,-15,-16} -}; + .i8 = -1, .i16 = -2, .i32 = -3, .i64 = -4, .i8array = {-5, -6, -7}, .i16array = {-8, -9, -10}, .i32array = {-11, -12, -13}, .i64array = {-14, -15, -16}}; static umsg_test_uints_t msg_uints_ref = { - .u8 = 1, - .u16 = 2, - .u32 = 3, - .u64 = 4, - .u8array = {5,6,7}, - .u16array = {8,9,10}, - .u32array = {11,12,13}, - .u64array = {14,15,16} -}; -static umsg_test_floats_t msg_floats_ref = { - .single = 1.1f, - .double_var = 2.2, - .single_array = {3.3f,4.4f,5.5f}, - .double_array = {6.6,7.7,8.8} + .u8 = 1, .u16 = 2, .u32 = 3, .u64 = 4, .u8array = {5, 6, 7}, .u16array = {8, 9, 10}, .u32array = {11, 12, 13}, .u64array = {14, 15, 16}}; +static umsg_test_floats_t msg_floats_ref = {.single = 1.1f, .double_var = 2.2, .single_array = {3.3f, 4.4f, 5.5f}, .double_array = {6.6, 7.7, 8.8} }; -static umsg_test_strings_t msg_strings_ref = { - .single = 'a', - .array = "Hello World!" -}; -static umsg_test_bools_t msg_bools_ref = { - .a = true, - .b = {false, true, false} -}; +static umsg_test_strings_t msg_strings_ref = {.single = 'a', .array = "Hello World!"}; +static umsg_test_bools_t msg_bools_ref = {.a = true, .b = {false, true, false}}; -static umsg_test_enums_t msg_enums_ref = { - .single_enum = ENUM_A, - .enum_array = {ENUM_A, ENUM_B, ENUM_C} -}; +static umsg_test_enums_t msg_enums_ref = {.single_enum = ENUM_A, .enum_array = {ENUM_A, ENUM_B, ENUM_C}}; static umsg_test_bitfield_t msg_bitfield_ref = { - .a = 1, - .b = 2, - .c = 3, + .a = 1, + .b = 2, + .c = 3, }; static void pub_task(void* params); static void sub_task(void* params); -int main( void ) -{ +int main(void) { - xTaskCreate(pub_task, "pub_task", 1000, NULL, 1, NULL); - xTaskCreate(sub_task, "sub_task", 1000, NULL, 1, NULL); - vTaskStartScheduler(); + xTaskCreate(pub_task, "pub_task", 1000, NULL, 1, NULL); + xTaskCreate(sub_task, "sub_task", 1000, NULL, 1, NULL); + vTaskStartScheduler(); - return 0; + return 0; } -static void sub_task(void* params) -{ - umsg_sub_handle_t sub_uints = umsg_test_uints_subscribe(1,1); - umsg_sub_handle_t sub_ints = umsg_test_ints_subscribe(1,1); - umsg_sub_handle_t sub_floats = umsg_test_floats_subscribe(1,1); - umsg_sub_handle_t sub_strings = umsg_test_strings_subscribe(1,1); - umsg_sub_handle_t sub_bools = umsg_test_bools_subscribe(1,1); - umsg_sub_handle_t sub_enums = umsg_test_enums_subscribe(1,1); - - - umsg_test_uints_t msg_uints; - umsg_test_ints_t msg_ints; - umsg_test_floats_t msg_floats; - umsg_test_strings_t msg_strings; - umsg_test_bools_t msg_bools; - umsg_test_enums_t msg_enums; - - while(1) { - uint8_t flag = 0; - flag |= umsg_test_uints_receive(sub_uints,&msg_uints, pdMS_TO_TICKS(100)); - flag |= umsg_test_ints_receive(sub_ints,&msg_ints,pdMS_TO_TICKS(100)); - flag |= umsg_test_floats_receive(sub_floats,&msg_floats,pdMS_TO_TICKS(100)); - flag |= umsg_test_strings_receive(sub_strings,&msg_strings,pdMS_TO_TICKS(100)); - flag |= umsg_test_bools_receive(sub_bools,&msg_bools,pdMS_TO_TICKS(100)); - flag |= umsg_test_enums_receive(sub_enums,&msg_enums,portMAX_DELAY); - - if(flag == 1) { - printf("Received all messages!\n"); - } - else { - printf("failed to receive all messages\n"); - exit(1); - } - - // check messages match reference - if (msg_uints.u8 != msg_uints_ref.u8) { - printf("u8 mismatch!\n"); - exit(1); - } - if (msg_uints.u16 != msg_uints_ref.u16) { - printf("u16 mismatch!\n"); - exit(1); - } - if (msg_uints.u32 != msg_uints_ref.u32) { - printf("u32 mismatch!\n"); - exit(1); - } - if (msg_uints.u64 != msg_uints_ref.u64) { - printf("u64 mismatch!\n"); - exit(1); - } - for (int i = 0; i < 3; i++) { - if (msg_uints.u8array[i] != msg_uints_ref.u8array[i]) { - printf("u8array mismatch!\n"); - exit(1); - } - if (msg_uints.u16array[i] != msg_uints_ref.u16array[i]) { - printf("u16array mismatch!\n"); - exit(1); - } - if (msg_uints.u32array[i] != msg_uints_ref.u32array[i]) { - printf("u32array mismatch!\n"); - exit(1); - } - if (msg_uints.u64array[i] != msg_uints_ref.u64array[i]) { - printf("u64array mismatch!\n"); - exit(1); - } - } - - if (msg_ints.i8 != msg_ints_ref.i8) { - printf("i8 mismatch!\n"); - exit(1); - } - if (msg_ints.i16 != msg_ints_ref.i16) { - printf("i16 mismatch!\n"); - exit(1); - } - if (msg_ints.i32 != msg_ints_ref.i32) { - printf("i32 mismatch!\n"); - exit(1); - } - if (msg_ints.i64 != msg_ints_ref.i64) { - printf("i64 mismatch!\n"); - exit(1); - } - for (int i = 0; i < 3; i++) { - if (msg_ints.i8array[i] != msg_ints_ref.i8array[i]) { - printf("i8array mismatch!\n"); - exit(1); - } - if (msg_ints.i16array[i] != msg_ints_ref.i16array[i]) { - printf("i16array mismatch!\n"); - exit(1); - } - if (msg_ints.i32array[i] != msg_ints_ref.i32array[i]) { - printf("i32array mismatch!\n"); - exit(1); - } - if (msg_ints.i64array[i] != msg_ints_ref.i64array[i]) { - printf("i64array mismatch!\n"); - exit(1); - } - } - - if (msg_floats.single != msg_floats_ref.single) { - printf("single mismatch!\n"); - exit(1); - } - if (msg_floats.double_var != msg_floats_ref.double_var) { - printf("double mismatch!\n"); - exit(1); - } - for (int i = 0; i < 3; i++) { - if (msg_floats.single_array[i] != msg_floats_ref.single_array[i]) { - printf("single_array mismatch!\n"); - exit(1); - } - if (msg_floats.double_array[i] != msg_floats_ref.double_array[i]) { - printf("double_array mismatch!\n"); - exit(1); - } - } - - if (msg_strings.single != msg_strings_ref.single) { - printf("single mismatch!\n"); - exit(1); - } - if (strcmp(msg_strings.array,msg_strings_ref.array) != 0) { - printf("array mismatch!\n"); - exit(1); - } - - if (msg_bools.a != msg_bools_ref.a) { - printf("a mismatch!\n"); - exit(1); - } - for (int i = 0; i < 3; i++) { - if (msg_bools.b[i] != msg_bools_ref.b[i]) { - printf("b mismatch!\n"); - exit(1); - } - } - - if (msg_enums.single_enum != msg_enums_ref.single_enum) { - printf("single_enum mismatch!\n"); - exit(1); - } - for (int i = 0; i < 3; i++) { - if (msg_enums.enum_array[i] != msg_enums_ref.enum_array[i]) { - printf("enum_array mismatch!\n"); - exit(1); - } - } - - printf("All messages match reference!\n"); - exit(0); +static void sub_task(void* params) { + umsg_sub_handle_t sub_uints = umsg_test_uints_subscribe(1, 1); + umsg_sub_handle_t sub_ints = umsg_test_ints_subscribe(1, 1); + umsg_sub_handle_t sub_floats = umsg_test_floats_subscribe(1, 1); + umsg_sub_handle_t sub_strings = umsg_test_strings_subscribe(1, 1); + umsg_sub_handle_t sub_bools = umsg_test_bools_subscribe(1, 1); + umsg_sub_handle_t sub_enums = umsg_test_enums_subscribe(1, 1); + + + umsg_test_uints_t msg_uints; + umsg_test_ints_t msg_ints; + umsg_test_floats_t msg_floats; + umsg_test_strings_t msg_strings; + umsg_test_bools_t msg_bools; + umsg_test_enums_t msg_enums; + + while (1) { + uint8_t flag = 0; + flag |= umsg_test_uints_receive(sub_uints, &msg_uints, pdMS_TO_TICKS(100)); + flag |= umsg_test_ints_receive(sub_ints, &msg_ints, pdMS_TO_TICKS(100)); + flag |= umsg_test_floats_receive(sub_floats, &msg_floats, pdMS_TO_TICKS(100)); + flag |= umsg_test_strings_receive(sub_strings, &msg_strings, pdMS_TO_TICKS(100)); + flag |= umsg_test_bools_receive(sub_bools, &msg_bools, pdMS_TO_TICKS(100)); + flag |= umsg_test_enums_receive(sub_enums, &msg_enums, portMAX_DELAY); + + if (flag == 1) { + printf("Received all messages!\n"); + } else { + printf("failed to receive all messages\n"); + exit(1); } -} -static void pub_task(void* params) -{ - while(1) - { - umsg_test_uints_publish(&msg_uints_ref); - umsg_test_ints_publish(&msg_ints_ref); - umsg_test_floats_publish(&msg_floats_ref); - umsg_test_strings_publish(&msg_strings_ref); - umsg_test_bools_publish(&msg_bools_ref); - umsg_test_enums_publish(&msg_enums_ref); + // check messages match reference + if (msg_uints.u8 != msg_uints_ref.u8) { + printf("u8 mismatch!\n"); + exit(1); + } + if (msg_uints.u16 != msg_uints_ref.u16) { + printf("u16 mismatch!\n"); + exit(1); + } + if (msg_uints.u32 != msg_uints_ref.u32) { + printf("u32 mismatch!\n"); + exit(1); + } + if (msg_uints.u64 != msg_uints_ref.u64) { + printf("u64 mismatch!\n"); + exit(1); + } + for (int i = 0; i < 3; i++) { + if (msg_uints.u8array[i] != msg_uints_ref.u8array[i]) { + printf("u8array mismatch!\n"); + exit(1); + } + if (msg_uints.u16array[i] != msg_uints_ref.u16array[i]) { + printf("u16array mismatch!\n"); + exit(1); + } + if (msg_uints.u32array[i] != msg_uints_ref.u32array[i]) { + printf("u32array mismatch!\n"); + exit(1); + } + if (msg_uints.u64array[i] != msg_uints_ref.u64array[i]) { + printf("u64array mismatch!\n"); + exit(1); + } + } - vTaskDelay(pdMS_TO_TICKS(10)); + if (msg_ints.i8 != msg_ints_ref.i8) { + printf("i8 mismatch!\n"); + exit(1); + } + if (msg_ints.i16 != msg_ints_ref.i16) { + printf("i16 mismatch!\n"); + exit(1); } + if (msg_ints.i32 != msg_ints_ref.i32) { + printf("i32 mismatch!\n"); + exit(1); + } + if (msg_ints.i64 != msg_ints_ref.i64) { + printf("i64 mismatch!\n"); + exit(1); + } + for (int i = 0; i < 3; i++) { + if (msg_ints.i8array[i] != msg_ints_ref.i8array[i]) { + printf("i8array mismatch!\n"); + exit(1); + } + if (msg_ints.i16array[i] != msg_ints_ref.i16array[i]) { + printf("i16array mismatch!\n"); + exit(1); + } + if (msg_ints.i32array[i] != msg_ints_ref.i32array[i]) { + printf("i32array mismatch!\n"); + exit(1); + } + if (msg_ints.i64array[i] != msg_ints_ref.i64array[i]) { + printf("i64array mismatch!\n"); + exit(1); + } + } + + if (msg_floats.single != msg_floats_ref.single) { + printf("single mismatch!\n"); + exit(1); + } + if (msg_floats.double_var != msg_floats_ref.double_var) { + printf("double mismatch!\n"); + exit(1); + } + for (int i = 0; i < 3; i++) { + if (msg_floats.single_array[i] != msg_floats_ref.single_array[i]) { + printf("single_array mismatch!\n"); + exit(1); + } + if (msg_floats.double_array[i] != msg_floats_ref.double_array[i]) { + printf("double_array mismatch!\n"); + exit(1); + } + } + + if (msg_strings.single != msg_strings_ref.single) { + printf("single mismatch!\n"); + exit(1); + } + if (strcmp(msg_strings.array, msg_strings_ref.array) != 0) { + printf("array mismatch!\n"); + exit(1); + } + + if (msg_bools.a != msg_bools_ref.a) { + printf("a mismatch!\n"); + exit(1); + } + for (int i = 0; i < 3; i++) { + if (msg_bools.b[i] != msg_bools_ref.b[i]) { + printf("b mismatch!\n"); + exit(1); + } + } + + if (msg_enums.single_enum != msg_enums_ref.single_enum) { + printf("single_enum mismatch!\n"); + exit(1); + } + for (int i = 0; i < 3; i++) { + if (msg_enums.enum_array[i] != msg_enums_ref.enum_array[i]) { + printf("enum_array mismatch!\n"); + exit(1); + } + } + + printf("All messages match reference!\n"); + exit(0); + } +} + +static void pub_task(void* params) { + while (1) { + umsg_test_uints_publish(&msg_uints_ref); + umsg_test_ints_publish(&msg_ints_ref); + umsg_test_floats_publish(&msg_floats_ref); + umsg_test_strings_publish(&msg_strings_ref); + umsg_test_bools_publish(&msg_bools_ref); + umsg_test_enums_publish(&msg_enums_ref); + + vTaskDelay(pdMS_TO_TICKS(10)); + } } diff --git a/tests/freertos/test_unused_messages.c b/tests/freertos/test_unused_messages.c index d75ca78..0483f28 100644 --- a/tests/freertos/test_unused_messages.c +++ b/tests/freertos/test_unused_messages.c @@ -7,32 +7,28 @@ static void pub_task(void* params); static void sub_task(void* params); -int main( void ) -{ - xTaskCreate(pub_task, "pub_task", 1000, NULL, 1, NULL); - xTaskCreate(sub_task, "sub_task", 1000, NULL, 1, NULL); - vTaskStartScheduler(); +int main(void) { + xTaskCreate(pub_task, "pub_task", 1000, NULL, 1, NULL); + xTaskCreate(sub_task, "sub_task", 1000, NULL, 1, NULL); + vTaskStartScheduler(); - return 0; + return 0; } -static void sub_task(void* params) -{ - umsg_sub_handle_t sub = umsg_unused_used_var_subscribe(1,1); - umsg_unused_used_var_t msg; - while(1) { - umsg_unused_used_var_receive(sub,&msg,portMAX_DELAY); - printf("Received msg!"); - exit(0); - } +static void sub_task(void* params) { + umsg_sub_handle_t sub = umsg_unused_used_var_subscribe(1, 1); + umsg_unused_used_var_t msg; + while (1) { + umsg_unused_used_var_receive(sub, &msg, portMAX_DELAY); + printf("Received msg!"); + exit(0); + } } -static void pub_task(void* params) -{ - umsg_unused_used_var_t msg = {.a = 0x66, .b = 0x77, .c = 0x88}; - while(1) - { - umsg_unused_used_var_publish(&msg); - vTaskDelay(pdMS_TO_TICKS(10)); - } +static void pub_task(void* params) { + umsg_unused_used_var_t msg = {.a = 0x66, .b = 0x77, .c = 0x88}; + while (1) { + umsg_unused_used_var_publish(&msg); + vTaskDelay(pdMS_TO_TICKS(10)); + } } diff --git a/tests/graph/application/communication.c b/tests/graph/application/communication.c index 7f618b6..c2e0fcd 100644 --- a/tests/graph/application/communication.c +++ b/tests/graph/application/communication.c @@ -1,54 +1,47 @@ // Pseudo code which contains uMsg api function calls to test graph generation -int main( void ) -{ - // single task which will publish messages and then read them back - xTaskCreate(user_command_task, "user_command_task", 1000, NULL, 1, NULL); - xTaskCreate(user_telemtry_task, "user_telemtry_task", 1000, NULL, 1, NULL); - vTaskStartScheduler(); - - return 0; +int main(void) { + // single task which will publish messages and then read them back + xTaskCreate(user_command_task, "user_command_task", 1000, NULL, 1, NULL); + xTaskCreate(user_telemtry_task, "user_telemtry_task", 1000, NULL, 1, NULL); + vTaskStartScheduler(); + + return 0; } -static void user_command_task(void* params) -{ - umsg_system_state_t msg_system_state; - umsg_usercmd_setpoints_t msg_usercmd_setpoints; - umsg_servo_setpoint_t msg_servo_setpoint; - umsg_lighting_cmd_t msg_lighting_cmd; - while(1) - { - // receive usart commands and parse them - usart_parse_command(); - - // send system state (ACTIVE/IDLE) - umsg_system_state_publish(&msg_system_state); - - // send user setpoints - umsg_usercmd_setpoints_publish(&msg_usercmd_setpoints); - - // send servo setpoints - umsg_servo_setpoint_publish(&msg_servo_setpoint); - - // send lighting commands - umsg_lighting_cmd_publish(&msg_lighting_cmd); - - } +static void user_command_task(void* params) { + umsg_system_state_t msg_system_state; + umsg_usercmd_setpoints_t msg_usercmd_setpoints; + umsg_servo_setpoint_t msg_servo_setpoint; + umsg_lighting_cmd_t msg_lighting_cmd; + while (1) { + // receive usart commands and parse them + usart_parse_command(); + + // send system state (ACTIVE/IDLE) + umsg_system_state_publish(&msg_system_state); + + // send user setpoints + umsg_usercmd_setpoints_publish(&msg_usercmd_setpoints); + + // send servo setpoints + umsg_servo_setpoint_publish(&msg_servo_setpoint); + + // send lighting commands + umsg_lighting_cmd_publish(&msg_lighting_cmd); + } } -static void telemetry_task(void* params) -{ - umsg_motors_telemtry_t telem_msg; - // subscrive to motor telemetry with a prescaler of 10 - umsg_sub_handle_t sub = umsg_motors_telemtry_subscribe(10,1); - while(1) - { - // wait for motor telemetry - umsg_motors_telemtry_receive(sub, &telem_msg, 0); - - // send telemetry to user via usart communication - - vTaskDelay(100) - - } +static void telemetry_task(void* params) { + umsg_motors_telemtry_t telem_msg; + // subscrive to motor telemetry with a prescaler of 10 + umsg_sub_handle_t sub = umsg_motors_telemtry_subscribe(10, 1); + while (1) { + // wait for motor telemetry + umsg_motors_telemtry_receive(sub, &telem_msg, 0); + + // send telemetry to user via usart communication + + vTaskDelay(100) + } } \ No newline at end of file diff --git a/tests/graph/application/robot_control.c b/tests/graph/application/robot_control.c index a8ce2cb..574e8af 100644 --- a/tests/graph/application/robot_control.c +++ b/tests/graph/application/robot_control.c @@ -1,53 +1,45 @@ // Pseudo code which contains uMsg api function calls to test graph generation -int main( void ) -{ - // single task which will publish messages and then read them back - xTaskCreate(control_task, "control_task", 1000, NULL, 1, NULL); - vTaskStartScheduler(); +int main(void) { + // single task which will publish messages and then read them back + xTaskCreate(control_task, "control_task", 1000, NULL, 1, NULL); + vTaskStartScheduler(); - return 0; + return 0; } -static void control_task(void* params) -{ - umsg_usercmd_setpoints_t msg_usercmd_setpoints; - umsg_system_state_t msg_system_state; - umsg_estimation_attitude_t msg_att; - umsg_motors_speedsetpoint_t msg_sp; +static void control_task(void* params) { + umsg_usercmd_setpoints_t msg_usercmd_setpoints; + umsg_system_state_t msg_system_state; + umsg_estimation_attitude_t msg_att; + umsg_motors_speedsetpoint_t msg_sp; - // subscribe state estimate and sonar messages - umsg_sub_handle_t sub_att = umsg_estimation_attitude_subscribe(1,1); - umsg_sub_handle_t sub_sonar = umsg_sensors_sonar_subscribe(1,1); - umsg_sub_handle_t sub_state = umsg_system_state_subscribe(1,1); + // subscribe state estimate and sonar messages + umsg_sub_handle_t sub_att = umsg_estimation_attitude_subscribe(1, 1); + umsg_sub_handle_t sub_sonar = umsg_sensors_sonar_subscribe(1, 1); + umsg_sub_handle_t sub_state = umsg_system_state_subscribe(1, 1); - while(1) - { - // synchronize on state estimate and sonar messages - umsg_estimation_attitude_receive(sub_att, &msg_att, portMAX_DELAY); + while (1) { + // synchronize on state estimate and sonar messages + umsg_estimation_attitude_receive(sub_att, &msg_att, portMAX_DELAY); - // receive sonar message with no timeout (async) - umsg_sensors_sonar_receive(sub_sonar, &msg_sonar, 0); + // receive sonar message with no timeout (async) + umsg_sensors_sonar_receive(sub_sonar, &msg_sonar, 0); - // receive system state message with no timeout (async) - umsg_system_state_receive(sub_state, &msg_state, 0); + // receive system state message with no timeout (async) + umsg_system_state_receive(sub_state, &msg_state, 0); - // peek at user setpoints message (async) - umsg_usercmd_setpoints_peek(&msg_usercmd_setpoints); + // peek at user setpoints message (async) + umsg_usercmd_setpoints_peek(&msg_usercmd_setpoints); - if(msg_system_state == ACTIVE) - { - // do control loop math - } - else - { - // set motor speed setpoints to 0 - - } - - // publish motor speed setpoints - umsg_motors_speedsetpoint_publish(&msg_sp); - + if (msg_system_state == ACTIVE) { + // do control loop math + } else { + // set motor speed setpoints to 0 } + + // publish motor speed setpoints + umsg_motors_speedsetpoint_publish(&msg_sp); + } } \ No newline at end of file diff --git a/tests/graph/drivers/actuators/motor_driver.c b/tests/graph/drivers/actuators/motor_driver.c index a33f079..0765537 100644 --- a/tests/graph/drivers/actuators/motor_driver.c +++ b/tests/graph/drivers/actuators/motor_driver.c @@ -1,42 +1,34 @@ // Pseudo code which contains uMsg api function calls to test graph generation -int main( void ) -{ - // single task which will publish messages and then read them back - xTaskCreate(control_task, "control_task", 1000, NULL, 1, NULL); - xTaskCreate(telemetry_task, "control_task", 1000, NULL, 1, NULL); - vTaskStartScheduler(); +int main(void) { + // single task which will publish messages and then read them back + xTaskCreate(control_task, "control_task", 1000, NULL, 1, NULL); + xTaskCreate(telemetry_task, "control_task", 1000, NULL, 1, NULL); + vTaskStartScheduler(); - return 0; + return 0; } -static void control_task(void* params) -{ - umsg_motors_speedsetpoint_t msg; - // subscribe to speed setpoint message - umsg_sub_handle_t sub = umsg_motors_speedsetpoint_subscribe(1,1); +static void control_task(void* params) { + umsg_motors_speedsetpoint_t msg; + // subscribe to speed setpoint message + umsg_sub_handle_t sub = umsg_motors_speedsetpoint_subscribe(1, 1); - while(1) - { - // wait for setpoints - umsg_motors_speedsetpoint_receive(sub, &msg, portMAX_DELAY); + while (1) { + // wait for setpoints + umsg_motors_speedsetpoint_receive(sub, &msg, portMAX_DELAY); - // set timer PWM - timer_set_duty(msg); - - } + // set timer PWM + timer_set_duty(msg); + } } -static void telemetry_task(void* params) -{ - umsg_motors_telemtry_t telem_msg; - while(1) - { - // get motor telemetry via usart (RPM, current, temperature - usart_get_telem(&telem_msg) +static void telemetry_task(void* params) { + umsg_motors_telemtry_t telem_msg; + while (1) { + // get motor telemetry via usart (RPM, current, temperature + usart_get_telem(&telem_msg) // publish umsg umsg_motors_telemtry_publish(&telem_msg); - - } + } } - diff --git a/tests/graph/drivers/actuators/servo_driver.c b/tests/graph/drivers/actuators/servo_driver.c index 61e08eb..dd6ca5c 100644 --- a/tests/graph/drivers/actuators/servo_driver.c +++ b/tests/graph/drivers/actuators/servo_driver.c @@ -1,27 +1,23 @@ // Pseudo code which contains uMsg api function calls to test graph generation -int main( void ) -{ - // single task which will publish messages and then read them back - xTaskCreate(control_task, "control_task", 1000, NULL, 1, NULL); - vTaskStartScheduler(); +int main(void) { + // single task which will publish messages and then read them back + xTaskCreate(control_task, "control_task", 1000, NULL, 1, NULL); + vTaskStartScheduler(); - return 0; + return 0; } -static void control_task(void* params) -{ - umsg_servo_setpoint_t msg; - // subscribe to speed setpoint message - umsg_sub_handle_t sub = umsg_servo_setpoint_subscribe(1,1); +static void control_task(void* params) { + umsg_servo_setpoint_t msg; + // subscribe to speed setpoint message + umsg_sub_handle_t sub = umsg_servo_setpoint_subscribe(1, 1); - while(1) - { - // wait for setpoints - umsg_servo_setpoint_receive(sub, &msg, portMAX_DELAY); + while (1) { + // wait for setpoints + umsg_servo_setpoint_receive(sub, &msg, portMAX_DELAY); - // set timer PWM - timer_set_duty(msg); - - } + // set timer PWM + timer_set_duty(msg); + } } \ No newline at end of file diff --git a/tests/graph/drivers/other/lighting_driver.c b/tests/graph/drivers/other/lighting_driver.c index de61ef9..a0a4882 100644 --- a/tests/graph/drivers/other/lighting_driver.c +++ b/tests/graph/drivers/other/lighting_driver.c @@ -1,33 +1,29 @@ // Pseudo code which contains uMsg api function calls to test graph generation -int main( void ) -{ - // single task which will publish messages and then read them back - xTaskCreate(main_task, "main_task", 1000, NULL, 1, NULL); - vTaskStartScheduler(); +int main(void) { + // single task which will publish messages and then read them back + xTaskCreate(main_task, "main_task", 1000, NULL, 1, NULL); + vTaskStartScheduler(); - return 0; + return 0; } -static void main_task(void* params) -{ - umsg_lighting_cmd_t msg; - // subscribe to speed setpoint message - umsg_sub_handle_t sub = umsg_lighting_cmd_subscribe(1,1); +static void main_task(void* params) { + umsg_lighting_cmd_t msg; + // subscribe to speed setpoint message + umsg_sub_handle_t sub = umsg_lighting_cmd_subscribe(1, 1); - while(1) - { - // get latest lighting commands - umsg_lighting_cmd_receive(sub, &msg, 0); + while (1) { + // get latest lighting commands + umsg_lighting_cmd_receive(sub, &msg, 0); - // get lighting temperature + // get lighting temperature - // control loop to make sure led's dont over heat + // control loop to make sure led's dont over heat - // set timer PWM - timer_set_duty(led_power); + // set timer PWM + timer_set_duty(led_power); - vTaskDelay(100) - - } + vTaskDelay(100) + } } \ No newline at end of file diff --git a/tests/graph/drivers/sensors/barometer_driver.c b/tests/graph/drivers/sensors/barometer_driver.c index 3d803ad..89c1ae8 100644 --- a/tests/graph/drivers/sensors/barometer_driver.c +++ b/tests/graph/drivers/sensors/barometer_driver.c @@ -1,23 +1,19 @@ // Pseudo code which contains uMsg api function calls to test graph generation -int main( void ) -{ - // single task which will publish messages and then read them back - xTaskCreate(dummy_task, "dummy_task", 1000, NULL, 1, NULL); - vTaskStartScheduler(); +int main(void) { + // single task which will publish messages and then read them back + xTaskCreate(dummy_task, "dummy_task", 1000, NULL, 1, NULL); + vTaskStartScheduler(); - return 0; + return 0; } -static void dummy_task(void* params) -{ - umsg_sensor_imu_t msg; - while(1) - { - // read sensor via SPI - spi_read(&msg) +static void dummy_task(void* params) { + umsg_sensor_imu_t msg; + while (1) { + // read sensor via SPI + spi_read(&msg) // publish umsg umsg_sensors_barometer_publish(&msg); - - } + } } diff --git a/tests/graph/drivers/sensors/imu_driver.c b/tests/graph/drivers/sensors/imu_driver.c index 644e89d..2c0a85b 100644 --- a/tests/graph/drivers/sensors/imu_driver.c +++ b/tests/graph/drivers/sensors/imu_driver.c @@ -1,23 +1,19 @@ // Pseudo code which contains uMsg api function calls to test graph generation -int main( void ) -{ - // single task which will publish messages and then read them back - xTaskCreate(dummy_task, "dummy_task", 1000, NULL, 1, NULL); - vTaskStartScheduler(); +int main(void) { + // single task which will publish messages and then read them back + xTaskCreate(dummy_task, "dummy_task", 1000, NULL, 1, NULL); + vTaskStartScheduler(); - return 0; + return 0; } -static void dummy_task(void* params) -{ - umsg_sensor_imu_t msg; - while(1) - { - // read sensor via SPI - spi_read(&msg) +static void dummy_task(void* params) { + umsg_sensor_imu_t msg; + while (1) { + // read sensor via SPI + spi_read(&msg) // publish umsg umsg_sensors_imu_publish(&msg); - - } + } } diff --git a/tests/graph/drivers/sensors/sonar_sensor.c b/tests/graph/drivers/sensors/sonar_sensor.c index c4ad1a1..2af0871 100644 --- a/tests/graph/drivers/sensors/sonar_sensor.c +++ b/tests/graph/drivers/sensors/sonar_sensor.c @@ -1,23 +1,19 @@ // Pseudo code which contains uMsg api function calls to test graph generation -int main( void ) -{ - // single task which will publish messages and then read them back - xTaskCreate(dummy_task, "dummy_task", 1000, NULL, 1, NULL); - vTaskStartScheduler(); +int main(void) { + // single task which will publish messages and then read them back + xTaskCreate(dummy_task, "dummy_task", 1000, NULL, 1, NULL); + vTaskStartScheduler(); - return 0; + return 0; } -static void dummy_task(void* params) -{ - umsg_sensor_imu_t msg; - while(1) - { - // read sensor via I2C - i2c_read(&msg) +static void dummy_task(void* params) { + umsg_sensor_imu_t msg; + while (1) { + // read sensor via I2C + i2c_read(&msg) // publish umsg umsg_sensors_sonar_publish(&msg); - - } + } } diff --git a/tests/graph/modules/attitude_estimation.c b/tests/graph/modules/attitude_estimation.c index 382888f..e9d981b 100644 --- a/tests/graph/modules/attitude_estimation.c +++ b/tests/graph/modules/attitude_estimation.c @@ -1,30 +1,26 @@ // Pseudo code which contains uMsg api function calls to test graph generation -int main( void ) -{ - // single task which will publish messages and then read them back - xTaskCreate(dummy_task, "dummy_task", 1000, NULL, 1, NULL); - vTaskStartScheduler(); +int main(void) { + // single task which will publish messages and then read them back + xTaskCreate(dummy_task, "dummy_task", 1000, NULL, 1, NULL); + vTaskStartScheduler(); - return 0; + return 0; } -static void dummy_task(void* params) -{ - umsg_sensor_imu_t imu_msg; - umsg_estimation_attitude_t att_msg; - umsg_sub_handle_t sub = umsg_sensor_imu_subscribe(1,1); - while(1) - { - // wait for imu data - umsg_sensor_imu_receive(sub, &msg, portMAX_DELAY); +static void dummy_task(void* params) { + umsg_sensor_imu_t imu_msg; + umsg_estimation_attitude_t att_msg; + umsg_sub_handle_t sub = umsg_sensor_imu_subscribe(1, 1); + while (1) { + // wait for imu data + umsg_sensor_imu_receive(sub, &msg, portMAX_DELAY); - // filter imu data + // filter imu data - // run kalman filter + // run kalman filter - // publish attitude - umsg_estimation_attitude_publish(&att_msg); - - } + // publish attitude + umsg_estimation_attitude_publish(&att_msg); + } } diff --git a/umsg_gen/umsg_gen/core/inc/umsg.h b/umsg_gen/umsg_gen/core/inc/umsg.h index 2109976..a7461df 100644 --- a/umsg_gen/umsg_gen/core/inc/umsg.h +++ b/umsg_gen/umsg_gen/core/inc/umsg.h @@ -13,36 +13,35 @@ extern "C" { typedef struct { - umsg_sub_handle_t sub_handle; - uint16_t prescaler; - uint8_t length; - uint8_t channel; - void* next_sub; + umsg_sub_handle_t sub_handle; + uint16_t prescaler; + uint8_t length; + uint8_t channel; + void* next_sub; } umsg_sub_t; typedef struct { - umsg_sub_t* sub_list; - void* msg_value; - uint32_t counter; - char* name; + umsg_sub_t* sub_list; + void* msg_value; + uint32_t counter; + char* name; } umsg_msg_metadata_t; umsg_sub_handle_t umsg_subscribe(umsg_msg_metadata_t* msg, uint16_t prescaler, uint32_t size, uint8_t length, uint8_t ch_id); -void umsg_publish(umsg_msg_metadata_t* msg, void* data, uint8_t ch_id); -uint8_t umsg_receive(umsg_sub_handle_t queue, void* data, uint32_t timeout); -uint8_t umsg_peek(umsg_msg_metadata_t* msg, void* data, uint32_t size); +void umsg_publish(umsg_msg_metadata_t* msg, void* data, uint8_t ch_id); +uint8_t umsg_receive(umsg_sub_handle_t queue, void* data, uint32_t timeout); +uint8_t umsg_peek(umsg_msg_metadata_t* msg, void* data, uint32_t size); -void umsg_CRCInit(); +void umsg_CRCInit(); uint8_t umsg_checkCRC(uint8_t* buffer, uint32_t len); uint8_t umsg_calcCRC(uint8_t* buffer, uint32_t len); - #ifdef __cplusplus } #endif -#endif //UMSG_UMSG_H +#endif // UMSG_UMSG_H diff --git a/umsg_gen/umsg_gen/core/inc/umsg_port.h b/umsg_gen/umsg_gen/core/inc/umsg_port.h index 5cd4ed1..eb632fd 100644 --- a/umsg_gen/umsg_gen/core/inc/umsg_port.h +++ b/umsg_gen/umsg_gen/core/inc/umsg_port.h @@ -10,13 +10,13 @@ extern "C" { #include -void * umsg_port_malloc(uint32_t size); -void * umsg_port_create(uint32_t size, uint8_t length); -void umsg_port_send(umsg_sub_t* sub, void * data); -uint8_t umsg_port_receive(umsg_sub_handle_t sub_handle, void * data, uint32_t timeout); +void* umsg_port_malloc(uint32_t size); +void* umsg_port_create(uint32_t size, uint8_t length); +void umsg_port_send(umsg_sub_t* sub, void* data); +uint8_t umsg_port_receive(umsg_sub_handle_t sub_handle, void* data, uint32_t timeout); #ifdef __cplusplus } #endif -#endif //UMSG_UMSG_PORT_H +#endif // UMSG_UMSG_PORT_H diff --git a/umsg_gen/umsg_gen/core/inc/umsg_types.h b/umsg_gen/umsg_gen/core/inc/umsg_types.h index 94e395d..2a2b6a2 100644 --- a/umsg_gen/umsg_gen/core/inc/umsg_types.h +++ b/umsg_gen/umsg_gen/core/inc/umsg_types.h @@ -18,4 +18,4 @@ typedef void* umsg_sub_handle_t; } #endif -#endif //UMSG_UMSG_TYPES_H +#endif // UMSG_UMSG_TYPES_H diff --git a/umsg_gen/umsg_gen/core/src/port_freertos.c b/umsg_gen/umsg_gen/core/src/port_freertos.c index 53233a3..e8577d4 100644 --- a/umsg_gen/umsg_gen/core/src/port_freertos.c +++ b/umsg_gen/umsg_gen/core/src/port_freertos.c @@ -7,64 +7,48 @@ #include // obtained from cmsis core.h. All cortex M processors have this register at this address -const uint32_t* ARM_CORTEX_ICSR = (uint32_t*)(0xE000E000UL+0x0D00UL+0x004); -const uint32_t SCB_ICSR_VECTACTIVE_POS = 0x1FFUL; +const uint32_t* ARM_CORTEX_ICSR = (uint32_t*)(0xE000E000UL + 0x0D00UL + 0x004); +const uint32_t SCB_ICSR_VECTACTIVE_POS = 0x1FFUL; -bool is_isr_active() -{ +bool is_isr_active() { #if defined(__GNUC__) && defined(__arm__) - // if the current active vector is 0, then we are not in an ISR - return (*ARM_CORTEX_ICSR & SCB_ICSR_VECTACTIVE_POS) != 0; + // if the current active vector is 0, then we are not in an ISR + return (*ARM_CORTEX_ICSR & SCB_ICSR_VECTACTIVE_POS) != 0; #endif - return false; + return false; } -void * umsg_port_malloc(uint32_t size) -{ - return pvPortMalloc(size); +void* umsg_port_malloc(uint32_t size) { + return pvPortMalloc(size); } -umsg_sub_handle_t umsg_port_create(uint32_t size, uint8_t length) -{ - return xQueueCreate(length, size); +umsg_sub_handle_t umsg_port_create(uint32_t size, uint8_t length) { + return xQueueCreate(length, size); } -void umsg_port_send(umsg_sub_t* sub, void * data) -{ - QueueHandle_t queue = (QueueHandle_t)sub->sub_handle; - if(sub->length > 1) - { - if(is_isr_active()) - { - BaseType_t xHigherPriorityTaskWoken; - xQueueSendToBackFromISR(queue, data, - &xHigherPriorityTaskWoken); - portYIELD_FROM_ISR(xHigherPriorityTaskWoken); +void umsg_port_send(umsg_sub_t* sub, void* data) { + QueueHandle_t queue = (QueueHandle_t)sub->sub_handle; + if (sub->length > 1) { + if (is_isr_active()) { + BaseType_t xHigherPriorityTaskWoken; + xQueueSendToBackFromISR(queue, data, &xHigherPriorityTaskWoken); + portYIELD_FROM_ISR(xHigherPriorityTaskWoken); - } - else - { - xQueueSendToBack(queue, data, 0); - } + } else { + xQueueSendToBack(queue, data, 0); } - else - { - // check if in interrupt context - if(is_isr_active()) - { - BaseType_t xHigherPriorityTaskWoken; - xQueueOverwriteFromISR(queue, data, - &xHigherPriorityTaskWoken); - portYIELD_FROM_ISR(xHigherPriorityTaskWoken); - } - else - { - xQueueOverwrite(queue, data); - } + } else { + // check if in interrupt context + if (is_isr_active()) { + BaseType_t xHigherPriorityTaskWoken; + xQueueOverwriteFromISR(queue, data, &xHigherPriorityTaskWoken); + portYIELD_FROM_ISR(xHigherPriorityTaskWoken); + } else { + xQueueOverwrite(queue, data); } + } } -uint8_t umsg_port_receive(umsg_sub_handle_t sub_handle, void * data, uint32_t timeout) -{ - return xQueueReceive((QueueHandle_t)sub_handle, data, timeout); +uint8_t umsg_port_receive(umsg_sub_handle_t sub_handle, void* data, uint32_t timeout) { + return xQueueReceive((QueueHandle_t)sub_handle, data, timeout); } \ No newline at end of file diff --git a/umsg_gen/umsg_gen/core/src/port_posix.c b/umsg_gen/umsg_gen/core/src/port_posix.c index 46ca460..0f9fad4 100644 --- a/umsg_gen/umsg_gen/core/src/port_posix.c +++ b/umsg_gen/umsg_gen/core/src/port_posix.c @@ -4,19 +4,14 @@ #include -void * umsg_port_malloc(uint32_t size) -{ - return 0; +void* umsg_port_malloc(uint32_t size) { + return 0; } -void * umsg_port_create(uint32_t size, uint8_t length) -{ - return 0; +void* umsg_port_create(uint32_t size, uint8_t length) { + return 0; } -void umsg_port_send(umsg_sub_t* sub, void * data) -{ - +void umsg_port_send(umsg_sub_t* sub, void* data) { } -uint8_t umsg_port_receive(umsg_sub_handle_t sub_handle, void * data, uint32_t timeout) -{ - return 0; +uint8_t umsg_port_receive(umsg_sub_handle_t sub_handle, void* data, uint32_t timeout) { + return 0; } \ No newline at end of file diff --git a/umsg_gen/umsg_gen/core/src/umsg.c b/umsg_gen/umsg_gen/core/src/umsg.c index db845d6..47141af 100644 --- a/umsg_gen/umsg_gen/core/src/umsg.c +++ b/umsg_gen/umsg_gen/core/src/umsg.c @@ -8,118 +8,100 @@ uint8_t CRCresults[256]; -const uint8_t remainder_len = 8; -const uint16_t POLYNOMIAL = 0x2F; // this is a CRC8 polynomial - -umsg_sub_handle_t umsg_subscribe(umsg_msg_metadata_t* msg, uint16_t prescaler, uint32_t size, uint8_t length, uint8_t ch_id) -{ - if(msg->sub_list == NULL) - { - msg->msg_value = umsg_port_malloc(size); - - msg->sub_list = umsg_port_malloc(sizeof(umsg_sub_t)); - msg->sub_list->sub_handle = umsg_port_create(size,length); - msg->sub_list->prescaler = prescaler; - msg->sub_list->length = length; - msg->sub_list->channel = ch_id; - msg->sub_list->next_sub = NULL; - return msg->sub_list->sub_handle; - } - else - { - umsg_sub_t* sub = msg->sub_list; - while(sub->next_sub != NULL) - { - sub = sub->next_sub; - } - sub->next_sub = umsg_port_malloc(sizeof(umsg_sub_t)); - sub = sub->next_sub; - sub->sub_handle = umsg_port_create(size,length); - sub->prescaler = prescaler; - sub->length = length; - sub->channel = ch_id; - sub->next_sub = NULL; - return sub->sub_handle; +const uint8_t remainder_len = 8; +const uint16_t POLYNOMIAL = 0x2F; // this is a CRC8 polynomial + +umsg_sub_handle_t umsg_subscribe(umsg_msg_metadata_t* msg, uint16_t prescaler, uint32_t size, uint8_t length, uint8_t ch_id) { + if (msg->sub_list == NULL) { + msg->msg_value = umsg_port_malloc(size); + + msg->sub_list = umsg_port_malloc(sizeof(umsg_sub_t)); + msg->sub_list->sub_handle = umsg_port_create(size, length); + msg->sub_list->prescaler = prescaler; + msg->sub_list->length = length; + msg->sub_list->channel = ch_id; + msg->sub_list->next_sub = NULL; + return msg->sub_list->sub_handle; + } else { + umsg_sub_t* sub = msg->sub_list; + while (sub->next_sub != NULL) { + sub = sub->next_sub; } + sub->next_sub = umsg_port_malloc(sizeof(umsg_sub_t)); + sub = sub->next_sub; + sub->sub_handle = umsg_port_create(size, length); + sub->prescaler = prescaler; + sub->length = length; + sub->channel = ch_id; + sub->next_sub = NULL; + return sub->sub_handle; + } } -void umsg_publish(umsg_msg_metadata_t* msg, void* data, uint8_t ch_id) -{ - msg->msg_value = data; - msg->counter++; - umsg_sub_t* sub = msg->sub_list; - while(sub != NULL) - { - if(msg->counter % sub->prescaler == 0 && sub->channel == ch_id) - { - umsg_port_send(sub, data); - } - sub = sub->next_sub; +void umsg_publish(umsg_msg_metadata_t* msg, void* data, uint8_t ch_id) { + msg->msg_value = data; + msg->counter++; + umsg_sub_t* sub = msg->sub_list; + while (sub != NULL) { + if (msg->counter % sub->prescaler == 0 && sub->channel == ch_id) { + umsg_port_send(sub, data); } + sub = sub->next_sub; + } } -uint8_t umsg_receive(umsg_sub_handle_t queue, void* data, uint32_t timeout) -{ - return umsg_port_receive(queue, data, timeout); +uint8_t umsg_receive(umsg_sub_handle_t queue, void* data, uint32_t timeout) { + return umsg_port_receive(queue, data, timeout); } -uint8_t umsg_peek(umsg_msg_metadata_t* msg, void* data, uint32_t size) -{ - if(msg->counter > 0) - { - memcpy(data, msg->msg_value, size); - return 1; - } - return 0; +uint8_t umsg_peek(umsg_msg_metadata_t* msg, void* data, uint32_t size) { + if (msg->counter > 0) { + memcpy(data, msg->msg_value, size); + return 1; + } + return 0; } -void umsg_CRCInit(){ - - uint8_t top_bit = (1 << (remainder_len - 1)); - uint8_t remainder = 0; - for(int i = 0; i < 256; i++){ - remainder = i; - for (uint8_t bit = 8; bit > 0; --bit) - { - /* - * Try to divide the current data bit. - */ - if (remainder & top_bit) - { - remainder = (remainder << 1) ^ POLYNOMIAL; - } - else - { - remainder = (remainder << 1); - } - } - CRCresults[i] = remainder; +void umsg_CRCInit() { + + uint8_t top_bit = (1 << (remainder_len - 1)); + uint8_t remainder = 0; + for (int i = 0; i < 256; i++) { + remainder = i; + for (uint8_t bit = 8; bit > 0; --bit) { + /* + * Try to divide the current data bit. + */ + if (remainder & top_bit) { + remainder = (remainder << 1) ^ POLYNOMIAL; + } else { + remainder = (remainder << 1); + } } - - + CRCresults[i] = remainder; + } } -uint8_t umsg_checkCRC(uint8_t* buffer, uint32_t len){ - uint8_t remainder = umsg_calcCRC(buffer,len); - if(remainder == 0) - return 0; - return 1; +uint8_t umsg_checkCRC(uint8_t* buffer, uint32_t len) { + uint8_t remainder = umsg_calcCRC(buffer, len); + if (remainder == 0) + return 0; + return 1; } -uint8_t umsg_calcCRC(uint8_t* buffer, uint32_t len){ - uint8_t data; - uint8_t remainder = 0; +uint8_t umsg_calcCRC(uint8_t* buffer, uint32_t len) { + uint8_t data; + uint8_t remainder = 0; - /* - * Divide the message by the polynomial, a byte at a time. - */ - for (int byte = 0; byte < len; ++byte) - { - data = buffer[byte] ^ (remainder); - remainder = CRCresults[data] ^ (remainder << 8); - } - return remainder; + /* + * Divide the message by the polynomial, a byte at a time. + */ + for (int byte = 0; byte < len; ++byte) { + data = buffer[byte] ^ (remainder); + remainder = CRCresults[data] ^ (remainder << 8); + } + return remainder; } \ No newline at end of file diff --git a/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 b/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 index 940075c..fec6d93 100644 --- a/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 +++ b/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 @@ -19,7 +19,7 @@ //globally defined streams for topic files -char buffer[1000]; +MessageToTransfer buffer; {% for dict in topic_dict_list%} @@ -42,16 +42,19 @@ void sort_{{dict.name}}_type(std::ifstream &file) exit(2); } - buffer[0] = UMSG_{{dict.name.upper()}}; - buffer[1] = msg_type; + buffer.s.sync0 = 'M'; + buffer.s.sync1 = 'R'; + buffer.s.msg_class = UMSG_{{dict.name.upper()}}; + buffer.s.msg_type = msg_type; switch(msg_type) { {% for msg_dict in dict.msgs%} case {{dict.name.upper()}}_{{msg_dict.name.upper()}}: { - file.read(buffer + 2,sizeof(umsg_{{dict.name}}_{{msg_dict.name}}_t) + 1); //read including the crc byte - umsg_{{dict.name}}_{{msg_dict.name}}_t message; - uint8_t retval = umsg_{{dict.name}}_{{msg_dict.name}}_deserialize_CRC(&message,(uint8_t *)buffer); + uint32_t len = sizeof(umsg_{{dict.name}}_{{msg_dict.name}}_t) + 5; + file.read((char *)(buffer.raw + 4),len-4); //read including the crc byte + umsg_{{dict.name}}_{{msg_dict.name}}_t message = buffer.s.{{dict.name}}.{{msg_dict.name}}; + uint8_t retval = umsg_calcCRC(buffer.raw,len); if(retval){ std::cout << "retval for message {{dict.name.upper()}}_{{msg_dict.name.upper()}} failed with value: " << static_cast(retval) << std::endl; } @@ -60,8 +63,8 @@ void sort_{{dict.name}}_type(std::ifstream &file) {% if field.length %} for(uint32_t i=0;i<{{field.length}}; i++){ file_{{dict.name}}_{{msg_dict.name}} << {% if field.type =="uint8"%} static_cast(message.{{field.name}}[i]) - {% elif field.type == "float"%} std::setprecision(std::numeric_limits::max_digits10) << message.{{field.name}}[i] - {%elif field.type == "double"%} std::setprecision(std::numeric_limits::max_digits10) << message.{{field.name}}[i] + {% elif field.type == "float"%} std::setprecision(19) << message.{{field.name}}[i] + {%elif field.type == "double"%} std::setprecision(19) << message.{{field.name}}[i] {% else %}message.{{field.name}}[i] {% endif %} ; {%if loop.last%} if(i<{{field.length}} - 1) @@ -71,8 +74,8 @@ void sort_{{dict.name}}_type(std::ifstream &file) {% endif %} {% if not field.length %} file_{{dict.name}}_{{msg_dict.name}} << {% if field.type =="uint8"%} static_cast(message.{{field.name}}) - {% elif field.type == "float"%} std::setprecision(std::numeric_limits::max_digits10) << message.{{field.name}} - {%elif field.type == "double"%} std::setprecision(std::numeric_limits::max_digits10) << message.{{field.name}} + {% elif field.type == "float"%} std::setprecision(19) << message.{{field.name}} + {%elif field.type == "double"%} std::setprecision(19) << message.{{field.name}} {% else %}message.{{field.name}}{% endif %}{% if not loop.last%} << ", "{% endif %}; {% endif %} {% endif %} @@ -102,14 +105,20 @@ void sort_msg(std::ifstream &file) std::cerr << std::endl << "Error opening logfile" << std::endl; return; } + uint8_t starthead[3]; + file.read((char *)starthead, 3); + + if(starthead[0]!= 'M' || starthead[1] !='R'){ + std::cerr << std::endl << "Error, no sync bytes detected" << std::endl; + return; + + } - uint8_t msg_class; - file.read((char *)&msg_class, 1); if (!file) { std::cerr << std::endl << "Error reading file" << std::endl; return; } - + uint8_t msg_class = starthead[2]; switch(msg_class) { {% for dict in topic_dict_list%} diff --git a/umsg_gen/umsg_gen/templates/msg.c.j2 b/umsg_gen/umsg_gen/templates/msg.c.j2 index a67c9ff..c41a315 100644 --- a/umsg_gen/umsg_gen/templates/msg.c.j2 +++ b/umsg_gen/umsg_gen/templates/msg.c.j2 @@ -2,6 +2,8 @@ #include #include +#include "umsg_classes.h" +#include "umsg.h" // msg instances {% for msg_dict in topic_dict.msgs %} {% set prefix = topic_dict.name+'_'+msg_dict.name%} @@ -37,23 +39,29 @@ uint8_t umsg_{{prefix}}_peek(umsg_{{prefix}}_t* data) return umsg_peek(&msg_{{prefix}}, data, sizeof(umsg_{{prefix}}_t)); } {%if log == "do_log" %} -uint32_t umsg_{{prefix}}_serialize(umsg_{{prefix}}_t* data, uint8_t* buffer) -{ + + + +uint32_t umsg_{{prefix}}_receive_to_transfer(umsg_sub_handle_t queue, MessageToTransfer* msg){ uint32_t len = 2; - buffer[0] = UMSG_{{topic_dict.name.upper()}}; - buffer[1] = {{topic_dict.name.upper()}}_{{msg_dict.name.upper()}}; - uint8_t *flattened_data = (uint8_t *)data; - //this can probably be replaced by memcpy but it is done like this for now just to be safe - for(uint32_t i = 0; i < sizeof(umsg_{{prefix}}_t);i++) - { - buffer[len] = flattened_data[i]; - len++; + + if(umsg_{{prefix}}_receive(queue,&(msg->s.{{topic_dict.name}}.{{msg_dict.name}}),0)){ + + + msg->s.msg_class = UMSG_{{topic_dict.name.upper()}}; + msg->s.msg_type = {{topic_dict.name.upper()}}_{{msg_dict.name.upper()}}; + len+= sizeof(umsg_{{topic_dict.name}}_{{msg_dict.name}}_t); + msg->raw[len+1] = umsg_calcCRC(&(msg->raw),len); + return len+1; } - return len; + + return 0; } + //for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future -uint8_t umsg_{{prefix}}_deserialize(umsg_{{prefix}}_t* data,uint8_t* buffer) +/* +uint32_t umsg_{{prefix}}_publish_received(MessageToTransfer* msg) { if(buffer[0]!=UMSG_{{topic_dict.name.upper()}} || buffer[1] !={{topic_dict.name.upper()}}_{{msg_dict.name.upper()}}) { @@ -71,20 +79,7 @@ uint8_t umsg_{{prefix}}_deserialize(umsg_{{prefix}}_t* data,uint8_t* buffer) return 0; } - -uint32_t umsg_{{prefix}}_serialize_CRC(umsg_{{prefix}}_t* data, uint8_t* buffer){ - uint32_t len = umsg_{{prefix}}_serialize(data,buffer); - uint8_t crc = umsg_calcCRC(buffer, len); - buffer[len] = crc; - len++; - return len; -} -uint8_t umsg_{{prefix}}_deserialize_CRC(umsg_{{prefix}}_t* data,uint8_t* buffer){ - uint8_t invalidcrc = umsg_checkCRC(buffer, sizeof(umsg_{{prefix}}_t) + 3); - uint8_t retval = umsg_{{prefix}}_deserialize(data,buffer); - return invalidcrc | (retval << 1); -} - +*/ {% endif %} {% endfor %} diff --git a/umsg_gen/umsg_gen/templates/msg.h.j2 b/umsg_gen/umsg_gen/templates/msg.h.j2 index e59d765..fbd55f9 100644 --- a/umsg_gen/umsg_gen/templates/msg.h.j2 +++ b/umsg_gen/umsg_gen/templates/msg.h.j2 @@ -1,32 +1,3 @@ -{% macro type_map(type) %} -{%- if type.lower()=="uint8" -%} -uint8_t -{%- elif type.lower()=="int8" -%} -int8_t -{%- elif type.lower()=="uint16" -%} -uint16_t -{%- elif type.lower()=="int16" -%} -int16_t -{%- elif type.lower()=="uint32" -%} -uint32_t -{%- elif type.lower()=="int32" -%} -int32_t -{%- elif type.lower()=="uint64" -%} -uint64_t -{%- elif type.lower()=="int64" -%} -int64_t -{%- elif type.lower()=="float" -%} -float -{%- elif type.lower()=="double" -%} -double -{%- elif type.lower()=="bool" -%} -bool -{%- elif type.lower()=="char" -%} -char -{%- else -%} -umsg_{{topic_dict.name}}_{{type.lower()}}_t -{%- endif%} -{% endmacro %} // Generated with umsg_gen on {{ date }} #pragma once @@ -35,42 +6,9 @@ extern "C" { #endif #include +#include -#include "umsg_classes.h" -// msg structure typedefs -{%if topic_dict.enums %} -{% for enum in topic_dict.enums%} -typedef enum __attribute__((__packed__)) -{ - {%for val in enum.enumerators%} - {{val.upper()}}{{ "," if not loop.last else "" }} - {%endfor%} -} umsg_{{topic_dict.name}}_{{enum.name}}_t; - -{%endfor%} -{% endif %} - -//enumeration of topics -typedef enum -{ -{% for msg_dict in topic_dict.msgs %} - {{topic_dict.name.upper()}}_{{msg_dict.name.upper()}}{{', ' if not loop.last else ''}} -{% endfor -%} -} umsg_enum_{{topic_dict.name}}_t; - - - -{% for msg_dict in topic_dict.msgs %} -typedef struct -{ - {% for field in msg_dict.fields %} - {%+ if not field.bitfield %}{{type_map(field.type)}} {{field.name}}{% if field.length %}[{{field.length}}]{% endif %};{% endif %} - {% if field.bitfield %}{{type_map(field.type)}} {%for bitfield in field.bitfield %}{{bitfield.name}} : {{bitfield.bits}}{{ ", " if not loop.last else ";" }}{%endfor%}{% endif +%} - {% endfor %} -} umsg_{{topic_dict.name}}_{{msg_dict.name}}_t; - -{% endfor -%} // api function headers {% for msg_dict in topic_dict.msgs %} @@ -87,13 +25,12 @@ uint8_t umsg_{{prefix}}_peek(umsg_{{prefix}}_t* data); //function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class and type //for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future //please take care that the messages are build properly to avoid padding issues if the messages are opened on different system -uint32_t umsg_{{prefix}}_serialize(umsg_{{prefix}}_t* data, uint8_t* buffer); -uint8_t umsg_{{prefix}}_deserialize(umsg_{{prefix}}_t* data,uint8_t* buffer); // this function includes check that the message type is correct - -uint32_t umsg_{{prefix}}_serialize_CRC(umsg_{{prefix}}_t* data, uint8_t* buffer); -uint8_t umsg_{{prefix}}_deserialize_CRC(umsg_{{prefix}}_t* data,uint8_t* buffer); // this function includes check that the message type is correct +// this method automatically appends the CRC to the struct +uint32_t umsg_{{prefix}}_receive_to_transfer(umsg_sub_handle_t queue,MessageToTransfer* msg); +/* +*/ {% endif %} {% endfor %} diff --git a/umsg_gen/umsg_gen/templates/msg_classes.c.j2 b/umsg_gen/umsg_gen/templates/msg_classes.c.j2 new file mode 100644 index 0000000..b60164b --- /dev/null +++ b/umsg_gen/umsg_gen/templates/msg_classes.c.j2 @@ -0,0 +1 @@ +#include "msg_classes.h" \ No newline at end of file diff --git a/umsg_gen/umsg_gen/templates/msg_classes.h.j2 b/umsg_gen/umsg_gen/templates/msg_classes.h.j2 index 315bbb1..d38b34b 100644 --- a/umsg_gen/umsg_gen/templates/msg_classes.h.j2 +++ b/umsg_gen/umsg_gen/templates/msg_classes.h.j2 @@ -9,11 +9,117 @@ extern "C" { typedef enum { -{% for val in headers%} -{{val.upper()}}{{ "," if not loop.last else "" }} +{% for topic_dict in topic_dict_list%} +UMSG_{{topic_dict.name.upper()}}{{ "," if not loop.last else "" }} {%endfor%} } umsg_classes_t; +// the plus one is there for a CRC checksum + + +//all the topic lists included + +{% for topic_dict in topic_dict_list%} +{% macro type_map(type) %} +{%- if type.lower()=="uint8" -%} +uint8_t +{%- elif type.lower()=="int8" -%} +int8_t +{%- elif type.lower()=="uint16" -%} +uint16_t +{%- elif type.lower()=="int16" -%} +int16_t +{%- elif type.lower()=="uint32" -%} +uint32_t +{%- elif type.lower()=="int32" -%} +int32_t +{%- elif type.lower()=="uint64" -%} +uint64_t +{%- elif type.lower()=="int64" -%} +int64_t +{%- elif type.lower()=="float" -%} +float +{%- elif type.lower()=="double" -%} +double +{%- elif type.lower()=="bool" -%} +bool +{%- elif type.lower()=="char" -%} +char +{%- else -%} +umsg_{{topic_dict.name}}_{{type.lower()}}_t +{%- endif%} +{% endmacro %} + // msg structure typedefs for {{topic_dict.name}} + {%if topic_dict.enums %} + + {% for enum in topic_dict.enums%} + typedef enum __attribute__((__packed__)) + { + {%for val in enum.enumerators%} + {{val.upper()}}{{ "," if not loop.last else "" }} + {%endfor%} + } umsg_{{topic_dict.name}}_{{enum.name}}_t; + + {%endfor%} + {% endif %} + + //enumeration of topics + typedef enum + { + {% for msg_dict in topic_dict.msgs %} + {{topic_dict.name.upper()}}_{{msg_dict.name.upper()}}{{', ' if not loop.last else ''}} + {% endfor -%} + } umsg_enum_{{topic_dict.name}}_t; + + + + {% for msg_dict in topic_dict.msgs %} + typedef struct + { + {% for field in msg_dict.fields %} + {%+ if not field.bitfield %}{{type_map(field.type)}} {{field.name}}{% if field.length %}[{{field.length}}]{% endif %};{% endif %} + {% if field.bitfield %}{{type_map(field.type)}} {%for bitfield in field.bitfield %}{{bitfield.name}} : {{bitfield.bits}}{{ ", " if not loop.last else ";" }}{%endfor%}{% endif +%} + {% endfor %} + } umsg_{{topic_dict.name}}_{{msg_dict.name}}_t; + + {% endfor -%} + + union umsg_{{topic_dict.name}}_Messages + { + {% for msg_dict in topic_dict.msgs %} + umsg_{{topic_dict.name}}_{{msg_dict.name}}_t {{msg_dict.name}}; + {% endfor -%} + }; +{%endfor%} + +struct Structured{ + uint8_t sync0; + uint8_t sync1; + uint8_t msg_class; + uint8_t msg_type; + union{ + {% for topic_dict in topic_dict_list%} + union umsg_{{topic_dict.name}}_Messages {{topic_dict.name}}; + {%endfor%} + }; +}; + + +typedef union { + struct Structured s; + uint8_t raw[sizeof(struct Structured) + 1]; + +}MessageToTransfer; + + +// this method only publishes the message if the CRC is correct +uint32_t umsg_publish_received(MessageToTransfer* msg); + + + + + + #ifdef __cplusplus } #endif diff --git a/umsg_gen/umsg_gen/umsg_gen.py b/umsg_gen/umsg_gen/umsg_gen.py index da8b154..705b615 100644 --- a/umsg_gen/umsg_gen/umsg_gen.py +++ b/umsg_gen/umsg_gen/umsg_gen.py @@ -56,10 +56,10 @@ def main(): # load topic json file f = open(file) topic_dict = json.load(f) - topic_dict_list.append(topic_dict) # add name field to topic dict topic_dict['name'] = Path(file).stem - + topic_dict_list.append(topic_dict) + # generate header filename = f'{output_path}/inc/umsg_{topic_dict["name"]}.h' Path(filename).parent.mkdir(parents=True, exist_ok=True) @@ -76,11 +76,11 @@ def main(): # add file name to list sources.append(Path(filename).name) - headers.append(f'umsg_{topic_dict["name"]}') + headers.append(f'{topic_dict["name"]}') # Generate the msg_classes header file - content = msg_class_inc_template.render(headers=headers, date=datetime.date.today()) + content = msg_class_inc_template.render(topic_dict_list = topic_dict_list, date=datetime.date.today()) filename = f'{output_path}/inc/umsg_classes.h' with open(filename, mode="w", encoding="utf-8") as message: message.write(content) diff --git a/umsg_lib/core/inc/umsg.h b/umsg_lib/core/inc/umsg.h index b263042..b5c4a68 100644 --- a/umsg_lib/core/inc/umsg.h +++ b/umsg_lib/core/inc/umsg.h @@ -13,29 +13,29 @@ extern "C" { typedef struct { - umsg_sub_handle_t sub_handle; - uint16_t prescaler; - uint8_t length; - uint8_t channel; - void* next_sub; + umsg_sub_handle_t sub_handle; + uint16_t prescaler; + uint8_t length; + uint8_t channel; + void* next_sub; } umsg_sub_t; typedef struct { - umsg_sub_t* sub_list; - void* msg_value; - uint32_t counter; - char* name; + umsg_sub_t* sub_list; + void* msg_value; + uint32_t counter; + char* name; } umsg_msg_metadata_t; umsg_sub_handle_t umsg_subscribe(umsg_msg_metadata_t* msg, uint16_t prescaler, uint32_t size, uint8_t length, uint8_t ch_id); -void umsg_publish(umsg_msg_metadata_t* msg, void* data, uint8_t ch_id); -uint8_t umsg_receive(umsg_sub_handle_t queue, void* data, uint32_t timeout); -uint8_t umsg_peek(umsg_msg_metadata_t* msg, void* data, uint32_t size); +void umsg_publish(umsg_msg_metadata_t* msg, void* data, uint8_t ch_id); +uint8_t umsg_receive(umsg_sub_handle_t queue, void* data, uint32_t timeout); +uint8_t umsg_peek(umsg_msg_metadata_t* msg, void* data, uint32_t size); #ifdef __cplusplus } #endif -#endif //UMSG_UMSG_H +#endif // UMSG_UMSG_H diff --git a/umsg_lib/core/inc/umsg_port.h b/umsg_lib/core/inc/umsg_port.h index 5cd4ed1..eb632fd 100644 --- a/umsg_lib/core/inc/umsg_port.h +++ b/umsg_lib/core/inc/umsg_port.h @@ -10,13 +10,13 @@ extern "C" { #include -void * umsg_port_malloc(uint32_t size); -void * umsg_port_create(uint32_t size, uint8_t length); -void umsg_port_send(umsg_sub_t* sub, void * data); -uint8_t umsg_port_receive(umsg_sub_handle_t sub_handle, void * data, uint32_t timeout); +void* umsg_port_malloc(uint32_t size); +void* umsg_port_create(uint32_t size, uint8_t length); +void umsg_port_send(umsg_sub_t* sub, void* data); +uint8_t umsg_port_receive(umsg_sub_handle_t sub_handle, void* data, uint32_t timeout); #ifdef __cplusplus } #endif -#endif //UMSG_UMSG_PORT_H +#endif // UMSG_UMSG_PORT_H diff --git a/umsg_lib/core/inc/umsg_types.h b/umsg_lib/core/inc/umsg_types.h index 94e395d..2a2b6a2 100644 --- a/umsg_lib/core/inc/umsg_types.h +++ b/umsg_lib/core/inc/umsg_types.h @@ -18,4 +18,4 @@ typedef void* umsg_sub_handle_t; } #endif -#endif //UMSG_UMSG_TYPES_H +#endif // UMSG_UMSG_TYPES_H diff --git a/umsg_lib/core/src/port_freertos.c b/umsg_lib/core/src/port_freertos.c index 53233a3..e8577d4 100644 --- a/umsg_lib/core/src/port_freertos.c +++ b/umsg_lib/core/src/port_freertos.c @@ -7,64 +7,48 @@ #include // obtained from cmsis core.h. All cortex M processors have this register at this address -const uint32_t* ARM_CORTEX_ICSR = (uint32_t*)(0xE000E000UL+0x0D00UL+0x004); -const uint32_t SCB_ICSR_VECTACTIVE_POS = 0x1FFUL; +const uint32_t* ARM_CORTEX_ICSR = (uint32_t*)(0xE000E000UL + 0x0D00UL + 0x004); +const uint32_t SCB_ICSR_VECTACTIVE_POS = 0x1FFUL; -bool is_isr_active() -{ +bool is_isr_active() { #if defined(__GNUC__) && defined(__arm__) - // if the current active vector is 0, then we are not in an ISR - return (*ARM_CORTEX_ICSR & SCB_ICSR_VECTACTIVE_POS) != 0; + // if the current active vector is 0, then we are not in an ISR + return (*ARM_CORTEX_ICSR & SCB_ICSR_VECTACTIVE_POS) != 0; #endif - return false; + return false; } -void * umsg_port_malloc(uint32_t size) -{ - return pvPortMalloc(size); +void* umsg_port_malloc(uint32_t size) { + return pvPortMalloc(size); } -umsg_sub_handle_t umsg_port_create(uint32_t size, uint8_t length) -{ - return xQueueCreate(length, size); +umsg_sub_handle_t umsg_port_create(uint32_t size, uint8_t length) { + return xQueueCreate(length, size); } -void umsg_port_send(umsg_sub_t* sub, void * data) -{ - QueueHandle_t queue = (QueueHandle_t)sub->sub_handle; - if(sub->length > 1) - { - if(is_isr_active()) - { - BaseType_t xHigherPriorityTaskWoken; - xQueueSendToBackFromISR(queue, data, - &xHigherPriorityTaskWoken); - portYIELD_FROM_ISR(xHigherPriorityTaskWoken); +void umsg_port_send(umsg_sub_t* sub, void* data) { + QueueHandle_t queue = (QueueHandle_t)sub->sub_handle; + if (sub->length > 1) { + if (is_isr_active()) { + BaseType_t xHigherPriorityTaskWoken; + xQueueSendToBackFromISR(queue, data, &xHigherPriorityTaskWoken); + portYIELD_FROM_ISR(xHigherPriorityTaskWoken); - } - else - { - xQueueSendToBack(queue, data, 0); - } + } else { + xQueueSendToBack(queue, data, 0); } - else - { - // check if in interrupt context - if(is_isr_active()) - { - BaseType_t xHigherPriorityTaskWoken; - xQueueOverwriteFromISR(queue, data, - &xHigherPriorityTaskWoken); - portYIELD_FROM_ISR(xHigherPriorityTaskWoken); - } - else - { - xQueueOverwrite(queue, data); - } + } else { + // check if in interrupt context + if (is_isr_active()) { + BaseType_t xHigherPriorityTaskWoken; + xQueueOverwriteFromISR(queue, data, &xHigherPriorityTaskWoken); + portYIELD_FROM_ISR(xHigherPriorityTaskWoken); + } else { + xQueueOverwrite(queue, data); } + } } -uint8_t umsg_port_receive(umsg_sub_handle_t sub_handle, void * data, uint32_t timeout) -{ - return xQueueReceive((QueueHandle_t)sub_handle, data, timeout); +uint8_t umsg_port_receive(umsg_sub_handle_t sub_handle, void* data, uint32_t timeout) { + return xQueueReceive((QueueHandle_t)sub_handle, data, timeout); } \ No newline at end of file diff --git a/umsg_lib/core/src/port_posix.c b/umsg_lib/core/src/port_posix.c index 46ca460..0f9fad4 100644 --- a/umsg_lib/core/src/port_posix.c +++ b/umsg_lib/core/src/port_posix.c @@ -4,19 +4,14 @@ #include -void * umsg_port_malloc(uint32_t size) -{ - return 0; +void* umsg_port_malloc(uint32_t size) { + return 0; } -void * umsg_port_create(uint32_t size, uint8_t length) -{ - return 0; +void* umsg_port_create(uint32_t size, uint8_t length) { + return 0; } -void umsg_port_send(umsg_sub_t* sub, void * data) -{ - +void umsg_port_send(umsg_sub_t* sub, void* data) { } -uint8_t umsg_port_receive(umsg_sub_handle_t sub_handle, void * data, uint32_t timeout) -{ - return 0; +uint8_t umsg_port_receive(umsg_sub_handle_t sub_handle, void* data, uint32_t timeout) { + return 0; } \ No newline at end of file diff --git a/umsg_lib/inc/umsg_battery.h b/umsg_lib/inc/umsg_battery.h index 746c636..cd09240 100644 --- a/umsg_lib/inc/umsg_battery.h +++ b/umsg_lib/inc/umsg_battery.h @@ -12,44 +12,40 @@ extern "C" { typedef enum { - BATTERY_OK, - BATTERY_LOW, - BATTERY_DEAD + BATTERY_OK, + BATTERY_LOW, + BATTERY_DEAD } umsg_battery_battery_state_t; -//enumeration of topics +// enumeration of topics typedef enum { - BATTERY_STATE + BATTERY_STATE } umsg_enum_battery_t; - typedef struct { - umsg_battery_battery_state_t state; - uint8_t low_battery : 1, critical_battery : 1, high_temperature : 1, low_temperature : 1, charging : 1, discharging : 1, full : 1, not_present : 1; + umsg_battery_battery_state_t state; + uint8_t low_battery : 1, critical_battery : 1, high_temperature : 1, low_temperature : 1, charging : 1, discharging : 1, full : 1, not_present : 1; } umsg_battery_state_t; // api function headers umsg_sub_handle_t umsg_battery_state_subscribe(uint32_t prescaler, uint8_t length); umsg_sub_handle_t umsg_battery_state_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel); -void umsg_battery_state_publish(umsg_battery_state_t* data); -void umsg_battery_state_publish_ch(umsg_battery_state_t* data, uint8_t channel); -uint8_t umsg_battery_state_receive(umsg_sub_handle_t queue, umsg_battery_state_t* data, uint32_t timeout); -uint8_t umsg_battery_state_peek(umsg_battery_state_t* data); - -//function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class and type -//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future -//please take care that the messages are build properly to avoid padding issues if the messages are opened on different system +void umsg_battery_state_publish(umsg_battery_state_t* data); +void umsg_battery_state_publish_ch(umsg_battery_state_t* data, uint8_t channel); +uint8_t umsg_battery_state_receive(umsg_sub_handle_t queue, umsg_battery_state_t* data, uint32_t timeout); +uint8_t umsg_battery_state_peek(umsg_battery_state_t* data); + +// function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class +// and type for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future please take +// care that the messages are build properly to avoid padding issues if the messages are opened on different system uint32_t umsg_battery_state_serialize(umsg_battery_state_t* data, uint8_t* buffer); -uint8_t umsg_battery_state_deserialize(umsg_battery_state_t* data,uint8_t* buffer); // this function includes check that the message type is correct - - +uint8_t umsg_battery_state_deserialize(umsg_battery_state_t* data, uint8_t* buffer); // this function includes check that the message type is correct #ifdef __cplusplus } #endif - diff --git a/umsg_lib/inc/umsg_classes.h b/umsg_lib/inc/umsg_classes.h index 6ccc875..4293809 100644 --- a/umsg_lib/inc/umsg_classes.h +++ b/umsg_lib/inc/umsg_classes.h @@ -9,16 +9,14 @@ extern "C" { typedef enum { -UMSG_BATTERY, -UMSG_CONTROL, -UMSG_UNUSED, -UMSG_TEST, -UMSG_SENSORS, -UMSG_EXAMPLE + UMSG_BATTERY, + UMSG_CONTROL, + UMSG_UNUSED, + UMSG_TEST, + UMSG_SENSORS, + UMSG_EXAMPLE } umsg_classes_t; #ifdef __cplusplus } #endif - - diff --git a/umsg_lib/inc/umsg_control.h b/umsg_lib/inc/umsg_control.h index fa15838..0bfd554 100644 --- a/umsg_lib/inc/umsg_control.h +++ b/umsg_lib/inc/umsg_control.h @@ -10,39 +10,35 @@ extern "C" { #include "umsg_classes.h" // msg structure typedefs -//enumeration of topics +// enumeration of topics typedef enum { - CONTROL_SETPOINTS + CONTROL_SETPOINTS } umsg_enum_control_t; - typedef struct { - float w[3]; - float vel_b[3]; - float quat[4]; + float w[3]; + float vel_b[3]; + float quat[4]; } umsg_control_setpoints_t; // api function headers umsg_sub_handle_t umsg_control_setpoints_subscribe(uint32_t prescaler, uint8_t length); umsg_sub_handle_t umsg_control_setpoints_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel); -void umsg_control_setpoints_publish(umsg_control_setpoints_t* data); -void umsg_control_setpoints_publish_ch(umsg_control_setpoints_t* data, uint8_t channel); -uint8_t umsg_control_setpoints_receive(umsg_sub_handle_t queue, umsg_control_setpoints_t* data, uint32_t timeout); -uint8_t umsg_control_setpoints_peek(umsg_control_setpoints_t* data); - -//function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class and type -//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future -//please take care that the messages are build properly to avoid padding issues if the messages are opened on different system +void umsg_control_setpoints_publish(umsg_control_setpoints_t* data); +void umsg_control_setpoints_publish_ch(umsg_control_setpoints_t* data, uint8_t channel); +uint8_t umsg_control_setpoints_receive(umsg_sub_handle_t queue, umsg_control_setpoints_t* data, uint32_t timeout); +uint8_t umsg_control_setpoints_peek(umsg_control_setpoints_t* data); + +// function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class +// and type for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future please take +// care that the messages are build properly to avoid padding issues if the messages are opened on different system uint32_t umsg_control_setpoints_serialize(umsg_control_setpoints_t* data, uint8_t* buffer); -uint8_t umsg_control_setpoints_deserialize(umsg_control_setpoints_t* data,uint8_t* buffer); // this function includes check that the message type is correct - - +uint8_t umsg_control_setpoints_deserialize(umsg_control_setpoints_t* data, uint8_t* buffer); // this function includes check that the message type is correct #ifdef __cplusplus } #endif - diff --git a/umsg_lib/inc/umsg_example.h b/umsg_lib/inc/umsg_example.h index 5ee11be..8bf3fc6 100644 --- a/umsg_lib/inc/umsg_example.h +++ b/umsg_lib/inc/umsg_example.h @@ -12,65 +12,62 @@ extern "C" { typedef enum { - GREEN, - BLUE, - READ + GREEN, + BLUE, + READ } umsg_example_colors_t; -//enumeration of topics +// enumeration of topics typedef enum { - EXAMPLE_COLOR_SELECTION, - EXAMPLE_SIMPLE_MSG + EXAMPLE_COLOR_SELECTION, + EXAMPLE_SIMPLE_MSG } umsg_enum_example_t; - typedef struct { - umsg_example_colors_t chosen_color; + umsg_example_colors_t chosen_color; } umsg_example_color_selection_t; typedef struct { - char name[10]; - uint8_t age; - float height; - uint8_t married : 1, has_children : 1, has_dog : 1; + char name[10]; + uint8_t age; + float height; + uint8_t married : 1, has_children : 1, has_dog : 1; } umsg_example_simple_msg_t; // api function headers umsg_sub_handle_t umsg_example_color_selection_subscribe(uint32_t prescaler, uint8_t length); umsg_sub_handle_t umsg_example_color_selection_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel); -void umsg_example_color_selection_publish(umsg_example_color_selection_t* data); -void umsg_example_color_selection_publish_ch(umsg_example_color_selection_t* data, uint8_t channel); -uint8_t umsg_example_color_selection_receive(umsg_sub_handle_t queue, umsg_example_color_selection_t* data, uint32_t timeout); -uint8_t umsg_example_color_selection_peek(umsg_example_color_selection_t* data); - -//function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class and type -//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future -//please take care that the messages are build properly to avoid padding issues if the messages are opened on different system +void umsg_example_color_selection_publish(umsg_example_color_selection_t* data); +void umsg_example_color_selection_publish_ch(umsg_example_color_selection_t* data, uint8_t channel); +uint8_t umsg_example_color_selection_receive(umsg_sub_handle_t queue, umsg_example_color_selection_t* data, uint32_t timeout); +uint8_t umsg_example_color_selection_peek(umsg_example_color_selection_t* data); + +// function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class +// and type for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future please take +// care that the messages are build properly to avoid padding issues if the messages are opened on different system uint32_t umsg_example_color_selection_serialize(umsg_example_color_selection_t* data, uint8_t* buffer); -uint8_t umsg_example_color_selection_deserialize(umsg_example_color_selection_t* data,uint8_t* buffer); // this function includes check that the message type is correct +uint8_t umsg_example_color_selection_deserialize(umsg_example_color_selection_t* data, + uint8_t* buffer); // this function includes check that the message type is correct umsg_sub_handle_t umsg_example_simple_msg_subscribe(uint32_t prescaler, uint8_t length); umsg_sub_handle_t umsg_example_simple_msg_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel); -void umsg_example_simple_msg_publish(umsg_example_simple_msg_t* data); -void umsg_example_simple_msg_publish_ch(umsg_example_simple_msg_t* data, uint8_t channel); -uint8_t umsg_example_simple_msg_receive(umsg_sub_handle_t queue, umsg_example_simple_msg_t* data, uint32_t timeout); -uint8_t umsg_example_simple_msg_peek(umsg_example_simple_msg_t* data); - -//function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class and type -//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future -//please take care that the messages are build properly to avoid padding issues if the messages are opened on different system +void umsg_example_simple_msg_publish(umsg_example_simple_msg_t* data); +void umsg_example_simple_msg_publish_ch(umsg_example_simple_msg_t* data, uint8_t channel); +uint8_t umsg_example_simple_msg_receive(umsg_sub_handle_t queue, umsg_example_simple_msg_t* data, uint32_t timeout); +uint8_t umsg_example_simple_msg_peek(umsg_example_simple_msg_t* data); + +// function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class +// and type for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future please take +// care that the messages are build properly to avoid padding issues if the messages are opened on different system uint32_t umsg_example_simple_msg_serialize(umsg_example_simple_msg_t* data, uint8_t* buffer); -uint8_t umsg_example_simple_msg_deserialize(umsg_example_simple_msg_t* data,uint8_t* buffer); // this function includes check that the message type is correct - - +uint8_t umsg_example_simple_msg_deserialize(umsg_example_simple_msg_t* data, uint8_t* buffer); // this function includes check that the message type is correct #ifdef __cplusplus } #endif - diff --git a/umsg_lib/inc/umsg_sensors.h b/umsg_lib/inc/umsg_sensors.h index 13f1a07..be6b8b8 100644 --- a/umsg_lib/inc/umsg_sensors.h +++ b/umsg_lib/inc/umsg_sensors.h @@ -10,59 +10,55 @@ extern "C" { #include "umsg_classes.h" // msg structure typedefs -//enumeration of topics +// enumeration of topics typedef enum { - SENSORS_IMU, - SENSORS_BARO + SENSORS_IMU, + SENSORS_BARO } umsg_enum_sensors_t; - typedef struct { - float gyro[3]; - float accel[3]; - float temperature; + float gyro[3]; + float accel[3]; + float temperature; } umsg_sensors_imu_t; typedef struct { - float pressure; - float temperature; + float pressure; + float temperature; } umsg_sensors_baro_t; // api function headers umsg_sub_handle_t umsg_sensors_imu_subscribe(uint32_t prescaler, uint8_t length); umsg_sub_handle_t umsg_sensors_imu_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel); -void umsg_sensors_imu_publish(umsg_sensors_imu_t* data); -void umsg_sensors_imu_publish_ch(umsg_sensors_imu_t* data, uint8_t channel); -uint8_t umsg_sensors_imu_receive(umsg_sub_handle_t queue, umsg_sensors_imu_t* data, uint32_t timeout); -uint8_t umsg_sensors_imu_peek(umsg_sensors_imu_t* data); - -//function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class and type -//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future -//please take care that the messages are build properly to avoid padding issues if the messages are opened on different system +void umsg_sensors_imu_publish(umsg_sensors_imu_t* data); +void umsg_sensors_imu_publish_ch(umsg_sensors_imu_t* data, uint8_t channel); +uint8_t umsg_sensors_imu_receive(umsg_sub_handle_t queue, umsg_sensors_imu_t* data, uint32_t timeout); +uint8_t umsg_sensors_imu_peek(umsg_sensors_imu_t* data); + +// function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class +// and type for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future please take +// care that the messages are build properly to avoid padding issues if the messages are opened on different system uint32_t umsg_sensors_imu_serialize(umsg_sensors_imu_t* data, uint8_t* buffer); -uint8_t umsg_sensors_imu_deserialize(umsg_sensors_imu_t* data,uint8_t* buffer); // this function includes check that the message type is correct +uint8_t umsg_sensors_imu_deserialize(umsg_sensors_imu_t* data, uint8_t* buffer); // this function includes check that the message type is correct umsg_sub_handle_t umsg_sensors_baro_subscribe(uint32_t prescaler, uint8_t length); umsg_sub_handle_t umsg_sensors_baro_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel); -void umsg_sensors_baro_publish(umsg_sensors_baro_t* data); -void umsg_sensors_baro_publish_ch(umsg_sensors_baro_t* data, uint8_t channel); -uint8_t umsg_sensors_baro_receive(umsg_sub_handle_t queue, umsg_sensors_baro_t* data, uint32_t timeout); -uint8_t umsg_sensors_baro_peek(umsg_sensors_baro_t* data); - -//function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class and type -//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future -//please take care that the messages are build properly to avoid padding issues if the messages are opened on different system +void umsg_sensors_baro_publish(umsg_sensors_baro_t* data); +void umsg_sensors_baro_publish_ch(umsg_sensors_baro_t* data, uint8_t channel); +uint8_t umsg_sensors_baro_receive(umsg_sub_handle_t queue, umsg_sensors_baro_t* data, uint32_t timeout); +uint8_t umsg_sensors_baro_peek(umsg_sensors_baro_t* data); + +// function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class +// and type for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future please take +// care that the messages are build properly to avoid padding issues if the messages are opened on different system uint32_t umsg_sensors_baro_serialize(umsg_sensors_baro_t* data, uint8_t* buffer); -uint8_t umsg_sensors_baro_deserialize(umsg_sensors_baro_t* data,uint8_t* buffer); // this function includes check that the message type is correct - - +uint8_t umsg_sensors_baro_deserialize(umsg_sensors_baro_t* data, uint8_t* buffer); // this function includes check that the message type is correct #ifdef __cplusplus } #endif - diff --git a/umsg_lib/inc/umsg_test.h b/umsg_lib/inc/umsg_test.h index 755baeb..be70219 100644 --- a/umsg_lib/inc/umsg_test.h +++ b/umsg_lib/inc/umsg_test.h @@ -12,177 +12,173 @@ extern "C" { typedef enum { - ENUM_A, - ENUM_B, - ENUM_C + ENUM_A, + ENUM_B, + ENUM_C } umsg_test_enum_test_t; -//enumeration of topics +// enumeration of topics typedef enum { - TEST_FLOATS, - TEST_UINTS, - TEST_INTS, - TEST_STRINGS, - TEST_BOOLS, - TEST_ENUMS, - TEST_BITFIELD + TEST_FLOATS, + TEST_UINTS, + TEST_INTS, + TEST_STRINGS, + TEST_BOOLS, + TEST_ENUMS, + TEST_BITFIELD } umsg_enum_test_t; - typedef struct { - float single; - double double_var; - float single_array[3]; - double double_array[3]; + float single; + double double_var; + float single_array[3]; + double double_array[3]; } umsg_test_floats_t; typedef struct { - uint8_t u8; - uint16_t u16; - uint32_t u32; - uint64_t u64; - uint8_t u8array[3]; - uint16_t u16array[3]; - uint32_t u32array[3]; - uint64_t u64array[3]; + uint8_t u8; + uint16_t u16; + uint32_t u32; + uint64_t u64; + uint8_t u8array[3]; + uint16_t u16array[3]; + uint32_t u32array[3]; + uint64_t u64array[3]; } umsg_test_uints_t; typedef struct { - int8_t i8; - int16_t i16; - int32_t i32; - int64_t i64; - int8_t i8array[3]; - int16_t i16array[3]; - int32_t i32array[3]; - int64_t i64array[3]; + int8_t i8; + int16_t i16; + int32_t i32; + int64_t i64; + int8_t i8array[3]; + int16_t i16array[3]; + int32_t i32array[3]; + int64_t i64array[3]; } umsg_test_ints_t; typedef struct { - char single; - char array[20]; + char single; + char array[20]; } umsg_test_strings_t; typedef struct { - bool a; - bool b[3]; + bool a; + bool b[3]; } umsg_test_bools_t; typedef struct { - umsg_test_enum_test_t single_enum; - umsg_test_enum_test_t enum_array[3]; + umsg_test_enum_test_t single_enum; + umsg_test_enum_test_t enum_array[3]; } umsg_test_enums_t; typedef struct { - uint8_t a : 1, b : 2, c : 4; + uint8_t a : 1, b : 2, c : 4; } umsg_test_bitfield_t; // api function headers umsg_sub_handle_t umsg_test_floats_subscribe(uint32_t prescaler, uint8_t length); umsg_sub_handle_t umsg_test_floats_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel); -void umsg_test_floats_publish(umsg_test_floats_t* data); -void umsg_test_floats_publish_ch(umsg_test_floats_t* data, uint8_t channel); -uint8_t umsg_test_floats_receive(umsg_sub_handle_t queue, umsg_test_floats_t* data, uint32_t timeout); -uint8_t umsg_test_floats_peek(umsg_test_floats_t* data); - -//function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class and type -//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future -//please take care that the messages are build properly to avoid padding issues if the messages are opened on different system +void umsg_test_floats_publish(umsg_test_floats_t* data); +void umsg_test_floats_publish_ch(umsg_test_floats_t* data, uint8_t channel); +uint8_t umsg_test_floats_receive(umsg_sub_handle_t queue, umsg_test_floats_t* data, uint32_t timeout); +uint8_t umsg_test_floats_peek(umsg_test_floats_t* data); + +// function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class +// and type for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future please take +// care that the messages are build properly to avoid padding issues if the messages are opened on different system uint32_t umsg_test_floats_serialize(umsg_test_floats_t* data, uint8_t* buffer); -uint8_t umsg_test_floats_deserialize(umsg_test_floats_t* data,uint8_t* buffer); // this function includes check that the message type is correct +uint8_t umsg_test_floats_deserialize(umsg_test_floats_t* data, uint8_t* buffer); // this function includes check that the message type is correct umsg_sub_handle_t umsg_test_uints_subscribe(uint32_t prescaler, uint8_t length); umsg_sub_handle_t umsg_test_uints_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel); -void umsg_test_uints_publish(umsg_test_uints_t* data); -void umsg_test_uints_publish_ch(umsg_test_uints_t* data, uint8_t channel); -uint8_t umsg_test_uints_receive(umsg_sub_handle_t queue, umsg_test_uints_t* data, uint32_t timeout); -uint8_t umsg_test_uints_peek(umsg_test_uints_t* data); - -//function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class and type -//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future -//please take care that the messages are build properly to avoid padding issues if the messages are opened on different system +void umsg_test_uints_publish(umsg_test_uints_t* data); +void umsg_test_uints_publish_ch(umsg_test_uints_t* data, uint8_t channel); +uint8_t umsg_test_uints_receive(umsg_sub_handle_t queue, umsg_test_uints_t* data, uint32_t timeout); +uint8_t umsg_test_uints_peek(umsg_test_uints_t* data); + +// function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class +// and type for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future please take +// care that the messages are build properly to avoid padding issues if the messages are opened on different system uint32_t umsg_test_uints_serialize(umsg_test_uints_t* data, uint8_t* buffer); -uint8_t umsg_test_uints_deserialize(umsg_test_uints_t* data,uint8_t* buffer); // this function includes check that the message type is correct +uint8_t umsg_test_uints_deserialize(umsg_test_uints_t* data, uint8_t* buffer); // this function includes check that the message type is correct umsg_sub_handle_t umsg_test_ints_subscribe(uint32_t prescaler, uint8_t length); umsg_sub_handle_t umsg_test_ints_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel); -void umsg_test_ints_publish(umsg_test_ints_t* data); -void umsg_test_ints_publish_ch(umsg_test_ints_t* data, uint8_t channel); -uint8_t umsg_test_ints_receive(umsg_sub_handle_t queue, umsg_test_ints_t* data, uint32_t timeout); -uint8_t umsg_test_ints_peek(umsg_test_ints_t* data); - -//function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class and type -//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future -//please take care that the messages are build properly to avoid padding issues if the messages are opened on different system +void umsg_test_ints_publish(umsg_test_ints_t* data); +void umsg_test_ints_publish_ch(umsg_test_ints_t* data, uint8_t channel); +uint8_t umsg_test_ints_receive(umsg_sub_handle_t queue, umsg_test_ints_t* data, uint32_t timeout); +uint8_t umsg_test_ints_peek(umsg_test_ints_t* data); + +// function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class +// and type for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future please take +// care that the messages are build properly to avoid padding issues if the messages are opened on different system uint32_t umsg_test_ints_serialize(umsg_test_ints_t* data, uint8_t* buffer); -uint8_t umsg_test_ints_deserialize(umsg_test_ints_t* data,uint8_t* buffer); // this function includes check that the message type is correct +uint8_t umsg_test_ints_deserialize(umsg_test_ints_t* data, uint8_t* buffer); // this function includes check that the message type is correct umsg_sub_handle_t umsg_test_strings_subscribe(uint32_t prescaler, uint8_t length); umsg_sub_handle_t umsg_test_strings_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel); -void umsg_test_strings_publish(umsg_test_strings_t* data); -void umsg_test_strings_publish_ch(umsg_test_strings_t* data, uint8_t channel); -uint8_t umsg_test_strings_receive(umsg_sub_handle_t queue, umsg_test_strings_t* data, uint32_t timeout); -uint8_t umsg_test_strings_peek(umsg_test_strings_t* data); - -//function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class and type -//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future -//please take care that the messages are build properly to avoid padding issues if the messages are opened on different system +void umsg_test_strings_publish(umsg_test_strings_t* data); +void umsg_test_strings_publish_ch(umsg_test_strings_t* data, uint8_t channel); +uint8_t umsg_test_strings_receive(umsg_sub_handle_t queue, umsg_test_strings_t* data, uint32_t timeout); +uint8_t umsg_test_strings_peek(umsg_test_strings_t* data); + +// function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class +// and type for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future please take +// care that the messages are build properly to avoid padding issues if the messages are opened on different system uint32_t umsg_test_strings_serialize(umsg_test_strings_t* data, uint8_t* buffer); -uint8_t umsg_test_strings_deserialize(umsg_test_strings_t* data,uint8_t* buffer); // this function includes check that the message type is correct +uint8_t umsg_test_strings_deserialize(umsg_test_strings_t* data, uint8_t* buffer); // this function includes check that the message type is correct umsg_sub_handle_t umsg_test_bools_subscribe(uint32_t prescaler, uint8_t length); umsg_sub_handle_t umsg_test_bools_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel); -void umsg_test_bools_publish(umsg_test_bools_t* data); -void umsg_test_bools_publish_ch(umsg_test_bools_t* data, uint8_t channel); -uint8_t umsg_test_bools_receive(umsg_sub_handle_t queue, umsg_test_bools_t* data, uint32_t timeout); -uint8_t umsg_test_bools_peek(umsg_test_bools_t* data); - -//function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class and type -//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future -//please take care that the messages are build properly to avoid padding issues if the messages are opened on different system +void umsg_test_bools_publish(umsg_test_bools_t* data); +void umsg_test_bools_publish_ch(umsg_test_bools_t* data, uint8_t channel); +uint8_t umsg_test_bools_receive(umsg_sub_handle_t queue, umsg_test_bools_t* data, uint32_t timeout); +uint8_t umsg_test_bools_peek(umsg_test_bools_t* data); + +// function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class +// and type for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future please take +// care that the messages are build properly to avoid padding issues if the messages are opened on different system uint32_t umsg_test_bools_serialize(umsg_test_bools_t* data, uint8_t* buffer); -uint8_t umsg_test_bools_deserialize(umsg_test_bools_t* data,uint8_t* buffer); // this function includes check that the message type is correct +uint8_t umsg_test_bools_deserialize(umsg_test_bools_t* data, uint8_t* buffer); // this function includes check that the message type is correct umsg_sub_handle_t umsg_test_enums_subscribe(uint32_t prescaler, uint8_t length); umsg_sub_handle_t umsg_test_enums_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel); -void umsg_test_enums_publish(umsg_test_enums_t* data); -void umsg_test_enums_publish_ch(umsg_test_enums_t* data, uint8_t channel); -uint8_t umsg_test_enums_receive(umsg_sub_handle_t queue, umsg_test_enums_t* data, uint32_t timeout); -uint8_t umsg_test_enums_peek(umsg_test_enums_t* data); - -//function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class and type -//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future -//please take care that the messages are build properly to avoid padding issues if the messages are opened on different system +void umsg_test_enums_publish(umsg_test_enums_t* data); +void umsg_test_enums_publish_ch(umsg_test_enums_t* data, uint8_t channel); +uint8_t umsg_test_enums_receive(umsg_sub_handle_t queue, umsg_test_enums_t* data, uint32_t timeout); +uint8_t umsg_test_enums_peek(umsg_test_enums_t* data); + +// function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class +// and type for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future please take +// care that the messages are build properly to avoid padding issues if the messages are opened on different system uint32_t umsg_test_enums_serialize(umsg_test_enums_t* data, uint8_t* buffer); -uint8_t umsg_test_enums_deserialize(umsg_test_enums_t* data,uint8_t* buffer); // this function includes check that the message type is correct +uint8_t umsg_test_enums_deserialize(umsg_test_enums_t* data, uint8_t* buffer); // this function includes check that the message type is correct umsg_sub_handle_t umsg_test_bitfield_subscribe(uint32_t prescaler, uint8_t length); umsg_sub_handle_t umsg_test_bitfield_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel); -void umsg_test_bitfield_publish(umsg_test_bitfield_t* data); -void umsg_test_bitfield_publish_ch(umsg_test_bitfield_t* data, uint8_t channel); -uint8_t umsg_test_bitfield_receive(umsg_sub_handle_t queue, umsg_test_bitfield_t* data, uint32_t timeout); -uint8_t umsg_test_bitfield_peek(umsg_test_bitfield_t* data); - -//function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class and type -//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future -//please take care that the messages are build properly to avoid padding issues if the messages are opened on different system +void umsg_test_bitfield_publish(umsg_test_bitfield_t* data); +void umsg_test_bitfield_publish_ch(umsg_test_bitfield_t* data, uint8_t channel); +uint8_t umsg_test_bitfield_receive(umsg_sub_handle_t queue, umsg_test_bitfield_t* data, uint32_t timeout); +uint8_t umsg_test_bitfield_peek(umsg_test_bitfield_t* data); + +// function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class +// and type for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future please take +// care that the messages are build properly to avoid padding issues if the messages are opened on different system uint32_t umsg_test_bitfield_serialize(umsg_test_bitfield_t* data, uint8_t* buffer); -uint8_t umsg_test_bitfield_deserialize(umsg_test_bitfield_t* data,uint8_t* buffer); // this function includes check that the message type is correct - - +uint8_t umsg_test_bitfield_deserialize(umsg_test_bitfield_t* data, uint8_t* buffer); // this function includes check that the message type is correct #ifdef __cplusplus } #endif - diff --git a/umsg_lib/inc/umsg_unused.h b/umsg_lib/inc/umsg_unused.h index 6dc2c7a..905c303 100644 --- a/umsg_lib/inc/umsg_unused.h +++ b/umsg_lib/inc/umsg_unused.h @@ -10,58 +10,54 @@ extern "C" { #include "umsg_classes.h" // msg structure typedefs -//enumeration of topics +// enumeration of topics typedef enum { - UNUSED_USED_VAR, - UNUSED_UNUSED_VAR + UNUSED_USED_VAR, + UNUSED_UNUSED_VAR } umsg_enum_unused_t; - typedef struct { - uint8_t a; - uint8_t b; - uint8_t c; + uint8_t a; + uint8_t b; + uint8_t c; } umsg_unused_used_var_t; typedef struct { - uint64_t a[512]; + uint64_t a[512]; } umsg_unused_unused_var_t; // api function headers umsg_sub_handle_t umsg_unused_used_var_subscribe(uint32_t prescaler, uint8_t length); umsg_sub_handle_t umsg_unused_used_var_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel); -void umsg_unused_used_var_publish(umsg_unused_used_var_t* data); -void umsg_unused_used_var_publish_ch(umsg_unused_used_var_t* data, uint8_t channel); -uint8_t umsg_unused_used_var_receive(umsg_sub_handle_t queue, umsg_unused_used_var_t* data, uint32_t timeout); -uint8_t umsg_unused_used_var_peek(umsg_unused_used_var_t* data); - -//function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class and type -//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future -//please take care that the messages are build properly to avoid padding issues if the messages are opened on different system +void umsg_unused_used_var_publish(umsg_unused_used_var_t* data); +void umsg_unused_used_var_publish_ch(umsg_unused_used_var_t* data, uint8_t channel); +uint8_t umsg_unused_used_var_receive(umsg_sub_handle_t queue, umsg_unused_used_var_t* data, uint32_t timeout); +uint8_t umsg_unused_used_var_peek(umsg_unused_used_var_t* data); + +// function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class +// and type for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future please take +// care that the messages are build properly to avoid padding issues if the messages are opened on different system uint32_t umsg_unused_used_var_serialize(umsg_unused_used_var_t* data, uint8_t* buffer); -uint8_t umsg_unused_used_var_deserialize(umsg_unused_used_var_t* data,uint8_t* buffer); // this function includes check that the message type is correct +uint8_t umsg_unused_used_var_deserialize(umsg_unused_used_var_t* data, uint8_t* buffer); // this function includes check that the message type is correct umsg_sub_handle_t umsg_unused_unused_var_subscribe(uint32_t prescaler, uint8_t length); umsg_sub_handle_t umsg_unused_unused_var_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel); -void umsg_unused_unused_var_publish(umsg_unused_unused_var_t* data); -void umsg_unused_unused_var_publish_ch(umsg_unused_unused_var_t* data, uint8_t channel); -uint8_t umsg_unused_unused_var_receive(umsg_sub_handle_t queue, umsg_unused_unused_var_t* data, uint32_t timeout); -uint8_t umsg_unused_unused_var_peek(umsg_unused_unused_var_t* data); - -//function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class and type -//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future -//please take care that the messages are build properly to avoid padding issues if the messages are opened on different system +void umsg_unused_unused_var_publish(umsg_unused_unused_var_t* data); +void umsg_unused_unused_var_publish_ch(umsg_unused_unused_var_t* data, uint8_t channel); +uint8_t umsg_unused_unused_var_receive(umsg_sub_handle_t queue, umsg_unused_unused_var_t* data, uint32_t timeout); +uint8_t umsg_unused_unused_var_peek(umsg_unused_unused_var_t* data); + +// function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class +// and type for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future please take +// care that the messages are build properly to avoid padding issues if the messages are opened on different system uint32_t umsg_unused_unused_var_serialize(umsg_unused_unused_var_t* data, uint8_t* buffer); -uint8_t umsg_unused_unused_var_deserialize(umsg_unused_unused_var_t* data,uint8_t* buffer); // this function includes check that the message type is correct - - +uint8_t umsg_unused_unused_var_deserialize(umsg_unused_unused_var_t* data, uint8_t* buffer); // this function includes check that the message type is correct #ifdef __cplusplus } #endif - diff --git a/umsg_lib/src/battery.c b/umsg_lib/src/battery.c index 824fb85..4751c12 100644 --- a/umsg_lib/src/battery.c +++ b/umsg_lib/src/battery.c @@ -7,64 +7,51 @@ static umsg_msg_metadata_t msg_battery_state = {.name = "battery_state"}; // msg api's // battery_state -umsg_sub_handle_t umsg_battery_state_subscribe(uint32_t prescaler, uint8_t length) -{ - return umsg_subscribe(&msg_battery_state, prescaler, sizeof(umsg_battery_state_t), length, 0); +umsg_sub_handle_t umsg_battery_state_subscribe(uint32_t prescaler, uint8_t length) { + return umsg_subscribe(&msg_battery_state, prescaler, sizeof(umsg_battery_state_t), length, 0); } -umsg_sub_handle_t umsg_battery_state_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel) -{ - return umsg_subscribe(&msg_battery_state, prescaler, sizeof(umsg_battery_state_t), length, channel); +umsg_sub_handle_t umsg_battery_state_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel) { + return umsg_subscribe(&msg_battery_state, prescaler, sizeof(umsg_battery_state_t), length, channel); } -void umsg_battery_state_publish(umsg_battery_state_t* data) -{ - umsg_publish(&msg_battery_state, data, 0); +void umsg_battery_state_publish(umsg_battery_state_t* data) { + umsg_publish(&msg_battery_state, data, 0); } -void umsg_battery_state_publish_ch(umsg_battery_state_t* data, uint8_t channel) -{ - umsg_publish(&msg_battery_state, data, channel); +void umsg_battery_state_publish_ch(umsg_battery_state_t* data, uint8_t channel) { + umsg_publish(&msg_battery_state, data, channel); } -uint8_t umsg_battery_state_receive(umsg_sub_handle_t queue, umsg_battery_state_t* data, uint32_t timeout) -{ - return umsg_receive(queue, data, timeout); +uint8_t umsg_battery_state_receive(umsg_sub_handle_t queue, umsg_battery_state_t* data, uint32_t timeout) { + return umsg_receive(queue, data, timeout); } -uint8_t umsg_battery_state_peek(umsg_battery_state_t* data) -{ - return umsg_peek(&msg_battery_state, data, sizeof(umsg_battery_state_t)); +uint8_t umsg_battery_state_peek(umsg_battery_state_t* data) { + return umsg_peek(&msg_battery_state, data, sizeof(umsg_battery_state_t)); } - - -uint32_t umsg_battery_state_serialize(umsg_battery_state_t* data, uint8_t* buffer) -{ - uint32_t len = 2; - buffer[0] = UMSG_BATTERY; - buffer[1] = BATTERY_STATE; - char *flattened_data = (char *)data; - for(uint32_t i = 0; i < sizeof(umsg_battery_state_t);i++) - { - buffer[len] = flattened_data[i]; - len++; - } - return len; +uint32_t umsg_battery_state_serialize(umsg_battery_state_t* data, uint8_t* buffer) { + uint32_t len = 2; + buffer[0] = UMSG_BATTERY; + buffer[1] = BATTERY_STATE; + char* flattened_data = (char*)data; + for (uint32_t i = 0; i < sizeof(umsg_battery_state_t); i++) { + buffer[len] = flattened_data[i]; + len++; + } + return len; } -//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future -uint8_t umsg_battery_state_deserialize(umsg_battery_state_t* data,uint8_t* buffer) -{ - if(buffer[0]!=UMSG_BATTERY || buffer[1] !=BATTERY_STATE) - { - return 0; - } +// for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +uint8_t umsg_battery_state_deserialize(umsg_battery_state_t* data, uint8_t* buffer) { + if (buffer[0] != UMSG_BATTERY || buffer[1] != BATTERY_STATE) { + return 0; + } - uint32_t offset = 2; - char *flattened_data = (char *)data; - for(uint32_t i = 0; i < sizeof(umsg_battery_state_t);i++) - { - flattened_data[i] = buffer[offset]; - offset++; - } + uint32_t offset = 2; + char* flattened_data = (char*)data; + for (uint32_t i = 0; i < sizeof(umsg_battery_state_t); i++) { + flattened_data[i] = buffer[offset]; + offset++; + } - return 1; + return 1; } diff --git a/umsg_lib/src/control.c b/umsg_lib/src/control.c index 931c6d6..0fec39b 100644 --- a/umsg_lib/src/control.c +++ b/umsg_lib/src/control.c @@ -7,64 +7,51 @@ static umsg_msg_metadata_t msg_control_setpoints = {.name = "control_setpoints"} // msg api's // control_setpoints -umsg_sub_handle_t umsg_control_setpoints_subscribe(uint32_t prescaler, uint8_t length) -{ - return umsg_subscribe(&msg_control_setpoints, prescaler, sizeof(umsg_control_setpoints_t), length, 0); +umsg_sub_handle_t umsg_control_setpoints_subscribe(uint32_t prescaler, uint8_t length) { + return umsg_subscribe(&msg_control_setpoints, prescaler, sizeof(umsg_control_setpoints_t), length, 0); } -umsg_sub_handle_t umsg_control_setpoints_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel) -{ - return umsg_subscribe(&msg_control_setpoints, prescaler, sizeof(umsg_control_setpoints_t), length, channel); +umsg_sub_handle_t umsg_control_setpoints_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel) { + return umsg_subscribe(&msg_control_setpoints, prescaler, sizeof(umsg_control_setpoints_t), length, channel); } -void umsg_control_setpoints_publish(umsg_control_setpoints_t* data) -{ - umsg_publish(&msg_control_setpoints, data, 0); +void umsg_control_setpoints_publish(umsg_control_setpoints_t* data) { + umsg_publish(&msg_control_setpoints, data, 0); } -void umsg_control_setpoints_publish_ch(umsg_control_setpoints_t* data, uint8_t channel) -{ - umsg_publish(&msg_control_setpoints, data, channel); +void umsg_control_setpoints_publish_ch(umsg_control_setpoints_t* data, uint8_t channel) { + umsg_publish(&msg_control_setpoints, data, channel); } -uint8_t umsg_control_setpoints_receive(umsg_sub_handle_t queue, umsg_control_setpoints_t* data, uint32_t timeout) -{ - return umsg_receive(queue, data, timeout); +uint8_t umsg_control_setpoints_receive(umsg_sub_handle_t queue, umsg_control_setpoints_t* data, uint32_t timeout) { + return umsg_receive(queue, data, timeout); } -uint8_t umsg_control_setpoints_peek(umsg_control_setpoints_t* data) -{ - return umsg_peek(&msg_control_setpoints, data, sizeof(umsg_control_setpoints_t)); +uint8_t umsg_control_setpoints_peek(umsg_control_setpoints_t* data) { + return umsg_peek(&msg_control_setpoints, data, sizeof(umsg_control_setpoints_t)); } - - -uint32_t umsg_control_setpoints_serialize(umsg_control_setpoints_t* data, uint8_t* buffer) -{ - uint32_t len = 2; - buffer[0] = UMSG_CONTROL; - buffer[1] = CONTROL_SETPOINTS; - char *flattened_data = (char *)data; - for(uint32_t i = 0; i < sizeof(umsg_control_setpoints_t);i++) - { - buffer[len] = flattened_data[i]; - len++; - } - return len; +uint32_t umsg_control_setpoints_serialize(umsg_control_setpoints_t* data, uint8_t* buffer) { + uint32_t len = 2; + buffer[0] = UMSG_CONTROL; + buffer[1] = CONTROL_SETPOINTS; + char* flattened_data = (char*)data; + for (uint32_t i = 0; i < sizeof(umsg_control_setpoints_t); i++) { + buffer[len] = flattened_data[i]; + len++; + } + return len; } -//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future -uint8_t umsg_control_setpoints_deserialize(umsg_control_setpoints_t* data,uint8_t* buffer) -{ - if(buffer[0]!=UMSG_CONTROL || buffer[1] !=CONTROL_SETPOINTS) - { - return 0; - } +// for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +uint8_t umsg_control_setpoints_deserialize(umsg_control_setpoints_t* data, uint8_t* buffer) { + if (buffer[0] != UMSG_CONTROL || buffer[1] != CONTROL_SETPOINTS) { + return 0; + } - uint32_t offset = 2; - char *flattened_data = (char *)data; - for(uint32_t i = 0; i < sizeof(umsg_control_setpoints_t);i++) - { - flattened_data[i] = buffer[offset]; - offset++; - } + uint32_t offset = 2; + char* flattened_data = (char*)data; + for (uint32_t i = 0; i < sizeof(umsg_control_setpoints_t); i++) { + flattened_data[i] = buffer[offset]; + offset++; + } - return 1; + return 1; } diff --git a/umsg_lib/src/example.c b/umsg_lib/src/example.c index 869c507..624cdf9 100644 --- a/umsg_lib/src/example.c +++ b/umsg_lib/src/example.c @@ -4,130 +4,104 @@ // msg instances static umsg_msg_metadata_t msg_example_color_selection = {.name = "example_color_selection"}; -static umsg_msg_metadata_t msg_example_simple_msg = {.name = "example_simple_msg"}; +static umsg_msg_metadata_t msg_example_simple_msg = {.name = "example_simple_msg"}; // msg api's // example_color_selection -umsg_sub_handle_t umsg_example_color_selection_subscribe(uint32_t prescaler, uint8_t length) -{ - return umsg_subscribe(&msg_example_color_selection, prescaler, sizeof(umsg_example_color_selection_t), length, 0); +umsg_sub_handle_t umsg_example_color_selection_subscribe(uint32_t prescaler, uint8_t length) { + return umsg_subscribe(&msg_example_color_selection, prescaler, sizeof(umsg_example_color_selection_t), length, 0); } -umsg_sub_handle_t umsg_example_color_selection_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel) -{ - return umsg_subscribe(&msg_example_color_selection, prescaler, sizeof(umsg_example_color_selection_t), length, channel); +umsg_sub_handle_t umsg_example_color_selection_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel) { + return umsg_subscribe(&msg_example_color_selection, prescaler, sizeof(umsg_example_color_selection_t), length, channel); } -void umsg_example_color_selection_publish(umsg_example_color_selection_t* data) -{ - umsg_publish(&msg_example_color_selection, data, 0); +void umsg_example_color_selection_publish(umsg_example_color_selection_t* data) { + umsg_publish(&msg_example_color_selection, data, 0); } -void umsg_example_color_selection_publish_ch(umsg_example_color_selection_t* data, uint8_t channel) -{ - umsg_publish(&msg_example_color_selection, data, channel); +void umsg_example_color_selection_publish_ch(umsg_example_color_selection_t* data, uint8_t channel) { + umsg_publish(&msg_example_color_selection, data, channel); } -uint8_t umsg_example_color_selection_receive(umsg_sub_handle_t queue, umsg_example_color_selection_t* data, uint32_t timeout) -{ - return umsg_receive(queue, data, timeout); +uint8_t umsg_example_color_selection_receive(umsg_sub_handle_t queue, umsg_example_color_selection_t* data, uint32_t timeout) { + return umsg_receive(queue, data, timeout); } -uint8_t umsg_example_color_selection_peek(umsg_example_color_selection_t* data) -{ - return umsg_peek(&msg_example_color_selection, data, sizeof(umsg_example_color_selection_t)); +uint8_t umsg_example_color_selection_peek(umsg_example_color_selection_t* data) { + return umsg_peek(&msg_example_color_selection, data, sizeof(umsg_example_color_selection_t)); } - - -uint32_t umsg_example_color_selection_serialize(umsg_example_color_selection_t* data, uint8_t* buffer) -{ - uint32_t len = 2; - buffer[0] = UMSG_EXAMPLE; - buffer[1] = EXAMPLE_COLOR_SELECTION; - char *flattened_data = (char *)data; - for(uint32_t i = 0; i < sizeof(umsg_example_color_selection_t);i++) - { - buffer[len] = flattened_data[i]; - len++; - } - return len; +uint32_t umsg_example_color_selection_serialize(umsg_example_color_selection_t* data, uint8_t* buffer) { + uint32_t len = 2; + buffer[0] = UMSG_EXAMPLE; + buffer[1] = EXAMPLE_COLOR_SELECTION; + char* flattened_data = (char*)data; + for (uint32_t i = 0; i < sizeof(umsg_example_color_selection_t); i++) { + buffer[len] = flattened_data[i]; + len++; + } + return len; } -//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future -uint8_t umsg_example_color_selection_deserialize(umsg_example_color_selection_t* data,uint8_t* buffer) -{ - if(buffer[0]!=UMSG_EXAMPLE || buffer[1] !=EXAMPLE_COLOR_SELECTION) - { - return 0; - } +// for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +uint8_t umsg_example_color_selection_deserialize(umsg_example_color_selection_t* data, uint8_t* buffer) { + if (buffer[0] != UMSG_EXAMPLE || buffer[1] != EXAMPLE_COLOR_SELECTION) { + return 0; + } - uint32_t offset = 2; - char *flattened_data = (char *)data; - for(uint32_t i = 0; i < sizeof(umsg_example_color_selection_t);i++) - { - flattened_data[i] = buffer[offset]; - offset++; - } + uint32_t offset = 2; + char* flattened_data = (char*)data; + for (uint32_t i = 0; i < sizeof(umsg_example_color_selection_t); i++) { + flattened_data[i] = buffer[offset]; + offset++; + } - return 1; + return 1; } // example_simple_msg -umsg_sub_handle_t umsg_example_simple_msg_subscribe(uint32_t prescaler, uint8_t length) -{ - return umsg_subscribe(&msg_example_simple_msg, prescaler, sizeof(umsg_example_simple_msg_t), length, 0); +umsg_sub_handle_t umsg_example_simple_msg_subscribe(uint32_t prescaler, uint8_t length) { + return umsg_subscribe(&msg_example_simple_msg, prescaler, sizeof(umsg_example_simple_msg_t), length, 0); } -umsg_sub_handle_t umsg_example_simple_msg_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel) -{ - return umsg_subscribe(&msg_example_simple_msg, prescaler, sizeof(umsg_example_simple_msg_t), length, channel); +umsg_sub_handle_t umsg_example_simple_msg_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel) { + return umsg_subscribe(&msg_example_simple_msg, prescaler, sizeof(umsg_example_simple_msg_t), length, channel); } -void umsg_example_simple_msg_publish(umsg_example_simple_msg_t* data) -{ - umsg_publish(&msg_example_simple_msg, data, 0); +void umsg_example_simple_msg_publish(umsg_example_simple_msg_t* data) { + umsg_publish(&msg_example_simple_msg, data, 0); } -void umsg_example_simple_msg_publish_ch(umsg_example_simple_msg_t* data, uint8_t channel) -{ - umsg_publish(&msg_example_simple_msg, data, channel); +void umsg_example_simple_msg_publish_ch(umsg_example_simple_msg_t* data, uint8_t channel) { + umsg_publish(&msg_example_simple_msg, data, channel); } -uint8_t umsg_example_simple_msg_receive(umsg_sub_handle_t queue, umsg_example_simple_msg_t* data, uint32_t timeout) -{ - return umsg_receive(queue, data, timeout); +uint8_t umsg_example_simple_msg_receive(umsg_sub_handle_t queue, umsg_example_simple_msg_t* data, uint32_t timeout) { + return umsg_receive(queue, data, timeout); } -uint8_t umsg_example_simple_msg_peek(umsg_example_simple_msg_t* data) -{ - return umsg_peek(&msg_example_simple_msg, data, sizeof(umsg_example_simple_msg_t)); +uint8_t umsg_example_simple_msg_peek(umsg_example_simple_msg_t* data) { + return umsg_peek(&msg_example_simple_msg, data, sizeof(umsg_example_simple_msg_t)); } - - -uint32_t umsg_example_simple_msg_serialize(umsg_example_simple_msg_t* data, uint8_t* buffer) -{ - uint32_t len = 2; - buffer[0] = UMSG_EXAMPLE; - buffer[1] = EXAMPLE_SIMPLE_MSG; - char *flattened_data = (char *)data; - for(uint32_t i = 0; i < sizeof(umsg_example_simple_msg_t);i++) - { - buffer[len] = flattened_data[i]; - len++; - } - return len; +uint32_t umsg_example_simple_msg_serialize(umsg_example_simple_msg_t* data, uint8_t* buffer) { + uint32_t len = 2; + buffer[0] = UMSG_EXAMPLE; + buffer[1] = EXAMPLE_SIMPLE_MSG; + char* flattened_data = (char*)data; + for (uint32_t i = 0; i < sizeof(umsg_example_simple_msg_t); i++) { + buffer[len] = flattened_data[i]; + len++; + } + return len; } -//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future -uint8_t umsg_example_simple_msg_deserialize(umsg_example_simple_msg_t* data,uint8_t* buffer) -{ - if(buffer[0]!=UMSG_EXAMPLE || buffer[1] !=EXAMPLE_SIMPLE_MSG) - { - return 0; - } +// for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +uint8_t umsg_example_simple_msg_deserialize(umsg_example_simple_msg_t* data, uint8_t* buffer) { + if (buffer[0] != UMSG_EXAMPLE || buffer[1] != EXAMPLE_SIMPLE_MSG) { + return 0; + } - uint32_t offset = 2; - char *flattened_data = (char *)data; - for(uint32_t i = 0; i < sizeof(umsg_example_simple_msg_t);i++) - { - flattened_data[i] = buffer[offset]; - offset++; - } + uint32_t offset = 2; + char* flattened_data = (char*)data; + for (uint32_t i = 0; i < sizeof(umsg_example_simple_msg_t); i++) { + flattened_data[i] = buffer[offset]; + offset++; + } - return 1; + return 1; } diff --git a/umsg_lib/src/sensors.c b/umsg_lib/src/sensors.c index 7d884ce..21b9b5d 100644 --- a/umsg_lib/src/sensors.c +++ b/umsg_lib/src/sensors.c @@ -4,131 +4,105 @@ #include // msg instances -static umsg_msg_metadata_t msg_sensors_imu = {.name = "sensors_imu"}; +static umsg_msg_metadata_t msg_sensors_imu = {.name = "sensors_imu"}; static umsg_msg_metadata_t msg_sensors_baro = {.name = "sensors_baro"}; // msg api's // sensors_imu -umsg_sub_handle_t umsg_sensors_imu_subscribe(uint32_t prescaler, uint8_t length) -{ - return umsg_subscribe(&msg_sensors_imu, prescaler, sizeof(umsg_sensors_imu_t), length, 0); +umsg_sub_handle_t umsg_sensors_imu_subscribe(uint32_t prescaler, uint8_t length) { + return umsg_subscribe(&msg_sensors_imu, prescaler, sizeof(umsg_sensors_imu_t), length, 0); } -umsg_sub_handle_t umsg_sensors_imu_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel) -{ - return umsg_subscribe(&msg_sensors_imu, prescaler, sizeof(umsg_sensors_imu_t), length, channel); +umsg_sub_handle_t umsg_sensors_imu_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel) { + return umsg_subscribe(&msg_sensors_imu, prescaler, sizeof(umsg_sensors_imu_t), length, channel); } -void umsg_sensors_imu_publish(umsg_sensors_imu_t* data) -{ - umsg_publish(&msg_sensors_imu, data, 0); +void umsg_sensors_imu_publish(umsg_sensors_imu_t* data) { + umsg_publish(&msg_sensors_imu, data, 0); } -void umsg_sensors_imu_publish_ch(umsg_sensors_imu_t* data, uint8_t channel) -{ - umsg_publish(&msg_sensors_imu, data, channel); +void umsg_sensors_imu_publish_ch(umsg_sensors_imu_t* data, uint8_t channel) { + umsg_publish(&msg_sensors_imu, data, channel); } -uint8_t umsg_sensors_imu_receive(umsg_sub_handle_t queue, umsg_sensors_imu_t* data, uint32_t timeout) -{ - return umsg_receive(queue, data, timeout); +uint8_t umsg_sensors_imu_receive(umsg_sub_handle_t queue, umsg_sensors_imu_t* data, uint32_t timeout) { + return umsg_receive(queue, data, timeout); } -uint8_t umsg_sensors_imu_peek(umsg_sensors_imu_t* data) -{ - return umsg_peek(&msg_sensors_imu, data, sizeof(umsg_sensors_imu_t)); +uint8_t umsg_sensors_imu_peek(umsg_sensors_imu_t* data) { + return umsg_peek(&msg_sensors_imu, data, sizeof(umsg_sensors_imu_t)); } - - -uint32_t umsg_sensors_imu_serialize(umsg_sensors_imu_t* data, uint8_t* buffer) -{ - uint32_t len = 2; - buffer[0] = UMSG_SENSORS; - buffer[1] = SENSORS_IMU; - char *flattened_data = (char *)data; - for(uint32_t i = 0; i < sizeof(umsg_sensors_imu_t);i++) - { - buffer[len] = flattened_data[i]; - len++; - } - return len; +uint32_t umsg_sensors_imu_serialize(umsg_sensors_imu_t* data, uint8_t* buffer) { + uint32_t len = 2; + buffer[0] = UMSG_SENSORS; + buffer[1] = SENSORS_IMU; + char* flattened_data = (char*)data; + for (uint32_t i = 0; i < sizeof(umsg_sensors_imu_t); i++) { + buffer[len] = flattened_data[i]; + len++; + } + return len; } -//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future -uint8_t umsg_sensors_imu_deserialize(umsg_sensors_imu_t* data,uint8_t* buffer) -{ - if(buffer[0]!=UMSG_SENSORS || buffer[1] !=SENSORS_IMU) - { - return 0; - } +// for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +uint8_t umsg_sensors_imu_deserialize(umsg_sensors_imu_t* data, uint8_t* buffer) { + if (buffer[0] != UMSG_SENSORS || buffer[1] != SENSORS_IMU) { + return 0; + } - uint32_t offset = 2; - char *flattened_data = (char *)data; - for(uint32_t i = 0; i < sizeof(umsg_sensors_imu_t);i++) - { - flattened_data[i] = buffer[offset]; - offset++; - } + uint32_t offset = 2; + char* flattened_data = (char*)data; + for (uint32_t i = 0; i < sizeof(umsg_sensors_imu_t); i++) { + flattened_data[i] = buffer[offset]; + offset++; + } - return 1; + return 1; } // sensors_baro -umsg_sub_handle_t umsg_sensors_baro_subscribe(uint32_t prescaler, uint8_t length) -{ - return umsg_subscribe(&msg_sensors_baro, prescaler, sizeof(umsg_sensors_baro_t), length, 0); +umsg_sub_handle_t umsg_sensors_baro_subscribe(uint32_t prescaler, uint8_t length) { + return umsg_subscribe(&msg_sensors_baro, prescaler, sizeof(umsg_sensors_baro_t), length, 0); } -umsg_sub_handle_t umsg_sensors_baro_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel) -{ - return umsg_subscribe(&msg_sensors_baro, prescaler, sizeof(umsg_sensors_baro_t), length, channel); +umsg_sub_handle_t umsg_sensors_baro_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel) { + return umsg_subscribe(&msg_sensors_baro, prescaler, sizeof(umsg_sensors_baro_t), length, channel); } -void umsg_sensors_baro_publish(umsg_sensors_baro_t* data) -{ - umsg_publish(&msg_sensors_baro, data, 0); +void umsg_sensors_baro_publish(umsg_sensors_baro_t* data) { + umsg_publish(&msg_sensors_baro, data, 0); } -void umsg_sensors_baro_publish_ch(umsg_sensors_baro_t* data, uint8_t channel) -{ - umsg_publish(&msg_sensors_baro, data, channel); +void umsg_sensors_baro_publish_ch(umsg_sensors_baro_t* data, uint8_t channel) { + umsg_publish(&msg_sensors_baro, data, channel); } -uint8_t umsg_sensors_baro_receive(umsg_sub_handle_t queue, umsg_sensors_baro_t* data, uint32_t timeout) -{ - return umsg_receive(queue, data, timeout); +uint8_t umsg_sensors_baro_receive(umsg_sub_handle_t queue, umsg_sensors_baro_t* data, uint32_t timeout) { + return umsg_receive(queue, data, timeout); } -uint8_t umsg_sensors_baro_peek(umsg_sensors_baro_t* data) -{ - return umsg_peek(&msg_sensors_baro, data, sizeof(umsg_sensors_baro_t)); +uint8_t umsg_sensors_baro_peek(umsg_sensors_baro_t* data) { + return umsg_peek(&msg_sensors_baro, data, sizeof(umsg_sensors_baro_t)); } - - -uint32_t umsg_sensors_baro_serialize(umsg_sensors_baro_t* data, uint8_t* buffer) -{ - uint32_t len = 2; - buffer[0] = UMSG_SENSORS; - buffer[1] = SENSORS_BARO; - char *flattened_data = (char *)data; - for(uint32_t i = 0; i < sizeof(umsg_sensors_baro_t);i++) - { - buffer[len] = flattened_data[i]; - len++; - } - return len; +uint32_t umsg_sensors_baro_serialize(umsg_sensors_baro_t* data, uint8_t* buffer) { + uint32_t len = 2; + buffer[0] = UMSG_SENSORS; + buffer[1] = SENSORS_BARO; + char* flattened_data = (char*)data; + for (uint32_t i = 0; i < sizeof(umsg_sensors_baro_t); i++) { + buffer[len] = flattened_data[i]; + len++; + } + return len; } -//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future -uint8_t umsg_sensors_baro_deserialize(umsg_sensors_baro_t* data,uint8_t* buffer) -{ - if(buffer[0]!=UMSG_SENSORS || buffer[1] !=SENSORS_BARO) - { - return 0; - } +// for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +uint8_t umsg_sensors_baro_deserialize(umsg_sensors_baro_t* data, uint8_t* buffer) { + if (buffer[0] != UMSG_SENSORS || buffer[1] != SENSORS_BARO) { + return 0; + } - uint32_t offset = 2; - char *flattened_data = (char *)data; - for(uint32_t i = 0; i < sizeof(umsg_sensors_baro_t);i++) - { - flattened_data[i] = buffer[offset]; - offset++; - } + uint32_t offset = 2; + char* flattened_data = (char*)data; + for (uint32_t i = 0; i < sizeof(umsg_sensors_baro_t); i++) { + flattened_data[i] = buffer[offset]; + offset++; + } - return 1; + return 1; } diff --git a/umsg_lib/src/test.c b/umsg_lib/src/test.c index e1f5aae..7f6888e 100644 --- a/umsg_lib/src/test.c +++ b/umsg_lib/src/test.c @@ -3,446 +3,355 @@ #include // msg instances -static umsg_msg_metadata_t msg_test_floats = {.name = "test_floats"}; -static umsg_msg_metadata_t msg_test_uints = {.name = "test_uints"}; -static umsg_msg_metadata_t msg_test_ints = {.name = "test_ints"}; -static umsg_msg_metadata_t msg_test_strings = {.name = "test_strings"}; -static umsg_msg_metadata_t msg_test_bools = {.name = "test_bools"}; -static umsg_msg_metadata_t msg_test_enums = {.name = "test_enums"}; +static umsg_msg_metadata_t msg_test_floats = {.name = "test_floats"}; +static umsg_msg_metadata_t msg_test_uints = {.name = "test_uints"}; +static umsg_msg_metadata_t msg_test_ints = {.name = "test_ints"}; +static umsg_msg_metadata_t msg_test_strings = {.name = "test_strings"}; +static umsg_msg_metadata_t msg_test_bools = {.name = "test_bools"}; +static umsg_msg_metadata_t msg_test_enums = {.name = "test_enums"}; static umsg_msg_metadata_t msg_test_bitfield = {.name = "test_bitfield"}; // msg api's // test_floats -umsg_sub_handle_t umsg_test_floats_subscribe(uint32_t prescaler, uint8_t length) -{ - return umsg_subscribe(&msg_test_floats, prescaler, sizeof(umsg_test_floats_t), length, 0); +umsg_sub_handle_t umsg_test_floats_subscribe(uint32_t prescaler, uint8_t length) { + return umsg_subscribe(&msg_test_floats, prescaler, sizeof(umsg_test_floats_t), length, 0); } -umsg_sub_handle_t umsg_test_floats_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel) -{ - return umsg_subscribe(&msg_test_floats, prescaler, sizeof(umsg_test_floats_t), length, channel); +umsg_sub_handle_t umsg_test_floats_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel) { + return umsg_subscribe(&msg_test_floats, prescaler, sizeof(umsg_test_floats_t), length, channel); } -void umsg_test_floats_publish(umsg_test_floats_t* data) -{ - umsg_publish(&msg_test_floats, data, 0); +void umsg_test_floats_publish(umsg_test_floats_t* data) { + umsg_publish(&msg_test_floats, data, 0); } -void umsg_test_floats_publish_ch(umsg_test_floats_t* data, uint8_t channel) -{ - umsg_publish(&msg_test_floats, data, channel); +void umsg_test_floats_publish_ch(umsg_test_floats_t* data, uint8_t channel) { + umsg_publish(&msg_test_floats, data, channel); } -uint8_t umsg_test_floats_receive(umsg_sub_handle_t queue, umsg_test_floats_t* data, uint32_t timeout) -{ - return umsg_receive(queue, data, timeout); +uint8_t umsg_test_floats_receive(umsg_sub_handle_t queue, umsg_test_floats_t* data, uint32_t timeout) { + return umsg_receive(queue, data, timeout); } -uint8_t umsg_test_floats_peek(umsg_test_floats_t* data) -{ - return umsg_peek(&msg_test_floats, data, sizeof(umsg_test_floats_t)); +uint8_t umsg_test_floats_peek(umsg_test_floats_t* data) { + return umsg_peek(&msg_test_floats, data, sizeof(umsg_test_floats_t)); } - - -uint32_t umsg_test_floats_serialize(umsg_test_floats_t* data, uint8_t* buffer) -{ - uint32_t len = 2; - buffer[0] = UMSG_TEST; - buffer[1] = TEST_FLOATS; - char *flattened_data = (char *)data; - for(uint32_t i = 0; i < sizeof(umsg_test_floats_t);i++) - { - buffer[len] = flattened_data[i]; - len++; - } - return len; +uint32_t umsg_test_floats_serialize(umsg_test_floats_t* data, uint8_t* buffer) { + uint32_t len = 2; + buffer[0] = UMSG_TEST; + buffer[1] = TEST_FLOATS; + char* flattened_data = (char*)data; + for (uint32_t i = 0; i < sizeof(umsg_test_floats_t); i++) { + buffer[len] = flattened_data[i]; + len++; + } + return len; } -//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future -uint8_t umsg_test_floats_deserialize(umsg_test_floats_t* data,uint8_t* buffer) -{ - if(buffer[0]!=UMSG_TEST || buffer[1] !=TEST_FLOATS) - { - return 0; - } +// for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +uint8_t umsg_test_floats_deserialize(umsg_test_floats_t* data, uint8_t* buffer) { + if (buffer[0] != UMSG_TEST || buffer[1] != TEST_FLOATS) { + return 0; + } - uint32_t offset = 2; - char *flattened_data = (char *)data; - for(uint32_t i = 0; i < sizeof(umsg_test_floats_t);i++) - { - flattened_data[i] = buffer[offset]; - offset++; - } + uint32_t offset = 2; + char* flattened_data = (char*)data; + for (uint32_t i = 0; i < sizeof(umsg_test_floats_t); i++) { + flattened_data[i] = buffer[offset]; + offset++; + } - return 1; + return 1; } // test_uints -umsg_sub_handle_t umsg_test_uints_subscribe(uint32_t prescaler, uint8_t length) -{ - return umsg_subscribe(&msg_test_uints, prescaler, sizeof(umsg_test_uints_t), length, 0); +umsg_sub_handle_t umsg_test_uints_subscribe(uint32_t prescaler, uint8_t length) { + return umsg_subscribe(&msg_test_uints, prescaler, sizeof(umsg_test_uints_t), length, 0); } -umsg_sub_handle_t umsg_test_uints_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel) -{ - return umsg_subscribe(&msg_test_uints, prescaler, sizeof(umsg_test_uints_t), length, channel); +umsg_sub_handle_t umsg_test_uints_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel) { + return umsg_subscribe(&msg_test_uints, prescaler, sizeof(umsg_test_uints_t), length, channel); } -void umsg_test_uints_publish(umsg_test_uints_t* data) -{ - umsg_publish(&msg_test_uints, data, 0); +void umsg_test_uints_publish(umsg_test_uints_t* data) { + umsg_publish(&msg_test_uints, data, 0); } -void umsg_test_uints_publish_ch(umsg_test_uints_t* data, uint8_t channel) -{ - umsg_publish(&msg_test_uints, data, channel); +void umsg_test_uints_publish_ch(umsg_test_uints_t* data, uint8_t channel) { + umsg_publish(&msg_test_uints, data, channel); } -uint8_t umsg_test_uints_receive(umsg_sub_handle_t queue, umsg_test_uints_t* data, uint32_t timeout) -{ - return umsg_receive(queue, data, timeout); +uint8_t umsg_test_uints_receive(umsg_sub_handle_t queue, umsg_test_uints_t* data, uint32_t timeout) { + return umsg_receive(queue, data, timeout); } -uint8_t umsg_test_uints_peek(umsg_test_uints_t* data) -{ - return umsg_peek(&msg_test_uints, data, sizeof(umsg_test_uints_t)); +uint8_t umsg_test_uints_peek(umsg_test_uints_t* data) { + return umsg_peek(&msg_test_uints, data, sizeof(umsg_test_uints_t)); } - - -uint32_t umsg_test_uints_serialize(umsg_test_uints_t* data, uint8_t* buffer) -{ - uint32_t len = 2; - buffer[0] = UMSG_TEST; - buffer[1] = TEST_UINTS; - char *flattened_data = (char *)data; - for(uint32_t i = 0; i < sizeof(umsg_test_uints_t);i++) - { - buffer[len] = flattened_data[i]; - len++; - } - return len; +uint32_t umsg_test_uints_serialize(umsg_test_uints_t* data, uint8_t* buffer) { + uint32_t len = 2; + buffer[0] = UMSG_TEST; + buffer[1] = TEST_UINTS; + char* flattened_data = (char*)data; + for (uint32_t i = 0; i < sizeof(umsg_test_uints_t); i++) { + buffer[len] = flattened_data[i]; + len++; + } + return len; } -//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future -uint8_t umsg_test_uints_deserialize(umsg_test_uints_t* data,uint8_t* buffer) -{ - if(buffer[0]!=UMSG_TEST || buffer[1] !=TEST_UINTS) - { - return 0; - } +// for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +uint8_t umsg_test_uints_deserialize(umsg_test_uints_t* data, uint8_t* buffer) { + if (buffer[0] != UMSG_TEST || buffer[1] != TEST_UINTS) { + return 0; + } - uint32_t offset = 2; - char *flattened_data = (char *)data; - for(uint32_t i = 0; i < sizeof(umsg_test_uints_t);i++) - { - flattened_data[i] = buffer[offset]; - offset++; - } + uint32_t offset = 2; + char* flattened_data = (char*)data; + for (uint32_t i = 0; i < sizeof(umsg_test_uints_t); i++) { + flattened_data[i] = buffer[offset]; + offset++; + } - return 1; + return 1; } // test_ints -umsg_sub_handle_t umsg_test_ints_subscribe(uint32_t prescaler, uint8_t length) -{ - return umsg_subscribe(&msg_test_ints, prescaler, sizeof(umsg_test_ints_t), length, 0); +umsg_sub_handle_t umsg_test_ints_subscribe(uint32_t prescaler, uint8_t length) { + return umsg_subscribe(&msg_test_ints, prescaler, sizeof(umsg_test_ints_t), length, 0); } -umsg_sub_handle_t umsg_test_ints_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel) -{ - return umsg_subscribe(&msg_test_ints, prescaler, sizeof(umsg_test_ints_t), length, channel); +umsg_sub_handle_t umsg_test_ints_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel) { + return umsg_subscribe(&msg_test_ints, prescaler, sizeof(umsg_test_ints_t), length, channel); } -void umsg_test_ints_publish(umsg_test_ints_t* data) -{ - umsg_publish(&msg_test_ints, data, 0); +void umsg_test_ints_publish(umsg_test_ints_t* data) { + umsg_publish(&msg_test_ints, data, 0); } -void umsg_test_ints_publish_ch(umsg_test_ints_t* data, uint8_t channel) -{ - umsg_publish(&msg_test_ints, data, channel); +void umsg_test_ints_publish_ch(umsg_test_ints_t* data, uint8_t channel) { + umsg_publish(&msg_test_ints, data, channel); } -uint8_t umsg_test_ints_receive(umsg_sub_handle_t queue, umsg_test_ints_t* data, uint32_t timeout) -{ - return umsg_receive(queue, data, timeout); +uint8_t umsg_test_ints_receive(umsg_sub_handle_t queue, umsg_test_ints_t* data, uint32_t timeout) { + return umsg_receive(queue, data, timeout); } -uint8_t umsg_test_ints_peek(umsg_test_ints_t* data) -{ - return umsg_peek(&msg_test_ints, data, sizeof(umsg_test_ints_t)); +uint8_t umsg_test_ints_peek(umsg_test_ints_t* data) { + return umsg_peek(&msg_test_ints, data, sizeof(umsg_test_ints_t)); } - - -uint32_t umsg_test_ints_serialize(umsg_test_ints_t* data, uint8_t* buffer) -{ - uint32_t len = 2; - buffer[0] = UMSG_TEST; - buffer[1] = TEST_INTS; - char *flattened_data = (char *)data; - for(uint32_t i = 0; i < sizeof(umsg_test_ints_t);i++) - { - buffer[len] = flattened_data[i]; - len++; - } - return len; +uint32_t umsg_test_ints_serialize(umsg_test_ints_t* data, uint8_t* buffer) { + uint32_t len = 2; + buffer[0] = UMSG_TEST; + buffer[1] = TEST_INTS; + char* flattened_data = (char*)data; + for (uint32_t i = 0; i < sizeof(umsg_test_ints_t); i++) { + buffer[len] = flattened_data[i]; + len++; + } + return len; } -//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future -uint8_t umsg_test_ints_deserialize(umsg_test_ints_t* data,uint8_t* buffer) -{ - if(buffer[0]!=UMSG_TEST || buffer[1] !=TEST_INTS) - { - return 0; - } +// for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +uint8_t umsg_test_ints_deserialize(umsg_test_ints_t* data, uint8_t* buffer) { + if (buffer[0] != UMSG_TEST || buffer[1] != TEST_INTS) { + return 0; + } - uint32_t offset = 2; - char *flattened_data = (char *)data; - for(uint32_t i = 0; i < sizeof(umsg_test_ints_t);i++) - { - flattened_data[i] = buffer[offset]; - offset++; - } + uint32_t offset = 2; + char* flattened_data = (char*)data; + for (uint32_t i = 0; i < sizeof(umsg_test_ints_t); i++) { + flattened_data[i] = buffer[offset]; + offset++; + } - return 1; + return 1; } // test_strings -umsg_sub_handle_t umsg_test_strings_subscribe(uint32_t prescaler, uint8_t length) -{ - return umsg_subscribe(&msg_test_strings, prescaler, sizeof(umsg_test_strings_t), length, 0); +umsg_sub_handle_t umsg_test_strings_subscribe(uint32_t prescaler, uint8_t length) { + return umsg_subscribe(&msg_test_strings, prescaler, sizeof(umsg_test_strings_t), length, 0); } -umsg_sub_handle_t umsg_test_strings_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel) -{ - return umsg_subscribe(&msg_test_strings, prescaler, sizeof(umsg_test_strings_t), length, channel); +umsg_sub_handle_t umsg_test_strings_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel) { + return umsg_subscribe(&msg_test_strings, prescaler, sizeof(umsg_test_strings_t), length, channel); } -void umsg_test_strings_publish(umsg_test_strings_t* data) -{ - umsg_publish(&msg_test_strings, data, 0); +void umsg_test_strings_publish(umsg_test_strings_t* data) { + umsg_publish(&msg_test_strings, data, 0); } -void umsg_test_strings_publish_ch(umsg_test_strings_t* data, uint8_t channel) -{ - umsg_publish(&msg_test_strings, data, channel); +void umsg_test_strings_publish_ch(umsg_test_strings_t* data, uint8_t channel) { + umsg_publish(&msg_test_strings, data, channel); } -uint8_t umsg_test_strings_receive(umsg_sub_handle_t queue, umsg_test_strings_t* data, uint32_t timeout) -{ - return umsg_receive(queue, data, timeout); +uint8_t umsg_test_strings_receive(umsg_sub_handle_t queue, umsg_test_strings_t* data, uint32_t timeout) { + return umsg_receive(queue, data, timeout); } -uint8_t umsg_test_strings_peek(umsg_test_strings_t* data) -{ - return umsg_peek(&msg_test_strings, data, sizeof(umsg_test_strings_t)); +uint8_t umsg_test_strings_peek(umsg_test_strings_t* data) { + return umsg_peek(&msg_test_strings, data, sizeof(umsg_test_strings_t)); } - - -uint32_t umsg_test_strings_serialize(umsg_test_strings_t* data, uint8_t* buffer) -{ - uint32_t len = 2; - buffer[0] = UMSG_TEST; - buffer[1] = TEST_STRINGS; - char *flattened_data = (char *)data; - for(uint32_t i = 0; i < sizeof(umsg_test_strings_t);i++) - { - buffer[len] = flattened_data[i]; - len++; - } - return len; +uint32_t umsg_test_strings_serialize(umsg_test_strings_t* data, uint8_t* buffer) { + uint32_t len = 2; + buffer[0] = UMSG_TEST; + buffer[1] = TEST_STRINGS; + char* flattened_data = (char*)data; + for (uint32_t i = 0; i < sizeof(umsg_test_strings_t); i++) { + buffer[len] = flattened_data[i]; + len++; + } + return len; } -//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future -uint8_t umsg_test_strings_deserialize(umsg_test_strings_t* data,uint8_t* buffer) -{ - if(buffer[0]!=UMSG_TEST || buffer[1] !=TEST_STRINGS) - { - return 0; - } +// for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +uint8_t umsg_test_strings_deserialize(umsg_test_strings_t* data, uint8_t* buffer) { + if (buffer[0] != UMSG_TEST || buffer[1] != TEST_STRINGS) { + return 0; + } - uint32_t offset = 2; - char *flattened_data = (char *)data; - for(uint32_t i = 0; i < sizeof(umsg_test_strings_t);i++) - { - flattened_data[i] = buffer[offset]; - offset++; - } + uint32_t offset = 2; + char* flattened_data = (char*)data; + for (uint32_t i = 0; i < sizeof(umsg_test_strings_t); i++) { + flattened_data[i] = buffer[offset]; + offset++; + } - return 1; + return 1; } // test_bools -umsg_sub_handle_t umsg_test_bools_subscribe(uint32_t prescaler, uint8_t length) -{ - return umsg_subscribe(&msg_test_bools, prescaler, sizeof(umsg_test_bools_t), length, 0); +umsg_sub_handle_t umsg_test_bools_subscribe(uint32_t prescaler, uint8_t length) { + return umsg_subscribe(&msg_test_bools, prescaler, sizeof(umsg_test_bools_t), length, 0); } -umsg_sub_handle_t umsg_test_bools_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel) -{ - return umsg_subscribe(&msg_test_bools, prescaler, sizeof(umsg_test_bools_t), length, channel); +umsg_sub_handle_t umsg_test_bools_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel) { + return umsg_subscribe(&msg_test_bools, prescaler, sizeof(umsg_test_bools_t), length, channel); } -void umsg_test_bools_publish(umsg_test_bools_t* data) -{ - umsg_publish(&msg_test_bools, data, 0); +void umsg_test_bools_publish(umsg_test_bools_t* data) { + umsg_publish(&msg_test_bools, data, 0); } -void umsg_test_bools_publish_ch(umsg_test_bools_t* data, uint8_t channel) -{ - umsg_publish(&msg_test_bools, data, channel); +void umsg_test_bools_publish_ch(umsg_test_bools_t* data, uint8_t channel) { + umsg_publish(&msg_test_bools, data, channel); } -uint8_t umsg_test_bools_receive(umsg_sub_handle_t queue, umsg_test_bools_t* data, uint32_t timeout) -{ - return umsg_receive(queue, data, timeout); +uint8_t umsg_test_bools_receive(umsg_sub_handle_t queue, umsg_test_bools_t* data, uint32_t timeout) { + return umsg_receive(queue, data, timeout); } -uint8_t umsg_test_bools_peek(umsg_test_bools_t* data) -{ - return umsg_peek(&msg_test_bools, data, sizeof(umsg_test_bools_t)); +uint8_t umsg_test_bools_peek(umsg_test_bools_t* data) { + return umsg_peek(&msg_test_bools, data, sizeof(umsg_test_bools_t)); } - - -uint32_t umsg_test_bools_serialize(umsg_test_bools_t* data, uint8_t* buffer) -{ - uint32_t len = 2; - buffer[0] = UMSG_TEST; - buffer[1] = TEST_BOOLS; - char *flattened_data = (char *)data; - for(uint32_t i = 0; i < sizeof(umsg_test_bools_t);i++) - { - buffer[len] = flattened_data[i]; - len++; - } - return len; +uint32_t umsg_test_bools_serialize(umsg_test_bools_t* data, uint8_t* buffer) { + uint32_t len = 2; + buffer[0] = UMSG_TEST; + buffer[1] = TEST_BOOLS; + char* flattened_data = (char*)data; + for (uint32_t i = 0; i < sizeof(umsg_test_bools_t); i++) { + buffer[len] = flattened_data[i]; + len++; + } + return len; } -//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future -uint8_t umsg_test_bools_deserialize(umsg_test_bools_t* data,uint8_t* buffer) -{ - if(buffer[0]!=UMSG_TEST || buffer[1] !=TEST_BOOLS) - { - return 0; - } +// for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +uint8_t umsg_test_bools_deserialize(umsg_test_bools_t* data, uint8_t* buffer) { + if (buffer[0] != UMSG_TEST || buffer[1] != TEST_BOOLS) { + return 0; + } - uint32_t offset = 2; - char *flattened_data = (char *)data; - for(uint32_t i = 0; i < sizeof(umsg_test_bools_t);i++) - { - flattened_data[i] = buffer[offset]; - offset++; - } + uint32_t offset = 2; + char* flattened_data = (char*)data; + for (uint32_t i = 0; i < sizeof(umsg_test_bools_t); i++) { + flattened_data[i] = buffer[offset]; + offset++; + } - return 1; + return 1; } // test_enums -umsg_sub_handle_t umsg_test_enums_subscribe(uint32_t prescaler, uint8_t length) -{ - return umsg_subscribe(&msg_test_enums, prescaler, sizeof(umsg_test_enums_t), length, 0); +umsg_sub_handle_t umsg_test_enums_subscribe(uint32_t prescaler, uint8_t length) { + return umsg_subscribe(&msg_test_enums, prescaler, sizeof(umsg_test_enums_t), length, 0); } -umsg_sub_handle_t umsg_test_enums_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel) -{ - return umsg_subscribe(&msg_test_enums, prescaler, sizeof(umsg_test_enums_t), length, channel); +umsg_sub_handle_t umsg_test_enums_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel) { + return umsg_subscribe(&msg_test_enums, prescaler, sizeof(umsg_test_enums_t), length, channel); } -void umsg_test_enums_publish(umsg_test_enums_t* data) -{ - umsg_publish(&msg_test_enums, data, 0); +void umsg_test_enums_publish(umsg_test_enums_t* data) { + umsg_publish(&msg_test_enums, data, 0); } -void umsg_test_enums_publish_ch(umsg_test_enums_t* data, uint8_t channel) -{ - umsg_publish(&msg_test_enums, data, channel); +void umsg_test_enums_publish_ch(umsg_test_enums_t* data, uint8_t channel) { + umsg_publish(&msg_test_enums, data, channel); } -uint8_t umsg_test_enums_receive(umsg_sub_handle_t queue, umsg_test_enums_t* data, uint32_t timeout) -{ - return umsg_receive(queue, data, timeout); +uint8_t umsg_test_enums_receive(umsg_sub_handle_t queue, umsg_test_enums_t* data, uint32_t timeout) { + return umsg_receive(queue, data, timeout); } -uint8_t umsg_test_enums_peek(umsg_test_enums_t* data) -{ - return umsg_peek(&msg_test_enums, data, sizeof(umsg_test_enums_t)); +uint8_t umsg_test_enums_peek(umsg_test_enums_t* data) { + return umsg_peek(&msg_test_enums, data, sizeof(umsg_test_enums_t)); } - - -uint32_t umsg_test_enums_serialize(umsg_test_enums_t* data, uint8_t* buffer) -{ - uint32_t len = 2; - buffer[0] = UMSG_TEST; - buffer[1] = TEST_ENUMS; - char *flattened_data = (char *)data; - for(uint32_t i = 0; i < sizeof(umsg_test_enums_t);i++) - { - buffer[len] = flattened_data[i]; - len++; - } - return len; +uint32_t umsg_test_enums_serialize(umsg_test_enums_t* data, uint8_t* buffer) { + uint32_t len = 2; + buffer[0] = UMSG_TEST; + buffer[1] = TEST_ENUMS; + char* flattened_data = (char*)data; + for (uint32_t i = 0; i < sizeof(umsg_test_enums_t); i++) { + buffer[len] = flattened_data[i]; + len++; + } + return len; } -//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future -uint8_t umsg_test_enums_deserialize(umsg_test_enums_t* data,uint8_t* buffer) -{ - if(buffer[0]!=UMSG_TEST || buffer[1] !=TEST_ENUMS) - { - return 0; - } +// for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +uint8_t umsg_test_enums_deserialize(umsg_test_enums_t* data, uint8_t* buffer) { + if (buffer[0] != UMSG_TEST || buffer[1] != TEST_ENUMS) { + return 0; + } - uint32_t offset = 2; - char *flattened_data = (char *)data; - for(uint32_t i = 0; i < sizeof(umsg_test_enums_t);i++) - { - flattened_data[i] = buffer[offset]; - offset++; - } + uint32_t offset = 2; + char* flattened_data = (char*)data; + for (uint32_t i = 0; i < sizeof(umsg_test_enums_t); i++) { + flattened_data[i] = buffer[offset]; + offset++; + } - return 1; + return 1; } // test_bitfield -umsg_sub_handle_t umsg_test_bitfield_subscribe(uint32_t prescaler, uint8_t length) -{ - return umsg_subscribe(&msg_test_bitfield, prescaler, sizeof(umsg_test_bitfield_t), length, 0); +umsg_sub_handle_t umsg_test_bitfield_subscribe(uint32_t prescaler, uint8_t length) { + return umsg_subscribe(&msg_test_bitfield, prescaler, sizeof(umsg_test_bitfield_t), length, 0); } -umsg_sub_handle_t umsg_test_bitfield_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel) -{ - return umsg_subscribe(&msg_test_bitfield, prescaler, sizeof(umsg_test_bitfield_t), length, channel); +umsg_sub_handle_t umsg_test_bitfield_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel) { + return umsg_subscribe(&msg_test_bitfield, prescaler, sizeof(umsg_test_bitfield_t), length, channel); } -void umsg_test_bitfield_publish(umsg_test_bitfield_t* data) -{ - umsg_publish(&msg_test_bitfield, data, 0); +void umsg_test_bitfield_publish(umsg_test_bitfield_t* data) { + umsg_publish(&msg_test_bitfield, data, 0); } -void umsg_test_bitfield_publish_ch(umsg_test_bitfield_t* data, uint8_t channel) -{ - umsg_publish(&msg_test_bitfield, data, channel); +void umsg_test_bitfield_publish_ch(umsg_test_bitfield_t* data, uint8_t channel) { + umsg_publish(&msg_test_bitfield, data, channel); } -uint8_t umsg_test_bitfield_receive(umsg_sub_handle_t queue, umsg_test_bitfield_t* data, uint32_t timeout) -{ - return umsg_receive(queue, data, timeout); +uint8_t umsg_test_bitfield_receive(umsg_sub_handle_t queue, umsg_test_bitfield_t* data, uint32_t timeout) { + return umsg_receive(queue, data, timeout); } -uint8_t umsg_test_bitfield_peek(umsg_test_bitfield_t* data) -{ - return umsg_peek(&msg_test_bitfield, data, sizeof(umsg_test_bitfield_t)); +uint8_t umsg_test_bitfield_peek(umsg_test_bitfield_t* data) { + return umsg_peek(&msg_test_bitfield, data, sizeof(umsg_test_bitfield_t)); } - - -uint32_t umsg_test_bitfield_serialize(umsg_test_bitfield_t* data, uint8_t* buffer) -{ - uint32_t len = 2; - buffer[0] = UMSG_TEST; - buffer[1] = TEST_BITFIELD; - char *flattened_data = (char *)data; - for(uint32_t i = 0; i < sizeof(umsg_test_bitfield_t);i++) - { - buffer[len] = flattened_data[i]; - len++; - } - return len; +uint32_t umsg_test_bitfield_serialize(umsg_test_bitfield_t* data, uint8_t* buffer) { + uint32_t len = 2; + buffer[0] = UMSG_TEST; + buffer[1] = TEST_BITFIELD; + char* flattened_data = (char*)data; + for (uint32_t i = 0; i < sizeof(umsg_test_bitfield_t); i++) { + buffer[len] = flattened_data[i]; + len++; + } + return len; } -//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future -uint8_t umsg_test_bitfield_deserialize(umsg_test_bitfield_t* data,uint8_t* buffer) -{ - if(buffer[0]!=UMSG_TEST || buffer[1] !=TEST_BITFIELD) - { - return 0; - } +// for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +uint8_t umsg_test_bitfield_deserialize(umsg_test_bitfield_t* data, uint8_t* buffer) { + if (buffer[0] != UMSG_TEST || buffer[1] != TEST_BITFIELD) { + return 0; + } - uint32_t offset = 2; - char *flattened_data = (char *)data; - for(uint32_t i = 0; i < sizeof(umsg_test_bitfield_t);i++) - { - flattened_data[i] = buffer[offset]; - offset++; - } + uint32_t offset = 2; + char* flattened_data = (char*)data; + for (uint32_t i = 0; i < sizeof(umsg_test_bitfield_t); i++) { + flattened_data[i] = buffer[offset]; + offset++; + } - return 1; + return 1; } diff --git a/umsg_lib/src/unused.c b/umsg_lib/src/unused.c index 97bc29f..183cd14 100644 --- a/umsg_lib/src/unused.c +++ b/umsg_lib/src/unused.c @@ -3,131 +3,105 @@ #include // msg instances -static umsg_msg_metadata_t msg_unused_used_var = {.name = "unused_used_var"}; +static umsg_msg_metadata_t msg_unused_used_var = {.name = "unused_used_var"}; static umsg_msg_metadata_t msg_unused_unused_var = {.name = "unused_unused_var"}; // msg api's // unused_used_var -umsg_sub_handle_t umsg_unused_used_var_subscribe(uint32_t prescaler, uint8_t length) -{ - return umsg_subscribe(&msg_unused_used_var, prescaler, sizeof(umsg_unused_used_var_t), length, 0); +umsg_sub_handle_t umsg_unused_used_var_subscribe(uint32_t prescaler, uint8_t length) { + return umsg_subscribe(&msg_unused_used_var, prescaler, sizeof(umsg_unused_used_var_t), length, 0); } -umsg_sub_handle_t umsg_unused_used_var_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel) -{ - return umsg_subscribe(&msg_unused_used_var, prescaler, sizeof(umsg_unused_used_var_t), length, channel); +umsg_sub_handle_t umsg_unused_used_var_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel) { + return umsg_subscribe(&msg_unused_used_var, prescaler, sizeof(umsg_unused_used_var_t), length, channel); } -void umsg_unused_used_var_publish(umsg_unused_used_var_t* data) -{ - umsg_publish(&msg_unused_used_var, data, 0); +void umsg_unused_used_var_publish(umsg_unused_used_var_t* data) { + umsg_publish(&msg_unused_used_var, data, 0); } -void umsg_unused_used_var_publish_ch(umsg_unused_used_var_t* data, uint8_t channel) -{ - umsg_publish(&msg_unused_used_var, data, channel); +void umsg_unused_used_var_publish_ch(umsg_unused_used_var_t* data, uint8_t channel) { + umsg_publish(&msg_unused_used_var, data, channel); } -uint8_t umsg_unused_used_var_receive(umsg_sub_handle_t queue, umsg_unused_used_var_t* data, uint32_t timeout) -{ - return umsg_receive(queue, data, timeout); +uint8_t umsg_unused_used_var_receive(umsg_sub_handle_t queue, umsg_unused_used_var_t* data, uint32_t timeout) { + return umsg_receive(queue, data, timeout); } -uint8_t umsg_unused_used_var_peek(umsg_unused_used_var_t* data) -{ - return umsg_peek(&msg_unused_used_var, data, sizeof(umsg_unused_used_var_t)); +uint8_t umsg_unused_used_var_peek(umsg_unused_used_var_t* data) { + return umsg_peek(&msg_unused_used_var, data, sizeof(umsg_unused_used_var_t)); } - - -uint32_t umsg_unused_used_var_serialize(umsg_unused_used_var_t* data, uint8_t* buffer) -{ - uint32_t len = 2; - buffer[0] = UMSG_UNUSED; - buffer[1] = UNUSED_USED_VAR; - char *flattened_data = (char *)data; - for(uint32_t i = 0; i < sizeof(umsg_unused_used_var_t);i++) - { - buffer[len] = flattened_data[i]; - len++; - } - return len; +uint32_t umsg_unused_used_var_serialize(umsg_unused_used_var_t* data, uint8_t* buffer) { + uint32_t len = 2; + buffer[0] = UMSG_UNUSED; + buffer[1] = UNUSED_USED_VAR; + char* flattened_data = (char*)data; + for (uint32_t i = 0; i < sizeof(umsg_unused_used_var_t); i++) { + buffer[len] = flattened_data[i]; + len++; + } + return len; } -//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future -uint8_t umsg_unused_used_var_deserialize(umsg_unused_used_var_t* data,uint8_t* buffer) -{ - if(buffer[0]!=UMSG_UNUSED || buffer[1] !=UNUSED_USED_VAR) - { - return 0; - } +// for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +uint8_t umsg_unused_used_var_deserialize(umsg_unused_used_var_t* data, uint8_t* buffer) { + if (buffer[0] != UMSG_UNUSED || buffer[1] != UNUSED_USED_VAR) { + return 0; + } - uint32_t offset = 2; - char *flattened_data = (char *)data; - for(uint32_t i = 0; i < sizeof(umsg_unused_used_var_t);i++) - { - flattened_data[i] = buffer[offset]; - offset++; - } + uint32_t offset = 2; + char* flattened_data = (char*)data; + for (uint32_t i = 0; i < sizeof(umsg_unused_used_var_t); i++) { + flattened_data[i] = buffer[offset]; + offset++; + } - return 1; + return 1; } // unused_unused_var -umsg_sub_handle_t umsg_unused_unused_var_subscribe(uint32_t prescaler, uint8_t length) -{ - return umsg_subscribe(&msg_unused_unused_var, prescaler, sizeof(umsg_unused_unused_var_t), length, 0); +umsg_sub_handle_t umsg_unused_unused_var_subscribe(uint32_t prescaler, uint8_t length) { + return umsg_subscribe(&msg_unused_unused_var, prescaler, sizeof(umsg_unused_unused_var_t), length, 0); } -umsg_sub_handle_t umsg_unused_unused_var_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel) -{ - return umsg_subscribe(&msg_unused_unused_var, prescaler, sizeof(umsg_unused_unused_var_t), length, channel); +umsg_sub_handle_t umsg_unused_unused_var_subscribe_ch(uint32_t prescaler, uint8_t length, uint8_t channel) { + return umsg_subscribe(&msg_unused_unused_var, prescaler, sizeof(umsg_unused_unused_var_t), length, channel); } -void umsg_unused_unused_var_publish(umsg_unused_unused_var_t* data) -{ - umsg_publish(&msg_unused_unused_var, data, 0); +void umsg_unused_unused_var_publish(umsg_unused_unused_var_t* data) { + umsg_publish(&msg_unused_unused_var, data, 0); } -void umsg_unused_unused_var_publish_ch(umsg_unused_unused_var_t* data, uint8_t channel) -{ - umsg_publish(&msg_unused_unused_var, data, channel); +void umsg_unused_unused_var_publish_ch(umsg_unused_unused_var_t* data, uint8_t channel) { + umsg_publish(&msg_unused_unused_var, data, channel); } -uint8_t umsg_unused_unused_var_receive(umsg_sub_handle_t queue, umsg_unused_unused_var_t* data, uint32_t timeout) -{ - return umsg_receive(queue, data, timeout); +uint8_t umsg_unused_unused_var_receive(umsg_sub_handle_t queue, umsg_unused_unused_var_t* data, uint32_t timeout) { + return umsg_receive(queue, data, timeout); } -uint8_t umsg_unused_unused_var_peek(umsg_unused_unused_var_t* data) -{ - return umsg_peek(&msg_unused_unused_var, data, sizeof(umsg_unused_unused_var_t)); +uint8_t umsg_unused_unused_var_peek(umsg_unused_unused_var_t* data) { + return umsg_peek(&msg_unused_unused_var, data, sizeof(umsg_unused_unused_var_t)); } - - -uint32_t umsg_unused_unused_var_serialize(umsg_unused_unused_var_t* data, uint8_t* buffer) -{ - uint32_t len = 2; - buffer[0] = UMSG_UNUSED; - buffer[1] = UNUSED_UNUSED_VAR; - char *flattened_data = (char *)data; - for(uint32_t i = 0; i < sizeof(umsg_unused_unused_var_t);i++) - { - buffer[len] = flattened_data[i]; - len++; - } - return len; +uint32_t umsg_unused_unused_var_serialize(umsg_unused_unused_var_t* data, uint8_t* buffer) { + uint32_t len = 2; + buffer[0] = UMSG_UNUSED; + buffer[1] = UNUSED_UNUSED_VAR; + char* flattened_data = (char*)data; + for (uint32_t i = 0; i < sizeof(umsg_unused_unused_var_t); i++) { + buffer[len] = flattened_data[i]; + len++; + } + return len; } -//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future -uint8_t umsg_unused_unused_var_deserialize(umsg_unused_unused_var_t* data,uint8_t* buffer) -{ - if(buffer[0]!=UMSG_UNUSED || buffer[1] !=UNUSED_UNUSED_VAR) - { - return 0; - } +// for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future +uint8_t umsg_unused_unused_var_deserialize(umsg_unused_unused_var_t* data, uint8_t* buffer) { + if (buffer[0] != UMSG_UNUSED || buffer[1] != UNUSED_UNUSED_VAR) { + return 0; + } - uint32_t offset = 2; - char *flattened_data = (char *)data; - for(uint32_t i = 0; i < sizeof(umsg_unused_unused_var_t);i++) - { - flattened_data[i] = buffer[offset]; - offset++; - } + uint32_t offset = 2; + char* flattened_data = (char*)data; + for (uint32_t i = 0; i < sizeof(umsg_unused_unused_var_t); i++) { + flattened_data[i] = buffer[offset]; + offset++; + } - return 1; + return 1; } From 6742f658a35cf44d0583a44853c5a15fb963c558 Mon Sep 17 00:00:00 2001 From: Michal Reiser Date: Wed, 27 Nov 2024 13:53:26 +0100 Subject: [PATCH 11/16] solved the packing issue --- umsg_gen/umsg_gen/templates/log_parser.cpp.j2 | 2 +- umsg_gen/umsg_gen/templates/msg.c.j2 | 5 ++--- umsg_gen/umsg_gen/templates/msg_classes.h.j2 | 4 +++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 b/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 index fec6d93..95d4c0f 100644 --- a/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 +++ b/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 @@ -54,7 +54,7 @@ void sort_{{dict.name}}_type(std::ifstream &file) uint32_t len = sizeof(umsg_{{dict.name}}_{{msg_dict.name}}_t) + 5; file.read((char *)(buffer.raw + 4),len-4); //read including the crc byte umsg_{{dict.name}}_{{msg_dict.name}}_t message = buffer.s.{{dict.name}}.{{msg_dict.name}}; - uint8_t retval = umsg_calcCRC(buffer.raw,len); + uint8_t retval = umsg_checkCRC(buffer.raw,len); if(retval){ std::cout << "retval for message {{dict.name.upper()}}_{{msg_dict.name.upper()}} failed with value: " << static_cast(retval) << std::endl; } diff --git a/umsg_gen/umsg_gen/templates/msg.c.j2 b/umsg_gen/umsg_gen/templates/msg.c.j2 index c41a315..f16e359 100644 --- a/umsg_gen/umsg_gen/templates/msg.c.j2 +++ b/umsg_gen/umsg_gen/templates/msg.c.j2 @@ -43,15 +43,14 @@ uint8_t umsg_{{prefix}}_peek(umsg_{{prefix}}_t* data) uint32_t umsg_{{prefix}}_receive_to_transfer(umsg_sub_handle_t queue, MessageToTransfer* msg){ - uint32_t len = 2; if(umsg_{{prefix}}_receive(queue,&(msg->s.{{topic_dict.name}}.{{msg_dict.name}}),0)){ - + uint32_t len = 4; msg->s.msg_class = UMSG_{{topic_dict.name.upper()}}; msg->s.msg_type = {{topic_dict.name.upper()}}_{{msg_dict.name.upper()}}; len+= sizeof(umsg_{{topic_dict.name}}_{{msg_dict.name}}_t); - msg->raw[len+1] = umsg_calcCRC(&(msg->raw),len); + msg->raw[len] = umsg_calcCRC(&(msg->raw),len); return len+1; } diff --git a/umsg_gen/umsg_gen/templates/msg_classes.h.j2 b/umsg_gen/umsg_gen/templates/msg_classes.h.j2 index d38b34b..5824b7b 100644 --- a/umsg_gen/umsg_gen/templates/msg_classes.h.j2 +++ b/umsg_gen/umsg_gen/templates/msg_classes.h.j2 @@ -92,7 +92,9 @@ umsg_{{topic_dict.name}}_{{type.lower()}}_t }; {%endfor%} -struct Structured{ + + +struct __attribute__((packed, aligned(4))) Structured{ uint8_t sync0; uint8_t sync1; uint8_t msg_class; From d37d9db7079c84f5c8343c276f4ac174104a4c83 Mon Sep 17 00:00:00 2001 From: Michal Reiser Date: Mon, 9 Dec 2024 14:05:57 +0100 Subject: [PATCH 12/16] started different implementation for transmitter --- umsg_gen/umsg_gen/templates/CMakeLists.txt.j2 | 2 ++ umsg_gen/umsg_gen/templates/msg.c.j2 | 10 ++++++ umsg_gen/umsg_gen/templates/msg_classes.c.j2 | 35 ++++++++++++++++++- umsg_gen/umsg_gen/templates/msg_classes.h.j2 | 18 +++++++--- umsg_gen/umsg_gen/umsg_gen.py | 9 +++++ 5 files changed, 69 insertions(+), 5 deletions(-) diff --git a/umsg_gen/umsg_gen/templates/CMakeLists.txt.j2 b/umsg_gen/umsg_gen/templates/CMakeLists.txt.j2 index 7113a70..a4dba45 100644 --- a/umsg_gen/umsg_gen/templates/CMakeLists.txt.j2 +++ b/umsg_gen/umsg_gen/templates/CMakeLists.txt.j2 @@ -5,7 +5,9 @@ add_library(uMsgLib STATIC {% for src_name in sources %} src/{{ src_name }} {% endfor %} + src/umsg_classes.c ) + # select port if(NOT DEFINED UMSG_PORT) message(FATAL_ERROR "UMSG_PORT is not defined") diff --git a/umsg_gen/umsg_gen/templates/msg.c.j2 b/umsg_gen/umsg_gen/templates/msg.c.j2 index f16e359..8f28ea9 100644 --- a/umsg_gen/umsg_gen/templates/msg.c.j2 +++ b/umsg_gen/umsg_gen/templates/msg.c.j2 @@ -10,6 +10,8 @@ static umsg_msg_metadata_t msg_{{prefix}} = {.name = "{{prefix}}"}; {% endfor %} +extern umsg_msg_metadata_t msg_structured; + // msg api's {% for msg_dict in topic_dict.msgs %} {% set prefix = topic_dict.name+'_'+msg_dict.name%} @@ -25,6 +27,14 @@ umsg_sub_handle_t umsg_{{prefix}}_subscribe_ch(uint32_t prescaler, uint8_t lengt void umsg_{{prefix}}_publish(umsg_{{prefix}}_t* data) { umsg_publish(&msg_{{prefix}}, data, 0); + {%if == 0 %} + + + {% else %} + + umsg_publish(&msg_{{prefix}}, data, channel); + + {% endif %} } void umsg_{{prefix}}_publish_ch(umsg_{{prefix}}_t* data, uint8_t channel) { diff --git a/umsg_gen/umsg_gen/templates/msg_classes.c.j2 b/umsg_gen/umsg_gen/templates/msg_classes.c.j2 index b60164b..1fd42aa 100644 --- a/umsg_gen/umsg_gen/templates/msg_classes.c.j2 +++ b/umsg_gen/umsg_gen/templates/msg_classes.c.j2 @@ -1 +1,34 @@ -#include "msg_classes.h" \ No newline at end of file +#include "umsg_classes.h" +#include + + +umsg_msg_metadata_t msg_structured = {.name = "structured"}; + + + +umsg_sub_handle_t umsg_structured_subscribe_logger(uint32_t prescaler, uint8_t length){ + return umsg_subscribe(&msg_structured, prescaler, sizeof(struct umsg_structured), length, 0); +} + +umsg_sub_handle_t umsg_structured_subscribe_transmitter(uint32_t prescaler, uint8_t length){ + return umsg_subscribe(&msg_structured, prescaler, sizeof(struct umsg_structured), length, 1); +} + +uint8_t umsg_receive_structured(umsg_sub_handle_t queue ,struct umsg_structured * data, uint32_t timeout){ + return umsg_receive(queue, data, timeout); +} + + +uint32_t umsg_publish_structured_to_log(struct umsg_structured * data){ + umsg_publish(&msg_structured, data, 0); +} + + +uint32_t umsg_publish_structured_to_transmit(struct umsg_structured * data){ + umsg_publish(&msg_structured, data, 1); +} + + +void umsg_broadcast_structured(MessageToTransfer *msg){ + +} \ No newline at end of file diff --git a/umsg_gen/umsg_gen/templates/msg_classes.h.j2 b/umsg_gen/umsg_gen/templates/msg_classes.h.j2 index 5824b7b..42f08c2 100644 --- a/umsg_gen/umsg_gen/templates/msg_classes.h.j2 +++ b/umsg_gen/umsg_gen/templates/msg_classes.h.j2 @@ -94,7 +94,7 @@ umsg_{{topic_dict.name}}_{{type.lower()}}_t -struct __attribute__((packed, aligned(4))) Structured{ +struct __attribute__((packed, aligned(4))) umsg_structured{ uint8_t sync0; uint8_t sync1; uint8_t msg_class; @@ -108,14 +108,24 @@ struct __attribute__((packed, aligned(4))) Structured{ typedef union { - struct Structured s; - uint8_t raw[sizeof(struct Structured) + 1]; + struct umsg_structured s; + uint8_t raw[sizeof(struct umsg_structured) + 1]; }MessageToTransfer; + + + // this method only publishes the message if the CRC is correct -uint32_t umsg_publish_received(MessageToTransfer* msg); + +umsg_sub_handle_t umsg_structured_subscribe(uint32_t prescaler, uint8_t length); + +uint32_t umsg_receive_structured(umsg_sub_handle_t queue ,struct umsg_structured * data, uint32_t timeout); + +uint8_t umsg_publish_structured(struct umsg_structured * data); + +void umsg_broadcast_structured(MessageToTransfer *msg); diff --git a/umsg_gen/umsg_gen/umsg_gen.py b/umsg_gen/umsg_gen/umsg_gen.py index 705b615..c0613e4 100644 --- a/umsg_gen/umsg_gen/umsg_gen.py +++ b/umsg_gen/umsg_gen/umsg_gen.py @@ -31,6 +31,7 @@ def main(): env.lstrip_blocks = True msg_class_inc_template = env.get_template(name='msg_classes.h.j2') + msg_class_src_template = env.get_template(name='msg_classes.c.j2') log_parser_template = env.get_template(name='log_parser.cpp.j2') cmake_log_parser_template = env.get_template(name='CMakeLists_log_parser.txt.j2') inc_template = env.get_template(name='msg.h.j2') @@ -85,6 +86,14 @@ def main(): with open(filename, mode="w", encoding="utf-8") as message: message.write(content) + + content = msg_class_src_template.render(topic_dict_list = topic_dict_list, date=datetime.date.today()) + filename = f'{output_path}/src/umsg_classes.c' + with open(filename, mode="w", encoding="utf-8") as message: + message.write(content) + + + if log == "do_log": #Generate the logfile parser filename = f'{output_path}/log_parser/log_parser.cpp' From 2a8bb6b826c3d8ca5642545b114738a4b63f1d1a Mon Sep 17 00:00:00 2001 From: Michal Reiser Date: Tue, 10 Dec 2024 14:26:04 +0100 Subject: [PATCH 13/16] added log and transmit parameters to messages, that allow creation of special queues for output of the system --- umsg_gen/umsg_gen/templates/log_parser.cpp.j2 | 9 ++- umsg_gen/umsg_gen/templates/msg.c.j2 | 66 ++++++------------- umsg_gen/umsg_gen/templates/msg.h.j2 | 12 ---- umsg_gen/umsg_gen/templates/msg_classes.c.j2 | 13 ++-- umsg_gen/umsg_gen/templates/msg_classes.h.j2 | 20 ++++-- 5 files changed, 46 insertions(+), 74 deletions(-) diff --git a/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 b/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 index 95d4c0f..5f6e0ae 100644 --- a/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 +++ b/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 @@ -19,7 +19,7 @@ //globally defined streams for topic files -MessageToTransfer buffer; +umsg_MessageToTransfer buffer; {% for dict in topic_dict_list%} @@ -36,7 +36,9 @@ std::ofstream file_{{dict.name}}_{{msg_dict.name}}; void sort_{{dict.name}}_type(std::ifstream &file) { uint8_t msg_type; + uint32_t len; file.read((char *)&msg_type, 1); + file.read((char *)&len, 4); if (!file) { std::cerr << std::endl << "Error reading file" << std::endl; exit(2); @@ -49,10 +51,10 @@ void sort_{{dict.name}}_type(std::ifstream &file) switch(msg_type) { {% for msg_dict in dict.msgs%} + {%if msg_dict.log == 1%} case {{dict.name.upper()}}_{{msg_dict.name.upper()}}: { - uint32_t len = sizeof(umsg_{{dict.name}}_{{msg_dict.name}}_t) + 5; - file.read((char *)(buffer.raw + 4),len-4); //read including the crc byte + file.read((char *)(buffer.raw + 8),len-8); //read including the crc byte umsg_{{dict.name}}_{{msg_dict.name}}_t message = buffer.s.{{dict.name}}.{{msg_dict.name}}; uint8_t retval = umsg_checkCRC(buffer.raw,len); if(retval){ @@ -89,6 +91,7 @@ void sort_{{dict.name}}_type(std::ifstream &file) file_{{dict.name}}_{{msg_dict.name}} << std::endl; } break; + {% endif %} {%endfor%} default: std::cerr << std::endl << "ERROR UNKNOWN MESSAGE TYPE: " << static_cast(msg_type) << std::endl; diff --git a/umsg_gen/umsg_gen/templates/msg.c.j2 b/umsg_gen/umsg_gen/templates/msg.c.j2 index 8f28ea9..4061ab9 100644 --- a/umsg_gen/umsg_gen/templates/msg.c.j2 +++ b/umsg_gen/umsg_gen/templates/msg.c.j2 @@ -27,14 +27,29 @@ umsg_sub_handle_t umsg_{{prefix}}_subscribe_ch(uint32_t prescaler, uint8_t lengt void umsg_{{prefix}}_publish(umsg_{{prefix}}_t* data) { umsg_publish(&msg_{{prefix}}, data, 0); - {%if == 0 %} + + {%if msg_dict.log == 1 or msg_dict.transmit == 1 %} + uint32_t len = 8; + len+= sizeof(umsg_{{topic_dict.name}}_{{msg_dict.name}}_t) + 1; + umsg_MessageToTransfer M; + M.s.sync0 = 'M'; + M.s.sync1 = 'R'; + M.s.msg_class = UMSG_{{topic_dict.name.upper()}}; + M.s.msg_type = {{topic_dict.name.upper()}}_{{msg_dict.name.upper()}}; + M.s.len = len; + M.s.{{topic_dict.name}}.{{msg_dict.name}} = *data; - {% else %} - - umsg_publish(&msg_{{prefix}}, data, channel); + M.raw[len] = umsg_calcCRC(&(M.raw),len); {% endif %} + {%if msg_dict.transmit == 1%} + umsg_publish_structured_to_transmit(&M); + {% endif %} + {%if msg_dict.log == 1 %} + umsg_publish_structured_to_log(&M); + {% endif %} + } void umsg_{{prefix}}_publish_ch(umsg_{{prefix}}_t* data, uint8_t channel) { @@ -48,48 +63,5 @@ uint8_t umsg_{{prefix}}_peek(umsg_{{prefix}}_t* data) { return umsg_peek(&msg_{{prefix}}, data, sizeof(umsg_{{prefix}}_t)); } -{%if log == "do_log" %} - - - -uint32_t umsg_{{prefix}}_receive_to_transfer(umsg_sub_handle_t queue, MessageToTransfer* msg){ - - if(umsg_{{prefix}}_receive(queue,&(msg->s.{{topic_dict.name}}.{{msg_dict.name}}),0)){ - - uint32_t len = 4; - msg->s.msg_class = UMSG_{{topic_dict.name.upper()}}; - msg->s.msg_type = {{topic_dict.name.upper()}}_{{msg_dict.name.upper()}}; - len+= sizeof(umsg_{{topic_dict.name}}_{{msg_dict.name}}_t); - msg->raw[len] = umsg_calcCRC(&(msg->raw),len); - return len+1; - } - - return 0; -} - - -//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future -/* -uint32_t umsg_{{prefix}}_publish_received(MessageToTransfer* msg) -{ - if(buffer[0]!=UMSG_{{topic_dict.name.upper()}} || buffer[1] !={{topic_dict.name.upper()}}_{{msg_dict.name.upper()}}) - { - return 1; - } - - uint32_t offset = 2; - uint8_t *flattened_data = (uint8_t *)data; - //this can probably be replaced by memcpy but it is done like this for now just to be safe - for(uint32_t i = 0; i < sizeof(umsg_{{prefix}}_t);i++) - { - flattened_data[i] = buffer[offset]; - offset++; - } - - return 0; -} -*/ - -{% endif %} {% endfor %} diff --git a/umsg_gen/umsg_gen/templates/msg.h.j2 b/umsg_gen/umsg_gen/templates/msg.h.j2 index fbd55f9..0e7d373 100644 --- a/umsg_gen/umsg_gen/templates/msg.h.j2 +++ b/umsg_gen/umsg_gen/templates/msg.h.j2 @@ -21,18 +21,6 @@ uint8_t umsg_{{prefix}}_receive(umsg_sub_handle_t queue, umsg_{{prefix}}_t* data uint8_t umsg_{{prefix}}_peek(umsg_{{prefix}}_t* data); -{%if log == "do_log"%} -//function headers for converting to binary format that can be used for message passing or logging the first symbols in the buffer indicate the message class and type -//for now lets assume that there are less than 255 message classes and 255 message types per class, this has to be fixed in the future -//please take care that the messages are build properly to avoid padding issues if the messages are opened on different system -// this method automatically appends the CRC to the struct -uint32_t umsg_{{prefix}}_receive_to_transfer(umsg_sub_handle_t queue,MessageToTransfer* msg); - - -/* -*/ -{% endif %} - {% endfor %} diff --git a/umsg_gen/umsg_gen/templates/msg_classes.c.j2 b/umsg_gen/umsg_gen/templates/msg_classes.c.j2 index 1fd42aa..fab5caf 100644 --- a/umsg_gen/umsg_gen/templates/msg_classes.c.j2 +++ b/umsg_gen/umsg_gen/templates/msg_classes.c.j2 @@ -7,28 +7,27 @@ umsg_msg_metadata_t msg_structured = {.name = "structured"}; umsg_sub_handle_t umsg_structured_subscribe_logger(uint32_t prescaler, uint8_t length){ - return umsg_subscribe(&msg_structured, prescaler, sizeof(struct umsg_structured), length, 0); + return umsg_subscribe(&msg_structured, prescaler, sizeof(umsg_MessageToTransfer), length, 0); } umsg_sub_handle_t umsg_structured_subscribe_transmitter(uint32_t prescaler, uint8_t length){ - return umsg_subscribe(&msg_structured, prescaler, sizeof(struct umsg_structured), length, 1); + return umsg_subscribe(&msg_structured, prescaler, sizeof(umsg_MessageToTransfer), length, 1); } -uint8_t umsg_receive_structured(umsg_sub_handle_t queue ,struct umsg_structured * data, uint32_t timeout){ +uint8_t umsg_receive_structured(umsg_sub_handle_t queue ,umsg_MessageToTransfer * data, uint32_t timeout){ return umsg_receive(queue, data, timeout); } -uint32_t umsg_publish_structured_to_log(struct umsg_structured * data){ +void umsg_publish_structured_to_log(umsg_MessageToTransfer * data){ umsg_publish(&msg_structured, data, 0); } - -uint32_t umsg_publish_structured_to_transmit(struct umsg_structured * data){ +void umsg_publish_structured_to_transmit(umsg_MessageToTransfer * data){ umsg_publish(&msg_structured, data, 1); } -void umsg_broadcast_structured(MessageToTransfer *msg){ +void umsg_broadcast_structured(umsg_MessageToTransfer *msg){ } \ No newline at end of file diff --git a/umsg_gen/umsg_gen/templates/msg_classes.h.j2 b/umsg_gen/umsg_gen/templates/msg_classes.h.j2 index 42f08c2..09b3ad6 100644 --- a/umsg_gen/umsg_gen/templates/msg_classes.h.j2 +++ b/umsg_gen/umsg_gen/templates/msg_classes.h.j2 @@ -87,7 +87,9 @@ umsg_{{topic_dict.name}}_{{type.lower()}}_t union umsg_{{topic_dict.name}}_Messages { {% for msg_dict in topic_dict.msgs %} + {%if msg_dict.log == 1 or msg_dict.transmit == 1 %} umsg_{{topic_dict.name}}_{{msg_dict.name}}_t {{msg_dict.name}}; + {% endif %} {% endfor -%} }; {%endfor%} @@ -99,6 +101,7 @@ struct __attribute__((packed, aligned(4))) umsg_structured{ uint8_t sync1; uint8_t msg_class; uint8_t msg_type; + uint32_t len; // length of the message including the CRC union{ {% for topic_dict in topic_dict_list%} union umsg_{{topic_dict.name}}_Messages {{topic_dict.name}}; @@ -111,7 +114,7 @@ typedef union { struct umsg_structured s; uint8_t raw[sizeof(struct umsg_structured) + 1]; -}MessageToTransfer; +}umsg_MessageToTransfer; @@ -119,13 +122,20 @@ typedef union { // this method only publishes the message if the CRC is correct -umsg_sub_handle_t umsg_structured_subscribe(uint32_t prescaler, uint8_t length); +umsg_sub_handle_t umsg_structured_subscribe_logger(uint32_t prescaler, uint8_t length); -uint32_t umsg_receive_structured(umsg_sub_handle_t queue ,struct umsg_structured * data, uint32_t timeout); +umsg_sub_handle_t umsg_structured_subscribe_transmitter(uint32_t prescaler, uint8_t length); -uint8_t umsg_publish_structured(struct umsg_structured * data); +uint8_t umsg_receive_structured(umsg_sub_handle_t queue ,umsg_MessageToTransfer * data, uint32_t timeout); -void umsg_broadcast_structured(MessageToTransfer *msg); + +void umsg_publish_structured_to_log(umsg_MessageToTransfer * data); + +void umsg_publish_structured_to_transmit(umsg_MessageToTransfer * data); + + + +void umsg_broadcast_structured(umsg_MessageToTransfer *msg); From 1e4226ac0324017ce34a1249aa2a776e63955400 Mon Sep 17 00:00:00 2001 From: Michal Reiser Date: Fri, 13 Dec 2024 14:21:54 +0100 Subject: [PATCH 14/16] modified the logging and transmition of the messages --- umsg_gen/umsg_gen/templates/log_parser.cpp.j2 | 3 ++- umsg_gen/umsg_gen/templates/msg.c.j2 | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 b/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 index 5f6e0ae..5e63bba 100644 --- a/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 +++ b/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 @@ -36,7 +36,7 @@ std::ofstream file_{{dict.name}}_{{msg_dict.name}}; void sort_{{dict.name}}_type(std::ifstream &file) { uint8_t msg_type; - uint32_t len; + uint32_t len = 0; file.read((char *)&msg_type, 1); file.read((char *)&len, 4); if (!file) { @@ -48,6 +48,7 @@ void sort_{{dict.name}}_type(std::ifstream &file) buffer.s.sync1 = 'R'; buffer.s.msg_class = UMSG_{{dict.name.upper()}}; buffer.s.msg_type = msg_type; + buffer.s.len = len; switch(msg_type) { {% for msg_dict in dict.msgs%} diff --git a/umsg_gen/umsg_gen/templates/msg.c.j2 b/umsg_gen/umsg_gen/templates/msg.c.j2 index 4061ab9..b381ff9 100644 --- a/umsg_gen/umsg_gen/templates/msg.c.j2 +++ b/umsg_gen/umsg_gen/templates/msg.c.j2 @@ -40,7 +40,7 @@ void umsg_{{prefix}}_publish(umsg_{{prefix}}_t* data) M.s.len = len; M.s.{{topic_dict.name}}.{{msg_dict.name}} = *data; - M.raw[len] = umsg_calcCRC(&(M.raw),len); + M.raw[len -1] = umsg_calcCRC((M.raw),len -1); {% endif %} {%if msg_dict.transmit == 1%} From 396b90b12ad50ac4b3a97da8f626a7e97c8dfe8f Mon Sep 17 00:00:00 2001 From: Michal Reiser Date: Mon, 27 Jan 2025 14:51:28 +0100 Subject: [PATCH 15/16] hopefully fixed the hardfault causing bug --- umsg_gen/umsg_gen/core/src/umsg.c | 4 +-- umsg_gen/umsg_gen/templates/msg.c.j2 | 2 +- umsg_gen/umsg_gen/templates/msg_classes.c.j2 | 35 +++++++++++++++++++- umsg_gen/umsg_gen/templates/msg_classes.h.j2 | 7 ++-- 4 files changed, 41 insertions(+), 7 deletions(-) diff --git a/umsg_gen/umsg_gen/core/src/umsg.c b/umsg_gen/umsg_gen/core/src/umsg.c index 47141af..228c3cc 100644 --- a/umsg_gen/umsg_gen/core/src/umsg.c +++ b/umsg_gen/umsg_gen/core/src/umsg.c @@ -6,7 +6,7 @@ #include #include -uint8_t CRCresults[256]; +static uint8_t CRCresults[256]; const uint8_t remainder_len = 8; const uint16_t POLYNOMIAL = 0x2F; // this is a CRC8 polynomial @@ -104,4 +104,4 @@ uint8_t umsg_calcCRC(uint8_t* buffer, uint32_t len) { remainder = CRCresults[data] ^ (remainder << 8); } return remainder; -} \ No newline at end of file +} diff --git a/umsg_gen/umsg_gen/templates/msg.c.j2 b/umsg_gen/umsg_gen/templates/msg.c.j2 index b381ff9..d026831 100644 --- a/umsg_gen/umsg_gen/templates/msg.c.j2 +++ b/umsg_gen/umsg_gen/templates/msg.c.j2 @@ -29,7 +29,7 @@ void umsg_{{prefix}}_publish(umsg_{{prefix}}_t* data) umsg_publish(&msg_{{prefix}}, data, 0); - {%if msg_dict.log == 1 or msg_dict.transmit == 1 %} + {%if msg_dict.log == 1 or msg_dict.transmit == 1 %} uint32_t len = 8; len+= sizeof(umsg_{{topic_dict.name}}_{{msg_dict.name}}_t) + 1; umsg_MessageToTransfer M; diff --git a/umsg_gen/umsg_gen/templates/msg_classes.c.j2 b/umsg_gen/umsg_gen/templates/msg_classes.c.j2 index fab5caf..b0b36e3 100644 --- a/umsg_gen/umsg_gen/templates/msg_classes.c.j2 +++ b/umsg_gen/umsg_gen/templates/msg_classes.c.j2 @@ -30,4 +30,37 @@ void umsg_publish_structured_to_transmit(umsg_MessageToTransfer * data){ void umsg_broadcast_structured(umsg_MessageToTransfer *msg){ -} \ No newline at end of file + switch(msg->s.msg_class){ + {% for topic_dict in topic_dict_list%} + case UMSG_{{topic_dict.name.upper()}}: + { + switch(msg->s.msg_type){ + {% for msg_dict in topic_dict.msgs %} + {% set prefix = topic_dict.name+'_'+msg_dict.name%} + {%if msg_dict.receive == 1 %} + case {{topic_dict.name.upper()}}_{{msg_dict.name.upper()}}: + { + umsg_{{prefix}}_t data = *msg->s.{{topic_dict.name}}.{{msg_dict.name}}; + umsg_{{prefix}}_publish(&data); + } + break; + {%endif%} + {% endfor%} + default: + break; + + } + break; + } + {% endfor%} + + + + + default: + break; + } + + + +} diff --git a/umsg_gen/umsg_gen/templates/msg_classes.h.j2 b/umsg_gen/umsg_gen/templates/msg_classes.h.j2 index 09b3ad6..368c008 100644 --- a/umsg_gen/umsg_gen/templates/msg_classes.h.j2 +++ b/umsg_gen/umsg_gen/templates/msg_classes.h.j2 @@ -87,7 +87,7 @@ umsg_{{topic_dict.name}}_{{type.lower()}}_t union umsg_{{topic_dict.name}}_Messages { {% for msg_dict in topic_dict.msgs %} - {%if msg_dict.log == 1 or msg_dict.transmit == 1 %} + {%if msg_dict.log == 1 or msg_dict.transmit == 1 or msg_dict.receive == 1 %} umsg_{{topic_dict.name}}_{{msg_dict.name}}_t {{msg_dict.name}}; {% endif %} {% endfor -%} @@ -95,6 +95,7 @@ umsg_{{topic_dict.name}}_{{type.lower()}}_t {%endfor%} +#define UMSG_HEADER_SIZE 8 struct __attribute__((packed, aligned(4))) umsg_structured{ uint8_t sync0; @@ -109,10 +110,10 @@ struct __attribute__((packed, aligned(4))) umsg_structured{ }; }; - +// +1 for crc spot typedef union { struct umsg_structured s; - uint8_t raw[sizeof(struct umsg_structured) + 1]; + uint8_t raw[sizeof(struct umsg_structured) + 2]; }umsg_MessageToTransfer; From c2394c2b35a2abcb98b16e283e6da89eb8f490d4 Mon Sep 17 00:00:00 2001 From: Michal Reiser Date: Mon, 27 Jan 2025 14:52:46 +0100 Subject: [PATCH 16/16] fixed the wrong syntax --- umsg_gen/umsg_gen/templates/msg_classes.c.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/umsg_gen/umsg_gen/templates/msg_classes.c.j2 b/umsg_gen/umsg_gen/templates/msg_classes.c.j2 index b0b36e3..aa8b674 100644 --- a/umsg_gen/umsg_gen/templates/msg_classes.c.j2 +++ b/umsg_gen/umsg_gen/templates/msg_classes.c.j2 @@ -40,7 +40,7 @@ void umsg_broadcast_structured(umsg_MessageToTransfer *msg){ {%if msg_dict.receive == 1 %} case {{topic_dict.name.upper()}}_{{msg_dict.name.upper()}}: { - umsg_{{prefix}}_t data = *msg->s.{{topic_dict.name}}.{{msg_dict.name}}; + umsg_{{prefix}}_t data = msg->s.{{topic_dict.name}}.{{msg_dict.name}}; umsg_{{prefix}}_publish(&data); } break;