/** * @Author: 李建 * @Date: 2023/12/20 12:43:30 * @LastEditors: 李建 * @LastEditTime: 2023/12/20 12:43:30 * Description: 云平台接入框架 * Copyright: Copyright (©)}) 2023 YXLJ@2024. All rights reserved. */ #include "framework.h" #include "esp_log.h" #include "esp_system.h" #include "channel.h" #include "sub_device/command.h" #include #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include #include "gateway/gateway.h" static const char *TAG = "FRAMEWORK"; TaskHandle_t access_task_handle; bool is_framework_init = false; /** * 处理云端状态消息 */ static void status_message_process(char *payload) { } // 处理云端事件消息 static void event_message_process(char *payload) { } // 处理云端指令消息 static void command_message_process(char *payload) { cJSON *root = cJSON_Parse(payload); cJSON *cmd = cJSON_GetObjectItemCaseSensitive(root, "cmd"); cJSON *params = cJSON_GetObjectItem(root, "params"); if (!root || !cmd || !params) return; sparrow_command *spCmd = find_sparrow_command(cmd->valuestring); if (NULL != spCmd) { spCmd->unpack(cJSON_PrintUnformatted(params)); } else { ESP_LOGI(TAG, "%s is not found!", cmd->valuestring); } cJSON_Delete(root); } // 处理收到的云平台的消息包 void sub_device_recv_callback(char *payload, sparrow_topic_type topicType) { if (NULL == payload) { return; } switch (topicType) { case SPARROW_TOPIC_STATUS: status_message_process(payload); break; case SPARROW_TOPIC_COMMAND: command_message_process(payload); break; case SPARROW_TOPIC_EVENT: event_message_process(payload); break; default: break; } } void yxlj_framework_deinit() { //vEventGroupDelete(frame_work_event_group); if(access_task_handle != 0) { vTaskDelete(access_task_handle); } } void yxlj_framework_init() { ESP_LOGI(TAG, "Init..."); ESP_LOGI(TAG, "Free memory: %"PRIu32" bytes", esp_get_free_heap_size()); ESP_LOGI(TAG, "IDF version: %s", esp_get_idf_version()); vTaskDelay(3000 / portTICK_PERIOD_MS); // 增加延迟注册 防止初始化过快 yxlj_gateway_init(); if (!is_framework_init) { register_sub_device_channel_recv(SPARROW_CHANNEL_PORT_1, sub_device_recv_callback); is_framework_init = true; } }