// #include #include #include "FreeRTOS.h" #include "task.h" #include "hart.h" #include "gpio.h" #include "apps_gather.h" void hart_send(UART_HandleTypeDef *huart, uint8_t *data) { usart_printf(huart, (char *)data); } void parse_scom_hart(st_scom *scom) { if (scom == &scom1_hart) { scom->rx_flag = FALSE; if ((scom->rx_buff[0] == 0xff) && (scom->rx_buff[1] == 0xff) && (scom->rx_buff[scom->rx_len - 1] == 0xAA)) { ; } scom->tx_flag = TRUE; scom->rx_len = 0; } } void hart_communicate(st_scom *scom) { uint8_t hart_data_test[18] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0xaa}; HART_RTS(RTS_OFF); if (scom->rx_flag == TRUE) { scom->rx_flag = FALSE; parse_scom_hart(scom); } // scom->tx_flag = TRUE; if (scom->tx_flag == TRUE) { scom->tx_flag = FALSE; HART_RTS(RTS_ON); vTaskDelay(15); memcpy(scom->tx_buff, hart_data_test, sizeof(hart_data_test)); hart_send(&huart1, scom->tx_buff); HART_RTS(RTS_OFF); } } //DEVICE <---SIG---> PC //将来自设备的HART数据装载至com485_tx,将comhart_tx的HART数据发送至设备 // void transparent_hart(st_scom *scom) // { // if (scom != &scom1_hart) return; // HART_RTS(RTS_OFF); // //来自HART设备的数据是否接收完成 // if (scom->rx_flag == TRUE) // { // scom->rx_flag = FALSE; // //接收到的数据是否符合HART数据报,符合则写入485的tx,准备发送至上位机 // if ((scom->rx_buff[0] == 0xff) && (scom->rx_buff[1] == 0xff) && (scom->rx_buff[scom->rx_len - 1] == 0xAA)) // { // //SIG -> PC // memcpy(scom2_rs485.tx_buff, scom->rx_buff, sizeof(scom->rx_buff)); // scom2_rs485.tx_len = scom->rx_len; // scom2_rs485.tx_flag = TRUE; // } // //清空缓存区,等待新的数据 // memset(scom->rx_buff, 0, sizeof(scom->rx_buff)); // scom->rx_len = 0; // } // //来自上位机的数据是否准备完毕 // if (scom->tx_flag == TRUE) // { // scom->tx_flag = FALSE; // HART_RTS(RTS_ON); // vTaskDelay(15); // //将tx中的数据发送至HART设备 // hart_send(&huart1, scom->tx_buff); // HART_RTS(RTS_OFF); // //清空缓存区,等待新的数据 // memset(scom->tx_buff, 0, sizeof(scom->tx_buff)); // scom->tx_len = 0; // xTaskResumeFromISR(task_lcdHandle); // xTaskResumeFromISR(task_menuHandle); // screen_suspend_flag = 0; // } // }