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
/* ***********************************************************
* This file was automatically generated on 2024-02-27. *
* *
* Rust Bindings Version 2.0.21 *
* *
* If you have a bugfix for this file and want to commit it, *
* please fix the bug in the generator. You can find a link *
* to the generators git repository on tinkerforge.com *
*************************************************************/
//! Basis to build stacks and has 4 Bricklet ports.
//!
//! See also the documentation [here](https://www.tinkerforge.com/en/doc/Software/Bricks/Master_Brick_Rust.html).
use crate::{
byte_converter::*,
converting_callback_receiver::ConvertingCallbackReceiver,
converting_receiver::{BrickletError, ConvertingReceiver},
device::*,
ip_connection::GetRequestSender,
};
pub enum MasterBrickFunction {
GetStackVoltage,
GetStackCurrent,
SetExtensionType,
GetExtensionType,
IsChibiPresent,
SetChibiAddress,
GetChibiAddress,
SetChibiMasterAddress,
GetChibiMasterAddress,
SetChibiSlaveAddress,
GetChibiSlaveAddress,
GetChibiSignalStrength,
GetChibiErrorLog,
SetChibiFrequency,
GetChibiFrequency,
SetChibiChannel,
GetChibiChannel,
IsRs485Present,
SetRs485Address,
GetRs485Address,
SetRs485SlaveAddress,
GetRs485SlaveAddress,
GetRs485ErrorLog,
SetRs485Configuration,
GetRs485Configuration,
IsWifiPresent,
SetWifiConfiguration,
GetWifiConfiguration,
SetWifiEncryption,
GetWifiEncryption,
GetWifiStatus,
RefreshWifiStatus,
SetWifiCertificate,
GetWifiCertificate,
SetWifiPowerMode,
GetWifiPowerMode,
GetWifiBufferInfo,
SetWifiRegulatoryDomain,
GetWifiRegulatoryDomain,
GetUsbVoltage,
SetLongWifiKey,
GetLongWifiKey,
SetWifiHostname,
GetWifiHostname,
SetStackCurrentCallbackPeriod,
GetStackCurrentCallbackPeriod,
SetStackVoltageCallbackPeriod,
GetStackVoltageCallbackPeriod,
SetUsbVoltageCallbackPeriod,
GetUsbVoltageCallbackPeriod,
SetStackCurrentCallbackThreshold,
GetStackCurrentCallbackThreshold,
SetStackVoltageCallbackThreshold,
GetStackVoltageCallbackThreshold,
SetUsbVoltageCallbackThreshold,
GetUsbVoltageCallbackThreshold,
SetDebouncePeriod,
GetDebouncePeriod,
IsEthernetPresent,
SetEthernetConfiguration,
GetEthernetConfiguration,
GetEthernetStatus,
SetEthernetHostname,
SetEthernetMacAddress,
SetEthernetWebsocketConfiguration,
GetEthernetWebsocketConfiguration,
SetEthernetAuthenticationSecret,
GetEthernetAuthenticationSecret,
SetWifiAuthenticationSecret,
GetWifiAuthenticationSecret,
GetConnectionType,
IsWifi2Present,
StartWifi2Bootloader,
WriteWifi2SerialPort,
ReadWifi2SerialPort,
SetWifi2AuthenticationSecret,
GetWifi2AuthenticationSecret,
SetWifi2Configuration,
GetWifi2Configuration,
GetWifi2Status,
SetWifi2ClientConfiguration,
GetWifi2ClientConfiguration,
SetWifi2ClientHostname,
GetWifi2ClientHostname,
SetWifi2ClientPassword,
GetWifi2ClientPassword,
SetWifi2ApConfiguration,
GetWifi2ApConfiguration,
SetWifi2ApPassword,
GetWifi2ApPassword,
SaveWifi2Configuration,
GetWifi2FirmwareVersion,
EnableWifi2StatusLed,
DisableWifi2StatusLed,
IsWifi2StatusLedEnabled,
SetWifi2MeshConfiguration,
GetWifi2MeshConfiguration,
SetWifi2MeshRouterSsid,
GetWifi2MeshRouterSsid,
SetWifi2MeshRouterPassword,
GetWifi2MeshRouterPassword,
GetWifi2MeshCommonStatus,
GetWifi2MeshClientStatus,
GetWifi2MeshApStatus,
SetBrickletXmcFlashConfig,
SetBrickletXmcFlashData,
SetBrickletsEnabled,
GetBrickletsEnabled,
SetSpitfpBaudrateConfig,
GetSpitfpBaudrateConfig,
GetSendTimeoutCount,
SetSpitfpBaudrate,
GetSpitfpBaudrate,
GetSpitfpErrorCount,
EnableStatusLed,
DisableStatusLed,
IsStatusLedEnabled,
GetProtocol1BrickletName,
GetChipTemperature,
Reset,
WriteBrickletPlugin,
ReadBrickletPlugin,
GetIdentity,
CallbackStackCurrent,
CallbackStackVoltage,
CallbackUsbVoltage,
CallbackStackCurrentReached,
CallbackStackVoltageReached,
CallbackUsbVoltageReached,
}
impl From<MasterBrickFunction> for u8 {
fn from(fun: MasterBrickFunction) -> Self {
match fun {
MasterBrickFunction::GetStackVoltage => 1,
MasterBrickFunction::GetStackCurrent => 2,
MasterBrickFunction::SetExtensionType => 3,
MasterBrickFunction::GetExtensionType => 4,
MasterBrickFunction::IsChibiPresent => 5,
MasterBrickFunction::SetChibiAddress => 6,
MasterBrickFunction::GetChibiAddress => 7,
MasterBrickFunction::SetChibiMasterAddress => 8,
MasterBrickFunction::GetChibiMasterAddress => 9,
MasterBrickFunction::SetChibiSlaveAddress => 10,
MasterBrickFunction::GetChibiSlaveAddress => 11,
MasterBrickFunction::GetChibiSignalStrength => 12,
MasterBrickFunction::GetChibiErrorLog => 13,
MasterBrickFunction::SetChibiFrequency => 14,
MasterBrickFunction::GetChibiFrequency => 15,
MasterBrickFunction::SetChibiChannel => 16,
MasterBrickFunction::GetChibiChannel => 17,
MasterBrickFunction::IsRs485Present => 18,
MasterBrickFunction::SetRs485Address => 19,
MasterBrickFunction::GetRs485Address => 20,
MasterBrickFunction::SetRs485SlaveAddress => 21,
MasterBrickFunction::GetRs485SlaveAddress => 22,
MasterBrickFunction::GetRs485ErrorLog => 23,
MasterBrickFunction::SetRs485Configuration => 24,
MasterBrickFunction::GetRs485Configuration => 25,
MasterBrickFunction::IsWifiPresent => 26,
MasterBrickFunction::SetWifiConfiguration => 27,
MasterBrickFunction::GetWifiConfiguration => 28,
MasterBrickFunction::SetWifiEncryption => 29,
MasterBrickFunction::GetWifiEncryption => 30,
MasterBrickFunction::GetWifiStatus => 31,
MasterBrickFunction::RefreshWifiStatus => 32,
MasterBrickFunction::SetWifiCertificate => 33,
MasterBrickFunction::GetWifiCertificate => 34,
MasterBrickFunction::SetWifiPowerMode => 35,
MasterBrickFunction::GetWifiPowerMode => 36,
MasterBrickFunction::GetWifiBufferInfo => 37,
MasterBrickFunction::SetWifiRegulatoryDomain => 38,
MasterBrickFunction::GetWifiRegulatoryDomain => 39,
MasterBrickFunction::GetUsbVoltage => 40,
MasterBrickFunction::SetLongWifiKey => 41,
MasterBrickFunction::GetLongWifiKey => 42,
MasterBrickFunction::SetWifiHostname => 43,
MasterBrickFunction::GetWifiHostname => 44,
MasterBrickFunction::SetStackCurrentCallbackPeriod => 45,
MasterBrickFunction::GetStackCurrentCallbackPeriod => 46,
MasterBrickFunction::SetStackVoltageCallbackPeriod => 47,
MasterBrickFunction::GetStackVoltageCallbackPeriod => 48,
MasterBrickFunction::SetUsbVoltageCallbackPeriod => 49,
MasterBrickFunction::GetUsbVoltageCallbackPeriod => 50,
MasterBrickFunction::SetStackCurrentCallbackThreshold => 51,
MasterBrickFunction::GetStackCurrentCallbackThreshold => 52,
MasterBrickFunction::SetStackVoltageCallbackThreshold => 53,
MasterBrickFunction::GetStackVoltageCallbackThreshold => 54,
MasterBrickFunction::SetUsbVoltageCallbackThreshold => 55,
MasterBrickFunction::GetUsbVoltageCallbackThreshold => 56,
MasterBrickFunction::SetDebouncePeriod => 57,
MasterBrickFunction::GetDebouncePeriod => 58,
MasterBrickFunction::IsEthernetPresent => 65,
MasterBrickFunction::SetEthernetConfiguration => 66,
MasterBrickFunction::GetEthernetConfiguration => 67,
MasterBrickFunction::GetEthernetStatus => 68,
MasterBrickFunction::SetEthernetHostname => 69,
MasterBrickFunction::SetEthernetMacAddress => 70,
MasterBrickFunction::SetEthernetWebsocketConfiguration => 71,
MasterBrickFunction::GetEthernetWebsocketConfiguration => 72,
MasterBrickFunction::SetEthernetAuthenticationSecret => 73,
MasterBrickFunction::GetEthernetAuthenticationSecret => 74,
MasterBrickFunction::SetWifiAuthenticationSecret => 75,
MasterBrickFunction::GetWifiAuthenticationSecret => 76,
MasterBrickFunction::GetConnectionType => 77,
MasterBrickFunction::IsWifi2Present => 78,
MasterBrickFunction::StartWifi2Bootloader => 79,
MasterBrickFunction::WriteWifi2SerialPort => 80,
MasterBrickFunction::ReadWifi2SerialPort => 81,
MasterBrickFunction::SetWifi2AuthenticationSecret => 82,
MasterBrickFunction::GetWifi2AuthenticationSecret => 83,
MasterBrickFunction::SetWifi2Configuration => 84,
MasterBrickFunction::GetWifi2Configuration => 85,
MasterBrickFunction::GetWifi2Status => 86,
MasterBrickFunction::SetWifi2ClientConfiguration => 87,
MasterBrickFunction::GetWifi2ClientConfiguration => 88,
MasterBrickFunction::SetWifi2ClientHostname => 89,
MasterBrickFunction::GetWifi2ClientHostname => 90,
MasterBrickFunction::SetWifi2ClientPassword => 91,
MasterBrickFunction::GetWifi2ClientPassword => 92,
MasterBrickFunction::SetWifi2ApConfiguration => 93,
MasterBrickFunction::GetWifi2ApConfiguration => 94,
MasterBrickFunction::SetWifi2ApPassword => 95,
MasterBrickFunction::GetWifi2ApPassword => 96,
MasterBrickFunction::SaveWifi2Configuration => 97,
MasterBrickFunction::GetWifi2FirmwareVersion => 98,
MasterBrickFunction::EnableWifi2StatusLed => 99,
MasterBrickFunction::DisableWifi2StatusLed => 100,
MasterBrickFunction::IsWifi2StatusLedEnabled => 101,
MasterBrickFunction::SetWifi2MeshConfiguration => 102,
MasterBrickFunction::GetWifi2MeshConfiguration => 103,
MasterBrickFunction::SetWifi2MeshRouterSsid => 104,
MasterBrickFunction::GetWifi2MeshRouterSsid => 105,
MasterBrickFunction::SetWifi2MeshRouterPassword => 106,
MasterBrickFunction::GetWifi2MeshRouterPassword => 107,
MasterBrickFunction::GetWifi2MeshCommonStatus => 108,
MasterBrickFunction::GetWifi2MeshClientStatus => 109,
MasterBrickFunction::GetWifi2MeshApStatus => 110,
MasterBrickFunction::SetBrickletXmcFlashConfig => 111,
MasterBrickFunction::SetBrickletXmcFlashData => 112,
MasterBrickFunction::SetBrickletsEnabled => 113,
MasterBrickFunction::GetBrickletsEnabled => 114,
MasterBrickFunction::SetSpitfpBaudrateConfig => 231,
MasterBrickFunction::GetSpitfpBaudrateConfig => 232,
MasterBrickFunction::GetSendTimeoutCount => 233,
MasterBrickFunction::SetSpitfpBaudrate => 234,
MasterBrickFunction::GetSpitfpBaudrate => 235,
MasterBrickFunction::GetSpitfpErrorCount => 237,
MasterBrickFunction::EnableStatusLed => 238,
MasterBrickFunction::DisableStatusLed => 239,
MasterBrickFunction::IsStatusLedEnabled => 240,
MasterBrickFunction::GetProtocol1BrickletName => 241,
MasterBrickFunction::GetChipTemperature => 242,
MasterBrickFunction::Reset => 243,
MasterBrickFunction::WriteBrickletPlugin => 246,
MasterBrickFunction::ReadBrickletPlugin => 247,
MasterBrickFunction::GetIdentity => 255,
MasterBrickFunction::CallbackStackCurrent => 59,
MasterBrickFunction::CallbackStackVoltage => 60,
MasterBrickFunction::CallbackUsbVoltage => 61,
MasterBrickFunction::CallbackStackCurrentReached => 62,
MasterBrickFunction::CallbackStackVoltageReached => 63,
MasterBrickFunction::CallbackUsbVoltageReached => 64,
}
}
}
pub const MASTER_BRICK_EXTENSION_TYPE_CHIBI: u32 = 1;
pub const MASTER_BRICK_EXTENSION_TYPE_RS485: u32 = 2;
pub const MASTER_BRICK_EXTENSION_TYPE_WIFI: u32 = 3;
pub const MASTER_BRICK_EXTENSION_TYPE_ETHERNET: u32 = 4;
pub const MASTER_BRICK_EXTENSION_TYPE_WIFI2: u32 = 5;
pub const MASTER_BRICK_CHIBI_FREQUENCY_OQPSK_868_MHZ: u8 = 0;
pub const MASTER_BRICK_CHIBI_FREQUENCY_OQPSK_915_MHZ: u8 = 1;
pub const MASTER_BRICK_CHIBI_FREQUENCY_OQPSK_780_MHZ: u8 = 2;
pub const MASTER_BRICK_CHIBI_FREQUENCY_BPSK40_915_MHZ: u8 = 3;
pub const MASTER_BRICK_RS485_PARITY_NONE: char = 'n';
pub const MASTER_BRICK_RS485_PARITY_EVEN: char = 'e';
pub const MASTER_BRICK_RS485_PARITY_ODD: char = 'o';
pub const MASTER_BRICK_WIFI_CONNECTION_DHCP: u8 = 0;
pub const MASTER_BRICK_WIFI_CONNECTION_STATIC_IP: u8 = 1;
pub const MASTER_BRICK_WIFI_CONNECTION_ACCESS_POINT_DHCP: u8 = 2;
pub const MASTER_BRICK_WIFI_CONNECTION_ACCESS_POINT_STATIC_IP: u8 = 3;
pub const MASTER_BRICK_WIFI_CONNECTION_AD_HOC_DHCP: u8 = 4;
pub const MASTER_BRICK_WIFI_CONNECTION_AD_HOC_STATIC_IP: u8 = 5;
pub const MASTER_BRICK_WIFI_ENCRYPTION_WPA_WPA2: u8 = 0;
pub const MASTER_BRICK_WIFI_ENCRYPTION_WPA_ENTERPRISE: u8 = 1;
pub const MASTER_BRICK_WIFI_ENCRYPTION_WEP: u8 = 2;
pub const MASTER_BRICK_WIFI_ENCRYPTION_NO_ENCRYPTION: u8 = 3;
pub const MASTER_BRICK_WIFI_EAP_OPTION_OUTER_AUTH_EAP_FAST: u8 = 0;
pub const MASTER_BRICK_WIFI_EAP_OPTION_OUTER_AUTH_EAP_TLS: u8 = 1;
pub const MASTER_BRICK_WIFI_EAP_OPTION_OUTER_AUTH_EAP_TTLS: u8 = 2;
pub const MASTER_BRICK_WIFI_EAP_OPTION_OUTER_AUTH_EAP_PEAP: u8 = 3;
pub const MASTER_BRICK_WIFI_EAP_OPTION_INNER_AUTH_EAP_MSCHAP: u8 = 0;
pub const MASTER_BRICK_WIFI_EAP_OPTION_INNER_AUTH_EAP_GTC: u8 = 4;
pub const MASTER_BRICK_WIFI_EAP_OPTION_CERT_TYPE_CA_CERT: u8 = 0;
pub const MASTER_BRICK_WIFI_EAP_OPTION_CERT_TYPE_CLIENT_CERT: u8 = 8;
pub const MASTER_BRICK_WIFI_EAP_OPTION_CERT_TYPE_PRIVATE_KEY: u8 = 16;
pub const MASTER_BRICK_WIFI_STATE_DISASSOCIATED: u8 = 0;
pub const MASTER_BRICK_WIFI_STATE_ASSOCIATED: u8 = 1;
pub const MASTER_BRICK_WIFI_STATE_ASSOCIATING: u8 = 2;
pub const MASTER_BRICK_WIFI_STATE_ERROR: u8 = 3;
pub const MASTER_BRICK_WIFI_STATE_NOT_INITIALIZED_YET: u8 = 255;
pub const MASTER_BRICK_WIFI_POWER_MODE_FULL_SPEED: u8 = 0;
pub const MASTER_BRICK_WIFI_POWER_MODE_LOW_POWER: u8 = 1;
pub const MASTER_BRICK_WIFI_DOMAIN_CHANNEL_1TO11: u8 = 0;
pub const MASTER_BRICK_WIFI_DOMAIN_CHANNEL_1TO13: u8 = 1;
pub const MASTER_BRICK_WIFI_DOMAIN_CHANNEL_1TO14: u8 = 2;
pub const MASTER_BRICK_THRESHOLD_OPTION_OFF: char = 'x';
pub const MASTER_BRICK_THRESHOLD_OPTION_OUTSIDE: char = 'o';
pub const MASTER_BRICK_THRESHOLD_OPTION_INSIDE: char = 'i';
pub const MASTER_BRICK_THRESHOLD_OPTION_SMALLER: char = '<';
pub const MASTER_BRICK_THRESHOLD_OPTION_GREATER: char = '>';
pub const MASTER_BRICK_ETHERNET_CONNECTION_DHCP: u8 = 0;
pub const MASTER_BRICK_ETHERNET_CONNECTION_STATIC_IP: u8 = 1;
pub const MASTER_BRICK_CONNECTION_TYPE_NONE: u8 = 0;
pub const MASTER_BRICK_CONNECTION_TYPE_USB: u8 = 1;
pub const MASTER_BRICK_CONNECTION_TYPE_SPI_STACK: u8 = 2;
pub const MASTER_BRICK_CONNECTION_TYPE_CHIBI: u8 = 3;
pub const MASTER_BRICK_CONNECTION_TYPE_RS485: u8 = 4;
pub const MASTER_BRICK_CONNECTION_TYPE_WIFI: u8 = 5;
pub const MASTER_BRICK_CONNECTION_TYPE_ETHERNET: u8 = 6;
pub const MASTER_BRICK_CONNECTION_TYPE_WIFI2: u8 = 7;
pub const MASTER_BRICK_WIFI2_PHY_MODE_B: u8 = 0;
pub const MASTER_BRICK_WIFI2_PHY_MODE_G: u8 = 1;
pub const MASTER_BRICK_WIFI2_PHY_MODE_N: u8 = 2;
pub const MASTER_BRICK_WIFI2_CLIENT_STATUS_IDLE: u8 = 0;
pub const MASTER_BRICK_WIFI2_CLIENT_STATUS_CONNECTING: u8 = 1;
pub const MASTER_BRICK_WIFI2_CLIENT_STATUS_WRONG_PASSWORD: u8 = 2;
pub const MASTER_BRICK_WIFI2_CLIENT_STATUS_NO_AP_FOUND: u8 = 3;
pub const MASTER_BRICK_WIFI2_CLIENT_STATUS_CONNECT_FAILED: u8 = 4;
pub const MASTER_BRICK_WIFI2_CLIENT_STATUS_GOT_IP: u8 = 5;
pub const MASTER_BRICK_WIFI2_CLIENT_STATUS_UNKNOWN: u8 = 255;
pub const MASTER_BRICK_WIFI2_AP_ENCRYPTION_OPEN: u8 = 0;
pub const MASTER_BRICK_WIFI2_AP_ENCRYPTION_WEP: u8 = 1;
pub const MASTER_BRICK_WIFI2_AP_ENCRYPTION_WPA_PSK: u8 = 2;
pub const MASTER_BRICK_WIFI2_AP_ENCRYPTION_WPA2_PSK: u8 = 3;
pub const MASTER_BRICK_WIFI2_AP_ENCRYPTION_WPA_WPA2_PSK: u8 = 4;
pub const MASTER_BRICK_WIFI2_MESH_STATUS_DISABLED: u8 = 0;
pub const MASTER_BRICK_WIFI2_MESH_STATUS_WIFI_CONNECTING: u8 = 1;
pub const MASTER_BRICK_WIFI2_MESH_STATUS_GOT_IP: u8 = 2;
pub const MASTER_BRICK_WIFI2_MESH_STATUS_MESH_LOCAL: u8 = 3;
pub const MASTER_BRICK_WIFI2_MESH_STATUS_MESH_ONLINE: u8 = 4;
pub const MASTER_BRICK_WIFI2_MESH_STATUS_AP_AVAILABLE: u8 = 5;
pub const MASTER_BRICK_WIFI2_MESH_STATUS_AP_SETUP: u8 = 6;
pub const MASTER_BRICK_WIFI2_MESH_STATUS_LEAF_AVAILABLE: u8 = 7;
pub const MASTER_BRICK_COMMUNICATION_METHOD_NONE: u8 = 0;
pub const MASTER_BRICK_COMMUNICATION_METHOD_USB: u8 = 1;
pub const MASTER_BRICK_COMMUNICATION_METHOD_SPI_STACK: u8 = 2;
pub const MASTER_BRICK_COMMUNICATION_METHOD_CHIBI: u8 = 3;
pub const MASTER_BRICK_COMMUNICATION_METHOD_RS485: u8 = 4;
pub const MASTER_BRICK_COMMUNICATION_METHOD_WIFI: u8 = 5;
pub const MASTER_BRICK_COMMUNICATION_METHOD_ETHERNET: u8 = 6;
pub const MASTER_BRICK_COMMUNICATION_METHOD_WIFI_V2: u8 = 7;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct ChibiErrorLog {
pub underrun: u16,
pub crc_error: u16,
pub no_ack: u16,
pub overflow: u16,
}
impl FromByteSlice for ChibiErrorLog {
fn bytes_expected() -> usize { 8 }
fn from_le_byte_slice(bytes: &[u8]) -> ChibiErrorLog {
ChibiErrorLog {
underrun: <u16>::from_le_byte_slice(&bytes[0..2]),
crc_error: <u16>::from_le_byte_slice(&bytes[2..4]),
no_ack: <u16>::from_le_byte_slice(&bytes[4..6]),
overflow: <u16>::from_le_byte_slice(&bytes[6..8]),
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct Rs485Configuration {
pub speed: u32,
pub parity: char,
pub stopbits: u8,
}
impl FromByteSlice for Rs485Configuration {
fn bytes_expected() -> usize { 6 }
fn from_le_byte_slice(bytes: &[u8]) -> Rs485Configuration {
Rs485Configuration {
speed: <u32>::from_le_byte_slice(&bytes[0..4]),
parity: <char>::from_le_byte_slice(&bytes[4..5]),
stopbits: <u8>::from_le_byte_slice(&bytes[5..6]),
}
}
}
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
pub struct WifiConfiguration {
pub ssid: String,
pub connection: u8,
pub ip: [u8; 4],
pub subnet_mask: [u8; 4],
pub gateway: [u8; 4],
pub port: u16,
}
impl FromByteSlice for WifiConfiguration {
fn bytes_expected() -> usize { 47 }
fn from_le_byte_slice(bytes: &[u8]) -> WifiConfiguration {
WifiConfiguration {
ssid: <String>::from_le_byte_slice(&bytes[0..32]),
connection: <u8>::from_le_byte_slice(&bytes[32..33]),
ip: <[u8; 4]>::from_le_byte_slice(&bytes[33..37]),
subnet_mask: <[u8; 4]>::from_le_byte_slice(&bytes[37..41]),
gateway: <[u8; 4]>::from_le_byte_slice(&bytes[41..45]),
port: <u16>::from_le_byte_slice(&bytes[45..47]),
}
}
}
#[derive(Clone)]
pub struct WifiEncryption {
pub encryption: u8,
pub key: String,
pub key_index: u8,
pub eap_options: u8,
pub ca_certificate_length: u16,
pub client_certificate_length: u16,
pub private_key_length: u16,
}
impl FromByteSlice for WifiEncryption {
fn bytes_expected() -> usize { 59 }
fn from_le_byte_slice(bytes: &[u8]) -> WifiEncryption {
WifiEncryption {
encryption: <u8>::from_le_byte_slice(&bytes[0..1]),
key: <String>::from_le_byte_slice(&bytes[1..51]),
key_index: <u8>::from_le_byte_slice(&bytes[51..52]),
eap_options: <u8>::from_le_byte_slice(&bytes[52..53]),
ca_certificate_length: <u16>::from_le_byte_slice(&bytes[53..55]),
client_certificate_length: <u16>::from_le_byte_slice(&bytes[55..57]),
private_key_length: <u16>::from_le_byte_slice(&bytes[57..59]),
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct WifiStatus {
pub mac_address: [u8; 6],
pub bssid: [u8; 6],
pub channel: u8,
pub rssi: i16,
pub ip: [u8; 4],
pub subnet_mask: [u8; 4],
pub gateway: [u8; 4],
pub rx_count: u32,
pub tx_count: u32,
pub state: u8,
}
impl FromByteSlice for WifiStatus {
fn bytes_expected() -> usize { 36 }
fn from_le_byte_slice(bytes: &[u8]) -> WifiStatus {
WifiStatus {
mac_address: <[u8; 6]>::from_le_byte_slice(&bytes[0..6]),
bssid: <[u8; 6]>::from_le_byte_slice(&bytes[6..12]),
channel: <u8>::from_le_byte_slice(&bytes[12..13]),
rssi: <i16>::from_le_byte_slice(&bytes[13..15]),
ip: <[u8; 4]>::from_le_byte_slice(&bytes[15..19]),
subnet_mask: <[u8; 4]>::from_le_byte_slice(&bytes[19..23]),
gateway: <[u8; 4]>::from_le_byte_slice(&bytes[23..27]),
rx_count: <u32>::from_le_byte_slice(&bytes[27..31]),
tx_count: <u32>::from_le_byte_slice(&bytes[31..35]),
state: <u8>::from_le_byte_slice(&bytes[35..36]),
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct WifiCertificate {
pub data: [u8; 32],
pub data_length: u8,
}
impl FromByteSlice for WifiCertificate {
fn bytes_expected() -> usize { 33 }
fn from_le_byte_slice(bytes: &[u8]) -> WifiCertificate {
WifiCertificate { data: <[u8; 32]>::from_le_byte_slice(&bytes[0..32]), data_length: <u8>::from_le_byte_slice(&bytes[32..33]) }
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct WifiBufferInfo {
pub overflow: u32,
pub low_watermark: u16,
pub used: u16,
}
impl FromByteSlice for WifiBufferInfo {
fn bytes_expected() -> usize { 8 }
fn from_le_byte_slice(bytes: &[u8]) -> WifiBufferInfo {
WifiBufferInfo {
overflow: <u32>::from_le_byte_slice(&bytes[0..4]),
low_watermark: <u16>::from_le_byte_slice(&bytes[4..6]),
used: <u16>::from_le_byte_slice(&bytes[6..8]),
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct StackCurrentCallbackThreshold {
pub option: char,
pub min: u16,
pub max: u16,
}
impl FromByteSlice for StackCurrentCallbackThreshold {
fn bytes_expected() -> usize { 5 }
fn from_le_byte_slice(bytes: &[u8]) -> StackCurrentCallbackThreshold {
StackCurrentCallbackThreshold {
option: <char>::from_le_byte_slice(&bytes[0..1]),
min: <u16>::from_le_byte_slice(&bytes[1..3]),
max: <u16>::from_le_byte_slice(&bytes[3..5]),
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct StackVoltageCallbackThreshold {
pub option: char,
pub min: u16,
pub max: u16,
}
impl FromByteSlice for StackVoltageCallbackThreshold {
fn bytes_expected() -> usize { 5 }
fn from_le_byte_slice(bytes: &[u8]) -> StackVoltageCallbackThreshold {
StackVoltageCallbackThreshold {
option: <char>::from_le_byte_slice(&bytes[0..1]),
min: <u16>::from_le_byte_slice(&bytes[1..3]),
max: <u16>::from_le_byte_slice(&bytes[3..5]),
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct UsbVoltageCallbackThreshold {
pub option: char,
pub min: u16,
pub max: u16,
}
impl FromByteSlice for UsbVoltageCallbackThreshold {
fn bytes_expected() -> usize { 5 }
fn from_le_byte_slice(bytes: &[u8]) -> UsbVoltageCallbackThreshold {
UsbVoltageCallbackThreshold {
option: <char>::from_le_byte_slice(&bytes[0..1]),
min: <u16>::from_le_byte_slice(&bytes[1..3]),
max: <u16>::from_le_byte_slice(&bytes[3..5]),
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct EthernetConfiguration {
pub connection: u8,
pub ip: [u8; 4],
pub subnet_mask: [u8; 4],
pub gateway: [u8; 4],
pub port: u16,
}
impl FromByteSlice for EthernetConfiguration {
fn bytes_expected() -> usize { 15 }
fn from_le_byte_slice(bytes: &[u8]) -> EthernetConfiguration {
EthernetConfiguration {
connection: <u8>::from_le_byte_slice(&bytes[0..1]),
ip: <[u8; 4]>::from_le_byte_slice(&bytes[1..5]),
subnet_mask: <[u8; 4]>::from_le_byte_slice(&bytes[5..9]),
gateway: <[u8; 4]>::from_le_byte_slice(&bytes[9..13]),
port: <u16>::from_le_byte_slice(&bytes[13..15]),
}
}
}
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
pub struct EthernetStatus {
pub mac_address: [u8; 6],
pub ip: [u8; 4],
pub subnet_mask: [u8; 4],
pub gateway: [u8; 4],
pub rx_count: u32,
pub tx_count: u32,
pub hostname: String,
}
impl FromByteSlice for EthernetStatus {
fn bytes_expected() -> usize { 58 }
fn from_le_byte_slice(bytes: &[u8]) -> EthernetStatus {
EthernetStatus {
mac_address: <[u8; 6]>::from_le_byte_slice(&bytes[0..6]),
ip: <[u8; 4]>::from_le_byte_slice(&bytes[6..10]),
subnet_mask: <[u8; 4]>::from_le_byte_slice(&bytes[10..14]),
gateway: <[u8; 4]>::from_le_byte_slice(&bytes[14..18]),
rx_count: <u32>::from_le_byte_slice(&bytes[18..22]),
tx_count: <u32>::from_le_byte_slice(&bytes[22..26]),
hostname: <String>::from_le_byte_slice(&bytes[26..58]),
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct EthernetWebsocketConfiguration {
pub sockets: u8,
pub port: u16,
}
impl FromByteSlice for EthernetWebsocketConfiguration {
fn bytes_expected() -> usize { 3 }
fn from_le_byte_slice(bytes: &[u8]) -> EthernetWebsocketConfiguration {
EthernetWebsocketConfiguration { sockets: <u8>::from_le_byte_slice(&bytes[0..1]), port: <u16>::from_le_byte_slice(&bytes[1..3]) }
}
}
#[derive(Clone, Copy)]
pub struct ReadWifi2SerialPort {
pub data: [u8; 60],
pub result: u8,
}
impl FromByteSlice for ReadWifi2SerialPort {
fn bytes_expected() -> usize { 61 }
fn from_le_byte_slice(bytes: &[u8]) -> ReadWifi2SerialPort {
ReadWifi2SerialPort { data: <[u8; 60]>::from_le_byte_slice(&bytes[0..60]), result: <u8>::from_le_byte_slice(&bytes[60..61]) }
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct Wifi2Configuration {
pub port: u16,
pub websocket_port: u16,
pub website_port: u16,
pub phy_mode: u8,
pub sleep_mode: u8,
pub website: u8,
}
impl FromByteSlice for Wifi2Configuration {
fn bytes_expected() -> usize { 9 }
fn from_le_byte_slice(bytes: &[u8]) -> Wifi2Configuration {
Wifi2Configuration {
port: <u16>::from_le_byte_slice(&bytes[0..2]),
websocket_port: <u16>::from_le_byte_slice(&bytes[2..4]),
website_port: <u16>::from_le_byte_slice(&bytes[4..6]),
phy_mode: <u8>::from_le_byte_slice(&bytes[6..7]),
sleep_mode: <u8>::from_le_byte_slice(&bytes[7..8]),
website: <u8>::from_le_byte_slice(&bytes[8..9]),
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct Wifi2Status {
pub client_enabled: bool,
pub client_status: u8,
pub client_ip: [u8; 4],
pub client_subnet_mask: [u8; 4],
pub client_gateway: [u8; 4],
pub client_mac_address: [u8; 6],
pub client_rx_count: u32,
pub client_tx_count: u32,
pub client_rssi: i8,
pub ap_enabled: bool,
pub ap_ip: [u8; 4],
pub ap_subnet_mask: [u8; 4],
pub ap_gateway: [u8; 4],
pub ap_mac_address: [u8; 6],
pub ap_rx_count: u32,
pub ap_tx_count: u32,
pub ap_connected_count: u8,
}
impl FromByteSlice for Wifi2Status {
fn bytes_expected() -> usize { 57 }
fn from_le_byte_slice(bytes: &[u8]) -> Wifi2Status {
Wifi2Status {
client_enabled: <bool>::from_le_byte_slice(&bytes[0..1]),
client_status: <u8>::from_le_byte_slice(&bytes[1..2]),
client_ip: <[u8; 4]>::from_le_byte_slice(&bytes[2..6]),
client_subnet_mask: <[u8; 4]>::from_le_byte_slice(&bytes[6..10]),
client_gateway: <[u8; 4]>::from_le_byte_slice(&bytes[10..14]),
client_mac_address: <[u8; 6]>::from_le_byte_slice(&bytes[14..20]),
client_rx_count: <u32>::from_le_byte_slice(&bytes[20..24]),
client_tx_count: <u32>::from_le_byte_slice(&bytes[24..28]),
client_rssi: <i8>::from_le_byte_slice(&bytes[28..29]),
ap_enabled: <bool>::from_le_byte_slice(&bytes[29..30]),
ap_ip: <[u8; 4]>::from_le_byte_slice(&bytes[30..34]),
ap_subnet_mask: <[u8; 4]>::from_le_byte_slice(&bytes[34..38]),
ap_gateway: <[u8; 4]>::from_le_byte_slice(&bytes[38..42]),
ap_mac_address: <[u8; 6]>::from_le_byte_slice(&bytes[42..48]),
ap_rx_count: <u32>::from_le_byte_slice(&bytes[48..52]),
ap_tx_count: <u32>::from_le_byte_slice(&bytes[52..56]),
ap_connected_count: <u8>::from_le_byte_slice(&bytes[56..57]),
}
}
}
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
pub struct Wifi2ClientConfiguration {
pub enable: bool,
pub ssid: String,
pub ip: [u8; 4],
pub subnet_mask: [u8; 4],
pub gateway: [u8; 4],
pub mac_address: [u8; 6],
pub bssid: [u8; 6],
}
impl FromByteSlice for Wifi2ClientConfiguration {
fn bytes_expected() -> usize { 57 }
fn from_le_byte_slice(bytes: &[u8]) -> Wifi2ClientConfiguration {
Wifi2ClientConfiguration {
enable: <bool>::from_le_byte_slice(&bytes[0..1]),
ssid: <String>::from_le_byte_slice(&bytes[1..33]),
ip: <[u8; 4]>::from_le_byte_slice(&bytes[33..37]),
subnet_mask: <[u8; 4]>::from_le_byte_slice(&bytes[37..41]),
gateway: <[u8; 4]>::from_le_byte_slice(&bytes[41..45]),
mac_address: <[u8; 6]>::from_le_byte_slice(&bytes[45..51]),
bssid: <[u8; 6]>::from_le_byte_slice(&bytes[51..57]),
}
}
}
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
pub struct Wifi2ApConfiguration {
pub enable: bool,
pub ssid: String,
pub ip: [u8; 4],
pub subnet_mask: [u8; 4],
pub gateway: [u8; 4],
pub encryption: u8,
pub hidden: bool,
pub channel: u8,
pub mac_address: [u8; 6],
}
impl FromByteSlice for Wifi2ApConfiguration {
fn bytes_expected() -> usize { 54 }
fn from_le_byte_slice(bytes: &[u8]) -> Wifi2ApConfiguration {
Wifi2ApConfiguration {
enable: <bool>::from_le_byte_slice(&bytes[0..1]),
ssid: <String>::from_le_byte_slice(&bytes[1..33]),
ip: <[u8; 4]>::from_le_byte_slice(&bytes[33..37]),
subnet_mask: <[u8; 4]>::from_le_byte_slice(&bytes[37..41]),
gateway: <[u8; 4]>::from_le_byte_slice(&bytes[41..45]),
encryption: <u8>::from_le_byte_slice(&bytes[45..46]),
hidden: <bool>::from_le_byte_slice(&bytes[46..47]),
channel: <u8>::from_le_byte_slice(&bytes[47..48]),
mac_address: <[u8; 6]>::from_le_byte_slice(&bytes[48..54]),
}
}
}
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
pub struct Wifi2MeshConfiguration {
pub enable: bool,
pub root_ip: [u8; 4],
pub root_subnet_mask: [u8; 4],
pub root_gateway: [u8; 4],
pub router_bssid: [u8; 6],
pub group_id: [u8; 6],
pub group_ssid_prefix: String,
pub gateway_ip: [u8; 4],
pub gateway_port: u16,
}
impl FromByteSlice for Wifi2MeshConfiguration {
fn bytes_expected() -> usize { 47 }
fn from_le_byte_slice(bytes: &[u8]) -> Wifi2MeshConfiguration {
Wifi2MeshConfiguration {
enable: <bool>::from_le_byte_slice(&bytes[0..1]),
root_ip: <[u8; 4]>::from_le_byte_slice(&bytes[1..5]),
root_subnet_mask: <[u8; 4]>::from_le_byte_slice(&bytes[5..9]),
root_gateway: <[u8; 4]>::from_le_byte_slice(&bytes[9..13]),
router_bssid: <[u8; 6]>::from_le_byte_slice(&bytes[13..19]),
group_id: <[u8; 6]>::from_le_byte_slice(&bytes[19..25]),
group_ssid_prefix: <String>::from_le_byte_slice(&bytes[25..41]),
gateway_ip: <[u8; 4]>::from_le_byte_slice(&bytes[41..45]),
gateway_port: <u16>::from_le_byte_slice(&bytes[45..47]),
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct Wifi2MeshCommonStatus {
pub status: u8,
pub root_node: bool,
pub root_candidate: bool,
pub connected_nodes: u16,
pub rx_count: u32,
pub tx_count: u32,
}
impl FromByteSlice for Wifi2MeshCommonStatus {
fn bytes_expected() -> usize { 13 }
fn from_le_byte_slice(bytes: &[u8]) -> Wifi2MeshCommonStatus {
Wifi2MeshCommonStatus {
status: <u8>::from_le_byte_slice(&bytes[0..1]),
root_node: <bool>::from_le_byte_slice(&bytes[1..2]),
root_candidate: <bool>::from_le_byte_slice(&bytes[2..3]),
connected_nodes: <u16>::from_le_byte_slice(&bytes[3..5]),
rx_count: <u32>::from_le_byte_slice(&bytes[5..9]),
tx_count: <u32>::from_le_byte_slice(&bytes[9..13]),
}
}
}
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
pub struct Wifi2MeshClientStatus {
pub hostname: String,
pub ip: [u8; 4],
pub subnet_mask: [u8; 4],
pub gateway: [u8; 4],
pub mac_address: [u8; 6],
}
impl FromByteSlice for Wifi2MeshClientStatus {
fn bytes_expected() -> usize { 50 }
fn from_le_byte_slice(bytes: &[u8]) -> Wifi2MeshClientStatus {
Wifi2MeshClientStatus {
hostname: <String>::from_le_byte_slice(&bytes[0..32]),
ip: <[u8; 4]>::from_le_byte_slice(&bytes[32..36]),
subnet_mask: <[u8; 4]>::from_le_byte_slice(&bytes[36..40]),
gateway: <[u8; 4]>::from_le_byte_slice(&bytes[40..44]),
mac_address: <[u8; 6]>::from_le_byte_slice(&bytes[44..50]),
}
}
}
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
pub struct Wifi2MeshApStatus {
pub ssid: String,
pub ip: [u8; 4],
pub subnet_mask: [u8; 4],
pub gateway: [u8; 4],
pub mac_address: [u8; 6],
}
impl FromByteSlice for Wifi2MeshApStatus {
fn bytes_expected() -> usize { 50 }
fn from_le_byte_slice(bytes: &[u8]) -> Wifi2MeshApStatus {
Wifi2MeshApStatus {
ssid: <String>::from_le_byte_slice(&bytes[0..32]),
ip: <[u8; 4]>::from_le_byte_slice(&bytes[32..36]),
subnet_mask: <[u8; 4]>::from_le_byte_slice(&bytes[36..40]),
gateway: <[u8; 4]>::from_le_byte_slice(&bytes[40..44]),
mac_address: <[u8; 6]>::from_le_byte_slice(&bytes[44..50]),
}
}
}
#[derive(Clone, Copy)]
pub struct SetBrickletXmcFlashConfig {
pub return_value: u32,
pub return_data: [u8; 60],
}
impl FromByteSlice for SetBrickletXmcFlashConfig {
fn bytes_expected() -> usize { 64 }
fn from_le_byte_slice(bytes: &[u8]) -> SetBrickletXmcFlashConfig {
SetBrickletXmcFlashConfig {
return_value: <u32>::from_le_byte_slice(&bytes[0..4]),
return_data: <[u8; 60]>::from_le_byte_slice(&bytes[4..64]),
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct SpitfpBaudrateConfig {
pub enable_dynamic_baudrate: bool,
pub minimum_dynamic_baudrate: u32,
}
impl FromByteSlice for SpitfpBaudrateConfig {
fn bytes_expected() -> usize { 5 }
fn from_le_byte_slice(bytes: &[u8]) -> SpitfpBaudrateConfig {
SpitfpBaudrateConfig {
enable_dynamic_baudrate: <bool>::from_le_byte_slice(&bytes[0..1]),
minimum_dynamic_baudrate: <u32>::from_le_byte_slice(&bytes[1..5]),
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct SpitfpErrorCount {
pub error_count_ack_checksum: u32,
pub error_count_message_checksum: u32,
pub error_count_frame: u32,
pub error_count_overflow: u32,
}
impl FromByteSlice for SpitfpErrorCount {
fn bytes_expected() -> usize { 16 }
fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
SpitfpErrorCount {
error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
}
}
}
#[derive(Clone)]
pub struct Protocol1BrickletName {
pub protocol_version: u8,
pub firmware_version: [u8; 3],
pub name: String,
}
impl FromByteSlice for Protocol1BrickletName {
fn bytes_expected() -> usize { 44 }
fn from_le_byte_slice(bytes: &[u8]) -> Protocol1BrickletName {
Protocol1BrickletName {
protocol_version: <u8>::from_le_byte_slice(&bytes[0..1]),
firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[1..4]),
name: <String>::from_le_byte_slice(&bytes[4..44]),
}
}
}
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
pub struct Identity {
pub uid: String,
pub connected_uid: String,
pub position: char,
pub hardware_version: [u8; 3],
pub firmware_version: [u8; 3],
pub device_identifier: u16,
}
impl FromByteSlice for Identity {
fn bytes_expected() -> usize { 25 }
fn from_le_byte_slice(bytes: &[u8]) -> Identity {
Identity {
uid: <String>::from_le_byte_slice(&bytes[0..8]),
connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
position: <char>::from_le_byte_slice(&bytes[16..17]),
hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
}
}
}
/// Basis to build stacks and has 4 Bricklet ports
#[derive(Clone)]
pub struct MasterBrick {
device: Device,
}
impl MasterBrick {
pub const DEVICE_IDENTIFIER: u16 = 13;
pub const DEVICE_DISPLAY_NAME: &'static str = "Master Brick";
/// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
pub fn new<T: GetRequestSender>(uid: &str, req_sender: T) -> MasterBrick {
let mut result = MasterBrick { device: Device::new([2, 0, 10], uid, req_sender, 0) };
result.device.response_expected[u8::from(MasterBrickFunction::GetStackVoltage) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::GetStackCurrent) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SetExtensionType) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::GetExtensionType) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::IsChibiPresent) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SetChibiAddress) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::GetChibiAddress) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SetChibiMasterAddress) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::GetChibiMasterAddress) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SetChibiSlaveAddress) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::GetChibiSlaveAddress) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::GetChibiSignalStrength) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::GetChibiErrorLog) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SetChibiFrequency) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::GetChibiFrequency) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SetChibiChannel) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::GetChibiChannel) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::IsRs485Present) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SetRs485Address) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::GetRs485Address) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SetRs485SlaveAddress) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::GetRs485SlaveAddress) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::GetRs485ErrorLog) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SetRs485Configuration) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::GetRs485Configuration) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::IsWifiPresent) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SetWifiConfiguration) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::GetWifiConfiguration) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SetWifiEncryption) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::GetWifiEncryption) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::GetWifiStatus) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::RefreshWifiStatus) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::SetWifiCertificate) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::GetWifiCertificate) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SetWifiPowerMode) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::GetWifiPowerMode) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::GetWifiBufferInfo) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SetWifiRegulatoryDomain) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::GetWifiRegulatoryDomain) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::GetUsbVoltage) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SetLongWifiKey) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::GetLongWifiKey) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SetWifiHostname) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::GetWifiHostname) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SetStackCurrentCallbackPeriod) as usize] = ResponseExpectedFlag::True;
result.device.response_expected[u8::from(MasterBrickFunction::GetStackCurrentCallbackPeriod) as usize] =
ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SetStackVoltageCallbackPeriod) as usize] = ResponseExpectedFlag::True;
result.device.response_expected[u8::from(MasterBrickFunction::GetStackVoltageCallbackPeriod) as usize] =
ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SetUsbVoltageCallbackPeriod) as usize] = ResponseExpectedFlag::True;
result.device.response_expected[u8::from(MasterBrickFunction::GetUsbVoltageCallbackPeriod) as usize] =
ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SetStackCurrentCallbackThreshold) as usize] =
ResponseExpectedFlag::True;
result.device.response_expected[u8::from(MasterBrickFunction::GetStackCurrentCallbackThreshold) as usize] =
ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SetStackVoltageCallbackThreshold) as usize] =
ResponseExpectedFlag::True;
result.device.response_expected[u8::from(MasterBrickFunction::GetStackVoltageCallbackThreshold) as usize] =
ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SetUsbVoltageCallbackThreshold) as usize] =
ResponseExpectedFlag::True;
result.device.response_expected[u8::from(MasterBrickFunction::GetUsbVoltageCallbackThreshold) as usize] =
ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SetDebouncePeriod) as usize] = ResponseExpectedFlag::True;
result.device.response_expected[u8::from(MasterBrickFunction::GetDebouncePeriod) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::IsEthernetPresent) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SetEthernetConfiguration) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::GetEthernetConfiguration) as usize] =
ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::GetEthernetStatus) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SetEthernetHostname) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::SetEthernetMacAddress) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::SetEthernetWebsocketConfiguration) as usize] =
ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::GetEthernetWebsocketConfiguration) as usize] =
ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SetEthernetAuthenticationSecret) as usize] =
ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::GetEthernetAuthenticationSecret) as usize] =
ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SetWifiAuthenticationSecret) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::GetWifiAuthenticationSecret) as usize] =
ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::GetConnectionType) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::IsWifi2Present) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::StartWifi2Bootloader) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::WriteWifi2SerialPort) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::ReadWifi2SerialPort) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SetWifi2AuthenticationSecret) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::GetWifi2AuthenticationSecret) as usize] =
ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SetWifi2Configuration) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::GetWifi2Configuration) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::GetWifi2Status) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SetWifi2ClientConfiguration) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::GetWifi2ClientConfiguration) as usize] =
ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SetWifi2ClientHostname) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::GetWifi2ClientHostname) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SetWifi2ClientPassword) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::GetWifi2ClientPassword) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SetWifi2ApConfiguration) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::GetWifi2ApConfiguration) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SetWifi2ApPassword) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::GetWifi2ApPassword) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SaveWifi2Configuration) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::GetWifi2FirmwareVersion) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::EnableWifi2StatusLed) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::DisableWifi2StatusLed) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::IsWifi2StatusLedEnabled) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SetWifi2MeshConfiguration) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::GetWifi2MeshConfiguration) as usize] =
ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SetWifi2MeshRouterSsid) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::GetWifi2MeshRouterSsid) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SetWifi2MeshRouterPassword) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::GetWifi2MeshRouterPassword) as usize] =
ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::GetWifi2MeshCommonStatus) as usize] =
ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::GetWifi2MeshClientStatus) as usize] =
ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::GetWifi2MeshApStatus) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SetBrickletXmcFlashConfig) as usize] =
ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SetBrickletXmcFlashData) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SetBrickletsEnabled) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::GetBrickletsEnabled) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SetSpitfpBaudrateConfig) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::GetSpitfpBaudrateConfig) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::GetSendTimeoutCount) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::SetSpitfpBaudrate) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::GetSpitfpBaudrate) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::GetSpitfpErrorCount) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::EnableStatusLed) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::DisableStatusLed) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::IsStatusLedEnabled) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::GetProtocol1BrickletName) as usize] =
ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::GetChipTemperature) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::Reset) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::WriteBrickletPlugin) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(MasterBrickFunction::ReadBrickletPlugin) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(MasterBrickFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
result
}
/// Returns the response expected flag for the function specified by the function ID parameter.
/// It is true if the function is expected to send a response, false otherwise.
///
/// For getter functions this is enabled by default and cannot be disabled, because those
/// functions will always send a response. For callback configuration functions it is enabled
/// by default too, but can be disabled by [`set_response_expected`](crate::master_brick::MasterBrick::set_response_expected).
/// For setter functions it is disabled by default and can be enabled.
///
/// Enabling the response expected flag for a setter function allows to detect timeouts
/// and other error conditions calls of this setter as well. The device will then send a response
/// for this purpose. If this flag is disabled for a setter function then no response is sent
/// and errors are silently ignored, because they cannot be detected.
///
/// See [`set_response_expected`](crate::master_brick::MasterBrick::set_response_expected) for the list of function ID constants available for this function.
pub fn get_response_expected(&mut self, fun: MasterBrickFunction) -> Result<bool, GetResponseExpectedError> {
self.device.get_response_expected(u8::from(fun))
}
/// Changes the response expected flag of the function specified by the function ID parameter.
/// This flag can only be changed for setter (default value: false) and callback configuration
/// functions (default value: true). For getter functions it is always enabled.
///
/// Enabling the response expected flag for a setter function allows to detect timeouts and
/// other error conditions calls of this setter as well. The device will then send a response
/// for this purpose. If this flag is disabled for a setter function then no response is sent
/// and errors are silently ignored, because they cannot be detected.
pub fn set_response_expected(&mut self, fun: MasterBrickFunction, response_expected: bool) -> Result<(), SetResponseExpectedError> {
self.device.set_response_expected(u8::from(fun), response_expected)
}
/// Changes the response expected flag for all setter and callback configuration functions of this device at once.
pub fn set_response_expected_all(&mut self, response_expected: bool) { self.device.set_response_expected_all(response_expected) }
/// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
/// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
pub fn get_api_version(&self) -> [u8; 3] { self.device.api_version }
/// This receiver is triggered periodically with the period that is set by
/// [`set_stack_current_callback_period`]. The parameter is the current
/// of the sensor.
///
/// The [`get_stack_current_callback_receiver`] receiver is only triggered if the current has changed
/// since the last triggering.
///
/// [`set_stack_current_callback_period`]: #method.set_stack_current_callback_period
/// [`get_stack_current_callback_receiver`]: #method.get_stack_current_callback_receiver
/// .. versionadded:: 2.0.5$nbsp;(Firmware)
pub fn get_stack_current_callback_receiver(&self) -> ConvertingCallbackReceiver<u16> {
self.device.get_callback_receiver(u8::from(MasterBrickFunction::CallbackStackCurrent))
}
/// This receiver is triggered periodically with the period that is set by
/// [`set_stack_voltage_callback_period`]. The parameter is the voltage
/// of the sensor.
///
/// The [`get_stack_voltage_callback_receiver`] receiver is only triggered if the voltage has changed
/// since the last triggering.
///
///
/// .. versionadded:: 2.0.5$nbsp;(Firmware)
pub fn get_stack_voltage_callback_receiver(&self) -> ConvertingCallbackReceiver<u16> {
self.device.get_callback_receiver(u8::from(MasterBrickFunction::CallbackStackVoltage))
}
/// This receiver is triggered periodically with the period that is set by
/// [`set_usb_voltage_callback_period`]. The parameter is the USB
/// voltage.
///
/// The [`get_usb_voltage_callback_receiver`] receiver is only triggered if the USB voltage has changed
/// since the last triggering.
///
/// Does not work with hardware version 2.1 or newer.
///
///
/// .. versionadded:: 2.0.5$nbsp;(Firmware)
pub fn get_usb_voltage_callback_receiver(&self) -> ConvertingCallbackReceiver<u16> {
self.device.get_callback_receiver(u8::from(MasterBrickFunction::CallbackUsbVoltage))
}
/// This receiver is triggered when the threshold as set by
/// [`set_stack_current_callback_threshold`] is reached.
/// The parameter is the stack current.
///
/// If the threshold keeps being reached, the receiver is triggered periodically
/// with the period as set by [`set_debounce_period`].
///
///
/// .. versionadded:: 2.0.5$nbsp;(Firmware)
pub fn get_stack_current_reached_callback_receiver(&self) -> ConvertingCallbackReceiver<u16> {
self.device.get_callback_receiver(u8::from(MasterBrickFunction::CallbackStackCurrentReached))
}
/// This receiver is triggered when the threshold as set by
/// [`set_stack_voltage_callback_threshold`] is reached.
/// The parameter is the stack voltage.
///
/// If the threshold keeps being reached, the receiver is triggered periodically
/// with the period as set by [`set_debounce_period`].
///
///
/// .. versionadded:: 2.0.5$nbsp;(Firmware)
pub fn get_stack_voltage_reached_callback_receiver(&self) -> ConvertingCallbackReceiver<u16> {
self.device.get_callback_receiver(u8::from(MasterBrickFunction::CallbackStackVoltageReached))
}
/// This receiver is triggered when the threshold as set by
/// [`set_usb_voltage_callback_threshold`] is reached.
/// The parameter is the voltage of the sensor.
///
/// If the threshold keeps being reached, the receiver is triggered periodically
/// with the period as set by [`set_debounce_period`].
///
///
/// .. versionadded:: 2.0.5$nbsp;(Firmware)
pub fn get_usb_voltage_reached_callback_receiver(&self) -> ConvertingCallbackReceiver<u16> {
self.device.get_callback_receiver(u8::from(MasterBrickFunction::CallbackUsbVoltageReached))
}
/// Returns the stack voltage. The stack voltage is the
/// voltage that is supplied via the stack, i.e. it is given by a
/// Step-Down or Step-Up Power Supply.
///
/// # Note
/// It is not possible to measure voltages supplied per PoE or USB with this function.
pub fn get_stack_voltage(&self) -> ConvertingReceiver<u16> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetStackVoltage), payload)
}
/// Returns the stack current. The stack current is the
/// current that is drawn via the stack, i.e. it is given by a
/// Step-Down or Step-Up Power Supply.
///
/// # Note
/// It is not possible to measure the current drawn via PoE or USB with this function.
pub fn get_stack_current(&self) -> ConvertingReceiver<u16> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetStackCurrent), payload)
}
/// Writes the extension type to the EEPROM of a specified extension.
/// The extension is either 0 or 1 (0 is the lower one, 1 is the upper one,
/// if only one extension is present use 0).
///
/// Possible extension types:
///
/// Type| Description
/// --- | ---
/// 1| Chibi
/// 2| RS485
/// 3| WIFI
/// 4| Ethernet
/// 5| WIFI 2.0
///
/// The extension type is already set when bought and it can be set with the
/// Brick Viewer, it is unlikely that you need this function.
///
/// Associated constants:
/// * MASTER_BRICK_EXTENSION_TYPE_CHIBI
/// * MASTER_BRICK_EXTENSION_TYPE_RS485
/// * MASTER_BRICK_EXTENSION_TYPE_WIFI
/// * MASTER_BRICK_EXTENSION_TYPE_ETHERNET
/// * MASTER_BRICK_EXTENSION_TYPE_WIFI2
pub fn set_extension_type(&self, extension: u8, exttype: u32) -> ConvertingReceiver<()> {
let mut payload = vec![0; 5];
payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(extension));
payload[1..5].copy_from_slice(&<u32>::to_le_byte_vec(exttype));
self.device.set(u8::from(MasterBrickFunction::SetExtensionType), payload)
}
/// Returns the type for a given extension as set by [`set_extension_type`].
///
/// Associated constants:
/// * MASTER_BRICK_EXTENSION_TYPE_CHIBI
/// * MASTER_BRICK_EXTENSION_TYPE_RS485
/// * MASTER_BRICK_EXTENSION_TYPE_WIFI
/// * MASTER_BRICK_EXTENSION_TYPE_ETHERNET
/// * MASTER_BRICK_EXTENSION_TYPE_WIFI2
pub fn get_extension_type(&self, extension: u8) -> ConvertingReceiver<u32> {
let mut payload = vec![0; 1];
payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(extension));
self.device.get(u8::from(MasterBrickFunction::GetExtensionType), payload)
}
/// Returns *true* if the Master Brick is at position 0 in the stack and a Chibi
/// Extension is available.
pub fn is_chibi_present(&self) -> ConvertingReceiver<bool> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::IsChibiPresent), payload)
}
/// Sets the address belonging to the Chibi Extension.
///
/// It is possible to set the address with the Brick Viewer and it will be
/// saved in the EEPROM of the Chibi Extension, it does not
/// have to be set on every startup.
pub fn set_chibi_address(&self, address: u8) -> ConvertingReceiver<()> {
let mut payload = vec![0; 1];
payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(address));
self.device.set(u8::from(MasterBrickFunction::SetChibiAddress), payload)
}
/// Returns the address as set by [`set_chibi_address`].
pub fn get_chibi_address(&self) -> ConvertingReceiver<u8> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetChibiAddress), payload)
}
/// Sets the address of the Chibi Master. This address is used if the
/// Chibi Extension is used as slave (i.e. it does not have a USB connection).
///
/// It is possible to set the address with the Brick Viewer and it will be
/// saved in the EEPROM of the Chibi Extension, it does not
/// have to be set on every startup.
pub fn set_chibi_master_address(&self, address: u8) -> ConvertingReceiver<()> {
let mut payload = vec![0; 1];
payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(address));
self.device.set(u8::from(MasterBrickFunction::SetChibiMasterAddress), payload)
}
/// Returns the address as set by [`set_chibi_master_address`].
pub fn get_chibi_master_address(&self) -> ConvertingReceiver<u8> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetChibiMasterAddress), payload)
}
/// Sets up to 254 slave addresses. 0 has a
/// special meaning, it is used as list terminator and not allowed as normal slave
/// address. The address numeration (via \c num parameter) has to be used
/// ascending from 0. For example: If you use the Chibi Extension in Master mode
/// (i.e. the stack has an USB connection) and you want to talk to three other
/// Chibi stacks with the slave addresses 17, 23, and 42, you should call with
/// ``(0, 17)``, ``(1, 23)``, ``(2, 42)`` and ``(3, 0)``. The last call with
/// ``(3, 0)`` is a list terminator and indicates that the Chibi slave address
/// list contains 3 addresses in this case.
///
/// It is possible to set the addresses with the Brick Viewer, that will take care
/// of correct address numeration and list termination.
///
/// The slave addresses will be saved in the EEPROM of the Chibi Extension, they
/// don't have to be set on every startup.
pub fn set_chibi_slave_address(&self, num: u8, address: u8) -> ConvertingReceiver<()> {
let mut payload = vec![0; 2];
payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(num));
payload[1..2].copy_from_slice(&<u8>::to_le_byte_vec(address));
self.device.set(u8::from(MasterBrickFunction::SetChibiSlaveAddress), payload)
}
/// Returns the slave address for a given \c num as set by
/// [`set_chibi_slave_address`].
pub fn get_chibi_slave_address(&self, num: u8) -> ConvertingReceiver<u8> {
let mut payload = vec![0; 1];
payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(num));
self.device.get(u8::from(MasterBrickFunction::GetChibiSlaveAddress), payload)
}
/// Returns the signal strength in dBm. The signal strength updates every time a
/// packet is received.
pub fn get_chibi_signal_strength(&self) -> ConvertingReceiver<u8> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetChibiSignalStrength), payload)
}
/// Returns underrun, CRC error, no ACK and overflow error counts of the Chibi
/// communication. If these errors start rising, it is likely that either the
/// distance between two Chibi stacks is becoming too big or there are
/// interferences.
pub fn get_chibi_error_log(&self) -> ConvertingReceiver<ChibiErrorLog> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetChibiErrorLog), payload)
}
/// Sets the Chibi frequency range for the Chibi Extension. Possible values are:
///
/// Type| Description
/// --- | ---
/// 0| OQPSK 868MHz (Europe)
/// 1| OQPSK 915MHz (US)
/// 2| OQPSK 780MHz (China)
/// 3| BPSK40 915MHz
///
/// It is possible to set the frequency with the Brick Viewer and it will be
/// saved in the EEPROM of the Chibi Extension, it does not
/// have to be set on every startup.
///
/// Associated constants:
/// * MASTER_BRICK_CHIBI_FREQUENCY_OQPSK_868_MHZ
/// * MASTER_BRICK_CHIBI_FREQUENCY_OQPSK_915_MHZ
/// * MASTER_BRICK_CHIBI_FREQUENCY_OQPSK_780_MHZ
/// * MASTER_BRICK_CHIBI_FREQUENCY_BPSK40_915_MHZ
pub fn set_chibi_frequency(&self, frequency: u8) -> ConvertingReceiver<()> {
let mut payload = vec![0; 1];
payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(frequency));
self.device.set(u8::from(MasterBrickFunction::SetChibiFrequency), payload)
}
/// Returns the frequency value as set by [`set_chibi_frequency`].
///
/// Associated constants:
/// * MASTER_BRICK_CHIBI_FREQUENCY_OQPSK_868_MHZ
/// * MASTER_BRICK_CHIBI_FREQUENCY_OQPSK_915_MHZ
/// * MASTER_BRICK_CHIBI_FREQUENCY_OQPSK_780_MHZ
/// * MASTER_BRICK_CHIBI_FREQUENCY_BPSK40_915_MHZ
pub fn get_chibi_frequency(&self) -> ConvertingReceiver<u8> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetChibiFrequency), payload)
}
/// Sets the channel used by the Chibi Extension. Possible channels are
/// different for different frequencies:
///
/// Frequency| Possible Channels
/// --- | ---
/// OQPSK 868MHz (Europe)| 0
/// OQPSK 915MHz (US)| 1| 2| 3| 4| 5| 6| 7| 8| 9| 10
/// OQPSK 780MHz (China)| 0| 1| 2| 3
/// BPSK40 915MHz| 1| 2| 3| 4| 5| 6| 7| 8| 9| 10
///
/// It is possible to set the channel with the Brick Viewer and it will be
/// saved in the EEPROM of the Chibi Extension, it does not
/// have to be set on every startup.
pub fn set_chibi_channel(&self, channel: u8) -> ConvertingReceiver<()> {
let mut payload = vec![0; 1];
payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(channel));
self.device.set(u8::from(MasterBrickFunction::SetChibiChannel), payload)
}
/// Returns the channel as set by [`set_chibi_channel`].
pub fn get_chibi_channel(&self) -> ConvertingReceiver<u8> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetChibiChannel), payload)
}
/// Returns *true* if the Master Brick is at position 0 in the stack and a RS485
/// Extension is available.
pub fn is_rs485_present(&self) -> ConvertingReceiver<bool> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::IsRs485Present), payload)
}
/// Sets the address (0-255) belonging to the RS485 Extension.
///
/// Set to 0 if the RS485 Extension should be the RS485 Master (i.e.
/// connected to a PC via USB).
///
/// It is possible to set the address with the Brick Viewer and it will be
/// saved in the EEPROM of the RS485 Extension, it does not
/// have to be set on every startup.
pub fn set_rs485_address(&self, address: u8) -> ConvertingReceiver<()> {
let mut payload = vec![0; 1];
payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(address));
self.device.set(u8::from(MasterBrickFunction::SetRs485Address), payload)
}
/// Returns the address as set by [`set_rs485_address`].
pub fn get_rs485_address(&self) -> ConvertingReceiver<u8> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetRs485Address), payload)
}
/// Sets up to 255 slave addresses. Valid addresses are in range 1-255. 0 has a
/// special meaning, it is used as list terminator and not allowed as normal slave
/// address. The address numeration (via ``num`` parameter) has to be used
/// ascending from 0. For example: If you use the RS485 Extension in Master mode
/// (i.e. the stack has an USB connection) and you want to talk to three other
/// RS485 stacks with the addresses 17, 23, and 42, you should call with
/// ``(0, 17)``, ``(1, 23)``, ``(2, 42)`` and ``(3, 0)``. The last call with
/// ``(3, 0)`` is a list terminator and indicates that the RS485 slave address list
/// contains 3 addresses in this case.
///
/// It is possible to set the addresses with the Brick Viewer, that will take care
/// of correct address numeration and list termination.
///
/// The slave addresses will be saved in the EEPROM of the Chibi Extension, they
/// don't have to be set on every startup.
pub fn set_rs485_slave_address(&self, num: u8, address: u8) -> ConvertingReceiver<()> {
let mut payload = vec![0; 2];
payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(num));
payload[1..2].copy_from_slice(&<u8>::to_le_byte_vec(address));
self.device.set(u8::from(MasterBrickFunction::SetRs485SlaveAddress), payload)
}
/// Returns the slave address for a given ``num`` as set by
/// [`set_rs485_slave_address`].
pub fn get_rs485_slave_address(&self, num: u8) -> ConvertingReceiver<u8> {
let mut payload = vec![0; 1];
payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(num));
self.device.get(u8::from(MasterBrickFunction::GetRs485SlaveAddress), payload)
}
/// Returns CRC error counts of the RS485 communication.
/// If this counter starts rising, it is likely that the distance
/// between the RS485 nodes is too big or there is some kind of
/// interference.
pub fn get_rs485_error_log(&self) -> ConvertingReceiver<u16> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetRs485ErrorLog), payload)
}
/// Sets the configuration of the RS485 Extension. The
/// Master Brick will try to match the given baud rate as exactly as possible.
/// The maximum recommended baud rate is 2000000 (2MBd).
/// Possible values for parity are 'n' (none), 'e' (even) and 'o' (odd).
///
/// If your RS485 is unstable (lost messages etc.), the first thing you should
/// try is to decrease the speed. On very large bus (e.g. 1km), you probably
/// should use a value in the range of 100000 (100kBd).
///
/// The values are stored in the EEPROM and only applied on startup. That means
/// you have to restart the Master Brick after configuration.
///
/// Associated constants:
/// * MASTER_BRICK_RS485_PARITY_NONE
/// * MASTER_BRICK_RS485_PARITY_EVEN
/// * MASTER_BRICK_RS485_PARITY_ODD
pub fn set_rs485_configuration(&self, speed: u32, parity: char, stopbits: u8) -> ConvertingReceiver<()> {
let mut payload = vec![0; 6];
payload[0..4].copy_from_slice(&<u32>::to_le_byte_vec(speed));
payload[4..5].copy_from_slice(&<char>::to_le_byte_vec(parity));
payload[5..6].copy_from_slice(&<u8>::to_le_byte_vec(stopbits));
self.device.set(u8::from(MasterBrickFunction::SetRs485Configuration), payload)
}
/// Returns the configuration as set by [`set_rs485_configuration`].
///
/// Associated constants:
/// * MASTER_BRICK_RS485_PARITY_NONE
/// * MASTER_BRICK_RS485_PARITY_EVEN
/// * MASTER_BRICK_RS485_PARITY_ODD
pub fn get_rs485_configuration(&self) -> ConvertingReceiver<Rs485Configuration> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetRs485Configuration), payload)
}
/// Returns *true* if the Master Brick is at position 0 in the stack and a WIFI
/// Extension is available.
pub fn is_wifi_present(&self) -> ConvertingReceiver<bool> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::IsWifiPresent), payload)
}
/// Sets the configuration of the WIFI Extension. The ``ssid`` can have a max length
/// of 32 characters. Possible values for ``connection`` are:
///
/// Value| Description
/// --- | ---
/// 0| DHCP
/// 1| Static IP
/// 2| Access Point: DHCP
/// 3| Access Point: Static IP
/// 4| Ad Hoc: DHCP
/// 5| Ad Hoc: Static IP
///
/// If you set ``connection`` to one of the static IP options then you have to
/// supply ``ip``, ``subnet_mask`` and ``gateway`` as an array of size 4 (first
/// element of the array is the least significant byte of the address). If
/// ``connection`` is set to one of the DHCP options then ``ip``, ``subnet_mask``
/// and ``gateway`` are ignored, you can set them to 0.
///
/// The last parameter is the port that your program will connect to.
///
/// The values are stored in the EEPROM and only applied on startup. That means
/// you have to restart the Master Brick after configuration.
///
/// It is recommended to use the Brick Viewer to set the WIFI configuration.
///
/// Associated constants:
/// * MASTER_BRICK_WIFI_CONNECTION_DHCP
/// * MASTER_BRICK_WIFI_CONNECTION_STATIC_IP
/// * MASTER_BRICK_WIFI_CONNECTION_ACCESS_POINT_DHCP
/// * MASTER_BRICK_WIFI_CONNECTION_ACCESS_POINT_STATIC_IP
/// * MASTER_BRICK_WIFI_CONNECTION_AD_HOC_DHCP
/// * MASTER_BRICK_WIFI_CONNECTION_AD_HOC_STATIC_IP
pub fn set_wifi_configuration(
&self,
ssid: String,
connection: u8,
ip: [u8; 4],
subnet_mask: [u8; 4],
gateway: [u8; 4],
port: u16,
) -> ConvertingReceiver<()> {
let mut payload = vec![0; 47];
match <String>::try_to_le_byte_vec(ssid, 32) {
Err(e) => {
let (tx, rx) = std::sync::mpsc::channel::<Result<Vec<u8>, BrickletError>>();
let _ = tx.send(Err(e));
return ConvertingReceiver::new(rx, std::time::Duration::new(1, 0));
}
Ok(bytes) => payload[0..32].copy_from_slice(&bytes),
}
payload[32..33].copy_from_slice(&<u8>::to_le_byte_vec(connection));
payload[33..37].copy_from_slice(&<[u8; 4]>::to_le_byte_vec(ip));
payload[37..41].copy_from_slice(&<[u8; 4]>::to_le_byte_vec(subnet_mask));
payload[41..45].copy_from_slice(&<[u8; 4]>::to_le_byte_vec(gateway));
payload[45..47].copy_from_slice(&<u16>::to_le_byte_vec(port));
self.device.set(u8::from(MasterBrickFunction::SetWifiConfiguration), payload)
}
/// Returns the configuration as set by [`set_wifi_configuration`].
///
/// Associated constants:
/// * MASTER_BRICK_WIFI_CONNECTION_DHCP
/// * MASTER_BRICK_WIFI_CONNECTION_STATIC_IP
/// * MASTER_BRICK_WIFI_CONNECTION_ACCESS_POINT_DHCP
/// * MASTER_BRICK_WIFI_CONNECTION_ACCESS_POINT_STATIC_IP
/// * MASTER_BRICK_WIFI_CONNECTION_AD_HOC_DHCP
/// * MASTER_BRICK_WIFI_CONNECTION_AD_HOC_STATIC_IP
pub fn get_wifi_configuration(&self) -> ConvertingReceiver<WifiConfiguration> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetWifiConfiguration), payload)
}
/// Sets the encryption of the WIFI Extension. The first parameter is the
/// type of the encryption. Possible values are:
///
/// Value| Description
/// --- | ---
/// 0| WPA/WPA2
/// 1| WPA Enterprise (EAP-FAST| EAP-TLS| EAP-TTLS| PEAP)
/// 2| WEP
/// 3| No Encryption
///
/// The ``key`` has a max length of 50 characters and is used if ``encryption``
/// is set to 0 or 2 (WPA/WPA2 or WEP). Otherwise the value is ignored.
///
/// For WPA/WPA2 the key has to be at least 8 characters long. If you want to set
/// a key with more than 50 characters, see [`set_long_wifi_key`].
///
/// For WEP the key has to be either 10 or 26 hexadecimal digits long. It is
/// possible to set the WEP ``key_index`` (1-4). If you don't know your
/// ``key_index``, it is likely 1.
///
/// If you choose WPA Enterprise as encryption, you have to set ``eap_options`` and
/// the length of the certificates (for other encryption types these parameters
/// are ignored). The certificates
/// themselves can be set with [`set_wifi_certificate`]. ``eap_options`` consist
/// of the outer authentication (bits 1-2), inner authentication (bit 3) and
/// certificate type (bits 4-5):
///
/// Option| Bits| Description
/// --- | --- | ---
/// outer authentication| 1-2| 0=EAP-FAST| 1=EAP-TLS| 2=EAP-TTLS| 3=EAP-PEAP
/// inner authentication| 3| 0=EAP-MSCHAP| 1=EAP-GTC
/// certificate type| 4-5| 0=CA Certificate| 1=Client Certificate| 2=Private Key
///
/// Example for EAP-TTLS + EAP-GTC + Private Key: ``option = 2 | (1 << 2) | (2 << 3)``.
///
/// The values are stored in the EEPROM and only applied on startup. That means
/// you have to restart the Master Brick after configuration.
///
/// It is recommended to use the Brick Viewer to set the Wi-Fi encryption.
///
/// Associated constants:
/// * MASTER_BRICK_WIFI_ENCRYPTION_WPA_WPA2
/// * MASTER_BRICK_WIFI_ENCRYPTION_WPA_ENTERPRISE
/// * MASTER_BRICK_WIFI_ENCRYPTION_WEP
/// * MASTER_BRICK_WIFI_ENCRYPTION_NO_ENCRYPTION
/// * MASTER_BRICK_WIFI_EAP_OPTION_OUTER_AUTH_EAP_FAST
/// * MASTER_BRICK_WIFI_EAP_OPTION_OUTER_AUTH_EAP_TLS
/// * MASTER_BRICK_WIFI_EAP_OPTION_OUTER_AUTH_EAP_TTLS
/// * MASTER_BRICK_WIFI_EAP_OPTION_OUTER_AUTH_EAP_PEAP
/// * MASTER_BRICK_WIFI_EAP_OPTION_INNER_AUTH_EAP_MSCHAP
/// * MASTER_BRICK_WIFI_EAP_OPTION_INNER_AUTH_EAP_GTC
/// * MASTER_BRICK_WIFI_EAP_OPTION_CERT_TYPE_CA_CERT
/// * MASTER_BRICK_WIFI_EAP_OPTION_CERT_TYPE_CLIENT_CERT
/// * MASTER_BRICK_WIFI_EAP_OPTION_CERT_TYPE_PRIVATE_KEY
pub fn set_wifi_encryption(
&self,
encryption: u8,
key: String,
key_index: u8,
eap_options: u8,
ca_certificate_length: u16,
client_certificate_length: u16,
private_key_length: u16,
) -> ConvertingReceiver<()> {
let mut payload = vec![0; 59];
payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(encryption));
match <String>::try_to_le_byte_vec(key, 50) {
Err(e) => {
let (tx, rx) = std::sync::mpsc::channel::<Result<Vec<u8>, BrickletError>>();
let _ = tx.send(Err(e));
return ConvertingReceiver::new(rx, std::time::Duration::new(1, 0));
}
Ok(bytes) => payload[1..51].copy_from_slice(&bytes),
}
payload[51..52].copy_from_slice(&<u8>::to_le_byte_vec(key_index));
payload[52..53].copy_from_slice(&<u8>::to_le_byte_vec(eap_options));
payload[53..55].copy_from_slice(&<u16>::to_le_byte_vec(ca_certificate_length));
payload[55..57].copy_from_slice(&<u16>::to_le_byte_vec(client_certificate_length));
payload[57..59].copy_from_slice(&<u16>::to_le_byte_vec(private_key_length));
self.device.set(u8::from(MasterBrickFunction::SetWifiEncryption), payload)
}
/// Returns the encryption as set by [`set_wifi_encryption`].
///
/// # Note
/// Since Master Brick Firmware version 2.4.4 the key is not returned anymore.
///
/// Associated constants:
/// * MASTER_BRICK_WIFI_ENCRYPTION_WPA_WPA2
/// * MASTER_BRICK_WIFI_ENCRYPTION_WPA_ENTERPRISE
/// * MASTER_BRICK_WIFI_ENCRYPTION_WEP
/// * MASTER_BRICK_WIFI_ENCRYPTION_NO_ENCRYPTION
/// * MASTER_BRICK_WIFI_EAP_OPTION_OUTER_AUTH_EAP_FAST
/// * MASTER_BRICK_WIFI_EAP_OPTION_OUTER_AUTH_EAP_TLS
/// * MASTER_BRICK_WIFI_EAP_OPTION_OUTER_AUTH_EAP_TTLS
/// * MASTER_BRICK_WIFI_EAP_OPTION_OUTER_AUTH_EAP_PEAP
/// * MASTER_BRICK_WIFI_EAP_OPTION_INNER_AUTH_EAP_MSCHAP
/// * MASTER_BRICK_WIFI_EAP_OPTION_INNER_AUTH_EAP_GTC
/// * MASTER_BRICK_WIFI_EAP_OPTION_CERT_TYPE_CA_CERT
/// * MASTER_BRICK_WIFI_EAP_OPTION_CERT_TYPE_CLIENT_CERT
/// * MASTER_BRICK_WIFI_EAP_OPTION_CERT_TYPE_PRIVATE_KEY
pub fn get_wifi_encryption(&self) -> ConvertingReceiver<WifiEncryption> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetWifiEncryption), payload)
}
/// Returns the status of the WIFI Extension. The ``state`` is updated automatically,
/// all of the other parameters are updated on startup and every time
/// [`refresh_wifi_status`] is called.
///
/// Possible states are:
///
/// State| Description
/// --- | ---
/// 0| Disassociated
/// 1| Associated
/// 2| Associating
/// 3| Error
/// 255| Not initialized yet
///
/// Associated constants:
/// * MASTER_BRICK_WIFI_STATE_DISASSOCIATED
/// * MASTER_BRICK_WIFI_STATE_ASSOCIATED
/// * MASTER_BRICK_WIFI_STATE_ASSOCIATING
/// * MASTER_BRICK_WIFI_STATE_ERROR
/// * MASTER_BRICK_WIFI_STATE_NOT_INITIALIZED_YET
pub fn get_wifi_status(&self) -> ConvertingReceiver<WifiStatus> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetWifiStatus), payload)
}
/// Refreshes the Wi-Fi status (see [`get_wifi_status`]). To read the status
/// of the Wi-Fi module, the Master Brick has to change from data mode to
/// command mode and back. This transaction and the readout itself is
/// unfortunately time consuming. This means, that it might take some ms
/// until the stack with attached WIFI Extension reacts again after this
/// function is called.
pub fn refresh_wifi_status(&self) -> ConvertingReceiver<()> {
let payload = vec![0; 0];
self.device.set(u8::from(MasterBrickFunction::RefreshWifiStatus), payload)
}
/// This function is used to set the certificate as well as password and username
/// for WPA Enterprise. To set the username use index 0xFFFF,
/// to set the password use index 0xFFFE. The max length of username and
/// password is 32.
///
/// The certificate is written in chunks of size 32 and the index is used as
/// the index of the chunk. ``data_length`` should nearly always be 32. Only
/// the last chunk can have a length that is not equal to 32.
///
/// The starting index of the CA Certificate is 0, of the Client Certificate
/// 10000 and for the Private Key 20000. Maximum sizes are 1312, 1312 and
/// 4320 byte respectively.
///
/// The values are stored in the EEPROM and only applied on startup. That means
/// you have to restart the Master Brick after uploading the certificate.
///
/// It is recommended to use the Brick Viewer to set the certificate, username
/// and password.
pub fn set_wifi_certificate(&self, index: u16, data: [u8; 32], data_length: u8) -> ConvertingReceiver<()> {
let mut payload = vec![0; 35];
payload[0..2].copy_from_slice(&<u16>::to_le_byte_vec(index));
payload[2..34].copy_from_slice(&<[u8; 32]>::to_le_byte_vec(data));
payload[34..35].copy_from_slice(&<u8>::to_le_byte_vec(data_length));
self.device.set(u8::from(MasterBrickFunction::SetWifiCertificate), payload)
}
/// Returns the certificate for a given index as set by [`set_wifi_certificate`].
pub fn get_wifi_certificate(&self, index: u16) -> ConvertingReceiver<WifiCertificate> {
let mut payload = vec![0; 2];
payload[0..2].copy_from_slice(&<u16>::to_le_byte_vec(index));
self.device.get(u8::from(MasterBrickFunction::GetWifiCertificate), payload)
}
/// Sets the power mode of the WIFI Extension. Possible modes are:
///
/// Mode| Description
/// --- | ---
/// 0| Full Speed (high power consumption| high throughput)
/// 1| Low Power (low power consumption| low throughput)
///
/// Associated constants:
/// * MASTER_BRICK_WIFI_POWER_MODE_FULL_SPEED
/// * MASTER_BRICK_WIFI_POWER_MODE_LOW_POWER
pub fn set_wifi_power_mode(&self, mode: u8) -> ConvertingReceiver<()> {
let mut payload = vec![0; 1];
payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(mode));
self.device.set(u8::from(MasterBrickFunction::SetWifiPowerMode), payload)
}
/// Returns the power mode as set by [`set_wifi_power_mode`].
///
/// Associated constants:
/// * MASTER_BRICK_WIFI_POWER_MODE_FULL_SPEED
/// * MASTER_BRICK_WIFI_POWER_MODE_LOW_POWER
pub fn get_wifi_power_mode(&self) -> ConvertingReceiver<u8> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetWifiPowerMode), payload)
}
/// Returns informations about the Wi-Fi receive buffer. The Wi-Fi
/// receive buffer has a max size of 1500 byte and if data is transfered
/// too fast, it might overflow.
///
/// The return values are the number of overflows, the low watermark
/// (i.e. the smallest number of bytes that were free in the buffer) and
/// the bytes that are currently used.
///
/// You should always try to keep the buffer empty, otherwise you will
/// have a permanent latency. A good rule of thumb is, that you can transfer
/// 1000 messages per second without problems.
///
/// Try to not send more then 50 messages at a time without any kind of
/// break between them.
pub fn get_wifi_buffer_info(&self) -> ConvertingReceiver<WifiBufferInfo> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetWifiBufferInfo), payload)
}
/// Sets the regulatory domain of the WIFI Extension. Possible domains are:
///
/// Domain| Description
/// --- | ---
/// 0| FCC: Channel 1-11 (N/S America| Australia| New Zealand)
/// 1| ETSI: Channel 1-13 (Europe| Middle East| Africa)
/// 2| TELEC: Channel 1-14 (Japan)
///
/// Associated constants:
/// * MASTER_BRICK_WIFI_DOMAIN_CHANNEL_1TO11
/// * MASTER_BRICK_WIFI_DOMAIN_CHANNEL_1TO13
/// * MASTER_BRICK_WIFI_DOMAIN_CHANNEL_1TO14
pub fn set_wifi_regulatory_domain(&self, domain: u8) -> ConvertingReceiver<()> {
let mut payload = vec![0; 1];
payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(domain));
self.device.set(u8::from(MasterBrickFunction::SetWifiRegulatoryDomain), payload)
}
/// Returns the regulatory domain as set by [`set_wifi_regulatory_domain`].
///
/// Associated constants:
/// * MASTER_BRICK_WIFI_DOMAIN_CHANNEL_1TO11
/// * MASTER_BRICK_WIFI_DOMAIN_CHANNEL_1TO13
/// * MASTER_BRICK_WIFI_DOMAIN_CHANNEL_1TO14
pub fn get_wifi_regulatory_domain(&self) -> ConvertingReceiver<u8> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetWifiRegulatoryDomain), payload)
}
/// Returns the USB voltage. Does not work with hardware version 2.1 or newer.
pub fn get_usb_voltage(&self) -> ConvertingReceiver<u16> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetUsbVoltage), payload)
}
/// Sets a long Wi-Fi key (up to 63 chars, at least 8 chars) for WPA encryption.
/// This key will be used
/// if the key in [`set_wifi_encryption`] is set to -. In the old protocol,
/// a payload of size 63 was not possible, so the maximum key length was 50 chars.
///
/// With the new protocol this is possible, since we didn't want to break API,
/// this function was added additionally.
///
///
/// .. versionadded:: 2.0.2$nbsp;(Firmware)
pub fn set_long_wifi_key(&self, key: String) -> ConvertingReceiver<()> {
let mut payload = vec![0; 64];
match <String>::try_to_le_byte_vec(key, 64) {
Err(e) => {
let (tx, rx) = std::sync::mpsc::channel::<Result<Vec<u8>, BrickletError>>();
let _ = tx.send(Err(e));
return ConvertingReceiver::new(rx, std::time::Duration::new(1, 0));
}
Ok(bytes) => payload[0..64].copy_from_slice(&bytes),
}
self.device.set(u8::from(MasterBrickFunction::SetLongWifiKey), payload)
}
/// Returns the encryption key as set by [`set_long_wifi_key`].
///
/// # Note
/// Since Master Brick firmware version 2.4.4 the key is not returned anymore.
///
///
/// .. versionadded:: 2.0.2$nbsp;(Firmware)
pub fn get_long_wifi_key(&self) -> ConvertingReceiver<String> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetLongWifiKey), payload)
}
/// Sets the hostname of the WIFI Extension. The hostname will be displayed
/// by access points as the hostname in the DHCP clients table.
///
/// Setting an empty String will restore the default hostname.
///
///
/// .. versionadded:: 2.0.5$nbsp;(Firmware)
pub fn set_wifi_hostname(&self, hostname: String) -> ConvertingReceiver<()> {
let mut payload = vec![0; 16];
match <String>::try_to_le_byte_vec(hostname, 16) {
Err(e) => {
let (tx, rx) = std::sync::mpsc::channel::<Result<Vec<u8>, BrickletError>>();
let _ = tx.send(Err(e));
return ConvertingReceiver::new(rx, std::time::Duration::new(1, 0));
}
Ok(bytes) => payload[0..16].copy_from_slice(&bytes),
}
self.device.set(u8::from(MasterBrickFunction::SetWifiHostname), payload)
}
/// Returns the hostname as set by [`set_wifi_hostname`].
///
/// An empty String means, that the default hostname is used.
///
///
/// .. versionadded:: 2.0.5$nbsp;(Firmware)
pub fn get_wifi_hostname(&self) -> ConvertingReceiver<String> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetWifiHostname), payload)
}
/// Sets the period with which the [`get_stack_current_callback_receiver`] receiver is triggered
/// periodically. A value of 0 turns the receiver off.
///
/// The [`get_stack_current_callback_receiver`] receiver is only triggered if the current has changed
/// since the last triggering.
///
///
/// .. versionadded:: 2.0.5$nbsp;(Firmware)
pub fn set_stack_current_callback_period(&self, period: u32) -> ConvertingReceiver<()> {
let mut payload = vec![0; 4];
payload[0..4].copy_from_slice(&<u32>::to_le_byte_vec(period));
self.device.set(u8::from(MasterBrickFunction::SetStackCurrentCallbackPeriod), payload)
}
/// Returns the period as set by [`set_stack_current_callback_period`].
///
///
/// .. versionadded:: 2.0.5$nbsp;(Firmware)
pub fn get_stack_current_callback_period(&self) -> ConvertingReceiver<u32> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetStackCurrentCallbackPeriod), payload)
}
/// Sets the period with which the [`get_stack_voltage_callback_receiver`] receiver is triggered
/// periodically. A value of 0 turns the receiver off.
///
/// The [`get_stack_voltage_callback_receiver`] receiver is only triggered if the voltage has changed
/// since the last triggering.
///
///
/// .. versionadded:: 2.0.5$nbsp;(Firmware)
pub fn set_stack_voltage_callback_period(&self, period: u32) -> ConvertingReceiver<()> {
let mut payload = vec![0; 4];
payload[0..4].copy_from_slice(&<u32>::to_le_byte_vec(period));
self.device.set(u8::from(MasterBrickFunction::SetStackVoltageCallbackPeriod), payload)
}
/// Returns the period as set by [`set_stack_voltage_callback_period`].
///
///
/// .. versionadded:: 2.0.5$nbsp;(Firmware)
pub fn get_stack_voltage_callback_period(&self) -> ConvertingReceiver<u32> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetStackVoltageCallbackPeriod), payload)
}
/// Sets the period with which the [`get_usb_voltage_callback_receiver`] receiver is triggered
/// periodically. A value of 0 turns the receiver off.
///
/// The [`get_usb_voltage_callback_receiver`] receiver is only triggered if the voltage has changed
/// since the last triggering.
///
///
/// .. versionadded:: 2.0.5$nbsp;(Firmware)
pub fn set_usb_voltage_callback_period(&self, period: u32) -> ConvertingReceiver<()> {
let mut payload = vec![0; 4];
payload[0..4].copy_from_slice(&<u32>::to_le_byte_vec(period));
self.device.set(u8::from(MasterBrickFunction::SetUsbVoltageCallbackPeriod), payload)
}
/// Returns the period as set by [`set_usb_voltage_callback_period`].
///
///
/// .. versionadded:: 2.0.5$nbsp;(Firmware)
pub fn get_usb_voltage_callback_period(&self) -> ConvertingReceiver<u32> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetUsbVoltageCallbackPeriod), payload)
}
/// Sets the thresholds for the [`get_stack_current_reached_callback_receiver`] receiver.
///
/// The following options are possible:
///
/// Option| Description
/// --- | ---
/// 'x'| Receiver is turned off
/// 'o'| Receiver is triggered when the current is *outside* the min and max values
/// 'i'| Receiver is triggered when the current is *inside* the min and max values
/// '<'| Receiver is triggered when the current is smaller than the min value (max is ignored)
/// '>'| Receiver is triggered when the current is greater than the min value (max is ignored)
///
///
/// .. versionadded:: 2.0.5$nbsp;(Firmware)
///
/// Associated constants:
/// * MASTER_BRICK_THRESHOLD_OPTION_OFF
/// * MASTER_BRICK_THRESHOLD_OPTION_OUTSIDE
/// * MASTER_BRICK_THRESHOLD_OPTION_INSIDE
/// * MASTER_BRICK_THRESHOLD_OPTION_SMALLER
/// * MASTER_BRICK_THRESHOLD_OPTION_GREATER
pub fn set_stack_current_callback_threshold(&self, option: char, min: u16, max: u16) -> ConvertingReceiver<()> {
let mut payload = vec![0; 5];
payload[0..1].copy_from_slice(&<char>::to_le_byte_vec(option));
payload[1..3].copy_from_slice(&<u16>::to_le_byte_vec(min));
payload[3..5].copy_from_slice(&<u16>::to_le_byte_vec(max));
self.device.set(u8::from(MasterBrickFunction::SetStackCurrentCallbackThreshold), payload)
}
/// Returns the threshold as set by [`set_stack_current_callback_threshold`].
///
///
/// .. versionadded:: 2.0.5$nbsp;(Firmware)
///
/// Associated constants:
/// * MASTER_BRICK_THRESHOLD_OPTION_OFF
/// * MASTER_BRICK_THRESHOLD_OPTION_OUTSIDE
/// * MASTER_BRICK_THRESHOLD_OPTION_INSIDE
/// * MASTER_BRICK_THRESHOLD_OPTION_SMALLER
/// * MASTER_BRICK_THRESHOLD_OPTION_GREATER
pub fn get_stack_current_callback_threshold(&self) -> ConvertingReceiver<StackCurrentCallbackThreshold> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetStackCurrentCallbackThreshold), payload)
}
/// Sets the thresholds for the [`get_stack_voltage_reached_callback_receiver`] receiver.
///
/// The following options are possible:
///
/// Option| Description
/// --- | ---
/// 'x'| Receiver is turned off
/// 'o'| Receiver is triggered when the voltage is *outside* the min and max values
/// 'i'| Receiver is triggered when the voltage is *inside* the min and max values
/// '<'| Receiver is triggered when the voltage is smaller than the min value (max is ignored)
/// '>'| Receiver is triggered when the voltage is greater than the min value (max is ignored)
///
///
/// .. versionadded:: 2.0.5$nbsp;(Firmware)
///
/// Associated constants:
/// * MASTER_BRICK_THRESHOLD_OPTION_OFF
/// * MASTER_BRICK_THRESHOLD_OPTION_OUTSIDE
/// * MASTER_BRICK_THRESHOLD_OPTION_INSIDE
/// * MASTER_BRICK_THRESHOLD_OPTION_SMALLER
/// * MASTER_BRICK_THRESHOLD_OPTION_GREATER
pub fn set_stack_voltage_callback_threshold(&self, option: char, min: u16, max: u16) -> ConvertingReceiver<()> {
let mut payload = vec![0; 5];
payload[0..1].copy_from_slice(&<char>::to_le_byte_vec(option));
payload[1..3].copy_from_slice(&<u16>::to_le_byte_vec(min));
payload[3..5].copy_from_slice(&<u16>::to_le_byte_vec(max));
self.device.set(u8::from(MasterBrickFunction::SetStackVoltageCallbackThreshold), payload)
}
/// Returns the threshold as set by [`set_stack_voltage_callback_threshold`].
///
///
/// .. versionadded:: 2.0.5$nbsp;(Firmware)
///
/// Associated constants:
/// * MASTER_BRICK_THRESHOLD_OPTION_OFF
/// * MASTER_BRICK_THRESHOLD_OPTION_OUTSIDE
/// * MASTER_BRICK_THRESHOLD_OPTION_INSIDE
/// * MASTER_BRICK_THRESHOLD_OPTION_SMALLER
/// * MASTER_BRICK_THRESHOLD_OPTION_GREATER
pub fn get_stack_voltage_callback_threshold(&self) -> ConvertingReceiver<StackVoltageCallbackThreshold> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetStackVoltageCallbackThreshold), payload)
}
/// Sets the thresholds for the [`get_usb_voltage_reached_callback_receiver`] receiver.
///
/// The following options are possible:
///
/// Option| Description
/// --- | ---
/// 'x'| Receiver is turned off
/// 'o'| Receiver is triggered when the voltage is *outside* the min and max values
/// 'i'| Receiver is triggered when the voltage is *inside* the min and max values
/// '<'| Receiver is triggered when the voltage is smaller than the min value (max is ignored)
/// '>'| Receiver is triggered when the voltage is greater than the min value (max is ignored)
///
///
/// .. versionadded:: 2.0.5$nbsp;(Firmware)
///
/// Associated constants:
/// * MASTER_BRICK_THRESHOLD_OPTION_OFF
/// * MASTER_BRICK_THRESHOLD_OPTION_OUTSIDE
/// * MASTER_BRICK_THRESHOLD_OPTION_INSIDE
/// * MASTER_BRICK_THRESHOLD_OPTION_SMALLER
/// * MASTER_BRICK_THRESHOLD_OPTION_GREATER
pub fn set_usb_voltage_callback_threshold(&self, option: char, min: u16, max: u16) -> ConvertingReceiver<()> {
let mut payload = vec![0; 5];
payload[0..1].copy_from_slice(&<char>::to_le_byte_vec(option));
payload[1..3].copy_from_slice(&<u16>::to_le_byte_vec(min));
payload[3..5].copy_from_slice(&<u16>::to_le_byte_vec(max));
self.device.set(u8::from(MasterBrickFunction::SetUsbVoltageCallbackThreshold), payload)
}
/// Returns the threshold as set by [`set_usb_voltage_callback_threshold`].
///
///
/// .. versionadded:: 2.0.5$nbsp;(Firmware)
///
/// Associated constants:
/// * MASTER_BRICK_THRESHOLD_OPTION_OFF
/// * MASTER_BRICK_THRESHOLD_OPTION_OUTSIDE
/// * MASTER_BRICK_THRESHOLD_OPTION_INSIDE
/// * MASTER_BRICK_THRESHOLD_OPTION_SMALLER
/// * MASTER_BRICK_THRESHOLD_OPTION_GREATER
pub fn get_usb_voltage_callback_threshold(&self) -> ConvertingReceiver<UsbVoltageCallbackThreshold> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetUsbVoltageCallbackThreshold), payload)
}
/// Sets the period with which the threshold receivers
///
/// * [`get_stack_current_reached_callback_receiver`],
/// * [`get_stack_voltage_reached_callback_receiver`],
/// * [`get_usb_voltage_reached_callback_receiver`]
///
/// are triggered, if the thresholds
///
/// * [`set_stack_current_callback_threshold`],
/// * [`set_stack_voltage_callback_threshold`],
/// * [`set_usb_voltage_callback_threshold`]
///
/// keep being reached.
///
///
/// .. versionadded:: 2.0.5$nbsp;(Firmware)
pub fn set_debounce_period(&self, debounce: u32) -> ConvertingReceiver<()> {
let mut payload = vec![0; 4];
payload[0..4].copy_from_slice(&<u32>::to_le_byte_vec(debounce));
self.device.set(u8::from(MasterBrickFunction::SetDebouncePeriod), payload)
}
/// Returns the debounce period as set by [`set_debounce_period`].
///
///
/// .. versionadded:: 2.0.5$nbsp;(Firmware)
pub fn get_debounce_period(&self) -> ConvertingReceiver<u32> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetDebouncePeriod), payload)
}
/// Returns *true* if the Master Brick is at position 0 in the stack and an Ethernet
/// Extension is available.
///
///
/// .. versionadded:: 2.1.0$nbsp;(Firmware)
pub fn is_ethernet_present(&self) -> ConvertingReceiver<bool> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::IsEthernetPresent), payload)
}
/// Sets the configuration of the Ethernet Extension. Possible values for
/// ``connection`` are:
///
/// Value| Description
/// --- | ---
/// 0| DHCP
/// 1| Static IP
///
/// If you set ``connection`` to static IP options then you have to supply ``ip``,
/// ``subnet_mask`` and ``gateway`` as an array of size 4 (first element of the
/// array is the least significant byte of the address). If ``connection`` is set
/// to the DHCP options then ``ip``, ``subnet_mask`` and ``gateway`` are ignored,
/// you can set them to 0.
///
/// The last parameter is the port that your program will connect to.
///
/// The values are stored in the EEPROM and only applied on startup. That means
/// you have to restart the Master Brick after configuration.
///
/// It is recommended to use the Brick Viewer to set the Ethernet configuration.
///
///
/// .. versionadded:: 2.1.0$nbsp;(Firmware)
///
/// Associated constants:
/// * MASTER_BRICK_ETHERNET_CONNECTION_DHCP
/// * MASTER_BRICK_ETHERNET_CONNECTION_STATIC_IP
pub fn set_ethernet_configuration(
&self,
connection: u8,
ip: [u8; 4],
subnet_mask: [u8; 4],
gateway: [u8; 4],
port: u16,
) -> ConvertingReceiver<()> {
let mut payload = vec![0; 15];
payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(connection));
payload[1..5].copy_from_slice(&<[u8; 4]>::to_le_byte_vec(ip));
payload[5..9].copy_from_slice(&<[u8; 4]>::to_le_byte_vec(subnet_mask));
payload[9..13].copy_from_slice(&<[u8; 4]>::to_le_byte_vec(gateway));
payload[13..15].copy_from_slice(&<u16>::to_le_byte_vec(port));
self.device.set(u8::from(MasterBrickFunction::SetEthernetConfiguration), payload)
}
/// Returns the configuration as set by [`set_ethernet_configuration`].
///
///
/// .. versionadded:: 2.1.0$nbsp;(Firmware)
///
/// Associated constants:
/// * MASTER_BRICK_ETHERNET_CONNECTION_DHCP
/// * MASTER_BRICK_ETHERNET_CONNECTION_STATIC_IP
pub fn get_ethernet_configuration(&self) -> ConvertingReceiver<EthernetConfiguration> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetEthernetConfiguration), payload)
}
/// Returns the status of the Ethernet Extension.
///
/// ``mac_address``, ``ip``, ``subnet_mask`` and ``gateway`` are given as an array.
/// The first element of the array is the least significant byte of the address.
///
/// ``rx_count`` and ``tx_count`` are the number of bytes that have been
/// received/send since last restart.
///
/// ``hostname`` is the currently used hostname.
///
///
/// .. versionadded:: 2.1.0$nbsp;(Firmware)
pub fn get_ethernet_status(&self) -> ConvertingReceiver<EthernetStatus> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetEthernetStatus), payload)
}
/// Sets the hostname of the Ethernet Extension. The hostname will be displayed
/// by access points as the hostname in the DHCP clients table.
///
/// Setting an empty String will restore the default hostname.
///
/// The current hostname can be discovered with [`get_ethernet_status`].
///
///
/// .. versionadded:: 2.1.0$nbsp;(Firmware)
pub fn set_ethernet_hostname(&self, hostname: String) -> ConvertingReceiver<()> {
let mut payload = vec![0; 32];
match <String>::try_to_le_byte_vec(hostname, 32) {
Err(e) => {
let (tx, rx) = std::sync::mpsc::channel::<Result<Vec<u8>, BrickletError>>();
let _ = tx.send(Err(e));
return ConvertingReceiver::new(rx, std::time::Duration::new(1, 0));
}
Ok(bytes) => payload[0..32].copy_from_slice(&bytes),
}
self.device.set(u8::from(MasterBrickFunction::SetEthernetHostname), payload)
}
/// Sets the MAC address of the Ethernet Extension. The Ethernet Extension should
/// come configured with a valid MAC address, that is also written on a
/// sticker of the extension itself.
///
/// The MAC address can be read out again with [`get_ethernet_status`].
///
///
/// .. versionadded:: 2.1.0$nbsp;(Firmware)
pub fn set_ethernet_mac_address(&self, mac_address: [u8; 6]) -> ConvertingReceiver<()> {
let mut payload = vec![0; 6];
payload[0..6].copy_from_slice(&<[u8; 6]>::to_le_byte_vec(mac_address));
self.device.set(u8::from(MasterBrickFunction::SetEthernetMacAddress), payload)
}
/// Sets the Ethernet WebSocket configuration. The first parameter sets the number of socket
/// connections that are reserved for WebSockets. The range is 0-7. The connections
/// are shared with the plain sockets. Example: If you set the connections to 3,
/// there will be 3 WebSocket and 4 plain socket connections available.
///
/// The second parameter is the port for the WebSocket connections. The port can
/// not be the same as the port for the plain socket connections.
///
/// The values are stored in the EEPROM and only applied on startup. That means
/// you have to restart the Master Brick after configuration.
///
/// It is recommended to use the Brick Viewer to set the Ethernet configuration.
///
///
/// .. versionadded:: 2.2.0$nbsp;(Firmware)
pub fn set_ethernet_websocket_configuration(&self, sockets: u8, port: u16) -> ConvertingReceiver<()> {
let mut payload = vec![0; 3];
payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(sockets));
payload[1..3].copy_from_slice(&<u16>::to_le_byte_vec(port));
self.device.set(u8::from(MasterBrickFunction::SetEthernetWebsocketConfiguration), payload)
}
/// Returns the configuration as set by [`set_ethernet_configuration`].
///
///
/// .. versionadded:: 2.2.0$nbsp;(Firmware)
pub fn get_ethernet_websocket_configuration(&self) -> ConvertingReceiver<EthernetWebsocketConfiguration> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetEthernetWebsocketConfiguration), payload)
}
/// Sets the Ethernet authentication secret. The secret can be a string of up to 64
/// characters. An empty string disables the authentication.
///
/// See the [authentication tutorial](tutorial_authentication) for more
/// information.
///
/// The secret is stored in the EEPROM and only applied on startup. That means
/// you have to restart the Master Brick after configuration.
///
/// It is recommended to use the Brick Viewer to set the Ethernet authentication secret.
///
/// The default value is an empty string (authentication disabled).
///
///
/// .. versionadded:: 2.2.0$nbsp;(Firmware)
pub fn set_ethernet_authentication_secret(&self, secret: String) -> ConvertingReceiver<()> {
let mut payload = vec![0; 64];
match <String>::try_to_le_byte_vec(secret, 64) {
Err(e) => {
let (tx, rx) = std::sync::mpsc::channel::<Result<Vec<u8>, BrickletError>>();
let _ = tx.send(Err(e));
return ConvertingReceiver::new(rx, std::time::Duration::new(1, 0));
}
Ok(bytes) => payload[0..64].copy_from_slice(&bytes),
}
self.device.set(u8::from(MasterBrickFunction::SetEthernetAuthenticationSecret), payload)
}
/// Returns the authentication secret as set by
/// [`set_ethernet_authentication_secret`].
///
///
/// .. versionadded:: 2.2.0$nbsp;(Firmware)
pub fn get_ethernet_authentication_secret(&self) -> ConvertingReceiver<String> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetEthernetAuthenticationSecret), payload)
}
/// Sets the WIFI authentication secret. The secret can be a string of up to 64
/// characters. An empty string disables the authentication.
///
/// See the [authentication tutorial](tutorial_authentication) for more
/// information.
///
/// The secret is stored in the EEPROM and only applied on startup. That means
/// you have to restart the Master Brick after configuration.
///
/// It is recommended to use the Brick Viewer to set the WIFI authentication secret.
///
/// The default value is an empty string (authentication disabled).
///
///
/// .. versionadded:: 2.2.0$nbsp;(Firmware)
pub fn set_wifi_authentication_secret(&self, secret: String) -> ConvertingReceiver<()> {
let mut payload = vec![0; 64];
match <String>::try_to_le_byte_vec(secret, 64) {
Err(e) => {
let (tx, rx) = std::sync::mpsc::channel::<Result<Vec<u8>, BrickletError>>();
let _ = tx.send(Err(e));
return ConvertingReceiver::new(rx, std::time::Duration::new(1, 0));
}
Ok(bytes) => payload[0..64].copy_from_slice(&bytes),
}
self.device.set(u8::from(MasterBrickFunction::SetWifiAuthenticationSecret), payload)
}
/// Returns the authentication secret as set by
/// [`set_wifi_authentication_secret`].
///
///
/// .. versionadded:: 2.2.0$nbsp;(Firmware)
pub fn get_wifi_authentication_secret(&self) -> ConvertingReceiver<String> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetWifiAuthenticationSecret), payload)
}
/// Returns the type of the connection over which this function was called.
///
///
/// .. versionadded:: 2.4.0$nbsp;(Firmware)
///
/// Associated constants:
/// * MASTER_BRICK_CONNECTION_TYPE_NONE
/// * MASTER_BRICK_CONNECTION_TYPE_USB
/// * MASTER_BRICK_CONNECTION_TYPE_SPI_STACK
/// * MASTER_BRICK_CONNECTION_TYPE_CHIBI
/// * MASTER_BRICK_CONNECTION_TYPE_RS485
/// * MASTER_BRICK_CONNECTION_TYPE_WIFI
/// * MASTER_BRICK_CONNECTION_TYPE_ETHERNET
/// * MASTER_BRICK_CONNECTION_TYPE_WIFI2
pub fn get_connection_type(&self) -> ConvertingReceiver<u8> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetConnectionType), payload)
}
/// Returns *true* if the Master Brick is at position 0 in the stack and a WIFI
/// Extension 2.0 is available.
///
///
/// .. versionadded:: 2.4.0$nbsp;(Firmware)
pub fn is_wifi2_present(&self) -> ConvertingReceiver<bool> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::IsWifi2Present), payload)
}
/// Starts the bootloader of the WIFI Extension 2.0. Returns 0 on success.
/// Afterwards the [`write_wifi2_serial_port`] and [`read_wifi2_serial_port`]
/// functions can be used to communicate with the bootloader to flash a new
/// firmware.
///
/// The bootloader should only be started over a USB connection. It cannot be
/// started over a WIFI2 connection, see the [`get_connection_type`] function.
///
/// It is recommended to use the Brick Viewer to update the firmware of the WIFI
/// Extension 2.0.
///
///
/// .. versionadded:: 2.4.0$nbsp;(Firmware)
pub fn start_wifi2_bootloader(&self) -> ConvertingReceiver<i8> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::StartWifi2Bootloader), payload)
}
/// Writes up to 60 bytes (number of bytes to be written specified by ``length``)
/// to the serial port of the bootloader of the WIFI Extension 2.0. Returns 0 on
/// success.
///
/// Before this function can be used the bootloader has to be started using the
/// [`start_wifi2_bootloader`] function.
///
/// It is recommended to use the Brick Viewer to update the firmware of the WIFI
/// Extension 2.0.
///
///
/// .. versionadded:: 2.4.0$nbsp;(Firmware)
pub fn write_wifi2_serial_port(&self, data: [u8; 60], length: u8) -> ConvertingReceiver<i8> {
let mut payload = vec![0; 61];
payload[0..60].copy_from_slice(&<[u8; 60]>::to_le_byte_vec(data));
payload[60..61].copy_from_slice(&<u8>::to_le_byte_vec(length));
self.device.get(u8::from(MasterBrickFunction::WriteWifi2SerialPort), payload)
}
/// Reads up to 60 bytes (number of bytes to be read specified by ``length``)
/// from the serial port of the bootloader of the WIFI Extension 2.0.
/// Returns the number of actually read bytes.
///
/// Before this function can be used the bootloader has to be started using the
/// [`start_wifi2_bootloader`] function.
///
/// It is recommended to use the Brick Viewer to update the firmware of the WIFI
/// Extension 2.0.
///
///
/// .. versionadded:: 2.4.0$nbsp;(Firmware)
pub fn read_wifi2_serial_port(&self, length: u8) -> ConvertingReceiver<ReadWifi2SerialPort> {
let mut payload = vec![0; 1];
payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(length));
self.device.get(u8::from(MasterBrickFunction::ReadWifi2SerialPort), payload)
}
/// Sets the WIFI authentication secret. The secret can be a string of up to 64
/// characters. An empty string disables the authentication. The default value is
/// an empty string (authentication disabled).
///
/// See the [authentication tutorial](tutorial_authentication) for more
/// information.
///
/// To apply configuration changes to the WIFI Extension 2.0 the
/// [`save_wifi2_configuration`] function has to be called and the Master Brick
/// has to be restarted afterwards.
///
/// It is recommended to use the Brick Viewer to configure the WIFI Extension 2.0.
///
///
/// .. versionadded:: 2.4.0$nbsp;(Firmware)
pub fn set_wifi2_authentication_secret(&self, secret: String) -> ConvertingReceiver<()> {
let mut payload = vec![0; 64];
match <String>::try_to_le_byte_vec(secret, 64) {
Err(e) => {
let (tx, rx) = std::sync::mpsc::channel::<Result<Vec<u8>, BrickletError>>();
let _ = tx.send(Err(e));
return ConvertingReceiver::new(rx, std::time::Duration::new(1, 0));
}
Ok(bytes) => payload[0..64].copy_from_slice(&bytes),
}
self.device.set(u8::from(MasterBrickFunction::SetWifi2AuthenticationSecret), payload)
}
/// Returns the WIFI authentication secret as set by
/// [`set_wifi2_authentication_secret`].
///
///
/// .. versionadded:: 2.4.0$nbsp;(Firmware)
pub fn get_wifi2_authentication_secret(&self) -> ConvertingReceiver<String> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetWifi2AuthenticationSecret), payload)
}
/// Sets the general configuration of the WIFI Extension 2.0.
///
/// The ``port`` parameter sets the port number that your programm will connect
/// to.
///
/// The ``websocket_port`` parameter sets the WebSocket port number that your
/// JavaScript programm will connect to.
///
/// The ``website_port`` parameter sets the port number for the website of the
/// WIFI Extension 2.0.
///
/// The ``phy_mode`` parameter sets the specific wireless network mode to be used.
/// Possible values are B, G and N.
///
/// The ``sleep_mode`` parameter is currently unused.
///
/// The ``website`` parameter is used to enable or disable the web interface of
/// the WIFI Extension 2.0, which is available from firmware version 2.0.1. Note
/// that, for firmware version 2.0.3 and older, to disable the the web interface
/// the ``website_port`` parameter must be set to 1 and greater than 1 to enable
/// the web interface. For firmware version 2.0.4 and later, setting this parameter
/// to 1 will enable the web interface and setting it to 0 will disable the web
/// interface.
///
/// To apply configuration changes to the WIFI Extension 2.0 the
/// [`save_wifi2_configuration`] function has to be called and the Master Brick
/// has to be restarted afterwards.
///
/// It is recommended to use the Brick Viewer to configure the WIFI Extension 2.0.
///
///
/// .. versionadded:: 2.4.0$nbsp;(Firmware)
///
/// Associated constants:
/// * MASTER_BRICK_WIFI2_PHY_MODE_B
/// * MASTER_BRICK_WIFI2_PHY_MODE_G
/// * MASTER_BRICK_WIFI2_PHY_MODE_N
pub fn set_wifi2_configuration(
&self,
port: u16,
websocket_port: u16,
website_port: u16,
phy_mode: u8,
sleep_mode: u8,
website: u8,
) -> ConvertingReceiver<()> {
let mut payload = vec![0; 9];
payload[0..2].copy_from_slice(&<u16>::to_le_byte_vec(port));
payload[2..4].copy_from_slice(&<u16>::to_le_byte_vec(websocket_port));
payload[4..6].copy_from_slice(&<u16>::to_le_byte_vec(website_port));
payload[6..7].copy_from_slice(&<u8>::to_le_byte_vec(phy_mode));
payload[7..8].copy_from_slice(&<u8>::to_le_byte_vec(sleep_mode));
payload[8..9].copy_from_slice(&<u8>::to_le_byte_vec(website));
self.device.set(u8::from(MasterBrickFunction::SetWifi2Configuration), payload)
}
/// Returns the general configuration as set by [`set_wifi2_configuration`].
///
///
/// .. versionadded:: 2.4.0$nbsp;(Firmware)
///
/// Associated constants:
/// * MASTER_BRICK_WIFI2_PHY_MODE_B
/// * MASTER_BRICK_WIFI2_PHY_MODE_G
/// * MASTER_BRICK_WIFI2_PHY_MODE_N
pub fn get_wifi2_configuration(&self) -> ConvertingReceiver<Wifi2Configuration> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetWifi2Configuration), payload)
}
/// Returns the client and access point status of the WIFI Extension 2.0.
///
///
/// .. versionadded:: 2.4.0$nbsp;(Firmware)
///
/// Associated constants:
/// * MASTER_BRICK_WIFI2_CLIENT_STATUS_IDLE
/// * MASTER_BRICK_WIFI2_CLIENT_STATUS_CONNECTING
/// * MASTER_BRICK_WIFI2_CLIENT_STATUS_WRONG_PASSWORD
/// * MASTER_BRICK_WIFI2_CLIENT_STATUS_NO_AP_FOUND
/// * MASTER_BRICK_WIFI2_CLIENT_STATUS_CONNECT_FAILED
/// * MASTER_BRICK_WIFI2_CLIENT_STATUS_GOT_IP
/// * MASTER_BRICK_WIFI2_CLIENT_STATUS_UNKNOWN
pub fn get_wifi2_status(&self) -> ConvertingReceiver<Wifi2Status> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetWifi2Status), payload)
}
/// Sets the client specific configuration of the WIFI Extension 2.0.
///
/// The ``enable`` parameter enables or disables the client part of the
/// WIFI Extension 2.0.
///
/// The ``ssid`` parameter sets the SSID (up to 32 characters) of the access point
/// to connect to.
///
/// If the ``ip`` parameter is set to all zero then ``subnet_mask`` and ``gateway``
/// parameters are also set to all zero and DHCP is used for IP address configuration.
/// Otherwise those three parameters can be used to configure a static IP address.
/// The default configuration is DHCP.
///
/// If the ``mac_address`` parameter is set to all zero then the factory MAC
/// address is used. Otherwise this parameter can be used to set a custom MAC
/// address.
///
/// If the ``bssid`` parameter is set to all zero then WIFI Extension 2.0 will
/// connect to any access point that matches the configured SSID. Otherwise this
/// parameter can be used to make the WIFI Extension 2.0 only connect to an
/// access point if SSID and BSSID match.
///
/// To apply configuration changes to the WIFI Extension 2.0 the
/// [`save_wifi2_configuration`] function has to be called and the Master Brick
/// has to be restarted afterwards.
///
/// It is recommended to use the Brick Viewer to configure the WIFI Extension 2.0.
///
///
/// .. versionadded:: 2.4.0$nbsp;(Firmware)
pub fn set_wifi2_client_configuration(
&self,
enable: bool,
ssid: String,
ip: [u8; 4],
subnet_mask: [u8; 4],
gateway: [u8; 4],
mac_address: [u8; 6],
bssid: [u8; 6],
) -> ConvertingReceiver<()> {
let mut payload = vec![0; 57];
payload[0..1].copy_from_slice(&<bool>::to_le_byte_vec(enable));
match <String>::try_to_le_byte_vec(ssid, 32) {
Err(e) => {
let (tx, rx) = std::sync::mpsc::channel::<Result<Vec<u8>, BrickletError>>();
let _ = tx.send(Err(e));
return ConvertingReceiver::new(rx, std::time::Duration::new(1, 0));
}
Ok(bytes) => payload[1..33].copy_from_slice(&bytes),
}
payload[33..37].copy_from_slice(&<[u8; 4]>::to_le_byte_vec(ip));
payload[37..41].copy_from_slice(&<[u8; 4]>::to_le_byte_vec(subnet_mask));
payload[41..45].copy_from_slice(&<[u8; 4]>::to_le_byte_vec(gateway));
payload[45..51].copy_from_slice(&<[u8; 6]>::to_le_byte_vec(mac_address));
payload[51..57].copy_from_slice(&<[u8; 6]>::to_le_byte_vec(bssid));
self.device.set(u8::from(MasterBrickFunction::SetWifi2ClientConfiguration), payload)
}
/// Returns the client configuration as set by [`set_wifi2_client_configuration`].
///
///
/// .. versionadded:: 2.4.0$nbsp;(Firmware)
pub fn get_wifi2_client_configuration(&self) -> ConvertingReceiver<Wifi2ClientConfiguration> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetWifi2ClientConfiguration), payload)
}
/// Sets the client hostname (up to 32 characters) of the WIFI Extension 2.0. The
/// hostname will be displayed by access points as the hostname in the DHCP clients
/// table.
///
/// To apply configuration changes to the WIFI Extension 2.0 the
/// [`save_wifi2_configuration`] function has to be called and the Master Brick
/// has to be restarted afterwards.
///
/// It is recommended to use the Brick Viewer to configure the WIFI Extension 2.0.
///
///
/// .. versionadded:: 2.4.0$nbsp;(Firmware)
pub fn set_wifi2_client_hostname(&self, hostname: String) -> ConvertingReceiver<()> {
let mut payload = vec![0; 32];
match <String>::try_to_le_byte_vec(hostname, 32) {
Err(e) => {
let (tx, rx) = std::sync::mpsc::channel::<Result<Vec<u8>, BrickletError>>();
let _ = tx.send(Err(e));
return ConvertingReceiver::new(rx, std::time::Duration::new(1, 0));
}
Ok(bytes) => payload[0..32].copy_from_slice(&bytes),
}
self.device.set(u8::from(MasterBrickFunction::SetWifi2ClientHostname), payload)
}
/// Returns the client hostname as set by [`set_wifi2_client_hostname`].
///
///
/// .. versionadded:: 2.4.0$nbsp;(Firmware)
pub fn get_wifi2_client_hostname(&self) -> ConvertingReceiver<String> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetWifi2ClientHostname), payload)
}
/// Sets the client password (up to 63 chars) for WPA/WPA2 encryption.
///
/// To apply configuration changes to the WIFI Extension 2.0 the
/// [`save_wifi2_configuration`] function has to be called and the Master Brick
/// has to be restarted afterwards.
///
/// It is recommended to use the Brick Viewer to configure the WIFI Extension 2.0.
///
///
/// .. versionadded:: 2.4.0$nbsp;(Firmware)
pub fn set_wifi2_client_password(&self, password: String) -> ConvertingReceiver<()> {
let mut payload = vec![0; 64];
match <String>::try_to_le_byte_vec(password, 64) {
Err(e) => {
let (tx, rx) = std::sync::mpsc::channel::<Result<Vec<u8>, BrickletError>>();
let _ = tx.send(Err(e));
return ConvertingReceiver::new(rx, std::time::Duration::new(1, 0));
}
Ok(bytes) => payload[0..64].copy_from_slice(&bytes),
}
self.device.set(u8::from(MasterBrickFunction::SetWifi2ClientPassword), payload)
}
/// Returns the client password as set by [`set_wifi2_client_password`].
///
/// # Note
/// Since WIFI Extension 2.0 firmware version 2.1.3 the password is not
/// returned anymore.
///
///
/// .. versionadded:: 2.4.0$nbsp;(Firmware)
pub fn get_wifi2_client_password(&self) -> ConvertingReceiver<String> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetWifi2ClientPassword), payload)
}
/// Sets the access point specific configuration of the WIFI Extension 2.0.
///
/// The ``enable`` parameter enables or disables the access point part of the
/// WIFI Extension 2.0.
///
/// The ``ssid`` parameter sets the SSID (up to 32 characters) of the access point.
///
/// If the ``ip`` parameter is set to all zero then ``subnet_mask`` and ``gateway``
/// parameters are also set to all zero and DHCP is used for IP address configuration.
/// Otherwise those three parameters can be used to configure a static IP address.
/// The default configuration is DHCP.
///
/// The ``encryption`` parameter sets the encryption mode to be used. Possible
/// values are Open (no encryption), WEP or WPA/WPA2 PSK.
/// Use the [`set_wifi2_ap_password`] function to set the encryption
/// password.
///
/// The ``hidden`` parameter makes the access point hide or show its SSID.
///
/// The ``channel`` parameter sets the channel (1 to 13) of the access point.
///
/// If the ``mac_address`` parameter is set to all zero then the factory MAC
/// address is used. Otherwise this parameter can be used to set a custom MAC
/// address.
///
/// To apply configuration changes to the WIFI Extension 2.0 the
/// [`save_wifi2_configuration`] function has to be called and the Master Brick
/// has to be restarted afterwards.
///
/// It is recommended to use the Brick Viewer to configure the WIFI Extension 2.0.
///
///
/// .. versionadded:: 2.4.0$nbsp;(Firmware)
///
/// Associated constants:
/// * MASTER_BRICK_WIFI2_AP_ENCRYPTION_OPEN
/// * MASTER_BRICK_WIFI2_AP_ENCRYPTION_WEP
/// * MASTER_BRICK_WIFI2_AP_ENCRYPTION_WPA_PSK
/// * MASTER_BRICK_WIFI2_AP_ENCRYPTION_WPA2_PSK
/// * MASTER_BRICK_WIFI2_AP_ENCRYPTION_WPA_WPA2_PSK
pub fn set_wifi2_ap_configuration(
&self,
enable: bool,
ssid: String,
ip: [u8; 4],
subnet_mask: [u8; 4],
gateway: [u8; 4],
encryption: u8,
hidden: bool,
channel: u8,
mac_address: [u8; 6],
) -> ConvertingReceiver<()> {
let mut payload = vec![0; 54];
payload[0..1].copy_from_slice(&<bool>::to_le_byte_vec(enable));
match <String>::try_to_le_byte_vec(ssid, 32) {
Err(e) => {
let (tx, rx) = std::sync::mpsc::channel::<Result<Vec<u8>, BrickletError>>();
let _ = tx.send(Err(e));
return ConvertingReceiver::new(rx, std::time::Duration::new(1, 0));
}
Ok(bytes) => payload[1..33].copy_from_slice(&bytes),
}
payload[33..37].copy_from_slice(&<[u8; 4]>::to_le_byte_vec(ip));
payload[37..41].copy_from_slice(&<[u8; 4]>::to_le_byte_vec(subnet_mask));
payload[41..45].copy_from_slice(&<[u8; 4]>::to_le_byte_vec(gateway));
payload[45..46].copy_from_slice(&<u8>::to_le_byte_vec(encryption));
payload[46..47].copy_from_slice(&<bool>::to_le_byte_vec(hidden));
payload[47..48].copy_from_slice(&<u8>::to_le_byte_vec(channel));
payload[48..54].copy_from_slice(&<[u8; 6]>::to_le_byte_vec(mac_address));
self.device.set(u8::from(MasterBrickFunction::SetWifi2ApConfiguration), payload)
}
/// Returns the access point configuration as set by [`set_wifi2_ap_configuration`].
///
///
/// .. versionadded:: 2.4.0$nbsp;(Firmware)
///
/// Associated constants:
/// * MASTER_BRICK_WIFI2_AP_ENCRYPTION_OPEN
/// * MASTER_BRICK_WIFI2_AP_ENCRYPTION_WEP
/// * MASTER_BRICK_WIFI2_AP_ENCRYPTION_WPA_PSK
/// * MASTER_BRICK_WIFI2_AP_ENCRYPTION_WPA2_PSK
/// * MASTER_BRICK_WIFI2_AP_ENCRYPTION_WPA_WPA2_PSK
pub fn get_wifi2_ap_configuration(&self) -> ConvertingReceiver<Wifi2ApConfiguration> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetWifi2ApConfiguration), payload)
}
/// Sets the access point password (at least 8 and up to 63 chars) for the configured encryption
/// mode, see [`set_wifi2_ap_configuration`].
///
/// To apply configuration changes to the WIFI Extension 2.0 the
/// [`save_wifi2_configuration`] function has to be called and the Master Brick
/// has to be restarted afterwards.
///
/// It is recommended to use the Brick Viewer to configure the WIFI Extension 2.0.
///
///
/// .. versionadded:: 2.4.0$nbsp;(Firmware)
pub fn set_wifi2_ap_password(&self, password: String) -> ConvertingReceiver<()> {
let mut payload = vec![0; 64];
match <String>::try_to_le_byte_vec(password, 64) {
Err(e) => {
let (tx, rx) = std::sync::mpsc::channel::<Result<Vec<u8>, BrickletError>>();
let _ = tx.send(Err(e));
return ConvertingReceiver::new(rx, std::time::Duration::new(1, 0));
}
Ok(bytes) => payload[0..64].copy_from_slice(&bytes),
}
self.device.set(u8::from(MasterBrickFunction::SetWifi2ApPassword), payload)
}
/// Returns the access point password as set by [`set_wifi2_ap_password`].
///
/// # Note
/// Since WIFI Extension 2.0 firmware version 2.1.3 the password is not
/// returned anymore.
///
///
/// .. versionadded:: 2.4.0$nbsp;(Firmware)
pub fn get_wifi2_ap_password(&self) -> ConvertingReceiver<String> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetWifi2ApPassword), payload)
}
/// All configuration functions for the WIFI Extension 2.0 do not change the
/// values permanently. After configuration this function has to be called to
/// permanently store the values.
///
/// The values are stored in the EEPROM and only applied on startup. That means
/// you have to restart the Master Brick after configuration.
///
///
/// .. versionadded:: 2.4.0$nbsp;(Firmware)
pub fn save_wifi2_configuration(&self) -> ConvertingReceiver<u8> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::SaveWifi2Configuration), payload)
}
/// Returns the current version of the WIFI Extension 2.0 firmware.
///
///
/// .. versionadded:: 2.4.0$nbsp;(Firmware)
pub fn get_wifi2_firmware_version(&self) -> ConvertingReceiver<[u8; 3]> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetWifi2FirmwareVersion), payload)
}
/// Turns the green status LED of the WIFI Extension 2.0 on.
///
///
/// .. versionadded:: 2.4.0$nbsp;(Firmware)
pub fn enable_wifi2_status_led(&self) -> ConvertingReceiver<()> {
let payload = vec![0; 0];
self.device.set(u8::from(MasterBrickFunction::EnableWifi2StatusLed), payload)
}
/// Turns the green status LED of the WIFI Extension 2.0 off.
///
///
/// .. versionadded:: 2.4.0$nbsp;(Firmware)
pub fn disable_wifi2_status_led(&self) -> ConvertingReceiver<()> {
let payload = vec![0; 0];
self.device.set(u8::from(MasterBrickFunction::DisableWifi2StatusLed), payload)
}
/// Returns *true* if the green status LED of the WIFI Extension 2.0 is turned on.
///
///
/// .. versionadded:: 2.4.0$nbsp;(Firmware)
pub fn is_wifi2_status_led_enabled(&self) -> ConvertingReceiver<bool> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::IsWifi2StatusLedEnabled), payload)
}
/// Requires WIFI Extension 2.0 firmware 2.1.0.
///
/// Sets the mesh specific configuration of the WIFI Extension 2.0.
///
/// The ``enable`` parameter enables or disables the mesh part of the
/// WIFI Extension 2.0. The mesh part cannot be
/// enabled together with the client and access-point part.
///
/// If the ``root_ip`` parameter is set to all zero then ``root_subnet_mask``
/// and ``root_gateway`` parameters are also set to all zero and DHCP is used for
/// IP address configuration. Otherwise those three parameters can be used to
/// configure a static IP address. The default configuration is DHCP.
///
/// If the ``router_bssid`` parameter is set to all zero then the information is
/// taken from Wi-Fi scan when connecting the SSID as set by
/// [`set_wifi2_mesh_router_ssid`]. This only works if the the SSID is not hidden.
/// In case the router has hidden SSID this parameter must be specified, otherwise
/// the node will not be able to reach the mesh router.
///
/// The ``group_id`` and the ``group_ssid_prefix`` parameters identifies a
/// particular mesh network and nodes configured with same ``group_id`` and the
/// ``group_ssid_prefix`` are considered to be in the same mesh network.
///
/// The ``gateway_ip`` and the ``gateway_port`` parameters specifies the location
/// of the brickd that supports mesh feature.
///
/// To apply configuration changes to the WIFI Extension 2.0 the
/// [`save_wifi2_configuration`] function has to be called and the Master Brick
/// has to be restarted afterwards.
///
/// It is recommended to use the Brick Viewer to configure the WIFI Extension 2.0.
///
///
/// .. versionadded:: 2.4.2$nbsp;(Firmware)
pub fn set_wifi2_mesh_configuration(
&self,
enable: bool,
root_ip: [u8; 4],
root_subnet_mask: [u8; 4],
root_gateway: [u8; 4],
router_bssid: [u8; 6],
group_id: [u8; 6],
group_ssid_prefix: String,
gateway_ip: [u8; 4],
gateway_port: u16,
) -> ConvertingReceiver<()> {
let mut payload = vec![0; 47];
payload[0..1].copy_from_slice(&<bool>::to_le_byte_vec(enable));
payload[1..5].copy_from_slice(&<[u8; 4]>::to_le_byte_vec(root_ip));
payload[5..9].copy_from_slice(&<[u8; 4]>::to_le_byte_vec(root_subnet_mask));
payload[9..13].copy_from_slice(&<[u8; 4]>::to_le_byte_vec(root_gateway));
payload[13..19].copy_from_slice(&<[u8; 6]>::to_le_byte_vec(router_bssid));
payload[19..25].copy_from_slice(&<[u8; 6]>::to_le_byte_vec(group_id));
match <String>::try_to_le_byte_vec(group_ssid_prefix, 16) {
Err(e) => {
let (tx, rx) = std::sync::mpsc::channel::<Result<Vec<u8>, BrickletError>>();
let _ = tx.send(Err(e));
return ConvertingReceiver::new(rx, std::time::Duration::new(1, 0));
}
Ok(bytes) => payload[25..41].copy_from_slice(&bytes),
}
payload[41..45].copy_from_slice(&<[u8; 4]>::to_le_byte_vec(gateway_ip));
payload[45..47].copy_from_slice(&<u16>::to_le_byte_vec(gateway_port));
self.device.set(u8::from(MasterBrickFunction::SetWifi2MeshConfiguration), payload)
}
/// Requires WIFI Extension 2.0 firmware 2.1.0.
///
/// Returns the mesh configuration as set by [`set_wifi2_mesh_configuration`].
///
///
/// .. versionadded:: 2.4.2$nbsp;(Firmware)
pub fn get_wifi2_mesh_configuration(&self) -> ConvertingReceiver<Wifi2MeshConfiguration> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetWifi2MeshConfiguration), payload)
}
/// Requires WIFI Extension 2.0 firmware 2.1.0.
///
/// Sets the mesh router SSID of the WIFI Extension 2.0.
/// It is used to specify the mesh router to connect to.
///
/// Note that even though in the argument of this function a 32 characters long SSID
/// is allowed, in practice valid SSID should have a maximum of 31 characters. This
/// is due to a bug in the mesh library that we use in the firmware of the extension.
///
/// To apply configuration changes to the WIFI Extension 2.0 the
/// [`save_wifi2_configuration`] function has to be called and the Master Brick
/// has to be restarted afterwards.
///
/// It is recommended to use the Brick Viewer to configure the WIFI Extension 2.0.
///
///
/// .. versionadded:: 2.4.2$nbsp;(Firmware)
pub fn set_wifi2_mesh_router_ssid(&self, ssid: String) -> ConvertingReceiver<()> {
let mut payload = vec![0; 32];
match <String>::try_to_le_byte_vec(ssid, 32) {
Err(e) => {
let (tx, rx) = std::sync::mpsc::channel::<Result<Vec<u8>, BrickletError>>();
let _ = tx.send(Err(e));
return ConvertingReceiver::new(rx, std::time::Duration::new(1, 0));
}
Ok(bytes) => payload[0..32].copy_from_slice(&bytes),
}
self.device.set(u8::from(MasterBrickFunction::SetWifi2MeshRouterSsid), payload)
}
/// Requires WIFI Extension 2.0 firmware 2.1.0.
///
/// Returns the mesh router SSID as set by [`set_wifi2_mesh_router_ssid`].
///
///
/// .. versionadded:: 2.4.2$nbsp;(Firmware)
pub fn get_wifi2_mesh_router_ssid(&self) -> ConvertingReceiver<String> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetWifi2MeshRouterSsid), payload)
}
/// Requires WIFI Extension 2.0 firmware 2.1.0.
///
/// Sets the mesh router password (up to 64 characters) for WPA/WPA2 encryption.
/// The password will be used to connect to the mesh router.
///
/// To apply configuration changes to the WIFI Extension 2.0 the
/// [`save_wifi2_configuration`] function has to be called and the Master Brick
/// has to be restarted afterwards.
///
/// It is recommended to use the Brick Viewer to configure the WIFI Extension 2.0.
///
///
/// .. versionadded:: 2.4.2$nbsp;(Firmware)
pub fn set_wifi2_mesh_router_password(&self, password: String) -> ConvertingReceiver<()> {
let mut payload = vec![0; 64];
match <String>::try_to_le_byte_vec(password, 64) {
Err(e) => {
let (tx, rx) = std::sync::mpsc::channel::<Result<Vec<u8>, BrickletError>>();
let _ = tx.send(Err(e));
return ConvertingReceiver::new(rx, std::time::Duration::new(1, 0));
}
Ok(bytes) => payload[0..64].copy_from_slice(&bytes),
}
self.device.set(u8::from(MasterBrickFunction::SetWifi2MeshRouterPassword), payload)
}
/// Requires WIFI Extension 2.0 firmware 2.1.0.
///
/// Returns the mesh router password as set by [`set_wifi2_mesh_router_password`].
///
///
/// .. versionadded:: 2.4.2$nbsp;(Firmware)
pub fn get_wifi2_mesh_router_password(&self) -> ConvertingReceiver<String> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetWifi2MeshRouterPassword), payload)
}
/// Requires WIFI Extension 2.0 firmware 2.1.0.
///
/// Returns the common mesh status of the WIFI Extension 2.0.
///
///
/// .. versionadded:: 2.4.2$nbsp;(Firmware)
///
/// Associated constants:
/// * MASTER_BRICK_WIFI2_MESH_STATUS_DISABLED
/// * MASTER_BRICK_WIFI2_MESH_STATUS_WIFI_CONNECTING
/// * MASTER_BRICK_WIFI2_MESH_STATUS_GOT_IP
/// * MASTER_BRICK_WIFI2_MESH_STATUS_MESH_LOCAL
/// * MASTER_BRICK_WIFI2_MESH_STATUS_MESH_ONLINE
/// * MASTER_BRICK_WIFI2_MESH_STATUS_AP_AVAILABLE
/// * MASTER_BRICK_WIFI2_MESH_STATUS_AP_SETUP
/// * MASTER_BRICK_WIFI2_MESH_STATUS_LEAF_AVAILABLE
pub fn get_wifi2_mesh_common_status(&self) -> ConvertingReceiver<Wifi2MeshCommonStatus> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetWifi2MeshCommonStatus), payload)
}
/// Requires WIFI Extension 2.0 firmware 2.1.0.
///
/// Returns the mesh client status of the WIFI Extension 2.0.
///
///
/// .. versionadded:: 2.4.2$nbsp;(Firmware)
pub fn get_wifi2_mesh_client_status(&self) -> ConvertingReceiver<Wifi2MeshClientStatus> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetWifi2MeshClientStatus), payload)
}
/// Requires WIFI Extension 2.0 firmware 2.1.0.
///
/// Returns the mesh AP status of the WIFI Extension 2.0.
///
///
/// .. versionadded:: 2.4.2$nbsp;(Firmware)
pub fn get_wifi2_mesh_ap_status(&self) -> ConvertingReceiver<Wifi2MeshApStatus> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetWifi2MeshApStatus), payload)
}
/// This function is for internal use to flash the initial
/// bootstrapper and bootloader to the Bricklets.
///
/// If you need to flash a boostrapper/bootloader (for exmaple
/// because you made your own Bricklet from scratch) please
/// take a look at our open source flash and test tool at
/// [https://github.com/Tinkerforge/flash-test](https://github.com/Tinkerforge/flash-test)__
///
/// Don't use this function directly.
///
///
/// .. versionadded:: 2.5.0$nbsp;(Firmware)
pub fn set_bricklet_xmc_flash_config(
&self,
config: u32,
parameter1: u32,
parameter2: u32,
data: [u8; 52],
) -> ConvertingReceiver<SetBrickletXmcFlashConfig> {
let mut payload = vec![0; 64];
payload[0..4].copy_from_slice(&<u32>::to_le_byte_vec(config));
payload[4..8].copy_from_slice(&<u32>::to_le_byte_vec(parameter1));
payload[8..12].copy_from_slice(&<u32>::to_le_byte_vec(parameter2));
payload[12..64].copy_from_slice(&<[u8; 52]>::to_le_byte_vec(data));
self.device.get(u8::from(MasterBrickFunction::SetBrickletXmcFlashConfig), payload)
}
/// This function is for internal use to flash the initial
/// bootstrapper and bootloader to the Bricklets.
///
/// If you need to flash a boostrapper/bootloader (for exmaple
/// because you made your own Bricklet from scratch) please
/// take a look at our open source flash and test tool at
/// [https://github.com/Tinkerforge/flash-test](https://github.com/Tinkerforge/flash-test)__
///
/// Don't use this function directly.
///
///
/// .. versionadded:: 2.5.0$nbsp;(Firmware)
pub fn set_bricklet_xmc_flash_data(&self, data: [u8; 64]) -> ConvertingReceiver<u32> {
let mut payload = vec![0; 64];
payload[0..64].copy_from_slice(&<[u8; 64]>::to_le_byte_vec(data));
self.device.get(u8::from(MasterBrickFunction::SetBrickletXmcFlashData), payload)
}
/// This function is only available in Master Brick hardware version >= 3.0.
///
/// Enables/disables all four Bricklets if set to true/false.
///
/// If you disable the Bricklets the power supply to the Bricklets will be disconnected.
/// The Bricklets will lose all configurations if disabled.
///
///
/// .. versionadded:: 2.5.0$nbsp;(Firmware)
pub fn set_bricklets_enabled(&self, bricklets_enabled: bool) -> ConvertingReceiver<()> {
let mut payload = vec![0; 1];
payload[0..1].copy_from_slice(&<bool>::to_le_byte_vec(bricklets_enabled));
self.device.set(u8::from(MasterBrickFunction::SetBrickletsEnabled), payload)
}
/// Returns *true* if the Bricklets are enabled, *false* otherwise.
///
///
/// .. versionadded:: 2.5.0$nbsp;(Firmware)
pub fn get_bricklets_enabled(&self) -> ConvertingReceiver<bool> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetBrickletsEnabled), payload)
}
/// The SPITF protocol can be used with a dynamic baudrate. If the dynamic baudrate is
/// enabled, the Brick will try to adapt the baudrate for the communication
/// between Bricks and Bricklets according to the amount of data that is transferred.
///
/// The baudrate will be increased exponentially if lots of data is sent/received and
/// decreased linearly if little data is sent/received.
///
/// This lowers the baudrate in applications where little data is transferred (e.g.
/// a weather station) and increases the robustness. If there is lots of data to transfer
/// (e.g. Thermal Imaging Bricklet) it automatically increases the baudrate as needed.
///
/// In cases where some data has to transferred as fast as possible every few seconds
/// (e.g. RS485 Bricklet with a high baudrate but small payload) you may want to turn
/// the dynamic baudrate off to get the highest possible performance.
///
/// The maximum value of the baudrate can be set per port with the function
/// [`set_spitfp_baudrate`]. If the dynamic baudrate is disabled, the baudrate
/// as set by [`set_spitfp_baudrate`] will be used statically.
///
///
/// .. versionadded:: 2.4.6$nbsp;(Firmware)
pub fn set_spitfp_baudrate_config(&self, enable_dynamic_baudrate: bool, minimum_dynamic_baudrate: u32) -> ConvertingReceiver<()> {
let mut payload = vec![0; 5];
payload[0..1].copy_from_slice(&<bool>::to_le_byte_vec(enable_dynamic_baudrate));
payload[1..5].copy_from_slice(&<u32>::to_le_byte_vec(minimum_dynamic_baudrate));
self.device.set(u8::from(MasterBrickFunction::SetSpitfpBaudrateConfig), payload)
}
/// Returns the baudrate config, see [`set_spitfp_baudrate_config`].
///
///
/// .. versionadded:: 2.4.6$nbsp;(Firmware)
pub fn get_spitfp_baudrate_config(&self) -> ConvertingReceiver<SpitfpBaudrateConfig> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetSpitfpBaudrateConfig), payload)
}
/// Returns the timeout count for the different communication methods.
///
/// The methods 0-2 are available for all Bricks, 3-7 only for Master Bricks.
///
/// This function is mostly used for debugging during development, in normal operation
/// the counters should nearly always stay at 0.
///
///
/// .. versionadded:: 2.4.3$nbsp;(Firmware)
///
/// Associated constants:
/// * MASTER_BRICK_COMMUNICATION_METHOD_NONE
/// * MASTER_BRICK_COMMUNICATION_METHOD_USB
/// * MASTER_BRICK_COMMUNICATION_METHOD_SPI_STACK
/// * MASTER_BRICK_COMMUNICATION_METHOD_CHIBI
/// * MASTER_BRICK_COMMUNICATION_METHOD_RS485
/// * MASTER_BRICK_COMMUNICATION_METHOD_WIFI
/// * MASTER_BRICK_COMMUNICATION_METHOD_ETHERNET
/// * MASTER_BRICK_COMMUNICATION_METHOD_WIFI_V2
pub fn get_send_timeout_count(&self, communication_method: u8) -> ConvertingReceiver<u32> {
let mut payload = vec![0; 1];
payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(communication_method));
self.device.get(u8::from(MasterBrickFunction::GetSendTimeoutCount), payload)
}
/// Sets the baudrate for a specific Bricklet port.
///
/// If you want to increase the throughput of Bricklets you can increase
/// the baudrate. If you get a high error count because of high
/// interference (see [`get_spitfp_error_count`]) you can decrease the
/// baudrate.
///
/// If the dynamic baudrate feature is enabled, the baudrate set by this
/// function corresponds to the maximum baudrate (see [`set_spitfp_baudrate_config`]).
///
/// Regulatory testing is done with the default baudrate. If CE compatibility
/// or similar is necessary in your applications we recommend to not change
/// the baudrate.
///
///
/// .. versionadded:: 2.4.3$nbsp;(Firmware)
pub fn set_spitfp_baudrate(&self, bricklet_port: char, baudrate: u32) -> ConvertingReceiver<()> {
let mut payload = vec![0; 5];
payload[0..1].copy_from_slice(&<char>::to_le_byte_vec(bricklet_port));
payload[1..5].copy_from_slice(&<u32>::to_le_byte_vec(baudrate));
self.device.set(u8::from(MasterBrickFunction::SetSpitfpBaudrate), payload)
}
/// Returns the baudrate for a given Bricklet port, see [`set_spitfp_baudrate`].
///
///
/// .. versionadded:: 2.4.3$nbsp;(Firmware)
pub fn get_spitfp_baudrate(&self, bricklet_port: char) -> ConvertingReceiver<u32> {
let mut payload = vec![0; 1];
payload[0..1].copy_from_slice(&<char>::to_le_byte_vec(bricklet_port));
self.device.get(u8::from(MasterBrickFunction::GetSpitfpBaudrate), payload)
}
/// Returns the error count for the communication between Brick and Bricklet.
///
/// The errors are divided into
///
/// * ACK checksum errors,
/// * message checksum errors,
/// * framing errors and
/// * overflow errors.
///
/// The errors counts are for errors that occur on the Brick side. All
/// Bricklets have a similar function that returns the errors on the Bricklet side.
///
///
/// .. versionadded:: 2.4.3$nbsp;(Firmware)
pub fn get_spitfp_error_count(&self, bricklet_port: char) -> ConvertingReceiver<SpitfpErrorCount> {
let mut payload = vec![0; 1];
payload[0..1].copy_from_slice(&<char>::to_le_byte_vec(bricklet_port));
self.device.get(u8::from(MasterBrickFunction::GetSpitfpErrorCount), payload)
}
/// Enables the status LED.
///
/// The status LED is the blue LED next to the USB connector. If enabled is is
/// on and it flickers if data is transfered. If disabled it is always off.
///
/// The default state is enabled.
///
///
/// .. versionadded:: 2.3.2$nbsp;(Firmware)
pub fn enable_status_led(&self) -> ConvertingReceiver<()> {
let payload = vec![0; 0];
self.device.set(u8::from(MasterBrickFunction::EnableStatusLed), payload)
}
/// Disables the status LED.
///
/// The status LED is the blue LED next to the USB connector. If enabled is is
/// on and it flickers if data is transfered. If disabled it is always off.
///
/// The default state is enabled.
///
///
/// .. versionadded:: 2.3.2$nbsp;(Firmware)
pub fn disable_status_led(&self) -> ConvertingReceiver<()> {
let payload = vec![0; 0];
self.device.set(u8::from(MasterBrickFunction::DisableStatusLed), payload)
}
/// Returns *true* if the status LED is enabled, *false* otherwise.
///
///
/// .. versionadded:: 2.3.2$nbsp;(Firmware)
pub fn is_status_led_enabled(&self) -> ConvertingReceiver<bool> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::IsStatusLedEnabled), payload)
}
/// Returns the firmware and protocol version and the name of the Bricklet for a
/// given port.
///
/// This functions sole purpose is to allow automatic flashing of v1.x.y Bricklet
/// plugins.
pub fn get_protocol1_bricklet_name(&self, port: char) -> ConvertingReceiver<Protocol1BrickletName> {
let mut payload = vec![0; 1];
payload[0..1].copy_from_slice(&<char>::to_le_byte_vec(port));
self.device.get(u8::from(MasterBrickFunction::GetProtocol1BrickletName), payload)
}
/// Returns the temperature as measured inside the microcontroller. The
/// value returned is not the ambient temperature!
///
/// The temperature is only proportional to the real temperature and it has an
/// accuracy of ±15%. Practically it is only useful as an indicator for
/// temperature changes.
pub fn get_chip_temperature(&self) -> ConvertingReceiver<i16> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetChipTemperature), payload)
}
/// Calling this function will reset the Brick. Calling this function
/// on a Brick inside of a stack will reset the whole stack.
///
/// After a reset you have to create new device objects,
/// calling functions on the existing ones will result in
/// undefined behavior!
pub fn reset(&self) -> ConvertingReceiver<()> {
let payload = vec![0; 0];
self.device.set(u8::from(MasterBrickFunction::Reset), payload)
}
/// Writes 32 bytes of firmware to the bricklet attached at the given port.
/// The bytes are written to the position offset * 32.
///
/// This function is used by Brick Viewer during flashing. It should not be
/// necessary to call it in a normal user program.
pub fn write_bricklet_plugin(&self, port: char, offset: u8, chunk: [u8; 32]) -> ConvertingReceiver<()> {
let mut payload = vec![0; 34];
payload[0..1].copy_from_slice(&<char>::to_le_byte_vec(port));
payload[1..2].copy_from_slice(&<u8>::to_le_byte_vec(offset));
payload[2..34].copy_from_slice(&<[u8; 32]>::to_le_byte_vec(chunk));
self.device.set(u8::from(MasterBrickFunction::WriteBrickletPlugin), payload)
}
/// Reads 32 bytes of firmware from the bricklet attached at the given port.
/// The bytes are read starting at the position offset * 32.
///
/// This function is used by Brick Viewer during flashing. It should not be
/// necessary to call it in a normal user program.
pub fn read_bricklet_plugin(&self, port: char, offset: u8) -> ConvertingReceiver<[u8; 32]> {
let mut payload = vec![0; 2];
payload[0..1].copy_from_slice(&<char>::to_le_byte_vec(port));
payload[1..2].copy_from_slice(&<u8>::to_le_byte_vec(offset));
self.device.get(u8::from(MasterBrickFunction::ReadBrickletPlugin), payload)
}
/// Returns the UID, the UID where the Brick is connected to,
/// the position, the hardware and firmware version as well as the
/// device identifier.
///
/// The position is the position in the stack from '0' (bottom) to '8' (top).
///
/// The device identifier numbers can be found [here](device_identifier).
/// |device_identifier_constant|
pub fn get_identity(&self) -> ConvertingReceiver<Identity> {
let payload = vec![0; 0];
self.device.get(u8::from(MasterBrickFunction::GetIdentity), payload)
}
}