mirror of
https://gitee.com/jiuyilian/embedded-framework.git
synced 2025-01-06 10:16:51 -05:00
Fixed:save file in sd card ok.
This commit is contained in:
parent
f5043e8efe
commit
2d495b6f00
|
@ -45,6 +45,9 @@ bool SdCardHandleState::MediaReportHandle(VStateMachineData *msg)
|
|||
}
|
||||
LogInfo("file = %s.\n", data->mData.mFileName.c_str());
|
||||
SaveFileInfo saveFileInfo(data->mData.mFileName);
|
||||
IFilesManager::GetInstance()->SaveFile(saveFileInfo);
|
||||
StatusCode code = IFilesManager::GetInstance()->SaveFile(saveFileInfo);
|
||||
if (IsCodeOK(code) == false) {
|
||||
LogError("SaveFile failed.\n");
|
||||
}
|
||||
return EXECUTED;
|
||||
}
|
|
@ -62,29 +62,36 @@ std::shared_ptr<IHalCpp> &IHalCpp::GetInstance(std::shared_ptr<IHalCpp> *impl)
|
|||
}
|
||||
void VSdCardHal::SetSdCardMonitor(std::shared_ptr<VSdCardHalMonitor> &monitor)
|
||||
{
|
||||
LogWarning("STATUS_CODE_VIRTUAL_FUNCTION.\n");
|
||||
}
|
||||
SdCardHalStatus VSdCardHal::GetSdCardStatus(void)
|
||||
{
|
||||
LogWarning("STATUS_CODE_VIRTUAL_FUNCTION.\n");
|
||||
return SdCardHalStatus::END;
|
||||
}
|
||||
StatusCode IHalCpp::Init(void)
|
||||
{
|
||||
LogWarning("STATUS_CODE_VIRTUAL_FUNCTION.\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode IHalCpp::UnInit(void)
|
||||
{
|
||||
LogWarning("STATUS_CODE_VIRTUAL_FUNCTION.\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode IHalCpp::GetAllLeds(std::map<std::string, std::shared_ptr<VLedHal>> &allLeds)
|
||||
{
|
||||
LogWarning("STATUS_CODE_VIRTUAL_FUNCTION.\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode IHalCpp::GetAllKeys(std::map<std::string, std::shared_ptr<VKeyHal>> &allKeys)
|
||||
{
|
||||
LogWarning("STATUS_CODE_VIRTUAL_FUNCTION.\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode IHalCpp::GetWifiHal(std::shared_ptr<VWifiHal> &wifi)
|
||||
{
|
||||
LogWarning("STATUS_CODE_VIRTUAL_FUNCTION.\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode IHalCpp::GetCameraHal(std::map<CameraType, std::shared_ptr<VCameraHal>> &allCameras)
|
||||
|
@ -94,5 +101,6 @@ StatusCode IHalCpp::GetCameraHal(std::map<CameraType, std::shared_ptr<VCameraHal
|
|||
}
|
||||
StatusCode IHalCpp::GetSdCardHal(std::shared_ptr<VSdCardHal> &sdCard)
|
||||
{
|
||||
LogWarning("STATUS_CODE_VIRTUAL_FUNCTION.\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
|
@ -101,12 +101,6 @@ void SdCardHal::DevDetectingThread(void)
|
|||
void SdCardHal::ReportDetecedChangedResult(const SdCardHalStatus &status)
|
||||
{
|
||||
LogInfo("SdCardHalStatus changed: %s.\n", PrintfStatusString(status));
|
||||
auto monitor = mMonitor.lock();
|
||||
if (mMonitor.expired()) {
|
||||
LogWarning("SdCardHal: monitor is expired.\n");
|
||||
return;
|
||||
}
|
||||
monitor->ReportEvent(status);
|
||||
if (SdCardHalStatus::INSERTED == status) {
|
||||
LogInfo("mount sd SD_CARD_DEVICE %s.\n", SD_CARD_MOUNT_PATH);
|
||||
constexpr int BUF_LENGTH = 128;
|
||||
|
@ -114,6 +108,12 @@ void SdCardHal::ReportDetecedChangedResult(const SdCardHalStatus &status)
|
|||
snprintf(cmd, BUF_LENGTH, "mount %s %s", SD_CARD_DEV, SD_CARD_MOUNT_PATH);
|
||||
fx_system(cmd);
|
||||
}
|
||||
auto monitor = mMonitor.lock();
|
||||
if (mMonitor.expired()) {
|
||||
LogWarning("SdCardHal: monitor is expired.\n");
|
||||
return;
|
||||
}
|
||||
monitor->ReportEvent(status);
|
||||
}
|
||||
const char *SdCardHal::PrintfStatusString(const SdCardHalStatus &status)
|
||||
{
|
||||
|
|
|
@ -49,13 +49,15 @@ StatusCode SdCardHandle::SdSaveFile(const std::string &sourceFile, const std::st
|
|||
LogInfo("SaveFile: %s -> %s", sourceFile.c_str(), savePaht.c_str());
|
||||
constexpr int CMD_BUF_SIZE = 128;
|
||||
char cmd[CMD_BUF_SIZE] = {0};
|
||||
bool directoryExist = StorageBase::CheckDirectory((SD_CARD_MOUNT_PATH + savePaht).c_str());
|
||||
const std::string realSavePah = SD_CARD_MOUNT_PATH + savePaht;
|
||||
bool directoryExist = StorageBase::CheckDirectory(realSavePah.c_str());
|
||||
if (false == directoryExist) {
|
||||
LogInfo("Directory not exist.\n");
|
||||
LogError("Directory not exist.\n");
|
||||
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
||||
}
|
||||
snprintf(cmd, CMD_BUF_SIZE, "cp %s %s", sourceFile.c_str(), savePaht.c_str());
|
||||
snprintf(cmd, CMD_BUF_SIZE, "cp %s %s", sourceFile.c_str(), realSavePah.c_str());
|
||||
fx_system(cmd);
|
||||
fx_system("sync");
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StorageEvent SdCardHandle::StorageEventConvert(const SdCardHalStatus &status)
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <sys/types.h>
|
||||
bool StorageBase::CheckDirectory(const char *filepath)
|
||||
{
|
||||
LogInfo("CheckDirectory:%s\n", filepath);
|
||||
char *path = nullptr;
|
||||
char *sep = nullptr;
|
||||
struct stat st = {0};
|
||||
|
@ -33,10 +34,14 @@ bool StorageBase::CheckDirectory(const char *filepath)
|
|||
|
||||
for (sep = strchr(path, '/'); sep != NULL; sep = strchr(sep + 1, '/')) {
|
||||
*sep = '\0';
|
||||
if (strlen(path) == 0) {
|
||||
*sep = '/';
|
||||
continue;
|
||||
}
|
||||
if (stat(path, &st) == -1) {
|
||||
if (errno == ENOENT) {
|
||||
if (mkdir(path, 0755) == -1) {
|
||||
LogError("mkdir\n");
|
||||
LogError("mkdir path failed:%s\n", path);
|
||||
free(path);
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user