//protected override bool OnLock(Route route) //{ // return true; //} //protected override bool OnUnlock(Route route) //{ // return true; //} protected override int OnPrepare(Routes.Route route, int port, PollTask initiator) { route.Subscribe(this, (bytes, dir) => { log.Trace(string.Format("[{0}] {1} [{2}]", GetName(), dir == Routes.Direction.FromInitiator ? "->" : "<-", string.Join(",", bytes.Select(b => b.ToString("X2"))))); route.Send(this, bytes, dir); }); return(Codes.SUCCESS); }
protected override int OnPrepare(Routes.Route route, int port, PollTask initiator) { var isOpen = false; route.Subscribe(this, (bytes, dir) => { if (dir == Routes.Direction.ToInitiator) { ParsePackage(bytes, pack => { if (!pack.success) { log.Debug(string.Format("ошибка при обработке данных в свитче: {0}", pack.error)); return; } if (pack.channel != port) { return; } if (pack.cmd == 3) { byte[] clear = pack.body; log.Debug(string.Format("[Switch] {0} {1}", dir == Routes.Direction.FromInitiator ? "->" : "<-", string.Join(",", clear.Select(b => b.ToString("X2"))))); route.Send(this, clear, dir); } //0x00 - OK; 0x82 - другой порт открыт?; 0x83 - порт УЖЕ открыт - OK if (pack.cmd == 1 && (pack.body[0] == 0x00 || pack.body[0] == 0x83 || pack.body[0] == 0x82)) { log.Debug(string.Format("[Switch] порт {0} открыт", port)); isOpen = true; } }); } else { byte[] pack = MakePackage(GetNA(), (byte)port, 0x02, bytes); route.Send(this, pack, dir); log.Trace(string.Format("[Switch] {0} {1}", dir == Routes.Direction.FromInitiator ? "->" : "<-", string.Join(",", pack.Select(b => b.ToString("X2"))))); } }); //команда на открытие порта route.Send(this, MakePackage(GetNA(), (byte)port, 0x01, new byte[] { }), Routes.Direction.FromInitiator); var tmt = 5000; while (!isOpen && tmt > 0) { tmt -= 100; Thread.Sleep(100); } if (isOpen) { log.Debug("свитч порт открыт"); } else { log.Debug("свитч порт закрыт"); } return(isOpen ? Codes.SUCCESS : Codes.MATRIX_NOT_CONNECTED); }