MushinyManager.cs 85.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100
using AGVLib;
using CtuDeviceLib.model;
using Mushiny;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Windows.Forms;

namespace CtuDeviceLib
{
    public class MushinyManager
    {
        public static string WarnMsgSummary = "";
        public static string WarnMsgDetails = "";
        static string appPath = System.Windows.Forms.Application.StartupPath;
        public static string FinishedCTUName = "原材料运输";
        public static string SemiFinishedCTUName = "半成品运输";
        /// <summary>
        /// 出料机构工单出库执行的最低层数
        /// </summary>
        public static int OutEquipOutStoreMinRow = 1;
        /// <summary>
        /// 出料机构工单任务切换到手动线
        /// </summary>

        public static bool OutEquipStoreSwitchToManualLine = false;
        /// <summary>
        /// 出料机构手动线切换到工单任务
        /// </summary>
        public static bool OutEquipManualSwitchToOutLine = false;

        /// <summary>
        /// 屏蔽呼叫
        /// </summary>
        public static bool DisableCallAGV = false;
        /// <summary>
        /// 当前机器人类型
        /// 2=半成品
        /// 3=原材料
        /// </summary>
        public static int CurRobotType = ConfigAppSettings.GetValue("CurRobotType", 3);
        /// <summary>
        /// 3=原材料
        /// </summary>
        public static int FinishedCTUIndex = 3;
        /// <summary>
        /// 2=半成品
        /// </summary>
        public static int SemiFinishedCTUIndex = 2;

        /// <summary>
        /// 启用异常ctu转移
        /// </summary>
        public static bool EnableCheckEnabledCtuIsOk { get { return ConfigAppSettings.GetValue(Mushiny.Common.Mushiny_ + "EnableCheckEnabledCtuIsOk", true); } }
        /// <summary>
        /// 异常转移等待时间
        /// </summary>
        public static int TaskTransWaitMinute { get { return ConfigAppSettings.GetValue(Mushiny.Common.Mushiny_ + "TaskTransWaitMinute", 10); } }

        public static int RePlaneWaitSeconds { get { return ConfigAppSettings.GetValue(Mushiny.Common.Mushiny_ + "RePlaneWaitSeconds", 15); } }

        public static bool EnableAutoRePlane { get { return ConfigAppSettings.GetValue(Mushiny.Common.Mushiny_ + "EnableAutoRePlane", false); } }

        public static bool UseBuff { get { return ConfigAppSettings.GetValue("Buff_Enable", false); } }

        /// <summary>
        /// 启用手动出库优先
        /// </summary>
        public static bool EnableManualFirst { get { return ConfigAppSettings.GetValue("Enable_ManualOutstoreFirst", false); } }

        /// <summary>
        /// 出料机构 出库最多数量
        /// </summary>
        public static int OutEquipMaxOutCnt { get { return ConfigAppSettings.GetValue(Mushiny.Common.Mushiny_ + "OutEquipMaxOutCnt", 4); } }
        /// <summary>
        /// 出入库模式--半成品使用
        /// 0=均衡
        /// 1=优先入库
        /// 2=优先出库
        /// </summary>
        public static int InOutMode
        {
            get { return ConfigAppSettings.GetIntValue(Mushiny.Common.Mushiny_ + "InOutMode", 0); }
            set
            {
                ConfigAppSettings.SaveValue(Mushiny.Common.Mushiny_ + "InOutMode", value);
                LogUtil.info($"设置出入库模式为【{value}】【0=均衡,1=优先入库,2=优先出库】");
            }
        }
        public static string ServerBase
        {
            get
            {
                if (MushinyManager.CurRobotType == MushinyManager.FinishedCTUIndex)
                {
                    return ConfigAppSettings.GetValue(Setting_Init.http_server, "http://10.68.27.83/smf-core/");
                }
                else if (MushinyManager.CurRobotType == MushinyManager.SemiFinishedCTUIndex)
                {
                    return ConfigAppSettings.GetValue(Setting_Init.http_server, "http://10.68.27.86/smf-core/");
                }
                else
                {
                    return ConfigAppSettings.GetValue(Setting_Init.http_server, "http://localhost/smf-core/");
                }
            }
        }
        /// <summary>
        /// 加载配置
        /// </summary>
        public static void Load()
        {
            CTUManager.Init();
            Init();
            loadCtuScopes();
        }

        #region 待机点

        //public static CtuStandby GetIdleCtuStand(List<PathWay> usedPathway)
        //{
        //    if (ctuStandbies == null || ctuStandbies.Count == 0)
        //    {
        //        return ctuStandbies.Find(s => !s.IsOccupied());
        //    }
        //    var usedPoints = ctuBean.GetAllUsedPoint();
        //    foreach (var item in ctuStandbies)
        //    {
        //        if (!string.IsNullOrEmpty(item.StandbyGroup)) continue;//固定待机点,不使用
        //        if (item.IsOccupied()) continue;
        //        if (usedPoints.Contains(item.PointCode)) continue;//待机点被占用,不分配
        //        var find = usedPathway?.Find(s => s.Paths.Contains(item.PointCode));
        //        if (find == null)//当前待机点未被占用
        //        {
        //            return item;
        //        }
        //    }
        //    return null;
        //}

        /// <summary>
        /// 获取其他ctu占用的路线
        /// </summary>
        /// <param name="ctu"></param>
        /// <returns></returns>
        //public static List<PathWay> GetOtherCtuUsedPaths(CTU ctu)
        //{
        //    var usedPathways = new List<PathWay>();
        //    var busyCtus = ctuBean.GetCTUs();
        //    if (busyCtus != null)
        //    {
        //        busyCtus.ForEach(s =>
        //        {
        //            if (ctu.IP.Equals(s.IP))
        //            {

        //            }
        //            else
        //            {
        //                var path = PathWays.GetPathWay(s.CurLandMark);
        //                if (path != null)
        //                {
        //                    usedPathways.Add(path);
        //                }
        //                //当前ctu目的所在路线是否占用
        //                var find = RunningCtuRealtimeInfos.Find(ss => s.IP.Equals(ss.Ctu.IP));
        //                if (find != null && find.DstPosInfo != null)
        //                {
        //                    path = PathWays.GetPathWay(find.DstPosInfo.PointCode);
        //                    if (path != null)
        //                    {
        //                        usedPathways.Add(path);
        //                    }
        //                }
        //            }

        //        });
        //    }
        //    return usedPathways;
        //}







        //    return ctuStandby != null;
        //}



        /// <summary>
        /// 查找路径距离
        /// </summary>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="barriers"></param>
        /// <param name="dis"></param>
        /// <returns></returns>
        //public static bool FindPathDis(PointCode start, PointCode end, List<PointCode> barriers, out int dis)
        //{
        //    dis = 0;
        //    if (start == null || end == null) return false;
        //    var startPoint = new AStartPoint(start);
        //    var endPoint = new AStartPoint(end);
        //    List<AStartPoint> barrierPoints = null;
        //    if (barriers != null && barriers.Count > 0)
        //    {
        //        barrierPoints = new List<AStartPoint>();
        //        barriers.ForEach(s =>
        //        {
        //            var asp = new AStartPoint(s);
        //            barrierPoints.Add(asp);
        //        });
        //    }
        //    var rtnPoint = ctuBean.AStart.FindPath(startPoint, endPoint, barrierPoints);
        //    if (rtnPoint == null) return false;
        //    dis = rtnPoint.F;
        //    return true;
        //}
        /// <summary>
        /// 获取起始到目标的点顺序
        /// </summary>
        /// <param name="curCtu"></param>
        /// <param name="src"></param>
        /// <param name="dst"></param>
        /// <param name="pointCodes"></param>
        /// <param name="useBarrier"></param>
        /// <returns></returns>
        //public static bool GetPointsBySrcDst(CTU curCtu, uint src, uint dst, out List<PointCode> pointCodes, bool useBarrier = true)
        //{
        //    return ctuBean.GenPointsBySrcDst(curCtu, src, dst, out pointCodes, useBarrier);
        //}
        ///// <summary>
        ///// 检查是否存在可到达的路线点
        ///// </summary>
        ///// <param name="curCtu"></param>
        ///// <param name="src"></param>
        ///// <param name="dst"></param>
        ///// <param name="useBarrier"></param>
        ///// <returns></returns>
        //public static bool CheckHasPathFromSrcToDst(CTU curCtu, uint src, uint dst, bool useBarrier = true)
        //{
        //    return ctuBean.CheckPointsBySrcDst(curCtu, src, dst, out List<PointCode> pointCodes, useBarrier);
        //}
        /// <summary>
        /// 获取指定待机点组的待机点
        /// </summary>
        /// <param name="standGroup"></param>
        /// <returns></returns>




        /// <summary>
        /// 检查当前地码所在的巷道是否将被使用(已有ctu接任务过来)
        /// </summary>
        /// <param name="pointCode"></param>
        /// <returns></returns>
        //public static bool CheckIsCurLaneWillBeUsed(uint pointCode)
        //{
        //    var find = ctuBean.PosInfos.Find(s => s.PointCode == pointCode);
        //    if (find != null)
        //    {
        //        var lane = find.Lanway;
        //        var allTasks = TaskManager.GetAllTasks();
        //        foreach (var item in allTasks)
        //        {
        //            if (item.TaskState >= RobotTaskState.已分配车)
        //            {
        //                if (item.TaskType == RobotTaskType.Insotre)
        //                {
        //                    var tarname = item.DestPoint;
        //                    var tarInfo = ctuBean.GetPosInfoByName(tarname);
        //                    if (tarInfo.Lanway == lane)
        //                    {
        //                        return true;
        //                    }
        //                }
        //                else if (item.TaskType == RobotTaskType.Outstore)
        //                {
        //                    var tarname = item.SrcPoint;
        //                    var tarInfo = ctuBean.GetPosInfoByName(tarname);
        //                    if (tarInfo.Lanway == lane)
        //                    {
        //                        return true;
        //                    }
        //                }
        //            }

        //        }
        //    }
        //    return false;
        //}
        #endregion

        #region 出料机构区域逻辑
        /// <summary>
        /// 启用出料机构根据区域
        /// </summary>
        public static bool Enable_OutEquipByScope { get { return ConfigAppSettings.GetValue("Enable_OutEquipByScope", false); } }
        /// <summary>
        /// 加载待机点信息
        /// </summary>
        static void loadCtuScopes()
        {
            if (CurRobotType == 2) return;
            {
                var laneways = new List<string>();

                PosInfos.GetAllPosInfos().ForEach(s =>
                {
                    if (s.Lanway.StartsWith("0") || s.Lanway.StartsWith("1"))
                    {

                    }
                    else
                    {
                        if (!laneways.Contains(s.Lanway))
                        {
                            laneways.Add(s.Lanway);
                        }
                    }
                });

                for (int i = 1; i < 7; i++)
                {
                    var outTmp = new CtuScope("outLine0" + i);
                    outTmp.OutEquipNames.Add($"outLine0{i}_in");
                    outTmp.OutEquipNames.Add($"outLine0{i}_out");
                }
                setCtuScopeInfo();
            }
        }
        public static void setCtuScopeInfo()
        {
            // if (CurRobotType == 2) return;
            //ConfigAppSettings.SaveValue(Mushiny.Common.Mushiny_ + "CtuScopes", JsonHelper.SerializeObject(CtuScopes));
        }
        public static CtuScope GetScopeByCtu(string ctuName)
        {
            return GetCtuScopes().Find(s => ctuName.Equals(s.CtuName));
        }
        public static CtuScope GetScopeByEquipName(string equipName)
        {
            return GetCtuScopes().Find(s => s.OutEquipNames.Contains(equipName));
        }
        public static CtuScope GetScopeByLaneCode(string lanCode)
        {
            return GetCtuScopes().Find(s => s.LaneCodes.Contains(lanCode));
        }
        public static List<CtuScope> GetCtuScopes()
        {
            return CtuScope.ctuScopes;
        }
        #endregion


        public static void Init()
        {
            try
            {

                string linefilePath = appPath + $"/CtuService/Config/CSV/CTU/tbl_landmarks.csv";
                LandMarks.Load(linefilePath);

                linefilePath = appPath + $"/CtuService/Config/CSV/CTU/tbl_shelves.csv";
                PosInfos.Load(linefilePath);



                linefilePath = appPath + $"/CtuService/Config/CSV/CTU/tbl_pathways.csv";
                PathWays.Load(linefilePath);
            }
            catch (Exception ex)
            {
                LogUtil.error("加载CTU配置异常", ex);
            }

        }

        /// <summary>
        /// 获取路线的关键点
        /// </summary>
        /// <param name="pathWay">路线</param>
        /// <returns></returns>
        static List<uint> getKeyPointIds(PathWay pathWay, bool isSrc)
        {
            if (pathWay == null || pathWay.Paths == null) return new List<uint>();
            int idx = pathWay.Paths.Count - 1;
            if (pathWay.IsTwoWayLanes)
            {
                return new List<uint> { pathWay.Paths[0], pathWay.Paths[idx] };
            }
            else
            {
                if (isSrc)
                {
                    return new List<uint> { pathWay.Paths[0] };
                }
                else
                {
                    return new List<uint> { pathWay.Paths[idx] };
                }
            }
        }



        /// <summary>
        /// 移动速度
        /// </summary>
        static byte moveSpeed { get { return (byte)ConfigHelper.Config.Get(Mushiny.Common.Mushiny_ + "MoveSpeed", 1); } }
        /// <summary>
        /// 在巷道统一车头朝右(货叉一侧)
        /// </summary>
        static short ctuHeadAngleAtLane = ConfigAppSettings.GetValue(Mushiny.Common.Mushiny_ + "HeadAngleAtLane", (short)270);
        /// <summary>
        /// 是否检查料箱定位码
        /// </summary>
        static bool CheckContainerLocCode { get { return ConfigAppSettings.GetValue(Mushiny.Common.Mushiny_ + "CheckContainerLocCode", false); } }

        #region 生成路径点
        /// <summary>
        /// 是否可以旋转
        /// </summary>
        /// <param name="pointCode"></param>
        /// <returns></returns>
        static bool canXunzhuan(PointCode pointCode)
        {
            if (pointCode.Type == LandmarkType.Turning) return false;
            if (pointCode.Type == LandmarkType.Shelves) return false;
            var codeInPath = PathWays.GetPathWay(pointCode.Id);
            if (codeInPath != null) return false;

            return true;
        }
        /// <summary>
        /// 生成CTU移动的路径点
        /// </summary>
        /// <param name="ctu"></param>
        /// <param name="pointCodes"></param>
        /// <param name="pathPoints"></param>
        /// <returns></returns>
        public static bool GenMovePathPoints(CTU ctu, List<PointCode> pointCodes, out List<PathPoint> pathPoints,out string errmsg)
        {
            errmsg = "";
            pathPoints = new List<PathPoint>();
            if (pointCodes == null || pointCodes.Count == 0)
            {
                errmsg = "移动点数量为0";
                return false;
            }
            //ctu最新角度
            var ctuLastDir = ctu.CurDir;
            bool isForkInDown = false;
            //目标点
            var targetPoint = pointCodes.Last();
            if (pointCodes.Count > 2)
            {
                var first = pointCodes[0];

                if (first.Type != LandmarkType.Shelves)//在货架里面不降到最低
                {
                    short upHeight = (short)ConfigAppSettings.GetIntValue(Mushiny.Common.Mushiny_ + "DefaultUpdownHeight", 250);
                    var preAction = PathPoint.GenReadyToPutToShelves(pointCodes[0].Id, 1, upHeight);
                    pathPoints.Add(preAction);
                    isForkInDown = true;
                }

            }
            if (pointCodes.Count == 1)//当前点就是目标点
            {
                pathPoints.Add(PathPoint.Add(ActionCode.整个路径结束, pointCodes[0].Id, 0, 0));
                return true;
            }
            else if (pointCodes.Count == 2)//移动一个距离
            {
                var firstPoint = pointCodes[0];
                var second = pointCodes[1];
                if (firstPoint.Type == LandmarkType.Turning)
                {
                    var angle = firstPoint.GetAngle(second.Id);
                    var dis = firstPoint.GetDis(second.Id);
                    if (second.Type == LandmarkType.Docking_0)
                    {
                        if (ctuLastDir != 0)
                            pathPoints.Add(PathPoint.GenTurn(firstPoint.Id, 0));
                        ctuLastDir = 0;
                    }
                    else if (second.Type == LandmarkType.Docking_90)
                    {
                        if (ctuLastDir != 90)
                            pathPoints.Add(PathPoint.GenTurn(firstPoint.Id, 90));
                        ctuLastDir = 90;
                    }
                    else if (second.Type == LandmarkType.Docking_180)
                    {
                        if (ctuLastDir != 180)
                            pathPoints.Add(PathPoint.GenTurn(firstPoint.Id, 180));
                        ctuLastDir = 180;
                    }
                    else if (second.Type == LandmarkType.Docking_270)
                    {
                        if (ctuLastDir != 270)
                            pathPoints.Add(PathPoint.GenTurn(firstPoint.Id, 270));
                        ctuLastDir = 270;
                    }
                    else
                    {
                        if (ctuLastDir != angle)
                            pathPoints.Add(PathPoint.GenTurn(firstPoint.Id, angle));
                        ctuLastDir = angle;
                    }
                    if (Math.Abs(angle - ctuLastDir) < 90)
                    {
                        pathPoints.Add(PathPoint.GenDirectMove(firstPoint.Id, moveSpeed, dis));
                    }
                    else
                    {
                        pathPoints.Add(PathPoint.GenDirectBackMove(firstPoint.Id, moveSpeed, dis));
                    }
                }

                else if (firstPoint.Type == LandmarkType.Shelves || firstPoint.Type == LandmarkType.Docking_0 || firstPoint.Type == LandmarkType.Docking_90 || firstPoint.Type == LandmarkType.Docking_180 || firstPoint.Type == LandmarkType.Docking_270)
                {
                    var angle = firstPoint.GetAngle(second.Id);
                    var dis = firstPoint.GetDis(second.Id);
                    if (Math.Abs(angle - ctuLastDir) < 90)
                    {
                        pathPoints.Add(PathPoint.GenChannelDirectMove(firstPoint.Id, moveSpeed, dis));
                    }
                    else
                    {
                        pathPoints.Add(PathPoint.GenChannelDirectBackMove(firstPoint.Id, moveSpeed, dis));
                    }
                }
                else //其他点类型
                {
                    var angle = firstPoint.GetAngle(second.Id);
                    var dis = firstPoint.GetDis(second.Id);
                    if (Math.Abs(angle - ctuLastDir) < 90)
                    {
                        pathPoints.Add(PathPoint.GenDirectMove(firstPoint.Id, moveSpeed, dis));
                    }
                    else
                    {
                        pathPoints.Add(PathPoint.GenDirectBackMove(firstPoint.Id, moveSpeed, dis));
                    }
                }
                pathPoints.Add(PathPoint.GenAllPathEnd(second.Id));
                return true;
            }
            else //三个以上
            {

                var firstPoint = pointCodes[0];
                var second = pointCodes[1];
                var lastPoint = pointCodes[pointCodes.Count - 1];
                var angle = firstPoint.GetAngle(second.Id);
                var dis = firstPoint.GetDis(second.Id);
                //最后一个转弯点
                var lastTurnPointCode = pointCodes.FindLast(s => s.CanTurning || s.Type == LandmarkType.Turning);
                if (lastTurnPointCode != null)
                {
                    if (lastTurnPointCode.Id == firstPoint.Id)
                    {
                        if (targetPoint.Type == LandmarkType.Shelves)
                        {
                            //在巷道同一车头朝右(货叉一侧)
                            if (ctuLastDir != ctuHeadAngleAtLane)
                                pathPoints.Add(PathPoint.GenTurn(firstPoint.Id, ctuHeadAngleAtLane));
                            ctuLastDir = ctuHeadAngleAtLane;
                            if (Math.Abs(angle - ctuHeadAngleAtLane) < 90)
                            {
                                pathPoints.Add(PathPoint.GenChannelDirectMove(firstPoint.Id, moveSpeed, dis));
                            }
                            else
                            {
                                pathPoints.Add(PathPoint.GenChannelDirectBackMove(firstPoint.Id, moveSpeed, dis));
                            }
                        }
                        else if (targetPoint.Type == LandmarkType.Docking_0)
                        {
                            if (ctuLastDir != 0)
                                pathPoints.Add(PathPoint.GenTurn(firstPoint.Id, 0));
                            ctuLastDir = 0;
                            if (Math.Abs(angle - 0) < 90)
                            {
                                pathPoints.Add(PathPoint.GenChannelDirectMove(firstPoint.Id, moveSpeed, dis));
                            }
                            else
                            {
                                pathPoints.Add(PathPoint.GenChannelDirectBackMove(firstPoint.Id, moveSpeed, dis));
                            }
                        }
                        else if (targetPoint.Type == LandmarkType.Docking_90)
                        {
                            if (ctuLastDir != 90)
                                pathPoints.Add(PathPoint.GenTurn(firstPoint.Id, 90));
                            ctuLastDir = 90;
                            if (Math.Abs(angle - ctuLastDir) < 90)
                            {
                                pathPoints.Add(PathPoint.GenChannelDirectMove(firstPoint.Id, moveSpeed, dis));
                            }
                            else
                            {
                                pathPoints.Add(PathPoint.GenChannelDirectBackMove(firstPoint.Id, moveSpeed, dis));
                            }
                        }
                        else if (targetPoint.Type == LandmarkType.Docking_180)
                        {
                            if (ctuLastDir != 180)
                                pathPoints.Add(PathPoint.GenTurn(firstPoint.Id, 180));
                            ctuLastDir = 180;
                            if (Math.Abs(angle - ctuLastDir) < 90)
                            {
                                pathPoints.Add(PathPoint.GenChannelDirectMove(firstPoint.Id, moveSpeed, dis));
                            }
                            else
                            {
                                pathPoints.Add(PathPoint.GenChannelDirectBackMove(firstPoint.Id, moveSpeed, dis));
                            }
                        }
                        else if (targetPoint.Type == LandmarkType.Docking_270)
                        {
                            if (ctuLastDir != 270)
                                pathPoints.Add(PathPoint.GenTurn(firstPoint.Id, 270));
                            ctuLastDir = 270;
                            if (Math.Abs(angle - ctuLastDir) < 90)
                            {
                                pathPoints.Add(PathPoint.GenChannelDirectMove(firstPoint.Id, moveSpeed, dis));
                            }
                            else
                            {
                                pathPoints.Add(PathPoint.GenChannelDirectBackMove(firstPoint.Id, moveSpeed, dis));
                            }
                        }
                        else
                        {
                            if (ctuLastDir != angle)
                                pathPoints.Add(PathPoint.GenTurn(firstPoint.Id, angle));
                            ctuLastDir = angle;
                            if (Math.Abs(angle - angle) < 90)
                            {
                                pathPoints.Add(PathPoint.GenFollowDirectMove(firstPoint.Id, moveSpeed, dis));
                            }
                            else
                            {
                                pathPoints.Add(PathPoint.GenFollowDirectBackMove(firstPoint.Id, moveSpeed, dis));
                            }
                        }
                    }
                    else
                    {
                        if (firstPoint.CanTurning || firstPoint.Type == LandmarkType.Turning)
                        {
                            if (ctuLastDir != angle)
                                pathPoints.Add(PathPoint.GenTurn(firstPoint.Id, angle));
                            ctuLastDir = angle;
                        }
                        if (Math.Abs(angle - ctuLastDir) < 90)
                        {
                            if (firstPoint.Type == LandmarkType.Shelves)
                            {
                                pathPoints.Add(PathPoint.GenChannelDirectMove(firstPoint.Id, moveSpeed, dis));
                            }
                            else if (firstPoint.Type == LandmarkType.Docking_0 ||
               firstPoint.Type == LandmarkType.Docking_90 ||
                  firstPoint.Type == LandmarkType.Docking_180 ||
                     firstPoint.Type == LandmarkType.Docking_270
)
                            {
                                pathPoints.Add(PathPoint.GenFollowDirectMove(firstPoint.Id, moveSpeed, dis));
                            }
                            else
                                pathPoints.Add(PathPoint.GenDirectMove(firstPoint.Id, moveSpeed, dis));
                        }
                        else
                        {
                            if (firstPoint.Type == LandmarkType.Shelves)
                            {
                                pathPoints.Add(PathPoint.GenChannelDirectBackMove(firstPoint.Id, moveSpeed, dis));
                            }
                            else if (firstPoint.Type == LandmarkType.Docking_0 ||
                                     firstPoint.Type == LandmarkType.Docking_90 ||
                                        firstPoint.Type == LandmarkType.Docking_180 ||
                                           firstPoint.Type == LandmarkType.Docking_270
         )
                            {
                                pathPoints.Add(PathPoint.GenFollowDirectBackMove(firstPoint.Id, moveSpeed, dis));
                            }
                            else
                                pathPoints.Add(PathPoint.GenDirectBackMove(firstPoint.Id, moveSpeed, dis));
                        }
                    }

                    for (int i = 1; i < pointCodes.Count - 1; i++)
                    {
                        var cur = pointCodes[i];
                        var next = pointCodes[i + 1];
                        angle = cur.GetAngle(next.Id);
                        dis = cur.GetDis(next.Id);
                        if (!isForkInDown)
                        {
                            var prePoint = pointCodes[i - 1];
                            if (cur.Type != LandmarkType.Shelves && prePoint.Type != LandmarkType.Shelves)//上一个跟当前都不是货架
                            {
                                short upHeight = (short)ConfigAppSettings.GetIntValue(Mushiny.Common.Mushiny_ + "DefaultUpdownHeight", 250);
                                var preAction = PathPoint.GenReadyToPutToShelves(cur.Id, 1, upHeight);
                                pathPoints.Add(preAction);
                                isForkInDown = true;
                            }
                        }
                        if (cur.Id == lastTurnPointCode.Id)
                        {
                            if (targetPoint.Type == LandmarkType.Shelves)
                            {
                                //在巷道同一车头朝右(货叉一侧)
                                if (ctuLastDir != ctuHeadAngleAtLane)
                                    pathPoints.Add(PathPoint.GenTurn(cur.Id, ctuHeadAngleAtLane));
                                ctuLastDir = ctuHeadAngleAtLane;
                                if (Math.Abs(angle - ctuHeadAngleAtLane) < 90)
                                {
                                    pathPoints.Add(PathPoint.GenChannelDirectMove(cur.Id, moveSpeed, dis));
                                }
                                else
                                {
                                    pathPoints.Add(PathPoint.GenChannelDirectBackMove(cur.Id, moveSpeed, dis));
                                }
                            }
                            else if (targetPoint.Type == LandmarkType.Docking_0)
                            {
                                if (ctuLastDir != 0)
                                    pathPoints.Add(PathPoint.GenTurn(cur.Id, 0));
                                ctuLastDir = 0;
                                if (Math.Abs(angle - ctuLastDir) < 90)
                                {
                                    pathPoints.Add(PathPoint.GenChannelDirectMove(cur.Id, moveSpeed, dis));
                                }
                                else
                                {
                                    pathPoints.Add(PathPoint.GenChannelDirectBackMove(cur.Id, moveSpeed, dis));
                                }
                            }
                            else if (targetPoint.Type == LandmarkType.Docking_90)
                            {
                                if (ctuLastDir != 90)
                                    pathPoints.Add(PathPoint.GenTurn(cur.Id, 90));
                                ctuLastDir = 90;
                                if (Math.Abs(angle - ctuLastDir) < 90)
                                {
                                    pathPoints.Add(PathPoint.GenChannelDirectMove(cur.Id, moveSpeed, dis));
                                }
                                else
                                {
                                    pathPoints.Add(PathPoint.GenChannelDirectBackMove(cur.Id, moveSpeed, dis));
                                }
                            }
                            else if (targetPoint.Type == LandmarkType.Docking_180)
                            {
                                if (ctuLastDir != 180)
                                    pathPoints.Add(PathPoint.GenTurn(cur.Id, 180));
                                ctuLastDir = 180;
                                if (Math.Abs(angle - ctuLastDir) < 90)
                                {
                                    pathPoints.Add(PathPoint.GenChannelDirectMove(cur.Id, moveSpeed, dis));
                                }
                                else
                                {
                                    pathPoints.Add(PathPoint.GenChannelDirectBackMove(cur.Id, moveSpeed, dis));
                                }
                            }
                            else if (targetPoint.Type == LandmarkType.Docking_270)
                            {
                                if (ctuLastDir != 270)
                                    pathPoints.Add(PathPoint.GenTurn(cur.Id, 270));
                                ctuLastDir = 270;
                                if (Math.Abs(angle - ctuLastDir) < 90)
                                {
                                    pathPoints.Add(PathPoint.GenChannelDirectMove(cur.Id, moveSpeed, dis));
                                }
                                else
                                {
                                    pathPoints.Add(PathPoint.GenChannelDirectBackMove(cur.Id, moveSpeed, dis));
                                }
                            }
                            else
                            {
                                if (ctuLastDir != angle)
                                    pathPoints.Add(PathPoint.GenTurn(cur.Id, angle));
                                ctuLastDir = angle;
                                if (Math.Abs(angle - ctuLastDir) < 90)
                                {
                                    pathPoints.Add(PathPoint.GenFollowDirectMove(cur.Id, moveSpeed, dis));
                                }
                                else
                                {
                                    pathPoints.Add(PathPoint.GenFollowDirectBackMove(cur.Id, moveSpeed, dis));
                                }
                            }
                        }
                        else if (cur.Type == LandmarkType.Turning)
                        {
                            if (next.Type == LandmarkType.Shelves)
                            {
                                //在巷道同一车头朝右(货叉一侧)
                                if (ctuLastDir != ctuHeadAngleAtLane)
                                    pathPoints.Add(PathPoint.GenTurn(cur.Id, ctuHeadAngleAtLane));
                                ctuLastDir = ctuHeadAngleAtLane;
                                if (Math.Abs(angle - ctuHeadAngleAtLane) < 90)
                                {
                                    pathPoints.Add(PathPoint.GenChannelDirectMove(cur.Id, moveSpeed, dis));
                                }
                                else
                                {
                                    pathPoints.Add(PathPoint.GenChannelDirectBackMove(cur.Id, moveSpeed, dis));
                                }
                            }
                            else
                            {
                                //不是最后一个转弯点,不需要每个转弯点都转完
                                if (ctuLastDir != angle)
                                    pathPoints.Add(PathPoint.GenTurn(cur.Id, angle));
                                ctuLastDir = angle;
                                pathPoints.Add(PathPoint.GenDirectMove(cur.Id, moveSpeed, dis));
                            }

                        }
                        else if (cur.Type == LandmarkType.Shelves)
                        {
                            //在巷道同一车头朝右(货叉一侧)
                            if (Math.Abs(angle - ctuLastDir) < 90)
                            {
                                pathPoints.Add(PathPoint.GenChannelDirectMove(cur.Id, moveSpeed, dis));
                            }
                            else
                            {
                                pathPoints.Add(PathPoint.GenChannelDirectBackMove(cur.Id, moveSpeed, dis));
                            }
                        }
                        else if (cur.Type == LandmarkType.Docking_0 ||
                              cur.Type == LandmarkType.Docking_90 ||
                                 cur.Type == LandmarkType.Docking_180 ||
                                    cur.Type == LandmarkType.Docking_270
                              )
                        {

                            if (Math.Abs(angle - ctuLastDir) < 90)//车头和下一点方向一直
                            {
                                pathPoints.Add(PathPoint.GenFollowDirectMove(cur.Id, moveSpeed, dis));
                            }
                            else
                            {
                                pathPoints.Add(PathPoint.GenFollowDirectBackMove(cur.Id, moveSpeed, dis));
                            }
                        }
                        else
                        {
                            if (Math.Abs(angle - ctuLastDir) < 90)//车头和下一点方向一直
                            {
                                pathPoints.Add(PathPoint.GenDirectMove(cur.Id, moveSpeed, dis));
                            }
                            else
                            {
                                pathPoints.Add(PathPoint.GenDirectBackMove(cur.Id, moveSpeed, dis));
                            }

                        }
                    }

                }
                else //无转弯点
                {
                    var firstCode = pointCodes[0];
                    if (firstCode.Type == LandmarkType.Shelves)
                    {
                        if (Math.Abs(ctuLastDir - ctuHeadAngleAtLane) >= 90)
                        {
                            List<uint> ps = new List<uint>();
                            pointCodes.ForEach(s => ps.Add(s.Id));
                            errmsg=($"当前路径点[{string.Join("->", ps)}]无转弯点,车头方向[{ctuLastDir}]与[{ctuHeadAngleAtLane}]不同,无法生成路径点");
                            return false;
                        }
                    }
                    else if (
                    firstCode.Type == LandmarkType.Docking_0)
                    {
                        if (Math.Abs(ctuLastDir - 0) >= 90)
                        {
                            List<uint> ps = new List<uint>();
                            pointCodes.ForEach(s => ps.Add(s.Id));
                            errmsg = ($"当前路径点[{string.Join("->", ps)}]无转弯点,车头方向[{ctuLastDir}]与[{ctuHeadAngleAtLane}]不同,无法生成路径点");
                            return false;
                        }
                    }
                    else if (firstCode.Type == LandmarkType.Docking_90)
                    {
                        if (Math.Abs(ctuLastDir - 90) >= 90)
                        {
                            List<uint> ps = new List<uint>();
                            pointCodes.ForEach(s => ps.Add(s.Id));
                            errmsg = ($"当前路径点[{string.Join("->", ps)}]无转弯点,车头方向[{ctuLastDir}]与[{ctuHeadAngleAtLane}]不同,无法生成路径点");
                            return false;
                        }
                    }
                    else if (
                  firstCode.Type == LandmarkType.Docking_180)
                    {
                        if (Math.Abs(ctuLastDir - 180) >= 90)
                        {
                            List<uint> ps = new List<uint>();
                            pointCodes.ForEach(s => ps.Add(s.Id));
                            LogUtil.error($"当前路径点[{string.Join("->", ps)}]无转弯点,车头方向[{ctuLastDir}]与[{ctuHeadAngleAtLane}]不同,无法生成路径点");
                            return false;
                        }
                    }
                    else if (
                     firstCode.Type == LandmarkType.Docking_270)
                    {
                        if (Math.Abs(ctuLastDir - 270) >= 90)
                        {
                            List<uint> ps = new List<uint>();
                            pointCodes.ForEach(s => ps.Add(s.Id));
                            errmsg = ($"当前路径点[{string.Join("->", ps)}]无转弯点,车头方向[{ctuLastDir}]与[{ctuHeadAngleAtLane}]不同,无法生成路径点");
                            return false;
                        }
                    }
                    for (int i = 0; i < pointCodes.Count - 1; i++)
                    {
                        var cur = pointCodes[i];
                        var next = pointCodes[i + 1];
                        angle = cur.GetAngle(next.Id);
                        dis = cur.GetDis(next.Id);
                        //if (cur.Type == LandmarkType.Turning)
                        //{
                        //    if (next.Type == LandmarkType.Shelves)
                        //    {
                        //        //在巷道同一车头朝右(货叉一侧)
                        //        pathPoints.Add(PathPoint.GenTurn(cur.Id, ctuHeadAngleAtLane));
                        //        ctuLastDir = ctuHeadAngleAtLane;
                        //        if (Math.Abs(angle - ctuHeadAngleAtLane) < 90)
                        //        {
                        //            pathPoints.Add(PathPoint.GenChannelDirectMove(cur.Id, moveSpeed, dis));
                        //        }
                        //        else
                        //        {
                        //            pathPoints.Add(PathPoint.GenChannelDirectBackMove(cur.Id, moveSpeed, dis));
                        //        }
                        //    }
                        //    else if (next.Type == LandmarkType.Turning)
                        //    {
                        //        if (Math.Abs(angle - ctuLastDir) < 90)
                        //        {
                        //            pathPoints.Add(PathPoint.GenDirectMove(cur.Id, moveSpeed, dis));
                        //        }
                        //        else
                        //        {
                        //            pathPoints.Add(PathPoint.GenTurn(cur.Id, angle));
                        //            ctuLastDir = angle;
                        //            pathPoints.Add(PathPoint.GenDirectBackMove(cur.Id, moveSpeed, dis));
                        //        }
                        //    }
                        //    else
                        //    {
                        //        pathPoints.Add(PathPoint.GenTurn(cur.Id, angle));
                        //        ctuLastDir = angle;
                        //        pathPoints.Add(PathPoint.GenDirectMove(cur.Id, moveSpeed, dis));
                        //    }

                        //}
                        //else 

                        if (cur.Type == LandmarkType.Shelves)
                        {
                            //在巷道同一车头朝右(货叉一侧)
                            if (Math.Abs(angle - ctuLastDir) < 90)
                            {
                                pathPoints.Add(PathPoint.GenChannelDirectMove(cur.Id, moveSpeed, dis));
                            }
                            else
                            {
                                pathPoints.Add(PathPoint.GenChannelDirectBackMove(cur.Id, moveSpeed, dis));
                            }
                        }
                        else if (cur.Type == LandmarkType.Docking_0 ||
                                       cur.Type == LandmarkType.Docking_90 ||
                                          cur.Type == LandmarkType.Docking_180 ||
                                             cur.Type == LandmarkType.Docking_270
                                       )
                        {

                            if (Math.Abs(angle - ctuLastDir) < 90)//车头和下一点方向一直
                            {
                                pathPoints.Add(PathPoint.GenFollowDirectMove(cur.Id, moveSpeed, dis));
                            }
                            else
                            {
                                pathPoints.Add(PathPoint.GenFollowDirectBackMove(cur.Id, moveSpeed, dis));
                            }
                        }
                        else
                        {
                            if (Math.Abs(angle - ctuLastDir) < 90)//车头和下一点方向一直
                            {
                                pathPoints.Add(PathPoint.GenDirectMove(cur.Id, moveSpeed, dis));
                            }
                            else
                            {
                                pathPoints.Add(PathPoint.GenDirectBackMove(cur.Id, moveSpeed, dis));
                            }
                        }
                    }
                }
                pathPoints.Add(PathPoint.GenAllPathEnd(lastPoint.Id));
                return true;
            }
        }

        /// <summary>
        ///生成手动从背篓取料箱的路径点
        /// </summary>
        /// <param name="curCTU"></param>
        /// <param name="row"></param>
        /// <param name="pathPoints"></param>
        /// <returns></returns>
        public static bool GenManualGetFromBunkerPathPoints(CTU curCTU, byte row, out List<PathPoint> pathPoints)
        {
            pathPoints = new List<PathPoint>();

            byte[] containerLocateCode = new byte[12];
            var pathPoint1 = PathPoint.GenGetFromBunker(curCTU.CurLandMark, row, containerLocateCode);
            short upHeight = (short)ConfigAppSettings.GetIntValue(Mushiny.Common.Mushiny_ + "DefaultUpdownHeight", 250);
            var preAction = PathPoint.GenReadyToPutToShelves(curCTU.CurLandMark, 1, upHeight);

            pathPoints.Add(pathPoint1);
            pathPoints.Add(preAction);
            return true;
        }

        /// <summary>
        /// 生成从料架/设备取货->背篓放货
        /// </summary>
        /// <param name="curCTU"></param>
        /// <param name="posInfo"></param>
        /// <param name="boxCode"></param>
        /// <param name="pathPoints"></param>
        /// <returns></returns>
        public static bool GenTakePathPoints(CTU curCTU, PosInfo posInfo, string boxCode, out List<PathPoint> pathPoints, out string errmsg, out Basket basket)
        {
            pathPoints = new List<PathPoint>();
            errmsg = "";
            basket = curCTU.GetEnabledBaskets().Find(s => boxCode.Equals(s.BoxCode));
            if (curCTU.CurLandMark != posInfo.PointCode)
            {
                errmsg = ($"【{curCTU.Name}】当前地标【{curCTU.CurLandMark}】与取料的地标【{posInfo.PointCode}】不符,不生成取料任务");
                LogUtil.error(errmsg);
                return false;
            }
            if (basket == null)
            {
                if (!curCTU.HasEmptyBasket(out basket))
                {
                    errmsg = ($"【{curCTU.Name}】无可用背篓,不生成取料任务");
                    LogUtil.error(errmsg);
                    return false;
                }
            }

            string shelfCodeStr = posInfo.ShelveCode;
            byte[] shelfCode = Mushiny.Common.ConvertToBytes(shelfCodeStr, 16);

            var tmpStr = Basket.BoxCodeToLocateCode(boxCode);
            byte[] containerLocateCode = new byte[12];
            if (string.IsNullOrEmpty(tmpStr))
            {
                if (CheckContainerLocCode)
                {
                    containerLocateCode[0] = (byte)(0xf0 + basket.Row);
                }
                else
                {
                    containerLocateCode[0] = (byte)(0x00 + basket.Row);
                }
            }
            else
            {
                containerLocateCode = Mushiny.Common.ConvertToBytes(tmpStr, 12);
            }

            short updown = (short)posInfo.UpDownHeight;
            ushort scanCodeShift = (ushort)posInfo.ScanCodeShift;
            short depth = (short)posInfo.InoutDepth;
            byte dir = (byte)posInfo.Dir;
            var pathPoint1 = PathPoint.GenGetFromShelves(posInfo.PointCode, dir,
                shelfCode, containerLocateCode, updown, scanCodeShift, depth);

            var pathPoint2 = PathPoint.GenPutToBunker(posInfo.PointCode, (byte)basket.Row,
                    containerLocateCode);

            pathPoints.Add(pathPoint1);
            pathPoints.Add(pathPoint2);
            return true;
        }
        /// <summary>
        /// 生成从背篓取货-》往料架放货
        /// </summary>
        /// <param name="curCTU"></param>
        /// <param name="posInfo"></param>
        /// <param name="taskId"></param>
        /// <param name="pathPoints"></param>
        /// <returns></returns>
        public static bool GenGetPutPathPoints(CTU curCTU, PosInfo posInfo, string boxCode, out List<PathPoint> pathPoints, out string errmsg)
        {
            pathPoints = new List<PathPoint>();
            errmsg = "";
            if (curCTU.CurLandMark != posInfo.PointCode)
            {
                errmsg = $"【{curCTU.Name}】当前地标【{curCTU.CurLandMark}】与取料的地标【{posInfo.PointCode}】不符,不生成放料任务";
                LogUtil.error(errmsg);
                return false;
            }
            var row = curCTU.GetAllBaskets().Find(s => s.BoxCode == boxCode);
            if (row == null)
            {
                errmsg = ($"【{curCTU.Name}】未在背篓里找到料箱【{boxCode}】,不生成取料任务");
                LogUtil.error(errmsg);
                return false;
            }

            string shelfCodeStr = posInfo.ShelveCode;
            byte[] shelfCode = Mushiny.Common.ConvertToBytes(shelfCodeStr, 16);
            short updown = (short)posInfo.UpDownHeight;
            ushort scanCodeShift = (ushort)posInfo.ScanCodeShift;
            short depth = (short)posInfo.InoutDepth;
            byte dir = (byte)posInfo.Dir;
            var tmpStr = row.GetLocateCodeByContainerCode();
            byte[] containerLocateCode = new byte[12];
            if (string.IsNullOrEmpty(tmpStr))
            {
                if (CheckContainerLocCode)
                {
                    containerLocateCode[0] = (byte)(0xf0 + row.Row);
                }
                else
                {
                    containerLocateCode[0] = (byte)(0x00 + row.Row);
                }
            }
            else
            {
                containerLocateCode = Mushiny.Common.ConvertToBytes(tmpStr, 12);
            }

            var pathPoint1 = PathPoint.GenGetFromBunker(posInfo.PointCode, (byte)row.Row,
                                   containerLocateCode);
            var pathPoint2 = PathPoint.GenPutToShelves(posInfo.PointCode, dir,
                    shelfCode, containerLocateCode, updown, scanCodeShift, depth);

            pathPoints.Add(pathPoint1);
            pathPoints.Add(pathPoint2);

            // pathPoints.Add(PathPoint.Add(ActionCode.整个路径结束, posInfo.PointCode, 0, 0));
            return true;
        }

        /// <summary>
        ///  生成从背篓取货-》准备往料架/设备放货等待
        /// </summary>
        /// <param name="curCTU"></param>
        /// <param name="posInfo"></param>
        /// <param name="boxCode"></param>
        /// <param name="pathPoints"></param>
        /// <returns></returns>
        public static bool GenReadyPutPathPoints(CTU curCTU, PosInfo posInfo, string boxCode, out List<PathPoint> pathPoints)
        {
            pathPoints = new List<PathPoint>();

            if (curCTU.CurLandMark != posInfo.PointCode)
            {
                LogUtil.error($"【{curCTU.Name}】当前地标【{curCTU.CurLandMark}】与取料的地标【{posInfo.PointCode}】不符,不生成放料任务");
                return false;
            }
            var row = curCTU.GetAllBaskets().Find(s => s.BoxCode == boxCode);
            if (row == null)
            {
                LogUtil.error($"【{curCTU.Name}】未在背篓里找到料箱【{boxCode}】,不生成取料任务");
                return false;
            }

            string shelfCodeStr = posInfo.ShelveCode;
            byte[] shelfCode = Mushiny.Common.ConvertToBytes(shelfCodeStr, 16);
            short updown = (short)posInfo.UpDownHeight;
            ushort scanCodeShift = (ushort)posInfo.ScanCodeShift;
            short depth = (short)posInfo.InoutDepth;
            byte dir = (byte)posInfo.Dir;
            var tmpStr = row.GetLocateCodeByContainerCode();
            byte[] containerLocateCode = new byte[12];
            if (string.IsNullOrEmpty(tmpStr))
            {
                if (CheckContainerLocCode)
                {
                    containerLocateCode[0] = (byte)(0xf0 + row.Row);
                }
                else
                {
                    containerLocateCode[0] = (byte)(0x00 + row.Row);
                }
            }
            else
            {
                containerLocateCode = Mushiny.Common.ConvertToBytes(tmpStr, 12);
            }
            var pathPoint1 = PathPoint.GenGetFromBunker(posInfo.PointCode, (byte)row.Row,
                                   containerLocateCode);
            var pathPoint2 = PathPoint.GenReadyToPutToShelves(posInfo.PointCode, dir,
                     updown);

            pathPoints.Add(pathPoint1);
            pathPoints.Add(pathPoint2);
            return true;
        }


        /// <summary>
        /// 生成将料箱从货叉放入货架
        /// </summary>
        /// <param name="curCTU"></param>
        /// <param name="posInfo"></param>
        /// <param name="boxCode"></param>
        /// <param name="pathPoints"></param>
        /// <returns></returns>
        public static bool GenPutToShelfPathPoints(CTU curCTU, PosInfo posInfo, string boxCode, out List<PathPoint> pathPoints)
        {
            pathPoints = new List<PathPoint>();

            if (curCTU.CurLandMark != posInfo.PointCode)
            {
                LogUtil.error($"【{curCTU.Name}】当前地标【{curCTU.CurLandMark}】与取料的地标【{posInfo.PointCode}】不符,不生成放料任务");
                return false;
            }
            var row = curCTU.GetAllBaskets().Find(s => s.BoxCode == boxCode);
            if (row == null)
            {
                LogUtil.error($"【{curCTU.Name}】未在背篓里找到料箱【{boxCode}】,不生成放料任务");
                return false;
            }

            string shelfCodeStr = posInfo.ShelveCode;
            byte[] shelfCode = Mushiny.Common.ConvertToBytes(shelfCodeStr, 16);
            short updown = (short)posInfo.UpDownHeight;
            ushort scanCodeShift = (ushort)posInfo.ScanCodeShift;
            short depth = (short)posInfo.InoutDepth;
            byte dir = (byte)posInfo.Dir;
            var tmpStr = row.GetLocateCodeByContainerCode();
            byte[] containerLocateCode = new byte[12];
            if (string.IsNullOrEmpty(tmpStr))
            {
                if (CheckContainerLocCode)
                {
                    containerLocateCode[0] = (byte)(0xf0 + row.Row);
                }
                else
                {
                    containerLocateCode[0] = (byte)(0x00 + row.Row);
                }
            }
            else
            {
                containerLocateCode = Mushiny.Common.ConvertToBytes(tmpStr, 12);
            }
            var pathPoint2 = PathPoint.GenPutToShelves(posInfo.PointCode, dir,
                    shelfCode, containerLocateCode, updown, scanCodeShift, depth);
            pathPoints.Add(pathPoint2);

            // pathPoints.Add(PathPoint.Add(ActionCode.整个路径结束, posInfo.PointCode, 0, 0));
            return true;
        }

        /// <summary>
        /// 生成从背篓取箱子
        /// </summary>
        /// <param name="curCTU"></param>
        /// <param name="posInfo"></param>
        /// <param name="boxCode"></param>
        /// <param name="pathPoints"></param>
        /// <returns></returns>
        public static bool GetBoxFromBasket(CTU curCTU, string boxCode, out List<PathPoint> pathPoints)
        {
            pathPoints = new List<PathPoint>();
            var row = curCTU.GetAllBaskets().Find(s => s.BoxCode == boxCode);
            if (row == null)
            {
                LogUtil.error($"【{curCTU.Name}】未在背篓里找到料箱【{boxCode}】,不生成取料任务");
                return false;
            }
            // short updown = (short)posInfo.UpDownHeight;
            //ushort scanCodeShift = (ushort)posInfo.ScanCodeShift;
            //  short depth = (short)posInfo.InoutDepth;
            // byte dir = (byte)posInfo.Dir;
            var tmpStr = row.GetLocateCodeByContainerCode();
            byte[] containerLocateCode = new byte[12];
            if (string.IsNullOrEmpty(tmpStr))
            {
                if (CheckContainerLocCode)
                {
                    containerLocateCode[0] = (byte)(0xf0 + row.Row);
                }
                else
                {
                    containerLocateCode[0] = (byte)(0x00 + row.Row);
                }
            }
            else
            {
                containerLocateCode = Mushiny.Common.ConvertToBytes(tmpStr, 12);
            }
            var pathPoint1 = PathPoint.GenGetFromBunker(curCTU.CurLandMark, (byte)row.Row,
                                   containerLocateCode);

            pathPoints.Add(pathPoint1);
            return true;
        }


        /// <summary>
        /// 生成开始充电
        /// </summary>
        /// <param name="curCTU"></param>
        /// <param name="posInfo"></param>
        /// <param name="pathPoints"></param>
        /// <returns></returns>
        public static bool GenStartChargePathPoints(CTU curCTU, PosInfo posInfo, out PathPoint pathPoint)
        {
            pathPoint = null;

            if (curCTU.CurLandMark != posInfo.PointCode)
            {
                LogUtil.error($"【{curCTU.Name}】当前地标【{curCTU.CurLandMark}】与充电的地标【{posInfo.PointCode}】不符,不生成充电任务");
                return false;
            }
            pathPoint = PathPoint.Add(ActionCode.进入充电, (uint)posInfo.PointCode, (byte)0, (short)0);
            return true;
        }
        /// <summary>
        /// 生成退出充电
        /// </summary>
        /// <param name="curCTU"></param>
        /// <param name="posInfo"></param>
        /// <param name="pathPoint"></param>
        /// <returns></returns>
        public static bool GenStopChargePathPoints(CTU curCTU, PosInfo posInfo, out PathPoint pathPoint)
        {
            pathPoint = null;

            if (curCTU.CurLandMark != posInfo.PointCode)
            {
                LogUtil.error($"【{curCTU.Name}】当前地标【{curCTU.CurLandMark}】与充点地标【{posInfo.PointCode}】不符,不生成退出充电任务");
                return false;
            }
            // pathPoint = PathPoint.Add(ActionCode.退出充电, (uint)posInfo.PointCode, (byte)0, (short)0);
            pathPoint = PathPoint.GenTurn(curCTU.CurLandMark, (short)curCTU.CurDir);
            LogUtil.info($"【{curCTU.Name}】在当前地标【{curCTU.CurLandMark}】角度【{curCTU.CurDir}】生成退出充电任务");
            return true;
        }

        /// <summary>
        /// 将料箱放入背篓
        /// </summary>
        /// <param name="curCTU"></param>
        /// <param name="posInfo"></param>
        /// <param name="boxCode"></param>
        /// <param name="pathPoints"></param>
        /// <param name="errmsg"></param>
        /// <param name="basket"></param>
        /// <returns></returns>
        public static bool PutBoxToBasket(CTU curCTU, PosInfo posInfo, string boxCode, out List<PathPoint> pathPoints, out string errmsg, out Basket basket)
        {
            pathPoints = new List<PathPoint>();
            errmsg = "";
            basket = curCTU.GetEnabledBaskets().Find(s => boxCode.Equals(s.BoxCode));
            if (basket == null)
            {
                if (!curCTU.HasEmptyBasket(out basket))
                {
                    errmsg = ($"【{curCTU.Name}】无可用背篓,不生成取料任务");
                    LogUtil.error(errmsg);
                    return false;
                }
            }

            string shelfCodeStr = posInfo.ShelveCode;
            byte[] shelfCode = Mushiny.Common.ConvertToBytes(shelfCodeStr, 16);

            var tmpStr = Basket.BoxCodeToLocateCode(boxCode);
            byte[] containerLocateCode = new byte[12];
            if (string.IsNullOrEmpty(tmpStr))
            {
                if (CheckContainerLocCode)
                {
                    containerLocateCode[0] = (byte)(0xf0 + basket.Row);
                }
                else
                {
                    containerLocateCode[0] = (byte)(0x00 + basket.Row);
                }
            }
            else
            {
                containerLocateCode = Mushiny.Common.ConvertToBytes(tmpStr, 12);
            }

            short updown = (short)posInfo.UpDownHeight;
            ushort scanCodeShift = (ushort)posInfo.ScanCodeShift;
            short depth = (short)posInfo.InoutDepth;
            byte dir = (byte)posInfo.Dir;
            var pathPoint2 = PathPoint.GenPutToBunker(posInfo.PointCode, (byte)basket.Row,
                    containerLocateCode);
            pathPoints.Add(pathPoint2);
            return true;
        }


        /// <summary>
        /// 生成从料架/设备取货
        /// </summary>
        /// <param name="curCTU"></param>
        /// <param name="posInfo"></param>
        /// <param name="boxCode"></param>
        /// <param name="pathPoints"></param>
        /// <returns></returns>
        public static bool GenGetBoxFomShelf(CTU curCTU, PosInfo posInfo, string boxCode, out List<PathPoint> pathPoints, out string errmsg)
        {
            pathPoints = new List<PathPoint>();
            errmsg = "";
            string shelfCodeStr = posInfo.ShelveCode;
            byte[] shelfCode = Mushiny.Common.ConvertToBytes(shelfCodeStr, 16);

            var tmpStr = Basket.BoxCodeToLocateCode(boxCode);
            byte[] containerLocateCode = new byte[12];
            if (string.IsNullOrEmpty(tmpStr))
            {
                if (CheckContainerLocCode)
                {
                    containerLocateCode[0] = (byte)(0xf0);
                }
                else
                {
                    containerLocateCode[0] = (byte)(0x00);
                }
            }
            else
            {
                containerLocateCode = Mushiny.Common.ConvertToBytes(tmpStr, 12);
            }

            short updown = (short)posInfo.UpDownHeight;
            ushort scanCodeShift = (ushort)posInfo.ScanCodeShift;
            short depth = (short)posInfo.InoutDepth;
            byte dir = (byte)posInfo.Dir;
            var pathPoint1 = PathPoint.GenGetFromShelves(posInfo.PointCode, dir,
                shelfCode, containerLocateCode, updown, scanCodeShift, depth);

            pathPoints.Add(pathPoint1);
            return true;
        }

        #endregion

        #region 两车相遇问题
        static List<CTURealtimeInfo> RunningCtuRealtimeInfos = new List<CTURealtimeInfo>();

        public static CTURealtimeInfo GetRealTimeInfo(CTU ctu)
        {
            return RunningCtuRealtimeInfos.Find(s => ctu.IP.Equals(s.Ctu.IP));
        }
        public static void UpdateCtuMoveState(CTU ctu, CtuMoveState moveState)
        {
            var find = RunningCtuRealtimeInfos.Find(s => ctu.IP.Equals(s.Ctu.IP));
            if (find != null)
            {
                find.MoveState = moveState;
                if (moveState == CtuMoveState.空闲)
                {
                    UpdateCtuRealTimeLoc(ctu, new List<PointCode>());
                }
            }
        }
        public static void UpdateCtuDstInfo(CTU ctu, PosInfo posInfo)
        {
            var find = RunningCtuRealtimeInfos.Find(s => ctu.IP.Equals(s.Ctu.IP));
            if (find != null)
            {
                find.DstPosInfo = posInfo;
            }
        }
        static string preRealtimeInfo = "";

        public static void UpdateCtuRealTimeLoc(CTU ctu, List<PointCode> movePoints)
        {
            var find = RunningCtuRealtimeInfos.Find(s => ctu.IP.Equals(s.Ctu.IP));
            if (find != null)
            {
                find.SetNextPathWay(movePoints);
                find.SetBlockedPoints(movePoints);
            }
            StringBuilder stringBuilder = new StringBuilder();
            RunningCtuRealtimeInfos.ForEach(s =>
            {
                stringBuilder.AppendLine($"【CTU实时】【{s.Ctu?.Name}】优先级【{s.Priority}】" +
                    $"目的地【{s.DstPosInfo?.Name}】移动状态【{s.MoveState}】【{s.DstPosInfo?.PointCode}】路径上的CTU【{string.Join(",", s.CtusInPath)}】当前路线【{s.CurPathWay?.Name}】下一路线【{s.NextPathWay?.Name}】");
            });
            string curInfo = stringBuilder.ToString();
            if (!preRealtimeInfo.Equals(curInfo))
            {
                preRealtimeInfo = curInfo;
                LogUtil.debug(curInfo);
            }
        }
        public static void UpdateCtuRealTimeLoc(CTU ctu, List<uint> movePoints)
        {
            var find = RunningCtuRealtimeInfos.Find(s => ctu.IP.Equals(s.Ctu.IP));
            if (find != null)
            {
                var points = new List<PointCode>();
                movePoints.ForEach(s =>
                {
                    var pp = LandMarks.GetPointCode(s);
                    if (pp != null)
                    {
                        points.Add(pp);
                    }
                });
                find.SetNextPathWay(points);
                find.SetBlockedPoints(points);
            }
            StringBuilder stringBuilder = new StringBuilder();
            RunningCtuRealtimeInfos.ForEach(s =>
            {
                stringBuilder.AppendLine($"【CTU实时】【{s.Ctu?.Name}】优先级【{s.Priority}】" +
                    $"目的地【{s.DstPosInfo?.Name}】移动状态【{s.MoveState}】【{s.DstPosInfo?.PointCode}】路径上的CTU【{string.Join(",", s.CtusInPath)}】当前路线【{s.CurPathWay?.Name}】下一路线【{s.NextPathWay?.Name}】");
            });
            string curInfo = stringBuilder.ToString();
            if (!preRealtimeInfo.Equals(curInfo))
            {
                preRealtimeInfo = curInfo;
                LogUtil.debug(curInfo);
            }
        }
        public static void ClearCtuRealtimeInfo(CTU ctu)
        {
            var find = RunningCtuRealtimeInfos.Find(s => ctu.IP.Equals(s.Ctu.IP));
            if (find != null)
            {
                UpdateCtuDstInfo(ctu, null);
                UpdateCtuMoveState(ctu, CtuMoveState.空闲);
                UpdateCtuRealTimeLoc(ctu, new List<PointCode>());
            }
        }
        /// <summary>
        /// 检查是否有互相冲突的CTU
        /// </summary>
        /// <param name="ctuNames"></param>
        /// <returns></returns>
        public static bool CheckHasLockedStatus(CTU curCtu, out List<string> ctuNames, out bool willReplane)
        {
            willReplane = false;
            ctuNames = new List<string>();
            var hasCtus = RunningCtuRealtimeInfos.FindAll(s => s.CtusInPath.Contains(curCtu.Name));
            if (hasCtus != null && hasCtus.Count > 0)
            {
                foreach (var item in hasCtus)
                {
                    ctuNames.Add(item.Ctu.Name);
                }
                hasCtus.Sort((a, b) => { return a.Priority - b.Priority; });
                willReplane = hasCtus[0].Ctu.Name.Equals(curCtu.Name);
            }
            return ctuNames.Count > 0;
        }
        public static CTURealtimeInfo AddOrUpdateCtuRealtimeInfo(CTU ctu)
        {
            var find = RunningCtuRealtimeInfos.Find(s => ctu.IP.Equals(s.Ctu.IP));
            if (find != null)
            {
            }
            else
            {
                find = new CTURealtimeInfo(ctu);
                RunningCtuRealtimeInfos.Add(find);
            }
            return find;
        }
        #endregion

        //public static void SetBasket(CTU ctu, byte row, string taskId, string containerCode, string locateCode = "")
        //{
        //    ctu.SetBasket(row, taskId, containerCode, locateCode);
        //}
        #region 限制区
        /// <summary>
        /// 获取限制区域
        /// </summary>
        public static bool GetLimitareas(out List<LimitAreaInfo> limitAreaInfos)
        {
            if (manager.HttpManager.GetLimitAreas(out limitAreaInfos))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 检查该地标所在限制区是否被占用
        /// </summary>
        /// <param name="pointCode"></param>
        /// <returns></returns>
        public static bool IsLimitAreaOccupied(string ctuName, uint pointCode, out string areaName, out string occupyAgv)
        {
            areaName = "";
            occupyAgv = "";
            if (GetLimitareas(out List<LimitAreaInfo> areas))
            {
                var finds = areas.FindAll(s => s.CtuPointCodes.Contains(pointCode));
                if (finds != null && finds.Count > 0)
                {
                    foreach (var item in finds)
                    {
                        if (!item.Enabled) continue;
                        if (!string.IsNullOrEmpty(item.OccupiedAgvName))
                        {
                            if (!ctuName.Equals(item.OccupiedAgvName))
                            {
                                areaName = item.Name;
                                occupyAgv = item.OccupiedAgvName;
                                return true;
                            }

                        }
                    }
                }
            }
            else //获取失败,认为在限制区
            {
                return true;
            }
            return false;
        }
        /// <summary>
        /// 获取该点所在的空闲限制区
        /// </summary>
        /// <param name="ctuName"></param>
        /// <param name="pointCode"></param>
        /// <param name="areaNames"></param>
        /// <returns></returns>
        public static bool GetIdleLimitAreasByPoint(string ctuName, uint pointCode, out List<string> areaNames)
        {
            areaNames = new List<string>();
            if (GetLimitareas(out List<LimitAreaInfo> areas))
            {
                foreach (var area in areas)
                {
                    if (!area.Enabled) continue;
                    if (area.CtuPointCodes.Contains(pointCode))
                    {
                        if (string.IsNullOrEmpty(area.OccupiedAgvName))
                        {
                            areaNames.Add(area.Name);
                        }
                        else if (ctuName.Equals(area.OccupiedAgvName))
                        {
                            areaNames.Add(area.Name);
                        }
                    }
                }
            }
            else
            {
                return false;
            }
            return true;
        }
        /// <summary>
        /// 查找该点所在的限制区域
        /// </summary>
        /// <param name="pointCode"></param>
        /// <param name="areaNames"></param>
        /// <returns>true:获取成功</returns>
        public static bool GetLimitAreasByPoint(uint pointCode, out List<string> areaNames)
        {
            areaNames = new List<string>();
            if (GetLimitareas(out List<LimitAreaInfo> areas))
            {
                foreach (var area in areas)
                {
                    if (!area.Enabled) continue;
                    if (area.CtuPointCodes.Contains(pointCode))
                    {
                        areaNames.Add(area.Name);
                    }
                }
            }
            else
            {
                return false;
            }
            return true;
        }
        /// <summary>
        /// 地标是否在限制区
        /// </summary>
        /// <param name="pointCode"></param>
        /// <param name="areaName"></param>
        /// <returns></returns>
        public static bool PointIsInLimitArea(uint pointCode, out string areaName)
        {
            areaName = "";
            if (GetLimitareas(out List<LimitAreaInfo> areas))
            {
                foreach (var area in areas)
                {
                    if (!area.Enabled) continue;
                    if (area.CtuPointCodes.Contains(pointCode))
                    {
                        areaName = area.Name;
                    }
                }
            }
            else
            {
                return false;
            }
            return !string.IsNullOrEmpty(areaName);
        }
        #endregion
        /// <summary>
        /// 获取当前ctu的占地面积
        /// ctu的范围内占用的点
        /// </summary>
        /// <param name="ctu"></param>
        /// <returns></returns>
        public static List<uint> GetCurCtuOccupyArea(CTU ctu)
        {
            int len = ConfigAppSettings.GetIntValue(Mushiny.Common.Mushiny_ + "CtuSelfSemiLength", 990);
            var limitArea = new List<uint>();
            if (ctu.CurLandMark == 0 || ctu.CurLandMark == 10001) return limitArea;
            var posInfo = LandMarks.GetPointCode(ctu.CurLandMark);
            if (posInfo == null) return limitArea;
            int sumLen = 0;
            var neighboor = posInfo.Above;
            while (neighboor != null)
            {
                var dis = neighboor.Distance;
                var id = neighboor.Id;
                sumLen += dis;
                limitArea.Add(id);
                if (sumLen > len)
                {
                    break;
                }
                else
                {
                    var tmpPP = LandMarks.GetPointCode(id);
                    neighboor = tmpPP.Above;
                }
            }
            sumLen = 0;
            neighboor = posInfo.Right;
            while (neighboor != null)
            {
                var dis = neighboor.Distance;
                var id = neighboor.Id;
                sumLen += dis;
                limitArea.Add(id);
                if (sumLen > len)
                {
                    break;
                }
                else
                {
                    var tmpPP = LandMarks.GetPointCode(id);
                    neighboor = tmpPP.Right;
                }
            }
            sumLen = 0;
            neighboor = posInfo.Below;
            while (neighboor != null)
            {
                var dis = neighboor.Distance;
                var id = neighboor.Id;
                sumLen += dis;
                limitArea.Add(id);
                if (sumLen > len)
                {
                    break;
                }
                else
                {
                    var tmpPP = LandMarks.GetPointCode(id);
                    neighboor = tmpPP.Below;
                }
            }

            sumLen = 0;
            neighboor = posInfo.Left;
            while (neighboor != null)
            {
                var dis = neighboor.Distance;
                var id = neighboor.Id;
                sumLen += dis;
                limitArea.Add(id);
                if (sumLen > len)
                {
                    break;
                }
                else
                {
                    var tmpPP = LandMarks.GetPointCode(id);
                    neighboor = tmpPP.Left;
                }
            }

            if (limitArea.Contains(ctu.CurLandMark))
            {
                limitArea.Remove(ctu.CurLandMark);
            }
            return limitArea;
        }
        /// <summary>
        /// 获取该Ctu路径点的限制区域
        /// </summary>
        /// <param name="ctu"></param>
        /// <param name="usedPoints"></param>
        /// <returns></returns>
        public static List<uint> GetCtuOccupyArea(CTU ctu, List<uint> usedPoints)
        {
            int len = ConfigAppSettings.GetIntValue(Mushiny.Common.Mushiny_ + "CtuSelfSemiLength", 990);
            var limitArea = new List<uint>();
            if (usedPoints.Count == 0) return limitArea;
            foreach (var pp in usedPoints)
            {
                var ppc = LandMarks.GetPointCode(pp);
                if (ppc == null) continue;
                if (ppc.Type != LandmarkType.Turning) continue;
                int sumLen = 0;
                var neighboor = ppc.Above;
                while (neighboor != null)
                {
                    var dis = neighboor.Distance;
                    var id = neighboor.Id;
                    sumLen += dis;
                    limitArea.Add(id);
                    if (sumLen > len)
                    {
                        break;
                    }
                    else
                    {
                        var tmpPP = LandMarks.GetPointCode(id);
                        neighboor = tmpPP.Above;
                    }
                }
                sumLen = 0;
                neighboor = ppc.Right;
                while (neighboor != null)
                {
                    var dis = neighboor.Distance;
                    var id = neighboor.Id;
                    sumLen += dis;
                    limitArea.Add(id);
                    if (sumLen > len)
                    {
                        break;
                    }
                    else
                    {
                        var tmpPP = LandMarks.GetPointCode(id);
                        neighboor = tmpPP.Right;
                    }
                }
                sumLen = 0;
                neighboor = ppc.Below;
                while (neighboor != null)
                {
                    var dis = neighboor.Distance;
                    var id = neighboor.Id;
                    sumLen += dis;
                    limitArea.Add(id);
                    if (sumLen > len)
                    {
                        break;
                    }
                    else
                    {
                        var tmpPP = LandMarks.GetPointCode(id);
                        neighboor = tmpPP.Below;
                    }
                }

                sumLen = 0;
                neighboor = ppc.Left;
                while (neighboor != null)
                {
                    var dis = neighboor.Distance;
                    var id = neighboor.Id;
                    sumLen += dis;
                    limitArea.Add(id);
                    if (sumLen > len)
                    {
                        break;
                    }
                    else
                    {
                        var tmpPP = LandMarks.GetPointCode(id);
                        neighboor = tmpPP.Left;
                    }
                }
            }
            if (limitArea.Contains(ctu.CurLandMark))
            {
                limitArea.Remove(ctu.CurLandMark);
            }
            return limitArea;
        }


        public static bool canShow(FaultId faultId)
        {
            if (FaultId.待机状态下丢码.Equals(faultId) || FaultId.直行中丢码.Equals(faultId)
                || FaultId.直行中错码.Equals(faultId) || FaultId.直行过程因错码停下_要求路径重算.Equals(faultId)
                || FaultId.直行末尾点丢码.Equals(faultId) || FaultId.转弯中丢码.Equals(faultId)
                || FaultId.转弯中错码_要求路径重算.Equals(faultId) || FaultId.校正过程中丢码.Equals(faultId)
                || FaultId.位姿融合失败.Equals(faultId)
                || FaultId.直行过程中发生角度切换.Equals(faultId) || FaultId.充电对接过程中左右偏差过大.Equals(faultId)
                || FaultId.动作码参数异常.Equals(faultId) || FaultId.命令码参数异常.Equals(faultId)
                || FaultId.液晶屏失联.Equals(faultId) || FaultId.顶端灯带失联.Equals(faultId)
                || FaultId.语音播报模块失联.Equals(faultId))
            {
                return false;
            }
            return true;
        }
        ///// <summary>
        ///// 对任务按照巷道分组
        ///// </summary>
        ///// <param name="tasks"></param>
        ///// <returns></returns>
        //public static Dictionary<string, List<finishedOutTask>> GroupTaskByLanCode(List<FinishedCtuTask> tasks)
        //{
        //    if (tasks == null || tasks.Count == 0) return null;
        //    var finishedTasks = new List<finishedOutTask>();

        //    foreach (var task in tasks)
        //    {
        //        if (task.taskType == SmfTaskType.OutStore)
        //            finishedTasks.Add(new finishedOutTask(task, ctuBean.GetPosInfoByName(task.fromLoc)));
        //        else if (task.taskType == SmfTaskType.Instore)
        //            finishedTasks.Add(new finishedOutTask(task, ctuBean.GetPosInfoByName(task.toLoc)));
        //    }
        //    var lanePos = finishedTasks.GroupBy(s => s.PosInfo.Lanway);
        //    Dictionary<string, List<finishedOutTask>> pairs = new Dictionary<string, List<finishedOutTask>>();
        //    foreach (var lane in lanePos)
        //    {
        //        string laneCode = lane.Key;
        //        var outs = lane.ToList();
        //        pairs.Add(laneCode, outs);
        //    }
        //    return pairs;
        //}

        //public static List<finishedOutTask> SwitchTaskType(List<FinishedCtuTask> finishedCtuTasks)
        //{
        //    if (finishedCtuTasks == null || finishedCtuTasks.Count == 0) return null;
        //    var finishedTasks = new List<finishedOutTask>();

        //    foreach (var task in finishedCtuTasks)
        //    {
        //        if (task.taskType == SmfTaskType.OutStore)
        //            finishedTasks.Add(new finishedOutTask(task, ctuBean.GetPosInfoByName(task.fromLoc)));
        //        else if (task.taskType == SmfTaskType.Instore)
        //        {
        //            finishedTasks.Add(new finishedOutTask(task, ctuBean.GetPosInfoByName(task.toLoc)));
        //        }

        //    }
        //    return finishedTasks;
        //}
        ///// <summary>
        ///// 找到ctu可执行的巷道任务
        ///// </summary>
        ///// <param name="ctu"></param>
        ///// <param name="tasks"></param>
        ///// <returns></returns>
        //public static Dictionary<string, List<finishedOutTask>> FilterExecuteTasksByLanCode(CTU ctu, List<FinishedCtuTask> tasks)
        //{
        //    if (tasks == null || tasks.Count == 0) return null;
        //    var finishedTasks = SwitchTaskType(tasks);
        //    var lanePos = finishedTasks.GroupBy(s => s.PosInfo.Lanway);
        //    Dictionary<string, List<finishedOutTask>> pairs = new Dictionary<string, List<finishedOutTask>>();
        //    foreach (var lane in lanePos)
        //    {
        //        string laneCode = lane.Key;
        //        var outs = lane.ToList();
        //        if (outs == null || outs.Count == 0) continue;
        //        var task = outs[0];
        //        string tar = "";
        //        if (task.OutTask.taskType == SmfTaskType.Instore)
        //        {
        //            tar = task.OutTask.fromLoc;//入库看起点是否有车
        //        }
        //        else if (task.OutTask.taskType == SmfTaskType.OutStore)
        //        {
        //            tar = task.OutTask.fromLoc;
        //        }
        //        var posInfo = ctuBean.GetPosInfoByName(tar);
        //        if (posInfo == null)
        //        {
        //            continue;
        //        }
        //        var otherCtus = ctuBean.GetEnabledCTUs()?.FindAll(s => !ctu.IP.Equals(s.IP));
        //        if (otherCtus != null)
        //        {
        //            bool hasAgvAtTask = false;
        //            foreach (var agv in otherCtus)
        //            {
        //                if (ctuBean.IsInSamePath(ctu.CurLandMark, agv.CurLandMark))
        //                {
        //                    hasAgvAtTask = true;
        //                }
        //            }
        //            if (hasAgvAtTask)
        //            {
        //                continue;
        //            }
        //        }
        //        pairs.Add(laneCode, outs);
        //    }
        //    return pairs;
        //}

        /// <summary>
        /// 根据料箱尺寸筛选任务
        /// </summary>
        /// <param name="pairs"></param>
        /// <param name="boxSizes"></param>
        /// <returns></returns>
        //public static List<finishedOutTask> FilterTasksByBoxType(List<finishedOutTask> pairs, List<string> boxSizes)
        //{
        //    if (pairs == null || pairs.Count == 0) return null;
        //    if (boxSizes == null || boxSizes.Count == 0) return pairs;

        //    return pairs.FindAll(s =>
        //    {
        //        string preCode = s.OutTask.boxCode.Substring(0, 3);
        //        return boxSizes.Contains(preCode);
        //    });
        //}
        /// <summary>
        /// 根据设备名筛选任务
        /// </summary>
        /// <param name="pairs"></param>
        /// <param name="equipNames"></param>
        /// <returns></returns>
        //public static List<finishedOutTask> FilterTasksByEquipName(List<finishedOutTask> pairs, List<string> equipNames)
        //{
        //    if (pairs == null || pairs.Count == 0) return null;
        //    if (equipNames == null || equipNames.Count == 0) return pairs;

        //    return pairs.FindAll(s =>
        //    {
        //        if (s.OutTask.taskType == SmfTaskType.Instore)
        //        {
        //            return equipNames.Contains(s.OutTask.fromLoc);
        //        }
        //        else if (s.OutTask.taskType == SmfTaskType.OutStore)
        //        {
        //            return equipNames.Contains(s.OutTask.toLoc);
        //        }
        //        return false;
        //    });
        //}
    }


    public class TasktateChangeEventArg : EventArgs
    {
        public string TaskId { get; set; }

        public RobotTaskState State { get; set; }
    }


}