/// <summary> /// 处理数据的任务入口 /// </summary> /// <param name="args"></param> private void DealSoilData(CSingleSoilDataArgs args) { CEntitySoilData data = new CEntitySoilData(); // if (null == CDBDataMgr.Instance.GetStationById(args.StrStationId)) if (null == GetSoilStationInfoByStationId(args.StrStationId)) { // 也就是收到未知站点的数据 CSystemInfoMgr.Instance.AddInfo(string.Format("收到未知站点{0}墒情数据", args.StrStationId)); return; } // 判断当前数据库配置中是否有站点的墒情配置 CEntitySoilStation _soilStation = GetSoilStationInfoByStationId(args.StrStationId); if (null == _soilStation) { CSystemInfoMgr.Instance.AddInfo(string.Format("站点{0}未配置墒情参数,数据丢弃", args.StrStationId)); return; } data.StationID = args.StrStationId; // data.StrDeviceNumber = _soilStation.StrDeviceNumber; data.DataTime = args.DataTime; data.DVoltage = decimal.Parse(args.Voltage.ToString()); data.ChannelType = args.EChannelType; data.MessageType = args.EMessageType; data.reciveTime = DateTime.Now; data.state = 1; // 计算10cm出的含水率 data.Voltage10 = args.D10Value; data.Moisture10 = CalMoisture(args.D10Value, _soilStation.A10, _soilStation.B10, _soilStation.C10, _soilStation.D10, _soilStation.M10, _soilStation.N10); //data.Moisture10 = CalMoisture(args.D10Value, _soilStation.A10, _soilStation.B10, _soilStation.C10, _soilStation.D10); // 计算20cm处的含水率 data.Voltage20 = args.D20Value; data.Moisture20 = CalMoisture(args.D20Value, _soilStation.A20, _soilStation.B20, _soilStation.C20, _soilStation.D20, _soilStation.M20, _soilStation.N20); //// 计算30cm处的含水率 //data.Voltage30 = args.D30Value; //data.Moisture30 = CalMoisture(args.D30Value, _soilStation.A30, _soilStation.B30, _soilStation.C30, _soilStation.D30); // 计算40cm处的含水率 data.Voltage40 = args.D40Value; data.Moisture40 = CalMoisture(args.D40Value, _soilStation.A40, _soilStation.B40, _soilStation.C40, _soilStation.D40, _soilStation.M40, _soilStation.N40); //// 计算60cm处的含水率 //data.Voltage60 = args.D60Value; //data.Moisture60 = CalMoisture(args.D60Value, _soilStation.A60, _soilStation.B60, _soilStation.C60, _soilStation.D60); // 写入数据库 m_proxySoilData.AddNewRow(data); //if (RecvedRTDSoilData != null) //{ // // 发消息通知界面 // RecvedRTDSoilData.Invoke(this, new CEventSingleArgs<CEntitySoilData>(data)); //} // 更新内存最新数据,便于写入文件 if (m_mapStataionLastData.ContainsKey(args.StrStationId)) { m_mapStataionLastData[args.StrStationId] = data; } else { // 新建一个,进行更新 m_mapStataionLastData.Add(args.StrStationId, data); } }
/// <summary> /// 收到墒情数据,从通信协议中收到,多线程处理 /// </summary> /// <param name="sender"></param> /// <param name="args"></param> public void EHRecvSoildData(object sender, CSingleSoilDataArgs args) { m_taskMgr.NewTask(() => { DealSoilData(args); }); }