Commit Graph

105 Commits

Author SHA1 Message Date
Maxime Desroches 209f7ab09f
misra8.4: safety.h + safety_declarations.h (#2022)
* safety

* static!

* ALLOW_DEBUG

* fix

* fix 12.3

* remove comment

* no debug

* move stuff to debug

* only usage

* cleanup

* canfd hyundai

* no include for now

* indent

* comment for ford suppression

* also gm

* remove suppression

* only safety headers

* cleanup
2024-09-20 19:25:37 -07:00
Maxime Desroches ac9c1b3b3f
misra8.7 (#2033)
* 8_7

* fix test
2024-09-20 15:51:27 -07:00
Maxime Desroches ae8ef1f71a
misra8.4: safety modes (#2029)
safety mode
2024-09-19 10:30:57 -07:00
dzid26 d401ba169c
Enable misra-c2012-1.2 (#1962)
* misra-c2012-1.2 - allow __typeof__ compiler extension

* explicit c11
2024-05-30 22:13:47 -07:00
Adeeb Shihadeh 567dbfe6d8
remove comma pedal (#1902) 2024-03-17 22:22:46 -07:00
Aryan b4442a7c93
enable misra-c2012-10.3 (#1852)
* enable misra-c2012-10.3

* fix that

* cleanup

* little more

* one more

---------

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
2024-02-18 11:56:44 -08:00
Jason Young 00fab5e18e
refactor GET_BIT to be MISRA friendly (#1877)
* refactor GET_BIT to be MISRA friendly

* better fix for ternary op

* remove whitespace that crept in
2024-02-18 11:03:30 -08:00
Ruben Medina 7d99cb2ef3
enable misra-c2012-8.2 (#1829) 2024-01-21 16:19:16 -08:00
Ruben Medina 80731c0aa7
enable misra-constParameterCallback (#1827) 2024-01-20 22:22:11 -08:00
Ruben Medina 40671436ee
enable misra-constParameterPointer (#1826) 2024-01-20 21:50:42 -08:00
Adeeb Shihadeh 08ca10e91c
add AEB enable flag (#1791) 2024-01-11 15:37:43 -08:00
Shane Smiskol 6e645d2d33
safety: fully reset dynamic rx check fields (#1767)
* stash

* clean up

* clean up

* more clean up

* just status

* status

* does nothing

* not here
2023-12-15 21:59:19 -08:00
Shane Smiskol bb75afc84e
safety: add safety param for gas interceptor (#1735)
* some refactoring still needing to be done here

* 50hz

* set rx checks

* tx msgs

* test

* fix

* forgot to check this since it's static now

* enable_gas_interceptor

* more

* remove int funcs since are common

* generic!

* not generic

* need to set counter now

* set_enable_gas_interceptor not needed

* already reset in safety init

* fix test

* remove gas_interceptor_detected (partly)

* oof need for hjonda too

* edit structs

* more honda (still broken)

* fix typo

* shift these down

* can also make this extensible

* stash

* defining classes is much simpler, maybe in future we will have some sort of wrapper after some more thought

* remove create_interceptor_test now

* add lta interceptor

* clean up print

* clean up

* once

* type hint

* rm

* no interceptor with stock long + good test

* add interceptor counter to honda

* need alt interceptor + set rx checks for honda

* we were never testing button enable with nidec + interceptor!

honda almost all passing

* these fixes make sense

* clean up

* better

* clean up test cov

* clean up

* not needed

* fix tx msgs

* clean up

* cppcheck

* fix

* unnecessary
2023-12-14 15:22:17 -08:00
Shane Smiskol f741a90de8
safety: macro to update vehicle speed (#1762)
vehicle speed update macro
2023-12-06 18:05:07 -08:00
Adeeb Shihadeh 892ca5a0f1 this is a better name 2023-11-30 19:20:08 -08:00
Adeeb Shihadeh b50455cc76
safety: specify RX message frequency in Hz (#1754)
* safety: specify RX message frequency in Hz

* these are redundant now

* update that

* cleanup
2023-11-30 14:55:15 -08:00
Shane Smiskol 5884962372
Honda: fix alt brake address check race condition (#1746)
* common honda addr checks

* oohhhh

* rename RxCheck from merge

* more rename

* checked data and found 0x1A6 does not exist on any Bosch, so combining with 0x296 is safe

* formatting

* need this since refactor

* clean up

* fixup

* misra

* coverage caught another bug!

* another duplicate addr from multi tests

* proper base class

* formatting

* misra

* flat

* Revert "flat"

This reverts commit d5ea2adf26.

* forgot to specify bus (fuzzy test caught it, but whitelisting rx addrs
would so much quicker)
2023-11-27 00:18:24 -06:00
Adeeb Shihadeh c67c973b99 Revert "Honda: fix alt brake address check race condition (#1723)"
This reverts commit 42a62936fb.
2023-11-24 16:49:55 -08:00
Adeeb Shihadeh f1cd12651c
safety: remove LIN hook (#1741)
* safety: remove LIN hook

* rm more
2023-11-23 16:30:20 -08:00
Shane Smiskol 42a62936fb
Honda: fix alt brake address check race condition (#1723)
* common honda addr checks

* oohhhh

* rename RxCheck from merge

* more rename

* checked data and found 0x1A6 does not exist on any Bosch, so combining with 0x296 is safe

* formatting

* need this since refactor

* clean up

* fixup

* misra

* coverage caught another bug!

* another duplicate addr from multi tests

* proper base class

* formatting

* misra

* flat

* Revert "flat"

This reverts commit d5ea2adf26.
2023-11-20 19:27:18 -08:00
Adeeb Shihadeh 933a301cad
safety: do TX whitelist check in top level hook (#1730)
* new fields

* add check

* do first one

* first two

* all done

* fix all output

* simpler

* unused now

* fix body and elm

* fix that

* fix misra

* revert that
2023-11-20 00:15:46 -08:00
Adeeb Shihadeh b1ca493580
safety: fix ambiguous names (#1729)
renames
2023-11-19 22:44:13 -08:00
Adeeb Shihadeh 606d7580c8
safety: cleanup init return struct (#1728)
* try 1

* do the rest

* fix misra
2023-11-19 21:05:53 -08:00
Adeeb Shihadeh 3d2f99dd40
safety: move RX addr check into top level hook (#1727)
* safety: move RX addr check into top level hook

* tesla

* rest

* can't forget about the body

* rm more

* fix that

* cleanup

* drop the fn
2023-11-19 20:03:35 -08:00
Adeeb Shihadeh c6248d6504
safety: cleanup ints that are bools (#1726)
* safety: cleanup ints that are bools

* update tests
2023-11-19 16:47:09 -08:00
Shane Smiskol 43af1df79e
safety: sample_t is not fully reset on safety mode init (#1376)
* found another bug!

* update test

* why does toyota add 1 but not chrysler?!

* test/fix others

* clean up

* more

* global

* clean up

* one function to reset AND update

* without abs and only negative values: this is not caught (since negative error < 1)

* ugly draft

* clean up, tests work

* now only should use this function

* better cmt

* better loc

* constant in python too!

* actually duplicate comment
2023-10-03 03:15:16 -07:00
Shane Smiskol e9a0987617
Hyundai CAN FD: utilize macros for common address checks (#1658)
* draft

* now clean up old comments

* no more special broken ice addr checks

* revert

* fix

* add test for ICE HDA1

* Revert "add test for ICE HDA1"

This reverts commit 76d2b0f066.

* can be separate

* macro for addr check struct

* add checks for alt buttons (fixes race condition)

* add macro for array len

* add comment

* misra

* comments to help separate

* can't put parenthesis around array item

* review suggestions

* no intermediary macros for making the structs (remove misra violation)

* Update board/safety/safety_hyundai_canfd.h

* single lines

* can avoid double checking hda2 since we have addr checks for it now
2023-09-07 23:52:27 -07:00
Justin Newberry f4e63e7da5
Safety: Rename alt transmission rpm (#1583)
* renamre transmision rpm

* consistent whitespace

* rename declarations too
2023-08-15 17:25:44 -07:00
Justin Newberry 05295dc42a
Safety: alternate longitudinal limits (#1577)
alt limits
2023-08-12 19:34:53 -07:00
Shane Smiskol c1e79333fb
angle safety: make angle conversion factor a float (#1498)
* make this a float

* no need to cast to float now
2023-07-06 17:06:31 -07:00
Shane Smiskol 35609dfdce
safety utils: add ROUND helper (#1397)
* add round macro

* Update board/utils.h

* function

* one line

* misra

* use here too
2023-05-06 21:25:25 -07:00
Shane Smiskol 94cd9a0788
Ford: curvature rate limits (#1258)
* ford curvature rate limits draft

* make common angle tests work with curvature

* comment

* no need for this

* extra line

* fix test

* generic curvature test class

* more reasonable limits

* adjust limits

* draft

* works

* works

* clean up

* add vehicle speed

* works

* clean up

* clean up

* more clean up

* more clean up

* lower

* double

* add updated bp

* remove

* can clean that up

* draft

* this works!

* think that's the correct placement

* try this

* closer

* use min

* add/sub one to not falsely trip

* remove old angle error safety

* i'm not sure if clamp is more readable

* fix that

* fix

* stash

* fix these tests

* ternary

* floats are a pain

* draft, works kinda

* even better

* round that

* need tolerance

* this should work (adding tol=1 wouldn't let us have multiple rate limits)

* test works

* clamp breaks if low is higher than high :(((

down from 150 blocked msgs to 7!

* no blocked msgs!!!

* test a whole bunch

* stash

* stash

* clean up test

* clean up test to be more like torque (+ speeds)

* clean up

* cmt

* test up

* up and down are good

* rename and remove

* this is tested

* uncomment

* this is tested by ensuring we move towards error at a minimum rate

* not used any more

* revert common

* clean up test_ford a bit more

* some clean up (combine variables where it makes sense)

* yeah can't use clamp since min isn't always < max, min(max(.. handles this

* clean up

* revert that

* comments

* cmt

* another

* that's old

* misra!

* Update board/safety/safety_ford.h

* Update board/safety/safety_ford.h

* add todo, fix test case

* more clear, matches panda

* add comment

* Update tests/safety/test_ford.py

* more fine speed increments

* rm comment

* better names

* this is expected behavior (tested by common checks)

* CURVATURE_ERROR_LIMIT_SPEED

* better name?

* pretty clean!

* same for up

* only used in one place now

* these are now clear

* common term

* make vehicle_speed a sample_t

* need to use values[0]

* speed is a float

* Revert "speed is a float"

This reverts commit 01af02f1d3.

* Revert "need to use values[0]"

This reverts commit 8f6d68345a.

* Revert "make vehicle_speed a sample_t"

This reverts commit ecd8dc86b6.

* safety fixes for new speed sample

* test fixes for new speed sample

* fix misra and make intermediate variable

* this isn't needed
2023-05-04 04:59:35 +00:00
Shane Smiskol 3a64b6ccb5
safety: make vehicle_speed a sample (#1391)
* convert vehicle_speed into sample_t, change no behavior

* draft

* round

* test

* clean up

* round

* round all

* use min

* remove round macro from this PR

* reset speed measurement

* debug

* bbd

* rm

* revert

* test above and below

* need this now

* misra pt 1

* misra pt 2

* misra pt 3

* i don't understand this one, not different from other cases

* fix test

* test

* revert that

* draft

* test the sample_t works properly for safety modes that use it (angle only)

* can combine these tests

* test decimals

* global

* misra

comment

* suggestions

* fix

* use new helper
2023-05-04 03:37:56 +00:00
Shane Smiskol aa30b15de5
Ford safety: more clear variable names (#1392)
* that's a better name

* that too
2023-05-03 03:45:33 +00:00
Shane Smiskol 4160d8d71c
safety: common angle safety function (#1369)
* draft clean up

* always check

* add angle to name

* ford sends curvature when not steering and bit is 0.

it's not torque, curvature of 0 will still apply torque

* need this to be generic

* formatting

* rm

* test that we can send curvature=0 if enabled=False while control_allowed=True (let's say EPS faults, OP doesn't want to actuate)

* revert ford tests to master

* this <i>should</i> preserve behavior

* this is fine to remove

* and this should also be covered

* yeet

* change opt name, combine checks, much better!

* one more

* modes

* Add comment

* misra has a bug :(

* ugh

* make this clear

* ?

* order

* fix

* comments
2023-04-27 23:33:54 -07:00
Shane Smiskol c9c3cb38f6
Ford safety: curvature error limit (#1353)
* set ford vehicle speed

* parse yaw rate signals

* misra

* misra

* misra

* misra

* draft

* update module

* already checked

* and set it properly

* some stuff

* draft

* clean up (will fail tests because we don't send yaw rate yet)

* could do something like this

* this is better and less prone to bugs

* match simple op limiting, debugging

* set checksum for messages in tests

* clean up

* fix that

* one m/s fudge

* fix sign of yaw rate

* interpolate detects size

* forgot OP flips the curvature sign. it matches yaw on can

* all my debugging crap

* make replay work for ford

* fix panda blocking messages (array is fixed size so size-1 is 0 rate at high speed)

* uncomment safety test limits

* revert

* round for zero blocked msgs

* fix limits

* meas safety checks that down rate is >=, not <

* test pass

* lots of comments and draft what one meas torque check would look like

* fix that

* add curvature meas

* add debugging stuff

* Revert "add debugging stuff"

This reverts commit 449783fc62.

* messy but at least one test passes now

* draft

* add max_steer

* some safety clean up

* and that

* start with a test that works

* another test that works (sort of, we need more strict panda safety without false positives)

* no max curvature check (not safety related), allow any rate limits

* add new function

* also need to consider max val here, since OP will send up to that

* and now use the function

* lower to 10

* compilation fixes

* clean up (no rate limiting)

* remove that too

* curvature diff test

* more clean up

* debug

* ?

* better names

* more official

* use _curvature_meas_msg_array here

* bit faster

* no i don't

* revert that

* why not just use angle_meas?

* bb ll

* bb deb

* clean up debug vals

* more

* revert replay drive debugging changes

* Update board/safety.h

* rm line

* only need to round the final thing

* not needed, under 10 ms

* make a class variable

* fix a misra?

* another misra?

better

* ?

* 12.1

* need to explicitly convert

* add one to not false trigger the violation (float rounding)

* not really needed

* rm line

* cmt

* use clamp

* rename

* in struct

* comment

* use max_limit_check

* draft clean up

* Revert "draft clean up"

This reverts commit d1a0e8acd1.

* make a global

make a global

* this is fine
2023-04-27 00:40:29 -07:00
Adeeb Shihadeh 7aef934d4c
Fix undefined behavior in GET_BYTES macro (#1367) 2023-04-26 22:59:58 -07:00
Shane Smiskol f3d6d613c0
safety: don't check out of bounds array item (#1360)
* safety: don't check out of bounds array item

* better name

* cleanup

---------

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
2023-04-26 19:43:30 -07:00
Adeeb Shihadeh 85cc70d4aa
safety: only pass addr to fwd hook (#1339) 2023-04-08 16:45:59 -07:00
Shane Smiskol f7ba061279
Ford: test quality flags (#1266)
* adeeb

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>

* check checksum

* think pylint won't like this

* complete test

* do this

* no need

---------

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
2023-03-01 19:17:40 -08:00
Shane Smiskol 8bb62cf226
Ford: check quality flag (#1264)
* quality flag support

* add NULL to other safety modes

* add to safety helpers debug print

* comment

* rename to quality_flag and add comment
2023-02-24 22:54:51 -08:00
Shane Smiskol a6d0765b69
safety: common angle checks (#1182)
* common angle checks

* clean up

* clean up check and add comments

* readable

* ints

* tests draft

* clean up

* comment

* pylint exception

* clean up

* duplicate
2022-12-02 16:45:23 -08:00
Robbe Derks 288e14cde9
Simple CAN chunking (#1011)
* simple chunking

* make pylint happy

* misra happy?

* good practice anyways since we cast to a uint32_t later

* fix bug dropping packets

* minor fixes + prepare for shared lib testing

* working library now

* first queue test

* can send test

* fix running in github actions?

* add big rx test and fix it

* don't complain about empty buffers

* disable for now

* comment

* test runs

* some cleanup

* merge those

* test works

* rm that

* comment

* proper logging

* makes things too slow

Co-authored-by: Comma Device <device@comma.ai>
Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
2022-11-30 23:38:00 -08:00
Shane Smiskol b238d41979
safety: clean up passing in longitudinal_allowed (#1176)
* clean up

* clean up

* and fix that

* interceptor func

* fix

* draft

* fix that
2022-11-30 22:09:13 -08:00
Shane Smiskol a0b1d64e4e
Honda Nidec: max gas safety and common speed cmd checks (#1179)
* limit gas and speed

* gas safety test
2022-11-30 18:56:05 -08:00
Shane Smiskol cb8fc6bd42
safety: common interceptor checks (#1178)
* interceptor checks

* only one line needed for now

* whoops

* misra

* misread as |
2022-11-30 17:22:42 -08:00
Shane Smiskol e8bd1df511
safety: common gas & brake safety checks (#1168)
* do toyota, hyundai, gm

* comments

* honda draft

* Revert "honda draft"

This reverts commit a1f466a5c9.

* do tesla

* vw draft

* finish vw

* fix safety

* clean up

* fix function names

* do honda and fix safety test not checking pos accel for bosch

* clean that up
2022-11-29 23:45:55 -08:00
Shane Smiskol 2baa0ffed5
Safety: common acceleration cmd checks (#1171)
* do toyota, hyundai, gm

* comments

* honda draft

* Revert "honda draft"

This reverts commit a1f466a5c9.

* do tesla

* vw draft

* finish vw

* fix safety

* only accel

* only accel

* some clean up

* fix mqb tests

* rename
2022-11-29 16:46:32 -08:00
Shane Smiskol 0a819ad465
Torque request bit: support multiple invalid frames (#1094)
* h90d safety

* quicker rate

* update comment

* support multi frames?

* stash

* stash

* might work?

* stash

* clean up

* revert that

* add test

* fixup tests

* clean up

* remove test

* try to combine tests

* Revert "try to combine tests"

This reverts commit f147955b94.

* seems simpler

* more explicit

* shouldn't be needed

* no hyundai stuff

* no line

* consecutively

* comment

* comment

* comment

* revert

* comment

* check earlier

check earlier

* ensure we don't set a negative value

* add todo comments

* for loop
2022-10-11 13:20:24 -07:00
Adeeb Shihadeh e987e6c639
add pandaState.safetyRxChecksInvalid field (#1083)
* add fault for invalid safety RX checks

* fix test build

* debug

* fix debug

* fix test

* just a bool in health
2022-10-03 16:05:16 -07:00