parent
0dcea73572
commit
5de4afdcaa
14
Config.cpp
14
Config.cpp
|
@ -190,6 +190,20 @@ bool Config::Get(const char* name, ByteArray& bs)
|
|||
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)
|
||||
{
|
||||
if(name == NULL) return NULL;
|
||||
|
|
2
Config.h
2
Config.h
|
@ -25,6 +25,8 @@ public:
|
|||
const void* Set(const char* name, const ByteArray& bs);
|
||||
// 获取配置数据
|
||||
bool Get(const char* name, ByteArray& bs);
|
||||
// 获取配置数据,如果不存在则覆盖
|
||||
bool GetOrSet(const char* name, ByteArray& bs);
|
||||
// 获取配置数据
|
||||
const void* Get(const char* name);
|
||||
|
||||
|
|
|
@ -9,12 +9,38 @@
|
|||
Length = len;
|
||||
}*/
|
||||
|
||||
/*const TinyConfig& Default()
|
||||
{
|
||||
const TinyConfig tc =
|
||||
{
|
||||
sizeof(TinyConfig),
|
||||
|
||||
1,
|
||||
1,
|
||||
|
||||
10,
|
||||
60,
|
||||
5,
|
||||
|
||||
120,
|
||||
250,
|
||||
60,
|
||||
};
|
||||
|
||||
return tc;
|
||||
}*/
|
||||
|
||||
void TinyConfig::LoadDefault()
|
||||
{
|
||||
// 实际内存大小,减去头部大小
|
||||
uint len = sizeof(this) - ((int)&Length - (int)this);
|
||||
memset(&Length, 0, len);
|
||||
Length = len;
|
||||
|
||||
Kind = Sys.Code;
|
||||
//Server = 0x01;
|
||||
|
||||
PingTime = 15;
|
||||
PingTime = 10;
|
||||
OfflineTime = 60;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,10 +13,15 @@
|
|||
// 配置信息
|
||||
struct TinyConfig
|
||||
{
|
||||
ushort Length; // 数据长度
|
||||
byte Length; // 数据长度
|
||||
|
||||
byte HardVer; // 硬件版本
|
||||
byte SoftVer; // 软件版本
|
||||
|
||||
byte PingTime; // 心跳时间。秒
|
||||
byte OfflineTime;// 离线阀值时间。秒
|
||||
byte SleepTime; // 睡眠时间。秒
|
||||
|
||||
ushort Kind; // 类型
|
||||
byte Address; // 分配得到的设备地址
|
||||
byte Password[16]; // 通信密码
|
||||
|
@ -25,14 +30,11 @@ struct TinyConfig
|
|||
ushort Speed; // 传输速度
|
||||
byte ServerKey[16]; // 服务端组网密码,退网时使用。一般6字节
|
||||
|
||||
ushort PingTime; // 心跳时间。秒
|
||||
ushort OfflineTime; // 离线阀值时间。秒
|
||||
ushort SleepTime; // 睡眠时间。秒
|
||||
|
||||
// 初始化,各字段为0
|
||||
//TinyConfig();
|
||||
//const TinyConfig& Default();
|
||||
void LoadDefault();
|
||||
|
||||
|
||||
// 序列化到消息数据流
|
||||
void Write(Stream& ms) const;
|
||||
void Read(Stream& ms);
|
||||
|
|
Loading…
Reference in New Issue