Add MucManager module.
This commit is contained in:
parent
c1a5ad44a9
commit
a2c4fa60ec
|
@ -21,7 +21,7 @@ AllowShortLoopsOnASingleLine: false
|
||||||
AlwaysBreakAfterDefinitionReturnType: None
|
AlwaysBreakAfterDefinitionReturnType: None
|
||||||
AlwaysBreakAfterReturnType: None
|
AlwaysBreakAfterReturnType: None
|
||||||
AlwaysBreakBeforeMultilineStrings: false
|
AlwaysBreakBeforeMultilineStrings: false
|
||||||
AlwaysBreakTemplateDeclarations: MultiLine
|
AlwaysBreakTemplateDeclarations: true
|
||||||
BinPackArguments: false
|
BinPackArguments: false
|
||||||
BinPackParameters: true
|
BinPackParameters: true
|
||||||
BraceWrapping:
|
BraceWrapping:
|
||||||
|
|
|
@ -46,3 +46,6 @@ set(GOAHEAD_DOCUMENTS_PATH "web")
|
||||||
# GOAHEAD_CONFIG_FILE_PATH should be set when cross compile
|
# GOAHEAD_CONFIG_FILE_PATH should be set when cross compile
|
||||||
# set(GOAHEAD_CONFIG_FILE_PATH "./")
|
# set(GOAHEAD_CONFIG_FILE_PATH "./")
|
||||||
# ------------ build GoAhead end ------------ #
|
# ------------ build GoAhead end ------------ #
|
||||||
|
# ------------ build McuManager ------------ #
|
||||||
|
set(MCU_UART_DEVICE "dev/s1")
|
||||||
|
# ------------ build McuManager end ------------ #
|
|
@ -1,3 +1,4 @@
|
||||||
add_subdirectory(StateMachine)
|
add_subdirectory(StateMachine)
|
||||||
add_subdirectory(IpcConfig)
|
add_subdirectory(IpcConfig)
|
||||||
add_subdirectory(DeviceManager)
|
add_subdirectory(DeviceManager)
|
||||||
|
add_subdirectory(McuManager)
|
67
middleware/McuManager/CMakeLists.txt
Normal file
67
middleware/McuManager/CMakeLists.txt
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
|
||||||
|
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}/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(
|
||||||
|
#)
|
||||||
|
|
||||||
|
set(CMAKE_AUTOMOC ON)
|
||||||
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||||
|
|
||||||
|
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 McuManager)
|
||||||
|
add_library(${TARGET_NAME} STATIC ${SRC_FILES})
|
||||||
|
|
||||||
|
target_link_libraries(${TARGET_NAME} UartDevice McuProtocol StatusCode Log)
|
||||||
|
|
||||||
|
if ("${CLANG_TIDY_SUPPORT}" MATCHES "true")
|
||||||
|
add_custom_target(
|
||||||
|
McuManager_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}/McuManager
|
||||||
|
)
|
||||||
|
add_custom_command(
|
||||||
|
TARGET ${TARGET_NAME}
|
||||||
|
PRE_BUILD
|
||||||
|
COMMAND make McuManager_code_check
|
||||||
|
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
|
||||||
|
)
|
||||||
|
file(GLOB_RECURSE HEADER_FILES *.h)
|
||||||
|
add_custom_target(
|
||||||
|
McuManager_code_format
|
||||||
|
COMMAND ${CLANG_FORMAT_EXE}
|
||||||
|
-style=file
|
||||||
|
-i ${SRC_FILES} ${HEADER_FILES}
|
||||||
|
WORKING_DIRECTORY ${MIDDLEWARE_SOURCE_PATH}/McuManager
|
||||||
|
)
|
||||||
|
add_custom_command(
|
||||||
|
TARGET ${TARGET_NAME}
|
||||||
|
PRE_BUILD
|
||||||
|
COMMAND make McuManager_code_check
|
||||||
|
COMMAND make McuManager_code_format
|
||||||
|
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
|
||||||
|
)
|
||||||
|
endif()
|
58
middleware/McuManager/include/IMcuManager.h
Normal file
58
middleware/McuManager/include/IMcuManager.h
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
/*
|
||||||
|
* 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_MCU_MANAGER_H
|
||||||
|
#define I_MCU_MANAGER_H
|
||||||
|
#include "StatusCode.h"
|
||||||
|
#include <memory>
|
||||||
|
bool CreateMcuManager(void);
|
||||||
|
enum class IpcMission
|
||||||
|
{
|
||||||
|
TEST = 0,
|
||||||
|
END
|
||||||
|
};
|
||||||
|
constexpr int NEVER_TIMEOUT_UNTIL_REPLY = 0;
|
||||||
|
class VMcuAsk
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
VMcuAsk() = default;
|
||||||
|
virtual ~VMcuAsk() = default;
|
||||||
|
bool IsBlock(void) { return false; }
|
||||||
|
unsigned int GetTimeOutMs(void) { return NEVER_TIMEOUT_UNTIL_REPLY; }
|
||||||
|
};
|
||||||
|
template <typename T>
|
||||||
|
class McuAsk : public VMcuAsk
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
McuAsk() {}
|
||||||
|
virtual ~McuAsk() = default;
|
||||||
|
|
||||||
|
public:
|
||||||
|
T mDataReply;
|
||||||
|
};
|
||||||
|
class IMcuManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
IMcuManager() = default;
|
||||||
|
virtual ~IMcuManager() = default;
|
||||||
|
static std::shared_ptr<IMcuManager> &GetInstance(std::shared_ptr<IMcuManager> *impl = nullptr);
|
||||||
|
virtual const StatusCode Init(void) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); }
|
||||||
|
virtual const StatusCode UnInit(void) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); }
|
||||||
|
virtual const StatusCode GetIpcMissiony(std::shared_ptr<VMcuAsk> ask)
|
||||||
|
{
|
||||||
|
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
#endif
|
30
middleware/McuManager/src/IMcuManager.cpp
Normal file
30
middleware/McuManager/src/IMcuManager.cpp
Normal file
|
@ -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 "IMcuManager.h"
|
||||||
|
#include "ILog.h"
|
||||||
|
std::shared_ptr<IMcuManager> &IMcuManager::GetInstance(std::shared_ptr<IMcuManager> *impl)
|
||||||
|
{
|
||||||
|
static auto instance = std::make_shared<IMcuManager>();
|
||||||
|
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;
|
||||||
|
}
|
39
middleware/McuManager/src/McuDevice.cpp
Normal file
39
middleware/McuManager/src/McuDevice.cpp
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* 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 "McuDevice.h"
|
||||||
|
McuDevice::McuDevice() { mUartDevice = nullptr; }
|
||||||
|
McuDevice::~McuDevice() {}
|
||||||
|
const StatusCode McuDevice::Init(void)
|
||||||
|
{
|
||||||
|
UartInfo uartDevice = {
|
||||||
|
MCU_UART_DEVICE,
|
||||||
|
1152000,
|
||||||
|
'N',
|
||||||
|
8,
|
||||||
|
1,
|
||||||
|
'N',
|
||||||
|
};
|
||||||
|
mUartDevice = CreateUartDevice(uartDevice);
|
||||||
|
return CreateStatusCode(STATUS_CODE_OK);
|
||||||
|
}
|
||||||
|
const StatusCode McuDevice::UnInit(void)
|
||||||
|
{
|
||||||
|
if (nullptr != mUartDevice) {
|
||||||
|
|
||||||
|
IUartDeviceFree(mUartDevice);
|
||||||
|
}
|
||||||
|
mUartDevice = nullptr;
|
||||||
|
return CreateStatusCode(STATUS_CODE_OK);
|
||||||
|
}
|
31
middleware/McuManager/src/McuDevice.h
Normal file
31
middleware/McuManager/src/McuDevice.h
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
* 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 MCU_DEVICE_H
|
||||||
|
#define MCU_DEVICE_H
|
||||||
|
#include "IMcuManager.h"
|
||||||
|
#include "McuProtocol.h"
|
||||||
|
#include "UartDevice.h"
|
||||||
|
class McuDevice : public IMcuManager, virtual public VProtocolBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
McuDevice();
|
||||||
|
virtual ~McuDevice();
|
||||||
|
const StatusCode Init(void) override;
|
||||||
|
const StatusCode UnInit(void) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void *mUartDevice;
|
||||||
|
};
|
||||||
|
#endif
|
22
middleware/McuManager/src/McuManagerImpl.cpp
Normal file
22
middleware/McuManager/src/McuManagerImpl.cpp
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
/*
|
||||||
|
* 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 "McuManagerImpl.h"
|
||||||
|
const StatusCode McuManagerImpl::GetIpcMissiony(std::shared_ptr<VMcuAsk> ask)
|
||||||
|
{
|
||||||
|
std::shared_ptr<VProtocolContext> context = std::make_shared<ProtocolContext<std::shared_ptr<VMcuAsk>>>(ask);
|
||||||
|
McuProtocol::GetIpcMissiony(context);
|
||||||
|
// IpcMission mission = static_cast<IpcMission>(data);
|
||||||
|
return CreateStatusCode(STATUS_CODE_OK);
|
||||||
|
}
|
27
middleware/McuManager/src/McuManagerImpl.h
Normal file
27
middleware/McuManager/src/McuManagerImpl.h
Normal file
|
@ -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 MCU_MANAGER_IMPL_H
|
||||||
|
#define MCU_MANAGER_IMPL_H
|
||||||
|
#include "IMcuManager.h"
|
||||||
|
#include "McuDevice.h"
|
||||||
|
#include "McuProtocol.h"
|
||||||
|
class McuManagerImpl : public McuDevice, public McuProtocol
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
McuManagerImpl() = default;
|
||||||
|
virtual ~McuManagerImpl() = default;
|
||||||
|
const StatusCode GetIpcMissiony(std::shared_ptr<VMcuAsk> ask) override;
|
||||||
|
};
|
||||||
|
#endif
|
42
middleware/McuManager/src/McuManagerMakePtr.cpp
Normal file
42
middleware/McuManager/src/McuManagerMakePtr.cpp
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
* 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 "McuManagerMakePtr.h"
|
||||||
|
#include "ILog.h"
|
||||||
|
#include "McuManagerImpl.h"
|
||||||
|
bool CreateMcuManager(void)
|
||||||
|
{
|
||||||
|
auto instance = std::make_shared<IMcuManager>();
|
||||||
|
StatusCode code = McuManagerMakePtr::GetInstance()->CreateMcuManager(instance);
|
||||||
|
if (IsCodeOK(code)) {
|
||||||
|
LogInfo("CreateMcuManager is ok.\n");
|
||||||
|
IMcuManager::GetInstance(&instance);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
std::shared_ptr<McuManagerMakePtr> &McuManagerMakePtr::GetInstance(std::shared_ptr<McuManagerMakePtr> *impl)
|
||||||
|
{
|
||||||
|
static auto instance = std::make_shared<McuManagerMakePtr>();
|
||||||
|
if (impl) {
|
||||||
|
instance = *impl;
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
const StatusCode McuManagerMakePtr::CreateMcuManager(std::shared_ptr<IMcuManager> &impl)
|
||||||
|
{
|
||||||
|
auto tmp = std::make_shared<McuManagerImpl>();
|
||||||
|
impl = tmp;
|
||||||
|
return CreateStatusCode(STATUS_CODE_OK);
|
||||||
|
}
|
28
middleware/McuManager/src/McuManagerMakePtr.h
Normal file
28
middleware/McuManager/src/McuManagerMakePtr.h
Normal file
|
@ -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 MCUMANAGER_MAKE_PTR_H
|
||||||
|
#define MCUMANAGER_MAKE_PTR_H
|
||||||
|
#include "IMcuManager.h"
|
||||||
|
#include "StatusCode.h"
|
||||||
|
#include <memory>
|
||||||
|
class McuManagerMakePtr
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
McuManagerMakePtr() = default;
|
||||||
|
virtual ~McuManagerMakePtr() = default;
|
||||||
|
static std::shared_ptr<McuManagerMakePtr> &GetInstance(std::shared_ptr<McuManagerMakePtr> *impl = nullptr);
|
||||||
|
virtual const StatusCode CreateMcuManager(std::shared_ptr<IMcuManager> &impl);
|
||||||
|
};
|
||||||
|
#endif // !IPC_CONFIG_MAKE_PTR_H
|
|
@ -1,3 +1,4 @@
|
||||||
|
|
||||||
# cmake_minimum_required(VERSION 2.8.0)
|
# cmake_minimum_required(VERSION 2.8.0)
|
||||||
add_subdirectory(IpcConfig)
|
add_subdirectory(IpcConfig)
|
||||||
|
add_subdirectory(McuManager)
|
|
@ -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 <gmock/gmock.h>
|
#include <gmock/gmock.h>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
78
test/middleware/McuManager/CMakeLists.txt
Normal file
78
test/middleware/McuManager/CMakeLists.txt
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
# include(${CMAKE_SOURCE_DIR}/build/independent_source.cmake)
|
||||||
|
include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake)
|
||||||
|
set(EXECUTABLE_OUTPUT_PATH ${TEST_OUTPUT_PATH}/bin)
|
||||||
|
|
||||||
|
include_directories(
|
||||||
|
.
|
||||||
|
./src
|
||||||
|
./include
|
||||||
|
${UTILS_SOURCE_PATH}/Log/include
|
||||||
|
${UTILS_SOURCE_PATH}/StatusCode/include
|
||||||
|
${MIDDLEWARE_SOURCE_PATH}/McuManager/include
|
||||||
|
${TEST_SOURCE_PATH}/utils/LinuxApiMock/include
|
||||||
|
${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googletest/include
|
||||||
|
${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googlemock/include
|
||||||
|
)
|
||||||
|
|
||||||
|
link_directories(
|
||||||
|
${LIBS_OUTPUT_PATH}
|
||||||
|
${EXTERNAL_LIBS_OUTPUT_PATH}
|
||||||
|
)
|
||||||
|
|
||||||
|
set(CMAKE_AUTOMOC ON)
|
||||||
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||||
|
|
||||||
|
set(CMAKE_AUTOMOC ON)
|
||||||
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||||
|
|
||||||
|
aux_source_directory(. SRC_FILES_MAIN)
|
||||||
|
aux_source_directory(./src SRC_FILES)
|
||||||
|
if(${TARGET_PLATFORM} MATCHES ${DEFINE_LINUX})
|
||||||
|
aux_source_directory(./src_mock SRC_FILES)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(TARGET_NAME McuManagerTest)
|
||||||
|
add_executable(${TARGET_NAME} ${SRC_FILES_MAIN} ${SRC_FILES})
|
||||||
|
target_link_libraries(${TARGET_NAME} McuManager UartDeviceTestTool gtest gmock pthread)
|
||||||
|
if(${TEST_COVERAGE} MATCHES "true")
|
||||||
|
target_link_libraries(${TARGET_NAME} gcov)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if ("${CLANG_TIDY_SUPPORT}" MATCHES "true")
|
||||||
|
add_custom_target(
|
||||||
|
McuManagerTest_code_check
|
||||||
|
COMMAND ${CLANG_TIDY_EXE}
|
||||||
|
-checks='${CLANG_TIDY_CHECKS}'
|
||||||
|
--header-filter=.*
|
||||||
|
--system-headers=false
|
||||||
|
${SRC_FILES}
|
||||||
|
${CLANG_TIDY_CONFIG}
|
||||||
|
# --line-filter='[{\"name\":\"${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googletest/include/getest/gtest.h\"}]'
|
||||||
|
--line-filter='[{\"name\":\"${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googletest/include/getest/*.h\"}]'
|
||||||
|
-p ${PLATFORM_PATH}/cmake-shell
|
||||||
|
WORKING_DIRECTORY ${TEST_SOURCE_PATH}/middleware/McuManager
|
||||||
|
)
|
||||||
|
add_custom_command(
|
||||||
|
TARGET ${TARGET_NAME}
|
||||||
|
PRE_BUILD
|
||||||
|
COMMAND make McuManagerTest_code_check
|
||||||
|
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
|
||||||
|
)
|
||||||
|
|
||||||
|
file(GLOB_RECURSE HEADER_FILES *.h)
|
||||||
|
add_custom_target(
|
||||||
|
McuManagerTest_code_format
|
||||||
|
COMMAND ${CLANG_FORMAT_EXE}
|
||||||
|
-style=file
|
||||||
|
-i ${SRC_FILES} ${SRC_FILES_MAIN} ${HEADER_FILES}
|
||||||
|
WORKING_DIRECTORY ${TEST_SOURCE_PATH}/middleware/McuManager
|
||||||
|
)
|
||||||
|
add_custom_command(
|
||||||
|
TARGET ${TARGET_NAME}
|
||||||
|
PRE_BUILD
|
||||||
|
COMMAND make McuManagerTest_code_check
|
||||||
|
COMMAND make McuManagerTest_code_format
|
||||||
|
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
define_file_name(${TARGET_NAME})
|
23
test/middleware/McuManager/mainTest.cpp
Normal file
23
test/middleware/McuManager/mainTest.cpp
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
/*
|
||||||
|
* 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 <gmock/gmock.h>
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include <thread>
|
||||||
|
#include <unistd.h>
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
testing::InitGoogleTest(&argc, argv);
|
||||||
|
return RUN_ALL_TESTS();
|
||||||
|
}
|
42
test/middleware/McuManager/src_mock/McuManager_Mock_Test.cpp
Normal file
42
test/middleware/McuManager/src_mock/McuManager_Mock_Test.cpp
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
#include "ILog.h"
|
||||||
|
#include "IMcuManager.h"
|
||||||
|
#include "LinuxApiMock.h"
|
||||||
|
#include <gmock/gmock.h>
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
namespace McuManagerMockTest
|
||||||
|
{
|
||||||
|
class McuManagerMockTest : public testing::Test
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
McuManagerMockTest() {}
|
||||||
|
virtual ~McuManagerMockTest() {}
|
||||||
|
static void SetUpTestCase()
|
||||||
|
{
|
||||||
|
CreateLogModule();
|
||||||
|
CreateMcuManager();
|
||||||
|
ILogInit(LOG_INSTANCE_TYPE_END);
|
||||||
|
}
|
||||||
|
static void TearDownTestCase() { ILogUnInit(); }
|
||||||
|
virtual void SetUp()
|
||||||
|
{
|
||||||
|
mLinuxTest = LinuxTest::CreateLinuxTest();
|
||||||
|
std::shared_ptr<LinuxApiMock> test = mLinuxTest;
|
||||||
|
LinuxApiMock::GetInstance(&test);
|
||||||
|
LinuxApiMock::GetInstance()->Init();
|
||||||
|
// RegisterUartDevice(mLinuxTest, gUartDevice);
|
||||||
|
}
|
||||||
|
virtual void TearDown()
|
||||||
|
{
|
||||||
|
LinuxApiMock::GetInstance()->UnInit();
|
||||||
|
mLinuxTest = std::make_shared<LinuxTest>();
|
||||||
|
std::shared_ptr<LinuxApiMock> test = std::make_shared<LinuxApiMock>();
|
||||||
|
LinuxApiMock::GetInstance(&test);
|
||||||
|
// UnregisterUartDevice(gUartDevice);
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
std::shared_ptr<LinuxTest> mLinuxTest;
|
||||||
|
};
|
||||||
|
// ../output_files/test/bin/UartDeviceTest --gtest_filter=McuManagerTest.UNIT_UartDevice_EXAMPLE_AUTO_Demo
|
||||||
|
TEST_F(McuManagerMockTest, UNIT_UartDevice_EXAMPLE_AUTO_Demo) {}
|
||||||
|
} // namespace McuManagerMockTest
|
|
@ -20,7 +20,7 @@ aux_source_directory(./src SRC_FILES)
|
||||||
|
|
||||||
set(TARGET_NAME LinuxApiMock)
|
set(TARGET_NAME LinuxApiMock)
|
||||||
add_library(${TARGET_NAME} STATIC ${SRC_FILES})
|
add_library(${TARGET_NAME} STATIC ${SRC_FILES})
|
||||||
target_link_libraries(${TARGET_NAME} gtest gmock Log)
|
target_link_libraries(${TARGET_NAME} LinuxApi gtest gmock Log)
|
||||||
|
|
||||||
if ("${CLANG_TIDY_SUPPORT}" MATCHES "true")
|
if ("${CLANG_TIDY_SUPPORT}" MATCHES "true")
|
||||||
add_custom_target(
|
add_custom_target(
|
||||||
|
|
|
@ -19,7 +19,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||||
aux_source_directory(./src TEST_TOOL_SRC_FILES)
|
aux_source_directory(./src TEST_TOOL_SRC_FILES)
|
||||||
set(TEST_TOOL_TARGET UartDeviceTestTool)
|
set(TEST_TOOL_TARGET UartDeviceTestTool)
|
||||||
add_library(${TEST_TOOL_TARGET} STATIC ${TEST_TOOL_SRC_FILES})
|
add_library(${TEST_TOOL_TARGET} STATIC ${TEST_TOOL_SRC_FILES})
|
||||||
target_link_libraries(${TEST_TOOL_TARGET} Log)
|
target_link_libraries(${TEST_TOOL_TARGET} UartDevice LinuxApiMock Log)
|
||||||
|
|
||||||
if ("${CLANG_TIDY_SUPPORT}" MATCHES "true")
|
if ("${CLANG_TIDY_SUPPORT}" MATCHES "true")
|
||||||
add_custom_target(
|
add_custom_target(
|
||||||
|
|
|
@ -8,3 +8,4 @@ add_subdirectory(UartDevice)
|
||||||
add_subdirectory(LinuxApi)
|
add_subdirectory(LinuxApi)
|
||||||
# add_subdirectory(MultiProcess)
|
# add_subdirectory(MultiProcess)
|
||||||
add_subdirectory(WebServer)
|
add_subdirectory(WebServer)
|
||||||
|
add_subdirectory(McuProtocol)
|
||||||
|
|
54
utils/McuProtocol/CMakeLists.txt
Normal file
54
utils/McuProtocol/CMakeLists.txt
Normal file
|
@ -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}/Log/include
|
||||||
|
)
|
||||||
|
# link_directories(
|
||||||
|
# ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs
|
||||||
|
# )
|
||||||
|
|
||||||
|
set(CMAKE_AUTOMOC ON)
|
||||||
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||||
|
|
||||||
|
aux_source_directory(./src SRC_FILES)
|
||||||
|
|
||||||
|
set(TARGET_NAME McuProtocol)
|
||||||
|
add_library(${TARGET_NAME} STATIC ${SRC_FILES})
|
||||||
|
target_link_libraries(${TARGET_NAME} StatusCode Log)
|
||||||
|
|
||||||
|
if ("${CLANG_TIDY_SUPPORT}" MATCHES "true")
|
||||||
|
add_custom_target(
|
||||||
|
McuProtocol_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}/McuProtocol
|
||||||
|
)
|
||||||
|
file(GLOB_RECURSE HEADER_FILES *.h)
|
||||||
|
add_custom_target(
|
||||||
|
McuProtocol_code_format
|
||||||
|
COMMAND ${CLANG_FORMAT_EXE}
|
||||||
|
-style=file
|
||||||
|
-i ${SRC_FILES} ${HEADER_FILES}
|
||||||
|
WORKING_DIRECTORY ${UTILS_SOURCE_PATH}/McuProtocol
|
||||||
|
)
|
||||||
|
add_custom_command(
|
||||||
|
TARGET ${TARGET_NAME}
|
||||||
|
PRE_BUILD
|
||||||
|
COMMAND make McuProtocol_code_check
|
||||||
|
COMMAND make McuProtocol_code_format
|
||||||
|
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
define_file_name(${TARGET_NAME})
|
60
utils/McuProtocol/include/McuProtocol.h
Normal file
60
utils/McuProtocol/include/McuProtocol.h
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
/*
|
||||||
|
* 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 MCU_PROTOCOL_H
|
||||||
|
#define MCU_PROTOCOL_H
|
||||||
|
#include "StatusCode.h"
|
||||||
|
#include <cstddef>
|
||||||
|
#include <memory>
|
||||||
|
/**
|
||||||
|
* @brief The context of protocol processing is used for the association binding of protocol data transmission and
|
||||||
|
* reception, ensuring the correct logic of protocol question and answer.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class VProtocolContext
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
VProtocolContext() = default;
|
||||||
|
virtual ~VProtocolContext() = default;
|
||||||
|
};
|
||||||
|
template <typename T>
|
||||||
|
class ProtocolContext : public VProtocolContext
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
ProtocolContext(T &value) : mData(value) {}
|
||||||
|
virtual ~ProtocolContext() = default;
|
||||||
|
|
||||||
|
public:
|
||||||
|
T mData;
|
||||||
|
};
|
||||||
|
class VProtocolBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
VProtocolBase() = default;
|
||||||
|
virtual ~VProtocolBase() = default;
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual size_t WriteData(const void *buff, const size_t buffLength) { return 0; }
|
||||||
|
|
||||||
|
public:
|
||||||
|
};
|
||||||
|
class McuProtocol : virtual public VProtocolBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
McuProtocol() = default;
|
||||||
|
virtual ~McuProtocol() = default;
|
||||||
|
const StatusCode GetIpcMissiony(std::shared_ptr<VProtocolContext> &context);
|
||||||
|
};
|
||||||
|
#endif
|
25
utils/McuProtocol/src/McuProtocol.cpp
Normal file
25
utils/McuProtocol/src/McuProtocol.cpp
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
/*
|
||||||
|
* 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 "McuProtocol.h"
|
||||||
|
#include "ProtocolHandle.h"
|
||||||
|
const StatusCode McuProtocol::GetIpcMissiony(std::shared_ptr<VProtocolContext> &context)
|
||||||
|
{
|
||||||
|
char data = 0;
|
||||||
|
std::shared_ptr<VProtocolParam> param =
|
||||||
|
std::make_shared<ProtocolParam<char>>(PROTOCOL_COMMAND::ASK_IPC_MISSION, data);
|
||||||
|
std::shared_ptr<ProtocolHandle> handle = ProtocolHandle::CreateProtocolData(param);
|
||||||
|
WriteData(handle->GetProtocolDataBuff(), handle->GetProtocolDataLength());
|
||||||
|
return CreateStatusCode(STATUS_CODE_OK);
|
||||||
|
}
|
31
utils/McuProtocol/src/ProtocolHandle.cpp
Normal file
31
utils/McuProtocol/src/ProtocolHandle.cpp
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
* 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 "ProtocolHandle.h"
|
||||||
|
constexpr unsigned short PROTOCOL_HEAD = 0xFAC1;
|
||||||
|
#pragma pack(1)
|
||||||
|
typedef struct protocol_packet
|
||||||
|
{
|
||||||
|
short mHead;
|
||||||
|
short mCommand;
|
||||||
|
short mLength;
|
||||||
|
char *mData;
|
||||||
|
short mCheckCode;
|
||||||
|
} ProtocolPacket;
|
||||||
|
#pragma pack()
|
||||||
|
std::shared_ptr<ProtocolHandle> ProtocolHandle::CreateProtocolData(const std::shared_ptr<VProtocolParam> ¶m)
|
||||||
|
{
|
||||||
|
std::shared_ptr<ProtocolHandle> handle = std::make_shared<ProtocolHandle>();
|
||||||
|
return handle;
|
||||||
|
}
|
57
utils/McuProtocol/src/ProtocolHandle.h
Normal file
57
utils/McuProtocol/src/ProtocolHandle.h
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
/*
|
||||||
|
* 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 PROTOCOL_HANDLE_H
|
||||||
|
#define PROTOCOL_HANDLE_H
|
||||||
|
#include <memory>
|
||||||
|
enum PROTOCOL_COMMAND
|
||||||
|
{
|
||||||
|
ASK_IPC_MISSION = 0x8101,
|
||||||
|
REPLY_IPC_MISSION = 0x0101,
|
||||||
|
PROTOCOL_COMMAND_END
|
||||||
|
};
|
||||||
|
class VProtocolParam
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
VProtocolParam(const PROTOCOL_COMMAND &command) : mCommand(command) {}
|
||||||
|
virtual ~VProtocolParam() = default;
|
||||||
|
const PROTOCOL_COMMAND mCommand;
|
||||||
|
};
|
||||||
|
template <typename T>
|
||||||
|
class ProtocolParam : public VProtocolParam
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
ProtocolParam(const PROTOCOL_COMMAND &command, T &value) : VProtocolParam(command), mData(value) {}
|
||||||
|
virtual ~ProtocolParam() = default;
|
||||||
|
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
* Protocol data.
|
||||||
|
*/
|
||||||
|
T mData;
|
||||||
|
};
|
||||||
|
class ProtocolHandle
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ProtocolHandle() = default;
|
||||||
|
virtual ~ProtocolHandle() = default;
|
||||||
|
virtual void *GetProtocolDataBuff(void) { return nullptr; }
|
||||||
|
virtual size_t GetProtocolDataLength(void) { return 0; }
|
||||||
|
|
||||||
|
public:
|
||||||
|
static std::shared_ptr<ProtocolHandle> CreateProtocolData(const std::shared_ptr<VProtocolParam> ¶m);
|
||||||
|
};
|
||||||
|
#endif
|
|
@ -50,7 +50,7 @@ const StatusCode IUartOpen(void *object);
|
||||||
* @param buffLength The length of data to be sent.
|
* @param buffLength The length of data to be sent.
|
||||||
* @return const size_t
|
* @return const size_t
|
||||||
*/
|
*/
|
||||||
const size_t IUartSend(void *object, const char *buff, const size_t buffLength);
|
const size_t IUartSend(void *object, const void *buff, const size_t buffLength);
|
||||||
/**
|
/**
|
||||||
* @brief Use a serial port to receive data.
|
* @brief Use a serial port to receive data.
|
||||||
*
|
*
|
||||||
|
@ -60,7 +60,7 @@ const size_t IUartSend(void *object, const char *buff, const size_t buffLength);
|
||||||
* @param timeoutMs The timeout time in milliseconds.
|
* @param timeoutMs The timeout time in milliseconds.
|
||||||
* @return const size_t
|
* @return const size_t
|
||||||
*/
|
*/
|
||||||
const size_t IUartRecv(void *object, char *buff, const size_t buffLength, const unsigned int timeoutMs);
|
const size_t IUartRecv(void *object, void *buff, const size_t buffLength, const unsigned int timeoutMs);
|
||||||
/**
|
/**
|
||||||
* @brief Clear the serial port cache data.
|
* @brief Clear the serial port cache data.
|
||||||
*
|
*
|
||||||
|
|
|
@ -29,7 +29,7 @@ const StatusCode IUartOpen(void *object)
|
||||||
}
|
}
|
||||||
return ((UartDevice *)object)->mOpen((UartDevice *)object);
|
return ((UartDevice *)object)->mOpen((UartDevice *)object);
|
||||||
}
|
}
|
||||||
const size_t IUartSend(void *object, const char *buff, const size_t buffLength)
|
const size_t IUartSend(void *object, const void *buff, const size_t buffLength)
|
||||||
{
|
{
|
||||||
if (nullptr == object) {
|
if (nullptr == object) {
|
||||||
LogError("nullptr object!\n");
|
LogError("nullptr object!\n");
|
||||||
|
@ -41,7 +41,7 @@ const size_t IUartSend(void *object, const char *buff, const size_t buffLength)
|
||||||
}
|
}
|
||||||
return ((UartDevice *)object)->mSend((UartDevice *)object, buff, buffLength);
|
return ((UartDevice *)object)->mSend((UartDevice *)object, buff, buffLength);
|
||||||
}
|
}
|
||||||
const size_t IUartRecv(void *object, char *buff, const size_t buffLength, const unsigned int timeoutMs)
|
const size_t IUartRecv(void *object, void *buff, const size_t buffLength, const unsigned int timeoutMs)
|
||||||
{
|
{
|
||||||
if (nullptr == object) {
|
if (nullptr == object) {
|
||||||
LogError("nullptr object!\n");
|
LogError("nullptr object!\n");
|
||||||
|
|
|
@ -38,7 +38,7 @@ const StatusCode UartDeviceImpl::UartOpen(void)
|
||||||
return SetConfig();
|
return SetConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
const size_t UartDeviceImpl::UartSend(const char *buff, const size_t &buffLength)
|
const size_t UartDeviceImpl::UartSend(const void *buff, const size_t &buffLength)
|
||||||
{
|
{
|
||||||
constexpr int SEND_FAILED = -1;
|
constexpr int SEND_FAILED = -1;
|
||||||
size_t writeLength = 0;
|
size_t writeLength = 0;
|
||||||
|
@ -61,7 +61,7 @@ const size_t UartDeviceImpl::UartSend(const char *buff, const size_t &buffLength
|
||||||
tcflush(mFd, TCOFLUSH);
|
tcflush(mFd, TCOFLUSH);
|
||||||
return writeTotal;
|
return writeTotal;
|
||||||
}
|
}
|
||||||
const size_t UartDeviceImpl::UartRecv(char *buff, const size_t &buffLength, const unsigned int &timeOutMs,
|
const size_t UartDeviceImpl::UartRecv(void *buff, const size_t &buffLength, const unsigned int &timeOutMs,
|
||||||
const unsigned int delayReadMs)
|
const unsigned int delayReadMs)
|
||||||
{
|
{
|
||||||
constexpr int RECV_FAILED = -1;
|
constexpr int RECV_FAILED = -1;
|
||||||
|
@ -229,12 +229,12 @@ static const StatusCode UartOpen(UartDevice *object)
|
||||||
UartDeviceImpl_S *impl = UartDeviceImplConvert(object);
|
UartDeviceImpl_S *impl = UartDeviceImplConvert(object);
|
||||||
return impl->mUartImpl->UartOpen();
|
return impl->mUartImpl->UartOpen();
|
||||||
}
|
}
|
||||||
static const size_t UartSend(UartDevice *object, const char *buff, const size_t buffLength)
|
static const size_t UartSend(UartDevice *object, const void *buff, const size_t buffLength)
|
||||||
{
|
{
|
||||||
UartDeviceImpl_S *impl = UartDeviceImplConvert(object);
|
UartDeviceImpl_S *impl = UartDeviceImplConvert(object);
|
||||||
return impl->mUartImpl->UartSend(buff, buffLength);
|
return impl->mUartImpl->UartSend(buff, buffLength);
|
||||||
}
|
}
|
||||||
static const size_t UartRecv(UartDevice *object, char *buff, const size_t buffLength, const unsigned int timeoutMs)
|
static const size_t UartRecv(UartDevice *object, void *buff, const size_t buffLength, const unsigned int timeoutMs)
|
||||||
{
|
{
|
||||||
UartDeviceImpl_S *impl = UartDeviceImplConvert(object);
|
UartDeviceImpl_S *impl = UartDeviceImplConvert(object);
|
||||||
constexpr int READ_NOT_DELAY = 0;
|
constexpr int READ_NOT_DELAY = 0;
|
||||||
|
|
|
@ -29,8 +29,8 @@ public:
|
||||||
UartDeviceImpl(const UartInfo &uatrInfo);
|
UartDeviceImpl(const UartInfo &uatrInfo);
|
||||||
virtual ~UartDeviceImpl() = default;
|
virtual ~UartDeviceImpl() = default;
|
||||||
const StatusCode UartOpen(void);
|
const StatusCode UartOpen(void);
|
||||||
const size_t UartSend(const char *buff, const size_t &buffLength);
|
const size_t UartSend(const void *buff, const size_t &buffLength);
|
||||||
const size_t UartRecv(char *buff, const size_t &buffLength, const unsigned int &timeOutMs = 0,
|
const size_t UartRecv(void *buff, const size_t &buffLength, const unsigned int &timeOutMs = 0,
|
||||||
const unsigned int delayReadMs = 0);
|
const unsigned int delayReadMs = 0);
|
||||||
void UartTcflush(void);
|
void UartTcflush(void);
|
||||||
|
|
||||||
|
@ -45,8 +45,8 @@ typedef struct uart_device UartDevice;
|
||||||
typedef struct uart_device
|
typedef struct uart_device
|
||||||
{
|
{
|
||||||
const StatusCode (*mOpen)(UartDevice *);
|
const StatusCode (*mOpen)(UartDevice *);
|
||||||
const size_t (*mSend)(UartDevice *, const char *, const size_t);
|
const size_t (*mSend)(UartDevice *, const void *, const size_t);
|
||||||
const size_t (*mRecv)(UartDevice *, char *, const size_t, const unsigned int);
|
const size_t (*mRecv)(UartDevice *, void *, const size_t, const unsigned int);
|
||||||
void (*mTcflush)(UartDevice *);
|
void (*mTcflush)(UartDevice *);
|
||||||
void (*mFree)(void *);
|
void (*mFree)(void *);
|
||||||
} UartDevice;
|
} UartDevice;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user