/usr/share/tk5/gui5.tcl is in tk5 0.6-6.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 | ###################################################################
# This file is part of tk5, a utility program for the
# ICOM IC-R5 receiver.
#
# Copyright (C) 2004, Bob Parnass, AJ9S
#
# tk5 is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published
# by the Free Software Foundation; either version 2 of the License,
# or (at your option) any later version.
#
# tk5 is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with tk5; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# 02111-1307 USA
###################################################################
proc MakeGui { } \
{
global Cht
global Chvector
global GlobalParam
global ReadRadioFlag
global TemplateSavedFlag
set Cht ""
set GlobalParam(TemplateFilename) untitled.tr5
set TemplateSavedFlag no
set ReadRadioFlag no
# Set custom font and colors.
SetAppearance
###############################################################
# Menu bar along the top edge.
###############################################################
set fr_menubar [MakeMenuBar .mb]
set mf [frame .mainframe]
set fr_line1 [frame $mf.line1]
set fr_lim [frame $mf.lim]
# frame $mf.chtable
# set Cht $mf.chtable
set fr_misc [MakeMiscFrame $fr_line1.omsg]
set fr_display [MakeDisplayFrame $fr_line1.dis]
set fr_blabels [MakeBankLabelsFrame $fr_line1.blabels]
set fr_title [MakeTitleFrame $fr_line1.title]
pack $fr_title -side right -fill y
pack $fr_misc $fr_display $fr_blabels -side left -fill y
pack $fr_blabels -side left -fill y
###############################################################
# Memory channel scrolled window
###############################################################
if {$GlobalParam(EditMemoryChannels) == "off"} \
{
toplevel .mc
set Cht .mc
# Prevent user from closing the channel list window unless
# he elects to exit the entire program.
wm protocol .mc WM_DELETE_WINDOW {ExitApplication}
wm title $Cht "tk5 Memory Channels"
wm iconify $Cht
}
###############################################################
# VFO controls window
###############################################################
toplevel .vfo
set fr_vfo .vfo.ctls
frame $fr_vfo -relief groove
set fr_search [MakeSearchFrame $fr_vfo.search]
pack $fr_search \
-side left \
-fill both -expand true
pack $fr_vfo
# Prevent user from closing the VFO controls window unless
# he elects to exit the entire program.
wm protocol .vfo WM_DELETE_WINDOW {ExitApplication}
wm title .vfo "tk5 VFO Settings"
###############################################################
# Memory Bank controls window
###############################################################
# toplevel .mbank
# set mbank .mbank.ctls
# frame $mbank -relief groove
# wm title .mbank "tk5 Memory Bank"
#
# set fr_bank [MakeMemoryBankFrame $mbank.bank]
#
# pack $fr_bank -side left -fill both -expand true
# pack $mbank -side left -fill both -expand true
#
# # Prevent user from closing the Bank window unless
# # he elects to exit the entire program.
# wm protocol .mbank WM_DELETE_WINDOW {ExitApplication}
#
###############################################################
# TV controls window
###############################################################
toplevel .tv
set fr_tv .tv.ctls
frame $fr_tv -relief groove
set fr_tvc [MakeTVFrame $fr_tv.c]
pack $fr_tvc \
-side left \
-fill both -expand true
pack $fr_tv
# Prevent user from closing the window unless
# he elects to exit the entire program.
wm protocol .tv WM_DELETE_WINDOW {ExitApplication}
wm title .tv "tk5 Television Settings "
###############################################################
# Secondary controls window
###############################################################
toplevel .controls
set ctls .controls.ctls
frame $ctls -relief groove
set fr_com [MakeCommFrame $ctls.com]
pack $fr_com -side left -fill both -expand true
###############################################################
set Chvector ""
pack $fr_menubar -side top -fill x -pady 3 -padx 3
pack $fr_line1 -side top -fill x -pady 3 -padx 3
pack $fr_lim -side top -fill x -pady 3 -padx 3
pack $ctls -side top -fill both -expand true -padx 3 -pady 3
pack .mainframe -side top -fill both -expand true
update idletasks
###############################################################
# Ask the window manager to catch the delete window
# event.
###############################################################
wm protocol . WM_DELETE_WINDOW {ExitApplication}
# Prevent user from shrinking or expanding main window.
wm minsize . [winfo width .] [winfo height .]
# wm maxsize . [winfo width .] [winfo height .]
wm protocol .controls WM_DELETE_WINDOW {ExitApplication}
wm title .controls "tk5 Secondary Controls"
# Prevent user from overshrinking or expanding controls window.
wm minsize .controls [winfo width .controls] [winfo height .controls]
wm maxsize .controls [winfo width .controls] [winfo height .controls]
# Prevent user from shrinking or expanding window.
wm minsize .vfo [winfo width .vfo] [winfo height .vfo]
# wm maxsize .vfo [winfo width .vfo] [winfo height .vfo]
# Force main window to appear on top by hiding, then
# then showing it.
wm withdraw .
wm deiconify .
return
}
###################################################################
# Alter color and font appearance based on user preferences.
###################################################################
proc SetAppearance { } \
{
global GlobalParam
if {$GlobalParam(Font) != "" } \
{
# Designate a custom font for most widgets.
option add *font $GlobalParam(Font)
}
if {$GlobalParam(BackGroundColor) != "" } \
{
# Designate a custom background color for most widgets.
option add *background $GlobalParam(BackGroundColor)
}
if {$GlobalParam(ForeGroundColor) != "" } \
{
# Designate a custom foreground color for most widgets.
option add *foreground $GlobalParam(ForeGroundColor)
}
if {$GlobalParam(TroughColor) != "" } \
{
# Designate a custom slider trough color
# for most scale widgets.
option add *troughColor $GlobalParam(TroughColor)
}
return
}
##########################################################
# Check if the configuration file exists.
# If it exits, return 1.
#
# Otherwise, prompt the user to select the
# serial port.
##########################################################
proc FirstTimeCheck { Rcfile } \
{
global AboutMsg
global GlobalParam
global Libdir
global tcl_platform
if { [file readable $Rcfile] == 1 } \
{
return 0
}
tk_dialog .about "About tk5" \
$AboutMsg info 0 OK
# No readable config file found.
# Treat this as the first time the user has run the program.
# Create a new window with radio buttions and
# an entry field so user can designate the proper
# serial port.
set msg "Please identify the serial port to which\n"
set msg [append msg "your IC-R5 receiver is connected."]
toplevel .serialport
set sp .serialport
label $sp.intro -text $msg
frame $sp.rbframe
set fr $sp.rbframe
if { $tcl_platform(platform) == "windows" } \
{
# For Windows.
radiobutton $fr.com1 -text COM1: -variable port \
-value {COM1:}
radiobutton $fr.com2 -text COM2: -variable port \
-value {COM2:}
radiobutton $fr.com3 -text COM3: -variable port \
-value {COM3:}
radiobutton $fr.com4 -text COM4: -variable port \
-value {COM4:}
pack $fr.com1 $fr.com2 $fr.com3 $fr.com4 \
-side top -padx 3 -pady 3 -anchor w
} \
else \
{
# For unix, mac, etc..
radiobutton $fr.s0 -text /dev/ttyS0 -variable port \
-value {/dev/ttyS0}
radiobutton $fr.s1 -text /dev/ttyS1 -variable port \
-value {/dev/ttyS1}
radiobutton $fr.s2 -text /dev/ttyS2 -variable port \
-value {/dev/ttyS2}
radiobutton $fr.s3 -text /dev/ttyS3 -variable port \
-value {/dev/ttyS3}
radiobutton $fr.s4 -text /dev/ttyS4 -variable port \
-value {/dev/ttyS4}
radiobutton $fr.s5 -text /dev/ttyS5 -variable port \
-value {/dev/ttyS5}
pack \
$fr.s0 $fr.s1 $fr.s2 \
$fr.s3 $fr.s4 $fr.s5 \
-side top -padx 3 -pady 3 -anchor w
}
radiobutton $fr.other -text "other (enter below)" \
-variable port \
-value other
entry $fr.ent -width 30 -textvariable otherport
pack $fr.other $fr.ent \
-side top -padx 3 -pady 3 -anchor w
button $sp.ok -text "OK" \
-command \
{ \
global GlobalParam
if {$port == "other"} \
{
set GlobalParam(Device) $otherport
} \
else \
{
set GlobalParam(Device) $port
}
# puts stderr "entered $GlobalParam(Device)"
}
button $sp.exit -text "Exit" \
-command { exit }
pack $sp.intro -side top -padx 3 -pady 3
pack $fr -side top -padx 3 -pady 3
pack $sp.ok $sp.exit -side left -padx 3 -pady 3 -expand true
bind $fr.ent <Key-Return> \
{
global GlobalParam
set GlobalParam(Device) $otherport
}
wm title $sp "Select serial port"
wm protocol $sp WM_DELETE_WINDOW {exit}
set errorflag true
while { $errorflag == "true" } \
{
tkwait variable GlobalParam(Device)
if { $tcl_platform(platform) != "unix" } \
{
set errorflag false
break
}
# The following tests do not work properly
# in Windows. That is why we won't perform
# the serial port tests when running Windows version.
if { ([file readable $GlobalParam(Device)] != 1) \
|| ([file writable $GlobalParam(Device)] != 1)}\
{
# Device must be readable, writable
bell
tk_dialog .badport "Serial port problem" \
"Serial port problem" error 0 OK
} \
else \
{
set errorflag false
}
}
destroy $sp
return 1
}
##########################################################
# ExitApplication
#
# This procedure can do any cleanup necessary before
# exiting the program.
#
# Disable computer control of the radio, then quit.
##########################################################
proc ExitApplication { } \
{
global GlobalParam
global ReadRadioFlag
global TemplateSavedFlag
if { ($ReadRadioFlag == "yes") \
&& ($TemplateSavedFlag == "no") } \
{
set msg "You did not save the template data"
append msg " in a file."
set result [tk_dialog .sav "Warning" \
$msg \
warning 0 Cancel Exit ]
if {$result == 0} \
{
return
}
}
set GlobalParam(EditMemoryChannels) \
$GlobalParam(EditMemoryChannelsNext)
SaveSetup
# DisableCControl
exit
}
##########################################################
# NoExitApplication
#
# This procedure prevents the user from
# killing the window.
##########################################################
proc NoExitApplication { } \
{
set response [tk_dialog .quitit "Exit?" \
"Do not close this window." \
warning 0 OK ]
return
}
##########################################################
#
# Scroll_Set manages optional scrollbars.
#
# From "Practical Programming in Tcl and Tk,"
# second edition, by Brent B. Welch.
# Example 27-2
#
##########################################################
proc Scroll_Set {scrollbar geoCmd offset size} {
if {$offset != 0.0 || $size != 1.0} {
eval $geoCmd;# Make sure it is visible
$scrollbar set $offset $size
} else {
set manager [lindex $geoCmd 0]
$manager forget $scrollbar ;# hide it
}
}
##########################################################
#
# Listbox with optional scrollbars.
#
#
# Inputs: basename of configuration file
#
# From "Practical Programming in Tcl and Tk,"
# second edition, by Brent B. Welch.
# Example 27-3
#
##########################################################
proc Scrolled_Listbox { f args } {
frame $f
listbox $f.list \
-font {courier 12} \
-xscrollcommand [list Scroll_Set $f.xscroll \
[list grid $f.xscroll -row 1 -column 0 -sticky we]] \
-yscrollcommand [list Scroll_Set $f.yscroll \
[list grid $f.yscroll -row 0 -column 1 -sticky ns]]
eval {$f.list configure} $args
scrollbar $f.xscroll -orient horizontal \
-command [list $f.list xview]
scrollbar $f.yscroll -orient vertical \
-command [list $f.list yview]
grid $f.list $f.yscroll -sticky news
grid $f.xscroll -sticky news
grid rowconfigure $f 0 -weight 1
grid columnconfigure $f 0 -weight 1
return $f.list
}
##########################################################
#
# Create a scrollable frame.
#
#
# From "Effective Tcl/Tk Programming,"
# by Mark Harrison and Michael McLennan.
# Page 121.
#
##########################################################
proc ScrollformCreate { win } \
{
frame $win -class Scrollform -relief groove -borderwidth 3
scrollbar $win.sbar -command "$win.vport yview"
pack $win.sbar -side right -fill y
canvas $win.vport -yscrollcommand "$win.sbar set"
pack $win.vport -side left -fill both -expand true
frame $win.vport.form
$win.vport create window 0 0 -anchor nw \
-window $win.vport.form
bind $win.vport.form <Configure> "ScrollFormResize $win"
return $win
}
proc ScrollFormResize { win } \
{
set bbox [ $win.vport bbox all ]
set wid [ winfo width $win.vport.form ]
$win.vport configure -width $wid \
-scrollregion $bbox -yscrollincrement 0.1i
}
proc ScrollFormInterior { win } \
{
return "$win.vport.form"
}
##########################################################
# Contruct the top row of pulldown menus
##########################################################
proc MakeMenuBar { f } \
{
global AboutMsg
global Device
global FileTypes
global GlobalParam
global Pgm
global Version
# File pull down menu
frame $f -relief groove -borderwidth 3
menubutton $f.file -text "File" -menu $f.file.m \
-underline 0
menubutton $f.view -text "View" -menu $f.view.m \
-underline 0
menubutton $f.data -text "Data" -menu $f.data.m \
-underline 0
menubutton $f.radio -text "Radio" -menu $f.radio.m \
-underline 0
menubutton $f.help -text "Help" -menu $f.help.m \
-underline 0
menu $f.view.m
AddView $f.view.m
menu $f.data.m
AddData $f.data.m
menu $f.help.m
$f.help.m add command -label "Readme" \
-underline 0 \
-command { \
set helpfile [format "%s/README" $Libdir ]
set win [textdisplay_create "README"]
textdisplay_file $win $helpfile
}
$f.help.m add command -label "Tcl info" \
-underline 0 \
-command { \
tk_dialog .about "Tcl info" \
[HelpTclInfo] info 0 OK
}
$f.help.m add command -label "License" \
-underline 0 \
-command { \
set helpfile [format "%s/COPYING" $Libdir ]
set win [textdisplay_create "Notice"]
textdisplay_file $win $helpfile
}
$f.help.m add command -label "About tk5" \
-underline 0 \
-command { \
tk_dialog .about "About tk5" \
$AboutMsg info 0 OK
}
menu $f.file.m -tearoff no
$f.file.m add command -label "Open ..." \
-underline 0 \
-command {OpenTemplate .mainframe}
$f.file.m add command -label "Save" \
-underline 0 \
-command {SaveTemplate .mainframe 0}
$f.file.m add command -label "Save As ..." \
-underline 0 \
-command {SaveTemplate .mainframe 1}
$f.file.m add separator
set msg "Import memory channels from CSV file ..."
$f.file.m add command -label $msg \
-underline 0 \
-command {\
ImportCSV .
}
set msg "Export memory channels to CSV file..."
$f.file.m add command -label $msg \
-underline 0 \
-command {ExportChannels .mainframe}
$f.file.m add separator
$f.file.m add command -label "Exit" \
-underline 1 \
-command { ExitApplication}
menu $f.radio.m -tearoff no
AddRadio $f.radio.m
pack $f.file $f.view $f.data $f.radio -side left -padx 10
pack $f.help -side right
update
return $f
}
proc MakeScrollPane {w x y} {
frame $w -class ScrollPane -width $x -height $y
canvas $w.c -xscrollcommand [list $w.x set] -yscrollcommand [list $w.y set]
scrollbar $w.x -orient horizontal -command [list $w.c xview]
scrollbar $w.y -orient vertical -command [list $w.c yview]
set f [frame $w.c.content -borderwidth 0 -highlightthickness 0]
$w.c create window 0 0 -anchor nw -window $f
grid $w.c $w.y -sticky nsew
grid $w.x -sticky nsew
grid rowconfigure $w 0 -weight 1
grid columnconfigure $w 0 -weight 1
# This binding makes the scroll-region of the canvas behave correctly as
# you place more things in the content frame.
bind $f <Configure> [list Scrollpane_cfg $w %w %h]
$w.c configure -borderwidth 0 -highlightthickness 0
return $f
}
proc Scrollpane_cfg {w wide high} {
set newSR [list 0 0 $wide $high]
return
if {![string equals [$w cget -scrollregion] $newSR]} {
$w configure -scrollregion $newSR
}
}
##########################################################
# Add widgets to the view menu
##########################################################
proc AddView { m } \
{
global GlobalParam
# Change font.
if {$GlobalParam(Font) == ""} \
{
set msg "Change Font"
} \
else \
{
set msg [format "Change Font (%s)" $GlobalParam(Font)]
}
$m add command -label $msg -command \
{
set ft [font_select]
if {$ft != ""} \
{
set GlobalParam(Font) $ft
set msg "The change will take effect next "
set msg [append msg "time you start tk5."]
tk_dialog .wcf "Change Appearance" \
$msg info 0 OK
}
}
$m add command -label "Restore Original Font" -command \
{
set GlobalParam(Font) ""
set msg "The change will take effect next "
set msg [append msg "time you start tk5."]
tk_dialog .wcf "Change Appearance" $msg info 0 OK
}
$m add separator
$m add command -label "Change Panel Color" -command \
{
set col [tk_chooseColor -initialcolor #d9d9d9]
if {$col != ""} \
{
set GlobalParam(BackGroundColor) $col
set msg "The change will take effect next "
set msg [append msg "time you start tk5."]
tk_dialog .wcf "Change Appearance" \
$msg info 0 OK
}
}
$m add command -label "Change Lettering Color" -command \
{
set col [tk_chooseColor -initialcolor black]
if {$col != ""} \
{
set GlobalParam(ForeGroundColor) $col
set msg "The change will take effect next "
set msg [append msg "time you start tk5."]
tk_dialog .wcf "Change Appearance" \
$msg info 0 OK
}
}
$m add command -label "Change Slider Trough Color" -command \
{
set col [tk_chooseColor -initialcolor #c3c3c3]
if {$col != ""} \
{
set GlobalParam(TroughColor) $col
set msg "The change will take effect next "
set msg [append msg "time you start tk5."]
tk_dialog .wcf "Change Appearance" \
$msg info 0 OK
}
}
$m add separator
# Helpful tips balloons
$m add checkbutton \
-label "Balloon Help Windows" \
-variable GlobalParam(BalloonHelpWindows) \
-onvalue on -offvalue off
return
}
##########################################################
# Add widgets to the Data menu
##########################################################
proc AddData { m } \
{
global GlobalParam
set hint ""
append hint "The Encode Image operation "
append hint "is designed for use when "
append hint "testing tk5."
balloonhelp_for $m $hint
$m add command -label "Validate data" \
-command \
{
if {[ValidateData] == 0} \
{
tk_dialog .info "Valiate data" \
"The data is ok." info 0 OK
}
}
# $m add command -label "Check for duplicate frequencies" \
# -command { CkDuplicate }
$m add command -label "Encode Image" \
-command { \
if {[ValidateData] == 0} \
{
MakeWait
EncodeImage
KillWait
}
}
$m add separator
# $m add command -label "Swap Memory Banks ..." \
# -command { MakeSwapFrame }
#
# $m add command -label "Sort Channels ..." \
-command { MakeSortFrame }
$m add command -label "Clear All Channels" \
-command { ClearAllChannels }
return
}
##########################################################
# Add choices to the Radio menu
##########################################################
proc AddRadio { m } \
{
global GlobalParam
global Libdir
$m add command -label "Read from radio ..." \
-command { \
Radio2Template .mainframe
update
}
$m add command -label "Write to radio ..." \
-command { \
Image2Radio .mainframe
update
}
$m add separator
$m add command -label "Interrogate radio for model info ..." \
-command { \
global GlobalParam
set s [GetModelInfo]
binary scan $s "H*" x
set GlobalParam(RadioVersion) $x
update
}
$m add separator
$m add radiobutton -label "Model with 10 kHz BCB steps" \
-variable GlobalParam(WhichModel) \
-value 10
$m add radiobutton -label "Model with 9 kHz BCB steps" \
-variable GlobalParam(WhichModel) \
-value 9
$m add separator
$m add command -label "Configure Serial Port ..." \
-command { MakeConfigurePortFrame }
$m add separator
$m add checkbutton \
-label "Debug" \
-variable GlobalParam(Debug) \
-onvalue "1" \
-offvalue "0"
return $m
}
###################################################################
#
# Permit user to adjust serial port settings.
# Create a popup window.
#
###################################################################
proc MakeConfigurePortFrame { } \
{
global GlobalParam
global tcl_platform
global tcl_version
catch {destroy .timingwin}
toplevel .timingwin
wm title .timingwin "Configure serial port"
set f .timingwin
set a $f.a
frame $a -relief flat -borderwidth 3
label $a.lrtslevel \
-text "Set RTS pin to +12 VDC" \
-borderwidth 3
checkbutton $a.rtslevel -text "" \
-variable GlobalParam(RTSline) \
-onvalue "12" -offvalue "-12"
set hint ""
append hint "Some cloning cables require +12 VDC on "
append hint "the RTS pin, but most do not."
balloonhelp_for $a.lrtslevel $hint
balloonhelp_for $a.rtslevel $hint
label $a.lcableechos \
-text "Read back commands from serial port" \
-borderwidth 3
checkbutton $a.cableechos -text "" \
-variable GlobalParam(CableEchos) \
-onvalue 1 -offvalue 0
set hint ""
append hint "Read back commands if:\n\n"
append hint "(1) You are using Microsoft Windows "
append hint "and using either the Purple or RT Sytems "
append hint "CT29A cloning cable.\n\n"
append hint "(2) You are using Linux and using \n"
append hint "an RT Systems CT29A cloning cable.\n\n"
append hint "Do not read back commands if "
append hint "you are using Bill Petrowsky's 2-transistor "
append hint "cable. "
balloonhelp_for $a.cableechos $hint
balloonhelp_for $a.lcableechos $hint
grid $a.lrtslevel -row 10 -column 0 -sticky w
grid $a.rtslevel -row 10 -column 1 -sticky w
grid $a.lcableechos -row 20 -column 0 -sticky w
grid $a.cableechos -row 20 -column 1 -sticky w
pack $a -side top -anchor w -padx 3 -pady 3 -expand true
button $f.ok -text "OK" -command \
{
catch {destroy .timingwin}
}
pack $f.ok -side top -padx 3 -pady 3 -expand true
update
return
}
##########################################################
#
# Create a progress gauge widget.
#
#
# From "Effective Tcl/Tk Programming,"
# by Mark Harrison and Michael McLennan.
# Page 125.
#
##########################################################
proc gauge_create {win {color ""}} \
{
frame $win -class Gauge
# set len [option get $win length Length]
set len 300
canvas $win.display -borderwidth 0 -background white \
-highlightthickness 0 -width $len -height 20
pack $win.display -expand yes -padx 10
if {$color == ""} \
{
set color [option get $win color Color]
}
$win.display create rectangle 0 0 0 20 \
-outline "" -fill $color -tags bar
$win.display create text [expr {0.5 * $len}] 10 \
-anchor c -text "0%" -tags value
return $win
}
proc gauge_value {win val} \
{
if {$val < 0 || $val > 100} \
{
error "bad value \"$val\": should be 0-100"
}
set msg [format "%.0f%%" $val]
$win.display itemconfigure value -text $msg
set w [expr {0.01 * $val * [winfo width $win.display]}]
set h [winfo height $win.display]
$win.display coords bar 0 0 $w $h
update
}
proc MakeWaitWindow {f cnflag color} \
{
global CancelXfer
set CancelXfer 0
frame $f
button $f.cancel -text Cancel -command {\
global CancelXfer; set CancelXfer 1; puts "Canceled"}
gauge_create $f.g PaleGreen
option add *Gauge.borderWidth 2 widgetDefault
option add *Gauge.relief sunken widgetDefault
option add *Gauge.length 300 widgetDefault
option add *Gauge.color gray widgetDefault
pack $f.g -expand yes -fill both \
-padx 10 -pady 10
if {$cnflag} \
{
pack $f.cancel -side top -padx 3 -pady 3
}
pack $f
return $f.g
}
##########################################################
#
# Copy data from radio to template image (a lengthy string).
#
##########################################################
proc Radio2Template { f }\
{
global Cht
global FileTypes
global GlobalParam
global Home
global MemFreq
global MemMode
global ReadRadioFlag
set msg ""
append msg "Instructions (read all steps):\n"
append msg "1) Ensure the radio is connected to your computer"
append msg " and powered on.\n"
set result [tk_dialog .info "Read from radio" \
$msg \
info 0 OK Cancel ]
if {$result} \
{
return
}
# Read memory image from radio.
if {[ReadImage]} \
{
set ReadRadioFlag no
set msg "Error while reading from radio."
tk_dialog .error $msg $msg error 0 OK
return
}
set GlobalParam(Populated) 1
# ZapBankLabels
DecodeImage
ShowChannels $Cht
set msg "Transfer Complete.\n"
append msg "Look at the radio display "
append msg "to see if it displays a message."
tk_dialog .belch "Read IC-R5" \
$msg info 0 OK
set ReadRadioFlag yes
return
}
##########################################################
# Write memory image to a template file.
##########################################################
proc SaveTemplate { f asflag } \
{
global GlobalParam
global TemplateSavedFlag
global ReadRadioFlag
global Mimage
global Nmessages
if {[string length $Mimage] <= 0} \
{
set msg "You must first read template data from"
append msg " the radio before saving it in a"
append msg " template file."
append msg " (Use the Radio menu for reading"
append msg " from the radio.)"
tk_dialog .error "No template data" \
$msg error 0 OK
return
}
set mitypes \
{
{"IC-R5 template files" {.tr5} }
}
set filename $GlobalParam(TemplateFilename)
if { ($GlobalParam(TemplateFilename) == "") \
|| ($asflag) } \
{
set filename \
[Mytk_getSaveFile $f \
$GlobalParam(MemoryFileDir) \
.tr5 \
"Save IC-R5 data to template file" \
$mitypes]
}
if { $filename != "" }\
{
if {[ValidateData]} {return}
MakeWait
EncodeImage
# Truncate memory image to the proper length.
# We want to ignore the several FF records
# which may have been appended
# at the end of the image.
set n [expr {($Nmessages * 32) - 1}]
set Mimage [string range $Mimage 0 $n]
KillWait
set GlobalParam(TemplateFilename) $filename
SetWinTitle
set GlobalParam(MemoryFileDir) \
[ Dirname $GlobalParam(TemplateFilename) ]
set fid [open $GlobalParam(TemplateFilename) "w"]
fconfigure $fid -translation binary
puts -nonewline $fid $Mimage
close $fid
set TemplateSavedFlag yes
}
return
}
##########################################################
# Read memory image from a template file.
##########################################################
proc OpenTemplate { f } \
{
global BytesPerMessage
global Cht
global GlobalParam
global Mimage
global Nmessages
set mitypes \
{
{"IC-R5 template files" {.tr5} }
{"Percon web files" {.icf .ICF} }
{"www.ic-r5.com files" {.ic5 .IC5} }
}
set GlobalParam(TemplateFilename) [Mytk_getOpenFile \
$f $GlobalParam(MemoryFileDir) \
"Open template file" $mitypes]
if { $GlobalParam(TemplateFilename) != "" }\
{
set GlobalParam(MemoryFileDir) \
[ Dirname $GlobalParam(TemplateFilename) ]
if [ catch { open $GlobalParam(TemplateFilename) "r"} fid] \
{
# error
tk_dialog .error "tk5" \
"Cannot open file $file" \
error 0 OK
set GlobalParam(TemplateFilename) ""
return
}
fconfigure $fid -translation binary
if { [regexp -nocase {\.icf$} \
$GlobalParam(TemplateFilename)] } \
{
# User wants to read a Percon .ICF file.
set GlobalParam(TemplateFilename) ""
set code [ReadICFFile $fid]
if {$code == 0} \
{
DecodeImage
}
} \
elseif { [regexp -nocase {\.ic5$} \
$GlobalParam(TemplateFilename)] } \
{
# User wants to read a www.ic-r5.com .IC5 file.
set GlobalParam(TemplateFilename) ""
set code [ReadIC5File $fid]
if {$code == 0} \
{
DecodeImage
}
} \
elseif { [regexp -nocase {\.tr5$} \
$GlobalParam(TemplateFilename)] } \
{
# User specified a .tr5 file.
set nbytes [expr {$Nmessages * $BytesPerMessage / 2}]
set Mimage [read $fid $nbytes]
if { [string length $Mimage] != $nbytes } \
{
# Corrupted file.
set msg "Corrupted template file "
append msg $GlobalParam(TemplateFilename)
tk_dialog .error "tk5" \
"Corrupted template file" \
error 0 OK
set code 1
} \
else \
{
set code 0
DecodeImage
set lst [ReadVariables \
$GlobalParam(TemplateFilename) $fid]
# ZapBankLabels
}
}
close $fid
SetWinTitle
if {$code == 0} \
{
set GlobalParam(Populated) 1
ShowChannels $Cht
}
}
return
}
##########################################################
# Read data from a .ICF (ICOM Clone Format) file
##########################################################
proc ReadICFFile { fid }\
{
global Cht
global GlobalParam
global Icf2Hex
global Mimage
if {$fid == ""} then {return ""}
# Read entire .ICF file at one time.
set allicf [read $fid]
set line ""
set i 0
set Mimage ""
# For each line in the file.
foreach line [split $allicf "\n" ] \
{
update
incr i
# trim any spurious characters from end, e.g., \r
# Skip the first 2 lines in the file.
if { $i > 2 } then\
{
set line [string range $line 0 37]
set nchar [string len $line]
# for each char in the line
# set c [string range $line $j $j]
set buf [string range $line 6 $nchar]
# Translate to binary
set buf [string toupper $buf]
set pbuf [PackString $buf]
append Mimage $pbuf
}
}
set GlobalParam(TemplateFilename) ""
return 0
}
##########################################################
# Read data from a .IC5 (www.ic-r5.com) file
##########################################################
proc ReadIC5File { fid }\
{
global Cht
global GlobalParam
global Icf2Hex
global Mimage
if {$fid == ""} then {return ""}
set file $GlobalParam(TemplateFilename)
# Read entire .IC5 file at one time.
set allicf [read $fid]
# Sanity test the file.
set len [string length $allicf]
if {$len != 64562} \
{
# Corrupted file or unexpected length.
tk_dialog .error "tk5" \
"Corrupt file $file. Wrong size." \
error 0 OK
set GlobalParam(TemplateFilename) ""
return 1
}
set line ""
set i 0
set addr 0
set Mimage ""
foreach line [split $allicf "\n" ] \
{
update
incr i
if { [string length $line] == 0} { break }
# trim any spurious characters from end, e.g., \r
# Skip the first 2 lines in the file.
if { $i > 2 } then\
{
set haddr [format "%04x" $addr]
set xaddr [string range $line 0 3]
set xaddr [string tolower $xaddr]
# puts stderr "$i, haddr: $haddr, xaddr: $xaddr"
# If hex address mismatch
if {$xaddr != $haddr} \
{
# Corrupted file or unexpected fmt.
tk_dialog .error "tk5" \
"Corrupt file $file. Wrong format." \
error 0 OK
set GlobalParam(TemplateFilename) ""
set Mimage ""
return 1
}
set line [string range $line 0 69]
set nchar [string len $line]
set buf [string range $line 6 $nchar]
# Translate to binary
set buf [string toupper $buf]
set pbuf [PackString $buf]
append Mimage $pbuf
incr addr 32
}
}
set GlobalParam(TemplateFilename) ""
return 0
}
##########################################################
# Import memory channels from a .csv file
##########################################################
proc ImportCSV { f }\
{
global BankID
global Cht
global CtcssBias
global GlobalParam
global Mimage
global ImageAddr
if { ([info exists Mimage] == 0) \
|| ([string length $Mimage] <= 0)} \
{
set msg "You must open a template file\n"
append msg " or read an image from the radio\n"
append msg " before importing channels.\n"
tk_dialog .importinfo "tk5" \
$msg info 0 OK
return
}
set filetypes \
{
{"IC-R5 memory channel files" {.csv .txt} }
}
set filename [Mytk_getOpenFile $f \
$GlobalParam(MemoryFileDir) \
"Import channels" $filetypes]
if {$filename == ""} then {return ""}
set GlobalParam(MemoryFileDir) [ Dirname $filename ]
if [ catch { open $filename "r"} fid] \
{
# error
tk_dialog .error "tk5" \
"Cannot open file $file" \
error 0 OK
return
}
# Read entire .csv file at one time.
set allchannels [read $fid]
set line ""
set i 0
# For each line in the .csv file.
foreach line [split $allchannels "\n" ] \
{
update
incr i
if { $i > 1 } then\
{
# Delete double quote characters.
regsub -all "\"" $line "" bline
set line $bline
if {$line == ""} then {continue}
# puts stderr "line: $line."
set msg [ParseCsvLine $line]
if {$msg != ""} \
{
set response [ErrorInFile \
$msg $line $filename]
if {$response == 0} then {continue} \
else {ExitApplication}
}
}
}
ShowChannels $Cht
close $fid
return
}
###################################################################
# Parse a line from the csv file. Perform sanity checks on
# the field values and store them in array variables.
#
# Returns:
# empty string -ok
# descriptive error message string otherwise
###################################################################
proc ParseCsvLine {line} \
{
global Ctcss
global CtcssBias
global Dcs
global GlobalParam
global ImageAddr
global Mimage
global MemBankLetter
global MemBankCh
global MemDuplex
global MemFreq
global MemHide
global MemLabel
global MemMode
global MemOffset
global MemSkip
global MemStep
global MemDToneCode
global MemDTonePolarity
global MemToneCode
global MemToneFlag
global Mode
global RBankID
global Skip
global Step
global ToneFlag
set endlabel $GlobalParam(LabelLength)
incr endlabel -1
if {$line == ""} {return error}
set mlist [split $line ","]
set n [llength $mlist]
set m [ expr {15 - $n} ]
# Add empty fields to the end of the line
# if there are too few fields.
for {set i 0} {$i < $m} {incr i} \
{
append line ","
}
set mlist [split $line ","]
set i [lindex $mlist 0]
set ch $i
set freq [lindex $mlist 1]
set mode [lindex $mlist 2]
set step [lindex $mlist 3]
set offset [lindex $mlist 4]
set duplex [lindex $mlist 5]
set toneflag [lindex $mlist 6]
set ctcss [lindex $mlist 7]
set dcs [lindex $mlist 8]
set polarity [lindex $mlist 9]
set skip [lindex $mlist 10]
set bn [lindex $mlist 11]
set membankch [lindex $mlist 12]
set label [lindex $mlist 13]
# puts stderr "freq: $freq, label: $label"
set bn [string toupper $bn]
if { $bn != ""} \
{
if { [info exists RBankID($bn)] == 0 } \
{
return "Invalid bank $bn."
}
}
if {$membankch != ""} \
{
if {($membankch < 0) || ($membankch > 99)} \
{
return "Invalid bank channel $membankch."
}
}
if { ($i < 0) || ($i > 999) } \
{
return "Invalid memory number $i."
}
if { ($freq < $GlobalParam(LowestFreq)) \
|| ($freq > $GlobalParam(HighestFreq)) } \
{
return "Invalid frequency $freq."
}
set nmode [string toupper $mode]
if {$nmode == ""} \
{
set nmode NFM
}
if { [info exists Mode($nmode)] == 0 } \
{
return "Invalid mode $mode."
}
set nstep $step
if {$nstep == ""} \
{
set nstep 5
}
if {[info exists Step($nstep)] == 0 } \
{
return "Invalid step $step."
}
if {$offset == ""} \
{
set noffset 0.000
} \
else \
{
set noffset [format "%.3f" $offset]
}
if { ($noffset < 0.0) || ($noffset > 159.995) } \
{
return "Invalid offset $offset."
}
# If duplex field consists of one or more spaces,
# translate it.
if { [regexp {^[[:blank:]]+$} $duplex] != 0} \
{
set duplex ""
}
if {($duplex != "") \
&& ($duplex != " ") \
&& ($duplex != "+") \
&& ($duplex != "-")} \
{
return "Invalid duplex flag $duplex."
}
if {$duplex == " "} \
{
set duplex ""
}
if {$toneflag == "d"} \
{
set ntoneflag d
} \
elseif {$toneflag == "t"} \
{
set ntoneflag t
} \
elseif {$toneflag == "b"} \
{
set ntoneflag b
} \
elseif {$toneflag == "p"} \
{
set ntoneflag p
} \
else \
{
set ntoneflag off
}
set nctcss $ctcss
if {$ctcss == ""} \
{
set nctcss 0.0
} \
elseif { [regexp {\.} $ctcss] == 0} \
{
# CTCSS code is probably an integer
# so append .0 to it.
set nctcss [format "%s.0" $ctcss]
}
if { [info exists Ctcss($nctcss)] == 0 } \
{
return "Invalid CTCSS code $ctcss."
}
set odcs $dcs
if {($dcs == "") || ($dcs == 0)} \
{
set dcs "023"
}
# Pad with zeroes on the left until there are 3 characters.
# This is to compensate for people who use Excel to
# edit csv files. Excel may ruthlessly trim leading zeroes.
set dcs [PadLeft0 3 $dcs]
if { [info exists Dcs($dcs)] == 0 } \
{
return "Invalid DCS code $odcs."
}
set polarity [string tolower $polarity]
if { ($polarity != "") && ($polarity != "normal") \
&& ($polarity != "n") && ($polarity != "r") \
&& ($polarity != "reverse") } \
{
return "Invalid DCS Polarity $polarity."
}
# Must be null, a space, skip, or pskip to be valid.
if {($skip != "") && ($skip != " ")} \
{
if { [info exists Skip($skip)] == 0 } \
{
return "Invalid skip value $skip."
}
}
ZapChannel $ch
set MemHide($ch) ""
set MemFreq($ch) [format "%.5f" $freq]
set MemMode($ch) $nmode
set MemStep($ch) $nstep
set MemOffset($ch) $noffset
set MemDuplex($ch) $duplex
set MemToneFlag($ch) $ntoneflag
set MemToneCode($ch) $nctcss
set MemDToneCode($ch) $dcs
set MemDTonePolarity($ch) $polarity
set MemSkip($ch) $skip
set MemBankLetter($ch) $bn
set MemBankCh($ch) $membankch
set s [string range $label 0 $endlabel]
set s [string trimright $s " "]
set MemLabel($ch) $s
return ""
}
##########################################################
# Read memory image from an open Goran Valaski .r2 file
#
# Inputs:
# fid -file descriptor
##########################################################
proc ReadR5File { fid }\
{
global GlobalParam
global Mimage
global Nmessages
global Pgm
# Read the first part of .r2 file one record at a time.
set image ""
for {set i 0} {$i < $Nmessages} {incr i} \
{
set line [read $fid 46]
set len [string length $line]
if {$len != 46} \
{
set msg "$Pgm: "
append msg "Corruption in .r2 file"
puts stderr $msg
tk_dialog .error "tk5" \
"Corrupted template file" \
error 0 OK
return -1
}
set cc [string index $line 4]
if { [string compare -nocase -length 1 $cc \xE4] } \
{
set msg "$Pgm: "
append msg "Corruption in template file"
puts stderr $msg
tk_dialog .error "tk5" \
"Corrupted template file" \
error 0 OK
return -1
}
set pline [PackString [string range $line 5 44]]
set plen [string length $pline]
set dbuf [string range $pline 0 18]
set cksum [string range $pline 19 19]
set ccksum [CalcCheckSum $dbuf]
binary scan $cksum "H*" icksum
scan $icksum "%x" cksum
# puts stderr [format "CHECKSUM file: %s, calculated: %s\n" \
# $cksum $ccksum]
if {$cksum != $ccksum} \
{
set msg [format \
"%s: error, checksum mismatch, radio: %s, calculated: %s\n" \
$Pgm $cksum $ccksum]
Tattle $msg
tk_dialog .error "Checksum error while reading file" \
$msg error 0 OK
return -1
}
# Strip off memory address and count bytes.
set buf [string range $dbuf 3 end]
# set buf [string range $pline 5 44]
# set abuf "$i) "
# append abuf [DumpBinary $buf]
# puts stderr $abuf
append image $buf
}
set Mimage $image
return 0
}
##########################################################
# Read memory image from an open Butel ARC2 .IC2 file
#
# Inputs:
# fid -file descriptor
##########################################################
proc ReadIC2File { fid }\
{
global GlobalParam
global Mimage
global Nmessages
global Pgm
# Read the first part of .r2 file one line at a time.
set image ""
for {set i 0} {$i < $Nmessages} {incr i} \
{
set len [gets $fid line]
if {$len < 40} \
{
set msg "$Pgm: "
append msg "Corruption in ARC .IC2 file"
puts stderr $msg
tk_dialog .error "tk5" \
"Corrupted ARC2 .IC2 file" \
error 0 OK
return -1
}
set line [string range $line 0 39]
set pline [binary format "H40" $line]
set plen [string length $pline]
set dbuf [string range $pline 0 18]
set cksum [string range $pline 19 19]
set ccksum [CalcCheckSum $dbuf]
binary scan $cksum "H*" icksum
scan $icksum "%x" cksum
# puts stderr [format "CHECKSUM file: %s, calculated: %s\n" \
# $cksum $ccksum]
if {$cksum != $ccksum} \
{
set msg [format \
"%s: error, checksum mismatch, radio: %s, calculated: %s\n" \
$Pgm $cksum $ccksum]
Tattle $msg
tk_dialog .error "Checksum error while reading file" \
$msg error 0 OK
return -1
}
# Strip off memory address and count bytes.
set buf [string range $dbuf 3 end]
# set buf [string range $pline 5 44]
# set abuf "$i) "
# append abuf [DumpBinary $buf]
# puts stderr $abuf
append image $buf
}
set Mimage $image
return 0
}
##########################################################
# Show memory channels in a window.
##########################################################
proc ShowChannels { f }\
{
global BankLabel
global Chb
global Chvector
global GlobalParam
global MemBankCh
global MemBankLetter
global MemDuplex
global MemFreq
global MemHide
global MemLabel
global MemMode
global MemOffset
global MemSkip
global MemStep
global MemDToneCode
global MemToneCode
global MemToneFlag
global NBanks
global RMode
set Chvector ""
if {$GlobalParam(EditMemoryChannels) == "on"} {return}
for {set ch 0} {$ch < 1000} {incr ch} \
{
if {($MemHide($ch) != "hide") \
&& ($MemFreq($ch) > 0.0001)} \
{
if { ($MemOffset($ch) < .001) \
|| ($MemDuplex($ch) == "") \
|| ($MemDuplex($ch) == " ") } \
{
set offset ""
} \
else \
{
set offset [format "%9.5f" \
$MemOffset($ch)]
}
if { $MemToneFlag($ch) == "d"} \
{
# DCS
set toneflag $MemToneFlag($ch)
set dtonecode $MemDToneCode($ch)
set tonecode ""
} \
elseif { $MemToneFlag($ch) == "p"} \
{
# DCS with pocket beep
set toneflag $MemToneFlag($ch)
set dtonecode $MemDToneCode($ch)
set tonecode ""
} \
elseif { $MemToneFlag($ch) == "t"} \
{
# CTCSS
set toneflag $MemToneFlag($ch)
set dtonecode ""
set tonecode $MemToneCode($ch)
} \
elseif { $MemToneFlag($ch) == "b"} \
{
# CTCSS with pocket beep
set toneflag $MemToneFlag($ch)
set dtonecode ""
set tonecode $MemToneCode($ch)
} \
else \
{
# presume Tone is off, so
# hide CTCSS the code.
set toneflag ""
set tonecode ""
set dtonecode ""
}
set mode [string toupper $MemMode($ch)]
set s [format "%3d %11.5f %-3s %5s %9s %1s %1s %5s %3s %-5s %1s %2s %-s" \
$ch $MemFreq($ch) \
$mode \
$MemStep($ch) \
$offset \
$MemDuplex($ch) \
$toneflag \
$tonecode \
$dtonecode \
$MemSkip($ch) \
$MemBankLetter($ch) \
$MemBankCh($ch) \
$MemLabel($ch)
]
lappend Chvector $s
} \
else \
{
# puts stderr "ch $ch, $MemSkip($ch)"
}
}
catch {destroy $f.lch}
set Chb [ List_channels $f.lch $Chvector 30 ]
# Force memory ch window to appear on top by hiding, then
# then showing it.
catch {wm withdraw $f}
catch {wm deiconify $f}
$Chb activate 1
pack $f.lch -side top
wm maxsize .vfo [winfo width .vfo] [winfo height .vfo]
return
}
##########################################################
# Export memory channels to a .csv file
##########################################################
proc ExportChannels { f }\
{
global FileTypes
global GlobalParam
global Home
global MemBankCh
global MemBankLetter
global MemDuplex
global MemFreq
global MemHide
global MemLabel
global MemMode
global MemOffset
global MemSkip
global MemStep
global MemDTonePolarity
global MemDToneCode
global MemToneCode
global MemToneFlag
global Mimage
global Ofilename
set endlabel $GlobalParam(LabelLength)
incr endlabel -1
if { ([info exists Mimage] == 0) \
|| ([string length $Mimage] <= 0) } \
{
set msg "You must read data from the radio"
append msg " before exporting channels."
append msg " (See the Radio menu.)"
tk_dialog .info "tk5" $msg info 0 OK
return
}
set Ofilename [Mytk_getSaveFile $f \
$GlobalParam(MemoryFileDir) \
.csv \
"Export memory channels to .csv file" \
$FileTypes]
if {$Ofilename != ""} \
{
# puts stderr "ExportChannels: Ofilename $Ofilename"
set GlobalParam(MemoryFileDir) [ Dirname $Ofilename ]
set fid [open $Ofilename "w"]
# Write first line as the field names.
puts -nonewline $fid [format "Mem,MHz,Mode,"]
puts -nonewline $fid [format "Step,Offset,Duplex,"]
puts -nonewline $fid [format "TSQL,CTCSS,DCS,Polarity,"]
puts $fid [format "Skip,Bank,Ch,Label"]
set s ""
for {set ch 0} {$ch < 1000} {incr ch} \
{
if {($MemHide($ch) == "hide") \
|| ($MemFreq($ch) == "") \
|| ($MemFreq($ch) <= .000001)} \
{
continue
}
if {$MemToneFlag($ch) == "t"} \
{
set toneflag t
} \
elseif {$MemToneFlag($ch) == "b"} \
{
set toneflag b
} \
elseif {$MemToneFlag($ch) == "d"} \
{
set toneflag d
} \
elseif {$MemToneFlag($ch) == "p"} \
{
set toneflag p
} \
else \
{
set toneflag ""
}
set skip $MemSkip($ch)
if {$skip == " "} \
{
set skip ""
}
set duplex $MemDuplex($ch)
if {$duplex == " "} \
{
set duplex ""
}
if { [info exists MemBankLetter($ch)] == 0} \
{
set bank ""
} \
else \
{
set bank $MemBankLetter($ch)
}
if { [info exists MemBankCh($ch)] == 0} \
{
set bchan ""
} \
else \
{
set bchan $MemBankCh($ch)
}
set s [format "%d,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s," \
$ch $MemFreq($ch) \
$MemMode($ch) \
$MemStep($ch) \
$MemOffset($ch) \
$duplex \
$toneflag \
$MemToneCode($ch) \
$MemDToneCode($ch) \
$MemDTonePolarity($ch) \
$skip \
$bank \
$bchan ]
if {$MemLabel($ch) != ""} \
{
set lab [string range \
$MemLabel($ch) 0 \
$endlabel]
set lab [string trimright $lab \
" "]
set lab [format "\"%s\"" $lab]
append s $lab
}
puts $fid $s
}
close $fid
tk_dialog .belch "Export" \
"Export Complete" info 0 OK
}
return
}
##########################################################
# Create a popup window which tells the user
# that the file already exists. Ask for guidance.
#
# Returns:
# Cancel
# Overwrite
##########################################################
proc FileExistsDialog { file } \
{
set result [tk_dialog .fed "Warning" \
"File $file already exists. Overwrite file?" \
warning 0 Cancel Overwrite ]
puts "result is $result"
return $result
}
##########################################################
# Copy memory image to the radio
##########################################################
proc Image2Radio { f }\
{
global FileTypes
global Mimage
global ReadRadioFlag
if { ([info exists Mimage] == 0) \
|| ([string length $Mimage] <= 0)} \
{
# No image to write.
set msg "You must first read template data from"
append msg " the radio or a file before"
append msg " writing it to the radio."
tk_dialog .error "Write to radio" $msg error 0 OK
}
if {$ReadRadioFlag == "yes"} \
{
# We read an image from the radio.
# Cannot read from and write to the radio
# during the same session or else the radio
# complains. (Reason unknown.)
#
# Tell user to save the image file, exit
# the program, restart the program, read
# the image file, then write to the radio.
set msg ""
append msg "You cannot read from the radio "
append msg "and write to the radio during the same "
append msg "session.\n\n"
append msg "Please:\n"
append msg "1) Save the memory image in a file,\n"
append msg "using File --> Save As ...\n"
append msg "2) Exit this program.\n"
append msg "3) Restart this program.\n"
append msg "4) Open the image file you saved "
append msg "previously, using File --> Open ...\n "
append msg "5) Then, you can write the image "
append msg "to the radio."
tk_dialog .belch "Write blocked warning" \
$msg warning 0 OK
return
}
if {[ValidateData]} {return}
MakeWait
EncodeImage
KillWait
set msg ""
append msg "Instructions:\n"
append msg "1) Ensure the radio is connected to"
append msg " your computer and radio power is on.\n"
set result [tk_dialog .info "Write to IC-R5" \
$msg \
info 0 OK Cancel ]
if {$result} \
{
# User canceled the write.
return
}
set wcode [WriteImage]
if {$wcode == 1} \
{
set msg "Error while writing to the radio."
tk_dialog .error "Write error" $msg error 0 OK
KillWait
} \
elseif {$wcode == 2} \
{
set msg "Error, cannot read radio version info."
tk_dialog .error "Write error" $msg error 0 OK
KillWait
} \
else \
{
set msg "Transfer Complete.\n"
append msg "Look at the radio display "
append msg "to view a status message."
tk_dialog .belch "Transfer Complete" \
$msg info 0 OK
}
return
}
###################################################################
# Return 1 if frequency is in range 0 - 2000 exclusive.
###################################################################
proc FreqInRange { f units } \
{
if {$units == "mhz" } \
{
if { $f > 0 && $f < 2000.0 } \
{
return 1
}
} \
elseif {$units == "khz" } \
{
if { $f > 0 && $f < 2000000.0 } \
{
return 1
}
}
return 0
}
###################################################################
# Return 1 if string 's' is a valid frequency.
# Return 0 otherwise.
#
# Units should be kHz or MHz
###################################################################
proc CheckFreqValid { s units }\
{
if {$s == ""} then {return 0}
# Check for non-digit and non decimal point chars.
set rc [regexp {^[0-9.]*$} $s]
if {$rc == 0} then {return 0}
# All digits.
set rc [regexp {^[0-9]*$} $s]
if {$rc == 1} \
{
return [FreqInRange $s $units]
}
if {$s == "."} then {return 0}
# Check for Two or more decimal points
set tmp $s
set tmp [split $s "."]
set n [llength $tmp]
if { $n >= 3 } then {return 0}
return [FreqInRange $s $units]
}
###################################################################
# Set default receiver parameters
###################################################################
proc SetUp { } \
{
global env
global GlobalParam
global RootDir
global tcl_platform
if { [regexp "Darwin" $tcl_platform(os) ] } \
{
# For Mac OS X.
set RootDir ":"
} \
else \
{
set RootDir "/"
}
set GlobalParam(Debug) 0
# set GlobalParam(Device) /dev/ttyS1
set GlobalParam(Ifilename) {}
set GlobalParam(MemoryFileDir) $RootDir
set GlobalParam(PreviousFreq) 0.0
return
}
###################################################################
#
# Define receiver parameters before we read the
# global parameter configuration file in case they are missing
# from the configuration file.
# This avoids a tcl error if we tried to refer to an
# undefined variable.
#
# These initial definitions will be overridden with
# definitions from the configuration file.
#
###################################################################
proc PresetGlobals { } \
{
global GlobalParam
global Mode
global Rcfile
global RootDir
global tcl_platform
set GlobalParam(BalloonHelpWindows) on
set GlobalParam(AMantenna) EXT
set GlobalParam(Attenuator) 0
set GlobalParam(AutoOff) OFF
set GlobalParam(BackGroundColor) ""
set GlobalParam(BankScan) 0
set GlobalParam(BankSort) -1
set GlobalParam(BatterySaver) 1
set GlobalParam(Beep) 1
set GlobalParam(CableEchos) 1
set GlobalParam(Contrast) 2
set GlobalParam(Debug) 0
set GlobalParam(Dial) 1MHz
set GlobalParam(DialAccel) 1
set GlobalParam(DTRline) 12
set GlobalParam(EditMemoryChannels) off
set GlobalParam(EditMemoryChannelsNext) \
$GlobalParam(EditMemoryChannels)
set GlobalParam(FMantenna) EXT
set GlobalParam(Font) ""
set GlobalParam(ForeGroundColor) ""
set GlobalParam(Lamp) AUTO
set GlobalParam(LimitSearch) 0
set GlobalParam(Lock) 0
set GlobalParam(LockEffect) NORMAL
set GlobalParam(MemoryFileDir) $RootDir
set GlobalParam(Mode) $Mode(NFM)
set GlobalParam(Monitor) PUSH
set GlobalParam(Pause) 10
set GlobalParam(PowerSave) 1
set GlobalParam(RadioVersion) ""
set GlobalParam(Resume) 2
set GlobalParam(DTRline) 12
set GlobalParam(RTSline) -12
set GlobalParam(ScanStopBeep) 0
set GlobalParam(SetMenuItem) 0
set GlobalParam(TroughColor) ""
set GlobalParam(TuningStep) 5
set GlobalParam(VFOSearch) ALL
set GlobalParam(VFOFreq) 162.4000
set GlobalParam(WhichModel) 10
set GlobalParam(WXFreq) 162.55
set GlobalParam(WXMode) AUTO
return
}
###################################################################
# Set global variables after reading the global
# configuration file so these settings override
# whatever values were in the configuration file.
###################################################################
proc OverrideGlobals { } \
{
global env
global GlobalParam
global RootDir
global tcl_platform
set GlobalParam(BypassAllEncoding) 0
set GlobalParam(EditMemoryChannelsNext) \
$GlobalParam(EditMemoryChannels)
set GlobalParam(FileVersion) " "
set GlobalParam(Ifilename) {}
set GlobalParam(LowestFreq) .100
set GlobalParam(HighestFreq) 1309.995
set GlobalParam(LabelLength) 6
set GlobalParam(NmsgsRead) 0
set GlobalParam(Populated) 0
set GlobalParam(SortBank) 0
set GlobalParam(SortType) freq
set GlobalParam(TemplateFilename) {}
set GlobalParam(UserComment) " "
set GlobalParam(UserPort) 0
# Note on MacOS X:
# The initial directory passed to the file chooser widget.
# The problem here is that osx's tcl is utterly busted.
# The _only_ pathname it accepts is ':' - no other ones work.
# Now this isn't as bad as you might think because
# the native macos file selector widget persistantly
# remembers the last place you opened/saved a file
# for a particular application. So the logic to
# remember this is simply redundant on macos anyway...
# Presumably they'll fix this someday and we can take
# out the hack.
# - Ben Mesander
if { [regexp "Darwin" $tcl_platform(os) ] } \
{
# kluge for MacOS X.
set GlobalParam(LogFileDir) $RootDir
set GlobalParam(MemoryFileDir) $RootDir
if {$GlobalParam(Ifilename) != ""} \
{
set GlobalParam(Ifilename) $RootDir
}
}
return
}
###################################################################
#
# Parse data from inside the memory image and store it
# in global arrays.
#
###################################################################
proc DecodeImage { } \
{
global MemFreq
global MemDuplex
global MemMode
global MemOffset
global MemStep
global MemToneCode
global MemToneFlag
MakeWait
update idletasks
ZapBankLabels
for {set ch 0} {$ch < 1000} {incr ch} \
{
ZapChannel $ch
}
DecodeMisc
DecodeMemories
DecodeBankLabels
DecodeSearchBanks
DecodeTV
DecodeHiddenTVChannelFlags
DecodeSkipTVChannelFlags
update idletasks
KillWait
update idletasks
return
}
###################################################################
#
# Parse data from inside the memory image and store it
# in global arrays.
#
###################################################################
proc DecodeMisc { } \
{
global GlobalParam
global ImageAddr
global Mimage
global Priority
global PriorityMode
global RAMant
global RAutoOff
global RDial
global RFMant
global RBatterySaver
global RMode
global RMonitor
global RLockEffect
global RLamp
global RFstep
global RPause
global RResume
global RStep
# # Parse file version
# scan $ImageAddr(FileVersion) "%x" first
# set last [expr {$first + 15}]
# set GlobalParam(FileVersion) \
# [string range $Mimage $first $last]
#
# # Parse user comment
# scan $ImageAddr(UserComment) "%x" first
# set last [expr {$first + 15}]
# set GlobalParam(UserComment) \
# [string range $Mimage $first $last]
# Parse Lock function effect
scan $ImageAddr(LockEffect) "%x" first
set s [string range $Mimage $first $first]
set n [Char2Int $s]
if { [info exists RLockEffect($n)] } \
{
set GlobalParam(LockEffect) $RLockEffect($n)
} \
else \
{
set GlobalParam(LockEffect) NORMAL
}
# Parse dial acceleration flag
scan $ImageAddr(DialAccel) "%x" first
set byte [string range $Mimage $first $first]
set GlobalParam(DialAccel) [Char2Int $byte]
# Parse power save flag
scan $ImageAddr(PowerSave) "%x" first
set byte [string range $Mimage $first $first]
set GlobalParam(PowerSave) [Char2Int $byte]
# # Parse bank scan flag
# scan $ImageAddr(BankScan) "%x" first
# set byte [string range $Mimage $first $first]
# set GlobalParam(BankScan) [Char2Int $byte]
#
# Parse beep tone, on or off flag
scan $ImageAddr(Beep) "%x" first
set byte [string range $Mimage $first $first]
set GlobalParam(Beep) [Char2Int $byte]
# # parse Tuning Step
# scan $ImageAddr(VFOStep) "%x" first
# set byte [string range $Mimage $first $first]
# binary scan $byte "H2" s
#
# if { [info exists RStep($s)] } \
# {
# set GlobalParam(TuningStep) $RStep($s)
# } \
# else \
# {
# set GlobalParam(TuningStep) AUTO
# }
#
# # Parse VFO/Limit Search bit
# scan $ImageAddr(FlagByte0) "%x" first
# set s [string range $Mimage $first $first]
# set GlobalParam(LimitSearch) [GetBit $s 3]
# Parse Auto Power Off
scan $ImageAddr(AutoOff) "%x" first
set s [string range $Mimage $first $first]
set n [Char2Int $s]
if { [info exists RAutoOff($n)] } \
{
set GlobalParam(AutoOff) $RAutoOff($n)
} \
else \
{
set GlobalParam(AutoOff) OFF
}
# parse Expanded Set Mode Flag
scan $ImageAddr(ExpandedSetModeFlag) "%x" first
set s [string range $Mimage $first $first]
set GlobalParam(ExpandedSetMode) [Char2Int $s]
# parse Scan stop beep flag
scan $ImageAddr(ScanStopBeep) "%x" first
set s [string range $Mimage $first $first]
set GlobalParam(ScanStopBeep) [Char2Int $s]
# Parse Dial
scan $ImageAddr(DialStep) "%x" first
set s [string range $Mimage $first $first]
set n [Char2Int $s]
if { [info exists RDial($n)] } \
{
set GlobalParam(Dial) $RDial($n)
} \
else \
{
set GlobalParam(Dial) 1MHz
}
# decode display contrast
# contrast is stored in the image as one less.
scan $ImageAddr(Contrast) "%x" first
set s [string range $Mimage $first $first]
set n [Char2Int $s]
if { ($n >= 0) && ($n <= 3) } \
{
incr n
set GlobalParam(Contrast) $n
} \
else \
{
set GlobalParam(Contrast) 2
}
scan $ImageAddr(Lamp) "%x" first
set s [string range $Mimage $first $first]
set n [Char2Int $s]
if { [info exists RLamp($n)] } \
{
set GlobalParam(Lamp) $RLamp($n)
} \
else \
{
set GlobalParam(Lamp) AUTO
}
# parse AM antenna
scan $ImageAddr(AMantenna) "%x" first
set s [string range $Mimage $first $first]
set n [Char2Int $s]
if { [info exists RAMant($n)] } \
{
set GlobalParam(AMantenna) $RAMant($n)
} \
else \
{
set GlobalParam(AMantenna) EXT
}
# parse FM antenna
scan $ImageAddr(FMantenna) "%x" first
set s [string range $Mimage $first $first]
set n [Char2Int $s]
if { [info exists RFMant($n)] } \
{
set GlobalParam(FMantenna) $RFMant($n)
} \
else \
{
set GlobalParam(FMantenna) EXT
}
scan $ImageAddr(Pause) "%x" first
set s [string range $Mimage $first $first]
set n [Char2Int $s]
if { [info exists RPause($n)] } \
{
set GlobalParam(Pause) $RPause($n)
} \
else \
{
set GlobalParam(Pause) 2
}
scan $ImageAddr(Resume) "%x" first
set s [string range $Mimage $first $first]
set n [Char2Int $s]
if { [info exists RResume($n)] } \
{
set GlobalParam(Resume) $RResume($n)
} \
else \
{
set GlobalParam(Resume) 2
}
# Monitor key
scan $ImageAddr(Monitor) "%x" first
set s [string range $Mimage $first $first]
set n [Char2Int $s]
if { [info exists RMonitor($n)] } \
{
set GlobalParam(Monitor) $RMonitor($n)
} \
else \
{
set GlobalParam(Monitor) PUSH
}
# # Parse Fast Tuning Step
# scan $ImageAddr(FastTuningStep) "%x" first
# set s [string range $Mimage $first $first]
# set n [Char2Int $s]
# if { [info exists RFstep($n)] } \
# {
# set GlobalParam(FastTuningStep) $RFstep($n)
# } \
# else \
# {
# set GlobalParam(FastTuningStep) 1MHz
# }
return
}
###################################################################
#
# Parse data from inside the memory image and store it
# in global arrays.
#
# NOTES:
# Each memory channel is represented by 8 consecutive bytes.
# The first 3 bytes contain the frequency digits in hex.
# The most significant nibble in the first byte is 0-E.
# Frequencies of 1000 MHz and higher start with a letter.
#
# The fourth byte is a little strange. It contains both the
# simplex/duplex flag and part of the offset
#
#
###################################################################
proc DecodeMemories { } \
{
global BankID
global CtcssBias
global Mimage
global MemBankLetter
global MemBankCh
global MemDuplex
global MemFreq
global MemHide
global MemLabel
global MemMode
global MemOffset
global MemSkip
global MemStep
global MemDToneCode
global MemDTonePolarity
global MemToneCode
global MemToneFlag
global ImageAddr
global RCtcss
global RDcs
global RMode
global RSkip
global RStep
global ToneFlag
# Parse memory channel frequencies.
scan $ImageAddr(MemoryFreqs) "%x" first
set last [expr {$first + 2}]
for {set ch 0} {$ch < 1000} {incr ch} \
{
set s [string range $Mimage $first $last]
set f [Internal2Freq3 $s]
if {$f < .001} \
{
set MemFreq($ch) ""
} \
else \
{
set MemFreq($ch) $f
}
incr first 16
incr last 16
}
# Parse memory channel offset frequencies.
scan $ImageAddr(MemoryOffset) "%x" first
set last [expr {$first + 1}]
scan $ImageAddr(MemoryMult) "%x" mfirst
for {set ch 0} {$ch < 1000} {incr ch} \
{
set s [string range $Mimage $first $last]
set m [string index $Mimage $mfirst]
set f [Offset2Freq $s $m]
if {$f < .001} {set f ""}
set MemOffset($ch) $f
incr first 16
incr last 16
incr mfirst 16
}
# Parse memory channel duplex/simplex flag.
scan $ImageAddr(MemoryDuplex) "%x" first
for {set ch 0} {$ch < 1000} {incr ch} \
{
set MemDuplex($ch) " "
set byte [string range $Mimage $first $first]
set n [GetBitField $byte 6 7]
if {$n == 0}\
{
set MemDuplex($ch) " "
} \
elseif {$n == 1} \
{
set MemDuplex($ch) "-"
} \
elseif {$n == 2} \
{
set MemDuplex($ch) "+"
} \
else \
{
set MemDuplex($ch) " "
}
incr first 16
incr last 16
}
# Parse memory channel mode.
scan $ImageAddr(MemoryModes) "%x" first
for {set ch 0} {$ch < 1000} {incr ch} \
{
set byte [string range $Mimage $first $first]
set m [GetBitField $byte 4 5]
if { [info exists RMode($m)] } \
{
set MemMode($ch) $RMode($m)
} \
else \
{
set MemMode($ch) NFM
}
incr first 16
incr last 16
}
# Parse memory channel tone flag.
scan $ImageAddr(MemoryToneFlag) "%x" first
for {set ch 0} {$ch < 1000} {incr ch} \
{
set byte [string range $Mimage $first $first]
set m [GetBitField $byte 0 3]
if { [info exists ToneFlag($m)] } \
{
set MemToneFlag($ch) $ToneFlag($m)
} \
else \
{
set MemToneFlag($ch) "off"
}
incr first 16
incr last 16
}
# Parse memory CTCSS tone code.
scan $ImageAddr(MemoryToneCode) "%x" first
for {set ch 0} {$ch < 1000} {incr ch} \
{
set MemToneCode($ch) "0.0"
set byte [string range $Mimage $first $first]
set n [Char2Int $byte]
# fix me
incr n $CtcssBias
if { [info exists RCtcss($n)] } \
{
set MemToneCode($ch) $RCtcss($n)
} \
else \
{
set MemToneCode($ch) "0.0"
}
incr first 16
incr last 16
}
# Parse memory DCS tone code.
scan $ImageAddr(MemoryDToneCode) "%x" first
for {set ch 0} {$ch < 1000} {incr ch} \
{
set MemDToneCode($ch) "0"
set byte [string range $Mimage $first $first]
if { [GetBitField $byte 0 0] } \
{
set MemDTonePolarity($ch) r
} \
else \
{
set MemDTonePolarity($ch) n
}
set n [GetBitField $byte 1 7]
if { [info exists RDcs($n)] } \
{
set MemDToneCode($ch) $RDcs($n)
} \
else \
{
set MemDToneCode($ch) "023"
}
incr first 16
incr last 16
}
# Parse skip field.
scan $ImageAddr(MemorySkip) "%x" first
for {set ch 0} {$ch < 1000} {incr ch} \
{
set byte [string range $Mimage $first $first]
set n [GetBitField $byte 1 2]
if { [info exists RSkip($n)] } \
{
set MemSkip($ch) $RSkip($n)
} \
else \
{
set MemSkip($ch) " "
}
incr first 2
incr last 2
}
# Parse bank letter field.
scan $ImageAddr(MemoryBankNumber) "%x" first
for {set ch 0} {$ch < 1000} {incr ch} \
{
set byte [string range $Mimage $first $first]
if { [string compare -nocase -length 1 $byte \xff] == 0} \
{
# hidden memory channel, not programmed
set MemHide($ch) "hide"
} \
else \
{
set MemHide($ch) ""
}
set n [GetBitField $byte 3 7]
if {$n == 31} \
{
# no bank
set MemBankLetter($ch) ""
}
if { [info exists BankID($n)] } \
{
set MemBankLetter($ch) $BankID($n)
} \
else \
{
set MemBankLetter($ch) ""
}
incr first 2
incr last 2
}
# Parse bank memory channel field.
scan $ImageAddr(MemoryBankCh) "%x" first
for {set ch 0} {$ch < 1000} {incr ch} \
{
set byte [string range $Mimage $first $first]
if { [string compare -nocase -length 1 $byte \xff] == 0} \
{
# no bank channel
set MemBankCh($ch) ""
} \
else \
{
set n [GetBitField $byte 1 7]
if {$n <= 99} \
{
set MemBankCh($ch) $n
} \
else \
{
# invalid channel
set MemBankCh($ch) ""
}
}
incr first 2
incr last 2
}
# Parse memory channel step size.
scan $ImageAddr(MemorySteps) "%x" first
for {set ch 0} {$ch < 1000} {incr ch} \
{
set byte [string range $Mimage $first $first]
set n [GetBitField $byte 0 3]
if { [info exists RStep($n)] } \
{
set MemStep($ch) $RStep($n)
} \
else \
{
set MemStep($ch) 5
}
incr first 16
incr last 16
}
# Parse label field.
scan $ImageAddr(MemoryLabels) "%x" first
set last [expr {$first + 4}]
for {set ch 0} {$ch < 1000} {incr ch} \
{
set s [string range $Mimage $first $last]
set MemLabel($ch) [Internal2MemoryLabel $s]
incr first 16
incr last 16
}
# Parse the hide field.
scan $ImageAddr(MemoryBankNumber) "%x" first
for {set ch 0} {$ch < 1000} {incr ch} \
{
set byte [string range $Mimage $first $first]
if { [string compare -nocase -length 1 $byte \xff] == 0} \
{
# hidden memory channel, not programmed
ZapChannel $ch
set MemHide($ch) "hide"
} \
else \
{
set MemHide($ch) ""
}
incr first 2
}
return
}
###################################################################
#
# Parse data from inside the memory image and store it
# in global arrays.
#
###################################################################
proc DecodeTV { } \
{
global ImageAddr
global TV
global Mimage
# Parse TV channel frequencies.
scan $ImageAddr(TVFreq) "%x" first
set last [expr {$first + 2}]
for {set ch 0} {$ch < 70} {incr ch} \
{
set s [string range $Mimage $first $last]
set f [Internal2TV3 $s]
if {$f < .001} \
{
set TV($ch,freq) ""
} \
else \
{
set TV($ch,freq) $f
}
# puts stderr "tv ch: $ch, f: $f"
incr first 8
incr last 8
}
# Parse TV channel mode.
scan $ImageAddr(TVMode) "%x" first
for {set ch 0} {$ch < 70} {incr ch} \
{
set byte [string index $Mimage $first]
if { [string compare -nocase -length 1 $byte \x01] == 0} \
{
# WFM
set TV($ch,mode) WFM
} \
elseif { [string compare -nocase -length 1 $byte \x02] == 0} \
{
# AM
set TV($ch,mode) AM
} \
else \
{
# Bogus mode
puts -nonewline stderr "TV channel $ch, "
puts stderr "unknown mode. Defaulting to WFM."
set TV($ch,mode) WFM
}
incr first 8
}
# Parse label field.
scan $ImageAddr(TVLabel) "%x" first
set last [expr {$first + 3}]
for {set ch 0} {$ch < 70} {incr ch} \
{
set s [string range $Mimage $first $last]
# Translate bogus characters to spaces
regsub -all {[^A-Za-z0-9 .,\+\*/()\-=]} $s " " s
# Labels must be upper case.
set s [string toupper $s]
set TV($ch,label) $s
incr first 8
incr last 8
}
# Parse hide field.
scan $ImageAddr(TVHide) "%x" first
for {set ch 0} {$ch < 70} {incr ch} \
{
# fix me
set TV($ch,hide) 0
}
# Parse skip field.
DecodeSkipTVChannelFlags
return
}
###################################################################
#
# Parse data from inside the memory image and store it
# in global arrays.
#
###################################################################
proc DecodeBankLabels { } \
{
global BankLabel
global GlobalParam
global Mimage
global ImageAddr
# Parse bank names.
scan $ImageAddr(BankLabels) "%x" first
set last [expr {$first + 5}]
for {set bn 0} {$bn < 18} {incr bn} \
{
set s [string range $Mimage $first $last]
set BankLabel($bn) [Internal2BankLabel $s]
incr first 6
incr last 6
}
return
}
###################################################################
# Encode the bank labels into a memory image.
###################################################################
proc EncodeBankLabels { image } \
{
global BankLabel
global GlobalParam
global Mimage
global ImageAddr
# Bank names.
scan $ImageAddr(BankLabels) "%x" first
set last [expr {$first + 5}]
for {set bn 0} {$bn < 18} {incr bn} \
{
set s [BankLabel2Internal $BankLabel($bn)]
set image [string replace $image $first $last $s]
incr first 6
incr last 6
}
return $image
}
###################################################################
#
# Parse data from inside the memory image and store it
# in global arrays.
#
###################################################################
proc DecodeSearchBanks { } \
{
global LimitScan
global Mimage
global ImageAddr
global RMode
global RStep
# Parse search bank lower hidden flag.
scan $ImageAddr(SearchHideFirst) "%x" first
for {set bn 0} {$bn < 25} {incr bn} \
{
set byte [string range $Mimage $first $first]
if { [string compare -nocase -length 1 $byte \xff] == 0} \
{
# hidden bank, not programmed
set LimitScan($bn,lhide) "hide"
set LimitScan($bn,lower) ""
} \
else \
{
set LimitScan($bn,lhide) ""
}
incr first 4
}
# Parse search bank upper hidden flag.
scan $ImageAddr(SearchHideSecond) "%x" first
for {set bn 0} {$bn < 25} {incr bn} \
{
set byte [string range $Mimage $first $first]
if { [string compare -nocase -length 1 $byte \xff] == 0} \
{
# hidden bank, not programmed
set LimitScan($bn,uhide) "hide"
set LimitScan($bn,upper) ""
} \
else \
{
set LimitScan($bn,uhide) ""
}
incr first 4
}
# Parse search bank frequencies.
scan $ImageAddr(SearchFreqFirst) "%x" first
set last [expr {$first + 2}]
for {set bn 0} {$bn < 25} {incr bn} \
{
set s [string range $Mimage $first $last]
set f [Internal2Freq3 $s]
if {($LimitScan($bn,lhide) == "hide") \
|| ($f < .001)} \
{
set LimitScan($bn,lower) ""
} \
else \
{
set LimitScan($bn,lower) $f
}
incr first 32
incr last 32
}
# Parse seach bank frequencies.
scan $ImageAddr(SearchFreqSecond) "%x" first
set last [expr {$first + 2}]
for {set bn 0} {$bn < 25} {incr bn} \
{
set s [string range $Mimage $first $last]
set f [Internal2Freq3 $s]
if {($LimitScan($bn,uhide) == "hide") \
|| ($f < .001)} \
{
set LimitScan($bn,upper) ""
} \
else \
{
set LimitScan($bn,upper) $f
}
incr first 32
incr last 32
}
# Parse mode.
scan $ImageAddr(SearchModeFirst) "%x" first
for {set bn 0} {$bn < 25} {incr bn} \
{
set byte [string range $Mimage $first $first]
set m [GetBitField $byte 4 5]
if { [info exists RMode($m)] } \
{
set LimitScan($bn,lmode) $RMode($m)
} \
else \
{
set LimitScan($bn,lmode) NFM
}
incr first 32
incr last 32
}
scan $ImageAddr(SearchModeSecond) "%x" first
for {set bn 0} {$bn < 25} {incr bn} \
{
set byte [string range $Mimage $first $first]
set m [GetBitField $byte 4 5]
if { [info exists RMode($m)] } \
{
set LimitScan($bn,umode) $RMode($m)
} \
else \
{
set LimitScan($bn,umode) NFM
}
incr first 32
incr last 32
}
# Parse step size.
scan $ImageAddr(SearchStepFirst) "%x" first
for {set bn 0} {$bn < 25} {incr bn} \
{
set byte [string range $Mimage $first $first]
set n [GetBitField $byte 0 3]
if { [info exists RStep($n)] } \
{
set LimitScan($bn,lstep) $RStep($n)
} \
else \
{
set LimitScan($bn,lstep) 5
}
incr first 32
incr last 32
}
scan $ImageAddr(SearchStepSecond) "%x" first
for {set bn 0} {$bn < 25} {incr bn} \
{
set byte [string range $Mimage $first $first]
set n [GetBitField $byte 0 3]
if { [info exists RStep($n)] } \
{
set LimitScan($bn,ustep) $RStep($n)
} \
else \
{
set LimitScan($bn,ustep) 5
}
incr first 32
incr last 32
}
# Parse lower label.
scan $ImageAddr(SearchLabelFirst) "%x" first
set last [expr {$first + 5}]
for {set bn 0} {$bn < 25} {incr bn} \
{
set s [string range $Mimage $first $last]
set LimitScan($bn,llabel) [Internal2MemoryLabel $s]
incr first 32
incr last 32
}
# Parse upper label.
scan $ImageAddr(SearchLabelSecond) "%x" first
set last [expr {$first + 5}]
for {set bn 0} {$bn < 25} {incr bn} \
{
set s [string range $Mimage $first $last]
set LimitScan($bn,ulabel) [Internal2MemoryLabel $s]
incr first 32
incr last 32
}
return
}
###################################################################
# Decode a 3 byte BCD frequency.
#
# Returns: frequency in MHz
###################################################################
proc BCD2Freq3 { s } \
{
global GlobalParam
# Note: Icom packs two digits per byte, one per nibble.
# An important exception is the most significant nibble
# in the most significant byte. That nibble can be
# 0-9 or a-f.
# a-f means 10-15.
# set abuf ""
# append abuf [DumpBinary $s]
# puts stderr "s: $abuf"
if {[string length $s] == 0} \
{
return "0.0000"
}
binary scan $s "H6" as
if {$GlobalParam(WhichModel) == 9} \
{
if { $as == "ffffff" } {return "0.0000"} \
else \
{
set rc [regexp {ffff$} $as]
if {$rc} \
{
# The last 2 bytes are ff
# which means
# 9 kHz spacing and
# freqency is .495 - 1.620 MHz
# Multiply value in first byte
# by .009 and add it to .495
set b [string index $s 0]
binary scan $b "H2" imult
scan $imult "%x" mult
set f [expr {($mult * .009) + .495}]
set f [format "%.4f" $f]
return $f
}
}
}
# Frequency digit pairs.
set i 0
set f1 [string index $s $i]
binary scan $f1 "H2" f1
regsub -nocase {a} $f1 10 f1
regsub -nocase {b} $f1 11 f1
regsub -nocase {c} $f1 12 f1
regsub -nocase {d} $f1 13 f1
regsub -nocase {e} $f1 14 f1
regsub -nocase {f} $f1 15 f1
incr i
set f2 [string index $s $i]
binary scan $f2 "H2" f2
incr i
set f3 [string index $s $i]
binary scan $f3 "H2" f3
incr i
set f [format "%s%s%s" $f1 $f2 $f3]
set f [string trimleft $f 0]
if { $f == ""} \
{
set f "00000000"
}
# Check for non-digit chars.
set rc [regexp {^[0-9]*$} $f]
if {$rc == 0} then {set f "00000000"}
set f [expr {$f/1000.0}]
set f [ format "%.4f" $f]
if {($GlobalParam(WhichModel) == 9) \
&& ($f >= .495) && ($f <= 1.620)} \
{
return [format "%.5f" $f]
}
set len [string length $f]
set j [expr {$len - 2}]
set c [string index $f $j]
if {($c == "2") || ($c == "7")} \
{
# If the kHz position digit is a 2 or 5,
# force the last digit to be 5.
set f [string replace $f end end 5]
} \
elseif {($c == "1") || ($c == "6")} \
{
# If the kHz position digit is a 1 or 6,
# force the last digit to be 2.
set f [string replace $f end end 2]
} \
elseif {($c == "3") || ($c == "8")} \
{
# If the kHz position digit is a 3 or 8,
# force the last digit to be 7.
set f [string replace $f end end 7]
}
return [format "%.5f" $f]
}
###################################################################
# Decode a 3 byte internally-represented frequency.
#
# Returns: frequency in MHz
###################################################################
proc Internal2Freq3 { s } \
{
global GlobalParam
global RIstep
# set abuf [DumpBinary $s]
# puts stderr "s: $abuf"
if {[string length $s] == 0} \
{
return "0.0000"
}
set b0 [string index $s 0]
set b1 [string index $s 1]
set b2 [string index $s 2]
set n0 [Char2Int $b0]
set n1 [Char2Int $b1]
set n2 [GetBitField $b2 6 7]
set nstep [GetBitField $b2 2 3]
if { [info exists RIstep($nstep)] } \
{
set step [expr {$RIstep($nstep) / 1000.0}]
} \
else \
{
puts stderr "invalid step $nstep"
exit
}
set step $RIstep($nstep)
set mult [expr { ($n2 * 256 * 256) + ($n1 * 256) + $n0}]
set freq [ expr { $mult * $step/ 1000.0 } ]
# puts stderr "nstep: $nstep, mult: $mult, freq: $freq"
set f $freq
return [format "%.5f" $f]
}
###################################################################
# Decode a 3 byte internally-represented TV channel frequency.
#
# Returns: frequency in MHz
###################################################################
proc Internal2TV3 { s } \
{
global GlobalParam
# set abuf [DumpBinary $s]
# puts stderr "s: $abuf"
if {[string length $s] == 0} \
{
return "0.0000"
}
set b0 [string index $s 0]
set b1 [string index $s 1]
set b2 [string index $s 2]
set n0 [Char2Int $b0]
set n1 [Char2Int $b1]
set n2 [Char2Int $b2]
set mult [expr { ($n2 * 256 * 256) + ($n1 * 256) + $n0}]
set freq [ expr { $mult * 5/ 1000.0 } ]
set f $freq
return [format "%.3f" $f]
}
###################################################################
# Encode a frequency into a 3 byte internally-represented TV frequency.
#
# Returns: 3-byte string
###################################################################
proc TV2Internal3 { f } \
{
global GlobalParam
if { ($f <= .0) } \
{
set bytes [binary format "H2H2H2" 00 00 00]
return $bytes
}
# Convert frequency to kHz, then divide by 5
# because it is the number of 5 kHz steps.
set nf [expr {$f * 200}]
set nf [expr {int($nf)}]
# The most significant bits go in the final byte.
set n2 [expr {$nf / (256 * 256)}]
set n2 [expr {int($n2)}]
# The least significant bits go in the first byte.
set tmp [expr {$nf / (256)}]
set tmp [expr {int($tmp)}]
set tmp [expr {256 * $tmp}]
set n0 [expr {$nf - $tmp}]
# The most middle bits go in the middle byte.
set tmp [expr {($n2 * 256 * 256) + $n0}]
set n1 [expr {($nf - $tmp)/256}]
set n1 [expr {int($n1)}]
set h0 [format "%02x" $n0]
set h1 [format "%02x" $n1]
set h2 [format "%02x" $n2]
set bytes [binary format "H2H2H2" $h0 $h1 $h2]
# set buf [DumpBinary $bytes]
# puts stderr "TV2Internal3: f: $f, bytes: $buf"
return $bytes
}
###################################################################
# Decode an internally-represented offset.
#
# Inputs;
# s - a 2-byte string
# m - a 1-byte string which contains the multiplier
# coded in the two most significant bits
#
# Returns: frequency in MHz
###################################################################
proc Offset2Freq { s m } \
{
global GlobalParam
global RIstep
set sbuf [DumpBinary $s]
set mbuf [DumpBinary $m]
if { ($s == 0) || ($m == "") } \
{
return "0.0000"
}
set b0 [string index $s 0]
set b1 [string index $s 1]
set n0 [Char2Int $b0]
set n1 [Char2Int $b1]
set nstep [GetBitField $m 0 1]
if { [info exists RIstep($nstep)] } \
{
set step [expr {$RIstep($nstep) / 1000.0}]
} \
else \
{
puts stderr "invalid step $nstep"
exit
}
set step $RIstep($nstep)
set mult [expr { ($n1 * 256) + $n0}]
set freq [ expr { $mult * $step/ 1000.0 } ]
# puts stderr "nstep: $nstep, mult: $mult, freq: $freq"
set f [format "%.5f" $freq]
# puts stderr "s: $sbuf, m: $mbuf, freq: $f"
return $f
}
###################################################################
# Encode a frequency into a 2 byte internally-represented value.
# This is used for encoding duplex offset values, which consist
# of a 2-byte number and a multiplier.
#
# Inputs:
# f -frequency between 0 and 159.995 MHz
# step -step size in kHz
#
# Returns:
# a 2-element list, consisting of:
# a 2-byte binary string
# a multiplier value
###################################################################
proc Freq2Offset { f step } \
{
global GlobalParam
global Istep
global Wstep
# puts stderr "Freq2Offset: f: $f, step: $step"
if {($f == "") \
|| ($f < 0) \
|| ($f > 159.995) } \
{
# Frequency is out of range or null.
# puts stderr "Frequency $f not a valid offset."
set fbytes [binary format "H2H2" 00 00]
return [list $fbytes 0]
}
if { [info exists Wstep($step)] } \
{
# determine the internal step
set ns $Istep($Wstep($step))
set khz [expr {$f * 1000}]
set m [expr {$khz / $Wstep($step)}]
# mid significant 8 bits
set midbits [ expr {fmod($m,65536)}]
set midbits [ expr {int($midbits/256)}]
# least significant 8 bits
set lsbits [ expr {fmod($m,256)}]
set lsbits [ expr {int($lsbits)}]
set s [format "%02x" $midbits]
set b1 [binary format "H2" $s]
set s [format "%02x" $lsbits]
set b0 [binary format "H2" $s]
set fbytes $b0
append fbytes $b1
# set abuf [DumpBinary $fbytes]
# puts stderr "f: $f, step: $step, ns: $ns, m: $m, fbytes: $abuf"
return [list $fbytes $ns]
} \
else \
{
# Undefined step value
puts stderr "Undefined step value $step, frequency $f"
# set fbytes [binary format "H2H2H2" 00 00 00]
set fbytes [binary format "H2H2" 00 00]
return [list $fbytes 0]
}
}
###################################################################
# Encode a frequency into a 3 byte internally-represented value.
#
# Returns: a 3-byte string
###################################################################
proc Freq2Internal3 { f step } \
{
global GlobalParam
global Istep
global Wstep
# puts stderr "Freq2Internal3: f: $f, step: $step"
if {($f == "") \
|| ($f < $GlobalParam(LowestFreq)) \
|| ($f > $GlobalParam(HighestFreq)) } \
{
# Frequency is out of range
set fbytes [binary format "H2H2H2" 00 00 00]
return $fbytes
}
if { [info exists Wstep($step)] } \
{
# determine the internal step
set ns $Istep($Wstep($step))
# Add 1 to prevent rounding error.
set khz [expr {($f * 1000) + 1}]
set m [expr {$khz / $Wstep($step)}]
# most significant 2 bits
set msbits [expr {($m / 256) / 256}]
set msbits [expr {int($msbits)}]
# mid significant 8 bits
set midbits [ expr {fmod($m,65536)}]
set midbits [ expr {int($midbits/256)}]
# least significant 8 bits
set lsbits [ expr {fmod($m,256)}]
set lsbits [ expr {int($lsbits)}]
set b2 [binary format "H2" 00]
set b2 [SetBitField $b2 2 3 $ns]
set b2 [SetBitField $b2 6 7 $msbits]
set s [format "%02x" $midbits]
set b1 [binary format "H2" $s]
set s [format "%02x" $lsbits]
set b0 [binary format "H2" $s]
set fbytes $b0
append fbytes $b1
append fbytes $b2
set abuf [DumpBinary $fbytes]
# puts stderr "f: $f, step: $step, ns: $ns, fbytes: $abuf"
return $fbytes
} \
else \
{
# Undefined step value
set fbytes [binary format "H2H2H2" 00 00 00]
return $fbytes
}
}
###################################################################
# Decode a 2-1/2 byte BCD frequency offset.
#
# Returns: frequency in MHz
###################################################################
proc BCD2Offset { s } \
{
global GlobalParam
# Note: ICOM packs two digits per byte, one per nibble.
# An important exception is the least significant nibble
# in the most significant byte. That nibble can be
# 0-9 or a-f.
# a-f means 10-15.
# Frequency digit pairs.
set i 0
set f1 [string index $s $i]
# Extract right nibble of most significant byte.
set f1 [GetBitField $f1 4 7]
incr i
set f2 [string index $s $i]
binary scan $f2 "H2" f2
incr i
set f3 [string index $s $i]
binary scan $f3 "H2" f3
incr i
set f [format "%d%s%s" $f1 $f2 $f3]
set f [string trimleft $f 0]
if { $f == ""} \
{
set f "00000000"
}
# Check for non-digit chars.
set rc [regexp {^[0-9]*$} $f]
if {$rc == 0} then {set f "00000000"}
set f [expr {$f/1000.0}]
set f [ format "%.3f" $f]
return $f
}
###################################################################
# Create widgets for the name of this program.
###################################################################
proc MakeTitleFrame { f }\
{
global DisplayFontSize
global Version
frame $f -relief flat -borderwidth 3
# set s [format "tk5 v%s" $Version]
set s [format "tk5"]
label $f.lab -text $s \
-background blue \
-foreground white \
-relief raised \
-borderwidth 3 \
-font $DisplayFontSize
set s ""
append s [format "Version %s\n" $Version]
append s "Experimental Utility\n"
append s "for the ICOM IC-R5 Receiver\n"
append s "Copyright 2004, Bob Parnass"
label $f.use -text $s \
-background black \
-foreground white \
-relief raised \
-borderwidth 3
pack $f.lab $f.use -side top -padx 0 -pady 0 \
-fill y -fill x -expand true
return $f
}
###################################################################
# Create frame for display parameters.
###################################################################
proc MakeDisplayFrame { f }\
{
frame $f -relief groove -borderwidth 3
label $f.lab -text "Display, Keypad Settings" \
-borderwidth 3
pack $f.lab -side top
frame $f.b -relief flat -borderwidth 3
MakeDispWidgets $f.b
pack $f.b -side top -expand true -fill both
return $f
}
proc MakeDispWidgets {f} \
{
global GlobalParam
label $f.lmonitor -text "Monitor key" -borderwidth 3
tk_optionMenu $f.monitor GlobalParam(Monitor) PUSH HOLD
label $f.llockeffect -text "Key lock effect" -borderwidth 3
tk_optionMenu $f.lockeffect GlobalParam(LockEffect) \
NORMAL NO_SQL NO_VOL ALL
label $f.lcontrast -text "Display contrast" -borderwidth 3
tk_optionMenu $f.contrast GlobalParam(Contrast) \
1 2 3 4
label $f.llamp -text "Lamp" -borderwidth 3
tk_optionMenu $f.lamp GlobalParam(Lamp) OFF ON AUTO
checkbutton $f.beep -text "Confirmation beep" \
-variable GlobalParam(Beep) \
-onvalue 1 -offvalue 0
grid $f.lmonitor -row 10 -column 0 -sticky w
grid $f.monitor -row 10 -column 1 -sticky e
grid $f.llockeffect -row 20 -column 0 -sticky w
grid $f.lockeffect -row 20 -column 1 -sticky e
grid $f.lcontrast -row 25 -column 0 -sticky w
grid $f.contrast -row 25 -column 1 -sticky e
grid $f.llamp -row 30 -column 0 -sticky w
grid $f.lamp -row 30 -column 1 -sticky e
grid $f.beep -row 40 -column 0 -sticky w -columnspan 2
return
}
###################################################################
# Create frame for memory bank labels.
###################################################################
proc MakeBankLabelsFrame { f } \
{
global GlobalParam
frame $f -relief groove -borderwidth 3
ScrollformCreate $f.b
pack $f.b -expand yes -fill both
set w [ScrollFormInterior $f.b]
label $w.ltitle -text "Memory Banks" -borderwidth 3
label $w.lbank -text "Bank" -borderwidth 3
label $w.lname -text "Label" -borderwidth 3
for {set i 0} {$i < 18} {incr i} \
{
MakeBankLabel $w $i
}
set c 1
grid $w.ltitle -row 0 -column 1 -columnspan 2
grid $w.lbank -row 1 -column $c ; incr c
grid $w.lname -row 1 -column $c ; incr c
set hint ""
append hint "You may create memory bank labels "
append hint "up to $GlobalParam(LabelLength) "
append hint "characters long. "
balloonhelp_for $f $hint
pack $f.b -side top -fill both -expand true -padx 3 -pady 3
return $f
}
###################################################################
# Create one a set of widgets for one memory bank.
###################################################################
proc MakeBankLabel { f bn } \
{
global BankID
global BankLabel
global GlobalParam
if {[info exists BankID($bn)]} \
{
set bid "$BankID($bn)"
} \
else \
{
set bid $bn
}
label $f.id$bn -text "$bid" -borderwidth 3
entry $f.label$bn -width 10 \
-textvariable BankLabel($bn) \
-background white
set row [expr {$bn + 2}]
set c 1
grid $f.id$bn -row $row -column $c ; incr c
grid $f.label$bn -row $row -column $c ; incr c
return $f
}
###################################################################
# Create 25 search banks.
###################################################################
proc MakeSearchFrame { f }\
{
global GlobalParam
frame $f -relief groove -borderwidth 3
frame $f.rb -relief groove -borderwidth 3
set r $f.rb
label $r.ldial -text "Fast dial step" -borderwidth 3
tk_optionMenu $r.dial GlobalParam(Dial) 100kHz 1MHz 10MHz
# checkbutton $r.dialaccel -text "Dial acceleration"
checkbutton $r.dialaccel -text "" \
-variable GlobalParam(DialAccel) \
-onvalue 1 -offvalue 0
label $r.ldialaccel -text "Dial acceleration" -borderwidth 3
label $r.lvfosearch -text "VFO Search" -borderwidth 3
$r.lvfosearch configure -foreground yellow
tk_optionMenu $r.vfosearch GlobalParam(VFOSearch) \
BAND ALL \
PROG0 PROG1 PROG2 PROG3 PROG4 PROG5 \
PROG6 PROG7 PROG8 PROG9 \
PROG10 PROG11 PROG12 PROG13 PROG14 PROG15 \
PROG16 PROG17 PROG18 PROG19 \
PROG20 PROG21 PROG22 PROG23 PROG24
grid $r.ldial -row 8 -column 1 -sticky w
grid $r.dial -row 8 -column 2 -sticky ew
grid $r.ldialaccel -row 12 -column 1 -sticky w
grid $r.dialaccel -row 12 -column 2 -sticky e
# pack $r.lvfosearch $r.vfosearch -side left
pack $r -side top -padx 3 -pady 3
label $f.lab -text "\nLimit Search Banks" -borderwidth 3
pack $f.lab -side top -padx 3 -pady 3
ScrollformCreate $f.b
pack $f.b -expand yes -fill both
set w [ScrollFormInterior $f.b]
label $w.lowerf -text "Lower Freq" -borderwidth 3
label $w.lowerm -text "Mode" -borderwidth 3
label $w.lowers -text "Step" -borderwidth 3
label $w.lowerl -text "Label" -borderwidth 3
label $w.divider -text "" -borderwidth 3
label $w.upperf -text "Upper Freq" -borderwidth 3
label $w.upperm -text "Mode" -borderwidth 3
label $w.uppers -text "Step" -borderwidth 3
label $w.upperl -text "Label" -borderwidth 3
for {set i 0} {$i < 25} {incr i} \
{
MakeSearchBank $w $i
}
set c 1
grid $w.lowerf -row 1 -column $c ; incr c
grid $w.lowerm -row 1 -column $c ; incr c
grid $w.lowers -row 1 -column $c ; incr c
grid $w.lowerl -row 1 -column $c ; incr c
grid $w.divider -row 1 -column $c ; incr c
grid $w.upperf -row 1 -column $c ; incr c
grid $w.upperm -row 1 -column $c ; incr c
grid $w.uppers -row 1 -column $c ; incr c
grid $w.upperl -row 1 -column $c ; incr c
pack $f.b -side top -fill both -expand true -padx 3 -pady 3
return $f
}
###################################################################
# Create one a set of widgets for one search bank.
###################################################################
proc MakeSearchBank { f bn }\
{
global LimitScan
global GlobalParam
label $f.lab$bn -text "PROG$bn" -borderwidth 3
entry $f.lower$bn -width 10 \
-textvariable LimitScan($bn,lower) \
-background white
tk_optionMenu $f.lmodemenu$bn LimitScan($bn,lmode) \
NFM WFM AM
tk_optionMenu $f.lstep$bn LimitScan($bn,lstep) \
5 6.25 8.33 9 10 12.5 15 20 25 30 50 100
entry $f.lowerlabel$bn -width 10 \
-textvariable LimitScan($bn,llabel) \
-background white
set hint ""
append hint "Limit Search labels are saved by the software, "
append hint "but are not actually used by the radio. "
balloonhelp_for $f.lowerlabel$bn $hint
label $f.divider$bn -text " ---- " -borderwidth 3
entry $f.upper$bn -width 10 \
-textvariable LimitScan($bn,upper) \
-background white
tk_optionMenu $f.umodemenu$bn LimitScan($bn,umode) \
NFM WFM AM
tk_optionMenu $f.ustep$bn LimitScan($bn,ustep) \
5 6.25 8.33 9 10 12.5 15 20 25 30 50 100
entry $f.upperlabel$bn -width 10 \
-textvariable LimitScan($bn,ulabel) \
-background white
set hint ""
append hint "Limit Search labels are saved by the software, "
append hint "but are not actually used by the radio. "
balloonhelp_for $f.upperlabel$bn $hint
set row [expr {$bn + 2}]
set c 0
grid $f.lab$bn -row $row -column $c ; incr c
grid $f.lower$bn -row $row -column $c ; incr c
grid $f.lmodemenu$bn -row $row -column $c -sticky ew ; incr c
grid $f.lstep$bn -row $row -column $c -sticky ew ; incr c
grid $f.lowerlabel$bn -row $row -column $c -sticky ew ; incr c
grid $f.divider$bn -row $row -column $c ; incr c
grid $f.upper$bn -row $row -column $c ; incr c
grid $f.umodemenu$bn -row $row -column $c -sticky ew ; incr c
grid $f.ustep$bn -row $row -column $c -sticky ew ; incr c
grid $f.upperlabel$bn -row $row -column $c -sticky ew ; incr c
return $f
}
###################################################################
# Create frame for misc parameters.
###################################################################
proc MakeMiscFrame { f }\
{
frame $f -relief groove -borderwidth 3
label $f.lab -text "Misc. Settings" \
-borderwidth 3
pack $f.lab -side top
frame $f.b -relief flat -borderwidth 3
MakeMiscWidgets $f.b
pack $f.b -side top -expand true -fill both
return $f
}
###################################################################
# Create widgets for misc. parameters.
###################################################################
proc MakeMiscWidgets { f } \
{
global GlobalParam
global Priority
global PriorityMode
label $f.lamantenna -text "AM broadcast antenna" -borderwidth 3
tk_optionMenu $f.amantenna GlobalParam(AMantenna) \
EXT INTERNAL_BAR
label $f.lfmantenna -text "FM broadcast antenna" -borderwidth 3
tk_optionMenu $f.fmantenna GlobalParam(FMantenna) EXT EARPHONE
checkbutton $f.battery -text "Power save" \
-variable GlobalParam(PowerSave) \
-onvalue 1 -offvalue 0
label $f.lautooff -text "Auto power off (min.)" -borderwidth 3
tk_optionMenu $f.autooff GlobalParam(AutoOff) \
OFF 30 60 90 120
label $f.lpause -text "Scan pause (sec.)" -borderwidth 3
tk_optionMenu $f.pause GlobalParam(Pause) \
2 4 6 8 10 12 14 16 18 20 HOLD
set hint ""
append hint "When receiving signals, "
append hint "the radio will stop scanning "
append hint "to let you hear the transmission for the "
append hint "length of time determined by the Scan Pause "
append hint "value. "
balloonhelp_for $f.lpause $hint
balloonhelp_for $f.pause $hint
label $f.labresume -text "Scan resume (sec.)" -borderwidth 3
tk_optionMenu $f.resume GlobalParam(Resume) \
0 1 2 3 4 5 HOLD
set hint ""
append hint "After a transmission ends, the radio waits "
append hint "a brief period before resuming the scan. "
balloonhelp_for $f.labresume $hint
balloonhelp_for $f.resume $hint
# checkbutton $f.atten -text "Attenuator" \
# -variable GlobalParam(Attenuator) \
# -onvalue 1 -offvalue 0
checkbutton $f.scanstopbeep -text "Scan stop beep" \
-variable GlobalParam(ScanStopBeep) \
-onvalue 1 -offvalue 0
checkbutton $f.expanded -text "Expanded set mode" \
-variable GlobalParam(ExpandedSetMode) \
-onvalue 1 -offvalue 0
# $f.atten configure -foreground yellow
grid $f.lamantenna -row 10 -column 0 -sticky w
grid $f.amantenna -row 10 -column 1 -sticky ew
grid $f.lfmantenna -row 20 -column 0 -sticky w
grid $f.fmantenna -row 20 -column 1 -sticky ew
grid $f.battery -row 30 -column 0 -sticky w -columnspan 2
grid $f.lautooff -row 40 -column 0 -sticky w
grid $f.autooff -row 40 -column 1 -sticky ew
grid $f.lpause -row 50 -column 0 -sticky w
grid $f.pause -row 50 -column 1 -sticky ew
grid $f.labresume -row 60 -column 0 -sticky w
grid $f.resume -row 60 -column 1 -sticky ew
# grid $f.atten -row 12 -column 0 -sticky w -columnspan 2
grid $f.scanstopbeep -row 80 -column 0 -sticky w -columnspan 2
grid $f.expanded -row 90 -column 0 -sticky w -columnspan 2
return $f
}
###################################################################
# Create frame for Communications parameters.
###################################################################
proc MakeCommFrame { f }\
{
frame $f -relief groove -borderwidth 3
label $f.lab -text "Debugging Information" \
-borderwidth 3
pack $f.lab -side top
frame $f.b -relief flat -borderwidth 3
MakeCommWidgets $f.b
set hint ""
append hint "Serial Communications fields "
append hint "are useful for testing tk5. "
balloonhelp_for $f $hint
pack $f.b -side top -expand true -fill y
return $f
}
###################################################################
# Create widgets for Communications params.
###################################################################
proc MakeCommWidgets { f } \
{
global GlobalParam
label $f.labpre -text "Radio Version" -borderwidth 3
entry $f.pre -width 26 \
-textvariable GlobalParam(RadioVersion) \
-background yellow
label $f.lfileversion -text "File Version" -borderwidth 3
entry $f.fileversion -width 26 \
-textvariable GlobalParam(FileVersion) \
-background yellow
label $f.lusercomment -text "User comment" -borderwidth 3
entry $f.usercomment -width 26 \
-textvariable GlobalParam(UserComment) \
-background yellow
label $f.labnmsgs -text "Number Messages Read" -borderwidth 3
entry $f.nmsgs -width 5 \
-textvariable GlobalParam(NmsgsRead) \
-background yellow
checkbutton $f.bypassall -text "Bypass All Encoding" \
-variable GlobalParam(BypassAllEncoding) \
-onvalue 1 -offvalue 0
grid $f.labpre -row 0 -column 0 -sticky w
grid $f.pre -row 0 -column 1 -sticky e
grid $f.lfileversion -row 4 -column 0 -sticky w
grid $f.fileversion -row 4 -column 1 -sticky e
grid $f.lusercomment -row 8 -column 0 -sticky w
grid $f.usercomment -row 8 -column 1 -sticky e
grid $f.labnmsgs -row 12 -column 0 -sticky w
grid $f.nmsgs -row 12 -column 1 -sticky e
grid $f.bypassall -row 16 -column 0 -columnspan 2
return $f
}
###################################################################
# Create TV channel frequencies.
###################################################################
proc MakeTVFrame { f }\
{
global GlobalParam
frame $f -relief groove -borderwidth 3
ScrollformCreate $f.b
pack $f.b -expand yes -fill both
set w [ScrollFormInterior $f.b]
set msg1 "TV Channels\n(1999.995 MHz max)"
label $w.msg1 -text $msg1 -borderwidth 3
label $w.ln -text "" -borderwidth 3
label $w.lfreq -text "Freq" -borderwidth 3
label $w.lmode -text "Mode" -borderwidth 3
label $w.llabel -text "Label" -borderwidth 3
for {set i 0} {$i < 70} {incr i} \
{
MakeTVChan $w $i
}
set r 1
grid $w.msg1 -row $r -column 1 -columnspan 5
incr r
grid $w.ln -row $r -column 1
grid $w.lfreq -row $r -column 2
grid $w.lmode -row $r -column 3
grid $w.llabel -row $r -column 4
set hint ""
append hint "TV channel notes:\n\n"
append hint "- TV channel frequencies must be multiples "
append hint "of 5 kHz.\n\n"
append hint "- North American TV channels are WFM mode.\n\n"
append hint "- TV channel labels are 4 characters or less.\n\n"
append hint "- Select Skip for channels you want "
append hint "to ignore. "
append hint "(To access skipped TV channels when using the "
append hint "the radio, press and hold the FUNC key while "
append hint "rotating the selector knob.)"
balloonhelp_for $f $hint
return $f
}
###################################################################
# Create one a set of widgets for tv channel freq.
###################################################################
proc MakeTVChan { f bn }\
{
global TV
global GlobalParam
set j $bn
incr j
label $f.lab$bn -text "$j" -borderwidth 3
entry $f.f$bn -width 10 \
-textvariable TV($bn,freq) -background white
tk_optionMenu $f.modemenu$bn TV($bn,mode) \
WFM AM
entry $f.label$bn -width 10 \
-textvariable TV($bn,label) -background white
# checkbutton $f.hide$bn -text "Hide" \
# -variable TV($bn,hide) \
# -onvalue 1 -offvalue 0
checkbutton $f.skip$bn -text "Skip" \
-variable TV($bn,skip) \
-onvalue 1 -offvalue 0
set r [expr {$bn + 5}]
grid $f.lab$bn -row $r -column 1
grid $f.f$bn -row $r -column 2
grid $f.modemenu$bn -row $r -column 3
grid $f.label$bn -row $r -column 4
# grid $f.hide$bn -row $r -column 5
grid $f.skip$bn -row $r -column 6
return $f
}
###################################################################
# Encode the information from the data structures into
# the memory image string which can be written to the radio.
#
# We don't understand the meaning of all the bytes in
# the memory image. Therefore, the
# image string must already exist and we will only
# change the bytes which we understand.
#
###################################################################
proc EncodeImage { } \
{
global GlobalParam
global Mimage
if {$GlobalParam(BypassAllEncoding)} \
{
puts stderr "EncodeImage: skip encoding"
return 0
}
# puts stderr "EncodeImage: encoding"
if { ([info exists Mimage] == 0) } \
{
puts stderr "EncodeImage: image does not exist"
return error
}
set image $Mimage
set image [EncodeMisc $image]
if { [string length $image] == 0} {return error}
set image [EncodeMemories $image]
if { [string length $image] == 0} {return error}
set image [EncodeBankLabels $image]
if { [string length $image] == 0} {return error}
set image [EncodeSearchBanks $image]
if { [string length $image] == 0} {return error}
set image [EncodeTV $image]
if { [string length $image] == 0} {return error}
set Mimage $image
return 0
}
###################################################################
# Encode misc
# information into a memory image.
###################################################################
proc EncodeMisc { image } \
{
global AMant
global AutoOff
global BatterySaver
global Dial
global FMant
global Fstep
global ImageAddr
global GlobalParam
global Lamp
global LockEffect
global Mimage
global Mode
global Monitor
global Pause
global Priority
global PriorityMode
global Resume
global Step
# # Priority frequency and mode.
#
# set s [FreqMode2BCD $Priority $PriorityMode ""]
#
# scan $ImageAddr(Priority) "%x" first
# set last [expr {$first + 3}]
# set image [string replace $image $first $last $s]
#
#
# # VFO frequency
#
# set s [Freq2BCD3p $GlobalParam(VFOFreq)]
# scan $ImageAddr(VFOFreq) "%x" first
# set last [expr {$first + 3}]
# set image [string replace $image $first $last $s]
#
# # VFO mode.
# scan $ImageAddr(VFOMode) "%x" first
# set last $first
#
# set m $GlobalParam(VFOMode)
# if { [info exists Mode($m)] } \
# {
# set c $Mode($m)
# } \
# else \
# {
# set c $Mode(NFM)
# }
#
# set s [format "%02x" $c]
# set b [binary format "H2" $s]
# set image [string replace $image $first $first $b]
#
#
# # Set Attenuator bit
# scan $ImageAddr(FlagByte3) "%x" first
# set byte [string index $image $first]
# set newbyte [AssignBit $byte 5 $GlobalParam(Attenuator)]
# set image [string replace $image $first $first $newbyte]
#
#
# # Set Keypad Lock bit
# scan $ImageAddr(FlagByte3) "%x" first
# set byte [string index $image $first]
# set newbyte [AssignBit $byte 1 $GlobalParam(Lock)]
# set image [string replace $image $first $first $newbyte]
#
# encode Lock function effect
scan $ImageAddr(LockEffect) "%x" first
set byte [string index $image $first]
set n [format "%02x" $LockEffect($GlobalParam(LockEffect))]
set newbyte [binary format "H2" $n]
set image [string replace $image $first $first $newbyte]
# encode Scan Resume.
# Scan Resume is stored in one hex byte as one
# less than what the user sees on the radio's display.
# Example: Resume of 12 seconds is stored as 0B.
# encode Scan stop beep flag
scan $ImageAddr(ScanStopBeep) "%x" first
set s [format "%02x" $GlobalParam(ScanStopBeep)]
set b [binary format "H2" $s]
set image [string replace $image $first $first $b]
# encode Expanded Set Mode Flag
scan $ImageAddr(ExpandedSetModeFlag) "%x" first
set s [format "%02x" $GlobalParam(ExpandedSetMode)]
set b [binary format "H2" $s]
set image [string replace $image $first $first $b]
# encode Dial Acceleration
scan $ImageAddr(DialAccel) "%x" first
set s [format "%02x" $GlobalParam(DialAccel)]
set b [binary format "H2" $s]
set image [string replace $image $first $first $b]
# encode Power Saver
scan $ImageAddr(PowerSave) "%x" first
set s [format "%02x" $GlobalParam(PowerSave)]
set b [binary format "H2" $s]
set image [string replace $image $first $first $b]
# # Tuning Step is stored in one byte.
# # Important note:
# # There is a correlation between the Tuning Step byte
# # and bit 7 of FlagByte3.
# # Bit 7 = 0 if step is AUTO,
# # othewise Bit 7 = 1.
#
# scan $ImageAddr(VFOStep) "%x" first
# set c $GlobalParam(TuningStep)
# # Translate to hex equivalent
# set c $Step($c)
# set b [binary format "H2" $c]
# set image [string replace $image $first $first $b]
#
# scan $ImageAddr(FlagByte3) "%x" first
# set b [string range $image $first $first]
# if {$GlobalParam(TuningStep) == "AUTO"} \
# {
# set b [ClearBit $b 7]
# } \
# else \
# {
# set b [SetBit $b 7]
# }
# set image [string replace $image $first $first $b]
#
# # Bank scan flag
# scan $ImageAddr(FlagByte0) "%x" first
# set b [string range $image $first $first]
# set b [AssignBit $b 4 $GlobalParam(BankScan)]
# set image [string replace $image $first $first $b]
# encode AM broadcast antenna
scan $ImageAddr(AMantenna) "%x" first
set c $GlobalParam(AMantenna)
# Translate to hex equivalent
set c [format "%02x" $AMant($c)]
set b [binary format "H2" $c]
set image [string replace $image $first $first $b]
# encode FM broadcast antenna
scan $ImageAddr(FMantenna) "%x" first
set c $GlobalParam(FMantenna)
# Translate to hex equivalent
set c [format "%02x" $FMant($c)]
set b [binary format "H2" $c]
set image [string replace $image $first $first $b]
# Pause
scan $ImageAddr(Pause) "%x" first
set b [string range $image $first $first]
set s [format "%02x" $Pause($GlobalParam(Pause))]
set b [binary format "H2" $s]
set image [string replace $image $first $first $b]
# Resume
scan $ImageAddr(Resume) "%x" first
set b [string range $image $first $first]
set s [format "%02x" $Resume($GlobalParam(Resume))]
set b [binary format "H2" $s]
set image [string replace $image $first $first $b]
# Monitor flag
scan $ImageAddr(Monitor) "%x" first
set b [string range $image $first $first]
set s [format "%02x" $Monitor($GlobalParam(Monitor))]
set b [binary format "H2" $s]
set image [string replace $image $first $first $b]
# encode Beep tone flag
scan $ImageAddr(Beep) "%x" first
set b [string range $image $first $first]
set s [format "%02x" $GlobalParam(Beep)]
set b [binary format "H2" $s]
set image [string replace $image $first $first $b]
# encode Auto Power Off
scan $ImageAddr(AutoOff) "%x" first
set byte [string index $image $first]
set n [format "%02x" $AutoOff($GlobalParam(AutoOff))]
set newbyte [binary format "H2" $n]
set image [string replace $image $first $first $newbyte]
# encode Dial fast step
scan $ImageAddr(DialStep) "%x" first
set byte [string index $image $first]
set n [format "%02x" $Dial($GlobalParam(Dial))]
set newbyte [binary format "H2" $n]
set image [string replace $image $first $first $newbyte]
# encode Contrast
# contrast is stored in the image as one less.
scan $ImageAddr(Contrast) "%x" first
set byte [string index $image $first]
set n $GlobalParam(Contrast)
incr n -1
set n [format "%02x" $n]
set newbyte [binary format "H2" $n]
set image [string replace $image $first $first $newbyte]
# encode Lamp
scan $ImageAddr(Lamp) "%x" first
set byte [string index $image $first]
set n [format "%02x" $Lamp($GlobalParam(Lamp))]
set newbyte [binary format "H2" $n]
set image [string replace $image $first $first $newbyte]
# # Set VFO/Limit Search bit
# scan $ImageAddr(FlagByte0) "%x" first
# set byte [string index $image $first]
# set newbyte [AssignBit $byte 3 $GlobalParam(LimitSearch)]
# set image [string replace $image $first $first $newbyte]
#
# # Fast Tuning Step is stored in one byte
# scan $ImageAddr(FastTuningStep) "%x" first
# set s $GlobalParam(FastTuningStep)
# set s [format "%02x" $Fstep($s)]
# set b [binary format "H2" $s]
# set image [string replace $image $first $first $b]
return $image
}
###################################################################
# Encode the memory channel frequency, mode, and preferential
# flag information into a memory image.
###################################################################
proc EncodeMemories { image } \
{
global Ctcss
global CtcssBias
global Dcs
global ImageAddr
global MemBankLetter
global MemBankCh
global MemDuplex
global MemFreq
global MemHide
global MemLabel
global MemMode
global MemOffset
global MemSkip
global MemStep
global MemDToneCode
global MemDTonePolarity
global MemToneCode
global MemToneFlag
global Mode
global RBankID
global RToneFlag
global Skip
global Step
global Mimage
global ImageAddr
for {set ch 0} {$ch < 1000} {incr ch} \
{
if {$MemHide($ch) == "hide"} \
{
set $MemFreq($ch) 0
}
}
# Encode channel frequency.
scan $ImageAddr(MemoryFreqs) "%x" first
set last [expr {$first + 2}]
for {set ch 0} {$ch < 1000} {incr ch} \
{
set b [ Freq2Internal3 $MemFreq($ch) $MemStep($ch) ]
# set buf [DumpBinary $b]
# puts stderr "ch: $ch, f: $MemFreq($ch), $buf"
set image [string replace $image $first $last $b]
incr first 16
incr last 16
}
# Encode memory step.
scan $ImageAddr(MemorySteps) "%x" first
for {set ch 0} {$ch < 1000} {incr ch} \
{
set b [string index $image $first]
if { [info exists Step($MemStep($ch))] } \
{
set m $Step($MemStep($ch))
} \
else \
{
set m $Step(5)
}
set b [SetBitField $b 0 3 $m]
set image [string replace $image $first $first $b]
incr first 16
}
# Encode memory label.
scan $ImageAddr(MemoryLabels) "%x" first
set last [expr {$first + 4}]
for {set ch 0} {$ch < 1000} {incr ch} \
{
set s [MemoryLabel2Internal $MemLabel($ch)]
set len [string length $s]
# puts stderr "ch: $ch, s: $s, first: $first, last: $last, len: $len"
set image [string replace $image $first $last $s]
incr first 16
incr last 16
}
# Encode memory hide flag.
scan $ImageAddr(MemoryBankNumber) "%x" first
set last [expr {$first + 1}]
for {set ch 0} {$ch < 1000} {incr ch} \
{
if {$MemHide($ch) == "hide"} \
{
set b [binary format "H2H2" FF FF]
} \
else \
{
set b [binary format "H2H2" 1F FF]
}
# set abuf " $ch) "
# append abuf [DumpBinary $b]
# puts stderr $abuf
set image [string replace $image $first $last $b]
incr first 2
incr last 2
}
# Encode bank letter.
scan $ImageAddr(MemoryBankNumber) "%x" first
for {set ch 0} {$ch < 1000} {incr ch} \
{
if {$MemHide($ch) == "hide"} \
{
incr first 2
continue
}
set b [string index $image $first]
if { [info exists RBankID($MemBankLetter($ch))] } \
{
set n $RBankID($MemBankLetter($ch))
} \
else \
{
# Invalid bank, so default it to no bank.
set n 31
}
set b [SetBitField $b 3 7 $n]
set image [string replace $image $first $first $b]
incr first 2
}
# Encode bank channel number.
scan $ImageAddr(MemoryBankCh) "%x" first
for {set ch 0} {$ch < 1000} {incr ch} \
{
if {$MemHide($ch) == "hide"} \
{
incr first 2
continue
}
set n $MemBankCh($ch)
if { [info exists RBankID($MemBankLetter($ch))] \
&& ($n >= 0) && ($n <= 99) } \
{
set hn [format "%02x" $n]
set b [binary format "H2" $hn]
} \
else \
{
# This memory is not assigned to
# a bank or channel number is invalid.
set b [binary format "H2" FF]
}
set image [string replace $image $first $first $b]
incr first 2
}
# Encode memory mode.
scan $ImageAddr(MemoryModes) "%x" first
set last $first
for {set ch 0} {$ch < 1000} {incr ch} \
{
if { [info exists Mode($MemMode($ch))] } \
{
set m $Mode($MemMode($ch))
} \
else \
{
set m $Mode(NFM)
}
set b [string index $image $first]
set b [SetBitField $b 4 5 $m]
set image [string replace $image $first $last $b]
incr first 16
incr last 16
}
# Encode channel duplex/simplex flag.
scan $ImageAddr(MemoryDuplex) "%x" first
for {set ch 0} {$ch < 1000} {incr ch} \
{
set b [string index $image $first]
if {$MemDuplex($ch) == "+"} \
{
set n 2
} \
elseif {$MemDuplex($ch) == "-"} \
{
set n 1
} \
else \
{
set n 0
}
set b [SetBitField $b 6 7 $n]
set image [string replace $image $first $first $b]
incr first 16
}
# Encode a frequency offset for a channel.
scan $ImageAddr(MemoryOffset) "%x" first
set last [expr {$first + 1}]
scan $ImageAddr(MemoryMult) "%x" mfirst
for {set ch 0} {$ch < 1000} {incr ch} \
{
set lst [ Freq2Offset $MemOffset($ch) $MemStep($ch) ]
set s [ lindex $lst 0 ]
set image [string replace $image $first $last $s]
set m [ lindex $lst 1 ]
set b [string index $image $mfirst]
set b [SetBitField $b 0 1 $m]
set image [string replace $image $mfirst $mfirst $b]
incr first 16
incr last 16
incr mfirst 16
}
# Encode CTCSS code.
scan $ImageAddr(MemoryToneCode) "%x" first
for {set ch 0} {$ch < 1000} {incr ch} \
{
set b [ string index $image $first ]
# CTCSS code
set ccode $MemToneCode($ch)
if { [info exists Ctcss($ccode)] == 0 } \
{
set n 0
} \
else \
{
set n [expr {$Ctcss($ccode) - $CtcssBias}]
}
set hn [format "%02x" $n]
set b [binary format "H2" $hn]
set image [string replace $image $first $first $b]
incr first 16
}
# Encode Tone Squelch Flag.
scan $ImageAddr(MemoryToneFlag) "%x" first
for {set ch 0} {$ch < 1000} {incr ch} \
{
set b [ string index $image $first ]
# Tone Squelch flag
set m $MemToneFlag($ch)
if { [info exists RToneFlag($m)] } \
{
set b [SetBitField $b 0 3 $RToneFlag($m)]
} \
else \
{
set b [SetBitField $b 0 3 $RToneFlag(off)]
}
set image [string replace $image $first $first $b]
incr first 16
}
# Encode DCS code and polarity.
scan $ImageAddr(MemoryDToneCode) "%x" first
for {set ch 0} {$ch < 1000} {incr ch} \
{
set b [ string index $image $first ]
# DCS code
set ccode $MemDToneCode($ch)
if { [info exists Dcs($ccode)] == 0 } \
{
set n 0
} \
else \
{
set n $Dcs($ccode)
}
# puts -nonewline stderr " ($ccode $n)"
set hn [format "%02x" $n]
set b [binary format "H2" $hn]
if {$MemDTonePolarity($ch) == "r"} \
{
# Reverse
set b [SetBit $b 0]
} \
else \
{
# Normal
set b [ClearBit $b 0]
}
set image [string replace $image $first $first $b]
incr first 16
}
# Encode skip field.
scan $ImageAddr(MemorySkip) "%x" first
set last $first
for {set ch 0} {$ch < 1000} {incr ch} \
{
if {$MemHide($ch) == "hide"} \
{
incr first 2
incr last 2
continue
}
if {($MemSkip($ch) != "") && ($MemSkip($ch) != " ")} \
{
if { [info exists Skip($MemSkip($ch))] } \
{
set m $Skip($MemSkip($ch))
} \
else \
{
set m $Skip(scan)
}
} \
else \
{
set m $Skip(scan)
}
set b [string index $image $first]
set b [SetBitField $b 1 2 $m]
set image [string replace $image $first $last $b]
incr first 2
incr last 2
}
return $image
}
###################################################################
# Encode the limit search bank frequencies and modes
# information into a memory image.
###################################################################
proc EncodeSearchBanks { image } \
{
global Ctcss
global CtcssBias
global ImageAddr
global LimitScan
global Mode
global Skip
global Step
global Mimage
global ImageAddr
# Encode lower frequency.
scan $ImageAddr(SearchFreqFirst) "%x" first
set last [expr {$first + 2}]
for {set bn 0} {$bn < 25} {incr bn} \
{
set b [ Freq2Internal3 $LimitScan($bn,lower) \
$LimitScan($bn,lstep)]
set image [string replace $image $first $last $b]
incr first 32
incr last 32
}
# Encode upper frequency.
scan $ImageAddr(SearchFreqSecond) "%x" first
set last [expr {$first + 2}]
for {set bn 0} {$bn < 25} {incr bn} \
{
set b [ Freq2Internal3 $LimitScan($bn,upper) \
$LimitScan($bn,ustep)]
set image [string replace $image $first $last $b]
incr first 32
incr last 32
}
for {set bn 0} {$bn < 25} {incr bn} \
{
# Set flag to hide lower limit if the frequency is
# close to 0 MHz.
if { ($LimitScan($bn,lower) == "") \
|| ($LimitScan($bn,lower) < .001) } \
{
set LimitScan($bn,lhide) hide
} \
else \
{
set LimitScan($bn,lhide) ""
}
# Set flag to hide upper limit if the frequency is
# close to 0 MHz.
if { ($LimitScan($bn,upper) == "") \
|| ($LimitScan($bn,upper) < .001) } \
{
set LimitScan($bn,uhide) hide
} \
else \
{
set LimitScan($bn,uhide) ""
}
}
# Encode lower search limit mode
scan $ImageAddr(SearchModeFirst) "%x" first
for {set bn 0} {$bn < 25} {incr bn} \
{
set b [ string index $image $first ]
# Mode
set m $Mode($LimitScan($bn,lmode))
set b [SetBitField $b 4 5 $m]
set image [string replace $image $first $first $b]
incr first 32
}
# Encode upper search limit mode
scan $ImageAddr(SearchModeSecond) "%x" first
for {set bn 0} {$bn < 25} {incr bn} \
{
set b [ string index $image $first ]
# Mode
set m $Mode($LimitScan($bn,umode))
set b [SetBitField $b 4 5 $m]
set image [string replace $image $first $first $b]
incr first 32
}
# Encode lower search limit Tuning Step.
scan $ImageAddr(SearchStepFirst) "%x" first
for {set bn 0} {$bn < 25} {incr bn} \
{
set b [ string index $image $first ]
if { [info exists Step($LimitScan($bn,lstep))] } \
{
set m $Step($LimitScan($bn,lstep))
} \
else \
{
set m $Step(5)
}
set b [SetBitField $b 0 3 $m]
set image [string replace $image $first $first $b]
incr first 32
}
# Encode upper search limit Tuning Step.
scan $ImageAddr(SearchStepSecond) "%x" first
for {set bn 0} {$bn < 25} {incr bn} \
{
set b [ string index $image $first ]
if { [info exists Step($LimitScan($bn,ustep))] } \
{
set m $Step($LimitScan($bn,ustep))
} \
else \
{
set m $Step(5)
}
set b [SetBitField $b 0 3 $m]
set image [string replace $image $first $first $b]
incr first 32
}
# Encode lower label name
scan $ImageAddr(SearchLabelFirst) "%x" first
set last [expr {$first + 4}]
for {set bn 0} {$bn < 25} {incr bn} \
{
set s [MemoryLabel2Internal $LimitScan($bn,llabel)]
set image [string replace $image $first $last $s]
incr first 32
incr last 32
}
# Encode upper label name
scan $ImageAddr(SearchLabelSecond) "%x" first
set last [expr {$first + 4}]
for {set bn 0} {$bn < 25} {incr bn} \
{
set s [MemoryLabel2Internal $LimitScan($bn,ulabel)]
set image [string replace $image $first $last $s]
incr first 32
incr last 32
}
# Encode hidden flag for lower search limit.
scan $ImageAddr(SearchHideFirst) "%x" first
set last [expr {$first + 1}]
for {set bn 0} {$bn < 25} {incr bn} \
{
if { $LimitScan($bn,lhide) == "hide" } \
{
set b [binary format "H2H2" FF FF]
} \
else \
{
set b [binary format "H2H2" 1F FF]
}
set image [string replace $image $first $last $b]
incr first 4
incr last 4
}
# Encode hidden flag for upper search limit.
scan $ImageAddr(SearchHideSecond) "%x" first
set last [expr {$first + 1}]
for {set bn 0} {$bn < 25} {incr bn} \
{
if { $LimitScan($bn,uhide) == "hide" } \
{
set b [binary format "H2H2" FF FF]
} \
else \
{
set b [binary format "H2H2" 1F FF]
}
set image [string replace $image $first $last $b]
incr first 4
incr last 4
}
return $image
}
###################################################################
# Encode the TV channel info
# information into a memory image.
###################################################################
proc EncodeTV { image } \
{
global TVHideByte
global TVSkipByte
global ImageAddr
global Mimage
global TV
# Encode channel frequency.
scan $ImageAddr(TVFreq) "%x" first
set last [expr {$first + 2}]
for {set ch 0} {$ch < 70} {incr ch} \
{
set b [ TV2Internal3 $TV($ch,freq) ]
set image [string replace $image $first $last $b]
incr first 8
incr last 8
}
# Encode channel mode.
scan $ImageAddr(TVMode) "%x" first
for {set ch 0} {$ch < 70} {incr ch} \
{
if { $TV($ch,mode) == "WFM" } \
{
set b [binary format "H2" 01]
} \
else \
{
set b [binary format "H2" 02]
}
set image [string replace $image $first $first $b]
incr first 8
}
# Encode TV channel label.
scan $ImageAddr(TVLabel) "%x" first
set last [expr {$first + 3}]
for {set ch 0} {$ch < 70} {incr ch} \
{
set s $TV($ch,label)
# Translate bogus characters to spaces
regsub -all {[^A-Za-z0-9 .,\+\*/()\-=]} $s " " s
# Labels must be upper case.
set s [string toupper $s]
set s [format "%-4s" $s]
set s [string range $s 0 3]
set image [string replace $image $first $last $s]
incr first 8
incr last 8
}
# Encode TV channel hide flag.
ClearHiddenTVChannelFlags
SetHiddenTVChannelFlags
# PrintHiddenTVChannelFlags
scan $ImageAddr(TVHide) "%x" first
for {set i 0} {$i < 9} {incr i} \
{
set b [binary format "B8" $TVHideByte($i)]
set image [string replace $image $first $first $b]
incr first
}
# Encode TV channel skip flag.
ClearSkipTVChannelFlags
SetSkipTVChannelFlags
scan $ImageAddr(TVSkip) "%x" first
for {set i 0} {$i < 9} {incr i} \
{
set b [binary format "B8" $TVSkipByte($i)]
set image [string replace $image $first $first $b]
incr first
}
return $image
}
###################################################################
# Pop up a window which says "Please wait..."
###################################################################
proc MakeWait { } \
{
global DisplayFontSize
toplevel .wait
set w .wait
wm title $w "tk5 running"
label $w.lab -font $DisplayFontSize -text "Please wait ..."
pack $w.lab
update idletasks
waiter 500
return
}
###################################################################
# Kill the window which says "Please wait..."
###################################################################
proc KillWait { } \
{
catch {destroy .wait}
update idletasks
}
###################################################################
# ValidateData tests the data.
# It pops up a window with error and/or warning messages.
# If there are warnings but no errors, the user can elect
# to continue or cancel the current operation.
#
# Returns:
# 0 - continue
# 1 - cancel the current operation
###################################################################
proc ValidateData { } \
{
global Band
global Emsg
global GlobalParam
global MemFreq
global MemHide
global MemMode
global MemStep
global LimitScan
global Priority
global PriorityMode
global Skip
global TV
if { [info exists MemFreq(0)] == 0 } \
{
# No data to validate.
return 1
}
if { $GlobalParam(BypassAllEncoding) } \
{
# do not validate.
return 0
}
set Emsg ""
set nerror 0
set nwarning 0
# Memory channels.
for {set ch 0} {$ch < 1000} {incr ch} \
{
if {$MemHide($ch) == "hide"} {continue}
set m "Memory $ch"
set f $MemFreq($ch)
set code [ValidateFreq $f $m]
if {$code == "error"} { incr nerror } \
elseif {$code == "warning"} { incr nwarning }
set mode $MemMode($ch)
set code [ValidateMode $mode $m $f]
if {$code == "error"} { incr nerror }
set step $MemStep($ch)
set code [ValidateStep $step $m $f]
if {$code == "error"} { incr nerror } \
elseif {$code == "warning"} { incr nwarning }
if { [expr {$nerror + $nwarning}] > 5} {break}
}
# puts stderr "ValidateData: done with memories"
# TV channels.
for {set ch 0} {$ch < 70} {incr ch} \
{
set nch $ch
incr nch
set m "TV channel $nch"
set f $TV($ch,freq)
set code [ValidateFreq $f $m]
if {$code == "error"} { incr nerror } \
elseif {$code == "warning"} { incr nwarning }
if { [expr {$nerror + $nwarning}] > 5} {break}
}
# puts stderr "ValidateData: done with memories"
# Limit scan freqs, steps
for {set i 0} {$i < 25} {incr i} \
{
set m "Limit Scan bank PROG$i lower"
set f $LimitScan($i,lower)
set code [ValidateFreq $f $m]
if {$code == "error"} { incr nerror } \
elseif {$code == "warning"} { incr nwarning }
set step $LimitScan($i,lstep)
set code [ValidateStep $step $m $f]
if {$code == "error"} { incr nerror } \
elseif {$code == "warning"} { incr nwarning }
set code [ValidateMode $LimitScan($i,lmode) $m $f]
if {$code == "error"} { incr nerror }
set m "Limit Scan bank PROG$i upper"
set f $LimitScan($i,upper)
set code [ValidateFreq $f $m]
if {$code == "error"} { incr nerror } \
elseif {$code == "warning"} { incr nwarning }
set step $LimitScan($i,ustep)
set code [ValidateStep $step $m $f]
if {$code == "error"} { incr nerror } \
elseif {$code == "warning"} { incr nwarning }
set code [ValidateMode $LimitScan($i,umode) $m $f]
if {$code == "error"} { incr nerror }
if { [expr {$nerror + $nwarning}] > 5} {break}
}
set m "Bank/Channel assignment."
set code [ValidateMemoryBanks $m]
if {$code == "error"} { incr nerror }
if {$nerror} \
{
tk_dialog .baddata1 "tk5 Invalid data" \
$Emsg error 0 OK
# puts stderr "ValidateData: returning 1"
return 1
}
if {$nwarning} \
{
set response [tk_dialog .baddata2 \
"tk5 Data warning" \
$Emsg error 0 Cancel Continue]
if {$response == 0} then {return 1} \
else {return 0}
}
return 0
}
###################################################################
# Check a frequency for validity.
# Append the error or warning message to a global string.
#
# Returns:
# 0
# warning
# error
###################################################################
proc ValidateFreq {f m} \
{
global Emsg
global GlobalParam
set code 0
set msg ""
if {( ($f != "") && ($f != 0.0) ) \
&& (($f < $GlobalParam(LowestFreq)) \
|| ($f > $GlobalParam(HighestFreq)))} \
{
append msg "\nError: $m frequency ($f) is out"
append msg " of range.\n"
set code error
}
append Emsg $msg
return $code
}
###################################################################
# Return 1 if a string consists of 2 hex digits.
###################################################################
proc IsHex { s } \
{
# Check for non-digit and non decimal point chars.
set rc [regexp -nocase {^[0-9a-f][0-9a-f]$} $s]
if {$rc} \
{
return 1
} \
else \
{
return 0
}
}
###################################################################
# Check a mode for validity.
# Append the error message to a global string.
#
# Returns:
# 0
# warning
# error
###################################################################
proc ValidateMode {mode m f} \
{
global GlobalParam
global Emsg
global Mode
set code 0
if { [info exists Mode($mode)] == 0} \
{
append Emsg "\nError: $m mode ($mode) is invalid.\n"
set code error
}
if { ($f != "") && ($f != 0.0) } \
{
if {($mode != "AM") \
&& ($mode != "WFM") \
&& ($mode != "NFM") } \
{
append Emsg "\nError: $m mode ($mode) "
append Emsg "is invalid.\n"
set code error
}
}
if { ($code != "error") && ($f != "") && ($f >= .495) \
&& ($f <= 1.620) } \
{
if {$GlobalParam(WhichModel) == 9} \
{
if {$mode != "AM"} \
{
append Emsg "\nWarning: $m mode "
append Emsg "must be AM for this "
append Emsg "version radio.\n"
set code error
}
}
}
return $code
}
###################################################################
# Check a step size for validity.
# Append the error message to a global string.
#
# Radio version with 9 kHz step in the AM BCB may only have
# a 9 kHz step between .495 and 1.620 MHz.
#
# Radio version with 10 kHz step in the AM BCB cannot have
# a 9 kHz step between .495 and 1.620 MHz.
#
# Returns:
# 0
# warning
# error
###################################################################
proc ValidateStep {step m f} \
{
global Emsg
global GlobalParam
set code 0
if { ($f == "") || ($f == 0.0) } \
{
return 0
}
if {($f >= .495) && ($f <= 1.620)} \
{
if {($step == 9) \
&& ($GlobalParam(WhichModel) != 9)} \
{
append Emsg "\nError: $m step ($step) "
append Emsg "is invalid for this "
append Emsg "version radio.\n"
set code error
} \
elseif {($step != 9) \
&& ($GlobalParam(WhichModel) == 9)} \
{
append Emsg "\nError: $m step ($step) "
append Emsg "is invalid for this "
append Emsg "version radio.\n"
set code error
}
} \
else \
{
# Extract the Hz portion of the frequency
# to the right of the decimal point.
set f [format "%.6f" $f]
set lst [split $f "."]
set fhz [ lindex $lst 1 ]
set fhz [string trimleft $fhz 0]
if {$fhz == ""} {set fhz 0}
# puts stderr "f= $f, fhz= $fhz"
# set fhz [expr {$fhz * 1000000}]
set stephz [expr {$step * 1000}]
set n [expr {fmod($fhz, $stephz)}]
set n [expr {int($n)}]
# if {$n } \
# {
#
# # Frequency incompatible with step size.
# # puts stderr "f: $f, fhz: $fhz, step $step, stephz: $stephz, n: $n"
# append Emsg "\nWarning: $m frequency ($f) "
# append Emsg "will be adjusted to conform "
# append Emsg "to step ($step).\n"
# set code warning
# }
}
return $code
}
###################################################################
#
# Determine if there are any bank/channels assigned more than
# once.
#
###################################################################
proc ValidateMemoryBanks { m } \
{
global Emsg
global MemFreq
global MemHide
global MemBankLetter
global MemBankCh
global RBankID
set code 0
for {set ch 0} {$ch < 1000} {incr ch} \
{
if { ($MemHide($ch) == "hide") \
|| ($MemBankLetter($ch) == "") \
|| ($MemBankCh($ch) == "") } \
{
continue
}
set key "$MemBankLetter($ch),$MemBankCh($ch)"
if {$key == ","} {continue}
if { ($MemBankCh($ch) < 0) || ($MemBankCh($ch) > 99) } \
{
append Emsg "\nError: $m\n"
append Emsg "Memory $ch, memory "
append Emsg "channel number must be "
append Emsg "be 0 to 99, not $MemBankCh($ch)."
set code error
break
}
if { [info exists RBankID($MemBankLetter($ch))] == 0 } \
{
append Emsg "\nError: $m\n"
append Emsg "Memory $ch, memory "
append Emsg "bank number must be "
append Emsg "A-H, J, L, N, O-R, T, U, "
append Emsg "or Y, not $MemBankLetter($ch)."
set code error
break
}
# If this bank/ch is already assigned.
if { [info exists bankch($key)] } \
{
# Error - Another memory location is assigned
# to this bank and channel.
append Emsg "\nError: $m\n"
append Emsg "Bank $MemBankLetter($ch) "
append Emsg "Channel $MemBankCh($ch) "
append Emsg "cannot be assigned to two "
append Emsg "different memories "
append Emsg "($bankch($key) and $ch). "
set code error
break
} \
else \
{
# Mark this bank/ch as assigned.
set bankch($key) $ch
}
}
return $code
}
###################################################################
# Set title of the main window so it contains the
# current template file name.
###################################################################
proc SetWinTitle { } \
{
global GlobalParam
if { ( [info exists GlobalParam(TemplateFilename)] == 0 ) \
|| ($GlobalParam(TemplateFilename) == "") } \
{
set filename untitled.tr5
} \
else \
{
set filename $GlobalParam(TemplateFilename)
}
set s [format "tk5 - %s" $filename]
wm title . $s
return
}
# Prevent user from shrinking or expanding window.
proc FixSize { w } \
{
wm minsize $w [winfo width $w] [winfo height $w]
wm maxsize $w [winfo width $w] [winfo height $w]
return
}
######################################################################
# Bob Parnass
# DATE:
#
# USAGE: SortaBank first last
#
# INPUTS:
# first -starting channel to sort
# last -ending channel to sort
#
# RETURNS:
# 0 -ok
# -1 -error
#
#
# PURPOSE: Sort a range of memory channels based on frequency.
#
# DESCRIPTION:
#
######################################################################
proc SortaBank { first last } \
{
global GlobalParam
global MemDuplex
global MemFreq
global MemLabel
global MemMode
global MemOffset
global MemSkip
global MemStep
global MemToneCode
global MemToneFlag
global Mimage
if {[info exists Mimage] == 0} \
{
set msg "You must open a template file\n"
append msg " or read an image from the radio\n"
append msg " before sorting channels.\n"
tk_dialog .belch "tk5" \
$msg info 0 OK
return -1
}
if {$GlobalParam(SortType) == "freq"} \
{
set inlist [Bank2List MemFreq $first $last]
set vorder [SortFreqList $inlist]
} \
else \
{
set inlist [Bank2List MemLabel $first $last]
set vorder [SortLabelList $inlist]
}
set inlist [Bank2List MemFreq $first $last]
set slist [ReorderList $inlist $vorder]
for {set i $first; set j 0} {$i <= $last} {incr i; incr j} \
{
set MemFreq($i) [lindex $slist $j]
}
set slist [ReorderList $inlist $vorder]
for {set i $first; set j 0} {$i <= $last} {incr i; incr j} \
{
set MemFreq($i) [lindex $slist $j]
}
set inlist [Bank2List MemMode $first $last]
set slist [ReorderList $inlist $vorder]
for {set i $first; set j 0} {$i <= $last} {incr i; incr j} \
{
set MemMode($i) [lindex $slist $j]
if {$MemMode($i) == ""} \
{
set MemMode($i) NFM
}
}
set inlist [Bank2List MemDuplex $first $last]
set slist [ReorderList $inlist $vorder]
for {set i $first; set j 0} {$i <= $last} {incr i; incr j} \
{
set MemDuplex($i) [lindex $slist $j]
}
set inlist [Bank2List MemOffset $first $last]
set slist [ReorderList $inlist $vorder]
for {set i $first; set j 0} {$i <= $last} {incr i; incr j} \
{
set MemOffset($i) [lindex $slist $j]
}
set inlist [Bank2List MemSkip $first $last]
set slist [ReorderList $inlist $vorder]
for {set i $first; set j 0} {$i <= $last} {incr i; incr j} \
{
set MemSkip($i) [lindex $slist $j]
}
set inlist [Bank2List MemToneCode $first $last]
set slist [ReorderList $inlist $vorder]
for {set i $first; set j 0} {$i <= $last} {incr i; incr j} \
{
set MemToneCode($i) [lindex $slist $j]
}
set inlist [Bank2List MemToneFlag $first $last]
set slist [ReorderList $inlist $vorder]
for {set i $first; set j 0} {$i <= $last} {incr i; incr j} \
{
set MemToneFlag($i) [lindex $slist $j]
}
set inlist [Bank2List MemStep $first $last]
set slist [ReorderList $inlist $vorder]
for {set i $first; set j 0} {$i <= $last} {incr i; incr j} \
{
set MemStep($i) [lindex $slist $j]
}
set inlist [Bank2List MemLabel $first $last]
set slist [ReorderList $inlist $vorder]
for {set i $first; set j 0} {$i <= $last} {incr i; incr j} \
{
set MemLabel($i) [lindex $slist $j]
}
return 0
}
proc ClearAllChannels { } \
{
global Cht
global GlobalParam
global Mimage
global MemFreq
global MemSkip
if { ([info exists Mimage] == 0) \
|| ([string length $Mimage] <= 0)} \
{
# No image to write.
set msg "You must first read template data from"
append msg " the radio or open a file before"
append msg " clearing memories."
tk_dialog .error "Clear all channels" $msg error 0 OK
return
}
set msg "Warning: This operation will clear all 1000 "
append msg "memory channels."
set result [tk_dialog .clearall "Warning" \
$msg warning 0 Cancel "Clear Memories" ]
if {$result == 0} {return}
for {set ch 0} {$ch < 1000} {incr ch} \
{
ZapChannel $ch
}
ShowChannels $Cht
return
}
proc ZapChannel { ch } \
{
global MemBankLetter
global MemBankCh
global MemDuplex
global MemFreq
global MemHide
global MemLabel
global MemMode
global MemOffset
global MemSkip
global MemStep
global MemDTonePolarity
global MemDToneCode
global MemToneCode
global MemToneFlag
set MemFreq($ch) 0
set MemDuplex($ch) ""
set MemHide($ch) hide
set MemLabel($ch) ""
set MemMode($ch) NFM
set MemOffset($ch) ""
set MemSkip($ch) " "
set MemStep($ch) 5
set MemDTonePolarity($ch) n
set MemDToneCode($ch) "023"
set MemToneCode($ch) "88.5"
set MemToneFlag($ch) "off"
set MemBankLetter($ch) ""
set MemBankCh($ch) ""
return
}
proc ZapBankLabels { } \
{
global BankLabel
global NBanks
for {set bn 0} {$bn < $NBanks} {incr bn} \
{
set BankLabel($bn) ""
}
return
}
###################################################################
# Create memory banks.
###################################################################
proc MakeMemoryBankFrame { f }\
{
global GlobalParam
global MemNB
frame $f -relief groove -borderwidth 3
# frame $f.b -relief flat -borderwidth 3
label $f.lab -text "Memory Bank Settings" -borderwidth 3
pack $f.lab \
-side top -fill both -expand false -padx 3 -pady 3
MakeMemoryBankFrameCommon $f.common
pack $f.common -side left -padx 3 -pady 3 -fill both
set MemNB $f.banknb
MakeMemoryBankNB $MemNB
return $f
}
###################################################################
# Make a frame for settings common to all memory banks.
###################################################################
proc MakeMemoryBankFrameCommon { f }\
{
global GlobalParam
frame $f -relief groove -borderwidth 3
return $f
}
###################################################################
# Make a single tabbed notebook to hold the settings
# for the individual memory banks.
###################################################################
proc MakeMemoryBankNB { w } \
{
global BankID
global NBanks
tabnotebook_create $w
# fix me
# for {set i 0} {$i < $NBanks} {incr i}
for {set i 0} {$i < 1} {incr i} \
{
if {[info exists BankID($i)]} \
{
set tl "Bank $BankID($i)"
} \
else \
{
set tl "Bank $i"
}
set p [tabnotebook_page $w $tl]
set fr $p.f; MakeMemoryBankPage $fr $i
pack $fr
}
pack $w -expand true -fill both
}
###################################################################
# Make a frame to hold the settings
# for one memory bank.
###################################################################
proc MakeMemoryBankPage { f bn }\
{
global GlobalParam
frame $f -relief flat -borderwidth 3
MakeBankSettingsFrame $f.c1 $bn
pack $f.c1 -side top \
-fill both -padx 3 -pady 3 -expand true
if {$GlobalParam(EditMemoryChannels) == "on"} \
{
MakeMemoryChannelFrame $f.c2 $bn
MakeFillerFrame $f.c3 $bn
pack $f.c2 -side left \
-fill both -padx 3 -pady 3 -expand true
pack $f.c3 -side left \
-fill both -padx 3 -pady 3 -expand true
}
return $f
}
###################################################################
# Create one a set of widgets which pertain to
# for one memory bank.
#
# INPUTS:
# f -frame to create
# bn -bank number
#
###################################################################
proc MakeBankSettingsFrame { f bn }\
{
global BankID
global BankLabel
global ChanBank
global DisplayFontSize
global GlobalParam
frame $f -relief flat -borderwidth 3
return $f
}
###################################################################
#
# INPUTS:
# f -frame to create
# bn -bank number
#
###################################################################
proc MakeFillerFrame { f bn }\
{
global DisplayFontSize
frame $f -relief flat -borderwidth 3
for {set i 0} {$i < 12} {incr i} \
{
label $f.filler$bn$i -text "-" -relief flat \
-borderwidth 6
grid $f.filler$bn$i -row $i -column 0 -sticky ew
}
return $f
}
###################################################################
# Create widgets for memory channels for a bank.
###################################################################
proc MakeMemoryChannelFrame { f bn }\
{
global GlobalParam
global NBanks
global NChanPerBank
global VNChanPerBank
frame $f -relief flat -borderwidth 3
label $f.lab -text "Memory Channels" -borderwidth 3
pack $f.lab -side top
ScrollformCreate $f.b
pack $f.b -expand yes -fill both
set w [ScrollFormInterior $f.b]
label $w.freq -text "Freq" -borderwidth 3
label $w.mode -text "Mode" -borderwidth 3
label $w.label -text "Label" -borderwidth 3
label $w.step -text "Step" -borderwidth 3
label $w.offset -text "Offset" -borderwidth 3
label $w.duplex -text "Duplex" -borderwidth 3
label $w.toneflag -text "TSQL" -borderwidth 3
label $w.tonecode -text "CTCSS" -borderwidth 3
label $w.skip -text "Skip" -borderwidth 3
label $w.move -text "Move" -borderwidth 3
if {$GlobalParam(EditMemoryChannels) == "on"} \
{
set ch 0
set bn 0
set i 0
MakeChannel $w $bn $i $ch
update idletasks
}
grid $w.freq -row 0 -column 20
grid $w.mode -row 0 -column 30
grid $w.label -row 0 -column 35
grid $w.step -row 0 -column 40
grid $w.offset -row 0 -column 50
grid $w.duplex -row 0 -column 60
grid $w.toneflag -row 0 -column 70
grid $w.tonecode -row 0 -column 80
grid $w.skip -row 0 -column 100
grid $w.move -row 0 -column 110 -columnspan 2
return $f
}
###################################################################
# Create one a set of widgets for one channel.
###################################################################
proc MakeChannel { f bn n ch }\
{
global ChanNumberRepeat
global GlobalParam
global MemDuplex
global MemFreq
global MemMode
global MemOffset
global MemSkip
global MemStep
global MemToneCode
global MemToneFlag
set row [expr {$n + 2}]
if {$ChanNumberRepeat == "yes"}\
{
set chn $n
} \
else \
{
set chn $ch
}
label $f.lab$bn$ch -text "$chn" -borderwidth 3
entry $f.freq$bn$ch -width 12 \
-textvariable MemFreq($ch) \
-background white
tk_optionMenu $f.modemenu$bn$ch MemMode($ch) \
NFM WFM AM
set wid [expr {2 + $GlobalParam(LabelLength)}]
entry $f.label$bn$ch -width $wid \
-textvariable MemLabel($ch) \
-background white
# tk_optionMenu $f.stepmenu$bn$ch MemStep($ch) \
# 5 6.25 9 10 12.5 15 20 25 30 50 100
#
entry $f.offset$bn$ch -width 12 \
-textvariable MemOffset($ch) \
-background white
tk_optionMenu $f.duplexmenu$bn$ch MemDuplex($ch) \
" " "-" "+"
# tk_optionMenu $f.toneflagmenu$bn$ch MemToneFlag($ch) \
# off tsql
entry $f.tonecode$bn$ch -width 7 \
-textvariable MemToneCode($ch) \
-background white
# tk_optionMenu $f.skipmenu$bn$ch MemSkip($ch) \
# pskip skip hide " "
#
#
button $f.lower$bn$ch -text "^" \
-command "SwapChannel $ch [expr {$ch - 1}] 1"
button $f.higher$bn$ch -text "v" \
-command "SwapChannel $ch [expr { $ch + 1}] 1"
button $f.insert$bn$ch -text "Insert" \
-command "InsertChannel $ch"
button $f.delete$bn$ch -text "Delete" \
-command "DeleteChannel $ch"
grid $f.lab$bn$ch -row $row -column 10
grid $f.freq$bn$ch -row $row -column 20
grid $f.modemenu$bn$ch -row $row -column 30 -sticky ew
grid $f.label$bn$ch -row $row -column 35 -sticky ew
# grid $f.stepmenu$bn$ch -row $row -column 40 -sticky ew
grid $f.offset$bn$ch -row $row -column 50 -sticky ew
grid $f.duplexmenu$bn$ch -row $row -column 60 -sticky ew
# grid $f.toneflagmenu$bn$ch -row $row -column 70 -sticky ew
grid $f.tonecode$bn$ch -row $row -column 80 -sticky ew
# grid $f.skipmenu$bn$ch -row $row -column 100 -sticky ew
grid $f.lower$bn$ch -row $row -column 110
grid $f.higher$bn$ch -row $row -column 120
grid $f.insert$bn$ch -row $row -column 130
grid $f.delete$bn$ch -row $row -column 140
return
}
###################################################################
# Insert a memory channel and move all the higher channels
# in the same bank higher by one channel. Clear the current
# channel in the bank.
###################################################################
proc InsertChannel { ch } \
{
global MemDuplex
global MemFreq
global MemLabel
global MemMode
global MemOffset
global MemSkip
global MemStep
global MemToneCode
global MemToneFlag
global NChanPerBank
global VNChanPerBank
set bn [expr {int($ch/$VNChanPerBank)}]
set last [expr {($bn * $VNChanPerBank) + $NChanPerBank - 1}]
if {$MemFreq($last) > 0} \
{
# No room.
set msg "Channel $last is not empty.\n\n"
append msg "Please delete channel $last before "
append msg "inserting a new channel $ch and "
append msg "moving the existing channels higher."
tk_dialog .belch "Insert new channel" \
$msg error 0 OK
return
}
set n [expr {$NChanPerBank - fmod($ch, $VNChanPerBank) - 1}]
set to $last
set from $last
incr from -1
for {set i 0} {$i < $n} {incr i} \
{
# puts stderr "InsertChannel: n: $n, moving channel $from to $to"
set MemFreq($to) $MemFreq($from)
set MemLabel($to) $MemLabel($from)
set MemMode($to) $MemMode($from)
set MemStep($to) $MemStep($from)
set MemOffset($to) $MemOffset($from)
set MemDuplex($to) $MemDuplex($from)
set MemToneFlag($to) $MemToneFlag($from)
set MemToneCode($to) $MemToneCode($from)
set MemSkip($to) $MemSkip($from)
incr from -1
incr to -1
}
ZapChannel $ch
}
###################################################################
# Delete a memory channel and move all the higher channels
# in the same bank to the previous channel. Clear the last
# channel in the bank.
###################################################################
proc DeleteChannel { ch } \
{
global MemDuplex
global MemFreq
global MemLabel
global MemMode
global MemOffset
global MemSkip
global MemStep
global MemToneCode
global MemToneFlag
global NChanPerBank
global VNChanPerBank
set n [expr {$NChanPerBank - fmod($ch, $VNChanPerBank) - 1}]
set to $ch
set from $ch
incr from
for {set i 0} {$i < $n} {incr i} \
{
set MemFreq($to) $MemFreq($from)
set MemLabel($to) $MemLabel($from)
set MemMode($to) $MemMode($from)
set MemStep($to) $MemStep($from)
set MemOffset($to) $MemOffset($from)
set MemDuplex($to) $MemDuplex($from)
set MemToneFlag($to) $MemToneFlag($from)
set MemToneCode($to) $MemToneCode($from)
set MemSkip($to) $MemSkip($from)
incr from
incr to
}
set bn [expr {int($ch/$VNChanPerBank)}]
set last [expr {($bn * $VNChanPerBank) + $NChanPerBank - 1}]
ZapChannel $last
return
}
###################################################################
# Swap channel with the another channel in the bank.
#
# INPUTS:
# ch1 -first channel
# ch2 -second channel
# samebank -1 = channels must be withn
# the same bank.
# 0 = channels may be in different
# banks.
###################################################################
proc SwapChannel { ch1 ch2 samebank } \
{
global MemDuplex
global MemFreq
global MemLabel
global MemMode
global MemOffset
global MemSkip
global MemStep
global MemToneCode
global MemToneFlag
global NChanPerBank
global VNChanPerBank
set bn [expr {int($ch1/$VNChanPerBank)}]
set last [expr {($bn * $VNChanPerBank) + $NChanPerBank - 1}]
set ch1r [expr {int(fmod($ch1,$VNChanPerBank))}]
set ch2r [expr {int(fmod($ch2,$VNChanPerBank))}]
if { $samebank && ( ($ch1 > $last) \
|| ($ch1 < 0) \
|| ($ch2 > $last) \
|| ($ch2 < 0) \
|| ($ch1r >= $NChanPerBank) \
|| ($ch2r >= $NChanPerBank) ) } \
{
set msg "Cannot move channel $ch1 to $ch2."
tk_dialog .belch "Move channel" \
$msg error 0 OK
return
}
set tmp $MemFreq($ch2)
set MemFreq($ch2) $MemFreq($ch1)
set MemFreq($ch1) $tmp
set tmp $MemLabel($ch2)
set MemLabel($ch2) $MemLabel($ch1)
set MemLabel($ch1) $tmp
set tmp $MemMode($ch2)
set MemMode($ch2) $MemMode($ch1)
set MemMode($ch1) $tmp
set tmp $MemStep($ch2)
set MemStep($ch2) $MemStep($ch1)
set MemStep($ch1) $tmp
set tmp $MemOffset($ch2)
set MemOffset($ch2) $MemOffset($ch1)
set MemOffset($ch1) $tmp
set tmp $MemDuplex($ch2)
set MemDuplex($ch2) $MemDuplex($ch1)
set MemDuplex($ch1) $tmp
set tmp $MemToneFlag($ch2)
set MemToneFlag($ch2) $MemToneFlag($ch1)
set MemToneFlag($ch1) $tmp
set tmp $MemToneCode($ch2)
set MemToneCode($ch2) $MemToneCode($ch1)
set MemToneCode($ch1) $tmp
set tmp $MemSkip($ch2)
set MemSkip($ch2) $MemSkip($ch1)
set MemSkip($ch1) $tmp
return
}
###################################################################
#
# Swap the bank settings, memory channel info, fleet map,
# and talk group info for 2 banks with each other.
#
###################################################################
proc SwapBank { bn1 bn2 } \
{
global BankLabel
global ChanBank
global Cht
global GlobalParam
global NBanks
global NChanPerBank
global VNChanPerBank
# Sanity checks.
if { $bn1 == $bn2 } \
{
# Swap bank with itself.
return
}
if { ($bn1 < 0) || ($bn1 >= $NBanks) \
|| ($bn2 < 0) || ($bn2 >= $NBanks) } \
{
# No such bank.
return
}
# Swap the memory channels.
set ch1 [expr {$bn1 * $VNChanPerBank}]
set ch2 [expr {$bn2 * $VNChanPerBank}]
for {set i 0} {$i < $NChanPerBank} {incr i} \
{
SwapChannel $ch1 $ch2 0
incr ch1
incr ch2
}
# Swap bank labels.
set tmp $BankLabel($bn1)
set BankLabel($bn1) $BankLabel($bn2)
set BankLabel($bn2) $tmp
ShowChannels $Cht
return
}
##############################################################
# Format a 6-character bank label for internal storage.
# Make it upper case.
# If it is all blanks, make it nulls.
#
# Input: s -label
#
# Returns: 6-byte internal representation
##############################################################
proc BankLabel2Internal { s } \
{
set s [ format "%-6s" $s ]
set s [ string range $s 0 5 ]
# Translate bogus characters to spaces
regsub -all {[^A-Za-z0-9 .,\+\*/()\-=]} $s " " s
# Labels must be upper case.
set s [string toupper $s]
if {$s == " "} \
{
set s [binary format "H2H2H2H2H2H2" 00 00 00 00 00 00]
}
return $s
}
##############################################################
# Format a 6-character bank label for display.
# If it is all nulls, make it blanks.
#
# Input: s -label
#
# Returns: 6-character ASCII string
##############################################################
proc Internal2BankLabel { s } \
{
# Translate bogus characters to spaces
regsub -all {[^A-Za-z0-9 .,\+\*/()\-=]} $s " " s
set s [ string range $s 0 5 ]
set s [string trimright $s " "]
# Labels must be upper case.
set s [string toupper $s]
return $s
}
##############################################################
# Translate an internal 36-bit (4-1/2 byte) label into
# ASCII for display.
# If it is all nulls, make it blanks.
#
# Input: s -5 byte string
#
# Returns: 6-character ASCII string
##############################################################
proc Internal2MemoryLabel { s } \
{
global Int2a
set b0 [string index $s 0]
set b1 [string index $s 1]
set b2 [string index $s 2]
set b3 [string index $s 3]
set b4 [string index $s 4]
set first [GetBitField $b0 4 7]
set second [GetBitField $b1 0 1]
set c(0) [expr {($first * 4) + $second}]
set c(1) [GetBitField $b1 2 7]
set c(2) [GetBitField $b2 0 5]
set first [GetBitField $b2 6 7]
set second [GetBitField $b3 0 3]
set c(3) [expr {($first * 16) + $second}]
set first [GetBitField $b3 4 7]
set second [GetBitField $b4 0 1]
set c(4) [expr {($first * 4) + $second}]
set c(5) [GetBitField $b4 2 7]
for {set i 0} {$i < 6} {incr i} \
{
if { [info exists Int2a($c($i))] == 0 } \
{
set c($i) 0
}
}
set s ""
for {set i 0} {$i < 6} {incr i} \
{
append s $Int2a($c($i))
}
# Translate bogus characters to spaces
# regsub -all {[^A-Za-z0-9 .,\+\*/()\-=]} $s " " s
set s [string trimright $s " "]
# Labels must be upper case.
set s [string toupper $s]
return $s
}
##############################################################
# Translate an ASCII label to internal 36-bit (4-1/2 byte)
# label into format.
# If it is all blanks, make it nulls.
#
# Input: s -ASCII string
#
# Returns: 5-byte binary string
##############################################################
proc MemoryLabel2Internal { s } \
{
global A2int
set s [ format "%-6s" $s ]
set s [ string range $s 0 5 ]
# Labels must be upper case.
set s [string toupper $s]
for {set i 0} {$i < 6} {incr i} \
{
set c($i) [string index $s $i]
if { [info exists A2int($c($i))] == 0 } \
{
set n($i) 0
} \
else \
{
set n($i) $A2int($c($i))
}
}
set b0 [binary format "H2" 00]
set b1 [binary format "H2" 00]
set b2 [binary format "H2" 00]
set b3 [binary format "H2" 00]
set b4 [binary format "H2" 00]
set x1 [expr {int($n(0) / 4)}]
set b0 [SetBitField $b0 4 7 $x1]
set x2 [expr {$n(0) - ($x1 * 4)}]
set b1 [SetBitField $b1 0 1 $x2]
set b1 [SetBitField $b1 2 7 $n(1)]
set b2 [SetBitField $b2 0 5 $n(2)]
set x1 [expr {int($n(3) / 16)}]
set b2 [SetBitField $b2 6 7 $x1]
set x2 [expr {$n(3) - ($x1 * 16)}]
set b3 [SetBitField $b3 0 3 $x2]
set x1 [expr {int($n(4) / 4)}]
set b3 [SetBitField $b3 4 7 $x1]
set x2 [expr {$n(4) - ($x1 * 4)}]
set b4 [SetBitField $b4 0 1 $x2]
set b4 [SetBitField $b4 2 7 $n(5)]
set bytes ""
append bytes $b0 $b1 $b2 $b3 $b4
return $bytes
}
##############################################################
# Clear the flags which indicate whether to hide a
# TV channel.
##############################################################
proc ClearHiddenTVChannelFlags { } \
{
global TVHideByte
for {set i 0} {$i < 9} {incr i} \
{
set TVHideByte($i) "00000000"
}
return
}
proc SetHiddenTVChannelFlags { } \
{
global TVHideByte
global TV
for {set ch 0} {$ch < 70} {incr ch} \
{
set whichbyte [ expr { floor($ch / 8) } ]
# set whichbyte [ expr { floor($whichbyte) } ]
set whichbyte [ expr { int($whichbyte) } ]
set whichbit [expr {$ch - ($whichbyte * 8)}]
set whichbit [expr {7 - $whichbit}]
set flag 0
if {$TV($ch,freq) < .1} \
{
set flag 1
}
set TVHideByte($whichbyte) [string replace \
$TVHideByte($whichbyte) \
$whichbit $whichbit $flag]
}
return
}
###################################################################
# Decode the TV channel hidden bit flags.
###################################################################
proc DecodeHiddenTVChannelFlags { } \
{
global ImageAddr
global Mimage
global TV
scan $ImageAddr(TVHide) "%x" first
set ch 0
for {set j 0} {$j < 9} {incr j} \
{
set b [string index $Mimage $first]
set k 7
for {set i 0} {$i < 8} {incr i} \
{
set hidden [GetBit $b $k]
if {$hidden} \
{
set TV($ch,hide) 1
} \
else \
{
set TV($ch,hide) 0
}
incr ch
incr k -1
}
incr first
}
return
}
proc PrintHiddenTVChannelFlags { } \
{
global TVHideByte
for {set i 0} {$i < 9} {incr i} \
{
set s [binary format "B8" $TVHideByte($i)]
binary scan $s "H2" s
puts stderr "$i $TVHideByte($i) $s"
}
return
}
##############################################################
# Clear the flags which indicate whether to skip a
# TV channel.
##############################################################
proc ClearSkipTVChannelFlags { } \
{
global TVSkipByte
for {set i 0} {$i < 9} {incr i} \
{
set TVSkipByte($i) "00000000"
}
return
}
proc SetSkipTVChannelFlags { } \
{
global TVSkipByte
global TV
for {set ch 0} {$ch < 70} {incr ch} \
{
set whichbyte [ expr { floor($ch / 8) } ]
# set whichbyte [ expr { floor($whichbyte) } ]
set whichbyte [ expr { int($whichbyte) } ]
set whichbit [expr {$ch - ($whichbyte * 8)}]
set whichbit [expr {7 - $whichbit}]
set flag 0
if {$TV($ch,skip)} \
{
set flag 1
}
set TVSkipByte($whichbyte) [string replace \
$TVSkipByte($whichbyte) \
$whichbit $whichbit $flag]
}
return
}
###################################################################
# Decode the TV channel skip bit flags.
###################################################################
proc DecodeSkipTVChannelFlags { } \
{
global ImageAddr
global Mimage
global TV
scan $ImageAddr(TVSkip) "%x" first
set ch 0
for {set j 0} {$j < 9} {incr j} \
{
set b [string index $Mimage $first]
set k 7
for {set i 0} {$i < 8} {incr i} \
{
set skipped [GetBit $b $k]
if {$skipped} \
{
set TV($ch,skip) 1
} \
else \
{
set TV($ch,skip) 0
}
incr ch
incr k -1
}
incr first
}
return
}
proc PrintSkipTVChannelFlags { } \
{
global TVSkipByte
for {set i 0} {$i < 9} {incr i} \
{
set s [binary format "B8" $TVSkipByte($i)]
binary scan $s "H2" s
puts stderr "$i $TVSkipByte($i) $s"
}
return
}
|