From 8a66f07266eb64f03f428d40c05af8fe3e1f5e23 Mon Sep 17 00:00:00 2001
From: Fancy code <258828110.@qq.com>
Date: Sat, 24 Feb 2024 00:29:16 -0800
Subject: [PATCH] Add:MediaManager module.
---
doc/design.md | 4 +-
middleware/CMakeLists.txt | 3 +-
middleware/McuManager/CMakeLists.txt | 3 -
.../McuManager/src/McuManagerMakePtr.cpp | 8 ++-
middleware/McuManager/src/McuManagerMakePtr.h | 4 +-
middleware/MediaHal/README.md | 37 -----------
middleware/MediaManager/CMakeLists.txt | 66 +++++++++++++++++++
middleware/MediaManager/README.md | 11 ++++
.../MediaManager/include/IMediaManager.h | 66 +++++++++++++++++++
middleware/MediaManager/src/IMediaManager.cpp | 30 +++++++++
.../MediaManager/src/MediaManagerImpl.cpp | 15 +++++
.../MediaManager/src/MediaManagerImpl.h | 24 +++++++
.../MediaManager/src/MediaManagerMakePtr.cpp | 54 +++++++++++++++
.../MediaManager/src/MediaManagerMakePtr.h | 28 ++++++++
utils/CMakeLists.txt | 3 +-
utils/McuProtocol/src/McuProtocolMakePtr.cpp | 8 ++-
utils/MediaAdapter/CMakeLists.txt | 54 +++++++++++++++
utils/MediaAdapter/include/MediaAdapter.h | 27 ++++++++
utils/MediaAdapter/src/IMediaAdapter.cpp | 29 ++++++++
utils/MediaAdapter/src/IMediaAdapter.h | 36 ++++++++++
utils/MediaAdapter/src/MediaAdapter.cpp | 49 ++++++++++++++
utils/UartDevice/src/UartDeviceImpl.h | 1 +
22 files changed, 512 insertions(+), 48 deletions(-)
delete mode 100644 middleware/MediaHal/README.md
create mode 100644 middleware/MediaManager/CMakeLists.txt
create mode 100644 middleware/MediaManager/README.md
create mode 100644 middleware/MediaManager/include/IMediaManager.h
create mode 100644 middleware/MediaManager/src/IMediaManager.cpp
create mode 100644 middleware/MediaManager/src/MediaManagerImpl.cpp
create mode 100644 middleware/MediaManager/src/MediaManagerImpl.h
create mode 100644 middleware/MediaManager/src/MediaManagerMakePtr.cpp
create mode 100644 middleware/MediaManager/src/MediaManagerMakePtr.h
create mode 100644 utils/MediaAdapter/CMakeLists.txt
create mode 100644 utils/MediaAdapter/include/MediaAdapter.h
create mode 100644 utils/MediaAdapter/src/IMediaAdapter.cpp
create mode 100644 utils/MediaAdapter/src/IMediaAdapter.h
create mode 100644 utils/MediaAdapter/src/MediaAdapter.cpp
diff --git a/doc/design.md b/doc/design.md
index a6fad107..267d184d 100644
--- a/doc/design.md
+++ b/doc/design.md
@@ -647,7 +647,7 @@ unsigned short calculate_check_sum(const unsigned char* pData, unsigned short le
| 命令字 | CPU | MCU | 数据段 | 协议解析 | 备注 |
|----|----|----|----|----|----|
| 0x8101 | ask | - | - | 获取启动模式 | - |
-| 0x0101 | - | reply | Data[0]:启动模式
0x01:PIR启动
0x02:TEST启动
0x03:连拍启动
0x04:PIR延时启动
0x05:定时(间隔一定时间)启动 | 回复启动模式 | - |
+| 0x0101 | - | reply | Data[0]:启动模式
0x01:PIR启动
0x02:TEST启动
0x03:连拍启动
0x04:PIR延时启动
0x05:定时(间隔一定时间)启动
0x06:关机
0x07:低电关机 | 回复启动模式 | - |
| 0x8102 | ask | - | - | 断电关机 | - |
| 0x8103 | ask | - | - | 喂狗 | - |
| 0x8104 | ask | - | Data[0]:Hour
0-23
Data[1]:Min
0-59
Data[2]:Sec
0-59 | 开启狗/设置喂狗周期 | - |
@@ -668,7 +668,7 @@ unsigned short calculate_check_sum(const unsigned char* pData, unsigned short le
| 0x010B | - | reply | Data[0]:结果
0-100 | 获取光敏值回复 | - |
| ====== | === | ====== | ============================ | ==================== | ======= |
| 0xC101 | reply | - | Data[0]:结果
0x01:成功
0x02:失败 | 发送启动模式回复 | - |
-| 0x4101 | - | ask | Data[0]:启动模式
0x01:PIR启动
0x02:TEST启动
0x03:连拍启动
0x04:PIR延时启动
0x05:定时(间隔一定时间)启动 | 发送启动模式 | - |
+| 0x4101 | - | ask | Data[0]:启动模式
0x01:PIR启动
0x02:TEST启动
0x03:连拍启动
0x04:PIR延时启动
0x05:定时(间隔一定时间)启动
0x06:关机
0x07:低电关机 | 发送启动模式 | - |
##### 1.4.3.2.6. IPC配置库
diff --git a/middleware/CMakeLists.txt b/middleware/CMakeLists.txt
index ba42c991..6b9db00f 100644
--- a/middleware/CMakeLists.txt
+++ b/middleware/CMakeLists.txt
@@ -2,4 +2,5 @@ add_subdirectory(StateMachine)
add_subdirectory(IpcConfig)
add_subdirectory(DeviceManager)
add_subdirectory(McuManager)
-add_subdirectory(McuAskBase)
\ No newline at end of file
+add_subdirectory(McuAskBase)
+add_subdirectory(MediaManager)
\ No newline at end of file
diff --git a/middleware/McuManager/CMakeLists.txt b/middleware/McuManager/CMakeLists.txt
index 3887c224..20b58ff4 100644
--- a/middleware/McuManager/CMakeLists.txt
+++ b/middleware/McuManager/CMakeLists.txt
@@ -15,9 +15,6 @@ include_directories(
#do not rely on any other library
#link_directories(
#)
-
-
-
if (DEFINED MCU_UART_DEVICE)
add_definitions(-DMCU_UART_DEVICE=\"${MCU_UART_DEVICE}\")
else()
diff --git a/middleware/McuManager/src/McuManagerMakePtr.cpp b/middleware/McuManager/src/McuManagerMakePtr.cpp
index a805220f..e47fafeb 100644
--- a/middleware/McuManager/src/McuManagerMakePtr.cpp
+++ b/middleware/McuManager/src/McuManagerMakePtr.cpp
@@ -36,7 +36,13 @@ std::shared_ptr &McuManagerMakePtr::GetInstance(std::shared_p
{
static auto instance = std::make_shared();
if (impl) {
- instance = *impl;
+ if (instance.use_count() == 1) {
+ LogInfo("Instance changed succeed.\n");
+ instance = *impl;
+ }
+ else {
+ LogError("Can't changing the instance becase of using by some one.\n");
+ }
}
return instance;
}
diff --git a/middleware/McuManager/src/McuManagerMakePtr.h b/middleware/McuManager/src/McuManagerMakePtr.h
index a1948223..a8ed74f9 100644
--- a/middleware/McuManager/src/McuManagerMakePtr.h
+++ b/middleware/McuManager/src/McuManagerMakePtr.h
@@ -12,8 +12,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#ifndef MCUMANAGER_MAKE_PTR_H
-#define MCUMANAGER_MAKE_PTR_H
+#ifndef MCU_MANAGER_MAKE_PTR_H
+#define MCU_MANAGER_MAKE_PTR_H
#include "IMcuManager.h"
#include "StatusCode.h"
#include
diff --git a/middleware/MediaHal/README.md b/middleware/MediaHal/README.md
deleted file mode 100644
index b220d3f1..00000000
--- a/middleware/MediaHal/README.md
+++ /dev/null
@@ -1,37 +0,0 @@
-# 1. 媒体适配
-
- 基于IPC项目芯片大部分都支持双核(低功耗),媒体接口对接需要考虑Linux和RTOS双系统的兼容支持。
-
-## 1.1. 软件设计
-
-### 1.1.1. 媒体适配模块UML类图
-```mermaid
-classDiagram
-class IMediaManager{
-<<媒体管理模块抽象接口>>
-+初始化()
-+解初始化()
-+音频编码()
-+音频解码()
-+视频编码()
-+视频解码()
-+抓怕()
-+录像()
-+录影()
-}
-class MediaManager{
-<<媒体管理模块实例>>
-}
-class LightSensor{
-<<光传感器类型枚举>>
-SENSOR_MAIN = 0,
-SENSOR_MINOR,
-END
-}
-class AudioHandle{
-<<音频处理>>
-}
-class VideoHandle{
-<<视频处理>>
-}
-```
\ No newline at end of file
diff --git a/middleware/MediaManager/CMakeLists.txt b/middleware/MediaManager/CMakeLists.txt
new file mode 100644
index 00000000..77146524
--- /dev/null
+++ b/middleware/MediaManager/CMakeLists.txt
@@ -0,0 +1,66 @@
+
+include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake)
+set(EXECUTABLE_OUTPUT_PATH ${EXEC_OUTPUT_PATH})
+set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH})
+
+include_directories(
+ ./src
+ ./include
+ ${MIDDLEWARE_SOURCE_PATH}/McuAskBase/include
+ ${UTILS_SOURCE_PATH}/StatusCode/include
+ ${UTILS_SOURCE_PATH}/Log/include
+ ${UTILS_SOURCE_PATH}/McuProtocol/include
+ ${UTILS_SOURCE_PATH}/UartDevice/include
+)
+#do not rely on any other library
+#link_directories(
+#)
+if (DEFINED MCU_UART_DEVICE)
+ add_definitions(-DMCU_UART_DEVICE=\"${MCU_UART_DEVICE}\")
+else()
+ message(FATAL_ERROR "You set define MCU_UART_DEVICE in toolchan .cmake file to tell what uart device to contrl.")
+endif()
+
+aux_source_directory(./src SRC_FILES)
+
+set(TARGET_NAME MediaManager)
+add_library(${TARGET_NAME} STATIC ${SRC_FILES})
+
+target_link_libraries(${TARGET_NAME} StatusCode Log)
+
+if ("${CLANG_TIDY_SUPPORT}" MATCHES "true")
+add_custom_target(
+ MediaManager_code_check
+ COMMAND ${CLANG_TIDY_EXE}
+ -checks='${CLANG_TIDY_CHECKS}'
+ --header-filter=.*
+ --system-headers=false
+ ${SRC_FILES}
+ ${CLANG_TIDY_CONFIG}
+ -p ${PLATFORM_PATH}/cmake-shell
+ WORKING_DIRECTORY ${MIDDLEWARE_SOURCE_PATH}/MediaManager
+)
+add_custom_command(
+ TARGET ${TARGET_NAME}
+ PRE_BUILD
+ COMMAND make MediaManager_code_check
+ WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
+)
+file(GLOB_RECURSE HEADER_FILES *.h)
+add_custom_target(
+ MediaManager_code_format
+ COMMAND ${CLANG_FORMAT_EXE}
+ -style=file
+ -i ${SRC_FILES} ${HEADER_FILES}
+ WORKING_DIRECTORY ${MIDDLEWARE_SOURCE_PATH}/MediaManager
+)
+add_custom_command(
+ TARGET ${TARGET_NAME}
+ PRE_BUILD
+ COMMAND make MediaManager_code_check
+ COMMAND make MediaManager_code_format
+ WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
+)
+endif()
+
+define_file_name(${TARGET_NAME})
\ No newline at end of file
diff --git a/middleware/MediaManager/README.md b/middleware/MediaManager/README.md
new file mode 100644
index 00000000..8bc1da5d
--- /dev/null
+++ b/middleware/MediaManager/README.md
@@ -0,0 +1,11 @@
+# 1. 媒体管理模块
+
+ 媒体管理模块,负责媒体相关的管理功能,包含抓拍,录像,文件管理(增/删/查)。
+
+## 1.1. 双摄管理
+
+ 以sensor为单位,对sensor创建实例对象进行管理。
+
+## 1.2. 文件管理
+
+ 对抓拍的图片/视频文件的管理。
\ No newline at end of file
diff --git a/middleware/MediaManager/include/IMediaManager.h b/middleware/MediaManager/include/IMediaManager.h
new file mode 100644
index 00000000..1d72895c
--- /dev/null
+++ b/middleware/MediaManager/include/IMediaManager.h
@@ -0,0 +1,66 @@
+/*
+ * 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.
+ */
+#ifndef I_MEDIA_MANAGER_H
+#define I_MEDIA_MANAGER_H
+#include "StatusCode.h"
+#include
+#include
+bool CreateMediaManager(void);
+bool DestroyMediaManager(void);
+enum class SensorNum
+{
+ SENSOR_1 = 1,
+ SENSOR_2,
+ END
+};
+enum class SensorTaskType
+{
+ TAKE_PICTURE = 0,
+ TAKE_VIDEO,
+ TAKE_PICTURE_AND_VIDEO,
+ MONITOR,
+ END
+};
+class SensorTaskResponse
+{
+public:
+ SensorTaskResponse() {}
+ ~SensorTaskResponse() {}
+};
+class VSensorTask
+{
+public:
+ VSensorTask() = default;
+ virtual ~VSensorTask() = default;
+ virtual const SensorTaskType GetTaskType(void) { return SensorTaskType::END; }
+ virtual void Response(const std::vector &response) {}
+ virtual bool IsTaskFinished(void) { return false; }
+ virtual const signed int GetIsNight(void) { return 0; }
+ virtual const unsigned int GetIsMultShot(void) { return false; }
+};
+class VSensorHandle
+{
+public:
+ VSensorHandle() = default;
+ virtual ~VSensorHandle() = default;
+};
+class IMediaManager
+{
+public:
+ IMediaManager() = default;
+ virtual ~IMediaManager() = default;
+ static std::shared_ptr &GetInstance(std::shared_ptr *impl = nullptr);
+};
+#endif
\ No newline at end of file
diff --git a/middleware/MediaManager/src/IMediaManager.cpp b/middleware/MediaManager/src/IMediaManager.cpp
new file mode 100644
index 00000000..a794d1e9
--- /dev/null
+++ b/middleware/MediaManager/src/IMediaManager.cpp
@@ -0,0 +1,30 @@
+/*
+ * 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 "IMediaManager.h"
+#include "ILog.h"
+std::shared_ptr &IMediaManager::GetInstance(std::shared_ptr *impl)
+{
+ static auto instance = std::make_shared();
+ if (impl) {
+ if (instance.use_count() == 1) {
+ LogInfo("Instance changed succeed.\n");
+ instance = *impl;
+ }
+ else {
+ LogError("Can't changing the instance becase of using by some one.\n");
+ }
+ }
+ return instance;
+}
\ No newline at end of file
diff --git a/middleware/MediaManager/src/MediaManagerImpl.cpp b/middleware/MediaManager/src/MediaManagerImpl.cpp
new file mode 100644
index 00000000..1152ba7c
--- /dev/null
+++ b/middleware/MediaManager/src/MediaManagerImpl.cpp
@@ -0,0 +1,15 @@
+/*
+ * 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 "MediaManagerImpl.h"
\ No newline at end of file
diff --git a/middleware/MediaManager/src/MediaManagerImpl.h b/middleware/MediaManager/src/MediaManagerImpl.h
new file mode 100644
index 00000000..d23495e4
--- /dev/null
+++ b/middleware/MediaManager/src/MediaManagerImpl.h
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+#ifndef MEDIA_MANAGER_IMPL_H
+#define MEDIA_MANAGER_IMPL_H
+#include "IMediaManager.h"
+class MediaManagerImpl : public IMediaManager
+{
+public:
+ MediaManagerImpl() = default;
+ virtual ~MediaManagerImpl() = default;
+};
+#endif
\ No newline at end of file
diff --git a/middleware/MediaManager/src/MediaManagerMakePtr.cpp b/middleware/MediaManager/src/MediaManagerMakePtr.cpp
new file mode 100644
index 00000000..9c313200
--- /dev/null
+++ b/middleware/MediaManager/src/MediaManagerMakePtr.cpp
@@ -0,0 +1,54 @@
+/*
+ * 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 "MediaManagerMakePtr.h"
+#include "ILog.h"
+#include "MediaManagerImpl.h"
+bool CreateMediaManager(void)
+{
+ auto instance = std::make_shared();
+ StatusCode code = MediaManagerMakePtr::GetInstance()->CreateMediaManager(instance);
+ if (IsCodeOK(code)) {
+ LogInfo("CreateMediaManager is ok.\n");
+ IMediaManager::GetInstance(&instance);
+ return true;
+ }
+ return false;
+}
+bool DestroyMediaManager(void)
+{
+ auto instance = std::make_shared();
+ IMediaManager::GetInstance(&instance);
+ return true;
+}
+std::shared_ptr &MediaManagerMakePtr::GetInstance(std::shared_ptr *impl)
+{
+ static auto instance = std::make_shared();
+ if (impl) {
+ if (instance.use_count() == 1) {
+ LogInfo("Instance changed succeed.\n");
+ instance = *impl;
+ }
+ else {
+ LogError("Can't changing the instance becase of using by some one.\n");
+ }
+ }
+ return instance;
+}
+const StatusCode MediaManagerMakePtr::CreateMediaManager(std::shared_ptr &impl)
+{
+ auto tmp = std::make_shared();
+ impl = tmp;
+ return CreateStatusCode(STATUS_CODE_OK);
+}
\ No newline at end of file
diff --git a/middleware/MediaManager/src/MediaManagerMakePtr.h b/middleware/MediaManager/src/MediaManagerMakePtr.h
new file mode 100644
index 00000000..6896c914
--- /dev/null
+++ b/middleware/MediaManager/src/MediaManagerMakePtr.h
@@ -0,0 +1,28 @@
+/*
+ * 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.
+ */
+#ifndef MEDIA_MANAGER_MAKE_PTR_H
+#define MEDIA_MANAGER_MAKE_PTR_H
+#include "IMediaManager.h"
+#include "StatusCode.h"
+#include
+class MediaManagerMakePtr
+{
+public:
+ MediaManagerMakePtr() = default;
+ virtual ~MediaManagerMakePtr() = default;
+ static std::shared_ptr &GetInstance(std::shared_ptr *impl = nullptr);
+ virtual const StatusCode CreateMediaManager(std::shared_ptr &impl);
+};
+#endif // !IPC_CONFIG_MAKE_PTR_H
\ No newline at end of file
diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt
index 9e595ba6..7dc13e50 100644
--- a/utils/CMakeLists.txt
+++ b/utils/CMakeLists.txt
@@ -11,4 +11,5 @@ add_subdirectory(WebServer)
add_subdirectory(McuProtocol)
add_subdirectory(ModBusCRC16)
add_subdirectory(LedControl)
-add_subdirectory(KeyControl)
\ No newline at end of file
+add_subdirectory(KeyControl)
+add_subdirectory(MediaAdapter)
\ No newline at end of file
diff --git a/utils/McuProtocol/src/McuProtocolMakePtr.cpp b/utils/McuProtocol/src/McuProtocolMakePtr.cpp
index 05db48f7..8c448bf5 100644
--- a/utils/McuProtocol/src/McuProtocolMakePtr.cpp
+++ b/utils/McuProtocol/src/McuProtocolMakePtr.cpp
@@ -20,7 +20,13 @@ std::shared_ptr &McuProtocolMakePtr::GetInstance(std::shared
{
static auto instance = std::make_shared();
if (impl) {
- instance = *impl;
+ if (instance.use_count() == 1) {
+ LogInfo("Instance changed succeed.\n");
+ instance = *impl;
+ }
+ else {
+ LogError("Can't changing the instance becase of using by some one.\n");
+ }
}
return instance;
}
diff --git a/utils/MediaAdapter/CMakeLists.txt b/utils/MediaAdapter/CMakeLists.txt
new file mode 100644
index 00000000..e7926b82
--- /dev/null
+++ b/utils/MediaAdapter/CMakeLists.txt
@@ -0,0 +1,54 @@
+include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake)
+set(EXECUTABLE_OUTPUT_PATH ${EXEC_OUTPUT_PATH})
+set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH})
+
+include_directories(
+ ./src
+ ./include
+ # ${UTILS_SOURCE_PATH}/LinuxApi/include
+ ${UTILS_SOURCE_PATH}/StatusCode/include
+ ${UTILS_SOURCE_PATH}/ModBusCRC16/include
+ ${UTILS_SOURCE_PATH}/Log/include
+)
+# link_directories(
+# ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs
+# )
+
+
+
+aux_source_directory(./src SRC_FILES)
+
+set(TARGET_NAME MediaAdapter)
+add_library(${TARGET_NAME} STATIC ${SRC_FILES})
+target_link_libraries(${TARGET_NAME} StatusCode Log)
+
+if ("${CLANG_TIDY_SUPPORT}" MATCHES "true")
+add_custom_target(
+ MediaAdapter_code_check
+ COMMAND ${CLANG_TIDY_EXE}
+ -checks='${CLANG_TIDY_CHECKS}'
+ --header-filter=.*
+ --system-headers=false
+ ${SRC_FILES}
+ ${CLANG_TIDY_CONFIG}
+ -p ${PLATFORM_PATH}/cmake-shell
+ WORKING_DIRECTORY ${UTILS_SOURCE_PATH}/MediaAdapter
+)
+file(GLOB_RECURSE HEADER_FILES *.h)
+add_custom_target(
+ MediaAdapter_code_format
+ COMMAND ${CLANG_FORMAT_EXE}
+ -style=file
+ -i ${SRC_FILES} ${HEADER_FILES}
+ WORKING_DIRECTORY ${UTILS_SOURCE_PATH}/MediaAdapter
+)
+add_custom_command(
+ TARGET ${TARGET_NAME}
+ PRE_BUILD
+ COMMAND make MediaAdapter_code_check
+ COMMAND make MediaAdapter_code_format
+ WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
+)
+endif()
+
+define_file_name(${TARGET_NAME})
\ No newline at end of file
diff --git a/utils/MediaAdapter/include/MediaAdapter.h b/utils/MediaAdapter/include/MediaAdapter.h
new file mode 100644
index 00000000..c7568f4e
--- /dev/null
+++ b/utils/MediaAdapter/include/MediaAdapter.h
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+#ifndef MEDIA_ADAPTER_H
+#define MEDIA_ADAPTER_H
+#include "StatusCode.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+void *CreateMediaAdapter(void);
+void TestApi(void *object);
+void IMediaAdapterFree(void *object);
+#ifdef __cplusplus
+}
+#endif
+#endif
\ No newline at end of file
diff --git a/utils/MediaAdapter/src/IMediaAdapter.cpp b/utils/MediaAdapter/src/IMediaAdapter.cpp
new file mode 100644
index 00000000..751c9605
--- /dev/null
+++ b/utils/MediaAdapter/src/IMediaAdapter.cpp
@@ -0,0 +1,29 @@
+/*
+ * 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 "IMediaAdapter.h"
+#include "ILog.h"
+#include
+static const char *MEDIA_ADAPTER_NAME = "media_adapter";
+const char inline *GetMediaAdapterModuleName(void) { return MEDIA_ADAPTER_NAME; }
+std::shared_ptr *NewIMediaAdapter(void)
+{
+ LogInfo("Create the uart device object.\n");
+ MeidaAdapter *impl = (MeidaAdapter *)malloc(sizeof(MeidaAdapter));
+ MeidaAdapter tmp;
+ memcpy((void *)impl, (void *)&tmp, sizeof(MeidaAdapter));
+ impl->mHeader.mCheckName = MEDIA_ADAPTER_NAME;
+ impl->mIMediaAdapter = std::make_shared();
+ return (std::shared_ptr *)(((char *)impl) + sizeof(MediaAdapterHeader));
+}
\ No newline at end of file
diff --git a/utils/MediaAdapter/src/IMediaAdapter.h b/utils/MediaAdapter/src/IMediaAdapter.h
new file mode 100644
index 00000000..6005cdae
--- /dev/null
+++ b/utils/MediaAdapter/src/IMediaAdapter.h
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ */
+#ifndef I_MEDIA_ADAPTER_H
+#define I_MEDIA_ADAPTER_H
+#include
+class IMediaAdapter
+{
+public:
+ IMediaAdapter() = default;
+ virtual ~IMediaAdapter() = default;
+ virtual void TestApi(void) {}
+};
+typedef struct media_adapter_header
+{
+ const char *mCheckName;
+} MediaAdapterHeader;
+typedef struct media_adapter
+{
+ MediaAdapterHeader mHeader;
+ std::shared_ptr mIMediaAdapter;
+} MeidaAdapter;
+const char *GetMediaAdapterModuleName(void);
+std::shared_ptr *NewIMediaAdapter(void);
+#endif
\ No newline at end of file
diff --git a/utils/MediaAdapter/src/MediaAdapter.cpp b/utils/MediaAdapter/src/MediaAdapter.cpp
new file mode 100644
index 00000000..1c031d11
--- /dev/null
+++ b/utils/MediaAdapter/src/MediaAdapter.cpp
@@ -0,0 +1,49 @@
+/*
+ * 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 "MediaAdapter.h"
+#include "ILog.h"
+#include "IMediaAdapter.h"
+void *CreateMediaAdapter(void) { return NewIMediaAdapter(); }
+static bool ObjectCheck(void *object)
+{
+ if (nullptr == object) {
+ LogError("nullptr object!\n");
+ return false;
+ }
+ if (*((const char **)(((char *)object) - sizeof(IMediaAdapter))) != GetMediaAdapterModuleName()) {
+ LogError("Illegal object!\n");
+ return false;
+ }
+ return true;
+}
+void TestApi(void *object)
+{
+ if (nullptr == object) {
+ LogError("nullptr object!\n");
+ return;
+ }
+ if (*((const char **)(((char *)object) - sizeof(IMediaAdapter))) != GetMediaAdapterModuleName()) {
+ LogError("Illegal object!\n");
+ return;
+ }
+ (*(std::shared_ptr *)object)->TestApi();
+}
+void IMediaAdapterFree(void *object)
+{
+ if (ObjectCheck(object) == true) {
+ (*(std::shared_ptr *)object).reset();
+ free(((char *)object) - sizeof(IMediaAdapter));
+ }
+}
\ No newline at end of file
diff --git a/utils/UartDevice/src/UartDeviceImpl.h b/utils/UartDevice/src/UartDeviceImpl.h
index e37e15f6..8859bfe4 100644
--- a/utils/UartDevice/src/UartDeviceImpl.h
+++ b/utils/UartDevice/src/UartDeviceImpl.h
@@ -50,6 +50,7 @@ typedef struct uart_device
void (*mTcflush)(UartDevice *);
void (*mFree)(void *);
} UartDevice;
+// TODO: There may be a CPU byte alignment bug.
typedef struct uart_device_impl UartDeviceImpl_S;
typedef struct uart_device_impl
{