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/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/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 b263042..a7461df 100644 --- a/umsg_gen/umsg_gen/core/inc/umsg.h +++ b/umsg_gen/umsg_gen/core/inc/umsg.h @@ -13,29 +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(); +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 4fb8d8b..228c3cc 100644 --- a/umsg_gen/umsg_gen/core/src/umsg.c +++ b/umsg_gen/umsg_gen/core/src/umsg.c @@ -6,64 +6,102 @@ #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; +static 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; + } } -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; + +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; -} \ No newline at end of file + 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; +} 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/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..5e63bba --- /dev/null +++ b/umsg_gen/umsg_gen/templates/log_parser.cpp.j2 @@ -0,0 +1,224 @@ +// Generated with umsg_gen on {{ date }} + +#include +#include +#include +#include +#include +#include + +#include "umsg.h" +#include"umsg_classes.h" + +{% for val in topic_dict_list%} +#include +{%endfor%} + + + + +//globally defined streams for topic files + +umsg_MessageToTransfer buffer; + + +{% 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; + uint32_t len = 0; + file.read((char *)&msg_type, 1); + file.read((char *)&len, 4); + if (!file) { + std::cerr << std::endl << "Error reading file" << std::endl; + exit(2); + } + + buffer.s.sync0 = 'M'; + 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%} + {%if msg_dict.log == 1%} + case {{dict.name.upper()}}_{{msg_dict.name.upper()}}: + { + 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){ + 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(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) + {%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}}) + {% 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 %} + {% if field.bitfield %} + {%for bitfield in field.bitfield %} + file_{{dict.name}}_{{msg_dict.name}} << static_cast(message.{{bitfield.name}}){% if not loop.last%} << ", "{% endif %}; + {%endfor%} + {% endif %} + {% endfor %} + + 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; + 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 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; + + } + + 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%} + 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; + } + umsg_CRCInit(); + //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)) + { + sort_msg(file); + std::cout << "cursor at: " << file.tellg() << " from " << std::filesystem::file_size(file_path) << "\r"; + } + + // 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 +#include "umsg_classes.h" +#include "umsg.h" // msg instances {% for msg_dict in topic_dict.msgs %} {% set prefix = topic_dict.name+'_'+msg_dict.name%} 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%} @@ -23,6 +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 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; + + M.raw[len -1] = umsg_calcCRC((M.raw),len -1); + + {% 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) { @@ -36,5 +63,5 @@ uint8_t umsg_{{prefix}}_peek(umsg_{{prefix}}_t* data) { return umsg_peek(&msg_{{prefix}}, data, sizeof(umsg_{{prefix}}_t)); } +{% endfor %} -{% endfor %} \ No newline at end of file diff --git a/umsg_gen/umsg_gen/templates/msg.h.j2 b/umsg_gen/umsg_gen/templates/msg.h.j2 index 30e09ff..0e7d373 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,30 +6,9 @@ extern "C" { #endif #include +#include -// msg structure typedefs -{%if topic_dict.enums %} -{% for enum in topic_dict.enums%} -typedef enum -{ - {%for val in enum.enumerators%} - {{val.upper()}}{{ "," if not loop.last else "" }} - {%endfor%} -} umsg_{{topic_dict.name}}_{{enum.name}}_t; - -{%endfor%} -{% endif %} -{% 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 %} @@ -70,8 +20,11 @@ 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); + {% endfor %} + + #ifdef __cplusplus } #endif 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..aa8b674 --- /dev/null +++ b/umsg_gen/umsg_gen/templates/msg_classes.c.j2 @@ -0,0 +1,66 @@ +#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(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(umsg_MessageToTransfer), length, 1); +} + +uint8_t umsg_receive_structured(umsg_sub_handle_t queue ,umsg_MessageToTransfer * data, uint32_t timeout){ + return umsg_receive(queue, data, timeout); +} + + +void umsg_publish_structured_to_log(umsg_MessageToTransfer * data){ + umsg_publish(&msg_structured, data, 0); +} + +void umsg_publish_structured_to_transmit(umsg_MessageToTransfer * data){ + umsg_publish(&msg_structured, data, 1); +} + + +void umsg_broadcast_structured(umsg_MessageToTransfer *msg){ + + 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 new file mode 100644 index 0000000..368c008 --- /dev/null +++ b/umsg_gen/umsg_gen/templates/msg_classes.h.j2 @@ -0,0 +1,151 @@ +// Generated with umsg_gen on {{ date }} +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +typedef enum +{ +{% 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 %} + {%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 -%} + }; +{%endfor%} + + +#define UMSG_HEADER_SIZE 8 + +struct __attribute__((packed, aligned(4))) umsg_structured{ + uint8_t sync0; + 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}}; + {%endfor%} + }; +}; + +// +1 for crc spot +typedef union { + struct umsg_structured s; + uint8_t raw[sizeof(struct umsg_structured) + 2]; + +}umsg_MessageToTransfer; + + + + + +// this method only publishes the message if the CRC is correct + +umsg_sub_handle_t umsg_structured_subscribe_logger(uint32_t prescaler, uint8_t length); + +umsg_sub_handle_t umsg_structured_subscribe_transmitter(uint32_t prescaler, uint8_t length); + +uint8_t umsg_receive_structured(umsg_sub_handle_t queue ,umsg_MessageToTransfer * data, uint32_t timeout); + + +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); + + + + + + +#ifdef __cplusplus +} +#endif + + + diff --git a/umsg_gen/umsg_gen/umsg_gen.py b/umsg_gen/umsg_gen/umsg_gen.py index 3589eae..c0613e4 100644 --- a/umsg_gen/umsg_gen/umsg_gen.py +++ b/umsg_gen/umsg_gen/umsg_gen.py @@ -10,18 +10,30 @@ 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)) env.trim_blocks = True 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') src_template = env.get_template(name='msg.c.j2') cmake_template = env.get_template(name='CMakeLists.txt.j2') @@ -33,37 +45,70 @@ def main(): if not files: print('No files found') exit(1) - # 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 = [] + topic_dict_list = [] 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 - + 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) - 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'{topic_dict["name"]}') + + + # Generate the msg_classes header file + 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) + + + 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' + 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()) 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/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/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 diff --git a/umsg_lib/inc/umsg_battery.h b/umsg_lib/inc/umsg_battery.h index ebafa11..cd09240 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-07 #pragma once #ifdef __cplusplus @@ -7,31 +7,45 @@ extern "C" { #include +#include "umsg_classes.h" // msg structure typedefs typedef enum { - BATTERY_OK, - BATTERY_LOW, - BATTERY_DEAD + BATTERY_OK, + BATTERY_LOW, + 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; - 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); +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 #ifdef __cplusplus } #endif - diff --git a/umsg_lib/inc/umsg_classes.h b/umsg_lib/inc/umsg_classes.h new file mode 100644 index 0000000..4293809 --- /dev/null +++ b/umsg_lib/inc/umsg_classes.h @@ -0,0 +1,22 @@ +// Generated with umsg_gen on 2024-08-07 +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +typedef enum +{ + 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 316025f..0bfd554 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-07 #pragma once #ifdef __cplusplus @@ -7,24 +7,38 @@ extern "C" { #include +#include "umsg_classes.h" // msg structure typedefs + +// enumeration of topics +typedef enum +{ + 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); +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 #ifdef __cplusplus } #endif - diff --git a/umsg_lib/inc/umsg_example.h b/umsg_lib/inc/umsg_example.h index 14a919c..8bf3fc6 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-07 #pragma once #ifdef __cplusplus @@ -7,45 +7,67 @@ extern "C" { #include +#include "umsg_classes.h" // msg structure typedefs typedef enum { - GREEN, - BLUE, - READ + GREEN, + BLUE, + 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; + 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); +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 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); +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 #ifdef __cplusplus } #endif - diff --git a/umsg_lib/inc/umsg_sensors.h b/umsg_lib/inc/umsg_sensors.h index 069f0ad..be6b8b8 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-07 #pragma once #ifdef __cplusplus @@ -7,37 +7,58 @@ extern "C" { #include +#include "umsg_classes.h" // msg structure typedefs + +// enumeration of topics +typedef enum +{ + 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); +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 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); +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 #ifdef __cplusplus } #endif - diff --git a/umsg_lib/inc/umsg_test.h b/umsg_lib/inc/umsg_test.h index 2351e41..be70219 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-07 #pragma once #ifdef __cplusplus @@ -7,122 +7,178 @@ extern "C" { #include +#include "umsg_classes.h" // msg structure typedefs typedef enum { - ENUM_A, - ENUM_B, - ENUM_C + ENUM_A, + ENUM_B, + 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; - 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); +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 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); +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 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); +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 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); +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 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); +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 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); +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 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); +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 #ifdef __cplusplus } #endif - diff --git a/umsg_lib/inc/umsg_unused.h b/umsg_lib/inc/umsg_unused.h index a50276d..905c303 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-07 #pragma once #ifdef __cplusplus @@ -7,36 +7,57 @@ extern "C" { #include +#include "umsg_classes.h" // msg structure typedefs + +// enumeration of topics +typedef enum +{ + 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); +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 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); +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 #ifdef __cplusplus } #endif - diff --git a/umsg_lib/src/battery.c b/umsg_lib/src/battery.c index a24fd83..4751c12 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-07 #include #include @@ -7,28 +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; +} + + +// 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 ba562a0..0fec39b 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-07 #include #include @@ -7,28 +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; +} + + +// 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 186fcc5..624cdf9 100644 --- a/umsg_lib/src/example.c +++ b/umsg_lib/src/example.c @@ -1,61 +1,107 @@ -// Generated with umsg_gen on 2024-08-05 +// Generated with umsg_gen on 2024-08-07 #include #include // 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; +} + + +// 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) -{ - 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; +} + + +// 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 352d42d..21b9b5d 100644 --- a/umsg_lib/src/sensors.c +++ b/umsg_lib/src/sensors.c @@ -1,61 +1,108 @@ -// Generated with umsg_gen on 2024-08-05 +// Generated with umsg_gen on 2024-08-07 #include + #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; } + +// 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) -{ - 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; +} + + +// 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 f184098..7f6888e 100644 --- a/umsg_lib/src/test.c +++ b/umsg_lib/src/test.c @@ -1,196 +1,357 @@ -// Generated with umsg_gen on 2024-08-05 +// Generated with umsg_gen on 2024-08-07 #include #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; +} + + +// 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) -{ - 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; +} + + +// 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) -{ - 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; } + +// 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) -{ - 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; } + +// 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) -{ - 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; } + +// 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) -{ - 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; } + +// 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) -{ - 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; } + +// 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 e87fbc8..183cd14 100644 --- a/umsg_lib/src/unused.c +++ b/umsg_lib/src/unused.c @@ -1,61 +1,107 @@ -// Generated with umsg_gen on 2024-08-05 +// Generated with umsg_gen on 2024-08-07 #include #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; +} + + +// 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) -{ - 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; +} + + +// 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; +}