yincheng.zhong
7 天以前 b53fff11e6f0d560594834de32886239cbba90a3
STM32H743/FML/DBG.c
@@ -1,8 +1,8 @@
/*******************************************************************************
 * File Name         : DBG.c
 * Description       :
 * Created on        : 2018年7月23日
 * Author            : 杜键
 * Created on        : 2018��7��23��
 * Author            : �ż�
 *******************************************************************************/
/*******************************************************************************
@@ -36,7 +36,7 @@
static HIDO_UINT8 l_au8DBGUartTxBuf[DBG_UART_TX_BUF_SIZE];
static HIDO_UINT8 l_u8DBGFlag = DBG_FLAG_ON;
static E_DBGMode l_eDBGMode = DBG_MODE_CHARGE;
static E_DBGMode l_eDBGMode = DBG_MODE_SHELL;
/*******************************************************************************
 *                        Local Function Declaration                           *
 *******************************************************************************/
@@ -53,8 +53,8 @@
 * Input             :
 * Output            :
 * Return            :
 * Author            : 杜键
 * Modified Date:    : 2018年7月23日
 * Author            : �ż�
 * Modified Date:    : 2018��7��23��
 *******************************************************************************/
static HIDO_INT32 DBG_SerialGetChar(HIDO_UINT8 *_pu8Char)
{
@@ -67,8 +67,8 @@
 * Input             :
 * Output            :
 * Return            :
 * Author            : 杜键
 * Modified Date:    : 2018年7月23日
 * Author            : �ż�
 * Modified Date:    : 2018��7��23��
 *******************************************************************************/
static HIDO_INT32 DBG_SerialPrintf(const HIDO_CHAR *_pcFmt, ...)
{
@@ -85,12 +85,12 @@
/*******************************************************************************
 * 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)
{
@@ -103,13 +103,13 @@
/*******************************************************************************
 * 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)
{
@@ -129,8 +129,8 @@
 * Input             :
 * Output            :
 * Return            :
 * Author            : 杜键
 * Modified Date:    : 2018年7月23日
 * Author            : �ż�
 * Modified Date:    : 2018��7��23��
 *******************************************************************************/
HIDO_INT32 HIDO_Debug(const HIDO_CHAR *_pcFmt, ...)
{
@@ -176,7 +176,7 @@
        u32Len = sizeof(acOutputBuf) - 1;
    }
    Uart_Send(UART_ID_DBG, (HIDO_UINT8 *)acOutputBuf, u32Len);
    Uart_Send(UART_ID_PYTHON, (HIDO_UINT8 *)acOutputBuf, u32Len);
    return HIDO_OK;
}
@@ -187,8 +187,8 @@
 * Input             :
 * Output            :
 * Return            :
 * Author            : 杜键
 * Modified Date:    : 2018年7月23日
 * Author            : �ż�
 * Modified Date:    : 2018��7��23��
 *******************************************************************************/
HIDO_INT32 HIDO_DebugEx(const HIDO_CHAR *_pcFmt, ...)
{
@@ -202,7 +202,7 @@
    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,
@@ -224,14 +224,32 @@
    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_DBG, (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)
{
@@ -277,8 +295,8 @@
 * 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)
{
@@ -292,7 +310,7 @@
    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,
@@ -309,8 +327,8 @@
 * Input             :
 * Output            :
 * Return            :
 * Author            : 杜键
 * Modified Date:    : 2018年7月23日
 * Author            : �ż�
 * Modified Date:    : 2018��7��23��
 *******************************************************************************/
HIDO_VOID DBG_SetDebugFlag(HIDO_UINT8 _u8Flag)
{
@@ -323,8 +341,8 @@
 * Input             :
 * Output            :
 * Return            :
 * Author            : 杜键
 * Modified Date:    : 2018年7月23日
 * Author            : �ż�
 * Modified Date:    : 2018��7��23��
 *******************************************************************************/
HIDO_INT32 DBG_SetMode(E_DBGMode _eMode)
{
@@ -339,8 +357,8 @@
 * Input             :
 * Output            :
 * Return            :
 * Author            : 杜键
 * Modified Date:    : 2018年7月23日
 * Author            : �ż�
 * Modified Date:    : 2018��7��23��
 *******************************************************************************/
E_DBGMode DBG_GetMode(void)
{
@@ -349,7 +367,7 @@
#ifdef __APP_CODE__
// 组包参数
// �������
#define MAX_PACKET_SIZE 1000
#define TIMEOUT_MS 100
@@ -363,7 +381,7 @@
static uart_packet_t g_uart_packet = {0};
//// 初始化组包结构
//// ��ʼ������ṹ
//void uart_packet_init(void)
//{
//    memset(&g_uart_packet, 0, sizeof(g_uart_packet));
@@ -371,50 +389,50 @@
//    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; // ��ջ�����
//         }
//     }
// }
@@ -423,7 +441,7 @@
uint8_t chargedbg_flag;
HIDO_VOID DBG_Poll(void)
{
    // 有5V输入的时候,默认是给调试口
    // ��5V�����ʱ��Ĭ���Ǹ����Կ�
    if (DBG_GetMode() == DBG_MODE_SHELL)
    {
        HIDO_InputPoll();
@@ -539,17 +557,17 @@
            {
                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);
@@ -560,12 +578,12 @@
/*******************************************************************************
 * 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)
{