Beispiel #1
0
        public CarScheduler(Dictionary <string, Station> sDic, Dictionary <string, Track> tDic, AdjacencyList adj)
        {
            stationDic    = sDic;
            trackDic      = tDic;
            adjList       = adj;
            gStartStation = stationDic["F28"];
            stationList1  = new List <Station>(8);
            stationList1.Add(stationDic["F28"]);

            rStartStation = stationDic["F29"];
            stationList2  = new List <Station>(8);
            stationList2.Add(stationDic["F29"]);

            pStartStation = stationDic["F30"];
            stationList3  = new List <Station>(8);
            stationList3.Add(stationDic["F30"]);

            goStartStation = stationDic["F31"];
            stationList4   = new List <Station>(8);
            stationList4.Add(stationDic["F31"]);
            carQueues[5]     = greenCarQueue;
            carQueues[6]     = redCarQueue;
            carQueues[7]     = pinkCarQueue;
            carQueues[8]     = goldCarQueue;
            carTaskQueues[5] = new Queue <CarTask>(10);
            carTaskQueues[6] = new Queue <CarTask>(10);
            carTaskQueues[7] = new Queue <CarTask>(10);
            carTaskQueues[8] = new Queue <CarTask>(10);
        }
Beispiel #2
0
        public byte planRoadTable(byte carID, Station startStation, Station targetStation, Station endStation, AdjacencyList adj, SerialPort sp, Dictionary <string, Station> stationDic)
        {
            List <Track> list1   = adj.FindWay(adj.Find(startStation), adj.Find(targetStation));
            List <Track> list2   = adj.FindWay(adj.Find(targetStation), adj.Find(stationDic["F32"]));
            List <Track> list3   = adj.FindWay(adj.Find(stationDic["F32"]), adj.Find(endStation));
            List <byte>  command = new List <byte>();

            for (int i = 0; i < list1.Count; ++i)
            {
                if (list1[i].CarAction != null)
                {
                    string station = list1[i].CarAction.Substring(0, list1[i].CarAction.IndexOf('G'));
                    command.Add((byte)stationDic[station].CardID);
                    switch (list1[i].CarAction.Substring(list1[i].CarAction.Length - 1, 1))
                    {
                    case "L":
                        command.Add((byte)(0x50));
                        break;

                    case "R":
                        command.Add((byte)(0x51));
                        break;

                    case "S":
                        command.Add((byte)(0x52));
                        break;
                    }
                }
            }
            command.Add((byte)stationDic[targetStation.Name].CardID);
            command.Add((byte)(0x53));
            for (int i = 0; i < list2.Count; ++i)
            {
                if (list2[i].CarAction != null)
                {
                    string station = list2[i].CarAction.Substring(0, list2[i].CarAction.IndexOf('G'));
                    command.Add((byte)stationDic[station].CardID);
                    switch (list2[i].CarAction.Substring(list2[i].CarAction.Length - 1, 1))
                    {
                    case "L":
                        command.Add((byte)(0x50));
                        break;

                    case "R":
                        command.Add((byte)(0x51));
                        break;

                    case "S":
                        command.Add((byte)(0x52));
                        break;
                    }
                }
            }
            command.Add((byte)stationDic["F32"].CardID);
            command.Add((byte)(0x53));
            for (int i = 1; i < list3.Count; ++i)
            {
                if (list3[i].CarAction != null)
                {
                    string station = list3[i].CarAction.Substring(0, list3[i].CarAction.IndexOf('G'));
                    command.Add((byte)stationDic[station].CardID);
                    switch (list3[i].CarAction.Substring(list3[i].CarAction.Length - 1, 1))
                    {
                    case "L":
                        command.Add((byte)(0x50));
                        break;

                    case "R":
                        command.Add((byte)(0x51));
                        break;

                    case "S":
                        command.Add((byte)(0x52));
                        break;
                    }
                }
            }
            command.Add((byte)stationDic[endStation.Name].CardID);
            command.Add((byte)(0x53));
            if (command.Count >= 4 && command.Count <= 20)
            {
                byte CardCount = (byte)(command.Count >> 1);
                command.Insert(0, CardCount);
                command.Insert(0, CardCount);
                command.Insert(0, (byte)0);
                command.Insert(0, (byte)(carID));
                command.Insert(0, (byte)0);
                command.Insert(0, (byte)0);
                command.Insert(0, (byte)(CardCount * 2 + 4));
                command.Insert(0, (byte)0xe6);
                command.Add(checksum(command));
                command.Insert(0, (byte)0x68);
                byte[] roadTable = new byte[command.Count];
                command.CopyTo(roadTable);

                //for (int j = 0; j < roadTable.Length; ++j)
                //{
                //    Console.Write(roadTable[j] + " ");
                //}
                sp.Write(roadTable, 0, roadTable.Length);

                return(CardCount);
            }
            else if (command != null && 20 < command.Count && command.Count <= 40)
            {
                byte total       = (byte)(command.Count >> 1);
                byte CardAccount = (byte)(command.Count >> 1);
                command.Insert(0, (byte)10);
                command.Insert(0, total);
                command.Insert(0, (byte)0);
                command.Insert(0, carID);
                command.Insert(0, (byte)0);
                command.Insert(0, (byte)0);
                command.Insert(0, (byte)(24));
                command.Insert(0, (byte)0xe6);
                byte csum = checksum(command, 28);
                command.Insert(0, (byte)0x68);
                byte[] roadTable = new byte[30];
                command.CopyTo(0, roadTable, 0, 29);
                roadTable[29] = (byte)(csum);

                //for (int j = 0; j < 30; ++j)
                //{
                //    Console.Write(roadTable[j] + " ");
                //}
                //Console.WriteLine();
                //roadTable[12] = (byte)0x50;
                //roadTable[18] = (byte)0x50;
                //roadTable[26] = (byte)0x50;
                //roadTable[28] = (byte)0x50;
                sp.Write(roadTable, 0, 30);
                Thread.Sleep(5000);
                command.RemoveRange(0, 29);
                CardAccount = (byte)(command.Count / 2);
                command.Insert(0, CardAccount);
                command.Insert(0, total);
                command.Insert(0, (byte)0x0a);
                command.Insert(0, carID);//bug
                command.Insert(0, (byte)0);
                command.Insert(0, (byte)0);
                command.Insert(0, (byte)(CardAccount * 2 + 4));
                command.Insert(0, (byte)0xe6);
                command.Add(checksum(command));
                command.Insert(0, (byte)0x68);
                roadTable = new byte[command.Count];
                command.CopyTo(roadTable);
                //for (int j = 0; j < roadTable.Length; ++j)
                //{
                //    Console.Write(roadTable[j] + " ");
                //}
                sp.Write(roadTable, 0, roadTable.Length);

                return(total);
            }
            else if (command != null && 56 < command.Count && command.Count <= 84)
            {
                byte total       = (byte)(command.Count >> 1);
                byte CardAccount = (byte)(command.Count >> 1);
                command.Insert(0, (byte)14);
                command.Insert(0, total);
                command.Insert(0, (byte)0);
                command.Insert(0, carID);
                command.Insert(0, (byte)0);
                command.Insert(0, (byte)0);
                command.Insert(0, (byte)(32));
                command.Insert(0, (byte)0xe6);
                //command.Add(checksum(command));
                byte csum = checksum(command, 36);
                command.Insert(0, (byte)0x68);
                byte[] roadTable = new byte[38];
                command.CopyTo(0, roadTable, 0, 37);
                roadTable[37] = csum;
                for (int j = 0; j < 38; ++j)
                {
                    Console.Write(roadTable[j] + " ");
                }
                Console.WriteLine();
                sp.Write(roadTable, 0, 38);
                command.RemoveRange(0, 37);
                Console.WriteLine();
                command.Insert(0, (byte)14);
                command.Insert(0, total);
                command.Insert(0, (byte)0x26);
                command.Insert(0, carID);
                command.Insert(0, (byte)0);
                command.Insert(0, (byte)0);
                command.Insert(0, (byte)(32));
                command.Insert(0, (byte)0xe6);
                //command.Add(checksum(command));
                csum = checksum(command, 36);
                command.Insert(0, (byte)0x68);
                roadTable = new byte[38];
                command.CopyTo(0, roadTable, 0, 37);
                roadTable[37] = csum;
                for (int j = 0; j < 38; ++j)
                {
                    Console.Write(roadTable[j] + " ");
                }
                Console.WriteLine();
                sp.Write(roadTable, 0, 38);
                command.RemoveRange(0, 37);
                CardAccount = (byte)(command.Count >> 1);
                command.Insert(0, CardAccount);
                command.Insert(0, total);
                command.Insert(0, (byte)0x4c);
                command.Insert(0, carID);
                command.Insert(0, (byte)0);
                command.Insert(0, (byte)0);
                command.Insert(0, (byte)(CardAccount * 2 + 4));
                command.Insert(0, (byte)0xe6);
                command.Add(checksum(command));
                command.Insert(0, (byte)0x68);
                roadTable = new byte[command.Count];
                command.CopyTo(roadTable);
                for (int j = 0; j < roadTable.Length; ++j)
                {
                    Console.Write(roadTable[j] + " ");
                }
                sp.Write(roadTable, 0, roadTable.Length);
                return(0);
            }
            return(0);
        }