| | |
| | | using System; |
| | | using System.Text; |
| | | using Newtonsoft.Json.Linq; |
| | | |
| | | namespace HDL_ON.Common |
| | | namespace HDL_ON.DriverLayer |
| | | { |
| | | public class A_Protocal_Common |
| | | { |
| | | public static A_Protocal_Common apc; |
| | | |
| | | public A_Protocal_Common() |
| | | { |
| | | apc = new A_Protocal_Common(); |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 获取13位时间戳 |
| | | /// </summary> |
| | | /// <param name="time">时间</param> |
| | | /// <returns>long</returns> |
| | | public long Get_time_stamp() |
| | | { |
| | | //DateTime startTime = new DateTime(1970, 1, 1, 0, 0, 0, 0); |
| | | long t = DateTime.Now.Ticks / 10000; //除10000调整为13位 |
| | | return t; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 转换通讯数据 |
| | | /// </summary> |
| | | public byte[] ConvertSendBodyData(string topic, string bodyDataString) |
| | | { |
| | | string topicString = "Topic:" + topic + "/r/n"; |
| | | byte[] bodyBytes = Encoding.ASCII.GetBytes(bodyDataString); |
| | | string lenghtString = "Length:" + bodyBytes.Length.ToString() + "/r/n" + "/r/n"; |
| | | |
| | | string sendDataString = topicString + lenghtString + bodyDataString; |
| | | byte[] sendDataBytes = Encoding.ASCII.GetBytes(sendDataString); |
| | | |
| | | return sendDataBytes; |
| | | } |
| | | /// <summary> |
| | | /// 转换接收到的数据 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public string ConvertReceiveData(byte[] bytes) |
| | | { |
| | | string receiveString = ""; |
| | | |
| | | string topic = ""; |
| | | int lenght = 0; |
| | | |
| | | var reString = System.Text.Encoding.UTF8.GetString(bytes); |
| | | var res = reString.Split("/r/n/r/n"); |
| | | |
| | | |
| | | if (res.Length == 2) |
| | | { |
| | | var topics = res[0].Split("/r/n"); |
| | | foreach (var ts in topics) |
| | | { |
| | | var key = ts.Split(":"); |
| | | switch (key[0]) |
| | | { |
| | | case "Topic": |
| | | topic = key[1]; |
| | | break; |
| | | case "Lenght": |
| | | lenght = Convert.ToInt32(key[1]); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | switch (topic) |
| | | { |
| | | case CommunicationTopic.SearchLoaclGateway: |
| | | var jt = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponsePack>(res[1]); |
| | | if (jt != null) |
| | | { |
| | | var device = Newtonsoft.Json.JsonConvert.DeserializeObject<Entity.DeviceModule>(jt.objects.ToString()); |
| | | //Newtonsoft.Json.Linq.JObject.FromObject(jt.objects); |
| | | } |
| | | break; |
| | | } |
| | | |
| | | } |
| | | return receiveString; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 通讯回复数据包 |
| | | /// 本地通讯数据 |
| | | /// </summary> |
| | | public class LocalCommunicationData |
| | | { |
| | | public string Topic; |
| | | public int Length; |
| | | |
| | | public string BodyDataString; |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 通讯回复有效数据 |
| | | /// </summary> |
| | | public class ResponsePack |
| | | { |
| | |
| | | /// <summary> |
| | | /// 通讯主题 |
| | | /// </summary> |
| | | public static class CommunicationTopic |
| | | public class CommunicationTopic |
| | | { |
| | | static CommunicationTopic _ct; |
| | | public static CommunicationTopic ct |
| | | { |
| | | get |
| | | { |
| | | if (_ct == null) |
| | | { |
| | | _ct = new CommunicationTopic(); |
| | | } |
| | | return _ct; |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 搜索本地网关 |
| | | /// </summary> |
| | | public const string SearchLoaclGateway = "/user/all/custom/gateway/search"; |
| | | /// <summary> |
| | | /// 搜索网关回复 |
| | | /// </summary> |
| | | public const string SearchLoaclGatewayReply = "/user/all/custom/gateway/search_reply"; |
| | | /// <summary> |
| | | /// 网关广播数据 |
| | | /// </summary> |
| | | public const string GatewayBroadcast = "/user/all/custom/gateway/broadcast"; |
| | | /// <summary> |
| | | /// 调试软件上传oid列表 |
| | | /// </summary> |
| | | public const string AddDeviceOids = "/user/onpro/custom/device/add"; |
| | | /// <summary> |
| | | /// 调试软件上传功能列表 |
| | | /// </summary> |
| | | public const string AddFunctions = "/user/onpro/custom/function/attribute/add"; |
| | | /// <summary> |
| | | /// 调试软件获取appOid列表 |
| | | /// </summary> |
| | | public const string BusPcGetAppOids = "/user/onpro/custom/device/list/get"; |
| | | /// <summary> |
| | | /// 调试软件获取appSid列表 |
| | | /// </summary> |
| | | public const string BusPcGetAppSids = "/user/onpro/custom/function/list/get"; |
| | | |
| | | /// <summary> |
| | | /// 本地控制功能状态主题 |
| | | /// </summary> |
| | | public string ControlFunctionTopic |
| | | { |
| | | get |
| | | { |
| | | return $"/base/{Control.Ins.GatewayId}/thing/property/down"; |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 本地控制红外设备功能主题 |
| | | /// </summary> |
| | | public string ControlIrFunctionTopic |
| | | { |
| | | get |
| | | { |
| | | return $"/base/${Control.Ins.GatewayId}/thing/property/down"; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 读取功能状态 |
| | | /// </summary> |
| | | public string ReadStatus |
| | | { |
| | | get |
| | | { |
| | | return $"/base/{Control.Ins.GatewayId}/thing/property/read"; |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 网关上报设备状态 |
| | | /// </summary> |
| | | public string GatewayUpStatus |
| | | { |
| | | get |
| | | { |
| | | return $"/base/{Control.Ins.GatewayId}/thing/property/up"; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取网关的功能列表 |
| | | /// </summary> |
| | | public string GetGatewayFunctionList |
| | | { |
| | | get |
| | | { |
| | | return $"/user/{Control.Ins.GatewayId}/custom/device/list/get"; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 网关上报设备状态 |
| | | /// 去掉id对比 |
| | | /// </summary> |
| | | public string GatewayUpSortTopic |
| | | { |
| | | get |
| | | { |
| | | return "/thing/property/up"; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 场景执行 |
| | | /// </summary> |
| | | public string ControlScene |
| | | { |
| | | get |
| | | { |
| | | return $"/user/{Control.Ins.GatewayId}/custom/scene/execute"; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 网关进入配网模式 |
| | | /// </summary> |
| | | public string AuthGateway |
| | | { |
| | | get |
| | | { |
| | | return $"/user/{Control.Ins.GatewayId}/custom/device/auth_gateway"; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 安防控制 |
| | | /// </summary> |
| | | public string ControlSeurity |
| | | { |
| | | get |
| | | { |
| | | return $"/user/{Control.Ins.GatewayId}/custom/security/status/set"; |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 安防状态更新 |
| | | /// </summary> |
| | | public string SecurityStatusUp |
| | | { |
| | | get |
| | | { |
| | | return $"/user/{Control.Ins.GatewayId}/custom/security/status/up"; |
| | | }///user/1413055228417130497/custom/security/status/up |
| | | } |
| | | /// <summary> |
| | | /// 读取安防状态信息 |
| | | /// </summary> |
| | | public string ReadSecurityStatus |
| | | { |
| | | get |
| | | { |
| | | return $"/user/{Control.Ins.GatewayId}/custom/security/list/get"; |
| | | } |
| | | } |
| | | } |
| | | } |