From 4780a46e8a5f43fc433cb240be339114b483bca8 Mon Sep 17 00:00:00 2001 From: Fancy code <258828110.@qq.com> Date: Mon, 25 Mar 2024 14:46:29 +0800 Subject: [PATCH] Improve:SixFrame protocol. --- application/MissionManager/src/AppMonitor.cpp | 2 +- .../src/Protocol/SixFrame/SixFrameHandle.cpp | 67 ++++++++++++++++--- .../src/Protocol/SixFrame/SixFrameHandle.h | 3 +- .../src/Protocol/SixFrame/SixFrameMakePtr.cpp | 14 ++++ 4 files changed, 73 insertions(+), 13 deletions(-) diff --git a/application/MissionManager/src/AppMonitor.cpp b/application/MissionManager/src/AppMonitor.cpp index 8771a11..ad7f424 100644 --- a/application/MissionManager/src/AppMonitor.cpp +++ b/application/MissionManager/src/AppMonitor.cpp @@ -91,7 +91,7 @@ StatusCode AppMonitor::GetStorageFileList(const AppGetFileInfo &fileInfo, std::v AppGetFileList file; file.mCreateTime_s = 123456789; file.mDuration = 15; - file.mName = "/video/test.mp4"; + file.mName = "/DCIM/2024/01/15/20240115135444-20240115135504.mp4"; file.mSize = 1024; file.mType = StorageFileType::VIDEO; param.push_back(file); diff --git a/middleware/AppManager/src/Protocol/SixFrame/SixFrameHandle.cpp b/middleware/AppManager/src/Protocol/SixFrame/SixFrameHandle.cpp index e2dd5d2..997df0b 100644 --- a/middleware/AppManager/src/Protocol/SixFrame/SixFrameHandle.cpp +++ b/middleware/AppManager/src/Protocol/SixFrame/SixFrameHandle.cpp @@ -22,6 +22,7 @@ using std::placeholders::_3; // using std::placeholders::_4; // clang-format off const char *CJSON_INFO_STRING = "info"; +const char *CJSON_FILES_STRING = "files"; const char *APP_GET_PRODUCT_INFO = "/app/getproductinfo"; const char *APP_GET_DEVICE_ATTR = "/app/getdeviceattr"; const char *APP_GET_MEDIA_INFO = "/app/getmediainfo"; @@ -38,6 +39,8 @@ const char *APP_SET_PARAM_VALUE = "/app/setparamvalue"; const char *APP_ENTER_RECORDER = "/app/enterrecorder"; const char *APP_PLAYBACK = "/app/playback"; const char *APP_UPLOAD_FILE = "/upload"; +// /app/getparamvalue?param=rec +// /app/exitrecorder // clang-format on constexpr bool SET_REQUEST_RESPONSE = true; SixFrameHandle::SixFrameHandle() @@ -371,7 +374,7 @@ AppGetFileInfo inline SixFrameHandle::RequestGetFileListParse(const std::string std::dynamic_pointer_cast>(parse); if ("folder" == key) { if ("loop" == value) { - parseyImpl->mData.mEvent = StorageFileEvent::END; + parseyImpl->mData.mEvent = StorageFileEvent::LOOP; } if ("emr" == value) { parseyImpl->mData.mEvent = StorageFileEvent::END; @@ -407,30 +410,57 @@ void SixFrameHandle::RequestGetFileList(const std::string &url, ResponseHandle r responseHandle("Device run out of memory.", context); return; } - ResponseGetFileList(result, param); + ResponseGetFileList(result, param, info); ResponseJsonString(result, responseHandle, context); cJSON_Delete(result); } -void inline SixFrameHandle::ResponseGetFileList(cJSON *result, const std::vector ¶m) +/** + * @brief +{ + "result": 0, + "info": [{ + "folder": "loop", + "count": 1, + "files": [{ + "name": "/DCIM/2024/01/15/20240115135444-20240115135504.mp4", + "duration": 15, + "size": 1024, + "createtime": 123456789, + "type": 0 + }] + }] +} + * @param result + * @param param + * @param fileInfo + */ +void inline SixFrameHandle::ResponseGetFileList(cJSON *result, const std::vector ¶m, + const AppGetFileInfo &fileInfo) { cJSON *info = cJSON_CreateArray(); - if (nullptr == info) { + cJSON *folder = cJSON_CreateObject(); + cJSON *files = cJSON_CreateArray(); + if (nullptr == info || nullptr == folder || nullptr == files) { LogError("cJSON_CreateArray failed.\n"); return; } cJSON_AddItemToObject(result, CJSON_INFO_STRING, info); - for (const auto &fileInfo : param) { + cJSON_AddItemToArray(info, folder); + for (const auto &fileList : param) { + cJSON_AddStringToObject(folder, "folder", PrintfFileEvent(fileInfo)); + cJSON_AddNumberToObject(folder, "count", param.size()); cJSON *file = nullptr; file = cJSON_CreateObject(); if (nullptr != file) { - cJSON_AddItemToArray(info, file); - cJSON_AddStringToObject(file, "name", fileInfo.mName.c_str()); - cJSON_AddNumberToObject(file, "duration", fileInfo.mDuration); - cJSON_AddNumberToObject(file, "size", fileInfo.mSize); - cJSON_AddNumberToObject(file, "createtime", fileInfo.mCreateTime_s); - cJSON_AddNumberToObject(file, "type", static_cast(fileInfo.mType)); + cJSON_AddItemToArray(files, file); + cJSON_AddStringToObject(file, "name", fileList.mName.c_str()); + cJSON_AddNumberToObject(file, "duration", fileList.mDuration); + cJSON_AddNumberToObject(file, "size", fileList.mSize); + cJSON_AddNumberToObject(file, "createtime", fileList.mCreateTime_s); + cJSON_AddNumberToObject(file, "type", static_cast(fileList.mType)); } } + cJSON_AddItemToObject(folder, CJSON_FILES_STRING, files); } AppSetDateTime inline SixFrameHandle::RequestSetDateTimeParse(const std::string &url) { @@ -640,6 +670,21 @@ void SixFrameHandle::ResponseJsonString(cJSON *json, ResponseHandle responseHand responseHandle("Device run out of memory.", context); } } +const char *SixFrameHandle::PrintfFileEvent(const AppGetFileInfo &fileInfo) +{ + switch (fileInfo.mEvent) { + case StorageFileEvent::LOOP: { + return "loop"; + break; + } + + default: { + LogWarning("Unknown event.\n"); + break; + } + } + return "unknown event"; +} void SixFrameHandle::SetAppMonitor(std::shared_ptr &monitor) { if (monitor) { diff --git a/middleware/AppManager/src/Protocol/SixFrame/SixFrameHandle.h b/middleware/AppManager/src/Protocol/SixFrame/SixFrameHandle.h index 914a5ec..014fa39 100644 --- a/middleware/AppManager/src/Protocol/SixFrame/SixFrameHandle.h +++ b/middleware/AppManager/src/Protocol/SixFrame/SixFrameHandle.h @@ -78,7 +78,7 @@ private: void ResponseGetStorageInfo(cJSON *result, const std::vector ¶m); AppGetFileInfo RequestGetFileListParse(const std::string &url); void RequestGetFileList(const std::string &url, ResponseHandle responseHandle, void *context); - void ResponseGetFileList(cJSON *result, const std::vector ¶m); + void ResponseGetFileList(cJSON *result, const std::vector ¶m, const AppGetFileInfo &fileInfo); AppSetDateTime RequestSetDateTimeParse(const std::string &url); void RequestSetDateTime(const std::string &url, ResponseHandle responseHandle, void *context); int RequestSetTimeZoneParse(const std::string &url); @@ -93,6 +93,7 @@ private: private: cJSON *MakeResponseResult(const ResposeResult result, const bool requestSet = false); void ResponseJsonString(cJSON *json, ResponseHandle responseHandle, void *context); + const char *PrintfFileEvent(const AppGetFileInfo &fileInfo); protected: void SetAppMonitor(std::shared_ptr &monitor) override; diff --git a/middleware/AppManager/src/Protocol/SixFrame/SixFrameMakePtr.cpp b/middleware/AppManager/src/Protocol/SixFrame/SixFrameMakePtr.cpp index 2149cef..b64e824 100644 --- a/middleware/AppManager/src/Protocol/SixFrame/SixFrameMakePtr.cpp +++ b/middleware/AppManager/src/Protocol/SixFrame/SixFrameMakePtr.cpp @@ -1,3 +1,17 @@ +/* + * Copyright (c) 2023 Fancy Code. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #include "SixFrameMakePtr.h" #include "ILog.h" #include "SixFrameHandle.h"