36 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			36 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| // #include "device/pc.h"
 | |
| // #include "usart.h" // 包含 USART 驱动头文件
 | |
| // #include <string.h> // 用于 memcpy
 | |
| 
 | |
| // /* Private variables --------------------------------------------------------- */
 | |
| 
 | |
| // /* Exported functions -------------------------------------------------------- */
 | |
| 
 | |
| // /**
 | |
| //  * @brief 初始化PC通信
 | |
| //  */
 | |
| // void PC_Init(void) {
 | |
| //     // MX_USART1_UART_Init(); // 初始化 USART1
 | |
| //     pc_data.PC_online = false; // 默认PC离线
 | |
| // }
 | |
| 
 | |
| // /**
 | |
| //  * @brief 通过串口发送数据
 | |
| //  * @param data 要发送的16位数据
 | |
| //  */
 | |
| // void PC_SendData(void) {
 | |
| //     // 将 pc_data.to_pc 数据通过串口发送
 | |
| //     HAL_UART_Transmit(&huart1, (uint8_t *)&pc_data.to_pc, sizeof(PC_UpPackage_t), HAL_MAX_DELAY);
 | |
| // }
 | |
| 
 | |
| // /**
 | |
| //  * @brief 接收串口数据
 | |
| //  * @param data 接收缓冲区
 | |
| //  * @param length 接收数据长度
 | |
| //  */
 | |
| // void PC_ReceiveData(uint8_t *data, uint16_t length) {
 | |
| //     if (length == sizeof(PC_DownPackage_t)) {
 | |
| //         memcpy(&pc_data.from_pc, data, length); // 将接收到的数据存储到 pc_data.from_pc
 | |
| //         pc_data.PC_online = true; // 标记PC在线
 | |
| //     }
 | |
| // }
 | 
