diff options
Diffstat (limited to 'src/event/test/CanProviderDemo.cpp')
-rw-r--r-- | src/event/test/CanProviderDemo.cpp | 259 |
1 files changed, 259 insertions, 0 deletions
diff --git a/src/event/test/CanProviderDemo.cpp b/src/event/test/CanProviderDemo.cpp new file mode 100644 index 0000000..dc51e9d --- /dev/null +++ b/src/event/test/CanProviderDemo.cpp @@ -0,0 +1,259 @@ +/**************************************************************************** +** +** Copyright (C) 2016 NVIDIA Corporation. +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt 3D Studio. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <time.h> +#include <math.h> + +#include "CanProviderDemo.h" + +CCanProviderDemo::CCanProviderDemo() + : m_Frame(0) + , m_LastClock(0) +{ +} + +CCanProviderDemo::~CCanProviderDemo() +{ +} + +unsigned short g_VehicleSpeedData[] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 6, 8, 10, 12, 14, 16, + 18, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 136, + 144, 152, 160, 168, 176, 184, 192, 200, 208, 216, 224, 232, 240, 248, 256, 264, + 272, 280, 288, 296, 304, 312, 320, 328, 336, 344, 352, 360, 368, 376, 384, 392, + 400, 408, 416, 424, 432, 440, 448, 456, 462, 468, 474, 480, 486, 492, 498, 504, + 510, 516, 522, 528, 534, 540, 546, 552, 558, 564, 570, 576, 582, 588, 594, 600, + 606, 612, 618, 624, 630, 636, 642, 648, 654, 660, 666, 672, 678, 684, 690, 696, + 702, 708, 714, 720, 726, 732, 738, 744, 750, 756, 762, 768, 774, 780, 786, 792, + 798, 804, 810, 816, 820, 824, 828, 832, 836, 840, 844, 848, 852, 856, 860, 864, + 868, 872, 876, 880, 884, 888, 892, 896, 900, 904, 908, 912, 916, 920, 924, 928, + 932, 936, 940, 944, 948, 952, 956, 960, 964, 968, 972, 976, 980, 984, 988, 992, + 996, 1000, 1004, 1008, 1012, 1016, 1020, 1024, 1028, 1032, 1036, 1040, 1044, 1048, 1052, 1056, + 1054, 1052, 1050, 1048, 1046, 1044, 1042, 1040, 1038, 1036, 1034, 1032, 1030, 1028, 1026, 1024, + 1022, 1020, 1018, 1016, 1014, 1012, 1010, 1008, 1006, 1004, 1002, 1000, 998, 996, 994, 992, + 990, 988, 986, 984, 982, 980, 978, 976, 974, 972, 970, 968, 966, 964, 962, 960, + 958, 956, 954, 952, 950, 948, 946, 944, 942, 940, 938, 936, 934, 932, 930, 928, + 926, 924, 922, 920, 918, 916, 914, 912, 910, 908, 906, 904, 902, 900, 898, 896, + 894, 892, 890, 888, 886, 884, 882, 880, 878, 876, 874, 872, 870, 868, 866, 864, + 862, 860, 858, 856, 854, 852, 850, 848, 846, 844, 842, 840, 838, 836, 834, 832, + 830, 828, 826, 824, 822, 820, 818, 816, 823, 830, 837, 844, 851, 858, 865, 872, + 879, 886, 893, 900, 907, 914, 921, 928, 935, 942, 949, 956, 963, 970, 977, 984, + 991, 998, 1005, 1012, 1019, 1026, 1033, 1040, 1047, 1054, 1061, 1068, 1075, 1082, 1089, 1096, + 1103, 1110, 1117, 1124, 1131, 1138, 1145, 1152, 1159, 1166, 1173, 1180, 1187, 1194, 1201, 1208, + 1215, 1222, 1229, 1236, 1246, 1256, 1266, 1276, 1286, 1296, 1306, 1316, 1326, 1336, 1346, 1356, + 1366, 1376, 1386, 1396, 1406, 1416, 1426, 1436, 1446, 1456, 1466, 1476, 1486, 1496, 1506, 1516, + 1526, 1536, 1546, 1556, 1566, 1576, 1586, 1596, 1606, 1616, 1626, 1636, 1646, 1656, 1666, 1676, + 1686, 1696, 1706, 1716, 1726, 1736, 1746, 1756, 1766, 1776, 1786, 1796, 1806, 1816, 1826, 1836, + 1836, 1836, 1836, 1834, 1832, 1830, 1828, 1826, 1824, 1822, 1820, 1818, 1816, 1814, 1812, 1810, + 1808, 1806, 1804, 1802, 1800, 1798, 1796, 1794, 1792, 1790, 1788, 1786, 1784, 1782, 1780, 1778, + 1776, 1774, 1772, 1770, 1768, 1766, 1764, 1762, 1760, 1758, 1756, 1754, 1752, 1750, 1748, 1746, + 1744, 1742, 1740, 1738, 1736, 1734, 1732, 1730, 1728, 1726, 1724, 1722, 1723, 1724, 1725, 1726, + 1728, 1730, 1732, 1734, 1736, 1738, 1740, 1742, 1744, 1746, 1748, 1750, 1753, 1756, 1759, 1762, + 1765, 1768, 1771, 1774, 1777, 1780, 1783, 1786, 1789, 1792, 1795, 1798, 1801, 1804, 1807, 1810, + 1813, 1816, 1819, 1822, 1825, 1828, 1831, 1834, 1837, 1840, 1843, 1846, 1849, 1852, 1855, 1858, + 1861, 1864, 1867, 1870, 1873, 1876, 1879, 1882, 1885, 1888, 1891, 1894, 1897, 1900, 1903, 1906, + 1909, 1912, 1915, 1918, 1921, 1924, 1927, 1930, 1933, 1936, 1939, 1942, 1945, 1948, 1951, 1954, + 1957, 1960, 1963, 1966, 1969, 1972, 1975, 1978, 1981, 1984, 1987, 1990, 1993, 1996, 1999, 2002, + 2005, 2008, 2011, 2014, 2017, 2020, 2023, 2026, 2029, 2032, 2035, 2038, 2041, 2044, 2047, 2050, + 2053, 2056, 2059, 2062, 2064, 2066, 2068, 2070, 2072, 2074, 2076, 2078, 2080, 2082, 2084, 2086, + 2088, 2090, 2092, 2094, 2096, 2098, 2100, 2102, 2104, 2106, 2108, 2110, 2112, 2114, 2116, 2118, + 2120, 2122, 2124, 2126, 2128, 2130, 2132, 2134, 2136, 2138, 2140, 2142, 2144, 2146, 2148, 2150, + 2152, 2154, 2156, 2158, 2160, 2162, 2164, 2166, 2168, 2170, 2172, 2174, 2176, 2178, 2180, 2182, + 2184, 2186, 2188, 2190, 2192, 2194, 2196, 2198, 2200, 2202, 2204, 2206, 2208, 2210, 2212, 2214, + 2216, 2218, 2220, 2222, 2224, 2226, 2228, 2230, 2232, 2234, 2236, 2238, 2240, 2242, 2244, 2246, + 2248, 2250, 2252, 2254, 2256, 2258, 2260, 2262, 2264, 2266, 2268, 2270, 2272, 2274, 2276, 2278, + 2280, 2282, 2284, 2286, 2288, 2290, 2292, 2294, 2296, 2298, 2300, 2302, 2301, 2300, 2299, 2298, + 2297, 2296, 2295, 2294, 2293, 2292, 2291, 2290, 2289, 2288, 2287, 2286, 2285, 2284, 2283, 2282, + 2281, 2280, 2279, 2278, 2277, 2276, 2275, 2274, 2273, 2272, 2271, 2270, 2269, 2268, 2267, 2266, + 2265, 2264, 2263, 2262, 2261, 2260, 2259, 2258, 2257, 2256, 2255, 2254, 2253, 2252, 2251, 2250, + 2249, 2248, 2247, 2246, 2245, 2244, 2243, 2242, 2239, 2236, 2233, 2230, 2227, 2224, 2221, 2218, + 2215, 2212, 2209, 2206, 2203, 2200, 2197, 2194, 2191, 2188, 2185, 2182, 2179, 2176, 2173, 2170, + 2167, 2164, 2161, 2158, 2155, 2152, 2149, 2146, 2143, 2140, 2137, 2134, 2131, 2128, 2125, 2122, + 2119, 2116, 2113, 2110, 2107, 2104, 2101, 2098, 2095, 2092, 2089, 2086, 2083, 2080, 2077, 2074, + 2071, 2068, 2065, 2062, 2058, 2054, 2050, 2046, 2042, 2038, 2034, 2030, 2026, 2022, 2018, 2014, + 2010, 2006, 2001, 1996, 1991, 1986, 1981, 1976, 1971, 1966, 1961, 1956, 1951, 1946, 1941, 1936, + 1931, 1926, 1921, 1916, 1911, 1906, 1901, 1896, 1891, 1886, 1881, 1876, 1871, 1866, 1861, 1856, + 1851, 1846, 1841, 1836, 1831, 1826, 1821, 1816, 1811, 1806, 1801, 1796, 1791, 1786, 1781, 1776, + 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, + 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, + 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, + 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1779, 1782, 1785, 1788, + 1791, 1794, 1797, 1800, 1803, 1806, 1809, 1812, 1815, 1818, 1821, 1824, 1827, 1830, 1833, 1836, + 1839, 1842, 1845, 1848, 1851, 1854, 1857, 1860, 1863, 1866, 1869, 1872, 1875, 1878, 1881, 1884, + 1887, 1890, 1893, 1896, 1899, 1902, 1905, 1908, 1911, 1914, 1917, 1920, 1923, 1926, 1929, 1932, + 1935, 1938, 1941, 1944, 1947, 1950, 1953, 1956, 1958, 1960, 1962, 1964, 1966, 1968, 1970, 1972, + 1974, 1976, 1978, 1980, 1982, 1984, 1986, 1988, 1990, 1992, 1994, 1996, 1998, 2000, 2002, 2004, + 2006, 2008, 2010, 2012, 2014, 2016, 2018, 2020, 2022, 2024, 2026, 2028, 2030, 2032, 2034, 2036, + 2038, 2040, 2042, 2044, 2046, 2048, 2050, 2052, 2054, 2056, 2058, 2060, 2062, 2064, 2066, 2068, + 2070, 2072, 2074, 2076, 2078, 2080, 2082, 2084, 2086, 2088, 2090, 2092, 2094, 2096, 2098, 2100, + 2102, 2104, 2106, 2108, 2110, 2112, 2114, 2116, 2118, 2120, 2122, 2124, 2126, 2128, 2130, 2132, + 2134, 2136, 2138, 2140, 2142, 2144, 2146, 2148, 2150, 2152, 2154, 2156, 2158, 2160, 2162, 2164, + 2166, 2168, 2170, 2172, 2174, 2176, 2178, 2180, 2182, 2184, 2186, 2188, 2190, 2192, 2194, 2196, + 2198, 2200, 2202, 2204, 2206, 2208, 2210, 2212, 2214, 2216, 2218, 2220, 2222, 2224, 2226, 2228, + 2230, 2232, 2234, 2236, 2238, 2240, 2242, 2244, 2246, 2248, 2250, 2252, 2254, 2256, 2258, 2260, + 2262, 2264, 2266, 2268, 2270, 2272, 2274, 2276, 2278, 2280, 2282, 2284, 2286, 2288, 2290, 2292, + 2294, 2296, 2298, 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, 2366, 2364, 2362, 2360, 2358, 2356, 2354, 2352, + 2350, 2348, 2346, 2344, 2342, 2340, 2338, 2336, 2334, 2332, 2330, 2328, 2326, 2324, 2322, 2320, + 2318, 2316, 2314, 2312, 2310, 2308, 2306, 2304, 2302, 2300, 2298, 2296, 2294, 2292, 2290, 2288, + 2286, 2284, 2282, 2280, 2278, 2276, 2274, 2272, 2270, 2268, 2266, 2264, 2262, 2260, 2258, 2256, + 2254, 2252, 2250, 2248, 2240, 2230, 2220, 2210, 2200, 2190, 2180, 2170, 2160, 2150, 2140, 2130, + 2120, 2110, 2100, 2090, 2080, 2070, 2060, 2050, 2040, 2030, 2020, 2010, 2000, 1990, 1980, 1970, + 1960, 1950, 1940, 1930, 1920, 1910, 1900, 1890, 1880, 1870, 1860, 1850, 1840, 1830, 1820, 1810, + 1800, 1790, 1780, 1770, 1760, 1750, 1740, 1730, 1720, 1710, 1700, 1690, 1680, 1670, 1660, 1650, + 1645, 1640, 1635, 1630, 1625, 1620, 1615, 1610, 1605, 1600, 1595, 1590, 1585, 1580, 1575, 1570, + 1565, 1560, 1555, 1550, 1545, 1540, 1535, 1530, 1525, 1520, 1515, 1510, 1505, 1500, 1495, 1490, + 1485, 1480, 1475, 1470, 1465, 1460, 1455, 1450, 1445, 1440, 1435, 1430, 1425, 1420, 1415, 1410, + 1405, 1400, 1395, 1390, 1385, 1380, 1375, 1370, 1365, 1360, 1355, 1350, 1345, 1340, 1335, 1330, + 1325, 1320, 1315, 1310, 1305, 1300, 1295, 1290, 1285, 1280, 1275, 1270, 1265, 1260, 1255, 1250, + 1245, 1240, 1235, 1230, 1225, 1220, 1215, 1210, 1205, 1200, 1195, 1190, 1185, 1180, 1175, 1170, + 1165, 1160, 1155, 1150, 1145, 1140, 1135, 1130, 1125, 1120, 1115, 1110, 1105, 1100, 1090, 1088, + 1086, 1084, 1082, 1080, 1078, 1076, 1074, 1072, 1070, 1065, 1060, 1055, 1050, 1045, 1040, 1035, + 1030, 1025, 1020, 1015, 1010, 1005, 1000, 995, 990, 985, 980, 975, 970, 965, 960, 955, + 950, 945, 940, 935, 930, 925, 920, 915, 910, 905, 900, 895, 890, 885, 880, 875, + 870, 865, 860, 855, 850, 845, 840, 835, 830, 825, 820, 815, 810, 805, 800, 795, + 790, 785, 780, 775, 772, 769, 766, 763, 760, 757, 754, 751, 748, 745, 742, 739, + 736, 733, 730, 727, 724, 721, 718, 715, 712, 709, 706, 703, 700, 697, 694, 691, + 688, 685, 682, 679, 676, 673, 670, 667, 664, 661, 658, 655, 652, 649, 646, 643, + 640, 637, 634, 631, 628, 625, 622, 619, 616, 613, 610, 607, 604, 601, 598, 595, + 597, 599, 601, 603, 605, 607, 609, 611, 613, 615, 617, 619, 621, 623, 625, 627, + 629, 631, 633, 635, 637, 639, 641, 643, 645, 647, 649, 651, 653, 655, 657, 659, + 661, 663, 665, 667, 669, 671, 673, 675, 677, 679, 681, 683, 685, 687, 689, 691, + 693, 695, 697, 699, 701, 703, 705, 707, 709, 711, 713, 715, 715, 715, 715, 715, + 715, 715, 715, 715, 715, 715, 715, 715, 715, 715, 715, 715, 715, 715, 715, 715, + 715, 715, 715, 715, 715, 715, 715, 715, 715, 715, 715, 715, 715, 715, 715, 715, + 715, 715, 715, 715, 715, 715, 715, 715, 715, 715, 715, 715, 715, 715, 715, 715, + 715, 715, 715, 715, 715, 715, 715, 715, 710, 705, 700, 695, 690, 685, 680, 675, + 670, 665, 660, 655, 650, 645, 640, 635, 630, 625, 620, 615, 610, 605, 600, 595, + 590, 585, 580, 575, 570, 565, 560, 555, 550, 545, 540, 535, 530, 525, 520, 515, + 510, 505, 500, 495, 490, 485, 480, 475, 470, 465, 460, 455, 450, 445, 440, 435, + 430, 425, 420, 415, 417, 419, 421, 423, 425, 427, 429, 431, 433, 435, 437, 439, + 441, 443, 445, 447, 449, 451, 453, 455, 457, 459, 461, 463, 465, 467, 469, 471, + 473, 475, 477, 479, 481, 483, 485, 487, 489, 491, 493, 495, 497, 499, 501, 503, + 505, 507, 509, 511, 513, 515, 517, 519, 521, 523, 525, 527, 529, 531, 533, 535, + 536, 532, 528, 524, 520, 516, 512, 508, 504, 500, 496, 492, 488, 484, 480, 476, + 472, 468, 464, 460, 456, 452, 448, 444, 440, 436, 432, 428, 424, 420, 416, 412, + 408, 404, 400, 396, 392, 388, 384, 380, 376, 372, 368, 364, 360, 356, 352, 348, + 344, 340, 336, 332, 328, 324, 320, 316, 312, 308, 304, 300, 295, 290, 285, 280, + 275, 270, 265, 260, 255, 250, 245, 240, 235, 230, 225, 220, 215, 210, 205, 200, + 195, 190, 185, 180, 175, 170, 165, 160, 155, 150, 145, 140, 135, 130, 125, 120, + 115, 110, 105, 100, 95, 90, 85, 80, 75, 70, 65, 60, 55, 50, 45, 40, + 35, 30, 25, 20, 15, 10, 5, 0 +}; + +Qt3DSEventSystemEvent *CCanProviderDemo::GetNextEvent(IEventFactory &inFactory) +{ + clock_t theCurClock = clock(); + if (theCurClock > m_LastClock + && (theCurClock - m_LastClock) / (CLOCKS_PER_SEC / 1000) < 1000 / 6) + return 0; + m_LastClock = theCurClock; + unsigned char theLength = 0; + unsigned char theData[8]; + theData[0] = 81; +#define SIN_SAMPLE(s, m) ((sin((float)s) / 2 + 0.5) * m) + switch (rand() % 2) { + case 0: + theData[1] = 1; + { // Vehicle speed + int theIndex = m_Frame % (sizeof(g_VehicleSpeedData) / sizeof(g_VehicleSpeedData[0])); + theData[2] = (unsigned short)(g_VehicleSpeedData[theIndex] * 0.06) >> 8; + theData[3] = (unsigned char)(g_VehicleSpeedData[theIndex] * 0.06); + } + { + unsigned short theOdo = m_Frame; + theData[4] = theOdo >> 8; + theData[5] = (unsigned char)theOdo; + } + theLength = 6; + break; + case 1: + theData[1] = 2; + { + unsigned short theTrip = m_Frame; + theData[2] = theTrip >> 8; + theData[3] = (unsigned char)theTrip; + } + { + unsigned short theCoolant = (unsigned char)SIN_SAMPLE(m_Frame / 170, 300); + theData[4] = theCoolant >> 8; + theData[5] = (unsigned char)theCoolant; + } + theLength = 6; + break; + default: + return 0; + } + ++m_Frame; + Qt3DSEventSystemEvent &theEvent = inFactory.CreateEvent(9); + Qt3DSEventSystemEventData *theCurrentData = theEvent.m_Data; + theCurrentData->m_Name = inFactory.RegisterStr("device_type"); + theCurrentData->m_Value.m_Type = QT3DSEventSystemEventTypesString; + theCurrentData->m_Value.m_String = inFactory.AllocateStr("CAN"); + ++theCurrentData; + theCurrentData->m_Name = inFactory.RegisterStr("id"); + theCurrentData->m_Value.m_Type = QT3DSEventSystemEventTypesNumber; + theCurrentData->m_Value.m_Number = 101; + ++theCurrentData; + theCurrentData->m_Name = inFactory.RegisterStr("length"); + theCurrentData->m_Value.m_Type = QT3DSEventSystemEventTypesNumber; + theCurrentData->m_Value.m_Number = 6; + ++theCurrentData; + for (int i = 0; i < theLength; ++i) { + theCurrentData->m_Name = inFactory.RegisterStr("data"); + theCurrentData->m_Value.m_Type = QT3DSEventSystemEventTypesNumber; + theCurrentData->m_Value.m_Number = theData[i]; + ++theCurrentData; + } + + return &theEvent; +} + +size_t CCanProviderDemo::GetNextEvents(IEventFactory &inFactory, Qt3DSEventSystemEvent **outBuffer, + size_t bufLen) +{ + size_t bufIdx = 0; + Qt3DSEventSystemEvent *evt = NULL; + for (evt = GetNextEvent(inFactory); evt && bufIdx < bufLen; + evt = GetNextEvent(inFactory), ++bufIdx) + outBuffer[bufIdx] = evt; + return bufIdx; +} + +void CCanProviderDemo::Release() +{ + delete this; +} |