endpoint for changing DeviceSettings

This commit is contained in:
2024-04-30 11:02:41 +02:00
parent a9cfa7bc5e
commit a23a0f5a6d
2 changed files with 30 additions and 5 deletions

32
CLS.c
View File

@@ -3,22 +3,43 @@
#include "CLSAddress.h"
#include "cmsis_os2.h"
#include "version_info.h"
#include "CanDataHandler.h"
osTimerId_t CLS_HeatbeatTimerId; // Timer ID
osTimerId_t CLS_HeatbeatTimerId = NULL; // Timer ID
static CLS_HeatbeatData_t cls_heatbeat_data = {0};
static uint8_t EventChangeTypeData[2] ={0};
_Static_assert(sizeof(cls_heatbeat_data) == 8, "CLS_HeatbeatData_t is not 8 bytes");
void CLS_Heatbeat(void *argument) {
// Code to be executed every CLS_HEARTBEAT_INTERVAL_MS
CLS_BSP_TxHeaderType cls_hartbeat_header = CREATE_BSP_CAN_HEADER(GENERATE_CLS_ADDRESS(CLS_CODE_STATUS,gCLS_DEVICE_ADDRESS,CLS_CH_STA_HEATBEAT), CLS_BSP_DLC_BYTES_8);
cls_heatbeat_data.counter++;
CLS_BSP_CAN_AddMessageToSend(&cls_hartbeat_header, (uint8_t*)&cls_heatbeat_data);
}
void CLS_SendEventChangeTypePostion(CanDataId canid, CLS_Type_t newType, CLS_Position_t newPostion) {
const uint16_t cls_address = GENERATE_CLS_ADDRESS(CLS_CODE_CONFIG,canid,CLS_CHANNEL8);
EventChangeTypeData[0] = (uint8_t)newType;
EventChangeTypeData[1] = (newPostion.p0 & 0x0F) | ((newPostion.p1 << 4) & 0xF0);
CLS_BSP_TxHeaderType cls_hartbeat_header = CREATE_BSP_CAN_HEADER(cls_address, CLS_BSP_DLC_BYTES_2);
CLS_BSP_CAN_AddMessageToSend(&cls_hartbeat_header, (uint8_t*)&EventChangeTypeData);
}
void CLS_OnEventChangeTypePostion(CanDataId canid, uint8_t* data, uint8_t len) {
if (len > 0) {
CLS_BSP_SetDeviceType((CLS_Type_t) data[0]);
}
if(len >1) {
CLS_Position_t pos;
pos.p0 = (data[1] & 0x0F);
pos.p1 = ((data[1] >> 4) & 0x0F);
CLS_BSP_SetPosition(pos);
}
}
void CLS_Init(void) {
osTimerAttr_t timerAttr;
@@ -43,4 +64,9 @@ void CLS_Init(void) {
// Timer started successfully
}
}
uint16_t cls_address = GENERATE_CLS_ADDRESS(CLS_CODE_CONFIG,gCLS_DEVICE_ADDRESS,CLS_CHANNEL8);
//setup endpoint for changing the Device Type/Position
CanData_regEventMsg(cls_address, CLS_OnEventChangeTypePostion);
}

3
CLS.h
View File

@@ -33,6 +33,5 @@ typedef struct CLS_HeatbeatData
extern uint8_t gCLS_DEVICE_ADDRESS;
void CLS_Init(void);
void CLS_SendEventChangeTypePostion(uint16_t canid, CLS_Type_t newType, CLS_Position_t newPostion);