Improve:Format sd card.
This commit is contained in:
parent
3a4538a82c
commit
0f60695c14
|
@ -24,8 +24,8 @@ using DataProcessingFunc = std::function<bool(VStateMachineData *)>;
|
|||
enum class InternalStateEvent
|
||||
{
|
||||
STORAGE_HANDLE_STATE_INIT = static_cast<int>(MissionEvent::END),
|
||||
SD_CARD_HANDLE_STATE_SD_STATUS_REPORTED,
|
||||
ANY_STATE_SD_STATUS_PERORIED,
|
||||
SD_CARD_HANDLE_STATE_SD_STATUS_REPORTED, ///< Only SdCardHandleState can process this message.
|
||||
ANY_STATE_SD_STATUS_PERORIED, ///< Use it to notify other statuses.
|
||||
CHECK_UPGRADE_FILE,
|
||||
MEDIA_REPORT_EVENT,
|
||||
KEY_EVENT_HANDLE,
|
||||
|
|
|
@ -16,16 +16,21 @@
|
|||
#include "DataProcessing.h"
|
||||
#include "IFilesManager.h"
|
||||
#include "ILog.h"
|
||||
#include "IMissionManager.h"
|
||||
#include "IStateMachine.h"
|
||||
#include "IStorageManager.h"
|
||||
#include "LedControl.h"
|
||||
#include "LedsHandle.h"
|
||||
#include "MissionStateMachine.h"
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
using std::placeholders::_1;
|
||||
FormattingState::FormattingState() : State("FormattingState")
|
||||
FormattingState::FormattingState() : State("FormattingState"), mFormatting(false)
|
||||
{
|
||||
mEventHandle[InternalStateEvent::FORMAT_KEY_FORMAT_SD_CARD] =
|
||||
std::bind(&FormattingState::FormatKeyFormattingSDCardHandle, this, _1);
|
||||
mEventHandle[InternalStateEvent::ANY_STATE_SD_STATUS_PERORIED] =
|
||||
std::bind(&FormattingState::ComfirmFormatResult, this, _1);
|
||||
}
|
||||
void FormattingState::GoInState()
|
||||
{
|
||||
|
@ -37,6 +42,8 @@ void FormattingState::GoOutState()
|
|||
if (mFormattingThread.joinable()) {
|
||||
mFormattingThread.join();
|
||||
}
|
||||
mFormatting = false;
|
||||
LedsHandle::DeleteAllLeds();
|
||||
}
|
||||
bool FormattingState::ExecuteStateMsg(VStateMachineData *msg)
|
||||
{
|
||||
|
@ -57,11 +64,25 @@ bool FormattingState::FormatKeyFormattingSDCardHandle(VStateMachineData *msg)
|
|||
auto formatting = [](std::shared_ptr<FormattingState> impl) {
|
||||
impl->FormattingThread();
|
||||
};
|
||||
mFormatting = true;
|
||||
mFormattingThread = std::thread(formatting, shared_from_this());
|
||||
return EXECUTED;
|
||||
}
|
||||
bool FormattingState::ComfirmFormatResult(VStateMachineData *msg)
|
||||
{
|
||||
std::shared_ptr<MissionMessage> message = std::dynamic_pointer_cast<MissionMessage>(msg->GetMessageObj());
|
||||
std::shared_ptr<VMissionDataV2<StorageEvent>> data =
|
||||
std::dynamic_pointer_cast<VMissionDataV2<StorageEvent>>(message->mMissionData);
|
||||
LogInfo(" SdCardEventHandle event:%s.\n", IStorageManager::GetInstance()->PrintStringStorageEvent(data->mData));
|
||||
if (StorageEvent::SD_CARD_INSERT == data->mData) {
|
||||
LogInfo(" SD card inserted. Format sd card final finished.\n");
|
||||
MissionStateMachine::GetInstance()->SwitchState(SystemState::IDLE_STATE);
|
||||
}
|
||||
return EXECUTED;
|
||||
}
|
||||
void FormattingState::FormattingThread(void)
|
||||
{
|
||||
LedsHandle::ControlDeviceStatusLed(DeviceStatus::FORMATTING, KEEP_ALIVE_FOREVER, BLINKING_FAST_MS);
|
||||
IFilesManager::GetInstance()->UnInit();
|
||||
IStorageManager::GetInstance()->FormatSDCardNow();
|
||||
// IFilesManager::GetInstance()->Init();
|
||||
|
|
|
@ -19,11 +19,13 @@
|
|||
#include "IMediaManager.h"
|
||||
#include "IStateMachine.h"
|
||||
#include "IStorageManager.h"
|
||||
#include "LedsHandle.h"
|
||||
#include "VStateBase.h"
|
||||
#include <thread>
|
||||
class FormattingState : public State,
|
||||
public DataProcessing,
|
||||
public VStateBase,
|
||||
public LedsHandle,
|
||||
public std::enable_shared_from_this<FormattingState>
|
||||
{
|
||||
public:
|
||||
|
@ -37,9 +39,11 @@ protected:
|
|||
void StateInit(void) override;
|
||||
void StateUnInit(void) override;
|
||||
bool FormatKeyFormattingSDCardHandle(VStateMachineData *msg);
|
||||
bool ComfirmFormatResult(VStateMachineData *msg);
|
||||
void FormattingThread(void);
|
||||
|
||||
private:
|
||||
bool mFormatting;
|
||||
std::thread mFormattingThread;
|
||||
};
|
||||
|
||||
|
|
|
@ -20,9 +20,6 @@
|
|||
#include <functional>
|
||||
IdleState::IdleState() : State("IdleState")
|
||||
{
|
||||
// mEventHandle[InternalStateEvent::MEDIA_REPORT_EVENT] = std::bind(&IdleState::MediaReportHandle, this, _1);
|
||||
// mEventHandle[InternalStateEvent::SD_CARD_HANDLE_STATE_SD_STATUS_REPORTED] =
|
||||
// std::bind(&IdleState::SdCardEventHandle, this, _1);
|
||||
mEventHandle[InternalStateEvent::RESET_KEY_MEDIA_TASK] = std::bind(&IdleState::ResetKeyMediaTaskHandle, this, _1);
|
||||
mEventHandle[InternalStateEvent::FORMAT_KEY_FORMAT_SD_CARD] =
|
||||
std::bind(&IdleState::FormatKeyFormattingSDCardHandle, this, _1);
|
||||
|
|
|
@ -23,6 +23,9 @@ void LedsHandle::ControlDeviceStatusLed(const DeviceStatus &status, const long i
|
|||
case DeviceStatus::NORMAL:
|
||||
mDeviceStatus = SetLedState::ControlLed("device_status", LedState::GREEN, keepAliveTime, blinkPeriod);
|
||||
break;
|
||||
case DeviceStatus::FORMATTING:
|
||||
mDeviceStatus = SetLedState::ControlLed("device_status", LedState::YELLOW, keepAliveTime, blinkPeriod);
|
||||
break;
|
||||
|
||||
default:
|
||||
LogWarning("unknow device status.\n");
|
||||
|
|
|
@ -19,6 +19,7 @@ enum class DeviceStatus
|
|||
{
|
||||
NORMAL = 0,
|
||||
TAKING_PICTURE_OR_VIDEO,
|
||||
FORMATTING,
|
||||
END
|
||||
};
|
||||
class LedsHandle
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
#include "MissionStateMachine.h"
|
||||
OnMissionState::OnMissionState() : MissionState("OnMissionState")
|
||||
{
|
||||
// mEventHandle[InternalStateEvent::ANY_STATE_SD_STATUS_PERORIED] =
|
||||
// std::bind(&OnMissionState::SdCardEventReportSendToApp, this, _1);
|
||||
}
|
||||
void OnMissionState::GoInState()
|
||||
{
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
#include "PirTriggeredMissionState.h"
|
||||
PirTriggeredMissionState::PirTriggeredMissionState() : MissionState("PirTriggeredMissionState")
|
||||
{
|
||||
// mEventHandle[InternalStateEvent::ANY_STATE_SD_STATUS_PERORIED] =
|
||||
// std::bind(&PirTriggeredMissionState::SdCardEventReportSendToApp, this, _1);
|
||||
}
|
||||
void PirTriggeredMissionState::GoInState()
|
||||
{
|
||||
|
|
|
@ -43,7 +43,7 @@ void TestMissionState::GoInState()
|
|||
std::shared_ptr<VAppMonitor> monitor =
|
||||
std::dynamic_pointer_cast<TestMissionState>(MissionState::shared_from_this());
|
||||
IAppManager::GetInstance()->SetAppMonitor(monitor);
|
||||
ControlDeviceStatusLed(DeviceStatus::NORMAL);
|
||||
LedsHandle::ControlDeviceStatusLed(DeviceStatus::NORMAL);
|
||||
}
|
||||
void TestMissionState::GoOutState()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user