[zhoulongyu]: 添加和修改配置库数据: 图片大小, 夜间模式, 工作区间

This commit is contained in:
jas 2023-12-17 20:37:31 +08:00
parent 985ae0edef
commit d47aff4e47
4 changed files with 96 additions and 66 deletions

View File

@ -32,13 +32,14 @@ enum class IpcConfigKey
KEY_STORAGE_LOOP_SWITCH,
KEY_FACTORY_RESET_FLAG,
KEY_FORMATTING_SD_CARD,
KEY_DARK_MODE,
KEY_WORK_INTERVAL,
TEST_SHORT,
TEST_LONG,
TEST_LLONG,
TEST_CHAR,
TEST_BOOL,
TEST_FLOAT,
TEST_STRING,
END
};
enum WorkMode

View File

@ -36,9 +36,9 @@ IpcConfig::IpcConfig()
std::make_pair("burst_photo_interval", std::reference_wrapper<int>(mAllData.burstPhotoInterval)));
mCfgMapInt.insert(std::make_pair(IpcConfigKey::KEY_BURST_PHOTO_INTERVAL, innerMapBurstPhotoInterval));
std::map<std::string, std::reference_wrapper<double>> innerMapImageSize;
innerMapImageSize.insert(std::make_pair("image_size", std::reference_wrapper<double>(mAllData.imageSize)));
mCfgMapDouble.insert(std::make_pair(IpcConfigKey::KEY_IMGAE_SIZE, innerMapImageSize));
std::map<std::string, std::reference_wrapper<CHAR_STRING>> innerMapImageSize;
innerMapImageSize.insert(std::make_pair("image_size", std::reference_wrapper<CHAR_STRING>(mAllData.imageSize)));
mCfgMapString.insert(std::make_pair(IpcConfigKey::KEY_IMGAE_SIZE, innerMapImageSize));
std::map<std::string, std::reference_wrapper<int>> innerMapVideoSize;
innerMapVideoSize.insert(std::make_pair("video_size", std::reference_wrapper<int>(mAllData.videoSize)));
@ -72,6 +72,15 @@ IpcConfig::IpcConfig()
std::make_pair("formatting_SD_card", std::reference_wrapper<bool>(mAllData.formattingSDCard)));
mCfgMapBool.insert(std::make_pair(IpcConfigKey::KEY_FORMATTING_SD_CARD, innerMapFormattingSDCard));
std::map<std::string, std::reference_wrapper<CHAR_STRING>> innerMapDrakMode;
innerMapDrakMode.insert(std::make_pair("dark_mode", std::reference_wrapper<CHAR_STRING>(mAllData.darkMode)));
mCfgMapString.insert(std::make_pair(IpcConfigKey::KEY_DARK_MODE, innerMapDrakMode));
std::map<std::string, std::reference_wrapper<CHAR_STRING>> innerMapWorkInterval;
innerMapWorkInterval.insert(
std::make_pair("work_interval", std::reference_wrapper<CHAR_STRING>(mAllData.workingInterval)));
mCfgMapString.insert(std::make_pair(IpcConfigKey::KEY_WORK_INTERVAL, innerMapWorkInterval));
std::map<std::string, std::reference_wrapper<short>> innerMapShort;
innerMapShort.insert(std::make_pair("test_short", std::reference_wrapper<short>(mAllData.testShort)));
mCfgMapShort.insert(std::make_pair(IpcConfigKey::TEST_SHORT, innerMapShort));
@ -91,10 +100,6 @@ IpcConfig::IpcConfig()
std::map<std::string, std::reference_wrapper<float>> innerMapFloat;
innerMapFloat.insert(std::make_pair("test_float", std::reference_wrapper<float>(mAllData.testFloat)));
mCfgMapFloat.insert(std::make_pair(IpcConfigKey::TEST_FLOAT, innerMapFloat));
std::map<std::string, std::reference_wrapper<CHAR_STRING>> innerMapString;
innerMapString.insert(std::make_pair("test_string", std::reference_wrapper<CHAR_STRING>(mAllData.testString)));
mCfgMapString.insert(std::make_pair(IpcConfigKey::TEST_STRING, innerMapString));
}
const StatusCode IpcConfig::Init(void)
{
@ -394,12 +399,17 @@ void IpcConfig::ReadAllConfigParameters(void)
ConfigSetInt(mCfg, "burst_photo_interval", mAllData.burstPhotoInterval);
}
StatusCode imageSizeCode = ConfigGetDouble(mCfg, "image_size", &(mAllData.imageSize));
const char *imageSizeString = NULL;
StatusCode imageSizeCode = ConfigGetString(mCfg, "image_size", &(imageSizeString));
if (StatusCodeEqual(imageSizeCode, "CONFIG_CODE_PARAM_NOT_EXIST")) {
LogWarning("image_size doesn't exist, will make it as default.\n");
mCfgChanged = CONFIG_HAS_CHANGED;
mAllData.imageSize = 410.014;
ConfigSetDouble(mCfg, "image_size", mAllData.imageSize);
char defaultImageSize[] = "320*320";
strncpy(mAllData.imageSize, defaultImageSize, sizeof(mAllData.imageSize));
ConfigSetString(mCfg, "image_size", mAllData.imageSize);
}
else {
strncpy(mAllData.imageSize, imageSizeString, sizeof(mAllData.imageSize));
}
StatusCode videoSizeCode = ConfigGetInt(mCfg, "video_size", &(mAllData.videoSize));
@ -461,6 +471,32 @@ void IpcConfig::ReadAllConfigParameters(void)
ConfigSetBool(mCfg, "formatting_SD_card", mAllData.formattingSDCard);
}
const char *darkModeString = NULL;
StatusCode darkModeCode = ConfigGetString(mCfg, "dark_mode", &(darkModeString));
if (StatusCodeEqual(darkModeCode, "CONFIG_CODE_PARAM_NOT_EXIST")) {
LogWarning("dark_mode doesn't exist, will make it as default.\n");
mCfgChanged = CONFIG_HAS_CHANGED;
char defaultDarkMode[] = "19:00:00-07:00:00";
strncpy(mAllData.darkMode, defaultDarkMode, sizeof(mAllData.darkMode));
ConfigSetString(mCfg, "dark_mode", mAllData.darkMode);
}
else {
strncpy(mAllData.darkMode, darkModeString, sizeof(mAllData.darkMode));
}
const char *workIntervalString = NULL;
StatusCode workIntervalCode = ConfigGetString(mCfg, "work_interval", &(workIntervalString));
if (StatusCodeEqual(workIntervalCode, "CONFIG_CODE_PARAM_NOT_EXIST")) {
LogWarning("work_interval doesn't exist, will make it as default.\n");
mCfgChanged = CONFIG_HAS_CHANGED;
char defaultWorkInterval[] = "07:00:01-07:00:00";
strncpy(mAllData.workingInterval, defaultWorkInterval, sizeof(mAllData.workingInterval));
ConfigSetString(mCfg, "work_interval", mAllData.workingInterval);
}
else {
strncpy(mAllData.workingInterval, workIntervalString, sizeof(mAllData.workingInterval));
}
StatusCode shortCode = ConfigGetShort(mCfg, "test_short", &(mAllData.testShort));
if (StatusCodeEqual(shortCode, "CONFIG_CODE_PARAM_NOT_EXIST")) {
LogWarning("test_short doesn't exist, will make it as default.\n");
@ -506,19 +542,6 @@ void IpcConfig::ReadAllConfigParameters(void)
ConfigSetFloat(mCfg, "test_float", mAllData.testFloat);
}
const char *testString = NULL;
StatusCode stringCode = ConfigGetString(mCfg, "test_string", &(testString));
if (StatusCodeEqual(stringCode, "CONFIG_CODE_PARAM_NOT_EXIST")) {
LogWarning("test_string doesn't exist, will make it as default.\n");
mCfgChanged = CONFIG_HAS_CHANGED;
char DEFAULT_TEST_STRING[] = "undefine";
strncpy(mAllData.testString, DEFAULT_TEST_STRING, sizeof(mAllData.testString));
ConfigSetString(mCfg, "test_string", mAllData.testString);
}
else {
strncpy(mAllData.testString, testString, sizeof(mAllData.testString));
}
if (CONFIG_HAS_CHANGED == mCfgChanged) {
LogInfo("Save the config file.\n");
mCfgChanged = CONFIG_HAS_NOT_CHANGED;

View File

@ -22,7 +22,7 @@
constexpr bool CONFIG_HAS_CHANGED = true;
constexpr bool CONFIG_HAS_NOT_CHANGED = false;
typedef char CHAR_STRING[256];
typedef char CHAR_STRING[64];
typedef struct Config_s
{
bool storageLoopSwitch;
@ -35,13 +35,14 @@ typedef struct Config_s
int infraredIampPower;
int delayed;
int pirSensitivity;
double imageSize;
short testShort;
char testChar;
long testLong;
long long testLLong;
float testFloat;
CHAR_STRING testString;
CHAR_STRING imageSize;
CHAR_STRING darkMode;
CHAR_STRING workingInterval;
} Config_s;
class MapInt
{

View File

@ -12,60 +12,70 @@ TEST(IpcConfigTest, Demo)
ILogInit(LOG_INSTANCE_TYPE_END);
IIpcConfig::GetInstance()->Init();
int workMode = IIpcConfig::GetInstance()->GetInt(IpcConfigKey::KEY_WORK_MODE);
const int workMode = IIpcConfig::GetInstance()->GetInt(IpcConfigKey::KEY_WORK_MODE);
LogInfo("Get workMode = %d\n", workMode);
workMode = WORK_MODE_PIC_VIDEO;
IIpcConfig::GetInstance()->SetInt(IpcConfigKey::KEY_WORK_MODE, workMode);
const int wworkMode = WORK_MODE_PIC_VIDEO;
IIpcConfig::GetInstance()->SetInt(IpcConfigKey::KEY_WORK_MODE, wworkMode);
int continuousShot = IIpcConfig::GetInstance()->GetInt(IpcConfigKey::KEY_CONTINUOUS_SHOT);
const int continuousShot = IIpcConfig::GetInstance()->GetInt(IpcConfigKey::KEY_CONTINUOUS_SHOT);
LogInfo("Get continuousShot = %d\n", continuousShot);
continuousShot = CONTINUOUS_SHOT_TWO_PIC;
IIpcConfig::GetInstance()->SetInt(IpcConfigKey::KEY_CONTINUOUS_SHOT, continuousShot);
const int ccontinuousShot = CONTINUOUS_SHOT_TWO_PIC;
IIpcConfig::GetInstance()->SetInt(IpcConfigKey::KEY_CONTINUOUS_SHOT, ccontinuousShot);
int burstPhotoInterval = IIpcConfig::GetInstance()->GetInt(IpcConfigKey::KEY_BURST_PHOTO_INTERVAL);
const int burstPhotoInterval = IIpcConfig::GetInstance()->GetInt(IpcConfigKey::KEY_BURST_PHOTO_INTERVAL);
LogInfo("Get burstPhotoInterval = %d\n", burstPhotoInterval);
burstPhotoInterval = BURST_PHOTO_INTERVAL_DEFAULT;
IIpcConfig::GetInstance()->SetInt(IpcConfigKey::KEY_BURST_PHOTO_INTERVAL, burstPhotoInterval);
const int bburstPhotoInterval = BURST_PHOTO_INTERVAL_DEFAULT;
IIpcConfig::GetInstance()->SetInt(IpcConfigKey::KEY_BURST_PHOTO_INTERVAL, bburstPhotoInterval);
double imageSize = IIpcConfig::GetInstance()->GetDouble(IpcConfigKey::KEY_IMGAE_SIZE);
LogInfo("Get image_size = %lf\n", imageSize);
imageSize = 320.023;
IIpcConfig::GetInstance()->SetDouble(IpcConfigKey::KEY_IMGAE_SIZE, imageSize);
const std::string imageSize = IIpcConfig::GetInstance()->GetString(IpcConfigKey::KEY_IMGAE_SIZE);
LogInfo("Get image_size = %s\n", imageSize.c_str());
const std::string iimageSize = "410*410";
IIpcConfig::GetInstance()->SetString(IpcConfigKey::KEY_IMGAE_SIZE, iimageSize);
int videoSize = IIpcConfig::GetInstance()->GetInt(IpcConfigKey::KEY_VIDEO_SIZE);
const int videoSize = IIpcConfig::GetInstance()->GetInt(IpcConfigKey::KEY_VIDEO_SIZE);
LogInfo("Get video_size = %d\n", videoSize);
videoSize = VIDEO_SIZE_10;
IIpcConfig::GetInstance()->SetInt(IpcConfigKey::KEY_VIDEO_SIZE, videoSize);
const int vvideoSize = VIDEO_SIZE_10;
IIpcConfig::GetInstance()->SetInt(IpcConfigKey::KEY_VIDEO_SIZE, vvideoSize);
int infraredIampPower = IIpcConfig::GetInstance()->GetInt(IpcConfigKey::KEY_INFRARED_LAMP_POWER);
const int infraredIampPower = IIpcConfig::GetInstance()->GetInt(IpcConfigKey::KEY_INFRARED_LAMP_POWER);
LogInfo("Get infrared_lamp_power = %d\n", infraredIampPower);
infraredIampPower = INFRARED_IAMP_POWER_LOW;
IIpcConfig::GetInstance()->SetInt(IpcConfigKey::KEY_INFRARED_LAMP_POWER, infraredIampPower);
const int iinfraredIampPower = INFRARED_IAMP_POWER_LOW;
IIpcConfig::GetInstance()->SetInt(IpcConfigKey::KEY_INFRARED_LAMP_POWER, iinfraredIampPower);
int delayed = IIpcConfig::GetInstance()->GetInt(IpcConfigKey::KEY_DELAYED);
const int delayed = IIpcConfig::GetInstance()->GetInt(IpcConfigKey::KEY_DELAYED);
LogInfo("Get delayed = %d\n", delayed);
delayed = DELAYED_MAX;
IIpcConfig::GetInstance()->SetInt(IpcConfigKey::KEY_DELAYED, delayed);
const int ddelayed = DELAYED_MAX;
IIpcConfig::GetInstance()->SetInt(IpcConfigKey::KEY_DELAYED, ddelayed);
int pirSensitivity = IIpcConfig::GetInstance()->GetInt(IpcConfigKey::KEY_PIR_SENSITIVITY);
const int pirSensitivity = IIpcConfig::GetInstance()->GetInt(IpcConfigKey::KEY_PIR_SENSITIVITY);
LogInfo("Get pir_sensitivity = %d\n", pirSensitivity);
pirSensitivity = PIR_SENSITIVITY_MAX;
IIpcConfig::GetInstance()->SetInt(IpcConfigKey::KEY_PIR_SENSITIVITY, pirSensitivity);
const int ppirSensitivity = PIR_SENSITIVITY_MAX;
IIpcConfig::GetInstance()->SetInt(IpcConfigKey::KEY_PIR_SENSITIVITY, ppirSensitivity);
bool storageLoopSwitch = IIpcConfig::GetInstance()->GetBool(IpcConfigKey::KEY_STORAGE_LOOP_SWITCH);
const bool storageLoopSwitch = IIpcConfig::GetInstance()->GetBool(IpcConfigKey::KEY_STORAGE_LOOP_SWITCH);
LogInfo("Get storage_loop_switch = %d\n", storageLoopSwitch);
storageLoopSwitch = false;
IIpcConfig::GetInstance()->SetBool(IpcConfigKey::KEY_STORAGE_LOOP_SWITCH, storageLoopSwitch);
const bool sstorageLoopSwitch = false;
IIpcConfig::GetInstance()->SetBool(IpcConfigKey::KEY_STORAGE_LOOP_SWITCH, sstorageLoopSwitch);
bool factoryReset = IIpcConfig::GetInstance()->GetBool(IpcConfigKey::KEY_FACTORY_RESET_FLAG);
const bool factoryReset = IIpcConfig::GetInstance()->GetBool(IpcConfigKey::KEY_FACTORY_RESET_FLAG);
LogInfo("Get factory_reset = %d\n", factoryReset);
factoryReset = false;
IIpcConfig::GetInstance()->SetBool(IpcConfigKey::KEY_FACTORY_RESET_FLAG, factoryReset);
const bool ffactoryReset = false;
IIpcConfig::GetInstance()->SetBool(IpcConfigKey::KEY_FACTORY_RESET_FLAG, ffactoryReset);
bool formattingSDCard = IIpcConfig::GetInstance()->GetBool(IpcConfigKey::KEY_FORMATTING_SD_CARD);
const bool formattingSDCard = IIpcConfig::GetInstance()->GetBool(IpcConfigKey::KEY_FORMATTING_SD_CARD);
LogInfo("Get formatting_SD_card = %d\n", formattingSDCard);
formattingSDCard = false;
IIpcConfig::GetInstance()->SetBool(IpcConfigKey::KEY_FORMATTING_SD_CARD, formattingSDCard);
const bool fformattingSDCard = false;
IIpcConfig::GetInstance()->SetBool(IpcConfigKey::KEY_FORMATTING_SD_CARD, fformattingSDCard);
const std::string workInterval = IIpcConfig::GetInstance()->GetString(IpcConfigKey::KEY_WORK_INTERVAL);
LogInfo("Get work_Interval = %s\n", workInterval.c_str());
const std::string wworkInterval = "06:00:01-06:00:00";
IIpcConfig::GetInstance()->SetString(IpcConfigKey::KEY_WORK_INTERVAL, wworkInterval);
const std::string drakMode = IIpcConfig::GetInstance()->GetString(IpcConfigKey::KEY_DARK_MODE);
LogInfo("Get dark_mode = %s\n", drakMode.c_str());
const std::string ddrakMode = "18:00:00-06:00:00";
IIpcConfig::GetInstance()->SetString(IpcConfigKey::KEY_DARK_MODE, ddrakMode);
short testShort = IIpcConfig::GetInstance()->GetShort(IpcConfigKey::TEST_SHORT);
LogInfo("Get test_short = %d\n", testShort);
@ -92,11 +102,6 @@ TEST(IpcConfigTest, Demo)
const float numFloat = 1.123456;
IIpcConfig::GetInstance()->SetFloat(IpcConfigKey::TEST_FLOAT, numFloat);
const std::string testString = IIpcConfig::GetInstance()->GetString(IpcConfigKey::TEST_STRING);
LogInfo("Get testString = %s\n", testString.c_str());
const std::string string = "define";
IIpcConfig::GetInstance()->SetString(IpcConfigKey::TEST_STRING, string);
IIpcConfig::GetInstance()->ConfigFileSave();
IIpcConfig::GetInstance()->UnInit();
ILogUnInit();