Improve:IpcConfig module.
This commit is contained in:
parent
95aa8c86c9
commit
7c1a8ddd74
|
@ -55,3 +55,20 @@ void McuManagerImpl::OtherSideSendIpcMission(const unsigned int &serialNumber, c
|
|||
### 1.1.3. C++继承
|
||||
|
||||
* 子类使用父类的函数时,函数前必须加父类名,降低阅读难度,没有父类名的一律为本类函数(有可能是虚函数);
|
||||
|
||||
### 1.1.4. 变量命名
|
||||
|
||||
#### 1.1.4.1. 结构体/类成员
|
||||
|
||||
* 结构体和类成员必须要使用驼峰命名法,且首字母必须为m表示成员变量;
|
||||
|
||||
```
|
||||
typedef struct app_get_product_info
|
||||
{
|
||||
app_get_product_info();
|
||||
std::string mModel;
|
||||
std::string mCompany;
|
||||
std::string mSoc;
|
||||
std::string mSp;
|
||||
} AppGetProductInfo;
|
||||
```
|
||||
|
|
|
@ -26,8 +26,8 @@ enum class IpcConfigKey
|
|||
CONTINUOUS_SHOT,
|
||||
BURST_PHOTO_INTERVAL,
|
||||
IMGAE_SIZE,
|
||||
VIDEO_SIZE,
|
||||
INFRARED_LAMP_POWER,
|
||||
VIDEO_LENGTH,
|
||||
INFRARED_POWER,
|
||||
PIR_DELAYED,
|
||||
PIR_SENSITIVITY,
|
||||
STORAGE_LOOP_SWITCH,
|
||||
|
@ -49,6 +49,19 @@ enum class WorkMode
|
|||
MODE_PIC_VIDEO,
|
||||
END,
|
||||
};
|
||||
enum class ConfigSwitch
|
||||
{
|
||||
OFF = 0,
|
||||
ON,
|
||||
END
|
||||
};
|
||||
enum class ConfigLevel
|
||||
{
|
||||
HIGHT = 0,
|
||||
MIDDLE,
|
||||
LOW,
|
||||
END
|
||||
};
|
||||
enum ContinuousShot
|
||||
{
|
||||
CONTINUOUS_SHOT_ONE_PIC = 1,
|
||||
|
@ -90,6 +103,14 @@ enum PirSensitivity
|
|||
PIR_SENSITIVITY_MAX = 9,
|
||||
PIR_SENSITIVITY_END,
|
||||
};
|
||||
typedef struct working_time
|
||||
{
|
||||
working_time();
|
||||
unsigned char mHourFrom;
|
||||
unsigned char mHourTo;
|
||||
unsigned char mMinuteFrom;
|
||||
unsigned char mMinuteTo;
|
||||
} WorkingTime; // TODO:
|
||||
bool CreateIpcConfigModule(void);
|
||||
bool DestroyIpcConfigModule(void);
|
||||
class IIpcConfig
|
||||
|
@ -123,5 +144,9 @@ public:
|
|||
virtual void SetString(const IpcConfigKey &key, const std::string &string);
|
||||
virtual WorkMode GetWorkMode(void);
|
||||
virtual void SetWorkMode(const WorkMode &mode);
|
||||
virtual ConfigSwitch GetSwitch(const IpcConfigKey &key);
|
||||
virtual void SetSwitch(const IpcConfigKey &key, const ConfigSwitch &value);
|
||||
virtual ConfigLevel GetLevel(const IpcConfigKey &key);
|
||||
virtual void SetLevel(const IpcConfigKey &key, const ConfigLevel &value);
|
||||
};
|
||||
#endif
|
|
@ -14,6 +14,9 @@
|
|||
*/
|
||||
#include "IIpcConfig.h"
|
||||
#include "ILog.h"
|
||||
working_time::working_time() : mHourFrom(0), mHourTo(0), mMinuteFrom(0), mMinuteTo(0)
|
||||
{
|
||||
}
|
||||
std::shared_ptr<IIpcConfig> &IIpcConfig::GetInstance(std::shared_ptr<IIpcConfig> *impl)
|
||||
{
|
||||
static auto instance = std::make_shared<IIpcConfig>();
|
||||
|
@ -117,3 +120,17 @@ WorkMode IIpcConfig::GetWorkMode(void)
|
|||
void IIpcConfig::SetWorkMode(const WorkMode &mode)
|
||||
{
|
||||
}
|
||||
ConfigSwitch IIpcConfig::GetSwitch(const IpcConfigKey &key)
|
||||
{
|
||||
return ConfigSwitch::END;
|
||||
}
|
||||
void IIpcConfig::SetSwitch(const IpcConfigKey &key, const ConfigSwitch &value)
|
||||
{
|
||||
}
|
||||
ConfigLevel IIpcConfig::GetLevel(const IpcConfigKey &key)
|
||||
{
|
||||
return ConfigLevel::END;
|
||||
}
|
||||
void IIpcConfig::SetLevel(const IpcConfigKey &key, const ConfigLevel &value)
|
||||
{
|
||||
}
|
|
@ -23,6 +23,13 @@ const char *CONFIG_WIFI_PASSWORD = "wifi_password";
|
|||
const char *CONFIG_WIFI_PASSWORD_DEFAULT = "123456";
|
||||
const char *CONFIG_WORK_MODE = "work_mode";
|
||||
const char *CONFIG_CONTINUE_SHOT = "continuous_shot";
|
||||
const char *CONFIG_BURST_PHOTO_INTERVAL = "continuous_interval";
|
||||
const char *CONFIG_IMAGE_SIZE = "image_size";
|
||||
const char *CONFIG_VIDEO_SIZE = "video_size";
|
||||
const char *CONFIG_PIR_DELAYED = "pir_delayed";
|
||||
const char *CONFIG_STORAGE_LOOP = "storage_loop";
|
||||
const char *CONFIG_INFRARED_POWER = "infrared_power";
|
||||
const char *CONFIG_PIR_SENSITIVITY = "pir_sensitivity";
|
||||
IpcConfigImpl::IpcConfigImpl()
|
||||
{
|
||||
mCfgChanged = CONFIG_HAS_NOT_CHANGED;
|
||||
|
@ -45,11 +52,46 @@ IpcConfigImpl::IpcConfigImpl()
|
|||
config.insert(std::make_pair(CONFIG_WORK_MODE, &mAllData.mWorkMode));
|
||||
mCfgMapCharV2.insert(std::make_pair(IpcConfigKey::WORK_MODE, config));
|
||||
}
|
||||
{
|
||||
std::map<std::string, char *> config;
|
||||
config.insert(std::make_pair(CONFIG_INFRARED_POWER, &mAllData.mInfraredPower));
|
||||
mCfgMapCharV2.insert(std::make_pair(IpcConfigKey::INFRARED_POWER, config));
|
||||
}
|
||||
{
|
||||
std::map<std::string, int *> config;
|
||||
config.insert(std::make_pair(CONFIG_CONTINUE_SHOT, &mAllData.mContinuousShot));
|
||||
mCfgMapIntV2.insert(std::make_pair(IpcConfigKey::CONTINUOUS_SHOT, config));
|
||||
}
|
||||
{
|
||||
std::map<std::string, int *> config;
|
||||
config.insert(std::make_pair(CONFIG_BURST_PHOTO_INTERVAL, &mAllData.mBurstPhotoInterval));
|
||||
mCfgMapIntV2.insert(std::make_pair(IpcConfigKey::BURST_PHOTO_INTERVAL, config));
|
||||
}
|
||||
{
|
||||
std::map<std::string, int *> config;
|
||||
config.insert(std::make_pair(CONFIG_IMAGE_SIZE, &mAllData.mImageSize));
|
||||
mCfgMapIntV2.insert(std::make_pair(IpcConfigKey::IMGAE_SIZE, config));
|
||||
}
|
||||
{
|
||||
std::map<std::string, int *> config;
|
||||
config.insert(std::make_pair(CONFIG_VIDEO_SIZE, &mAllData.mVideoLength));
|
||||
mCfgMapIntV2.insert(std::make_pair(IpcConfigKey::VIDEO_LENGTH, config));
|
||||
}
|
||||
{
|
||||
std::map<std::string, int *> config;
|
||||
config.insert(std::make_pair(CONFIG_PIR_DELAYED, &mAllData.mPirDelayed));
|
||||
mCfgMapIntV2.insert(std::make_pair(IpcConfigKey::PIR_DELAYED, config));
|
||||
}
|
||||
{
|
||||
std::map<std::string, int *> config;
|
||||
config.insert(std::make_pair(CONFIG_PIR_SENSITIVITY, &mAllData.mPirSensitivity));
|
||||
mCfgMapIntV2.insert(std::make_pair(IpcConfigKey::PIR_SENSITIVITY, config));
|
||||
}
|
||||
{
|
||||
std::map<std::string, bool *> config;
|
||||
config.insert(std::make_pair(CONFIG_STORAGE_LOOP, &mAllData.mStorageLoopSwitch));
|
||||
mCfgMapBoolV2.insert(std::make_pair(IpcConfigKey::STORAGE_LOOP_SWITCH, config));
|
||||
}
|
||||
|
||||
// std::map<std::string, std::reference_wrapper<int>> innerMapWorkMode;
|
||||
// innerMapWorkMode.insert(std::make_pair("work_mode", std::reference_wrapper<int>(mAllData.mWorkMode)));
|
||||
|
@ -62,7 +104,7 @@ IpcConfigImpl::IpcConfigImpl()
|
|||
|
||||
// std::map<std::string, std::reference_wrapper<int>> innerMapBurstPhotoInterval;
|
||||
// innerMapBurstPhotoInterval.insert(
|
||||
// std::make_pair("burst_photo_interval", std::reference_wrapper<int>(mAllData.burstPhotoInterval)));
|
||||
// std::make_pair("burst_photo_interval", std::reference_wrapper<int>(mAllData.mBurstPhotoInterval)));
|
||||
// mCfgMapInt.insert(std::make_pair(IpcConfigKey::BURST_PHOTO_INTERVAL, innerMapBurstPhotoInterval));
|
||||
|
||||
// std::map<std::string, std::reference_wrapper<CHAR_STRING>> innerMapImageSize;
|
||||
|
@ -71,12 +113,12 @@ IpcConfigImpl::IpcConfigImpl()
|
|||
|
||||
// std::map<std::string, std::reference_wrapper<int>> innerMapVideoSize;
|
||||
// innerMapVideoSize.insert(std::make_pair("video_size", std::reference_wrapper<int>(mAllData.videoSize)));
|
||||
// mCfgMapInt.insert(std::make_pair(IpcConfigKey::VIDEO_SIZE, innerMapVideoSize));
|
||||
// mCfgMapInt.insert(std::make_pair(IpcConfigKey::VIDEO_LENGTH, innerMapVideoSize));
|
||||
|
||||
// std::map<std::string, std::reference_wrapper<int>> innerMapInfraredLampPower;
|
||||
// innerMapInfraredLampPower.insert(
|
||||
// std::make_pair("infrared_lamp_power", std::reference_wrapper<int>(mAllData.infraredIampPower)));
|
||||
// mCfgMapInt.insert(std::make_pair(IpcConfigKey::INFRARED_LAMP_POWER, innerMapInfraredLampPower));
|
||||
// std::make_pair("infrared_lamp_power", std::reference_wrapper<int>(mAllData.mInfraredPower)));
|
||||
// mCfgMapInt.insert(std::make_pair(IpcConfigKey::INFRARED_POWER, innerMapInfraredLampPower));
|
||||
|
||||
// std::map<std::string, std::reference_wrapper<int>> innerMapDelayed;
|
||||
// innerMapDelayed.insert(std::make_pair("delayed", std::reference_wrapper<int>(mAllData.delayed)));
|
||||
|
@ -84,12 +126,12 @@ IpcConfigImpl::IpcConfigImpl()
|
|||
|
||||
// std::map<std::string, std::reference_wrapper<int>> innerMapPirSensitivity;
|
||||
// innerMapPirSensitivity.insert(
|
||||
// std::make_pair("pir_sensitivity", std::reference_wrapper<int>(mAllData.pirSensitivity)));
|
||||
// std::make_pair("pir_sensitivity", std::reference_wrapper<int>(mAllData.mPirSensitivity)));
|
||||
// mCfgMapInt.insert(std::make_pair(IpcConfigKey::PIR_SENSITIVITY, innerMapPirSensitivity));
|
||||
|
||||
// std::map<std::string, std::reference_wrapper<bool>> innerMapStorageLoopSwitch;
|
||||
// innerMapStorageLoopSwitch.insert(
|
||||
// std::make_pair("storage_loop_switch", std::reference_wrapper<bool>(mAllData.storageLoopSwitch)));
|
||||
// std::make_pair("storage_loop_switch", std::reference_wrapper<bool>(mAllData.mStorageLoopSwitch)));
|
||||
// mCfgMapBool.insert(std::make_pair(IpcConfigKey::STORAGE_LOOP_SWITCH, innerMapStorageLoopSwitch));
|
||||
|
||||
// std::map<std::string, std::reference_wrapper<bool>> innerMapFactoryReset;
|
||||
|
@ -158,14 +200,6 @@ const StatusCode IpcConfigImpl::ConfigFileSave(void)
|
|||
|
||||
const int IpcConfigImpl::GetInt(const IpcConfigKey &key)
|
||||
{
|
||||
// std::map<IpcConfigKey, std::map<std::string, std::reference_wrapper<int>>>::iterator iter;
|
||||
// iter = mCfgMapInt.find(key);
|
||||
// if (iter != mCfgMapInt.end() && CHECK_MAP(iter->second)) {
|
||||
// return iter->second.begin()->second;
|
||||
// }
|
||||
// LogError("Can't find the key.\n");
|
||||
// constexpr int UNKNOWN_CONFIG = -1;
|
||||
// return UNKNOWN_CONFIG;
|
||||
std::map<IpcConfigKey, std::map<std::string, int *>>::iterator iter;
|
||||
iter = mCfgMapIntV2.find(key);
|
||||
if (iter != mCfgMapIntV2.end() && CHECK_MAP(iter->second)) {
|
||||
|
@ -177,17 +211,6 @@ const int IpcConfigImpl::GetInt(const IpcConfigKey &key)
|
|||
}
|
||||
void IpcConfigImpl::SetInt(const IpcConfigKey &key, const int &value)
|
||||
{
|
||||
// std::map<IpcConfigKey, std::map<std::string, std::reference_wrapper<int>>>::iterator iter;
|
||||
// iter = mCfgMapInt.find(key);
|
||||
// if (iter != mCfgMapInt.end() && CHECK_MAP(iter->second)) {
|
||||
// iter->second.begin()->second.get() = value;
|
||||
// const char *name = iter->second.begin()->first.c_str();
|
||||
// ConfigSetInt(mCfg, name, iter->second.begin()->second);
|
||||
// mCfgChanged = CONFIG_HAS_CHANGED;
|
||||
// }
|
||||
// else {
|
||||
// LogError("Can't find the key.\n");
|
||||
// }
|
||||
std::map<IpcConfigKey, std::map<std::string, int *>>::iterator iter;
|
||||
iter = mCfgMapIntV2.find(key);
|
||||
if (iter != mCfgMapIntV2.end() && CHECK_MAP(iter->second)) {
|
||||
|
@ -374,10 +397,10 @@ void IpcConfigImpl::SetLongDouble(const IpcConfigKey &key, const long double &va
|
|||
}
|
||||
const bool IpcConfigImpl::GetBool(const IpcConfigKey &key)
|
||||
{
|
||||
std::map<IpcConfigKey, std::map<std::string, std::reference_wrapper<bool>>>::iterator iter;
|
||||
iter = mCfgMapBool.find(key);
|
||||
if (iter != mCfgMapBool.end() && CHECK_MAP(iter->second)) {
|
||||
return iter->second.begin()->second;
|
||||
std::map<IpcConfigKey, std::map<std::string, bool *>>::iterator iter;
|
||||
iter = mCfgMapBoolV2.find(key);
|
||||
if (iter != mCfgMapBoolV2.end() && CHECK_MAP(iter->second)) {
|
||||
return *(iter->second.begin()->second);
|
||||
}
|
||||
LogError("Can't find the key.\n");
|
||||
constexpr bool UNKNOWN_CONFIG = false;
|
||||
|
@ -385,12 +408,11 @@ const bool IpcConfigImpl::GetBool(const IpcConfigKey &key)
|
|||
}
|
||||
void IpcConfigImpl::SetBool(const IpcConfigKey &key, const bool &value)
|
||||
{
|
||||
std::map<IpcConfigKey, std::map<std::string, std::reference_wrapper<bool>>>::iterator iter;
|
||||
iter = mCfgMapBool.find(key);
|
||||
if (iter != mCfgMapBool.end() && CHECK_MAP(iter->second)) {
|
||||
iter->second.begin()->second.get() = value;
|
||||
const char *name = iter->second.begin()->first.c_str();
|
||||
ConfigSetBool(mCfg, name, iter->second.begin()->second);
|
||||
std::map<IpcConfigKey, std::map<std::string, bool *>>::iterator iter;
|
||||
iter = mCfgMapBoolV2.find(key);
|
||||
if (iter != mCfgMapBoolV2.end() && CHECK_MAP(iter->second)) {
|
||||
*(iter->second.begin()->second) = value;
|
||||
ConfigSetBool(mCfg, iter->second.begin()->first.c_str(), *(iter->second.begin()->second));
|
||||
mCfgChanged = CONFIG_HAS_CHANGED;
|
||||
}
|
||||
else {
|
||||
|
@ -436,6 +458,26 @@ void IpcConfigImpl::SetWorkMode(const WorkMode &mode)
|
|||
{
|
||||
SetChar(IpcConfigKey::WORK_MODE, static_cast<char>(mode));
|
||||
}
|
||||
ConfigSwitch IpcConfigImpl::GetSwitch(const IpcConfigKey &key)
|
||||
{
|
||||
bool value = GetBool(key);
|
||||
return value == true ? ConfigSwitch::ON : ConfigSwitch::OFF;
|
||||
}
|
||||
void IpcConfigImpl::SetSwitch(const IpcConfigKey &key, const ConfigSwitch &value)
|
||||
{
|
||||
bool config = value == ConfigSwitch::ON ? true : false;
|
||||
SetBool(key, config);
|
||||
}
|
||||
ConfigLevel IpcConfigImpl::GetLevel(const IpcConfigKey &key)
|
||||
{
|
||||
char value = GetChar(key);
|
||||
return static_cast<ConfigLevel>(value);
|
||||
}
|
||||
void IpcConfigImpl::SetLevel(const IpcConfigKey &key, const ConfigLevel &value)
|
||||
{
|
||||
char config = static_cast<char>(value);
|
||||
SetChar(key, config);
|
||||
}
|
||||
void IpcConfigImpl::ReadAllConfigParameters(void)
|
||||
{
|
||||
{
|
||||
|
@ -483,6 +525,15 @@ void IpcConfigImpl::ReadAllConfigParameters(void)
|
|||
ConfigSetChar(mCfg, CONFIG_WORK_MODE, mAllData.mWorkMode);
|
||||
}
|
||||
}
|
||||
{
|
||||
StatusCode code = ConfigGetChar(mCfg, CONFIG_INFRARED_POWER, &mAllData.mInfraredPower);
|
||||
if (StatusCodeEqual(code, "CONFIG_CODE_PARAM_NOT_EXIST")) {
|
||||
LogWarning("CONFIG_INFRARED_POWER doesn't exist, will make it as default.\n");
|
||||
mCfgChanged = CONFIG_HAS_CHANGED;
|
||||
mAllData.mInfraredPower = CONFIG_INFRARED_POWER_DEFAULT;
|
||||
ConfigSetChar(mCfg, CONFIG_INFRARED_POWER, mAllData.mInfraredPower);
|
||||
}
|
||||
}
|
||||
{
|
||||
int config = -1;
|
||||
StatusCode code = ConfigGetInt(mCfg, CONFIG_CONTINUE_SHOT, &config);
|
||||
|
@ -496,6 +547,80 @@ void IpcConfigImpl::ReadAllConfigParameters(void)
|
|||
mAllData.mContinuousShot = config;
|
||||
}
|
||||
}
|
||||
{
|
||||
int config = -1;
|
||||
StatusCode code = ConfigGetInt(mCfg, CONFIG_BURST_PHOTO_INTERVAL, &config);
|
||||
if (StatusCodeEqual(code, "CONFIG_CODE_PARAM_NOT_EXIST")) {
|
||||
LogWarning("CONFIG_BURST_PHOTO_INTERVAL doesn't exist, will make it as default.\n");
|
||||
mCfgChanged = CONFIG_HAS_CHANGED;
|
||||
mAllData.mBurstPhotoInterval = CONFIG_BURST_PHOTO_INTERVAL_DEFAULT;
|
||||
ConfigSetInt(mCfg, CONFIG_BURST_PHOTO_INTERVAL, mAllData.mBurstPhotoInterval);
|
||||
}
|
||||
else {
|
||||
mAllData.mBurstPhotoInterval = config;
|
||||
}
|
||||
}
|
||||
{
|
||||
int config = -1;
|
||||
StatusCode code = ConfigGetInt(mCfg, CONFIG_IMAGE_SIZE, &config);
|
||||
if (StatusCodeEqual(code, "CONFIG_CODE_PARAM_NOT_EXIST")) {
|
||||
LogWarning("CONFIG_IMAGE_SIZE doesn't exist, will make it as default.\n");
|
||||
mCfgChanged = CONFIG_HAS_CHANGED;
|
||||
mAllData.mImageSize = CONFIG_IMAGE_SIZE_DEFAULT;
|
||||
ConfigSetInt(mCfg, CONFIG_IMAGE_SIZE, mAllData.mImageSize);
|
||||
}
|
||||
else {
|
||||
mAllData.mImageSize = config;
|
||||
}
|
||||
}
|
||||
{
|
||||
int config = -1;
|
||||
StatusCode code = ConfigGetInt(mCfg, CONFIG_VIDEO_SIZE, &config);
|
||||
if (StatusCodeEqual(code, "CONFIG_CODE_PARAM_NOT_EXIST")) {
|
||||
LogWarning("CONFIG_VIDEO_SIZE doesn't exist, will make it as default.\n");
|
||||
mCfgChanged = CONFIG_HAS_CHANGED;
|
||||
mAllData.mVideoLength = CONFIG_VIDEO_SIZE_DEFAULT;
|
||||
ConfigSetInt(mCfg, CONFIG_VIDEO_SIZE, mAllData.mVideoLength);
|
||||
}
|
||||
else {
|
||||
mAllData.mVideoLength = config;
|
||||
}
|
||||
}
|
||||
{
|
||||
int config = -1;
|
||||
StatusCode code = ConfigGetInt(mCfg, CONFIG_PIR_DELAYED, &config);
|
||||
if (StatusCodeEqual(code, "CONFIG_CODE_PARAM_NOT_EXIST")) {
|
||||
LogWarning("CONFIG_PIR_DELAYED doesn't exist, will make it as default.\n");
|
||||
mCfgChanged = CONFIG_HAS_CHANGED;
|
||||
mAllData.mPirDelayed = CONFIG_PIR_DELAYED_DEFAULT;
|
||||
ConfigSetInt(mCfg, CONFIG_PIR_DELAYED, mAllData.mPirDelayed);
|
||||
}
|
||||
else {
|
||||
mAllData.mPirDelayed = config;
|
||||
}
|
||||
}
|
||||
{
|
||||
int config = -1;
|
||||
StatusCode code = ConfigGetInt(mCfg, CONFIG_PIR_SENSITIVITY, &config);
|
||||
if (StatusCodeEqual(code, "CONFIG_CODE_PARAM_NOT_EXIST")) {
|
||||
LogWarning("CONFIG_PIR_SENSITIVITY doesn't exist, will make it as default.\n");
|
||||
mCfgChanged = CONFIG_HAS_CHANGED;
|
||||
mAllData.mPirSensitivity = CONFIG_PIR_SENSITIVITY_DEFAULT;
|
||||
ConfigSetInt(mCfg, CONFIG_PIR_SENSITIVITY, mAllData.mPirSensitivity);
|
||||
}
|
||||
else {
|
||||
mAllData.mPirSensitivity = config;
|
||||
}
|
||||
}
|
||||
{
|
||||
StatusCode code = ConfigGetBool(mCfg, CONFIG_STORAGE_LOOP, &(mAllData.mStorageLoopSwitch));
|
||||
if (StatusCodeEqual(code, "CONFIG_CODE_PARAM_NOT_EXIST")) {
|
||||
LogWarning("CONFIG_STORAGE_LOOP doesn't exist, will make it as default.\n");
|
||||
mCfgChanged = CONFIG_HAS_CHANGED;
|
||||
mAllData.mStorageLoopSwitch = CONFIG_STORAGE_LOOP_DEFAULT;
|
||||
ConfigSetBool(mCfg, CONFIG_STORAGE_LOOP, mAllData.mStorageLoopSwitch);
|
||||
}
|
||||
}
|
||||
|
||||
// StatusCode workModeCode = ConfigGetInt(mCfg, "work_mode", &(mAllData.mWorkMode));
|
||||
// if (StatusCodeEqual(workModeCode, "CONFIG_CODE_PARAM_NOT_EXIST")) {
|
||||
|
@ -513,12 +638,13 @@ void IpcConfigImpl::ReadAllConfigParameters(void)
|
|||
// ConfigSetInt(mCfg, "continuous_shot", mAllData.mContinuousShot);
|
||||
// }
|
||||
|
||||
// StatusCode burstPhotoIntervalCode = ConfigGetInt(mCfg, "burst_photo_interval", &(mAllData.burstPhotoInterval));
|
||||
// if (StatusCodeEqual(burstPhotoIntervalCode, "CONFIG_CODE_PARAM_NOT_EXIST")) {
|
||||
// StatusCode burstPhotoIntervalCode = ConfigGetInt(mCfg, "burst_photo_interval",
|
||||
// &(mAllData.mBurstPhotoInterval)); if (StatusCodeEqual(burstPhotoIntervalCode, "CONFIG_CODE_PARAM_NOT_EXIST"))
|
||||
// {
|
||||
// LogWarning("burst_photo_interval doesn't exist, will make it as default.\n");
|
||||
// mCfgChanged = CONFIG_HAS_CHANGED;
|
||||
// mAllData.burstPhotoInterval = BURST_PHOTO_INTERVAL_DEFAULT;
|
||||
// ConfigSetInt(mCfg, "burst_photo_interval", mAllData.burstPhotoInterval);
|
||||
// mAllData.mBurstPhotoInterval = BURST_PHOTO_INTERVAL_DEFAULT;
|
||||
// ConfigSetInt(mCfg, "burst_photo_interval", mAllData.mBurstPhotoInterval);
|
||||
// }
|
||||
|
||||
// const char *imageSizeString = nullptr;
|
||||
|
@ -547,12 +673,12 @@ void IpcConfigImpl::ReadAllConfigParameters(void)
|
|||
// ConfigSetInt(mCfg, "video_size", mAllData.videoSize);
|
||||
// }
|
||||
|
||||
// StatusCode infraredIampPowerCode = ConfigGetInt(mCfg, "infrared_lamp_power", &(mAllData.infraredIampPower));
|
||||
// StatusCode infraredIampPowerCode = ConfigGetInt(mCfg, "infrared_lamp_power", &(mAllData.mInfraredPower));
|
||||
// if (StatusCodeEqual(infraredIampPowerCode, "CONFIG_CODE_PARAM_NOT_EXIST")) {
|
||||
// LogWarning("infrared_lamp_power doesn't exist, will make it as default.\n");
|
||||
// mCfgChanged = CONFIG_HAS_CHANGED;
|
||||
// mAllData.infraredIampPower = INFRARED_IAMP_POWER_MID;
|
||||
// ConfigSetInt(mCfg, "infrared_lamp_power", mAllData.infraredIampPower);
|
||||
// mAllData.mInfraredPower = INFRARED_IAMP_POWER_MID;
|
||||
// ConfigSetInt(mCfg, "infrared_lamp_power", mAllData.mInfraredPower);
|
||||
// }
|
||||
|
||||
// StatusCode delayedCode = ConfigGetInt(mCfg, "delayed", &(mAllData.delayed));
|
||||
|
@ -563,21 +689,21 @@ void IpcConfigImpl::ReadAllConfigParameters(void)
|
|||
// ConfigSetInt(mCfg, "delayed", mAllData.delayed);
|
||||
// }
|
||||
|
||||
// StatusCode pirSensitivityCode = ConfigGetInt(mCfg, "pir_sensitivity", &(mAllData.pirSensitivity));
|
||||
// StatusCode pirSensitivityCode = ConfigGetInt(mCfg, "pir_sensitivity", &(mAllData.mPirSensitivity));
|
||||
// if (StatusCodeEqual(pirSensitivityCode, "CONFIG_CODE_PARAM_NOT_EXIST")) {
|
||||
// LogWarning("pir_sensitivity doesn't exist, will make it as default.\n");
|
||||
// mCfgChanged = CONFIG_HAS_CHANGED;
|
||||
// mAllData.pirSensitivity = PIR_SENSITIVITY_DEFAULT;
|
||||
// ConfigSetInt(mCfg, "pir_sensitivity", mAllData.pirSensitivity);
|
||||
// mAllData.mPirSensitivity = PIR_SENSITIVITY_DEFAULT;
|
||||
// ConfigSetInt(mCfg, "pir_sensitivity", mAllData.mPirSensitivity);
|
||||
// }
|
||||
|
||||
// StatusCode storageLoopSwitchCode = ConfigGetBool(mCfg, "storage_loop_switch", &(mAllData.storageLoopSwitch));
|
||||
// if (StatusCodeEqual(storageLoopSwitchCode, "CONFIG_CODE_PARAM_NOT_EXIST")) {
|
||||
// StatusCode storageLoopSwitchCode = ConfigGetBool(mCfg, "storage_loop_switch",
|
||||
// &(mAllData.mStorageLoopSwitch)); if (StatusCodeEqual(storageLoopSwitchCode, "CONFIG_CODE_PARAM_NOT_EXIST")) {
|
||||
// LogWarning("storage_loop_switch doesn't exist, will make it as default.\n");
|
||||
// mCfgChanged = CONFIG_HAS_CHANGED;
|
||||
// constexpr bool storageLoopSwitch = true;
|
||||
// mAllData.storageLoopSwitch = storageLoopSwitch;
|
||||
// ConfigSetBool(mCfg, "storage_loop_switch", mAllData.storageLoopSwitch);
|
||||
// mAllData.mStorageLoopSwitch = storageLoopSwitch;
|
||||
// ConfigSetBool(mCfg, "storage_loop_switch", mAllData.mStorageLoopSwitch);
|
||||
// }
|
||||
|
||||
// StatusCode factoryResetCode = ConfigGetBool(mCfg, "factory_reset", &(mAllData.factoryReset));
|
||||
|
|
|
@ -23,8 +23,16 @@ constexpr bool CONFIG_HAS_CHANGED = true;
|
|||
constexpr bool CONFIG_HAS_NOT_CHANGED = false;
|
||||
constexpr unsigned int WIFI_SSID_BUFF_SIZE = 64;
|
||||
constexpr unsigned int WIFI_PASSWORD_BUFF_SIZE = 8;
|
||||
constexpr unsigned int WORKING_TIME_MAX_ALLOW = 32;
|
||||
constexpr char CONFIG_WORK_MODE_DEFAULT = static_cast<char>(WorkMode::MODE_PIC);
|
||||
constexpr char CONFIG_INFRARED_POWER_DEFAULT = static_cast<char>(ConfigLevel::LOW);
|
||||
constexpr int CONFIG_CONTINUE_SHOT_DEFAULT = 1;
|
||||
constexpr int CONFIG_BURST_PHOTO_INTERVAL_DEFAULT = 0;
|
||||
constexpr int CONFIG_IMAGE_SIZE_DEFAULT = 8;
|
||||
constexpr int CONFIG_VIDEO_SIZE_DEFAULT = 10;
|
||||
constexpr int CONFIG_PIR_DELAYED_DEFAULT = 0;
|
||||
constexpr int CONFIG_PIR_SENSITIVITY_DEFAULT = 9;
|
||||
constexpr bool CONFIG_STORAGE_LOOP_DEFAULT = true;
|
||||
typedef char CHAR_STRING[64];
|
||||
typedef struct string_config_pack
|
||||
{
|
||||
|
@ -33,16 +41,17 @@ typedef struct string_config_pack
|
|||
} StringConfigPack;
|
||||
typedef struct __attribute__((packed)) Config_s
|
||||
{
|
||||
bool storageLoopSwitch;
|
||||
bool mStorageLoopSwitch;
|
||||
bool factoryReset;
|
||||
bool formattingSDCard;
|
||||
char mWorkMode;
|
||||
int mContinuousShot;
|
||||
int burstPhotoInterval;
|
||||
int videoSize;
|
||||
int infraredIampPower;
|
||||
int delayed;
|
||||
int pirSensitivity;
|
||||
int mBurstPhotoInterval;
|
||||
int mImageSize;
|
||||
int mVideoLength;
|
||||
char mInfraredPower;
|
||||
int mPirDelayed;
|
||||
int mPirSensitivity;
|
||||
short testShort;
|
||||
char testChar;
|
||||
long testLong;
|
||||
|
@ -53,6 +62,8 @@ typedef struct __attribute__((packed)) Config_s
|
|||
CHAR_STRING workingInterval;
|
||||
char mWifiSsid[WIFI_SSID_BUFF_SIZE + 1];
|
||||
char mWifiPassword[WIFI_PASSWORD_BUFF_SIZE + 1];
|
||||
unsigned char mWorkingTimeFrom[WORKING_TIME_MAX_ALLOW];
|
||||
unsigned char mWorkingTimeTo[WORKING_TIME_MAX_ALLOW];
|
||||
} Config_s;
|
||||
class MapInt
|
||||
{
|
||||
|
@ -90,6 +101,10 @@ public:
|
|||
void SetString(const IpcConfigKey &key, const std::string &string) override;
|
||||
WorkMode GetWorkMode(void) override;
|
||||
void SetWorkMode(const WorkMode &mode) override;
|
||||
ConfigSwitch GetSwitch(const IpcConfigKey &key) override;
|
||||
void SetSwitch(const IpcConfigKey &key, const ConfigSwitch &value) override;
|
||||
ConfigLevel GetLevel(const IpcConfigKey &key) override;
|
||||
void SetLevel(const IpcConfigKey &key, const ConfigLevel &value) override;
|
||||
|
||||
private:
|
||||
void ReadAllConfigParameters(void);
|
||||
|
@ -109,6 +124,7 @@ private:
|
|||
std::map<IpcConfigKey, std::map<std::string, std::reference_wrapper<double>>> mCfgMapDouble;
|
||||
std::map<IpcConfigKey, std::reference_wrapper<long double>> mCfgMapLongDouble;
|
||||
std::map<IpcConfigKey, std::map<std::string, std::reference_wrapper<bool>>> mCfgMapBool;
|
||||
std::map<IpcConfigKey, std::map<std::string, bool *>> mCfgMapBoolV2;
|
||||
std::map<IpcConfigKey, std::map<std::string, std::reference_wrapper<CHAR_STRING>>> mCfgMapString;
|
||||
std::map<IpcConfigKey, std::map<std::string, StringConfigPack>> mCfgMapStringV2;
|
||||
};
|
||||
|
|
|
@ -36,15 +36,15 @@ TEST(IpcConfigDemo, Demo)
|
|||
const std::string iimageSize = "410*410";
|
||||
IIpcConfig::GetInstance()->SetString(IpcConfigKey::IMGAE_SIZE, iimageSize);
|
||||
|
||||
const int videoSize = IIpcConfig::GetInstance()->GetInt(IpcConfigKey::VIDEO_SIZE);
|
||||
const int videoSize = IIpcConfig::GetInstance()->GetInt(IpcConfigKey::VIDEO_LENGTH);
|
||||
LogInfo("Get video_size = %d\n", videoSize);
|
||||
const int vvideoSize = VIDEO_SIZE_10;
|
||||
IIpcConfig::GetInstance()->SetInt(IpcConfigKey::VIDEO_SIZE, vvideoSize);
|
||||
IIpcConfig::GetInstance()->SetInt(IpcConfigKey::VIDEO_LENGTH, vvideoSize);
|
||||
|
||||
const int infraredIampPower = IIpcConfig::GetInstance()->GetInt(IpcConfigKey::INFRARED_LAMP_POWER);
|
||||
const int infraredIampPower = IIpcConfig::GetInstance()->GetInt(IpcConfigKey::INFRARED_POWER);
|
||||
LogInfo("Get infrared_lamp_power = %d\n", infraredIampPower);
|
||||
const int iinfraredIampPower = INFRARED_IAMP_POWER_LOW;
|
||||
IIpcConfig::GetInstance()->SetInt(IpcConfigKey::INFRARED_LAMP_POWER, iinfraredIampPower);
|
||||
IIpcConfig::GetInstance()->SetInt(IpcConfigKey::INFRARED_POWER, iinfraredIampPower);
|
||||
|
||||
const int delayed = IIpcConfig::GetInstance()->GetInt(IpcConfigKey::PIR_DELAYED);
|
||||
LogInfo("Get delayed = %d\n", delayed);
|
||||
|
@ -228,4 +228,68 @@ TEST_F(IpcConfigTest, HS_RH_UNIT_IpcConfig_AUTO_ContinueShot)
|
|||
config = IIpcConfig::GetInstance()->GetInt(IpcConfigKey::CONTINUOUS_SHOT);
|
||||
EXPECT_EQ(config, 2);
|
||||
}
|
||||
// ../output_files/test/bin/IpcConfigTest --gtest_filter=IpcConfigTest.HS_RH_UNIT_IpcConfig_AUTO_BurstPhotoInterval
|
||||
TEST_F(IpcConfigTest, HS_RH_UNIT_IpcConfig_AUTO_BurstPhotoInterval)
|
||||
{
|
||||
int config = IIpcConfig::GetInstance()->GetInt(IpcConfigKey::BURST_PHOTO_INTERVAL);
|
||||
EXPECT_EQ(config, CONFIG_BURST_PHOTO_INTERVAL_DEFAULT);
|
||||
IIpcConfig::GetInstance()->SetInt(IpcConfigKey::BURST_PHOTO_INTERVAL, 10);
|
||||
config = IIpcConfig::GetInstance()->GetInt(IpcConfigKey::BURST_PHOTO_INTERVAL);
|
||||
EXPECT_EQ(config, 10);
|
||||
}
|
||||
// ../output_files/test/bin/IpcConfigTest --gtest_filter=IpcConfigTest.HS_RH_UNIT_IpcConfig_AUTO_ImageSize
|
||||
TEST_F(IpcConfigTest, HS_RH_UNIT_IpcConfig_AUTO_ImageSize)
|
||||
{
|
||||
int config = IIpcConfig::GetInstance()->GetInt(IpcConfigKey::IMGAE_SIZE);
|
||||
EXPECT_EQ(config, CONFIG_IMAGE_SIZE_DEFAULT);
|
||||
IIpcConfig::GetInstance()->SetInt(IpcConfigKey::IMGAE_SIZE, 16);
|
||||
config = IIpcConfig::GetInstance()->GetInt(IpcConfigKey::IMGAE_SIZE);
|
||||
EXPECT_EQ(config, 16);
|
||||
}
|
||||
// ../output_files/test/bin/IpcConfigTest --gtest_filter=IpcConfigTest.HS_RH_UNIT_IpcConfig_AUTO_VideoLength
|
||||
TEST_F(IpcConfigTest, HS_RH_UNIT_IpcConfig_AUTO_VideoLength)
|
||||
{
|
||||
int config = IIpcConfig::GetInstance()->GetInt(IpcConfigKey::VIDEO_LENGTH);
|
||||
EXPECT_EQ(config, CONFIG_VIDEO_SIZE_DEFAULT);
|
||||
IIpcConfig::GetInstance()->SetInt(IpcConfigKey::VIDEO_LENGTH, 15);
|
||||
config = IIpcConfig::GetInstance()->GetInt(IpcConfigKey::VIDEO_LENGTH);
|
||||
EXPECT_EQ(config, 15);
|
||||
}
|
||||
// ../output_files/test/bin/IpcConfigTest --gtest_filter=IpcConfigTest.HS_RH_UNIT_IpcConfig_AUTO_PirDelayed
|
||||
TEST_F(IpcConfigTest, HS_RH_UNIT_IpcConfig_AUTO_PirDelayed)
|
||||
{
|
||||
int config = IIpcConfig::GetInstance()->GetInt(IpcConfigKey::PIR_DELAYED);
|
||||
EXPECT_EQ(config, CONFIG_PIR_DELAYED_DEFAULT);
|
||||
IIpcConfig::GetInstance()->SetInt(IpcConfigKey::PIR_DELAYED, 15);
|
||||
config = IIpcConfig::GetInstance()->GetInt(IpcConfigKey::PIR_DELAYED);
|
||||
EXPECT_EQ(config, 15);
|
||||
}
|
||||
// ../output_files/test/bin/IpcConfigTest --gtest_filter=IpcConfigTest.HS_RH_UNIT_IpcConfig_AUTO_StorageLoop
|
||||
TEST_F(IpcConfigTest, HS_RH_UNIT_IpcConfig_AUTO_StorageLoop)
|
||||
{
|
||||
ConfigSwitch config = IIpcConfig::GetInstance()->GetSwitch(IpcConfigKey::STORAGE_LOOP_SWITCH);
|
||||
EXPECT_EQ(static_cast<int>(config),
|
||||
static_cast<int>(CONFIG_STORAGE_LOOP_DEFAULT == true ? ConfigSwitch::ON : ConfigSwitch::OFF));
|
||||
IIpcConfig::GetInstance()->SetSwitch(IpcConfigKey::STORAGE_LOOP_SWITCH, ConfigSwitch::OFF);
|
||||
config = IIpcConfig::GetInstance()->GetSwitch(IpcConfigKey::STORAGE_LOOP_SWITCH);
|
||||
EXPECT_EQ(static_cast<int>(config), static_cast<int>(ConfigSwitch::OFF));
|
||||
}
|
||||
// ../output_files/test/bin/IpcConfigTest --gtest_filter=IpcConfigTest.HS_RH_UNIT_IpcConfig_AUTO_InfraredPower
|
||||
TEST_F(IpcConfigTest, HS_RH_UNIT_IpcConfig_AUTO_InfraredPower)
|
||||
{
|
||||
ConfigLevel config = IIpcConfig::GetInstance()->GetLevel(IpcConfigKey::INFRARED_POWER);
|
||||
EXPECT_EQ(static_cast<int>(config), static_cast<int>(CONFIG_INFRARED_POWER_DEFAULT));
|
||||
IIpcConfig::GetInstance()->SetLevel(IpcConfigKey::INFRARED_POWER, ConfigLevel::HIGHT);
|
||||
config = IIpcConfig::GetInstance()->GetLevel(IpcConfigKey::INFRARED_POWER);
|
||||
EXPECT_EQ(static_cast<int>(config), static_cast<int>(ConfigSwitch::OFF));
|
||||
}
|
||||
// ../output_files/test/bin/IpcConfigTest --gtest_filter=IpcConfigTest.HS_RH_UNIT_IpcConfig_AUTO_PirSensitivity
|
||||
TEST_F(IpcConfigTest, HS_RH_UNIT_IpcConfig_AUTO_PirSensitivity)
|
||||
{
|
||||
int config = IIpcConfig::GetInstance()->GetInt(IpcConfigKey::PIR_SENSITIVITY);
|
||||
EXPECT_EQ(config, CONFIG_PIR_SENSITIVITY_DEFAULT);
|
||||
IIpcConfig::GetInstance()->SetInt(IpcConfigKey::PIR_SENSITIVITY, 0);
|
||||
config = IIpcConfig::GetInstance()->GetInt(IpcConfigKey::PIR_SENSITIVITY);
|
||||
EXPECT_EQ(config, 0);
|
||||
}
|
||||
} // namespace IpcConfigTest
|
Loading…
Reference in New Issue
Block a user