public Switch(int pins) : base(pins == 1 ? 6 : pins) { SwitchPins = pins; SwitchState = Enumerable.Repeat(false, pins == 1 ? 1 : pins / 2).ToArray(); SwitchType = SwitchTypes.Momentary; IcType = ICType.ic4; ModelName = "momentary_switch"; WriteToNodes = false; }
//given the occupancy of the three blocks, the switch determines whether it should change or not //this boolean expression should be changeable by the PLC program!!!! later //changing to directions! positive number means train heading towards switch from that direction //this function assumes a unidirectional source, t1, and t2 but can easily be extrapolated to bidirectional given public int?determineSwitchState(Switch sw, int?s, int?t1, int?t2) { Console.WriteLine("Determining switch : " + sw.switchId + " - " + switchTypes[sw].ToString()); Console.WriteLine(s + " : " + t1 + " : " + t2); //Switch sw = switches.Find(x => x.switchId == switchId); SwitchTypes type = switchTypes[sw]; if (s == null) { s = 0; } if (t1 == null) { t1 = 0; } if (t2 == null) { t2 = 0; } switch (type) { case SwitchTypes.Loop1: return(Loop1(sw, s, t1, t2)); case SwitchTypes.Loop2: return(Loop2(sw, s, t1, t2)); case SwitchTypes.BiLoop: return(BiLoop(sw, s, t1, t2)); case SwitchTypes.SplitIn: return(SplitIn(sw, s, t1, t2)); case SwitchTypes.SplitOut: return(SplitOut(sw, s, t1, t2)); default: return(-1); } }
//id is switch id //which branch determines whether source, t1, or t2 is to be gotten public int?getSwitchDirection(Switch sw, int whichBranch) { //Switch sw = switches.Find(x => x.switchId == id); SwitchTypes type = switchTypes[sw]; if (whichBranch > 2 || whichBranch < 0) { return(null); } switch (type) { case SwitchTypes.Loop1: if (whichBranch == 0) { return(0); } else if (whichBranch == 1) { return(-1); } else if (whichBranch == 2) { return(1); } break; case SwitchTypes.Loop2: if (whichBranch == 0) { return(0); } else if (whichBranch == 1) { return(1); } else if (whichBranch == 2) { return(-1); } break; case SwitchTypes.BiLoop: if (whichBranch == 0) { return(0); } else if (whichBranch == 1) { return(0); } else if (whichBranch == 2) { return(0); } break; case SwitchTypes.SplitIn: if (whichBranch == 0) { return(-1); } else if (whichBranch == 1) { return(1); } else if (whichBranch == 2) { return(1); } break; case SwitchTypes.SplitOut: if (whichBranch == 0) { return(1); } else if (whichBranch == 1) { return(-1); } else if (whichBranch == 2) { return(-1); } break; default: return(null); } return(null); }