chore: Cleanup for Demo

This commit is contained in:
CarlWachter
2024-07-05 14:06:49 +02:00
parent fd7c123a5e
commit 1f6c939630
44 changed files with 432 additions and 7326 deletions

BIN
App/Src/.DS_Store vendored Normal file

Binary file not shown.

View File

@@ -5,19 +5,9 @@
* Author: Dario
*/
#include <sta/debug/debug.hpp>
#include <tasks/can_task.hpp>
#include <tasks/thermo.hpp>
#include <sta/devices/stm32/gpio_pin.hpp>
#include <sta/rtos/debug/heap_stats.hpp>
#include <sta/tacos.hpp>
#include <memory>
extern CAN_HandleTypeDef hcan1;
#include <tasks/can_spam.hpp>
#include <tasks/can_receiver.hpp>
namespace sta
{
namespace tacos
@@ -31,12 +21,13 @@ namespace sta
{
// ###### Register different threads for different states here. ######
// The dummy task runs for state 0.
Manager::instance()->registerThread(std::make_shared<demo::CanTask>("CAN test", 0x123), {ALL_STATES});
// Register Spam Thread to only run in the first state
addThread<demo::CanSpam>({ALL_STATES}, 0x123);
// Register Receive Thread to run in states 0 and 2
addThread<demo::CanReceiver>({0,2}, 0x124);
STA_DEBUG_PRINTF("The answer to everything is %d", 42);
STA_DEBUG_HEAP_STATS();
}
} // namespace tacos
} // namespace sta

BIN
App/Src/tasks/.DS_Store vendored Normal file

Binary file not shown.

View File

@@ -0,0 +1,45 @@
/*
* can_task.cpp
*
* Created on: 10 Dec 2023
* Author: Carl
*/
#include <sta/tacos.hpp>
#include <tasks/can_receiver.hpp>
namespace demo
{
CanReceiver::CanReceiver(uint32_t canID)
: TacosThread("CAN Receiver", osPriorityNormal)
{
setCanID(canID);
}
void CanReceiver::init()
{
}
void CanReceiver::func()
{
CanSysMsg msg;
if (CAN_queue_.get(&msg, osWaitForever))
{
STA_DEBUG_PRINTF("Received Message!\n"
"Payload Byte 0: %d\n"
"Payload Byte 1: %d\n"
"Payload Byte 2: %d\n"
"Payload Byte 3: %d\n"
"Payload Byte 4: %d\n"
"Payload Byte 5: %d\n"
"Payload Byte 6: %d\n"
"Payload Byte 7: %d\n",
msg.payload[0], msg.payload[1],
msg.payload[2], msg.payload[3],
msg.payload[4], msg.payload[5],
msg.payload[6], msg.payload[7]);
}
}
} // namespace demo

View File

@@ -0,0 +1,41 @@
/*
* can_task.cpp
*
* Created on: 10 Dec 2023
* Author: Carl
*/
#include <sta/tacos.hpp>
#include <tasks/can_spam.hpp>
namespace demo
{
CanSpam::CanSpam(uint32_t canID)
: TacosThread("CAN Spam", osPriorityNormal)
{
setCanID(canID);
}
void CanSpam::init()
{
}
void CanSpam::func()
{
CanSysMsg msg;
// Send some random stuff
msg.payload[0] = 1;
msg.payload[1] = 2;
msg.payload[2] = 3;
msg.header.sid = getCanID();
msg.header.format = 0;
sta::tacos::queueCanBusMsg(msg, 0);
STA_DEBUG_PRINTLN("Can Task sent message");
this->periodicDelay(1); // Delay to ensure 1 Hz rate.
}
} // namespace demo

View File

@@ -1,51 +0,0 @@
/*
* can_task.cpp
*
* Created on: 10 Dec 2023
* Author: Carl
*/
#include <tasks/can_task.hpp>
#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, uint32_t canID)
: TacosThread(name, osPriorityNormal)
{
setCanID(canID);
}
void CanTask::init()
{
}
void CanTask::func()
{
//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 with one changed bit
msg.payload[1] = 3;
msg.header.sid = getCanID();
msg.header.eid = 0;
msg.header.format = 0;
sta::tacos::queueCanBusMsg(msg, 0);
STA_DEBUG_PRINTLN("Can Task sent message");
HAL_Delay(500);
}
}
} // namespace demo

View File

@@ -1,58 +0,0 @@
/*
* can_task.cpp
*
* Created on: 10 Dec 2023
* Author: Carl
*/
#include <tasks/thermo.hpp>
#include <sta/debug/debug.hpp>
#include <sta/rtos/debug/heap_stats.hpp>
#include <gpio.h>
#include <spi.h>
#include <sta/MAX31855.hpp>
#include <sta/devices/stm32/bus/spi.hpp>
#include <sta/rtos/mutex.hpp>
#include <cmsis_os2.h>
namespace demo
{
ThermoTask::ThermoTask()
: TacosThread("Thermo", osPriorityNormal)
{
}
void ThermoTask::init()
{
mutex = new sta::RtosMutex("spi2");
spi2 = new sta::STM32SPI(&hspi2, 16000000, mutex);
device_ = new sta::STM32SPIDevice(spi2, &cs_pin);
tc = new sta::MAX31855(device_); //create driver object
}
void ThermoTask::func()
{
//STA_DEBUG_HEAP_STATS();
//canController.sendFrame(txHeader, payload);
//STA_DEBUG_HEAP_STATS();
//fuck off other pins
HAL_GPIO_WritePin(GPIOE,GPIO_PIN_12, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOB,GPIO_PIN_10, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOE,GPIO_PIN_15, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOE,GPIO_PIN_14, GPIO_PIN_SET);
tc->update(); // update internal values
float temperature = tc->getTemp(); //read out temperature in degrees Celsius
float referenceTemperature = tc->getReferenceTemp(); // read out reference temperature in degrees Celsius
uint8_t status = tc->getStatus(); //read out status of the update
HAL_Delay(1000);
}
} // namespace demo

View File

@@ -1,72 +0,0 @@
/*
* test.cpp
*
* Created on: Oct 24, 2023
* Author: carlw
*/
/*
//#include <sta/bus/can/controller.hpp>
#include <sta/devices/stm32/can.hpp>
//extern STM32CanController(CAN_HandleTypeDef * handle);
extern "C" void testCan(CAN_HandleTypeDef * handle){
sta::STM32CanController canController(handle);
canController.start();
// Create a CanTxHeader for your message
sta::CanTxHeader txHeader;
txHeader.id.format = sta::CanIdFormat::STD; // Set to EXT for extended ID
txHeader.id.sid = 0x010; // Set the standard ID or extended ID
txHeader.payloadLength = 8; // Set the payload length (max 8 bytes)
// Create your message payload
uint8_t payload[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
// Send the CAN message
while (true){
canController.sendFrame(txHeader, payload);
HAL_Delay(1000);
}
}
extern "C" void testCanMsg(CAN_HandleTypeDef * handle, uint8_t payload[8]){
sta::STM32CanController canController(handle);
//canController.start();
// Create a CanTxHeader for your message
sta::CanTxHeader txHeader;
txHeader.id.format = sta::CanIdFormat::STD; // Set to EXT for extended ID
txHeader.id.sid = 0x030; // Set the standard ID or extended ID
txHeader.payloadLength = 8; // Set the payload length (max 8 bytes)
// Send the CAN message
canController.sendFrame(txHeader, payload);
}
extern "C" 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
}
extern "C" uint8_t packValues(uint8_t type_id, uint8_t sensor_ID, uint8_t value, uint8_t include) {
uint8_t packedByte = 0;
// Shifting and ORing the values
packedByte |= (type_id & 0x03) << 6; // Two bits for type_id, left-shifted by 6
packedByte |= (sensor_ID & 0x07) << 3; // Three bits for sensorID, left-shifted by 3
packedByte |= (include & 0x01) << 2; // Flag for included value
packedByte |= (value & 0x01) << 1; // One bit for value
return packedByte;
}*/