From 452246951bb9bce24b4a6099d8c07d3d2196c442 Mon Sep 17 00:00:00 2001 From: Oliver Walter Date: Tue, 28 May 2024 04:55:31 +0200 Subject: [PATCH] fixed error on can parsing --- Application/Tasks/CanDataTask.c | 7 +++++-- Application/Vehicle/Vehicle_can.c | 20 +++++++++++++++++--- tools/set_device_type.py | 8 ++++---- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/Application/Tasks/CanDataTask.c b/Application/Tasks/CanDataTask.c index b4d170f..b5a6467 100644 --- a/Application/Tasks/CanDataTask.c +++ b/Application/Tasks/CanDataTask.c @@ -139,6 +139,10 @@ void byteToHex(uint8_t byte, char * hex) { hex[1] = hexLookup[byte & 0x0F]; } + +static FDCAN_RxHeaderTypeDef RxHeader = {0}; +static uint8_t RxData[8] = {0}; + void CarCanTask_func(void *argument) { // for testing accept all messages from the car can bus @@ -160,8 +164,7 @@ void CarCanTask_func(void *argument) { Error_Handler(); } - FDCAN_RxHeaderTypeDef RxHeader; - uint8_t RxData[8]; + for(;;) { // wait for interrupt event on any fifo diff --git a/Application/Vehicle/Vehicle_can.c b/Application/Vehicle/Vehicle_can.c index f278128..c05dab4 100644 --- a/Application/Vehicle/Vehicle_can.c +++ b/Application/Vehicle/Vehicle_can.c @@ -31,7 +31,7 @@ void Vehicle_Setup_CAN() { } -static void rx_unlock(uint8_t * RxData ) { +static void rx_unlock_key(uint8_t * RxData ) { if (RxData[1] == 0x04) { // car was unlocked @@ -47,6 +47,20 @@ static void rx_unlock(uint8_t * RxData ) { } +static void rx_unlock_secure(uint8_t * RxData ) { + if ((RxData[0] & 0x0F) == 0x01) { + // car was unlocked + last_unlock_message_time = osKernelGetTickCount(); + + } else if ((RxData[0] & 0x0F) == 0x02) { + // car was locked + if (!BSP_GPIO_K15isSet()) { + NVIC_SystemReset(); + } + } + + +} static void rx_speed(uint8_t * RxData) { // speed signal @@ -70,11 +84,11 @@ static void rx_brightness(uint8_t* RxData) { void Vehicle_Receive_CAN( FDCAN_RxHeaderTypeDef RxHeader, uint8_t* RxData) { if(RxHeader.Identifier == 0x391) { - rx_unlock(RxData); + rx_unlock_key(RxData); } if (RxHeader.Identifier == 0x395) { - rx_unlock(RxData); + rx_unlock_secure(RxData); } diff --git a/tools/set_device_type.py b/tools/set_device_type.py index 5445a92..97b003b 100644 --- a/tools/set_device_type.py +++ b/tools/set_device_type.py @@ -6,10 +6,10 @@ if __name__ == "__main__": ser = setup_connection() # Create a message request = UpdateDeviceSettings() - request.device = 5 - request.type = Type.LIGHT - request.position.append(Position.RIGHT) - request.position.append(Position.FLOOR) + request.device = 0 + request.type = Type.COMMING_HOME + request.position.append(Position.LEFT) + request.position.append(Position.CENTER) # Serialize the request to a bytearray request_data = request.SerializeToString()