This commit is contained in:
parent
9ec4787700
commit
cb99915ec3
|
@ -89,7 +89,7 @@ bool Alarm::AlarmSet(const Pair& args, Stream& result)
|
||||||
|
|
||||||
byte resid = SetCfg(Id, alarm);
|
byte resid = SetCfg(Id, alarm);
|
||||||
result.Write((byte)resid);
|
result.Write((byte)resid);
|
||||||
if(resid)return true;
|
if (resid)return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ byte Alarm::SetCfg(byte id, AlarmDataType& data)
|
||||||
{
|
{
|
||||||
if (!cfg.Data[i].Enable)
|
if (!cfg.Data[i].Enable)
|
||||||
{
|
{
|
||||||
id = i+1;
|
id = i + 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -131,7 +131,7 @@ byte Alarm::SetCfg(byte id, AlarmDataType& data)
|
||||||
if (!id)return 0; // 查找失败
|
if (!id)return 0; // 查找失败
|
||||||
|
|
||||||
Buffer bf(&data.Number, sizeof(AlarmDataType));
|
Buffer bf(&data.Number, sizeof(AlarmDataType));
|
||||||
Buffer bf2(&cfg.Data[id-1].Number, sizeof(AlarmDataType));
|
Buffer bf2(&cfg.Data[id - 1].Number, sizeof(AlarmDataType));
|
||||||
bf2 = bf;
|
bf2 = bf;
|
||||||
|
|
||||||
for (int i = 0; i < 20; i++)
|
for (int i = 0; i < 20; i++)
|
||||||
|
@ -265,10 +265,10 @@ void Alarm::AlarmTask()
|
||||||
bs.Show(true);
|
bs.Show(true);
|
||||||
|
|
||||||
auto type = (int)data.Data[1];
|
auto type = (int)data.Data[1];
|
||||||
AlarmActuator* acttor;
|
AlarmActuator acttor;
|
||||||
if (dic.TryGetValue(type, acttor))
|
if (dic.TryGetValue(type, acttor))
|
||||||
{
|
{
|
||||||
acttor->Actuator(bs);
|
acttor(NextAlarmId, bs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
21
App/Alarm.h
21
App/Alarm.h
|
@ -32,12 +32,12 @@ public:
|
||||||
#pragma pack(1)
|
#pragma pack(1)
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
byte Number;
|
byte Number; // 闹钟编号
|
||||||
byte Enable;
|
byte Enable; // 是否有效
|
||||||
AlarmType Type;
|
AlarmType Type; // week相关
|
||||||
byte Hour;
|
byte Hour; // 时
|
||||||
byte Minutes;
|
byte Minutes; // 分
|
||||||
byte Seconds;
|
byte Seconds; // 秒
|
||||||
byte Data[11]; // 第一个字节 有效数据长度,第二个字节动作类型,后面是数据
|
byte Data[11]; // 第一个字节 有效数据长度,第二个字节动作类型,后面是数据
|
||||||
}AlarmDataType;
|
}AlarmDataType;
|
||||||
#pragma pack(pop) // 恢复对齐状态
|
#pragma pack(pop) // 恢复对齐状态
|
||||||
|
@ -51,22 +51,25 @@ public:
|
||||||
bool AlarmSet(const Pair& args, Stream& result);
|
bool AlarmSet(const Pair& args, Stream& result);
|
||||||
/* 注册给 TokenClient 名称 Policy/AlarmGet */
|
/* 注册给 TokenClient 名称 Policy/AlarmGet */
|
||||||
bool AlarmGet(const Pair& args, Stream& result);
|
bool AlarmGet(const Pair& args, Stream& result);
|
||||||
|
// Config
|
||||||
byte SetCfg(byte id, AlarmDataType& data);
|
byte SetCfg(byte id, AlarmDataType& data);
|
||||||
bool GetCfg(byte id, AlarmDataType& data);
|
bool GetCfg(byte id, AlarmDataType& data);
|
||||||
|
|
||||||
void Start();
|
void Start();
|
||||||
|
// 注册执行动作的函数
|
||||||
void Register(byte type, AlarmActuator act);
|
void Register(byte type, AlarmActuator act);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Dictionary<int, AlarmActuator> dic;// AlarmDataType.Data[1] 表示动作类型,由此字典进行匹配动作执行器
|
Dictionary<int, AlarmActuator> dic;// AlarmDataType.Data[1] 表示动作类型,由此字典进行匹配动作执行器
|
||||||
|
|
||||||
uint AlarmTaskId;
|
uint AlarmTaskId; // 闹钟TaskId
|
||||||
List<int>NextAlarmIds; // 下次运行的编号,允许多组定时器定时时间相同
|
List<int>NextAlarmIds; // 下次运行的编号,允许多组定时器定时时间相同
|
||||||
int NextAlarmMs; // 下次闹钟时间
|
int NextAlarmMs; // 下次闹钟时间
|
||||||
|
// Task
|
||||||
void AlarmTask();
|
void AlarmTask();
|
||||||
|
// 找到最近的闹钟时间的id以及时间
|
||||||
byte FindNext(int& nextTime);
|
byte FindNext(int& nextTime);
|
||||||
|
// 计算下次闹钟时间
|
||||||
int CalcNextTime(AlarmDataType& data);
|
int CalcNextTime(AlarmDataType& data);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue