diff --git a/application/MissionManager/src/MissionManagerMakePtr.cpp b/application/MissionManager/src/MissionManagerMakePtr.cpp index 5d4f839..16bfb3e 100644 --- a/application/MissionManager/src/MissionManagerMakePtr.cpp +++ b/application/MissionManager/src/MissionManagerMakePtr.cpp @@ -15,6 +15,7 @@ #include "MissionManagerMakePtr.h" #include "ILog.h" #include "MissionManager.h" +#include "OnMissionState.h" #include "SdCardHandleState.h" #include "StorageHandleState.h" #include "TestMissionState.h" @@ -63,7 +64,23 @@ std::shared_ptr MissionManagerMakePtr::CreateTopState(void) } std::shared_ptr MissionManagerMakePtr::CreateMissionState(const IpcMission &mission) { - std::shared_ptr state = std::make_shared(); + LogInfo("MissionManagerMakePtr::CreateMissionState\n"); + std::shared_ptr state; + switch (mission) { + case IpcMission::TEST: + LogInfo("Create TestMissionState.\n"); + state = std::make_shared(); + break; + case IpcMission::ON: + LogInfo("Create OnMissionState.\n"); + state = std::make_shared(); + break; + + default: + LogWarning("Unknown mission.\n"); + state = std::make_shared(); + break; + } return state; } std::shared_ptr MissionManagerMakePtr::CreateStorageHandleState(void) diff --git a/application/MissionManager/src/MissionStateMachine.cpp b/application/MissionManager/src/MissionStateMachine.cpp index eaeeed0..670d504 100644 --- a/application/MissionManager/src/MissionStateMachine.cpp +++ b/application/MissionManager/src/MissionStateMachine.cpp @@ -85,7 +85,8 @@ IpcMission MissionStateMachine::GetStartMission(void) } void MissionStateMachine::RunStateMachine(const IpcMission &mission) { - LogInfo("Make all states and start the state machine.\n"); + LogInfo("Make all states and start the state machine, ipc mission = %s.\n", + IMcuManager::GetInstance()->PrintIpcMissionString(mission)); mStateTree[SystemState::TOP_STATE] = MissionManagerMakePtr::GetInstance()->CreateTopState(); mStateTree[SystemState::MISSION_STATE] = MissionManagerMakePtr::GetInstance()->CreateMissionState(mission); mStateTree[SystemState::STORAGE_HANDLE_STATE] = MissionManagerMakePtr::GetInstance()->CreateStorageHandleState(); diff --git a/application/MissionManager/src/OnMissionState.cpp b/application/MissionManager/src/OnMissionState.cpp new file mode 100644 index 0000000..f84c44e --- /dev/null +++ b/application/MissionManager/src/OnMissionState.cpp @@ -0,0 +1,37 @@ +/* + * 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 "OnMissionState.h" +#include "ILog.h" +#include "IStorageManager.h" +#include "MissionStateMachine.h" +OnMissionState::OnMissionState() : MissionState("OnMissionState") +{ + // mEventHandle[InternalStateEvent::ANY_STATE_SD_STATUS_PERORIED] = + // std::bind(&OnMissionState::SdCardEventReportSendToApp, this, _1); +} +void OnMissionState::GoInState() +{ + MissionState::GoInState(); + LogInfo(" ========== OnMissionState::GoInState.\n"); +} +void OnMissionState::GoOutState() +{ + MissionState::GoOutState(); + LogInfo(" ========== OnMissionState::GoOutState.\n"); +} +bool OnMissionState::SdCardEventReportSendToApp(VStateMachineData *msg) +{ + return EXECUTED; +} \ No newline at end of file diff --git a/application/MissionManager/src/OnMissionState.h b/application/MissionManager/src/OnMissionState.h new file mode 100644 index 0000000..9b8e617 --- /dev/null +++ b/application/MissionManager/src/OnMissionState.h @@ -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 ON_MISSION_STATE_H +#define ON_MISSION_STATE_H +#include "IStateMachine.h" +#include "IStorageManager.h" +#include "MissionState.h" +class OnMissionState : public MissionState +{ +public: + OnMissionState(); + virtual ~OnMissionState() = default; + void GoInState() override; + void GoOutState() override; + +private: + bool SdCardEventReportSendToApp(VStateMachineData *msg); +}; +#endif \ No newline at end of file diff --git a/middleware/AppManager/README.md b/middleware/AppManager/README.md index a66981a..b9c3dee 100644 --- a/middleware/AppManager/README.md +++ b/middleware/AppManager/README.md @@ -1,5 +1,9 @@ # 1. 打猎相机APP(WiFi单机版)设计文档 +| 版本 | 时间 | 说明 | +| ---- | ---- | ---- | +| V1.0 | 2024-5-21 | 首次评审。 | + ## 1.1. 概述     打猎相机手机APP是用于查看相机的实时视频,回放保存在SD卡的MP4视频文件,以及对相机进行设置/管理。 @@ -152,3 +156,14 @@ | 时间 | 时间 | ---- | 设置时间 | | 功能 | 功能按钮 | 取消/确定 | 例如:格式化/恢复出厂/重启
可通过协议自由定义,协议带显示字符 | | 选项 | 数字 | ---- | 协议带选项对应的文字字符 | + +### 1.4.2. 动态渲染设置界面 + +1. APP获取设置参数列表,协议根据设置类型定义; +2. 设置界面根据设置类型显示设置控件; +3. 有操作后回传自定义控件信息; +4. 设备根据协议解析操作的控件,并执行自定义行为; + +### 1.4.3. 拓展规划 + +  需要考虑拓展为4G版本。 \ No newline at end of file diff --git a/middleware/McuManager/include/IMcuManager.h b/middleware/McuManager/include/IMcuManager.h index 4356bfa..eefcd83 100644 --- a/middleware/McuManager/include/IMcuManager.h +++ b/middleware/McuManager/include/IMcuManager.h @@ -21,6 +21,7 @@ bool DestroyMcuManager(void); enum class IpcMission { PIR_TRIGGERED = 0, + ON, TEST, CONTINUOUS_SHOOTING, PIR_TRIGGERED_DELAY, diff --git a/middleware/McuManager/src/McuManagerImpl.cpp b/middleware/McuManager/src/McuManagerImpl.cpp index 25c2766..a10324d 100644 --- a/middleware/McuManager/src/McuManagerImpl.cpp +++ b/middleware/McuManager/src/McuManagerImpl.cpp @@ -135,6 +135,9 @@ const char *McuManagerImpl::PrintIpcMissionString(const IpcMission &mission) case IpcMission::PIR_TRIGGERED: { return "PIR_TRIGGERED"; } + case IpcMission::ON: { + return "ON"; + } case IpcMission::TEST: { return "TEST"; } diff --git a/test/application/HuntingCamera/src_mock/McuManager_Mock_Test.cpp b/test/application/HuntingCamera/src_mock/McuManager_Mock_Test.cpp index 4e56108..14ab5aa 100644 --- a/test/application/HuntingCamera/src_mock/McuManager_Mock_Test.cpp +++ b/test/application/HuntingCamera/src_mock/McuManager_Mock_Test.cpp @@ -27,19 +27,28 @@ namespace McuManager_Mock_Test /** * @brief Construct a new test f object * ../output_files/test/bin/HuntingCameraTest - * --gtest_filter=HuntingCameraTest.INTEGRATION_HunttingCamera_EXAMPLE_UartOpenSuccessButReadNothing + * --gtest_filter=HuntingCameraTest.HS_INTEGRATION_HunttingCamera_EXAMPLE_UartOpenSuccessButReadNothing */ -TEST_F(HuntingCameraTest, INTEGRATION_HunttingCamera_EXAMPLE_UartOpenSuccessButReadNothing) +TEST_F(HuntingCameraTest, HS_INTEGRATION_HunttingCamera_EXAMPLE_UartOpenSuccessButReadNothing) { - // SetAllCamerasResult(mAllCamerasMock); - // MockReportCameraEvent("/tmp/test.MP4", CameraType::MAIN_CAMERA); - // CreateUpgradeFile(); McuManagerTestTool::MockMcuDeviceOpenSuccessButReadNothing(mLinuxTest); - // std::this_thread::sleep_for(std::chrono::milliseconds(100)); MainThread::GetInstance()->Init(); - TestManager::ResetTimeOut(1000 * 6); + TestManager::ResetTimeOut(1000 * 3); std::this_thread::sleep_for(std::chrono::milliseconds(100)); MainThread::GetInstance()->Runing(); RemoveUpgradeFile(); } +/** + * @brief Construct a new test f object + * ../output_files/test/bin/HuntingCameraTest + * --gtest_filter=HuntingCameraTest.HS_INTEGRATION_HunttingCamera_EXAMPLE_OnMissionStateStart + */ +TEST_F(HuntingCameraTest, HS_INTEGRATION_HunttingCamera_EXAMPLE_OnMissionStateStart) +{ + McuManagerTestTool::MockOtherSideIpcMissionReply(IpcMission::ON); + MainThread::GetInstance()->Init(); + TestManager::ResetTimeOut(1000 * 3); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + MainThread::GetInstance()->Runing(); +} } // namespace McuManager_Mock_Test \ No newline at end of file diff --git a/test/application/MissionManager/tool/src/MissionManagerMakePtrTest.cpp b/test/application/MissionManager/tool/src/MissionManagerMakePtrTest.cpp index e2b71c1..d52042a 100644 --- a/test/application/MissionManager/tool/src/MissionManagerMakePtrTest.cpp +++ b/test/application/MissionManager/tool/src/MissionManagerMakePtrTest.cpp @@ -14,6 +14,7 @@ */ #include "MissionManagerMakePtrTest.h" #include "ILog.h" +#include "OnMissionStateMock.h" #include "TestMissionStateMock.h" #include "TopStateMock.h" void OverrideMissionManagerMakePtrObject(std::shared_ptr &appManagerMock) @@ -51,6 +52,22 @@ std::shared_ptr MissionManagerMakePtrTest::CreateTopState(void) } std::shared_ptr MissionManagerMakePtrTest::CreateMissionState(const IpcMission &mission) { - std::shared_ptr state = std::make_shared(); + LogInfo("MissionManagerMakePtrTest::CreateMissionState\n"); + std::shared_ptr state; + switch (mission) { + case IpcMission::TEST: + LogInfo("Create TestMissionStateMock.\n"); + state = std::make_shared(); + break; + case IpcMission::ON: + LogInfo("Create OnMissionStateMock.\n"); + state = std::make_shared(); + break; + + default: + LogWarning("Unknown mission.\n"); + state = std::make_shared(); + break; + } return state; } \ No newline at end of file diff --git a/test/application/MissionManager/tool/src/OnMissionStateMock.cpp b/test/application/MissionManager/tool/src/OnMissionStateMock.cpp new file mode 100644 index 0000000..8b64a89 --- /dev/null +++ b/test/application/MissionManager/tool/src/OnMissionStateMock.cpp @@ -0,0 +1,16 @@ +/* + * 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 "OnMissionStateMock.h" +#include "ILog.h" \ No newline at end of file diff --git a/test/application/MissionManager/tool/src/OnMissionStateMock.h b/test/application/MissionManager/tool/src/OnMissionStateMock.h new file mode 100644 index 0000000..77ecbb7 --- /dev/null +++ b/test/application/MissionManager/tool/src/OnMissionStateMock.h @@ -0,0 +1,33 @@ +/* + * 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 ON_MISSION_STATE_MOCK_H +#define ON_MISSION_STATE_MOCK_H +#include "MissionManagerTestTool.h" +#include "OnMissionState.h" +class OnMissionStateTest : public OnMissionState +{ +public: + OnMissionStateTest() = default; + virtual ~OnMissionStateTest() = default; + +protected: +}; +class OnMissionStateMock : public OnMissionStateTest +{ +public: + OnMissionStateMock() = default; + virtual ~OnMissionStateMock() = default; +}; +#endif \ No newline at end of file diff --git a/test/middleware/AppManager/tool/src/AppManagerTestTool.cpp b/test/middleware/AppManager/tool/src/AppManagerTestTool.cpp index b1f5fee..bbc9d65 100644 --- a/test/middleware/AppManager/tool/src/AppManagerTestTool.cpp +++ b/test/middleware/AppManager/tool/src/AppManagerTestTool.cpp @@ -304,7 +304,7 @@ void AppManagerTestTool::AppManagerMockInit(std::shared_ptr &vMock) AppManagerTestTool::AppMonitorInit(mAppMonitorMock); }; EXPECT_CALL(*mock.get(), SetAppMonitorTrace(_)) - .Times(ONLY_BE_CALLED_ONCE) + .Times(testing::Between(0, 1)) .WillOnce(DoAll(WithArgs<0>(Invoke(getAppMonitor)), Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION)))); } std::shared_ptr AppManagerTestTool::MakeMonitorMock(void) diff --git a/test/middleware/McuManager/src_mock/McuManager_AbnormalData_Test.cpp b/test/middleware/McuManager/src_mock/McuManager_AbnormalData_Test.cpp index c605366..e47e98f 100644 --- a/test/middleware/McuManager/src_mock/McuManager_AbnormalData_Test.cpp +++ b/test/middleware/McuManager/src_mock/McuManager_AbnormalData_Test.cpp @@ -24,6 +24,8 @@ const unsigned char McuRecvData[] = { 0x41, 0x07, 0x00, 0x0C, 0x35, 0x88, 0xFA, 0xC1, 0x00, 0x00, 0xFA, 0xC1, 0x00, 0x00, 0x00, 0x0A}; const unsigned char McuSendData_GetDateTime[] = { 0xFA, 0xC1, 0x00, 0x00, 0x00, 0x0A, 0x41, 0x07, 0x00, 0x0C, 0x35, 0x88}; +const unsigned char McuSendData_OtherSideReplyGetIpcMission[] = { + 0xFA, 0xC1, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x0D, 0x03, 0x09, 0xBA}; namespace McuManager_AbnormalData_Test { /** @@ -52,4 +54,18 @@ TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_EXAMPLE_OtherSideGetDateTim std::this_thread::sleep_for(std::chrono::milliseconds(1000)); IMcuManager::GetInstance()->UnInit(); } +/** + * @brief Construct a new test f object + * ../output_files/test/bin/McuManagerTest + * --gtest_filter=McuManagerMockTest.HS_INTEGRATION_McuManager_EXAMPLE_OtherSideReplyGetIpcMission + */ +TEST_F(McuManagerMockTest, HS_INTEGRATION_McuManager_EXAMPLE_OtherSideReplyGetIpcMission) +{ + IMcuManager::GetInstance()->Init(); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + McuManagerTestTool::MockOtherSideSendData( + mLinuxTest, McuSendData_OtherSideReplyGetIpcMission, sizeof(McuSendData_OtherSideReplyGetIpcMission)); + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + IMcuManager::GetInstance()->UnInit(); +} } // namespace McuManager_AbnormalData_Test \ No newline at end of file diff --git a/test/middleware/McuManager/tool/include/McuManagerTestTool.h b/test/middleware/McuManager/tool/include/McuManagerTestTool.h index ac2e9b5..d1edb25 100644 --- a/test/middleware/McuManager/tool/include/McuManagerTestTool.h +++ b/test/middleware/McuManager/tool/include/McuManagerTestTool.h @@ -44,6 +44,7 @@ protected: void MockOtherSideSendData(std::shared_ptr &mock, const void *data, const size_t &size); void MockMcuDeviceOpenFailed(std::shared_ptr &mock); void MockMcuDeviceOpenSuccessButReadNothing(std::shared_ptr &mock); + void MockOtherSideIpcMissionReply(const IpcMission &replyIpcMission); private: std::shared_ptr mMcuManagerMock; diff --git a/test/middleware/McuManager/tool/src/McuManagerTestTool.cpp b/test/middleware/McuManager/tool/src/McuManagerTestTool.cpp index d23cd21..fd44113 100644 --- a/test/middleware/McuManager/tool/src/McuManagerTestTool.cpp +++ b/test/middleware/McuManager/tool/src/McuManagerTestTool.cpp @@ -77,4 +77,9 @@ void McuManagerTestTool::MockMcuDeviceOpenFailed(std::shared_ptr &moc void McuManagerTestTool::MockMcuDeviceOpenSuccessButReadNothing(std::shared_ptr &mock) { McuProtocolTestTool::ReadNothingAnyTime(mock); +} +void McuManagerTestTool::MockOtherSideIpcMissionReply(const IpcMission &replyIpcMission) +{ + unsigned char reply = static_cast(replyIpcMission); + McuProtocolTestTool::MockOtherSideIpcMissionReply(reply); } \ No newline at end of file diff --git a/test/utils/McuProtocol/tool/include/McuProtocolTestTool.h b/test/utils/McuProtocol/tool/include/McuProtocolTestTool.h index 36c04cc..6803e75 100644 --- a/test/utils/McuProtocol/tool/include/McuProtocolTestTool.h +++ b/test/utils/McuProtocol/tool/include/McuProtocolTestTool.h @@ -39,8 +39,10 @@ public: void MockOtherSideAskSendAnyData(std::shared_ptr &mock, const void *data, const size_t &size); void ReadNothingAnyTime(std::shared_ptr &mock); void ReadOnceSelectSucceed(std::shared_ptr &mock, const int &uartFd); + void MockOtherSideIpcMissionReply(const unsigned char &replyIpcMission); private: + void InitProtocolBuff(void); void CheckSerialNumber(const void *buf, const size_t &count); void ChecCRC16Code(const void *buf, const size_t &count); void ResetCheckCode(const void *buf, const size_t &count); diff --git a/test/utils/McuProtocol/tool/src/McuProtocolTestTool.cpp b/test/utils/McuProtocol/tool/src/McuProtocolTestTool.cpp index a69aa9c..16cb847 100644 --- a/test/utils/McuProtocol/tool/src/McuProtocolTestTool.cpp +++ b/test/utils/McuProtocol/tool/src/McuProtocolTestTool.cpp @@ -39,6 +39,7 @@ constexpr size_t PROTOCOL_DATA_LENGTH_OFFSET = PROTOCOL_COMMAND_OFFSET + PROTOCO constexpr size_t PROTOCOL_CHECK_CODE_LENGTH = sizeof(short); constexpr size_t PROTOCOL_DATA_KEY_HEAD_LENGTH = PROTOCOL_HEAD_LENGTH + PROTOCOL_SERIAL_NUMBER_LENGTH + PROTOCOL_COMMAND_LENGTH + PROTOCOL_DATA_LENGTH_LENGTH; +constexpr size_t PROTOCOL_DATA_OFFSET = PROTOCOL_DATA_KEY_HEAD_LENGTH; unsigned char ASK_IPC_MISSION_X[] = {0xFA, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x81, 0x01, 0x00, 0x0C, 0xFF, 0xFF}; unsigned char REPLY_IPC_MISSION_X[] = {0xFA, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x0D, 0x01, 0xFF, 0xFF}; unsigned char ASK_CUT_OFF_POWER_SUPPLY_X[] = {0xFA, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x81, 0x02, 0x00, 0x0C, 0xFF, 0xFF}; @@ -129,6 +130,7 @@ void McuProtocolTestTool::Init(std::shared_ptr &mock, const UartInfo .WillRepeatedly( DoAll(SaveArg<2>(&WRITE_COUNT), WithArgs<0, 1, 2>(Invoke(api_write)), ReturnPointee(&WRITE_COUNT))); SelectInit(mock, mUartFd); + InitProtocolBuff(); } void McuProtocolTestTool::UnInit(void) { @@ -190,6 +192,10 @@ void McuProtocolTestTool::ReadNothingAnyTime(std::shared_ptr &mock) LogWarning("mUart is null.\n"); } } +void McuProtocolTestTool::InitProtocolBuff(void) +{ + REPLY_IPC_MISSION_X[PROTOCOL_DATA_OFFSET] = 0x01; +} void McuProtocolTestTool::CheckSerialNumber(const void *buf, const size_t &count) { unsigned int serialNumber = 0; @@ -341,6 +347,10 @@ void McuProtocolTestTool::ReadOnceSelectSucceed(std::shared_ptr &mock .WillRepeatedly(DoAll(WithArgs<0, 1, 2, 3, 4>(Invoke(selectTimeOut)), Return(MOCK_SELECT_TIME_OUT))); PipeSelectTimeoutForProtocolHandleImmediately(); } +void McuProtocolTestTool::MockOtherSideIpcMissionReply(const unsigned char &replyIpcMission) +{ + REPLY_IPC_MISSION_X[PROTOCOL_DATA_OFFSET] = replyIpcMission; +} void McuProtocolTestTool::ReplySelectTimeOut(std::shared_ptr &mock, const int &uartFd) { if (mUart) {