diff --git a/Core/Inc/main.h b/Core/Inc/main.h index 8937c6c..00bf3cf 100644 --- a/Core/Inc/main.h +++ b/Core/Inc/main.h @@ -57,7 +57,7 @@ typedef struct { void Error_Handler(void); /* USER CODE BEGIN EFP */ -void AMS_Error_Handler(AMSErrorHandle); +void AMS_Error_Handler(AMSErrorHandle*); /* USER CODE END EFP */ /* Private defines -----------------------------------------------------------*/ diff --git a/Core/Src/CAN_Communication.c b/Core/Src/CAN_Communication.c index 25ae679..b65a946 100644 --- a/Core/Src/CAN_Communication.c +++ b/Core/Src/CAN_Communication.c @@ -11,6 +11,8 @@ #include "stm32g4xx_hal_fdcan.h" +#include + // 3 should be programmed with CAN id 2 // const uint16_t slave_CAN_id_to_slave_index[7] = { // 255, 255, 0, 255, 255, 255, 1}; // TODO: Make this pretty pls @@ -68,16 +70,9 @@ uint8_t CAN_Receive(FDCAN_HandleTypeDef* hcan) { } else if (rxFrame.FrameID == SLAVE_EMERGENCY_ADDRESS) { AMSErrorHandle errorframe = {0}; errorframe.errorcode = SlavesErrorFrameError; - errorframe.errorarg[0] = rxFrame.data[0]; - errorframe.errorarg[1] = rxFrame.data[1]; - errorframe.errorarg[2] = rxFrame.data[2]; - errorframe.errorarg[3] = rxFrame.data[3]; - errorframe.errorarg[4] = rxFrame.data[4]; - errorframe.errorarg[5] = rxFrame.data[5]; - errorframe.errorarg[6] = rxFrame.data[6]; - errorframe.errorarg[7] = rxFrame.data[7]; + memcpy(errorframe.errorarg, rxFrame.data, 7); - AMS_Error_Handler(errorframe); + AMS_Error_Handler(&errorframe); } } diff --git a/Core/Src/SPI_Slave_Communication.c b/Core/Src/SPI_Slave_Communication.c index 96019f5..94e38f1 100644 --- a/Core/Src/SPI_Slave_Communication.c +++ b/Core/Src/SPI_Slave_Communication.c @@ -33,19 +33,7 @@ AIRStateHandler* spi_airstates; AMSErrorHandle* spierrorinfo; -void set_SPI_errorInfo(AMSErrorHandle* errorinfo) { - spierrorinfo = errorinfo; - - spierrorinfo->errorcode = 0; - spierrorinfo->errorarg[0] = 0; - spierrorinfo->errorarg[1] = 0; - spierrorinfo->errorarg[2] = 0; - spierrorinfo->errorarg[3] = 0; - spierrorinfo->errorarg[4] = 0; - spierrorinfo->errorarg[5] = 0; - spierrorinfo->errorarg[6] = 0; - spierrorinfo->errorarg[7] = 0; -} +void set_SPI_errorInfo(AMSErrorHandle* errorinfo) { spierrorinfo = errorinfo; } void spi_communication_init(SPI_HandleTypeDef* spi, AIRStateHandler* airstatemaschine) { diff --git a/Core/Src/Slave_Monitoring.c b/Core/Src/Slave_Monitoring.c index 48627af..166b048 100644 --- a/Core/Src/Slave_Monitoring.c +++ b/Core/Src/Slave_Monitoring.c @@ -48,8 +48,9 @@ uint8_t checkSlaveTimeout() { AMSErrorHandle timeouterror; timeouterror.errorcode = SlavesTimeoutError; + timeouterror.errorarg[0] = n; - AMS_Error_Handler(timeouterror); + AMS_Error_Handler(&timeouterror); return 1; } } diff --git a/Core/Src/main.c b/Core/Src/main.c index 618e016..0122891 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -351,10 +351,9 @@ static void MX_GPIO_Init(void) { } /* USER CODE BEGIN 4 */ -void AMS_Error_Handler(AMSErrorHandle errorinfo) { +void AMS_Error_Handler(AMSErrorHandle* errorinfo) { while (1) { - set_SPI_errorInfo(&errorinfo); - errorinfo.errorarg[7] = 1; + set_SPI_errorInfo(errorinfo); setAMSError(); airstates.targetTSState = TS_ERROR; Update_AIR_State(&airstates);