获取配置数据,如果不存在则覆盖。

三位触摸开关测试通过
This commit is contained in:
nnhy 2015-10-25 10:16:51 +00:00
parent 0dcea73572
commit 5de4afdcaa
4 changed files with 51 additions and 7 deletions

View File

@ -190,6 +190,20 @@ bool Config::Get(const char* name, ByteArray& bs)
return false; return false;
} }
// 获取配置数据,如果不存在则覆盖
bool Config::GetOrSet(const char* name, ByteArray& bs)
{
if(name == NULL) return false;
// 输入数据已存在,直接返回
if(Get(name, bs)) return true;
// 否则,用这块数据去覆盖吧
Set(name, bs);
return false;
}
const void* Config::Get(const char* name) const void* Config::Get(const char* name)
{ {
if(name == NULL) return NULL; if(name == NULL) return NULL;

View File

@ -25,6 +25,8 @@ public:
const void* Set(const char* name, const ByteArray& bs); const void* Set(const char* name, const ByteArray& bs);
// 获取配置数据 // 获取配置数据
bool Get(const char* name, ByteArray& bs); bool Get(const char* name, ByteArray& bs);
// 获取配置数据,如果不存在则覆盖
bool GetOrSet(const char* name, ByteArray& bs);
// 获取配置数据 // 获取配置数据
const void* Get(const char* name); const void* Get(const char* name);

View File

@ -9,12 +9,38 @@
Length = len; Length = len;
}*/ }*/
/*const TinyConfig& Default()
{
const TinyConfig tc =
{
sizeof(TinyConfig),
1,
1,
10,
60,
5,
120,
250,
60,
};
return tc;
}*/
void TinyConfig::LoadDefault() void TinyConfig::LoadDefault()
{ {
// 实际内存大小,减去头部大小
uint len = sizeof(this) - ((int)&Length - (int)this);
memset(&Length, 0, len);
Length = len;
Kind = Sys.Code; Kind = Sys.Code;
//Server = 0x01; //Server = 0x01;
PingTime = 15; PingTime = 10;
OfflineTime = 60; OfflineTime = 60;
} }

View File

@ -13,10 +13,15 @@
// 配置信息 // 配置信息
struct TinyConfig struct TinyConfig
{ {
ushort Length; // 数据长度 byte Length; // 数据长度
byte HardVer; // 硬件版本 byte HardVer; // 硬件版本
byte SoftVer; // 软件版本 byte SoftVer; // 软件版本
byte PingTime; // 心跳时间。秒
byte OfflineTime;// 离线阀值时间。秒
byte SleepTime; // 睡眠时间。秒
ushort Kind; // 类型 ushort Kind; // 类型
byte Address; // 分配得到的设备地址 byte Address; // 分配得到的设备地址
byte Password[16]; // 通信密码 byte Password[16]; // 通信密码
@ -25,12 +30,9 @@ struct TinyConfig
ushort Speed; // 传输速度 ushort Speed; // 传输速度
byte ServerKey[16]; // 服务端组网密码退网时使用。一般6字节 byte ServerKey[16]; // 服务端组网密码退网时使用。一般6字节
ushort PingTime; // 心跳时间。秒
ushort OfflineTime; // 离线阀值时间。秒
ushort SleepTime; // 睡眠时间。秒
// 初始化各字段为0 // 初始化各字段为0
//TinyConfig(); //TinyConfig();
//const TinyConfig& Default();
void LoadDefault(); void LoadDefault();
// 序列化到消息数据流 // 序列化到消息数据流