diff --git a/.gitignore b/.gitignore index 46053e926d200a..4f6f8212e9dd54 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,6 @@ openpilot notebooks xx +.coverage* +htmlcov + diff --git a/Pipfile b/Pipfile index 4519727b9ae18a..888275b2d18ca9 100644 --- a/Pipfile +++ b/Pipfile @@ -7,6 +7,7 @@ verify_ssl = true opencv-python= "==3.4.2.17" PyQt5 = "*" ipython = "*" +networkx = "*" azure-common = "*" azure-nspkg = "*" azure-storage-blob = "*" @@ -99,6 +100,7 @@ gast = "==0.2.2" matplotlib = "*" dictdiffer = "*" aenum = "*" +coverage = "*" [packages] overpy = {git = "https://github.com/commaai/python-overpy.git",ref = "f86529af402d4642e1faeb146671c40284007323"} @@ -135,7 +137,7 @@ Flask = "*" PyJWT = "*" "Jinja2" = "*" nose = "*" -pyflakes = "*" +flake8 = "*" pylint = "*" pycryptodome = "*" pillow = "*" diff --git a/Pipfile.lock b/Pipfile.lock index 0d410dcaea9a6b..c99cbdfa5b71ef 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "b684c418bc2eb803f0d3e173e0c9b2776eedd27c51d80b6fe58cf7588f35563d" + "sha256": "5bcd9143fb723dcf4cbecdc3fa38c325e706d67073dab42fb3d966619ee591df" }, "pipfile-spec": 6, "requires": { @@ -16,20 +16,13 @@ ] }, "default": { - "asn1crypto": { - "hashes": [ - "sha256:d02bf8ea1b964a5ff04ac7891fe3a39150045d1e5e4fe99273ba677d11b92a04", - "sha256:f822954b90c4c44f002e2cd46d636ab630f1fe4df22c816a82b66505c404eb2a" - ], - "version": "==1.0.0" - }, "astroid": { "hashes": [ - "sha256:98c665ad84d10b18318c5ab7c3d203fe11714cbad2a4aef4f44651f415392754", - "sha256:b7546ffdedbf7abcfbff93cd1de9e9980b1ef744852689decc5aeada324238c6" + "sha256:09a3fba616519311f1af8a461f804b68f0370e100c9264a035aa7846d7852e33", + "sha256:5a79c9b4bd6c4be777424593f957c996e20beb5f74e0bc332f47713c6f675efe" ], "markers": "python_version >= '3.5'", - "version": "==2.3.1" + "version": "==2.3.2" }, "atomicwrites": { "hashes": [ @@ -48,37 +41,39 @@ }, "cffi": { "hashes": [ - "sha256:041c81822e9f84b1d9c401182e174996f0bae9991f33725d059b771744290774", - "sha256:046ef9a22f5d3eed06334d01b1e836977eeef500d9b78e9ef693f9380ad0b83d", - "sha256:066bc4c7895c91812eff46f4b1c285220947d4aa46fa0a2651ff85f2afae9c90", - "sha256:066c7ff148ae33040c01058662d6752fd73fbc8e64787229ea8498c7d7f4041b", - "sha256:2444d0c61f03dcd26dbf7600cf64354376ee579acad77aef459e34efcb438c63", - "sha256:300832850b8f7967e278870c5d51e3819b9aad8f0a2c8dbe39ab11f119237f45", - "sha256:34c77afe85b6b9e967bd8154e3855e847b70ca42043db6ad17f26899a3df1b25", - "sha256:46de5fa00f7ac09f020729148ff632819649b3e05a007d286242c4882f7b1dc3", - "sha256:4aa8ee7ba27c472d429b980c51e714a24f47ca296d53f4d7868075b175866f4b", - "sha256:4d0004eb4351e35ed950c14c11e734182591465a33e960a4ab5e8d4f04d72647", - "sha256:4e3d3f31a1e202b0f5a35ba3bc4eb41e2fc2b11c1eff38b362de710bcffb5016", - "sha256:50bec6d35e6b1aaeb17f7c4e2b9374ebf95a8975d57863546fa83e8d31bdb8c4", - "sha256:55cad9a6df1e2a1d62063f79d0881a414a906a6962bc160ac968cc03ed3efcfb", - "sha256:5662ad4e4e84f1eaa8efce5da695c5d2e229c563f9d5ce5b0113f71321bcf753", - "sha256:59b4dc008f98fc6ee2bb4fd7fc786a8d70000d058c2bbe2698275bc53a8d3fa7", - "sha256:73e1ffefe05e4ccd7bcea61af76f36077b914f92b76f95ccf00b0c1b9186f3f9", - "sha256:a1f0fd46eba2d71ce1589f7e50a9e2ffaeb739fb2c11e8192aa2b45d5f6cc41f", - "sha256:a2e85dc204556657661051ff4bab75a84e968669765c8a2cd425918699c3d0e8", - "sha256:a5457d47dfff24882a21492e5815f891c0ca35fefae8aa742c6c263dac16ef1f", - "sha256:a8dccd61d52a8dae4a825cdbb7735da530179fea472903eb871a5513b5abbfdc", - "sha256:ae61af521ed676cf16ae94f30fe202781a38d7178b6b4ab622e4eec8cefaff42", - "sha256:b012a5edb48288f77a63dba0840c92d0504aa215612da4541b7b42d849bc83a3", - "sha256:d2c5cfa536227f57f97c92ac30c8109688ace8fa4ac086d19d0af47d134e2909", - "sha256:d42b5796e20aacc9d15e66befb7a345454eef794fdb0737d1af593447c6c8f45", - "sha256:dee54f5d30d775f525894d67b1495625dd9322945e7fee00731952e0368ff42d", - "sha256:e070535507bd6aa07124258171be2ee8dfc19119c28ca94c9dfb7efd23564512", - "sha256:e1ff2748c84d97b065cc95429814cdba39bcbd77c9c85c89344b317dc0d9cbff", - "sha256:ed851c75d1e0e043cbf5ca9a8e1b13c4c90f3fbd863dacb01c0808e2b5204201" - ], - "index": "pypi", - "version": "==1.12.3" + "sha256:00d890313797d9fe4420506613384b43099ad7d2b905c0752dbcc3a6f14d80fa", + "sha256:0cf9e550ac6c5e57b713437e2f4ac2d7fd0cd10336525a27224f5fc1ec2ee59a", + "sha256:0ea23c9c0cdd6778146a50d867d6405693ac3b80a68829966c98dd5e1bbae400", + "sha256:193697c2918ecdb3865acf6557cddf5076bb39f1f654975e087b67efdff83365", + "sha256:1ae14b542bf3b35e5229439c35653d2ef7d8316c1fffb980f9b7647e544baa98", + "sha256:1e389e069450609c6ffa37f21f40cce36f9be7643bbe5051ab1de99d5a779526", + "sha256:263242b6ace7f9cd4ea401428d2d45066b49a700852334fd55311bde36dcda14", + "sha256:33142ae9807665fa6511cfa9857132b2c3ee6ddffb012b3f0933fc11e1e830d5", + "sha256:364f8404034ae1b232335d8c7f7b57deac566f148f7222cef78cf8ae28ef764e", + "sha256:47368f69fe6529f8f49a5d146ddee713fc9057e31d61e8b6dc86a6a5e38cecc1", + "sha256:4895640844f17bec32943995dc8c96989226974dfeb9dd121cc45d36e0d0c434", + "sha256:558b3afef987cf4b17abd849e7bedf64ee12b28175d564d05b628a0f9355599b", + "sha256:5ba86e1d80d458b338bda676fd9f9d68cb4e7a03819632969cf6d46b01a26730", + "sha256:63424daa6955e6b4c70dc2755897f5be1d719eabe71b2625948b222775ed5c43", + "sha256:6381a7d8b1ebd0bc27c3bc85bc1bfadbb6e6f756b4d4db0aa1425c3719ba26b4", + "sha256:6381ab708158c4e1639da1f2a7679a9bbe3e5a776fc6d1fd808076f0e3145331", + "sha256:6fd58366747debfa5e6163ada468a90788411f10c92597d3b0a912d07e580c36", + "sha256:728ec653964655d65408949b07f9b2219df78badd601d6c49e28d604efe40599", + "sha256:7cfcfda59ef1f95b9f729c56fe8a4041899f96b72685d36ef16a3440a0f85da8", + "sha256:819f8d5197c2684524637f940445c06e003c4a541f9983fd30d6deaa2a5487d8", + "sha256:825ecffd9574557590e3225560a8a9d751f6ffe4a49e3c40918c9969b93395fa", + "sha256:9009e917d8f5ef780c2626e29b6bc126f4cb2a4d43ca67aa2b40f2a5d6385e78", + "sha256:9c77564a51d4d914ed5af096cd9843d90c45b784b511723bd46a8a9d09cf16fc", + "sha256:a19089fa74ed19c4fe96502a291cfdb89223a9705b1d73b3005df4256976142e", + "sha256:a40ed527bffa2b7ebe07acc5a3f782da072e262ca994b4f2085100b5a444bbb2", + "sha256:bb75ba21d5716abc41af16eac1145ab2e471deedde1f22c6f99bd9f995504df0", + "sha256:e22a00c0c81ffcecaf07c2bfb3672fa372c50e2bd1024ffee0da191c1b27fc71", + "sha256:e55b5a746fb77f10c83e8af081979351722f6ea48facea79d470b3731c7b2891", + "sha256:ec2fa3ee81707a5232bf2dfbd6623fdb278e070d596effc7e2d788f2ada71a05", + "sha256:fd82eb4694be712fcae03c717ca2e0fc720657ac226b80bbb597e971fc6928c2" + ], + "index": "pypi", + "version": "==1.13.1" }, "chardet": { "hashes": [ @@ -108,25 +103,30 @@ }, "cryptography": { "hashes": [ - "sha256:24b61e5fcb506424d3ec4e18bca995833839bf13c59fc43e530e488f28d46b8c", - "sha256:25dd1581a183e9e7a806fe0543f485103232f940fcfc301db65e630512cce643", - "sha256:3452bba7c21c69f2df772762be0066c7ed5dc65df494a1d53a58b683a83e1216", - "sha256:41a0be220dd1ed9e998f5891948306eb8c812b512dc398e5a01846d855050799", - "sha256:5751d8a11b956fbfa314f6553d186b94aa70fdb03d8a4d4f1c82dcacf0cbe28a", - "sha256:5f61c7d749048fa6e3322258b4263463bfccefecb0dd731b6561cb617a1d9bb9", - "sha256:72e24c521fa2106f19623a3851e9f89ddfdeb9ac63871c7643790f872a305dfc", - "sha256:7b97ae6ef5cba2e3bb14256625423413d5ce8d1abb91d4f29b6d1a081da765f8", - "sha256:961e886d8a3590fd2c723cf07be14e2a91cf53c25f02435c04d39e90780e3b53", - "sha256:96d8473848e984184b6728e2c9d391482008646276c3ff084a1bd89e15ff53a1", - "sha256:ae536da50c7ad1e002c3eee101871d93abdc90d9c5f651818450a0d3af718609", - "sha256:b0db0cecf396033abb4a93c95d1602f268b3a68bb0a9cc06a7cff587bb9a7292", - "sha256:cfee9164954c186b191b91d4193989ca994703b2fff406f71cf454a2d3c7327e", - "sha256:e6347742ac8f35ded4a46ff835c60e68c22a536a8ae5c4422966d06946b6d4c6", - "sha256:f27d93f0139a3c056172ebb5d4f9056e770fdf0206c2f422ff2ebbad142e09ed", - "sha256:f57b76e46a58b63d1c6375017f4564a28f19a5ca912691fd2e4261b3414b618d" - ], - "index": "pypi", - "version": "==2.7" + "sha256:02079a6addc7b5140ba0825f542c0869ff4df9a69c360e339ecead5baefa843c", + "sha256:1df22371fbf2004c6f64e927668734070a8953362cd8370ddd336774d6743595", + "sha256:369d2346db5934345787451504853ad9d342d7f721ae82d098083e1f49a582ad", + "sha256:3cda1f0ed8747339bbdf71b9f38ca74c7b592f24f65cdb3ab3765e4b02871651", + "sha256:44ff04138935882fef7c686878e1c8fd80a723161ad6a98da31e14b7553170c2", + "sha256:4b1030728872c59687badcca1e225a9103440e467c17d6d1730ab3d2d64bfeff", + "sha256:58363dbd966afb4f89b3b11dfb8ff200058fbc3b947507675c19ceb46104b48d", + "sha256:6ec280fb24d27e3d97aa731e16207d58bd8ae94ef6eab97249a2afe4ba643d42", + "sha256:7270a6c29199adc1297776937a05b59720e8a782531f1f122f2eb8467f9aab4d", + "sha256:73fd30c57fa2d0a1d7a49c561c40c2f79c7d6c374cc7750e9ac7c99176f6428e", + "sha256:7f09806ed4fbea8f51585231ba742b58cbcfbfe823ea197d8c89a5e433c7e912", + "sha256:90df0cc93e1f8d2fba8365fb59a858f51a11a394d64dbf3ef844f783844cc793", + "sha256:971221ed40f058f5662a604bd1ae6e4521d84e6cad0b7b170564cc34169c8f13", + "sha256:a518c153a2b5ed6b8cc03f7ae79d5ffad7315ad4569b2d5333a13c38d64bd8d7", + "sha256:b0de590a8b0979649ebeef8bb9f54394d3a41f66c5584fff4220901739b6b2f0", + "sha256:b43f53f29816ba1db8525f006fa6f49292e9b029554b3eb56a189a70f2a40879", + "sha256:d31402aad60ed889c7e57934a03477b572a03af7794fa8fb1780f21ea8f6551f", + "sha256:de96157ec73458a7f14e3d26f17f8128c959084931e8997b9e655a39c8fde9f9", + "sha256:df6b4dca2e11865e6cfbfb708e800efb18370f5a46fd601d3755bc7f85b3a8a2", + "sha256:ecadccc7ba52193963c0475ac9f6fa28ac01e01349a2ca48509667ef41ffd2cf", + "sha256:fb81c17e0ebe3358486cd8cc3ad78adbae58af12fc2bf2bc0bb84e8090fa5ce8" + ], + "index": "pypi", + "version": "==2.8" }, "cython": { "hashes": [ @@ -162,6 +162,22 @@ "index": "pypi", "version": "==0.29.13" }, + "entrypoints": { + "hashes": [ + "sha256:589f874b313739ad35be6e0cd7efde2a4e9b6fea91edcc34e58ecbb8dbe56d19", + "sha256:c70dd71abe5a8c85e55e12c19bd91ccfeec11a6e99044204511f9ed547d48451" + ], + "markers": "python_version >= '2.7'", + "version": "==0.3" + }, + "flake8": { + "hashes": [ + "sha256:19241c1cbc971b9962473e4438a2ca19749a7dd002dd1a946eaba171b4114548", + "sha256:8e9dfa3cecb2400b3738a42c54c3043e821682b9c840b0448c0503f781130696" + ], + "index": "pypi", + "version": "==3.7.8" + }, "flask": { "hashes": [ "sha256:13f9f196f330c7c2c5d7a5cf91af894110ca0215ac051b5844701f2bfd934d52", @@ -211,11 +227,11 @@ }, "jinja2": { "hashes": [ - "sha256:065c4f02ebe7f7cf559e49ee5a95fb800a9e4528727aec6f24402a5374c65013", - "sha256:14dd6caf1527abb21f08f86c784eac40853ba93edb79552aa1e4b8aef1b61c7b" + "sha256:74320bb91f31270f9551d46522e33af46a80c3d619f4a4bf42b3164d30b5911f", + "sha256:9fe95f19286cfefaa917656583d020be14e7859c6b0252588391e47db34527de" ], "index": "pypi", - "version": "==2.10.1" + "version": "==2.10.3" }, "json-rpc": { "hashes": [ @@ -319,25 +335,30 @@ }, "numpy": { "hashes": [ - "sha256:05dbfe72684cc14b92568de1bc1f41e5f62b00f714afc9adee42f6311738091f", - "sha256:0d82cb7271a577529d07bbb05cb58675f2deb09772175fab96dc8de025d8ac05", - "sha256:10132aa1fef99adc85a905d82e8497a580f83739837d7cbd234649f2e9b9dc58", - "sha256:12322df2e21f033a60c80319c25011194cd2a21294cc66fee0908aeae2c27832", - "sha256:16f19b3aa775dddc9814e02a46b8e6ae6a54ed8cf143962b4e53f0471dbd7b16", - "sha256:3d0b0989dd2d066db006158de7220802899a1e5c8cf622abe2d0bd158fd01c2c", - "sha256:438a3f0e7b681642898fd7993d38e2bf140a2d1eafaf3e89bb626db7f50db355", - "sha256:5fd214f482ab53f2cea57414c5fb3e58895b17df6e6f5bca5be6a0bb6aea23bb", - "sha256:73615d3edc84dd7c4aeb212fa3748fb83217e00d201875a47327f55363cef2df", - "sha256:7bd355ad7496f4ce1d235e9814ec81ee3d28308d591c067ce92e49f745ba2c2f", - "sha256:7d077f2976b8f3de08a0dcf5d72083f4af5411e8fddacd662aae27baa2601196", - "sha256:a4092682778dc48093e8bda8d26ee8360153e2047826f95a3f5eae09f0ae3abf", - "sha256:b458de8624c9f6034af492372eb2fee41a8e605f03f4732f43fc099e227858b2", - "sha256:e70fc8ff03a961f13363c2c95ef8285e0cf6a720f8271836f852cc0fa64e97c8", - "sha256:ee8e9d7cad5fe6dde50ede0d2e978d81eafeaa6233fb0b8719f60214cf226578", - "sha256:f4a4f6aba148858a5a5d546a99280f71f5ee6ec8182a7d195af1a914195b21a2" - ], - "index": "pypi", - "version": "==1.17.2" + "sha256:0b0dd8f47fb177d00fa6ef2d58783c4f41ad3126b139c91dd2f7c4b3fdf5e9a5", + "sha256:25ffe71f96878e1da7e014467e19e7db90ae7d4e12affbc73101bcf61785214e", + "sha256:26efd7f7d755e6ca966a5c0ac5a930a87dbbaab1c51716ac26a38f42ecc9bc4b", + "sha256:28b1180c758abf34a5c3fea76fcee66a87def1656724c42bb14a6f9717a5bdf7", + "sha256:2e418f0a59473dac424f888dd57e85f77502a593b207809211c76e5396ae4f5c", + "sha256:30c84e3a62cfcb9e3066f25226e131451312a044f1fe2040e69ce792cb7de418", + "sha256:4650d94bb9c947151737ee022b934b7d9a845a7c76e476f3e460f09a0c8c6f39", + "sha256:4dd830a11e8724c9c9379feed1d1be43113f8bcce55f47ea7186d3946769ce26", + "sha256:4f2a2b279efde194877aff1f76cf61c68e840db242a5c7169f1ff0fd59a2b1e2", + "sha256:62d22566b3e3428dfc9ec972014c38ed9a4db4f8969c78f5414012ccd80a149e", + "sha256:669795516d62f38845c7033679c648903200980d68935baaa17ac5c7ae03ae0c", + "sha256:75fcd60d682db3e1f8fbe2b8b0c6761937ad56d01c1dc73edf4ef2748d5b6bc4", + "sha256:9395b0a41e8b7e9a284e3be7060db9d14ad80273841c952c83a5afc241d2bd98", + "sha256:9e37c35fc4e9410093b04a77d11a34c64bf658565e30df7cbe882056088a91c1", + "sha256:a0678793096205a4d784bd99f32803ba8100f639cf3b932dc63b21621390ea7e", + "sha256:b46554ad4dafb2927f88de5a1d207398c5385edbb5c84d30b3ef187c4a3894d8", + "sha256:c867eeccd934920a800f65c6068acdd6b87e80d45cd8c8beefff783b23cdc462", + "sha256:dd0667f5be56fb1b570154c2c0516a528e02d50da121bbbb2cbb0b6f87f59bc2", + "sha256:de2b1c20494bdf47f0160bd88ed05f5e48ae5dc336b8de7cfade71abcc95c0b9", + "sha256:f1df7b2b7740dd777571c732f98adb5aad5450aee32772f1b39249c8a50386f6", + "sha256:ffca69e29079f7880c5392bf675eb8b4146479d976ae1924d01cd92b04cccbcc" + ], + "index": "pypi", + "version": "==1.17.3" }, "overpy": { "git": "https://github.com/commaai/python-overpy.git", @@ -346,39 +367,44 @@ }, "pillow": { "hashes": [ - "sha256:00fdeb23820f30e43bba78eb9abb00b7a937a655de7760b2e09101d63708b64e", - "sha256:01f948e8220c85eae1aa1a7f8edddcec193918f933fb07aaebe0bfbbcffefbf1", - "sha256:08abf39948d4b5017a137be58f1a52b7101700431f0777bec3d897c3949f74e6", - "sha256:099a61618b145ecb50c6f279666bbc398e189b8bc97544ae32b8fcb49ad6b830", - "sha256:2c1c61546e73de62747e65807d2cc4980c395d4c5600ecb1f47a650c6fa78c79", - "sha256:2ed9c4f694861642401f27dc3cb99772be67cd190e84845c749dae0a06c3bfae", - "sha256:338581b30b908e111be578f0297255f6b57a51358cd16fa0e6f664c9a1f88bff", - "sha256:38c7d48a21cd06fdeee93987147b9b1c55b73b4cfcbf83240568bfbd5adee447", - "sha256:43fd026f613c8e48a25eba1a92f4d2ad7f3903c95d8c33a11611a7717d2ab654", - "sha256:4548236844327a718ce3bb182ab32a16fa2050c61e334e959f554cac052fb0df", - "sha256:5090857876c58885cfa388dc649e5db30aae98a068c26f3fd0ac9d7d9a4d9572", - "sha256:5bbba34f97a26a93f5e8dec469ca4ddd712451418add43da946dbaed7f7a98d2", - "sha256:65a28969a025a0eb4594637b6103201dc4ed2a9508bdab56ac33e43e3081c404", - "sha256:892bb52b70bd5ea9dbbc3ac44f38e84f5a04e9d8b1bff48159d96cb795b81159", - "sha256:8a9becd5cbd5062f973bcd2e7bc79483af310222de112b6541f8af1f93a3cc42", - "sha256:972a7aaeb7c4a2795b52eef52ee991ef040b31009f36deca6207a986607b55f3", - "sha256:97b119c436bfa96a92ac2ca525f7025836d4d4e64b1c9f9eff8dbaf3ff1d86f3", - "sha256:9ba37698e242223f8053cc158f130aee046a96feacbeab65893dbe94f5530118", - "sha256:b1b0e1f626a0f079c0d3696db70132fb1f29aa87c66aecb6501a9b8be64ce9f7", - "sha256:c14c1224fd1a5be2733530d648a316974dbbb3c946913562c6005a76f21ca042", - "sha256:c79a8546c48ae6465189e54e3245a97ddf21161e33ff7eaa42787353417bb2b6", - "sha256:ceb76935ac4ebdf6d7bc845482a4450b284c6ccfb281e34da51d510658ab34d8", - "sha256:e22bffaad04b4d16e1c091baed7f2733fc1ebb91e0c602abf1b6834d17158b1f", - "sha256:ec883b8e44d877bda6f94a36313a1c6063f8b1997aa091628ae2f34c7f97c8d5", - "sha256:f1baa54d50ec031d1a9beb89974108f8f2c0706f49798f4777df879df0e1adb6", - "sha256:f53a5385932cda1e2c862d89460992911a89768c65d176ff8c50cddca4d29bed" - ], - "index": "pypi", - "version": "==6.2.0" + "sha256:047d9473cf68af50ac85f8ee5d5f21a60f849bc17d348da7fc85711287a75031", + "sha256:0f66dc6c8a3cc319561a633b6aa82c44107f12594643efa37210d8c924fc1c71", + "sha256:12c9169c4e8fe0a7329e8658c7e488001f6b4c8e88740e76292c2b857af2e94c", + "sha256:248cffc168896982f125f5c13e9317c059f74fffdb4152893339f3be62a01340", + "sha256:27faf0552bf8c260a5cee21a76e031acaea68babb64daf7e8f2e2540745082aa", + "sha256:285edafad9bc60d96978ed24d77cdc0b91dace88e5da8c548ba5937c425bca8b", + "sha256:384b12c9aa8ef95558abdcb50aada56d74bc7cc131dd62d28c2d0e4d3aadd573", + "sha256:38950b3a707f6cef09cd3cbb142474357ad1a985ceb44d921bdf7b4647b3e13e", + "sha256:4aad1b88933fd6dc2846552b89ad0c74ddbba2f0884e2c162aa368374bf5abab", + "sha256:4ac6148008c169603070c092e81f88738f1a0c511e07bd2bb0f9ef542d375da9", + "sha256:4deb1d2a45861ae6f0b12ea0a786a03d19d29edcc7e05775b85ec2877cb54c5e", + "sha256:59aa2c124df72cc75ed72c8d6005c442d4685691a30c55321e00ed915ad1a291", + "sha256:5a47d2123a9ec86660fe0e8d0ebf0aa6bc6a17edc63f338b73ea20ba11713f12", + "sha256:5cc901c2ab9409b4b7ac7b5bcc3e86ac14548627062463da0af3b6b7c555a871", + "sha256:6c1db03e8dff7b9f955a0fb9907eb9ca5da75b5ce056c0c93d33100a35050281", + "sha256:7ce80c0a65a6ea90ef9c1f63c8593fcd2929448613fc8da0adf3e6bfad669d08", + "sha256:809c19241c14433c5d6135e1b6c72da4e3b56d5c865ad5736ab99af8896b8f41", + "sha256:83792cb4e0b5af480588601467c0764242b9a483caea71ef12d22a0d0d6bdce2", + "sha256:846fa202bd7ee0f6215c897a1d33238ef071b50766339186687bd9b7a6d26ac5", + "sha256:9f5529fc02009f96ba95bea48870173426879dc19eec49ca8e08cd63ecd82ddb", + "sha256:a423c2ea001c6265ed28700df056f75e26215fd28c001e93ef4380b0f05f9547", + "sha256:ac4428094b42907aba5879c7c000d01c8278d451a3b7cccd2103e21f6397ea75", + "sha256:b1ae48d87f10d1384e5beecd169c77502fcc04a2c00a4c02b85f0a94b419e5f9", + "sha256:bf4e972a88f8841d8fdc6db1a75e0f8d763e66e3754b03006cbc3854d89f1cb1", + "sha256:c6414f6aad598364aaf81068cabb077894eb88fed99c6a65e6e8217bab62ae7a", + "sha256:c710fcb7ee32f67baf25aa9ffede4795fd5d93b163ce95fdc724383e38c9df96", + "sha256:c7be4b8a09852291c3c48d3c25d1b876d2494a0a674980089ac9d5e0d78bd132", + "sha256:c9e5ffb910b14f090ac9c38599063e354887a5f6d7e6d26795e916b4514f2c1a", + "sha256:e0697b826da6c2472bb6488db4c0a7fa8af0d52fa08833ceb3681358914b14e5", + "sha256:e9a3edd5f714229d41057d56ac0f39ad9bdba6767e8c888c951869f0bdd129b0" + ], + "index": "pypi", + "version": "==6.2.1" }, "psutil": { "hashes": [ "sha256:028a1ec3c6197eadd11e7b46e8cc2f0720dc18ac6d7aabdb8e8c0d6c9704f000", + "sha256:12542c3642909f4cd1928a2fba59e16fa27e47cbeea60928ebb62a8cbd1ce123", "sha256:503e4b20fa9d3342bcf58191bbc20a4a5ef79ca7df8972e6197cc14c5513e73d", "sha256:863a85c1c0a5103a12c05a35e59d336e1d665747e531256e061213e2e90f63f3", "sha256:954f782608bfef9ae9f78e660e065bd8ffcfaea780f9f2c8a133bb7cb9e826d7", @@ -398,6 +424,14 @@ "index": "pypi", "version": "==0.6.4" }, + "pycodestyle": { + "hashes": [ + "sha256:95a2219d12372f05704562a14ec30bc76b05a5b297b21a5dfe3f6fac3491ae56", + "sha256:e40a936c9a450ad81df37f549d676d127b1b66000a6c500caa2b085bc0ca976c" + ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "version": "==2.5.0" + }, "pycparser": { "hashes": [ "sha256:a988718abfad80b6b157acce7bf130a30876d27603738ac39f140993246b25b3" @@ -443,7 +477,7 @@ "sha256:17dbeb2e3f4d772725c777fabc446d5634d1038f234e77343108ce445ea69ce0", "sha256:d976835886f8c5b31d47970ed689944a0262b5f3afa00a5a7b4dc81e5449f8a2" ], - "index": "pypi", + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==2.1.1" }, "pyjwt": { @@ -456,11 +490,11 @@ }, "pylint": { "hashes": [ - "sha256:7edbae11476c2182708063ac387a8f97c760d9cfe36a5ede0ca996f90cf346c8", - "sha256:844ce067788028c1a35086a5c66bc5e599ddd851841c41d6ee1623b36774d9f2" + "sha256:7b76045426c650d2b0f02fc47c14d7934d17898779da95288a74c2a7ec440702", + "sha256:856476331f3e26598017290fd65bebe81c960e806776f324093a46b76fb2d1c0" ], "index": "pypi", - "version": "==2.4.2" + "version": "==2.4.3" }, "pyserial": { "hashes": [ @@ -585,20 +619,25 @@ }, "typed-ast": { "hashes": [ + "sha256:1170afa46a3799e18b4c977777ce137bb53c7485379d9706af8a59f2ea1aa161", "sha256:18511a0b3e7922276346bcb47e2ef9f38fb90fd31cb9223eed42c85d1312344e", "sha256:262c247a82d005e43b5b7f69aff746370538e176131c32dda9cb0f324d27141e", "sha256:2b907eb046d049bcd9892e3076c7a6456c93a25bebfe554e931620c90e6a25b0", "sha256:354c16e5babd09f5cb0ee000d54cfa38401d8b8891eefa878ac772f827181a3c", + "sha256:48e5b1e71f25cfdef98b013263a88d7145879fbb2d5185f2a0c79fa7ebbeae47", "sha256:4e0b70c6fc4d010f8107726af5fd37921b666f5b31d9331f0bd24ad9a088e631", "sha256:630968c5cdee51a11c05a30453f8cd65e0cc1d2ad0d9192819df9978984529f4", "sha256:66480f95b8167c9c5c5c87f32cf437d585937970f3fc24386f313a4c97b44e34", "sha256:71211d26ffd12d63a83e079ff258ac9d56a1376a25bc80b1cdcdf601b855b90b", + "sha256:7954560051331d003b4e2b3eb822d9dd2e376fa4f6d98fee32f452f52dd6ebb2", + "sha256:838997f4310012cf2e1ad3803bce2f3402e9ffb71ded61b5ee22617b3a7f6b6e", "sha256:95bd11af7eafc16e829af2d3df510cecfd4387f6453355188342c3e79a2ec87a", "sha256:bc6c7d3fa1325a0c6613512a093bc2a2a15aeec350451cbdf9e1d4bffe3e3233", "sha256:cc34a6f5b426748a507dd5d1de4c1978f2eb5626d51326e43280941206c209e1", "sha256:d755f03c1e4a51e9b24d899561fec4ccaf51f210d52abdf8c07ee2849b212a36", "sha256:d7c45933b1bdfaf9f36c579671fec15d25b06c8398f113dab64c18ed1adda01d", "sha256:d896919306dd0aa22d0132f62a1b78d11aaf4c9fc5b3410d3c666b818191630a", + "sha256:fdc1c9bbf79510b76408840e009ed65958feba92a88833cdceecff93ae8fff66", "sha256:ffde2fbfad571af120fcbfbbc61c72469e72f550d676c3342492a9dfdefb8f12" ], "markers": "python_version < '3.8' and implementation_name == 'cpython'", @@ -645,9 +684,9 @@ "develop": { "absl-py": { "hashes": [ - "sha256:0ce45920056fbbb66f52fcee7408ba6311da19f55589b2b3aab9f8af92a0e1f2" + "sha256:d9129186431e150d7fe455f1cb1ecbb92bb5dba9da9bc3ef7b012d98c4db2526" ], - "version": "==0.8.0" + "version": "==0.8.1" }, "aenum": { "hashes": [ @@ -666,13 +705,6 @@ "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==2.5.1" }, - "asn1crypto": { - "hashes": [ - "sha256:d02bf8ea1b964a5ff04ac7891fe3a39150045d1e5e4fe99273ba677d11b92a04", - "sha256:f822954b90c4c44f002e2cd46d636ab630f1fe4df22c816a82b66505c404eb2a" - ], - "version": "==1.0.0" - }, "astor": { "hashes": [ "sha256:0e41295809baf43ae8303350e031aff81ae52189b6f881f36d623fa8b2f1960e", @@ -683,19 +715,19 @@ }, "astroid": { "hashes": [ - "sha256:98c665ad84d10b18318c5ab7c3d203fe11714cbad2a4aef4f44651f415392754", - "sha256:b7546ffdedbf7abcfbff93cd1de9e9980b1ef744852689decc5aeada324238c6" + "sha256:09a3fba616519311f1af8a461f804b68f0370e100c9264a035aa7846d7852e33", + "sha256:5a79c9b4bd6c4be777424593f957c996e20beb5f74e0bc332f47713c6f675efe" ], "markers": "python_version >= '3.5'", - "version": "==2.3.1" + "version": "==2.3.2" }, "attrs": { "hashes": [ - "sha256:ec20e7a4825331c1b5ebf261d111e16fa9612c1f7a5e1f884f12bd53a664dfd2", - "sha256:f913492e1663d3c36f502e5e9ba6cd13cf19d7fab50aa13239e420fef95e1396" + "sha256:08a96c641c3a74e44eb59afb61a24f2cb9f4d7188748e76ba4bb5edfa3cb7d1c", + "sha256:f7b7ce16570fe9965acd6d30101a28f62fb4a7f9e926b3bbc9b61f8b04247e72" ], "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==19.2.0" + "version": "==19.3.0" }, "azure-common": { "hashes": [ @@ -800,18 +832,18 @@ }, "boto3": { "hashes": [ - "sha256:4189e1ffed768bd0efd754a0abedebce19495ba2aa6b2f5e20f29ba80f81f9cb", - "sha256:fa4e28166922feeb9b7b56134c1acc817a1bca36284a0035bc08a3dab1853a9f" + "sha256:7fc97cb2c9cdff905e950750c8e8b23b872a84696158a28852355dc4b712ba3a", + "sha256:818c56a317c176142dbf1dca3f5b4366c80460c6cc3c4efe22f0bde736571283" ], "index": "pypi", - "version": "==1.9.242" + "version": "==1.10.2" }, "botocore": { "hashes": [ - "sha256:7af52e0aabaf4ba045e1a5832308e70e1ea4b499b71624857f09aed2ba5e667c", - "sha256:dd62d63bcd3176c92775c52d3e879288f89bf0ac0039df14ea31f25d693acd6d" + "sha256:8223485841ef4731a5d4943a733295ba69d0005c4ae64c468308cc07f6960d39", + "sha256:f8e12dc6e536ea512f0ad25b74e7eecdf5d9e09ae92b5de236b535bee7804d5b" ], - "version": "==1.12.242" + "version": "==1.13.2" }, "celery": { "hashes": [ @@ -830,37 +862,39 @@ }, "cffi": { "hashes": [ - "sha256:041c81822e9f84b1d9c401182e174996f0bae9991f33725d059b771744290774", - "sha256:046ef9a22f5d3eed06334d01b1e836977eeef500d9b78e9ef693f9380ad0b83d", - "sha256:066bc4c7895c91812eff46f4b1c285220947d4aa46fa0a2651ff85f2afae9c90", - "sha256:066c7ff148ae33040c01058662d6752fd73fbc8e64787229ea8498c7d7f4041b", - "sha256:2444d0c61f03dcd26dbf7600cf64354376ee579acad77aef459e34efcb438c63", - "sha256:300832850b8f7967e278870c5d51e3819b9aad8f0a2c8dbe39ab11f119237f45", - "sha256:34c77afe85b6b9e967bd8154e3855e847b70ca42043db6ad17f26899a3df1b25", - "sha256:46de5fa00f7ac09f020729148ff632819649b3e05a007d286242c4882f7b1dc3", - "sha256:4aa8ee7ba27c472d429b980c51e714a24f47ca296d53f4d7868075b175866f4b", - "sha256:4d0004eb4351e35ed950c14c11e734182591465a33e960a4ab5e8d4f04d72647", - "sha256:4e3d3f31a1e202b0f5a35ba3bc4eb41e2fc2b11c1eff38b362de710bcffb5016", - "sha256:50bec6d35e6b1aaeb17f7c4e2b9374ebf95a8975d57863546fa83e8d31bdb8c4", - "sha256:55cad9a6df1e2a1d62063f79d0881a414a906a6962bc160ac968cc03ed3efcfb", - "sha256:5662ad4e4e84f1eaa8efce5da695c5d2e229c563f9d5ce5b0113f71321bcf753", - "sha256:59b4dc008f98fc6ee2bb4fd7fc786a8d70000d058c2bbe2698275bc53a8d3fa7", - "sha256:73e1ffefe05e4ccd7bcea61af76f36077b914f92b76f95ccf00b0c1b9186f3f9", - "sha256:a1f0fd46eba2d71ce1589f7e50a9e2ffaeb739fb2c11e8192aa2b45d5f6cc41f", - "sha256:a2e85dc204556657661051ff4bab75a84e968669765c8a2cd425918699c3d0e8", - "sha256:a5457d47dfff24882a21492e5815f891c0ca35fefae8aa742c6c263dac16ef1f", - "sha256:a8dccd61d52a8dae4a825cdbb7735da530179fea472903eb871a5513b5abbfdc", - "sha256:ae61af521ed676cf16ae94f30fe202781a38d7178b6b4ab622e4eec8cefaff42", - "sha256:b012a5edb48288f77a63dba0840c92d0504aa215612da4541b7b42d849bc83a3", - "sha256:d2c5cfa536227f57f97c92ac30c8109688ace8fa4ac086d19d0af47d134e2909", - "sha256:d42b5796e20aacc9d15e66befb7a345454eef794fdb0737d1af593447c6c8f45", - "sha256:dee54f5d30d775f525894d67b1495625dd9322945e7fee00731952e0368ff42d", - "sha256:e070535507bd6aa07124258171be2ee8dfc19119c28ca94c9dfb7efd23564512", - "sha256:e1ff2748c84d97b065cc95429814cdba39bcbd77c9c85c89344b317dc0d9cbff", - "sha256:ed851c75d1e0e043cbf5ca9a8e1b13c4c90f3fbd863dacb01c0808e2b5204201" - ], - "index": "pypi", - "version": "==1.12.3" + "sha256:00d890313797d9fe4420506613384b43099ad7d2b905c0752dbcc3a6f14d80fa", + "sha256:0cf9e550ac6c5e57b713437e2f4ac2d7fd0cd10336525a27224f5fc1ec2ee59a", + "sha256:0ea23c9c0cdd6778146a50d867d6405693ac3b80a68829966c98dd5e1bbae400", + "sha256:193697c2918ecdb3865acf6557cddf5076bb39f1f654975e087b67efdff83365", + "sha256:1ae14b542bf3b35e5229439c35653d2ef7d8316c1fffb980f9b7647e544baa98", + "sha256:1e389e069450609c6ffa37f21f40cce36f9be7643bbe5051ab1de99d5a779526", + "sha256:263242b6ace7f9cd4ea401428d2d45066b49a700852334fd55311bde36dcda14", + "sha256:33142ae9807665fa6511cfa9857132b2c3ee6ddffb012b3f0933fc11e1e830d5", + "sha256:364f8404034ae1b232335d8c7f7b57deac566f148f7222cef78cf8ae28ef764e", + "sha256:47368f69fe6529f8f49a5d146ddee713fc9057e31d61e8b6dc86a6a5e38cecc1", + "sha256:4895640844f17bec32943995dc8c96989226974dfeb9dd121cc45d36e0d0c434", + "sha256:558b3afef987cf4b17abd849e7bedf64ee12b28175d564d05b628a0f9355599b", + "sha256:5ba86e1d80d458b338bda676fd9f9d68cb4e7a03819632969cf6d46b01a26730", + "sha256:63424daa6955e6b4c70dc2755897f5be1d719eabe71b2625948b222775ed5c43", + "sha256:6381a7d8b1ebd0bc27c3bc85bc1bfadbb6e6f756b4d4db0aa1425c3719ba26b4", + "sha256:6381ab708158c4e1639da1f2a7679a9bbe3e5a776fc6d1fd808076f0e3145331", + "sha256:6fd58366747debfa5e6163ada468a90788411f10c92597d3b0a912d07e580c36", + "sha256:728ec653964655d65408949b07f9b2219df78badd601d6c49e28d604efe40599", + "sha256:7cfcfda59ef1f95b9f729c56fe8a4041899f96b72685d36ef16a3440a0f85da8", + "sha256:819f8d5197c2684524637f940445c06e003c4a541f9983fd30d6deaa2a5487d8", + "sha256:825ecffd9574557590e3225560a8a9d751f6ffe4a49e3c40918c9969b93395fa", + "sha256:9009e917d8f5ef780c2626e29b6bc126f4cb2a4d43ca67aa2b40f2a5d6385e78", + "sha256:9c77564a51d4d914ed5af096cd9843d90c45b784b511723bd46a8a9d09cf16fc", + "sha256:a19089fa74ed19c4fe96502a291cfdb89223a9705b1d73b3005df4256976142e", + "sha256:a40ed527bffa2b7ebe07acc5a3f782da072e262ca994b4f2085100b5a444bbb2", + "sha256:bb75ba21d5716abc41af16eac1145ab2e471deedde1f22c6f99bd9f995504df0", + "sha256:e22a00c0c81ffcecaf07c2bfb3672fa372c50e2bd1024ffee0da191c1b27fc71", + "sha256:e55b5a746fb77f10c83e8af081979351722f6ea48facea79d470b3731c7b2891", + "sha256:ec2fa3ee81707a5232bf2dfbd6623fdb278e070d596effc7e2d788f2ada71a05", + "sha256:fd82eb4694be712fcae03c717ca2e0fc720657ac226b80bbb597e971fc6928c2" + ], + "index": "pypi", + "version": "==1.13.1" }, "chardet": { "hashes": [ @@ -885,27 +919,70 @@ "index": "pypi", "version": "==0.8.2" }, + "coverage": { + "hashes": [ + "sha256:08907593569fe59baca0bf152c43f3863201efb6113ecb38ce7e97ce339805a6", + "sha256:0be0f1ed45fc0c185cfd4ecc19a1d6532d72f86a2bac9de7e24541febad72650", + "sha256:141f08ed3c4b1847015e2cd62ec06d35e67a3ac185c26f7635f4406b90afa9c5", + "sha256:19e4df788a0581238e9390c85a7a09af39c7b539b29f25c89209e6c3e371270d", + "sha256:23cc09ed395b03424d1ae30dcc292615c1372bfba7141eb85e11e50efaa6b351", + "sha256:245388cda02af78276b479f299bbf3783ef0a6a6273037d7c60dc73b8d8d7755", + "sha256:331cb5115673a20fb131dadd22f5bcaf7677ef758741312bee4937d71a14b2ef", + "sha256:386e2e4090f0bc5df274e720105c342263423e77ee8826002dcffe0c9533dbca", + "sha256:3a794ce50daee01c74a494919d5ebdc23d58873747fa0e288318728533a3e1ca", + "sha256:60851187677b24c6085248f0a0b9b98d49cba7ecc7ec60ba6b9d2e5574ac1ee9", + "sha256:63a9a5fc43b58735f65ed63d2cf43508f462dc49857da70b8980ad78d41d52fc", + "sha256:6b62544bb68106e3f00b21c8930e83e584fdca005d4fffd29bb39fb3ffa03cb5", + "sha256:6ba744056423ef8d450cf627289166da65903885272055fb4b5e113137cfa14f", + "sha256:7494b0b0274c5072bddbfd5b4a6c6f18fbbe1ab1d22a41e99cd2d00c8f96ecfe", + "sha256:826f32b9547c8091679ff292a82aca9c7b9650f9fda3e2ca6bf2ac905b7ce888", + "sha256:93715dffbcd0678057f947f496484e906bf9509f5c1c38fc9ba3922893cda5f5", + "sha256:9a334d6c83dfeadae576b4d633a71620d40d1c379129d587faa42ee3e2a85cce", + "sha256:af7ed8a8aa6957aac47b4268631fa1df984643f07ef00acd374e456364b373f5", + "sha256:bf0a7aed7f5521c7ca67febd57db473af4762b9622254291fbcbb8cd0ba5e33e", + "sha256:bf1ef9eb901113a9805287e090452c05547578eaab1b62e4ad456fcc049a9b7e", + "sha256:c0afd27bc0e307a1ffc04ca5ec010a290e49e3afbe841c5cafc5c5a80ecd81c9", + "sha256:dd579709a87092c6dbee09d1b7cfa81831040705ffa12a1b248935274aee0437", + "sha256:df6712284b2e44a065097846488f66840445eb987eb81b3cc6e4149e7b6982e1", + "sha256:e07d9f1a23e9e93ab5c62902833bf3e4b1f65502927379148b6622686223125c", + "sha256:e2ede7c1d45e65e209d6093b762e98e8318ddeff95317d07a27a2140b80cfd24", + "sha256:e4ef9c164eb55123c62411f5936b5c2e521b12356037b6e1c2617cef45523d47", + "sha256:eca2b7343524e7ba246cab8ff00cab47a2d6d54ada3b02772e908a45675722e2", + "sha256:eee64c616adeff7db37cc37da4180a3a5b6177f5c46b187894e633f088fb5b28", + "sha256:ef824cad1f980d27f26166f86856efe11eff9912c4fed97d3804820d43fa550c", + "sha256:efc89291bd5a08855829a3c522df16d856455297cf35ae827a37edac45f466a7", + "sha256:fa964bae817babece5aa2e8c1af841bebb6d0b9add8e637548809d040443fee0", + "sha256:ff37757e068ae606659c28c3bd0d923f9d29a85de79bf25b2b34b148473b5025" + ], + "index": "pypi", + "version": "==4.5.4" + }, "cryptography": { "hashes": [ - "sha256:24b61e5fcb506424d3ec4e18bca995833839bf13c59fc43e530e488f28d46b8c", - "sha256:25dd1581a183e9e7a806fe0543f485103232f940fcfc301db65e630512cce643", - "sha256:3452bba7c21c69f2df772762be0066c7ed5dc65df494a1d53a58b683a83e1216", - "sha256:41a0be220dd1ed9e998f5891948306eb8c812b512dc398e5a01846d855050799", - "sha256:5751d8a11b956fbfa314f6553d186b94aa70fdb03d8a4d4f1c82dcacf0cbe28a", - "sha256:5f61c7d749048fa6e3322258b4263463bfccefecb0dd731b6561cb617a1d9bb9", - "sha256:72e24c521fa2106f19623a3851e9f89ddfdeb9ac63871c7643790f872a305dfc", - "sha256:7b97ae6ef5cba2e3bb14256625423413d5ce8d1abb91d4f29b6d1a081da765f8", - "sha256:961e886d8a3590fd2c723cf07be14e2a91cf53c25f02435c04d39e90780e3b53", - "sha256:96d8473848e984184b6728e2c9d391482008646276c3ff084a1bd89e15ff53a1", - "sha256:ae536da50c7ad1e002c3eee101871d93abdc90d9c5f651818450a0d3af718609", - "sha256:b0db0cecf396033abb4a93c95d1602f268b3a68bb0a9cc06a7cff587bb9a7292", - "sha256:cfee9164954c186b191b91d4193989ca994703b2fff406f71cf454a2d3c7327e", - "sha256:e6347742ac8f35ded4a46ff835c60e68c22a536a8ae5c4422966d06946b6d4c6", - "sha256:f27d93f0139a3c056172ebb5d4f9056e770fdf0206c2f422ff2ebbad142e09ed", - "sha256:f57b76e46a58b63d1c6375017f4564a28f19a5ca912691fd2e4261b3414b618d" - ], - "index": "pypi", - "version": "==2.7" + "sha256:02079a6addc7b5140ba0825f542c0869ff4df9a69c360e339ecead5baefa843c", + "sha256:1df22371fbf2004c6f64e927668734070a8953362cd8370ddd336774d6743595", + "sha256:369d2346db5934345787451504853ad9d342d7f721ae82d098083e1f49a582ad", + "sha256:3cda1f0ed8747339bbdf71b9f38ca74c7b592f24f65cdb3ab3765e4b02871651", + "sha256:44ff04138935882fef7c686878e1c8fd80a723161ad6a98da31e14b7553170c2", + "sha256:4b1030728872c59687badcca1e225a9103440e467c17d6d1730ab3d2d64bfeff", + "sha256:58363dbd966afb4f89b3b11dfb8ff200058fbc3b947507675c19ceb46104b48d", + "sha256:6ec280fb24d27e3d97aa731e16207d58bd8ae94ef6eab97249a2afe4ba643d42", + "sha256:7270a6c29199adc1297776937a05b59720e8a782531f1f122f2eb8467f9aab4d", + "sha256:73fd30c57fa2d0a1d7a49c561c40c2f79c7d6c374cc7750e9ac7c99176f6428e", + "sha256:7f09806ed4fbea8f51585231ba742b58cbcfbfe823ea197d8c89a5e433c7e912", + "sha256:90df0cc93e1f8d2fba8365fb59a858f51a11a394d64dbf3ef844f783844cc793", + "sha256:971221ed40f058f5662a604bd1ae6e4521d84e6cad0b7b170564cc34169c8f13", + "sha256:a518c153a2b5ed6b8cc03f7ae79d5ffad7315ad4569b2d5333a13c38d64bd8d7", + "sha256:b0de590a8b0979649ebeef8bb9f54394d3a41f66c5584fff4220901739b6b2f0", + "sha256:b43f53f29816ba1db8525f006fa6f49292e9b029554b3eb56a189a70f2a40879", + "sha256:d31402aad60ed889c7e57934a03477b572a03af7794fa8fb1780f21ea8f6551f", + "sha256:de96157ec73458a7f14e3d26f17f8128c959084931e8997b9e655a39c8fde9f9", + "sha256:df6b4dca2e11865e6cfbfb708e800efb18370f5a46fd601d3755bc7f85b3a8a2", + "sha256:ecadccc7ba52193963c0475ac9f6fa28ac01e01349a2ca48509667ef41ffd2cf", + "sha256:fb81c17e0ebe3358486cd8cc3ad78adbae58af12fc2bf2bc0bb84e8090fa5ce8" + ], + "index": "pypi", + "version": "==2.8" }, "cycler": { "hashes": [ @@ -1050,10 +1127,10 @@ }, "future": { "hashes": [ - "sha256:67045236dcfd6816dc439556d009594abf643e5eb48992e36beac09c2ca659b8" + "sha256:858e38522e8fd0d3ce8f0c1feaf0603358e366d5403209674c7b617fa0c24093" ], "index": "pypi", - "version": "==0.17.1" + "version": "==0.18.1" }, "futures": { "hashes": [ @@ -1150,40 +1227,56 @@ }, "grpcio": { "hashes": [ - "sha256:0302331e014fc4bac028b6ad480b33f7abfe20b9bdcca7be417124dda8f22115", - "sha256:0aa0cce9c5eb1261b32173a20ed42b51308d55ce28ecc2021e868b3cb90d9503", - "sha256:0c83947575300499adbc308e986d754e7f629be0bdd9bea1ffdd5cf76e1f1eff", - "sha256:0ca26ff968d45efd4ef73447c4d4b34322ea8c7d06fbb6907ce9e5db78f1bbcb", - "sha256:0cf80a7955760c2498f8821880242bb657d70998065ff0d2a082de5ffce230a7", - "sha256:0d40706e57d9833fe0e023a08b468f33940e8909affa12547874216d36bba208", - "sha256:11872069156de34c6f3f9a1deb46cc88bc35dfde88262c4c73eb22b39b16fc55", - "sha256:16065227faae0ab0abf1789bfb92a2cd2ab5da87630663f93f8178026da40e0d", - "sha256:1e33778277685f6fabb22539136269c87c029e39b6321ef1a639b756a1c0a408", - "sha256:2b16be15b1ae656bc7a36642b8c7045be2dde2048bb4b67478003e9d9db8022a", - "sha256:3701dfca3ada27ceef0d17f728ce9dfef155ed20c57979c2b05083082258c6c1", - "sha256:41912ecaf482abf2de74c69f509878f99223f5dd6b2de1a09c955afd4de3cf9b", - "sha256:4332cbd20544fe7406910137590f38b5b3a1f6170258e038652cf478c639430f", - "sha256:44068ecbdc6467c2bff4d8198816c8a2701b6dd1ec16078fceb6adc7c1f577d6", - "sha256:53115960e37059420e2d16a4b04b00dd2ab3b6c3c67babd01ffbfdcd7881a69b", - "sha256:6e7027bcd4070414751e2a5e60706facb98a1fc636497c9bac5442fe37b8ae6b", - "sha256:6ff57fb2f07b7226b5bec89e8e921ea9bd220f35f11e094f2ba38f09eecd49c6", - "sha256:73240e244d7644654bbda1f309f4911748b6a1804b7a8897ddbe8a04c90f7407", - "sha256:785234bbc469bc75e26c868789a2080ffb30bd6e93930167797729889ad06b0b", - "sha256:82f9d3c7f91d2d1885631335c003c5d45ae1cd69cc0bc4893f21fef50b8151bc", - "sha256:86bdc2a965510658407a1372eb61f0c92f763fdfb2795e4d038944da4320c950", - "sha256:95e925b56676a55e6282b3de80a1cbad5774072159779c61eac02791dface049", - "sha256:96673bb4f14bd3263613526d1e7e33fdb38a9130e3ce87bf52314965706e1900", - "sha256:970014205e76920484679035b6fb4b16e02fc977e5aac4d22025da849c79dab9", - "sha256:ace5e8bf11a1571f855f5dab38a9bd34109b6c9bc2864abf24a597598c7e3695", - "sha256:ad375f03eb3b9cb75a24d91eab8609e134d34605f199efc41e20dd642bdac855", - "sha256:b819c4c7dcf0de76788ce5f95daad6d4e753d6da2b6a5f84e5bb5b5ce95fddc4", - "sha256:c17943fd340cbd906db49f3f03c7545e5a66b617e8348b2c7a0d2c759d216af1", - "sha256:d21247150dea86dabd3b628d8bc4b563036db3d332b3f4db3c5b1b0b122cb4f6", - "sha256:d4d500a7221116de9767229ff5dd10db91f789448d85befb0adf5a37b0cd83b5", - "sha256:e2a942a3cfccbbca21a90c144867112698ef36486345c285da9e98c466f22b22", - "sha256:e983273dca91cb8a5043bc88322eb48e2b8d4e4998ff441a1ee79ced89db3909" - ], - "version": "==1.24.1" + "sha256:01cb705eafba1108e2a947ba0457da4f6a1e8142c729fc61702b5fdd11009eb1", + "sha256:0b5a79e29f167d3cd06faad6b15babbc2661066daaacf79373c3a8e67ca1fca1", + "sha256:1097a61a0e97b3580642e6e1460a3a1f1ba1815e2a70d6057173bcc495417076", + "sha256:13970e665a4ec4cec7d067d7d3504a0398c657d91d26c581144ad9044e429c9a", + "sha256:1557817cea6e0b87fad2a3e20da385170efb03a313db164e8078955add2dfa1b", + "sha256:1b0fb036a2f9dd93d9a35c57c26420eeb4b571fcb14b51cddf5b1e73ea5d882b", + "sha256:24d9e58d08e8cd545d8a3247a18654aff0e5e60414701696a8098fbb0d792b75", + "sha256:2c38b586163d2b91567fe5e6d9e7798f792012365adc838a64b66b22dce3f4d4", + "sha256:2df3ab4348507de60e1cbf75196403df1b9b4c4d4dc5bd11ac4eb63c46f691c7", + "sha256:32f70f7c90454ea568b868af2e96616743718d9233d23f62407e98caed81dfbf", + "sha256:3af2a49d576820045c9c880ff29a5a96d020fe31b35d248519bfc6ccb8be4eac", + "sha256:4ff7d63800a63db031ebac6a6f581ae84877c959401c24c28f2cc51fd36c47ad", + "sha256:502aaa8be56f0ae69cda66bc27e1fb5531ceaa27ca515ec3c34f6178b1297180", + "sha256:55358ce3ec283222e435f7dbc6603521438458f3c65f7c1cb33b8dabf56d70d8", + "sha256:5583b01c67f85fa64a2c3fb085e5517c88b9c1500a2cce12d473cd99d0ed2e49", + "sha256:58d9a5557d3eb7b734a3cea8b16c891099a522b3953a45a30bd4c034f75fc913", + "sha256:5911f042c4ab177757eec5bcb4e2e9a2e823d888835d24577321bf55f02938fa", + "sha256:5e16ea922f4e5017c04fd94e2639b1006e03097e9dd0cbb7a1c852af3ea8bf2e", + "sha256:656e19d3f1b9050ee01b457f92838a9679d7cf84c995f708780f44484048705e", + "sha256:6a1435449a82008c451c7e1a82a834387b9108f9a8d27910f86e7c482f5568e9", + "sha256:6ff02ca6cbed0ddb76e93ba0f8beb6a8c77d83a84eb7cafe2ae3399a8b9d69ea", + "sha256:76de68f60102f333bf4817f38e81ecbee68b850f5a5da9f355235e948ac40981", + "sha256:7c6d7ddd50fc6548ea1dfe09c62509c4f95b8b40082287747be05aa8feb15ee2", + "sha256:836b9d29507de729129e363276fe7c7d6a34c7961e0f155787025552b15d22c0", + "sha256:869242b2baf8a888a4fe0548f86abc47cb4b48bdfd76ae62d6456e939c202e65", + "sha256:8954b24bd08641d906ee50b2d638efc76df893fbd0913149b80484fd0eac40c9", + "sha256:8cdea65d1abb2e698420db8daf20c8d272fbd9d96a51b26a713c1c76f237d181", + "sha256:90161840b4fe9636f91ed0d3ea1e7e615e488cbea4e77594c889e5f3d7a776db", + "sha256:90fb6316b4d7d36700c40db4335902b78dcae13b5466673c21fd3b08a3c1b0c6", + "sha256:91b34f58db2611c9a93ecf751028f97fba1f06e65f49b38f272f6aa5d2977331", + "sha256:9474944a96a33eb8734fa8dc5805403d57973a3526204a5e1c1780d02e0572b6", + "sha256:9a36275db2a4774ac16c6822e7af816ee048071d5030b4c035fd53942b361935", + "sha256:9cbe26e2976b994c5f7c2d35a63354674d6ca0ce62f5b513f078bf63c1745229", + "sha256:9eaeabb3c0eecd6ddd0c16767fd12d130e2cebb8c2618f959a278b1ff336ddc3", + "sha256:a2bc7e10ebcf4be503ae427f9887e75c0cc24e88ce467a8e6eaca6bd2862406e", + "sha256:a5b42e6292ba51b8e67e09fc256963ba4ca9c04026de004d2fe59cc17e3c3776", + "sha256:bd6ec1233c86c0b9bb5d03ec30dbe3ffbfa53335790320d99a7ae9018c5450f2", + "sha256:bef57530816af54d66b1f4c70a8f851f320cb6f84d4b5a0b422b0e9811ea4e59", + "sha256:c146a63eaadc6589b732780061f3c94cd0574388d372baccbb3c1597a9ebdb7a", + "sha256:c2efd3b130dc639d615b6f58980e1bfd1b177ad821f30827afa5001aa30ddd48", + "sha256:c888b18f7392e6cc79a33a803e7ebd7890ac3318f571fca6b356526f35b53b12", + "sha256:ca30721fda297ae22f16bc37aa7ed244970ddfdcb98247570cdd26daaad4665e", + "sha256:cf5f5340dd682ab034baa52f423a0f91326489c262ac9617fa06309ec05880e9", + "sha256:d0726aa0d9b57c56985db5952e90fb1033a317074f2877db5307cdd6eede1564", + "sha256:df442945b2dd6f8ae0e20b403e0fd4548cd5c2aad69200047cc3251257b78f65", + "sha256:e08e758c31919d167c0867539bd3b2441629ef00aa595e3ea2b635273659f40a", + "sha256:e4864339deeeaefaad34dd3a432ee618a039fca28efb292949c855e00878203c", + "sha256:f4cd049cb94d9f517b1cab5668a3b345968beba093bc79a637e671000b3540ec" + ], + "version": "==1.24.3" }, "gunicorn": { "hashes": [ @@ -1258,11 +1351,11 @@ }, "imageio": { "hashes": [ - "sha256:1a2bbbb7cd38161340fa3b14d806dfbf914abf3ee6fd4592af2afb87d049f209", - "sha256:42e65aadfc3d57a1043615c92bdf6319b67589e49a0aae2b985b82144aceacad" + "sha256:c9763e5c187ecf74091c845626b0bdcc6130a20a0de7a86ae0108e2b5335ed3f", + "sha256:f44eb231b9df485874f2ffd22dfd0c3c711e7de076516b9374edea5c65bc67ae" ], "index": "pypi", - "version": "==2.5.0" + "version": "==2.6.1" }, "importlib-metadata": { "hashes": [ @@ -1281,11 +1374,11 @@ }, "ipykernel": { "hashes": [ - "sha256:167c3ef08450f5e060b76c749905acb0e0fbef9365899377a4a1eae728864383", - "sha256:b503913e0b4cce7ed2de965457dfb2edd633e8234161a60e23f2fe2161345d12" + "sha256:1a7def9c986f1ee018c1138d16951932d4c9d4da01dad45f9d34e9899565a22f", + "sha256:b368ad13edb71fa2db367a01e755a925d7f75ed5e09fbd3f06c85e7a8ef108a8" ], "index": "pypi", - "version": "==5.1.2" + "version": "==5.1.3" }, "ipython": { "hashes": [ @@ -1335,11 +1428,11 @@ }, "jinja2": { "hashes": [ - "sha256:065c4f02ebe7f7cf559e49ee5a95fb800a9e4528727aec6f24402a5374c65013", - "sha256:14dd6caf1527abb21f08f86c784eac40853ba93edb79552aa1e4b8aef1b61c7b" + "sha256:74320bb91f31270f9551d46522e33af46a80c3d619f4a4bf42b3164d30b5911f", + "sha256:9fe95f19286cfefaa917656583d020be14e7859c6b0252588391e47db34527de" ], "index": "pypi", - "version": "==2.10.1" + "version": "==2.10.3" }, "jmespath": { "hashes": [ @@ -1365,10 +1458,10 @@ }, "jsonschema": { "hashes": [ - "sha256:5f9c0a719ca2ce14c5de2fd350a64fd2d13e8539db29836a86adc990bb1a068f", - "sha256:8d4a2b7b6c2237e0199c8ea1a6d3e05bf118e289ae2b9d7ba444182a2959560d" + "sha256:2fa0684276b6333ff3c0b1b27081f4b2305f0a36cf702a23db50edb141893c3f", + "sha256:94c0a13b4a0616458b42529091624e66700a17f847453e52279e35509a5b7631" ], - "version": "==3.0.2" + "version": "==3.1.1" }, "jupyter": { "hashes": [ @@ -1381,11 +1474,11 @@ }, "jupyter-client": { "hashes": [ - "sha256:6a6d415c62179728f6d9295b37356d8f6833e9e01c2b6e1901dc555571f57b21", - "sha256:f406f214f9daa92be110d5b83d62f3451ffc73d3522db7350f0554683533ab18" + "sha256:60e6faec1031d63df57f1cc671ed673dced0ed420f4377ea33db37b1c188b910", + "sha256:d0c077c9aaa4432ad485e7733e4d91e48f87b4f4bab7d283d42bb24cbbba0a0f" ], "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==5.3.3" + "version": "==5.3.4" }, "jupyter-console": { "hashes": [ @@ -1397,11 +1490,11 @@ }, "jupyter-core": { "hashes": [ - "sha256:2c6e7c1e9f2ac45b5c2ceea5730bc9008d92fe59d0725eac57b04c0edfba24f7", - "sha256:f4fa22d6cf25f34807c995f22d2923693575c70f02557bcbfbe59bd5ec8d8b84" + "sha256:464769f7387d7a62a2403d067f1ddc616655b7f77f5d810c0dd62cb54bfd0fb9", + "sha256:a183e0ec2e8f6adddf62b0a3fc6a2237e3e0056d381e536d3e7c7ecc3067e244" ], "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==4.5.0" + "version": "==4.6.1" }, "keras-applications": { "hashes": [ @@ -1596,13 +1689,6 @@ ], "version": "==0.6.1" }, - "meld3": { - "hashes": [ - "sha256:1efda676264490db2e30bfb81b27a918cc6d9c2de6d609491aa43410b9537eb9", - "sha256:a78cdcb6c0342b7ac82d900b584bd918ef72f86b60cdbf04754f840c070eb20c" - ], - "version": "==2.0.0" - }, "mistune": { "hashes": [ "sha256:59a3429db53c50b5c6bcc8a07f8848cb00d7dc8bdb431a4ab41920d201d4756e", @@ -1672,10 +1758,11 @@ }, "networkx": { "hashes": [ - "sha256:8311ddef63cf5c5c5e7c1d0212dd141d9a1fe3f474915281b73597ed5f1d4e3d" + "sha256:cdfbf698749a5014bf2ed9db4a07a5295df1d3a53bf80bf3cbd61edf9df05fa1", + "sha256:f8f4ff0b6f96e4f9b16af6b84622597b5334bf9cae8cf9b2e42e7985d5c95c64" ], - "markers": "python_version >= '3.5'", - "version": "==2.3" + "index": "pypi", + "version": "==2.4" }, "nose": { "hashes": [ @@ -1704,25 +1791,30 @@ }, "numpy": { "hashes": [ - "sha256:05dbfe72684cc14b92568de1bc1f41e5f62b00f714afc9adee42f6311738091f", - "sha256:0d82cb7271a577529d07bbb05cb58675f2deb09772175fab96dc8de025d8ac05", - "sha256:10132aa1fef99adc85a905d82e8497a580f83739837d7cbd234649f2e9b9dc58", - "sha256:12322df2e21f033a60c80319c25011194cd2a21294cc66fee0908aeae2c27832", - "sha256:16f19b3aa775dddc9814e02a46b8e6ae6a54ed8cf143962b4e53f0471dbd7b16", - "sha256:3d0b0989dd2d066db006158de7220802899a1e5c8cf622abe2d0bd158fd01c2c", - "sha256:438a3f0e7b681642898fd7993d38e2bf140a2d1eafaf3e89bb626db7f50db355", - "sha256:5fd214f482ab53f2cea57414c5fb3e58895b17df6e6f5bca5be6a0bb6aea23bb", - "sha256:73615d3edc84dd7c4aeb212fa3748fb83217e00d201875a47327f55363cef2df", - "sha256:7bd355ad7496f4ce1d235e9814ec81ee3d28308d591c067ce92e49f745ba2c2f", - "sha256:7d077f2976b8f3de08a0dcf5d72083f4af5411e8fddacd662aae27baa2601196", - "sha256:a4092682778dc48093e8bda8d26ee8360153e2047826f95a3f5eae09f0ae3abf", - "sha256:b458de8624c9f6034af492372eb2fee41a8e605f03f4732f43fc099e227858b2", - "sha256:e70fc8ff03a961f13363c2c95ef8285e0cf6a720f8271836f852cc0fa64e97c8", - "sha256:ee8e9d7cad5fe6dde50ede0d2e978d81eafeaa6233fb0b8719f60214cf226578", - "sha256:f4a4f6aba148858a5a5d546a99280f71f5ee6ec8182a7d195af1a914195b21a2" - ], - "index": "pypi", - "version": "==1.17.2" + "sha256:0b0dd8f47fb177d00fa6ef2d58783c4f41ad3126b139c91dd2f7c4b3fdf5e9a5", + "sha256:25ffe71f96878e1da7e014467e19e7db90ae7d4e12affbc73101bcf61785214e", + "sha256:26efd7f7d755e6ca966a5c0ac5a930a87dbbaab1c51716ac26a38f42ecc9bc4b", + "sha256:28b1180c758abf34a5c3fea76fcee66a87def1656724c42bb14a6f9717a5bdf7", + "sha256:2e418f0a59473dac424f888dd57e85f77502a593b207809211c76e5396ae4f5c", + "sha256:30c84e3a62cfcb9e3066f25226e131451312a044f1fe2040e69ce792cb7de418", + "sha256:4650d94bb9c947151737ee022b934b7d9a845a7c76e476f3e460f09a0c8c6f39", + "sha256:4dd830a11e8724c9c9379feed1d1be43113f8bcce55f47ea7186d3946769ce26", + "sha256:4f2a2b279efde194877aff1f76cf61c68e840db242a5c7169f1ff0fd59a2b1e2", + "sha256:62d22566b3e3428dfc9ec972014c38ed9a4db4f8969c78f5414012ccd80a149e", + "sha256:669795516d62f38845c7033679c648903200980d68935baaa17ac5c7ae03ae0c", + "sha256:75fcd60d682db3e1f8fbe2b8b0c6761937ad56d01c1dc73edf4ef2748d5b6bc4", + "sha256:9395b0a41e8b7e9a284e3be7060db9d14ad80273841c952c83a5afc241d2bd98", + "sha256:9e37c35fc4e9410093b04a77d11a34c64bf658565e30df7cbe882056088a91c1", + "sha256:a0678793096205a4d784bd99f32803ba8100f639cf3b932dc63b21621390ea7e", + "sha256:b46554ad4dafb2927f88de5a1d207398c5385edbb5c84d30b3ef187c4a3894d8", + "sha256:c867eeccd934920a800f65c6068acdd6b87e80d45cd8c8beefff783b23cdc462", + "sha256:dd0667f5be56fb1b570154c2c0516a528e02d50da121bbbb2cbb0b6f87f59bc2", + "sha256:de2b1c20494bdf47f0160bd88ed05f5e48ae5dc336b8de7cfade71abcc95c0b9", + "sha256:f1df7b2b7740dd777571c732f98adb5aad5450aee32772f1b39249c8a50386f6", + "sha256:ffca69e29079f7880c5392bf675eb8b4146479d976ae1924d01cd92b04cccbcc" + ], + "index": "pypi", + "version": "==1.17.3" }, "opencv-python": { "hashes": [ @@ -1794,24 +1886,28 @@ }, "pandas": { "hashes": [ - "sha256:18d91a9199d1dfaa01ad645f7540370ba630bdcef09daaf9edf45b4b1bca0232", - "sha256:3f26e5da310a0c0b83ea50da1fd397de2640b02b424aa69be7e0784228f656c9", - "sha256:4182e32f4456d2c64619e97c58571fa5ca0993d1e8c2d9ca44916185e1726e15", - "sha256:426e590e2eb0e60f765271d668a30cf38b582eaae5ec9b31229c8c3c10c5bc21", - "sha256:5eb934a8f0dc358f0e0cdf314072286bbac74e4c124b64371395e94644d5d919", - "sha256:717928808043d3ea55b9bcde636d4a52d2236c246f6df464163a66ff59980ad8", - "sha256:8145f97c5ed71827a6ec98ceaef35afed1377e2d19c4078f324d209ff253ecb5", - "sha256:8744c84c914dcc59cbbb2943b32b7664df1039d99e834e1034a3372acb89ea4d", - "sha256:c1ac1d9590d0c9314ebf01591bd40d4c03d710bfc84a3889e5263c97d7891dee", - "sha256:cb2e197b7b0687becb026b84d3c242482f20cbb29a9981e43604eb67576da9f6", - "sha256:d4001b71ad2c9b84ff18b182cea22b7b6cbf624216da3ea06fb7af28d1f93165", - "sha256:d8930772adccb2882989ab1493fa74bd87d47c8ac7417f5dd3dd834ba8c24dc9", - "sha256:dfbb0173ee2399bc4ed3caf2d236e5c0092f948aafd0a15fbe4a0e77ee61a958", - "sha256:eebfbba048f4fa8ac711b22c78516e16ff8117d05a580e7eeef6b0c2be554c18", - "sha256:f1b21bc5cf3dbea53d33615d1ead892dfdae9d7052fa8898083bec88be20dcd2" + "sha256:0f484f43658a72e7d586a74978259657839b5bd31b903e963bb1b1491ab51775", + "sha256:0ffc6f9e20e77f3a7dc8baaad9c7fd25b858b084d3a2d8ce877bc3ea804e0636", + "sha256:23e0eac646419c3057f15eb96ab821964848607bf1d4ea5a82f26565986ec5e9", + "sha256:27c0603b15b5c6fa24885253bbe49a0c289381e7759385c59308ba4f0b166cf1", + "sha256:397fe360643fffc5b26b41efdf608647e3334a618d185a07976cd2dc51c90bce", + "sha256:3dbb3aa41c01504255bff2bd56944bdb915f6c9ce4bac7e2868efbace0b2a639", + "sha256:4e07c63247c59d61c6ebdbbb50196143cec6c5044403510c4e1a9d31854a83d6", + "sha256:4fa6d9235c6d2fecbeca82c3d326abd255866cafbfd37f66a0e826544e619760", + "sha256:56cb88b3876363d410a9d7724f43641ff164e2c9902d3266a648213e2efd5e6d", + "sha256:7ce1be1614455f83710b9a5dc1fc602a755bdddbe4dda1d41515062923a37bbf", + "sha256:ae1c96ffdeec376895e533107e0b0f9da16225a2184fbb24a5abc866769db75e", + "sha256:b6f27c9231be8a23de846f2302373991467dd8e397a4804d2614e8c5aa8d5a90", + "sha256:c6056067f894f9355bedcd168dd740aa849908d41c0a74756f6e38f203e941b3", + "sha256:ca91a19d1f0a280874a24dca44aadce42da7f3a7edb7e9ab7c7baad8febee2be", + "sha256:cbe4985f5c82a173f8cff6b7fe92d551addf99fb4ea9ff4eb4b1fe606bb098ec", + "sha256:e3e9893bfe80a8b8e6d56d36ebb7afe1df77db7b4068a6e2ef3636a91f6f1caa", + "sha256:e7b218e8711910dac3fed0d19376cd1ef0e386be5175965d332fd0c65d02a43b", + "sha256:ec48d18b8b63a5dbb838e8ea7892ee1034299e03f852bd9b6dffe870310414dd", + "sha256:f4ab6280277e3208a59bfa9f2e51240304d09e69ffb65abfb4a21d678b495f74" ], "markers": "python_version >= '3.5.3'", - "version": "==0.25.1" + "version": "==0.25.2" }, "pandocfilters": { "hashes": [ @@ -1858,35 +1954,39 @@ }, "pillow": { "hashes": [ - "sha256:00fdeb23820f30e43bba78eb9abb00b7a937a655de7760b2e09101d63708b64e", - "sha256:01f948e8220c85eae1aa1a7f8edddcec193918f933fb07aaebe0bfbbcffefbf1", - "sha256:08abf39948d4b5017a137be58f1a52b7101700431f0777bec3d897c3949f74e6", - "sha256:099a61618b145ecb50c6f279666bbc398e189b8bc97544ae32b8fcb49ad6b830", - "sha256:2c1c61546e73de62747e65807d2cc4980c395d4c5600ecb1f47a650c6fa78c79", - "sha256:2ed9c4f694861642401f27dc3cb99772be67cd190e84845c749dae0a06c3bfae", - "sha256:338581b30b908e111be578f0297255f6b57a51358cd16fa0e6f664c9a1f88bff", - "sha256:38c7d48a21cd06fdeee93987147b9b1c55b73b4cfcbf83240568bfbd5adee447", - "sha256:43fd026f613c8e48a25eba1a92f4d2ad7f3903c95d8c33a11611a7717d2ab654", - "sha256:4548236844327a718ce3bb182ab32a16fa2050c61e334e959f554cac052fb0df", - "sha256:5090857876c58885cfa388dc649e5db30aae98a068c26f3fd0ac9d7d9a4d9572", - "sha256:5bbba34f97a26a93f5e8dec469ca4ddd712451418add43da946dbaed7f7a98d2", - "sha256:65a28969a025a0eb4594637b6103201dc4ed2a9508bdab56ac33e43e3081c404", - "sha256:892bb52b70bd5ea9dbbc3ac44f38e84f5a04e9d8b1bff48159d96cb795b81159", - "sha256:8a9becd5cbd5062f973bcd2e7bc79483af310222de112b6541f8af1f93a3cc42", - "sha256:972a7aaeb7c4a2795b52eef52ee991ef040b31009f36deca6207a986607b55f3", - "sha256:97b119c436bfa96a92ac2ca525f7025836d4d4e64b1c9f9eff8dbaf3ff1d86f3", - "sha256:9ba37698e242223f8053cc158f130aee046a96feacbeab65893dbe94f5530118", - "sha256:b1b0e1f626a0f079c0d3696db70132fb1f29aa87c66aecb6501a9b8be64ce9f7", - "sha256:c14c1224fd1a5be2733530d648a316974dbbb3c946913562c6005a76f21ca042", - "sha256:c79a8546c48ae6465189e54e3245a97ddf21161e33ff7eaa42787353417bb2b6", - "sha256:ceb76935ac4ebdf6d7bc845482a4450b284c6ccfb281e34da51d510658ab34d8", - "sha256:e22bffaad04b4d16e1c091baed7f2733fc1ebb91e0c602abf1b6834d17158b1f", - "sha256:ec883b8e44d877bda6f94a36313a1c6063f8b1997aa091628ae2f34c7f97c8d5", - "sha256:f1baa54d50ec031d1a9beb89974108f8f2c0706f49798f4777df879df0e1adb6", - "sha256:f53a5385932cda1e2c862d89460992911a89768c65d176ff8c50cddca4d29bed" - ], - "index": "pypi", - "version": "==6.2.0" + "sha256:047d9473cf68af50ac85f8ee5d5f21a60f849bc17d348da7fc85711287a75031", + "sha256:0f66dc6c8a3cc319561a633b6aa82c44107f12594643efa37210d8c924fc1c71", + "sha256:12c9169c4e8fe0a7329e8658c7e488001f6b4c8e88740e76292c2b857af2e94c", + "sha256:248cffc168896982f125f5c13e9317c059f74fffdb4152893339f3be62a01340", + "sha256:27faf0552bf8c260a5cee21a76e031acaea68babb64daf7e8f2e2540745082aa", + "sha256:285edafad9bc60d96978ed24d77cdc0b91dace88e5da8c548ba5937c425bca8b", + "sha256:384b12c9aa8ef95558abdcb50aada56d74bc7cc131dd62d28c2d0e4d3aadd573", + "sha256:38950b3a707f6cef09cd3cbb142474357ad1a985ceb44d921bdf7b4647b3e13e", + "sha256:4aad1b88933fd6dc2846552b89ad0c74ddbba2f0884e2c162aa368374bf5abab", + "sha256:4ac6148008c169603070c092e81f88738f1a0c511e07bd2bb0f9ef542d375da9", + "sha256:4deb1d2a45861ae6f0b12ea0a786a03d19d29edcc7e05775b85ec2877cb54c5e", + "sha256:59aa2c124df72cc75ed72c8d6005c442d4685691a30c55321e00ed915ad1a291", + "sha256:5a47d2123a9ec86660fe0e8d0ebf0aa6bc6a17edc63f338b73ea20ba11713f12", + "sha256:5cc901c2ab9409b4b7ac7b5bcc3e86ac14548627062463da0af3b6b7c555a871", + "sha256:6c1db03e8dff7b9f955a0fb9907eb9ca5da75b5ce056c0c93d33100a35050281", + "sha256:7ce80c0a65a6ea90ef9c1f63c8593fcd2929448613fc8da0adf3e6bfad669d08", + "sha256:809c19241c14433c5d6135e1b6c72da4e3b56d5c865ad5736ab99af8896b8f41", + "sha256:83792cb4e0b5af480588601467c0764242b9a483caea71ef12d22a0d0d6bdce2", + "sha256:846fa202bd7ee0f6215c897a1d33238ef071b50766339186687bd9b7a6d26ac5", + "sha256:9f5529fc02009f96ba95bea48870173426879dc19eec49ca8e08cd63ecd82ddb", + "sha256:a423c2ea001c6265ed28700df056f75e26215fd28c001e93ef4380b0f05f9547", + "sha256:ac4428094b42907aba5879c7c000d01c8278d451a3b7cccd2103e21f6397ea75", + "sha256:b1ae48d87f10d1384e5beecd169c77502fcc04a2c00a4c02b85f0a94b419e5f9", + "sha256:bf4e972a88f8841d8fdc6db1a75e0f8d763e66e3754b03006cbc3854d89f1cb1", + "sha256:c6414f6aad598364aaf81068cabb077894eb88fed99c6a65e6e8217bab62ae7a", + "sha256:c710fcb7ee32f67baf25aa9ffede4795fd5d93b163ce95fdc724383e38c9df96", + "sha256:c7be4b8a09852291c3c48d3c25d1b876d2494a0a674980089ac9d5e0d78bd132", + "sha256:c9e5ffb910b14f090ac9c38599063e354887a5f6d7e6d26795e916b4514f2c1a", + "sha256:e0697b826da6c2472bb6488db4c0a7fa8af0d52fa08833ceb3681358914b14e5", + "sha256:e9a3edd5f714229d41057d56ac0f39ad9bdba6767e8c888c951869f0bdd129b0" + ], + "index": "pypi", + "version": "==6.2.1" }, "pprofile": { "hashes": [ @@ -1934,6 +2034,7 @@ "psutil": { "hashes": [ "sha256:028a1ec3c6197eadd11e7b46e8cc2f0720dc18ac6d7aabdb8e8c0d6c9704f000", + "sha256:12542c3642909f4cd1928a2fba59e16fa27e47cbeea60928ebb62a8cbd1ce123", "sha256:503e4b20fa9d3342bcf58191bbc20a4a5ef79ca7df8972e6197cc14c5513e73d", "sha256:863a85c1c0a5103a12c05a35e59d336e1d665747e531256e061213e2e90f63f3", "sha256:954f782608bfef9ae9f78e660e065bd8ffcfaea780f9f2c8a133bb7cb9e826d7", @@ -2021,11 +2122,11 @@ }, "pylint": { "hashes": [ - "sha256:7edbae11476c2182708063ac387a8f97c760d9cfe36a5ede0ca996f90cf346c8", - "sha256:844ce067788028c1a35086a5c66bc5e599ddd851841c41d6ee1623b36774d9f2" + "sha256:7b76045426c650d2b0f02fc47c14d7934d17898779da95288a74c2a7ec440702", + "sha256:856476331f3e26598017290fd65bebe81c960e806776f324093a46b76fb2d1c0" ], "index": "pypi", - "version": "==2.4.2" + "version": "==2.4.3" }, "pylogbeat": { "hashes": [ @@ -2090,6 +2191,7 @@ "sha256:30f36a9c70450c7878053fa1344aca0145fd47d845270b43a7ee9192a051bf39", "sha256:37aa336a317209f1bb099ad177fef0da45be36a2aa664507c5d72015f956c310", "sha256:4943decfc5b905748f0756fdd99d4f9498d7064815c4cf3643820c9028b711d1", + "sha256:53126cd91356342dcae7e209f840212a58dcf1177ad52c1d938d428eebc9fee5", "sha256:57ef38a65056e7800859e5ba9e6091053cd06e1038983016effaffe0efcd594a", "sha256:5bd61e9b44c543016ce1f6aef48606280e45f892a928ca7068fba30021e9b786", "sha256:6482d3017a0c0327a49dddc8bd1074cc730d45db2ccb09c3bac1f8f32d1eb61b", @@ -2098,6 +2200,7 @@ "sha256:a39f54ccbcd2757d1d63b0ec00a00980c0b382c62865b61a505163943624ab20", "sha256:aabb0c5232910a20eec8563503c153a8e78bbf5459490c49ab31f6adf3f3a415", "sha256:bd4ecb473a96ad0f90c20acba4f0bf0df91a4e03a1f4dd6a4bdc9ca75aa3a715", + "sha256:bf459128feb543cfca16a95f8da31e2e65e4c5257d2f3dfa8c0c1031139c9c92", "sha256:e2da3c13307eac601f3de04887624939aca8ee3c9488a0bb0eca4fb9401fc6b1", "sha256:f67814c38162f4deb31f68d590771a29d5ae3b1bd64b75cf232308e5c74777e0" ], @@ -2169,24 +2272,26 @@ }, "pyqt5-sip": { "hashes": [ - "sha256:304acf771b6033cb4bafc415939d227c91265d30664ed643b298d7e95f509f81", - "sha256:39d2677f4de46ed4d7aa3b612f31c74c881975efe51c6a23fbb1d9382e4cc850", - "sha256:54b99a3057e8f01b90d49cca9ca566b1ea23d8920038760f44e75b90c62b9d5f", - "sha256:59f5332f86f3ccd3ac94674fe91eae6e8aca26da7c6588917cabd0fe22af106d", - "sha256:72be07a21b0f379987c4ec59bc86834a9719a2f9cfb49606a4d4e34dae9aa549", - "sha256:7b3b8c015e545fa30e42205fc1115b7c6afcb6acec790ce3f330a06323730523", - "sha256:7fbb6389c20aff4c3257e89bb1787effffcaf05c32d937c00094ae45846bffd5", - "sha256:828d9911acc483672a2bae1cc1bf79f591eb3338faad1f2c798aa2f45459a318", - "sha256:a9460dac973deccc6ff2d90f18fd105cbaada147f84e5917ed79374dcb237758", - "sha256:aade50f9a1b9d20f6aabe88e8999b10db57218f5c31950160f3f7957dd64e07c", - "sha256:ac9e5b282d1f0771a8310ed974afe1961ec31e9ae787d052c0e504ea46ae323a", - "sha256:ba41bd21b89c6713f7077b5f7d4a1c452989190aad5704e215560a266a1ecbab", - "sha256:c309dbbd6c155e961bfd6893496afa5cd184cce6f7dffd87ea68ee048b6f97e1", - "sha256:cfc21b1f80d4655ffa776c505a2576b4d148bbc52bb3e33fedbf6cfbdbc09d1b", - "sha256:d7b26e0b6d81bf14c1239e6a891ac1303a7e882512d990ec330369c7269226d7", - "sha256:f8b7a3e05235ce58a38bf317f71a5cb4ab45d3b34dc57421dd8cea48e0e4023e" - ], - "version": "==4.19.19" + "sha256:02d94786bada670ab17a2b62ce95b3cf8e3b40c99d36007593a6334d551840bb", + "sha256:06bc66b50556fb949f14875a4c224423dbf03f972497ccb883fb19b7b7c3b346", + "sha256:091fbbe10a7aebadc0e8897a9449cda08d3c3f663460d812eca3001ca1ed3526", + "sha256:0a067ade558befe4d46335b13d8b602b5044363bfd601419b556d4ec659bca18", + "sha256:1910c1cb5a388d4e59ebb2895d7015f360f3f6eeb1700e7e33e866c53137eb9e", + "sha256:1c7ad791ec86247f35243bbbdd29cd59989afbe0ab678e0a41211f4407f21dd8", + "sha256:3c330ff1f70b3eaa6f63dce9274df996dffea82ad9726aa8e3d6cbe38e986b2f", + "sha256:482a910fa73ee0e36c258d7646ef38f8061774bbc1765a7da68c65056b573341", + "sha256:7695dfafb4f5549ce1290ae643d6508dfc2646a9003c989218be3ce42a1aa422", + "sha256:8274ed50f4ffbe91d0f4cc5454394631edfecd75dc327aa01be8bc5818a57e88", + "sha256:9047d887d97663790d811ac4e0d2e895f1bf2ecac4041691487de40c30239480", + "sha256:9f6ab1417ecfa6c1ce6ce941e0cebc03e3ec9cd9925058043229a5f003ae5e40", + "sha256:b43ba2f18999d41c3df72f590348152e14cd4f6dcea2058c734d688dfb1ec61f", + "sha256:c3ab9ea1bc3f4ce8c57ebc66fb25cd044ef92ed1ca2afa3729854ecc59658905", + "sha256:da69ba17f6ece9a85617743cb19de689f2d63025bf8001e2facee2ec9bcff18f", + "sha256:ef3c7a0bf78674b0dda86ff5809d8495019903a096c128e1f160984b37848f73", + "sha256:fabff832046643cdb93920ddaa8f77344df90768930fbe6bb33d211c4dcd0b5e" + ], + "markers": "python_version >= '3.5'", + "version": "==12.7.0" }, "pyrsistent": { "hashes": [ @@ -2218,10 +2323,10 @@ }, "python-engineio": { "hashes": [ - "sha256:2a4c874aea686e79f8ea9efc30748110df581df6d577d18bb5eaa1a8f2199d12", - "sha256:eae09ef72bbb13e66ad0bbe2fbb87271e0ba5e2ec8c6693c6be1e14239564e32" + "sha256:4a13fb87c819b855c55a731fdf82559adb8311c04cfdfebd6b9ecd1c2afbb575", + "sha256:9c9a6035b4b5e5a225f426f846afa14cf627f7571d1ae02167cb703fefd134b7" ], - "version": "==3.9.3" + "version": "==3.10.0" }, "python-logstash": { "hashes": [ @@ -2247,10 +2352,10 @@ }, "pytz": { "hashes": [ - "sha256:26c0b32e437e54a18161324a2fca3c4b9846b74a8dccddd843113109e1116b32", - "sha256:c894d57500a4cd2d5c71114aaab77dbab5eabd9022308ce5ac9bb93a60a6f0c7" + "sha256:1c557d7d0e871de1f5ccd5833f60fb2550652da6be2693c1e02300743d21500d", + "sha256:b02c06db6cf09c12dd25137e563b31700d3b80fcc4ad23abb7a315f2789819be" ], - "version": "==2019.2" + "version": "==2019.3" }, "pyvcd": { "hashes": [ @@ -2262,34 +2367,30 @@ }, "pywavelets": { "hashes": [ - "sha256:18b193b67937e805a8e79c036bd2aa4ea3a357737256efeefdabd19c95083c3b", - "sha256:1d7ba03baa81938b17d4819db36f018e680d929af329062af4d4b6d6236d02ba", - "sha256:21f39d86cc35e003576fc1400b15534e2999570418fcdb17ea62d1ff8773b076", - "sha256:250412f482d5cb358b7ec323b2a783d91e5cfc337fdf8fde3c59bf2c35d6366f", - "sha256:25c0c592bf43eaffb4d3c6b6444b14c7407db750b6f2d344d809d4af934319d9", - "sha256:2f2cdd96e4882b0c18e75cc90c4710de429ac226ce53b58a90c7420e3e307631", - "sha256:3abed8dcd3e94ead72ee8010b494df5a9bdbdd5e39129d52fbf8066efa323a51", - "sha256:3e99ab8feeb47755738fb8deb8154c9604c4a7996b1b7db6b090475105ca7c92", - "sha256:64926c4c78dd690ec0d61be20f7c27cfbde6de9fa66ab8205eb079d9db6927fc", - "sha256:687ec8877c10e3a03595ad167d1ea2662bc1ab13ef43d63a6e207a53b2ee4c26", - "sha256:6af0077c7a4c9935aa64301f6942468b494656b8812e801d4a635cf42088f96c", - "sha256:7215856a5d2e1a2dccca1f71d912ee6a7387086f3b3adcb55d7c41314c6abb0c", - "sha256:9e47b241533add77961093b1e40cfff031597d429e91ad7c675838be0f7cc0df", - "sha256:9e782f49dca57bc0fd2a40c0917949d77be2ecc999ccd44fff57fb10aa214135", - "sha256:a12c7a6258c0015d2c75d88b87393ee015494551f049009e8b63eafed2d78efc", - "sha256:a5027d47484498e70391b311a2688c4f74294de629b982ed17be57be4c77ade7", - "sha256:ab02363467ee3cb222c5b425bc53453270ddae72bce313e72fd14616692d725a", - "sha256:adc79308c65a2007bdbd5846fda70088e7ead0ef0a5a6f44d08829e9478a907f", - "sha256:afaaee392450785a346d9e5e5f6e5307b13958d8b0633818632cb38972a7752a", - "sha256:b26b836c7f71df7b2779e62d1338367cfe37b98324e9b0d54b428ac030e3d1f0", - "sha256:b9adbc27d70a2626c235a18b41315de2832c384651d03383db7a58c2a2bccc6f", - "sha256:bd6e62efb7839fd6bf894b7b9aec6d58be0c44a38ea0c9f3c5bea834d84d05eb", - "sha256:de083a3a71576a9c3d8ba73b6f0425e4690d6ac6e480562f30bec5cb20667324", - "sha256:e89551257233a3da717a9e6e2e303243df75faffe0b6781d21c15eb9d682ec6d", - "sha256:eafb7d609c41a04028144f4b6697792f448554960ef353244aaf0a5883263543", - "sha256:fb3ee9f65d25ee5c89104e533d5f341c253cdb9543ef6fcd6dfa599b12e84f1c" - ], - "version": "==1.0.3" + "sha256:076ca8907001fdfe4205484f719d12b4a0262dfe6652fa1cfc3c5c362d14dc84", + "sha256:18a51b3f9416a2ae6e9a35c4af32cf520dd7895f2b69714f4aa2f4342fca47f9", + "sha256:1a64b40f6acb4ffbaccce0545d7fc641744f95351f62e4c6aaa40549326008c9", + "sha256:35959c041ec014648575085a97b498eafbbaa824f86f6e4a59bfdef8a3fe6308", + "sha256:55e39ec848ceec13c9fa1598253ae9dd5c31d09dfd48059462860d2b908fb224", + "sha256:6162dc0ae04669ea04b4b51420777b9ea2d30b0a9d02901b2a3b4d61d159c2e9", + "sha256:68b5c33741d26c827074b3d8f0251de1c3019bb9567b8d303eb093c822ce28f1", + "sha256:720dbcdd3d91c6dfead79c80bf8b00a1d8aa4e5d551dc528c6d5151e4efc3403", + "sha256:7947e51ca05489b85928af52a34fe67022ab5b81d4ae32a4109a99e883a0635e", + "sha256:79f5b54f9dc353e5ee47f0c3f02bebd2c899d49780633aa771fed43fa20b3149", + "sha256:80b924edbc012ded8aa8b91cb2fd6207fb1a9a3a377beb4049b8a07445cec6f0", + "sha256:889d4c5c5205a9c90118c1980df526857929841df33e4cd1ff1eff77c6817a65", + "sha256:935ff247b8b78bdf77647fee962b1cc208c51a7b229db30b9ba5f6da3e675178", + "sha256:98b2669c5af842a70cfab33a7043fcb5e7535a690a00cd251b44c9be0be418e5", + "sha256:9e2528823ccf5a0a1d23262dfefe5034dce89cd84e4e124dc553dfcdf63ebb92", + "sha256:bc5e87b72371da87c9bebc68e54882aada9c3114e640de180f62d5da95749cd3", + "sha256:be105382961745f88d8196bba5a69ee2c4455d87ad2a2e5d1eed6bd7fda4d3fd", + "sha256:c06d2e340c7bf8b9ec71da2284beab8519a3908eab031f4ea126e8ccfc3fd567", + "sha256:cfe79844526dd92e3ecc9490b5031fca5f8ab607e1e858feba232b1b788ff0ea", + "sha256:d510aef84d9852653d079c84f2f81a82d5d09815e625f35c95714e7364570ad4", + "sha256:e02a0558e0c2ac8b8bbe6a6ac18c136767ec56b96a321e0dfde2173adfa5a504" + ], + "markers": "python_version >= '3.5'", + "version": "==1.1.1" }, "pyzmq": { "hashes": [ @@ -2331,11 +2432,11 @@ }, "redis": { "hashes": [ - "sha256:98a22fb750c9b9bb46e75e945dc3f61d0ab30d06117cbb21ff9cd1d315fedd3b", - "sha256:c504251769031b0dd7dd5cf786050a6050197c6de0d37778c80c08cb04ae8275" + "sha256:3613daad9ce5951e426f460deddd5caf469e08a3af633e9578fc77d362becf62", + "sha256:8d0fc278d3f5e1249967cba2eb4a5632d19e45ce5c09442b8422d15ee2c22cc2" ], "index": "pypi", - "version": "==3.3.8" + "version": "==3.3.11" }, "redlock": { "hashes": [ @@ -2377,25 +2478,20 @@ }, "scikit-image": { "hashes": [ - "sha256:0fb4f61ba28e7034dc490b7fd37a35428493cc1180205991aea41ab78c1a3b2a", - "sha256:117244d206f014fcdc7fd3b03dc25ffd3c32be49c5103b916dadcf3c268ce629", - "sha256:2dee5c19893bbfebeb30c2edd47e3092d84fe671e1278c8e1b8ab0b541b88590", - "sha256:2edf2189a89d68e7909bfe939f6f9978d4807c4c2c6464b9d23944171272efe5", - "sha256:56f8ec5106c1b6037f25395eb6a2c29cbbb1baa9d8cedb48a6488a697f9e0c02", - "sha256:5c24501fbe0000bf215418ced56fc718ae5bbd004df7dc460fd3fb095385dec5", - "sha256:6665b00b649237171eb0c34ec7d2c5ee96f51cc826edf1b70654fc05fddec7a8", - "sha256:676838be922fdc7c65a1bfa71409b382874d60e2a7a0c968fe832f63b485842d", - "sha256:6b8697a52e1e3c2663f74a0a972cc601d2ceb5b3299cc9be3c3b6ac41d76d238", - "sha256:91208ff13381ccbacce8a38a771e9d9d8982dce146581bcf6656aa8fd05d06ea", - "sha256:a8fb7dc56b14656768fdf21d4325bf82f543fad51dc83c24aa6a27456a946a2d", - "sha256:bea86976ab9b7bebca43721b3ff8fd74a002e1fd95e7600987cd42664fde8a39", - "sha256:ce9354571e1323ed98251723a7e5ffb3526ddd3b533a27aaca4ebd13ed479c56", - "sha256:df111e654b47e5ea456c50553debe4c5ddd97258894c7ad3b7f2f9f10798e053", - "sha256:ed6d2dbb54a68b200df8783fcb17c406ece20420c8c86508ab0f5966e8631da5", - "sha256:f0491621a6b1d2828d47acaf41d3167a647eaae44ef8fcf83b72eb3e1cc7ac51" - ], - "index": "pypi", - "version": "==0.15.0" + "sha256:063d1c20fcd53762f82ee58c29783ae4e8f6fbed445b41b704fa33b6f355729d", + "sha256:0808ab5f8218d91a1c008036993636535a37efd67a52ab0f2e6e3f4b7e75aeda", + "sha256:2a54bea469eb1b611bee1ce36e60710f5f94f29205bc5bd67a51793909b1e62b", + "sha256:2aa962aa82d815606d7dad7f045f5d7ca55c65b4320d47e15a98fc92612c2d6c", + "sha256:2d346d49b6852cffb47cbde995e2696d5b07f688d8c057a0a4548abf3a98f920", + "sha256:3ad2efa792ab8de5fcefe6f4f5bc1ab64c411cdb5c829ce1526ab3a5a7729627", + "sha256:3af3d781ce085573ced37b2b5b9abfd32ce3d4723bd17f37e829025d189b0421", + "sha256:6786b127f33470fd843e644435522fbf43bce05c9f5527946c390ccb9e1cac27", + "sha256:8b2b768b02c6b7476f2e16ddd91f827d3817aef73f82cf28bff7a8dcdfd8c55c", + "sha256:dd7fbd32da74d4e9967dc15845f731f16e7966cee61f5dc0e12e2abb1305068c", + "sha256:e774377876cb258e8f4d63f7809863f961c98aa02263b3ff54a39483bc6f7d26" + ], + "index": "pypi", + "version": "==0.16.2" }, "scipy": { "hashes": [ @@ -2496,10 +2592,10 @@ }, "sqlalchemy": { "hashes": [ - "sha256:2f8ff566a4d3a92246d367f2e9cd6ed3edeef670dcd6dda6dfdc9efed88bcd80" + "sha256:0f0768b5db594517e1f5e1572c73d14cf295140756431270d89496dc13d5e46c" ], "index": "pypi", - "version": "==1.3.8" + "version": "==1.3.10" }, "subprocess32": { "hashes": [ @@ -2511,11 +2607,11 @@ }, "supervisor": { "hashes": [ - "sha256:43e87c7b572a94acdb586aaebb06844dae1aa02856b984c5a738032abd753fb7", - "sha256:9644990d21a1ba03b1a7ac5e9a0c0c62e12822e258f9e98f4a0b128461b3f10a" + "sha256:2dc86fe0476e945e61483d614ceb2cf4f93b95282eb243bdf792621994360383", + "sha256:a76b2f77a560f2dc411c0254a4eb15f555e99faac48621b0f1fc9ab013944f47" ], "index": "pypi", - "version": "==4.0.4" + "version": "==4.1.0" }, "tenacity": { "hashes": [ @@ -2535,10 +2631,10 @@ }, "tensorflow-estimator": { "hashes": [ - "sha256:54fdfe8712d54627579bc6d524ced43bbd57042cb2ce411bdf2ae46b29a772da" + "sha256:aa8deab25d09a9730dfbae8ec58f4eb00ec2a90b5ca3dcbd8fa0717103d3bbb3" ], "index": "pypi", - "version": "==2.0.0" + "version": "==2.0.1" }, "tensorflow-gpu": { "hashes": [ @@ -2603,20 +2699,25 @@ }, "typed-ast": { "hashes": [ + "sha256:1170afa46a3799e18b4c977777ce137bb53c7485379d9706af8a59f2ea1aa161", "sha256:18511a0b3e7922276346bcb47e2ef9f38fb90fd31cb9223eed42c85d1312344e", "sha256:262c247a82d005e43b5b7f69aff746370538e176131c32dda9cb0f324d27141e", "sha256:2b907eb046d049bcd9892e3076c7a6456c93a25bebfe554e931620c90e6a25b0", "sha256:354c16e5babd09f5cb0ee000d54cfa38401d8b8891eefa878ac772f827181a3c", + "sha256:48e5b1e71f25cfdef98b013263a88d7145879fbb2d5185f2a0c79fa7ebbeae47", "sha256:4e0b70c6fc4d010f8107726af5fd37921b666f5b31d9331f0bd24ad9a088e631", "sha256:630968c5cdee51a11c05a30453f8cd65e0cc1d2ad0d9192819df9978984529f4", "sha256:66480f95b8167c9c5c5c87f32cf437d585937970f3fc24386f313a4c97b44e34", "sha256:71211d26ffd12d63a83e079ff258ac9d56a1376a25bc80b1cdcdf601b855b90b", + "sha256:7954560051331d003b4e2b3eb822d9dd2e376fa4f6d98fee32f452f52dd6ebb2", + "sha256:838997f4310012cf2e1ad3803bce2f3402e9ffb71ded61b5ee22617b3a7f6b6e", "sha256:95bd11af7eafc16e829af2d3df510cecfd4387f6453355188342c3e79a2ec87a", "sha256:bc6c7d3fa1325a0c6613512a093bc2a2a15aeec350451cbdf9e1d4bffe3e3233", "sha256:cc34a6f5b426748a507dd5d1de4c1978f2eb5626d51326e43280941206c209e1", "sha256:d755f03c1e4a51e9b24d899561fec4ccaf51f210d52abdf8c07ee2849b212a36", "sha256:d7c45933b1bdfaf9f36c579671fec15d25b06c8398f113dab64c18ed1adda01d", "sha256:d896919306dd0aa22d0132f62a1b78d11aaf4c9fc5b3410d3c666b818191630a", + "sha256:fdc1c9bbf79510b76408840e009ed65958feba92a88833cdceecff93ae8fff66", "sha256:ffde2fbfad571af120fcbfbbc61c72469e72f550d676c3342492a9dfdefb8f12" ], "markers": "python_version < '3.8' and implementation_name == 'cpython'", diff --git a/README.md b/README.md index 29987ff117781f..564287562b4bfa 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ 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). +[openpilot](http://github.com/commaai/openpilot) is an open source driver assistance system. Currently, it performs the functions of Adaptive Cruise Control (ACC) and Automated Lane Centering (ALC) for selected Honda, Toyota, Acura, Lexus, Chevrolet, Hyundai, Kia, Subaru, Volkswagen. 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. @@ -29,116 +29,116 @@ Community 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). +[Follow us on Twitter](https://twitter.com/comma_ai) and [join our Discord](https://discord.comma.ai). - - - - + + + + - - - - + + + +
Hardware ------ -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. +At the moment openpilot supports the [EON DevKit](https://comma.ai/shop/products/eon-dashcam-devkit). A [car harness](https://comma.ai/shop/products/car-harness) is recommended to connect the EON to the car. We'd like to support other platforms as well. Install openpilot on a neo device by entering ``https://openpilot.comma.ai`` during NEOS setup. Supported Cars ------ -| Make | Model (US Market Reference)| Supported Package | Lateral | Longitudinal | No Accel Below | No Steer Below | Giraffe | -| ---------------------| ---------------------------| ---------------------| --------| ---------------| -----------------| ---------------|-------------------| -| Acura | ILX 2016-18 | AcuraWatch Plus | Yes | Yes | 25mph1| 25mph | Nidec | -| Acura | RDX 2016-18 | AcuraWatch Plus | Yes | Yes | 25mph1| 12mph | Nidec | -| Buick3 | Regal 2018 | Adaptive Cruise | Yes | Yes | 0mph | 7mph | Custom7| -| Chevrolet3| Malibu 2017 | Adaptive Cruise | Yes | Yes | 0mph | 7mph | Custom7| -| Chevrolet3| Volt 2017-18 | Adaptive Cruise | Yes | Yes | 0mph | 7mph | Custom7| -| Cadillac3 | ATS 2018 | Adaptive Cruise | Yes | Yes | 0mph | 7mph | Custom7| -| 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 | -| GMC3 | Acadia Denali 2018 | Adaptive Cruise | Yes | Yes | 0mph | 7mph | Custom7| -| Holden3 | Astra 2017 | Adaptive Cruise | Yes | Yes | 0mph | 7mph | Custom7| -| 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 | 25mph1| 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 | 25mph1| 12mph | Inverted Nidec | -| Honda | Odyssey 2018-19 | Honda Sensing | Yes | Yes | 25mph1| 0mph | Inverted Nidec | -| Honda | Passport 2019 | All | Yes | Yes | 25mph1| 12mph | Inverted Nidec | -| Honda | Pilot 2016-18 | Honda Sensing | Yes | Yes | 25mph1| 12mph | Nidec | -| Honda | Pilot 2019 | All | Yes | Yes | 25mph1| 12mph | Inverted Nidec | -| Honda | Ridgeline 2017-19 | Honda Sensing | Yes | Yes | 25mph1| 12mph | Nidec | -| Hyundai | Santa Fe 2019 | All | Yes | Stock | 0mph | 0mph | Custom6| -| Hyundai | Elantra 2017-19 | SCC + LKAS | Yes | Stock | 19mph | 34mph | Custom6| -| Hyundai | Genesis 2018 | All | Yes | Stock | 19mph | 34mph | Custom6| -| 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 | Custom6| -| Kia | Sorento 2018 | All | Yes | Stock | 0mph | 0mph | Custom6| -| Kia | Stinger 2018 | SCC + LKAS | Yes | Stock | 0mph | 0mph | Custom6| -| Lexus | CT Hybrid 2017-18 | All | Yes | Yes2| 0mph | 0mph | Toyota | -| Lexus | ES Hybrid 2019 | All | Yes | Yes | 0mph | 0mph | Toyota | -| Lexus | RX Hybrid 2016-19 | All | Yes | Yes2| 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 | EyeSight | Yes | Stock | 0mph | 0mph | Custom4| -| Subaru | Impreza 2019 | EyeSight | Yes | Stock | 0mph | 0mph | Custom4| -| Toyota | Avalon 2016 | TSS-P | Yes | Yes2| 20mph1| 0mph | Toyota | -| Toyota | Avalon 2017-18 | All | Yes | Yes2| 20mph1| 0mph | Toyota | -| Toyota | Camry 2018-19 | All | Yes | Stock | 0mph5 | 0mph | Toyota | -| Toyota | Camry Hybrid 2018-19 | All | Yes | Stock | 0mph5 | 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 | Yes2| 20mph1| 0mph | Toyota | -| Toyota | Corolla 2020 | All | Yes | Yes | 0mph | 0mph | Toyota | -| Toyota | Corolla Hatchback 2019 | All | Yes | Yes | 0mph | 0mph | Toyota | -| Toyota | Highlander 2017-19 | All | Yes | Yes2| 0mph | 0mph | Toyota | -| Toyota | Highlander Hybrid 2017-19 | All | Yes | Yes2| 0mph | 0mph | Toyota | -| Toyota | Prius 2016 | TSS-P | Yes | Yes2| 0mph | 0mph | Toyota | -| Toyota | Prius 2017-19 | All | Yes | Yes2| 0mph | 0mph | Toyota | -| Toyota | Prius Prime 2017-20 | All | Yes | Yes2| 0mph | 0mph | Toyota | -| Toyota | Rav4 2016 | TSS-P | Yes | Yes2| 20mph1| 0mph | Toyota | -| Toyota | Rav4 2017-18 | All | Yes | Yes2| 20mph1| 0mph | Toyota | -| Toyota | Rav4 2019 | All | Yes | Yes | 0mph | 0mph | Toyota | -| Toyota | Rav4 Hybrid 2016 | TSS-P | Yes | Yes2| 0mph | 0mph | Toyota | -| Toyota | Rav4 Hybrid 2017-18 | All | Yes | Yes2| 0mph | 0mph | Toyota | -| Toyota | Rav4 Hybrid 2019 | All | Yes | Yes | 0mph | 0mph | Toyota | -| Toyota | Sienna 2018 | All | Yes | Yes2| 0mph | 0mph | Toyota | +| Make | Model (US Market Reference) | Supported Package | Lateral | Longitudinal | No Accel Below | No Steer Below | +| ----------------------| -----------------------------------| ---------------------| --------| ---------------| -----------------| ---------------| +| Acura | ILX 2016-18 | AcuraWatch Plus | Yes | Yes | 25mph1| 25mph | +| Acura | RDX 2016-18 | AcuraWatch Plus | Yes | Yes | 25mph1| 12mph | +| Buick3 | Regal 20186 | Adaptive Cruise | Yes | Yes | 0mph | 7mph | +| Chevrolet3 | Malibu 20176 | Adaptive Cruise | Yes | Yes | 0mph | 7mph | +| Chevrolet3 | Volt 2017-186 | Adaptive Cruise | Yes | Yes | 0mph | 7mph | +| Cadillac3 | ATS 2018 | Adaptive Cruise | Yes | Yes | 0mph | 7mph | +| Chrysler | Pacifica 2017-187 | Adaptive Cruise | Yes | Stock | 0mph | 9mph | +| Chrysler | Pacifica Hybrid 2017-187| Adaptive Cruise | Yes | Stock | 0mph | 9mph | +| Chrysler | Pacifica Hybrid 20197 | Adaptive Cruise | Yes | Stock | 0mph | 39mph | +| GMC3 | Acadia Denali 20186 | Adaptive Cruise | Yes | Yes | 0mph | 7mph | +| Holden3 | Astra 20176 | Adaptive Cruise | Yes | Yes | 0mph | 7mph | +| Honda | Accord 2018-19 | All | Yes | Stock | 0mph | 3mph | +| Honda | Accord Hybrid 2018-19 | All | Yes | Stock | 0mph | 3mph | +| Honda | Civic Sedan/Coupe 2016-18 | Honda Sensing | Yes | Yes | 0mph | 12mph | +| Honda | Civic Sedan/Coupe 2019 | Honda Sensing | Yes | Stock | 0mph | 2mph | +| Honda | Civic Hatchback 2017-19 | Honda Sensing | Yes | Stock | 0mph | 12mph | +| Honda | CR-V 2015-16 | Touring | Yes | Yes | 25mph1| 12mph | +| Honda | CR-V 2017-19 | Honda Sensing | Yes | Stock | 0mph | 12mph | +| Honda | CR-V Hybrid 2017-2019 | Honda Sensing | Yes | Stock | 0mph | 12mph | +| Honda | Fit 2018-19 | Honda Sensing | Yes | Yes | 25mph1| 12mph | +| Honda | Odyssey 2018-19 | Honda Sensing | Yes | Yes | 25mph1| 0mph | +| Honda | Passport 2019 | All | Yes | Yes | 25mph1| 12mph | +| Honda | Pilot 2016-18 | Honda Sensing | Yes | Yes | 25mph1| 12mph | +| Honda | Pilot 2019 | All | Yes | Yes | 25mph1| 12mph | +| Honda | Ridgeline 2017-19 | Honda Sensing | Yes | Yes | 25mph1| 12mph | +| Hyundai | Santa Fe 20195 | All | Yes | Stock | 0mph | 0mph | +| Hyundai | Elantra 2017-195 | SCC + LKAS | Yes | Stock | 19mph | 34mph | +| Hyundai | Genesis 20185 | All | Yes | Stock | 19mph | 34mph | +| Jeep | Grand Cherokee 2016-187 | Adaptive Cruise | Yes | Stock | 0mph | 9mph | +| Jeep | Grand Cherokee 20197 | Adaptive Cruise | Yes | Stock | 0mph | 39mph | +| Kia | Optima 20195 | SCC + LKAS | Yes | Stock | 0mph | 0mph | +| Kia | Sorento 20185 | All | Yes | Stock | 0mph | 0mph | +| Kia | Stinger 20185 | SCC + LKAS | Yes | Stock | 0mph | 0mph | +| Lexus | CT Hybrid 2017-18 | All | Yes | Yes2| 0mph | 0mph | +| Lexus | ES Hybrid 2019 | All | Yes | Yes | 0mph | 0mph | +| Lexus | RX Hybrid 2016-19 | All | Yes | Yes2| 0mph | 0mph | +| Lexus | IS 2017-2019 | All | Yes | Stock | 22mph | 0mph | +| Lexus | IS Hybrid 2017 | All | Yes | Stock | 0mph | 0mph | +| Subaru | Crosstrek 2018-19 | EyeSight | Yes | Stock | 0mph | 0mph | +| Subaru | Impreza 2019-20 | EyeSight | Yes | Stock | 0mph | 0mph | +| Toyota | Avalon 2016 | TSS-P | Yes | Yes2| 20mph1| 0mph | +| Toyota | Avalon 2017-18 | All | Yes | Yes2| 20mph1| 0mph | +| Toyota | Camry 2018-19 | All | Yes | Stock | 0mph4 | 0mph | +| Toyota | Camry Hybrid 2018-19 | All | Yes | Stock | 0mph4 | 0mph | +| Toyota | C-HR 2017-19 | All | Yes | Stock | 0mph | 0mph | +| Toyota | C-HR Hybrid 2017-19 | All | Yes | Stock | 0mph | 0mph | +| Toyota | Corolla 2017-19 | All | Yes | Yes2| 20mph1| 0mph | +| Toyota | Corolla 2020 | All | Yes | Yes | 0mph | 0mph | +| Toyota | Corolla Hatchback 2019 | All | Yes | Yes | 0mph | 0mph | +| Toyota | Corolla Hybrid 2020 | All | Yes | Yes | 0mph | 0mph | +| Toyota | Highlander 2017-19 | All | Yes | Yes2| 0mph | 0mph | +| Toyota | Highlander Hybrid 2017-19 | All | Yes | Yes2| 0mph | 0mph | +| Toyota | Prius 2016 | TSS-P | Yes | Yes2| 0mph | 0mph | +| Toyota | Prius 2017-19 | All | Yes | Yes2| 0mph | 0mph | +| Toyota | Prius Prime 2017-20 | All | Yes | Yes2| 0mph | 0mph | +| Toyota | Rav4 2016 | TSS-P | Yes | Yes2| 20mph1| 0mph | +| Toyota | Rav4 2017-18 | All | Yes | Yes2| 20mph1| 0mph | +| Toyota | Rav4 2019 | All | Yes | Yes | 0mph | 0mph | +| Toyota | Rav4 Hybrid 2016 | TSS-P | Yes | Yes2| 0mph | 0mph | +| Toyota | Rav4 Hybrid 2017-18 | All | Yes | Yes2| 0mph | 0mph | +| Toyota | Sienna 2018 | All | Yes | Yes2| 0mph | 0mph | +| Volkswagen8| Golf 2016-19 | Driver Assistance | Yes | Stock | 0mph | 0mph | 1[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).***
2When 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).***
3[GM installation guide](https://zoneos.com/volt/). ***NOTE: disconnecting the ASCM disables Automatic Emergency Braking (AEB).***
-4Subaru Giraffe is DIY.
-528mph for Camry 4CYL L, 4CYL LE and 4CYL SE which don't have Full-Speed Range Dynamic Radar Cruise Control.
-6Open 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.
-7Community built Giraffe, find more information [here](https://zoneos.com/shop/).
+428mph for Camry 4CYL L, 4CYL LE and 4CYL SE which don't have Full-Speed Range Dynamic Radar Cruise Control.
+5Requires 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 Hyundais.
+6Requires a [panda](https://comma.ai/shop/products/panda-obd-ii-dongle) and community built giraffe, find more information [here](https://zoneos.com/shop/).
+7Requires a [panda](https://comma.ai/shop/products/panda-obd-ii-dongle) and FCA [giraffe](https://comma.ai/shop/products/giraffe)
+8Requires a [custom connector](https://community.comma.ai/wiki/index.php/Volkswagen#Integration_at_J533_Gateway) for the [car harness](https://comma.ai/shop/products/car-harness)
Community Maintained Cars ------ -| 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 | Custom8| +| Make | Model (US Market Reference) | Supported Package | Lateral | Longitudinal | No Accel Below | No Steer Below | +| ---------------------| -----------------------------------| ---------------------| --------| ---------------| -----------------| ---------------| +| Tesla | Model S 2012-139 | All | Yes | NA | NA | 0mph | [[Tesla Model S Pull Request]](https://github.com/commaai/openpilot/pull/246)
-8Community built Giraffe, find more information here [Community Tesla Giraffe](https://github.com/jeankalud/neo/tree/tesla_giraffe/giraffe/tesla)
+9Requires a [panda](https://comma.ai/shop/products/panda-obd-ii-dongle) and community built giraffe, find more information [here](https://github.com/jeankalud/neo/tree/tesla_giraffe/giraffe/tesla).
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. @@ -149,6 +149,7 @@ In Progress Cars - All Kia, Genesis with SCC and LKAS. - All Chrysler, Jeep, Fiat with Adaptive Cruise Control and LaneSense. - All Subaru with EyeSight. +- All Volkswagen, Audi, Škoda and SEAT with Adaptive Cruise Control. How can I add support for my car? ------ @@ -203,7 +204,7 @@ It logs the road facing camera, CAN, GPS, IMU, magnetometer, thermal sensors, cr 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. +By using it, 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.ai. By accepting this agreement, you grant an irrevocable, perpetual, worldwide right to comma.ai for the use of this data. Testing on PC ------ diff --git a/RELEASES.md b/RELEASES.md index 1cabbf1200bd15..839f41d7379e8a 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,13 +1,26 @@ +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.1 (2019-10-17) ======================== * Enable auto updater, every 30 minutes with auto reboot, can be disabled in multiple ways of needed * FAST Braking due to acceleration in corners based on steering angle now and later predicted from model - + Version 0.6.5 (2019-10-07) ======================== * NEOS update: upgrade to Python3 and new installer! * comma Harness support! - * New driving model: lateral control has lower reliance on lanelines + * New driving model: improve path prediction * New driver monitoring model: more accurate face and eye detection * Redesign offroad screen to display updates and alerts * Increase maximum allowed acceleration @@ -67,7 +80,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 TSS2 + * Improve tuning for supported Toyota with TSS 2.0 * Various other stability improvements Version 0.5.13 (2019-05-31) diff --git a/SAFETY.md b/SAFETY.md index 3cda811e0cd9f9..f3089c497b22ab 100644 --- a/SAFETY.md +++ b/SAFETY.md @@ -1,8 +1,8 @@ openpilot Safety ====== -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 +openpilot is an Adaptive Cruise Control (ACC) and Automated Lane Centering (ALC) system. +Like other ACC and ALC 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**. @@ -93,7 +93,7 @@ GM/Chevrolet 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 + torque exceeds 12 units in the opposite direction 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, @@ -116,7 +116,7 @@ Hyundai/Kia (Lateral only) 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 + torque exceeds 50 units in the opposite direction to ensure limited applied torque against the driver's will. Chrysler/Jeep/Fiat (Lateral only) @@ -144,8 +144,31 @@ Subaru (Lateral only) 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 + torque exceeds 60 units in the opposite direction to ensure limited applied torque against the driver's will. +Volkswagen, Audi, SEAT, Škoda (Lateral only) +------ + + - While the system is engaged, steer commands are subject to the same limits used by the stock system, and + additional limits required to meet Comma safety standards. + + - Steering torque is controlled through the CAN message 0x126, also known as HCA_01 for Heading Control Assist. + It's limited by openpilot and Panda to a value between -250 and 250, representing 2.5 Nm of torque applied + at the steering rack. The vehicle EPS unit will fault for values outside -300 and 300. + + - The vehicle EPS unit will tolerate any rate of increase or decrease, but may limit the effective rate of + change to 5.0 Nm/s. In accordance with the Comma AI safety model requirements, a rate limit is enforced by + the Panda firmware and by openpilot, so that the commanded steering torque cannot rise from 0 to maximum + faster than 1.25s. Commanded steering torque is gradually limited by the Panda firmware and by openpilot + if the driver's torque exceeds 0.8 Nm in the opposite direction to ensure limited applied torque against + the driver's will. + + - Brake and gas pedal pressed signals are contained in the ESP_05 0x106 and Motor_20 0x121 CAN messages, + respectively. A rising edge of either signals triggers a disengagement and is enforced by openpilot. + The cancellation due to the rising edge of the gas pressed signal is also enforced by the Panda firmware. + Additionally, the cruise control system disengages on the rising edge of the brake pedal pressed signal, + and it's enforced by both openpilot and the Panda firmware. + **Extra note**: comma.ai strongly discourages the use of openpilot forks with safety code either missing or not fully meeting the above requirements. diff --git a/apk/ai.comma.plus.offroad.apk b/apk/ai.comma.plus.offroad.apk index 224f4b066af432..d8c84cc6bd2d25 100644 Binary files a/apk/ai.comma.plus.offroad.apk and b/apk/ai.comma.plus.offroad.apk differ diff --git a/cereal/log.capnp b/cereal/log.capnp index 30e346668d0ac8..0fd5155bf691bc 100644 --- a/cereal/log.capnp +++ b/cereal/log.capnp @@ -297,7 +297,7 @@ struct HealthData { # from can health voltage @0 :UInt32; current @1 :UInt32; - started @2 :Bool; + ignitionLine @2 :Bool; controlsAllowed @3 :Bool; gasInterceptorDetected @4 :Bool; startedSignalDetectedDeprecated @5 :Bool; @@ -308,6 +308,8 @@ struct HealthData { hwType @10 :HwType; fanSpeedRpm @11 :UInt16; usbPowerMode @12 :UsbPowerMode; + ignitionCan @13 :Bool; + safetyModel @14 :Car.CarParams.SafetyModel; enum HwType { unknown @0; @@ -1723,6 +1725,7 @@ struct DriverMonitoring { rightEyeProb @7 :Float32; leftBlinkProb @8 :Float32; rightBlinkProb @9 :Float32; + irPwr @10 :Float32; } struct Boot { diff --git a/check_code_quality.sh b/check_code_quality.sh index 854d757a847254..aed17230eb243d 100644 --- a/check_code_quality.sh +++ b/check_code_quality.sh @@ -1,6 +1,7 @@ #!/bin/bash -pyflakes $(find . -iname "*.py" | grep -vi "^\./pyextra.*" | grep -vi "^\./panda") +# Only pyflakes checks (--select=F) +flake8 --select=F $(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") diff --git a/common/kalman/simple_kalman.py b/common/kalman/simple_kalman.py index 0b35555b614ba3..b6fdb7da2c829b 100644 --- a/common/kalman/simple_kalman.py +++ b/common/kalman/simple_kalman.py @@ -6,5 +6,4 @@ subprocess.check_call(["make", "simple_kalman_impl.so"], cwd=kalman_dir) from .simple_kalman_impl import KF1D as KF1D -# Silence pyflakes assert KF1D diff --git a/common/op_params.py b/common/op_params.py index d43e9bf76587f5..3f63638b4cc36e 100644 --- a/common/op_params.py +++ b/common/op_params.py @@ -32,7 +32,7 @@ def __init__(self): self.read_timeout = 1.0 # max frequency to read with self.get(...) (sec) self.default_params = {'camera_offset': 0.06, 'awareness_factor': 2.0, 'lane_hug_direction': None, 'lane_hug_mod': 1.2, 'lane_hug_angle': 10, 'use_car_caching': True, 'osm': True, - 'speed_offset': 0} + 'speed_offset': 0, 'keep_openpilot_engaged': True} self.force_update = False # replaces values with default params if True, not just add add missing key/value pairs self.run_init() # restores, reads, and updates params diff --git a/common/params.py b/common/params.py index 3e6670cdb485c5..170af6ab6f79ac 100644 --- a/common/params.py +++ b/common/params.py @@ -77,10 +77,11 @@ class UnknownKeyName(Exception): "LiveParameters": [TxType.PERSISTENT], "LongitudinalControl": [TxType.PERSISTENT], "OpenpilotEnabledToggle": [TxType.PERSISTENT], + "PandaFirmware": [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], @@ -90,9 +91,11 @@ class UnknownKeyName(Exception): "Version": [TxType.PERSISTENT], "CachedFingerprint": [TxType.PERSISTENT], "Offroad_ChargeDisabled": [TxType.CLEAR_ON_MANAGER_START, TxType.CLEAR_ON_PANDA_DISCONNECT], - "Offroad_TemperatureTooHigh": [TxType.CLEAR_ON_MANAGER_START], - "Offroad_ConnectivityNeededPrompt": [TxType.CLEAR_ON_MANAGER_START], "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], } diff --git a/models/driving_model.dlc b/models/driving_model.dlc index 419cee019c4df7..e04f9f93a1a0fa 100644 Binary files a/models/driving_model.dlc and b/models/driving_model.dlc differ diff --git a/models/monitoring_model.dlc b/models/monitoring_model.dlc index 58615915b0f829..d252d5d158dbbc 100644 Binary files a/models/monitoring_model.dlc and b/models/monitoring_model.dlc differ diff --git a/opendbc/generator/toyota/lexus_is_2018_pt.dbc b/opendbc/generator/toyota/lexus_is_2018_pt.dbc index ffcd949f05fbd3..e1a6922e89ce71 100644 --- a/opendbc/generator/toyota/lexus_is_2018_pt.dbc +++ b/opendbc/generator/toyota/lexus_is_2018_pt.dbc @@ -6,6 +6,9 @@ BO_ 550 BRAKE_MODULE: 8 XXX SG_ BRAKE_POSITION : 16|9@0+ (1,0) [0|511] "" XXX SG_ BRAKE_PRESSED : 37|1@0+ (1,0) [0|1] "" XXX +BO_ 581 GAS_PEDAL_ALT: 5 XXX + SG_ GAS_PEDAL : 23|8@0+ (0.005,0) [0|1] "" XXX + BO_ 705 GAS_PEDAL: 8 XXX SG_ GAS_RELEASED : 3|1@0+ (1,0) [0|1] "" XXX SG_ GAS_PEDAL : 55|8@0+ (0.005,0) [0|1] "" XXX @@ -15,6 +18,7 @@ BO_ 608 STEER_TORQUE_SENSOR: 8 XXX SG_ STEER_TORQUE_DRIVER : 15|16@0- (1,0) [-32768|32767] "" XXX SG_ STEER_OVERRIDE : 0|1@0+ (1,0) [0|1] "" XXX SG_ CHECKSUM : 63|8@0+ (1,0) [0|255] "" XXX + SG_ STEER_ANGLE : 31|16@0- (0.0573,0) [-500|500] "" XXX BO_ 610 EPS_STATUS: 5 EPS SG_ IPAS_STATE : 3|4@0+ (1,0) [0|15] "" XXX diff --git a/opendbc/honda_accord_touring_2016_can.dbc b/opendbc/honda_accord_touring_2016_can.dbc index e8f388de08692c..744e55a9b5e3b5 100644 --- a/opendbc/honda_accord_touring_2016_can.dbc +++ b/opendbc/honda_accord_touring_2016_can.dbc @@ -177,14 +177,14 @@ BO_ 597 ROUGH_WHEEL_SPEED: 8 VSA SG_ SET_TO_X55_2 : 47|8@0+ (1,0) [0|255] "" NEO SG_ LONG_COUNTER : 55|8@0+ (1,0) [0|255] "" XXX SG_ COUNTER : 61|2@0+ (1,0) [0|3] "" XXX - SG_ CHECKSUM : 59|4@1+ (1,0) [0|15] "" XXX + SG_ CHECKSUM : 59|4@0+ (1,0) [0|15] "" XXX BO_ 660 SCM_COMMANDS: 8 SCM SG_ RIGHT_BLINKER : 6|1@0+ (1,0) [0|1] "" NEO SG_ LEFT_BLINKER : 5|1@0+ (1,0) [0|1] "" NEO SG_ WIPERS_SPEED : 4|2@0+ (1,0) [0|3] "" NEO SG_ COUNTER : 61|2@0+ (1,0) [0|3] "" XXX - SG_ CHECKSUM : 59|4@1+ (1,0) [0|15] "" XXX + SG_ CHECKSUM : 59|4@0+ (1,0) [0|15] "" XXX BO_ 661 XXX_10: 4 XXX SG_ COUNTER : 29|2@0+ (1,0) [0|3] "" XXX diff --git a/opendbc/lexus_is_2018_pt_generated.dbc b/opendbc/lexus_is_2018_pt_generated.dbc index ac6bdf3832e5dc..0b1f5315e40e09 100644 --- a/opendbc/lexus_is_2018_pt_generated.dbc +++ b/opendbc/lexus_is_2018_pt_generated.dbc @@ -365,6 +365,9 @@ BO_ 550 BRAKE_MODULE: 8 XXX SG_ BRAKE_POSITION : 16|9@0+ (1,0) [0|511] "" XXX SG_ BRAKE_PRESSED : 37|1@0+ (1,0) [0|1] "" XXX +BO_ 581 GAS_PEDAL_ALT: 5 XXX + SG_ GAS_PEDAL : 23|8@0+ (0.005,0) [0|1] "" XXX + BO_ 705 GAS_PEDAL: 8 XXX SG_ GAS_RELEASED : 3|1@0+ (1,0) [0|1] "" XXX SG_ GAS_PEDAL : 55|8@0+ (0.005,0) [0|1] "" XXX @@ -374,6 +377,7 @@ BO_ 608 STEER_TORQUE_SENSOR: 8 XXX SG_ STEER_TORQUE_DRIVER : 15|16@0- (1,0) [-32768|32767] "" XXX SG_ STEER_OVERRIDE : 0|1@0+ (1,0) [0|1] "" XXX SG_ CHECKSUM : 63|8@0+ (1,0) [0|255] "" XXX + SG_ STEER_ANGLE : 31|16@0- (0.0573,0) [-500|500] "" XXX BO_ 610 EPS_STATUS: 5 EPS SG_ IPAS_STATE : 3|4@0+ (1,0) [0|15] "" XXX diff --git a/opendbc/luxgen_s5_2015.dbc b/opendbc/luxgen_s5_2015.dbc new file mode 100644 index 00000000000000..855e67bfeba9e5 --- /dev/null +++ b/opendbc/luxgen_s5_2015.dbc @@ -0,0 +1,153 @@ +VERSION "" + + +NS_ : + NS_DESC_ + CM_ + BA_DEF_ + BA_ + VAL_ + CAT_DEF_ + CAT_ + FILTER + BA_DEF_DEF_ + EV_DATA_ + ENVVAR_DATA_ + SGTYPE_ + SGTYPE_VAL_ + BA_DEF_SGTYPE_ + BA_SGTYPE_ + SIG_TYPE_REF_ + VAL_TABLE_ + SIG_GROUP_ + SIG_VALTYPE_ + SIGTYPE_VALTYPE_ + BO_TX_BU_ + BA_DEF_REL_ + BA_REL_ + BA_DEF_DEF_REL_ + BU_SG_REL_ + BU_EV_REL_ + BU_BO_REL_ + SG_MUL_VAL_ + +BS_: + +BU_: XXX + + +BO_ 928 EPB_STATUS: 8 XXX + SG_ EPB_BRAKE : 16|1@1+ (1,0) [0|3] "" XXX + +BO_ 1104 SEATBELT_STATUS: 8 XXX + SG_ DRIVER_SEAT_BELT_ONOFF : 21|1@0+ (1,0) [0|3] "" XXX + +BO_ 1056 BODY_ECU_STATUS: 8 XXX + SG_ DOOR_RL_STATUS : 18|1@0+ (1,0) [0|255] "" XXX + SG_ DOOR_FL_STATUS : 13|1@0+ (1,0) [0|1] "" XXX + SG_ DOOR_FR_STATUS : 12|1@0+ (1,0) [0|1] "" XXX + SG_ DOOR_RR_STATUS : 19|1@0+ (1,0) [0|1] "" XXX + SG_ DOOR_BACK_DOOR_STATUS : 22|1@0+ (1,0) [0|1] "" XXX + SG_ LEFT_SIGNAL_STATUS : 10|1@0+ (1,0) [0|1] "" XXX + SG_ RIGHT_SIGNAL_STATUS : 9|1@0+ (1,0) [0|1] "" XXX + +BO_ 832 GEAR_RPM_SPEED_STATUS: 8 XXX + SG_ TRANS_MODE : 7|5@1+ (1,0) [0|0] "" XXX + SG_ TRANS_GEAR_POS : 2|3@0+ (1,0) [0|1] "" XXX + SG_ ENGINE_RPM1 : 55|8@0+ (1,0) [0|255] "" XXX + SG_ ENGINE_TEMP : 63|8@0+ (1,0) [0|255] "" XXX + +BO_ 821 THROTTLE_STATUS: 8 XXX + SG_ CRUSE_ONOFF : 2|1@0+ (1,0) [0|1] "on/off" XXX + SG_ CRUSE_ENABLED : 4|1@0+ (1,0) [0|1] "" XXX + SG_ THROTTLE_PEDAL_POS : 32|8@1+ (1,0) [0|255] "" XXX + SG_ THROTTLE_POS : 24|8@1+ (1,0) [0|255] "" XXX + SG_ RPM : 48|8@1- (1,0) [0|65535] "" XXX + +BO_ 922 STEERING_ANGLE_STATUS: 8 XXX + SG_ STEER_ANGLE_9000 : 7|16@0- (1,0) [0|65535] "" XXX + +BO_ 906 WHEEL_SPEEDS: 8 XXX + SG_ SPEED_FR : 24|8@1+ (1,0) [0|255] "" XXX + SG_ ABS_UNDEF1 : 32|8@1+ (1,0) [0|255] "" XXX + SG_ SPEED_FL : 0|8@1+ (1,0) [0|255] "" XXX + +BO_ 848 ABS_WHEELS_STATUS: 8 XXX + SG_ NEW_SIGNAL_1 : 23|8@0+ (1,0) [0|255] "" XXX + SG_ NEW_SIGNAL_2 : 31|8@0+ (1,0) [0|255] "" XXX + SG_ NEW_SIGNAL_3 : 7|8@0+ (1,0) [0|255] "" XXX + SG_ NEW_SIGNAL_4 : 15|8@0+ (1,0) [0|255] "" XXX + +BO_ 1402 DASH_STATUS: 8 XXX + SG_ CAR_SPEED : 32|8@1+ (1,0) [0|255] "" XXX + SG_ DASH_INFO2 : 16|8@1+ (1,0) [0|255] "" XXX + SG_ DASH_INFO0 : 0|8@1+ (1,0) [0|255] "" XXX + SG_ DASH_INFO_2 : 15|8@0+ (1,0) [0|255] "" XXX + SG_ DASH_INFO_3 : 31|8@0+ (1,0) [0|255] "" XXX + +BO_ 1306 _SPEEDX: 8 XXX + SG_ DASH_CAR_SPEED : 7|9@0+ (1,0) [0|255] "" XXX + +BO_ 1296 undefined: 8 XXX + +BO_ 790 ENGINE_DATA: 8 XXX + SG_ _X2 : 6|1@0+ (1,0) [0|1] "" XXX + SG_ NEW_SIGNAL_1 : 15|8@0+ (1,0) [0|255] "" XXX + SG_ NEW_SIGNAL_2 : 23|8@0+ (1,0) [0|255] "" XXX + SG_ NEW_SIGNAL_3 : 31|8@0+ (1,0) [0|255] "" XXX + SG_ NEW_SIGNAL_4 : 39|8@0+ (1,0) [0|255] "" XXX + SG_ NEW_SIGNAL_5 : 47|8@0+ (1,0) [0|255] "" XXX + +BO_ 1313 undefined: 8 XXX + +BO_ 1312 __trigger_every_range: 8 XXX + SG_ __SIGNAL_every_interval : 4|1@0+ (1,0) [0|1] "" XXX + +BO_ 896 undefined: 8 XXX + SG_ NEW_SIGNAL_1 : 32|4@1+ (1,0) [0|15] "" XXX + +BO_ 809 undefined: 8 XXX + +BO_ 864 BREAK_TCS_STATUS: 8 XXX + SG_ SPEED3 : 24|8@1+ (1,0) [0|255] "" XXX + SG_ TCS_ON_FF : 45|1@0+ (1,0) [0|1] "" XXX + SG_ XXXX1 : 63|8@0+ (1,0) [0|255] "" XXX + SG_ BRAKE_PRSSED : 42|1@0+ (1,0) [0|1] "" XXX + +BO_ 842 undefined: 8 XXX + +BO_ 880 WHEEL_RPM_STATUS: 8 XXX + SG_ WHEEL_RL_SPEED : 23|16@0+ (1,0) [0|255] "" XXX + SG_ WHEEL_FR_SPEED : 39|16@0+ (1,0) [0|255] "" XXX + SG_ WHEEL_FL_SPEED : 55|16@0+ (1,0) [0|255] "" XXX + SG_ WHEEL_RR_SPEED : 7|16@0- (1,0) [0|255] "" XXX + +BO_ 1040 CONSOLE_STATUS: 8 XXX + SG_ LEFT_SIGNAL_SWITCH : 1|1@0+ (1,0) [0|1] "" XXX + SG_ RIGHT_SIGNAL_SWITCH : 2|1@0+ (1,0) [0|1] "" XXX + SG_ HEAD_LIGHT_HANDLE_SWITCH : 3|1@0+ (1,0) [0|1] "" XXX + SG_ HID_LIGHT_SWITCH : 4|1@0+ (1,0) [0|1] "" XXX + SG_ YELLOW_WARN_TEMP_TRIGGER : 5|1@0+ (1,0) [0|1] "" XXX + SG_ HID_LIGHT_HANDLE_SWITCH : 6|1@0+ (1,0) [0|1] "" XXX + SG_ MIX_MODE : 7|1@0+ (1,0) [0|1] "" XXX + SG_ slider_rain_bar : 13|1@0+ (1,0) [0|1] "" XXX + SG_ temp_slider_rain_bar : 15|1@0+ (1,0) [0|1] "" XXX + SG_ temp_water_push : 11|1@0+ (1,0) [0|1] "" XXX + +BO_ 1120 HAVC_STATUS: 8 XXX + SG_ HAVC_TEMP : 32|8@1+ (1,0) [0|255] "" XXX + + +CM_ SG_ 1104 DRIVER_SEAT_BELT_ONOFF "0 - on , 1 = off"; +CM_ SG_ 1056 DOOR_RL_STATUS "04 - RL - open"; +CM_ SG_ 1056 DOOR_FL_STATUS "28 - FL open , 38 - FR"; +CM_ SG_ 1056 RIGHT_SIGNAL_STATUS "R,L shows at same time means hazard"; +CM_ SG_ 832 TRANS_MODE "AT - 85 / MT - 8D"; +CM_ SG_ 832 TRANS_GEAR_POS "R-7 , 0 - N"; +CM_ SG_ 821 CRUSE_ONOFF "Cruse Switch"; +CM_ SG_ 821 CRUSE_ENABLED "Cruse enabled"; +CM_ SG_ 821 THROTTLE_PEDAL_POS "Real Pedal Pos"; +CM_ SG_ 821 THROTTLE_POS "Throttle Pos for Cruse Mode"; +CM_ SG_ 906 ABS_UNDEF1 "ABS force"; +CM_ SG_ 906 SPEED_FL "used for car speed in dash board"; +CM_ SG_ 864 TCS_ON_FF "ON = 1, OFF =0"; diff --git a/opendbc/subaru_outback_2016_eyesight.dbc b/opendbc/subaru_outback_2016_eyesight.dbc deleted file mode 100644 index 871f7821843231..00000000000000 --- a/opendbc/subaru_outback_2016_eyesight.dbc +++ /dev/null @@ -1,73 +0,0 @@ -VERSION "" - - -NS_ : - NS_DESC_ - CM_ - BA_DEF_ - BA_ - VAL_ - CAT_DEF_ - CAT_ - FILTER - BA_DEF_DEF_ - EV_DATA_ - ENVVAR_DATA_ - SGTYPE_ - SGTYPE_VAL_ - BA_DEF_SGTYPE_ - BA_SGTYPE_ - SIG_TYPE_REF_ - VAL_TABLE_ - SIG_GROUP_ - SIG_VALTYPE_ - SIGTYPE_VALTYPE_ - BO_TX_BU_ - BA_DEF_REL_ - BA_REL_ - BA_DEF_DEF_REL_ - BU_SG_REL_ - BU_EV_REL_ - BU_BO_REL_ - SG_MUL_VAL_ - -BS_: - -BU_: XXX - - -BO_ 884 DoorStatus: 8 XXX - SG_ DoorOpenFD : 24|1@0+ (1,0) [0|1] "" XXX - SG_ DoorOpenFP : 25|1@0+ (1,0) [0|1] "" XXX - SG_ DoorOpenRP : 26|1@0+ (1,0) [0|1] "" XXX - SG_ DoorOpenRD : 27|1@0+ (1,0) [0|1] "" XXX - SG_ DoorOpenHatch : 28|1@0+ (1,0) [0|1] "" XXX - -BO_ 324 CruiseControl: 7 XXX - SG_ BrakeApplied : 8|1@0+ (1,0) [0|0] "" XXX - SG_ CruiseEnabled : 48|1@0+ (1,0) [0|0] "" XXX - SG_ BrakeStatus : 51|1@0+ (1,0) [0|0] "" XXX - SG_ CruiseButtons : 4|2@0+ (1,0) [0|3] "" XXX - -BO_ 320 Throttle: 8 XXX - SG_ ThrottlePosition : 7|8@0+ (1,0) [0|255] "" XXX - -BO_ 209 NEW_MSG_1: 8 XXX - SG_ BrakePosition : 23|8@0+ (1,0) [0|255] "" XXX - -BO_ 2 Steering: 8 XXX - SG_ SteeringAngle : 7|16@0- (0.1,0) [-500|500] "degree" XXX - -BO_ 642 NEW_MSG_2: 8 XXX - SG_ TurnSignal : 45|2@0+ (1,0) [0|3] "" XXX - - - -CM_ "CHFFR_METRIC 2 STEER_ANGLE STEER_ANGLE 0.36 180"; - -VAL_ 324 BrakeApplied 1 "On" 0 "Off" ; -VAL_ 324 CruiseEnabled 1 "On" 0 "Off" ; -VAL_ 324 BrakeStatus 1 "On" 0 "Off" ; -VAL_ 324 CruiseButtons 2 "Set" 1 "Resume" ; - -VAL_ 642 TurnSignal 2 "Left" 1 "Right" ; diff --git a/opendbc/vw_golf_mk4.dbc b/opendbc/vw_golf_mk4.dbc index 70cc8cc3aff74a..bdfe6390f77740 100644 --- a/opendbc/vw_golf_mk4.dbc +++ b/opendbc/vw_golf_mk4.dbc @@ -1039,3 +1039,12 @@ BO_ 1324 ADR_1: 8 XXX SG_ Fehler_ADR_1 : 12|1@1+ (1,0) [0|0] "" XXX SG_ Zaehler_ADR_1 : 8|4@1+ (1,0) [0|15] "" XXX SG_ Momentenanforderung_ADR : 0|8@1+ (0.39,0) [0|99] "MDI" XXX + +BO_ 210 PQ_HCA: 8 XXX + SG_ HCA_Torque : 16|15@1+ (1,0) [0|32767] "" XXX + SG_ UNK_Bit : 34|1@0+ (1,0) [0|1] "" XXX + SG_ HCA_Torque_VZ : 31|1@0+ (1,0) [0|1] "" XXX + SG_ PQ_HCA_BZ : 8|4@1+ (1,0) [0|15] "" XXX + SG_ PQ_HCA_Checksum : 0|4@1+ (1,0) [0|15] "" XXX + +BO_ 1490 VIN_1: 8 XXX diff --git a/opendbc/vw_mqb_2010.dbc b/opendbc/vw_mqb_2010.dbc index 4529f8847a0b87..063cd1b795b614 100644 --- a/opendbc/vw_mqb_2010.dbc +++ b/opendbc/vw_mqb_2010.dbc @@ -37,8 +37,8 @@ BU_: Airbag_MQB BAP_Tester_MQB BMS_MQB Datenlogger_MQB Gateway_MQB Getriebe_DQ_H BO_ 290 ACC_06: 8 Gateway_MQB - SG_ ACC_06_CRC : 0|8@1+ (1,0) [0|255] "" Getriebe_DQ_Hybrid_MQB,Getriebe_DQ_MQB,Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB - SG_ ACC_06_BZ : 8|4@1+ (1,0) [0|15] "" Getriebe_DQ_Hybrid_MQB,Getriebe_DQ_MQB,Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB + SG_ CHECKSUM : 0|8@1+ (1,0) [0|255] "" Getriebe_DQ_Hybrid_MQB,Getriebe_DQ_MQB,Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB + SG_ COUNTER : 8|4@1+ (1,0) [0|15] "" Getriebe_DQ_Hybrid_MQB,Getriebe_DQ_MQB,Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB SG_ ACC_limitierte_Anfahrdyn : 12|1@1+ (1,0) [0|1] "" Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB SG_ ACC_zul_Regelabw_unten : 16|6@1+ (0.024,0) [0|1.512] "Unit_MeterPerSeconSquar" Getriebe_DQ_Hybrid_MQB,Getriebe_DQ_MQB,Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB SG_ ACC_StartStopp_Info : 22|2@1+ (1,0) [0|3] "" Motor_Diesel_MQB,Motor_Otto_MQB @@ -53,8 +53,8 @@ BO_ 290 ACC_06: 8 Gateway_MQB SG_ ACC_Minimale_Bremsung : 63|1@1+ (1,0) [0|1] "" Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB BO_ 279 ACC_10: 8 Gateway_MQB - SG_ ACC_10_CRC : 0|8@1+ (1,0) [0|255] "" Airbag_MQB - SG_ ACC_10_BZ : 8|4@1+ (1,0) [0|15] "" Airbag_MQB + SG_ CHECKSUM : 0|8@1+ (1,0) [0|255] "" Airbag_MQB + SG_ COUNTER : 8|4@1+ (1,0) [0|15] "" Airbag_MQB SG_ AWV1_Anf_Prefill : 16|1@1+ (1,0) [0|1] "" Airbag_MQB SG_ ANB_CM_Info : 17|1@1+ (1,0) [0|1] "" Vector__XXX SG_ AWV2_Freigabe : 18|1@1+ (1,0) [0|1] "" Airbag_MQB @@ -281,8 +281,8 @@ BO_ 257 ESP_02: 8 Gateway_MQB SG_ ESP_Status_ESP_PLA : 60|4@1+ (1,0) [0|15] "" Getriebe_DQ_Hybrid_MQB,Getriebe_DQ_MQB BO_ 262 ESP_05: 8 Gateway_MQB - SG_ ESP_05_CRC : 0|8@1+ (1,0) [0|255] "" Airbag_MQB,Getriebe_DQ_Hybrid_MQB,Getriebe_DQ_MQB,Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB - SG_ ESP_05_BZ : 8|4@1+ (1,0) [0|15] "" Airbag_MQB,Getriebe_DQ_Hybrid_MQB,Getriebe_DQ_MQB,Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB + SG_ CHECKSUM : 0|8@1+ (1,0) [0|255] "" Airbag_MQB,Getriebe_DQ_Hybrid_MQB,Getriebe_DQ_MQB,Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB + SG_ COUNTER : 8|4@1+ (1,0) [0|15] "" Airbag_MQB,Getriebe_DQ_Hybrid_MQB,Getriebe_DQ_MQB,Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB SG_ ESP_QBit_Bremsdruck : 12|1@1+ (1,0) [0|1] "" Airbag_MQB,Getriebe_DQ_Hybrid_MQB,Getriebe_DQ_MQB,Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB SG_ ESP_QBit_Fahrer_bremst : 13|1@1+ (1,0) [0|1] "" Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB SG_ ESP_Schwelle_Unterdruck : 14|2@1+ (1,0) [0|3] "" Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB @@ -360,8 +360,8 @@ BO_ 178 ESP_19: 8 Gateway_MQB SG_ ESP_VR_Radgeschw_02 : 48|16@1+ (0.0075,0) [0|491.49] "Unit_KiloMeterPerHour" Airbag_MQB,Getriebe_DQ_Hybrid_MQB,Getriebe_DQ_MQB,Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB BO_ 1629 ESP_20: 8 Gateway_MQB - SG_ ESP_20_CRC : 0|8@1+ (1,0) [0|255] "" Vector__XXX - SG_ ESP_20_BZ : 8|4@1+ (1,0) [0|15] "" Vector__XXX + SG_ CHECKSUM : 0|8@1+ (1,0) [0|255] "" Vector__XXX + SG_ COUNTER : 8|4@1+ (1,0) [0|15] "" Vector__XXX SG_ BR_Systemart : 12|2@1+ (1,0) [0|3] "" Vector__XXX SG_ ESP_Zaehnezahl : 16|8@1+ (1,0) [0|255] "" Getriebe_DQ_Hybrid_MQB,Getriebe_DQ_MQB SG_ ESP_Charisma_FahrPr : 24|4@1+ (1,0) [0|15] "" Vector__XXX @@ -370,8 +370,8 @@ BO_ 1629 ESP_20: 8 Gateway_MQB SG_ BR_Reifenumfang : 52|12@1+ (1,0) [0|4095] "Unit_MilliMeter" Getriebe_DQ_Hybrid_MQB,Getriebe_DQ_MQB BO_ 253 ESP_21: 8 Gateway_MQB - SG_ ESP_21_CRC : 0|8@1+ (1,0) [0|255] "" Airbag_MQB,Getriebe_DQ_Hybrid_MQB,Getriebe_DQ_MQB,LEH_MQB,Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB - SG_ ESP_21_BZ : 8|4@1+ (1,0) [0|15] "" Airbag_MQB,BMS_MQB,Getriebe_DQ_Hybrid_MQB,Getriebe_DQ_MQB,LEH_MQB,Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB + SG_ CHECKSUM : 0|8@1+ (1,0) [0|255] "" Airbag_MQB,Getriebe_DQ_Hybrid_MQB,Getriebe_DQ_MQB,LEH_MQB,Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB + SG_ COUNTER : 8|4@1+ (1,0) [0|15] "" Airbag_MQB,BMS_MQB,Getriebe_DQ_Hybrid_MQB,Getriebe_DQ_MQB,LEH_MQB,Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB SG_ BR_Eingriffsmoment : 12|10@1+ (1,-509) [-509|509] "Unit_NewtoMeter" Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB SG_ ESP_v_Signal : 32|16@1+ (0.01,0) [0|655.32] "Unit_KiloMeterPerHour" Airbag_MQB,BMS_MQB,Getriebe_DQ_Hybrid_MQB,Getriebe_DQ_MQB,LEH_MQB,Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB,SAK_MQB SG_ ASR_Tastung_passiv : 48|1@1+ (1,0) [0|1] "" Airbag_MQB,Getriebe_DQ_Hybrid_MQB,Getriebe_DQ_MQB,Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB @@ -451,8 +451,8 @@ BO_ 296 Getriebe_06: 3 Getriebe_DQ_Hybrid_MQB SG_ GE_Testparameter_2 : 16|8@1+ (1,0) [0|255] "" Waehlhebel_MQB BO_ 173 Getriebe_11: 8 Getriebe_DQ_Hybrid_MQB - SG_ Getriebe_11_CRC : 0|8@1+ (1,0) [0|255] "" Gateway_MQB,Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB - SG_ Getriebe_11_BZ : 8|4@1+ (1,0) [0|15] "" Gateway_MQB,Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB + SG_ CHECKSUM : 0|8@1+ (1,0) [0|255] "" Gateway_MQB,Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB + SG_ COUNTERXX : 8|4@1+ (1,0) [0|15] "" Gateway_MQB,Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB SG_ GE_MMom_Soll_02 : 12|10@1+ (1,-509) [-509|509] "Unit_NewtoMeter" Gateway_MQB,Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB SG_ GE_MMom_Vorhalt_02 : 22|10@1+ (1,-509) [-509|509] "Unit_NewtoMeter" Gateway_MQB,Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB SG_ GE_Uefkt : 32|10@1+ (0.1,0) [0|102.2] "" Gateway_MQB,Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB @@ -520,8 +520,8 @@ BO_ 158 Getriebe_Hybrid_01: 8 Getriebe_DQ_Hybrid_MQB SG_ GE_HYB_VM_Startkontr : 63|1@1+ (1,0) [0|1] "" Motor_Hybrid_MQB BO_ 299 GRA_ACC_01: 8 Gateway_MQB - SG_ GRA_ACC_01_CRC : 0|8@1+ (1,0) [0|255] "" Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB - SG_ GRA_ACC_01_BZ : 8|4@1+ (1,0) [0|15] "" Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB + SG_ CHECKSUM : 0|8@1+ (1,0) [0|255] "" Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB + SG_ COUNTER : 8|4@1+ (1,0) [0|15] "" Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB SG_ GRA_Hauptschalter : 12|1@1+ (1,0) [0|1] "" Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB SG_ GRA_Abbrechen : 13|1@1+ (1,0) [0|1] "" Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB SG_ GRA_Typ_Hauptschalter : 14|1@1+ (1,0) [0|1] "" Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB @@ -535,10 +535,11 @@ BO_ 299 GRA_ACC_01: 8 Gateway_MQB SG_ GRA_Fehler : 24|1@1+ (1,0) [0|1] "" Getriebe_DQ_Hybrid_MQB,Getriebe_DQ_MQB,Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB SG_ GRA_Typ468 : 25|2@1+ (1,0) [0|3] "" Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB SG_ GRA_Tip_Stufe_2 : 27|1@1+ (1,0) [0|1] "" Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB + SG_ GRA_ButtonTypeInfo : 28|2@1+ (1,0) [0|1] "" Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB BO_ 960 Klemmen_Status_01: 4 Gateway_MQB - SG_ Klemmen_Status_01_CRC : 0|8@1+ (1,0) [0|255] "" Airbag_MQB,BMS_MQB,Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB - SG_ Klemmen_Status_01_BZ : 8|4@1+ (1,0) [0|15] "" Airbag_MQB,BMS_MQB,Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB + SG_ CHECKSUM : 0|8@1+ (1,0) [0|255] "" Airbag_MQB,BMS_MQB,Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB + SG_ COUNTER : 8|4@1+ (1,0) [0|15] "" Airbag_MQB,BMS_MQB,Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB SG_ ZAS_Kl_S : 16|1@1+ (1,0) [0|1] "" Vector__XXX SG_ ZAS_Kl_15 : 17|1@1+ (1,0) [0|1] "" Airbag_MQB,BMS_MQB,Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB SG_ ZAS_Kl_X : 18|1@1+ (1,0) [0|1] "" Vector__XXX @@ -683,16 +684,16 @@ BO_ 982 Licht_hinten_01: 8 Gateway_MQB SG_ LH_Bremsl_re_ges_def : 55|1@1+ (1,0) [0|1] "" Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB BO_ 134 LWI_01: 8 Gateway_MQB - SG_ LWI_01_CRC : 0|8@1+ (1,0) [0|255] "" Airbag_MQB,Getriebe_DQ_Hybrid_MQB,Getriebe_DQ_MQB,Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB - SG_ LWI_01_BZ : 8|4@1+ (1,0) [0|15] "" Airbag_MQB,Getriebe_DQ_Hybrid_MQB,Getriebe_DQ_MQB,Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB + SG_ CHECKSUM : 0|8@1+ (1,0) [0|255] "" Airbag_MQB,Getriebe_DQ_Hybrid_MQB,Getriebe_DQ_MQB,Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB + SG_ COUNTER : 8|4@1+ (1,0) [0|15] "" Airbag_MQB,Getriebe_DQ_Hybrid_MQB,Getriebe_DQ_MQB,Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB SG_ LWI_Sensorstatus : 12|1@1+ (1,0) [0|1] "" Airbag_MQB,Getriebe_DQ_Hybrid_MQB,Getriebe_DQ_MQB,Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB SG_ LWI_QBit_Sub_Daten : 13|1@1+ (1,0) [0|1] "" Vector__XXX + SG_ LWI_QBit_Lenkradwinkel : 15|1@1+ (1,0) [0|1] "" Airbag_MQB,Getriebe_DQ_Hybrid_MQB,Getriebe_DQ_MQB,Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB + SG_ LWI_Lenkradwinkel : 16|13@1+ (0.1,0) [0|800] "Unit_DegreOfArc" Airbag_MQB,Getriebe_DQ_Hybrid_MQB,Getriebe_DQ_MQB,Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB + SG_ LWI_VZ_Lenkradwinkel : 29|1@1+ (1,0) [0|1] "" Airbag_MQB,Getriebe_DQ_Hybrid_MQB,Getriebe_DQ_MQB,Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB SG_ LWI_VZ_Lenkradw_Geschw : 30|1@1+ (1,0) [0|1] "" Vector__XXX SG_ LWI_Lenkradw_Geschw : 31|9@1+ (5,0) [0|2500] "Unit_DegreOfArcPerSecon" Vector__XXX SG_ LWI_Sub_Daten : 40|16@1+ (1,0) [0|65535] "" Vector__XXX - SG_ LWI_Lenkradwinkel : 16|13@1+ (0.1,0) [0|800] "Unit_DegreOfArc" Airbag_MQB,Getriebe_DQ_Hybrid_MQB,Getriebe_DQ_MQB,Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB - SG_ LWI_QBit_Lenkradwinkel : 15|1@1+ (1,0) [0|1] "" Airbag_MQB,Getriebe_DQ_Hybrid_MQB,Getriebe_DQ_MQB,Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB - SG_ LWI_VZ_Lenkradwinkel : 29|1@1+ (1,0) [0|1] "" Airbag_MQB,Getriebe_DQ_Hybrid_MQB,Getriebe_DQ_MQB,Motor_Diesel_MQB,Motor_Hybrid_MQB,Motor_Otto_MQB BO_ 263 Motor_04: 8 Motor_Diesel_MQB SG_ MO_Istgang : 8|4@1+ (1,0) [0|15] "" Gateway_MQB @@ -1126,6 +1127,28 @@ BO_ 798 TSK_07: 8 Motor_Diesel_MQB SG_ TSK_Status_Anzeige : 61|3@1+ (1,0) [0|7] "" Gateway_MQB BO_ 1716 VIN_01: 8 Gateway_MQB + SG_ VIN_01_MUX M : 0|2@1+ (1,0) [0|3] "" Airbag_MQB + SG_ KS_Geheimnis_1 m0 : 8|8@1+ (1,0) [0|255] "" Vector__XXX + SG_ VIN_4 m1 : 8|8@1+ (1,0) [0|255] "" Airbag_MQB + SG_ VIN_11 m2 : 8|8@1+ (1,0) [0|255] "" Airbag_MQB + SG_ KS_Geheimnis_2 m0 : 16|8@1+ (1,0) [0|255] "" Vector__XXX + SG_ VIN_5 m1 : 16|8@1+ (1,0) [0|255] "" Airbag_MQB + SG_ VIN_12 m2 : 16|8@1+ (1,0) [0|255] "" Airbag_MQB + SG_ KS_Geheimnis_3 m0 : 24|8@1+ (1,0) [0|255] "" Vector__XXX + SG_ VIN_6 m1 : 24|8@1+ (1,0) [0|255] "" Airbag_MQB + SG_ VIN_13 m2 : 24|8@1+ (1,0) [0|255] "" Airbag_MQB + SG_ KS_Geheimnis_4 m0 : 32|8@1+ (1,0) [0|255] "" Vector__XXX + SG_ VIN_7 m1 : 32|8@1+ (1,0) [0|255] "" Airbag_MQB + SG_ VIN_14 m2 : 32|8@1+ (1,0) [0|255] "" Airbag_MQB + SG_ VIN_1 m0 : 40|8@1+ (1,0) [0|255] "" Airbag_MQB + SG_ VIN_8 m1 : 40|8@1+ (1,0) [0|255] "" Airbag_MQB + SG_ VIN_15 m2 : 40|8@1+ (1,0) [0|255] "" Airbag_MQB + SG_ VIN_2 m0 : 48|8@1+ (1,0) [0|255] "" Airbag_MQB + SG_ VIN_9 m1 : 48|8@1+ (1,0) [0|255] "" Airbag_MQB + SG_ VIN_16 m2 : 48|8@1+ (1,0) [0|255] "" Airbag_MQB + SG_ VIN_3 m0 : 56|8@1+ (1,0) [0|255] "" Airbag_MQB + SG_ VIN_10 m1 : 56|8@1+ (1,0) [0|255] "" Airbag_MQB + SG_ VIN_17 m2 : 56|8@1+ (1,0) [0|255] "" Airbag_MQB BO_ 175 Waehlhebel_03: 4 Waehlhebel_MQB SG_ WH_Status_Sperre : 0|3@1+ (1,0) [0|7] "" Getriebe_DQ_Hybrid_MQB,Getriebe_DQ_MQB @@ -1157,30 +1180,30 @@ BO_ 1602 WIV_01: 8 Motor_Diesel_MQB SG_ WIV_W_max : 56|7@1+ (1000,0) [0|127000] "Unit_KiloMeter" Gateway_MQB BO_ 294 HCA_01: 8 XXX - SG_ 3 : 15|4@0+ (1,0) [0|15] "" XXX - SG_ 7 : 55|8@0+ (1,0) [0|255] "" XXX - SG_ 254 : 47|8@0+ (1,0) [0|255] "" XXX - SG_ HCA_01_CRC : 7|8@0+ (1,0) [0|255] "" XXX - SG_ HCA_01_BZ : 11|4@0+ (1,0) [0|255] "" XXX - SG_ Assist_Requested : 30|1@0+ (1,0) [0|1] "" XXX + SG_ CHECKSUM : 0|8@1+ (1,0) [0|255] "" XXX + SG_ COUNTER : 8|4@1+ (1,0) [0|255] "" XXX + SG_ SET_ME_0X3 : 12|4@1+ (1,0) [0|15] "" XXX SG_ Assist_Torque : 16|14@1+ (1,0) [0|300] "Nm" XXX - SG_ Assist_VZ : 31|1@0+ (1,0) [0|1] "" XXX + SG_ Assist_Requested : 30|1@1+ (1,0) [0|1] "" XXX + SG_ Assist_VZ : 31|1@1+ (1,0) [0|1] "" XXX SG_ HCA_Available : 32|1@1+ (1,0) [0|1] "" XXX - SG_ HCA_Standby : 33|1@0+ (1,0) [0|1] "" XXX - SG_ HCA_Active : 34|1@0+ (1,0) [0|1] "" XXX + SG_ HCA_Standby : 33|1@1+ (1,0) [0|1] "" XXX + SG_ HCA_Active : 34|1@1+ (1,0) [0|1] "" XXX + SG_ SET_ME_0XFE : 40|8@1+ (1,0) [0|255] "" XXX + SG_ SET_ME_0X07 : 48|8@1+ (1,0) [0|255] "" XXX BO_ 159 EPS_01: 8 XXX - SG_ EPS_01_CRC : 0|8@1+ (1,0) [0|255] "" XXX - SG_ EPS_01_BZ : 8|4@1+ (1,0) [0|15] "" XXX - SG_ Steering_Wheel_Angle : 16|13@1+ (0.075,0) [0|16383] "Unit_DegreOfArc" XXX - SG_ Steering_Wheel_Angle_VZ : 31|1@0+ (1,0) [0|1] "" XXX - SG_ HCA_Active : 34|1@0+ (1,0) [0|1] "" XXX - SG_ HCA_Standby : 33|1@0+ (1,0) [0|1] "" XXX - SG_ Unknown_Status2 : 63|1@0+ (1,0) [0|1] "" XXX + SG_ CHECKSUM : 0|8@1+ (1,0) [0|255] "" XXX + SG_ COUNTER : 8|4@1+ (1,0) [0|15] "" XXX + SG_ Steering_Wheel_Angle : 16|13@1+ (0.15,0) [0|16383] "Unit_DegreOfArc" XXX + SG_ Steering_Wheel_Angle_VZ : 31|1@1+ (1,0) [0|1] "" XXX + SG_ HCA_Active : 34|1@1+ (1,0) [0|1] "" XXX + SG_ HCA_Standby : 33|1@1+ (1,0) [0|1] "" XXX + SG_ Unknown_Status2 : 63|1@1+ (1,0) [0|1] "" XXX SG_ HCA_Ready : 32|1@1+ (1,0) [0|3] "" XXX SG_ Driver_Strain : 40|13@1+ (1,0) [0|255] "Nm" XXX SG_ Driver_Strain_VZ : 55|1@1+ (1,0) [0|1] "" XXX - SG_ Unknown_Status1 : 62|1@0+ (1,0) [0|1] "" XXX + SG_ Unknown_Status1 : 62|1@1+ (1,0) [0|1] "" XXX BO_ 286 VehicleSpeed: 8 XXX SG_ VehicleSpeed_CRC : 0|8@1+ (1,0) [0|255] "" XXX @@ -1190,16 +1213,20 @@ BO_ 286 VehicleSpeed: 8 XXX BO_ 919 LDW_02: 8 XXX SG_ LDW_DLC : 40|8@1+ (0.01,0) [0|255] "m" XXX SG_ LDW_TLC : 48|5@1+ (0.05,0) [0|255] "Seconds" XXX - SG_ LDW_Unknown : 15|2@0+ (1,0) [0|3] "" XXX + SG_ LDW_Unknown : 14|2@1+ (1,0) [0|3] "" XXX SG_ Alert_Message : 16|4@1+ (1,0) [0|15] "" XXX - SG_ LDW_Direction : 20|1@0+ (1,0) [0|1] "" XXX + SG_ LDW_Direction : 20|1@1+ (1,0) [0|1] "" XXX SG_ Right_Lane_Status : 36|2@1+ (1,0) [0|3] "" XXX SG_ Left_Lane_Status : 38|2@1+ (1,0) [0|3] "" XXX - SG_ Kombi_Lamp_Orange : 61|1@0+ (1,0) [0|1] "" XXX - SG_ Kombi_Lamp_Green : 62|1@0+ (1,0) [0|1] "" XXX + SG_ Kombi_Lamp_Orange : 61|1@1+ (1,0) [0|1] "" XXX + SG_ Kombi_Lamp_Green : 62|1@1+ (1,0) [0|1] "" XXX BO_ 780 ACC_02: 8 XXX + SG_ CHECKSUM : 0|8@1+ (1,0) [0|255] "" XXX + SG_ COUNTER : 8|4@1+ (1,0) [0|15] "" XXX + SG_ SetSpeed : 12|10@1+ (0.08865,0) [0|90.68] "Unit_MeterPerSecond" XXX SG_ Kollision1 : 23|1@1+ (1,0) [0|1] "" XXX + SG_ Abstand : 24|10@1+ (0.1,0) [0|102.3] "m" XXX SG_ ACC_MinusInv : 36|2@1+ (1,0) [0|3] "" XXX SG_ ACC_Minus : 38|2@1+ (1,0) [0|3] "" XXX SG_ Kollision2 : 40|1@1+ (1,0) [0|1] "" XXX @@ -1212,10 +1239,6 @@ BO_ 780 ACC_02: 8 XXX SG_ MotorbitB5_7 : 47|1@1+ (1,0) [0|1] "" XXX SG_ SetAbstand : 48|4@1+ (1,0) [0|15] "" XXX SG_ Hebel : 56|4@1+ (1,0) [0|15] "" XXX - SG_ SetSpeed : 12|10@1+ (0.32,0) [0|320] "kmh" XXX - SG_ Abstand : 24|10@1+ (0.1,0) [0|102.3] "m" XXX - SG_ ACC_02_CRC : 0|8@1+ (1,0) [0|255] "" XXX - SG_ ACC_02_BZ : 8|4@1+ (1,0) [0|15] "" XXX BO_ 302 ACC_07: 8 XXX SG_ ACC_07_BZ : 8|4@1+ (1,0) [0|15] "" XXX @@ -1251,9 +1274,47 @@ BO_ 427 ESP_33: 8 XXX SG_ ESP_33_BZ : 8|4@1+ (1,0) [0|15] "" XXX SG_ ESP_33_CRC : 0|8@1+ (1,0) [0|255] "" XXX +BO_ 418 ESP_15: 8 XXX + SG_ ESP_15_CRC : 0|8@1+ (1,0) [0|255] "" XXX + SG_ ESP_15_BZ : 8|4@1+ (1,0) [0|15] "" XXX + +BO_ 1122 PSD_04: 8 XXX + SG_ PSD_Object_Index : 0|6@1+ (1,0) [0|63] "" XXX + +BO_ 1123 PSD_05: 8 XXX + SG_ PSD_Current_Route_Index : 0|6@1+ (1,0) [0|63] "" XXX + SG_ Route_Distance_Remaining : 8|5@1+ (1,0) [0|31] "" XXX + +BO_ 1124 PSD_06: 8 XXX +BO_ 988 Gateway_73: 8 XXX +BO_ 792 Kamera_Status: 8 XXX +BO_ 981 Licht_Anf_01: 8 XXX + +BO_ 1440 RLS_01: 8 XXX + +BO_ 870 Blinkmodi_02: 8 XXX + +BO_ 1385 HVEM_04: 8 XXX + +BO_ 1605 FLA_01: 8 XXX + +BO_ 1624 Licht_vorne_01: 8 XXX + +BO_ 1646 Klima_03: 8 XXX + +BO_ 1720 Kombi_03: 8 XXX + +BO_ 391 EV_Gearshift: 8 XXX + SG_ CHECKSUM : 0|8@1+ (1,0) [0|255] "" XXX + SG_ COUNTER : 8|4@1+ (1,0) [0|15] "" XXX + SG_ GearPosition : 16|4@1+ (1,0) [0|255] "" XXX + SG_ RegenBrakingMode : 12|2@1+ (1,0) [0|3] "" XXX + +CM_ SG_ 173 COUNTERXX "Message not renamed to COUNTER because J533 rate-limiting makes it look like messages are being lost"; +CM_ SG_ 134 LWI_Lenkradwinkel "Steering angle WITH variable ratio effect included"; CM_ SG_ 294 3 "May be zero when sent by older cameras"; CM_ SG_ 294 7 "May be zero when sent by older cameras"; CM_ SG_ 294 254 "May be zero when sent by older cameras"; @@ -1263,6 +1324,7 @@ CM_ SG_ 294 HCA_Available "Must be 1 for steering rack to accept HCA commands"; CM_ SG_ 159 HCA_Ready "1 if HCA is okay, 0 if the rack doesn't have HCA configured or a timer/constraint has been violated, rack will not respond to HCA commands"; CM_ SG_ 159 Driver_Strain "Steering input by driver, torque"; CM_ SG_ 159 Driver_Strain_VZ "Steering input by driver, sign (direction)"; +CM_ SG_ 159 Steering_Wheel_Angle "Steering angle WITHOUT variable ratio effect included"; CM_ SG_ 919 LDW_DLC "Probable DLC (distance to line crossing)"; CM_ SG_ 919 LDW_TLC "Probable TLC (time to line crossing)"; CM_ SG_ 919 LDW_Unknown "Might be a steering pressed / driver active flag"; @@ -1274,6 +1336,10 @@ CM_ SG_ 919 Kombi_Lamp_Orange "Enables orange LDW light in instrument cluster"; CM_ SG_ 919 Kombi_Lamp_Green "Enables green LDW light in instrument cluster"; CM_ SG_ 780 Folgefahrt "Following another vehicle"; CM_ SG_ 780 SetAbstand "Set following distance"; -CM_ SG_ 780 SetSpeed "ACC set speed"; CM_ SG_ 780 Abstand "Following distance"; -VAL_ 173 GE_Fahrstufe 5 "P" 6 "R" 7 "N" 8 "D" 9 "S" 10 "E" 14 "T" ; +CM_ SG_ 780 SetSpeed "ACC set speed"; +CM_ SG_ 391 GearPosition "Traditional PRND plus B-mode aggressive regen, B-mode mapped to Drive"; +CM_ SG_ 960 ZAS_Kl_15 "Indicates ignition on"; +VAL_ 173 GE_Fahrstufe 5 "P" 6 "R" 7 "N" 8 "D" 9 "S" 10 "E" 14 "T"; +VAL_ 391 GearPosition 2 "P" 3 "R" 4 "N" 5 "D" 6 "D"; +VAL_ 391 RegenBrakingMode 0 "default" 1 "B1" 2 "B2" 3 "B3"; diff --git a/panda/.circleci/config.yml b/panda/.circleci/config.yml index 6348ff0f5542f0..58fc1d13bc9dbd 100644 --- a/panda/.circleci/config.yml +++ b/panda/.circleci/config.yml @@ -92,6 +92,20 @@ jobs: command: | docker run language_check /bin/bash -c "cd /panda/tests/language; ./test_language.py" + linter_python: + machine: + docker_layer_caching: true + steps: + - checkout + - run: + name: Build image + command: "docker build -t linter_python -f tests/linter_python/Dockerfile ." + - run: + name: Run linter python test + command: | + docker run linter_python /bin/bash -c "cd /panda/tests/linter_python; PYTHONPATH=/ ./flake8_panda.sh" + docker run linter_python /bin/bash -c "cd /panda/tests/linter_python; PYTHONPATH=/ ./pylint_panda.sh" + workflows: version: 2 main: @@ -101,3 +115,4 @@ workflows: - build - safety_replay - language_check + - linter_python diff --git a/panda/Jenkinsfile b/panda/Jenkinsfile index 7f147a2fe9e08d..204b5beb3d925a 100644 --- a/panda/Jenkinsfile +++ b/panda/Jenkinsfile @@ -46,6 +46,21 @@ pipeline { } } } +/* + stage('Test Dev Build (WIFI)') { + steps { + lock(resource: "Pandas", inversePrecedence: true, quantity: 1){ + timeout(time: 60, unit: 'MINUTES') { + script { + sh "docker run --name ${env.DOCKER_NAME} --privileged --volume /dev/bus/usb:/dev/bus/usb --volume /var/run/dbus:/var/run/dbus --net host ${env.DOCKER_IMAGE_TAG} bash -c 'cd /tmp/panda; ./run_automated_tests.sh'" + sh "docker cp ${env.DOCKER_NAME}:/tmp/panda/nosetests.xml test_results_dev.xml" + sh "docker rm ${env.DOCKER_NAME}" + } + } + } + } + } +*/ } post { failure { diff --git a/panda/README.md b/panda/README.md index 7c9bd68bf7926a..634db4c120b157 100644 --- a/panda/README.md +++ b/panda/README.md @@ -108,6 +108,8 @@ to ensure that the behavior remains unchanged. * compiling the code in various configuration and flashing it both through USB and WiFi. * Receiving, sending and forwarding CAN messages on all buses, over USB and WiFi. +In addition, we run [Pylint](https://www.pylint.org/) and [Flake8](https://github.com/PyCQA/flake8) linters on all python files within the panda repo. + Hardware ------ diff --git a/panda/UPDATING.md b/panda/UPDATING.md index 100acc6bab5fbc..ab60f88ac81694 100644 --- a/panda/UPDATING.md +++ b/panda/UPDATING.md @@ -1,9 +1,9 @@ # Updating your panda -Panda should update automatically via the [Chffr](http://chffr.comma.ai/) app ([apple](https://itunes.apple.com/us/app/chffr-dash-cam-that-remembers/id1146683979) and [android](https://play.google.com/store/apps/details?id=ai.comma.chffr)) +Panda should update automatically via the [openpilot](http://openpilot.comma.ai/). -If it doesn't however, you can use the following commands on linux or Mac OSX - `sudo pip install --upgrade pandacan` -` PYTHONPATH="" sudo python -c "import panda; panda.flash_release()"` - -(You'll need to have `pip` and `sudo` installed.) +On Linux or Mac OSX, you can manually update it using: +``` +sudo pip install --upgrade pandacan` +PYTHONPATH="" sudo python -c "import panda; panda.flash_release()"` +``` diff --git a/panda/VERSION b/panda/VERSION index 74a63a2249463a..0fa909eb360030 100644 --- a/panda/VERSION +++ b/panda/VERSION @@ -1 +1 @@ -v1.5.2 \ No newline at end of file +v1.5.9 diff --git a/panda/__init__.py b/panda/__init__.py index b802cf5a59582a..5374d5a9ab550a 100644 --- a/panda/__init__.py +++ b/panda/__init__.py @@ -1 +1 @@ -from .python import Panda, PandaWifiStreaming, PandaDFU, ESPROM, CesantaFlasher, flash_release, BASEDIR, ensure_st_up_to_date, build_st, PandaSerial +from .python import Panda, PandaWifiStreaming, PandaDFU, ESPROM, CesantaFlasher, flash_release, BASEDIR, ensure_st_up_to_date, build_st, PandaSerial # noqa: F401 diff --git a/panda/board/README.md b/panda/board/README.md index 5fe2e4b238c2dd..7151bfbf93e32a 100644 --- a/panda/board/README.md +++ b/panda/board/README.md @@ -4,6 +4,7 @@ Dependencies **Mac** ``` +xcode-select --install ./get_sdk_mac.sh ``` diff --git a/panda/board/board.h b/panda/board/board.h index 154f32132ea9d6..5629a841d3f5fd 100644 --- a/panda/board/board.h +++ b/panda/board/board.h @@ -7,9 +7,12 @@ // ///// Board definition and detection ///// // #include "drivers/harness.h" #ifdef PANDA + #include "drivers/fan.h" + #include "drivers/rtc.h" #include "boards/white.h" #include "boards/grey.h" #include "boards/black.h" + #include "boards/uno.h" #else #include "boards/pedal.h" #endif @@ -23,6 +26,9 @@ void detect_board_type(void) { } else if(detect_with_pull(GPIOA, 13, PULL_DOWN)) { // Rev AB deprecated, so no pullup means black. In REV C, A13 is pulled up to 5V with a 10K hw_type = HW_TYPE_GREY_PANDA; current_board = &board_grey; + } else if(!detect_with_pull(GPIOB, 15, PULL_UP)) { + hw_type = HW_TYPE_UNO; + current_board = &board_uno; } else { hw_type = HW_TYPE_BLACK_PANDA; current_board = &board_black; @@ -31,7 +37,7 @@ void detect_board_type(void) { #ifdef PEDAL hw_type = HW_TYPE_PEDAL; current_board = &board_pedal; - #else + #else hw_type = HW_TYPE_UNKNOWN; puts("Hardware type is UNKNOWN!\n"); #endif @@ -60,6 +66,27 @@ void detect_configuration(void) { } // ///// Board functions ///// // +// TODO: Make these config options in the board struct bool board_has_gps(void) { - return ((hw_type == HW_TYPE_GREY_PANDA) || (hw_type == HW_TYPE_BLACK_PANDA)); -} \ No newline at end of file + return ((hw_type == HW_TYPE_GREY_PANDA) || (hw_type == HW_TYPE_BLACK_PANDA) || (hw_type == HW_TYPE_UNO)); +} + +bool board_has_gmlan(void) { + return ((hw_type == HW_TYPE_WHITE_PANDA) || (hw_type == HW_TYPE_GREY_PANDA)); +} + +bool board_has_obd(void) { + return ((hw_type == HW_TYPE_BLACK_PANDA) || (hw_type == HW_TYPE_UNO)); +} + +bool board_has_lin(void) { + return ((hw_type == HW_TYPE_WHITE_PANDA) || (hw_type == HW_TYPE_GREY_PANDA)); +} + +bool board_has_rtc(void) { + return (hw_type == HW_TYPE_UNO); +} + +bool board_has_relay(void) { + return ((hw_type == HW_TYPE_BLACK_PANDA) || (hw_type == HW_TYPE_UNO)); +} diff --git a/panda/board/board_declarations.h b/panda/board/board_declarations.h index 21eb140c3ef272..2fd3976a0dac68 100644 --- a/panda/board/board_declarations.h +++ b/panda/board/board_declarations.h @@ -8,6 +8,9 @@ typedef void (*board_set_esp_gps_mode)(uint8_t mode); typedef void (*board_set_can_mode)(uint8_t mode); typedef void (*board_usb_power_mode_tick)(uint64_t tcnt); typedef bool (*board_check_ignition)(void); +typedef uint32_t (*board_read_current)(void); +typedef void (*board_set_ir_power)(uint8_t percentage); +typedef void (*board_set_fan_power)(uint8_t percentage); struct board { const char *board_type; @@ -21,6 +24,9 @@ struct board { board_set_can_mode set_can_mode; board_usb_power_mode_tick usb_power_mode_tick; board_check_ignition check_ignition; + board_read_current read_current; + board_set_ir_power set_ir_power; + board_set_fan_power set_fan_power; }; // ******************* Definitions ******************** @@ -30,6 +36,7 @@ struct board { #define HW_TYPE_GREY_PANDA 2U #define HW_TYPE_BLACK_PANDA 3U #define HW_TYPE_PEDAL 4U +#define HW_TYPE_UNO 5U // LED colors #define LED_RED 0U @@ -55,3 +62,11 @@ struct board { // ********************* Globals ********************** uint8_t usb_power_mode = USB_POWER_NONE; + +// ************ Board function prototypes ************* +bool board_has_gps(void); +bool board_has_gmlan(void); +bool board_has_obd(void); +bool board_has_lin(void); +bool board_has_rtc(void); +bool board_has_relay(void); \ No newline at end of file diff --git a/panda/board/boards/black.h b/panda/board/boards/black.h index c6078e3b56b370..f033e82b23ed34 100644 --- a/panda/board/boards/black.h +++ b/panda/board/boards/black.h @@ -23,7 +23,8 @@ void black_enable_can_transciever(uint8_t transciever, bool enabled) { } void black_enable_can_transcievers(bool enabled) { - for(uint8_t i=1U; i<=4U; i++){ + uint8_t t1 = enabled ? 1U : 2U; // leave transciever 1 enabled to detect CAN ignition + for(uint8_t i=t1; i<=4U; i++) { black_enable_can_transciever(i, enabled); } } @@ -132,6 +133,19 @@ bool black_check_ignition(void){ return harness_check_ignition(); } +uint32_t black_read_current(void){ + // No current sense on black panda + return 0U; +} + +void black_set_ir_power(uint8_t percentage){ + UNUSED(percentage); +} + +void black_set_fan_power(uint8_t percentage){ + UNUSED(percentage); +} + void black_init(void) { common_init_gpio(); @@ -153,9 +167,6 @@ void black_init(void) { set_gpio_output(GPIOC, 10, 1); set_gpio_output(GPIOC, 11, 1); - // C8: FAN aka TIM3_CH3 - set_gpio_alternate(GPIOC, 8, GPIO_AF2_TIM3); - // Turn on GPS load switch. black_set_gps_load_switch(true); @@ -213,5 +224,8 @@ const board board_black = { .set_esp_gps_mode = black_set_esp_gps_mode, .set_can_mode = black_set_can_mode, .usb_power_mode_tick = black_usb_power_mode_tick, - .check_ignition = black_check_ignition + .check_ignition = black_check_ignition, + .read_current = black_read_current, + .set_fan_power = black_set_fan_power, + .set_ir_power = black_set_ir_power }; diff --git a/panda/board/boards/common.h b/panda/board/boards/common.h index d176e4eaf561a0..e33b2a2f0426c4 100644 --- a/panda/board/boards/common.h +++ b/panda/board/boards/common.h @@ -58,16 +58,18 @@ void peripherals_init(void){ #endif RCC->APB1ENR |= RCC_APB1ENR_DACEN; RCC->APB1ENR |= RCC_APB1ENR_TIM2EN; // main counter - RCC->APB1ENR |= RCC_APB1ENR_TIM3EN; // slow loop and pedal - RCC->APB1ENR |= RCC_APB1ENR_TIM4EN; // gmlan_alt + RCC->APB1ENR |= RCC_APB1ENR_TIM3EN; // pedal and fan PWM + RCC->APB1ENR |= RCC_APB1ENR_TIM4EN; // gmlan_alt and IR PWM //RCC->APB1ENR |= RCC_APB1ENR_TIM5EN; //RCC->APB1ENR |= RCC_APB1ENR_TIM6EN; + RCC->APB1ENR |= RCC_APB1ENR_PWREN; // for RTC config RCC->APB2ENR |= RCC_APB2ENR_USART1EN; RCC->AHB2ENR |= RCC_AHB2ENR_OTGFSEN; //RCC->APB2ENR |= RCC_APB2ENR_TIM1EN; RCC->APB2ENR |= RCC_APB2ENR_ADC1EN; RCC->APB2ENR |= RCC_APB2ENR_SPI1EN; RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN; + RCC->APB2ENR |= RCC_APB2ENR_TIM9EN; // slow loop } // Detection with internal pullup diff --git a/panda/board/boards/grey.h b/panda/board/boards/grey.h index 1927b5459196bb..1a39bce07fad9b 100644 --- a/panda/board/boards/grey.h +++ b/panda/board/boards/grey.h @@ -14,5 +14,8 @@ const board board_grey = { .set_esp_gps_mode = white_set_esp_gps_mode, .set_can_mode = white_set_can_mode, .usb_power_mode_tick = white_usb_power_mode_tick, - .check_ignition = white_check_ignition + .check_ignition = white_check_ignition, + .read_current = white_read_current, + .set_fan_power = white_set_fan_power, + .set_ir_power = white_set_ir_power }; \ No newline at end of file diff --git a/panda/board/boards/pedal.h b/panda/board/boards/pedal.h index 9209a33ba79fdf..02612d3f0966e7 100644 --- a/panda/board/boards/pedal.h +++ b/panda/board/boards/pedal.h @@ -60,6 +60,19 @@ bool pedal_check_ignition(void){ return false; } +uint32_t pedal_read_current(void){ + // No current sense on pedal + return 0U; +} + +void pedal_set_ir_power(uint8_t percentage){ + UNUSED(percentage); +} + +void pedal_set_fan_power(uint8_t percentage){ + UNUSED(percentage); +} + void pedal_init(void) { common_init_gpio(); @@ -93,4 +106,7 @@ const board board_pedal = { .set_can_mode = pedal_set_can_mode, .usb_power_mode_tick = pedal_usb_power_mode_tick, .check_ignition = pedal_check_ignition, + .read_current = pedal_read_current, + .set_fan_power = pedal_set_fan_power, + .set_ir_power = pedal_set_ir_power }; \ No newline at end of file diff --git a/panda/board/boards/uno.h b/panda/board/boards/uno.h new file mode 100644 index 00000000000000..f5765c226f8a6f --- /dev/null +++ b/panda/board/boards/uno.h @@ -0,0 +1,247 @@ +// ///////////// // +// Uno + Harness // +// ///////////// // + +void uno_enable_can_transciever(uint8_t transciever, bool enabled) { + switch (transciever){ + case 1U: + set_gpio_output(GPIOC, 1, !enabled); + break; + case 2U: + set_gpio_output(GPIOC, 13, !enabled); + break; + case 3U: + set_gpio_output(GPIOA, 0, !enabled); + break; + case 4U: + set_gpio_output(GPIOB, 10, !enabled); + break; + default: + puts("Invalid CAN transciever ("); puth(transciever); puts("): enabling failed\n"); + break; + } +} + +void uno_enable_can_transcievers(bool enabled) { + for(uint8_t i=1U; i<=4U; i++){ + uno_enable_can_transciever(i, enabled); + } +} + +void uno_set_led(uint8_t color, bool enabled) { + switch (color){ + case LED_RED: + set_gpio_output(GPIOC, 9, !enabled); + break; + case LED_GREEN: + set_gpio_output(GPIOC, 7, !enabled); + break; + case LED_BLUE: + set_gpio_output(GPIOC, 6, !enabled); + break; + default: + break; + } +} + +void uno_set_gps_load_switch(bool enabled) { + set_gpio_output(GPIOC, 12, enabled); +} + +void uno_set_usb_power_mode(uint8_t mode) { + UNUSED(mode); + puts("Setting USB mode makes no sense on UNO\n"); +} + +void uno_set_esp_gps_mode(uint8_t mode) { + switch (mode) { + case ESP_GPS_DISABLED: + // GPS OFF + set_gpio_output(GPIOB, 1, 0); + set_gpio_output(GPIOC, 5, 0); + uno_set_gps_load_switch(false); + break; + case ESP_GPS_ENABLED: + // GPS ON + set_gpio_output(GPIOB, 1, 1); + set_gpio_output(GPIOC, 5, 1); + uno_set_gps_load_switch(true); + break; + case ESP_GPS_BOOTMODE: + set_gpio_output(GPIOB, 1, 1); + set_gpio_output(GPIOC, 5, 0); + uno_set_gps_load_switch(true); + break; + default: + puts("Invalid ESP/GPS mode\n"); + break; + } +} + +void uno_set_can_mode(uint8_t mode){ + switch (mode) { + case CAN_MODE_NORMAL: + case CAN_MODE_OBD_CAN2: + if ((bool)(mode == CAN_MODE_NORMAL) != (bool)(car_harness_status == HARNESS_STATUS_NORMAL)) { + // B12,B13: disable OBD mode + set_gpio_mode(GPIOB, 12, MODE_INPUT); + set_gpio_mode(GPIOB, 13, MODE_INPUT); + + // B5,B6: normal CAN2 mode + set_gpio_alternate(GPIOB, 5, GPIO_AF9_CAN2); + set_gpio_alternate(GPIOB, 6, GPIO_AF9_CAN2); + } else { + // B5,B6: disable normal CAN2 mode + set_gpio_mode(GPIOB, 5, MODE_INPUT); + set_gpio_mode(GPIOB, 6, MODE_INPUT); + + // B12,B13: OBD mode + set_gpio_alternate(GPIOB, 12, GPIO_AF9_CAN2); + set_gpio_alternate(GPIOB, 13, GPIO_AF9_CAN2); + } + break; + default: + puts("Tried to set unsupported CAN mode: "); puth(mode); puts("\n"); + break; + } +} + +void uno_set_bootkick(bool enabled){ + set_gpio_output(GPIOB, 14, !enabled); +} + +void uno_usb_power_mode_tick(uint64_t tcnt){ + if(tcnt == 3U){ + uno_set_bootkick(false); + } +} + +bool uno_check_ignition(void){ + // ignition is checked through harness + return harness_check_ignition(); +} + +void uno_set_usb_switch(bool phone){ + set_gpio_output(GPIOB, 3, phone); +} + +void uno_set_ir_power(uint8_t percentage){ + pwm_set(TIM4, 2, percentage); +} + +void uno_set_fan_power(uint8_t percentage){ + // Enable fan power only if percentage is non-zero. + set_gpio_output(GPIOA, 1, (percentage != 0U)); + fan_set_power(percentage); +} + +uint32_t uno_read_current(void){ + // No current sense on Uno + return 0U; +} + +void uno_init(void) { + common_init_gpio(); + + // A8,A15: normal CAN3 mode + set_gpio_alternate(GPIOA, 8, GPIO_AF11_CAN3); + set_gpio_alternate(GPIOA, 15, GPIO_AF11_CAN3); + + // C0: OBD_SBU1 (orientation detection) + // C3: OBD_SBU2 (orientation detection) + set_gpio_mode(GPIOC, 0, MODE_ANALOG); + set_gpio_mode(GPIOC, 3, MODE_ANALOG); + + // C10: OBD_SBU1_RELAY (harness relay driving output) + // C11: OBD_SBU2_RELAY (harness relay driving output) + set_gpio_mode(GPIOC, 10, MODE_OUTPUT); + set_gpio_mode(GPIOC, 11, MODE_OUTPUT); + set_gpio_output_type(GPIOC, 10, OUTPUT_TYPE_OPEN_DRAIN); + set_gpio_output_type(GPIOC, 11, OUTPUT_TYPE_OPEN_DRAIN); + set_gpio_output(GPIOC, 10, 1); + set_gpio_output(GPIOC, 11, 1); + + // C8: FAN PWM aka TIM3_CH3 + set_gpio_alternate(GPIOC, 8, GPIO_AF2_TIM3); + + // Turn on GPS load switch. + uno_set_gps_load_switch(true); + + // Turn on phone regulator + set_gpio_output(GPIOB, 4, 1); + + // Initialize IR PWM and set to 0% + set_gpio_alternate(GPIOB, 7, GPIO_AF2_TIM4); + pwm_init(TIM4, 2); + uno_set_ir_power(0U); + + // Initialize fan and set to 0% + fan_init(); + uno_set_fan_power(0U); + + // Initialize harness + harness_init(); + + // Initialize RTC + rtc_init(); + + // Enable CAN transcievers + uno_enable_can_transcievers(true); + + // Disable LEDs + uno_set_led(LED_RED, false); + uno_set_led(LED_GREEN, false); + uno_set_led(LED_BLUE, false); + + // Set normal CAN mode + uno_set_can_mode(CAN_MODE_NORMAL); + + // flip CAN0 and CAN2 if we are flipped + if (car_harness_status == HARNESS_STATUS_NORMAL) { + can_flip_buses(0, 2); + } + + // init multiplexer + can_set_obd(car_harness_status, false); + + // Switch to phone usb mode if harness connection is powered by less than 7V + if(adc_get_voltage() < 7000U){ + uno_set_usb_switch(true); + } else { + uno_set_usb_switch(false); + } + + // Bootkick phone + uno_set_bootkick(true); +} + +const harness_configuration uno_harness_config = { + .has_harness = true, + .GPIO_SBU1 = GPIOC, + .GPIO_SBU2 = GPIOC, + .GPIO_relay_normal = GPIOC, + .GPIO_relay_flipped = GPIOC, + .pin_SBU1 = 0, + .pin_SBU2 = 3, + .pin_relay_normal = 10, + .pin_relay_flipped = 11, + .adc_channel_SBU1 = 10, + .adc_channel_SBU2 = 13 +}; + +const board board_uno = { + .board_type = "Uno", + .harness_config = &uno_harness_config, + .init = uno_init, + .enable_can_transciever = uno_enable_can_transciever, + .enable_can_transcievers = uno_enable_can_transcievers, + .set_led = uno_set_led, + .set_usb_power_mode = uno_set_usb_power_mode, + .set_esp_gps_mode = uno_set_esp_gps_mode, + .set_can_mode = uno_set_can_mode, + .usb_power_mode_tick = uno_usb_power_mode_tick, + .check_ignition = uno_check_ignition, + .read_current = uno_read_current, + .set_fan_power = uno_set_fan_power, + .set_ir_power = uno_set_ir_power +}; diff --git a/panda/board/boards/white.h b/panda/board/boards/white.h index 241f1b91bcf8dd..899ba8d4fef9f5 100644 --- a/panda/board/boards/white.h +++ b/panda/board/boards/white.h @@ -20,8 +20,10 @@ void white_enable_can_transciever(uint8_t transciever, bool enabled) { } void white_enable_can_transcievers(bool enabled) { - for(uint8_t i=1; i<=3U; i++) + uint8_t t1 = enabled ? 1U : 2U; // leave transciever 1 enabled to detect CAN ignition + for(uint8_t i=t1; i<=3U; i++) { white_enable_can_transciever(i, enabled); + } } void white_set_led(uint8_t color, bool enabled) { @@ -150,6 +152,10 @@ void white_set_can_mode(uint8_t mode){ } } +uint32_t white_read_current(void){ + return adc_get(ADCCHAN_CURRENT); +} + uint64_t marker = 0; void white_usb_power_mode_tick(uint64_t tcnt){ @@ -158,7 +164,7 @@ void white_usb_power_mode_tick(uint64_t tcnt){ #define CURRENT_THRESHOLD 0xF00U #define CLICKS 5U // 5 seconds to switch modes - uint32_t current = adc_get(ADCCHAN_CURRENT); + uint32_t current = white_read_current(); // ~0x9a = 500 ma // puth(current); puts("\n"); @@ -217,6 +223,14 @@ void white_usb_power_mode_tick(uint64_t tcnt){ #endif } +void white_set_ir_power(uint8_t percentage){ + UNUSED(percentage); +} + +void white_set_fan_power(uint8_t percentage){ + UNUSED(percentage); +} + bool white_check_ignition(void){ // ignition is on PA1 return !get_gpio_input(GPIOA, 1); @@ -315,5 +329,8 @@ const board board_white = { .set_esp_gps_mode = white_set_esp_gps_mode, .set_can_mode = white_set_can_mode, .usb_power_mode_tick = white_usb_power_mode_tick, - .check_ignition = white_check_ignition + .check_ignition = white_check_ignition, + .read_current = white_read_current, + .set_fan_power = white_set_fan_power, + .set_ir_power = white_set_ir_power }; diff --git a/panda/board/bootstub.c b/panda/board/bootstub.c index 51ce6695db79ee..8ada20c7383224 100644 --- a/panda/board/bootstub.c +++ b/panda/board/bootstub.c @@ -33,6 +33,7 @@ const board *current_board; #include "drivers/clock.h" #include "drivers/llgpio.h" #include "drivers/adc.h" +#include "drivers/pwm.h" #include "board.h" diff --git a/panda/board/drivers/can.h b/panda/board/drivers/can.h index c45a3fe8d1d754..c9bf2d25436b35 100644 --- a/panda/board/drivers/can.h +++ b/panda/board/drivers/can.h @@ -30,6 +30,9 @@ void can_init_all(void); void can_send(CAN_FIFOMailBox_TypeDef *to_push, uint8_t bus_number); bool can_pop(can_ring *q, CAN_FIFOMailBox_TypeDef *elem); +// Ignition detected from CAN meessages +bool ignition_can = false; + // end API #define ALL_CAN_SILENT 0xFF @@ -173,7 +176,7 @@ void can_flip_buses(uint8_t bus1, uint8_t bus2){ // TODO: Cleanup with new abstraction void can_set_gmlan(uint8_t bus) { - if(hw_type != HW_TYPE_BLACK_PANDA){ + if(board_has_gmlan()){ // first, disable GMLAN on prev bus uint8_t prev_bus = can_num_lookup[3]; if (bus != prev_bus) { @@ -226,7 +229,7 @@ void can_set_obd(uint8_t harness_orientation, bool obd){ } else { puts("setting CAN2 to be normal\n"); } - if(hw_type == HW_TYPE_BLACK_PANDA){ + if(board_has_obd()){ if(obd != (bool)(harness_orientation == HARNESS_STATUS_NORMAL)){ // B5,B6: disable normal mode set_gpio_mode(GPIOB, 5, MODE_INPUT); @@ -243,7 +246,7 @@ void can_set_obd(uint8_t harness_orientation, bool obd){ set_gpio_mode(GPIOB, 13, MODE_INPUT); } } else { - puts("OBD CAN not available on non-black panda\n"); + puts("OBD CAN not available on this board\n"); } } @@ -332,6 +335,36 @@ void process_can(uint8_t can_number) { } } +void ignition_can_hook(CAN_FIFOMailBox_TypeDef *to_push) { + + int bus = GET_BUS(to_push); + int addr = GET_ADDR(to_push); + int len = GET_LEN(to_push); + + if (bus == 0) { + // GM exception + if ((addr == 0x1F1) && (len == 8)) { + //Bit 5 is ignition "on" + ignition_can = (GET_BYTE(to_push, 0) & 0x20) != 0; + } + // Tesla exception + if ((addr == 0x348) && (len == 8)) { + // GTW_status + ignition_can = (GET_BYTE(to_push, 0) & 0x1) != 0; + } + // Cadillac exception + if ((addr == 0x160) && (len == 5)) { + // this message isn't all zeros when ignition is on + ignition_can = GET_BYTES_04(to_push) != 0; + } + // VW exception + if ((addr == 0x3C0) && (len == 4)) { + // VW Terminal 15 (ignition-on) state + ignition_can = (GET_BYTE(to_push, 2) & 0x2) != 0; + } + } +} + // CAN receive handlers // blink blue when we are receiving CAN messages void can_rx(uint8_t can_number) { @@ -365,6 +398,7 @@ void can_rx(uint8_t can_number) { } safety_rx_hook(&to_push); + ignition_can_hook(&to_push); current_board->set_led(LED_BLUE, true); can_send_errs += can_push(&can_rx_q, &to_push) ? 0U : 1U; diff --git a/panda/board/drivers/fan.h b/panda/board/drivers/fan.h new file mode 100644 index 00000000000000..d7326ec0b33d59 --- /dev/null +++ b/panda/board/drivers/fan.h @@ -0,0 +1,36 @@ +void fan_init(void){ + // Init PWM speed control + pwm_init(TIM3, 3); + + // Init TACH interrupt + SYSCFG->EXTICR[0] = SYSCFG_EXTICR1_EXTI2_PD; + EXTI->IMR |= (1U << 2); + EXTI->RTSR |= (1U << 2); + EXTI->FTSR |= (1U << 2); + NVIC_EnableIRQ(EXTI2_IRQn); +} + +void fan_set_power(uint8_t percentage){ + pwm_set(TIM3, 3, percentage); +} + +uint16_t fan_tach_counter = 0U; +uint16_t fan_rpm = 0U; + +// Can be way more acurate than this, but this is probably good enough for our purposes. + +// Call this every second +void fan_tick(void){ + // 4 interrupts per rotation + fan_rpm = fan_tach_counter * 15U; + fan_tach_counter = 0U; +} + +// TACH interrupt handler +void EXTI2_IRQHandler(void) { + volatile unsigned int pr = EXTI->PR & (1U << 2); + if ((pr & (1U << 2)) != 0U) { + fan_tach_counter++; + } + EXTI->PR = (1U << 2); +} \ No newline at end of file diff --git a/panda/board/drivers/pwm.h b/panda/board/drivers/pwm.h new file mode 100644 index 00000000000000..d2e1652c1ce4ff --- /dev/null +++ b/panda/board/drivers/pwm.h @@ -0,0 +1,55 @@ +#define PWM_COUNTER_OVERFLOW 2000U // To get ~50kHz + +void pwm_init(TIM_TypeDef *TIM, uint8_t channel){ + // Enable timer and auto-reload + TIM->CR1 = TIM_CR1_CEN | TIM_CR1_ARPE; + + // Set channel as PWM mode 1 and enable output + switch(channel){ + case 1U: + TIM->CCMR1 |= (TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1PE); + TIM->CCER |= TIM_CCER_CC1E; + break; + case 2U: + TIM->CCMR1 |= (TIM_CCMR1_OC2M_2 | TIM_CCMR1_OC2M_1 | TIM_CCMR1_OC2PE); + TIM->CCER |= TIM_CCER_CC2E; + break; + case 3U: + TIM->CCMR2 |= (TIM_CCMR2_OC3M_2 | TIM_CCMR2_OC3M_1 | TIM_CCMR2_OC3PE); + TIM->CCER |= TIM_CCER_CC3E; + break; + case 4U: + TIM->CCMR2 |= (TIM_CCMR2_OC4M_2 | TIM_CCMR2_OC4M_1 | TIM_CCMR2_OC4PE); + TIM->CCER |= TIM_CCER_CC4E; + break; + default: + break; + } + + // Set max counter value + TIM->ARR = PWM_COUNTER_OVERFLOW; + + // Update registers and clear counter + TIM->EGR |= TIM_EGR_UG; +} + +// TODO: Implement for 32-bit timers +void pwm_set(TIM_TypeDef *TIM, uint8_t channel, uint8_t percentage){ + uint16_t comp_value = (((uint16_t) percentage * PWM_COUNTER_OVERFLOW) / 100U); + switch(channel){ + case 1U: + TIM->CCR1 = comp_value; + break; + case 2U: + TIM->CCR2 = comp_value; + break; + case 3U: + TIM->CCR3 = comp_value; + break; + case 4U: + TIM->CCR4 = comp_value; + break; + default: + break; + } +} \ No newline at end of file diff --git a/panda/board/drivers/rtc.h b/panda/board/drivers/rtc.h new file mode 100644 index 00000000000000..9cf113a02e82fb --- /dev/null +++ b/panda/board/drivers/rtc.h @@ -0,0 +1,108 @@ +#define RCC_BDCR_OPTIONS (RCC_BDCR_RTCEN | RCC_BDCR_RTCSEL_0 | RCC_BDCR_LSEON) +#define RCC_BDCR_MASK (RCC_BDCR_RTCEN | RCC_BDCR_RTCSEL | RCC_BDCR_LSEMOD | RCC_BDCR_LSEBYP | RCC_BDCR_LSEON) + +#define YEAR_OFFSET 2000U + +typedef struct __attribute__((packed)) timestamp_t { + uint16_t year; + uint8_t month; + uint8_t day; + uint8_t weekday; + uint8_t hour; + uint8_t minute; + uint8_t second; +} timestamp_t; + +uint8_t to_bcd(uint16_t value){ + return (((value / 10U) & 0x0FU) << 4U) | ((value % 10U) & 0x0FU); +} + +uint16_t from_bcd(uint8_t value){ + return (((value & 0xF0U) >> 4U) * 10U) + (value & 0x0FU); +} + +void rtc_init(void){ + if(board_has_rtc()){ + // Initialize RTC module and clock if not done already. + if((RCC->BDCR & RCC_BDCR_MASK) != RCC_BDCR_OPTIONS){ + puts("Initializing RTC\n"); + // Reset backup domain + RCC->BDCR |= RCC_BDCR_BDRST; + + // Disable write protection + PWR->CR |= PWR_CR_DBP; + + // Clear backup domain reset + RCC->BDCR &= ~(RCC_BDCR_BDRST); + + // Set RTC options + RCC->BDCR = RCC_BDCR_OPTIONS | (RCC->BDCR & (~RCC_BDCR_MASK)); + + // Enable write protection + PWR->CR &= ~(PWR_CR_DBP); + } + } +} + +void rtc_set_time(timestamp_t time){ + if(board_has_rtc()){ + puts("Setting RTC time\n"); + + // Disable write protection + PWR->CR |= PWR_CR_DBP; + RTC->WPR = 0xCA; + RTC->WPR = 0x53; + + // Enable initialization mode + RTC->ISR |= RTC_ISR_INIT; + while((RTC->ISR & RTC_ISR_INITF) == 0){} + + // Set time + RTC->TR = (to_bcd(time.hour) << RTC_TR_HU_Pos) | (to_bcd(time.minute) << RTC_TR_MNU_Pos) | (to_bcd(time.second) << RTC_TR_SU_Pos); + RTC->DR = (to_bcd(time.year - YEAR_OFFSET) << RTC_DR_YU_Pos) | (time.weekday << RTC_DR_WDU_Pos) | (to_bcd(time.month) << RTC_DR_MU_Pos) | (to_bcd(time.day) << RTC_DR_DU_Pos); + + // Set options + RTC->CR = 0U; + + // Disable initalization mode + RTC->ISR &= ~(RTC_ISR_INIT); + + // Wait for synchronization + while((RTC->ISR & RTC_ISR_RSF) == 0){} + + // Re-enable write protection + RTC->WPR = 0x00; + PWR->CR &= ~(PWR_CR_DBP); + } +} + +timestamp_t rtc_get_time(void){ + timestamp_t result; + // Init with zero values in case there is no RTC running + result.year = 0U; + result.month = 0U; + result.day = 0U; + result.weekday = 0U; + result.hour = 0U; + result.minute = 0U; + result.second = 0U; + + if(board_has_rtc()){ + // Wait until the register sync flag is set + while((RTC->ISR & RTC_ISR_RSF) == 0){} + + // Read time and date registers. Since our HSE > 7*LSE, this should be fine. + uint32_t time = RTC->TR; + uint32_t date = RTC->DR; + + // Parse values + result.year = from_bcd((date & (RTC_DR_YT | RTC_DR_YU)) >> RTC_DR_YU_Pos) + YEAR_OFFSET; + result.month = from_bcd((date & (RTC_DR_MT | RTC_DR_MU)) >> RTC_DR_MU_Pos); + result.day = from_bcd((date & (RTC_DR_DT | RTC_DR_DU)) >> RTC_DR_DU_Pos); + result.weekday = ((date & RTC_DR_WDU) >> RTC_DR_WDU_Pos); + result.hour = from_bcd((time & (RTC_TR_HT | RTC_TR_HU)) >> RTC_TR_HU_Pos); + result.minute = from_bcd((time & (RTC_TR_MNT | RTC_TR_MNU)) >> RTC_TR_MNU_Pos); + result.second = from_bcd((time & (RTC_TR_ST | RTC_TR_SU)) >> RTC_TR_SU_Pos); + } + return result; +} \ No newline at end of file diff --git a/panda/board/get_sdk.sh b/panda/board/get_sdk.sh index 7b8d1f9154c0ac..3a009a5a13173f 100755 --- a/panda/board/get_sdk.sh +++ b/panda/board/get_sdk.sh @@ -1,3 +1,3 @@ #!/bin/bash sudo apt-get install gcc-arm-none-eabi python-pip -sudo pip2 install libusb1 pycrypto requests +sudo pip install libusb1 pycrypto requests diff --git a/panda/board/get_sdk_mac.sh b/panda/board/get_sdk_mac.sh index a6f641dce12116..a0a919f7d85e04 100755 --- a/panda/board/get_sdk_mac.sh +++ b/panda/board/get_sdk_mac.sh @@ -2,4 +2,4 @@ # Need formula for gcc brew tap ArmMbed/homebrew-formulae brew install python dfu-util arm-none-eabi-gcc -pip2 install libusb1 pycrypto requests +pip install --user libusb1 pycrypto requests diff --git a/panda/board/inc/cmsis_compiler.h b/panda/board/inc/cmsis_compiler.h new file mode 100644 index 00000000000000..d0f39eef67ed91 --- /dev/null +++ b/panda/board/inc/cmsis_compiler.h @@ -0,0 +1,284 @@ +/**************************************************************************//** + * @file cmsis_compiler.h + * @brief CMSIS compiler generic header file + * @version V5.1.0 + * @date 09. October 2018 + ******************************************************************************/ +/* + * Copyright (c) 2009-2018 Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __CMSIS_COMPILER_H +#define __CMSIS_COMPILER_H + +#include + +/* + * Arm Compiler 4/5 + */ +#if defined ( __CC_ARM ) + #include "cmsis_armcc.h" + + +/* + * Arm Compiler 6.6 LTM (armclang) + */ +#elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) && (__ARMCC_VERSION < 6100100) + #include "cmsis_armclang_ltm.h" + + /* + * Arm Compiler above 6.10.1 (armclang) + */ +#elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6100100) + #include "cmsis_armclang.h" + + +/* + * GNU Compiler + */ +#elif defined ( __GNUC__ ) + #include "cmsis_gcc.h" + + +/* + * IAR Compiler + */ +#elif defined ( __ICCARM__ ) + #include + + +/* + * TI Arm Compiler + */ +#elif defined ( __TI_ARM__ ) + #include + + #ifndef __ASM + #define __ASM __asm + #endif + #ifndef __INLINE + #define __INLINE inline + #endif + #ifndef __STATIC_INLINE + #define __STATIC_INLINE static inline + #endif + #ifndef __STATIC_FORCEINLINE + #define __STATIC_FORCEINLINE __STATIC_INLINE + #endif + #ifndef __NO_RETURN + #define __NO_RETURN __attribute__((noreturn)) + #endif + #ifndef __USED + #define __USED __attribute__((used)) + #endif + #ifndef __WEAK + #define __WEAK __attribute__((weak)) + #endif + #ifndef __PACKED + #define __PACKED __attribute__((packed)) + #endif + #ifndef __PACKED_STRUCT + #define __PACKED_STRUCT struct __attribute__((packed)) + #endif + #ifndef __PACKED_UNION + #define __PACKED_UNION union __attribute__((packed)) + #endif + #ifndef __UNALIGNED_UINT32 /* deprecated */ + struct __attribute__((packed)) T_UINT32 { uint32_t v; }; + #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) + #endif + #ifndef __UNALIGNED_UINT16_WRITE + __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; + #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val)) + #endif + #ifndef __UNALIGNED_UINT16_READ + __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; + #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) + #endif + #ifndef __UNALIGNED_UINT32_WRITE + __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; + #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) + #endif + #ifndef __UNALIGNED_UINT32_READ + __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; + #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) + #endif + #ifndef __ALIGNED + #define __ALIGNED(x) __attribute__((aligned(x))) + #endif + #ifndef __RESTRICT + #define __RESTRICT __restrict + #endif + #ifndef __COMPILER_BARRIER + #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored. + #define __COMPILER_BARRIER() (void)0 + #endif + + +/* + * TASKING Compiler + */ +#elif defined ( __TASKING__ ) + /* + * The CMSIS functions have been implemented as intrinsics in the compiler. + * Please use "carm -?i" to get an up to date list of all intrinsics, + * Including the CMSIS ones. + */ + + #ifndef __ASM + #define __ASM __asm + #endif + #ifndef __INLINE + #define __INLINE inline + #endif + #ifndef __STATIC_INLINE + #define __STATIC_INLINE static inline + #endif + #ifndef __STATIC_FORCEINLINE + #define __STATIC_FORCEINLINE __STATIC_INLINE + #endif + #ifndef __NO_RETURN + #define __NO_RETURN __attribute__((noreturn)) + #endif + #ifndef __USED + #define __USED __attribute__((used)) + #endif + #ifndef __WEAK + #define __WEAK __attribute__((weak)) + #endif + #ifndef __PACKED + #define __PACKED __packed__ + #endif + #ifndef __PACKED_STRUCT + #define __PACKED_STRUCT struct __packed__ + #endif + #ifndef __PACKED_UNION + #define __PACKED_UNION union __packed__ + #endif + #ifndef __UNALIGNED_UINT32 /* deprecated */ + struct __packed__ T_UINT32 { uint32_t v; }; + #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) + #endif + #ifndef __UNALIGNED_UINT16_WRITE + __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; + #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val)) + #endif + #ifndef __UNALIGNED_UINT16_READ + __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; + #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) + #endif + #ifndef __UNALIGNED_UINT32_WRITE + __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; + #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) + #endif + #ifndef __UNALIGNED_UINT32_READ + __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; + #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) + #endif + #ifndef __ALIGNED + #define __ALIGNED(x) __align(x) + #endif + #ifndef __RESTRICT + #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored. + #define __RESTRICT + #endif + #ifndef __COMPILER_BARRIER + #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored. + #define __COMPILER_BARRIER() (void)0 + #endif + + +/* + * COSMIC Compiler + */ +#elif defined ( __CSMC__ ) + #include + + #ifndef __ASM + #define __ASM _asm + #endif + #ifndef __INLINE + #define __INLINE inline + #endif + #ifndef __STATIC_INLINE + #define __STATIC_INLINE static inline + #endif + #ifndef __STATIC_FORCEINLINE + #define __STATIC_FORCEINLINE __STATIC_INLINE + #endif + #ifndef __NO_RETURN + // NO RETURN is automatically detected hence no warning here + #define __NO_RETURN + #endif + #ifndef __USED + #warning No compiler specific solution for __USED. __USED is ignored. + #define __USED + #endif + #ifndef __WEAK + #define __WEAK __weak + #endif + #ifndef __PACKED + #define __PACKED @packed + #endif + #ifndef __PACKED_STRUCT + #define __PACKED_STRUCT @packed struct + #endif + #ifndef __PACKED_UNION + #define __PACKED_UNION @packed union + #endif + #ifndef __UNALIGNED_UINT32 /* deprecated */ + @packed struct T_UINT32 { uint32_t v; }; + #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) + #endif + #ifndef __UNALIGNED_UINT16_WRITE + __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; + #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val)) + #endif + #ifndef __UNALIGNED_UINT16_READ + __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; + #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) + #endif + #ifndef __UNALIGNED_UINT32_WRITE + __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; + #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) + #endif + #ifndef __UNALIGNED_UINT32_READ + __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; + #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) + #endif + #ifndef __ALIGNED + #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored. + #define __ALIGNED(x) + #endif + #ifndef __RESTRICT + #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored. + #define __RESTRICT + #endif + #ifndef __COMPILER_BARRIER + #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored. + #define __COMPILER_BARRIER() (void)0 + #endif + + +#else + #error Unknown compiler. +#endif + + +#endif /* __CMSIS_COMPILER_H */ + + diff --git a/panda/board/inc/cmsis_gcc.h b/panda/board/inc/cmsis_gcc.h index bb89fbba9e4000..3589d18b243b7d 100644 --- a/panda/board/inc/cmsis_gcc.h +++ b/panda/board/inc/cmsis_gcc.h @@ -1,48 +1,186 @@ /**************************************************************************//** * @file cmsis_gcc.h - * @brief CMSIS Cortex-M Core Function/Instruction Header File - * @version V4.30 - * @date 20. October 2015 + * @brief CMSIS compiler GCC header file + * @version V5.2.0 + * @date 08. May 2019 ******************************************************************************/ -/* Copyright (c) 2009 - 2015 ARM LIMITED - - All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of ARM nor the names of its contributors may be used - to endorse or promote products derived from this software without - specific prior written permission. - * - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - ---------------------------------------------------------------------------*/ - +/* + * Copyright (c) 2009-2019 Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #ifndef __CMSIS_GCC_H #define __CMSIS_GCC_H /* ignore some GCC warnings */ -#if defined ( __GNUC__ ) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wsign-conversion" #pragma GCC diagnostic ignored "-Wconversion" #pragma GCC diagnostic ignored "-Wunused-parameter" + +/* Fallback for __has_builtin */ +#ifndef __has_builtin + #define __has_builtin(x) (0) +#endif + +/* CMSIS compiler specific defines */ +#ifndef __ASM + #define __ASM __asm +#endif +#ifndef __INLINE + #define __INLINE inline +#endif +#ifndef __STATIC_INLINE + #define __STATIC_INLINE static inline +#endif +#ifndef __STATIC_FORCEINLINE + #define __STATIC_FORCEINLINE __attribute__((always_inline)) static inline +#endif +#ifndef __NO_RETURN + #define __NO_RETURN __attribute__((__noreturn__)) +#endif +#ifndef __USED + #define __USED __attribute__((used)) +#endif +#ifndef __WEAK + #define __WEAK __attribute__((weak)) +#endif +#ifndef __PACKED + #define __PACKED __attribute__((packed, aligned(1))) +#endif +#ifndef __PACKED_STRUCT + #define __PACKED_STRUCT struct __attribute__((packed, aligned(1))) +#endif +#ifndef __PACKED_UNION + #define __PACKED_UNION union __attribute__((packed, aligned(1))) +#endif +#ifndef __UNALIGNED_UINT32 /* deprecated */ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wpacked" + #pragma GCC diagnostic ignored "-Wattributes" + struct __attribute__((packed)) T_UINT32 { uint32_t v; }; + #pragma GCC diagnostic pop + #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) +#endif +#ifndef __UNALIGNED_UINT16_WRITE + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wpacked" + #pragma GCC diagnostic ignored "-Wattributes" + __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; + #pragma GCC diagnostic pop + #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val)) +#endif +#ifndef __UNALIGNED_UINT16_READ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wpacked" + #pragma GCC diagnostic ignored "-Wattributes" + __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; + #pragma GCC diagnostic pop + #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) +#endif +#ifndef __UNALIGNED_UINT32_WRITE + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wpacked" + #pragma GCC diagnostic ignored "-Wattributes" + __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; + #pragma GCC diagnostic pop + #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) +#endif +#ifndef __UNALIGNED_UINT32_READ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wpacked" + #pragma GCC diagnostic ignored "-Wattributes" + __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; + #pragma GCC diagnostic pop + #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) +#endif +#ifndef __ALIGNED + #define __ALIGNED(x) __attribute__((aligned(x))) +#endif +#ifndef __RESTRICT + #define __RESTRICT __restrict +#endif +#ifndef __COMPILER_BARRIER + #define __COMPILER_BARRIER() __ASM volatile("":::"memory") #endif +/* ######################### Startup and Lowlevel Init ######################## */ + +#ifndef __PROGRAM_START + +/** + \brief Initializes data and bss sections + \details This default implementations initialized all data and additional bss + sections relying on .copy.table and .zero.table specified properly + in the used linker script. + + */ +__STATIC_FORCEINLINE __NO_RETURN void __cmsis_start(void) +{ + extern void _start(void) __NO_RETURN; + + typedef struct { + uint32_t const* src; + uint32_t* dest; + uint32_t wlen; + } __copy_table_t; + + typedef struct { + uint32_t* dest; + uint32_t wlen; + } __zero_table_t; + + extern const __copy_table_t __copy_table_start__; + extern const __copy_table_t __copy_table_end__; + extern const __zero_table_t __zero_table_start__; + extern const __zero_table_t __zero_table_end__; + + for (__copy_table_t const* pTable = &__copy_table_start__; pTable < &__copy_table_end__; ++pTable) { + for(uint32_t i=0u; iwlen; ++i) { + pTable->dest[i] = pTable->src[i]; + } + } + + for (__zero_table_t const* pTable = &__zero_table_start__; pTable < &__zero_table_end__; ++pTable) { + for(uint32_t i=0u; iwlen; ++i) { + pTable->dest[i] = 0u; + } + } + + _start(); +} + +#define __PROGRAM_START __cmsis_start +#endif + +#ifndef __INITIAL_SP +#define __INITIAL_SP __StackTop +#endif + +#ifndef __STACK_LIMIT +#define __STACK_LIMIT __StackLimit +#endif + +#ifndef __VECTOR_TABLE +#define __VECTOR_TABLE __Vectors +#endif + +#ifndef __VECTOR_TABLE_ATTRIBUTE +#define __VECTOR_TABLE_ATTRIBUTE __attribute((used, section(".vectors"))) +#endif /* ########################### Core Function Access ########################### */ /** \ingroup CMSIS_Core_FunctionInterface @@ -55,7 +193,7 @@ \details Enables IRQ interrupts by clearing the I-bit in the CPSR. Can only be executed in Privileged modes. */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __enable_irq(void) +__STATIC_FORCEINLINE void __enable_irq(void) { __ASM volatile ("cpsie i" : : : "memory"); } @@ -64,9 +202,9 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE void __enable_irq(void) /** \brief Disable IRQ Interrupts \details Disables IRQ interrupts by setting the I-bit in the CPSR. - Can only be executed in Privileged modes. + Can only be executed in Privileged modes. */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __disable_irq(void) +__STATIC_FORCEINLINE void __disable_irq(void) { __ASM volatile ("cpsid i" : : : "memory"); } @@ -77,7 +215,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE void __disable_irq(void) \details Returns the content of the Control Register. \return Control Register value */ -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_CONTROL(void) +__STATIC_FORCEINLINE uint32_t __get_CONTROL(void) { uint32_t result; @@ -86,23 +224,52 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_CONTROL(void) } +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Get Control Register (non-secure) + \details Returns the content of the non-secure Control Register when in secure mode. + \return non-secure Control Register value + */ +__STATIC_FORCEINLINE uint32_t __TZ_get_CONTROL_NS(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, control_ns" : "=r" (result) ); + return(result); +} +#endif + + /** \brief Set Control Register \details Writes the given value to the Control Register. \param [in] control Control Register value to set */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_CONTROL(uint32_t control) +__STATIC_FORCEINLINE void __set_CONTROL(uint32_t control) { __ASM volatile ("MSR control, %0" : : "r" (control) : "memory"); } +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Set Control Register (non-secure) + \details Writes the given value to the non-secure Control Register when in secure state. + \param [in] control Control Register value to set + */ +__STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control) +{ + __ASM volatile ("MSR control_ns, %0" : : "r" (control) : "memory"); +} +#endif + + /** \brief Get IPSR Register \details Returns the content of the IPSR Register. \return IPSR Register value */ -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_IPSR(void) +__STATIC_FORCEINLINE uint32_t __get_IPSR(void) { uint32_t result; @@ -116,7 +283,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_IPSR(void) \details Returns the content of the APSR Register. \return APSR Register value */ -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_APSR(void) +__STATIC_FORCEINLINE uint32_t __get_APSR(void) { uint32_t result; @@ -128,10 +295,9 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_APSR(void) /** \brief Get xPSR Register \details Returns the content of the xPSR Register. - - \return xPSR Register value + \return xPSR Register value */ -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_xPSR(void) +__STATIC_FORCEINLINE uint32_t __get_xPSR(void) { uint32_t result; @@ -145,13 +311,29 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_xPSR(void) \details Returns the current value of the Process Stack Pointer (PSP). \return PSP Register value */ -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_PSP(void) +__STATIC_FORCEINLINE uint32_t __get_PSP(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, psp" : "=r" (result) ); + return(result); +} + + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Get Process Stack Pointer (non-secure) + \details Returns the current value of the non-secure Process Stack Pointer (PSP) when in secure state. + \return PSP Register value + */ +__STATIC_FORCEINLINE uint32_t __TZ_get_PSP_NS(void) { - register uint32_t result; + uint32_t result; - __ASM volatile ("MRS %0, psp\n" : "=r" (result) ); + __ASM volatile ("MRS %0, psp_ns" : "=r" (result) ); return(result); } +#endif /** @@ -159,36 +341,104 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_PSP(void) \details Assigns the given value to the Process Stack Pointer (PSP). \param [in] topOfProcStack Process Stack Pointer value to set */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_PSP(uint32_t topOfProcStack) +__STATIC_FORCEINLINE void __set_PSP(uint32_t topOfProcStack) { - __ASM volatile ("MSR psp, %0\n" : : "r" (topOfProcStack) : "sp"); + __ASM volatile ("MSR psp, %0" : : "r" (topOfProcStack) : ); } +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Set Process Stack Pointer (non-secure) + \details Assigns the given value to the non-secure Process Stack Pointer (PSP) when in secure state. + \param [in] topOfProcStack Process Stack Pointer value to set + */ +__STATIC_FORCEINLINE void __TZ_set_PSP_NS(uint32_t topOfProcStack) +{ + __ASM volatile ("MSR psp_ns, %0" : : "r" (topOfProcStack) : ); +} +#endif + + /** \brief Get Main Stack Pointer \details Returns the current value of the Main Stack Pointer (MSP). \return MSP Register value */ -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_MSP(void) +__STATIC_FORCEINLINE uint32_t __get_MSP(void) { - register uint32_t result; + uint32_t result; - __ASM volatile ("MRS %0, msp\n" : "=r" (result) ); + __ASM volatile ("MRS %0, msp" : "=r" (result) ); return(result); } +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Get Main Stack Pointer (non-secure) + \details Returns the current value of the non-secure Main Stack Pointer (MSP) when in secure state. + \return MSP Register value + */ +__STATIC_FORCEINLINE uint32_t __TZ_get_MSP_NS(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, msp_ns" : "=r" (result) ); + return(result); +} +#endif + + /** \brief Set Main Stack Pointer \details Assigns the given value to the Main Stack Pointer (MSP). + \param [in] topOfMainStack Main Stack Pointer value to set + */ +__STATIC_FORCEINLINE void __set_MSP(uint32_t topOfMainStack) +{ + __ASM volatile ("MSR msp, %0" : : "r" (topOfMainStack) : ); +} - \param [in] topOfMainStack Main Stack Pointer value to set + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Set Main Stack Pointer (non-secure) + \details Assigns the given value to the non-secure Main Stack Pointer (MSP) when in secure state. + \param [in] topOfMainStack Main Stack Pointer value to set + */ +__STATIC_FORCEINLINE void __TZ_set_MSP_NS(uint32_t topOfMainStack) +{ + __ASM volatile ("MSR msp_ns, %0" : : "r" (topOfMainStack) : ); +} +#endif + + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Get Stack Pointer (non-secure) + \details Returns the current value of the non-secure Stack Pointer (SP) when in secure state. + \return SP Register value + */ +__STATIC_FORCEINLINE uint32_t __TZ_get_SP_NS(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, sp_ns" : "=r" (result) ); + return(result); +} + + +/** + \brief Set Stack Pointer (non-secure) + \details Assigns the given value to the non-secure Stack Pointer (SP) when in secure state. + \param [in] topOfStack Stack Pointer value to set */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_MSP(uint32_t topOfMainStack) +__STATIC_FORCEINLINE void __TZ_set_SP_NS(uint32_t topOfStack) { - __ASM volatile ("MSR msp, %0\n" : : "r" (topOfMainStack) : "sp"); + __ASM volatile ("MSR sp_ns, %0" : : "r" (topOfStack) : ); } +#endif /** @@ -196,13 +446,29 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_MSP(uint32_t topOf \details Returns the current state of the priority mask bit from the Priority Mask Register. \return Priority Mask value */ -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_PRIMASK(void) +__STATIC_FORCEINLINE uint32_t __get_PRIMASK(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, primask" : "=r" (result) :: "memory"); + return(result); +} + + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Get Priority Mask (non-secure) + \details Returns the current state of the non-secure priority mask bit from the Priority Mask Register when in secure state. + \return Priority Mask value + */ +__STATIC_FORCEINLINE uint32_t __TZ_get_PRIMASK_NS(void) { uint32_t result; - __ASM volatile ("MRS %0, primask" : "=r" (result) ); + __ASM volatile ("MRS %0, primask_ns" : "=r" (result) :: "memory"); return(result); } +#endif /** @@ -210,20 +476,34 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_PRIMASK(void) \details Assigns the given value to the Priority Mask Register. \param [in] priMask Priority Mask */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_PRIMASK(uint32_t priMask) +__STATIC_FORCEINLINE void __set_PRIMASK(uint32_t priMask) { __ASM volatile ("MSR primask, %0" : : "r" (priMask) : "memory"); } -#if (__CORTEX_M >= 0x03U) +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Set Priority Mask (non-secure) + \details Assigns the given value to the non-secure Priority Mask Register when in secure state. + \param [in] priMask Priority Mask + */ +__STATIC_FORCEINLINE void __TZ_set_PRIMASK_NS(uint32_t priMask) +{ + __ASM volatile ("MSR primask_ns, %0" : : "r" (priMask) : "memory"); +} +#endif + +#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) /** \brief Enable FIQ \details Enables FIQ interrupts by clearing the F-bit in the CPSR. Can only be executed in Privileged modes. */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __enable_fault_irq(void) +__STATIC_FORCEINLINE void __enable_fault_irq(void) { __ASM volatile ("cpsie f" : : : "memory"); } @@ -234,7 +514,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE void __enable_fault_irq(void) \details Disables FIQ interrupts by setting the F-bit in the CPSR. Can only be executed in Privileged modes. */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __disable_fault_irq(void) +__STATIC_FORCEINLINE void __disable_fault_irq(void) { __ASM volatile ("cpsid f" : : : "memory"); } @@ -245,7 +525,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE void __disable_fault_irq(void \details Returns the current value of the Base Priority register. \return Base Priority register value */ -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_BASEPRI(void) +__STATIC_FORCEINLINE uint32_t __get_BASEPRI(void) { uint32_t result; @@ -254,15 +534,44 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_BASEPRI(void) } +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Get Base Priority (non-secure) + \details Returns the current value of the non-secure Base Priority register when in secure state. + \return Base Priority register value + */ +__STATIC_FORCEINLINE uint32_t __TZ_get_BASEPRI_NS(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, basepri_ns" : "=r" (result) ); + return(result); +} +#endif + + /** \brief Set Base Priority \details Assigns the given value to the Base Priority register. \param [in] basePri Base Priority value to set */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_BASEPRI(uint32_t value) +__STATIC_FORCEINLINE void __set_BASEPRI(uint32_t basePri) +{ + __ASM volatile ("MSR basepri, %0" : : "r" (basePri) : "memory"); +} + + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Set Base Priority (non-secure) + \details Assigns the given value to the non-secure Base Priority register when in secure state. + \param [in] basePri Base Priority value to set + */ +__STATIC_FORCEINLINE void __TZ_set_BASEPRI_NS(uint32_t basePri) { - __ASM volatile ("MSR basepri, %0" : : "r" (value) : "memory"); + __ASM volatile ("MSR basepri_ns, %0" : : "r" (basePri) : "memory"); } +#endif /** @@ -271,9 +580,9 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_BASEPRI(uint32_t v or the new value increases the BASEPRI priority level. \param [in] basePri Base Priority value to set */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_BASEPRI_MAX(uint32_t value) +__STATIC_FORCEINLINE void __set_BASEPRI_MAX(uint32_t basePri) { - __ASM volatile ("MSR basepri_max, %0" : : "r" (value) : "memory"); + __ASM volatile ("MSR basepri_max, %0" : : "r" (basePri) : "memory"); } @@ -282,7 +591,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_BASEPRI_MAX(uint32 \details Returns the current value of the Fault Mask register. \return Fault Mask register value */ -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_FAULTMASK(void) +__STATIC_FORCEINLINE uint32_t __get_FAULTMASK(void) { uint32_t result; @@ -291,38 +600,253 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_FAULTMASK(void } +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Get Fault Mask (non-secure) + \details Returns the current value of the non-secure Fault Mask register when in secure state. + \return Fault Mask register value + */ +__STATIC_FORCEINLINE uint32_t __TZ_get_FAULTMASK_NS(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, faultmask_ns" : "=r" (result) ); + return(result); +} +#endif + + /** \brief Set Fault Mask \details Assigns the given value to the Fault Mask register. \param [in] faultMask Fault Mask value to set */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask) +__STATIC_FORCEINLINE void __set_FAULTMASK(uint32_t faultMask) { __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) : "memory"); } -#endif /* (__CORTEX_M >= 0x03U) */ +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Set Fault Mask (non-secure) + \details Assigns the given value to the non-secure Fault Mask register when in secure state. + \param [in] faultMask Fault Mask value to set + */ +__STATIC_FORCEINLINE void __TZ_set_FAULTMASK_NS(uint32_t faultMask) +{ + __ASM volatile ("MSR faultmask_ns, %0" : : "r" (faultMask) : "memory"); +} +#endif + +#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */ + + +#if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) + +/** + \brief Get Process Stack Pointer Limit + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence zero is returned always in non-secure + mode. + + \details Returns the current value of the Process Stack Pointer Limit (PSPLIM). + \return PSPLIM Register value + */ +__STATIC_FORCEINLINE uint32_t __get_PSPLIM(void) +{ +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ + (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) + // without main extensions, the non-secure PSPLIM is RAZ/WI + return 0U; +#else + uint32_t result; + __ASM volatile ("MRS %0, psplim" : "=r" (result) ); + return result; +#endif +} + +#if (defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Get Process Stack Pointer Limit (non-secure) + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence zero is returned always. + + \details Returns the current value of the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state. + \return PSPLIM Register value + */ +__STATIC_FORCEINLINE uint32_t __TZ_get_PSPLIM_NS(void) +{ +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))) + // without main extensions, the non-secure PSPLIM is RAZ/WI + return 0U; +#else + uint32_t result; + __ASM volatile ("MRS %0, psplim_ns" : "=r" (result) ); + return result; +#endif +} +#endif + + +/** + \brief Set Process Stack Pointer Limit + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence the write is silently ignored in non-secure + mode. + + \details Assigns the given value to the Process Stack Pointer Limit (PSPLIM). + \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set + */ +__STATIC_FORCEINLINE void __set_PSPLIM(uint32_t ProcStackPtrLimit) +{ +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ + (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) + // without main extensions, the non-secure PSPLIM is RAZ/WI + (void)ProcStackPtrLimit; +#else + __ASM volatile ("MSR psplim, %0" : : "r" (ProcStackPtrLimit)); +#endif +} + + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Set Process Stack Pointer (non-secure) + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence the write is silently ignored. + + \details Assigns the given value to the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state. + \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set + */ +__STATIC_FORCEINLINE void __TZ_set_PSPLIM_NS(uint32_t ProcStackPtrLimit) +{ +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))) + // without main extensions, the non-secure PSPLIM is RAZ/WI + (void)ProcStackPtrLimit; +#else + __ASM volatile ("MSR psplim_ns, %0\n" : : "r" (ProcStackPtrLimit)); +#endif +} +#endif + + +/** + \brief Get Main Stack Pointer Limit + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence zero is returned always in non-secure + mode. + + \details Returns the current value of the Main Stack Pointer Limit (MSPLIM). + \return MSPLIM Register value + */ +__STATIC_FORCEINLINE uint32_t __get_MSPLIM(void) +{ +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ + (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) + // without main extensions, the non-secure MSPLIM is RAZ/WI + return 0U; +#else + uint32_t result; + __ASM volatile ("MRS %0, msplim" : "=r" (result) ); + return result; +#endif +} + + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Get Main Stack Pointer Limit (non-secure) + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence zero is returned always. + + \details Returns the current value of the non-secure Main Stack Pointer Limit(MSPLIM) when in secure state. + \return MSPLIM Register value + */ +__STATIC_FORCEINLINE uint32_t __TZ_get_MSPLIM_NS(void) +{ +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))) + // without main extensions, the non-secure MSPLIM is RAZ/WI + return 0U; +#else + uint32_t result; + __ASM volatile ("MRS %0, msplim_ns" : "=r" (result) ); + return result; +#endif +} +#endif + + +/** + \brief Set Main Stack Pointer Limit + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence the write is silently ignored in non-secure + mode. + + \details Assigns the given value to the Main Stack Pointer Limit (MSPLIM). + \param [in] MainStackPtrLimit Main Stack Pointer Limit value to set + */ +__STATIC_FORCEINLINE void __set_MSPLIM(uint32_t MainStackPtrLimit) +{ +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ + (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) + // without main extensions, the non-secure MSPLIM is RAZ/WI + (void)MainStackPtrLimit; +#else + __ASM volatile ("MSR msplim, %0" : : "r" (MainStackPtrLimit)); +#endif +} + + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Set Main Stack Pointer Limit (non-secure) + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence the write is silently ignored. + + \details Assigns the given value to the non-secure Main Stack Pointer Limit (MSPLIM) when in secure state. + \param [in] MainStackPtrLimit Main Stack Pointer value to set + */ +__STATIC_FORCEINLINE void __TZ_set_MSPLIM_NS(uint32_t MainStackPtrLimit) +{ +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))) + // without main extensions, the non-secure MSPLIM is RAZ/WI + (void)MainStackPtrLimit; +#else + __ASM volatile ("MSR msplim_ns, %0" : : "r" (MainStackPtrLimit)); +#endif +} +#endif + +#endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */ -#if (__CORTEX_M == 0x04U) || (__CORTEX_M == 0x07U) /** \brief Get FPSCR \details Returns the current value of the Floating Point Status/Control register. \return Floating Point Status/Control register value */ -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_FPSCR(void) -{ -#if (__FPU_PRESENT == 1U) && (__FPU_USED == 1U) +__STATIC_FORCEINLINE uint32_t __get_FPSCR(void) +{ +#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ + (defined (__FPU_USED ) && (__FPU_USED == 1U)) ) +#if __has_builtin(__builtin_arm_get_fpscr) +// Re-enable using built-in when GCC has been fixed +// || (__GNUC__ > 7) || (__GNUC__ == 7 && __GNUC_MINOR__ >= 2) + /* see https://gcc.gnu.org/ml/gcc-patches/2017-04/msg00443.html */ + return __builtin_arm_get_fpscr(); +#else uint32_t result; - /* Empty asm statement works as a scheduling barrier */ - __ASM volatile (""); __ASM volatile ("VMRS %0, fpscr" : "=r" (result) ); - __ASM volatile (""); return(result); +#endif #else - return(0); + return(0U); #endif } @@ -332,19 +856,23 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_FPSCR(void) \details Assigns the given value to the Floating Point Status/Control register. \param [in] fpscr Floating Point Status/Control value to set */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_FPSCR(uint32_t fpscr) -{ -#if (__FPU_PRESENT == 1U) && (__FPU_USED == 1U) - /* Empty asm statement works as a scheduling barrier */ - __ASM volatile (""); - __ASM volatile ("VMSR fpscr, %0" : : "r" (fpscr) : "vfpcc"); - __ASM volatile (""); +__STATIC_FORCEINLINE void __set_FPSCR(uint32_t fpscr) +{ +#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ + (defined (__FPU_USED ) && (__FPU_USED == 1U)) ) +#if __has_builtin(__builtin_arm_set_fpscr) +// Re-enable using built-in when GCC has been fixed +// || (__GNUC__ > 7) || (__GNUC__ == 7 && __GNUC_MINOR__ >= 2) + /* see https://gcc.gnu.org/ml/gcc-patches/2017-04/msg00443.html */ + __builtin_arm_set_fpscr(fpscr); +#else + __ASM volatile ("VMSR fpscr, %0" : : "r" (fpscr) : "vfpcc", "memory"); +#endif +#else + (void)fpscr; #endif } -#endif /* (__CORTEX_M == 0x04U) || (__CORTEX_M == 0x07U) */ - - /*@} end of CMSIS_Core_RegAccFunctions */ @@ -360,9 +888,11 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_FPSCR(uint32_t fps * Otherwise, use general registers, specified by constraint "r" */ #if defined (__thumb__) && !defined (__thumb2__) #define __CMSIS_GCC_OUT_REG(r) "=l" (r) +#define __CMSIS_GCC_RW_REG(r) "+l" (r) #define __CMSIS_GCC_USE_REG(r) "l" (r) #else #define __CMSIS_GCC_OUT_REG(r) "=r" (r) +#define __CMSIS_GCC_RW_REG(r) "+r" (r) #define __CMSIS_GCC_USE_REG(r) "r" (r) #endif @@ -370,41 +900,28 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_FPSCR(uint32_t fps \brief No Operation \details No Operation does nothing. This instruction can be used for code alignment purposes. */ -__attribute__((always_inline)) __STATIC_INLINE void __NOP(void) -{ - __ASM volatile ("nop"); -} - +#define __NOP() __ASM volatile ("nop") /** \brief Wait For Interrupt \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs. */ -__attribute__((always_inline)) __STATIC_INLINE void __WFI(void) -{ - __ASM volatile ("wfi"); -} +#define __WFI() __ASM volatile ("wfi") /** \brief Wait For Event \details Wait For Event is a hint instruction that permits the processor to enter - a low-power state until one of a number of events occurs. + a low-power state until one of a number of events occurs. */ -__attribute__((always_inline)) __STATIC_INLINE void __WFE(void) -{ - __ASM volatile ("wfe"); -} +#define __WFE() __ASM volatile ("wfe") /** \brief Send Event \details Send Event is a hint instruction. It causes an event to be signaled to the CPU. */ -__attribute__((always_inline)) __STATIC_INLINE void __SEV(void) -{ - __ASM volatile ("sev"); -} +#define __SEV() __ASM volatile ("sev") /** @@ -413,7 +930,7 @@ __attribute__((always_inline)) __STATIC_INLINE void __SEV(void) so that all instructions following the ISB are fetched from cache or memory, after the instruction has been completed. */ -__attribute__((always_inline)) __STATIC_INLINE void __ISB(void) +__STATIC_FORCEINLINE void __ISB(void) { __ASM volatile ("isb 0xF":::"memory"); } @@ -424,7 +941,7 @@ __attribute__((always_inline)) __STATIC_INLINE void __ISB(void) \details Acts as a special kind of Data Memory Barrier. It completes when all explicit memory accesses before this instruction complete. */ -__attribute__((always_inline)) __STATIC_INLINE void __DSB(void) +__STATIC_FORCEINLINE void __DSB(void) { __ASM volatile ("dsb 0xF":::"memory"); } @@ -435,7 +952,7 @@ __attribute__((always_inline)) __STATIC_INLINE void __DSB(void) \details Ensures the apparent order of the explicit memory operations before and after the instruction, without ensuring their completion. */ -__attribute__((always_inline)) __STATIC_INLINE void __DMB(void) +__STATIC_FORCEINLINE void __DMB(void) { __ASM volatile ("dmb 0xF":::"memory"); } @@ -443,11 +960,11 @@ __attribute__((always_inline)) __STATIC_INLINE void __DMB(void) /** \brief Reverse byte order (32 bit) - \details Reverses the byte order in integer value. + \details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412. \param [in] value Value to reverse \return Reversed value */ -__attribute__((always_inline)) __STATIC_INLINE uint32_t __REV(uint32_t value) +__STATIC_FORCEINLINE uint32_t __REV(uint32_t value) { #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) return __builtin_bswap32(value); @@ -455,41 +972,41 @@ __attribute__((always_inline)) __STATIC_INLINE uint32_t __REV(uint32_t value) uint32_t result; __ASM volatile ("rev %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) ); - return(result); + return result; #endif } /** \brief Reverse byte order (16 bit) - \details Reverses the byte order in two unsigned short values. + \details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856. \param [in] value Value to reverse \return Reversed value */ -__attribute__((always_inline)) __STATIC_INLINE uint32_t __REV16(uint32_t value) +__STATIC_FORCEINLINE uint32_t __REV16(uint32_t value) { uint32_t result; __ASM volatile ("rev16 %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) ); - return(result); + return result; } /** - \brief Reverse byte order in signed short value - \details Reverses the byte order in a signed short value with sign extension to integer. + \brief Reverse byte order (16 bit) + \details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000. \param [in] value Value to reverse \return Reversed value */ -__attribute__((always_inline)) __STATIC_INLINE int32_t __REVSH(int32_t value) +__STATIC_FORCEINLINE int16_t __REVSH(int16_t value) { #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) - return (short)__builtin_bswap16(value); + return (int16_t)__builtin_bswap16(value); #else - int32_t result; + int16_t result; __ASM volatile ("revsh %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) ); - return(result); + return result; #endif } @@ -497,12 +1014,17 @@ __attribute__((always_inline)) __STATIC_INLINE int32_t __REVSH(int32_t value) /** \brief Rotate Right in unsigned value (32 bit) \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits. - \param [in] value Value to rotate - \param [in] value Number of Bits to rotate + \param [in] op1 Value to rotate + \param [in] op2 Number of Bits to rotate \return Rotated value */ -__attribute__((always_inline)) __STATIC_INLINE uint32_t __ROR(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __ROR(uint32_t op1, uint32_t op2) { + op2 %= 32U; + if (op2 == 0U) + { + return op1; + } return (op1 >> op2) | (op1 << (32U - op2)); } @@ -523,17 +1045,19 @@ __attribute__((always_inline)) __STATIC_INLINE uint32_t __ROR(uint32_t op1, uint \param [in] value Value to reverse \return Reversed value */ -__attribute__((always_inline)) __STATIC_INLINE uint32_t __RBIT(uint32_t value) +__STATIC_FORCEINLINE uint32_t __RBIT(uint32_t value) { uint32_t result; -#if (__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U) +#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) __ASM volatile ("rbit %0, %1" : "=r" (result) : "r" (value) ); #else - int32_t s = 4 /*sizeof(v)*/ * 8 - 1; /* extra shift needed at end */ + uint32_t s = (4U /*sizeof(v)*/ * 8U) - 1U; /* extra shift needed at end */ result = value; /* r will be reversed bits of v; first get LSB of v */ - for (value >>= 1U; value; value >>= 1U) + for (value >>= 1U; value != 0U; value >>= 1U) { result <<= 1U; result |= value & 1U; @@ -541,7 +1065,7 @@ __attribute__((always_inline)) __STATIC_INLINE uint32_t __RBIT(uint32_t value) } result <<= s; /* shift when v's highest bits are zero */ #endif - return(result); + return result; } @@ -551,18 +1075,36 @@ __attribute__((always_inline)) __STATIC_INLINE uint32_t __RBIT(uint32_t value) \param [in] value Value to count the leading zeros \return number of leading zeros in value */ -#define __CLZ __builtin_clz - +__STATIC_FORCEINLINE uint8_t __CLZ(uint32_t value) +{ + /* Even though __builtin_clz produces a CLZ instruction on ARM, formally + __builtin_clz(0) is undefined behaviour, so handle this case specially. + This guarantees ARM-compatible results if happening to compile on a non-ARM + target, and ensures the compiler doesn't decide to activate any + optimisations using the logic "value was passed to __builtin_clz, so it + is non-zero". + ARM GCC 7.3 and possibly earlier will optimise this test away, leaving a + single CLZ instruction. + */ + if (value == 0U) + { + return 32U; + } + return __builtin_clz(value); +} -#if (__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U) +#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) /** \brief LDR Exclusive (8 bit) \details Executes a exclusive LDR instruction for 8 bit value. \param [in] ptr Pointer to data \return value of type uint8_t at (*ptr) */ -__attribute__((always_inline)) __STATIC_INLINE uint8_t __LDREXB(volatile uint8_t *addr) +__STATIC_FORCEINLINE uint8_t __LDREXB(volatile uint8_t *addr) { uint32_t result; @@ -584,7 +1126,7 @@ __attribute__((always_inline)) __STATIC_INLINE uint8_t __LDREXB(volatile uint8_t \param [in] ptr Pointer to data \return value of type uint16_t at (*ptr) */ -__attribute__((always_inline)) __STATIC_INLINE uint16_t __LDREXH(volatile uint16_t *addr) +__STATIC_FORCEINLINE uint16_t __LDREXH(volatile uint16_t *addr) { uint32_t result; @@ -606,7 +1148,7 @@ __attribute__((always_inline)) __STATIC_INLINE uint16_t __LDREXH(volatile uint16 \param [in] ptr Pointer to data \return value of type uint32_t at (*ptr) */ -__attribute__((always_inline)) __STATIC_INLINE uint32_t __LDREXW(volatile uint32_t *addr) +__STATIC_FORCEINLINE uint32_t __LDREXW(volatile uint32_t *addr) { uint32_t result; @@ -623,7 +1165,7 @@ __attribute__((always_inline)) __STATIC_INLINE uint32_t __LDREXW(volatile uint32 \return 0 Function succeeded \return 1 Function failed */ -__attribute__((always_inline)) __STATIC_INLINE uint32_t __STREXB(uint8_t value, volatile uint8_t *addr) +__STATIC_FORCEINLINE uint32_t __STREXB(uint8_t value, volatile uint8_t *addr) { uint32_t result; @@ -640,7 +1182,7 @@ __attribute__((always_inline)) __STATIC_INLINE uint32_t __STREXB(uint8_t value, \return 0 Function succeeded \return 1 Function failed */ -__attribute__((always_inline)) __STATIC_INLINE uint32_t __STREXH(uint16_t value, volatile uint16_t *addr) +__STATIC_FORCEINLINE uint32_t __STREXH(uint16_t value, volatile uint16_t *addr) { uint32_t result; @@ -657,7 +1199,7 @@ __attribute__((always_inline)) __STATIC_INLINE uint32_t __STREXH(uint16_t value, \return 0 Function succeeded \return 1 Function failed */ -__attribute__((always_inline)) __STATIC_INLINE uint32_t __STREXW(uint32_t value, volatile uint32_t *addr) +__STATIC_FORCEINLINE uint32_t __STREXW(uint32_t value, volatile uint32_t *addr) { uint32_t result; @@ -670,22 +1212,31 @@ __attribute__((always_inline)) __STATIC_INLINE uint32_t __STREXW(uint32_t value, \brief Remove the exclusive lock \details Removes the exclusive lock which is created by LDREX. */ -__attribute__((always_inline)) __STATIC_INLINE void __CLREX(void) +__STATIC_FORCEINLINE void __CLREX(void) { __ASM volatile ("clrex" ::: "memory"); } +#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */ + +#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) /** \brief Signed Saturate \details Saturates a signed value. - \param [in] value Value to be saturated - \param [in] sat Bit position to saturate to (1..32) + \param [in] ARG1 Value to be saturated + \param [in] ARG2 Bit position to saturate to (1..32) \return Saturated value */ #define __SSAT(ARG1,ARG2) \ +__extension__ \ ({ \ - uint32_t __RES, __ARG1 = (ARG1); \ + int32_t __RES, __ARG1 = (ARG1); \ __ASM ("ssat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \ __RES; \ }) @@ -694,11 +1245,12 @@ __attribute__((always_inline)) __STATIC_INLINE void __CLREX(void) /** \brief Unsigned Saturate \details Saturates an unsigned value. - \param [in] value Value to be saturated - \param [in] sat Bit position to saturate to (0..31) + \param [in] ARG1 Value to be saturated + \param [in] ARG2 Bit position to saturate to (0..31) \return Saturated value */ #define __USAT(ARG1,ARG2) \ + __extension__ \ ({ \ uint32_t __RES, __ARG1 = (ARG1); \ __ASM ("usat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \ @@ -713,7 +1265,7 @@ __attribute__((always_inline)) __STATIC_INLINE void __CLREX(void) \param [in] value Value to rotate \return Rotated value */ -__attribute__((always_inline)) __STATIC_INLINE uint32_t __RRX(uint32_t value) +__STATIC_FORCEINLINE uint32_t __RRX(uint32_t value) { uint32_t result; @@ -728,17 +1280,17 @@ __attribute__((always_inline)) __STATIC_INLINE uint32_t __RRX(uint32_t value) \param [in] ptr Pointer to data \return value of type uint8_t at (*ptr) */ -__attribute__((always_inline)) __STATIC_INLINE uint8_t __LDRBT(volatile uint8_t *addr) +__STATIC_FORCEINLINE uint8_t __LDRBT(volatile uint8_t *ptr) { uint32_t result; #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) - __ASM volatile ("ldrbt %0, %1" : "=r" (result) : "Q" (*addr) ); + __ASM volatile ("ldrbt %0, %1" : "=r" (result) : "Q" (*ptr) ); #else /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not accepted by assembler. So has to use following less efficient pattern. */ - __ASM volatile ("ldrbt %0, [%1]" : "=r" (result) : "r" (addr) : "memory" ); + __ASM volatile ("ldrbt %0, [%1]" : "=r" (result) : "r" (ptr) : "memory" ); #endif return ((uint8_t) result); /* Add explicit type cast here */ } @@ -750,17 +1302,17 @@ __attribute__((always_inline)) __STATIC_INLINE uint8_t __LDRBT(volatile uint8_t \param [in] ptr Pointer to data \return value of type uint16_t at (*ptr) */ -__attribute__((always_inline)) __STATIC_INLINE uint16_t __LDRHT(volatile uint16_t *addr) +__STATIC_FORCEINLINE uint16_t __LDRHT(volatile uint16_t *ptr) { uint32_t result; #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) - __ASM volatile ("ldrht %0, %1" : "=r" (result) : "Q" (*addr) ); + __ASM volatile ("ldrht %0, %1" : "=r" (result) : "Q" (*ptr) ); #else /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not accepted by assembler. So has to use following less efficient pattern. */ - __ASM volatile ("ldrht %0, [%1]" : "=r" (result) : "r" (addr) : "memory" ); + __ASM volatile ("ldrht %0, [%1]" : "=r" (result) : "r" (ptr) : "memory" ); #endif return ((uint16_t) result); /* Add explicit type cast here */ } @@ -772,11 +1324,11 @@ __attribute__((always_inline)) __STATIC_INLINE uint16_t __LDRHT(volatile uint16_ \param [in] ptr Pointer to data \return value of type uint32_t at (*ptr) */ -__attribute__((always_inline)) __STATIC_INLINE uint32_t __LDRT(volatile uint32_t *addr) +__STATIC_FORCEINLINE uint32_t __LDRT(volatile uint32_t *ptr) { uint32_t result; - __ASM volatile ("ldrt %0, %1" : "=r" (result) : "Q" (*addr) ); + __ASM volatile ("ldrt %0, %1" : "=r" (result) : "Q" (*ptr) ); return(result); } @@ -787,9 +1339,9 @@ __attribute__((always_inline)) __STATIC_INLINE uint32_t __LDRT(volatile uint32_t \param [in] value Value to store \param [in] ptr Pointer to location */ -__attribute__((always_inline)) __STATIC_INLINE void __STRBT(uint8_t value, volatile uint8_t *addr) +__STATIC_FORCEINLINE void __STRBT(uint8_t value, volatile uint8_t *ptr) { - __ASM volatile ("strbt %1, %0" : "=Q" (*addr) : "r" ((uint32_t)value) ); + __ASM volatile ("strbt %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); } @@ -799,9 +1351,9 @@ __attribute__((always_inline)) __STATIC_INLINE void __STRBT(uint8_t value, volat \param [in] value Value to store \param [in] ptr Pointer to location */ -__attribute__((always_inline)) __STATIC_INLINE void __STRHT(uint16_t value, volatile uint16_t *addr) +__STATIC_FORCEINLINE void __STRHT(uint16_t value, volatile uint16_t *ptr) { - __ASM volatile ("strht %1, %0" : "=Q" (*addr) : "r" ((uint32_t)value) ); + __ASM volatile ("strht %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); } @@ -811,12 +1363,249 @@ __attribute__((always_inline)) __STATIC_INLINE void __STRHT(uint16_t value, vola \param [in] value Value to store \param [in] ptr Pointer to location */ -__attribute__((always_inline)) __STATIC_INLINE void __STRT(uint32_t value, volatile uint32_t *addr) +__STATIC_FORCEINLINE void __STRT(uint32_t value, volatile uint32_t *ptr) { - __ASM volatile ("strt %1, %0" : "=Q" (*addr) : "r" (value) ); + __ASM volatile ("strt %1, %0" : "=Q" (*ptr) : "r" (value) ); } -#endif /* (__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U) */ +#else /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */ + +/** + \brief Signed Saturate + \details Saturates a signed value. + \param [in] value Value to be saturated + \param [in] sat Bit position to saturate to (1..32) + \return Saturated value + */ +__STATIC_FORCEINLINE int32_t __SSAT(int32_t val, uint32_t sat) +{ + if ((sat >= 1U) && (sat <= 32U)) + { + const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U); + const int32_t min = -1 - max ; + if (val > max) + { + return max; + } + else if (val < min) + { + return min; + } + } + return val; +} + +/** + \brief Unsigned Saturate + \details Saturates an unsigned value. + \param [in] value Value to be saturated + \param [in] sat Bit position to saturate to (0..31) + \return Saturated value + */ +__STATIC_FORCEINLINE uint32_t __USAT(int32_t val, uint32_t sat) +{ + if (sat <= 31U) + { + const uint32_t max = ((1U << sat) - 1U); + if (val > (int32_t)max) + { + return max; + } + else if (val < 0) + { + return 0U; + } + } + return (uint32_t)val; +} + +#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */ + + +#if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) +/** + \brief Load-Acquire (8 bit) + \details Executes a LDAB instruction for 8 bit value. + \param [in] ptr Pointer to data + \return value of type uint8_t at (*ptr) + */ +__STATIC_FORCEINLINE uint8_t __LDAB(volatile uint8_t *ptr) +{ + uint32_t result; + + __ASM volatile ("ldab %0, %1" : "=r" (result) : "Q" (*ptr) ); + return ((uint8_t) result); +} + + +/** + \brief Load-Acquire (16 bit) + \details Executes a LDAH instruction for 16 bit values. + \param [in] ptr Pointer to data + \return value of type uint16_t at (*ptr) + */ +__STATIC_FORCEINLINE uint16_t __LDAH(volatile uint16_t *ptr) +{ + uint32_t result; + + __ASM volatile ("ldah %0, %1" : "=r" (result) : "Q" (*ptr) ); + return ((uint16_t) result); +} + + +/** + \brief Load-Acquire (32 bit) + \details Executes a LDA instruction for 32 bit values. + \param [in] ptr Pointer to data + \return value of type uint32_t at (*ptr) + */ +__STATIC_FORCEINLINE uint32_t __LDA(volatile uint32_t *ptr) +{ + uint32_t result; + + __ASM volatile ("lda %0, %1" : "=r" (result) : "Q" (*ptr) ); + return(result); +} + + +/** + \brief Store-Release (8 bit) + \details Executes a STLB instruction for 8 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + */ +__STATIC_FORCEINLINE void __STLB(uint8_t value, volatile uint8_t *ptr) +{ + __ASM volatile ("stlb %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); +} + + +/** + \brief Store-Release (16 bit) + \details Executes a STLH instruction for 16 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + */ +__STATIC_FORCEINLINE void __STLH(uint16_t value, volatile uint16_t *ptr) +{ + __ASM volatile ("stlh %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); +} + + +/** + \brief Store-Release (32 bit) + \details Executes a STL instruction for 32 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + */ +__STATIC_FORCEINLINE void __STL(uint32_t value, volatile uint32_t *ptr) +{ + __ASM volatile ("stl %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); +} + + +/** + \brief Load-Acquire Exclusive (8 bit) + \details Executes a LDAB exclusive instruction for 8 bit value. + \param [in] ptr Pointer to data + \return value of type uint8_t at (*ptr) + */ +__STATIC_FORCEINLINE uint8_t __LDAEXB(volatile uint8_t *ptr) +{ + uint32_t result; + + __ASM volatile ("ldaexb %0, %1" : "=r" (result) : "Q" (*ptr) ); + return ((uint8_t) result); +} + + +/** + \brief Load-Acquire Exclusive (16 bit) + \details Executes a LDAH exclusive instruction for 16 bit values. + \param [in] ptr Pointer to data + \return value of type uint16_t at (*ptr) + */ +__STATIC_FORCEINLINE uint16_t __LDAEXH(volatile uint16_t *ptr) +{ + uint32_t result; + + __ASM volatile ("ldaexh %0, %1" : "=r" (result) : "Q" (*ptr) ); + return ((uint16_t) result); +} + + +/** + \brief Load-Acquire Exclusive (32 bit) + \details Executes a LDA exclusive instruction for 32 bit values. + \param [in] ptr Pointer to data + \return value of type uint32_t at (*ptr) + */ +__STATIC_FORCEINLINE uint32_t __LDAEX(volatile uint32_t *ptr) +{ + uint32_t result; + + __ASM volatile ("ldaex %0, %1" : "=r" (result) : "Q" (*ptr) ); + return(result); +} + + +/** + \brief Store-Release Exclusive (8 bit) + \details Executes a STLB exclusive instruction for 8 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed + */ +__STATIC_FORCEINLINE uint32_t __STLEXB(uint8_t value, volatile uint8_t *ptr) +{ + uint32_t result; + + __ASM volatile ("stlexb %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) ); + return(result); +} + + +/** + \brief Store-Release Exclusive (16 bit) + \details Executes a STLH exclusive instruction for 16 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed + */ +__STATIC_FORCEINLINE uint32_t __STLEXH(uint16_t value, volatile uint16_t *ptr) +{ + uint32_t result; + + __ASM volatile ("stlexh %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) ); + return(result); +} + + +/** + \brief Store-Release Exclusive (32 bit) + \details Executes a STL exclusive instruction for 32 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed + */ +__STATIC_FORCEINLINE uint32_t __STLEX(uint32_t value, volatile uint32_t *ptr) +{ + uint32_t result; + + __ASM volatile ("stlex %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) ); + return(result); +} + +#endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */ /*@}*/ /* end of group CMSIS_Core_InstructionInterface */ @@ -827,9 +1616,9 @@ __attribute__((always_inline)) __STATIC_INLINE void __STRT(uint32_t value, volat @{ */ -#if (__CORTEX_M >= 0x04U) /* only for Cortex-M4 and above */ +#if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1)) -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SADD8(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __SADD8(uint32_t op1, uint32_t op2) { uint32_t result; @@ -837,7 +1626,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SADD8(uint32_t op1 return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QADD8(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __QADD8(uint32_t op1, uint32_t op2) { uint32_t result; @@ -845,7 +1634,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QADD8(uint32_t op1 return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHADD8(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __SHADD8(uint32_t op1, uint32_t op2) { uint32_t result; @@ -853,7 +1642,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHADD8(uint32_t op return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UADD8(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __UADD8(uint32_t op1, uint32_t op2) { uint32_t result; @@ -861,7 +1650,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UADD8(uint32_t op1 return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQADD8(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __UQADD8(uint32_t op1, uint32_t op2) { uint32_t result; @@ -869,7 +1658,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQADD8(uint32_t op return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHADD8(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __UHADD8(uint32_t op1, uint32_t op2) { uint32_t result; @@ -878,7 +1667,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHADD8(uint32_t op } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SSUB8(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __SSUB8(uint32_t op1, uint32_t op2) { uint32_t result; @@ -886,7 +1675,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SSUB8(uint32_t op1 return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QSUB8(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __QSUB8(uint32_t op1, uint32_t op2) { uint32_t result; @@ -894,7 +1683,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QSUB8(uint32_t op1 return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHSUB8(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __SHSUB8(uint32_t op1, uint32_t op2) { uint32_t result; @@ -902,7 +1691,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHSUB8(uint32_t op return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __USUB8(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __USUB8(uint32_t op1, uint32_t op2) { uint32_t result; @@ -910,7 +1699,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __USUB8(uint32_t op1 return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQSUB8(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __UQSUB8(uint32_t op1, uint32_t op2) { uint32_t result; @@ -918,7 +1707,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQSUB8(uint32_t op return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHSUB8(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __UHSUB8(uint32_t op1, uint32_t op2) { uint32_t result; @@ -927,7 +1716,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHSUB8(uint32_t op } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SADD16(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __SADD16(uint32_t op1, uint32_t op2) { uint32_t result; @@ -935,7 +1724,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SADD16(uint32_t op return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QADD16(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __QADD16(uint32_t op1, uint32_t op2) { uint32_t result; @@ -943,7 +1732,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QADD16(uint32_t op return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHADD16(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __SHADD16(uint32_t op1, uint32_t op2) { uint32_t result; @@ -951,7 +1740,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHADD16(uint32_t o return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UADD16(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __UADD16(uint32_t op1, uint32_t op2) { uint32_t result; @@ -959,7 +1748,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UADD16(uint32_t op return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQADD16(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __UQADD16(uint32_t op1, uint32_t op2) { uint32_t result; @@ -967,7 +1756,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQADD16(uint32_t o return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHADD16(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __UHADD16(uint32_t op1, uint32_t op2) { uint32_t result; @@ -975,7 +1764,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHADD16(uint32_t o return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SSUB16(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __SSUB16(uint32_t op1, uint32_t op2) { uint32_t result; @@ -983,7 +1772,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SSUB16(uint32_t op return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QSUB16(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __QSUB16(uint32_t op1, uint32_t op2) { uint32_t result; @@ -991,7 +1780,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QSUB16(uint32_t op return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHSUB16(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __SHSUB16(uint32_t op1, uint32_t op2) { uint32_t result; @@ -999,7 +1788,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHSUB16(uint32_t o return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __USUB16(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __USUB16(uint32_t op1, uint32_t op2) { uint32_t result; @@ -1007,7 +1796,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __USUB16(uint32_t op return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQSUB16(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __UQSUB16(uint32_t op1, uint32_t op2) { uint32_t result; @@ -1015,7 +1804,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQSUB16(uint32_t o return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHSUB16(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __UHSUB16(uint32_t op1, uint32_t op2) { uint32_t result; @@ -1023,7 +1812,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHSUB16(uint32_t o return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SASX(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __SASX(uint32_t op1, uint32_t op2) { uint32_t result; @@ -1031,7 +1820,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SASX(uint32_t op1, return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QASX(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __QASX(uint32_t op1, uint32_t op2) { uint32_t result; @@ -1039,7 +1828,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QASX(uint32_t op1, return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHASX(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __SHASX(uint32_t op1, uint32_t op2) { uint32_t result; @@ -1047,7 +1836,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHASX(uint32_t op1 return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UASX(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __UASX(uint32_t op1, uint32_t op2) { uint32_t result; @@ -1055,7 +1844,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UASX(uint32_t op1, return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQASX(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __UQASX(uint32_t op1, uint32_t op2) { uint32_t result; @@ -1063,7 +1852,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQASX(uint32_t op1 return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHASX(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __UHASX(uint32_t op1, uint32_t op2) { uint32_t result; @@ -1071,7 +1860,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHASX(uint32_t op1 return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SSAX(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __SSAX(uint32_t op1, uint32_t op2) { uint32_t result; @@ -1079,7 +1868,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SSAX(uint32_t op1, return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QSAX(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __QSAX(uint32_t op1, uint32_t op2) { uint32_t result; @@ -1087,7 +1876,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QSAX(uint32_t op1, return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHSAX(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __SHSAX(uint32_t op1, uint32_t op2) { uint32_t result; @@ -1095,7 +1884,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHSAX(uint32_t op1 return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __USAX(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __USAX(uint32_t op1, uint32_t op2) { uint32_t result; @@ -1103,7 +1892,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __USAX(uint32_t op1, return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQSAX(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __UQSAX(uint32_t op1, uint32_t op2) { uint32_t result; @@ -1111,7 +1900,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQSAX(uint32_t op1 return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHSAX(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __UHSAX(uint32_t op1, uint32_t op2) { uint32_t result; @@ -1119,7 +1908,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHSAX(uint32_t op1 return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __USAD8(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __USAD8(uint32_t op1, uint32_t op2) { uint32_t result; @@ -1127,7 +1916,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __USAD8(uint32_t op1 return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __USADA8(uint32_t op1, uint32_t op2, uint32_t op3) +__STATIC_FORCEINLINE uint32_t __USADA8(uint32_t op1, uint32_t op2, uint32_t op3) { uint32_t result; @@ -1149,7 +1938,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __USADA8(uint32_t op __RES; \ }) -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UXTB16(uint32_t op1) +__STATIC_FORCEINLINE uint32_t __UXTB16(uint32_t op1) { uint32_t result; @@ -1157,7 +1946,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UXTB16(uint32_t op return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UXTAB16(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __UXTAB16(uint32_t op1, uint32_t op2) { uint32_t result; @@ -1165,7 +1954,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UXTAB16(uint32_t o return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SXTB16(uint32_t op1) +__STATIC_FORCEINLINE uint32_t __SXTB16(uint32_t op1) { uint32_t result; @@ -1173,7 +1962,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SXTB16(uint32_t op return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SXTAB16(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __SXTAB16(uint32_t op1, uint32_t op2) { uint32_t result; @@ -1181,7 +1970,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SXTAB16(uint32_t o return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMUAD (uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __SMUAD (uint32_t op1, uint32_t op2) { uint32_t result; @@ -1189,7 +1978,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMUAD (uint32_t o return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMUADX (uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __SMUADX (uint32_t op1, uint32_t op2) { uint32_t result; @@ -1197,7 +1986,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMUADX (uint32_t o return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMLAD (uint32_t op1, uint32_t op2, uint32_t op3) +__STATIC_FORCEINLINE uint32_t __SMLAD (uint32_t op1, uint32_t op2, uint32_t op3) { uint32_t result; @@ -1205,7 +1994,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMLAD (uint32_t op return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMLADX (uint32_t op1, uint32_t op2, uint32_t op3) +__STATIC_FORCEINLINE uint32_t __SMLADX (uint32_t op1, uint32_t op2, uint32_t op3) { uint32_t result; @@ -1213,7 +2002,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMLADX (uint32_t o return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint64_t __SMLALD (uint32_t op1, uint32_t op2, uint64_t acc) +__STATIC_FORCEINLINE uint64_t __SMLALD (uint32_t op1, uint32_t op2, uint64_t acc) { union llreg_u{ uint32_t w32[2]; @@ -1230,7 +2019,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint64_t __SMLALD (uint32_t o return(llr.w64); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint64_t __SMLALDX (uint32_t op1, uint32_t op2, uint64_t acc) +__STATIC_FORCEINLINE uint64_t __SMLALDX (uint32_t op1, uint32_t op2, uint64_t acc) { union llreg_u{ uint32_t w32[2]; @@ -1247,7 +2036,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint64_t __SMLALDX (uint32_t return(llr.w64); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMUSD (uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __SMUSD (uint32_t op1, uint32_t op2) { uint32_t result; @@ -1255,7 +2044,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMUSD (uint32_t o return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMUSDX (uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __SMUSDX (uint32_t op1, uint32_t op2) { uint32_t result; @@ -1263,7 +2052,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMUSDX (uint32_t o return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMLSD (uint32_t op1, uint32_t op2, uint32_t op3) +__STATIC_FORCEINLINE uint32_t __SMLSD (uint32_t op1, uint32_t op2, uint32_t op3) { uint32_t result; @@ -1271,7 +2060,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMLSD (uint32_t op return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMLSDX (uint32_t op1, uint32_t op2, uint32_t op3) +__STATIC_FORCEINLINE uint32_t __SMLSDX (uint32_t op1, uint32_t op2, uint32_t op3) { uint32_t result; @@ -1279,7 +2068,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMLSDX (uint32_t o return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint64_t __SMLSLD (uint32_t op1, uint32_t op2, uint64_t acc) +__STATIC_FORCEINLINE uint64_t __SMLSLD (uint32_t op1, uint32_t op2, uint64_t acc) { union llreg_u{ uint32_t w32[2]; @@ -1296,7 +2085,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint64_t __SMLSLD (uint32_t o return(llr.w64); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint64_t __SMLSLDX (uint32_t op1, uint32_t op2, uint64_t acc) +__STATIC_FORCEINLINE uint64_t __SMLSLDX (uint32_t op1, uint32_t op2, uint64_t acc) { union llreg_u{ uint32_t w32[2]; @@ -1313,7 +2102,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint64_t __SMLSLDX (uint32_t return(llr.w64); } -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SEL (uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __SEL (uint32_t op1, uint32_t op2) { uint32_t result; @@ -1321,7 +2110,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SEL (uint32_t op1 return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE int32_t __QADD( int32_t op1, int32_t op2) +__STATIC_FORCEINLINE int32_t __QADD( int32_t op1, int32_t op2) { int32_t result; @@ -1329,7 +2118,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE int32_t __QADD( int32_t op1, return(result); } -__attribute__( ( always_inline ) ) __STATIC_INLINE int32_t __QSUB( int32_t op1, int32_t op2) +__STATIC_FORCEINLINE int32_t __QSUB( int32_t op1, int32_t op2) { int32_t result; @@ -1337,6 +2126,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE int32_t __QSUB( int32_t op1, return(result); } +#if 0 #define __PKHBT(ARG1,ARG2,ARG3) \ ({ \ uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \ @@ -1353,8 +2143,15 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE int32_t __QSUB( int32_t op1, __ASM ("pkhtb %0, %1, %2, asr %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \ __RES; \ }) +#endif + +#define __PKHBT(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0x0000FFFFUL) | \ + ((((uint32_t)(ARG2)) << (ARG3)) & 0xFFFF0000UL) ) -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMMLA (int32_t op1, int32_t op2, int32_t op3) +#define __PKHTB(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0xFFFF0000UL) | \ + ((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL) ) + +__STATIC_FORCEINLINE int32_t __SMMLA (int32_t op1, int32_t op2, int32_t op3) { int32_t result; @@ -1362,12 +2159,11 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMMLA (int32_t op1 return(result); } -#endif /* (__CORTEX_M >= 0x04) */ +#endif /* (__ARM_FEATURE_DSP == 1) */ /*@} end of group CMSIS_SIMD_intrinsics */ -#if defined ( __GNUC__ ) #pragma GCC diagnostic pop -#endif #endif /* __CMSIS_GCC_H */ + diff --git a/panda/board/inc/cmsis_version.h b/panda/board/inc/cmsis_version.h new file mode 100644 index 00000000000000..bf57cf3e805348 --- /dev/null +++ b/panda/board/inc/cmsis_version.h @@ -0,0 +1,40 @@ +/**************************************************************************//** + * @file cmsis_version.h + * @brief CMSIS Core(M) Version definitions + * @version V5.0.3 + * @date 24. June 2019 + ******************************************************************************/ +/* + * Copyright (c) 2009-2019 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#if defined ( __ICCARM__ ) + #pragma system_include /* treat file as system include file for MISRA check */ +#elif defined (__clang__) + #pragma clang system_header /* treat file as system include file */ +#endif + +#ifndef __CMSIS_VERSION_H +#define __CMSIS_VERSION_H + +/* CMSIS Version definitions */ +#define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */ +#define __CM_CMSIS_VERSION_SUB ( 3U) /*!< [15:0] CMSIS Core(M) sub version */ +#define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \ + __CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */ +#endif + diff --git a/panda/board/inc/core_cm3.h b/panda/board/inc/core_cm3.h index b4ac4c7b05a799..0918c5eb4c827b 100644 --- a/panda/board/inc/core_cm3.h +++ b/panda/board/inc/core_cm3.h @@ -1,40 +1,30 @@ /**************************************************************************//** * @file core_cm3.h * @brief CMSIS Cortex-M3 Core Peripheral Access Layer Header File - * @version V4.30 - * @date 20. October 2015 + * @version V5.1.0 + * @date 13. March 2019 ******************************************************************************/ -/* Copyright (c) 2009 - 2015 ARM LIMITED - - All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of ARM nor the names of its contributors may be used - to endorse or promote products derived from this software without - specific prior written permission. - * - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - ---------------------------------------------------------------------------*/ - +/* + * Copyright (c) 2009-2019 Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #if defined ( __ICCARM__ ) - #pragma system_include /* treat file as system include file for MISRA check */ -#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) + #pragma system_include /* treat file as system include file for MISRA check */ +#elif defined (__clang__) #pragma clang system_header /* treat file as system include file */ #endif @@ -70,53 +60,15 @@ @{ */ +#include "cmsis_version.h" + /* CMSIS CM3 definitions */ -#define __CM3_CMSIS_VERSION_MAIN (0x04U) /*!< [31:16] CMSIS HAL main version */ -#define __CM3_CMSIS_VERSION_SUB (0x1EU) /*!< [15:0] CMSIS HAL sub version */ +#define __CM3_CMSIS_VERSION_MAIN (__CM_CMSIS_VERSION_MAIN) /*!< \deprecated [31:16] CMSIS HAL main version */ +#define __CM3_CMSIS_VERSION_SUB (__CM_CMSIS_VERSION_SUB) /*!< \deprecated [15:0] CMSIS HAL sub version */ #define __CM3_CMSIS_VERSION ((__CM3_CMSIS_VERSION_MAIN << 16U) | \ - __CM3_CMSIS_VERSION_SUB ) /*!< CMSIS HAL version number */ - -#define __CORTEX_M (0x03U) /*!< Cortex-M Core */ - - -#if defined ( __CC_ARM ) - #define __ASM __asm /*!< asm keyword for ARM Compiler */ - #define __INLINE __inline /*!< inline keyword for ARM Compiler */ - #define __STATIC_INLINE static __inline - -#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) - #define __ASM __asm /*!< asm keyword for ARM Compiler */ - #define __INLINE __inline /*!< inline keyword for ARM Compiler */ - #define __STATIC_INLINE static __inline - -#elif defined ( __GNUC__ ) - #define __ASM __asm /*!< asm keyword for GNU Compiler */ - #define __INLINE inline /*!< inline keyword for GNU Compiler */ - #define __STATIC_INLINE static inline - -#elif defined ( __ICCARM__ ) - #define __ASM __asm /*!< asm keyword for IAR Compiler */ - #define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */ - #define __STATIC_INLINE static inline - -#elif defined ( __TMS470__ ) - #define __ASM __asm /*!< asm keyword for TI CCS Compiler */ - #define __STATIC_INLINE static inline - -#elif defined ( __TASKING__ ) - #define __ASM __asm /*!< asm keyword for TASKING Compiler */ - #define __INLINE inline /*!< inline keyword for TASKING Compiler */ - #define __STATIC_INLINE static inline - -#elif defined ( __CSMC__ ) - #define __packed - #define __ASM _asm /*!< asm keyword for COSMIC Compiler */ - #define __INLINE inline /*!< inline keyword for COSMIC Compiler. Use -pc99 on compile line */ - #define __STATIC_INLINE static inline + __CM3_CMSIS_VERSION_SUB ) /*!< \deprecated CMSIS HAL version number */ -#else - #error Unknown compiler -#endif +#define __CORTEX_M (3U) /*!< Cortex-M Core */ /** __FPU_USED indicates whether an FPU is used or not. This core does not support an FPU at all @@ -128,8 +80,8 @@ #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" #endif -#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) - #if defined __ARM_PCS_VFP +#elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) + #if defined __ARM_FP #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" #endif @@ -143,7 +95,7 @@ #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" #endif -#elif defined ( __TMS470__ ) +#elif defined ( __TI_ARM__ ) #if defined __TI_VFP_SUPPORT__ #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" #endif @@ -160,8 +112,8 @@ #endif -#include "core_cmInstr.h" /* Core Instruction Access */ -#include "core_cmFunc.h" /* Core Function Access */ +#include "cmsis_compiler.h" /* CMSIS compiler specific defines */ + #ifdef __cplusplus } @@ -191,7 +143,7 @@ #endif #ifndef __NVIC_PRIO_BITS - #define __NVIC_PRIO_BITS 4U + #define __NVIC_PRIO_BITS 3U #warning "__NVIC_PRIO_BITS not defined in device header file; using default!" #endif @@ -308,9 +260,11 @@ typedef union struct { uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */ - uint32_t _reserved0:15; /*!< bit: 9..23 Reserved */ - uint32_t T:1; /*!< bit: 24 Thumb bit (read 0) */ - uint32_t IT:2; /*!< bit: 25..26 saved IT state (read 0) */ + uint32_t _reserved0:1; /*!< bit: 9 Reserved */ + uint32_t ICI_IT_1:6; /*!< bit: 10..15 ICI/IT part 1 */ + uint32_t _reserved1:8; /*!< bit: 16..23 Reserved */ + uint32_t T:1; /*!< bit: 24 Thumb bit */ + uint32_t ICI_IT_2:2; /*!< bit: 25..26 ICI/IT part 2 */ uint32_t Q:1; /*!< bit: 27 Saturation condition flag */ uint32_t V:1; /*!< bit: 28 Overflow condition code flag */ uint32_t C:1; /*!< bit: 29 Carry condition code flag */ @@ -336,12 +290,15 @@ typedef union #define xPSR_Q_Pos 27U /*!< xPSR: Q Position */ #define xPSR_Q_Msk (1UL << xPSR_Q_Pos) /*!< xPSR: Q Mask */ -#define xPSR_IT_Pos 25U /*!< xPSR: IT Position */ -#define xPSR_IT_Msk (3UL << xPSR_IT_Pos) /*!< xPSR: IT Mask */ +#define xPSR_ICI_IT_2_Pos 25U /*!< xPSR: ICI/IT part 2 Position */ +#define xPSR_ICI_IT_2_Msk (3UL << xPSR_ICI_IT_2_Pos) /*!< xPSR: ICI/IT part 2 Mask */ #define xPSR_T_Pos 24U /*!< xPSR: T Position */ #define xPSR_T_Msk (1UL << xPSR_T_Pos) /*!< xPSR: T Mask */ +#define xPSR_ICI_IT_1_Pos 10U /*!< xPSR: ICI/IT part 1 Position */ +#define xPSR_ICI_IT_1_Msk (0x3FUL << xPSR_ICI_IT_1_Pos) /*!< xPSR: ICI/IT part 1 Mask */ + #define xPSR_ISR_Pos 0U /*!< xPSR: ISR Position */ #define xPSR_ISR_Msk (0x1FFUL /*<< xPSR_ISR_Pos*/) /*!< xPSR: ISR Mask */ @@ -385,7 +342,7 @@ typedef struct __IOM uint32_t ISER[8U]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */ uint32_t RESERVED0[24U]; __IOM uint32_t ICER[8U]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */ - uint32_t RSERVED1[24U]; + uint32_t RESERVED1[24U]; __IOM uint32_t ISPR[8U]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */ uint32_t RESERVED2[24U]; __IOM uint32_t ICPR[8U]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */ @@ -487,7 +444,7 @@ typedef struct #define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL /*<< SCB_ICSR_VECTACTIVE_Pos*/) /*!< SCB ICSR: VECTACTIVE Mask */ /* SCB Vector Table Offset Register Definitions */ -#if (__CM3_REV < 0x0201U) /* core r2p1 */ +#if defined (__CM3_REV) && (__CM3_REV < 0x0201U) /* core r2p1 */ #define SCB_VTOR_TBLBASE_Pos 29U /*!< SCB VTOR: TBLBASE Position */ #define SCB_VTOR_TBLBASE_Msk (1UL << SCB_VTOR_TBLBASE_Pos) /*!< SCB VTOR: TBLBASE Mask */ @@ -602,6 +559,60 @@ typedef struct #define SCB_CFSR_MEMFAULTSR_Pos 0U /*!< SCB CFSR: Memory Manage Fault Status Register Position */ #define SCB_CFSR_MEMFAULTSR_Msk (0xFFUL /*<< SCB_CFSR_MEMFAULTSR_Pos*/) /*!< SCB CFSR: Memory Manage Fault Status Register Mask */ +/* MemManage Fault Status Register (part of SCB Configurable Fault Status Register) */ +#define SCB_CFSR_MMARVALID_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 7U) /*!< SCB CFSR (MMFSR): MMARVALID Position */ +#define SCB_CFSR_MMARVALID_Msk (1UL << SCB_CFSR_MMARVALID_Pos) /*!< SCB CFSR (MMFSR): MMARVALID Mask */ + +#define SCB_CFSR_MSTKERR_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 4U) /*!< SCB CFSR (MMFSR): MSTKERR Position */ +#define SCB_CFSR_MSTKERR_Msk (1UL << SCB_CFSR_MSTKERR_Pos) /*!< SCB CFSR (MMFSR): MSTKERR Mask */ + +#define SCB_CFSR_MUNSTKERR_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 3U) /*!< SCB CFSR (MMFSR): MUNSTKERR Position */ +#define SCB_CFSR_MUNSTKERR_Msk (1UL << SCB_CFSR_MUNSTKERR_Pos) /*!< SCB CFSR (MMFSR): MUNSTKERR Mask */ + +#define SCB_CFSR_DACCVIOL_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 1U) /*!< SCB CFSR (MMFSR): DACCVIOL Position */ +#define SCB_CFSR_DACCVIOL_Msk (1UL << SCB_CFSR_DACCVIOL_Pos) /*!< SCB CFSR (MMFSR): DACCVIOL Mask */ + +#define SCB_CFSR_IACCVIOL_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 0U) /*!< SCB CFSR (MMFSR): IACCVIOL Position */ +#define SCB_CFSR_IACCVIOL_Msk (1UL /*<< SCB_CFSR_IACCVIOL_Pos*/) /*!< SCB CFSR (MMFSR): IACCVIOL Mask */ + +/* BusFault Status Register (part of SCB Configurable Fault Status Register) */ +#define SCB_CFSR_BFARVALID_Pos (SCB_CFSR_BUSFAULTSR_Pos + 7U) /*!< SCB CFSR (BFSR): BFARVALID Position */ +#define SCB_CFSR_BFARVALID_Msk (1UL << SCB_CFSR_BFARVALID_Pos) /*!< SCB CFSR (BFSR): BFARVALID Mask */ + +#define SCB_CFSR_STKERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 4U) /*!< SCB CFSR (BFSR): STKERR Position */ +#define SCB_CFSR_STKERR_Msk (1UL << SCB_CFSR_STKERR_Pos) /*!< SCB CFSR (BFSR): STKERR Mask */ + +#define SCB_CFSR_UNSTKERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 3U) /*!< SCB CFSR (BFSR): UNSTKERR Position */ +#define SCB_CFSR_UNSTKERR_Msk (1UL << SCB_CFSR_UNSTKERR_Pos) /*!< SCB CFSR (BFSR): UNSTKERR Mask */ + +#define SCB_CFSR_IMPRECISERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 2U) /*!< SCB CFSR (BFSR): IMPRECISERR Position */ +#define SCB_CFSR_IMPRECISERR_Msk (1UL << SCB_CFSR_IMPRECISERR_Pos) /*!< SCB CFSR (BFSR): IMPRECISERR Mask */ + +#define SCB_CFSR_PRECISERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 1U) /*!< SCB CFSR (BFSR): PRECISERR Position */ +#define SCB_CFSR_PRECISERR_Msk (1UL << SCB_CFSR_PRECISERR_Pos) /*!< SCB CFSR (BFSR): PRECISERR Mask */ + +#define SCB_CFSR_IBUSERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 0U) /*!< SCB CFSR (BFSR): IBUSERR Position */ +#define SCB_CFSR_IBUSERR_Msk (1UL << SCB_CFSR_IBUSERR_Pos) /*!< SCB CFSR (BFSR): IBUSERR Mask */ + +/* UsageFault Status Register (part of SCB Configurable Fault Status Register) */ +#define SCB_CFSR_DIVBYZERO_Pos (SCB_CFSR_USGFAULTSR_Pos + 9U) /*!< SCB CFSR (UFSR): DIVBYZERO Position */ +#define SCB_CFSR_DIVBYZERO_Msk (1UL << SCB_CFSR_DIVBYZERO_Pos) /*!< SCB CFSR (UFSR): DIVBYZERO Mask */ + +#define SCB_CFSR_UNALIGNED_Pos (SCB_CFSR_USGFAULTSR_Pos + 8U) /*!< SCB CFSR (UFSR): UNALIGNED Position */ +#define SCB_CFSR_UNALIGNED_Msk (1UL << SCB_CFSR_UNALIGNED_Pos) /*!< SCB CFSR (UFSR): UNALIGNED Mask */ + +#define SCB_CFSR_NOCP_Pos (SCB_CFSR_USGFAULTSR_Pos + 3U) /*!< SCB CFSR (UFSR): NOCP Position */ +#define SCB_CFSR_NOCP_Msk (1UL << SCB_CFSR_NOCP_Pos) /*!< SCB CFSR (UFSR): NOCP Mask */ + +#define SCB_CFSR_INVPC_Pos (SCB_CFSR_USGFAULTSR_Pos + 2U) /*!< SCB CFSR (UFSR): INVPC Position */ +#define SCB_CFSR_INVPC_Msk (1UL << SCB_CFSR_INVPC_Pos) /*!< SCB CFSR (UFSR): INVPC Mask */ + +#define SCB_CFSR_INVSTATE_Pos (SCB_CFSR_USGFAULTSR_Pos + 1U) /*!< SCB CFSR (UFSR): INVSTATE Position */ +#define SCB_CFSR_INVSTATE_Msk (1UL << SCB_CFSR_INVSTATE_Pos) /*!< SCB CFSR (UFSR): INVSTATE Mask */ + +#define SCB_CFSR_UNDEFINSTR_Pos (SCB_CFSR_USGFAULTSR_Pos + 0U) /*!< SCB CFSR (UFSR): UNDEFINSTR Position */ +#define SCB_CFSR_UNDEFINSTR_Msk (1UL << SCB_CFSR_UNDEFINSTR_Pos) /*!< SCB CFSR (UFSR): UNDEFINSTR Mask */ + /* SCB Hard Fault Status Register Definitions */ #define SCB_HFSR_DEBUGEVT_Pos 31U /*!< SCB HFSR: DEBUGEVT Position */ #define SCB_HFSR_DEBUGEVT_Msk (1UL << SCB_HFSR_DEBUGEVT_Pos) /*!< SCB HFSR: DEBUGEVT Mask */ @@ -645,7 +656,7 @@ typedef struct { uint32_t RESERVED0[1U]; __IM uint32_t ICTR; /*!< Offset: 0x004 (R/ ) Interrupt Controller Type Register */ -#if ((defined __CM3_REV) && (__CM3_REV >= 0x200U)) +#if defined (__CM3_REV) && (__CM3_REV >= 0x200U) __IOM uint32_t ACTLR; /*!< Offset: 0x008 (R/W) Auxiliary Control Register */ #else uint32_t RESERVED1[1U]; @@ -657,6 +668,12 @@ typedef struct #define SCnSCB_ICTR_INTLINESNUM_Msk (0xFUL /*<< SCnSCB_ICTR_INTLINESNUM_Pos*/) /*!< ICTR: INTLINESNUM Mask */ /* Auxiliary Control Register Definitions */ +#if defined (__CM3_REV) && (__CM3_REV >= 0x200U) +#define SCnSCB_ACTLR_DISOOFP_Pos 9U /*!< ACTLR: DISOOFP Position */ +#define SCnSCB_ACTLR_DISOOFP_Msk (1UL << SCnSCB_ACTLR_DISOOFP_Pos) /*!< ACTLR: DISOOFP Mask */ + +#define SCnSCB_ACTLR_DISFPCA_Pos 8U /*!< ACTLR: DISFPCA Position */ +#define SCnSCB_ACTLR_DISFPCA_Msk (1UL << SCnSCB_ACTLR_DISFPCA_Pos) /*!< ACTLR: DISFPCA Mask */ #define SCnSCB_ACTLR_DISFOLD_Pos 2U /*!< ACTLR: DISFOLD Position */ #define SCnSCB_ACTLR_DISFOLD_Msk (1UL << SCnSCB_ACTLR_DISFOLD_Pos) /*!< ACTLR: DISFOLD Mask */ @@ -666,6 +683,7 @@ typedef struct #define SCnSCB_ACTLR_DISMCYCINT_Pos 0U /*!< ACTLR: DISMCYCINT Position */ #define SCnSCB_ACTLR_DISMCYCINT_Msk (1UL /*<< SCnSCB_ACTLR_DISMCYCINT_Pos*/) /*!< ACTLR: DISMCYCINT Mask */ +#endif /*@} end of group CMSIS_SCnotSCB */ @@ -746,10 +764,7 @@ typedef struct __IOM uint32_t TPR; /*!< Offset: 0xE40 (R/W) ITM Trace Privilege Register */ uint32_t RESERVED2[15U]; __IOM uint32_t TCR; /*!< Offset: 0xE80 (R/W) ITM Trace Control Register */ - uint32_t RESERVED3[29U]; - __OM uint32_t IWR; /*!< Offset: 0xEF8 ( /W) ITM Integration Write Register */ - __IM uint32_t IRR; /*!< Offset: 0xEFC (R/ ) ITM Integration Read Register */ - __IOM uint32_t IMCR; /*!< Offset: 0xF00 (R/W) ITM Integration Mode Control Register */ + uint32_t RESERVED3[32U]; uint32_t RESERVED4[43U]; __OM uint32_t LAR; /*!< Offset: 0xFB0 ( /W) ITM Lock Access Register */ __IM uint32_t LSR; /*!< Offset: 0xFB4 (R/ ) ITM Lock Status Register */ @@ -770,7 +785,7 @@ typedef struct /* ITM Trace Privilege Register Definitions */ #define ITM_TPR_PRIVMASK_Pos 0U /*!< ITM TPR: PRIVMASK Position */ -#define ITM_TPR_PRIVMASK_Msk (0xFUL /*<< ITM_TPR_PRIVMASK_Pos*/) /*!< ITM TPR: PRIVMASK Mask */ +#define ITM_TPR_PRIVMASK_Msk (0xFFFFFFFFUL /*<< ITM_TPR_PRIVMASK_Pos*/) /*!< ITM TPR: PRIVMASK Mask */ /* ITM Trace Control Register Definitions */ #define ITM_TCR_BUSY_Pos 23U /*!< ITM TCR: BUSY Position */ @@ -800,18 +815,6 @@ typedef struct #define ITM_TCR_ITMENA_Pos 0U /*!< ITM TCR: ITM Enable bit Position */ #define ITM_TCR_ITMENA_Msk (1UL /*<< ITM_TCR_ITMENA_Pos*/) /*!< ITM TCR: ITM Enable bit Mask */ -/* ITM Integration Write Register Definitions */ -#define ITM_IWR_ATVALIDM_Pos 0U /*!< ITM IWR: ATVALIDM Position */ -#define ITM_IWR_ATVALIDM_Msk (1UL /*<< ITM_IWR_ATVALIDM_Pos*/) /*!< ITM IWR: ATVALIDM Mask */ - -/* ITM Integration Read Register Definitions */ -#define ITM_IRR_ATREADYM_Pos 0U /*!< ITM IRR: ATREADYM Position */ -#define ITM_IRR_ATREADYM_Msk (1UL /*<< ITM_IRR_ATREADYM_Pos*/) /*!< ITM IRR: ATREADYM Mask */ - -/* ITM Integration Mode Control Register Definitions */ -#define ITM_IMCR_INTEGRATION_Pos 0U /*!< ITM IMCR: INTEGRATION Position */ -#define ITM_IMCR_INTEGRATION_Msk (1UL /*<< ITM_IMCR_INTEGRATION_Pos*/) /*!< ITM IMCR: INTEGRATION Mask */ - /* ITM Lock Status Register Definitions */ #define ITM_LSR_ByteAcc_Pos 2U /*!< ITM LSR: ByteAcc Position */ #define ITM_LSR_ByteAcc_Msk (1UL << ITM_LSR_ByteAcc_Pos) /*!< ITM LSR: ByteAcc Mask */ @@ -984,7 +987,7 @@ typedef struct */ typedef struct { - __IOM uint32_t SSPSR; /*!< Offset: 0x000 (R/ ) Supported Parallel Port Size Register */ + __IM uint32_t SSPSR; /*!< Offset: 0x000 (R/ ) Supported Parallel Port Size Register */ __IOM uint32_t CSPSR; /*!< Offset: 0x004 (R/W) Current Parallel Port Size Register */ uint32_t RESERVED0[2U]; __IOM uint32_t ACPR; /*!< Offset: 0x010 (R/W) Asynchronous Clock Prescaler Register */ @@ -995,7 +998,7 @@ typedef struct __IOM uint32_t FFCR; /*!< Offset: 0x304 (R/W) Formatter and Flush Control Register */ __IM uint32_t FSCR; /*!< Offset: 0x308 (R/ ) Formatter Synchronization Counter Register */ uint32_t RESERVED3[759U]; - __IM uint32_t TRIGGER; /*!< Offset: 0xEE8 (R/ ) TRIGGER */ + __IM uint32_t TRIGGER; /*!< Offset: 0xEE8 (R/ ) TRIGGER Register */ __IM uint32_t FIFO0; /*!< Offset: 0xEEC (R/ ) Integration ETM Data */ __IM uint32_t ITATBCTR2; /*!< Offset: 0xEF0 (R/ ) ITATBCTR2 */ uint32_t RESERVED4[1U]; @@ -1044,13 +1047,13 @@ typedef struct /* TPI Integration ETM Data Register Definitions (FIFO0) */ #define TPI_FIFO0_ITM_ATVALID_Pos 29U /*!< TPI FIFO0: ITM_ATVALID Position */ -#define TPI_FIFO0_ITM_ATVALID_Msk (0x3UL << TPI_FIFO0_ITM_ATVALID_Pos) /*!< TPI FIFO0: ITM_ATVALID Mask */ +#define TPI_FIFO0_ITM_ATVALID_Msk (0x1UL << TPI_FIFO0_ITM_ATVALID_Pos) /*!< TPI FIFO0: ITM_ATVALID Mask */ #define TPI_FIFO0_ITM_bytecount_Pos 27U /*!< TPI FIFO0: ITM_bytecount Position */ #define TPI_FIFO0_ITM_bytecount_Msk (0x3UL << TPI_FIFO0_ITM_bytecount_Pos) /*!< TPI FIFO0: ITM_bytecount Mask */ #define TPI_FIFO0_ETM_ATVALID_Pos 26U /*!< TPI FIFO0: ETM_ATVALID Position */ -#define TPI_FIFO0_ETM_ATVALID_Msk (0x3UL << TPI_FIFO0_ETM_ATVALID_Pos) /*!< TPI FIFO0: ETM_ATVALID Mask */ +#define TPI_FIFO0_ETM_ATVALID_Msk (0x1UL << TPI_FIFO0_ETM_ATVALID_Pos) /*!< TPI FIFO0: ETM_ATVALID Mask */ #define TPI_FIFO0_ETM_bytecount_Pos 24U /*!< TPI FIFO0: ETM_bytecount Position */ #define TPI_FIFO0_ETM_bytecount_Msk (0x3UL << TPI_FIFO0_ETM_bytecount_Pos) /*!< TPI FIFO0: ETM_bytecount Mask */ @@ -1065,18 +1068,21 @@ typedef struct #define TPI_FIFO0_ETM0_Msk (0xFFUL /*<< TPI_FIFO0_ETM0_Pos*/) /*!< TPI FIFO0: ETM0 Mask */ /* TPI ITATBCTR2 Register Definitions */ -#define TPI_ITATBCTR2_ATREADY_Pos 0U /*!< TPI ITATBCTR2: ATREADY Position */ -#define TPI_ITATBCTR2_ATREADY_Msk (0x1UL /*<< TPI_ITATBCTR2_ATREADY_Pos*/) /*!< TPI ITATBCTR2: ATREADY Mask */ +#define TPI_ITATBCTR2_ATREADY2_Pos 0U /*!< TPI ITATBCTR2: ATREADY2 Position */ +#define TPI_ITATBCTR2_ATREADY2_Msk (0x1UL /*<< TPI_ITATBCTR2_ATREADY2_Pos*/) /*!< TPI ITATBCTR2: ATREADY2 Mask */ + +#define TPI_ITATBCTR2_ATREADY1_Pos 0U /*!< TPI ITATBCTR2: ATREADY1 Position */ +#define TPI_ITATBCTR2_ATREADY1_Msk (0x1UL /*<< TPI_ITATBCTR2_ATREADY1_Pos*/) /*!< TPI ITATBCTR2: ATREADY1 Mask */ /* TPI Integration ITM Data Register Definitions (FIFO1) */ #define TPI_FIFO1_ITM_ATVALID_Pos 29U /*!< TPI FIFO1: ITM_ATVALID Position */ -#define TPI_FIFO1_ITM_ATVALID_Msk (0x3UL << TPI_FIFO1_ITM_ATVALID_Pos) /*!< TPI FIFO1: ITM_ATVALID Mask */ +#define TPI_FIFO1_ITM_ATVALID_Msk (0x1UL << TPI_FIFO1_ITM_ATVALID_Pos) /*!< TPI FIFO1: ITM_ATVALID Mask */ #define TPI_FIFO1_ITM_bytecount_Pos 27U /*!< TPI FIFO1: ITM_bytecount Position */ #define TPI_FIFO1_ITM_bytecount_Msk (0x3UL << TPI_FIFO1_ITM_bytecount_Pos) /*!< TPI FIFO1: ITM_bytecount Mask */ #define TPI_FIFO1_ETM_ATVALID_Pos 26U /*!< TPI FIFO1: ETM_ATVALID Position */ -#define TPI_FIFO1_ETM_ATVALID_Msk (0x3UL << TPI_FIFO1_ETM_ATVALID_Pos) /*!< TPI FIFO1: ETM_ATVALID Mask */ +#define TPI_FIFO1_ETM_ATVALID_Msk (0x1UL << TPI_FIFO1_ETM_ATVALID_Pos) /*!< TPI FIFO1: ETM_ATVALID Mask */ #define TPI_FIFO1_ETM_bytecount_Pos 24U /*!< TPI FIFO1: ETM_bytecount Position */ #define TPI_FIFO1_ETM_bytecount_Msk (0x3UL << TPI_FIFO1_ETM_bytecount_Pos) /*!< TPI FIFO1: ETM_bytecount Mask */ @@ -1091,12 +1097,15 @@ typedef struct #define TPI_FIFO1_ITM0_Msk (0xFFUL /*<< TPI_FIFO1_ITM0_Pos*/) /*!< TPI FIFO1: ITM0 Mask */ /* TPI ITATBCTR0 Register Definitions */ -#define TPI_ITATBCTR0_ATREADY_Pos 0U /*!< TPI ITATBCTR0: ATREADY Position */ -#define TPI_ITATBCTR0_ATREADY_Msk (0x1UL /*<< TPI_ITATBCTR0_ATREADY_Pos*/) /*!< TPI ITATBCTR0: ATREADY Mask */ +#define TPI_ITATBCTR0_ATREADY2_Pos 0U /*!< TPI ITATBCTR0: ATREADY2 Position */ +#define TPI_ITATBCTR0_ATREADY2_Msk (0x1UL /*<< TPI_ITATBCTR0_ATREADY2_Pos*/) /*!< TPI ITATBCTR0: ATREADY2 Mask */ + +#define TPI_ITATBCTR0_ATREADY1_Pos 0U /*!< TPI ITATBCTR0: ATREADY1 Position */ +#define TPI_ITATBCTR0_ATREADY1_Msk (0x1UL /*<< TPI_ITATBCTR0_ATREADY1_Pos*/) /*!< TPI ITATBCTR0: ATREADY1 Mask */ /* TPI Integration Mode Control Register Definitions */ #define TPI_ITCTRL_Mode_Pos 0U /*!< TPI ITCTRL: Mode Position */ -#define TPI_ITCTRL_Mode_Msk (0x1UL /*<< TPI_ITCTRL_Mode_Pos*/) /*!< TPI ITCTRL: Mode Mask */ +#define TPI_ITCTRL_Mode_Msk (0x3UL /*<< TPI_ITCTRL_Mode_Pos*/) /*!< TPI ITCTRL: Mode Mask */ /* TPI DEVID Register Definitions */ #define TPI_DEVID_NRZVALID_Pos 11U /*!< TPI DEVID: NRZVALID Position */ @@ -1118,16 +1127,16 @@ typedef struct #define TPI_DEVID_NrTraceInput_Msk (0x1FUL /*<< TPI_DEVID_NrTraceInput_Pos*/) /*!< TPI DEVID: NrTraceInput Mask */ /* TPI DEVTYPE Register Definitions */ -#define TPI_DEVTYPE_MajorType_Pos 4U /*!< TPI DEVTYPE: MajorType Position */ -#define TPI_DEVTYPE_MajorType_Msk (0xFUL << TPI_DEVTYPE_MajorType_Pos) /*!< TPI DEVTYPE: MajorType Mask */ - -#define TPI_DEVTYPE_SubType_Pos 0U /*!< TPI DEVTYPE: SubType Position */ +#define TPI_DEVTYPE_SubType_Pos 4U /*!< TPI DEVTYPE: SubType Position */ #define TPI_DEVTYPE_SubType_Msk (0xFUL /*<< TPI_DEVTYPE_SubType_Pos*/) /*!< TPI DEVTYPE: SubType Mask */ +#define TPI_DEVTYPE_MajorType_Pos 0U /*!< TPI DEVTYPE: MajorType Position */ +#define TPI_DEVTYPE_MajorType_Msk (0xFUL << TPI_DEVTYPE_MajorType_Pos) /*!< TPI DEVTYPE: MajorType Mask */ + /*@}*/ /* end of group CMSIS_TPI */ -#if (__MPU_PRESENT == 1U) +#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) /** \ingroup CMSIS_core_register \defgroup CMSIS_MPU Memory Protection Unit (MPU) @@ -1153,6 +1162,8 @@ typedef struct __IOM uint32_t RASR_A3; /*!< Offset: 0x028 (R/W) MPU Alias 3 Region Attribute and Size Register */ } MPU_Type; +#define MPU_TYPE_RALIASES 4U + /* MPU Type Register Definitions */ #define MPU_TYPE_IREGION_Pos 16U /*!< MPU TYPE: IREGION Position */ #define MPU_TYPE_IREGION_Msk (0xFFUL << MPU_TYPE_IREGION_Pos) /*!< MPU TYPE: IREGION Mask */ @@ -1337,18 +1348,18 @@ typedef struct /** \brief Mask and shift a bit field value for use in a register bit range. \param[in] field Name of the register bit field. - \param[in] value Value of the bit field. + \param[in] value Value of the bit field. This parameter is interpreted as an uint32_t type. \return Masked and shifted value. */ -#define _VAL2FLD(field, value) ((value << field ## _Pos) & field ## _Msk) +#define _VAL2FLD(field, value) (((uint32_t)(value) << field ## _Pos) & field ## _Msk) /** \brief Mask and shift a register value to extract a bit filed value. \param[in] field Name of the register bit field. - \param[in] value Value of register. + \param[in] value Value of register. This parameter is interpreted as an uint32_t type. \return Masked and shifted bit field value. */ -#define _FLD2VAL(field, value) ((value & field ## _Msk) >> field ## _Pos) +#define _FLD2VAL(field, value) (((uint32_t)(value) & field ## _Msk) >> field ## _Pos) /*@} end of group CMSIS_core_bitfield */ @@ -1360,7 +1371,7 @@ typedef struct @{ */ -/* Memory mapping of Cortex-M3 Hardware */ +/* Memory mapping of Core Hardware */ #define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */ #define ITM_BASE (0xE0000000UL) /*!< ITM Base Address */ #define DWT_BASE (0xE0001000UL) /*!< DWT Base Address */ @@ -1379,7 +1390,7 @@ typedef struct #define TPI ((TPI_Type *) TPI_BASE ) /*!< TPI configuration struct */ #define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE) /*!< Core Debug configuration struct */ -#if (__MPU_PRESENT == 1U) +#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) #define MPU_BASE (SCS_BASE + 0x0D90UL) /*!< Memory Protection Unit */ #define MPU ((MPU_Type *) MPU_BASE ) /*!< Memory Protection Unit */ #endif @@ -1410,6 +1421,45 @@ typedef struct @{ */ +#ifdef CMSIS_NVIC_VIRTUAL + #ifndef CMSIS_NVIC_VIRTUAL_HEADER_FILE + #define CMSIS_NVIC_VIRTUAL_HEADER_FILE "cmsis_nvic_virtual.h" + #endif + #include CMSIS_NVIC_VIRTUAL_HEADER_FILE +#else + #define NVIC_SetPriorityGrouping __NVIC_SetPriorityGrouping + #define NVIC_GetPriorityGrouping __NVIC_GetPriorityGrouping + #define NVIC_EnableIRQ __NVIC_EnableIRQ + #define NVIC_GetEnableIRQ __NVIC_GetEnableIRQ + #define NVIC_DisableIRQ __NVIC_DisableIRQ + #define NVIC_GetPendingIRQ __NVIC_GetPendingIRQ + #define NVIC_SetPendingIRQ __NVIC_SetPendingIRQ + #define NVIC_ClearPendingIRQ __NVIC_ClearPendingIRQ + #define NVIC_GetActive __NVIC_GetActive + #define NVIC_SetPriority __NVIC_SetPriority + #define NVIC_GetPriority __NVIC_GetPriority + #define NVIC_SystemReset __NVIC_SystemReset +#endif /* CMSIS_NVIC_VIRTUAL */ + +#ifdef CMSIS_VECTAB_VIRTUAL + #ifndef CMSIS_VECTAB_VIRTUAL_HEADER_FILE + #define CMSIS_VECTAB_VIRTUAL_HEADER_FILE "cmsis_vectab_virtual.h" + #endif + #include CMSIS_VECTAB_VIRTUAL_HEADER_FILE +#else + #define NVIC_SetVector __NVIC_SetVector + #define NVIC_GetVector __NVIC_GetVector +#endif /* (CMSIS_VECTAB_VIRTUAL) */ + +#define NVIC_USER_IRQ_OFFSET 16 + + +/* The following EXC_RETURN values are saved the LR on exception entry */ +#define EXC_RETURN_HANDLER (0xFFFFFFF1UL) /* return to Handler mode, uses MSP after return */ +#define EXC_RETURN_THREAD_MSP (0xFFFFFFF9UL) /* return to Thread mode, uses MSP after return */ +#define EXC_RETURN_THREAD_PSP (0xFFFFFFFDUL) /* return to Thread mode, uses PSP after return */ + + /** \brief Set Priority Grouping \details Sets the priority grouping field using the required unlock sequence. @@ -1419,7 +1469,7 @@ typedef struct priority bits (__NVIC_PRIO_BITS), the smallest possible priority group is set. \param [in] PriorityGroup Priority grouping field. */ -__STATIC_INLINE void NVIC_SetPriorityGrouping(uint32_t PriorityGroup) +__STATIC_INLINE void __NVIC_SetPriorityGrouping(uint32_t PriorityGroup) { uint32_t reg_value; uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */ @@ -1428,7 +1478,7 @@ __STATIC_INLINE void NVIC_SetPriorityGrouping(uint32_t PriorityGroup) reg_value &= ~((uint32_t)(SCB_AIRCR_VECTKEY_Msk | SCB_AIRCR_PRIGROUP_Msk)); /* clear bits to change */ reg_value = (reg_value | ((uint32_t)0x5FAUL << SCB_AIRCR_VECTKEY_Pos) | - (PriorityGroupTmp << 8U) ); /* Insert write key and priorty group */ + (PriorityGroupTmp << SCB_AIRCR_PRIGROUP_Pos) ); /* Insert write key and priority group */ SCB->AIRCR = reg_value; } @@ -1438,121 +1488,180 @@ __STATIC_INLINE void NVIC_SetPriorityGrouping(uint32_t PriorityGroup) \details Reads the priority grouping field from the NVIC Interrupt Controller. \return Priority grouping field (SCB->AIRCR [10:8] PRIGROUP field). */ -__STATIC_INLINE uint32_t NVIC_GetPriorityGrouping(void) +__STATIC_INLINE uint32_t __NVIC_GetPriorityGrouping(void) { return ((uint32_t)((SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) >> SCB_AIRCR_PRIGROUP_Pos)); } /** - \brief Enable External Interrupt - \details Enables a device-specific interrupt in the NVIC interrupt controller. - \param [in] IRQn External interrupt number. Value cannot be negative. + \brief Enable Interrupt + \details Enables a device specific interrupt in the NVIC interrupt controller. + \param [in] IRQn Device specific interrupt number. + \note IRQn must not be negative. + */ +__STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + __COMPILER_BARRIER(); + NVIC->ISER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + __COMPILER_BARRIER(); + } +} + + +/** + \brief Get Interrupt Enable status + \details Returns a device specific interrupt enable status from the NVIC interrupt controller. + \param [in] IRQn Device specific interrupt number. + \return 0 Interrupt is not enabled. + \return 1 Interrupt is enabled. + \note IRQn must not be negative. */ -__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn) +__STATIC_INLINE uint32_t __NVIC_GetEnableIRQ(IRQn_Type IRQn) { - NVIC->ISER[(((uint32_t)(int32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL)); + if ((int32_t)(IRQn) >= 0) + { + return((uint32_t)(((NVIC->ISER[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + } + else + { + return(0U); + } } /** - \brief Disable External Interrupt - \details Disables a device-specific interrupt in the NVIC interrupt controller. - \param [in] IRQn External interrupt number. Value cannot be negative. + \brief Disable Interrupt + \details Disables a device specific interrupt in the NVIC interrupt controller. + \param [in] IRQn Device specific interrupt number. + \note IRQn must not be negative. */ -__STATIC_INLINE void NVIC_DisableIRQ(IRQn_Type IRQn) +__STATIC_INLINE void __NVIC_DisableIRQ(IRQn_Type IRQn) { - NVIC->ICER[(((uint32_t)(int32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL)); + if ((int32_t)(IRQn) >= 0) + { + NVIC->ICER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + __DSB(); + __ISB(); + } } /** \brief Get Pending Interrupt - \details Reads the pending register in the NVIC and returns the pending bit for the specified interrupt. - \param [in] IRQn Interrupt number. + \details Reads the NVIC pending register and returns the pending bit for the specified device specific interrupt. + \param [in] IRQn Device specific interrupt number. \return 0 Interrupt status is not pending. \return 1 Interrupt status is pending. + \note IRQn must not be negative. */ -__STATIC_INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn) +__STATIC_INLINE uint32_t __NVIC_GetPendingIRQ(IRQn_Type IRQn) { - return((uint32_t)(((NVIC->ISPR[(((uint32_t)(int32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + if ((int32_t)(IRQn) >= 0) + { + return((uint32_t)(((NVIC->ISPR[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + } + else + { + return(0U); + } } /** \brief Set Pending Interrupt - \details Sets the pending bit of an external interrupt. - \param [in] IRQn Interrupt number. Value cannot be negative. + \details Sets the pending bit of a device specific interrupt in the NVIC pending register. + \param [in] IRQn Device specific interrupt number. + \note IRQn must not be negative. */ -__STATIC_INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn) +__STATIC_INLINE void __NVIC_SetPendingIRQ(IRQn_Type IRQn) { - NVIC->ISPR[(((uint32_t)(int32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL)); + if ((int32_t)(IRQn) >= 0) + { + NVIC->ISPR[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + } } /** \brief Clear Pending Interrupt - \details Clears the pending bit of an external interrupt. - \param [in] IRQn External interrupt number. Value cannot be negative. + \details Clears the pending bit of a device specific interrupt in the NVIC pending register. + \param [in] IRQn Device specific interrupt number. + \note IRQn must not be negative. */ -__STATIC_INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn) +__STATIC_INLINE void __NVIC_ClearPendingIRQ(IRQn_Type IRQn) { - NVIC->ICPR[(((uint32_t)(int32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL)); + if ((int32_t)(IRQn) >= 0) + { + NVIC->ICPR[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + } } /** \brief Get Active Interrupt - \details Reads the active register in NVIC and returns the active bit. - \param [in] IRQn Interrupt number. + \details Reads the active register in the NVIC and returns the active bit for the device specific interrupt. + \param [in] IRQn Device specific interrupt number. \return 0 Interrupt status is not active. \return 1 Interrupt status is active. + \note IRQn must not be negative. */ -__STATIC_INLINE uint32_t NVIC_GetActive(IRQn_Type IRQn) +__STATIC_INLINE uint32_t __NVIC_GetActive(IRQn_Type IRQn) { - return((uint32_t)(((NVIC->IABR[(((uint32_t)(int32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + if ((int32_t)(IRQn) >= 0) + { + return((uint32_t)(((NVIC->IABR[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + } + else + { + return(0U); + } } /** \brief Set Interrupt Priority - \details Sets the priority of an interrupt. - \note The priority cannot be set for every core interrupt. + \details Sets the priority of a device specific interrupt or a processor exception. + The interrupt number can be positive to specify a device specific interrupt, + or negative to specify a processor exception. \param [in] IRQn Interrupt number. \param [in] priority Priority to set. + \note The priority cannot be set for every processor exception. */ -__STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority) +__STATIC_INLINE void __NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority) { - if ((int32_t)(IRQn) < 0) + if ((int32_t)(IRQn) >= 0) { - SCB->SHP[(((uint32_t)(int32_t)IRQn) & 0xFUL)-4UL] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL); + NVIC->IP[((uint32_t)IRQn)] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL); } else { - NVIC->IP[((uint32_t)(int32_t)IRQn)] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL); + SCB->SHP[(((uint32_t)IRQn) & 0xFUL)-4UL] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL); } } /** \brief Get Interrupt Priority - \details Reads the priority of an interrupt. - The interrupt number can be positive to specify an external (device specific) interrupt, - or negative to specify an internal (core) interrupt. + \details Reads the priority of a device specific interrupt or a processor exception. + The interrupt number can be positive to specify a device specific interrupt, + or negative to specify a processor exception. \param [in] IRQn Interrupt number. \return Interrupt Priority. Value is aligned automatically to the implemented priority bits of the microcontroller. */ -__STATIC_INLINE uint32_t NVIC_GetPriority(IRQn_Type IRQn) +__STATIC_INLINE uint32_t __NVIC_GetPriority(IRQn_Type IRQn) { - if ((int32_t)(IRQn) < 0) + if ((int32_t)(IRQn) >= 0) { - return(((uint32_t)SCB->SHP[(((uint32_t)(int32_t)IRQn) & 0xFUL)-4UL] >> (8U - __NVIC_PRIO_BITS))); + return(((uint32_t)NVIC->IP[((uint32_t)IRQn)] >> (8U - __NVIC_PRIO_BITS))); } else { - return(((uint32_t)NVIC->IP[((uint32_t)(int32_t)IRQn)] >> (8U - __NVIC_PRIO_BITS))); + return(((uint32_t)SCB->SHP[(((uint32_t)IRQn) & 0xFUL)-4UL] >> (8U - __NVIC_PRIO_BITS))); } } @@ -1609,11 +1718,43 @@ __STATIC_INLINE void NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGr } +/** + \brief Set Interrupt Vector + \details Sets an interrupt vector in SRAM based interrupt vector table. + The interrupt number can be positive to specify a device specific interrupt, + or negative to specify a processor exception. + VTOR must been relocated to SRAM before. + \param [in] IRQn Interrupt number + \param [in] vector Address of interrupt handler function + */ +__STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) +{ + uint32_t vectors = (uint32_t )SCB->VTOR; + (* (int *) (vectors + ((int32_t)IRQn + NVIC_USER_IRQ_OFFSET) * 4)) = vector; + /* ARM Application Note 321 states that the M3 does not require the architectural barrier */ +} + + +/** + \brief Get Interrupt Vector + \details Reads an interrupt vector from interrupt vector table. + The interrupt number can be positive to specify a device specific interrupt, + or negative to specify a processor exception. + \param [in] IRQn Interrupt number. + \return Address of interrupt handler function + */ +__STATIC_INLINE uint32_t __NVIC_GetVector(IRQn_Type IRQn) +{ + uint32_t vectors = (uint32_t )SCB->VTOR; + return (uint32_t)(* (int *) (vectors + ((int32_t)IRQn + NVIC_USER_IRQ_OFFSET) * 4)); +} + + /** \brief System Reset \details Initiates a system reset request to reset the MCU. */ -__STATIC_INLINE void NVIC_SystemReset(void) +__NO_RETURN __STATIC_INLINE void __NVIC_SystemReset(void) { __DSB(); /* Ensure all outstanding memory accesses included buffered write are completed before reset */ @@ -1630,6 +1771,39 @@ __STATIC_INLINE void NVIC_SystemReset(void) /*@} end of CMSIS_Core_NVICFunctions */ +/* ########################## MPU functions #################################### */ + +#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) + +#include "mpu_armv7.h" + +#endif + + +/* ########################## FPU functions #################################### */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_FpuFunctions FPU Functions + \brief Function that provides FPU type. + @{ + */ + +/** + \brief get FPU type + \details returns the FPU type + \returns + - \b 0: No FPU + - \b 1: Single precision FPU + - \b 2: Double + Single precision FPU + */ +__STATIC_INLINE uint32_t SCB_GetFPUType(void) +{ + return 0U; /* No FPU */ +} + + +/*@} end of CMSIS_Core_FpuFunctions */ + /* ################################## SysTick function ############################################ */ @@ -1640,7 +1814,7 @@ __STATIC_INLINE void NVIC_SystemReset(void) @{ */ -#if (__Vendor_SysTickConfig == 0U) +#if defined (__Vendor_SysTickConfig) && (__Vendor_SysTickConfig == 0U) /** \brief System Tick Configuration @@ -1683,8 +1857,8 @@ __STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks) @{ */ -extern volatile int32_t ITM_RxBuffer; /*!< External variable to receive characters. */ -#define ITM_RXBUFFER_EMPTY 0x5AA55AA5U /*!< Value identifying \ref ITM_RxBuffer is ready for next character. */ +extern volatile int32_t ITM_RxBuffer; /*!< External variable to receive characters. */ +#define ITM_RXBUFFER_EMPTY ((int32_t)0x5AA55AA5U) /*!< Value identifying \ref ITM_RxBuffer is ready for next character. */ /** @@ -1761,3 +1935,4 @@ __STATIC_INLINE int32_t ITM_CheckChar (void) #endif /* __CORE_CM3_H_DEPENDANT */ #endif /* __CMSIS_GENERIC */ + diff --git a/panda/board/inc/core_cm4.h b/panda/board/inc/core_cm4.h index dc840ebf222138..0d40081a385dc1 100644 --- a/panda/board/inc/core_cm4.h +++ b/panda/board/inc/core_cm4.h @@ -1,40 +1,30 @@ /**************************************************************************//** * @file core_cm4.h * @brief CMSIS Cortex-M4 Core Peripheral Access Layer Header File - * @version V4.30 - * @date 20. October 2015 + * @version V5.1.0 + * @date 13. March 2019 ******************************************************************************/ -/* Copyright (c) 2009 - 2015 ARM LIMITED - - All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of ARM nor the names of its contributors may be used - to endorse or promote products derived from this software without - specific prior written permission. - * - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - ---------------------------------------------------------------------------*/ - +/* + * Copyright (c) 2009-2019 Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #if defined ( __ICCARM__ ) - #pragma system_include /* treat file as system include file for MISRA check */ -#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) + #pragma system_include /* treat file as system include file for MISRA check */ +#elif defined (__clang__) #pragma clang system_header /* treat file as system include file */ #endif @@ -70,60 +60,22 @@ @{ */ -/* CMSIS CM4 definitions */ -#define __CM4_CMSIS_VERSION_MAIN (0x04U) /*!< [31:16] CMSIS HAL main version */ -#define __CM4_CMSIS_VERSION_SUB (0x1EU) /*!< [15:0] CMSIS HAL sub version */ -#define __CM4_CMSIS_VERSION ((__CM4_CMSIS_VERSION_MAIN << 16U) | \ - __CM4_CMSIS_VERSION_SUB ) /*!< CMSIS HAL version number */ - -#define __CORTEX_M (0x04U) /*!< Cortex-M Core */ - - -#if defined ( __CC_ARM ) - #define __ASM __asm /*!< asm keyword for ARM Compiler */ - #define __INLINE __inline /*!< inline keyword for ARM Compiler */ - #define __STATIC_INLINE static __inline - -#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) - #define __ASM __asm /*!< asm keyword for ARM Compiler */ - #define __INLINE __inline /*!< inline keyword for ARM Compiler */ - #define __STATIC_INLINE static __inline - -#elif defined ( __GNUC__ ) - #define __ASM __asm /*!< asm keyword for GNU Compiler */ - #define __INLINE inline /*!< inline keyword for GNU Compiler */ - #define __STATIC_INLINE static inline +#include "cmsis_version.h" -#elif defined ( __ICCARM__ ) - #define __ASM __asm /*!< asm keyword for IAR Compiler */ - #define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */ - #define __STATIC_INLINE static inline - -#elif defined ( __TMS470__ ) - #define __ASM __asm /*!< asm keyword for TI CCS Compiler */ - #define __STATIC_INLINE static inline - -#elif defined ( __TASKING__ ) - #define __ASM __asm /*!< asm keyword for TASKING Compiler */ - #define __INLINE inline /*!< inline keyword for TASKING Compiler */ - #define __STATIC_INLINE static inline +/* CMSIS CM4 definitions */ +#define __CM4_CMSIS_VERSION_MAIN (__CM_CMSIS_VERSION_MAIN) /*!< \deprecated [31:16] CMSIS HAL main version */ +#define __CM4_CMSIS_VERSION_SUB (__CM_CMSIS_VERSION_SUB) /*!< \deprecated [15:0] CMSIS HAL sub version */ +#define __CM4_CMSIS_VERSION ((__CM4_CMSIS_VERSION_MAIN << 16U) | \ + __CM4_CMSIS_VERSION_SUB ) /*!< \deprecated CMSIS HAL version number */ -#elif defined ( __CSMC__ ) - #define __packed - #define __ASM _asm /*!< asm keyword for COSMIC Compiler */ - #define __INLINE inline /*!< inline keyword for COSMIC Compiler. Use -pc99 on compile line */ - #define __STATIC_INLINE static inline - -#else - #error Unknown compiler -#endif +#define __CORTEX_M (4U) /*!< Cortex-M Core */ /** __FPU_USED indicates whether an FPU is used or not. For this, __FPU_PRESENT has to be checked prior to making use of FPU specific registers and functions. */ #if defined ( __CC_ARM ) #if defined __TARGET_FPU_VFP - #if (__FPU_PRESENT == 1U) + #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) #define __FPU_USED 1U #else #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" @@ -133,9 +85,9 @@ #define __FPU_USED 0U #endif -#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) - #if defined __ARM_PCS_VFP - #if (__FPU_PRESENT == 1) +#elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) + #if defined __ARM_FP + #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) #define __FPU_USED 1U #else #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" @@ -147,7 +99,7 @@ #elif defined ( __GNUC__ ) #if defined (__VFP_FP__) && !defined(__SOFTFP__) - #if (__FPU_PRESENT == 1U) + #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) #define __FPU_USED 1U #else #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" @@ -159,7 +111,7 @@ #elif defined ( __ICCARM__ ) #if defined __ARMVFP__ - #if (__FPU_PRESENT == 1U) + #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) #define __FPU_USED 1U #else #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" @@ -169,9 +121,9 @@ #define __FPU_USED 0U #endif -#elif defined ( __TMS470__ ) +#elif defined ( __TI_ARM__ ) #if defined __TI_VFP_SUPPORT__ - #if (__FPU_PRESENT == 1U) + #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) #define __FPU_USED 1U #else #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" @@ -183,7 +135,7 @@ #elif defined ( __TASKING__ ) #if defined __FPU_VFP__ - #if (__FPU_PRESENT == 1U) + #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) #define __FPU_USED 1U #else #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" @@ -195,7 +147,7 @@ #elif defined ( __CSMC__ ) #if ( __CSMC__ & 0x400U) - #if (__FPU_PRESENT == 1U) + #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) #define __FPU_USED 1U #else #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" @@ -207,9 +159,8 @@ #endif -#include "core_cmInstr.h" /* Core Instruction Access */ -#include "core_cmFunc.h" /* Core Function Access */ -#include "core_cmSimd.h" /* Compiler specific SIMD Intrinsics */ +#include "cmsis_compiler.h" /* CMSIS compiler specific defines */ + #ifdef __cplusplus } @@ -244,7 +195,7 @@ #endif #ifndef __NVIC_PRIO_BITS - #define __NVIC_PRIO_BITS 4U + #define __NVIC_PRIO_BITS 3U #warning "__NVIC_PRIO_BITS not defined in device header file; using default!" #endif @@ -367,11 +318,12 @@ typedef union struct { uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */ - uint32_t _reserved0:7; /*!< bit: 9..15 Reserved */ + uint32_t _reserved0:1; /*!< bit: 9 Reserved */ + uint32_t ICI_IT_1:6; /*!< bit: 10..15 ICI/IT part 1 */ uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */ uint32_t _reserved1:4; /*!< bit: 20..23 Reserved */ - uint32_t T:1; /*!< bit: 24 Thumb bit (read 0) */ - uint32_t IT:2; /*!< bit: 25..26 saved IT state (read 0) */ + uint32_t T:1; /*!< bit: 24 Thumb bit */ + uint32_t ICI_IT_2:2; /*!< bit: 25..26 ICI/IT part 2 */ uint32_t Q:1; /*!< bit: 27 Saturation condition flag */ uint32_t V:1; /*!< bit: 28 Overflow condition code flag */ uint32_t C:1; /*!< bit: 29 Carry condition code flag */ @@ -397,8 +349,8 @@ typedef union #define xPSR_Q_Pos 27U /*!< xPSR: Q Position */ #define xPSR_Q_Msk (1UL << xPSR_Q_Pos) /*!< xPSR: Q Mask */ -#define xPSR_IT_Pos 25U /*!< xPSR: IT Position */ -#define xPSR_IT_Msk (3UL << xPSR_IT_Pos) /*!< xPSR: IT Mask */ +#define xPSR_ICI_IT_2_Pos 25U /*!< xPSR: ICI/IT part 2 Position */ +#define xPSR_ICI_IT_2_Msk (3UL << xPSR_ICI_IT_2_Pos) /*!< xPSR: ICI/IT part 2 Mask */ #define xPSR_T_Pos 24U /*!< xPSR: T Position */ #define xPSR_T_Msk (1UL << xPSR_T_Pos) /*!< xPSR: T Mask */ @@ -406,6 +358,9 @@ typedef union #define xPSR_GE_Pos 16U /*!< xPSR: GE Position */ #define xPSR_GE_Msk (0xFUL << xPSR_GE_Pos) /*!< xPSR: GE Mask */ +#define xPSR_ICI_IT_1_Pos 10U /*!< xPSR: ICI/IT part 1 Position */ +#define xPSR_ICI_IT_1_Msk (0x3FUL << xPSR_ICI_IT_1_Pos) /*!< xPSR: ICI/IT part 1 Mask */ + #define xPSR_ISR_Pos 0U /*!< xPSR: ISR Position */ #define xPSR_ISR_Msk (0x1FFUL /*<< xPSR_ISR_Pos*/) /*!< xPSR: ISR Mask */ @@ -453,7 +408,7 @@ typedef struct __IOM uint32_t ISER[8U]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */ uint32_t RESERVED0[24U]; __IOM uint32_t ICER[8U]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */ - uint32_t RSERVED1[24U]; + uint32_t RESERVED1[24U]; __IOM uint32_t ISPR[8U]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */ uint32_t RESERVED2[24U]; __IOM uint32_t ICPR[8U]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */ @@ -662,6 +617,66 @@ typedef struct #define SCB_CFSR_MEMFAULTSR_Pos 0U /*!< SCB CFSR: Memory Manage Fault Status Register Position */ #define SCB_CFSR_MEMFAULTSR_Msk (0xFFUL /*<< SCB_CFSR_MEMFAULTSR_Pos*/) /*!< SCB CFSR: Memory Manage Fault Status Register Mask */ +/* MemManage Fault Status Register (part of SCB Configurable Fault Status Register) */ +#define SCB_CFSR_MMARVALID_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 7U) /*!< SCB CFSR (MMFSR): MMARVALID Position */ +#define SCB_CFSR_MMARVALID_Msk (1UL << SCB_CFSR_MMARVALID_Pos) /*!< SCB CFSR (MMFSR): MMARVALID Mask */ + +#define SCB_CFSR_MLSPERR_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 5U) /*!< SCB CFSR (MMFSR): MLSPERR Position */ +#define SCB_CFSR_MLSPERR_Msk (1UL << SCB_CFSR_MLSPERR_Pos) /*!< SCB CFSR (MMFSR): MLSPERR Mask */ + +#define SCB_CFSR_MSTKERR_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 4U) /*!< SCB CFSR (MMFSR): MSTKERR Position */ +#define SCB_CFSR_MSTKERR_Msk (1UL << SCB_CFSR_MSTKERR_Pos) /*!< SCB CFSR (MMFSR): MSTKERR Mask */ + +#define SCB_CFSR_MUNSTKERR_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 3U) /*!< SCB CFSR (MMFSR): MUNSTKERR Position */ +#define SCB_CFSR_MUNSTKERR_Msk (1UL << SCB_CFSR_MUNSTKERR_Pos) /*!< SCB CFSR (MMFSR): MUNSTKERR Mask */ + +#define SCB_CFSR_DACCVIOL_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 1U) /*!< SCB CFSR (MMFSR): DACCVIOL Position */ +#define SCB_CFSR_DACCVIOL_Msk (1UL << SCB_CFSR_DACCVIOL_Pos) /*!< SCB CFSR (MMFSR): DACCVIOL Mask */ + +#define SCB_CFSR_IACCVIOL_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 0U) /*!< SCB CFSR (MMFSR): IACCVIOL Position */ +#define SCB_CFSR_IACCVIOL_Msk (1UL /*<< SCB_CFSR_IACCVIOL_Pos*/) /*!< SCB CFSR (MMFSR): IACCVIOL Mask */ + +/* BusFault Status Register (part of SCB Configurable Fault Status Register) */ +#define SCB_CFSR_BFARVALID_Pos (SCB_CFSR_BUSFAULTSR_Pos + 7U) /*!< SCB CFSR (BFSR): BFARVALID Position */ +#define SCB_CFSR_BFARVALID_Msk (1UL << SCB_CFSR_BFARVALID_Pos) /*!< SCB CFSR (BFSR): BFARVALID Mask */ + +#define SCB_CFSR_LSPERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 5U) /*!< SCB CFSR (BFSR): LSPERR Position */ +#define SCB_CFSR_LSPERR_Msk (1UL << SCB_CFSR_LSPERR_Pos) /*!< SCB CFSR (BFSR): LSPERR Mask */ + +#define SCB_CFSR_STKERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 4U) /*!< SCB CFSR (BFSR): STKERR Position */ +#define SCB_CFSR_STKERR_Msk (1UL << SCB_CFSR_STKERR_Pos) /*!< SCB CFSR (BFSR): STKERR Mask */ + +#define SCB_CFSR_UNSTKERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 3U) /*!< SCB CFSR (BFSR): UNSTKERR Position */ +#define SCB_CFSR_UNSTKERR_Msk (1UL << SCB_CFSR_UNSTKERR_Pos) /*!< SCB CFSR (BFSR): UNSTKERR Mask */ + +#define SCB_CFSR_IMPRECISERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 2U) /*!< SCB CFSR (BFSR): IMPRECISERR Position */ +#define SCB_CFSR_IMPRECISERR_Msk (1UL << SCB_CFSR_IMPRECISERR_Pos) /*!< SCB CFSR (BFSR): IMPRECISERR Mask */ + +#define SCB_CFSR_PRECISERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 1U) /*!< SCB CFSR (BFSR): PRECISERR Position */ +#define SCB_CFSR_PRECISERR_Msk (1UL << SCB_CFSR_PRECISERR_Pos) /*!< SCB CFSR (BFSR): PRECISERR Mask */ + +#define SCB_CFSR_IBUSERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 0U) /*!< SCB CFSR (BFSR): IBUSERR Position */ +#define SCB_CFSR_IBUSERR_Msk (1UL << SCB_CFSR_IBUSERR_Pos) /*!< SCB CFSR (BFSR): IBUSERR Mask */ + +/* UsageFault Status Register (part of SCB Configurable Fault Status Register) */ +#define SCB_CFSR_DIVBYZERO_Pos (SCB_CFSR_USGFAULTSR_Pos + 9U) /*!< SCB CFSR (UFSR): DIVBYZERO Position */ +#define SCB_CFSR_DIVBYZERO_Msk (1UL << SCB_CFSR_DIVBYZERO_Pos) /*!< SCB CFSR (UFSR): DIVBYZERO Mask */ + +#define SCB_CFSR_UNALIGNED_Pos (SCB_CFSR_USGFAULTSR_Pos + 8U) /*!< SCB CFSR (UFSR): UNALIGNED Position */ +#define SCB_CFSR_UNALIGNED_Msk (1UL << SCB_CFSR_UNALIGNED_Pos) /*!< SCB CFSR (UFSR): UNALIGNED Mask */ + +#define SCB_CFSR_NOCP_Pos (SCB_CFSR_USGFAULTSR_Pos + 3U) /*!< SCB CFSR (UFSR): NOCP Position */ +#define SCB_CFSR_NOCP_Msk (1UL << SCB_CFSR_NOCP_Pos) /*!< SCB CFSR (UFSR): NOCP Mask */ + +#define SCB_CFSR_INVPC_Pos (SCB_CFSR_USGFAULTSR_Pos + 2U) /*!< SCB CFSR (UFSR): INVPC Position */ +#define SCB_CFSR_INVPC_Msk (1UL << SCB_CFSR_INVPC_Pos) /*!< SCB CFSR (UFSR): INVPC Mask */ + +#define SCB_CFSR_INVSTATE_Pos (SCB_CFSR_USGFAULTSR_Pos + 1U) /*!< SCB CFSR (UFSR): INVSTATE Position */ +#define SCB_CFSR_INVSTATE_Msk (1UL << SCB_CFSR_INVSTATE_Pos) /*!< SCB CFSR (UFSR): INVSTATE Mask */ + +#define SCB_CFSR_UNDEFINSTR_Pos (SCB_CFSR_USGFAULTSR_Pos + 0U) /*!< SCB CFSR (UFSR): UNDEFINSTR Position */ +#define SCB_CFSR_UNDEFINSTR_Msk (1UL << SCB_CFSR_UNDEFINSTR_Pos) /*!< SCB CFSR (UFSR): UNDEFINSTR Mask */ + /* SCB Hard Fault Status Register Definitions */ #define SCB_HFSR_DEBUGEVT_Pos 31U /*!< SCB HFSR: DEBUGEVT Position */ #define SCB_HFSR_DEBUGEVT_Msk (1UL << SCB_HFSR_DEBUGEVT_Pos) /*!< SCB HFSR: DEBUGEVT Mask */ @@ -807,10 +822,7 @@ typedef struct __IOM uint32_t TPR; /*!< Offset: 0xE40 (R/W) ITM Trace Privilege Register */ uint32_t RESERVED2[15U]; __IOM uint32_t TCR; /*!< Offset: 0xE80 (R/W) ITM Trace Control Register */ - uint32_t RESERVED3[29U]; - __OM uint32_t IWR; /*!< Offset: 0xEF8 ( /W) ITM Integration Write Register */ - __IM uint32_t IRR; /*!< Offset: 0xEFC (R/ ) ITM Integration Read Register */ - __IOM uint32_t IMCR; /*!< Offset: 0xF00 (R/W) ITM Integration Mode Control Register */ + uint32_t RESERVED3[32U]; uint32_t RESERVED4[43U]; __OM uint32_t LAR; /*!< Offset: 0xFB0 ( /W) ITM Lock Access Register */ __IM uint32_t LSR; /*!< Offset: 0xFB4 (R/ ) ITM Lock Status Register */ @@ -831,7 +843,7 @@ typedef struct /* ITM Trace Privilege Register Definitions */ #define ITM_TPR_PRIVMASK_Pos 0U /*!< ITM TPR: PRIVMASK Position */ -#define ITM_TPR_PRIVMASK_Msk (0xFUL /*<< ITM_TPR_PRIVMASK_Pos*/) /*!< ITM TPR: PRIVMASK Mask */ +#define ITM_TPR_PRIVMASK_Msk (0xFFFFFFFFUL /*<< ITM_TPR_PRIVMASK_Pos*/) /*!< ITM TPR: PRIVMASK Mask */ /* ITM Trace Control Register Definitions */ #define ITM_TCR_BUSY_Pos 23U /*!< ITM TCR: BUSY Position */ @@ -861,18 +873,6 @@ typedef struct #define ITM_TCR_ITMENA_Pos 0U /*!< ITM TCR: ITM Enable bit Position */ #define ITM_TCR_ITMENA_Msk (1UL /*<< ITM_TCR_ITMENA_Pos*/) /*!< ITM TCR: ITM Enable bit Mask */ -/* ITM Integration Write Register Definitions */ -#define ITM_IWR_ATVALIDM_Pos 0U /*!< ITM IWR: ATVALIDM Position */ -#define ITM_IWR_ATVALIDM_Msk (1UL /*<< ITM_IWR_ATVALIDM_Pos*/) /*!< ITM IWR: ATVALIDM Mask */ - -/* ITM Integration Read Register Definitions */ -#define ITM_IRR_ATREADYM_Pos 0U /*!< ITM IRR: ATREADYM Position */ -#define ITM_IRR_ATREADYM_Msk (1UL /*<< ITM_IRR_ATREADYM_Pos*/) /*!< ITM IRR: ATREADYM Mask */ - -/* ITM Integration Mode Control Register Definitions */ -#define ITM_IMCR_INTEGRATION_Pos 0U /*!< ITM IMCR: INTEGRATION Position */ -#define ITM_IMCR_INTEGRATION_Msk (1UL /*<< ITM_IMCR_INTEGRATION_Pos*/) /*!< ITM IMCR: INTEGRATION Mask */ - /* ITM Lock Status Register Definitions */ #define ITM_LSR_ByteAcc_Pos 2U /*!< ITM LSR: ByteAcc Position */ #define ITM_LSR_ByteAcc_Msk (1UL << ITM_LSR_ByteAcc_Pos) /*!< ITM LSR: ByteAcc Mask */ @@ -1045,7 +1045,7 @@ typedef struct */ typedef struct { - __IOM uint32_t SSPSR; /*!< Offset: 0x000 (R/ ) Supported Parallel Port Size Register */ + __IM uint32_t SSPSR; /*!< Offset: 0x000 (R/ ) Supported Parallel Port Size Register */ __IOM uint32_t CSPSR; /*!< Offset: 0x004 (R/W) Current Parallel Port Size Register */ uint32_t RESERVED0[2U]; __IOM uint32_t ACPR; /*!< Offset: 0x010 (R/W) Asynchronous Clock Prescaler Register */ @@ -1056,7 +1056,7 @@ typedef struct __IOM uint32_t FFCR; /*!< Offset: 0x304 (R/W) Formatter and Flush Control Register */ __IM uint32_t FSCR; /*!< Offset: 0x308 (R/ ) Formatter Synchronization Counter Register */ uint32_t RESERVED3[759U]; - __IM uint32_t TRIGGER; /*!< Offset: 0xEE8 (R/ ) TRIGGER */ + __IM uint32_t TRIGGER; /*!< Offset: 0xEE8 (R/ ) TRIGGER Register */ __IM uint32_t FIFO0; /*!< Offset: 0xEEC (R/ ) Integration ETM Data */ __IM uint32_t ITATBCTR2; /*!< Offset: 0xEF0 (R/ ) ITATBCTR2 */ uint32_t RESERVED4[1U]; @@ -1105,13 +1105,13 @@ typedef struct /* TPI Integration ETM Data Register Definitions (FIFO0) */ #define TPI_FIFO0_ITM_ATVALID_Pos 29U /*!< TPI FIFO0: ITM_ATVALID Position */ -#define TPI_FIFO0_ITM_ATVALID_Msk (0x3UL << TPI_FIFO0_ITM_ATVALID_Pos) /*!< TPI FIFO0: ITM_ATVALID Mask */ +#define TPI_FIFO0_ITM_ATVALID_Msk (0x1UL << TPI_FIFO0_ITM_ATVALID_Pos) /*!< TPI FIFO0: ITM_ATVALID Mask */ #define TPI_FIFO0_ITM_bytecount_Pos 27U /*!< TPI FIFO0: ITM_bytecount Position */ #define TPI_FIFO0_ITM_bytecount_Msk (0x3UL << TPI_FIFO0_ITM_bytecount_Pos) /*!< TPI FIFO0: ITM_bytecount Mask */ #define TPI_FIFO0_ETM_ATVALID_Pos 26U /*!< TPI FIFO0: ETM_ATVALID Position */ -#define TPI_FIFO0_ETM_ATVALID_Msk (0x3UL << TPI_FIFO0_ETM_ATVALID_Pos) /*!< TPI FIFO0: ETM_ATVALID Mask */ +#define TPI_FIFO0_ETM_ATVALID_Msk (0x1UL << TPI_FIFO0_ETM_ATVALID_Pos) /*!< TPI FIFO0: ETM_ATVALID Mask */ #define TPI_FIFO0_ETM_bytecount_Pos 24U /*!< TPI FIFO0: ETM_bytecount Position */ #define TPI_FIFO0_ETM_bytecount_Msk (0x3UL << TPI_FIFO0_ETM_bytecount_Pos) /*!< TPI FIFO0: ETM_bytecount Mask */ @@ -1126,18 +1126,21 @@ typedef struct #define TPI_FIFO0_ETM0_Msk (0xFFUL /*<< TPI_FIFO0_ETM0_Pos*/) /*!< TPI FIFO0: ETM0 Mask */ /* TPI ITATBCTR2 Register Definitions */ -#define TPI_ITATBCTR2_ATREADY_Pos 0U /*!< TPI ITATBCTR2: ATREADY Position */ -#define TPI_ITATBCTR2_ATREADY_Msk (0x1UL /*<< TPI_ITATBCTR2_ATREADY_Pos*/) /*!< TPI ITATBCTR2: ATREADY Mask */ +#define TPI_ITATBCTR2_ATREADY2_Pos 0U /*!< TPI ITATBCTR2: ATREADY2 Position */ +#define TPI_ITATBCTR2_ATREADY2_Msk (0x1UL /*<< TPI_ITATBCTR2_ATREADY2_Pos*/) /*!< TPI ITATBCTR2: ATREADY2 Mask */ + +#define TPI_ITATBCTR2_ATREADY1_Pos 0U /*!< TPI ITATBCTR2: ATREADY1 Position */ +#define TPI_ITATBCTR2_ATREADY1_Msk (0x1UL /*<< TPI_ITATBCTR2_ATREADY1_Pos*/) /*!< TPI ITATBCTR2: ATREADY1 Mask */ /* TPI Integration ITM Data Register Definitions (FIFO1) */ #define TPI_FIFO1_ITM_ATVALID_Pos 29U /*!< TPI FIFO1: ITM_ATVALID Position */ -#define TPI_FIFO1_ITM_ATVALID_Msk (0x3UL << TPI_FIFO1_ITM_ATVALID_Pos) /*!< TPI FIFO1: ITM_ATVALID Mask */ +#define TPI_FIFO1_ITM_ATVALID_Msk (0x1UL << TPI_FIFO1_ITM_ATVALID_Pos) /*!< TPI FIFO1: ITM_ATVALID Mask */ #define TPI_FIFO1_ITM_bytecount_Pos 27U /*!< TPI FIFO1: ITM_bytecount Position */ #define TPI_FIFO1_ITM_bytecount_Msk (0x3UL << TPI_FIFO1_ITM_bytecount_Pos) /*!< TPI FIFO1: ITM_bytecount Mask */ #define TPI_FIFO1_ETM_ATVALID_Pos 26U /*!< TPI FIFO1: ETM_ATVALID Position */ -#define TPI_FIFO1_ETM_ATVALID_Msk (0x3UL << TPI_FIFO1_ETM_ATVALID_Pos) /*!< TPI FIFO1: ETM_ATVALID Mask */ +#define TPI_FIFO1_ETM_ATVALID_Msk (0x1UL << TPI_FIFO1_ETM_ATVALID_Pos) /*!< TPI FIFO1: ETM_ATVALID Mask */ #define TPI_FIFO1_ETM_bytecount_Pos 24U /*!< TPI FIFO1: ETM_bytecount Position */ #define TPI_FIFO1_ETM_bytecount_Msk (0x3UL << TPI_FIFO1_ETM_bytecount_Pos) /*!< TPI FIFO1: ETM_bytecount Mask */ @@ -1152,12 +1155,15 @@ typedef struct #define TPI_FIFO1_ITM0_Msk (0xFFUL /*<< TPI_FIFO1_ITM0_Pos*/) /*!< TPI FIFO1: ITM0 Mask */ /* TPI ITATBCTR0 Register Definitions */ -#define TPI_ITATBCTR0_ATREADY_Pos 0U /*!< TPI ITATBCTR0: ATREADY Position */ -#define TPI_ITATBCTR0_ATREADY_Msk (0x1UL /*<< TPI_ITATBCTR0_ATREADY_Pos*/) /*!< TPI ITATBCTR0: ATREADY Mask */ +#define TPI_ITATBCTR0_ATREADY2_Pos 0U /*!< TPI ITATBCTR0: ATREADY2 Position */ +#define TPI_ITATBCTR0_ATREADY2_Msk (0x1UL /*<< TPI_ITATBCTR0_ATREADY2_Pos*/) /*!< TPI ITATBCTR0: ATREADY2 Mask */ + +#define TPI_ITATBCTR0_ATREADY1_Pos 0U /*!< TPI ITATBCTR0: ATREADY1 Position */ +#define TPI_ITATBCTR0_ATREADY1_Msk (0x1UL /*<< TPI_ITATBCTR0_ATREADY1_Pos*/) /*!< TPI ITATBCTR0: ATREADY1 Mask */ /* TPI Integration Mode Control Register Definitions */ #define TPI_ITCTRL_Mode_Pos 0U /*!< TPI ITCTRL: Mode Position */ -#define TPI_ITCTRL_Mode_Msk (0x1UL /*<< TPI_ITCTRL_Mode_Pos*/) /*!< TPI ITCTRL: Mode Mask */ +#define TPI_ITCTRL_Mode_Msk (0x3UL /*<< TPI_ITCTRL_Mode_Pos*/) /*!< TPI ITCTRL: Mode Mask */ /* TPI DEVID Register Definitions */ #define TPI_DEVID_NRZVALID_Pos 11U /*!< TPI DEVID: NRZVALID Position */ @@ -1179,16 +1185,16 @@ typedef struct #define TPI_DEVID_NrTraceInput_Msk (0x1FUL /*<< TPI_DEVID_NrTraceInput_Pos*/) /*!< TPI DEVID: NrTraceInput Mask */ /* TPI DEVTYPE Register Definitions */ -#define TPI_DEVTYPE_MajorType_Pos 4U /*!< TPI DEVTYPE: MajorType Position */ -#define TPI_DEVTYPE_MajorType_Msk (0xFUL << TPI_DEVTYPE_MajorType_Pos) /*!< TPI DEVTYPE: MajorType Mask */ - -#define TPI_DEVTYPE_SubType_Pos 0U /*!< TPI DEVTYPE: SubType Position */ +#define TPI_DEVTYPE_SubType_Pos 4U /*!< TPI DEVTYPE: SubType Position */ #define TPI_DEVTYPE_SubType_Msk (0xFUL /*<< TPI_DEVTYPE_SubType_Pos*/) /*!< TPI DEVTYPE: SubType Mask */ +#define TPI_DEVTYPE_MajorType_Pos 0U /*!< TPI DEVTYPE: MajorType Position */ +#define TPI_DEVTYPE_MajorType_Msk (0xFUL << TPI_DEVTYPE_MajorType_Pos) /*!< TPI DEVTYPE: MajorType Mask */ + /*@}*/ /* end of group CMSIS_TPI */ -#if (__MPU_PRESENT == 1U) +#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) /** \ingroup CMSIS_core_register \defgroup CMSIS_MPU Memory Protection Unit (MPU) @@ -1214,6 +1220,8 @@ typedef struct __IOM uint32_t RASR_A3; /*!< Offset: 0x028 (R/W) MPU Alias 3 Region Attribute and Size Register */ } MPU_Type; +#define MPU_TYPE_RALIASES 4U + /* MPU Type Register Definitions */ #define MPU_TYPE_IREGION_Pos 16U /*!< MPU TYPE: IREGION Position */ #define MPU_TYPE_IREGION_Msk (0xFFUL << MPU_TYPE_IREGION_Pos) /*!< MPU TYPE: IREGION Mask */ @@ -1280,10 +1288,9 @@ typedef struct #define MPU_RASR_ENABLE_Msk (1UL /*<< MPU_RASR_ENABLE_Pos*/) /*!< MPU RASR: Region enable bit Disable Mask */ /*@} end of group CMSIS_MPU */ -#endif +#endif /* defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) */ -#if (__FPU_PRESENT == 1U) /** \ingroup CMSIS_core_register \defgroup CMSIS_FPU Floating Point Unit (FPU) @@ -1302,6 +1309,7 @@ typedef struct __IOM uint32_t FPDSCR; /*!< Offset: 0x00C (R/W) Floating-Point Default Status Control Register */ __IM uint32_t MVFR0; /*!< Offset: 0x010 (R/ ) Media and FP Feature Register 0 */ __IM uint32_t MVFR1; /*!< Offset: 0x014 (R/ ) Media and FP Feature Register 1 */ + __IM uint32_t MVFR2; /*!< Offset: 0x018 (R/ ) Media and FP Feature Register 2 */ } FPU_Type; /* Floating-Point Context Control Register Definitions */ @@ -1387,8 +1395,12 @@ typedef struct #define FPU_MVFR1_FtZ_mode_Pos 0U /*!< MVFR1: FtZ mode bits Position */ #define FPU_MVFR1_FtZ_mode_Msk (0xFUL /*<< FPU_MVFR1_FtZ_mode_Pos*/) /*!< MVFR1: FtZ mode bits Mask */ +/* Media and FP Feature Register 2 Definitions */ + +#define FPU_MVFR2_VFP_Misc_Pos 4U /*!< MVFR2: VFP Misc bits Position */ +#define FPU_MVFR2_VFP_Misc_Msk (0xFUL << FPU_MVFR2_VFP_Misc_Pos) /*!< MVFR2: VFP Misc bits Mask */ + /*@} end of group CMSIS_FPU */ -#endif /** @@ -1506,18 +1518,18 @@ typedef struct /** \brief Mask and shift a bit field value for use in a register bit range. \param[in] field Name of the register bit field. - \param[in] value Value of the bit field. + \param[in] value Value of the bit field. This parameter is interpreted as an uint32_t type. \return Masked and shifted value. */ -#define _VAL2FLD(field, value) ((value << field ## _Pos) & field ## _Msk) +#define _VAL2FLD(field, value) (((uint32_t)(value) << field ## _Pos) & field ## _Msk) /** \brief Mask and shift a register value to extract a bit filed value. \param[in] field Name of the register bit field. - \param[in] value Value of register. + \param[in] value Value of register. This parameter is interpreted as an uint32_t type. \return Masked and shifted bit field value. */ -#define _FLD2VAL(field, value) ((value & field ## _Msk) >> field ## _Pos) +#define _FLD2VAL(field, value) (((uint32_t)(value) & field ## _Msk) >> field ## _Pos) /*@} end of group CMSIS_core_bitfield */ @@ -1529,7 +1541,7 @@ typedef struct @{ */ -/* Memory mapping of Cortex-M4 Hardware */ +/* Memory mapping of Core Hardware */ #define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */ #define ITM_BASE (0xE0000000UL) /*!< ITM Base Address */ #define DWT_BASE (0xE0001000UL) /*!< DWT Base Address */ @@ -1548,15 +1560,13 @@ typedef struct #define TPI ((TPI_Type *) TPI_BASE ) /*!< TPI configuration struct */ #define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE) /*!< Core Debug configuration struct */ -#if (__MPU_PRESENT == 1U) +#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) #define MPU_BASE (SCS_BASE + 0x0D90UL) /*!< Memory Protection Unit */ #define MPU ((MPU_Type *) MPU_BASE ) /*!< Memory Protection Unit */ #endif -#if (__FPU_PRESENT == 1U) - #define FPU_BASE (SCS_BASE + 0x0F30UL) /*!< Floating Point Unit */ - #define FPU ((FPU_Type *) FPU_BASE ) /*!< Floating Point Unit */ -#endif +#define FPU_BASE (SCS_BASE + 0x0F30UL) /*!< Floating Point Unit */ +#define FPU ((FPU_Type *) FPU_BASE ) /*!< Floating Point Unit */ /*@} */ @@ -1584,6 +1594,48 @@ typedef struct @{ */ +#ifdef CMSIS_NVIC_VIRTUAL + #ifndef CMSIS_NVIC_VIRTUAL_HEADER_FILE + #define CMSIS_NVIC_VIRTUAL_HEADER_FILE "cmsis_nvic_virtual.h" + #endif + #include CMSIS_NVIC_VIRTUAL_HEADER_FILE +#else + #define NVIC_SetPriorityGrouping __NVIC_SetPriorityGrouping + #define NVIC_GetPriorityGrouping __NVIC_GetPriorityGrouping + #define NVIC_EnableIRQ __NVIC_EnableIRQ + #define NVIC_GetEnableIRQ __NVIC_GetEnableIRQ + #define NVIC_DisableIRQ __NVIC_DisableIRQ + #define NVIC_GetPendingIRQ __NVIC_GetPendingIRQ + #define NVIC_SetPendingIRQ __NVIC_SetPendingIRQ + #define NVIC_ClearPendingIRQ __NVIC_ClearPendingIRQ + #define NVIC_GetActive __NVIC_GetActive + #define NVIC_SetPriority __NVIC_SetPriority + #define NVIC_GetPriority __NVIC_GetPriority + #define NVIC_SystemReset __NVIC_SystemReset +#endif /* CMSIS_NVIC_VIRTUAL */ + +#ifdef CMSIS_VECTAB_VIRTUAL + #ifndef CMSIS_VECTAB_VIRTUAL_HEADER_FILE + #define CMSIS_VECTAB_VIRTUAL_HEADER_FILE "cmsis_vectab_virtual.h" + #endif + #include CMSIS_VECTAB_VIRTUAL_HEADER_FILE +#else + #define NVIC_SetVector __NVIC_SetVector + #define NVIC_GetVector __NVIC_GetVector +#endif /* (CMSIS_VECTAB_VIRTUAL) */ + +#define NVIC_USER_IRQ_OFFSET 16 + + +/* The following EXC_RETURN values are saved the LR on exception entry */ +#define EXC_RETURN_HANDLER (0xFFFFFFF1UL) /* return to Handler mode, uses MSP after return */ +#define EXC_RETURN_THREAD_MSP (0xFFFFFFF9UL) /* return to Thread mode, uses MSP after return */ +#define EXC_RETURN_THREAD_PSP (0xFFFFFFFDUL) /* return to Thread mode, uses PSP after return */ +#define EXC_RETURN_HANDLER_FPU (0xFFFFFFE1UL) /* return to Handler mode, uses MSP after return, restore floating-point state */ +#define EXC_RETURN_THREAD_MSP_FPU (0xFFFFFFE9UL) /* return to Thread mode, uses MSP after return, restore floating-point state */ +#define EXC_RETURN_THREAD_PSP_FPU (0xFFFFFFEDUL) /* return to Thread mode, uses PSP after return, restore floating-point state */ + + /** \brief Set Priority Grouping \details Sets the priority grouping field using the required unlock sequence. @@ -1593,7 +1645,7 @@ typedef struct priority bits (__NVIC_PRIO_BITS), the smallest possible priority group is set. \param [in] PriorityGroup Priority grouping field. */ -__STATIC_INLINE void NVIC_SetPriorityGrouping(uint32_t PriorityGroup) +__STATIC_INLINE void __NVIC_SetPriorityGrouping(uint32_t PriorityGroup) { uint32_t reg_value; uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */ @@ -1602,7 +1654,7 @@ __STATIC_INLINE void NVIC_SetPriorityGrouping(uint32_t PriorityGroup) reg_value &= ~((uint32_t)(SCB_AIRCR_VECTKEY_Msk | SCB_AIRCR_PRIGROUP_Msk)); /* clear bits to change */ reg_value = (reg_value | ((uint32_t)0x5FAUL << SCB_AIRCR_VECTKEY_Pos) | - (PriorityGroupTmp << 8U) ); /* Insert write key and priorty group */ + (PriorityGroupTmp << SCB_AIRCR_PRIGROUP_Pos) ); /* Insert write key and priority group */ SCB->AIRCR = reg_value; } @@ -1612,121 +1664,180 @@ __STATIC_INLINE void NVIC_SetPriorityGrouping(uint32_t PriorityGroup) \details Reads the priority grouping field from the NVIC Interrupt Controller. \return Priority grouping field (SCB->AIRCR [10:8] PRIGROUP field). */ -__STATIC_INLINE uint32_t NVIC_GetPriorityGrouping(void) +__STATIC_INLINE uint32_t __NVIC_GetPriorityGrouping(void) { return ((uint32_t)((SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) >> SCB_AIRCR_PRIGROUP_Pos)); } /** - \brief Enable External Interrupt - \details Enables a device-specific interrupt in the NVIC interrupt controller. - \param [in] IRQn External interrupt number. Value cannot be negative. + \brief Enable Interrupt + \details Enables a device specific interrupt in the NVIC interrupt controller. + \param [in] IRQn Device specific interrupt number. + \note IRQn must not be negative. + */ +__STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + __COMPILER_BARRIER(); + NVIC->ISER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + __COMPILER_BARRIER(); + } +} + + +/** + \brief Get Interrupt Enable status + \details Returns a device specific interrupt enable status from the NVIC interrupt controller. + \param [in] IRQn Device specific interrupt number. + \return 0 Interrupt is not enabled. + \return 1 Interrupt is enabled. + \note IRQn must not be negative. */ -__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn) +__STATIC_INLINE uint32_t __NVIC_GetEnableIRQ(IRQn_Type IRQn) { - NVIC->ISER[(((uint32_t)(int32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL)); + if ((int32_t)(IRQn) >= 0) + { + return((uint32_t)(((NVIC->ISER[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + } + else + { + return(0U); + } } /** - \brief Disable External Interrupt - \details Disables a device-specific interrupt in the NVIC interrupt controller. - \param [in] IRQn External interrupt number. Value cannot be negative. + \brief Disable Interrupt + \details Disables a device specific interrupt in the NVIC interrupt controller. + \param [in] IRQn Device specific interrupt number. + \note IRQn must not be negative. */ -__STATIC_INLINE void NVIC_DisableIRQ(IRQn_Type IRQn) +__STATIC_INLINE void __NVIC_DisableIRQ(IRQn_Type IRQn) { - NVIC->ICER[(((uint32_t)(int32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL)); + if ((int32_t)(IRQn) >= 0) + { + NVIC->ICER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + __DSB(); + __ISB(); + } } /** \brief Get Pending Interrupt - \details Reads the pending register in the NVIC and returns the pending bit for the specified interrupt. - \param [in] IRQn Interrupt number. + \details Reads the NVIC pending register and returns the pending bit for the specified device specific interrupt. + \param [in] IRQn Device specific interrupt number. \return 0 Interrupt status is not pending. \return 1 Interrupt status is pending. + \note IRQn must not be negative. */ -__STATIC_INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn) +__STATIC_INLINE uint32_t __NVIC_GetPendingIRQ(IRQn_Type IRQn) { - return((uint32_t)(((NVIC->ISPR[(((uint32_t)(int32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + if ((int32_t)(IRQn) >= 0) + { + return((uint32_t)(((NVIC->ISPR[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + } + else + { + return(0U); + } } /** \brief Set Pending Interrupt - \details Sets the pending bit of an external interrupt. - \param [in] IRQn Interrupt number. Value cannot be negative. + \details Sets the pending bit of a device specific interrupt in the NVIC pending register. + \param [in] IRQn Device specific interrupt number. + \note IRQn must not be negative. */ -__STATIC_INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn) +__STATIC_INLINE void __NVIC_SetPendingIRQ(IRQn_Type IRQn) { - NVIC->ISPR[(((uint32_t)(int32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL)); + if ((int32_t)(IRQn) >= 0) + { + NVIC->ISPR[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + } } /** \brief Clear Pending Interrupt - \details Clears the pending bit of an external interrupt. - \param [in] IRQn External interrupt number. Value cannot be negative. + \details Clears the pending bit of a device specific interrupt in the NVIC pending register. + \param [in] IRQn Device specific interrupt number. + \note IRQn must not be negative. */ -__STATIC_INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn) +__STATIC_INLINE void __NVIC_ClearPendingIRQ(IRQn_Type IRQn) { - NVIC->ICPR[(((uint32_t)(int32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL)); + if ((int32_t)(IRQn) >= 0) + { + NVIC->ICPR[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + } } /** \brief Get Active Interrupt - \details Reads the active register in NVIC and returns the active bit. - \param [in] IRQn Interrupt number. + \details Reads the active register in the NVIC and returns the active bit for the device specific interrupt. + \param [in] IRQn Device specific interrupt number. \return 0 Interrupt status is not active. \return 1 Interrupt status is active. + \note IRQn must not be negative. */ -__STATIC_INLINE uint32_t NVIC_GetActive(IRQn_Type IRQn) +__STATIC_INLINE uint32_t __NVIC_GetActive(IRQn_Type IRQn) { - return((uint32_t)(((NVIC->IABR[(((uint32_t)(int32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + if ((int32_t)(IRQn) >= 0) + { + return((uint32_t)(((NVIC->IABR[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + } + else + { + return(0U); + } } /** \brief Set Interrupt Priority - \details Sets the priority of an interrupt. - \note The priority cannot be set for every core interrupt. + \details Sets the priority of a device specific interrupt or a processor exception. + The interrupt number can be positive to specify a device specific interrupt, + or negative to specify a processor exception. \param [in] IRQn Interrupt number. \param [in] priority Priority to set. + \note The priority cannot be set for every processor exception. */ -__STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority) +__STATIC_INLINE void __NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority) { - if ((int32_t)(IRQn) < 0) + if ((int32_t)(IRQn) >= 0) { - SCB->SHP[(((uint32_t)(int32_t)IRQn) & 0xFUL)-4UL] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL); + NVIC->IP[((uint32_t)IRQn)] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL); } else { - NVIC->IP[((uint32_t)(int32_t)IRQn)] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL); + SCB->SHP[(((uint32_t)IRQn) & 0xFUL)-4UL] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL); } } /** \brief Get Interrupt Priority - \details Reads the priority of an interrupt. - The interrupt number can be positive to specify an external (device specific) interrupt, - or negative to specify an internal (core) interrupt. + \details Reads the priority of a device specific interrupt or a processor exception. + The interrupt number can be positive to specify a device specific interrupt, + or negative to specify a processor exception. \param [in] IRQn Interrupt number. \return Interrupt Priority. Value is aligned automatically to the implemented priority bits of the microcontroller. */ -__STATIC_INLINE uint32_t NVIC_GetPriority(IRQn_Type IRQn) +__STATIC_INLINE uint32_t __NVIC_GetPriority(IRQn_Type IRQn) { - if ((int32_t)(IRQn) < 0) + if ((int32_t)(IRQn) >= 0) { - return(((uint32_t)SCB->SHP[(((uint32_t)(int32_t)IRQn) & 0xFUL)-4UL] >> (8U - __NVIC_PRIO_BITS))); + return(((uint32_t)NVIC->IP[((uint32_t)IRQn)] >> (8U - __NVIC_PRIO_BITS))); } else { - return(((uint32_t)NVIC->IP[((uint32_t)(int32_t)IRQn)] >> (8U - __NVIC_PRIO_BITS))); + return(((uint32_t)SCB->SHP[(((uint32_t)IRQn) & 0xFUL)-4UL] >> (8U - __NVIC_PRIO_BITS))); } } @@ -1783,11 +1894,43 @@ __STATIC_INLINE void NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGr } +/** + \brief Set Interrupt Vector + \details Sets an interrupt vector in SRAM based interrupt vector table. + The interrupt number can be positive to specify a device specific interrupt, + or negative to specify a processor exception. + VTOR must been relocated to SRAM before. + \param [in] IRQn Interrupt number + \param [in] vector Address of interrupt handler function + */ +__STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) +{ + uint32_t vectors = (uint32_t )SCB->VTOR; + (* (int *) (vectors + ((int32_t)IRQn + NVIC_USER_IRQ_OFFSET) * 4)) = vector; + /* ARM Application Note 321 states that the M4 does not require the architectural barrier */ +} + + +/** + \brief Get Interrupt Vector + \details Reads an interrupt vector from interrupt vector table. + The interrupt number can be positive to specify a device specific interrupt, + or negative to specify a processor exception. + \param [in] IRQn Interrupt number. + \return Address of interrupt handler function + */ +__STATIC_INLINE uint32_t __NVIC_GetVector(IRQn_Type IRQn) +{ + uint32_t vectors = (uint32_t )SCB->VTOR; + return (uint32_t)(* (int *) (vectors + ((int32_t)IRQn + NVIC_USER_IRQ_OFFSET) * 4)); +} + + /** \brief System Reset \details Initiates a system reset request to reset the MCU. */ -__STATIC_INLINE void NVIC_SystemReset(void) +__NO_RETURN __STATIC_INLINE void __NVIC_SystemReset(void) { __DSB(); /* Ensure all outstanding memory accesses included buffered write are completed before reset */ @@ -1805,6 +1948,50 @@ __STATIC_INLINE void NVIC_SystemReset(void) /*@} end of CMSIS_Core_NVICFunctions */ +/* ########################## MPU functions #################################### */ + +#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) + +#include "mpu_armv7.h" + +#endif + + +/* ########################## FPU functions #################################### */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_FpuFunctions FPU Functions + \brief Function that provides FPU type. + @{ + */ + +/** + \brief get FPU type + \details returns the FPU type + \returns + - \b 0: No FPU + - \b 1: Single precision FPU + - \b 2: Double + Single precision FPU + */ +__STATIC_INLINE uint32_t SCB_GetFPUType(void) +{ + uint32_t mvfr0; + + mvfr0 = FPU->MVFR0; + if ((mvfr0 & (FPU_MVFR0_Single_precision_Msk | FPU_MVFR0_Double_precision_Msk)) == 0x020U) + { + return 1U; /* Single precision FPU */ + } + else + { + return 0U; /* No FPU */ + } +} + + +/*@} end of CMSIS_Core_FpuFunctions */ + + /* ################################## SysTick function ############################################ */ /** @@ -1814,7 +2001,7 @@ __STATIC_INLINE void NVIC_SystemReset(void) @{ */ -#if (__Vendor_SysTickConfig == 0U) +#if defined (__Vendor_SysTickConfig) && (__Vendor_SysTickConfig == 0U) /** \brief System Tick Configuration @@ -1857,8 +2044,8 @@ __STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks) @{ */ -extern volatile int32_t ITM_RxBuffer; /*!< External variable to receive characters. */ -#define ITM_RXBUFFER_EMPTY 0x5AA55AA5U /*!< Value identifying \ref ITM_RxBuffer is ready for next character. */ +extern volatile int32_t ITM_RxBuffer; /*!< External variable to receive characters. */ +#define ITM_RXBUFFER_EMPTY ((int32_t)0x5AA55AA5U) /*!< Value identifying \ref ITM_RxBuffer is ready for next character. */ /** @@ -1935,3 +2122,4 @@ __STATIC_INLINE int32_t ITM_CheckChar (void) #endif /* __CORE_CM4_H_DEPENDANT */ #endif /* __CMSIS_GENERIC */ + diff --git a/panda/board/inc/core_cmFunc.h b/panda/board/inc/core_cmFunc.h deleted file mode 100644 index 652a48af07a93d..00000000000000 --- a/panda/board/inc/core_cmFunc.h +++ /dev/null @@ -1,87 +0,0 @@ -/**************************************************************************//** - * @file core_cmFunc.h - * @brief CMSIS Cortex-M Core Function Access Header File - * @version V4.30 - * @date 20. October 2015 - ******************************************************************************/ -/* Copyright (c) 2009 - 2015 ARM LIMITED - - All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of ARM nor the names of its contributors may be used - to endorse or promote products derived from this software without - specific prior written permission. - * - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - ---------------------------------------------------------------------------*/ - - -#if defined ( __ICCARM__ ) - #pragma system_include /* treat file as system include file for MISRA check */ -#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) - #pragma clang system_header /* treat file as system include file */ -#endif - -#ifndef __CORE_CMFUNC_H -#define __CORE_CMFUNC_H - - -/* ########################### Core Function Access ########################### */ -/** \ingroup CMSIS_Core_FunctionInterface - \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions - @{ -*/ - -/*------------------ RealView Compiler -----------------*/ -#if defined ( __CC_ARM ) - #include "cmsis_armcc.h" - -/*------------------ ARM Compiler V6 -------------------*/ -#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) - #include "cmsis_armcc_V6.h" - -/*------------------ GNU Compiler ----------------------*/ -#elif defined ( __GNUC__ ) - #include "cmsis_gcc.h" - -/*------------------ ICC Compiler ----------------------*/ -#elif defined ( __ICCARM__ ) - #include - -/*------------------ TI CCS Compiler -------------------*/ -#elif defined ( __TMS470__ ) - #include - -/*------------------ TASKING Compiler ------------------*/ -#elif defined ( __TASKING__ ) - /* - * The CMSIS functions have been implemented as intrinsics in the compiler. - * Please use "carm -?i" to get an up to date list of all intrinsics, - * Including the CMSIS ones. - */ - -/*------------------ COSMIC Compiler -------------------*/ -#elif defined ( __CSMC__ ) - #include - -#endif - -/*@} end of CMSIS_Core_RegAccFunctions */ - -#endif /* __CORE_CMFUNC_H */ diff --git a/panda/board/inc/core_cmInstr.h b/panda/board/inc/core_cmInstr.h deleted file mode 100644 index f474b0e6f362c7..00000000000000 --- a/panda/board/inc/core_cmInstr.h +++ /dev/null @@ -1,87 +0,0 @@ -/**************************************************************************//** - * @file core_cmInstr.h - * @brief CMSIS Cortex-M Core Instruction Access Header File - * @version V4.30 - * @date 20. October 2015 - ******************************************************************************/ -/* Copyright (c) 2009 - 2015 ARM LIMITED - - All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of ARM nor the names of its contributors may be used - to endorse or promote products derived from this software without - specific prior written permission. - * - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - ---------------------------------------------------------------------------*/ - - -#if defined ( __ICCARM__ ) - #pragma system_include /* treat file as system include file for MISRA check */ -#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) - #pragma clang system_header /* treat file as system include file */ -#endif - -#ifndef __CORE_CMINSTR_H -#define __CORE_CMINSTR_H - - -/* ########################## Core Instruction Access ######################### */ -/** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface - Access to dedicated instructions - @{ -*/ - -/*------------------ RealView Compiler -----------------*/ -#if defined ( __CC_ARM ) - #include "cmsis_armcc.h" - -/*------------------ ARM Compiler V6 -------------------*/ -#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) - #include "cmsis_armcc_V6.h" - -/*------------------ GNU Compiler ----------------------*/ -#elif defined ( __GNUC__ ) - #include "cmsis_gcc.h" - -/*------------------ ICC Compiler ----------------------*/ -#elif defined ( __ICCARM__ ) - #include - -/*------------------ TI CCS Compiler -------------------*/ -#elif defined ( __TMS470__ ) - #include - -/*------------------ TASKING Compiler ------------------*/ -#elif defined ( __TASKING__ ) - /* - * The CMSIS functions have been implemented as intrinsics in the compiler. - * Please use "carm -?i" to get an up to date list of all intrinsics, - * Including the CMSIS ones. - */ - -/*------------------ COSMIC Compiler -------------------*/ -#elif defined ( __CSMC__ ) - #include - -#endif - -/*@}*/ /* end of group CMSIS_Core_InstructionInterface */ - -#endif /* __CORE_CMINSTR_H */ diff --git a/panda/board/inc/core_cmSimd.h b/panda/board/inc/core_cmSimd.h deleted file mode 100644 index 66bf5c2a725b6d..00000000000000 --- a/panda/board/inc/core_cmSimd.h +++ /dev/null @@ -1,96 +0,0 @@ -/**************************************************************************//** - * @file core_cmSimd.h - * @brief CMSIS Cortex-M SIMD Header File - * @version V4.30 - * @date 20. October 2015 - ******************************************************************************/ -/* Copyright (c) 2009 - 2015 ARM LIMITED - - All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of ARM nor the names of its contributors may be used - to endorse or promote products derived from this software without - specific prior written permission. - * - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - ---------------------------------------------------------------------------*/ - - -#if defined ( __ICCARM__ ) - #pragma system_include /* treat file as system include file for MISRA check */ -#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) - #pragma clang system_header /* treat file as system include file */ -#endif - -#ifndef __CORE_CMSIMD_H -#define __CORE_CMSIMD_H - -#ifdef __cplusplus - extern "C" { -#endif - - -/* ################### Compiler specific Intrinsics ########################### */ -/** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics - Access to dedicated SIMD instructions - @{ -*/ - -/*------------------ RealView Compiler -----------------*/ -#if defined ( __CC_ARM ) - #include "cmsis_armcc.h" - -/*------------------ ARM Compiler V6 -------------------*/ -#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) - #include "cmsis_armcc_V6.h" - -/*------------------ GNU Compiler ----------------------*/ -#elif defined ( __GNUC__ ) - #include "cmsis_gcc.h" - -/*------------------ ICC Compiler ----------------------*/ -#elif defined ( __ICCARM__ ) - #include - -/*------------------ TI CCS Compiler -------------------*/ -#elif defined ( __TMS470__ ) - #include - -/*------------------ TASKING Compiler ------------------*/ -#elif defined ( __TASKING__ ) - /* - * The CMSIS functions have been implemented as intrinsics in the compiler. - * Please use "carm -?i" to get an up to date list of all intrinsics, - * Including the CMSIS ones. - */ - -/*------------------ COSMIC Compiler -------------------*/ -#elif defined ( __CSMC__ ) - #include - -#endif - -/*@} end of group CMSIS_SIMD_intrinsics */ - - -#ifdef __cplusplus -} -#endif - -#endif /* __CORE_CMSIMD_H */ diff --git a/panda/board/inc/mpu_armv7.h b/panda/board/inc/mpu_armv7.h new file mode 100644 index 00000000000000..ef8e6810ca42ff --- /dev/null +++ b/panda/board/inc/mpu_armv7.h @@ -0,0 +1,273 @@ +/****************************************************************************** + * @file mpu_armv7.h + * @brief CMSIS MPU API for Armv7-M MPU + * @version V5.1.0 + * @date 08. March 2019 + ******************************************************************************/ +/* + * Copyright (c) 2017-2019 Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#if defined ( __ICCARM__ ) + #pragma system_include /* treat file as system include file for MISRA check */ +#elif defined (__clang__) + #pragma clang system_header /* treat file as system include file */ +#endif + +#ifndef ARM_MPU_ARMV7_H +#define ARM_MPU_ARMV7_H + +#define ARM_MPU_REGION_SIZE_32B ((uint8_t)0x04U) ///!< MPU Region Size 32 Bytes +#define ARM_MPU_REGION_SIZE_64B ((uint8_t)0x05U) ///!< MPU Region Size 64 Bytes +#define ARM_MPU_REGION_SIZE_128B ((uint8_t)0x06U) ///!< MPU Region Size 128 Bytes +#define ARM_MPU_REGION_SIZE_256B ((uint8_t)0x07U) ///!< MPU Region Size 256 Bytes +#define ARM_MPU_REGION_SIZE_512B ((uint8_t)0x08U) ///!< MPU Region Size 512 Bytes +#define ARM_MPU_REGION_SIZE_1KB ((uint8_t)0x09U) ///!< MPU Region Size 1 KByte +#define ARM_MPU_REGION_SIZE_2KB ((uint8_t)0x0AU) ///!< MPU Region Size 2 KBytes +#define ARM_MPU_REGION_SIZE_4KB ((uint8_t)0x0BU) ///!< MPU Region Size 4 KBytes +#define ARM_MPU_REGION_SIZE_8KB ((uint8_t)0x0CU) ///!< MPU Region Size 8 KBytes +#define ARM_MPU_REGION_SIZE_16KB ((uint8_t)0x0DU) ///!< MPU Region Size 16 KBytes +#define ARM_MPU_REGION_SIZE_32KB ((uint8_t)0x0EU) ///!< MPU Region Size 32 KBytes +#define ARM_MPU_REGION_SIZE_64KB ((uint8_t)0x0FU) ///!< MPU Region Size 64 KBytes +#define ARM_MPU_REGION_SIZE_128KB ((uint8_t)0x10U) ///!< MPU Region Size 128 KBytes +#define ARM_MPU_REGION_SIZE_256KB ((uint8_t)0x11U) ///!< MPU Region Size 256 KBytes +#define ARM_MPU_REGION_SIZE_512KB ((uint8_t)0x12U) ///!< MPU Region Size 512 KBytes +#define ARM_MPU_REGION_SIZE_1MB ((uint8_t)0x13U) ///!< MPU Region Size 1 MByte +#define ARM_MPU_REGION_SIZE_2MB ((uint8_t)0x14U) ///!< MPU Region Size 2 MBytes +#define ARM_MPU_REGION_SIZE_4MB ((uint8_t)0x15U) ///!< MPU Region Size 4 MBytes +#define ARM_MPU_REGION_SIZE_8MB ((uint8_t)0x16U) ///!< MPU Region Size 8 MBytes +#define ARM_MPU_REGION_SIZE_16MB ((uint8_t)0x17U) ///!< MPU Region Size 16 MBytes +#define ARM_MPU_REGION_SIZE_32MB ((uint8_t)0x18U) ///!< MPU Region Size 32 MBytes +#define ARM_MPU_REGION_SIZE_64MB ((uint8_t)0x19U) ///!< MPU Region Size 64 MBytes +#define ARM_MPU_REGION_SIZE_128MB ((uint8_t)0x1AU) ///!< MPU Region Size 128 MBytes +#define ARM_MPU_REGION_SIZE_256MB ((uint8_t)0x1BU) ///!< MPU Region Size 256 MBytes +#define ARM_MPU_REGION_SIZE_512MB ((uint8_t)0x1CU) ///!< MPU Region Size 512 MBytes +#define ARM_MPU_REGION_SIZE_1GB ((uint8_t)0x1DU) ///!< MPU Region Size 1 GByte +#define ARM_MPU_REGION_SIZE_2GB ((uint8_t)0x1EU) ///!< MPU Region Size 2 GBytes +#define ARM_MPU_REGION_SIZE_4GB ((uint8_t)0x1FU) ///!< MPU Region Size 4 GBytes + +#define ARM_MPU_AP_NONE 0U ///!< MPU Access Permission no access +#define ARM_MPU_AP_PRIV 1U ///!< MPU Access Permission privileged access only +#define ARM_MPU_AP_URO 2U ///!< MPU Access Permission unprivileged access read-only +#define ARM_MPU_AP_FULL 3U ///!< MPU Access Permission full access +#define ARM_MPU_AP_PRO 5U ///!< MPU Access Permission privileged access read-only +#define ARM_MPU_AP_RO 6U ///!< MPU Access Permission read-only access + +/** MPU Region Base Address Register Value +* +* \param Region The region to be configured, number 0 to 15. +* \param BaseAddress The base address for the region. +*/ +#define ARM_MPU_RBAR(Region, BaseAddress) \ + (((BaseAddress) & MPU_RBAR_ADDR_Msk) | \ + ((Region) & MPU_RBAR_REGION_Msk) | \ + (MPU_RBAR_VALID_Msk)) + +/** +* MPU Memory Access Attributes +* +* \param TypeExtField Type extension field, allows you to configure memory access type, for example strongly ordered, peripheral. +* \param IsShareable Region is shareable between multiple bus masters. +* \param IsCacheable Region is cacheable, i.e. its value may be kept in cache. +* \param IsBufferable Region is bufferable, i.e. using write-back caching. Cacheable but non-bufferable regions use write-through policy. +*/ +#define ARM_MPU_ACCESS_(TypeExtField, IsShareable, IsCacheable, IsBufferable) \ + ((((TypeExtField) << MPU_RASR_TEX_Pos) & MPU_RASR_TEX_Msk) | \ + (((IsShareable) << MPU_RASR_S_Pos) & MPU_RASR_S_Msk) | \ + (((IsCacheable) << MPU_RASR_C_Pos) & MPU_RASR_C_Msk) | \ + (((IsBufferable) << MPU_RASR_B_Pos) & MPU_RASR_B_Msk)) + +/** +* MPU Region Attribute and Size Register Value +* +* \param DisableExec Instruction access disable bit, 1= disable instruction fetches. +* \param AccessPermission Data access permissions, allows you to configure read/write access for User and Privileged mode. +* \param AccessAttributes Memory access attribution, see \ref ARM_MPU_ACCESS_. +* \param SubRegionDisable Sub-region disable field. +* \param Size Region size of the region to be configured, for example 4K, 8K. +*/ +#define ARM_MPU_RASR_EX(DisableExec, AccessPermission, AccessAttributes, SubRegionDisable, Size) \ + ((((DisableExec) << MPU_RASR_XN_Pos) & MPU_RASR_XN_Msk) | \ + (((AccessPermission) << MPU_RASR_AP_Pos) & MPU_RASR_AP_Msk) | \ + (((AccessAttributes) & (MPU_RASR_TEX_Msk | MPU_RASR_S_Msk | MPU_RASR_C_Msk | MPU_RASR_B_Msk))) | \ + (((SubRegionDisable) << MPU_RASR_SRD_Pos) & MPU_RASR_SRD_Msk) | \ + (((Size) << MPU_RASR_SIZE_Pos) & MPU_RASR_SIZE_Msk) | \ + (((MPU_RASR_ENABLE_Msk)))) + +/** +* MPU Region Attribute and Size Register Value +* +* \param DisableExec Instruction access disable bit, 1= disable instruction fetches. +* \param AccessPermission Data access permissions, allows you to configure read/write access for User and Privileged mode. +* \param TypeExtField Type extension field, allows you to configure memory access type, for example strongly ordered, peripheral. +* \param IsShareable Region is shareable between multiple bus masters. +* \param IsCacheable Region is cacheable, i.e. its value may be kept in cache. +* \param IsBufferable Region is bufferable, i.e. using write-back caching. Cacheable but non-bufferable regions use write-through policy. +* \param SubRegionDisable Sub-region disable field. +* \param Size Region size of the region to be configured, for example 4K, 8K. +*/ +#define ARM_MPU_RASR(DisableExec, AccessPermission, TypeExtField, IsShareable, IsCacheable, IsBufferable, SubRegionDisable, Size) \ + ARM_MPU_RASR_EX(DisableExec, AccessPermission, ARM_MPU_ACCESS_(TypeExtField, IsShareable, IsCacheable, IsBufferable), SubRegionDisable, Size) + +/** +* MPU Memory Access Attribute for strongly ordered memory. +* - TEX: 000b +* - Shareable +* - Non-cacheable +* - Non-bufferable +*/ +#define ARM_MPU_ACCESS_ORDERED ARM_MPU_ACCESS_(0U, 1U, 0U, 0U) + +/** +* MPU Memory Access Attribute for device memory. +* - TEX: 000b (if shareable) or 010b (if non-shareable) +* - Shareable or non-shareable +* - Non-cacheable +* - Bufferable (if shareable) or non-bufferable (if non-shareable) +* +* \param IsShareable Configures the device memory as shareable or non-shareable. +*/ +#define ARM_MPU_ACCESS_DEVICE(IsShareable) ((IsShareable) ? ARM_MPU_ACCESS_(0U, 1U, 0U, 1U) : ARM_MPU_ACCESS_(2U, 0U, 0U, 0U)) + +/** +* MPU Memory Access Attribute for normal memory. +* - TEX: 1BBb (reflecting outer cacheability rules) +* - Shareable or non-shareable +* - Cacheable or non-cacheable (reflecting inner cacheability rules) +* - Bufferable or non-bufferable (reflecting inner cacheability rules) +* +* \param OuterCp Configures the outer cache policy. +* \param InnerCp Configures the inner cache policy. +* \param IsShareable Configures the memory as shareable or non-shareable. +*/ +#define ARM_MPU_ACCESS_NORMAL(OuterCp, InnerCp, IsShareable) ARM_MPU_ACCESS_((4U | (OuterCp)), IsShareable, ((InnerCp) & 2U), ((InnerCp) & 1U)) + +/** +* MPU Memory Access Attribute non-cacheable policy. +*/ +#define ARM_MPU_CACHEP_NOCACHE 0U + +/** +* MPU Memory Access Attribute write-back, write and read allocate policy. +*/ +#define ARM_MPU_CACHEP_WB_WRA 1U + +/** +* MPU Memory Access Attribute write-through, no write allocate policy. +*/ +#define ARM_MPU_CACHEP_WT_NWA 2U + +/** +* MPU Memory Access Attribute write-back, no write allocate policy. +*/ +#define ARM_MPU_CACHEP_WB_NWA 3U + + +/** +* Struct for a single MPU Region +*/ +typedef struct { + uint32_t RBAR; //!< The region base address register value (RBAR) + uint32_t RASR; //!< The region attribute and size register value (RASR) \ref MPU_RASR +} ARM_MPU_Region_t; + +/** Enable the MPU. +* \param MPU_Control Default access permissions for unconfigured regions. +*/ +__STATIC_INLINE void ARM_MPU_Enable(uint32_t MPU_Control) +{ + MPU->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk; +#ifdef SCB_SHCSR_MEMFAULTENA_Msk + SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk; +#endif + __DSB(); + __ISB(); +} + +/** Disable the MPU. +*/ +__STATIC_INLINE void ARM_MPU_Disable(void) +{ + __DMB(); +#ifdef SCB_SHCSR_MEMFAULTENA_Msk + SCB->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk; +#endif + MPU->CTRL &= ~MPU_CTRL_ENABLE_Msk; +} + +/** Clear and disable the given MPU region. +* \param rnr Region number to be cleared. +*/ +__STATIC_INLINE void ARM_MPU_ClrRegion(uint32_t rnr) +{ + MPU->RNR = rnr; + MPU->RASR = 0U; +} + +/** Configure an MPU region. +* \param rbar Value for RBAR register. +* \param rsar Value for RSAR register. +*/ +__STATIC_INLINE void ARM_MPU_SetRegion(uint32_t rbar, uint32_t rasr) +{ + MPU->RBAR = rbar; + MPU->RASR = rasr; +} + +/** Configure the given MPU region. +* \param rnr Region number to be configured. +* \param rbar Value for RBAR register. +* \param rsar Value for RSAR register. +*/ +__STATIC_INLINE void ARM_MPU_SetRegionEx(uint32_t rnr, uint32_t rbar, uint32_t rasr) +{ + MPU->RNR = rnr; + MPU->RBAR = rbar; + MPU->RASR = rasr; +} + +/** Memcopy with strictly ordered memory access, e.g. for register targets. +* \param dst Destination data is copied to. +* \param src Source data is copied from. +* \param len Amount of data words to be copied. +*/ +__STATIC_INLINE void ARM_MPU_OrderedMemcpy(volatile uint32_t* dst, const uint32_t* __RESTRICT src, uint32_t len) +{ + uint32_t i; + for (i = 0U; i < len; ++i) + { + dst[i] = src[i]; + } +} + +/** Load the given number of MPU regions from a table. +* \param table Pointer to the MPU configuration table. +* \param cnt Amount of regions to be configured. +*/ +__STATIC_INLINE void ARM_MPU_Load(ARM_MPU_Region_t const* table, uint32_t cnt) +{ + const uint32_t rowWordSize = sizeof(ARM_MPU_Region_t)/4U; + while (cnt > MPU_TYPE_RALIASES) { + ARM_MPU_OrderedMemcpy(&(MPU->RBAR), &(table->RBAR), MPU_TYPE_RALIASES*rowWordSize); + table += MPU_TYPE_RALIASES; + cnt -= MPU_TYPE_RALIASES; + } + ARM_MPU_OrderedMemcpy(&(MPU->RBAR), &(table->RBAR), cnt*rowWordSize); +} + +#endif + diff --git a/panda/board/main.c b/panda/board/main.c index df134e046baaad..3bcae876e203d0 100644 --- a/panda/board/main.c +++ b/panda/board/main.c @@ -13,6 +13,7 @@ #include "drivers/llcan.h" #include "drivers/llgpio.h" #include "drivers/adc.h" +#include "drivers/pwm.h" #include "board.h" @@ -35,6 +36,10 @@ // ********************* Serial debugging ********************* +bool check_started(void) { + return current_board->check_ignition() || ignition_can; +} + void debug_ring_callback(uart_ring *ring) { char rcv; while (getc(ring, &rcv)) { @@ -80,10 +85,10 @@ void started_interrupt_handler(uint8_t interrupt_line) { #ifdef EON // set power savings mode here if on EON build - int power_save_state = current_board->check_ignition() ? POWER_SAVE_STATUS_DISABLED : POWER_SAVE_STATUS_ENABLED; + int power_save_state = check_started() ? POWER_SAVE_STATUS_DISABLED : POWER_SAVE_STATUS_ENABLED; set_power_save_state(power_save_state); // set CDP usb power mode everytime that the car starts to make sure EON is charging - if (current_board->check_ignition()) { + if (check_started()) { current_board->set_usb_power_mode(USB_POWER_CDP); } #endif @@ -117,7 +122,7 @@ void set_safety_mode(uint16_t mode, int16_t param) { switch (mode) { case SAFETY_NOOUTPUT: set_intercept_relay(false); - if(hw_type == HW_TYPE_BLACK_PANDA){ + if(board_has_obd()){ current_board->set_can_mode(CAN_MODE_NORMAL); } can_silent = ALL_CAN_SILENT; @@ -125,7 +130,7 @@ void set_safety_mode(uint16_t mode, int16_t param) { case SAFETY_ELM327: set_intercept_relay(false); heartbeat_counter = 0U; - if(hw_type == HW_TYPE_BLACK_PANDA){ + if(board_has_obd()){ current_board->set_can_mode(CAN_MODE_OBD_CAN2); } can_silent = ALL_CAN_LIVE; @@ -133,19 +138,12 @@ void set_safety_mode(uint16_t mode, int16_t param) { default: set_intercept_relay(true); heartbeat_counter = 0U; - if(hw_type == HW_TYPE_BLACK_PANDA){ + if(board_has_obd()){ current_board->set_can_mode(CAN_MODE_NORMAL); } can_silent = ALL_CAN_LIVE; break; } - if (safety_ignition_hook() != -1) { - // if the ignition hook depends on something other than the started GPIO - // we have to disable power savings (fix for GM and Tesla) - set_power_save_state(POWER_SAVE_STATUS_DISABLED); - } else { - // power mode is already POWER_SAVE_STATUS_DISABLED and CAN TXs are active - } can_init_all(); } } @@ -159,30 +157,21 @@ int get_health_pkt(void *dat) { uint32_t can_send_errs_pkt; uint32_t can_fwd_errs_pkt; uint32_t gmlan_send_errs_pkt; - uint8_t started_pkt; + uint8_t ignition_line_pkt; + uint8_t ignition_can_pkt; uint8_t controls_allowed_pkt; uint8_t gas_interceptor_detected_pkt; uint8_t car_harness_status_pkt; uint8_t usb_power_mode_pkt; + uint8_t safety_mode_pkt; } *health = dat; health->voltage_pkt = adc_get_voltage(); + health->current_pkt = current_board->read_current(); - // No current sense on panda black - if(hw_type != HW_TYPE_BLACK_PANDA){ - health->current_pkt = adc_get(ADCCHAN_CURRENT); - } else { - health->current_pkt = 0; - } - - int safety_ignition = safety_ignition_hook(); - if (safety_ignition < 0) { - //Use the GPIO pin to determine ignition - health->started_pkt = (uint8_t)(current_board->check_ignition()); - } else { - //Current safety hooks want to determine ignition (ex: GM) - health->started_pkt = safety_ignition; - } + //Use the GPIO pin to determine ignition or use a CAN based logic + health->ignition_line_pkt = (uint8_t)(current_board->check_ignition()); + health->ignition_can_pkt = (uint8_t)(ignition_can); health->controls_allowed_pkt = controls_allowed; health->gas_interceptor_detected_pkt = gas_interceptor_detected; @@ -191,10 +180,17 @@ int get_health_pkt(void *dat) { health->gmlan_send_errs_pkt = gmlan_send_errs; health->car_harness_status_pkt = car_harness_status; health->usb_power_mode_pkt = usb_power_mode; + health->safety_mode_pkt = (uint8_t)(current_safety_mode); return sizeof(*health); } +int get_rtc_pkt(void *dat) { + timestamp_t t = rtc_get_time(); + (void)memcpy(dat, &t, sizeof(t)); + return sizeof(t); +} + int usb_cb_ep1_in(void *usbdata, int len, bool hardwired) { UNUSED(hardwired); CAN_FIFOMailBox_TypeDef *reply = (CAN_FIFOMailBox_TypeDef *)usbdata; @@ -247,7 +243,76 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired) unsigned int resp_len = 0; uart_ring *ur = NULL; int i; + timestamp_t t; switch (setup->b.bRequest) { + // **** 0xa0: get rtc time + case 0xa0: + resp_len = get_rtc_pkt(resp); + break; + // **** 0xa1: set rtc year + case 0xa1: + t = rtc_get_time(); + t.year = setup->b.wValue.w; + rtc_set_time(t); + break; + // **** 0xa2: set rtc month + case 0xa2: + t = rtc_get_time(); + t.month = setup->b.wValue.w; + rtc_set_time(t); + break; + // **** 0xa3: set rtc day + case 0xa3: + t = rtc_get_time(); + t.day = setup->b.wValue.w; + rtc_set_time(t); + break; + // **** 0xa4: set rtc weekday + case 0xa4: + t = rtc_get_time(); + t.weekday = setup->b.wValue.w; + rtc_set_time(t); + break; + // **** 0xa5: set rtc hour + case 0xa5: + t = rtc_get_time(); + t.hour = setup->b.wValue.w; + rtc_set_time(t); + break; + // **** 0xa6: set rtc minute + case 0xa6: + t = rtc_get_time(); + t.minute = setup->b.wValue.w; + rtc_set_time(t); + break; + // **** 0xa7: set rtc second + case 0xa7: + t = rtc_get_time(); + t.second = setup->b.wValue.w; + rtc_set_time(t); + break; + // **** 0xb0: set IR power + case 0xb0: + if(power_save_status == POWER_SAVE_STATUS_DISABLED){ + current_board->set_ir_power(setup->b.wValue.w); + } else { + puts("Setting IR power not allowed in power saving mode\n"); + } + break; + // **** 0xb1: set fan power + case 0xb1: + if(power_save_status == POWER_SAVE_STATUS_DISABLED){ + current_board->set_fan_power(setup->b.wValue.w); + } else { + puts("Setting fan power not allowed in power saving mode\n"); + } + break; + // **** 0xb2: get fan rpm + case 0xb2: + resp[0] = (fan_rpm & 0x00FFU); + resp[1] = ((fan_rpm & 0xFF00U) >> 8U); + resp_len = 2; + break; // **** 0xc0: get CAN debug info case 0xc0: puts("can tx: "); puth(can_tx_cnt); @@ -335,7 +400,7 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired) break; // **** 0xdb: set GMLAN (white/grey) or OBD CAN (black) multiplexing mode case 0xdb: - if(hw_type == HW_TYPE_BLACK_PANDA){ + if(board_has_obd()){ if (setup->b.wValue.w == 1U) { // Enable OBD CAN current_board->set_can_mode(CAN_MODE_OBD_CAN2); @@ -583,8 +648,8 @@ uint64_t tcnt = 0; // called once per second // cppcheck-suppress unusedFunction ; used in headers not included in cppcheck -void TIM3_IRQHandler(void) { - if (TIM3->SR != 0) { +void TIM1_BRK_TIM9_IRQHandler(void) { + if (TIM9->SR != 0) { can_live = pending_can_live; current_board->usb_power_mode_tick(tcnt); @@ -602,6 +667,10 @@ void TIM3_IRQHandler(void) { puth(can_tx2_q.r_ptr); puts(" "); puth(can_tx2_q.w_ptr); puts("\n"); #endif + // Tick fan driver + fan_tick(); + //puts("Fan speed: "); puth((unsigned int) fan_rpm); puts("rpm\n"); + // set green LED to be controls allowed current_board->set_led(LED_GREEN, controls_allowed); @@ -616,7 +685,7 @@ void TIM3_IRQHandler(void) { // check heartbeat counter if we are running EON code. If the heartbeat has been gone for a while, go to NOOUTPUT safety mode. #ifdef EON - if (heartbeat_counter >= (current_board->check_ignition() ? EON_HEARTBEAT_IGNITION_CNT_ON : EON_HEARTBEAT_IGNITION_CNT_OFF)) { + if (heartbeat_counter >= (check_started() ? EON_HEARTBEAT_IGNITION_CNT_ON : EON_HEARTBEAT_IGNITION_CNT_OFF)) { puts("EON hasn't sent a heartbeat for 0x"); puth(heartbeat_counter); puts(" seconds. Safety is set to NOOUTPUT mode.\n"); if(current_safety_mode != SAFETY_NOOUTPUT){ set_safety_mode(SAFETY_NOOUTPUT, 0U); @@ -627,7 +696,7 @@ void TIM3_IRQHandler(void) { // on to the next one tcnt += 1U; } - TIM3->SR = 0; + TIM9->SR = 0; } int main(void) { @@ -675,8 +744,7 @@ int main(void) { uart_init(&uart_ring_esp_gps, 115200); } - // there is no LIN on panda black - if(hw_type != HW_TYPE_BLACK_PANDA){ + if(board_has_lin()){ // enable LIN uart_init(&uart_ring_lin1, 10400); UART5->CR2 |= USART_CR2_LINEN; @@ -714,14 +782,13 @@ int main(void) { current_board->set_esp_gps_mode(ESP_GPS_DISABLED); } // only enter power save after the first cycle - /*if (current_board->check_ignition()) { + /*if (check_started()) { set_power_save_state(POWER_SAVE_STATUS_ENABLED); }*/ #endif - - // 48mhz / 65536 ~= 732 / 732 = 1 - timer_init(TIM3, 732); - NVIC_EnableIRQ(TIM3_IRQn); + // 1hz + timer_init(TIM9, 1464); + NVIC_EnableIRQ(TIM1_BRK_TIM9_IRQn); #ifdef DEBUG puts("DEBUG ENABLED\n"); diff --git a/panda/board/power_saving.h b/panda/board/power_saving.h index 0a926c119d3e22..d397884f6e6a8f 100644 --- a/panda/board/power_saving.h +++ b/panda/board/power_saving.h @@ -25,7 +25,6 @@ void set_power_save_state(int state) { enable = true; } - // Switch CAN transcievers current_board->enable_can_transcievers(enable); // Switch EPS/GPS @@ -34,17 +33,25 @@ void set_power_save_state(int state) { } else { current_board->set_esp_gps_mode(ESP_GPS_DISABLED); } - - if(hw_type != HW_TYPE_BLACK_PANDA){ + + if(board_has_gmlan()){ // turn on GMLAN set_gpio_output(GPIOB, 14, enable); set_gpio_output(GPIOB, 15, enable); + } - // turn on LIN + if(board_has_lin()){ + // turn on LIN set_gpio_output(GPIOB, 7, enable); set_gpio_output(GPIOA, 14, enable); } + // Switch off IR and fan when in power saving + if(!enable){ + current_board->set_ir_power(0U); + current_board->set_fan_power(0U); + } + power_save_status = state; } } diff --git a/panda/board/safety.h b/panda/board/safety.h index ffdfebb45472b5..c68eda2c4a4864 100644 --- a/panda/board/safety.h +++ b/panda/board/safety.h @@ -14,6 +14,7 @@ #include "safety/safety_chrysler.h" #include "safety/safety_subaru.h" #include "safety/safety_mazda.h" +#include "safety/safety_volkswagen.h" #include "safety/safety_elm327.h" // from cereal.car.CarParams.SafetyModel @@ -29,8 +30,8 @@ #define SAFETY_CHRYSLER 9U #define SAFETY_TESLA 10U #define SAFETY_SUBARU 11U -#define SAFETY_GM_PASSIVE 12U #define SAFETY_MAZDA 13U +#define SAFETY_VOLKSWAGEN 15U #define SAFETY_TOYOTA_IPAS 16U #define SAFETY_ALLOUTPUT 17U #define SAFETY_GM_ASCM 18U @@ -50,12 +51,6 @@ int safety_tx_lin_hook(int lin_num, uint8_t *data, int len){ return current_hooks->tx_lin(lin_num, data, len); } -// -1 = Disabled (Use GPIO to determine ignition) -// 0 = Off (not started) -// 1 = On (started) -int safety_ignition_hook() { - return current_hooks->ignition(); -} int safety_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) { return current_hooks->fwd(bus_num, to_fwd); } @@ -78,8 +73,8 @@ const safety_hook_config safety_hook_registry[] = { {SAFETY_CHRYSLER, &chrysler_hooks}, {SAFETY_TESLA, &tesla_hooks}, {SAFETY_SUBARU, &subaru_hooks}, - {SAFETY_GM_PASSIVE, &gm_passive_hooks}, {SAFETY_MAZDA, &mazda_hooks}, + {SAFETY_VOLKSWAGEN, &volkswagen_hooks}, {SAFETY_TOYOTA_IPAS, &toyota_ipas_hooks}, {SAFETY_ALLOUTPUT, &alloutput_hooks}, {SAFETY_GM_ASCM, &gm_ascm_hooks}, diff --git a/panda/board/safety/safety_cadillac.h b/panda/board/safety/safety_cadillac.h index ef63360955fe7f..4ae2045505d8a7 100644 --- a/panda/board/safety/safety_cadillac.h +++ b/panda/board/safety/safety_cadillac.h @@ -10,7 +10,6 @@ const int CADILLAC_MAX_RATE_DOWN = 5; const int CADILLAC_DRIVER_TORQUE_ALLOWANCE = 50; const int CADILLAC_DRIVER_TORQUE_FACTOR = 4; -bool cadillac_ign = 0; int cadillac_cruise_engaged_last = 0; int cadillac_rt_torque_last = 0; const int cadillac_torque_msgs_n = 4; @@ -35,11 +34,6 @@ static void cadillac_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { update_sample(&cadillac_torque_driver, torque_driver_new); } - // this message isn't all zeros when ignition is on - if ((addr == 0x160) && (bus == 0)) { - cadillac_ign = GET_BYTES_04(to_push) != 0; - } - // enter controls on rising edge of ACC, exit controls on ACC off if ((addr == 0x370) && (bus == 0)) { int cruise_engaged = GET_BYTE(to_push, 2) & 0x80; // bit 23 @@ -118,11 +112,6 @@ static int cadillac_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { static void cadillac_init(int16_t param) { UNUSED(param); controls_allowed = 0; - cadillac_ign = 0; -} - -static int cadillac_ign_hook(void) { - return cadillac_ign; } const safety_hooks cadillac_hooks = { @@ -130,6 +119,5 @@ const safety_hooks cadillac_hooks = { .rx = cadillac_rx_hook, .tx = cadillac_tx_hook, .tx_lin = nooutput_tx_lin_hook, - .ignition = cadillac_ign_hook, .fwd = default_fwd_hook, }; diff --git a/panda/board/safety/safety_chrysler.h b/panda/board/safety/safety_chrysler.h index e608785739b109..9b8fc361546f59 100644 --- a/panda/board/safety/safety_chrysler.h +++ b/panda/board/safety/safety_chrysler.h @@ -136,6 +136,5 @@ const safety_hooks chrysler_hooks = { .rx = chrysler_rx_hook, .tx = chrysler_tx_hook, .tx_lin = nooutput_tx_lin_hook, - .ignition = default_ign_hook, .fwd = chrysler_fwd_hook, }; diff --git a/panda/board/safety/safety_defaults.h b/panda/board/safety/safety_defaults.h index 9dc23b54b79906..2743db96fe6eff 100644 --- a/panda/board/safety/safety_defaults.h +++ b/panda/board/safety/safety_defaults.h @@ -2,10 +2,6 @@ void default_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { UNUSED(to_push); } -int default_ign_hook(void) { - return -1; // use GPIO to determine ignition -} - // *** no output safety mode *** static void nooutput_init(int16_t param) { @@ -36,7 +32,6 @@ const safety_hooks nooutput_hooks = { .rx = default_rx_hook, .tx = nooutput_tx_hook, .tx_lin = nooutput_tx_lin_hook, - .ignition = default_ign_hook, .fwd = default_fwd_hook, }; @@ -64,6 +59,5 @@ const safety_hooks alloutput_hooks = { .rx = default_rx_hook, .tx = alloutput_tx_hook, .tx_lin = alloutput_tx_lin_hook, - .ignition = default_ign_hook, .fwd = default_fwd_hook, }; diff --git a/panda/board/safety/safety_elm327.h b/panda/board/safety/safety_elm327.h index bbad909f28cb37..ce405b47675f11 100644 --- a/panda/board/safety/safety_elm327.h +++ b/panda/board/safety/safety_elm327.h @@ -38,6 +38,5 @@ const safety_hooks elm327_hooks = { .rx = default_rx_hook, .tx = elm327_tx_hook, .tx_lin = elm327_tx_lin_hook, - .ignition = default_ign_hook, .fwd = default_fwd_hook, }; diff --git a/panda/board/safety/safety_ford.h b/panda/board/safety/safety_ford.h index 0bb839f2f6513d..22fc604ff1dd9d 100644 --- a/panda/board/safety/safety_ford.h +++ b/panda/board/safety/safety_ford.h @@ -97,6 +97,5 @@ const safety_hooks ford_hooks = { .rx = ford_rx_hook, .tx = ford_tx_hook, .tx_lin = nooutput_tx_lin_hook, - .ignition = default_ign_hook, .fwd = default_fwd_hook, }; diff --git a/panda/board/safety/safety_gm.h b/panda/board/safety/safety_gm.h index 7899c6a6daf86c..65a381e27f0b61 100644 --- a/panda/board/safety/safety_gm.h +++ b/panda/board/safety/safety_gm.h @@ -27,7 +27,6 @@ int gm_gas_prev = 0; bool gm_moving = false; // silence everything if stock car control ECUs are still online bool gm_ascm_detected = 0; -bool gm_ignition_started = 0; int gm_rt_torque_last = 0; int gm_desired_torque_last = 0; uint32_t gm_ts_last = 0; @@ -44,13 +43,6 @@ static void gm_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { update_sample(&gm_torque_driver, torque_driver_new); } - if ((addr == 0x1F1) && (bus_number == 0)) { - //Bit 5 should be ignition "on" - //Backup plan is Bit 2 (accessory power) - bool ign = (GET_BYTE(to_push, 0) & 0x20) != 0; - gm_ignition_started = ign; - } - // sample speed, really only care if car is moving or not // rear left wheel speed if (addr == 842) { @@ -227,41 +219,13 @@ static int gm_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { static void gm_init(int16_t param) { UNUSED(param); controls_allowed = 0; - gm_ignition_started = 0; -} - -static int gm_ign_hook(void) { - return gm_ignition_started; } -// All sending is disallowed. -// The only difference from "no output" model -// is using GM ignition hook. - -static void gm_passive_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { - int bus_number = GET_BUS(to_push); - int addr = GET_ADDR(to_push); - - if ((addr == 0x1F1) && (bus_number == 0)) { - bool ign = (GET_BYTE(to_push, 0) & 0x20) != 0; - gm_ignition_started = ign; - } -} const safety_hooks gm_hooks = { .init = gm_init, .rx = gm_rx_hook, .tx = gm_tx_hook, .tx_lin = nooutput_tx_lin_hook, - .ignition = gm_ign_hook, - .fwd = default_fwd_hook, -}; - -const safety_hooks gm_passive_hooks = { - .init = gm_init, - .rx = gm_passive_rx_hook, - .tx = nooutput_tx_hook, - .tx_lin = nooutput_tx_lin_hook, - .ignition = gm_ign_hook, .fwd = default_fwd_hook, }; diff --git a/panda/board/safety/safety_gm_ascm.h b/panda/board/safety/safety_gm_ascm.h index 82f1db6ae5741e..36fd1d8f2adfa9 100644 --- a/panda/board/safety/safety_gm_ascm.h +++ b/panda/board/safety/safety_gm_ascm.h @@ -39,7 +39,6 @@ const safety_hooks gm_ascm_hooks = { .rx = default_rx_hook, .tx = alloutput_tx_hook, .tx_lin = nooutput_tx_lin_hook, - .ignition = default_ign_hook, .fwd = gm_ascm_fwd_hook, }; diff --git a/panda/board/safety/safety_honda.h b/panda/board/safety/safety_honda.h index 950da45e26b9b2..eb54d8168c03f4 100644 --- a/panda/board/safety/safety_honda.h +++ b/panda/board/safety/safety_honda.h @@ -156,7 +156,7 @@ static int honda_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { // FORCE CANCEL: safety check only relevant when spamming the cancel button in Bosch HW // ensuring that only the cancel button press is sent (VAL 2) when controls are off. // This avoids unintended engagements while still allowing resume spam - int bus_pt = ((hw_type == HW_TYPE_BLACK_PANDA) && honda_bosch_hardware)? 1 : 0; + int bus_pt = ((board_has_relay()) && honda_bosch_hardware)? 1 : 0; if ((addr == 0x296) && honda_bosch_hardware && !current_controls_allowed && (bus == bus_pt)) { if (((GET_BYTE(to_send, 0) >> 5) & 0x7) != 2) { @@ -210,8 +210,8 @@ static int honda_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) { static int honda_bosch_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) { int bus_fwd = -1; - int bus_rdr_cam = (hw_type == HW_TYPE_BLACK_PANDA) ? 2 : 1; // radar bus, camera side - int bus_rdr_car = (hw_type == HW_TYPE_BLACK_PANDA) ? 0 : 2; // radar bus, car side + int bus_rdr_cam = (board_has_relay()) ? 2 : 1; // radar bus, camera side + int bus_rdr_car = (board_has_relay()) ? 0 : 2; // radar bus, car side if (bus_num == bus_rdr_car) { bus_fwd = bus_rdr_cam; @@ -231,7 +231,6 @@ const safety_hooks honda_hooks = { .rx = honda_rx_hook, .tx = honda_tx_hook, .tx_lin = nooutput_tx_lin_hook, - .ignition = default_ign_hook, .fwd = honda_fwd_hook, }; @@ -240,6 +239,5 @@ const safety_hooks honda_bosch_hooks = { .rx = honda_rx_hook, .tx = honda_tx_hook, .tx_lin = nooutput_tx_lin_hook, - .ignition = default_ign_hook, .fwd = honda_bosch_fwd_hook, }; diff --git a/panda/board/safety/safety_hyundai.h b/panda/board/safety/safety_hyundai.h index aed30621f44b00..21796e4caaf128 100644 --- a/panda/board/safety/safety_hyundai.h +++ b/panda/board/safety/safety_hyundai.h @@ -155,6 +155,5 @@ const safety_hooks hyundai_hooks = { .rx = hyundai_rx_hook, .tx = hyundai_tx_hook, .tx_lin = nooutput_tx_lin_hook, - .ignition = default_ign_hook, .fwd = hyundai_fwd_hook, }; diff --git a/panda/board/safety/safety_mazda.h b/panda/board/safety/safety_mazda.h index 63fbcdfd6f919f..60d8b2bda9b16a 100644 --- a/panda/board/safety/safety_mazda.h +++ b/panda/board/safety/safety_mazda.h @@ -164,6 +164,5 @@ const safety_hooks mazda_hooks = { .rx = mazda_rx_hook, .tx = mazda_tx_hook, .tx_lin = nooutput_tx_lin_hook, - .ignition = default_ign_hook, .fwd = mazda_fwd_hook, }; diff --git a/panda/board/safety/safety_subaru.h b/panda/board/safety/safety_subaru.h index 5b482973e6ec2f..c09b9d6225ed19 100644 --- a/panda/board/safety/safety_subaru.h +++ b/panda/board/safety/safety_subaru.h @@ -124,6 +124,5 @@ const safety_hooks subaru_hooks = { .rx = subaru_rx_hook, .tx = subaru_tx_hook, .tx_lin = nooutput_tx_lin_hook, - .ignition = default_ign_hook, .fwd = subaru_fwd_hook, }; diff --git a/panda/board/safety/safety_tesla.h b/panda/board/safety/safety_tesla.h index 188b12ac481dfc..2e5d20c622826e 100644 --- a/panda/board/safety/safety_tesla.h +++ b/panda/board/safety/safety_tesla.h @@ -39,9 +39,6 @@ int tesla_gas_prev = 0; int tesla_speed = 0; int eac_status = 0; -int tesla_ignition_started = 0; - - void set_gmlan_digital_output(int to_set); void reset_gmlan_switch_timeout(void); void gmlan_switch_init(int timeout_enable); @@ -66,13 +63,6 @@ static void tesla_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { } } - // Detect drive rail on (ignition) (start recording) - if (addr == 0x348) { - // GTW_status - int drive_rail_on = GET_BYTE(to_push, 0) & 0x1; - tesla_ignition_started = drive_rail_on == 1; - } - // exit controls on brake press // DI_torque2::DI_brakePedal 0x118 if (addr == 0x118) { @@ -183,14 +173,9 @@ static int tesla_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { static void tesla_init(int16_t param) { UNUSED(param); controls_allowed = 0; - tesla_ignition_started = 0; gmlan_switch_init(1); //init the gmlan switch with 1s timeout enabled } -static int tesla_ign_hook(void) { - return tesla_ignition_started; -} - static int tesla_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) { int bus_fwd = -1; @@ -224,6 +209,5 @@ const safety_hooks tesla_hooks = { .rx = tesla_rx_hook, .tx = tesla_tx_hook, .tx_lin = nooutput_tx_lin_hook, - .ignition = tesla_ign_hook, .fwd = tesla_fwd_hook, }; diff --git a/panda/board/safety/safety_toyota.h b/panda/board/safety/safety_toyota.h index a6304b8393f6ce..866ae177f47fbe 100644 --- a/panda/board/safety/safety_toyota.h +++ b/panda/board/safety/safety_toyota.h @@ -13,8 +13,8 @@ const int TOYOTA_MAX_RT_DELTA = 375; // max delta torque allowed for real t const uint32_t TOYOTA_RT_INTERVAL = 250000; // 250ms between real time checks // longitudinal limits -const int TOYOTA_MAX_ACCEL = 3000; // 3.0 m/s2 -const int TOYOTA_MIN_ACCEL = -3000; // 3.0 m/s2 +const int TOYOTA_MAX_ACCEL = 3500; // 3.0 m/s2 +const int TOYOTA_MIN_ACCEL = -4000; // 3.0 m/s2 const int TOYOTA_GAS_INTERCEPTOR_THRESHOLD = 475; // ratio between offset and gain from dbc file @@ -232,6 +232,5 @@ const safety_hooks toyota_hooks = { .rx = toyota_rx_hook, .tx = toyota_tx_hook, .tx_lin = nooutput_tx_lin_hook, - .ignition = default_ign_hook, .fwd = toyota_fwd_hook, }; diff --git a/panda/board/safety/safety_toyota_ipas.h b/panda/board/safety/safety_toyota_ipas.h index 3e3a3b3a24134f..d5833e45db5544 100644 --- a/panda/board/safety/safety_toyota_ipas.h +++ b/panda/board/safety/safety_toyota_ipas.h @@ -164,6 +164,5 @@ const safety_hooks toyota_ipas_hooks = { .rx = toyota_ipas_rx_hook, .tx = toyota_ipas_tx_hook, .tx_lin = nooutput_tx_lin_hook, - .ignition = default_ign_hook, .fwd = toyota_fwd_hook, }; diff --git a/panda/board/safety/safety_volkswagen.h b/panda/board/safety/safety_volkswagen.h new file mode 100644 index 00000000000000..bb184cd91f5418 --- /dev/null +++ b/panda/board/safety/safety_volkswagen.h @@ -0,0 +1,167 @@ +const int VOLKSWAGEN_MAX_STEER = 250; // 2.5 Nm (EPS side max of 3.0Nm with fault if violated) +const int VOLKSWAGEN_MAX_RT_DELTA = 75; // 4 max rate up * 50Hz send rate * 250000 RT interval / 1000000 = 50 ; 50 * 1.5 for safety pad = 75 +const uint32_t VOLKSWAGEN_RT_INTERVAL = 250000; // 250ms between real time checks +const int VOLKSWAGEN_MAX_RATE_UP = 4; // 2.0 Nm/s available rate of change from the steering rack (EPS side delta-limit of 5.0 Nm/s) +const int VOLKSWAGEN_MAX_RATE_DOWN = 10; // 5.0 Nm/s available rate of change from the steering rack (EPS side delta-limit of 5.0 Nm/s) +const int VOLKSWAGEN_DRIVER_TORQUE_ALLOWANCE = 80; +const int VOLKSWAGEN_DRIVER_TORQUE_FACTOR = 3; + +struct sample_t volkswagen_torque_driver; // last few driver torques measured +int volkswagen_rt_torque_last = 0; +int volkswagen_desired_torque_last = 0; +uint32_t volkswagen_ts_last = 0; +int volkswagen_gas_prev = 0; + +// Safety-relevant CAN messages for the Volkswagen MQB platform. +#define MSG_EPS_01 0x09F +#define MSG_MOTOR_20 0x121 +#define MSG_ACC_06 0x122 +#define MSG_HCA_01 0x126 +#define MSG_GRA_ACC_01 0x12B +#define MSG_LDW_02 0x397 +#define MSG_KLEMMEN_STATUS_01 0x3C0 + +static void volkswagen_init(int16_t param) { + UNUSED(param); // May use param in the future to indicate MQB vs PQ35/PQ46/NMS vs MLB, or wiring configuration. + controls_allowed = 0; +} + +static void volkswagen_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { + int bus = GET_BUS(to_push); + int addr = GET_ADDR(to_push); + + // Update driver input torque samples from EPS_01.Driver_Strain for absolute torque, and EPS_01.Driver_Strain_VZ + // for the direction. + if ((bus == 0) && (addr == MSG_EPS_01)) { + int torque_driver_new = GET_BYTE(to_push, 5) | ((GET_BYTE(to_push, 6) & 0x1F) << 8); + int sign = (GET_BYTE(to_push, 6) & 0x80) >> 7; + if (sign == 1) { + torque_driver_new *= -1; + } + + update_sample(&volkswagen_torque_driver, torque_driver_new); + } + + // Monitor ACC_06.ACC_Status_ACC for stock ACC status. Because the current MQB port is lateral-only, OP's control + // allowed state is directly driven by stock ACC engagement. Permit the ACC message to come from either bus, in + // order to accommodate future camera-side integrations if needed. + if (addr == MSG_ACC_06) { + int acc_status = (GET_BYTE(to_push, 7) & 0x70) >> 4; + controls_allowed = ((acc_status == 3) || (acc_status == 4) || (acc_status == 5)) ? 1 : 0; + } + + // exit controls on rising edge of gas press. Bits [12-20) + if (addr == MSG_MOTOR_20) { + int gas = (GET_BYTES_04(to_push) >> 12) & 0xFF; + if ((gas > 0) && (volkswagen_gas_prev == 0) && long_controls_allowed) { + controls_allowed = 0; + } + volkswagen_gas_prev = gas; + } +} + +static int volkswagen_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { + int addr = GET_ADDR(to_send); + int bus = GET_BUS(to_send); + int tx = 1; + + // Safety check for HCA_01 Heading Control Assist torque. + if (addr == MSG_HCA_01) { + bool violation = false; + + int desired_torque = GET_BYTE(to_send, 2) | ((GET_BYTE(to_send, 3) & 0x3F) << 8); + int sign = (GET_BYTE(to_send, 3) & 0x80) >> 7; + if (sign == 1) { + desired_torque *= -1; + } + + uint32_t ts = TIM2->CNT; + + if (controls_allowed) { + + // *** global torque limit check *** + violation |= max_limit_check(desired_torque, VOLKSWAGEN_MAX_STEER, -VOLKSWAGEN_MAX_STEER); + + // *** torque rate limit check *** + violation |= driver_limit_check(desired_torque, volkswagen_desired_torque_last, &volkswagen_torque_driver, + VOLKSWAGEN_MAX_STEER, VOLKSWAGEN_MAX_RATE_UP, VOLKSWAGEN_MAX_RATE_DOWN, + VOLKSWAGEN_DRIVER_TORQUE_ALLOWANCE, VOLKSWAGEN_DRIVER_TORQUE_FACTOR); + volkswagen_desired_torque_last = desired_torque; + + // *** torque real time rate limit check *** + violation |= rt_rate_limit_check(desired_torque, volkswagen_rt_torque_last, VOLKSWAGEN_MAX_RT_DELTA); + + // every RT_INTERVAL set the new limits + uint32_t ts_elapsed = get_ts_elapsed(ts, volkswagen_ts_last); + if (ts_elapsed > VOLKSWAGEN_RT_INTERVAL) { + volkswagen_rt_torque_last = desired_torque; + volkswagen_ts_last = ts; + } + } + + // no torque if controls is not allowed + if (!controls_allowed && (desired_torque != 0)) { + violation = true; + } + + // reset to 0 if either controls is not allowed or there's a violation + if (violation || !controls_allowed) { + volkswagen_desired_torque_last = 0; + volkswagen_rt_torque_last = 0; + volkswagen_ts_last = ts; + } + + if (violation) { + tx = 0; + } + } + + // FORCE CANCEL: ensuring that only the cancel button press is sent when controls are off. + // This avoids unintended engagements while still allowing resume spam + if ((bus == 2) && (addr == MSG_GRA_ACC_01) && !controls_allowed) { + // disallow resume and set: bits 16 and 19 + if ((GET_BYTE(to_send, 2) & 0x9) != 0) { + tx = 0; + } + } + + // 1 allows the message through + return tx; +} + +static int volkswagen_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) { + int addr = GET_ADDR(to_fwd); + int bus_fwd = -1; + + // NOTE: Will need refactoring for other bus layouts, such as no-forwarding at camera or J533 running-gear CAN + + switch (bus_num) { + case 0: + // Forward all traffic from J533 gateway to Extended CAN devices. + bus_fwd = 2; + break; + case 2: + if ((addr == MSG_HCA_01) || (addr == MSG_LDW_02)) { + // OP takes control of the Heading Control Assist and Lane Departure Warning messages from the camera. + bus_fwd = -1; + } else { + // Forward all remaining traffic from Extended CAN devices to J533 gateway. + bus_fwd = 0; + } + break; + default: + // No other buses should be in use; fallback to do-not-forward. + bus_fwd = -1; + break; + } + + return bus_fwd; +} + +const safety_hooks volkswagen_hooks = { + .init = volkswagen_init, + .rx = volkswagen_rx_hook, + .tx = volkswagen_tx_hook, + .tx_lin = nooutput_tx_lin_hook, + .fwd = volkswagen_fwd_hook, +}; diff --git a/panda/board/safety_declarations.h b/panda/board/safety_declarations.h index 7e0a54d73e8231..efa6a4e2b8744c 100644 --- a/panda/board/safety_declarations.h +++ b/panda/board/safety_declarations.h @@ -14,7 +14,6 @@ struct lookup_t { void safety_rx_hook(CAN_FIFOMailBox_TypeDef *to_push); int safety_tx_hook(CAN_FIFOMailBox_TypeDef *to_send); int safety_tx_lin_hook(int lin_num, uint8_t *data, int len); -int safety_ignition_hook(void); uint32_t get_ts_elapsed(uint32_t ts, uint32_t ts_last); int to_signed(int d, int bits); void update_sample(struct sample_t *sample, int sample_new); @@ -31,12 +30,10 @@ typedef void (*safety_hook_init)(int16_t param); typedef void (*rx_hook)(CAN_FIFOMailBox_TypeDef *to_push); typedef int (*tx_hook)(CAN_FIFOMailBox_TypeDef *to_send); typedef int (*tx_lin_hook)(int lin_num, uint8_t *data, int len); -typedef int (*ign_hook)(void); typedef int (*fwd_hook)(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd); typedef struct { safety_hook_init init; - ign_hook ignition; rx_hook rx; tx_hook tx; tx_lin_hook tx_lin; diff --git a/panda/board/tools/enter_download_mode.py b/panda/board/tools/enter_download_mode.py index 3dd6545f4caffe..17d30dda1131e8 100755 --- a/panda/board/tools/enter_download_mode.py +++ b/panda/board/tools/enter_download_mode.py @@ -11,7 +11,7 @@ def enter_download_mode(device): try: handle.controlWrite(usb1.TYPE_VENDOR | usb1.RECIPIENT_DEVICE, 0xd1, 0, 0, b'') - except (usb1.USBErrorIO, usb1.USBErrorPipe) as e: + except (usb1.USBErrorIO, usb1.USBErrorPipe): print("Device download mode enabled.") time.sleep(1) else: diff --git a/panda/crypto/getcertheader.py b/panda/crypto/getcertheader.py index b323cd101d81b3..bbbe475ef8b000 100755 --- a/panda/crypto/getcertheader.py +++ b/panda/crypto/getcertheader.py @@ -1,6 +1,5 @@ #!/usr/bin/env python3 import sys -import struct from Crypto.PublicKey import RSA def egcd(a, b): diff --git a/panda/examples/can_bit_transition.py b/panda/examples/can_bit_transition.py index 1cd72a6831cde5..aa4aa9df95f010 100755 --- a/panda/examples/can_bit_transition.py +++ b/panda/examples/can_bit_transition.py @@ -1,6 +1,4 @@ #!/usr/bin/env python3 - -import binascii import csv import sys diff --git a/panda/examples/can_unique.py b/panda/examples/can_unique.py index 05f24a7d91d254..fdd586c3d3517d 100755 --- a/panda/examples/can_unique.py +++ b/panda/examples/can_unique.py @@ -13,10 +13,8 @@ # 0,344,c000c00000000000 -import binascii import csv import sys -from panda import Panda class Message(): """Details about a specific message ID.""" diff --git a/panda/examples/eps_read_software_ids.py b/panda/examples/eps_read_software_ids.py new file mode 100755 index 00000000000000..a3292207c7e90c --- /dev/null +++ b/panda/examples/eps_read_software_ids.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 +from panda import Panda +from panda.python.uds import UdsClient, NegativeResponseError, DATA_IDENTIFIER_TYPE + +if __name__ == "__main__": + address = 0x18da30f1 # Honda EPS + panda = Panda() + uds_client = UdsClient(panda, address, debug=False) + + print("tester present ...") + uds_client.tester_present() + + try: + print("") + print("read data by id: boot software id ...") + data = uds_client.read_data_by_identifier(DATA_IDENTIFIER_TYPE.BOOT_SOFTWARE_IDENTIFICATION) + print(data.decode('utf-8')) + except NegativeResponseError as e: + print(e) + + try: + print("") + print("read data by id: application software id ...") + data = uds_client.read_data_by_identifier(DATA_IDENTIFIER_TYPE.APPLICATION_SOFTWARE_IDENTIFICATION) + print(data.decode('utf-8')) + except NegativeResponseError as e: + print(e) + + try: + print("") + print("read data by id: application data id ...") + data = uds_client.read_data_by_identifier(DATA_IDENTIFIER_TYPE.APPLICATION_DATA_IDENTIFICATION) + print(data.decode('utf-8')) + except NegativeResponseError as e: + print(e) + + try: + print("") + print("read data by id: boot software fingerprint ...") + data = uds_client.read_data_by_identifier(DATA_IDENTIFIER_TYPE.BOOT_SOFTWARE_FINGERPRINT) + print(data.decode('utf-8')) + except NegativeResponseError as e: + print(e) + + try: + print("") + print("read data by id: application software fingerprint ...") + data = uds_client.read_data_by_identifier(DATA_IDENTIFIER_TYPE.APPLICATION_SOFTWARE_FINGERPRINT) + print(data.decode('utf-8')) + except NegativeResponseError as e: + print(e) + + try: + print("") + print("read data by id: application data fingerprint ...") + data = uds_client.read_data_by_identifier(DATA_IDENTIFIER_TYPE.APPLICATION_DATA_FINGERPRINT) + print(data.decode('utf-8')) + except NegativeResponseError as e: + print(e) diff --git a/panda/examples/get_panda_password.py b/panda/examples/get_panda_password.py index 13dacf25340c4b..54cbe57ec363a6 100644 --- a/panda/examples/get_panda_password.py +++ b/panda/examples/get_panda_password.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +import sys from panda import Panda def get_panda_password(): diff --git a/panda/examples/query_vin_and_stats.py b/panda/examples/query_vin_and_stats.py index 9a0df78ec1d05a..f8b5d9b2eb880a 100755 --- a/panda/examples/query_vin_and_stats.py +++ b/panda/examples/query_vin_and_stats.py @@ -8,9 +8,10 @@ # 0x7e0 = Toyota # 0x18DB33F1 for Honda? + def get_current_data_for_pid(pid): # 01 xx = Show current data - isotp_send(panda, "\x01"+chr(pid), 0x7e0) + isotp_send(panda, b"\x01"+ bytes([pid]), 0x7e0) return isotp_recv(panda, 0x7e8) def get_supported_pids(): @@ -33,15 +34,15 @@ def get_supported_pids(): panda.can_clear(0) # 09 02 = Get VIN - isotp_send(panda, "\x09\x02", 0x7df) + isotp_send(panda, b"\x09\x02", 0x7df) ret = isotp_recv(panda, 0x7e8) hexdump(ret) - print("VIN: %s" % ret[2:]) + print("VIN: %s" % "".join(map(chr, ret[:2]))) # 03 = get DTCS - isotp_send(panda, "\x03", 0x7e0) + isotp_send(panda, b"\x03", 0x7e0) dtcs = isotp_recv(panda, 0x7e8) - print("DTCs:", dtcs[2:].encode("hex")) + print("DTCs:", "".join(map(chr, dtcs[:2]))) supported_pids = get_supported_pids() print("Supported PIDs:",supported_pids) diff --git a/panda/examples/tesla_tester.py b/panda/examples/tesla_tester.py index 74f19f25528da7..9a77eb4edf502a 100644 --- a/panda/examples/tesla_tester.py +++ b/panda/examples/tesla_tester.py @@ -29,11 +29,11 @@ def tesla_tester(): # BDY 0x248 is the MCU_commands message, which includes folding mirrors, opening the trunk, frunk, setting the cars lock state and more. For our test, we will edit the 3rd byte, which is MCU_lockRequest. 0x01 will lock, 0x02 will unlock: print("Unlocking Tesla...") - p.can_send(0x248, "\x00\x00\x02\x00\x00\x00\x00\x00", body_bus_num) + p.can_send(0x248, b"\x00\x00\x02\x00\x00\x00\x00\x00", body_bus_num) #Or, we can set the first byte, MCU_frontHoodCommand + MCU_liftgateSwitch, to 0x01 to pop the frunk, or 0x04 to open/close the trunk (0x05 should open both) print("Opening Frunk...") - p.can_send(0x248, "\x01\x00\x00\x00\x00\x00\x00\x00", body_bus_num) + p.can_send(0x248, b"\x01\x00\x00\x00\x00\x00\x00\x00", body_bus_num) #Back to safety... print("Disabling output on Panda...") diff --git a/panda/python/__init__.py b/panda/python/__init__.py index 565770918a61e9..326128d3ec306a 100644 --- a/panda/python/__init__.py +++ b/panda/python/__init__.py @@ -1,5 +1,5 @@ # python library to interface with panda - +import datetime import binascii import struct import hashlib @@ -10,10 +10,10 @@ import traceback import subprocess from .dfu import PandaDFU -from .esptool import ESPROM, CesantaFlasher -from .flash_release import flash_release -from .update import ensure_st_up_to_date -from .serial import PandaSerial +from .esptool import ESPROM, CesantaFlasher # noqa: F401 +from .flash_release import flash_release # noqa: F401 +from .update import ensure_st_up_to_date # noqa: F401 +from .serial import PandaSerial # noqa: F401 from .isotp import isotp_send, isotp_recv __version__ = '0.0.9' @@ -27,10 +27,10 @@ def build_st(target, mkfile="Makefile"): from panda import BASEDIR cmd = 'cd %s && make -f %s clean && make -f %s %s >/dev/null' % (os.path.join(BASEDIR, "board"), mkfile, mkfile, target) try: - output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) - except subprocess.CalledProcessError as exception: - output = exception.output - returncode = exception.returncode + _ = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) + except subprocess.CalledProcessError: + #output = exception.output + #returncode = exception.returncode raise def parse_can_buffer(dat): @@ -122,8 +122,8 @@ class Panda(object): SAFETY_CHRYSLER = 9 SAFETY_TESLA = 10 SAFETY_SUBARU = 11 - SAFETY_GM_PASSIVE = 12 SAFETY_MAZDA = 13 + SAFETY_VOLKSWAGEN = 15 SAFETY_TOYOTA_IPAS = 16 SAFETY_ALLOUTPUT = 17 SAFETY_GM_ASCM = 18 @@ -144,6 +144,7 @@ class Panda(object): HW_TYPE_GREY_PANDA = b'\x02' HW_TYPE_BLACK_PANDA = b'\x03' HW_TYPE_PEDAL = b'\x04' + HW_TYPE_UNO = b'\x05' def __init__(self, serial=None, claim=True): self._serial = serial @@ -382,11 +383,14 @@ def is_grey(self): def is_black(self): return self.get_type() == Panda.HW_TYPE_BLACK_PANDA + def is_uno(self): + return self.get_type() == Panda.HW_TYPE_UNO + def get_serial(self): dat = self._handle.controlRead(Panda.REQUEST_IN, 0xd0, 0, 0, 0x20) hashsig, calc_hash = dat[0x1c:], hashlib.sha1(dat[0:0x1c]).digest()[0:4] assert(hashsig == calc_hash) - return [dat[0:0x10], dat[0x10:0x10+10]] + return [dat[0:0x10].decode("utf8"), dat[0x10:0x10+10].decode("utf8")] def get_secret(self): return self._handle.controlRead(Panda.REQUEST_IN, 0xd0, 1, 0, 0x10) @@ -557,7 +561,7 @@ def kline_drain(self, bus=2): def kline_ll_recv(self, cnt, bus=2): echo = bytearray() while len(echo) != cnt: - ret = str(self._handle.controlRead(Panda.REQUEST_OUT, 0xe0, bus, 0, cnt-len(echo))) + ret = self._handle.controlRead(Panda.REQUEST_OUT, 0xe0, bus, 0, cnt-len(echo)) if DEBUG and len(ret) > 0: print("kline recv: " + binascii.hexlify(ret)) echo += ret @@ -577,7 +581,7 @@ def get_checksum(dat): ts = x[i:i+0xf] if DEBUG: print("kline send: " + binascii.hexlify(ts)) - self._handle.bulkWrite(2, chr(bus).encode()+ts) + self._handle.bulkWrite(2, bytes([bus]) + ts) echo = self.kline_ll_recv(len(ts), bus=bus) if echo != ts: print("**** ECHO ERROR %d ****" % i) @@ -592,3 +596,31 @@ def kline_recv(self, bus=2): def send_heartbeat(self): self._handle.controlWrite(Panda.REQUEST_OUT, 0xf3, 0, 0, b'') + + # ******************* RTC ******************* + def set_datetime(self, dt): + self._handle.controlWrite(Panda.REQUEST_OUT, 0xa1, int(dt.year), 0, b'') + self._handle.controlWrite(Panda.REQUEST_OUT, 0xa2, int(dt.month), 0, b'') + self._handle.controlWrite(Panda.REQUEST_OUT, 0xa3, int(dt.day), 0, b'') + self._handle.controlWrite(Panda.REQUEST_OUT, 0xa4, int(dt.isoweekday()), 0, b'') + self._handle.controlWrite(Panda.REQUEST_OUT, 0xa5, int(dt.hour), 0, b'') + self._handle.controlWrite(Panda.REQUEST_OUT, 0xa6, int(dt.minute), 0, b'') + self._handle.controlWrite(Panda.REQUEST_OUT, 0xa7, int(dt.second), 0, b'') + + def get_datetime(self): + dat = self._handle.controlRead(Panda.REQUEST_IN, 0xa0, 0, 0, 8) + a = struct.unpack("HBBBBBB", dat) + return datetime.datetime(a[0], a[1], a[2], a[4], a[5], a[6]) + + # ******************* IR ******************* + def set_ir_power(self, percentage): + self._handle.controlWrite(Panda.REQUEST_OUT, 0xb0, int(percentage), 0, b'') + + # ******************* Fan ****************** + def set_fan_power(self, percentage): + self._handle.controlWrite(Panda.REQUEST_OUT, 0xb1, int(percentage), 0, b'') + + def get_fan_rpm(self): + dat = self._handle.controlRead(Panda.REQUEST_IN, 0xb2, 0, 0, 2) + a = struct.unpack("H", dat) + return a[0] \ No newline at end of file diff --git a/panda/python/dfu.py b/panda/python/dfu.py index bbab812b0709ea..d9d619a822de80 100644 --- a/panda/python/dfu.py +++ b/panda/python/dfu.py @@ -1,8 +1,6 @@ - import os import usb1 import struct -import time import binascii # *** DFU mode *** @@ -116,6 +114,6 @@ def reset(self): self.status() try: self._handle.controlWrite(0x21, DFU_DNLOAD, 2, 0, b"") - stat = str(self._handle.controlRead(0x21, DFU_GETSTATUS, 0, 0, 6)) + _ = str(self._handle.controlRead(0x21, DFU_GETSTATUS, 0, 0, 6)) except Exception: pass diff --git a/panda/python/esptool.py b/panda/python/esptool.py index 941c3557c8a00c..74e383eb08600c 100755 --- a/panda/python/esptool.py +++ b/panda/python/esptool.py @@ -29,7 +29,7 @@ import sys import tempfile import time -import traceback +#import traceback import usb1 __version__ = "1.2" @@ -44,7 +44,7 @@ def __init__(self, serial=None): @property def baudrate(self): - return self._baudrate + return self.baudrate @baudrate.setter def baudrate(self, x): @@ -434,7 +434,7 @@ def append_checksum(self, f, checksum): def write_v1_header(self, f, segments): f.write(struct.pack('>8)) + chr(len(x)&0xFF)).encode("utf8") + x[0:5] + ss = bytes([subaddr, 0x10 + (len(x) >> 8), len(x) & 0xFF]) + x[0:5] x = x[5:] else: - ss = (chr(0x10 + (len(x)>>8)) + chr(len(x)&0xFF)).encode("utf8") + x[0:6] + ss = bytes([0x10 + (len(x) >> 8), len(x) & 0xFF]) + x[0:6] x = x[6:] idx = 1 sends = [] while len(x) > 0: if subaddr: - sends.append((((chr(subaddr) + chr(0x20 + (idx&0xF))).encode('utf8') + x[0:6]).ljust(8, b"\x00"))) + sends.append(((bytes([subaddr, 0x20 + (idx & 0xF)]) + x[0:6]).ljust(8, b"\x00"))) x = x[6:] else: - sends.append(((chr(0x20 + (idx&0xF)).encode("utf8") + x[0:7]).ljust(8, b"\x00"))) + sends.append(((bytes([0x20 + (idx & 0xF)]) + x[0:7]).ljust(8, b"\x00"))) x = x[7:] idx += 1 @@ -107,7 +107,7 @@ def isotp_recv(panda, addr, bus=0, sendaddr=None, subaddr=None): else: msg = recv(panda, 1, addr, bus)[0] - if msg[0]&0xf0 == 0x10: + if msg[0] & 0xf0 == 0x10: # first tlen = ((msg[0] & 0xf) << 8) | msg[1] dat = msg[2:] @@ -122,7 +122,7 @@ def isotp_recv(panda, addr, bus=0, sendaddr=None, subaddr=None): assert mm[0] == (0x20 | (idx&0xF)) dat += mm[1:] idx += 1 - elif msg[0]&0xf0 == 0x00: + elif msg[0] & 0xf0 == 0x00: # single tlen = msg[0] & 0xf dat = msg[1:] diff --git a/panda/python/serial.py b/panda/python/serial.py index 72ab3de92b6752..4d900cf29f6610 100644 --- a/panda/python/serial.py +++ b/panda/python/serial.py @@ -19,10 +19,7 @@ def read(self, l=1): def write(self, dat): #print "W: ", dat.encode("hex") #print ' pigeon_send("' + ''.join(map(lambda x: "\\x%02X" % ord(x), dat)) + '");' - if(isinstance(dat, bytes)): - return self.panda.serial_write(self.port, dat) - else: - return self.panda.serial_write(self.port, str.encode(dat)) + return self.panda.serial_write(self.port, dat) def close(self): pass diff --git a/panda/python/uds.py b/panda/python/uds.py new file mode 100644 index 00000000000000..5f5ae53bfbac01 --- /dev/null +++ b/panda/python/uds.py @@ -0,0 +1,770 @@ +#!/usr/bin/env python3 +import time +import struct +from typing import NamedTuple, List +from enum import IntEnum +from queue import Queue, Empty +from threading import Thread +from binascii import hexlify + +class SERVICE_TYPE(IntEnum): + DIAGNOSTIC_SESSION_CONTROL = 0x10 + ECU_RESET = 0x11 + SECURITY_ACCESS = 0x27 + COMMUNICATION_CONTROL = 0x28 + TESTER_PRESENT = 0x3E + ACCESS_TIMING_PARAMETER = 0x83 + SECURED_DATA_TRANSMISSION = 0x84 + CONTROL_DTC_SETTING = 0x85 + RESPONSE_ON_EVENT = 0x86 + LINK_CONTROL = 0x87 + READ_DATA_BY_IDENTIFIER = 0x22 + READ_MEMORY_BY_ADDRESS = 0x23 + READ_SCALING_DATA_BY_IDENTIFIER = 0x24 + READ_DATA_BY_PERIODIC_IDENTIFIER = 0x2A + DYNAMICALLY_DEFINE_DATA_IDENTIFIER = 0x2C + WRITE_DATA_BY_IDENTIFIER = 0x2E + WRITE_MEMORY_BY_ADDRESS = 0x3D + CLEAR_DIAGNOSTIC_INFORMATION = 0x14 + READ_DTC_INFORMATION = 0x19 + INPUT_OUTPUT_CONTROL_BY_IDENTIFIER = 0x2F + ROUTINE_CONTROL = 0x31 + REQUEST_DOWNLOAD = 0x34 + REQUEST_UPLOAD = 0x35 + TRANSFER_DATA = 0x36 + REQUEST_TRANSFER_EXIT = 0x37 + +class SESSION_TYPE(IntEnum): + DEFAULT = 1 + PROGRAMMING = 2 + EXTENDED_DIAGNOSTIC = 3 + SAFETY_SYSTEM_DIAGNOSTIC = 4 + +class RESET_TYPE(IntEnum): + HARD = 1 + KEY_OFF_ON = 2 + SOFT = 3 + ENABLE_RAPID_POWER_SHUTDOWN = 4 + DISABLE_RAPID_POWER_SHUTDOWN = 5 + +class ACCESS_TYPE(IntEnum): + REQUEST_SEED = 1 + SEND_KEY = 2 + +class CONTROL_TYPE(IntEnum): + ENABLE_RX_ENABLE_TX = 0 + ENABLE_RX_DISABLE_TX = 1 + DISABLE_RX_ENABLE_TX = 2 + DISABLE_RX_DISABLE_TX = 3 + +class MESSAGE_TYPE(IntEnum): + NORMAL = 1 + NETWORK_MANAGEMENT = 2 + NORMAL_AND_NETWORK_MANAGEMENT = 3 + +class TIMING_PARAMETER_TYPE(IntEnum): + READ_EXTENDED_SET = 1 + SET_TO_DEFAULT_VALUES = 2 + READ_CURRENTLY_ACTIVE = 3 + SET_TO_GIVEN_VALUES = 4 + +class DTC_SETTING_TYPE(IntEnum): + ON = 1 + OFF = 2 + +class RESPONSE_EVENT_TYPE(IntEnum): + STOP_RESPONSE_ON_EVENT = 0 + ON_DTC_STATUS_CHANGE = 1 + ON_TIMER_INTERRUPT = 2 + ON_CHANGE_OF_DATA_IDENTIFIER = 3 + REPORT_ACTIVATED_EVENTS = 4 + START_RESPONSE_ON_EVENT = 5 + CLEAR_RESPONSE_ON_EVENT = 6 + ON_COMPARISON_OF_VALUES = 7 + +class LINK_CONTROL_TYPE(IntEnum): + VERIFY_BAUDRATE_TRANSITION_WITH_FIXED_BAUDRATE = 1 + VERIFY_BAUDRATE_TRANSITION_WITH_SPECIFIC_BAUDRATE = 2 + TRANSITION_BAUDRATE = 3 + +class BAUD_RATE_TYPE(IntEnum): + PC9600 = 1 + PC19200 = 2 + PC38400 = 3 + PC57600 = 4 + PC115200 = 5 + CAN125000 = 16 + CAN250000 = 17 + CAN500000 = 18 + CAN1000000 = 19 + +class DATA_IDENTIFIER_TYPE(IntEnum): + BOOT_SOFTWARE_IDENTIFICATION = 0xF180 + APPLICATION_SOFTWARE_IDENTIFICATION = 0xF181 + APPLICATION_DATA_IDENTIFICATION = 0xF182 + BOOT_SOFTWARE_FINGERPRINT = 0xF183 + APPLICATION_SOFTWARE_FINGERPRINT = 0xF184 + APPLICATION_DATA_FINGERPRINT = 0xF185 + ACTIVE_DIAGNOSTIC_SESSION = 0xF186 + VEHICLE_MANUFACTURER_SPARE_PART_NUMBER = 0xF187 + VEHICLE_MANUFACTURER_ECU_SOFTWARE_NUMBER = 0xF188 + VEHICLE_MANUFACTURER_ECU_SOFTWARE_VERSION_NUMBER = 0xF189 + SYSTEM_SUPPLIER_IDENTIFIER = 0xF18A + ECU_MANUFACTURING_DATE = 0xF18B + ECU_SERIAL_NUMBER = 0xF18C + SUPPORTED_FUNCTIONAL_UNITS = 0xF18D + VEHICLE_MANUFACTURER_KIT_ASSEMBLY_PART_NUMBER = 0xF18E + VIN = 0xF190 + VEHICLE_MANUFACTURER_ECU_HARDWARE_NUMBER = 0xF191 + SYSTEM_SUPPLIER_ECU_HARDWARE_NUMBER = 0xF192 + SYSTEM_SUPPLIER_ECU_HARDWARE_VERSION_NUMBER = 0xF193 + SYSTEM_SUPPLIER_ECU_SOFTWARE_NUMBER = 0xF194 + SYSTEM_SUPPLIER_ECU_SOFTWARE_VERSION_NUMBER = 0xF195 + EXHAUST_REGULATION_OR_TYPE_APPROVAL_NUMBER = 0xF196 + SYSTEM_NAME_OR_ENGINE_TYPE = 0xF197 + REPAIR_SHOP_CODE_OR_TESTER_SERIAL_NUMBER = 0xF198 + PROGRAMMING_DATE = 0xF199 + CALIBRATION_REPAIR_SHOP_CODE_OR_CALIBRATION_EQUIPMENT_SERIAL_NUMBER = 0xF19A + CALIBRATION_DATE = 0xF19B + CALIBRATION_EQUIPMENT_SOFTWARE_NUMBER = 0xF19C + ECU_INSTALLATION_DATE = 0xF19D + ODX_FILE = 0xF19E + ENTITY = 0xF19F + +class TRANSMISSION_MODE_TYPE(IntEnum): + SEND_AT_SLOW_RATE = 1 + SEND_AT_MEDIUM_RATE = 2 + SEND_AT_FAST_RATE = 3 + STOP_SENDING = 4 + +class DYNAMIC_DEFINITION_TYPE(IntEnum): + DEFINE_BY_IDENTIFIER = 1 + DEFINE_BY_MEMORY_ADDRESS = 2 + CLEAR_DYNAMICALLY_DEFINED_DATA_IDENTIFIER = 3 + +class DynamicSourceDefinition(NamedTuple): + data_identifier: int + position: int + memory_size: int + memory_address: int + +class DTC_GROUP_TYPE(IntEnum): + EMISSIONS = 0x000000 + ALL = 0xFFFFFF + +class DTC_REPORT_TYPE(IntEnum): + NUMBER_OF_DTC_BY_STATUS_MASK = 0x01 + DTC_BY_STATUS_MASK = 0x02 + DTC_SNAPSHOT_IDENTIFICATION = 0x03 + DTC_SNAPSHOT_RECORD_BY_DTC_NUMBER = 0x04 + DTC_SNAPSHOT_RECORD_BY_RECORD_NUMBER = 0x05 + DTC_EXTENDED_DATA_RECORD_BY_DTC_NUMBER = 0x06 + NUMBER_OF_DTC_BY_SEVERITY_MASK_RECORD = 0x07 + DTC_BY_SEVERITY_MASK_RECORD = 0x08 + SEVERITY_INFORMATION_OF_DTC = 0x09 + SUPPORTED_DTC = 0x0A + FIRST_TEST_FAILED_DTC = 0x0B + FIRST_CONFIRMED_DTC = 0x0C + MOST_RECENT_TEST_FAILED_DTC = 0x0D + MOST_RECENT_CONFIRMED_DTC = 0x0E + MIRROR_MEMORY_DTC_BY_STATUS_MASK = 0x0F + MIRROR_MEMORY_DTC_EXTENDED_DATA_RECORD_BY_DTC_NUMBER = 0x10 + NUMBER_OF_MIRROR_MEMORY_DTC_BY_STATUS_MASK = 0x11 + NUMBER_OF_EMISSIONS_RELATED_OBD_DTC_BY_STATUS_MASK = 0x12 + EMISSIONS_RELATED_OBD_DTC_BY_STATUS_MASK = 0x13 + DTC_FAULT_DETECTION_COUNTER = 0x14 + DTC_WITH_PERMANENT_STATUS = 0x15 + +class DTC_STATUS_MASK_TYPE(IntEnum): + TEST_FAILED = 0x01 + TEST_FAILED_THIS_OPERATION_CYCLE = 0x02 + PENDING_DTC = 0x04 + CONFIRMED_DTC = 0x08 + TEST_NOT_COMPLETED_SINCE_LAST_CLEAR = 0x10 + TEST_FAILED_SINCE_LAST_CLEAR = 0x20 + TEST_NOT_COMPLETED_THIS_OPERATION_CYCLE = 0x40 + WARNING_INDICATOR_REQUESTED = 0x80 + ALL = 0xFF + +class DTC_SEVERITY_MASK_TYPE(IntEnum): + MAINTENANCE_ONLY = 0x20 + CHECK_AT_NEXT_HALT = 0x40 + CHECK_IMMEDIATELY = 0x80 + ALL = 0xE0 + +class CONTROL_PARAMETER_TYPE(IntEnum): + RETURN_CONTROL_TO_ECU = 0 + RESET_TO_DEFAULT = 1 + FREEZE_CURRENT_STATE = 2 + SHORT_TERM_ADJUSTMENT = 3 + +class ROUTINE_CONTROL_TYPE(IntEnum): + START = 1 + STOP = 2 + REQUEST_RESULTS = 3 + +class ROUTINE_IDENTIFIER_TYPE(IntEnum): + ERASE_MEMORY = 0xFF00 + CHECK_PROGRAMMING_DEPENDENCIES = 0xFF01 + ERASE_MIRROR_MEMORY_DTCS = 0xFF02 + +class MessageTimeoutError(Exception): + pass + +class NegativeResponseError(Exception): + def __init__(self, message, service_id, error_code): + self.message = message + self.service_id = service_id + self.error_code = error_code + + def __str__(self): + return self.message + +class InvalidServiceIdError(Exception): + pass + +class InvalidSubFunctioneError(Exception): + pass + +_negative_response_codes = { + 0x00: 'positive response', + 0x10: 'general reject', + 0x11: 'service not supported', + 0x12: 'sub-function not supported', + 0x13: 'incorrect message length or invalid format', + 0x14: 'response too long', + 0x21: 'busy repeat request', + 0x22: 'conditions not correct', + 0x24: 'request sequence error', + 0x25: 'no response from subnet component', + 0x26: 'failure prevents execution of requested action', + 0x31: 'request out of range', + 0x33: 'security access denied', + 0x35: 'invalid key', + 0x36: 'exceed numebr of attempts', + 0x37: 'required time delay not expired', + 0x70: 'upload download not accepted', + 0x71: 'transfer data suspended', + 0x72: 'general programming failure', + 0x73: 'wrong block sequence counter', + 0x78: 'request correctly received - response pending', + 0x7e: 'sub-function not supported in active session', + 0x7f: 'service not supported in active session', + 0x81: 'rpm too high', + 0x82: 'rpm too low', + 0x83: 'engine is running', + 0x84: 'engine is not running', + 0x85: 'engine run time too low', + 0x86: 'temperature too high', + 0x87: 'temperature too low', + 0x88: 'vehicle speed too high', + 0x89: 'vehicle speed too low', + 0x8a: 'throttle/pedal too high', + 0x8b: 'throttle/pedal too low', + 0x8c: 'transmission not in neutral', + 0x8d: 'transmission not in gear', + 0x8f: 'brake switch(es) not closed', + 0x90: 'shifter lever not in park', + 0x91: 'torque converter clutch locked', + 0x92: 'voltage too high', + 0x93: 'voltage too low', +} + +class IsoTpMessage(): + def __init__(self, can_tx_queue: Queue, can_rx_queue: Queue, timeout: float, debug: bool=False): + self.can_tx_queue = can_tx_queue + self.can_rx_queue = can_rx_queue + self.timeout = timeout + self.debug = debug + + def send(self, dat: bytes) -> None: + self.tx_dat = dat + self.tx_len = len(dat) + self.tx_idx = 0 + self.tx_done = False + + if self.debug: print(f"ISO-TP: REQUEST - {hexlify(self.tx_dat)}") + self._tx_first_frame() + + def _tx_first_frame(self) -> None: + if self.tx_len < 8: + # single frame (send all bytes) + if self.debug: print("ISO-TP: TX - single frame") + msg = (bytes([self.tx_len]) + self.tx_dat).ljust(8, b"\x00") + self.tx_done = True + else: + # first frame (send first 6 bytes) + if self.debug: print("ISO-TP: TX - first frame") + msg = (struct.pack("!H", 0x1000 | self.tx_len) + self.tx_dat[:6]).ljust(8, b"\x00") + self.can_tx_queue.put(msg) + + def recv(self) -> bytes: + self.rx_dat = b"" + self.rx_len = 0 + self.rx_idx = 0 + self.rx_done = False + + try: + while True: + self._isotp_rx_next() + if self.tx_done and self.rx_done: + return self.rx_dat + except Empty: + raise MessageTimeoutError("timeout waiting for response") + finally: + if self.debug: print(f"ISO-TP: RESPONSE - {hexlify(self.rx_dat)}") + + def _isotp_rx_next(self) -> None: + rx_data = self.can_rx_queue.get(block=True, timeout=self.timeout) + + # single rx_frame + if rx_data[0] >> 4 == 0x0: + self.rx_len = rx_data[0] & 0xFF + self.rx_dat = rx_data[1:1+self.rx_len] + self.rx_idx = 0 + self.rx_done = True + if self.debug: print(f"ISO-TP: RX - single frame - idx={self.rx_idx} done={self.rx_done}") + return + + # first rx_frame + if rx_data[0] >> 4 == 0x1: + self.rx_len = ((rx_data[0] & 0x0F) << 8) + rx_data[1] + self.rx_dat = rx_data[2:] + self.rx_idx = 0 + self.rx_done = False + if self.debug: print(f"ISO-TP: RX - first frame - idx={self.rx_idx} done={self.rx_done}") + if self.debug: print(f"ISO-TP: TX - flow control continue") + # send flow control message (send all bytes) + msg = b"\x30\x00\x00".ljust(8, b"\x00") + self.can_tx_queue.put(msg) + return + + # consecutive rx frame + if rx_data[0] >> 4 == 0x2: + assert self.rx_done == False, "isotp - rx: consecutive frame with no active frame" + self.rx_idx += 1 + assert self.rx_idx & 0xF == rx_data[0] & 0xF, "isotp - rx: invalid consecutive frame index" + rx_size = self.rx_len - len(self.rx_dat) + self.rx_dat += rx_data[1:1+min(rx_size, 7)] + if self.rx_len == len(self.rx_dat): + self.rx_done = True + if self.debug: print(f"ISO-TP: RX - consecutive frame - idx={self.rx_idx} done={self.rx_done}") + return + + # flow control + if rx_data[0] >> 4 == 0x3: + assert self.tx_done == False, "isotp - rx: flow control with no active frame" + assert rx_data[0] != 0x32, "isotp - rx: flow-control overflow/abort" + assert rx_data[0] == 0x30 or rx_data[0] == 0x31, "isotp - rx: flow-control transfer state indicator invalid" + if rx_data[0] == 0x30: + if self.debug: print("ISO-TP: RX - flow control continue") + delay_ts = rx_data[2] & 0x7F + # scale is 1 milliseconds if first bit == 0, 100 micro seconds if first bit == 1 + delay_div = 1000. if rx_data[2] & 0x80 == 0 else 10000. + # first frame = 6 bytes, each consecutive frame = 7 bytes + start = 6 + self.tx_idx * 7 + count = rx_data[1] + end = start + count * 7 if count > 0 else self.tx_len + for i in range(start, end, 7): + if delay_ts > 0 and i > start: + delay_s = delay_ts / delay_div + if self.debug: print(f"ISO-TP: TX - delay - seconds={delay_s}") + time.sleep(delay_s) + self.tx_idx += 1 + # consecutive tx frames + msg = (bytes([0x20 | (self.tx_idx & 0xF)]) + self.tx_dat[i:i+7]).ljust(8, b"\x00") + self.can_tx_queue.put(msg) + if end >= self.tx_len: + self.tx_done = True + if self.debug: print(f"ISO-TP: TX - consecutive frame - idx={self.tx_idx} done={self.tx_done}") + elif rx_data[0] == 0x31: + # wait (do nothing until next flow control message) + if self.debug: print("ISO-TP: TX - flow control wait") + +class UdsClient(): + def __init__(self, panda, tx_addr: int, rx_addr: int=None, bus: int=0, timeout: float=10, debug: bool=False): + self.panda = panda + self.bus = bus + self.tx_addr = tx_addr + if rx_addr == None: + if tx_addr < 0xFFF8: + # standard 11 bit response addr (add 8) + self.rx_addr = tx_addr+8 + elif tx_addr > 0x10000000 and tx_addr < 0xFFFFFFFF: + # standard 29 bit response addr (flip last two bytes) + self.rx_addr = (tx_addr & 0xFFFF0000) + (tx_addr<<8 & 0xFF00) + (tx_addr>>8 & 0xFF) + else: + raise ValueError("invalid tx_addr: {}".format(tx_addr)) + + self.can_tx_queue = Queue() + self.can_rx_queue = Queue() + self.timeout = timeout + self.debug = debug + + self.can_thread = Thread(target=self._can_thread, args=(self.debug,)) + self.can_thread.daemon = True + self.can_thread.start() + + def _can_thread(self, debug: bool=False): + try: + # allow all output + self.panda.set_safety_mode(0x1337) + # clear tx buffer + self.panda.can_clear(self.bus) + # clear rx buffer + self.panda.can_clear(0xFFFF) + + while True: + # send + while not self.can_tx_queue.empty(): + msg = self.can_tx_queue.get(block=False) + if debug: print("CAN-TX: {} - {}".format(hex(self.tx_addr), hexlify(msg))) + self.panda.can_send(self.tx_addr, msg, self.bus) + + # receive + msgs = self.panda.can_recv() + for rx_addr, rx_ts, rx_data, rx_bus in msgs: + if rx_bus != self.bus or rx_addr != self.rx_addr or len(rx_data) == 0: + continue + if debug: print("CAN-RX: {} - {}".format(hex(self.rx_addr), hexlify(rx_data))) + self.can_rx_queue.put(rx_data) + else: + time.sleep(0.01) + finally: + self.panda.close() + + # generic uds request + def _uds_request(self, service_type: SERVICE_TYPE, subfunction: int=None, data: bytes=None) -> bytes: + req = bytes([service_type]) + if subfunction is not None: + req += bytes([subfunction]) + if data is not None: + req += data + + # send request, wait for response + isotp_msg = IsoTpMessage(self.can_tx_queue, self.can_rx_queue, self.timeout, self.debug) + isotp_msg.send(req) + while True: + resp = isotp_msg.recv() + resp_sid = resp[0] if len(resp) > 0 else None + + # negative response + if resp_sid == 0x7F: + service_id = resp[1] if len(resp) > 1 else -1 + try: + service_desc = SERVICE_TYPE(service_id).name + except Exception: + service_desc = 'NON_STANDARD_SERVICE' + error_code = resp[2] if len(resp) > 2 else -1 + try: + error_desc = _negative_response_codes[error_code] + except Exception: + error_desc = resp[3:] + # wait for another message if response pending + if error_code == 0x78: + if self.debug: print("UDS-RX: response pending") + continue + raise NegativeResponseError('{} - {}'.format(service_desc, error_desc), service_id, error_code) + + # positive response + if service_type+0x40 != resp_sid: + resp_sid_hex = hex(resp_sid) if resp_sid is not None else None + raise InvalidServiceIdError('invalid response service id: {}'.format(resp_sid_hex)) + + if subfunction is not None: + resp_sfn = resp[1] if len(resp) > 1 else None + if subfunction != resp_sfn: + resp_sfn_hex = hex(resp_sfn) if resp_sfn is not None else None + raise InvalidSubFunctioneError('invalid response subfunction: {}'.format(hex(resp_sfn_hex))) + + # return data (exclude service id and sub-function id) + return resp[(1 if subfunction is None else 2):] + + # services + def diagnostic_session_control(self, session_type: SESSION_TYPE): + self._uds_request(SERVICE_TYPE.DIAGNOSTIC_SESSION_CONTROL, subfunction=session_type) + + def ecu_reset(self, reset_type: RESET_TYPE): + resp = self._uds_request(SERVICE_TYPE.ECU_RESET, subfunction=reset_type) + power_down_time = None + if reset_type == RESET_TYPE.ENABLE_RAPID_POWER_SHUTDOWN: + power_down_time = resp[0] + return power_down_time + + def security_access(self, access_type: ACCESS_TYPE, security_key: bytes=None): + request_seed = access_type % 2 != 0 + if request_seed and security_key is not None: + raise ValueError('security_key not allowed') + if not request_seed and security_key is None: + raise ValueError('security_key is missing') + resp = self._uds_request(SERVICE_TYPE.SECURITY_ACCESS, subfunction=access_type, data=security_key) + if request_seed: + security_seed = resp + return security_seed + + def communication_control(self, control_type: CONTROL_TYPE, message_type: MESSAGE_TYPE): + data = bytes([message_type]) + self._uds_request(SERVICE_TYPE.COMMUNICATION_CONTROL, subfunction=control_type, data=data) + + def tester_present(self, ): + self._uds_request(SERVICE_TYPE.TESTER_PRESENT, subfunction=0x00) + + def access_timing_parameter(self, timing_parameter_type: TIMING_PARAMETER_TYPE, parameter_values: bytes=None): + write_custom_values = timing_parameter_type == TIMING_PARAMETER_TYPE.SET_TO_GIVEN_VALUES + read_values = ( + timing_parameter_type == TIMING_PARAMETER_TYPE.READ_CURRENTLY_ACTIVE or + timing_parameter_type == TIMING_PARAMETER_TYPE.READ_EXTENDED_SET + ) + if not write_custom_values and parameter_values is not None: + raise ValueError('parameter_values not allowed') + if write_custom_values and parameter_values is None: + raise ValueError('parameter_values is missing') + resp = self._uds_request(SERVICE_TYPE.ACCESS_TIMING_PARAMETER, subfunction=timing_parameter_type, data=parameter_values) + if read_values: + # TODO: parse response into values? + parameter_values = resp + return parameter_values + + def secured_data_transmission(self, data: bytes): + # TODO: split data into multiple input parameters? + resp = self._uds_request(SERVICE_TYPE.SECURED_DATA_TRANSMISSION, subfunction=None, data=data) + # TODO: parse response into multiple output values? + return resp + + def control_dtc_setting(self, dtc_setting_type: DTC_SETTING_TYPE): + self._uds_request(SERVICE_TYPE.CONTROL_DTC_SETTING, subfunction=dtc_setting_type) + + def response_on_event(self, response_event_type: RESPONSE_EVENT_TYPE, store_event: bool, window_time: int, event_type_record: int, service_response_record: int): + if store_event: + response_event_type |= 0x20 + # TODO: split record parameters into arrays + data = bytes([window_time, event_type_record, service_response_record]) + resp = self._uds_request(SERVICE_TYPE.RESPONSE_ON_EVENT, subfunction=response_event_type, data=data) + + if response_event_type == RESPONSE_EVENT_TYPE.REPORT_ACTIVATED_EVENTS: + return { + "num_of_activated_events": resp[0], + "data": resp[1:], # TODO: parse the reset of response + } + + return { + "num_of_identified_events": resp[0], + "event_window_time": resp[1], + "data": resp[2:], # TODO: parse the reset of response + } + + def link_control(self, link_control_type: LINK_CONTROL_TYPE, baud_rate_type: BAUD_RATE_TYPE=None): + if link_control_type == LINK_CONTROL_TYPE.VERIFY_BAUDRATE_TRANSITION_WITH_FIXED_BAUDRATE: + # baud_rate_type = BAUD_RATE_TYPE + data = bytes([baud_rate_type]) + elif link_control_type == LINK_CONTROL_TYPE.VERIFY_BAUDRATE_TRANSITION_WITH_SPECIFIC_BAUDRATE: + # baud_rate_type = custom value (3 bytes big-endian) + data = struct.pack('!I', baud_rate_type)[1:] + else: + data = None + self._uds_request(SERVICE_TYPE.LINK_CONTROL, subfunction=link_control_type, data=data) + + def read_data_by_identifier(self, data_identifier_type: DATA_IDENTIFIER_TYPE): + # TODO: support list of identifiers + data = struct.pack('!H', data_identifier_type) + resp = self._uds_request(SERVICE_TYPE.READ_DATA_BY_IDENTIFIER, subfunction=None, data=data) + resp_id = struct.unpack('!H', resp[0:2])[0] if len(resp) >= 2 else None + if resp_id != data_identifier_type: + raise ValueError('invalid response data identifier: {}'.format(hex(resp_id))) + return resp[2:] + + def read_memory_by_address(self, memory_address: int, memory_size: int, memory_address_bytes: int=4, memory_size_bytes: int=1): + if memory_address_bytes < 1 or memory_address_bytes > 4: + raise ValueError('invalid memory_address_bytes: {}'.format(memory_address_bytes)) + if memory_size_bytes < 1 or memory_size_bytes > 4: + raise ValueError('invalid memory_size_bytes: {}'.format(memory_size_bytes)) + data = bytes([memory_size_bytes<<4 | memory_address_bytes]) + + if memory_address >= 1<<(memory_address_bytes*8): + raise ValueError('invalid memory_address: {}'.format(memory_address)) + data += struct.pack('!I', memory_address)[4-memory_address_bytes:] + if memory_size >= 1<<(memory_size_bytes*8): + raise ValueError('invalid memory_size: {}'.format(memory_size)) + data += struct.pack('!I', memory_size)[4-memory_size_bytes:] + + resp = self._uds_request(SERVICE_TYPE.READ_MEMORY_BY_ADDRESS, subfunction=None, data=data) + return resp + + def read_scaling_data_by_identifier(self, data_identifier_type: DATA_IDENTIFIER_TYPE): + data = struct.pack('!H', data_identifier_type) + resp = self._uds_request(SERVICE_TYPE.READ_SCALING_DATA_BY_IDENTIFIER, subfunction=None, data=data) + resp_id = struct.unpack('!H', resp[0:2])[0] if len(resp) >= 2 else None + if resp_id != data_identifier_type: + raise ValueError('invalid response data identifier: {}'.format(hex(resp_id))) + return resp[2:] # TODO: parse the response + + def read_data_by_periodic_identifier(self, transmission_mode_type: TRANSMISSION_MODE_TYPE, periodic_data_identifier: int): + # TODO: support list of identifiers + data = bytes([transmission_mode_type, periodic_data_identifier]) + self._uds_request(SERVICE_TYPE.READ_DATA_BY_PERIODIC_IDENTIFIER, subfunction=None, data=data) + + def dynamically_define_data_identifier(self, dynamic_definition_type: DYNAMIC_DEFINITION_TYPE, dynamic_data_identifier: int, source_definitions: List[DynamicSourceDefinition], memory_address_bytes: int=4, memory_size_bytes: int=1): + if memory_address_bytes < 1 or memory_address_bytes > 4: + raise ValueError('invalid memory_address_bytes: {}'.format(memory_address_bytes)) + if memory_size_bytes < 1 or memory_size_bytes > 4: + raise ValueError('invalid memory_size_bytes: {}'.format(memory_size_bytes)) + + data = struct.pack('!H', dynamic_data_identifier) + if dynamic_definition_type == DYNAMIC_DEFINITION_TYPE.DEFINE_BY_IDENTIFIER: + for s in source_definitions: + data += struct.pack('!H', s["data_identifier"]) + bytes([s["position"], s["memory_size"]]) + elif dynamic_definition_type == DYNAMIC_DEFINITION_TYPE.DEFINE_BY_MEMORY_ADDRESS: + data += bytes([memory_size_bytes<<4 | memory_address_bytes]) + for s in source_definitions: + if s["memory_address"] >= 1<<(memory_address_bytes*8): + raise ValueError('invalid memory_address: {}'.format(s["memory_address"])) + data += struct.pack('!I', s["memory_address"])[4-memory_address_bytes:] + if s["memory_size"] >= 1<<(memory_size_bytes*8): + raise ValueError('invalid memory_size: {}'.format(s["memory_size"])) + data += struct.pack('!I', s["memory_size"])[4-memory_size_bytes:] + elif dynamic_definition_type == DYNAMIC_DEFINITION_TYPE.CLEAR_DYNAMICALLY_DEFINED_DATA_IDENTIFIER: + pass + else: + raise ValueError('invalid dynamic identifier type: {}'.format(hex(dynamic_definition_type))) + self._uds_request(SERVICE_TYPE.DYNAMICALLY_DEFINE_DATA_IDENTIFIER, subfunction=dynamic_definition_type, data=data) + + def write_data_by_identifier(self, data_identifier_type: DATA_IDENTIFIER_TYPE, data_record: bytes): + data = struct.pack('!H', data_identifier_type) + data_record + resp = self._uds_request(SERVICE_TYPE.WRITE_DATA_BY_IDENTIFIER, subfunction=None, data=data) + resp_id = struct.unpack('!H', resp[0:2])[0] if len(resp) >= 2 else None + if resp_id != data_identifier_type: + raise ValueError('invalid response data identifier: {}'.format(hex(resp_id))) + + def write_memory_by_address(self, memory_address: int, memory_size: int, data_record: bytes, memory_address_bytes: int=4, memory_size_bytes: int=1): + if memory_address_bytes < 1 or memory_address_bytes > 4: + raise ValueError('invalid memory_address_bytes: {}'.format(memory_address_bytes)) + if memory_size_bytes < 1 or memory_size_bytes > 4: + raise ValueError('invalid memory_size_bytes: {}'.format(memory_size_bytes)) + data = bytes([memory_size_bytes<<4 | memory_address_bytes]) + + if memory_address >= 1<<(memory_address_bytes*8): + raise ValueError('invalid memory_address: {}'.format(memory_address)) + data += struct.pack('!I', memory_address)[4-memory_address_bytes:] + if memory_size >= 1<<(memory_size_bytes*8): + raise ValueError('invalid memory_size: {}'.format(memory_size)) + data += struct.pack('!I', memory_size)[4-memory_size_bytes:] + + data += data_record + self._uds_request(SERVICE_TYPE.WRITE_MEMORY_BY_ADDRESS, subfunction=0x00, data=data) + + def clear_diagnostic_information(self, dtc_group_type: DTC_GROUP_TYPE): + data = struct.pack('!I', dtc_group_type)[1:] # 3 bytes + self._uds_request(SERVICE_TYPE.CLEAR_DIAGNOSTIC_INFORMATION, subfunction=None, data=data) + + def read_dtc_information(self, dtc_report_type: DTC_REPORT_TYPE, dtc_status_mask_type: DTC_STATUS_MASK_TYPE=DTC_STATUS_MASK_TYPE.ALL, dtc_severity_mask_type: DTC_SEVERITY_MASK_TYPE=DTC_SEVERITY_MASK_TYPE.ALL, dtc_mask_record: int=0xFFFFFF, dtc_snapshot_record_num: int=0xFF, dtc_extended_record_num: int=0xFF): + data = b'' + # dtc_status_mask_type + if dtc_report_type == DTC_REPORT_TYPE.NUMBER_OF_DTC_BY_STATUS_MASK or \ + dtc_report_type == DTC_REPORT_TYPE.DTC_BY_STATUS_MASK or \ + dtc_report_type == DTC_REPORT_TYPE.MIRROR_MEMORY_DTC_BY_STATUS_MASK or \ + dtc_report_type == DTC_REPORT_TYPE.NUMBER_OF_MIRROR_MEMORY_DTC_BY_STATUS_MASK or \ + dtc_report_type == DTC_REPORT_TYPE.NUMBER_OF_EMISSIONS_RELATED_OBD_DTC_BY_STATUS_MASK or \ + dtc_report_type == DTC_REPORT_TYPE.EMISSIONS_RELATED_OBD_DTC_BY_STATUS_MASK: + data += bytes([dtc_status_mask_type]) + # dtc_mask_record + if dtc_report_type == DTC_REPORT_TYPE.DTC_SNAPSHOT_IDENTIFICATION or \ + dtc_report_type == DTC_REPORT_TYPE.DTC_SNAPSHOT_RECORD_BY_DTC_NUMBER or \ + dtc_report_type == DTC_REPORT_TYPE.DTC_EXTENDED_DATA_RECORD_BY_DTC_NUMBER or \ + dtc_report_type == DTC_REPORT_TYPE.MIRROR_MEMORY_DTC_EXTENDED_DATA_RECORD_BY_DTC_NUMBER or \ + dtc_report_type == DTC_REPORT_TYPE.SEVERITY_INFORMATION_OF_DTC: + data += struct.pack('!I', dtc_mask_record)[1:] # 3 bytes + # dtc_snapshot_record_num + if dtc_report_type == DTC_REPORT_TYPE.DTC_SNAPSHOT_IDENTIFICATION or \ + dtc_report_type == DTC_REPORT_TYPE.DTC_SNAPSHOT_RECORD_BY_DTC_NUMBER or \ + dtc_report_type == DTC_REPORT_TYPE.DTC_SNAPSHOT_RECORD_BY_RECORD_NUMBER: + data += ord(dtc_snapshot_record_num) + # dtc_extended_record_num + if dtc_report_type == DTC_REPORT_TYPE.DTC_EXTENDED_DATA_RECORD_BY_DTC_NUMBER or \ + dtc_report_type == DTC_REPORT_TYPE.MIRROR_MEMORY_DTC_EXTENDED_DATA_RECORD_BY_DTC_NUMBER: + data += bytes([dtc_extended_record_num]) + # dtc_severity_mask_type + if dtc_report_type == DTC_REPORT_TYPE.NUMBER_OF_DTC_BY_SEVERITY_MASK_RECORD or \ + dtc_report_type == DTC_REPORT_TYPE.DTC_BY_SEVERITY_MASK_RECORD: + data += bytes([dtc_severity_mask_type, dtc_status_mask_type]) + + resp = self._uds_request(SERVICE_TYPE.READ_DTC_INFORMATION, subfunction=dtc_report_type, data=data) + + # TODO: parse response + return resp + + def input_output_control_by_identifier(self, data_identifier_type: DATA_IDENTIFIER_TYPE, control_parameter_type: CONTROL_PARAMETER_TYPE, control_option_record: bytes, control_enable_mask_record: bytes=b''): + data = struct.pack('!H', data_identifier_type) + bytes([control_parameter_type]) + control_option_record + control_enable_mask_record + resp = self._uds_request(SERVICE_TYPE.INPUT_OUTPUT_CONTROL_BY_IDENTIFIER, subfunction=None, data=data) + resp_id = struct.unpack('!H', resp[0:2])[0] if len(resp) >= 2 else None + if resp_id != data_identifier_type: + raise ValueError('invalid response data identifier: {}'.format(hex(resp_id))) + return resp[2:] + + def routine_control(self, routine_control_type: ROUTINE_CONTROL_TYPE, routine_identifier_type: ROUTINE_IDENTIFIER_TYPE, routine_option_record: bytes=b''): + data = struct.pack('!H', routine_identifier_type) + routine_option_record + resp = self._uds_request(SERVICE_TYPE.ROUTINE_CONTROL, subfunction=routine_control_type, data=data) + resp_id = struct.unpack('!H', resp[0:2])[0] if len(resp) >= 2 else None + if resp_id != routine_identifier_type: + raise ValueError('invalid response routine identifier: {}'.format(hex(resp_id))) + return resp[2:] + + def request_download(self, memory_address: int, memory_size: int, memory_address_bytes: int=4, memory_size_bytes: int=4, data_format: int=0x00): + data = bytes([data_format]) + + if memory_address_bytes < 1 or memory_address_bytes > 4: + raise ValueError('invalid memory_address_bytes: {}'.format(memory_address_bytes)) + if memory_size_bytes < 1 or memory_size_bytes > 4: + raise ValueError('invalid memory_size_bytes: {}'.format(memory_size_bytes)) + data += bytes([memory_size_bytes<<4 | memory_address_bytes]) + + if memory_address >= 1<<(memory_address_bytes*8): + raise ValueError('invalid memory_address: {}'.format(memory_address)) + data += struct.pack('!I', memory_address)[4-memory_address_bytes:] + if memory_size >= 1<<(memory_size_bytes*8): + raise ValueError('invalid memory_size: {}'.format(memory_size)) + data += struct.pack('!I', memory_size)[4-memory_size_bytes:] + + resp = self._uds_request(SERVICE_TYPE.REQUEST_DOWNLOAD, subfunction=None, data=data) + max_num_bytes_len = resp[0] >> 4 if len(resp) > 0 else None + if max_num_bytes_len >= 1 and max_num_bytes_len <= 4: + max_num_bytes = struct.unpack('!I', (b"\x00"*(4-max_num_bytes_len))+resp[1:max_num_bytes_len+1])[0] + else: + raise ValueError('invalid max_num_bytes_len: {}'.format(max_num_bytes_len)) + + return max_num_bytes # max number of bytes per transfer data request + + def request_upload(self, memory_address: int, memory_size: int, memory_address_bytes: int=4, memory_size_bytes: int=4, data_format: int=0x00): + data = bytes([data_format]) + + if memory_address_bytes < 1 or memory_address_bytes > 4: + raise ValueError('invalid memory_address_bytes: {}'.format(memory_address_bytes)) + if memory_size_bytes < 1 or memory_size_bytes > 4: + raise ValueError('invalid memory_size_bytes: {}'.format(memory_size_bytes)) + data += bytes([memory_size_bytes<<4 | memory_address_bytes]) + + if memory_address >= 1<<(memory_address_bytes*8): + raise ValueError('invalid memory_address: {}'.format(memory_address)) + data += struct.pack('!I', memory_address)[4-memory_address_bytes:] + if memory_size >= 1<<(memory_size_bytes*8): + raise ValueError('invalid memory_size: {}'.format(memory_size)) + data += struct.pack('!I', memory_size)[4-memory_size_bytes:] + + resp = self._uds_request(SERVICE_TYPE.REQUEST_UPLOAD, subfunction=None, data=data) + max_num_bytes_len = resp[0] >> 4 if len(resp) > 0 else None + if max_num_bytes_len >= 1 and max_num_bytes_len <= 4: + max_num_bytes = struct.unpack('!I', (b"\x00"*(4-max_num_bytes_len))+resp[1:max_num_bytes_len+1])[0] + else: + raise ValueError('invalid max_num_bytes_len: {}'.format(max_num_bytes_len)) + + return max_num_bytes # max number of bytes per transfer data request + + def transfer_data(self, block_sequence_count: int, data: bytes=b''): + data = bytes([block_sequence_count]) + data + resp = self._uds_request(SERVICE_TYPE.TRANSFER_DATA, subfunction=None, data=data) + resp_id = resp[0] if len(resp) > 0 else None + if resp_id != block_sequence_count: + raise ValueError('invalid block_sequence_count: {}'.format(resp_id)) + return resp[1:] + + def request_transfer_exit(self): + self._uds_request(SERVICE_TYPE.REQUEST_TRANSFER_EXIT, subfunction=None) diff --git a/panda/python/update.py b/panda/python/update.py index d72de11645f0c6..7d8d2c04023b8e 100755 --- a/panda/python/update.py +++ b/panda/python/update.py @@ -12,7 +12,6 @@ def ensure_st_up_to_date(): panda = None panda_dfu = None - should_flash_recover = False while 1: # break on normal mode Panda diff --git a/panda/requirements.txt b/panda/requirements.txt index ad6b4c76e054f3..e7cf9931d550e7 100644 --- a/panda/requirements.txt +++ b/panda/requirements.txt @@ -1,7 +1,11 @@ libusb1 == 1.6.6 -hexdump -pycrypto -tqdm +numpy==1.17.2 +hexdump>=3.3 +pycrypto==2.6.1 +tqdm>=4.14.0 nose parameterized requests +flake8==3.7.8 +pylint==2.4.2 +cffi==1.11.4 diff --git a/panda/setup.py b/panda/setup.py index 2acd9b9e1654df..f34905d7a2ee17 100644 --- a/panda/setup.py +++ b/panda/setup.py @@ -13,7 +13,7 @@ import codecs import os import re -from setuptools import setup, Extension +from setuptools import setup here = os.path.abspath(os.path.dirname(__file__)) diff --git a/panda/tests/automated/0_builds.py b/panda/tests/automated/0_builds.py index df4186cce4e6f6..fa3a1125d48244 100644 --- a/panda/tests/automated/0_builds.py +++ b/panda/tests/automated/0_builds.py @@ -1,4 +1,3 @@ -import os from panda import build_st def test_build_panda(): diff --git a/panda/tests/automated/1_program.py b/panda/tests/automated/1_program.py index 944db18d9aaed6..538f18c0c7f63a 100644 --- a/panda/tests/automated/1_program.py +++ b/panda/tests/automated/1_program.py @@ -1,6 +1,4 @@ -import os -from panda import Panda -from .helpers import panda_type_to_serial, test_white_and_grey, test_all_pandas, panda_connect_and_init +from .helpers import test_all_pandas, panda_connect_and_init @test_all_pandas @panda_connect_and_init diff --git a/panda/tests/automated/2_usb_to_can.py b/panda/tests/automated/2_usb_to_can.py index 645f686e155914..32ef558cfc409a 100644 --- a/panda/tests/automated/2_usb_to_can.py +++ b/panda/tests/automated/2_usb_to_can.py @@ -1,5 +1,3 @@ - -import os import sys import time from panda import Panda @@ -180,6 +178,6 @@ def test_gmlan_bad_toggle(p): @test_all_pandas @panda_connect_and_init def test_serial_debug(p): - junk = p.serial_read(Panda.SERIAL_DEBUG) + _ = p.serial_read(Panda.SERIAL_DEBUG) # junk p.call_control_api(0xc0) assert(p.serial_read(Panda.SERIAL_DEBUG).startswith(b"can ")) diff --git a/panda/tests/automated/3_wifi.py b/panda/tests/automated/3_wifi.py index f57dbbd0210c69..df66d6c0f37d2f 100644 --- a/panda/tests/automated/3_wifi.py +++ b/panda/tests/automated/3_wifi.py @@ -1,5 +1,3 @@ - -import os import time from panda import Panda from .helpers import connect_wifi, test_white, test_all_pandas, panda_type_to_serial, panda_connect_and_init diff --git a/panda/tests/automated/4_wifi_functionality.py b/panda/tests/automated/4_wifi_functionality.py index 67cce4bf9c37a6..ee349ddcbf69b8 100644 --- a/panda/tests/automated/4_wifi_functionality.py +++ b/panda/tests/automated/4_wifi_functionality.py @@ -1,8 +1,6 @@ - import time from panda import Panda from .helpers import time_many_sends, connect_wifi, test_white, panda_type_to_serial -from nose.tools import timed, assert_equal, assert_less, assert_greater @test_white @panda_type_to_serial diff --git a/panda/tests/automated/5_wifi_udp.py b/panda/tests/automated/5_wifi_udp.py index 642d8f02a59961..fd905aa895e4b3 100644 --- a/panda/tests/automated/5_wifi_udp.py +++ b/panda/tests/automated/5_wifi_udp.py @@ -3,7 +3,7 @@ import time from .helpers import time_many_sends, connect_wifi, test_white, panda_type_to_serial from panda import Panda, PandaWifiStreaming -from nose.tools import timed, assert_equal, assert_less, assert_greater +from nose.tools import assert_less, assert_greater @test_white @panda_type_to_serial diff --git a/panda/tests/automated/6_two_panda.py b/panda/tests/automated/6_two_panda.py index 711b83fddf63e6..f91403545f367a 100644 --- a/panda/tests/automated/6_two_panda.py +++ b/panda/tests/automated/6_two_panda.py @@ -171,7 +171,7 @@ def _test_buses(send_panda, recv_panda, _test_array): time.sleep(0.1) # check for receive - cans_echo = send_panda.can_recv() + _ = send_panda.can_recv() # cans echo cans_loop = recv_panda.can_recv() loop_buses = [] diff --git a/panda/tests/automated/helpers.py b/panda/tests/automated/helpers.py index f73a17dc043e21..2642e9156ad316 100644 --- a/panda/tests/automated/helpers.py +++ b/panda/tests/automated/helpers.py @@ -2,13 +2,12 @@ import sys import time import random -import binascii import subprocess import requests import _thread from functools import wraps from panda import Panda -from nose.tools import timed, assert_equal, assert_less, assert_greater +from nose.tools import assert_equal from parameterized import parameterized, param SPEED_NORMAL = 500 @@ -50,7 +49,7 @@ def connect_wifi(serial=None): FNULL = open(os.devnull, 'w') def _connect_wifi(dongle_id, pw, insecure_okay=False): - ssid = "panda-" + dongle_id.decode("utf8") + ssid = "panda-" + dongle_id r = subprocess.call(["ping", "-W", "4", "-c", "1", "192.168.0.10"], stdout=FNULL, stderr=subprocess.STDOUT) if not r: @@ -69,7 +68,7 @@ def _connect_wifi(dongle_id, pw, insecure_okay=False): if sys.platform == "darwin": os.system("networksetup -setairportnetwork en0 %s %s" % (ssid, pw)) else: - wlan_interface = subprocess.check_output(["sh", "-c", "iw dev | awk '/Interface/ {print $2}'"]).strip() + wlan_interface = subprocess.check_output(["sh", "-c", "iw dev | awk '/Interface/ {print $2}'"]).strip().decode('utf8') cnt = 0 MAX_TRIES = 10 while cnt < MAX_TRIES: @@ -87,13 +86,13 @@ def _connect_wifi(dongle_id, pw, insecure_okay=False): if "-pair" in wifi_scan[0]: os.system("nmcli d wifi connect %s-pair" % (ssid)) connect_cnt = 0 - MAX_TRIES = 20 + MAX_TRIES = 100 while connect_cnt < MAX_TRIES: connect_cnt += 1 r = subprocess.call(["ping", "-W", "4", "-c", "1", "192.168.0.10"], stdout=FNULL, stderr=subprocess.STDOUT) if r: print("Waiting for panda to ping...") - time.sleep(0.1) + time.sleep(0.5) else: break if insecure_okay: diff --git a/panda/tests/black_loopback_test.py b/panda/tests/black_loopback_test.py index 0953cba4faba02..5fe0c48077e238 100755 --- a/panda/tests/black_loopback_test.py +++ b/panda/tests/black_loopback_test.py @@ -11,9 +11,6 @@ import random import argparse -from hexdump import hexdump -from itertools import permutations - sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) from panda import Panda @@ -33,7 +30,7 @@ def run_test(sleep_duration): pandas[0] = Panda(pandas[0]) pandas[1] = Panda(pandas[1]) - # find out the hardware types + # find out the hardware types if not pandas[0].is_black() or not pandas[1].is_black(): print("Connect two black pandas to run this test!") assert False @@ -66,14 +63,14 @@ def run_test(sleep_duration): test_buses(pandas[0], pandas[1], test_array, sleep_duration) print("***************** TESTING (1 --> 0) *****************") test_buses(pandas[1], pandas[0], test_array, sleep_duration) - + def test_buses(send_panda, recv_panda, test_array, sleep_duration): for send_bus, send_obd, recv_obd, recv_buses in test_array: send_panda.send_heartbeat() recv_panda.send_heartbeat() print("\nSend bus:", send_bus, " Send OBD:", send_obd, " Recv OBD:", recv_obd) - + # set OBD on pandas send_panda.set_gmlan(True if send_obd else None) recv_panda.set_gmlan(True if recv_obd else None) @@ -92,7 +89,7 @@ def test_buses(send_panda, recv_panda, test_array, sleep_duration): time.sleep(0.1) # check for receive - cans_echo = send_panda.can_recv() + _ = send_panda.can_recv() # cans echo cans_loop = recv_panda.can_recv() loop_buses = [] @@ -101,7 +98,7 @@ def test_buses(send_panda, recv_panda, test_array, sleep_duration): loop_buses.append(loop[3]) if len(cans_loop) == 0: print(" No loop") - + # test loop buses recv_buses.sort() loop_buses.sort() diff --git a/panda/tests/black_white_loopback_test.py b/panda/tests/black_white_loopback_test.py index 7ad2107fa0918f..66c5e80f452ad6 100755 --- a/panda/tests/black_white_loopback_test.py +++ b/panda/tests/black_white_loopback_test.py @@ -11,9 +11,6 @@ import random import argparse -from hexdump import hexdump -from itertools import permutations - sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) from panda import Panda @@ -118,10 +115,10 @@ def test_buses(black_panda, other_panda, direction, test_array, sleep_duration): # check for receive if direction: - cans_echo = black_panda.can_recv() + _ = black_panda.can_recv() # can echo cans_loop = other_panda.can_recv() else: - cans_echo = other_panda.can_recv() + _ = other_panda.can_recv() # can echo cans_loop = black_panda.can_recv() loop_buses = [] diff --git a/panda/tests/black_white_relay_endurance.py b/panda/tests/black_white_relay_endurance.py index 3eaaa1655575e1..6970966526c7bc 100755 --- a/panda/tests/black_white_relay_endurance.py +++ b/panda/tests/black_white_relay_endurance.py @@ -11,9 +11,6 @@ import random import argparse -from hexdump import hexdump -from itertools import permutations - sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) from panda import Panda @@ -42,7 +39,7 @@ def run_test(sleep_duration): black_panda = None other_panda = None - + # find out which one is black if pandas[0].is_black() and not pandas[1].is_black(): black_panda = pandas[0] @@ -69,7 +66,7 @@ def run_test(sleep_duration): test_buses(black_panda, other_panda, True, [(0, False, [0]), (1, False, [1]), (2, False, [2]), (1, True, [0])], sleep_duration) test_buses(black_panda, other_panda, False, [(0, False, [0]), (1, False, [1]), (2, False, [2]), (0, True, [0, 1])], sleep_duration) counter += 1 - + runtime = time.time() - start_time print("Number of cycles:", counter, "Non-zero bus errors:", nonzero_bus_errors, "Zero bus errors:", zero_bus_errors, "Content errors:", content_errors, "Runtime: ", runtime) @@ -80,7 +77,7 @@ def run_test(sleep_duration): black_panda.set_safety_mode(Panda.SAFETY_ALLOUTPUT) time.sleep(1) temp_start_time = time.time() - + def test_buses(black_panda, other_panda, direction, test_array, sleep_duration): global nonzero_bus_errors, zero_bus_errors, content_errors @@ -94,7 +91,7 @@ def test_buses(black_panda, other_panda, direction, test_array, sleep_duration): black_panda.send_heartbeat() other_panda.send_heartbeat() print("\ntest can: ", send_bus, " OBD: ", obd) - + # set OBD on black panda black_panda.set_gmlan(True if obd else None) @@ -109,7 +106,7 @@ def test_buses(black_panda, other_panda, direction, test_array, sleep_duration): other_panda.can_clear(recv_bus) else: black_panda.can_clear(recv_bus) - + black_panda.can_recv() other_panda.can_recv() @@ -124,10 +121,10 @@ def test_buses(black_panda, other_panda, direction, test_array, sleep_duration): # check for receive if direction: - cans_echo = black_panda.can_recv() + _ = black_panda.can_recv() # cans echo cans_loop = other_panda.can_recv() else: - cans_echo = other_panda.can_recv() + _ = other_panda.can_recv() # cans echo cans_loop = black_panda.can_recv() loop_buses = [] @@ -141,7 +138,7 @@ def test_buses(black_panda, other_panda, direction, test_array, sleep_duration): print(" No loop") if not os.getenv("NOASSERT"): assert False - + # test loop buses recv_buses.sort() loop_buses.sort() diff --git a/panda/tests/black_white_relay_test.py b/panda/tests/black_white_relay_test.py index 65877dc29f7058..d80490f7d465da 100755 --- a/panda/tests/black_white_relay_test.py +++ b/panda/tests/black_white_relay_test.py @@ -10,9 +10,6 @@ import random import argparse -from hexdump import hexdump -from itertools import permutations - sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) from panda import Panda @@ -46,7 +43,7 @@ def run_test(sleep_duration): black_panda = None other_panda = None - + if type0 == "\x03" and type1 != "\x03": black_panda = pandas[0] other_panda = pandas[1] @@ -86,15 +83,15 @@ def run_test(sleep_duration): assert False counter += 1 - print("Number of cycles:", counter, "Open errors:", open_errors, "Closed errors:", closed_errors, "Content errors:", content_errors) + print("Number of cycles:", counter, "Open errors:", open_errors, "Closed errors:", closed_errors, "Content errors:", content_errors) def test_buses(black_panda, other_panda, test_obj): global content_errors send_bus, obd, recv_buses = test_obj - + black_panda.send_heartbeat() other_panda.send_heartbeat() - + # Set OBD on send panda other_panda.set_gmlan(True if obd else None) @@ -103,7 +100,7 @@ def test_buses(black_panda, other_panda, test_obj): for recv_bus in recv_buses: black_panda.can_clear(recv_bus) - + black_panda.can_recv() other_panda.can_recv() @@ -114,7 +111,7 @@ def test_buses(black_panda, other_panda, test_obj): time.sleep(0.05) # check for receive - cans_echo = other_panda.can_recv() + _ = other_panda.can_recv() # can echo cans_loop = black_panda.can_recv() loop_buses = [] @@ -122,7 +119,7 @@ def test_buses(black_panda, other_panda, test_obj): if (loop[0] != at) or (loop[2] != st): content_errors += 1 loop_buses.append(loop[3]) - + # test loop buses recv_buses.sort() loop_buses.sort() diff --git a/panda/tests/elm_car_simulator.py b/panda/tests/elm_car_simulator.py index ffb309664e4532..01b79c88404e48 100755 --- a/panda/tests/elm_car_simulator.py +++ b/panda/tests/elm_car_simulator.py @@ -109,9 +109,9 @@ def _lin_send(self, to_addr, msg): print(" LIN Reply (%x)" % to_addr, binascii.hexlify(msg)) PHYS_ADDR = 0x80 - FUNC_ADDR = 0xC0 + #FUNC_ADDR = 0xC0 RECV = 0xF1 - SEND = 0x33 # Car OBD Functional Address + #SEND = 0x33 # Car OBD Functional Address headers = struct.pack("BBB", PHYS_ADDR | len(msg), RECV, to_addr) if not self.__silent: print(" Sending LIN", binascii.hexlify(headers+msg), @@ -172,7 +172,7 @@ def __can_monitor(self): while not self.__stop: for address, ts, data, src in self.panda.can_recv(): - if self.__on and src is 0 and len(data) == 8 and data[0] >= 2: + if self.__on and src == 0 and len(data) == 8 and data[0] >= 2: if not self.__silent: print("Processing CAN message", src, hex(address), binascii.hexlify(data)) self.__can_process_msg(data[1], data[2], address, ts, data, src) diff --git a/panda/tests/elm_wifi.py b/panda/tests/elm_wifi.py index 6c4a334b73d152..b0645ea8898d22 100644 --- a/panda/tests/elm_wifi.py +++ b/panda/tests/elm_wifi.py @@ -1,16 +1,14 @@ - import os import sys import time import socket import select -import pytest import struct sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) -from . import elm_car_simulator sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..")) from panda import Panda +from panda.tests import elm_car_simulator def elm_connect(): s = socket.create_connection(("192.168.0.10", 35000)) @@ -234,35 +232,35 @@ def test_elm_send_lin_multiline_msg(): send_compare(s, b'0902\r', # headers OFF, Spaces ON b"BUS INIT: OK\r" - "49 02 01 00 00 00 31 \r" - "49 02 02 44 34 47 50 \r" - "49 02 03 30 30 52 35 \r" - "49 02 04 35 42 31 32 \r" - "49 02 05 33 34 35 36 \r\r>") + b"49 02 01 00 00 00 31 \r" + b"49 02 02 44 34 47 50 \r" + b"49 02 03 30 30 52 35 \r" + b"49 02 04 35 42 31 32 \r" + b"49 02 05 33 34 35 36 \r\r>") send_compare(s, b'ATS0\r', b'OK\r\r>') # Spaces OFF send_compare(s, b'0902\r', # Headers OFF, Spaces OFF b"49020100000031\r" - "49020244344750\r" - "49020330305235\r" - "49020435423132\r" - "49020533343536\r\r>") + b"49020244344750\r" + b"49020330305235\r" + b"49020435423132\r" + b"49020533343536\r\r>") send_compare(s, b'ATH1\r', b'OK\r\r>') # Headers ON send_compare(s, b'0902\r', # Headers ON, Spaces OFF b"87F1104902010000003105\r" - "87F11049020244344750E4\r" - "87F11049020330305235BD\r" - "87F11049020435423132B1\r" - "87F11049020533343536AA\r\r>") + b"87F11049020244344750E4\r" + b"87F11049020330305235BD\r" + b"87F11049020435423132B1\r" + b"87F11049020533343536AA\r\r>") send_compare(s, b'ATS1\r', b'OK\r\r>') # Spaces ON send_compare(s, b'0902\r', # Headers ON, Spaces ON b"87 F1 10 49 02 01 00 00 00 31 05 \r" - "87 F1 10 49 02 02 44 34 47 50 E4 \r" - "87 F1 10 49 02 03 30 30 52 35 BD \r" - "87 F1 10 49 02 04 35 42 31 32 B1 \r" - "87 F1 10 49 02 05 33 34 35 36 AA \r\r>") + b"87 F1 10 49 02 02 44 34 47 50 E4 \r" + b"87 F1 10 49 02 03 30 30 52 35 BD \r" + b"87 F1 10 49 02 04 35 42 31 32 B1 \r" + b"87 F1 10 49 02 05 33 34 35 36 AA \r\r>") finally: sim.stop() sim.join() @@ -322,7 +320,7 @@ def timed_recv_check(p, bus, goodmsg): def kline_send(p, x, bus=2): p.kline_drain(bus=bus) - p._handle.bulkWrite(2, chr(bus).encode()+x) + p._handle.bulkWrite(2, bytes([bus]) + x) return timed_recv_check(p, bus, x) def did_send(priority, toaddr, fromaddr, dat, bus=2, checkbyte=None): @@ -461,7 +459,7 @@ def test_elm_send_can_multimsg(): sim.can_add_extra_noise(b'\x03\x41\x0D\xFA', addr=0x7E9)# Inject message into the stream send_compare(s, b'010D\r', b"7E8 03 41 0D 53 \r" - "7E9 03 41 0D FA \r\r>") # Check it was ignored. + b"7E9 03 41 0D FA \r\r>") # Check it was ignored. finally: sim.stop() sim.join() @@ -503,28 +501,28 @@ def test_elm_send_can_multiline_msg(): send_compare(s, b'0902\r', # headers OFF, Spaces ON b"014 \r" - "0: 49 02 01 31 44 34 \r" - "1: 47 50 30 30 52 35 35 \r" - "2: 42 31 32 33 34 35 36 \r\r>") + b"0: 49 02 01 31 44 34 \r" + b"1: 47 50 30 30 52 35 35 \r" + b"2: 42 31 32 33 34 35 36 \r\r>") send_compare(s, b'ATS0\r', b'OK\r\r>') # Spaces OFF send_compare(s, b'0902\r', # Headers OFF, Spaces OFF b"014\r" - "0:490201314434\r" - "1:47503030523535\r" - "2:42313233343536\r\r>") + b"0:490201314434\r" + b"1:47503030523535\r" + b"2:42313233343536\r\r>") send_compare(s, b'ATH1\r', b'OK\r\r>') # Headers ON send_compare(s, b'0902\r', # Headers ON, Spaces OFF b"7E81014490201314434\r" - "7E82147503030523535\r" - "7E82242313233343536\r\r>") + b"7E82147503030523535\r" + b"7E82242313233343536\r\r>") send_compare(s, b'ATS1\r', b'OK\r\r>') # Spaces ON send_compare(s, b'0902\r', # Headers ON, Spaces ON b"7E8 10 14 49 02 01 31 44 34 \r" - "7E8 21 47 50 30 30 52 35 35 \r" - "7E8 22 42 31 32 33 34 35 36 \r\r>") + b"7E8 21 47 50 30 30 52 35 35 \r" + b"7E8 22 42 31 32 33 34 35 36 \r\r>") finally: sim.stop() sim.join() diff --git a/panda/tests/fan_test.py b/panda/tests/fan_test.py new file mode 100755 index 00000000000000..73856988281b19 --- /dev/null +++ b/panda/tests/fan_test.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python +import os +import sys +import time + +sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) +from panda import Panda + +power = 0 +if __name__ == "__main__": + p = Panda() + while True: + p.set_fan_power(power) + time.sleep(5) + print("Power: ", power, "RPM: ", str(p.get_fan_rpm())) + power += 10 + power %=100 diff --git a/panda/tests/gmbitbang/recv.py b/panda/tests/gmbitbang/recv.py index 92111ed7eca369..3949c424d9ef36 100755 --- a/panda/tests/gmbitbang/recv.py +++ b/panda/tests/gmbitbang/recv.py @@ -1,17 +1,16 @@ #!/usr/bin/env python3 -import time from panda import Panda p = Panda() p.set_safety_mode(Panda.SAFETY_ALLOUTPUT) p.set_gmlan(bus=2) -#p.can_send(0xaaa, "\x00\x00", bus=3) +#p.can_send(0xaaa, b"\x00\x00", bus=3) last_add = None while 1: ret = p.can_recv() if len(ret) > 0: add = ret[0][0] - if last_add is not None and add != last_add+1: - print("MISS %d %d" % (last_add, add)) + if last_add is not None and add != last_add + 1: + print("MISS: ", last_add, add) last_add = add print(ret) diff --git a/panda/tests/gmbitbang/rigol.py b/panda/tests/gmbitbang/rigol.py index f2efb0340ec06e..5fcdf243ecd4d7 100755 --- a/panda/tests/gmbitbang/rigol.py +++ b/panda/tests/gmbitbang/rigol.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +# pylint: skip-file import numpy as np import visa import matplotlib.pyplot as plt diff --git a/panda/tests/gps_stability_test.py b/panda/tests/gps_stability_test.py index c96aaf123b3529..529970e0f4e1fa 100755 --- a/panda/tests/gps_stability_test.py +++ b/panda/tests/gps_stability_test.py @@ -77,7 +77,7 @@ def add_nmea_checksum(msg): # Upping baud rate print("Upping GPS baud rate") - msg = add_nmea_checksum("$PUBX,41,1,0007,0003,%d,0" % GPS_BAUD)+"\r\n" + msg = str.encode(add_nmea_checksum("$PUBX,41,1,0007,0003,%d,0" % GPS_BAUD)+"\r\n") ser.write(msg) time.sleep(1) # needs a wait for it to actually send @@ -86,24 +86,24 @@ def add_nmea_checksum(msg): # Sending all config messages boardd sends print("Sending config") - ser.write("\xB5\x62\x06\x00\x14\x00\x03\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x01\x00\x00\x00\x00\x00\x1E\x7F") - ser.write("\xB5\x62\x06\x3E\x00\x00\x44\xD2") - ser.write("\xB5\x62\x06\x00\x14\x00\x00\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x19\x35") - ser.write("\xB5\x62\x06\x00\x14\x00\x01\x00\x00\x00\xC0\x08\x00\x00\x00\x08\x07\x00\x01\x00\x01\x00\x00\x00\x00\x00\xF4\x80") - ser.write("\xB5\x62\x06\x00\x14\x00\x04\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1D\x85") - ser.write("\xB5\x62\x06\x00\x00\x00\x06\x18") - ser.write("\xB5\x62\x06\x00\x01\x00\x01\x08\x22") - ser.write("\xB5\x62\x06\x00\x01\x00\x02\x09\x23") - ser.write("\xB5\x62\x06\x00\x01\x00\x03\x0A\x24") - ser.write("\xB5\x62\x06\x08\x06\x00\x64\x00\x01\x00\x00\x00\x79\x10") - ser.write("\xB5\x62\x06\x24\x24\x00\x05\x00\x04\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x5A\x63") - ser.write("\xB5\x62\x06\x1E\x14\x00\x00\x00\x00\x00\x01\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x3C\x37") - ser.write("\xB5\x62\x06\x24\x00\x00\x2A\x84") - ser.write("\xB5\x62\x06\x23\x00\x00\x29\x81") - ser.write("\xB5\x62\x06\x1E\x00\x00\x24\x72") - ser.write("\xB5\x62\x06\x01\x03\x00\x01\x07\x01\x13\x51") - ser.write("\xB5\x62\x06\x01\x03\x00\x02\x15\x01\x22\x70") - ser.write("\xB5\x62\x06\x01\x03\x00\x02\x13\x01\x20\x6C") + ser.write(b"\xB5\x62\x06\x00\x14\x00\x03\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x01\x00\x00\x00\x00\x00\x1E\x7F") + ser.write(b"\xB5\x62\x06\x3E\x00\x00\x44\xD2") + ser.write(b"\xB5\x62\x06\x00\x14\x00\x00\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x19\x35") + ser.write(b"\xB5\x62\x06\x00\x14\x00\x01\x00\x00\x00\xC0\x08\x00\x00\x00\x08\x07\x00\x01\x00\x01\x00\x00\x00\x00\x00\xF4\x80") + ser.write(b"\xB5\x62\x06\x00\x14\x00\x04\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1D\x85") + ser.write(b"\xB5\x62\x06\x00\x00\x00\x06\x18") + ser.write(b"\xB5\x62\x06\x00\x01\x00\x01\x08\x22") + ser.write(b"\xB5\x62\x06\x00\x01\x00\x02\x09\x23") + ser.write(b"\xB5\x62\x06\x00\x01\x00\x03\x0A\x24") + ser.write(b"\xB5\x62\x06\x08\x06\x00\x64\x00\x01\x00\x00\x00\x79\x10") + ser.write(b"\xB5\x62\x06\x24\x24\x00\x05\x00\x04\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x5A\x63") + ser.write(b"\xB5\x62\x06\x1E\x14\x00\x00\x00\x00\x00\x01\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x3C\x37") + ser.write(b"\xB5\x62\x06\x24\x00\x00\x2A\x84") + ser.write(b"\xB5\x62\x06\x23\x00\x00\x29\x81") + ser.write(b"\xB5\x62\x06\x1E\x00\x00\x24\x72") + ser.write(b"\xB5\x62\x06\x01\x03\x00\x01\x07\x01\x13\x51") + ser.write(b"\xB5\x62\x06\x01\x03\x00\x02\x15\x01\x22\x70") + ser.write(b"\xB5\x62\x06\x01\x03\x00\x02\x13\x01\x20\x6C") print("Initialized GPS") @@ -163,7 +163,3 @@ def gps_read_thread(panda): print("Total max failures: ", max_failures) received_messages = 0 received_bytes = 0 - - - - \ No newline at end of file diff --git a/panda/tests/ir_test.py b/panda/tests/ir_test.py new file mode 100755 index 00000000000000..caef9e4909d3d9 --- /dev/null +++ b/panda/tests/ir_test.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python +import os +import sys +import time + +sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) +from panda import Panda + +power = 0 +if __name__ == "__main__": + p = Panda() + while True: + p.set_ir_power(power) + print("Power: ", str(power)) + time.sleep(1) + power += 10 + power %=100 diff --git a/panda/tests/language/Dockerfile b/panda/tests/language/Dockerfile index fe957ff7230722..6a1d8bb7c77ff9 100644 --- a/panda/tests/language/Dockerfile +++ b/panda/tests/language/Dockerfile @@ -14,5 +14,4 @@ RUN pyenv install 3.7.3 RUN pyenv global 3.7.3 RUN pyenv rehash -COPY tests/safety/requirements.txt /panda/tests/safety/requirements.txt COPY . /panda diff --git a/panda/tests/language/test_language.py b/panda/tests/language/test_language.py index 353f37e8546fb8..98b029042551e9 100755 --- a/panda/tests/language/test_language.py +++ b/panda/tests/language/test_language.py @@ -20,7 +20,7 @@ res = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT) print(res) found_bad_language = True - except subprocess.CalledProcessError as e: + except subprocess.CalledProcessError: pass if found_bad_language: sys.exit("Failed: found bad language") diff --git a/panda/tests/linter_python/.pylintrc b/panda/tests/linter_python/.pylintrc new file mode 100644 index 00000000000000..64a55daf8fabb3 --- /dev/null +++ b/panda/tests/linter_python/.pylintrc @@ -0,0 +1,585 @@ +[MASTER] + +# A comma-separated list of package or module names from where C extensions may +# be loaded. Extensions are loading into the active Python interpreter and may +# run arbitrary code +extension-pkg-whitelist=scipy + +# Add files or directories to the blacklist. They should be base names, not +# paths. +ignore=CVS + +# Add files or directories matching the regex patterns to the blacklist. The +# regex matches against base names, not paths. +ignore-patterns= + +# Python code to execute, usually for sys.path manipulation such as +# pygtk.require(). +#init-hook= + +# Use multiple processes to speed up Pylint. +jobs=4 + +# List of plugins (as comma separated values of python modules names) to load, +# usually to register additional checkers. +load-plugins= + +# Pickle collected data for later comparisons. +persistent=yes + +# Specify a configuration file. +#rcfile= + +# When enabled, pylint would attempt to guess common misconfiguration and emit +# user-friendly hints instead of false-positive error messages +suggestion-mode=yes + +# Allow loading of arbitrary C extensions. Extensions are imported into the +# active Python interpreter and may run arbitrary code. +unsafe-load-any-extension=no + + +[MESSAGES CONTROL] + +# Only show warnings with the listed confidence levels. Leave empty to show +# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED +confidence= + +# Disable the message, report, category or checker with the given id(s). You +# can either give multiple identifiers separated by comma (,) or put this +# option multiple times (only on the command line, not in the configuration +# file where it should appear only once).You can also use "--disable=all" to +# disable everything first and then reenable specific checks. For example, if +# you want to run only the similarities checker, you can use "--disable=all +# --enable=similarities". If you want to run only the classes checker, but have +# no Warning level messages displayed, use"--disable=all --enable=classes +# --disable=W" +disable=print-statement, + parameter-unpacking, + unpacking-in-except, + old-raise-syntax, + backtick, + long-suffix, + old-ne-operator, + old-octal-literal, + import-star-module-level, + non-ascii-bytes-literal, + raw-checker-failed, + bad-inline-option, + locally-disabled, + locally-enabled, + file-ignored, + suppressed-message, + useless-suppression, + deprecated-pragma, + apply-builtin, + basestring-builtin, + buffer-builtin, + cmp-builtin, + coerce-builtin, + execfile-builtin, + file-builtin, + long-builtin, + raw_input-builtin, + reduce-builtin, + standarderror-builtin, + unicode-builtin, + xrange-builtin, + coerce-method, + delslice-method, + getslice-method, + setslice-method, + no-absolute-import, + old-division, + dict-iter-method, + dict-view-method, + next-method-called, + metaclass-assignment, + indexing-exception, + raising-string, + reload-builtin, + oct-method, + hex-method, + nonzero-method, + cmp-method, + input-builtin, + round-builtin, + intern-builtin, + unichr-builtin, + map-builtin-not-iterating, + zip-builtin-not-iterating, + range-builtin-not-iterating, + filter-builtin-not-iterating, + using-cmp-argument, + eq-without-hash, + div-method, + idiv-method, + rdiv-method, + exception-message-attribute, + invalid-str-codec, + sys-max-int, + bad-python3-import, + deprecated-string-function, + deprecated-str-translate-call, + deprecated-itertools-function, + deprecated-types-field, + next-method-defined, + dict-items-not-iterating, + dict-keys-not-iterating, + dict-values-not-iterating, + bad-indentation, + line-too-long, + missing-docstring, + multiple-statements, + bad-continuation, + invalid-name, + too-many-arguments, + too-many-locals, + superfluous-parens, + bad-whitespace, + too-many-instance-attributes, + wrong-import-position, + ungrouped-imports, + wrong-import-order, + protected-access, + trailing-whitespace, + too-many-branches, + too-few-public-methods, + too-many-statements, + trailing-newlines, + attribute-defined-outside-init, + too-many-return-statements, + too-many-public-methods, + unused-argument, + old-style-class, + no-init, + len-as-condition, + unneeded-not, + no-self-use, + multiple-imports, + no-else-return, + logging-not-lazy, + fixme, + redefined-outer-name, + unused-variable, + unsubscriptable-object, + expression-not-assigned, + too-many-boolean-expressions, + consider-using-ternary, + invalid-unary-operand-type, + relative-import, + deprecated-lambda + + +# Enable the message, report, category or checker with the given id(s). You can +# either give multiple identifier separated by comma (,) or put this option +# multiple time (only on the command line, not in the configuration file where +# it should appear only once). See also the "--disable" option for examples. +enable=c-extension-no-member + + +[REPORTS] + +# Python expression which should return a note less than 10 (10 is the highest +# note). You have access to the variables errors warning, statement which +# respectively contain the number of errors / warnings messages and the total +# number of statements analyzed. This is used by the global evaluation report +# (RP0004). +evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) + +# Template used to display messages. This is a python new-style format string +# used to format the message information. See doc for all details +#msg-template= + +# Set the output format. Available formats are text, parseable, colorized, json +# and msvs (visual studio).You can also give a reporter class, eg +# mypackage.mymodule.MyReporterClass. +output-format=text + +# Tells whether to display a full report or only the messages +reports=no + +# Activate the evaluation score. +score=yes + + +[REFACTORING] + +# Maximum number of nested blocks for function / method body +max-nested-blocks=5 + +# Complete name of functions that never returns. When checking for +# inconsistent-return-statements if a never returning function is called then +# it will be considered as an explicit return statement and no message will be +# printed. +never-returning-functions=optparse.Values,sys.exit + + +[LOGGING] + +# Logging modules to check that the string format arguments are in logging +# function parameter format +logging-modules=logging + + +[SPELLING] + +# Limits count of emitted suggestions for spelling mistakes +max-spelling-suggestions=4 + +# Spelling dictionary name. Available dictionaries: none. To make it working +# install python-enchant package. +spelling-dict= + +# List of comma separated words that should not be checked. +spelling-ignore-words= + +# A path to a file that contains private dictionary; one word per line. +spelling-private-dict-file= + +# Tells whether to store unknown words to indicated private dictionary in +# --spelling-private-dict-file option instead of raising a message. +spelling-store-unknown-words=no + + +[MISCELLANEOUS] + +# List of note tags to take in consideration, separated by a comma. +notes=FIXME, + XXX, + TODO + + +[SIMILARITIES] + +# Ignore comments when computing similarities. +ignore-comments=yes + +# Ignore docstrings when computing similarities. +ignore-docstrings=yes + +# Ignore imports when computing similarities. +ignore-imports=no + +# Minimum lines number of a similarity. +min-similarity-lines=4 + + +[TYPECHECK] + +# List of decorators that produce context managers, such as +# contextlib.contextmanager. Add to this list to register other decorators that +# produce valid context managers. +contextmanager-decorators=contextlib.contextmanager + +# List of members which are set dynamically and missed by pylint inference +# system, and so shouldn't trigger E1101 when accessed. Python regular +# expressions are accepted. +generated-members=capnp.* cereal.* pygame.* zmq.* setproctitle.* smbus2.* usb1.* serial.* cv2.* + +# Tells whether missing members accessed in mixin class should be ignored. A +# mixin class is detected if its name ends with "mixin" (case insensitive). +ignore-mixin-members=yes + +# This flag controls whether pylint should warn about no-member and similar +# checks whenever an opaque object is returned when inferring. The inference +# can return multiple potential results while evaluating a Python object, but +# some branches might not be evaluated, which results in partial inference. In +# that case, it might be useful to still emit no-member and other checks for +# the rest of the inferred objects. +ignore-on-opaque-inference=yes + +# List of class names for which member attributes should not be checked (useful +# for classes with dynamically set attributes). This supports the use of +# qualified names. +ignored-classes=optparse.Values,thread._local,_thread._local + +# List of module names for which member attributes should not be checked +# (useful for modules/projects where namespaces are manipulated during runtime +# and thus existing member attributes cannot be deduced by static analysis. It +# supports qualified module names, as well as Unix pattern matching. +ignored-modules=flask setproctitle usb1 flask.ext.socketio smbus2 usb1.* + +# Show a hint with possible names when a member name was not found. The aspect +# of finding the hint is based on edit distance. +missing-member-hint=yes + +# The minimum edit distance a name should have in order to be considered a +# similar match for a missing member name. +missing-member-hint-distance=1 + +# The total number of similar names that should be taken in consideration when +# showing a hint for a missing member. +missing-member-max-choices=1 + + +[VARIABLES] + +# List of additional names supposed to be defined in builtins. Remember that +# you should avoid to define new builtins when possible. +additional-builtins= + +# Tells whether unused global variables should be treated as a violation. +allow-global-unused-variables=yes + +# List of strings which can identify a callback function by name. A callback +# name must start or end with one of those strings. +callbacks=cb_, + _cb + +# A regular expression matching the name of dummy variables (i.e. expectedly +# not used). +dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_ + +# Argument names that match this expression will be ignored. Default to name +# with leading underscore +ignored-argument-names=_.*|^ignored_|^unused_ + +# Tells whether we should check for unused import in __init__ files. +init-import=no + +# List of qualified module names which can have objects that can redefine +# builtins. +redefining-builtins-modules=six.moves,past.builtins,future.builtins + + +[FORMAT] + +# Expected format of line ending, e.g. empty (any line ending), LF or CRLF. +expected-line-ending-format= + +# Regexp for a line that is allowed to be longer than the limit. +ignore-long-lines=^\s*(# )??$ + +# Number of spaces of indent required inside a hanging or continued line. +indent-after-paren=4 + +# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 +# tab). +indent-string=' ' + +# Maximum number of characters on a single line. +max-line-length=100 + +# Maximum number of lines in a module +max-module-lines=1000 + +# List of optional constructs for which whitespace checking is disabled. `dict- +# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}. +# `trailing-comma` allows a space between comma and closing bracket: (a, ). +# `empty-line` allows space-only lines. +no-space-check=trailing-comma, + dict-separator + +# Allow the body of a class to be on the same line as the declaration if body +# contains single statement. +single-line-class-stmt=no + +# Allow the body of an if to be on the same line as the test if there is no +# else. +single-line-if-stmt=no + + +[BASIC] + +# Naming style matching correct argument names +argument-naming-style=snake_case + +# Regular expression matching correct argument names. Overrides argument- +# naming-style +#argument-rgx= + +# Naming style matching correct attribute names +attr-naming-style=snake_case + +# Regular expression matching correct attribute names. Overrides attr-naming- +# style +#attr-rgx= + +# Bad variable names which should always be refused, separated by a comma +bad-names=foo, + bar, + baz, + toto, + tutu, + tata + +# Naming style matching correct class attribute names +class-attribute-naming-style=any + +# Regular expression matching correct class attribute names. Overrides class- +# attribute-naming-style +#class-attribute-rgx= + +# Naming style matching correct class names +class-naming-style=PascalCase + +# Regular expression matching correct class names. Overrides class-naming-style +#class-rgx= + +# Naming style matching correct constant names +const-naming-style=UPPER_CASE + +# Regular expression matching correct constant names. Overrides const-naming- +# style +#const-rgx= + +# Minimum line length for functions/classes that require docstrings, shorter +# ones are exempt. +docstring-min-length=-1 + +# Naming style matching correct function names +function-naming-style=snake_case + +# Regular expression matching correct function names. Overrides function- +# naming-style +#function-rgx= + +# Good variable names which should always be accepted, separated by a comma +good-names=i, + j, + k, + ex, + Run, + _ + +# Include a hint for the correct naming format with invalid-name +include-naming-hint=no + +# Naming style matching correct inline iteration names +inlinevar-naming-style=any + +# Regular expression matching correct inline iteration names. Overrides +# inlinevar-naming-style +#inlinevar-rgx= + +# Naming style matching correct method names +method-naming-style=snake_case + +# Regular expression matching correct method names. Overrides method-naming- +# style +#method-rgx= + +# Naming style matching correct module names +module-naming-style=snake_case + +# Regular expression matching correct module names. Overrides module-naming- +# style +#module-rgx= + +# Colon-delimited sets of names that determine each other's naming style when +# the name regexes allow several styles. +name-group= + +# Regular expression which should only match function or class names that do +# not require a docstring. +no-docstring-rgx=^_ + +# List of decorators that produce properties, such as abc.abstractproperty. Add +# to this list to register other decorators that produce valid properties. +property-classes=abc.abstractproperty + +# Naming style matching correct variable names +variable-naming-style=snake_case + +# Regular expression matching correct variable names. Overrides variable- +# naming-style +#variable-rgx= + + +[DESIGN] + +# Maximum number of arguments for function / method +max-args=5 + +# Maximum number of attributes for a class (see R0902). +max-attributes=7 + +# Maximum number of boolean expressions in a if statement +max-bool-expr=5 + +# Maximum number of branch for function / method body +max-branches=12 + +# Maximum number of locals for function / method body +max-locals=15 + +# Maximum number of parents for a class (see R0901). +max-parents=7 + +# Maximum number of public methods for a class (see R0904). +max-public-methods=20 + +# Maximum number of return / yield for function / method body +max-returns=6 + +# Maximum number of statements in function / method body +max-statements=50 + +# Minimum number of public methods for a class (see R0903). +min-public-methods=2 + + +[CLASSES] + +# List of method names used to declare (i.e. assign) instance attributes. +defining-attr-methods=__init__, + __new__, + setUp + +# List of member names, which should be excluded from the protected access +# warning. +exclude-protected=_asdict, + _fields, + _replace, + _source, + _make + +# List of valid names for the first argument in a class method. +valid-classmethod-first-arg=cls + +# List of valid names for the first argument in a metaclass class method. +valid-metaclass-classmethod-first-arg=mcs + + +[IMPORTS] + +# Allow wildcard imports from modules that define __all__. +allow-wildcard-with-all=no + +# Analyse import fallback blocks. This can be used to support both Python 2 and +# 3 compatible code, which means that the block might have code that exists +# only in one or another interpreter, leading to false positives when analysed. +analyse-fallback-blocks=no + +# Deprecated modules which should not be used, separated by a comma +deprecated-modules=regsub, + TERMIOS, + Bastion, + rexec + +# Create a graph of external dependencies in the given file (report RP0402 must +# not be disabled) +ext-import-graph= + +# Create a graph of every (i.e. internal and external) dependencies in the +# given file (report RP0402 must not be disabled) +import-graph= + +# Create a graph of internal dependencies in the given file (report RP0402 must +# not be disabled) +int-import-graph= + +# Force import order to recognize a module as part of the standard +# compatibility libraries. +known-standard-library= + +# Force import order to recognize a module as part of a third party library. +known-third-party=enchant + + +[EXCEPTIONS] + +# Exceptions that will emit a warning when being caught. Defaults to +# "Exception" +overgeneral-exceptions=Exception diff --git a/panda/tests/linter_python/Dockerfile b/panda/tests/linter_python/Dockerfile new file mode 100644 index 00000000000000..819d692109e1c3 --- /dev/null +++ b/panda/tests/linter_python/Dockerfile @@ -0,0 +1,19 @@ +FROM ubuntu:16.04 + +RUN apt-get update && apt-get install -y make python python-pip locales curl git zlib1g-dev libffi-dev bzip2 libssl-dev + +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 + +COPY requirements.txt /tmp/ +RUN pip install -r /tmp/requirements.txt +COPY . /panda diff --git a/panda/tests/linter_python/flake8_panda.sh b/panda/tests/linter_python/flake8_panda.sh new file mode 100755 index 00000000000000..a1d02ea548eabe --- /dev/null +++ b/panda/tests/linter_python/flake8_panda.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +RESULT=$(python3 -m flake8 --select=F $(find ../../ -type f | grep -v "/boardesp/" | grep -v "/cppcheck/" | grep "\.py$")) +if [[ $RESULT ]]; then + echo "Pyflakes found errors in the code. Please fix and try again" + echo "$RESULT" + exit 1 +fi diff --git a/panda/tests/linter_python/pylint_panda.sh b/panda/tests/linter_python/pylint_panda.sh new file mode 100755 index 00000000000000..1486bd839cceff --- /dev/null +++ b/panda/tests/linter_python/pylint_panda.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +python3 -m pylint --disable=R,C,W $(find ../../ -type f | grep -v "/boardesp/" | grep -v "/cppcheck/" | grep "\.py$") + +exit_status=$? +(( res = exit_status & 3 )) + +if [[ $res != 0 ]]; then + echo "Pylint found errors in the code. Please fix and try again" + exit 1 +fi diff --git a/panda/tests/location_listener.py b/panda/tests/location_listener.py index 62ade10f03fdde..1a784babc98806 100755 --- a/panda/tests/location_listener.py +++ b/panda/tests/location_listener.py @@ -30,7 +30,7 @@ def add_nmea_checksum(msg): baudrate = 460800 print("upping baud rate") - msg = add_nmea_checksum("$PUBX,41,1,0007,0003,%d,0" % baudrate)+"\r\n" + msg = str.encode(add_nmea_checksum("$PUBX,41,1,0007,0003,%d,0" % baudrate)+"\r\n") print(msg) ser.write(msg) time.sleep(0.1) # needs a wait for it to actually send diff --git a/panda/tests/loopback_test.py b/panda/tests/loopback_test.py index 02c8d2cd144a12..60009fae51fd00 100755 --- a/panda/tests/loopback_test.py +++ b/panda/tests/loopback_test.py @@ -55,7 +55,7 @@ def run_test_w_pandas(pandas, sleep_duration): # send the characters st = get_test_string() - st = b"\xaa"+chr(len(st)+3).encode()+st + st = bytes([0xaa, len(st) + 3]) + st h[ho[0]].kline_send(st, bus=bus, checksum=False) # check for receive diff --git a/panda/tests/misra/Dockerfile b/panda/tests/misra/Dockerfile index e63cc7e9e151ed..06882834fcdfbe 100644 --- a/panda/tests/misra/Dockerfile +++ b/panda/tests/misra/Dockerfile @@ -1,6 +1,19 @@ FROM ubuntu:16.04 -RUN apt-get update && apt-get install -y make python python-pip git -COPY tests/safety/requirements.txt /panda/tests/safety/requirements.txt -RUN pip install -r /panda/tests/safety/requirements.txt +RUN apt-get update && apt-get install -y clang make python python-pip git curl locales zlib1g-dev libffi-dev bzip2 libssl-dev libbz2-dev libusb-1.0-0 + +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 + +COPY requirements.txt /tmp/ +RUN pip install -r /tmp/requirements.txt COPY . /panda diff --git a/panda/tests/misra/coverage_table b/panda/tests/misra/coverage_table index a00cd84a5f304d..dcb5992bc74743 100644 --- a/panda/tests/misra/coverage_table +++ b/panda/tests/misra/coverage_table @@ -9,9 +9,9 @@ 2.6 X (Cppcheck) 2.7 3.1 X (Addon) -3.2 +3.2 X (Addon) 4.1 X (Addon) -4.2 +4.2 X (Addon) 5.1 X (Addon) 5.2 X (Addon) 5.3 X (Addon) @@ -123,7 +123,7 @@ 20.12 20.13 X (Addon) 20.14 X (Addon) -21.1 +21.1 X (Addon) 21.2 21.3 X (Addon) 21.4 X (Addon) @@ -134,7 +134,7 @@ 21.9 X (Addon) 21.10 X (Addon) 21.11 X (Addon) -21.12 +21.12 X (Addon) 22.1 X (Cppcheck) 22.2 X (Cppcheck) 22.3 diff --git a/panda/tests/misra/suppressions.txt b/panda/tests/misra/suppressions.txt index b98a491eeb07ad..e0a270831a3526 100644 --- a/panda/tests/misra/suppressions.txt +++ b/panda/tests/misra/suppressions.txt @@ -4,3 +4,5 @@ misra.19.2 misra.11.4 # Advisory: casting from void pointer to type pointer is ok. Done by STM libraries as well misra.11.5 +# Required: it's ok re-defining potentially reserved Macro names. Not likely to cause confusion +misra.21.1 diff --git a/panda/tests/misra/test_misra.sh b/panda/tests/misra/test_misra.sh index c4aceaa92c010d..2542290744d963 100755 --- a/panda/tests/misra/test_misra.sh +++ b/panda/tests/misra/test_misra.sh @@ -4,7 +4,7 @@ mkdir /tmp/misra || true git clone https://github.com/danmar/cppcheck.git || true cd cppcheck git fetch -git checkout ff7dba91e177dfb712477faddb9e91bece7e743c +git checkout bdd41151ed550e3d240a6dd6847859216b7ad736 make -j4 cd ../../../ diff --git a/panda/tests/pedal/enter_canloader.py b/panda/tests/pedal/enter_canloader.py index cc37f2b843533c..4488c3205626cf 100755 --- a/panda/tests/pedal/enter_canloader.py +++ b/panda/tests/pedal/enter_canloader.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -import sys import time import struct import argparse diff --git a/panda/tests/rtc_test.py b/panda/tests/rtc_test.py new file mode 100755 index 00000000000000..3732cb765f81e9 --- /dev/null +++ b/panda/tests/rtc_test.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python +import os +import sys +import datetime + +sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) +from panda import Panda + +if __name__ == "__main__": + p = Panda() + + p.set_datetime(datetime.datetime.now()) + print(p.get_datetime()) diff --git a/panda/tests/safety/Dockerfile b/panda/tests/safety/Dockerfile index b0135b085f6595..3c70d253411b26 100644 --- a/panda/tests/safety/Dockerfile +++ b/panda/tests/safety/Dockerfile @@ -14,6 +14,7 @@ RUN pyenv install 3.7.3 RUN pyenv global 3.7.3 RUN pyenv rehash -COPY tests/safety/requirements.txt requirements.txt -RUN pip install -r requirements.txt +COPY requirements.txt /tmp/ +RUN pip install -r /tmp/requirements.txt + COPY . /panda diff --git a/panda/tests/safety/libpandasafety_py.py b/panda/tests/safety/libpandasafety_py.py index bb332e52b6b8e0..819fcada37e3d2 100644 --- a/panda/tests/safety/libpandasafety_py.py +++ b/panda/tests/safety/libpandasafety_py.py @@ -30,6 +30,8 @@ uint32_t CNT; } TIM_TypeDef; +bool board_has_relay(void); + void set_controls_allowed(bool c); bool get_controls_allowed(void); void set_long_controls_allowed(bool c); @@ -94,6 +96,11 @@ void set_subaru_rt_torque_last(int t); void set_subaru_torque_driver(int min, int max); +void init_tests_volkswagen(void); +void set_volkswagen_desired_torque_last(int t); +void set_volkswagen_rt_torque_last(int t); +void set_volkswagen_torque_driver(int min, int max); +int get_volkswagen_gas_prev(void); """) diff --git a/panda/tests/safety/requirements.txt b/panda/tests/safety/requirements.txt deleted file mode 100644 index 0c3124d87fb216..00000000000000 --- a/panda/tests/safety/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -cffi==1.11.4 -numpy==1.14.5 -libusb1==1.6.6 -requests diff --git a/panda/tests/safety/test.c b/panda/tests/safety/test.c index d92eb8680f6ecd..c61f64077c63b1 100644 --- a/panda/tests/safety/test.c +++ b/panda/tests/safety/test.c @@ -29,10 +29,27 @@ struct sample_t gm_torque_driver; struct sample_t hyundai_torque_driver; struct sample_t chrysler_torque_meas; struct sample_t subaru_torque_driver; +struct sample_t volkswagen_torque_driver; TIM_TypeDef timer; TIM_TypeDef *TIM2 = &timer; +// from board_declarations.h +#define HW_TYPE_UNKNOWN 0U +#define HW_TYPE_WHITE_PANDA 1U +#define HW_TYPE_GREY_PANDA 2U +#define HW_TYPE_BLACK_PANDA 3U +#define HW_TYPE_PEDAL 4U +#define HW_TYPE_UNO 5U + +// from main_declarations.h +uint8_t hw_type = HW_TYPE_UNKNOWN; + +// from board.h +bool board_has_relay(void) { + return hw_type == HW_TYPE_BLACK_PANDA || hw_type == HW_TYPE_UNO; +} + // from config.h #define MIN(a,b) \ ({ __typeof__ (a) _a = (a); \ @@ -52,16 +69,6 @@ TIM_TypeDef *TIM2 = &timer; #define GET_BYTES_04(msg) ((msg)->RDLR) #define GET_BYTES_48(msg) ((msg)->RDHR) -// from board_declarations.h -#define HW_TYPE_UNKNOWN 0U -#define HW_TYPE_WHITE_PANDA 1U -#define HW_TYPE_GREY_PANDA 2U -#define HW_TYPE_BLACK_PANDA 3U -#define HW_TYPE_PEDAL 4U - -// from main_declarations.h -uint8_t hw_type = 0U; - #define UNUSED(x) (void)(x) #define PANDA @@ -155,6 +162,11 @@ void set_subaru_torque_driver(int min, int max){ subaru_torque_driver.max = max; } +void set_volkswagen_torque_driver(int min, int max){ + volkswagen_torque_driver.min = min; + volkswagen_torque_driver.max = max; +} + int get_chrysler_torque_meas_min(void){ return chrysler_torque_meas.min; } @@ -199,6 +211,10 @@ void set_subaru_rt_torque_last(int t){ subaru_rt_torque_last = t; } +void set_volkswagen_rt_torque_last(int t){ + volkswagen_rt_torque_last = t; +} + void set_toyota_desired_torque_last(int t){ toyota_desired_torque_last = t; } @@ -223,6 +239,14 @@ void set_subaru_desired_torque_last(int t){ subaru_desired_torque_last = t; } +void set_volkswagen_desired_torque_last(int t){ + volkswagen_desired_torque_last = t; +} + +int get_volkswagen_gas_prev(void){ + return volkswagen_gas_prev; +} + bool get_honda_moving(void){ return honda_moving; } @@ -316,6 +340,16 @@ void init_tests_subaru(void){ set_timer(0); } +void init_tests_volkswagen(void){ + init_tests(); + volkswagen_torque_driver.min = 0; + volkswagen_torque_driver.max = 0; + volkswagen_desired_torque_last = 0; + volkswagen_rt_torque_last = 0; + volkswagen_ts_last = 0; + set_timer(0); +} + void init_tests_honda(void){ init_tests(); honda_moving = false; diff --git a/panda/tests/safety/test.sh b/panda/tests/safety/test.sh index 2674281addd9f4..39d70ff615bee8 100755 --- a/panda/tests/safety/test.sh +++ b/panda/tests/safety/test.sh @@ -6,11 +6,12 @@ # HW_TYPE_GREY_PANDA 2U # HW_TYPE_BLACK_PANDA 3U # HW_TYPE_PEDAL 4U +# HW_TYPE_UNO 5U # Make sure test fails if one HW_TYPE fails set -e -for hw_type in 0 1 2 3 4 +for hw_type in 0 1 2 3 4 5 do echo "Testing HW_TYPE: $hw_type" HW_TYPE=$hw_type python -m unittest discover . diff --git a/panda/tests/safety/test_cadillac.py b/panda/tests/safety/test_cadillac.py index 5573682d0cd44c..f211908b7bd11d 100644 --- a/panda/tests/safety/test_cadillac.py +++ b/panda/tests/safety/test_cadillac.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import unittest import numpy as np -import libpandasafety_py +import libpandasafety_py # pylint: disable=import-error from panda import Panda MAX_RATE_UP = 2 diff --git a/panda/tests/safety/test_chrysler.py b/panda/tests/safety/test_chrysler.py index 25f50a11f9fb31..37bffe0eaf392b 100755 --- a/panda/tests/safety/test_chrysler.py +++ b/panda/tests/safety/test_chrysler.py @@ -1,9 +1,7 @@ #!/usr/bin/env python3 -import csv -import glob import unittest import numpy as np -import libpandasafety_py +import libpandasafety_py # pylint: disable=import-error from panda import Panda MAX_RATE_UP = 3 diff --git a/panda/tests/safety/test_gm.py b/panda/tests/safety/test_gm.py index e2251f7b557f8f..304dbbe939bf48 100644 --- a/panda/tests/safety/test_gm.py +++ b/panda/tests/safety/test_gm.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import unittest import numpy as np -import libpandasafety_py +import libpandasafety_py # pylint: disable=import-error from panda import Panda MAX_RATE_UP = 7 diff --git a/panda/tests/safety/test_honda.py b/panda/tests/safety/test_honda.py index a5eb04ad6632c5..55a376a2e58a37 100755 --- a/panda/tests/safety/test_honda.py +++ b/panda/tests/safety/test_honda.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import unittest import numpy as np -import libpandasafety_py +import libpandasafety_py # pylint: disable=import-error from panda import Panda MAX_BRAKE = 255 @@ -34,9 +34,9 @@ def _button_msg(self, buttons, msg): to_send = libpandasafety_py.ffi.new('CAN_FIFOMailBox_TypeDef *') to_send[0].RIR = msg << 21 to_send[0].RDLR = buttons << 5 - is_panda_black = self.safety.get_hw_type() == 3 # black_panda + has_relay = self.safety.board_has_relay() honda_bosch_hardware = self.safety.get_honda_bosch_hardware() - bus = 1 if is_panda_black and honda_bosch_hardware else 0 + bus = 1 if has_relay and honda_bosch_hardware else 0 to_send[0].RDTR = bus << 4 return to_send diff --git a/panda/tests/safety/test_honda_bosch.py b/panda/tests/safety/test_honda_bosch.py index 3affc74c9a72f8..7571e1eddc4576 100755 --- a/panda/tests/safety/test_honda_bosch.py +++ b/panda/tests/safety/test_honda_bosch.py @@ -1,7 +1,6 @@ #!/usr/bin/env python3 import unittest -import numpy as np -import libpandasafety_py +import libpandasafety_py # pylint: disable=import-error from panda import Panda MAX_BRAKE = 255 @@ -22,12 +21,13 @@ def _send_msg(self, bus, addr, length): return to_send def test_fwd_hook(self): - buss = list(range(0x0, 0x3)) - msgs = list(range(0x1, 0x800)) - is_panda_black = self.safety.get_hw_type() == 3 # black panda - bus_rdr_cam = 2 if is_panda_black else 1 - bus_rdr_car = 0 if is_panda_black else 2 - bus_pt = 1 if is_panda_black else 0 + buss = range(0x0, 0x3) + msgs = range(0x1, 0x800) + #has_relay = self.safety.get_hw_type() == 3 # black panda + has_relay = self.safety.board_has_relay() + bus_rdr_cam = 2 if has_relay else 1 + bus_rdr_car = 0 if has_relay else 2 + bus_pt = 1 if has_relay else 0 blocked_msgs = [0xE4, 0x33D] for b in buss: diff --git a/panda/tests/safety/test_hyundai.py b/panda/tests/safety/test_hyundai.py index d836dad37b266f..d8fa02691b6d41 100644 --- a/panda/tests/safety/test_hyundai.py +++ b/panda/tests/safety/test_hyundai.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import unittest import numpy as np -import libpandasafety_py +import libpandasafety_py # pylint: disable=import-error from panda import Panda MAX_RATE_UP = 3 diff --git a/panda/tests/safety/test_subaru.py b/panda/tests/safety/test_subaru.py index 93859e0217837b..49933e6636dd3c 100644 --- a/panda/tests/safety/test_subaru.py +++ b/panda/tests/safety/test_subaru.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import unittest import numpy as np -import libpandasafety_py +import libpandasafety_py # pylint: disable=import-error from panda import Panda MAX_RATE_UP = 50 diff --git a/panda/tests/safety/test_toyota.py b/panda/tests/safety/test_toyota.py index af82c5de7cee9d..4d3c9661c85f17 100644 --- a/panda/tests/safety/test_toyota.py +++ b/panda/tests/safety/test_toyota.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import unittest import numpy as np -import libpandasafety_py +import libpandasafety_py # pylint: disable=import-error from panda import Panda MAX_RATE_UP = 10 diff --git a/panda/tests/safety/test_toyota_ipas.py b/panda/tests/safety/test_toyota_ipas.py index 8d565553fd2144..df0f36ffd76e47 100644 --- a/panda/tests/safety/test_toyota_ipas.py +++ b/panda/tests/safety/test_toyota_ipas.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import unittest import numpy as np -import libpandasafety_py +import libpandasafety_py # pylint: disable=import-error from panda import Panda IPAS_OVERRIDE_THRESHOLD = 200 @@ -233,8 +233,8 @@ def test_angle_measured_rate(self): self.safety.safety_tx_hook(self._ipas_control_msg(a, 1)) self.safety.set_controls_allowed(1) self.safety.safety_rx_hook(self._speed_msg(s)) - max_delta_up = int(np.interp(s, ANGLE_DELTA_BP, ANGLE_DELTA_V) * 2 / 3. + 1.) - max_delta_down = int(np.interp(s, ANGLE_DELTA_BP, ANGLE_DELTA_VU) * 2 / 3. + 1.) + #max_delta_up = int(np.interp(s, ANGLE_DELTA_BP, ANGLE_DELTA_V) * 2 / 3. + 1.) + #max_delta_down = int(np.interp(s, ANGLE_DELTA_BP, ANGLE_DELTA_VU) * 2 / 3. + 1.) self.safety.safety_rx_hook(self._angle_meas_msg(a)) self.assertTrue(self.safety.get_controls_allowed()) self.safety.safety_rx_hook(self._angle_meas_msg(a + 150)) diff --git a/panda/tests/safety/test_volkswagen.py b/panda/tests/safety/test_volkswagen.py new file mode 100644 index 00000000000000..aa535cdac9cbf1 --- /dev/null +++ b/panda/tests/safety/test_volkswagen.py @@ -0,0 +1,247 @@ +#!/usr/bin/env python3 +import unittest +import numpy as np +import libpandasafety_py # pylint: disable=import-error +from panda import Panda + +MAX_RATE_UP = 4 +MAX_RATE_DOWN = 10 +MAX_STEER = 250 + +MAX_RT_DELTA = 75 +RT_INTERVAL = 250000 + +DRIVER_TORQUE_ALLOWANCE = 80 +DRIVER_TORQUE_FACTOR = 3 + +def sign(a): + if a > 0: + return 1 + else: + return -1 + +class TestVolkswagenSafety(unittest.TestCase): + @classmethod + def setUp(cls): + cls.safety = libpandasafety_py.libpandasafety + cls.safety.safety_set_mode(Panda.SAFETY_VOLKSWAGEN, 0) + cls.safety.init_tests_volkswagen() + + def _send_msg(self, bus, addr, length): + to_send = libpandasafety_py.ffi.new('CAN_FIFOMailBox_TypeDef *') + to_send[0].RIR = addr << 21 + to_send[0].RDTR = length + to_send[0].RDTR = bus << 4 + return to_send + + def _set_prev_torque(self, t): + self.safety.set_volkswagen_desired_torque_last(t) + self.safety.set_volkswagen_rt_torque_last(t) + + def _torque_driver_msg(self, torque): + to_send = libpandasafety_py.ffi.new('CAN_FIFOMailBox_TypeDef *') + to_send[0].RIR = 0x9F << 21 + + t = abs(torque) + to_send[0].RDHR = ((t & 0x1FFF) << 8) + if torque < 0: + to_send[0].RDHR |= 0x1 << 23 + return to_send + + def _torque_msg(self, torque): + to_send = libpandasafety_py.ffi.new('CAN_FIFOMailBox_TypeDef *') + to_send[0].RIR = 0x126 << 21 + + t = abs(torque) + to_send[0].RDLR = (t & 0xFFF) << 16 + if torque < 0: + to_send[0].RDLR |= 0x1 << 31 + return to_send + + def _gas_msg(self, gas): + to_send = libpandasafety_py.ffi.new('CAN_FIFOMailBox_TypeDef *') + to_send[0].RIR = 0x121 << 21 + to_send[0].RDLR = (gas & 0xFF) << 12 + + return to_send + + def _button_msg(self, bit): + to_send = libpandasafety_py.ffi.new('CAN_FIFOMailBox_TypeDef *') + to_send[0].RIR = 0x12B << 21 + to_send[0].RDLR = 1 << bit + to_send[0].RDTR = 2 << 4 + + return to_send + + def test_prev_gas(self): + for g in range(0, 256): + self.safety.safety_rx_hook(self._gas_msg(g)) + self.assertEqual(g, self.safety.get_volkswagen_gas_prev()) + + def test_default_controls_not_allowed(self): + self.assertFalse(self.safety.get_controls_allowed()) + + def test_enable_control_allowed_from_cruise(self): + to_push = libpandasafety_py.ffi.new('CAN_FIFOMailBox_TypeDef *') + to_push[0].RIR = 0x122 << 21 + to_push[0].RDHR = 0x30000000 + + self.safety.safety_rx_hook(to_push) + self.assertTrue(self.safety.get_controls_allowed()) + + def test_disable_control_allowed_from_cruise(self): + to_push = libpandasafety_py.ffi.new('CAN_FIFOMailBox_TypeDef *') + to_push[0].RIR = 0x122 << 21 + to_push[0].RDHR = 0 + + self.safety.set_controls_allowed(1) + self.safety.safety_rx_hook(to_push) + self.assertFalse(self.safety.get_controls_allowed()) + + def test_disengage_on_gas(self): + for long_controls_allowed in [0, 1]: + self.safety.set_long_controls_allowed(long_controls_allowed) + self.safety.safety_rx_hook(self._gas_msg(0)) + self.safety.set_controls_allowed(True) + self.safety.safety_rx_hook(self._gas_msg(1)) + if long_controls_allowed: + self.assertFalse(self.safety.get_controls_allowed()) + else: + self.assertTrue(self.safety.get_controls_allowed()) + self.safety.set_long_controls_allowed(True) + + def test_allow_engage_with_gas_pressed(self): + self.safety.safety_rx_hook(self._gas_msg(1)) + self.safety.set_controls_allowed(True) + self.safety.safety_rx_hook(self._gas_msg(1)) + self.assertTrue(self.safety.get_controls_allowed()) + self.safety.safety_rx_hook(self._gas_msg(1)) + self.assertTrue(self.safety.get_controls_allowed()) + + + def test_steer_safety_check(self): + for enabled in [0, 1]: + for t in range(-500, 500): + self.safety.set_controls_allowed(enabled) + self._set_prev_torque(t) + if abs(t) > MAX_STEER or (not enabled and abs(t) > 0): + self.assertFalse(self.safety.safety_tx_hook(self._torque_msg(t))) + else: + self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(t))) + + def test_manually_enable_controls_allowed(self): + self.safety.set_controls_allowed(1) + self.assertTrue(self.safety.get_controls_allowed()) + self.safety.set_controls_allowed(0) + self.assertFalse(self.safety.get_controls_allowed()) + + def test_spam_cancel_safety_check(self): + BIT_CANCEL = 13 + BIT_RESUME = 19 + BIT_SET = 16 + self.safety.set_controls_allowed(0) + self.assertTrue(self.safety.safety_tx_hook(self._button_msg(BIT_CANCEL))) + self.assertFalse(self.safety.safety_tx_hook(self._button_msg(BIT_RESUME))) + self.assertFalse(self.safety.safety_tx_hook(self._button_msg(BIT_SET))) + # do not block resume if we are engaged already + self.safety.set_controls_allowed(1) + self.assertTrue(self.safety.safety_tx_hook(self._button_msg(BIT_RESUME))) + + def test_non_realtime_limit_up(self): + self.safety.set_volkswagen_torque_driver(0, 0) + self.safety.set_controls_allowed(True) + + self._set_prev_torque(0) + self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(MAX_RATE_UP))) + self._set_prev_torque(0) + self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(-MAX_RATE_UP))) + + self._set_prev_torque(0) + self.assertFalse(self.safety.safety_tx_hook(self._torque_msg(MAX_RATE_UP + 1))) + self.safety.set_controls_allowed(True) + self._set_prev_torque(0) + self.assertFalse(self.safety.safety_tx_hook(self._torque_msg(-MAX_RATE_UP - 1))) + + def test_non_realtime_limit_down(self): + self.safety.set_volkswagen_torque_driver(0, 0) + self.safety.set_controls_allowed(True) + + def test_against_torque_driver(self): + self.safety.set_controls_allowed(True) + + for sign in [-1, 1]: + for t in np.arange(0, DRIVER_TORQUE_ALLOWANCE + 1, 1): + t *= -sign + self.safety.set_volkswagen_torque_driver(t, t) + self._set_prev_torque(MAX_STEER * sign) + self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(MAX_STEER * sign))) + + self.safety.set_volkswagen_torque_driver(DRIVER_TORQUE_ALLOWANCE + 1, DRIVER_TORQUE_ALLOWANCE + 1) + self.assertFalse(self.safety.safety_tx_hook(self._torque_msg(-MAX_STEER))) + + # spot check some individual cases + for sign in [-1, 1]: + driver_torque = (DRIVER_TORQUE_ALLOWANCE + 10) * sign + torque_desired = (MAX_STEER - 10 * DRIVER_TORQUE_FACTOR) * sign + delta = 1 * sign + self._set_prev_torque(torque_desired) + self.safety.set_volkswagen_torque_driver(-driver_torque, -driver_torque) + self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(torque_desired))) + self._set_prev_torque(torque_desired + delta) + self.safety.set_volkswagen_torque_driver(-driver_torque, -driver_torque) + self.assertFalse(self.safety.safety_tx_hook(self._torque_msg(torque_desired + delta))) + + self._set_prev_torque(MAX_STEER * sign) + self.safety.set_volkswagen_torque_driver(-MAX_STEER * sign, -MAX_STEER * sign) + self.assertTrue(self.safety.safety_tx_hook(self._torque_msg((MAX_STEER - MAX_RATE_DOWN) * sign))) + self._set_prev_torque(MAX_STEER * sign) + self.safety.set_volkswagen_torque_driver(-MAX_STEER * sign, -MAX_STEER * sign) + self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(0))) + self._set_prev_torque(MAX_STEER * sign) + self.safety.set_volkswagen_torque_driver(-MAX_STEER * sign, -MAX_STEER * sign) + self.assertFalse(self.safety.safety_tx_hook(self._torque_msg((MAX_STEER - MAX_RATE_DOWN + 1) * sign))) + + + def test_realtime_limits(self): + self.safety.set_controls_allowed(True) + + for sign in [-1, 1]: + self.safety.init_tests_volkswagen() + self._set_prev_torque(0) + self.safety.set_volkswagen_torque_driver(0, 0) + for t in np.arange(0, MAX_RT_DELTA, 1): + t *= sign + self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(t))) + self.assertFalse(self.safety.safety_tx_hook(self._torque_msg(sign * (MAX_RT_DELTA + 1)))) + + self._set_prev_torque(0) + for t in np.arange(0, MAX_RT_DELTA, 1): + t *= sign + self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(t))) + + # Increase timer to update rt_torque_last + self.safety.set_timer(RT_INTERVAL + 1) + self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(sign * (MAX_RT_DELTA - 1)))) + self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(sign * (MAX_RT_DELTA + 1)))) + + + def test_fwd_hook(self): + buss = list(range(0x0, 0x2)) + msgs = list(range(0x1, 0x800)) + blocked_msgs_0to2 = [] + blocked_msgs_2to0 = [0x122, 0x397] + for b in buss: + for m in msgs: + if b == 0: + fwd_bus = -1 if m in blocked_msgs_0to2 else 2 + elif b == 1: + fwd_bus = -1 + elif b == 2: + fwd_bus = -1 if m in blocked_msgs_2to0 else 0 + + # assume len 8 + self.assertEqual(fwd_bus, self.safety.safety_fwd_hook(b, self._send_msg(b, m, 8))) + + +if __name__ == "__main__": + unittest.main() diff --git a/panda/tests/safety_replay/Dockerfile b/panda/tests/safety_replay/Dockerfile index 80663964d3e2da..f5175c74582005 100644 --- a/panda/tests/safety_replay/Dockerfile +++ b/panda/tests/safety_replay/Dockerfile @@ -14,8 +14,10 @@ RUN pyenv install 3.7.3 RUN pyenv global 3.7.3 RUN pyenv rehash -COPY tests/safety_replay/requirements.txt requirements.txt -RUN pip install -r requirements.txt +COPY requirements.txt /tmp/ +RUN pip install -r /tmp/requirements.txt +COPY tests/safety_replay/requirements_extra.txt requirements_extra.txt +RUN pip install -r requirements_extra.txt COPY tests/safety_replay/install_capnp.sh install_capnp.sh RUN ./install_capnp.sh diff --git a/panda/tests/safety_replay/replay_drive.py b/panda/tests/safety_replay/replay_drive.py index d92ab8e7080533..3db57dfd168fae 100755 --- a/panda/tests/safety_replay/replay_drive.py +++ b/panda/tests/safety_replay/replay_drive.py @@ -2,12 +2,9 @@ import os import sys -from panda import Panda import panda.tests.safety.libpandasafety_py as libpandasafety_py -from panda.tests.safety_replay.helpers import is_steering_msg, get_steer_torque, \ - set_desired_torque_last, package_can_msg, \ - init_segment -from tools.lib.logreader import LogReader +from panda.tests.safety_replay.helpers import package_can_msg, init_segment +from tools.lib.logreader import LogReader # pylint: disable=import-error # replay a drive to check for safety violations def replay_drive(lr, safety_mode, param): diff --git a/panda/tests/safety_replay/requirements.txt b/panda/tests/safety_replay/requirements.txt deleted file mode 100644 index 4c9d301dce0b4d..00000000000000 --- a/panda/tests/safety_replay/requirements.txt +++ /dev/null @@ -1,8 +0,0 @@ -aenum -cffi==1.11.4 -libusb1==1.6.6 -numpy==1.14.5 -requests -subprocess32 -libarchive -pycapnp diff --git a/panda/tests/safety_replay/requirements_extra.txt b/panda/tests/safety_replay/requirements_extra.txt new file mode 100644 index 00000000000000..b04b7674d76efa --- /dev/null +++ b/panda/tests/safety_replay/requirements_extra.txt @@ -0,0 +1,4 @@ +aenum +subprocess32 +libarchive +pycapnp diff --git a/panda/tests/safety_replay/test_safety_replay.py b/panda/tests/safety_replay/test_safety_replay.py index e6e49dc02d8556..cb38a94edff66a 100755 --- a/panda/tests/safety_replay/test_safety_replay.py +++ b/panda/tests/safety_replay/test_safety_replay.py @@ -5,7 +5,7 @@ from panda import Panda from replay_drive import replay_drive -from tools.lib.logreader import LogReader +from tools.lib.logreader import LogReader # pylint: disable=import-error BASE_URL = "https://commadataci.blob.core.windows.net/openpilotci/" diff --git a/panda/tests/spam_can.py b/panda/tests/spam_can.py index 6b0c2d9c60a581..1daffdbd91009d 100755 --- a/panda/tests/spam_can.py +++ b/panda/tests/spam_can.py @@ -2,7 +2,6 @@ import os import sys -import time import random sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) @@ -21,4 +20,4 @@ def get_test_string(): st = get_test_string()[0:8] bus = random.randint(0, 2) p.can_send(at, st, bus) - #print("Sent message on bus: ", bus) \ No newline at end of file + #print("Sent message on bus: ", bus) diff --git a/panda/tests/throughput_test.py b/panda/tests/throughput_test.py index 69b06c7646d0b2..9f6021240173e9 100755 --- a/panda/tests/throughput_test.py +++ b/panda/tests/throughput_test.py @@ -25,7 +25,7 @@ # p_in.can_recv() #sys.exit(0) - p_out.set_controls_allowed(True) + p_out.set_safety_mode(Panda.SAFETY_ALLOUTPUT) set_out, set_in = set(), set() diff --git a/panda/tests/tucan_loopback.py b/panda/tests/tucan_loopback.py index 1b5ed016633837..cb5d1cbfea12e8 100755 --- a/panda/tests/tucan_loopback.py +++ b/panda/tests/tucan_loopback.py @@ -33,7 +33,7 @@ def run_test_w_pandas(pandas, sleep_duration): print("H", h) for hh in h: - hh.set_controls_allowed(True) + hh.set_safety_mode(Panda.SAFETY_ALLOUTPUT) # test both directions for ho in permutations(list(range(len(h))), r=2): @@ -55,7 +55,7 @@ def run_test_w_pandas(pandas, sleep_duration): # send the characters st = get_test_string() - st = b"\xaa"+chr(len(st)+3).encode()+st + st = bytes([0xaa, len(st) + 3]) + st h[ho[0]].kline_send(st, bus=bus, checksum=False) # check for receive @@ -70,8 +70,8 @@ def run_test_w_pandas(pandas, sleep_duration): time.sleep(sleep_duration) # **** test can line loopback **** -# for bus, gmlan in [(0, None), (1, False), (2, False), (1, True), (2, True)]: -for bus, gmlan in [(0, None), (1, None)]: + # for bus, gmlan in [(0, None), (1, False), (2, False), (1, True), (2, True)]: + for bus, gmlan in [(0, None), (1, None)]: print("\ntest can", bus) # flush cans_echo = panda0.can_recv() diff --git a/phonelibs/yaml-cpp/lib/libyaml-cpp.a b/phonelibs/yaml-cpp/lib/libyaml-cpp.a index c03917510782c7..f871781d35c297 100644 Binary files a/phonelibs/yaml-cpp/lib/libyaml-cpp.a and b/phonelibs/yaml-cpp/lib/libyaml-cpp.a differ diff --git a/phonelibs/yaml-cpp/x64/lib/libyaml-cpp.a b/phonelibs/yaml-cpp/x64/lib/libyaml-cpp.a new file mode 100644 index 00000000000000..eb1a3637d93605 Binary files /dev/null and b/phonelibs/yaml-cpp/x64/lib/libyaml-cpp.a differ diff --git a/run_docker_tests.sh b/run_docker_tests.sh old mode 100755 new mode 100644 index 2726baaeb565f3..7d2484d79a60a2 --- a/run_docker_tests.sh +++ b/run_docker_tests.sh @@ -1,16 +1,19 @@ #!/bin/bash set -e +SETUP="cd /tmp/openpilot && make -C cereal && " + docker build -t tmppilot -f Dockerfile.openpilot . -docker run --rm tmppilot /bin/sh -c 'cd /tmp/openpilot/ && make -C cereal && cd /tmp/openpilot/selfdrive/test/ && ./test_fingerprints.py' -#docker run --rm tmppilot /bin/sh -c 'cd /tmp/openpilot/ && pyflakes $(find . -iname "*.py" | grep -vi "^\./pyextra.*" | grep -vi "^\./panda" | grep -vi "^\./tools")' -#docker run --rm tmppilot /bin/sh -c 'cd /tmp/openpilot/ && pylint $(find . -iname "*.py" | grep -vi "^\./pyextra.*" | grep -vi "^\./panda" | grep -vi "^\./tools"); exit $(($? & 3))' -docker run --rm tmppilot /bin/sh -c 'cd /tmp/openpilot/ && make -C cereal && python -m unittest discover common' -docker run --rm tmppilot /bin/sh -c 'cd /tmp/openpilot/ && make -C cereal && python -m unittest discover selfdrive/can' -docker run --rm tmppilot /bin/sh -c 'cd /tmp/openpilot/ && make -C cereal && python -m unittest discover selfdrive/boardd' -docker run --rm tmppilot /bin/sh -c 'cd /tmp/openpilot/ && make -C cereal && python -m unittest discover selfdrive/controls' -docker run --rm tmppilot /bin/sh -c 'cd /tmp/openpilot/ && python -m unittest discover selfdrive/loggerd' -docker run --rm -v "$(pwd)"/selfdrive/test/longitudinal_maneuvers/out:/tmp/openpilot/selfdrive/test/longitudinal_maneuvers/out tmppilot /bin/sh -c 'cd /tmp/openpilot/selfdrive/test/longitudinal_maneuvers && OPTEST=1 ./test_longitudinal.py' -docker run --rm tmppilot /bin/sh -c 'cd /tmp/openpilot/ && make -C cereal && cd /tmp/openpilot/selfdrive/test/process_replay/ && ./test_processes.py' -docker run --rm tmppilot /bin/sh -c 'mkdir -p /data/params && cd /tmp/openpilot/ && make -C cereal && cd /tmp/openpilot/selfdrive/test/ && ./test_car_models.py' + +docker run --rm tmppilot /bin/sh -c "$SETUP cd /tmp/openpilot/selfdrive/test/ && ./test_fingerprints.py" +# docker run --rm tmppilot /bin/sh -c 'cd /tmp/openpilot/ && flake8 --select=F $(find . -iname "*.py" | grep -vi "^\./pyextra.*" | grep -vi "^\./panda" | grep -vi "^\./tools")' +# docker run --rm tmppilot /bin/sh -c 'cd /tmp/openpilot/ && pylint $(find . -iname "*.py" | grep -vi "^\./pyextra.*" | grep -vi "^\./panda" | grep -vi "^\./tools"); exit $(($? & 3))' +docker run --rm tmppilot /bin/sh -c "$SETUP python -m unittest discover common" +docker run --rm tmppilot /bin/sh -c "$SETUP make -C selfdrive/can -j4 && python -m unittest discover selfdrive/can" +docker run --rm tmppilot /bin/sh -c "$SETUP python -m unittest discover selfdrive/boardd" +docker run --rm tmppilot /bin/sh -c "$SETUP make -C selfdrive/can -j4 && python -m unittest discover selfdrive/controls" +docker run --rm tmppilot /bin/sh -c "$SETUP python -m unittest discover selfdrive/loggerd" +docker run --rm -v "$(pwd)"/selfdrive/test/longitudinal_maneuvers/out:/tmp/openpilot/selfdrive/test/longitudinal_maneuvers/out tmppilot /bin/sh -c "$SETUP make -C selfdrive/can -j4 && cd /tmp/openpilot/selfdrive/test/longitudinal_maneuvers && OPTEST=1 ./test_longitudinal.py" +docker run --rm tmppilot /bin/sh -c "$SETUP make -C selfdrive/can -j4 && cd /tmp/openpilot/selfdrive/test/process_replay/ && ./test_processes.py" +docker run --rm tmppilot /bin/sh -c "$SETUP make -C selfdrive/can -j4 && mkdir -p /data/params && cd /tmp/openpilot/selfdrive/test/ && ./test_car_models.py" diff --git a/selfdrive/athena/athenad.py b/selfdrive/athena/athenad.py old mode 100755 new mode 100644 index 1474b346ba780d..d3b98e71314798 --- a/selfdrive/athena/athenad.py +++ b/selfdrive/athena/athenad.py @@ -10,22 +10,19 @@ import time import threading import traceback -import zmq import base64 import requests -import six.moves.queue +import queue from functools import partial from jsonrpc import JSONRPCResponseManager, dispatcher from websocket import create_connection, WebSocketTimeoutException, ABNF from selfdrive.loggerd.config import ROOT -import selfdrive.crash as crash import selfdrive.messaging as messaging from common.api import Api from common.params import Params from selfdrive.services import service_list from selfdrive.swaglog import cloudlog -from selfdrive.version import version, dirty from functools import reduce ATHENA_HOST = os.getenv('ATHENA_HOST', 'wss://athena.comma.ai') @@ -33,8 +30,8 @@ LOCAL_PORT_WHITELIST = set([8022]) dispatcher["echo"] = lambda s: s -payload_queue = six.moves.queue.Queue() -response_queue = six.moves.queue.Queue() +payload_queue = queue.Queue() +response_queue = queue.Queue() def handle_long_poll(ws): end_event = threading.Event() @@ -66,7 +63,7 @@ def jsonrpc_handler(end_event): data = payload_queue.get(timeout=1) response = JSONRPCResponseManager.handle(data, dispatcher) response_queue.put_nowait(response) - except six.moves.queue.Empty: + except queue.Empty: pass except Exception as e: cloudlog.exception("athena jsonrpc handler failed") @@ -79,8 +76,8 @@ def jsonrpc_handler(end_event): def getMessage(service=None, timeout=1000): if service is None or service not in service_list: raise Exception("invalid service") - socket = messaging.sub_sock(service_list[service].port) - socket.setsockopt(zmq.RCVTIMEO, timeout) + socket = messaging.sub_sock(service) + socket.setTimeout(timeout) ret = messaging.recv_one(socket) return ret.to_dict() @@ -99,8 +96,6 @@ def uploadFileToUrl(fn, url, headers): def startLocalProxy(global_end_event, remote_ws_uri, local_port): try: - cloudlog.event("athena startLocalProxy", remote_ws_uri=remote_ws_uri, local_port=local_port) - if local_port not in LOCAL_PORT_WHITELIST: raise Exception("Requested local port not whitelisted") @@ -169,9 +164,12 @@ def takeSnapshot(): ret = snapshot() if ret is not None: def b64jpeg(x): - f = io.BytesIO() - jpeg_write(f, x) - return base64.b64encode(f.getvalue()).decode("utf-8") + if x is not None: + f = io.BytesIO() + jpeg_write(f, x) + return base64.b64encode(f.getvalue()).decode("utf-8") + else: + return None return {'jpegBack': b64jpeg(ret[0]), 'jpegFront': b64jpeg(ret[1])} else: @@ -185,6 +183,7 @@ def ws_proxy_recv(ws, local_sock, ssock, end_event, global_end_event): except WebSocketTimeoutException: pass except Exception: + cloudlog.exception("athenad.ws_proxy_recv.exception") traceback.print_exc() break @@ -208,8 +207,9 @@ def ws_proxy_send(ws, local_sock, signal_sock, end_event): ws.send(data, ABNF.OPCODE_BINARY) except Exception: - traceback.print_exc() - end_event.set() + cloudlog.exception("athenad.ws_proxy_send.exception") + traceback.print_exc() + end_event.set() def ws_recv(ws, end_event): while not end_event.is_set(): @@ -219,6 +219,7 @@ def ws_recv(ws, end_event): except WebSocketTimeoutException: pass except Exception: + cloudlog.exception("athenad.ws_recv.exception") traceback.print_exc() end_event.set() @@ -227,9 +228,10 @@ def ws_send(ws, end_event): try: response = response_queue.get(timeout=1) ws.send(response.json) - except six.moves.queue.Empty: + except queue.Empty: pass except Exception: + cloudlog.exception("athenad.ws_send.exception") traceback.print_exc() end_event.set() @@ -241,31 +243,26 @@ def main(gctx=None): dongle_id = params.get("DongleId").decode('utf-8') ws_uri = ATHENA_HOST + "/ws/v2/" + dongle_id - crash.bind_user(id=dongle_id) - crash.bind_extra(version=version, dirty=dirty, is_eon=True) - crash.install() - api = Api(dongle_id) conn_retries = 0 while 1: try: - print("connecting to %s" % ws_uri) ws = create_connection(ws_uri, cookie="jwt=" + api.get_token(), enable_multithread=True) + cloudlog.event("athenad.main.connected_ws", ws_uri=ws_uri) ws.settimeout(1) conn_retries = 0 handle_long_poll(ws) except (KeyboardInterrupt, SystemExit): break except Exception: + cloudlog.exception("athenad.main.exception") conn_retries += 1 traceback.print_exc() time.sleep(backoff(conn_retries)) - params.delete("AthenadPid") - if __name__ == "__main__": main() diff --git a/selfdrive/athena/manage_athenad.py b/selfdrive/athena/manage_athenad.py new file mode 100644 index 00000000000000..034bfac5cb0dad --- /dev/null +++ b/selfdrive/athena/manage_athenad.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 + +import time +from multiprocessing import Process + +import selfdrive.crash as crash +from common.params import Params +from selfdrive.manager import launcher +from selfdrive.swaglog import cloudlog +from selfdrive.version import version, dirty + +ATHENA_MGR_PID_PARAM = "AthenadPid" + +def main(): + params = Params() + dongle_id = params.get("DongleId").decode('utf-8') + cloudlog.bind_global(dongle_id=dongle_id, version=version, dirty=dirty, is_eon=True) + crash.bind_user(id=dongle_id) + crash.bind_extra(version=version, dirty=dirty, is_eon=True) + crash.install() + + try: + while 1: + cloudlog.info("starting athena daemon") + proc = Process(name='athenad', target=launcher, args=('selfdrive.athena.athenad',)) + proc.start() + proc.join() + cloudlog.event("athenad exited", exitcode=proc.exitcode) + time.sleep(5) + except: + cloudlog.exception("manage_athenad.exception") + finally: + params.delete(ATHENA_MGR_PID_PARAM) + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/selfdrive/boardd/Makefile b/selfdrive/boardd/Makefile index 67a315d8d98e82..f9d0155c6f27f1 100644 --- a/selfdrive/boardd/Makefile +++ b/selfdrive/boardd/Makefile @@ -16,7 +16,8 @@ WARN_FLAGS = -Werror=implicit-function-declaration \ CFLAGS = -std=gnu11 -g -fPIC -I../ -I../../ -O2 $(WARN_FLAGS) CXXFLAGS = -std=c++11 -g -fPIC -I../ -I../../ -O2 $(WARN_FLAGS) -ZMQ_LIBS = -l:libczmq.a -l:libzmq.a -lgnustl_shared +MESSAGING_FLAGS = -I$(BASEDIR)/selfdrive/messaging +MESSAGING_LIBS = $(BASEDIR)/selfdrive/messaging/messaging.a JSON_FLAGS = -I$(PHONELIBS)/json/src @@ -31,13 +32,12 @@ EXTRA_LIBS = -lusb-1.0 ifeq ($(ARCH),aarch64) CFLAGS += -mcpu=cortex-a57 CXXFLAGS += -mcpu=cortex-a57 +EXTRA_LIBS += -lgnustl_shared endif ifeq ($(ARCH),x86_64) ZMQ_FLAGS = -I$(PHONELIBS)/zmq/aarch64/include -ZMQ_LIBS = -L$(BASEDIR)/external/zmq/lib/ \ - -l:libczmq.a -l:libzmq.a EXTRA_LIBS = -lusb-1.0 -lpthread CXXFLAGS += -I/usr/include/libusb-1.0 CFLAGS += -I/usr/include/libusb-1.0 @@ -58,11 +58,10 @@ OBJS = boardd.o \ DEPS := $(OBJS:.o=.d) -boardd: $(OBJS) +boardd: $(OBJS) $(MESSAGING_LIBS) @echo "[ LINK ] $@" $(CXX) -fPIC -o '$@' $^ \ $(CEREAL_LIBS) \ - $(ZMQ_LIBS) \ $(EXTRA_LIBS) boardd.o: boardd.cc @@ -72,6 +71,7 @@ boardd.o: boardd.cc $(CEREAL_CFLAGS) \ $(CEREAL_CXXFLAGS) \ $(ZMQ_FLAGS) \ + $(MESSAGING_FLAGS) \ -I../ \ -I../../ \ -c -o '$@' '$<' @@ -100,6 +100,7 @@ libcan_list_to_can_capnp.a: can_list_to_can_capnp.o $(CEREAL_OBJS) -Iinclude -I.. -I../.. \ $(CEREAL_CXXFLAGS) \ $(ZMQ_FLAGS) \ + $(MESSAGING_FLAGS) \ -c -o '$@' '$<' .PHONY: clean diff --git a/selfdrive/boardd/boardd.cc b/selfdrive/boardd/boardd.cc index fde2b3ea21ca2d..b94bf3a3ed23f4 100644 --- a/selfdrive/boardd/boardd.cc +++ b/selfdrive/boardd/boardd.cc @@ -1,11 +1,12 @@ #include +#include #include #include #include #include #include #include -#include +#include #include #include #include @@ -14,7 +15,6 @@ #include #include -#include #include #include @@ -25,6 +25,7 @@ #include "common/params.h" #include "common/swaglog.h" #include "common/timing.h" +#include "messaging.hpp" #include @@ -36,6 +37,16 @@ namespace { volatile sig_atomic_t do_exit = 0; +struct __attribute__((packed)) timestamp_t { + uint16_t year; + uint8_t month; + uint8_t day; + uint8_t weekday; + uint8_t hour; + uint8_t minute; + uint8_t second; +}; + libusb_context *ctx = NULL; libusb_device_handle *dev_handle; pthread_mutex_t usb_lock; @@ -48,8 +59,7 @@ bool is_pigeon = false; const uint32_t NO_IGNITION_CNT_MAX = 2 * 60 * 60 * 24 * 3; // turn off charge after 3 days uint32_t no_ignition_cnt = 0; bool connected_once = false; -uint8_t ignition_last = 0; -bool safety_model_locked = false; +bool ignition_last = false; pthread_t safety_setter_thread_handle = -1; pthread_t pigeon_thread_handle = -1; @@ -76,11 +86,9 @@ void *safety_setter_thread(void *s) { LOGW("got CarVin %s", value_vin); // VIN query done, stop listening to OBDII - if (!safety_model_locked) { - pthread_mutex_lock(&usb_lock); - libusb_control_transfer(dev_handle, 0x40, 0xdc, (uint16_t)(cereal::CarParams::SafetyModel::NO_OUTPUT), 0, NULL, 0, TIMEOUT); - pthread_mutex_unlock(&usb_lock); - } + pthread_mutex_lock(&usb_lock); + libusb_control_transfer(dev_handle, 0x40, 0xdc, (uint16_t)(cereal::CarParams::SafetyModel::NO_OUTPUT), 0, NULL, 0, TIMEOUT); + pthread_mutex_unlock(&usb_lock); char *value; size_t value_sz = 0; @@ -103,7 +111,7 @@ void *safety_setter_thread(void *s) { capnp::FlatArrayMessageReader cmsg(amsg); cereal::CarParams::Reader car_params = cmsg.getRoot(); - auto safety_model = car_params.getSafetyModel(); + int safety_model = int(car_params.getSafetyModel()); auto safety_param = car_params.getSafetyParam(); LOGW("setting safety model: %d with param %d", safety_model, safety_param); @@ -115,7 +123,7 @@ void *safety_setter_thread(void *s) { // set if long_control is allowed by openpilot. Hardcoded to True for now libusb_control_transfer(dev_handle, 0x40, 0xdf, 1, 0, NULL, 0, TIMEOUT); - libusb_control_transfer(dev_handle, 0x40, 0xdc, (uint16_t)(cereal::CarParams::SafetyModel(safety_model)), safety_param, NULL, 0, TIMEOUT); + libusb_control_transfer(dev_handle, 0x40, 0xdc, safety_model, safety_param, NULL, 0, TIMEOUT); pthread_mutex_unlock(&usb_lock); @@ -126,12 +134,14 @@ void *safety_setter_thread(void *s) { bool usb_connect() { int err; unsigned char hw_query[1] = {0}; - char *value_safety_model; - size_t value_safety_model_sz = 0; - int safety_model; - const int result = read_db_value(NULL, "SafetyModelLock", &value_safety_model, &value_safety_model_sz); + unsigned char fw_ver_buf[64]; + unsigned char serial_buf[16]; + const char *fw_ver; + const char *serial; + int fw_ver_sz = 0; + int serial_sz = 0; - ignition_last = 0; + ignition_last = false; dev_handle = libusb_open_device_with_vid_pid(ctx, 0xbbaa, 0xddcc); if (dev_handle == NULL) { goto fail; } @@ -146,15 +156,26 @@ bool usb_connect() { libusb_control_transfer(dev_handle, 0xc0, 0xe5, 1, 0, NULL, 0, TIMEOUT); } - // check if safety mode is forced (needed to support gm) - if (value_safety_model_sz > 0) { - sscanf(value_safety_model, "%d", &safety_model); - // sanity check that we are not setting all output - assert(safety_model != (int)(cereal::CarParams::SafetyModel::ALL_OUTPUT)); - safety_model_locked = true; - LOGW("Setting Locked Safety Model %s", value_safety_model); - libusb_control_transfer(dev_handle, 0x40, 0xdc, (uint16_t)(cereal::CarParams::SafetyModel(safety_model)), 0, NULL, 0, TIMEOUT); + // get panda fw + err = libusb_control_transfer(dev_handle, 0xc0, 0xd6, 0, 0, fw_ver_buf, 64, TIMEOUT); + if (err > 0) { + fw_ver = (const char *)fw_ver_buf; + fw_ver_sz = err; + write_db_value(NULL, "PandaFirmware", fw_ver, fw_ver_sz); + printf("panda fw: %.*s\n", fw_ver_sz, fw_ver); } + else { goto fail; } + + // get panda serial + err = libusb_control_transfer(dev_handle, 0xc0, 0xd0, 0, 0, serial_buf, 16, TIMEOUT); + + if (err > 0) { + serial = (const char *)serial_buf; + serial_sz = strnlen(serial, err); + write_db_value(NULL, "PandaDongleId", serial, serial_sz); + printf("panda serial: %.*s\n", serial_sz, serial); + } + else { goto fail; } // power off ESP libusb_control_transfer(dev_handle, 0xc0, 0xd9, 0, 0, NULL, 0, TIMEOUT); @@ -182,6 +203,38 @@ bool usb_connect() { } } + if (hw_type == cereal::HealthData::HwType::UNO){ + // Get time from system + time_t rawtime; + time(&rawtime); + + struct tm * sys_time = gmtime(&rawtime); + + // Get time from RTC + timestamp_t rtc_time; + libusb_control_transfer(dev_handle, 0xc0, 0xa0, 0, 0, (unsigned char*)&rtc_time, sizeof(rtc_time), TIMEOUT); + + //printf("System: %d-%d-%d\t%d:%d:%d\n", 1900 + sys_time->tm_year, 1 + sys_time->tm_mon, sys_time->tm_mday, sys_time->tm_hour, sys_time->tm_min, sys_time->tm_sec); + //printf("RTC: %d-%d-%d\t%d:%d:%d\n", rtc_time.year, rtc_time.month, rtc_time.day, rtc_time.hour, rtc_time.minute, rtc_time.second); + + // Update system time from RTC if it looks off, and RTC time is good + if (1900 + sys_time->tm_year < 2019 && rtc_time.year >= 2019){ + LOGE("System time wrong, setting from RTC"); + + struct tm new_time = { 0 }; + new_time.tm_year = rtc_time.year - 1900; + new_time.tm_mon = rtc_time.month - 1; + new_time.tm_mday = rtc_time.day; + new_time.tm_hour = rtc_time.hour; + new_time.tm_min = rtc_time.minute; + new_time.tm_sec = rtc_time.second; + + setenv("TZ","UTC",1); + const struct timeval tv = {mktime(&new_time), 0}; + settimeofday(&tv, 0); + } + } + return true; fail: return false; @@ -202,7 +255,7 @@ void handle_usb_issue(int err, const char func[]) { // TODO: check other errors, is simply retrying okay? } -void can_recv(void *s) { +void can_recv(PubSocket *publisher) { int err; uint32_t data[RECV_SIZE/4]; int recv; @@ -256,10 +309,10 @@ void can_recv(void *s) { // send to can auto words = capnp::messageToFlatArray(msg); auto bytes = words.asBytes(); - zmq_send(s, bytes.begin(), bytes.size(), 0); + publisher->send((char*)bytes.begin(), bytes.size()); } -void can_health(void *s) { +void can_health(PubSocket *publisher) { int cnt; int err; @@ -270,11 +323,13 @@ void can_health(void *s) { uint32_t can_send_errs; uint32_t can_fwd_errs; uint32_t gmlan_send_errs; - uint8_t started; + uint8_t ignition_line; + uint8_t ignition_can; uint8_t controls_allowed; uint8_t gas_interceptor_detected; uint8_t car_harness_status; uint8_t usb_power_mode; + uint8_t safety_model; } health; // recv from board @@ -289,7 +344,9 @@ void can_health(void *s) { pthread_mutex_unlock(&usb_lock); - if (health.started == 0) { + bool ignition = ((health.ignition_line != 0) || (health.ignition_can != 0)); + + if (!ignition) { no_ignition_cnt += 1; } else { no_ignition_cnt = 0; @@ -305,7 +362,7 @@ void can_health(void *s) { #endif // clear VIN, CarParams, and set new safety on car start - if ((health.started != 0) && (ignition_last == 0)) { + if (ignition && !ignition_last) { int result = delete_db_value(NULL, "CarVin"); assert((result == 0) || (result == ERR_NO_VALUE)); @@ -313,18 +370,46 @@ void can_health(void *s) { assert((result == 0) || (result == ERR_NO_VALUE)); // diagnostic only is the default, needed for VIN query - if (!safety_model_locked) { - pthread_mutex_lock(&usb_lock); - libusb_control_transfer(dev_handle, 0x40, 0xdc, (uint16_t)(cereal::CarParams::SafetyModel::ELM327), 0, NULL, 0, TIMEOUT); - pthread_mutex_unlock(&usb_lock); - } + pthread_mutex_lock(&usb_lock); + libusb_control_transfer(dev_handle, 0x40, 0xdc, (uint16_t)(cereal::CarParams::SafetyModel::ELM327), 0, NULL, 0, TIMEOUT); + pthread_mutex_unlock(&usb_lock); + if (safety_setter_thread_handle == -1) { err = pthread_create(&safety_setter_thread_handle, NULL, safety_setter_thread, NULL); assert(err == 0); } } - ignition_last = health.started; + // Get fan RPM + uint16_t fan_speed_rpm = 0; + + pthread_mutex_lock(&usb_lock); + int sz = libusb_control_transfer(dev_handle, 0xc0, 0xb2, 0, 0, (unsigned char*)&fan_speed_rpm, sizeof(fan_speed_rpm), TIMEOUT); + pthread_mutex_unlock(&usb_lock); + + // Write to rtc once per minute when no ignition present + if ((hw_type == cereal::HealthData::HwType::UNO) && !ignition && (no_ignition_cnt % 120 == 1)){ + // Get time from system + time_t rawtime; + time(&rawtime); + + struct tm * sys_time = gmtime(&rawtime); + + // Write time to RTC if it looks reasonable + if (1900 + sys_time->tm_year >= 2019){ + pthread_mutex_lock(&usb_lock); + libusb_control_transfer(dev_handle, 0x40, 0xa1, (uint16_t)(1900 + sys_time->tm_year), 0, NULL, 0, TIMEOUT); + libusb_control_transfer(dev_handle, 0x40, 0xa2, (uint16_t)(1 + sys_time->tm_mon), 0, NULL, 0, TIMEOUT); + libusb_control_transfer(dev_handle, 0x40, 0xa3, (uint16_t)sys_time->tm_mday, 0, NULL, 0, TIMEOUT); + // libusb_control_transfer(dev_handle, 0x40, 0xa4, (uint16_t)(1 + sys_time->tm_wday), 0, NULL, 0, TIMEOUT); + libusb_control_transfer(dev_handle, 0x40, 0xa5, (uint16_t)sys_time->tm_hour, 0, NULL, 0, TIMEOUT); + libusb_control_transfer(dev_handle, 0x40, 0xa6, (uint16_t)sys_time->tm_min, 0, NULL, 0, TIMEOUT); + libusb_control_transfer(dev_handle, 0x40, 0xa7, (uint16_t)sys_time->tm_sec, 0, NULL, 0, TIMEOUT); + pthread_mutex_unlock(&usb_lock); + } + } + + ignition_last = ignition; // create message capnp::MallocMessageBuilder msg; @@ -336,10 +421,11 @@ void can_health(void *s) { healthData.setVoltage(health.voltage); healthData.setCurrent(health.current); if (spoofing_started) { - healthData.setStarted(1); + healthData.setIgnitionLine(1); } else { - healthData.setStarted(health.started); + healthData.setIgnitionLine(health.ignition_line); } + healthData.setIgnitionCan(health.ignition_can); healthData.setControlsAllowed(health.controls_allowed); healthData.setGasInterceptorDetected(health.gas_interceptor_detected); healthData.setHasGps(is_pigeon); @@ -348,11 +434,13 @@ void can_health(void *s) { healthData.setGmlanSendErrs(health.gmlan_send_errs); healthData.setHwType(hw_type); healthData.setUsbPowerMode(cereal::HealthData::UsbPowerMode(health.usb_power_mode)); + healthData.setSafetyModel(cereal::CarParams::SafetyModel(health.safety_model)); + healthData.setFanSpeedRpm(fan_speed_rpm); // send to health auto words = capnp::messageToFlatArray(msg); auto bytes = words.asBytes(); - zmq_send(s, bytes.begin(), bytes.size(), 0); + publisher->send((char*)bytes.begin(), bytes.size()); pthread_mutex_lock(&usb_lock); @@ -363,24 +451,20 @@ void can_health(void *s) { } -void can_send(void *s) { +void can_send(SubSocket *subscriber) { int err; // recv from sendcan - zmq_msg_t msg; - zmq_msg_init(&msg); - err = zmq_msg_recv(&msg, s, 0); - assert(err >= 0); + Message * msg = subscriber->receive(); - // format for board, make copy due to alignment issues, will be freed on out of scope - auto amsg = kj::heapArray((zmq_msg_size(&msg) / sizeof(capnp::word)) + 1); - memcpy(amsg.begin(), zmq_msg_data(&msg), zmq_msg_size(&msg)); + auto amsg = kj::heapArray((msg->getSize() / sizeof(capnp::word)) + 1); + memcpy(amsg.begin(), msg->getData(), msg->getSize()); capnp::FlatArrayMessageReader cmsg(amsg); cereal::Event::Reader event = cmsg.getRoot(); if (nanos_since_boot() - event.getLogMonoTime() > 1e9) { //Older than 1 second. Dont send. - zmq_msg_close(&msg); + delete msg; return; } int msg_count = event.getCan().size(); @@ -403,7 +487,7 @@ void can_send(void *s) { } // release msg - zmq_msg_close(&msg); + delete msg; // send to board int sent; @@ -428,15 +512,17 @@ void *can_send_thread(void *crap) { LOGD("start send thread"); // sendcan = 8017 - void *context = zmq_ctx_new(); - void *subscriber = sub_sock(context, "tcp://127.0.0.1:8017"); + Context * context = Context::create(); + SubSocket * subscriber = SubSocket::create(context, "sendcan"); + // drain sendcan to delete any stale messages from previous runs - zmq_msg_t msg; - zmq_msg_init(&msg); - int err = 0; - while(err >= 0) { - err = zmq_msg_recv(&msg, subscriber, ZMQ_DONTWAIT); + while (true){ + Message * msg = subscriber->receive(true); + if (msg == NULL){ + break; + } + delete msg; } // run as fast as messages come in @@ -450,9 +536,8 @@ void *can_recv_thread(void *crap) { LOGD("start recv thread"); // can = 8006 - void *context = zmq_ctx_new(); - void *publisher = zmq_socket(context, ZMQ_PUB); - zmq_bind(publisher, "tcp://*:8006"); + Context * c = Context::create(); + PubSocket * publisher = PubSocket::create(c, "can"); // run at 100hz const uint64_t dt = 10000000ULL; @@ -479,9 +564,8 @@ void *can_recv_thread(void *crap) { void *can_health_thread(void *crap) { LOGD("start health thread"); // health = 8011 - void *context = zmq_ctx_new(); - void *publisher = zmq_socket(context, ZMQ_PUB); - zmq_bind(publisher, "tcp://*:8011"); + Context * c = Context::create(); + PubSocket * publisher = PubSocket::create(c, "health"); // run at 2hz while (!do_exit) { @@ -491,6 +575,69 @@ void *can_health_thread(void *crap) { return NULL; } +void *hardware_control_thread(void *crap) { + LOGD("start hardware control thread"); + Context * c = Context::create(); + SubSocket * thermal_sock = SubSocket::create(c, "thermal"); + SubSocket * driver_monitoring_sock = SubSocket::create(c, "driverMonitoring"); + + Poller * poller = Poller::create({thermal_sock, driver_monitoring_sock}); + + // Wait for hardware type to be set. + while (hw_type == cereal::HealthData::HwType::UNKNOWN){ + usleep(100*1000); + } + // Only control fan speed on UNO + if (hw_type != cereal::HealthData::HwType::UNO) return NULL; + + + uint16_t prev_fan_speed = 999; + uint16_t prev_ir_pwr = 999; + + while (!do_exit) { + for (auto sock : poller->poll(1000)){ + Message * msg = sock->receive(); + if (msg == NULL) continue; + + auto amsg = kj::heapArray((msg->getSize() / sizeof(capnp::word)) + 1); + memcpy(amsg.begin(), msg->getData(), msg->getSize()); + + delete msg; + + capnp::FlatArrayMessageReader cmsg(amsg); + cereal::Event::Reader event = cmsg.getRoot(); + + auto type = event.which(); + if(type == cereal::Event::THERMAL){ + uint16_t fan_speed = event.getThermal().getFanSpeed(); + if (fan_speed != prev_fan_speed){ + pthread_mutex_lock(&usb_lock); + libusb_control_transfer(dev_handle, 0x40, 0xb1, fan_speed, 0, NULL, 0, TIMEOUT); + pthread_mutex_unlock(&usb_lock); + + prev_fan_speed = fan_speed; + } + } else if (type == cereal::Event::DRIVER_MONITORING){ + uint16_t ir_pwr = 100.0 * event.getDriverMonitoring().getIrPwr(); + + if (ir_pwr != prev_ir_pwr){ + pthread_mutex_lock(&usb_lock); + libusb_control_transfer(dev_handle, 0x40, 0xb0, ir_pwr, 0, NULL, 0, TIMEOUT); + pthread_mutex_unlock(&usb_lock); + + prev_ir_pwr = ir_pwr; + } + } + } + } + + delete poller; + delete thermal_sock; + delete c; + + return NULL; +} + #define pigeon_send(x) _pigeon_send(x, sizeof(x)-1) void hexdump(unsigned char *d, int l) { @@ -582,7 +729,7 @@ void pigeon_init() { LOGW("panda GPS on"); } -static void pigeon_publish_raw(void *publisher, unsigned char *dat, int alen) { +static void pigeon_publish_raw(PubSocket *publisher, unsigned char *dat, int alen) { // create message capnp::MallocMessageBuilder msg; cereal::Event::Builder event = msg.initRoot(); @@ -593,15 +740,14 @@ static void pigeon_publish_raw(void *publisher, unsigned char *dat, int alen) { // send to ubloxRaw auto words = capnp::messageToFlatArray(msg); auto bytes = words.asBytes(); - zmq_send(publisher, bytes.begin(), bytes.size(), 0); + publisher->send((char*)bytes.begin(), bytes.size()); } void *pigeon_thread(void *crap) { // ubloxRaw = 8042 - void *context = zmq_ctx_new(); - void *publisher = zmq_socket(context, ZMQ_PUB); - zmq_bind(publisher, "tcp://*:8042"); + Context * context = Context::create(); + PubSocket * publisher = PubSocket::create(context, "ubloxRaw"); // run at ~100hz unsigned char dat[0x1000]; @@ -695,6 +841,11 @@ int main() { can_recv_thread, NULL); assert(err == 0); + pthread_t hardware_control_thread_handle; + err = pthread_create(&hardware_control_thread_handle, NULL, + hardware_control_thread, NULL); + assert(err == 0); + // join threads err = pthread_join(can_recv_thread_handle, NULL); diff --git a/selfdrive/boardd/tests/boardd_old.py b/selfdrive/boardd/tests/boardd_old.py index 3f5ad7cf6c22b3..f963004423ab98 100755 --- a/selfdrive/boardd/tests/boardd_old.py +++ b/selfdrive/boardd/tests/boardd_old.py @@ -12,7 +12,6 @@ import selfdrive.messaging as messaging from common.realtime import Ratekeeper -from selfdrive.services import service_list from selfdrive.swaglog import cloudlog from selfdrive.boardd.boardd import can_capnp_to_can_list from cereal import car @@ -46,13 +45,13 @@ def can_list_to_can_capnp(can_msgs, msgtype='can'): def can_health(): while 1: try: - dat = handle.controlRead(usb1.TYPE_VENDOR | usb1.RECIPIENT_DEVICE, 0xd2, 0, 0, 0x10) + dat = handle.controlRead(usb1.TYPE_VENDOR | usb1.RECIPIENT_DEVICE, 0xd2, 0, 0, 0x16) break except (USBErrorIO, USBErrorOverflow): cloudlog.exception("CAN: BAD HEALTH, RETRYING") - v, i, started = struct.unpack("IIB", dat[0:9]) - # TODO: units - return {"voltage": v, "current": i, "started": bool(started)} + v, i = struct.unpack("II", dat[0:8]) + ign_line, ign_can = struct.unpack("BB", dat[20:22]) + return {"voltage": v, "current": i, "ignition_line": bool(ign_line), "ignition_can": bool(ign_can)} def __parse_can_buffer(dat): ret = [] @@ -111,8 +110,8 @@ def boardd_mock_loop(): can_init() handle.controlWrite(0x40, 0xdc, SafetyModel.allOutput, 0, b'') - logcan = messaging.sub_sock(service_list['can'].port) - sendcan = messaging.pub_sock(service_list['sendcan'].port) + logcan = messaging.sub_sock('can') + sendcan = messaging.pub_sock('sendcan') while 1: tsc = messaging.drain_sock(logcan, wait_for_one=True) @@ -150,24 +149,24 @@ def boardd_test_loop(): cnt += 1 # *** main loop *** -def boardd_loop(rate=200): +def boardd_loop(rate=100): rk = Ratekeeper(rate) can_init() # *** publishes can and health - logcan = messaging.pub_sock(service_list['can'].port) - health_sock = messaging.pub_sock(service_list['health'].port) + logcan = messaging.pub_sock('can') + health_sock = messaging.pub_sock('health') # *** subscribes to can send - sendcan = messaging.sub_sock(service_list['sendcan'].port) + sendcan = messaging.sub_sock('sendcan') # drain sendcan to delete any stale messages from previous runs messaging.drain_sock(sendcan) while 1: - # health packet @ 1hz - if (rk.frame%rate) == 0: + # health packet @ 2hz + if (rk.frame % (rate // 2)) == 0: health = can_health() msg = messaging.new_message() msg.init('health') @@ -175,7 +174,8 @@ def boardd_loop(rate=200): # store the health to be logged msg.health.voltage = health['voltage'] msg.health.current = health['current'] - msg.health.started = health['started'] + msg.health.ignitionLine = health['ignition_line'] + msg.health.ignitionCan = health['ignition_can'] msg.health.controlsAllowed = True health_sock.send(msg.to_bytes()) @@ -197,15 +197,15 @@ def boardd_loop(rate=200): rk.keep_time() # *** main loop *** -def boardd_proxy_loop(rate=200, address="192.168.2.251"): +def boardd_proxy_loop(rate=100, address="192.168.2.251"): rk = Ratekeeper(rate) can_init() # *** subscribes can - logcan = messaging.sub_sock(service_list['can'].port, addr=address) + logcan = messaging.sub_sock('can', addr=address) # *** publishes to can send - sendcan = messaging.pub_sock(service_list['sendcan'].port) + sendcan = messaging.pub_sock('sendcan') # drain sendcan to delete any stale messages from previous runs messaging.drain_sock(sendcan) diff --git a/selfdrive/boardd/tests/replay_many.py b/selfdrive/boardd/tests/replay_many.py index 548ec6549adbaa..cd94806a87c5a9 100755 --- a/selfdrive/boardd/tests/replay_many.py +++ b/selfdrive/boardd/tests/replay_many.py @@ -2,34 +2,37 @@ import sys import time import signal +import traceback from panda import Panda from multiprocessing import Pool import selfdrive.messaging as messaging -from selfdrive.services import service_list from selfdrive.boardd.boardd import can_capnp_to_can_list def initializer(): - """Ignore CTRL+C in the worker process. - source: https://stackoverflow.com/a/44869451 """ - signal.signal(signal.SIGINT, signal.SIG_IGN) + """Ignore CTRL+C in the worker process. + source: https://stackoverflow.com/a/44869451 """ + signal.signal(signal.SIGINT, signal.SIG_IGN) def send_thread(serial): - panda = Panda(serial) - panda.set_safety_mode(Panda.SAFETY_ALLOUTPUT) - panda.set_can_loopback(False) - - can_sock = messaging.sub_sock(service_list['can'].port) - - while True: - # Send messages one bus 0 and 1 - tsc = messaging.recv_one(can_sock) - snd = can_capnp_to_can_list(tsc.can) - snd = filter(lambda x: x[-1] <= 2, snd) - panda.can_send_many(snd) - - # Drain panda message buffer - panda.can_recv() + try: + panda = Panda(serial) + panda.set_safety_mode(Panda.SAFETY_ALLOUTPUT) + panda.set_can_loopback(False) + + can_sock = messaging.sub_sock('can') + + while True: + # Send messages one bus 0 and 1 + tsc = messaging.recv_one(can_sock) + snd = can_capnp_to_can_list(tsc.can) + snd = list(filter(lambda x: x[-1] <= 2, snd)) + panda.can_send_many(snd) + + # Drain panda message buffer + panda.can_recv() + except Exception: + traceback.print_exc() if __name__ == "__main__": diff --git a/selfdrive/boardd/tests/test_boardd_loopback.py b/selfdrive/boardd/tests/test_boardd_loopback.py index c3992bdac44e80..fefb3bf254c001 100755 --- a/selfdrive/boardd/tests/test_boardd_loopback.py +++ b/selfdrive/boardd/tests/test_boardd_loopback.py @@ -7,7 +7,6 @@ from selfdrive.boardd.boardd import can_list_to_can_capnp from selfdrive.messaging import drain_sock, pub_sock, sub_sock -from selfdrive.services import service_list def get_test_string(): return b"test"+os.urandom(10) @@ -15,8 +14,8 @@ def get_test_string(): BUS = 0 def main(): - rcv = sub_sock(service_list['can'].port) # port 8006 - snd = pub_sock(service_list['sendcan'].port) # port 8017 + rcv = sub_sock('can') # port 8006 + snd = pub_sock('sendcan') # port 8017 time.sleep(0.3) # wait to bind before send/recv for i in range(10): diff --git a/selfdrive/can/Makefile b/selfdrive/can/Makefile index 85d2c494a96699..cc1175b8c1413f 100644 --- a/selfdrive/can/Makefile +++ b/selfdrive/can/Makefile @@ -23,17 +23,6 @@ CFLAGS += -mcpu=cortex-a57 CXXFLAGS += -mcpu=cortex-a57 endif -ifeq ($(UNAME_S),Darwin) - ZMQ_LIBS = -L/usr/local/lib -lzmq -else ifeq ($(OPTEST),1) - ZMQ_LIBS = -lzmq -else ifeq ($(UNAME_M),x86_64) - ZMQ_FLAGS = -I$(PHONELIBS)/zmq/x64/include - ZMQ_LIBS = -L$(PHONELIBS)/zmq/x64/lib -l:libzmq.a -else ifeq ($(UNAME_M),aarch64) - ZMQ_LIBS = -l:libzmq.a -lgnustl_shared -endif - OBJDIR = obj OPENDBC_PATH := $(shell python3 -c 'import opendbc; print(opendbc.DBC_PATH)') @@ -43,7 +32,7 @@ DBC_OBJS := $(patsubst $(OPENDBC_PATH)/%.dbc,$(OBJDIR)/%.o,$(DBC_SOURCES)) DBC_CCS := $(patsubst $(OPENDBC_PATH)/%.dbc,dbc_out/%.cc,$(DBC_SOURCES)) .SECONDARY: $(DBC_CCS) -LIBDBC_OBJS := $(OBJDIR)/dbc.o $(OBJDIR)/parser.o $(OBJDIR)/packer.o +LIBDBC_OBJS := $(OBJDIR)/dbc.o $(OBJDIR)/parser.o $(OBJDIR)/packer.o $(OBJDIR)/common.o CWD := $(shell pwd) @@ -64,8 +53,6 @@ libdbc.so:: $(LIBDBC_OBJS) $(DBC_OBJS) -I. -I../.. \ $(CXXFLAGS) \ $(LDFLAGS) \ - $(ZMQ_FLAGS) \ - $(ZMQ_LIBS) \ $(CEREAL_CXXFLAGS) \ $(CEREAL_LIBS) @@ -74,8 +61,8 @@ packer_impl.so: packer_impl.pyx packer_setup.py rm -rf build rm -f packer_impl.cpp -parser_pyx.so: parser_pyx_setup.py parser_pyx.pyx parser_pyx.pxd - python3 $< build_ext --inplace +parser_pyx.so: libdbc.so parser_pyx_setup.py parser_pyx.pyx common.pxd + python3 parser_pyx_setup.py build_ext --inplace rm -rf build rm -f parser_pyx.cpp @@ -84,7 +71,6 @@ $(OBJDIR)/%.o: %.cc $(CXX) -fPIC -c -o '$@' $^ \ -I. -I../.. \ $(CXXFLAGS) \ - $(ZMQ_FLAGS) \ $(CEREAL_CXXFLAGS) \ $(OBJDIR)/%.o: dbc_out/%.cc @@ -92,13 +78,11 @@ $(OBJDIR)/%.o: dbc_out/%.cc $(CXX) -fPIC -c -o '$@' $^ \ -I. -I../.. \ $(CXXFLAGS) \ - $(ZMQ_FLAGS) \ $(CEREAL_CXXFLAGS) \ dbc_out/%.cc: process_dbc.py dbc_template.cc $(OPENDBC_PATH)/%.dbc @echo "[ DBC GEN ] $@" - @echo "Missing prereq $?" - ./process_dbc.py $(OPENDBC_PATH) dbc_out + ./process_dbc.py $(OPENDBC_PATH) '$@' $(OBJDIR): mkdir -p $@ @@ -109,4 +93,5 @@ clean: rm -f dbc_out/*.cc rm -f dbcs.txt rm -f dbcs.csv + rm -f *.so rm -rf $(OBJDIR)/* diff --git a/selfdrive/can/can_define.py b/selfdrive/can/can_define.py index d6ffc5c669e9fb..eb708869f09963 100644 --- a/selfdrive/can/can_define.py +++ b/selfdrive/can/can_define.py @@ -35,5 +35,5 @@ def __init__(self, dbc_name): self.dv[msgname] = {} # two ways to lookup: address or msg name - self.dv[address][sgname] = {v: d for v, d in zip(values, defs)} #build dict + self.dv[address][sgname] = dict(zip(values, defs)) self.dv[msgname][sgname] = self.dv[address][sgname] diff --git a/selfdrive/can/common.cc b/selfdrive/can/common.cc new file mode 100644 index 00000000000000..5a131eb6c757af --- /dev/null +++ b/selfdrive/can/common.cc @@ -0,0 +1,165 @@ +#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)); +} diff --git a/selfdrive/can/common.h b/selfdrive/can/common.h index 4f097228432543..a496c3918b91ad 100644 --- a/selfdrive/can/common.h +++ b/selfdrive/can/common.h @@ -1,90 +1,59 @@ -#ifndef SELFDRIVE_CAN_COMMON_H -#define SELFDRIVE_CAN_COMMON_H +#pragma once -#include -#include -#include +#include +#include -#define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0])) +#include "common_dbc.h" +#include +#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); -unsigned int pedal_checksum(unsigned int address, uint64_t d, int l); - -struct SignalPackValue { - const char* name; - double value; -}; - - -struct SignalParseOptions { +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; - const char* name; - double default_value; -}; + unsigned int size; -struct MessageParseOptions { - uint32_t address; - int check_frequency; -}; + std::vector parse_sigs; + std::vector vals; -struct SignalValue { - uint32_t address; uint16_t ts; - const char* name; - double value; -}; + uint64_t seen; + uint64_t check_threshold; + uint8_t counter; + uint8_t counter_fail; -enum SignalType { - DEFAULT, - HONDA_CHECKSUM, - HONDA_COUNTER, - TOYOTA_CHECKSUM, - PEDAL_CHECKSUM, - PEDAL_COUNTER, + bool parse(uint64_t sec, uint16_t ts_, uint8_t * dat); + bool update_counter_generic(int64_t v, int cnt_size); }; -struct Signal { - const char* name; - int b1, b2, bo; - bool is_signed; - double factor, offset; - bool is_little_endian; - SignalType type; -}; +class CANParser { +private: + const int bus; -struct Msg { - const char* name; - uint32_t address; - unsigned int size; - size_t num_sigs; - const Signal *sigs; -}; - -struct Val { - const char* name; - uint32_t address; - const char* def_val; - const Signal *sigs; -}; - -struct DBC { - const char* name; - size_t num_msgs; - const Msg *msgs; - const Val *vals; - size_t num_vals; -}; + const DBC *dbc = NULL; + std::unordered_map message_states; -const DBC* dbc_lookup(const std::string& dbc_name); +public: + bool can_valid = false; + uint64_t last_sec = 0; -void dbc_register(const DBC* dbc); + CANParser(int abus, const std::string& dbc_name, + const std::vector &options, + const std::vector &sigoptions); + void UpdateCans(uint64_t sec, const capnp::List::Reader& cans); + void UpdateValid(uint64_t sec); + void update_string(std::string data); + std::vector query_latest(); -#define dbc_init(dbc) \ -static void __attribute__((constructor)) do_dbc_init_ ## dbc(void) { \ - dbc_register(&dbc); \ -} - -#endif +}; diff --git a/selfdrive/can/common.pxd b/selfdrive/can/common.pxd new file mode 100644 index 00000000000000..54c6e444fdfcd8 --- /dev/null +++ b/selfdrive/can/common.pxd @@ -0,0 +1,71 @@ +# 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.h": + + ctypedef enum SignalType: + DEFAULT, + HONDA_CHECKSUM, + HONDA_COUNTER, + TOYOTA_CHECKSUM, + PEDAL_CHECKSUM, + PEDAL_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 const DBC* dbc_lookup(const string); + + cdef cppclass CANParser: + bool can_valid + CANParser(int, string, vector[MessageParseOptions], vector[SignalParseOptions]) + void update_string(string) + vector[SignalValue] query_latest() diff --git a/selfdrive/can/common_dbc.h b/selfdrive/can/common_dbc.h new file mode 100644 index 00000000000000..ae6f443ec90cd3 --- /dev/null +++ b/selfdrive/can/common_dbc.h @@ -0,0 +1,82 @@ +#pragma once + +#include +#include +#include + +#define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0])) + +struct SignalPackValue { + const char* name; + double value; +}; + +struct SignalParseOptions { + uint32_t address; + const char* name; + double default_value; +}; + +struct MessageParseOptions { + uint32_t address; + int check_frequency; +}; + +struct SignalValue { + uint32_t address; + uint16_t ts; + const char* name; + double value; +}; + +enum SignalType { + DEFAULT, + HONDA_CHECKSUM, + HONDA_COUNTER, + TOYOTA_CHECKSUM, + PEDAL_CHECKSUM, + PEDAL_COUNTER, + VOLKSWAGEN_CHECKSUM, + VOLKSWAGEN_COUNTER, +}; + +struct Signal { + const char* name; + int b1, b2, bo; + bool is_signed; + double factor, offset; + bool is_little_endian; + SignalType type; +}; + +struct Msg { + const char* name; + uint32_t address; + unsigned int size; + size_t num_sigs; + const Signal *sigs; +}; + +struct Val { + const char* name; + uint32_t address; + const char* def_val; + const Signal *sigs; +}; + +struct DBC { + const char* name; + size_t num_msgs; + const Msg *msgs; + const Val *vals; + size_t num_vals; +}; + +const DBC* dbc_lookup(const std::string& dbc_name); + +void dbc_register(const DBC* dbc); + +#define dbc_init(dbc) \ +static void __attribute__((constructor)) do_dbc_init_ ## dbc(void) { \ + dbc_register(&dbc); \ +} diff --git a/selfdrive/can/dbc.cc b/selfdrive/can/dbc.cc index 95d5e4d791394a..6587de7fe0163a 100644 --- a/selfdrive/can/dbc.cc +++ b/selfdrive/can/dbc.cc @@ -1,7 +1,6 @@ -#include #include -#include "common.h" +#include "common_dbc.h" namespace { diff --git a/selfdrive/can/dbc_template.cc b/selfdrive/can/dbc_template.cc index 776403b22f03ff..d916eeada06a43 100644 --- a/selfdrive/can/dbc_template.cc +++ b/selfdrive/can/dbc_template.cc @@ -1,6 +1,4 @@ -#include - -#include "common.h" +#include "common_dbc.h" namespace { @@ -27,6 +25,10 @@ const Signal sigs_{{address}}[] = { .type = SignalType::HONDA_COUNTER, {% elif checksum_type == "toyota" and sig.name == "CHECKSUM" %} .type = SignalType::TOYOTA_CHECKSUM, + {% elif checksum_type == "volkswagen" and sig.name == "CHECKSUM" %} + .type = SignalType::VOLKSWAGEN_CHECKSUM, + {% elif checksum_type == "volkswagen" and sig.name == "COUNTER" %} + .type = SignalType::VOLKSWAGEN_COUNTER, {% elif address in [512, 513] and sig.name == "CHECKSUM_PEDAL" %} .type = SignalType::PEDAL_CHECKSUM, {% elif address in [512, 513] and sig.name == "COUNTER_PEDAL" %} diff --git a/selfdrive/can/libdbc_py.py b/selfdrive/can/libdbc_py.py index fbf36a3d4d0764..92093f9316896e 100644 --- a/selfdrive/can/libdbc_py.py +++ b/selfdrive/can/libdbc_py.py @@ -5,7 +5,7 @@ can_dir = os.path.dirname(os.path.abspath(__file__)) libdbc_fn = os.path.join(can_dir, "libdbc.so") -subprocess.check_call(["make"], cwd=can_dir) +subprocess.check_call(["make", "-j3"], cwd=can_dir) # don't use all the cores to avoid overheating ffi = FFI() ffi.cdef(""" @@ -41,6 +41,8 @@ TOYOTA_CHECKSUM, PEDAL_CHECKSUM, PEDAL_COUNTER, + VOLKSWAGEN_CHECKSUM, + VOLKSWAGEN_COUNTER, } SignalType; typedef struct { @@ -77,10 +79,9 @@ void* can_init(int bus, const char* dbc_name, size_t num_message_options, const MessageParseOptions* message_options, - size_t num_signal_options, const SignalParseOptions* signal_options, bool sendcan, - const char* tcp_addr, int timeout); + size_t num_signal_options, const SignalParseOptions* signal_options); -int can_update(void* can, uint64_t sec, bool wait); +void can_update_string(void *can, const char* dat, int len); size_t can_query_latest(void* can, bool *out_can_valid, size_t out_values_size, SignalValue* out_values); diff --git a/selfdrive/can/packer.cc b/selfdrive/can/packer.cc index d0e84197887a8f..c658e56731f3f3 100644 --- a/selfdrive/can/packer.cc +++ b/selfdrive/can/packer.cc @@ -1,6 +1,4 @@ #include -#include -#include #include #include #include @@ -51,6 +49,7 @@ namespace { signal_lookup[std::make_pair(msg->address, std::string(sig->name))] = *sig; } } + init_crc_lookup_tables(); } uint64_t pack(uint32_t address, const std::vector &signals, int counter) { @@ -82,23 +81,28 @@ namespace { } auto sig = sig_it->second; - if (sig.type != SignalType::HONDA_COUNTER){ + 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 = signal_lookup.find(std::make_pair(address, "CHECKSUM")); - if (sig_it != signal_lookup.end()) { - auto sig = sig_it->second; - if (sig.type == SignalType::HONDA_CHECKSUM){ + 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){ + } 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"); } @@ -108,7 +112,6 @@ namespace { } - private: const DBC *dbc = NULL; std::map, Signal> signal_lookup; diff --git a/selfdrive/can/packer.py b/selfdrive/can/packer.py index 81a8c34270fb75..ccb537c9565036 100644 --- a/selfdrive/can/packer.py +++ b/selfdrive/can/packer.py @@ -3,7 +3,7 @@ import subprocess can_dir = os.path.dirname(os.path.abspath(__file__)) -subprocess.check_call(["make", "packer_impl.so"], cwd=can_dir) +subprocess.check_call(["make", "-j3", "packer_impl.so"], cwd=can_dir) # don't use all the cores to avoid overheating from selfdrive.can.packer_impl import CANPacker assert CANPacker diff --git a/selfdrive/can/packer_impl.pyx b/selfdrive/can/packer_impl.pyx index 7429338ac40721..d7c6119b753874 100644 --- a/selfdrive/can/packer_impl.pyx +++ b/selfdrive/can/packer_impl.pyx @@ -20,7 +20,9 @@ ctypedef enum SignalType: HONDA_COUNTER, TOYOTA_CHECKSUM, PEDAL_CHECKSUM, - PEDAL_COUNTER + PEDAL_COUNTER, + VOLKSWAGEN_CHECKSUM, + VOLKSWAGEN_COUNTER cdef struct Signal: const char* name diff --git a/selfdrive/can/parser.cc b/selfdrive/can/parser.cc index 830e8b14c066e9..4d2dc32e2af919 100644 --- a/selfdrive/can/parser.cc +++ b/selfdrive/can/parser.cc @@ -1,5 +1,3 @@ -#include -#include #include #include @@ -7,16 +5,7 @@ #include #include #include - -#include -#include #include -#include - -#include - -#include -#include "cereal/gen/cpp/log.capnp.h" #include "common.h" @@ -25,555 +14,227 @@ #define INFO printf -#define MAX_BAD_COUNTER 5 - -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 +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); - unsigned int s = l; - while (address) { s += address & 0xff; address >>= 8; } - while (d) { s += d & 0xff; d >>= 8; } + for (int i=0; i < parse_sigs.size(); i++) { + auto& sig = parse_sigs[i]; + int64_t tmp; - return s & 0xFF; -} - -unsigned int pedal_checksum(unsigned int address, uint64_t d, int l) { - uint8_t crc = 0xFF; - uint8_t poly = 0xD5; // standard crc8 + if (sig.is_little_endian){ + tmp = (dat_le >> sig.b1) & ((1ULL << sig.b2)-1); + } else { + tmp = (dat_be >> sig.bo) & ((1ULL << sig.b2)-1); + } - d >>= ((8-l)*8); // remove padding - d >>= 8; // remove checksum + if (sig.is_signed) { + tmp -= (tmp >> (sig.b2-1)) ? (1ULL << sig.b2) : 0; //signed + } - uint8_t *dat = (uint8_t *)&d; + DEBUG("parse 0x%X %s -> %lld\n", address, sig.name, tmp); - 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); + if (sig.type == SignalType::HONDA_CHECKSUM) { + if (honda_checksum(address, dat_be, size) != tmp) { + INFO("0x%X CHECKSUM FAIL\n", address); + return false; } - else { - crc <<= 1; + } else if (sig.type == SignalType::HONDA_COUNTER) { + if (!update_counter_generic(tmp, sig.b2)) { + return false; } - } - } - return crc; -} - -namespace { - -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)); -} - - -struct MessageState { - uint32_t address; - unsigned int size; - - std::vector parse_sigs; - std::vector 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_, uint64_t 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 >> sig.b1) & ((1ULL << sig.b2)-1); - } else { - tmp = (dat >> sig.bo) & ((1ULL << sig.b2)-1); + } else if (sig.type == SignalType::TOYOTA_CHECKSUM) { + if (toyota_checksum(address, dat_be, size) != tmp) { + INFO("0x%X CHECKSUM FAIL\n", address); + return false; } - - if (sig.is_signed) { - tmp -= (tmp >> (sig.b2-1)) ? (1ULL << sig.b2) : 0; //signed + } else if (sig.type == SignalType::VOLKSWAGEN_CHECKSUM) { + if (volkswagen_crc(address, dat_le, size) != tmp) { + INFO("0x%X CRC FAIL\n", address); + return false; } - - DEBUG("parse %X %s -> %lld\n", address, sig.name, tmp); - - if (sig.type == SignalType::HONDA_CHECKSUM) { - if (honda_checksum(address, dat, size) != tmp) { - INFO("%X CHECKSUM FAIL\n", address); - return false; - } - } else if (sig.type == SignalType::HONDA_COUNTER) { + } else if (sig.type == SignalType::VOLKSWAGEN_COUNTER) { if (!update_counter_generic(tmp, sig.b2)) { - return false; - } - } else if (sig.type == SignalType::TOYOTA_CHECKSUM) { - if (toyota_checksum(address, dat, size) != tmp) { - INFO("%X CHECKSUM FAIL\n", address); - return false; - } - } else if (sig.type == SignalType::PEDAL_CHECKSUM) { - if (pedal_checksum(address, dat, size) != tmp) { - INFO("%X PEDAL CHECKSUM FAIL\n", address); - return false; - } - } else if (sig.type == SignalType::PEDAL_COUNTER) { - if (!update_counter_generic(tmp, sig.b2)) { - return false; - } + INFO("0x%X CHECKSUM FAIL\n", address); + return false; } - - vals[i] = tmp * sig.factor + sig.offset; - } - ts = ts_; - seen = sec; - - return true; - } - - - bool 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("%X COUNTER FAIL %d -- %d vs %d\n", address, counter_fail, old_counter, (int)v); + } else if (sig.type == SignalType::PEDAL_CHECKSUM) { + if (pedal_checksum(dat_be, size) != tmp) { + INFO("0x%X PEDAL CHECKSUM FAIL\n", address); + return false; } - if (counter_fail >= MAX_BAD_COUNTER) { + } else if (sig.type == SignalType::PEDAL_COUNTER) { + if (!update_counter_generic(tmp, sig.b2)) { return false; } - } else if (counter_fail > 0) { - counter_fail--; } - return true; + + vals[i] = tmp * sig.factor + sig.offset; } + ts = ts_; + seen = sec; -}; + return true; +} -class CANParser { - public: - CANParser(int abus, const std::string& dbc_name, - const std::vector &options, - const std::vector &sigoptions, - bool sendcan, const std::string& tcp_addr, int timeout=-1) - : bus(abus) { - // connect to can on 8006 - context = zmq_ctx_new(); +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("%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; +} - if (tcp_addr.length() > 0) { - subscriber = zmq_socket(context, ZMQ_SUB); - zmq_setsockopt(subscriber, ZMQ_SUBSCRIBE, "", 0); - zmq_setsockopt(subscriber, ZMQ_RCVTIMEO, &timeout, sizeof(int)); - std::string tcp_addr_str; +CANParser::CANParser(int abus, const std::string& dbc_name, + const std::vector &options, + const std::vector &sigoptions) + : bus(abus) { - if (sendcan) { - tcp_addr_str = "tcp://" + tcp_addr + ":8017"; - } else { - tcp_addr_str = "tcp://" + tcp_addr + ":8006"; - } - const char *tcp_addr_char = tcp_addr_str.c_str(); + dbc = dbc_lookup(dbc_name); + assert(dbc); + init_crc_lookup_tables(); - zmq_connect(subscriber, tcp_addr_char); + for (const auto& op : options) { + MessageState state = { + .address = op.address, + // .check_frequency = op.check_frequency, + }; - // drain sendcan to delete any stale messages from previous runs - zmq_msg_t msgDrain; - zmq_msg_init(&msgDrain); - int err = 0; - while(err >= 0) { - err = zmq_msg_recv(&msgDrain, subscriber, ZMQ_DONTWAIT); - } - } else { - subscriber = NULL; + // 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; } - dbc = dbc_lookup(dbc_name); - assert(dbc); - 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; inum_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 dnc %s\n", op.address, dbc_name.c_str()); + assert(false); + } + state.size = msg->size; - const Msg* msg = NULL; - for (int i=0; inum_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 dnc %s\n", op.address, dbc_name.c_str()); - assert(false); + // track checksums and counters for this message + for (int i=0; inum_sigs; i++) { + const Signal *sig = &msg->sigs[i]; + if (sig->type != SignalType::DEFAULT) { + state.parse_sigs.push_back(*sig); + state.vals.push_back(0); } + } - state.size = msg->size; + // track requested signals for this message + for (const auto& sigop : sigoptions) { + if (sigop.address != op.address) continue; - // track checksums and counters for this message for (int i=0; inum_sigs; i++) { const Signal *sig = &msg->sigs[i]; - if (sig->type != SignalType::DEFAULT) { + if (strcmp(sig->name, sigop.name) == 0 + && 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; inum_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 UpdateCans(uint64_t sec, const capnp::List::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()); - - // Assumes all signals in the message are of the same type (little or big endian) - // TODO: allow signals within the same message to have different endianess - auto& sig = message_states[cmsg.getAddress()].parse_sigs[0]; - if (sig.is_little_endian) { - p = read_u64_le(dat); - } else { - p = read_u64_be(dat); + state.vals.push_back(sigop.default_value); + break; } - - DEBUG(" proc %X: %llx\n", cmsg.getAddress(), p); - - state_it->second.parse(sec, cmsg.getBusTime(), p); } - } - void 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("%X TIMEOUT\n", state.address); - } - can_valid = false; - } } - } - - void update_string(std::string data) { - // format for board, make copy due to alignment issues, will be freed on out of scope - auto amsg = kj::heapArray((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(); - last_sec = event.getLogMonoTime(); - - auto cans = event.getCan(); - UpdateCans(last_sec, cans); - - UpdateValid(last_sec); + message_states[state.address] = state; } +} - int update(uint64_t sec, bool wait) { - int err; - int result = 0; - - // recv from can - zmq_msg_t msg; - zmq_msg_init(&msg); +void CANParser::UpdateCans(uint64_t sec, const capnp::List::Reader& cans) { + int msg_count = cans.size(); + uint64_t p; - // multiple recv is fine - bool first = wait; - while (subscriber != NULL) { - if (first) { - err = zmq_msg_recv(&msg, subscriber, 0); - first = false; + DEBUG("got %d messages\n", msg_count); - // When we timeout on the first message, return error - if (err < 0){ - result = -1; - } - } else { - err = zmq_msg_recv(&msg, subscriber, ZMQ_DONTWAIT); + // 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 (err < 0) break; - - // format for board, make copy due to alignment issues, will be freed on out of scope - auto amsg = kj::heapArray((zmq_msg_size(&msg) / sizeof(capnp::word)) + 1); - memcpy(amsg.begin(), zmq_msg_data(&msg), zmq_msg_size(&msg)); - // extract the messages - capnp::FlatArrayMessageReader cmsg(amsg); - cereal::Event::Reader event = cmsg.getRoot(); + if (cmsg.getDat().size() > 8) continue; //shouldnt ever happen + uint8_t dat[8] = {0}; + memcpy(dat, cmsg.getDat().begin(), cmsg.getDat().size()); - auto cans = event.getCan(); - UpdateCans(sec, cans); + state_it->second.parse(sec, cmsg.getBusTime(), dat); } +} - last_sec = sec; - UpdateValid(sec); - zmq_msg_close(&msg); - return result; - } - - std::vector query_latest() { - std::vector 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 0 && (sec - state.seen) > state.check_threshold) { + if (state.seen > 0) { + DEBUG("%X TIMEOUT\n", state.address); } + can_valid = false; } - - return ret; } - - bool can_valid = false; - uint64_t last_sec = 0; - - private: - const int bus; - // zmq vars - void *context = NULL; - void *subscriber = NULL; - - const DBC *dbc = NULL; - std::unordered_map message_states; -}; - } -extern "C" { - -void* can_init(int bus, const char* dbc_name, - size_t num_message_options, const MessageParseOptions* message_options, - size_t num_signal_options, const SignalParseOptions* signal_options, - bool sendcan, const char* tcp_addr, int timeout) { - CANParser* ret = new CANParser(bus, std::string(dbc_name), - (message_options ? std::vector(message_options, message_options+num_message_options) - : std::vector{}), - (signal_options ? std::vector(signal_options, signal_options+num_signal_options) - : std::vector{}), sendcan, std::string(tcp_addr), timeout); - return (void*)ret; -} +void CANParser::update_string(std::string data) { + // format for board, make copy due to alignment issues, will be freed on out of scope + auto amsg = kj::heapArray((data.length() / sizeof(capnp::word)) + 1); + memcpy(amsg.begin(), data.data(), data.length()); -void* can_init_with_vectors(int bus, const char* dbc_name, - std::vector message_options, - std::vector signal_options, - bool sendcan, const char* tcp_addr, int timeout) { - CANParser* ret = new CANParser(bus, std::string(dbc_name), - message_options, - signal_options, - sendcan, std::string(tcp_addr), timeout); - return (void*)ret; -} + // extract the messages + capnp::FlatArrayMessageReader cmsg(amsg); + cereal::Event::Reader event = cmsg.getRoot(); -int can_update(void* can, uint64_t sec, bool wait) { - CANParser* cp = (CANParser*)can; - return cp->update(sec, wait); -} + last_sec = event.getLogMonoTime(); -void can_update_string(void *can, const char* dat, int len) { - CANParser* cp = (CANParser*)can; - cp->update_string(std::string(dat, len)); -} + auto cans = event.getCan(); + UpdateCans(last_sec, cans); -size_t can_query_latest(void* can, bool *out_can_valid, size_t out_values_size, SignalValue* out_values) { - CANParser* cp = (CANParser*)can; - - if (out_can_valid) { - *out_can_valid = cp->can_valid; - } + UpdateValid(last_sec); +} - const std::vector values = cp->query_latest(); - if (out_values) { - std::copy(values.begin(), values.begin()+std::min(out_values_size, values.size()), out_values); - } - return values.size(); -}; -void can_query_latest_vector(void* can, bool *out_can_valid, std::vector &values) { - CANParser* cp = (CANParser*)can; - if (out_can_valid) { - *out_can_valid = cp->can_valid; - } - values = cp->query_latest(); -}; +std::vector CANParser::query_latest() { + std::vector ret; -} + for (const auto& kv : message_states) { + const auto& state = kv.second; + if (last_sec != 0 && state.seen != last_sec) continue; -#ifdef TEST - -int main(int argc, char** argv) { - CANParser cp(0, "honda_civic_touring_2016_can", - std::vector{ - // address, check_frequency - {0x14a, 100}, - {0x158, 100}, - {0x17c, 100}, - {0x191, 100}, - {0x1a4, 50}, - {0x326, 10}, - {0x1b0, 50}, - {0x1d0, 50}, - {0x305, 10}, - {0x324, 10}, - {0x405, 3}, - {0x18f, 0}, - {0x130, 0}, - {0x296, 0}, - {0x30c, 0}, - }, - std::vector{ - // sig_name, sig_address, default - {0x158, "XMISSION_SPEED", 0}, - {0x1d0, "WHEEL_SPEED_FL", 0}, - {0x1d0, "WHEEL_SPEED_FR", 0}, - {0x1d0, "WHEEL_SPEED_RL", 0}, - {0x14a, "STEER_ANGLE", 0}, - {0x18f, "STEER_TORQUE_SENSOR", 0}, - {0x191, "GEAR", 0}, - {0x1b0, "WHEELS_MOVING", 1}, - {0x405, "DOOR_OPEN_FL", 1}, - {0x405, "DOOR_OPEN_FR", 1}, - {0x405, "DOOR_OPEN_RL", 1}, - {0x405, "DOOR_OPEN_RR", 1}, - {0x324, "CRUISE_SPEED_PCM", 0}, - {0x305, "SEATBELT_DRIVER_LAMP", 1}, - {0x305, "SEATBELT_DRIVER_LATCHED", 0}, - {0x17c, "BRAKE_PRESSED", 0}, - {0x130, "CAR_GAS", 0}, - {0x296, "CRUISE_BUTTONS", 0}, - {0x1a4, "ESP_DISABLED", 1}, - {0x30c, "HUD_LEAD", 0}, - {0x1a4, "USER_BRAKE", 0}, - {0x18f, "STEER_STATUS", 5}, - {0x1d0, "WHEEL_SPEED_RR", 0}, - {0x1b0, "BRAKE_ERROR_1", 1}, - {0x1b0, "BRAKE_ERROR_2", 1}, - {0x191, "GEAR_SHIFTER", 0}, - {0x326, "MAIN_ON", 0}, - {0x17c, "ACC_STATUS", 0}, - {0x17c, "PEDAL_GAS", 0}, - {0x296, "CRUISE_SETTING", 0}, - {0x326, "LEFT_BLINKER", 0}, - {0x326, "RIGHT_BLINKER", 0}, - {0x324, "COUNTER", 0}, - {0x17c, "ENGINE_RPM", 0}, - }); - - - - const std::string log_fn = "dats.bin"; - - int log_fd = open(log_fn.c_str(), O_RDONLY, 0); - assert(log_fd >= 0); - - off_t log_size = lseek(log_fd, 0, SEEK_END); - lseek(log_fd, 0, SEEK_SET); - - void* log_data = mmap(NULL, log_size, PROT_READ, MAP_PRIVATE, log_fd, 0); - assert(log_data); - - auto words = kj::arrayPtr((const capnp::word*)log_data, log_size/sizeof(capnp::word)); - while (words.size() > 0) { - capnp::FlatArrayMessageReader reader(words); - - auto evt = reader.getRoot(); - auto cans = evt.getCan(); - - cp.UpdateCans(0, cans); - - words = kj::arrayPtr(reader.getEnd(), words.end()); + for (int i=0; idlsym(libdbc, 'can_init_with_vectors') - self.dbc_lookup = dlsym(libdbc, 'dbc_lookup') - self.can_update = dlsym(libdbc, 'can_update') - self.can_update_string = dlsym(libdbc, 'can_update_string') - self.can_query_latest_vector = dlsym(libdbc, 'can_query_latest_vector') + cdef: + cpp_CANParser *can + const DBC *dbc + map[string, uint32_t] msg_name_to_address + map[uint32_t, string] address_to_msg_name + vector[SignalValue] can_values + bool test_mode_enabled + + cdef public: + string dbc_name + dict vl + dict ts + bool can_valid + int can_invalid_cnt + + def __init__(self, dbc_name, signals, checks=None, bus=0): if checks is None: checks = [] self.can_valid = True self.dbc_name = dbc_name - self.dbc = self.dbc_lookup(dbc_name) + self.dbc = dbc_lookup(dbc_name) self.vl = {} self.ts = {} @@ -78,15 +92,15 @@ cdef class CANParser: mpo.check_frequency = freq message_options_v.push_back(mpo) - self.can = self.can_init_with_vectors(bus, dbc_name, message_options_v, signal_options_v, sendcan, tcp_addr, timeout) + self.can = new cpp_CANParser(bus, dbc_name, message_options_v, signal_options_v) self.update_vl() cdef unordered_set[uint32_t] update_vl(self): cdef string sig_name cdef unordered_set[uint32_t] updated_val - cdef bool valid = False - self.can_query_latest_vector(self.can, &valid, self.can_values) + can_values = self.can.query_latest() + valid = self.can.can_valid # Update invalid flag self.can_invalid_cnt += 1 @@ -95,7 +109,7 @@ cdef class CANParser: self.can_valid = self.can_invalid_cnt < CAN_INVALID_CNT - for cv in self.can_values: + for cv in can_values: # Cast char * directly to unicde name = self.address_to_msg_name[cv.address].c_str() cv_name = cv.name @@ -111,7 +125,7 @@ cdef class CANParser: return updated_val def update_string(self, dat): - self.can_update_string(self.can, dat, len(dat)) + self.can.update_string(dat) return self.update_vl() def update_strings(self, strings): @@ -122,8 +136,3 @@ cdef class CANParser: updated_vals.update(updated_val) return updated_vals - - def update(self, uint64_t sec, bool wait): - r = (self.can_update(self.can, sec, wait) >= 0) - updated_val = self.update_vl() - return r, updated_val diff --git a/selfdrive/can/parser_pyx_setup.py b/selfdrive/can/parser_pyx_setup.py index 29102ee0269b22..a024c7a640f27a 100644 --- a/selfdrive/can/parser_pyx_setup.py +++ b/selfdrive/can/parser_pyx_setup.py @@ -1,8 +1,10 @@ +import os import subprocess from distutils.core import Extension, setup # pylint: disable=import-error,no-name-in-module from Cython.Build import cythonize +from common.basedir import BASEDIR from common.cython_hacks import BuildExtWithoutPlatformSuffix sourcefiles = ['parser_pyx.pyx'] @@ -12,12 +14,22 @@ if ARCH == "aarch64": extra_compile_args += ["-Wno-deprecated-register"] -setup(name='Radard Thread', +setup(name='CAN parser', cmdclass={'build_ext': BuildExtWithoutPlatformSuffix}, ext_modules=cythonize( Extension( "parser_pyx", + language="c++", sources=sourcefiles, - extra_compile_args=extra_compile_args - ), - nthreads=4)) + extra_compile_args=extra_compile_args, + include_dirs=[ + BASEDIR, + os.path.join(BASEDIR, 'phonelibs', 'capnp-cpp/include'), + ], + extra_link_args=[ + os.path.join(BASEDIR, 'selfdrive', 'can', 'libdbc.so'), + ], + ) + ), + nthreads=4, +) diff --git a/selfdrive/can/plant_can_parser.py b/selfdrive/can/plant_can_parser.py index 65fcfc64152f19..37ea3353744a60 100644 --- a/selfdrive/can/plant_can_parser.py +++ b/selfdrive/can/plant_can_parser.py @@ -21,7 +21,7 @@ def __init__(self, dbc_f, signals, checks=None): # - frequency is the frequency at which health should be monitored. checks = [] if checks is None else checks - self.msgs_ck = set([check[0] for check in checks]) + self.msgs_ck = {check[0] for check in checks} self.frqs = dict(checks) self.can_valid = False # start with False CAN assumption # list of received msg we want to monitor counter and checksum for diff --git a/selfdrive/can/process_dbc.py b/selfdrive/can/process_dbc.py index 187d413584dcd7..dc544f741f65a4 100755 --- a/selfdrive/can/process_dbc.py +++ b/selfdrive/can/process_dbc.py @@ -1,7 +1,6 @@ #!/usr/bin/env python3 from __future__ import print_function import os -import glob import sys import jinja2 @@ -11,80 +10,96 @@ def main(): if len(sys.argv) != 3: - print("usage: %s dbc_directory output_directory" % (sys.argv[0],)) + print("usage: %s dbc_directory output_filename" % (sys.argv[0],)) sys.exit(0) dbc_dir = sys.argv[1] - out_dir = sys.argv[2] + out_fn = sys.argv[2] - template_fn = os.path.join(os.path.dirname(__file__), "dbc_template.cc") - template_mtime = os.path.getmtime(template_fn) + dbc_name = os.path.split(out_fn)[-1].replace('.cc', '') - this_file_mtime = os.path.getmtime(__file__) + 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) - for dbc_path in glob.iglob(os.path.join(dbc_dir, "*.dbc")): - dbc_mtime = os.path.getmtime(dbc_path) - dbc_fn = os.path.split(dbc_path)[1] - dbc_name = os.path.splitext(dbc_fn)[0] - can_dbc = dbc(dbc_path) - out_fn = os.path.join(os.path.dirname(__file__), out_dir, dbc_name + ".cc") - if os.path.exists(out_fn): - out_mtime = os.path.getmtime(out_fn) - else: - out_mtime = 0 - - if dbc_mtime < out_mtime and template_mtime < out_mtime and this_file_mtime < out_mtime: - continue #skip output is newer than template and dbc - - msgs = [(address, msg_name, msg_size, sorted(msg_sigs, key=lambda s: s.name not in (b"COUNTER", b"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: set(b) for a,b in can_dbc.def_vals.items()} #remove duplicates - def_vals = [(address, sig) for address, sig in sorted(def_vals.items())] - - if can_dbc.name.startswith("honda") or can_dbc.name.startswith("acura"): - checksum_type = "honda" - checksum_size = 4 - elif can_dbc.name.startswith("toyota") or can_dbc.name.startswith("lexus"): - checksum_type = "toyota" - checksum_size = 8 - else: - checksum_type = None - - for address, msg_name, msg_size, sigs in msgs: - for sig in sigs: - if checksum_type is not None and sig.name == b"CHECKSUM": + can_dbc = dbc(os.path.join(dbc_dir, dbc_name + '.dbc')) + + 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("CHECKSUM is not %d bits longs %s" % (checksum_size, msg_name)) - if checksum_type == "honda" and sig.start_bit % 8 != 3: - sys.exit("CHECKSUM starts at wrong bit %s" % msg_name) - if checksum_type == "toyota" and sig.start_bit % 8 != 7: - sys.exit("CHECKSUM starts at wrong bit %s" % msg_name) - if checksum_type == "honda" and sig.name == b"COUNTER": - if sig.size != 2: - sys.exit("COUNTER is not 2 bits longs %s" % msg_name) - if sig.start_bit % 8 != 5: - sys.exit("COUNTER starts at wrong bit %s" % msg_name) - if address in [0x200, 0x201]: - if sig.name == b"COUNTER_PEDAL" and sig.size != 4: - sys.exit("PEDAL COUNTER is not 4 bits longs %s" % msg_name) - if sig.name == b"CHECKSUM_PEDAL" and sig.size != 8: - sys.exit("PEDAL CHECKSUM is not 8 bits longs %s" % 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("Duplicate message name in DBC file %s" % 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) + 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) if __name__ == '__main__': main() diff --git a/selfdrive/can/tests/packer_old.py b/selfdrive/can/tests/packer_old.py deleted file mode 100644 index 63120218e96c0a..00000000000000 --- a/selfdrive/can/tests/packer_old.py +++ /dev/null @@ -1,68 +0,0 @@ -import struct -from selfdrive.can.libdbc_py import libdbc, ffi - - -class CANPacker(): - def __init__(self, dbc_name): - dbc_name = dbc_name.encode('utf8') - self.packer = libdbc.canpack_init(dbc_name) - self.dbc = libdbc.dbc_lookup(dbc_name) - self.sig_names = {} - self.name_to_address_and_size = {} - - num_msgs = self.dbc[0].num_msgs - for i in range(num_msgs): - msg = self.dbc[0].msgs[i] - - name = ffi.string(msg.name).decode('utf8') - address = msg.address - self.name_to_address_and_size[name] = (address, msg.size) - self.name_to_address_and_size[address] = (address, msg.size) - - def pack(self, addr, values, counter): - values_thing = [] - for name, value in values.items(): - if name not in self.sig_names: - self.sig_names[name] = ffi.new("char[]", name.encode('utf8')) - - values_thing.append({ - 'name': self.sig_names[name], - 'value': value - }) - - values_c = ffi.new("SignalPackValue[]", values_thing) - - return libdbc.canpack_pack(self.packer, addr, len(values_thing), values_c, counter) - - def pack_bytes(self, addr, values, counter=-1): - addr, size = self.name_to_address_and_size[addr] - - val = self.pack(addr, values, counter) - r = struct.pack(">Q", val) - return addr, r[:size] - - def make_can_msg(self, addr, bus, values, counter=-1): - addr, msg = self.pack_bytes(addr, values, counter) - return [addr, 0, msg, bus] - - -if __name__ == "__main__": - ## little endian test - cp = CANPacker("hyundai_santa_fe_2019_ccan") - s = cp.pack_bytes(0x340, { - "CR_Lkas_StrToqReq": -0.06, - #"CF_Lkas_FcwBasReq": 1, - "CF_Lkas_MsgCount": 7, - "CF_Lkas_HbaSysState": 0, - #"CF_Lkas_Chksum": 3, - }) - s = cp.pack_bytes(0x340, { - "CF_Lkas_MsgCount": 1, - }) - # big endian test - #cp = CANPacker("honda_civic_touring_2016_can_generated") - #s = cp.pack_bytes(0xe4, { - # "STEER_TORQUE": -2, - #}) - print([hex(ord(v)) for v in s[1]]) - print(s[1].encode("hex")) diff --git a/selfdrive/can/tests/parser_old.py b/selfdrive/can/tests/parser_old.py deleted file mode 100644 index 1d2da57862f3f9..00000000000000 --- a/selfdrive/can/tests/parser_old.py +++ /dev/null @@ -1,220 +0,0 @@ -import time -import numbers - -from selfdrive.can.libdbc_py import libdbc, ffi - -CAN_INVALID_CNT = 5 # after so many consecutive CAN data with wrong checksum, counter or frequency, flag CAN invalidity - -class CANParser(): - def __init__(self, dbc_name, signals, checks=None, bus=0, sendcan=False, tcp_addr="127.0.0.1", timeout=-1): - if checks is None: - checks = [] - - self.can_valid = True - self.can_invalid_cnt = CAN_INVALID_CNT - self.vl = {} - self.ts = {} - - self.dbc_name = dbc_name - self.dbc = libdbc.dbc_lookup(dbc_name.encode('utf8')) - self.msg_name_to_addres = {} - self.address_to_msg_name = {} - - num_msgs = self.dbc[0].num_msgs - for i in range(num_msgs): - msg = self.dbc[0].msgs[i] - - name = ffi.string(msg.name).decode('utf8') - address = msg.address - - self.msg_name_to_addres[name] = address - self.address_to_msg_name[address] = name - - self.vl[address] = {} - self.vl[name] = {} - self.ts[address] = {} - self.ts[name] = {} - - # Convert message names into addresses - for i in range(len(signals)): - s = signals[i] - if not isinstance(s[1], numbers.Number): - s = (s[0], self.msg_name_to_addres[s[1]], s[2]) - signals[i] = s - - for i in range(len(checks)): - c = checks[i] - if not isinstance(c[0], numbers.Number): - c = (self.msg_name_to_addres[c[0]], c[1]) - checks[i] = c - - sig_names = dict((name, ffi.new("char[]", name.encode('utf8'))) for name, _, _ in signals) - - signal_options_c = ffi.new("SignalParseOptions[]", [ - { - 'address': sig_address, - 'name': sig_names[sig_name], - 'default_value': sig_default, - } for sig_name, sig_address, sig_default in signals]) - - message_options = dict((address, 0) for _, address, _ in signals) - message_options.update(dict(checks)) - - message_options_c = ffi.new("MessageParseOptions[]", [ - { - 'address': msg_address, - 'check_frequency': freq, - } for msg_address, freq in message_options.items()]) - - self.can = libdbc.can_init(bus, dbc_name.encode('utf8'), len(message_options_c), message_options_c, - len(signal_options_c), signal_options_c, sendcan, tcp_addr.encode('utf8'), timeout) - - self.p_can_valid = ffi.new("bool*") - - value_count = libdbc.can_query_latest(self.can, self.p_can_valid, 0, ffi.NULL) - self.can_values = ffi.new("SignalValue[%d]" % value_count) - self.update_vl(0) - - def update_vl(self, sec): - can_values_len = libdbc.can_query_latest(self.can, self.p_can_valid, len(self.can_values), self.can_values) - assert can_values_len <= len(self.can_values) - - self.can_invalid_cnt += 1 - if self.p_can_valid[0]: - self.can_invalid_cnt = 0 - self.can_valid = self.can_invalid_cnt < CAN_INVALID_CNT - - ret = set() - for i in range(can_values_len): - cv = self.can_values[i] - address = cv.address - # print("{0} {1}".format(hex(cv.address), ffi.string(cv.name))) - name = ffi.string(cv.name).decode('utf8') - self.vl[address][name] = cv.value - self.ts[address][name] = cv.ts - - sig_name = self.address_to_msg_name[address] - self.vl[sig_name][name] = cv.value - self.ts[sig_name][name] = cv.ts - ret.add(address) - return ret - - def update(self, sec, wait): - """Returns if the update was successfull (e.g. no rcv timeout happened)""" - r = libdbc.can_update(self.can, sec, wait) - return bool(r >= 0), self.update_vl(sec) - - -if __name__ == "__main__": - from common.realtime import sec_since_boot - - radar_messages = range(0x430, 0x43A) + range(0x440, 0x446) - # signals = zip(['LONG_DIST'] * 16 + ['NEW_TRACK'] * 16 + ['LAT_DIST'] * 16 + - # ['REL_SPEED'] * 16, radar_messages * 4, - # [255] * 16 + [1] * 16 + [0] * 16 + [0] * 16) - # checks = zip(radar_messages, [20]*16) - - # cp = CANParser("acura_ilx_2016_nidec", signals, checks, 1) - - - # signals = [ - # ("XMISSION_SPEED", 0x158, 0), #sig_name, sig_address, default - # ("WHEEL_SPEED_FL", 0x1d0, 0), - # ("WHEEL_SPEED_FR", 0x1d0, 0), - # ("WHEEL_SPEED_RL", 0x1d0, 0), - # ("STEER_ANGLE", 0x14a, 0), - # ("STEER_TORQUE_SENSOR", 0x18f, 0), - # ("GEAR", 0x191, 0), - # ("WHEELS_MOVING", 0x1b0, 1), - # ("DOOR_OPEN_FL", 0x405, 1), - # ("DOOR_OPEN_FR", 0x405, 1), - # ("DOOR_OPEN_RL", 0x405, 1), - # ("DOOR_OPEN_RR", 0x405, 1), - # ("CRUISE_SPEED_PCM", 0x324, 0), - # ("SEATBELT_DRIVER_LAMP", 0x305, 1), - # ("SEATBELT_DRIVER_LATCHED", 0x305, 0), - # ("BRAKE_PRESSED", 0x17c, 0), - # ("CAR_GAS", 0x130, 0), - # ("CRUISE_BUTTONS", 0x296, 0), - # ("ESP_DISABLED", 0x1a4, 1), - # ("HUD_LEAD", 0x30c, 0), - # ("USER_BRAKE", 0x1a4, 0), - # ("STEER_STATUS", 0x18f, 5), - # ("WHEEL_SPEED_RR", 0x1d0, 0), - # ("BRAKE_ERROR_1", 0x1b0, 1), - # ("BRAKE_ERROR_2", 0x1b0, 1), - # ("GEAR_SHIFTER", 0x191, 0), - # ("MAIN_ON", 0x326, 0), - # ("ACC_STATUS", 0x17c, 0), - # ("PEDAL_GAS", 0x17c, 0), - # ("CRUISE_SETTING", 0x296, 0), - # ("LEFT_BLINKER", 0x326, 0), - # ("RIGHT_BLINKER", 0x326, 0), - # ("COUNTER", 0x324, 0), - # ("ENGINE_RPM", 0x17C, 0) - # ] - # checks = [ - # (0x14a, 100), # address, frequency - # (0x158, 100), - # (0x17c, 100), - # (0x191, 100), - # (0x1a4, 50), - # (0x326, 10), - # (0x1b0, 50), - # (0x1d0, 50), - # (0x305, 10), - # (0x324, 10), - # (0x405, 3), - # ] - - # cp = CANParser("honda_civic_touring_2016_can_generated", signals, checks, 0) - - - signals = [ - # sig_name, sig_address, default - ("GEAR", 956, 0x20), - ("BRAKE_PRESSED", 548, 0), - ("GAS_PEDAL", 705, 0), - - ("WHEEL_SPEED_FL", 170, 0), - ("WHEEL_SPEED_FR", 170, 0), - ("WHEEL_SPEED_RL", 170, 0), - ("WHEEL_SPEED_RR", 170, 0), - ("DOOR_OPEN_FL", 1568, 1), - ("DOOR_OPEN_FR", 1568, 1), - ("DOOR_OPEN_RL", 1568, 1), - ("DOOR_OPEN_RR", 1568, 1), - ("SEATBELT_DRIVER_UNLATCHED", 1568, 1), - ("TC_DISABLED", 951, 1), - ("STEER_ANGLE", 37, 0), - ("STEER_FRACTION", 37, 0), - ("STEER_RATE", 37, 0), - ("GAS_RELEASED", 466, 0), - ("CRUISE_STATE", 466, 0), - ("MAIN_ON", 467, 0), - ("SET_SPEED", 467, 0), - ("STEER_TORQUE_DRIVER", 608, 0), - ("STEER_TORQUE_EPS", 608, 0), - ("TURN_SIGNALS", 1556, 3), # 3 is no blinkers - ("LKA_STATE", 610, 0), - ] - checks = [ - (548, 40), - (705, 33), - - (170, 80), - (37, 80), - (466, 33), - (608, 50), - ] - - cp = CANParser("toyota_rav4_2017_pt_generated", signals, checks, 0) - - # print(cp.vl) - - while True: - cp.update(int(sec_since_boot()*1e9), True) - # print(cp.vl) - print(cp.ts) - print(cp.can_valid) - time.sleep(0.01) diff --git a/selfdrive/can/tests/test_packer_chrysler.py b/selfdrive/can/tests/test_packer_chrysler.py deleted file mode 100644 index e566d87a72a40a..00000000000000 --- a/selfdrive/can/tests/test_packer_chrysler.py +++ /dev/null @@ -1,35 +0,0 @@ -import unittest -import random - -from selfdrive.can.tests.packer_old import CANPacker as CANPackerOld -from selfdrive.can.packer import CANPacker -import selfdrive.car.chrysler.chryslercan as chryslercan - - -class TestPackerMethods(unittest.TestCase): - def setUp(self): - self.chrysler_cp_old = CANPackerOld("chrysler_pacifica_2017_hybrid") - self.chrysler_cp = CANPacker("chrysler_pacifica_2017_hybrid") - - def test_correctness(self): - # Test all commands, randomize the params. - for _ in range(1000): - gear = ('drive', 'reverse', 'low')[random.randint(0, 3) % 3] - lkas_active = (random.randint(0, 2) % 2 == 0) - hud_alert = random.randint(0, 6) - hud_count = random.randint(0, 65536) - lkas_car_model = random.randint(0, 65536) - m_old = chryslercan.create_lkas_hud(self.chrysler_cp_old, gear, lkas_active, hud_alert, hud_count, lkas_car_model) - m = chryslercan.create_lkas_hud(self.chrysler_cp, gear, lkas_active, hud_alert, hud_count, lkas_car_model) - self.assertEqual(m_old, m) - - apply_steer = (random.randint(0, 2) % 2 == 0) - moving_fast = (random.randint(0, 2) % 2 == 0) - frame = random.randint(0, 65536) - m_old = chryslercan.create_lkas_command(self.chrysler_cp_old, apply_steer, moving_fast, frame) - m = chryslercan.create_lkas_command(self.chrysler_cp, apply_steer, moving_fast, frame) - self.assertEqual(m_old, m) - - -if __name__ == "__main__": - unittest.main() diff --git a/selfdrive/can/tests/test_packer_gm.py b/selfdrive/can/tests/test_packer_gm.py deleted file mode 100644 index 54119fbe436b0b..00000000000000 --- a/selfdrive/can/tests/test_packer_gm.py +++ /dev/null @@ -1,66 +0,0 @@ -import unittest -import random - -from selfdrive.can.tests.packer_old import CANPacker as CANPackerOld -from selfdrive.can.packer import CANPacker -import selfdrive.car.gm.gmcan as gmcan -from selfdrive.car.gm.interface import CanBus as GMCanBus - - -class TestPackerMethods(unittest.TestCase): - def setUp(self): - self.gm_cp_old = CANPackerOld("gm_global_a_powertrain") - self.gm_cp = CANPacker("gm_global_a_powertrain") - - self.ct6_cp_old = CANPackerOld("cadillac_ct6_chassis") - self.ct6_cp = CANPacker("cadillac_ct6_chassis") - - def test_correctness(self): - # Test all cars' commands, randomize the params. - for _ in range(1000): - bus = random.randint(0, 65536) - apply_steer = (random.randint(0, 2) % 2 == 0) - idx = random.randint(0, 65536) - lkas_active = (random.randint(0, 2) % 2 == 0) - m_old = gmcan.create_steering_control(self.gm_cp_old, bus, apply_steer, idx, lkas_active) - m = gmcan.create_steering_control(self.gm_cp, bus, apply_steer, idx, lkas_active) - self.assertEqual(m_old, m) - - canbus = GMCanBus() - apply_steer = (random.randint(0, 2) % 2 == 0) - v_ego = random.randint(0, 65536) - idx = random.randint(0, 65536) - enabled = (random.randint(0, 2) % 2 == 0) - m_old = gmcan.create_steering_control_ct6(self.ct6_cp_old, canbus, apply_steer, v_ego, idx, enabled) - m = gmcan.create_steering_control_ct6(self.ct6_cp, canbus, apply_steer, v_ego, idx, enabled) - self.assertEqual(m_old, m) - - bus = random.randint(0, 65536) - throttle = random.randint(0, 65536) - idx = random.randint(0, 65536) - acc_engaged = (random.randint(0, 2) % 2 == 0) - at_full_stop = (random.randint(0, 2) % 2 == 0) - m_old = gmcan.create_gas_regen_command(self.gm_cp_old, bus, throttle, idx, acc_engaged, at_full_stop) - m = gmcan.create_gas_regen_command(self.gm_cp, bus, throttle, idx, acc_engaged, at_full_stop) - self.assertEqual(m_old, m) - - bus = random.randint(0, 65536) - apply_brake = (random.randint(0, 2) % 2 == 0) - idx = random.randint(0, 65536) - near_stop = (random.randint(0, 2) % 2 == 0) - at_full_stop = (random.randint(0, 2) % 2 == 0) - m_old = gmcan.create_friction_brake_command(self.ct6_cp_old, bus, apply_brake, idx, near_stop, at_full_stop) - m = gmcan.create_friction_brake_command(self.ct6_cp, bus, apply_brake, idx, near_stop, at_full_stop) - self.assertEqual(m_old, m) - - bus = random.randint(0, 65536) - acc_engaged = (random.randint(0, 2) % 2 == 0) - target_speed_kph = random.randint(0, 65536) - lead_car_in_sight = (random.randint(0, 2) % 2 == 0) - m_old = gmcan.create_acc_dashboard_command(self.gm_cp_old, bus, acc_engaged, target_speed_kph, lead_car_in_sight) - m = gmcan.create_acc_dashboard_command(self.gm_cp, bus, acc_engaged, target_speed_kph, lead_car_in_sight) - self.assertEqual(m_old, m) - - -if __name__ == "__main__": - unittest.main() diff --git a/selfdrive/can/tests/test_packer_honda.py b/selfdrive/can/tests/test_packer_honda.py deleted file mode 100644 index 3a9548a3ef5f5a..00000000000000 --- a/selfdrive/can/tests/test_packer_honda.py +++ /dev/null @@ -1,56 +0,0 @@ -import unittest -import random - -from selfdrive.can.tests.packer_old import CANPacker as CANPackerOld -from selfdrive.can.packer import CANPacker -import selfdrive.car.honda.hondacan as hondacan -from selfdrive.car.honda.values import HONDA_BOSCH -from selfdrive.car.honda.carcontroller import HUDData - - -class TestPackerMethods(unittest.TestCase): - def setUp(self): - self.honda_cp_old = CANPackerOld("honda_pilot_touring_2017_can_generated") - self.honda_cp = CANPacker("honda_pilot_touring_2017_can_generated") - - def test_correctness(self): - # Test all commands, randomize the params. - for _ in range(1000): - has_relay = False - car_fingerprint = HONDA_BOSCH[0] - - apply_brake = (random.randint(0, 2) % 2 == 0) - pump_on = (random.randint(0, 2) % 2 == 0) - pcm_override = (random.randint(0, 2) % 2 == 0) - pcm_cancel_cmd = (random.randint(0, 2) % 2 == 0) - fcw = random.randint(0, 65536) - idx = random.randint(0, 65536) - m_old = hondacan.create_brake_command(self.honda_cp_old, apply_brake, pump_on, pcm_override, pcm_cancel_cmd, fcw, idx, car_fingerprint, has_relay) - m = hondacan.create_brake_command(self.honda_cp, apply_brake, pump_on, pcm_override, pcm_cancel_cmd, fcw, idx, car_fingerprint, has_relay) - self.assertEqual(m_old, m) - - apply_steer = (random.randint(0, 2) % 2 == 0) - lkas_active = (random.randint(0, 2) % 2 == 0) - idx = random.randint(0, 65536) - m_old = hondacan.create_steering_control(self.honda_cp_old, apply_steer, lkas_active, car_fingerprint, idx, has_relay) - m = hondacan.create_steering_control(self.honda_cp, apply_steer, lkas_active, car_fingerprint, idx, has_relay) - self.assertEqual(m_old, m) - - pcm_speed = random.randint(0, 65536) - hud = HUDData(random.randint(0, 65536), random.randint(0, 65536), 1, random.randint(0, 65536), - 0xc1, random.randint(0, 65536), random.randint(0, 65536), random.randint(0, 65536), random.randint(0, 65536)) - idx = random.randint(0, 65536) - is_metric = (random.randint(0, 2) % 2 == 0) - m_old = hondacan.create_ui_commands(self.honda_cp_old, pcm_speed, hud, car_fingerprint, is_metric, idx, has_relay) - m = hondacan.create_ui_commands(self.honda_cp, pcm_speed, hud, car_fingerprint, is_metric, idx, has_relay) - self.assertEqual(m_old, m) - - button_val = random.randint(0, 65536) - idx = random.randint(0, 65536) - m_old = hondacan.spam_buttons_command(self.honda_cp_old, button_val, idx, car_fingerprint, has_relay) - m = hondacan.spam_buttons_command(self.honda_cp, button_val, idx, car_fingerprint, has_relay) - self.assertEqual(m_old, m) - - -if __name__ == "__main__": - unittest.main() diff --git a/selfdrive/can/tests/test_packer_hyundai.py b/selfdrive/can/tests/test_packer_hyundai.py deleted file mode 100644 index c2bcb04014c560..00000000000000 --- a/selfdrive/can/tests/test_packer_hyundai.py +++ /dev/null @@ -1,70 +0,0 @@ -import unittest -import random - -from selfdrive.can.tests.packer_old import CANPacker as CANPackerOld -from selfdrive.can.packer import CANPacker -import selfdrive.car.hyundai.hyundaican as hyundaican -from selfdrive.car.hyundai.values import CHECKSUM as hyundai_checksum - - -class TestPackerMethods(unittest.TestCase): - def setUp(self): - self.hyundai_cp_old = CANPackerOld("hyundai_kia_generic") - self.hyundai_cp = CANPacker("hyundai_kia_generic") - - def test_correctness(self): - # Test all commands, randomize the params. - for _ in range(1000): - # Hyundai - car_fingerprint = hyundai_checksum["crc8"][0] - apply_steer = (random.randint(0, 2) % 2 == 0) - steer_req = (random.randint(0, 2) % 2 == 0) - cnt = random.randint(0, 65536) - enabled = (random.randint(0, 2) % 2 == 0) - lkas11 = { - "CF_Lkas_LdwsSysState": random.randint(0,65536), - "CF_Lkas_SysWarning": random.randint(0,65536), - "CF_Lkas_LdwsLHWarning": random.randint(0,65536), - "CF_Lkas_LdwsRHWarning": random.randint(0,65536), - "CF_Lkas_HbaLamp": random.randint(0,65536), - "CF_Lkas_FcwBasReq": random.randint(0,65536), - "CF_Lkas_ToiFlt": random.randint(0,65536), - "CF_Lkas_HbaSysState": random.randint(0,65536), - "CF_Lkas_FcwOpt": random.randint(0,65536), - "CF_Lkas_HbaOpt": random.randint(0,65536), - "CF_Lkas_FcwSysState": random.randint(0,65536), - "CF_Lkas_FcwCollisionWarning": random.randint(0,65536), - "CF_Lkas_FusionState": random.randint(0,65536), - "CF_Lkas_FcwOpt_USM": random.randint(0,65536), - "CF_Lkas_LdwsOpt_USM": random.randint(0,65536) - } - hud_alert = random.randint(0, 65536) - keep_stock = (random.randint(0, 2) % 2 == 0) - m_old = hyundaican.create_lkas11(self.hyundai_cp_old, car_fingerprint, apply_steer, steer_req, cnt, enabled, - lkas11, hud_alert, keep_stock) - m = hyundaican.create_lkas11(self.hyundai_cp, car_fingerprint, apply_steer, steer_req, cnt, enabled, - lkas11, hud_alert, keep_stock) - self.assertEqual(m_old, m) - - clu11 = { - "CF_Clu_CruiseSwState": random.randint(0,65536), - "CF_Clu_CruiseSwMain": random.randint(0,65536), - "CF_Clu_SldMainSW": random.randint(0,65536), - "CF_Clu_ParityBit1": random.randint(0,65536), - "CF_Clu_VanzDecimal": random.randint(0,65536), - "CF_Clu_Vanz": random.randint(0,65536), - "CF_Clu_SPEED_UNIT": random.randint(0,65536), - "CF_Clu_DetentOut": random.randint(0,65536), - "CF_Clu_RheostatLevel": random.randint(0,65536), - "CF_Clu_CluInfo": random.randint(0,65536), - "CF_Clu_AmpInfo": random.randint(0,65536), - "CF_Clu_AliveCnt1": random.randint(0,65536), - } - button = random.randint(0, 65536) - m_old = hyundaican.create_clu11(self.hyundai_cp_old, clu11, button) - m = hyundaican.create_clu11(self.hyundai_cp, clu11, button) - self.assertEqual(m_old, m) - - -if __name__ == "__main__": - unittest.main() diff --git a/selfdrive/can/tests/test_packer_parser.py b/selfdrive/can/tests/test_packer_parser.py new file mode 100644 index 00000000000000..9b8a886c465590 --- /dev/null +++ b/selfdrive/can/tests/test_packer_parser.py @@ -0,0 +1,92 @@ +#!/usr/bin/env python3 + +import unittest + +from selfdrive.can.parser import CANParser +from selfdrive.can.packer import CANPacker + +from selfdrive.boardd.boardd import can_list_to_can_capnp + +from selfdrive.car.honda.interface import CarInterface as HondaInterface +from selfdrive.car.honda.values import CAR as HONDA_CAR +from selfdrive.car.honda.values import DBC as HONDA_DBC + +from selfdrive.car.subaru.interface import CarInterface as SubaruInterface +from selfdrive.car.subaru.values import CAR as SUBARU_CAR +from selfdrive.car.subaru.values import DBC as SUBARU_DBC + +class TestCanParserPacker(unittest.TestCase): + def test_civic(self): + CP = HondaInterface.get_params(HONDA_CAR.CIVIC) + + signals = [ + ("STEER_TORQUE", "STEERING_CONTROL", 0), + ("STEER_TORQUE_REQUEST", "STEERING_CONTROL", 0), + ] + checks = [] + + parser = CANParser(HONDA_DBC[CP.carFingerprint]['pt'], signals, checks, 0) + packer = CANPacker(HONDA_DBC[CP.carFingerprint]['pt']) + + idx = 0 + + for steer in range(0, 255): + for active in [1, 0]: + values = { + "STEER_TORQUE": steer, + "STEER_TORQUE_REQUEST": active, + } + + msgs = packer.make_can_msg("STEERING_CONTROL", 0, values, idx) + bts = can_list_to_can_capnp([msgs]) + + parser.update_string(bts) + + self.assertAlmostEqual(parser.vl["STEERING_CONTROL"]["STEER_TORQUE"], steer) + self.assertAlmostEqual(parser.vl["STEERING_CONTROL"]["STEER_TORQUE_REQUEST"], active) + self.assertAlmostEqual(parser.vl["STEERING_CONTROL"]["COUNTER"], idx % 4) + + idx += 1 + + def test_subaru(self): + # Subuaru is little endian + CP = SubaruInterface.get_params(SUBARU_CAR.IMPREZA) + + signals = [ + ("Counter", "ES_LKAS", 0), + ("LKAS_Output", "ES_LKAS", 0), + ("LKAS_Request", "ES_LKAS", 0), + ("SET_1", "ES_LKAS", 0), + + ] + + checks = [] + + parser = CANParser(SUBARU_DBC[CP.carFingerprint]['pt'], signals, checks, 0) + packer = CANPacker(SUBARU_DBC[CP.carFingerprint]['pt']) + + idx = 0 + + for steer in range(0, 255): + for active in [1, 0]: + values = { + "Counter": idx, + "LKAS_Output": steer, + "LKAS_Request": active, + "SET_1": 1 + } + + msgs = packer.make_can_msg("ES_LKAS", 0, values) + bts = can_list_to_can_capnp([msgs]) + parser.update_string(bts) + + self.assertAlmostEqual(parser.vl["ES_LKAS"]["LKAS_Output"], steer) + self.assertAlmostEqual(parser.vl["ES_LKAS"]["LKAS_Request"], active) + self.assertAlmostEqual(parser.vl["ES_LKAS"]["SET_1"], 1) + self.assertAlmostEqual(parser.vl["ES_LKAS"]["Counter"], idx % 16) + + idx += 1 + + +if __name__ == "__main__": + unittest.main() diff --git a/selfdrive/can/tests/test_packer_subaru.py b/selfdrive/can/tests/test_packer_subaru.py deleted file mode 100644 index 0690806d7c1917..00000000000000 --- a/selfdrive/can/tests/test_packer_subaru.py +++ /dev/null @@ -1,37 +0,0 @@ -import unittest -import random - -from selfdrive.can.tests.packer_old import CANPacker as CANPackerOld -from selfdrive.can.packer import CANPacker -import selfdrive.car.subaru.subarucan as subarucan -from selfdrive.car.subaru.values import CAR as subaru_car - - -class TestPackerMethods(unittest.TestCase): - def setUp(self): - self.subaru_cp_old = CANPackerOld("subaru_global_2017") - self.subaru_cp = CANPacker("subaru_global_2017") - - def test_correctness(self): - # Test all cars' commands, randomize the params. - for _ in range(1000): - apply_steer = (random.randint(0, 2) % 2 == 0) - frame = random.randint(1, 65536) - steer_step = random.randint(1, 65536) - m_old = subarucan.create_steering_control(self.subaru_cp_old, subaru_car.IMPREZA, apply_steer, frame, steer_step) - m = subarucan.create_steering_control(self.subaru_cp, subaru_car.IMPREZA, apply_steer, frame, steer_step) - self.assertEqual(m_old, m) - - m_old = subarucan.create_steering_status(self.subaru_cp_old, subaru_car.IMPREZA, apply_steer, frame, steer_step) - m = subarucan.create_steering_status(self.subaru_cp, subaru_car.IMPREZA, apply_steer, frame, steer_step) - self.assertEqual(m_old, m) - - es_distance_msg = {} - pcm_cancel_cmd = (random.randint(0, 2) % 2 == 0) - m_old = subarucan.create_es_distance(self.subaru_cp_old, es_distance_msg, pcm_cancel_cmd) - m = subarucan.create_es_distance(self.subaru_cp, es_distance_msg, pcm_cancel_cmd) - self.assertEqual(m_old, m) - - -if __name__ == "__main__": - unittest.main() diff --git a/selfdrive/can/tests/test_packer_toyota.py b/selfdrive/can/tests/test_packer_toyota.py deleted file mode 100644 index 05f5eeed2e0348..00000000000000 --- a/selfdrive/can/tests/test_packer_toyota.py +++ /dev/null @@ -1,86 +0,0 @@ -import unittest -import random - -from selfdrive.can.tests.packer_old import CANPacker as CANPackerOld -from selfdrive.can.packer import CANPacker -from selfdrive.car.toyota.toyotacan import ( - create_ipas_steer_command, create_steer_command, create_accel_command, - create_fcw_command, create_ui_command -) -from common.realtime import sec_since_boot - - -class TestPackerMethods(unittest.TestCase): - def setUp(self): - self.cp_old = CANPackerOld("toyota_rav4_hybrid_2017_pt_generated") - self.cp = CANPacker("toyota_rav4_hybrid_2017_pt_generated") - - def test_correctness(self): - # Test all commands, randomize the params. - for _ in range(1000): - # Toyota - steer = random.randint(-1, 1) - enabled = (random.randint(0, 2) % 2 == 0) - apgs_enabled = (random.randint(0, 2) % 2 == 0) - m_old = create_ipas_steer_command(self.cp_old, steer, enabled, apgs_enabled) - m = create_ipas_steer_command(self.cp, steer, enabled, apgs_enabled) - self.assertEqual(m_old, m) - - steer = (random.randint(0, 2) % 2 == 0) - steer_req = (random.randint(0, 2) % 2 == 0) - raw_cnt = random.randint(1, 65536) - m_old = create_steer_command(self.cp_old, steer, steer_req, raw_cnt) - m = create_steer_command(self.cp, steer, steer_req, raw_cnt) - self.assertEqual(m_old, m) - - accel = (random.randint(0, 2) % 2 == 0) - pcm_cancel = (random.randint(0, 2) % 2 == 0) - standstill_req = (random.randint(0, 2) % 2 == 0) - lead = (random.randint(0, 2) % 2 == 0) - m_old = create_accel_command(self.cp_old, accel, pcm_cancel, standstill_req, lead) - m = create_accel_command(self.cp, accel, pcm_cancel, standstill_req, lead) - self.assertEqual(m_old, m) - - fcw = random.randint(1, 65536) - m_old = create_fcw_command(self.cp_old, fcw) - m = create_fcw_command(self.cp, fcw) - self.assertEqual(m_old, m) - - steer = (random.randint(0, 2) % 2 == 0) - chime = random.randint(1, 65536) - left_line = (random.randint(0, 2) % 2 == 0) - right_line = (random.randint(0, 2) % 2 == 0) - left_lane_depart = (random.randint(0, 2) % 2 == 0) - right_lane_depart = (random.randint(0, 2) % 2 == 0) - m_old = create_ui_command(self.cp_old, steer, chime, left_line, right_line, left_lane_depart, right_lane_depart) - m = create_ui_command(self.cp, steer, chime, left_line, right_line, left_lane_depart, right_lane_depart) - self.assertEqual(m_old, m) - - def test_performance(self): - n1 = sec_since_boot() - recursions = 100000 - steer = (random.randint(0, 2) % 2 == 0) - chime = random.randint(1, 65536) - left_line = (random.randint(0, 2) % 2 == 0) - right_line = (random.randint(0, 2) % 2 == 0) - left_lane_depart = (random.randint(0, 2) % 2 == 0) - right_lane_depart = (random.randint(0, 2) % 2 == 0) - - for _ in range(recursions): - create_ui_command(self.cp_old, steer, chime, left_line, right_line, left_lane_depart, right_lane_depart) - n2 = sec_since_boot() - elapsed_old = n2 - n1 - - # print('Old API, elapsed time: {} secs'.format(elapsed_old)) - n1 = sec_since_boot() - for _ in range(recursions): - create_ui_command(self.cp, steer, chime, left_line, right_line, left_lane_depart, right_lane_depart) - n2 = sec_since_boot() - elapsed_new = n2 - n1 - # print('New API, elapsed time: {} secs'.format(elapsed_new)) - self.assertTrue(elapsed_new < elapsed_old / 2) - - - -if __name__ == "__main__": - unittest.main() diff --git a/selfdrive/can/tests/test_parser.py b/selfdrive/can/tests/test_parser.py deleted file mode 100755 index 09d153c1bd45ca..00000000000000 --- a/selfdrive/can/tests/test_parser.py +++ /dev/null @@ -1,106 +0,0 @@ -#!/usr/bin/env python3 - -import os -import unittest - -import requests - -import selfdrive.messaging as messaging -from selfdrive.can.parser import CANParser as CANParserNew -from selfdrive.can.tests.parser_old import CANParser as CANParserOld -from selfdrive.car.honda.carstate import get_can_signals -from selfdrive.car.honda.interface import CarInterface -from selfdrive.car.honda.values import CAR, DBC -from selfdrive.services import service_list -from tools.lib.logreader import LogReader - -BASE_URL = "https://commadataci.blob.core.windows.net/openpilotci/" -DT = int(0.01 * 1e9) # ns - - -def dict_keys_differ(dict1, dict2): - keys1 = set(dict1.keys()) - keys2 = set(dict2.keys()) - - if keys1 != keys2: - return True - - for k in keys1: - keys1 = set(dict1[k].keys()) - keys2 = set(dict2[k].keys()) - - if keys1 != keys2: - return True - - return False - -def dicts_vals_differ(dict1, dict2): - for k_outer in dict1.keys(): - for k_inner in dict1[k_outer].keys(): - if dict1[k_outer][k_inner] != dict2[k_outer][k_inner]: - return True - - return False - -def run_route(route): - can = messaging.pub_sock(service_list['can'].port) - - CP = CarInterface.get_params(CAR.CIVIC) - signals, checks = get_can_signals(CP) - parser_old = CANParserOld(DBC[CP.carFingerprint]['pt'], signals, checks, 0, timeout=-1, tcp_addr="127.0.0.1") - parser_new = CANParserNew(DBC[CP.carFingerprint]['pt'], signals, checks, 0, timeout=-1, tcp_addr="127.0.0.1") - parser_string = CANParserNew(DBC[CP.carFingerprint]['pt'], signals, checks, 0, timeout=-1) - - if dict_keys_differ(parser_old.vl, parser_new.vl): - return False - - lr = LogReader(route + ".bz2") - - route_ok = True - - for msg in lr: - if msg.which() == 'can': - t = msg.logMonoTime - msg_bytes = msg.as_builder().to_bytes() - can.send(msg_bytes) - - _, updated_old = parser_old.update(t, True) - _, updated_new = parser_new.update(t, True) - updated_string = parser_string.update_string(msg_bytes) - - if updated_old != updated_new: - route_ok = False - print(t, "Diff in seen") - - if updated_new != updated_string: - route_ok = False - print(t, "Diff in seen string") - - if dicts_vals_differ(parser_old.vl, parser_new.vl): - print(t, "Diff in dict") - route_ok = False - - if dicts_vals_differ(parser_new.vl, parser_string.vl): - print(t, "Diff in dict string") - route_ok = False - - return route_ok - -class TestCanParser(unittest.TestCase): - def setUp(self): - self.routes = { - CAR.CIVIC: "b0c9d2329ad1606b|2019-05-30--20-23-57" - } - - for route in self.routes.values(): - route_filename = route + ".bz2" - if not os.path.isfile(route_filename): - with open(route + ".bz2", "wb") as f: - f.write(requests.get(BASE_URL + route_filename).content) - - def test_parser_civic(self): - self.assertTrue(run_route(self.routes[CAR.CIVIC])) - - -if __name__ == "__main__": - unittest.main() diff --git a/selfdrive/car/car_helpers.py b/selfdrive/car/car_helpers.py index 85f52b41855f40..2a599ecea6f903 100644 --- a/selfdrive/car/car_helpers.py +++ b/selfdrive/car/car_helpers.py @@ -17,15 +17,6 @@ op_params = opParams() use_car_caching = op_params.get('use_car_caching', True) -def get_one_can(logcan): - while True: - try: - can = messaging.recv_one(logcan) - if len(can.can) > 0: - return can - except zmq.error.Again: - continue - def get_startup_alert(car_recognized, controller_available): alert = 'startup' @@ -110,7 +101,7 @@ def fingerprint(logcan, sendcan, has_relay): return (str(cached_fingerprint[0]), finger, vin) while not done: - a = get_one_can(logcan) + a = messaging.get_one_can(logcan) for can in a.can: # need to independently try to fingerprint both bus 0 and 1 to work diff --git a/selfdrive/car/chrysler/carcontroller.py b/selfdrive/car/chrysler/carcontroller.py index 7e2dc5cff60170..ed92b1427dcde1 100644 --- a/selfdrive/car/chrysler/carcontroller.py +++ b/selfdrive/car/chrysler/carcontroller.py @@ -1,16 +1,9 @@ from selfdrive.car import apply_toyota_steer_torque_limits from selfdrive.car.chrysler.chryslercan import create_lkas_hud, create_lkas_command, \ create_wheel_buttons -from selfdrive.car.chrysler.values import ECU, CAR +from selfdrive.car.chrysler.values import ECU, CAR, SteerLimitParams from selfdrive.can.packer import CANPacker -class SteerLimitParams: - STEER_MAX = 261 # 262 faults - STEER_DELTA_UP = 3 # 3 is stock. 100 is fine. 200 is too much it seems - STEER_DELTA_DOWN = 3 # no faults on the way down it seems - STEER_ERROR_MAX = 80 - - class CarController(): def __init__(self, dbc_name, car_fingerprint, enable_camera): self.braking = False diff --git a/selfdrive/car/chrysler/values.py b/selfdrive/car/chrysler/values.py index 3e829ac95b15b9..fa9a9c109890f8 100644 --- a/selfdrive/car/chrysler/values.py +++ b/selfdrive/car/chrysler/values.py @@ -1,5 +1,12 @@ from selfdrive.car import dbc_dict +class SteerLimitParams: + STEER_MAX = 261 # 262 faults + STEER_DELTA_UP = 3 # 3 is stock. 100 is fine. 200 is too much it seems + STEER_DELTA_DOWN = 3 # no faults on the way down it seems + STEER_ERROR_MAX = 80 + + class CAR: PACIFICA_2017_HYBRID = "CHRYSLER PACIFICA HYBRID 2017" diff --git a/selfdrive/car/gm/interface.py b/selfdrive/car/gm/interface.py index 81a2bfc5bd5e7e..4b9dc41c8d0410 100755 --- a/selfdrive/car/gm/interface.py +++ b/selfdrive/car/gm/interface.py @@ -62,7 +62,6 @@ def get_params(candidate, fingerprint=gen_empty_fingerprint(), vin="", has_relay candidate == CAR.CADILLAC_CT6 ret.openpilotLongitudinalControl = ret.enableCamera tire_stiffness_factor = 0.444 # not optimized yet - ret.safetyModelPassive = car.CarParams.SafetyModel.gmPassive if candidate == CAR.VOLT: # supports stop and go, but initial engage must be above 18mph (which include conservatism) diff --git a/selfdrive/car/honda/carstate.py b/selfdrive/car/honda/carstate.py index bb974b3d14d4d6..792542167ba359 100644 --- a/selfdrive/car/honda/carstate.py +++ b/selfdrive/car/honda/carstate.py @@ -354,19 +354,3 @@ def update(self, cp, cp_cam): # TODO: discover the CAN msg that has the imperial unit bit for all other cars self.is_metric = not cp.vl["HUD_SETTING"]['IMPERIAL_UNIT'] if self.CP.carFingerprint in (CAR.CIVIC) else False - -# carstate standalone tester -if __name__ == '__main__': - import zmq - context = zmq.Context() - - class CarParams(): - def __init__(self): - self.carFingerprint = "HONDA CIVIC 2016 TOURING" - self.enableGasInterceptor = 0 - CP = CarParams() - CS = CarState(CP) - - # while 1: - # CS.update() - # time.sleep(0.01) diff --git a/selfdrive/car/honda/values.py b/selfdrive/car/honda/values.py index ab940681300c8d..90dfd4eab32a9f 100644 --- a/selfdrive/car/honda/values.py +++ b/selfdrive/car/honda/values.py @@ -81,8 +81,9 @@ class CAR: CAR.CRV: [{ 57: 3, 145: 8, 316: 8, 340: 8, 342: 6, 344: 8, 380: 8, 398: 3, 399: 6, 401: 8, 404: 4, 420: 8, 422: 8, 426: 8, 432: 7, 464: 8, 474: 5, 476: 4, 487: 4, 490: 8, 493: 3, 506: 8, 507: 1, 512: 6, 513: 6, 542: 7, 545: 4, 597: 8, 660: 8, 661: 4, 773: 7, 777: 8, 780: 8, 800: 8, 804: 8, 808: 8, 829: 5, 882: 2, 884: 7, 888: 8, 891: 8, 892: 8, 923: 2, 929: 8, 983: 8, 985: 3, 1024: 5, 1027: 5, 1029: 8, 1033: 5, 1036: 8, 1039: 8, 1057: 5, 1064: 7, 1108: 8, 1125: 8, 1296: 8, 1365: 5, 1424: 5, 1600: 5, 1601: 8, }], + # msg 1115 has seen with len 2 and 4, so ignore it CAR.CRV_5G: [{ - 57: 3, 148: 8, 199: 4, 228: 5, 231: 5, 232: 7, 304: 8, 330: 8, 340: 8, 344: 8, 380: 8, 399: 7, 401: 8, 420: 8, 423: 2, 427: 3, 428: 8, 432: 7, 441: 5, 446: 3, 450: 8, 464: 8, 467: 2, 469: 3, 470: 2, 474: 8, 476: 7, 477: 8, 479: 8, 490: 8, 493: 5, 495: 8, 507: 1, 545: 6, 597: 8, 661: 4, 662: 4, 773: 7, 777: 8, 780: 8, 795: 8, 800: 8, 804: 8, 806: 8, 808: 8, 814: 4, 815: 8, 817: 4, 825: 4, 829: 5, 862: 8, 881: 8, 882: 4, 884: 8, 888: 8, 891: 8, 927: 8, 918: 7, 929: 8, 983: 8, 985: 3, 1024: 5, 1027: 5, 1029: 8, 1036: 8, 1039: 8, 1064: 7, 1108: 8, 1092: 1, 1115: 4, 1125: 8, 1127: 2, 1296: 8, 1302: 8, 1322: 5, 1361: 5, 1365: 5, 1424: 5, 1600: 5, 1601: 8, 1618: 5, 1633: 8, 1670: 5 + 57: 3, 148: 8, 199: 4, 228: 5, 231: 5, 232: 7, 304: 8, 330: 8, 340: 8, 344: 8, 380: 8, 399: 7, 401: 8, 420: 8, 423: 2, 427: 3, 428: 8, 432: 7, 441: 5, 446: 3, 450: 8, 464: 8, 467: 2, 469: 3, 470: 2, 474: 8, 476: 7, 477: 8, 479: 8, 490: 8, 493: 5, 495: 8, 507: 1, 545: 6, 597: 8, 661: 4, 662: 4, 773: 7, 777: 8, 780: 8, 795: 8, 800: 8, 804: 8, 806: 8, 808: 8, 814: 4, 815: 8, 817: 4, 825: 4, 829: 5, 862: 8, 881: 8, 882: 4, 884: 8, 888: 8, 891: 8, 927: 8, 918: 7, 929: 8, 983: 8, 985: 3, 1024: 5, 1027: 5, 1029: 8, 1036: 8, 1039: 8, 1064: 7, 1108: 8, 1092: 1, 1125: 8, 1127: 2, 1296: 8, 1302: 8, 1322: 5, 1361: 5, 1365: 5, 1424: 5, 1600: 5, 1601: 8, 1618: 5, 1633: 8, 1670: 5 }], CAR.CRV_HYBRID: [{ 57: 3, 148: 8, 228: 5, 304: 8, 330: 8, 344: 8, 380: 8, 387: 8, 388: 8, 399: 7, 408: 6, 415: 6, 419: 8, 420: 8, 427: 3, 428: 8, 432: 7, 441: 5, 450: 8, 464: 8, 477: 8, 479: 8, 490: 8, 495: 8, 525: 8, 531: 8, 545: 6, 662: 4, 773: 7, 777: 8, 780: 8, 804: 8, 806: 8, 808: 8, 814: 4, 829: 5, 833: 6, 862: 8, 884: 8, 891: 8, 927: 8, 929: 8, 930: 8, 931: 8, 1302: 8, 1361: 5, 1365: 5, 1600: 5, 1601: 8, 1626: 5, 1627: 5 diff --git a/selfdrive/car/hyundai/carcontroller.py b/selfdrive/car/hyundai/carcontroller.py index 729c853628a792..daf3ca31421f4a 100644 --- a/selfdrive/car/hyundai/carcontroller.py +++ b/selfdrive/car/hyundai/carcontroller.py @@ -2,19 +2,10 @@ from selfdrive.car.hyundai.hyundaican import create_lkas11, create_lkas12, \ create_1191, create_1156, \ create_clu11 -from selfdrive.car.hyundai.values import Buttons +from selfdrive.car.hyundai.values import Buttons, SteerLimitParams from selfdrive.can.packer import CANPacker -# Steer torque limits - -class SteerLimitParams: - STEER_MAX = 255 # 409 is the max, 255 is stock - STEER_DELTA_UP = 3 - STEER_DELTA_DOWN = 7 - STEER_DRIVER_ALLOWANCE = 50 - STEER_DRIVER_MULTIPLIER = 2 - STEER_DRIVER_FACTOR = 1 class CarController(): def __init__(self, dbc_name, car_fingerprint): diff --git a/selfdrive/car/hyundai/values.py b/selfdrive/car/hyundai/values.py index e801260a9538c8..f2a800a9dae55f 100644 --- a/selfdrive/car/hyundai/values.py +++ b/selfdrive/car/hyundai/values.py @@ -9,6 +9,16 @@ def get_hud_alerts(visual_alert): else: return 0 +# Steer torque limits + +class SteerLimitParams: + STEER_MAX = 255 # 409 is the max, 255 is stock + STEER_DELTA_UP = 3 + STEER_DELTA_DOWN = 7 + STEER_DRIVER_ALLOWANCE = 50 + STEER_DRIVER_MULTIPLIER = 2 + STEER_DRIVER_FACTOR = 1 + class CAR: ELANTRA = "HYUNDAI ELANTRA LIMITED ULTIMATE 2017" GENESIS = "HYUNDAI GENESIS 2018" diff --git a/selfdrive/car/interfaces.py b/selfdrive/car/interfaces.py index 0d619cb9504b11..0c7c2c81dc9d77 100644 --- a/selfdrive/car/interfaces.py +++ b/selfdrive/car/interfaces.py @@ -13,6 +13,10 @@ def __init__(self, CP, CarController): def calc_accel_override(a_ego, a_target, v_ego, v_target): return 1. + @staticmethod + def compute_gb(accel, speed): + raise NotImplementedError + @staticmethod def get_params(candidate, fingerprint=gen_empty_fingerprint(), vin="", has_relay=False): raise NotImplementedError diff --git a/selfdrive/car/lock_safety_model.py b/selfdrive/car/lock_safety_model.py deleted file mode 100755 index 055d8c0c2b499d..00000000000000 --- a/selfdrive/car/lock_safety_model.py +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env python3 -import sys -from cereal import car -from common.params import Params - -# This script locks the safety model to a given value. -# When the safety model is locked, boardd will preset panda to the locked safety model - -# run example: -# ./lock_safety_model.py gm - -if __name__ == "__main__": - - params = Params() - - if len(sys.argv) < 2: - params.delete("SafetyModelLock") - print("Clear locked safety model") - - else: - safety_model = getattr(car.CarParams.SafetyModel, sys.argv[1]) - if type(safety_model) != int: - raise Exception("Invalid safety model: " + sys.argv[1]) - if safety_model == car.CarParams.SafetyModel.allOutput: - raise Exception("Locking the safety model to allOutput is not allowed") - params.put("SafetyModelLock", str(safety_model)) - print("Locked safety model: " + sys.argv[1]) diff --git a/selfdrive/car/mock/interface.py b/selfdrive/car/mock/interface.py index 3b768d2838d137..a46b93aa61cda8 100755 --- a/selfdrive/car/mock/interface.py +++ b/selfdrive/car/mock/interface.py @@ -1,7 +1,6 @@ #!/usr/bin/env python3 from cereal import car from selfdrive.config import Conversions as CV -from selfdrive.services import service_list from selfdrive.swaglog import cloudlog import selfdrive.messaging as messaging from selfdrive.car import gen_empty_fingerprint @@ -16,15 +15,14 @@ class CarInterface(CarInterfaceBase): def __init__(self, CP, CarController): - self.CP = CP self.CC = CarController cloudlog.debug("Using Mock Car Interface") # TODO: subscribe to phone sensor - self.sensor = messaging.sub_sock(service_list['sensorEvents'].port) - self.gps = messaging.sub_sock(service_list['gpsLocation'].port) + self.sensor = messaging.sub_sock('sensorEvents') + self.gps = messaging.sub_sock('gpsLocation') self.speed = 0. self.prev_speed = 0. diff --git a/selfdrive/car/subaru/carcontroller.py b/selfdrive/car/subaru/carcontroller.py index 6005976faefb02..e7b9b7d94de20a 100644 --- a/selfdrive/car/subaru/carcontroller.py +++ b/selfdrive/car/subaru/carcontroller.py @@ -1,7 +1,7 @@ #from common.numpy_fast import clip from selfdrive.car import apply_std_steer_torque_limits from selfdrive.car.subaru import subarucan -from selfdrive.car.subaru.values import CAR, DBC +from selfdrive.car.subaru.values import DBC from selfdrive.can.packer import CANPacker @@ -11,10 +11,9 @@ def __init__(self, car_fingerprint): self.STEER_STEP = 2 # how often we update the steer cmd self.STEER_DELTA_UP = 50 # torque increase per refresh, 0.8s to max self.STEER_DELTA_DOWN = 70 # torque decrease per refresh - if car_fingerprint == CAR.IMPREZA: - self.STEER_DRIVER_ALLOWANCE = 60 # allowed driver torque before start limiting - self.STEER_DRIVER_MULTIPLIER = 10 # weight driver torque heavily - self.STEER_DRIVER_FACTOR = 1 # from dbc + self.STEER_DRIVER_ALLOWANCE = 60 # allowed driver torque before start limiting + self.STEER_DRIVER_MULTIPLIER = 10 # weight driver torque heavily + self.STEER_DRIVER_FACTOR = 1 # from dbc @@ -30,7 +29,6 @@ def __init__(self, car_fingerprint): # Setup detection helper. Routes commands to # an appropriate CAN bus number. self.params = CarControllerParams(car_fingerprint) - print(DBC) self.packer = CANPacker(DBC[car_fingerprint]['pt']) def update(self, enabled, CS, frame, actuators, pcm_cancel_cmd, visual_alert, left_line, right_line): diff --git a/selfdrive/car/subaru/carstate.py b/selfdrive/car/subaru/carstate.py index cc24f63d2acde5..f0256de3d0675b 100644 --- a/selfdrive/car/subaru/carstate.py +++ b/selfdrive/car/subaru/carstate.py @@ -123,7 +123,7 @@ def update(self, cp, cp_cam): self.v_cruise_pcm *= CV.MPH_TO_KPH v_wheel = (self.v_wheel_fl + self.v_wheel_fr + self.v_wheel_rl + self.v_wheel_rr) / 4. - # Kalman filter, even though Hyundai raw wheel speed is heaviliy filtered by default + # Kalman filter, even though Subaru raw wheel speed is heaviliy filtered by default if abs(v_wheel - self.v_ego) > 2.0: # Prevent large accelerations when car starts at non zero speed self.v_ego_kf.x = [[v_wheel], [0.0]] diff --git a/selfdrive/car/subaru/interface.py b/selfdrive/car/subaru/interface.py index 0fa12cf7d9bb89..e2195b00a19ca1 100644 --- a/selfdrive/car/subaru/interface.py +++ b/selfdrive/car/subaru/interface.py @@ -3,9 +3,9 @@ from selfdrive.config import Conversions as CV from selfdrive.controls.lib.drive_helpers import create_event, EventTypes as ET from selfdrive.controls.lib.vehicle_model import VehicleModel -from selfdrive.car.subaru.values import CAR, FINGERPRINTS, ECU_FINGERPRINT, ECU +from selfdrive.car.subaru.values import CAR from selfdrive.car.subaru.carstate import CarState, get_powertrain_can_parser, get_camera_can_parser -from selfdrive.car import STD_CARGO_KG, scale_rot_inertia, scale_tire_stiffness, gen_empty_fingerprint, is_ecu_disconnected +from selfdrive.car import STD_CARGO_KG, scale_rot_inertia, scale_tire_stiffness, gen_empty_fingerprint from selfdrive.car.interfaces import CarInterfaceBase ButtonType = car.CarState.ButtonEvent.Type @@ -48,7 +48,9 @@ def get_params(candidate, fingerprint=gen_empty_fingerprint(), vin="", has_relay ret.enableCruise = True ret.steerLimitAlert = True - ret.enableCamera = is_ecu_disconnected(fingerprint[0], FINGERPRINTS, ECU_FINGERPRINT, candidate, ECU.CAM) or has_relay + # force openpilot to fake the stock camera, since car harness is not supported yet and old style giraffe (with switches) + # was never released + ret.enableCamera = True ret.steerRateCost = 0.7 diff --git a/selfdrive/car/subaru/values.py b/selfdrive/car/subaru/values.py index 9abbaef3c80daf..7292a135c06c1c 100644 --- a/selfdrive/car/subaru/values.py +++ b/selfdrive/car/subaru/values.py @@ -7,7 +7,7 @@ class CAR: CAR.IMPREZA: [{ 2: 8, 64: 8, 65: 8, 72: 8, 73: 8, 280: 8, 281: 8, 290: 8, 312: 8, 313: 8, 314: 8, 315: 8, 316: 8, 326: 8, 544: 8, 545: 8, 546: 8, 552: 8, 554: 8, 557: 8, 576: 8, 577: 8, 722: 8, 801: 8, 802: 8, 805: 8, 808: 8, 816: 8, 826: 8, 837: 8, 838: 8, 839: 8, 842: 8, 912: 8, 915: 8, 940: 8, 1614: 8, 1617: 8, 1632: 8, 1650: 8, 1657: 8, 1658: 8, 1677: 8, 1697: 8, 1722: 8, 1743: 8, 1759: 8, 1786: 5, 1787: 5, 1788: 8, 1809: 8, 1813: 8, 1817: 8, 1821: 8, 1840: 8, 1848: 8, 1924: 8, 1932: 8, 1952: 8, 1960: 8 }, - # Crosstrek 2018 (same platform as Subaru) + # Crosstrek 2018 (same platform as Impreza) { 2: 8, 64: 8, 65: 8, 72: 8, 73: 8, 256: 8, 280: 8, 281: 8, 290: 8, 312: 8, 313: 8, 314: 8, 315: 8, 316: 8, 326: 8, 372: 8, 544: 8, 545: 8, 546: 8, 554: 8, 557: 8, 576: 8, 577: 8, 722: 8, 801: 8, 802: 8, 805: 8, 808: 8, 811: 8, 826: 8, 837: 8, 838: 8, 839: 8, 842: 8, 912: 8, 915: 8, 940: 8, 1614: 8, 1617: 8, 1632: 8, 1650: 8, 1657: 8, 1658: 8, 1677: 8, 1697: 8, 1759: 8, 1786: 5, 1787: 5, 1788: 8 }], diff --git a/selfdrive/car/toyota/carcontroller.py b/selfdrive/car/toyota/carcontroller.py index 95f3f6f38bc1cc..665a8c6cff9bde 100644 --- a/selfdrive/car/toyota/carcontroller.py +++ b/selfdrive/car/toyota/carcontroller.py @@ -2,27 +2,22 @@ from common.numpy_fast import clip, interp from selfdrive.car import apply_toyota_steer_torque_limits from selfdrive.car import create_gas_command -from selfdrive.car.toyota.toyotacan import make_can_msg, create_video_target,\ +from selfdrive.car.toyota.toyotacan import make_can_msg, \ create_steer_command, create_ui_command, \ create_ipas_steer_command, create_accel_command, \ create_acc_cancel_command, create_fcw_command -from selfdrive.car.toyota.values import CAR, ECU, STATIC_MSGS, TSS2_CAR +from selfdrive.car.toyota.values import CAR, ECU, STATIC_MSGS, TSS2_CAR, SteerLimitParams from selfdrive.can.packer import CANPacker +from selfdrive.phantom import Phantom VisualAlert = car.CarControl.HUDControl.VisualAlert # Accel limits ACCEL_HYST_GAP = 0.02 # don't change accel command for small oscilalitons within this value -ACCEL_MAX = 2.7 # 2.7 m/s2 -ACCEL_MIN = -2.7 # -2.7 m/s2 +ACCEL_MAX = 3.5 # 2.7 m/s2 +ACCEL_MIN = -4.0 # -2.7 m/s2 ACCEL_SCALE = max(ACCEL_MAX, -ACCEL_MIN) -# Steer torque limits -class SteerLimitParams: - STEER_MAX = 1500 - STEER_DELTA_UP = 10 # 1.5s time to peak torque - STEER_DELTA_DOWN = 44 # always lower than 45 otherwise the Rav4 faults (Prius seems ok with 50) - STEER_ERROR_MAX = 250 # max delta between torque cmd and torque motor # Steer angle limits (tested at the Crows Landing track and considered ok) ANGLE_MAX_BP = [0., 5.] @@ -102,6 +97,7 @@ def __init__(self, dbc_name, car_fingerprint, enable_camera, enable_dsu, enable_ self.last_standstill = False self.standstill_req = False self.angle_control = False + self.phantom = Phantom() self.steer_angle_enabled = False self.ipas_reset_counter = 0 @@ -114,9 +110,8 @@ def __init__(self, dbc_name, car_fingerprint, enable_camera, enable_dsu, enable_ self.packer = CANPacker(dbc_name) - def update(self, enabled, CS, frame, actuators, - pcm_cancel_cmd, hud_alert, forwarding_camera, left_line, - right_line, lead, left_lane_depart, right_lane_depart): + def update(self, enabled, CS, frame, actuators, pcm_cancel_cmd, hud_alert, + left_line, right_line, lead, left_lane_depart, right_lane_depart): # *** compute control surfaces *** @@ -147,7 +142,11 @@ def update(self, enabled, CS, frame, actuators, apply_accel = min(apply_accel, 0.0) # steer torque - apply_steer = int(round(actuators.steer * SteerLimitParams.STEER_MAX)) + self.phantom.update() + if self.phantom.data['status']: + apply_steer = int(round(self.phantom.data["angle"])) if abs(CS.angle_steers) <= 400 else 0 + else: + apply_steer = int(round(actuators.steer * SteerLimitParams.STEER_MAX)) if abs(CS.angle_steers) <= 100 else 0 # only cut torque when steer state is a known fault if CS.steer_state in [9, 25] and self.last_steer > 0: @@ -256,10 +255,6 @@ def update(self, enabled, CS, frame, actuators, # This prevents unexpected pedal range rescaling can_sends.append(create_gas_command(self.packer, apply_gas, frame//2)) - if frame % 10 == 0 and ECU.CAM in self.fake_ecus and not forwarding_camera: - for addr in TARGET_IDS: - can_sends.append(create_video_target(frame//10, addr)) - # ui mesg is at 100Hz but we send asap if: # - there is something to display # - there is something to stop displaying @@ -286,19 +281,7 @@ def update(self, enabled, CS, frame, actuators, #*** static msgs *** for (addr, ecu, cars, bus, fr_step, vl) in STATIC_MSGS: - if frame % fr_step == 0 and ecu in self.fake_ecus and self.car_fingerprint in cars and not (ecu == ECU.CAM and forwarding_camera): - # special cases - if fr_step == 5 and ecu == ECU.CAM and bus == 1: - cnt = (((frame // 5) % 7) + 1) << 5 - vl = bytes([cnt]) + vl - elif addr in (0x489, 0x48a) and bus == 0: - # add counter for those 2 messages (last 4 bits) - cnt = ((frame // 100) % 0xf) + 1 - if addr == 0x48a: - # 0x48a has a 8 preceding the counter - cnt += 1 << 7 - vl += bytes([cnt]) - + if frame % fr_step == 0 and ecu in self.fake_ecus and self.car_fingerprint in cars: can_sends.append(make_can_msg(addr, vl, bus, False)) return can_sends diff --git a/selfdrive/car/toyota/interface.py b/selfdrive/car/toyota/interface.py index 37538f4d381aeb..51f86bae4e58ce 100644 --- a/selfdrive/car/toyota/interface.py +++ b/selfdrive/car/toyota/interface.py @@ -8,6 +8,7 @@ from selfdrive.car import STD_CARGO_KG, scale_rot_inertia, scale_tire_stiffness, is_ecu_disconnected, gen_empty_fingerprint from selfdrive.swaglog import cloudlog from selfdrive.car.interfaces import CarInterfaceBase +from common.op_params import opParams ButtonType = car.CarState.ButtonEvent.Type GearShifter = car.CarState.GearShifter @@ -28,11 +29,11 @@ def __init__(self, CP, CarController): self.cp = get_can_parser(CP) self.cp_cam = get_cam_can_parser(CP) - self.forwarding_camera = False - self.CC = None if CarController is not None: self.CC = CarController(self.cp.dbc_name, CP.carFingerprint, CP.enableCamera, CP.enableDsu, CP.enableApgs) + self.op_params = opParams() + self.keep_openpilot_engaged = self.op_params.get('keep_openpilot_engaged', True) @staticmethod def compute_gb(accel, speed): @@ -176,7 +177,7 @@ def get_params(candidate, fingerprint=gen_empty_fingerprint(), vin="", has_relay ret.mass = 3585. * CV.LB_TO_KG + STD_CARGO_KG ret.lateralTuning.pid.kf = 0.00007818594 - elif candidate == CAR.COROLLA_TSS2: + elif candidate in [CAR.COROLLA_TSS2, CAR.COROLLAH_TSS2]: stop_and_go = True ret.safetyParam = 73 ret.wheelbase = 2.63906 @@ -186,7 +187,7 @@ def get_params(candidate, fingerprint=gen_empty_fingerprint(), vin="", has_relay ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.6], [0.1]] ret.lateralTuning.pid.kf = 0.00007818594 - elif candidate == CAR.LEXUS_ESH_TSS2: + elif candidate in [CAR.LEXUS_ES_TSS2, CAR.LEXUS_ESH_TSS2]: stop_and_go = True ret.safetyParam = 73 ret.wheelbase = 2.8702 @@ -339,7 +340,7 @@ def update(self, c, can_strings): ret.cruiseState.enabled = bool(self.CS.main_on) if not self.CS.pcm_acc_active: ret.brakePressed = True - if self.CS.v_ego < 1: + if self.CS.v_ego < 1 or not self.keep_openpilot_engaged: ret.cruiseState.enabled = self.CS.pcm_acc_active ret.cruiseState.speed = self.CS.v_cruise_pcm * CV.KPH_TO_MS ret.cruiseState.available = bool(self.CS.main_on) @@ -377,22 +378,21 @@ def update(self, c, can_strings): # events events = [] - if self.cp_cam.can_valid: - self.forwarding_camera = True + # todo: arne, do we need this section below? it's not present in 066 - if ret.cruiseState.enabled and not self.cruise_enabled_prev: + if ret.cruiseState.enabled and not self.cruise_enabled_prev: # this lets us modularize which checks we want to turn off op if cc was engaged previoiusly or not disengage_event = True else: disengage_event = False if self.cp_cam.can_invalid_cnt >= 100 and self.CP.enableCamera: - events.append(create_event('invalidGiraffeToyota', [ET.PERMANENT])) + events.append(create_event('invalidGiraffeToyota', [ET.PERMANENT, ET.NO_ENTRY])) if not ret.gearShifter == GearShifter.drive and self.CP.enableDsu: events.append(create_event('wrongGear', [ET.NO_ENTRY, ET.SOFT_DISABLE])) if ret.doorOpen and disengage_event: events.append(create_event('doorOpen', [ET.NO_ENTRY, ET.SOFT_DISABLE])) - if ret.seatbeltUnlatched and disengage_event: + if ret.seatbeltUnlatched and disengage_event: # place `and disengage_event` whereever you want to not disengage openpilot if this occurs. safety issue events.append(create_event('seatbeltNotLatched', [ET.NO_ENTRY, ET.SOFT_DISABLE])) if self.CS.esp_disabled and self.CP.enableDsu: events.append(create_event('espDisabled', [ET.NO_ENTRY, ET.SOFT_DISABLE])) @@ -440,8 +440,8 @@ def update(self, c, can_strings): def apply(self, c): can_sends = self.CC.update(c.enabled, self.CS, self.frame, - c.actuators, c.cruiseControl.cancel, c.hudControl.visualAlert, - self.forwarding_camera, c.hudControl.leftLaneVisible, + c.actuators, c.cruiseControl.cancel, + c.hudControl.visualAlert, c.hudControl.leftLaneVisible, c.hudControl.rightLaneVisible, c.hudControl.leadVisible, c.hudControl.leftLaneDepart, c.hudControl.rightLaneDepart) diff --git a/selfdrive/car/toyota/toyotacan.py b/selfdrive/car/toyota/toyotacan.py index 7125ecbf3e634f..92d1c2ea26d0a8 100644 --- a/selfdrive/car/toyota/toyotacan.py +++ b/selfdrive/car/toyota/toyotacan.py @@ -22,12 +22,6 @@ def make_can_msg(addr, dat, alt, cks=False): return [addr, 0, dat, alt] -def create_video_target(frame, addr): - counter = frame & 0xff - msg = struct.pack("!BBBBBBB", counter, 0x03, 0xff, 0x00, 0x00, 0x00, 0x00) - return make_can_msg(addr, msg, 1, True) - - def create_ipas_steer_command(packer, steer, enabled, apgs_enabled): """Creates a CAN message for the Toyota Steer Command.""" if steer < 0: diff --git a/selfdrive/car/toyota/values.py b/selfdrive/car/toyota/values.py index b32748b96d2004..0b8445bb81497e 100644 --- a/selfdrive/car/toyota/values.py +++ b/selfdrive/car/toyota/values.py @@ -1,5 +1,12 @@ from selfdrive.car import dbc_dict +# Steer torque limits +class SteerLimitParams: + STEER_MAX = 1500 + STEER_DELTA_UP = 10 # 1.5s time to peak torque + STEER_DELTA_DOWN = 44 # always lower than 45 otherwise the Rav4 faults (Prius seems ok with 50) todo: stock 25, got 44 from arne's carcontroller.py + STEER_ERROR_MAX = 350 # max delta between torque cmd and torque motor + class CAR: PRIUS = "TOYOTA PRIUS 2017" RAV4H = "TOYOTA RAV4 HYBRID 2017" @@ -15,6 +22,8 @@ class CAR: AVALON = "TOYOTA AVALON 2016" RAV4_TSS2 = "TOYOTA RAV4 2019" COROLLA_TSS2 = "TOYOTA COROLLA TSS2 2019" + COROLLAH_TSS2 = "TOYOTA COROLLA HYBRID TSS2 2019" + LEXUS_ES_TSS2 = "LEXUS ES 2019" LEXUS_ESH_TSS2 = "LEXUS ES 300H 2019" SIENNA = "TOYOTA SIENNA XLE 2018" LEXUS_IS = "LEXUS IS300 2018" @@ -30,21 +39,6 @@ class ECU: # addr: (ecu, cars, bus, 1/freq*100, vl) STATIC_MSGS = [ - (0x130, ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA, CAR.HIGHLANDER, CAR.HIGHLANDERH, CAR.AVALON), 1, 100, b'\x00\x00\x00\x00\x00\x00\x38'), - (0x240, ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA, CAR.HIGHLANDER, CAR.HIGHLANDERH, CAR.AVALON), 1, 5, b'\x00\x10\x01\x00\x10\x01\x00'), - (0x241, ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA, CAR.HIGHLANDER, CAR.HIGHLANDERH, CAR.AVALON), 1, 5, b'\x00\x10\x01\x00\x10\x01\x00'), - (0x244, ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA, CAR.HIGHLANDER, CAR.HIGHLANDERH, CAR.AVALON), 1, 5, b'\x00\x10\x01\x00\x10\x01\x00'), - (0x245, ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA, CAR.HIGHLANDER, CAR.HIGHLANDERH, CAR.AVALON), 1, 5, b'\x00\x10\x01\x00\x10\x01\x00'), - (0x248, ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA, CAR.HIGHLANDER, CAR.HIGHLANDERH, CAR.AVALON), 1, 5, b'\x00\x00\x00\x00\x00\x00\x01'), - (0x367, ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA, CAR.HIGHLANDER, CAR.HIGHLANDERH, CAR.AVALON), 0, 40, b'\x06\x00'), - (0x414, ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA, CAR.HIGHLANDER, CAR.HIGHLANDERH, CAR.AVALON), 0, 100, b'\x00\x00\x00\x00\x00\x00\x17\x00'), - (0x466, ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.HIGHLANDER, CAR.HIGHLANDERH), 1, 100, b'\x20\x20\xAD'), - (0x466, ECU.CAM, (CAR.COROLLA, CAR.AVALON), 1, 100, b'\x24\x20\xB1'), - (0x489, ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA, CAR.HIGHLANDER, CAR.HIGHLANDERH, CAR.AVALON), 0, 100, b'\x00\x00\x00\x00\x00\x00\x00'), - (0x48a, ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA, CAR.HIGHLANDER, CAR.HIGHLANDERH, CAR.AVALON), 0, 100, b'\x00\x00\x00\x00\x00\x00\x00'), - (0x48b, ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA, CAR.HIGHLANDER, CAR.HIGHLANDERH, CAR.AVALON), 0, 100, b'\x66\x06\x08\x0a\x02\x00\x00\x00'), - (0x4d3, ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA, CAR.AVALON), 0, 100, b'\x1C\x00\x00\x01\x00\x00\x00\x00'), - (0x128, ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA, CAR.AVALON), 1, 3, b'\xf4\x01\x90\x83\x00\x37'), (0x128, ECU.DSU, (CAR.HIGHLANDER, CAR.HIGHLANDERH, CAR.SIENNA, CAR.LEXUS_CTH), 1, 3, b'\x03\x00\x20\x00\x00\x52'), (0x141, ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA, CAR.HIGHLANDER, CAR.HIGHLANDERH, CAR.AVALON, CAR.SIENNA, CAR.LEXUS_CTH), 1, 2, b'\x00\x00\x00\x46'), @@ -120,9 +114,6 @@ class ECU: CAR.AVALON: [{ 36: 8, 37: 8, 170: 8, 180: 8, 426: 6, 452: 8, 464: 8, 466: 8, 467: 8, 547: 8, 550: 8, 552: 4, 562: 6, 608: 8, 610: 5, 643: 7, 705: 8, 740: 5, 800: 8, 835: 8, 836: 8, 849: 4, 869: 7, 870: 7, 871: 2, 896: 8, 897: 8, 905: 8, 911: 1, 916: 2, 921: 8, 933: 6, 944: 8, 945: 8, 951: 8, 955: 8, 956: 8, 979: 2, 1005: 2, 1014: 8, 1017: 8, 1041: 8, 1042: 8, 1044: 8, 1056: 8, 1059: 1, 1114: 8, 1161: 8, 1162: 8, 1163: 8, 1176: 8, 1177: 8, 1178: 8, 1179: 8, 1180: 8, 1181: 8, 1190: 8, 1191: 8, 1192: 8, 1196: 8, 1200: 8, 1201: 8, 1202: 8, 1203: 8, 1206: 8, 1227: 8, 1235: 8, 1237: 8, 1264: 8, 1279: 8, 1552: 8, 1553: 8, 1554: 8, 1555: 8, 1556: 8, 1557: 8, 1558: 8, 1561: 8, 1562: 8, 1568: 8, 1569: 8, 1570: 8, 1571: 8, 1572: 8, 1584: 8, 1589: 8, 1592: 8, 1593: 8, 1595: 8, 1596: 8, 1597: 8, 1664: 8, 1728: 8, 1779: 8, 1904: 8, 1912: 8, 1990: 8, 1998: 8 }], - CAR.SIENNA: [{ - 36: 8, 37: 8, 114: 5, 119: 6, 120: 4, 170: 8, 180: 8, 186: 4, 238: 4, 426: 6, 452: 8, 464: 8, 466: 8, 467: 8, 544: 4, 545: 5, 548: 8, 550: 8, 552: 4, 562: 4, 608: 8, 610: 5, 643: 7, 705: 8, 725: 2, 740: 5, 764: 8, 800: 8, 824: 8, 835: 8, 836: 8, 849: 4, 869: 7, 870: 7, 871: 2, 888: 8, 896: 8, 900: 6, 902: 6, 905: 8, 911: 8, 916: 1, 918: 7, 921: 8, 933: 8, 944: 6, 945: 8, 951: 8, 955: 8, 956: 8, 979: 2, 992: 8, 998: 5, 999: 7, 1000: 8, 1001: 8, 1002: 8, 1008: 2, 1014: 8, 1017: 8, 1041: 8, 1042: 8, 1043: 8, 1056: 8, 1059: 1, 1076: 8, 1077: 8, 1114: 8, 1160: 8, 1161: 8, 1162: 8, 1163: 8, 1164: 8, 1165: 8, 1166: 8, 1167: 8, 1176: 8, 1177: 8, 1178: 8, 1179: 8, 1180: 8, 1181: 8, 1182: 8, 1183: 8, 1191: 8, 1192: 8, 1196: 8, 1197: 8, 1198: 8, 1199: 8, 1200: 8, 1201: 8, 1202: 8, 1203: 8, 1212: 8, 1227: 8, 1228: 8, 1235: 8, 1237: 8, 1279: 8, 1552: 8, 1553: 8, 1555: 8, 1556: 8, 1557: 8, 1561: 8, 1562: 8, 1568: 8, 1569: 8, 1570: 8, 1571: 8, 1572: 8, 1584: 8, 1589: 8, 1592: 8, 1593: 8, 1595: 8, 1656: 8, 1664: 8, 1666: 8, 1667: 8, 1728: 8, 1745: 8, 1779: 8, 1904: 8, 1912: 8, 1990: 8, 1998: 8, 2015: 8, 2016: 8, 2024: 8 - }], CAR.COROLLA_TSS2: [{ 36: 8, 37: 8, 114: 5, 170: 8, 180: 8, 186: 4, 401: 8, 426: 6, 452: 8 , 464: 8, 466: 8, 467: 8, 544: 4, 550: 8, 552: 4, 562: 6, 608: 8, 610: 8, 643: 7 , 705: 8, 728: 8, 740: 5, 742: 8, 743: 8, 761: 8, 764: 8, 765: 8, 800: 8, 810: 2, 812: 8, 824: 8, 829: 2, 830: 7, 835: 8, 836: 8, 865: 8, 869: 7, 870: 7, 871: 2, 877: 8, 881: 8, 896: 8, 898: 8, 900: 6, 902: 6, 905: 8, 921: 8, 933: 8, 934: 8, 935: 8, 944: 8, 945: 8, 951: 8, 955: 8, 956: 8, 976: 1, 998: 5, 999: 7, 1000:8, 1001: 8, 1002: 8, 1014: 8, 1017:8, 1020: 8, 1041: 8, 1042: 8, 1044: 8, 1056: 8, 1059:1, 1076: 8, 1077: 8, 1114: 8, 1161: 8, 1162: 8, 1163: 8, 1164: 8, 1165: 8, 1166: 8, 1167: 8, 1172: 8, 1235: 8, 1237: 8, 1279: 8, 1541: 8, 1552: 8, 1553: 8, 1556: 8, 1557: 8, 1568: 8, 1570: 8, 1571: 8, 1572: 8, 1592: 8, 1595: 8, 1649: 8, 1745: 8, 1775: 8, 1779: 8, 1786: 8, 1787: 8, 1788: 8, 1789: 8, 1904: 8, 1912: 8, 1990: 8, 1998: 8 }], @@ -132,10 +123,31 @@ class ECU: CAR.RAV4H_TSS2: [{ 36: 8, 37: 8, 166: 8, 170: 8, 180: 8, 295: 8, 296: 8, 401: 8, 426: 6, 452: 8, 466: 8, 467: 8, 550: 8, 552: 4, 560: 7, 562: 6, 581: 5, 608: 8, 610: 8, 643: 7, 658: 8, 713: 8, 728: 8, 740: 5, 742: 8, 743: 8, 761: 8, 764: 8, 765: 8, 800: 8, 810: 2, 812: 8, 814: 8, 818: 8, 822: 8, 824: 8, 829: 2, 830: 7, 835: 8, 836: 8, 863: 8, 865: 8, 869: 7, 870: 7, 871: 2, 877: 8, 881: 8, 882: 8, 885: 8, 889: 8, 891: 8, 896: 8, 898: 8, 900: 6, 902: 6, 905: 8, 913: 8, 918: 8, 921: 8, 933: 8, 934: 8, 935: 8, 944: 8, 945: 8, 950: 8, 951: 8, 953: 8, 955: 8, 956: 8, 971: 7, 975: 5, 987: 8, 993: 8, 998: 5, 999: 7, 1000: 8, 1001: 8, 1002: 8, 1014: 8, 1017: 8, 1020: 8, 1041: 8, 1042: 8, 1044: 8, 1056: 8, 1057: 8, 1059: 1, 1063: 8, 1071: 8, 1076: 8, 1077: 8, 1082: 8, 1084: 8, 1085: 8, 1086: 8, 1114: 8, 1132: 8, 1161: 8, 1162: 8, 1163: 8, 1164: 8, 1165: 8, 1166: 8, 1167: 8, 1172: 8, 1228: 8, 1235: 8, 1237: 8, 1263: 8, 1264: 8, 1279: 8, 1541: 8, 1552: 8, 1553: 8, 1556: 8, 1557: 8, 1568: 8, 1570: 8, 1571: 8, 1572: 8, 1592: 8, 1594: 8, 1595: 8, 1649: 8, 1696: 8, 1745: 8, 1775: 8, 1779: 8, 1786: 8, 1787: 8, 1788: 8, 1789: 8, 1904: 8, 1912: 8, 1990: 8, 1998: 8 }], + CAR.COROLLAH_TSS2: [ + # 2019 Taiwan Altis Hybrid + { + 36: 8, 37: 8, 166: 8, 170: 8, 180: 8, 295: 8, 296: 8, 401: 8, 426: 6, 452: 8, 466: 8, 467: 8, 550: 8, 552: 4, 560: 7, 562: 6, 581: 5, 608: 8, 610: 8, 643: 7, 713: 8, 728: 8, 740: 5, 742: 8, 743: 8, 761: 8, 765: 8, 800: 8, 810: 2, 829: 2, 830: 7, 835: 8, 836: 8, 865: 8, 869: 7, 870: 7, 871: 2, 877: 8, 881: 8, 885: 8, 896: 8, 898: 8, 918: 7, 921: 8, 944: 8, 945: 8, 950: 8, 951: 8, 953: 8, 955: 8, 956: 8, 971: 7, 975: 5, 987: 8, 993: 8, 1002: 8, 1014: 8, 1017: 8, 1020: 8, 1041: 8, 1042: 8, 1044: 8, 1056: 8, 1057: 8, 1059: 1, 1071: 8, 1082: 8, 1112: 8, 1114: 8, 1161: 8, 1162: 8, 1163: 8, 1172: 8, 1235: 8, 1237: 8, 1279: 8, 1541: 8, 1552: 8, 1553: 8, 1556: 8, 1557: 8, 1568: 8, 1570: 8, 1571: 8, 1572: 8, 1592: 8, 1594: 8, 1595: 8, 1745: 8, 1775: 8, 1779: 8 + }, + # 2019 Chinese Levin Hybrid + { + 36: 8, 37: 8, 166: 8, 170: 8, 180: 8, 295: 8, 296: 8, 401: 8, 426: 6, 452: 8, 466: 8, 467: 8, 550: 8, 552: 4, 560: 7, 562: 6, 581: 5, 608: 8, 610: 8, 643: 7, 713: 8, 728: 8, 740: 5, 742: 8, 743: 8, 761: 8, 765: 8, 800: 8, 810: 2, 812: 8, 829: 2, 830: 7, 835: 8, 836: 8, 865: 8, 869: 7, 870: 7, 871: 2, 877: 8, 881: 8, 885: 8, 896: 8, 898: 8, 921: 8, 944: 8, 945: 8, 950: 8, 951: 8, 953: 8, 955: 8, 956: 8, 971: 7, 975: 5, 993: 8, 1002: 8, 1017: 8, 1020: 8, 1041: 8, 1042: 8, 1044: 8, 1056: 8, 1057: 8, 1059: 1, 1071: 8, 1114: 8, 1161: 8, 1162: 8, 1163: 8, 1172: 8, 1235: 8, 1279: 8, 1541: 8, 1552: 8, 1553: 8, 1556: 8, 1557: 8, 1568: 8, 1570: 8, 1571: 8, 1572: 8, 1592: 8, 1594: 8, 1595: 8, 1600: 8, 1649: 8, 1745: 8, 1775: 8, 1779: 8 + } + ], + CAR.LEXUS_ES_TSS2: [{ + 36: 8, 37: 8, 114: 5, 119: 6, 120: 4, 170: 8, 180: 8, 186: 4, 401: 8, 426: 6, 452: 8, 464: 8, 466: 8, 467: 8, 544: 4, 550: 8, 552: 4, 562: 6, 608: 8, 610: 8, 643: 7, 658: 8, 705: 8, 728: 8, 740: 5, 761: 8, 764: 8, 765: 8, 800: 8, 810: 2, 812: 8, 814: 8, 818: 8, 824: 8, 830: 7, 835: 8, 836: 8, 865: 8, 869: 7, 870: 7, 871: 2, 877: 8, 881: 8, 882: 8, 885: 8, 889: 8, 896: 8, 898: 8, 900: 6, 902: 6, 905: 8, 913: 8, 918: 8, 921: 8, 933: 8, 934: 8, 935: 8, 944: 8, 945: 8, 951: 8, 955: 8, 956: 8, 976: 1, 987: 8, 998: 5, 999: 7, 1000: 8, 1001: 8, 1002: 8, 1014: 8, 1017: 8, 1020: 8, 1041: 8, 1042: 8, 1044: 8, 1056: 8, 1059: 1, 1076: 8, 1077: 8, 1082: 8, 1114: 8, 1161: 8, 1162: 8, 1163: 8, 1164: 8, 1165: 8, 1166: 8, 1167: 8, 1172: 8, 1228: 8, 1235: 8, 1237: 8, 1264: 8, 1279: 8, 1541: 8, 1552: 8, 1553: 8, 1556: 8, 1557: 8, 1568: 8, 1570: 8, 1571: 8, 1572: 8, 1575: 8, 1592: 8, 1594: 8, 1595: 8, 1649: 8, 1696: 8, 1775: 8, 1777: 8, 1779: 8, 1786: 8, 1787: 8, 1788: 8, 1789: 8, 1904: 8, 1912: 8 + }], CAR.LEXUS_ESH_TSS2: [ { 36: 8, 37: 8, 166: 8, 170: 8, 180: 8, 295: 8, 296: 8, 401: 8, 426: 6, 452: 8, 466: 8, 467: 8, 550: 8, 552: 4, 560: 7, 562: 6, 581: 5, 608: 8, 610: 8, 643: 7, 658: 8, 713: 8, 728: 8, 740: 5, 742: 8, 743: 8, 744: 8, 761: 8, 764: 8, 765: 8, 800: 8, 810: 2, 812: 8, 814: 8, 818: 8, 824: 8, 829: 2, 830: 7, 835: 8, 836: 8, 863: 8, 865: 8, 869: 7, 870: 7, 871: 2, 877: 8, 881: 8, 882: 8, 885: 8, 889: 8, 896: 8, 898: 8, 900: 6, 902: 6, 905: 8, 913: 8, 918: 8, 921: 8, 933: 8, 934: 8, 935: 8, 944: 8, 945: 8, 950: 8, 951: 8, 953: 8, 955: 8, 956: 8, 971: 7, 975: 5, 987: 8, 993: 8, 998: 5, 999: 7, 1000: 8, 1001: 8, 1002: 8, 1017: 8, 1020: 8, 1041: 8, 1042: 8, 1056: 8, 1057: 8, 1059: 1, 1071: 8, 1076: 8, 1077: 8, 1082: 8, 1084: 8, 1085: 8, 1086: 8, 1114: 8, 1132: 8, 1161: 8, 1162: 8, 1163: 8, 1164: 8, 1165: 8, 1166: 8, 1167: 8, 1172: 8, 1228: 8, 1235: 8, 1264: 8, 1279: 8, 1541: 8, 1552: 8, 1553: 8, 1556: 8, 1557: 8, 1568: 8, 1570: 8, 1571: 8, 1572: 8, 1575: 8, 1592: 8, 1594: 8, 1595: 8, 1649: 8, 1696: 8, 1775: 8, 1777: 8, 1779: 8, 1786: 8, 1787: 8, 1788: 8, 1789: 8, 1904: 8, 1912: 8, 1990: 8, 1998: 8 }], + CAR.SIENNA: [ + { + 36: 8, 37: 8, 114: 5, 119: 6, 120: 4, 170: 8, 180: 8, 186: 4, 426: 6, 452: 8, 464: 8, 466: 8, 467: 8, 544: 4, 545: 5, 548: 8, 550: 8, 552: 4, 562: 4, 608: 8, 610: 5, 643: 7, 705: 8, 725: 2, 740: 5, 764: 8, 800: 8, 824: 8, 835: 8, 836: 8, 849: 4, 869: 7, 870: 7, 871: 2, 888: 8, 896: 8, 900: 6, 902: 6, 905: 8, 911: 8, 916: 1, 918: 7, 921: 8, 933: 8, 944: 6, 945: 8, 951: 8, 955: 8, 956: 8, 979: 2, 992: 8, 998: 5, 999: 7, 1000: 8, 1001: 8, 1002: 8, 1008: 2, 1014: 8, 1017: 8, 1041: 8, 1042: 8, 1043: 8, 1056: 8, 1059: 1, 1076: 8, 1077: 8, 1114: 8, 1160: 8, 1161: 8, 1162: 8, 1163: 8, 1164: 8, 1165: 8, 1166: 8, 1167: 8, 1176: 8, 1177: 8, 1178: 8, 1179: 8, 1180: 8, 1181: 8, 1182: 8, 1183: 8, 1191: 8, 1192: 8, 1196: 8, 1197: 8, 1198: 8, 1199: 8, 1200: 8, 1201: 8, 1202: 8, 1203: 8, 1212: 8, 1227: 8, 1228: 8, 1235: 8, 1237: 8, 1279: 8, 1552: 8, 1553: 8, 1555: 8, 1556: 8, 1557: 8, 1561: 8, 1562: 8, 1568: 8, 1569: 8, 1570: 8, 1571: 8, 1572: 8, 1584: 8, 1589: 8, 1592: 8, 1593: 8, 1595: 8, 1656: 8, 1664: 8, 1666: 8, 1667: 8, 1728: 8, 1745: 8, 1779: 8, 1904: 8, 1912: 8, 1990: 8, 1998: 8 + }, + # XLE AWD 2018 + { + 36: 8, 37: 8, 114: 5, 119: 6, 120: 4, 170: 8, 180: 8, 186: 4, 238: 4, 426: 6, 452: 8, 464: 8, 466: 8, 467: 8, 544: 4, 545: 5, 548: 8, 550: 8, 552: 4, 562: 4, 608: 8, 610: 5, 643: 7, 705: 8, 725: 2, 740: 5, 764: 8, 800: 8, 824: 8, 835: 8, 836: 8, 849: 4, 869: 7, 870: 7, 871: 2, 896: 8, 900: 6, 902: 6, 905: 8, 911: 8, 916: 1, 921: 8, 933: 8, 944: 6, 945: 8, 951: 8, 955: 8, 956: 8, 979: 2, 992: 8, 998: 5, 999: 7, 1000: 8, 1001: 8, 1002: 8, 1008: 2, 1014: 8, 1017: 8, 1041: 8, 1042: 8, 1043: 8, 1056: 8, 1059: 1, 1076: 8, 1077: 8, 1114: 8, 1160: 8, 1161: 8, 1162: 8, 1163: 8, 1164: 8, 1165: 8, 1166: 8, 1167: 8, 1176: 8, 1177: 8, 1178: 8, 1179: 8, 1180: 8, 1181: 8, 1182: 8, 1183: 8, 1191: 8, 1192: 8, 1196: 8, 1197: 8, 1198: 8, 1199: 8, 1200: 8, 1201: 8, 1202: 8, 1203: 8, 1212: 8, 1227: 8, 1235: 8, 1237: 8, 1279: 8, 1552: 8, 1553: 8, 1555: 8, 1556: 8, 1557: 8, 1561: 8, 1562: 8, 1568: 8, 1569: 8, 1570: 8, 1571: 8, 1572: 8, 1584: 8, 1589: 8, 1592: 8, 1593: 8, 1595: 8, 1656: 8, 1664: 8, 1666: 8, 1667: 8, 1728: 8, 1745: 8, 1779: 8, 1904: 8, 1912: 8, 1990: 8, 1998: 8 + }], CAR.LEXUS_IS: [ # IS300 2018 { @@ -170,6 +182,8 @@ class ECU: CAR.AVALON: dbc_dict('toyota_avalon_2017_pt_generated', 'toyota_adas'), CAR.RAV4_TSS2: dbc_dict('toyota_nodsu_pt_generated', 'toyota_tss2_adas'), CAR.COROLLA_TSS2: dbc_dict('toyota_nodsu_pt_generated', 'toyota_tss2_adas'), + CAR.COROLLAH_TSS2: dbc_dict('toyota_nodsu_hybrid_pt_generated', 'toyota_tss2_adas'), + CAR.LEXUS_ES_TSS2: dbc_dict('toyota_nodsu_pt_generated', 'toyota_tss2_adas'), CAR.LEXUS_ESH_TSS2: dbc_dict('toyota_nodsu_hybrid_pt_generated', 'toyota_tss2_adas'), CAR.SIENNA: dbc_dict('toyota_sienna_xle_2018_pt_generated', 'toyota_adas'), CAR.LEXUS_IS: dbc_dict('lexus_is_2018_pt_generated', 'toyota_adas'), @@ -177,6 +191,12 @@ class ECU: CAR.LEXUS_CTH: dbc_dict('lexus_ct200h_2018_pt_generated', 'toyota_adas'), } +''' NO_DSU_CAR = [CAR.CHR, CAR.CHRH, CAR.CAMRY, CAR.CAMRYH, CAR.RAV4_TSS2, CAR.COROLLA_TSS2, CAR.LEXUS_ESH_TSS2, CAR.RAV4H_TSS2] TSS2_CAR = [CAR.RAV4_TSS2, CAR.COROLLA_TSS2, CAR.LEXUS_ESH_TSS2, CAR.RAV4H_TSS2] NO_STOP_TIMER_CAR = [CAR.RAV4H, CAR.HIGHLANDERH, CAR.HIGHLANDER, CAR.RAV4_TSS2, CAR.COROLLA_TSS2, CAR.LEXUS_ESH_TSS2, CAR.SIENNA, CAR.RAV4H_TSS2] # no resume button press required +''' +# todo: I'm using stock 066 below, above this is from 065-clean. Arne, check this out and delete the above if it looks good +NO_DSU_CAR = [CAR.CHR, CAR.CHRH, CAR.CAMRY, CAR.CAMRYH, CAR.RAV4_TSS2, CAR.COROLLA_TSS2, CAR.COROLLAH_TSS2, CAR.LEXUS_ES_TSS2, CAR.LEXUS_ESH_TSS2] +TSS2_CAR = [CAR.RAV4_TSS2, CAR.COROLLA_TSS2, CAR.COROLLAH_TSS2, CAR.LEXUS_ES_TSS2, CAR.LEXUS_ESH_TSS2] +NO_STOP_TIMER_CAR = [CAR.RAV4H, CAR.HIGHLANDERH, CAR.HIGHLANDER, CAR.RAV4_TSS2, CAR.COROLLA_TSS2, CAR.COROLLAH_TSS2, CAR.LEXUS_ES_TSS2, CAR.LEXUS_ESH_TSS2, CAR.SIENNA] # no resume button press required diff --git a/selfdrive/car/vin.py b/selfdrive/car/vin.py index 76fd34ca6d80e8..eac0316db4d33e 100755 --- a/selfdrive/car/vin.py +++ b/selfdrive/car/vin.py @@ -80,7 +80,7 @@ def get_vin(logcan, sendcan, bus, query_time=1.): # 1s max of VIN query time while frame < query_time * 100: - a = messaging.recv_one(logcan) + a = messaging.get_one_can(logcan) for can in a.can: vin_query.check_response(can) @@ -92,7 +92,6 @@ def get_vin(logcan, sendcan, bus, query_time=1.): if __name__ == "__main__": - from selfdrive.services import service_list - logcan = messaging.sub_sock(service_list['can'].port) - sendcan = messaging.pub_sock(service_list['sendcan'].port) + logcan = messaging.sub_sock('can') + sendcan = messaging.pub_sock('sendcan') print(get_vin(logcan, sendcan, 0)) diff --git a/selfdrive/car/volkswagen/__init__.py b/selfdrive/car/volkswagen/__init__.py new file mode 100644 index 00000000000000..8b137891791fe9 --- /dev/null +++ b/selfdrive/car/volkswagen/__init__.py @@ -0,0 +1 @@ + diff --git a/selfdrive/car/volkswagen/carcontroller.py b/selfdrive/car/volkswagen/carcontroller.py new file mode 100644 index 00000000000000..4ec662dce4c6bf --- /dev/null +++ b/selfdrive/car/volkswagen/carcontroller.py @@ -0,0 +1,188 @@ +from cereal import car +from selfdrive.car import apply_std_steer_torque_limits +from selfdrive.car.volkswagen import volkswagencan +from selfdrive.car.volkswagen.values import DBC, MQB_LDW_MESSAGES, BUTTON_STATES, CarControllerParams +from selfdrive.can.packer import CANPacker + +VisualAlert = car.CarControl.HUDControl.VisualAlert + + +class CarController(): + def __init__(self, canbus, car_fingerprint): + self.apply_steer_last = 0 + self.car_fingerprint = car_fingerprint + + # Setup detection helper. Routes commands to an appropriate CAN bus number. + self.canbus = canbus + self.packer_gw = CANPacker(DBC[car_fingerprint]['pt']) + + self.hcaSameTorqueCount = 0 + self.hcaEnabledFrameCount = 0 + self.graButtonStatesToSend = None + self.graMsgSentCount = 0 + self.graMsgStartFramePrev = 0 + self.graMsgBusCounterPrev = 0 + + def update(self, enabled, CS, frame, actuators, visual_alert, audible_alert, leftLaneVisible, rightLaneVisible): + """ Controls thread """ + + P = CarControllerParams + + # Send CAN commands. + can_sends = [] + canbus = self.canbus + + #-------------------------------------------------------------------------- + # # + # Prepare HCA_01 Heading Control Assist messages with steering torque. # + # # + #-------------------------------------------------------------------------- + + # The factory camera sends at 50Hz while steering and 1Hz when not. When + # OP is active, Panda filters HCA_01 from the factory camera and OP emits + # HCA_01 at 50Hz. Rate switching creates some confusion in Cabana and + # doesn't seem to add value at this time. The rack will accept HCA_01 at + # 100Hz if we want to control at finer resolution in the future. + if frame % P.HCA_STEP == 0: + + # FAULT AVOIDANCE: HCA must not be enabled at standstill. Also stop + # commanding HCA if there's a fault, so the steering rack recovers. + if enabled and not (CS.standstill or CS.steeringFault): + + # FAULT AVOIDANCE: Requested HCA torque must not exceed 3.0 Nm. This + # is inherently handled by scaling to STEER_MAX. The rack doesn't seem + # to care about up/down rate, but we have some evidence it may do its + # own rate limiting, and matching OP helps for accurate tuning. + apply_steer = int(round(actuators.steer * P.STEER_MAX)) + apply_steer = apply_std_steer_torque_limits(apply_steer, self.apply_steer_last, CS.steeringTorque, P) + + # FAULT AVOIDANCE: HCA must not be enabled for >360 seconds. Sending + # a single frame with HCA disabled is an effective workaround. + if apply_steer == 0: + # We can usually reset the timer for free, just by disabling HCA + # when apply_steer is exactly zero, which happens by chance during + # many steer torque direction changes. This could be expanded with + # a small dead-zone to capture all zero crossings, but not seeing a + # major need at this time. + hcaEnabled = False + self.hcaEnabledFrameCount = 0 + else: + self.hcaEnabledFrameCount += 1 + if self.hcaEnabledFrameCount >= 118 * (100 / P.HCA_STEP): # 118s + # The Kansas I-70 Crosswind Problem: if we truly do need to steer + # in one direction for > 360 seconds, we have to disable HCA for a + # frame while actively steering. Testing shows we can just set the + # disabled flag, and keep sending non-zero torque, which keeps the + # Panda torque rate limiting safety happy. Do so 3x within the 360 + # second window for safety and redundancy. + hcaEnabled = False + self.hcaEnabledFrameCount = 0 + else: + hcaEnabled = True + # FAULT AVOIDANCE: HCA torque must not be static for > 6 seconds. + # This is to detect the sending camera being stuck or frozen. OP + # can trip this on a curve if steering is saturated. Avoid this by + # reducing torque 0.01 Nm for one frame. Do so 3x within the 6 + # second period for safety and redundancy. + if self.apply_steer_last == apply_steer: + self.hcaSameTorqueCount += 1 + if self.hcaSameTorqueCount > 1.9 * (100 / P.HCA_STEP): # 1.9s + apply_steer -= (1, -1)[apply_steer < 0] + self.hcaSameTorqueCount = 0 + else: + self.hcaSameTorqueCount = 0 + + else: + # Continue sending HCA_01 messages, with the enable flags turned off. + hcaEnabled = False + apply_steer = 0 + + self.apply_steer_last = apply_steer + idx = (frame / P.HCA_STEP) % 16 + can_sends.append(volkswagencan.create_mqb_steering_control(self.packer_gw, canbus.gateway, apply_steer, + idx, hcaEnabled)) + + #-------------------------------------------------------------------------- + # # + # Prepare LDW_02 HUD messages with lane borders, confidence levels, and # + # the LKAS status LED. # + # # + #-------------------------------------------------------------------------- + + # The factory camera emits this message at 10Hz. When OP is active, Panda + # filters LDW_02 from the factory camera and OP emits LDW_02 at 10Hz. + + if frame % P.LDW_STEP == 0: + hcaEnabled = True if enabled and not CS.standstill else False + + if visual_alert == VisualAlert.steerRequired: + hud_alert = MQB_LDW_MESSAGES["laneAssistTakeOverSilent"] + else: + hud_alert = MQB_LDW_MESSAGES["none"] + + can_sends.append(volkswagencan.create_mqb_hud_control(self.packer_gw, canbus.gateway, hcaEnabled, + CS.steeringPressed, hud_alert, leftLaneVisible, + rightLaneVisible)) + + #-------------------------------------------------------------------------- + # # + # Prepare GRA_ACC_01 ACC control messages with button press events. # + # # + #-------------------------------------------------------------------------- + + # The car sends this message at 33hz. OP sends it on-demand only for + # virtual button presses. + # + # First create any virtual button press event needed by openpilot, to sync + # stock ACC with OP disengagement, or to auto-resume from stop. + + if frame > self.graMsgStartFramePrev + P.GRA_VBP_STEP: + if not enabled and CS.accEnabled: + # Cancel ACC if it's engaged with OP disengaged. + self.graButtonStatesToSend = BUTTON_STATES.copy() + self.graButtonStatesToSend["cancel"] = True + elif enabled and CS.standstill: + # Blip the Resume button if we're engaged at standstill. + # FIXME: This is a naive implementation, improve with visiond or radar input. + # A subset of MQBs like to "creep" too aggressively with this implementation. + self.graButtonStatesToSend = BUTTON_STATES.copy() + self.graButtonStatesToSend["resumeCruise"] = True + + # OP/Panda can see this message but can't filter it when integrated at the + # R242 LKAS camera. It could do so if integrated at the J533 gateway, but + # we need a generalized solution that works for either. The message is + # counter-protected, so we need to time our transmissions very precisely + # to achieve fast and fault-free switching between message flows accepted + # at the J428 ACC radar. + # + # Example message flow on the bus, frequency of 33Hz (GRA_ACC_STEP): + # + # CAR: 0 1 2 3 4 5 6 7 8 9 A B C D E F 0 1 2 3 4 5 6 + # EON: 3 4 5 6 7 8 9 A B C D E F 0 1 2 GG^ + # + # If OP needs to send a button press, it waits to see a GRA_ACC_01 message + # counter change, and then immediately follows up with the next increment. + # The OP message will be sent within about 1ms of the car's message, which + # is about 2ms before the car's next message is expected. OP sends for an + # arbitrary duration of 16 messages / ~0.5 sec, in lockstep with each new + # message from the car. + # + # Because OP's counter is synced to the car, J428 immediately accepts the + # OP messages as valid. Further messages from the car get discarded as + # duplicates without a fault. When OP stops sending, the extra time gap + # (GG) to the next valid car message is less than 1 * GRA_ACC_STEP. J428 + # tolerates the gap just fine and control returns to the car immediately. + + if CS.graMsgBusCounter != self.graMsgBusCounterPrev: + self.graMsgBusCounterPrev = CS.graMsgBusCounter + if self.graButtonStatesToSend is not None: + if self.graMsgSentCount == 0: + self.graMsgStartFramePrev = frame + idx = (CS.graMsgBusCounter + 1) % 16 + can_sends.append(volkswagencan.create_mqb_acc_buttons_control(self.packer_gw, canbus.extended, self.graButtonStatesToSend, CS, idx)) + self.graMsgSentCount += 1 + if self.graMsgSentCount >= 16: + self.graButtonStatesToSend = None + self.graMsgSentCount = 0 + + return can_sends diff --git a/selfdrive/car/volkswagen/carstate.py b/selfdrive/car/volkswagen/carstate.py new file mode 100644 index 00000000000000..a39cbae8c57af0 --- /dev/null +++ b/selfdrive/car/volkswagen/carstate.py @@ -0,0 +1,229 @@ +import numpy as np +from cereal import car +from common.kalman.simple_kalman import KF1D +from selfdrive.config import Conversions as CV +from selfdrive.can.parser import CANParser +from selfdrive.can.can_define import CANDefine +from selfdrive.car.volkswagen.values import DBC, BUTTON_STATES +from selfdrive.car.volkswagen.carcontroller import CarControllerParams + +GEAR = car.CarState.GearShifter + +def get_mqb_gateway_can_parser(CP, canbus): + # this function generates lists for signal, messages and initial values + signals = [ + # sig_name, sig_address, default + ("LWI_Lenkradwinkel", "LWI_01", 0), # Absolute steering angle + ("LWI_VZ_Lenkradwinkel", "LWI_01", 0), # Steering angle sign + ("LWI_Lenkradw_Geschw", "LWI_01", 0), # Absolute steering rate + ("LWI_VZ_Lenkradw_Geschw", "LWI_01", 0), # Steering rate sign + ("ESP_VL_Radgeschw_02", "ESP_19", 0), # ABS wheel speed, front left + ("ESP_VR_Radgeschw_02", "ESP_19", 0), # ABS wheel speed, front right + ("ESP_HL_Radgeschw_02", "ESP_19", 0), # ABS wheel speed, rear left + ("ESP_HR_Radgeschw_02", "ESP_19", 0), # ABS wheel speed, rear right + ("ESP_Gierrate", "ESP_02", 0), # Absolute yaw rate + ("ESP_VZ_Gierrate", "ESP_02", 0), # Yaw rate sign + ("ZV_FT_offen", "Gateway_72", 0), # Door open, driver + ("ZV_BT_offen", "Gateway_72", 0), # Door open, passenger + ("ZV_HFS_offen", "Gateway_72", 0), # Door open, rear left + ("ZV_HBFS_offen", "Gateway_72", 0), # Door open, rear right + ("ZV_HD_offen", "Gateway_72", 0), # Trunk or hatch open + ("BH_Blinker_li", "Gateway_72", 0), # Left turn signal on + ("BH_Blinker_re", "Gateway_72", 0), # Right turn signal on + ("GE_Fahrstufe", "Getriebe_11", 0), # Auto trans gear selector position + ("AB_Gurtschloss_FA", "Airbag_02", 0), # Seatbelt status, driver + ("AB_Gurtschloss_BF", "Airbag_02", 0), # Seatbelt status, passenger + ("ESP_Fahrer_bremst", "ESP_05", 0), # Brake pedal pressed + ("ESP_Status_Bremsdruck", "ESP_05", 0), # Brakes applied + ("ESP_Bremsdruck", "ESP_05", 0), # Brake pressure applied + ("MO_Fahrpedalrohwert_01", "Motor_20", 0), # Accelerator pedal value + ("MO_Kuppl_schalter", "Motor_14", 0), # Clutch switch + ("Driver_Strain", "EPS_01", 0), # Absolute driver torque input + ("Driver_Strain_VZ", "EPS_01", 0), # Driver torque input sign + ("HCA_Ready", "EPS_01", 0), # Steering rack HCA support configured + ("ESP_Tastung_passiv", "ESP_21", 0), # Stability control disabled + ("KBI_MFA_v_Einheit_02", "Einheiten_01", 0), # MPH vs KMH speed display + ("KBI_Handbremse", "Kombi_01", 0), # Manual handbrake applied + ("TSK_Fahrzeugmasse_02", "Motor_16", 0), # Estimated vehicle mass from drivetrain coordinator + ("GRA_Hauptschalter", "GRA_ACC_01", 0), # ACC button, on/off + ("GRA_Abbrechen", "GRA_ACC_01", 0), # ACC button, cancel + ("GRA_Tip_Setzen", "GRA_ACC_01", 0), # ACC button, set + ("GRA_Tip_Hoch", "GRA_ACC_01", 0), # ACC button, increase or accel + ("GRA_Tip_Runter", "GRA_ACC_01", 0), # ACC button, decrease or decel + ("GRA_Tip_Wiederaufnahme", "GRA_ACC_01", 0), # ACC button, resume + ("GRA_Verstellung_Zeitluecke", "GRA_ACC_01", 0), # ACC button, time gap adj + ("GRA_Typ_Hauptschalter", "GRA_ACC_01", 0), # ACC main button type + ("GRA_Tip_Stufe_2", "GRA_ACC_01", 0), # unknown related to stalk type + ("GRA_ButtonTypeInfo", "GRA_ACC_01", 0), # unknown related to stalk type + ("COUNTER", "GRA_ACC_01", 0), # GRA_ACC_01 CAN message counter + ] + + checks = [ + # sig_address, frequency + ("LWI_01", 100), # From J500 Steering Assist with integrated sensors + ("EPS_01", 100), # From J500 Steering Assist with integrated sensors + ("ESP_19", 100), # From J104 ABS/ESP controller + ("ESP_05", 50), # From J104 ABS/ESP controller + ("ESP_21", 50), # From J104 ABS/ESP controller + ("Motor_20", 50), # From J623 Engine control module + ("GRA_ACC_01", 33), # From J??? steering wheel control buttons + ("Getriebe_11", 20), # From J743 Auto transmission control module + ("Gateway_72", 10), # From J533 CAN gateway (aggregated data) + ("Motor_14", 10), # From J623 Engine control module + ("Airbag_02", 5), # From J234 Airbag control module + ("Kombi_01", 2), # From J285 Instrument cluster + ("Motor_16", 2), # From J623 Engine control module + ("Einheiten_01", 1), # From J??? not known if gateway, cluster, or BCM + ] + + return CANParser(DBC[CP.carFingerprint]['pt'], signals, checks, canbus.gateway) + +def get_mqb_extended_can_parser(CP, canbus): + + signals = [ + # sig_name, sig_address, default + ("ACC_Status_ACC", "ACC_06", 0), # ACC engagement status + ("ACC_Typ", "ACC_06", 0), # ACC type (follow to stop, stop&go) + ("SetSpeed", "ACC_02", 0), # ACC set speed + ] + + checks = [ + # sig_address, frequency + ("ACC_06", 50), # From J428 ACC radar control module + ("ACC_02", 17), # From J428 ACC radar control module + ] + + return CANParser(DBC[CP.carFingerprint]['pt'], signals, checks, canbus.extended) + +def parse_gear_shifter(gear, vals): + # Return mapping of gearshift position to selected gear. + + val_to_capnp = {'P': GEAR.park, 'R': GEAR.reverse, 'N': GEAR.neutral, + 'D': GEAR.drive, 'E': GEAR.eco, 'S': GEAR.sport, 'T': GEAR.manumatic} + try: + return val_to_capnp[vals[gear]] + except KeyError: + return "unknown" + +class CarState(): + def __init__(self, CP, canbus): + # initialize can parser + self.CP = CP + self.car_fingerprint = CP.carFingerprint + self.can_define = CANDefine(DBC[CP.carFingerprint]['pt']) + + self.shifter_values = self.can_define.dv["Getriebe_11"]['GE_Fahrstufe'] + + self.buttonStates = BUTTON_STATES.copy() + + # vEgo Kalman filter + dt = 0.01 + self.v_ego_kf = KF1D(x0=[[0.], [0.]], + A=[[1., dt], [0., 1.]], + C=[1., 0.], + K=[[0.12287673], [0.29666309]]) + + def update(self, gw_cp, ex_cp): + # Update vehicle speed and acceleration from ABS wheel speeds. + self.wheelSpeedFL = gw_cp.vl["ESP_19"]['ESP_VL_Radgeschw_02'] * CV.KPH_TO_MS + self.wheelSpeedFR = gw_cp.vl["ESP_19"]['ESP_VR_Radgeschw_02'] * CV.KPH_TO_MS + self.wheelSpeedRL = gw_cp.vl["ESP_19"]['ESP_HL_Radgeschw_02'] * CV.KPH_TO_MS + self.wheelSpeedRR = gw_cp.vl["ESP_19"]['ESP_HR_Radgeschw_02'] * CV.KPH_TO_MS + + self.vEgoRaw = float(np.mean([self.wheelSpeedFL, self.wheelSpeedFR, self.wheelSpeedRL, self.wheelSpeedRR])) + v_ego_x = self.v_ego_kf.update(self.vEgoRaw) + self.vEgo = float(v_ego_x[0]) + self.aEgo = float(v_ego_x[1]) + self.standstill = self.vEgoRaw < 0.1 + + # Update steering angle, rate, yaw rate, and driver input torque. VW send + # the sign/direction in a separate signal so they must be recombined. + self.steeringAngle = gw_cp.vl["LWI_01"]['LWI_Lenkradwinkel'] * (1,-1)[int(gw_cp.vl["LWI_01"]['LWI_VZ_Lenkradwinkel'])] + self.steeringRate = gw_cp.vl["LWI_01"]['LWI_Lenkradw_Geschw'] * (1,-1)[int(gw_cp.vl["LWI_01"]['LWI_VZ_Lenkradwinkel'])] + self.steeringTorque = gw_cp.vl["EPS_01"]['Driver_Strain'] * (1,-1)[int(gw_cp.vl["EPS_01"]['Driver_Strain_VZ'])] + self.steeringPressed = abs(self.steeringTorque) > CarControllerParams.STEER_DRIVER_ALLOWANCE + self.yawRate = gw_cp.vl["ESP_02"]['ESP_Gierrate'] * (1,-1)[int(gw_cp.vl["ESP_02"]['ESP_VZ_Gierrate'])] * CV.DEG_TO_RAD + + # Update gas, brakes, and gearshift. + self.gas = gw_cp.vl["Motor_20"]['MO_Fahrpedalrohwert_01'] / 100.0 + self.gasPressed = self.gas > 0 + self.brake = gw_cp.vl["ESP_05"]['ESP_Bremsdruck'] / 250.0 # FIXME: this is pressure in Bar, not sure what OP expects + self.brakePressed = bool(gw_cp.vl["ESP_05"]['ESP_Fahrer_bremst']) + self.brakeLights = bool(gw_cp.vl["ESP_05"]['ESP_Status_Bremsdruck']) + + # Update gear and/or clutch position data. + can_gear_shifter = int(gw_cp.vl["Getriebe_11"]['GE_Fahrstufe']) + self.gearShifter = parse_gear_shifter(can_gear_shifter, self.shifter_values) + + # Update door and trunk/hatch lid open status. + self.doorOpen = any([gw_cp.vl["Gateway_72"]['ZV_FT_offen'], + gw_cp.vl["Gateway_72"]['ZV_BT_offen'], + gw_cp.vl["Gateway_72"]['ZV_HFS_offen'], + gw_cp.vl["Gateway_72"]['ZV_HBFS_offen'], + gw_cp.vl["Gateway_72"]['ZV_HD_offen']]) + + # Update seatbelt fastened status. + self.seatbeltUnlatched = False if gw_cp.vl["Airbag_02"]["AB_Gurtschloss_FA"] == 3 else True + + # Update driver preference for metric. VW stores many different unit + # preferences, including separate units for for distance vs. speed. + # We use the speed preference for OP. + self.displayMetricUnits = not gw_cp.vl["Einheiten_01"]["KBI_MFA_v_Einheit_02"] + + # Update ACC radar status. + accStatus = ex_cp.vl["ACC_06"]['ACC_Status_ACC'] + if accStatus == 1: + # ACC okay but disabled + self.accFault = False + self.accAvailable = False + self.accEnabled = False + elif accStatus == 2: + # ACC okay and enabled, but not currently engaged + self.accFault = False + self.accAvailable = True + self.accEnabled = False + elif accStatus in [3, 4, 5]: + # ACC okay and enabled, currently engaged and regulating speed (3) or engaged with driver accelerating (4) or overrun (5) + self.accFault = False + self.accAvailable = True + self.accEnabled = True + else: + # ACC fault of some sort. Seen statuses 6 or 7 for CAN comms disruptions, visibility issues, etc. + self.accFault = True + self.accAvailable = False + self.accEnabled = False + + # Update ACC setpoint. When the setpoint is zero or there's an error, the + # radar sends a set-speed of ~90.69 m/s / 203mph. + self.accSetSpeed = ex_cp.vl["ACC_02"]['SetSpeed'] + if self.accSetSpeed > 90: self.accSetSpeed = 0 + + # Update control button states for turn signals and ACC controls. + self.buttonStates["leftBlinker"] = bool(gw_cp.vl["Gateway_72"]['BH_Blinker_li']) + self.buttonStates["leftBlinker"] = bool(gw_cp.vl["Gateway_72"]['BH_Blinker_re']) + self.buttonStates["accelCruise"] = bool(gw_cp.vl["GRA_ACC_01"]['GRA_Tip_Hoch']) + self.buttonStates["decelCruise"] = bool(gw_cp.vl["GRA_ACC_01"]['GRA_Tip_Runter']) + self.buttonStates["cancel"] = bool(gw_cp.vl["GRA_ACC_01"]['GRA_Abbrechen']) + self.buttonStates["setCruise"] = bool(gw_cp.vl["GRA_ACC_01"]['GRA_Tip_Setzen']) + self.buttonStates["resumeCruise"] = bool(gw_cp.vl["GRA_ACC_01"]['GRA_Tip_Wiederaufnahme']) + self.buttonStates["gapAdjustCruise"] = bool(gw_cp.vl["GRA_ACC_01"]['GRA_Verstellung_Zeitluecke']) + + # Read ACC hardware button type configuration info that has to pass thru + # to the radar. Ends up being different for steering wheel buttons vs + # third stalk type controls. + self.graHauptschalter = gw_cp.vl["GRA_ACC_01"]['GRA_Hauptschalter'] + self.graTypHauptschalter = gw_cp.vl["GRA_ACC_01"]['GRA_Typ_Hauptschalter'] + self.graButtonTypeInfo = gw_cp.vl["GRA_ACC_01"]['GRA_ButtonTypeInfo'] + self.graTipStufe2 = gw_cp.vl["GRA_ACC_01"]['GRA_Tip_Stufe_2'] + # Pick up the GRA_ACC_01 CAN message counter so we can sync to it for + # later cruise-control button spamming. + self.graMsgBusCounter = gw_cp.vl["GRA_ACC_01"]['COUNTER'] + + # Check to make sure the electric power steering rack is configured to + # accept and respond to HCA_01 messages and has not encountered a fault. + self.steeringFault = not gw_cp.vl["EPS_01"]["HCA_Ready"] + + # Additional safety checks performed in CarInterface. + self.parkingBrakeSet = bool(gw_cp.vl["Kombi_01"]['KBI_Handbremse']) # FIXME: need to include an EPB check as well + self.stabilityControlDisabled = gw_cp.vl["ESP_21"]['ESP_Tastung_passiv'] + diff --git a/selfdrive/car/volkswagen/interface.py b/selfdrive/car/volkswagen/interface.py new file mode 100644 index 00000000000000..272c86bece9402 --- /dev/null +++ b/selfdrive/car/volkswagen/interface.py @@ -0,0 +1,242 @@ +from cereal import car +from selfdrive.config import Conversions as CV +from selfdrive.controls.lib.drive_helpers import create_event, EventTypes as ET +from selfdrive.controls.lib.vehicle_model import VehicleModel +from selfdrive.car.volkswagen.values import CAR, BUTTON_STATES +from selfdrive.car.volkswagen.carstate import CarState, get_mqb_gateway_can_parser, get_mqb_extended_can_parser +from common.params import Params +from selfdrive.car import STD_CARGO_KG, scale_rot_inertia, scale_tire_stiffness, gen_empty_fingerprint +from selfdrive.car.interfaces import CarInterfaceBase + +GEAR = car.CarState.GearShifter + +class CANBUS: + gateway = 0 + extended = 2 + +class CarInterface(CarInterfaceBase): + def __init__(self, CP, CarController): + self.CP = CP + self.CC = None + + self.frame = 0 + + self.gasPressedPrev = False + self.brakePressedPrev = False + self.cruiseStateEnabledPrev = False + self.displayMetricUnitsPrev = None + self.buttonStatesPrev = BUTTON_STATES.copy() + + # *** init the major players *** + self.CS = CarState(CP, CANBUS) + self.VM = VehicleModel(CP) + self.gw_cp = get_mqb_gateway_can_parser(CP, CANBUS) + self.ex_cp = get_mqb_extended_can_parser(CP, CANBUS) + + # sending if read only is False + if CarController is not None: + self.CC = CarController(CANBUS, CP.carFingerprint) + + @staticmethod + def compute_gb(accel, speed): + return float(accel) / 4.0 + + @staticmethod + def get_params(candidate, fingerprint=gen_empty_fingerprint(), vin="", has_relay=False): + ret = car.CarParams.new_message() + + ret.carFingerprint = candidate + ret.isPandaBlack = has_relay + ret.carVin = vin + + if candidate == CAR.GOLF: + # Set common MQB parameters that will apply globally + ret.carName = "volkswagen" + ret.safetyModel = car.CarParams.SafetyModel.volkswagen + ret.enableCruise = True # Stock ACC still controls acceleration and braking + ret.openpilotLongitudinalControl = False + ret.steerControlType = car.CarParams.SteerControlType.torque + # Steer torque is strongly rate limit and max value is decently high. Off to avoid false positives + ret.steerLimitAlert = False + + # Additional common MQB parameters that may be overridden per-vehicle + ret.steerRateCost = 0.5 + ret.steerActuatorDelay = 0.05 # Hopefully all MQB racks are similar here + ret.steerMaxBP = [0.] # m/s + ret.steerMaxV = [1.] + + # As a starting point for speed-adjusted lateral tuning, use the example + # map speed breakpoints from a VW Tiguan (SSP 399 page 9). It's unclear + # whether the driver assist map breakpoints have any direct bearing on + # HCA assist torque, but if they're good breakpoints for the driver, + # they're probably good breakpoints for HCA as well. OP won't be driving + # 250kph/155mph but it provides interpolation scaling above 100kmh/62mph. + ret.lateralTuning.pid.kpBP = [0., 15 * CV.KPH_TO_MS, 50 * CV.KPH_TO_MS] + ret.lateralTuning.pid.kiBP = [0., 15 * CV.KPH_TO_MS, 50 * CV.KPH_TO_MS] + + # FIXME: Per-vehicle parameters need to be reintegrated. + # For the time being, per-vehicle stuff is being archived since we + # can't auto-detect very well yet. Now that tuning is figured out, + # averaged params should work reasonably on a range of cars. Owners + # can tweak here, as needed, until we have car type auto-detection. + + ret.mass = 1700 + STD_CARGO_KG + ret.wheelbase = 2.75 + ret.centerToFront = ret.wheelbase * 0.45 + ret.steerRatio = 15.6 + ret.lateralTuning.pid.kf = 0.00006 + ret.lateralTuning.pid.kpV = [0.15, 0.25, 0.60] + ret.lateralTuning.pid.kiV = [0.05, 0.05, 0.05] + tire_stiffness_factor = 0.6 + + ret.enableCamera = True # Stock camera detection doesn't apply to VW + ret.transmissionType = car.CarParams.TransmissionType.automatic + ret.steerRatioRear = 0. + + # No support for OP longitudinal control on Volkswagen at this time. + ret.gasMaxBP = [0.] + ret.gasMaxV = [0.] + ret.brakeMaxBP = [0.] + ret.brakeMaxV = [0.] + ret.longitudinalTuning.deadzoneBP = [0.] + ret.longitudinalTuning.deadzoneV = [0.] + ret.longitudinalTuning.kpBP = [0.] + ret.longitudinalTuning.kpV = [0.] + ret.longitudinalTuning.kiBP = [0.] + ret.longitudinalTuning.kiV = [0.] + + # TODO: get actual value, for now starting with reasonable value for + # civic and scaling by mass and wheelbase + ret.rotationalInertia = scale_rot_inertia(ret.mass, ret.wheelbase) + + # TODO: start from empirically derived lateral slip stiffness for the civic and scale by + # mass and CG position, so all cars will have approximately similar dyn behaviors + ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(ret.mass, ret.wheelbase, ret.centerToFront, + tire_stiffness_factor=tire_stiffness_factor) + + return ret + + # returns a car.CarState + def update(self, c, can_strings): + canMonoTimes = [] + events = [] + buttonEvents = [] + params = Params() + ret = car.CarState.new_message() + + # Process the most recent CAN message traffic, and check for validity + self.gw_cp.update_strings(can_strings) + self.ex_cp.update_strings(can_strings) + self.CS.update(self.gw_cp, self.ex_cp) + ret.canValid = self.gw_cp.can_valid and self.ex_cp.can_valid + + # Wheel and vehicle speed, yaw rate + ret.wheelSpeeds.fl = self.CS.wheelSpeedFL + ret.wheelSpeeds.fr = self.CS.wheelSpeedFR + ret.wheelSpeeds.rl = self.CS.wheelSpeedRL + ret.wheelSpeeds.rr = self.CS.wheelSpeedRR + ret.vEgoRaw = self.CS.vEgoRaw + ret.vEgo = self.CS.vEgo + ret.aEgo = self.CS.aEgo + ret.standstill = self.CS.standstill + + # Steering wheel position, movement, yaw rate, and driver input + ret.steeringAngle = self.CS.steeringAngle + ret.steeringRate = self.CS.steeringRate + ret.steeringTorque = self.CS.steeringTorque + ret.steeringPressed = self.CS.steeringPressed + ret.yawRate = self.CS.yawRate + + # Gas, brakes and shifting + ret.gas = self.CS.gas + ret.gasPressed = self.CS.gasPressed + ret.brake = self.CS.brake + ret.brakePressed = self.CS.brakePressed + ret.brakeLights = self.CS.brakeLights + ret.gearShifter = self.CS.gearShifter + + # Doors open, seatbelt unfastened + ret.doorOpen = self.CS.doorOpen + ret.seatbeltUnlatched = self.CS.seatbeltUnlatched + + # Update the EON metric configuration to match the car at first startup, + # or if there's been a change. + if self.CS.displayMetricUnits != self.displayMetricUnitsPrev: + params.put("IsMetric", "1" if self.CS.displayMetricUnits else "0") + + # Blinker switch updates + ret.leftBlinker = self.CS.buttonStates["leftBlinker"] + ret.rightBlinker = self.CS.buttonStates["rightBlinker"] + + # ACC cruise state + ret.cruiseState.available = self.CS.accAvailable + ret.cruiseState.enabled = self.CS.accEnabled + ret.cruiseState.speed = self.CS.accSetSpeed + + # Check for and process state-change events (button press or release) from + # the turn stalk switch or ACC steering wheel/control stalk buttons. + for button in self.CS.buttonStates: + if self.CS.buttonStates[button] != self.buttonStatesPrev[button]: + be = car.CarState.ButtonEvent.new_message() + be.type = button + be.pressed = self.CS.buttonStates[button] + buttonEvents.append(be) + + # Vehicle operation safety checks and events + if ret.doorOpen: + events.append(create_event('doorOpen', [ET.NO_ENTRY, ET.SOFT_DISABLE])) + if ret.seatbeltUnlatched: + events.append(create_event('seatbeltNotLatched', [ET.NO_ENTRY, ET.SOFT_DISABLE])) + if ret.gearShifter == GEAR.reverse: + events.append(create_event('reverseGear', [ET.NO_ENTRY, ET.IMMEDIATE_DISABLE])) + if not ret.gearShifter in [GEAR.drive, GEAR.eco, GEAR.sport]: + events.append(create_event('wrongGear', [ET.NO_ENTRY, ET.SOFT_DISABLE])) + if self.CS.stabilityControlDisabled: + events.append(create_event('espDisabled', [ET.NO_ENTRY, ET.SOFT_DISABLE])) + if self.CS.parkingBrakeSet: + events.append(create_event('parkBrake', [ET.NO_ENTRY, ET.USER_DISABLE])) + + # Vehicle health safety checks and events + if self.CS.accFault: + events.append(create_event('radarFault', [ET.NO_ENTRY, ET.IMMEDIATE_DISABLE])) + if self.CS.steeringFault: + events.append(create_event('steerTempUnavailable', [ET.NO_ENTRY, ET.WARNING])) + + # Per the Comma safety model, disable on pedals rising edge or when brake + # is pressed and speed isn't zero. + if (ret.gasPressed and not self.gasPressedPrev) or \ + (ret.brakePressed and (not self.brakePressedPrev or not ret.standstill)): + events.append(create_event('pedalPressed', [ET.NO_ENTRY, ET.USER_DISABLE])) + if ret.gasPressed: + events.append(create_event('pedalPressed', [ET.PRE_ENABLE])) + + # Engagement and longitudinal control using stock ACC. Make sure OP is + # disengaged if stock ACC is disengaged. + if not ret.cruiseState.enabled: + events.append(create_event('pcmDisable', [ET.USER_DISABLE])) + # Attempt OP engagement only on rising edge of stock ACC engagement. + elif not self.cruiseStateEnabledPrev: + events.append(create_event('pcmEnable', [ET.ENABLE])) + + ret.events = events + ret.buttonEvents = buttonEvents + ret.canMonoTimes = canMonoTimes + + # update previous car states + self.gasPressedPrev = ret.gasPressed + self.brakePressedPrev = ret.brakePressed + self.cruiseStateEnabledPrev = ret.cruiseState.enabled + self.displayMetricUnitsPrev = self.CS.displayMetricUnits + self.buttonStatesPrev = self.CS.buttonStates.copy() + + # cast to reader so it can't be modified + return ret.as_reader() + + def apply(self, c): + can_sends = self.CC.update(c.enabled, self.CS, self.frame, c.actuators, + c.hudControl.visualAlert, + c.hudControl.audibleAlert, + c.hudControl.leftLaneVisible, + c.hudControl.rightLaneVisible) + self.frame += 1 + return can_sends diff --git a/selfdrive/car/volkswagen/radar_interface.py b/selfdrive/car/volkswagen/radar_interface.py new file mode 100644 index 00000000000000..b2f76511360320 --- /dev/null +++ b/selfdrive/car/volkswagen/radar_interface.py @@ -0,0 +1,5 @@ +#!/usr/bin/env python3 +from selfdrive.car.interfaces import RadarInterfaceBase + +class RadarInterface(RadarInterfaceBase): + pass diff --git a/selfdrive/car/volkswagen/values.py b/selfdrive/car/volkswagen/values.py new file mode 100644 index 00000000000000..6a1106076c384f --- /dev/null +++ b/selfdrive/car/volkswagen/values.py @@ -0,0 +1,63 @@ +from selfdrive.car import dbc_dict + +class CarControllerParams: + HCA_STEP = 2 # HCA_01 message frequency 50Hz + LDW_STEP = 10 # LDW_02 message frequency 10Hz + GRA_ACC_STEP = 3 # GRA_ACC_01 message frequency 33Hz + + GRA_VBP_STEP = 100 # Send ACC virtual button presses once a second + GRA_VBP_COUNT = 16 # Send VBP messages for ~0.5s (GRA_ACC_STEP * 16) + + # Observed documented MQB limits: 3.00 Nm max, rate of change 5.00 Nm/sec. + # Limiting both torque and rate-of-change based on real-world testing and + # Comma's safety requirements for minimum time to lane departure. + STEER_MAX = 250 # Max heading control assist torque 2.50 Nm + STEER_DELTA_UP = 4 # Max HCA reached in 1.25s (STEER_MAX / (50Hz * 1.25)) + STEER_DELTA_DOWN = 10 # Min HCA reached in 0.60s (STEER_MAX / (50Hz * 0.60)) + STEER_DRIVER_ALLOWANCE = 80 + STEER_DRIVER_MULTIPLIER = 3 # weight driver torque heavily + STEER_DRIVER_FACTOR = 1 # from dbc + +BUTTON_STATES = { + "leftBlinker": False, + "rightBlinker": False, + "accelCruise": False, + "decelCruise": False, + "cancel": False, + "setCruise": False, + "resumeCruise": False, + "gapAdjustCruise": False +} + +MQB_LDW_MESSAGES = { + "none": 0, # Nothing to display + "laneAssistUnavailChime": 1, # "Lane Assist currently not available." with chime + "laneAssistUnavailNoSensorChime": 3, # "Lane Assist not available. No sensor view." with chime + "laneAssistTakeOverUrgent": 4, # "Lane Assist: Please Take Over Steering" with urgent beep + "emergencyAssistUrgent": 6, # "Emergency Assist: Please Take Over Steering" with urgent beep + "laneAssistTakeOverChime": 7, # "Lane Assist: Please Take Over Steering" with chime + "laneAssistTakeOverSilent": 8, # "Lane Assist: Please Take Over Steering" silent + "emergencyAssistChangingLanes": 9, # "Emergency Assist: Changing lanes..." with urgent beep + "laneAssistDeactivated": 10, # "Lane Assist deactivated." silent with persistent icon afterward +} + +class CAR: + GOLF = "Volkswagen Golf" + +FINGERPRINTS = { + CAR.GOLF: [ + # 76b83eb0245de90e|2019-10-21--17-40-42 - jyoung8607 car + {64: 8, 134: 8, 159: 8, 173: 8, 178: 8, 253: 8, 257: 8, 260: 8, 262: 8, 264: 8, 278: 8, 279: 8, 283: 8, 286: 8, 288: 8, 289: 8, 290: 8, 294: 8, 299: 8, 302: 8, 346: 8, 385: 8, 418: 8, 427: 8, 668: 8, 679: 8, 681: 8, 695: 8, 779: 8, 780: 8, 783: 8, 792: 8, 795: 8, 804: 8, 806: 8, 807: 8, 808: 8, 809: 8, 870: 8, 896: 8, 897: 8, 898: 8, 901: 8, 917: 8, 919: 8, 949: 8, 958: 8, 960: 4, 981: 8, 987: 8, 988: 8, 991: 8, 997: 8, 1000: 8, 1019: 8, 1120: 8, 1122: 8, 1123: 8, 1124: 8, 1153: 8, 1162: 8, 1175: 8, 1312: 8, 1385: 8, 1413: 8, 1440: 5, 1514: 8, 1515: 8, 1520: 8, 1600: 8, 1601: 8, 1603: 8, 1605: 8, 1624: 8, 1626: 8, 1629: 8, 1631: 8, 1646: 8, 1648: 8, 1712: 6, 1714: 8, 1716: 8, 1717: 8, 1719: 8, 1720: 8, 1721: 8 + }], +} + +class ECU: + CAM = 0 + +ECU_FINGERPRINT = { + ECU.CAM: [294, 919], # HCA_01 Heading Control Assist, LDW_02 Lane Departure Warning +} + +DBC = { + CAR.GOLF: dbc_dict('vw_mqb_2010', None), +} diff --git a/selfdrive/car/volkswagen/volkswagencan.py b/selfdrive/car/volkswagen/volkswagencan.py new file mode 100644 index 00000000000000..34f19003d89b04 --- /dev/null +++ b/selfdrive/car/volkswagen/volkswagencan.py @@ -0,0 +1,52 @@ +# CAN controls for MQB platform Volkswagen, Audi, Skoda and SEAT. +# PQ35/PQ46/NMS, and any future MLB, to come later. + +def create_mqb_steering_control(packer, bus, apply_steer, idx, lkas_enabled): + values = { + "SET_ME_0X3": 0x3, + "Assist_Torque": abs(apply_steer), + "Assist_Requested": lkas_enabled, + "Assist_VZ": 1 if apply_steer < 0 else 0, + "HCA_Available": 1, + "HCA_Standby": not lkas_enabled, + "HCA_Active": lkas_enabled, + "SET_ME_0XFE": 0xFE, + "SET_ME_0X07": 0x07, + } + return packer.make_can_msg("HCA_01", bus, values, idx) + +def create_mqb_hud_control(packer, bus, hca_enabled, steering_pressed, hud_alert, leftLaneVisible, rightLaneVisible): + + if hca_enabled: + leftlanehud = 3 if leftLaneVisible else 1 + rightlanehud = 3 if rightLaneVisible else 1 + else: + leftlanehud = 2 if leftLaneVisible else 1 + rightlanehud = 2 if rightLaneVisible else 1 + + values = { + "LDW_Unknown": 2, # FIXME: possible speed or attention relationship + "Kombi_Lamp_Orange": 1 if hca_enabled and steering_pressed else 0, + "Kombi_Lamp_Green": 1 if hca_enabled and not steering_pressed else 0, + "Left_Lane_Status": leftlanehud, + "Right_Lane_Status": rightlanehud, + "Alert_Message": hud_alert, + } + return packer.make_can_msg("LDW_02", bus, values) + +def create_mqb_acc_buttons_control(packer, bus, buttonStatesToSend, CS, idx): + values = { + "GRA_Hauptschalter": CS.graHauptschalter, + "GRA_Abbrechen": buttonStatesToSend["cancel"], + "GRA_Tip_Setzen": buttonStatesToSend["setCruise"], + "GRA_Tip_Hoch": buttonStatesToSend["accelCruise"], + "GRA_Tip_Runter": buttonStatesToSend["decelCruise"], + "GRA_Tip_Wiederaufnahme": buttonStatesToSend["resumeCruise"], + "GRA_Verstellung_Zeitluecke": 3 if buttonStatesToSend["gapAdjustCruise"] else 0, + "GRA_Typ_Hauptschalter": CS.graTypHauptschalter, + "GRA_Codierung": 2, + "GRA_Tip_Stufe_2": CS.graTipStufe2, + "GRA_ButtonTypeInfo": CS.graButtonTypeInfo + } + + return packer.make_can_msg("GRA_ACC_01", bus, values, idx) diff --git a/selfdrive/common/params.cc b/selfdrive/common/params.cc index 0bdf6118a6616e..6e0e8b186f33ba 100644 --- a/selfdrive/common/params.cc +++ b/selfdrive/common/params.cc @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -109,6 +110,12 @@ int write_db_value(const char* params_path, const char* key, const char* value, goto cleanup; } + // change permissions to 0666 for apks + result = fchmod(tmp_fd, 0666); + if (result < 0) { + goto cleanup; + } + // fsync to force persist the changes. result = fsync(tmp_fd); if (result < 0) { diff --git a/selfdrive/common/utilpp.h b/selfdrive/common/utilpp.h index e374c5c256f772..6a68b5fba2d1d7 100644 --- a/selfdrive/common/utilpp.h +++ b/selfdrive/common/utilpp.h @@ -18,7 +18,7 @@ inline bool starts_with(std::string s, std::string prefix) { template inline std::string string_format( const std::string& format, Args ... args ) { size_t size = snprintf( nullptr, 0, format.c_str(), args ... ) + 1; - std::unique_ptr buf( new char[ size ] ); + std::unique_ptr buf( new char[ size ] ); snprintf( buf.get(), size, format.c_str(), args ... ); return std::string( buf.get(), buf.get() + size - 1 ); } @@ -32,7 +32,7 @@ inline std::string read_file(std::string fn) { inline std::string tohex(const uint8_t* buf, size_t buf_size) { std::unique_ptr hexbuf(new char[buf_size*2+1]); - for (int i=0; i +#include +#include + +#ifdef __APPLE__ +#include +#else +#include +#endif + +VisionBuf visionbuf_allocate(size_t len) { + // const size_t alignment = 4096; + // void* addr = aligned_alloc(alignment, alignment * ((len - 1) / alignment + 1)); + void* addr = calloc(1, len); + + return (VisionBuf){ + .len = len, .addr = addr, .handle = 1, .fd = -1, + }; +} + +cl_mem visionbuf_to_cl(const VisionBuf* buf, cl_device_id device_id, cl_context ctx) { + // HACK because this platform is just for convenience + VisionBuf *w_buf = (VisionBuf*)buf; + cl_mem ret; + *w_buf = visionbuf_allocate_cl(buf->len, device_id, ctx, &ret); + return ret; +} + +VisionBuf visionbuf_allocate_cl(size_t len, cl_device_id device_id, cl_context ctx, cl_mem *out_mem) { + int err; + assert(out_mem); + +#if __OPENCL_VERSION__ >= 200 + void* host_ptr = + clSVMAlloc(ctx, CL_MEM_READ_WRITE | CL_MEM_SVM_FINE_GRAIN_BUFFER, len, 0); + assert(host_ptr); +#else + void* host_ptr = calloc(1, len); + + cl_command_queue q = clCreateCommandQueue(ctx, device_id, 0, &err); + assert(err == 0); +#endif + + cl_mem mem = clCreateBuffer(ctx, CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR, len, host_ptr, &err); + assert(err == 0); + + *out_mem = mem; + + return (VisionBuf){ + .len = len, .addr = host_ptr, .handle = 0, .fd = -1, + .device_id = device_id, .ctx = ctx, .buf_cl = mem, + +#if __OPENCL_VERSION__ < 200 + .copy_q = q, +#endif + + }; +} + +void visionbuf_sync(const VisionBuf* buf, int dir) { + int err = 0; + if (!buf->buf_cl) return; + +#if __OPENCL_VERSION__ < 200 + if (dir == VISIONBUF_SYNC_FROM_DEVICE) { + err = clEnqueueReadBuffer(buf->copy_q, buf->buf_cl, CL_FALSE, 0, buf->len, buf->addr, 0, NULL, NULL); + } else { + err = clEnqueueWriteBuffer(buf->copy_q, buf->buf_cl, CL_FALSE, 0, buf->len, buf->addr, 0, NULL, NULL); + } + assert(err == 0); + clFinish(buf->copy_q); +#endif +} + +void visionbuf_free(const VisionBuf* buf) { + if (buf->handle) { + free(buf->addr); + } else { + int err = clReleaseMemObject(buf->buf_cl); + assert(err == 0); +#if __OPENCL_VERSION__ >= 200 + clSVMFree(buf->ctx, buf->addr); +#else + free(buf->addr); +#endif + } +} diff --git a/selfdrive/controls/controlsd.py b/selfdrive/controls/controlsd.py index 6452c1dfa2084e..de3b9a7c2efc0c 100644 --- a/selfdrive/controls/controlsd.py +++ b/selfdrive/controls/controlsd.py @@ -1,9 +1,9 @@ #!/usr/bin/env python3 import os import gc -import json import capnp import zmq +from selfdrive.services import service_list from cereal import car, log, arne182 from common.numpy_fast import clip from common.realtime import sec_since_boot, set_realtime_priority, Ratekeeper, DT_CTRL @@ -11,9 +11,8 @@ from common.params import Params, put_nonblocking import selfdrive.messaging as messaging from selfdrive.config import Conversions as CV -from selfdrive.services import service_list from selfdrive.boardd.boardd import can_list_to_can_capnp -from selfdrive.car.car_helpers import get_car, get_startup_alert, get_one_can +from selfdrive.car.car_helpers import get_car, get_startup_alert from selfdrive.controls.lib.lane_planner import CAMERA_OFFSET from selfdrive.controls.lib.drive_helpers import get_events, \ create_event, \ @@ -55,12 +54,12 @@ def events_to_bytes(events): return ret -def data_sample(CI, CC, sm, can_poller, can_sock, cal_status, cal_perc, overtemp, free_space, low_battery, +def data_sample(CI, CC, sm, can_sock, cal_status, cal_perc, overtemp, free_space, low_battery, driver_status, state, mismatch_counter, params): """Receive data from sockets and create events for battery, temperature and disk space""" # Update carstate from CAN and create events - can_strs = messaging.drain_sock_raw_poller(can_poller, can_sock, wait_for_one=True) + can_strs = messaging.drain_sock_raw(can_sock, wait_for_one=True) CS = CI.update(CC, can_strs) sm.update(0) @@ -462,17 +461,16 @@ def controlsd_thread(sm=None, pm=None, can_sock=None): can_poller = zmq.Poller() poller = zmq.Poller() - arne182Status = messaging.sub_sock(service_list['arne182Status'].port, poller, conflate=True) + arne182Status = messaging.sub_sock(service_list['arne182Status'].port, poller, conflate=True) # todo: can we use messaging_arne here? if can_sock is None: can_timeout = None if os.environ.get('NO_CAN_TIMEOUT', False) else 100 - can_sock = messaging.sub_sock(service_list['can'].port, timeout=can_timeout) - can_poller.register(can_sock) + can_sock = messaging.sub_sock('can', timeout=can_timeout) # wait for health and CAN packets hw_type = messaging.recv_one(sm.sock['health']).health.hwType has_relay = hw_type in [HwType.blackPanda, HwType.uno] print("Waiting for CAN messages...") - get_one_can(can_sock) + messaging.get_one_can(can_sock) CI, CP = get_car(can_sock, pm.sock['sendcan'], has_relay) @@ -481,7 +479,7 @@ def controlsd_thread(sm=None, pm=None, can_sock=None): controller_available = CP.enableCamera and CI.CC is not None and not passive read_only = not car_recognized or not controller_available or CP.dashcamOnly if read_only: - CP.safetyModel = CP.safetyModelPassive + CP.safetyModel = car.CarParams.SafetyModel.noOutput # Write CarParams for radard and boardd safety mode params.put("CarParams", CP.to_bytes()) @@ -529,9 +527,7 @@ def controlsd_thread(sm=None, pm=None, can_sock=None): # controlsd is driven by can recv, expected at 100Hz rk = Ratekeeper(100, print_delay_threshold=None) - # FIXME: offroad alerts should not be created with negative severity - connectivity_alert = params.get("Offroad_ConnectivityNeeded", encoding='utf8') - internet_needed = connectivity_alert is not None and json.loads(connectivity_alert.replace("'", "\""))["severity"] >= 0 + internet_needed = params.get("Offroad_ConnectivityNeeded", encoding='utf8') is not None prof = Profiler(False) # off by default @@ -541,7 +537,7 @@ def controlsd_thread(sm=None, pm=None, can_sock=None): # Sample data and compute car events CS, events, cal_status, cal_perc, overtemp, free_space, low_battery, mismatch_counter =\ - data_sample(CI, CC, sm, can_poller, can_sock, cal_status, cal_perc, overtemp, free_space, low_battery, + data_sample(CI, CC, sm, can_sock, cal_status, cal_perc, overtemp, free_space, low_battery, driver_status, state, mismatch_counter, params) prof.checkpoint("Sample") diff --git a/selfdrive/controls/lib/alerts.py b/selfdrive/controls/lib/alerts.py index 2e2a38f3dc4c61..40d35c48a60662 100644 --- a/selfdrive/controls/lib/alerts.py +++ b/selfdrive/controls/lib/alerts.py @@ -403,63 +403,63 @@ def __gt__(self, alert2): "TAKE CONTROL IMMEDIATELY", "Controls Failed", AlertStatus.critical, AlertSize.full, - Priority.HIGHEST, VisualAlert.steerRequired, AudibleAlert.chimeWarningRepeat, 1., 3., 4.), + Priority.HIGHEST, VisualAlert.steerRequired, AudibleAlert.chimeWarningRepeat, 2.2, 3., 4.), Alert( "controlsMismatch", "TAKE CONTROL IMMEDIATELY", "Controls Mismatch", AlertStatus.critical, AlertSize.full, - Priority.HIGHEST, VisualAlert.steerRequired, AudibleAlert.chimeWarningRepeat, 1., 3., 4.), + Priority.HIGHEST, VisualAlert.steerRequired, AudibleAlert.chimeWarningRepeat, 2.2, 3., 4.), Alert( "canError", "TAKE CONTROL IMMEDIATELY", "CAN Error: Check Connections", AlertStatus.critical, AlertSize.full, - Priority.HIGHEST, VisualAlert.steerRequired, AudibleAlert.chimeWarningRepeat, 1., 3., 4.), + Priority.HIGHEST, VisualAlert.steerRequired, AudibleAlert.chimeWarningRepeat, 2.2, 3., 4.), Alert( "steerUnavailable", "TAKE CONTROL IMMEDIATELY", "LKAS Fault: Restart the Car", AlertStatus.critical, AlertSize.full, - Priority.HIGHEST, VisualAlert.steerRequired, AudibleAlert.chimeWarningRepeat, 1., 3., 4.), + Priority.HIGHEST, VisualAlert.steerRequired, AudibleAlert.chimeWarningRepeat, 2.2, 3., 4.), Alert( "brakeUnavailable", "TAKE CONTROL IMMEDIATELY", "Cruise Fault: Restart the Car", AlertStatus.critical, AlertSize.full, - Priority.HIGHEST, VisualAlert.steerRequired, AudibleAlert.chimeWarningRepeat, 1., 3., 4.), + Priority.HIGHEST, VisualAlert.steerRequired, AudibleAlert.chimeWarningRepeat, 2.2, 3., 4.), Alert( "gasUnavailable", "TAKE CONTROL IMMEDIATELY", "Gas Fault: Restart the Car", AlertStatus.critical, AlertSize.full, - Priority.HIGHEST, VisualAlert.steerRequired, AudibleAlert.chimeWarningRepeat, 1., 3., 4.), + Priority.HIGHEST, VisualAlert.steerRequired, AudibleAlert.chimeWarningRepeat, 2.2, 3., 4.), Alert( "reverseGear", "TAKE CONTROL IMMEDIATELY", "Reverse Gear", AlertStatus.critical, AlertSize.full, - Priority.HIGHEST, VisualAlert.steerRequired, AudibleAlert.chimeWarningRepeat, 1., 3., 4.), + Priority.HIGHEST, VisualAlert.steerRequired, AudibleAlert.chimeWarningRepeat, 2.2, 3., 4.), Alert( "cruiseDisabled", "TAKE CONTROL IMMEDIATELY", "Cruise Is Off", AlertStatus.critical, AlertSize.full, - Priority.HIGHEST, VisualAlert.steerRequired, AudibleAlert.chimeWarningRepeat, 1., 3., 4.), + Priority.HIGHEST, VisualAlert.steerRequired, AudibleAlert.chimeWarningRepeat, 2.2, 3., 4.), Alert( "plannerError", "TAKE CONTROL IMMEDIATELY", "Planner Solution Error", AlertStatus.critical, AlertSize.full, - Priority.HIGHEST, VisualAlert.steerRequired, AudibleAlert.chimeWarningRepeat, 1., 3., 4.), + Priority.HIGHEST, VisualAlert.steerRequired, AudibleAlert.chimeWarningRepeat, 2.2, 3., 4.), # not loud cancellations (user is in control) Alert( @@ -631,6 +631,13 @@ def __gt__(self, alert2): AlertStatus.normal, AlertSize.mid, Priority.LOW, VisualAlert.none, AudibleAlert.chimeDisengage, .4, 2., 3.), + Alert( + "invalidGiraffeToyotaNoEntry", + "openpilot Unavailable", + "Visit comma.ai/tg", + AlertStatus.normal, AlertSize.mid, + Priority.LOW, VisualAlert.none, AudibleAlert.chimeDisengage, .4, 2., 3.), + Alert( "commIssueNoEntry", "openpilot Unavailable", diff --git a/selfdrive/controls/lib/alerts_offroad.json b/selfdrive/controls/lib/alerts_offroad.json index 52a55f23a6684d..534deae2fe3879 100644 --- a/selfdrive/controls/lib/alerts_offroad.json +++ b/selfdrive/controls/lib/alerts_offroad.json @@ -15,5 +15,13 @@ "Offroad_ConnectivityNeeded": { "text": "Connect to internet to check for updates. openpilot won't engage.", "severity": 1 + }, + "Offroad_PandaFirmwareMismatch": { + "text": "Unexpected panda firmware version. System won't start. Reboot your EON to reflash panda.", + "severity": 1 + }, + "Offroad_InvalidTime": { + "text": "Invalid date and time settings, system won't start. Connect to internet to set time.", + "severity": 1 } } diff --git a/selfdrive/controls/lib/lane_planner.py b/selfdrive/controls/lib/lane_planner.py index 63ef2858b1f994..df313ae7759736 100644 --- a/selfdrive/controls/lib/lane_planner.py +++ b/selfdrive/controls/lib/lane_planner.py @@ -29,7 +29,7 @@ def calc_d_poly(l_poly, r_poly, p_poly, l_prob, r_prob, lane_width): path_from_right_lane = r_poly.copy() path_from_right_lane[3] += lane_width / 2.0 - lr_prob = l_prob * r_prob + lr_prob = l_prob + r_prob - l_prob * r_prob d_poly_lane = (l_prob * path_from_left_lane + r_prob * path_from_right_lane) / (l_prob + r_prob + 0.0001) return lr_prob * d_poly_lane + (1.0 - lr_prob) * p_poly diff --git a/selfdrive/controls/lib/latcontrol_indi.py b/selfdrive/controls/lib/latcontrol_indi.py index 7b8b95722d3f8c..e43445afbf8e06 100644 --- a/selfdrive/controls/lib/latcontrol_indi.py +++ b/selfdrive/controls/lib/latcontrol_indi.py @@ -4,7 +4,7 @@ from cereal import log from common.realtime import DT_CTRL from common.numpy_fast import clip -from selfdrive.car.toyota.carcontroller import SteerLimitParams +from selfdrive.car.toyota.values import SteerLimitParams from selfdrive.car import apply_toyota_steer_torque_limits from selfdrive.controls.lib.drive_helpers import get_steer_max from selfdrive.controls.lane_hugging import LaneHugging diff --git a/selfdrive/controls/lib/long_mpc.py b/selfdrive/controls/lib/long_mpc.py index a55a24cb619851..2caba30ee2fc16 100644 --- a/selfdrive/controls/lib/long_mpc.py +++ b/selfdrive/controls/lib/long_mpc.py @@ -8,6 +8,7 @@ from selfdrive.controls.lib.radar_helpers import _LEAD_ACCEL_TAU from selfdrive.controls.lib.longitudinal_mpc import libmpc_py from selfdrive.controls.lib.drive_helpers import MPC_COST_LONG +from selfdrive.phantom import Phantom import time LOG_MPC = os.environ.get('LOG_MPC', False) @@ -33,8 +34,8 @@ def __init__(self, mpc_id): self.last_time = None self.v_lead = None self.x_lead = None - self.df_data = [] self.df_frame = 0 + self.phantom = Phantom(timeout=1.) self.last_cloudlog_t = 0.0 @@ -119,16 +120,16 @@ def smooth_follow(self): # in m/s TR = interp(self.v_ego, x, y) if self.v_lead is not None: # since the new mpc now handles braking nicely, simplify mods - x = [0, 0.61, 1.26, 2.1, 2.68] # relative velocity values + x = [0, 0.61, 1.26, 2.1, 2.68] # relative velocity values todo: add back negative values to get farther away from lead when it's slower y = [0, -0.017, -0.053, -0.154, -0.272] # modification values TR_mod = interp(self.v_lead - self.v_ego, x, y) # quicker acceleration/don't brake when lead is overtaking - '''x = [-1.49, -1.1, -0.67, 0.0, 0.67, 1.1, 1.49] - y = [0.056, 0.032, 0.016, 0.0, -0.016, -0.032, -0.056] - TR_mod += interp(self.get_acceleration(), x, y) # when lead car has been braking over the past 3 seconds, slightly increase TR''' + # x = [-1.49, -1.1, -0.67, 0.0, 0.67, 1.1, 1.49] # todo: work on adding this back + # y = [0.056, 0.032, 0.016, 0.0, -0.016, -0.032, -0.056] + # TR_mod += interp(self.get_acceleration(), x, y) # when lead car has been braking over the past 3 seconds, slightly increase TR TR += TR_mod - #TR *= self.get_traffic_level() # modify TR based on last minute of traffic data + #TR *= self.get_traffic_level() # modify TR based on last minute of traffic data # todo: look at getting this to work, a model could be used if TR < 0.9: return 0.9 else: @@ -188,15 +189,51 @@ def calc_rate(self, seconds=1.0, new_frame=False): # return current rate of lon self.last_time = current_time return int(round(max(min(rate, max_return), min_return))) # ensure we return a value between range, in hertz + def process_phantom(self, lead): + if lead is not None and lead.status: + v_lead = max(0.0, lead.vLead) + if v_lead < 0.1 or -lead.aLeadK / 2.0 > v_lead: + v_lead = 0.0 + # if radar lead is available, ensure we use that as the real lead rather than ignoring it and running into it + # todo: this is buggy and probably needs to be looked at + x_lead = min(9.144, lead.dRel) + v_lead = min(self.phantom.data["speed"], v_lead) + else: + x_lead = 9.144 + v_lead = self.phantom.data["speed"] + return x_lead, v_lead + def update(self, pm, CS, lead, v_cruise_setpoint): v_ego = CS.vEgo self.car_state = CS self.v_ego = CS.vEgo - + self.phantom.update() + # Setup current mpc state self.cur_state[0].x_ego = 0.0 - if lead is not None and lead.status: + if self.phantom.data["status"]: + if self.phantom.data["speed"] != 0.0: + x_lead, v_lead = self.process_phantom(lead) + elif 'lost_connection' in self.phantom.data: + x_lead = 1.5 + v_lead = 0. # stop as quickly as possible + else: # else, smooth deceleration + x_lead = 3.75 + v_lead = max(self.v_ego - (.7 / max(max(self.v_ego, 0) ** .4, .01)), 0.0) # smoothly decelerate to 0 todo: tune this! + + a_lead = 0.0 + self.a_lead_tau = lead.aLeadTau + self.new_lead = False + if not self.prev_lead_status or abs(x_lead - self.prev_lead_x) > 2.5: + self.libmpc.init_with_simulation(self.v_mpc, x_lead, v_lead, a_lead, self.a_lead_tau) + self.new_lead = True + + self.prev_lead_status = True + self.prev_lead_x = x_lead + self.cur_state[0].x_l = x_lead + self.cur_state[0].v_l = v_lead + elif lead is not None and lead.status: x_lead = lead.dRel v_lead = max(0.0, lead.vLead) a_lead = lead.aLeadK @@ -204,10 +241,10 @@ def update(self, pm, CS, lead, v_cruise_setpoint): if (v_lead < 0.1 or -a_lead / 2.0 > v_lead): v_lead = 0.0 a_lead = 0.0 - + self.v_lead = v_lead self.x_lead = x_lead - + self.a_lead_tau = lead.aLeadTau self.new_lead = False if not self.prev_lead_status or abs(x_lead - self.prev_lead_x) > 2.5: diff --git a/selfdrive/controls/lib/planner.py b/selfdrive/controls/lib/planner.py index 4951dc9522a7f6..8f989cba29abb1 100644 --- a/selfdrive/controls/lib/planner.py +++ b/selfdrive/controls/lib/planner.py @@ -33,8 +33,8 @@ # lookup tables VS speed to determine min and max accels in cruise # make sure these accelerations are smaller than mpc limits -_A_CRUISE_MIN_V_FOLLOWING = [-3.0, -1.7, -1.6, -1.5, -1.3] -_A_CRUISE_MIN_V = [-1.6, -0.7, -0.6, -0.5, -0.3] +_A_CRUISE_MIN_V_FOLLOWING = [-3.0, -1.7, -1.6, -1.5, -1.3] +_A_CRUISE_MIN_V = [-1.6, -0.7, -0.6, -0.5, -0.3] _A_CRUISE_MIN_BP = [0.0, 5.0, 10.0, 20.0, 55.0] # need fast accel at very low speed for stop and go diff --git a/selfdrive/controls/radard.py b/selfdrive/controls/radard.py index 2a36d9a0ab1845..4969ba3357d4e2 100755 --- a/selfdrive/controls/radard.py +++ b/selfdrive/controls/radard.py @@ -3,8 +3,6 @@ import math from collections import defaultdict, deque -import zmq - import selfdrive.messaging as messaging from cereal import car from common.params import Params @@ -13,7 +11,6 @@ from selfdrive.controls.lib.cluster.fastcluster_py import \ cluster_points_centroid from selfdrive.controls.lib.radar_helpers import Cluster, Track -from selfdrive.services import service_list from selfdrive.swaglog import cloudlog DEBUG = False @@ -189,11 +186,8 @@ def radard_thread(sm=None, pm=None, can_sock=None): cloudlog.info("radard is importing %s", CP.carName) RadarInterface = importlib.import_module('selfdrive.car.%s.radar_interface' % CP.carName).RadarInterface - can_poller = zmq.Poller() - if can_sock is None: - can_sock = messaging.sub_sock(service_list['can'].port) - can_poller.register(can_sock) + can_sock = messaging.sub_sock('can') if sm is None: sm = messaging.SubMaster(['model', 'controlsState', 'liveParameters']) @@ -210,7 +204,7 @@ def radard_thread(sm=None, pm=None, can_sock=None): has_radar = not CP.radarOffCan while 1: - can_strings = messaging.drain_sock_raw_poller(can_poller, can_sock, wait_for_one=True) + can_strings = messaging.drain_sock_raw(can_sock, wait_for_one=True) rr = RI.update(can_strings) if rr is None: diff --git a/selfdrive/debug/can_printer.py b/selfdrive/debug/can_printer.py index 6b5d188be39d00..9a72b29fa20a41 100755 --- a/selfdrive/debug/can_printer.py +++ b/selfdrive/debug/can_printer.py @@ -6,11 +6,10 @@ import selfdrive.messaging as messaging from common.realtime import sec_since_boot -from selfdrive.services import service_list def can_printer(bus=0, max_msg=None, addr="127.0.0.1"): - logcan = messaging.sub_sock(service_list['can'].port, addr=addr) + logcan = messaging.sub_sock('can', addr=addr) start = sec_since_boot() lp = sec_since_boot() diff --git a/selfdrive/debug/dump.py b/selfdrive/debug/dump.py index 84846a17a675fe..b8fc0582e88db9 100755 --- a/selfdrive/debug/dump.py +++ b/selfdrive/debug/dump.py @@ -1,20 +1,15 @@ #!/usr/bin/env python3 import sys import argparse -import zmq import json from hexdump import hexdump -from threading import Thread from cereal import log import selfdrive.messaging as messaging from selfdrive.services import service_list -def run_server(socketio): - socketio.run(app, host='0.0.0.0', port=4000) - if __name__ == "__main__": - poller = zmq.Poller() + poller = messaging.Poller() parser = argparse.ArgumentParser(description='Sniff a communcation socket') parser.add_argument('--pipe', action='store_true') @@ -22,57 +17,25 @@ def run_server(socketio): parser.add_argument('--json', action='store_true') parser.add_argument('--dump-json', action='store_true') parser.add_argument('--no-print', action='store_true') - parser.add_argument('--proxy', action='store_true', help='republish on localhost') - parser.add_argument('--map', action='store_true') parser.add_argument('--addr', default='127.0.0.1') parser.add_argument('--values', help='values to monitor (instead of entire event)') parser.add_argument("socket", type=str, nargs='*', help="socket name") args = parser.parse_args() - republish_socks = {} for m in args.socket if len(args.socket) > 0 else service_list: - if m in service_list: - port = service_list[m].port - elif m.isdigit(): - port = int(m) - else: - print("service not found") - sys.exit(-1) - sock = messaging.sub_sock(port, poller, addr=args.addr) - if args.proxy: - republish_socks[sock] = messaging.pub_sock(port) - - if args.map: - from flask.ext.socketio import SocketIO #pylint: disable=no-name-in-module, import-error - from flask import Flask - app = Flask(__name__) - socketio = SocketIO(app, async_mode='threading') - server_thread = Thread(target=run_server, args=(socketio,)) - server_thread.daemon = True - server_thread.start() - print('server running') + sock = messaging.sub_sock(m, poller, addr=args.addr) values = None if args.values: values = [s.strip().split(".") for s in args.values.split(",")] while 1: - polld = poller.poll(timeout=1000) - for sock, mode in polld: - if mode != zmq.POLLIN: - continue - msg = sock.recv() + polld = poller.poll(1000) + for sock in polld: + msg = sock.receive() evt = log.Event.from_bytes(msg) - if sock in republish_socks: - republish_socks[sock].send(msg) - if args.map and evt.which() == 'liveLocation': - print('send loc') - socketio.emit('location', { - 'lat': evt.liveLocation.lat, - 'lon': evt.liveLocation.lon, - 'alt': evt.liveLocation.alt, - }) + if not args.no_print: if args.pipe: sys.stdout.write(msg) diff --git a/selfdrive/debug/get_fingerprint.py b/selfdrive/debug/get_fingerprint.py index 286b71a132dd4f..e2111e191418eb 100755 --- a/selfdrive/debug/get_fingerprint.py +++ b/selfdrive/debug/get_fingerprint.py @@ -12,16 +12,15 @@ # until all messages are received at least once import selfdrive.messaging as messaging -from selfdrive.services import service_list -logcan = messaging.sub_sock(service_list['can'].port) +logcan = messaging.sub_sock('can') msgs = {} while True: lc = messaging.recv_sock(logcan, True) for c in lc.can: # read also msgs sent by EON on CAN bus 0x80 and filter out the # addr with more than 11 bits - if c.src%0x80 == 0 and c.address < 0x800: + if c.src in [0, 2] and c.address < 0x800: msgs[c.address] = len(c.dat) fingerprint = ', '.join("%d: %d" % v for v in sorted(msgs.items())) diff --git a/selfdrive/debug/mpc/live_lateral_mpc.py b/selfdrive/debug/mpc/live_lateral_mpc.py index f4ee7a18435836..5d7bc2bb828078 100755 --- a/selfdrive/debug/mpc/live_lateral_mpc.py +++ b/selfdrive/debug/mpc/live_lateral_mpc.py @@ -3,7 +3,6 @@ matplotlib.use('TkAgg') import sys -from selfdrive.services import service_list import selfdrive.messaging as messaging import numpy as np import matplotlib.pyplot as plt @@ -58,9 +57,9 @@ def mpc_vwr_thread(addr="127.0.0.1"): # *** log *** - livempc = messaging.sub_sock(service_list['liveMpc'].port, addr=addr) - model = messaging.sub_sock(service_list['model'].port, addr=addr) - path_plan_sock = messaging.sub_sock(service_list['pathPlan'].port, addr=addr) + livempc = messaging.sub_sock('liveMpc', addr=addr) + model = messaging.sub_sock('model', addr=addr) + path_plan_sock = messaging.sub_sock('pathPlan', addr=addr) while 1: lMpc = messaging.recv_sock(livempc, wait=True) diff --git a/selfdrive/debug/mpc/live_longitudinal_mpc.py b/selfdrive/debug/mpc/live_longitudinal_mpc.py index e72a37585fb8e8..c2d1143dd18597 100755 --- a/selfdrive/debug/mpc/live_longitudinal_mpc.py +++ b/selfdrive/debug/mpc/live_longitudinal_mpc.py @@ -4,7 +4,6 @@ matplotlib.use('TkAgg') import sys -from selfdrive.services import service_list import selfdrive.messaging as messaging import numpy as np import matplotlib.pyplot as plt @@ -16,8 +15,8 @@ def plot_longitudinal_mpc(addr="127.0.0.1"): # *** log *** - livempc = messaging.sub_sock(service_list['liveLongitudinalMpc'].port, addr=addr, conflate=True) - radarstate = messaging.sub_sock(service_list['radarState'].port, addr=addr, conflate=True) + livempc = messaging.sub_sock('liveLongitudinalMpc', addr=addr, conflate=True) + radarstate = messaging.sub_sock('radarState', addr=addr, conflate=True) plt.ion() fig = plt.figure() diff --git a/selfdrive/locationd/Makefile b/selfdrive/locationd/Makefile index ff46847689c805..995329334687f8 100644 --- a/selfdrive/locationd/Makefile +++ b/selfdrive/locationd/Makefile @@ -15,28 +15,25 @@ WARN_FLAGS = -Werror=implicit-function-declaration \ CFLAGS = -std=gnu11 -g -fPIC -I../ -I../../ -O2 $(WARN_FLAGS) -Wall CXXFLAGS = -std=c++11 -g -fPIC -I../ -I../../ -O2 $(WARN_FLAGS) -Wall -ZMQ_LIBS = -l:libczmq.a -l:libzmq.a + +MESSAGING_FLAGS = -I$(BASEDIR)/selfdrive/messaging +MESSAGING_LIBS = $(BASEDIR)/selfdrive/messaging/messaging.a + +EXTRA_LIBS = -lpthread ifeq ($(ARCH),aarch64) CFLAGS += -mcpu=cortex-a57 CXXFLAGS += -mcpu=cortex-a57 -ZMQ_LIBS += -lgnustl_shared +EXTRA_LIBS += -llog -luuid -lgnustl_shared endif JSON_FLAGS = -I$(PHONELIBS)/json/src JSON11_FLAGS = -I$(PHONELIBS)/json11 -EXTRA_LIBS = -lpthread ifeq ($(ARCH),x86_64) ZMQ_FLAGS = -I$(BASEDIR)/phonelibs/zmq/x64/include -ZMQ_LIBS = -L$(BASEDIR)/external/zmq/lib \ - -l:libczmq.a -l:libzmq.a -ZMQ_SHARED_LIBS = -L$(BASEDIR)/external/zmq/lib \ - -lczmq -lzmq -else -EXTRA_LIBS += -llog -luuid endif .PHONY: all @@ -64,32 +61,28 @@ OBJS = ublox_msg.o \ DEPS := $(OBJS:.o=.d) ubloxd.d ubloxd_test.d -liblocationd.so: $(LOC_OBJS) +liblocationd.so: $(LOC_OBJS) $(MESSAGING_LIBS) @echo "[ LINK ] $@" $(CXX) -shared -o '$@' $^ \ $(CEREAL_LIBS) \ - $(ZMQ_SHARED_LIBS) \ $(EXTRA_LIBS) -paramsd: $(LOC_OBJS) +paramsd: $(LOC_OBJS) $(MESSAGING_LIBS) @echo "[ LINK ] $@" $(CXX) -fPIC -o '$@' $^ \ $(CEREAL_LIBS) \ - $(ZMQ_LIBS) \ $(EXTRA_LIBS) -ubloxd: ubloxd.o $(OBJS) +ubloxd: ubloxd.o $(OBJS) $(MESSAGING_LIBS) @echo "[ LINK ] $@" $(CXX) -fPIC -o '$@' $^ \ $(CEREAL_LIBS) \ - $(ZMQ_LIBS) \ $(EXTRA_LIBS) -ubloxd_test: ubloxd_test.o $(OBJS) +ubloxd_test: ubloxd_test.o $(OBJS) $(MESSAGING_LIBS) @echo "[ LINK ] $@" $(CXX) -fPIC -o '$@' $^ \ $(CEREAL_LIBS) \ - $(ZMQ_LIBS) \ $(EXTRA_LIBS) %.o: %.cc @@ -98,6 +91,7 @@ ubloxd_test: ubloxd_test.o $(OBJS) -Iinclude -I.. -I../.. \ $(CEREAL_CXXFLAGS) \ $(ZMQ_FLAGS) \ + $(MESSAGING_FLAGS) \ $(JSON11_FLAGS) \ $(JSON_FLAGS) \ -I../ \ diff --git a/selfdrive/locationd/locationd_yawrate.cc b/selfdrive/locationd/locationd_yawrate.cc index de6ff9ff4e8251..83c837d7fb1bba 100644 --- a/selfdrive/locationd/locationd_yawrate.cc +++ b/selfdrive/locationd/locationd_yawrate.cc @@ -31,7 +31,7 @@ void Localizer::update_state(const Eigen::Matrix &C, const double void Localizer::handle_sensor_events(capnp::List::Reader sensor_events, double current_time) { for (cereal::SensorEventData::Reader sensor_event : sensor_events){ - if (sensor_event.getSensor() == 5) { + if (sensor_event.getSensor() == 5 && sensor_event.getType() == 16) { sensor_data_time = current_time; double meas = -sensor_event.getGyroUncalibrated().getV()[0]; update_state(C_gyro, R_gyro, current_time, meas); diff --git a/selfdrive/locationd/paramsd.cc b/selfdrive/locationd/paramsd.cc index a38729dcd12d91..a38fc403ab4560 100644 --- a/selfdrive/locationd/paramsd.cc +++ b/selfdrive/locationd/paramsd.cc @@ -1,7 +1,10 @@ #include #include +#include +#include +#include + -#include #include #include @@ -13,32 +16,28 @@ #include "common/params.h" #include "common/timing.h" +#include "messaging.hpp" #include "locationd_yawrate.h" #include "params_learner.h" -const int num_polls = 3; + +void sigpipe_handler(int sig) { + LOGE("SIGPIPE received"); +} + int main(int argc, char *argv[]) { - auto ctx = zmq_ctx_new(); - auto controls_state_sock = sub_sock(ctx, "tcp://127.0.0.1:8007"); - auto sensor_events_sock = sub_sock(ctx, "tcp://127.0.0.1:8003"); - auto camera_odometry_sock = sub_sock(ctx, "tcp://127.0.0.1:8066"); + signal(SIGPIPE, (sighandler_t)sigpipe_handler); - auto live_parameters_sock = zsock_new_pub("@tcp://*:8064"); - assert(live_parameters_sock); - auto live_parameters_sock_raw = zsock_resolve(live_parameters_sock); + Context * c = Context::create(); + SubSocket * controls_state_sock = SubSocket::create(c, "controlsState"); + SubSocket * sensor_events_sock = SubSocket::create(c, "sensorEvents"); + SubSocket * camera_odometry_sock = SubSocket::create(c, "cameraOdometry"); + PubSocket * live_parameters_sock = PubSocket::create(c, "liveParameters"); + Poller * poller = Poller::create({controls_state_sock, sensor_events_sock, camera_odometry_sock}); - int err; Localizer localizer; - zmq_pollitem_t polls[num_polls] = {{0}}; - polls[0].socket = controls_state_sock; - polls[0].events = ZMQ_POLLIN; - polls[1].socket = camera_odometry_sock; - polls[1].events = ZMQ_POLLIN; - polls[2].socket = sensor_events_sock; - polls[2].events = ZMQ_POLLIN; - // Read car params char *value; size_t value_sz = 0; @@ -98,96 +97,84 @@ int main(int argc, char *argv[]) { // Main loop int save_counter = 0; while (true){ - int ret = zmq_poll(polls, num_polls, 100); + for (auto s : poller->poll(-1)){ + Message * msg = s->receive(); - if (ret == 0){ - continue; - } else if (ret < 0){ - break; - } + auto amsg = kj::heapArray((msg->getSize() / sizeof(capnp::word)) + 1); + memcpy(amsg.begin(), msg->getData(), msg->getSize()); + + capnp::FlatArrayMessageReader capnp_msg(amsg); + cereal::Event::Reader event = capnp_msg.getRoot(); + + localizer.handle_log(event); - for (int i=0; i < num_polls; i++) { - if (polls[i].revents) { - zmq_msg_t msg; - err = zmq_msg_init(&msg); - assert(err == 0); - err = zmq_msg_recv(&msg, polls[i].socket, 0); - assert(err >= 0); - - // make copy due to alignment issues, will be freed on out of scope - auto amsg = kj::heapArray((zmq_msg_size(&msg) / sizeof(capnp::word)) + 1); - memcpy(amsg.begin(), zmq_msg_data(&msg), zmq_msg_size(&msg)); - zmq_msg_close(&msg); - - capnp::FlatArrayMessageReader capnp_msg(amsg); - cereal::Event::Reader event = capnp_msg.getRoot(); - - localizer.handle_log(event); - - auto which = event.which(); - // Throw vision failure if posenet and odometric speed too different - if (which == cereal::Event::CAMERA_ODOMETRY){ - if (std::abs(localizer.posenet_speed - localizer.car_speed) > std::max(0.4 * localizer.car_speed, 5.0)) { - posenet_invalid_count++; - } else { - posenet_invalid_count = 0; - } - } else if (which == cereal::Event::CONTROLS_STATE){ - save_counter++; - - double yaw_rate = -localizer.x[0]; - bool valid = learner.update(yaw_rate, localizer.car_speed, localizer.steering_angle); - - // TODO: Fix in replay - double sensor_data_age = localizer.controls_state_time - localizer.sensor_data_time; - double camera_odometry_age = localizer.controls_state_time - localizer.camera_odometry_time; - - double angle_offset_degrees = RADIANS_TO_DEGREES * learner.ao; - double angle_offset_average_degrees = RADIANS_TO_DEGREES * learner.slow_ao; - - capnp::MallocMessageBuilder msg; - cereal::Event::Builder event = msg.initRoot(); - event.setLogMonoTime(nanos_since_boot()); - auto live_params = event.initLiveParameters(); - live_params.setValid(valid); - live_params.setYawRate(localizer.x[0]); - live_params.setGyroBias(localizer.x[2]); - live_params.setSensorValid(sensor_data_age < 5.0); - live_params.setAngleOffset(angle_offset_degrees); - live_params.setAngleOffsetAverage(angle_offset_average_degrees); - live_params.setStiffnessFactor(learner.x); - live_params.setSteerRatio(learner.sR); - live_params.setPosenetSpeed(localizer.posenet_speed); - live_params.setPosenetValid((posenet_invalid_count < 4) && (camera_odometry_age < 5.0)); - - auto words = capnp::messageToFlatArray(msg); - auto bytes = words.asBytes(); - zmq_send(live_parameters_sock_raw, bytes.begin(), bytes.size(), ZMQ_DONTWAIT); - - // Save parameters every minute - if (save_counter % 6000 == 0) { - json11::Json json = json11::Json::object { - {"carVin", vin}, - {"carFingerprint", fingerprint}, - {"steerRatio", learner.sR}, - {"stiffnessFactor", learner.x}, - {"angleOffsetAverage", angle_offset_average_degrees}, - }; - - std::string out = json.dump(); - std::async(std::launch::async, - [out]{ - write_db_value(NULL, "LiveParameters", out.c_str(), out.length()); - }); - } + auto which = event.which(); + // Throw vision failure if posenet and odometric speed too different + if (which == cereal::Event::CAMERA_ODOMETRY){ + if (std::abs(localizer.posenet_speed - localizer.car_speed) > std::max(0.4 * localizer.car_speed, 5.0)) { + posenet_invalid_count++; + } else { + posenet_invalid_count = 0; + } + } else if (which == cereal::Event::CONTROLS_STATE){ + save_counter++; + + double yaw_rate = -localizer.x[0]; + bool valid = learner.update(yaw_rate, localizer.car_speed, localizer.steering_angle); + + // TODO: Fix in replay + double sensor_data_age = localizer.controls_state_time - localizer.sensor_data_time; + double camera_odometry_age = localizer.controls_state_time - localizer.camera_odometry_time; + + double angle_offset_degrees = RADIANS_TO_DEGREES * learner.ao; + double angle_offset_average_degrees = RADIANS_TO_DEGREES * learner.slow_ao; + + capnp::MallocMessageBuilder msg; + cereal::Event::Builder event = msg.initRoot(); + event.setLogMonoTime(nanos_since_boot()); + auto live_params = event.initLiveParameters(); + live_params.setValid(valid); + live_params.setYawRate(localizer.x[0]); + live_params.setGyroBias(localizer.x[2]); + live_params.setSensorValid(sensor_data_age < 5.0); + live_params.setAngleOffset(angle_offset_degrees); + live_params.setAngleOffsetAverage(angle_offset_average_degrees); + live_params.setStiffnessFactor(learner.x); + live_params.setSteerRatio(learner.sR); + live_params.setPosenetSpeed(localizer.posenet_speed); + live_params.setPosenetValid((posenet_invalid_count < 4) && (camera_odometry_age < 5.0)); + + auto words = capnp::messageToFlatArray(msg); + auto bytes = words.asBytes(); + live_parameters_sock->send((char*)bytes.begin(), bytes.size()); + + // Save parameters every minute + if (save_counter % 6000 == 0) { + json11::Json json = json11::Json::object { + {"carVin", vin}, + {"carFingerprint", fingerprint}, + {"steerRatio", learner.sR}, + {"stiffnessFactor", learner.x}, + {"angleOffsetAverage", angle_offset_average_degrees}, + }; + + std::string out = json.dump(); + std::async(std::launch::async, + [out]{ + write_db_value(NULL, "LiveParameters", out.c_str(), out.length()); + }); } } + delete msg; } } - zmq_close(controls_state_sock); - zmq_close(sensor_events_sock); - zmq_close(camera_odometry_sock); - zmq_close(live_parameters_sock_raw); + delete live_parameters_sock; + delete controls_state_sock; + delete camera_odometry_sock; + delete sensor_events_sock; + delete poller; + delete c; + return 0; } diff --git a/selfdrive/locationd/test/ublox.py b/selfdrive/locationd/test/ublox.py index 82d775930142d3..c7a2adf08ec7a8 100644 --- a/selfdrive/locationd/test/ublox.py +++ b/selfdrive/locationd/test/ublox.py @@ -720,12 +720,11 @@ def __init__(self, port, baudrate=115200, timeout=0, panda=False, grey=False): self.dev = PandaSerial(self.panda, 1, self.baudrate) elif grey: - from selfdrive.services import service_list import selfdrive.messaging as messaging class BoarddSerial(): def __init__(self): - self.ubloxRaw = messaging.sub_sock(service_list['ubloxRaw'].port) + self.ubloxRaw = messaging.sub_sock('ubloxRaw') self.buf = "" def read(self, n): diff --git a/selfdrive/locationd/test/ubloxd.py b/selfdrive/locationd/test/ubloxd.py index 409bfc331ce222..91c57119583e9c 100755 --- a/selfdrive/locationd/test/ubloxd.py +++ b/selfdrive/locationd/test/ubloxd.py @@ -10,7 +10,6 @@ from cereal import log from common import realtime import selfdrive.messaging as messaging -from selfdrive.services import service_list from selfdrive.locationd.test.ephemeris import EphemerisData, GET_FIELD_U panda = os.getenv("PANDA") is not None # panda directly connected @@ -270,8 +269,8 @@ def main(gctx=None): nav_frame_buffer[0][i] = {} - gpsLocationExternal = messaging.pub_sock(service_list['gpsLocationExternal'].port) - ubloxGnss = messaging.pub_sock(service_list['ubloxGnss'].port) + gpsLocationExternal = messaging.pub_sock('gpsLocationExternal') + ubloxGnss = messaging.pub_sock('ubloxGnss') dev = init_reader() while True: diff --git a/selfdrive/locationd/test/ubloxd_easy.py b/selfdrive/locationd/test/ubloxd_easy.py index b936badd57bb4d..0753789fbad974 100755 --- a/selfdrive/locationd/test/ubloxd_easy.py +++ b/selfdrive/locationd/test/ubloxd_easy.py @@ -6,7 +6,6 @@ from selfdrive.locationd.test.ubloxd import gen_raw, gen_solution import zmq import selfdrive.messaging as messaging -from selfdrive.services import service_list unlogger = os.getenv("UNLOGGER") is not None # debug prints @@ -14,10 +13,10 @@ def main(gctx=None): poller = zmq.Poller() - gpsLocationExternal = messaging.pub_sock(service_list['gpsLocationExternal'].port) - ubloxGnss = messaging.pub_sock(service_list['ubloxGnss'].port) + gpsLocationExternal = messaging.pub_sock('gpsLocationExternal') + ubloxGnss = messaging.pub_sock('ubloxGnss') - # ubloxRaw = messaging.sub_sock(service_list['ubloxRaw'].port, poller) + # ubloxRaw = messaging.sub_sock('ubloxRaw', poller) # buffer with all the messages that still need to be input into the kalman while 1: diff --git a/selfdrive/locationd/ublox_msg.cc b/selfdrive/locationd/ublox_msg.cc index ef523b8870e4fc..ae78eb719222e5 100644 --- a/selfdrive/locationd/ublox_msg.cc +++ b/selfdrive/locationd/ublox_msg.cc @@ -16,7 +16,6 @@ #include #include -#include #include #include "cereal/gen/cpp/log.capnp.h" diff --git a/selfdrive/locationd/ublox_msg.h b/selfdrive/locationd/ublox_msg.h index c7860f14cf4e5a..eca6186d4a6c09 100644 --- a/selfdrive/locationd/ublox_msg.h +++ b/selfdrive/locationd/ublox_msg.h @@ -1,6 +1,7 @@ #pragma once #include +#include "messaging.hpp" #define min(x, y) ((x) <= (y) ? (x) : (y)) @@ -144,6 +145,6 @@ namespace ublox { } -typedef int (*poll_ubloxraw_msg_func)(void *gpsLocationExternal, void *ubloxGnss, void *subscriber, zmq_msg_t *msg); -typedef int (*send_gps_event_func)(uint8_t msg_cls, uint8_t msg_id, void *s, const void *buf, size_t len, int flags); +typedef Message * (*poll_ubloxraw_msg_func)(Poller *poller); +typedef int (*send_gps_event_func)(PubSocket *s, const void *buf, size_t len); int ubloxd_main(poll_ubloxraw_msg_func poll_func, send_gps_event_func send_func); diff --git a/selfdrive/locationd/ubloxd.cc b/selfdrive/locationd/ubloxd.cc index 82853f132858c8..2c28f142286b8c 100644 --- a/selfdrive/locationd/ubloxd.cc +++ b/selfdrive/locationd/ubloxd.cc @@ -15,7 +15,7 @@ #include #include -#include +#include "messaging.hpp" #include #include "cereal/gen/cpp/log.capnp.h" @@ -27,17 +27,19 @@ const long ZMQ_POLL_TIMEOUT = 1000; // In miliseconds -int poll_ubloxraw_msg(void *gpsLocationExternal, void *ubloxGnss, void *subscriber, zmq_msg_t *msg) { - int err; - zmq_pollitem_t item = {.socket = subscriber, .events = ZMQ_POLLIN}; - err = zmq_poll (&item, 1, ZMQ_POLL_TIMEOUT); - if(err <= 0) - return err; - return zmq_msg_recv(msg, subscriber, 0); +Message * poll_ubloxraw_msg(Poller * poller) { + auto p = poller->poll(ZMQ_POLL_TIMEOUT); + + if (p.size()) { + return p[0]->receive(); + } else { + return NULL; + } } -int send_gps_event(uint8_t msg_cls, uint8_t msg_id, void *s, const void *buf, size_t len, int flags) { - return zmq_send(s, buf, len, flags); + +int send_gps_event(PubSocket *s, const void *buf, size_t len) { + return s->send((char*)buf, len); } int main() { diff --git a/selfdrive/locationd/ubloxd_main.cc b/selfdrive/locationd/ubloxd_main.cc index df3b3aa8bcf571..d87942d8a1789e 100644 --- a/selfdrive/locationd/ubloxd_main.cc +++ b/selfdrive/locationd/ubloxd_main.cc @@ -15,7 +15,7 @@ #include #include -#include +#include "messaging.hpp" #include #include "cereal/gen/cpp/log.capnp.h" @@ -39,30 +39,24 @@ int ubloxd_main(poll_ubloxraw_msg_func poll_func, send_gps_event_func send_func) signal(SIGTERM, (sighandler_t) set_do_exit); UbloxMsgParser parser; - void *context = zmq_ctx_new(); - void *gpsLocationExternal = zmq_socket(context, ZMQ_PUB); - zmq_bind(gpsLocationExternal, "tcp://*:8032"); - void *ubloxGnss = zmq_socket(context, ZMQ_PUB); - zmq_bind(ubloxGnss, "tcp://*:8033"); - // ubloxRaw = 8042 - void *subscriber = zmq_socket(context, ZMQ_SUB); - zmq_setsockopt(subscriber, ZMQ_SUBSCRIBE, "", 0); - zmq_connect(subscriber, "tcp://127.0.0.1:8042"); + + Context * c = Context::create(); + PubSocket * gpsLocationExternal = PubSocket::create(c, "gpsLocationExternal"); + PubSocket * ubloxGnss = PubSocket::create(c, "ubloxGnss"); + SubSocket * ubloxRaw = SubSocket::create(c, "ubloxRaw"); + Poller * poller = Poller::create({ubloxRaw}); + + while (!do_exit) { - zmq_msg_t msg; - zmq_msg_init(&msg); - int err = poll_func(gpsLocationExternal, ubloxGnss, subscriber, &msg); - if(err < 0) { - LOGE_100("zmq_poll error %s in %s", strerror(errno ), __FUNCTION__); - break; - } else if(err == 0) { - continue; - } - // format for board, make copy due to alignment issues, will be freed on out of scope - auto amsg = kj::heapArray((zmq_msg_size(&msg) / sizeof(capnp::word)) + 1); - memcpy(amsg.begin(), zmq_msg_data(&msg), zmq_msg_size(&msg)); + Message * msg = poll_func(poller); + if (msg == NULL) continue; + + auto amsg = kj::heapArray((msg->getSize() / sizeof(capnp::word)) + 1); + memcpy(amsg.begin(), msg->getData(), msg->getSize()); + capnp::FlatArrayMessageReader cmsg(amsg); cereal::Event::Reader event = cmsg.getRoot(); + const uint8_t *data = event.getUbloxRaw().begin(); size_t len = event.getUbloxRaw().size(); size_t bytes_consumed = 0; @@ -76,7 +70,7 @@ int ubloxd_main(poll_ubloxraw_msg_func poll_func, send_gps_event_func send_func) auto words = parser.gen_solution(); if(words.size() > 0) { auto bytes = words.asBytes(); - send_func(parser.msg_class(), parser.msg_id(), gpsLocationExternal, bytes.begin(), bytes.size(), 0); + send_func(gpsLocationExternal, bytes.begin(), bytes.size()); } } else LOGW("Unknown nav msg id: 0x%02X", parser.msg_id()); @@ -86,14 +80,14 @@ int ubloxd_main(poll_ubloxraw_msg_func poll_func, send_gps_event_func send_func) auto words = parser.gen_raw(); if(words.size() > 0) { auto bytes = words.asBytes(); - send_func(parser.msg_class(), parser.msg_id(), ubloxGnss, bytes.begin(), bytes.size(), 0); + send_func(ubloxGnss, bytes.begin(), bytes.size()); } } else if(parser.msg_id() == MSG_RXM_SFRBX) { //LOGD("MSG_RXM_SFRBX"); auto words = parser.gen_nav_data(); if(words.size() > 0) { auto bytes = words.asBytes(); - send_func(parser.msg_class(), parser.msg_id(), ubloxGnss, bytes.begin(), bytes.size(), 0); + send_func(ubloxGnss, bytes.begin(), bytes.size()); } } else LOGW("Unknown rxm msg id: 0x%02X", parser.msg_id()); @@ -103,11 +97,14 @@ int ubloxd_main(poll_ubloxraw_msg_func poll_func, send_gps_event_func send_func) } bytes_consumed += bytes_consumed_this_time; } - zmq_msg_close(&msg); + delete msg; } - zmq_close(subscriber); - zmq_close(gpsLocationExternal); - zmq_close(ubloxGnss); - zmq_ctx_destroy(context); + + delete poller; + delete ubloxRaw; + delete ubloxGnss; + delete gpsLocationExternal; + delete c; + return 0; } diff --git a/selfdrive/locationd/ubloxd_test.cc b/selfdrive/locationd/ubloxd_test.cc index a1395fa5960d13..68fe6351ea6660 100644 --- a/selfdrive/locationd/ubloxd_test.cc +++ b/selfdrive/locationd/ubloxd_test.cc @@ -16,7 +16,8 @@ #include #include -#include +#include "messaging.hpp" +#include "impl_zmq.hpp" #include #include "cereal/gen/cpp/log.capnp.h" @@ -27,6 +28,7 @@ #include "ublox_msg.h" using namespace ublox; +extern volatile sig_atomic_t do_exit; void write_file(std::string fpath, uint8_t *data, int len) { FILE* f = fopen(fpath.c_str(), "wb"); @@ -43,40 +45,37 @@ static size_t consumed = 0U; static uint8_t *data = NULL; static int save_idx = 0; static std::string prefix; -static void *gps_sock, *ublox_gnss_sock; -int poll_ubloxraw_msg(void *gpsLocationExternal, void *ubloxGnss, void *subscriber, zmq_msg_t *msg) { - gps_sock = gpsLocationExternal; - ublox_gnss_sock = ubloxGnss; +Message * poll_ubloxraw_msg(Poller * poller) { + assert(poller); + size_t consuming = min(len - consumed, 128); if(consumed < len) { // create message capnp::MallocMessageBuilder msg_builder; cereal::Event::Builder event = msg_builder.initRoot(); event.setLogMonoTime(nanos_since_boot()); + auto ublox_raw = event.initUbloxRaw(consuming); memcpy(ublox_raw.begin(), (void *)(data + consumed), consuming); + auto words = capnp::messageToFlatArray(msg_builder); auto bytes = words.asBytes(); - zmq_msg_init_size (msg, bytes.size()); - memcpy (zmq_msg_data(msg), (void *)bytes.begin(), bytes.size()); + + Message * msg = new ZMQMessage(); + msg->init((char*)bytes.begin(), bytes.size()); consumed += consuming; - return 1; - } else - return -1; + return msg; + } else { + do_exit = 1; + return NULL; + } } -int send_gps_event(uint8_t msg_cls, uint8_t msg_id, void *s, const void *buf, size_t len, int flags) { - if(msg_cls == CLASS_NAV && msg_id == MSG_NAV_PVT) - assert(s == gps_sock); - else if(msg_cls == CLASS_RXM && msg_id == MSG_RXM_RAW) - assert(s == ublox_gnss_sock); - else if(msg_cls == CLASS_RXM && msg_id == MSG_RXM_SFRBX) - assert(s == ublox_gnss_sock); - else - assert(0); +int send_gps_event(PubSocket *s, const void *buf, size_t len) { + assert(s); write_file(prefix + "/" + std::to_string(save_idx), (uint8_t *)buf, len); - save_idx ++; + save_idx++; return len; } diff --git a/selfdrive/logcatd/Makefile b/selfdrive/logcatd/Makefile index fff9220dd303a0..c1a3ef979e7eb6 100644 --- a/selfdrive/logcatd/Makefile +++ b/selfdrive/logcatd/Makefile @@ -14,12 +14,14 @@ WARN_FLAGS = -Werror=implicit-function-declaration \ CFLAGS = -std=gnu11 -g -fPIC -O2 $(WARN_FLAGS) CXXFLAGS = -std=c++11 -g -fPIC -O2 $(WARN_FLAGS) -ZMQ_LIBS = -l:libczmq.a -l:libzmq.a + +MESSAGING_FLAGS = -I$(BASEDIR)/selfdrive/messaging +MESSAGING_LIBS = $(BASEDIR)/selfdrive/messaging/messaging.a ifeq ($(ARCH),aarch64) CFLAGS += -mcpu=cortex-a57 CXXFLAGS += -mcpu=cortex-a57 -ZMQ_LIBS += -lgnustl_shared +EXTRA_LIBS += -lgnustl_shared endif @@ -33,11 +35,11 @@ OBJS = logcatd.o \ DEPS := $(OBJS:.o=.d) -logcatd: $(OBJS) +logcatd: $(OBJS) $(MESSAGING_LIBS) @echo "[ LINK ] $@" $(CXX) -fPIC -o '$@' $^ \ $(CEREAL_LIBS) \ - $(ZMQ_LIBS) \ + $(EXTRA_LIBS) \ -llog %.o: %.cc @@ -45,7 +47,7 @@ logcatd: $(OBJS) $(CXX) $(CXXFLAGS) \ -I$(PHONELIBS)/android_system_core/include \ $(CEREAL_CXXFLAGS) \ - $(ZMQ_FLAGS) \ + $(MESSAGING_FLAGS) \ -I../ \ -I../../ \ -c -o '$@' '$<' diff --git a/selfdrive/logcatd/logcatd.cc b/selfdrive/logcatd/logcatd.cc index 637c5e6c0a47ac..9e5707c29fc6e1 100644 --- a/selfdrive/logcatd/logcatd.cc +++ b/selfdrive/logcatd/logcatd.cc @@ -7,10 +7,10 @@ #include #include -#include #include #include "common/timing.h" #include "cereal/gen/cpp/log.capnp.h" +#include "messaging.hpp" int main() { int err; @@ -28,10 +28,8 @@ int main() { // struct logger *kernel_logger = android_logger_open(logger_list, LOG_ID_KERNEL); // assert(kernel_logger); - void *context = zmq_ctx_new(); - void *publisher = zmq_socket(context, ZMQ_PUB); - err = zmq_bind(publisher, "tcp://*:8020"); - assert(err == 0); + Context * c = Context::create(); + PubSocket * androidLog = PubSocket::create(c, "androidLog"); while (1) { log_msg log_msg; @@ -60,10 +58,13 @@ int main() { auto words = capnp::messageToFlatArray(msg); auto bytes = words.asBytes(); - zmq_send(publisher, bytes.begin(), bytes.size(), 0); + androidLog->send((char*)bytes.begin(), bytes.size()); } android_logger_list_close(logger_list); + delete c; + delete androidLog; + return 0; } diff --git a/selfdrive/loggerd/build_from_src.mk b/selfdrive/loggerd/build_from_src.mk index 47f4f9b265fa7a..90db118bc977b9 100644 --- a/selfdrive/loggerd/build_from_src.mk +++ b/selfdrive/loggerd/build_from_src.mk @@ -24,6 +24,9 @@ CXXFLAGS = -std=c++11 -g -fPIC -O2 $(WARN_FLAGS) \ ZMQ_LIBS = -l:libczmq.a -l:libzmq.a +MESSAGING_FLAGS = -I$(BASEDIR)/selfdrive/messaging +MESSAGING_LIBS = $(BASEDIR)/selfdrive/messaging/messaging.a + ifeq ($(ARCH),aarch64) CFLAGS += -mcpu=cortex-a57 CXXFLAGS += -mcpu=cortex-a57 @@ -78,12 +81,12 @@ YAML_LIBS = $(PHONELIBS)/yaml-cpp/x64/lib/libyaml-cpp.a else OBJS += encoder.o \ raw_logger.o -EXTRA_LIBS = -lcutils -llog +EXTRA_LIBS = -lcutils -llog -lgnustl_shared endif DEPS := $(OBJS:.o=.d) -loggerd: $(OBJS) +loggerd: $(OBJS) $(MESSAGING_LIBS) @echo "[ LINK ] $@" $(CXX) -fPIC -o '$@' $^ \ $(LIBYUV_LIBS) \ @@ -104,6 +107,7 @@ loggerd: $(OBJS) $(CEREAL_CXXFLAGS) \ $(LIBYUV_FLAGS) \ $(ZMQ_FLAGS) \ + $(MESSAGING_FLAGS) \ $(OPENMAX_FLAGS) \ $(YAML_FLAGS) \ $(BZIP_FLAGS) \ diff --git a/selfdrive/loggerd/encoder.c b/selfdrive/loggerd/encoder.c index 1b85ad263deb9d..747c7a1957f06a 100644 --- a/selfdrive/loggerd/encoder.c +++ b/selfdrive/loggerd/encoder.c @@ -27,7 +27,6 @@ #define ALOG(...) __android_log_print(ANDROID_LOG_VERBOSE, "omxapp", ##__VA_ARGS__) // encoder: lossey codec using hardware hevc - static void wait_for_state(EncoderState *s, OMX_STATETYPE state) { pthread_mutex_lock(&s->state_lock); while (s->state != state) { @@ -60,7 +59,7 @@ static OMX_ERRORTYPE event_handler(OMX_HANDLETYPE component, OMX_PTR app_data, O } pthread_mutex_unlock(&s->state_lock); - + return OMX_ErrorNone; } @@ -108,7 +107,7 @@ static const char* omx_color_fomat_name(uint32_t format) { case OMX_COLOR_Format16bitBGR565: return "OMX_COLOR_Format16bitBGR565"; case OMX_COLOR_Format18bitRGB666: return "OMX_COLOR_Format18bitRGB666"; case OMX_COLOR_Format18bitARGB1665: return "OMX_COLOR_Format18bitARGB1665"; - case OMX_COLOR_Format19bitARGB1666: return "OMX_COLOR_Format19bitARGB1666"; + case OMX_COLOR_Format19bitARGB1666: return "OMX_COLOR_Format19bitARGB1666"; case OMX_COLOR_Format24bitRGB888: return "OMX_COLOR_Format24bitRGB888"; case OMX_COLOR_Format24bitBGR888: return "OMX_COLOR_Format24bitBGR888"; case OMX_COLOR_Format24bitARGB1887: return "OMX_COLOR_Format24bitARGB1887"; @@ -131,11 +130,11 @@ static const char* omx_color_fomat_name(uint32_t format) { case OMX_COLOR_FormatRawBayer8bit: return "OMX_COLOR_FormatRawBayer8bit"; case OMX_COLOR_FormatRawBayer10bit: return "OMX_COLOR_FormatRawBayer10bit"; case OMX_COLOR_FormatRawBayer8bitcompressed: return "OMX_COLOR_FormatRawBayer8bitcompressed"; - case OMX_COLOR_FormatL2: return "OMX_COLOR_FormatL2"; - case OMX_COLOR_FormatL4: return "OMX_COLOR_FormatL4"; - case OMX_COLOR_FormatL8: return "OMX_COLOR_FormatL8"; - case OMX_COLOR_FormatL16: return "OMX_COLOR_FormatL16"; - case OMX_COLOR_FormatL24: return "OMX_COLOR_FormatL24"; + case OMX_COLOR_FormatL2: return "OMX_COLOR_FormatL2"; + case OMX_COLOR_FormatL4: return "OMX_COLOR_FormatL4"; + case OMX_COLOR_FormatL8: return "OMX_COLOR_FormatL8"; + case OMX_COLOR_FormatL16: return "OMX_COLOR_FormatL16"; + case OMX_COLOR_FormatL24: return "OMX_COLOR_FormatL24"; case OMX_COLOR_FormatL32: return "OMX_COLOR_FormatL32"; case OMX_COLOR_FormatYUV420PackedSemiPlanar: return "OMX_COLOR_FormatYUV420PackedSemiPlanar"; case OMX_COLOR_FormatYUV422PackedSemiPlanar: return "OMX_COLOR_FormatYUV422PackedSemiPlanar"; @@ -165,8 +164,7 @@ static const char* omx_color_fomat_name(uint32_t format) { } } - -void encoder_init(EncoderState *s, const char* filename, int width, int height, int fps, int bitrate) { +void encoder_init(EncoderState *s, const char* filename, int width, int height, int fps, int bitrate, bool h265, bool downscale) { int err; memset(s, 0, sizeof(*s)); @@ -176,6 +174,17 @@ void encoder_init(EncoderState *s, const char* filename, int width, int height, s->fps = fps; mutex_init_reentrant(&s->lock); + if (!h265) { + s->remuxing = true; + } + + if (downscale) { + s->downscale = true; + s->y_ptr2 = malloc(s->width*s->height); + s->u_ptr2 = malloc(s->width*s->height/4); + s->v_ptr2 = malloc(s->width*s->height/4); + } + s->segment = -1; s->state = OMX_StateLoaded; @@ -188,10 +197,13 @@ void encoder_init(EncoderState *s, const char* filename, int width, int height, pthread_mutex_init(&s->state_lock, NULL); pthread_cond_init(&s->state_cv, NULL); - err = OMX_GetHandle(&s->handle, (OMX_STRING)"OMX.qcom.video.encoder.hevc", - s, &omx_callbacks); - // err = OMX_GetHandle(&s->handle, (OMX_STRING)"OMX.qcom.video.encoder.avc", - // s, &omx_callbacks); + if (h265) { + err = OMX_GetHandle(&s->handle, (OMX_STRING)"OMX.qcom.video.encoder.hevc", + s, &omx_callbacks); + } else { + err = OMX_GetHandle(&s->handle, (OMX_STRING)"OMX.qcom.video.encoder.avc", + s, &omx_callbacks); + } assert(err == OMX_ErrorNone); // printf("handle: %p\n", s->handle); @@ -204,7 +216,6 @@ void encoder_init(EncoderState *s, const char* filename, int width, int height, (OMX_PTR) &in_port); assert(err == OMX_ErrorNone); - in_port.format.video.nFrameWidth = s->width; in_port.format.video.nFrameHeight = s->height; in_port.format.video.nStride = VENUS_Y_STRIDE(COLOR_FMT_NV12, s->width); @@ -237,45 +248,26 @@ void encoder_init(EncoderState *s, const char* filename, int width, int height, err = OMX_GetParameter(s->handle, OMX_IndexParamPortDefinition, (OMX_PTR)&out_port); assert(err == OMX_ErrorNone); - out_port.format.video.nFrameWidth = s->width; out_port.format.video.nFrameHeight = s->height; out_port.format.video.xFramerate = 0; out_port.format.video.nBitrate = bitrate; - out_port.format.video.eCompressionFormat = OMX_VIDEO_CodingHEVC; - // out_port.format.video.eCompressionFormat = OMX_VIDEO_CodingAVC; + if (h265) { + out_port.format.video.eCompressionFormat = OMX_VIDEO_CodingHEVC; + } else { + out_port.format.video.eCompressionFormat = OMX_VIDEO_CodingAVC; + } out_port.format.video.eColorFormat = OMX_COLOR_FormatUnused; err = OMX_SetParameter(s->handle, OMX_IndexParamPortDefinition, (OMX_PTR) &out_port); assert(err == OMX_ErrorNone); - err = OMX_GetParameter(s->handle, OMX_IndexParamPortDefinition, (OMX_PTR) &out_port); assert(err == OMX_ErrorNone); s->num_out_bufs = out_port.nBufferCountActual; - // printf("out buf num %d\n", out_port.nBufferSize); - - - // setup HEVC - - OMX_VIDEO_PARAM_HEVCTYPE hecv_type = {0}; - hecv_type.nSize = sizeof(hecv_type); - hecv_type.nPortIndex = (OMX_U32) PORT_INDEX_OUT; - err = OMX_GetParameter(s->handle, (OMX_INDEXTYPE)OMX_IndexParamVideoHevc, - (OMX_PTR) &hecv_type); - assert(err == OMX_ErrorNone); - - hecv_type.eProfile = OMX_VIDEO_HEVCProfileMain; - hecv_type.eLevel = OMX_VIDEO_HEVCHighTierLevel5; - - err = OMX_SetParameter(s->handle, (OMX_INDEXTYPE)OMX_IndexParamVideoHevc, - (OMX_PTR) &hecv_type); - assert(err == OMX_ErrorNone); - - OMX_VIDEO_PARAM_BITRATETYPE bitrate_type = {0}; bitrate_type.nSize = sizeof(bitrate_type); bitrate_type.nPortIndex = (OMX_U32) PORT_INDEX_OUT; @@ -290,42 +282,41 @@ void encoder_init(EncoderState *s, const char* filename, int width, int height, (OMX_PTR) &bitrate_type); assert(err == OMX_ErrorNone); + if (h265) { + // setup HEVC + OMX_VIDEO_PARAM_HEVCTYPE hecv_type = {0}; + hecv_type.nSize = sizeof(hecv_type); + hecv_type.nPortIndex = (OMX_U32) PORT_INDEX_OUT; + err = OMX_GetParameter(s->handle, (OMX_INDEXTYPE)OMX_IndexParamVideoHevc, + (OMX_PTR) &hecv_type); + assert(err == OMX_ErrorNone); -#if 0 - // setup h264 - OMX_VIDEO_PARAM_BITRATETYPE bitrate_type = {0}; - bitrate_type.nSize = sizeof(bitrate_type); - bitrate_type.nPortIndex = (OMX_U32) PORT_INDEX_OUT; - err = OMX_GetParameter(s->handle, OMX_IndexParamVideoBitrate, - (OMX_PTR) &bitrate_type); - assert(err == OMX_ErrorNone); - - bitrate_type.eControlRate = OMX_Video_ControlRateVariable; - bitrate_type.nTargetBitrate = 2000000; - - err = OMX_SetParameter(s->handle, OMX_IndexParamVideoBitrate, - (OMX_PTR) &bitrate_type); - assert(err == OMX_ErrorNone); - + hecv_type.eProfile = OMX_VIDEO_HEVCProfileMain; + hecv_type.eLevel = OMX_VIDEO_HEVCHighTierLevel5; - OMX_VIDEO_PARAM_AVCTYPE avc = { 0 }; - avc.nSize = sizeof(avc); - avc.nPortIndex = (OMX_U32) PORT_INDEX_OUT; - err = OMX_GetParameter(s->handle, OMX_IndexParamVideoAvc, &avc); - assert(err == OMX_ErrorNone); + err = OMX_SetParameter(s->handle, (OMX_INDEXTYPE)OMX_IndexParamVideoHevc, + (OMX_PTR) &hecv_type); + assert(err == OMX_ErrorNone); + } else { + // setup h264 + OMX_VIDEO_PARAM_AVCTYPE avc = { 0 }; + avc.nSize = sizeof(avc); + avc.nPortIndex = (OMX_U32) PORT_INDEX_OUT; + err = OMX_GetParameter(s->handle, OMX_IndexParamVideoAvc, &avc); + assert(err == OMX_ErrorNone); - avc.nBFrames = 0; - avc.nPFrames = 20;//avctx->gop_size - 1; + avc.nBFrames = 0; + avc.nPFrames = 15; - avc.eProfile = OMX_VIDEO_AVCProfileBaseline; - avc.eLevel = OMX_VIDEO_AVCLevel31; + avc.eProfile = OMX_VIDEO_AVCProfileBaseline; + avc.eLevel = OMX_VIDEO_AVCLevel31; - avc.nAllowedPictureTypes |= OMX_VIDEO_PictureTypeB; - avc.eLoopFilterMode = OMX_VIDEO_AVCLoopFilterEnable; + avc.nAllowedPictureTypes |= OMX_VIDEO_PictureTypeB; + avc.eLoopFilterMode = OMX_VIDEO_AVCLoopFilterEnable; - err = OMX_SetParameter(s->handle, OMX_IndexParamVideoAvc, &avc); - assert(err == OMX_ErrorNone); -#endif + err = OMX_SetParameter(s->handle, OMX_IndexParamVideoAvc, &avc); + assert(err == OMX_ErrorNone); + } // for (int i = 0; ; i++) { @@ -389,7 +380,6 @@ void encoder_init(EncoderState *s, const char* filename, int width, int height, static void handle_out_buf(EncoderState *s, OMX_BUFFERHEADERTYPE *out_buf) { int err; - uint8_t *buf_data = out_buf->pBuffer + out_buf->nOffset; if (out_buf->nFlags & OMX_BUFFERFLAG_CODECCONFIG) { @@ -410,20 +400,59 @@ static void handle_out_buf(EncoderState *s, OMX_BUFFERHEADERTYPE *out_buf) { } if (s->of) { - // printf("write %d flags 0x%x\n", out_buf->nFilledLen, out_buf->nFlags); + //printf("write %d flags 0x%x\n", out_buf->nFilledLen, out_buf->nFlags); fwrite(buf_data, out_buf->nFilledLen, 1, s->of); } + if (s->remuxing) { + if (!s->wrote_codec_config && s->codec_config_len > 0) { + if (s->codec_ctx->extradata_size < s->codec_config_len) { + s->codec_ctx->extradata = realloc(s->codec_ctx->extradata, s->codec_config_len + AV_INPUT_BUFFER_PADDING_SIZE); + } + s->codec_ctx->extradata_size = s->codec_config_len; + memcpy(s->codec_ctx->extradata, s->codec_config, s->codec_config_len); + memset(s->codec_ctx->extradata + s->codec_ctx->extradata_size, 0, AV_INPUT_BUFFER_PADDING_SIZE); + + err = avcodec_parameters_from_context(s->out_stream->codecpar, s->codec_ctx); + assert(err >= 0); + err = avformat_write_header(s->ofmt_ctx, NULL); + assert(err >= 0); + + s->wrote_codec_config = true; + } + + if (out_buf->nTimeStamp > 0) { + // input timestamps are in microseconds + AVRational in_timebase = {1, 1000000}; + + AVPacket pkt; + av_init_packet(&pkt); + pkt.data = buf_data; + pkt.size = out_buf->nFilledLen; + pkt.pts = pkt.dts = av_rescale_q_rnd(out_buf->nTimeStamp, in_timebase, s->ofmt_ctx->streams[0]->time_base, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX); + pkt.duration = av_rescale_q(50*1000, in_timebase, s->ofmt_ctx->streams[0]->time_base); + + if (out_buf->nFlags & OMX_BUFFERFLAG_SYNCFRAME) { + pkt.flags |= AV_PKT_FLAG_KEY; + } + + err = av_write_frame(s->ofmt_ctx, &pkt); + if (err < 0) { LOGW("ts encoder write issue"); } + + av_free_packet(&pkt); + } + } + // give omx back the buffer err = OMX_FillThisBuffer(s->handle, out_buf); assert(err == OMX_ErrorNone); } -int encoder_encode_frame(EncoderState *s, uint64_t ts, +int encoder_encode_frame(EncoderState *s, const uint8_t *y_ptr, const uint8_t *u_ptr, const uint8_t *v_ptr, + int in_width, int in_height, int *frame_segment, VIPCBufExtra *extra) { int err; - pthread_mutex_lock(&s->lock); if (s->opening) { @@ -456,10 +485,24 @@ int encoder_encode_frame(EncoderState *s, uint64_t ts, uint8_t *in_y_ptr = in_buf_ptr; int in_y_stride = VENUS_Y_STRIDE(COLOR_FMT_NV12, s->width); - int in_uv_stride = VENUS_UV_STRIDE(COLOR_FMT_NV12, s->width); + int in_uv_stride = VENUS_UV_STRIDE(COLOR_FMT_NV12, s->width); // uint8_t *in_uv_ptr = in_buf_ptr + (s->width * s->height); uint8_t *in_uv_ptr = in_buf_ptr + (in_y_stride * VENUS_Y_SCANLINES(COLOR_FMT_NV12, s->height)); + if (s->downscale) { + I420Scale(y_ptr, in_width, + u_ptr, in_width/2, + v_ptr, in_width/2, + in_width, in_height, + s->y_ptr2, s->width, + s->u_ptr2, s->width/2, + s->v_ptr2, s->width/2, + s->width, s->height, + kFilterNone); + y_ptr = s->y_ptr2; + u_ptr = s->u_ptr2; + v_ptr = s->v_ptr2; + } err = I420ToNV12(y_ptr, s->width, u_ptr, s->width/2, v_ptr, s->width/2, @@ -472,7 +515,7 @@ int encoder_encode_frame(EncoderState *s, uint64_t ts, in_buf->nFilledLen = VENUS_BUFFER_SIZE(COLOR_FMT_NV12, s->width, s->height); in_buf->nFlags = OMX_BUFFERFLAG_ENDOFFRAME; in_buf->nOffset = 0; - in_buf->nTimeStamp = extra->timestamp_eof/1000LL; + in_buf->nTimeStamp = extra->timestamp_eof/1000LL; // OMX_TICKS, in microseconds err = OMX_EmptyThisBuffer(s->handle, in_buf); assert(err == OMX_ErrorNone); @@ -508,12 +551,39 @@ void encoder_open(EncoderState *s, const char* path) { pthread_mutex_lock(&s->lock); - snprintf(s->vid_path, sizeof(s->vid_path), "%s/%s.hevc", path, s->filename); - s->of = fopen(s->vid_path, "wb"); - assert(s->of); + snprintf(s->vid_path, sizeof(s->vid_path), "%s/%s", path, s->filename); + + if (s->remuxing) { + avformat_alloc_output_context2(&s->ofmt_ctx, NULL, NULL, s->vid_path); + assert(s->ofmt_ctx); + + s->out_stream = avformat_new_stream(s->ofmt_ctx, NULL); + assert(s->out_stream); + + // set codec correctly + av_register_all(); + + AVCodec *codec = NULL; + codec = avcodec_find_encoder(AV_CODEC_ID_H264); + assert(codec); + + s->codec_ctx = avcodec_alloc_context3(codec); + assert(s->codec_ctx); + s->codec_ctx->width = s->width; + s->codec_ctx->height = s->height; + s->codec_ctx->pix_fmt = AV_PIX_FMT_YUV420P; + s->codec_ctx->time_base = (AVRational){ 1, s->fps }; - if (s->codec_config_len > 0) { - fwrite(s->codec_config, s->codec_config_len, 1, s->of); + err = avio_open(&s->ofmt_ctx->pb, s->vid_path, AVIO_FLAG_WRITE); + assert(err >= 0); + + s->wrote_codec_config = false; + } else { + s->of = fopen(s->vid_path, "wb"); + assert(s->of); + if (s->codec_config_len > 0) { + fwrite(s->codec_config, s->codec_config_len, 1, s->of); + } } // create camera lock file @@ -558,7 +628,13 @@ void encoder_close(EncoderState *s) { s->dirty = false; } - fclose(s->of); + if (s->remuxing) { + av_write_trailer(s->ofmt_ctx); + avio_closep(&s->ofmt_ctx->pb); + avformat_free_context(s->ofmt_ctx); + } else { + fclose(s->of); + } unlink(s->lock_path); } s->open = false; @@ -612,6 +688,12 @@ void encoder_destroy(EncoderState *s) { err = OMX_FreeHandle(s->handle); assert(err == OMX_ErrorNone); + + if (s->downscale) { + free(s->y_ptr2); + free(s->u_ptr2); + free(s->v_ptr2); + } } #if 0 @@ -658,7 +740,7 @@ int main() { memset(inbuf, 0, w*h*3/2); for (int i=0; i<20*3+5; i++) { - + // fread(inbuf, w*h*3/2, 1, infile); uint8_t *tmpy = inbuf; @@ -692,7 +774,7 @@ int main() { encoder_rotate(s, "/sdcard/t2"); for (int i=0; i<20*3+5; i++) { - + // fread(inbuf, w*h*3/2, 1, infile); uint8_t *tmpy = inbuf; diff --git a/selfdrive/loggerd/encoder.h b/selfdrive/loggerd/encoder.h index 617dee28bd4629..18054d20d8254a 100644 --- a/selfdrive/loggerd/encoder.h +++ b/selfdrive/loggerd/encoder.h @@ -8,6 +8,7 @@ #include #include +#include #include "common/cqueue.h" #include "common/visionipc.h" @@ -38,6 +39,7 @@ typedef struct EncoderState { size_t codec_config_len; uint8_t *codec_config; + bool wrote_codec_config; pthread_mutex_t state_lock; pthread_cond_t state_cv; @@ -47,7 +49,7 @@ typedef struct EncoderState { int num_in_bufs; OMX_BUFFERHEADERTYPE** in_buf_headers; - + int num_out_bufs; OMX_BUFFERHEADERTYPE** out_buf_headers; @@ -55,11 +57,22 @@ typedef struct EncoderState { Queue done_out; void *stream_sock_raw; + + AVFormatContext *ofmt_ctx; + AVCodecContext *codec_ctx; + AVStream *out_stream; + bool remuxing; + + void *zmq_ctx; + + bool downscale; + uint8_t *y_ptr2, *u_ptr2, *v_ptr2; } EncoderState; -void encoder_init(EncoderState *s, const char* filename, int width, int height, int fps, int bitrate); -int encoder_encode_frame(EncoderState *s, uint64_t ts, +void encoder_init(EncoderState *s, const char* filename, int width, int height, int fps, int bitrate, bool h265, bool downscale); +int encoder_encode_frame(EncoderState *s, const uint8_t *y_ptr, const uint8_t *u_ptr, const uint8_t *v_ptr, + int in_width, int in_height, int *frame_segment, VIPCBufExtra *extra); void encoder_open(EncoderState *s, const char* path); void encoder_rotate(EncoderState *s, const char* new_path, int new_segment); diff --git a/selfdrive/loggerd/loggerd.cc b/selfdrive/loggerd/loggerd.cc index ec4c1140e1e858..18996353eaa4fe 100644 --- a/selfdrive/loggerd/loggerd.cc +++ b/selfdrive/loggerd/loggerd.cc @@ -36,6 +36,7 @@ #include "common/util.h" #include "logger.h" +#include "messaging.hpp" #ifndef DISABLE_ENCODER @@ -68,7 +69,7 @@ static void set_do_exit(int sig) { do_exit = 1; } struct LoggerdState { - void *ctx; + Context *ctx; LoggerState logger; std::mutex lock; @@ -101,13 +102,13 @@ void encoder_thread(bool is_streaming, bool raw_clips, bool front) { bool encoder_inited = false; EncoderState encoder; + EncoderState encoder_alt; + bool has_encoder_alt = false; int encoder_segment = -1; int cnt = 0; - void *idx_sock = zmq_socket(s.ctx, ZMQ_PUB); - assert(idx_sock); - zmq_bind(idx_sock, front ? "tcp://*:8061" : "tcp://*:8015"); + PubSocket *idx_sock = PubSocket::create(s.ctx, front ? "frontEncodeIdx" : "encodeIdx"); LoggerHandle *lh = NULL; @@ -126,10 +127,15 @@ void encoder_thread(bool is_streaming, bool raw_clips, bool front) { if (!encoder_inited) { LOGD("encoder init %dx%d", buf_info.width, buf_info.height); - encoder_init(&encoder, front ? "dcamera" : "fcamera", buf_info.width, buf_info.height, CAMERA_FPS, front ? 2500000 : 5000000); + encoder_init(&encoder, front ? "dcamera.hevc" : "fcamera.hevc", buf_info.width, buf_info.height, CAMERA_FPS, front ? 2500000 : 5000000, true, false); + if (!front) { + encoder_init(&encoder_alt, "qcamera.ts", 480, 360, CAMERA_FPS, 128000, false, true); + has_encoder_alt = true; + } encoder_inited = true; if (is_streaming) { - encoder.stream_sock_raw = zmq_socket(s.ctx, ZMQ_PUB); + encoder.zmq_ctx = zmq_ctx_new(); + encoder.stream_sock_raw = zmq_socket(encoder.zmq_ctx, ZMQ_PUB); assert(encoder.stream_sock_raw); zmq_bind(encoder.stream_sock_raw, "tcp://*:9002"); } @@ -183,6 +189,9 @@ void encoder_thread(bool is_streaming, bool raw_clips, bool front) { LOG("rotate encoder to %s", s.segment_path); encoder_rotate(&encoder, s.segment_path, s.rotate_segment); + if (has_encoder_alt) { + encoder_rotate(&encoder_alt, s.segment_path, s.rotate_segment); + } if (raw_clips) { rawlogger->Rotate(s.segment_path, s.rotate_segment); @@ -199,8 +208,18 @@ void encoder_thread(bool is_streaming, bool raw_clips, bool front) { { // encode hevc int out_segment = -1; - int out_id = encoder_encode_frame(&encoder, cnt*50000ULL, - y, u, v, &out_segment, &extra); + int out_id = encoder_encode_frame(&encoder, + y, u, v, + buf_info.width, buf_info.height, + &out_segment, &extra); + + if (has_encoder_alt) { + int out_segment_alt = -1; + encoder_encode_frame(&encoder_alt, + y, u, v, + buf_info.width, buf_info.height, + &out_segment_alt, &extra); + } // publish encode index capnp::MallocMessageBuilder msg; @@ -215,7 +234,7 @@ void encoder_thread(bool is_streaming, bool raw_clips, bool front) { auto words = capnp::messageToFlatArray(msg); auto bytes = words.asBytes(); - if (zmq_send(idx_sock, bytes.begin(), bytes.size(), 0) < 0) { + if (idx_sock->send((char*)bytes.begin(), bytes.size()) < 0) { printf("err sending encodeIdx pkt: %s\n", strerror(errno)); } if (lh) { @@ -280,11 +299,19 @@ void encoder_thread(bool is_streaming, bool raw_clips, bool front) { visionstream_destroy(&stream); } + delete idx_sock; + if (encoder_inited) { LOG("encoder destroy"); encoder_close(&encoder); encoder_destroy(&encoder); } + + if (has_encoder_alt) { + LOG("encoder alt destroy"); + encoder_close(&encoder_alt); + encoder_destroy(&encoder_alt); + } } #endif @@ -536,64 +563,32 @@ int main(int argc, char** argv) { signal(SIGINT, (sighandler_t)set_do_exit); signal(SIGTERM, (sighandler_t)set_do_exit); - s.ctx = zmq_ctx_new(); - assert(s.ctx); - - std::set ts_replace_sock; + s.ctx = Context::create(); + Poller * poller = Poller::create(); std::string exe_dir = util::dir_name(util::readlink("/proc/self/exe")); std::string service_list_path = exe_dir + "/../service_list.yaml"; // subscribe to all services - void *frame_sock = NULL; + SubSocket *frame_sock = NULL; + std::vector socks; - // zmq_poll is slow because it has to be careful because the signaling - // fd is edge-triggered. we can be faster by knowing that we're not messing with it - // other than draining and polling - std::vector polls; - std::vector socks; - - std::map qlog_counter; - std::map qlog_freqs; + std::map qlog_counter; + std::map qlog_freqs; YAML::Node service_list = YAML::LoadFile(service_list_path); for (const auto& it : service_list) { auto name = it.first.as(); - int port = it.second[0].as(); bool should_log = it.second[1].as(); int qlog_freq = it.second[3] ? it.second[3].as() : 0; if (should_log) { - void* sock = zmq_socket(s.ctx, ZMQ_SUB); - zmq_setsockopt(sock, ZMQ_SUBSCRIBE, "", 0); - - // make zmq will do exponential backoff from 100ms to 500ms for socket reconnects - int reconnect_ivl = 500; - zmq_setsockopt(sock, ZMQ_RECONNECT_IVL_MAX, &reconnect_ivl, sizeof(reconnect_ivl)); - - std::stringstream ss; - ss << "tcp://"; - if (it.second[4]) { - ss << it.second[4].as(); - ts_replace_sock.insert(sock); - } else{ - ss << "127.0.0.1"; - } - ss << ":" << port; - - zmq_connect(sock, ss.str().c_str()); - - struct pollfd pfd = {0}; - size_t fd_size = sizeof(pfd.fd); - err = zmq_getsockopt(sock, ZMQ_FD, &pfd.fd, &fd_size); - assert(err == 0); - pfd.events = POLLIN; - polls.push_back(pfd); + SubSocket * sock = SubSocket::create(s.ctx, name); + poller->registerSocket(sock); socks.push_back(sock); if (name == "frame") { - LOGD("found frame sock at port %d", port); frame_sock = sock; } @@ -644,32 +639,21 @@ int main(int argc, char** argv) { uint64_t bytes_count = 0; while (!do_exit) { - // err = zmq_poll(polls.data(), polls.size(), 100 * 1000); - err = poll(polls.data(), polls.size(), 100*1000); - if (err < 0) break; - - for (int i=0; ipoll(100 * 1000)){ while (true) { - zmq_msg_t msg; - zmq_msg_init(&msg); - - err = zmq_msg_recv(&msg, socks[i], ZMQ_DONTWAIT); - if (err < 0) { - zmq_msg_close(&msg); + Message * msg = sock->receive(true); + if (msg == NULL){ break; } - uint8_t* data = (uint8_t*)zmq_msg_data(&msg); - size_t len = zmq_msg_size(&msg); + uint8_t* data = (uint8_t*)msg->getData(); + size_t len = msg->getSize(); - if (socks[i] == frame_sock) { - // make copy due to alignment issues, will be freed on out of scope + if (sock == frame_sock) { + // track camera frames to sync to encoder auto amsg = kj::heapArray((len / sizeof(capnp::word)) + 1); memcpy(amsg.begin(), data, len); - // track camera frames to sync to encoder capnp::FlatArrayMessageReader cmsg(amsg); cereal::Event::Reader event = cmsg.getRoot(); if (event.isFrame()) { @@ -680,48 +664,13 @@ int main(int argc, char** argv) { } } - if (ts_replace_sock.find(socks[i]) != ts_replace_sock.end()) { - // get new time - uint64_t current_time = nanos_since_boot(); + logger_log(&s.logger, data, len, qlog_counter[sock] == 0); + delete msg; - // read out the current message - /*auto amsg = kj::heapArray((len / sizeof(capnp::word)) + 1); - memcpy(amsg.begin(), data, len); - capnp::FlatArrayMessageReader cmsg(amsg); - cereal::Event::Reader revent = cmsg.getRoot(); - - // create a copy, ugh - capnp::MallocMessageBuilder msg; - msg.setRoot(revent); - - // replace the timestamp with the current timestamp on the phone - cereal::Event::Builder event = msg.getRoot(); - - // test it's correct - auto twords = capnp::messageToFlatArray(msg); - auto tbytes = twords.asBytes(); - assert(memcmp(data, tbytes.begin(), len) == 0); - - // modify it - event.setLogMonoTime(current_time); - - // put it back - auto words = capnp::messageToFlatArray(msg); - auto bytes = words.asBytes(); - memcpy(data, bytes.begin(), len);*/ - - // binary patching HACK! - assert(memcmp(data+0xC, "\x02\x00\x01\x00", 4) == 0); - memcpy(data+0x10, ¤t_time, sizeof(current_time)); - } - - logger_log(&s.logger, data, len, qlog_counter[socks[i]] == 0); - zmq_msg_close(&msg); - - if (qlog_counter[socks[i]] != -1) { + if (qlog_counter[sock] != -1) { //printf("%p: %d/%d\n", socks[i], qlog_counter[socks[i]], qlog_freqs[socks[i]]); - qlog_counter[socks[i]]++; - qlog_counter[socks[i]] %= qlog_freqs[socks[i]]; + qlog_counter[sock]++; + qlog_counter[sock] %= qlog_freqs[sock]; } bytes_count += len; @@ -753,6 +702,7 @@ int main(int argc, char** argv) { LOGW("joining threads"); s.cv.notify_all(); + #ifndef DISABLE_ENCODER front_encoder_thread_handle.join(); encoder_thread_handle.join(); @@ -766,5 +716,10 @@ int main(int argc, char** argv) { logger_close(&s.logger); + for (auto s : socks){ + delete s; + } + + delete s.ctx; return 0; } diff --git a/selfdrive/loggerd/uploader.py b/selfdrive/loggerd/uploader.py index b4f0e19bf1e4ad..86078437bedfb0 100644 --- a/selfdrive/loggerd/uploader.py +++ b/selfdrive/loggerd/uploader.py @@ -102,7 +102,7 @@ def __init__(self, dongle_id, root): self.last_resp = None self.last_exc = None - self.immediate_priority = {"qlog.bz2": 0} + self.immediate_priority = {"qlog.bz2": 0, "qcamera.ts": 1} self.high_priority = {"rlog.bz2": 0, "fcamera.hevc": 1, "dcamera.hevc": 2} def clean_dirs(self): diff --git a/selfdrive/logmessaged.py b/selfdrive/logmessaged.py index 57e5416aa5f3dd..265152be5db7a7 100755 --- a/selfdrive/logmessaged.py +++ b/selfdrive/logmessaged.py @@ -1,7 +1,6 @@ #!/usr/bin/env python3 import zmq from logentries import LogentriesHandler -from selfdrive.services import service_list import selfdrive.messaging as messaging def main(gctx=None): @@ -16,7 +15,7 @@ def main(gctx=None): sock.bind("ipc:///tmp/logmessage") # and we publish them - pub_sock = messaging.pub_sock(service_list['logMessage'].port) + pub_sock = messaging.pub_sock('logMessage') while True: dat = b''.join(sock.recv_multipart()) diff --git a/selfdrive/manager.py b/selfdrive/manager.py index 24defbc250229f..c2d13f58cccd17 100755 --- a/selfdrive/manager.py +++ b/selfdrive/manager.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3.7 import os +import time import sys import fcntl import errno @@ -63,7 +64,6 @@ def unblock_stdout(): import cereal ThermalStatus = cereal.log.ThermalData.ThermalStatus -from selfdrive.services import service_list from selfdrive.swaglog import cloudlog import selfdrive.messaging as messaging from selfdrive.registration import register @@ -91,14 +91,14 @@ def unblock_stdout(): "ui": ("selfdrive/ui", ["./start.py"]), "calibrationd": "selfdrive.locationd.calibrationd", "paramsd": ("selfdrive/locationd", ["./paramsd"]), - "visiond": ("selfdrive/visiond", ["./visiond"]), + "visiond": ("selfdrive/visiond", ["./start.py"]), "sensord": ("selfdrive/sensord", ["./start_sensord.py"]), "gpsd": ("selfdrive/sensord", ["./start_gpsd.py"]), "updated": "selfdrive.updated", "mapd": ("selfdrive/mapd", ["./mapd.py"]), } daemon_processes = { - "athenad": "selfdrive.athena.athenad", + "manage_athenad": ("selfdrive.athena.manage_athenad", "AthenadPid"), } android_packages = ("ai.comma.plus.offroad", "ai.comma.plus.frame") @@ -159,9 +159,8 @@ def launcher(proc): # rename the process setproctitle(proc) - # terminate the zmq context since we forked - import zmq - zmq.Context.instance().term() + # create now context since we forked + messaging.context = messaging.Context() # exec the process mod.main() @@ -197,8 +196,7 @@ def start_managed_process(name): running[name].start() def start_daemon_process(name, params): - proc = daemon_processes[name] - pid_param = name.capitalize() + 'Pid' + proc, pid_param = daemon_processes[name] pid = params.get(pid_param) if pid is not None: @@ -250,8 +248,14 @@ def kill_managed_process(name): else: running[name].terminate() - # give it 5 seconds to die - running[name].join(5.0) + # Process().join(timeout) will hang due to a python 3 bug: https://bugs.python.org/issue28382 + # We have to poll the exitcode instead + # running[name].join(5.0) + + t = time.time() + while time.time() - t < 5 and running[name].exitcode is None: + time.sleep(0.001) + if running[name].exitcode is None: if name in unkillable_processes: cloudlog.critical("unkillable process %s failed to exit! rebooting in 15 if it doesn't die" % name) @@ -326,7 +330,7 @@ def system(cmd): def manager_thread(): # now loop - thermal_sock = messaging.sub_sock(service_list['thermal'].port) + thermal_sock = messaging.sub_sock('thermal') cloudlog.info("manager start") cloudlog.info({"environ": os.environ}) @@ -381,8 +385,8 @@ def manager_thread(): running_list = [" running %s %s" % (p, running[p]) for p in running] cloudlog.debug('\n'.join(running_list)) - # is this still needed? - if params.get("DoUninstall") == "1": + # Exit main loop when uninstall is needed + if params.get("DoUninstall", encoding='utf8') == "1": break def get_installed_apks(): @@ -559,7 +563,7 @@ def main(): finally: cleanup_all_processes(None, None) - if params.get("DoUninstall") == "1": + if params.get("DoUninstall", encoding='utf8') == "1": uninstall() if __name__ == "__main__": diff --git a/selfdrive/messaging/.gitignore b/selfdrive/messaging/.gitignore new file mode 100644 index 00000000000000..1549b67ca5936e --- /dev/null +++ b/selfdrive/messaging/.gitignore @@ -0,0 +1 @@ +demo diff --git a/selfdrive/messaging/Makefile b/selfdrive/messaging/Makefile new file mode 100644 index 00000000000000..d53e5ece190bee --- /dev/null +++ b/selfdrive/messaging/Makefile @@ -0,0 +1,63 @@ +CXX := clang++ +CC := clang + +BASEDIR = ../.. +PHONELIBS = ../../phonelibs + +CXXFLAGS := -g -O3 -fPIC -std=c++11 -Wall -Wextra -Wshadow -Weffc++ -Wstrict-aliasing -Wpedantic -Werror -MMD -I$(BASEDIR)/selfdrive + +LDLIBS=-lm -lstdc++ -lrt -lpthread + +UNAME_M := $(shell uname -m) + +YAML_FLAGS = -I$(PHONELIBS)/yaml-cpp/include +YAML_LIB = $(abspath $(PHONELIBS)/yaml-cpp/lib/libyaml-cpp.a) + +ifeq ($(UNAME_M),aarch64) + LDFLAGS += -llog -lgnustl_shared + ZMQ_LIBS = /usr/lib/libzmq.a +endif +ifeq ($(UNAME_M),x86_64) + ZMQ_FLAGS = -I$(BASEDIR)/phonelibs/zmq/x64/include + ZMQ_LIBS = $(abspath $(PHONELIBS)/zmq/x64/lib/libzmq.a) + YAML_DIR = $(PHONELIBS)/yaml-cpp/x64/lib/ + YAML_LIB = $(abspath $(PHONELIBS)/yaml-cpp/x64/lib/libyaml-cpp.a) +endif + +ifdef ASAN + CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer + LDFLAGS += -fsanitize=address +endif + +CXXFLAGS += $(ZMQ_FLAGS) $(YAML_FLAGS) + +OBJS := messaging.o impl_zmq.o +DEPS=$(OBJS:.o=.d) + +.PRECIOUS: $(OBJS) +.PHONY: all clean +all: messaging.a messaging_pyx.so + +demo: messaging.a demo.o + $(CC) $(LDFLAGS) $^ $(LDLIBS) -L. -l:messaging.a -o '$@' + +messaging_pyx.so: messaging.a messaging_pyx_setup.py messaging_pyx.pyx messaging.pxd + python3 messaging_pyx_setup.py build_ext --inplace + rm -rf build + rm -f messaging_pyx.cpp + +%.a: $(OBJS) + @echo "[ LINK ] $@" + mkdir -p libs; \ + cd libs; \ + ar -x $(ZMQ_LIBS); \ + ar -x $(YAML_LIB); + + ar rcsD '$@' $^ libs/*.o + rm -r libs + +clean: + @echo "[ CLEAN ]" + rm -rf *.so *.a demo libs $(OBJS) $(DEPS) + +-include $(DEPS) diff --git a/selfdrive/messaging/__init__.py b/selfdrive/messaging/__init__.py new file mode 100644 index 00000000000000..f7845cdf62d7ba --- /dev/null +++ b/selfdrive/messaging/__init__.py @@ -0,0 +1,214 @@ +import os +import subprocess + +can_dir = os.path.dirname(os.path.abspath(__file__)) +subprocess.check_call(["make"], cwd=can_dir) +from .messaging_pyx import Context, Poller, SubSocket, PubSocket # pylint: disable=no-name-in-module, import-error + +from cereal import log +from common.realtime import sec_since_boot +from selfdrive.services import service_list + + +context = Context() + +def new_message(): + dat = log.Event.new_message() + dat.logMonoTime = int(sec_since_boot() * 1e9) + dat.valid = True + return dat + +def pub_sock(endpoint): + sock = PubSocket() + sock.connect(context, endpoint) + return sock + +def sub_sock(endpoint, poller=None, addr="127.0.0.1", conflate=False, timeout=None): + sock = SubSocket() + addr = addr.encode('utf8') + sock.connect(context, endpoint, addr, conflate) + + if timeout is not None: + sock.setTimeout(timeout) + + if poller is not None: + poller.registerSocket(sock) + return sock + + +def drain_sock_raw(sock, wait_for_one=False): + """Receive all message currently available on the queue""" + ret = [] + while 1: + if wait_for_one and len(ret) == 0: + dat = sock.receive() + else: + dat = sock.receive(non_blocking=True) + + if dat is None: + break + + ret.append(dat) + + return ret + +def drain_sock(sock, wait_for_one=False): + """Receive all message currently available on the queue""" + ret = [] + while 1: + if wait_for_one and len(ret) == 0: + dat = sock.receive() + else: + dat = sock.receive(non_blocking=True) + + if dat is None: # Timeout hit + break + + dat = log.Event.from_bytes(dat) + ret.append(dat) + + return ret + + +# TODO: print when we drop packets? +def recv_sock(sock, wait=False): + """Same as drain sock, but only returns latest message. Consider using conflate instead.""" + dat = None + + while 1: + if wait and dat is None: + rcv = sock.receive() + else: + rcv = sock.receive(non_blocking=True) + + if rcv is None: # Timeout hit + break + + dat = rcv + + if dat is not None: + dat = log.Event.from_bytes(dat) + + return dat + +def recv_one(sock): + dat = sock.receive() + if dat is not None: + dat = log.Event.from_bytes(dat) + return dat + +def recv_one_or_none(sock): + dat = sock.receive(non_blocking=True) + if dat is not None: + dat = log.Event.from_bytes(dat) + return dat + +def recv_one_retry(sock): + """Keep receiving until we get a message""" + while True: + dat = sock.receive() + if dat is not None: + return log.Event.from_bytes(dat) + +def get_one_can(logcan): + while True: + can = recv_one_retry(logcan) + if len(can.can) > 0: + return can + +class SubMaster(): + def __init__(self, services, ignore_alive=None, addr="127.0.0.1"): + self.poller = Poller() + self.frame = -1 + self.updated = {s : False for s in services} + self.rcv_time = {s : 0. for s in services} + self.rcv_frame = {s : 0 for s in services} + self.alive = {s : False for s in services} + self.sock = {} + self.freq = {} + self.data = {} + self.logMonoTime = {} + self.valid = {} + + if ignore_alive is not None: + self.ignore_alive = ignore_alive + else: + self.ignore_alive = [] + + for s in services: + # TODO: get address automatically from service_list + if addr is not None: + self.sock[s] = sub_sock(s, poller=self.poller, addr=addr, conflate=True) + self.freq[s] = service_list[s].frequency + + data = new_message() + if s in ['can', 'sensorEvents', 'liveTracks', 'sendCan', + 'ethernetData', 'cellInfo', 'wifiScan', + 'trafficEvents', 'orbObservation', 'carEvents']: + data.init(s, 0) + else: + data.init(s) + self.data[s] = getattr(data, s) + self.logMonoTime[s] = 0 + self.valid[s] = data.valid + + def __getitem__(self, s): + return self.data[s] + + def update(self, timeout=-1): + msgs = [] + for sock in self.poller.poll(timeout): + msgs.append(recv_one(sock)) + self.update_msgs(sec_since_boot(), msgs) + + def update_msgs(self, cur_time, msgs): + # TODO: add optional input that specify the service to wait for + self.frame += 1 + self.updated = dict.fromkeys(self.updated, False) + for msg in msgs: + if msg is None: + continue + + s = msg.which() + self.updated[s] = True + self.rcv_time[s] = cur_time + self.rcv_frame[s] = self.frame + self.data[s] = getattr(msg, s) + self.logMonoTime[s] = msg.logMonoTime + self.valid[s] = msg.valid + + for s in self.data: + # arbitrary small number to avoid float comparison. If freq is 0, we can skip the check + if self.freq[s] > 1e-5: + # alive if delay is within 10x the expected frequency + self.alive[s] = (cur_time - self.rcv_time[s]) < (10. / self.freq[s]) + else: + self.alive[s] = True + + def all_alive(self, service_list=None): + if service_list is None: # check all + service_list = self.alive.keys() + return all(self.alive[s] for s in service_list if s not in self.ignore_alive) + + def all_valid(self, service_list=None): + if service_list is None: # check all + service_list = self.valid.keys() + return all(self.valid[s] for s in service_list) + + def all_alive_and_valid(self, service_list=None): + if service_list is None: # check all + service_list = self.alive.keys() + return self.all_alive(service_list=service_list) and self.all_valid(service_list=service_list) + + +class PubMaster(): + def __init__(self, services): + self.sock = {} + for s in services: + self.sock[s] = pub_sock(s) + + def send(self, s, dat): + # accept either bytes or capnp builder + if not isinstance(dat, bytes): + dat = dat.to_bytes() + self.sock[s].send(dat) \ No newline at end of file diff --git a/selfdrive/messaging/demo.cc b/selfdrive/messaging/demo.cc new file mode 100644 index 00000000000000..cfdf42209415fc --- /dev/null +++ b/selfdrive/messaging/demo.cc @@ -0,0 +1,50 @@ +#include +#include +#include +#include +#include + +#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(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; +} diff --git a/selfdrive/messaging/demo.py b/selfdrive/messaging/demo.py new file mode 100644 index 00000000000000..7906a41e203cdf --- /dev/null +++ b/selfdrive/messaging/demo.py @@ -0,0 +1,30 @@ +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)) diff --git a/selfdrive/messaging/impl_zmq.cc b/selfdrive/messaging/impl_zmq.cc new file mode 100644 index 00000000000000..93223e863ac089 --- /dev/null +++ b/selfdrive/messaging/impl_zmq.cc @@ -0,0 +1,173 @@ +#include +#include +#include +#include + +#include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wshadow" +#include +#pragma GCC diagnostic pop + +#include "impl_zmq.hpp" + +static int get_port(std::string endpoint) { + char * base_dir_ptr = std::getenv("BASEDIR"); + + if (base_dir_ptr == NULL){ + base_dir_ptr = std::getenv("PYTHONPATH"); + } + + assert(base_dir_ptr); + std::string base_dir = base_dir_ptr; + std::string service_list_path = base_dir + "/selfdrive/service_list.yaml"; + YAML::Node service_list = YAML::LoadFile(service_list_path); + + int port = -1; + for (const auto& it : service_list) { + auto name = it.first.as(); + + if (name == endpoint){ + port = it.second[0].as(); + break; + } + } + + if (port == -1){ + std::cout << "Service " << endpoint << " not found" << std::endl; + } + + 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(); +} + + +void ZMQSubSocket::connect(Context *context, std::string endpoint, std::string address, bool conflate){ + sock = zmq_socket(context->getRawContext(), ZMQ_SUB); + assert(sock); + + 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)); + + std::cout << "ZMQ SUB: " << full_endpoint << std::endl; + + assert(zmq_connect(sock, full_endpoint.c_str()) == 0); +} + + +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); +} + +void ZMQPubSocket::connect(Context *context, std::string endpoint){ + sock = zmq_socket(context->getRawContext(), ZMQ_PUB); + + full_endpoint = "tcp://*:"; + full_endpoint += std::to_string(get_port(endpoint)); + + std::cout << "ZMQ PUB: " << full_endpoint << std::endl; + + assert(zmq_bind(sock, full_endpoint.c_str()) == 0); +} + +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 ZMQPoller::poll(int timeout){ + std::vector 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; +} diff --git a/selfdrive/messaging/impl_zmq.hpp b/selfdrive/messaging/impl_zmq.hpp new file mode 100644 index 00000000000000..a40d623e3af849 --- /dev/null +++ b/selfdrive/messaging/impl_zmq.hpp @@ -0,0 +1,63 @@ +#pragma once +#include "messaging.hpp" +#include +#include + +#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: + void 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: + void 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 sockets; + zmq_pollitem_t polls[MAX_POLLERS]; + size_t num_polls = 0; + +public: + void registerSocket(SubSocket *socket); + std::vector poll(int timeout); + ~ZMQPoller(){}; +}; diff --git a/selfdrive/messaging/messaging.cc b/selfdrive/messaging/messaging.cc new file mode 100644 index 00000000000000..a1178a510872a6 --- /dev/null +++ b/selfdrive/messaging/messaging.cc @@ -0,0 +1,51 @@ +#include "messaging.hpp" +#include "impl_zmq.hpp" + +Context * Context::create(){ + Context * c = new ZMQContext(); + return c; +} + +SubSocket * SubSocket::create(){ + SubSocket * s = new ZMQSubSocket(); + return s; +} + +SubSocket * SubSocket::create(Context * context, std::string endpoint){ + SubSocket *s = SubSocket::create(); + s->connect(context, endpoint, "127.0.0.1"); + + return s; +} + +SubSocket * SubSocket::create(Context * context, std::string endpoint, std::string address){ + SubSocket *s = SubSocket::create(); + s->connect(context, endpoint, address); + + return s; +} + +PubSocket * PubSocket::create(){ + PubSocket * s = new ZMQPubSocket(); + return s; +} + +PubSocket * PubSocket::create(Context * context, std::string endpoint){ + PubSocket *s = PubSocket::create(); + s->connect(context, endpoint); + return s; +} + +Poller * Poller::create(){ + Poller * p = new ZMQPoller(); + return p; +} + +Poller * Poller::create(std::vector sockets){ + Poller * p = Poller::create(); + + for (auto s : sockets){ + p->registerSocket(s); + } + return p; +} diff --git a/selfdrive/messaging/messaging.hpp b/selfdrive/messaging/messaging.hpp new file mode 100644 index 00000000000000..95e34c0d67f4dc --- /dev/null +++ b/selfdrive/messaging/messaging.hpp @@ -0,0 +1,53 @@ +#pragma once +#include +#include +#include + +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 void 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); + virtual ~SubSocket(){}; +}; + +class PubSocket { +public: + virtual void 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 poll(int timeout) = 0; + static Poller * create(); + static Poller * create(std::vector sockets); + virtual ~Poller(){}; +}; diff --git a/selfdrive/messaging/messaging.pxd b/selfdrive/messaging/messaging.pxd new file mode 100644 index 00000000000000..5e3da7241544cf --- /dev/null +++ b/selfdrive/messaging/messaging.pxd @@ -0,0 +1,42 @@ +# 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() + void connect(Context *, string, string, bool) + Message * receive(bool) + void setTimeout(int) + + + cdef cppclass PubSocket: + @staticmethod + PubSocket * create() + void connect(Context *, string) + int sendMessage(Message *) + int send(char *, size_t) + + cdef cppclass Poller: + @staticmethod + Poller * create() + void registerSocket(SubSocket *) + vector[SubSocket*] poll(int) diff --git a/selfdrive/messaging/messaging_pyx.pyx b/selfdrive/messaging/messaging_pyx.pyx new file mode 100644 index 00000000000000..ff55c310750fd1 --- /dev/null +++ b/selfdrive/messaging/messaging_pyx.pyx @@ -0,0 +1,104 @@ +# distutils: language = c++ +# cython: c_string_encoding=ascii, language_level=3 + +from libcpp.string cimport string +from libcpp cimport bool + + +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 + + +cdef class Context: + cdef cppContext * context + def __cinit__(self): + self.context = cppContext.create() + + 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 = [] + + result = self.poller.poll(timeout) + 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 + + 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): + self.socket.connect(context.context, endpoint, address, conflate) + + 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: + 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() + + def __dealloc__(self): + del self.socket + + def connect(self, Context context, string endpoint): + self.socket.connect(context.context, endpoint) + + def send(self, string data): + return self.socket.send(data.c_str(), len(data)) diff --git a/selfdrive/messaging/messaging_pyx_setup.py b/selfdrive/messaging/messaging_pyx_setup.py new file mode 100644 index 00000000000000..53cd73c7d76d3a --- /dev/null +++ b/selfdrive/messaging/messaging_pyx_setup.py @@ -0,0 +1,34 @@ +import os +import subprocess +from distutils.core import Extension, setup # pylint: disable=import-error,no-name-in-module + +from Cython.Build import cythonize + +from common.basedir import BASEDIR +from common.cython_hacks import BuildExtWithoutPlatformSuffix + +sourcefiles = ['messaging_pyx.pyx'] +extra_compile_args = ["-std=c++11"] +libraries = [] +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(BASEDIR, 'selfdrive', 'messaging', 'messaging.a'), + ] + ) + ), + nthreads=4, +) diff --git a/selfdrive/messaging.py b/selfdrive/messaging_arne.py similarity index 94% rename from selfdrive/messaging.py rename to selfdrive/messaging_arne.py index db53b4ac7d4702..80f9085c2db10b 100644 --- a/selfdrive/messaging.py +++ b/selfdrive/messaging_arne.py @@ -1,11 +1,11 @@ import zmq -from cereal import log +from cereal import arne182 as log from common.realtime import sec_since_boot from selfdrive.services import service_list def new_message(): - dat = log.Event.new_message() + dat = log.EventArne182.new_message() dat.logMonoTime = int(sec_since_boot() * 1e9) dat.valid = True return dat @@ -70,7 +70,7 @@ def drain_sock(sock, wait_for_one=False): dat = sock.recv() else: dat = sock.recv(zmq.NOBLOCK) - dat = log.Event.from_bytes(dat) + dat = log.EventArne182.from_bytes(dat) ret.append(dat) except zmq.error.Again: break @@ -89,15 +89,15 @@ def recv_sock(sock, wait=False): except zmq.error.Again: break if dat is not None: - dat = log.Event.from_bytes(dat) + dat = log.EventArne182.from_bytes(dat) return dat def recv_one(sock): - return log.Event.from_bytes(sock.recv()) + return log.EventArne182.from_bytes(sock.recv()) def recv_one_or_none(sock): try: - return log.Event.from_bytes(sock.recv(zmq.NOBLOCK)) + return log.EventArne182.from_bytes(sock.recv(zmq.NOBLOCK)) except zmq.error.Again: return None @@ -194,4 +194,4 @@ def send(self, s, dat): # accept either bytes or capnp builder if not isinstance(dat, bytes): dat = dat.to_bytes() - self.sock[s].send(dat) \ No newline at end of file + self.sock[s].send(dat) diff --git a/selfdrive/pandad.py b/selfdrive/pandad.py index eac0ea92d133ad..2ef286fa7a6a3a 100755 --- a/selfdrive/pandad.py +++ b/selfdrive/pandad.py @@ -7,10 +7,15 @@ from panda import Panda, PandaDFU, BASEDIR -def update_panda(): +def get_expected_version(): with open(os.path.join(BASEDIR, "VERSION")) as f: repo_version = f.read() repo_version += "-EON" if os.path.isfile('/EON') else "-DEV" + return repo_version + + +def update_panda(): + repo_version = get_expected_version() panda = None panda_dfu = None diff --git a/selfdrive/phantom.py b/selfdrive/phantom.py new file mode 100644 index 00000000000000..7dda9004383d56 --- /dev/null +++ b/selfdrive/phantom.py @@ -0,0 +1,61 @@ +import zmq +import selfdrive.messaging_arne as messaging_arne +from selfdrive.services import service_list +from common.op_params import opParams +import subprocess +from common.travis_checker import travis +import time + + +class Phantom: + def __init__(self, timeout=1.): + context = zmq.Context() + self.op_params = opParams() + self.phantom_Data_sock = messaging_arne.sub_sock(service_list['phantomData'].port, conflate=True) + self.data = {"status": False, "speed": 0.0} + self.last_receive_time = time.time() + self.last_phantom_data = {"status": False, "speed": 0.0} + self.timeout = timeout # in seconds + self.to_disable = True + if not travis and not self.op_params.get("UseDNS", None): # ensure we only run once + self.mod_sshd_config() + + def update(self): + phantom_data = messaging_arne.recv_one_or_none(self.phantom_Data_sock) + if phantom_data is not None: + self.data = {"status": phantom_data.phantomData.status, "speed": phantom_data.phantomData.speed, + "angle": phantom_data.phantomData.angle, "time": phantom_data.phantomData.time} + self.last_phantom_data = dict(self.data) + self.last_receive_time = time.time() + self.to_disable = not self.data["status"] + else: + if self.to_disable: # if last message is status: False, disable phantom mode, also disable by default + self.data = {"status": False, "speed": 0.0} + elif time.time() - self.last_receive_time >= self.timeout: # lost connection, don't disable. keep phantom on but set speed to 0 + self.data = {"status": True, "speed": 0.0, "angle": 0.0, "time": 0.0, "lost_connection": True} + else: # if waiting between messages from app, message becomes none, this uses the data from last message + self.data = dict(self.last_phantom_data) + + def mod_sshd_config(self): + # this disables dns lookup when connecting to EON to speed up commands from phantom app, reboot required + sshd_config_file = "/system/comma/usr/etc/ssh/sshd_config" + try: + # mount /system as rw so we can modify sshd_config file + result = subprocess.check_call(["mount", "-o", "remount,rw", "/system"]) + except: + result = 1 + if result == 0: + with open(sshd_config_file, "r") as f: + sshd_config = f.read() + if "UseDNS no" not in sshd_config: + use_dns = "{}UseDNS no\n" + use_dns = use_dns.format("") if sshd_config[-1] == "\n" else use_dns.format("\n") + with open(sshd_config_file, "w") as f: + f.write(sshd_config + use_dns) + self.op_params.put("UseDNS", True) + try: + subprocess.call(["mount", "-o", "remount,ro", "/system"]) # remount system as read only + except: + pass + else: + self.op_params.put("UseDNS", False) diff --git a/selfdrive/phantom_receiver.py b/selfdrive/phantom_receiver.py new file mode 100644 index 00000000000000..db69a95a6b78e4 --- /dev/null +++ b/selfdrive/phantom_receiver.py @@ -0,0 +1,30 @@ +from selfdrive.services import service_list +import selfdrive.messaging_arne as messaging_arne + + +class PhantomReceiver: + def __init__(self): + self.phantom_data_sock = None + + def receive_data(self, speed, angle, time): + self.broadcast_data(True, speed, angle, time) + + def broadcast_data(self, status, speed, angle, time): + with open('/data/bd.test', 'a') as f: + f.write('{}\n'.format([status, speed, angle, time])) + phantom_data = messaging_arne.new_message() + phantom_data.init('phantomData') + phantom_data.phantomData.status = status + phantom_data.phantomData.speed = speed + phantom_data.phantomData.angle = angle + phantom_data.phantomData.time = time + self.phantom_data_sock.send(phantom_data.to_bytes()) + + def enable_phantom(self): + self.phantom_data_sock = messaging_arne.pub_sock(service_list['phantomData'].port) + return "ENABLED" # needed to tell the app we're all done with this function + + def disable_phantom(self): + self.broadcast_data(False, 0.0, 0.0, 0.0) + self.phantom_data_sock.close() + return "DISABLED" diff --git a/selfdrive/proclogd/Makefile b/selfdrive/proclogd/Makefile index 9939a715f3d104..46c4ca5c464d92 100644 --- a/selfdrive/proclogd/Makefile +++ b/selfdrive/proclogd/Makefile @@ -15,15 +15,15 @@ WARN_FLAGS = -Werror=implicit-function-declaration \ CFLAGS = -std=gnu11 -g -fPIC -O2 $(WARN_FLAGS) CXXFLAGS = -std=c++11 -g -fPIC -O2 $(WARN_FLAGS) -ZMQ_LIBS = -l:libczmq.a -l:libzmq.a +MESSAGING_FLAGS = -I$(BASEDIR)/selfdrive/messaging +MESSAGING_LIBS = $(BASEDIR)/selfdrive/messaging/messaging.a ifeq ($(ARCH),aarch64) CFLAGS += -mcpu=cortex-a57 CXXFLAGS += -mcpu=cortex-a57 -ZMQ_LIBS += -lgnustl_shared +EXTRA_LIBS += -lgnustl_shared endif -#ZMQ_FLAGS = -I$(PHONELIBS)/zmq/aarch64/include .PHONY: all all: proclogd @@ -35,18 +35,18 @@ OBJS = proclogd.o \ DEPS := $(OBJS:.o=.d) -proclogd: $(OBJS) +proclogd: $(OBJS) $(MESSAGING_LIBS) @echo "[ LINK ] $@" $(CXX) -fPIC -o '$@' $^ \ $(CEREAL_LIBS) \ - $(ZMQ_LIBS) \ + $(EXTRA_LIBS) \ -llog %.o: %.cc @echo "[ CXX ] $@" $(CXX) $(CXXFLAGS) \ $(CEREAL_CXXFLAGS) \ - $(ZMQ_FLAGS) \ + $(MESSAGING_FLAGS) \ -I../ \ -I../../ \ -c -o '$@' '$<' diff --git a/selfdrive/proclogd/proclogd.cc b/selfdrive/proclogd/proclogd.cc index fbb7704e0378e7..50e3b4b6595cd2 100644 --- a/selfdrive/proclogd/proclogd.cc +++ b/selfdrive/proclogd/proclogd.cc @@ -16,7 +16,7 @@ #include #include -#include +#include "messaging.hpp" #include #include "cereal/gen/cpp/log.capnp.h" @@ -36,10 +36,8 @@ struct ProcCache { int main() { int err; - void *context = zmq_ctx_new(); - void *publisher = zmq_socket(context, ZMQ_PUB); - err = zmq_bind(publisher, "tcp://*:8031"); - assert(err == 0); + Context * c = Context::create(); + PubSocket * publisher = PubSocket::create(c, "procLog"); double jiffy = sysconf(_SC_CLK_TCK); size_t page_size = sysconf(_SC_PAGE_SIZE); @@ -103,7 +101,7 @@ int main() { std::ifstream smem("/proc/meminfo"); std::string mem_line; - + uint64_t mem_total = 0, mem_free = 0, mem_available = 0, mem_buffers = 0; uint64_t mem_cached = 0, mem_active = 0, mem_inactive = 0, mem_shared = 0; @@ -203,7 +201,7 @@ int main() { std::string cmdline_s = util::read_file(util::string_format("/proc/%d/cmdline", pid)); const char* cmdline_p = cmdline_s.c_str(); const char* cmdline_ep = cmdline_p + cmdline_s.size(); - + // strip trailing null bytes while ((cmdline_ep-1) > cmdline_p && *(cmdline_ep-1) == 0) { cmdline_ep--; @@ -236,10 +234,13 @@ int main() { auto words = capnp::messageToFlatArray(msg); auto bytes = words.asBytes(); - zmq_send(publisher, bytes.begin(), bytes.size(), 0); + publisher->send((char*)bytes.begin(), bytes.size()); usleep(2000000); // 2 secs } + delete c; + delete publisher; + return 0; } diff --git a/selfdrive/sensord/build_from_src.mk b/selfdrive/sensord/build_from_src.mk index 8c71f5f96d06f0..b51364e8ddc3a6 100644 --- a/selfdrive/sensord/build_from_src.mk +++ b/selfdrive/sensord/build_from_src.mk @@ -19,12 +19,13 @@ CXXFLAGS = -std=c++11 -g -fPIC -O2 $(WARN_FLAGS) \ -I$(PHONELIBS)/android_system_core/include \ -I$(PHONELIBS)/android_hardware_libhardware/include -ZMQ_LIBS = -l:libczmq.a -l:libzmq.a -llog -luuid -lgnustl_shared +MESSAGING_FLAGS = -I$(BASEDIR)/selfdrive/messaging +MESSAGING_LIBS = $(BASEDIR)/selfdrive/messaging/messaging.a -ifeq ($(ARCH),aarch64) +# Sensord can only be compiled for the phone CFLAGS += -mcpu=cortex-a57 CXXFLAGS += -mcpu=cortex-a57 -endif +EXTRA_LIBS += -lgnustl_shared JSON_FLAGS = -I$(PHONELIBS)/json/src @@ -47,26 +48,26 @@ GPSD_OBJS = gpsd.o \ DEPS := $(SENSORD_OBJS:.o=.d) $(GPSD_OBJS:.o=.d) -sensord: $(SENSORD_OBJS) +sensord: $(SENSORD_OBJS) $(MESSAGING_LIBS) @echo "[ LINK ] $@" $(CXX) -fPIC -o '$@' $^ \ $(CEREAL_LIBS) \ - $(ZMQ_LIBS) \ + $(EXTRA_LIBS) \ -lhardware -gpsd: $(GPSD_OBJS) +gpsd: $(GPSD_OBJS) $(MESSAGING_LIBS) @echo "[ LINK ] $@" $(CXX) -fPIC -o '$@' $^ \ $(CEREAL_LIBS) \ - $(ZMQ_LIBS) \ $(DIAG_LIBS) \ + $(EXTRA_LIBS) \ -lhardware %.o: %.cc @echo "[ CXX ] $@" $(CXX) $(CXXFLAGS) \ $(CEREAL_CXXFLAGS) \ - $(ZMQ_FLAGS) \ + $(MESSAGING_FLAGS) \ $(JSON_FLAGS) \ -I../ \ -I../../ \ @@ -77,6 +78,7 @@ gpsd: $(GPSD_OBJS) @echo "[ CC ] $@" $(CC) $(CFLAGS) \ $(JSON_FLAGS) \ + $(ZMQ_FLAGS) \ -I../ \ -I../../ \ -c -o '$@' '$<' diff --git a/selfdrive/sensord/gpsd.cc b/selfdrive/sensord/gpsd.cc index 0a8cd1bffc72a6..d7637651f9a581 100644 --- a/selfdrive/sensord/gpsd.cc +++ b/selfdrive/sensord/gpsd.cc @@ -17,10 +17,9 @@ #include #include -#include - #include +#include "messaging.hpp" #include "common/timing.h" #include "common/swaglog.h" @@ -34,10 +33,9 @@ namespace { pthread_t clock_thread_handle; -// zmq output -void *gps_context; -void *gps_publisher; -void *gps_location_publisher; +Context *gps_context; +PubSocket *gps_publisher; +PubSocket *gps_location_publisher; const GpsInterface* gGpsInterface = NULL; const AGpsInterface* gAGpsInterface = NULL; @@ -63,7 +61,7 @@ void nmea_callback(GpsUtcTime timestamp, const char* nmea, int length) { auto words = capnp::messageToFlatArray(msg); auto bytes = words.asBytes(); // printf("gps send %d\n", bytes.size()); - zmq_send(gps_publisher, bytes.begin(), bytes.size(), 0); + gps_publisher->send((char*)bytes.begin(), bytes.size()); } void location_callback(GpsLocation* location) { @@ -87,7 +85,7 @@ void location_callback(GpsLocation* location) { auto words = capnp::messageToFlatArray(msg); auto bytes = words.asBytes(); - zmq_send(gps_location_publisher, bytes.begin(), bytes.size(), 0); + gps_location_publisher->send((char*)bytes.begin(), bytes.size()); } pthread_t create_thread_callback(const char* name, void (*start)(void *), void* arg) { @@ -163,12 +161,9 @@ void gps_init() { GPS_POSITION_RECURRENCE_PERIODIC, 100, 0, 0); - gps_context = zmq_ctx_new(); - gps_publisher = zmq_socket(gps_context, ZMQ_PUB); - zmq_bind(gps_publisher, "tcp://*:8004"); - - gps_location_publisher = zmq_socket(gps_context, ZMQ_PUB); - zmq_bind(gps_location_publisher, "tcp://*:8026"); + gps_context = Context::create(); + gps_publisher = PubSocket::create(gps_context, "gpsNMEA"); + gps_location_publisher = PubSocket::create(gps_context, "gpsLocation"); } void gps_destroy() { @@ -187,8 +182,7 @@ int64_t arm_cntpct() { void* clock_thread(void* args) { int err = 0; - void* clock_publisher = zmq_socket(gps_context, ZMQ_PUB); - zmq_bind(clock_publisher, "tcp://*:8034"); + PubSocket* clock_publisher = PubSocket::create(gps_context, "clocks"); int timerfd = timerfd_create(CLOCK_BOOTTIME, 0); assert(timerfd >= 0); @@ -228,11 +222,11 @@ void* clock_thread(void* args) { auto words = capnp::messageToFlatArray(msg); auto bytes = words.asBytes(); - zmq_send(clock_publisher, bytes.begin(), bytes.size(), 0); + clock_publisher->send((char*)bytes.begin(), bytes.size()); } close(timerfd); - zmq_close(clock_publisher); + delete clock_publisher; return NULL; } diff --git a/selfdrive/sensord/rawgps.cc b/selfdrive/sensord/rawgps.cc index 7f5206a06c0cb4..2cd497517556e5 100644 --- a/selfdrive/sensord/rawgps.cc +++ b/selfdrive/sensord/rawgps.cc @@ -7,11 +7,11 @@ #include #include -#include #include #include "cereal/gen/cpp/log.capnp.h" +#include "messaging.hpp" #include "common/timing.h" #include "common/util.h" #include "common/swaglog.h" @@ -458,8 +458,8 @@ struct __attribute__((packed)) GNSSOemdreSVPolyReportv2 { _Static_assert(sizeof(GNSSOemdreSVPolyReportv2) == 271, "error"); -static void* rawgps_context; -static void *rawgps_publisher; +static Context *rawgps_context; +static PubSocket *rawgps_publisher; static int client_id = 0; static void hexdump(uint8_t* d, size_t len) { @@ -913,7 +913,7 @@ static void handle_log(uint8_t *ptr, int len) { auto words = capnp::messageToFlatArray(msg); auto bytes = words.asBytes(); - zmq_send(rawgps_publisher, bytes.begin(), bytes.size(), 0); + rawgps_publisher->send((char*)bytes.begin(), bytes.size()); } static void handle_event(unsigned char *ptr, int len) { @@ -1106,11 +1106,8 @@ static void nav_config(int client_id, uint8_t config) { void rawgps_init() { int err; - - rawgps_context = zmq_ctx_new(); - rawgps_publisher = zmq_socket(rawgps_context, ZMQ_PUB); - zmq_bind(rawgps_publisher, "tcp://*:8029"); - + rawgps_context = Context::create(); + rawgps_publisher = PubSocket::create(rawgps_context, "qcomGnss"); bool init_success = Diag_LSM_Init(NULL); assert(init_success); @@ -1166,9 +1163,8 @@ void rawgps_destroy() { Diag_LSM_DeInit(); - zmq_close(rawgps_publisher); - zmq_term(rawgps_context); - + delete rawgps_publisher; + delete rawgps_context; } diff --git a/selfdrive/sensord/sensors.cc b/selfdrive/sensord/sensors.cc index ded2b88c44d740..de20bfc6c3cbc1 100644 --- a/selfdrive/sensord/sensors.cc +++ b/selfdrive/sensord/sensors.cc @@ -17,10 +17,9 @@ #include #include -#include - #include +#include "messaging.hpp" #include "common/timing.h" #include "common/swaglog.h" @@ -53,6 +52,10 @@ void sigpipe_handler(int sig) { void sensor_loop() { LOG("*** sensor loop"); + + Context * c = Context::create(); + PubSocket * sensor_events_sock = PubSocket::create(c, "sensorEvents"); + struct sensors_poll_device_t* device; struct sensors_module_t* module; @@ -99,9 +102,6 @@ void sensor_loop() { static const size_t numEvents = 16; sensors_event_t buffer[numEvents]; - auto sensor_events_sock = zsock_new_pub("@tcp://*:8003"); - assert(sensor_events_sock); - auto sensor_events_sock_raw = zsock_resolve(sensor_events_sock); while (!do_exit) { int n = device->poll(device, buffer, numEvents); @@ -212,12 +212,12 @@ void sensor_loop() { auto words = capnp::messageToFlatArray(msg); auto bytes = words.asBytes(); - zmq_send(sensor_events_sock_raw, bytes.begin(), bytes.size(), ZMQ_DONTWAIT); - + sensor_events_sock->send((char*)bytes.begin(), bytes.size()); } - LOG("bye"); -} + delete sensor_events_sock; + delete c; +} } int main(int argc, char *argv[]) { diff --git a/selfdrive/service_list.yaml b/selfdrive/service_list.yaml index 0d422c0c425e33..81575375a4d463 100644 --- a/selfdrive/service_list.yaml +++ b/selfdrive/service_list.yaml @@ -84,6 +84,7 @@ liveTrafficData: [8208, false, 100.] liveMapData: [8065, false, 10.] arne182Status: [8209, false, 100.] latControl: [8210, false, 20.] +phantomData: [8211, false, 20.] # 8080 is reserved for slave testing daemon # 8762 is reserved for logserver diff --git a/selfdrive/test/longitudinal_maneuvers/plant.py b/selfdrive/test/longitudinal_maneuvers/plant.py index 1a57284697ad57..b81f5ea0e19953 100755 --- a/selfdrive/test/longitudinal_maneuvers/plant.py +++ b/selfdrive/test/longitudinal_maneuvers/plant.py @@ -11,7 +11,6 @@ from common.realtime import Ratekeeper from selfdrive.config import Conversions as CV import selfdrive.messaging as messaging -from selfdrive.services import service_list from selfdrive.car import crc8_pedal from selfdrive.car.honda.hondacan import fix from selfdrive.car.honda.values import CAR @@ -97,16 +96,16 @@ def __init__(self, lead_relevancy=False, rate=100, speed=0.0, distance_lead=2.0) self.rate = rate if not Plant.messaging_initialized: - Plant.logcan = messaging.pub_sock(service_list['can'].port) - Plant.sendcan = messaging.sub_sock(service_list['sendcan'].port) - Plant.model = messaging.pub_sock(service_list['model'].port) - Plant.live_params = messaging.pub_sock(service_list['liveParameters'].port) - Plant.health = messaging.pub_sock(service_list['health'].port) - Plant.thermal = messaging.pub_sock(service_list['thermal'].port) - Plant.driverMonitoring = messaging.pub_sock(service_list['driverMonitoring'].port) - Plant.cal = messaging.pub_sock(service_list['liveCalibration'].port) - Plant.controls_state = messaging.sub_sock(service_list['controlsState'].port) - Plant.plan = messaging.sub_sock(service_list['plan'].port) + Plant.logcan = messaging.pub_sock('can') + Plant.sendcan = messaging.sub_sock('sendcan') + Plant.model = messaging.pub_sock('model') + Plant.live_params = messaging.pub_sock('liveParameters') + Plant.health = messaging.pub_sock('health') + Plant.thermal = messaging.pub_sock('thermal') + Plant.driverMonitoring = messaging.pub_sock('driverMonitoring') + Plant.cal = messaging.pub_sock('liveCalibration') + Plant.controls_state = messaging.sub_sock('controlsState') + Plant.plan = messaging.sub_sock('plan') Plant.messaging_initialized = True self.frame = 0 diff --git a/selfdrive/test/openpilotci_upload.py b/selfdrive/test/openpilotci_upload.py index df40715716bad7..e2ad2d41295ee6 100755 --- a/selfdrive/test/openpilotci_upload.py +++ b/selfdrive/test/openpilotci_upload.py @@ -7,11 +7,9 @@ def upload_file(path, name): from azure.storage.blob import BlockBlobService # pylint: disable=no-name-in-module, import-error sas_token = os.getenv("TOKEN", None) - if sas_token is not None: - service = BlockBlobService(account_name="commadataci", sas_token=sas_token) - else: - account_key = subprocess.check_output("az storage account keys list --account-name commadataci --output tsv --query '[0].value'", shell=True) - service = BlockBlobService(account_name="commadataci", account_key=account_key) + if sas_token is None: + sas_token = subprocess.check_output("az storage container generate-sas --account-name commadataci --name openpilotci --https-only --permissions lrw --expiry $(date -u '+%Y-%m-%dT%H:%M:%SZ' -d '+1 hour') --auth-mode login --as-user --output tsv", shell=True).decode().strip("\n") + service = BlockBlobService(account_name="commadataci", sas_token=sas_token) service.create_blob_from_path("openpilotci", name, path) return "https://commadataci.blob.core.windows.net/openpilotci/" + name diff --git a/selfdrive/test/process_replay/compare_logs.py b/selfdrive/test/process_replay/compare_logs.py index a6397ab592816a..a742d82a242008 100755 --- a/selfdrive/test/process_replay/compare_logs.py +++ b/selfdrive/test/process_replay/compare_logs.py @@ -12,22 +12,22 @@ from tools.lib.logreader import LogReader def save_log(dest, log_msgs): - dat = "" + dat = b"" for msg in log_msgs: dat += msg.as_builder().to_bytes() dat = bz2.compress(dat) - with open(dest, "w") as f: + with open(dest, "wb") as f: f.write(dat) def remove_ignored_fields(msg, ignore): - msg = msg.as_builder() + msg = msg.as_builder() for key, val in ignore: attr = msg keys = key.split(".") if msg.which() not in key and len(keys) > 1: continue - + for k in keys[:-1]: try: attr = getattr(msg, k) diff --git a/selfdrive/test/process_replay/process_replay.py b/selfdrive/test/process_replay/process_replay.py index 1676daa142b714..718bab6dd60a63 100755 --- a/selfdrive/test/process_replay/process_replay.py +++ b/selfdrive/test/process_replay/process_replay.py @@ -3,7 +3,6 @@ import threading import importlib import shutil -import zmq if "CI" in os.environ: tqdm = lambda x: x @@ -27,9 +26,9 @@ def __init__(self, wait=True): self.recv_called = threading.Event() self.recv_ready = threading.Event() - def recv(self, block=None): - if block == zmq.NOBLOCK: - raise zmq.error.Again + def receive(self, non_blocking=False): + if non_blocking: + return None if self.wait: self.recv_called.set() @@ -57,7 +56,7 @@ def __init__(self, s=None): dat.init(s) self.data = dat.to_bytes() - def recv(self, block=None): + def receive(self, non_blocking=False): return self.data def send(self, dat): diff --git a/selfdrive/test/process_replay/ref_commit b/selfdrive/test/process_replay/ref_commit index 557be7d88d35e9..f00366d3f83c79 100644 --- a/selfdrive/test/process_replay/ref_commit +++ b/selfdrive/test/process_replay/ref_commit @@ -1 +1 @@ -8def7e7391802f2e86498d764c953f487361f6a1 \ No newline at end of file +5fe3678541ca1254ca5c1f04231f42225d68c538 \ No newline at end of file diff --git a/selfdrive/test/test_car_models.py b/selfdrive/test/test_car_models.py old mode 100755 new mode 100644 index ac2bc5542932d0..63e979b3de0bdb --- a/selfdrive/test/test_car_models.py +++ b/selfdrive/test/test_car_models.py @@ -1,7 +1,6 @@ #!/usr/bin/env python3 import shutil import time -import zmq import os import sys import signal @@ -10,7 +9,6 @@ from cereal import car import selfdrive.manager as manager -from selfdrive.services import service_list import selfdrive.messaging as messaging from common.params import Params from common.basedir import BASEDIR @@ -22,24 +20,24 @@ from selfdrive.car.hyundai.values import CAR as HYUNDAI from selfdrive.car.chrysler.values import CAR as CHRYSLER from selfdrive.car.subaru.values import CAR as SUBARU +from selfdrive.car.volkswagen.values import CAR as VOLKSWAGEN from selfdrive.car.mock.values import CAR as MOCK os.environ['NOCRASH'] = '1' def wait_for_socket(name, timeout=10.0): - socket = messaging.sub_sock(service_list[name].port) + socket = messaging.sub_sock(name) cur_time = time.time() r = None while time.time() - cur_time < timeout: print("waiting for %s" % name) - try: - r = socket.recv(zmq.NOBLOCK) + r = socket.receive(non_blocking=True) + if r is not None: break - except zmq.error.Again: - pass time.sleep(0.5) + if r is None: sys.exit(-1) return r @@ -260,6 +258,11 @@ def get_route_logs(route_name): 'enableCamera': True, 'enableDsu': True, }, + "5ceff72287a5c86c|2019-10-19--10-59-02": { + 'carFingerprint': TOYOTA.COROLLAH_TSS2, + 'enableCamera': True, + 'enableDsu': True, + }, "56fb1c86a9a86404|2017-11-10--10-18-43": { 'carFingerprint': TOYOTA.PRIUS, 'enableCamera': True, @@ -282,6 +285,11 @@ def get_route_logs(route_name): 'enableCamera': True, 'enableDsu': True, }, + "e6a24be49a6cd46e|2019-10-29--10-52-42": { + 'carFingerprint': TOYOTA.LEXUS_ES_TSS2, + 'enableCamera': True, + 'enableDsu': True, + }, "f49e8041283f2939|2019-05-29--13-48-33": { 'carFingerprint': TOYOTA.LEXUS_ESH_TSS2, 'enableCamera': False, @@ -375,6 +383,10 @@ def get_route_logs(route_name): 'enableCamera': True, 'enableDsu': False, }, + "76b83eb0245de90e|2019-10-20--15-42-29": { + 'carFingerprint': VOLKSWAGEN.GOLF, + 'enableCamera': True, + }, "791340bc01ed993d|2019-03-10--16-28-08": { 'carFingerprint': SUBARU.IMPREZA, 'enableCamera': True, @@ -471,13 +483,9 @@ def get_route_logs(route_name): # Start unlogger print("Start unlogger") if route in non_public_routes: - unlogger_cmd = [os.path.join(BASEDIR, os.environ['UNLOGGER_PATH']), '%s' % route, '--disable', - 'frame,plan,pathPlan,liveLongitudinalMpc,radarState,controlsState,liveTracks,liveMpc,sendcan,carState,carControl', - '--no-interactive'] + unlogger_cmd = [os.path.join(BASEDIR, os.environ['UNLOGGER_PATH']), '%s' % route, '--disable', 'frame,plan,pathPlan,liveLongitudinalMpc,radarState,controlsState,liveTracks,liveMpc,sendcan,carState,carControl,carEvents,carParams', '--no-interactive'] else: - unlogger_cmd = [os.path.join(BASEDIR, 'tools/replay/unlogger.py'), '%s' % route, '/tmp', '--disable', - 'frame,plan,pathPlan,liveLongitudinalMpc,radarState,controlsState,liveTracks,liveMpc,sendcan,carState,carControl', - '--no-interactive'] + unlogger_cmd = [os.path.join(BASEDIR, 'tools/replay/unlogger.py'), '%s' % route, '/tmp', '--disable', 'frame,plan,pathPlan,liveLongitudinalMpc,radarState,controlsState,liveTracks,liveMpc,sendcan,carState,carControl,carEvents,carParams', '--no-interactive'] unlogger = subprocess.Popen(unlogger_cmd, preexec_fn=os.setsid) print("Check sockets") @@ -544,9 +552,9 @@ def get_route_logs(route_name): for route in results: print(results[route]) - params.put("Passive", "0") # put back not passive to not leave the params in an unintended state + Params().put("Passive", "0") # put back not passive to not leave the params in an unintended state if not all(passed for passed, _ in results.values()): print("TEST FAILED") sys.exit(1) else: - print("TEST SUCESSFUL") + print("TEST SUCCESSFUL") diff --git a/selfdrive/test/test_fingerprints.py b/selfdrive/test/test_fingerprints.py index b291ff6a1c1193..6b5e8378af081f 100755 --- a/selfdrive/test/test_fingerprints.py +++ b/selfdrive/test/test_fingerprints.py @@ -3,6 +3,14 @@ import sys from common.basedir import BASEDIR +# messages reserved for CAN based ignition (see can_ignition_hook function in panda/board/drivers/can) +# (addr, len) +CAN_IGNITION_MSGS = { + 'gm': [(0x1F1, 8), (0x160, 5)], + 'tesla' : [(0x348, 8)], + 'volkswagen' : [(0x3C0, 4)], +} + def _get_fingerprints(): # read all the folders in selfdrive/car and return a dict where: # - keys are all the car names that which we have a fingerprint dict for @@ -20,9 +28,9 @@ def _get_fingerprints(): def check_fingerprint_consistency(f1, f2): # return false if it finds a fingerprint fully included in another - # max message worth checking is 1800, as above that they usually come too infrequently and not # usable for fingerprinting + max_msg = 1800 is_f1_in_f2 = True @@ -38,15 +46,33 @@ def check_fingerprint_consistency(f1, f2): return not is_f1_in_f2 and not is_f2_in_f1 +def check_can_ignition_conflicts(fingerprints, brands): + # loops through all the fingerprints and exits if CAN ignition dedicated messages + # are found in unexpected fingerprints + + for brand_can, msgs_can in CAN_IGNITION_MSGS.items(): + for i, f in enumerate(fingerprints): + for msg_can in msgs_can: + if brand_can != brands[i] and msg_can[0] in f and msg_can[1] == f[msg_can[0]]: + print("CAN ignition dedicated msg %d with len %d found in %s fingerprints!" % (msg_can[0], msg_can[1], brands[i])) + print("TEST FAILED") + sys.exit(1) + + fingerprints = _get_fingerprints() + fingerprints_flat = [] car_names = [] +brand_names = [] for brand in fingerprints: for car in fingerprints[brand]: fingerprints_flat += fingerprints[brand][car] for i in range(len(fingerprints[brand][car])): car_names.append(car) + brand_names.append(brand) +# first check if CAN ignition specific messages are unexpectedly included in other fingerprints +check_can_ignition_conflicts(fingerprints_flat, brand_names) valid = True for idx1, f1 in enumerate(fingerprints_flat): diff --git a/selfdrive/thermald.py b/selfdrive/thermald.py index 22a59f027da5f2..eeec3f3b11a1b8 100755 --- a/selfdrive/thermald.py +++ b/selfdrive/thermald.py @@ -8,13 +8,15 @@ from common.basedir import BASEDIR from common.params import Params from common.realtime import sec_since_boot, DT_TRML -from common.numpy_fast import clip +from common.numpy_fast import clip, interp from common.filter_simple import FirstOrderFilter from selfdrive.version import terms_version, training_version from selfdrive.swaglog import cloudlog import selfdrive.messaging as messaging -from selfdrive.services import service_list from selfdrive.loggerd.config import get_available_percent +from selfdrive.pandad import get_expected_version + +FW_VERSION = get_expected_version() ThermalStatus = log.ThermalData.ThermalStatus CURRENT_TAU = 15. # 15s time constant @@ -94,7 +96,7 @@ def set_eon_fan(val): _BAT_TEMP_THERSHOLD = 45. -def handle_fan(max_cpu_temp, bat_temp, fan_speed): +def handle_fan_eon(max_cpu_temp, bat_temp, fan_speed): new_speed_h = next(speed for speed, temp_h in zip(_FAN_SPEEDS, _TEMP_THRS_H) if temp_h > max_cpu_temp) new_speed_l = next(speed for speed, temp_l in zip(_FAN_SPEEDS, _TEMP_THRS_L) if temp_l > max_cpu_temp) @@ -113,6 +115,9 @@ def handle_fan(max_cpu_temp, bat_temp, fan_speed): return fan_speed +def handle_fan_uno(max_cpu_temp, bat_temp, fan_speed): + # TODO: implement better fan control + return int(interp(max_cpu_temp, [40.0, 80.0], [0, 100])) def thermald_thread(): setup_eon_fan() @@ -120,10 +125,13 @@ def thermald_thread(): # prevent LEECO from undervoltage BATT_PERC_OFF = 10 if LEON else 3 + health_timeout = int(1000 * 2 * DT_TRML) # 2x the expected health frequency + # now loop - thermal_sock = messaging.pub_sock(service_list['thermal'].port) - health_sock = messaging.sub_sock(service_list['health'].port) - location_sock = messaging.sub_sock(service_list['gpsLocation'].port) + thermal_sock = messaging.pub_sock('thermal') + health_sock = messaging.sub_sock('health', timeout=health_timeout) + location_sock = messaging.sub_sock('gpsLocation') + fan_speed = 0 count = 0 @@ -134,10 +142,12 @@ def thermald_thread(): thermal_status_prev = ThermalStatus.green usb_power = True usb_power_prev = True - health_sock.RCVTIMEO = int(1000 * 2 * DT_TRML) # 2x the expected health frequency + current_filter = FirstOrderFilter(0., CURRENT_TAU, DT_TRML) health_prev = None + fw_version_match_prev = True current_connectivity_alert = None + time_valid_prev = True params = Params() @@ -178,7 +188,12 @@ def thermald_thread(): msg.thermal.cpu2, msg.thermal.cpu3) / 10.0 max_comp_temp = max(max_cpu_temp, msg.thermal.mem / 10., msg.thermal.gpu / 10.) bat_temp = msg.thermal.bat/1000. - fan_speed = handle_fan(max_cpu_temp, bat_temp, fan_speed) + + if health is not None and health.health.hwType == log.HealthData.HwType.uno: + fan_speed = handle_fan_uno(max_cpu_temp, bat_temp, fan_speed) + else: + fan_speed = handle_fan_eon(max_cpu_temp, bat_temp, fan_speed) + msg.thermal.fanSpeed = fan_speed # thermal logic with hysterisis @@ -205,6 +220,16 @@ def thermald_thread(): # Check for last update time and display alerts if needed now = datetime.datetime.now() + + # show invalid date/time alert + time_valid = now.year >= 2019 + if time_valid and not time_valid_prev: + params.delete("Offroad_InvalidTime") + if not time_valid and time_valid_prev: + params.put("Offroad_InvalidTime", json.dumps(OFFROAD_ALERTS["Offroad_InvalidTime"])) + time_valid_prev = time_valid + + # Show update prompt try: last_update = datetime.datetime.fromisoformat(params.get("LastUpdateTime", encoding='utf8')) except (TypeError, ValueError): @@ -230,11 +255,13 @@ def thermald_thread(): params.delete("Offroad_ConnectivityNeededPrompt") # start constellation of processes when the car starts - ignition = health is not None and health.health.started + ignition = health is not None and (health.health.ignitionLine or health.health.ignitionCan) do_uninstall = params.get("DoUninstall") == b"1" accepted_terms = params.get("HasAcceptedTerms") == terms_version completed_training = params.get("CompletedTrainingVersion") == training_version + fw_version = params.get("PandaFirmware", encoding="utf8") + fw_version_match = fw_version is None or fw_version.startswith(FW_VERSION) # don't show alert is no panda is connected (None) should_start = ignition @@ -247,6 +274,17 @@ def thermald_thread(): # confirm we have completed training and aren't uninstalling should_start = should_start and accepted_terms and (passive or completed_training) and (not do_uninstall) + # check for firmware mismatch + should_start = should_start and fw_version_match + + # check if system time is valid + should_start = should_start and time_valid + + if fw_version_match and not fw_version_match_prev: + params.delete("Offroad_PandaFirmwareMismatch") + if not fw_version_match and fw_version_match_prev: + params.put("Offroad_PandaFirmwareMismatch", json.dumps(OFFROAD_ALERTS["Offroad_PandaFirmwareMismatch"])) + # if any CPU gets above 107 or the battery gets above 63, kill all processes # controls will warn with CPU above 95 or battery above 60 if thermal_status >= ThermalStatus.danger: @@ -289,6 +327,7 @@ def thermald_thread(): thermal_status_prev = thermal_status usb_power_prev = usb_power + fw_version_match_prev = fw_version_match print(msg) diff --git a/selfdrive/ui/Makefile b/selfdrive/ui/Makefile index c00d9df28d70ed..24f7b4878dedec 100644 --- a/selfdrive/ui/Makefile +++ b/selfdrive/ui/Makefile @@ -1,7 +1,7 @@ CC = clang CXX = clang++ - +BASEDIR = ../.. PHONELIBS = ../../phonelibs WARN_FLAGS = -Werror=implicit-function-declaration \ @@ -13,7 +13,10 @@ WARN_FLAGS = -Werror=implicit-function-declaration \ CFLAGS = -std=gnu11 -fPIC -O2 $(WARN_FLAGS) CXXFLAGS = -std=c++11 -fPIC -O2 $(WARN_FLAGS) -ZMQ_LIBS = -l:libczmq.a -l:libzmq.a -lgnustl_shared +ZMQ_LIBS = -l:libczmq.a + +MESSAGING_FLAGS = -I$(BASEDIR)/selfdrive/messaging +MESSAGING_LIBS = $(BASEDIR)/selfdrive/messaging/messaging.a CEREAL_LIBS = -l:libcapn.a CEREAL_OBJS = ../../cereal/gen/c/log.capnp.o ../../cereal/gen/c/car.capnp.o @@ -41,10 +44,9 @@ CXXFLAGS += -DQCOM \ -I$(PHONELIBS)/android_system_core/include \ -I$(PHONELIBS)/android_hardware_libhardware/include -ifeq ($(ARCH),aarch64) +# ui can only be compiled for the phone CFLAGS += -mcpu=cortex-a57 CXXFLAGS += -mcpu=cortex-a57 -endif OBJS = slplay.o \ ui.o \ @@ -66,14 +68,15 @@ DEPS := $(OBJS:.o=.d) all: ui -ui: $(OBJS) +ui: $(OBJS) $(MESSAGING_LIBS) @echo "[ LINK ] $@" $(CXX) -fPIC -o '$@' $^ \ $(FRAMEBUFFER_LIBS) \ $(CEREAL_LIBS) \ - $(ZMQ_LIBS) \ + -lgnustl_shared \ -L/system/vendor/lib64 \ -lhardware -lui \ + $(ZMQ_LIBS) \ $(OPENGL_LIBS) \ $(OPENCL_LIBS) \ ${OPENSL_LIBS} \ @@ -93,6 +96,11 @@ slplay.o: slplay.c $(CXX) $(CXXFLAGS) -MMD \ -Iinclude -I.. -I../.. \ $(OPENCL_FLAGS) \ + $(NANOVG_FLAGS) \ + $(ZMQ_FLAGS) \ + $(MESSAGING_FLAGS) \ + $(CEREAL_CFLAGS) \ + $(JSON_FLAGS) \ -I$(PHONELIBS)/android_frameworks_native/include \ -I$(PHONELIBS)/android_system_core/include \ -I$(PHONELIBS)/android_hardware_libhardware/include \ diff --git a/selfdrive/ui/ui.c b/selfdrive/ui/ui.cc similarity index 66% rename from selfdrive/ui/ui.c rename to selfdrive/ui/ui.cc index 4563a7a4e4f011..0e3f9fc61bab5f 100644 --- a/selfdrive/ui/ui.c +++ b/selfdrive/ui/ui.cc @@ -24,7 +24,10 @@ #include "common/util.h" #include "common/swaglog.h" #include "common/mat.h" + +extern "C"{ #include "common/glutil.h" +} #include "common/touch.h" #include "common/framebuffer.h" @@ -34,16 +37,18 @@ #include "common/params.h" #include "cereal/gen/c/log.capnp.h" + +extern "C"{ #include "slplay.h" +} -#include "devicestate.c" +#include "messaging.hpp" #define STATUS_STOPPED 0 #define STATUS_DISENGAGED 1 #define STATUS_ENGAGED 2 #define STATUS_WARNING 3 #define STATUS_ALERT 4 -#define STATUS_MAX 5 #define ALERTSIZE_NONE 0 #define ALERTSIZE_SMALL 1 @@ -51,8 +56,8 @@ #define ALERTSIZE_FULL 3 #define UI_BUF_COUNT 4 -#define SHOW_SPEEDLIMIT 1 -#define DEBUG_TURN +//#define SHOW_SPEEDLIMIT 1 +//#define DEBUG_TURN //#define DEBUG_FPS @@ -60,9 +65,8 @@ const int vwp_w = 1920; const int vwp_h = 1080; const int nav_w = 640; const int nav_ww= 760; -const int sbr_w = 0; //300; -const int bdr_s = 0; //30; -const int bdr_is = 30; +const int sbr_w = 300; +const int bdr_s = 30; const int box_x = sbr_w+bdr_s; const int box_y = bdr_s; const int box_w = vwp_w-sbr_w-(bdr_s*2); @@ -101,17 +105,6 @@ const int alert_sizes[] = { [ALERTSIZE_FULL] = vwp_h, }; -#define UIEVENT_BTN1 1 -#define UIEVENT_BTN2 2 -#define UIEVENT_BTN3 3 -#define UIEVENT_BTN4 4 -#define UIEVENT_BTN5 5 -#define UIEVENT_BTN6 6 -#define UIEVENT_BTN7 7 -#define UIEVENT_BTN8 8 -#define UIEVENT_STARTUP 10 -#define UIEVENT_SHUTDOWN 11 - const int SET_SPEED_NA = 255; // TODO: this is also hardcoded in common/transformations/camera.py @@ -136,19 +129,15 @@ typedef struct UIScene { float mpc_y[50]; bool world_objects_visible; - mat3 warp_matrix; // transformed box -> frame. mat4 extrinsic_matrix; // Last row is 0 so we can use mat4. float v_cruise; uint64_t v_cruise_update_ts; float v_ego; bool decel_for_model; - bool decel_for_turn; float speedlimit; - float speedlimitaheaddistance; bool speedlimit_valid; - bool speedlimitahead_valid; bool map_valid; float curvature; @@ -178,31 +167,6 @@ typedef struct UIScene { uint64_t started_ts; - - //BB CPU TEMP - uint16_t maxCpuTemp; - uint32_t maxBatTemp; - float gpsAccuracy; - float freeSpace; - float angleSteers; - float angleSteersDes; - float output_scale; - bool recording; - bool recordDash; - //BB END CPU TEMP - bool steerOverride; - // Used to display calibration progress - int cal_status; - int cal_perc; - - - - bool brakeLights; - bool leftBlinker; - bool rightBlinker; - int blinker_blinkingrate; - - bool is_playing_alert; // Used to show gps planner status bool gps_planner_active; } UIScene; @@ -241,23 +205,18 @@ typedef struct UIState { int img_turn; int img_face; int img_map; - int img_brake; - int img_speed; - - void *ctx; - - void *thermal_sock_raw; - void *model_sock_raw; - void *controlsstate_sock_raw; - void *livecalibration_sock_raw; - void *radarstate_sock_raw; - void *livempc_sock_raw; - void *plus_sock_raw; - void *map_data_sock_raw; - void *gps_sock_raw; - void *carstate_sock_raw; - void *uilayout_sock_raw; + // Sockets + Context *ctx; + SubSocket *thermal_sock; + SubSocket *model_sock; + SubSocket *controlsstate_sock; + SubSocket *livecalibration_sock; + SubSocket *radarstate_sock; + SubSocket *plus_sock; + SubSocket *map_data_sock; + SubSocket *uilayout_sock; + Poller * poller; int plus_state; @@ -286,11 +245,11 @@ typedef struct UIState { GLint line_pos_loc, line_color_loc; GLint line_transform_loc; - unsigned int rgb_width, rgb_height, rgb_stride; + int rgb_width, rgb_height, rgb_stride; size_t rgb_buf_len; mat4 rgb_transform; - unsigned int rgb_front_width, rgb_front_height, rgb_front_stride; + int rgb_front_width, rgb_front_height, rgb_front_stride; size_t rgb_front_buf_len; UIScene scene; @@ -299,12 +258,15 @@ typedef struct UIState { int awake_timeout; int volume_timeout; + int controls_timeout; int alert_sound_timeout; int speed_lim_off_timeout; int is_metric_timeout; int longitudinal_control_timeout; int limit_set_speed_timeout; + bool controls_seen; + int status; bool is_metric; bool longitudinal_control; @@ -331,15 +293,8 @@ typedef struct UIState { model_path_vertices_data model_path_vertices[MODEL_LANE_PATH_CNT * 2]; track_vertices_data track_vertices[2]; - - bool ignoreLayout; - int touchTimeout; - } UIState; -#include "dashcam.h" -//#include "dashboard.h" - static int last_brightness = -1; static void set_brightness(UIState *s, int brightness) { if (last_brightness != brightness && (s->awake || brightness == 0)) { @@ -388,7 +343,7 @@ static void set_do_exit(int sig) { do_exit = 1; } -static void read_param_bool(bool* param, char* param_name) { +static void read_param_bool(bool* param, const char* param_name) { char *s; const int result = read_db_value(NULL, param_name, &s, NULL); if (result == 0) { @@ -397,7 +352,7 @@ static void read_param_bool(bool* param, char* param_name) { } } -static void read_param_float(float* param, char* param_name) { +static void read_param_float(float* param, const char* param_name) { char *s; const int result = read_db_value(NULL, param_name, &s, NULL); if (result == 0) { @@ -406,7 +361,7 @@ static void read_param_float(float* param, char* param_name) { } } -static void read_param_bool_timeout(bool* param, char* param_name, int* timeout) { +static void read_param_bool_timeout(bool* param, const char* param_name, int* timeout) { if (*timeout > 0){ (*timeout)--; } else { @@ -415,7 +370,7 @@ static void read_param_bool_timeout(bool* param, char* param_name, int* timeout) } } -static void read_param_float_timeout(float* param, char* param_name, int* timeout) { +static void read_param_float_timeout(float* param, const char* param_name, int* timeout) { if (*timeout > 0){ (*timeout)--; } else { @@ -511,6 +466,25 @@ sound_file* get_sound_file(AudibleAlert alert) { return NULL; } +void play_alert_sound(AudibleAlert alert) { + sound_file* sound = get_sound_file(alert); + char* error = NULL; + + slplay_play(sound->uri, sound->loop, &error); + if(error) { + LOGW("error playing sound: %s", error); + } +} + +void stop_alert_sound(AudibleAlert alert) { + sound_file* sound = get_sound_file(alert); + char* error = NULL; + + slplay_stop_uri(sound->uri, &error); + if(error) { + LOGW("error stopping sound: %s", error); + } +} void ui_sound_init(char **error) { slplay_setup(error); @@ -524,26 +498,31 @@ void ui_sound_init(char **error) { static void ui_init(UIState *s) { memset(s, 0, sizeof(UIState)); - s->ignoreLayout = true; pthread_mutex_init(&s->lock, NULL); pthread_cond_init(&s->bg_cond, NULL); - s->ctx = zmq_ctx_new(); - - s->thermal_sock_raw = sub_sock(s->ctx, "tcp://127.0.0.1:8005"); - s->model_sock_raw = sub_sock(s->ctx, "tcp://127.0.0.1:8009"); - s->controlsstate_sock_raw = sub_sock(s->ctx, "tcp://127.0.0.1:8007"); - s->uilayout_sock_raw = sub_sock(s->ctx, "tcp://127.0.0.1:8060"); - s->livecalibration_sock_raw = sub_sock(s->ctx, "tcp://127.0.0.1:8019"); - s->radarstate_sock_raw = sub_sock(s->ctx, "tcp://127.0.0.1:8012"); - s->livempc_sock_raw = sub_sock(s->ctx, "tcp://127.0.0.1:8035"); - s->plus_sock_raw = sub_sock(s->ctx, "tcp://127.0.0.1:8037"); - s->gps_sock_raw = sub_sock(s->ctx, "tcp://127.0.0.1:8032"); - s->carstate_sock_raw = sub_sock(s->ctx, "tcp://127.0.0.1:8021"); + s->ctx = Context::create(); + s->thermal_sock = SubSocket::create(s->ctx, "thermal"); + s->model_sock = SubSocket::create(s->ctx, "model"); + s->controlsstate_sock = SubSocket::create(s->ctx, "controlsState"); + s->uilayout_sock = SubSocket::create(s->ctx, "uiLayoutState"); + s->livecalibration_sock = SubSocket::create(s->ctx, "liveCalibration"); + s->radarstate_sock = SubSocket::create(s->ctx, "radarState"); + s->plus_sock = SubSocket::create(s->ctx, "plusFrame"); + s->poller = Poller::create({ + s->thermal_sock, + s->model_sock, + s->controlsstate_sock, + s->uilayout_sock, + s->livecalibration_sock, + s->radarstate_sock, + s->plus_sock + }); #ifdef SHOW_SPEEDLIMIT - s->map_data_sock_raw = sub_sock(s->ctx, "tcp://127.0.0.1:8065"); + s->map_data_sock = SubSock::create(s->ctx, "liveMapData"); + s->poller.registerSocket(s->map_data_sock); #endif s->ipc_fd = -1; @@ -580,12 +559,6 @@ static void ui_init(UIState *s) { assert(s->img_map >= 0); s->img_map = nvgCreateImage(s->vg, "../assets/img_map.png", 1); - assert(s->img_brake >= 0); - s->img_brake = nvgCreateImage(s->vg, "../assets/img_brake_disc.png", 1); - - assert(s->img_speed >= 0); - s->img_speed = nvgCreateImage(s->vg, "../assets/img_trafficSign_speedahead.png", 1); - // init gl s->frame_program = load_program(frame_vertex_shader, frame_fragment_shader); assert(s->frame_program); @@ -688,7 +661,7 @@ static void ui_init_vision(UIState *s, const VisionStreamBufs back_bufs, .front_box_width = ui_info.front_box_width, .front_box_height = ui_info.front_box_height, .world_objects_visible = false, // Invisible until we receive a calibration message. - //.gps_planner_active = false, + .gps_planner_active = false, }; s->rgb_width = back_bufs.width; @@ -702,10 +675,10 @@ static void ui_init_vision(UIState *s, const VisionStreamBufs back_bufs, s->rgb_front_buf_len = front_bufs.buf_len; s->rgb_transform = (mat4){{ - 2.0/s->rgb_width, 0.0, 0.0, -1.0, - 0.0, 2.0/s->rgb_height, 0.0, -1.0, - 0.0, 0.0, 1.0, 0.0, - 0.0, 0.0, 0.0, 1.0, + 2.0f/s->rgb_width, 0.0f, 0.0f, -1.0f, + 0.0f, 2.0f/s->rgb_height, 0.0f, -1.0f, + 0.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f, }}; read_param_float(&s->speed_lim_off, "SpeedLimitOffset"); @@ -719,43 +692,6 @@ static void ui_init_vision(UIState *s, const VisionStreamBufs back_bufs, s->limit_set_speed_timeout = UI_FREQ; } -static void ui_draw_transformed_box(UIState *s, uint32_t color) { - const UIScene *scene = &s->scene; - - const mat3 bbt = scene->warp_matrix; - - struct { - vec3 pos; - uint32_t color; - } verts[] = { - {matvecmul3(bbt, (vec3){{0.0, 0.0, 1.0,}}), color}, - {matvecmul3(bbt, (vec3){{scene->transformed_width, 0.0, 1.0,}}), color}, - {matvecmul3(bbt, (vec3){{scene->transformed_width, scene->transformed_height, 1.0,}}), color}, - {matvecmul3(bbt, (vec3){{0.0, scene->transformed_height, 1.0,}}), color}, - {matvecmul3(bbt, (vec3){{0.0, 0.0, 1.0,}}), color}, - }; - - for (int i=0; irgb_height - verts[i].pos.v[1] / verts[i].pos.v[2]; - } - - glUseProgram(s->line_program); - - mat4 out_mat = matmul(device_transform, - matmul(frame_transform, s->rgb_transform)); - glUniformMatrix4fv(s->line_transform_loc, 1, GL_TRUE, out_mat.v); - - glEnableVertexAttribArray(s->line_pos_loc); - glVertexAttribPointer(s->line_pos_loc, 2, GL_FLOAT, GL_FALSE, sizeof(verts[0]), &verts[0].pos.v[0]); - - glEnableVertexAttribArray(s->line_color_loc); - glVertexAttribPointer(s->line_color_loc, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(verts[0]), &verts[0].color); - - assert(glGetError() == GL_NO_ERROR); - glDrawArrays(GL_LINE_STRIP, 0, ARRAYSIZE(verts)); -} - // Projects a point in car to space to the corresponding point in full frame // image space. vec3 car_space_to_full_frame(const UIState *s, vec4 car_space_projective) { @@ -868,8 +804,8 @@ static void update_track_data(UIState *s, bool is_mpc, track_vertices_data *pvd) bool started = false; float off = is_mpc?0.3:0.5; float lead_d = scene->lead_d_rel*2.; - float path_height = is_mpc?(lead_d>5.)?min(lead_d, 25.)-min(lead_d*0.35, 10.):20. - :(lead_d>0.)?min(lead_d, 50.)-min(lead_d*0.35, 10.):49.; + float path_height = is_mpc?(lead_d>5.)?fmin(lead_d, 25.)-fmin(lead_d*0.35, 10.):20. + :(lead_d>0.)?fmin(lead_d, 50.)-fmin(lead_d*0.35, 10.):49.; pvd->cnt = 0; // left side up for (int i=0; i<=path_height; i++) { @@ -880,14 +816,12 @@ static void update_track_data(UIState *s, bool is_mpc, track_vertices_data *pvd) py = mpc_y_coords[i] - off; } else { px = lerp(i+1.0, i, i/100.0); - py = path.points[i] - (off); + py = path.points[i] - off; } vec4 p_car_space = (vec4){{px, py, 0., 1.}}; vec3 p_full_frame = car_space_to_full_frame(s, p_car_space); - float x = p_full_frame.v[0]; - float y = p_full_frame.v[1]; - if (x < 0 || y < 0) { + if (p_full_frame.v[0] < 0. || p_full_frame.v[1] < 0.) { continue; } pvd->v[pvd->cnt].x = p_full_frame.v[0]; @@ -943,8 +877,8 @@ const UIScene *scene = &s->scene; bool started = false; float off = is_mpc?0.3:0.5; float lead_d = scene->lead_d_rel*2.; - float path_height = is_mpc?(lead_d>5.)?min(lead_d, 25.)-min(lead_d*0.35, 10.):20. - :(lead_d>0.)?min(lead_d, 50.)-min(lead_d*0.35, 10.):49.; + float path_height = is_mpc?(lead_d>5.)?fmin(lead_d, 25.)-fmin(lead_d*0.35, 10.):20. + :(lead_d>0.)?fmin(lead_d, 50.)-fmin(lead_d*0.35, 10.):49.; int vi = 0; for(int i = 0;i < pvd->cnt;i++) { if (pvd->v[i].x < 0 || pvd->v[i].y < 0) { @@ -964,21 +898,13 @@ const UIScene *scene = &s->scene; NVGpaint track_bg; if (is_mpc) { // Draw colored MPC track - if (scene->steerOverride) { - track_bg = nvgLinearGradient(s->vg, vwp_w, vwp_h, vwp_w, vwp_h*.4, - nvgRGBA(0, 191, 255, 255), nvgRGBA(0, 95, 128, 50)); - } else { - int torque_scale = (int)fabs(510*(float)s->scene.output_scale); - int red_lvl = min(255, torque_scale); - int green_lvl = min(255, 510-torque_scale); - track_bg = nvgLinearGradient(s->vg, vwp_w, vwp_h, vwp_w, vwp_h*.4, - nvgRGBA( red_lvl, green_lvl, 0, 255), - nvgRGBA((int)(0.5*red_lvl), (int)(0.5*green_lvl), 0, 50)); - } + const uint8_t *clr = bg_colors[s->status]; + track_bg = nvgLinearGradient(s->vg, vwp_w, vwp_h, vwp_w, vwp_h*.4, + nvgRGBA(clr[0], clr[1], clr[2], 255), nvgRGBA(clr[0], clr[1], clr[2], 255/2)); } else { // Draw white vision track track_bg = nvgLinearGradient(s->vg, vwp_w, vwp_h, vwp_w, vwp_h*.4, - nvgRGBA(255, 255, 255, 200), nvgRGBA(255, 255, 255, 50)); + nvgRGBA(255, 255, 255, 255), nvgRGBA(255, 255, 255, 0)); } nvgFillPaint(s->vg, track_bg); @@ -998,12 +924,14 @@ static void draw_steering(UIState *s, float curvature) { static void draw_frame(UIState *s) { const UIScene *scene = &s->scene; + float x1, x2, y1, y2; if (s->scene.frontview) { glBindVertexArray(s->frame_vao[1]); } else { glBindVertexArray(s->frame_vao[0]); } + mat4 *out_mat; if (s->scene.frontview || s->scene.fullview) { out_mat = &s->front_frame_mat; @@ -1016,9 +944,11 @@ static void draw_frame(UIState *s) { } else if (!scene->frontview && s->cur_vision_idx >= 0) { glBindTexture(GL_TEXTURE_2D, s->frame_texs[s->cur_vision_idx]); } + glUseProgram(s->frame_program); glUniform1i(s->frame_texture_loc, 0); glUniformMatrix4fv(s->frame_transform_loc, 1, GL_TRUE, out_mat->v); + assert(glGetError() == GL_NO_ERROR); glEnableVertexAttribArray(0); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, (const void*)0); @@ -1058,14 +988,14 @@ static void update_lane_line_data(UIState *s, const float *points, float off, bo static void update_all_lane_lines_data(UIState *s, const PathData path, model_path_vertices_data *pstart) { update_lane_line_data(s, path.points, 0.025*path.prob, false, pstart); - float var = min(path.std, 0.7); + float var = fmin(path.std, 0.7); update_lane_line_data(s, path.points, -var, true, pstart + 1); update_lane_line_data(s, path.points, var, true, pstart + 2); } static void ui_draw_lane(UIState *s, const PathData *path, model_path_vertices_data *pstart, NVGcolor color) { ui_draw_lane_line(s, pstart, color); - float var = min(path->std, 0.7); + float var = fmin(path->std, 0.7); color.a /= 4; ui_draw_lane_line(s, pstart + 1, color); ui_draw_lane_line(s, pstart + 2, color); @@ -1125,395 +1055,13 @@ static void ui_draw_world(UIState *s) { if (scene->lead_v_rel < 0) { fillAlpha += 255*(-1*(scene->lead_v_rel/speedBuff)); } - fillAlpha = (int)(min(fillAlpha, 255)); + fillAlpha = (int)(fmin(fillAlpha, 255)); } draw_chevron(s, scene->lead_d_rel+2.7, scene->lead_y_rel, 25, - nvgRGBA(201, 34, 49, fillAlpha), nvgRGBA(255, 255, 255, 255)); - } -} - -//BB START: functions added for the display of various items -static int bb_ui_draw_measure(UIState *s, const char* bb_value, const char* bb_uom, const char* bb_label, - int bb_x, int bb_y, int bb_uom_dx, - NVGcolor bb_valueColor, NVGcolor bb_labelColor, NVGcolor bb_uomColor, - int bb_valueFontSize, int bb_labelFontSize, int bb_uomFontSize ) { - const UIScene *scene = &s->scene; - nvgTextAlign(s->vg, NVG_ALIGN_CENTER | NVG_ALIGN_BASELINE); - int dx = 0; - if (strlen(bb_uom) > 0) { - dx = (int)(bb_uomFontSize*2.5/2); - } - //print value - nvgFontFace(s->vg, "sans-semibold"); - nvgFontSize(s->vg, bb_valueFontSize*2.5); - nvgFillColor(s->vg, bb_valueColor); - nvgText(s->vg, bb_x-dx/2, bb_y+ (int)(bb_valueFontSize*2.5)+5, bb_value, NULL); - //print label - nvgFontFace(s->vg, "sans-regular"); - nvgFontSize(s->vg, bb_labelFontSize*2.5); - nvgFillColor(s->vg, bb_labelColor); - nvgText(s->vg, bb_x, bb_y + (int)(bb_valueFontSize*2.5)+5 + (int)(bb_labelFontSize*2.5)+5, bb_label, NULL); - //print uom - if (strlen(bb_uom) > 0) { - nvgSave(s->vg); - int rx =bb_x + bb_uom_dx + bb_valueFontSize -3; - int ry = bb_y + (int)(bb_valueFontSize*2.5/2)+25; - nvgTranslate(s->vg,rx,ry); - nvgRotate(s->vg, -1.5708); //-90deg in radians - nvgFontFace(s->vg, "sans-regular"); - nvgFontSize(s->vg, (int)(bb_uomFontSize*2.5)); - nvgFillColor(s->vg, bb_uomColor); - nvgText(s->vg, 0, 0, bb_uom, NULL); - nvgRestore(s->vg); - } - return (int)((bb_valueFontSize + bb_labelFontSize)*2.5) + 5; -} - -static void bb_ui_draw_measures_left(UIState *s, int bb_x, int bb_y, int bb_w ) { - const UIScene *scene = &s->scene; - int bb_rx = bb_x + (int)(bb_w/2); - int bb_ry = bb_y; - int bb_h = 5; - NVGcolor lab_color = nvgRGBA(255, 255, 255, 200); - NVGcolor uom_color = nvgRGBA(255, 255, 255, 200); - int value_fontSize=30; - int label_fontSize=15; - int uom_fontSize = 15; - int bb_uom_dx = (int)(bb_w /2 - uom_fontSize*2.5) ; - - //add CPU temperature - if (true) { - char val_str[16]; - char uom_str[6]; - NVGcolor val_color = nvgRGBA(255, 255, 255, 200); - if((int)(scene->maxCpuTemp/10) > 80) { - val_color = nvgRGBA(255, 188, 3, 200); - } - if((int)(scene->maxCpuTemp/10) > 92) { - val_color = nvgRGBA(255, 0, 0, 200); - } - // temp is alway in C * 10 - snprintf(val_str, sizeof(val_str), "%d°C", (int)(scene->maxCpuTemp/10)); - snprintf(uom_str, sizeof(uom_str), ""); - bb_h +=bb_ui_draw_measure(s, val_str, uom_str, "CPU TEMP", - bb_rx, bb_ry, bb_uom_dx, - val_color, lab_color, uom_color, - value_fontSize, label_fontSize, uom_fontSize ); - bb_ry = bb_y + bb_h; - } - - //add battery temperature - if (true) { - char val_str[16]; - char uom_str[6]; - NVGcolor val_color = nvgRGBA(255, 255, 255, 200); - if((int)(scene->maxBatTemp/1000) > 40) { - val_color = nvgRGBA(255, 188, 3, 200); - } - if((int)(scene->maxBatTemp/1000) > 50) { - val_color = nvgRGBA(255, 0, 0, 200); - } - // temp is alway in C * 1000 - snprintf(val_str, sizeof(val_str), "%d°C", (int)(scene->maxBatTemp/1000)); - snprintf(uom_str, sizeof(uom_str), ""); - bb_h +=bb_ui_draw_measure(s, val_str, uom_str, "BAT TEMP", - bb_rx, bb_ry, bb_uom_dx, - val_color, lab_color, uom_color, - value_fontSize, label_fontSize, uom_fontSize ); - bb_ry = bb_y + bb_h; - } - - //add grey panda GPS accuracy - if (true) { - char val_str[16]; - char uom_str[3]; - NVGcolor val_color = nvgRGBA(255, 255, 255, 200); - //show red/orange if gps accuracy is high - if(scene->gpsAccuracy > 0.59) { - val_color = nvgRGBA(255, 188, 3, 200); - } - if(scene->gpsAccuracy > 0.8) { - val_color = nvgRGBA(255, 0, 0, 200); - } - - // gps accuracy is always in meters - snprintf(val_str, sizeof(val_str), "%.2f", (s->scene.gpsAccuracy)); - snprintf(uom_str, sizeof(uom_str), "m");; - bb_h +=bb_ui_draw_measure(s, val_str, uom_str, "GPS PREC", - bb_rx, bb_ry, bb_uom_dx, - val_color, lab_color, uom_color, - value_fontSize, label_fontSize, uom_fontSize ); - bb_ry = bb_y + bb_h; - } - - //add free space - from bthaler1 - if (true) { - char val_str[16]; - char uom_str[3]; - NVGcolor val_color = nvgRGBA(255, 255, 255, 200); - - //show red/orange if free space is low - if(scene->freeSpace < 0.4) { - val_color = nvgRGBA(255, 188, 3, 200); - } - if(scene->freeSpace < 0.2) { - val_color = nvgRGBA(255, 0, 0, 200); - } - - snprintf(val_str, sizeof(val_str), "%.0f%%", s->scene.freeSpace* 100); - snprintf(uom_str, sizeof(uom_str), ""); - - bb_h +=bb_ui_draw_measure(s, val_str, uom_str, "FREE SPACE", - bb_rx, bb_ry, bb_uom_dx, - val_color, lab_color, uom_color, - value_fontSize, label_fontSize, uom_fontSize ); - bb_ry = bb_y + bb_h; - } - - //finally draw the frame - bb_h += 20; - nvgBeginPath(s->vg); - nvgRoundedRect(s->vg, bb_x, bb_y, bb_w, bb_h, 20); - nvgStrokeColor(s->vg, nvgRGBA(255,255,255,80)); - nvgStrokeWidth(s->vg, 6); - nvgStroke(s->vg); -} - - -static void bb_ui_draw_measures_right(UIState *s, int bb_x, int bb_y, int bb_w ) { - const UIScene *scene = &s->scene; - int bb_rx = bb_x + (int)(bb_w/2); - int bb_ry = bb_y; - int bb_h = 5; - NVGcolor lab_color = nvgRGBA(255, 255, 255, 200); - NVGcolor uom_color = nvgRGBA(255, 255, 255, 200); - int value_fontSize=30; - int label_fontSize=15; - int uom_fontSize = 15; - int bb_uom_dx = (int)(bb_w /2 - uom_fontSize*2.5) ; - - //add visual radar relative distance - if (true) { - char val_str[16]; - char uom_str[6]; - NVGcolor val_color = nvgRGBA(255, 255, 255, 200); - if (scene->lead_status) { - //show RED if less than 5 meters - //show orange if less than 15 meters - if((int)(scene->lead_d_rel) < 15) { - val_color = nvgRGBA(255, 188, 3, 200); - } - if((int)(scene->lead_d_rel) < 5) { - val_color = nvgRGBA(255, 0, 0, 200); - } - // lead car relative distance is always in meters - snprintf(val_str, sizeof(val_str), "%d", (int)scene->lead_d_rel); - } else { - snprintf(val_str, sizeof(val_str), "-"); - } - snprintf(uom_str, sizeof(uom_str), "m "); - bb_h +=bb_ui_draw_measure(s, val_str, uom_str, "REL DIST", - bb_rx, bb_ry, bb_uom_dx, - val_color, lab_color, uom_color, - value_fontSize, label_fontSize, uom_fontSize ); - bb_ry = bb_y + bb_h; - } - - //add visual radar relative speed - if (true) { - char val_str[16]; - char uom_str[6]; - NVGcolor val_color = nvgRGBA(255, 255, 255, 200); - if (scene->lead_status) { - //show Orange if negative speed (approaching) - //show Orange if negative speed faster than 5mph (approaching fast) - if((int)(scene->lead_v_rel) < 0) { - val_color = nvgRGBA(255, 188, 3, 200); - } - if((int)(scene->lead_v_rel) < -5) { - val_color = nvgRGBA(255, 0, 0, 200); - } - // lead car relative speed is always in meters - if (s->is_metric) { - snprintf(val_str, sizeof(val_str), "%d", (int)(scene->lead_v_rel * 3.6 + 0.5)); - } else { - snprintf(val_str, sizeof(val_str), "%d", (int)(scene->lead_v_rel * 2.2374144 + 0.5)); - } - } else { - snprintf(val_str, sizeof(val_str), "-"); - } - if (s->is_metric) { - snprintf(uom_str, sizeof(uom_str), "km/h");; - } else { - snprintf(uom_str, sizeof(uom_str), "mph"); - } - bb_h +=bb_ui_draw_measure(s, val_str, uom_str, "REL SPEED", - bb_rx, bb_ry, bb_uom_dx, - val_color, lab_color, uom_color, - value_fontSize, label_fontSize, uom_fontSize ); - bb_ry = bb_y + bb_h; - } - - //add steering angle - if (true) { - char val_str[16]; - char uom_str[6]; - NVGcolor val_color = nvgRGBA(255, 255, 255, 200); - //show Orange if more than 6 degrees - //show red if more than 12 degrees - if(((int)(scene->angleSteers) < -6) || ((int)(scene->angleSteers) > 6)) { - val_color = nvgRGBA(255, 188, 3, 200); - } - if(((int)(scene->angleSteers) < -12) || ((int)(scene->angleSteers) > 12)) { - val_color = nvgRGBA(255, 0, 0, 200); - } - // steering is in degrees - snprintf(val_str, sizeof(val_str), "%.0f°",(scene->angleSteers)); - - snprintf(uom_str, sizeof(uom_str), ""); - bb_h +=bb_ui_draw_measure(s, val_str, uom_str, "REAL STEER", - bb_rx, bb_ry, bb_uom_dx, - val_color, lab_color, uom_color, - value_fontSize, label_fontSize, uom_fontSize ); - bb_ry = bb_y + bb_h; - } - - //add desired steering angle - if (true) { - char val_str[16]; - char uom_str[6]; - NVGcolor val_color = nvgRGBA(255, 255, 255, 200); - //show Orange if more than 6 degrees - //show red if more than 12 degrees - if(((int)(scene->angleSteersDes) < -6) || ((int)(scene->angleSteersDes) > 6)) { - val_color = nvgRGBA(255, 188, 3, 200); - } - if(((int)(scene->angleSteersDes) < -12) || ((int)(scene->angleSteersDes) > 12)) { - val_color = nvgRGBA(255, 0, 0, 200); - } - // steering is in degrees - snprintf(val_str, sizeof(val_str), "%.0f°",(scene->angleSteersDes)); - - snprintf(uom_str, sizeof(uom_str), ""); - bb_h +=bb_ui_draw_measure(s, val_str, uom_str, "DESIR STEER", - bb_rx, bb_ry, bb_uom_dx, - val_color, lab_color, uom_color, - value_fontSize, label_fontSize, uom_fontSize ); - bb_ry = bb_y + bb_h; - } - - - //finally draw the frame - bb_h += 20; - nvgBeginPath(s->vg); - nvgRoundedRect(s->vg, bb_x, bb_y, bb_w, bb_h, 20); - nvgStrokeColor(s->vg, nvgRGBA(255,255,255,80)); - nvgStrokeWidth(s->vg, 6); - nvgStroke(s->vg); -} - -//draw grid from wiki -static void ui_draw_vision_grid(UIState *s) -{ - const UIScene *scene = &s->scene; - bool is_cruise_set = (s->scene.v_cruise != 0 && s->scene.v_cruise != 255); - if (!is_cruise_set) - { - const int grid_spacing = 30; - - int ui_viz_rx = scene->ui_viz_rx; - int ui_viz_rw = scene->ui_viz_rw; - - nvgSave(s->vg); - - // path coords are worked out in rgb-box space - nvgTranslate(s->vg, 240.0f, 0.0); - - // zooom in 2x - nvgTranslate(s->vg, -1440.0f / 2, -1080.0f / 2); - nvgScale(s->vg, 2.0, 2.0); - - nvgScale(s->vg, 1440.0f / s->rgb_width, 1080.0f / s->rgb_height); - - nvgBeginPath(s->vg); - nvgStrokeColor(s->vg, nvgRGBA(255, 255, 255, 128)); - nvgStrokeWidth(s->vg, 1); - - for (int i = box_y; i < box_h; i += grid_spacing) - { - nvgMoveTo(s->vg, ui_viz_rx, i); - //nvgLineTo(s->vg, ui_viz_rx, i); - nvgLineTo(s->vg, ((ui_viz_rw + ui_viz_rx) / 2) + 10, i); - } - - for (int i = ui_viz_rx + 12; i <= ui_viz_rw; i += grid_spacing) - { - nvgMoveTo(s->vg, i, 0); - nvgLineTo(s->vg, i, 1000); - } - nvgStroke(s->vg); - nvgRestore(s->vg); + nvgRGBA(201, 34, 49, fillAlpha), nvgRGBA(218, 202, 37, 255)); } } -static void ui_draw_button(NVGcontext *vg, int x, int y, int w, int h, const char *label, bool highlight) { - nvgBeginPath(vg); - nvgRoundedRect(vg, x, y, w, h, 20); - nvgStrokeColor(vg, nvgRGBA(255, 255, 255, 80)); - nvgStrokeWidth(vg, 6); - nvgStroke(vg); - if(highlight) { - nvgFillColor(vg, nvgRGBA(128, 128, 128, 160)); - nvgFill(vg); - } - - nvgTextAlign(vg, NVG_ALIGN_CENTER | NVG_ALIGN_BASELINE); - nvgFontFace(vg, "sans-semibold"); - nvgFontSize(vg, (strlen(label)>2?30:40) * 2.5); - nvgFillColor(vg, nvgRGBA(255, 255, 255, 200)); - nvgText(vg, x + w/2, y + (int)(40 * 2.5) + 5, label, NULL); -} -static void bb_ui_draw_UI(UIState *s) -{ - /* - //get 3-state switch position - int tri_state_fd; - int tri_state_switch; - char buffer[10]; - tri_state_switch = 0; - tri_state_fd = open("/sys/devices/virtual/switch/tri-state-key/state", O_RDONLY); - //if we can't open then switch should be considered in the middle, nothing done - if (tri_state_fd == -1) - { - tri_state_switch = 1; - } - else - { - read(tri_state_fd, &buffer, 10); - tri_state_switch = buffer[0] - 48; - close(tri_state_fd); - } - s->ignoreLayout = (tri_state_switch==3); - if (tri_state_switch >= 2) - { - */ - const UIScene *scene = &s->scene; - const int bb_dml_w = 180; - const int bb_dml_x = (scene->ui_viz_rx + (bdr_is * 2)); - const int bb_dml_y = (box_y + (bdr_is * 1.5)) + 220; - - const int bb_dmr_w = 180; - const int bb_dmr_x = scene->ui_viz_rx + scene->ui_viz_rw - bb_dmr_w - (bdr_is * 2); - const int bb_dmr_y = (box_y + (bdr_is * 1.5)) + 220; - //bool hasSidebar = !s->scene.uilayout_sidebarcollapsed; - - bb_ui_draw_measures_right(s, bb_dml_x, bb_dml_y, bb_dml_w); - bb_ui_draw_measures_left(s, bb_dmr_x, bb_dmr_y, bb_dmr_w); - -} - -//BB END: functions added for the display of various items - static void ui_draw_vision_maxspeed(UIState *s) { /*if (!s->longitudinal_control){ return; @@ -1542,8 +1090,8 @@ static void ui_draw_vision_maxspeed(UIState *s) { int viz_maxspeed_w = 184; int viz_maxspeed_h = 202; - int viz_maxspeed_x = (ui_viz_rx + (bdr_is*2)); - int viz_maxspeed_y = (box_y + (bdr_is*1.5)); + int viz_maxspeed_x = (ui_viz_rx + (bdr_s*2)); + int viz_maxspeed_y = (box_y + (bdr_s*1.5)); int viz_maxspeed_xo = 180; #ifdef SHOW_SPEEDLIMIT @@ -1555,7 +1103,7 @@ static void ui_draw_vision_maxspeed(UIState *s) { // Draw Background nvgBeginPath(s->vg); - nvgRoundedRect(s->vg, viz_maxspeed_x, viz_maxspeed_y, viz_maxspeed_w, viz_maxspeed_h, 20); + nvgRoundedRect(s->vg, viz_maxspeed_x, viz_maxspeed_y, viz_maxspeed_w, viz_maxspeed_h, 30); if (is_set_over_limit) { nvgFillColor(s->vg, nvgRGBA(218, 111, 37, 180)); } else { @@ -1587,7 +1135,7 @@ static void ui_draw_vision_maxspeed(UIState *s) { } else { nvgFillColor(s->vg, nvgRGBA(255, 255, 255, 100)); } - nvgText(s->vg, viz_maxspeed_x+(viz_maxspeed_xo/2)+(viz_maxspeed_w/2), 148-bdr_is, "MAX", NULL); + nvgText(s->vg, viz_maxspeed_x+(viz_maxspeed_xo/2)+(viz_maxspeed_w/2), 148, "MAX", NULL); // Draw Speed Text nvgFontFace(s->vg, "sans-bold"); @@ -1595,17 +1143,14 @@ static void ui_draw_vision_maxspeed(UIState *s) { if (is_cruise_set) { snprintf(maxspeed_str, sizeof(maxspeed_str), "%d", maxspeed_calc); nvgFillColor(s->vg, nvgRGBA(255, 255, 255, 255)); - nvgText(s->vg, viz_maxspeed_x+(viz_maxspeed_xo/2)+(viz_maxspeed_w/2), 242-bdr_is, maxspeed_str, NULL); + nvgText(s->vg, viz_maxspeed_x+(viz_maxspeed_xo/2)+(viz_maxspeed_w/2), 242, maxspeed_str, NULL); } else { nvgFontFace(s->vg, "sans-semibold"); nvgFontSize(s->vg, 42*2.5); nvgFillColor(s->vg, nvgRGBA(255, 255, 255, 100)); - nvgText(s->vg, viz_maxspeed_x+(viz_maxspeed_xo/2)+(viz_maxspeed_w/2), 242-bdr_is, "-", NULL); + nvgText(s->vg, viz_maxspeed_x+(viz_maxspeed_xo/2)+(viz_maxspeed_w/2), 242, "N/A", NULL); } - //BB START: add new measures panel const int bb_dml_w = 180; - bb_ui_draw_UI(s); - //BB END: add new measures panel } static void ui_draw_vision_speedlimit(UIState *s) { @@ -1629,8 +1174,8 @@ static void ui_draw_vision_speedlimit(UIState *s) { int viz_speedlim_w = 180; int viz_speedlim_h = 202; - int viz_speedlim_x = (ui_viz_rx + (bdr_is*2)); - int viz_speedlim_y = (box_y + (bdr_is*1.5)); + int viz_speedlim_x = (ui_viz_rx + (bdr_s*2)); + int viz_speedlim_y = (box_y + (bdr_s*1.5)); if (!is_speedlim_valid) { viz_speedlim_w -= 5; viz_speedlim_h -= 10; @@ -1689,7 +1234,7 @@ static void ui_draw_vision_speedlimit(UIState *s) { } else { nvgFontFace(s->vg, "sans-semibold"); nvgFontSize(s->vg, 42*2.5); - nvgText(s->vg, viz_speedlim_x+viz_speedlim_w/2, viz_speedlim_y + (is_speedlim_valid ? 170 : 165), "-", NULL); + nvgText(s->vg, viz_speedlim_x+viz_speedlim_w/2, viz_speedlim_y + (is_speedlim_valid ? 170 : 165), "N/A", NULL); } } @@ -1703,39 +1248,14 @@ static void ui_draw_vision_speed(UIState *s) { const int viz_speed_x = ui_viz_rx+((ui_viz_rw/2)-(viz_speed_w/2)); char speed_str[32]; - if(s->scene.leftBlinker) { - nvgBeginPath(s->vg); - nvgMoveTo(s->vg, viz_speed_x, box_y + header_h/4); - nvgLineTo(s->vg, viz_speed_x - viz_speed_w/2, box_y + header_h/4 + header_h/4); - nvgLineTo(s->vg, viz_speed_x, box_y + header_h/2 + header_h/4); - nvgClosePath(s->vg); - nvgFillColor(s->vg, nvgRGBA(23,134,68,s->scene.blinker_blinkingrate>=50?210:60)); - nvgFill(s->vg); - } - - if(s->scene.rightBlinker) { - nvgBeginPath(s->vg); - nvgMoveTo(s->vg, viz_speed_x+viz_speed_w, box_y + header_h/4); - nvgLineTo(s->vg, viz_speed_x+viz_speed_w + viz_speed_w/2, box_y + header_h/4 + header_h/4); - nvgLineTo(s->vg, viz_speed_x+viz_speed_w, box_y + header_h/2 + header_h/4); - nvgClosePath(s->vg); - nvgFillColor(s->vg, nvgRGBA(23,134,68,s->scene.blinker_blinkingrate>=50?210:60)); - nvgFill(s->vg); - } - - if(s->scene.leftBlinker || s->scene.rightBlinker) { - s->scene.blinker_blinkingrate -= 3; - if(s->scene.blinker_blinkingrate<0) s->scene.blinker_blinkingrate = 120; - } - - //nvgBeginPath(s->vg); - //nvgRect(s->vg, viz_speed_x, box_y, viz_speed_w, header_h); + nvgBeginPath(s->vg); + nvgRect(s->vg, viz_speed_x, box_y, viz_speed_w, header_h); nvgTextAlign(s->vg, NVG_ALIGN_CENTER | NVG_ALIGN_BASELINE); if (s->is_metric) { snprintf(speed_str, sizeof(speed_str), "%d", (int)(speed * 3.6 + 0.5)); } else { - snprintf(speed_str, sizeof(speed_str), "%d", (int)(speed * 2.2374144 + 0.5)); + snprintf(speed_str, sizeof(speed_str), "%d", (int)(speed * 2.2369363 + 0.5)); } nvgFontFace(s->vg, "sans-bold"); nvgFontSize(s->vg, 96*2.5); @@ -1758,26 +1278,14 @@ static void ui_draw_vision_event(UIState *s) { const int ui_viz_rx = scene->ui_viz_rx; const int ui_viz_rw = scene->ui_viz_rw; const int viz_event_w = 220; - const int viz_event_x = ((ui_viz_rx + ui_viz_rw) - (viz_event_w + (bdr_is*2))); - const int viz_event_y = (box_y + (bdr_is*1.5)); - const int viz_event_h = (header_h - (bdr_is*1.5)); - if (s->scene.speedlimitahead_valid && s->scene.speedlimitaheaddistance < 300 && s->scene.engaged && s->limit_set_speed) { - // draw speed sign - const int img_turn_size = 160; - const int img_turn_x = viz_event_x-(img_turn_size/4)+80; - const int img_turn_y = viz_event_y+bdr_is-25; - float img_turn_alpha = 1.0f; - nvgBeginPath(s->vg); - NVGpaint imgPaint = nvgImagePattern(s->vg, img_turn_x, img_turn_y, - img_turn_size, img_turn_size, 0, s->img_speed, img_turn_alpha); - nvgRect(s->vg, img_turn_x, img_turn_y, img_turn_size, img_turn_size); - nvgFillPaint(s->vg, imgPaint); - nvgFill(s->vg); - } else if ((s->scene.decel_for_turn && s->scene.engaged && s->limit_set_speed) || (s->scene.decel_for_model && s->scene.engaged)) { + const int viz_event_x = ((ui_viz_rx + ui_viz_rw) - (viz_event_w + (bdr_s*2))); + const int viz_event_y = (box_y + (bdr_s*1.5)); + const int viz_event_h = (header_h - (bdr_s*1.5)); + if (s->scene.decel_for_model && s->scene.engaged) { // draw winding road sign - const int img_turn_size = 160; - const int img_turn_x = viz_event_x-(img_turn_size/4)+80; - const int img_turn_y = viz_event_y+bdr_is-25; + const int img_turn_size = 160*1.5; + const int img_turn_x = viz_event_x-(img_turn_size/4); + const int img_turn_y = viz_event_y+bdr_s-25; float img_turn_alpha = 1.0f; nvgBeginPath(s->vg); NVGpaint imgPaint = nvgImagePattern(s->vg, img_turn_x, img_turn_y, @@ -1793,14 +1301,13 @@ static void ui_draw_vision_event(UIState *s) { const int img_wheel_size = bg_wheel_size*1.5; const int img_wheel_x = bg_wheel_x-(img_wheel_size/2); const int img_wheel_y = bg_wheel_y-25; - const float img_rotation = s->scene.angleSteers/180*3.141592; float img_wheel_alpha = 0.1f; - bool is_engaged = (s->status == STATUS_ENGAGED) && !scene->steerOverride; + bool is_engaged = (s->status == STATUS_ENGAGED); bool is_warning = (s->status == STATUS_WARNING); bool is_engageable = scene->engageable; if (is_engaged || is_warning || is_engageable) { nvgBeginPath(s->vg); - nvgCircle(s->vg, bg_wheel_x, (bg_wheel_y + (bdr_is*1.5)), bg_wheel_size); + nvgCircle(s->vg, bg_wheel_x, (bg_wheel_y + (bdr_s*1.5)), bg_wheel_size); if (is_engaged) { nvgFillColor(s->vg, nvgRGBA(23, 134, 68, 255)); } else if (is_warning) { @@ -1811,23 +1318,19 @@ static void ui_draw_vision_event(UIState *s) { nvgFill(s->vg); img_wheel_alpha = 1.0f; } - nvgSave(s->vg); - nvgTranslate(s->vg,bg_wheel_x,(bg_wheel_y + (bdr_is*1.5))); - nvgRotate(s->vg,-img_rotation); nvgBeginPath(s->vg); - NVGpaint imgPaint = nvgImagePattern(s->vg, img_wheel_x-bg_wheel_x, img_wheel_y-(bg_wheel_y + (bdr_is*1.5)), + NVGpaint imgPaint = nvgImagePattern(s->vg, img_wheel_x, img_wheel_y, img_wheel_size, img_wheel_size, 0, s->img_wheel, img_wheel_alpha); - nvgRect(s->vg, img_wheel_x-bg_wheel_x, img_wheel_y-(bg_wheel_y + (bdr_is*1.5)), img_wheel_size, img_wheel_size); + nvgRect(s->vg, img_wheel_x, img_wheel_y, img_wheel_size, img_wheel_size); nvgFillPaint(s->vg, imgPaint); nvgFill(s->vg); - nvgRestore(s->vg); } } static void ui_draw_vision_map(UIState *s) { const UIScene *scene = &s->scene; const int map_size = 96; - const int map_x = (scene->ui_viz_rx + (map_size * 3) + (bdr_is * 3)); + const int map_x = (scene->ui_viz_rx + (map_size * 3) + (bdr_s * 3)); const int map_y = (footer_y + ((footer_h - map_size) / 2)); const int map_img_size = (map_size * 1.5); const int map_img_x = (map_x - (map_img_size / 2)); @@ -1841,7 +1344,7 @@ static void ui_draw_vision_map(UIState *s) { map_img_size, map_img_size, 0, s->img_map, map_img_alpha); nvgBeginPath(s->vg); - nvgCircle(s->vg, map_x, (map_y + (bdr_is * 1.5)), map_size); + nvgCircle(s->vg, map_x, (map_y + (bdr_s * 1.5)), map_size); nvgFillColor(s->vg, map_bg); nvgFill(s->vg); @@ -1854,7 +1357,7 @@ static void ui_draw_vision_map(UIState *s) { static void ui_draw_vision_face(UIState *s) { const UIScene *scene = &s->scene; const int face_size = 96; - const int face_x = (scene->ui_viz_rx + face_size + (bdr_is * 2)); + const int face_x = (scene->ui_viz_rx + face_size + (bdr_s * 2)); const int face_y = (footer_y + ((footer_h - face_size) / 2)); const int face_img_size = (face_size * 1.5); const int face_img_x = (face_x - (face_img_size / 2)); @@ -1866,7 +1369,7 @@ static void ui_draw_vision_face(UIState *s) { face_img_size, face_img_size, 0, s->img_face, face_img_alpha); nvgBeginPath(s->vg); - nvgCircle(s->vg, face_x, (face_y + (bdr_is * 1.5)), face_size); + nvgCircle(s->vg, face_x, (face_y + (bdr_s * 1.5)), face_size); nvgFillColor(s->vg, face_bg); nvgFill(s->vg); @@ -1876,33 +1379,6 @@ static void ui_draw_vision_face(UIState *s) { nvgFill(s->vg); } -static void ui_draw_vision_brake(UIState *s) { - const UIScene *scene = &s->scene; - const int brake_size = 96; - const int brake_x = (scene->ui_viz_rx + (brake_size * 5) + (bdr_is * 4)); - const int brake_y = (footer_y + ((footer_h - brake_size) / 2)); - const int brake_img_size = (brake_size * 1.5); - const int brake_img_x = (brake_x - (brake_img_size / 2)); - const int brake_img_y = (brake_y - (brake_size / 4)); - - bool brake_valid = scene->brakeLights; - float brake_img_alpha = brake_valid ? 1.0f : 0.15f; - float brake_bg_alpha = brake_valid ? 0.3f : 0.1f; - NVGcolor brake_bg = nvgRGBA(0, 0, 0, (255 * brake_bg_alpha)); - NVGpaint brake_img = nvgImagePattern(s->vg, brake_img_x, brake_img_y, - brake_img_size, brake_img_size, 0, s->img_brake, brake_img_alpha); - - nvgBeginPath(s->vg); - nvgCircle(s->vg, brake_x, (brake_y + (bdr_is * 1.5)), brake_size); - nvgFillColor(s->vg, brake_bg); - nvgFill(s->vg); - - nvgBeginPath(s->vg); - nvgRect(s->vg, brake_img_x, brake_img_y, brake_img_size, brake_img_size); - nvgFillPaint(s->vg, brake_img); - nvgFill(s->vg); -} - static void ui_draw_vision_header(UIState *s) { const UIScene *scene = &s->scene; int ui_viz_rx = scene->ui_viz_rx; @@ -1917,7 +1393,6 @@ static void ui_draw_vision_header(UIState *s) { nvgRect(s->vg, ui_viz_rx, box_y, ui_viz_rw, header_h); nvgFill(s->vg); - //bool hasSidebar = !s->scene.uilayout_sidebarcollapsed; ui_draw_vision_maxspeed(s); #ifdef SHOW_SPEEDLIMIT @@ -1936,10 +1411,9 @@ static void ui_draw_vision_footer(UIState *s) { nvgRect(s->vg, ui_viz_rx, footer_y, ui_viz_rw, footer_h); ui_draw_vision_face(s); - ui_draw_vision_brake(s); #ifdef SHOW_SPEEDLIMIT - ui_draw_vision_map(s); + // ui_draw_vision_map(s); #endif } @@ -1954,9 +1428,9 @@ static void ui_draw_vision_alert(UIState *s, int va_size, int va_color, const uint8_t *color = alert_colors[va_color]; const int alr_s = alert_sizes[va_size]; - const int alr_x = ui_viz_rx-(mapEnabled?(hasSidebar?nav_w:(nav_ww)):0)-bdr_is; - const int alr_w = ui_viz_rw+(mapEnabled?(hasSidebar?nav_w:(nav_ww)):0)+(bdr_is*2); - const int alr_h = alr_s+(va_size==ALERTSIZE_NONE?0:bdr_is); + const int alr_x = ui_viz_rx-(mapEnabled?(hasSidebar?nav_w:(nav_ww)):0)-bdr_s; + const int alr_w = ui_viz_rw+(mapEnabled?(hasSidebar?nav_w:(nav_ww)):0)+(bdr_s*2); + const int alr_h = alr_s+(va_size==ALERTSIZE_NONE?0:bdr_s); const int alr_y = vwp_h-alr_h; nvgBeginPath(s->vg); @@ -2051,18 +1525,6 @@ static void ui_draw_vision(UIState *s) { static void ui_draw_blank(UIState *s) { glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT); - // draw IP address - nvgBeginPath(s->vg); - nvgTextAlign(s->vg, NVG_ALIGN_CENTER| NVG_ALIGN_TOP); - nvgFontFace(s->vg, "sans-semibold"); - nvgFontSize(s->vg, 15 * 2.5); - nvgFillColor(s->vg, nvgRGBA(255, 255, 255, 200)); - nvgText(s->vg, 150, 292, ds.ipAddress, NULL); - if(ds.tx_throughput>0) { - char str[64]; - sprintf(str, "%d KB/s", ds.tx_throughput); - nvgText(s->vg, 150, 217, str, NULL); - } } static void ui_draw(UIState *s) { @@ -2082,7 +1544,6 @@ static void ui_draw(UIState *s) { nvgEndFrame(s->vg); glDisable(GL_BLEND); } - assert(glGetError() == GL_NO_ERROR); } static PathData read_path(cereal_ModelData_PathData_ptr pathp) { @@ -2136,16 +1597,9 @@ static void update_status(UIState *s, int status) { } -void handle_message(UIState *s, void *which) { - int err; - zmq_msg_t msg; - err = zmq_msg_init(&msg); - assert(err == 0); - err = zmq_msg_recv(&msg, which, 0); - assert(err >= 0); - +void handle_message(UIState *s, Message * msg) { struct capn ctx; - capn_init_mem(&ctx, zmq_msg_data(&msg), zmq_msg_size(&msg), 0); + capn_init_mem(&ctx, (uint8_t*)msg->getData(), msg->getSize(), 0); cereal_Event_ptr eventp; eventp.p = capn_getp(capn_root(&ctx), 0, 1); @@ -2156,72 +1610,35 @@ void handle_message(UIState *s, void *which) { struct cereal_ControlsState datad; cereal_read_ControlsState(&datad, eventd.controlsState); - struct cereal_ControlsState_LateralPIDState pdata; - cereal_read_ControlsState_LateralPIDState(&pdata, datad.lateralControlState.pidState); - - struct cereal_ControlsState_LateralLQRState qdata; - cereal_read_ControlsState_LateralLQRState(&qdata, datad.lateralControlState.lqrState); - - struct cereal_ControlsState_LateralINDIState rdata; - cereal_read_ControlsState_LateralINDIState(&rdata, datad.lateralControlState.indiState); + s->controls_timeout = 1 * UI_FREQ; + s->controls_seen = true; if (datad.vCruise != s->scene.v_cruise) { s->scene.v_cruise_update_ts = eventd.logMonoTime; } s->scene.v_cruise = datad.vCruise; s->scene.v_ego = datad.vEgo; - s->scene.angleSteers = datad.angleSteers; - s->scene.angleSteersDes = datad.angleSteersDes; - s->scene.steerOverride = datad.steerOverride; s->scene.curvature = datad.curvature; - s->scene.angleSteers = datad.angleSteers; s->scene.engaged = datad.enabled; s->scene.engageable = datad.engageable; - //s->scene.gps_planner_active = datad.gpsPlannerActive; + s->scene.gps_planner_active = datad.gpsPlannerActive; s->scene.monitoring_active = datad.driverMonitoringOn; - if (fabs(pdata.output) < 1){ - s->scene.output_scale = pdata.output; - } - if (fabs(rdata.output) < 1){ - s->scene.output_scale = rdata.output; - } - if (fabs(qdata.output) < 1){ - s->scene.output_scale = qdata.output; - } - + s->scene.frontview = datad.rearViewCam; - s->scene.decel_for_model = datad.decelForModel; - s->scene.decel_for_turn = datad.decelForTurn; - s->alert_sound_timeout = 1 * UI_FREQ; + s->scene.decel_for_model = datad.decelForModel; if (datad.alertSound != cereal_CarControl_HUDControl_AudibleAlert_none && datad.alertSound != s->alert_sound) { - char* error = NULL; if (s->alert_sound != cereal_CarControl_HUDControl_AudibleAlert_none) { - sound_file* active_sound = get_sound_file(s->alert_sound); - slplay_stop_uri(active_sound->uri, &error); - if (error) { - LOGW("error stopping active sound %s", error); - } - } - - sound_file* sound = get_sound_file(datad.alertSound); - slplay_play(sound->uri, sound->loop, &error); - if(error) { - LOGW("error playing sound: %s", error); + stop_alert_sound(s->alert_sound); } + play_alert_sound(datad.alertSound); s->alert_sound = datad.alertSound; snprintf(s->alert_type, sizeof(s->alert_type), "%s", datad.alertType.str); - } else if ((!datad.alertSound || datad.alertSound == cereal_CarControl_HUDControl_AudibleAlert_none) && s->alert_sound != cereal_CarControl_HUDControl_AudibleAlert_none) { - sound_file* sound = get_sound_file(s->alert_sound); - - char* error = NULL; - - slplay_stop_uri(sound->uri, &error); - if(error) { - LOGW("error stopping sound: %s", error); - } + } else if ((!datad.alertSound || datad.alertSound == cereal_CarControl_HUDControl_AudibleAlert_none) + && s->alert_sound != cereal_CarControl_HUDControl_AudibleAlert_none) { + stop_alert_sound(s->alert_sound); s->alert_type[0] = '\0'; s->alert_sound = cereal_CarControl_HUDControl_AudibleAlert_none; } @@ -2293,13 +1710,6 @@ void handle_message(UIState *s, void *which) { struct cereal_LiveCalibrationData datad; cereal_read_LiveCalibrationData(&datad, eventd.liveCalibration); - // should we still even have this? - capn_list32 warpl = datad.warpMatrix2; - capn_resolve(&warpl.p); // is this a bug? - for (int i = 0; i < 3 * 3; i++) { - s->scene.warp_matrix.v[i] = capn_to_f32(capn_get32(warpl, i)); - } - capn_list32 extrinsicl = datad.extrinsicMatrix; capn_resolve(&extrinsicl.p); // is this a bug? for (int i = 0; i < 3 * 4; i++) { @@ -2340,23 +1750,6 @@ void handle_message(UIState *s, void *which) { } s->scene.started_ts = datad.startedTs; - //BBB CPU TEMP - s->scene.maxCpuTemp = datad.cpu0; - if (s->scene.maxCpuTemp < datad.cpu1) - { - s->scene.maxCpuTemp = datad.cpu1; - } - else if (s->scene.maxCpuTemp < datad.cpu2) - { - s->scene.maxCpuTemp = datad.cpu2; - } - else if (s->scene.maxCpuTemp < datad.cpu3) - { - s->scene.maxCpuTemp = datad.cpu3; - } - s->scene.maxBatTemp = datad.bat; - s->scene.freeSpace = datad.freeSpace; - //BBB END CPU TEMP } else if (eventd.which == cereal_Event_uiLayoutState) { struct cereal_UiLayoutState datad; cereal_read_UiLayoutState(&datad, eventd.uiLayoutState); @@ -2378,33 +1771,8 @@ void handle_message(UIState *s, void *which) { struct cereal_LiveMapData datad; cereal_read_LiveMapData(&datad, eventd.liveMapData); s->scene.map_valid = datad.mapValid; - s->scene.speedlimit = datad.speedLimit; - s->scene.speedlimitahead_valid = datad.speedLimitAheadValid; - s->scene.speedlimitaheaddistance = datad.speedLimitAheadDistance; - s->scene.speedlimit_valid = datad.speedLimitValid; - } else if (eventd.which == cereal_Event_carState) { - struct cereal_CarState datad; - cereal_read_CarState(&datad, eventd.carState); - s->scene.brakeLights = datad.brakeLights; - if(s->scene.leftBlinker!=datad.leftBlinker || s->scene.rightBlinker!=datad.rightBlinker) - s->scene.blinker_blinkingrate = 100; - s->scene.leftBlinker = datad.leftBlinker; - s->scene.rightBlinker = datad.rightBlinker; - } else if (eventd.which == cereal_Event_gpsLocationExternal) { - struct cereal_GpsLocationData datad; - cereal_read_GpsLocationData(&datad, eventd.gpsLocationExternal); - s->scene.gpsAccuracy = datad.accuracy; - if (s->scene.gpsAccuracy > 100) - { - s->scene.gpsAccuracy = 99.99; - } - else if (s->scene.gpsAccuracy == 0) - { - s->scene.gpsAccuracy = 99.8; - } } capn_free(&ctx); - zmq_msg_close(&msg); } static void ui_update(UIState *s) { @@ -2471,8 +1839,8 @@ static void ui_update(UIState *s) { assert(glGetError() == GL_NO_ERROR); // Default UI Measurements (Assumes sidebar collapsed) - s->scene.ui_viz_rx = (box_x-sbr_w+bdr_is*2); - s->scene.ui_viz_rw = (box_w+sbr_w-(bdr_is*2)); + s->scene.ui_viz_rx = (box_x-sbr_w+bdr_s*2); + s->scene.ui_viz_rw = (box_w+sbr_w-(bdr_s*2)); s->scene.ui_viz_ro = 0; s->vision_connect_firstrun = false; @@ -2481,7 +1849,7 @@ static void ui_update(UIState *s) { s->alert_blinked = false; } - zmq_pollitem_t polls[12] = {{0}}; + zmq_pollitem_t polls[1] = {{0}}; // Wait for next rgb image from visiond while(true) { assert(s->ipc_fd >= 0); @@ -2542,85 +1910,35 @@ static void ui_update(UIState *s) { } // peek and consume all events in the zmq queue, then return. while(true) { - int plus_sock_num = 7; - int num_polls = 8; - - polls[0].socket = s->controlsstate_sock_raw; - polls[0].events = ZMQ_POLLIN; - polls[1].socket = s->livecalibration_sock_raw; - polls[1].events = ZMQ_POLLIN; - polls[2].socket = s->model_sock_raw; - polls[2].events = ZMQ_POLLIN; - polls[3].socket = s->radarstate_sock_raw; - polls[3].events = ZMQ_POLLIN; - polls[4].socket = s->livempc_sock_raw; - polls[4].events = ZMQ_POLLIN; - polls[5].socket = s->thermal_sock_raw; - polls[5].events = ZMQ_POLLIN; - polls[6].socket = s->uilayout_sock_raw; - polls[6].events = ZMQ_POLLIN; - - - if (s->vision_connected) { - num_polls++; - plus_sock_num++; - polls[7].socket = s->carstate_sock_raw; - polls[7].events = ZMQ_POLLIN; - num_polls++; - plus_sock_num++; - polls[8].socket = s->map_data_sock_raw; - polls[8].events = ZMQ_POLLIN; - num_polls++; - plus_sock_num++; - polls[9].socket = s->gps_sock_raw; - polls[9].events = ZMQ_POLLIN; - } - - polls[plus_sock_num].socket = s->plus_sock_raw; // plus_sock should be last - polls[plus_sock_num].events = ZMQ_POLLIN; + bool awake = false; + auto polls = s->poller->poll(0); - int ret = zmq_poll(polls, num_polls, 0); - if (ret < 0) { - LOGW("poll failed (%d)", ret); + if (polls.size() == 0) return; - } - if (ret == 0) { - return; - } - if (polls[0].revents || polls[1].revents || polls[2].revents || - polls[3].revents || polls[4].revents || polls[6].revents || - polls[7].revents || polls[8].revents || polls[plus_sock_num].revents) { - // awake on any (old) activity - set_awake(s, true); - } + for (auto sock : polls){ + Message * msg = sock->receive(); - if (polls[plus_sock_num].revents) { - // plus socket - zmq_msg_t msg; - err = zmq_msg_init(&msg); - assert(err == 0); - err = zmq_msg_recv(&msg, s->plus_sock_raw, 0); - assert(err >= 0); - - assert(zmq_msg_size(&msg) == 1); + if (sock != s->thermal_sock){ + awake = true; + } - s->plus_state = ((char*)zmq_msg_data(&msg))[0]; + if (sock == s->plus_sock){ + s->plus_state = msg->getData()[0]; + } else { + handle_message(s, msg); + } - zmq_msg_close(&msg); + delete msg; + } - } else { - // zmq messages - for (int i=0; ilock); @@ -2699,7 +2017,7 @@ static void* light_sensor_thread(void *args) { int err; set_thread_name("light_sensor"); - UIState *s = args; + UIState *s = (UIState*)args; s->light_sensor = 0.0; struct sensors_poll_device_t* device; @@ -2744,7 +2062,7 @@ static void* light_sensor_thread(void *args) { static void* bg_thread(void* args) { - UIState *s = args; + UIState *s = (UIState*)args; set_thread_name("bg"); EGLDisplay bg_display; @@ -2781,7 +2099,7 @@ int is_leon() { #define MAXCHAR 1000 FILE *fp; char str[MAXCHAR]; - char* filename = "/proc/cmdline"; + const char* filename = "/proc/cmdline"; fp = fopen(filename, "r"); if (fp == NULL){ @@ -2805,7 +2123,6 @@ int main(int argc, char* argv[]) { UIState uistate; UIState *s = &uistate; ui_init(s); - ds_init(); pthread_t connect_thread_handle; err = pthread_create(&connect_thread_handle, NULL, @@ -2885,51 +2202,21 @@ int main(int argc, char* argv[]) { } else { // Car started, fetch a new rgb image from ipc and peek for zmq events. ui_update(s); - ds_update(s->awake && (!s->vision_connected || s->plus_state != 0), s->awake); - } - if (s->awake) { - ds_update(s->awake, s->awake); - } - - // wake up on button press while not driving - if(ds.statePwr && (!s->vision_connected || s->plus_state != 0)) - set_awake(s, !s->awake); - if(ds.stateVol && (!s->vision_connected || s->plus_state != 0) && !s->awake) - set_awake(s, true); - - // awake on any touch - int touch_x = -1, touch_y = -1; - int touched = touch_poll(&touch, &touch_x, &touch_y, s->awake ? 0 : 100); - if (touched == 1) { - // touch event will still happen :( - set_awake(s, true); - - if(touch_x>=vwp_w-100 && touch_y>=vwp_h-100 && s->touchTimeout==0) { - s->touchTimeout = 30; - } else if(touch_x>=vwp_w-100 && touch_y<=100 && s->touchTimeout==0) { - s->touchTimeout = 30; + if(!s->vision_connected) { + // Visiond process is just stopped, force a redraw to make screen blank again. + ui_draw(s); + glFinish(); + should_swap = true; } } - if(s->touchTimeout>0) - s->touchTimeout--; - - if(!s->vision_connected) { - // Visiond process is just stopped, force a redraw to make screen blank again. - ui_draw(s); - glFinish(); - should_swap = true; - } - // manage wakefulness if (s->awake_timeout > 0) { s->awake_timeout--; - } else if(!ds.logOn) { + } else { set_awake(s, false); } // Don't waste resources on drawing in case screen is off or car is not started. if (s->awake && s->vision_connected) { - dashcam(s, touch_x, touch_y); - //dashboard(s, touch_x, touch_y); ui_draw(s); glFinish(); should_swap = true; @@ -2944,25 +2231,39 @@ int main(int argc, char* argv[]) { } #endif } + if (s->volume_timeout > 0) { s->volume_timeout--; } else { - int volume = min(MAX_VOLUME, MIN_VOLUME + s->scene.v_ego / 5); // up one notch every 5 m/s + int volume = fmin(MAX_VOLUME, MIN_VOLUME + s->scene.v_ego / 5); // up one notch every 5 m/s set_volume(s, volume); } - // stop playing alert sounds if no controlsState msg for 1 second - if (s->alert_sound_timeout > 0) { - s->alert_sound_timeout--; - } else if (s->alert_sound != cereal_CarControl_HUDControl_AudibleAlert_none){ - sound_file* sound = get_sound_file(s->alert_sound); - char* error = NULL; + if (s->controls_timeout > 0) { + s->controls_timeout--; + } else { + // stop playing alert sound + if ((!s->vision_connected || (s->vision_connected && s->alert_sound_timeout == 0)) && + s->alert_sound != cereal_CarControl_HUDControl_AudibleAlert_none) { + stop_alert_sound(s->alert_sound); + s->alert_sound = cereal_CarControl_HUDControl_AudibleAlert_none; + } + + // if visiond is still running and controlsState times out, display an alert + if (s->controls_seen && s->vision_connected && strcmp(s->scene.alert_text2, "Controls Unresponsive") != 0) { + s->scene.alert_size = ALERTSIZE_FULL; + update_status(s, STATUS_ALERT); + snprintf(s->scene.alert_text1, sizeof(s->scene.alert_text1), "%s", "TAKE CONTROL IMMEDIATELY"); + snprintf(s->scene.alert_text2, sizeof(s->scene.alert_text2), "%s", "Controls Unresponsive"); + ui_draw_vision_alert(s, s->scene.alert_size, s->status, s->scene.alert_text1, s->scene.alert_text2); + + s->alert_sound_timeout = 2 * UI_FREQ; - slplay_stop_uri(sound->uri, &error); - if(error) { - LOGW("error stopping sound: %s", error); + s->alert_sound = cereal_CarControl_HUDControl_AudibleAlert_chimeWarningRepeat; + play_alert_sound(s->alert_sound); } - s->alert_sound = cereal_CarControl_HUDControl_AudibleAlert_none; + s->alert_sound_timeout--; + s->controls_seen = false; } read_param_bool_timeout(&s->is_metric, "IsMetric", &s->is_metric_timeout); @@ -2994,4 +2295,4 @@ int main(int argc, char* argv[]) { assert(err == 0); return 0; -} +} \ No newline at end of file diff --git a/selfdrive/visiond/build_from_src.mk b/selfdrive/visiond/build_from_src.mk index 41e844fe1d8663..725b345fa42002 100644 --- a/selfdrive/visiond/build_from_src.mk +++ b/selfdrive/visiond/build_from_src.mk @@ -15,6 +15,9 @@ WARN_FLAGS = -Werror=implicit-function-declaration \ CFLAGS = -I. -std=gnu11 -fPIC -O2 $(WARN_FLAGS) CXXFLAGS = -I. -std=c++14 -fPIC -O2 $(WARN_FLAGS) +MESSAGING_FLAGS = -I$(BASEDIR)/selfdrive/messaging +MESSAGING_LIBS = $(BASEDIR)/selfdrive/messaging/messaging.a + ifeq ($(ARCH),aarch64) CFLAGS += -mcpu=cortex-a57 CXXFLAGS += -mcpu=cortex-a57 @@ -51,9 +54,9 @@ else OPENCL_LIBS = -lOpenCL - TF_FLAGS = -I$(EXTERNAL)/tensorflow/include - TF_LIBS = -L$(EXTERNAL)/tensorflow/lib -ltensorflow \ - -Wl,-rpath $(EXTERNAL)/tensorflow/lib + #TF_FLAGS = -I$(EXTERNAL)/tensorflow/include + #TF_LIBS = -L$(EXTERNAL)/tensorflow/lib -ltensorflow \ + # -Wl,-rpath $(EXTERNAL)/tensorflow/lib SNPE_FLAGS = -I$(PHONELIBS)/snpe/include/ SNPE_LIBS = -L$(PHONELIBS)/snpe/x86_64-linux-clang/ \ @@ -66,7 +69,7 @@ else PLATFORM_OBJS = cameras/camera_frame_stream.o \ ../common/visionbuf_cl.o \ ../common/visionimg.o \ - runners/tfmodel.o + # runners/tfmodel.o endif SSL_FLAGS = -I/usr/include/openssl/ @@ -161,7 +164,7 @@ rgb_to_yuv_test: transforms/rgb_to_yuv_test.o clutil.o transforms/rgb_to_yuv.o . $(OPENCL_LIBS) \ -$(OUTPUT): $(OBJS) +$(OUTPUT): $(OBJS) $(MESSAGING_LIBS) @echo "[ LINK ] $@" $(CXX) -fPIC -o '$@' $^ \ $(LDFLAGS) \ @@ -190,6 +193,7 @@ $(MODEL_OBJS): %.o: %.dlc -Iinclude -I.. -I../.. \ $(EIGEN_FLAGS) \ $(ZMQ_FLAGS) \ + $(MESSAGING_FLAGS) \ $(CEREAL_CXXFLAGS) \ $(OPENCL_FLAGS) \ $(LIBYUV_FLAGS) \ @@ -206,6 +210,7 @@ $(MODEL_OBJS): %.o: %.dlc $(CC) $(CFLAGS) -MMD \ -Iinclude -I.. -I../.. \ $(ZMQ_FLAGS) \ + $(MESSAGING_FLAGS) \ $(CEREAL_CFLAGS) \ $(OPENCL_FLAGS) \ $(LIBYUV_FLAGS) \ diff --git a/selfdrive/visiond/cameras/camera_frame_stream.cc b/selfdrive/visiond/cameras/camera_frame_stream.cc index ae3c8b14ca1af8..fe1bba3bb8c80a 100644 --- a/selfdrive/visiond/cameras/camera_frame_stream.cc +++ b/selfdrive/visiond/cameras/camera_frame_stream.cc @@ -3,12 +3,14 @@ #include #include #include +#include #include +#include -#include #include #include #include "cereal/gen/cpp/log.capnp.h" +#include "messaging.hpp" #include "common/util.h" #include "common/timing.h" @@ -51,26 +53,17 @@ void camera_init(CameraState *s, int camera_id, unsigned int fps) { void run_frame_stream(DualCameraState *s) { int err; - zsock_t *recorder_sock = zsock_new_sub(">tcp://127.0.0.1:8002", ""); - assert(recorder_sock); - void *recorder_sock_raw = zsock_resolve(recorder_sock); + Context * context = Context::create(); + SubSocket * recorder_sock = SubSocket::create(context, "frame"); CameraState *const rear_camera = &s->rear; auto *tb = &rear_camera->camera_tb; while (!do_exit) { - zmq_msg_t msg; - err = zmq_msg_init(&msg); - assert(err == 0); - - err = zmq_msg_recv(&msg, recorder_sock_raw, 0); - if(err == -1) - break; + Message * msg = recorder_sock->receive(); - // make copy due to alignment issues, will be freed on out of scope - size_t len = zmq_msg_size(&msg); - auto amsg = kj::heapArray((len / sizeof(capnp::word)) + 1); - memcpy(amsg.begin(), (const uint8_t*)zmq_msg_data(&msg), len); + auto amsg = kj::heapArray((msg->getSize() / sizeof(capnp::word)) + 1); + memcpy(amsg.begin(), msg->getData(), msg->getSize()); capnp::FlatArrayMessageReader cmsg(amsg); cereal::Event::Reader event = cmsg.getRoot(); @@ -100,11 +93,11 @@ void run_frame_stream(DualCameraState *s) { clWaitForEvents(1, &map_event); clReleaseEvent(map_event); tbuffer_dispatch(tb, buf_idx); + delete msg; - err = zmq_msg_close(&msg); - assert(err == 0); } - zsock_destroy(&recorder_sock); + delete recorder_sock; + delete context; } } // namespace diff --git a/selfdrive/visiond/cameras/camera_frame_stream.h b/selfdrive/visiond/cameras/camera_frame_stream.h index 6351a183d35c3c..5cb7e27c5fa72a 100644 --- a/selfdrive/visiond/cameras/camera_frame_stream.h +++ b/selfdrive/visiond/cameras/camera_frame_stream.h @@ -33,6 +33,8 @@ typedef struct CameraState { int fps; float digital_gain; + float cur_gain_frac; + mat3 transform; } CameraState; diff --git a/selfdrive/visiond/dsp/libsnpe_dsp_skel.so b/selfdrive/visiond/dsp/libsnpe_dsp_skel.so new file mode 100644 index 00000000000000..f63f2fae70b8ab Binary files /dev/null and b/selfdrive/visiond/dsp/libsnpe_dsp_skel.so differ diff --git a/selfdrive/visiond/models/driving.cc b/selfdrive/visiond/models/driving.cc index 174b6685b3ab7a..bb985425f80e8e 100644 --- a/selfdrive/visiond/models/driving.cc +++ b/selfdrive/visiond/models/driving.cc @@ -30,14 +30,14 @@ // #define DUMP_YUV -Eigen::Matrix vander; +Eigen::Matrix vander; void model_init(ModelState* s, cl_device_id device_id, cl_context context, int temporal) { model_input_init(&s->in, MODEL_WIDTH, MODEL_HEIGHT, device_id, context); const int output_size = OUTPUT_SIZE + TEMPORAL_SIZE; s->output = (float*)malloc(output_size * sizeof(float)); memset(s->output, 0, output_size * sizeof(float)); - s->m = new DefaultRunModel("../../models/driving_model.dlc", s->output, output_size); + s->m = new DefaultRunModel("../../models/driving_model.dlc", s->output, output_size, USE_GPU_RUNTIME); #ifdef TEMPORAL assert(temporal); s->m->addRecurrent(&s->output[OUTPUT_SIZE], TEMPORAL_SIZE); @@ -50,7 +50,7 @@ void model_init(ModelState* s, cl_device_id device_id, cl_context context, int t // Build Vandermonde matrix for(int i = 0; i < MODEL_PATH_DISTANCE; i++) { - for(int j = 0; j < POLYFIT_DEGREE; j++) { + for(int j = 0; j < POLYFIT_DEGREE - 1; j++) { vander(i, j) = pow(i, POLYFIT_DEGREE-j-1); } } @@ -195,14 +195,17 @@ void poly_fit(float *in_pts, float *in_stds, float *out) { // References to inputs Eigen::Map > pts(in_pts, MODEL_PATH_DISTANCE); Eigen::Map > std(in_stds, MODEL_PATH_DISTANCE); - Eigen::Map > p(out, POLYFIT_DEGREE); + Eigen::Map > p(out, POLYFIT_DEGREE - 1); + + float y0 = pts[0]; + pts = pts.array() - y0; // Build Least Squares equations - Eigen::Matrix lhs = vander.array().colwise() / std.array(); + Eigen::Matrix lhs = vander.array().colwise() / std.array(); Eigen::Matrix rhs = pts.array() / std.array(); // Improve numerical stability - Eigen::Matrix scale = 1. / (lhs.array()*lhs.array()).sqrt().colwise().sum(); + Eigen::Matrix scale = 1. / (lhs.array()*lhs.array()).sqrt().colwise().sum(); lhs = lhs * scale.asDiagonal(); // Solve inplace @@ -211,10 +214,19 @@ void poly_fit(float *in_pts, float *in_stds, float *out) { // Apply scale to output p = p.transpose() * scale.asDiagonal(); + out[3] = y0; } void fill_path(cereal::ModelData::PathData::Builder path, const PathData path_data) { + if (std::getenv("DEBUG")){ + kj::ArrayPtr stds(&path_data.stds[0], ARRAYSIZE(path_data.stds)); + path.setStds(stds); + + kj::ArrayPtr points(&path_data.points[0], ARRAYSIZE(path_data.points)); + path.setPoints(points); + } + kj::ArrayPtr poly(&path_data.poly[0], ARRAYSIZE(path_data.poly)); path.setPoly(poly); path.setProb(path_data.prob); @@ -233,7 +245,7 @@ void fill_lead(cereal::ModelData::LeadData::Builder lead, const LeadData lead_da lead.setRelAStd(lead_data.rel_a_std); } -void model_publish(void* sock, uint32_t frame_id, +void model_publish(PubSocket *sock, uint32_t frame_id, const ModelData data, uint64_t timestamp_eof) { // make msg capnp::MallocMessageBuilder msg; @@ -246,8 +258,8 @@ void model_publish(void* sock, uint32_t frame_id, kj::ArrayPtr speed(&data.speed[0], ARRAYSIZE(data.speed)); framed.setSpeed(speed); - - + + auto lpath = framed.initPath(); fill_path(lpath, data.path); auto left_lane = framed.initLeftLane(); @@ -264,5 +276,5 @@ void model_publish(void* sock, uint32_t frame_id, // send message auto words = capnp::messageToFlatArray(msg); auto bytes = words.asBytes(); - zmq_send(sock, bytes.begin(), bytes.size(), ZMQ_DONTWAIT); + sock->send((char*)bytes.begin(), bytes.size()); } diff --git a/selfdrive/visiond/models/driving.h b/selfdrive/visiond/models/driving.h index c384d6ef4a2f22..ccf8a94be291bf 100644 --- a/selfdrive/visiond/models/driving.h +++ b/selfdrive/visiond/models/driving.h @@ -19,6 +19,7 @@ #include "cereal/gen/cpp/log.capnp.h" #include #include +#include "messaging.hpp" typedef struct ModelState { @@ -38,6 +39,6 @@ ModelData model_eval_frame(ModelState* s, cl_command_queue q, void model_free(ModelState* s); void poly_fit(float *in_pts, float *in_stds, float *out); -void model_publish(void* sock, uint32_t frame_id, +void model_publish(PubSocket* sock, uint32_t frame_id, const ModelData data, uint64_t timestamp_eof); #endif diff --git a/selfdrive/visiond/models/monitoring.cc b/selfdrive/visiond/models/monitoring.cc index 959902b98575c5..30a6f56c1ab95d 100644 --- a/selfdrive/visiond/models/monitoring.cc +++ b/selfdrive/visiond/models/monitoring.cc @@ -6,9 +6,18 @@ #define MODEL_WIDTH 320 #define MODEL_HEIGHT 160 +#define MAX_IR_POWER 0.5f +#define MIN_IR_POWER 0.0f +#define CUTOFF_GAIN 0.015625f // iso400 +#define SATURATE_GAIN 0.0625f // iso1600 + +// match driver_monitor.py +#define FACE_THRESH 0.4f +#define EYE_THRESH 0.4f + void monitoring_init(MonitoringState* s, cl_device_id device_id, cl_context context) { model_input_init(&s->in, MODEL_WIDTH, MODEL_HEIGHT, device_id, context); - s->m = new SNPEModel("../../models/monitoring_model.dlc", (float*)&s->output, OUTPUT_SIZE); + s->m = new DefaultRunModel("../../models/monitoring_model.dlc", (float*)&s->output, OUTPUT_SIZE, USE_DSP_RUNTIME); } MonitoringResult monitoring_eval_frame(MonitoringState* s, cl_command_queue q, @@ -48,7 +57,7 @@ MonitoringResult monitoring_eval_frame(MonitoringState* s, cl_command_queue q, return ret; } -void monitoring_publish(void* sock, uint32_t frame_id, const MonitoringResult res) { +void monitoring_publish(PubSocket* sock, uint32_t frame_id, const MonitoringResult res, float ir_target) { // make msg capnp::MallocMessageBuilder msg; cereal::Event::Builder event = msg.initRoot(); @@ -66,14 +75,34 @@ void monitoring_publish(void* sock, uint32_t frame_id, const MonitoringResult re framed.setRightEyeProb(res.right_eye_prob); framed.setLeftBlinkProb(res.left_blink_prob); framed.setRightBlinkProb(res.right_blink_prob); + framed.setIrPwr(ir_target); // send message auto words = capnp::messageToFlatArray(msg); auto bytes = words.asBytes(); - zmq_send(sock, bytes.begin(), bytes.size(), ZMQ_DONTWAIT); + sock->send((char*)bytes.begin(), bytes.size()); } void monitoring_free(MonitoringState* s) { model_input_free(&s->in); delete s->m; } + +float ir_target_set(float *cur_front_gain, const MonitoringResult res) { + bool face_detected = res.face_prob > FACE_THRESH; + bool eyes_detected = (res.left_eye_prob > EYE_THRESH) && (res.right_eye_prob > EYE_THRESH); + static float set_point = 0.5; + + if ((*cur_front_gain <= CUTOFF_GAIN) && !face_detected) { + set_point = MIN_IR_POWER; + } else if (face_detected && eyes_detected) { + if (*cur_front_gain > SATURATE_GAIN) { + set_point = MAX_IR_POWER; + } else { + set_point = MIN_IR_POWER + ((*cur_front_gain - CUTOFF_GAIN) * (MAX_IR_POWER - MIN_IR_POWER) / (SATURATE_GAIN - CUTOFF_GAIN)); + } + } else { + set_point = (set_point*1.1 > MAX_IR_POWER) ? MAX_IR_POWER : set_point*1.1; + } + return set_point; +} \ No newline at end of file diff --git a/selfdrive/visiond/models/monitoring.h b/selfdrive/visiond/models/monitoring.h index 49b910ef5c3106..4732363711d02f 100644 --- a/selfdrive/visiond/models/monitoring.h +++ b/selfdrive/visiond/models/monitoring.h @@ -6,8 +6,8 @@ #include "runners/run.h" #include "cereal/gen/cpp/log.capnp.h" -#include #include +#include "messaging.hpp" #ifdef __cplusplus extern "C" { @@ -37,9 +37,11 @@ typedef struct MonitoringState { void monitoring_init(MonitoringState* s, cl_device_id device_id, cl_context context); MonitoringResult monitoring_eval_frame(MonitoringState* s, cl_command_queue q, cl_mem yuv_cl, int width, int height); -void monitoring_publish(void* sock, uint32_t frame_id, const MonitoringResult res); +void monitoring_publish(PubSocket *sock, uint32_t frame_id, const MonitoringResult res, float ir_target); void monitoring_free(MonitoringState* s); +float ir_target_set(float *cur_front_gain, const MonitoringResult res); + #ifdef __cplusplus } #endif diff --git a/selfdrive/visiond/models/posenet.cc b/selfdrive/visiond/models/posenet.cc index d1c8d805441d54..c843e81f4d919f 100644 --- a/selfdrive/visiond/models/posenet.cc +++ b/selfdrive/visiond/models/posenet.cc @@ -4,7 +4,7 @@ void posenet_init(PosenetState *s) { s->input = (float*)malloc(2*200*532*sizeof(float)); - s->m = new DefaultRunModel("../../models/posenet.dlc", s->output, sizeof(s->output)/sizeof(float)); + s->m = new DefaultRunModel("../../models/posenet.dlc", s->output, sizeof(s->output)/sizeof(float), USE_GPU_RUNTIME); } void posenet_push(PosenetState *s, uint8_t *yuv_ptr_y, int yuv_width) { diff --git a/selfdrive/visiond/runners/snpemodel.cc b/selfdrive/visiond/runners/snpemodel.cc index ae69f76d66187e..257f203d7fd3c0 100644 --- a/selfdrive/visiond/runners/snpemodel.cc +++ b/selfdrive/visiond/runners/snpemodel.cc @@ -9,9 +9,17 @@ void PrintErrorStringAndExit() { std::exit(EXIT_FAILURE); } -SNPEModel::SNPEModel(const char *path, float *output, size_t output_size) { +SNPEModel::SNPEModel(const char *path, float *output, size_t output_size, int runtime) { #ifdef QCOM - assert(zdl::SNPE::SNPEFactory::isRuntimeAvailable(zdl::DlSystem::Runtime_t::GPU)); + zdl::DlSystem::Runtime_t Runtime; + if (runtime==USE_GPU_RUNTIME) { + Runtime = zdl::DlSystem::Runtime_t::GPU; + } else if (runtime==USE_DSP_RUNTIME) { + Runtime = zdl::DlSystem::Runtime_t::DSP; + } else { + Runtime = zdl::DlSystem::Runtime_t::CPU; + } + assert(zdl::SNPE::SNPEFactory::isRuntimeAvailable(Runtime)); #endif size_t model_size; model_data = (uint8_t *)read_file(path, &model_size); @@ -27,7 +35,7 @@ SNPEModel::SNPEModel(const char *path, float *output, size_t output_size) { while (!snpe) { #ifdef QCOM snpe = snpeBuilder.setOutputLayers({}) - .setRuntimeProcessor(zdl::DlSystem::Runtime_t::GPU) + .setRuntimeProcessor(Runtime) .setUseUserSuppliedBuffers(true) .setPerformanceProfile(zdl::DlSystem::PerformanceProfile_t::HIGH_PERFORMANCE) .build(); diff --git a/selfdrive/visiond/runners/snpemodel.h b/selfdrive/visiond/runners/snpemodel.h index cd47a3ade10b7b..f750baaf13f25e 100644 --- a/selfdrive/visiond/runners/snpemodel.h +++ b/selfdrive/visiond/runners/snpemodel.h @@ -13,9 +13,13 @@ #include "runmodel.h" +#define USE_CPU_RUNTIME 0 +#define USE_GPU_RUNTIME 1 +#define USE_DSP_RUNTIME 2 + class SNPEModel : public RunModel { public: - SNPEModel(const char *path, float *output, size_t output_size); + SNPEModel(const char *path, float *output, size_t output_size, int runtime); ~SNPEModel() { if (model_data) free(model_data); } diff --git a/selfdrive/visiond/snapshot/snapshot.py b/selfdrive/visiond/snapshot/snapshot.py index cb24209655878b..affc635b81d5f0 100755 --- a/selfdrive/visiond/snapshot/snapshot.py +++ b/selfdrive/visiond/snapshot/snapshot.py @@ -2,6 +2,7 @@ import os import subprocess from PIL import Image +from common.params import Params import time import signal @@ -19,7 +20,9 @@ def snapshot(): if len(ret) > 0: return None - proc = subprocess.Popen(os.path.join(os.getenv("HOME"), "one/selfdrive/visiond/visiond"), cwd=os.path.join(os.getenv("HOME"), "one/selfdrive/visiond")) + front_camera_allowed = int(Params().get("RecordFront")) + + proc = subprocess.Popen(os.path.join(os.getenv("HOME"), "one/selfdrive/visiond/start.py"), cwd=os.path.join(os.getenv("HOME"), "one/selfdrive/visiond")) time.sleep(6.0) ret = None @@ -28,9 +31,12 @@ def snapshot(): pic = ipc.get() del ipc - ipc_front = VisionIPC(front=True) - fpic = ipc_front.get() - del ipc_front + if front_camera_allowed: + ipc_front = VisionIPC(front=True) + fpic = ipc_front.get() + del ipc_front + else: + fpic = None ret = pic, fpic finally: diff --git a/selfdrive/visiond/start.py b/selfdrive/visiond/start.py new file mode 100755 index 00000000000000..5556ac2997e17f --- /dev/null +++ b/selfdrive/visiond/start.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python3 +import os + +assert os.system("make") == 0 +from common.basedir import BASEDIR + +os.environ["ADSP_LIBRARY_PATH"] = os.path.join(BASEDIR, "selfdrive/visiond/dsp") +os.execv("./visiond", ["visiond"]) diff --git a/selfdrive/visiond/visiond.cc b/selfdrive/visiond/visiond.cc index 62682918c04247..31546f956d43de 100644 --- a/selfdrive/visiond/visiond.cc +++ b/selfdrive/visiond/visiond.cc @@ -51,6 +51,8 @@ #include "cameras/camera_frame_stream.h" #endif +#include "messaging.hpp" + // 3 models #include "models/driving.h" @@ -162,8 +164,7 @@ struct VisionState { ModelData model_bufs[UI_BUF_COUNT]; MonitoringState monitoring; - zsock_t *monitoring_sock; - void* monitoring_sock_raw; + PubSocket *monitoring_sock; PosenetState posenet; @@ -183,14 +184,11 @@ struct VisionState { DualCameraState cameras; zsock_t *terminate_pub; - zsock_t *recorder_sock; - void* recorder_sock_raw; - - zsock_t *posenet_sock; - void* posenet_sock_raw; - zsock_t *thumbnail_sock; - void* thumbnail_sock_raw; + Context * msg_context; + PubSocket *recorder_sock; + PubSocket *posenet_sock; + PubSocket *thumbnail_sock; pthread_mutex_t clients_lock; VisionClientState clients[MAX_CLIENTS]; @@ -745,7 +743,7 @@ void* monitoring_thread(void *arg) { } // send dm packet - monitoring_publish(s->monitoring_sock_raw, frame_data.frame_id, res); + monitoring_publish(s->monitoring_sock, frame_data.frame_id, res, ir_target_set(&s->cameras.front.cur_gain_frac, res)); //t2 = millis_since_boot(); //LOGD("monitoring process: %.2fms, from last %.2fms", t2-t1, t1-last); @@ -895,9 +893,8 @@ void* processing_thread(void *arg) { cl_command_queue q = clCreateCommandQueueWithProperties(s->context, s->device_id, props, &err); assert(err == 0); - zsock_t *model_sock = zsock_new_pub("@tcp://*:8009"); - assert(model_sock); - void *model_sock_raw = zsock_resolve(model_sock); + Context * context = Context::create(); + PubSocket * model_sock = PubSocket::create(context, "model"); #ifdef SEND_NET_INPUT zsock_t *img_sock = zsock_new_pub("@tcp://*:9000"); @@ -1014,7 +1011,7 @@ void* processing_thread(void *arg) { model_transform, img_sock_raw, NULL); mt2 = millis_since_boot(); - model_publish(model_sock_raw, frame_id, s->model_bufs[ui_idx], frame_data.timestamp_eof); + model_publish(model_sock, frame_id, s->model_bufs[ui_idx], frame_data.timestamp_eof); } @@ -1044,10 +1041,10 @@ void* processing_thread(void *arg) { kj::ArrayPtr transform_vs(&s->yuv_transform.v[0], 9); framed.setTransform(transform_vs); - if (s->recorder_sock_raw != NULL) { + if (s->recorder_sock != NULL) { auto words = capnp::messageToFlatArray(msg); auto bytes = words.asBytes(); - zmq_send(s->recorder_sock_raw, bytes.begin(), bytes.size(), ZMQ_DONTWAIT); + s->recorder_sock->send((char*)bytes.begin(), bytes.size()); } } @@ -1082,7 +1079,7 @@ void* processing_thread(void *arg) { auto words = capnp::messageToFlatArray(msg); auto bytes = words.asBytes(); - zmq_send(s->posenet_sock_raw, bytes.begin(), bytes.size(), ZMQ_DONTWAIT); + s->posenet_sock->send((char*)bytes.begin(), bytes.size()); } pt3 = millis_since_boot(); LOGD("pre: %.2fms | posenet: %.2fms", (pt2-pt1), (pt3-pt1)); @@ -1144,7 +1141,7 @@ void* processing_thread(void *arg) { auto words = capnp::messageToFlatArray(msg); auto bytes = words.asBytes(); - zmq_send(s->thumbnail_sock_raw, bytes.begin(), bytes.size(), ZMQ_DONTWAIT); + s->thumbnail_sock->send((char*)bytes.begin(), bytes.size()); free(thumbnail_buffer); } @@ -1201,7 +1198,8 @@ void* processing_thread(void *arg) { fclose(dump_rgb_file); #endif - zsock_destroy(&model_sock); + delete model_sock; + delete context; return NULL; } @@ -1212,14 +1210,9 @@ void* live_thread(void *arg) { set_thread_name("live"); - zsock_t *terminate = zsock_new_sub(">inproc://terminate", ""); - assert(terminate); - - zsock_t *liveCalibration_sock = zsock_new_sub(">tcp://127.0.0.1:8019", ""); - assert(liveCalibration_sock); - - zpoller_t *poller = zpoller_new(liveCalibration_sock, terminate, NULL); - assert(poller); + Context * c = Context::create(); + SubSocket * live_calibration_sock = SubSocket::create(c, "liveCalibration"); + Poller * poller = Poller::create({live_calibration_sock}); /* import numpy as np @@ -1240,59 +1233,45 @@ void* live_thread(void *arg) { 0.0, 0.0, 1.0; while (!do_exit) { - zsock_t *which = (zsock_t*)zpoller_wait(poller, -1); - if (which == terminate || which == NULL) { - break; - } - - zmq_msg_t msg; - err = zmq_msg_init(&msg); - assert(err == 0); + for (auto sock : poller->poll(10)){ + Message * msg = sock->receive(); - err = zmq_msg_recv(&msg, zsock_resolve(which), 0); - assert(err >= 0); - size_t len = zmq_msg_size(&msg); + auto amsg = kj::heapArray((msg->getSize() / sizeof(capnp::word)) + 1); + memcpy(amsg.begin(), msg->getData(), msg->getSize()); - // make copy due to alignment issues, will be freed on out of scope - auto amsg = kj::heapArray((len / sizeof(capnp::word)) + 1); - memcpy(amsg.begin(), (const uint8_t*)zmq_msg_data(&msg), len); + capnp::FlatArrayMessageReader cmsg(amsg); + cereal::Event::Reader event = cmsg.getRoot(); - // track camera frames to sync to encoder - capnp::FlatArrayMessageReader cmsg(amsg); - cereal::Event::Reader event = cmsg.getRoot(); + if (event.isLiveCalibration()) { + pthread_mutex_lock(&s->transform_lock); - if (event.isLiveCalibration()) { - pthread_mutex_lock(&s->transform_lock); + auto extrinsic_matrix = event.getLiveCalibration().getExtrinsicMatrix(); + Eigen::Matrix extrinsic_matrix_eigen; + for (int i = 0; i < 4*3; i++){ + extrinsic_matrix_eigen(i / 4, i % 4) = extrinsic_matrix[i]; + } - auto extrinsic_matrix = event.getLiveCalibration().getExtrinsicMatrix(); - Eigen::Matrix extrinsic_matrix_eigen; - for (int i = 0; i < 4*3; i++){ - extrinsic_matrix_eigen(i / 4, i % 4) = extrinsic_matrix[i]; - } + auto camera_frame_from_road_frame = eon_intrinsics * extrinsic_matrix_eigen; + Eigen::Matrix camera_frame_from_ground; + camera_frame_from_ground.col(0) = camera_frame_from_road_frame.col(0); + camera_frame_from_ground.col(1) = camera_frame_from_road_frame.col(1); + camera_frame_from_ground.col(2) = camera_frame_from_road_frame.col(3); - auto camera_frame_from_road_frame = eon_intrinsics * extrinsic_matrix_eigen; - Eigen::Matrix camera_frame_from_ground; - camera_frame_from_ground.col(0) = camera_frame_from_road_frame.col(0); - camera_frame_from_ground.col(1) = camera_frame_from_road_frame.col(1); - camera_frame_from_ground.col(2) = camera_frame_from_road_frame.col(3); + auto warp_matrix = camera_frame_from_ground * ground_from_medmodel_frame; - auto warp_matrix = camera_frame_from_ground * ground_from_medmodel_frame; + for (int i=0; i<3*3; i++) { + s->cur_transform.v[i] = warp_matrix(i / 3, i % 3); + } - for (int i=0; i<3*3; i++) { - s->cur_transform.v[i] = warp_matrix(i / 3, i % 3); + s->run_model = true; + pthread_mutex_unlock(&s->transform_lock); } - s->run_model = true; - pthread_mutex_unlock(&s->transform_lock); + delete msg; } - zmq_msg_close(&msg); } - zpoller_destroy(&poller); - zsock_destroy(&terminate); - - zsock_destroy(&liveCalibration_sock); return NULL; } @@ -1400,7 +1379,6 @@ int main(int argc, char **argv) { monitoring_init(&s->monitoring, s->device_id, s->context); posenet_init(&s->posenet); - // s->zctx = zctx_shadow_zmq_ctx(zsys_init()); cameras_init(&s->cameras); @@ -1415,23 +1393,16 @@ int main(int argc, char **argv) { init_buffers(s); + s->msg_context = Context::create(); + #ifdef QCOM - s->recorder_sock = zsock_new_pub("@tcp://*:8002"); - assert(s->recorder_sock); - s->recorder_sock_raw = zsock_resolve(s->recorder_sock); + s->recorder_sock = PubSocket::create(s->msg_context, "frame"); #endif - s->monitoring_sock = zsock_new_pub("@tcp://*:8063"); - assert(s->monitoring_sock); - s->monitoring_sock_raw = zsock_resolve(s->monitoring_sock); + s->monitoring_sock = PubSocket::create(s->msg_context, "driverMonitoring"); + s->posenet_sock = PubSocket::create(s->msg_context, "cameraOdometry"); + s->thumbnail_sock = PubSocket::create(s->msg_context, "thumbnail"); - s->posenet_sock = zsock_new_pub("@tcp://*:8066"); - assert(s->posenet_sock); - s->posenet_sock_raw = zsock_resolve(s->posenet_sock); - - s->thumbnail_sock = zsock_new_pub("@tcp://*:8069"); - assert(s->thumbnail_sock); - s->thumbnail_sock_raw = zsock_resolve(s->thumbnail_sock); cameras_open(&s->cameras, &s->camera_bufs[0], &s->focus_bufs[0], &s->stats_bufs[0], &s->front_camera_bufs[0]); @@ -1440,11 +1411,12 @@ int main(int argc, char **argv) { } party(s); - zsock_destroy(&s->recorder_sock); - zsock_destroy(&s->monitoring_sock); - zsock_destroy(&s->posenet_sock); - zsock_destroy(&s->thumbnail_sock); - // zctx_destroy(&s->zctx); + + delete s->recorder_sock; + delete s->monitoring_sock; + delete s->posenet_sock; + delete s->thumbnail_sock; + delete s->msg_context; model_free(&s->model); monitoring_free(&s->monitoring);