mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-06-19 21:12:04 +08:00
Compare commits
955 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 86e7c5d5b6 | |||
| 9062391a9c | |||
| 6f7bf752cd | |||
| 450e6001a7 | |||
| 92c4111bdd | |||
| 2c11113671 | |||
| 5e341385cb | |||
| 4adf4d138e | |||
| 995af1de45 | |||
| 399cdf4e4a | |||
| e8c7da8f4e | |||
| fe0ed57f45 | |||
| affe1c3d2c | |||
| 8a816ea8e1 | |||
| b2c0070a7b | |||
| a2d6b0241f | |||
| 98d2907a35 | |||
| 70e315f14a | |||
| 2a77b02bd8 | |||
| dc8d7e3939 | |||
| 53f3688e4a | |||
| 9ec47b48bd | |||
| d44e8b5d3b | |||
| 48edf7f7d7 | |||
| cf0e7d4a92 | |||
| 70df20f749 | |||
| d2a92fcbe3 | |||
| 9e1db5ee4a | |||
| c9a3e8f8bc | |||
| 45399cc201 | |||
| 12df763d61 | |||
| c065bc1a01 | |||
| df40837f48 | |||
| 8db3fa8caf | |||
| aba77b1163 | |||
| 4097231dcb | |||
| 56742acbd4 | |||
| 72ba044226 | |||
| 7a2addf782 | |||
| 63cee44949 | |||
| b1e698ee82 | |||
| c6f324d407 | |||
| 23250ba37f | |||
| aa89df14b8 | |||
| 969c3c1e05 | |||
| 23dfde1ce7 | |||
| d953b6a7aa | |||
| 26dd7e27c8 | |||
| 1447a3b458 | |||
| 0dc120f4d8 | |||
| 8db70980fa | |||
| 91bbd7c28f | |||
| df432c5e2e | |||
| 02d6549fa7 | |||
| 0302835853 | |||
| 5581835f79 | |||
| 7030de2a82 | |||
| 4065e9360c | |||
| 0d02fbe2ec | |||
| 33386b6365 | |||
| 8fd9ff49f4 | |||
| 5a2bc4f616 | |||
| 50d8771c29 | |||
| fd839b7614 | |||
| 33393412f8 | |||
| bfd61871d4 | |||
| 45bb3350e1 | |||
| 8ab6b4313b | |||
| 853c1c24fb | |||
| 7b4602907e | |||
| 6291d6c31a | |||
| 70d17cd69b | |||
| be9e6fa698 | |||
| d21b783199 | |||
| e450d8a4fb | |||
| 07c8465c2b | |||
| 069e337bea | |||
| 6b62dd2308 | |||
| 4ff7da61e0 | |||
| 686d4bbdc2 | |||
| 08d86aa7d7 | |||
| 8b3aa6f561 | |||
| 973bdc4318 | |||
| 1d38e040c9 | |||
| aa58f52db3 | |||
| 62fbb6302a | |||
| be1376ecd2 | |||
| 38a9cf9489 | |||
| a7602eae5e | |||
| adf8e823b9 | |||
| 9636661da4 | |||
| 071457dc9e | |||
| dc77d4a88e | |||
| f1e26b346f | |||
| 6c1fa5dc3a | |||
| 7b8bd9e3ff | |||
| b8557616dd | |||
| cf80f7a28b | |||
| 3a04a69cbe | |||
| f2de9784f8 | |||
| d17745fb5e | |||
| 3a006aa99e | |||
| e8084fd9dd | |||
| e5281a98fa | |||
| 99fdd691a3 | |||
| 037727cd62 | |||
| 22b5eb0e06 | |||
| 236a05f2ad | |||
| 8ef944eceb | |||
| 01e62f49dc | |||
| 5c4701d035 | |||
| 38ce7dae51 | |||
| 7d8ba56cda | |||
| 9c7e8aa391 | |||
| ca1903a3c0 | |||
| d20b63c909 | |||
| ef4b2d32d2 | |||
| 1bc51d6b47 | |||
| f875296a4a | |||
| fbb5860e9f | |||
| 2074e530e0 | |||
| 6edc36181a | |||
| a0b41e6cf9 | |||
| d1923f7dc6 | |||
| 03589f71e5 | |||
| b47ca2543e | |||
| 5a8bff7f56 | |||
| 701bdf0b4a | |||
| c1c40321b6 | |||
| f165fed722 | |||
| 145319bcd3 | |||
| c7b9d28232 | |||
| 2e73e55e97 | |||
| 2e0dc8cdc0 | |||
| 26b063f60f | |||
| 0ebdd0731f | |||
| 6573a67742 | |||
| 32adcf1591 | |||
| 7b7be6975a | |||
| 377038642c | |||
| dc76fb165e | |||
| 951b5c695a | |||
| 01542c4a19 | |||
| b88362d508 | |||
| 2463873b14 | |||
| 39d527fa5b | |||
| 7bfdd09dc1 | |||
| 8a392c7c2e | |||
| da8706ec07 | |||
| 066d88e754 | |||
| 47e87baa60 | |||
| 36924194ad | |||
| 99149ebfb1 | |||
| 5cfc0be5cb | |||
| 41d0a8957a | |||
| 67d3494b30 | |||
| 881178d542 | |||
| 0042b3d64e | |||
| cd87c50753 | |||
| 35666b24f3 | |||
| 259e6ecf49 | |||
| 58f376002e | |||
| eb3cd1efc5 | |||
| 284fe1f2b1 | |||
| baf9ab37c2 | |||
| 82160eb2e4 | |||
| f4546ba8d4 | |||
| 2509a1e753 | |||
| 71886e2be6 | |||
| 10d3b8aa90 | |||
| 0441cf139c | |||
| 4eb316c291 | |||
| a75abd788b | |||
| 436640c108 | |||
| 11d6583b62 | |||
| a71307229f | |||
| b318162e6a | |||
| 3826cf23d2 | |||
| 8a6dfb05ab | |||
| d3becbacdd | |||
| 7700b6aa59 | |||
| 634ee8746a | |||
| 8a2b649f22 | |||
| a5c9f571ce | |||
| cd00c32dbc | |||
| f5113edc50 | |||
| a65f57fac5 | |||
| 995cd1aa65 | |||
| dd9e649296 | |||
| 5e7cb5de3c | |||
| afb5d372fd | |||
| ee28ef1ae4 | |||
| e7b2a98fe3 | |||
| 6813559bbe | |||
| 33926ee432 | |||
| 04fd1f4e6c | |||
| ebfd786af0 | |||
| 9c7ae433ec | |||
| 10cd4c0bd2 | |||
| 7e8618dc9d | |||
| c68503d8a1 | |||
| 14b0c9427d | |||
| b0563a5968 | |||
| 44fc1767fd | |||
| 61229779e4 | |||
| af4f9f1f31 | |||
| 4dc51cfea6 | |||
| f274a8e3b0 | |||
| 97ed349d04 | |||
| 9affab1f27 | |||
| b14f39b2c8 | |||
| 69780971aa | |||
| 0105342caf | |||
| 8c442ec989 | |||
| c29f96069e | |||
| 781c392a22 | |||
| 23f142bcf0 | |||
| da42760e55 | |||
| fd86f04e82 | |||
| df85e66a6d | |||
| 49eec4cab3 | |||
| f2648fd12f | |||
| d50811859a | |||
| c1f03ce883 | |||
| 7ce952e165 | |||
| d1e95be073 | |||
| 04a7dd2633 | |||
| 6168ce1ef9 | |||
| 836a836f0d | |||
| 50d5e988e8 | |||
| f5a7e06770 | |||
| f6322f0262 | |||
| 91be9e9fa9 | |||
| 49c488a79e | |||
| 34b85671d1 | |||
| be5366787b | |||
| 4ac4dd57e9 | |||
| 3b66e6a9c4 | |||
| d45a88d5cd | |||
| 80e24f2051 | |||
| 80a8817048 | |||
| 4151d1526e | |||
| 0de789a7cb | |||
| 38ab273163 | |||
| f6531a9d08 | |||
| 0f571e8a4e | |||
| 9567d75d1c | |||
| bb182edec0 | |||
| 6d76ef3ef0 | |||
| 4365be9056 | |||
| b5c5e04d4b | |||
| f61add3913 | |||
| c73464f67f | |||
| 9050903cee | |||
| 85bc608675 | |||
| 2ccdc68ca9 | |||
| 24ca97d828 | |||
| 751aa5cf7e | |||
| e05df8f0fc | |||
| 5c059504ed | |||
| c187ea5986 | |||
| 4d5d709bea | |||
| 9833c901e6 | |||
| 194081b0f1 | |||
| 5af0f2748c | |||
| 29d25df7a6 | |||
| ca0fd6fe8a | |||
| 151e45c9cd | |||
| 33ff1c9783 | |||
| c7c29cac6f | |||
| f6d402c1e7 | |||
| 96041f0dbe | |||
| c1cf70fd3a | |||
| 9fc0107636 | |||
| e3a19a2458 | |||
| 001f45b3a9 | |||
| 472f55faa8 | |||
| 4315386cfe | |||
| 00caf953fa | |||
| 7fd9e33cb4 | |||
| 1b09ac739e | |||
| 252c0fd86d | |||
| f4e4ae6508 | |||
| cc203dc17e | |||
| 2765a7fadc | |||
| be9736c796 | |||
| 59686c07db | |||
| 8ec9cdf607 | |||
| 4bed6f6bfc | |||
| 7eb487ae30 | |||
| b6a00be9f1 | |||
| 868078fe36 | |||
| 043ed96294 | |||
| 7b9a314093 | |||
| 4221d3b985 | |||
| 73d345cd24 | |||
| bb9e4cb7c2 | |||
| 9865597b4a | |||
| 6c167f5ef9 | |||
| c18067d705 | |||
| a5dc451697 | |||
| cdfb4101be | |||
| 0dc8b03f07 | |||
| 504f43ea4b | |||
| d0deb8d9d2 | |||
| 5772b681d0 | |||
| 5f394317b5 | |||
| 5b296967eb | |||
| d5f9caa82d | |||
| 6a61788682 | |||
| ead59a5a61 | |||
| a1f069c6d8 | |||
| 6d8174e89f | |||
| f4946a9e9d | |||
| fd79368f3b | |||
| d2cfd239d5 | |||
| 2861467183 | |||
| d478d6a931 | |||
| dc77655e2a | |||
| f5d88c5813 | |||
| 095ef5f9f6 | |||
| fd71fe698c | |||
| d5242c5b82 | |||
| 1f1893a170 | |||
| 043d2e9f36 | |||
| 3f78957ccc | |||
| 8bcb9331fd | |||
| 5808958fb2 | |||
| af3234f1d7 | |||
| e2ff61da9b | |||
| 80e87ee0ae | |||
| bcb3f6077c | |||
| 87679a75b8 | |||
| c6c41f1a29 | |||
| 5d57078474 | |||
| 11229fc9c0 | |||
| 1727b59882 | |||
| e90c41c576 | |||
| aa1b61eb8e | |||
| 98cd6147c3 | |||
| d22636b194 | |||
| a440425ef8 | |||
| 0ecaf72ed4 | |||
| 3300143b1b | |||
| 902413200a | |||
| ce57ac073b | |||
| 91bf49bdd4 | |||
| 017cbbfa51 | |||
| 8773fbf7d9 | |||
| 8d4ff30c60 | |||
| be2ba93ca0 | |||
| 48425a1fc1 | |||
| 84c8790192 | |||
| 25681a31e5 | |||
| 61bbb52172 | |||
| c9270bfa2f | |||
| 0a7d2f4343 | |||
| dc6107dac3 | |||
| 5eacdcee9d | |||
| 978839a861 | |||
| fbc243aa94 | |||
| cf5c4aeacb | |||
| 194d4d7f71 | |||
| 5b596aec6f | |||
| 09533fee0c | |||
| 6ee6161d23 | |||
| 4e16a1454d | |||
| d0bdd513cd | |||
| 54b920eb79 | |||
| 94053536b4 | |||
| cd98235644 | |||
| c8b4633cd1 | |||
| 53413fa019 | |||
| e453e79bc8 | |||
| b02e848395 | |||
| ed9d5615ba | |||
| 8264fd8b93 | |||
| 532e7710f3 | |||
| 63da1abe2c | |||
| 62bd6cee67 | |||
| e8af5d6364 | |||
| 386ec39885 | |||
| 2a99c660c3 | |||
| be28530ee4 | |||
| 15cb2f05c7 | |||
| 3595162d1a | |||
| 8e97f70b92 | |||
| a9a35894ad | |||
| c3a1a438d8 | |||
| 13bdfcdd95 | |||
| 9675794969 | |||
| 151a504507 | |||
| 99da7077ab | |||
| 3d941253a5 | |||
| 03e764bcb3 | |||
| 0d41146fa8 | |||
| 7f04682b4c | |||
| a6545b1604 | |||
| 2db4cb0e8c | |||
| 26d0b8d4ee | |||
| 323660961f | |||
| 88966b488a | |||
| 41fc9c55a0 | |||
| 8c2b3d5e37 | |||
| 22fc7e9dae | |||
| 9f53e446d9 | |||
| 7e0ba31ceb | |||
| fe46b24be5 | |||
| a9e94ef9bb | |||
| c9db3ef937 | |||
| 9a3dc91b35 | |||
| c5e71d2f37 | |||
| 61ce864e28 | |||
| 36d0a70b69 | |||
| 20a2007d10 | |||
| 64701acb68 | |||
| 17922bd096 | |||
| f85055a19c | |||
| 28ebecdbc5 | |||
| 16eb74250c | |||
| 4a48ef8dbc | |||
| 5eda5fc81b | |||
| 76ab558ca6 | |||
| 60a20537c5 | |||
| 71e65750d1 | |||
| 2ce741275b | |||
| 8cb09e1329 | |||
| 17f21c5b6f | |||
| 0992311f83 | |||
| a42fea2041 | |||
| 4aaf4f437b | |||
| 610bb58845 | |||
| 4c77b9162e | |||
| cd096d1c2e | |||
| 11a7b2d9bf | |||
| be020bdedb | |||
| 1e77f2482c | |||
| 7fa09edc03 | |||
| 13ae651f46 | |||
| c345bb1d8f | |||
| a2b00731cb | |||
| d36b78e273 | |||
| 6ab7c27d9b | |||
| a90c3bc8be | |||
| 8b3c922cf0 | |||
| d460e0e735 | |||
| a52b947ce2 | |||
| c75137b262 | |||
| 6fd3f9bad8 | |||
| d8da18ed54 | |||
| 6abd80f116 | |||
| f4b258a082 | |||
| 8a9ed94f5f | |||
| ae44a57565 | |||
| b93f77ea0e | |||
| 983120bfed | |||
| 27803e787b | |||
| 6651d50c81 | |||
| f64c4df8c8 | |||
| 00c48f0ba3 | |||
| f78b6fdd17 | |||
| 7c537ee201 | |||
| e2d77db22a | |||
| bf5e361b26 | |||
| a7ad4488b9 | |||
| f7fbcfe59d | |||
| 1efed2ed00 | |||
| 15c43ad722 | |||
| 5fcbfcc359 | |||
| 672d80735f | |||
| 2f5e35035d | |||
| 1aafc5b0ef | |||
| 9f66b533e2 | |||
| 1883bd6135 | |||
| 1ba6b0004d | |||
| 68b86c7ca8 | |||
| 65a8f13d98 | |||
| 9a4eb3e0b0 | |||
| 3148499f69 | |||
| 36881b6410 | |||
| fe7e5cf5df | |||
| d8b1588937 | |||
| a2f4d6b5ad | |||
| 16d0c4a3e7 | |||
| dca99bea38 | |||
| 392cf59937 | |||
| dd34ccfe28 | |||
| 59bd6b8837 | |||
| f91df07d3f | |||
| 0829b0a767 | |||
| 1e8098c140 | |||
| b5a88f5700 | |||
| 0bf4dbc3b0 | |||
| c0a3e48d94 | |||
| 65e1342e41 | |||
| 7ada2abca0 | |||
| 9278fad15c | |||
| 0aa41e348e | |||
| 64a6e9776c | |||
| 56b2945de4 | |||
| b686ca87d3 | |||
| 1b3b260b4d | |||
| 25d43fe15e | |||
| cbc73e55a2 | |||
| 0a94454812 | |||
| 9b31da0985 | |||
| 2a698bf73e | |||
| 64e6706a0b | |||
| 18e80ea755 | |||
| af7e33bae8 | |||
| 484fa1ac63 | |||
| 3f9059fea8 | |||
| 52e55eb244 | |||
| ec36bc3a39 | |||
| 603af161fd | |||
| 98797fb24e | |||
| 42906ef1ae | |||
| 127998ca8b | |||
| 1da59216b0 | |||
| 184ba93833 | |||
| c9a9d8bd97 | |||
| a321836788 | |||
| f5044670fa | |||
| 340e0f4a4c | |||
| d8b1e99d77 | |||
| 2eebe49940 | |||
| 91f0b5c6cd | |||
| e0eccb87b5 | |||
| 9dae0bfac4 | |||
| 5b8976af61 | |||
| 2f92d577f9 | |||
| 790732bea3 | |||
| 7834995df4 | |||
| 0a7fed9437 | |||
| a201322160 | |||
| d64025cca4 | |||
| 58d645cd18 | |||
| 76dfb135ca | |||
| 185375ed64 | |||
| a7cf5c2cbb | |||
| 7978afabe5 | |||
| e89fd1236f | |||
| bdf6585650 | |||
| 4662cfc8d7 | |||
| dd32343342 | |||
| 1efa3f0eba | |||
| 5fe6367d08 | |||
| ca2f30989d | |||
| 03f09105c6 | |||
| 5a9d89ed42 | |||
| 99ba8c8cc8 | |||
| 88213d0cfd | |||
| f74a201edc | |||
| be5c2aef3a | |||
| ede869e34a | |||
| 113d4c1b70 | |||
| 66f2a6fe01 | |||
| 365f3bd4dc | |||
| a85488fbb8 | |||
| c5933c9d8d | |||
| 27e0adc434 | |||
| 4697568e67 | |||
| 21a24446db | |||
| 26cc816c1b | |||
| 6c1f516bb3 | |||
| de0ea4820c | |||
| 26e60a6b4b | |||
| 737f2ace69 | |||
| e7d4197a08 | |||
| 0db8d26c12 | |||
| f0203614ee | |||
| 8b7dfb647f | |||
| 15fa6664c0 | |||
| 26c583b5c4 | |||
| 181dba4514 | |||
| 5f5698900c | |||
| 1d0dc50f98 | |||
| 5c8aa7295d | |||
| 2890a4ede8 | |||
| 882eaf15bf | |||
| 6fba167ef9 | |||
| 65b8466f22 | |||
| 9c3ec2fd2d | |||
| a1d96b4d8a | |||
| 57bca3c658 | |||
| 40422ea5d6 | |||
| 0207a97040 | |||
| fdb04d9f69 | |||
| 27f405bb6f | |||
| 26da755a1e | |||
| 7017f8ebf0 | |||
| 19660515b5 | |||
| d1fe6a9667 | |||
| c227f977e6 | |||
| b9cf00f4ce | |||
| d192b4fa8f | |||
| f760fa00ae | |||
| 88246af4c7 | |||
| 03f13e614b | |||
| 83cbf29588 | |||
| 022b058bc5 | |||
| 23512ba932 | |||
| f789be8485 | |||
| ee35b905d7 | |||
| 8310b01530 | |||
| d2f755286c | |||
| 8fbcaf423e | |||
| 2c9d5afd75 | |||
| 860623f157 | |||
| 73c1df714d | |||
| 6ff384ba3f | |||
| 9e2be16440 | |||
| 5dfc758d33 | |||
| b967da5fc1 | |||
| f364a3ee8f | |||
| ece9cf9480 | |||
| d5f8643e7c | |||
| 9cf542d7f7 | |||
| 9eb1666a52 | |||
| b78ed77f1d | |||
| d84e64b315 | |||
| 0fded2c08b | |||
| 67e7f6dc3d | |||
| 4d2ff103d6 | |||
| 58e716ff48 | |||
| f41cb3b4ec | |||
| b5d8230c3d | |||
| 853bcda352 | |||
| 4610a6e4d4 | |||
| 14894b4b66 | |||
| fdccc48bf7 | |||
| 067f1bfe9e | |||
| 8e491aaf58 | |||
| c46d931f40 | |||
| e3c934bcc1 | |||
| 6c3468b02f | |||
| d398ba2c62 | |||
| 8e346aa668 | |||
| 989f3c5ecc | |||
| 5806c90a3e | |||
| 2c081208eb | |||
| ef64a1bf5f | |||
| 278ce557da | |||
| 210db686bb | |||
| 573a6915fc | |||
| dc331df1fc | |||
| 5c4ae7a2fc | |||
| 29bea62ac1 | |||
| 024870d16a | |||
| 5ff4ff176b | |||
| 68e56c8017 | |||
| 9d76070ab7 | |||
| 87b02db857 | |||
| 6ec0d23b7a | |||
| c0929d6954 | |||
| c9dd7fe0e6 | |||
| 8ca37f5d44 | |||
| e32463ee96 | |||
| f43e347fbf | |||
| 32003bd048 | |||
| a326b4b4cd | |||
| bf1368b4cf | |||
| 53c6ca6589 | |||
| e4ed48928b | |||
| c3d5b9d62e | |||
| d5916b92d5 | |||
| b94d598c2d | |||
| 860a48765d | |||
| 92c596544d | |||
| 3e78efacca | |||
| 3b744f4fba | |||
| 91dd484c27 | |||
| b4dd562c43 | |||
| bfaf9e6f66 | |||
| 30eb131980 | |||
| 24d0084938 | |||
| a7cadcc390 | |||
| 8cfdc1cbc2 | |||
| 88dd52414f | |||
| 0b21c835a4 | |||
| 81f3709a9f | |||
| f6214eb932 | |||
| 892e14aa92 | |||
| de3e265b36 | |||
| 8b7c726bea | |||
| 3239f78e69 | |||
| d27257bbbb | |||
| 4631a7e81f | |||
| 53f2722a3d | |||
| 0d62ee7598 | |||
| db24b1e838 | |||
| 1efeded724 | |||
| 7db592d3b8 | |||
| b7c029c92c | |||
| fdbf1c5938 | |||
| 29aaade7ab | |||
| f7f91aec22 | |||
| 00429e6bbb | |||
| 2f8034b2ec | |||
| 1d4c811611 | |||
| 5501541aa2 | |||
| 421fe728f1 | |||
| 9683bccaf6 | |||
| 666826198f | |||
| fcbb07b1a0 | |||
| 3d05cca678 | |||
| 195139999b | |||
| 9e067e91ee | |||
| c675c28356 | |||
| f2f7e8d516 | |||
| c9fa92b377 | |||
| 8237b60749 | |||
| 7405041b42 | |||
| dfa7757c40 | |||
| 4bc57a9792 | |||
| 8f3539a27b | |||
| e8ae37e36e | |||
| a2c76acf3b | |||
| 7ed5c6554d | |||
| 851d6f1b96 | |||
| 4eeaaf1b08 | |||
| 5641fc986d | |||
| c499aa549c | |||
| 243f10d5fb | |||
| 0a99fe3baa | |||
| 837809774b | |||
| 8cc32df779 | |||
| 2100e46b60 | |||
| 8291f35701 | |||
| 0f885c87a5 | |||
| c7f9c1bd69 | |||
| a422246dc3 | |||
| e5b2ec4f01 | |||
| 97f1ee4a0d | |||
| 2d450bc3a8 | |||
| 96c923875b | |||
| 14b7eadf63 | |||
| 574fabf9ca | |||
| 402faabd42 | |||
| 00def2849c | |||
| 9df9019c1e | |||
| c818b6ada3 | |||
| be750af7ff | |||
| f8752fbe2c | |||
| fbbfcc5a74 | |||
| 67ccfb11c7 | |||
| 31d9f18fca | |||
| 02b6a7a82b | |||
| de79a07745 | |||
| 4b2c137489 | |||
| b3654cbcc9 | |||
| 3103b9bfea | |||
| d2b8c4f0cb | |||
| 50d9c446cf | |||
| 6eb1247426 | |||
| faea9a42c4 | |||
| 86813e6d37 | |||
| 012727ef60 | |||
| fb470830ed | |||
| 9653f9d6a6 | |||
| a988911e05 | |||
| 9abe003d1d | |||
| 81477e857a | |||
| 67669174f0 | |||
| 285c52eb69 | |||
| 8f6e36f426 | |||
| f0c5ca7227 | |||
| e0d7ce9e57 | |||
| 8970cc8d70 | |||
| ec975a36cd | |||
| 65ca70c731 | |||
| 3dffd9a942 | |||
| 547c9eaad0 | |||
| 54f3c2b373 | |||
| 40c70cc865 | |||
| 112c02991d | |||
| bdc16ce545 | |||
| 5c041d3b78 | |||
| 97949b12b3 | |||
| fabf747d74 | |||
| 41b7ba1092 | |||
| f86b42cd81 | |||
| 3d0859dc39 | |||
| 1ad1340b58 | |||
| 05231722e5 | |||
| 2c4e1fd4fa | |||
| 401c4026ac | |||
| 22f0a89cf8 | |||
| b942ab58e1 | |||
| c29b311583 | |||
| ed72759a48 | |||
| 0129a8a4ff | |||
| db96b4b912 | |||
| b70d75d1d0 | |||
| 6a02547b42 | |||
| 33a75c3506 | |||
| 2cfdc67610 | |||
| 6f3d10a4c4 | |||
| 589b6187a1 | |||
| 6b1efbf185 | |||
| b63d51d3ef | |||
| e07853bb5e | |||
| 866711ef2e | |||
| ef8e6fb39f | |||
| 4568504c41 | |||
| 18c6482545 | |||
| b0c83bb9a6 | |||
| ce57ce4898 | |||
| 7d9f8c55e0 | |||
| 04c26981f0 | |||
| 7f6ea03066 | |||
| de33bc4645 | |||
| e9ad7793f0 | |||
| 4bdf3b95f3 | |||
| 504d00353d | |||
| ce67c75f1f | |||
| 95509a58cd | |||
| 21b3f5321a | |||
| b75d606c91 | |||
| ca3e1ce9b0 | |||
| 58744df1c5 | |||
| 1181a00fe9 | |||
| 35b08e1e3d | |||
| fd2bead226 | |||
| ae5cb7a0da | |||
| e3ab9d6460 | |||
| c210011c84 | |||
| 2751d87d01 | |||
| 8849aa02a3 | |||
| f49e9f4f09 | |||
| f0a6db351e | |||
| 53b177b3c1 | |||
| c6df34f55b | |||
| 28e3543ec4 | |||
| 7865525451 | |||
| 4a5019d925 | |||
| 1b7b3b4e66 | |||
| 37285038d3 | |||
| 91a731f2ae | |||
| e41761eb1b | |||
| 9a9ff839a9 | |||
| 4f7336f0e4 | |||
| 94a27e351f | |||
| 28b8043c5b | |||
| 78df63a6af | |||
| d0c9cd28d1 | |||
| 9e1cabde36 | |||
| c7cd8b4459 | |||
| 3d628a6fe2 | |||
| 51fad4a6c6 | |||
| a70a821d28 | |||
| 013351a2ee | |||
| ad3f0a348a | |||
| 9a411ebf32 | |||
| 19010d3766 | |||
| 02968cda63 | |||
| 650c45dcc5 | |||
| 93f55f3ccf | |||
| 569db3c1d2 | |||
| 26d97d3374 | |||
| 3acfa1b39b | |||
| bbc67f8506 | |||
| 8343b56870 | |||
| 008d900f81 | |||
| 32e5d6cd15 | |||
| 28c0797d30 | |||
| a701aa7292 | |||
| 433f934783 | |||
| 0dc6778548 | |||
| c86b52698b | |||
| e5e5aa7ded | |||
| 4474b9b371 | |||
| 26e966852c | |||
| 75ac92b90f | |||
| b68f3f7781 | |||
| 36bef17224 | |||
| 715771bcff | |||
| 8e264baaa2 | |||
| 8ff147de6d | |||
| 71057c586f | |||
| fac22f4038 | |||
| 40094779d7 | |||
| 2552aa45c3 | |||
| c2972a80f9 | |||
| 791a440709 | |||
| 13145dd9a7 | |||
| e9c477dcf2 | |||
| 8eebd19884 | |||
| a54b35a4d6 | |||
| 8a6f7a5e78 | |||
| 6752959d4a | |||
| da52d065a4 | |||
| b731b7cf12 | |||
| ef3d8314d3 | |||
| 7ef3fd567f | |||
| b773e27ad1 | |||
| a77c0a1098 | |||
| c7b5fb9116 | |||
| b8085e2c42 | |||
| 14fb17e22f | |||
| a34c87ab46 | |||
| 1ad9cc8c67 | |||
| 5627d0d7fd | |||
| 2cfdbefde8 | |||
| 7dabcdace8 | |||
| 187a70f760 | |||
| 48303589e9 | |||
| 8385b27cad | |||
| abd75aedd7 | |||
| daf54ad54d | |||
| 94fe677f91 | |||
| 3de85098e5 | |||
| 5524dc8773 | |||
| 19dd5f3e32 | |||
| 99cb610b12 | |||
| 9d3963559a | |||
| 1b8c44b506 | |||
| 6f46f988d9 | |||
| 68485aa4e4 | |||
| 1581fdc198 | |||
| 317ae0fb37 | |||
| 5bf4196aed | |||
| 38aa03e0f7 | |||
| 9a9dc3ab23 | |||
| e4aa959e2c | |||
| 2aa9a56f40 | |||
| 721ed4ec0e | |||
| 70be4ceab1 | |||
| 5cf91d0496 | |||
| 6fee0bdb2d | |||
| e40c161125 | |||
| 97eb55cc55 | |||
| 65134be0d1 | |||
| dbf71a23aa | |||
| 7fec3db1d6 | |||
| 26b573c1d0 | |||
| 5ec1e7307e | |||
| 8bc36b7f21 | |||
| 3b909eb693 | |||
| 57e39c4472 | |||
| ff7672339c | |||
| 6e824a2c22 | |||
| 32fa49e093 | |||
| 2250eac58f | |||
| 97be6b3a0e | |||
| 942655c947 | |||
| 615db3f7fd | |||
| 0bb75c5389 | |||
| 7b5ee81d2d | |||
| 7fe46f1e1d | |||
| 50c0d1c9da | |||
| 6dbf544d06 | |||
| 41e3a0f699 | |||
| c5d8aec28b | |||
| 4653a9aef0 |
@@ -16,7 +16,7 @@ Steps to reproduce the behavior, or a explorer/cabana link to the exact drive an
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Device/Version information (please complete the following information):**
|
||||
** Device/Version information (please complete the following information):**
|
||||
- Device: [e.g. EON/EON Gold]
|
||||
- Version: [e.g. 0.6.4], or commit hash when on devel
|
||||
- Car make/model [e.g. Toyota Prius 2016]
|
||||
|
||||
+3
-17
@@ -3,14 +3,11 @@ venv/
|
||||
.tags
|
||||
.ipynb_checkpoints
|
||||
.idea
|
||||
.overlay_init
|
||||
.overlay_consistent
|
||||
.sconsign.dblite
|
||||
.vscode
|
||||
model2.png
|
||||
a.out
|
||||
|
||||
*.dylib
|
||||
*.DSYM
|
||||
*.d
|
||||
*.pyc
|
||||
@@ -18,9 +15,7 @@ a.out
|
||||
.*.swp
|
||||
.*.swo
|
||||
.*.un~
|
||||
*.tmp
|
||||
*.o
|
||||
*.os
|
||||
*.so
|
||||
*.a
|
||||
*.clb
|
||||
@@ -30,30 +25,21 @@ a.out
|
||||
config.json
|
||||
clcache
|
||||
|
||||
persist
|
||||
board/obj/
|
||||
selfdrive/boardd/boardd
|
||||
selfdrive/logcatd/logcatd
|
||||
selfdrive/mapd/default_speeds_by_region.json
|
||||
selfdrive/proclogd/proclogd
|
||||
selfdrive/ui/_ui
|
||||
selfdrive/ui/ui
|
||||
selfdrive/test/longitudinal_maneuvers/out
|
||||
selfdrive/visiond/visiond
|
||||
selfdrive/loggerd/loggerd
|
||||
selfdrive/sensord/_gpsd
|
||||
selfdrive/sensord/_sensord
|
||||
selfdrive/camerad/camerad
|
||||
selfdrive/modeld/_modeld
|
||||
selfdrive/modeld/_dmonitoringmodeld
|
||||
selfdrive/sensord/gpsd
|
||||
selfdrive/sensord/sensord
|
||||
/src/
|
||||
|
||||
one
|
||||
openpilot
|
||||
notebooks
|
||||
xx
|
||||
panda_jungle
|
||||
|
||||
.coverage*
|
||||
htmlcov
|
||||
pandaextra
|
||||
|
||||
|
||||
@@ -29,12 +29,3 @@ Code is automatically check for style by travis as part of the automated tests.
|
||||
We've released a [Model Port guide](https://medium.com/@comma_ai/openpilot-port-guide-for-toyota-models-e5467f4b5fe6) for porting to Toyota/Lexus models.
|
||||
|
||||
If you port openpilot to a substantially new car brand, see this more generic [Brand Port guide](https://medium.com/@comma_ai/how-to-write-a-car-port-for-openpilot-7ce0785eda84). You might also be eligible for a bounty. See our bounties at [comma.ai/bounties.html](https://comma.ai/bounties.html)
|
||||
|
||||
## Pull Requests
|
||||
|
||||
Pull requests should be against the master branch. Before running master on in-car hardware, you'll need to run
|
||||
```
|
||||
git submodule init
|
||||
git submodule update
|
||||
```
|
||||
in order to pull down the submodules, such as `panda` and `opendbc`.
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
FROM ubuntu:16.04
|
||||
ENV PYTHONUNBUFFERED 1
|
||||
|
||||
RUN apt-get update && apt-get install -y \
|
||||
autoconf \
|
||||
build-essential \
|
||||
bzip2 \
|
||||
clang \
|
||||
cmake \
|
||||
curl \
|
||||
ffmpeg \
|
||||
git \
|
||||
libarchive-dev \
|
||||
libbz2-dev \
|
||||
libcurl4-openssl-dev \
|
||||
libeigen3-dev \
|
||||
libffi-dev \
|
||||
libglew-dev \
|
||||
libglib2.0-0 \
|
||||
liblzma-dev \
|
||||
libmysqlclient-dev \
|
||||
libomp-dev \
|
||||
libopencv-dev \
|
||||
libssl-dev \
|
||||
libtool \
|
||||
libusb-1.0-0 \
|
||||
libzmq5-dev \
|
||||
locales \
|
||||
ocl-icd-libopencl1 \
|
||||
ocl-icd-opencl-dev \
|
||||
opencl-headers \
|
||||
python-dev \
|
||||
python-pip \
|
||||
screen \
|
||||
sudo \
|
||||
vim \
|
||||
wget
|
||||
|
||||
|
||||
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && locale-gen
|
||||
ENV LANG en_US.UTF-8
|
||||
ENV LANGUAGE en_US:en
|
||||
ENV LC_ALL en_US.UTF-8
|
||||
|
||||
RUN curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
|
||||
|
||||
ENV PATH="/root/.pyenv/bin:/root/.pyenv/shims:${PATH}"
|
||||
RUN pyenv install 3.7.3
|
||||
RUN pyenv global 3.7.3
|
||||
RUN pyenv rehash
|
||||
|
||||
RUN pip install pipenv==2018.11.26
|
||||
|
||||
COPY Pipfile /tmp/
|
||||
COPY Pipfile.lock /tmp/
|
||||
|
||||
RUN python --version
|
||||
RUN cd /tmp && pipenv install --system --deploy
|
||||
|
||||
# Install subset of dev dependencies needed for CI
|
||||
RUN pip install matplotlib==3.1.1 dictdiffer==0.8.0 fastcluster==1.1.25 aenum==2.2.1 scipy==1.3.1 lru-dict==1.1.6 tenacity==5.1.1 azure-common==1.1.23 azure-nspkg==3.0.2 azure-storage-blob==2.1.0 azure-storage-common==2.1.0 azure-storage-nspkg==3.1.0 pycurl==7.43.0.3
|
||||
|
||||
COPY phonelibs/install_capnp.sh /tmp/install_capnp.sh
|
||||
RUN /tmp/install_capnp.sh
|
||||
|
||||
RUN git clone --branch v0.6.5 https://github.com/commaai/openpilot-tools.git /tmp/openpilot/tools
|
||||
|
||||
ENV PYTHONPATH /tmp/openpilot:${PYTHONPATH}
|
||||
COPY ./.pylintrc /tmp/openpilot/.pylintrc
|
||||
COPY ./common /tmp/openpilot/common
|
||||
COPY ./cereal /tmp/openpilot/cereal
|
||||
COPY ./opendbc /tmp/openpilot/opendbc
|
||||
COPY ./selfdrive /tmp/openpilot/selfdrive
|
||||
COPY ./phonelibs /tmp/openpilot/phonelibs
|
||||
COPY ./pyextra /tmp/openpilot/pyextra
|
||||
COPY ./panda /tmp/openpilot/panda
|
||||
|
||||
RUN mkdir -p /tmp/openpilot/selfdrive/test/out
|
||||
RUN make -C /tmp/openpilot/selfdrive/controls/lib/longitudinal_mpc clean
|
||||
RUN make -C /tmp/openpilot/selfdrive/controls/lib/lateral_mpc clean
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
code_dir := $(shell pwd)
|
||||
|
||||
# TODO: Add a global build system
|
||||
|
||||
.PHONY: all
|
||||
all:
|
||||
cd selfdrive && PYTHONPATH=$(code_dir) PREPAREONLY=1 ./manager.py
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
[[source]]
|
||||
name = "pypi"
|
||||
url = "https://pypi.org/simple"
|
||||
verify_ssl = true
|
||||
|
||||
[dev-packages]
|
||||
opencv-python= "==3.4.2.17"
|
||||
PyQt5 = "*"
|
||||
ipython = "*"
|
||||
azure-common = "*"
|
||||
azure-nspkg = "*"
|
||||
azure-storage-blob = "*"
|
||||
azure-storage-common = "*"
|
||||
azure-storage-nspkg = "*"
|
||||
bincopy = "*"
|
||||
bleach = "*"
|
||||
boto = "*"
|
||||
"boto3" = "*"
|
||||
celery = "*"
|
||||
control = "*"
|
||||
datadog = "*"
|
||||
decorator = "*"
|
||||
dlib = "*"
|
||||
dominate = "*"
|
||||
elasticsearch = "*"
|
||||
fasteners = "*"
|
||||
future = "*"
|
||||
futures = "*"
|
||||
gevent = "*"
|
||||
pycocotools = {git = "https://github.com/cocodataset/cocoapi.git",subdirectory = "PythonAPI"}
|
||||
gunicorn = "*"
|
||||
"h5py" = "*"
|
||||
hexdump = "*"
|
||||
"html5lib" = "*"
|
||||
imageio = "*"
|
||||
intervaltree = "*"
|
||||
ipykernel = "*"
|
||||
joblib = "*"
|
||||
json-logging-py = "*"
|
||||
jupyter = "*"
|
||||
libarchive = "*"
|
||||
lru-dict = "*"
|
||||
lxml = "*"
|
||||
"mpld3" = "*"
|
||||
msgpack-python = "*"
|
||||
nbstripout = "*"
|
||||
nose-parameterized = "*"
|
||||
numpy = "*"
|
||||
osmium = "*"
|
||||
pbr = "*"
|
||||
percache = "*"
|
||||
pprofile = "*"
|
||||
psutil = "*"
|
||||
pycurl = "*"
|
||||
git-pylint-commit-hook = "*"
|
||||
pymongo = "*"
|
||||
"pynmea2" = "*"
|
||||
pypolyline = "*"
|
||||
pysendfile = "*"
|
||||
python-logstash = "*"
|
||||
pyvcd = "*"
|
||||
redis = "*"
|
||||
redlock = "*"
|
||||
"s2sphere" = "*"
|
||||
scikit-image = "*"
|
||||
"subprocess32" = "*"
|
||||
supervisor = "*"
|
||||
tenacity = "*"
|
||||
tensorflow-gpu = ""
|
||||
utm = "*"
|
||||
"v4l2" = "*"
|
||||
PyJWT = "==1.4.1"
|
||||
PyMySQL = "==0.9.2"
|
||||
Theano = "*"
|
||||
Werkzeug = "*"
|
||||
"backports.lzma" = "*"
|
||||
Flask-Cors = "*"
|
||||
Flask-SocketIO = "*"
|
||||
"GeoAlchemy2" = "*"
|
||||
Pygments = "*"
|
||||
PyNaCl = "*"
|
||||
"PySDL2" = "*"
|
||||
reverse_geocoder = "*"
|
||||
Shapely = "*"
|
||||
SQLAlchemy = "*"
|
||||
uWSGI = "*"
|
||||
scipy = "*"
|
||||
fastcluster = "*"
|
||||
backports-abc = "*"
|
||||
pygame = "*"
|
||||
simplejson = "*"
|
||||
python-logstash-async = "*"
|
||||
seaborn = "*"
|
||||
tensorflow-estimator = "*"
|
||||
pyproj = "*"
|
||||
mock = "*"
|
||||
blinker = "*"
|
||||
gast = "==0.2.2"
|
||||
matplotlib = "*"
|
||||
dictdiffer = "*"
|
||||
aenum = "*"
|
||||
|
||||
[packages]
|
||||
overpy = {git = "https://github.com/commaai/python-overpy.git",ref = "f86529af402d4642e1faeb146671c40284007323"}
|
||||
atomicwrites = "*"
|
||||
cffi = "*"
|
||||
crcmod = "*"
|
||||
hexdump = "*"
|
||||
libusb1 = "*"
|
||||
numpy = "*"
|
||||
psutil = "*"
|
||||
pycapnp = "*"
|
||||
cryptography = "*"
|
||||
pyserial = "*"
|
||||
python-dateutil = "*"
|
||||
pyzmq = "*"
|
||||
raven = "*"
|
||||
requests = "*"
|
||||
setproctitle = "*"
|
||||
six = "*"
|
||||
smbus2 = "*"
|
||||
sympy = "*"
|
||||
tqdm = "*"
|
||||
Cython = "*"
|
||||
PyYAML = "*"
|
||||
websocket_client = "*"
|
||||
Logentries = {git = "https://github.com/commaai/le_python.git",ref = "feaeacb48f7f4bdb02c0a8fc092326d4e101b7f2"}
|
||||
urllib3 = "*"
|
||||
chardet = "*"
|
||||
idna = "*"
|
||||
gunicorn = "*"
|
||||
utm = "*"
|
||||
json-rpc = "*"
|
||||
Flask = "*"
|
||||
PyJWT = "*"
|
||||
"Jinja2" = "*"
|
||||
nose = "*"
|
||||
pyflakes = "*"
|
||||
pylint = "*"
|
||||
pycryptodome = "*"
|
||||
pillow = "*"
|
||||
|
||||
[requires]
|
||||
python_version = "3.7.3"
|
||||
Generated
+2714
File diff suppressed because it is too large
Load Diff
@@ -1,280 +1,182 @@
|
||||
[](#)
|
||||
[](#)
|
||||
|
||||
Welcome to openpilot
|
||||
======
|
||||
|
||||
[openpilot](http://github.com/commaai/openpilot) is an open source driver assistance system. Currently, it performs the functions of Adaptive Cruise Control (ACC) and Lane Keeping Assist System (LKAS) for selected Honda, Toyota, Acura, Lexus, Chevrolet, Hyundai, Kia. It's about on par with Tesla Autopilot and GM Super Cruise, and better than [all other manufacturers](http://www.thedrive.com/tech/5707/the-war-for-autonomous-driving-part-iii-us-vs-germany-vs-japan).
|
||||
|
||||
The openpilot codebase has been written to be concise and to enable rapid prototyping. We look forward to your contributions - improving real vehicle automation has never been easier.
|
||||
|
||||
Table of Contents
|
||||
=======================
|
||||
|
||||
* [What is openpilot?](#what-is-openpilot)
|
||||
* [Integration with Stock Features](#integration-with-stock-features)
|
||||
* [Supported Hardware](#supported-hardware)
|
||||
* [Community](#community)
|
||||
* [Hardware](#hardware)
|
||||
* [Supported Cars](#supported-cars)
|
||||
* [Community Maintained Cars and Features](#community-maintained-cars-and-features)
|
||||
* [Installation Instructions](#installation-instructions)
|
||||
* [Limitations of openpilot ALC and LDW](#limitations-of-openpilot-alc-and-ldw)
|
||||
* [Limitations of openpilot ACC and FCW](#limitations-of-openpilot-acc-and-fcw)
|
||||
* [Limitations of openpilot DM](#limitations-of-openpilot-dm)
|
||||
* [User Data and comma Account](#user-data-and-comma-account)
|
||||
* [Safety and Testing](#safety-and-testing)
|
||||
* [Community Maintained Cars](#community-maintained-cars)
|
||||
* [In Progress Cars](#in-progress-cars)
|
||||
* [How can I add support for my car?](#how-can-i-add-support-for-my-car)
|
||||
* [Directory structure](#directory-structure)
|
||||
* [User Data / chffr Account / Crash Reporting](#user-data--chffr-account--crash-reporting)
|
||||
* [Testing on PC](#testing-on-pc)
|
||||
* [Community and Contributing](#community-and-contributing)
|
||||
* [Directory Structure](#directory-structure)
|
||||
* [Contributing](#contributing)
|
||||
* [Licensing](#licensing)
|
||||
|
||||
---
|
||||
|
||||
What is openpilot?
|
||||
Community
|
||||
------
|
||||
|
||||
[openpilot](http://github.com/commaai/openpilot) is an open source driver assistance system. Currently, openpilot performs the functions of Adaptive Cruise Control (ACC), Automated Lane Centering (ALC), Forward Collision Warning (FCW) and Lane Departure Warning (LDW) for a growing variety of supported [car makes, models and model years](#supported-cars). In addition, while openpilot is engaged, a camera based Driver Monitoring (DM) feature alerts distracted and asleep drivers.
|
||||
openpilot is developed by [comma.ai](https://comma.ai/) and users like you.
|
||||
|
||||
We have a [Twitter you should follow](https://twitter.com/comma_ai).
|
||||
|
||||
Also, we have a several thousand people community on [Discord](https://discord.comma.ai).
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td><a href="https://www.youtube.com/watch?v=mgAbfr42oI8" title="YouTube" rel="noopener"><img src="https://i.imgur.com/kAtT6Ei.png"></a></td>
|
||||
<td><a href="https://www.youtube.com/watch?v=394rJKeh76k" title="YouTube" rel="noopener"><img src="https://i.imgur.com/lTt8cS2.png"></a></td>
|
||||
<td><a href="https://www.youtube.com/watch?v=1iNOc3cq8cs" title="YouTube" rel="noopener"><img src="https://i.imgur.com/ANnuSpe.png"></a></td>
|
||||
<td><a href="https://www.youtube.com/watch?v=Vr6NgrB-zHw" title="YouTube" rel="noopener"><img src="https://i.imgur.com/Qypanuq.png"></a></td>
|
||||
<td><a href="https://www.youtube.com/watch?v=ICOIin4p70w" title="YouTube" rel="noopener"><img src="https://i.imgur.com/gBTo7yB.png"></a></td>
|
||||
<td><a href="https://www.youtube.com/watch?v=1zCtj3ckGFo" title="YouTube" rel="noopener"><img src="https://i.imgur.com/gNhhcep.png"></a></td>
|
||||
<td><a href="https://www.youtube.com/watch?v=Qd2mjkBIRx0" title="YouTube" rel="noopener"><img src="https://i.imgur.com/tFnSexp.png"></a></td>
|
||||
<td><a href="https://www.youtube.com/watch?v=ju12vlBm59E" title="YouTube" rel="noopener"><img src="https://i.imgur.com/3BKiJVy.png"></a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="https://www.youtube.com/watch?v=Ug41KIKF0oo" title="YouTube" rel="noopener"><img src="https://i.imgur.com/3caZ7xM.png"></a></td>
|
||||
<td><a href="https://www.youtube.com/watch?v=NVR_CdG1FRg" title="YouTube" rel="noopener"><img src="https://i.imgur.com/bAZOwql.png"></a></td>
|
||||
<td><a href="https://www.youtube.com/watch?v=tkEvIdzdfUE" title="YouTube" rel="noopener"><img src="https://i.imgur.com/EFINEzG.png"></a></td>
|
||||
<td><a href="https://www.youtube.com/watch?v=_P-N1ewNne4" title="YouTube" rel="noopener"><img src="https://i.imgur.com/gAyAq22.png"></a></td>
|
||||
<td><a href="https://www.youtube.com/watch?v=Z5VY5FzgNt4" title="YouTube" rel="noopener"><img src="https://i.imgur.com/3I9XOK2.png"></a></td>
|
||||
<td><a href="https://www.youtube.com/watch?v=blnhZC7OmMg" title="YouTube" rel="noopener"><img src="https://i.imgur.com/f9IgX6s.png"></a></td>
|
||||
<td><a href="https://www.youtube.com/watch?v=iRkz7FuJsA8" title="YouTube" rel="noopener"><img src="https://i.imgur.com/Vo5Zvmn.png"></a></td>
|
||||
<td><a href="https://www.youtube.com/watch?v=IHjEqAKDqjM" title="YouTube" rel="noopener"><img src="https://i.imgur.com/V9Zd81n.png"></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
Integration with Stock Features
|
||||
Hardware
|
||||
------
|
||||
|
||||
In all supported cars:
|
||||
* Stock Lane Keep Assist (LKA) and stock ALC are replaced by openpilot ALC, which only functions when openpilot is engaged by the user.
|
||||
* Stock LDW is replaced by openpilot LDW.
|
||||
At the moment openpilot supports the [EON Dashcam DevKit](https://comma.ai/shop/products/eon-dashcam-devkit). A [panda](https://shop.comma.ai/products/panda-obd-ii-dongle) and a [giraffe](https://comma.ai/shop/products/giraffe/) are recommended tools to interface the EON with the car. We'd like to support other platforms as well.
|
||||
|
||||
Additionally, on specific supported cars (see ACC column in [supported cars](#supported-cars)):
|
||||
* Stock ACC is replaced by openpilot ACC.
|
||||
* openpilot FCW operates in addition to stock FCW.
|
||||
|
||||
openpilot should preserve all other vehicle's stock features, including, but are not limited to: FCW, Automatic Emergency Braking (AEB), auto high-beam, blind spot warning, and side collision warning.
|
||||
|
||||
Supported Hardware
|
||||
------
|
||||
|
||||
At the moment, openpilot supports the [EON DevKit](https://comma.ai/shop/products/eon-dashcam-devkit) and the [comma two](https://comma.ai/shop/products/comma-two-devkit). A [car harness](https://comma.ai/shop/products/car-harness) is recommended to connect the EON or comma two to the car. In the future, we'd like to support other platforms as well, like gaming PCs.
|
||||
Install openpilot on a neo device by entering ``https://openpilot.comma.ai`` during NEOS setup.
|
||||
|
||||
Supported Cars
|
||||
------
|
||||
|
||||
| Make | Model (US Market Reference) | Supported Package | ACC | No ACC accel below | No ALC below |
|
||||
| ----------| ------------------------------| ------------------| -----------------| -------------------| -------------|
|
||||
| Acura | ILX 2016-18 | AcuraWatch Plus | openpilot | 25mph<sup>5</sup> | 25mph |
|
||||
| Acura | RDX 2016-18 | AcuraWatch Plus | openpilot | 25mph<sup>5</sup> | 12mph |
|
||||
| Chrysler | Pacifica 2017-18 | Adaptive Cruise | Stock | 0mph | 9mph |
|
||||
| Chrysler | Pacifica Hybrid 2017-18 | Adaptive Cruise | Stock | 0mph | 9mph |
|
||||
| Chrysler | Pacifica Hybrid 2019-20 | Adaptive Cruise | Stock | 0mph | 39mph |
|
||||
| Honda | Accord 2018-19 | All | Stock | 0mph | 3mph |
|
||||
| Honda | Accord Hybrid 2018-19 | All | Stock | 0mph | 3mph |
|
||||
| Honda | Civic Hatchback 2017-19 | Honda Sensing | Stock | 0mph | 12mph |
|
||||
| Honda | Civic Sedan/Coupe 2016-18 | Honda Sensing | openpilot | 0mph | 12mph |
|
||||
| Honda | Civic Sedan/Coupe 2019 | Honda Sensing | Stock | 0mph | 2mph |
|
||||
| Honda | CR-V 2015-16 | Touring | openpilot | 25mph<sup>5</sup> | 12mph |
|
||||
| Honda | CR-V 2017-19 | Honda Sensing | Stock | 0mph | 12mph |
|
||||
| Honda | CR-V Hybrid 2017-2019 | Honda Sensing | Stock | 0mph | 12mph |
|
||||
| Honda | Fit 2018-19 | Honda Sensing | openpilot | 25mph<sup>5</sup> | 12mph |
|
||||
| Honda | Odyssey 2018-20 | Honda Sensing | openpilot | 25mph<sup>5</sup> | 0mph |
|
||||
| Honda | Passport 2019 | All | openpilot | 25mph<sup>5</sup> | 12mph |
|
||||
| Honda | Pilot 2016-18 | Honda Sensing | openpilot | 25mph<sup>5</sup> | 12mph |
|
||||
| Honda | Pilot 2019 | All | openpilot | 25mph<sup>5</sup> | 12mph |
|
||||
| Honda | Ridgeline 2017-19 | Honda Sensing | openpilot | 25mph<sup>5</sup> | 12mph |
|
||||
| Hyundai | Elantra 2017-19<sup>1</sup> | SCC + LKAS | Stock | 19mph | 34mph |
|
||||
| Hyundai | Genesis 2018<sup>1</sup> | All | Stock | 19mph | 34mph |
|
||||
| Hyundai | Santa Fe 2019<sup>1</sup> | All | Stock | 0mph | 0mph |
|
||||
| Jeep | Grand Cherokee 2016-18 | Adaptive Cruise | Stock | 0mph | 9mph |
|
||||
| Jeep | Grand Cherokee 2019 | Adaptive Cruise | Stock | 0mph | 39mph |
|
||||
| Kia | Optima 2019<sup>1</sup> | SCC + LKAS | Stock | 0mph | 0mph |
|
||||
| Kia | Sorento 2018<sup>1</sup> | All | Stock | 0mph | 0mph |
|
||||
| Kia | Stinger 2018<sup>1</sup> | SCC + LKAS | Stock | 0mph | 0mph |
|
||||
| Lexus | CT Hybrid 2017-18 | All | Stock<sup>4</sup>| 0mph | 0mph |
|
||||
| Lexus | ES 2019 | All | openpilot | 0mph | 0mph |
|
||||
| Lexus | ES Hybrid 2019 | All | openpilot | 0mph | 0mph |
|
||||
| Lexus | IS 2017-2019 | All | Stock | 22mph | 0mph |
|
||||
| Lexus | IS Hybrid 2017 | All | Stock | 0mph | 0mph |
|
||||
| Lexus | RX 2016-17 | All | Stock<sup>4</sup>| 0mph | 0mph |
|
||||
| Lexus | RX 2020 | All | openpilot | 0mph | 0mph |
|
||||
| Lexus | RX Hybrid 2016-19 | All | Stock<sup>4</sup>| 0mph | 0mph |
|
||||
| Subaru | Crosstrek 2018-19 | EyeSight | Stock | 0mph | 0mph |
|
||||
| Subaru | Impreza 2019-20 | EyeSight | Stock | 0mph | 0mph |
|
||||
| Toyota | Avalon 2016 | TSS-P | Stock<sup>4</sup>| 20mph<sup>5</sup> | 0mph |
|
||||
| Toyota | Avalon 2017-18 | All | Stock<sup>4</sup>| 20mph<sup>5</sup> | 0mph |
|
||||
| Toyota | Camry 2018-19 | All | Stock | 0mph<sup>2</sup> | 0mph |
|
||||
| Toyota | Camry Hybrid 2018-19 | All | Stock | 0mph<sup>2</sup> | 0mph |
|
||||
| Toyota | C-HR 2017-19 | All | Stock | 0mph | 0mph |
|
||||
| Toyota | C-HR Hybrid 2017-19 | All | Stock | 0mph | 0mph |
|
||||
| Toyota | Corolla 2017-19 | All | Stock<sup>4</sup>| 20mph<sup>5</sup> | 0mph |
|
||||
| Toyota | Corolla 2020 | All | openpilot | 0mph | 0mph |
|
||||
| Toyota | Corolla Hatchback 2019-20 | All | openpilot | 0mph | 0mph |
|
||||
| Toyota | Corolla Hybrid 2020 | All | openpilot | 0mph | 0mph |
|
||||
| Toyota | Highlander 2017-19 | All | Stock<sup>4</sup>| 0mph | 0mph |
|
||||
| Toyota | Highlander Hybrid 2017-19 | All | Stock<sup>4</sup>| 0mph | 0mph |
|
||||
| Toyota | Prius 2016 | TSS-P | Stock<sup>4</sup>| 0mph | 0mph |
|
||||
| Toyota | Prius 2017-19 | All | Stock<sup>4</sup>| 0mph | 0mph |
|
||||
| Toyota | Prius Prime 2017-20 | All | Stock<sup>4</sup>| 0mph | 0mph |
|
||||
| Toyota | Rav4 2016 | TSS-P | Stock<sup>4</sup>| 20mph<sup>5</sup> | 0mph |
|
||||
| Toyota | Rav4 2017-18 | All | Stock<sup>4</sup>| 20mph<sup>5</sup> | 0mph |
|
||||
| Toyota | Rav4 2019 | All | openpilot | 0mph | 0mph |
|
||||
| Toyota | Rav4 Hybrid 2016 | TSS-P | Stock<sup>4</sup>| 0mph | 0mph |
|
||||
| Toyota | Rav4 Hybrid 2017-18 | All | Stock<sup>4</sup>| 0mph | 0mph |
|
||||
| Toyota | Rav4 Hybrid 2019-20 | All | openpilot | 0mph | 0mph |
|
||||
| Toyota | Sienna 2018 | All | Stock<sup>4</sup>| 0mph | 0mph |
|
||||
| Volkswagen| Golf 2016-19<sup>3</sup> | Driver Assistance | Stock | 0mph | 0mph |
|
||||
| Make | Model (US Market Reference)| Supported Package | Lateral | Longitudinal | No Accel Below | No Steer Below | Giraffe |
|
||||
| ---------------------| ---------------------------| ---------------------| --------| ---------------| -----------------| ---------------|-------------------|
|
||||
| Acura | ILX 2016-18 | AcuraWatch Plus | Yes | Yes | 25mph<sup>1</sup>| 25mph | Nidec |
|
||||
| Acura | RDX 2016-18 | AcuraWatch Plus | Yes | Yes | 25mph<sup>1</sup>| 12mph | Nidec |
|
||||
| Buick<sup>3</sup> | Regal 2018 | Adaptive Cruise | Yes | Yes | 0mph | 7mph | Custom<sup>6</sup>|
|
||||
| Chevrolet<sup>3</sup>| Malibu 2017 | Adaptive Cruise | Yes | Yes | 0mph | 7mph | Custom<sup>6</sup>|
|
||||
| Chevrolet<sup>3</sup>| Volt 2017-18 | Adaptive Cruise | Yes | Yes | 0mph | 7mph | Custom<sup>6</sup>|
|
||||
| Cadillac<sup>3</sup> | ATS 2018 | Adaptive Cruise | Yes | Yes | 0mph | 7mph | Custom<sup>6</sup>|
|
||||
| Chrysler | Pacifica 2017-18 | Adaptive Cruise | Yes | Stock | 0mph | 9mph | FCA |
|
||||
| Chrysler | Pacifica Hybrid 2017-18 | Adaptive Cruise | Yes | Stock | 0mph | 9mph | FCA |
|
||||
| Chrysler | Pacifica Hybrid 2019 | Adaptive Cruise | Yes | Stock | 0mph | 39mph | FCA |
|
||||
| GMC<sup>3</sup> | Acadia Denali 2018 | Adaptive Cruise | Yes | Yes | 0mph | 7mph | Custom<sup>6</sup>|
|
||||
| Holden<sup>3</sup> | Astra 2017 | Adaptive Cruise | Yes | Yes | 0mph | 7mph | Custom<sup>6</sup>|
|
||||
| Honda | Accord 2018-19 | All | Yes | Stock | 0mph | 3mph | Bosch |
|
||||
| Honda | Accord Hybrid 2018-19 | All | Yes | Stock | 0mph | 3mph | Bosch |
|
||||
| Honda | Civic Sedan/Coupe 2016-18 | Honda Sensing | Yes | Yes | 0mph | 12mph | Nidec |
|
||||
| Honda | Civic Sedan/Coupe 2019 | Honda Sensing | Yes | Stock | 0mph | 2mph | Bosch |
|
||||
| Honda | Civic Hatchback 2017-19 | Honda Sensing | Yes | Stock | 0mph | 12mph | Bosch |
|
||||
| Honda | CR-V 2015-16 | Touring | Yes | Yes | 25mph<sup>1</sup>| 12mph | Nidec |
|
||||
| Honda | CR-V 2017-19 | Honda Sensing | Yes | Stock | 0mph | 12mph | Bosch |
|
||||
| Honda | CR-V Hybrid 2017-2019 | Honda Sensing | Yes | Stock | 0mph | 12mph | Bosch |
|
||||
| Honda | Fit 2018-19 | Honda Sensing | Yes | Yes | 25mph<sup>1</sup>| 12mph | Inverted Nidec |
|
||||
| Honda | Odyssey 2018-19 | Honda Sensing | Yes | Yes | 25mph<sup>1</sup>| 0mph | Inverted Nidec |
|
||||
| Honda | Passport 2019 | All | Yes | Yes | 25mph<sup>1</sup>| 12mph | Inverted Nidec |
|
||||
| Honda | Pilot 2016-18 | Honda Sensing | Yes | Yes | 25mph<sup>1</sup>| 12mph | Nidec |
|
||||
| Honda | Pilot 2019 | All | Yes | Yes | 25mph<sup>1</sup>| 12mph | Inverted Nidec |
|
||||
| Honda | Ridgeline 2017-19 | Honda Sensing | Yes | Yes | 25mph<sup>1</sup>| 12mph | Nidec |
|
||||
| Hyundai | Santa Fe 2019 | All | Yes | Stock | 0mph | 0mph | Custom<sup>5</sup>|
|
||||
| Hyundai | Elantra 2017-19 | SCC + LKAS | Yes | Stock | 19mph | 34mph | Custom<sup>5</sup>|
|
||||
| Hyundai | Genesis 2018 | All | Yes | Stock | 19mph | 34mph | Custom<sup>5</sup>|
|
||||
| Jeep | Grand Cherokee 2016-18 | Adaptive Cruise | Yes | Stock | 0mph | 9mph | FCA |
|
||||
| Jeep | Grand Cherokee 2019 | Adaptive Cruise | Yes | Stock | 0mph | 39mph | FCA |
|
||||
| Kia | Optima 2019 | SCC + LKAS | Yes | Stock | 0mph | 0mph | Custom<sup>5</sup>|
|
||||
| Kia | Sorento 2018 | All | Yes | Stock | 0mph | 0mph | Custom<sup>5</sup>|
|
||||
| Kia | Stinger 2018 | SCC + LKAS | Yes | Stock | 0mph | 0mph | Custom<sup>5</sup>|
|
||||
| Lexus | CT Hybrid 2017-18 | All | Yes | Yes<sup>2</sup>| 0mph | 0mph | Toyota |
|
||||
| Lexus | ES 2019 | All | Yes | Yes | 0mph | 0mph | Toyota |
|
||||
| Lexus | ES Hybrid 2019 | All | Yes | Yes | 0mph | 0mph | Toyota |
|
||||
| Lexus | RX Hybrid 2016-19 | All | Yes | Yes<sup>2</sup>| 0mph | 0mph | Toyota |
|
||||
| Lexus | IS 2017-2019 | All | Yes | Stock | 22mph | 0mph | Toyota |
|
||||
| Lexus | IS Hybrid 2017 | All | Yes | Stock | 0mph | 0mph | Toyota |
|
||||
| Subaru | Crosstrek 2018-19 | EyeSight | Yes | Stock | 0mph | 0mph | Subaru |
|
||||
| Subaru | Impreza 2019-20 | EyeSight | Yes | Stock | 0mph | 0mph | Subaru |
|
||||
| Toyota | Avalon 2016 | TSS-P | Yes | Yes<sup>2</sup>| 20mph<sup>1</sup>| 0mph | Toyota |
|
||||
| Toyota | Avalon 2017-18 | All | Yes | Yes<sup>2</sup>| 20mph<sup>1</sup>| 0mph | Toyota |
|
||||
| Toyota | Camry 2018-19 | All | Yes | Stock | 0mph<sup>4</sup> | 0mph | Toyota |
|
||||
| Toyota | Camry Hybrid 2018-19 | All | Yes | Stock | 0mph<sup>4</sup> | 0mph | Toyota |
|
||||
| Toyota | C-HR 2017-19 | All | Yes | Stock | 0mph | 0mph | Toyota |
|
||||
| Toyota | C-HR Hybrid 2017-19 | All | Yes | Stock | 0mph | 0mph | Toyota |
|
||||
| Toyota | Corolla 2017-19 | All | Yes | Yes<sup>2</sup>| 20mph<sup>1</sup>| 0mph | Toyota |
|
||||
| Toyota | Corolla 2020 | All | Yes | Yes | 0mph | 0mph | Toyota |
|
||||
| Toyota | Corolla Hatchback 2019 | All | Yes | Yes | 0mph | 0mph | Toyota |
|
||||
| Toyota | Corolla Hybrid 2019 | All | Yes | Yes | 0mph | 0mph | Toyota |
|
||||
| Toyota | Highlander 2017-19 | All | Yes | Yes<sup>2</sup>| 0mph | 0mph | Toyota |
|
||||
| Toyota | Highlander Hybrid 2017-19 | All | Yes | Yes<sup>2</sup>| 0mph | 0mph | Toyota |
|
||||
| Toyota | Prius 2016 | TSS-P | Yes | Yes<sup>2</sup>| 0mph | 0mph | Toyota |
|
||||
| Toyota | Prius 2017-19 | All | Yes | Yes<sup>2</sup>| 0mph | 0mph | Toyota |
|
||||
| Toyota | Prius Prime 2017-20 | All | Yes | Yes<sup>2</sup>| 0mph | 0mph | Toyota |
|
||||
| Toyota | Rav4 2016 | TSS-P | Yes | Yes<sup>2</sup>| 20mph<sup>1</sup>| 0mph | Toyota |
|
||||
| Toyota | Rav4 2017-18 | All | Yes | Yes<sup>2</sup>| 20mph<sup>1</sup>| 0mph | Toyota |
|
||||
| Toyota | Rav4 2019 | All | Yes | Yes | 0mph | 0mph | Toyota |
|
||||
| Toyota | Rav4 Hybrid 2016 | TSS-P | Yes | Yes<sup>2</sup>| 0mph | 0mph | Toyota |
|
||||
| Toyota | Rav4 Hybrid 2017-18 | All | Yes | Yes<sup>2</sup>| 0mph | 0mph | Toyota |
|
||||
| Toyota | Sienna 2018 | All | Yes | Yes<sup>2</sup>| 0mph | 0mph | Toyota |
|
||||
|
||||
<sup>1</sup>Requires a [panda](https://comma.ai/shop/products/panda-obd-ii-dongle) and open sourced [Hyundai giraffe](https://github.com/commaai/neo/tree/master/giraffe/hyundai), designed for the 2019 Sante Fe; pinout may differ for other Hyundai and Kia models. <br />
|
||||
<sup>2</sup>28mph for Camry 4CYL L, 4CYL LE and 4CYL SE which don't have Full-Speed Range Dynamic Radar Cruise Control. <br />
|
||||
<sup>3</sup>Requires a [custom connector](https://community.comma.ai/wiki/index.php/Volkswagen#Integration_at_R242_Camera) for the [car harness](https://comma.ai/shop/products/car-harness) <br />
|
||||
<sup>1</sup>[Comma Pedal](https://community.comma.ai/wiki/index.php/Comma_Pedal) is used to provide stop-and-go capability to some of the openpilot-supported cars that don't currently support stop-and-go. Here is how to [build a Comma Pedal](https://medium.com/@jfrux/comma-pedal-building-with-macrofab-6328bea791e8). ***NOTE: The Comma Pedal is not officially supported by [comma.ai](https://comma.ai).*** <br />
|
||||
<sup>2</sup>When disconnecting the Driver Support Unit (DSU), otherwise longitudinal control is stock ACC. For DSU locations, see [Toyota Wiki page](https://community.comma.ai/wiki/index.php/Toyota). ***NOTE: disconnecting the DSU disables Automatic Emergency Braking (AEB).*** <br />
|
||||
<sup>3</sup>[GM installation guide](https://zoneos.com/volt/). ***NOTE: disconnecting the ASCM disables Automatic Emergency Braking (AEB).*** <br />
|
||||
<sup>4</sup>28mph for Camry 4CYL L, 4CYL LE and 4CYL SE which don't have Full-Speed Range Dynamic Radar Cruise Control. <br />
|
||||
<sup>5</sup>Open sourced [Hyundai Giraffe](https://github.com/commaai/neo/tree/master/giraffe/hyundai) is designed for the 2019 Sante Fe; pinout may differ for other Hyundais. <br />
|
||||
<sup>6</sup>Community built Giraffe, find more information [here](https://zoneos.com/shop/). <br />
|
||||
|
||||
Community Maintained Cars and Features
|
||||
Community Maintained Cars
|
||||
------
|
||||
|
||||
| Make | Model (US Market Reference) | Supported Package | ACC | No ACC accel below | No ALC below |
|
||||
| ----------| ------------------------------| ------------------| -----------------| -------------------| -------------|
|
||||
| Buick | Regal 2018<sup>6</sup> | Adaptive Cruise | openpilot | 0mph | 7mph |
|
||||
| Cadillac | ATS 2018<sup>6</sup> | Adaptive Cruise | openpilot | 0mph | 7mph |
|
||||
| Chevrolet | Malibu 2017<sup>6</sup> | Adaptive Cruise | openpilot | 0mph | 7mph |
|
||||
| Chevrolet | Volt 2017-18<sup>6</sup> | Adaptive Cruise | openpilot | 0mph | 7mph |
|
||||
| GMC | Acadia Denali 2018<sup>6</sup>| Adaptive Cruise | openpilot | 0mph | 7mph |
|
||||
| Holden | Astra 2017<sup>6</sup> | Adaptive Cruise | openpilot | 0mph | 7mph |
|
||||
| Make | Model | Supported Package | Lateral | Longitudinal | No Accel Below | No Steer Below | Giraffe |
|
||||
| ---------------------| -------------------------| ---------------------| --------| ---------------| -----------------| ---------------|-------------------|
|
||||
| Tesla | Model S 2012-13 | All | Yes | Not yet | Not applicable | 0mph | Custom<sup>7</sup>|
|
||||
|
||||
<sup>4</sup>When disconnecting the Driver Support Unit (DSU), openpilot ACC will replace stock ACC. For DSU locations, see [Toyota Wiki page](https://community.comma.ai/wiki/index.php/Toyota). ***NOTE: disconnecting the DSU disables Automatic Emergency Braking (AEB).*** <br />
|
||||
<sup>5</sup>[Comma Pedal](https://community.comma.ai/wiki/index.php/Comma_Pedal) is used to provide stop-and-go capability to some of the openpilot-supported cars that don't currently support stop-and-go. Here is how to [build a Comma Pedal](https://medium.com/@jfrux/comma-pedal-building-with-macrofab-6328bea791e8). ***NOTE: The Comma Pedal is not officially supported by [comma](https://comma.ai).*** <br />
|
||||
<sup>6</sup>Requires a [panda](https://comma.ai/shop/products/panda-obd-ii-dongle) and [community built giraffe](https://zoneos.com/volt/). ***NOTE: disconnecting the ASCM disables Automatic Emergency Braking (AEB).*** <br />
|
||||
[[Tesla Model S Pull Request]](https://github.com/commaai/openpilot/pull/246) <br />
|
||||
<sup>7</sup>Community built Giraffe, find more information here [Community Tesla Giraffe](https://github.com/jeankalud/neo/tree/tesla_giraffe/giraffe/tesla) <br />
|
||||
|
||||
Community Maintained Cars and Features are not verified by comma to meet our [safety model](SAFETY.md). Be extra cautious using them. They are only available after enabling the toggle in `Settings->Developer->Enable Community Features`.
|
||||
Community Maintained Cars are not confirmed by comma.ai to meet our [safety model](https://github.com/commaai/openpilot/blob/devel/SAFETY.md). Be extra cautious using them.
|
||||
|
||||
Installation Instructions
|
||||
In Progress Cars
|
||||
------
|
||||
- All TSS-P Toyota with Steering Assist and LSS-P Lexus with Steering Assist or Lane Keep Assist.
|
||||
- All Hyundai with SmartSense.
|
||||
- All Kia, Genesis with SCC and LKAS.
|
||||
- All Chrysler, Jeep, Fiat with Adaptive Cruise Control and LaneSense.
|
||||
- All Subaru with EyeSight.
|
||||
|
||||
How can I add support for my car?
|
||||
------
|
||||
|
||||
Install openpilot on a EON by entering ``https://openpilot.comma.ai`` during the installer setup.
|
||||
If your car has adaptive cruise control and lane keep assist, you are in luck. Using a [panda](https://comma.ai/shop/products/panda-obd-ii-dongle/) and [cabana](https://community.comma.ai/cabana/), you can understand how to make your car drive by wire.
|
||||
|
||||
Follow this [video instructions](https://youtu.be/3nlkomHathI) to properly mount the EON on the windshield. Note: openpilot features an automatic pose calibration routine and openpilot performance should not be affected by small pitch and yaw misalignments caused by imprecise EON mounting.
|
||||
We've written guides for [Brand](https://medium.com/@comma_ai/how-to-write-a-car-port-for-openpilot-7ce0785eda84) and [Model](https://medium.com/@comma_ai/openpilot-port-guide-for-toyota-models-e5467f4b5fe6) ports. These guides might help you after you have the basics figured out.
|
||||
|
||||
Before placing the device on your windshield, check the state and local laws and ordinances where you drive. Some state laws prohibit or restrict the placement of objects on the windshield of a motor vehicle.
|
||||
- BMW, Audi, Volvo, and Mercedes all use [FlexRay](https://en.wikipedia.org/wiki/FlexRay) and can be supported after [FlexRay support](https://github.com/commaai/openpilot/pull/463) is merged.
|
||||
- We put time into a Ford port, but the steering has a 10 second cutout limitation that makes it unusable.
|
||||
- The 2016-2017 Honda Accord uses a custom signaling protocol for steering that's unlikely to ever be upstreamed.
|
||||
|
||||
You will be able to engage openpilot after reviewing the onboarding screens and finishing the calibration procedure.
|
||||
|
||||
Limitations of openpilot ALC and LDW
|
||||
------
|
||||
|
||||
openpilot ALC and openpilot LDW do not automatically drive the vehicle or reduce the amount of attention that must be paid to operate your vehicle. The driver must always keep control of the steering wheel and be ready to correct the openpilot ALC action at all times.
|
||||
|
||||
While changing lanes, openpilot is not capable of looking next to you or checking your blind spot. Only nudge the wheel to initiate a lane change after you have confirmed it's safe to do so.
|
||||
|
||||
Many factors can impact the performance of openpilot ALC and openpilot LDW, causing them to be unable to function as intended. These include, but are not limited to:
|
||||
|
||||
* Poor visibility (heavy rain, snow, fog, etc.) or weather conditions that may interfere with sensor operation.
|
||||
* The road facing camera is obstructed, covered or damaged by mud, ice, snow, etc.
|
||||
* Obstruction caused by applying excessive paint or adhesive products (such as wraps, stickers, rubber coating, etc.) onto the vehicle.
|
||||
* The EON is mounted incorrectly.
|
||||
* When in sharp curves, like on-off ramps, intersections etc...; openpilot is designed to be limited in the amount of steering torque it can produce.
|
||||
* In the presence of restricted lanes or construction zones.
|
||||
* When driving on highly banked roads or in presence of strong cross-wind.
|
||||
* Extremely hot or cold temperatures.
|
||||
* Bright light (due to oncoming headlights, direct sunlight, etc.).
|
||||
* Driving on hills, narrow, or winding roads.
|
||||
|
||||
The list above does not represent an exhaustive list of situations that may interfere with proper operation of openpilot components. It is the driver's responsibility to be in control of the vehicle at all times.
|
||||
|
||||
Limitations of openpilot ACC and FCW
|
||||
------
|
||||
|
||||
openpilot ACC and openpilot FCW are not systems that allow careless or inattentive driving. It is still necessary for the driver to pay close attention to the vehicle’s surroundings and to be ready to re-take control of the gas and the brake at all times.
|
||||
|
||||
Many factors can impact the performance of openpilot ACC and openpilot FCW, causing them to be unable to function as intended. These include, but are not limited to:
|
||||
|
||||
* Poor visibility (heavy rain, snow, fog, etc.) or weather conditions that may interfere with sensor operation.
|
||||
* The road facing camera or radar are obstructed, covered, or damaged by mud, ice, snow, etc.
|
||||
* Obstruction caused by applying excessive paint or adhesive products (such as wraps, stickers, rubber coating, etc.) onto the vehicle.
|
||||
* The EON is mounted incorrectly.
|
||||
* Approaching a toll booth, a bridge or a large metal plate.
|
||||
* When driving on roads with pedestrians, cyclists, etc...
|
||||
* In presence of traffic signs or stop lights, which are not detected by openpilot at this time.
|
||||
* When the posted speed limit is below the user selected set speed. openpilot does not detect speed limits at this time.
|
||||
* In presence of vehicles in the same lane that are not moving.
|
||||
* When abrupt braking maneuvers are required. openpilot is designed to be limited in the amount of deceleration and acceleration that it can produce.
|
||||
* When surrounding vehicles perform close cut-ins from neighbor lanes.
|
||||
* Driving on hills, narrow, or winding roads.
|
||||
* Extremely hot or cold temperatures.
|
||||
* Bright light (due to oncoming headlights, direct sunlight, etc.).
|
||||
* Interference from other equipment that generates radar waves.
|
||||
|
||||
The list above does not represent an exhaustive list of situations that may interfere with proper operation of openpilot components. It is the driver's responsibility to be in control of the vehicle at all times.
|
||||
|
||||
Limitations of openpilot DM
|
||||
------
|
||||
|
||||
openpilot DM should not be considered an exact measurements of the status of alertness of the driver.
|
||||
|
||||
Many factors can impact the performance of openpilot DM, causing it to be unable to function as intended. These include, but are not limited to:
|
||||
|
||||
* Low light conditions, such as driving at night or in dark tunnels.
|
||||
* Bright light (due to oncoming headlights, direct sunlight, etc.).
|
||||
* The driver face is partially or completely outside field of view of the driver facing camera.
|
||||
* Right hand driving vehicles.
|
||||
* The driver facing camera is obstructed, covered, or damaged.
|
||||
|
||||
The list above does not represent an exhaustive list of situations that may interfere with proper operation of openpilot components. A driver should not rely on openpilot DM to assess their level of attention.
|
||||
|
||||
User Data and comma Account
|
||||
------
|
||||
|
||||
By default, openpilot uploads the driving data to our servers. You can also access your data by pairing with the comma connect app ([iOS](https://apps.apple.com/us/app/comma-connect/id1456551889), [Android](https://play.google.com/store/apps/details?id=ai.comma.connect&hl=en_US)). We use your data to train better models and improve openpilot for everyone.
|
||||
|
||||
openpilot is open source software: the user is free to disable data collection if they wish to do so.
|
||||
|
||||
openpilot logs the road facing camera, CAN, GPS, IMU, magnetometer, thermal sensors, crashes, and operating system logs.
|
||||
The driver facing camera is only logged if you explicitly opt-in in settings. The microphone is not recorded.
|
||||
|
||||
By using openpilot, you agree to [our Privacy Policy](https://my.comma.ai/privacy). You understand that use of this software or its related services will generate certain types of user data, which may be logged and stored at the sole discretion of comma. By accepting this agreement, you grant an irrevocable, perpetual, worldwide right to comma for the use of this data.
|
||||
|
||||
Safety and Testing
|
||||
----
|
||||
|
||||
* openpilot observes ISO26262 guidelines, see [SAFETY.md](SAFETY.md) for more detail.
|
||||
* openpilot has software in the loop [tests](run_docker_tests.sh) that run on every commit.
|
||||
* The safety model code lives in panda and is written in C, see [code rigor](https://github.com/commaai/panda#code-rigor) for more details.
|
||||
* panda has software in the loop [safety tests](https://github.com/commaai/panda/tree/master/tests/safety).
|
||||
* Internally, we have a hardware in the loop Jenkins test suite that builds and unit tests the various processes.
|
||||
* panda has additional hardware in the loop [tests](https://github.com/commaai/panda/blob/master/Jenkinsfile).
|
||||
* We run the latest openpilot in a testing closet containing 10 EONs continuously replaying routes.
|
||||
|
||||
Testing on PC
|
||||
------
|
||||
|
||||
Check out the tools directory in master: lots of tools you can use to replay driving data, test and develop openpilot from your pc.
|
||||
|
||||
Community and Contributing
|
||||
------
|
||||
|
||||
openpilot is developed by [comma](https://comma.ai/) and by users like you. We welcome both pull requests and issues on [GitHub](http://github.com/commaai/openpilot). Bug fixes and new car ports are encouraged.
|
||||
|
||||
You can add support for your car by following guides we have written for [Brand](https://medium.com/@comma_ai/how-to-write-a-car-port-for-openpilot-7ce0785eda84) and [Model](https://medium.com/@comma_ai/openpilot-port-guide-for-toyota-models-e5467f4b5fe6) ports. Generally, a car with adaptive cruise control and lane keep assist is a good candidate. [Join our Discord](https://discord.comma.ai) to discuss car ports: most car makes have a dedicated channel.
|
||||
|
||||
Want to get paid to work on openpilot? [comma is hiring](https://comma.ai/jobs/). We also have a [bounty program](https://comma.ai/bounties.html).
|
||||
|
||||
And [follow us on Twitter](https://twitter.com/comma_ai).
|
||||
|
||||
Directory Structure
|
||||
Directory structure
|
||||
------
|
||||
.
|
||||
├── apk # The apk files used for the UI
|
||||
├── cereal # The messaging spec and libs used for all logs on EON
|
||||
├── cereal # The messaging spec used for all logs on EON
|
||||
├── common # Library like functionality we've developed here
|
||||
├── installer/updater # Manages auto-updates of openpilot
|
||||
├── opendbc # Files showing how to interpret data from cars
|
||||
├── panda # Code used to communicate on CAN
|
||||
├── panda # Code used to communicate on CAN and LIN
|
||||
├── phonelibs # Libraries used on EON
|
||||
├── pyextra # Libraries used on EON
|
||||
└── selfdrive # Code needed to drive the car
|
||||
├── assets # Fonts and images for UI
|
||||
├── athena # Allows communication with the app
|
||||
├── boardd # Daemon to talk to the board
|
||||
├── camerad # Driver to capture images from the camera sensors
|
||||
├── can # Helpers for parsing CAN messages
|
||||
├── car # Car specific code to read states and control actuators
|
||||
├── common # Shared C/C++ code for the daemons
|
||||
├── controls # Perception, planning and controls
|
||||
@@ -282,20 +184,54 @@ Directory Structure
|
||||
├── locationd # Soon to be home of precise location
|
||||
├── logcatd # Android logcat as a service
|
||||
├── loggerd # Logger and uploader of car data
|
||||
├── modeld # Driving and monitoring model runners
|
||||
├── proclogd # Logs information from proc
|
||||
├── sensord # IMU / GPS interface code
|
||||
├── tests # Unit tests, system tests and a car simulator
|
||||
└── ui # The UI
|
||||
├── test # Car simulator running code through virtual maneuvers
|
||||
├── ui # The UI
|
||||
└── visiond # Vision pipeline
|
||||
|
||||
To understand how the services interact, see `cereal/service_list.yaml`.
|
||||
To understand how the services interact, see `selfdrive/service_list.yaml`
|
||||
|
||||
User Data / chffr Account / Crash Reporting
|
||||
------
|
||||
|
||||
By default, openpilot creates an account and includes a client for chffr, our dashcam app. We use your data to train better models and improve openpilot for everyone.
|
||||
|
||||
It's open source software, so you are free to disable it if you wish.
|
||||
|
||||
It logs the road facing camera, CAN, GPS, IMU, magnetometer, thermal sensors, crashes, and operating system logs.
|
||||
The user facing camera is only logged if you explicitly opt-in in settings.
|
||||
It does not log the microphone.
|
||||
|
||||
By using it, you agree to [our privacy policy](https://community.comma.ai/privacy.html). You understand that use of this software or its related services will generate certain types of user data, which may be logged and stored at the sole discretion of comma.ai. By accepting this agreement, you grant an irrevocable, perpetual, worldwide right to comma.ai for the use of this data.
|
||||
|
||||
Testing on PC
|
||||
------
|
||||
|
||||
Check out [openpilot-tools](https://github.com/commaai/openpilot-tools): lots of tools you can use to replay driving data, test and develop openpilot from your pc.
|
||||
|
||||
Also, within openpilot there is a rudimentary infrastructure to run a basic simulation and generate a report of openpilot's behavior in different longitudinal control scenarios.
|
||||
|
||||
```bash
|
||||
# Requires working docker
|
||||
./run_docker_tests.sh
|
||||
```
|
||||
|
||||
Contributing
|
||||
------
|
||||
|
||||
We welcome both pull requests and issues on [github](http://github.com/commaai/openpilot). Bug fixes and new car ports encouraged.
|
||||
|
||||
We also have a [bounty program](https://comma.ai/bounties.html).
|
||||
|
||||
Want to get paid to work on openpilot? [comma.ai is hiring](https://comma.ai/jobs/)
|
||||
|
||||
Licensing
|
||||
------
|
||||
|
||||
openpilot is released under the MIT license. Some parts of the software are released under other licenses as specified.
|
||||
|
||||
Any user of this software shall indemnify and hold harmless comma.ai, Inc. and its directors, officers, employees, agents, stockholders, affiliates, subcontractors and customers from and against all allegations, claims, actions, suits, demands, damages, liabilities, obligations, losses, settlements, judgments, costs and expenses (including without limitation attorneys’ fees and costs) which arise out of, relate to or result from any use of this software by user.
|
||||
Any user of this software shall indemnify and hold harmless Comma.ai, Inc. and its directors, officers, employees, agents, stockholders, affiliates, subcontractors and customers from and against all allegations, claims, actions, suits, demands, damages, liabilities, obligations, losses, settlements, judgments, costs and expenses (including without limitation attorneys’ fees and costs) which arise out of, relate to or result from any use of this software by user.
|
||||
|
||||
**THIS IS ALPHA QUALITY SOFTWARE FOR RESEARCH PURPOSES ONLY. THIS IS NOT A PRODUCT.
|
||||
YOU ARE RESPONSIBLE FOR COMPLYING WITH LOCAL LAWS AND REGULATIONS.
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
Welcome to chffrplus
|
||||
======
|
||||
|
||||
[chffrplus](https://github.com/commaai/chffrplus) is an open source dashcam.
|
||||
|
||||
This is the shipping reference software for the comma EON Dashcam DevKit. It keeps many of the niceities of [openpilot](https://github.com/commaai/openpilot), like high quality sensors, great camera, and good autostart and stop. Though unlike openpilot, it cannot control your car. chffrplus can interface with your car through a [panda](https://shop.comma.ai/products/panda-obd-ii-dongle), but just like our dashcam app [chffr](https://getchffr.com/), it is read only.
|
||||
|
||||
It integrates with the rest of the comma ecosystem, so you can view your drives on the [chffr](https://getchffr.com/) app for Android or iOS, and reverse engineer your car with [cabana](https://community.comma.ai/cabana/?demo=1).
|
||||
|
||||
|
||||
Hardware
|
||||
------
|
||||
|
||||
Right now chffrplus supports the [EON Dashcam DevKit](https://shop.comma.ai/products/eon-dashcam-devkit) for hardware to run on.
|
||||
|
||||
Install chffrplus on a EON device by entering ``https://chffrplus.comma.ai`` during NEOS setup.
|
||||
|
||||
|
||||
User Data / chffr Account / Crash Reporting
|
||||
------
|
||||
|
||||
By default chffrplus creates an account and includes a client for chffr, our dashcam app.
|
||||
|
||||
It's open source software, so you are free to disable it if you wish.
|
||||
|
||||
It logs the road facing camera, CAN, GPS, IMU, magnetometer, thermal sensors, crashes, and operating system logs.
|
||||
It does not log the user facing camera or the microphone.
|
||||
|
||||
By using it, you agree to [our privacy policy](https://beta.comma.ai/privacy.html). You understand that use of this software or its related services will generate certain types of user data, which may be logged and stored at the sole discretion of comma.ai. By accepting this agreement, you grant an irrevocable, perpetual, worldwide right to comma.ai for the use of this data.
|
||||
|
||||
|
||||
Licensing
|
||||
------
|
||||
|
||||
chffrplus is released under the MIT license.
|
||||
|
||||
+2
-48
@@ -1,54 +1,8 @@
|
||||
Version 0.7.2 (2020-02-07)
|
||||
========================
|
||||
* ECU firmware version based fingerprinting for Honda & Toyota
|
||||
* New driving model: improved path prediction during turns and lane changes and better lead speed tracking
|
||||
* Improve driver monitoring under extreme lighting and add low accuracy alert
|
||||
* Support for 2019 Rav4 Hybrid thanks to illumiN8i!
|
||||
* Support for 2016, 2017 and 2020 Lexus RX thanks to illumiN8i!
|
||||
* Support for 2020 Chrysler Pacifica Hybrid thanks to adhintz!
|
||||
|
||||
Version 0.7.1 (2020-01-20)
|
||||
========================
|
||||
* comma two support!
|
||||
* Lane Change Assist above 45 mph!
|
||||
* Replace zmq with custom messaging library, msgq!
|
||||
* Supercombo model: calibration and driving models are combined for better lead estimate
|
||||
* More robust updater thanks to jyoung8607! Requires NEOS update
|
||||
* Improve low speed ACC tuning
|
||||
|
||||
Version 0.7 (2019-12-13)
|
||||
========================
|
||||
* Move to SCons build system!
|
||||
* Add Lane Departure Warning (LDW) for all supported vehicles!
|
||||
* NEOS update: increase wifi speed thanks to jyoung8607!
|
||||
* Adaptive driver monitoring based on scene
|
||||
* New driving model trained end-to-end: improve lane lines and lead detection
|
||||
* Smarter torque limit alerts for all cars
|
||||
* Improve GM longitudinal control: proper computations for 15Hz radar
|
||||
* Move GM port, Toyota with DSU removed, comma pedal in community features; toggle switch required
|
||||
* Remove upload over cellular toggle: only upload qlog and qcamera files if not on wifi
|
||||
* Refactor Panda code towards ISO26262 and SIL2 compliancy
|
||||
* Forward stock FCW for Honda Nidec
|
||||
* Volkswagen port now standard: comma Harness intercepts stock camera
|
||||
|
||||
Version 0.6.6 (2019-11-05)
|
||||
========================
|
||||
* Volkswagen support thanks to jyoung8607!
|
||||
* Toyota Corolla Hybrid with TSS 2.0 support thanks to u8511049!
|
||||
* Lexus ES with TSS 2.0 support thanks to energee!
|
||||
* Fix GM ignition detection and lock safety mode not required anymore
|
||||
* Log panda firmware and dongle ID thanks to martinl!
|
||||
* New driving model: improve path prediction and lead detection
|
||||
* New driver monitoring model, 4x smaller and running on DSP
|
||||
* Display an alert and don't start openpilot if panda has wrong firmware
|
||||
* Fix bug preventing EON from terminating processes after a drive
|
||||
* Remove support for Toyota giraffe without the 120Ohm resistor
|
||||
|
||||
Version 0.6.5 (2019-10-07)
|
||||
========================
|
||||
* NEOS update: upgrade to Python3 and new installer!
|
||||
* comma Harness support!
|
||||
* New driving model: improve path prediction
|
||||
* New driving model: lateral control has lower reliance on lanelines
|
||||
* New driver monitoring model: more accurate face and eye detection
|
||||
* Redesign offroad screen to display updates and alerts
|
||||
* Increase maximum allowed acceleration
|
||||
@@ -108,7 +62,7 @@ Version 0.6 (2019-07-01)
|
||||
* Panda safety code is MISRA compliant and ships with a signed version on release2
|
||||
* New NEOS is 500MB smaller and has a reproducible usr/pipenv
|
||||
* Lexus ES Hybrid support thanks to wocsor!
|
||||
* Improve tuning for supported Toyota with TSS 2.0
|
||||
* Improve tuning for supported Toyota with TSS2
|
||||
* Various other stability improvements
|
||||
|
||||
Version 0.5.13 (2019-05-31)
|
||||
|
||||
@@ -1,26 +1,16 @@
|
||||
openpilot Safety
|
||||
======
|
||||
|
||||
openpilot is an Adaptive Cruise Control (ACC) and Automated Lane Centering (ALC) system.
|
||||
Like other ACC and ALC systems, openpilot is a failsafe passive system and it requires the
|
||||
driver to be alert and to pay attention at all times.
|
||||
openpilot is an Adaptive Cruise Control (ACC) and Lane Keeping Assist (LKA) system.
|
||||
Like other ACC and LKA systems, openpilot requires the driver to be alert and to
|
||||
pay attention at all times. We repeat, **driver alertness is necessary, but not
|
||||
sufficient, for openpilot to be used safely**.
|
||||
|
||||
In order to enforce driver alertness, openpilot includes a driver monitoring feature
|
||||
that alerts the driver when distracted.
|
||||
|
||||
However, even with an attentive driver, we must make further efforts for the system to be
|
||||
safe. We repeat, **driver alertness is necessary, but not sufficient, for openpilot to be
|
||||
used safely** and openpilot is provided with no warranty of fitness for any purpose.
|
||||
|
||||
openpilot is developed in good faith to be compliant with FMVSS requirements and to follow
|
||||
industry standards of safety for Level 2 Driver Assistance Systems. In particular, we observe
|
||||
ISO26262 guidelines, including those from [pertinent documents](https://www.nhtsa.gov/sites/nhtsa.dot.gov/files/documents/13498a_812_573_alcsystemreport.pdf)
|
||||
released by NHTSA. In addition, we impose strict coding guidelines (like [MISRA C : 2012](https://www.misra.org.uk/MISRAHome/MISRAC2012/tabid/196/Default.aspx))
|
||||
on parts of openpilot that are safety relevant. We also perform software-in-the-loop,
|
||||
hardware-in-the-loop and in-vehicle tests before each software release.
|
||||
|
||||
Following Hazard and Risk Analysis and FMEA, at a very high level, we have designed openpilot
|
||||
ensuring two main safety requirements.
|
||||
safe. We have designed openpilot with two other safety considerations.
|
||||
|
||||
1. The driver must always be capable to immediately retake manual control of the vehicle,
|
||||
by stepping on either pedal or by pressing the cancel button.
|
||||
@@ -28,7 +18,134 @@ ensuring two main safety requirements.
|
||||
react. This means that while the system is engaged, the actuators are constrained
|
||||
to operate within reasonable limits.
|
||||
|
||||
For vehicle specific implementation of the safety concept, refer to `panda/board/safety/`.
|
||||
Following are details of the car specific safety implementations:
|
||||
|
||||
Honda/Acura
|
||||
------
|
||||
|
||||
- While the system is engaged, gas, brake and steer commands are subject to the same limits used by
|
||||
the stock system.
|
||||
|
||||
- Without an interceptor, the gas is controlled by the Powertrain Control Module (PCM).
|
||||
The PCM limits acceleration to what is reasonable for a cruise control system. With an
|
||||
interceptor, the gas is clipped to 60%.
|
||||
|
||||
- The brake is controlled by the 0x1FA CAN message. This message allows full
|
||||
braking, although the panda firmware and openpilot clip it to 1/4th of the max.
|
||||
This is approximately 0.3g of braking.
|
||||
|
||||
- Steering is controlled by the 0xE4 CAN message. The Electronic Power Steering (EPS)
|
||||
controller in the car limits the torque to a very small amount, so regardless of the
|
||||
message, the controller cannot jerk the wheel.
|
||||
|
||||
- Brake and gas pedal pressed signals are contained in the 0x17C CAN message. A rising edge of
|
||||
either signals triggers a disengagement, which is enforced by the panda firmware and by openpilot. The
|
||||
white led on the panda signifies if the panda is allowing control messages.
|
||||
|
||||
- Honda CAN uses both a counter and a checksum to ensure integrity and prevent
|
||||
replay of the same message.
|
||||
|
||||
Toyota/Lexus
|
||||
------
|
||||
|
||||
- While the system is engaged, gas, brake and steer commands are subject to the same limits used by
|
||||
the stock system.
|
||||
|
||||
- With the stock Driving Support Unit (DSU) connected (or in DSU-less models like Camry and C-HR),
|
||||
the acceleration is controlled by the stock system and is subject to the stock adaptive cruise
|
||||
control limits. Without the stock DSU connected, the acceleration command is controlled by the
|
||||
0x343 CAN message and its value is limited between .3g of deceleration and .15g of acceleration
|
||||
by the panda firmware and by openpilot. The acceleration command is ignored by the Engine Control
|
||||
Module (ECM) while the cruise control system is disengaged.
|
||||
|
||||
- Steering torque is controlled through the 0x2E4 CAN message and it's limited by the panda firmware and by
|
||||
openpilot to a value between -1500 and 1500. In addition, the vehicle EPS unit will not respond to
|
||||
commands outside these limits. A steering torque rate limit is enforced by the panda firmware and by
|
||||
openpilot, so that the commanded steering torque must rise from 0 to max value no faster than
|
||||
1.5s. Commanded steering torque is limited by the panda firmware and by openpilot to be no more than 350
|
||||
units above the actual EPS generated motor torque to ensure limited differences between
|
||||
commanded and actual torques.
|
||||
|
||||
- Brake and gas pedal pressed signals are contained in the 0x224 and 0x1D2 CAN messages,
|
||||
respectively. A rising edge of either signals triggers a disengagement, which is enforced by the
|
||||
panda firmware and by openpilot. Additionally, the cruise control system disengages on the rising edge of
|
||||
the brake pedal pressed signal.
|
||||
|
||||
- The cruise control system state is contained in the 0x1D2 message. No control messages are
|
||||
allowed if the cruise control system is not active. This is enforced by openpilot and the
|
||||
panda firmware. The white led on the panda signifies if the panda is allowing control messages.
|
||||
|
||||
GM/Chevrolet
|
||||
------
|
||||
|
||||
- While the system is engaged, gas, brake and steer commands are subject to the same limits used by
|
||||
the stock system.
|
||||
|
||||
- The gas and regen are controlled by the 0x2CB message and it's limited by the panda firmware and by
|
||||
openpilot to a value between 1404 and 3072. the minimum value correspond to a mild decel due to regen,
|
||||
while 3072 correspond to approximately 0.18g of acceleration from stop.
|
||||
|
||||
- The friction brakes are controlled by the 0x315 message and its value is limited by the panda firmware
|
||||
and openpilot to 350. This is approximately 0.3g of braking.
|
||||
|
||||
- Steering torque is controlled through the 0x180 CAN message and it's limited by the panda firmware and by
|
||||
openpilot to a value between -300 and 300. In addition, the vehicle EPS unit will fault for
|
||||
commands outside these limits. A steering torque rate limit is enforced by the panda firmware and by
|
||||
openpilot, so that the commanded steering torque must rise from 0 to max value no faster than
|
||||
0.75s. Commanded steering torque is gradually limited by the panda firmware and by openpilot if the driver's
|
||||
torque exceeds 12 units in the opposite dicrection to ensure limited applied torque against the
|
||||
driver's will.
|
||||
|
||||
- Brake pedal and gas pedal potentiometer signals are contained in the 0xF1 and 0x1A1 CAN messages,
|
||||
respectively. A rising edge of either signals triggers a disengagement, which is enforced by the
|
||||
panda firmware and by openpilot. Additionally, the cruise control system disengages on the rising edge of
|
||||
the brake pedal pressed signal. The regen paddle pressed signal is in the 0xBD message. When the
|
||||
regen paddle is pressed, a disengagement is enforced by both the firmware and by openpilot.
|
||||
|
||||
- GM CAN uses both a counter and a checksum to ensure integrity and prevent
|
||||
replay of the same message.
|
||||
|
||||
Hyundai/Kia (Lateral only)
|
||||
------
|
||||
|
||||
- While the system is engaged, steer commands are subject to the same limits used by
|
||||
the stock system.
|
||||
|
||||
- Steering torque is controlled through the 0x340 CAN message and it's limited by the panda firmware and by
|
||||
openpilot to a value between -255 and 255. In addition, the vehicle EPS unit will fault for
|
||||
commands outside the values of -409 and 409. A steering torque rate limit is enforced by the panda firmware and by
|
||||
openpilot, so that the commanded steering torque must rise from 0 to max value no faster than
|
||||
0.85s. Commanded steering torque is gradually limited by the panda firmware and by openpilot if the driver's
|
||||
torque exceeds 50 units in the opposite dicrection to ensure limited applied torque against the
|
||||
driver's will.
|
||||
|
||||
Chrysler/Jeep/Fiat (Lateral only)
|
||||
------
|
||||
|
||||
- While the system is engaged, steer commands are subject to the same limits used by
|
||||
the stock system.
|
||||
|
||||
- Steering torque is controlled through the 0x292 CAN message and it's limited by the panda firmware and by
|
||||
openpilot to a value between -261 and 261. In addition, the vehicle EPS unit will fault for
|
||||
commands outside these limits. A steering torque rate limit is enforced by the panda firmware and by
|
||||
openpilot, so that the commanded steering torque must rise from 0 to max value no faster than
|
||||
0.87s. Commanded steering torque is limited by the panda firmware and by openpilot to be no more than 80
|
||||
units above the actual EPS generated motor torque to ensure limited differences between
|
||||
commanded and actual torques.
|
||||
|
||||
Subaru (Lateral only)
|
||||
------
|
||||
|
||||
- While the system is engaged, steer commands are subject to the same limits used by
|
||||
the stock system.
|
||||
|
||||
- Steering torque is controlled through the 0x122 CAN message and it's limited by the panda firmware and by
|
||||
openpilot to a value between -255 and 255. In addition, the vehicle EPS unit will fault for
|
||||
commands outside the values of -2047 and 2047. A steering torque rate limit is enforced by the panda firmware and by
|
||||
openpilot, so that the commanded steering torque must rise from 0 to max value no faster than
|
||||
0.41s. Commanded steering torque is gradually limited by the panda firmware and by openpilot if the driver's
|
||||
torque exceeds 60 units in the opposite dicrection to ensure limited applied torque against the
|
||||
driver's will.
|
||||
|
||||
**Extra note**: comma.ai strongly discourages the use of openpilot forks with safety code either missing or
|
||||
not fully meeting the above requirements.
|
||||
|
||||
-232
@@ -1,232 +0,0 @@
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import platform
|
||||
|
||||
AddOption('--test',
|
||||
action='store_true',
|
||||
help='build test files')
|
||||
|
||||
AddOption('--asan',
|
||||
action='store_true',
|
||||
help='turn on ASAN')
|
||||
|
||||
arch = subprocess.check_output(["uname", "-m"], encoding='utf8').rstrip()
|
||||
if platform.system() == "Darwin":
|
||||
arch = "Darwin"
|
||||
|
||||
if arch == "aarch64":
|
||||
lenv = {
|
||||
"LD_LIBRARY_PATH": '/data/data/com.termux/files/usr/lib',
|
||||
"PATH": os.environ['PATH'],
|
||||
"ANDROID_DATA": os.environ['ANDROID_DATA'],
|
||||
"ANDROID_ROOT": os.environ['ANDROID_ROOT'],
|
||||
}
|
||||
|
||||
cpppath = [
|
||||
"#phonelibs/opencl/include",
|
||||
]
|
||||
libpath = [
|
||||
"#phonelibs/snpe/aarch64-android-clang3.8",
|
||||
"/usr/lib",
|
||||
"/data/data/com.termux/files/usr/lib",
|
||||
"/system/vendor/lib64",
|
||||
"/system/comma/usr/lib",
|
||||
"#phonelibs/nanovg",
|
||||
"#phonelibs/libyuv/lib",
|
||||
]
|
||||
|
||||
cflags = ["-DQCOM", "-mcpu=cortex-a57"]
|
||||
cxxflags = ["-DQCOM", "-mcpu=cortex-a57"]
|
||||
|
||||
rpath = ["/system/vendor/lib64"]
|
||||
else:
|
||||
lenv = {
|
||||
"PATH": "#external/bin:" + os.environ['PATH'],
|
||||
}
|
||||
cpppath = [
|
||||
"#phonelibs/capnp-cpp/include",
|
||||
"#phonelibs/capnp-c/include",
|
||||
"#phonelibs/zmq/x64/include",
|
||||
"#external/tensorflow/include",
|
||||
]
|
||||
|
||||
if arch == "Darwin":
|
||||
libpath = [
|
||||
"#phonelibs/capnp-cpp/mac/lib",
|
||||
"#phonelibs/capnp-c/mac/lib",
|
||||
"#phonelibs/libyuv/mac/lib",
|
||||
"#cereal",
|
||||
"#selfdrive/common",
|
||||
"/usr/local/lib",
|
||||
"/System/Library/Frameworks/OpenGL.framework/Libraries",
|
||||
]
|
||||
else:
|
||||
libpath = [
|
||||
"#phonelibs/capnp-cpp/x64/lib",
|
||||
"#phonelibs/capnp-c/x64/lib",
|
||||
"#phonelibs/snpe/x86_64-linux-clang",
|
||||
"#phonelibs/zmq/x64/lib",
|
||||
"#phonelibs/libyuv/x64/lib",
|
||||
"#external/zmq/lib",
|
||||
"#external/tensorflow/lib",
|
||||
"#cereal",
|
||||
"#selfdrive/common",
|
||||
"/usr/lib",
|
||||
"/usr/local/lib",
|
||||
]
|
||||
|
||||
rpath = ["phonelibs/capnp-cpp/x64/lib",
|
||||
"phonelibs/zmq/x64/lib",
|
||||
"external/tensorflow/lib",
|
||||
"cereal",
|
||||
"selfdrive/common"]
|
||||
|
||||
# allows shared libraries to work globally
|
||||
rpath = [os.path.join(os.getcwd(), x) for x in rpath]
|
||||
|
||||
cflags = []
|
||||
cxxflags = []
|
||||
|
||||
ccflags_asan = ["-fsanitize=address", "-fno-omit-frame-pointer"] if GetOption('asan') else []
|
||||
ldflags_asan = ["-fsanitize=address"] if GetOption('asan') else []
|
||||
|
||||
# change pythonpath to this
|
||||
lenv["PYTHONPATH"] = Dir("#").path
|
||||
|
||||
env = Environment(
|
||||
ENV=lenv,
|
||||
CCFLAGS=[
|
||||
"-g",
|
||||
"-fPIC",
|
||||
"-O2",
|
||||
"-Werror=implicit-function-declaration",
|
||||
"-Werror=incompatible-pointer-types",
|
||||
"-Werror=int-conversion",
|
||||
"-Werror=return-type",
|
||||
"-Werror=format-extra-args",
|
||||
] + cflags + ccflags_asan,
|
||||
|
||||
CPPPATH=cpppath + [
|
||||
"#",
|
||||
"#selfdrive",
|
||||
"#phonelibs/bzip2",
|
||||
"#phonelibs/libyuv/include",
|
||||
"#phonelibs/openmax/include",
|
||||
"#phonelibs/json/src",
|
||||
"#phonelibs/json11",
|
||||
"#phonelibs/eigen",
|
||||
"#phonelibs/curl/include",
|
||||
"#phonelibs/opencv/include",
|
||||
"#phonelibs/libgralloc/include",
|
||||
"#phonelibs/android_frameworks_native/include",
|
||||
"#phonelibs/android_hardware_libhardware/include",
|
||||
"#phonelibs/android_system_core/include",
|
||||
"#phonelibs/linux/include",
|
||||
"#phonelibs/snpe/include",
|
||||
"#phonelibs/nanovg",
|
||||
"#selfdrive/common",
|
||||
"#selfdrive/camerad",
|
||||
"#selfdrive/camerad/include",
|
||||
"#selfdrive/loggerd/include",
|
||||
"#selfdrive/modeld",
|
||||
"#cereal/messaging",
|
||||
"#cereal",
|
||||
"#opendbc/can",
|
||||
],
|
||||
|
||||
CC='clang',
|
||||
CXX='clang++',
|
||||
LINKFLAGS=ldflags_asan,
|
||||
|
||||
RPATH=rpath,
|
||||
|
||||
CFLAGS=["-std=gnu11"] + cflags,
|
||||
CXXFLAGS=["-std=c++14"] + cxxflags,
|
||||
LIBPATH=libpath +
|
||||
[
|
||||
"#cereal",
|
||||
"#selfdrive/common",
|
||||
"#phonelibs",
|
||||
]
|
||||
)
|
||||
|
||||
if os.environ.get('SCONS_CACHE'):
|
||||
CacheDir('/tmp/scons_cache')
|
||||
|
||||
node_interval = 5
|
||||
node_count = 0
|
||||
def progress_function(node):
|
||||
global node_count
|
||||
node_count += node_interval
|
||||
sys.stderr.write("progress: %d\n" % node_count)
|
||||
|
||||
if os.environ.get('SCONS_PROGRESS'):
|
||||
Progress(progress_function, interval=node_interval)
|
||||
|
||||
SHARED = False
|
||||
|
||||
def abspath(x):
|
||||
if arch == 'aarch64':
|
||||
pth = os.path.join("/data/pythonpath", x[0].path)
|
||||
env.Depends(pth, x)
|
||||
return File(pth)
|
||||
else:
|
||||
# rpath works elsewhere
|
||||
return x[0].path.rsplit("/", 1)[1][:-3]
|
||||
|
||||
#zmq = 'zmq'
|
||||
# still needed for apks
|
||||
zmq = FindFile("libzmq.a", libpath)
|
||||
Export('env', 'arch', 'zmq', 'SHARED')
|
||||
|
||||
# cereal and messaging are shared with the system
|
||||
SConscript(['cereal/SConscript'])
|
||||
if SHARED:
|
||||
cereal = abspath([File('cereal/libcereal_shared.so')])
|
||||
messaging = abspath([File('cereal/libmessaging_shared.so')])
|
||||
else:
|
||||
cereal = [File('#cereal/libcereal.a')]
|
||||
messaging = [File('#cereal/libmessaging.a')]
|
||||
Export('cereal', 'messaging')
|
||||
|
||||
SConscript(['selfdrive/common/SConscript'])
|
||||
Import('_common', '_visionipc', '_gpucommon', '_gpu_libs')
|
||||
|
||||
if SHARED:
|
||||
common, visionipc, gpucommon = abspath(common), abspath(visionipc), abspath(gpucommon)
|
||||
else:
|
||||
common = [_common, 'json']
|
||||
visionipc = _visionipc
|
||||
gpucommon = [_gpucommon] + _gpu_libs
|
||||
|
||||
Export('common', 'visionipc', 'gpucommon')
|
||||
|
||||
SConscript(['opendbc/can/SConscript'])
|
||||
|
||||
SConscript(['common/SConscript'])
|
||||
SConscript(['common/kalman/SConscript'])
|
||||
SConscript(['phonelibs/SConscript'])
|
||||
|
||||
if arch != "Darwin":
|
||||
SConscript(['selfdrive/camerad/SConscript'])
|
||||
SConscript(['selfdrive/modeld/SConscript'])
|
||||
|
||||
SConscript(['selfdrive/controls/lib/cluster/SConscript'])
|
||||
SConscript(['selfdrive/controls/lib/lateral_mpc/SConscript'])
|
||||
SConscript(['selfdrive/controls/lib/longitudinal_mpc/SConscript'])
|
||||
|
||||
SConscript(['selfdrive/boardd/SConscript'])
|
||||
SConscript(['selfdrive/proclogd/SConscript'])
|
||||
|
||||
SConscript(['selfdrive/ui/SConscript'])
|
||||
SConscript(['selfdrive/loggerd/SConscript'])
|
||||
|
||||
if arch == "aarch64":
|
||||
SConscript(['selfdrive/logcatd/SConscript'])
|
||||
SConscript(['selfdrive/sensord/SConscript'])
|
||||
SConscript(['selfdrive/clocksd/SConscript'])
|
||||
|
||||
SConscript(['selfdrive/locationd/SConscript'])
|
||||
|
||||
# TODO: finish cereal, dbcbuilder, MPC
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
-11
@@ -1,11 +0,0 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
mode=$1
|
||||
if [ $1 -eq 1 ]; then
|
||||
printf %s "1" > /data/params/d/DragonBTG
|
||||
fi
|
||||
if [ $1 -eq 0 ]; then
|
||||
printf %s "0" > /data/params/d/DragonBTG
|
||||
fi
|
||||
|
||||
rm -rf /data/openpilot/selfdrive/boardd/boardd && reboot
|
||||
@@ -1 +0,0 @@
|
||||
.sconsign.dblite
|
||||
@@ -3,12 +3,4 @@ node_modules
|
||||
package-lock.json
|
||||
*.pyc
|
||||
__pycache__
|
||||
.*.swp
|
||||
.*.swo
|
||||
libcereal*.a
|
||||
libmessaging.*
|
||||
libmessaging_shared.*
|
||||
services.h
|
||||
.sconsign.dblite
|
||||
libcereal_shared.*
|
||||
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
from ubuntu:16.04
|
||||
|
||||
RUN apt-get update && apt-get install -y libzmq3-dev clang wget git autoconf libtool curl make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl
|
||||
|
||||
RUN curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
|
||||
ENV PATH="/root/.pyenv/bin:/root/.pyenv/shims:${PATH}"
|
||||
RUN pyenv install 3.7.3
|
||||
RUN pyenv global 3.7.3
|
||||
RUN pyenv rehash
|
||||
RUN pip3 install pyyaml==5.1.2 Cython==0.29.14 scons==3.1.1 pycapnp==0.6.4
|
||||
|
||||
WORKDIR /project/cereal
|
||||
COPY install_capnp.sh .
|
||||
RUN ./install_capnp.sh
|
||||
|
||||
ENV PYTHONPATH=/project
|
||||
|
||||
COPY . .
|
||||
RUN scons -c && scons -j$(nproc)
|
||||
@@ -0,0 +1,62 @@
|
||||
PWD := $(shell pwd)
|
||||
|
||||
SRCS := log.capnp car.capnp
|
||||
|
||||
GENS := gen/cpp/car.capnp.c++ gen/cpp/log.capnp.c++
|
||||
JS := gen/js/car.capnp.js gen/js/log.capnp.js
|
||||
|
||||
UNAME_M ?= $(shell uname -m)
|
||||
|
||||
GENS += gen/c/car.capnp.c gen/c/log.capnp.c gen/c/include/c++.capnp.h gen/c/include/java.capnp.h
|
||||
|
||||
ifeq ($(UNAME_M),x86_64)
|
||||
|
||||
ifneq (, $(shell which capnpc-java))
|
||||
GENS += gen/java/Car.java gen/java/Log.java
|
||||
else
|
||||
$(warning capnpc-java not found, skipping java build)
|
||||
endif
|
||||
|
||||
endif
|
||||
|
||||
|
||||
ifeq ($(UNAME_M),aarch64)
|
||||
CAPNPC=PATH=$(PWD)/../phonelibs/capnp-cpp/aarch64/bin/:$$PATH capnpc
|
||||
else
|
||||
CAPNPC=capnpc
|
||||
endif
|
||||
|
||||
.PHONY: all
|
||||
all: $(GENS)
|
||||
js: $(JS)
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -rf gen
|
||||
rm -rf node_modules
|
||||
rm -rf package-lock.json
|
||||
|
||||
gen/c/%.capnp.c: %.capnp
|
||||
@echo "[ CAPNPC C ] $@"
|
||||
mkdir -p gen/c/
|
||||
$(CAPNPC) '$<' -o c:gen/c/
|
||||
|
||||
gen/js/%.capnp.js: %.capnp
|
||||
@echo "[ CAPNPC JavaScript ] $@"
|
||||
mkdir -p gen/js/
|
||||
sh ./generate_javascript.sh
|
||||
|
||||
gen/cpp/%.capnp.c++: %.capnp
|
||||
@echo "[ CAPNPC C++ ] $@"
|
||||
mkdir -p gen/cpp/
|
||||
$(CAPNPC) '$<' -o c++:gen/cpp/
|
||||
|
||||
gen/java/Car.java gen/java/Log.java: $(SRCS)
|
||||
@echo "[ CAPNPC java ] $@"
|
||||
mkdir -p gen/java/
|
||||
$(CAPNPC) $^ -o java:gen/java
|
||||
|
||||
# c-capnproto needs some empty headers
|
||||
gen/c/include/c++.capnp.h gen/c/include/java.capnp.h:
|
||||
mkdir -p gen/c/include
|
||||
touch '$@'
|
||||
@@ -1,42 +0,0 @@
|
||||
What is cereal?
|
||||
----
|
||||
|
||||
cereal is both a messaging spec for robotics systems as well as generic high performance IPC pub sub messaging with a single publisher and multiple subscribers.
|
||||
|
||||
Imagine this use case:
|
||||
* A sensor process reads gyro measurements directly from an IMU and publishes a sensorEvents packet
|
||||
* A calibration process subscribes to the sensorEvents packet to use the IMU
|
||||
* A localization process subscribes to the sensorEvents packet to use the IMU also
|
||||
|
||||
|
||||
Messaging Spec
|
||||
----
|
||||
|
||||
You'll find the message types in [log.capnp](log.capnp). It uses [Cap'n proto](https://capnproto.org/capnp-tool.html) and defines one struct called Event.
|
||||
|
||||
All Events have a logMonoTime and a valid. Then a big union defines the packet type.
|
||||
|
||||
|
||||
Pub Sub Backends
|
||||
----
|
||||
|
||||
cereal supports two backends, one based on [zmq](https://zeromq.org/), the other called msgq, a custom pub sub based on shared memory that doesn't require the bytes to pass through the kernel.
|
||||
|
||||
Example
|
||||
---
|
||||
```python
|
||||
import cereal.messaging as messaging
|
||||
|
||||
# in subscriber
|
||||
sm = messaging.SubMaster(['sensorEvents'])
|
||||
while 1:
|
||||
sm.update()
|
||||
print(sm['sensorEvents'])
|
||||
|
||||
# in publisher
|
||||
pm = messaging.PubMaster(['sensorEvents'])
|
||||
dat = messaging.new_message()
|
||||
dat.init('sensorEvents', 1)
|
||||
dat.sensorEvents[0] = {"gyro": {"v": [0.1, -0.1, 0.1]}}
|
||||
pm.send('sensorEvents', dat)
|
||||
```
|
||||
@@ -1,68 +0,0 @@
|
||||
Import('env', 'arch', 'zmq')
|
||||
|
||||
gen_dir = Dir('gen')
|
||||
messaging_dir = Dir('messaging')
|
||||
|
||||
# TODO: remove src-prefix and cereal from command string. can we set working directory?
|
||||
env.Command(["gen/c/include/c++.capnp.h", "gen/c/include/java.capnp.h"], [], "mkdir -p " + gen_dir.path + "/c/include && touch $TARGETS")
|
||||
env.Command(
|
||||
['gen/c/car.capnp.c', 'gen/c/log.capnp.c', 'gen/c/car.capnp.h', 'gen/c/log.capnp.h'],
|
||||
['car.capnp', 'log.capnp'],
|
||||
'capnpc $SOURCES --src-prefix=cereal -o c:' + gen_dir.path + '/c/')
|
||||
env.Command(
|
||||
['gen/cpp/car.capnp.c++', 'gen/cpp/log.capnp.c++', 'gen/cpp/car.capnp.h', 'gen/cpp/log.capnp.h'],
|
||||
['car.capnp', 'log.capnp'],
|
||||
'capnpc $SOURCES --src-prefix=cereal -o c++:' + gen_dir.path + '/cpp/')
|
||||
import shutil
|
||||
if shutil.which('capnpc-java'):
|
||||
env.Command(
|
||||
['gen/java/Car.java', 'gen/java/Log.java'],
|
||||
['car.capnp', 'log.capnp'],
|
||||
'capnpc $SOURCES --src-prefix=cereal -o java:' + gen_dir.path + '/java/')
|
||||
|
||||
# TODO: remove non shared cereal and messaging
|
||||
cereal_objects = env.SharedObject([
|
||||
'gen/c/car.capnp.c',
|
||||
'gen/c/log.capnp.c',
|
||||
'gen/cpp/car.capnp.c++',
|
||||
'gen/cpp/log.capnp.c++',
|
||||
])
|
||||
|
||||
env.Library('cereal', cereal_objects)
|
||||
env.SharedLibrary('cereal_shared', cereal_objects, LIBS=["capnp_c"])
|
||||
|
||||
cereal_dir = Dir('.')
|
||||
services_h = env.Command(
|
||||
['services.h'],
|
||||
['service_list.yaml', 'services.py'],
|
||||
'python3 ' + cereal_dir.path + '/services.py > $TARGET')
|
||||
|
||||
messaging_objects = env.SharedObject([
|
||||
'messaging/messaging.cc',
|
||||
'messaging/impl_zmq.cc',
|
||||
'messaging/impl_msgq.cc',
|
||||
'messaging/msgq.cc',
|
||||
])
|
||||
|
||||
messaging_lib = env.Library('messaging', messaging_objects)
|
||||
Depends('messaging/impl_zmq.cc', services_h)
|
||||
|
||||
# note, this rebuilds the deps shared, zmq is statically linked to make APK happy
|
||||
# TODO: get APK to load system zmq to remove the static link
|
||||
shared_lib_shared_lib = [zmq, 'm', 'stdc++'] + ["gnustl_shared"] if arch == "aarch64" else [zmq]
|
||||
env.SharedLibrary('messaging_shared', messaging_objects, LIBS=shared_lib_shared_lib)
|
||||
|
||||
env.Program('messaging/bridge', ['messaging/bridge.cc'], LIBS=[messaging_lib, 'zmq'])
|
||||
Depends('messaging/bridge.cc', services_h)
|
||||
|
||||
# different target?
|
||||
#env.Program('messaging/demo', ['messaging/demo.cc'], LIBS=[messaging_lib, 'zmq'])
|
||||
|
||||
|
||||
env.Command(['messaging/messaging_pyx.so'],
|
||||
[messaging_lib, 'messaging/messaging_pyx_setup.py', 'messaging/messaging_pyx.pyx', 'messaging/messaging.pxd'],
|
||||
"cd " + messaging_dir.path + " && python3 messaging_pyx_setup.py build_ext --inplace")
|
||||
|
||||
|
||||
if GetOption('test'):
|
||||
env.Program('messaging/test_runner', ['messaging/test_runner.cc', 'messaging/msgq_tests.cc'], LIBS=[messaging_lib])
|
||||
@@ -1,49 +0,0 @@
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
zmq = 'zmq'
|
||||
arch = subprocess.check_output(["uname", "-m"], encoding='utf8').rstrip()
|
||||
|
||||
cereal_dir = Dir('.')
|
||||
|
||||
cpppath = [
|
||||
cereal_dir,
|
||||
'/usr/lib/include',
|
||||
]
|
||||
|
||||
AddOption('--test',
|
||||
action='store_true',
|
||||
help='build test files')
|
||||
|
||||
AddOption('--asan',
|
||||
action='store_true',
|
||||
help='turn on ASAN')
|
||||
|
||||
ccflags_asan = ["-fsanitize=address", "-fno-omit-frame-pointer"] if GetOption('asan') else []
|
||||
ldflags_asan = ["-fsanitize=address"] if GetOption('asan') else []
|
||||
|
||||
env = Environment(
|
||||
ENV=os.environ,
|
||||
CC='clang',
|
||||
CXX='clang++',
|
||||
CCFLAGS=[
|
||||
"-g",
|
||||
"-fPIC",
|
||||
"-O2",
|
||||
"-Werror=implicit-function-declaration",
|
||||
"-Werror=incompatible-pointer-types",
|
||||
"-Werror=int-conversion",
|
||||
"-Werror=return-type",
|
||||
"-Werror=format-extra-args",
|
||||
] + ccflags_asan,
|
||||
LDFLAGS=ldflags_asan,
|
||||
LINKFLAGS=ldflags_asan,
|
||||
|
||||
CFLAGS="-std=gnu11",
|
||||
CXXFLAGS="-std=c++14",
|
||||
CPPPATH=cpppath,
|
||||
)
|
||||
|
||||
|
||||
Export('env', 'zmq', 'arch')
|
||||
SConscript(['SConscript'])
|
||||
@@ -1,14 +0,0 @@
|
||||
pr: none
|
||||
|
||||
pool:
|
||||
vmImage: 'ubuntu-16.04'
|
||||
|
||||
steps:
|
||||
- script: |
|
||||
set -e
|
||||
docker build -t cereal .
|
||||
docker run cereal bash -c "scons --test --asan -j$(nproc) && messaging/test_runner"
|
||||
docker run cereal bash -c "ZMQ=1 python -m unittest discover ."
|
||||
docker run cereal bash -c "MSGQ=1 python -m unittest discover ."
|
||||
|
||||
displayName: 'Run Tests'
|
||||
+10
-61
@@ -84,21 +84,9 @@ struct CarEvent @0x9b1657f34caf3ad3 {
|
||||
laneChange @59;
|
||||
invalidGiraffeToyota @60;
|
||||
internetConnectivityNeeded @61;
|
||||
communityFeatureDisallowed @62;
|
||||
lowMemory @63;
|
||||
stockAeb @64;
|
||||
ldw @65;
|
||||
carUnrecognized @66;
|
||||
radarCommIssue @67;
|
||||
driverMonitorLowAcc @68;
|
||||
# dragonpilot
|
||||
manualSteeringRequired @69;
|
||||
manualSteeringRequiredBlinkersOn @70;
|
||||
leadCarMoving @71;
|
||||
leadCarDetected @72;
|
||||
preAutoLaneChangeLeft @73;
|
||||
preAutoLaneChangeRight @74;
|
||||
autoLaneChange @75;
|
||||
manualSteeringRequired @62;
|
||||
manualSteeringRequiredBlinkersOn @63;
|
||||
leadCarMoving @64;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,9 +120,6 @@ struct CarState {
|
||||
steeringTorque @8 :Float32; # TODO: standardize units
|
||||
steeringTorqueEps @27 :Float32; # TODO: standardize units
|
||||
steeringPressed @9 :Bool; # if the user is using the steering wheel
|
||||
steeringRateLimited @29 :Bool; # if the torque is limited by the rate limiter
|
||||
stockAeb @30 :Bool;
|
||||
stockFcw @31 :Bool;
|
||||
|
||||
# cruise state
|
||||
cruiseState @10 :CruiseState;
|
||||
@@ -188,6 +173,7 @@ struct CarState {
|
||||
manumatic @9;
|
||||
}
|
||||
|
||||
|
||||
# send on change
|
||||
struct ButtonEvent {
|
||||
pressed @0 :Bool;
|
||||
@@ -331,7 +317,7 @@ struct CarParams {
|
||||
minEnableSpeed @7 :Float32;
|
||||
minSteerSpeed @8 :Float32;
|
||||
safetyModel @9 :SafetyModel;
|
||||
safetyModelPassive @42 :SafetyModel = silent;
|
||||
safetyModelPassive @42 :SafetyModel = noOutput;
|
||||
safetyParam @10 :Int16;
|
||||
|
||||
steerMaxBP @11 :List(Float32);
|
||||
@@ -341,6 +327,7 @@ struct CarParams {
|
||||
brakeMaxBP @15 :List(Float32);
|
||||
brakeMaxV @16 :List(Float32);
|
||||
|
||||
|
||||
# things about the car in the manual
|
||||
mass @17 :Float32; # [kg] running weight
|
||||
wheelbase @18 :Float32; # [m] distance from rear to front axle
|
||||
@@ -354,7 +341,6 @@ struct CarParams {
|
||||
tireStiffnessRear @24 :Float32; # [N/rad] rear tire coeff of stiff
|
||||
|
||||
longitudinalTuning @25 :LongitudinalPIDTuning;
|
||||
lateralParams @48 :LateralParams;
|
||||
lateralTuning :union {
|
||||
pid @26 :LateralPIDTuning;
|
||||
indi @27 :LateralINDITuning;
|
||||
@@ -362,7 +348,6 @@ struct CarParams {
|
||||
}
|
||||
|
||||
steerLimitAlert @28 :Bool;
|
||||
steerLimitTimer @47 :Float32; # time before steerLimitAlert is issued
|
||||
|
||||
vEgoStopping @29 :Float32; # Speed at which the car goes into stopping state
|
||||
directAccelControl @30 :Bool; # Does the car have direct accel control or just gas/brake
|
||||
@@ -378,15 +363,6 @@ struct CarParams {
|
||||
isPandaBlack @39: Bool;
|
||||
dashcamOnly @41: Bool;
|
||||
transmissionType @43 :TransmissionType;
|
||||
carFw @44 :List(CarFw);
|
||||
radarTimeStep @45: Float32 = 0.05; # time delta between radar updates, 20Hz is very standard
|
||||
communityFeature @46: Bool; # true if a community maintained feature is detected
|
||||
fingerprintSource @49: FingerprintSource;
|
||||
|
||||
struct LateralParams {
|
||||
torqueBP @0 :List(Int32);
|
||||
torqueV @1 :List(Int32);
|
||||
}
|
||||
|
||||
struct LateralPIDTuning {
|
||||
kpBP @0 :List(Float32);
|
||||
@@ -405,6 +381,7 @@ struct CarParams {
|
||||
deadzoneV @5 :List(Float32);
|
||||
}
|
||||
|
||||
|
||||
struct LateralINDITuning {
|
||||
outerLoopGain @0 :Float32;
|
||||
innerLoopGain @1 :Float32;
|
||||
@@ -427,12 +404,12 @@ struct CarParams {
|
||||
}
|
||||
|
||||
enum SafetyModel {
|
||||
silent @0;
|
||||
hondaNidec @1;
|
||||
noOutput @0;
|
||||
honda @1;
|
||||
toyota @2;
|
||||
elm327 @3;
|
||||
gm @4;
|
||||
hondaBoschGiraffe @5;
|
||||
hondaBosch @5;
|
||||
ford @6;
|
||||
cadillac @7;
|
||||
hyundai @8;
|
||||
@@ -446,9 +423,6 @@ struct CarParams {
|
||||
toyotaIpas @16;
|
||||
allOutput @17;
|
||||
gmAscm @18;
|
||||
noOutput @19; # like silent but without silent CAN TXs
|
||||
hondaBoschHarness @20;
|
||||
volkswagenPq @21;
|
||||
}
|
||||
|
||||
enum SteerControlType {
|
||||
@@ -461,29 +435,4 @@ struct CarParams {
|
||||
automatic @1;
|
||||
manual @2;
|
||||
}
|
||||
|
||||
struct CarFw {
|
||||
ecu @0 :Ecu;
|
||||
fwVersion @1 :Data;
|
||||
address @2: UInt32;
|
||||
subAddress @3: UInt8;
|
||||
}
|
||||
|
||||
enum Ecu {
|
||||
eps @0;
|
||||
esp @1;
|
||||
fwdRadar @2;
|
||||
fwdCamera @3;
|
||||
engine @4;
|
||||
unknown @5;
|
||||
|
||||
# Toyota only
|
||||
dsu @6;
|
||||
apgs @7;
|
||||
}
|
||||
|
||||
enum FingerprintSource {
|
||||
can @0;
|
||||
fw @1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,7 @@ tar xvf capnproto-c++-${VERSION}.tar.gz
|
||||
cd capnproto-c++-${VERSION}
|
||||
CXXFLAGS="-fPIC" ./configure
|
||||
|
||||
make -j$(nproc)
|
||||
make install
|
||||
make -j4
|
||||
|
||||
# manually build binaries statically
|
||||
g++ -std=gnu++11 -I./src -I./src -DKJ_HEADER_WARNINGS -DCAPNP_HEADER_WARNINGS -DCAPNP_INCLUDE_DIR=\"/usr/local/include\" -pthread -O2 -DNDEBUG -pthread -pthread -o .libs/capnp src/capnp/compiler/module-loader.o src/capnp/compiler/capnp.o ./.libs/libcapnpc.a ./.libs/libcapnp.a ./.libs/libkj.a -lpthread -pthread
|
||||
@@ -19,6 +18,7 @@ g++ -std=gnu++11 -I./src -I./src -DKJ_HEADER_WARNINGS -DCAPNP_HEADER_WARNINGS -D
|
||||
g++ -std=gnu++11 -I./src -I./src -DKJ_HEADER_WARNINGS -DCAPNP_HEADER_WARNINGS -DCAPNP_INCLUDE_DIR=\"/usr/local/include\" -pthread -O2 -DNDEBUG -pthread -pthread -o .libs/capnpc-capnp src/capnp/compiler/capnpc-capnp.o ./.libs/libcapnp.a ./.libs/libkj.a -lpthread -pthread
|
||||
|
||||
cp .libs/capnp /usr/local/bin/
|
||||
ln -s /usr/local/bin/capnp /usr/local/bin/capnpc
|
||||
cp .libs/capnpc-c++ /usr/local/bin/
|
||||
cp .libs/capnpc-capnp /usr/local/bin/
|
||||
cp .libs/*.a /usr/local/lib
|
||||
@@ -30,8 +30,7 @@ cd c-capnproto
|
||||
git submodule update --init --recursive
|
||||
autoreconf -f -i -s
|
||||
CXXFLAGS="-fPIC" ./configure
|
||||
make -j$(nproc)
|
||||
make install
|
||||
make -j4
|
||||
|
||||
# manually build binaries statically
|
||||
gcc -fPIC -o .libs/capnpc-c compiler/capnpc-c.o compiler/schema.capnp.o compiler/str.o ./.libs/libcapnp_c.a
|
||||
|
||||
+5
-106
@@ -126,7 +126,6 @@ struct FrameData {
|
||||
lensErr @13 :Float32;
|
||||
lensTruePos @14 :Float32;
|
||||
image @6 :Data;
|
||||
gainFrac @15 :Float32;
|
||||
|
||||
frameType @7 :FrameType;
|
||||
timestampSof @8 :UInt64;
|
||||
@@ -138,7 +137,6 @@ struct FrameData {
|
||||
unknown @0;
|
||||
neo @1;
|
||||
chffrAndroid @2;
|
||||
front @3;
|
||||
}
|
||||
|
||||
struct AndroidCaptureResult {
|
||||
@@ -270,7 +268,6 @@ struct ThermalData {
|
||||
mem @4 :UInt16;
|
||||
gpu @5 :UInt16;
|
||||
bat @6 :UInt32;
|
||||
pa0 @21 :UInt16;
|
||||
|
||||
# not thermal
|
||||
freeSpace @7 :Float32;
|
||||
@@ -279,7 +276,6 @@ struct ThermalData {
|
||||
batteryCurrent @15 :Int32;
|
||||
batteryVoltage @16 :Int32;
|
||||
usbOnline @12 :Bool;
|
||||
networkType @22 :NetworkType;
|
||||
|
||||
fanSpeed @10 :UInt16;
|
||||
started @11 :Bool;
|
||||
@@ -288,11 +284,7 @@ struct ThermalData {
|
||||
thermalStatus @14 :ThermalStatus;
|
||||
chargingError @17 :Bool;
|
||||
chargingDisabled @18 :Bool;
|
||||
|
||||
memUsedPercent @19 :Int8;
|
||||
cpuPerc @20 :Int8;
|
||||
|
||||
ipAddr @23 :Text; # dragonpilot
|
||||
ipAddr @19 :Text;
|
||||
|
||||
enum ThermalStatus {
|
||||
green @0; # all processes run
|
||||
@@ -300,49 +292,23 @@ struct ThermalData {
|
||||
red @2; # no engage, will disengage
|
||||
danger @3; # immediate process shutdown
|
||||
}
|
||||
|
||||
enum NetworkType {
|
||||
none @0;
|
||||
wifi @1;
|
||||
cell2G @2;
|
||||
cell3G @3;
|
||||
cell4G @4;
|
||||
cell5G @5;
|
||||
}
|
||||
}
|
||||
|
||||
struct HealthData {
|
||||
# from can health
|
||||
voltage @0 :UInt32;
|
||||
current @1 :UInt32;
|
||||
ignitionLine @2 :Bool;
|
||||
started @2 :Bool;
|
||||
controlsAllowed @3 :Bool;
|
||||
gasInterceptorDetected @4 :Bool;
|
||||
startedSignalDetectedDeprecated @5 :Bool;
|
||||
hasGps @6 :Bool;
|
||||
canSendErrs @7 :UInt32;
|
||||
canFwdErrs @8 :UInt32;
|
||||
canRxErrs @19 :UInt32;
|
||||
gmlanSendErrs @9 :UInt32;
|
||||
hwType @10 :HwType;
|
||||
fanSpeedRpm @11 :UInt16;
|
||||
usbPowerMode @12 :UsbPowerMode;
|
||||
ignitionCan @13 :Bool;
|
||||
safetyModel @14 :Car.CarParams.SafetyModel;
|
||||
faultStatus @15 :FaultStatus;
|
||||
powerSaveEnabled @16 :Bool;
|
||||
uptime @17 :UInt32;
|
||||
faults @18 :List(FaultType);
|
||||
|
||||
enum FaultStatus {
|
||||
none @0;
|
||||
faultTemp @1;
|
||||
faultPerm @2;
|
||||
}
|
||||
|
||||
enum FaultType {
|
||||
relayMalfunction @0;
|
||||
}
|
||||
|
||||
enum HwType {
|
||||
unknown @0;
|
||||
@@ -497,7 +463,6 @@ struct ControlsState @0x97ff69c53601abf1 {
|
||||
decelForTurn @47 :Bool;
|
||||
|
||||
decelForModel @54 :Bool;
|
||||
canErrorCounter @57 :UInt32;
|
||||
|
||||
lateralControlState :union {
|
||||
indiState @52 :LateralINDIState;
|
||||
@@ -543,7 +508,6 @@ struct ControlsState @0x97ff69c53601abf1 {
|
||||
delayedOutput @7 :Float32;
|
||||
delta @8 :Float32;
|
||||
output @9 :Float32;
|
||||
saturated @10 :Bool;
|
||||
}
|
||||
|
||||
struct LateralPIDState {
|
||||
@@ -564,7 +528,6 @@ struct ControlsState @0x97ff69c53601abf1 {
|
||||
i @2 :Float32;
|
||||
output @3 :Float32;
|
||||
lqrOutput @4 :Float32;
|
||||
saturated @5 :Bool;
|
||||
}
|
||||
|
||||
|
||||
@@ -588,8 +551,6 @@ struct ModelData {
|
||||
settings @5 :ModelSettings;
|
||||
leadFuture @7 :LeadData;
|
||||
speed @8 :List(Float32);
|
||||
meta @10 :MetaData;
|
||||
longitudinal @11 :LongitudinalData;
|
||||
|
||||
struct PathData {
|
||||
points @0 :List(Float32);
|
||||
@@ -620,19 +581,6 @@ struct ModelData {
|
||||
yuvCorrection @5 :List(Float32);
|
||||
inputTransform @6 :List(Float32);
|
||||
}
|
||||
|
||||
struct MetaData {
|
||||
engagedProb @0 :Float32;
|
||||
desirePrediction @1 :List(Float32);
|
||||
brakeDisengageProb @2 :Float32;
|
||||
gasDisengageProb @3 :Float32;
|
||||
steerOverrideProb @4 :Float32;
|
||||
}
|
||||
|
||||
struct LongitudinalData {
|
||||
speeds @0 :List(Float32);
|
||||
accelerations @1 :List(Float32);
|
||||
}
|
||||
}
|
||||
|
||||
struct CalibrationFeatures {
|
||||
@@ -766,8 +714,6 @@ struct PathPlan {
|
||||
desire @17 :Desire;
|
||||
laneChangeState @18 :LaneChangeState;
|
||||
laneChangeDirection @19 :LaneChangeDirection;
|
||||
# dragonpilot
|
||||
autoLCAllowed @20 :Bool;
|
||||
|
||||
enum Desire {
|
||||
none @0;
|
||||
@@ -1436,7 +1382,6 @@ struct UbloxGnss {
|
||||
measurementReport @0 :MeasurementReport;
|
||||
ephemeris @1 :Ephemeris;
|
||||
ionoData @2 :IonoData;
|
||||
hwStatus @3 :HwStatus;
|
||||
}
|
||||
|
||||
struct MeasurementReport {
|
||||
@@ -1560,30 +1505,9 @@ struct UbloxGnss {
|
||||
healthValid @5 :Bool;
|
||||
ionoCoeffsValid @6 :Bool;
|
||||
}
|
||||
|
||||
struct HwStatus {
|
||||
noisePerMS @0 :UInt16;
|
||||
agcCnt @1 :UInt16;
|
||||
aStatus @2 :AntennaSupervisorState;
|
||||
aPower @3 :AntennaPowerStatus;
|
||||
jamInd @4 :UInt8;
|
||||
|
||||
enum AntennaSupervisorState {
|
||||
init @0;
|
||||
dontknow @1;
|
||||
ok @2;
|
||||
short @3;
|
||||
open @4;
|
||||
}
|
||||
|
||||
enum AntennaPowerStatus {
|
||||
off @0;
|
||||
on @1;
|
||||
dontknow @2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct Clocks {
|
||||
bootTimeNanos @0 :UInt64;
|
||||
monotonicNanos @1 :UInt64;
|
||||
@@ -1724,7 +1648,6 @@ struct UiLayoutState {
|
||||
home @0;
|
||||
music @1;
|
||||
nav @2;
|
||||
settings @3;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1790,7 +1713,7 @@ struct OrbKeyFrame {
|
||||
descriptors @3 :Data;
|
||||
}
|
||||
|
||||
struct DriverState {
|
||||
struct DriverMonitoring {
|
||||
frameId @0 :UInt32;
|
||||
descriptorDEPRECATED @1 :List(Float32);
|
||||
stdDEPRECATED @2 :Float32;
|
||||
@@ -1801,28 +1724,6 @@ struct DriverState {
|
||||
rightEyeProb @7 :Float32;
|
||||
leftBlinkProb @8 :Float32;
|
||||
rightBlinkProb @9 :Float32;
|
||||
irPwrDEPRECATED @10 :Float32;
|
||||
faceOrientationStd @11 :List(Float32);
|
||||
facePositionStd @12 :List(Float32);
|
||||
}
|
||||
|
||||
struct DMonitoringState {
|
||||
# TODO: deprecate old fields in controlsState
|
||||
events @0 :List(Car.CarEvent);
|
||||
faceDetected @1 :Bool;
|
||||
isDistracted @2 :Bool;
|
||||
awarenessStatus @3 :Float32;
|
||||
isRHD @4 :Bool;
|
||||
rhdChecked @5 :Bool;
|
||||
posePitchOffset @6 :Float32;
|
||||
posePitchValidCount @7 :UInt32;
|
||||
poseYawOffset @8 :Float32;
|
||||
poseYawValidCount @9 :UInt32;
|
||||
stepChange @10 :Float32;
|
||||
awarenessActive @11 :Float32;
|
||||
awarenessPassive @12 :Float32;
|
||||
isLowStd @13 :Bool;
|
||||
hiStdCount @14 :UInt32;
|
||||
}
|
||||
|
||||
struct Boot {
|
||||
@@ -1944,7 +1845,7 @@ struct Event {
|
||||
orbKeyFrame @56 :OrbKeyFrame;
|
||||
uiLayoutState @57 :UiLayoutState;
|
||||
orbFeaturesSummary @58 :OrbFeaturesSummary;
|
||||
driverState @59 :DriverState;
|
||||
driverMonitoring @59 :DriverMonitoring;
|
||||
boot @60 :Boot;
|
||||
liveParameters @61 :LiveParametersData;
|
||||
liveMapData @62 :LiveMapData;
|
||||
@@ -1954,7 +1855,5 @@ struct Event {
|
||||
thumbnail @66: Thumbnail;
|
||||
carEvents @68: List(Car.CarEvent);
|
||||
carParams @69: Car.CarParams;
|
||||
frontFrame @70: FrameData;
|
||||
dMonitoringState @71: DMonitoringState;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
demo
|
||||
bridge
|
||||
test_runner
|
||||
*.o
|
||||
*.os
|
||||
*.d
|
||||
*.a
|
||||
*.so
|
||||
messaging_pyx.cpp
|
||||
build/
|
||||
@@ -1,64 +0,0 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
#include <csignal>
|
||||
#include <map>
|
||||
|
||||
typedef void (*sighandler_t)(int sig);
|
||||
|
||||
#include "services.h"
|
||||
|
||||
#include "impl_msgq.hpp"
|
||||
#include "impl_zmq.hpp"
|
||||
|
||||
void sigpipe_handler(int sig) {
|
||||
assert(sig == SIGPIPE);
|
||||
std::cout << "SIGPIPE received" << std::endl;
|
||||
}
|
||||
|
||||
static std::vector<std::string> get_services() {
|
||||
std::vector<std::string> name_list;
|
||||
|
||||
for (const auto& it : services) {
|
||||
std::string name = it.name;
|
||||
if (name == "plusFrame" || name == "uiLayoutState") continue;
|
||||
name_list.push_back(name);
|
||||
}
|
||||
|
||||
return name_list;
|
||||
}
|
||||
|
||||
|
||||
int main(void){
|
||||
signal(SIGPIPE, (sighandler_t)sigpipe_handler);
|
||||
|
||||
auto endpoints = get_services();
|
||||
|
||||
std::map<SubSocket*, PubSocket*> sub2pub;
|
||||
|
||||
Context *zmq_context = new ZMQContext();
|
||||
Context *msgq_context = new MSGQContext();
|
||||
Poller *poller = new MSGQPoller();
|
||||
|
||||
for (auto endpoint: endpoints){
|
||||
SubSocket * msgq_sock = new MSGQSubSocket();
|
||||
msgq_sock->connect(msgq_context, endpoint, "127.0.0.1", false);
|
||||
poller->registerSocket(msgq_sock);
|
||||
|
||||
PubSocket * zmq_sock = new ZMQPubSocket();
|
||||
zmq_sock->connect(zmq_context, endpoint);
|
||||
|
||||
sub2pub[msgq_sock] = zmq_sock;
|
||||
}
|
||||
|
||||
|
||||
while (true){
|
||||
for (auto sub_sock : poller->poll(100)){
|
||||
Message * msg = sub_sock->receive();
|
||||
if (msg == NULL) continue;
|
||||
sub2pub[sub_sock]->sendMessage(msg);
|
||||
delete msg;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,50 +0,0 @@
|
||||
#include <iostream>
|
||||
#include <cstddef>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#include <cassert>
|
||||
|
||||
#include "messaging.hpp"
|
||||
#include "impl_zmq.hpp"
|
||||
|
||||
#define MSGS 1e5
|
||||
|
||||
int main() {
|
||||
Context * c = Context::create();
|
||||
SubSocket * sub_sock = SubSocket::create(c, "controlsState");
|
||||
PubSocket * pub_sock = PubSocket::create(c, "controlsState");
|
||||
|
||||
char data[8];
|
||||
|
||||
Poller * poller = Poller::create({sub_sock});
|
||||
|
||||
auto start = std::chrono::steady_clock::now();
|
||||
|
||||
for (uint64_t i = 0; i < MSGS; i++){
|
||||
*(uint64_t*)data = i;
|
||||
pub_sock->send(data, 8);
|
||||
|
||||
auto r = poller->poll(100);
|
||||
|
||||
for (auto p : r){
|
||||
Message * m = p->receive();
|
||||
uint64_t ii = *(uint64_t*)m->getData();
|
||||
assert(i == ii);
|
||||
delete m;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
auto end = std::chrono::steady_clock::now();
|
||||
double elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count() / 1e9;
|
||||
double throughput = ((double) MSGS / (double) elapsed);
|
||||
std::cout << throughput << " msg/s" << std::endl;
|
||||
|
||||
delete poller;
|
||||
delete sub_sock;
|
||||
delete pub_sock;
|
||||
delete c;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
import time
|
||||
|
||||
from messaging_pyx import Context, Poller, SubSocket, PubSocket # pylint: disable=no-name-in-module, import-error
|
||||
|
||||
MSGS = 1e5
|
||||
|
||||
if __name__ == "__main__":
|
||||
c = Context()
|
||||
sub_sock = SubSocket()
|
||||
pub_sock = PubSocket()
|
||||
|
||||
sub_sock.connect(c, "controlsState")
|
||||
pub_sock.connect(c, "controlsState")
|
||||
|
||||
|
||||
poller = Poller()
|
||||
poller.registerSocket(sub_sock)
|
||||
|
||||
t = time.time()
|
||||
for i in range(int(MSGS)):
|
||||
bts = i.to_bytes(4, 'little')
|
||||
pub_sock.send(bts)
|
||||
|
||||
for s in poller.poll(100):
|
||||
dat = s.receive()
|
||||
ii = int.from_bytes(dat, 'little')
|
||||
assert(i == ii)
|
||||
|
||||
dt = time.time() - t
|
||||
print("%.1f msg/s" % (MSGS / dt))
|
||||
@@ -1,195 +0,0 @@
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <csignal>
|
||||
#include <cerrno>
|
||||
|
||||
|
||||
#include "impl_msgq.hpp"
|
||||
|
||||
volatile sig_atomic_t msgq_do_exit = 0;
|
||||
|
||||
void sig_handler(int signal) {
|
||||
assert(signal == SIGINT || signal == SIGTERM);
|
||||
msgq_do_exit = 1;
|
||||
}
|
||||
|
||||
|
||||
MSGQContext::MSGQContext() {
|
||||
}
|
||||
|
||||
MSGQContext::~MSGQContext() {
|
||||
}
|
||||
|
||||
void MSGQMessage::init(size_t sz) {
|
||||
size = sz;
|
||||
data = new char[size];
|
||||
}
|
||||
|
||||
void MSGQMessage::init(char * d, size_t sz) {
|
||||
size = sz;
|
||||
data = new char[size];
|
||||
memcpy(data, d, size);
|
||||
}
|
||||
|
||||
void MSGQMessage::takeOwnership(char * d, size_t sz) {
|
||||
size = sz;
|
||||
data = d;
|
||||
}
|
||||
|
||||
void MSGQMessage::close() {
|
||||
if (size > 0){
|
||||
delete[] data;
|
||||
}
|
||||
size = 0;
|
||||
}
|
||||
|
||||
MSGQMessage::~MSGQMessage() {
|
||||
this->close();
|
||||
}
|
||||
|
||||
|
||||
int MSGQSubSocket::connect(Context *context, std::string endpoint, std::string address, bool conflate){
|
||||
assert(context);
|
||||
assert(address == "127.0.0.1");
|
||||
|
||||
q = new msgq_queue_t;
|
||||
int r = msgq_new_queue(q, endpoint.c_str(), DEFAULT_SEGMENT_SIZE);
|
||||
if (r != 0){
|
||||
return r;
|
||||
}
|
||||
|
||||
msgq_init_subscriber(q);
|
||||
|
||||
if (conflate){
|
||||
q->read_conflate = true;
|
||||
}
|
||||
|
||||
timeout = -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Message * MSGQSubSocket::receive(bool non_blocking){
|
||||
msgq_do_exit = 0;
|
||||
|
||||
void (*prev_handler_sigint)(int);
|
||||
void (*prev_handler_sigterm)(int);
|
||||
if (!non_blocking){
|
||||
prev_handler_sigint = std::signal(SIGINT, sig_handler);
|
||||
prev_handler_sigterm = std::signal(SIGTERM, sig_handler);
|
||||
}
|
||||
|
||||
msgq_msg_t msg;
|
||||
|
||||
MSGQMessage *r = NULL;
|
||||
|
||||
int rc = msgq_msg_recv(&msg, q);
|
||||
|
||||
// Hack to implement blocking read with a poller. Don't use this
|
||||
while (!non_blocking && rc == 0 && msgq_do_exit == 0){
|
||||
msgq_pollitem_t items[1];
|
||||
items[0].q = q;
|
||||
|
||||
int t = (timeout != -1) ? timeout : 100;
|
||||
|
||||
int n = msgq_poll(items, 1, t);
|
||||
rc = msgq_msg_recv(&msg, q);
|
||||
|
||||
// The poll indicated a message was ready, but the receive failed. Try again
|
||||
if (n == 1 && rc == 0){
|
||||
continue;
|
||||
}
|
||||
|
||||
if (timeout != -1){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!non_blocking){
|
||||
std::signal(SIGINT, prev_handler_sigint);
|
||||
std::signal(SIGTERM, prev_handler_sigterm);
|
||||
}
|
||||
|
||||
errno = msgq_do_exit ? EINTR : 0;
|
||||
|
||||
if (rc > 0){
|
||||
if (msgq_do_exit){
|
||||
msgq_msg_close(&msg); // Free unused message on exit
|
||||
} else {
|
||||
r = new MSGQMessage;
|
||||
r->takeOwnership(msg.data, msg.size);
|
||||
}
|
||||
}
|
||||
|
||||
return (Message*)r;
|
||||
}
|
||||
|
||||
void MSGQSubSocket::setTimeout(int t){
|
||||
timeout = t;
|
||||
}
|
||||
|
||||
MSGQSubSocket::~MSGQSubSocket(){
|
||||
if (q != NULL){
|
||||
msgq_close_queue(q);
|
||||
delete q;
|
||||
}
|
||||
}
|
||||
|
||||
int MSGQPubSocket::connect(Context *context, std::string endpoint){
|
||||
assert(context);
|
||||
|
||||
q = new msgq_queue_t;
|
||||
msgq_new_queue(q, endpoint.c_str(), DEFAULT_SEGMENT_SIZE);
|
||||
msgq_init_publisher(q);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int MSGQPubSocket::sendMessage(Message *message){
|
||||
msgq_msg_t msg;
|
||||
msg.data = message->getData();
|
||||
msg.size = message->getSize();
|
||||
|
||||
return msgq_msg_send(&msg, q);
|
||||
}
|
||||
|
||||
int MSGQPubSocket::send(char *data, size_t size){
|
||||
msgq_msg_t msg;
|
||||
msg.data = data;
|
||||
msg.size = size;
|
||||
|
||||
return msgq_msg_send(&msg, q);
|
||||
}
|
||||
|
||||
MSGQPubSocket::~MSGQPubSocket(){
|
||||
if (q != NULL){
|
||||
msgq_close_queue(q);
|
||||
delete q;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MSGQPoller::registerSocket(SubSocket * socket){
|
||||
assert(num_polls + 1 < MAX_POLLERS);
|
||||
polls[num_polls].q = (msgq_queue_t*)socket->getRawSocket();
|
||||
|
||||
sockets.push_back(socket);
|
||||
num_polls++;
|
||||
}
|
||||
|
||||
std::vector<SubSocket*> MSGQPoller::poll(int timeout){
|
||||
std::vector<SubSocket*> r;
|
||||
|
||||
msgq_poll(polls, num_polls, timeout);
|
||||
for (size_t i = 0; i < num_polls; i++){
|
||||
if (polls[i].revents){
|
||||
r.push_back(sockets[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
#pragma once
|
||||
#include "messaging.hpp"
|
||||
#include "msgq.hpp"
|
||||
#include <zmq.h>
|
||||
#include <string>
|
||||
|
||||
#define MAX_POLLERS 128
|
||||
|
||||
class MSGQContext : public Context {
|
||||
private:
|
||||
void * context = NULL;
|
||||
public:
|
||||
MSGQContext();
|
||||
void * getRawContext() {return context;}
|
||||
~MSGQContext();
|
||||
};
|
||||
|
||||
class MSGQMessage : public Message {
|
||||
private:
|
||||
char * data;
|
||||
size_t size;
|
||||
public:
|
||||
void init(size_t size);
|
||||
void init(char *data, size_t size);
|
||||
void takeOwnership(char *data, size_t size);
|
||||
size_t getSize(){return size;}
|
||||
char * getData(){return data;}
|
||||
void close();
|
||||
~MSGQMessage();
|
||||
};
|
||||
|
||||
class MSGQSubSocket : public SubSocket {
|
||||
private:
|
||||
msgq_queue_t * q = NULL;
|
||||
int timeout;
|
||||
public:
|
||||
int connect(Context *context, std::string endpoint, std::string address, bool conflate=false);
|
||||
void setTimeout(int timeout);
|
||||
void * getRawSocket() {return (void*)q;}
|
||||
Message *receive(bool non_blocking=false);
|
||||
~MSGQSubSocket();
|
||||
};
|
||||
|
||||
class MSGQPubSocket : public PubSocket {
|
||||
private:
|
||||
msgq_queue_t * q = NULL;
|
||||
public:
|
||||
int connect(Context *context, std::string endpoint);
|
||||
int sendMessage(Message *message);
|
||||
int send(char *data, size_t size);
|
||||
~MSGQPubSocket();
|
||||
};
|
||||
|
||||
class MSGQPoller : public Poller {
|
||||
private:
|
||||
std::vector<SubSocket*> sockets;
|
||||
msgq_pollitem_t polls[MAX_POLLERS];
|
||||
size_t num_polls = 0;
|
||||
|
||||
public:
|
||||
void registerSocket(SubSocket *socket);
|
||||
std::vector<SubSocket*> poll(int timeout);
|
||||
~MSGQPoller(){};
|
||||
};
|
||||
@@ -1,155 +0,0 @@
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <cerrno>
|
||||
|
||||
#include <zmq.h>
|
||||
|
||||
#include "services.h"
|
||||
#include "impl_zmq.hpp"
|
||||
|
||||
static int get_port(std::string endpoint) {
|
||||
int port = -1;
|
||||
for (const auto& it : services) {
|
||||
std::string name = it.name;
|
||||
if (name == endpoint) {
|
||||
port = it.port;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert(port >= 0);
|
||||
return port;
|
||||
}
|
||||
|
||||
ZMQContext::ZMQContext() {
|
||||
context = zmq_ctx_new();
|
||||
}
|
||||
|
||||
ZMQContext::~ZMQContext() {
|
||||
zmq_ctx_term(context);
|
||||
}
|
||||
|
||||
void ZMQMessage::init(size_t sz) {
|
||||
size = sz;
|
||||
data = new char[size];
|
||||
}
|
||||
|
||||
void ZMQMessage::init(char * d, size_t sz) {
|
||||
size = sz;
|
||||
data = new char[size];
|
||||
memcpy(data, d, size);
|
||||
}
|
||||
|
||||
void ZMQMessage::close() {
|
||||
if (size > 0){
|
||||
delete[] data;
|
||||
}
|
||||
size = 0;
|
||||
}
|
||||
|
||||
ZMQMessage::~ZMQMessage() {
|
||||
this->close();
|
||||
}
|
||||
|
||||
|
||||
int ZMQSubSocket::connect(Context *context, std::string endpoint, std::string address, bool conflate){
|
||||
sock = zmq_socket(context->getRawContext(), ZMQ_SUB);
|
||||
if (sock == NULL){
|
||||
return -1;
|
||||
}
|
||||
|
||||
zmq_setsockopt(sock, ZMQ_SUBSCRIBE, "", 0);
|
||||
|
||||
if (conflate){
|
||||
int arg = 1;
|
||||
zmq_setsockopt(sock, ZMQ_CONFLATE, &arg, sizeof(int));
|
||||
}
|
||||
|
||||
int reconnect_ivl = 500;
|
||||
zmq_setsockopt(sock, ZMQ_RECONNECT_IVL_MAX, &reconnect_ivl, sizeof(reconnect_ivl));
|
||||
|
||||
full_endpoint = "tcp://" + address + ":";
|
||||
full_endpoint += std::to_string(get_port(endpoint));
|
||||
|
||||
return zmq_connect(sock, full_endpoint.c_str());
|
||||
}
|
||||
|
||||
|
||||
Message * ZMQSubSocket::receive(bool non_blocking){
|
||||
zmq_msg_t msg;
|
||||
assert(zmq_msg_init(&msg) == 0);
|
||||
|
||||
int flags = non_blocking ? ZMQ_DONTWAIT : 0;
|
||||
int rc = zmq_msg_recv(&msg, sock, flags);
|
||||
Message *r = NULL;
|
||||
|
||||
if (rc >= 0){
|
||||
// Make a copy to ensure the data is aligned
|
||||
r = new ZMQMessage;
|
||||
r->init((char*)zmq_msg_data(&msg), zmq_msg_size(&msg));
|
||||
}
|
||||
|
||||
zmq_msg_close(&msg);
|
||||
return r;
|
||||
}
|
||||
|
||||
void ZMQSubSocket::setTimeout(int timeout){
|
||||
zmq_setsockopt(sock, ZMQ_RCVTIMEO, &timeout, sizeof(int));
|
||||
}
|
||||
|
||||
ZMQSubSocket::~ZMQSubSocket(){
|
||||
zmq_close(sock);
|
||||
}
|
||||
|
||||
int ZMQPubSocket::connect(Context *context, std::string endpoint){
|
||||
sock = zmq_socket(context->getRawContext(), ZMQ_PUB);
|
||||
if (sock == NULL){
|
||||
return -1;
|
||||
}
|
||||
|
||||
full_endpoint = "tcp://*:";
|
||||
full_endpoint += std::to_string(get_port(endpoint));
|
||||
|
||||
return zmq_bind(sock, full_endpoint.c_str());
|
||||
}
|
||||
|
||||
int ZMQPubSocket::sendMessage(Message *message){
|
||||
return zmq_send(sock, message->getData(), message->getSize(), ZMQ_DONTWAIT);
|
||||
}
|
||||
|
||||
int ZMQPubSocket::send(char *data, size_t size){
|
||||
return zmq_send(sock, data, size, ZMQ_DONTWAIT);
|
||||
}
|
||||
|
||||
ZMQPubSocket::~ZMQPubSocket(){
|
||||
zmq_close(sock);
|
||||
}
|
||||
|
||||
|
||||
void ZMQPoller::registerSocket(SubSocket * socket){
|
||||
assert(num_polls + 1 < MAX_POLLERS);
|
||||
polls[num_polls].socket = socket->getRawSocket();
|
||||
polls[num_polls].events = ZMQ_POLLIN;
|
||||
|
||||
sockets.push_back(socket);
|
||||
num_polls++;
|
||||
}
|
||||
|
||||
std::vector<SubSocket*> ZMQPoller::poll(int timeout){
|
||||
std::vector<SubSocket*> r;
|
||||
|
||||
int rc = zmq_poll(polls, num_polls, timeout);
|
||||
if (rc < 0){
|
||||
return r;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < num_polls; i++){
|
||||
if (polls[i].revents){
|
||||
r.push_back(sockets[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
#pragma once
|
||||
#include "messaging.hpp"
|
||||
#include <zmq.h>
|
||||
#include <string>
|
||||
|
||||
#define MAX_POLLERS 128
|
||||
|
||||
class ZMQContext : public Context {
|
||||
private:
|
||||
void * context = NULL;
|
||||
public:
|
||||
ZMQContext();
|
||||
void * getRawContext() {return context;}
|
||||
~ZMQContext();
|
||||
};
|
||||
|
||||
class ZMQMessage : public Message {
|
||||
private:
|
||||
char * data;
|
||||
size_t size;
|
||||
public:
|
||||
void init(size_t size);
|
||||
void init(char *data, size_t size);
|
||||
size_t getSize(){return size;}
|
||||
char * getData(){return data;}
|
||||
void close();
|
||||
~ZMQMessage();
|
||||
};
|
||||
|
||||
class ZMQSubSocket : public SubSocket {
|
||||
private:
|
||||
void * sock;
|
||||
std::string full_endpoint;
|
||||
public:
|
||||
int connect(Context *context, std::string endpoint, std::string address, bool conflate=false);
|
||||
void setTimeout(int timeout);
|
||||
void * getRawSocket() {return sock;}
|
||||
Message *receive(bool non_blocking=false);
|
||||
~ZMQSubSocket();
|
||||
};
|
||||
|
||||
class ZMQPubSocket : public PubSocket {
|
||||
private:
|
||||
void * sock;
|
||||
std::string full_endpoint;
|
||||
public:
|
||||
int connect(Context *context, std::string endpoint);
|
||||
int sendMessage(Message *message);
|
||||
int send(char *data, size_t size);
|
||||
~ZMQPubSocket();
|
||||
};
|
||||
|
||||
class ZMQPoller : public Poller {
|
||||
private:
|
||||
std::vector<SubSocket*> sockets;
|
||||
zmq_pollitem_t polls[MAX_POLLERS];
|
||||
size_t num_polls = 0;
|
||||
|
||||
public:
|
||||
void registerSocket(SubSocket *socket);
|
||||
std::vector<SubSocket*> poll(int timeout);
|
||||
~ZMQPoller(){};
|
||||
};
|
||||
@@ -1,117 +0,0 @@
|
||||
#include "messaging.hpp"
|
||||
#include "impl_zmq.hpp"
|
||||
#include "impl_msgq.hpp"
|
||||
|
||||
Context * Context::create(){
|
||||
Context * c;
|
||||
if (std::getenv("ZMQ")){
|
||||
c = new ZMQContext();
|
||||
} else {
|
||||
c = new MSGQContext();
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
SubSocket * SubSocket::create(){
|
||||
SubSocket * s;
|
||||
if (std::getenv("ZMQ")){
|
||||
s = new ZMQSubSocket();
|
||||
} else {
|
||||
s = new MSGQSubSocket();
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
SubSocket * SubSocket::create(Context * context, std::string endpoint){
|
||||
SubSocket *s = SubSocket::create();
|
||||
int r = s->connect(context, endpoint, "127.0.0.1");
|
||||
|
||||
if (r == 0) {
|
||||
return s;
|
||||
} else {
|
||||
delete s;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
SubSocket * SubSocket::create(Context * context, std::string endpoint, std::string address){
|
||||
SubSocket *s = SubSocket::create();
|
||||
int r = s->connect(context, endpoint, address);
|
||||
|
||||
if (r == 0) {
|
||||
return s;
|
||||
} else {
|
||||
delete s;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
SubSocket * SubSocket::create(Context * context, std::string endpoint, std::string address, bool conflate){
|
||||
SubSocket *s = SubSocket::create();
|
||||
int r = s->connect(context, endpoint, address, conflate);
|
||||
|
||||
if (r == 0) {
|
||||
return s;
|
||||
} else {
|
||||
delete s;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
PubSocket * PubSocket::create(){
|
||||
PubSocket * s;
|
||||
if (std::getenv("ZMQ")){
|
||||
s = new ZMQPubSocket();
|
||||
} else {
|
||||
s = new MSGQPubSocket();
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
PubSocket * PubSocket::create(Context * context, std::string endpoint){
|
||||
PubSocket *s = PubSocket::create();
|
||||
int r = s->connect(context, endpoint);
|
||||
|
||||
if (r == 0) {
|
||||
return s;
|
||||
} else {
|
||||
delete s;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
Poller * Poller::create(){
|
||||
Poller * p;
|
||||
if (std::getenv("ZMQ")){
|
||||
p = new ZMQPoller();
|
||||
} else {
|
||||
p = new MSGQPoller();
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
Poller * Poller::create(std::vector<SubSocket*> sockets){
|
||||
Poller * p = Poller::create();
|
||||
|
||||
for (auto s : sockets){
|
||||
p->registerSocket(s);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
extern "C" Context * messaging_context_create() {
|
||||
return Context::create();
|
||||
}
|
||||
|
||||
extern "C" SubSocket * messaging_subsocket_create(Context* context, const char* endpoint) {
|
||||
return SubSocket::create(context, std::string(endpoint));
|
||||
}
|
||||
|
||||
extern "C" PubSocket * messaging_pubsocket_create(Context* context, const char* endpoint) {
|
||||
return PubSocket::create(context, std::string(endpoint));
|
||||
}
|
||||
|
||||
extern "C" Poller * messaging_poller_create(SubSocket** sockets, int size) {
|
||||
std::vector<SubSocket*> socketsVec(sockets, sockets + size);
|
||||
return Poller::create(socketsVec);
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
#pragma once
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#define MSG_MULTIPLE_PUBLISHERS 100
|
||||
|
||||
class Context {
|
||||
public:
|
||||
virtual void * getRawContext() = 0;
|
||||
static Context * create();
|
||||
virtual ~Context(){};
|
||||
};
|
||||
|
||||
class Message {
|
||||
public:
|
||||
virtual void init(size_t size) = 0;
|
||||
virtual void init(char * data, size_t size) = 0;
|
||||
virtual void close() = 0;
|
||||
virtual size_t getSize() = 0;
|
||||
virtual char * getData() = 0;
|
||||
virtual ~Message(){};
|
||||
};
|
||||
|
||||
|
||||
class SubSocket {
|
||||
public:
|
||||
virtual int connect(Context *context, std::string endpoint, std::string address, bool conflate=false) = 0;
|
||||
virtual void setTimeout(int timeout) = 0;
|
||||
virtual Message *receive(bool non_blocking=false) = 0;
|
||||
virtual void * getRawSocket() = 0;
|
||||
static SubSocket * create();
|
||||
static SubSocket * create(Context * context, std::string endpoint);
|
||||
static SubSocket * create(Context * context, std::string endpoint, std::string address);
|
||||
static SubSocket * create(Context * context, std::string endpoint, std::string address, bool conflate);
|
||||
virtual ~SubSocket(){};
|
||||
};
|
||||
|
||||
class PubSocket {
|
||||
public:
|
||||
virtual int connect(Context *context, std::string endpoint) = 0;
|
||||
virtual int sendMessage(Message *message) = 0;
|
||||
virtual int send(char *data, size_t size) = 0;
|
||||
static PubSocket * create();
|
||||
static PubSocket * create(Context * context, std::string endpoint);
|
||||
virtual ~PubSocket(){};
|
||||
};
|
||||
|
||||
class Poller {
|
||||
public:
|
||||
virtual void registerSocket(SubSocket *socket) = 0;
|
||||
virtual std::vector<SubSocket*> poll(int timeout) = 0;
|
||||
static Poller * create();
|
||||
static Poller * create(std::vector<SubSocket*> sockets);
|
||||
virtual ~Poller(){};
|
||||
};
|
||||
@@ -1,39 +0,0 @@
|
||||
# distutils: language = c++
|
||||
#cython: language_level=3
|
||||
|
||||
from libcpp.string cimport string
|
||||
from libcpp.vector cimport vector
|
||||
from libcpp cimport bool
|
||||
|
||||
|
||||
cdef extern from "messaging.hpp":
|
||||
cdef cppclass Context:
|
||||
@staticmethod
|
||||
Context * create()
|
||||
|
||||
cdef cppclass Message:
|
||||
void init(size_t)
|
||||
void init(char *, size_t)
|
||||
void close()
|
||||
size_t getSize()
|
||||
char *getData()
|
||||
|
||||
cdef cppclass SubSocket:
|
||||
@staticmethod
|
||||
SubSocket * create()
|
||||
int connect(Context *, string, string, bool)
|
||||
Message * receive(bool)
|
||||
void setTimeout(int)
|
||||
|
||||
cdef cppclass PubSocket:
|
||||
@staticmethod
|
||||
PubSocket * create()
|
||||
int connect(Context *, string)
|
||||
int sendMessage(Message *)
|
||||
int send(char *, size_t)
|
||||
|
||||
cdef cppclass Poller:
|
||||
@staticmethod
|
||||
Poller * create()
|
||||
void registerSocket(SubSocket *)
|
||||
vector[SubSocket*] poll(int) nogil
|
||||
@@ -1,151 +0,0 @@
|
||||
# distutils: language = c++
|
||||
# cython: c_string_encoding=ascii, language_level=3
|
||||
|
||||
import sys
|
||||
from libcpp.string cimport string
|
||||
from libcpp cimport bool
|
||||
from libc cimport errno
|
||||
|
||||
|
||||
from messaging cimport Context as cppContext
|
||||
from messaging cimport SubSocket as cppSubSocket
|
||||
from messaging cimport PubSocket as cppPubSocket
|
||||
from messaging cimport Poller as cppPoller
|
||||
from messaging cimport Message as cppMessage
|
||||
|
||||
|
||||
class MessagingError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class MultiplePublishersError(MessagingError):
|
||||
pass
|
||||
|
||||
|
||||
cdef class Context:
|
||||
cdef cppContext * context
|
||||
|
||||
def __cinit__(self):
|
||||
self.context = cppContext.create()
|
||||
|
||||
def term(self):
|
||||
del self.context
|
||||
self.context = NULL
|
||||
|
||||
def __dealloc__(self):
|
||||
pass
|
||||
# Deleting the context will hang if sockets are still active
|
||||
# TODO: Figure out a way to make sure the context is closed last
|
||||
# del self.context
|
||||
|
||||
|
||||
cdef class Poller:
|
||||
cdef cppPoller * poller
|
||||
cdef list sub_sockets
|
||||
|
||||
def __cinit__(self):
|
||||
self.sub_sockets = []
|
||||
self.poller = cppPoller.create()
|
||||
|
||||
def __dealloc__(self):
|
||||
del self.poller
|
||||
|
||||
def registerSocket(self, SubSocket socket):
|
||||
self.sub_sockets.append(socket)
|
||||
self.poller.registerSocket(socket.socket)
|
||||
|
||||
def poll(self, timeout):
|
||||
sockets = []
|
||||
cdef int t = timeout
|
||||
|
||||
with nogil:
|
||||
result = self.poller.poll(t)
|
||||
|
||||
for s in result:
|
||||
socket = SubSocket()
|
||||
socket.setPtr(s)
|
||||
sockets.append(socket)
|
||||
|
||||
return sockets
|
||||
|
||||
cdef class SubSocket:
|
||||
cdef cppSubSocket * socket
|
||||
cdef bool is_owner
|
||||
|
||||
def __cinit__(self):
|
||||
self.socket = cppSubSocket.create()
|
||||
self.is_owner = True
|
||||
|
||||
if self.socket == NULL:
|
||||
raise MessagingError
|
||||
|
||||
def __dealloc__(self):
|
||||
if self.is_owner:
|
||||
del self.socket
|
||||
|
||||
cdef setPtr(self, cppSubSocket * ptr):
|
||||
if self.is_owner:
|
||||
del self.socket
|
||||
|
||||
self.is_owner = False
|
||||
self.socket = ptr
|
||||
|
||||
def connect(self, Context context, string endpoint, string address=b"127.0.0.1", bool conflate=False):
|
||||
r = self.socket.connect(context.context, endpoint, address, conflate)
|
||||
|
||||
if r != 0:
|
||||
if errno.errno == errno.EADDRINUSE:
|
||||
raise MultiplePublishersError
|
||||
else:
|
||||
raise MessagingError
|
||||
|
||||
def setTimeout(self, int timeout):
|
||||
self.socket.setTimeout(timeout)
|
||||
|
||||
def receive(self, bool non_blocking=False):
|
||||
msg = self.socket.receive(non_blocking)
|
||||
|
||||
if msg == NULL:
|
||||
# If a blocking read returns no message check errno if SIGINT was caught in the C++ code
|
||||
if errno.errno == errno.EINTR:
|
||||
print("SIGINT received, exiting")
|
||||
sys.exit(1)
|
||||
|
||||
return None
|
||||
else:
|
||||
sz = msg.getSize()
|
||||
m = msg.getData()[:sz]
|
||||
del msg
|
||||
|
||||
return m
|
||||
|
||||
|
||||
cdef class PubSocket:
|
||||
cdef cppPubSocket * socket
|
||||
|
||||
def __cinit__(self):
|
||||
self.socket = cppPubSocket.create()
|
||||
if self.socket == NULL:
|
||||
raise MessagingError
|
||||
|
||||
def __dealloc__(self):
|
||||
del self.socket
|
||||
|
||||
def connect(self, Context context, string endpoint):
|
||||
r = self.socket.connect(context.context, endpoint)
|
||||
|
||||
if r != 0:
|
||||
if errno.errno == errno.EADDRINUSE:
|
||||
raise MultiplePublishersError
|
||||
else:
|
||||
raise MessagingError
|
||||
|
||||
def send(self, string data):
|
||||
length = len(data)
|
||||
r = self.socket.send(<char*>data.c_str(), length)
|
||||
|
||||
if r != length:
|
||||
if errno.errno == errno.EADDRINUSE:
|
||||
raise MultiplePublishersError
|
||||
else:
|
||||
raise MessagingError
|
||||
@@ -1,56 +0,0 @@
|
||||
import os
|
||||
import subprocess
|
||||
import sysconfig
|
||||
from distutils.core import Extension, setup # pylint: disable=import-error,no-name-in-module
|
||||
|
||||
from Cython.Build import cythonize
|
||||
from Cython.Distutils import build_ext
|
||||
|
||||
|
||||
def get_ext_filename_without_platform_suffix(filename):
|
||||
name, ext = os.path.splitext(filename)
|
||||
ext_suffix = sysconfig.get_config_var('EXT_SUFFIX')
|
||||
|
||||
if ext_suffix == ext:
|
||||
return filename
|
||||
|
||||
ext_suffix = ext_suffix.replace(ext, '')
|
||||
idx = name.find(ext_suffix)
|
||||
|
||||
if idx == -1:
|
||||
return filename
|
||||
else:
|
||||
return name[:idx] + ext
|
||||
|
||||
|
||||
class BuildExtWithoutPlatformSuffix(build_ext):
|
||||
def get_ext_filename(self, ext_name):
|
||||
filename = super().get_ext_filename(ext_name)
|
||||
return get_ext_filename_without_platform_suffix(filename)
|
||||
|
||||
|
||||
sourcefiles = ['messaging_pyx.pyx']
|
||||
extra_compile_args = ["-std=c++11"]
|
||||
libraries = ['zmq']
|
||||
ARCH = subprocess.check_output(["uname", "-m"], encoding='utf8').rstrip() # pylint: disable=unexpected-keyword-arg
|
||||
|
||||
if ARCH == "aarch64":
|
||||
extra_compile_args += ["-Wno-deprecated-register"]
|
||||
libraries += ['gnustl_shared']
|
||||
|
||||
setup(name='CAN parser',
|
||||
cmdclass={'build_ext': BuildExtWithoutPlatformSuffix},
|
||||
ext_modules=cythonize(
|
||||
Extension(
|
||||
"messaging_pyx",
|
||||
language="c++",
|
||||
sources=sourcefiles,
|
||||
extra_compile_args=extra_compile_args,
|
||||
libraries=libraries,
|
||||
extra_objects=[
|
||||
os.path.join(os.path.dirname(os.path.realpath(__file__)), '../', 'libmessaging.a'),
|
||||
]
|
||||
)
|
||||
),
|
||||
nthreads=4,
|
||||
)
|
||||
@@ -1,449 +0,0 @@
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
#include <cerrno>
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <cstdint>
|
||||
#include <chrono>
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <csignal>
|
||||
#include <random>
|
||||
|
||||
#include <poll.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "msgq.hpp"
|
||||
|
||||
void sigusr2_handler(int signal) {
|
||||
assert(signal == SIGUSR2);
|
||||
}
|
||||
|
||||
uint64_t msgq_get_uid(void){
|
||||
std::random_device rd("/dev/urandom");
|
||||
std::uniform_int_distribution<uint64_t> distribution(0,std::numeric_limits<uint32_t>::max());
|
||||
|
||||
uint64_t uid = distribution(rd) << 32 | syscall(SYS_gettid);
|
||||
return uid;
|
||||
}
|
||||
|
||||
int msgq_msg_init_size(msgq_msg_t * msg, size_t size){
|
||||
msg->size = size;
|
||||
msg->data = new(std::nothrow) char[size];
|
||||
|
||||
return (msg->data == NULL) ? -1 : 0;
|
||||
}
|
||||
|
||||
|
||||
int msgq_msg_init_data(msgq_msg_t * msg, char * data, size_t size) {
|
||||
int r = msgq_msg_init_size(msg, size);
|
||||
|
||||
if (r == 0)
|
||||
memcpy(msg->data, data, size);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int msgq_msg_close(msgq_msg_t * msg){
|
||||
if (msg->size > 0)
|
||||
delete[] msg->data;
|
||||
|
||||
msg->size = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void msgq_reset_reader(msgq_queue_t * q){
|
||||
int id = q->reader_id;
|
||||
q->read_valids[id]->store(true);
|
||||
q->read_pointers[id]->store(*q->write_pointer);
|
||||
}
|
||||
|
||||
void msgq_wait_for_subscriber(msgq_queue_t *q){
|
||||
while (*q->num_readers == 0){
|
||||
;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int msgq_new_queue(msgq_queue_t * q, const char * path, size_t size){
|
||||
assert(size < 0xFFFFFFFF); // Buffer must be smaller than 2^32 bytes
|
||||
|
||||
std::signal(SIGUSR2, sigusr2_handler);
|
||||
|
||||
const char * prefix = "/dev/shm/";
|
||||
char * full_path = new char[strlen(path) + strlen(prefix) + 1];
|
||||
strcpy(full_path, prefix);
|
||||
strcat(full_path, path);
|
||||
|
||||
auto fd = open(full_path, O_RDWR | O_CREAT, 0777);
|
||||
delete[] full_path;
|
||||
|
||||
if (fd < 0)
|
||||
return -1;
|
||||
|
||||
int rc = ftruncate(fd, size + sizeof(msgq_header_t));
|
||||
if (rc < 0)
|
||||
return -1;
|
||||
|
||||
char * mem = (char*)mmap(NULL, size + sizeof(msgq_header_t), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
close(fd);
|
||||
|
||||
if (mem == NULL)
|
||||
return -1;
|
||||
|
||||
q->mmap_p = mem;
|
||||
|
||||
msgq_header_t *header = (msgq_header_t *)mem;
|
||||
|
||||
// Setup pointers to header segment
|
||||
q->num_readers = reinterpret_cast<std::atomic<uint64_t>*>(&header->num_readers);
|
||||
q->write_pointer = reinterpret_cast<std::atomic<uint64_t>*>(&header->write_pointer);
|
||||
q->write_uid = reinterpret_cast<std::atomic<uint64_t>*>(&header->write_uid);
|
||||
|
||||
for (size_t i = 0; i < NUM_READERS; i++){
|
||||
q->read_pointers[i] = reinterpret_cast<std::atomic<uint64_t>*>(&header->read_pointers[i]);
|
||||
q->read_valids[i] = reinterpret_cast<std::atomic<uint64_t>*>(&header->read_valids[i]);
|
||||
q->read_uids[i] = reinterpret_cast<std::atomic<uint64_t>*>(&header->read_uids[i]);
|
||||
}
|
||||
|
||||
q->data = mem + sizeof(msgq_header_t);
|
||||
q->size = size;
|
||||
q->reader_id = -1;
|
||||
|
||||
q->endpoint = path;
|
||||
q->read_conflate = false;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void msgq_close_queue(msgq_queue_t *q){
|
||||
if (q->mmap_p != NULL){
|
||||
munmap(q->mmap_p, q->size + sizeof(msgq_header_t));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void msgq_init_publisher(msgq_queue_t * q) {
|
||||
//std::cout << "Starting publisher" << std::endl;
|
||||
uint64_t uid = msgq_get_uid();
|
||||
|
||||
*q->write_uid = uid;
|
||||
*q->num_readers = 0;
|
||||
|
||||
for (size_t i = 0; i < NUM_READERS; i++){
|
||||
*q->read_valids[i] = false;
|
||||
*q->read_uids[i] = 0;
|
||||
}
|
||||
|
||||
q->write_uid_local = uid;
|
||||
}
|
||||
|
||||
static void thread_signal(uint32_t tid) {
|
||||
#ifndef SYS_tkill
|
||||
// TODO: this won't work for multithreaded programs
|
||||
kill(tid, SIGUSR2);
|
||||
#else
|
||||
syscall(SYS_tkill, tid, SIGUSR2);
|
||||
#endif
|
||||
}
|
||||
|
||||
void msgq_init_subscriber(msgq_queue_t * q) {
|
||||
assert(q != NULL);
|
||||
assert(q->num_readers != NULL);
|
||||
|
||||
uint64_t uid = msgq_get_uid();
|
||||
|
||||
// Get reader id
|
||||
while (true){
|
||||
uint64_t cur_num_readers = *q->num_readers;
|
||||
uint64_t new_num_readers = cur_num_readers + 1;
|
||||
|
||||
// No more slots available. Reset all subscribers to kick out inactive ones
|
||||
if (new_num_readers > NUM_READERS){
|
||||
std::cout << "Warning, evicting all subscribers!" << std::endl;
|
||||
*q->num_readers = 0;
|
||||
|
||||
for (size_t i = 0; i < NUM_READERS; i++){
|
||||
*q->read_valids[i] = false;
|
||||
|
||||
uint64_t old_uid = *q->read_uids[i];
|
||||
*q->read_uids[i] = 0;
|
||||
|
||||
// Wake up reader in case they are in a poll
|
||||
thread_signal(old_uid & 0xFFFFFFFF);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// Use atomic compare and swap to handle race condition
|
||||
// where two subscribers start at the same time
|
||||
if (std::atomic_compare_exchange_strong(q->num_readers,
|
||||
&cur_num_readers,
|
||||
new_num_readers)){
|
||||
q->reader_id = cur_num_readers;
|
||||
q->read_uid_local = uid;
|
||||
|
||||
// We start with read_valid = false,
|
||||
// on the first read the read pointer will be synchronized with the write pointer
|
||||
*q->read_valids[cur_num_readers] = false;
|
||||
*q->read_pointers[cur_num_readers] = 0;
|
||||
*q->read_uids[cur_num_readers] = uid;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//std::cout << "New subscriber id: " << q->reader_id << " uid: " << q->read_uid_local << " " << q->endpoint << std::endl;
|
||||
msgq_reset_reader(q);
|
||||
}
|
||||
|
||||
int msgq_msg_send(msgq_msg_t * msg, msgq_queue_t *q){
|
||||
// Die if we are no longer the active publisher
|
||||
if (q->write_uid_local != *q->write_uid){
|
||||
std::cout << "Killing old publisher: " << q->endpoint << std::endl;
|
||||
errno = EADDRINUSE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint64_t total_msg_size = ALIGN(msg->size + sizeof(int64_t));
|
||||
|
||||
// We need to fit at least three messages in the queue,
|
||||
// then we can always safely access the last message
|
||||
assert(3 * total_msg_size <= q->size);
|
||||
|
||||
uint64_t num_readers = *q->num_readers;
|
||||
|
||||
uint32_t write_cycles, write_pointer;
|
||||
UNPACK64(write_cycles, write_pointer, *q->write_pointer);
|
||||
|
||||
char *p = q->data + write_pointer; // add base offset
|
||||
|
||||
// Check remaining space
|
||||
// Always leave space for a wraparound tag for the next message, including alignment
|
||||
int64_t remaining_space = q->size - write_pointer - total_msg_size - sizeof(int64_t);
|
||||
if (remaining_space <= 0){
|
||||
// Write -1 size tag indicating wraparound
|
||||
*(int64_t*)p = -1;
|
||||
|
||||
// Invalidate all readers that are beyond the write pointer
|
||||
// TODO: should we handle the case where a new reader shows up while this is running?
|
||||
for (uint64_t i = 0; i < num_readers; i++){
|
||||
uint64_t read_pointer = *q->read_pointers[i];
|
||||
uint64_t read_cycles = read_pointer >> 32;
|
||||
read_pointer &= 0xFFFFFFFF;
|
||||
|
||||
if ((read_pointer > write_pointer) && (read_cycles != write_cycles)) {
|
||||
*q->read_valids[i] = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Update global and local copies of write pointer and write_cycles
|
||||
write_pointer = 0;
|
||||
write_cycles = write_cycles + 1;
|
||||
PACK64(*q->write_pointer, write_cycles, write_pointer);
|
||||
|
||||
// Set actual pointer to the beginning of the data segment
|
||||
p = q->data;
|
||||
}
|
||||
|
||||
// Invalidate readers that are in the area that will be written
|
||||
uint64_t start = write_pointer;
|
||||
uint64_t end = ALIGN(start + sizeof(int64_t) + msg->size);
|
||||
|
||||
for (uint64_t i = 0; i < num_readers; i++){
|
||||
uint32_t read_cycles, read_pointer;
|
||||
UNPACK64(read_cycles, read_pointer, *q->read_pointers[i]);
|
||||
|
||||
if ((read_pointer >= start) && (read_pointer < end) && (read_cycles != write_cycles)) {
|
||||
*q->read_valids[i] = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Write size tag
|
||||
std::atomic<int64_t> *size_p = reinterpret_cast<std::atomic<int64_t>*>(p);
|
||||
*size_p = msg->size;
|
||||
|
||||
// Copy data
|
||||
memcpy(p + sizeof(int64_t), msg->data, msg->size);
|
||||
__sync_synchronize();
|
||||
|
||||
// Update write pointer
|
||||
uint32_t new_ptr = ALIGN(write_pointer + msg->size + sizeof(int64_t));
|
||||
PACK64(*q->write_pointer, write_cycles, new_ptr);
|
||||
|
||||
// Notify readers
|
||||
for (uint64_t i = 0; i < num_readers; i++){
|
||||
uint64_t reader_uid = *q->read_uids[i];
|
||||
thread_signal(reader_uid & 0xFFFFFFFF);
|
||||
}
|
||||
|
||||
return msg->size;
|
||||
}
|
||||
|
||||
|
||||
int msgq_msg_ready(msgq_queue_t * q){
|
||||
start:
|
||||
int id = q->reader_id;
|
||||
assert(id >= 0); // Make sure subscriber is initialized
|
||||
|
||||
if (q->read_uid_local != *q->read_uids[id]){
|
||||
std::cout << q->endpoint << ": Reader was evicted, reconnecting" << std::endl;
|
||||
msgq_init_subscriber(q);
|
||||
goto start;
|
||||
}
|
||||
|
||||
// Check valid
|
||||
if (!*q->read_valids[id]){
|
||||
msgq_reset_reader(q);
|
||||
goto start;
|
||||
}
|
||||
|
||||
uint32_t read_cycles, read_pointer;
|
||||
UNPACK64(read_cycles, read_pointer, *q->read_pointers[id]);
|
||||
|
||||
uint32_t write_cycles, write_pointer;
|
||||
UNPACK64(write_cycles, write_pointer, *q->write_pointer);
|
||||
|
||||
// Check if new message is available
|
||||
return (read_pointer != write_pointer);
|
||||
}
|
||||
|
||||
int msgq_msg_recv(msgq_msg_t * msg, msgq_queue_t * q){
|
||||
start:
|
||||
int id = q->reader_id;
|
||||
assert(id >= 0); // Make sure subscriber is initialized
|
||||
|
||||
if (q->read_uid_local != *q->read_uids[id]){
|
||||
std::cout << q->endpoint << ": Reader was evicted, reconnecting" << std::endl;
|
||||
msgq_init_subscriber(q);
|
||||
goto start;
|
||||
}
|
||||
|
||||
// Check valid
|
||||
if (!*q->read_valids[id]){
|
||||
msgq_reset_reader(q);
|
||||
goto start;
|
||||
}
|
||||
|
||||
uint32_t read_cycles, read_pointer;
|
||||
UNPACK64(read_cycles, read_pointer, *q->read_pointers[id]);
|
||||
|
||||
uint32_t write_cycles, write_pointer;
|
||||
UNPACK64(write_cycles, write_pointer, *q->write_pointer);
|
||||
|
||||
char * p = q->data + read_pointer;
|
||||
|
||||
// Check if new message is available
|
||||
if (read_pointer == write_pointer) {
|
||||
msg->size = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Read potential message size
|
||||
std::atomic<int64_t> *size_p = reinterpret_cast<std::atomic<int64_t>*>(p);
|
||||
std::int64_t size = *size_p;
|
||||
|
||||
// Check if the size that was read is valid
|
||||
if (!*q->read_valids[id]){
|
||||
msgq_reset_reader(q);
|
||||
goto start;
|
||||
}
|
||||
|
||||
// If size is -1 the buffer was full, and we need to wrap around
|
||||
if (size == -1){
|
||||
read_cycles++;
|
||||
PACK64(*q->read_pointers[id], read_cycles, 0);
|
||||
goto start;
|
||||
}
|
||||
|
||||
// crashing is better than passing garbage data to the consumer
|
||||
// the size will have weird value if it was overwritten by data accidentally
|
||||
assert((uint64_t)size < q->size);
|
||||
assert(size > 0);
|
||||
|
||||
uint32_t new_read_pointer = ALIGN(read_pointer + sizeof(std::int64_t) + size);
|
||||
|
||||
// If conflate is true, check if this is the latest message, else start over
|
||||
if (q->read_conflate){
|
||||
if (new_read_pointer != write_pointer){
|
||||
// Update read pointer
|
||||
PACK64(*q->read_pointers[id], read_cycles, new_read_pointer);
|
||||
goto start;
|
||||
}
|
||||
}
|
||||
|
||||
// Copy message
|
||||
if (msgq_msg_init_size(msg, size) < 0)
|
||||
return -1;
|
||||
|
||||
__sync_synchronize();
|
||||
memcpy(msg->data, p + sizeof(int64_t), size);
|
||||
__sync_synchronize();
|
||||
|
||||
// Update read pointer
|
||||
PACK64(*q->read_pointers[id], read_cycles, new_read_pointer);
|
||||
|
||||
// Check if the actual data that was copied is valid
|
||||
if (!*q->read_valids[id]){
|
||||
msgq_msg_close(msg);
|
||||
msgq_reset_reader(q);
|
||||
goto start;
|
||||
}
|
||||
|
||||
|
||||
return msg->size;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int msgq_poll(msgq_pollitem_t * items, size_t nitems, int timeout){
|
||||
assert(timeout >= 0);
|
||||
|
||||
int num = 0;
|
||||
|
||||
// Check if messages ready
|
||||
for (size_t i = 0; i < nitems; i++) {
|
||||
items[i].revents = msgq_msg_ready(items[i].q);
|
||||
if (items[i].revents) num++;
|
||||
}
|
||||
|
||||
int ms = (timeout == -1) ? 100 : timeout;
|
||||
struct timespec ts;
|
||||
ts.tv_sec = ms / 1000;
|
||||
ts.tv_nsec = (ms % 1000) * 1000 * 1000;
|
||||
|
||||
|
||||
while (num == 0) {
|
||||
int ret;
|
||||
|
||||
ret = nanosleep(&ts, &ts);
|
||||
|
||||
// Check if messages ready
|
||||
for (size_t i = 0; i < nitems; i++) {
|
||||
if (items[i].revents == 0 && msgq_msg_ready(items[i].q)){
|
||||
num += 1;
|
||||
items[i].revents = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// exit if we had a timeout and the sleep finished
|
||||
if (timeout != -1 && ret == 0){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <atomic>
|
||||
|
||||
#define DEFAULT_SEGMENT_SIZE (10 * 1024 * 1024)
|
||||
#define NUM_READERS 8
|
||||
#define ALIGN(n) ((n + (8 - 1)) & -8)
|
||||
|
||||
#define UNPACK64(higher, lower, input) do {uint64_t tmp = input; higher = tmp >> 32; lower = tmp & 0xFFFFFFFF;} while (0)
|
||||
#define PACK64(output, higher, lower) output = ((uint64_t)higher << 32 ) | ((uint64_t)lower & 0xFFFFFFFF)
|
||||
|
||||
struct msgq_header_t {
|
||||
uint64_t num_readers;
|
||||
uint64_t write_pointer;
|
||||
uint64_t write_uid;
|
||||
uint64_t read_pointers[NUM_READERS];
|
||||
uint64_t read_valids[NUM_READERS];
|
||||
uint64_t read_uids[NUM_READERS];
|
||||
};
|
||||
|
||||
struct msgq_queue_t {
|
||||
std::atomic<uint64_t> *num_readers;
|
||||
std::atomic<uint64_t> *write_pointer;
|
||||
std::atomic<uint64_t> *write_uid;
|
||||
std::atomic<uint64_t> *read_pointers[NUM_READERS];
|
||||
std::atomic<uint64_t> *read_valids[NUM_READERS];
|
||||
std::atomic<uint64_t> *read_uids[NUM_READERS];
|
||||
char * mmap_p;
|
||||
char * data;
|
||||
size_t size;
|
||||
int reader_id;
|
||||
uint64_t read_uid_local;
|
||||
uint64_t write_uid_local;
|
||||
|
||||
bool read_conflate;
|
||||
std::string endpoint;
|
||||
};
|
||||
|
||||
struct msgq_msg_t {
|
||||
size_t size;
|
||||
char * data;
|
||||
};
|
||||
|
||||
struct msgq_pollitem_t {
|
||||
msgq_queue_t *q;
|
||||
int revents;
|
||||
};
|
||||
|
||||
void msgq_wait_for_subscriber(msgq_queue_t *q);
|
||||
void msgq_reset_reader(msgq_queue_t *q);
|
||||
|
||||
int msgq_msg_init_size(msgq_msg_t *msg, size_t size);
|
||||
int msgq_msg_init_data(msgq_msg_t *msg, char * data, size_t size);
|
||||
int msgq_msg_close(msgq_msg_t *msg);
|
||||
|
||||
int msgq_new_queue(msgq_queue_t * q, const char * path, size_t size);
|
||||
void msgq_close_queue(msgq_queue_t *q);
|
||||
void msgq_init_publisher(msgq_queue_t * q);
|
||||
void msgq_init_subscriber(msgq_queue_t * q);
|
||||
|
||||
int msgq_msg_send(msgq_msg_t *msg, msgq_queue_t *q);
|
||||
int msgq_msg_recv(msgq_msg_t *msg, msgq_queue_t *q);
|
||||
int msgq_msg_ready(msgq_queue_t * q);
|
||||
int msgq_poll(msgq_pollitem_t * items, size_t nitems, int timeout);
|
||||
@@ -1,56 +0,0 @@
|
||||
# MSGQ: A lock free single producer multi consumer message queue
|
||||
|
||||
[](https://dev.azure.com/commaai/default/_build/latest?definitionId=21&branchName=master)
|
||||
|
||||
## What is MSGQ?
|
||||
MSGQ is a system to pass messages from a single producer to multiple consumers. All the consumers need to be able to receive all the messages. It is designed to be a high performance replacement for ZMQ-like SUB/PUB patterns. It uses a ring buffer in shared memory to efficiently read and write data. Each read requires a copy. Writing can be done without a copy, as long as the size of the data is known in advance.
|
||||
|
||||
## Storage
|
||||
The storage for the queue consists of an area of metadata, and the actual buffer. The metadata contains:
|
||||
|
||||
1. A counter to the number of readers that are active
|
||||
2. A pointer to the head of the queue for writing. From now on referred to as *write pointer*
|
||||
3. A cycle counter for the writer. This counter is incremented when the writer wraps around
|
||||
4. N pointers, pointing to the current read position for all the readers. From now on referred to as *read pointer*
|
||||
5. N counters, counting the number of cycles for all the readers
|
||||
6. N booleans, indicating validity for all the readers. From now on referred to as *validity flag*
|
||||
|
||||
The counter and the pointer are both 32 bit values, packed into 64 bit so they can be read and written atomically.
|
||||
|
||||
The data buffer is a ring buffer. All messages are prefixed by an 8 byte size field, followed by the data. A size of -1 indicates a wrap-around, and means the next message is stored at the beginning of the buffer.
|
||||
|
||||
|
||||
## Writing
|
||||
Writing involves the following steps:
|
||||
|
||||
1. Check if the area that is to be written overlaps with any of the read pointers, mark those readers as invalid by clearing the validity flag.
|
||||
2. Write the message
|
||||
3. Increase the write pointer by the size of the message
|
||||
|
||||
In case there is not enough space at the end of the buffer, a special empty message with a prefix of -1 is written. The cycle counter is incremented by one. In this case step 1 will check there are no read pointers pointing to the remainder of the buffer. Then another write cycle will start with the actual message.
|
||||
|
||||
There always needs to be 8 bytes of empty space at the end of the buffer. By doing this there is always space to write the -1.
|
||||
|
||||
## Reset reader
|
||||
When the reader is lagging too much behind the read pointer becomes invalid and no longer points to the beginning of a valid message. To reset a reader to the current write pointer, the following steps are performed:
|
||||
|
||||
1. Set valid flag
|
||||
2. Set read cycle counter to that of the writer
|
||||
3. Set read pointer to write pointer
|
||||
|
||||
## Reading
|
||||
Reading involves the following steps:
|
||||
|
||||
1. Read the size field at the current read pointer
|
||||
2. Read the validity flag
|
||||
3. Copy the data out of the buffer
|
||||
4. Increase the read pointer by the size of the message
|
||||
5. Check the validity flag again
|
||||
|
||||
Before starting the copy, the valid flag is checked. This is to prevent a race condition where the size prefix was invalid, and the read could read outside of the buffer. Make sure that step 1 and 2 are not reordered by your compiler or CPU.
|
||||
|
||||
If a writer overwrites the data while it's being copied out, the data will be invalid. Therefore the validity flag is also checked after reading it. The order of step 4 and 5 does not matter.
|
||||
|
||||
If at steps 2 or 5 the validity flag is not set, the reader is reset. Any data that was already read is discarded. After the reader is reset, the reading starts from the beginning.
|
||||
|
||||
If a message with size -1 is encountered, step 3 and 4 are replaced by increasing the cycle counter and setting the read pointer to the beginning of the buffer. After that another read is performed.
|
||||
@@ -1,395 +0,0 @@
|
||||
#include "catch2/catch.hpp"
|
||||
#include "msgq.hpp"
|
||||
|
||||
TEST_CASE("ALIGN"){
|
||||
REQUIRE(ALIGN(0) == 0);
|
||||
REQUIRE(ALIGN(1) == 8);
|
||||
REQUIRE(ALIGN(7) == 8);
|
||||
REQUIRE(ALIGN(8) == 8);
|
||||
REQUIRE(ALIGN(99999) == 100000);
|
||||
}
|
||||
|
||||
TEST_CASE("msgq_msg_init_size"){
|
||||
const size_t msg_size = 30;
|
||||
msgq_msg_t msg;
|
||||
|
||||
msgq_msg_init_size(&msg, msg_size);
|
||||
REQUIRE(msg.size == msg_size);
|
||||
|
||||
msgq_msg_close(&msg);
|
||||
}
|
||||
|
||||
TEST_CASE("msgq_msg_init_data"){
|
||||
const size_t msg_size = 30;
|
||||
char * data = new char[msg_size];
|
||||
|
||||
for (size_t i = 0; i < msg_size; i++){
|
||||
data[i] = i;
|
||||
}
|
||||
|
||||
msgq_msg_t msg;
|
||||
msgq_msg_init_data(&msg, data, msg_size);
|
||||
|
||||
REQUIRE(msg.size == msg_size);
|
||||
REQUIRE(memcmp(msg.data, data, msg_size) == 0);
|
||||
|
||||
delete[] data;
|
||||
msgq_msg_close(&msg);
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("msgq_init_subscriber"){
|
||||
remove("/dev/shm/test_queue");
|
||||
msgq_queue_t q;
|
||||
msgq_new_queue(&q, "test_queue", 1024);
|
||||
REQUIRE(*q.num_readers == 0);
|
||||
|
||||
q.reader_id = 1;
|
||||
*q.read_valids[0] = false;
|
||||
*q.read_pointers[0] = ((uint64_t)1 << 32);
|
||||
|
||||
*q.write_pointer = 255;
|
||||
|
||||
msgq_init_subscriber(&q);
|
||||
REQUIRE(q.read_conflate == false);
|
||||
REQUIRE(*q.read_valids[0] == true);
|
||||
REQUIRE((*q.read_pointers[0] >> 32) == 0);
|
||||
REQUIRE((*q.read_pointers[0] & 0xFFFFFFFF) == 255);
|
||||
}
|
||||
|
||||
TEST_CASE("msgq_msg_send first message"){
|
||||
remove("/dev/shm/test_queue");
|
||||
msgq_queue_t q;
|
||||
msgq_new_queue(&q, "test_queue", 1024);
|
||||
msgq_init_publisher(&q);
|
||||
|
||||
REQUIRE(*q.write_pointer == 0);
|
||||
|
||||
size_t msg_size = 128;
|
||||
|
||||
SECTION("Aligned message size"){
|
||||
}
|
||||
SECTION("Unaligned message size"){
|
||||
msg_size--;
|
||||
}
|
||||
|
||||
char * data = new char[msg_size];
|
||||
|
||||
for (size_t i = 0; i < msg_size; i++){
|
||||
data[i] = i;
|
||||
}
|
||||
|
||||
msgq_msg_t msg;
|
||||
msgq_msg_init_data(&msg, data, msg_size);
|
||||
|
||||
|
||||
msgq_msg_send(&msg, &q);
|
||||
REQUIRE(*(int64_t*)q.data == msg_size); // Check size tag
|
||||
REQUIRE(*q.write_pointer == 128 + sizeof(int64_t));
|
||||
REQUIRE(memcmp(q.data + sizeof(int64_t), data, msg_size) == 0);
|
||||
|
||||
delete[] data;
|
||||
msgq_msg_close(&msg);
|
||||
}
|
||||
|
||||
TEST_CASE("msgq_msg_send test wraparound"){
|
||||
remove("/dev/shm/test_queue");
|
||||
msgq_queue_t q;
|
||||
msgq_new_queue(&q, "test_queue", 1024);
|
||||
msgq_init_publisher(&q);
|
||||
|
||||
REQUIRE((*q.write_pointer & 0xFFFFFFFF) == 0);
|
||||
REQUIRE((*q.write_pointer >> 32) == 0);
|
||||
|
||||
const size_t msg_size = 120;
|
||||
msgq_msg_t msg;
|
||||
msgq_msg_init_size(&msg, msg_size);
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
msgq_msg_send(&msg, &q);
|
||||
}
|
||||
// Check 8th message was written at the beginning
|
||||
REQUIRE((*q.write_pointer & 0xFFFFFFFF) == msg_size + sizeof(int64_t));
|
||||
|
||||
// Check cycle count
|
||||
REQUIRE((*q.write_pointer >> 32) == 1);
|
||||
|
||||
// Check wraparound tag
|
||||
char * tag_location = q.data;
|
||||
tag_location += 7 * (msg_size + sizeof(int64_t));
|
||||
REQUIRE(*(int64_t*)tag_location == -1);
|
||||
|
||||
msgq_msg_close(&msg);
|
||||
}
|
||||
|
||||
TEST_CASE("msgq_msg_recv test wraparound"){
|
||||
remove("/dev/shm/test_queue");
|
||||
msgq_queue_t q_pub, q_sub;
|
||||
msgq_new_queue(&q_pub, "test_queue", 1024);
|
||||
msgq_new_queue(&q_sub, "test_queue", 1024);
|
||||
|
||||
msgq_init_publisher(&q_pub);
|
||||
msgq_init_subscriber(&q_sub);
|
||||
|
||||
REQUIRE((*q_pub.write_pointer >> 32) == 0);
|
||||
REQUIRE((*q_sub.read_pointers[0] >> 32) == 0);
|
||||
|
||||
const size_t msg_size = 120;
|
||||
msgq_msg_t msg1;
|
||||
msgq_msg_init_size(&msg1, msg_size);
|
||||
|
||||
|
||||
SECTION("Check cycle counter after reset") {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
msgq_msg_send(&msg1, &q_pub);
|
||||
}
|
||||
|
||||
msgq_msg_t msg2;
|
||||
msgq_msg_recv(&msg2, &q_sub);
|
||||
REQUIRE(msg2.size == 0); // Reader had to reset
|
||||
msgq_msg_close(&msg2);
|
||||
|
||||
}
|
||||
SECTION("Check cycle counter while keeping up with writer") {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
msgq_msg_send(&msg1, &q_pub);
|
||||
|
||||
msgq_msg_t msg2;
|
||||
msgq_msg_recv(&msg2, &q_sub);
|
||||
REQUIRE(msg2.size > 0);
|
||||
msgq_msg_close(&msg2);
|
||||
}
|
||||
}
|
||||
|
||||
REQUIRE((*q_sub.read_pointers[0] >> 32) == 1);
|
||||
msgq_msg_close(&msg1);
|
||||
}
|
||||
|
||||
TEST_CASE("msgq_msg_send test invalidation"){
|
||||
remove("/dev/shm/test_queue");
|
||||
msgq_queue_t q_pub, q_sub;
|
||||
msgq_new_queue(&q_pub, "test_queue", 1024);
|
||||
msgq_new_queue(&q_sub, "test_queue", 1024);
|
||||
|
||||
msgq_init_publisher(&q_pub);
|
||||
msgq_init_subscriber(&q_sub);
|
||||
*q_sub.write_pointer = (uint64_t)1 << 32;
|
||||
|
||||
REQUIRE(*q_sub.read_valids[0] == true);
|
||||
|
||||
SECTION("read pointer in tag"){
|
||||
*q_sub.read_pointers[0] = 0;
|
||||
}
|
||||
SECTION("read pointer in data section"){
|
||||
*q_sub.read_pointers[0] = 64;
|
||||
}
|
||||
SECTION("read pointer in wraparound section"){
|
||||
*q_pub.write_pointer = ((uint64_t)1 << 32) | 1000; // Writer is one cycle ahead
|
||||
*q_sub.read_pointers[0] = 1020;
|
||||
}
|
||||
|
||||
msgq_msg_t msg;
|
||||
msgq_msg_init_size(&msg, 128);
|
||||
msgq_msg_send(&msg, &q_pub);
|
||||
|
||||
REQUIRE(*q_sub.read_valids[0] == false);
|
||||
|
||||
msgq_msg_close(&msg);
|
||||
}
|
||||
|
||||
TEST_CASE("msgq_init_subscriber init 2 subscribers"){
|
||||
remove("/dev/shm/test_queue");
|
||||
msgq_queue_t q1, q2;
|
||||
msgq_new_queue(&q1, "test_queue", 1024);
|
||||
msgq_new_queue(&q2, "test_queue", 1024);
|
||||
|
||||
*q1.num_readers = 0;
|
||||
|
||||
REQUIRE(*q1.num_readers == 0);
|
||||
REQUIRE(*q2.num_readers == 0);
|
||||
|
||||
msgq_init_subscriber(&q1);
|
||||
REQUIRE(*q1.num_readers == 1);
|
||||
REQUIRE(*q2.num_readers == 1);
|
||||
REQUIRE(q1.reader_id == 0);
|
||||
|
||||
msgq_init_subscriber(&q2);
|
||||
REQUIRE(*q1.num_readers == 2);
|
||||
REQUIRE(*q2.num_readers == 2);
|
||||
REQUIRE(q2.reader_id == 1);
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("Write 1 msg, read 1 msg", "[integration]"){
|
||||
remove("/dev/shm/test_queue");
|
||||
const size_t msg_size = 128;
|
||||
msgq_queue_t writer, reader;
|
||||
|
||||
msgq_new_queue(&writer, "test_queue", 1024);
|
||||
msgq_new_queue(&reader, "test_queue", 1024);
|
||||
|
||||
msgq_init_publisher(&writer);
|
||||
msgq_init_subscriber(&reader);
|
||||
|
||||
// Build 128 byte message
|
||||
msgq_msg_t outgoing_msg;
|
||||
msgq_msg_init_size(&outgoing_msg, msg_size);
|
||||
|
||||
for (size_t i = 0; i < msg_size; i++){
|
||||
outgoing_msg.data[i] = i;
|
||||
}
|
||||
|
||||
REQUIRE(msgq_msg_send(&outgoing_msg, &writer) == msg_size);
|
||||
|
||||
msgq_msg_t incoming_msg1;
|
||||
REQUIRE(msgq_msg_recv(&incoming_msg1, &reader) == msg_size);
|
||||
REQUIRE(memcmp(incoming_msg1.data, outgoing_msg.data, msg_size) == 0);
|
||||
|
||||
// Verify that there are no more messages
|
||||
msgq_msg_t incoming_msg2;
|
||||
REQUIRE(msgq_msg_recv(&incoming_msg2, &reader) == 0);
|
||||
|
||||
msgq_msg_close(&outgoing_msg);
|
||||
msgq_msg_close(&incoming_msg1);
|
||||
msgq_msg_close(&incoming_msg2);
|
||||
}
|
||||
|
||||
TEST_CASE("Write 2 msg, read 2 msg - conflate = false", "[integration]"){
|
||||
remove("/dev/shm/test_queue");
|
||||
const size_t msg_size = 128;
|
||||
msgq_queue_t writer, reader;
|
||||
|
||||
msgq_new_queue(&writer, "test_queue", 1024);
|
||||
msgq_new_queue(&reader, "test_queue", 1024);
|
||||
|
||||
msgq_init_publisher(&writer);
|
||||
msgq_init_subscriber(&reader);
|
||||
|
||||
// Build 128 byte message
|
||||
msgq_msg_t outgoing_msg;
|
||||
msgq_msg_init_size(&outgoing_msg, msg_size);
|
||||
|
||||
for (size_t i = 0; i < msg_size; i++){
|
||||
outgoing_msg.data[i] = i;
|
||||
}
|
||||
|
||||
REQUIRE(msgq_msg_send(&outgoing_msg, &writer) == msg_size);
|
||||
REQUIRE(msgq_msg_send(&outgoing_msg, &writer) == msg_size);
|
||||
|
||||
msgq_msg_t incoming_msg1;
|
||||
REQUIRE(msgq_msg_recv(&incoming_msg1, &reader) == msg_size);
|
||||
REQUIRE(memcmp(incoming_msg1.data, outgoing_msg.data, msg_size) == 0);
|
||||
|
||||
msgq_msg_t incoming_msg2;
|
||||
REQUIRE(msgq_msg_recv(&incoming_msg2, &reader) == msg_size);
|
||||
REQUIRE(memcmp(incoming_msg2.data, outgoing_msg.data, msg_size) == 0);
|
||||
|
||||
msgq_msg_close(&outgoing_msg);
|
||||
msgq_msg_close(&incoming_msg1);
|
||||
msgq_msg_close(&incoming_msg2);
|
||||
}
|
||||
|
||||
TEST_CASE("Write 2 msg, read 2 msg - conflate = true", "[integration]"){
|
||||
remove("/dev/shm/test_queue");
|
||||
const size_t msg_size = 128;
|
||||
msgq_queue_t writer, reader;
|
||||
|
||||
msgq_new_queue(&writer, "test_queue", 1024);
|
||||
msgq_new_queue(&reader, "test_queue", 1024);
|
||||
|
||||
msgq_init_publisher(&writer);
|
||||
msgq_init_subscriber(&reader);
|
||||
reader.read_conflate = true;
|
||||
|
||||
// Build 128 byte message
|
||||
msgq_msg_t outgoing_msg;
|
||||
msgq_msg_init_size(&outgoing_msg, msg_size);
|
||||
|
||||
for (size_t i = 0; i < msg_size; i++){
|
||||
outgoing_msg.data[i] = i;
|
||||
}
|
||||
|
||||
REQUIRE(msgq_msg_send(&outgoing_msg, &writer) == msg_size);
|
||||
REQUIRE(msgq_msg_send(&outgoing_msg, &writer) == msg_size);
|
||||
|
||||
msgq_msg_t incoming_msg1;
|
||||
REQUIRE(msgq_msg_recv(&incoming_msg1, &reader) == msg_size);
|
||||
REQUIRE(memcmp(incoming_msg1.data, outgoing_msg.data, msg_size) == 0);
|
||||
|
||||
// Verify that there are no more messages
|
||||
msgq_msg_t incoming_msg2;
|
||||
REQUIRE(msgq_msg_recv(&incoming_msg2, &reader) == 0);
|
||||
|
||||
msgq_msg_close(&outgoing_msg);
|
||||
msgq_msg_close(&incoming_msg1);
|
||||
msgq_msg_close(&incoming_msg2);
|
||||
}
|
||||
|
||||
TEST_CASE("1 publisher, 1 slow subscriber", "[integration]"){
|
||||
remove("/dev/shm/test_queue");
|
||||
msgq_queue_t writer, reader;
|
||||
|
||||
msgq_new_queue(&writer, "test_queue", 1024);
|
||||
msgq_new_queue(&reader, "test_queue", 1024);
|
||||
|
||||
msgq_init_publisher(&writer);
|
||||
msgq_init_subscriber(&reader);
|
||||
|
||||
int n_received = 0;
|
||||
int n_skipped = 0;
|
||||
|
||||
for (uint64_t i = 0; i < 1e5; i++) {
|
||||
msgq_msg_t outgoing_msg;
|
||||
msgq_msg_init_data(&outgoing_msg, (char*)&i, sizeof(uint64_t));
|
||||
msgq_msg_send(&outgoing_msg, &writer);
|
||||
msgq_msg_close(&outgoing_msg);
|
||||
|
||||
if (i % 10 == 0){
|
||||
msgq_msg_t msg1;
|
||||
msgq_msg_recv(&msg1, &reader);
|
||||
|
||||
if (msg1.size == 0){
|
||||
n_skipped++;
|
||||
} else {
|
||||
n_received++;
|
||||
}
|
||||
msgq_msg_close(&msg1);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: verify these numbers by hand
|
||||
REQUIRE(n_received == 8572);
|
||||
REQUIRE(n_skipped == 1428);
|
||||
}
|
||||
|
||||
TEST_CASE("1 publisher, 2 subscribers", "[integration]"){
|
||||
remove("/dev/shm/test_queue");
|
||||
msgq_queue_t writer, reader1, reader2;
|
||||
|
||||
msgq_new_queue(&writer, "test_queue", 1024);
|
||||
msgq_new_queue(&reader1, "test_queue", 1024);
|
||||
msgq_new_queue(&reader2, "test_queue", 1024);
|
||||
|
||||
msgq_init_publisher(&writer);
|
||||
msgq_init_subscriber(&reader1);
|
||||
msgq_init_subscriber(&reader2);
|
||||
|
||||
for (uint64_t i = 0; i < 1024 * 3; i++) {
|
||||
msgq_msg_t outgoing_msg;
|
||||
msgq_msg_init_data(&outgoing_msg, (char*)&i, sizeof(uint64_t));
|
||||
msgq_msg_send(&outgoing_msg, &writer);
|
||||
|
||||
msgq_msg_t msg1, msg2;
|
||||
msgq_msg_recv(&msg1, &reader1);
|
||||
msgq_msg_recv(&msg2, &reader2);
|
||||
|
||||
REQUIRE(msg1.size == sizeof(uint64_t));
|
||||
REQUIRE(msg2.size == sizeof(uint64_t));
|
||||
REQUIRE(*(uint64_t*)msg1.data == i);
|
||||
REQUIRE(*(uint64_t*)msg2.data == i);
|
||||
|
||||
msgq_msg_close(&outgoing_msg);
|
||||
msgq_msg_close(&msg1);
|
||||
msgq_msg_close(&msg2);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
from messaging_pyx import Context, SubSocket, PubSocket # pylint: disable=no-name-in-module, import-error
|
||||
|
||||
if __name__ == "__main__":
|
||||
c = Context()
|
||||
pub_sock = PubSocket()
|
||||
pub_sock.connect(c, "controlsState")
|
||||
|
||||
for i in range(int(1e10)):
|
||||
print(i)
|
||||
sub_sock = SubSocket()
|
||||
sub_sock.connect(c, "controlsState")
|
||||
|
||||
pub_sock.send(b'a')
|
||||
print(sub_sock.receive())
|
||||
@@ -1,2 +0,0 @@
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include "catch2/catch.hpp"
|
||||
@@ -1,142 +0,0 @@
|
||||
import unittest
|
||||
import time
|
||||
import cereal.messaging as messaging
|
||||
|
||||
import concurrent.futures
|
||||
|
||||
|
||||
def poller():
|
||||
context = messaging.Context()
|
||||
|
||||
p = messaging.Poller()
|
||||
|
||||
sub = messaging.SubSocket()
|
||||
sub.connect(context, 'controlsState')
|
||||
p.registerSocket(sub)
|
||||
|
||||
socks = p.poll(10000)
|
||||
r = [s.receive(non_blocking=True) for s in socks]
|
||||
|
||||
return r
|
||||
|
||||
|
||||
class TestPoller(unittest.TestCase):
|
||||
def test_poll_once(self):
|
||||
context = messaging.Context()
|
||||
|
||||
pub = messaging.PubSocket()
|
||||
pub.connect(context, 'controlsState')
|
||||
|
||||
with concurrent.futures.ThreadPoolExecutor() as e:
|
||||
poll = e.submit(poller)
|
||||
|
||||
time.sleep(0.1) # Slow joiner syndrome
|
||||
|
||||
# Send message
|
||||
pub.send("a")
|
||||
|
||||
# Wait for poll result
|
||||
result = poll.result()
|
||||
|
||||
del pub
|
||||
context.term()
|
||||
|
||||
self.assertEqual(result, [b"a"])
|
||||
|
||||
def test_poll_and_create_many_subscribers(self):
|
||||
context = messaging.Context()
|
||||
|
||||
pub = messaging.PubSocket()
|
||||
pub.connect(context, 'controlsState')
|
||||
|
||||
with concurrent.futures.ThreadPoolExecutor() as e:
|
||||
poll = e.submit(poller)
|
||||
|
||||
time.sleep(0.1) # Slow joiner syndrome
|
||||
c = messaging.Context()
|
||||
for _ in range(10):
|
||||
messaging.SubSocket().connect(c, 'controlsState')
|
||||
|
||||
time.sleep(0.1)
|
||||
|
||||
# Send message
|
||||
pub.send("a")
|
||||
|
||||
# Wait for poll result
|
||||
result = poll.result()
|
||||
|
||||
del pub
|
||||
context.term()
|
||||
|
||||
self.assertEqual(result, [b"a"])
|
||||
|
||||
def test_multiple_publishers_exception(self):
|
||||
context = messaging.Context()
|
||||
|
||||
with self.assertRaises(messaging.MultiplePublishersError):
|
||||
pub1 = messaging.PubSocket()
|
||||
pub1.connect(context, 'controlsState')
|
||||
|
||||
pub2 = messaging.PubSocket()
|
||||
pub2.connect(context, 'controlsState')
|
||||
|
||||
pub1.send("a")
|
||||
|
||||
del pub1
|
||||
del pub2
|
||||
context.term()
|
||||
|
||||
def test_multiple_messages(self):
|
||||
context = messaging.Context()
|
||||
|
||||
pub = messaging.PubSocket()
|
||||
pub.connect(context, 'controlsState')
|
||||
|
||||
sub = messaging.SubSocket()
|
||||
sub.connect(context, 'controlsState')
|
||||
|
||||
time.sleep(0.1) # Slow joiner
|
||||
|
||||
for i in range(100):
|
||||
pub.send(str(i))
|
||||
|
||||
msg_seen = False
|
||||
i = 0
|
||||
while True:
|
||||
r = sub.receive(non_blocking=True)
|
||||
|
||||
if r is not None:
|
||||
self.assertEqual(str(i), r.decode('utf8'))
|
||||
|
||||
msg_seen = True
|
||||
i += 1
|
||||
|
||||
if r is None and msg_seen: # ZMQ sometimes receives nothing on the first receive
|
||||
break
|
||||
|
||||
del pub
|
||||
del sub
|
||||
context.term()
|
||||
|
||||
def test_conflate(self):
|
||||
context = messaging.Context()
|
||||
|
||||
pub = messaging.PubSocket()
|
||||
pub.connect(context, 'controlsState')
|
||||
|
||||
sub = messaging.SubSocket()
|
||||
sub.connect(context, 'controlsState', conflate=True)
|
||||
|
||||
time.sleep(0.1) # Slow joiner
|
||||
pub.send('a')
|
||||
pub.send('b')
|
||||
|
||||
self.assertEqual(b'b', sub.receive())
|
||||
|
||||
del pub
|
||||
del sub
|
||||
context.term()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -1,33 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
import yaml
|
||||
|
||||
class Service():
|
||||
def __init__(self, port, should_log, frequency, decimation=None):
|
||||
self.port = port
|
||||
self.should_log = should_log
|
||||
self.frequency = frequency
|
||||
self.decimation = decimation
|
||||
|
||||
service_list_path = os.path.join(os.path.dirname(__file__), "service_list.yaml")
|
||||
|
||||
service_list = {}
|
||||
with open(service_list_path, "r") as f:
|
||||
for k, v in yaml.safe_load(f).items():
|
||||
decimation = None
|
||||
if len(v) == 4:
|
||||
decimation = v[3]
|
||||
|
||||
service_list[k] = Service(v[0], v[1], v[2], decimation)
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("/* THIS IS AN AUTOGENERATED FILE, PLEASE EDIT service_list.yaml */")
|
||||
print("#ifndef __SERVICES_H")
|
||||
print("#define __SERVICES_H")
|
||||
print("struct service { int port; bool should_log; int frequency; int decimation; char name[0x100]; };")
|
||||
print("static struct service services[] = {")
|
||||
for k, v in service_list.items():
|
||||
print(' { .name = "%s", .port = %d, .should_log = %s, .frequency = %d, .decimation = %d },' % (k, v.port, "true" if v.should_log else "false", v.frequency, -1 if v.decimation is None else v.decimation))
|
||||
print("};")
|
||||
print("#endif")
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
pyflakes $(find . -iname "*.py" | grep -vi "^\./pyextra.*" | grep -vi "^\./panda")
|
||||
RESULT=$?
|
||||
if [ $RESULT -eq 0 ]; then
|
||||
pylint $(find . -iname "*.py" | grep -vi "^\./pyextra.*" | grep -vi "^\./panda")
|
||||
RESULT=$? & 3
|
||||
fi
|
||||
|
||||
[ $RESULT -ne 0 ] && exit 1
|
||||
exit 0
|
||||
@@ -1 +0,0 @@
|
||||
*.cpp
|
||||
@@ -1,6 +0,0 @@
|
||||
Import('env')
|
||||
|
||||
# parser
|
||||
env.Command(['common_pyx.so'],
|
||||
['common_pyx_setup.py', 'clock.pyx'],
|
||||
"cd common && python3 common_pyx_setup.py build_ext --inplace")
|
||||
@@ -1,130 +0,0 @@
|
||||
import os
|
||||
import binascii
|
||||
import itertools
|
||||
import re
|
||||
import struct
|
||||
import subprocess
|
||||
import random
|
||||
from cereal import log
|
||||
|
||||
NetworkType = log.ThermalData.NetworkType
|
||||
|
||||
ANDROID = os.path.isfile('/EON')
|
||||
|
||||
def getprop(key):
|
||||
if not ANDROID:
|
||||
return ""
|
||||
return subprocess.check_output(["getprop", key], encoding='utf8').strip()
|
||||
|
||||
def get_imei(slot):
|
||||
slot = str(slot)
|
||||
if slot not in ("0", "1"):
|
||||
raise ValueError("SIM slot must be 0 or 1")
|
||||
|
||||
ret = parse_service_call_string(service_call(["iphonesubinfo", "3" ,"i32", str(slot)]))
|
||||
if not ret:
|
||||
# allow non android to be identified differently
|
||||
ret = "%015d" % random.randint(0, 1<<32)
|
||||
return ret
|
||||
|
||||
def get_serial():
|
||||
ret = getprop("ro.serialno")
|
||||
if ret == "":
|
||||
ret = "cccccccc"
|
||||
return ret
|
||||
|
||||
def get_subscriber_info():
|
||||
ret = parse_service_call_string(service_call(["iphonesubinfo", "7"]))
|
||||
if ret is None or len(ret) < 8:
|
||||
return ""
|
||||
return ret
|
||||
|
||||
def reboot(reason=None):
|
||||
if reason is None:
|
||||
reason_args = ["null"]
|
||||
else:
|
||||
reason_args = ["s16", reason]
|
||||
|
||||
subprocess.check_output([
|
||||
"service", "call", "power", "16", # IPowerManager.reboot
|
||||
"i32", "0", # no confirmation,
|
||||
*reason_args,
|
||||
"i32", "1" # wait
|
||||
])
|
||||
|
||||
def service_call(call):
|
||||
if not ANDROID:
|
||||
return None
|
||||
|
||||
ret = subprocess.check_output(["service", "call", *call], encoding='utf8').strip()
|
||||
if 'Parcel' not in ret:
|
||||
return None
|
||||
|
||||
return parse_service_call_bytes(ret)
|
||||
|
||||
def parse_service_call_unpack(r, fmt):
|
||||
try:
|
||||
return struct.unpack(fmt, r)[0]
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
def parse_service_call_string(r):
|
||||
try:
|
||||
r = r[8:] # Cut off length field
|
||||
r = r.decode('utf_16_be')
|
||||
|
||||
# All pairs of two characters seem to be swapped. Not sure why
|
||||
result = ""
|
||||
for a, b, in itertools.zip_longest(r[::2], r[1::2], fillvalue='\x00'):
|
||||
result += b + a
|
||||
|
||||
result = result.replace('\x00', '')
|
||||
|
||||
return result
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
def parse_service_call_bytes(ret):
|
||||
try:
|
||||
r = b""
|
||||
for hex_part in re.findall(r'[ (]([0-9a-f]{8})', ret):
|
||||
r += binascii.unhexlify(hex_part)
|
||||
return r
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
def get_network_type():
|
||||
if not ANDROID:
|
||||
return NetworkType.none
|
||||
|
||||
wifi_check = parse_service_call_string(service_call(["connectivity", "2"]))
|
||||
if wifi_check is None:
|
||||
return NetworkType.none
|
||||
elif 'WIFI' in wifi_check:
|
||||
return NetworkType.wifi
|
||||
else:
|
||||
cell_check = parse_service_call_unpack(service_call(['phone', '59']), ">q")
|
||||
# from TelephonyManager.java
|
||||
cell_networks = {
|
||||
0: NetworkType.none,
|
||||
1: NetworkType.cell2G,
|
||||
2: NetworkType.cell2G,
|
||||
3: NetworkType.cell3G,
|
||||
4: NetworkType.cell2G,
|
||||
5: NetworkType.cell3G,
|
||||
6: NetworkType.cell3G,
|
||||
7: NetworkType.cell3G,
|
||||
8: NetworkType.cell3G,
|
||||
9: NetworkType.cell3G,
|
||||
10: NetworkType.cell3G,
|
||||
11: NetworkType.cell2G,
|
||||
12: NetworkType.cell3G,
|
||||
13: NetworkType.cell4G,
|
||||
14: NetworkType.cell4G,
|
||||
15: NetworkType.cell3G,
|
||||
16: NetworkType.cell2G,
|
||||
17: NetworkType.cell3G,
|
||||
18: NetworkType.cell4G,
|
||||
19: NetworkType.cell4G
|
||||
}
|
||||
return cell_networks.get(cell_check, NetworkType.none)
|
||||
@@ -1,13 +1,13 @@
|
||||
import jwt
|
||||
import requests
|
||||
from datetime import datetime, timedelta
|
||||
from common.basedir import PERSIST
|
||||
|
||||
from selfdrive.version import version
|
||||
|
||||
class Api():
|
||||
def __init__(self, dongle_id):
|
||||
self.dongle_id = dongle_id
|
||||
with open(PERSIST+'/comma/id_rsa') as f:
|
||||
with open('/persist/comma/id_rsa') as f:
|
||||
self.private_key = f.read()
|
||||
|
||||
def get(self, *args, **kwargs):
|
||||
|
||||
@@ -1,99 +0,0 @@
|
||||
import os
|
||||
import subprocess
|
||||
import glob
|
||||
import hashlib
|
||||
import shutil
|
||||
from common.basedir import BASEDIR
|
||||
from selfdrive.swaglog import cloudlog
|
||||
|
||||
android_packages = ("tw.com.ainvest.outpack", "cn.dragonpilot.gpsservice", "com.autonavi.amapauto", "com.mixplorer", "com.tomtom.speedcams.android.map", "ai.comma.plus.offroad", "ai.comma.plus.frame")
|
||||
|
||||
def get_installed_apks():
|
||||
dat = subprocess.check_output(["pm", "list", "packages", "-f"], encoding='utf8').strip().split("\n")
|
||||
ret = {}
|
||||
for x in dat:
|
||||
if x.startswith("package:"):
|
||||
v,k = x.split("package:")[1].split("=")
|
||||
ret[k] = v
|
||||
return ret
|
||||
|
||||
def install_apk(path):
|
||||
# can only install from world readable path
|
||||
install_path = "/sdcard/%s" % os.path.basename(path)
|
||||
shutil.copyfile(path, install_path)
|
||||
|
||||
ret = subprocess.call(["pm", "install", "-r", install_path])
|
||||
os.remove(install_path)
|
||||
return ret == 0
|
||||
|
||||
def start_frame():
|
||||
set_package_permissions()
|
||||
system("am start -n ai.comma.plus.frame/.MainActivity")
|
||||
|
||||
def set_package_permissions():
|
||||
pm_grant("ai.comma.plus.offroad", "android.permission.ACCESS_FINE_LOCATION")
|
||||
pm_grant("ai.comma.plus.offroad", "android.permission.READ_PHONE_STATE")
|
||||
appops_set("ai.comma.plus.offroad", "SU", "allow")
|
||||
appops_set("ai.comma.plus.offroad", "WIFI_SCAN", "allow")
|
||||
appops_set("ai.comma.plus.offroad", "READ_EXTERNAL_STORAGE", "allow")
|
||||
appops_set("ai.comma.plus.offroad", "WRITE_EXTERNAL_STORAGE", "allow")
|
||||
|
||||
def appops_set(package, op, mode):
|
||||
system(f"LD_LIBRARY_PATH= appops set {package} {op} {mode}")
|
||||
|
||||
def pm_grant(package, permission):
|
||||
system(f"pm grant {package} {permission}")
|
||||
|
||||
def system(cmd):
|
||||
try:
|
||||
cloudlog.info("running %s" % cmd)
|
||||
subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True)
|
||||
except subprocess.CalledProcessError as e:
|
||||
cloudlog.event("running failed",
|
||||
cmd=e.cmd,
|
||||
output=e.output[-1024:],
|
||||
returncode=e.returncode)
|
||||
|
||||
# *** external functions ***
|
||||
|
||||
def update_apks():
|
||||
# install apks
|
||||
installed = get_installed_apks()
|
||||
|
||||
install_apks = glob.glob(os.path.join(BASEDIR, "apk/*.apk"))
|
||||
for apk in install_apks:
|
||||
app = os.path.basename(apk)[:-4]
|
||||
if app not in installed:
|
||||
installed[app] = None
|
||||
|
||||
cloudlog.info("installed apks %s" % (str(installed), ))
|
||||
|
||||
for app in installed.keys():
|
||||
apk_path = os.path.join(BASEDIR, "apk/"+app+".apk")
|
||||
if not os.path.exists(apk_path):
|
||||
continue
|
||||
|
||||
h1 = hashlib.sha1(open(apk_path, 'rb').read()).hexdigest()
|
||||
h2 = None
|
||||
if installed[app] is not None:
|
||||
h2 = hashlib.sha1(open(installed[app], 'rb').read()).hexdigest()
|
||||
cloudlog.info("comparing version of %s %s vs %s" % (app, h1, h2))
|
||||
|
||||
if h2 is None or h1 != h2:
|
||||
cloudlog.info("installing %s" % app)
|
||||
|
||||
success = install_apk(apk_path)
|
||||
if not success:
|
||||
cloudlog.info("needing to uninstall %s" % app)
|
||||
system("pm uninstall %s" % app)
|
||||
success = install_apk(apk_path)
|
||||
|
||||
assert success
|
||||
|
||||
def pm_apply_packages(cmd):
|
||||
for p in android_packages:
|
||||
system("pm %s %s" % (cmd, p))
|
||||
|
||||
if __name__ == "__main__":
|
||||
update_apks()
|
||||
|
||||
@@ -1,11 +1,4 @@
|
||||
import os
|
||||
BASEDIR = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), "../"))
|
||||
|
||||
from common.android import ANDROID
|
||||
if ANDROID:
|
||||
PERSIST = "/persist"
|
||||
PARAMS = "/data/params"
|
||||
else:
|
||||
PERSIST = os.path.join(BASEDIR, "persist")
|
||||
PARAMS = os.path.join(BASEDIR, "persist", "params")
|
||||
|
||||
|
||||
+9
-15
@@ -1,22 +1,16 @@
|
||||
from posix.time cimport clock_gettime, timespec, CLOCK_MONOTONIC_RAW, clockid_t
|
||||
from posix.time cimport clock_gettime, timespec, CLOCK_BOOTTIME, CLOCK_MONOTONIC_RAW
|
||||
|
||||
IF UNAME_SYSNAME == "Darwin":
|
||||
# Darwin doesn't have a CLOCK_BOOTTIME
|
||||
CLOCK_BOOTTIME = CLOCK_MONOTONIC_RAW
|
||||
ELSE:
|
||||
from posix.time cimport CLOCK_BOOTTIME
|
||||
cdef double readclock(int clock_id):
|
||||
cdef timespec ts
|
||||
cdef double current
|
||||
|
||||
cdef double readclock(clockid_t clock_id):
|
||||
cdef timespec ts
|
||||
cdef double current
|
||||
clock_gettime(clock_id, &ts)
|
||||
current = ts.tv_sec + (ts.tv_nsec / 1000000000.)
|
||||
return current
|
||||
|
||||
clock_gettime(clock_id, &ts)
|
||||
current = ts.tv_sec + (ts.tv_nsec / 1000000000.)
|
||||
return current
|
||||
|
||||
def monotonic_time():
|
||||
return readclock(CLOCK_MONOTONIC_RAW)
|
||||
return readclock(CLOCK_MONOTONIC_RAW)
|
||||
|
||||
def sec_since_boot():
|
||||
return readclock(CLOCK_BOOTTIME)
|
||||
|
||||
return readclock(CLOCK_BOOTTIME)
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
from distutils.core import Extension, setup # pylint: disable=import-error,no-name-in-module
|
||||
from Cython.Build import cythonize
|
||||
|
||||
from common.cython_hacks import BuildExtWithoutPlatformSuffix
|
||||
|
||||
sourcefiles = ['clock.pyx']
|
||||
extra_compile_args = ["-std=c++11"]
|
||||
|
||||
setup(name='Common',
|
||||
cmdclass={'build_ext': BuildExtWithoutPlatformSuffix},
|
||||
ext_modules=cythonize(
|
||||
Extension(
|
||||
"common_pyx",
|
||||
language="c++",
|
||||
sources=sourcefiles,
|
||||
extra_compile_args=extra_compile_args,
|
||||
)
|
||||
),
|
||||
nthreads=4,
|
||||
)
|
||||
@@ -257,6 +257,7 @@ class dbc():
|
||||
|
||||
if __name__ == "__main__":
|
||||
from opendbc import DBC_PATH
|
||||
import numpy as np
|
||||
|
||||
dbc_test = dbc(os.path.join(DBC_PATH, 'toyota_prius_2017_pt_generated.dbc'))
|
||||
msg = ('STEER_ANGLE_SENSOR', {'STEER_ANGLE': -6.0, 'STEER_RATE': 4, 'STEER_FRACTION': -0.2})
|
||||
@@ -266,7 +267,7 @@ if __name__ == "__main__":
|
||||
|
||||
dbc_test = dbc(os.path.join(DBC_PATH, 'hyundai_santa_fe_2019_ccan.dbc'))
|
||||
decoded = dbc_test.decode((0x2b0, 0, "\xfa\xfe\x00\x07\x12"))
|
||||
assert abs(decoded[1]['SAS_Angle'] - (-26.2)) < 0.001
|
||||
assert np.isclose(decoded[1]['SAS_Angle'], -26.2)
|
||||
|
||||
msg = ('SAS11', {'SAS_Stat': 7.0, 'MsgCount': 0.0, 'SAS_Angle': -26.200000000000003, 'SAS_Speed': 0.0, 'CheckSum': 0.0})
|
||||
encoded = dbc_test.encode(*msg)
|
||||
@@ -2,14 +2,8 @@ import os
|
||||
import sys
|
||||
import fcntl
|
||||
import hashlib
|
||||
import platform
|
||||
from cffi import FFI
|
||||
|
||||
def suffix():
|
||||
if platform.system() == "Darwin":
|
||||
return ".dylib"
|
||||
else:
|
||||
return ".so"
|
||||
|
||||
def ffi_wrap(name, c_code, c_header, tmpdir="/tmp/ccache", cflags="", libraries=None):
|
||||
if libraries is None:
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
simple_kalman_impl.c
|
||||
@@ -0,0 +1,10 @@
|
||||
all: simple_kalman_impl.so
|
||||
|
||||
simple_kalman_impl.so: simple_kalman_impl.pyx simple_kalman_impl.pxd simple_kalman_setup.py
|
||||
python3 simple_kalman_setup.py build_ext --inplace
|
||||
rm -rf build
|
||||
rm simple_kalman_impl.c
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -f simple_kalman_impl.so
|
||||
@@ -1,6 +0,0 @@
|
||||
Import('env')
|
||||
|
||||
env.Command(['simple_kalman_impl.so'],
|
||||
['simple_kalman_impl.pyx', 'simple_kalman_impl.pxd', 'simple_kalman_setup.py'],
|
||||
"cd common/kalman && python3 simple_kalman_setup.py build_ext --inplace")
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
# pylint: skip-file
|
||||
from common.kalman.simple_kalman_impl import KF1D as KF1D
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
kalman_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
subprocess.check_call(["make", "simple_kalman_impl.so"], cwd=kalman_dir)
|
||||
|
||||
from .simple_kalman_impl import KF1D as KF1D
|
||||
# Silence pyflakes
|
||||
assert KF1D
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from distutils.core import Extension, setup
|
||||
from distutils.core import Extension, setup # pylint: disable=import-error,no-name-in-module
|
||||
|
||||
from Cython.Build import cythonize
|
||||
|
||||
|
||||
+22
-38
@@ -1,11 +1,9 @@
|
||||
import io
|
||||
import os
|
||||
import sys
|
||||
import copy
|
||||
import json
|
||||
import socket
|
||||
import logging
|
||||
import traceback
|
||||
from threading import local
|
||||
from collections import OrderedDict
|
||||
from contextlib import contextmanager
|
||||
@@ -80,6 +78,28 @@ class SwagLogger(logging.Logger):
|
||||
self.log_local = local()
|
||||
self.log_local.ctx = {}
|
||||
|
||||
def findCaller(self, stack_info=None):
|
||||
"""
|
||||
Find the stack frame of the caller so that we can note the source
|
||||
file name, line number and function name.
|
||||
"""
|
||||
# f = currentframe()
|
||||
f = sys._getframe(3)
|
||||
#On some versions of IronPython, currentframe() returns None if
|
||||
#IronPython isn't run with -X:Frames.
|
||||
if f is not None:
|
||||
f = f.f_back
|
||||
rv = "(unknown file)", 0, "(unknown function)"
|
||||
while hasattr(f, "f_code"):
|
||||
co = f.f_code
|
||||
filename = os.path.normcase(co.co_filename)
|
||||
if filename in (logging._srcfile, _srcfile):
|
||||
f = f.f_back
|
||||
continue
|
||||
rv = (co.co_filename, f.f_lineno, co.co_name)
|
||||
break
|
||||
return rv
|
||||
|
||||
def local_ctx(self):
|
||||
try:
|
||||
return self.log_local.ctx
|
||||
@@ -120,42 +140,6 @@ class SwagLogger(logging.Logger):
|
||||
else:
|
||||
self.info(evt)
|
||||
|
||||
def findCaller(self, stack_info=False, stacklevel=1):
|
||||
"""
|
||||
Find the stack frame of the caller so that we can note the source
|
||||
file name, line number and function name.
|
||||
"""
|
||||
f = sys._getframe(3)
|
||||
#On some versions of IronPython, currentframe() returns None if
|
||||
#IronPython isn't run with -X:Frames.
|
||||
if f is not None:
|
||||
f = f.f_back
|
||||
orig_f = f
|
||||
while f and stacklevel > 1:
|
||||
f = f.f_back
|
||||
stacklevel -= 1
|
||||
if not f:
|
||||
f = orig_f
|
||||
rv = "(unknown file)", 0, "(unknown function)", None
|
||||
while hasattr(f, "f_code"):
|
||||
co = f.f_code
|
||||
filename = os.path.normcase(co.co_filename)
|
||||
if filename == _srcfile:
|
||||
f = f.f_back
|
||||
continue
|
||||
sinfo = None
|
||||
if stack_info:
|
||||
sio = io.StringIO()
|
||||
sio.write('Stack (most recent call last):\n')
|
||||
traceback.print_stack(f, file=sio)
|
||||
sinfo = sio.getvalue()
|
||||
if sinfo[-1] == '\n':
|
||||
sinfo = sinfo[:-1]
|
||||
sio.close()
|
||||
rv = (co.co_filename, f.f_lineno, co.co_name, sinfo)
|
||||
break
|
||||
return rv
|
||||
|
||||
if __name__ == "__main__":
|
||||
log = SwagLogger()
|
||||
|
||||
|
||||
+8
-34
@@ -29,7 +29,7 @@ import fcntl
|
||||
import tempfile
|
||||
import threading
|
||||
from enum import Enum
|
||||
from common.basedir import PARAMS
|
||||
|
||||
|
||||
def mkdirs_exists_ok(path):
|
||||
try:
|
||||
@@ -54,9 +54,7 @@ keys = {
|
||||
"AthenadPid": [TxType.PERSISTENT],
|
||||
"CalibrationParams": [TxType.PERSISTENT],
|
||||
"CarParams": [TxType.CLEAR_ON_MANAGER_START, TxType.CLEAR_ON_PANDA_DISCONNECT],
|
||||
"CarParamsCache": [TxType.CLEAR_ON_MANAGER_START, TxType.CLEAR_ON_PANDA_DISCONNECT],
|
||||
"CarVin": [TxType.CLEAR_ON_MANAGER_START, TxType.CLEAR_ON_PANDA_DISCONNECT],
|
||||
"CommunityFeaturesToggle": [TxType.PERSISTENT],
|
||||
"CompletedTrainingVersion": [TxType.PERSISTENT],
|
||||
"ControlsParams": [TxType.PERSISTENT],
|
||||
"DoUninstall": [TxType.CLEAR_ON_MANAGER_START],
|
||||
@@ -67,26 +65,22 @@ keys = {
|
||||
"GithubSshKeys": [TxType.PERSISTENT],
|
||||
"HasAcceptedTerms": [TxType.PERSISTENT],
|
||||
"HasCompletedSetup": [TxType.PERSISTENT],
|
||||
"IsLdwEnabled": [TxType.PERSISTENT],
|
||||
"IsGeofenceEnabled": [TxType.PERSISTENT],
|
||||
"IsMetric": [TxType.PERSISTENT],
|
||||
"IsOffroad": [TxType.CLEAR_ON_MANAGER_START],
|
||||
"IsRHD": [TxType.PERSISTENT],
|
||||
"IsTakingSnapshot": [TxType.CLEAR_ON_MANAGER_START],
|
||||
"IsUpdateAvailable": [TxType.CLEAR_ON_MANAGER_START],
|
||||
"IsUpdateAvailable": [TxType.PERSISTENT],
|
||||
"IsUploadRawEnabled": [TxType.PERSISTENT],
|
||||
"IsUploadVideoOverCellularEnabled": [TxType.PERSISTENT],
|
||||
"LastUpdateTime": [TxType.PERSISTENT],
|
||||
"LimitSetSpeed": [TxType.PERSISTENT],
|
||||
"LimitSetSpeedNeural": [TxType.PERSISTENT],
|
||||
"LiveParameters": [TxType.PERSISTENT],
|
||||
"LongitudinalControl": [TxType.PERSISTENT],
|
||||
"OpenpilotEnabledToggle": [TxType.PERSISTENT],
|
||||
"PandaFirmware": [TxType.CLEAR_ON_MANAGER_START, TxType.CLEAR_ON_PANDA_DISCONNECT],
|
||||
"PandaFirmwareHex": [TxType.CLEAR_ON_MANAGER_START, TxType.CLEAR_ON_PANDA_DISCONNECT],
|
||||
"PandaDongleId": [TxType.CLEAR_ON_MANAGER_START, TxType.CLEAR_ON_PANDA_DISCONNECT],
|
||||
"Passive": [TxType.PERSISTENT],
|
||||
"RecordFront": [TxType.PERSISTENT],
|
||||
"ReleaseNotes": [TxType.PERSISTENT],
|
||||
"SafetyModelLock": [TxType.PERSISTENT],
|
||||
"ShouldDoUpdate": [TxType.CLEAR_ON_MANAGER_START],
|
||||
"SpeedLimitOffset": [TxType.PERSISTENT],
|
||||
"SubscriberInfo": [TxType.PERSISTENT],
|
||||
@@ -95,12 +89,9 @@ keys = {
|
||||
"UpdateAvailable": [TxType.CLEAR_ON_MANAGER_START],
|
||||
"Version": [TxType.PERSISTENT],
|
||||
"Offroad_ChargeDisabled": [TxType.CLEAR_ON_MANAGER_START, TxType.CLEAR_ON_PANDA_DISCONNECT],
|
||||
"Offroad_ConnectivityNeeded": [TxType.CLEAR_ON_MANAGER_START],
|
||||
"Offroad_ConnectivityNeededPrompt": [TxType.CLEAR_ON_MANAGER_START],
|
||||
"Offroad_TemperatureTooHigh": [TxType.CLEAR_ON_MANAGER_START],
|
||||
"Offroad_PandaFirmwareMismatch": [TxType.CLEAR_ON_MANAGER_START, TxType.CLEAR_ON_PANDA_DISCONNECT],
|
||||
"Offroad_InvalidTime": [TxType.CLEAR_ON_MANAGER_START],
|
||||
"Offroad_IsTakingSnapshot": [TxType.CLEAR_ON_MANAGER_START],
|
||||
"Offroad_ConnectivityNeededPrompt": [TxType.CLEAR_ON_MANAGER_START],
|
||||
"Offroad_ConnectivityNeeded": [TxType.CLEAR_ON_MANAGER_START],
|
||||
#dragonpilot config
|
||||
"DragonEnableDashcam": [TxType.PERSISTENT],
|
||||
"DragonEnableDriverSafetyCheck": [TxType.PERSISTENT],
|
||||
@@ -113,8 +104,6 @@ keys = {
|
||||
"DragonCachedModel": [TxType.PERSISTENT],
|
||||
"DragonCachedFP": [TxType.PERSISTENT],
|
||||
"DragonCachedVIN": [TxType.PERSISTENT],
|
||||
"DragonCachedCarFW": [TxType.PERSISTENT],
|
||||
"DragonCachedSource": [TxType.PERSISTENT],
|
||||
"DragonAllowGas": [TxType.PERSISTENT],
|
||||
"DragonToyotaStockDSU": [TxType.PERSISTENT],
|
||||
"DragonLatCtrl": [TxType.PERSISTENT],
|
||||
@@ -151,20 +140,10 @@ keys = {
|
||||
"DragonUIBlinker": [TxType.PERSISTENT],
|
||||
"DragonEnableDriverMonitoring": [TxType.PERSISTENT],
|
||||
"DragonCarModel": [TxType.PERSISTENT],
|
||||
"DragonCarVIN": [TxType.PERSISTENT], #deprecated
|
||||
"DragonCarVIN": [TxType.PERSISTENT],
|
||||
"DragonEnableSlowOnCurve": [TxType.PERSISTENT],
|
||||
"DragonEnableLeadCarMovingAlert": [TxType.PERSISTENT],
|
||||
"DragonToyotaSnGMod": [TxType.PERSISTENT],
|
||||
"DragonEnableSRLearner": [TxType.PERSISTENT],
|
||||
"DragonWazeMode": [TxType.PERSISTENT],
|
||||
"DragonRunWaze": [TxType.PERSISTENT],
|
||||
"DragonEnableAssistedLC": [TxType.PERSISTENT],
|
||||
"DragonEnableAutoLC": [TxType.PERSISTENT],
|
||||
"DragonAssistedLCMinMPH": [TxType.PERSISTENT],
|
||||
"DragonAutoLCMinMPH": [TxType.PERSISTENT],
|
||||
"DragonAutoLCDelay": [TxType.PERSISTENT],
|
||||
"DragonBTG": [TxType.PERSISTENT],
|
||||
"DragonBootHotspot": [TxType.PERSISTENT],
|
||||
}
|
||||
|
||||
|
||||
@@ -384,7 +363,7 @@ def write_db(params_path, key, value):
|
||||
lock.release()
|
||||
|
||||
class Params():
|
||||
def __init__(self, db=PARAMS):
|
||||
def __init__(self, db='/data/params'):
|
||||
self.db = db
|
||||
|
||||
# create the database if it doesn't exist...
|
||||
@@ -392,11 +371,6 @@ class Params():
|
||||
with self.transaction(write=True):
|
||||
pass
|
||||
|
||||
def clear_all(self):
|
||||
shutil.rmtree(self.db, ignore_errors=True)
|
||||
with self.transaction(write=True):
|
||||
pass
|
||||
|
||||
def transaction(self, write=False):
|
||||
if write:
|
||||
return DBWriter(self.db)
|
||||
|
||||
+9
-1
@@ -6,12 +6,20 @@ import subprocess
|
||||
import multiprocessing
|
||||
from cffi import FFI
|
||||
|
||||
from common.common_pyx import sec_since_boot # pylint: disable=no-name-in-module, import-error
|
||||
# Build and load cython module
|
||||
import pyximport
|
||||
installer = pyximport.install(inplace=True, build_dir='/tmp')
|
||||
from common.clock import monotonic_time, sec_since_boot # pylint: disable=no-name-in-module, import-error
|
||||
pyximport.uninstall(*installer)
|
||||
assert monotonic_time
|
||||
assert sec_since_boot
|
||||
|
||||
|
||||
# time step for each process
|
||||
DT_CTRL = 0.01 # controlsd
|
||||
DT_PLAN = 0.05 # mpc
|
||||
DT_MDL = 0.05 # model
|
||||
DT_RDR = 0.05 # radar
|
||||
DT_DMON = 0.1 # driver monitoring
|
||||
DT_TRML = 0.5 # thermald and manager
|
||||
|
||||
|
||||
+9
-44
@@ -2,62 +2,27 @@ import os
|
||||
import subprocess
|
||||
from common.basedir import BASEDIR
|
||||
|
||||
|
||||
class Spinner():
|
||||
def __init__(self):
|
||||
try:
|
||||
self.spinner_proc = subprocess.Popen(["./spinner"],
|
||||
stdin=subprocess.PIPE,
|
||||
cwd=os.path.join(BASEDIR, "selfdrive", "ui", "spinner"),
|
||||
close_fds=True)
|
||||
except OSError:
|
||||
self.spinner_proc = None
|
||||
|
||||
def __enter__(self):
|
||||
self.spinner_proc = subprocess.Popen(["./spinner"],
|
||||
stdin=subprocess.PIPE,
|
||||
cwd=os.path.join(BASEDIR, "selfdrive", "ui", "spinner"),
|
||||
close_fds=True)
|
||||
return self
|
||||
|
||||
def update(self, spinner_text):
|
||||
if self.spinner_proc is not None:
|
||||
self.spinner_proc.stdin.write(spinner_text.encode('utf8') + b"\n")
|
||||
try:
|
||||
self.spinner_proc.stdin.flush()
|
||||
except BrokenPipeError:
|
||||
pass
|
||||
|
||||
def close(self):
|
||||
if self.spinner_proc is not None:
|
||||
try:
|
||||
self.spinner_proc.stdin.close()
|
||||
except BrokenPipeError:
|
||||
pass
|
||||
self.spinner_proc.terminate()
|
||||
self.spinner_proc = None
|
||||
|
||||
def __del__(self):
|
||||
self.close()
|
||||
self.spinner_proc.stdin.write(spinner_text.encode('utf8') + b"\n")
|
||||
self.spinner_proc.stdin.flush()
|
||||
|
||||
def __exit__(self, type, value, traceback):
|
||||
self.close()
|
||||
self.spinner_proc.stdin.close()
|
||||
self.spinner_proc.terminate()
|
||||
|
||||
|
||||
class FakeSpinner():
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def update(self, _):
|
||||
pass
|
||||
|
||||
def __exit__(self, type, value, traceback):
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import time
|
||||
with Spinner() as s:
|
||||
s.update("Spinner text")
|
||||
time.sleep(5.0)
|
||||
print("gone")
|
||||
time.sleep(5.0)
|
||||
|
||||
|
||||
@@ -44,7 +44,6 @@ def get_calib_from_vp(vp):
|
||||
roll_calib = 0
|
||||
return roll_calib, pitch_calib, yaw_calib
|
||||
|
||||
|
||||
# aka 'extrinsic_matrix'
|
||||
# road : x->forward, y -> left, z->up
|
||||
def get_view_frame_from_road_frame(roll, pitch, yaw, height):
|
||||
@@ -62,13 +61,6 @@ def vp_from_ke(m):
|
||||
"""
|
||||
return (m[0, 0]/m[2,0], m[1,0]/m[2,0])
|
||||
|
||||
|
||||
def vp_from_rpy(rpy):
|
||||
e = get_view_frame_from_road_frame(rpy[0], rpy[1], rpy[2], 1.22)
|
||||
ke = np.dot(eon_intrinsics, e)
|
||||
return vp_from_ke(ke)
|
||||
|
||||
|
||||
def roll_from_ke(m):
|
||||
# note: different from calibration.h/RollAnglefromKE: i think that one's just wrong
|
||||
return np.arctan2(-(m[1, 0] - m[1, 1] * m[2, 0] / m[2, 1]),
|
||||
@@ -131,6 +123,37 @@ def img_from_device(pt_device):
|
||||
return pt_img.reshape(input_shape)[:,:2]
|
||||
|
||||
|
||||
#TODO please use generic img transform below
|
||||
def rotate_img(img, eulers, crop=None, intrinsics=eon_intrinsics):
|
||||
import cv2 # pylint: disable=no-name-in-module, import-error
|
||||
|
||||
size = img.shape[:2]
|
||||
rot = orient.rot_from_euler(eulers)
|
||||
quadrangle = np.array([[0, 0],
|
||||
[size[1]-1, 0],
|
||||
[0, size[0]-1],
|
||||
[size[1]-1, size[0]-1]], dtype=np.float32)
|
||||
quadrangle_norm = np.hstack((normalize(quadrangle, intrinsics=intrinsics), np.ones((4,1))))
|
||||
warped_quadrangle_full = np.einsum('ij, kj->ki', intrinsics.dot(rot), quadrangle_norm)
|
||||
warped_quadrangle = np.column_stack((warped_quadrangle_full[:,0]/warped_quadrangle_full[:,2],
|
||||
warped_quadrangle_full[:,1]/warped_quadrangle_full[:,2])).astype(np.float32)
|
||||
if crop:
|
||||
W_border = (size[1] - crop[0])//2
|
||||
H_border = (size[0] - crop[1])//2
|
||||
outside_crop = (((warped_quadrangle[:,0] < W_border) |
|
||||
(warped_quadrangle[:,0] >= size[1] - W_border)) &
|
||||
((warped_quadrangle[:,1] < H_border) |
|
||||
(warped_quadrangle[:,1] >= size[0] - H_border)))
|
||||
if not outside_crop.all():
|
||||
raise ValueError("warped image not contained inside crop")
|
||||
else:
|
||||
H_border, W_border = 0, 0
|
||||
M = cv2.getPerspectiveTransform(quadrangle, warped_quadrangle)
|
||||
img_warped = cv2.warpPerspective(img, M, size[::-1])
|
||||
return img_warped[H_border: size[0] - H_border,
|
||||
W_border: size[1] - W_border]
|
||||
|
||||
|
||||
def get_camera_frame_from_calib_frame(camera_frame_from_road_frame):
|
||||
camera_frame_from_ground = camera_frame_from_road_frame[:, (0, 1, 3)]
|
||||
calib_frame_from_ground = np.dot(eon_intrinsics,
|
||||
@@ -160,7 +183,7 @@ def transform_img(base_img,
|
||||
alpha=1.0,
|
||||
beta=0,
|
||||
blur=0):
|
||||
import cv2 # pylint: disable=import-error
|
||||
import cv2 # pylint: disable=no-name-in-module, import-error
|
||||
cv2.setNumThreads(1)
|
||||
|
||||
if yuv:
|
||||
@@ -218,7 +241,7 @@ def transform_img(base_img,
|
||||
def yuv_crop(frame, output_size, center=None):
|
||||
# output_size in camera coordinates so u,v
|
||||
# center in array coordinates so row, column
|
||||
import cv2 # pylint: disable=import-error
|
||||
import cv2 # pylint: disable=no-name-in-module, import-error
|
||||
rgb = cv2.cvtColor(frame, cv2.COLOR_YUV2RGB_I420)
|
||||
if not center:
|
||||
center = (rgb.shape[0]/2, rgb.shape[1]/2)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"ota_url": "http://dpp.cool/neosupdate/ota-signed-efdf7de63b1aef63d68301e6175930991bf9a5927d16ec6fcc69287e2ee7ca4a.zip",
|
||||
"ota_hash": "efdf7de63b1aef63d68301e6175930991bf9a5927d16ec6fcc69287e2ee7ca4a",
|
||||
"recovery_url": "http://dpp.cool/neosupdate/recovery-97c27e6ed04ed6bb0608b845a2d4100912093f9380c3f2ba6b56bccd608e5f6e.img",
|
||||
"recovery_len": 15861036,
|
||||
"recovery_hash": "97c27e6ed04ed6bb0608b845a2d4100912093f9380c3f2ba6b56bccd608e5f6e"
|
||||
"ota_url": "https://commadist.azureedge.net/neosupdate/ota-signed-7a0117425bc4a6673958d265312994e124654a566228f3cec2f0f9bc8120a9ab.zip",
|
||||
"ota_hash": "7a0117425bc4a6673958d265312994e124654a566228f3cec2f0f9bc8120a9ab",
|
||||
"recovery_url": "https://commadist.azureedge.net/neosupdate/recovery-3dc234d868c29a3739f6ca3bd47b1c2d3c570d9f478b6849a4fada129ee4af76.img",
|
||||
"recovery_len": 15848748,
|
||||
"recovery_hash": "3dc234d868c29a3739f6ca3bd47b1c2d3c570d9f478b6849a4fada129ee4af76"
|
||||
}
|
||||
|
||||
@@ -155,6 +155,8 @@ struct Updater {
|
||||
TouchState touch;
|
||||
|
||||
int fb_w, fb_h;
|
||||
EGLDisplay display;
|
||||
EGLSurface surface;
|
||||
|
||||
FramebufferState *fb = NULL;
|
||||
NVGcontext *vg = NULL;
|
||||
@@ -196,7 +198,7 @@ struct Updater {
|
||||
touch_init(&touch);
|
||||
|
||||
fb = framebuffer_init("updater", 0x00001000, false,
|
||||
&fb_w, &fb_h);
|
||||
&display, &surface, &fb_w, &fb_h);
|
||||
assert(fb);
|
||||
|
||||
vg = nvgCreateGLES3(NVG_ANTIALIAS | NVG_STENCIL_STROKES | NVG_DEBUG);
|
||||
@@ -706,7 +708,7 @@ struct Updater {
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
framebuffer_swap(fb);
|
||||
eglSwapBuffers(display, surface);
|
||||
|
||||
assert(glGetError() == GL_NO_ERROR);
|
||||
|
||||
|
||||
+18
-46
@@ -6,54 +6,26 @@ export NUMEXPR_NUM_THREADS=1
|
||||
export OPENBLAS_NUM_THREADS=1
|
||||
export VECLIB_MAXIMUM_THREADS=1
|
||||
|
||||
if [ -z "$BASEDIR" ]; then
|
||||
BASEDIR="/data/openpilot"
|
||||
fi
|
||||
|
||||
if [ -z "$PASSIVE" ]; then
|
||||
export PASSIVE="1"
|
||||
fi
|
||||
|
||||
STAGING_ROOT="/data/safe_staging"
|
||||
|
||||
function launch {
|
||||
# Wifi scan
|
||||
wpa_cli IFNAME=wlan0 SCAN
|
||||
|
||||
# Check to see if there's a valid overlay-based update available. Conditions
|
||||
# are as follows:
|
||||
#
|
||||
# 1. The BASEDIR init file has to exist, with a newer modtime than anything in
|
||||
# the BASEDIR Git repo. This checks for local development work or the user
|
||||
# switching branches/forks, which should not be overwritten.
|
||||
# 2. The FINALIZED consistent file has to exist, indicating there's an update
|
||||
# that completed successfully and synced to disk.
|
||||
|
||||
if [ -f "${BASEDIR}/.overlay_init" ]; then
|
||||
find ${BASEDIR}/.git -newer ${BASEDIR}/.overlay_init | grep -q '.' 2> /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "${BASEDIR} has been modified, skipping overlay update installation"
|
||||
else
|
||||
if [ -f "${STAGING_ROOT}/finalized/.overlay_consistent" ]; then
|
||||
if [ ! -d /data/safe_staging/old_openpilot ]; then
|
||||
echo "Valid overlay update found, installing"
|
||||
LAUNCHER_LOCATION="${BASH_SOURCE[0]}"
|
||||
|
||||
mv $BASEDIR /data/safe_staging/old_openpilot
|
||||
mv "${STAGING_ROOT}/finalized" $BASEDIR
|
||||
|
||||
# The mv changed our working directory to /data/safe_staging/old_openpilot
|
||||
cd "${BASEDIR}"
|
||||
|
||||
echo "Restarting launch script ${LAUNCHER_LOCATION}"
|
||||
exec "${LAUNCHER_LOCATION}"
|
||||
else
|
||||
echo "openpilot backup found, not updating"
|
||||
# TODO: restore backup? This means the updater didn't start after swapping
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
# apply update
|
||||
# if [ "$(git rev-parse HEAD)" != "$(git rev-parse @{u})" ]; then
|
||||
# git reset --hard @{u} &&
|
||||
# git clean -xdf &&
|
||||
#
|
||||
# # Touch all files on release2 after checkout to prevent rebuild
|
||||
# BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
||||
# if [[ "$BRANCH" == "release2" ]]; then
|
||||
# touch **
|
||||
# fi
|
||||
#
|
||||
# exec "${BASH_SOURCE[0]}"
|
||||
# fi
|
||||
chmod 700 reset_update.sh
|
||||
chmod 700 update_panda_firmware.sh
|
||||
|
||||
# no cpu rationing for now
|
||||
echo 0-3 > /dev/cpuset/background/cpus
|
||||
@@ -65,23 +37,23 @@ function launch {
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
|
||||
|
||||
# Remove old NEOS update file
|
||||
# TODO: move this code to the updater
|
||||
if [ -d /data/neoupdate ]; then
|
||||
rm -rf /data/neoupdate
|
||||
fi
|
||||
|
||||
# Check for NEOS update
|
||||
if [ $(< /VERSION) != "14" ]; then
|
||||
if [ $(< /VERSION) != "12" ]; then
|
||||
if [ -f "$DIR/scripts/continue.sh" ]; then
|
||||
cp "$DIR/scripts/continue.sh" "/data/data/com.termux/files/continue.sh"
|
||||
fi
|
||||
|
||||
git clean -xdf
|
||||
"$DIR/installer/updater/updater" "file://$DIR/installer/updater/update.json"
|
||||
fi
|
||||
|
||||
|
||||
# handle pythonpath
|
||||
ln -sfn $(pwd) /data/pythonpath
|
||||
ln -s /data/openpilot /data/pythonpath
|
||||
export PYTHONPATH="$PWD"
|
||||
|
||||
# start manager
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,13 +1,2 @@
|
||||
*.pyc
|
||||
*.os
|
||||
*.tmp
|
||||
*.dylib
|
||||
.*.swp
|
||||
.DS_Store
|
||||
|
||||
can/*.so
|
||||
can/build/
|
||||
can/obj/
|
||||
can/packer_pyx.cpp
|
||||
can/parser_pyx.cpp
|
||||
can/packer_impl.cpp
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
from ubuntu:16.04
|
||||
|
||||
RUN apt-get update && apt-get install -y libzmq3-dev clang wget git autoconf libtool curl make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl
|
||||
|
||||
RUN curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
|
||||
ENV PATH="/root/.pyenv/bin:/root/.pyenv/shims:${PATH}"
|
||||
RUN pyenv install 3.7.3
|
||||
RUN pyenv global 3.7.3
|
||||
RUN pyenv rehash
|
||||
|
||||
COPY requirements.txt /tmp/
|
||||
RUN pip install -r /tmp/requirements.txt
|
||||
|
||||
ENV PYTHONPATH=/project
|
||||
|
||||
# TODO: Add tag to cereal
|
||||
RUN git clone https://github.com/commaai/cereal.git /project/cereal
|
||||
RUN /project/cereal/install_capnp.sh
|
||||
|
||||
WORKDIR /project
|
||||
|
||||
COPY SConstruct .
|
||||
COPY . /project/opendbc
|
||||
|
||||
RUN scons -c && scons -j$(nproc)
|
||||
+1
-4
@@ -16,9 +16,6 @@ Wondering what's the DBC file format? [Here](http://www.socialledge.com/sjsu/ind
|
||||
|
||||
Use [panda](https://github.com/commaai/panda) to connect your car to a computer.
|
||||
|
||||
### How to use reverse engineered DBC
|
||||
To create custom CAN simulations or send reverse engineered signals back to the car you can use [CANdevStudio](https://github.com/GENIVI/CANdevStudio) project.
|
||||
|
||||
### DBC file preprocessor
|
||||
|
||||
DBC files for different models of the same brand have a lot of overlap. Therefore, we wrote a preprocessor to create DBC files from a brand DBC file and a model specific DBC file. The source DBC files can be found in the generator folder. After changing one of the files run the generator.py script to regenerate the output files. These output files will be placed in the root of the opendbc repository and are suffixed by _generated.
|
||||
@@ -45,7 +42,7 @@ For example:
|
||||
SG_ VEHICLE_SPEED : 7|15@0+ (0.01,0) [0|250] "kph" PCM
|
||||
```
|
||||
|
||||
- Signal size: always use the smallest amount of bits possible. For example, let's say I'm reverse engineering the gas pedal position and I've determined that it's in a 3 bytes message. For 0% pedal position I read a message value of `0x00 0x00 0x00`, while for 100% of pedal position I read `0x64 0x00 0x00`: clearly, the gas pedal position is within the first byte of the message and I might be tempted to define the signal `GAS_POS` as:
|
||||
- Signal's size: always use the smallest amount of bits possible. For example, let's say I'm reverse engineering the gas pedal position and I've determined that it's in a 3 bytes message. For 0% pedal position I read a message value of `0x00 0x00 0x00`, while for 100% of pedal position I read `0x64 0x00 0x00`: clearly, the gas pedal position is within the first byte of the message and I might be tempted to define the signal `GAS_POS` as:
|
||||
```
|
||||
SG_ GAS_POS : 7|8@0+ (1,0) [0|100] "%" PCM
|
||||
```
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
zmq = 'zmq'
|
||||
arch = subprocess.check_output(["uname", "-m"], encoding='utf8').rstrip()
|
||||
|
||||
cereal_dir = Dir('.')
|
||||
|
||||
cpppath = [
|
||||
'#',
|
||||
'#cereal',
|
||||
"#cereal/messaging",
|
||||
"#opendbc/can",
|
||||
'/usr/lib/include',
|
||||
]
|
||||
|
||||
AddOption('--test',
|
||||
action='store_true',
|
||||
help='build test files')
|
||||
|
||||
AddOption('--asan',
|
||||
action='store_true',
|
||||
help='turn on ASAN')
|
||||
|
||||
ccflags_asan = ["-fsanitize=address", "-fno-omit-frame-pointer"] if GetOption('asan') else []
|
||||
ldflags_asan = ["-fsanitize=address"] if GetOption('asan') else []
|
||||
|
||||
env = Environment(
|
||||
ENV=os.environ,
|
||||
CC='clang',
|
||||
CXX='clang++',
|
||||
CCFLAGS=[
|
||||
"-g",
|
||||
"-fPIC",
|
||||
"-O2",
|
||||
"-Werror=implicit-function-declaration",
|
||||
"-Werror=incompatible-pointer-types",
|
||||
"-Werror=int-conversion",
|
||||
"-Werror=return-type",
|
||||
"-Werror=format-extra-args",
|
||||
] + ccflags_asan,
|
||||
LDFLAGS=ldflags_asan,
|
||||
LINKFLAGS=ldflags_asan,
|
||||
|
||||
CFLAGS="-std=gnu11",
|
||||
CXXFLAGS="-std=c++14",
|
||||
CPPPATH=cpppath,
|
||||
)
|
||||
|
||||
Export('env', 'zmq', 'arch')
|
||||
|
||||
cereal = [File('#cereal/libcereal.a')]
|
||||
messaging = [File('#cereal/libmessaging.a')]
|
||||
Export('cereal', 'messaging')
|
||||
|
||||
SConscript(['cereal/SConscript'])
|
||||
SConscript(['opendbc/can/SConscript'])
|
||||
@@ -86,13 +86,6 @@ BO_ 420 VSA_STATUS: 8 VSA
|
||||
SG_ COUNTER : 61|2@0+ (1,0) [0|3] "" EON
|
||||
SG_ CHECKSUM : 59|4@0+ (1,0) [0|15] "" EON
|
||||
|
||||
BO_ 427 STEER_MOTOR_TORQUE: 3 EPS
|
||||
SG_ CONFIG_VALID : 7|1@0+ (1,0) [0|1] "" EON
|
||||
SG_ MOTOR_TORQUE : 1|10@0+ (1,0) [0|256] "" EON
|
||||
SG_ OUTPUT_DISABLED : 22|1@0+ (1,0) [0|1] "" EON
|
||||
SG_ COUNTER : 21|2@0+ (1,0) [0|3] "" EON
|
||||
SG_ CHECKSUM : 19|4@0+ (1,0) [0|15] "" EON
|
||||
|
||||
BO_ 432 STANDSTILL: 7 VSA
|
||||
SG_ CONTROLLED_STANDSTILL : 0|1@0+ (1,0) [0|1] "" EON
|
||||
SG_ WHEELS_MOVING : 12|1@0+ (1,0) [0|1] "" EON
|
||||
@@ -171,7 +164,7 @@ BO_ 780 ACC_HUD: 8 ADAS
|
||||
SG_ BOH : 38|1@0+ (1,0) [0|1] "" BDY
|
||||
SG_ ACC_PROBLEM : 37|1@0+ (1,0) [0|1] "" BDY
|
||||
SG_ FCM_OFF : 36|1@0+ (1,0) [0|1] "" BDY
|
||||
SG_ FCM_OFF_2 : 35|1@0+ (1,0) [0|1] "" BDY
|
||||
SG_ BOH_2 : 35|1@0+ (1,0) [0|1] "" BDY
|
||||
SG_ FCM_PROBLEM : 34|1@0+ (1,0) [0|1] "" BDY
|
||||
SG_ RADAR_OBSTRUCTED : 33|1@0+ (1,0) [0|1] "" BDY
|
||||
SG_ ENABLE_MINI_CAR : 32|1@0+ (1,0) [0|1] "" BDY
|
||||
@@ -181,12 +174,10 @@ BO_ 780 ACC_HUD: 8 ADAS
|
||||
SG_ BOH_4 : 42|1@0+ (1,0) [0|3] "" BDY
|
||||
SG_ BOH_5 : 41|1@0+ (1,0) [0|3] "" BDY
|
||||
SG_ CRUISE_CONTROL_LABEL : 40|1@0+ (1,0) [0|3] "" BDY
|
||||
SG_ SET_ME_X01_2 : 55|1@0+ (1,0) [0|1] "" BDY
|
||||
SG_ IMPERIAL_UNIT : 54|1@0+ (1,0) [0|1] "" BDY
|
||||
SG_ HUD_DISTANCE_3 : 52|1@0+ (1,0) [0|1] "" BDY
|
||||
SG_ CHIME : 51|3@0+ (1,0) [0|1] "" BDY
|
||||
SG_ IMPERIAL_UNIT : 54|1@0+ (1,0) [0|1] "" BDY
|
||||
SG_ SET_ME_X01_2 : 55|1@0+ (1,0) [0|1] "" BDY
|
||||
SG_ SET_ME_X01 : 48|1@0+ (1,0) [0|1] "" BDY
|
||||
SG_ ICONS : 63|2@0+ (1,0) [0|1] "" BDY
|
||||
SG_ COUNTER : 61|2@0+ (1,0) [0|3] "" BDY
|
||||
SG_ CHECKSUM : 59|4@0+ (1,0) [0|3] "" BDY
|
||||
|
||||
@@ -280,11 +271,10 @@ BO_ 342 STEERING_SENSORS: 6 EPS
|
||||
SG_ CHECKSUM : 43|4@0+ (1,0) [0|3] "" EON
|
||||
|
||||
BO_ 399 STEER_STATUS: 7 EPS
|
||||
SG_ STEER_TORQUE_SENSOR : 7|16@0- (-1,0) [-31000|31000] "tbd" EON
|
||||
SG_ STEER_ANGLE_RATE : 23|16@0- (-0.1,0) [-31000|31000] "deg/s" EON
|
||||
SG_ STEER_TORQUE_SENSOR : 7|16@0- (1,0) [-31000|31000] "tbd" EON
|
||||
SG_ STEER_TORQUE_MOTOR : 23|16@0- (1,0) [-31000|31000] "tbd" EON
|
||||
SG_ STEER_STATUS : 39|4@0+ (1,0) [0|15] "" EON
|
||||
SG_ STEER_CONTROL_ACTIVE : 35|1@0+ (1,0) [0|1] "" EON
|
||||
SG_ STEER_CONFIG_INDEX : 43|4@0+ (1,0) [0|15] "" EON
|
||||
SG_ COUNTER : 53|2@0+ (1,0) [0|3] "" EON
|
||||
SG_ CHECKSUM : 51|4@0+ (1,0) [0|3] "" EON
|
||||
|
||||
|
||||
@@ -86,13 +86,6 @@ BO_ 420 VSA_STATUS: 8 VSA
|
||||
SG_ COUNTER : 61|2@0+ (1,0) [0|3] "" EON
|
||||
SG_ CHECKSUM : 59|4@0+ (1,0) [0|15] "" EON
|
||||
|
||||
BO_ 427 STEER_MOTOR_TORQUE: 3 EPS
|
||||
SG_ CONFIG_VALID : 7|1@0+ (1,0) [0|1] "" EON
|
||||
SG_ MOTOR_TORQUE : 1|10@0+ (1,0) [0|256] "" EON
|
||||
SG_ OUTPUT_DISABLED : 22|1@0+ (1,0) [0|1] "" EON
|
||||
SG_ COUNTER : 21|2@0+ (1,0) [0|3] "" EON
|
||||
SG_ CHECKSUM : 19|4@0+ (1,0) [0|15] "" EON
|
||||
|
||||
BO_ 432 STANDSTILL: 7 VSA
|
||||
SG_ CONTROLLED_STANDSTILL : 0|1@0+ (1,0) [0|1] "" EON
|
||||
SG_ WHEELS_MOVING : 12|1@0+ (1,0) [0|1] "" EON
|
||||
@@ -171,7 +164,7 @@ BO_ 780 ACC_HUD: 8 ADAS
|
||||
SG_ BOH : 38|1@0+ (1,0) [0|1] "" BDY
|
||||
SG_ ACC_PROBLEM : 37|1@0+ (1,0) [0|1] "" BDY
|
||||
SG_ FCM_OFF : 36|1@0+ (1,0) [0|1] "" BDY
|
||||
SG_ FCM_OFF_2 : 35|1@0+ (1,0) [0|1] "" BDY
|
||||
SG_ BOH_2 : 35|1@0+ (1,0) [0|1] "" BDY
|
||||
SG_ FCM_PROBLEM : 34|1@0+ (1,0) [0|1] "" BDY
|
||||
SG_ RADAR_OBSTRUCTED : 33|1@0+ (1,0) [0|1] "" BDY
|
||||
SG_ ENABLE_MINI_CAR : 32|1@0+ (1,0) [0|1] "" BDY
|
||||
@@ -181,12 +174,10 @@ BO_ 780 ACC_HUD: 8 ADAS
|
||||
SG_ BOH_4 : 42|1@0+ (1,0) [0|3] "" BDY
|
||||
SG_ BOH_5 : 41|1@0+ (1,0) [0|3] "" BDY
|
||||
SG_ CRUISE_CONTROL_LABEL : 40|1@0+ (1,0) [0|3] "" BDY
|
||||
SG_ SET_ME_X01_2 : 55|1@0+ (1,0) [0|1] "" BDY
|
||||
SG_ IMPERIAL_UNIT : 54|1@0+ (1,0) [0|1] "" BDY
|
||||
SG_ HUD_DISTANCE_3 : 52|1@0+ (1,0) [0|1] "" BDY
|
||||
SG_ CHIME : 51|3@0+ (1,0) [0|1] "" BDY
|
||||
SG_ IMPERIAL_UNIT : 54|1@0+ (1,0) [0|1] "" BDY
|
||||
SG_ SET_ME_X01_2 : 55|1@0+ (1,0) [0|1] "" BDY
|
||||
SG_ SET_ME_X01 : 48|1@0+ (1,0) [0|1] "" BDY
|
||||
SG_ ICONS : 63|2@0+ (1,0) [0|1] "" BDY
|
||||
SG_ COUNTER : 61|2@0+ (1,0) [0|3] "" BDY
|
||||
SG_ CHECKSUM : 59|4@0+ (1,0) [0|3] "" BDY
|
||||
|
||||
@@ -268,8 +259,8 @@ BO_ 392 GEARBOX: 6 XXX
|
||||
SG_ GEAR : 36|5@0+ (1,0) [0|31] "" EON
|
||||
|
||||
BO_ 399 STEER_STATUS: 6 EPS
|
||||
SG_ STEER_TORQUE_SENSOR : 7|12@0- (-1,0) [-2047.5|2047.5] "tbd" EON
|
||||
SG_ STEER_ANGLE_RATE : 23|16@0- (-0.1,0) [-31000|31000] "deg/s" EON
|
||||
SG_ STEER_TORQUE_SENSOR : 7|12@0- (1,0) [-2047.5|2047.5] "tbd" EON
|
||||
SG_ STEER_TORQUE_MOTOR : 23|16@0- (1,0) [-31000|31000] "tbd" EON
|
||||
SG_ STEER_STATUS : 35|4@0+ (1,0) [0|15] "" EON
|
||||
SG_ STEER_CONTROL_ACTIVE : 36|1@0+ (1,0) [0|1] "" EON
|
||||
SG_ COUNTER : 45|2@0+ (1,0) [0|3] "" EON
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
pr: none
|
||||
|
||||
pool:
|
||||
vmImage: 'ubuntu-16.04'
|
||||
steps:
|
||||
- script: |
|
||||
set -e
|
||||
docker build -t opendbc .
|
||||
displayName: 'Build'
|
||||
- script: |
|
||||
docker run opendbc bash -c "python -m unittest discover opendbc"
|
||||
displayName: 'Unit tests'
|
||||
- script: |
|
||||
docker run opendbc bash -c "cd opendbc/can/tests/linter_python; PYTHONPATH=/ ./flake8_opendbc.sh"
|
||||
docker run opendbc bash -c "cd opendbc/can/tests/linter_python; PYTHONPATH=/ ./pylint_opendbc.sh"
|
||||
displayName: 'Python linter'
|
||||
- script: |
|
||||
docker run opendbc bash -c "cd opendbc/can/tests/; PYTHONPATH=/ ./test_generator.sh"
|
||||
displayName: 'Generator test'
|
||||
@@ -1,27 +0,0 @@
|
||||
Import('env', 'cereal')
|
||||
|
||||
import os
|
||||
from opendbc.can.process_dbc import process
|
||||
|
||||
dbcs = []
|
||||
for x in sorted(os.listdir('../')):
|
||||
if x.endswith(".dbc"):
|
||||
def compile_dbc(target, source, env):
|
||||
process(source[0].path, target[0].path)
|
||||
in_fn = [os.path.join('../', x), 'dbc_template.cc']
|
||||
out_fn = os.path.join('dbc_out', x.replace(".dbc", ".cc"))
|
||||
dbc = env.Command(out_fn, in_fn, compile_dbc)
|
||||
dbcs.append(dbc)
|
||||
|
||||
|
||||
libdbc = env.SharedLibrary('libdbc', ["dbc.cc", "parser.cc", "packer.cc", "common.cc"]+dbcs, LIBS=["capnp", "kj"])
|
||||
|
||||
# packer
|
||||
env.Command(['packer_pyx.so'],
|
||||
[libdbc, 'packer_pyx.pyx', 'packer_pyx_setup.py'],
|
||||
"cd opendbc/can && python3 packer_pyx_setup.py build_ext --inplace")
|
||||
|
||||
# parser
|
||||
env.Command(['parser_pyx.so'],
|
||||
[libdbc, cereal, 'parser_pyx_setup.py', 'parser_pyx.pyx', 'common.pxd'],
|
||||
"cd opendbc/can && python3 parser_pyx_setup.py build_ext --inplace")
|
||||
@@ -1,2 +0,0 @@
|
||||
from opendbc.can.parser_pyx import CANDefine # pylint: disable=no-name-in-module, import-error
|
||||
assert CANDefine
|
||||
@@ -1,165 +0,0 @@
|
||||
#include "common.h"
|
||||
|
||||
unsigned int honda_checksum(unsigned int address, uint64_t d, int l) {
|
||||
d >>= ((8-l)*8); // remove padding
|
||||
d >>= 4; // remove checksum
|
||||
|
||||
int s = 0;
|
||||
while (address) { s += (address & 0xF); address >>= 4; }
|
||||
while (d) { s += (d & 0xF); d >>= 4; }
|
||||
s = 8-s;
|
||||
s &= 0xF;
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
unsigned int toyota_checksum(unsigned int address, uint64_t d, int l) {
|
||||
d >>= ((8-l)*8); // remove padding
|
||||
d >>= 8; // remove checksum
|
||||
|
||||
unsigned int s = l;
|
||||
while (address) { s += address & 0xff; address >>= 8; }
|
||||
while (d) { s += d & 0xff; d >>= 8; }
|
||||
|
||||
return s & 0xFF;
|
||||
}
|
||||
|
||||
// Static lookup table for fast computation of CRC8 poly 0x2F, aka 8H2F/AUTOSAR
|
||||
uint8_t crc8_lut_8h2f[256];
|
||||
|
||||
void gen_crc_lookup_table(uint8_t poly, uint8_t crc_lut[]) {
|
||||
uint8_t crc;
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < 256; i++) {
|
||||
crc = i;
|
||||
for (j = 0; j < 8; j++) {
|
||||
if ((crc & 0x80) != 0)
|
||||
crc = (uint8_t)((crc << 1) ^ poly);
|
||||
else
|
||||
crc <<= 1;
|
||||
}
|
||||
crc_lut[i] = crc;
|
||||
}
|
||||
}
|
||||
|
||||
void init_crc_lookup_tables() {
|
||||
// At init time, set up static lookup tables for fast CRC computation.
|
||||
|
||||
gen_crc_lookup_table(0x2F, crc8_lut_8h2f); // CRC-8 8H2F/AUTOSAR for Volkswagen
|
||||
}
|
||||
|
||||
unsigned int volkswagen_crc(unsigned int address, uint64_t d, int l) {
|
||||
// Volkswagen uses standard CRC8 8H2F/AUTOSAR, but they compute it with
|
||||
// a magic variable padding byte tacked onto the end of the payload.
|
||||
// https://www.autosar.org/fileadmin/user_upload/standards/classic/4-3/AUTOSAR_SWS_CRCLibrary.pdf
|
||||
|
||||
uint8_t *dat = (uint8_t *)&d;
|
||||
uint8_t crc = 0xFF; // Standard init value for CRC8 8H2F/AUTOSAR
|
||||
|
||||
// CRC the payload first, skipping over the first byte where the CRC lives.
|
||||
for (int i = 1; i < l; i++) {
|
||||
crc ^= dat[i];
|
||||
crc = crc8_lut_8h2f[crc];
|
||||
}
|
||||
|
||||
// Look up and apply the magic final CRC padding byte, which permutes by CAN
|
||||
// address, and additionally (for SOME addresses) by the message counter.
|
||||
uint8_t counter = dat[1] & 0x0F;
|
||||
switch(address) {
|
||||
case 0x86: // LWI_01 Steering Angle
|
||||
crc ^= (uint8_t[]){0x86,0x86,0x86,0x86,0x86,0x86,0x86,0x86,0x86,0x86,0x86,0x86,0x86,0x86,0x86,0x86}[counter];
|
||||
break;
|
||||
case 0x9F: // EPS_01 Electric Power Steering
|
||||
crc ^= (uint8_t[]){0xF5,0xF5,0xF5,0xF5,0xF5,0xF5,0xF5,0xF5,0xF5,0xF5,0xF5,0xF5,0xF5,0xF5,0xF5,0xF5}[counter];
|
||||
break;
|
||||
case 0xAD: // Getriebe_11 Automatic Gearbox
|
||||
crc ^= (uint8_t[]){0x3F,0x69,0x39,0xDC,0x94,0xF9,0x14,0x64,0xD8,0x6A,0x34,0xCE,0xA2,0x55,0xB5,0x2C}[counter];
|
||||
break;
|
||||
case 0xFD: // ESP_21 Electronic Stability Program
|
||||
crc ^= (uint8_t[]){0xB4,0xEF,0xF8,0x49,0x1E,0xE5,0xC2,0xC0,0x97,0x19,0x3C,0xC9,0xF1,0x98,0xD6,0x61}[counter];
|
||||
break;
|
||||
case 0x106: // ESP_05 Electronic Stability Program
|
||||
crc ^= (uint8_t[]){0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07}[counter];
|
||||
break;
|
||||
case 0x117: // ACC_10 Automatic Cruise Control
|
||||
crc ^= (uint8_t[]){0xAC,0xAC,0xAC,0xAC,0xAC,0xAC,0xAC,0xAC,0xAC,0xAC,0xAC,0xAC,0xAC,0xAC,0xAC,0xAC}[counter];
|
||||
break;
|
||||
case 0x122: // ACC_06 Automatic Cruise Control
|
||||
crc ^= (uint8_t[]){0x37,0x7D,0xF3,0xA9,0x18,0x46,0x6D,0x4D,0x3D,0x71,0x92,0x9C,0xE5,0x32,0x10,0xB9}[counter];
|
||||
break;
|
||||
case 0x126: // HCA_01 Heading Control Assist
|
||||
crc ^= (uint8_t[]){0xDA,0xDA,0xDA,0xDA,0xDA,0xDA,0xDA,0xDA,0xDA,0xDA,0xDA,0xDA,0xDA,0xDA,0xDA,0xDA}[counter];
|
||||
break;
|
||||
case 0x12B: // GRA_ACC_01 Steering wheel controls for ACC
|
||||
crc ^= (uint8_t[]){0x6A,0x38,0xB4,0x27,0x22,0xEF,0xE1,0xBB,0xF8,0x80,0x84,0x49,0xC7,0x9E,0x1E,0x2B}[counter];
|
||||
break;
|
||||
case 0x187: // EV_Gearshift "Gear" selection data for EVs with no gearbox
|
||||
crc ^= (uint8_t[]){0x7F,0xED,0x17,0xC2,0x7C,0xEB,0x44,0x21,0x01,0xFA,0xDB,0x15,0x4A,0x6B,0x23,0x05}[counter];
|
||||
break;
|
||||
case 0x30C: // ACC_02 Automatic Cruise Control
|
||||
crc ^= (uint8_t[]){0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F}[counter];
|
||||
break;
|
||||
case 0x3C0: // Klemmen_Status_01 ignition and starting status
|
||||
crc ^= (uint8_t[]){0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3}[counter];
|
||||
break;
|
||||
case 0x65D: // ESP_20 Electronic Stability Program
|
||||
crc ^= (uint8_t[]){0xAC,0xB3,0xAB,0xEB,0x7A,0xE1,0x3B,0xF7,0x73,0xBA,0x7C,0x9E,0x06,0x5F,0x02,0xD9}[counter];
|
||||
break;
|
||||
default: // As-yet undefined CAN message, CRC check expected to fail
|
||||
printf("Attempt to CRC check undefined Volkswagen message 0x%02X\n", address);
|
||||
crc ^= (uint8_t[]){0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}[counter];
|
||||
break;
|
||||
}
|
||||
crc = crc8_lut_8h2f[crc];
|
||||
|
||||
return crc ^ 0xFF; // Return after standard final XOR for CRC8 8H2F/AUTOSAR
|
||||
}
|
||||
|
||||
|
||||
unsigned int pedal_checksum(uint64_t d, int l) {
|
||||
uint8_t crc = 0xFF;
|
||||
uint8_t poly = 0xD5; // standard crc8
|
||||
|
||||
d >>= ((8-l)*8); // remove padding
|
||||
d >>= 8; // remove checksum
|
||||
|
||||
uint8_t *dat = (uint8_t *)&d;
|
||||
|
||||
int i, j;
|
||||
for (i = 0; i < l - 1; i++) {
|
||||
crc ^= dat[i];
|
||||
for (j = 0; j < 8; j++) {
|
||||
if ((crc & 0x80) != 0) {
|
||||
crc = (uint8_t)((crc << 1) ^ poly);
|
||||
}
|
||||
else {
|
||||
crc <<= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
||||
|
||||
uint64_t read_u64_be(const uint8_t* v) {
|
||||
return (((uint64_t)v[0] << 56)
|
||||
| ((uint64_t)v[1] << 48)
|
||||
| ((uint64_t)v[2] << 40)
|
||||
| ((uint64_t)v[3] << 32)
|
||||
| ((uint64_t)v[4] << 24)
|
||||
| ((uint64_t)v[5] << 16)
|
||||
| ((uint64_t)v[6] << 8)
|
||||
| (uint64_t)v[7]);
|
||||
}
|
||||
|
||||
uint64_t read_u64_le(const uint8_t* v) {
|
||||
return ((uint64_t)v[0]
|
||||
| ((uint64_t)v[1] << 8)
|
||||
| ((uint64_t)v[2] << 16)
|
||||
| ((uint64_t)v[3] << 24)
|
||||
| ((uint64_t)v[4] << 32)
|
||||
| ((uint64_t)v[5] << 40)
|
||||
| ((uint64_t)v[6] << 48)
|
||||
| ((uint64_t)v[7] << 56));
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "common_dbc.h"
|
||||
#include <capnp/serialize.h>
|
||||
#include "cereal/gen/cpp/log.capnp.h"
|
||||
|
||||
#define MAX_BAD_COUNTER 5
|
||||
|
||||
// Helper functions
|
||||
unsigned int honda_checksum(unsigned int address, uint64_t d, int l);
|
||||
unsigned int toyota_checksum(unsigned int address, uint64_t d, int l);
|
||||
void init_crc_lookup_tables();
|
||||
unsigned int volkswagen_crc(unsigned int address, uint64_t d, int l);
|
||||
unsigned int pedal_checksum(uint64_t d, int l);
|
||||
uint64_t read_u64_be(const uint8_t* v);
|
||||
uint64_t read_u64_le(const uint8_t* v);
|
||||
|
||||
class MessageState {
|
||||
public:
|
||||
uint32_t address;
|
||||
unsigned int size;
|
||||
|
||||
std::vector<Signal> parse_sigs;
|
||||
std::vector<double> vals;
|
||||
|
||||
uint16_t ts;
|
||||
uint64_t seen;
|
||||
uint64_t check_threshold;
|
||||
|
||||
uint8_t counter;
|
||||
uint8_t counter_fail;
|
||||
|
||||
bool parse(uint64_t sec, uint16_t ts_, uint8_t * dat);
|
||||
bool update_counter_generic(int64_t v, int cnt_size);
|
||||
};
|
||||
|
||||
class CANParser {
|
||||
private:
|
||||
const int bus;
|
||||
|
||||
const DBC *dbc = NULL;
|
||||
std::unordered_map<uint32_t, MessageState> message_states;
|
||||
|
||||
public:
|
||||
bool can_valid = false;
|
||||
uint64_t last_sec = 0;
|
||||
|
||||
CANParser(int abus, const std::string& dbc_name,
|
||||
const std::vector<MessageParseOptions> &options,
|
||||
const std::vector<SignalParseOptions> &sigoptions);
|
||||
void UpdateCans(uint64_t sec, const capnp::List<cereal::CanData>::Reader& cans);
|
||||
void UpdateValid(uint64_t sec);
|
||||
void update_string(std::string data, bool sendcan);
|
||||
std::vector<SignalValue> query_latest();
|
||||
};
|
||||
|
||||
class CANPacker {
|
||||
private:
|
||||
const DBC *dbc = NULL;
|
||||
std::map<std::pair<uint32_t, std::string>, Signal> signal_lookup;
|
||||
std::map<uint32_t, Msg> message_lookup;
|
||||
|
||||
public:
|
||||
CANPacker(const std::string& dbc_name);
|
||||
uint64_t pack(uint32_t address, const std::vector<SignalPackValue> &signals, int counter);
|
||||
};
|
||||
@@ -1,82 +0,0 @@
|
||||
# distutils: language = c++
|
||||
#cython: language_level=3
|
||||
|
||||
from libc.stdint cimport uint32_t, uint64_t, uint16_t
|
||||
from libcpp.vector cimport vector
|
||||
from libcpp.map cimport map
|
||||
from libcpp.string cimport string
|
||||
from libcpp.unordered_set cimport unordered_set
|
||||
from libcpp cimport bool
|
||||
|
||||
|
||||
cdef extern from "common_dbc.h":
|
||||
ctypedef enum SignalType:
|
||||
DEFAULT,
|
||||
HONDA_CHECKSUM,
|
||||
HONDA_COUNTER,
|
||||
TOYOTA_CHECKSUM,
|
||||
PEDAL_CHECKSUM,
|
||||
PEDAL_COUNTER,
|
||||
VOLKSWAGEN_CHECKSUM,
|
||||
VOLKSWAGEN_COUNTER
|
||||
|
||||
cdef struct Signal:
|
||||
const char* name
|
||||
int b1, b2, bo
|
||||
bool is_signed
|
||||
double factor, offset
|
||||
SignalType type
|
||||
|
||||
cdef struct Msg:
|
||||
const char* name
|
||||
uint32_t address
|
||||
unsigned int size
|
||||
size_t num_sigs
|
||||
const Signal *sigs
|
||||
|
||||
cdef struct Val:
|
||||
const char* name
|
||||
uint32_t address
|
||||
const char* def_val
|
||||
const Signal *sigs
|
||||
|
||||
cdef struct DBC:
|
||||
const char* name
|
||||
size_t num_msgs
|
||||
const Msg *msgs
|
||||
const Val *vals
|
||||
size_t num_vals
|
||||
|
||||
cdef struct SignalParseOptions:
|
||||
uint32_t address
|
||||
const char* name
|
||||
double default_value
|
||||
|
||||
|
||||
cdef struct MessageParseOptions:
|
||||
uint32_t address
|
||||
int check_frequency
|
||||
|
||||
cdef struct SignalValue:
|
||||
uint32_t address
|
||||
uint16_t ts
|
||||
const char* name
|
||||
double value
|
||||
|
||||
cdef struct SignalPackValue:
|
||||
const char * name
|
||||
double value
|
||||
|
||||
|
||||
cdef extern from "common.h":
|
||||
cdef const DBC* dbc_lookup(const string);
|
||||
|
||||
cdef cppclass CANParser:
|
||||
bool can_valid
|
||||
CANParser(int, string, vector[MessageParseOptions], vector[SignalParseOptions])
|
||||
void update_string(string, bool)
|
||||
vector[SignalValue] query_latest()
|
||||
|
||||
cdef cppclass CANPacker:
|
||||
CANPacker(string)
|
||||
uint64_t pack(uint32_t, vector[SignalPackValue], int counter)
|
||||
@@ -1,108 +0,0 @@
|
||||
#include <cassert>
|
||||
#include <utility>
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
#include <cmath>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#define WARN printf
|
||||
|
||||
// this is the same as read_u64_le, but uses uint64_t as in/out
|
||||
uint64_t ReverseBytes(uint64_t x) {
|
||||
return ((x & 0xff00000000000000ull) >> 56) |
|
||||
((x & 0x00ff000000000000ull) >> 40) |
|
||||
((x & 0x0000ff0000000000ull) >> 24) |
|
||||
((x & 0x000000ff00000000ull) >> 8) |
|
||||
((x & 0x00000000ff000000ull) << 8) |
|
||||
((x & 0x0000000000ff0000ull) << 24) |
|
||||
((x & 0x000000000000ff00ull) << 40) |
|
||||
((x & 0x00000000000000ffull) << 56);
|
||||
}
|
||||
|
||||
uint64_t set_value(uint64_t ret, Signal sig, int64_t ival){
|
||||
int shift = sig.is_little_endian? sig.b1 : sig.bo;
|
||||
uint64_t mask = ((1ULL << sig.b2)-1) << shift;
|
||||
uint64_t dat = (ival & ((1ULL << sig.b2)-1)) << shift;
|
||||
if (sig.is_little_endian) {
|
||||
dat = ReverseBytes(dat);
|
||||
mask = ReverseBytes(mask);
|
||||
}
|
||||
ret &= ~mask;
|
||||
ret |= dat;
|
||||
return ret;
|
||||
}
|
||||
|
||||
CANPacker::CANPacker(const std::string& dbc_name) {
|
||||
dbc = dbc_lookup(dbc_name);
|
||||
assert(dbc);
|
||||
|
||||
for (int i=0; i<dbc->num_msgs; i++) {
|
||||
const Msg* msg = &dbc->msgs[i];
|
||||
message_lookup[msg->address] = *msg;
|
||||
for (int j=0; j<msg->num_sigs; j++) {
|
||||
const Signal* sig = &msg->sigs[j];
|
||||
signal_lookup[std::make_pair(msg->address, std::string(sig->name))] = *sig;
|
||||
}
|
||||
}
|
||||
init_crc_lookup_tables();
|
||||
}
|
||||
|
||||
uint64_t CANPacker::pack(uint32_t address, const std::vector<SignalPackValue> &signals, int counter) {
|
||||
uint64_t ret = 0;
|
||||
for (const auto& sigval : signals) {
|
||||
std::string name = std::string(sigval.name);
|
||||
double value = sigval.value;
|
||||
|
||||
auto sig_it = signal_lookup.find(std::make_pair(address, name));
|
||||
if (sig_it == signal_lookup.end()) {
|
||||
WARN("undefined signal %s - %d\n", name.c_str(), address);
|
||||
continue;
|
||||
}
|
||||
auto sig = sig_it->second;
|
||||
|
||||
int64_t ival = (int64_t)(round((value - sig.offset) / sig.factor));
|
||||
if (ival < 0) {
|
||||
ival = (1ULL << sig.b2) + ival;
|
||||
}
|
||||
|
||||
ret = set_value(ret, sig, ival);
|
||||
}
|
||||
|
||||
if (counter >= 0){
|
||||
auto sig_it = signal_lookup.find(std::make_pair(address, "COUNTER"));
|
||||
if (sig_it == signal_lookup.end()) {
|
||||
WARN("COUNTER not defined\n");
|
||||
return ret;
|
||||
}
|
||||
auto sig = sig_it->second;
|
||||
|
||||
if ((sig.type != SignalType::HONDA_COUNTER) && (sig.type != SignalType::VOLKSWAGEN_COUNTER)) {
|
||||
WARN("COUNTER signal type not valid\n");
|
||||
}
|
||||
|
||||
ret = set_value(ret, sig, counter);
|
||||
}
|
||||
|
||||
auto sig_it_checksum = signal_lookup.find(std::make_pair(address, "CHECKSUM"));
|
||||
if (sig_it_checksum != signal_lookup.end()) {
|
||||
auto sig = sig_it_checksum->second;
|
||||
if (sig.type == SignalType::HONDA_CHECKSUM) {
|
||||
unsigned int chksm = honda_checksum(address, ret, message_lookup[address].size);
|
||||
ret = set_value(ret, sig, chksm);
|
||||
} else if (sig.type == SignalType::TOYOTA_CHECKSUM) {
|
||||
unsigned int chksm = toyota_checksum(address, ret, message_lookup[address].size);
|
||||
ret = set_value(ret, sig, chksm);
|
||||
} else if (sig.type == SignalType::VOLKSWAGEN_CHECKSUM) {
|
||||
// FIXME: Hackish fix for an endianness issue. The message is in reverse byte order
|
||||
// until later in the pack process. Checksums can be run backwards, CRCs not so much.
|
||||
// The correct fix is unclear but this works for the moment.
|
||||
unsigned int chksm = volkswagen_crc(address, ReverseBytes(ret), message_lookup[address].size);
|
||||
ret = set_value(ret, sig, chksm);
|
||||
} else {
|
||||
//WARN("CHECKSUM signal type not valid\n");
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
# pylint: skip-file
|
||||
from opendbc.can.packer_pyx import CANPacker
|
||||
assert CANPacker
|
||||
@@ -1,67 +0,0 @@
|
||||
# distutils: language = c++
|
||||
# cython: c_string_encoding=ascii, language_level=3
|
||||
|
||||
from libc.stdint cimport uint32_t, uint64_t
|
||||
from libcpp.vector cimport vector
|
||||
from libcpp.map cimport map
|
||||
from libcpp.string cimport string
|
||||
from libcpp cimport bool
|
||||
from posix.dlfcn cimport dlopen, dlsym, RTLD_LAZY
|
||||
|
||||
from common cimport CANPacker as cpp_CANPacker
|
||||
from common cimport dbc_lookup, SignalPackValue, DBC
|
||||
|
||||
|
||||
cdef class CANPacker:
|
||||
cdef:
|
||||
cpp_CANPacker *packer
|
||||
const DBC *dbc
|
||||
map[string, (int, int)] name_to_address_and_size
|
||||
map[int, int] address_to_size
|
||||
|
||||
def __init__(self, dbc_name):
|
||||
self.packer = new cpp_CANPacker(dbc_name)
|
||||
self.dbc = dbc_lookup(dbc_name)
|
||||
|
||||
num_msgs = self.dbc[0].num_msgs
|
||||
for i in range(num_msgs):
|
||||
msg = self.dbc[0].msgs[i]
|
||||
self.name_to_address_and_size[string(msg.name)] = (msg.address, msg.size)
|
||||
self.address_to_size[msg.address] = msg.size
|
||||
|
||||
cdef uint64_t pack(self, addr, values, counter):
|
||||
cdef vector[SignalPackValue] values_thing
|
||||
cdef SignalPackValue spv
|
||||
|
||||
names = []
|
||||
|
||||
for name, value in values.iteritems():
|
||||
n = name.encode('utf8')
|
||||
names.append(n) # TODO: find better way to keep reference to temp string arround
|
||||
|
||||
spv.name = n
|
||||
spv.value = value
|
||||
values_thing.push_back(spv)
|
||||
|
||||
return self.packer.pack(addr, values_thing, counter)
|
||||
|
||||
cdef inline uint64_t ReverseBytes(self, uint64_t x):
|
||||
return (((x & 0xff00000000000000ull) >> 56) |
|
||||
((x & 0x00ff000000000000ull) >> 40) |
|
||||
((x & 0x0000ff0000000000ull) >> 24) |
|
||||
((x & 0x000000ff00000000ull) >> 8) |
|
||||
((x & 0x00000000ff000000ull) << 8) |
|
||||
((x & 0x0000000000ff0000ull) << 24) |
|
||||
((x & 0x000000000000ff00ull) << 40) |
|
||||
((x & 0x00000000000000ffull) << 56))
|
||||
|
||||
cpdef make_can_msg(self, name_or_addr, bus, values, counter=-1):
|
||||
cdef int addr, size
|
||||
if type(name_or_addr) == int:
|
||||
addr = name_or_addr
|
||||
size = self.address_to_size[name_or_addr]
|
||||
else:
|
||||
addr, size = self.name_to_address_and_size[name_or_addr.encode('utf8')]
|
||||
cdef uint64_t val = self.pack(addr, values, counter)
|
||||
val = self.ReverseBytes(val)
|
||||
return [addr, 0, (<char *>&val)[:size], bus]
|
||||
@@ -1,69 +0,0 @@
|
||||
import os
|
||||
import sysconfig
|
||||
import subprocess
|
||||
import platform
|
||||
from distutils.core import Extension, setup # pylint: disable=import-error,no-name-in-module
|
||||
|
||||
from Cython.Build import cythonize
|
||||
from Cython.Distutils import build_ext
|
||||
|
||||
BASEDIR = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), "../../"))
|
||||
|
||||
|
||||
def get_ext_filename_without_platform_suffix(filename):
|
||||
name, ext = os.path.splitext(filename)
|
||||
ext_suffix = sysconfig.get_config_var('EXT_SUFFIX')
|
||||
|
||||
if ext_suffix == ext:
|
||||
return filename
|
||||
|
||||
ext_suffix = ext_suffix.replace(ext, '')
|
||||
idx = name.find(ext_suffix)
|
||||
|
||||
if idx == -1:
|
||||
return filename
|
||||
else:
|
||||
return name[:idx] + ext
|
||||
|
||||
|
||||
class BuildExtWithoutPlatformSuffix(build_ext):
|
||||
def get_ext_filename(self, ext_name):
|
||||
filename = super().get_ext_filename(ext_name)
|
||||
return get_ext_filename_without_platform_suffix(filename)
|
||||
|
||||
|
||||
sourcefiles = ['packer_pyx.pyx']
|
||||
extra_compile_args = ["-std=c++11"]
|
||||
ARCH = subprocess.check_output(["uname", "-m"], encoding='utf8').rstrip() # pylint: disable=unexpected-keyword-arg
|
||||
|
||||
if ARCH == "aarch64":
|
||||
extra_compile_args += ["-Wno-deprecated-register"]
|
||||
|
||||
if platform.system() == "Darwin":
|
||||
libdbc = "libdbc.dylib"
|
||||
else:
|
||||
libdbc = "libdbc.so"
|
||||
|
||||
setup(name='CAN packer',
|
||||
cmdclass={'build_ext': BuildExtWithoutPlatformSuffix},
|
||||
ext_modules=cythonize(
|
||||
Extension(
|
||||
"packer_pyx",
|
||||
language="c++",
|
||||
sources=sourcefiles,
|
||||
extra_compile_args=extra_compile_args,
|
||||
include_dirs=[
|
||||
BASEDIR,
|
||||
os.path.join(BASEDIR, 'phonelibs', 'capnp-cpp/include'),
|
||||
],
|
||||
extra_link_args=[
|
||||
os.path.join(BASEDIR, 'opendbc', 'can', libdbc),
|
||||
],
|
||||
)
|
||||
),
|
||||
nthreads=4,
|
||||
)
|
||||
|
||||
if platform.system() == "Darwin":
|
||||
os.system("install_name_tool -change opendbc/can/libdbc.dylib "+BASEDIR+"/opendbc/can/libdbc.dylib packer_pyx.so")
|
||||
|
||||
@@ -1,239 +0,0 @@
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/mman.h>
|
||||
#include <algorithm>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#define DEBUG(...)
|
||||
// #define DEBUG printf
|
||||
#define INFO printf
|
||||
|
||||
|
||||
bool MessageState::parse(uint64_t sec, uint16_t ts_, uint8_t * dat) {
|
||||
uint64_t dat_le = read_u64_le(dat);
|
||||
uint64_t dat_be = read_u64_be(dat);
|
||||
|
||||
for (int i=0; i < parse_sigs.size(); i++) {
|
||||
auto& sig = parse_sigs[i];
|
||||
int64_t tmp;
|
||||
|
||||
if (sig.is_little_endian){
|
||||
tmp = (dat_le >> sig.b1) & ((1ULL << sig.b2)-1);
|
||||
} else {
|
||||
tmp = (dat_be >> sig.bo) & ((1ULL << sig.b2)-1);
|
||||
}
|
||||
|
||||
if (sig.is_signed) {
|
||||
tmp -= (tmp >> (sig.b2-1)) ? (1ULL << sig.b2) : 0; //signed
|
||||
}
|
||||
|
||||
DEBUG("parse 0x%X %s -> %lld\n", address, sig.name, tmp);
|
||||
|
||||
if (sig.type == SignalType::HONDA_CHECKSUM) {
|
||||
if (honda_checksum(address, dat_be, size) != tmp) {
|
||||
INFO("0x%X CHECKSUM FAIL\n", address);
|
||||
return false;
|
||||
}
|
||||
} else if (sig.type == SignalType::HONDA_COUNTER) {
|
||||
if (!update_counter_generic(tmp, sig.b2)) {
|
||||
return false;
|
||||
}
|
||||
} else if (sig.type == SignalType::TOYOTA_CHECKSUM) {
|
||||
if (toyota_checksum(address, dat_be, size) != tmp) {
|
||||
INFO("0x%X CHECKSUM FAIL\n", address);
|
||||
return false;
|
||||
}
|
||||
} else if (sig.type == SignalType::VOLKSWAGEN_CHECKSUM) {
|
||||
if (volkswagen_crc(address, dat_le, size) != tmp) {
|
||||
INFO("0x%X CRC FAIL\n", address);
|
||||
return false;
|
||||
}
|
||||
} else if (sig.type == SignalType::VOLKSWAGEN_COUNTER) {
|
||||
if (!update_counter_generic(tmp, sig.b2)) {
|
||||
return false;
|
||||
}
|
||||
} else if (sig.type == SignalType::PEDAL_CHECKSUM) {
|
||||
if (pedal_checksum(dat_be, size) != tmp) {
|
||||
INFO("0x%X PEDAL CHECKSUM FAIL\n", address);
|
||||
return false;
|
||||
}
|
||||
} else if (sig.type == SignalType::PEDAL_COUNTER) {
|
||||
if (!update_counter_generic(tmp, sig.b2)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
vals[i] = tmp * sig.factor + sig.offset;
|
||||
}
|
||||
ts = ts_;
|
||||
seen = sec;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool MessageState::update_counter_generic(int64_t v, int cnt_size) {
|
||||
uint8_t old_counter = counter;
|
||||
counter = v;
|
||||
if (((old_counter+1) & ((1 << cnt_size) -1)) != v) {
|
||||
counter_fail += 1;
|
||||
if (counter_fail > 1) {
|
||||
INFO("0x%X COUNTER FAIL %d -- %d vs %d\n", address, counter_fail, old_counter, (int)v);
|
||||
}
|
||||
if (counter_fail >= MAX_BAD_COUNTER) {
|
||||
return false;
|
||||
}
|
||||
} else if (counter_fail > 0) {
|
||||
counter_fail--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
CANParser::CANParser(int abus, const std::string& dbc_name,
|
||||
const std::vector<MessageParseOptions> &options,
|
||||
const std::vector<SignalParseOptions> &sigoptions)
|
||||
: bus(abus) {
|
||||
|
||||
dbc = dbc_lookup(dbc_name);
|
||||
assert(dbc);
|
||||
init_crc_lookup_tables();
|
||||
|
||||
for (const auto& op : options) {
|
||||
MessageState state = {
|
||||
.address = op.address,
|
||||
// .check_frequency = op.check_frequency,
|
||||
};
|
||||
|
||||
// msg is not valid if a message isn't received for 10 consecutive steps
|
||||
if (op.check_frequency > 0) {
|
||||
state.check_threshold = (1000000000ULL / op.check_frequency) * 10;
|
||||
}
|
||||
|
||||
|
||||
const Msg* msg = NULL;
|
||||
for (int i=0; i<dbc->num_msgs; i++) {
|
||||
if (dbc->msgs[i].address == op.address) {
|
||||
msg = &dbc->msgs[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!msg) {
|
||||
fprintf(stderr, "CANParser: could not find message 0x%X in DBC %s\n", op.address, dbc_name.c_str());
|
||||
assert(false);
|
||||
}
|
||||
|
||||
state.size = msg->size;
|
||||
|
||||
// track checksums and counters for this message
|
||||
for (int i=0; i<msg->num_sigs; i++) {
|
||||
const Signal *sig = &msg->sigs[i];
|
||||
if (sig->type != SignalType::DEFAULT) {
|
||||
state.parse_sigs.push_back(*sig);
|
||||
state.vals.push_back(0);
|
||||
}
|
||||
}
|
||||
|
||||
// track requested signals for this message
|
||||
for (const auto& sigop : sigoptions) {
|
||||
if (sigop.address != op.address) continue;
|
||||
|
||||
for (int i=0; i<msg->num_sigs; i++) {
|
||||
const Signal *sig = &msg->sigs[i];
|
||||
if (strcmp(sig->name, sigop.name) == 0
|
||||
&& sig->type == SignalType::DEFAULT) {
|
||||
state.parse_sigs.push_back(*sig);
|
||||
state.vals.push_back(sigop.default_value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
message_states[state.address] = state;
|
||||
}
|
||||
}
|
||||
|
||||
void CANParser::UpdateCans(uint64_t sec, const capnp::List<cereal::CanData>::Reader& cans) {
|
||||
int msg_count = cans.size();
|
||||
uint64_t p;
|
||||
|
||||
DEBUG("got %d messages\n", msg_count);
|
||||
|
||||
// parse the messages
|
||||
for (int i = 0; i < msg_count; i++) {
|
||||
auto cmsg = cans[i];
|
||||
if (cmsg.getSrc() != bus) {
|
||||
// DEBUG("skip %d: wrong bus\n", cmsg.getAddress());
|
||||
continue;
|
||||
}
|
||||
auto state_it = message_states.find(cmsg.getAddress());
|
||||
if (state_it == message_states.end()) {
|
||||
// DEBUG("skip %d: not specified\n", cmsg.getAddress());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (cmsg.getDat().size() > 8) continue; //shouldnt ever happen
|
||||
uint8_t dat[8] = {0};
|
||||
memcpy(dat, cmsg.getDat().begin(), cmsg.getDat().size());
|
||||
|
||||
state_it->second.parse(sec, cmsg.getBusTime(), dat);
|
||||
}
|
||||
}
|
||||
|
||||
void CANParser::UpdateValid(uint64_t sec) {
|
||||
can_valid = true;
|
||||
for (const auto& kv : message_states) {
|
||||
const auto& state = kv.second;
|
||||
if (state.check_threshold > 0 && (sec - state.seen) > state.check_threshold) {
|
||||
if (state.seen > 0) {
|
||||
DEBUG("0x%X TIMEOUT\n", state.address);
|
||||
}
|
||||
can_valid = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CANParser::update_string(std::string data, bool sendcan) {
|
||||
// format for board, make copy due to alignment issues, will be freed on out of scope
|
||||
auto amsg = kj::heapArray<capnp::word>((data.length() / sizeof(capnp::word)) + 1);
|
||||
memcpy(amsg.begin(), data.data(), data.length());
|
||||
|
||||
// extract the messages
|
||||
capnp::FlatArrayMessageReader cmsg(amsg);
|
||||
cereal::Event::Reader event = cmsg.getRoot<cereal::Event>();
|
||||
|
||||
last_sec = event.getLogMonoTime();
|
||||
|
||||
auto cans = sendcan? event.getSendcan() : event.getCan();
|
||||
UpdateCans(last_sec, cans);
|
||||
|
||||
UpdateValid(last_sec);
|
||||
}
|
||||
|
||||
|
||||
std::vector<SignalValue> CANParser::query_latest() {
|
||||
std::vector<SignalValue> ret;
|
||||
|
||||
for (const auto& kv : message_states) {
|
||||
const auto& state = kv.second;
|
||||
if (last_sec != 0 && state.seen != last_sec) continue;
|
||||
|
||||
for (int i=0; i<state.parse_sigs.size(); i++) {
|
||||
const Signal &sig = state.parse_sigs[i];
|
||||
ret.push_back((SignalValue){
|
||||
.address = state.address,
|
||||
.ts = state.ts,
|
||||
.name = sig.name,
|
||||
.value = state.vals[i],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
from opendbc.can.parser_pyx import CANParser # pylint: disable=no-name-in-module, import-error
|
||||
assert CANParser
|
||||
@@ -1,69 +0,0 @@
|
||||
import os
|
||||
import subprocess
|
||||
import sysconfig
|
||||
import platform
|
||||
from distutils.core import Extension, setup # pylint: disable=import-error,no-name-in-module
|
||||
|
||||
from Cython.Build import cythonize
|
||||
from Cython.Distutils import build_ext
|
||||
|
||||
BASEDIR = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), "../../"))
|
||||
|
||||
|
||||
def get_ext_filename_without_platform_suffix(filename):
|
||||
name, ext = os.path.splitext(filename)
|
||||
ext_suffix = sysconfig.get_config_var('EXT_SUFFIX')
|
||||
|
||||
if ext_suffix == ext:
|
||||
return filename
|
||||
|
||||
ext_suffix = ext_suffix.replace(ext, '')
|
||||
idx = name.find(ext_suffix)
|
||||
|
||||
if idx == -1:
|
||||
return filename
|
||||
else:
|
||||
return name[:idx] + ext
|
||||
|
||||
|
||||
class BuildExtWithoutPlatformSuffix(build_ext):
|
||||
def get_ext_filename(self, ext_name):
|
||||
filename = super().get_ext_filename(ext_name)
|
||||
return get_ext_filename_without_platform_suffix(filename)
|
||||
|
||||
|
||||
sourcefiles = ['parser_pyx.pyx']
|
||||
extra_compile_args = ["-std=c++11"]
|
||||
ARCH = subprocess.check_output(["uname", "-m"], encoding='utf8').rstrip() # pylint: disable=unexpected-keyword-arg
|
||||
|
||||
if ARCH == "aarch64":
|
||||
extra_compile_args += ["-Wno-deprecated-register"]
|
||||
|
||||
if platform.system() == "Darwin":
|
||||
libdbc = "libdbc.dylib"
|
||||
else:
|
||||
libdbc = "libdbc.so"
|
||||
|
||||
setup(name='CAN parser',
|
||||
cmdclass={'build_ext': BuildExtWithoutPlatformSuffix},
|
||||
ext_modules=cythonize(
|
||||
Extension(
|
||||
"parser_pyx",
|
||||
language="c++",
|
||||
sources=sourcefiles,
|
||||
extra_compile_args=extra_compile_args,
|
||||
include_dirs=[
|
||||
BASEDIR,
|
||||
os.path.join(BASEDIR, 'phonelibs', 'capnp-cpp/include'),
|
||||
],
|
||||
extra_link_args=[
|
||||
os.path.join(BASEDIR, 'opendbc', 'can', libdbc),
|
||||
],
|
||||
)
|
||||
),
|
||||
nthreads=4,
|
||||
)
|
||||
|
||||
if platform.system() == "Darwin":
|
||||
os.system("install_name_tool -change opendbc/can/libdbc.dylib "+BASEDIR+"/opendbc/can/libdbc.dylib parser_pyx.so")
|
||||
|
||||
@@ -1,112 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
from __future__ import print_function
|
||||
import os
|
||||
import sys
|
||||
|
||||
import jinja2
|
||||
|
||||
from collections import Counter
|
||||
from opendbc.can.dbc import dbc
|
||||
|
||||
def process(in_fn, out_fn):
|
||||
dbc_name = os.path.split(out_fn)[-1].replace('.cc', '')
|
||||
#print("processing %s: %s -> %s" % (dbc_name, in_fn, out_fn))
|
||||
|
||||
template_fn = os.path.join(os.path.dirname(__file__), "dbc_template.cc")
|
||||
|
||||
with open(template_fn, "r") as template_f:
|
||||
template = jinja2.Template(template_f.read(), trim_blocks=True, lstrip_blocks=True)
|
||||
|
||||
can_dbc = dbc(in_fn)
|
||||
|
||||
msgs = [(address, msg_name, msg_size, sorted(msg_sigs, key=lambda s: s.name not in ("COUNTER", "CHECKSUM"))) # process counter and checksums first
|
||||
for address, ((msg_name, msg_size), msg_sigs) in sorted(can_dbc.msgs.items()) if msg_sigs]
|
||||
|
||||
def_vals = {a: sorted(set(b)) for a, b in can_dbc.def_vals.items()} # remove duplicates
|
||||
def_vals = sorted(def_vals.items())
|
||||
|
||||
if can_dbc.name.startswith(("honda_", "acura_")):
|
||||
checksum_type = "honda"
|
||||
checksum_size = 4
|
||||
counter_size = 2
|
||||
checksum_start_bit = 3
|
||||
counter_start_bit = 5
|
||||
little_endian = False
|
||||
elif can_dbc.name.startswith(("toyota_", "lexus_")):
|
||||
checksum_type = "toyota"
|
||||
checksum_size = 8
|
||||
counter_size = None
|
||||
checksum_start_bit = 7
|
||||
counter_start_bit = None
|
||||
little_endian = False
|
||||
elif can_dbc.name.startswith(("vw_", "volkswagen_", "audi_", "seat_", "skoda_")):
|
||||
checksum_type = "volkswagen"
|
||||
checksum_size = 8
|
||||
counter_size = 4
|
||||
checksum_start_bit = 0
|
||||
counter_start_bit = 0
|
||||
little_endian = True
|
||||
else:
|
||||
checksum_type = None
|
||||
checksum_size = None
|
||||
counter_size = None
|
||||
checksum_start_bit = None
|
||||
counter_start_bit = None
|
||||
little_endian = None
|
||||
|
||||
# sanity checks on expected COUNTER and CHECKSUM rules, as packer and parser auto-compute those signals
|
||||
for address, msg_name, msg_size, sigs in msgs:
|
||||
dbc_msg_name = dbc_name + " " + msg_name
|
||||
for sig in sigs:
|
||||
if checksum_type is not None:
|
||||
# checksum rules
|
||||
if sig.name == "CHECKSUM":
|
||||
if sig.size != checksum_size:
|
||||
sys.exit("%s: CHECKSUM is not %d bits long" % (dbc_msg_name, checksum_size))
|
||||
if sig.start_bit % 8 != checksum_start_bit:
|
||||
sys.exit("%s: CHECKSUM starts at wrong bit" % dbc_msg_name)
|
||||
if little_endian != sig.is_little_endian:
|
||||
sys.exit("%s: CHECKSUM has wrong endianess" % dbc_msg_name)
|
||||
# counter rules
|
||||
if sig.name == "COUNTER":
|
||||
if counter_size is not None and sig.size != counter_size:
|
||||
sys.exit("%s: COUNTER is not %d bits long" % (dbc_msg_name, counter_size))
|
||||
if counter_start_bit is not None and sig.start_bit % 8 != counter_start_bit:
|
||||
print(counter_start_bit, sig.start_bit)
|
||||
sys.exit("%s: COUNTER starts at wrong bit" % dbc_msg_name)
|
||||
if little_endian != sig.is_little_endian:
|
||||
sys.exit("%s: COUNTER has wrong endianess" % dbc_msg_name)
|
||||
# pedal rules
|
||||
if address in [0x200, 0x201]:
|
||||
if sig.name == "COUNTER_PEDAL" and sig.size != 4:
|
||||
sys.exit("%s: PEDAL COUNTER is not 4 bits long" % dbc_msg_name)
|
||||
if sig.name == "CHECKSUM_PEDAL" and sig.size != 8:
|
||||
sys.exit("%s: PEDAL CHECKSUM is not 8 bits long" % dbc_msg_name)
|
||||
|
||||
# Fail on duplicate message names
|
||||
c = Counter([msg_name for address, msg_name, msg_size, sigs in msgs])
|
||||
for name, count in c.items():
|
||||
if count > 1:
|
||||
sys.exit("%s: Duplicate message name in DBC file %s" % (dbc_name, name))
|
||||
|
||||
parser_code = template.render(dbc=can_dbc, checksum_type=checksum_type, msgs=msgs, def_vals=def_vals, len=len)
|
||||
|
||||
with open(out_fn, "w") as out_f:
|
||||
out_f.write(parser_code)
|
||||
|
||||
def main():
|
||||
if len(sys.argv) != 3:
|
||||
print("usage: %s dbc_directory output_filename" % (sys.argv[0],))
|
||||
sys.exit(0)
|
||||
|
||||
dbc_dir = sys.argv[1]
|
||||
out_fn = sys.argv[2]
|
||||
|
||||
dbc_name = os.path.split(out_fn)[-1].replace('.cc', '')
|
||||
in_fn = os.path.join(dbc_dir, dbc_name + '.dbc')
|
||||
|
||||
process(in_fn, out_fn)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user