| | |
| | | |
| | | public class LogicMethod |
| | | { |
| | | |
| | | /// <summary> |
| | | /// 定义一个静态对象 |
| | | /// </summary> |
| | | private static LogicMethod logicMethod = null; |
| | | |
| | | /// <summary> |
| | | /// 获取静态对象 |
| | | /// </summary> |
| | | public static LogicMethod CurrLogicMethod |
| | | { |
| | | get |
| | |
| | | /// 获取安防列表 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public List<HDL_ON.Entity.SecurityAlarm> GetSecurityList() |
| | | public List<HDL_ON.Entity.SecurityAlarm> GetSecurityList() |
| | | { |
| | | return FunctionList.List.securities; |
| | | } |
| | |
| | | string strPath = ""; |
| | | switch (functionType) |
| | | { |
| | | |
| | | case SPK.AirSwitch: |
| | | { |
| | | strPath = "FunctionIcon/Icon/electricalbreaker.png"; |
| | | } |
| | | break; |
| | | case SPK.PanelSocket: |
| | | case SPK.ElectricSocket: |
| | | { |
| | | strPath = "FunctionIcon/Icon/electricalsocket.png"; |
| | | } |
| | | break; |
| | | case SPK.LightSwitch: |
| | | case SPK.LightRGB: |
| | | case SPK.LightRGBW: |
| | |
| | | strPath = "LogicIcon/airconditionerlogic.png"; |
| | | } |
| | | break; |
| | | case SPK.FloorHeatStandard:case SPK.HvacFloorHeat: |
| | | case SPK.FloorHeatStandard: |
| | | case SPK.HvacFloorHeat: |
| | | { |
| | | strPath = "LogicIcon/heatlogic.png"; |
| | | } |
| | |
| | | { |
| | | List<string> deviceStrTypeList = new List<string>(); |
| | | deviceStrTypeList.Clear(); |
| | | ///灯光类 |
| | | var lightjosn = deviceList.Find((device) => |
| | | device.spk == SPK.LightSwitch |
| | | || device.spk == SPK.LightDimming |
| | | || device.spk == SPK.LightCCT |
| | | || device.spk == SPK.LightRGB |
| | | || device.spk == SPK.LightRGBW); |
| | | || device.spk == SPK.LightRGBW |
| | | ); |
| | | if (lightjosn != null) |
| | | { |
| | | deviceStrTypeList.Add(Language.StringByID(StringId.Lights)); |
| | | } |
| | | |
| | | ///窗帘类 |
| | | var curtainjosn = deviceList.Find((device) => |
| | | device.spk == SPK.CurtainSwitch |
| | | || device.spk == SPK.CurtainTrietex |
| | |
| | | { |
| | | deviceStrTypeList.Add(Language.StringByID(StringId.Curtain)); |
| | | } |
| | | |
| | | ///空调类 |
| | | var ac = deviceList.Find((device) => device.spk == SPK.AcStandard || device.spk == SPK.HvacAC); |
| | | if (ac != null) |
| | | { |
| | | deviceStrTypeList.Add(Language.StringByID(StringId.AC)); |
| | | } |
| | | ///地暖类 |
| | | var floorHeating = deviceList.Find((device) => device.spk == SPK.FloorHeatStandard || device.spk == SPK.HvacFloorHeat); |
| | | if (floorHeating != null) |
| | | { |
| | | deviceStrTypeList.Add(Language.StringByID(StringId.FloorHeating)); |
| | | } |
| | | ///新风类 |
| | | var airFresh = deviceList.Find((device) => device.spk == SPK.AirFreshStandard || device.spk == SPK.HvacAirFresh); |
| | | if (airFresh != null) |
| | | { |
| | | deviceStrTypeList.Add(Language.StringByID(StringId.AirFresh)); |
| | | } |
| | | ///传感器类 |
| | | var sensor = deviceList.Find((device) => |
| | | device.spk == SPK.SensorWater |
| | | || device.spk == SPK.SensorGas |
| | |
| | | { |
| | | deviceStrTypeList.Add(Language.StringByID(StringId.Sensor)); |
| | | } |
| | | ///家电类 |
| | | var electric = deviceList.Find((device) => |
| | | device.spk == SPK.AirSwitch |
| | | || device.spk == SPK.PanelSocket |
| | | || device.spk == SPK.ElectricSocket |
| | | ); |
| | | if (electric != null) |
| | | { |
| | | deviceStrTypeList.Add(Language.StringByID(StringId.Electric)); |
| | | } |
| | | return deviceStrTypeList; |
| | | |
| | | } |
| | |
| | | public List<string> GetDeviceTypeFunctionList(string deviceType) |
| | | { |
| | | List<string> functionTypeList = new List<string>(); |
| | | ///灯光类 |
| | | if (deviceType == Language.StringByID(StringId.Lights)) |
| | | { |
| | | functionTypeList.Add(SPK.LightSwitch); |
| | |
| | | functionTypeList.Add(SPK.LightRGB); |
| | | functionTypeList.Add(SPK.LightRGBW); |
| | | functionTypeList.Add(SPK.LightCCT); |
| | | functionTypeList.Add(SPK.AirSwitch); |
| | | functionTypeList.Add(SPK.PanelSocket); |
| | | functionTypeList.Add(SPK.ElectricSocket); |
| | | } |
| | | ///窗帘类 |
| | | else if (deviceType == Language.StringByID(StringId.Curtain)) |
| | | { |
| | | functionTypeList.Add(SPK.CurtainSwitch); |
| | | functionTypeList.Add(SPK.CurtainRoller); |
| | | functionTypeList.Add(SPK.CurtainTrietex); |
| | | } |
| | | ///空调类 |
| | | else if (deviceType == Language.StringByID(StringId.AC)) |
| | | { |
| | | functionTypeList.Add(SPK.AcStandard); |
| | | functionTypeList.Add(SPK.HvacAC); |
| | | } |
| | | ///地暖类 |
| | | else if (deviceType == Language.StringByID(StringId.FloorHeating)) |
| | | { |
| | | functionTypeList.Add(SPK.FloorHeatStandard);functionTypeList.Add(SPK.HvacFloorHeat); |
| | | functionTypeList.Add(SPK.FloorHeatStandard); functionTypeList.Add(SPK.HvacFloorHeat); |
| | | } |
| | | ///新风类 |
| | | else if (deviceType == Language.StringByID(StringId.AirFresh)) |
| | | { |
| | | functionTypeList.Add(SPK.AirFreshStandard); functionTypeList.Add(SPK.HvacAirFresh); |
| | | } |
| | | ///传感器类 |
| | | else if (deviceType == Language.StringByID(StringId.Sensor)) |
| | | { |
| | | functionTypeList.Add(SPK.SensorSmoke); |
| | |
| | | |
| | | |
| | | } |
| | | ///家电类 |
| | | else if (deviceType == Language.StringByID(StringId.Electric)) |
| | | { |
| | | functionTypeList.Add(SPK.AirSwitch); |
| | | functionTypeList.Add(SPK.PanelSocket); |
| | | functionTypeList.Add(SPK.ElectricSocket); |
| | | } |
| | | |
| | | |
| | | return functionTypeList; |
| | | |
| | | } |
| | |
| | | deviceTypeList.Add(SPK.SensorPm25); |
| | | deviceTypeList.Add(SPK.SensorTVOC); |
| | | deviceTypeList.Add(SPK.SensorHcho); |
| | | deviceTypeList.Add(SPK.AirSwitch); |
| | | deviceTypeList.Add(SPK.PanelSocket); |
| | | deviceTypeList.Add(SPK.ElectricSocket); |
| | | |
| | | } |
| | | break; |
| | |
| | | deviceTypeList.Add(SPK.AcStandard); deviceTypeList.Add(SPK.HvacAC); |
| | | deviceTypeList.Add(SPK.FloorHeatStandard); deviceTypeList.Add(SPK.HvacFloorHeat); |
| | | deviceTypeList.Add(SPK.AirFreshStandard); deviceTypeList.Add(SPK.HvacAirFresh); |
| | | deviceTypeList.Add(SPK.AirSwitch); |
| | | deviceTypeList.Add(SPK.PanelSocket); |
| | | deviceTypeList.Add(SPK.ElectricSocket); |
| | | } |
| | | break; |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | #region 高德坐标转WGS84坐标 |
| | | /// <summary> |
| | | /// 高德坐标转WGS84坐标 |
| | | /// </summary> |
| | | /// <param name="in_lng"></param> |
| | | /// <param name="in_lat"></param> |
| | | /// <param name="out_lng"></param> |
| | | /// <param name="out_lat"></param> |
| | | public void GCJ02_to_WGS84(double in_lng, double in_lat, out double out_lng, out double out_lat) |
| | | { |
| | | if (OutOfChina(in_lat, in_lng)) |
| | | { |
| | | out_lng = in_lng; |
| | | out_lat = in_lat; |
| | | return; |
| | | } |
| | | |
| | | CalculateDev(in_lng, in_lat, out out_lng, out out_lat); |
| | | out_lng = in_lng - out_lng; |
| | | out_lat = in_lat - out_lat; |
| | | } |
| | | #endregion |
| | | |
| | | #region WGS84坐标转高德坐标 |
| | | /// <summary> |
| | | /// WGS84坐标转高德坐标 |
| | | /// </summary> |
| | | /// <param name="in_lng">经度</param> |
| | | /// <param name="in_lat">纬度</param> |
| | | /// <param name="out_lng"></param> |
| | | /// <param name="out_lat"></param> |
| | | public void WGS84_to_GCJ02(double in_lng, double in_lat, out double out_lng, out double out_lat) |
| | | { |
| | | if (OutOfChina(in_lat, in_lng)) |
| | | { |
| | | out_lng = in_lng; |
| | | out_lat = in_lat; |
| | | return; |
| | | } |
| | | |
| | | CalculateDev(in_lng, in_lat, out out_lng, out out_lat); |
| | | out_lng = in_lng + out_lng; |
| | | out_lat = in_lat + out_lat; |
| | | } |
| | | #endregion |
| | | |
| | | /// <summary> |
| | | /// 坐标是否在中国境内 |
| | | /// </summary> |
| | | /// <param name="lat"></param> |
| | | /// <param name="lng"></param> |
| | | /// <returns></returns> |
| | | public bool OutOfChina(double lat, double lng) |
| | | { |
| | | if (lng < 72.004 || lng > 137.8347) |
| | | return true; |
| | | if (lat < 0.8293 || lat > 55.8271) |
| | | return true; |
| | | return false; |
| | | } |
| | | /// <summary> |
| | | /// 计算偏差 |
| | | /// </summary> |
| | | /// <param name="in_lng"></param> |
| | | /// <param name="in_lat"></param> |
| | | /// <param name="dLng"></param> |
| | | /// <param name="dLat"></param> |
| | | private void CalculateDev(double in_lng, double in_lat, out double dLng, out double dLat) |
| | | { |
| | | dLat = TransformLat(in_lng - 105.0, in_lat - 35.0); |
| | | dLng = TransformLng(in_lng - 105.0, in_lat - 35.0); |
| | | |
| | | double radLat = in_lat / 180.0 * pi; |
| | | double magic = Math.Sin(radLat); |
| | | magic = 1 - ee * magic * magic; |
| | | double sqrtMagic = Math.Sqrt(magic); |
| | | dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi); |
| | | dLng = (dLng * 180.0) / (a / sqrtMagic * Math.Cos(radLat) * pi); |
| | | } |
| | | |
| | | private double TransformLat(double x, double y) |
| | | { |
| | | double ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.Sqrt(Math.Abs(x)); |
| | | ret += (20.0 * Math.Sin(6.0 * x * pi) + 20.0 * Math.Sin(2.0 * x * pi)) * 2.0 / 3.0; |
| | | ret += (20.0 * Math.Sin(y * pi) + 40.0 * Math.Sin(y / 3.0 * pi)) * 2.0 / 3.0; |
| | | ret += (160.0 * Math.Sin(y / 12.0 * pi) + 320 * Math.Sin(y * pi / 30.0)) * 2.0 / 3.0; |
| | | return ret; |
| | | } |
| | | private double TransformLng(double x, double y) |
| | | { |
| | | double ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.Sqrt(Math.Abs(x)); |
| | | ret += (20.0 * Math.Sin(6.0 * x * pi) + 20.0 * Math.Sin(2.0 * x * pi)) * 2.0 / 3.0; |
| | | ret += (20.0 * Math.Sin(x * pi) + 40.0 * Math.Sin(x / 3.0 * pi)) * 2.0 / 3.0; |
| | | ret += (150.0 * Math.Sin(x / 12.0 * pi) + 300.0 * Math.Sin(x / 30.0 * pi)) * 2.0 / 3.0; |
| | | return ret; |
| | | } |
| | | // 椭球参数-圆周率 |
| | | private const double pi = 3.14159265358979324; |
| | | |
| | | // (北京54)椭球长半轴,卫星椭球坐标投影到平面地图坐标系的投影因子 |
| | | private const double a = 6378245.0; |
| | | /* |
| | | * Krasovsky 1940 (北京54)椭球长半轴第一偏心率平方 |
| | | * 计算方式: |
| | | * 长半轴: |
| | | * a = 6378245.0 |
| | | * 扁率: |
| | | * 1/f = 298.3(变量相关计算为:(a-b)/a) |
| | | * 短半轴: |
| | | * b = 6356863.0188 (变量相关计算方法为:b = a * (1 - f)) |
| | | * 第一偏心率平方: |
| | | * e2 = (a^2 - b^2) / a^2; |
| | | */ |
| | | private const double ee = 0.00669342162296594323; |
| | | |
| | | /// <summary> |
| | | /// APP上报GPS经纬度 |
| | | /// </summary> |
| | | public void AppLatAndLonEvent() |
| | | { |
| | | Application.LocationAction += (lon, lat) => |
| | | { |
| | | ////GPS坐标转成高德坐标 |
| | | //double out_lng, out_lat; |
| | | //this.WGS84_to_GCJ02(lon, lat, out out_lng, out out_lat); |
| | | //上报经纬度 |
| | | this.AutomatedGeofenceStatusReporting(lon, lat); |
| | | }; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 自动化地理围栏状态上报云端 |
| | | /// </summary> |
| | | /// <param name="out_lng">APP GPS经度</param> |
| | | /// <param name="out_lat">APP GPS纬度</param> |
| | | private void AutomatedGeofenceStatusReporting(double out_lng, double out_lat) |
| | | { |
| | | List<LogicData> logicDataList = new List<LogicData>(); |
| | | logicDataList.Clear(); |
| | | //获取逻辑ID列表 |
| | | var idStr = Send.GetLogicIdList(); |
| | | if (idStr.Code == "0" && idStr.Data != null && idStr.Data.ToString() != "") |
| | | { |
| | | var date = Newtonsoft.Json.JsonConvert.SerializeObject(idStr.Data); |
| | | logicDataList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<LogicData>>(date); |
| | | } |
| | | ///有自动列表才处理 |
| | | if (logicDataList.Count>0) { |
| | | ///遍历所有列表 |
| | | for (int i = 0; i < logicDataList.Count; i++) |
| | | { |
| | | var logicDate = logicDataList[i]; |
| | | ///自动化没有配置地理围栏不处理 |
| | | if (string.IsNullOrEmpty(logicDate.geo_fence.latitude) || string.IsNullOrEmpty(logicDate.geo_fence.longitude)) |
| | | { |
| | | //经纬度为空,认为自动化没有配置地理围栏,不处理; |
| | | continue; |
| | | } |
| | | //自动化纬度 |
| | | double lat = Convert.ToDouble(logicDate.geo_fence.latitude); |
| | | //自动化经度 |
| | | double lon = Convert.ToDouble(logicDate.geo_fence.longitude); |
| | | //自动化配置输入条件<地理围栏半径><单位,公里、千米.米> |
| | | int radius = int.Parse(logicDate.geo_fence.radius); |
| | | //计算2个经纬度之间的距离 |
| | | int r =Infrastructure.Service.Helper.CalculatedDistance.Distance(out_lat, out_lng, lat, lon); |
| | | //定义一个局部变量 |
| | | string direction = string.Empty; |
| | | //两点距离小于配置距离<既自动化配置输入条件地理围栏半径>,说明进入区域 |
| | | if (r<radius) { |
| | | //到达某地 |
| | | direction = "arrive"; |
| | | } else { |
| | | //离开 |
| | | direction = "leave"; |
| | | } |
| | | bool f= Send.GeoFenceStateReport(logicDate.userLogicId,logicDate.sid, direction); |
| | | //if () { } |
| | | //Common.FileUtlis.Files.WriteFileByBytes(savePath, ssd); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | } |