diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml index 96f5bd0..ff2d585 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 959b373..5d0af61 100644 --- a/.settings/stm32cubeide.project.prefs +++ b/.settings/stm32cubeide.project.prefs @@ -1,5 +1,5 @@ 635E684B79701B039C64EA45C3F84D30=44DBEC1DE4EBA9B0485911FBE58BFC80 66BE74F758C12D739921AEA421D593D3=3 -8DF89ED150041C4CBC7CB9A9CAA90856=84EF3C290D485BA5E95DA5C0811FD966 -DC22A860405A8BF2F2C095E5B6529F12=84EF3C290D485BA5E95DA5C0811FD966 +8DF89ED150041C4CBC7CB9A9CAA90856=7B5B92F1162457C6ECACD202698061B0 +DC22A860405A8BF2F2C095E5B6529F12=3C8525AE6BF206AA629BF4979058680C eclipse.preferences.version=1 diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..1a0ac0d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,55 @@ +{ + "files.associations": { + "algorithm": "cpp", + "atomic": "cpp", + "bit": "cpp", + "cctype": "cpp", + "cinttypes": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "compare": "cpp", + "concepts": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "exception": "cpp", + "functional": "cpp", + "initializer_list": "cpp", + "ios": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "iterator": "cpp", + "limits": "cpp", + "list": "cpp", + "memory": "cpp", + "new": "cpp", + "ostream": "cpp", + "set": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "typeinfo": "cpp", + "unordered_map": "cpp", + "utility": "cpp", + "vector": "cpp", + "xfacet": "cpp", + "xhash": "cpp", + "xiosbase": "cpp", + "xlocale": "cpp", + "xlocinfo": "cpp", + "xlocnum": "cpp", + "xmemory": "cpp", + "xstddef": "cpp", + "xstring": "cpp", + "xtr1common": "cpp", + "xtree": "cpp", + "xutility": "cpp" + } +} \ No newline at end of file diff --git a/App/Inc/sta/config.hpp b/App/Inc/sta/config.hpp index 1c00977..c2e4c29 100644 --- a/App/Inc/sta/config.hpp +++ b/App/Inc/sta/config.hpp @@ -29,7 +29,7 @@ #define STA_RTOS_SYSTEM_EVENTS_ENABLE // #define STA_RTOS_SYSTEM_WATCHDOG_ENABLE // #define STA_RTOS_WATCHDOG_ENABLE -// #define STA_CAN_BUS_ENABLE +#define STA_CAN_BUS_ENABLE // Uses the default configuration for TACOS. #include diff --git a/App/Inc/tasks/can_task.hpp b/App/Inc/tasks/can_task.hpp index 8d70416..ada096d 100644 --- a/App/Inc/tasks/can_task.hpp +++ b/App/Inc/tasks/can_task.hpp @@ -15,18 +15,12 @@ namespace demo { class CanTask : public sta::tacos::TacosThread { public: - CanTask(const char* name, CAN_HandleTypeDef * handle); + CanTask(const char* name, uint32_t canID); void init() override; 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]; - sta::STM32CanController canController; - sta::CanTxHeader txHeader; }; } // namespace demo diff --git a/App/Inc/tasks/thermo.hpp b/App/Inc/tasks/thermo.hpp index 5cda223..3080d83 100644 --- a/App/Inc/tasks/thermo.hpp +++ b/App/Inc/tasks/thermo.hpp @@ -10,6 +10,9 @@ #include #include +#include +#include +#include #include #include @@ -30,7 +33,7 @@ namespace demo sta::STM32SPI* spi2; sta::STM32SPIDevice* device_; - sta::MAX31855 tc*; + sta::MAX31855* tc; }; } // namespace demo diff --git a/App/Src/startup.cpp b/App/Src/startup.cpp index fc9a855..7832ab8 100644 --- a/App/Src/startup.cpp +++ b/App/Src/startup.cpp @@ -8,11 +8,11 @@ #include #include #include -#include -#include #include #include +#include + #include @@ -32,8 +32,7 @@ namespace sta // ###### Register different threads for different states here. ###### // The dummy task runs for state 0. - Manager::instance()->registerThread(std::make_shared("CAN SPAM", &hcan1), {0}); - Manager::instance()->registerThread(std::make_shared(), {0}); + Manager::instance()->registerThread(std::make_shared("CAN test", 0x22), {ALL_STATES}); STA_DEBUG_PRINTF("The answer to everything is %d", 42); diff --git a/App/Src/tasks/can_task.cpp b/App/Src/tasks/can_task.cpp index 9f7940e..c668411 100644 --- a/App/Src/tasks/can_task.cpp +++ b/App/Src/tasks/can_task.cpp @@ -9,102 +9,36 @@ #include #include #include "can.h" +#include #include namespace demo { - CanTask::CanTask(const char* name, CAN_HandleTypeDef * handle) - : TacosThread(name, osPriorityNormal), canController(handle) + CanTask::CanTask(const char* name, uint32_t canID) + : TacosThread(name, osPriorityNormal) { - + setCanID(canID); } void CanTask::init() { - - canController.start(); - - txHeader.id.format = sta::CanIdFormat::STD; // Set to EXT for extended ID - txHeader.id.sid = 0x040; // Set the standard ID or extended ID - txHeader.payloadLength = 8; // Set the payload length (max 8 bytes) - - // Create your message payload - for (int i = 0; i < 8; ++i) { - payload[i] = i + 1; - } } void CanTask::func() { - //STA_DEBUG_HEAP_STATS(); - canController.sendFrame(txHeader, payload); - //STA_DEBUG_HEAP_STATS(); - - 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); - - uint8_t type_id, sensor_ID, value, include; - - unpackValues(canRX[0], &type_id, &sensor_ID, &value, &include); - - if (type_id == 0){ - if (sensor_ID == 1){ - - STA_DEBUG_PRINTLN("Relay 1 triggered"); - if(value == 1){ - HAL_GPIO_WritePin(GPIOA,GPIO_PIN_2, GPIO_PIN_SET); - } else if(value == 0){ - HAL_GPIO_WritePin(GPIOA,GPIO_PIN_2, GPIO_PIN_RESET); - } - - }else if (sensor_ID == 2){ - - STA_DEBUG_PRINTLN("Relay 2 triggered"); - if(value == 1){ - HAL_GPIO_WritePin(GPIOA,GPIO_PIN_1, GPIO_PIN_SET); - } else if(value == 0){ - HAL_GPIO_WritePin(GPIOA,GPIO_PIN_1, GPIO_PIN_RESET); - } - }else if (sensor_ID == 3){ - - STA_DEBUG_PRINTLN("Relay 3 triggered"); - if(value == 1){ - HAL_GPIO_WritePin(GPIOA,GPIO_PIN_0, GPIO_PIN_SET); - } else if(value == 0){ - HAL_GPIO_WritePin(GPIOA,GPIO_PIN_0, GPIO_PIN_RESET); - } - }else if (sensor_ID == 4){ - - STA_DEBUG_PRINTLN("Relay 4 triggered"); - if(value == 1){ - HAL_GPIO_WritePin(GPIOA,GPIO_PIN_3, GPIO_PIN_SET); - } else if(value == 0){ - HAL_GPIO_WritePin(GPIOA,GPIO_PIN_3, GPIO_PIN_RESET); - } - }else if (sensor_ID == 5){ - - STA_DEBUG_PRINTLN("Relay 5 triggered"); - if(value == 1){ - HAL_GPIO_WritePin(GPIOA,GPIO_PIN_6, GPIO_PIN_SET); - } else if(value == 0){ - HAL_GPIO_WritePin(GPIOA,GPIO_PIN_6, GPIO_PIN_RESET); - } - } + STA_DEBUG_PRINTLN("Can Task awaiting message"); + if (CAN_queue_.available() > 0) + { + // Receiving message + CanSysMsg msg; + CAN_queue_.get(&msg); + STA_DEBUG_PRINTLN("Can Task received message"); + // Sending it back + sta::tacos::queueCanBusMsg(msg, 0); + STA_DEBUG_PRINTLN("Can Task sent message"); } - - 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/tasks/thermo.cpp b/App/Src/tasks/thermo.cpp index dfee80c..4c855a9 100644 --- a/App/Src/tasks/thermo.cpp +++ b/App/Src/tasks/thermo.cpp @@ -28,10 +28,10 @@ namespace demo void ThermoTask::init() { mutex = new sta::RtosMutex("spi2"); - spi2 = new sta::STM32SPI(&hspi2, 16000000, &mutex); + spi2 = new sta::STM32SPI(&hspi2, 16000000, mutex); device_ = new sta::STM32SPIDevice(spi2, &cs_pin); - tc = new sta::MAX31855(&device_); //create driver object + tc = new sta::MAX31855(device_); //create driver object } void ThermoTask::func() diff --git a/Libs/TACOS b/Libs/TACOS index 16b2ed5..7147d6d 160000 --- a/Libs/TACOS +++ b/Libs/TACOS @@ -1 +1 @@ -Subproject commit 16b2ed5a20df1c04b9bbcf5e12101d5e822e45d2 +Subproject commit 7147d6de8308110eace178b11ab88548ca29177a