diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml index ff2d585..96f5bd0 100644 --- a/.settings/language.settings.xml +++ b/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + @@ -16,7 +16,7 @@ - + diff --git a/.settings/stm32cubeide.project.prefs b/.settings/stm32cubeide.project.prefs index 0d7d288..48449af 100644 --- a/.settings/stm32cubeide.project.prefs +++ b/.settings/stm32cubeide.project.prefs @@ -1,5 +1,5 @@ 635E684B79701B039C64EA45C3F84D30=44DBEC1DE4EBA9B0485911FBE58BFC80 66BE74F758C12D739921AEA421D593D3=3 -8DF89ED150041C4CBC7CB9A9CAA90856=7B5B92F1162457C6ECACD202698061B0 -DC22A860405A8BF2F2C095E5B6529F12=7B5B92F1162457C6ECACD202698061B0 +8DF89ED150041C4CBC7CB9A9CAA90856=84EF3C290D485BA5E95DA5C0811FD966 +DC22A860405A8BF2F2C095E5B6529F12=B12B632EDB5BE446F20C032575C0758A eclipse.preferences.version=1 diff --git a/App/Inc/tasks/can_task.hpp b/App/Inc/tasks/can_task.hpp index 896af90..8d70416 100644 --- a/App/Inc/tasks/can_task.hpp +++ b/App/Inc/tasks/can_task.hpp @@ -21,6 +21,7 @@ namespace demo void func() override; + void unpackValues(uint8_t packedByte, uint8_t* type_id, uint8_t* sensor_ID, uint8_t* value, uint8_t* include); private: uint8_t payload[8]; diff --git a/App/Src/tasks/can_task.cpp b/App/Src/tasks/can_task.cpp index 9f8e2ee..84bd5a3 100644 --- a/App/Src/tasks/can_task.cpp +++ b/App/Src/tasks/can_task.cpp @@ -8,6 +8,7 @@ #include #include #include +#include "can.h" #include @@ -37,10 +38,36 @@ namespace demo void CanTask::func() { //STA_DEBUG_HEAP_STATS(); - canController.sendFrame(txHeader, payload); + //canController.sendFrame(txHeader, payload); //STA_DEBUG_HEAP_STATS(); - STA_DEBUG_PRINTLN("SENT FRAME"); + + CAN_RxHeaderTypeDef rxHeader; //CAN Bus Receive Header + uint8_t canRX[8] = {0,0,0,0,0,0,0,0}; //CAN Bus Receive Buffer + + STA_DEBUG_PRINTLN("WAITING"); + HAL_CAN_GetRxMessage(&hcan1, CAN_RX_FIFO0, &rxHeader, canRX); + STA_DEBUG_PRINTLN("RECEIVED"); + + uint8_t type_id, sensor_ID, value, include; + + unpackValues(canRX[0], &type_id, &sensor_ID, &value, &include); + + if (type_id == 0 && sensor_ID == 1){ + if (value == 0){ + HAL_GPIO_WritePin(GPIOD,GPIO_PIN_8, GPIO_PIN_RESET); + }else{ + HAL_GPIO_WritePin(GPIOD,GPIO_PIN_8, GPIO_PIN_SET); + } + } + HAL_Delay(1000); } + + void CanTask::unpackValues(uint8_t packedByte, uint8_t* type_id, uint8_t* sensor_ID, uint8_t* value, uint8_t* include) { + *type_id = (packedByte >> 6) & 0x03; // Extracting two bits for type_id + *sensor_ID = (packedByte >> 3) & 0x07; // Extracting three bits for sensorID + *include = (packedByte >> 2) & 0x01; // Extracting the flag for included value + *value = (packedByte >> 1) & 0x01; // Extracting one bit for value + } } // namespace demo diff --git a/App/Src/test.cpp b/App/Src/test.cpp index 5f0f095..154166a 100644 --- a/App/Src/test.cpp +++ b/App/Src/test.cpp @@ -4,7 +4,7 @@ * Created on: Oct 24, 2023 * Author: carlw */ - +/* //#include #include @@ -69,4 +69,4 @@ packedByte |= (value & 0x01) << 1; // One bit for value return packedByte; - } + }*/ diff --git a/Core/Src/main.c b/Core/Src/main.c index cd8842f..f8a7cc3 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -26,10 +26,9 @@ /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ //#include -extern void testCan(CAN_HandleTypeDef * handle); -extern void testCanMsg(CAN_HandleTypeDef * handle, uint8_t payload[8]); -extern void unpackValues(uint8_t packedByte, uint8_t* type_id, uint8_t* sensor_ID, uint8_t* value, uint8_t* include); -extern uint8_t packValues(uint8_t type_id, uint8_t sensor_ID, uint8_t value, uint8_t include); +//extern void testCan(CAN_HandleTypeDef * handle); +//extern void testCanMsg(CAN_HandleTypeDef * handle, uint8_t payload[8]); +//extern uint8_t packValues(uint8_t type_id, uint8_t sensor_ID, uint8_t value, uint8_t include); /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ @@ -208,15 +207,19 @@ void SystemClock_Config(void) /* USER CODE BEGIN 4 */ +void unpackValues(uint8_t packedByte, uint8_t* type_id, uint8_t* sensor_ID, uint8_t* value, uint8_t* include) { + *type_id = (packedByte >> 6) & 0x03; // Extracting two bits for type_id + *sensor_ID = (packedByte >> 3) & 0x07; // Extracting three bits for sensorID + *include = (packedByte >> 2) & 0x01; // Extracting the flag for included value + *value = (packedByte >> 1) & 0x01; // Extracting one bit for value + } + void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan1) { - HAL_GPIO_TogglePin(GPIOD,GPIO_PIN_8); - received = 1; - HAL_CAN_GetRxMessage(hcan1, CAN_RX_FIFO0, &rxHeader, canRX); - /*uint8_t type_id, sensor_ID, value, include; + uint8_t type_id, sensor_ID, value, include; unpackValues(canRX[0], &type_id, &sensor_ID, &value, &include); @@ -226,7 +229,7 @@ void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan1) }else{ HAL_GPIO_WritePin(GPIOD,GPIO_PIN_8, GPIO_PIN_SET); } - }*/ + } }