| | |
| | | using HDL_ON.DAL.Net; |
| | | using HDL_ON.Entity; |
| | | using HDL_ON.UI; |
| | | using Newtonsoft.Json; |
| | | using Newtonsoft.Json.Linq; |
| | | using Shared; |
| | | using Shared.Net; |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | public static System.Net.IPEndPoint GetGatewayIP_EndPoint |
| | | { |
| | | get |
| | | { |
| | | //防止异常导致程序退出 |
| | | return new System.Net.IPEndPoint(System.Net.IPAddress.Parse("224.0.168.188"), 6688); |
| | | } |
| | | } |
| | | |
| | | ///保存设备备注才用gb2312,其他情况用utf8 |
| | | public static Encoding MyEncodingUTF8 = Encoding.UTF8;//Get |
| | | public static Encoding MyEncodingGB2312 |
| | |
| | | } |
| | | } |
| | | } |
| | | static bool isHttpListenerStart; |
| | | public static bool isHttpListenerStart; |
| | | public static DateTime dt; |
| | | |
| | | //public static byte currentSubnetID = 0; |
| | |
| | | { |
| | | return; |
| | | } |
| | | Console.WriteLine("Init Http Listener !"); |
| | | HttpListener.Start(new NetWiFi().IpAddress, 6002); |
| | | HttpListener.EventHandler -= httpListener_EventHandler; |
| | | HttpListener.EventHandler += httpListener_EventHandler; |
| | |
| | | { |
| | | try |
| | | { |
| | | if(revGatewayIP == "172.16.2.237") |
| | | { |
| | | |
| | | } |
| | | |
| | | switch (command) |
| | | { |
| | | case Command.ReadLightSingleLoopBrightnessACK: |
| | |
| | | } |
| | | } |
| | | break; |
| | | case Command.ReadDeviceLoopInfoACK: |
| | | FunctionType dt = (FunctionType)(11 * 256 + receiveBytes[1]); |
| | | string tag = receiveBytes[1] + "_" + subnetID + "_" + deviceID + "_" + receiveBytes[2]; |
| | | |
| | | foreach (var sensor in DB_ResidenceData.residenceData.functionList.sensorsEnvironmentalScience) |
| | | { |
| | | if (sensor.bus_Data != null) |
| | | { |
| | | if ((int)sensor.functionType % 256 == receiveBytes[1] && sensor.bus_Data.SubnetID == subnetID && |
| | | sensor.bus_Data.DeviceID == deviceID && sensor.bus_Data.LoopID == receiveBytes[2]) |
| | | { |
| | | switch (dt) |
| | | { |
| | | case FunctionType.Temp: |
| | | byte[] tempBytes = new byte[] { receiveBytes[24], receiveBytes[25], receiveBytes[26], receiveBytes[27] }; |
| | | sensor.values = Math.Round(BitConverter.ToSingle(tempBytes, 0), 1); |
| | | break; |
| | | case FunctionType.Humidity: |
| | | sensor.values = Convert.ToDouble(receiveBytes[24] * 256 + receiveBytes[25]) / 10; |
| | | break; |
| | | case FunctionType.TVOC: |
| | | sensor.values = Convert.ToDouble(receiveBytes[24] * 256 + receiveBytes[25]) / 100; |
| | | break; |
| | | case FunctionType.PM25: |
| | | sensor.values = Convert.ToInt32(receiveBytes[24] * 256 + receiveBytes[25]); |
| | | break; |
| | | case FunctionType.CO2: |
| | | sensor.values = Convert.ToInt32(receiveBytes[24] * 256 + receiveBytes[25]); |
| | | break; |
| | | } |
| | | EnvironmentalSciencePage.LoadEvent_UpdataStatus(sensor); |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | case Command.New_Analog_Quantity_BROADCAST: |
| | | string tag1 = receiveBytes[1] + "_" + subnetID + "_" + deviceID + "_" + receiveBytes[2]; |
| | | foreach (var sensor in DB_ResidenceData.residenceData.functionList.sensorsEnvironmentalScience) |
| | | { |
| | | if (sensor.bus_Data != null) |
| | | { |
| | | if ((int)sensor.functionType % 256 == receiveBytes[1] && sensor.bus_Data.SubnetID == subnetID && |
| | | sensor.bus_Data.DeviceID == deviceID && sensor.bus_Data.LoopID == receiveBytes[2]) |
| | | { |
| | | //0保留 1无符号4Byte整形 2有符号4Byte整形 3Float形(代±) |
| | | switch (receiveBytes[3]) |
| | | { |
| | | case 1: |
| | | sensor.values = (receiveBytes[5]*256 * 256 * 256)+ (receiveBytes[6] * 256 * 256)+ (receiveBytes[7] * 256)+ receiveBytes[8]; |
| | | break; |
| | | case 2: |
| | | sensor.values = -1 * ((receiveBytes[5] * 256 * 256 * 256) + (receiveBytes[6] * 256 * 256) + (receiveBytes[7] * 256) + receiveBytes[8]); |
| | | break; |
| | | case 3: |
| | | byte[] tempBytes = new byte[] { receiveBytes[5], receiveBytes[6], receiveBytes[7], receiveBytes[8] }; |
| | | sensor.values = Math.Round(BitConverter.ToSingle(tempBytes, 0), 1); |
| | | break; |
| | | } |
| | | EnvironmentalSciencePage.LoadEvent_UpdataStatus(sensor); |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | |
| | | string tempFileName = nameValueCollection["Command"].Replace("Get", ""); |
| | | if ("AllFiles" == tempFileName) |
| | | { |
| | | byte[] bytes = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(FileUtils.ReadFiles())); |
| | | byte[] bytes = Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(FileUtils.ReadFiles())); |
| | | outputStream.Write(bytes, 0, bytes.Length); |
| | | outputStream.Flush(); |
| | | } |
| | |
| | | byte[] bytes; |
| | | if (!FileUtils.Exists(tempFileName)) |
| | | { |
| | | bytes = System.Text.Encoding.UTF8.GetBytes("文件名不存在!"); |
| | | bytes = Encoding.UTF8.GetBytes("文件名不存在!"); |
| | | outputStream.Write(bytes, 0, bytes.Length); |
| | | outputStream.Flush(); |
| | | return; |
| | |
| | | { |
| | | string path = Application.RootPath + nameValueCollection["Command"].Replace("Upload", ""); |
| | | string dePath = nameValueCollection["Command"].Replace("Upload", ""); |
| | | FileUtils.WriteFileByInputStream(path, inputStream); |
| | | var reString = CommonPage.MyEncodingUTF8.GetString(FileUtils.ReadFile(path)); |
| | | var common = JsonConvert.DeserializeObject<AProtocolEntity>(reString); |
| | | //Console.WriteLine(common.ToString()); |
| | | if(dePath == "FunctionList") |
| | | { |
| | | foreach(var obj in common.objects) |
| | | { |
| | | DB_ResidenceData.residenceData.functionList.AddFunction(obj); |
| | | } |
| | | DB_ResidenceData.residenceData.functionList.GetAllFunction(); |
| | | } |
| | | } |
| | | else |
| | | { |