From 2b6eeda2c91f0e570b58b2799758475b46c1ad61 Mon Sep 17 00:00:00 2001 From: ningshuxia <ningshuxia0927@outlook.com> Date: 星期四, 27 十月 2022 14:22:03 +0800 Subject: [PATCH] 修改南通接口 --- Socket/IStation.DataDockingSocket4NT/MsgHandle/BseMsgHelper.cs | 129 ++++ Socket/IStation.DataDockingSocket4NT/MsgHandle/StartUpMsgHelper.cs | 102 +++ /dev/null | 575 --------------------- Socket/IStation.DataDockingSocket4NT/control/SendControlJobHelper.cs | 67 - Socket/IStation.DataDockingSocket4NT/MsgHandle/ShunDownMsgHelper.cs | 109 ++++ Socket/IStation.DataDockingSocket4NT/MsgHandle/MonitorMsgHelper.cs | 367 +++++++++++++ Socket/IStation.DataDockingSocket4NT/paras/AppParasHelper.cs | 45 + Socket/IStation.DataDockingSocket4NT/paras/eReceiveMsgType.cs | 17 Socket/IStation.DataDockingSocket4NT/paras/eShutDownInstructionStatus.cs | 15 Socket/IStation.DataDockingSocket4NT/paras/eStartUpInstructionStatus.cs | 17 Socket/IStation.DataDockingSocket4NT/Log/LogHelper.cs | 10 Socket/IStation.DataDockingSocket4NT/MsgHandle/HandleHelper.cs | 112 ++++ 12 files changed, 941 insertions(+), 624 deletions(-) diff --git a/Socket/IStation.DataDockingSocket4NT/HandleHelper.cs b/Socket/IStation.DataDockingSocket4NT/HandleHelper.cs deleted file mode 100644 index e065386..0000000 --- a/Socket/IStation.DataDockingSocket4NT/HandleHelper.cs +++ /dev/null @@ -1,103 +0,0 @@ -锘縰sing System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using IStation.Model; - -namespace IStation.DataDockingSocket -{ - public class HandleHelper : IDataDockingSocket.IHandleHelper - { - /// <summary> - /// 澶勭悊娉ㄥ唽鐮� - /// </summary> - public void HandleRegisterCode(IMonitorDataDockingSession session) - { - if (session == null) - return; - if (!session.IsConnected) - return; - - if (SessionHelper.Cache != null) - { - if (SessionHelper.Cache != session) - { - if (SessionHelper.Cache.IsConnected) - { - SessionHelper.Cache.Close($"{session.SessionName} 涓紝浜х敓鏂扮殑浼氳瘽锛�"); - } - } - } - - SessionHelper.Cache = session; - - - foreach (var item in MsgDataHelper.GetInstructionQuerys()) - { - SendInstructionJobHelper.StartJob(session, item); - if(item.SpaceTime>0) - Thread.Sleep(item.SpaceTime * 1000); - } - - SendControlJobHelper.StartJob(session); - } - - /// <summary> - /// 澶勭悊蹇冭烦鍖� - /// </summary> - public void HandleHeartbeat(IMonitorDataDockingSession session) - { - - } - - /// <summary> - /// 澶勭悊鏁版嵁 - /// </summary> - public void HandleData - ( - IMonitorDataDockingSession session, - byte[] bytes, - List<Model.DataDockingConfigure.Mapper> mappers, - Action<List<Model.MonitorDataDockingReceiveRecord>> receive - ) - { - if (session == null) - return; - if (!session.IsConnected) - return; - if (bytes == null) - return; - - - var receList = MsgDataHelper.HandleData(bytes); - if (receList != null && receList.Count > 0) - { - receive(receList); - NtLogHelper.Info($"瑙f瀽鏁版嵁鏁伴噺:{receList.Count}\n\r" + - $"{JsonHelper.Object2Json(receList)}"); - } - else - { - NtLogHelper.Error("鏃犺В鏋愭暟鎹�"); - } - - if (MsgDataHelper.IsSrc()) - { - NtLogHelper.Src(bytes); - } - if (MsgDataHelper.IsDebug()) - { - NtLogHelper.Debug(receList); - } - } - - - - - - - - } -} diff --git a/Socket/IStation.DataDockingSocket4NT/Log/LogHelper.cs b/Socket/IStation.DataDockingSocket4NT/Log/LogHelper.cs index d8835e2..32f1e86 100644 --- a/Socket/IStation.DataDockingSocket4NT/Log/LogHelper.cs +++ b/Socket/IStation.DataDockingSocket4NT/Log/LogHelper.cs @@ -24,16 +24,26 @@ var json = JsonHelper.Object2Json(rece_list); LogHelper.Custom(_logNameDebug, json); } + public static void Debug(string msg) + { + + LogHelper.Custom(_logNameDebug, msg); + } private const string _logNameSrc = "socket-nt-src"; + /// <summary> /// 鐢熸垚 /// </summary> public static void Src(byte[] bts) { + if (!AppParasHelper.IsSrc()) + return; + if (bts == null || bts.Count() < 1) return; + var message_bts = BitTransfer.ToString(bts); LogHelper.Custom(_logNameSrc, message_bts); } diff --git a/Socket/IStation.DataDockingSocket4NT/MsgHandle/BseMsgHelper.cs b/Socket/IStation.DataDockingSocket4NT/MsgHandle/BseMsgHelper.cs new file mode 100644 index 0000000..ba9a9ff --- /dev/null +++ b/Socket/IStation.DataDockingSocket4NT/MsgHandle/BseMsgHelper.cs @@ -0,0 +1,129 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IStation.DataDockingSocket +{ + internal class ByteMsgHelper + { + /// <summary> + /// 瀛楃涓茶浆16杩涘埗瀛楃2 + /// </summary> + /// <param name="content">瀛楃涓�</param> + /// <param name="encode">缂栫爜鏍煎紡</param> + /// <returns></returns> + public static List<byte> StringToHexValuve(string content, out string error_info) + { + //鍘绘帀绌烘牸 + string[] arr = content.Split(' '); + if (arr.Length < 3) + { + arr = content.Split('-'); + if (arr.Length < 3) + { + error_info = "瀛楃鏃犳硶瑙f瀽"; + return null; + } + } + List<byte> result = new List<byte>(); + for (int i = 0; i < arr.Length; i++) + { + if (string.IsNullOrWhiteSpace(arr[i])) + continue; + + var dddd = Convert.ToByte(arr[i], 16); + result.Add(dddd); + } + error_info = null; + return result; + } + + #region 鏁版嵁杞寲 + public static int GetInt2Byte(byte[] byteMessage, int startPosition, out string info) + { + byte[] value = new byte[2]; + Array.Copy(byteMessage, startPosition, value, 0, 2); + + info = BitConverter.ToString(value, 0, value.Length); + // ushort rValueP = BitConverter.ToUInt16(value.Reverse().ToArray(), 0); + + //short rValueP = 0; + //rValueP = byteMessage[ startPosition]; + //rValueP <<= 8; + //rValueP += byteMessage[ startPosition + 1]; + //return rValueP; + return bytesToInt2(byteMessage, startPosition); + } + + public static int GetInt4Byte(byte[] byteMessage, int startPosition, out string info) + { + byte[] value = new byte[4]; + Array.Copy(byteMessage, startPosition, value, 0, 4); + + info = BitConverter.ToString(value, 0, value.Length); + // ushort rValueP = BitConverter.ToUInt16(value.Reverse().ToArray(), 0); + + //short rValueP = 0; + //rValueP = byteMessage[ startPosition]; + //rValueP <<= 8; + //rValueP += byteMessage[ startPosition + 1]; + //return rValueP; + return bytesToInt4(byteMessage, startPosition); + } + /** + * byte鏁扮粍涓彇int鏁板�硷紝鏈柟娉曢�傜敤浜�(浣庝綅鍦ㄥ墠锛岄珮浣嶅湪鍚�)鐨勯『搴忥紝鍜屽拰intToBytes锛堬級閰嶅浣跨敤 + * + * @param src + * byte鏁扮粍 + * @param offset + * 浠庢暟缁勭殑绗琽ffset浣嶅紑濮� + * @return int鏁板�� + */ + public static int bytesToInt2_LH(byte[] src, int offset) + { + int value; + value = src[offset] & 0xFF + | (src[offset + 1] & 0xFF) << 8; + return value; + } + + /** + * byte鏁扮粍涓彇int鏁板�硷紝鏈柟娉曢�傜敤浜�(浣庝綅鍦ㄥ悗锛岄珮浣嶅湪鍓�)鐨勯『搴忋��2涓瓧鑺� + */ + public static int bytesToInt2(byte[] src, int offset) + { + int value; + value = + (src[offset + 0] & 0xFF) << 8 + | src[offset + 1] & 0xFF; + return value; + } + /** + * byte鏁扮粍涓彇int鏁板�硷紝鏈柟娉曢�傜敤浜�(浣庝綅鍦ㄥ悗锛岄珮浣嶅湪鍓�)鐨勯『搴忋��4涓瓧鑺� + */ + public static int bytesToInt4(byte[] src, int offset = 0) + { + int value; + value = (src[offset] & 0xFF) << 24 + | (src[offset + 1] & 0xFF) << 16 + | (src[offset + 2] & 0xFF) << 8 + | src[offset + 3] & 0xFF; + return value; + } + + public static double GetDouble1(byte[] byteMessage, int startPosition, out string info) + { + byte[] value = new byte[4]; + Array.Copy(byteMessage, startPosition, value, 0, 4); + info = BitConverter.ToString(value, 0, value.Length); + + //return BitConverter.ToDouble(byteMessage, startPosition); + return BitConverter.ToSingle(value.Reverse().ToArray(), 0);//閲囩敤浜咺EEE-754浜岃繘鍒舵诞鐐规暟绠楁湳鏍囧噯 + } + + + #endregion + } +} diff --git a/Socket/IStation.DataDockingSocket4NT/MsgHandle/HandleHelper.cs b/Socket/IStation.DataDockingSocket4NT/MsgHandle/HandleHelper.cs new file mode 100644 index 0000000..36382c1 --- /dev/null +++ b/Socket/IStation.DataDockingSocket4NT/MsgHandle/HandleHelper.cs @@ -0,0 +1,112 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using IStation.Model; +using IStation.Untity; + +namespace IStation.DataDockingSocket.MsgHandle +{ + public class HandleHelper : IDataDockingSocket.IHandleHelper + { + + + + /// <summary> + /// 澶勭悊娉ㄥ唽鐮� + /// </summary> + public void HandleRegisterCode(IMonitorDataDockingSession session) + { + if (session == null) + return; + if (!session.IsConnected) + return; + + if (SessionHelper.Cache != null) + { + if (SessionHelper.Cache != session) + { + if (SessionHelper.Cache.IsConnected) + { + SessionHelper.Cache.Close($"{session.SessionName} 涓紝浜х敓鏂扮殑浼氳瘽锛�"); + } + } + } + + SessionHelper.Cache = session; + + + foreach (var item in MonitorMsgHelper.GetInstructionQuerys()) + { + SendInstructionJobHelper.StartJob(session, item); + if (item.SpaceTime >= 1) + Thread.Sleep(item.SpaceTime * 1000); + } + + SendControlJobHelper.StartJob(session); + } + + /// <summary> + /// 澶勭悊蹇冭烦鍖� + /// </summary> + public void HandleHeartbeat(IMonitorDataDockingSession session) + { + + } + + /// <summary> + /// 澶勭悊鏁版嵁 + /// </summary> + public void HandleData + ( + IMonitorDataDockingSession session, + byte[] byteMessage, + List<DataDockingConfigure.Mapper> mappers, + Action<List<MonitorDataDockingReceiveRecord>> onReceive + ) + { + if (session == null) + return; + if (!session.IsConnected) + return; + if (byteMessage == null || byteMessage.Length < 4) + { + return; + } + + if (MonitorMsgHelper.IsCurrentMsg(byteMessage)) + { + var receList = MonitorMsgHelper.HandleReceive(byteMessage); + if (receList == null || receList.Count == 0) + return; + + NtLogHelper.Src(byteMessage); + + // NtLogHelper.Debug(src_list); + //NtLogHelper.Info($"瑙f瀽鏁版嵁鏁伴噺:{receList.Count}\n\r" + + // $"{JsonHelper.Object2Json(receList)}"); + + + onReceive(receList); + + return;//鎴愬姛灏辫繑鍥炴帀 + } + //涓嶈鍔爀lse + if (ShunDownMsgHelper.InstructionStatus == eShutDownInstructionStatus.鍏虫満鏈烘寚浠ゅ彂閫�) + { + ShunDownMsgHelper.HandleReceive(session,byteMessage); + } + //涓嶈鍔爀lse + if (StartUpMsgHelper.IsCurrentMsg(byteMessage)) + { + + } + + } + + } + + +} diff --git a/Socket/IStation.DataDockingSocket4NT/MsgHandle/MonitorMsgHelper.cs b/Socket/IStation.DataDockingSocket4NT/MsgHandle/MonitorMsgHelper.cs new file mode 100644 index 0000000..4345d87 --- /dev/null +++ b/Socket/IStation.DataDockingSocket4NT/MsgHandle/MonitorMsgHelper.cs @@ -0,0 +1,367 @@ +锘縰sing System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using IStation.Untity; + +namespace IStation.DataDockingSocket.MsgHandle +{ + /// <summary> + /// 澶勭悊鏁版嵁杈呭姪绫� + /// </summary> + internal class MonitorMsgHelper + { + /// <summary> + /// 鏄惁鏄綋鍓峂SG + /// </summary> + /// <param name="byteMessage"></param> + /// <returns></returns> + public static bool IsCurrentMsg(byte[] byteMessage) + { + if (byteMessage[0] == 0x01 && byteMessage[1] == 0x03 && byteMessage[2] == 0x42) + { + return true; + } + else + { + return false; + } + } + + /// <summary> + /// + /// </summary> + /// <returns></returns> + internal static IEnumerable<QueryInstructionItem> GetInstructionQuerys() + { + var appParas = AppParasHelper.GetInstance(); + if (appParas == null) + { + NtLogHelper.Error("Socket 鏁版嵁瀵规帴涓紝NT 缂哄皯鏁版嵁瀵规帴閰嶇疆鏂囦欢"); + return null; + } + return appParas.InstructionQuerys; + } + + /// <summary> + /// 鑾峰彇鏌ヨ鎸囦护(鐩戞帶鍊�) + /// </summary> + /// <returns></returns> + public byte[] GetMonitorMsg鐩戞帶鍊�() + { + return new byte[] { 0x01, 0x03, 0x00, 0x19, 0x00, 0x21, 0x54, 0x15 }; + } + + + + /// <summary> + /// 鑾峰彇鏌ヨ鎸囦护(鐘舵�佸��):01-03-00-12-00-04-E4-0C + /// </summary> + /// <returns></returns> + public static byte[] GetMonitorMsg鐘舵�佸��() + { + return new byte[] { 0x01, 0x03, 0x00, 0x12, 0x00, 0x04, 0xE4, 0x0C }; + } + + + + + + /// <summary> + /// 璇诲彇娑堟伅(鐩戞帶鍊�) + /// </summary> + /// <param name="byteMessage"></param> + public static List<Model.MonitorDataDockingReceiveRecord> HandleReceive(byte[] byteMessage) + { + var list = new List<Model.MonitorDataDockingReceiveRecord>(); + byte start = 0x1A; + if (byteMessage == null) + { + NtLogHelper.Error($"鏁版嵁瑙f瀽澶辫触!鏁版嵁涓虹┖"); + return null; + } + if (byteMessage.Count() < 70) + { + var byteMsg = BitConverter.ToString(byteMessage); + NtLogHelper.Error($"鏁版嵁瑙f瀽澶辫触!{byteMsg},闀垮害涓嶅, 闀垮害涓簕byteMessage.Count()},姝e父闀垮害71"); + return null; + } + + try + { + //鏄剧ず娑堟伅 + //string strMessage = BitConverter.ToString(byteMessage, 0, byteMessage.Length); + //DisplayMessage(string.Format(" 鏀跺埌鐨勬秷鎭�: {0} ", strMessage)); + + + //DisplayMessage(string.Format(" 璁惧鍦板潃: {0} (0x{1})", byteMessage[0], Convert.ToString(byteMessage[0], 16))); + //DisplayMessage(string.Format(" 鍔熻兘鐮�: {0} ", byteMessage[1])); + + + string msg; + var now = DateTime.Now; + //褰撳墠绠$綉鍘嬪姏 + list.Add(new Model.MonitorDataDockingReceiveRecord() + { + SysId = 1575030496453332992, + RecordType = Model.eMonitorType.General, + SrcTime = now, + SrcValue = (ByteMsgHelper.GetInt2Byte(byteMessage, 3, out msg) * 0.001).ToString() + }); + + //鍙橀棰戠巼 + list.Add(new Model.MonitorDataDockingReceiveRecord() + { + SysId = 1575030605857558528, + RecordType = Model.eMonitorType.General, + SrcTime = now, + SrcValue = (ByteMsgHelper.GetInt2Byte(byteMessage, 3 + (27 - start) * 2, out msg) * 0.1).ToString() + }); + + //鍙橀鐢垫祦 + list.Add(new Model.MonitorDataDockingReceiveRecord() + { + SysId = 1582301190702632960, + RecordType = Model.eMonitorType.General, + SrcTime = now, + SrcValue = (ByteMsgHelper.GetInt2Byte(byteMessage, 3 + (28 - start) * 2, out msg) * 0.1).ToString() + }); + + //鐪熺┖褰撳墠鍘嬪姏 + list.Add(new Model.MonitorDataDockingReceiveRecord() + { + SysId = 1575030435430404096, + RecordType = Model.eMonitorType.General, + SrcTime = now, + SrcValue = (ByteMsgHelper.GetInt2Byte(byteMessage, 3 + (29 - start) * 2, out msg) * 0.001).ToString() + }); + + //A鐩哥數鍘� + list.Add(new Model.MonitorDataDockingReceiveRecord() + { + SysId = 1582301249292865536, + RecordType = Model.eMonitorType.General, + SrcTime = now, + SrcValue = Math.Round(ByteMsgHelper.GetDouble1(byteMessage, 3 + (30 - start) * 2, out msg), 2).ToString() + }); + + //B鐩哥數鍘� + list.Add(new Model.MonitorDataDockingReceiveRecord() + { + SysId = 1582301287175819264, + RecordType = Model.eMonitorType.General, + SrcTime = now, + SrcValue = Math.Round(ByteMsgHelper.GetDouble1(byteMessage, 3 + (32 - start) * 2, out msg), 2).ToString() + }); + + //C鐩哥數鍘� + list.Add(new Model.MonitorDataDockingReceiveRecord() + { + SysId = 1582301332780486656, + RecordType = Model.eMonitorType.General, + SrcTime = now, + SrcValue = Math.Round(ByteMsgHelper.GetDouble1(byteMessage, 3 + (34 - start) * 2, out msg), 2).ToString() + }); + + //A鐩哥數娴� + list.Add(new Model.MonitorDataDockingReceiveRecord() + { + SysId = 1582301384118767616, + RecordType = Model.eMonitorType.General, + SrcTime = now, + SrcValue = Math.Round(ByteMsgHelper.GetDouble1(byteMessage, 3 + (36 - start) * 2, out msg), 3).ToString() + }); + + //B鐩哥數娴� + list.Add(new Model.MonitorDataDockingReceiveRecord() + { + SysId = 1582301478792597504, + RecordType = Model.eMonitorType.General, + SrcTime = now, + SrcValue = Math.Round(ByteMsgHelper.GetDouble1(byteMessage, 3 + (38 - start) * 2, out msg), 3).ToString() + }); + + //C鐩哥數娴� + list.Add(new Model.MonitorDataDockingReceiveRecord() + { + SysId = 1582301691439616000, + RecordType = Model.eMonitorType.General, + SrcTime = now, + SrcValue = Math.Round(ByteMsgHelper.GetDouble1(byteMessage, 3 + (40 - start) * 2, out msg), 3).ToString() + }); + + //鍙橀娉电姸鎬� + list.Add(new Model.MonitorDataDockingReceiveRecord() + { + SysId = 1582303421711650816, + RecordType = Model.eMonitorType.General, + SrcTime = now, + SrcValue = ByteMsgHelper.GetInt2Byte(byteMessage, 3 + (42 - start) * 2, out msg).ToString() + }); + + //鐪熺┖娉电姸鎬� + list.Add(new Model.MonitorDataDockingReceiveRecord() + { + SysId = 1582303241251721216, + RecordType = Model.eMonitorType.General, + SrcTime = now, + SrcValue = ByteMsgHelper.GetInt2Byte(byteMessage, 3 + (43 - start) * 2, out msg).ToString() + }); + + ////鐢靛姩闃�寮�闃�鐘舵�� + //list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1582301332780486656, RecordType = Model.eMonitorType.General, SrcTime = now, + // SrcValue = string.Format("########鐢靛姩闃�寮�闃�鐘舵�� -----> {0} 鏁版嵁浜岃繘鍒秢1}", GetInt2Byte(byteMessage, 3 + (44 - start) * 2, out msg).ToString() }); + + ////鐢靛姩闃�鍏抽榾鐘舵�� + //list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1582301332780486656, RecordType = Model.eMonitorType.General, SrcTime = now, + // SrcValue = string.Format("########鐢靛姩闃�鍏抽榾鐘舵�� -----> {0} 鏁版嵁浜岃繘鍒秢1}", GetInt2Byte(byteMessage, 3 + (45 - start) * 2, out msg).ToString() }); + + //鐢电闃�鐘舵�� + list.Add(new Model.MonitorDataDockingReceiveRecord() + { + SysId = 1582303081771700224, + RecordType = Model.eMonitorType.General, + SrcTime = now, + SrcValue = ByteMsgHelper.GetInt2Byte(byteMessage, 3 + (46 - start) * 2, out msg).ToString() + }); + + //姘翠綅鐘舵�� + list.Add(new Model.MonitorDataDockingReceiveRecord() + { + SysId = 1582303471342850048, + RecordType = Model.eMonitorType.General, + SrcTime = now, + SrcValue = ByteMsgHelper.GetInt2Byte(byteMessage, 3 + (47 - start) * 2, out msg).ToString() + }); + + //瓒呭帇鐘舵�� + list.Add(new Model.MonitorDataDockingReceiveRecord() + { + SysId = 1582303606781120512, + RecordType = Model.eMonitorType.General, + SrcTime = now, + SrcValue = ByteMsgHelper.GetInt2Byte(byteMessage, 3 + (48 - start) * 2, out msg).ToString() + }); + + //鎶ヨ鐘舵�� + list.Add(new Model.MonitorDataDockingReceiveRecord() + { + SysId = 1582303637420511232, + RecordType = Model.eMonitorType.General, + SrcTime = now, + SrcValue = ByteMsgHelper.GetInt2Byte(byteMessage, 3 + (49 - start) * 2, out msg).ToString() + }); + + //鍙橀鍣ㄧ姸鎬� + list.Add(new Model.MonitorDataDockingReceiveRecord() + { + SysId = 1582303671927050240, + RecordType = Model.eMonitorType.General, + SrcTime = now, + SrcValue = ByteMsgHelper.GetInt2Byte(byteMessage, 3 + (50 - start) * 2, out msg).ToString() + }); + + //褰撳墠娑蹭綅 + list.Add(new Model.MonitorDataDockingReceiveRecord() + { + SysId = 1575388386963886080, + RecordType = Model.eMonitorType.General, + SrcTime = now, + SrcValue = (ByteMsgHelper.GetInt2Byte(byteMessage, 3 + (51 - start) * 2, out msg) * 0.01).ToString() + }); + + //鐬椂娴侀噺 + list.Add(new Model.MonitorDataDockingReceiveRecord() + { + SysId = 1575030320913321984, + RecordType = Model.eMonitorType.General, + SrcTime = now, + SrcValue = (ByteMsgHelper.GetInt4Byte(byteMessage, 3 + (52 - start) * 2, out msg) * 0.001).ToString() + }); + + //绱娴侀噺 + list.Add(new Model.MonitorDataDockingReceiveRecord() + { + SysId = 1584475350807744512, + RecordType = Model.eMonitorType.General, + SrcTime = now, + SrcValue = (ByteMsgHelper.GetInt4Byte(byteMessage, 3 + (54 - start) * 2, out msg) * 1.0).ToString() + }); + + //绱娴侀噺鏈夊姛鍔熺巼 + list.Add(new Model.MonitorDataDockingReceiveRecord() + { + SysId = 1584475756476633088, + RecordType = Model.eMonitorType.General, + SrcTime = now, + SrcValue = Math.Round(ByteMsgHelper.GetDouble1(byteMessage, 3 + (56 - start) * 2, out msg), 2).ToString() + }); + } + catch (Exception err) + { + var byteMsg = string.Join(',', byteMessage); + NtLogHelper.Error($"鏁版嵁瑙f瀽寮傚父!{byteMsg}" + + $"閿欒鎻愮ず:{err.Message}"); + } + + return list; + } + + /// <summary> + /// 璇诲彇娑堟伅(鐘舵�佸��) + /// </summary> + /// <param name="byteMessage"></param> + private static List<Model.MonitorDataDockingReceiveRecord> ReadMessage鐘舵�佸��(byte[] byteMessage) + { + var list = new List<Model.MonitorDataDockingReceiveRecord>(); + byte start = 0x12; + if (byteMessage == null || byteMessage.Length < 8) + { + return null; + } + try + { + //鏄剧ず娑堟伅 + //string strMessage = BitConverter.ToString(byteMessage, 0, byteMessage.Length); + //DisplayMessage(string.Format(" 鏀跺埌鐨勬秷鎭�: {0} ", strMessage)); + + + //DisplayMessage(string.Format(" 璁惧鍦板潃: {0} (0x{1})", byteMessage[0], Convert.ToString(byteMessage[0], 16))); + //DisplayMessage(string.Format(" 鍔熻兘鐮�: {0} ", byteMessage[1])); + + + string msg; + + var now = DateTime.Now; + //娑蹭綅閲忕▼ + //list.Add(new Model.MonitorDataDockingReceiveRecord() + //{ + // SysId = , + // RecordType = Model.eMonitorType.General, + // SrcTime = now, + // SrcValue = (GetInt2Byte(byteMessage, 3 + (19 - start), out msg )* 0.1).ToString() + //}); + //璁惧畾棰戠巼 + list.Add(new Model.MonitorDataDockingReceiveRecord() + { + SysId = 1584894751252025344, + RecordType = Model.eMonitorType.General, + SrcTime = now, + SrcValue = (ByteMsgHelper.GetInt2Byte(byteMessage, 3 + (20 - start), out msg) * 0.1).ToString() + }); + } + catch// (Exception err) + { + return null; + } + return list; + } + + + + } + +} diff --git a/Socket/IStation.DataDockingSocket4NT/MsgHandle/ShunDownMsgHelper.cs b/Socket/IStation.DataDockingSocket4NT/MsgHandle/ShunDownMsgHelper.cs new file mode 100644 index 0000000..252a09e --- /dev/null +++ b/Socket/IStation.DataDockingSocket4NT/MsgHandle/ShunDownMsgHelper.cs @@ -0,0 +1,109 @@ +锘縰sing IStation.DataDockingSocket.MsgHandle; +using IStation.Untity; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IStation.DataDockingSocket +{ + internal class ShunDownMsgHelper + { + public static eShutDownInstructionStatus InstructionStatus = eShutDownInstructionStatus.鏈彂閫�; + public static DateTime sendTime ; + /// <summary> + /// 寮�濮嬪叧鏈� + /// </summary> + /// <param name="session"></param> + /// <returns></returns> + public static bool StartJob(Model.IMonitorDataDockingSession session) + { + if (session != null) + { + NtLogHelper.Error($"鍏虫満 session:Close"); + return false; + } + + if (session.IsConnected) + { + byte[] bts = GetControlMsg(); + + session.Send(bts, 0, bts.Length); + InstructionStatus = eShutDownInstructionStatus.鍏虫満鏈烘寚浠ゅ彂閫�; + sendTime = DateTime.Now; + NtLogHelper.Debug("鍏虫満鎸囦护鍙戦��:" + session.SessionName + ":" + BitTransfer.ToString(bts) + ", 鍙戦�佷竴鏉¤姹傛帶鍒舵寚浠�"); + + return true; + } + else + { + NtLogHelper.Error($"鍏虫満鏃� session:Not connected"); + return false; + } + + } + + + /// <summary> + /// 鏄惁鏄帶鍒舵寚浠� + /// </summary> + /// <param name="byteMessage"></param> + /// <returns></returns> + public static bool IsControlMsg(byte[] byteMessage) + { + + + return false; + } + + /// <summary> + /// 鑾峰彇鎺у埗鎸囦护(寮�鏈�) + /// </summary> + /// <returns></returns> + public static byte[] GetControlMsg () + { + // var appParas = AppParasHelper.GetInstance(); + // if (appParas == null || appParas.InstructionStartUp == null || appParas.InstructionStartUp.Content == null) + { + return BitTransfer.FromString("01-06-00-10-00-01-49-CF"); + } + // return BitTransfer.FromString(appParas.InstructionStartUp.Content); + } + + /// <summary> + /// 璇诲彇杩斿洖娑堟伅 + /// </summary> + /// <param name="byteMessage"></param> + public static void HandleReceive(Model.IMonitorDataDockingSession session,byte[] byteMessage) + { + if (InstructionStatus == eShutDownInstructionStatus.鏈彂閫�) + return; + if (InstructionStatus == eShutDownInstructionStatus.鍏虫満鏈烘寚浠ゅ彂閫�) + { + if (byteMessage.Length == 8) + { + if (byteMessage[0] == 0x01 && byteMessage[1] == 0x06 && byteMessage[2] == 0x00 + && byteMessage[3] == 0x10 && byteMessage[4] == 0x00 && byteMessage[5] == 0x01 + && byteMessage[6] == 0x49 && byteMessage[7] == 0xCF) + {//01-06-00-0F-00-01-78-09 + InstructionStatus = eShutDownInstructionStatus.鏈彂閫�; + + NtLogHelper.Debug("鍏虫満鎸囦护杩斿洖:" + BitTransfer.ToString(byteMessage) ); + + return; + } + } + //杩斿洖澶辫触, 鍐嶅彂閫佷竴娆″啀纭涓�涓� + if((DateTime.Now- sendTime).TotalSeconds > 3) + { + StartJob(session); + } + + } + + + } + + } +} diff --git a/Socket/IStation.DataDockingSocket4NT/MsgHandle/StartUpMsgHelper.cs b/Socket/IStation.DataDockingSocket4NT/MsgHandle/StartUpMsgHelper.cs new file mode 100644 index 0000000..68b2fc7 --- /dev/null +++ b/Socket/IStation.DataDockingSocket4NT/MsgHandle/StartUpMsgHelper.cs @@ -0,0 +1,102 @@ +锘縰sing IStation.DataDockingSocket.MsgHandle; +using IStation.Untity; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IStation.DataDockingSocket +{ + internal class StartUpMsgHelper + { + public static eStartUpInstructionStatus ShutUpInstructionStatus = eStartUpInstructionStatus.鏈彂閫�; + + /// <summary> + /// 寮�鏈� + /// </summary> + /// <param name="session"></param> + /// <returns></returns> + public static bool StartJob(Model.IMonitorDataDockingSession session) + { + if (session != null) + { + NtLogHelper.Error($"寮�鏈� session:Close"); + return false; + } + + if (session.IsConnected) + { + byte[] bts = GetControlMsg寮�鏈�(); + + session.Send(bts, 0, bts.Length); + ShutUpInstructionStatus = eStartUpInstructionStatus.璋冮鎸囦护鍙戦��; + NtLogHelper.Info("寮�鏈�" + session.SessionName + ":" + BitTransfer.ToString(bts) + ", 鍙戦�佷竴鏉¤姹傛帶鍒舵寚浠�"); + + return true; + } + else + { + NtLogHelper.Error($"寮�鏈烘椂 session:Not connected"); + return false; + } + + } + + + /// <summary> + /// + /// </summary> + /// <param name="byteMessage"></param> + /// <returns></returns> + public static bool IsCurrentMsg(byte[] byteMessage) + { + if(byteMessage.Length == 8) + { + if (byteMessage[0] == 0x01 && byteMessage[1] == 0x06 && byteMessage[2] == 0x00 + && byteMessage[3] == 0x0F && byteMessage[4] == 0x00 && byteMessage[5] == 0x01 + && byteMessage[6] == 0x78 && byteMessage[7] == 0x09) + {//01-06-00-0F-00-01-78-09 + return true; + } + } + + return false; + } + + /// <summary> + /// 鑾峰彇鎺у埗鎸囦护(寮�鏈�) + /// </summary> + /// <returns></returns> + public static byte[] GetControlMsg寮�鏈�() + { + //var appParas = AppParasHelper.GetInstance(); + //if (appParas == null || appParas.InstructionStartUp == null || appParas.InstructionStartUp.Content == null) + { + return BitTransfer.FromString("01-06-00-0F-00-01-78-09"); + } + //return BitTransfer.FromString(appParas.InstructionStartUp.Content); + } + + /// <summary> + /// 鑾峰彇鎺у埗鎸囦护(璋冮) + /// </summary> + /// <returns></returns> + public static byte[] GetControlMsg璋冮(double frequece) + { + var iFrequece = (int)(frequece * 10); + + byte[] commandSend = null; + + ModBusRtuHelper.BuildSendMessage06(0x01, 20, 2, + iFrequece, ref commandSend); + + return commandSend; + } + + + + + + } +} diff --git a/Socket/IStation.DataDockingSocket4NT/control/SendControlJobHelper.cs b/Socket/IStation.DataDockingSocket4NT/control/SendControlJobHelper.cs index 931ab34..b68768a 100644 --- a/Socket/IStation.DataDockingSocket4NT/control/SendControlJobHelper.cs +++ b/Socket/IStation.DataDockingSocket4NT/control/SendControlJobHelper.cs @@ -1,4 +1,5 @@ -锘縰sing IStation.Untity; +锘縰sing IStation.DataDockingSocket.MsgHandle; +using IStation.Untity; using System; using System.Collections.Generic; using System.Linq; @@ -12,6 +13,9 @@ /// </summary> public class SendControlJobHelper { + /// <summary> + /// 浠嶮Q閲岄潰鑾峰彇鎺у埗鎸囦护 杈呭姪绫� + /// </summary> private static RabbitMqExChangeHelper _queueHelper = null; /// <summary> @@ -48,58 +52,21 @@ NtLogHelper.Info("鍗楅�氭帶鍒跺懡浠わ紝鏁版嵁搴忓垪鍖栧け璐�"); return true; } - byte[] bts = null; - switch (paras.ControlType) - { + + switch (paras.Type) + {//0浠h〃鍏虫満 1浠h〃寮�鏈� case 0: - bts = MsgDataHelper.GetControlMsg鍏虫満(); - NtLogHelper.Info("鍏虫満"); - break;//浠庤緟鍔╃被涓幏鍙� 鍏抽棴 - case 1: - bts = MsgDataHelper.GetControlMsg寮�鏈�(); - NtLogHelper.Info("寮�鏈�"); + ShunDownMsgHelper.StartJob(session); + break;//浠庤緟鍔╃被涓幏鍙� 鍏抽棴 + case 1: + if (string.IsNullOrEmpty(paras.Paras)) + return false; + StartUpMsgHelper.StartJob(session); break;//浠庤緟鍔╃被涓幏鍙� 寮�鍚� - case -1: - { - if (string.IsNullOrEmpty(paras.Context)) - { - NtLogHelper.Error($"[璋冮]鍙傛暟: null"); - return false; - } - if (!double.TryParse(paras.Context, out double value)) - { - NtLogHelper.Error($"[璋冮]鍙傛暟寮傚父:{paras.Context}"); - return false; - } - - bts = MsgDataHelper.GetControlMsg璋冮(value); - NtLogHelper.Info($"[璋冮]鍙傛暟:{paras.Context}"); - } - break;//浠庤緟鍔╃被涓幏鍙� 鍙橀 default: return false; } - if (bts != null) - { - if (session != null) - { - if (session.IsConnected) - { - session.Send(bts, 0, bts.Length); - NtLogHelper.Info(session.SessionName + ":" + BitTransfer.ToString(bts) + ", 鍙戦�佷竴鏉¤姹傛帶鍒舵寚浠�"); - } - else - { - NtLogHelper.Error($"session:Not connected"); - return false; - } - } - else - { - NtLogHelper.Error($"session:Close"); - return false; - } - } + return true; } catch (Exception ex) @@ -109,8 +76,10 @@ } }); }); - } + + + } } diff --git a/Socket/IStation.DataDockingSocket4NT/helper/MsgDataHelper.cs b/Socket/IStation.DataDockingSocket4NT/helper/MsgDataHelper.cs deleted file mode 100644 index 2334621..0000000 --- a/Socket/IStation.DataDockingSocket4NT/helper/MsgDataHelper.cs +++ /dev/null @@ -1,575 +0,0 @@ -锘縰sing System; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using IStation.Untity; - -namespace IStation.DataDockingSocket -{ - /// <summary> - /// 澶勭悊鏁版嵁杈呭姪绫� - /// </summary> - internal class MsgDataHelper - { - - /// <summary> - /// 鑾峰彇 - /// </summary> - /// <returns></returns> - public static AppParas GetAppParas() - { - if (_appparas == null) - { - var jsonFileName = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "paras_datadocking_socket_nt.json"); - var json = FileHelper.ReadAllText(jsonFileName); - _appparas = JsonHelper.Json2Object<AppParas>(json); - } - return _appparas; - } - private static AppParas _appparas = null; - /// <summary> - /// - /// </summary> - /// <returns></returns> - public static bool IsSrc() - { - return GetAppParas().Src; - } - /// <summary> - /// - /// </summary> - /// <returns></returns> - public static bool IsDebug() - { - return GetAppParas().Debug; - } - - /// <summary> - /// 澶勭悊鏁版嵁 - /// </summary> - public static List<Model.MonitorDataDockingReceiveRecord> HandleData - ( - byte[] byteMessage - ) - { - - if (byteMessage[0] == 0x01 && byteMessage[1] == 0x03 &&byteMessage[2] == 0x42) - { - return ReadMessage鐩戞帶鍊�(byteMessage); - } - //else if (byteMessage[2] == 0x46) - //{ - // return ReadMessage鐘舵�佸��(byteMessage); - //} - else - { - string byteMsg =""; - if(byteMessage != null) - byteMsg = BitConverter.ToString(byteMessage); - NtLogHelper.Error("闈炴甯告煡璇㈡暟鎹�, 鏁版嵁鍐呭:"+ byteMsg); - return null; - } - - } - - - /// <summary> - /// - /// </summary> - /// <returns></returns> - internal static IEnumerable<QueryInstructionItem> GetInstructionQuerys() - { - var appParas = GetAppParas(); - if (appParas == null) - { - NtLogHelper.Error("Socket 鏁版嵁瀵规帴涓紝NT 缂哄皯鏁版嵁瀵规帴閰嶇疆鏂囦欢"); - return null; - } - return appParas.InstructionQuerys; - } - - /// <summary> - /// 鑾峰彇鏌ヨ鎸囦护(鐩戞帶鍊�) - /// </summary> - /// <returns></returns> - public byte[] GetMonitorMsg鐩戞帶鍊�() - { - return new byte[] { 0x01, 0x03, 0x00, 0x19, 0x00, 0x21, 0x54, 0x15 }; - } - - - - /// <summary> - /// 鑾峰彇鏌ヨ鎸囦护(鐘舵�佸��):01-03-00-12-00-04-E4-0C - /// </summary> - /// <returns></returns> - public static byte[] GetMonitorMsg鐘舵�佸��() - { - return new byte[] { 0x01, 0x03, 0x00, 0x12, 0x00, 0x04, 0xE4, 0x0C }; - } - - /// <summary> - /// 鑾峰彇鎺у埗鎸囦护(寮�鏈�) - /// </summary> - /// <returns></returns> - public static byte[] GetControlMsg寮�鏈�() - { - var appParas = GetAppParas(); - if (appParas == null || appParas.InstructionStartUp == null || appParas.InstructionStartUp.Content == null) - { - return BitTransfer.FromString("01-06-00-0F-00-01-78-09"); - } - return BitTransfer.FromString(appParas.InstructionStartUp.Content); - } - - /// <summary> - /// 鑾峰彇鎺у埗鎸囦护(鍏虫満) - /// </summary> - /// <returns></returns> - public static byte[] GetControlMsg鍏虫満() - { - var appParas = GetAppParas(); - if (appParas == null || appParas.InstructionStartUp == null || appParas.InstructionStartUp.Content == null) - { - return BitTransfer.FromString("01-06-00-10-00-01-49-CF"); - } - return BitTransfer.FromString(appParas.InstructionShutDown.Content); - } - - - /// <summary> - /// 鑾峰彇鎺у埗鎸囦护(璋冮) - /// </summary> - /// <returns></returns> - public static byte[] GetControlMsg璋冮(double frequece) - { - var iFrequece = (int)(frequece * 10); - - byte[] commandSend = null; - - IStation.DataDockingSocket.ModBusRtuHelper.BuildSendMessage06(0x01, 20, 2, - iFrequece, ref commandSend); - - return commandSend; - } - - - - - - /// <summary> - /// 瀛楃涓茶浆16杩涘埗瀛楃2 - /// </summary> - /// <param name="content">瀛楃涓�</param> - /// <param name="encode">缂栫爜鏍煎紡</param> - /// <returns></returns> - private static List<byte> StringToHexValuve(string content, out string error_info) - { - //鍘绘帀绌烘牸 - string[] arr = content.Split(' '); - if (arr.Length < 3) - { - arr = content.Split('-'); - if (arr.Length < 3) - { - error_info = "瀛楃鏃犳硶瑙f瀽"; - return null; - } - } - List<byte> result = new List<byte>(); - for (int i = 0; i < arr.Length; i++) - { - if (string.IsNullOrWhiteSpace(arr[i])) - continue; - - var dddd = Convert.ToByte(arr[i], 16); - result.Add(dddd); - } - error_info = null; - return result; - } - - - - /// <summary> - /// 璇诲彇娑堟伅(鐩戞帶鍊�) - /// </summary> - /// <param name="byteMessage"></param> - private static List<Model.MonitorDataDockingReceiveRecord> ReadMessage鐩戞帶鍊�(byte[] byteMessage) - { - var list = new List<Model.MonitorDataDockingReceiveRecord>(); - byte start = 0x1A; - if (byteMessage == null ) - { - NtLogHelper.Error($"鏁版嵁瑙f瀽澶辫触!鏁版嵁涓虹┖"); - return null; - } - if (byteMessage.Count() < 70) - { - var byteMsg = BitConverter.ToString ( byteMessage); - NtLogHelper.Error($"鏁版嵁瑙f瀽澶辫触!{byteMsg},闀垮害涓嶅, 闀垮害涓簕byteMessage.Count()},姝e父闀垮害71"); - return null; - } - - try - { - //鏄剧ず娑堟伅 - //string strMessage = BitConverter.ToString(byteMessage, 0, byteMessage.Length); - //DisplayMessage(string.Format(" 鏀跺埌鐨勬秷鎭�: {0} ", strMessage)); - - - //DisplayMessage(string.Format(" 璁惧鍦板潃: {0} (0x{1})", byteMessage[0], Convert.ToString(byteMessage[0], 16))); - //DisplayMessage(string.Format(" 鍔熻兘鐮�: {0} ", byteMessage[1])); - - - string msg; - var now = DateTime.Now; - //褰撳墠绠$綉鍘嬪姏 - list.Add(new Model.MonitorDataDockingReceiveRecord() - { - SysId = 1575030496453332992, - RecordType = Model.eMonitorType.General, - SrcTime = now, - SrcValue = (GetInt2Byte(byteMessage, 3, out msg) * 0.001).ToString() - }); - - //鍙橀棰戠巼 - list.Add(new Model.MonitorDataDockingReceiveRecord() - { - SysId = 1575030605857558528, - RecordType = Model.eMonitorType.General, - SrcTime = now, - SrcValue = (GetInt2Byte(byteMessage, 3 + (27 - start) * 2, out msg) * 0.1).ToString() - }); - - //鍙橀鐢垫祦 - list.Add(new Model.MonitorDataDockingReceiveRecord() - { - SysId = 1582301190702632960, - RecordType = Model.eMonitorType.General, - SrcTime = now, - SrcValue = (GetInt2Byte(byteMessage, 3 + (28 - start) * 2, out msg) * 0.1).ToString() - }); - - //鐪熺┖褰撳墠鍘嬪姏 - list.Add(new Model.MonitorDataDockingReceiveRecord() - { - SysId = 1575030435430404096, - RecordType = Model.eMonitorType.General, - SrcTime = now, - SrcValue = (GetInt2Byte(byteMessage, 3 + (29 - start) * 2, out msg) * 0.001).ToString() - }); - - //A鐩哥數鍘� - list.Add(new Model.MonitorDataDockingReceiveRecord() - { - SysId = 1582301249292865536, - RecordType = Model.eMonitorType.General, - SrcTime = now, - SrcValue = Math.Round( GetDouble1(byteMessage, 3 + (30 - start) * 2, out msg),2).ToString() - }); - - //B鐩哥數鍘� - list.Add(new Model.MonitorDataDockingReceiveRecord() - { - SysId = 1582301287175819264, - RecordType = Model.eMonitorType.General, - SrcTime = now, - SrcValue = Math.Round(GetDouble1(byteMessage, 3 + (32 - start) * 2, out msg),2).ToString() - }); - - //C鐩哥數鍘� - list.Add(new Model.MonitorDataDockingReceiveRecord() - { - SysId = 1582301332780486656, - RecordType = Model.eMonitorType.General, - SrcTime = now, - SrcValue = Math.Round(GetDouble1(byteMessage, 3 + (34 - start) * 2, out msg),2).ToString() - }); - - //A鐩哥數娴� - list.Add(new Model.MonitorDataDockingReceiveRecord() - { - SysId = 1582301384118767616, - RecordType = Model.eMonitorType.General, - SrcTime = now, - SrcValue = Math.Round(GetDouble1(byteMessage, 3 + (36 - start) * 2, out msg),3).ToString() - }); - - //B鐩哥數娴� - list.Add(new Model.MonitorDataDockingReceiveRecord() - { - SysId = 1582301478792597504, - RecordType = Model.eMonitorType.General, - SrcTime = now, - SrcValue = Math.Round(GetDouble1(byteMessage, 3 + (38 - start) * 2, out msg),3).ToString() - }); - - //C鐩哥數娴� - list.Add(new Model.MonitorDataDockingReceiveRecord() - { - SysId = 1582301691439616000, - RecordType = Model.eMonitorType.General, - SrcTime = now, - SrcValue = Math.Round(GetDouble1(byteMessage, 3 + (40 - start) * 2, out msg),3).ToString() - }); - - //鍙橀娉电姸鎬� - list.Add(new Model.MonitorDataDockingReceiveRecord() - { - SysId = 1582303421711650816, - RecordType = Model.eMonitorType.General, - SrcTime = now, - SrcValue = GetInt2Byte(byteMessage, 3 + (42 - start) * 2, out msg).ToString() - }); - - //鐪熺┖娉电姸鎬� - list.Add(new Model.MonitorDataDockingReceiveRecord() - { - SysId = 1582303241251721216, - RecordType = Model.eMonitorType.General, - SrcTime = now, - SrcValue = GetInt2Byte(byteMessage, 3 + (43 - start) * 2, out msg).ToString() - }); - - ////鐢靛姩闃�寮�闃�鐘舵�� - //list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1582301332780486656, RecordType = Model.eMonitorType.General, SrcTime = now, - // SrcValue = string.Format("########鐢靛姩闃�寮�闃�鐘舵�� -----> {0} 鏁版嵁浜岃繘鍒秢1}", GetInt2Byte(byteMessage, 3 + (44 - start) * 2, out msg).ToString() }); - - ////鐢靛姩闃�鍏抽榾鐘舵�� - //list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1582301332780486656, RecordType = Model.eMonitorType.General, SrcTime = now, - // SrcValue = string.Format("########鐢靛姩闃�鍏抽榾鐘舵�� -----> {0} 鏁版嵁浜岃繘鍒秢1}", GetInt2Byte(byteMessage, 3 + (45 - start) * 2, out msg).ToString() }); - - //鐢电闃�鐘舵�� - list.Add(new Model.MonitorDataDockingReceiveRecord() - { - SysId = 1582303081771700224, - RecordType = Model.eMonitorType.General, - SrcTime = now, - SrcValue = GetInt2Byte(byteMessage, 3 + (46 - start) * 2, out msg).ToString() - }); - - //姘翠綅鐘舵�� - list.Add(new Model.MonitorDataDockingReceiveRecord() - { - SysId = 1582303471342850048, - RecordType = Model.eMonitorType.General, - SrcTime = now, - SrcValue = GetInt2Byte(byteMessage, 3 + (47 - start) * 2, out msg).ToString() - }); - - //瓒呭帇鐘舵�� - list.Add(new Model.MonitorDataDockingReceiveRecord() - { - SysId = 1582303606781120512, - RecordType = Model.eMonitorType.General, - SrcTime = now, - SrcValue = GetInt2Byte(byteMessage, 3 + (48 - start) * 2, out msg).ToString() - }); - - //鎶ヨ鐘舵�� - list.Add(new Model.MonitorDataDockingReceiveRecord() - { - SysId = 1582303637420511232, - RecordType = Model.eMonitorType.General, - SrcTime = now, - SrcValue = GetInt2Byte(byteMessage, 3 + (49 - start) * 2, out msg).ToString() - }); - - //鍙橀鍣ㄧ姸鎬� - list.Add(new Model.MonitorDataDockingReceiveRecord() - { - SysId = 1582303671927050240, - RecordType = Model.eMonitorType.General, - SrcTime = now, - SrcValue = GetInt2Byte(byteMessage, 3 + (50 - start) * 2, out msg).ToString() - }); - - //褰撳墠娑蹭綅 - list.Add(new Model.MonitorDataDockingReceiveRecord() - { - SysId = 1575388386963886080, - RecordType = Model.eMonitorType.General, - SrcTime = now, - SrcValue = (GetInt2Byte(byteMessage, 3 + (51 - start) * 2, out msg) * 0.01).ToString() - }); - - //鐬椂娴侀噺 - list.Add(new Model.MonitorDataDockingReceiveRecord() - { - SysId = 1575030320913321984, - RecordType = Model.eMonitorType.General, - SrcTime = now, - SrcValue = (GetInt4Byte(byteMessage, 3 + (52 - start) * 2, out msg) * 0.001).ToString() - }); - - //绱娴侀噺 - list.Add(new Model.MonitorDataDockingReceiveRecord() - { - SysId = 1584475350807744512, - RecordType = Model.eMonitorType.General, - SrcTime = now, - SrcValue = (GetInt4Byte(byteMessage, 3 + (54 - start) * 2, out msg) * 1.0).ToString() - }); - - //绱娴侀噺鏈夊姛鍔熺巼 - list.Add(new Model.MonitorDataDockingReceiveRecord() - { - SysId = 1584475756476633088, - RecordType = Model.eMonitorType.General, - SrcTime = now, - SrcValue = Math.Round(GetDouble1(byteMessage, 3 + (56 - start) * 2, out msg),2).ToString() - }); - } - catch (Exception err) - { - var byteMsg = string.Join(',', byteMessage); - NtLogHelper.Error($"鏁版嵁瑙f瀽寮傚父!{byteMsg}" + - $"閿欒鎻愮ず:{err.Message}"); - } - - return list; - } - - /// <summary> - /// 璇诲彇娑堟伅(鐘舵�佸��) - /// </summary> - /// <param name="byteMessage"></param> - private static List<Model.MonitorDataDockingReceiveRecord> ReadMessage鐘舵�佸��(byte[] byteMessage) - { - var list = new List<Model.MonitorDataDockingReceiveRecord>(); - byte start = 0x12; - if (byteMessage == null || byteMessage.Length < 8 ) - { - return null; - } - try - { - //鏄剧ず娑堟伅 - //string strMessage = BitConverter.ToString(byteMessage, 0, byteMessage.Length); - //DisplayMessage(string.Format(" 鏀跺埌鐨勬秷鎭�: {0} ", strMessage)); - - - //DisplayMessage(string.Format(" 璁惧鍦板潃: {0} (0x{1})", byteMessage[0], Convert.ToString(byteMessage[0], 16))); - //DisplayMessage(string.Format(" 鍔熻兘鐮�: {0} ", byteMessage[1])); - - - string msg; - - var now = DateTime.Now; - //娑蹭綅閲忕▼ - //list.Add(new Model.MonitorDataDockingReceiveRecord() - //{ - // SysId = , - // RecordType = Model.eMonitorType.General, - // SrcTime = now, - // SrcValue = (GetInt2Byte(byteMessage, 3 + (19 - start), out msg )* 0.1).ToString() - //}); - //璁惧畾棰戠巼 - list.Add(new Model.MonitorDataDockingReceiveRecord() - { - SysId = 1584894751252025344, - RecordType = Model.eMonitorType.General, - SrcTime = now, - SrcValue = (GetInt2Byte(byteMessage, 3 + (20 - start), out msg) * 0.1).ToString() - }); - } - catch// (Exception err) - { - return null; - } - return list; - } - - - #region 鏁版嵁杞寲 - private static int GetInt2Byte(byte[] byteMessage, int startPosition, out string info) - { - byte[] value = new byte[2]; - Array.Copy(byteMessage, startPosition, value, 0, 2); - - info = BitConverter.ToString(value, 0, value.Length); - // ushort rValueP = BitConverter.ToUInt16(value.Reverse().ToArray(), 0); - - //short rValueP = 0; - //rValueP = byteMessage[ startPosition]; - //rValueP <<= 8; - //rValueP += byteMessage[ startPosition + 1]; - //return rValueP; - return bytesToInt2(byteMessage, startPosition); - } - - private static int GetInt4Byte(byte[] byteMessage, int startPosition, out string info) - { - byte[] value = new byte[4]; - Array.Copy(byteMessage, startPosition, value, 0, 4); - - info = BitConverter.ToString(value, 0, value.Length); - // ushort rValueP = BitConverter.ToUInt16(value.Reverse().ToArray(), 0); - - //short rValueP = 0; - //rValueP = byteMessage[ startPosition]; - //rValueP <<= 8; - //rValueP += byteMessage[ startPosition + 1]; - //return rValueP; - return bytesToInt4(byteMessage, startPosition); - } - /** - * byte鏁扮粍涓彇int鏁板�硷紝鏈柟娉曢�傜敤浜�(浣庝綅鍦ㄥ墠锛岄珮浣嶅湪鍚�)鐨勯『搴忥紝鍜屽拰intToBytes锛堬級閰嶅浣跨敤 - * - * @param src - * byte鏁扮粍 - * @param offset - * 浠庢暟缁勭殑绗琽ffset浣嶅紑濮� - * @return int鏁板�� - */ - public static int bytesToInt2_LH(byte[] src, int offset) - { - int value; - value = (int)((src[offset] & 0xFF) - | ((src[offset + 1] & 0xFF) << 8)); - return value; - } - - /** - * byte鏁扮粍涓彇int鏁板�硷紝鏈柟娉曢�傜敤浜�(浣庝綅鍦ㄥ悗锛岄珮浣嶅湪鍓�)鐨勯『搴忋��2涓瓧鑺� - */ - public static int bytesToInt2(byte[] src, int offset) - { - int value; - value = (int)( - ((src[offset + 0] & 0xFF) << 8) - | (src[offset + 1] & 0xFF)); - return value; - } - /** - * byte鏁扮粍涓彇int鏁板�硷紝鏈柟娉曢�傜敤浜�(浣庝綅鍦ㄥ悗锛岄珮浣嶅湪鍓�)鐨勯『搴忋��4涓瓧鑺� - */ - public static int bytesToInt4(byte[] src, int offset = 0) - { - int value; - value = (int)(((src[offset] & 0xFF) << 24) - | ((src[offset + 1] & 0xFF) << 16) - | ((src[offset + 2] & 0xFF) << 8) - | (src[offset + 3] & 0xFF)); - return value; - } - - private static double GetDouble1(byte[] byteMessage, int startPosition, out string info) - { - byte[] value = new byte[4]; - Array.Copy(byteMessage, startPosition, value, 0, 4); - info = BitConverter.ToString(value, 0, value.Length); - - //return BitConverter.ToDouble(byteMessage, startPosition); - return BitConverter.ToSingle(value.Reverse().ToArray(), 0);//閲囩敤浜咺EEE-754浜岃繘鍒舵诞鐐规暟绠楁湳鏍囧噯 - } - - - #endregion - } - -} diff --git a/Socket/IStation.DataDockingSocket4NT/paras/AppParasHelper.cs b/Socket/IStation.DataDockingSocket4NT/paras/AppParasHelper.cs new file mode 100644 index 0000000..4e56c4f --- /dev/null +++ b/Socket/IStation.DataDockingSocket4NT/paras/AppParasHelper.cs @@ -0,0 +1,45 @@ +锘縰sing IStation.Untity; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IStation.DataDockingSocket +{ + internal class AppParasHelper + { + /// <summary> + /// 鑾峰彇 + /// </summary> + /// <returns></returns> + public static AppParas GetInstance() + { + if (_appparas == null) + { + var jsonFileName = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "paras_datadocking_socket_nt.json"); + var json = FileHelper.ReadAllText(jsonFileName); + _appparas = JsonHelper.Json2Object<AppParas>(json); + } + return _appparas; + } + private static AppParas _appparas = null; + + /// <summary> + /// + /// </summary> + /// <returns></returns> + public static bool IsSrc() + { + return GetInstance().Src; + } + /// <summary> + /// + /// </summary> + /// <returns></returns> + public static bool IsDebug() + { + return GetInstance().Debug; + } + } +} diff --git a/Socket/IStation.DataDockingSocket4NT/paras/eReceiveMsgType.cs b/Socket/IStation.DataDockingSocket4NT/paras/eReceiveMsgType.cs new file mode 100644 index 0000000..42cd36f --- /dev/null +++ b/Socket/IStation.DataDockingSocket4NT/paras/eReceiveMsgType.cs @@ -0,0 +1,17 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IStation.DataDockingSocket +{ + public enum eReceiveMsgType + { + 鐩戞帶鎸囦护杩斿洖 = 0, + 寮�鏈烘寚浠よ繑鍥� = 1, + 鍏虫満鎸囦护杩斿洖 = 2, + 璋冮鎸囦护杩斿洖 = 3, + 鏈煡 = -1 + } +} diff --git a/Socket/IStation.DataDockingSocket4NT/paras/eShutDownInstructionStatus.cs b/Socket/IStation.DataDockingSocket4NT/paras/eShutDownInstructionStatus.cs new file mode 100644 index 0000000..11d9caa --- /dev/null +++ b/Socket/IStation.DataDockingSocket4NT/paras/eShutDownInstructionStatus.cs @@ -0,0 +1,15 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IStation.DataDockingSocket +{ + public enum eShutDownInstructionStatus + { + 鏈彂閫� = 0, + 鍏虫満鏈烘寚浠ゅ彂閫� = 3, + //鍏虫満鎸囦护杩斿洖 = 4 + } +} diff --git a/Socket/IStation.DataDockingSocket4NT/paras/eStartUpInstructionStatus.cs b/Socket/IStation.DataDockingSocket4NT/paras/eStartUpInstructionStatus.cs new file mode 100644 index 0000000..30656dc --- /dev/null +++ b/Socket/IStation.DataDockingSocket4NT/paras/eStartUpInstructionStatus.cs @@ -0,0 +1,17 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IStation.DataDockingSocket +{ + public enum eStartUpInstructionStatus + { + 鏈彂閫� = 0, + 璋冮鎸囦护鍙戦�� = 1, + 璋冮鎸囦护杩斿洖 = 2, + 寮�鏈烘寚浠ゅ彂閫� = 3, + 寮�鏈烘寚浠よ繑鍥� = 4 + } +} -- Gitblit v1.9.3