diff --git a/CLS.c b/CLS.c index f0cfd9a..f8c8731 100644 --- a/CLS.c +++ b/CLS.c @@ -8,6 +8,9 @@ osTimerId_t CLS_HeatbeatTimerId = NULL; // Timer ID static CLS_HeatbeatData_t cls_heatbeat_data = {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"); @@ -17,6 +20,12 @@ void CLS_Heatbeat(void *argument) { 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; + } } void CLS_SendEventChangeTypePostion(CanDataId canid, CLS_Type_t newType, CLS_Position_t newPostion) { @@ -29,15 +38,11 @@ void CLS_SendEventChangeTypePostion(CanDataId canid, CLS_Type_t newType, CLS_Pos 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); + if(len >= 2) { + newType = data[0]; + newPostion.p0 = (data[1] & 0x0F); + newPostion.p1 = ((data[1] >> 4) & 0x0F); + writeNewSetting = true; } }