Improve:McuManager TestTool code.
This commit is contained in:
parent
92a62a1db6
commit
40310496e9
|
@ -17,6 +17,7 @@
|
||||||
#include "StatusCode.h"
|
#include "StatusCode.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
bool CreateMcuManager(void);
|
bool CreateMcuManager(void);
|
||||||
|
bool DestroyMcuManager(void);
|
||||||
enum class IpcMission
|
enum class IpcMission
|
||||||
{
|
{
|
||||||
TEST = 0,
|
TEST = 0,
|
||||||
|
@ -84,5 +85,9 @@ public:
|
||||||
{
|
{
|
||||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||||
}
|
}
|
||||||
|
virtual const StatusCode FeedWatchDog(std::shared_ptr<VMcuAsk> &ask)
|
||||||
|
{
|
||||||
|
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
|
@ -206,7 +206,7 @@ void McuDevice::DeleteMcuAsk(std::shared_ptr<VMcuAsk> &ask)
|
||||||
std::lock_guard<std::mutex> locker(mMutex);
|
std::lock_guard<std::mutex> locker(mMutex);
|
||||||
auto searchMcuAsk = [&ask](std::shared_ptr<VMcuAsk> &askList) -> bool {
|
auto searchMcuAsk = [&ask](std::shared_ptr<VMcuAsk> &askList) -> bool {
|
||||||
if (ask->mSerialNumber == askList->mSerialNumber) {
|
if (ask->mSerialNumber == askList->mSerialNumber) {
|
||||||
// LogInfo("DeleteMcuAsk mSerialNumber = %d\n", askList->mSerialNumber);
|
LogInfo("DeleteMcuAsk mSerialNumber = %d\n", askList->mSerialNumber);
|
||||||
return REMOVE_THE_ASK;
|
return REMOVE_THE_ASK;
|
||||||
}
|
}
|
||||||
return KEEP_THE_ASK;
|
return KEEP_THE_ASK;
|
||||||
|
|
|
@ -29,12 +29,15 @@ const StatusCode McuManagerImpl::UnInit(void)
|
||||||
const StatusCode McuManagerImpl::GetIpcMission(std::shared_ptr<VMcuAsk> &ask)
|
const StatusCode McuManagerImpl::GetIpcMission(std::shared_ptr<VMcuAsk> &ask)
|
||||||
{
|
{
|
||||||
std::shared_ptr<VProtocolContext> context = std::make_shared<ProtocolContext<std::shared_ptr<VMcuAsk>>>(ask);
|
std::shared_ptr<VProtocolContext> context = std::make_shared<ProtocolContext<std::shared_ptr<VMcuAsk>>>(ask);
|
||||||
McuProtocol::GetIpcMission(context);
|
return McuProtocol::GetIpcMission(context);
|
||||||
return CreateStatusCode(STATUS_CODE_OK);
|
|
||||||
}
|
}
|
||||||
const StatusCode McuManagerImpl::CutOffPowerSupply(std::shared_ptr<VMcuAsk> &ask)
|
const StatusCode McuManagerImpl::CutOffPowerSupply(std::shared_ptr<VMcuAsk> &ask)
|
||||||
{
|
{
|
||||||
std::shared_ptr<VProtocolContext> context = std::make_shared<ProtocolContext<std::shared_ptr<VMcuAsk>>>(ask);
|
std::shared_ptr<VProtocolContext> context = std::make_shared<ProtocolContext<std::shared_ptr<VMcuAsk>>>(ask);
|
||||||
McuProtocol::CutOffPowerSupply(context);
|
return McuProtocol::CutOffPowerSupply(context);
|
||||||
return CreateStatusCode(STATUS_CODE_OK);
|
}
|
||||||
|
const StatusCode McuManagerImpl::FeedWatchDog(std::shared_ptr<VMcuAsk> &ask)
|
||||||
|
{
|
||||||
|
std::shared_ptr<VProtocolContext> context = std::make_shared<ProtocolContext<std::shared_ptr<VMcuAsk>>>(ask);
|
||||||
|
return McuProtocol::FeedWatchDog(context);
|
||||||
}
|
}
|
|
@ -27,5 +27,6 @@ public:
|
||||||
const StatusCode UnInit(void) override;
|
const StatusCode UnInit(void) override;
|
||||||
const StatusCode GetIpcMission(std::shared_ptr<VMcuAsk> &ask) override;
|
const StatusCode GetIpcMission(std::shared_ptr<VMcuAsk> &ask) override;
|
||||||
const StatusCode CutOffPowerSupply(std::shared_ptr<VMcuAsk> &ask) override;
|
const StatusCode CutOffPowerSupply(std::shared_ptr<VMcuAsk> &ask) override;
|
||||||
|
const StatusCode FeedWatchDog(std::shared_ptr<VMcuAsk> &ask) override;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
|
@ -26,6 +26,12 @@ bool CreateMcuManager(void)
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
bool DestroyMcuManager(void)
|
||||||
|
{
|
||||||
|
auto instance = std::make_shared<IMcuManager>();
|
||||||
|
IMcuManager::GetInstance(&instance);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
std::shared_ptr<McuManagerMakePtr> &McuManagerMakePtr::GetInstance(std::shared_ptr<McuManagerMakePtr> *impl)
|
std::shared_ptr<McuManagerMakePtr> &McuManagerMakePtr::GetInstance(std::shared_ptr<McuManagerMakePtr> *impl)
|
||||||
{
|
{
|
||||||
static auto instance = std::make_shared<McuManagerMakePtr>();
|
static auto instance = std::make_shared<McuManagerMakePtr>();
|
||||||
|
|
|
@ -9,7 +9,9 @@ include_directories(
|
||||||
${UTILS_SOURCE_PATH}/Log/include
|
${UTILS_SOURCE_PATH}/Log/include
|
||||||
${UTILS_SOURCE_PATH}/StatusCode/include
|
${UTILS_SOURCE_PATH}/StatusCode/include
|
||||||
${UTILS_SOURCE_PATH}/UartDevice/include
|
${UTILS_SOURCE_PATH}/UartDevice/include
|
||||||
|
${UTILS_SOURCE_PATH}/McuProtocol/include
|
||||||
${MIDDLEWARE_SOURCE_PATH}/McuManager/include
|
${MIDDLEWARE_SOURCE_PATH}/McuManager/include
|
||||||
|
${MIDDLEWARE_SOURCE_PATH}/McuManager/src
|
||||||
${MIDDLEWARE_SOURCE_PATH}/McuAskBase/include
|
${MIDDLEWARE_SOURCE_PATH}/McuAskBase/include
|
||||||
${TEST_SOURCE_PATH}/utils/LinuxApiMock/include
|
${TEST_SOURCE_PATH}/utils/LinuxApiMock/include
|
||||||
${TEST_SOURCE_PATH}/utils/UartDevice/tool/include
|
${TEST_SOURCE_PATH}/utils/UartDevice/tool/include
|
||||||
|
|
|
@ -17,7 +17,6 @@ public:
|
||||||
static void SetUpTestCase()
|
static void SetUpTestCase()
|
||||||
{
|
{
|
||||||
CreateLogModule();
|
CreateLogModule();
|
||||||
CreateMcuManager();
|
|
||||||
ILogInit(LOG_INSTANCE_TYPE_END);
|
ILogInit(LOG_INSTANCE_TYPE_END);
|
||||||
}
|
}
|
||||||
static void TearDownTestCase() { ILogUnInit(); }
|
static void TearDownTestCase() { ILogUnInit(); }
|
||||||
|
@ -28,6 +27,7 @@ public:
|
||||||
LinuxApiMock::GetInstance(&test);
|
LinuxApiMock::GetInstance(&test);
|
||||||
LinuxApiMock::GetInstance()->Init();
|
LinuxApiMock::GetInstance()->Init();
|
||||||
McuManagerTestTool::Init(mLinuxTest);
|
McuManagerTestTool::Init(mLinuxTest);
|
||||||
|
CreateMcuManager();
|
||||||
}
|
}
|
||||||
virtual void TearDown()
|
virtual void TearDown()
|
||||||
{
|
{
|
||||||
|
@ -36,6 +36,7 @@ public:
|
||||||
std::shared_ptr<LinuxApiMock> test = std::make_shared<LinuxApiMock>();
|
std::shared_ptr<LinuxApiMock> test = std::make_shared<LinuxApiMock>();
|
||||||
LinuxApiMock::GetInstance(&test);
|
LinuxApiMock::GetInstance(&test);
|
||||||
McuManagerTestTool::UnInit();
|
McuManagerTestTool::UnInit();
|
||||||
|
DestroyMcuManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -164,7 +165,7 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_GetIpcMission)
|
||||||
testTool->McuAskDefaultFeatures(testTool);
|
testTool->McuAskDefaultFeatures(testTool);
|
||||||
IMcuManager::GetInstance()->GetIpcMission(ask);
|
IMcuManager::GetInstance()->GetIpcMission(ask);
|
||||||
constexpr int NO_USER_USING_AFTER_ASK = 2; // ask and testTool
|
constexpr int NO_USER_USING_AFTER_ASK = 2; // ask and testTool
|
||||||
EXPECT_EQ(ask.use_count(), NO_USER_USING_AFTER_ASK);
|
EXPECT_EQ(ask.use_count(), NO_USER_USING_AFTER_ASK); // TODO: neet to improve.
|
||||||
IMcuManager::GetInstance()->UnInit();
|
IMcuManager::GetInstance()->UnInit();
|
||||||
}
|
}
|
||||||
// ../output_files/test/bin/McuManagerTest
|
// ../output_files/test/bin/McuManagerTest
|
||||||
|
|
|
@ -7,6 +7,8 @@ include_directories(
|
||||||
./include
|
./include
|
||||||
${UTILS_SOURCE_PATH}/StatusCode/include
|
${UTILS_SOURCE_PATH}/StatusCode/include
|
||||||
${UTILS_SOURCE_PATH}/Log/include
|
${UTILS_SOURCE_PATH}/Log/include
|
||||||
|
${UTILS_SOURCE_PATH}/McuProtocol/include
|
||||||
|
${MIDDLEWARE_SOURCE_PATH}/McuManager/src
|
||||||
${TEST_SOURCE_PATH}/utils/LinuxApiMock/include
|
${TEST_SOURCE_PATH}/utils/LinuxApiMock/include
|
||||||
${TEST_SOURCE_PATH}/utils/McuProtocol/tool/include
|
${TEST_SOURCE_PATH}/utils/McuProtocol/tool/include
|
||||||
)
|
)
|
||||||
|
|
|
@ -15,7 +15,46 @@
|
||||||
#ifndef MCU_MANAGER_TEST_TOOL_H
|
#ifndef MCU_MANAGER_TEST_TOOL_H
|
||||||
#define MCU_MANAGER_TEST_TOOL_H
|
#define MCU_MANAGER_TEST_TOOL_H
|
||||||
#include "LinuxApiMock.h"
|
#include "LinuxApiMock.h"
|
||||||
|
#include "McuManagerImpl.h"
|
||||||
#include "McuProtocolTestTool.h"
|
#include "McuProtocolTestTool.h"
|
||||||
|
#include <gmock/gmock.h>
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
using ::testing::_;
|
||||||
|
using ::testing::Action;
|
||||||
|
using ::testing::ActionInterface;
|
||||||
|
using ::testing::AnyNumber;
|
||||||
|
using ::testing::Assign;
|
||||||
|
using ::testing::AtLeast;
|
||||||
|
using ::testing::ByMove;
|
||||||
|
using ::testing::ByRef;
|
||||||
|
using ::testing::DefaultValue;
|
||||||
|
using ::testing::DoAll;
|
||||||
|
using ::testing::DoDefault;
|
||||||
|
using ::testing::IgnoreResult;
|
||||||
|
using ::testing::Invoke;
|
||||||
|
using ::testing::InvokeWithoutArgs;
|
||||||
|
using ::testing::MakePolymorphicAction;
|
||||||
|
using ::testing::PolymorphicAction;
|
||||||
|
using ::testing::Return;
|
||||||
|
using ::testing::ReturnNew;
|
||||||
|
using ::testing::ReturnNull;
|
||||||
|
using ::testing::ReturnPointee;
|
||||||
|
using ::testing::ReturnRef;
|
||||||
|
using ::testing::ReturnRefOfCopy;
|
||||||
|
using ::testing::ReturnRoundRobin;
|
||||||
|
using ::testing::SaveArg;
|
||||||
|
using ::testing::SetArgPointee;
|
||||||
|
using ::testing::SetArgumentPointee;
|
||||||
|
using ::testing::Unused;
|
||||||
|
using ::testing::WithArgs;
|
||||||
|
using ::testing::internal::BuiltInDefaultValue;
|
||||||
|
class McuManagerImplTest : public McuManagerImpl
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
McuManagerImplTest() = default;
|
||||||
|
virtual ~McuManagerImplTest() = default;
|
||||||
|
MOCK_METHOD1(DeleteMcuAsk, void(std::shared_ptr<VMcuAsk> &));
|
||||||
|
};
|
||||||
class McuManagerTestTool : virtual public McuProtocolTestTool
|
class McuManagerTestTool : virtual public McuProtocolTestTool
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -23,5 +62,8 @@ public:
|
||||||
virtual ~McuManagerTestTool() = default;
|
virtual ~McuManagerTestTool() = default;
|
||||||
void Init(std::shared_ptr<LinuxTest> &mock);
|
void Init(std::shared_ptr<LinuxTest> &mock);
|
||||||
void UnInit(void);
|
void UnInit(void);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::shared_ptr<McuManagerImplTest> mMcuManagerMock;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
* 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 "McuManagerMakePtrTest.h"
|
||||||
|
#include "ILog.h"
|
||||||
|
#include "McuManagerTestTool.h"
|
||||||
|
void OverrideMcuManagerMakePtrObject(void)
|
||||||
|
{
|
||||||
|
std::shared_ptr<McuManagerMakePtr> impl = std::make_shared<McuManagerMakePtrTest>();
|
||||||
|
McuManagerMakePtr::GetInstance(&impl);
|
||||||
|
}
|
||||||
|
McuManagerMakePtrTest::McuManagerMakePtrTest()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
McuManagerMakePtrTest::~McuManagerMakePtrTest()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
mMcuManagerMock.reset();
|
||||||
|
}
|
||||||
|
const StatusCode McuManagerMakePtrTest::CreateMcuManager(std::shared_ptr<IMcuManager> &impl)
|
||||||
|
{
|
||||||
|
if (mMcuManagerMock) {
|
||||||
|
impl = mMcuManagerMock;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LogWarning("CreateMcuManager failed:mMcuManagerMock is nullptr.\n");
|
||||||
|
}
|
||||||
|
return CreateStatusCode(STATUS_CODE_OK);
|
||||||
|
}
|
31
test/middleware/McuManager/tool/src/McuManagerMakePtrTest.h
Normal file
31
test/middleware/McuManager/tool/src/McuManagerMakePtrTest.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_MANAGER_MAKE_PTR_TEST_H
|
||||||
|
#define MCU_MANAGER_MAKE_PTR_TEST_H
|
||||||
|
#include "McuManagerMakePtr.h"
|
||||||
|
#include "McuManagerTestTool.h"
|
||||||
|
void OverrideMcuManagerMakePtrObject(void);
|
||||||
|
class McuManagerMakePtrTest : public McuManagerMakePtr
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
McuManagerMakePtrTest();
|
||||||
|
virtual ~McuManagerMakePtrTest();
|
||||||
|
const StatusCode CreateMcuManager(std::shared_ptr<IMcuManager> &impl) override;
|
||||||
|
|
||||||
|
public:
|
||||||
|
public:
|
||||||
|
std::shared_ptr<McuManagerImplTest> mMcuManagerMock;
|
||||||
|
};
|
||||||
|
#endif
|
|
@ -14,6 +14,7 @@
|
||||||
*/
|
*/
|
||||||
#include "McuManagerTestTool.h"
|
#include "McuManagerTestTool.h"
|
||||||
#include "ILog.h"
|
#include "ILog.h"
|
||||||
|
#include "McuManagerMakePtrTest.h"
|
||||||
extern const char *MCU_UART_DEVICE_PTR;
|
extern const char *MCU_UART_DEVICE_PTR;
|
||||||
static UartInfo gUartDevice = {
|
static UartInfo gUartDevice = {
|
||||||
MCU_UART_DEVICE_PTR,
|
MCU_UART_DEVICE_PTR,
|
||||||
|
@ -26,11 +27,26 @@ static UartInfo gUartDevice = {
|
||||||
void McuManagerTestTool::Init(std::shared_ptr<LinuxTest> &mock)
|
void McuManagerTestTool::Init(std::shared_ptr<LinuxTest> &mock)
|
||||||
{
|
{
|
||||||
LogInfo("McuManagerTestTool::Init\n");
|
LogInfo("McuManagerTestTool::Init\n");
|
||||||
|
mMcuManagerMock = std::make_shared<McuManagerImplTest>();
|
||||||
|
EXPECT_CALL(*mMcuManagerMock.get(), DeleteMcuAsk(_)).Times(500);
|
||||||
|
OverrideMcuManagerMakePtrObject();
|
||||||
|
std::shared_ptr<McuManagerMakePtr> tmp = McuManagerMakePtr::GetInstance();
|
||||||
|
std::shared_ptr<McuManagerMakePtrTest> test = std::dynamic_pointer_cast<McuManagerMakePtrTest>(tmp);
|
||||||
|
if (test) {
|
||||||
|
test->mMcuManagerMock = mMcuManagerMock;
|
||||||
|
}
|
||||||
UartDeviceTestTool::RegisterUartDevice(mock, gUartDevice);
|
UartDeviceTestTool::RegisterUartDevice(mock, gUartDevice);
|
||||||
McuProtocolTestTool::Init(mock, gUartDevice);
|
McuProtocolTestTool::Init(mock, gUartDevice);
|
||||||
}
|
}
|
||||||
void McuManagerTestTool::UnInit(void)
|
void McuManagerTestTool::UnInit(void)
|
||||||
{
|
{
|
||||||
//
|
mMcuManagerMock.reset();
|
||||||
|
std::shared_ptr<McuManagerMakePtr> tmp = McuManagerMakePtr::GetInstance();
|
||||||
|
std::shared_ptr<McuManagerMakePtrTest> test = std::dynamic_pointer_cast<McuManagerMakePtrTest>(tmp);
|
||||||
|
if (test) {
|
||||||
|
test->mMcuManagerMock.reset();
|
||||||
|
}
|
||||||
|
std::shared_ptr<McuManagerMakePtr> impl = std::make_shared<McuManagerMakePtr>();
|
||||||
|
McuManagerMakePtr::GetInstance(&impl);
|
||||||
UartDeviceTestTool::UnregisterUartDevice(gUartDevice);
|
UartDeviceTestTool::UnregisterUartDevice(gUartDevice);
|
||||||
}
|
}
|
|
@ -92,6 +92,7 @@ public:
|
||||||
const StatusCode UnInit(void);
|
const StatusCode UnInit(void);
|
||||||
const StatusCode GetIpcMission(std::shared_ptr<VProtocolContext> &context);
|
const StatusCode GetIpcMission(std::shared_ptr<VProtocolContext> &context);
|
||||||
const StatusCode CutOffPowerSupply(std::shared_ptr<VProtocolContext> &context);
|
const StatusCode CutOffPowerSupply(std::shared_ptr<VProtocolContext> &context);
|
||||||
|
const StatusCode FeedWatchDog(std::shared_ptr<VProtocolContext> &context);
|
||||||
void DataHandleThread(void);
|
void DataHandleThread(void);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -33,6 +33,7 @@ void LittleEndianHandle::BigEndianConversion(ProtocolPacket &packet)
|
||||||
packet.mCheckCode = htons(packet.mCheckCode);
|
packet.mCheckCode = htons(packet.mCheckCode);
|
||||||
packet.mSerialNumber = htonl(packet.mSerialNumber);
|
packet.mSerialNumber = htonl(packet.mSerialNumber);
|
||||||
}
|
}
|
||||||
|
short LittleEndianHandle::BigEndianConversion(const short &number) { return htons(number); }
|
||||||
void LittleEndianHandle::HostByteOrderConversion(ProtocolPacket &packet)
|
void LittleEndianHandle::HostByteOrderConversion(ProtocolPacket &packet)
|
||||||
{
|
{
|
||||||
packet.mHead = ntohs(packet.mHead);
|
packet.mHead = ntohs(packet.mHead);
|
||||||
|
|
|
@ -24,6 +24,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void BigEndianConversion(ProtocolPacket &packet) override;
|
void BigEndianConversion(ProtocolPacket &packet) override;
|
||||||
|
short BigEndianConversion(const short &number) override;
|
||||||
void HostByteOrderConversion(ProtocolPacket &packet) override;
|
void HostByteOrderConversion(ProtocolPacket &packet) override;
|
||||||
bool CheckoutTheCheckCode(const ProtocolPacket &packet) override;
|
bool CheckoutTheCheckCode(const ProtocolPacket &packet) override;
|
||||||
};
|
};
|
||||||
|
|
|
@ -48,6 +48,8 @@ const StatusCode McuProtocol::UnInit(void)
|
||||||
if (mDataHandleThread.joinable()) {
|
if (mDataHandleThread.joinable()) {
|
||||||
mDataHandleThread.join();
|
mDataHandleThread.join();
|
||||||
}
|
}
|
||||||
|
std::shared_ptr<VProtocolRecv> reply = std::make_shared<VProtocolRecv>();
|
||||||
|
VProtocolRecv::GetInstance(&reply);
|
||||||
sem_destroy(&mSem);
|
sem_destroy(&mSem);
|
||||||
return CreateStatusCode(STATUS_CODE_OK);
|
return CreateStatusCode(STATUS_CODE_OK);
|
||||||
}
|
}
|
||||||
|
@ -66,6 +68,13 @@ const StatusCode McuProtocol::CutOffPowerSupply(std::shared_ptr<VProtocolContext
|
||||||
return WriteProtocolData(
|
return WriteProtocolData(
|
||||||
handle->GetProtocolDataBuff(), handle->GetProtocolDataLength(), context, handle->GetSerialNumber());
|
handle->GetProtocolDataBuff(), handle->GetProtocolDataLength(), context, handle->GetSerialNumber());
|
||||||
}
|
}
|
||||||
|
const StatusCode McuProtocol::FeedWatchDog(std::shared_ptr<VProtocolContext> &context)
|
||||||
|
{
|
||||||
|
std::shared_ptr<VProtocolParam> param = std::make_shared<VProtocolParam>(PROTOCOL_COMMAND::ASK_FEED_WATCH_DOG);
|
||||||
|
std::shared_ptr<ProtocolHandle> handle = ProtocolHandle::CreateProtocolData(param);
|
||||||
|
return WriteProtocolData(
|
||||||
|
handle->GetProtocolDataBuff(), handle->GetProtocolDataLength(), context, handle->GetSerialNumber());
|
||||||
|
}
|
||||||
void McuProtocol::DataHandleThread(void)
|
void McuProtocol::DataHandleThread(void)
|
||||||
{
|
{
|
||||||
mThreadRuning = true;
|
mThreadRuning = true;
|
||||||
|
|
|
@ -81,7 +81,7 @@ void ProtocolHandle::MakeNoUserDataPacket(const std::shared_ptr<VProtocolParam>
|
||||||
BigEndianConversion(packet);
|
BigEndianConversion(packet);
|
||||||
memcpy(mProtocolData, &packet, KEY_HEAD_LENGTH);
|
memcpy(mProtocolData, &packet, KEY_HEAD_LENGTH);
|
||||||
packet.mCheckCode = calculate_check_sum(mProtocolData, dataLength - sizeof(short));
|
packet.mCheckCode = calculate_check_sum(mProtocolData, dataLength - sizeof(short));
|
||||||
packet.mCheckCode = htons(packet.mCheckCode);
|
packet.mCheckCode = BigEndianConversion(packet.mCheckCode);
|
||||||
memcpy(mProtocolData + KEY_HEAD_LENGTH, &packet.mCheckCode, sizeof(short));
|
memcpy(mProtocolData + KEY_HEAD_LENGTH, &packet.mCheckCode, sizeof(short));
|
||||||
mProtocolDataLength = dataLength;
|
mProtocolDataLength = dataLength;
|
||||||
}
|
}
|
||||||
|
@ -93,6 +93,10 @@ void ProtocolHandle::MakeAskCutOffPowerSupplyPacket(const std::shared_ptr<VProto
|
||||||
{
|
{
|
||||||
MakeNoUserDataPacket(param);
|
MakeNoUserDataPacket(param);
|
||||||
}
|
}
|
||||||
|
void ProtocolHandle::MakeAskFeedWatchDogPacket(const std::shared_ptr<VProtocolParam> ¶m)
|
||||||
|
{
|
||||||
|
MakeNoUserDataPacket(param);
|
||||||
|
}
|
||||||
void ProtocolHandle::AnalyzeProtocolPacket(void)
|
void ProtocolHandle::AnalyzeProtocolPacket(void)
|
||||||
{
|
{
|
||||||
ProtocolPacket packet = {0};
|
ProtocolPacket packet = {0};
|
||||||
|
|
|
@ -36,6 +36,7 @@ enum PROTOCOL_COMMAND
|
||||||
ASK_IPC_MISSION = 0x8101,
|
ASK_IPC_MISSION = 0x8101,
|
||||||
REPLY_IPC_MISSION = 0x0101,
|
REPLY_IPC_MISSION = 0x0101,
|
||||||
ASK_CUT_OFF_PWOER_SUPPLY = 0x8102,
|
ASK_CUT_OFF_PWOER_SUPPLY = 0x8102,
|
||||||
|
ASK_FEED_WATCH_DOG = 0x8103,
|
||||||
PROTOCOL_COMMAND_END
|
PROTOCOL_COMMAND_END
|
||||||
};
|
};
|
||||||
class VProtocolParam
|
class VProtocolParam
|
||||||
|
@ -62,6 +63,10 @@ public:
|
||||||
};
|
};
|
||||||
using MakePacketFunc = std::function<void(const std::shared_ptr<VProtocolParam> &)>;
|
using MakePacketFunc = std::function<void(const std::shared_ptr<VProtocolParam> &)>;
|
||||||
using AnalyzePacketFunc = std::function<void(const ProtocolPacket &)>;
|
using AnalyzePacketFunc = std::function<void(const ProtocolPacket &)>;
|
||||||
|
/**
|
||||||
|
* @brief Protocol processing classes need to focus on data size issues, and ProtocolHandle defaults to handling large
|
||||||
|
* end data.
|
||||||
|
*/
|
||||||
class ProtocolHandle
|
class ProtocolHandle
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -81,6 +86,7 @@ private:
|
||||||
void MakeNoUserDataPacket(const std::shared_ptr<VProtocolParam> ¶m);
|
void MakeNoUserDataPacket(const std::shared_ptr<VProtocolParam> ¶m);
|
||||||
void MakeAskIpcMissionPacket(const std::shared_ptr<VProtocolParam> ¶m);
|
void MakeAskIpcMissionPacket(const std::shared_ptr<VProtocolParam> ¶m);
|
||||||
void MakeAskCutOffPowerSupplyPacket(const std::shared_ptr<VProtocolParam> ¶m);
|
void MakeAskCutOffPowerSupplyPacket(const std::shared_ptr<VProtocolParam> ¶m);
|
||||||
|
void MakeAskFeedWatchDogPacket(const std::shared_ptr<VProtocolParam> ¶m);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief These function implementations parse the received frame by frame continuous data into the data required by
|
* @brief These function implementations parse the received frame by frame continuous data into the data required by
|
||||||
|
@ -92,6 +98,7 @@ private:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void BigEndianConversion(ProtocolPacket &packet) {}
|
virtual void BigEndianConversion(ProtocolPacket &packet) {}
|
||||||
|
virtual short BigEndianConversion(const short &number) { return number; }
|
||||||
virtual void HostByteOrderConversion(ProtocolPacket &packet) {}
|
virtual void HostByteOrderConversion(ProtocolPacket &packet) {}
|
||||||
virtual bool CheckoutTheCheckCode(const ProtocolPacket &packet);
|
virtual bool CheckoutTheCheckCode(const ProtocolPacket &packet);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user