[zhoulongyu]: 添加配置库数据: 红外灯功率,PIR灵敏度, 存储循环开关, 恢复出厂, 格式化SDk卡

This commit is contained in:
jas 2023-12-17 11:41:07 +08:00
parent c25e185c93
commit 985ae0edef
4 changed files with 143 additions and 20 deletions

View File

@ -26,6 +26,12 @@ enum class IpcConfigKey
KEY_BURST_PHOTO_INTERVAL, KEY_BURST_PHOTO_INTERVAL,
KEY_IMGAE_SIZE, KEY_IMGAE_SIZE,
KEY_VIDEO_SIZE, KEY_VIDEO_SIZE,
KEY_INFRARED_LAMP_POWER,
KEY_DELAYED,
KEY_PIR_SENSITIVITY,
KEY_STORAGE_LOOP_SWITCH,
KEY_FACTORY_RESET_FLAG,
KEY_FORMATTING_SD_CARD,
TEST_SHORT, TEST_SHORT,
TEST_LONG, TEST_LONG,
TEST_LLONG, TEST_LLONG,
@ -62,6 +68,28 @@ enum VideoSize
VIDEO_SIZE_END, VIDEO_SIZE_END,
}; };
enum InfraredIampPower
{
INFRARED_IAMP_POWER_LOW = 0,
INFRARED_IAMP_POWER_MID,
INFRARED_IAMP_POWER_HIGH,
INFRARED_IAMP_POWER_END,
};
enum Delayed
{
DELAYED_MIN = 0,
DELAYED_DEFAULT = 5,
DELAYED_MAX = 99,
DELAYED_END,
};
enum PirSensitivity
{
PIR_SENSITIVITY_MIN = 0,
PIR_SENSITIVITY_DEFAULT = 5,
PIR_SENSITIVITY_MAX = 9,
PIR_SENSITIVITY_END,
};
class IIpcConfig class IIpcConfig
{ {
public: public:

View File

@ -44,6 +44,34 @@ IpcConfig::IpcConfig()
innerMapVideoSize.insert(std::make_pair("video_size", std::reference_wrapper<int>(mAllData.videoSize))); innerMapVideoSize.insert(std::make_pair("video_size", std::reference_wrapper<int>(mAllData.videoSize)));
mCfgMapInt.insert(std::make_pair(IpcConfigKey::KEY_VIDEO_SIZE, innerMapVideoSize)); mCfgMapInt.insert(std::make_pair(IpcConfigKey::KEY_VIDEO_SIZE, 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::KEY_INFRARED_LAMP_POWER, innerMapInfraredLampPower));
std::map<std::string, std::reference_wrapper<int>> innerMapDelayed;
innerMapDelayed.insert(std::make_pair("delayed", std::reference_wrapper<int>(mAllData.delayed)));
mCfgMapInt.insert(std::make_pair(IpcConfigKey::KEY_DELAYED, innerMapDelayed));
std::map<std::string, std::reference_wrapper<int>> innerMapPirSensitivity;
innerMapPirSensitivity.insert(
std::make_pair("pir_sensitivity", std::reference_wrapper<int>(mAllData.pirSensitivity)));
mCfgMapInt.insert(std::make_pair(IpcConfigKey::KEY_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)));
mCfgMapBool.insert(std::make_pair(IpcConfigKey::KEY_STORAGE_LOOP_SWITCH, innerMapStorageLoopSwitch));
std::map<std::string, std::reference_wrapper<bool>> innerMapFactoryReset;
innerMapFactoryReset.insert(std::make_pair("factory_reset", std::reference_wrapper<bool>(mAllData.factoryReset)));
mCfgMapBool.insert(std::make_pair(IpcConfigKey::KEY_FACTORY_RESET_FLAG, innerMapFactoryReset));
std::map<std::string, std::reference_wrapper<bool>> innerMapFormattingSDCard;
innerMapFormattingSDCard.insert(
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<short>> innerMapShort; std::map<std::string, std::reference_wrapper<short>> innerMapShort;
innerMapShort.insert(std::make_pair("test_short", std::reference_wrapper<short>(mAllData.testShort))); innerMapShort.insert(std::make_pair("test_short", std::reference_wrapper<short>(mAllData.testShort)));
mCfgMapShort.insert(std::make_pair(IpcConfigKey::TEST_SHORT, innerMapShort)); mCfgMapShort.insert(std::make_pair(IpcConfigKey::TEST_SHORT, innerMapShort));
@ -60,10 +88,6 @@ IpcConfig::IpcConfig()
innerMapChar.insert(std::make_pair("test_char", std::reference_wrapper<char>(mAllData.testChar))); innerMapChar.insert(std::make_pair("test_char", std::reference_wrapper<char>(mAllData.testChar)));
mCfgMapChar.insert(std::make_pair(IpcConfigKey::TEST_CHAR, innerMapChar)); mCfgMapChar.insert(std::make_pair(IpcConfigKey::TEST_CHAR, innerMapChar));
std::map<std::string, std::reference_wrapper<bool>> innerMapBool;
innerMapBool.insert(std::make_pair("test_bool", std::reference_wrapper<bool>(mAllData.testBool)));
mCfgMapBool.insert(std::make_pair(IpcConfigKey::TEST_BOOL, innerMapBool));
std::map<std::string, std::reference_wrapper<float>> innerMapFloat; std::map<std::string, std::reference_wrapper<float>> innerMapFloat;
innerMapFloat.insert(std::make_pair("test_float", std::reference_wrapper<float>(mAllData.testFloat))); innerMapFloat.insert(std::make_pair("test_float", std::reference_wrapper<float>(mAllData.testFloat)));
mCfgMapFloat.insert(std::make_pair(IpcConfigKey::TEST_FLOAT, innerMapFloat)); mCfgMapFloat.insert(std::make_pair(IpcConfigKey::TEST_FLOAT, innerMapFloat));
@ -386,6 +410,57 @@ void IpcConfig::ReadAllConfigParameters(void)
ConfigSetInt(mCfg, "video_size", mAllData.videoSize); ConfigSetInt(mCfg, "video_size", mAllData.videoSize);
} }
StatusCode infraredIampPowerCode = ConfigGetInt(mCfg, "infrared_lamp_power", &(mAllData.infraredIampPower));
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);
}
StatusCode delayedCode = ConfigGetInt(mCfg, "delayed", &(mAllData.delayed));
if (StatusCodeEqual(delayedCode, "CONFIG_CODE_PARAM_NOT_EXIST")) {
LogWarning("delayed doesn't exist, will make it as default.\n");
mCfgChanged = CONFIG_HAS_CHANGED;
mAllData.delayed = DELAYED_DEFAULT;
ConfigSetInt(mCfg, "delayed", mAllData.delayed);
}
StatusCode pirSensitivityCode = ConfigGetInt(mCfg, "pir_sensitivity", &(mAllData.pirSensitivity));
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);
}
StatusCode storageLoopSwitchCode = ConfigGetBool(mCfg, "storage_loop_switch", &(mAllData.storageLoopSwitch));
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);
}
StatusCode factoryResetCode = ConfigGetBool(mCfg, "factory_reset", &(mAllData.factoryReset));
if (StatusCodeEqual(factoryResetCode, "CONFIG_CODE_PARAM_NOT_EXIST")) {
LogWarning("factory_resetCode doesn't exist, will make it as default.\n");
mCfgChanged = CONFIG_HAS_CHANGED;
constexpr bool factoryReset = true;
mAllData.factoryReset = factoryReset;
ConfigSetBool(mCfg, "factory_reset", mAllData.factoryReset);
}
StatusCode formattingSDCardCode = ConfigGetBool(mCfg, "formatting_SD_card", &(mAllData.formattingSDCard));
if (StatusCodeEqual(formattingSDCardCode, "CONFIG_CODE_PARAM_NOT_EXIST")) {
LogWarning("formatting_SD_card doesn't exist, will make it as default.\n");
mCfgChanged = CONFIG_HAS_CHANGED;
constexpr bool formattingSDCard = true;
mAllData.formattingSDCard = formattingSDCard;
ConfigSetBool(mCfg, "formatting_SD_card", mAllData.formattingSDCard);
}
StatusCode shortCode = ConfigGetShort(mCfg, "test_short", &(mAllData.testShort)); StatusCode shortCode = ConfigGetShort(mCfg, "test_short", &(mAllData.testShort));
if (StatusCodeEqual(shortCode, "CONFIG_CODE_PARAM_NOT_EXIST")) { if (StatusCodeEqual(shortCode, "CONFIG_CODE_PARAM_NOT_EXIST")) {
LogWarning("test_short doesn't exist, will make it as default.\n"); LogWarning("test_short doesn't exist, will make it as default.\n");
@ -422,15 +497,6 @@ void IpcConfig::ReadAllConfigParameters(void)
ConfigSetChar(mCfg, "test_char", mAllData.testChar); ConfigSetChar(mCfg, "test_char", mAllData.testChar);
} }
StatusCode boolCode = ConfigGetBool(mCfg, "test_bool", &(mAllData.testBool));
if (StatusCodeEqual(boolCode, "CONFIG_CODE_PARAM_NOT_EXIST")) {
LogWarning("test_bool doesn't exist, will make it as default.\n");
mCfgChanged = CONFIG_HAS_CHANGED;
constexpr bool DEFAULT_TEST_BOOL_NUM = true;
mAllData.testBool = DEFAULT_TEST_BOOL_NUM;
ConfigSetBool(mCfg, "test_bool", mAllData.testBool);
}
StatusCode floatCode = ConfigGetFloat(mCfg, "test_float", &(mAllData.testFloat)); StatusCode floatCode = ConfigGetFloat(mCfg, "test_float", &(mAllData.testFloat));
if (StatusCodeEqual(floatCode, "CONFIG_CODE_PARAM_NOT_EXIST")) { if (StatusCodeEqual(floatCode, "CONFIG_CODE_PARAM_NOT_EXIST")) {
LogWarning("test_float doesn't exist, will make it as default.\n"); LogWarning("test_float doesn't exist, will make it as default.\n");

View File

@ -25,15 +25,19 @@ constexpr bool CONFIG_HAS_NOT_CHANGED = false;
typedef char CHAR_STRING[256]; typedef char CHAR_STRING[256];
typedef struct Config_s typedef struct Config_s
{ {
bool storageLoopSwitch;
bool factoryReset;
bool formattingSDCard;
int workMode; int workMode;
int continuousShot; int continuousShot;
int burstPhotoInterval; int burstPhotoInterval;
int videoSize; int videoSize;
int infraredIampPower;
int delayed;
int pirSensitivity;
double imageSize; double imageSize;
short testShort; short testShort;
char testChar; char testChar;
bool testBool;
long testLong; long testLong;
long long testLLong; long long testLLong;
float testFloat; float testFloat;

View File

@ -37,6 +37,36 @@ TEST(IpcConfigTest, Demo)
videoSize = VIDEO_SIZE_10; videoSize = VIDEO_SIZE_10;
IIpcConfig::GetInstance()->SetInt(IpcConfigKey::KEY_VIDEO_SIZE, videoSize); IIpcConfig::GetInstance()->SetInt(IpcConfigKey::KEY_VIDEO_SIZE, videoSize);
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);
int delayed = IIpcConfig::GetInstance()->GetInt(IpcConfigKey::KEY_DELAYED);
LogInfo("Get delayed = %d\n", delayed);
delayed = DELAYED_MAX;
IIpcConfig::GetInstance()->SetInt(IpcConfigKey::KEY_DELAYED, delayed);
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);
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);
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);
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);
short testShort = IIpcConfig::GetInstance()->GetShort(IpcConfigKey::TEST_SHORT); short testShort = IIpcConfig::GetInstance()->GetShort(IpcConfigKey::TEST_SHORT);
LogInfo("Get test_short = %d\n", testShort); LogInfo("Get test_short = %d\n", testShort);
const short numShort = 888; const short numShort = 888;
@ -57,11 +87,6 @@ TEST(IpcConfigTest, Demo)
const char numChar = 'A'; const char numChar = 'A';
IIpcConfig::GetInstance()->SetChar(IpcConfigKey::TEST_CHAR, numChar); IIpcConfig::GetInstance()->SetChar(IpcConfigKey::TEST_CHAR, numChar);
bool testBool = IIpcConfig::GetInstance()->GetBool(IpcConfigKey::TEST_BOOL);
LogInfo("Get test_bool = %d\n", testBool);
const bool numBool = false;
IIpcConfig::GetInstance()->SetBool(IpcConfigKey::TEST_BOOL, numBool);
float testFloat = IIpcConfig::GetInstance()->GetFloat(IpcConfigKey::TEST_FLOAT); float testFloat = IIpcConfig::GetInstance()->GetFloat(IpcConfigKey::TEST_FLOAT);
LogInfo("Get test_float = %lf\n", testFloat); LogInfo("Get test_float = %lf\n", testFloat);
const float numFloat = 1.123456; const float numFloat = 1.123456;