196 lines
6.7 KiB
C++
196 lines
6.7 KiB
C++
/*
|
|
* 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 "AppMonitor.h"
|
|
#include "IAppManager.h"
|
|
#include "IFilesManager.h"
|
|
#include "ILog.h"
|
|
#include "IStorageManager.h"
|
|
#include "StatusCode.h"
|
|
#include <vector>
|
|
AppMonitor::AppMonitor() : mMicStatus(SwitchStatus::END)
|
|
{
|
|
}
|
|
StatusCode AppMonitor::GetProductInfo(AppGetProductInfo ¶m)
|
|
{
|
|
LogInfo("AppMonitor::GetProductInfo.\n");
|
|
param.mModel = "test";
|
|
param.mCompany = "test";
|
|
param.mSoc = "test";
|
|
param.mSp = "test";
|
|
return CreateStatusCode(STATUS_CODE_OK);
|
|
}
|
|
StatusCode AppMonitor::GetDeviceAttr(AppGetDeviceAttr ¶m)
|
|
{
|
|
LogInfo("AppMonitor::GetDeviceAttr.\n");
|
|
param.mUUID = "test";
|
|
param.mSoftVersion = "test";
|
|
param.mOtaVersion = "test";
|
|
param.mHardwareVersion = "test";
|
|
param.mSSID = "test";
|
|
param.mBSSID = "test";
|
|
param.mCameraNumber = "test";
|
|
param.mCurrentCameraID = "test";
|
|
param.mWifiReboot = "test";
|
|
return CreateStatusCode(STATUS_CODE_OK);
|
|
}
|
|
StatusCode AppMonitor::GetMediaInfo(AppGetMediaInfo ¶m)
|
|
{
|
|
LogInfo("AppMonitor::GetMediaInfo.\n");
|
|
param.mRtspUrl = "rtsp://192.168.169.1/live/0";
|
|
param.mTransport = "tcp";
|
|
param.mPort = APP_MANAGER_TCP_SERVER_PORT;
|
|
return CreateStatusCode(STATUS_CODE_OK);
|
|
}
|
|
StatusCode AppMonitor::GetSdCardInfo(AppGetSdCardInfo ¶m)
|
|
{
|
|
LogInfo("AppMonitor::GetSdCardInfo.\n");
|
|
SdCardInfo info;
|
|
IStorageManager::GetInstance()->GetSdCardInfo(info);
|
|
param.mStatus = SdCardStatusConvert(info.mEvent);
|
|
param.mFree = info.mFreeSizeMB;
|
|
param.mTotal = info.mTotalSizeMB;
|
|
return CreateStatusCode(STATUS_CODE_OK);
|
|
}
|
|
StatusCode AppMonitor::GetBatteryInfo(AppGetBatteryInfo ¶m)
|
|
{
|
|
LogInfo("AppMonitor::GetBatteryInfo.\n");
|
|
param.mCapacity = 0;
|
|
param.mChargeStatus = ChargeStatus::CHARGING;
|
|
return CreateStatusCode(STATUS_CODE_OK);
|
|
}
|
|
StatusCode AppMonitor::GetParamValue(AppParamValue ¶m)
|
|
{
|
|
param.mMicStatus = mMicStatus;
|
|
param.mRec = SwitchStatus::OFF;
|
|
return CreateStatusCode(STATUS_CODE_OK);
|
|
}
|
|
StatusCode AppMonitor::GetCapability(AppGetCapability ¶m)
|
|
{
|
|
param.mPlaybackType = PlaybackType::DOWNLOAD_PLAYBACK;
|
|
return CreateStatusCode(STATUS_CODE_OK);
|
|
}
|
|
StatusCode AppMonitor::GetLockVideoStatus(LockVideoStatus ¶m)
|
|
{
|
|
param = LockVideoStatus::LOCK;
|
|
return CreateStatusCode(STATUS_CODE_OK);
|
|
}
|
|
StatusCode AppMonitor::GetStorageInfo(std::vector<AppGetStorageInfo> ¶m)
|
|
{
|
|
AppGetStorageInfo info;
|
|
SdCardInfo sdInfo;
|
|
IStorageManager::GetInstance()->GetSdCardInfo(sdInfo);
|
|
info.mIndex = 0;
|
|
info.mName = "TF card 1";
|
|
info.mType = StorageType::SD_CARD_1;
|
|
info.mFree = sdInfo.mFreeSizeMB;
|
|
info.mTotal = sdInfo.mTotalSizeMB;
|
|
param.push_back(info);
|
|
return CreateStatusCode(STATUS_CODE_OK);
|
|
}
|
|
StatusCode AppMonitor::GetStorageFileList(const AppGetFileInfo &fileInfo, std::vector<AppGetFileList> ¶m)
|
|
{
|
|
std::vector<SyncFileInfo> info;
|
|
if (StorageFileEvent::ALL == fileInfo.mEvent) {
|
|
IFilesManager::GetInstance()->GetAllFiles(info);
|
|
}
|
|
else {
|
|
std::vector<FileCreateType> types;
|
|
if (StorageFileEvent::LOOP == fileInfo.mEvent) {
|
|
types.push_back(FileCreateType::TIMED);
|
|
types.push_back(FileCreateType::MANUAL_TEST);
|
|
types.push_back(FileCreateType::MANUAL_PHONE);
|
|
types.push_back(FileCreateType::TIMED);
|
|
}
|
|
if (StorageFileEvent::EMR == fileInfo.mEvent) {
|
|
types.push_back(FileCreateType::PIR);
|
|
}
|
|
if (StorageFileEvent::EVENT == fileInfo.mEvent) {
|
|
types.push_back(FileCreateType::MANUAL_TEST);
|
|
types.push_back(FileCreateType::MANUAL_PHONE);
|
|
}
|
|
if (StorageFileEvent::PARK == fileInfo.mEvent) {
|
|
types.push_back(FileCreateType::TIMED);
|
|
}
|
|
IFilesManager::GetInstance()->GetFiles(types, info);
|
|
}
|
|
const std::string webServerDocumentRoot = IAppManager::GetInstance()->GetFilesSavingRootPath();
|
|
LogInfo("GetStorageFileList: file size = %d, event = %s.\n",
|
|
info.size(),
|
|
IAppManager::GetInstance()->StorageFileEventToString(fileInfo.mEvent));
|
|
for (auto &oneFileInfo : info) {
|
|
AppGetFileList file;
|
|
file.mCreateTime_s = oneFileInfo.mCreateTime_s;
|
|
file.mDuration = oneFileInfo.mFileDuration;
|
|
file.mName = RemovePrefix(oneFileInfo.mFileName, webServerDocumentRoot);
|
|
file.mSize = oneFileInfo.mFileSize;
|
|
file.mType = StorageFileType::VIDEO;
|
|
param.push_back(file);
|
|
}
|
|
return CreateStatusCode(STATUS_CODE_OK);
|
|
}
|
|
StatusCode AppMonitor::SetDateTime(const AppSetDateTime ¶m)
|
|
{
|
|
return CreateStatusCode(STATUS_CODE_OK);
|
|
}
|
|
StatusCode AppMonitor::SetTimeZone(const unsigned int &zone)
|
|
{
|
|
return CreateStatusCode(STATUS_CODE_OK);
|
|
}
|
|
StatusCode AppMonitor::SetParamValue(const AppSetParamValue ¶m)
|
|
{
|
|
LogInfo("SetParamValue: param = %s.\n", param.mName.c_str());
|
|
if (param.mName == "mic") {
|
|
mMicStatus = static_cast<SwitchStatus>(param.mValue);
|
|
}
|
|
return CreateStatusCode(STATUS_CODE_OK);
|
|
}
|
|
StatusCode AppMonitor::EnterRecorder(void)
|
|
{
|
|
return CreateStatusCode(STATUS_CODE_OK);
|
|
}
|
|
StatusCode AppMonitor::AppPlayback(const PlayBackEvent &event)
|
|
{
|
|
return CreateStatusCode(STATUS_CODE_OK);
|
|
}
|
|
StatusCode AppMonitor::UploadFile(AppUploadFile ¶m)
|
|
{
|
|
return CreateStatusCode(STATUS_CODE_OK);
|
|
}
|
|
StatusCode AppMonitor::GetThumbnail(AppGetThumbnail ¶m)
|
|
{
|
|
param.mThumbnail = "./34a396526922a33e97906920dbfef2a5.jpg";
|
|
return CreateStatusCode(STATUS_CODE_OK);
|
|
}
|
|
SdCardStatus AppMonitor::SdCardStatusConvert(const StorageEvent &event)
|
|
{
|
|
switch (event) {
|
|
case StorageEvent::SD_CARD_INSERT:
|
|
return SdCardStatus::NORMAL;
|
|
case StorageEvent::SD_CARD_REMOVE:
|
|
return SdCardStatus::NOT_INSERTED;
|
|
case StorageEvent::SD_ABNORMAL:
|
|
return SdCardStatus::NOT_INSERTED;
|
|
default:
|
|
return SdCardStatus::END;
|
|
}
|
|
}
|
|
std::string AppMonitor::RemovePrefix(const std::string &originalStr, const std::string &prefix)
|
|
{
|
|
if (originalStr.compare(0, prefix.length(), prefix) == 0) {
|
|
return originalStr.substr(prefix.length());
|
|
}
|
|
LogWarning("Something wrong happened, prefix is %s.\n", prefix.c_str());
|
|
return originalStr;
|
|
} |