/* ********************************************************************************************************* * 函 数 名: gps_pro * 功能说明: 轮询GPS数据包。插入到主程序中执行即可。分析结果存放在全局变量 g_tGPS * 形 参: 无 * 返 回 值: 无 ********************************************************************************************************* */ void gps_pro(void) { uint8_t ucData; static uint8_t ucGpsHead = 0; static uint8_t ucaGpsBuf[512]; static uint16_t usGpsPos = 0; /* 从 GPS模块串口读取1个字节 comGetChar() 函数由 bsp_uart_fifo.c 实现 */ while (1) { if (comGetChar(COM2, &ucData)) { #ifdef DEBUG_GPS_TO_COM1 /* 将收到的GPS模块数据按原样 打印到COM1 口,便于跟踪调试 */ comSendChar(COM1, ucData); #endif if (ucGpsHead == 0) { if (ucData == '$') { ucGpsHead = 1; usGpsPos = 0; } } else { if (usGpsPos < sizeof(ucaGpsBuf)) { ucaGpsBuf[usGpsPos++] = ucData; if ((ucData == '\r') || (ucData == '\n')) { Analyze0183(ucaGpsBuf, usGpsPos-1); ucGpsHead = 0; g_tGPS.UartOk = 1; /* 接收到正确的命令 */ } } else { ucGpsHead = 0; } } continue; /* 可能还有数据,继续分析 */ } break; /* 分析完毕,退出函数 */ } }
/* ********************************************************************************************************* * 函 数 名: fputc * 功能说明: 重定义putc函数,这样可以使用printf函数从串口1打印输出 * 形 参: 无 * 返 回 值: 无 ********************************************************************************************************* */ int fputc(int ch, FILE *f) { #if 0 /* 将需要printf的字符通过串口中断FIFO发送出去,printf函数会立即返回 */ comSendChar(COM1, ch); return ch; #else /* 采用阻塞方式发送每个字符,等待数据发送完毕 */ /* 写一个字节到USART1 */ USART_SendData(USART1, (uint8_t) ch); /* 等待发送结束 */ while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET) {} return ch; #endif }
int uartPutchar(int ch) { comSendChar(UART_DEBUG_COM, ch); return (unsigned char)ch; }
/* ********************************************************************************************************* * 函 数 名: SIM800_PrintRxData * 功能说明: 打印STM32从SIM800收到的数据到COM1串口,主要用于跟踪调试 * 形 参: _ch : 收到的数据 * 返 回 值: 无 ********************************************************************************************************* */ void SIM800_PrintRxData(uint8_t _ch) { #ifdef SIM800_TO_COM1_EN comSendChar(COM1, _ch); /* 将接收到数据打印到调试串口1 */ #endif }
/* ********************************************************************************************************* * 函 数 名: MG323_PrintRxData * 功能说明: 打印STM32从MG323收到的数据到COM1串口,主要用于跟踪调试 * 形 参: _ch : 收到的数据 * 返 回 值: 无 ********************************************************************************************************* */ void MG323_PrintRxData(uint8_t _ch) { #ifdef MG323_TO_COM1_EN comSendChar(COM1, _ch); /* 将接收到数据打印到调试串口1 */ #endif }