diff --git a/Core/Inc/flash_config.h b/Core/Inc/flash_config.h index 916ec27..1c96e0e 100644 --- a/Core/Inc/flash_config.h +++ b/Core/Inc/flash_config.h @@ -9,7 +9,7 @@ typedef struct { uint32_t magic; // 魔数,用于验证配置有效性 wiz_NetInfo net_config; // 网络配置 - DeviceParam device_param; // 设备参数 + DeviceParam_t device_param; // 设备参数 uint32_t checksum; // 校验和 } FlashConfig_t; diff --git a/Core/Inc/main.h b/Core/Inc/main.h index 1dd54fb..8f9ec42 100644 --- a/Core/Inc/main.h +++ b/Core/Inc/main.h @@ -56,6 +56,9 @@ extern volatile uint8_t motorRxEnd; /* Exported functions prototypes ---------------------------------------------*/ void Error_Handler(void); void transDataToMotorValve(uint8_t *data, uint16_t len); +void transDataToHost(uint8_t *data, uint16_t len); +uint8_t readDataFromMotorValve(uint8_t *data, uint16_t len, uint32_t timeout); + /* USER CODE BEGIN EFP */ /* USER CODE END EFP */ diff --git a/Core/Src/http_server.c b/Core/Src/http_server.c index 1ac7530..9217a32 100644 --- a/Core/Src/http_server.c +++ b/Core/Src/http_server.c @@ -182,7 +182,7 @@ static void handle_status_request(uint8_t sn) "\"errorCode\":%d," "\"initStatus\":%d" "}", - deviceStatus.deviceStatus, + deviceStatus.sensorStatus, deviceStatus.valves.angle1, deviceStatus.valves.angle2, deviceStatus.pumps.status1, diff --git a/Core/Src/main.c b/Core/Src/main.c index f6ab2ff..e29443a 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -38,7 +38,7 @@ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ - +#define HOST_USE_DMA 1 /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ @@ -64,10 +64,13 @@ void transDataToHost(uint8_t *data, uint16_t len) { // 开启uart3 dma HAL_GPIO_WritePin(DIR1_GPIO_Port, DIR1_Pin, GPIO_PIN_SET); - // HAL_Delay(100); + #ifdef HOST_USE_DMA + HAL_UART_Transmit_DMA(&huart1, data, len); + #else HAL_UART_Transmit(&huart1, data, len, 1000); HAL_GPIO_WritePin(DIR1_GPIO_Port, DIR1_Pin, GPIO_PIN_RESET); - // HAL_Delay(100); + #endif + } void transDataToMotorValve(uint8_t *data, uint16_t len) @@ -80,6 +83,11 @@ void transDataToMotorValve(uint8_t *data, uint16_t len) HAL_GPIO_WritePin(DIR2_GPIO_Port, DIR2_Pin, GPIO_PIN_RESET); // HAL_Delay(100); } + +uint8_t readDataFromMotorValve(uint8_t *data, uint16_t len, uint32_t timeout) +{ + return HAL_UART_Receive(&huart2, data, len, timeout); +} /* USER CODE END PFP */ /* Private user code ---------------------------------------------------------*/ @@ -205,6 +213,16 @@ void SystemClock_Config(void) } /* USER CODE BEGIN 4 */ +// DMA 传输完成回调函数 +void HAL_DMA_XferCpltCallback(DMA_HandleTypeDef *hdma) +{ + if (hdma->Instance == DMA1_Channel4){ + // 在此处处理 DMA 发送完成的逻辑,例如切换 RS485 状态 + #ifdef HOST_USE_DMA + HAL_GPIO_WritePin(DIR1_GPIO_Port, DIR1_Pin, GPIO_PIN_RESET); + #endif + } +} /* USER CODE END 4 */ /**