public override void ExecuteCommand(RainfallSession session, RainfallRequestInfo requestInfo) { LOGGER.Debug("===================读取设备时间响应处理===================="); byte[] body = requestInfo.Body; DateTime dt = ConvertUtil.Bcd2Date(body); LOGGER.Debug("设备时间:" + dt.ToString("yyyy年MM月dd日hh:mm:ss")); }
public override void ExecuteCommand(RainfallSession session, RainfallRequestInfo requestInfo) { try { int bodyLength = requestInfo.Body.Length; if (bodyLength == 1) { if (requestInfo.Body[0] == 0x52) { LOGGER.Debug("参数设置成功"); } else if (requestInfo.Body[0] == 0x51) { LOGGER.Debug("参数设置失败"); } return; } //时间 byte[] timeBytes = requestInfo.Body.CloneRange(0, 6); DateTime dt = ConvertUtil.Bcd2Date(timeBytes); LOGGER.Debug("设备时间:" + dt.ToString("yyyy年MM月dd日hh:mm:ss")); //18组报警阀值内容 byte[] alarmValueListBytes = requestInfo.Body.CloneRange(6, 36); //雨量计分辨率 byte resolutionByte = requestInfo.Body[requestInfo.Body.Length - 1]; float resolution = 0.0f; if (resolutionByte == 0x01) { resolution = 0.2f; } else if (resolutionByte == 0x02) { resolution = 0.5f; } else if (resolutionByte == 0x03) { resolution = 1.0f; } List <float> alarmValueList = new List <float>(); for (int i = 0; i < alarmValueListBytes.Length / 2; i++) { float alarmValue = ConvertUtil.bytes2Int(alarmValueListBytes.CloneRange(i * 2, 2)) * resolution; alarmValueList.Add(alarmValue); } int offset = 1; foreach (float value in alarmValueList) { LOGGER.DebugFormat("第[{0}]组报警阀值[{1}]", offset++, value); } } catch (Exception e) { LOGGER.Error("参数设置响应处理异常", e); } }
public override void ExecuteCommand(RainfallSession session, RainfallRequestInfo requestInfo) { //数据包数量 uint countPackage = (uint)(requestInfo.Body[0] & 0xFF); byte[] contextBytes = requestInfo.Body.CloneRange(1, requestInfo.Body.Length - 1); if (contextBytes.Length == countPackage * 7) { List <HistoricalRainfall> dataList = new List <HistoricalRainfall>(); for (int i = 0; i < countPackage; i++) { byte[] dataByte = contextBytes.CloneRange(i * 7, 7); HistoricalRainfall data = new HistoricalRainfall(); data.historicalTime = ConvertUtil.Bcd2Date(dataByte.CloneRange(0, 6)); data.TipperCount = (uint)(dataByte[6] & 0xFF); dataList.Add(data); } //正常收到数据包的回复 byte[] responseData = { 0x38 }; session.Send(responseData, 0, 1); } }