update transDataToHost

This commit is contained in:
CSSC-WORK\murmur 2024-12-26 14:36:38 +08:00
parent df9e7376e6
commit e4a2ccf228
4 changed files with 26 additions and 5 deletions

View File

@ -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;

View File

@ -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 */

View File

@ -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,

View File

@ -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 */
/**