/// <summary> /// 过滤VIB板卡正常灯位消息 /// </summary> /// <param name="cr"></param> public void ProcessFilter(VIBTestResponse vvr) { if (vvr.ExpectedCode != vvr.RealCode) { FiltedVIBTestResponse fr = new FiltedVIBTestResponse(vvr); rxMsgQueue.Push(fr); } }
public FiltedVIBTestResponse(VIBTestResponse vib) : base() { this.CommunicatinBoard = vib.CommunicatinBoard; this.DtTime = vib.DtTime; this.OriginalBytes = vib.OriginalBytes; this.Board = vib.Board; this.smallCycleBoard = vib.smallCycleBoard; this.LightPos = vib.LightPos; this.ExpectedCode = vib.ExpectedCode; this.RealCode = vib.RealCode; this.ErrorTimes = vib.ErrorTimes; }
public int smallCycleBoard; //小周期号 #endregion Fields #region Methods public override List<BaseResponse> Decode(BasePackage bp, OriginalBytes obytes) { base.Decode(bp, obytes); Cabinet cabinet = SpringHelper.GetObject<Cabinet>("cabinet"); List<BaseResponse> list = new List<BaseResponse>(); Board communicatinBoard = cabinet.GetCommunicationBoard(bp.RemoteIpEndPoint); //应用区数据格式:rack(1)+slot(1)+boardtype(1)+smallcycle(1)+lightport(2) +[采集到的码字(4)*16] +[错误次数(4)*16] if (bp.AppData.Length == 6 + 4 * 16 + 4 * 16) { byte rackNo = bp.AppData[0]; byte slotNo = bp.AppData[1]; byte boardType = bp.AppData[2]; byte smallCycle = bp.AppData[3]; UInt32[] realCodes = new UInt32[16]; Int32[] errorTimes = new Int32[16]; for (int i = 0; i < 16; i++) { realCodes[i] = System.BitConverter.ToUInt32(bp.AppData, 6 + i * 4); errorTimes[i] = System.BitConverter.ToInt32(bp.AppData, 6 + 64 + i * 4); } int a = (int)(((bp.AppData[4] << 8) & 0xFF00) | (bp.AppData[5] & 0x00FF)); byte[] eqId = new byte[] { 0x05, rackNo, slotNo, 0xFF, 0xFF }; //byte[] eqId = GetEqId(rackNo, slotNo); for (int i = 0; i < 16; ++i) { if (((a >> i) & 0x01) == 0x01)//error { //例如 02 04 02 05 01 00 //表示 1 机笼 4槽道 VOB16板卡 01 00 ->0000 0001 0000 0000 : 第9个灯位有问题 int posk = (rackNo - 2) * 12 * 16 + (slotNo - 2) * 16 + i; if (boardType == 0x01)//VIB { VIBTestResponse vibR = new VIBTestResponse(); vibR.CommunicatinBoard = communicatinBoard; vibR.DtTime = DateTime.Now; vibR.OriginalBytes = obytes; vibR.Board = cabinet.FindEq(eqId) as Board; vibR.Board.BoardType = "VIB"; vibR.LightPos = i + 1; vibR.ExpectedCode = Util.vib_true[posk]; vibR.RealCode = realCodes[i]; vibR.ErrorTimes = errorTimes[i]; int readableSmallCycle = (int)smallCycle + 1; vibR.smallCycleBoard = readableSmallCycle; list.Add(vibR); } else if (boardType == 0x02)//VOB { VOBTestResponse vobR = new VOBTestResponse(); vobR.CommunicatinBoard = communicatinBoard; vobR.DtTime = DateTime.Now; vobR.OriginalBytes = obytes; vobR.Board = cabinet.FindEq(eqId) as Board; vobR.Board.BoardType = "VOB"; vobR.LightPos = i + 1; vobR.RealCode = realCodes[i]; vobR.ErrorTimes = errorTimes[i]; byte[] cycleNo = new byte[2]; Array.Copy(obytes.Data, 3, cycleNo, 0, 2);//帧协议中周期号四个字节中的低两位作为是否有输出 uint value = (uint)(((cycleNo[0] << 8) & 0xFF00) | (cycleNo[1] & 0x00FF)); int readableSmallCycle = (int)smallCycle; vobR.smallCycleBoard = readableSmallCycle; if (((value >> i) & 0x01) == 0x01)//有输出 { //VOB板卡第i个灯位错误,且当前灯位亮的状态(有输出) vobR.OutPut = true; vobR.ErrorCode = false; if (readableSmallCycle == 2) { vobR.ExpectedCode = Util.vob_ock_even[posk]; vobR.OCK = true; } else if (readableSmallCycle == 0 || readableSmallCycle == 4 || readableSmallCycle == 6 || readableSmallCycle == 8) { vobR.ExpectedCode = Util.vob_true_even; vobR.OCK = false; } else if (readableSmallCycle == 1) { vobR.ExpectedCode = Util.vob_ock_odd[posk]; vobR.OCK = true; } else if (readableSmallCycle == 3 || readableSmallCycle == 5 || readableSmallCycle == 7 || readableSmallCycle == 9) { vobR.ExpectedCode = Util.vob_true_odd; vobR.OCK = false; } } else { //当前的灯位灭的状态(无输出) vobR.OutPut = false; vobR.ErrorCode = true; if (readableSmallCycle == 0 || readableSmallCycle == 2 || readableSmallCycle == 4 || readableSmallCycle == 6 || readableSmallCycle == 8) { vobR.ExpectedCode = Util.vob_ckWord_even[posk]; } else if (readableSmallCycle == 1 || readableSmallCycle == 3 || readableSmallCycle == 5 || readableSmallCycle == 7 || readableSmallCycle == 9) { vobR.ExpectedCode = Util.vob_ckWord_odd[posk]; } } list.Add(vobR); } } } } return list; }
//编码工厂 public void ExecuteInternal() { List<BaseRequest> list = txMsgQueue.PopAll(); foreach (var br in list) { if (br is ShakeRequest) { ShakeResponse sr = new ShakeResponse(); sr.CommunicatinBoard = (br as ShakeRequest).Board; sr.DtTime = DateTime.Now; isFctRunning = false; rxFctMsgQueue.Push(sr); rxGeneralMsgQueue.Push(sr); rxSelfMsgQueue.Push(sr); } else if (br is StartFctRequest) { isFctRunning = true; } else if (br is StopFctRequest) { isFctRunning = true; StopFctTestResponse sr = new StopFctTestResponse(); sr.CommunicatinBoard = (br as StopFctRequest).Board; sr.DtTime = DateTime.Now; isFctRunning = false; rxFctMsgQueue.Push(sr); } else if (br is StartGeneralTestRequest) { isGeneralRunning = true; } else if (br is StopFctRequest) { isGeneralRunning = false; } } if (isFctRunning || isGeneralRunning) { //周期性的送心跳 HeartMsg msg1 = new HeartMsg(); msg1.CommunicatinBoard = cabinet.Racks[0].Boards[0]; msg1.DtTime = DateTime.Now; rxFctMsgQueue.Push(msg1); rxGeneralMsgQueue.Push(msg1); rxSelfMsgQueue.Push(msg1); HeartMsg msg2 = new HeartMsg(); msg2.CommunicatinBoard = cabinet.Racks[0].Boards[3]; msg2.DtTime = DateTime.Now; rxFctMsgQueue.Push(msg2); rxGeneralMsgQueue.Push(msg2); rxSelfMsgQueue.Push(msg2); } if (isFctRunning || isGeneralRunning) { //周期性送错误码子 { ComponentTestResponse cr1 = new ComponentTestResponse(); cr1.CommunicatinBoard = cabinet.Racks[0].Boards[0]; cr1.Component = cabinet.Racks[0].Boards[0].ComponentTypes[0].Components[2]; cr1.Component.AllTestTimes++; cr1.Component.ErrorPackageTimes++; cr1.DtTime = DateTime.Now; rxFctMsgQueue.Push(cr1); rxGeneralMsgQueue.Push(cr1); rxSelfMsgQueue.Push(cr1); } { ComponentTestResponse cr1 = new ComponentTestResponse(); cr1.CommunicatinBoard = cabinet.Racks[0].Boards[0]; cr1.Component = cabinet.Racks[0].Boards[0].ComponentTypes[1].Components[0]; cr1.Component.AllTestTimes++; cr1.Component.LostPackageTimes++; cr1.DtTime = DateTime.Now; rxFctMsgQueue.Push(cr1); rxGeneralMsgQueue.Push(cr1); rxSelfMsgQueue.Push(cr1); } { ComponentTestResponse cr1 = new ComponentTestResponse(); cr1.CommunicatinBoard = cabinet.Racks[0].Boards[0]; cr1.Component = cabinet.Racks[0].Boards[0].ComponentTypes[1].Components[1]; cr1.Component.AllTestTimes++; cr1.DtTime = DateTime.Now; rxFctMsgQueue.Push(cr1); rxGeneralMsgQueue.Push(cr1); rxSelfMsgQueue.Push(cr1); } { ComponentTestResponse cr1 = new ComponentTestResponse(); cr1.CommunicatinBoard = cabinet.Racks[0].Boards[3]; cr1.Component = cabinet.Racks[0].Boards[3].ComponentTypes[0].Components[0]; cr1.Component.AllTestTimes++; cr1.DtTime = DateTime.Now; rxFctMsgQueue.Push(cr1); rxGeneralMsgQueue.Push(cr1); rxSelfMsgQueue.Push(cr1); } } if (isGeneralRunning) { VIBTestResponse vr1 = new VIBTestResponse(); vr1.Board = cabinet.Racks[2].Boards[2]; vr1.CommunicatinBoard = cabinet.Racks[0].Boards[3]; vr1.DtTime = DateTime.Now; vr1.ErrorTimes = 0; vr1.LightPos = 10; vr1.ExpectedCode = 0xEAB10499; vr1.RealCode = 0xEAB10499; rxGeneralMsgQueue.Push(vr1); rxSelfMsgQueue.Push(vr1); VIBTestResponse vr2 = new VIBTestResponse(); vr2.Board = cabinet.Racks[2].Boards[2]; vr2.CommunicatinBoard = cabinet.Racks[0].Boards[3]; vr2.DtTime = DateTime.Now; vr2.ErrorTimes++; vr2.LightPos = 11; vr2.ExpectedCode = 0xEAB10499; vr2.RealCode = 0xEAB10498; rxGeneralMsgQueue.Push(vr2); rxSelfMsgQueue.Push(vr2); } }