| | |
| | | /******************************************************************************* |
| | | * File Name : DBG.c |
| | | * Description : |
| | | * Created on : 2018年7月23日 |
| | | * Author : 杜键 |
| | | * Created on : 2018��7��23�� |
| | | * Author : �ż� |
| | | *******************************************************************************/ |
| | | |
| | | /******************************************************************************* |
| | |
| | | * Input : |
| | | * Output : |
| | | * Return : |
| | | * Author : 杜键 |
| | | * Modified Date: : 2018年7月23日 |
| | | * Author : �ż� |
| | | * Modified Date: : 2018��7��23�� |
| | | *******************************************************************************/ |
| | | static HIDO_INT32 DBG_SerialGetChar(HIDO_UINT8 *_pu8Char) |
| | | { |
| | |
| | | * Input : |
| | | * Output : |
| | | * Return : |
| | | * Author : 杜键 |
| | | * Modified Date: : 2018年7月23日 |
| | | * Author : �ż� |
| | | * Modified Date: : 2018��7��23�� |
| | | *******************************************************************************/ |
| | | static HIDO_INT32 DBG_SerialPrintf(const HIDO_CHAR *_pcFmt, ...) |
| | | { |
| | |
| | | /******************************************************************************* |
| | | * Function Name : DBG_SerialPutString |
| | | * Description : |
| | | * Input : _pcString 输出字符串 |
| | | * Input : _pcString ����ַ��� |
| | | * Output : |
| | | * Return : HIDO_OK 成功 |
| | | * HIDO_ERR 失败 |
| | | * Author : 杜键 |
| | | * Modified Date: : 2018年7月23日 |
| | | * Return : HIDO_OK �ɹ� |
| | | * HIDO_ERR ʧ�� |
| | | * Author : �ż� |
| | | * Modified Date: : 2018��7��23�� |
| | | *******************************************************************************/ |
| | | static HIDO_INT32 DBG_SerialPutString(const char *_pcString) |
| | | { |
| | |
| | | |
| | | /******************************************************************************* |
| | | * Function Name : DBG_SerialPutChar |
| | | * Description : DBG输出一个字符 |
| | | * Input : _u8Char 输出字符 |
| | | * Description : DBG���һ���ַ� |
| | | * Input : _u8Char ����ַ� |
| | | * Output : |
| | | * Return : HIDO_OK 成功 |
| | | * HIDO_ERR 失败 |
| | | * Author : 杜键 |
| | | * Modified Date: : 2018年7月23日 |
| | | * Return : HIDO_OK �ɹ� |
| | | * HIDO_ERR ʧ�� |
| | | * Author : �ż� |
| | | * Modified Date: : 2018��7��23�� |
| | | *******************************************************************************/ |
| | | static HIDO_INT32 DBG_SerialPutChar(HIDO_UINT8 _u8Char) |
| | | { |
| | |
| | | * Input : |
| | | * Output : |
| | | * Return : |
| | | * Author : 杜键 |
| | | * Modified Date: : 2018年7月23日 |
| | | * Author : �ż� |
| | | * Modified Date: : 2018��7��23�� |
| | | *******************************************************************************/ |
| | | HIDO_INT32 HIDO_Debug(const HIDO_CHAR *_pcFmt, ...) |
| | | { |
| | |
| | | * Input : |
| | | * Output : |
| | | * Return : |
| | | * Author : 杜键 |
| | | * Modified Date: : 2018年7月23日 |
| | | * Author : �ż� |
| | | * Modified Date: : 2018��7��23�� |
| | | *******************************************************************************/ |
| | | HIDO_INT32 HIDO_DebugEx(const HIDO_CHAR *_pcFmt, ...) |
| | | { |
| | |
| | | HIDO_UINT32 u32Len = 0; |
| | | // ST_RTCDateTime stRTCDateTime; |
| | | |
| | | /* 输出日志格式 */ |
| | | /* �����־��ʽ */ |
| | | // RTC_GetDateTime(&stRTCDateTime); |
| | | // u32Len = HIDO_UtilSnprintf(acOutputBuf, sizeof(acOutputBuf), "%04u-%02u-%02u %02u:%02u:%02u.%03u ", |
| | | // stRTCDateTime.m_u16Year, stRTCDateTime.m_u8Month, stRTCDateTime.m_u8Day, stRTCDateTime.m_u8Hour, |
| | |
| | | return HIDO_OK; |
| | | } |
| | | |
| | | HIDO_INT32 DBG_Printf(const HIDO_CHAR *_pcFmt, ...) |
| | | { |
| | | va_list ap; |
| | | HIDO_CHAR acOutputBuf[OUTPUT_BUF_SIZE]; |
| | | HIDO_UINT32 u32Len = 0; |
| | | |
| | | va_start(ap, _pcFmt); |
| | | u32Len = vsnprintf(acOutputBuf, sizeof(acOutputBuf), _pcFmt, ap); |
| | | va_end(ap); |
| | | |
| | | if (u32Len > (sizeof(acOutputBuf) - 1)) |
| | | { |
| | | u32Len = sizeof(acOutputBuf) - 1; |
| | | } |
| | | |
| | | return Uart_Send(UART_ID_PYTHON, (HIDO_UINT8 *)acOutputBuf, u32Len); |
| | | } |
| | | |
| | | /******************************************************************************* |
| | | * Function Name : HIDO_DebugHex |
| | | * Description : |
| | | * Input : |
| | | * Output : |
| | | * Return : |
| | | * Author : 杜键 |
| | | * Modified Date: : 2018年7月23日 |
| | | * Author : �ż� |
| | | * Modified Date: : 2018��7��23�� |
| | | *******************************************************************************/ |
| | | HIDO_INT32 HIDO_DebugHex(const HIDO_UINT8 *_pu8Data, HIDO_UINT32 _u32Len) |
| | | { |
| | |
| | | * Input : |
| | | * Output : |
| | | * Return : |
| | | * Author : 杜键 |
| | | * Modified Date: : 2018年7月23日 |
| | | * Author : �ż� |
| | | * Modified Date: : 2018��7��23�� |
| | | *******************************************************************************/ |
| | | HIDO_INT32 HIDO_DebugString(const HIDO_CHAR *_pu8String, HIDO_UINT32 _u32StringLen) |
| | | { |
| | |
| | | HIDO_UINT32 u32Len = 0; |
| | | ST_RTCDateTime stRTCDateTime; |
| | | |
| | | /* 输出日志格式 */ |
| | | /* �����־��ʽ */ |
| | | RTC_GetDateTime(&stRTCDateTime); |
| | | u32Len = HIDO_UtilSnprintf(acOutputBuf, sizeof(acOutputBuf), "%04u-%02u-%02u %02u:%02u:%02u.%03u ", |
| | | stRTCDateTime.m_u16Year, stRTCDateTime.m_u8Month, stRTCDateTime.m_u8Day, stRTCDateTime.m_u8Hour, |
| | |
| | | * Input : |
| | | * Output : |
| | | * Return : |
| | | * Author : 杜键 |
| | | * Modified Date: : 2018年7月23日 |
| | | * Author : �ż� |
| | | * Modified Date: : 2018��7��23�� |
| | | *******************************************************************************/ |
| | | HIDO_VOID DBG_SetDebugFlag(HIDO_UINT8 _u8Flag) |
| | | { |
| | |
| | | * Input : |
| | | * Output : |
| | | * Return : |
| | | * Author : 杜键 |
| | | * Modified Date: : 2018年7月23日 |
| | | * Author : �ż� |
| | | * Modified Date: : 2018��7��23�� |
| | | *******************************************************************************/ |
| | | HIDO_INT32 DBG_SetMode(E_DBGMode _eMode) |
| | | { |
| | |
| | | * Input : |
| | | * Output : |
| | | * Return : |
| | | * Author : 杜键 |
| | | * Modified Date: : 2018年7月23日 |
| | | * Author : �ż� |
| | | * Modified Date: : 2018��7��23�� |
| | | *******************************************************************************/ |
| | | E_DBGMode DBG_GetMode(void) |
| | | { |
| | |
| | | |
| | | #ifdef __APP_CODE__ |
| | | |
| | | // 组包参数 |
| | | // ������� |
| | | #define MAX_PACKET_SIZE 1000 |
| | | #define TIMEOUT_MS 100 |
| | | |
| | |
| | | |
| | | static uart_packet_t g_uart_packet = {0}; |
| | | |
| | | //// 初始化组包结构 |
| | | //// ��ʼ������ṹ |
| | | //void uart_packet_init(void) |
| | | //{ |
| | | // memset(&g_uart_packet, 0, sizeof(g_uart_packet)); |
| | |
| | | // lora_uart_receiver_init(); |
| | | //} |
| | | |
| | | // 检查超时并处理完整数据包 |
| | | // ��鳬ʱ�������������ݰ� |
| | | void check_timeout_and_process(void) |
| | | { |
| | | uint32_t current_time = HIDO_TimerGetTick(); |
| | | |
| | | // 检查是否超时且缓冲区有数据 |
| | | // ����Ƿ�ʱ�һ����������� |
| | | if ((g_uart_packet.length > 0) && |
| | | ((current_time - g_uart_packet.last_receive_time) >= TIMEOUT_MS)) |
| | | { |
| | | |
| | | // 标记数据包就绪 |
| | | // ������ݰ����� |
| | | g_uart_packet.packet_ready = 1; |
| | | |
| | | // 这里可以调用处理函数,比如: |
| | | // ������Ե��ô������������磺 |
| | | // process_uart_packet(g_uart_packet.buffer, g_uart_packet.length); |
| | | |
| | | UDPClient_Uploadhex(g_uart_packet.buffer, g_uart_packet.length); |
| | | // 重置缓冲区,准备接收下一个数据包 |
| | | // ���û���������������һ�����ݰ� |
| | | g_uart_packet.length = 0; |
| | | } |
| | | } |
| | | |
| | | //// 主循环中的串口数据处理函数 |
| | | //// ��ѭ���еĴ������ݴ������� |
| | | // void uart_data_handler(void) |
| | | //{ |
| | | // uint8_t u8RecvChar; |
| | | // |
| | | // // 检查超时 |
| | | // // ��鳬ʱ |
| | | // check_timeout_and_process(); |
| | | // |
| | | // // 轮询读取串口数据 |
| | | // // ��ѯ��ȡ�������� |
| | | // while (Uart_GetChar(UART_ID_DBG, &u8RecvChar) == HIDO_OK) { |
| | | // // 更新最后接收时间 |
| | | // // ����������ʱ�� |
| | | // g_uart_packet.last_receive_time = HIDO_TimerGetTick(); |
| | | // |
| | | // // 检查缓冲区是否已满 |
| | | // // ��黺�����Ƿ����� |
| | | // if (g_uart_packet.length < MAX_PACKET_SIZE) { |
| | | // // 存储接收到的字符 |
| | | // // �洢���յ����ַ� |
| | | // g_uart_packet.buffer[g_uart_packet.length++] = u8RecvChar; |
| | | // |
| | | // } else { |
| | | // // 缓冲区溢出处理 |
| | | // // ������������� |
| | | // printf("Buffer overflow!\n"); |
| | | // g_uart_packet.length = 0; // 清空缓冲区 |
| | | // g_uart_packet.length = 0; // ��ջ����� |
| | | // } |
| | | // } |
| | | // } |
| | |
| | | uint8_t chargedbg_flag; |
| | | HIDO_VOID DBG_Poll(void) |
| | | { |
| | | // 有5V输入的时候,默认是给调试口 |
| | | // ��5V�����ʱ��Ĭ���Ǹ����Կ� |
| | | if (DBG_GetMode() == DBG_MODE_SHELL) |
| | | { |
| | | HIDO_InputPoll(); |
| | |
| | | { |
| | | g_uart_packet.last_receive_time = HIDO_TimerGetTick(); |
| | | |
| | | // 检查缓冲区是否已满 |
| | | // ��黺�����Ƿ����� |
| | | if (g_uart_packet.length < MAX_PACKET_SIZE) |
| | | { |
| | | // 存储接收到的字符 |
| | | // �洢���յ����ַ� |
| | | g_uart_packet.buffer[g_uart_packet.length++] = u8RecvChar; |
| | | } |
| | | else |
| | | { |
| | | // 缓冲区溢出处理 |
| | | // ������������� |
| | | printf("Buffer overflow!\n"); |
| | | g_uart_packet.length = 0; // 清空缓冲区 |
| | | g_uart_packet.length = 0; // ��ջ����� |
| | | } |
| | | } |
| | | // HAL_UART_Transmit(pstUartHandle, &u8RecvChar, 1, 1000); |
| | |
| | | |
| | | /******************************************************************************* |
| | | * Function Name : DBG_Init |
| | | * Description : 调试打印初始化 |
| | | * Description : ���Դ�ӡ��ʼ�� |
| | | * Input : None |
| | | * Output : None |
| | | * Return : None |
| | | * Author : 杜键 |
| | | * Modified Date: : 2018年7月23日 |
| | | * Author : �ż� |
| | | * Modified Date: : 2018��7��23�� |
| | | *******************************************************************************/ |
| | | HIDO_VOID DBG_Init(void) |
| | | { |