mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/CAN-Demo.git
synced 2025-08-05 21:59:42 +00:00
[untested] Rudeimentary demo for EGSE on TACOS
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include <tasks/can_task.hpp>
|
||||
#include <sta/debug/debug.hpp>
|
||||
#include <sta/rtos/debug/heap_stats.hpp>
|
||||
#include "can.h"
|
||||
|
||||
#include <cmsis_os2.h>
|
||||
|
||||
@@ -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
|
||||
|
||||
|
Reference in New Issue
Block a user