diff --git a/Core/Src/main.c b/Core/Src/main.c index 4eb7fbe..4743245 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -19,10 +19,12 @@ /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "cmsis_os.h" +#include /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ #include "../../MSB/api/msb_main.h" +#include "../../MSB/api/monitor_msb.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ @@ -32,7 +34,7 @@ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ - +#define BOARD_ID 1 /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ @@ -95,6 +97,14 @@ int main(void) /* USER CODE BEGIN Init */ + msb_temp_t *msb_temp= malloc(sizeof(msb_temp_t)); + msb_knuckle_t *msb_knuckle = malloc(sizeof(msb_knuckle_t)); + msb_central_t *msb_central = malloc(sizeof(msb_central_t)); + + msb_temp->id = BOARD_ID; + msb_knuckle->id = BOARD_ID; + msb_central->id = BOARD_ID; + /* USER CODE END Init */ /* Configure the system clock */ @@ -110,6 +120,7 @@ int main(void) MX_FDCAN1_Init(); MX_I2C3_Init(); MX_USART2_UART_Init(); + /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ @@ -138,7 +149,9 @@ int main(void) defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes); /* USER CODE BEGIN RTOS_THREADS */ - /* add threads, ... */ + osThreadId_t tempThread = osThreadNew(monitor_temp_msb, msb_temp, NULL); + osThreadId_t imuThread = osThreadNew(monitor_knuckle_msb, msb_knuckle, NULL); + osThreadId_t centralThread = osThreadNew(monitor_central_msb, msb_central, NULL); /* USER CODE END RTOS_THREADS */ /* USER CODE BEGIN RTOS_EVENTS */ @@ -440,7 +453,9 @@ void StartDefaultTask(void *argument) { /* USER CODE BEGIN 5 */ /* Infinite loop */ - start_msb(); + for (;;) { + + } /* USER CODE END 5 */ } diff --git a/MSB/api/monitor_msb.h b/MSB/api/monitor_msb.h new file mode 100644 index 0000000..c088abc --- /dev/null +++ b/MSB/api/monitor_msb.h @@ -0,0 +1,12 @@ +#ifndef READ_MSB_DATA +#define READ_MSB_DATA + +#include "msb_temp.h" +#include "msb_knuckle.h" +#include "msb_central.h" + +void monitor_temp_msb(void* arg); +void monitor_knuckle_msb(void* arg); +void monitor_central_msb(void* arg); + +#endif \ No newline at end of file diff --git a/MSB/api/msb_central.h b/MSB/api/msb_central.h index 6c9b1bd..0b0afe3 100644 --- a/MSB/api/msb_central.h +++ b/MSB/api/msb_central.h @@ -2,14 +2,21 @@ #ifndef MSB_CENTRAL_H #define MSB_CENTRAL_H -#include "api/msb_common.h" +#include "msb_common.h" typedef struct msb_central { - const short id; + short id; } msb_central_t; -void monitor_strain_gauge(msb_central_t* msb); -void monitor_potentiometer(msb_central_t* msb); -void monitor_tof(msb_central_t* msb); +typedef struct central_data { + const int strain; + const int potentiometer; + const int tof; +} central_data_t; + + +int measure_strain_gauge(central_data_t* out); +int measure_potentiometer(central_data_t* out); +int measure_tof(central_data_t* out); #endif diff --git a/MSB/api/msb_knuckle.h b/MSB/api/msb_knuckle.h index 6d3d67d..5dd89a8 100644 --- a/MSB/api/msb_knuckle.h +++ b/MSB/api/msb_knuckle.h @@ -2,12 +2,19 @@ #ifndef MSB_KNUCKLE_H #define MSB_KNUCKLE_H -#include "api/msb_common.h" +#include "msb_common.h" typedef struct msb_knuckle { - const short id; + short id; } msb_knuckle_t; -void monitor_imu(msb_knuckle_t* msb); +typedef struct msb_data { + int acceleration; + int x_angle; + int y_angle; + int z_angle; +} knuckle_data_t; + +int measure_imu(knuckle_data_t* out); #endif diff --git a/MSB/api/msb_temp.h b/MSB/api/msb_temp.h index 920873a..bec7401 100644 --- a/MSB/api/msb_temp.h +++ b/MSB/api/msb_temp.h @@ -2,12 +2,18 @@ #ifndef MSB_TEMP_H #define MSB_TEMP_H -#include "api/msb_common.h" +#include "msb_common.h" typedef struct msb_temp { - const short id; + short id; } msb_temp_t; -void monitor_temp(msb_temp_t* msb); +typedef struct temp_data { + int data; + char unit; +} temp_data_t; + +int measure_temp(temp_data_t* out); #endif + diff --git a/MSB/measure_msb.c b/MSB/measure_msb.c new file mode 100644 index 0000000..7c93e0d --- /dev/null +++ b/MSB/measure_msb.c @@ -0,0 +1,24 @@ + +#include "api/msb_central.h" +#include "api/msb_knuckle.h" +#include "api/msb_temp.h" + +int measure_strain_gauge(central_data_t* out) { + return 0; // TODO +} + +int measure_potentiometer(central_data_t* out) { + return 0; // TODO +} + +int measure_tof(central_data_t* out) { + return 0; // TODO +} + +int measure_imu(knuckle_data_t* out) { + return 0; // TODO +} + +int measure_temp(temp_data_t* out) { + return 0; // TODO +} diff --git a/MSB/monitor_msb.c b/MSB/monitor_msb.c new file mode 100644 index 0000000..4d2d26f --- /dev/null +++ b/MSB/monitor_msb.c @@ -0,0 +1,71 @@ +#include "cmsis_os.h" +#include +#include + +#include "api/monitor_msb.h" + +void monitor_temp_msb(void* arg) { + + msb_temp_t* msb = (msb_temp_t*) arg; + + temp_data_t* out = malloc(sizeof(temp_data_t)); + + char status[100]; + for (;;) { + int ret = measure_temp(out); + if (ret) { + return; //handle error + } + sprintf(status, "{\"id\": %d, \"data\": %d, \"unit\": \"%c\"}", msb->id, out->data, out->unit); + push_can_queue(status); + osDelay(500); + } +} + +void monitor_knuckle_msb(void* arg) { + + msb_knuckle_t* msb = (msb_knuckle_t*) arg; + + knuckle_data_t* out = malloc(sizeof(knuckle_data_t)); + + char status[100]; + for (;;) { + int ret = measure_imu(out); + if (ret) { + return; // handle error + } + sprintf(status, "{\"id\": %d, \"acceleration\": %d, \"x_angle\": %d, \"y-angle\": %d, \"z-angle\": %d}", + msb->id, out->acceleration, out->x_angle, out->y_angle, out->z_angle); + push_can_queue(status); + osDelay(500); + } +} + +void monitor_central_msb(void* arg) { + + msb_central_t* msb = (msb_central_t*) arg; + + central_data_t* out = malloc(sizeof(msb_central_t)); + + char status[100]; + for (;;) { + int potentiometer_ret = measure_potentiometer(out); + int strain_ret = measure_strain_gauge(out); + int tof_ret = measure_tof(out); + if (potentiometer_ret) { + return; //handle error + } + if (strain_ret) { + return; //handle error + } + if (tof_ret) { + return; //handle error + } + sprintf(status, "{\"id\": %d, \"potentiometer\": %d, \"strain\": %d, \"ToF\": %d}", + msb->id, out->potentiometer, out->strain, out->tof); + push_can_queue(status); + osDelay(500); + } +} + + diff --git a/Makefile b/Makefile index aaba8fa..71c2a48 100644 --- a/Makefile +++ b/Makefile @@ -75,7 +75,9 @@ Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c \ Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c \ Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c \ MSB/msb_main.c \ -MSB/msb_can.c +MSB/msb_can.c \ +MSB/monitor_msb.c \ +MSB/measure_msb.c # ASM sources ASM_SOURCES = \