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