mirror of
https://gitee.com/jiuyilian/embedded-framework.git
synced 2025-01-06 10:16:51 -05:00
Backup:MissionManger module.
This commit is contained in:
parent
a1d76b0339
commit
2fe56a23ae
|
@ -16,6 +16,12 @@
|
|||
#include "ILog.h"
|
||||
const bool NOT_EXECUTED = false;
|
||||
const bool EXECUTED = true;
|
||||
MissionData::MissionData(const std::shared_ptr<VMissionData> &data) : mMissionData(data)
|
||||
{
|
||||
}
|
||||
MissionMessage::MissionMessage(const std::shared_ptr<VMissionData> &message) : mMissionData(message)
|
||||
{
|
||||
}
|
||||
bool DataProcessing::EventHandle(VStateMachineData *msg)
|
||||
{
|
||||
if (nullptr == msg) {
|
||||
|
@ -23,7 +29,7 @@ bool DataProcessing::EventHandle(VStateMachineData *msg)
|
|||
return NOT_EXECUTED;
|
||||
}
|
||||
std::map<InternalStateEvent, DataProcessingFunc>::iterator iter;
|
||||
std::shared_ptr<MissionData> message = std::dynamic_pointer_cast<MissionData>(msg->GetMessageObj());
|
||||
std::shared_ptr<MissionMessage> message = std::dynamic_pointer_cast<MissionMessage>(msg->GetMessageObj());
|
||||
InternalStateEvent event = static_cast<InternalStateEvent>(message->mMissionData->mEvent);
|
||||
iter = mEventHandle.find(event);
|
||||
if (iter != mEventHandle.end()) {
|
||||
|
|
|
@ -18,21 +18,33 @@
|
|||
#include "IStateMachine.h"
|
||||
#include <functional>
|
||||
#include <map>
|
||||
using std::placeholders::_1;
|
||||
using DataProcessingFunc = std::function<bool(VStateMachineData *)>;
|
||||
enum class InternalStateEvent
|
||||
{
|
||||
TEST = static_cast<int>(MissionEvent::END),
|
||||
MEDIA_REPORT_EVENT,
|
||||
END
|
||||
};
|
||||
class MissionData : public VStateMachineData
|
||||
{
|
||||
public:
|
||||
MissionData(const std::shared_ptr<VMissionData> &data) : mMissionData(data)
|
||||
{
|
||||
}
|
||||
MissionData(const std::shared_ptr<VMissionData> &data);
|
||||
virtual ~MissionData() = default;
|
||||
const std::shared_ptr<VMissionData> mMissionData;
|
||||
};
|
||||
/**
|
||||
* @brief
|
||||
* MissionMessage abstracts user data into state machine data, enabling the transfer of arbitrary data within the state
|
||||
* machine.
|
||||
*/
|
||||
class MissionMessage : public VStateMessage
|
||||
{
|
||||
public:
|
||||
MissionMessage(const std::shared_ptr<VMissionData> &message);
|
||||
virtual ~MissionMessage() = default;
|
||||
const std::shared_ptr<VMissionData> mMissionData; // The message from users of state manager module.
|
||||
};
|
||||
class DataProcessing
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
#include "MissionManagerMakePtr.h"
|
||||
#include "ILog.h"
|
||||
#include "MissionManager.h"
|
||||
#include "SdCardHandleState.h"
|
||||
#include "StorageHandleState.h"
|
||||
#include "TestMissionState.h"
|
||||
#include "TopState.h"
|
||||
bool CreateMissionManagerModule(void)
|
||||
|
@ -62,4 +64,14 @@ std::shared_ptr<State> MissionManagerMakePtr::CreateMissionState(const IpcMissio
|
|||
{
|
||||
std::shared_ptr<State> state = std::make_shared<TestMissionState>();
|
||||
return state;
|
||||
}
|
||||
std::shared_ptr<State> MissionManagerMakePtr::CreateStorageHandleState(void)
|
||||
{
|
||||
std::shared_ptr<State> state = std::make_shared<StorageHandleState>();
|
||||
return state;
|
||||
}
|
||||
std::shared_ptr<State> MissionManagerMakePtr::CreateSdCardHandleState(void)
|
||||
{
|
||||
std::shared_ptr<State> state = std::make_shared<SdCardHandleState>();
|
||||
return state;
|
||||
}
|
|
@ -28,5 +28,7 @@ public:
|
|||
virtual const StatusCode CreateMissionManagerInstance(std::shared_ptr<IMissionManager> &instance);
|
||||
virtual std::shared_ptr<State> CreateTopState(void);
|
||||
virtual std::shared_ptr<State> CreateMissionState(const IpcMission &mission);
|
||||
virtual std::shared_ptr<State> CreateStorageHandleState(void);
|
||||
virtual std::shared_ptr<State> CreateSdCardHandleState(void);
|
||||
};
|
||||
#endif
|
|
@ -15,20 +15,26 @@
|
|||
#include "MissionState.h"
|
||||
#include "IAppManager.h"
|
||||
#include "ILog.h"
|
||||
#include "MissionStateMachine.h"
|
||||
MissionState::MissionState(const std::string &name) : State(name)
|
||||
{
|
||||
mEventHandle[InternalStateEvent::MEDIA_REPORT_EVENT] = std::bind(&MissionState::MediaReportHandle, this, _1);
|
||||
}
|
||||
void MissionState::GoInState()
|
||||
{
|
||||
//
|
||||
LogInfo(" ========== MissionState::GoInState.\n");
|
||||
}
|
||||
void MissionState::GoOutState()
|
||||
{
|
||||
//
|
||||
LogInfo(" ========== MissionState::GoOutState.\n");
|
||||
}
|
||||
bool MissionState::ExecuteStateMsg(VStateMachineData *msg)
|
||||
{
|
||||
return DataProcessing::EventHandle(msg);
|
||||
}
|
||||
bool MissionState::MediaReportHandle(VStateMachineData *msg)
|
||||
{
|
||||
MissionStateMachine::GetInstance()->DelayMessage(msg);
|
||||
MissionStateMachine::GetInstance()->SwitchState(SystemState::STORAGE_HANDLE_STATE);
|
||||
return EXECUTED;
|
||||
}
|
|
@ -24,5 +24,8 @@ public:
|
|||
void GoInState() override;
|
||||
void GoOutState() override;
|
||||
bool ExecuteStateMsg(VStateMachineData *msg) override;
|
||||
|
||||
private:
|
||||
bool MediaReportHandle(VStateMachineData *msg);
|
||||
};
|
||||
#endif
|
|
@ -54,7 +54,17 @@ void MissionStateMachine::UnInit(void)
|
|||
mStateMachine->StopHandlerThread();
|
||||
mStateTree.clear();
|
||||
}
|
||||
void MissionStateMachine::SwitchState(const MissionState &state)
|
||||
StatusCode MissionStateMachine::SendStateMessage(const std::shared_ptr<VMissionData> &message)
|
||||
{
|
||||
std::shared_ptr<VStateMessage> msg = std::make_shared<MissionMessage>(message);
|
||||
mStateMachine->SendMessage(static_cast<int>(message->mEvent), msg);
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
void MissionStateMachine::DelayMessage(VStateMachineData *msg)
|
||||
{
|
||||
mStateMachine->DelayMessage(msg);
|
||||
}
|
||||
void MissionStateMachine::SwitchState(const SystemState &state)
|
||||
{
|
||||
mStateMachine->SwitchState(mStateTree[state].get());
|
||||
}
|
||||
|
@ -76,10 +86,16 @@ IpcMission MissionStateMachine::GetStartMission(void)
|
|||
void MissionStateMachine::RunStateMachine(const IpcMission &mission)
|
||||
{
|
||||
LogInfo("Make all states and start the state machine.\n");
|
||||
mStateTree[MissionState::TOP_STATE] = MissionManagerMakePtr::GetInstance()->CreateTopState();
|
||||
mStateTree[MissionState::MISSION_STATE] = MissionManagerMakePtr::GetInstance()->CreateMissionState(mission);
|
||||
mStateMachine->StatePlus(mStateTree[MissionState::TOP_STATE].get(), nullptr);
|
||||
mStateMachine->StatePlus(mStateTree[MissionState::MISSION_STATE].get(), mStateTree[MissionState::TOP_STATE].get());
|
||||
mStateMachine->SetCurrentState(mStateTree[MissionState::TOP_STATE].get());
|
||||
mStateTree[SystemState::TOP_STATE] = MissionManagerMakePtr::GetInstance()->CreateTopState();
|
||||
mStateTree[SystemState::MISSION_STATE] = MissionManagerMakePtr::GetInstance()->CreateMissionState(mission);
|
||||
mStateTree[SystemState::STORAGE_HANDLE_STATE] = MissionManagerMakePtr::GetInstance()->CreateStorageHandleState();
|
||||
mStateTree[SystemState::SD_CARD_HANDLE_STATE] = MissionManagerMakePtr::GetInstance()->CreateSdCardHandleState();
|
||||
mStateMachine->StatePlus(mStateTree[SystemState::TOP_STATE].get(), nullptr);
|
||||
mStateMachine->StatePlus(mStateTree[SystemState::MISSION_STATE].get(), mStateTree[SystemState::TOP_STATE].get());
|
||||
mStateMachine->StatePlus(mStateTree[SystemState::STORAGE_HANDLE_STATE].get(),
|
||||
mStateTree[SystemState::MISSION_STATE].get());
|
||||
mStateMachine->StatePlus(mStateTree[SystemState::SD_CARD_HANDLE_STATE].get(),
|
||||
mStateTree[SystemState::STORAGE_HANDLE_STATE].get());
|
||||
mStateMachine->SetCurrentState(mStateTree[SystemState::TOP_STATE].get());
|
||||
mStateMachine->StartStateMachine();
|
||||
}
|
||||
|
|
|
@ -18,11 +18,16 @@
|
|||
#include "IMcuManager.h"
|
||||
#include "IMissionManager.h"
|
||||
#include "IStateMachine.h"
|
||||
#include "StatusCode.h"
|
||||
#include <map>
|
||||
enum class MissionState
|
||||
const bool NOT_EXECUTED = false;
|
||||
const bool EXECUTED = true;
|
||||
enum class SystemState
|
||||
{
|
||||
TOP_STATE = 0,
|
||||
MISSION_STATE,
|
||||
STORAGE_HANDLE_STATE,
|
||||
SD_CARD_HANDLE_STATE,
|
||||
END
|
||||
};
|
||||
class MissionStateMachine
|
||||
|
@ -33,7 +38,9 @@ public:
|
|||
static std::shared_ptr<MissionStateMachine> &GetInstance(std::shared_ptr<MissionStateMachine> *impl = nullptr);
|
||||
void Init(void);
|
||||
void UnInit(void);
|
||||
void SwitchState(const MissionState &state);
|
||||
StatusCode SendStateMessage(const std::shared_ptr<VMissionData> &message);
|
||||
void DelayMessage(VStateMachineData *msg);
|
||||
void SwitchState(const SystemState &state);
|
||||
|
||||
private:
|
||||
IpcMission GetStartMission(void);
|
||||
|
@ -41,7 +48,7 @@ private:
|
|||
|
||||
private:
|
||||
std::shared_ptr<VStateMachineHandle> mStateMachine;
|
||||
std::map<MissionState, std::shared_ptr<State>> mStateTree;
|
||||
std::map<SystemState, std::shared_ptr<State>> mStateTree;
|
||||
IpcMission mStartMission;
|
||||
};
|
||||
#endif
|
47
application/MissionManager/src/SdCardHandleState.cpp
Normal file
47
application/MissionManager/src/SdCardHandleState.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* 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 "SdCardHandleState.h"
|
||||
#include "ILog.h"
|
||||
#include "IMediaManager.h"
|
||||
#include "MissionStateMachine.h"
|
||||
SdCardHandleState::SdCardHandleState() : State("SdCardHandleState")
|
||||
{
|
||||
mEventHandle[InternalStateEvent::MEDIA_REPORT_EVENT] = std::bind(&SdCardHandleState::MediaReportHandle, this, _1);
|
||||
}
|
||||
void SdCardHandleState::GoInState()
|
||||
{
|
||||
LogInfo(" ========== opState::GoInState.\n");
|
||||
}
|
||||
void SdCardHandleState::GoOutState()
|
||||
{
|
||||
LogInfo(" ========== opState::GoOutState.\n");
|
||||
}
|
||||
bool SdCardHandleState::ExecuteStateMsg(VStateMachineData *msg)
|
||||
{
|
||||
return DataProcessing::EventHandle(msg);
|
||||
}
|
||||
bool SdCardHandleState::MediaReportHandle(VStateMachineData *msg)
|
||||
{
|
||||
LogInfo(" MediaReportHandle.\n");
|
||||
std::shared_ptr<MissionMessage> message = std::dynamic_pointer_cast<MissionMessage>(msg->GetMessageObj());
|
||||
std::shared_ptr<VMissionDataV2<MediaReportEvent>> data =
|
||||
std::dynamic_pointer_cast<VMissionDataV2<MediaReportEvent>>(message->mMissionData);
|
||||
if (!data) {
|
||||
LogError("nullptr pointer.\n");
|
||||
return NOT_EXECUTED;
|
||||
}
|
||||
LogInfo(" MediaReportHandle, file = %s, path = %s.\n", data->mData.mFileName.c_str(), data->mData.mFilePath.c_str());
|
||||
return EXECUTED;
|
||||
}
|
32
application/MissionManager/src/SdCardHandleState.h
Normal file
32
application/MissionManager/src/SdCardHandleState.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* 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 SD_CARD_HANDLE_STATE_H
|
||||
#define SD_CARD_HANDLE_STATE_H
|
||||
#include "DataProcessing.h"
|
||||
#include "IMediaManager.h"
|
||||
#include "IStateMachine.h"
|
||||
class SdCardHandleState : public State, public DataProcessing, public std::enable_shared_from_this<SdCardHandleState>
|
||||
{
|
||||
public:
|
||||
SdCardHandleState();
|
||||
virtual ~SdCardHandleState() = default;
|
||||
void GoInState() override;
|
||||
void GoOutState() override;
|
||||
bool ExecuteStateMsg(VStateMachineData *msg) override;
|
||||
|
||||
private:
|
||||
bool MediaReportHandle(VStateMachineData *msg);
|
||||
};
|
||||
#endif
|
34
application/MissionManager/src/StorageHandleState.cpp
Normal file
34
application/MissionManager/src/StorageHandleState.cpp
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* 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 "StorageHandleState.h"
|
||||
#include "ILog.h"
|
||||
#include "IMediaManager.h"
|
||||
#include "MissionStateMachine.h"
|
||||
StorageHandleState::StorageHandleState() : State("StorageHandleState")
|
||||
{
|
||||
}
|
||||
void StorageHandleState::GoInState()
|
||||
{
|
||||
LogInfo(" ========== opState::GoInState.\n");
|
||||
MissionStateMachine::GetInstance()->SwitchState(SystemState::SD_CARD_HANDLE_STATE);
|
||||
}
|
||||
void StorageHandleState::GoOutState()
|
||||
{
|
||||
LogInfo(" ========== opState::GoOutState.\n");
|
||||
}
|
||||
bool StorageHandleState::ExecuteStateMsg(VStateMachineData *msg)
|
||||
{
|
||||
return DataProcessing::EventHandle(msg);
|
||||
}
|
29
application/MissionManager/src/StorageHandleState.h
Normal file
29
application/MissionManager/src/StorageHandleState.h
Normal file
|
@ -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.
|
||||
*/
|
||||
#ifndef STORAGE_HANDLE_STATE_H
|
||||
#define STORAGE_HANDLE_STATE_H
|
||||
#include "DataProcessing.h"
|
||||
#include "IMediaManager.h"
|
||||
#include "IStateMachine.h"
|
||||
class StorageHandleState : public State, public DataProcessing, public std::enable_shared_from_this<StorageHandleState>
|
||||
{
|
||||
public:
|
||||
StorageHandleState();
|
||||
virtual ~StorageHandleState() = default;
|
||||
void GoInState() override;
|
||||
void GoOutState() override;
|
||||
bool ExecuteStateMsg(VStateMachineData *msg) override;
|
||||
};
|
||||
#endif
|
|
@ -33,7 +33,7 @@ void TestMissionState::GoOutState()
|
|||
MissionState::GoOutState();
|
||||
LogInfo(" ========== TestMissionState::GoOutState.\n");
|
||||
}
|
||||
bool TestMissionState::ExecuteStateMsg(VStateMachineData *msg)
|
||||
{
|
||||
return MissionState::EventHandle(msg);
|
||||
}
|
||||
// bool TestMissionState::ExecuteStateMsg(VStateMachineData *msg)
|
||||
// {
|
||||
// return MissionState::EventHandle(msg);
|
||||
// }
|
|
@ -24,6 +24,6 @@ public:
|
|||
virtual ~TestMissionState() = default;
|
||||
void GoInState() override;
|
||||
void GoOutState() override;
|
||||
bool ExecuteStateMsg(VStateMachineData *msg) override;
|
||||
// bool ExecuteStateMsg(VStateMachineData *msg) override;
|
||||
};
|
||||
#endif
|
|
@ -24,7 +24,7 @@ void TopState::GoInState()
|
|||
LogInfo(" ========== opState::GoInState.\n");
|
||||
std::shared_ptr<VMediaMonitor> monitor = std::dynamic_pointer_cast<TopState>(shared_from_this());
|
||||
IMediaManager::GetInstance()->SetMediaMonitor(monitor);
|
||||
MissionStateMachine::GetInstance()->SwitchState(MissionState::MISSION_STATE);
|
||||
MissionStateMachine::GetInstance()->SwitchState(SystemState::MISSION_STATE);
|
||||
}
|
||||
void TopState::GoOutState()
|
||||
{
|
||||
|
@ -36,6 +36,8 @@ bool TopState::ExecuteStateMsg(VStateMachineData *msg)
|
|||
}
|
||||
StatusCode TopState::ReportEvent(const MediaReportEvent &event)
|
||||
{
|
||||
LogInfo("sssssssssssssssssssssssssssssssssssssssssssssssssssssssss\n");
|
||||
std::shared_ptr<VMissionData> message = std::make_shared<VMissionDataV2<MediaReportEvent>>(
|
||||
static_cast<MissionEvent>(InternalStateEvent::MEDIA_REPORT_EVENT), event);
|
||||
MissionStateMachine::GetInstance()->SendStateMessage(message);
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
|
@ -484,7 +484,33 @@ deactivate 大核
|
|||
2. 定时启动拍照 / 录像;
|
||||
3. 测试启动;
|
||||
|
||||
###### 1.4.3.1.3.2. 任务状态获取启动
|
||||
###### 1.4.3.1.3.2. 状态机设计
|
||||
|
||||
```mermaid
|
||||
stateDiagram-v2
|
||||
[*] --> TopState
|
||||
TopState --> PowerOff
|
||||
TopState --> MSDCState
|
||||
TopState --> DeviceAbnormal
|
||||
TopState --> MissionState
|
||||
MissionState --> 存储管理
|
||||
存储管理 --> EMMC
|
||||
存储管理 --> SD卡
|
||||
SD卡 --> 插卡
|
||||
SD卡 --> 拔卡
|
||||
SD卡 --> 卡异常
|
||||
MissionState --> 网络管理
|
||||
网络管理 --> 联网
|
||||
联网 --> 上传文件
|
||||
网络管理 --> 未联网
|
||||
MissionState --> 直播
|
||||
MissionState --> 4G管理
|
||||
4G管理 --> Sim卡初始化
|
||||
4G管理 --> 注网状态
|
||||
MissionState --> Upgrade
|
||||
```
|
||||
|
||||
###### 1.4.3.1.3.3. 任务状态获取启动
|
||||
|
||||
  应用程序运行后,首先需要知道主控是由于何种任务被唤醒,然后根据任务来执行相应的功能代码;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user