/// <summary> /// 设置分钟数据间隔 /// </summary> private void SetMinuteDataInterval(HJ212Model model) { string content = string.Empty; int? MinInterval = Deserialize.SetMinuteDataInterval(model.CP); if (null == MinInterval) { content = Serialize.ExecuteResponse(config, model.QN, ExecuteResult.CommandError); } else { config.MinInterval = (int)MinInterval; ReWriteConfig(); if (null != minuterDataTimer) { minuterDataTimer.Dispose(); } if (config.MinuteData) { minuterDataTimer = new Timer(new TimerCallback(MinuteDataCallBack), null, (config.MinInterval - DateTime.Now.Minute % config.MinInterval) * 60 * 1000, config.MinInterval * 60 * 1000); } content = Serialize.ExecuteResponse(config, model.QN, ExecuteResult.Success); } SendData(content); }
/// <summary> /// 设置现场机参数 /// </summary> private void SetSceneDeviceParam(HJ212Model model) { string content = string.Empty; SetSceneDeviceParamModel setSceneDeviceParam = Deserialize.SetSceneDeviceParam(model.CP); if (string.IsNullOrEmpty(setSceneDeviceParam.PolId) || string.IsNullOrEmpty(setSceneDeviceParam.InfoId) || setSceneDeviceParam.Value == null) { content = Serialize.ExecuteResponse(config, model.QN, ExecuteResult.CommandError); } else { ParamCodeConfig param = config.ParamCodes.FirstOrDefault(x => x.ParamCode == setSceneDeviceParam.PolId); if (null != param) { InfoConfig info = param.Infos.FirstOrDefault(x => x.InfoId == setSceneDeviceParam.InfoId); if (null == info) { info = new InfoConfig(); info.InfoId = setSceneDeviceParam.InfoId; info.Value = setSceneDeviceParam.Value; } else { info.Value = setSceneDeviceParam.Value; } } ReWriteConfig(); content = Serialize.ExecuteResponse(config, model.QN, ExecuteResult.Success); } SendData(content); }
/// <summary> /// 设置实时数据间隔 /// </summary> private void SetRtdDataInterval(HJ212Model model) { string content = string.Empty; int? RtdInterval = Deserialize.SetRtdDataInterval(model.CP); if (null == RtdInterval) { content = Serialize.ExecuteResponse(config, model.QN, ExecuteResult.CommandError); } else { config.RtdInterval = (int)RtdInterval; ReWriteConfig(); if (null != rtdDataTimer) { rtdDataTimer.Dispose(); } if (config.RtdData) { rtdDataTimer = new Timer(new TimerCallback(RtdDataCallBack), null, 0, config.RtdInterval * 1000); } content = Serialize.ExecuteResponse(config, model.QN, ExecuteResult.Success); } SendData(content); }
/// <summary> /// 上传设备运行时间日历史数据 /// </summary> private void UploadDeviceRunTimeDayData(HJ212Model model) { string content = string.Empty; HistoryDataModel historyDataModel = Deserialize.GetDeviceRunTimeDayData(model.CP); if (null == historyDataModel.BeginTime || null == historyDataModel.EndTime) { content = Serialize.ExecuteResponse(config, model.QN, ExecuteResult.CommandError); } else { for (DateTime dt = (DateTime)historyDataModel.BeginTime; dt <= historyDataModel.EndTime; dt = dt.AddDays(1)) { string qn = Util.GetTimeStamp(); IList <DeviceRunTimeModel> datas = new List <DeviceRunTimeModel>(); foreach (DeviceConfig param in config.Devices) { DeviceRunTimeModel deviceRunTimeModel = new DeviceRunTimeModel(); deviceRunTimeModel.DeviceNumber = param.DeviceNumber; deviceRunTimeModel.DeviceRunTime = Util.GetRunHourRandom(); datas.Add(deviceRunTimeModel); } string c = Serialize.UploadDeviceRunTimeDayData(config, qn, dt, datas); SendData(content); } content = Serialize.ExecuteResponse(config, model.QN, ExecuteResult.Success); } SendData(content); }
/// <summary> /// 上传超标留样信息 /// </summary> private void UploadSuperstandardSample(HJ212Model model) { string content = Serialize.UploadSuperstandardSample(config, model.QN, DateTime.Now, config.VaseNo); SendData(content); content = Serialize.ExecuteResponse(config, model.QN, ExecuteResult.Success); SendData(content); }
/// <summary> /// 请求应答 /// </summary> /// <param name="model"></param> private void RequestResponse(HJ212Model model, CommandResult res) { if (model.Flag_A == 1) { string content = Serialize.RequestResponse(config, model.QN, res); SendData(content); } }
/// <summary> /// 通知应答 /// </summary> /// <param name="model"></param> private void NoticeResponse(HJ212Model model) { if (model.Flag_A == 1) { string content = Serialize.NoticeResponse(config, model.QN); SendData(content); } }
/// <summary> /// 上传分钟数据间隔 /// </summary> private void UploadMinuteDataInterval(HJ212Model model) { string content = Serialize.UploadMinuteDataInterval(config, model.QN, config.MinInterval); SendData(content); content = Serialize.ExecuteResponse(config, model.QN, ExecuteResult.Success); SendData(content); }
/// <summary> /// 取污染物实时数据 /// </summary> private void GetRtdData(HJ212Model model) { string content = string.Empty; if (!config.RtdData) { config.RtdData = true; ReWriteConfig(); rtdDataTimer = new Timer(new TimerCallback(RtdDataCallBack), null, 0, config.RtdInterval * 1000); } content = Serialize.ExecuteResponse(config, model.QN, ExecuteResult.Success); SendData(content); }
/// <summary> /// 取设备运行状态数据 /// </summary> private void GetDeviceRunState(HJ212Model model) { string content = string.Empty; if (!config.DeviceRunState) { config.DeviceRunState = true; ReWriteConfig(); deviceRunStateTimer = new Timer(new TimerCallback(DeviceRunStateCallBack), null, 0, config.DeviceRunStateInterval * 1000); } content = Serialize.ExecuteResponse(config, model.QN, ExecuteResult.Success); SendData(content); }
/// <summary> /// 停止察看设备运行状态 /// </summary> private void StopDeviceRunState(HJ212Model model) { string content = string.Empty; if (config.RtdData) { config.DeviceRunState = false; ReWriteConfig(); deviceRunStateTimer.Dispose(); } content = Serialize.ExecuteResponse(config, model.QN, ExecuteResult.Success); SendData(content); }
/// <summary> /// 比对采样 /// </summary> private void CompareSample(HJ212Model model) { string content = string.Empty; string PolId = Deserialize.CompareSample(model.CP); if (string.IsNullOrEmpty(PolId)) { content = Serialize.ExecuteResponse(config, model.QN, ExecuteResult.CommandError); } else { content = Serialize.ExecuteResponse(config, model.QN, ExecuteResult.Success); } SendData(content); }
/// <summary> /// 提取现场机信息 /// </summary> private void UploadSceneDeviceInfo(HJ212Model model) { string content = string.Empty; GetSceneDeviceInfoModel getSceneDeviceInfoModel = Deserialize.GetSceneDeviceInfo(model.CP); if (string.IsNullOrEmpty(getSceneDeviceInfoModel.PolId) || string.IsNullOrEmpty(getSceneDeviceInfoModel.InfoId)) { content = Serialize.ExecuteResponse(config, model.QN, ExecuteResult.CommandError); } else { string c = Serialize.UploadSceneDeviceInfo(config, model.QN, getSceneDeviceInfoModel.PolId, getSceneDeviceInfoModel.InfoId, new Random().NextDouble(), DateTime.Now); content = Serialize.ExecuteResponse(config, model.QN, ExecuteResult.Success); } SendData(content); }
/// <summary> /// 用于设置现场机的密码 /// </summary> private void SetSceneDevicePassword(HJ212Model model) { string content = string.Empty; string NewPW = Deserialize.SetSceneDevicePassword(model.CP); if (null == NewPW) { content = Serialize.ExecuteResponse(config, model.QN, ExecuteResult.CommandError); } else { config.PW = NewPW; ReWriteConfig(); content = Serialize.ExecuteResponse(config, model.QN, ExecuteResult.Success); } SendData(content); }
/// <summary> /// 设置超时时间及重发次数 /// </summary> private void SetTimeOutReSendTimes(HJ212Model model) { string content = string.Empty; SetTimeOutReSendTimesModel setTimeOutReSendTimesModel = Deserialize.SetTimeOutReSendTimes(model.CP); if (null == setTimeOutReSendTimesModel.ReCount || null == setTimeOutReSendTimesModel.OverTime) { content = Serialize.ExecuteResponse(config, model.QN, ExecuteResult.CommandError); } else { config.ReCount = (int)setTimeOutReSendTimesModel.ReCount; config.OverTime = (int)setTimeOutReSendTimesModel.OverTime; ReWriteConfig(); content = Serialize.ExecuteResponse(config, model.QN, ExecuteResult.Success); } SendData(content); }
/// <summary> /// 上传现场机时间 /// </summary> private void UploadSceneDeviceTime(HJ212Model model) { string content = string.Empty; string PolId = Deserialize.GetSceneDeviceTime(model.CP); if (string.IsNullOrEmpty(PolId)) { content = Serialize.ExecuteResponse(config, model.QN, ExecuteResult.CommandError); SendData(content); } else { content = Serialize.UploadSceneDeviceTime(config, model.QN, PolId, DateTime.Now); SendData(content); content = Serialize.ExecuteResponse(config, model.QN, ExecuteResult.Success); SendData(content); } }
/// <summary> /// 提取设备唯一标识 /// </summary> private void UploadSceneDeviceUUID(HJ212Model model) { string content = string.Empty; string PolId = Deserialize.GetSceneDeviceUUID(model.CP); if (string.IsNullOrEmpty(PolId)) { content = Serialize.ExecuteResponse(config, model.QN, ExecuteResult.CommandError); } else { ParamCodeConfig param = config.ParamCodes.FirstOrDefault(x => x.ParamCode == PolId); if (null != param) { string c = Serialize.UploadSceneDeviceUUID(config, model.QN, param.ParamCode, param.SN); SendData(c); } content = Serialize.ExecuteResponse(config, model.QN, ExecuteResult.Success); } SendData(content); }
/// <summary> /// 请求应答 /// </summary> /// <param name="model"></param> private CommandResult RequestResponse(HJ212Model model) { CommandResult res = CommandResult.Ready; if (string.IsNullOrEmpty(model.QN)) { res = CommandResult.QNError; } else if (config.PW != model.PW) { res = CommandResult.PWError; } else if (config.MN != model.MN) { res = CommandResult.MNError; } else if (config.ST != model.ST) { res = CommandResult.STError; } else if (string.IsNullOrEmpty(model.Flag)) { res = CommandResult.FlagError; } else if (0 == model.CN) { res = CommandResult.CNError; } else if (config.CheckCRC && model.CRC != Util.GetHj212Crc16(model.Body)) { res = CommandResult.CRCError; } if (model.Flag_A == 1) { string content = Serialize.RequestResponse(config, model.QN, res); SendData(content); } return(res); }
/// <summary> /// 上传污染物周期数据 /// </summary> private void UploadCycleData(HJ212Model model) { string content = string.Empty; HistoryDataModel historyDataModel = Deserialize.GetCycleData(model.CP); if (null == historyDataModel.BeginTime || null == historyDataModel.EndTime) { content = Serialize.ExecuteResponse(config, model.QN, ExecuteResult.CommandError); } else { for (DateTime dt = (DateTime)historyDataModel.BeginTime; dt <= historyDataModel.EndTime; dt = dt.AddHours(config.CycleInterval)) { string qn = Util.GetTimeStamp(); IDictionary <string, DataModel> datas = new Dictionary <string, DataModel>(); foreach (ParamCodeConfig param in config.ParamCodes) { DataModel dataModel = new DataModel(); dataModel.Rtd = Util.GetRandom(param.DefaultValue, param.Max, param.Min); dataModel.Min = Util.GetMin((double)dataModel.Rtd, param.DefaultValue - param.Min); dataModel.Max = Util.GetMax((double)dataModel.Rtd, param.DefaultValue + param.Max); if (param.CouValue) { dataModel.Cou = dataModel.Rtd * 60 * config.CycleInterval; } model.Flag = param.DataFlag; datas.Add(param.ParamCode, dataModel); } IEnumerable <string> contents = Serialize.UploadCycleData(config, qn, dt, datas); foreach (string c in contents) { SendData(c); } } content = Serialize.ExecuteResponse(config, model.QN, ExecuteResult.Success); } SendData(content); }
/// <summary> /// 设置现场机时间 /// </summary> private void SetSceneDeviceTime(HJ212Model model) { string content = string.Empty; DateTime?SystemTime = Deserialize.SetSceneDeviceTime(model.CP); if (null == SystemTime) { content = Serialize.ExecuteResponse(config, model.QN, ExecuteResult.CommandError); } else { bool res = Win32Util.SetSystemTime((DateTime)SystemTime); if (res) { content = Serialize.ExecuteResponse(config, model.QN, ExecuteResult.Success); } else { content = Serialize.ExecuteResponse(config, model.QN, ExecuteResult.Fail); } } SendData(content); }
/// <summary> /// 设置采样时间周期 /// </summary> private void SetSampleTimeInterval(HJ212Model model) { string content = string.Empty; SetSampleTimeIntervalModel setSampleTimeIntervalModel = Deserialize.SetSampleTimeInterval(model.CP); if (string.IsNullOrEmpty(setSampleTimeIntervalModel.PolId) || string.IsNullOrEmpty(setSampleTimeIntervalModel.CstartTime) || setSampleTimeIntervalModel.CTime == null) { content = Serialize.ExecuteResponse(config, model.QN, ExecuteResult.CommandError); } else { ParamCodeConfig param = config.ParamCodes.FirstOrDefault(x => x.ParamCode == setSampleTimeIntervalModel.PolId); if (null != param) { param.CstartTime = setSampleTimeIntervalModel.CstartTime; param.CTime = (int)setSampleTimeIntervalModel.CTime; ReWriteConfig(); } content = Serialize.ExecuteResponse(config, model.QN, ExecuteResult.Success); } SendData(content); }
/// <summary> /// 执行结果 /// </summary> /// <param name="model"></param> private void ExecuteResponse(HJ212Model model, ExecuteResult res) { string content = Serialize.ExecuteResponse(config, model.QN, res); SendData(content); }
/// <summary> /// 数据应答 /// </summary> /// <param name="model"></param> private void DataResponse(HJ212Model model) { string content = Serialize.DataResponse(config, model.QN); SendData(content); }
/// <summary> /// 数据接收 /// </summary> /// <param name="data"></param> public override void DataReceive(string data) { try { if (string.IsNullOrEmpty(data)) { return; } HJ212Model model = Deserialize.DeserializeBase(data); CommandType type = Util.GetCommandType((MiddleCode)model.CN); switch (type) { case CommandType.Notice: NoticeResponse(model); break; case CommandType.Request: CommandResult res = RequestResponse(model); if (res != CommandResult.Ready) { return; } break; case CommandType.Upload: RequestResponse(model, CommandResult.Forbidden); return; case CommandType.Other: return; case CommandType.None: RequestResponse(model, CommandResult.Forbidden); return; default: RequestResponse(model, CommandResult.Forbidden); return; } switch ((MiddleCode)model.CN) { case MiddleCode.SetTimeOutReSendTimes: SetTimeOutReSendTimes(model); break; case MiddleCode.GetSceneDeviceTime: UploadSceneDeviceTime(model); break; case MiddleCode.SetSceneDeviceTime: SetSceneDeviceTime(model); break; case MiddleCode.GetRtdDataInterval: UploadRtdDataInterval(model); break; case MiddleCode.SetRtdDataInterval: SetRtdDataInterval(model); break; case MiddleCode.GetMinuteDataInterval: UploadMinuteDataInterval(model); break; case MiddleCode.SetMinuteDataInterval: SetMinuteDataInterval(model); break; case MiddleCode.SetSceneDevicePassword: SetSceneDevicePassword(model); break; case MiddleCode.GetRtdData: GetRtdData(model); break; case MiddleCode.StopRtdData: StopRtdData(model); break; case MiddleCode.GetDeviceRunState: GetDeviceRunState(model); break; case MiddleCode.StopDeviceRunState: StopDeviceRunState(model); break; case MiddleCode.GetDayData: UploadDayData(model); break; case MiddleCode.GetDeviceRunTimeDayData: UploadDeviceRunTimeDayData(model); break; case MiddleCode.GetMinuteData: UploadMinuteData(model); break; case MiddleCode.GetHourData: UploadHourData(model); break; case MiddleCode.RangeCalibration: RangeCalibration(model); break; case MiddleCode.GetCycleData: UploadCycleData(model); break; case MiddleCode.TakeSampleImmediately: TakeSampleImmediately(model); break; case MiddleCode.StartClear: StartClear(model); break; case MiddleCode.CompareSample: CompareSample(model); break; case MiddleCode.LeaveSuperstandardSample: UploadSuperstandardSample(model); break; case MiddleCode.SetSampleTimeInterval: SetSampleTimeInterval(model); break; case MiddleCode.GetSampleTimeInterval: UploadSampleTimeInterval(model); break; case MiddleCode.GetSampleTime: UploadSampleTime(model); break; case MiddleCode.GetSceneDeviceUUID: UploadSceneDeviceUUID(model); break; case MiddleCode.GetSceneDeviceInfo: UploadSceneDeviceInfo(model); break; case MiddleCode.SetSceneDeviceParam: SetSceneDeviceParam(model); break; } } catch (Exception ex) { throw ex; } }