Compare commits
11 Commits
5535393c23
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 58b50b2fb3 | |||
| 4744762b4c | |||
| 4620d0a7ed | |||
| 7080707f9d | |||
| c322165491 | |||
| 2934954396 | |||
| a23a0f5a6d | |||
| a9cfa7bc5e | |||
| bcfcba5bb9 | |||
| 581ffc9ed9 | |||
| 7dc557c9a7 |
92
CLS.c
92
CLS.c
@@ -2,18 +2,65 @@
|
||||
#include "CLS.h"
|
||||
#include "CLSAddress.h"
|
||||
#include "cmsis_os2.h"
|
||||
#include "version_info.h"
|
||||
#include "CanDataHandler.h"
|
||||
|
||||
osTimerId_t CLS_HeatbeatTimerId; // Timer ID
|
||||
static uint8_t cls_hartbeat_counter = 0;
|
||||
osTimerId_t CLS_HeatbeatTimerId = NULL; // Timer ID
|
||||
osTimerId_t CLS_VehicleTimerId = NULL; // Timer ID
|
||||
static CLS_HeatbeatData_t cls_heatbeat_data = {0};
|
||||
static CLS_VehicleStatus_t cls_vehicle = {0};
|
||||
static uint8_t EventChangeTypeData[2] ={0};
|
||||
static CLS_Type_t newType = 0;
|
||||
static CLS_Position_t newPostion = {0};
|
||||
static bool writeNewSetting = false;
|
||||
|
||||
_Static_assert(sizeof(cls_heatbeat_data) == 8, "CLS_HeatbeatData_t is not 8 bytes");
|
||||
|
||||
void CLS_Heatbeat(void *argument) {
|
||||
// Code to be executed every 500ms
|
||||
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_1);
|
||||
cls_hartbeat_counter++;
|
||||
CLS_BSP_CAN_AddMessageToSend(&cls_hartbeat_header, &cls_hartbeat_counter);
|
||||
// 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);
|
||||
|
||||
if (writeNewSetting) {
|
||||
CLS_BSP_SetDeviceType(newType);
|
||||
CLS_BSP_SetPosition(newPostion);
|
||||
writeNewSetting = false;
|
||||
}
|
||||
}
|
||||
|
||||
__weak void CLS_VehicleHeatbeat(void *argument) {
|
||||
|
||||
}
|
||||
|
||||
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_CHANNEL7);
|
||||
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);
|
||||
}
|
||||
|
||||
const CLS_VehicleStatus_t * CLS_GetVehicleStatus(void) {
|
||||
return &cls_vehicle;
|
||||
}
|
||||
|
||||
void CLS_OnVehicleStatus(CanDataId canid, uint8_t* data, uint8_t len) {
|
||||
if(len == 8) {
|
||||
memcpy((uint8_t*)&cls_vehicle, data, 8);
|
||||
}
|
||||
}
|
||||
|
||||
void CLS_OnEventChangeTypePostion(CanDataId canid, uint8_t* data, uint8_t len) {
|
||||
|
||||
if(len >= 2) {
|
||||
newType = data[0];
|
||||
newPostion.p0 = (data[1] & 0x0F);
|
||||
newPostion.p1 = ((data[1] >> 4) & 0x0F);
|
||||
writeNewSetting = true;
|
||||
}
|
||||
}
|
||||
|
||||
void CLS_Init(void) {
|
||||
osTimerAttr_t timerAttr;
|
||||
@@ -22,11 +69,42 @@ void CLS_Init(void) {
|
||||
timerAttr.cb_mem = NULL;
|
||||
timerAttr.cb_size = 0U;
|
||||
|
||||
cls_heatbeat_data.firmware_version.major = VERSION_INFO.major;
|
||||
cls_heatbeat_data.firmware_version.minor = VERSION_INFO.minor;
|
||||
cls_heatbeat_data.firmware_version.patch = VERSION_INFO.patch;
|
||||
cls_heatbeat_data.firmware_version.count = VERSION_INFO.count;
|
||||
cls_heatbeat_data.id = gCLS_DEVICE_ADDRESS;
|
||||
cls_heatbeat_data.type = CLS_BSP_GetDeviceType();
|
||||
cls_heatbeat_data.counter = 0;
|
||||
cls_heatbeat_data.position = CLS_BSP_GetPosition();
|
||||
|
||||
CLS_HeatbeatTimerId = osTimerNew((osTimerFunc_t)CLS_Heatbeat, osTimerPeriodic, NULL, &timerAttr);
|
||||
if (CLS_HeatbeatTimerId != NULL) { // Timer object created
|
||||
if (osTimerStart(CLS_HeatbeatTimerId, 500) == osOK) { // Timer started
|
||||
// add gCLS_DEVICE_ADDRESS to the interval to avoid collisons
|
||||
if (osTimerStart(CLS_HeatbeatTimerId, CLS_HEARTBEAT_INTERVAL_MS + gCLS_DEVICE_ADDRESS) == osOK) { // Timer started
|
||||
// Timer started successfully
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (cls_heatbeat_data.type == cls_device_Type_MASTER) {
|
||||
timerAttr.name = "CLS_Vehicle_Heatbeat";
|
||||
CLS_VehicleTimerId = osTimerNew((osTimerFunc_t)CLS_VehicleHeatbeat, osTimerPeriodic, NULL, &timerAttr);
|
||||
if (CLS_VehicleTimerId != NULL) { // Timer object created
|
||||
|
||||
if (osTimerStart(CLS_VehicleTimerId, 100) == osOK) { // Timer started
|
||||
// Timer started successfully
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t cls_address = GENERATE_CLS_ADDRESS(CLS_CODE_CONFIG,gCLS_DEVICE_ADDRESS,CLS_CHANNEL7);
|
||||
//setup endpoint for changing the Device Type/Position
|
||||
CanData_regEventMsg(cls_address, CLS_OnEventChangeTypePostion);
|
||||
|
||||
|
||||
uint16_t cls_vehicle_address = GENERATE_CLS_ADDRESS(CLS_CODE_STATUS,0,CLS_CH_STA_VEHICLE);
|
||||
CanData_regEventMsg(cls_vehicle_address, CLS_OnVehicleStatus);
|
||||
}
|
||||
44
CLS.h
44
CLS.h
@@ -1,7 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
#define CLS_HEARTBEAT_INTERVAL_MS 1000
|
||||
|
||||
#include "cls_device.pb.h"
|
||||
|
||||
typedef cls_device_Type CLS_Type_t;
|
||||
|
||||
typedef cls_device_Position CLS_Position_Option_t;
|
||||
|
||||
typedef struct CLS_Position {
|
||||
CLS_Position_Option_t p0:4;
|
||||
CLS_Position_Option_t p1:4;
|
||||
} CLS_Position_t;
|
||||
|
||||
|
||||
typedef struct CLS_HeatbeatData
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint8_t major;
|
||||
uint8_t minor;
|
||||
uint8_t patch;
|
||||
uint8_t count;
|
||||
}firmware_version;
|
||||
|
||||
CLS_Type_t type;
|
||||
uint8_t id;
|
||||
uint8_t counter;
|
||||
CLS_Position_t position;
|
||||
} CLS_HeatbeatData_t;
|
||||
|
||||
|
||||
typedef struct CLS_VehicleStatus {
|
||||
uint8_t k15;
|
||||
uint8_t headlight;
|
||||
uint8_t engine;
|
||||
uint8_t speed;
|
||||
uint8_t unlocked;
|
||||
uint8_t reserved[3];
|
||||
} CLS_VehicleStatus_t;
|
||||
|
||||
extern uint8_t gCLS_DEVICE_ADDRESS;
|
||||
|
||||
|
||||
void CLS_Init(void);
|
||||
void CLS_SendEventChangeTypePostion(uint16_t canid, CLS_Type_t newType, CLS_Position_t newPostion);
|
||||
|
||||
const CLS_VehicleStatus_t * CLS_GetVehicleStatus(void);
|
||||
|
||||
void CLS_VehicleHeatbeat(void *argument);
|
||||
@@ -39,8 +39,8 @@ typedef enum {
|
||||
|
||||
typedef enum {
|
||||
CLS_CH_STA_HEATBEAT = 0, // 0b000
|
||||
CLS_CH_STA_1 = 1, // 0b001
|
||||
CLS_CH_STA_2 = 2, // 0b010
|
||||
CLS_CH_STA_VEHICLE = 1, // 0b001
|
||||
CLS_CH_STA_AMBIENTLIGHT = 2, // 0b010
|
||||
CLS_CH_STA_3 = 3, // 0b011
|
||||
CLS_CH_STA_4 = 4, // 0b100
|
||||
CLS_CH_STA_5 = 5, // 0b101
|
||||
|
||||
@@ -14,5 +14,5 @@ target_sources(${PROJECT_NAME}
|
||||
${CMAKE_CURRENT_LIST_DIR}/CanDataHandler.h
|
||||
)
|
||||
|
||||
target_include_directories(${PROJECT_NAME} INTERFACE ${CMAKE_CURRENT_LIST_DIR})
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE CLS_BSP)
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_LIST_DIR})
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE Revision CLS_BSP PROTOS)
|
||||
Reference in New Issue
Block a user