using System;
using System.Collections.Generic;
namespace HDL_ON.UI.UI2.Intelligence.Automation
{
///
/// 逻辑存储数据对象
///
public class Logic
{
///
/// 逻辑唯一标识
///
public string sid = "";
///
/// 逻辑名称
///
public string name = "逻辑一";
///
/// 逻辑条件关系(与and:,或:or)
///
public string relation = "or";
///
/// 逻辑状态(true,false)
///
public string enable = "true";
///
/// 逻辑执行循环周期(执行一次,每天,每月,星期)
///
public Cycle cycle = new Cycle();
///
/// 逻辑输入条件数组
///
public List input = new List ();
///
/// 逻辑输出目标数组
///
public List output = new List();
///
/// 生成逻辑sid方法
///
public string NewSid()
{
string logicId = "";
try
{
string sOidBeginsWith = "000101";//厂商 + 通讯方式
DateTime dt = DateTime.Now;
DateTime startTime = TimeZoneInfo.ConvertTimeToUtc(new DateTime(2020, 1, 1));
long m = (long)((dt - startTime).TotalMilliseconds / 10);
string sTimeSpan = "00000000";
byte[] arry = new byte[4];
arry[0] = (byte)(m & 0xFF);
arry[1] = (byte)((m & 0xFF00) >> 8);
arry[2] = (byte)((m & 0xFF0000) >> 16);
arry[3] = (byte)((m >> 24) & 0xFF);
sTimeSpan = arry[0].ToString("X2") + arry[1].ToString("X2") + arry[2].ToString("X2") + arry[3].ToString("X2");
if (sTimeSpan.Length > 8)
{
sTimeSpan = sTimeSpan.Substring(0, 8);
}
else
{
sTimeSpan = "00000000";
}
logicId = sOidBeginsWith + sTimeSpan;
logicId += "0A";
logicId += "0A01";
//0A01 物模型为逻辑, 0001 表示 1 号逻辑功能
int iTopLogicId = 1;
Random random = new Random();
iTopLogicId = random.Next(0, 255);
iTopLogicId += random.Next(0, 255);
logicId += iTopLogicId.ToString("X4");//逻辑号 两个byte
logicId += "1100";
}
catch
{
return logicId;
}
return logicId;
}
}
///
/// 执行周期对象
///
public class Cycle
{
///
/// 时间类型
/// (执行一次:once,每天:day,每月:mon,星期:week,日期段:date_to_date)
///
public string type = "";
public List value = new List();
}
///
/// 输入条件对象
///
public class Input
{
///
/// 逻辑输入条件唯一标识
///
public string sid = "";
///
/// 逻辑输入条件类型
/// 时间点条件=1;
/// 时间段条件=2;
/// 设备状态变化条件=3;
/// 环境信息条件=4;
/// 安防条件=5;
/// 云端天气条件=6;
/// 某个逻辑/场景的输出条件=7;
/// 地理围栏=8;
///
public string condition_type = "";
public List> condition = new List>();
}
///
/// 输出目标对象
///
public class Output
{
///
/// 逻辑输出目标唯一标识
///
public string sid = "";
///
/// 逻辑输出目标类型
/// 设备=1;
/// 场景=2;
/// 安防=3;
///
public string target_type = "";
public List> status = new List>();
}
}