STM32H743/APL/MQTTClient.c
@@ -26,6 +26,7 @@
#include "AppConfig.h"
#include "global_param.h"
#include "MQTTApp.h"
#include "PathStorage.h"
/*******************************************************************************
 *                                  Macro                                      *
@@ -210,7 +211,7 @@
/*******************************************************************************
 * Function Name     : MQTTClient_ReportStatus
 * Description       : ���ݰ�����
 * Description       : ���ݰ��ϱ�
 * Input             : _pstPackage                    ���ݰ�
 * Output            : None
 * Return            : HIDO_OK                        �ɹ�
@@ -239,7 +240,7 @@
/*******************************************************************************
 * Function Name     : MQTTClient_ReportResponse
 * Description       : ���ݰ�����
 * Description       : ���ݰ��ϱ�
 * Input             : _pstPackage                    ���ݰ�
 * Output            : None
 * Return            : HIDO_OK                        �ɹ�
@@ -281,13 +282,12 @@
    
    //TODO MsgPack_Parse
    
    return HIDO_OK;
}
/*******************************************************************************
 * Function Name     : MQTTClient_MQTTEventProc
 * Description       : ���ӷ�����
 * Description       : ���ӷ������¼�����
 * Input             : None
 * Output            : None
 * Return            : None
@@ -348,7 +348,7 @@
            while (MQTT_Recv(l_i32MQTTClientID, l_acRecvTopic, l_au8RecvBuf, sizeof(l_au8RecvBuf), &u32RecvLen) == HIDO_OK)
            {
                // 调用MQTTApp层解析消息
            // ����MQTTApp�������Ϣ
                MQTTApp_ParseMessage(l_acRecvTopic, l_au8RecvBuf, u32RecvLen);
            }
            break;
@@ -365,7 +365,7 @@
 *******************************************************************************/
/*******************************************************************************
 * Function Name     : MQTTClient_IsNetWorkReady
 * Description       : ��������Ƿ�׼����
 * Description       : ��������Ƿ�׼������
 * Input             : None
 * Output            : None
 * Return            : None
@@ -382,7 +382,7 @@
/*******************************************************************************
 * Function Name     : MQTTClient_IsConnected
 * Description       : ����Ƿ�Ҳ����������׼����
 * Description       : ����Ƿ�Ҳ�������粢׼������
 * Input             : None
 * Output            : None
 * Return            : HIDO_TRUE                      ��
@@ -429,7 +429,7 @@
                break;
            }
            /* �������ʱ�䵽 */
        /* ����ʱ�䵽 */
            if ((u32CurTick - l_u32MQTTConnectTick) >= HIDO_TIMER_TICK_S(5))
            {
                HIDO_DebugEx("Reconnect Server\r\n");
@@ -447,7 +447,6 @@
            ST_MQTTMessage *pstMQTTMessage = HIDO_NULL;
            HIDO_VLQMemberStruct *pstMember = HIDO_NULL;
            
            /* �����ڴ���� */
            while((pstMember = HIDO_VLQGetDequeueMember(&l_stMQTTClientQueue)) != HIDO_NULL)
            {
@@ -757,3 +756,95 @@
    return HIDO_OK;
}
/*******************************************************************************
 * Function Name     : MQTTClient_TestPathDownload
 * Description       : 测试路径文件下载功能
 * Input             : None
 * Output            : None
 * Return            : HIDO_OK                        成功
 *                     HIDO_ERR                       失败
 *******************************************************************************/
HIDO_INT32 MQTTClient_TestPathDownload(void)
{
    HIDO_INT32 ret;
    const HIDO_CHAR *url = "http://39.99.43.227:8866/api/file/download/21b09df9-9232-4e38-a5cc-19458d324019_data.bin";
    HIDO_Debug("[MQTTClient] Start path download test\r\n");
    // 启动下载
    ret = PathStorage_DownloadFromHTTP(url);
    if (ret != 0) {
        HIDO_Debug("[MQTTClient] PathStorage_DownloadFromHTTP failed: %d\r\n", ret);
        return HIDO_ERR;
    }
    HIDO_Debug("[MQTTClient] Download started, check status later\r\n");
    return HIDO_OK;
}
/*******************************************************************************
 * Function Name     : MQTTClient_CheckPathStatus
 * Description       : 检查路径下载和存储状态
 * Input             : None
 * Output            : None
 * Return            : None
 *******************************************************************************/
void MQTTClient_CheckPathStatus(void)
{
    E_PathStorageStatus status = PathStorage_GetStatus();
    HIDO_UINT8 progress = PathStorage_GetProgress();
    HIDO_Debug("[MQTTClient] Path Storage Status: %d, Progress: %u%%\r\n",
               status, progress);
    if (status == PATH_STORAGE_STATUS_SUCCESS) {
        // 下载成功,读取并验证数据
        MowerPathHeader_t header;
        HIDO_INT32 ret = PathStorage_ReadHeader(&header);
        if (ret == 0) {
            HIDO_Debug("[MQTTClient] === Path File Info ===\r\n");
            HIDO_Debug("  SOF: 0x%04X\r\n", header.sof);
            HIDO_Debug("  Type: 0x%02X\r\n", header.type);
            HIDO_Debug("  Version: 0x%02X\r\n", header.version);
            HIDO_Debug("  Path ID: 0x%08X\r\n", header.path_id);
            HIDO_Debug("  Timestamp: %u\r\n", header.timestamp);
            HIDO_Debug("  Origin: (%.8f, %.8f, %.2f)\r\n",
                       header.origin_lon, header.origin_lat, header.origin_alt);
            HIDO_Debug("  Boundary Count: %u\r\n", header.boundary_count);
            HIDO_Debug("  Path Count: %u\r\n", header.path_count);
            // 读取前几个点作为示例
            if (header.boundary_count > 0) {
                PathPoint_t point;
                ret = PathStorage_ReadPoint(HIDO_TRUE, 0, &point);
                if (ret == 0) {
                    HIDO_Debug("  First Boundary Point: (%.3f, %.3f)\r\n",
                               point.x, point.y);
                }
            }
            if (header.path_count > 0) {
                PathPoint_t point;
                ret = PathStorage_ReadPoint(HIDO_FALSE, 0, &point);
                if (ret == 0) {
                    HIDO_Debug("  First Path Point: (%.3f, %.3f)\r\n",
                               point.x, point.y);
                }
            }
            HIDO_Debug("[MQTTClient] === Path File Valid ===\r\n");
        } else {
            HIDO_Debug("[MQTTClient] Read header failed: %d\r\n", ret);
        }
    } else if (status == PATH_STORAGE_STATUS_FAIL_NETWORK) {
        HIDO_Debug("[MQTTClient] Download failed: Network error\r\n");
    } else if (status == PATH_STORAGE_STATUS_FAIL_FLASH) {
        HIDO_Debug("[MQTTClient] Download failed: Flash error\r\n");
    } else if (status == PATH_STORAGE_STATUS_FAIL_CRC) {
        HIDO_Debug("[MQTTClient] Download failed: CRC error\r\n");
    } else if (status == PATH_STORAGE_STATUS_FAIL_FORMAT) {
        HIDO_Debug("[MQTTClient] Download failed: Format error\r\n");
    }
}