/// <summary> /// 1.0和0.1都用同一种协议解析 /// </summary> private void analysis1_0or0_1() { int alllength = (int)SystemCode.HexNumberToDenary(this.messageContent.Substring(2 * 2, 2 * 2), true, 32, 'u') * 2; if (this.messageContent.Length >= (istart + icount) && alllength == (this.messageContent.Length - 2 * 2)) { messageHeader = new TcpHeader(); messageHeader.analyze(this.messageContent.Substring(istart, icount)); istart = istart + icount; //循环解析多个设备 listTcpbody = new List<DeviceDataBase>(); for (int i = 0; i < this.messageHeader.DevicesNum; i++) { DeviceDataBase ddb = null; if (istart > messageContent.Length) break; int type = (int)SystemCode.HexNumberToDenary(this.messageContent.Substring(istart + 2 * 2, 1 * 2), true, 32, 'u'); switch (type) { case DeviceData.TYPE_MODBUS_BUSBAR://modbus协议汇流箱 icount = ProtocolConst.LENGTH_MODBUS_BUSBAR * 2; if (istart + icount > this.messageContent.Length) { istart = istart + icount; break; } else { ddb = new ModbusBusbar(this.messageContent.Substring(istart, icount), this); istart = istart + icount; break; } case DeviceData.TYPE_MODBUS15_BUSBAR://光伏阵列汇流箱通讯协议(Modbus)V1.1.1.0-2011.8.30.pdf add by qianhb in 20111220 icount = ProtocolConst.LENGTH_MODBUS15_BUSBAR * 2; if (istart + icount > this.messageContent.Length) { istart = istart + icount; break; } else { ddb = new Modbus15Busbar(this.messageContent.Substring(istart, icount), this); istart = istart + icount; break; } case DeviceData.TYPE_MODBUS_CABINET://modbus协议配电柜 icount = ProtocolConst.LENGTH_MODBUS_CABINET * 2; if (istart + icount > this.messageContent.Length) { istart = istart + icount; break; } else { ddb = new ModbusCabinet(this.messageContent.Substring(istart, icount), this); istart = istart + icount; break; } case DeviceData.TYPE_MODBUS16_CABINET://光伏直流配电柜通信协议(Modbus)V1.0-柴达木-2011.8.30.pdf add by qianhb in 20111220 icount = ProtocolConst.LENGTH_MODBUS16_CABINET * 2; if (istart + icount > this.messageContent.Length) { istart = istart + icount; break; } else { ddb = new Modbus16Cabinet(this.messageContent.Substring(istart, icount), this); istart = istart + icount; break; } case DeviceData.TYPE_MODBUS_DETECTOR://设备类型0x22对应的数据区格式,环境检测仪(MODBUS协议) add by qianhb in 20111220 icount = ProtocolConst.LENGTH_MODBUS_DETECTOR * 2; if (istart + icount > this.messageContent.Length) { istart = istart + icount; break; } else { ddb = new ModbusDetector(this.messageContent.Substring(istart, icount), this); istart = istart + icount; break; } case DeviceData.TYPE_MODBUS_DETECTOR_V1020://设备类型0x23对应的数据区格式,环境检测仪(MODBUS协议) add by qianhb in 20120314 icount = ProtocolConst.LENGTH_MODBUS_DETECTOR_1020 * 2; if (istart + icount > this.messageContent.Length) { istart = istart + icount; break; } else { ddb = new ModbusDetector1020(this.messageContent.Substring(istart, icount), this); istart = istart + icount; break; } case DeviceData.TYPE_MODBUS_INVERTER://modbus协议逆变器 icount = ProtocolConst.LENGTH_MODBUS_INVERTER * 2; if (istart + icount > this.messageContent.Length) { istart = istart + icount; break; } else { ddb = new ModbusInverter(this.messageContent.Substring(istart, icount),this); istart = istart + icount; break; } case DeviceData.TYPE_SUNGROW_BUSBAR://sungrows协议汇流箱 icount = ProtocolConst.LENGTH_SUNGROW_BUSBAR * 2; if (istart + icount > this.messageContent.Length) { istart = istart + icount; break; } else { ddb = new SungrowBusbar(this.messageContent.Substring(istart, icount), this); istart = istart + icount; break; } case DeviceData.TYPE_SUNGROW_CABINET://sungrows协议配电柜 icount = ProtocolConst.LENGTH_SUNGROW_CABINET * 2; if (istart + icount > this.messageContent.Length) { istart = istart + icount; break; } else { ddb = new SungrowCabinet(this.messageContent.Substring(istart, icount), this); istart = istart + icount; break; } case DeviceData.TYPE_SUNGROW_DETECTOR://sungrow协议检测仪 icount = ProtocolConst.LENGTH_SUNGROW_DETECTOR * 2; if (istart + icount > this.messageContent.Length) { istart = istart + icount; break; } else { ddb = new SungrowDetector(this.messageContent.Substring(istart, icount), this); istart = istart + icount; break; } case DeviceData.TYPE_SUNGROW_INVERTER://sungrow协议逆变器 icount = ProtocolConst.LENGTH_SUNGROW_INVERTER * 2; if (istart + icount > this.messageContent.Length) { istart = istart + icount; break; } else { ddb = new SungrowInverter(this.messageContent.Substring(istart, icount),this); istart = istart + icount; break; } case DeviceData.TYPE_AMMETER://电表协议 icount = ProtocolConst.LENGTH_AMMETER * 2; if (istart + icount > this.messageContent.Length) { istart = istart + icount; break; } else { ddb = new Ammeter(this.messageContent.Substring(istart, icount), this); istart = istart + icount; break; } default: istart = istart + this.messageContent.Length; break; } if (ddb != null) listTcpbody.Add(ddb); } //取得告警信息 listTcpbug = new List<Bug>(); if (this.messageContent.Length > (ProtocolConst.LENGTH_BUG + ProtocolConst.LENGTH_HEAD) * 2) { istart = this.messageContent.Length - ProtocolConst.LENGTH_BUG * 2 * (this.messageHeader.BugNum); for (int i = 0; i < this.messageHeader.BugNum; i++) { Bug tcpb = new TcpBug(this.messageContent.Substring(istart + i * ProtocolConst.LENGTH_BUG * 2, ProtocolConst.LENGTH_BUG * 2)); listTcpbug.Add(tcpb); } } } else { base.messageHeader = new TcpHeader(); listTcpbody = new List<DeviceDataBase>(); listTcpbug = new List<Bug>(); } }
/// <summary> /// 1.0和0.1都用同一种协议解析 /// </summary> private void analysis1_0or0_1() { int alllength = (int)SystemCode.HexNumberToDenary(this.messageContent.Substring(2 * 2, 2 * 2), true, 32, 'u') * 2; if (this.messageContent.Length >= (istart + icount) && alllength == (this.messageContent.Length - 2 * 2)) { messageHeader = new TcpHeader(); messageHeader.analyze(this.messageContent.Substring(istart, icount)); //add by hbqian int 20130418 for其实0。1分的发电量是昨天,按道理不应该发的,但是现在LOG有个换存,导致0:到15分的这个时间发的发电量可能还是上一天的 if (messageHeader.TimeNow.Hour == 0 && messageHeader.TimeNow.Minute < 15) { return; } istart = istart + icount; //循环解析多个设备 listTcpbody = new List<DeviceDataBase>(); for (int i = 0; i < this.messageHeader.DevicesNum; i++) { DeviceDataBase ddb = null; if (istart > messageContent.Length) break; int type = (int)SystemCode.HexNumberToDenary(this.messageContent.Substring(istart + 2 * 2, 1 * 2), true, 32, 'u'); switch (type) { case DeviceData.TYPE_MODBUS_BUSBAR://modbus协议汇流箱 icount = ProtocolConst.LENGTH_MODBUS_BUSBAR * 2; if (istart + icount > this.messageContent.Length) { istart = istart + icount; break; } else { ddb = new ModbusBusbar(this.messageContent.Substring(istart, icount), this); istart = istart + icount; break; } case DeviceData.TYPE_MODBUS15_BUSBAR://光伏阵列汇流箱通讯协议(Modbus)V1.1.1.0-2011.8.30.pdf add by qianhb in 20111220 icount = ProtocolConst.LENGTH_MODBUS15_BUSBAR * 2; if (istart + icount > this.messageContent.Length) { istart = istart + icount; break; } else { ddb = new Modbus15Busbar(this.messageContent.Substring(istart, icount), this); istart = istart + icount; break; } case DeviceData.TYPE_MODBUS17_BUSBAR://光伏汇流箱通信协议(Modbus)V1.7设置定稿.doc add by ZHOUHUI in 20121118 icount = ProtocolConst.LENGTH_MODBUS17_BUSBAR * 2; if (istart + icount > this.messageContent.Length) { istart = istart + icount; break; } else { ddb = new Modbus17Busbar(this.messageContent.Substring(istart, icount), this); istart = istart + icount; break; } case DeviceData.TYPE_MODBUS_CABINET://modbus协议配电柜 icount = ProtocolConst.LENGTH_MODBUS_CABINET * 2; if (istart + icount > this.messageContent.Length) { istart = istart + icount; break; } else { ddb = new ModbusCabinet(this.messageContent.Substring(istart, icount), this); istart = istart + icount; break; } case DeviceData.TYPE_MODBUS16_CABINET://光伏直流配电柜通信协议(Modbus)V1.0-柴达木-2011.8.30.pdf add by qianhb in 20111220 icount = ProtocolConst.LENGTH_MODBUS16_CABINET * 2; if (istart + icount > this.messageContent.Length) { istart = istart + icount; break; } else { ddb = new Modbus16Cabinet(this.messageContent.Substring(istart, icount), this); istart = istart + icount; break; } case DeviceData.TYPE_MODBUS_DETECTOR://设备类型0x22对应的数据区格式,环境检测仪(MODBUS协议) add by qianhb in 20111220 icount = ProtocolConst.LENGTH_MODBUS_DETECTOR * 2; if (istart + icount > this.messageContent.Length) { istart = istart + icount; break; } else { ddb = new ModbusDetector(this.messageContent.Substring(istart, icount), this); istart = istart + icount; break; } case DeviceData.TYPE_MODBUS_DETECTOR_V1020://设备类型0x23对应的数据区格式,环境检测仪(MODBUS协议) add by qianhb in 20120314 icount = ProtocolConst.LENGTH_MODBUS_DETECTOR_1020 * 2; if (istart + icount > this.messageContent.Length) { istart = istart + icount; break; } else { ddb = new ModbusDetector1020(this.messageContent.Substring(istart, icount), this); istart = istart + icount; break; } case DeviceData.TYPE_MODBUS_INVERTER://modbus协议逆变器 icount = ProtocolConst.LENGTH_MODBUS_INVERTER * 2; if (istart + icount > this.messageContent.Length) { istart = istart + icount; break; } else { ddb = new ModbusInverter(this.messageContent.Substring(istart, icount),this); istart = istart + icount; break; } case DeviceData.TYPE_MODBUS_INVERTER03://modbus协议逆变器03,由于03协议只是在02基础上增加数据,前面完全一样,对于新增的数据不处理,所以暂用02协议解析类处理 icount = ProtocolConst.LENGTH_MODBUS_INVERTER03 * 2; if (istart + icount > this.messageContent.Length) { istart = istart + icount; break; } else { ddb = new ModbusInverter03(this.messageContent.Substring(istart, icount), this); istart = istart + icount; break; } case DeviceData.TYPE_SUNGROW_BUSBAR://sungrows协议汇流箱 icount = ProtocolConst.LENGTH_SUNGROW_BUSBAR * 2; if (istart + icount > this.messageContent.Length) { istart = istart + icount; break; } else { ddb = new SungrowBusbar(this.messageContent.Substring(istart, icount), this); istart = istart + icount; break; } case DeviceData.TYPE_SUNGROW_CABINET://sungrows协议配电柜 icount = ProtocolConst.LENGTH_SUNGROW_CABINET * 2; if (istart + icount > this.messageContent.Length) { istart = istart + icount; break; } else { ddb = new SungrowCabinet(this.messageContent.Substring(istart, icount), this); istart = istart + icount; break; } case DeviceData.TYPE_SUNGROW_DETECTOR://sungrow协议检测仪 icount = ProtocolConst.LENGTH_SUNGROW_DETECTOR * 2; if (istart + icount > this.messageContent.Length) { istart = istart + icount; break; } else { ddb = new SungrowDetector(this.messageContent.Substring(istart, icount), this); istart = istart + icount; break; } case DeviceData.TYPE_SUNGROW_INVERTER://sungrow协议逆变器 icount = ProtocolConst.LENGTH_SUNGROW_INVERTER * 2; if (istart + icount > this.messageContent.Length) { istart = istart + icount; break; } else { ddb = new SungrowInverter(this.messageContent.Substring(istart, icount),this); istart = istart + icount; break; } case DeviceData.TYPE_AMMETER://电表协议 icount = ProtocolConst.LENGTH_AMMETER * 2; if (istart + icount > this.messageContent.Length) { istart = istart + icount; break; } else { ddb = new Ammeter(this.messageContent.Substring(istart, icount), this); istart = istart + icount; break; } case DeviceData.TYPE_AMMETER_11://电表协议1.1 icount = ProtocolConst.LENGTH_AMMETER_11 * 2; if (istart + icount > this.messageContent.Length) { istart = istart + icount; break; } else { ddb = new Ammeter11(this.messageContent.Substring(istart, icount), this); istart = istart + icount; break; } default: istart = istart + this.messageContent.Length; break; } if (ddb != null) listTcpbody.Add(ddb); } //取得告警信息 listTcpbug = new List<Bug>(); int faultInfoLength = getFaultInfoLength(); if (this.messageContent.Length > (faultInfoLength + ProtocolConst.LENGTH_HEAD) * 2) { istart = this.messageContent.Length - faultInfoLength * 2 * (this.messageHeader.BugNum); for (int i = 0; i < this.messageHeader.BugNum; i++) { string bugmsg = this.messageContent.Substring(istart + i * faultInfoLength * 2, faultInfoLength * 2); try { Bug tcpb = parseBug(bugmsg); listTcpbug.Add(tcpb); } catch (Exception buge) { LogUtil.error("告警信息解析错误:" +bugmsg+":"+ buge.Message); } } } } else { base.messageHeader = new TcpHeader(); listTcpbody = new List<DeviceDataBase>(); listTcpbug = new List<Bug>(); } }