| | |
| | | public static Action RefreshAir; |
| | | public static string FindGatewayChilrenIPAddress = new NetWiFi ().BroadcastIpAddress.ToString (); |
| | | private static string ip = "0.0.0.0"; |
| | | public static System.Net.IPEndPoint EndPoint { |
| | | public static System.Net.IPEndPoint EndPoint |
| | | { |
| | | get |
| | | { |
| | | try |
| | |
| | | |
| | | ///保存设备备注才用gb2312,其他情况用utf8 |
| | | public static Encoding MyEncodingUTF8 = Encoding.UTF8;//Get |
| | | public static Encoding MyEncodingGB2312 { |
| | | public static Encoding MyEncodingGB2312 |
| | | { |
| | | get |
| | | { |
| | | try |
| | |
| | | //public static byte currentSubnetID = 0; |
| | | public static void InitHttpListener () |
| | | { |
| | | if (isHttpListenerStart) { |
| | | if (isHttpListenerStart) |
| | | { |
| | | return; |
| | | } |
| | | HttpListener.Start (new NetWiFi ().IpAddress, 6001); |
| | |
| | | { |
| | | case Command.ReadLightSingleLoopBrightnessACK: |
| | | case Command.SetSingleLightACK: |
| | | foreach (var function in DB_ResidenceData.residenceData.functions.lights) |
| | | foreach (var function in DB_ResidenceData.residenceData.functionList.lights) |
| | | { |
| | | if (function.GetBusId() == subnetID + "_" + deviceID + "_" + receiveBytes[0]) |
| | | { |
| | |
| | | var relay = function as Light; |
| | | relay.state = receiveBytes[2] == 0 ? 0 : 1; |
| | | HomePage.UpdataLightView(relay); |
| | | //RoomPage. |
| | | } |
| | | else if (function.functionType == "brightness") |
| | | { |
| | |
| | | break; |
| | | } |
| | | } |
| | | catch (Exception ex) { |
| | | catch (Exception ex) |
| | | { |
| | | MainPage.Log($"Bus Rev Erorr : {ex.Message}"); |
| | | } |
| | | } |
| | |
| | | public static string byteToHex16 (byte b) |
| | | { |
| | | string s = Convert.ToString (b, 16).ToUpper (); |
| | | if (s.Length <= 1) { |
| | | if (s.Length <= 1) |
| | | { |
| | | return "0" + s; |
| | | } |
| | | return s;// |
| | |
| | | |
| | | static void httpListener_EventHandler (System.Collections.Specialized.NameValueCollection nameValueCollection, System.IO.Stream outputStream, System.IO.Stream inputStream) |
| | | { |
| | | try { |
| | | if (nameValueCollection ["Command"] != null && nameValueCollection ["Command"].StartsWith ("Get")) { |
| | | try |
| | | { |
| | | if (nameValueCollection["Command"] != null && nameValueCollection["Command"].StartsWith("Get")) |
| | | { |
| | | string tempFileName = nameValueCollection ["Command"].Replace ("Get", ""); |
| | | if ("AllFiles" == tempFileName) { |
| | | if ("AllFiles" == tempFileName) |
| | | { |
| | | byte [] bytes = System.Text.Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (FileUtils.ReadFiles ())); |
| | | outputStream.Write (bytes, 0, bytes.Length); |
| | | outputStream.Flush (); |
| | | } else { |
| | | } |
| | | else |
| | | { |
| | | byte [] bytes; |
| | | if (!FileUtils.Exists (tempFileName)) { |
| | | if (!FileUtils.Exists(tempFileName)) |
| | | { |
| | | bytes = System.Text.Encoding.UTF8.GetBytes ("文件名不存在!"); |
| | | outputStream.Write (bytes, 0, bytes.Length); |
| | | outputStream.Flush (); |
| | |
| | | outputStream.Write (bytes, 0, bytes.Length); |
| | | outputStream.Flush (); |
| | | } |
| | | } else if (nameValueCollection ["Command"].StartsWith ("Upload")) { |
| | | } |
| | | else if (nameValueCollection["Command"].StartsWith("Upload")) |
| | | { |
| | | string path = Application.RootPath + nameValueCollection ["Command"].Replace ("Upload", ""); |
| | | string dePath = nameValueCollection ["Command"].Replace ("Upload", ""); |
| | | } else { |
| | | } |
| | | else |
| | | { |
| | | byte [] bytes = System.Text.Encoding.UTF8.GetBytes ("请求命令无效!"); |
| | | outputStream.Write (bytes, 0, bytes.Length); |
| | | outputStream.Flush (); |
| | | } |
| | | } catch (Exception ex) { |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MainPage.Log ("httpListener_EventHandler" + ex.ToString ()); |
| | | } |
| | | } |
| | |
| | | public static int Port = 5555; |
| | | static void httpListener_EventHandler (string rawUrl, System.IO.Stream outputStream, System.IO.Stream inputStream) |
| | | { |
| | | foreach (var musicInfo in MusicInfo.MusicInfoList) { |
| | | if ("audio-item-" + musicInfo.ID == rawUrl.TrimStart ('/')) { |
| | | foreach (var musicInfo in MusicInfo.MusicInfoList) |
| | | { |
| | | if ("audio-item-" + musicInfo.ID == rawUrl.TrimStart('/')) |
| | | { |
| | | var file = new System.IO.FileStream (musicInfo.Data, System.IO.FileMode.Open, System.IO.FileAccess.Read); |
| | | byte [] bytes = new byte [1024]; |
| | | try { |
| | | while (file.CanRead) { |
| | | try |
| | | { |
| | | while (file.CanRead) |
| | | { |
| | | int len = file.Read (bytes, 0, bytes.Length); |
| | | if (len == 0) { |
| | | if (len == 0) |
| | | { |
| | | break; |
| | | } |
| | | outputStream.Write (bytes, 0, len); |
| | | } |
| | | } catch { } |
| | | } |
| | | catch { } |
| | | file.Close (); |
| | | break; |
| | | } |