Sync:ffmpeg code.
This commit is contained in:
commit
e56c3d5bc5
|
@ -27,7 +27,7 @@ enum class InternalStateEvent
|
||||||
SD_CARD_HANDLE_STATE_SD_STATUS_REPORTED, ///< Only SdCardHandleState can process this message.
|
SD_CARD_HANDLE_STATE_SD_STATUS_REPORTED, ///< Only SdCardHandleState can process this message.
|
||||||
ANY_STATE_SD_STATUS_PERORIED, ///< Use it to notify other statuses.
|
ANY_STATE_SD_STATUS_PERORIED, ///< Use it to notify other statuses.
|
||||||
CHECK_UPGRADE_FILE,
|
CHECK_UPGRADE_FILE,
|
||||||
MEDIA_REPORT_EVENT,
|
MEDIA_REPORT_EVENT, ///< Media events proactively reported by the bottom layer.
|
||||||
KEY_EVENT_HANDLE,
|
KEY_EVENT_HANDLE,
|
||||||
RESET_KEY_MEDIA_TASK,
|
RESET_KEY_MEDIA_TASK,
|
||||||
FORMAT_KEY_FORMAT_SD_CARD,
|
FORMAT_KEY_FORMAT_SD_CARD,
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
#include "MissionStateMachine.h"
|
#include "MissionStateMachine.h"
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
MediaHandleState::MediaHandleState() : State("MediaHandleState")
|
MediaHandleState::MediaHandleState() : State("MediaHandleState")
|
||||||
{
|
{
|
||||||
|
@ -72,7 +71,7 @@ bool MediaHandleState::MediaTaskFinishedHandle(VStateMachineData *msg)
|
||||||
LogInfo("response files = %d.\n", data->mData.mResponse.size());
|
LogInfo("response files = %d.\n", data->mData.mResponse.size());
|
||||||
std::vector<SyncFileInfo> files;
|
std::vector<SyncFileInfo> files;
|
||||||
for (auto &response : data->mData.mResponse) {
|
for (auto &response : data->mData.mResponse) {
|
||||||
auto fileSize = GetFileSize_KB(response.mFileName.c_str());
|
auto fileSize = MediaTask::GetFileSize_KB(response.mFileName.c_str());
|
||||||
SyncFileInfo file(data->mData.mSerialNumber,
|
SyncFileInfo file(data->mData.mSerialNumber,
|
||||||
response.mFileName,
|
response.mFileName,
|
||||||
fileSize,
|
fileSize,
|
||||||
|
@ -86,13 +85,4 @@ bool MediaHandleState::MediaTaskFinishedHandle(VStateMachineData *msg)
|
||||||
LedsHandle::DeleteDeviceStatusLed();
|
LedsHandle::DeleteDeviceStatusLed();
|
||||||
MissionStateMachine::GetInstance()->SwitchState(SystemState::IDLE_STATE);
|
MissionStateMachine::GetInstance()->SwitchState(SystemState::IDLE_STATE);
|
||||||
return EXECUTED;
|
return EXECUTED;
|
||||||
}
|
|
||||||
int MediaHandleState::GetFileSize_KB(const char *filePath)
|
|
||||||
{
|
|
||||||
struct stat fileInfo;
|
|
||||||
if (stat(filePath, &fileInfo) != 0) {
|
|
||||||
LogError("stat failed.\n");
|
|
||||||
return FILE_SIZE_ERROR;
|
|
||||||
}
|
|
||||||
return static_cast<double>(fileInfo.st_size) / 1024.0;
|
|
||||||
}
|
}
|
|
@ -18,7 +18,6 @@
|
||||||
#include "IStateMachine.h"
|
#include "IStateMachine.h"
|
||||||
#include "LedsHandle.h"
|
#include "LedsHandle.h"
|
||||||
#include "MediaTaskHandle.h"
|
#include "MediaTaskHandle.h"
|
||||||
constexpr int FILE_SIZE_ERROR = -1;
|
|
||||||
class MediaHandleState : public State,
|
class MediaHandleState : public State,
|
||||||
public DataProcessing,
|
public DataProcessing,
|
||||||
public MediaTaskHandle,
|
public MediaTaskHandle,
|
||||||
|
@ -37,8 +36,5 @@ private:
|
||||||
void TaskResponse(const MediaTaskInfo &taskinfo) override;
|
void TaskResponse(const MediaTaskInfo &taskinfo) override;
|
||||||
bool ResetKeyMediaTaskHandle(VStateMachineData *msg);
|
bool ResetKeyMediaTaskHandle(VStateMachineData *msg);
|
||||||
bool MediaTaskFinishedHandle(VStateMachineData *msg);
|
bool MediaTaskFinishedHandle(VStateMachineData *msg);
|
||||||
|
|
||||||
private:
|
|
||||||
static int GetFileSize_KB(const char *filePath);
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
|
@ -14,6 +14,7 @@
|
||||||
*/
|
*/
|
||||||
#include "MediaTask.h"
|
#include "MediaTask.h"
|
||||||
#include "DataProcessing.h"
|
#include "DataProcessing.h"
|
||||||
|
#include "IIpcConfig.h"
|
||||||
#include "ILog.h"
|
#include "ILog.h"
|
||||||
#include "IMediaManager.h"
|
#include "IMediaManager.h"
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
|
@ -25,6 +26,7 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
MediaTask::MediaTask(const MediaTaskType &type, const InternalStateEvent &bindEvent,
|
MediaTask::MediaTask(const MediaTaskType &type, const InternalStateEvent &bindEvent,
|
||||||
const std::weak_ptr<VMediaTaskIniator> &iniator, const unsigned long &serialNumber,
|
const std::weak_ptr<VMediaTaskIniator> &iniator, const unsigned long &serialNumber,
|
||||||
|
@ -49,38 +51,14 @@ std::string MediaTask::GetTargetNameForSaving(void)
|
||||||
return mTargetName;
|
return mTargetName;
|
||||||
}
|
}
|
||||||
auto now = std::chrono::system_clock::now();
|
auto now = std::chrono::system_clock::now();
|
||||||
time_t t_now = std::chrono::system_clock::to_time_t(now);
|
|
||||||
struct tm tm_now = *std::localtime(&t_now);
|
|
||||||
|
|
||||||
mCreateTime_s = std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch()).count();
|
mCreateTime_s = std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch()).count();
|
||||||
int hour = tm_now.tm_hour;
|
|
||||||
int minute = tm_now.tm_min;
|
|
||||||
int second = tm_now.tm_sec;
|
|
||||||
const std::string fileType = MediaTaskType::TAKE_VIDEO == mType ? ".mp4" : ".jpeg";
|
const std::string fileType = MediaTaskType::TAKE_VIDEO == mType ? ".mp4" : ".jpeg";
|
||||||
std::ostringstream pathStream;
|
return CreateFileName(mSerialNumber, mSavePath, fileType);
|
||||||
pathStream << mSavePath << "xak47-" << mSerialNumber << "-" << std::setw(2) << std::setfill('0') << hour
|
|
||||||
<< std::setw(2) << std::setfill('0') << minute << std::setw(2) << std::setfill('0') << second
|
|
||||||
<< fileType;
|
|
||||||
mTargetName = pathStream.str();
|
|
||||||
LogInfo("GetTargetNameForSaving: %s\n", pathStream.str().c_str());
|
|
||||||
return pathStream.str();
|
|
||||||
}
|
}
|
||||||
std::string MediaTask::GetThumbnailNameForSaving(const std::string &targetName)
|
std::string MediaTask::GetThumbnailNameForSaving(const std::string &targetName)
|
||||||
{
|
{
|
||||||
return MediaTask::GetThumbnailNameByTargetName(targetName);
|
return MediaTask::GetThumbnailNameByTargetName(targetName);
|
||||||
// std::string thumbnailName = targetName;
|
|
||||||
// size_t dot_pos = thumbnailName.find_last_of('.');
|
|
||||||
// if (dot_pos != std::string::npos) {
|
|
||||||
// std::string extension = thumbnailName.substr(dot_pos);
|
|
||||||
// if (extension == ".mp4") {
|
|
||||||
// thumbnailName.replace(dot_pos, extension.length(), "-thumbnail.jpeg");
|
|
||||||
// LogInfo("GetThumbnailNameForSaving: %s\n", thumbnailName.c_str());
|
|
||||||
// return thumbnailName;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// LogError("TargetName is not a mp4 file.\n");
|
|
||||||
// std::string unknowFile = "unknow";
|
|
||||||
// return unknowFile;
|
|
||||||
}
|
}
|
||||||
int MediaTask::GetVideoDuration_ms(void)
|
int MediaTask::GetVideoDuration_ms(void)
|
||||||
{
|
{
|
||||||
|
@ -117,4 +95,67 @@ std::string MediaTask::GetThumbnailNameByTargetName(const std::string &targetNam
|
||||||
LogError("TargetName is not a mp4 file.\n");
|
LogError("TargetName is not a mp4 file.\n");
|
||||||
std::string unknowFile = "unknow";
|
std::string unknowFile = "unknow";
|
||||||
return unknowFile;
|
return unknowFile;
|
||||||
|
}
|
||||||
|
long long MediaTask::GetCreateTime_s(void)
|
||||||
|
{
|
||||||
|
auto now = std::chrono::system_clock::now();
|
||||||
|
// time_t t_now = std::chrono::system_clock::to_time_t(now);
|
||||||
|
// struct tm tm_now = *std::localtime(&t_now);
|
||||||
|
|
||||||
|
return std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch()).count();
|
||||||
|
}
|
||||||
|
int MediaTask::GetFileSize_KB(const char *filePath)
|
||||||
|
{
|
||||||
|
struct stat fileInfo;
|
||||||
|
if (stat(filePath, &fileInfo) != 0) {
|
||||||
|
LogError("stat failed.\n");
|
||||||
|
return FILE_SIZE_ERROR;
|
||||||
|
}
|
||||||
|
return static_cast<double>(fileInfo.st_size) / 1024.0;
|
||||||
|
}
|
||||||
|
MediaTaskType MediaTask::WorkModeConvert(const WorkMode &mode)
|
||||||
|
{
|
||||||
|
switch (mode) {
|
||||||
|
case WorkMode::MODE_PIC:
|
||||||
|
return MediaTaskType::TAKE_PICTURE;
|
||||||
|
case WorkMode::MODE_VIDEO:
|
||||||
|
return MediaTaskType::TAKE_VIDEO;
|
||||||
|
case WorkMode::MODE_PIC_VIDEO:
|
||||||
|
return MediaTaskType::TAKE_PICTURE_AND_VIDEO;
|
||||||
|
|
||||||
|
default:
|
||||||
|
LogWarning("unknow work mode.\n");
|
||||||
|
return MediaTaskType::TAKE_PICTURE_AND_VIDEO;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::string MediaTask::GetFileNameBySeriaNumber(const unsigned long &serialNumber, const std::string &sourceFile,
|
||||||
|
const std::string &savePaht)
|
||||||
|
{
|
||||||
|
std::string fileType = "";
|
||||||
|
size_t dot_pos = sourceFile.find_last_of('.');
|
||||||
|
if (dot_pos != std::string::npos) {
|
||||||
|
std::string extension = sourceFile.substr(dot_pos);
|
||||||
|
fileType = extension;
|
||||||
|
}
|
||||||
|
return CreateFileName(serialNumber, savePaht, fileType);
|
||||||
|
}
|
||||||
|
std::string MediaTask::CreateFileName(const unsigned long &serialNumber, const std::string &savePaht,
|
||||||
|
const std::string &fileType)
|
||||||
|
{
|
||||||
|
auto now = std::chrono::system_clock::now();
|
||||||
|
time_t t_now = std::chrono::system_clock::to_time_t(now);
|
||||||
|
struct tm tm_now = *std::localtime(&t_now);
|
||||||
|
/**
|
||||||
|
* @brief When the sequence number is 0, it indicates an invalid sequence number and is replaced by "???".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
const std::string serialNumberString = 0 == serialNumber ? "???" : std::to_string(serialNumber);
|
||||||
|
int hour = tm_now.tm_hour;
|
||||||
|
int minute = tm_now.tm_min;
|
||||||
|
int second = tm_now.tm_sec;
|
||||||
|
std::ostringstream pathStream;
|
||||||
|
pathStream << savePaht << "xak47-" << serialNumberString << "-" << std::setw(2) << std::setfill('0') << hour
|
||||||
|
<< std::setw(2) << std::setfill('0') << minute << std::setw(2) << std::setfill('0') << second
|
||||||
|
<< fileType;
|
||||||
|
return pathStream.str();
|
||||||
}
|
}
|
|
@ -15,9 +15,11 @@
|
||||||
#ifndef MEDIA_TASK_H
|
#ifndef MEDIA_TASK_H
|
||||||
#define MEDIA_TASK_H
|
#define MEDIA_TASK_H
|
||||||
#include "DataProcessing.h"
|
#include "DataProcessing.h"
|
||||||
|
#include "IIpcConfig.h"
|
||||||
#include "IMediaManager.h"
|
#include "IMediaManager.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
constexpr int FILE_SIZE_ERROR = -1;
|
||||||
constexpr unsigned int MEDIA_TASK_TIMEOUT_MS = 1000 * 60;
|
constexpr unsigned int MEDIA_TASK_TIMEOUT_MS = 1000 * 60;
|
||||||
constexpr int DEFAULT_VIDEO_DURATION_MS = 1000 * 10;
|
constexpr int DEFAULT_VIDEO_DURATION_MS = 1000 * 10;
|
||||||
typedef struct media_task_info
|
typedef struct media_task_info
|
||||||
|
@ -49,6 +51,13 @@ public:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static std::string GetThumbnailNameByTargetName(const std::string &targetName);
|
static std::string GetThumbnailNameByTargetName(const std::string &targetName);
|
||||||
|
static long long GetCreateTime_s(void);
|
||||||
|
static int GetFileSize_KB(const char *filePath);
|
||||||
|
static MediaTaskType WorkModeConvert(const WorkMode &mode);
|
||||||
|
static std::string GetFileNameBySeriaNumber(const unsigned long &serialNumber, const std::string &sourceFile,
|
||||||
|
const std::string &savePaht);
|
||||||
|
static std::string CreateFileName(const unsigned long &serialNumber, const std::string &savePaht,
|
||||||
|
const std::string &fileType);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const MediaTaskType mType;
|
const MediaTaskType mType;
|
||||||
|
|
|
@ -42,7 +42,7 @@ void MediaTaskHandle::MakeSingleTask(const InternalStateEvent &bindEvent,
|
||||||
{
|
{
|
||||||
InfoToBeSaved info = IFilesManager::GetInstance()->GetInfoForSavingFiles(1);
|
InfoToBeSaved info = IFilesManager::GetInstance()->GetInfoForSavingFiles(1);
|
||||||
WorkMode workMode = IIpcConfig::GetInstance()->GetWorkMode();
|
WorkMode workMode = IIpcConfig::GetInstance()->GetWorkMode();
|
||||||
MediaTaskType taskType = WorkModeConvert(workMode);
|
MediaTaskType taskType = MediaTask::WorkModeConvert(workMode);
|
||||||
LogInfo("taskType: %s\n", IMediaManager::PrintfTaskType(taskType));
|
LogInfo("taskType: %s\n", IMediaManager::PrintfTaskType(taskType));
|
||||||
std::shared_ptr<VMediaTask> task =
|
std::shared_ptr<VMediaTask> task =
|
||||||
std::make_shared<MediaTask>(taskType, bindEvent, iniator, info.mSerialNumber, info.mSavingPath);
|
std::make_shared<MediaTask>(taskType, bindEvent, iniator, info.mSerialNumber, info.mSavingPath);
|
||||||
|
@ -61,19 +61,4 @@ void MediaTaskHandle::MakeSingleTask(const InternalStateEvent &bindEvent,
|
||||||
// else if () {
|
// else if () {
|
||||||
// mMediaHandle->StopTask();
|
// mMediaHandle->StopTask();
|
||||||
// }
|
// }
|
||||||
}
|
|
||||||
MediaTaskType MediaTaskHandle::WorkModeConvert(const WorkMode &mode)
|
|
||||||
{
|
|
||||||
switch (mode) {
|
|
||||||
case WorkMode::MODE_PIC:
|
|
||||||
return MediaTaskType::TAKE_PICTURE;
|
|
||||||
case WorkMode::MODE_VIDEO:
|
|
||||||
return MediaTaskType::TAKE_VIDEO;
|
|
||||||
case WorkMode::MODE_PIC_VIDEO:
|
|
||||||
return MediaTaskType::TAKE_PICTURE_AND_VIDEO;
|
|
||||||
|
|
||||||
default:
|
|
||||||
LogWarning("unknow work mode.\n");
|
|
||||||
return MediaTaskType::TAKE_PICTURE_AND_VIDEO;
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -27,9 +27,6 @@ public:
|
||||||
void UnInit(void);
|
void UnInit(void);
|
||||||
void MakeSingleTask(const InternalStateEvent &bindEvent, const std::shared_ptr<VMediaTaskIniator> &iniator);
|
void MakeSingleTask(const InternalStateEvent &bindEvent, const std::shared_ptr<VMediaTaskIniator> &iniator);
|
||||||
|
|
||||||
private:
|
|
||||||
MediaTaskType WorkModeConvert(const WorkMode &mode);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::shared_ptr<VMediaHandle> mMediaHandle;
|
std::shared_ptr<VMediaHandle> mMediaHandle;
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,25 @@ bool MissionState::ExecuteStateMsg(VStateMachineData *msg)
|
||||||
}
|
}
|
||||||
bool MissionState::MediaReportHandle(VStateMachineData *msg)
|
bool MissionState::MediaReportHandle(VStateMachineData *msg)
|
||||||
{
|
{
|
||||||
|
LogInfo("Get media file from chip.\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;
|
||||||
|
// }
|
||||||
|
// auto fileSize = MediaTask::GetFileSize_KB(data->mData.mFileName.c_str());
|
||||||
|
// auto createTime = MediaTask::GetCreateTime_s();
|
||||||
|
// auto createType = MissionStateMachine::GetInstance()->GetFileCreateType();
|
||||||
|
// SyncFileInfo file(UNDEFINE_SERIAL_NUMBER,
|
||||||
|
// data->mData.mFileName,
|
||||||
|
// fileSize,
|
||||||
|
// data->mData.mDuration_ms,
|
||||||
|
// createTime,
|
||||||
|
// createType,
|
||||||
|
// FileStatus::FINISHED_RECORD);
|
||||||
|
// mFastStartMediaFiles.push_back(file);
|
||||||
MissionStateMachine::GetInstance()->DelayMessage(msg);
|
MissionStateMachine::GetInstance()->DelayMessage(msg);
|
||||||
MissionStateMachine::GetInstance()->SwitchState(SystemState::STORAGE_HANDLE_STATE);
|
MissionStateMachine::GetInstance()->SwitchState(SystemState::STORAGE_HANDLE_STATE);
|
||||||
return EXECUTED;
|
return EXECUTED;
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#ifndef MISSION_STATE_H
|
#ifndef MISSION_STATE_H
|
||||||
#define MISSION_STATE_H
|
#define MISSION_STATE_H
|
||||||
#include "DataProcessing.h"
|
#include "DataProcessing.h"
|
||||||
|
#include "IFilesManager.h"
|
||||||
#include "IStateMachine.h"
|
#include "IStateMachine.h"
|
||||||
#include "LedsHandle.h"
|
#include "LedsHandle.h"
|
||||||
class MissionState : public State,
|
class MissionState : public State,
|
||||||
|
@ -33,7 +34,17 @@ protected:
|
||||||
bool SdCardEventReportHandle(VStateMachineData *msg);
|
bool SdCardEventReportHandle(VStateMachineData *msg);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/**
|
||||||
|
* @brief Processes media events actively reported by the bottom layer, and refers to snapshot or video recording
|
||||||
|
* during quick start.
|
||||||
|
* @param msg
|
||||||
|
* @return true
|
||||||
|
* @return false
|
||||||
|
*/
|
||||||
bool MediaReportHandle(VStateMachineData *msg);
|
bool MediaReportHandle(VStateMachineData *msg);
|
||||||
bool CheckUpgradeFileHandle(VStateMachineData *msg);
|
bool CheckUpgradeFileHandle(VStateMachineData *msg);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<SyncFileInfo> mFastStartMediaFiles;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
|
@ -14,6 +14,7 @@
|
||||||
*/
|
*/
|
||||||
#include "MissionStateMachine.h"
|
#include "MissionStateMachine.h"
|
||||||
#include "DataProcessing.h"
|
#include "DataProcessing.h"
|
||||||
|
#include "IFilesManager.h"
|
||||||
#include "ILog.h"
|
#include "ILog.h"
|
||||||
#include "IMcuManager.h"
|
#include "IMcuManager.h"
|
||||||
#include "IMissionManager.h"
|
#include "IMissionManager.h"
|
||||||
|
@ -82,6 +83,19 @@ void MissionStateMachine::SwitchState(const SystemState &state)
|
||||||
{
|
{
|
||||||
mStateMachine->SwitchState(mStateTree[state].get());
|
mStateMachine->SwitchState(mStateTree[state].get());
|
||||||
}
|
}
|
||||||
|
FileCreateType MissionStateMachine::GetFileCreateType(void)
|
||||||
|
{
|
||||||
|
switch (mStartMission) {
|
||||||
|
case IpcMission::TEST:
|
||||||
|
return FileCreateType::MANUAL_TEST;
|
||||||
|
case IpcMission::PIR_TRIGGERED:
|
||||||
|
return FileCreateType::PIR;
|
||||||
|
|
||||||
|
default:
|
||||||
|
LogError("unknow ipcmission.\n");
|
||||||
|
return FileCreateType::END;
|
||||||
|
}
|
||||||
|
}
|
||||||
IpcMission MissionStateMachine::GetStartMission(void)
|
IpcMission MissionStateMachine::GetStartMission(void)
|
||||||
{
|
{
|
||||||
class McuAskIpcMission : public McuAsk<IpcMission>, public McuAskBase
|
class McuAskIpcMission : public McuAsk<IpcMission>, public McuAskBase
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#ifndef MISSION_STATE_MACHINE_H
|
#ifndef MISSION_STATE_MACHINE_H
|
||||||
#define MISSION_STATE_MACHINE_H
|
#define MISSION_STATE_MACHINE_H
|
||||||
// #include "IDeviceManager.h"
|
// #include "IDeviceManager.h"
|
||||||
|
#include "IFilesManager.h"
|
||||||
#include "IMcuManager.h"
|
#include "IMcuManager.h"
|
||||||
#include "IMissionManager.h"
|
#include "IMissionManager.h"
|
||||||
#include "IStateMachine.h"
|
#include "IStateMachine.h"
|
||||||
|
@ -48,6 +49,12 @@ public:
|
||||||
StatusCode MessageExecutedLater(const std::shared_ptr<VMissionData> &message, long long &delayTimeMs);
|
StatusCode MessageExecutedLater(const std::shared_ptr<VMissionData> &message, long long &delayTimeMs);
|
||||||
void DelayMessage(VStateMachineData *msg);
|
void DelayMessage(VStateMachineData *msg);
|
||||||
void SwitchState(const SystemState &state);
|
void SwitchState(const SystemState &state);
|
||||||
|
/**
|
||||||
|
* @brief Get the type of quick snapshot or video file based on the startup task parameters.
|
||||||
|
*
|
||||||
|
* @return FileCreateType
|
||||||
|
*/
|
||||||
|
FileCreateType GetFileCreateType(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IpcMission GetStartMission(void);
|
IpcMission GetStartMission(void);
|
||||||
|
|
|
@ -22,10 +22,12 @@
|
||||||
#include "IStorageManager.h"
|
#include "IStorageManager.h"
|
||||||
#include "LedControl.h"
|
#include "LedControl.h"
|
||||||
#include "LedsHandle.h"
|
#include "LedsHandle.h"
|
||||||
|
#include "MediaTask.h"
|
||||||
#include "MissionStateMachine.h"
|
#include "MissionStateMachine.h"
|
||||||
#include "StatusCode.h"
|
#include "StatusCode.h"
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
using std::placeholders::_1;
|
using std::placeholders::_1;
|
||||||
SdCardHandleState::SdCardHandleState() : State("SdCardHandleState"), mSdCardStatus(StorageEvent::END)
|
SdCardHandleState::SdCardHandleState() : State("SdCardHandleState"), mSdCardStatus(StorageEvent::END)
|
||||||
{
|
{
|
||||||
|
@ -67,20 +69,37 @@ bool SdCardHandleState::MediaReportHandle(VStateMachineData *msg)
|
||||||
LogError("nullptr pointer.\n");
|
LogError("nullptr pointer.\n");
|
||||||
return NOT_EXECUTED;
|
return NOT_EXECUTED;
|
||||||
}
|
}
|
||||||
|
InfoToBeSaved info = IFilesManager::GetInstance()->GetInfoForSavingFiles(1);
|
||||||
|
auto targetFile = MediaTask::GetFileNameBySeriaNumber(info.mSerialNumber, data->mData.mFileName, info.mSavingPath);
|
||||||
|
auto fileSize = MediaTask::GetFileSize_KB(data->mData.mFileName.c_str());
|
||||||
|
auto createTime = MediaTask::GetCreateTime_s();
|
||||||
|
auto createType = MissionStateMachine::GetInstance()->GetFileCreateType();
|
||||||
|
SyncFileInfo file(info.mSerialNumber,
|
||||||
|
// data->mData.mFileName,
|
||||||
|
targetFile,
|
||||||
|
fileSize,
|
||||||
|
data->mData.mDuration_ms,
|
||||||
|
createTime,
|
||||||
|
createType,
|
||||||
|
FileStatus::FINISHED_RECORD);
|
||||||
|
file.mSourceFile = data->mData.mFileName;
|
||||||
if (StorageEvent::SD_CARD_INSERT != mSdCardStatus) {
|
if (StorageEvent::SD_CARD_INSERT != mSdCardStatus) {
|
||||||
/**
|
/**
|
||||||
* @brief The SD card has not been mounted yet, cache the data for the quick start first.
|
* @brief The SD card has not been mounted yet, cache the data for the quick start first.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
LogWarning("Sd card is not inserted, cache data.\n");
|
LogWarning("Sd card is not inserted, cache data.\n");
|
||||||
mFileNeedToSave = std::make_shared<SaveFileInfo>(data->mData.mFileName);
|
// mFileNeedToSave = std::make_shared<SaveFileInfo>(data->mData.mFileName);
|
||||||
|
mFastStartMediaFiles.push_back(file);
|
||||||
return EXECUTED;
|
return EXECUTED;
|
||||||
}
|
}
|
||||||
LogInfo("file = %s.\n", data->mData.mFileName.c_str());
|
LogInfo("file = %s.\n", data->mData.mFileName.c_str());
|
||||||
SaveFileInfo saveFileInfo(data->mData.mFileName);
|
std::vector<SyncFileInfo> files;
|
||||||
StatusCode code = IFilesManager::GetInstance()->SaveFile(saveFileInfo);
|
files.push_back(file);
|
||||||
|
// SaveFileInfo saveFileInfo(data->mData.mFileName);
|
||||||
|
StatusCode code = IFilesManager::GetInstance()->SaveFiles(files);
|
||||||
if (IsCodeOK(code) == false) {
|
if (IsCodeOK(code) == false) {
|
||||||
LogError("SaveFile failed.\n");
|
LogError("SaveFiles failed.\n");
|
||||||
}
|
}
|
||||||
return EXECUTED;
|
return EXECUTED;
|
||||||
}
|
}
|
||||||
|
@ -90,14 +109,16 @@ bool SdCardHandleState::SdCardEventHandle(VStateMachineData *msg)
|
||||||
std::shared_ptr<VMissionDataV2<StorageEvent>> data =
|
std::shared_ptr<VMissionDataV2<StorageEvent>> data =
|
||||||
std::dynamic_pointer_cast<VMissionDataV2<StorageEvent>>(message->mMissionData);
|
std::dynamic_pointer_cast<VMissionDataV2<StorageEvent>>(message->mMissionData);
|
||||||
LogInfo(" SdCardEventHandle event:%s.\n", IStorageManager::GetInstance()->PrintStringStorageEvent(data->mData));
|
LogInfo(" SdCardEventHandle event:%s.\n", IStorageManager::GetInstance()->PrintStringStorageEvent(data->mData));
|
||||||
if (mFileNeedToSave && StorageEvent::SD_CARD_INSERT == data->mData) {
|
// if (!mFastStartMediaFiles.empty() && StorageEvent::SD_CARD_INSERT == data->mData) {
|
||||||
LogInfo("Sd card is inserted for the first time.\n");
|
// LogInfo("Sd card is inserted for the first time.\n");
|
||||||
StatusCode code = IFilesManager::GetInstance()->SaveFile(*(mFileNeedToSave.get()));
|
// // StatusCode code = IFilesManager::GetInstance()->SaveFile(*(mFileNeedToSave.get()));
|
||||||
if (IsCodeOK(code) == false) {
|
// StatusCode code = IFilesManager::GetInstance()->SaveFiles(mFastStartMediaFiles);
|
||||||
LogError("SaveFile failed.\n");
|
// if (IsCodeOK(code) == false) {
|
||||||
}
|
// LogError("SaveFile failed.\n");
|
||||||
mFileNeedToSave.reset();
|
// }
|
||||||
}
|
// // mFileNeedToSave.reset();
|
||||||
|
// mFastStartMediaFiles.clear();
|
||||||
|
// }
|
||||||
mSdCardStatus = data->mData;
|
mSdCardStatus = data->mData;
|
||||||
/**
|
/**
|
||||||
* @brief The file management uses a database. When the SD card is inserted or removed, the card's file data needs
|
* @brief The file management uses a database. When the SD card is inserted or removed, the card's file data needs
|
||||||
|
@ -108,6 +129,16 @@ bool SdCardHandleState::SdCardEventHandle(VStateMachineData *msg)
|
||||||
std::shared_ptr<VMissionData> message =
|
std::shared_ptr<VMissionData> message =
|
||||||
std::make_shared<VMissionData>(static_cast<MissionEvent>(InternalStateEvent::CHECK_UPGRADE_FILE));
|
std::make_shared<VMissionData>(static_cast<MissionEvent>(InternalStateEvent::CHECK_UPGRADE_FILE));
|
||||||
MissionStateMachine::GetInstance()->SendStateMessage(message);
|
MissionStateMachine::GetInstance()->SendStateMessage(message);
|
||||||
|
if (!mFastStartMediaFiles.empty()) {
|
||||||
|
LogInfo("Sd card is inserted for the first time.\n");
|
||||||
|
// StatusCode code = IFilesManager::GetInstance()->SaveFile(*(mFileNeedToSave.get()));
|
||||||
|
StatusCode code = IFilesManager::GetInstance()->SaveFiles(mFastStartMediaFiles);
|
||||||
|
if (IsCodeOK(code) == false) {
|
||||||
|
LogError("SaveFile failed.\n");
|
||||||
|
}
|
||||||
|
// mFileNeedToSave.reset();
|
||||||
|
mFastStartMediaFiles.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
IFilesManager::GetInstance()->UnInit();
|
IFilesManager::GetInstance()->UnInit();
|
||||||
|
|
|
@ -45,6 +45,7 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
StorageEvent mSdCardStatus;
|
StorageEvent mSdCardStatus;
|
||||||
std::shared_ptr<SaveFileInfo> mFileNeedToSave;
|
std::shared_ptr<SaveFileInfo> mFileNeedToSave; // TODO: delete.
|
||||||
|
std::vector<SyncFileInfo> mFastStartMediaFiles;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
|
@ -51,7 +51,7 @@ bool TopState::ExecuteStateMsg(VStateMachineData *msg)
|
||||||
}
|
}
|
||||||
StatusCode TopState::ReportEvent(const MediaReportEvent &event)
|
StatusCode TopState::ReportEvent(const MediaReportEvent &event)
|
||||||
{
|
{
|
||||||
LogInfo(" ReportEvent:\n");
|
LogInfo("Application recv media event(fast start).\n");
|
||||||
std::shared_ptr<VMissionData> message = std::make_shared<VMissionDataV2<MediaReportEvent>>(
|
std::shared_ptr<VMissionData> message = std::make_shared<VMissionDataV2<MediaReportEvent>>(
|
||||||
static_cast<MissionEvent>(InternalStateEvent::MEDIA_REPORT_EVENT), event);
|
static_cast<MissionEvent>(InternalStateEvent::MEDIA_REPORT_EVENT), event);
|
||||||
MissionStateMachine::GetInstance()->SendStateMessage(message);
|
MissionStateMachine::GetInstance()->SendStateMessage(message);
|
||||||
|
|
|
@ -18,8 +18,9 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
camera_report_event::camera_report_event(const std::string &fileName, const CameraType &cameraType)
|
camera_report_event::camera_report_event(const std::string &fileName, const CameraType &cameraType,
|
||||||
: mFileName(fileName), mCameraType(cameraType)
|
const unsigned int &duration_ms)
|
||||||
|
: mFileName(fileName), mCameraType(cameraType), mDuration_ms(duration_ms)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void VKeyHalMonitor::KeyEventHappened(const std::string &keyName, const VirtualKeyEvent &event,
|
void VKeyHalMonitor::KeyEventHappened(const std::string &keyName, const VirtualKeyEvent &event,
|
||||||
|
|
|
@ -50,9 +50,10 @@ enum class CameraTaskType
|
||||||
};
|
};
|
||||||
typedef struct camera_report_event
|
typedef struct camera_report_event
|
||||||
{
|
{
|
||||||
camera_report_event(const std::string &fileName, const CameraType &cameraType);
|
camera_report_event(const std::string &fileName, const CameraType &cameraType, const unsigned int &duration_ms);
|
||||||
const std::string mFileName;
|
const std::string mFileName;
|
||||||
const CameraType mCameraType;
|
const CameraType mCameraType;
|
||||||
|
const unsigned int mDuration_ms;
|
||||||
} CameraReportEvent;
|
} CameraReportEvent;
|
||||||
void CreateHalCppModule(void);
|
void CreateHalCppModule(void);
|
||||||
void DestroyHalCppModule(void);
|
void DestroyHalCppModule(void);
|
||||||
|
|
|
@ -32,7 +32,7 @@ void CameraHal::UnInit(void)
|
||||||
void CameraHal::SetCameraMonitor(std::shared_ptr<VCameraHalMonitor> &monitor)
|
void CameraHal::SetCameraMonitor(std::shared_ptr<VCameraHalMonitor> &monitor)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> locker(mMutex);
|
std::lock_guard<std::mutex> locker(mMutex);
|
||||||
LogInfo("ssssssssssssssssssssssssssssssssssssSetCameraMonitor.\n");
|
LogInfo("SetCameraMonitor.\n");
|
||||||
mCameraMonitor = monitor;
|
mCameraMonitor = monitor;
|
||||||
if (nullptr != mFastBootEvent) {
|
if (nullptr != mFastBootEvent) {
|
||||||
monitor->ReportEvent(*(mFastBootEvent.get()));
|
monitor->ReportEvent(*(mFastBootEvent.get()));
|
||||||
|
@ -127,16 +127,16 @@ void CameraHal::FastStartGetJpegData(const void *stream, const unsigned int &len
|
||||||
auto monitor = mCameraMonitor.lock();
|
auto monitor = mCameraMonitor.lock();
|
||||||
if (mCameraMonitor.expired()) {
|
if (mCameraMonitor.expired()) {
|
||||||
LogWarning("SdCardHal: monitor is expired.\n");
|
LogWarning("SdCardHal: monitor is expired.\n");
|
||||||
mFastBootEvent = std::make_shared<CameraReportEvent>(savedFile, CameraType::MAIN_CAMERA);
|
mFastBootEvent = std::make_shared<CameraReportEvent>(savedFile, CameraType::MAIN_CAMERA, 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
CameraReportEvent report(savedFile, CameraType::MAIN_CAMERA);
|
CameraReportEvent report(savedFile, CameraType::MAIN_CAMERA, 0);
|
||||||
monitor->ReportEvent(report);
|
monitor->ReportEvent(report);
|
||||||
}
|
}
|
||||||
std::string CameraHal::SaveJpeg(const void *data, unsigned int dataLength)
|
std::string CameraHal::SaveJpeg(const void *data, unsigned int dataLength)
|
||||||
{
|
{
|
||||||
const std::string SAVE_JPEG_FAILED = "";
|
const std::string SAVE_JPEG_FAILED = "";
|
||||||
const std::string SaveJpegPath = "/tmp/fastboot.jpg";
|
const std::string SaveJpegPath = "/tmp/fastboot.jpeg";
|
||||||
FILE *fp = nullptr;
|
FILE *fp = nullptr;
|
||||||
fp = fopen(SaveJpegPath.c_str(), "wb");
|
fp = fopen(SaveJpegPath.c_str(), "wb");
|
||||||
if (fp) {
|
if (fp) {
|
||||||
|
|
|
@ -39,7 +39,7 @@ enum class FileStatus
|
||||||
UPLOADED,
|
UPLOADED,
|
||||||
END
|
END
|
||||||
};
|
};
|
||||||
constexpr unsigned long UNDEFINE_SERIAL_NUMBER = -1;
|
constexpr unsigned long UNDEFINE_SERIAL_NUMBER = 0;
|
||||||
constexpr unsigned long UNDEFINE_FILE_SIZE = 0;
|
constexpr unsigned long UNDEFINE_FILE_SIZE = 0;
|
||||||
constexpr unsigned long UNDEFINE_FILE_DURATION = 0;
|
constexpr unsigned long UNDEFINE_FILE_DURATION = 0;
|
||||||
constexpr time_t UNDEFINE_CREATE_TIME = -1;
|
constexpr time_t UNDEFINE_CREATE_TIME = -1;
|
||||||
|
@ -50,6 +50,7 @@ typedef struct sync_file_info
|
||||||
const FileStatus &status);
|
const FileStatus &status);
|
||||||
const unsigned long mSerialNumber;
|
const unsigned long mSerialNumber;
|
||||||
const std::string mFileName;
|
const std::string mFileName;
|
||||||
|
std::string mSourceFile; ///< If the source file exists, it will be copied to overwrite the mFileName.
|
||||||
const unsigned int mFileSize;
|
const unsigned int mFileSize;
|
||||||
const unsigned int mFileDuration;
|
const unsigned int mFileDuration;
|
||||||
const time_t mCreateTime_s;
|
const time_t mCreateTime_s;
|
||||||
|
@ -64,8 +65,8 @@ typedef struct save_file_info
|
||||||
typedef struct info_to_be_saved
|
typedef struct info_to_be_saved
|
||||||
{
|
{
|
||||||
info_to_be_saved(const unsigned long &serialNumber, const std::string mSavingPath);
|
info_to_be_saved(const unsigned long &serialNumber, const std::string mSavingPath);
|
||||||
const unsigned long mSerialNumber;
|
const unsigned long mSerialNumber; ///< The unique key value of the file in the database.
|
||||||
const std::string mSavingPath;
|
const std::string mSavingPath; ///< The path where the file will be saved.
|
||||||
} InfoToBeSaved;
|
} InfoToBeSaved;
|
||||||
bool CreateFilesManagerModule(void);
|
bool CreateFilesManagerModule(void);
|
||||||
bool DestroyFilesManagerModule(void);
|
bool DestroyFilesManagerModule(void);
|
||||||
|
@ -77,8 +78,14 @@ public:
|
||||||
static std::shared_ptr<IFilesManager> &GetInstance(std::shared_ptr<IFilesManager> *impl = nullptr);
|
static std::shared_ptr<IFilesManager> &GetInstance(std::shared_ptr<IFilesManager> *impl = nullptr);
|
||||||
virtual StatusCode Init(void);
|
virtual StatusCode Init(void);
|
||||||
virtual StatusCode UnInit(void);
|
virtual StatusCode UnInit(void);
|
||||||
virtual StatusCode SaveFile(const SaveFileInfo &fileInfo);
|
virtual StatusCode SaveFile(const SaveFileInfo &fileInfo); // TODO: delete
|
||||||
virtual InfoToBeSaved GetInfoForSavingFiles(const unsigned int &count);
|
virtual InfoToBeSaved GetInfoForSavingFiles(const unsigned int &count);
|
||||||
|
/**
|
||||||
|
* @brief Synchronize file information.
|
||||||
|
*
|
||||||
|
* @param info
|
||||||
|
* @return StatusCode
|
||||||
|
*/
|
||||||
virtual StatusCode SaveFiles(const std::vector<SyncFileInfo> &info);
|
virtual StatusCode SaveFiles(const std::vector<SyncFileInfo> &info);
|
||||||
virtual StatusCode GetAllFiles(std::vector<SyncFileInfo> &info);
|
virtual StatusCode GetAllFiles(std::vector<SyncFileInfo> &info);
|
||||||
virtual StatusCode GetFiles(const std::vector<FileCreateType> &types, std::vector<SyncFileInfo> &info);
|
virtual StatusCode GetFiles(const std::vector<FileCreateType> &types, std::vector<SyncFileInfo> &info);
|
||||||
|
|
|
@ -25,7 +25,7 @@ public:
|
||||||
virtual ~FilesDatabase() = default;
|
virtual ~FilesDatabase() = default;
|
||||||
void Init(void);
|
void Init(void);
|
||||||
void UnInit(void);
|
void UnInit(void);
|
||||||
StatusCode DbSaveFile(const SaveFileInfo &fileInfo);
|
StatusCode DbSaveFile(const SaveFileInfo &fileInfo); // TODO: delete
|
||||||
InfoToBeSaved CreateInfoForSavingFiles(const unsigned int &count);
|
InfoToBeSaved CreateInfoForSavingFiles(const unsigned int &count);
|
||||||
StatusCode DbSaveFiles(const std::vector<SyncFileInfo> &info);
|
StatusCode DbSaveFiles(const std::vector<SyncFileInfo> &info);
|
||||||
StatusCode DbGetFiles(const std::vector<FileCreateType> &types, std::vector<SyncFileInfo> &info);
|
StatusCode DbGetFiles(const std::vector<FileCreateType> &types, std::vector<SyncFileInfo> &info);
|
||||||
|
|
|
@ -25,8 +25,8 @@ save_file_info::save_file_info(const std::string &fileName) : mFileName(fileName
|
||||||
sync_file_info::sync_file_info(const unsigned long &serialNumber, const std::string &fileName,
|
sync_file_info::sync_file_info(const unsigned long &serialNumber, const std::string &fileName,
|
||||||
const unsigned int &fileSize, const unsigned int &fileDuration,
|
const unsigned int &fileSize, const unsigned int &fileDuration,
|
||||||
const time_t &createTime_s, const FileCreateType &type, const FileStatus &status)
|
const time_t &createTime_s, const FileCreateType &type, const FileStatus &status)
|
||||||
: mSerialNumber(serialNumber), mFileName(fileName), mFileSize(fileSize), mFileDuration(fileDuration),
|
: mSerialNumber(serialNumber), mFileName(fileName), mSourceFile(""), mFileSize(fileSize),
|
||||||
mCreateTime_s(createTime_s), mType(type), mStatus(status)
|
mFileDuration(fileDuration), mCreateTime_s(createTime_s), mType(type), mStatus(status)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
info_to_be_saved::info_to_be_saved(const unsigned long &serialNumber, const std::string mSavingPath)
|
info_to_be_saved::info_to_be_saved(const unsigned long &serialNumber, const std::string mSavingPath)
|
||||||
|
|
|
@ -57,11 +57,20 @@ InfoToBeSaved FilesDatabase::CreateInfoForSavingFiles(const unsigned int &count)
|
||||||
StatusCode FilesDatabase::DbSaveFiles(const std::vector<SyncFileInfo> &info)
|
StatusCode FilesDatabase::DbSaveFiles(const std::vector<SyncFileInfo> &info)
|
||||||
{
|
{
|
||||||
for (auto &each : info) {
|
for (auto &each : info) {
|
||||||
bool result = SqliteHandle::GetInstance()->SyncFile(each);
|
unsigned long key = UNDEFINE_SERIAL_NUMBER;
|
||||||
|
bool result = SqliteHandle::GetInstance()->SyncFile(each, key);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
LogError("Save file failed.\n");
|
LogError("Save file failed.\n");
|
||||||
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
||||||
}
|
}
|
||||||
|
if (!each.mSourceFile.empty()) {
|
||||||
|
/**
|
||||||
|
* @brief If the source file parameter is passed in, the source file needs to be copied to overwrite the
|
||||||
|
* target file.
|
||||||
|
*/
|
||||||
|
std::string saveFile = SqliteHandle::RenameFileToSync(each.mFileName, key);
|
||||||
|
IStorageManager::GetInstance()->SaveFile(each.mSourceFile, saveFile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return CreateStatusCode(STATUS_CODE_OK);
|
return CreateStatusCode(STATUS_CODE_OK);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <stdio.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -93,7 +94,7 @@ unsigned long int SqliteHandle::CreateFiles(const unsigned int &count)
|
||||||
if (SQLITE_OK != rc) {
|
if (SQLITE_OK != rc) {
|
||||||
LogError("SQL error: %s\n", err_msg);
|
LogError("SQL error: %s\n", err_msg);
|
||||||
sqlite3_free(err_msg);
|
sqlite3_free(err_msg);
|
||||||
return 0;
|
return UNDEFINE_SERIAL_NUMBER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
auto last_rowid_lambda = [](void *last_rowid, int argc, char **argv, char **azColName) -> int {
|
auto last_rowid_lambda = [](void *last_rowid, int argc, char **argv, char **azColName) -> int {
|
||||||
|
@ -101,7 +102,7 @@ unsigned long int SqliteHandle::CreateFiles(const unsigned int &count)
|
||||||
LogInfo("last_rowid key = %s\n", argv[0]);
|
LogInfo("last_rowid key = %s\n", argv[0]);
|
||||||
*(unsigned long int *)last_rowid = strtoul(argv[0], nullptr, 10);
|
*(unsigned long int *)last_rowid = strtoul(argv[0], nullptr, 10);
|
||||||
}
|
}
|
||||||
return 0;
|
return UNDEFINE_SERIAL_NUMBER;
|
||||||
};
|
};
|
||||||
unsigned long int last_rowid = 0;
|
unsigned long int last_rowid = 0;
|
||||||
const char *sql2 = "SELECT last_insert_rowid();";
|
const char *sql2 = "SELECT last_insert_rowid();";
|
||||||
|
@ -109,16 +110,20 @@ unsigned long int SqliteHandle::CreateFiles(const unsigned int &count)
|
||||||
if (SQLITE_OK != rc) {
|
if (SQLITE_OK != rc) {
|
||||||
LogError("SQL error: %s\n", err_msg);
|
LogError("SQL error: %s\n", err_msg);
|
||||||
sqlite3_free(err_msg);
|
sqlite3_free(err_msg);
|
||||||
return 0;
|
return UNDEFINE_SERIAL_NUMBER;
|
||||||
}
|
}
|
||||||
constexpr int MINIMUM_AUTO_INCREMENT_PRIMARY_KEY = 1;
|
constexpr int MINIMUM_AUTO_INCREMENT_PRIMARY_KEY = 1;
|
||||||
return last_rowid - count + MINIMUM_AUTO_INCREMENT_PRIMARY_KEY;
|
return last_rowid - count + MINIMUM_AUTO_INCREMENT_PRIMARY_KEY;
|
||||||
}
|
}
|
||||||
bool SqliteHandle::SyncFile(const SyncFileInfo &info)
|
bool SqliteHandle::SyncFile(const SyncFileInfo &info, unsigned long &key)
|
||||||
{
|
{
|
||||||
if (UNDEFINE_SERIAL_NUMBER == info.mSerialNumber) {
|
unsigned long serialNumber = info.mSerialNumber;
|
||||||
LogError("Serial number is undefine.\n");
|
std::string fileName = info.mFileName;
|
||||||
return false;
|
if (UNDEFINE_SERIAL_NUMBER == serialNumber) {
|
||||||
|
LogWarning("Serial number is undefine, create new one.\n");
|
||||||
|
serialNumber = CreateFiles(1);
|
||||||
|
key = serialNumber;
|
||||||
|
fileName = SqliteHandle::RenameFileToSync(fileName, key);
|
||||||
}
|
}
|
||||||
std::stringstream sqlStream;
|
std::stringstream sqlStream;
|
||||||
std::string comma = " ";
|
std::string comma = " ";
|
||||||
|
@ -128,7 +133,7 @@ bool SqliteHandle::SyncFile(const SyncFileInfo &info)
|
||||||
comma = ", ";
|
comma = ", ";
|
||||||
}
|
}
|
||||||
if (info.mFileName.empty() == false) {
|
if (info.mFileName.empty() == false) {
|
||||||
sqlStream << comma << FILE_PATH " = '" << info.mFileName << "'";
|
sqlStream << comma << FILE_PATH " = '" << fileName << "'";
|
||||||
comma = ", ";
|
comma = ", ";
|
||||||
}
|
}
|
||||||
if (UNDEFINE_FILE_SIZE != info.mFileSize) {
|
if (UNDEFINE_FILE_SIZE != info.mFileSize) {
|
||||||
|
@ -147,7 +152,7 @@ bool SqliteHandle::SyncFile(const SyncFileInfo &info)
|
||||||
sqlStream << comma << FILE_DURATION " = '" << info.mFileDuration << "'";
|
sqlStream << comma << FILE_DURATION " = '" << info.mFileDuration << "'";
|
||||||
comma = ", ";
|
comma = ", ";
|
||||||
}
|
}
|
||||||
sqlStream << " WHERE " TABLE_KEY " = " << info.mSerialNumber << ";";
|
sqlStream << " WHERE " TABLE_KEY " = " << serialNumber << ";";
|
||||||
LogInfo("Sql: %s\n", sqlStream.str().c_str());
|
LogInfo("Sql: %s\n", sqlStream.str().c_str());
|
||||||
char *errMsg = nullptr;
|
char *errMsg = nullptr;
|
||||||
int rc = SQLITE_UNDEFINE;
|
int rc = SQLITE_UNDEFINE;
|
||||||
|
@ -445,4 +450,16 @@ FileStatus SqliteHandle::ConvertStringToFileStatus(const std::string &status)
|
||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
return FileStatus::END;
|
return FileStatus::END;
|
||||||
|
}
|
||||||
|
std::string SqliteHandle::RenameFileToSync(const std::string &sourceFile, unsigned long &key)
|
||||||
|
{
|
||||||
|
std::string original = sourceFile;
|
||||||
|
const std::string pattern = "???";
|
||||||
|
std::string replacement = std::to_string(key);
|
||||||
|
size_t pos = 0;
|
||||||
|
while ((pos = original.find(pattern, pos)) != std::string::npos) {
|
||||||
|
original.replace(pos, pattern.length(), replacement);
|
||||||
|
pos += replacement.length();
|
||||||
|
}
|
||||||
|
return original;
|
||||||
}
|
}
|
|
@ -30,8 +30,22 @@ public:
|
||||||
static std::shared_ptr<SqliteHandle> &GetInstance(std::shared_ptr<SqliteHandle> *impl = nullptr);
|
static std::shared_ptr<SqliteHandle> &GetInstance(std::shared_ptr<SqliteHandle> *impl = nullptr);
|
||||||
void Init(const std::string &dbFileName);
|
void Init(const std::string &dbFileName);
|
||||||
void UnInit(void);
|
void UnInit(void);
|
||||||
|
/**
|
||||||
|
* @brief Request to create a file and return the minimum value of the file's unique serial number.
|
||||||
|
*
|
||||||
|
* @param count
|
||||||
|
* @return unsigned long int If invalid, returns UNDEFINE_SERIAL_NUMBER.
|
||||||
|
*/
|
||||||
unsigned long int CreateFiles(const unsigned int &count);
|
unsigned long int CreateFiles(const unsigned int &count);
|
||||||
bool SyncFile(const SyncFileInfo &info);
|
/**
|
||||||
|
* @brief Synchronize file information. When the synchronized file number is invalid, a new number will be created
|
||||||
|
* and assigned to the given parameter "key".
|
||||||
|
* @param info
|
||||||
|
* @param key [out] If the key value does not exist, it is created and output as a parameter.
|
||||||
|
* @return true
|
||||||
|
* @return false
|
||||||
|
*/
|
||||||
|
bool SyncFile(const SyncFileInfo &info, unsigned long &key);
|
||||||
bool SearchFiles(const std::vector<FileCreateType> &types, std::vector<SyncFileInfo> &info);
|
bool SearchFiles(const std::vector<FileCreateType> &types, std::vector<SyncFileInfo> &info);
|
||||||
bool Remove();
|
bool Remove();
|
||||||
bool Modified();
|
bool Modified();
|
||||||
|
@ -51,6 +65,9 @@ private:
|
||||||
static std::string ConvertFileStatusToString(const FileStatus &status);
|
static std::string ConvertFileStatusToString(const FileStatus &status);
|
||||||
static FileStatus ConvertStringToFileStatus(const std::string &status);
|
static FileStatus ConvertStringToFileStatus(const std::string &status);
|
||||||
|
|
||||||
|
public:
|
||||||
|
static std::string RenameFileToSync(const std::string &sourceFile, unsigned long &key);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
sqlite3 *mDb;
|
sqlite3 *mDb;
|
||||||
};
|
};
|
||||||
|
|
|
@ -41,9 +41,10 @@ enum class MediaTaskType
|
||||||
};
|
};
|
||||||
typedef struct media_report_event
|
typedef struct media_report_event
|
||||||
{
|
{
|
||||||
media_report_event(const std::string &fileName, const MediaChannel &mediaChannedl);
|
media_report_event(const std::string &fileName, const MediaChannel &mediaChannedl, const unsigned int &duration_ms);
|
||||||
const std::string mFileName;
|
const std::string mFileName;
|
||||||
const MediaChannel mMediaChannedl;
|
const MediaChannel mMediaChannedl;
|
||||||
|
const unsigned int mDuration_ms;
|
||||||
} MediaReportEvent;
|
} MediaReportEvent;
|
||||||
typedef struct media_task_response
|
typedef struct media_task_response
|
||||||
{
|
{
|
||||||
|
|
|
@ -18,8 +18,9 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
media_report_event::media_report_event(const std::string &fileName, const MediaChannel &mediaChannedl)
|
media_report_event::media_report_event(const std::string &fileName, const MediaChannel &mediaChannedl,
|
||||||
: mFileName(fileName), mMediaChannedl(mediaChannedl)
|
const unsigned int &duration_ms)
|
||||||
|
: mFileName(fileName), mMediaChannedl(mediaChannedl), mDuration_ms(duration_ms)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
media_task_response::media_task_response(const std::string &fileName, const unsigned int &duration_ms)
|
media_task_response::media_task_response(const std::string &fileName, const unsigned int &duration_ms)
|
||||||
|
|
|
@ -51,7 +51,7 @@ StatusCode MediaManagerImpl::SetMediaMonitor(std::shared_ptr<VMediaMonitor> &mon
|
||||||
void MediaManagerImpl::ReportEvent(const CameraReportEvent &event)
|
void MediaManagerImpl::ReportEvent(const CameraReportEvent &event)
|
||||||
{
|
{
|
||||||
LogInfo("ReportEvent. file: %s.\n", event.mFileName.c_str());
|
LogInfo("ReportEvent. file: %s.\n", event.mFileName.c_str());
|
||||||
MediaReportEvent reprot(event.mFileName, static_cast<MediaChannel>(event.mCameraType));
|
MediaReportEvent reprot(event.mFileName, static_cast<MediaChannel>(event.mCameraType), event.mDuration_ms);
|
||||||
auto monitor = mMediaMonitor.lock();
|
auto monitor = mMediaMonitor.lock();
|
||||||
if (mMediaMonitor.expired()) {
|
if (mMediaMonitor.expired()) {
|
||||||
LogWarning("MediaMonitor is expired.\n");
|
LogWarning("MediaMonitor is expired.\n");
|
||||||
|
|
|
@ -66,14 +66,18 @@ StatusCode SdCardHandle::SdSaveFile(const std::string &sourceFile, const std::st
|
||||||
LogInfo("SaveFile: %s -> %s", sourceFile.c_str(), savePaht.c_str());
|
LogInfo("SaveFile: %s -> %s", sourceFile.c_str(), savePaht.c_str());
|
||||||
constexpr int CMD_BUF_SIZE = 128;
|
constexpr int CMD_BUF_SIZE = 128;
|
||||||
char cmd[CMD_BUF_SIZE] = {0};
|
char cmd[CMD_BUF_SIZE] = {0};
|
||||||
const std::string realSavePah = SD_CARD_MOUNT_PATH + savePaht;
|
const std::string realSavePah = savePaht;
|
||||||
bool directoryExist = StorageBase::CheckDirectory(realSavePah.c_str());
|
bool directoryExist = StorageBase::CheckDirectory(realSavePah.c_str());
|
||||||
if (false == directoryExist) {
|
if (false == directoryExist) {
|
||||||
LogError("Directory not exist.\n");
|
LogError("Directory not exist.\n");
|
||||||
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
||||||
}
|
}
|
||||||
snprintf(cmd, CMD_BUF_SIZE, "cp %s %s", sourceFile.c_str(), realSavePah.c_str());
|
snprintf(cmd, CMD_BUF_SIZE, "cp %s %s", sourceFile.c_str(), realSavePah.c_str());
|
||||||
fx_system_v2(cmd);
|
LogInfo("cmd: %s", cmd);
|
||||||
|
int ret = fx_system_v2(cmd);
|
||||||
|
if (ret != 0) {
|
||||||
|
LogError("Save file failed.\n");
|
||||||
|
}
|
||||||
fx_system_v2("sync");
|
fx_system_v2("sync");
|
||||||
return CreateStatusCode(STATUS_CODE_OK);
|
return CreateStatusCode(STATUS_CODE_OK);
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -54,6 +54,21 @@ TEST_F(HuntingCameraTest, INTEGRATION_HunttingCamera_EXAMPLE_TakePicture)
|
||||||
MainThread::GetInstance()->Runing();
|
MainThread::GetInstance()->Runing();
|
||||||
}
|
}
|
||||||
// ../output_files/test/bin/HuntingCameraTest
|
// ../output_files/test/bin/HuntingCameraTest
|
||||||
|
// --gtest_filter=HuntingCameraTest.INTEGRATION_HunttingCamera_EXAMPLE_FastStartMediaHandle
|
||||||
|
TEST_F(HuntingCameraTest, INTEGRATION_HunttingCamera_EXAMPLE_FastStartMediaHandle)
|
||||||
|
{
|
||||||
|
McuManagerTestTool::MockOtherSideIpcMissionReply(IpcMission::TEST);
|
||||||
|
SetAllCamerasResult(mAllCamerasMock);
|
||||||
|
HalTestTool::MockSdCardRemove(mLinuxTest);
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
|
MainThread::GetInstance()->Init();
|
||||||
|
TestManager::ResetTimeOut(1000 * 5);
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||||
|
HalTestTool::MockSdCardInsert(mLinuxTest);
|
||||||
|
HalTestTool::MockKeyClick("reset", 200); // Simulate pressing a button.
|
||||||
|
MainThread::GetInstance()->Runing();
|
||||||
|
}
|
||||||
|
// ../output_files/test/bin/HuntingCameraTest
|
||||||
// --gtest_filter=HuntingCameraTest.INTEGRATION_HunttingCamera_EXAMPLE_MediaTask
|
// --gtest_filter=HuntingCameraTest.INTEGRATION_HunttingCamera_EXAMPLE_MediaTask
|
||||||
TEST_F(HuntingCameraTest, INTEGRATION_HunttingCamera_EXAMPLE_MediaTask)
|
TEST_F(HuntingCameraTest, INTEGRATION_HunttingCamera_EXAMPLE_MediaTask)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user