mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/CAN-Demo.git
synced 2025-08-05 21:59:42 +00:00
Addapted to reduced CAN task
This commit is contained in:
@@ -9,102 +9,36 @@
|
||||
#include <sta/debug/debug.hpp>
|
||||
#include <sta/rtos/debug/heap_stats.hpp>
|
||||
#include "can.h"
|
||||
#include <sta/tacos.hpp>
|
||||
|
||||
#include <cmsis_os2.h>
|
||||
|
||||
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
|
||||
|
||||
|
@@ -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()
|
||||
|
Reference in New Issue
Block a user