From 0bdc0a135dbe31761b53f432ed34f347f0a4e36b Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期四, 05 三月 2020 10:49:41 +0800
Subject: [PATCH] 20200304
---
HDL_ON/DAL/Net/CommonPage.cs | 133 ++++++++++++++++++++++++++------------------
1 files changed, 78 insertions(+), 55 deletions(-)
diff --git a/HDL_ON/DAL/Net/CommonPage.cs b/HDL_ON/DAL/Net/CommonPage.cs
index d248b8a..582cbf2 100644
--- a/HDL_ON/DAL/Net/CommonPage.cs
+++ b/HDL_ON/DAL/Net/CommonPage.cs
@@ -1,7 +1,8 @@
锘縰sing System;
using System.Text;
using HDL_ON.DAL.Net;
-using HDL_ON.Entity.Enumerative;
+using HDL_ON.Entity;
+using HDL_ON.UI;
using Shared;
using Shared.Net;
@@ -11,30 +12,20 @@
{
public static bool IsRemote;
- //public static AirQuality AirQuality;
public static Action RefreshAir;
- public static bool FindGateway = false;
- public static bool FindGatewayChilren = false;
public static string FindGatewayChilrenIPAddress = new NetWiFi ().BroadcastIpAddress.ToString ();
- public static bool LocalPhoneFindDevice = false;
private static string ip = "0.0.0.0";
public static System.Net.IPEndPoint EndPoint {
- get {
- try {
- if (FindGateway) {
- return new System.Net.IPEndPoint (System.Net.IPAddress.Parse (new NetWiFi ().BroadcastIpAddress.ToString ()), 6000);
- } else if (FindGatewayChilren) {
- try {
- return new System.Net.IPEndPoint (System.Net.IPAddress.Parse (FindGatewayChilrenIPAddress), 6000);
- } catch {
- return new System.Net.IPEndPoint (System.Net.IPAddress.Parse ("224.0.168.188"), 6000);
- }
- } else {
- return new System.Net.IPEndPoint (System.Net.IPAddress.Parse (new NetWiFi ().BroadcastIpAddress.ToString ()), 6000);
- }
- } catch {
+ get
+ {
+ try
+ {
+ return new System.Net.IPEndPoint(System.Net.IPAddress.Parse(new NetWiFi().BroadcastIpAddress.ToString()), 6000);
+ }
+ catch
+ {
//闃叉寮傚父瀵艰嚧绋嬪簭閫�鍑�
- return new System.Net.IPEndPoint (System.Net.IPAddress.Parse ("127.0.0.1"), 6000);
+ return new System.Net.IPEndPoint(System.Net.IPAddress.Parse("127.0.0.1"), 6000);
}
}
}
@@ -42,16 +33,23 @@
///淇濆瓨璁惧澶囨敞鎵嶇敤gb2312锛屽叾浠栨儏鍐电敤utf8
public static Encoding MyEncodingUTF8 = Encoding.UTF8;//Get
public static Encoding MyEncodingGB2312 {
- get {
- try {
- if (System.Globalization.CultureInfo.InstalledUICulture.EnglishName.ToUpper().StartsWith("CZECH")) {
- return System.Text.Encoding.GetEncoding (1250);
- } else {
- return Encoding.GetEncoding ("gb2312");
+ get
+ {
+ try
+ {
+ if (System.Globalization.CultureInfo.InstalledUICulture.EnglishName.ToUpper().StartsWith("CZECH"))
+ {
+ return Encoding.GetEncoding(1250);
}
- }catch (Exception ex) {
- MainPage.Log ("MyEncodingGB2312 Erorr : "+ex.Message);
- return Encoding.GetEncoding ("gb2312");
+ else
+ {
+ return Encoding.GetEncoding("gb2312");
+ }
+ }
+ catch (Exception ex)
+ {
+ MainPage.Log("MyEncodingGB2312 Erorr : " + ex.Message);
+ return Encoding.GetEncoding("gb2312");
}
}
}
@@ -88,15 +86,60 @@
public static float floatChange (byte b1, byte b2, byte b3, byte b4)
{
- byte [] byteTemp = new byte [4] { b4, b3, b2, b1 };
+ byte[] byteTemp = { b4, b3, b2, b1 };
return BitConverter.ToSingle (byteTemp, 0);
}
- static void Packet_ReceiveEvent (byte subnetID, byte deviceID, Command command, byte [] usefullBytes, string revGatewayIP)
+ static void Packet_ReceiveEvent(byte subnetID, byte deviceID, Command command, byte[] receiveBytes, string revGatewayIP)
{
-
-
+ try
+ {
+ switch (command)
+ {
+ case Command.ReadLightSingleLoopBrightnessACK:
+ case Command.SetSingleLightACK:
+ foreach (var function in DB_ResidenceData.residenceData.functions.lights)
+ {
+ if (function.GetBusId() == subnetID + "_" + deviceID + "_" + receiveBytes[0])
+ {
+ if (function.functionCategory == FunctionType.Light)
+ {
+ var light = function as Light;
+ if (receiveBytes[2] == 0 && light.state == 0)
+ {
+ break;
+ }
+ if (receiveBytes[2] == 100 && light.state == 1)
+ {
+ break;
+ }
+ if (function.functionType == "Relay")
+ {
+ var relay = function as Light;
+ relay.state = receiveBytes[2] == 0 ? 0 : 1;
+ HomePage.UpdataLightView(relay);
+ //RoomPage.
+ }
+ else if (function.functionType == "brightness")
+ {
+ var dimmer = function as Light;
+ dimmer.state = receiveBytes[2] == 0 ? 0 : 1;
+ dimmer.dicPropert["brightness"] = receiveBytes[1];
+ //dimmer.brightness = receiveBytes[1];
+ if (receiveBytes[2] > 0)
+ dimmer.lastState = Language.StringByID(StringId.Brightness) + " : " + receiveBytes[2] + "%";
+ HomePage.UpdataLightView(dimmer);
+ }
+ }
+ }
+ }
+ break;
+ }
+ }
+ catch (Exception ex) {
+ MainPage.Log($"Bus Rev Erorr : {ex.Message}");
+ }
}
/// <summary>
/// byte 鍙樺瓧绗︿覆
@@ -118,12 +161,12 @@
if (nameValueCollection ["Command"] != null && nameValueCollection ["Command"].StartsWith ("Get")) {
string tempFileName = nameValueCollection ["Command"].Replace ("Get", "");
if ("AllFiles" == tempFileName) {
- byte [] bytes = System.Text.Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (MyIO.FileUtils.ReadFiles ()));
+ byte [] bytes = System.Text.Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (FileUtils.ReadFiles ()));
outputStream.Write (bytes, 0, bytes.Length);
outputStream.Flush ();
} else {
byte [] bytes;
- if (!MyIO.FileUtils.Exists (tempFileName)) {
+ if (!FileUtils.Exists (tempFileName)) {
bytes = System.Text.Encoding.UTF8.GetBytes ("鏂囦欢鍚嶄笉瀛樺湪锛�");
outputStream.Write (bytes, 0, bytes.Length);
outputStream.Flush ();
@@ -147,26 +190,6 @@
} catch (Exception ex) {
MainPage.Log ("httpListener_EventHandler" + ex.ToString ());
}
- }
-
- /// <summary>
- /// 闅忔満鏁伴珮浣�
- /// </summary>
- public static byte RandomHigh;
- /// <summary>
- /// 闅忔満鏁颁綆浣�
- /// </summary>
- public static byte RandomLow;
-
- /// <summary>
- /// Updates Device's remake.
- /// </summary>
- public static void UpdateRemark (byte subnetID, byte deviceID, string remark)
- {
- byte [] updateBytes = new byte [20];
- byte [] remakeBytes = MyEncodingGB2312.GetBytes (remark);
- Array.Copy (remakeBytes, 0, updateBytes, 0, remakeBytes.Length < 20 ? remakeBytes.Length : 20);
- Control.ControlBytesSend (Command.UpdataRemake, subnetID, deviceID, updateBytes);
}
/// <summary>
--
Gitblit v1.8.0