mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/CAN-Demo.git
synced 2025-06-12 03:56:00 +00:00
53 lines
1.3 KiB
C++
53 lines
1.3 KiB
C++
/*
|
|
* 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 <sta/rtos/system/can_bus.hpp>
|
|
|
|
#include <cmsis_os2.h>
|
|
|
|
#include <sta/tacos/can_bus.hpp>
|
|
|
|
namespace demo
|
|
{
|
|
CanTask::CanTask(const char* name, CAN_HandleTypeDef * handle)
|
|
: TacosThread(name, osPriorityNormal), canController(handle)
|
|
{
|
|
|
|
}
|
|
|
|
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()
|
|
{
|
|
//struct CanDataMsg myCanDataMsg = {
|
|
///*.header = */ txHeader.id.sid, txHeader.id.eid, (uint8_t)txHeader.id.format, txHeader.payloadLength ,
|
|
///*.payload = */ *payload // Initialize payload to zero (or any other values as needed)
|
|
//};
|
|
canController.sendFrame(txHeader, payload);
|
|
//STA_DEBUG_PRINTLN(sta::tacos::CanBus::instance()->queueCanBusMsg(myCanDataMsg, osWaitForever));
|
|
STA_DEBUG_PRINTLN("SENT FRAME");
|
|
HAL_Delay(1000);
|
|
}
|
|
} // namespace demo
|
|
|