Exemple #1
0
        private void UpdateDevGps(DevCtrlResponseCmd cmd, int devId)
        {
            var statInfo = DevsManage.GetStatInfo(devId);
            var data     = new byte[24];

            for (var i = 0; i < 24; i++)
            {
                if (cmd.Data[i] == 0x00)
                {
                    data[i] = 0x30;
                }
                else
                {
                    data[i] = cmd.Data[i];
                }
            }

            var sourceCoordinate = Encoding.ASCII.GetString(data, 0, 24).Insert(12, ",");
            var url = $"http://api.map.baidu.com/geoconv/v1/?coords={sourceCoordinate}&from=1&to=5&ak=0DpSiAEhexZzZR7c7pkYFq7E";

            var request  = (HttpWebRequest)WebRequest.Create(url);
            var response = request.GetResponse();
            // ReSharper disable once AssignNullToNotNullAttribute
            var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
            var result         = JsonConvert.DeserializeObject <BaiduCordinateResult>(responseString);
            var bll            = new ESMonitor.BLL.Devs();
            var cor            = result.result[0];

            bll.UpdateGps(statInfo.StatId, cor.y, cor.x);
        }
Exemple #2
0
        /// <summary>
        /// 保存下位机上传的分钟均值
        /// </summary>
        /// <param name="devId"></param>
        /// <param name="esParams"></param>
        private long AddEsMin(int devId, EsData esParams)
        {
            var model = new EsMin
            {
                Airpressure   = 0,
                DevId         = devId,
                UpdateTime    = DateTime.Now,
                Pm25          = esParams.Pm25,
                Pm100         = esParams.Pm100,
                Db            = esParams.Noise,
                Humidity      = esParams.Humidity,
                Temperature   = esParams.Temperature,
                Tp            = esParams.Cmp,
                WindDirection = esParams.WindDir,
                WindSpeed     = esParams.WindSpeed
            };

            var statInfo = DevsManage.GetStatInfo(devId);

            if (statInfo != null)
            {
                model.StatId     = statInfo.StatId;
                model.Country    = statInfo.Country;
                model.StatCodeUp = statInfo.StatCodeUp;
            }
            else
            {
                model.StatId  = 0;
                model.Country = "";
            }

            model.DataStatus = model.WindSpeed > 5 ? "S" : "N";

            RedisService.GetRedisDatabase().StringSet($"DustLastValue:{model.StatId}-{devId}", JsonConvert.SerializeObject(model), expiry: TimeSpan.FromMinutes(1));

            return(_esMinBll.Add(model));
        }