From 813d5b99824593e76f2c906df086c19ca29a94f3 Mon Sep 17 00:00:00 2001 From: Vehicle Researcher Date: Mon, 22 Jul 2019 19:15:25 +0000 Subject: [PATCH 1/4] Squashed 'cereal/' changes from 9f2076eef..4ea03bacb 4ea03bacb add speed 2198ad240 add alert for invalid posenet 9c18b3b21 rename to posenetValid 42669a812 add posenet debug fields to LiveParameters 852846f17 add whether point is detected by radar 1684698e5 add model prob fb87dba0b added HW type to support various panda versions 820bf7b4c added tooDistracted event 1105dc1e8 different name 45c424989 add second model lead f8c557fa3 Log can errors from panda 04f105a22 back ff9332035 add lead stuff git-subtree-dir: cereal git-subtree-split: 4ea03bacbfad1f086caa458de7788771b0c7c515 --- car.capnp | 2 ++ log.capnp | 25 ++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/car.capnp b/car.capnp index f30b20f97..fd781f9b1 100644 --- a/car.capnp +++ b/car.capnp @@ -76,6 +76,8 @@ struct CarEvent @0x9b1657f34caf3ad3 { controlsFailed @51; sensorDataInvalid @52; commIssue @53; + tooDistracted @54; + posenetInvalid @55; } } diff --git a/log.capnp b/log.capnp index adf76c488..3dbbc516d 100644 --- a/log.capnp +++ b/log.capnp @@ -300,8 +300,20 @@ struct HealthData { started @2 :Bool; controlsAllowed @3 :Bool; gasInterceptorDetected @4 :Bool; - startedSignalDetected @5 :Bool; + startedSignalDetectedDeprecated @5 :Bool; isGreyPanda @6 :Bool; + canSendErrs @7 :UInt32; + canFwdErrs @8 :UInt32; + gmlanSendErrs @9 :UInt32; + hwType @10: HwType; + + enum HwType { + unknown @0; + whitePanda @1; + greyPanda @2; + blackPanda @3; + pedal @4; + } } struct LiveUI { @@ -343,6 +355,8 @@ struct RadarState @0x9a185389d6fdd05f { fcw @10 :Bool; status @11 :Bool; aLeadTau @12 :Float32; + modelProb @13 :Float32; + radar @14 :Bool; } } @@ -508,6 +522,8 @@ struct ModelData { freePath @6 :List(Float32); settings @5 :ModelSettings; + leadFuture @7 :LeadData; + speed @8 :List(Float32); struct PathData { points @0 :List(Float32); @@ -523,6 +539,10 @@ struct ModelData { std @2 :Float32; relVel @3 :Float32; relVelStd @4 :Float32; + relY @5 :Float32; + relYStd @6 :Float32; + relA @7 :Float32; + relAStd @8 :Float32; } struct ModelSettings { @@ -662,6 +682,7 @@ struct PathPlan { angleOffset @11 :Float32; sensorValid @14 :Bool; commIssue @15 :Bool; + posenetValid @16 :Bool; } struct LiveLocationData { @@ -1659,6 +1680,8 @@ struct LiveParametersData { steerRatio @5 :Float32; sensorValid @6 :Bool; yawRate @7 :Float32; + posenetSpeed @8 :Float32; + posenetValid @9 :Bool; } struct LiveMapData { From 1ff59baea717f88e8038c01ead864ad5acb85f35 Mon Sep 17 00:00:00 2001 From: Vehicle Researcher Date: Mon, 22 Jul 2019 19:15:27 +0000 Subject: [PATCH 2/4] Squashed 'panda/' changes from ae816c104..45d0d286f MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 45d0d286f remove whitespace (#255) e49d0dbbd Pedal: use avg between tracks (#253) c597dcc89 VERSION update after health packet changes and minor misra test change 01072bec0 Misra 11.x: pointer usage. (#250) fd68c26ab Propagate can_push errors (#249) ce1daf206 Misra check only done for EON config 70d4fd7f6 cleanup docker container on failure 04756a037 Turning back Misra check: unvoluntarily change fcb1208e1 fix weird code in USB_ReadPacket b983cc8fe Re-wrote test_misra.sh 0b1920636 Misra 17.7: The value returned by a function having non-void return type shall be used. We should hang on initial failed safety_set_mode 06ee8bd2d Ignore Misra 5.4 until cppcheck bug (?) is fixed 4be858224 Update cppcheck commit and pass predefined params to avoid impossible combinations of configs f45dd04c6 cppcheck: ignore redundantAssignment and selfAssignment for registers in llcan.h 9ce631155 Misra 12.1 (operator order) and 10.4 (incompatible essential types) fixes, arised after properly checking UID_BASE config 1cd34e564 Explicitly set the define and undefine for unknown configs in misra checks 5a024999d remove esp flash from run_automated_tests.sh 23e3684d7 Cppcheck unused functions (#247) c97d60be6 Removed bad language b031480a7 Missed adding Dockerfile 91ff6bb21 Run language checker in CI 205ec342a Improved language checker f7bbab072 Language checker test d9d0a62f2 Misra 5.5: missed this change from previous PR 85fa3c02a Misra 5.5: Identifiers shall be distinct from macro names (#246) 190d604a0 Pedal: 2 minor fixes to Misra 15.7 (else needed) and 17.7 (non-void output must be used) 8ea01ff12 Pedal: no built-in functions to avoid puts and putc re-definitions 1f40d1e6a Misra pedal (#245) a4554e3e6 Ignore advisory Misra 19.2: the union keyword should not be used e6dc4172b Minor indent error 247e128b4 Fix strict compiler on bootstub build ba6856921 Removed build strict test and enabled -Werror flag da11f0fa0 safety replay: update openpilot-tools after logreader fix fc8b9e49b Cppcheck: also check pedal f7bd2c2f3 Misra 10.4: fix last 2 violations (#242) 9be5fdead finished misra 17.8 (#241) 3c3aba3db Misra 10.4: Both operands of an operator in which the usual arithmetic conversions are performed shall have the same essential type category (#240) f2a3a177b Misra 15_7: fix what seems to be a false positive of cppcheck 812ace538 Misra 15_7: if … else if constructs should be terminated with an else clause (#230) 79e9735ae rename 5_wifi_udp.py 3c3ff0c03 Update Jenkinsfile (#239) 1bd928437 Misra 17.7: the value returned by a function having non-void return shall be used (#237) 18c9e88bc Merge pull request #238 from commaai/misra_17_8 7ac321de4 Merge pull request #235 from commaai/memxxx 004e543cc Jenkins: run EON test first 4bff28620 Merge branch 'memxxx' of github.com:commaai/panda into memxxx 7cd80de23 typo 385e33b32 12.1 regression 955842bae WIP ea908cbb7 10_1 violations: Operands shall not be of an inappropriate essential type (#233) fa3303805 Fix Misra 5.3: An identifier declared in an inner scope shall not hide an identifier declared in an outer scope (#236) ebfe1c512 Merge branch 'master' of github.com:commaai/panda into memxxx 8c11470ef Fix EON test case 64e18e841 fix inverted logic to differentiate between dev and EON panda builds 36755a0fd Merge branch 'master' of github.com:commaai/panda into memxxx e2981d612 skip wifi tests for EON panda build db2eec98c Merge branch 'master' of github.com:commaai/panda into memxxx 11257e79a Ignore test 5_wifi_udp.py_ignore: too unreliable for now 6973c2a81 fix wifi tests cf6985ad1 memxxx function changes to be Misra compliant 3a6cd2930 wifi threshold perc back to 20%. Problem wasn't this. d92a03528 faster docker build for safety replay 3e9469b3e Fixing tests after min->MIN change ecb9b6c01 Revert "Misra 10 1: Operands shall not be of an inappropriate essential type (#232)" 8732e4faf Misra 10 1: Operands shall not be of an inappropriate essential type (#232) git-subtree-dir: panda git-subtree-split: 45d0d286f4b5c893590a98ec1438b8a143b9605d --- .circleci/config.yml | 28 +- Jenkinsfile | 42 +- VERSION | 2 +- board/Makefile | 2 +- board/Makefile.strict | 8 - board/bootstub.c | 17 +- board/config.h | 8 +- board/drivers/adc.h | 2 +- board/drivers/can.h | 112 +- board/drivers/clock.h | 2 +- board/drivers/dac.h | 9 +- board/drivers/gmlan_alt.h | 59 +- board/drivers/llcan.h | 69 +- board/drivers/llgpio.h | 30 +- board/drivers/spi.h | 10 +- board/drivers/uart.h | 61 +- board/drivers/usb.h | 112 +- board/gpio.h | 22 +- board/inc/stm32f205xx.h | 408 +- board/inc/stm32f2xx.h | 46 +- board/inc/stm32f2xx_hal_def.h | 46 +- board/inc/stm32f2xx_hal_gpio_ex.h | 118 +- board/inc/stm32f413xx.h | 8568 ++++++++--------- board/inc/stm32f4xx.h | 52 +- board/inc/stm32f4xx_hal_def.h | 58 +- board/inc/stm32f4xx_hal_gpio_ex.h | 976 +- board/inc/system_stm32f2xx.h | 20 +- board/inc/system_stm32f4xx.h | 22 +- board/libc.h | 28 +- board/main.c | 187 +- board/pedal/Makefile | 4 +- board/pedal/main.c | 147 +- board/power_saving.h | 4 +- board/provision.h | 4 +- board/safety.h | 30 +- board/safety/safety_cadillac.h | 15 +- board/safety/safety_chrysler.h | 8 +- board/safety/safety_ford.h | 24 +- board/safety/safety_gm.h | 31 +- board/safety/safety_gm_ascm.h | 2 +- board/safety/safety_honda.h | 35 +- board/safety/safety_hyundai.h | 8 +- board/safety/safety_subaru.h | 6 +- board/safety/safety_tesla.h | 24 +- board/safety/safety_toyota.h | 14 +- board/safety/safety_toyota_ipas.h | 12 +- board/safety_declarations.h | 7 +- board/spi_flasher.h | 32 +- board/startup_stm32f205xx.s | 40 +- board/startup_stm32f413xx.s | 58 +- boardesp/webserver.c | 10 +- crypto/sha.c | 2 +- .../pandaJ2534DLL/PandaJ2534Device.cpp | 2 +- drivers/windows/pandaJ2534DLL/resource.h | 2 +- examples/can_unique.md | 4 +- examples/get_panda_password.py | 6 +- examples/tesla_tester.py | 16 +- python/esptool.py | 2 +- python/flash_release.py | 2 +- python/isotp.py | 2 +- run_automated_tests.sh | 19 +- tests/automated/5_wifi_udp.py | 2 +- tests/build_strict/Dockerfile | 9 - tests/build_strict/test_build_strict.sh | 15 - tests/elm_car_simulator.py | 6 +- tests/gmbitbang/test_one.py | 2 +- tests/language/Dockerfile | 6 + tests/language/LICENSE | 201 + tests/language/list.txt | 451 + tests/language/test_language.py | 28 + tests/misra/suppressions.txt | 8 + tests/misra/test_misra.sh | 51 +- tests/safety/libpandasafety_py.py | 2 +- tests/safety/test.c | 15 +- tests/safety/test_honda.py | 29 +- tests/safety/test_toyota.py | 25 +- tests/safety_replay/Dockerfile | 2 +- tests/safety_replay/install_capnp.sh | 10 - 78 files changed, 6702 insertions(+), 5856 deletions(-) delete mode 100644 board/Makefile.strict delete mode 100644 tests/build_strict/Dockerfile delete mode 100755 tests/build_strict/test_build_strict.sh create mode 100644 tests/language/Dockerfile create mode 100644 tests/language/LICENSE create mode 100644 tests/language/list.txt create mode 100755 tests/language/test_language.py create mode 100644 tests/misra/suppressions.txt diff --git a/.circleci/config.yml b/.circleci/config.yml index e36aaa142..fdafd3da1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -40,19 +40,6 @@ jobs: path: /tmp/misra/misra_safety_output.txt - strict-compiler: - machine: - docker_layer_caching: true - steps: - - checkout - - run: - name: Build image - command: "docker build -t panda_strict_compiler -f tests/build_strict/Dockerfile ." - - run: - name: Build Panda with strict compiler rules - command: | - docker run panda_strict_compiler /bin/bash -c "cd /panda/tests/build_strict; ./test_build_strict.sh" - build: machine: docker_layer_caching: true @@ -99,12 +86,25 @@ jobs: command: | docker run panda_safety_replay /bin/bash -c "cd /openpilot/panda/tests/safety_replay; PYTHONPATH=/openpilot ./test_safety_replay.py" + language_check: + machine: + docker_layer_caching: true + steps: + - checkout + - run: + name: Build image + command: "docker build -t language_check -f tests/language/Dockerfile ." + - run: + name: Check code for bad language + command: | + docker run language_check /bin/bash -c "cd /panda/tests/language; ./test_language.py" + workflows: version: 2 main: jobs: - safety - misra-c2012 - - strict-compiler - build - safety_replay + - language_check diff --git a/Jenkinsfile b/Jenkinsfile index 0a861a5fa..19dc3d4c8 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -20,34 +20,54 @@ pipeline { } } } - stage('Test Dev Build') { + stage('Test Dev Build (no WIFI)') { steps { - lock(resource: "Pandas", inversePrecedence: true, quantity:1){ + lock(resource: "Pandas", inversePrecedence: true, quantity: 1){ timeout(time: 60, unit: 'MINUTES') { - 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 '" + 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; SKIPWIFI=1 ./run_automated_tests.sh'" + sh "docker cp ${env.DOCKER_NAME}:/tmp/panda/nosetests.xml test_results_dev_nowifi.xml" + sh "docker rm ${env.DOCKER_NAME}" + } } } } } stage('Test EON Build') { steps { - lock(resource: "Pandas", inversePrecedence: true, quantity:1){ + lock(resource: "Pandas", inversePrecedence: true, quantity: 1){ timeout(time: 60, unit: 'MINUTES') { - sh "docker cp ${env.DOCKER_NAME}:/tmp/panda/nosetests.xml test_results_dev.xml" - sh "touch EON && docker cp EON ${env.DOCKER_NAME}:/EON" - sh "docker start -a ${env.DOCKER_NAME}" + 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 'touch /EON; cd /tmp/panda; ./run_automated_tests.sh'" + sh "docker cp ${env.DOCKER_NAME}:/tmp/panda/nosetests.xml test_results_eon.xml" + sh "docker rm ${env.DOCKER_NAME}" + } + } + } + } + } + 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 { - always { + failure { script { - sh "docker cp ${env.DOCKER_NAME}:/tmp/panda/nosetests.xml test_results_EON.xml" - sh "docker rm ${env.DOCKER_NAME}" + sh "docker rm ${env.DOCKER_NAME} || true" } + } + always { junit "test_results*.xml" } } -} \ No newline at end of file +} diff --git a/VERSION b/VERSION index ec7b96782..9bdb566fc 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v1.4.0 \ No newline at end of file +v1.4.1 \ No newline at end of file diff --git a/board/Makefile b/board/Makefile index ed6dcaa03..adeba0479 100644 --- a/board/Makefile +++ b/board/Makefile @@ -1,5 +1,5 @@ PROJ_NAME = panda -CFLAGS = -g -Wall +CFLAGS = -g -Wall -Wextra -Wstrict-prototypes -Werror CFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m4 CFLAGS += -mhard-float -DSTM32F4 -DSTM32F413xx -mfpu=fpv4-sp-d16 -fsingle-precision-constant diff --git a/board/Makefile.strict b/board/Makefile.strict deleted file mode 100644 index b6c72b58b..000000000 --- a/board/Makefile.strict +++ /dev/null @@ -1,8 +0,0 @@ -PROJ_NAME = panda -CFLAGS = -g -Wall -Wextra -Wstrict-prototypes - -CFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m4 -CFLAGS += -mhard-float -DSTM32F4 -DSTM32F413xx -mfpu=fpv4-sp-d16 -fsingle-precision-constant -STARTUP_FILE = startup_stm32f413xx - -include build.mk diff --git a/board/bootstub.c b/board/bootstub.c index 691d0d02e..799c39d05 100644 --- a/board/bootstub.c +++ b/board/bootstub.c @@ -13,8 +13,13 @@ #endif // default since there's no serial -void puts(const char *a) {} -void puth(unsigned int i) {} +void puts(const char *a) { + UNUSED(a); +} + +void puth(unsigned int i) { + UNUSED(i); +} #include "libc.h" #include "provision.h" @@ -34,11 +39,11 @@ void puth(unsigned int i) {} #include "spi_flasher.h" -void __initialize_hardware_early() { +void __initialize_hardware_early(void) { early(); } -void fail() { +void fail(void) { soft_flasher_start(); } @@ -48,7 +53,7 @@ extern void *_app_start[]; // FIXME: sometimes your panda will fail flashing and will quickly blink a single Green LED // BOUNTY: $200 coupon on shop.comma.ai or $100 check. -int main() { +int main(void) { __disable_irq(); clock_init(); detect(); @@ -88,7 +93,7 @@ fail: return 0; good: // jump to flash - ((void(*)()) _app_start[1])(); + ((void(*)(void)) _app_start[1])(); return 0; } diff --git a/board/config.h b/board/config.h index 219ce64c2..7fd203fc3 100644 --- a/board/config.h +++ b/board/config.h @@ -12,12 +12,12 @@ #include "stm32f2xx.h" #endif -#define USB_VID 0xbbaa +#define USB_VID 0xbbaaU #ifdef BOOTSTUB -#define USB_PID 0xddee +#define USB_PID 0xddeeU #else -#define USB_PID 0xddcc +#define USB_PID 0xddccU #endif #include @@ -34,7 +34,7 @@ __typeof__ (b) _b = (b); \ (_a > _b) ? _a : _b; }) -#define MAX_RESP_LEN 0x40 +#define MAX_RESP_LEN 0x40U #endif diff --git a/board/drivers/adc.h b/board/drivers/adc.h index 3e5f1b32a..efd0a1687 100644 --- a/board/drivers/adc.h +++ b/board/drivers/adc.h @@ -19,7 +19,7 @@ void adc_init(void) { ADC1->SMPR1 = ADC_SMPR1_SMP12 | ADC_SMPR1_SMP13; } -uint32_t adc_get(int channel) { +uint32_t adc_get(unsigned int channel) { // includes length //ADC1->SQR1 = 0; diff --git a/board/drivers/can.h b/board/drivers/can.h index 7d0e63058..3db211051 100644 --- a/board/drivers/can.h +++ b/board/drivers/can.h @@ -9,11 +9,14 @@ typedef struct { CAN_FIFOMailBox_TypeDef *elems; } can_ring; -#define CAN_BUS_RET_FLAG 0x80 -#define CAN_BUS_NUM_MASK 0x7F +#define CAN_BUS_RET_FLAG 0x80U +#define CAN_BUS_NUM_MASK 0x7FU -#define BUS_MAX 4 +#define BUS_MAX 4U +uint32_t can_send_errs = 0; +uint32_t can_fwd_errs = 0; +uint32_t gmlan_send_errs = 0; extern int can_live, pending_can_live; // must reinit after changing these @@ -63,8 +66,11 @@ bool can_pop(can_ring *q, CAN_FIFOMailBox_TypeDef *elem) { enter_critical_section(); if (q->w_ptr != q->r_ptr) { *elem = q->elems[q->r_ptr]; - if ((q->r_ptr + 1) == q->fifo_size) q->r_ptr = 0; - else q->r_ptr += 1; + if ((q->r_ptr + 1U) == q->fifo_size) { + q->r_ptr = 0; + } else { + q->r_ptr += 1U; + } ret = 1; } exit_critical_section(); @@ -72,20 +78,23 @@ bool can_pop(can_ring *q, CAN_FIFOMailBox_TypeDef *elem) { return ret; } -int can_push(can_ring *q, CAN_FIFOMailBox_TypeDef *elem) { - int ret = 0; +bool can_push(can_ring *q, CAN_FIFOMailBox_TypeDef *elem) { + bool ret = false; uint32_t next_w_ptr; enter_critical_section(); - if ((q->w_ptr + 1) == q->fifo_size) next_w_ptr = 0; - else next_w_ptr = q->w_ptr + 1; + if ((q->w_ptr + 1U) == q->fifo_size) { + next_w_ptr = 0; + } else { + next_w_ptr = q->w_ptr + 1U; + } if (next_w_ptr != q->r_ptr) { q->elems[q->w_ptr] = *elem; q->w_ptr = next_w_ptr; - ret = 1; + ret = true; } exit_critical_section(); - if (ret == 0) { + if (!ret) { can_overflow_cnt++; #ifdef DEBUG puts("can_push failed!\n"); @@ -130,7 +139,7 @@ void can_set_speed(uint8_t can_number) { CAN_TypeDef *CAN = CANIF_FROM_CAN_NUM(can_number); uint8_t bus_number = BUS_NUM_FROM_CAN_NUM(can_number); - if (!llcan_set_speed(CAN, can_speed[bus_number], can_loopback, can_silent & (1 << can_number))) { + if (!llcan_set_speed(CAN, can_speed[bus_number], can_loopback, (unsigned int)(can_silent) & (1U << can_number))) { puts("CAN init FAILED!!!!!\n"); puth(can_number); puts(" "); puth(BUS_NUM_FROM_CAN_NUM(can_number)); puts("\n"); @@ -138,7 +147,7 @@ void can_set_speed(uint8_t can_number) { } void can_init(uint8_t can_number) { - if (can_number != 0xff) { + if (can_number != 0xffU) { CAN_TypeDef *CAN = CANIF_FROM_CAN_NUM(can_number); set_can_enable(CAN, 1); can_set_speed(can_number); @@ -156,48 +165,45 @@ void can_init_all(void) { } } -void can_set_gmlan(int bus) { - if ((bus == -1) || (bus != can_num_lookup[3])) { - // GMLAN OFF - switch (can_num_lookup[3]) { +void can_set_gmlan(uint8_t bus) { + + // first, disable GMLAN on prev bus + uint8_t prev_bus = can_num_lookup[3]; + if (bus != prev_bus) { + switch (prev_bus) { case 1: - puts("disable GMLAN on CAN2\n"); - set_can_mode(1, 0); - bus_lookup[1] = 1; - can_num_lookup[1] = 1; - can_num_lookup[3] = -1; - can_init(1); - break; case 2: - puts("disable GMLAN on CAN3\n"); - set_can_mode(2, 0); - bus_lookup[2] = 2; - can_num_lookup[2] = 2; + puts("Disable GMLAN on CAN"); + puth(prev_bus + 1U); + puts("\n"); + set_can_mode(prev_bus, 0); + bus_lookup[prev_bus] = prev_bus; + can_num_lookup[prev_bus] = prev_bus; can_num_lookup[3] = -1; - can_init(2); + can_init(prev_bus); break; default: - puts("GMLAN bus value invalid\n"); + // GMLAN was not set on either BUS 1 or 2 break; } } - if (bus == 1) { - puts("GMLAN on CAN2\n"); - // GMLAN on CAN2 - set_can_mode(1, 1); - bus_lookup[1] = 3; - can_num_lookup[1] = -1; - can_num_lookup[3] = 1; - can_init(1); - } else if (bus == 2) { - puts("GMLAN on CAN3\n"); - // GMLAN on CAN3 - set_can_mode(2, 1); - bus_lookup[2] = 3; - can_num_lookup[2] = -1; - can_num_lookup[3] = 2; - can_init(2); + // now enable GMLAN on the new bus + switch (bus) { + case 1: + case 2: + puts("Enable GMLAN on CAN"); + puth(bus + 1U); + puts("\n"); + set_can_mode(bus, 1); + bus_lookup[bus] = 3; + can_num_lookup[bus] = -1; + can_num_lookup[3] = bus; + can_init(bus); + break; + default: + puts("GMLAN can only be set on CAN2 or CAN3"); + break; } } @@ -232,7 +238,7 @@ void can_sce(CAN_TypeDef *CAN) { // ***************************** CAN ***************************** void process_can(uint8_t can_number) { - if (can_number != 0xff) { + if (can_number != 0xffU) { enter_critical_section(); @@ -249,10 +255,10 @@ void process_can(uint8_t can_number) { if ((CAN->TSR & CAN_TSR_TXOK0) == CAN_TSR_TXOK0) { CAN_FIFOMailBox_TypeDef to_push; to_push.RIR = CAN->sTxMailBox[0].TIR; - to_push.RDTR = (CAN->sTxMailBox[0].TDTR & 0xFFFF000F) | ((CAN_BUS_RET_FLAG | bus_number) << 4); + to_push.RDTR = (CAN->sTxMailBox[0].TDTR & 0xFFFF000FU) | ((CAN_BUS_RET_FLAG | bus_number) << 4); to_push.RDLR = CAN->sTxMailBox[0].TDLR; to_push.RDHR = CAN->sTxMailBox[0].TDHR; - can_push(&can_rx_q, &to_push); + can_send_errs += !can_push(&can_rx_q, &to_push); } if ((CAN->TSR & CAN_TSR_TERR0) == CAN_TSR_TERR0) { @@ -321,7 +327,7 @@ void can_rx(uint8_t can_number) { safety_rx_hook(&to_push); set_led(LED_BLUE, 1); - can_push(&can_rx_q, &to_push); + can_send_errs += !can_push(&can_rx_q, &to_push); // next CAN->RF0R |= CAN_RF0R_RFOM0; @@ -346,11 +352,11 @@ void can_send(CAN_FIFOMailBox_TypeDef *to_push, uint8_t bus_number) { // add CAN packet to send queue // bus number isn't passed through to_push->RDTR &= 0xF; - if ((bus_number == 3) && (can_num_lookup[3] == 0xFF)) { + if ((bus_number == 3U) && (can_num_lookup[3] == 0xFFU)) { // TODO: why uint8 bro? only int8? - bitbang_gmlan(to_push); + gmlan_send_errs += !bitbang_gmlan(to_push); } else { - can_push(can_queues[bus_number], to_push); + can_fwd_errs += !can_push(can_queues[bus_number], to_push); process_can(CAN_NUM_FROM_BUS_NUM(bus_number)); } } diff --git a/board/drivers/clock.h b/board/drivers/clock.h index a9f2dea73..d564c7f01 100644 --- a/board/drivers/clock.h +++ b/board/drivers/clock.h @@ -3,7 +3,7 @@ void clock_init(void) { RCC->CR |= RCC_CR_HSEON; while ((RCC->CR & RCC_CR_HSERDY) == 0); - // divide shit + // divide things RCC->CFGR = RCC_CFGR_HPRE_DIV1 | RCC_CFGR_PPRE2_DIV2 | RCC_CFGR_PPRE1_DIV4; // 16mhz crystal diff --git a/board/drivers/dac.h b/board/drivers/dac.h index b8833dc4a..ac565eb22 100644 --- a/board/drivers/dac.h +++ b/board/drivers/dac.h @@ -1,4 +1,7 @@ -void dac_init() { +void puth(unsigned int i); +void puts(const char *a); + +void dac_init(void) { // no buffers required since we have an opamp //DAC->CR = DAC_CR_EN1 | DAC_CR_BOFF1 | DAC_CR_EN2 | DAC_CR_BOFF2; DAC->DHR12R1 = 0; @@ -11,6 +14,10 @@ void dac_set(int channel, uint32_t value) { DAC->DHR12R1 = value; } else if (channel == 1) { DAC->DHR12R2 = value; + } else { + puts("Failed to set DAC: invalid channel value: "); + puth(value); + puts("\n"); } } diff --git a/board/drivers/gmlan_alt.h b/board/drivers/gmlan_alt.h index 357cffcd9..c697a21b4 100644 --- a/board/drivers/gmlan_alt.h +++ b/board/drivers/gmlan_alt.h @@ -41,35 +41,38 @@ int do_bitstuff(char *out, char *in, int in_len) { } int append_crc(char *in, int in_len) { - int crc = 0; + unsigned int crc = 0; for (int i = 0; i < in_len; i++) { crc <<= 1; - if ((in[i] ^ ((crc >> 15) & 1)) != 0) { - crc = crc ^ 0x4599; + if (((unsigned int)(in[i]) ^ ((crc >> 15) & 1U)) != 0U) { + crc = crc ^ 0x4599U; } - crc &= 0x7fff; + crc &= 0x7fffU; } + int in_len_copy = in_len; for (int i = 14; i >= 0; i--) { - in[in_len] = (crc>>i)&1; - in_len++; + in[in_len_copy] = (crc >> (unsigned int)(i)) & 1U; + in_len_copy++; } - return in_len; + return in_len_copy; } int append_bits(char *in, int in_len, char *app, int app_len) { + int in_len_copy = in_len; for (int i = 0; i < app_len; i++) { - in[in_len] = app[i]; - in_len++; + in[in_len_copy] = app[i]; + in_len_copy++; } - return in_len; + return in_len_copy; } int append_int(char *in, int in_len, int val, int val_len) { - for (int i = val_len-1; i >= 0; i--) { - in[in_len] = (val&(1<= 0; i--) { + in[in_len_copy] = ((unsigned int)(val) & (1U << (unsigned int)(i))) != 0U; + in_len_copy++; } - return in_len; + return in_len_copy; } int get_bit_message(char *out, CAN_FIFOMailBox_TypeDef *to_bang) { @@ -92,7 +95,7 @@ int get_bit_message(char *out, CAN_FIFOMailBox_TypeDef *to_bang) { // extended identifier len = append_int(pkt, len, to_bang->RIR >> 21, 11); // Identifier len = append_int(pkt, len, 3, 2); // SRR+IDE - len = append_int(pkt, len, (to_bang->RIR >> 3) & ((1<<18)-1), 18); // Identifier + len = append_int(pkt, len, (to_bang->RIR >> 3) & ((1U << 18) - 1U), 18); // Identifier len = append_int(pkt, len, 0, 3); // RTR+r1+r0 } else { // standard identifier @@ -168,15 +171,16 @@ void reset_gmlan_switch_timeout(void) { void set_bitbanged_gmlan(int val) { if (val != 0) { - GPIOB->ODR |= (1 << 13); + GPIOB->ODR |= (1U << 13); } else { - GPIOB->ODR &= ~(1 << 13); + GPIOB->ODR &= ~(1U << 13); } } char pkt_stuffed[MAX_BITS_CAN_PACKET]; int gmlan_sending = -1; int gmlan_sendmax = -1; +bool gmlan_send_ok = true; int gmlan_silent_count = 0; int gmlan_fail_count = 0; @@ -193,7 +197,7 @@ void TIM4_IRQHandler(void) { } else { gmlan_silent_count++; } - } else if (gmlan_silent_count == REQUIRED_SILENT_TIME) { + } else { bool retry = 0; // in send loop if ((gmlan_sending > 0) && // not first bit @@ -206,6 +210,8 @@ void TIM4_IRQHandler(void) { } else if ((read == 1) && (gmlan_sending == (gmlan_sendmax - 11))) { // recessive during ACK puts("GMLAN ERR: didn't recv ACK\n"); retry = 1; + } else { + // do not retry } if (retry) { // reset sender (retry after 7 silent) @@ -215,6 +221,7 @@ void TIM4_IRQHandler(void) { gmlan_fail_count++; if (gmlan_fail_count == MAX_FAIL_COUNT) { puts("GMLAN ERR: giving up send\n"); + gmlan_send_ok = false; } } else { set_bitbanged_gmlan(pkt_stuffed[gmlan_sending]); @@ -230,9 +237,7 @@ void TIM4_IRQHandler(void) { } } TIM4->SR = 0; - } //bit bang mode - - else if (gmlan_alt_mode == GPIO_SWITCH) { + } else if (gmlan_alt_mode == GPIO_SWITCH) { if ((TIM4->SR & TIM_SR_UIF) && (gmlan_switch_below_timeout != -1)) { if ((can_timeout_counter == 0) && gmlan_switch_timeout_enable) { //it has been more than 1 second since timeout was reset; disable timer and restore the GMLAN output @@ -255,25 +260,27 @@ void TIM4_IRQHandler(void) { } } TIM4->SR = 0; - } //gmlan switch mode + } else { + puts("invalid gmlan_alt_mode\n"); + } } -void bitbang_gmlan(CAN_FIFOMailBox_TypeDef *to_bang) { +bool bitbang_gmlan(CAN_FIFOMailBox_TypeDef *to_bang) { + gmlan_send_ok = true; gmlan_alt_mode = BITBANG; - // TODO: make failure less silent - if (gmlan_sendmax == -1) { + if (gmlan_sendmax == -1) { int len = get_bit_message(pkt_stuffed, to_bang); gmlan_fail_count = 0; gmlan_silent_count = 0; gmlan_sending = 0; gmlan_sendmax = len; - // setup for bitbang loop set_bitbanged_gmlan(1); // recessive set_gpio_mode(GPIOB, 13, MODE_OUTPUT); setup_timer4(); } + return gmlan_send_ok; } diff --git a/board/drivers/llcan.h b/board/drivers/llcan.h index 5d0b88845..0a698d4e8 100644 --- a/board/drivers/llcan.h +++ b/board/drivers/llcan.h @@ -1,38 +1,48 @@ // this is needed for 1 mbps support -#define CAN_QUANTA 8 +#define CAN_QUANTA 8U #define CAN_SEQ1 6 // roundf(quanta * 0.875f) - 1; #define CAN_SEQ2 1 // roundf(quanta * 0.125f); -#define CAN_PCLK 24000 +#define CAN_PCLK 24000U // 333 = 33.3 kbps // 5000 = 500 kbps -#define can_speed_to_prescaler(x) (CAN_PCLK / CAN_QUANTA * 10 / (x)) +#define can_speed_to_prescaler(x) (CAN_PCLK / CAN_QUANTA * 10U / (x)) -bool llcan_set_speed(CAN_TypeDef *CAN, uint32_t speed, bool loopback, bool silent) { +#define GET_BUS(msg) (((msg)->RDTR >> 4) & 0xFF) +#define GET_LEN(msg) ((msg)->RDTR & 0xF) +#define GET_ADDR(msg) ((((msg)->RIR & 4) != 0) ? ((msg)->RIR >> 3) : ((msg)->RIR >> 21)) +#define GET_BYTE(msg, b) (((int)(b) > 3) ? (((msg)->RDHR >> (8U * ((unsigned int)(b) % 4U))) & 0XFFU) : (((msg)->RDLR >> (8U * (unsigned int)(b))) & 0xFFU)) +#define GET_BYTES_04(msg) ((msg)->RDLR) +#define GET_BYTES_48(msg) ((msg)->RDHR) + +void puts(const char *a); + +bool llcan_set_speed(CAN_TypeDef *CAN_obj, uint32_t speed, bool loopback, bool silent) { // initialization mode - CAN->MCR = CAN_MCR_TTCM | CAN_MCR_INRQ; - while((CAN->MSR & CAN_MSR_INAK) != CAN_MSR_INAK); + CAN_obj->MCR = CAN_MCR_TTCM | CAN_MCR_INRQ; + while((CAN_obj->MSR & CAN_MSR_INAK) != CAN_MSR_INAK); // set time quanta from defines - CAN->BTR = (CAN_BTR_TS1_0 * (CAN_SEQ1-1)) | + CAN_obj->BTR = (CAN_BTR_TS1_0 * (CAN_SEQ1-1)) | (CAN_BTR_TS2_0 * (CAN_SEQ2-1)) | - (can_speed_to_prescaler(speed) - 1); + (can_speed_to_prescaler(speed) - 1U); // silent loopback mode for debugging if (loopback) { - CAN->BTR |= CAN_BTR_SILM | CAN_BTR_LBKM; + CAN_obj->BTR |= CAN_BTR_SILM | CAN_BTR_LBKM; } if (silent) { - CAN->BTR |= CAN_BTR_SILM; + CAN_obj->BTR |= CAN_BTR_SILM; } // reset - CAN->MCR = CAN_MCR_TTCM | CAN_MCR_ABOM; + // cppcheck-suppress redundantAssignment ; it's a register + CAN_obj->MCR = CAN_MCR_TTCM | CAN_MCR_ABOM; #define CAN_TIMEOUT 1000000 int tmp = 0; bool ret = false; - while(((CAN->MSR & CAN_MSR_INAK) == CAN_MSR_INAK) && (tmp < CAN_TIMEOUT)) tmp++; + while(((CAN_obj->MSR & CAN_MSR_INAK) == CAN_MSR_INAK) && (tmp < CAN_TIMEOUT)) tmp++; if (tmp < CAN_TIMEOUT) { ret = true; } @@ -40,42 +50,45 @@ bool llcan_set_speed(CAN_TypeDef *CAN, uint32_t speed, bool loopback, bool silen return ret; } -void llcan_init(CAN_TypeDef *CAN) { +void llcan_init(CAN_TypeDef *CAN_obj) { // accept all filter - CAN->FMR |= CAN_FMR_FINIT; + CAN_obj->FMR |= CAN_FMR_FINIT; // no mask - CAN->sFilterRegister[0].FR1 = 0; - CAN->sFilterRegister[0].FR2 = 0; - CAN->sFilterRegister[14].FR1 = 0; - CAN->sFilterRegister[14].FR2 = 0; - CAN->FA1R |= 1 | (1U << 14); + CAN_obj->sFilterRegister[0].FR1 = 0; + CAN_obj->sFilterRegister[0].FR2 = 0; + CAN_obj->sFilterRegister[14].FR1 = 0; + CAN_obj->sFilterRegister[14].FR2 = 0; + CAN_obj->FA1R |= 1U | (1U << 14); - CAN->FMR &= ~(CAN_FMR_FINIT); + CAN_obj->FMR &= ~(CAN_FMR_FINIT); // enable certain CAN interrupts - CAN->IER |= CAN_IER_TMEIE | CAN_IER_FMPIE0 | CAN_IER_WKUIE; + CAN_obj->IER |= CAN_IER_TMEIE | CAN_IER_FMPIE0 | CAN_IER_WKUIE; - if (CAN == CAN1) { + if (CAN_obj == CAN1) { NVIC_EnableIRQ(CAN1_TX_IRQn); NVIC_EnableIRQ(CAN1_RX0_IRQn); NVIC_EnableIRQ(CAN1_SCE_IRQn); - } else if (CAN == CAN2) { + } else if (CAN_obj == CAN2) { NVIC_EnableIRQ(CAN2_TX_IRQn); NVIC_EnableIRQ(CAN2_RX0_IRQn); NVIC_EnableIRQ(CAN2_SCE_IRQn); #ifdef CAN3 - } else if (CAN == CAN3) { + } else if (CAN_obj == CAN3) { NVIC_EnableIRQ(CAN3_TX_IRQn); NVIC_EnableIRQ(CAN3_RX0_IRQn); NVIC_EnableIRQ(CAN3_SCE_IRQn); #endif + } else { + puts("Invalid CAN: initialization failed\n"); } } -void llcan_clear_send(CAN_TypeDef *CAN) { - CAN->TSR |= CAN_TSR_ABRQ0; - CAN->MSR &= ~(CAN_MSR_ERRI); - CAN->MSR = CAN->MSR; +void llcan_clear_send(CAN_TypeDef *CAN_obj) { + CAN_obj->TSR |= CAN_TSR_ABRQ0; + CAN_obj->MSR &= ~(CAN_MSR_ERRI); + // cppcheck-suppress selfAssignment ; needed to clear the register + CAN_obj->MSR = CAN_obj->MSR; } diff --git a/board/drivers/llgpio.h b/board/drivers/llgpio.h index 172776eb3..f84ee7f8a 100644 --- a/board/drivers/llgpio.h +++ b/board/drivers/llgpio.h @@ -7,38 +7,38 @@ #define PULL_UP 1 #define PULL_DOWN 2 -void set_gpio_mode(GPIO_TypeDef *GPIO, int pin, int mode) { +void set_gpio_mode(GPIO_TypeDef *GPIO, unsigned int pin, unsigned int mode) { uint32_t tmp = GPIO->MODER; - tmp &= ~(3 << (pin*2)); - tmp |= (mode << (pin*2)); + tmp &= ~(3U << (pin * 2U)); + tmp |= (mode << (pin * 2U)); GPIO->MODER = tmp; } -void set_gpio_output(GPIO_TypeDef *GPIO, int pin, bool enabled) { +void set_gpio_output(GPIO_TypeDef *GPIO, unsigned int pin, bool enabled) { if (enabled) { - GPIO->ODR |= (1 << pin); + GPIO->ODR |= (1U << pin); } else { - GPIO->ODR &= ~(1 << pin); + GPIO->ODR &= ~(1U << pin); } set_gpio_mode(GPIO, pin, MODE_OUTPUT); } -void set_gpio_alternate(GPIO_TypeDef *GPIO, int pin, int mode) { - uint32_t tmp = GPIO->AFR[pin>>3]; - tmp &= ~(0xF << ((pin&7)*4)); - tmp |= mode << ((pin&7)*4); - GPIO->AFR[pin>>3] = tmp; +void set_gpio_alternate(GPIO_TypeDef *GPIO, unsigned int pin, unsigned int mode) { + uint32_t tmp = GPIO->AFR[pin >> 3U]; + tmp &= ~(0xFU << ((pin & 7U) * 4U)); + tmp |= mode << ((pin & 7U) * 4U); + GPIO->AFR[pin >> 3] = tmp; set_gpio_mode(GPIO, pin, MODE_ALTERNATE); } -void set_gpio_pullup(GPIO_TypeDef *GPIO, int pin, int mode) { +void set_gpio_pullup(GPIO_TypeDef *GPIO, unsigned int pin, unsigned int mode) { uint32_t tmp = GPIO->PUPDR; - tmp &= ~(3 << (pin*2)); - tmp |= (mode << (pin*2)); + tmp &= ~(3U << (pin * 2U)); + tmp |= (mode << (pin * 2U)); GPIO->PUPDR = tmp; } -int get_gpio_input(GPIO_TypeDef *GPIO, int pin) { +int get_gpio_input(GPIO_TypeDef *GPIO, unsigned int pin) { return (GPIO->IDR & (1U << pin)) == (1U << pin); } diff --git a/board/drivers/spi.h b/board/drivers/spi.h index b61cd719a..26690984d 100644 --- a/board/drivers/spi.h +++ b/board/drivers/spi.h @@ -28,8 +28,8 @@ void spi_init(void) { // setup interrupt on falling edge of SPI enable (on PA4) SYSCFG->EXTICR[2] = SYSCFG_EXTICR2_EXTI4_PA; - EXTI->IMR |= (1 << 4); - EXTI->FTSR |= (1 << 4); + EXTI->IMR |= (1U << 4); + EXTI->FTSR |= (1U << 4); NVIC_EnableIRQ(EXTI4_IRQn); } @@ -85,7 +85,7 @@ uint8_t spi_tx_buf[0x44]; // SPI RX void DMA2_Stream2_IRQHandler(void) { int *resp_len = (int*)spi_tx_buf; - memset(spi_tx_buf, 0xaa, 0x44); + (void)memset(spi_tx_buf, 0xaa, 0x44); *resp_len = spi_cb_rx(spi_buf, 0x14, spi_tx_buf+4); #ifdef DEBUG_SPI puts("SPI write: "); @@ -113,12 +113,12 @@ void DMA2_Stream3_IRQHandler(void) { } void EXTI4_IRQHandler(void) { - volatile int pr = EXTI->PR & (1 << 4); + volatile unsigned int pr = EXTI->PR & (1U << 4); #ifdef DEBUG_SPI puts("exti4\n"); #endif // SPI CS falling - if ((pr & (1 << 4)) != 0) { + if ((pr & (1U << 4)) != 0U) { spi_total_count = 0; spi_rx_dma(spi_buf, 0x14); } diff --git a/board/drivers/uart.h b/board/drivers/uart.h index f86c5f159..5c5452483 100644 --- a/board/drivers/uart.h +++ b/board/drivers/uart.h @@ -1,6 +1,6 @@ // IRQs: USART1, USART2, USART3, UART5 -#define FIFO_SIZE 0x400 +#define FIFO_SIZE 0x400U typedef struct uart_ring { volatile uint16_t w_ptr_tx; volatile uint16_t r_ptr_tx; @@ -81,7 +81,7 @@ void uart_ring_process(uart_ring *q) { if (q->w_ptr_tx != q->r_ptr_tx) { if ((sr & USART_SR_TXE) != 0) { q->uart->DR = q->elems_tx[q->r_ptr_tx]; - q->r_ptr_tx = (q->r_ptr_tx + 1) % FIFO_SIZE; + q->r_ptr_tx = (q->r_ptr_tx + 1U) % FIFO_SIZE; } // there could be more to send q->uart->CR1 |= USART_CR1_TXEIE; @@ -93,7 +93,7 @@ void uart_ring_process(uart_ring *q) { if ((sr & USART_SR_RXNE) || (sr & USART_SR_ORE)) { uint8_t c = q->uart->DR; // TODO: can drop packets if (q != &esp_ring) { - uint16_t next_w_ptr = (q->w_ptr_rx + 1) % FIFO_SIZE; + uint16_t next_w_ptr = (q->w_ptr_rx + 1U) % FIFO_SIZE; if (next_w_ptr != q->r_ptr_rx) { q->elems_rx[q->w_ptr_rx] = c; q->w_ptr_rx = next_w_ptr; @@ -124,7 +124,7 @@ bool getc(uart_ring *q, char *elem) { enter_critical_section(); if (q->w_ptr_rx != q->r_ptr_rx) { if (elem != NULL) *elem = q->elems_rx[q->r_ptr_rx]; - q->r_ptr_rx = (q->r_ptr_rx + 1) % FIFO_SIZE; + q->r_ptr_rx = (q->r_ptr_rx + 1U) % FIFO_SIZE; ret = true; } exit_critical_section(); @@ -137,7 +137,7 @@ bool injectc(uart_ring *q, char elem) { uint16_t next_w_ptr; enter_critical_section(); - next_w_ptr = (q->w_ptr_rx + 1) % FIFO_SIZE; + next_w_ptr = (q->w_ptr_rx + 1U) % FIFO_SIZE; if (next_w_ptr != q->r_ptr_rx) { q->elems_rx[q->w_ptr_rx] = elem; q->w_ptr_rx = next_w_ptr; @@ -153,7 +153,7 @@ bool putc(uart_ring *q, char elem) { uint16_t next_w_ptr; enter_critical_section(); - next_w_ptr = (q->w_ptr_tx + 1) % FIFO_SIZE; + next_w_ptr = (q->w_ptr_tx + 1U) % FIFO_SIZE; if (next_w_ptr != q->r_ptr_tx) { q->elems_tx[q->w_ptr_tx] = elem; q->w_ptr_tx = next_w_ptr; @@ -195,17 +195,17 @@ void clear_uart_buff(uart_ring *q) { // ***************************** start UART code ***************************** -#define __DIV(_PCLK_, _BAUD_) (((_PCLK_) * 25) / (4 * (_BAUD_))) -#define __DIVMANT(_PCLK_, _BAUD_) (__DIV((_PCLK_), (_BAUD_)) / 100) -#define __DIVFRAQ(_PCLK_, _BAUD_) ((((__DIV((_PCLK_), (_BAUD_)) - (__DIVMANT((_PCLK_), (_BAUD_)) * 100)) * 16) + 50) / 100) -#define __USART_BRR(_PCLK_, _BAUD_) ((__DIVMANT((_PCLK_), (_BAUD_)) << 4) | (__DIVFRAQ((_PCLK_), (_BAUD_)) & 0x0F)) +#define __DIV(_PCLK_, _BAUD_) (((_PCLK_) * 25U) / (4U * (_BAUD_))) +#define __DIVMANT(_PCLK_, _BAUD_) (__DIV((_PCLK_), (_BAUD_)) / 100U) +#define __DIVFRAQ(_PCLK_, _BAUD_) ((((__DIV((_PCLK_), (_BAUD_)) - (__DIVMANT((_PCLK_), (_BAUD_)) * 100U)) * 16U) + 50U) / 100U) +#define __USART_BRR(_PCLK_, _BAUD_) ((__DIVMANT((_PCLK_), (_BAUD_)) << 4) | (__DIVFRAQ((_PCLK_), (_BAUD_)) & 0x0FU)) -void uart_set_baud(USART_TypeDef *u, int baud) { +void uart_set_baud(USART_TypeDef *u, unsigned int baud) { if (u == USART1) { // USART1 is on APB2 - u->BRR = __USART_BRR(48000000, baud); + u->BRR = __USART_BRR(48000000U, baud); } else { - u->BRR = __USART_BRR(24000000, baud); + u->BRR = __USART_BRR(24000000U, baud); } } @@ -226,7 +226,7 @@ void uart_dma_drain(void) { unsigned int i; for (i = 0; i < (USART1_DMA_LEN - DMA2_Stream5->NDTR); i++) { char c = usart1_dma[i]; - uint16_t next_w_ptr = (q->w_ptr_rx + 1) % FIFO_SIZE; + uint16_t next_w_ptr = (q->w_ptr_rx + 1U) % FIFO_SIZE; if (next_w_ptr != q->r_ptr_rx) { q->elems_rx[q->w_ptr_rx] = c; q->w_ptr_rx = next_w_ptr; @@ -289,6 +289,8 @@ void uart_init(USART_TypeDef *u, int baud) { NVIC_EnableIRQ(USART3_IRQn); } else if (u == UART5) { NVIC_EnableIRQ(UART5_IRQn); + } else { + // USART type undefined, skip } } @@ -302,49 +304,48 @@ void putch(const char a) { //putc(&debug_ring, a); } else { - injectc(&debug_ring, a); + // misra-c2012-17.7: serial debug function, ok to ignore output + (void)injectc(&debug_ring, a); } } void puts(const char *a) { - for (;*a;a++) { - if (*a == '\n') putch('\r'); - putch(*a); + for (const char *in = a; *in; in++) { + if (*in == '\n') putch('\r'); + putch(*in); } } void putui(uint32_t i) { + uint32_t i_copy = i; char str[11]; uint8_t idx = 10; str[idx] = '\0'; idx--; do { - str[idx] = (i % 10) + 0x30; + str[idx] = (i_copy % 10U) + 0x30U; idx--; - i /= 10; - } while (i != 0); - puts(str + idx + 1); + i_copy /= 10; + } while (i_copy != 0U); + puts(str + idx + 1U); } void puth(unsigned int i) { - int pos; char c[] = "0123456789abcdef"; - for (pos = 28; pos != -4; pos -= 4) { - putch(c[(i >> pos) & 0xF]); + for (int pos = 28; pos != -4; pos -= 4) { + putch(c[(i >> (unsigned int)(pos)) & 0xFU]); } } void puth2(unsigned int i) { - int pos; char c[] = "0123456789abcdef"; - for (pos = 4; pos != -4; pos -= 4) { - putch(c[(i >> pos) & 0xF]); + for (int pos = 4; pos != -4; pos -= 4) { + putch(c[(i >> (unsigned int)(pos)) & 0xFU]); } } void hexdump(const void *a, int l) { - int i; - for (i=0;i> 8) & 0xFF) + ((num) & 0xFFU), (((num) >> 8) & 0xFFU) // take in string length and return the first 2 bytes of a string descriptor #define STRING_DESCRIPTOR_HEADER(size)\ @@ -158,7 +158,7 @@ uint8_t device_qualifier[] = { uint8_t configuration_desc[] = { DSCR_CONFIG_LEN, USB_DESC_TYPE_CONFIGURATION, // Length, Type, - TOUSBORDER(0x0045), // Total Len (uint16) + TOUSBORDER(0x0045U), // Total Len (uint16) 0x01, 0x01, STRING_OFFSET_ICONFIGURATION, // Num Interface, Config Value, Configuration 0xc0, 0x32, // Attributes, Max Power // interface 0 ALT 0 @@ -169,17 +169,17 @@ uint8_t configuration_desc[] = { // endpoint 1, read CAN DSCR_ENDPOINT_LEN, USB_DESC_TYPE_ENDPOINT, // Length, Type ENDPOINT_RCV | 1, ENDPOINT_TYPE_BULK, // Endpoint Num/Direction, Type - TOUSBORDER(0x0040), // Max Packet (0x0040) + TOUSBORDER(0x0040U), // Max Packet (0x0040) 0x00, // Polling Interval (NA) // endpoint 2, send serial DSCR_ENDPOINT_LEN, USB_DESC_TYPE_ENDPOINT, // Length, Type ENDPOINT_SND | 2, ENDPOINT_TYPE_BULK, // Endpoint Num/Direction, Type - TOUSBORDER(0x0040), // Max Packet (0x0040) + TOUSBORDER(0x0040U), // Max Packet (0x0040) 0x00, // Polling Interval // endpoint 3, send CAN DSCR_ENDPOINT_LEN, USB_DESC_TYPE_ENDPOINT, // Length, Type ENDPOINT_SND | 3, ENDPOINT_TYPE_BULK, // Endpoint Num/Direction, Type - TOUSBORDER(0x0040), // Max Packet (0x0040) + TOUSBORDER(0x0040U), // Max Packet (0x0040) 0x00, // Polling Interval // interface 0 ALT 1 DSCR_INTERFACE_LEN, USB_DESC_TYPE_INTERFACE, // Length, Type @@ -189,17 +189,17 @@ uint8_t configuration_desc[] = { // endpoint 1, read CAN DSCR_ENDPOINT_LEN, USB_DESC_TYPE_ENDPOINT, // Length, Type ENDPOINT_RCV | 1, ENDPOINT_TYPE_INT, // Endpoint Num/Direction, Type - TOUSBORDER(0x0040), // Max Packet (0x0040) + TOUSBORDER(0x0040U), // Max Packet (0x0040) 0x05, // Polling Interval (5 frames) // endpoint 2, send serial DSCR_ENDPOINT_LEN, USB_DESC_TYPE_ENDPOINT, // Length, Type ENDPOINT_SND | 2, ENDPOINT_TYPE_BULK, // Endpoint Num/Direction, Type - TOUSBORDER(0x0040), // Max Packet (0x0040) + TOUSBORDER(0x0040U), // Max Packet (0x0040) 0x00, // Polling Interval // endpoint 3, send CAN DSCR_ENDPOINT_LEN, USB_DESC_TYPE_ENDPOINT, // Length, Type ENDPOINT_SND | 3, ENDPOINT_TYPE_BULK, // Endpoint Num/Direction, Type - TOUSBORDER(0x0040), // Max Packet (0x0040) + TOUSBORDER(0x0040U), // Max Packet (0x0040) 0x00, // Polling Interval }; @@ -394,36 +394,36 @@ int current_int0_alt_setting = 0; // packet read and write void *USB_ReadPacket(void *dest, uint16_t len) { - uint32_t i=0; - uint32_t count32b = (len + 3) / 4; + uint32_t *dest_copy = (uint32_t *)dest; + uint32_t count32b = (len + 3U) / 4U; - for ( i = 0; i < count32b; i++) { - // packed? - *(__attribute__((__packed__)) uint32_t *)dest = USBx_DFIFO(0); - dest += 4; + for (uint32_t i = 0; i < count32b; i++) { + *dest_copy = USBx_DFIFO(0); + dest_copy++; } - return ((void *)dest); + return ((void *)dest_copy); } -void USB_WritePacket(const uint8_t *src, uint16_t len, uint32_t ep) { +void USB_WritePacket(const void *src, uint16_t len, uint32_t ep) { #ifdef DEBUG_USB puts("writing "); hexdump(src, len); #endif - uint8_t numpacket = (len+(MAX_RESP_LEN-1))/MAX_RESP_LEN; - uint32_t count32b = 0, i = 0; - count32b = (len + 3) / 4; + uint8_t numpacket = (len + (MAX_RESP_LEN - 1U)) / MAX_RESP_LEN; + uint32_t count32b = 0; + count32b = (len + 3U) / 4U; - // bullshit + // TODO: revisit this USBx_INEP(ep)->DIEPTSIZ = ((numpacket << 19) & USB_OTG_DIEPTSIZ_PKTCNT) | (len & USB_OTG_DIEPTSIZ_XFRSIZ); USBx_INEP(ep)->DIEPCTL |= (USB_OTG_DIEPCTL_CNAK | USB_OTG_DIEPCTL_EPENA); // load the FIFO - for (i = 0; i < count32b; i++) { - USBx_DFIFO(ep) = *((__attribute__((__packed__)) uint32_t *)src); - src += 4; + const uint32_t *src_copy = (const uint32_t *)src; + for (uint32_t i = 0; i < count32b; i++) { + USBx_DFIFO(ep) = *src_copy; + src_copy++; } } @@ -471,10 +471,10 @@ void usb_reset(void) { USBx->GRXFSIZ = 0x40; // 0x100 to offset past GRXFSIZ - USBx->DIEPTXF0_HNPTXFSIZ = (0x40 << 16) | 0x40; + USBx->DIEPTXF0_HNPTXFSIZ = (0x40U << 16) | 0x40U; // EP1, massive - USBx->DIEPTXF[0] = (0x40 << 16) | 0x80; + USBx->DIEPTXF[0] = (0x40U << 16) | 0x80U; // flush TX fifo USBx->GRSTCTL = USB_OTG_GRSTCTL_TXFFLSH | USB_OTG_GRSTCTL_TXFNUM_4; @@ -487,7 +487,7 @@ void usb_reset(void) { USBx_DEVICE->DCTL |= USB_OTG_DCTL_CGINAK; // ready to receive setup packets - USBx_OUTEP(0)->DOEPTSIZ = USB_OTG_DOEPTSIZ_STUPCNT | (USB_OTG_DOEPTSIZ_PKTCNT & (1 << 19)) | (3 * 8); + USBx_OUTEP(0)->DOEPTSIZ = USB_OTG_DOEPTSIZ_STUPCNT | (USB_OTG_DOEPTSIZ_PKTCNT & (1U << 19)) | (3U << 3); } char to_hex_char(int a) { @@ -506,17 +506,17 @@ void usb_setup(void) { switch (setup.b.bRequest) { case USB_REQ_SET_CONFIGURATION: // enable other endpoints, has to be here? - USBx_INEP(1)->DIEPCTL = (0x40 & USB_OTG_DIEPCTL_MPSIZ) | (2 << 18) | (1 << 22) | + USBx_INEP(1)->DIEPCTL = (0x40U & USB_OTG_DIEPCTL_MPSIZ) | (2U << 18) | (1U << 22) | USB_OTG_DIEPCTL_SD0PID_SEVNFRM | USB_OTG_DIEPCTL_USBAEP; USBx_INEP(1)->DIEPINT = 0xFF; - USBx_OUTEP(2)->DOEPTSIZ = (1 << 19) | 0x40; - USBx_OUTEP(2)->DOEPCTL = (0x40 & USB_OTG_DOEPCTL_MPSIZ) | (2 << 18) | + USBx_OUTEP(2)->DOEPTSIZ = (1U << 19) | 0x40U; + USBx_OUTEP(2)->DOEPCTL = (0x40U & USB_OTG_DOEPCTL_MPSIZ) | (2U << 18) | USB_OTG_DOEPCTL_SD0PID_SEVNFRM | USB_OTG_DOEPCTL_USBAEP; USBx_OUTEP(2)->DOEPINT = 0xFF; - USBx_OUTEP(3)->DOEPTSIZ = (1 << 19) | 0x40; - USBx_OUTEP(3)->DOEPCTL = (0x40 & USB_OTG_DOEPCTL_MPSIZ) | (2 << 18) | + USBx_OUTEP(3)->DOEPTSIZ = (1U << 19) | 0x40U; + USBx_OUTEP(3)->DOEPCTL = (0x40U & USB_OTG_DOEPCTL_MPSIZ) | (2U << 18) | USB_OTG_DOEPCTL_SD0PID_SEVNFRM | USB_OTG_DOEPCTL_USBAEP; USBx_OUTEP(3)->DOEPINT = 0xFF; @@ -529,7 +529,7 @@ void usb_setup(void) { break; case USB_REQ_SET_ADDRESS: // set now? - USBx_DEVICE->DCFG |= ((setup.b.wValue.w & 0x7f) << 4); + USBx_DEVICE->DCFG |= ((setup.b.wValue.w & 0x7fU) << 4); #ifdef DEBUG_USB puts(" set address\n"); @@ -575,16 +575,16 @@ void usb_setup(void) { break; case STRING_OFFSET_ISERIAL: #ifdef UID_BASE - resp[0] = 0x02 + 12*4; + resp[0] = 0x02 + (12 * 4); resp[1] = 0x03; // 96 bits = 12 bytes for (int i = 0; i < 12; i++){ uint8_t cc = ((uint8_t *)UID_BASE)[i]; - resp[2 + i*4 + 0] = to_hex_char((cc>>4)&0xF); - resp[2 + i*4 + 1] = '\0'; - resp[2 + i*4 + 2] = to_hex_char((cc>>0)&0xF); - resp[2 + i*4 + 3] = '\0'; + resp[2 + (i * 4) + 0] = to_hex_char((cc >> 4) & 0xFU); + resp[2 + (i * 4) + 1] = '\0'; + resp[2 + (i * 4) + 2] = to_hex_char((cc >> 0) & 0xFU); + resp[2 + (i * 4) + 3] = '\0'; } USB_WritePacket(resp, MIN(resp[0], setup.b.wLength.w), 0); @@ -683,7 +683,7 @@ void usb_init(void) { USBx->GUSBCFG = USB_OTG_GUSBCFG_PHYSEL | USB_OTG_GUSBCFG_FDMOD; // slowest timings - USBx->GUSBCFG |= (uint32_t)((USBD_FS_TRDT_VALUE << 10) & USB_OTG_GUSBCFG_TRDT); + USBx->GUSBCFG |= ((USBD_FS_TRDT_VALUE << 10) & USB_OTG_GUSBCFG_TRDT); // power up the PHY #ifdef STM32F4 @@ -732,7 +732,6 @@ void usb_init(void) { USBx->GAHBCFG = USB_OTG_GAHBCFG_GINT; // DCTL startup value is 2 on new chip, 0 on old chip - // THIS IS FUCKING BULLSHIT USBx_DEVICE->DCTL = 0; // enable the IRQ @@ -793,21 +792,22 @@ void usb_irqhandler(void) { if ((gintsts & USB_OTG_GINTSTS_RXFLVL) != 0) { // 1. Read the Receive status pop register volatile unsigned int rxst = USBx->GRXSTSP; + int status = (rxst & USB_OTG_GRXSTSP_PKTSTS) >> 17; #ifdef DEBUG_USB puts(" RX FIFO:"); puth(rxst); puts(" status: "); - puth((rxst & USB_OTG_GRXSTSP_PKTSTS) >> 17); + puth(status); puts(" len: "); puth((rxst & USB_OTG_GRXSTSP_BCNT) >> 4); puts("\n"); #endif - if (((rxst & USB_OTG_GRXSTSP_PKTSTS) >> 17) == STS_DATA_UPDT) { + if (status == STS_DATA_UPDT) { int endpoint = (rxst & USB_OTG_GRXSTSP_EPNUM); int len = (rxst & USB_OTG_GRXSTSP_BCNT) >> 4; - USB_ReadPacket(&usbdata, len); + (void)USB_ReadPacket(&usbdata, len); #ifdef DEBUG_USB puts(" data "); puth(len); @@ -822,13 +822,15 @@ void usb_irqhandler(void) { if (endpoint == 3) { usb_cb_ep3_out(usbdata, len, 1); } - } else if (((rxst & USB_OTG_GRXSTSP_PKTSTS) >> 17) == STS_SETUP_UPDT) { - USB_ReadPacket(&setup, 8); + } else if (status == STS_SETUP_UPDT) { + (void)USB_ReadPacket(&setup, 8); #ifdef DEBUG_USB puts(" setup "); hexdump(&setup, 8); puts("\n"); #endif + } else { + // status is neither STS_DATA_UPDT or STS_SETUP_UPDT, skip } } @@ -882,7 +884,7 @@ void usb_irqhandler(void) { #ifdef DEBUG_USB puts(" OUT2 PACKET XFRC\n"); #endif - USBx_OUTEP(2)->DOEPTSIZ = (1 << 19) | 0x40; + USBx_OUTEP(2)->DOEPTSIZ = (1U << 19) | 0x40U; USBx_OUTEP(2)->DOEPCTL |= USB_OTG_DOEPCTL_EPENA | USB_OTG_DOEPCTL_CNAK; } @@ -890,24 +892,26 @@ void usb_irqhandler(void) { #ifdef DEBUG_USB puts(" OUT3 PACKET XFRC\n"); #endif - USBx_OUTEP(3)->DOEPTSIZ = (1 << 19) | 0x40; + USBx_OUTEP(3)->DOEPTSIZ = (1U << 19) | 0x40U; USBx_OUTEP(3)->DOEPCTL |= USB_OTG_DOEPCTL_EPENA | USB_OTG_DOEPCTL_CNAK; } else if ((USBx_OUTEP(3)->DOEPINT & 0x2000) != 0) { #ifdef DEBUG_USB puts(" OUT3 PACKET WTF\n"); #endif // if NAK was set trigger this, unknown interrupt - USBx_OUTEP(3)->DOEPTSIZ = (1 << 19) | 0x40; + USBx_OUTEP(3)->DOEPTSIZ = (1U << 19) | 0x40U; USBx_OUTEP(3)->DOEPCTL |= USB_OTG_DOEPCTL_CNAK; } else if ((USBx_OUTEP(3)->DOEPINT) != 0) { puts("OUTEP3 error "); puth(USBx_OUTEP(3)->DOEPINT); puts("\n"); + } else { + // USBx_OUTEP(3)->DOEPINT is 0, ok to skip } if ((USBx_OUTEP(0)->DOEPINT & USB_OTG_DIEPINT_XFRC) != 0) { // ready for next packet - USBx_OUTEP(0)->DOEPTSIZ = USB_OTG_DOEPTSIZ_STUPCNT | (USB_OTG_DOEPTSIZ_PKTCNT & (1 << 19)) | (1 * 8); + USBx_OUTEP(0)->DOEPTSIZ = USB_OTG_DOEPTSIZ_STUPCNT | (USB_OTG_DOEPTSIZ_PKTCNT & (1U << 19)) | (1U << 3); } // respond to setup packets @@ -978,12 +982,12 @@ void usb_irqhandler(void) { puts(" IN PACKET QUEUE\n"); #endif - if ((ep0_txlen != 0) && ((USBx_INEP(0)->DTXFSTS & USB_OTG_DTXFSTS_INEPTFSAV) >= 0x40)) { + if ((ep0_txlen != 0U) && ((USBx_INEP(0)->DTXFSTS & USB_OTG_DTXFSTS_INEPTFSAV) >= 0x40U)) { uint16_t len = MIN(ep0_txlen, 0x40); USB_WritePacket(ep0_txdata, len, 0); ep0_txdata += len; ep0_txlen -= len; - if (ep0_txlen == 0) { + if (ep0_txlen == 0U) { ep0_txdata = NULL; USBx_DEVICE->DIEPEMPMSK &= ~1; USBx_OUTEP(0)->DOEPCTL |= USB_OTG_DOEPCTL_CNAK; diff --git a/board/gpio.h b/board/gpio.h index 26a82d627..e1936527e 100644 --- a/board/gpio.h +++ b/board/gpio.h @@ -99,9 +99,9 @@ void periph_init(void) { // ********************* setters ********************* -void set_can_enable(CAN_TypeDef *CAN, bool enabled) { +void set_can_enable(CAN_TypeDef *CAN_obj, bool enabled) { // enable CAN busses - if (CAN == CAN1) { + if (CAN_obj == CAN1) { #ifdef PANDA // CAN1_EN set_gpio_output(GPIOC, 1, !enabled); @@ -114,7 +114,7 @@ void set_can_enable(CAN_TypeDef *CAN, bool enabled) { set_gpio_output(GPIOB, 3, enabled); #endif #endif - } else if (CAN == CAN2) { + } else if (CAN_obj == CAN2) { #ifdef PANDA // CAN2_EN set_gpio_output(GPIOC, 13, !enabled); @@ -123,10 +123,12 @@ void set_can_enable(CAN_TypeDef *CAN, bool enabled) { set_gpio_output(GPIOB, 4, enabled); #endif #ifdef CAN3 - } else if (CAN == CAN3) { + } else if (CAN_obj == CAN3) { // CAN3_EN set_gpio_output(GPIOA, 0, !enabled); #endif + } else { + puts("Invalid CAN: enabling failed\n"); } } @@ -171,6 +173,8 @@ void set_can_mode(int can, bool use_gmlan) { set_gpio_alternate(GPIOB, 3, GPIO_AF11_CAN3); set_gpio_alternate(GPIOB, 4, GPIO_AF11_CAN3); #endif + } else { + puts("Invalid CAN: mode setting failed\n"); } } else { if (can == 1) { @@ -190,6 +194,8 @@ void set_can_mode(int can, bool use_gmlan) { set_gpio_alternate(GPIOA, 8, GPIO_AF11_CAN3); set_gpio_alternate(GPIOA, 15, GPIO_AF11_CAN3); #endif + } else { + puts("Invalid CAN: mode setting failed\n"); } } } @@ -404,9 +410,13 @@ void early(void) { // if wrong chip, reboot volatile unsigned int id = DBGMCU->IDCODE; #ifdef STM32F4 - if ((id&0xFFF) != 0x463) enter_bootloader_mode = ENTER_BOOTLOADER_MAGIC; + if ((id & 0xFFFU) != 0x463U) { + enter_bootloader_mode = ENTER_BOOTLOADER_MAGIC; + } #else - if ((id&0xFFF) != 0x411) enter_bootloader_mode = ENTER_BOOTLOADER_MAGIC; + if ((id & 0xFFFU) != 0x411U) { + enter_bootloader_mode = ENTER_BOOTLOADER_MAGIC; + } #endif // setup interrupt table diff --git a/board/inc/stm32f205xx.h b/board/inc/stm32f205xx.h index ba825d197..622faead6 100644 --- a/board/inc/stm32f205xx.h +++ b/board/inc/stm32f205xx.h @@ -4,8 +4,8 @@ * @author MCD Application Team * @version V2.1.2 * @date 29-June-2016 - * @brief CMSIS STM32F205xx Device Peripheral Access Layer Header File. - * This file contains : + * @brief CMSIS STM32F205xx Device Peripheral Access Layer Header File. + * This file contains : * - Data structures and the address mapping for all peripherals * - Peripherals registers declarations and bits definition * - Macros to access peripheral’s registers hardware @@ -47,21 +47,21 @@ /** @addtogroup stm32f205xx * @{ */ - + #ifndef __STM32F205xx_H #define __STM32F205xx_H #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ - + /** @addtogroup Configuration_section_for_CMSIS * @{ */ /** - * @brief Configuration of the Cortex-M3 Processor and Core Peripherals + * @brief Configuration of the Cortex-M3 Processor and Core Peripherals */ #define __CM3_REV 0x0200U /*!< Core revision r0p1 */ #define __MPU_PRESENT 1U /*!< STM32F2XX provides an MPU */ @@ -71,14 +71,14 @@ /** * @} */ - + /** @addtogroup Peripheral_interrupt_number_definition * @{ */ /** - * @brief STM32F2XX Interrupt Number Definition, according to the selected device - * in @ref Library_configuration_section + * @brief STM32F2XX Interrupt Number Definition, according to the selected device + * in @ref Library_configuration_section */ typedef enum { @@ -126,7 +126,7 @@ typedef enum I2C1_EV_IRQn = 31, /*!< I2C1 Event Interrupt */ I2C1_ER_IRQn = 32, /*!< I2C1 Error Interrupt */ I2C2_EV_IRQn = 33, /*!< I2C2 Event Interrupt */ - I2C2_ER_IRQn = 34, /*!< I2C2 Error Interrupt */ + I2C2_ER_IRQn = 34, /*!< I2C2 Error Interrupt */ SPI1_IRQn = 35, /*!< SPI1 global Interrupt */ SPI2_IRQn = 36, /*!< SPI2 global Interrupt */ USART1_IRQn = 37, /*!< USART1 global Interrupt */ @@ -134,7 +134,7 @@ typedef enum USART3_IRQn = 39, /*!< USART3 global Interrupt */ EXTI15_10_IRQn = 40, /*!< External Line[15:10] Interrupts */ RTC_Alarm_IRQn = 41, /*!< RTC Alarm (A and B) through EXTI Line Interrupt */ - OTG_FS_WKUP_IRQn = 42, /*!< USB OTG FS Wakeup through EXTI line interrupt */ + OTG_FS_WKUP_IRQn = 42, /*!< USB OTG FS Wakeup through EXTI line interrupt */ TIM8_BRK_TIM12_IRQn = 43, /*!< TIM8 Break Interrupt and TIM12 global interrupt */ TIM8_UP_TIM13_IRQn = 44, /*!< TIM8 Update Interrupt and TIM13 global interrupt */ TIM8_TRG_COM_TIM14_IRQn = 45, /*!< TIM8 Trigger and Commutation Interrupt and TIM14 global interrupt */ @@ -181,16 +181,16 @@ typedef enum /** @addtogroup Peripheral_registers_structures * @{ - */ + */ -/** - * @brief Analog to Digital Converter +/** + * @brief Analog to Digital Converter */ typedef struct { __IO uint32_t SR; /*!< ADC status register, Address offset: 0x00 */ - __IO uint32_t CR1; /*!< ADC control register 1, Address offset: 0x04 */ + __IO uint32_t CR1; /*!< ADC control register 1, Address offset: 0x04 */ __IO uint32_t CR2; /*!< ADC control register 2, Address offset: 0x08 */ __IO uint32_t SMPR1; /*!< ADC sample time register 1, Address offset: 0x0C */ __IO uint32_t SMPR2; /*!< ADC sample time register 2, Address offset: 0x10 */ @@ -220,8 +220,8 @@ typedef struct } ADC_Common_TypeDef; -/** - * @brief Controller Area Network TxMailBox +/** + * @brief Controller Area Network TxMailBox */ typedef struct @@ -232,10 +232,10 @@ typedef struct __IO uint32_t TDHR; /*!< CAN mailbox data high register */ } CAN_TxMailBox_TypeDef; -/** - * @brief Controller Area Network FIFOMailBox +/** + * @brief Controller Area Network FIFOMailBox */ - + typedef struct { __IO uint32_t RIR; /*!< CAN receive FIFO mailbox identifier register */ @@ -244,20 +244,20 @@ typedef struct __IO uint32_t RDHR; /*!< CAN receive FIFO mailbox data high register */ } CAN_FIFOMailBox_TypeDef; -/** - * @brief Controller Area Network FilterRegister +/** + * @brief Controller Area Network FilterRegister */ - + typedef struct { __IO uint32_t FR1; /*!< CAN Filter bank register 1 */ __IO uint32_t FR2; /*!< CAN Filter bank register 1 */ } CAN_FilterRegister_TypeDef; -/** - * @brief Controller Area Network +/** + * @brief Controller Area Network */ - + typedef struct { __IO uint32_t MCR; /*!< CAN master control register, Address offset: 0x00 */ @@ -280,12 +280,12 @@ typedef struct __IO uint32_t FFA1R; /*!< CAN filter FIFO assignment register, Address offset: 0x214 */ uint32_t RESERVED4; /*!< Reserved, 0x218 */ __IO uint32_t FA1R; /*!< CAN filter activation register, Address offset: 0x21C */ - uint32_t RESERVED5[8]; /*!< Reserved, 0x220-0x23F */ + uint32_t RESERVED5[8]; /*!< Reserved, 0x220-0x23F */ CAN_FilterRegister_TypeDef sFilterRegister[28]; /*!< CAN Filter Register, Address offset: 0x240-0x31C */ } CAN_TypeDef; -/** - * @brief CRC calculation unit +/** + * @brief CRC calculation unit */ typedef struct @@ -297,7 +297,7 @@ typedef struct __IO uint32_t CR; /*!< CRC Control register, Address offset: 0x08 */ } CRC_TypeDef; -/** +/** * @brief Digital to Analog Converter */ @@ -319,7 +319,7 @@ typedef struct __IO uint32_t SR; /*!< DAC status register, Address offset: 0x34 */ } DAC_TypeDef; -/** +/** * @brief Debug MCU */ @@ -332,7 +332,7 @@ typedef struct }DBGMCU_TypeDef; -/** +/** * @brief DMA Controller */ @@ -355,7 +355,7 @@ typedef struct } DMA_TypeDef; -/** +/** * @brief External Interrupt/Event Controller */ @@ -369,7 +369,7 @@ typedef struct __IO uint32_t PR; /*!< EXTI Pending register, Address offset: 0x14 */ } EXTI_TypeDef; -/** +/** * @brief FLASH Registers */ @@ -384,28 +384,28 @@ typedef struct } FLASH_TypeDef; -/** +/** * @brief Flexible Static Memory Controller */ typedef struct { - __IO uint32_t BTCR[8]; /*!< NOR/PSRAM chip-select control register(BCR) and chip-select timing register(BTR), Address offset: 0x00-1C */ -} FSMC_Bank1_TypeDef; + __IO uint32_t BTCR[8]; /*!< NOR/PSRAM chip-select control register(BCR) and chip-select timing register(BTR), Address offset: 0x00-1C */ +} FSMC_Bank1_TypeDef; -/** +/** * @brief Flexible Static Memory Controller Bank1E */ - + typedef struct { __IO uint32_t BWTR[7]; /*!< NOR/PSRAM write timing registers, Address offset: 0x104-0x11C */ } FSMC_Bank1E_TypeDef; -/** +/** * @brief Flexible Static Memory Controller Bank2 */ - + typedef struct { __IO uint32_t PCR2; /*!< NAND Flash control register 2, Address offset: 0x60 */ @@ -424,10 +424,10 @@ typedef struct __IO uint32_t ECCR3; /*!< NAND Flash ECC result registers 3, Address offset: 0x94 */ } FSMC_Bank2_3_TypeDef; -/** +/** * @brief Flexible Static Memory Controller Bank4 */ - + typedef struct { __IO uint32_t PCR4; /*!< PC Card control register 4, Address offset: 0xA0 */ @@ -435,10 +435,10 @@ typedef struct __IO uint32_t PMEM4; /*!< PC Card Common memory space timing register 4, Address offset: 0xA8 */ __IO uint32_t PATT4; /*!< PC Card Attribute memory space timing register 4, Address offset: 0xAC */ __IO uint32_t PIO4; /*!< PC Card I/O space timing register 4, Address offset: 0xB0 */ -} FSMC_Bank4_TypeDef; +} FSMC_Bank4_TypeDef; -/** +/** * @brief General Purpose I/O */ @@ -455,20 +455,20 @@ typedef struct __IO uint32_t AFR[2]; /*!< GPIO alternate function registers, Address offset: 0x20-0x24 */ } GPIO_TypeDef; -/** +/** * @brief System configuration controller */ - + typedef struct { __IO uint32_t MEMRMP; /*!< SYSCFG memory remap register, Address offset: 0x00 */ __IO uint32_t PMC; /*!< SYSCFG peripheral mode configuration register, Address offset: 0x04 */ __IO uint32_t EXTICR[4]; /*!< SYSCFG external interrupt configuration registers, Address offset: 0x08-0x14 */ - uint32_t RESERVED[2]; /*!< Reserved, 0x18-0x1C */ + uint32_t RESERVED[2]; /*!< Reserved, 0x18-0x1C */ __IO uint32_t CMPCR; /*!< SYSCFG Compensation cell control register, Address offset: 0x20 */ } SYSCFG_TypeDef; -/** +/** * @brief Inter-integrated Circuit Interface */ @@ -485,7 +485,7 @@ typedef struct __IO uint32_t TRISE; /*!< I2C TRISE register, Address offset: 0x20 */ } I2C_TypeDef; -/** +/** * @brief Independent WATCHDOG */ @@ -497,7 +497,7 @@ typedef struct __IO uint32_t SR; /*!< IWDG Status register, Address offset: 0x0C */ } IWDG_TypeDef; -/** +/** * @brief Power Control */ @@ -507,7 +507,7 @@ typedef struct __IO uint32_t CSR; /*!< PWR power control/status register, Address offset: 0x04 */ } PWR_TypeDef; -/** +/** * @brief Reset and Clock Control */ @@ -546,7 +546,7 @@ typedef struct } RCC_TypeDef; -/** +/** * @brief Real-Time Clock */ @@ -595,7 +595,7 @@ typedef struct } RTC_TypeDef; -/** +/** * @brief SD host Interface */ @@ -623,7 +623,7 @@ typedef struct __IO uint32_t FIFO; /*!< SDIO data FIFO register, Address offset: 0x80 */ } SDIO_TypeDef; -/** +/** * @brief Serial Peripheral Interface */ @@ -640,7 +640,7 @@ typedef struct __IO uint32_t I2SPR; /*!< SPI_I2S prescaler register, Address offset: 0x20 */ } SPI_TypeDef; -/** +/** * @brief TIM */ @@ -669,10 +669,10 @@ typedef struct __IO uint32_t OR; /*!< TIM option register, Address offset: 0x50 */ } TIM_TypeDef; -/** +/** * @brief Universal Synchronous Asynchronous Receiver Transmitter */ - + typedef struct { __IO uint32_t SR; /*!< USART Status register, Address offset: 0x00 */ @@ -684,7 +684,7 @@ typedef struct __IO uint32_t GTPR; /*!< USART Guard time and prescaler register, Address offset: 0x18 */ } USART_TypeDef; -/** +/** * @brief Window WATCHDOG */ @@ -696,11 +696,11 @@ typedef struct } WWDG_TypeDef; -/** +/** * @brief RNG */ - -typedef struct + +typedef struct { __IO uint32_t CR; /*!< RNG control register, Address offset: 0x00 */ __IO uint32_t SR; /*!< RNG status register, Address offset: 0x04 */ @@ -708,8 +708,8 @@ typedef struct } RNG_TypeDef; - -/** + +/** * @brief __USB_OTG_Core_register */ typedef struct @@ -737,10 +737,10 @@ USB_OTG_GlobalTypeDef; -/** +/** * @brief __device_Registers */ -typedef struct +typedef struct { __IO uint32_t DCFG; /*!< dev Configuration Register Address offset : 0x800 */ __IO uint32_t DCTL; /*!< dev Control Register Address offset : 0x804 */ @@ -757,19 +757,19 @@ typedef struct __IO uint32_t DTHRCTL; /*!< dev thr Address offset : 0x830 */ __IO uint32_t DIEPEMPMSK; /*!< dev empty msk Address offset : 0x834 */ __IO uint32_t DEACHINT; /*!< dedicated EP interrupt Address offset : 0x838 */ - __IO uint32_t DEACHMSK; /*!< dedicated EP msk Address offset : 0x83C */ + __IO uint32_t DEACHMSK; /*!< dedicated EP msk Address offset : 0x83C */ uint32_t Reserved40; /*!< dedicated EP mask Address offset : 0x840 */ __IO uint32_t DINEP1MSK; /*!< dedicated EP mask Address offset : 0x844 */ uint32_t Reserved44[15]; /*!< Reserved Address offset : 0x844-0x87C */ - __IO uint32_t DOUTEP1MSK; /*!< dedicated EP msk Address offset : 0x884 */ + __IO uint32_t DOUTEP1MSK; /*!< dedicated EP msk Address offset : 0x884 */ } USB_OTG_DeviceTypeDef; -/** +/** * @brief __IN_Endpoint-Specific_Register */ -typedef struct +typedef struct { __IO uint32_t DIEPCTL; /* dev IN Endpoint Control Reg 900h + (ep_num * 20h) + 00h */ uint32_t Reserved04; /* Reserved 900h + (ep_num * 20h) + 04h */ @@ -783,10 +783,10 @@ typedef struct USB_OTG_INEndpointTypeDef; -/** +/** * @brief __OUT_Endpoint-Specific_Registers */ -typedef struct +typedef struct { __IO uint32_t DOEPCTL; /* dev OUT Endpoint Control Reg B00h + (ep_num * 20h) + 00h*/ uint32_t Reserved04; /* Reserved B00h + (ep_num * 20h) + 04h*/ @@ -799,10 +799,10 @@ typedef struct USB_OTG_OUTEndpointTypeDef; -/** +/** * @brief __Host_Mode_Register_Structures */ -typedef struct +typedef struct { __IO uint32_t HCFG; /* Host Configuration Register 400h*/ __IO uint32_t HFIR; /* Host Frame Interval Register 404h*/ @@ -815,7 +815,7 @@ typedef struct USB_OTG_HostTypeDef; -/** +/** * @brief __Host_Channel_Specific_Registers */ typedef struct @@ -830,8 +830,8 @@ typedef struct } USB_OTG_HostChannelTypeDef; - -/** + +/** * @brief Peripheral_memory_map */ #define FLASH_BASE 0x08000000U /*!< FLASH(up to 1 MB) base address in the alias region */ @@ -965,10 +965,10 @@ USB_OTG_HostChannelTypeDef; /** * @} */ - + /** @addtogroup Peripheral_declaration * @{ - */ + */ #define TIM2 ((TIM_TypeDef *) TIM2_BASE) #define TIM3 ((TIM_TypeDef *) TIM3_BASE) #define TIM4 ((TIM_TypeDef *) TIM4_BASE) @@ -1003,7 +1003,7 @@ USB_OTG_HostChannelTypeDef; #define ADC2 ((ADC_TypeDef *) ADC2_BASE) #define ADC3 ((ADC_TypeDef *) ADC3_BASE) #define SDIO ((SDIO_TypeDef *) SDIO_BASE) -#define SPI1 ((SPI_TypeDef *) SPI1_BASE) +#define SPI1 ((SPI_TypeDef *) SPI1_BASE) #define SYSCFG ((SYSCFG_TypeDef *) SYSCFG_BASE) #define EXTI ((EXTI_TypeDef *) EXTI_BASE) #define TIM9 ((TIM_TypeDef *) TIM9_BASE) @@ -1038,7 +1038,7 @@ USB_OTG_HostChannelTypeDef; #define DMA2_Stream4 ((DMA_Stream_TypeDef *) DMA2_Stream4_BASE) #define DMA2_Stream5 ((DMA_Stream_TypeDef *) DMA2_Stream5_BASE) #define DMA2_Stream6 ((DMA_Stream_TypeDef *) DMA2_Stream6_BASE) -#define DMA2_Stream7 ((DMA_Stream_TypeDef *) DMA2_Stream7_BASE) +#define DMA2_Stream7 ((DMA_Stream_TypeDef *) DMA2_Stream7_BASE) #define RNG ((RNG_TypeDef *) RNG_BASE) #define FSMC_Bank1 ((FSMC_Bank1_TypeDef *) FSMC_Bank1_R_BASE) #define FSMC_Bank1E ((FSMC_Bank1E_TypeDef *) FSMC_Bank1E_R_BASE) @@ -1057,11 +1057,11 @@ USB_OTG_HostChannelTypeDef; /** @addtogroup Exported_constants * @{ */ - + /** @addtogroup Peripheral_Registers_Bits_Definition * @{ */ - + /******************************************************************************/ /* Peripheral Registers_Bits_Definition */ /******************************************************************************/ @@ -1104,7 +1104,7 @@ USB_OTG_HostChannelTypeDef; #define ADC_CR1_RES_0 0x01000000U /*!
© COPYRIGHT(c) 2016 STMicroelectronics
@@ -32,8 +32,8 @@ * 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. * - ****************************************************************************** - */ + ****************************************************************************** + */ /** @addtogroup CMSIS * @{ @@ -41,8 +41,8 @@ /** @addtogroup stm32f4xx_system * @{ - */ - + */ + /** * @brief Define to prevent recursive inclusion */ @@ -51,7 +51,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif /** @addtogroup STM32F4xx_System_Includes * @{ @@ -68,7 +68,7 @@ /* This variable is updated in three ways: 1) by calling CMSIS function SystemCoreClockUpdate() 2) by calling HAL API function HAL_RCC_GetSysClockFreq() - 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency + 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency Note: If you use this function to configure the system clock; then there is no need to call the 2 first functions listed above, since SystemCoreClock variable is updated automatically. @@ -101,7 +101,7 @@ extern const uint8_t APBPrescTable[8]; /*!< APB prescalers table values */ /** @addtogroup STM32F4xx_System_Exported_Functions * @{ */ - + extern void SystemInit(void); extern void SystemCoreClockUpdate(void); /** @@ -117,8 +117,8 @@ extern void SystemCoreClockUpdate(void); /** * @} */ - + /** * @} - */ + */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/board/libc.h b/board/libc.h index 564d29cd8..83adb9c09 100644 --- a/board/libc.h +++ b/board/libc.h @@ -6,32 +6,36 @@ void delay(int a) { } void *memset(void *str, int c, unsigned int n) { - unsigned int i; - for (i = 0; i < n; i++) { - *((uint8_t*)str) = c; - ++str; + uint8_t *s = str; + for (unsigned int i = 0; i < n; i++) { + *s = c; + s++; } return str; } void *memcpy(void *dest, const void *src, unsigned int n) { - unsigned int i; - // TODO: make not slow - for (i = 0; i < n; i++) { - ((uint8_t*)dest)[i] = *(uint8_t*)src; - ++src; + uint8_t *d = dest; + const uint8_t *s = src; + for (unsigned int i = 0; i < n; i++) { + *d = *s; + d++; + s++; } return dest; } int memcmp(const void * ptr1, const void * ptr2, unsigned int num) { - unsigned int i; int ret = 0; - for (i = 0; i < num; i++) { - if ( ((uint8_t*)ptr1)[i] != ((uint8_t*)ptr2)[i] ) { + const uint8_t *p1 = ptr1; + const uint8_t *p2 = ptr2; + for (unsigned int i = 0; i < num; i++) { + if (*p1 != *p2) { ret = -1; break; } + p1++; + p2++; } return ret; } diff --git a/board/main.c b/board/main.c index e24df3818..f96216912 100644 --- a/board/main.c +++ b/board/main.c @@ -33,7 +33,7 @@ void debug_ring_callback(uart_ring *ring) { char rcv; while (getc(ring, &rcv)) { - putc(ring, rcv); + (void)putc(ring, rcv); // misra-c2012-17.7: cast to void is ok: debug function // jump to DFU flash if (rcv == 'z') { @@ -69,9 +69,10 @@ bool is_gpio_started(void) { return (GPIOA->IDR & (1U << 1)) == 0; } +// cppcheck-suppress unusedFunction ; used in headers not included in cppcheck void EXTI1_IRQHandler(void) { - volatile int pr = EXTI->PR & (1U << 1); - if ((pr & (1U << 1)) != 0) { + volatile unsigned int pr = EXTI->PR & (1U << 1); + if ((pr & (1U << 1)) != 0U) { #ifdef DEBUG puts("got started interrupt\n"); #endif @@ -98,13 +99,14 @@ void started_interrupt_init(void) { int get_health_pkt(void *dat) { struct __attribute__((packed)) { - uint32_t voltage; - uint32_t current; - uint8_t started; - uint8_t controls_allowed; - uint8_t gas_interceptor_detected; - uint8_t started_signal_detected; - uint8_t started_alt; + uint32_t voltage_pkt; + uint32_t current_pkt; + uint8_t started_pkt; + uint8_t controls_allowed_pkt; + uint8_t gas_interceptor_detected_pkt; + uint32_t can_send_errs_pkt; + uint32_t can_fwd_errs_pkt; + uint32_t gmlan_send_errs_pkt; } *health = dat; //Voltage will be measured in mv. 5000 = 5V @@ -117,29 +119,28 @@ int get_health_pkt(void *dat) { // s = 1000/((4095/3.3)*(1/11)) = 8.8623046875 // Avoid needing floating point math - health->voltage = (voltage * 8862) / 1000; + health->voltage_pkt = (voltage * 8862U) / 1000U; - health->current = adc_get(ADCCHAN_CURRENT); + health->current_pkt = adc_get(ADCCHAN_CURRENT); int safety_ignition = safety_ignition_hook(); if (safety_ignition < 0) { //Use the GPIO pin to determine ignition - health->started = is_gpio_started(); + health->started_pkt = is_gpio_started(); } else { //Current safety hooks want to determine ignition (ex: GM) - health->started = safety_ignition; + health->started_pkt = safety_ignition; } - health->controls_allowed = controls_allowed; - health->gas_interceptor_detected = gas_interceptor_detected; - - // DEPRECATED - health->started_alt = 0; - health->started_signal_detected = 0; + health->controls_allowed_pkt = controls_allowed; + health->gas_interceptor_detected_pkt = gas_interceptor_detected; + health->can_send_errs_pkt = can_send_errs; + health->can_fwd_errs_pkt = can_fwd_errs; + health->gmlan_send_errs_pkt = gmlan_send_errs; return sizeof(*health); } -int usb_cb_ep1_in(uint8_t *usbdata, int len, bool hardwired) { +int usb_cb_ep1_in(void *usbdata, int len, bool hardwired) { UNUSED(hardwired); CAN_FIFOMailBox_TypeDef *reply = (CAN_FIFOMailBox_TypeDef *)usbdata; int ilen = 0; @@ -150,13 +151,14 @@ int usb_cb_ep1_in(uint8_t *usbdata, int len, bool hardwired) { } // send on serial, first byte to select the ring -void usb_cb_ep2_out(uint8_t *usbdata, int len, bool hardwired) { +void usb_cb_ep2_out(void *usbdata, int len, bool hardwired) { UNUSED(hardwired); - uart_ring *ur = get_ring_by_number(usbdata[0]); + uint8_t *usbdata8 = (uint8_t *)usbdata; + uart_ring *ur = get_ring_by_number(usbdata8[0]); if ((len != 0) && (ur != NULL)) { - if ((usbdata[0] < 2) || safety_tx_lin_hook(usbdata[0]-2, usbdata+1, len-1)) { + if ((usbdata8[0] < 2U) || safety_tx_lin_hook(usbdata8[0] - 2U, usbdata8 + 1, len - 1)) { for (int i = 1; i < len; i++) { - while (!putc(ur, usbdata[i])) { + while (!putc(ur, usbdata8[i])) { // wait } } @@ -165,18 +167,16 @@ void usb_cb_ep2_out(uint8_t *usbdata, int len, bool hardwired) { } // send on CAN -void usb_cb_ep3_out(uint8_t *usbdata, int len, bool hardwired) { +void usb_cb_ep3_out(void *usbdata, int len, bool hardwired) { UNUSED(hardwired); int dpkt = 0; - for (dpkt = 0; dpkt < len; dpkt += 0x10) { - uint32_t *tf = (uint32_t*)(&usbdata[dpkt]); - - // make a copy + uint32_t *d32 = (uint32_t *)usbdata; + for (dpkt = 0; dpkt < (len / 4); dpkt += 4) { CAN_FIFOMailBox_TypeDef to_push; - to_push.RDHR = tf[3]; - to_push.RDLR = tf[2]; - to_push.RDTR = tf[1]; - to_push.RIR = tf[0]; + to_push.RDHR = d32[dpkt + 3]; + to_push.RDLR = d32[dpkt + 2]; + to_push.RDTR = d32[dpkt + 1]; + to_push.RIR = d32[dpkt]; uint8_t bus_number = (to_push.RDTR >> 4) & CAN_BUS_NUM_MASK; can_send(&to_push, bus_number); @@ -191,7 +191,7 @@ void usb_cb_enumeration_complete() { } int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired) { - int resp_len = 0; + unsigned int resp_len = 0; uart_ring *ur = NULL; int i; switch (setup->b.bRequest) { @@ -211,8 +211,8 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired) // **** 0xd0: fetch serial number case 0xd0: // addresses are OTP - if (setup->b.wValue.w == 1) { - memcpy(resp, (void *)0x1fff79c0, 0x10); + if (setup->b.wValue.w == 1U) { + (void)memcpy(resp, (uint8_t *)0x1fff79c0, 0x10); resp_len = 0x10; } else { get_provision_chunk(resp); @@ -248,8 +248,8 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired) // **** 0xd6: get version case 0xd6: COMPILE_TIME_ASSERT(sizeof(gitversion) <= MAX_RESP_LEN); - memcpy(resp, gitversion, sizeof(gitversion)); - resp_len = sizeof(gitversion)-1; + (void)memcpy(resp, gitversion, sizeof(gitversion)); + resp_len = sizeof(gitversion) - 1U; break; // **** 0xd8: reset ST case 0xd8: @@ -257,9 +257,9 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired) break; // **** 0xd9: set ESP power case 0xd9: - if (setup->b.wValue.w == 1) { + if (setup->b.wValue.w == 1U) { set_esp_mode(ESP_ENABLED); - } else if (setup->b.wValue.w == 2) { + } else if (setup->b.wValue.w == 2U) { set_esp_mode(ESP_BOOTMODE); } else { set_esp_mode(ESP_DISABLED); @@ -269,7 +269,7 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired) case 0xda: set_esp_mode(ESP_DISABLED); delay(1000000); - if (setup->b.wValue.w == 1) { + if (setup->b.wValue.w == 1U) { set_esp_mode(ESP_BOOTMODE); } else { set_esp_mode(ESP_ENABLED); @@ -279,12 +279,14 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired) break; // **** 0xdb: set GMLAN multiplexing mode case 0xdb: - if (setup->b.wValue.w == 1) { + if (setup->b.wValue.w == 1U) { // GMLAN ON - if (setup->b.wIndex.w == 1) { + if (setup->b.wIndex.w == 1U) { can_set_gmlan(1); - } else if (setup->b.wIndex.w == 2) { + } else if (setup->b.wIndex.w == 2U) { can_set_gmlan(2); + } else { + puts("Invalid bus num for GMLAN CAN set\n"); } } else { can_set_gmlan(-1); @@ -296,27 +298,33 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired) // and it's blocked over WiFi // Allow ELM security mode to be set over wifi. if (hardwired || (setup->b.wValue.w == SAFETY_NOOUTPUT) || (setup->b.wValue.w == SAFETY_ELM327)) { - safety_set_mode(setup->b.wValue.w, (int16_t)setup->b.wIndex.w); - 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); - } - #ifndef EON - // always LIVE on EON - switch (setup->b.wValue.w) { - case SAFETY_NOOUTPUT: - can_silent = ALL_CAN_SILENT; - break; - case SAFETY_ELM327: - can_silent = ALL_CAN_BUT_MAIN_SILENT; - break; - default: - can_silent = ALL_CAN_LIVE; - break; + int err = safety_set_mode(setup->b.wValue.w, (int16_t)setup->b.wIndex.w); + if (err == -1) { + puts("Error: safety set mode failed\n"); + } else { + #ifndef EON + // always LIVE on EON + switch (setup->b.wValue.w) { + case SAFETY_NOOUTPUT: + can_silent = ALL_CAN_SILENT; + break; + case SAFETY_ELM327: + can_silent = ALL_CAN_BUT_MAIN_SILENT; + break; + default: + can_silent = ALL_CAN_LIVE; + break; + } + #endif + 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 } - #endif - can_init_all(); + can_init_all(); + } } break; // **** 0xdd: enable can forwarding @@ -326,8 +334,10 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired) if ((setup->b.wValue.w < BUS_MAX) && (setup->b.wIndex.w < BUS_MAX) && (setup->b.wValue.w != setup->b.wIndex.w)) { // set forwarding can_set_forwarding(setup->b.wValue.w, setup->b.wIndex.w & CAN_BUS_NUM_MASK); - } else if((setup->b.wValue.w < BUS_MAX) && (setup->b.wIndex.w == 0xFF)){ //Clear Forwarding + } else if((setup->b.wValue.w < BUS_MAX) && (setup->b.wIndex.w == 0xFFU)){ //Clear Forwarding can_set_forwarding(setup->b.wValue.w, -1); + } else { + puts("Invalid CAN bus forwarding\n"); } break; // **** 0xde: set can bitrate @@ -340,7 +350,7 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired) // **** 0xdf: set long controls allowed case 0xdf: if (hardwired) { - long_controls_allowed = setup->b.wValue.w & 1; + long_controls_allowed = setup->b.wValue.w & 1U; } break; // **** 0xe0: uart read @@ -401,15 +411,15 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired) break; // **** 0xe5: set CAN loopback (for testing) case 0xe5: - can_loopback = (setup->b.wValue.w > 0); + can_loopback = (setup->b.wValue.w > 0U); can_init_all(); break; // **** 0xe6: set USB power case 0xe6: - if (setup->b.wValue.w == 1) { + if (setup->b.wValue.w == 1U) { puts("user setting CDP mode\n"); set_usb_power_mode(USB_POWER_CDP); - } else if (setup->b.wValue.w == 2) { + } else if (setup->b.wValue.w == 2U) { puts("user setting DCP mode\n"); set_usb_power_mode(USB_POWER_DCP); } else { @@ -419,7 +429,7 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired) break; // **** 0xf0: do k-line wValue pulse on uart2 for Acura case 0xf0: - if (setup->b.wValue.w == 1) { + if (setup->b.wValue.w == 1U) { GPIOC->ODR &= ~(1U << 10); GPIOC->MODER &= ~GPIO_MODER_MODER10_1; GPIOC->MODER |= GPIO_MODER_MODER10_0; @@ -431,7 +441,7 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired) for (i = 0; i < 80; i++) { delay(8000); - if (setup->b.wValue.w == 1) { + if (setup->b.wValue.w == 1U) { GPIOC->ODR |= (1U << 10); GPIOC->ODR &= ~(1U << 10); } else { @@ -440,7 +450,7 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired) } } - if (setup->b.wValue.w == 1) { + if (setup->b.wValue.w == 1U) { GPIOC->MODER &= ~GPIO_MODER_MODER10_0; GPIOC->MODER |= GPIO_MODER_MODER10_1; } else { @@ -452,12 +462,14 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired) break; // **** 0xf1: Clear CAN ring buffer. case 0xf1: - if (setup->b.wValue.w == 0xFFFF) { + if (setup->b.wValue.w == 0xFFFFU) { puts("Clearing CAN Rx queue\n"); can_clear(&can_rx_q); } else if (setup->b.wValue.w < BUS_MAX) { puts("Clearing CAN Tx queue\n"); can_clear(can_queues[setup->b.wValue.w]); + } else { + puts("Clearing CAN CAN ring buffer failed: wrong bus number\n"); } break; // **** 0xf2: Clear UART ring buffer. @@ -479,6 +491,7 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired) return resp_len; } +#ifndef EON int spi_cb_rx(uint8_t *data, int len, uint8_t *data_out) { // data[0] = endpoint // data[2] = length @@ -508,26 +521,28 @@ int spi_cb_rx(uint8_t *data, int len, uint8_t *data_out) { } return resp_len; } - +#endif // ***************************** main code ***************************** +// cppcheck-suppress unusedFunction ; used in headers not included in cppcheck void __initialize_hardware_early(void) { early(); } void __attribute__ ((noinline)) enable_fpu(void) { // enable the FPU - SCB->CPACR |= ((3UL << (10U * 2)) | (3UL << (11U * 2))); + SCB->CPACR |= ((3UL << (10U * 2U)) | (3UL << (11U * 2U))); } uint64_t tcnt = 0; uint64_t marker = 0; // called once per second +// cppcheck-suppress unusedFunction ; used in headers not included in cppcheck void TIM3_IRQHandler(void) { - #define CURRENT_THRESHOLD 0xF00 - #define CLICKS 5 // 5 seconds to switch modes + #define CURRENT_THRESHOLD 0xF00U + #define CLICKS 5U // 5 seconds to switch modes if (TIM3->SR != 0) { can_live = pending_can_live; @@ -538,7 +553,7 @@ void TIM3_IRQHandler(void) { switch (usb_power_mode) { case USB_POWER_CLIENT: - if ((tcnt-marker) >= CLICKS) { + if ((tcnt - marker) >= CLICKS) { if (!is_enumerated) { puts("USBP: didn't enumerate, switching to CDP mode\n"); // switch to CDP @@ -594,7 +609,7 @@ void TIM3_IRQHandler(void) { puts("\n");*/ // reset this every 16th pass - if ((tcnt&0xF) == 0) { + if ((tcnt & 0xFU) == 0U) { pending_can_live = 0; } #ifdef DEBUG @@ -609,10 +624,10 @@ void TIM3_IRQHandler(void) { // turn off the blue LED, turned on by CAN // unless we are in power saving mode - set_led(LED_BLUE, (tcnt & 1) && (power_save_status == POWER_SAVE_STATUS_ENABLED)); + set_led(LED_BLUE, (tcnt & 1U) && (power_save_status == POWER_SAVE_STATUS_ENABLED)); // on to the next one - tcnt += 1; + tcnt += 1U; } TIM3->SR = 0; } @@ -680,7 +695,13 @@ int main(void) { // default to silent mode to prevent issues with Ford // hardcode a specific safety mode if you want to force the panda to be in a specific mode - safety_set_mode(SAFETY_NOOUTPUT, 0); + int err = safety_set_mode(SAFETY_NOOUTPUT, 0); + if (err == -1) { + puts("Failed to set safety mode\n"); + while (true) { + // if SAFETY_NOOUTPUT isn't succesfully set, we can't continue + } + } #ifdef EON // if we're on an EON, it's fine for CAN to be live for fingerprinting can_silent = ALL_CAN_LIVE; diff --git a/board/pedal/Makefile b/board/pedal/Makefile index 37b95f90f..7ce6dd076 100644 --- a/board/pedal/Makefile +++ b/board/pedal/Makefile @@ -1,10 +1,10 @@ # :set noet PROJ_NAME = comma -CFLAGS = -O2 -Wall -std=gnu11 -DPEDAL +CFLAGS = -O2 -Wall -Wextra -Wstrict-prototypes -Werror -std=gnu11 -DPEDAL CFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m3 CFLAGS += -msoft-float -DSTM32F2 -DSTM32F205xx -CFLAGS += -I ../inc -I ../ -I ../../ -nostdlib +CFLAGS += -I ../inc -I ../ -I ../../ -nostdlib -fno-builtin CFLAGS += -T../stm32_flash.ld STARTUP_FILE = startup_stm32f205xx diff --git a/board/pedal/main.c b/board/pedal/main.c index 4656db283..21a3a59fa 100644 --- a/board/pedal/main.c +++ b/board/pedal/main.c @@ -19,14 +19,19 @@ #include "drivers/usb.h" #else // no serial either - void puts(const char *a) {} - void puth(unsigned int i) {} + void puts(const char *a) { + UNUSED(a); + } + void puth(unsigned int i) { + UNUSED(i); + } #endif #define ENTER_BOOTLOADER_MAGIC 0xdeadbeef uint32_t enter_bootloader_mode; -void __initialize_hardware_early() { +// cppcheck-suppress unusedFunction ; used in headers not included in cppcheck +void __initialize_hardware_early(void) { early(); } @@ -36,31 +41,54 @@ void __initialize_hardware_early() { void debug_ring_callback(uart_ring *ring) { char rcv; - while (getc(ring, &rcv)) { - putc(ring, rcv); + while (getc(ring, &rcv) != 0) { + (void)putc(ring, rcv); } } -int usb_cb_ep1_in(uint8_t *usbdata, int len, bool hardwired) { return 0; } -void usb_cb_ep2_out(uint8_t *usbdata, int len, bool hardwired) {} -void usb_cb_ep3_out(uint8_t *usbdata, int len, bool hardwired) {} -void usb_cb_enumeration_complete() {} +int usb_cb_ep1_in(uint8_t *usbdata, int len, bool hardwired) { + UNUSED(usbdata); + UNUSED(len); + UNUSED(hardwired); + return 0; +} +void usb_cb_ep2_out(uint8_t *usbdata, int len, bool hardwired) { + UNUSED(usbdata); + UNUSED(len); + UNUSED(hardwired); +} +void usb_cb_ep3_out(uint8_t *usbdata, int len, bool hardwired) { + UNUSED(usbdata); + UNUSED(len); + UNUSED(hardwired); +} +void usb_cb_enumeration_complete(void) {} int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired) { - int resp_len = 0; + UNUSED(hardwired); + unsigned int resp_len = 0; uart_ring *ur = NULL; switch (setup->b.bRequest) { // **** 0xe0: uart read case 0xe0: ur = get_ring_by_number(setup->b.wValue.w); - if (!ur) break; - if (ur == &esp_ring) uart_dma_drain(); + if (!ur) { + break; + } + if (ur == &esp_ring) { + uart_dma_drain(); + } // read while ((resp_len < MIN(setup->b.wLength.w, MAX_RESP_LEN)) && getc(ur, (char*)&resp[resp_len])) { ++resp_len; } break; + default: + puts("NO HANDLER "); + puth(setup->b.bRequest); + puts("\n"); + break; } return resp_len; } @@ -76,7 +104,7 @@ uint8_t pedal_checksum(uint8_t *dat, int len) { for (i = len - 1; i >= 0; i--) { crc ^= dat[i]; for (j = 0; j < 8; j++) { - if ((crc & 0x80) != 0) { + if ((crc & 0x80U) != 0U) { crc = (uint8_t)((crc << 1) ^ poly); } else { @@ -91,11 +119,12 @@ uint8_t pedal_checksum(uint8_t *dat, int len) { // addresses to be used on CAN #define CAN_GAS_INPUT 0x200 -#define CAN_GAS_OUTPUT 0x201 +#define CAN_GAS_OUTPUT 0x201U #define CAN_GAS_SIZE 6 -#define COUNTER_CYCLE 0xF +#define COUNTER_CYCLE 0xFU -void CAN1_TX_IRQHandler() { +// cppcheck-suppress unusedFunction ; used in headers not included in cppcheck +void CAN1_TX_IRQHandler(void) { // clear interrupt CAN->TSR |= CAN_TSR_RQCP0; } @@ -104,51 +133,51 @@ void CAN1_TX_IRQHandler() { uint16_t gas_set_0 = 0; uint16_t gas_set_1 = 0; -#define MAX_TIMEOUT 10 +#define MAX_TIMEOUT 10U uint32_t timeout = 0; uint32_t current_index = 0; -#define NO_FAULT 0 -#define FAULT_BAD_CHECKSUM 1 -#define FAULT_SEND 2 -#define FAULT_SCE 3 -#define FAULT_STARTUP 4 -#define FAULT_TIMEOUT 5 -#define FAULT_INVALID 6 +#define NO_FAULT 0U +#define FAULT_BAD_CHECKSUM 1U +#define FAULT_SEND 2U +#define FAULT_SCE 3U +#define FAULT_STARTUP 4U +#define FAULT_TIMEOUT 5U +#define FAULT_INVALID 6U uint8_t state = FAULT_STARTUP; -void CAN1_RX0_IRQHandler() { - while (CAN->RF0R & CAN_RF0R_FMP0) { +// cppcheck-suppress unusedFunction ; used in headers not included in cppcheck +void CAN1_RX0_IRQHandler(void) { + while ((CAN->RF0R & CAN_RF0R_FMP0) != 0) { #ifdef DEBUG puts("CAN RX\n"); #endif - uint32_t address = CAN->sFIFOMailBox[0].RIR>>21; + int address = CAN->sFIFOMailBox[0].RIR >> 21; if (address == CAN_GAS_INPUT) { // softloader entry - if (CAN->sFIFOMailBox[0].RDLR == 0xdeadface) { - if (CAN->sFIFOMailBox[0].RDHR == 0x0ab00b1e) { + if (GET_BYTES_04(&CAN->sFIFOMailBox[0]) == 0xdeadface) { + if (GET_BYTES_48(&CAN->sFIFOMailBox[0]) == 0x0ab00b1e) { enter_bootloader_mode = ENTER_SOFTLOADER_MAGIC; NVIC_SystemReset(); - } else if (CAN->sFIFOMailBox[0].RDHR == 0x02b00b1e) { + } else if (GET_BYTES_48(&CAN->sFIFOMailBox[0]) == 0x02b00b1e) { enter_bootloader_mode = ENTER_BOOTLOADER_MAGIC; NVIC_SystemReset(); + } else { + puts("Failed entering Softloader or Bootloader\n"); } } // normal packet uint8_t dat[8]; - uint8_t *rdlr = (uint8_t *)&CAN->sFIFOMailBox[0].RDLR; - uint8_t *rdhr = (uint8_t *)&CAN->sFIFOMailBox[0].RDHR; - for (int i=0; i<4; i++) { - dat[i] = rdlr[i]; - dat[i+4] = rdhr[i]; + for (int i=0; i<8; i++) { + dat[i] = GET_BYTE(&CAN->sFIFOMailBox[0], i); } uint16_t value_0 = (dat[0] << 8) | dat[1]; uint16_t value_1 = (dat[2] << 8) | dat[3]; - uint8_t enable = (dat[4] >> 7) & 1; + bool enable = ((dat[4] >> 7) & 1U) != 0U; uint8_t index = dat[4] & COUNTER_CYCLE; if (pedal_checksum(dat, CAN_GAS_SIZE - 1) == dat[5]) { - if (((current_index + 1) & COUNTER_CYCLE) == index) { + if (((current_index + 1U) & COUNTER_CYCLE) == index) { #ifdef DEBUG puts("setting gas "); puth(value); @@ -159,12 +188,13 @@ void CAN1_RX0_IRQHandler() { gas_set_1 = value_1; } else { // clear the fault state if values are 0 - if (value_0 == 0 && value_1 == 0) { + if ((value_0 == 0U) && (value_1 == 0U)) { state = NO_FAULT; } else { state = FAULT_INVALID; } - gas_set_0 = gas_set_1 = 0; + gas_set_0 = 0; + gas_set_1 = 0; } // clear the timeout timeout = 0; @@ -180,17 +210,20 @@ void CAN1_RX0_IRQHandler() { } } -void CAN1_SCE_IRQHandler() { +// cppcheck-suppress unusedFunction ; used in headers not included in cppcheck +void CAN1_SCE_IRQHandler(void) { state = FAULT_SCE; llcan_clear_send(CAN); } -int pdl0 = 0, pdl1 = 0; -int pkt_idx = 0; +uint32_t pdl0 = 0; +uint32_t pdl1 = 0; +unsigned int pkt_idx = 0; int led_value = 0; -void TIM3_IRQHandler() { +// cppcheck-suppress unusedFunction ; used in headers not included in cppcheck +void TIM3_IRQHandler(void) { #ifdef DEBUG puth(TIM3->CNT); puts(" "); @@ -203,16 +236,16 @@ void TIM3_IRQHandler() { // check timer for sending the user pedal and clearing the CAN if ((CAN->TSR & CAN_TSR_TME0) == CAN_TSR_TME0) { uint8_t dat[8]; - dat[0] = (pdl0>>8) & 0xFF; - dat[1] = (pdl0>>0) & 0xFF; - dat[2] = (pdl1>>8) & 0xFF; - dat[3] = (pdl1>>0) & 0xFF; - dat[4] = (state & 0xF) << 4 | pkt_idx; + dat[0] = (pdl0 >> 8) & 0xFFU; + dat[1] = (pdl0 >> 0) & 0xFFU; + dat[2] = (pdl1 >> 8) & 0xFFU; + dat[3] = (pdl1 >> 0) & 0xFFU; + dat[4] = ((state & 0xFU) << 4) | pkt_idx; dat[5] = pedal_checksum(dat, CAN_GAS_SIZE - 1); - CAN->sTxMailBox[0].TDLR = dat[0] | (dat[1]<<8) | (dat[2]<<16) | (dat[3]<<24); - CAN->sTxMailBox[0].TDHR = dat[4] | (dat[5]<<8); + CAN->sTxMailBox[0].TDLR = dat[0] | (dat[1] << 8) | (dat[2] << 16) | (dat[3] << 24); + CAN->sTxMailBox[0].TDHR = dat[4] | (dat[5] << 8); CAN->sTxMailBox[0].TDTR = 6; // len of packet is 5 - CAN->sTxMailBox[0].TIR = (CAN_GAS_OUTPUT << 21) | 1; + CAN->sTxMailBox[0].TIR = (CAN_GAS_OUTPUT << 21) | 1U; ++pkt_idx; pkt_idx &= COUNTER_CYCLE; } else { @@ -233,13 +266,13 @@ void TIM3_IRQHandler() { if (timeout == MAX_TIMEOUT) { state = FAULT_TIMEOUT; } else { - timeout += 1; + timeout += 1U; } } // ***************************** main code ***************************** -void pedal() { +void pedal(void) { // read/write pdl0 = adc_get(ADCCHAN_ACCEL0); pdl1 = adc_get(ADCCHAN_ACCEL1); @@ -256,7 +289,7 @@ void pedal() { watchdog_feed(); } -int main() { +int main(void) { __disable_irq(); // init devices @@ -274,7 +307,11 @@ int main() { adc_init(); // init can - llcan_set_speed(CAN1, 5000, false, false); + bool llcan_speed_set = llcan_set_speed(CAN1, 5000, false, false); + if (!llcan_speed_set) { + puts("Failed to set llcan speed"); + } + llcan_init(CAN1); // 48mhz / 65536 ~= 732 diff --git a/board/power_saving.h b/board/power_saving.h index 986adf3ce..3a9ae39e4 100644 --- a/board/power_saving.h +++ b/board/power_saving.h @@ -13,14 +13,14 @@ void set_power_save_state(int state) { if (is_grey_panda) { char UBLOX_SLEEP_MSG[] = "\xb5\x62\x06\x04\x04\x00\x01\x00\x08\x00\x17\x78"; uart_ring *ur = get_ring_by_number(1); - for (unsigned int i = 0; i < sizeof(UBLOX_SLEEP_MSG) - 1; i++) while (!putc(ur, UBLOX_SLEEP_MSG[i])); + for (unsigned int i = 0; i < sizeof(UBLOX_SLEEP_MSG) - 1U; i++) while (!putc(ur, UBLOX_SLEEP_MSG[i])); } } else { puts("disable power savings\n"); if (is_grey_panda) { char UBLOX_WAKE_MSG[] = "\xb5\x62\x06\x04\x04\x00\x01\x00\x09\x00\x18\x7a"; uart_ring *ur = get_ring_by_number(1); - for (unsigned int i = 0; i < sizeof(UBLOX_WAKE_MSG) - 1; i++) while (!putc(ur, UBLOX_WAKE_MSG[i])); + for (unsigned int i = 0; i < sizeof(UBLOX_WAKE_MSG) - 1U; i++) while (!putc(ur, UBLOX_WAKE_MSG[i])); } enable = true; } diff --git a/board/provision.h b/board/provision.h index 2fad51350..9091322f1 100644 --- a/board/provision.h +++ b/board/provision.h @@ -5,9 +5,9 @@ // SHA1 checksum = 0x1C - 0x20 void get_provision_chunk(uint8_t *resp) { - memcpy(resp, (void *)0x1fff79e0, PROVISION_CHUNK_LEN); + (void)memcpy(resp, (uint8_t *)0x1fff79e0, PROVISION_CHUNK_LEN); if (memcmp(resp, "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", 0x20) == 0) { - memcpy(resp, "unprovisioned\x00\x00\x00testing123\x00\x00\xa3\xa6\x99\xec", 0x20); + (void)memcpy(resp, "unprovisioned\x00\x00\x00testing123\x00\x00\xa3\xa6\x99\xec", 0x20); } } diff --git a/board/safety.h b/board/safety.h index dd99e6db2..6b2b5a045 100644 --- a/board/safety.h +++ b/board/safety.h @@ -44,21 +44,21 @@ typedef struct { const safety_hooks *hooks; } safety_hook_config; -#define SAFETY_NOOUTPUT 0 -#define SAFETY_HONDA 1 -#define SAFETY_TOYOTA 2 -#define SAFETY_GM 3 -#define SAFETY_HONDA_BOSCH 4 -#define SAFETY_FORD 5 -#define SAFETY_CADILLAC 6 -#define SAFETY_HYUNDAI 7 -#define SAFETY_TESLA 8 -#define SAFETY_CHRYSLER 9 -#define SAFETY_SUBARU 10 -#define SAFETY_GM_ASCM 0x1334 -#define SAFETY_TOYOTA_IPAS 0x1335 -#define SAFETY_ALLOUTPUT 0x1337 -#define SAFETY_ELM327 0xE327 +#define SAFETY_NOOUTPUT 0U +#define SAFETY_HONDA 1U +#define SAFETY_TOYOTA 2U +#define SAFETY_GM 3U +#define SAFETY_HONDA_BOSCH 4U +#define SAFETY_FORD 5U +#define SAFETY_CADILLAC 6U +#define SAFETY_HYUNDAI 7U +#define SAFETY_TESLA 8U +#define SAFETY_CHRYSLER 9U +#define SAFETY_SUBARU 10U +#define SAFETY_GM_ASCM 0x1334U +#define SAFETY_TOYOTA_IPAS 0x1335U +#define SAFETY_ALLOUTPUT 0x1337U +#define SAFETY_ELM327 0xE327U const safety_hook_config safety_hook_registry[] = { {SAFETY_NOOUTPUT, &nooutput_hooks}, diff --git a/board/safety/safety_cadillac.h b/board/safety/safety_cadillac.h index ef114abfe..ef6336095 100644 --- a/board/safety/safety_cadillac.h +++ b/board/safety/safety_cadillac.h @@ -10,13 +10,13 @@ const int CADILLAC_MAX_RATE_DOWN = 5; const int CADILLAC_DRIVER_TORQUE_ALLOWANCE = 50; const int CADILLAC_DRIVER_TORQUE_FACTOR = 4; -int cadillac_ign = 0; +bool cadillac_ign = 0; int cadillac_cruise_engaged_last = 0; int cadillac_rt_torque_last = 0; const int cadillac_torque_msgs_n = 4; int cadillac_desired_torque_last[CADILLAC_TORQUE_MSG_N] = {0}; uint32_t cadillac_ts_last = 0; -int cadillac_supercruise_on = 0; +bool cadillac_supercruise_on = 0; struct sample_t cadillac_torque_driver; // last few driver torques measured int cadillac_get_torque_idx(int addr, int array_size) { @@ -28,7 +28,8 @@ static void cadillac_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { int addr = GET_ADDR(to_push); if (addr == 356) { - int torque_driver_new = ((to_push->RDLR & 0x7) << 8) | ((to_push->RDLR >> 8) & 0xFF); + int torque_driver_new = ((GET_BYTE(to_push, 0) & 0x7U) << 8) | (GET_BYTE(to_push, 1)); + torque_driver_new = to_signed(torque_driver_new, 11); // update array of samples update_sample(&cadillac_torque_driver, torque_driver_new); @@ -36,12 +37,12 @@ static void cadillac_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { // this message isn't all zeros when ignition is on if ((addr == 0x160) && (bus == 0)) { - cadillac_ign = to_push->RDLR > 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 = to_push->RDLR & 0x800000; // bit 23 + int cruise_engaged = GET_BYTE(to_push, 2) & 0x80; // bit 23 if (cruise_engaged && !cadillac_cruise_engaged_last) { controls_allowed = 1; } @@ -53,7 +54,7 @@ static void cadillac_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { // know supercruise mode and block openpilot msgs if on if ((addr == 0x152) || (addr == 0x154)) { - cadillac_supercruise_on = (to_push->RDHR>>4) & 0x1; + cadillac_supercruise_on = (GET_BYTE(to_push, 4) & 0x10) != 0; } } @@ -63,7 +64,7 @@ static int cadillac_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { // steer cmd checks if ((addr == 0x151) || (addr == 0x152) || (addr == 0x153) || (addr == 0x154)) { - int desired_torque = ((to_send->RDLR & 0x3f) << 8) + ((to_send->RDLR & 0xff00) >> 8); + int desired_torque = ((GET_BYTE(to_send, 0) & 0x3f) << 8) | GET_BYTE(to_send, 1); int violation = 0; uint32_t ts = TIM2->CNT; int idx = cadillac_get_torque_idx(addr, CADILLAC_TORQUE_MSG_N); diff --git a/board/safety/safety_chrysler.h b/board/safety/safety_chrysler.h index 19149b6b7..e60878573 100644 --- a/board/safety/safety_chrysler.h +++ b/board/safety/safety_chrysler.h @@ -18,8 +18,7 @@ static void chrysler_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { // Measured eps torque if (addr == 544) { - uint32_t rdhr = to_push->RDHR; - int torque_meas_new = ((rdhr & 0x7U) << 8) + ((rdhr & 0xFF00U) >> 8) - 1024U; + int torque_meas_new = ((GET_BYTE(to_push, 4) & 0x7U) << 8) + GET_BYTE(to_push, 5) - 1024U; // update array of samples update_sample(&chrysler_torque_meas, torque_meas_new); @@ -27,7 +26,7 @@ static void chrysler_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { // enter controls on rising edge of ACC, exit controls on ACC off if (addr == 0x1F4) { - int cruise_engaged = ((to_push->RDLR & 0x380000) >> 19) == 7; + int cruise_engaged = ((GET_BYTE(to_push, 2) & 0x38) >> 3) == 7; if (cruise_engaged && !chrysler_cruise_engaged_last) { controls_allowed = 1; } @@ -57,8 +56,7 @@ static int chrysler_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { // LKA STEER if (addr == 0x292) { - uint32_t rdlr = to_send->RDLR; - int desired_torque = ((rdlr & 0x7U) << 8) + ((rdlr & 0xFF00U) >> 8) - 1024U; + int desired_torque = ((GET_BYTE(to_send, 0) & 0x7U) << 8) + GET_BYTE(to_send, 1) - 1024U; uint32_t ts = TIM2->CNT; bool violation = 0; diff --git a/board/safety/safety_ford.h b/board/safety/safety_ford.h index 21c9c54db..0bb839f2f 100644 --- a/board/safety/safety_ford.h +++ b/board/safety/safety_ford.h @@ -9,7 +9,7 @@ int ford_brake_prev = 0; int ford_gas_prev = 0; -int ford_is_moving = 0; +bool ford_moving = false; static void ford_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { @@ -17,14 +17,16 @@ static void ford_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { if (addr == 0x217) { // wheel speeds are 14 bits every 16 - ford_is_moving = 0xFCFF & (to_push->RDLR | (to_push->RDLR >> 16) | - to_push->RDHR | (to_push->RDHR >> 16)); + ford_moving = false; + for (int i = 0; i < 8; i += 2) { + ford_moving |= GET_BYTE(to_push, i) | (GET_BYTE(to_push, (int)(i + 1)) & 0xFCU); + } } // state machine to enter and exit controls if (addr == 0x83) { - bool cancel = (to_push->RDLR >> 8) & 0x1; - bool set_or_resume = (to_push->RDLR >> 28) & 0x3; + bool cancel = GET_BYTE(to_push, 1) & 0x1; + bool set_or_resume = GET_BYTE(to_push, 3) & 0x30; if (cancel) { controls_allowed = 0; } @@ -36,8 +38,8 @@ static void ford_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { // exit controls on rising edge of brake press or on brake press when // speed > 0 if (addr == 0x165) { - int brake = to_push->RDLR & 0x20; - if (brake && (!(ford_brake_prev) || ford_is_moving)) { + int brake = GET_BYTE(to_push, 0) & 0x20; + if (brake && (!(ford_brake_prev) || ford_moving)) { controls_allowed = 0; } ford_brake_prev = brake; @@ -45,7 +47,7 @@ static void ford_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { // exit controls on rising edge of gas press if (addr == 0x204) { - int gas = to_push->RDLR & 0xFF03; + int gas = (GET_BYTE(to_push, 0) & 0x03) | GET_BYTE(to_push, 1); if (gas && !(ford_gas_prev)) { controls_allowed = 0; } @@ -64,7 +66,7 @@ static int ford_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { int tx = 1; // disallow actuator commands if gas or brake (with vehicle moving) are pressed // and the the latching controls_allowed flag is True - int pedal_pressed = ford_gas_prev || (ford_brake_prev && ford_is_moving); + int pedal_pressed = ford_gas_prev || (ford_brake_prev && ford_moving); bool current_controls_allowed = controls_allowed && !(pedal_pressed); int addr = GET_ADDR(to_send); @@ -72,7 +74,7 @@ static int ford_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { if (addr == 0x3CA) { if (!current_controls_allowed) { // bits 7-4 need to be 0xF to disallow lkas commands - if (((to_send->RDLR >> 4) & 0xF) != 0xF) { + if ((GET_BYTE(to_send, 0) & 0xF0) != 0xF0) { tx = 0; } } @@ -81,7 +83,7 @@ static int ford_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { // FORCE CANCEL: safety check only relevant when spamming the cancel button // ensuring that set and resume aren't sent if (addr == 0x83) { - if (((to_send->RDLR >> 28) & 0x3) != 0) { + if ((GET_BYTE(to_send, 3) & 0x30) != 0) { tx = 0; } } diff --git a/board/safety/safety_gm.h b/board/safety/safety_gm.h index 949f5c7e7..9ca5ca323 100644 --- a/board/safety/safety_gm.h +++ b/board/safety/safety_gm.h @@ -21,7 +21,7 @@ const int GM_MAX_BRAKE = 350; int gm_brake_prev = 0; int gm_gas_prev = 0; -int gm_speed = 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; @@ -35,7 +35,7 @@ static void gm_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { int addr = GET_ADDR(to_push); if (addr == 388) { - int torque_driver_new = (((to_push->RDHR >> 16) & 0x7) << 8) | ((to_push->RDHR >> 24) & 0xFF); + int torque_driver_new = ((GET_BYTE(to_push, 6) & 0x7) << 8) | GET_BYTE(to_push, 7); torque_driver_new = to_signed(torque_driver_new, 11); // update array of samples update_sample(&gm_torque_driver, torque_driver_new); @@ -44,14 +44,14 @@ static void gm_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { if ((addr == 0x1F1) && (bus_number == 0)) { //Bit 5 should be ignition "on" //Backup plan is Bit 2 (accessory power) - bool ign = ((to_push->RDLR) & 0x20) != 0; + 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) { - gm_speed = to_push->RDLR & 0xFFFF; + gm_moving = GET_BYTE(to_push, 0) | GET_BYTE(to_push, 1); } // Check if ASCM or LKA camera are online @@ -65,7 +65,7 @@ static void gm_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { // ACC steering wheel buttons if (addr == 481) { - int button = (to_push->RDHR >> 12) & 0x7; + int button = (GET_BYTE(to_push, 5) & 0x70) >> 4; switch (button) { case 2: // resume case 3: // set @@ -82,13 +82,13 @@ static void gm_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { // exit controls on rising edge of brake press or on brake press when // speed > 0 if (addr == 241) { - int brake = (to_push->RDLR & 0xFF00) >> 8; + int brake = GET_BYTE(to_push, 1); // Brake pedal's potentiometer returns near-zero reading // even when pedal is not pressed if (brake < 10) { brake = 0; } - if (brake && (!gm_brake_prev || gm_speed)) { + if (brake && (!gm_brake_prev || gm_moving)) { controls_allowed = 0; } gm_brake_prev = brake; @@ -96,7 +96,7 @@ static void gm_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { // exit controls on rising edge of gas press if (addr == 417) { - int gas = to_push->RDHR & 0xFF0000; + int gas = GET_BYTE(to_push, 6); if (gas && !gm_gas_prev && long_controls_allowed) { controls_allowed = 0; } @@ -105,7 +105,7 @@ static void gm_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { // exit controls on regen paddle if (addr == 189) { - bool regen = to_push->RDLR & 0x20; + bool regen = GET_BYTE(to_push, 0) & 0x20; if (regen) { controls_allowed = 0; } @@ -129,15 +129,14 @@ static int gm_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { // disallow actuator commands if gas or brake (with vehicle moving) are pressed // and the the latching controls_allowed flag is True - int pedal_pressed = gm_gas_prev || (gm_brake_prev && gm_speed); + int pedal_pressed = gm_gas_prev || (gm_brake_prev && gm_moving); bool current_controls_allowed = controls_allowed && !pedal_pressed; int addr = GET_ADDR(to_send); // BRAKE: safety check if (addr == 789) { - uint32_t rdlr = to_send->RDLR; - int brake = ((rdlr & 0xFU) << 8) + ((rdlr & 0xFF00U) >> 8); + int brake = ((GET_BYTE(to_send, 0) & 0xFU) << 8) + GET_BYTE(to_send, 1); brake = (0x1000 - brake) & 0xFFF; if (!current_controls_allowed || !long_controls_allowed) { if (brake != 0) { @@ -151,8 +150,7 @@ static int gm_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { // LKA STEER: safety check if (addr == 384) { - uint32_t rdlr = to_send->RDLR; - int desired_torque = ((rdlr & 0x7U) << 8) + ((rdlr & 0xFF00U) >> 8); + int desired_torque = ((GET_BYTE(to_send, 0) & 0x7U) << 8) + GET_BYTE(to_send, 1); uint32_t ts = TIM2->CNT; bool violation = 0; desired_torque = to_signed(desired_torque, 11); @@ -205,12 +203,11 @@ static int gm_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { // GAS/REGEN: safety check if (addr == 715) { - uint32_t rdlr = to_send->RDLR; - int gas_regen = ((rdlr & 0x7F0000U) >> 11) + ((rdlr & 0xF8000000U) >> 27); + int gas_regen = ((GET_BYTE(to_send, 2) & 0x7FU) << 5) + ((GET_BYTE(to_send, 3) & 0xF8U) >> 3); // Disabled message is !engaed with gas // value that corresponds to max regen. if (!current_controls_allowed || !long_controls_allowed) { - bool apply = (rdlr & 1U) != 0U; + bool apply = GET_BYTE(to_send, 0) & 1U; if (apply || (gas_regen != GM_MAX_REGEN)) { tx = 0; } diff --git a/board/safety/safety_gm_ascm.h b/board/safety/safety_gm_ascm.h index d452818d6..82f1db6ae 100644 --- a/board/safety/safety_gm_ascm.h +++ b/board/safety/safety_gm_ascm.h @@ -13,7 +13,7 @@ static int gm_ascm_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) { // block 0x315 and 0x2cb, which are the brake and accel commands from ASCM1 //if ((addr == 0x152) || (addr == 0x154) || (addr == 0x315) || (addr == 0x2cb)) { if ((addr == 0x152) || (addr == 0x154)) { - int supercruise_on = (to_fwd->RDHR >> 4) & 0x1; // bit 36 + bool supercruise_on = (GET_BYTE(to_fwd, 4) & 0x10) != 0; // bit 36 if (!supercruise_on) { bus_fwd = -1; } diff --git a/board/safety/safety_honda.h b/board/safety/safety_honda.h index 44a57ec97..6179a5e37 100644 --- a/board/safety/safety_honda.h +++ b/board/safety/safety_honda.h @@ -10,7 +10,7 @@ const int HONDA_GAS_INTERCEPTOR_THRESHOLD = 328; // ratio between offset and gain from dbc file int honda_brake_prev = 0; int honda_gas_prev = 0; -int honda_ego_speed = 0; +bool honda_moving = false; bool honda_bosch_hardware = false; bool honda_alt_brake_msg = false; @@ -22,13 +22,13 @@ static void honda_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { // sample speed if (addr == 0x158) { // first 2 bytes - honda_ego_speed = to_push->RDLR & 0xFFFF; + honda_moving = GET_BYTE(to_push, 0) | GET_BYTE(to_push, 1); } // state machine to enter and exit controls // 0x1A6 for the ILX, 0x296 for the Civic Touring if ((addr == 0x1A6) || (addr == 0x296)) { - int button = (to_push->RDLR & 0xE0) >> 5; + int button = (GET_BYTE(to_push, 0) & 0xE0) >> 5; switch (button) { case 2: // cancel controls_allowed = 0; @@ -48,14 +48,11 @@ static void honda_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { // in these cases, this is used instead. // most hondas: 0x17C bit 53 // accord, crv: 0x1BE bit 4 - #define IS_USER_BRAKE_MSG(addr) (!honda_alt_brake_msg ? ((addr) == 0x17C) : ((addr) == 0x1BE)) - #define USER_BRAKE_VALUE(to_push) (!honda_alt_brake_msg ? ((to_push)->RDHR & 0x200000) : ((to_push)->RDLR & 0x10)) - // exit controls on rising edge of brake press or on brake press when - // speed > 0 - bool is_user_brake_msg = IS_USER_BRAKE_MSG(addr); // needed to enforce type + // exit controls on rising edge of brake press or on brake press when speed > 0 + bool is_user_brake_msg = honda_alt_brake_msg ? ((addr) == 0x1BE) : ((addr) == 0x17C); if (is_user_brake_msg) { - int brake = USER_BRAKE_VALUE(to_push); - if (brake && (!(honda_brake_prev) || honda_ego_speed)) { + int brake = honda_alt_brake_msg ? (GET_BYTE((to_push), 0) & 0x10) : (GET_BYTE((to_push), 6) & 0x20); + if (brake && (!(honda_brake_prev) || honda_moving)) { controls_allowed = 0; } honda_brake_prev = brake; @@ -65,7 +62,7 @@ static void honda_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { // length check because bosch hardware also uses this id (0x201 w/ len = 8) if ((addr == 0x201) && (len == 6)) { gas_interceptor_detected = 1; - int gas_interceptor = ((to_push->RDLR & 0xFF) << 8) | ((to_push->RDLR & 0xFF00) >> 8); + int gas_interceptor = GET_INTERCEPTOR(to_push); if ((gas_interceptor > HONDA_GAS_INTERCEPTOR_THRESHOLD) && (gas_interceptor_prev <= HONDA_GAS_INTERCEPTOR_THRESHOLD) && long_controls_allowed) { @@ -77,7 +74,7 @@ static void honda_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { // exit controls on rising edge of gas press if no interceptor if (!gas_interceptor_detected) { if (addr == 0x17C) { - int gas = to_push->RDLR & 0xFF; + int gas = GET_BYTE(to_push, 0); if (gas && !(honda_gas_prev) && long_controls_allowed) { controls_allowed = 0; } @@ -101,17 +98,18 @@ static int honda_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { // disallow actuator commands if gas or brake (with vehicle moving) are pressed // and the the latching controls_allowed flag is True int pedal_pressed = honda_gas_prev || (gas_interceptor_prev > HONDA_GAS_INTERCEPTOR_THRESHOLD) || - (honda_brake_prev && honda_ego_speed); + (honda_brake_prev && honda_moving); bool current_controls_allowed = controls_allowed && !(pedal_pressed); // BRAKE: safety check if (addr == 0x1FA) { + int brake = (GET_BYTE(to_send, 0) << 2) + (GET_BYTE(to_send, 1) & 0x3); if (!current_controls_allowed || !long_controls_allowed) { - if ((to_send->RDLR & 0xFFFF0000) != to_send->RDLR) { + if (brake != 0) { tx = 0; } } - if ((to_send->RDLR & 0xFFFFFF3F) != to_send->RDLR) { + if (brake > 255) { tx = 0; } } @@ -119,7 +117,8 @@ static int honda_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { // STEER: safety check if ((addr == 0xE4) || (addr == 0x194)) { if (!current_controls_allowed) { - if ((to_send->RDLR & 0xFFFF0000) != to_send->RDLR) { + bool steer_applied = GET_BYTE(to_send, 0) | GET_BYTE(to_send, 1); + if (steer_applied) { tx = 0; } } @@ -128,7 +127,7 @@ static int honda_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { // GAS: safety check if (addr == 0x200) { if (!current_controls_allowed || !long_controls_allowed) { - if ((to_send->RDLR & 0xFFFF0000) != to_send->RDLR) { + if (GET_BYTE(to_send, 0) || GET_BYTE(to_send, 1)) { tx = 0; } } @@ -139,7 +138,7 @@ static int honda_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { // This avoids unintended engagements while still allowing resume spam if ((addr == 0x296) && honda_bosch_hardware && !current_controls_allowed && (bus == 0)) { - if (((to_send->RDLR >> 5) & 0x7) != 2) { + if (((GET_BYTE(to_send, 0) >> 5) & 0x7) != 2) { tx = 0; } } diff --git a/board/safety/safety_hyundai.h b/board/safety/safety_hyundai.h index c1b55359b..aed30621f 100644 --- a/board/safety/safety_hyundai.h +++ b/board/safety/safety_hyundai.h @@ -20,7 +20,7 @@ static void hyundai_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { int addr = GET_ADDR(to_push); if (addr == 897) { - int torque_driver_new = ((to_push->RDLR >> 11) & 0xfff) - 2048; + int torque_driver_new = ((GET_BYTES_04(to_push) >> 11) & 0xfff) - 2048; // update array of samples update_sample(&hyundai_torque_driver, torque_driver_new); } @@ -39,7 +39,7 @@ static void hyundai_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { // enter controls on rising edge of ACC, exit controls on ACC off if (addr == 1057) { // 2 bits: 13-14 - int cruise_engaged = (to_push->RDLR >> 13) & 0x3; + int cruise_engaged = (GET_BYTES_04(to_push) >> 13) & 0x3; if (cruise_engaged && !hyundai_cruise_engaged_last) { controls_allowed = 1; } @@ -67,7 +67,7 @@ static int hyundai_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { // LKA STEER: safety check if (addr == 832) { - int desired_torque = ((to_send->RDLR >> 16) & 0x7ff) - 1024; + int desired_torque = ((GET_BYTES_04(to_send) >> 16) & 0x7ff) - 1024; uint32_t ts = TIM2->CNT; bool violation = 0; @@ -117,7 +117,7 @@ static int hyundai_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { // This avoids unintended engagements while still allowing resume spam // TODO: fix bug preventing the button msg to be fwd'd on bus 2 //if ((addr == 1265) && !controls_allowed && (bus == 0) { - // if ((to_send->RDLR & 0x7) != 4) { + // if ((GET_BYTES_04(to_send) & 0x7) != 4) { // tx = 0; // } //} diff --git a/board/safety/safety_subaru.h b/board/safety/safety_subaru.h index c7a8c20e5..3eda8369b 100644 --- a/board/safety/safety_subaru.h +++ b/board/safety/safety_subaru.h @@ -20,7 +20,7 @@ static void subaru_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { int addr = GET_ADDR(to_push); if ((addr == 0x119) && (bus == 0)){ - int torque_driver_new = ((to_push->RDLR >> 16) & 0x7FF); + int torque_driver_new = ((GET_BYTES_04(to_push) >> 16) & 0x7FF); torque_driver_new = to_signed(torque_driver_new, 11); // update array of samples update_sample(&subaru_torque_driver, torque_driver_new); @@ -28,7 +28,7 @@ static void subaru_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { // enter controls on rising edge of ACC, exit controls on ACC off if ((addr == 0x240) && (bus == 0)) { - int cruise_engaged = (to_push->RDHR >> 9) & 1; + int cruise_engaged = GET_BYTE(to_push, 5) & 2; if (cruise_engaged && !subaru_cruise_engaged_last) { controls_allowed = 1; } @@ -45,7 +45,7 @@ static int subaru_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { // steer cmd checks if (addr == 0x122) { - int desired_torque = ((to_send->RDLR >> 16) & 0x1FFF); + int desired_torque = ((GET_BYTES_04(to_send) >> 16) & 0x1FFF); bool violation = 0; uint32_t ts = TIM2->CNT; desired_torque = to_signed(desired_torque, 13); diff --git a/board/safety/safety_tesla.h b/board/safety/safety_tesla.h index b58e6b2bb..188b12ac4 100644 --- a/board/safety/safety_tesla.h +++ b/board/safety/safety_tesla.h @@ -55,7 +55,7 @@ static void tesla_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { if (addr == 0x45) { // 6 bits starting at position 0 - int lever_position = (to_push->RDLR & 0x3F); + int lever_position = GET_BYTE(to_push, 0) & 0x3F; if (lever_position == 2) { // pull forward // activate openpilot controls_allowed = 1; @@ -69,7 +69,7 @@ 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 = (to_push->RDLR & 0x0001); + int drive_rail_on = GET_BYTE(to_push, 0) & 0x1; tesla_ignition_started = drive_rail_on == 1; } @@ -77,12 +77,12 @@ static void tesla_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { // DI_torque2::DI_brakePedal 0x118 if (addr == 0x118) { // 1 bit at position 16 - if ((((to_push->RDLR & 0x8000)) >> 15) == 1) { + if ((GET_BYTE(to_push, 1) & 0x80) != 0) { // disable break cancel by commenting line below controls_allowed = 0; } //get vehicle speed in m/s. Tesla gives MPH - tesla_speed = ((((((to_push->RDLR >> 24) & 0xF) << 8) + ((to_push->RDLR >> 16) & 0xFF)) * 0.05) - 25) * 1.609 / 3.6; + tesla_speed = (((((GET_BYTE(to_push, 3) & 0xF) << 8) + GET_BYTE(to_push, 2)) * 0.05) - 25) * 1.609 / 3.6; if (tesla_speed < 0) { tesla_speed = 0; } @@ -92,7 +92,7 @@ static void tesla_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { // EPAS_sysStatus::EPAS_eacStatus 0x370 if (addr == 0x370) { // if EPAS_eacStatus is not 1 or 2, disable control - eac_status = ((to_push->RDHR >> 21)) & 0x7; + eac_status = (GET_BYTE(to_push, 6) >> 5) & 0x7; // For human steering override we must not disable controls when eac_status == 0 // Additional safety: we could only allow eac_status == 0 when we have human steering allowed if (controls_allowed && (eac_status != 0) && (eac_status != 1) && (eac_status != 2)) { @@ -102,7 +102,7 @@ static void tesla_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { } //get latest steering wheel angle if (addr == 0x00E) { - float angle_meas_now = (int)(((((to_push->RDLR & 0x3F) << 8) + ((to_push->RDLR >> 8) & 0xFF)) * 0.1) - 819.2); + float angle_meas_now = (int)(((((GET_BYTE(to_push, 0) & 0x3F) << 8) + GET_BYTE(to_push, 1)) * 0.1) - 819.2); uint32_t ts = TIM2->CNT; uint32_t ts_elapsed = get_ts_elapsed(ts, tesla_ts_angle_last); @@ -146,10 +146,10 @@ static int tesla_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { // do not transmit CAN message if steering angle too high // DAS_steeringControl::DAS_steeringAngleRequest if (addr == 0x488) { - float angle_raw = ((to_send->RDLR & 0x7F) << 8) + ((to_send->RDLR & 0xFF00) >> 8); + float angle_raw = ((GET_BYTE(to_send, 0) & 0x7F) << 8) + GET_BYTE(to_send, 1); float desired_angle = (angle_raw * 0.1) - 1638.35; bool violation = 0; - int st_enabled = (to_send->RDLR & 0x400000) >> 22; + int st_enabled = GET_BYTE(to_send, 2) & 0x40; if (st_enabled == 0) { //steering is not enabled, do not check angles and do send @@ -204,10 +204,10 @@ static int tesla_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) { bus_fwd = 2; // Custom EPAS bus } if (addr == 0x101) { - to_fwd->RDLR = to_fwd->RDLR | 0x4000; // 0x4000: WITH_ANGLE, 0xC000: WITH_BOTH (angle and torque) - uint32_t checksum = (((to_fwd->RDLR & 0xFF00) >> 8) + (to_fwd->RDLR & 0xFF) + 2) & 0xFF; - to_fwd->RDLR = to_fwd->RDLR & 0xFFFF; - to_fwd->RDLR = to_fwd->RDLR + (checksum << 16); + to_fwd->RDLR = GET_BYTES_04(to_fwd) | 0x4000; // 0x4000: WITH_ANGLE, 0xC000: WITH_BOTH (angle and torque) + uint32_t checksum = (GET_BYTE(to_fwd, 1) + GET_BYTE(to_fwd, 0) + 2) & 0xFF; + to_fwd->RDLR = GET_BYTES_04(to_fwd) & 0xFFFF; + to_fwd->RDLR = GET_BYTES_04(to_fwd) + (checksum << 16); } } if (bus_num == 2) { diff --git a/board/safety/safety_toyota.h b/board/safety/safety_toyota.h index c4d579563..c1ce99605 100644 --- a/board/safety/safety_toyota.h +++ b/board/safety/safety_toyota.h @@ -39,7 +39,7 @@ static void toyota_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { // get eps motor torque (0.66 factor in dbc) if (addr == 0x260) { - int torque_meas_new = (((to_push->RDHR) & 0xFF00) | ((to_push->RDHR >> 16) & 0xFF)); + int torque_meas_new = (GET_BYTE(to_push, 5) << 8) | GET_BYTE(to_push, 6); torque_meas_new = to_signed(torque_meas_new, 16); // scale by dbc_factor @@ -56,7 +56,7 @@ static void toyota_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { // enter controls on rising edge of ACC, exit controls on ACC off if (addr == 0x1D2) { // 5th bit is CRUISE_ACTIVE - int cruise_engaged = to_push->RDLR & 0x20; + int cruise_engaged = GET_BYTE(to_push, 0) & 0x20; if (!cruise_engaged) { controls_allowed = 0; } @@ -69,7 +69,7 @@ static void toyota_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { // exit controls on rising edge of interceptor gas press if (addr == 0x201) { gas_interceptor_detected = 1; - int gas_interceptor = ((to_push->RDLR & 0xFF) << 8) | ((to_push->RDLR & 0xFF00) >> 8); + int gas_interceptor = GET_INTERCEPTOR(to_push); if ((gas_interceptor > TOYOTA_GAS_INTERCEPTOR_THRESHOLD) && (gas_interceptor_prev <= TOYOTA_GAS_INTERCEPTOR_THRESHOLD) && long_controls_allowed) { @@ -80,7 +80,7 @@ static void toyota_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { // exit controls on rising edge of gas press if (addr == 0x2C1) { - int gas = (to_push->RDHR >> 16) & 0xFF; + int gas = GET_BYTE(to_push, 6) & 0xFF; if ((gas > 0) && (toyota_gas_prev == 0) && !gas_interceptor_detected && long_controls_allowed) { controls_allowed = 0; } @@ -115,7 +115,7 @@ static int toyota_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { // GAS PEDAL: safety check if (addr == 0x200) { if (!controls_allowed || !long_controls_allowed) { - if ((to_send->RDLR & 0xFFFF0000) != to_send->RDLR) { + if (GET_BYTE(to_send, 0) || GET_BYTE(to_send, 1)) { tx = 0; } } @@ -123,7 +123,7 @@ static int toyota_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { // ACCEL: safety check on byte 1-2 if (addr == 0x343) { - int desired_accel = ((to_send->RDLR & 0xFF) << 8) | ((to_send->RDLR >> 8) & 0xFF); + int desired_accel = (GET_BYTE(to_send, 0) << 8) | GET_BYTE(to_send, 1); desired_accel = to_signed(desired_accel, 16); if (!controls_allowed || !long_controls_allowed) { if (desired_accel != 0) { @@ -138,7 +138,7 @@ static int toyota_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { // STEER: safety check on bytes 2-3 if (addr == 0x2E4) { - int desired_torque = (to_send->RDLR & 0xFF00) | ((to_send->RDLR >> 16) & 0xFF); + int desired_torque = (GET_BYTE(to_send, 1) << 8) | GET_BYTE(to_send, 2); desired_torque = to_signed(desired_torque, 16); bool violation = 0; diff --git a/board/safety/safety_toyota_ipas.h b/board/safety/safety_toyota_ipas.h index 99e6dae05..3e3a3b3a2 100644 --- a/board/safety/safety_toyota_ipas.h +++ b/board/safety/safety_toyota_ipas.h @@ -39,7 +39,7 @@ static void toyota_ipas_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { if (addr == 0x260) { // get driver steering torque - int16_t torque_driver_new = (((to_push->RDLR) & 0xFF00) | ((to_push->RDLR >> 16) & 0xFF)); + int16_t torque_driver_new = (GET_BYTE(to_push, 1) << 8) | GET_BYTE(to_push, 2); // update array of samples update_sample(&torque_driver, torque_driver_new); @@ -47,7 +47,7 @@ static void toyota_ipas_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { // get steer angle if (addr == 0x25) { - int angle_meas_new = ((to_push->RDLR & 0xf) << 8) + ((to_push->RDLR & 0xff00) >> 8); + int angle_meas_new = ((GET_BYTE(to_push, 0) & 0xF) << 8) | GET_BYTE(to_push, 1); uint32_t ts = TIM2->CNT; angle_meas_new = to_signed(angle_meas_new, 12); @@ -81,12 +81,12 @@ static void toyota_ipas_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { // get speed if (addr == 0xb4) { - speed = ((float) (((to_push->RDHR) & 0xFF00) | ((to_push->RDHR >> 16) & 0xFF))) * 0.01 / 3.6; + speed = ((float)((GET_BYTE(to_push, 5) << 8) | GET_BYTE(to_push, 6))) * 0.01 / 3.6; } // get ipas state if (addr == 0x262) { - ipas_state = (to_push->RDLR & 0xf); + ipas_state = GET_BYTE(to_push, 0) & 0xf; } // exit controls on high steering override @@ -111,8 +111,8 @@ static int toyota_ipas_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { if ((addr == 0x266) || (addr == 0x167)) { angle_control = 1; // we are in angle control mode - int desired_angle = ((to_send->RDLR & 0xf) << 8) + ((to_send->RDLR & 0xff00) >> 8); - int ipas_state_cmd = ((to_send->RDLR & 0xff) >> 4); + int desired_angle = ((GET_BYTE(to_send, 0) & 0xF) << 8) | GET_BYTE(to_send, 1); + int ipas_state_cmd = GET_BYTE(to_send, 0) >> 4; bool violation = 0; desired_angle = to_signed(desired_angle, 12); diff --git a/board/safety_declarations.h b/board/safety_declarations.h index 21e863869..7e0a54d73 100644 --- a/board/safety_declarations.h +++ b/board/safety_declarations.h @@ -1,7 +1,3 @@ -#define GET_BUS(msg) (((msg)->RDTR >> 4) & 0xFF) -#define GET_LEN(msg) ((msg)->RDTR & 0xf) -#define GET_ADDR(msg) ((((msg)->RIR & 4) != 0) ? ((msg)->RIR >> 3) : ((msg)->RIR >> 21)) - // sample struct that keeps 3 samples in memory struct sample_t { int values[6]; @@ -54,3 +50,6 @@ int gas_interceptor_prev = 0; // This is set by USB command 0xdf bool long_controls_allowed = 1; + +// avg between 2 tracks +#define GET_INTERCEPTOR(msg) (((GET_BYTE((msg), 0) << 8) + GET_BYTE((msg), 1) + ((GET_BYTE((msg), 2) << 8) + GET_BYTE((msg), 3)) / 2 ) / 2) diff --git a/board/spi_flasher.h b/board/spi_flasher.h index 94d41c7e3..aacea822c 100644 --- a/board/spi_flasher.h +++ b/board/spi_flasher.h @@ -92,16 +92,26 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired) return resp_len; } -int usb_cb_ep1_in(uint8_t *usbdata, int len, bool hardwired) { return 0; } -void usb_cb_ep3_out(uint8_t *usbdata, int len, bool hardwired) { } +int usb_cb_ep1_in(void *usbdata, int len, bool hardwired) { + UNUSED(usbdata); + UNUSED(len); + UNUSED(hardwired); + return 0; +} +void usb_cb_ep3_out(void *usbdata, int len, bool hardwired) { + UNUSED(usbdata); + UNUSED(len); + UNUSED(hardwired); +} int is_enumerated = 0; -void usb_cb_enumeration_complete() { +void usb_cb_enumeration_complete(void) { puts("USB enumeration complete\n"); is_enumerated = 1; } -void usb_cb_ep2_out(uint8_t *usbdata, int len, bool hardwired) { +void usb_cb_ep2_out(void *usbdata, int len, bool hardwired) { + UNUSED(hardwired); set_led(LED_RED, 0); for (int i = 0; i < len/4; i++) { // program byte 1 @@ -118,6 +128,7 @@ void usb_cb_ep2_out(uint8_t *usbdata, int len, bool hardwired) { int spi_cb_rx(uint8_t *data, int len, uint8_t *data_out) { + UNUSED(len); int resp_len = 0; switch (data[0]) { case 0: @@ -140,7 +151,7 @@ int spi_cb_rx(uint8_t *data, int len, uint8_t *data_out) { #define CAN_BL_INPUT 0x1 #define CAN_BL_OUTPUT 0x2 -void CAN1_TX_IRQHandler() { +void CAN1_TX_IRQHandler(void) { // clear interrupt CAN->TSR |= CAN_TSR_RQCP0; } @@ -167,12 +178,13 @@ void bl_can_send(uint8_t *odat) { CAN->sTxMailBox[0].TIR = (CAN_BL_OUTPUT << 21) | 1; } -void CAN1_RX0_IRQHandler() { +void CAN1_RX0_IRQHandler(void) { while (CAN->RF0R & CAN_RF0R_FMP0) { if ((CAN->sFIFOMailBox[0].RIR>>21) == CAN_BL_INPUT) { uint8_t dat[8]; - ((uint32_t*)dat)[0] = CAN->sFIFOMailBox[0].RDLR; - ((uint32_t*)dat)[1] = CAN->sFIFOMailBox[0].RDHR; + for (int i = 0; i < 8; i++) { + dat[0] = GET_BYTE(&CAN->sFIFOMailBox[0], i); + } uint8_t odat[8]; uint8_t type = dat[0] & 0xF0; if (type == 0x30) { @@ -241,13 +253,13 @@ void CAN1_RX0_IRQHandler() { } } -void CAN1_SCE_IRQHandler() { +void CAN1_SCE_IRQHandler(void) { llcan_clear_send(CAN); } #endif -void soft_flasher_start() { +void soft_flasher_start(void) { puts("\n\n\n************************ FLASHER START ************************\n"); enter_bootloader_mode = 0; diff --git a/board/startup_stm32f205xx.s b/board/startup_stm32f205xx.s index f4b6c6cb7..7554efc4c 100644 --- a/board/startup_stm32f205xx.s +++ b/board/startup_stm32f205xx.s @@ -4,7 +4,7 @@ * @author MCD Application Team * @version V2.1.2 * @date 29-June-2016 - * @brief STM32F205xx Devices vector table for Atollic TrueSTUDIO toolchain. + * @brief STM32F205xx Devices vector table for Atollic TrueSTUDIO toolchain. * This module performs: * - Set the initial SP * - Set the initial PC == Reset_Handler, @@ -42,7 +42,7 @@ * ****************************************************************************** */ - + .syntax unified .cpu cortex-m3 .thumb @@ -50,10 +50,10 @@ .global g_pfnVectors .global Default_Handler -/* start address for the initialization values of the .data section. +/* start address for the initialization values of the .data section. defined in linker script */ .word _sidata -/* start address for the .data section. defined in linker script */ +/* start address for the .data section. defined in linker script */ .word _sdata /* end address for the .data section. defined in linker script */ .word _edata @@ -67,7 +67,7 @@ defined in linker script */ * @brief This is the code that gets called when the processor first * starts execution following a reset event. Only the absolutely * necessary set is performed, after which the application - * supplied main() routine is called. + * supplied main() routine is called. * @param None * @retval : None */ @@ -75,7 +75,7 @@ defined in linker script */ .section .text.Reset_Handler .weak Reset_Handler .type Reset_Handler, %function -Reset_Handler: +Reset_Handler: ldr sp, =_estack /* set stack pointer */ bl __initialize_hardware_early @@ -88,7 +88,7 @@ CopyDataInit: ldr r3, [r3, r1] str r3, [r0, r1] adds r1, r1, #4 - + LoopCopyDataInit: ldr r0, =_sdata ldr r3, =_edata @@ -101,7 +101,7 @@ LoopCopyDataInit: FillZerobss: movs r3, #0 str r3, [r2], #4 - + LoopFillZerobss: ldr r3, = _ebss cmp r2, r3 @@ -113,15 +113,15 @@ LoopFillZerobss: /*bl __libc_init_array*/ /* Call the application's entry point.*/ bl main - bx lr + bx lr .size Reset_Handler, .-Reset_Handler /** - * @brief This is the code that gets called when the processor receives an + * @brief This is the code that gets called when the processor receives an * unexpected interrupt. This simply enters an infinite loop, preserving * the system state for examination by a debugger. - * @param None - * @retval None + * @param None + * @retval None */ .section .text.Default_Handler,"ax",%progbits Default_Handler: @@ -133,14 +133,14 @@ Infinite_Loop: * The minimal vector table for a Cortex M3. Note that the proper constructs * must be placed on this to ensure that it ends up at physical address * 0x0000.0000. -* +* *******************************************************************************/ .section .isr_vector,"a",%progbits .type g_pfnVectors, %object .size g_pfnVectors, .-g_pfnVectors - - + + g_pfnVectors: .word _estack .word Reset_Handler @@ -159,7 +159,7 @@ g_pfnVectors: .word 0 .word PendSV_Handler .word SysTick_Handler - + /* External Interrupts */ .word WWDG_IRQHandler /* Window WatchDog */ .word PVD_IRQHandler /* PVD through EXTI Line detection */ @@ -248,7 +248,7 @@ g_pfnVectors: * Provide weak aliases for each Exception handler to the Default_Handler. * As they are weak aliases, any function with the same name will override * this definition. -* +* *******************************************************************************/ .weak NMI_Handler .thumb_set NMI_Handler,Default_Handler @@ -302,7 +302,7 @@ g_pfnVectors: .thumb_set EXTI1_IRQHandler,Default_Handler .weak EXTI2_IRQHandler - .thumb_set EXTI2_IRQHandler,Default_Handler + .thumb_set EXTI2_IRQHandler,Default_Handler .weak EXTI3_IRQHandler .thumb_set EXTI3_IRQHandler,Default_Handler @@ -320,7 +320,7 @@ g_pfnVectors: .thumb_set DMA1_Stream2_IRQHandler,Default_Handler .weak DMA1_Stream3_IRQHandler - .thumb_set DMA1_Stream3_IRQHandler,Default_Handler + .thumb_set DMA1_Stream3_IRQHandler,Default_Handler .weak DMA1_Stream4_IRQHandler .thumb_set DMA1_Stream4_IRQHandler,Default_Handler @@ -432,7 +432,7 @@ g_pfnVectors: .weak SPI3_IRQHandler .thumb_set SPI3_IRQHandler,Default_Handler - + .weak UART4_IRQHandler .thumb_set UART4_IRQHandler,Default_Handler diff --git a/board/startup_stm32f413xx.s b/board/startup_stm32f413xx.s index 00b645d11..6e6fb5ffa 100644 --- a/board/startup_stm32f413xx.s +++ b/board/startup_stm32f413xx.s @@ -4,7 +4,7 @@ * @author MCD Application Team * @version V2.6.0 * @date 04-November-2016 - * @brief STM32F413xx Devices vector table for GCC based toolchains. + * @brief STM32F413xx Devices vector table for GCC based toolchains. * This module performs: * - Set the initial SP * - Set the initial PC == Reset_Handler, @@ -42,7 +42,7 @@ * ****************************************************************************** */ - + .syntax unified .cpu cortex-m4 .fpu softvfp @@ -51,7 +51,7 @@ .global g_pfnVectors .global Default_Handler -/* start address for the initialization values of the .data section. +/* start address for the initialization values of the .data section. defined in linker script */ .word _sidata /* start address for the .data section. defined in linker script */ @@ -68,7 +68,7 @@ defined in linker script */ * @brief This is the code that gets called when the processor first * starts execution following a reset event. Only the absolutely * necessary set is performed, after which the application - * supplied main() routine is called. + * supplied main() routine is called. * @param None * @retval : None */ @@ -76,7 +76,7 @@ defined in linker script */ .section .text.Reset_Handler .weak Reset_Handler .type Reset_Handler, %function -Reset_Handler: +Reset_Handler: ldr sp, =_estack /* set stack pointer */ bl __initialize_hardware_early @@ -89,7 +89,7 @@ CopyDataInit: ldr r3, [r3, r1] str r3, [r0, r1] adds r1, r1, #4 - + LoopCopyDataInit: ldr r0, =_sdata ldr r3, =_edata @@ -102,7 +102,7 @@ LoopCopyDataInit: FillZerobss: movs r3, #0 str r3, [r2], #4 - + LoopFillZerobss: ldr r3, = _ebss cmp r2, r3 @@ -114,15 +114,15 @@ LoopFillZerobss: /* bl __libc_init_array */ /* Call the application's entry point.*/ bl main - bx lr + bx lr .size Reset_Handler, .-Reset_Handler /** - * @brief This is the code that gets called when the processor receives an + * @brief This is the code that gets called when the processor receives an * unexpected interrupt. This simply enters an infinite loop, preserving * the system state for examination by a debugger. - * @param None - * @retval None + * @param None + * @retval None */ .section .text.Default_Handler,"ax",%progbits Default_Handler: @@ -134,12 +134,12 @@ Infinite_Loop: * The minimal vector table for a Cortex M3. Note that the proper constructs * must be placed on this to ensure that it ends up at physical address * 0x0000.0000. -* +* *******************************************************************************/ .section .isr_vector,"a",%progbits .type g_pfnVectors, %object .size g_pfnVectors, .-g_pfnVectors - + g_pfnVectors: .word _estack .word Reset_Handler @@ -261,11 +261,11 @@ g_pfnVectors: .word DFSDM2_FLT1_IRQHandler /* DFSDM2 Filter1 */ .word DFSDM2_FLT2_IRQHandler /* DFSDM2 Filter2 */ .word DFSDM2_FLT3_IRQHandler /* DFSDM2 Filter3 */ - + /******************************************************************************* * -* Provide weak aliases for each Exception handler to the Default_Handler. -* As they are weak aliases, any function with the same name will override +* Provide weak aliases for each Exception handler to the Default_Handler. +* As they are weak aliases, any function with the same name will override * this definition. * *******************************************************************************/ @@ -277,7 +277,7 @@ g_pfnVectors: .weak MemManage_Handler .thumb_set MemManage_Handler,Default_Handler - + .weak BusFault_Handler .thumb_set BusFault_Handler,Default_Handler @@ -321,7 +321,7 @@ g_pfnVectors: .thumb_set EXTI1_IRQHandler,Default_Handler .weak EXTI2_IRQHandler - .thumb_set EXTI2_IRQHandler,Default_Handler + .thumb_set EXTI2_IRQHandler,Default_Handler .weak EXTI3_IRQHandler .thumb_set EXTI3_IRQHandler,Default_Handler @@ -439,9 +439,9 @@ g_pfnVectors: .weak DMA1_Stream7_IRQHandler .thumb_set DMA1_Stream7_IRQHandler,Default_Handler - + .weak FSMC_IRQHandler - .thumb_set FSMC_IRQHandler,Default_Handler + .thumb_set FSMC_IRQHandler,Default_Handler .weak SDIO_IRQHandler .thumb_set SDIO_IRQHandler,Default_Handler @@ -451,12 +451,12 @@ g_pfnVectors: .weak SPI3_IRQHandler .thumb_set SPI3_IRQHandler,Default_Handler - + .weak UART4_IRQHandler .thumb_set UART4_IRQHandler,Default_Handler .weak UART5_IRQHandler - .thumb_set UART5_IRQHandler,Default_Handler + .thumb_set UART5_IRQHandler,Default_Handler .weak TIM6_DAC_IRQHandler .thumb_set TIM6_DAC_IRQHandler,Default_Handler @@ -517,7 +517,7 @@ g_pfnVectors: .weak I2C3_ER_IRQHandler .thumb_set I2C3_ER_IRQHandler,Default_Handler - + .weak CAN3_TX_IRQHandler .thumb_set CAN3_TX_IRQHandler,Default_Handler @@ -528,26 +528,26 @@ g_pfnVectors: .thumb_set CAN3_RX1_IRQHandler,Default_Handler .weak CAN3_SCE_IRQHandler - .thumb_set CAN3_SCE_IRQHandler,Default_Handler + .thumb_set CAN3_SCE_IRQHandler,Default_Handler .weak RNG_IRQHandler .thumb_set RNG_IRQHandler,Default_Handler .weak FPU_IRQHandler .thumb_set FPU_IRQHandler,Default_Handler - + .weak UART7_IRQHandler .thumb_set UART7_IRQHandler,Default_Handler .weak UART8_IRQHandler - .thumb_set UART8_IRQHandler,Default_Handler + .thumb_set UART8_IRQHandler,Default_Handler .weak SPI4_IRQHandler .thumb_set SPI4_IRQHandler,Default_Handler .weak SPI5_IRQHandler .thumb_set SPI5_IRQHandler,Default_Handler - + .weak SAI1_IRQHandler .thumb_set SAI1_IRQHandler,Default_Handler @@ -555,7 +555,7 @@ g_pfnVectors: .thumb_set UART9_IRQHandler,Default_Handler .weak UART10_IRQHandler - .thumb_set UART10_IRQHandler,Default_Handler + .thumb_set UART10_IRQHandler,Default_Handler .weak QUADSPI_IRQHandler .thumb_set QUADSPI_IRQHandler,Default_Handler @@ -565,7 +565,7 @@ g_pfnVectors: .weak FMPI2C1_ER_IRQHandler .thumb_set FMPI2C1_ER_IRQHandler,Default_Handler - + .weak LPTIM1_IRQHandler .thumb_set LPTIM1_IRQHandler,Default_Handler diff --git a/boardesp/webserver.c b/boardesp/webserver.c index f855f88c9..65e025882 100644 --- a/boardesp/webserver.c +++ b/boardesp/webserver.c @@ -84,7 +84,7 @@ int ICACHE_FLASH_ATTR usb_cmd(int ep, int len, int request, return recv[0]; } - + void ICACHE_FLASH_ATTR st_flash() { if (st_firmware != NULL) { @@ -212,14 +212,14 @@ static void ICACHE_FLASH_ATTR web_rx_cb(void *arg, char *data, uint16_t len) { } else { ets_strcat(resp, "\nin INSECURE mode...secure it"); } - + ets_strcat(resp,"\nSet USB Mode:" "" "" "\n"); ets_strcat(resp, pagefooter); - + espconn_send_string(&web_conn, resp); espconn_disconnect(conn); } else if (memcmp(data, "GET /secure", 11) == 0 && !wifi_secure_mode) { @@ -235,7 +235,7 @@ static void ICACHE_FLASH_ATTR web_rx_cb(void *arg, char *data, uint16_t len) { os_sprintf(resp, "%sUSB Mode set to %02x\n\n", OK_header, mode_value); espconn_send_string(&web_conn, resp); espconn_disconnect(conn); - } + } } else if (memcmp(data, "PUT /stupdate ", 14) == 0 && wifi_secure_mode) { os_printf("init st firmware\n"); char *cl = strstr(data, "Content-Length: "); @@ -251,7 +251,7 @@ static void ICACHE_FLASH_ATTR web_rx_cb(void *arg, char *data, uint16_t len) { memset(st_firmware, 0, real_content_length); state = RECEIVING_ST_FIRMWARE; } - + } else if (((memcmp(data, "PUT /espupdate1 ", 16) == 0) || (memcmp(data, "PUT /espupdate2 ", 16) == 0)) && wifi_secure_mode) { // 0x1000 = user1.bin diff --git a/crypto/sha.c b/crypto/sha.c index 8e1715525..a13162c5f 100644 --- a/crypto/sha.c +++ b/crypto/sha.c @@ -130,7 +130,7 @@ const uint8_t* SHA_final(SHA_CTX* ctx) { /* Hack - right shift operator with non const argument requires * libgcc.a which is missing in EON - * thus expanding for loop from + * thus expanding for loop from for (i = 0; i < 8; ++i) { uint8_t tmp = (uint8_t) (cnt >> ((7 - i) * 8)); diff --git a/drivers/windows/pandaJ2534DLL/PandaJ2534Device.cpp b/drivers/windows/pandaJ2534DLL/PandaJ2534Device.cpp index 4cda1fa2e..19ae43b0d 100644 --- a/drivers/windows/pandaJ2534DLL/PandaJ2534Device.cpp +++ b/drivers/windows/pandaJ2534DLL/PandaJ2534Device.cpp @@ -93,7 +93,7 @@ DWORD PandaJ2534Device::can_process_thread() { if (count == 0) { continue; } - + for (int i = 0; i < count; i++) { auto msg_in = msg_recv[i]; J2534Frame msg_out(msg_in); diff --git a/drivers/windows/pandaJ2534DLL/resource.h b/drivers/windows/pandaJ2534DLL/resource.h index 771e7b80b..af0e13cc0 100644 --- a/drivers/windows/pandaJ2534DLL/resource.h +++ b/drivers/windows/pandaJ2534DLL/resource.h @@ -3,7 +3,7 @@ // Used by pandaJ2534DLL.rc // Next default values for new objects -// +// #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 101 diff --git a/examples/can_unique.md b/examples/can_unique.md index bf316940d..4d8ac460e 100644 --- a/examples/can_unique.md +++ b/examples/can_unique.md @@ -10,8 +10,8 @@ First record a few minutes of background CAN messages with all the doors closed ./can_logger.py mv output.csv background.csv ``` -Then run can_logger.py for a few seconds while performing the action you're interested, such as opening and then closing the -front-left door and save it as door-fl-1.csv +Then run can_logger.py for a few seconds while performing the action you're interested, such as opening and then closing the +front-left door and save it as door-fl-1.csv Repeat the process and save it as door-f1-2.csv to have an easy way to confirm any suspicions. Now we'll use can_unique.py to look for unique bits: diff --git a/examples/get_panda_password.py b/examples/get_panda_password.py index 11071d035..575cbb079 100644 --- a/examples/get_panda_password.py +++ b/examples/get_panda_password.py @@ -2,11 +2,11 @@ from panda import Panda def get_panda_password(): - + try: print("Trying to connect to Panda over USB...") p = Panda() - + except AssertionError: print("USB connection failed") sys.exit(0) @@ -15,6 +15,6 @@ def get_panda_password(): #print('[%s]' % ', '.join(map(str, wifi))) print("SSID: " + wifi[0]) print("Password: " + wifi[1]) - + if __name__ == "__main__": get_panda_password() \ No newline at end of file diff --git a/examples/tesla_tester.py b/examples/tesla_tester.py index 99d8d9285..4365e424b 100644 --- a/examples/tesla_tester.py +++ b/examples/tesla_tester.py @@ -4,14 +4,14 @@ import binascii from panda import Panda def tesla_tester(): - + try: print("Trying to connect to Panda over USB...") p = Panda() - + except AssertionError: print("USB connection failed. Trying WiFi...") - + try: p = Panda("WIFI") except: @@ -21,12 +21,12 @@ def tesla_tester(): body_bus_speed = 125 # Tesla Body busses (B, BF) are 125kbps, rest are 500kbps body_bus_num = 1 # My TDC to OBD adapter has PT on bus0 BDY on bus1 and CH on bus2 p.set_can_speed_kbps(body_bus_num, body_bus_speed) - + # Now set the panda from its default of SAFETY_NOOUTPUT (read only) to SAFETY_ALLOUTPUT # Careful, as this will let us send any CAN messages we want (which could be very bad!) print("Setting Panda to output mode...") p.set_safety_mode(Panda.SAFETY_ALLOUTPUT) - + # 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) @@ -34,13 +34,13 @@ def tesla_tester(): #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) - + #Back to safety... print("Disabling output on Panda...") p.set_safety_mode(Panda.SAFETY_NOOUTPUT) - + print("Reading VIN from 0x568. This is painfully slow and can take up to 3 minutes (1 minute per message; 3 messages needed for full VIN)...") - + vin = {} while True: #Read the VIN diff --git a/python/esptool.py b/python/esptool.py index e68e6cd6e..970aa3d4d 100755 --- a/python/esptool.py +++ b/python/esptool.py @@ -1216,7 +1216,7 @@ def main(): operation_func = globals()[args.operation] operation_args,_,_,_ = inspect.getargspec(operation_func) if operation_args[0] == 'esp': # operation function takes an ESPROM connection object - initial_baud = MIN(ESPROM.ESP_ROM_BAUD, args.baud) # don't sync faster than the default baud rate + initial_baud = min(ESPROM.ESP_ROM_BAUD, args.baud) # don't sync faster than the default baud rate esp = ESPROM(args.port, initial_baud) esp.connect() operation_func(esp, args) diff --git a/python/flash_release.py b/python/flash_release.py index 51f6a72e7..0f407ff22 100755 --- a/python/flash_release.py +++ b/python/flash_release.py @@ -89,7 +89,7 @@ def flash_release(path=None, st_serial=None): # done! status("6. Success!") - + if __name__ == "__main__": flash_release(*sys.argv[1:]) diff --git a/python/isotp.py b/python/isotp.py index d68aa4d70..971827007 100644 --- a/python/isotp.py +++ b/python/isotp.py @@ -29,7 +29,7 @@ def recv(panda, cnt, addr, nbus): def isotp_recv_subaddr(panda, addr, bus, sendaddr, subaddr): msg = recv(panda, 1, addr, bus)[0] - # TODO: handle other subaddr also communicating + # TODO: handle other subaddr also communicating assert ord(msg[0]) == subaddr if ord(msg[1])&0xf0 == 0x10: diff --git a/run_automated_tests.sh b/run_automated_tests.sh index 4e07d329c..583d6c1ed 100755 --- a/run_automated_tests.sh +++ b/run_automated_tests.sh @@ -1,14 +1,21 @@ -#!/bin/bash +#!/bin/bash -e TEST_FILENAME=${TEST_FILENAME:-nosetests.xml} -if [ ! -f "/EON" ]; then +if [ -f "/EON" ]; then TESTSUITE_NAME="Panda_Test-EON" else TESTSUITE_NAME="Panda_Test-DEV" fi -cd boardesp -make flashall -cd .. +if [ ! -z "${SKIPWIFI}" ] || [ -f "/EON" ]; then + TEST_SCRIPTS=$(ls tests/automated/$1*.py | grep -v wifi) +else + TEST_SCRIPTS=$(ls tests/automated/$1*.py) +fi +IFS=$'\n' +for NAME in $(nmcli --fields NAME con show | grep panda | awk '{$1=$1};1') +do + nmcli connection delete "$NAME" +done -PYTHONPATH="." python $(which nosetests) -v --with-xunit --xunit-file=./$TEST_FILENAME --xunit-testsuite-name=$TESTSUITE_NAME -s tests/automated/$1*.py +PYTHONPATH="." python $(which nosetests) -v --with-xunit --xunit-file=./$TEST_FILENAME --xunit-testsuite-name=$TESTSUITE_NAME -s $TEST_SCRIPTS diff --git a/tests/automated/5_wifi_udp.py b/tests/automated/5_wifi_udp.py index 873f78bdb..d55baa659 100644 --- a/tests/automated/5_wifi_udp.py +++ b/tests/automated/5_wifi_udp.py @@ -34,7 +34,7 @@ def test_udp_doesnt_drop(serial=None): sys.stdout.flush() else: print("UDP WIFI loopback %d messages at speed %d, comp speed is %.2f, percent %.2f" % (msg_count, speed, comp_kbps, saturation_pct)) - assert_greater(saturation_pct, 15) #sometimes the wifi can be slow... + assert_greater(saturation_pct, 20) #sometimes the wifi can be slow... assert_less(saturation_pct, 100) saturation_pcts.append(saturation_pct) if len(saturation_pcts) > 0: diff --git a/tests/build_strict/Dockerfile b/tests/build_strict/Dockerfile deleted file mode 100644 index b1c75c025..000000000 --- a/tests/build_strict/Dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -FROM ubuntu:16.04 - -RUN apt-get update && apt-get install -y gcc-arm-none-eabi libnewlib-arm-none-eabi python python-pip gcc g++ - -RUN pip install pycrypto==2.6.1 - -COPY . /panda - -WORKDIR /panda diff --git a/tests/build_strict/test_build_strict.sh b/tests/build_strict/test_build_strict.sh deleted file mode 100755 index ee57ba8ad..000000000 --- a/tests/build_strict/test_build_strict.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash -e - -cd ../../board/ - -make -f Makefile.strict clean -make -f Makefile.strict bin 2> compiler_output.txt - - -if [[ -s "compiler_output.txt" ]] -then - echo "Found alerts from the compiler:" - cat compiler_output.txt - exit 1 -fi - diff --git a/tests/elm_car_simulator.py b/tests/elm_car_simulator.py index bcee821cd..f931e66ff 100755 --- a/tests/elm_car_simulator.py +++ b/tests/elm_car_simulator.py @@ -152,7 +152,7 @@ class ELMCarSimulator(): if len(outmsg) <= 5: self._lin_send(0x10, obd_header + outmsg) else: - first_msg_len = MIN(4, len(outmsg)%4) or 4 + first_msg_len = min(4, len(outmsg)%4) or 4 self._lin_send(0x10, obd_header + b'\x01' + b'\x00'*(4-first_msg_len) + outmsg[:first_msg_len]) @@ -229,7 +229,7 @@ class ELMCarSimulator(): outaddr = 0x7E8 if address == 0x7DF or address == 0x7E0 else 0x18DAF110 msgnum = 1 while(self.__can_multipart_data): - datalen = MIN(7, len(self.__can_multipart_data)) + datalen = min(7, len(self.__can_multipart_data)) msgpiece = struct.pack("B", 0x20 | msgnum) + self.__can_multipart_data[:datalen] self._can_send(outaddr, msgpiece) self.__can_multipart_data = self.__can_multipart_data[7:] @@ -246,7 +246,7 @@ class ELMCarSimulator(): self._can_send(outaddr, struct.pack("BBB", len(outmsg)+2, 0x40|data[1], pid) + outmsg) else: - first_msg_len = MIN(3, len(outmsg)%7) + first_msg_len = min(3, len(outmsg)%7) payload_len = len(outmsg)+3 msgpiece = struct.pack("BBBBB", 0x10 | ((payload_len>>8)&0xF), payload_len&0xFF, diff --git a/tests/gmbitbang/test_one.py b/tests/gmbitbang/test_one.py index a398e2780..d7d430437 100755 --- a/tests/gmbitbang/test_one.py +++ b/tests/gmbitbang/test_one.py @@ -5,7 +5,7 @@ from panda import Panda p = Panda() p.set_safety_mode(Panda.SAFETY_ALLOUTPUT) -# ack any crap on bus +# hack anything on bus p.set_gmlan(bus=2) time.sleep(0.1) while len(p.can_recv()) > 0: diff --git a/tests/language/Dockerfile b/tests/language/Dockerfile new file mode 100644 index 000000000..068847145 --- /dev/null +++ b/tests/language/Dockerfile @@ -0,0 +1,6 @@ +FROM ubuntu:16.04 + +RUN apt-get update && apt-get install -y make python python-pip +COPY tests/safety/requirements.txt /panda/tests/safety/requirements.txt +RUN pip install -r /panda/tests/safety/requirements.txt +COPY . /panda diff --git a/tests/language/LICENSE b/tests/language/LICENSE new file mode 100644 index 000000000..8dada3eda --- /dev/null +++ b/tests/language/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + 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 + + http://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. diff --git a/tests/language/list.txt b/tests/language/list.txt new file mode 100644 index 000000000..cfd25897d --- /dev/null +++ b/tests/language/list.txt @@ -0,0 +1,451 @@ +4r5e +5h1t +5hit +a55 +anal +anus +ar5e +arrse +arse +ass +ass-fucker +asses +assfucker +assfukka +asshole +assholes +asswhole +a_s_s +b!tch +b00bs +b17ch +b1tch +ballbag +balls +ballsack +bastard +beastial +beastiality +bellend +bestial +bestiality +bi+ch +biatch +bitch +bitcher +bitchers +bitches +bitchin +bitching +bloody +blow job +blowjob +blowjobs +boiolas +bollock +bollok +boner +boob +boobs +booobs +boooobs +booooobs +booooooobs +breasts +buceta +bugger +bum +bunny fucker +bullshit +butt +butthole +buttmuch +buttplug +c0ck +c0cksucker +carpet muncher +cawk +chink +cipa +cl1t +clit +clitoris +clits +cnut +cock +cock-sucker +cockface +cockhead +cockmunch +cockmuncher +cocks +cocksuck +cocksucked +cocksucker +cocksucking +cocksucks +cocksuka +cocksukka +cok +cokmuncher +coksucka +coon +cox +crap +cum +cummer +cumming +cums +cumshot +cunilingus +cunillingus +cunnilingus +cunt +cuntlick +cuntlicker +cuntlicking +cunts +cyalis +cyberfuc +cyberfuck +cyberfucked +cyberfucker +cyberfuckers +cyberfucking +d1ck +damn +dick +dickhead +dildo +dildos +dink +dinks +dirsa +dlck +dog-fucker +doggin +dogging +donkeyribber +doosh +duche +dyke +ejaculate +ejaculated +ejaculates +ejaculating +ejaculatings +ejaculation +ejakulate +f u c k +f u c k e r +f4nny +fag +fagging +faggitt +faggot +faggs +fagot +fagots +fags +fanny +fannyflaps +fannyfucker +fanyy +fatass +fcuk +fcuker +fcuking +feck +fecker +felching +fellate +fellatio +fingerfuck +fingerfucked +fingerfucker +fingerfuckers +fingerfucking +fingerfucks +fistfuck +fistfucked +fistfucker +fistfuckers +fistfucking +fistfuckings +fistfucks +flange +fook +fooker +fuck +fucka +fucked +fucker +fuckers +fuckhead +fuckheads +fuckin +fucking +fuckings +fuckingshitmotherfucker +fuckme +fucks +fuckwhit +fuckwit +fudge packer +fudgepacker +fuk +fuker +fukker +fukkin +fuks +fukwhit +fukwit +fux +fux0r +f_u_c_k +gangbang +gangbanged +gangbangs +gaylord +gaysex +goatse +God +god-dam +god-damned +goddamn +goddamned +hardcoresex +hell +heshe +hoar +hoare +hoer +homo +hore +horniest +horny +hotsex +jack-off +jackoff +jap +jerk-off +jism +jiz +jizm +jizz +kawk +knob +knobead +knobed +knobend +knobhead +knobjocky +knobjokey +kock +kondum +kondums +kum +kummer +kumming +kums +kunilingus +l3i+ch +l3itch +labia +lmfao +lust +lusting +m0f0 +m0fo +m45terbate +ma5terb8 +ma5terbate +masochist +master-bate +masterb8 +masterbat* +masterbat3 +masterbate +masterbation +masterbations +masturbate +mo-fo +mof0 +mofo +mothafuck +mothafucka +mothafuckas +mothafuckaz +mothafucked +mothafucker +mothafuckers +mothafuckin +mothafucking +mothafuckings +mothafucks +mother fucker +motherfuck +motherfucked +motherfucker +motherfuckers +motherfuckin +motherfucking +motherfuckings +motherfuckka +motherfucks +muff +mutha +muthafecker +muthafuckker +muther +mutherfucker +n1gga +n1gger +nazi +nigg3r +nigg4h +nigga +niggah +niggas +niggaz +nigger +niggers +nob +nob jokey +nobhead +nobjocky +nobjokey +numbnuts +nutsack +orgasim +orgasims +orgasm +orgasms +p0rn +pawn +pecker +penis +penisfucker +phonesex +phuck +phuk +phuked +phuking +phukked +phukking +phuks +phuq +pigfucker +pimpis +piss +pissed +pisser +pissers +pisses +pissflaps +pissin +pissing +pissoff +poop +porn +porno +pornography +pornos +prick +pricks +pron +pube +pusse +pussi +pussies +pussy +pussys +rectum +retard +rimjaw +rimming +s hit +s.o.b. +sadist +schlong +screwing +scroat +scrote +scrotum +semen +sex +sh!+ +sh!t +sh1t +shag +shagger +shaggin +shagging +shemale +shi+ +shit +shitdick +shite +shited +shitey +shitfuck +shitfull +shithead +shiting +shitings +shits +shitted +shitter +shitters +shitting +shittings +shitty +skank +slut +sluts +smegma +smut +snatch +son-of-a-bitch +spac +spunk +s_h_i_t +t1tt1e5 +t1tties +teets +teez +testical +testicle +tit +titfuck +tits +titt +tittie5 +tittiefucker +titties +tittyfuck +tittywank +titwank +tosser +turd +tw4t +twat +twathead +twatty +twunt +twunter +v14gra +v1gra +vagina +viagra +vulva +w00se +wang +wank +wanker +wanky +whoar +whore +willies +willy +xrated diff --git a/tests/language/test_language.py b/tests/language/test_language.py new file mode 100755 index 000000000..3afb34619 --- /dev/null +++ b/tests/language/test_language.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python + +import subprocess +import sys + +checked_ext = ["h", "c", "py", "pyx", "cpp", "hpp", "md", "mk"] + +if __name__ == "__main__": + with open("list.txt", 'r') as handle: + + suffix_cmd = " " + for i in checked_ext: + suffix_cmd += "--include \*." + i + " " + + found_bad_language = False + for line in handle: + line = line.rstrip('\n').rstrip(" ") + try: + cmd = "cd ../../; grep -R -i -w " + suffix_cmd + " '" + line + "'" + res = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT) + print res + found_bad_language = True + except subprocess.CalledProcessError as e: + pass + if found_bad_language: + sys.exit("Failed: found bad language") + else: + print "Success" diff --git a/tests/misra/suppressions.txt b/tests/misra/suppressions.txt new file mode 100644 index 000000000..8e58b6e34 --- /dev/null +++ b/tests/misra/suppressions.txt @@ -0,0 +1,8 @@ +# Advisory: union types can be used +misra.19.2 +# FIXME: add it back when fixed in cppcheck. Macro identifiers are unique but it false triggers on defines in #ifdef..#else conditions +misra.5.4 +# Advisory: casting from void pointer to type pointer is ok. Done by STM libraries as well +misra.11.4 +# Advisory: casting from void pointer to type pointer is ok. Done by STM libraries as well +misra.11.5 diff --git a/tests/misra/test_misra.sh b/tests/misra/test_misra.sh index 835f4ebcf..633800912 100755 --- a/tests/misra/test_misra.sh +++ b/tests/misra/test_misra.sh @@ -1,24 +1,53 @@ #!/bin/bash -e +mkdir /tmp/misra || true git clone https://github.com/danmar/cppcheck.git || true cd cppcheck git fetch -git checkout 44d6066c6fad32e2b0332b3f2b24bd340febaef8 +git checkout 862c4ef87b109ae86c2d5f12769b7c8d199f35c5 make -j4 cd ../../../ -# whole panda code -tests/misra/cppcheck/cppcheck --dump --enable=all --inline-suppr board/main.c 2>/tmp/misra/cppcheck_output.txt || true -python tests/misra/cppcheck/addons/misra.py board/main.c.dump 2>/tmp/misra/misra_output.txt || true -# violations in safety files -(cat /tmp/misra/misra_output.txt | grep safety) > /tmp/misra/misra_safety_output.txt || true -(cat /tmp/misra/cppcheck_output.txt | grep safety) > /tmp/misra/cppcheck_safety_output.txt || true +printf "\nPANDA CODE\n" +tests/misra/cppcheck/cppcheck -DPANDA -UPEDAL -DCAN3 -DUID_BASE -DEON \ + --suppressions-list=tests/misra/suppressions.txt \ + --dump --enable=all --inline-suppr --force \ + board/main.c 2>/tmp/misra/cppcheck_output.txt -if [[ -s "/tmp/misra/misra_safety_output.txt" ]] || [[ -s "/tmp/misra/cppcheck_safety_output.txt" ]] +python tests/misra/cppcheck/addons/misra.py board/main.c.dump 2> /tmp/misra/misra_output.txt || true + +# strip (information) lines +cppcheck_output=$( cat /tmp/misra/cppcheck_output.txt | grep -v "(information) " ) || true +misra_output=$( cat /tmp/misra/misra_output.txt | grep -v "(information) " ) || true + + +printf "\nPEDAL CODE\n" +tests/misra/cppcheck/cppcheck -UPANDA -DPEDAL -UCAN3 \ + --suppressions-list=tests/misra/suppressions.txt \ + -I board/ --dump --enable=all --inline-suppr --force \ + board/pedal/main.c 2>/tmp/misra/cppcheck_pedal_output.txt + +python tests/misra/cppcheck/addons/misra.py board/pedal/main.c.dump 2> /tmp/misra/misra_pedal_output.txt || true + +# strip (information) lines +cppcheck_pedal_output=$( cat /tmp/misra/cppcheck_pedal_output.txt | grep -v "(information) " ) || true +misra_pedal_output=$( cat /tmp/misra/misra_pedal_output.txt | grep -v "(information) " ) || true + +if [[ -n "$misra_output" ]] || [[ -n "$cppcheck_output" ]] then - echo "Found Misra violations in the safety code:" - cat /tmp/misra/misra_safety_output.txt - cat /tmp/misra/cppcheck_safety_output.txt + echo "Failed! found Misra violations in panda code:" + echo "$misra_output" + echo "$cppcheck_output" exit 1 fi + +if [[ -n "$misra_pedal_output" ]] || [[ -n "$cppcheck_pedal_output" ]] +then + echo "Failed! found Misra violations in pedal code:" + echo "$misra_pedal_output" + echo "$cppcheck_pedal_output" + exit 1 +fi + +echo "Success" diff --git a/tests/safety/libpandasafety_py.py b/tests/safety/libpandasafety_py.py index dc5e5be5a..1345065cb 100644 --- a/tests/safety/libpandasafety_py.py +++ b/tests/safety/libpandasafety_py.py @@ -55,7 +55,7 @@ void set_toyota_camera_forwarded(int t); void set_toyota_rt_torque_last(int t); void init_tests_honda(void); -int get_honda_ego_speed(void); +bool get_honda_moving(void); int get_honda_brake_prev(void); int get_honda_gas_prev(void); void set_honda_alt_brake_msg(bool); diff --git a/tests/safety/test.c b/tests/safety/test.c index be13d346a..dc3de5504 100644 --- a/tests/safety/test.c +++ b/tests/safety/test.c @@ -32,6 +32,7 @@ struct sample_t subaru_torque_driver; TIM_TypeDef timer; TIM_TypeDef *TIM2 = &timer; +// from config.h #define MIN(a,b) \ ({ __typeof__ (a) _a = (a); \ __typeof__ (b) _b = (b); \ @@ -42,6 +43,14 @@ TIM_TypeDef *TIM2 = &timer; __typeof__ (b) _b = (b); \ _a > _b ? _a : _b; }) +// from llcan.h +#define GET_BUS(msg) (((msg)->RDTR >> 4) & 0xFF) +#define GET_LEN(msg) ((msg)->RDTR & 0xf) +#define GET_ADDR(msg) ((((msg)->RIR & 4) != 0) ? ((msg)->RIR >> 3) : ((msg)->RIR >> 21)) +#define GET_BYTE(msg, b) (((int)(b) > 3) ? (((msg)->RDHR >> (8U * ((unsigned int)(b) % 4U))) & 0XFFU) : (((msg)->RDLR >> (8U * (unsigned int)(b))) & 0xFFU)) +#define GET_BYTES_04(msg) ((msg)->RDLR) +#define GET_BYTES_48(msg) ((msg)->RDHR) + #define UNUSED(x) (void)(x) #define PANDA @@ -199,8 +208,8 @@ void set_subaru_desired_torque_last(int t){ subaru_desired_torque_last = t; } -int get_honda_ego_speed(void){ - return honda_ego_speed; +bool get_honda_moving(void){ + return honda_moving; } int get_honda_brake_prev(void){ @@ -274,7 +283,7 @@ void init_tests_subaru(void){ } void init_tests_honda(void){ - honda_ego_speed = 0; + honda_moving = false; honda_brake_prev = 0; honda_gas_prev = 0; } diff --git a/tests/safety/test_honda.py b/tests/safety/test_honda.py index bc5e8d192..5833d96e3 100755 --- a/tests/safety/test_honda.py +++ b/tests/safety/test_honda.py @@ -5,6 +5,8 @@ import libpandasafety_py MAX_BRAKE = 255 +INTERCEPTOR_THRESHOLD = 328 + class TestHondaSafety(unittest.TestCase): @classmethod def setUp(cls): @@ -66,7 +68,9 @@ class TestHondaSafety(unittest.TestCase): to_send = libpandasafety_py.ffi.new('CAN_FIFOMailBox_TypeDef *') to_send[0].RIR = addr << 21 to_send[0].RDTR = 6 - to_send[0].RDLR = ((gas & 0xff) << 8) | ((gas & 0xff00) >> 8) + gas2 = gas * 2 + to_send[0].RDLR = ((gas & 0xff) << 8) | ((gas & 0xff00) >> 8) | \ + ((gas2 & 0xff) << 24) | ((gas2 & 0xff00) << 8) return to_send @@ -99,9 +103,9 @@ class TestHondaSafety(unittest.TestCase): self.assertFalse(self.safety.get_controls_allowed()) def test_sample_speed(self): - self.assertEqual(0, self.safety.get_honda_ego_speed()) + self.assertEqual(0, self.safety.get_honda_moving()) self.safety.safety_rx_hook(self._speed_msg(100)) - self.assertEqual(100, self.safety.get_honda_ego_speed()) + self.assertEqual(1, self.safety.get_honda_moving()) def test_prev_brake(self): self.assertFalse(self.safety.get_honda_brake_prev()) @@ -176,16 +180,15 @@ class TestHondaSafety(unittest.TestCase): def test_disengage_on_gas_interceptor(self): for long_controls_allowed in [0, 1]: - self.safety.set_long_controls_allowed(long_controls_allowed) - self.safety.safety_rx_hook(self._send_interceptor_msg(0, 0x201)) - self.safety.set_controls_allowed(1) - self.safety.safety_rx_hook(self._send_interceptor_msg(0x1000, 0x201)) - if long_controls_allowed: - self.assertFalse(self.safety.get_controls_allowed()) - else: - self.assertTrue(self.safety.get_controls_allowed()) - self.safety.safety_rx_hook(self._send_interceptor_msg(0, 0x201)) - self.safety.set_gas_interceptor_detected(False) + for g in range(0, 0x1000): + self.safety.set_long_controls_allowed(long_controls_allowed) + self.safety.safety_rx_hook(self._send_interceptor_msg(0, 0x201)) + self.safety.set_controls_allowed(True) + self.safety.safety_rx_hook(self._send_interceptor_msg(g, 0x201)) + remain_enabled = (not long_controls_allowed or g <= INTERCEPTOR_THRESHOLD) + self.assertEqual(remain_enabled, self.safety.get_controls_allowed()) + self.safety.safety_rx_hook(self._send_interceptor_msg(0, 0x201)) + self.safety.set_gas_interceptor_detected(False) self.safety.set_long_controls_allowed(True) def test_allow_engage_with_gas_interceptor_pressed(self): diff --git a/tests/safety/test_toyota.py b/tests/safety/test_toyota.py index 7dd1601d7..dc5b21ac8 100644 --- a/tests/safety/test_toyota.py +++ b/tests/safety/test_toyota.py @@ -15,6 +15,8 @@ RT_INTERVAL = 250000 MAX_TORQUE_ERROR = 350 +INTERCEPTOR_THRESHOLD = 475 + def twos_comp(val, bits): if val >= 0: return val @@ -81,7 +83,9 @@ class TestToyotaSafety(unittest.TestCase): to_send = libpandasafety_py.ffi.new('CAN_FIFOMailBox_TypeDef *') to_send[0].RIR = addr << 21 to_send[0].RDTR = 6 - to_send[0].RDLR = ((gas & 0xff) << 8) | ((gas & 0xff00) >> 8) + gas2 = gas * 2 + to_send[0].RDLR = ((gas & 0xff) << 8) | ((gas & 0xff00) >> 8) | \ + ((gas2 & 0xff) << 24) | ((gas2 & 0xff00) << 8) return to_send @@ -145,16 +149,15 @@ class TestToyotaSafety(unittest.TestCase): def test_disengage_on_gas_interceptor(self): for long_controls_allowed in [0, 1]: - self.safety.set_long_controls_allowed(long_controls_allowed) - self.safety.safety_rx_hook(self._send_interceptor_msg(0, 0x201)) - self.safety.set_controls_allowed(True) - self.safety.safety_rx_hook(self._send_interceptor_msg(0x1000, 0x201)) - if long_controls_allowed: - self.assertFalse(self.safety.get_controls_allowed()) - else: - self.assertTrue(self.safety.get_controls_allowed()) - self.safety.safety_rx_hook(self._send_interceptor_msg(0, 0x201)) - self.safety.set_gas_interceptor_detected(False) + for g in range(0, 0x1000): + self.safety.set_long_controls_allowed(long_controls_allowed) + self.safety.safety_rx_hook(self._send_interceptor_msg(0, 0x201)) + self.safety.set_controls_allowed(True) + self.safety.safety_rx_hook(self._send_interceptor_msg(g, 0x201)) + remain_enabled = (not long_controls_allowed or g <= INTERCEPTOR_THRESHOLD) + self.assertEqual(remain_enabled, self.safety.get_controls_allowed()) + self.safety.safety_rx_hook(self._send_interceptor_msg(0, 0x201)) + self.safety.set_gas_interceptor_detected(False) self.safety.set_long_controls_allowed(True) def test_allow_engage_with_gas_interceptor_pressed(self): diff --git a/tests/safety_replay/Dockerfile b/tests/safety_replay/Dockerfile index bf2b7f2c1..5d59ca38d 100644 --- a/tests/safety_replay/Dockerfile +++ b/tests/safety_replay/Dockerfile @@ -17,4 +17,4 @@ COPY . /openpilot/panda WORKDIR /openpilot/panda/tests/safety_replay RUN git clone https://github.com/commaai/openpilot-tools.git tools || true WORKDIR tools -RUN git checkout b6461274d684915f39dc45efc5292ea890698da9 +RUN git checkout feb724a14f0f5223c700c94317efaf46923fd48a diff --git a/tests/safety_replay/install_capnp.sh b/tests/safety_replay/install_capnp.sh index e13ab48c2..51559d399 100755 --- a/tests/safety_replay/install_capnp.sh +++ b/tests/safety_replay/install_capnp.sh @@ -8,13 +8,3 @@ cd capnproto-c++-0.6.1 make -j4 make install -cd .. -git clone https://github.com/commaai/c-capnproto.git -cd c-capnproto -git checkout 2e625acacf58a5f5c8828d8453d1f8dacc700a96 -git submodule update --init --recursive -autoreconf -f -i -s -CFLAGS="-fPIC" ./configure --prefix=/usr/local -make -j4 -make install - From b539ae3e2d9963b24e826823e1d78ba97f25352b Mon Sep 17 00:00:00 2001 From: Vehicle Researcher Date: Mon, 22 Jul 2019 19:15:28 +0000 Subject: [PATCH 3/4] Squashed 'opendbc/' changes from 38650f842..e1955ba06 e1955ba06 Nissan: Added nissan_2017.dbc (#173) c89eb71df properly generate Lexus 350 dbc file d08059c77 Lexus RX 350 DBC (#170) git-subtree-dir: opendbc git-subtree-split: e1955ba06e3308dbbfb4bcda78d0e6495bc9ff7e --- generator/toyota/lexus_rx_350_2016_pt.dbc | 37 +++ lexus_rx_350_2016_pt_generated.dbc | 335 ++++++++++++++++++++++ nissan_2017.dbc | 184 ++++++++++++ 3 files changed, 556 insertions(+) create mode 100644 generator/toyota/lexus_rx_350_2016_pt.dbc create mode 100644 lexus_rx_350_2016_pt_generated.dbc create mode 100644 nissan_2017.dbc diff --git a/generator/toyota/lexus_rx_350_2016_pt.dbc b/generator/toyota/lexus_rx_350_2016_pt.dbc new file mode 100644 index 000000000..4a6fe48fd --- /dev/null +++ b/generator/toyota/lexus_rx_350_2016_pt.dbc @@ -0,0 +1,37 @@ +CM_ "IMPORT _toyota_2017.dbc" +CM_ "IMPORT _comma.dbc" + +BO_ 550 BRAKE_MODULE: 8 XXX + SG_ BRAKE_PRESSURE : 0|9@0+ (1,0) [0|511] "" XXX + SG_ BRAKE_POSITION : 16|9@0+ (1,0) [0|511] "" XXX + SG_ BRAKE_PRESSED : 37|1@0+ (1,0) [0|1] "" XXX + +BO_ 608 STEER_TORQUE_SENSOR: 8 XXX + SG_ STEER_TORQUE_EPS : 47|16@0- (0.73,0) [-20000|20000] "" 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 + +BO_ 610 EPS_STATUS: 5 EPS + SG_ IPAS_STATE : 3|4@0+ (1,0) [0|15] "" XXX + SG_ LKA_STATE : 31|7@0+ (1,0) [0|127] "" XXX + SG_ TYPE : 24|1@0+ (1,0) [0|1] "" XXX + SG_ CHECKSUM : 39|8@0+ (1,0) [0|255] "" XXX + +BO_ 956 GEAR_PACKET: 8 XXX + SG_ SPORT_ON : 2|1@0+ (1,0) [0|1] "" XXX + SG_ GEAR : 13|6@0+ (1,0) [0|63] "" XXX + SG_ ECON_ON : 40|1@0+ (1,0) [0|1] "" XXX + +BO_ 705 GAS_PEDAL: 8 XXX + SG_ GAS_PEDAL : 55|8@0+ (1,0) [0|255] "" XXX + + +CM_ SG_ 550 BRAKE_PRESSURE "seems prop to pedal force"; +CM_ SG_ 550 BRAKE_POSITION "seems proportional to pedal displacement, unclear the max value of 0x1c8"; +CM_ SG_ 610 TYPE "seems 1 on Corolla, 0 on all others"; +VAL_ 610 IPAS_STATE 5 "override" 3 "enabled" 1 "disabled" ; +VAL_ 610 LKA_STATE 25 "temporary_fault" 9 "temporary_fault2" 5 "active" 1 "standby" ; +VAL_ 956 SPORT_ON 0 "off" 1 "on" ; +VAL_ 956 GEAR 0 "D" 1 "S" 8 "N" 16 "R" 32 "P" ; +VAL_ 956 ECON_ON 0 "off" 1 "on" ; diff --git a/lexus_rx_350_2016_pt_generated.dbc b/lexus_rx_350_2016_pt_generated.dbc new file mode 100644 index 000000000..18126133d --- /dev/null +++ b/lexus_rx_350_2016_pt_generated.dbc @@ -0,0 +1,335 @@ +CM_ "AUTOGENERATED FILE, DO NOT EDIT" + + +CM_ "Imported file _comma.dbc starts here" +BO_ 359 STEERING_IPAS_COMMA: 8 IPAS + SG_ STATE : 7|4@0+ (1,0) [0|15] "" XXX + SG_ ANGLE : 3|12@0- (1.5,0) [-510|510] "deg" XXX + SG_ SET_ME_X10 : 23|8@0+ (1,0) [0|255] "" XXX + SG_ SET_ME_X00 : 31|8@0+ (1,0) [0|255] "" XXX + SG_ DIRECTION_CMD : 38|2@0+ (1,0) [0|3] "" XXX + SG_ SET_ME_X40 : 47|8@0+ (1,0) [0|255] "" XXX + SG_ SET_ME_X00 : 55|8@0+ (1,0) [0|255] "" XXX + SG_ CHECKSUM : 63|8@0+ (1,0) [0|255] "" XXX + +CM BO_ STEERING_IPAS_COMMA "Copy of msg 614 so we can do angle control while the Park Assist ECU is connected (Panda spoofs 614 with 359 on connector J70). Note that addresses 0x266 and 0x167 are checksum-invariant"; + + BO_ 512 GAS_COMMAND: 6 EON + SG_ GAS_COMMAND : 7|16@0+ (0.159375,-75.555) [0|1] "" INTERCEPTOR + SG_ GAS_COMMAND2 : 23|16@0+ (0.159375,-151.111) [0|1] "" INTERCEPTOR + SG_ ENABLE : 39|1@0+ (1,0) [0|1] "" INTERCEPTOR + SG_ COUNTER_PEDAL : 35|4@0+ (1,0) [0|15] "" INTERCEPTOR + SG_ CHECKSUM_PEDAL : 47|8@0+ (1,0) [0|255] "" INTERCEPTOR + + BO_ 513 GAS_SENSOR: 6 INTERCEPTOR + SG_ INTERCEPTOR_GAS : 7|16@0+ (0.159375,-75.555) [0|1] "" EON + SG_ INTERCEPTOR_GAS2 : 23|16@0+ (0.159375,-151.111) [0|1] "" EON + SG_ STATE : 39|4@0+ (1,0) [0|15] "" EON + SG_ COUNTER_PEDAL : 35|4@0+ (1,0) [0|15] "" EON + SG_ CHECKSUM_PEDAL : 47|8@0+ (1,0) [0|255] "" EON + + VAL_ 513 STATE 5 "FAULT_TIMEOUT" 4 "FAULT_STARTUP" 3 "FAULT_SCE" 2 "FAULT_SEND" 1 "FAULT_BAD_CHECKSUM" 0 "NO_FAULT" ; + + +CM_ "Imported file _toyota_2017.dbc starts here" +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 DSU HCU EPS IPAS + +BO_ 36 KINEMATICS: 8 XXX + SG_ ACCEL_Y : 33|10@0+ (1,-512) [0|65535] "" XXX + SG_ YAW_RATE : 1|10@0+ (1,-512) [0|65535] "" XXX + SG_ STEERING_TORQUE : 17|10@0+ (1,-512) [0|65535] "" XXX + +BO_ 37 STEER_ANGLE_SENSOR: 8 XXX + SG_ STEER_ANGLE : 3|12@0- (1.5,0) [-500|500] "deg" XXX + SG_ STEER_FRACTION : 39|4@0- (0.1,0) [-0.7|0.7] "deg" XXX + SG_ STEER_RATE : 35|12@0- (1,0) [-2000|2000] "deg/s" XXX + +BO_ 166 BRAKE: 8 XXX + SG_ BRAKE_AMOUNT : 7|8@0+ (1,0) [0|255] "" XXX + SG_ BRAKE_PEDAL : 23|8@0+ (1,0) [0|255] "" XXX + +BO_ 170 WHEEL_SPEEDS: 8 XXX + SG_ WHEEL_SPEED_FR : 7|16@0+ (0.01,-67.67) [0|250] "kph" XXX + SG_ WHEEL_SPEED_FL : 23|16@0+ (0.01,-67.67) [0|250] "kph" XXX + SG_ WHEEL_SPEED_RR : 39|16@0+ (0.01,-67.67) [0|250] "kph" XXX + SG_ WHEEL_SPEED_RL : 55|16@0+ (0.01,-67.67) [0|250] "kph" XXX + +BO_ 180 SPEED: 8 XXX + SG_ ENCODER : 39|8@0+ (1,0) [0|255] "" XXX + SG_ CHECKSUM : 63|8@0+ (1,0) [0|255] "" XXX + SG_ SPEED : 47|16@0+ (0.01,0) [0|250] "kph" XXX + +BO_ 353 DSU_SPEED: 8 XXX + SG_ FORWARD_SPEED : 15|16@0- (0.00390625,-30) [0|255] "kph" XXX + +BO_ 466 PCM_CRUISE: 8 XXX + SG_ GAS_RELEASED : 4|1@0+ (1,0) [0|1] "" XXX + SG_ CRUISE_ACTIVE : 5|1@0+ (1,0) [0|1] "" XXX + SG_ STANDSTILL_ON : 12|1@0+ (1,0) [0|1] "" XXX + SG_ ACCEL_NET : 23|16@0- (0.001,0) [-20|20] "m/s2" XXX + SG_ CRUISE_STATE : 55|4@0+ (1,0) [0|15] "" XXX + SG_ CHECKSUM : 63|8@0+ (1,0) [0|255] "" XXX + +BO_ 467 PCM_CRUISE_2: 8 XXX + SG_ MAIN_ON : 15|1@0+ (1,0) [0|1] "" XXX + SG_ LOW_SPEED_LOCKOUT : 14|2@0+ (1,0) [0|3] "kph" XXX + SG_ SET_SPEED : 23|8@0+ (1,0) [0|255] "kph" XXX + SG_ CHECKSUM : 63|8@0+ (1,0) [0|255] "" XXX + +BO_ 552 ACCELEROMETER: 8 XXX + SG_ ACCEL_Z : 22|15@0- (1,0) [0|32767] "" XXX + SG_ ACCEL_X : 6|15@0- (0.001,0) [-20|20] "m/s2" XXX + +BO_ 560 BRAKE_MODULE2: 7 XXX + SG_ BRAKE_PRESSED : 26|1@0+ (1,0) [0|1] "" XXX + +BO_ 614 STEERING_IPAS: 8 IPAS + SG_ STATE : 7|4@0+ (1,0) [0|15] "" XXX + SG_ ANGLE : 3|12@0- (1.5,0) [-510|510] "deg" XXX + SG_ SET_ME_X10 : 23|8@0+ (1,0) [0|255] "" XXX + SG_ SET_ME_X00 : 31|8@0+ (1,0) [0|255] "" XXX + SG_ DIRECTION_CMD : 38|2@0+ (1,0) [0|3] "" XXX + SG_ SET_ME_X40 : 47|8@0+ (1,0) [0|255] "" XXX + SG_ SET_ME_X00_1 : 55|8@0+ (1,0) [0|255] "" XXX + SG_ CHECKSUM : 63|8@0+ (1,0) [0|255] "" XXX + +BO_ 643 PRE_COLLISION: 8 XXX + +BO_ 740 STEERING_LKA: 5 XXX + SG_ LKA_STATE : 31|8@0+ (1,0) [0|255] "" XXX + SG_ STEER_REQUEST : 0|1@0+ (1,0) [0|1] "" XXX + SG_ COUNTER : 6|6@0+ (1,0) [0|63] "" XXX + SG_ SET_ME_1 : 7|1@0+ (1,0) [0|1] "" XXX + SG_ STEER_TORQUE_CMD : 15|16@0- (1,0) [0|65535] "" XXX + SG_ CHECKSUM : 39|8@0+ (1,0) [0|255] "" XXX + +BO_ 742 LEAD_INFO: 8 DSU + SG_ CHECKSUM : 63|8@0+ (1,0) [0|255] "" HCU + SG_ LEAD_REL_SPEED : 23|12@0- (0.025,0) [-100|100] "m/s" HCU + SG_ LEAD_LONG_DIST : 7|13@0+ (0.05,0) [0|300] "m" HCU + +BO_ 835 ACC_CONTROL: 8 DSU + SG_ ACCEL_CMD : 7|16@0- (0.001,0) [-20|20] "m/s2" HCU + SG_ SET_ME_X01 : 23|2@0+ (1,0) [0|3] "" HCU + SG_ DISTANCE : 20|1@0+ (1,0) [0|1] "" XXX + SG_ MINI_CAR : 21|1@0+ (1,0) [0|1] "" XXX + SG_ SET_ME_X3 : 19|4@0+ (1,0) [0|15] "" XXX + SG_ SET_ME_1 : 30|1@0+ (1,0) [0|1] "" HCU + SG_ RELEASE_STANDSTILL : 31|1@0+ (1,0) [0|1] "" HCU + SG_ CANCEL_REQ : 24|1@0+ (1,0) [0|1] "" HCU + SG_ CHECKSUM : 63|8@0+ (1,0) [0|255] "" XXX + +BO_ 921 PCM_CRUISE_SM: 8 XXX + SG_ MAIN_ON : 4|1@0+ (1,0) [0|1] "" XXX + SG_ CRUISE_CONTROL_STATE : 11|4@0+ (1,0) [0|15] "" XXX + SG_ DISTANCE_LINES : 14|2@0+ (1,0) [0|3] "" XXX + SG_ UI_SET_SPEED : 31|8@0+ (1,0) [0|255] "" XXX + +BO_ 951 ESP_CONTROL: 8 ESP + SG_ TC_DISABLED : 13|1@0+ (1,0) [0|1] "" XXX + SG_ BRAKE_LIGHTS_ACC : 18|1@0+ (1,0) [0|1] "" XXX + +BO_ 1041 ACC_HUD: 8 DSU + SG_ FCW : 4|1@0+ (1,0) [0|1] "" XXX + SG_ SET_ME_X20 : 15|8@0+ (1,0) [0|1] "" XXX + SG_ SET_ME_X10 : 39|8@0+ (1,0) [0|1] "" XXX + SG_ SET_ME_X80 : 55|8@0+ (1,0) [0|1] "" XXX + +BO_ 1042 LKAS_HUD: 8 XXX + SG_ BARRIERS : 1|2@0+ (1,0) [0|3] "" XXX + SG_ RIGHT_LINE : 3|2@0+ (1,0) [0|3] "" XXX + SG_ LEFT_LINE : 5|2@0+ (1,0) [0|3] "" XXX + SG_ SET_ME_X01 : 7|2@0+ (1,0) [0|3] "" XXX + SG_ SET_ME_X01_2 : 11|2@0+ (1,0) [0|3] "" XXX + SG_ LDA_ALERT : 9|2@0+ (1,0) [0|3] "" XXX + SG_ TWO_BEEPS : 12|1@0+ (1,0) [0|1] "" XXX + SG_ ADJUSTING_CAMERA : 13|1@0+ (1,0) [0|1] "" XXX + SG_ LDA_MALFUNCTION : 15|1@0+ (1,0) [0|1] "" XXX + SG_ REPEATED_BEEPS : 32|1@0+ (1,0) [0|1] "" XXX + SG_ SET_ME_X0C : 23|8@0+ (1,0) [0|1] "" XXX + SG_ SET_ME_X2C : 47|8@0+ (1,0) [0|1] "" XXX + SG_ SET_ME_X38 : 55|8@0+ (1,0) [0|1] "" XXX + SG_ SET_ME_X02 : 63|8@0+ (1,0) [0|1] "" XXX + +BO_ 1553 UI_SEETING: 8 XXX + SG_ UNITS : 26|2@0+ (1,0) [0|3] "" XXX + +BO_ 1556 STEERING_LEVERS: 8 XXX + SG_ TURN_SIGNALS : 29|2@0+ (1,0) [0|3] "" XXX + +BO_ 1568 SEATS_DOORS: 8 XXX + SG_ SEATBELT_DRIVER_UNLATCHED : 62|1@0+ (1,0) [0|1] "" XXX + SG_ DOOR_OPEN_FL : 45|1@0+ (1,0) [0|1] "" XXX + SG_ DOOR_OPEN_RL : 42|1@0+ (1,0) [0|1] "" XXX + SG_ DOOR_OPEN_RR : 43|1@0+ (1,0) [0|1] "" XXX + SG_ DOOR_OPEN_FR : 44|1@0+ (1,0) [0|1] "" XXX + +BO_ 1570 LIGHT_STALK: 8 SCM + SG_ AUTO_HIGH_BEAM : 37|1@0+ (1,0) [0|1] "" XXX + +BO_ 1161 RSA1: 8 FCM + SG_ TSGN1 : 7|8@0+ (1,0) [0|0] "" XXX + SG_ TSGNGRY1 : 12|3@0+ (1,0) [0|0] "" XXX + SG_ TSGNHLT1 : 9|2@0+ (1,0) [0|0] "" XXX + SG_ SPDVAL1 : 23|8@0+ (1,0) [0|0] "kph" XXX + SG_ SPLSGN1 : 31|4@0+ (1,0) [0|0] "" XXX + SG_ SPLSGN2 : 27|4@0+ (1,0) [0|0] "" XXX + SG_ TSGN2 : 39|8@0+ (1,0) [0|0] "" XXX + SG_ TSGNGRY2 : 44|3@0+ (1,0) [0|0] "" XXX + SG_ TSGNHLT2 : 41|2@0+ (1,0) [0|0] "" XXX + SG_ SPDVAL2 : 55|8@0+ (1,0) [0|0] "" XXX + SG_ BZRRQ_P : 63|2@0+ (1,0) [0|0] "" XXX + SG_ BZRRQ_A : 61|2@0+ (1,0) [0|0] "" XXX + SG_ SYNCID1 : 59|4@0+ (1,0) [0|0] "" XXX + +BO_ 1162 RSA2: 8 FCM + SG_ TSGN3 : 7|8@0+ (1,0) [0|0] "" XXX + SG_ TSGNGRY3 : 12|3@0+ (1,0) [0|0] "" XXX + SG_ TSGNHLT3 : 9|2@0+ (1,0) [0|0] "" XXX + SG_ SPLSGN3 : 31|4@0+ (1,0) [0|0] "" XXX + SG_ SPLSGN4 : 27|4@0+ (1,0) [0|0] "" XXX + SG_ TSGN4 : 39|8@0+ (1,0) [0|0] "" XXX + SG_ TSGNGRY4 : 44|3@0+ (1,0) [0|0] "" XXX + SG_ TSGNHLT4 : 41|2@0+ (1,0) [0|0] "" XXX + SG_ DPSGNREQ : 54|1@0+ (1,0) [0|0] "" XXX + SG_ SGNNUMP : 53|3@0+ (1,0) [0|0] "" XXX + SG_ SGNNUMA : 50|3@0+ (1,0) [0|0] "" XXX + SG_ SPDUNT : 63|2@0+ (1,0) [0|0] "" XXX + SG_ TSRWMSG : 61|2@0+ (1,0) [0|0] "" XXX + SG_ SYNCID2 : 59|4@0+ (1,0) [0|0] "" XXX + +BO_ 1163 RSA3: 8 FCM + SG_ TSREQPD : 7|1@0+ (1,0) [0|0] "" XXX + SG_ TSRMSW : 6|1@0+ (1,0) [0|0] "" XXX + SG_ OTSGNNTM : 5|2@0+ (1,0) [0|0] "" XXX + SG_ NTLVLSPD : 3|2@0+ (1,0) [0|0] "" XXX + SG_ OVSPNTM : 1|2@0+ (1,0) [0|0] "" XXX + SG_ OVSPVALL : 11|4@0+ (1,-5) [0|0] "" XXX + SG_ OVSPVALM : 19|4@0+ (1,-5) [0|0] "" XXX + SG_ OVSPVALH : 27|4@0+ (1,-5) [0|0] "" XXX + SG_ TSRSPU : 33|2@0+ (1,0) [0|0] "" XXX + +CM_ SG_ 36 ACCEL_Y "unit is tbd"; +CM_ SG_ 36 YAW_RATE "verify"; +CM_ SG_ 36 STEERING_TORQUE "does not seem the steer torque, tbd"; +CM_ SG_ 37 STEER_FRACTION "1/15th of the signal STEER_ANGLE, which is 1.5 deg; note that 0x8 is never set"; +CM_ SG_ 37 STEER_RATE "factor is tbd"; +CM_ SG_ 466 ACCEL_NET "net acceleration produced by the system, given ACCEL_CMD, road grade and other factors"; +CM_ SG_ 467 SET_SPEED "43 kph are shown as 28mph, so conversion isnt perfect"; +CM_ SG_ 467 LOW_SPEED_LOCKOUT "in low speed lockout, system would always disengage below 28mph"; +CM_ SG_ 560 BRAKE_PRESSED "another brake pressed?"; +CM_ SG_ 608 STEER_TORQUE_DRIVER "driver torque"; +CM_ SG_ 608 STEER_OVERRIDE "set when driver torque exceeds a certain value"; +CM_ SG_ 614 ANGLE "set to measured angle when ipas control isn't active"; +CM_ SG_ 921 UI_SET_SPEED "set speed shown in UI with user set unit"; +CM_ SG_ 951 BRAKE_LIGHTS_ACC "brake lights when ACC commands decel"; +CM_ SG_ 1042 SET_ME_1 "unclear what this is, but it's always 1 in drive traces"; +CM_ SG_ 1042 REPEATED_BEEPS "recommended for fcw and other important alerts"; +CM_ SG_ 1161 SPDVAL1 "Numbers 0-199 is displayed, 200-254 displays circle without number and 255 is for no limit."; +CM_ SG_ 1161 SYNCID1 "counter from 1 to f at 1 Hz"; +CM_ SG_ 1161 SPDVAL2 "conditional speed value 70" +CM_ SG_ 1162 SGNNUMP "1 if SPDVAL1 is set, otherwise 0"; +CM_ SG_ 1162 SYNCID2 "counter from 1 to f at 1 Hz"; +CM_ SG_ 1163 TSREQPD "always 1"; +CM_ SG_ 1163 TSRMSW "always 1"; +CM_ SG_ 1163 OTSGNNTM "always 3"; +CM_ SG_ 1163 NTLVLSPD "always 3"; +CM_ SG_ 1163 OVSPNTM "always 3"; +CM_ SG_ 1163 OVSPVALL "-5 at start then 2 after 2 seconds"; +CM_ SG_ 1163 OVSPVALM "-5 at start then 5 after 2 seconds"; +CM_ SG_ 1163 OVSPVALH "-5 at start then 10 after 2 seconds"; +CM_ SG_ 1163 TSRSPU "always 1"; + +VAL_ 466 CRUISE_STATE 8 "active" 7 "standstill" 1 "off"; +VAL_ 467 LOW_SPEED_LOCKOUT 2 "low speed locked" 1 "ok"; +VAL_ 614 STATE 3 "enabled" 1 "disabled"; +VAL_ 614 DIRECTION_CMD 3 "right" 2 "center" 1 "left"; +VAL_ 921 CRUISE_CONTROL_STATE 2 "disabled" 11 "hold" 10 "hold_waiting_user_cmd" 6 "enabled" 5 "faulted"; +VAL_ 1042 LDA_ALERT 3 "hold with continuous beep" 2 "LDA unavailable" 1 "hold" 0 "none"; +VAL_ 1042 BARRIERS 3 "both" 2 "right" 1 "left" 0 "none"; +VAL_ 1042 RIGHT_LINE 3 "orange" 2 "faded" 1 "solid" 0 "none"; +VAL_ 1042 LEFT_LINE 3 "orange" 2 "faded" 1 "solid" 0 "none"; +VAL_ 1553 UNITS 1 "km" 2 "miles"; +VAL_ 1556 TURN_SIGNALS 3 "none" 2 "right" 1 "left"; +VAL_ 1161 TSGN1 1 "speed sign" 0 "none"; +VAL_ 1161 TSGN2 1 "speed sign" 0 "none"; +VAL_ 1161 SPLSGN2 15 "conditional blank" 4 "wet road" 5 "rain" 0 "none"; +VAL_ 1162 TSGN3 0 "none" 1 "speed sign" 2 "0 unlimited" 7 "unlimited" 16 "highway" 17 "no highway" 18 "motorway" 19 "no motorway" 20 "in city" 21 "outside city" 22 "pedestrian area" 23 "no pedestrian area" 65 "no overtaking left" 66 "no overtaking right" 67 "overtaking allowed again" 129 "no entry"; +VAL_ 1162 SPLSGN3 15 "conditional blank" 4 "wet road" 5 "rain" 0 "none"; + + +CM_ "CHFFR_METRIC 37 STEER_ANGLE STEER_ANGLE 0.36 180"; + +CM_ "lexus_rx_350_2016_pt.dbc starts here" + + + +BO_ 550 BRAKE_MODULE: 8 XXX + SG_ BRAKE_PRESSURE : 0|9@0+ (1,0) [0|511] "" XXX + SG_ BRAKE_POSITION : 16|9@0+ (1,0) [0|511] "" XXX + SG_ BRAKE_PRESSED : 37|1@0+ (1,0) [0|1] "" XXX + +BO_ 608 STEER_TORQUE_SENSOR: 8 XXX + SG_ STEER_TORQUE_EPS : 47|16@0- (0.73,0) [-20000|20000] "" 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 + +BO_ 610 EPS_STATUS: 5 EPS + SG_ IPAS_STATE : 3|4@0+ (1,0) [0|15] "" XXX + SG_ LKA_STATE : 31|7@0+ (1,0) [0|127] "" XXX + SG_ TYPE : 24|1@0+ (1,0) [0|1] "" XXX + SG_ CHECKSUM : 39|8@0+ (1,0) [0|255] "" XXX + +BO_ 956 GEAR_PACKET: 8 XXX + SG_ SPORT_ON : 2|1@0+ (1,0) [0|1] "" XXX + SG_ GEAR : 13|6@0+ (1,0) [0|63] "" XXX + SG_ ECON_ON : 40|1@0+ (1,0) [0|1] "" XXX + +BO_ 705 GAS_PEDAL: 8 XXX + SG_ GAS_PEDAL : 55|8@0+ (1,0) [0|255] "" XXX + + +CM_ SG_ 550 BRAKE_PRESSURE "seems prop to pedal force"; +CM_ SG_ 550 BRAKE_POSITION "seems proportional to pedal displacement, unclear the max value of 0x1c8"; +CM_ SG_ 610 TYPE "seems 1 on Corolla, 0 on all others"; +VAL_ 610 IPAS_STATE 5 "override" 3 "enabled" 1 "disabled" ; +VAL_ 610 LKA_STATE 25 "temporary_fault" 9 "temporary_fault2" 5 "active" 1 "standby" ; +VAL_ 956 SPORT_ON 0 "off" 1 "on" ; +VAL_ 956 GEAR 0 "D" 1 "S" 8 "N" 16 "R" 32 "P" ; +VAL_ 956 ECON_ON 0 "off" 1 "on" ; diff --git a/nissan_2017.dbc b/nissan_2017.dbc new file mode 100644 index 000000000..1d03b7ab5 --- /dev/null +++ b/nissan_2017.dbc @@ -0,0 +1,184 @@ +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_ 644 Speed_1: 8 XXX + SG_ Speed_FR : 7|16@0+ (0.0118,0) [0|65535] "" XXX + SG_ Speed_FL : 23|16@0+ (0.0118,0) [0|65535] "" XXX + SG_ Speed_Vehicle : 39|16@0+ (0.0245,0) [0|65535] "" XXX + +BO_ 645 WheelspeedRear: 8 XXX + SG_ RR : 7|16@0+ (0.00555,0) [0|65535] "KPH" XXX + SG_ RL : 23|16@0+ (0.00555,0) [0|65535] "KPH" XXX + +BO_ 768 STEER_TORQUE: 8 XXX + SG_ STEERING_TOURQUE : 0|7@1+ (1,0) [0|127] "" XXX + +BO_ 459 Maybe_RegenBraking: 8 XXX + +BO_ 372 Maybe_Gear_Selector: 8 XXX + SG_ Counter : 32|4@1+ (1,0) [0|15] "" XXX + +BO_ 374 Maybe_Motor_RPM_or_Speed: 8 XXX + SG_ Counter : 48|4@1+ (1,0) [0|15] "" XXX + +BO_ 460 Maybe_Brake_Related: 8 XXX + +BO_ 2 SteeringWheel: 8 XXX + SG_ Steering_RateChange : 23|8@0+ (1,0) [0|255] "" XXX + SG_ Always_07 : 31|8@0+ (1,0) [0|255] "" XXX + SG_ Steering_Angle : 0|16@1- (-0.1,0) [0|65535] "" XXX + +BO_ 384 Maybe_PowerInfo: 8 XXX + SG_ Unknown_Timer_PowerInfo : 48|4@1+ (1,0) [0|15] "" XXX + SG_ EnginePower : 27|12@0- (1,0) [0|1] "" XXX + SG_ RequestedAccel : 23|12@0- (1,0) [0|4294967295] "" XXX + +BO_ 1107 Lights: 8 XXX + SG_ RIGHT_BLINKER : 12|1@0+ (1,0) [0|1] "" XXX + SG_ LEFT_BLINKER : 11|1@0+ (1,0) [0|1] "" XXX + SG_ _HEADLIGHTS : 5|1@0+ (1,0) [0|1] "" XXX + +BO_ 666 WheelspeedFront: 8 XXX + SG_ _FL_WHEELSPEED : 39|16@0+ (0.01014,0) [0|65535] "" XXX + SG_ FR : 7|16@0+ (0.00555,0) [0|65535] "KPH" XXX + SG_ FL : 23|16@0+ (0.00555,0) [0|65535] "KPH" XXX + +BO_ 398 NEW_MSG_2: 8 XXX + +BO_ 389 NEW_MSG_3: 8 XXX + SG_ NEW_SIGNAL_1 : 15|8@0+ (1,0) [0|255] "" XXX + SG_ NEW_SIGNAL_2 : 22|6@0+ (1,0) [0|3] "" XXX + SG_ NEW_SIGNAL_4 : 47|8@0+ (1,0) [0|255] "" XXX + SG_ NEW_SIGNAL_5 : 55|4@0+ (1,0) [0|255] "" XXX + SG_ NEW_SIGNAL_6 : 63|8@0+ (1,0) [0|127] "" XXX + SG_ COUNTER : 48|4@1+ (1,0) [0|15] "" XXX + SG_ NEW_SIGNAL_3 : 30|8@0- (1,0) [0|255] "" XXX + +BO_ 397 NEW_MSG_4: 8 XXX + SG_ NEW_SIGNAL_1 : 7|16@0+ (1,0) [0|3] "" XXX + SG_ NEW_SIGNAL_2 : 23|16@0+ (1,0) [0|32767] "" XXX + SG_ NEW_SIGNAL_3 : 39|16@0+ (1,0) [0|65535] "" XXX + SG_ NEW_SIGNAL_4 : 55|16@0+ (1,0) [0|31] "" XXX + +BO_ 658 NEW_MSG_5: 8 XXX + SG_ NEW_SIGNAL_1 : 7|16@0+ (1,0) [0|255] "" XXX + +BO_ 855 NEW_MSG_6: 8 XXX + SG_ NEW_SIGNAL_1 : 7|8@0+ (1,0) [0|255] "" XXX + +BO_ 773 NEW_MSG_7: 8 XXX + SG_ NEW_SIGNAL_1 : 39|8@0+ (1,0) [0|255] "" XXX + SG_ NEW_SIGNAL_2 : 47|8@0+ (1,0) [0|255] "" XXX + +BO_ 851 SPEED_RELATED: 8 XXX + SG_ SPEED_RELATED : 7|16@0+ (0.01014,0) [0|65535] "" XXX + +BO_ 386 Accelerator: 8 XXX + SG_ Accelerator : 38|7@0+ (1,0) [0|127] "" XXX + +BO_ 347 ACCELSOMETHING: 8 XXX + SG_ PowerMaybe : 9|10@0+ (1,0) [0|1023] "" XXX + SG_ ACCELERATOR2 : 6|11@0+ (1,-800) [0|65535] "" XXX + +BO_ 346 ANOTHER_ACCEL: 8 XXX + SG_ ANOTHERACCEL : 23|10@0+ (1,0) [0|1023] "" XXX + SG_ Reverse_ACCEL : 25|10@0+ (1,0) [0|1023] "" XXX + +BO_ 348 FULLRANGEACCEL: 8 XXX + SG_ AccelFullRange : 47|10@0+ (1,0) [0|1023] "" XXX + SG_ Accel : 26|11@0+ (1,0) [0|2047] "" XXX + SG_ NEW_SIGNAL_1 : 7|8@0+ (1,0) [0|255] "" XXX + +BO_ 566 ANOTHERFULLRANGEACCEL: 8 XXX + SG_ ANOTHERFULLRANGEACCEL : 43|8@0+ (1,0) [0|1023] "" XXX + SG_ RPMORTORQUE : 31|8@0+ (1,0) [0|255] "" XXX + +BO_ 523 Yetyetanotheraccel: 8 XXX + SG_ ANOTHERREVERSEACCEL : 37|10@0+ (1,0) [0|1023] "" XXX + SG_ yetyetanotheraccel : 31|10@0+ (1,0) [0|255] "" XXX + +BO_ 779 ANOTHERRRFULLRANGEACCEL: 8 XXX + SG_ ANOTHERRRFULLRANGEACCEL : 47|8@0+ (1,0) [0|255] "" XXX + +BO_ 1108 Doors: 8 XXX + SG_ DOOR_CLOSED_RR : 40|1@0+ (1,0) [0|1] "" XXX + SG_ DOOR_OPEN_RR : 41|1@0+ (1,0) [0|1] "" XXX + SG_ DOOR_CLOSED_RL : 42|1@0+ (1,0) [0|1] "" XXX + SG_ DOOR_OPEN_RL : 43|1@0+ (1,0) [0|1] "" XXX + SG_ DOOR_CLOSED_FL : 44|1@0+ (1,0) [0|1] "" XXX + SG_ DOOR_OPEN_FL : 45|1@0+ (1,0) [0|1] "" XXX + SG_ DOOR_CLOSED_FR : 46|1@0+ (1,0) [0|3] "" XXX + SG_ DOOR_OPEN_FR : 47|1@0+ (1,0) [0|3] "" XXX + SG_ BOOT_OPEN : 55|1@0+ (1,0) [0|1] "" XXX + +BO_ 403 LKAS_OLD: 8 XXX + SG_ Checksum : 63|8@0+ (1,0) [0|255] "" XXX + SG_ Angle_2 : 32|13@0+ (1,-4000) [0|63] "" XXX + SG_ Counter : 48|4@1+ (1,0) [0|15] "" XXX + SG_ Angle_1 : 10|13@0+ (0.12,-480) [0|65535] "" XXX + SG_ Steering_Torque : 7|13@0+ (-1,4000) [0|65535] "" XXX + SG_ Torque_Command : 29|13@0+ (1,-4000) [0|255] "" XXX + +BO_ 412 NEW_MSG_9: 8 XXX + SG_ NEW_SIGNAL_1 : 7|16@0+ (1,0) [0|65535] "" XXX + SG_ NEW_SIGNAL_3 : 23|16@0+ (1,0) [0|65535] "" XXX + SG_ NEW_SIGNAL_2 : 39|8@0+ (1,0) [0|3] "" XXX + SG_ NEW_SIGNAL_4 : 47|8@0+ (1,0) [0|255] "" XXX + +BO_ 361 LKAS: 8 XXX + SG_ NEW_SIGNAL_4 : 39|8@0+ (1,0) [0|255] "" XXX + SG_ SET_X80 : 47|8@0+ (1,0) [0|255] "" XXX + SG_ LKA_Active : 52|1@0+ (1,0) [0|15] "" XXX + SG_ CRC : 63|8@0+ (1,0) [0|255] "" XXX + SG_ SET_0x80_2 : 31|8@0+ (1,0) [0|255] "" XXX + SG_ Counter : 51|4@0+ (1,0) [0|15] "" XXX + SG_ Des_Angle : 7|18@0+ (-0.01,1310) [0|255] "" XXX + +BO_ 438 ProPilot: 8 XXX + SG_ NEW_SIGNAL_2 : 11|4@0+ (1,0) [0|255] "" XXX + SG_ NEW_SIGNAL_4 : 27|4@0+ (1,0) [0|255] "" XXX + SG_ NEW_SIGNAL_8 : 63|8@0+ (1,0) [0|7] "" XXX + SG_ Counter : 55|4@0+ (1,0) [0|255] "" XXX + SG_ NEW_SIGNAL_6 : 47|8@0+ (1,0) [0|255] "" XXX + SG_ SET_3 : 32|2@1+ (1,0) [0|15] "" XXX + SG_ NEW_SIGNAL_1 : 7|12@0- (1,0) [0|255] "" XXX + SG_ NEW_SIGNAL_3 : 23|12@0- (-1,0) [0|255] "" XXX + SG_ CRUISE_ON : 36|1@0+ (1,0) [0|255] "" XXX + SG_ CRUISE_ACTIVATED : 38|1@0+ (1,0) [0|3] "" XXX + SG_ STEER_STATUS : 51|1@1+ (1,0) [0|3] "" XXX + From e3a266863db2bf49ef779b32782a398e5aba82d9 Mon Sep 17 00:00:00 2001 From: Vehicle Researcher Date: Mon, 22 Jul 2019 19:17:47 +0000 Subject: [PATCH 4/4] openpilot v0.6.1 release --- Pipfile | 3 + Pipfile.lock | 674 ++++++++++-------- README.md | 16 +- RELEASES.md | 7 + common/file_helpers.py | 17 +- common/fingerprints.py | 4 +- common/params.py | 3 + selfdrive/athena/athenad.py | 116 ++- selfdrive/boardd/boardd.cc | 9 +- selfdrive/can/parser.cc | 66 +- selfdrive/can/parser_pyx.pxd | 2 + selfdrive/can/parser_pyx.pyx | 16 +- selfdrive/can/tests/test_parser.py | 17 +- selfdrive/car/car_helpers.py | 18 +- selfdrive/car/chrysler/carstate.py | 4 +- selfdrive/car/chrysler/interface.py | 10 +- selfdrive/car/chrysler/radar_interface.py | 30 +- selfdrive/car/ford/carstate.py | 2 +- selfdrive/car/ford/interface.py | 9 +- selfdrive/car/ford/radar_interface.py | 29 +- selfdrive/car/gm/carstate.py | 2 +- selfdrive/car/gm/interface.py | 6 +- selfdrive/car/gm/radar_interface.py | 40 +- selfdrive/car/honda/carstate.py | 7 +- selfdrive/car/honda/interface.py | 10 +- selfdrive/car/honda/radar_interface.py | 43 +- selfdrive/car/hyundai/carstate.py | 4 +- selfdrive/car/hyundai/interface.py | 10 +- selfdrive/car/hyundai/radar_interface.py | 10 +- selfdrive/car/mock/interface.py | 2 +- selfdrive/car/mock/radar_interface.py | 10 +- selfdrive/car/subaru/carstate.py | 4 +- selfdrive/car/subaru/interface.py | 8 +- selfdrive/car/subaru/radar_interface.py | 9 +- selfdrive/car/toyota/carstate.py | 9 +- selfdrive/car/toyota/interface.py | 26 +- selfdrive/car/toyota/radar_interface.py | 39 +- selfdrive/car/toyota/values.py | 27 +- selfdrive/common/version.h | 2 +- selfdrive/controls/controlsd.py | 28 +- selfdrive/controls/lib/alerts.py | 7 + selfdrive/controls/lib/driver_monitor.py | 10 +- selfdrive/controls/lib/fcw.py | 11 +- selfdrive/controls/lib/planner.py | 4 +- selfdrive/controls/radard.py | 382 +++++----- selfdrive/locationd/.gitignore | 3 +- selfdrive/locationd/Makefile | 8 +- selfdrive/locationd/locationd_yawrate.cc | 345 ++------- selfdrive/locationd/locationd_yawrate.h | 34 + selfdrive/locationd/params_learner.cc | 59 +- selfdrive/locationd/paramsd.cc | 174 +++++ .../locationd/test/test_params_learner.py | 53 ++ selfdrive/loggerd/uploader.py | 4 +- selfdrive/manager.py | 84 ++- selfdrive/messaging.py | 34 +- selfdrive/registration.py | 3 +- selfdrive/test/plant/plant.py | 2 + selfdrive/thermald.py | 4 +- selfdrive/version.py | 1 + selfdrive/visiond/models/driving.cc | 7 + 60 files changed, 1519 insertions(+), 1058 deletions(-) create mode 100644 selfdrive/locationd/locationd_yawrate.h create mode 100644 selfdrive/locationd/paramsd.cc create mode 100755 selfdrive/locationd/test/test_params_learner.py diff --git a/Pipfile b/Pipfile index 614968710..6b9f7e95b 100644 --- a/Pipfile +++ b/Pipfile @@ -96,6 +96,9 @@ fastcluster = "==1.1.25" backports-abc = "*" pygame = "*" simplejson = "*" +python-logstash-async = "*" +pandas = "*" +seaborn = "*" [packages] overpy = {git = "https://github.com/commaai/python-overpy.git",ref = "f86529af402d4642e1faeb146671c40284007323"} diff --git a/Pipfile.lock b/Pipfile.lock index e4623df10..30c43e286 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "72c6a6eac19abf85ca5f272d04761f8336150d5bec599423c4b16891c99cb0bf" + "sha256": "89070d7d9478ac9e6ad2c9848aaf724cb7362a1de4af9f8fb8c40be5f37c043d" }, "pipfile-spec": 6, "requires": { @@ -43,15 +43,15 @@ "sha256:9d98697f088eb1b0fa451391f91afb5e3ebde16bbdb272819fd091151fda4f1a", "sha256:f0b0e4eba956de51238e17573b7087e852dfe9854afd2e9c873f73fc0ca0a6dd" ], - "markers": "python_version < '3.2'", + "markers": "python_version == '2.7'", "version": "==1.5" }, "certifi": { "hashes": [ - "sha256:59b7658e26ca9c7339e00f8f4636cdfe59d34fa37b9b04f6f9e9926b3cece1a5", - "sha256:b26104d6835d1f5e49452a26eb2ff87fe7090b89dfcaee5ea2212697e1e1d7ae" + "sha256:046832c04d4e752f37383b628bc601a7ea7211496b4638f6514d0e5b9acc4939", + "sha256:945e3ba63a0b9f577b1395204e13c3a231f9bc0223888be653286534e5873695" ], - "version": "==2019.3.9" + "version": "==2019.6.16" }, "cffi": { "hashes": [ @@ -149,37 +149,37 @@ }, "cython": { "hashes": [ - "sha256:0afa0b121b89de619e71587e25702e2b7068d7da2164c47e6eee80c17823a62f", - "sha256:1c608ba76f7a20cc9f0c021b7fe5cb04bc1a70327ae93a9298b1bc3e0edddebe", - "sha256:26229570d6787ff3caa932fe9d802960f51a89239b990d275ae845405ce43857", - "sha256:2a9deafa437b6154cac2f25bb88e0bfd075a897c8dc847669d6f478d7e3ee6b1", - "sha256:2f28396fbce6d9d68a40edbf49a6729cf9d92a4d39ff0f501947a89188e9099f", - "sha256:3983dd7b67297db299b403b29b328d9e03e14c4c590ea90aa1ad1d7b35fb178b", - "sha256:4100a3f8e8bbe47d499cdac00e56d5fe750f739701ea52dc049b6c56f5421d97", - "sha256:51abfaa7b6c66f3f18028876713c8804e73d4c2b6ceddbcbcfa8ec62429377f0", - "sha256:61c24f4554efdb8fb1ac6c8e75dab301bcdf2b7b739ed0c2b267493bb43163c5", - "sha256:700ccf921b2fdc9b23910e95b5caae4b35767685e0812343fa7172409f1b5830", - "sha256:7b41eb2e792822a790cb2a171df49d1a9e0baaa8e81f58077b7380a273b93d5f", - "sha256:803987d3b16d55faa997bfc12e8b97f1091f145930dee229b020487aed8a1f44", - "sha256:99af5cfcd208c81998dcf44b3ca466dee7e17453cfb50e98b87947c3a86f8753", - "sha256:9faea1cca34501c7e139bc7ef8e504d532b77865c58592493e2c154a003b450f", - "sha256:a7ba4c9a174db841cfee9a0b92563862a0301d7ca543334666c7266b541f141a", - "sha256:b26071c2313d1880599c69fd831a07b32a8c961ba69d7ccbe5db1cd8d319a4ca", - "sha256:b49dc8e1116abde13a3e6a9eb8da6ab292c5a3325155fb872e39011b110b37e6", - "sha256:bd40def0fd013569887008baa6da9ca428e3d7247adeeaeada153006227bb2e7", - "sha256:bfd0db770e8bd4e044e20298dcae6dfc42561f85d17ee546dcd978c8b23066ae", - "sha256:c2fad1efae5889925c8fd7867fdd61f59480e4e0b510f9db096c912e884704f1", - "sha256:c81aea93d526ccf6bc0b842c91216ee9867cd8792f6725a00f19c8b5837e1715", - "sha256:da786e039b4ad2bce3d53d4799438cf1f5e01a0108f1b8d78ac08e6627281b1a", - "sha256:deab85a069397540987082d251e9c89e0e5b2e3e044014344ff81f60e211fc4b", - "sha256:e3f1e6224c3407beb1849bdc5ae3150929e593e4cffff6ca41c6ec2b10942c80", - "sha256:e74eb224e53aae3943d66e2d29fe42322d5753fd4c0641329bccb7efb3a46552", - "sha256:ee697c7ea65cb14915a64f36874da8ffc2123df43cf8bc952172e04a26656cd6", - "sha256:f37792b16d11606c28e428460bd6a3d14b8917b109e77cdbe4ca78b0b9a52c87", - "sha256:fd2906b54cbf879c09d875ad4e4687c58d87f5ed03496063fec1c9065569fd5d" + "sha256:04ebf16df9406d3279a2489c3327803c782d9e17637d525bfb44ecf5ec65850f", + "sha256:1486ec88d1c73dea3846a5640054018b002608e04a791ccbd2082a47bce4440a", + "sha256:20da832a5e9a8e93d1e1eb64650258956723940968eb585506531719b55b804f", + "sha256:2464688b523d7a133b52cf1343c1c595b92fc6554af1015f74b9e49951e992d4", + "sha256:27827b68a8359e9ab6bf683c68d8ee79863a0c94a577acf56aa02cc302e16f51", + "sha256:27deeeeca0fd8933af07923e809c8fed0763d150a4fdd4082932a33b8c874ed6", + "sha256:31f4da785d5e09deb852ea59795a629c5befb6040929e7880c6f63e6668246ce", + "sha256:4828cf8fa638c35139e643f30201b240c0d156b1b9967a7321ae42d721d7224c", + "sha256:48b365e32cc5639ae2c239d7bd4f8a1d920a13a7ae92113c4c938903c9400147", + "sha256:4eb71856c1d1b33083df9318fd30143470ad6f0d1b9ad2ee61a120710842d28b", + "sha256:5b06ef8422d27d8128f8f80bdefa111eadcab246fba1d668720af4f0b97b7a0e", + "sha256:71c553640e1ddaaf143e38dbc6cd1863fa3c0738fb1830a9aaffba9a51838f30", + "sha256:73e2742ee1f923c5f213183bf493901f9630e395634fce5b739a53b7dc5d64be", + "sha256:82a632bc02063eff0b8e7ff3089aa3d912d1c7499709f51c8f04f57c8832cfe6", + "sha256:977ca1ac059e4d4a4bf5fe2224986baf42b69290453eda44822606f4deae6515", + "sha256:a7e6217d0dd864a7cc4f457172766864496efd64d24d4980df1521f75f992761", + "sha256:ad0ed7dd5dff76eb3aae8c18d95b1c9f885a91a92132728051a704fb8060d08c", + "sha256:b1b8eda9e931f0ca1aadb95a890811bdf530407e48c962643b85675329d99abf", + "sha256:cec99c79205131da3ee75becea1f3f55c57bf6a1c500431de9ae7a32ac8a5cc4", + "sha256:d4bbdaa6f61ce2ef26535a7d473d6ffa6e413013c5c580af999546bf1627ae11", + "sha256:d8bdb4208975b12048bdace46e9dd8e3dda3872432f95b53789700a1330e6060", + "sha256:dce0362ff9b61f8411d1efc9e16fc528dadbd3707a557561992457f5cb446297", + "sha256:defbbbf5653629ce5cc54091ce49c6830da8d3104de53ed2169c9efcb0720f27", + "sha256:e0c53a7e2b6d82ec3c26c009c937fc88eb8c7edf000c54334261beaf56bb08f2", + "sha256:e1065bacfe5303f107896e63263537dee90920d26050f2e23c4af12c37da2db6", + "sha256:e142837c4212c0b2c71e6773cb6740828922806b4c00ee4215be3ceb558671e6", + "sha256:f4cbbab28c93ffee6ec929cf0826f0b11d2488e53a708d51142a5e62f8cd9806", + "sha256:fa8f63b6551621eea9efea4db37ae401104352f0ebaee32f7d20be88cbe589c3" ], "index": "pypi", - "version": "==0.29.10" + "version": "==0.29.12" }, "enum34": { "hashes": [ @@ -193,19 +193,19 @@ }, "flask": { "hashes": [ - "sha256:ad7c6d841e64296b962296c2c2dabc6543752985727af86a975072dea984b6f3", - "sha256:e7d32475d1de5facaa55e3958bc4ec66d3762076b074296aa50ef8fdc5b9df61" + "sha256:13f9f196f330c7c2c5d7a5cf91af894110ca0215ac051b5844701f2bfd934d52", + "sha256:45eb5a6fd193d6cf7e0cf5d8a5b31f83d5faae0293695626f539a823e93b13f6" ], "index": "pypi", - "version": "==1.0.3" + "version": "==1.1.1" }, "futures": { "hashes": [ - "sha256:9ec02aa7d674acb8618afb127e27fde7fc68994c0437ad759fa094a574adb265", - "sha256:ec0a6cb848cc212002b9828c3e34c675e0c9ff6741dc445cab6fdd4e1085d1f1" + "sha256:49b3f5b064b6e3afc3316421a3f25f66c137ae88f068abbf72830170033c5e16", + "sha256:7e033af76a5e35f58e56da7a91e687706faf4e7bdfb2cbc3f2cca6b9bcda9794" ], "markers": "python_version < '3.2'", - "version": "==3.2.0" + "version": "==3.3.0" }, "gunicorn": { "hashes": [ @@ -240,10 +240,10 @@ }, "isort": { "hashes": [ - "sha256:c40744b6bc5162bbb39c1257fe298b7a393861d50978b565f3ccd9cb9de0182a", - "sha256:f57abacd059dc3bd666258d1efb0377510a89777fda3e3274e3c01f7c03ae22d" + "sha256:54da7e92468955c4fceacd0c86bd0ec997b0e1ee80d97f67c35a78b719dccab1", + "sha256:6e811fcb295968434526407adb8796944f1988c5b65e8139058f2014cbe100fd" ], - "version": "==4.3.20" + "version": "==4.3.21" }, "itsdangerous": { "hashes": [ @@ -470,11 +470,11 @@ }, "pylint": { "hashes": [ - "sha256:02c2b6d268695a8b64ad61847f92e611e6afcff33fd26c3a2125370c4662905d", - "sha256:ee1e85575587c5b58ddafa25e1c1b01691ef172e139fc25585e5d3f02451da93" + "sha256:367e3d49813d349a905390ac27989eff82ab84958731c5ef0bef867452cfdc42", + "sha256:97a42df23d436c70132971d1dcb9efad2fe5c0c6add55b90161e773caf729300" ], "index": "pypi", - "version": "==1.9.4" + "version": "==1.9.5" }, "pyserial": { "hashes": [ @@ -511,34 +511,34 @@ }, "pyzmq": { "hashes": [ - "sha256:1651e52ed91f0736afd6d94ef9f3259b5534ce8beddb054f3d5ca989c4ef7c4f", - "sha256:5ccb9b3d4cd20c000a9b75689d5add8cd3bce67fcbd0f8ae1b59345247d803af", - "sha256:5e120c4cd3872e332fb35d255ad5998ebcee32ace4387b1b337416b6b90436c7", - "sha256:5e2a3707c69a7281a9957f83718815fd74698cba31f6d69f9ed359921f662221", - "sha256:63d51add9af8d0442dc90f916baf98fdc04e3b0a32afec4bfc83f8d85e72959f", - "sha256:65c5a0bdc49e20f7d6b03a661f71e2fda7a99c51270cafe71598146d09810d0d", - "sha256:66828fabe911aa545d919028441a585edb7c9c77969a5fea6722ef6e6ece38ab", - "sha256:7d79427e82d9dad6e9b47c0b3e7ae5f9d489b1601e3a36ea629bb49501a4daf3", - "sha256:824ee5d3078c4eae737ffc500fbf32f2b14e6ec89b26b435b7834febd70120cf", - "sha256:89dc0a83cccec19ff3c62c091e43e66e0183d1e6b4658c16ee4e659518131494", - "sha256:8b319805f6f7c907b101c864c3ca6cefc9db8ce0791356f180b1b644c7347e4c", - "sha256:90facfb379ab47f94b19519c1ecc8ec8d10813b69d9c163117944948bdec5d15", - "sha256:a0a178c7420021fc0730180a914a4b4b3092ce9696ceb8e72d0f60f8ce1655dd", - "sha256:a7a89591ae315baccb8072f216614b3e59aed7385aef4393a6c741783d6ee9cf", - "sha256:ba2578f0ae582452c02ed9fac2dc477b08e80ce05d2c0885becf5fff6651ccb0", - "sha256:c69b0055c55702f5b0b6b354133e8325b9a56dbc80e1be2d240bead253fb9825", - "sha256:ca434e1858fe222380221ddeb81e86f45522773344c9da63c311d17161df5e06", - "sha256:d4b8ecfc3d92f114f04d5c40f60a65e5196198b827503341521dda12d8b14939", - "sha256:d706025c47b09a54f005953ebe206f6d07a22516776faa4f509aaff681cc5468", - "sha256:d8f27e958f8a2c0c8ffd4d8855c3ce8ac3fa1e105f0491ce31729aa2b3229740", - "sha256:dbd264298f76b9060ce537008eb989317ca787c857e23cbd1b3ddf89f190a9b1", - "sha256:e926d66f0df8fdbf03ba20583af0f215e475c667fb033d45fd031c66c63e34c9", - "sha256:efc3bd48237f973a749f7312f68062f1b4ca5c2032a0673ca3ea8e46aa77187b", - "sha256:f59bc782228777cbfe04555707a9c56d269c787ed25d6d28ed9d0fbb41cb1ad2", - "sha256:f8da5322f4ff5f667a0d5a27e871b560c6637153c81e318b35cb012b2a98835c" + "sha256:00dd015159eaeb1c0731ad49310e1f5d839c9a35a15e4f3267f5052233fad99b", + "sha256:03913b6beb8e7b417b9910b0ee1fd5d62e9626d218faefbe879d70714ceab1a2", + "sha256:13f17386df81d5e6efb9a4faea341d8de22cdc82e49a326dded26e33f42a3112", + "sha256:16c6281d96885db1e15f7047ddc1a8f48ff4ea35d31ca709f4d2eb39f246d356", + "sha256:17efab4a804e31f58361631256d660214204046f9e2b962738b171b9ad674ea7", + "sha256:2b79919ddeff3d3c96aa6087c21d294c8db1c01f6bfeee73324944683685f419", + "sha256:2f832e4711657bb8d16ea1feba860f676ec5f14fb9fe3b449b5953a60e89edae", + "sha256:31a11d37ac73107363b47e14c94547dbfc6a550029c3fe0530be443199026fc2", + "sha256:33a3e928e6c3138c675e1d6702dd11f6b7050177d7aab3fc322db6e1d2274490", + "sha256:34a38195a6d3a9646cbcdaf8eb245b4d935c7a57f7e1b3af467814bc1a92467e", + "sha256:42900054f1500acef6df7428edf806abbf641bf92eb9ceded24aa863397c3bae", + "sha256:4ccc7f3c63aa9d744dadb62c49eda2d0e7de55649b80c45d7c684d70161a69af", + "sha256:5b220c37c346e6575db8c88a940c1fc234f99ce8e0068c408919bb8896c4b6d2", + "sha256:6074848da5c8b44a1ca40adf75cf65aa92bc80f635e8249aa8f37a69b2b9b6f5", + "sha256:61a4155964bd4a14ef95bf46cb1651bcf8dcbbed8c0108e9c974c1fcbb57788f", + "sha256:62b5774688326600c52f587f7a033ca6b6284bef4c8b1b5fda32480897759eac", + "sha256:65a9ffa4f9f085d696f16fd7541f34b3c357d25fe99c90e3bce2ea59c3b5b4b6", + "sha256:76a077d2c30f8adc5e919a55985a784b96aeca69b53c1ea6fd5723d3ae2e6f53", + "sha256:8e5b4c51557071d6379d6dc1f54f35e9f6a137f5e84e102efb869c8d3c13c8ff", + "sha256:917f73e07cc04f0678a96d93e7bb8b1adcccdde9ccfe202e622814f4d1d1ecfd", + "sha256:91c75d3c4c357f9643e739db9e79ab9681b2f6ae8ec5678d6ef2ea0d01532596", + "sha256:923dd91618b100bb4c92ab9ed7b65825a595b8524a094ce03c7cb2aaae7d353b", + "sha256:9849054e0355e2bc7f4668766a25517ba76095031c9ff5e39ae8949cee5bb024", + "sha256:c9d453933f0e3f44b9759189f2a18aa765f7f1a4345c727c18ebe8ad0d748d26", + "sha256:cb7514936277abce64c2f4c56883e5704d85ed04d98d2d432d1c6764003bb003" ], "index": "pypi", - "version": "==18.0.1" + "version": "==18.0.2" }, "raven": { "hashes": [ @@ -597,11 +597,11 @@ }, "tqdm": { "hashes": [ - "sha256:0a860bf2683fdbb4812fe539a6c22ea3f1777843ea985cb8c3807db448a0f7ab", - "sha256:e288416eecd4df19d12407d0c913cbf77aa8009d7fddb18f632aded3bdbdda6b" + "sha256:14a285392c32b6f8222ecfbcd217838f88e11630affe9006cd0e94c7eff3cb61", + "sha256:25d4c0ea02a305a688e7e9c2cdc8f862f989ef2a4701ab28ee963295f5b109ab" ], "index": "pypi", - "version": "==4.32.1" + "version": "==4.32.2" }, "urllib3": { "hashes": [ @@ -613,10 +613,10 @@ }, "utm": { "hashes": [ - "sha256:a6608a67df84418fd959a79b228b90ab55b2ae877827f9c210947104c5a75d0e" + "sha256:07e55707ed660eec1ae983bd54a406c437962618a6261b38d70592fe30f5f508" ], "index": "pypi", - "version": "==0.4.2" + "version": "==0.5.0" }, "websocket-client": { "hashes": [ @@ -628,16 +628,16 @@ }, "werkzeug": { "hashes": [ - "sha256:865856ebb55c4dcd0630cdd8f3331a1847a819dda7e8c750d3db6f2aa6c0209c", - "sha256:a0b915f0815982fb2a09161cb8f31708052d0951c3ba433ccc5e1aa276507ca6" + "sha256:87ae4e5b5366da2347eb3116c0e6c681a0e939a33b2805e2c0cbd282664932c4", + "sha256:a13b74dd3c45f758d4ebdb224be8f1ab8ef58b3c0ffc1783a8c7d9f4f50227e6" ], - "version": "==0.15.4" + "version": "==0.15.5" }, "wrapt": { "hashes": [ - "sha256:4aea003270831cceb8a90ff27c4031da6ead7ec1886023b80ce0dfe0adf61533" + "sha256:565a021fd19419476b9362b05eeaa094178de64f8361e44468f9e9d7843901e1" ], - "version": "==1.11.1" + "version": "==1.11.2" } }, "develop": { @@ -649,19 +649,19 @@ }, "adal": { "hashes": [ - "sha256:82e84fa0b442caf8131f1e87a7ebee2546f57ab16a8917a599a02b6e455cb1b0", - "sha256:b6edd095be66561382bdaa59d40b04490e93149fb3b7fa44c1fa5504eed5b8b9" + "sha256:5a7f1e037c6290c6d7609cab33a9e5e988c2fbec5c51d1c4c649ee3faff37eaf", + "sha256:fd17e5661f60634ddf96a569b95d34ccb8a98de60593d729c28bdcfe360eaad1" ], - "version": "==1.2.1" + "version": "==1.2.2" }, "aenum": { "hashes": [ - "sha256:3df9b84cce5dc9ed77c337079f97b66c44c0053eb87d6f4d46b888dc45801e38", - "sha256:7a77c205c4bc9d7fe9bd73b3193002d724aebf5909fa0d297534208953891ec8", - "sha256:a3208e4b28db3a7b232ff69b934aef2ea1bf27286d9978e1e597d46f490e4687" + "sha256:058f0cfaf911899dc21b334362047df74ce989335dd8dff8e4be1a6313b15232", + "sha256:6af970173d9b4ac0384ad7d1cfe9523eeb9a3578793e1664090c13cb59df6469", + "sha256:80f14366578d84f6bccb0670259744cb3a7f2ab504480c306238a23cdd569457" ], "index": "pypi", - "version": "==2.1.2" + "version": "==2.2.0" }, "amqp": { "hashes": [ @@ -760,7 +760,7 @@ "sha256:9d98697f088eb1b0fa451391f91afb5e3ebde16bbdb272819fd091151fda4f1a", "sha256:f0b0e4eba956de51238e17573b7087e852dfe9854afd2e9c873f73fc0ca0a6dd" ], - "markers": "python_version < '3.2'", + "markers": "python_version == '2.7'", "version": "==1.5" }, "backports.lzma": { @@ -817,18 +817,18 @@ }, "boto3": { "hashes": [ - "sha256:794a9a4b6a9e40c1ac57a377de609872d28d62afe4295c48cdc1b1c92f96ab8e", - "sha256:962b078568cc520869ea2842f307864c9abc30ad5ed160e12b2a89debf220161" + "sha256:34a8ddb7247316be6ea94c7eeee41212312d250d99bf668fcd6748629b578622", + "sha256:71f3554cc69fa20be06cf20d6c9e0d8095d7c40695b48618676c3cd9a5ba0783" ], "index": "pypi", - "version": "==1.9.168" + "version": "==1.9.189" }, "botocore": { "hashes": [ - "sha256:675f2b66af486dd02f5825601bb0c8378773999f8705c6f75450849ca41fed80", - "sha256:c3fc314c0e0aa13aa024d272d991e23d37550050abf96b3c7dea889ed1743723" + "sha256:4febbf206d1dc8b8299aa211d8e382d5bf3f22097855b9f98d5e8c401ef8192b", + "sha256:b62ab3e4e98e075fc9e8e8fd4e8f5b92ebf311a6dc9f7578650938c7bc94e592" ], - "version": "==1.12.168" + "version": "==1.12.189" }, "celery": { "hashes": [ @@ -840,10 +840,10 @@ }, "certifi": { "hashes": [ - "sha256:59b7658e26ca9c7339e00f8f4636cdfe59d34fa37b9b04f6f9e9926b3cece1a5", - "sha256:b26104d6835d1f5e49452a26eb2ff87fe7090b89dfcaee5ea2212697e1e1d7ae" + "sha256:046832c04d4e752f37383b628bc601a7ea7211496b4638f6514d0e5b9acc4939", + "sha256:945e3ba63a0b9f577b1395204e13c3a231f9bc0223888be653286534e5873695" ], - "version": "==2019.3.9" + "version": "==2019.6.16" }, "cffi": { "hashes": [ @@ -947,37 +947,37 @@ }, "cython": { "hashes": [ - "sha256:0afa0b121b89de619e71587e25702e2b7068d7da2164c47e6eee80c17823a62f", - "sha256:1c608ba76f7a20cc9f0c021b7fe5cb04bc1a70327ae93a9298b1bc3e0edddebe", - "sha256:26229570d6787ff3caa932fe9d802960f51a89239b990d275ae845405ce43857", - "sha256:2a9deafa437b6154cac2f25bb88e0bfd075a897c8dc847669d6f478d7e3ee6b1", - "sha256:2f28396fbce6d9d68a40edbf49a6729cf9d92a4d39ff0f501947a89188e9099f", - "sha256:3983dd7b67297db299b403b29b328d9e03e14c4c590ea90aa1ad1d7b35fb178b", - "sha256:4100a3f8e8bbe47d499cdac00e56d5fe750f739701ea52dc049b6c56f5421d97", - "sha256:51abfaa7b6c66f3f18028876713c8804e73d4c2b6ceddbcbcfa8ec62429377f0", - "sha256:61c24f4554efdb8fb1ac6c8e75dab301bcdf2b7b739ed0c2b267493bb43163c5", - "sha256:700ccf921b2fdc9b23910e95b5caae4b35767685e0812343fa7172409f1b5830", - "sha256:7b41eb2e792822a790cb2a171df49d1a9e0baaa8e81f58077b7380a273b93d5f", - "sha256:803987d3b16d55faa997bfc12e8b97f1091f145930dee229b020487aed8a1f44", - "sha256:99af5cfcd208c81998dcf44b3ca466dee7e17453cfb50e98b87947c3a86f8753", - "sha256:9faea1cca34501c7e139bc7ef8e504d532b77865c58592493e2c154a003b450f", - "sha256:a7ba4c9a174db841cfee9a0b92563862a0301d7ca543334666c7266b541f141a", - "sha256:b26071c2313d1880599c69fd831a07b32a8c961ba69d7ccbe5db1cd8d319a4ca", - "sha256:b49dc8e1116abde13a3e6a9eb8da6ab292c5a3325155fb872e39011b110b37e6", - "sha256:bd40def0fd013569887008baa6da9ca428e3d7247adeeaeada153006227bb2e7", - "sha256:bfd0db770e8bd4e044e20298dcae6dfc42561f85d17ee546dcd978c8b23066ae", - "sha256:c2fad1efae5889925c8fd7867fdd61f59480e4e0b510f9db096c912e884704f1", - "sha256:c81aea93d526ccf6bc0b842c91216ee9867cd8792f6725a00f19c8b5837e1715", - "sha256:da786e039b4ad2bce3d53d4799438cf1f5e01a0108f1b8d78ac08e6627281b1a", - "sha256:deab85a069397540987082d251e9c89e0e5b2e3e044014344ff81f60e211fc4b", - "sha256:e3f1e6224c3407beb1849bdc5ae3150929e593e4cffff6ca41c6ec2b10942c80", - "sha256:e74eb224e53aae3943d66e2d29fe42322d5753fd4c0641329bccb7efb3a46552", - "sha256:ee697c7ea65cb14915a64f36874da8ffc2123df43cf8bc952172e04a26656cd6", - "sha256:f37792b16d11606c28e428460bd6a3d14b8917b109e77cdbe4ca78b0b9a52c87", - "sha256:fd2906b54cbf879c09d875ad4e4687c58d87f5ed03496063fec1c9065569fd5d" + "sha256:04ebf16df9406d3279a2489c3327803c782d9e17637d525bfb44ecf5ec65850f", + "sha256:1486ec88d1c73dea3846a5640054018b002608e04a791ccbd2082a47bce4440a", + "sha256:20da832a5e9a8e93d1e1eb64650258956723940968eb585506531719b55b804f", + "sha256:2464688b523d7a133b52cf1343c1c595b92fc6554af1015f74b9e49951e992d4", + "sha256:27827b68a8359e9ab6bf683c68d8ee79863a0c94a577acf56aa02cc302e16f51", + "sha256:27deeeeca0fd8933af07923e809c8fed0763d150a4fdd4082932a33b8c874ed6", + "sha256:31f4da785d5e09deb852ea59795a629c5befb6040929e7880c6f63e6668246ce", + "sha256:4828cf8fa638c35139e643f30201b240c0d156b1b9967a7321ae42d721d7224c", + "sha256:48b365e32cc5639ae2c239d7bd4f8a1d920a13a7ae92113c4c938903c9400147", + "sha256:4eb71856c1d1b33083df9318fd30143470ad6f0d1b9ad2ee61a120710842d28b", + "sha256:5b06ef8422d27d8128f8f80bdefa111eadcab246fba1d668720af4f0b97b7a0e", + "sha256:71c553640e1ddaaf143e38dbc6cd1863fa3c0738fb1830a9aaffba9a51838f30", + "sha256:73e2742ee1f923c5f213183bf493901f9630e395634fce5b739a53b7dc5d64be", + "sha256:82a632bc02063eff0b8e7ff3089aa3d912d1c7499709f51c8f04f57c8832cfe6", + "sha256:977ca1ac059e4d4a4bf5fe2224986baf42b69290453eda44822606f4deae6515", + "sha256:a7e6217d0dd864a7cc4f457172766864496efd64d24d4980df1521f75f992761", + "sha256:ad0ed7dd5dff76eb3aae8c18d95b1c9f885a91a92132728051a704fb8060d08c", + "sha256:b1b8eda9e931f0ca1aadb95a890811bdf530407e48c962643b85675329d99abf", + "sha256:cec99c79205131da3ee75becea1f3f55c57bf6a1c500431de9ae7a32ac8a5cc4", + "sha256:d4bbdaa6f61ce2ef26535a7d473d6ffa6e413013c5c580af999546bf1627ae11", + "sha256:d8bdb4208975b12048bdace46e9dd8e3dda3872432f95b53789700a1330e6060", + "sha256:dce0362ff9b61f8411d1efc9e16fc528dadbd3707a557561992457f5cb446297", + "sha256:defbbbf5653629ce5cc54091ce49c6830da8d3104de53ed2169c9efcb0720f27", + "sha256:e0c53a7e2b6d82ec3c26c009c937fc88eb8c7edf000c54334261beaf56bb08f2", + "sha256:e1065bacfe5303f107896e63263537dee90920d26050f2e23c4af12c37da2db6", + "sha256:e142837c4212c0b2c71e6773cb6740828922806b4c00ee4215be3ceb558671e6", + "sha256:f4cbbab28c93ffee6ec929cf0826f0b11d2488e53a708d51142a5e62f8cd9806", + "sha256:fa8f63b6551621eea9efea4db37ae401104352f0ebaee32f7d20be88cbe589c3" ], "index": "pypi", - "version": "==0.29.10" + "version": "==0.29.12" }, "datadog": { "hashes": [ @@ -1098,11 +1098,11 @@ }, "flask": { "hashes": [ - "sha256:ad7c6d841e64296b962296c2c2dabc6543752985727af86a975072dea984b6f3", - "sha256:e7d32475d1de5facaa55e3958bc4ec66d3762076b074296aa50ef8fdc5b9df61" + "sha256:13f9f196f330c7c2c5d7a5cf91af894110ca0215ac051b5844701f2bfd934d52", + "sha256:45eb5a6fd193d6cf7e0cf5d8a5b31f83d5faae0293695626f539a823e93b13f6" ], "index": "pypi", - "version": "==1.0.3" + "version": "==1.1.1" }, "flask-cors": { "hashes": [ @@ -1145,11 +1145,11 @@ }, "futures": { "hashes": [ - "sha256:9ec02aa7d674acb8618afb127e27fde7fc68994c0437ad759fa094a574adb265", - "sha256:ec0a6cb848cc212002b9828c3e34c675e0c9ff6741dc445cab6fdd4e1085d1f1" + "sha256:49b3f5b064b6e3afc3316421a3f25f66c137ae88f068abbf72830170033c5e16", + "sha256:7e033af76a5e35f58e56da7a91e687706faf4e7bdfb2cbc3f2cca6b9bcda9794" ], "markers": "python_version < '3.2'", - "version": "==3.2.0" + "version": "==3.3.0" }, "gast": { "hashes": [ @@ -1228,40 +1228,40 @@ }, "grpcio": { "hashes": [ - "sha256:0232add03144dd3cf9b660e2718244cb8e175370dca4d3855cb4e489a7811b53", - "sha256:0f20e6dcb1b8662cdca033bb97c0a8116a5343e3ebc7f71c5fe7f89039978350", - "sha256:10b07a623d33d4966f45c85d410bc6a79c5ac6341f06c3beda6c22be12cbfe07", - "sha256:10c0476d5a52d21f402fc073745dc43b87cc8e080a1f49bbff4e1059019310fb", - "sha256:289dae0b35c59d191c524e976dd0a6f8c995d2062e72621eb866ad0f4472a635", - "sha256:2be726f16142d358a0df1e81d583d6820ee561a7856a79cca2fbe49989308be7", - "sha256:4338d2a81f5b4ca022e085040b3cfce19419a5ce44aa7e6810ac1df05365bed7", - "sha256:4c535b46f20e66bee3097583231977e721acdfcb1671d1490c99b7be8902ce18", - "sha256:557154aef70a0e979700cc9528bc8b606b668084a29a0d57dbc4b06b078a2f1c", - "sha256:5bfdd7e6647498f979dc46583723c852d97b25afe995d55aa1c76a5f9816bc1f", - "sha256:87d8943ae7aa6ca5bbad732867d7f17d2550e4966a0c15b52088e8b579422e47", - "sha256:89d8719d8de4d137678f7caa979e1b0a6fd4026f8096ceef8c2d164bbabefaf2", - "sha256:9c3f4af989ce860710ac1864dc2e867dd87e6cee51a2368df1b253596868e52f", - "sha256:9da52c3c728883aee429bb7c315049f50b2139f680cd86bb1165418e4f93a982", - "sha256:9e9736659987beab42d18525ed10d21f80a1ba8389eac03425fbfd5684e6bbf0", - "sha256:9ebcbb1a054cab362d29d3be571d43d6b9b23302d9fc4b43e5327000da1680a9", - "sha256:a93e08636623e24c939851e2e0c0140b14f524b2980c9cdc4ea52b70a871c7e0", - "sha256:ac322d86d1a079e0a118d544443ee16f320af0062c191b4754c0c6ec2fc79310", - "sha256:b1fb101459868f52df6b61e7bb13375e50badf17a160e39fe1d51ae19e53f461", - "sha256:b39aac96cceac624a23d540473835086a3ffa77c91030189988c073488434493", - "sha256:b65507bc273c6dbf539175a786a344cc0ac78d50e5584f72c6599733f8a3301f", - "sha256:be5bb6e47417e537c884a2e2ff2e1a8b2c064a998fcfdfcc67528d4e63e7ebaf", - "sha256:c92de6a28a909c4f460dc1bbbcb50d676cf0b1f40224b222761f73fdd851b522", - "sha256:c9f5962eb7fa7607b20eb0e4f59ed35829bd600fc0eacb626a6db83229a3e445", - "sha256:d00bdf9c546ed6e649f785c55b05288e8b2dbb6bf2eb74b6c579fa0d591d35bd", - "sha256:da804b1dd8293bd9d61b1e6ea989c887ba042a808a4fbdd80001cfa059aafed2", - "sha256:ead6c5aa3e807345913649c3be395aaca2bbb2d225f18b8f31f37eab225508f6", - "sha256:eb4d81550ce6f826af4ec6e8d98be347fe96291d718bf115c3f254621ae8d98d", - "sha256:ef6a18ec8fd32ec81748fe720544ea2fb2d2dc50fd6d06739d5e2eb8f0626a1c", - "sha256:fad42835656e0b6d3b7ffc900598e776722e30f43b7234a48f2576ca30f31a47", - "sha256:fb98dbfee0d963b49ae5754554028cf62e6bd695f22de16d242ba9d2f0b7339b", - "sha256:fb9cd9bb8d26dc17c2dd715a46bca3a879ec8283879b164e85863110dc6e3b2a" + "sha256:03b78b4e7dcdfe3e257bb528cc93923f9cbbab6d5babf15a60d21e9a4a70b1a2", + "sha256:1ce0ccfbdfe84387dbcbf44adb4ae16ec7ae70e166ffab478993eb1ea1cba3ce", + "sha256:22e167a9406d73dd19ffe8ed6a485f17e6eac82505be8c108897f15e68badcbb", + "sha256:31d0aeca8d8ee2301c62c5c340e0889d653b1280d68f9fa203982cb6337b050e", + "sha256:44c7f99ca17ebbcc96fc54ed00b454d8313f1eac28c563098d8b901025aff941", + "sha256:5471444f53f9db6a1f1f11f5dbc173228881df8446380b6b98f90afb8fd8348e", + "sha256:561bca3b1bde6d6564306eb05848fd155136e9c3a25d2961129b1e2edba22fce", + "sha256:5bf58e1d2c2f55365c06e8cb5abe067b88ca2e5550fb62009c41df4b54505acf", + "sha256:6b7163d1e85d76b0815df63fcc310daec02b44532bb433f743142d4febcb181f", + "sha256:766d79cddad95f5f6020037fe60ea8b98578afdf0c59d5a60c106c1bdd886303", + "sha256:770b7372d5ca68308ff66d7baee53369fa5ce985f84bcb6aa1948c1f2f7b02f2", + "sha256:7ab178da777fc0f55b6aef5a755f99726e8e4b75e3903954df07b27059b54fcf", + "sha256:8078305e77c2f6649d36b24d8778096413e474d9d7892c6f92cfb589c9d71b2e", + "sha256:85600b63a386d860eeaa955e9335e18dd0d7e5477e9214825abf2c2884488369", + "sha256:857d9b939ae128be1c0c792eb885c7ff6a386b9dea899ac4b06f4d90a31f9d87", + "sha256:87a41630c90c179fa5c593400f30a467c498972c702f348d41e19dafeb1d319e", + "sha256:8805d486c6128cc0fcc8ecf16c4095d99a8693a541ef851429ab334e028a4a97", + "sha256:8d71b7a89c306a41ccc7741fc9409b14f5b86727455c2a1c0c7cfcb0f784e1f2", + "sha256:9e1b80bd65f8f160880cb4dad7f55697f6d37b2d7f251fc0c2128e811928f369", + "sha256:9e290c84a145ae2411ee0ec9913c41cd7500e2e7485fe93632434d84ef4fda67", + "sha256:9ec9f88b5bc94bd99372f27cdd53af1c92ba06717380b127733b953cfb181174", + "sha256:a0a02a8b4ba6deadf706d5f849539b3685b72b186a3c9ef5d43e8972ed60fb6f", + "sha256:a4059c59519f5940e01a071f74ae2a60ea8f6185b03d22a09d40c7959a36b16b", + "sha256:a6e028c2a6da2ebfa2365a5b32531d311fbfec0e3600fc27e901b64f0ff7e54e", + "sha256:adcdebf9f8463df4120c427cf6c9aed39258bccd03ed37b6939e7a145d64d6e0", + "sha256:bdec982610259d07156a58f80b8c3e69be7751a9208bc577b059c5193d087fad", + "sha256:cefc4d4251ffb73feb303d4b7e9d6c367cb60f2db16d259ea28b114045f965aa", + "sha256:d4145c8aa6afbac10ad27e408f7ce15992fe89ba5d0b4abca31c0c2729864c03", + "sha256:da76dc5ad719ee99de5ea28a5629ff92172cbb4a70d8a6ae3a5b7a53c7382ce1", + "sha256:dde2452c08ef8b6426ccab6b5b6de9f06d836d9937d6870e68153cbf8cb49348", + "sha256:e3d88091d2539a4868750914a6fe7b9ec50e42b913851fc1b77423b5bd918530", + "sha256:f9c67cfe6278499d7f83559dc6322a8bbb108e307817a3d7acbfea807b3603cc" ], - "version": "==1.21.1" + "version": "==1.22.0" }, "gunicorn": { "hashes": [ @@ -1384,10 +1384,10 @@ }, "ipywidgets": { "hashes": [ - "sha256:0f2b5cde9f272cb49d52f3f0889fdd1a7ae1e74f37b48dac35a83152780d2b7b", - "sha256:a3e224f430163f767047ab9a042fc55adbcab0c24bbe6cf9f306c4f89fdf0ba3" + "sha256:cb263c6974aca902d00a435711823bb4aaf6614a5f997f517e15fa84151e8fa2", + "sha256:eab6060f20f7f10d91f6efc8d33f9fd22133406980fcaee2738d836a910402f4" ], - "version": "==7.4.2" + "version": "==7.5.0" }, "isodate": { "hashes": [ @@ -1398,10 +1398,10 @@ }, "isort": { "hashes": [ - "sha256:c40744b6bc5162bbb39c1257fe298b7a393861d50978b565f3ccd9cb9de0182a", - "sha256:f57abacd059dc3bd666258d1efb0377510a89777fda3e3274e3c01f7c03ae22d" + "sha256:54da7e92468955c4fceacd0c86bd0ec997b0e1ee80d97f67c35a78b719dccab1", + "sha256:6e811fcb295968434526407adb8796944f1988c5b65e8139058f2014cbe100fd" ], - "version": "==4.3.20" + "version": "==4.3.21" }, "itsdangerous": { "hashes": [ @@ -1458,10 +1458,10 @@ }, "jupyter-client": { "hashes": [ - "sha256:b5f9cb06105c1d2d30719db5ffb3ea67da60919fb68deaefa583deccd8813551", - "sha256:c44411eb1463ed77548bc2d5ec0d744c9b81c4a542d9637c7a52824e2121b987" + "sha256:73a809a2964afa07adcc1521537fddb58c2ffbb7e84d53dc5901cf80480465b3", + "sha256:98e8af5edff5d24e4d31e73bc21043130ae9d955a91aa93fc0bc3b1d0f7b5880" ], - "version": "==5.2.4" + "version": "==5.3.1" }, "jupyter-console": { "hashes": [ @@ -1472,10 +1472,10 @@ }, "jupyter-core": { "hashes": [ - "sha256:927d713ffa616ea11972534411544589976b2493fc7e09ad946e010aa7eb9970", - "sha256:ba70754aa680300306c699790128f6fbd8c306ee5927976cbe48adacf240c0b7" + "sha256:2c6e7c1e9f2ac45b5c2ceea5730bc9008d92fe59d0725eac57b04c0edfba24f7", + "sha256:f4fa22d6cf25f34807c995f22d2923693575c70f02557bcbfbe59bd5ec8d8b84" ], - "version": "==4.4.0" + "version": "==4.5.0" }, "keras": { "hashes": [ @@ -1494,10 +1494,10 @@ }, "keras-maskrcnn": { "hashes": [ - "sha256:7cbadcf5d8a41e64ebd19157253f0357f2c46f289584c6f58fd38a19f7cc3509" + "sha256:9e2258390d749986fe6dc05aabdd7198ae689e60696b6a5568929379457a2e98" ], "index": "pypi", - "version": "==0.2.1" + "version": "==0.2.2" }, "keras-preprocessing": { "hashes": [ @@ -1514,10 +1514,10 @@ }, "keras-retinanet": { "hashes": [ - "sha256:257b77ca46c6846d8e9260e4eb1c77ab9b564c512bb5ebe23e72fc46b5c41899" + "sha256:6d4da9d83a9a82cb025298a88256546bc625e9c78cd4f1bbec576d11295910b6" ], "index": "pypi", - "version": "==0.5.0" + "version": "==0.5.1" }, "kiwisolver": { "hashes": [ @@ -1554,10 +1554,10 @@ }, "kombu": { "hashes": [ - "sha256:056a31cc95b10ca4eb0d4ebcba714007b1db1c6c45c8e2d139fe91933481b00b", - "sha256:af5b0f892b081f49d95c772a241fb7687f4cc3e42c94328f118dffb1f4e161e5" + "sha256:55b71d3785def3470a16217fe0780f9e6f95e61bf9ad39ef8dce0177224eab77", + "sha256:eb365ea795cd7e629ba2f1f398e0c3ba354b91ef4de225ffdf6ab45fdfc7d581" ], - "version": "==4.6.1" + "version": "==4.6.3" }, "lazy-object-proxy": { "hashes": [ @@ -1584,10 +1584,17 @@ }, "libarchive": { "hashes": [ - "sha256:37e8cca1eb85d30583cdcffc58116d83abc09be7549d5d6c9ead563c0a8d7b04" + "sha256:829dc298a08877f62335d528973bc034f7c1e8a03c16bfc1fa561e164e76a365" ], "index": "pypi", - "version": "==0.4.6" + "version": "==0.4.7" + }, + "limits": { + "hashes": [ + "sha256:9df578f4161017d79f5188609f1d65f6b639f8aad2914c3960c9252e56a0ff95", + "sha256:a017b8d9e9da6761f4574642149c337f8f540d4edfe573fb91ad2c4001a2bc76" + ], + "version": "==1.3" }, "lru-dict": { "hashes": [ @@ -1746,10 +1753,10 @@ }, "msrest": { "hashes": [ - "sha256:05538c68251eb0c81bd2010524d8ff36d4266ec0669338fbdcecfd23c733231c", - "sha256:8143093308975f815f968b0d2a1ac8e26ba217eb6d03f3f27aac616aa3a25bd0" + "sha256:2c0909570913785a4408a17286e151f3b28d39277113e5c63378572f7395c660", + "sha256:c9e9cbb0c47745f9f5c82cce60849d7c3ec9e33fc6fad9e2987b7657ad1ba479" ], - "version": "==0.6.7" + "version": "==0.6.8" }, "msrestazure": { "hashes": [ @@ -1774,11 +1781,11 @@ }, "nbstripout": { "hashes": [ - "sha256:814efbe00988445b2c3f3d1944c9f296a556e2b14a060f7b25372881c2e497d4", - "sha256:8f085e26e60e9d9c0710748510d1c763c8f63905cb16df7658b35a2936e8ca2b" + "sha256:1960caf7d1c1e281126c6c5cb98053db89eca8aaa616b58eed381e3e1508c0f4", + "sha256:d35c553f724d3fb7ec9e9602c6e55a75101064a6bbec4f8c28e8c84d6e3dd060" ], "index": "pypi", - "version": "==0.3.5" + "version": "==0.3.6" }, "networkx": { "hashes": [ @@ -1841,10 +1848,10 @@ }, "oauthlib": { "hashes": [ - "sha256:0ce32c5d989a1827e3f1148f98b9085ed2370fc939bf524c9c851d8714797298", - "sha256:3e1e14f6cde7e5475128d30e97edc3bfb4dc857cb884d8714ec161fdbb3b358e" + "sha256:40a63637707e9163eda62d0f5345120c65e001a790480b8256448543c1f78f66", + "sha256:b4d99ae8ccfb7d33ba9591b59355c64eef5241534aa3da2e4c0435346b84bc8e" ], - "version": "==3.0.1" + "version": "==3.0.2" }, "opencv-python": { "hashes": [ @@ -1905,6 +1912,32 @@ "index": "pypi", "version": "==2.15.0" }, + "pandas": { + "hashes": [ + "sha256:071e42b89b57baa17031af8c6b6bbd2e9a5c68c595bc6bf9adabd7a9ed125d3b", + "sha256:17450e25ae69e2e6b303817bdf26b2cd57f69595d8550a77c308be0cd0fd58fa", + "sha256:17916d818592c9ec891cbef2e90f98cc85e0f1e89ed0924c9b5220dc3209c846", + "sha256:2538f099ab0e9f9c9d09bbcd94b47fd889bad06dc7ae96b1ed583f1dc1a7a822", + "sha256:366f30710172cb45a6b4f43b66c220653b1ea50303fbbd94e50571637ffb9167", + "sha256:42e5ad741a0d09232efbc7fc648226ed93306551772fc8aecc6dce9f0e676794", + "sha256:4e718e7f395ba5bfe8b6f6aaf2ff1c65a09bb77a36af6394621434e7cc813204", + "sha256:4f919f409c433577a501e023943e582c57355d50a724c589e78bc1d551a535a2", + "sha256:4fe0d7e6438212e839fc5010c78b822664f1a824c0d263fd858f44131d9166e2", + "sha256:5149a6db3e74f23dc3f5a216c2c9ae2e12920aa2d4a5b77e44e5b804a5f93248", + "sha256:627594338d6dd995cfc0bacd8e654cd9e1252d2a7c959449228df6740d737eb8", + "sha256:83c702615052f2a0a7fb1dd289726e29ec87a27272d775cb77affe749cca28f8", + "sha256:8c872f7fdf3018b7891e1e3e86c55b190e6c5cee70cab771e8f246c855001296", + "sha256:90f116086063934afd51e61a802a943826d2aac572b2f7d55caaac51c13db5b5", + "sha256:a3352bacac12e1fc646213b998bce586f965c9d431773d9e91db27c7c48a1f7d", + "sha256:bcdd06007cca02d51350f96debe51331dec429ac8f93930a43eb8fb5639e3eb5", + "sha256:c1bd07ebc15285535f61ddd8c0c75d0d6293e80e1ee6d9a8d73f3f36954342d0", + "sha256:c9a4b7c55115eb278c19aa14b34fcf5920c8fe7797a09b7b053ddd6195ea89b3", + "sha256:cc8fc0c7a8d5951dc738f1c1447f71c43734244453616f32b8aa0ef6013a5dfb", + "sha256:d7b460bc316064540ce0c41c1438c416a40746fd8a4fb2999668bf18f3c4acf1" + ], + "index": "pypi", + "version": "==0.24.2" + }, "pandocfilters": { "hashes": [ "sha256:b3dd70e169bb5449e6bc6ff96aea89c5eea8c5f6ab5e207fc2f521a2cf4a0da9" @@ -1913,11 +1946,11 @@ }, "pathlib2": { "hashes": [ - "sha256:25199318e8cc3c25dcb45cbe084cc061051336d5a9ea2a12448d3d8cb748f742", - "sha256:5887121d7f7df3603bca2f710e7219f3eca0eb69e0b7cc6e0a022e155ac931a7" + "sha256:2156525d6576d21c4dcaddfa427fae887ef89a7a9de5cbfe0728b3aafa78427e", + "sha256:446014523bb9be5c28128c4d2a10ad6bb60769e78bd85658fe44a450674e0ef8" ], "markers": "python_version in '2.6 2.7 3.2 3.3'", - "version": "==2.3.3" + "version": "==2.3.4" }, "pbr": { "hashes": [ @@ -1951,34 +1984,34 @@ }, "pillow": { "hashes": [ - "sha256:15c056bfa284c30a7f265a41ac4cbbc93bdbfc0dfe0613b9cb8a8581b51a9e55", - "sha256:1a4e06ba4f74494ea0c58c24de2bb752818e9d504474ec95b0aa94f6b0a7e479", - "sha256:1c3c707c76be43c9e99cb7e3d5f1bee1c8e5be8b8a2a5eeee665efbf8ddde91a", - "sha256:1fd0b290203e3b0882d9605d807b03c0f47e3440f97824586c173eca0aadd99d", - "sha256:24114e4a6e1870c5a24b1da8f60d0ba77a0b4027907860188ea82bd3508c80eb", - "sha256:258d886a49b6b058cd7abb0ab4b2b85ce78669a857398e83e8b8e28b317b5abb", - "sha256:33c79b6dd6bc7f65079ab9ca5bebffb5f5d1141c689c9c6a7855776d1b09b7e8", - "sha256:367385fc797b2c31564c427430c7a8630db1a00bd040555dfc1d5c52e39fcd72", - "sha256:3c1884ff078fb8bf5f63d7d86921838b82ed4a7d0c027add773c2f38b3168754", - "sha256:44e5240e8f4f8861d748f2a58b3f04daadab5e22bfec896bf5434745f788f33f", - "sha256:46aa988e15f3ea72dddd81afe3839437b755fffddb5e173886f11460be909dce", - "sha256:74d90d499c9c736d52dd6d9b7221af5665b9c04f1767e35f5dd8694324bd4601", - "sha256:809c0a2ce9032cbcd7b5313f71af4bdc5c8c771cb86eb7559afd954cab82ebb5", - "sha256:85d1ef2cdafd5507c4221d201aaf62fc9276f8b0f71bd3933363e62a33abc734", - "sha256:8c3889c7681af77ecfa4431cd42a2885d093ecb811e81fbe5e203abc07e0995b", - "sha256:9218d81b9fca98d2c47d35d688a0cea0c42fd473159dfd5612dcb0483c63e40b", - "sha256:9aa4f3827992288edd37c9df345783a69ef58bd20cc02e64b36e44bcd157bbf1", - "sha256:9d80f44137a70b6f84c750d11019a3419f409c944526a95219bea0ac31f4dd91", - "sha256:b7ebd36128a2fe93991293f997e44be9286503c7530ace6a55b938b20be288d8", - "sha256:c4c78e2c71c257c136cdd43869fd3d5e34fc2162dc22e4a5406b0ebe86958239", - "sha256:c6a842537f887be1fe115d8abb5daa9bc8cc124e455ff995830cc785624a97af", - "sha256:cf0a2e040fdf5a6d95f4c286c6ef1df6b36c218b528c8a9158ec2452a804b9b8", - "sha256:cfd28aad6fc61f7a5d4ee556a997dc6e5555d9381d1390c00ecaf984d57e4232", - "sha256:dca5660e25932771460d4688ccbb515677caaf8595f3f3240ec16c117deff89a", - "sha256:de7aedc85918c2f887886442e50f52c1b93545606317956d65f342bd81cb4fc3", - "sha256:e6c0bbf8e277b74196e3140c35f9a1ae3eafd818f7f2d3a15819c49135d6c062" + "sha256:0804f77cb1e9b6dbd37601cee11283bba39a8d44b9ddb053400c58e0c0d7d9de", + "sha256:0ab7c5b5d04691bcbd570658667dd1e21ca311c62dcfd315ad2255b1cd37f64f", + "sha256:0b3e6cf3ea1f8cecd625f1420b931c83ce74f00c29a0ff1ce4385f99900ac7c4", + "sha256:365c06a45712cd723ec16fa4ceb32ce46ad201eb7bbf6d3c16b063c72b61a3ed", + "sha256:38301fbc0af865baa4752ddae1bb3cbb24b3d8f221bf2850aad96b243306fa03", + "sha256:3aef1af1a91798536bbab35d70d35750bd2884f0832c88aeb2499aa2d1ed4992", + "sha256:3fe0ab49537d9330c9bba7f16a5f8b02da615b5c809cdf7124f356a0f182eccd", + "sha256:45a619d5c1915957449264c81c008934452e3fd3604e36809212300b2a4dab68", + "sha256:49f90f147883a0c3778fd29d3eb169d56416f25758d0f66775db9184debc8010", + "sha256:571b5a758baf1cb6a04233fb23d6cf1ca60b31f9f641b1700bfaab1194020555", + "sha256:5ac381e8b1259925287ccc5a87d9cf6322a2dc88ae28a97fe3e196385288413f", + "sha256:6153db744a743c0c8c91b8e3b9d40e0b13a5d31dbf8a12748c6d9bfd3ddc01ad", + "sha256:6fd63afd14a16f5d6b408f623cc2142917a1f92855f0df997e09a49f0341be8a", + "sha256:70acbcaba2a638923c2d337e0edea210505708d7859b87c2bd81e8f9902ae826", + "sha256:70b1594d56ed32d56ed21a7fbb2a5c6fd7446cdb7b21e749c9791eac3a64d9e4", + "sha256:76638865c83b1bb33bcac2a61ce4d13c17dba2204969dedb9ab60ef62bede686", + "sha256:7b2ec162c87fc496aa568258ac88631a2ce0acfe681a9af40842fc55deaedc99", + "sha256:7cee2cef07c8d76894ebefc54e4bb707dfc7f258ad155bd61d87f6cd487a70ff", + "sha256:7d16d4498f8b374fc625c4037742fbdd7f9ac383fd50b06f4df00c81ef60e829", + "sha256:b50bc1780681b127e28f0075dfb81d6135c3a293e0c1d0211133c75e2179b6c0", + "sha256:bd0582f831ad5bcad6ca001deba4568573a4675437db17c4031939156ff339fa", + "sha256:cfd40d8a4b59f7567620410f966bb1f32dc555b2b19f82a91b147fac296f645c", + "sha256:e3ae410089de680e8f84c68b755b42bc42c0ceb8c03dbea88a5099747091d38e", + "sha256:e9046e559c299b395b39ac7dbf16005308821c2f24a63cae2ab173bd6aa11616", + "sha256:ef6be704ae2bc8ad0ebc5cb850ee9139493b0fc4e81abcc240fb392a63ebc808", + "sha256:f8dc19d92896558f9c4317ee365729ead9d7bbcf2052a9a19a3ef17abbb8ac5b" ], - "version": "==6.0.0" + "version": "==6.1.0" }, "pprofile": { "hashes": [ @@ -1996,9 +2029,9 @@ }, "prometheus-client": { "hashes": [ - "sha256:ee0c90350595e4a9f36591f291e6f9933246ea67d7cd7d1d6139a9781b14eaae" + "sha256:71cd24a2b3eb335cb800c7159f423df1bd4dcd5171b234be15e3f31ec9f622da" ], - "version": "==0.7.0" + "version": "==0.7.1" }, "prompt-toolkit": { "hashes": [ @@ -2010,26 +2043,26 @@ }, "protobuf": { "hashes": [ - "sha256:03f43eac9d5b651f976e91cf46a25b75e5779d98f0f4114b0abfed83376d75f8", - "sha256:0c94b21e6de01362f91a86b372555d22a60b59708599ca9d5032ae9fdf8e3538", - "sha256:2d2a9f30f61f4063fadd7fb68a2510a6939b43c0d6ceeec5c4704f22225da28e", - "sha256:34a0b05fca061e4abb77dd180209f68d8637115ff319f51e28a6a9382d69853a", - "sha256:358710fd0db25372edcf1150fa691f48376a134a6c69ce29f38f185eea7699e6", - "sha256:41e47198b94c27ba05a08b4a95160656105745c462af574e4bcb0807164065c0", - "sha256:8c61cc8a76e9d381c665aecc5105fa0f1878cf7db8b5cd17202603bcb386d0fc", - "sha256:a6eebc4db759e58fdac02efcd3028b811effac881d8a5bad1996e4e8ee6acb47", - "sha256:a9c12f7c98093da0a46ba76ec40ace725daa1ac4038c41e4b1466afb5c45bb01", - "sha256:cb95068492ba0859b8c9e61fa8ba206a83c64e5d0916fb4543700b2e2b214115", - "sha256:cd98476ce7bb4dcd6a7b101f5eecdc073dafea19f311e36eb8fba1a349346277", - "sha256:ce64cfbea18c535176bdaa10ba740c0fc4c6d998a3f511c17bedb0ae4b3b167c", - "sha256:dcbb59eac73fd454e8f2c5fba9e3d3320fd4707ed6a9d3ea3717924a6f0903ea", - "sha256:dd67f34458ae716029e2a71ede998e9092493b62a519236ca52e3c5202096c87", - "sha256:e3c96056eb5b7284a20e256cb0bf783c8f36ad82a4ae5434a7b7cd02384144a7", - "sha256:f612d584d7a27e2f39e7b17878430a959c1bc09a74ba09db096b468558e5e126", - "sha256:f6de8a7d6122297b81566e5bd4df37fd5d62bec14f8f90ebff8ede1c9726cd0a", - "sha256:fa529d9261682b24c2aaa683667253175c9acebe0a31105394b221090da75832" + "sha256:05c36022fef3c7d3562ac22402965c0c2b9fe8421f459bb377323598996e407f", + "sha256:139b7eadcca0a861d60b523cb37d9475505e0dfb07972436b15407c2b968d87e", + "sha256:15f683006cb77fb849b1f561e509b03dd2b7dcc749086b8dd1831090d0ba4740", + "sha256:2ad566b7b7cdd8717c7af1825e19f09e8fef2787b77fcb979588944657679604", + "sha256:35cfcf97642ef62108e10a9431c77733ec7eaab8e32fe4653de20403429907cb", + "sha256:387822859ecdd012fdc25ec879f7f487da6e1d5b1ae6115e227e6be208836f71", + "sha256:4df14cbe1e7134afcfdbb9f058949e31c466de27d9b2f7fb4da9e0b67231b538", + "sha256:586c4ca37a7146d4822c700059f150ac3445ce0aef6f3ea258640838bb892dc2", + "sha256:58b11e530e954d29ab3180c48dc558a409f705bf16739fd4e0d3e07924ad7add", + "sha256:63c8c98ccb8c95f41c18fb829aeeab21c6249adee4ed75354125bdc44488f30e", + "sha256:72edcbacd0c73eef507d2ff1af99a6c27df18e66a3ff4351e401182e4de62b03", + "sha256:83dc8a561b3b954fd7002c690bb83278b8d1742a1e28abba9aaef28b0c8b437d", + "sha256:913171ecc84c2726b86574e40549a0ea619d569657c5a5ff782a3be7d81401a5", + "sha256:aabb7c741d3416671c3e6fe7c52970a226e6a8274417a97d7d795f953fadef36", + "sha256:b3452bbda12b1cbe2187d416779de07b2ab4c497d83a050e43c344778763721d", + "sha256:c5d5b8d4a9212338297fa1fa44589f69b470c0ba1d38168b432d577176b386a8", + "sha256:d86ee389c2c4fc3cebabb8ce83a8e97b6b3b5dc727b7419c1ccdc7b6e545a233", + "sha256:f2db8c754de788ab8be5e108e1e967c774c0942342b4f8aaaf14063889a6cfdc" ], - "version": "==3.8.0" + "version": "==3.9.0" }, "psutil": { "hashes": [ @@ -2067,16 +2100,10 @@ }, "pycurl": { "hashes": [ - "sha256:0f0cdfc7a92d4f2a5c44226162434e34f7d6967d3af416a6f1448649c09a25a4", - "sha256:10510a0016c862af467c6e069e051409f15f5831552bed03f5104b395a5d7dd1", - "sha256:208dd2c89e80d32a69397ba8a5cdb3bc0dc60f961a4f2a9662e5e1624dc799d1", - "sha256:6dc6ee5e7628400083471cba8044010860fe8b22e4dee05e42150a68047d7d9d", - "sha256:794bda39ea6fe434b6e1f58ab3bea9f0e6123fb43702fecd760eed6f1547b20a", - "sha256:dae7277e7c06da00947f3cd32c095b1e65eae09f07478ada4ea9dfa57020b646", - "sha256:eccea049aef47decc380746b3ff242d95636d578c907d0eab3b00918292d6c48" + "sha256:6f08330c5cf79fa8ef68b9912b9901db7ffd34b63e225dce74db56bb21deda8e" ], "index": "pypi", - "version": "==7.43.0.2" + "version": "==7.43.0.3" }, "pygame": { "hashes": [ @@ -2126,11 +2153,18 @@ }, "pylint": { "hashes": [ - "sha256:02c2b6d268695a8b64ad61847f92e611e6afcff33fd26c3a2125370c4662905d", - "sha256:ee1e85575587c5b58ddafa25e1c1b01691ef172e139fc25585e5d3f02451da93" + "sha256:367e3d49813d349a905390ac27989eff82ab84958731c5ef0bef867452cfdc42", + "sha256:97a42df23d436c70132971d1dcb9efad2fe5c0c6add55b90161e773caf729300" ], "index": "pypi", - "version": "==1.9.4" + "version": "==1.9.5" + }, + "pylogbeat": { + "hashes": [ + "sha256:11f3b1d04424151d406d8b844a8db6299442b4af1f10d5f622a6febf1ad5c41d", + "sha256:473494a0c798a560a8312ee662b333888181cf4db18cd8f87a8d7d1548beefd9" + ], + "version": "==1.0.2" }, "pymongo": { "hashes": [ @@ -2232,9 +2266,9 @@ }, "pyrsistent": { "hashes": [ - "sha256:16692ee739d42cf5e39cef8d27649a8c1fdb7aa99887098f1460057c5eb75c3a" + "sha256:50cffebc87ca91b9d4be2dcc2e479272bcb466b5a0487b6c271f7ddea6917e14" ], - "version": "==0.15.2" + "version": "==0.15.3" }, "pysdl2": { "hashes": [ @@ -2260,10 +2294,10 @@ }, "python-engineio": { "hashes": [ - "sha256:9e4e7109d05d80ce5414f13b16f66725c2b5d574099fd43d37b024e7ea1c4354", - "sha256:d3315d3f972bd9bd32e0738d45801a912f522177ff75094762f31a8c341d1f41" + "sha256:4850c3e04b2040e4fd262d1047797473d1815b37a073807e7b80304c1c5f4848", + "sha256:89b90ee3816ed440c68ac7b6143244ae7d56a46a49295fbac8e6696482e596d1" ], - "version": "==3.8.1" + "version": "==3.8.2.post1" }, "python-logstash": { "hashes": [ @@ -2272,12 +2306,20 @@ "index": "pypi", "version": "==0.4.6" }, + "python-logstash-async": { + "hashes": [ + "sha256:994894e8b7e168e56f21e302334c08203af102c7bc760cacdb8d3d0f5aa74cea", + "sha256:ccd528a0a9c6b7aabd9944c01d628e9d6cc2149156011aafd3484c7c0abbce45" + ], + "index": "pypi", + "version": "==1.5.1" + }, "python-socketio": { "hashes": [ - "sha256:89a48591a8850c1f30d735f8e5a0294846da245a9b8940c39e1106e460c7a14e", - "sha256:c7ffeac3d81f2d8d63b3ec7ed1e2d4478cc84aa1da666c1934c19432f4b8c0f8" + "sha256:335bd0fab481d65edce4ab82c3bb5cac950afa843329ea7c38777cd56c8eba38", + "sha256:efec4844456791b7d702efefd543ed67a8e314ca45efb8f0bfca7ae18fdee60a" ], - "version": "==4.1.0" + "version": "==4.2.0" }, "python-utils": { "hashes": [ @@ -2351,34 +2393,34 @@ }, "pyzmq": { "hashes": [ - "sha256:1651e52ed91f0736afd6d94ef9f3259b5534ce8beddb054f3d5ca989c4ef7c4f", - "sha256:5ccb9b3d4cd20c000a9b75689d5add8cd3bce67fcbd0f8ae1b59345247d803af", - "sha256:5e120c4cd3872e332fb35d255ad5998ebcee32ace4387b1b337416b6b90436c7", - "sha256:5e2a3707c69a7281a9957f83718815fd74698cba31f6d69f9ed359921f662221", - "sha256:63d51add9af8d0442dc90f916baf98fdc04e3b0a32afec4bfc83f8d85e72959f", - "sha256:65c5a0bdc49e20f7d6b03a661f71e2fda7a99c51270cafe71598146d09810d0d", - "sha256:66828fabe911aa545d919028441a585edb7c9c77969a5fea6722ef6e6ece38ab", - "sha256:7d79427e82d9dad6e9b47c0b3e7ae5f9d489b1601e3a36ea629bb49501a4daf3", - "sha256:824ee5d3078c4eae737ffc500fbf32f2b14e6ec89b26b435b7834febd70120cf", - "sha256:89dc0a83cccec19ff3c62c091e43e66e0183d1e6b4658c16ee4e659518131494", - "sha256:8b319805f6f7c907b101c864c3ca6cefc9db8ce0791356f180b1b644c7347e4c", - "sha256:90facfb379ab47f94b19519c1ecc8ec8d10813b69d9c163117944948bdec5d15", - "sha256:a0a178c7420021fc0730180a914a4b4b3092ce9696ceb8e72d0f60f8ce1655dd", - "sha256:a7a89591ae315baccb8072f216614b3e59aed7385aef4393a6c741783d6ee9cf", - "sha256:ba2578f0ae582452c02ed9fac2dc477b08e80ce05d2c0885becf5fff6651ccb0", - "sha256:c69b0055c55702f5b0b6b354133e8325b9a56dbc80e1be2d240bead253fb9825", - "sha256:ca434e1858fe222380221ddeb81e86f45522773344c9da63c311d17161df5e06", - "sha256:d4b8ecfc3d92f114f04d5c40f60a65e5196198b827503341521dda12d8b14939", - "sha256:d706025c47b09a54f005953ebe206f6d07a22516776faa4f509aaff681cc5468", - "sha256:d8f27e958f8a2c0c8ffd4d8855c3ce8ac3fa1e105f0491ce31729aa2b3229740", - "sha256:dbd264298f76b9060ce537008eb989317ca787c857e23cbd1b3ddf89f190a9b1", - "sha256:e926d66f0df8fdbf03ba20583af0f215e475c667fb033d45fd031c66c63e34c9", - "sha256:efc3bd48237f973a749f7312f68062f1b4ca5c2032a0673ca3ea8e46aa77187b", - "sha256:f59bc782228777cbfe04555707a9c56d269c787ed25d6d28ed9d0fbb41cb1ad2", - "sha256:f8da5322f4ff5f667a0d5a27e871b560c6637153c81e318b35cb012b2a98835c" + "sha256:00dd015159eaeb1c0731ad49310e1f5d839c9a35a15e4f3267f5052233fad99b", + "sha256:03913b6beb8e7b417b9910b0ee1fd5d62e9626d218faefbe879d70714ceab1a2", + "sha256:13f17386df81d5e6efb9a4faea341d8de22cdc82e49a326dded26e33f42a3112", + "sha256:16c6281d96885db1e15f7047ddc1a8f48ff4ea35d31ca709f4d2eb39f246d356", + "sha256:17efab4a804e31f58361631256d660214204046f9e2b962738b171b9ad674ea7", + "sha256:2b79919ddeff3d3c96aa6087c21d294c8db1c01f6bfeee73324944683685f419", + "sha256:2f832e4711657bb8d16ea1feba860f676ec5f14fb9fe3b449b5953a60e89edae", + "sha256:31a11d37ac73107363b47e14c94547dbfc6a550029c3fe0530be443199026fc2", + "sha256:33a3e928e6c3138c675e1d6702dd11f6b7050177d7aab3fc322db6e1d2274490", + "sha256:34a38195a6d3a9646cbcdaf8eb245b4d935c7a57f7e1b3af467814bc1a92467e", + "sha256:42900054f1500acef6df7428edf806abbf641bf92eb9ceded24aa863397c3bae", + "sha256:4ccc7f3c63aa9d744dadb62c49eda2d0e7de55649b80c45d7c684d70161a69af", + "sha256:5b220c37c346e6575db8c88a940c1fc234f99ce8e0068c408919bb8896c4b6d2", + "sha256:6074848da5c8b44a1ca40adf75cf65aa92bc80f635e8249aa8f37a69b2b9b6f5", + "sha256:61a4155964bd4a14ef95bf46cb1651bcf8dcbbed8c0108e9c974c1fcbb57788f", + "sha256:62b5774688326600c52f587f7a033ca6b6284bef4c8b1b5fda32480897759eac", + "sha256:65a9ffa4f9f085d696f16fd7541f34b3c357d25fe99c90e3bce2ea59c3b5b4b6", + "sha256:76a077d2c30f8adc5e919a55985a784b96aeca69b53c1ea6fd5723d3ae2e6f53", + "sha256:8e5b4c51557071d6379d6dc1f54f35e9f6a137f5e84e102efb869c8d3c13c8ff", + "sha256:917f73e07cc04f0678a96d93e7bb8b1adcccdde9ccfe202e622814f4d1d1ecfd", + "sha256:91c75d3c4c357f9643e739db9e79ab9681b2f6ae8ec5678d6ef2ea0d01532596", + "sha256:923dd91618b100bb4c92ab9ed7b65825a595b8524a094ce03c7cb2aaae7d353b", + "sha256:9849054e0355e2bc7f4668766a25517ba76095031c9ff5e39ae8949cee5bb024", + "sha256:c9d453933f0e3f44b9759189f2a18aa765f7f1a4345c727c18ebe8ad0d748d26", + "sha256:cb7514936277abce64c2f4c56883e5704d85ed04d98d2d432d1c6764003bb003" ], "index": "pypi", - "version": "==18.0.1" + "version": "==18.0.2" }, "qtconsole": { "hashes": [ @@ -2523,6 +2565,14 @@ "index": "pypi", "version": "==1.2.2" }, + "seaborn": { + "hashes": [ + "sha256:42e627b24e849c2d3bbfd059e00005f6afbc4a76e4895baf44ae23fe8a4b09a5", + "sha256:76c83f794ca320fb6b23a7c6192d5e185a5fcf4758966a0c0a54baee46d41e2f" + ], + "index": "pypi", + "version": "==0.9.0" + }, "send2trash": { "hashes": [ "sha256:60001cc07d707fe247c94f74ca6ac0d3255aabcb930529690897ca2a39db28b2", @@ -2612,11 +2662,11 @@ }, "supervisor": { "hashes": [ - "sha256:a3289b9124e59aee1621d43b55cd1634468cb3212d09c5b0114a3183cc080cca", - "sha256:f768abc073e8702892718938b8a0ab98ebcb91c2afcb39bf2cb570d3eb51149e" + "sha256:43e87c7b572a94acdb586aaebb06844dae1aa02856b984c5a738032abd753fb7", + "sha256:9644990d21a1ba03b1a7ac5e9a0c0c62e12822e258f9e98f4a0b128461b3f10a" ], "index": "pypi", - "version": "==4.0.3" + "version": "==4.0.4" }, "tenacity": { "hashes": [ @@ -2635,9 +2685,9 @@ }, "tensorflow-estimator": { "hashes": [ - "sha256:7cfdaa3e83e3532f31713713feb98be7ea9f3065722be4267e49b6c301271419" + "sha256:ca073f66063407a091d610ec1b22e39ea30248710198cc6f13769320bdbe3992" ], - "version": "==1.13.0" + "version": "==1.14.0" }, "tensorflow-gpu": { "hashes": [ @@ -2713,12 +2763,12 @@ }, "typing": { "hashes": [ - "sha256:4027c5f6127a6267a435201981ba156de91ad0d1d98e9ddc2aa173453453492d", - "sha256:57dcf675a99b74d64dacf6fba08fb17cf7e3d5fdff53d4a30ea2a5e7e52543d4", - "sha256:a4c8473ce11a65999c8f59cb093e70686b6c84c98df58c1dae9b3b196089858a" + "sha256:38566c558a0a94d6531012c8e917b1b8518a41e418f7f15f00e129cc80162ad3", + "sha256:53765ec4f83a2b720214727e319607879fec4acde22c4fbb54fa2604e79e44ce", + "sha256:84698954b4e6719e912ef9a42a2431407fe3755590831699debda6fba92aac55" ], "markers": "python_version < '3.5'", - "version": "==3.6.6" + "version": "==3.7.4" }, "urllib3": { "hashes": [ @@ -2730,10 +2780,10 @@ }, "utm": { "hashes": [ - "sha256:a6608a67df84418fd959a79b228b90ab55b2ae877827f9c210947104c5a75d0e" + "sha256:07e55707ed660eec1ae983bd54a406c437962618a6261b38d70592fe30f5f508" ], "index": "pypi", - "version": "==0.4.2" + "version": "==0.5.0" }, "uwsgi": { "hashes": [ @@ -2780,10 +2830,10 @@ }, "werkzeug": { "hashes": [ - "sha256:865856ebb55c4dcd0630cdd8f3331a1847a819dda7e8c750d3db6f2aa6c0209c", - "sha256:a0b915f0815982fb2a09161cb8f31708052d0951c3ba433ccc5e1aa276507ca6" + "sha256:87ae4e5b5366da2347eb3116c0e6c681a0e939a33b2805e2c0cbd282664932c4", + "sha256:a13b74dd3c45f758d4ebdb224be8f1ab8ef58b3c0ffc1783a8c7d9f4f50227e6" ], - "version": "==0.15.4" + "version": "==0.15.5" }, "wheel": { "hashes": [ @@ -2795,16 +2845,16 @@ }, "widgetsnbextension": { "hashes": [ - "sha256:14b2c65f9940c9a7d3b70adbe713dbd38b5ec69724eebaba034d1036cf3d4740", - "sha256:fa618be8435447a017fd1bf2c7ae922d0428056cfc7449f7a8641edf76b48265" + "sha256:120f85acc3976450220b03b8933ce48678e518905cca69fc3c856ea5a0144196", + "sha256:8c9b4d73e388f2484296be18432d3cc0b8d59de243079a0db16a56c5571e1f86" ], - "version": "==3.4.2" + "version": "==3.5.0" }, "wrapt": { "hashes": [ - "sha256:4aea003270831cceb8a90ff27c4031da6ead7ec1886023b80ce0dfe0adf61533" + "sha256:565a021fd19419476b9362b05eeaa094178de64f8361e44468f9e9d7843901e1" ], - "version": "==1.11.1" + "version": "==1.11.2" } } } diff --git a/README.md b/README.md index dfbb76803..f6e3fbe79 100644 --- a/README.md +++ b/README.md @@ -60,13 +60,13 @@ Supported Cars | Make | Model | Supported Package | Lateral | Longitudinal | No Accel Below | No Steer Below | Giraffe | | ---------------------| -------------------------| ---------------------| --------| ---------------| -----------------| ---------------|-------------------| -| Acura | ILX 2016-17 | AcuraWatch Plus | Yes | Yes | 25mph1| 25mph | Nidec | -| Acura | RDX 2018 | AcuraWatch Plus | Yes | Yes | 25mph1| 12mph | Nidec | +| 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 2018 | Adaptive Cruise | Yes | Stock | 0mph | 9mph | FCA | +| 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| @@ -84,9 +84,9 @@ Supported Cars | 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 | SCC + LKAS | Yes | Stock | 19mph | 34mph | Custom6| +| Hyundai | Elantra 2017-19 | SCC + LKAS | Yes | Stock | 19mph | 34mph | Custom6| | Hyundai | Genesis 2018 | All | Yes | Stock | 19mph | 34mph | Custom6| -| Jeep | Grand Cherokee 2017-18 | Adaptive Cruise | Yes | Stock | 0mph | 9mph | FCA | +| 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| @@ -96,8 +96,9 @@ Supported Cars | 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 | Camry 2018 | All | Yes | Stock | 0mph5 | 0mph | Toyota | -| Toyota | C-HR 2017-18 | All | Yes | Stock | 0mph | 0mph | Toyota | +| Toyota | Avalon 2017-18 | All | Yes | Yes2| 20mph1| 0mph | Toyota | +| Toyota | Camry 2018-19 | All | Yes | Stock | 0mph5 | 0mph | Toyota | +| Toyota | C-HR 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 | @@ -110,6 +111,7 @@ Supported Cars | Toyota | Rav4 2017-18 | All | Yes | Yes2| 20mph1| 0mph | Toyota | | Toyota | Rav4 2019 | All | Yes | Yes | 0mph | 0mph | Toyota | | Toyota | Rav4 Hybrid 2017-18 | All | Yes | Yes2| 0mph | 0mph | Toyota | +| Toyota | Sienna 2018 | All | Yes | Yes2| 0mph | 0mph | Toyota | 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).
diff --git a/RELEASES.md b/RELEASES.md index f73b8daf8..07bbc6208 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,3 +1,10 @@ +Version 0.6.1 (2019-07-21) +======================== + * Remote SSH with comma prime and [ssh.comma.ai](https://ssh.comma.ai) + * Panda code Misra-c2012 compliance, tested against cppcheck coverage + * Lockout openpilot after 3 terminal alerts for driver distracted or unresponsive + * Toyota Sienna support thanks to wocsor! + Version 0.6 (2019-07-01) ======================== * New model, with double the pixels and ten times the temporal context! diff --git a/common/file_helpers.py b/common/file_helpers.py index bdfe9d0ec..3300ae595 100644 --- a/common/file_helpers.py +++ b/common/file_helpers.py @@ -28,7 +28,7 @@ def get_tmpdir_on_same_filesystem(path): normpath = os.path.normpath(path) parts = normpath.split("/") if len(parts) > 1: - if parts[1].startswith("raid"): + if parts[1].startswith("raid") or parts[1].startswith("datasets"): if len(parts) > 2 and parts[2] == "runner": return "/{}/runner/tmp".format(parts[1]) elif len(parts) > 2 and parts[2] == "aws": @@ -101,3 +101,18 @@ def atomic_write_in_dir(path, **kwargs): writer = AtomicWriter(path, **kwargs) return writer._open(_get_fileobject_func(writer, os.path.dirname(path))) +def atomic_write_in_dir_neos(path, contents, mode=None): + """ + Atomically writes contents to path using a temporary file in the same directory + as path. Useful on NEOS, where `os.link` (required by atomic_write_in_dir) is missing. + """ + + f = tempfile.NamedTemporaryFile(delete=False, prefix=".tmp", dir=os.path.dirname(path)) + f.write(contents) + f.flush() + if mode is not None: + os.fchmod(f.fileno(), mode) + os.fsync(f.fileno()) + f.close() + + os.rename(f.name, path) diff --git a/common/fingerprints.py b/common/fingerprints.py index ddc3bceb6..0e29e6c1e 100644 --- a/common/fingerprints.py +++ b/common/fingerprints.py @@ -28,10 +28,8 @@ _DEBUG_ADDRESS = {1880: 8} # reserved for debug purposes def is_valid_for_fingerprint(msg, car_fingerprint): adr = msg.address - bus = msg.src # ignore addresses that are more than 11 bits - return (adr in car_fingerprint and car_fingerprint[adr] == len(msg.dat)) or \ - bus != 0 or adr >= 0x800 + return (adr in car_fingerprint and car_fingerprint[adr] == len(msg.dat)) or adr >= 0x800 def eliminate_incompatible_cars(msg, candidate_cars): diff --git a/common/params.py b/common/params.py index c374d5233..963debd09 100755 --- a/common/params.py +++ b/common/params.py @@ -50,12 +50,14 @@ class UnknownKeyName(Exception): keys = { "AccessToken": [TxType.PERSISTENT], + "AthenadPid": [TxType.PERSISTENT], "CalibrationParams": [TxType.PERSISTENT], "CarParams": [TxType.CLEAR_ON_MANAGER_START, TxType.CLEAR_ON_PANDA_DISCONNECT], "CompletedTrainingVersion": [TxType.PERSISTENT], "ControlsParams": [TxType.PERSISTENT], "DoUninstall": [TxType.CLEAR_ON_MANAGER_START], "DongleId": [TxType.PERSISTENT], + "GithubSshKeys": [TxType.PERSISTENT], "GitBranch": [TxType.PERSISTENT], "GitCommit": [TxType.PERSISTENT], "GitRemote": [TxType.PERSISTENT], @@ -75,6 +77,7 @@ keys = { "ShouldDoUpdate": [TxType.CLEAR_ON_MANAGER_START], "SpeedLimitOffset": [TxType.PERSISTENT], "SubscriberInfo": [TxType.PERSISTENT], + "TermsVersion": [TxType.PERSISTENT], "TrainingVersion": [TxType.PERSISTENT], "Version": [TxType.PERSISTENT], } diff --git a/selfdrive/athena/athenad.py b/selfdrive/athena/athenad.py index 58918de81..d6d429d92 100755 --- a/selfdrive/athena/athenad.py +++ b/selfdrive/athena/athenad.py @@ -1,15 +1,22 @@ #!/usr/bin/env python2.7 import json +import jwt import os import random +import re +import select +import subprocess +import socket import time import threading import traceback import zmq import requests import six.moves.queue +from datetime import datetime, timedelta +from functools import partial from jsonrpc import JSONRPCResponseManager, dispatcher -from websocket import create_connection, WebSocketTimeoutException +from websocket import create_connection, WebSocketTimeoutException, ABNF from selfdrive.loggerd.config import ROOT import selfdrive.crash as crash @@ -21,6 +28,7 @@ from selfdrive.version import version, dirty ATHENA_HOST = os.getenv('ATHENA_HOST', 'wss://athena.comma.ai') HANDLER_THREADS = os.getenv('HANDLER_THREADS', 4) +LOCAL_PORT_WHITELIST = set([8022]) dispatcher["echo"] = lambda s: s payload_queue = six.moves.queue.Queue() @@ -49,6 +57,7 @@ def handle_long_poll(ws): thread.join() def jsonrpc_handler(end_event): + dispatcher["startLocalProxy"] = partial(startLocalProxy, end_event) while not end_event.is_set(): try: data = payload_queue.get(timeout=1) @@ -85,6 +94,109 @@ def uploadFileToUrl(fn, url, headers): ret = requests.put(url, data=f, headers=headers, timeout=10) return ret.status_code +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") + + params = Params() + dongle_id = params.get("DongleId") + private_key = open("/persist/comma/id_rsa").read() + identity_token = jwt.encode({'identity':dongle_id, 'exp': datetime.utcnow() + timedelta(hours=1)}, private_key, algorithm='RS256') + + ws = create_connection(remote_ws_uri, + cookie="jwt=" + identity_token, + enable_multithread=True) + + ssock, csock = socket.socketpair() + local_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + local_sock.connect(('127.0.0.1', local_port)) + local_sock.setblocking(0) + + proxy_end_event = threading.Event() + threads = [ + threading.Thread(target=ws_proxy_recv, args=(ws, local_sock, ssock, proxy_end_event, global_end_event)), + threading.Thread(target=ws_proxy_send, args=(ws, local_sock, csock, proxy_end_event)) + ] + + map(lambda thread: thread.start(), threads) + + return {"success": 1} + except Exception as e: + traceback.print_exc() + raise e + +@dispatcher.add_method +def getPublicKey(): + if not os.path.isfile('/persist/comma/id_rsa.pub'): + return None + + with open('/persist/comma/id_rsa.pub', 'r') as f: + return f.read() + +@dispatcher.add_method +def getSshAuthorizedKeys(): + with open('/system/comma/home/.ssh/authorized_keys', 'r') as f: + return f.read() + +@dispatcher.add_method +def getSimInfo(): + sim_state = subprocess.check_output(['getprop', 'gsm.sim.state']).strip().split(',') + network_type = subprocess.check_output(['getprop', 'gsm.network.type']).strip().split(',') + mcc_mnc = subprocess.check_output(['getprop', 'gsm.sim.operator.numeric']).strip() or None + + sim_id_aidl_out = subprocess.check_output(['service', 'call', 'iphonesubinfo', '11']) + sim_id_aidl_lines = sim_id_aidl_out.split('\n') + if len(sim_id_aidl_lines) > 3: + sim_id_lines = sim_id_aidl_lines[1:4] + sim_id_fragments = [re.search(r"'([0-9\.]+)'", line).group(1) for line in sim_id_lines] + sim_id = reduce(lambda frag1, frag2: frag1.replace('.', '') + frag2.replace('.', ''), sim_id_fragments) + else: + sim_id = None + + return { + 'sim_id': sim_id, + 'mcc_mnc': mcc_mnc, + 'network_type': network_type, + 'sim_state': sim_state + } + +def ws_proxy_recv(ws, local_sock, ssock, end_event, global_end_event): + while not (end_event.is_set() or global_end_event.is_set()): + try: + data = ws.recv() + local_sock.sendall(data) + except WebSocketTimeoutException: + pass + except Exception: + traceback.print_exc() + break + + ssock.close() + end_event.set() + +def ws_proxy_send(ws, local_sock, signal_sock, end_event): + while not end_event.is_set(): + try: + r, _, _ = select.select((local_sock, signal_sock), (), ()) + if r: + if r[0].fileno() == signal_sock.fileno(): + # got end signal from ws_proxy_recv + end_event.set() + break + data = local_sock.recv(4096) + if not data: + # local_sock is dead + end_event.set() + break + + ws.send(data, ABNF.OPCODE_BINARY) + except Exception: + traceback.print_exc() + end_event.set() + def ws_recv(ws, end_event): while not end_event.is_set(): try: @@ -138,5 +250,7 @@ def main(gctx=None): time.sleep(backoff(conn_retries)) + params.delete("AthenadPid") + if __name__ == "__main__": main() diff --git a/selfdrive/boardd/boardd.cc b/selfdrive/boardd/boardd.cc index 1a64416e9..779ca7b27 100644 --- a/selfdrive/boardd/boardd.cc +++ b/selfdrive/boardd/boardd.cc @@ -283,8 +283,9 @@ void can_health(void *s) { uint8_t started; uint8_t controls_allowed; uint8_t gas_interceptor_detected; - uint8_t started_signal_detected; - uint8_t started_alt; + uint32_t can_send_errs; + uint32_t can_fwd_errs; + uint32_t gmlan_send_errs; } health; // recv from board @@ -313,8 +314,10 @@ void can_health(void *s) { } healthData.setControlsAllowed(health.controls_allowed); healthData.setGasInterceptorDetected(health.gas_interceptor_detected); - healthData.setStartedSignalDetected(health.started_signal_detected); healthData.setIsGreyPanda(is_grey_panda); + healthData.setCanSendErrs(health.can_send_errs); + healthData.setCanFwdErrs(health.can_fwd_errs); + healthData.setGmlanSendErrs(health.gmlan_send_errs); // send to health auto words = capnp::messageToFlatArray(msg); diff --git a/selfdrive/can/parser.cc b/selfdrive/can/parser.cc index e3225181b..69b30fb51 100644 --- a/selfdrive/can/parser.cc +++ b/selfdrive/can/parser.cc @@ -194,32 +194,36 @@ class CANParser { : bus(abus) { // connect to can on 8006 context = zmq_ctx_new(); - 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; + 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)); - if (sendcan) { - tcp_addr_str = "tcp://" + tcp_addr + ":8017"; + std::string tcp_addr_str; + + 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(); + + zmq_connect(subscriber, tcp_addr_char); + + // 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 { - tcp_addr_str = "tcp://" + tcp_addr + ":8006"; - } - const char *tcp_addr_char = tcp_addr_str.c_str(); - - zmq_connect(subscriber, tcp_addr_char); - - // 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); + subscriber = NULL; } dbc = dbc_lookup(dbc_name); - assert(dbc); - + assert(dbc); for (const auto& op : options) { MessageState state = { .address = op.address, @@ -326,6 +330,21 @@ class CANParser { } } + void update_string(uint64_t sec, 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(); + + auto cans = event.getCan(); + UpdateCans(sec, cans); + + UpdateValid(sec); + } + int update(uint64_t sec, bool wait) { int err; int result = 0; @@ -336,7 +355,7 @@ class CANParser { // multiple recv is fine bool first = wait; - while (1) { + while (subscriber != NULL) { if (first) { err = zmq_msg_recv(&msg, subscriber, 0); first = false; @@ -432,6 +451,11 @@ int can_update(void* can, uint64_t sec, bool wait) { return cp->update(sec, wait); } +void can_update_string(void *can, uint64_t sec, const char* dat, int len) { + CANParser* cp = (CANParser*)can; + cp->update_string(sec, std::string(dat, len)); +} + size_t can_query(void* can, uint64_t sec, bool *out_can_valid, size_t out_values_size, SignalValue* out_values) { CANParser* cp = (CANParser*)can; diff --git a/selfdrive/can/parser_pyx.pxd b/selfdrive/can/parser_pyx.pxd index 9d8efa318..ac619707a 100644 --- a/selfdrive/can/parser_pyx.pxd +++ b/selfdrive/can/parser_pyx.pxd @@ -67,6 +67,7 @@ ctypedef void* (*can_init_with_vectors_func)(int bus, const char* dbc_name, const char* tcp_addr, int timeout) ctypedef int (*can_update_func)(void* can, uint64_t sec, bool wait); +ctypedef void (*can_update_string_func)(void* can, uint64_t sec, const char* dat, int len); ctypedef size_t (*can_query_func)(void* can, uint64_t sec, bool *out_can_valid, size_t out_values_size, SignalValue* out_values); ctypedef void (*can_query_vector_func)(void* can, uint64_t sec, bool *out_can_valid, vector[SignalValue] &values) @@ -77,6 +78,7 @@ cdef class CANParser: dbc_lookup_func dbc_lookup can_init_with_vectors_func can_init_with_vectors can_update_func can_update + can_update_string_func can_update_string can_query_vector_func can_query_vector map[string, uint32_t] msg_name_to_address map[uint32_t, string] address_to_msg_name diff --git a/selfdrive/can/parser_pyx.pyx b/selfdrive/can/parser_pyx.pyx index 65c6f5ab2..c6f1f58e0 100644 --- a/selfdrive/can/parser_pyx.pyx +++ b/selfdrive/can/parser_pyx.pyx @@ -8,7 +8,7 @@ import numbers cdef int CAN_INVALID_CNT = 5 cdef class CANParser: - def __init__(self, dbc_name, signals, checks=None, bus=0, sendcan=False, tcp_addr="127.0.0.1", timeout=-1): + def __init__(self, dbc_name, signals, checks=None, bus=0, sendcan=False, tcp_addr="", timeout=-1): self.test_mode_enabled = False can_dir = os.path.dirname(os.path.abspath(__file__)) libdbc_fn = os.path.join(can_dir, "libdbc.so") @@ -17,6 +17,7 @@ cdef class CANParser: self.can_init_with_vectors = dlsym(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_vector = dlsym(libdbc, 'can_query_vector') if checks is None: checks = [] @@ -99,6 +100,19 @@ cdef class CANParser: return updated_val + def update_string(self, uint64_t sec, dat): + self.can_update_string(self.can, sec, dat, len(dat)) + return self.update_vl(sec) + + def update_strings(self, uint64_t sec, strings): + updated_vals = set() + + for s in strings: + updated_val = self.update_string(sec, s) + 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(sec) diff --git a/selfdrive/can/tests/test_parser.py b/selfdrive/can/tests/test_parser.py index bb00d042f..53c95ce91 100755 --- a/selfdrive/can/tests/test_parser.py +++ b/selfdrive/can/tests/test_parser.py @@ -47,8 +47,9 @@ def run_route(route): CP = CarInterface.get_params(CAR.CIVIC, {}) signals, checks = get_can_signals(CP) - parser_old = CANParserOld(DBC[CP.carFingerprint]['pt'], signals, checks, 0, timeout=-1) - parser_new = CANParserNew(DBC[CP.carFingerprint]['pt'], signals, checks, 0, timeout=-1) + 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 @@ -61,19 +62,29 @@ def run_route(route): for msg in lr: if msg.which() == 'can': t += DT - can.send(msg.as_builder().to_bytes()) + 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(t, 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): diff --git a/selfdrive/car/car_helpers.py b/selfdrive/car/car_helpers.py index f7e8c5375..155e443e1 100644 --- a/selfdrive/car/car_helpers.py +++ b/selfdrive/car/car_helpers.py @@ -50,6 +50,8 @@ def _get_interface_names(): # imports from directory selfdrive/car// interfaces = load_interfaces(_get_interface_names()) +def only_toyota_left(candidate_cars): + return all(("TOYOTA" in c or "LEXUS" in c) for c in candidate_cars) # BOUNTY: every added fingerprint in selfdrive/car/*/values.py is a $100 coupon code on shop.comma.ai # **** for use live only **** @@ -59,7 +61,7 @@ def fingerprint(logcan, sendcan): elif os.getenv("SIMULATOR") is not None: return ("simulator", None, "") - finger = {} + finger = {0: {}, 2:{}} # collect on bus 0 or 2 cloudlog.warning("waiting for fingerprint...") candidate_cars = all_known_cars() can_seen_frame = None @@ -79,6 +81,7 @@ def fingerprint(logcan, sendcan): vin = "" frame = 0 + while True: a = messaging.recv_one(logcan) @@ -98,9 +101,12 @@ def fingerprint(logcan, sendcan): # ignore everything not on bus 0 and with more than 11 bits, # which are ussually sporadic and hard to include in fingerprints. - # also exclude VIN query response on 0x7e8 - if can.src == 0 and can.address < 0x800 and can.address != 0x7e8: - finger[can.address] = len(can.dat) + # also exclude VIN query response on 0x7e8. + # Include bus 2 for toyotas to disambiguate cars using camera messages + # (ideally should be done for all cars but we can't for Honda Bosch) + if (can.src == 0 or (only_toyota_left(candidate_cars) and can.src == 2)) and \ + can.address < 0x800 and can.address != 0x7e8: + finger[can.src][can.address] = len(can.dat) candidate_cars = eliminate_incompatible_cars(can, candidate_cars) if can_seen_frame is None and can_seen: @@ -110,7 +116,7 @@ def fingerprint(logcan, sendcan): # message has elapsed, exit. Toyota needs higher time_fingerprint, since DSU does not # broadcast immediately if len(candidate_cars) == 1 and can_seen_frame is not None: - time_fingerprint = 1.0 if ("TOYOTA" in candidate_cars[0] or "LEXUS" in candidate_cars[0]) else 0.1 + time_fingerprint = 1.0 if only_toyota_left(candidate_cars) else 0.1 if (frame - can_seen_frame) > (time_fingerprint * 100): break @@ -146,6 +152,6 @@ def get_car(logcan, sendcan): candidate = "mock" CarInterface, CarController = interfaces[candidate] - params = CarInterface.get_params(candidate, fingerprints, vin) + params = CarInterface.get_params(candidate, fingerprints[0], vin) return CarInterface(params, CarController), params diff --git a/selfdrive/car/chrysler/carstate.py b/selfdrive/car/chrysler/carstate.py index 1d38b8cda..24acc76a4 100644 --- a/selfdrive/car/chrysler/carstate.py +++ b/selfdrive/car/chrysler/carstate.py @@ -60,7 +60,7 @@ def get_can_parser(CP): ("ACC_2", 50), ] - return CANParser(DBC[CP.carFingerprint]['pt'], signals, checks, 0, timeout=100) + return CANParser(DBC[CP.carFingerprint]['pt'], signals, checks, 0) def get_camera_parser(CP): signals = [ @@ -72,7 +72,7 @@ def get_camera_parser(CP): ] checks = [] - return CANParser(DBC[CP.carFingerprint]['pt'], signals, checks, 2, timeout=100) + return CANParser(DBC[CP.carFingerprint]['pt'], signals, checks, 2) class CarState(object): diff --git a/selfdrive/car/chrysler/interface.py b/selfdrive/car/chrysler/interface.py index 793f73208..65a60904f 100755 --- a/selfdrive/car/chrysler/interface.py +++ b/selfdrive/car/chrysler/interface.py @@ -112,18 +112,17 @@ class CarInterface(object): return ret # returns a car.CarState - def update(self, c): + def update(self, c, can_strings): # ******************* do can recv ******************* - canMonoTimes = [] - can_rcv_valid, _ = self.cp.update(int(sec_since_boot() * 1e9), True) - cam_rcv_valid, _ = self.cp_cam.update(int(sec_since_boot() * 1e9), False) + self.cp.update_strings(int(sec_since_boot() * 1e9), can_strings) + self.cp_cam.update_strings(int(sec_since_boot() * 1e9), can_strings) self.CS.update(self.cp, self.cp_cam) # create message ret = car.CarState.new_message() - ret.canValid = can_rcv_valid and cam_rcv_valid and self.cp.can_valid and self.cp_cam.can_valid + ret.canValid = self.cp.can_valid and self.cp_cam.can_valid # speeds ret.vEgo = self.CS.v_ego @@ -222,7 +221,6 @@ class CarInterface(object): events.append(create_event('belowSteerSpeed', [ET.WARNING])) ret.events = events - ret.canMonoTimes = canMonoTimes self.gas_pressed_prev = ret.gasPressed self.brake_pressed_prev = ret.brakePressed diff --git a/selfdrive/car/chrysler/radar_interface.py b/selfdrive/car/chrysler/radar_interface.py index b4970b222..43f5c6105 100755 --- a/selfdrive/car/chrysler/radar_interface.py +++ b/selfdrive/car/chrysler/radar_interface.py @@ -51,27 +51,24 @@ class RadarInterface(object): self.pts = {} self.delay = 0.0 # Delay of radar #TUNE self.rcp = _create_radar_can_parser() + self.updated_messages = set() + self.trigger_msg = LAST_MSG - def update(self): - canMonoTimes = [] + def update(self, can_strings): + tm = int(sec_since_boot() * 1e9) + vls = self.rcp.update_strings(tm, can_strings) + self.updated_messages.update(vls) - updated_messages = set() # set of message IDs (sig_addresses) we've seen - - while 1: - tm = int(sec_since_boot() * 1e9) - _, vls = self.rcp.update(tm, True) - updated_messages.update(vls) - if LAST_MSG in updated_messages: - break + if self.trigger_msg not in self.updated_messages: + return None ret = car.RadarData.new_message() errors = [] if not self.rcp.can_valid: errors.append("canError") ret.errors = errors - ret.canMonoTimes = canMonoTimes - for ii in updated_messages: # ii should be the message ID as a number + for ii in self.updated_messages: # ii should be the message ID as a number cpt = self.rcp.vl[ii] trackId = _address_to_track(ii) @@ -92,11 +89,6 @@ class RadarInterface(object): # We want a list, not a dictionary. Filter out LONG_DIST==0 because that means it's not valid. ret.points = [x for x in self.pts.values() if x.dRel != 0] - return ret -if __name__ == "__main__": - RI = RadarInterface(None) - while 1: - ret = RI.update() - print(chr(27) + "[2J") # clear screen - print(ret) + self.updated_messages.clear() + return ret diff --git a/selfdrive/car/ford/carstate.py b/selfdrive/car/ford/carstate.py index dc6d824ff..5e87a2c87 100644 --- a/selfdrive/car/ford/carstate.py +++ b/selfdrive/car/ford/carstate.py @@ -29,7 +29,7 @@ def get_can_parser(CP): checks = [ ] - return CANParser(DBC[CP.carFingerprint]['pt'], signals, checks, 0, timeout=100) + return CANParser(DBC[CP.carFingerprint]['pt'], signals, checks, 0) class CarState(object): diff --git a/selfdrive/car/ford/interface.py b/selfdrive/car/ford/interface.py index 0f3bbc33c..ca0f9f830 100755 --- a/selfdrive/car/ford/interface.py +++ b/selfdrive/car/ford/interface.py @@ -105,18 +105,16 @@ class CarInterface(object): return ret # returns a car.CarState - def update(self, c): + def update(self, c, can_strings): # ******************* do can recv ******************* - canMonoTimes = [] - - can_rcv_valid, _ = self.cp.update(int(sec_since_boot() * 1e9), True) + self.cp.update_strings(int(sec_since_boot() * 1e9), can_strings) self.CS.update(self.cp) # create message ret = car.CarState.new_message() - ret.canValid = can_rcv_valid and self.cp.can_valid + ret.canValid = self.cp.can_valid # speeds ret.vEgo = self.CS.v_ego @@ -167,7 +165,6 @@ class CarInterface(object): events.append(create_event('steerTempUnavailableMute', [ET.WARNING])) ret.events = events - ret.canMonoTimes = canMonoTimes self.gas_pressed_prev = ret.gasPressed self.brake_pressed_prev = ret.brakePressed diff --git a/selfdrive/car/ford/radar_interface.py b/selfdrive/car/ford/radar_interface.py index 08b54723d..04cab9c66 100755 --- a/selfdrive/car/ford/radar_interface.py +++ b/selfdrive/car/ford/radar_interface.py @@ -28,28 +28,25 @@ class RadarInterface(object): # Nidec self.rcp = _create_radar_can_parser() + self.trigger_msg = 0x53f + self.updated_messages = set() - def update(self): - canMonoTimes = [] + def update(self, can_strings): + tm = int(sec_since_boot() * 1e9) + vls = self.rcp.update_strings(tm, can_strings) + self.updated_messages.update(vls) - updated_messages = set() - while 1: - tm = int(sec_since_boot() * 1e9) - _, vls = self.rcp.update(tm, True) - updated_messages.update(vls) + if self.trigger_msg not in self.updated_messages: + return None - # TODO: do not hardcode last msg - if 0x53f in updated_messages: - break ret = car.RadarData.new_message() errors = [] if not self.rcp.can_valid: errors.append("canError") ret.errors = errors - ret.canMonoTimes = canMonoTimes - for ii in updated_messages: + for ii in self.updated_messages: cpt = self.rcp.vl[ii] if cpt['X_Rel'] > 0.00001: @@ -78,11 +75,5 @@ class RadarInterface(object): del self.pts[ii] ret.points = self.pts.values() + self.updated_messages.clear() return ret - -if __name__ == "__main__": - RI = RadarInterface(None) - while 1: - ret = RI.update() - print(chr(27) + "[2J") - print(ret) diff --git a/selfdrive/car/gm/carstate.py b/selfdrive/car/gm/carstate.py index 174d11b46..2501598dd 100644 --- a/selfdrive/car/gm/carstate.py +++ b/selfdrive/car/gm/carstate.py @@ -47,7 +47,7 @@ def get_powertrain_can_parser(CP, canbus): ("CruiseState", "AcceleratorPedal2", 0), ] - return CANParser(DBC[CP.carFingerprint]['pt'], signals, [], canbus.powertrain, timeout=100) + return CANParser(DBC[CP.carFingerprint]['pt'], signals, [], canbus.powertrain) class CarState(object): diff --git a/selfdrive/car/gm/interface.py b/selfdrive/car/gm/interface.py index c066a6523..71b0efad2 100755 --- a/selfdrive/car/gm/interface.py +++ b/selfdrive/car/gm/interface.py @@ -170,15 +170,15 @@ class CarInterface(object): return ret # returns a car.CarState - def update(self, c): - can_rcv_valid, _ = self.pt_cp.update(int(sec_since_boot() * 1e9), True) + def update(self, c, can_strings): + self.pt_cp.update_strings(int(sec_since_boot() * 1e9), can_strings) self.CS.update(self.pt_cp) # create message ret = car.CarState.new_message() - ret.canValid = can_rcv_valid and self.pt_cp.can_valid + ret.canValid = self.pt_cp.can_valid # speeds ret.vEgo = self.CS.v_ego diff --git a/selfdrive/car/gm/radar_interface.py b/selfdrive/car/gm/radar_interface.py index 12fb7c234..6788e1ce7 100755 --- a/selfdrive/car/gm/radar_interface.py +++ b/selfdrive/car/gm/radar_interface.py @@ -52,21 +52,23 @@ class RadarInterface(object): print "Using %d as obstacle CAN bus ID" % canbus.obstacle self.rcp = create_radar_can_parser(canbus, CP.carFingerprint) - def update(self): - updated_messages = set() + self.trigger_msg = LAST_RADAR_MSG + self.updated_messages = set() + + def update(self, can_strings): + if self.rcp is None: + time.sleep(0.05) # nothing to do + return car.RadarData.new_message() + + tm = int(sec_since_boot() * 1e9) + vls = self.rcp.update_strings(tm, can_strings) + self.updated_messages.update(vls) + + if self.trigger_msg not in self.updated_messages: + return None + + ret = car.RadarData.new_message() - while 1: - - if self.rcp is None: - time.sleep(0.05) # nothing to do - return ret - - tm = int(sec_since_boot() * 1e9) - _, vls = self.rcp.update(tm, True) - updated_messages.update(vls) - if LAST_RADAR_MSG in updated_messages: - break - header = self.rcp.vl[RADAR_HEADER_MSG] fault = header['FLRRSnsrBlckd'] or header['FLRRSnstvFltPrsntInt'] or \ header['FLRRYawRtPlsblityFlt'] or header['FLRRHWFltPrsntInt'] or \ @@ -83,7 +85,7 @@ class RadarInterface(object): # Not all radar messages describe targets, # no need to monitor all of the self.rcp.msgs_upd - for ii in updated_messages: + for ii in self.updated_messages: if ii == RADAR_HEADER_MSG: continue @@ -112,11 +114,5 @@ class RadarInterface(object): del self.pts[oldTarget] ret.points = self.pts.values() + self.updated_messages.clear() return ret - -if __name__ == "__main__": - RI = RadarInterface(None) - while 1: - ret = RI.update() - print(chr(27) + "[2J") - print(ret) diff --git a/selfdrive/car/honda/carstate.py b/selfdrive/car/honda/carstate.py index 6c0aec52a..e2bb82c73 100644 --- a/selfdrive/car/honda/carstate.py +++ b/selfdrive/car/honda/carstate.py @@ -146,6 +146,7 @@ def get_can_signals(CP): # add gas interceptor reading if we are using it if CP.enableGasInterceptor: signals.append(("INTERCEPTOR_GAS", "GAS_SENSOR", 0)) + signals.append(("INTERCEPTOR_GAS2", "GAS_SENSOR", 0)) checks.append(("GAS_SENSOR", 50)) return signals, checks @@ -153,7 +154,7 @@ def get_can_signals(CP): def get_can_parser(CP): signals, checks = get_can_signals(CP) - return CANParser(DBC[CP.carFingerprint]['pt'], signals, checks, 0, timeout=100) + return CANParser(DBC[CP.carFingerprint]['pt'], signals, checks, 0) def get_cam_can_parser(CP): @@ -166,7 +167,7 @@ def get_cam_can_parser(CP): cam_bus = 1 if CP.carFingerprint in HONDA_BOSCH else 2 - return CANParser(DBC[CP.carFingerprint]['pt'], signals, checks, cam_bus, timeout=100) + return CANParser(DBC[CP.carFingerprint]['pt'], signals, checks, cam_bus) class CarState(object): def __init__(self, CP): @@ -261,7 +262,7 @@ class CarState(object): # this is a hack for the interceptor. This is now only used in the simulation # TODO: Replace tests by toyota so this can go away if self.CP.enableGasInterceptor: - self.user_gas = cp.vl["GAS_SENSOR"]['INTERCEPTOR_GAS'] + self.user_gas = (cp.vl["GAS_SENSOR"]['INTERCEPTOR_GAS'] + cp.vl["GAS_SENSOR"]['INTERCEPTOR_GAS2']) / 2. self.user_gas_pressed = self.user_gas > 0 # this works because interceptor read < 0 when pedal position is 0. Once calibrated, this will change self.gear = 0 if self.CP.carFingerprint == CAR.CIVIC else cp.vl["GEARBOX"]['GEAR'] diff --git a/selfdrive/car/honda/interface.py b/selfdrive/car/honda/interface.py index 93aaf0182..7ad72cdc4 100755 --- a/selfdrive/car/honda/interface.py +++ b/selfdrive/car/honda/interface.py @@ -358,18 +358,17 @@ class CarInterface(object): return ret # returns a car.CarState - def update(self, c): + def update(self, c, can_strings): # ******************* do can recv ******************* - canMonoTimes = [] - can_rcv_valid, _ = self.cp.update(int(sec_since_boot() * 1e9), True) - cam_rcv_valid, _ = self.cp_cam.update(int(sec_since_boot() * 1e9), False) + self.cp.update_strings(int(sec_since_boot() * 1e9), can_strings) + self.cp_cam.update_strings(int(sec_since_boot() * 1e9), can_strings) self.CS.update(self.cp, self.cp_cam) # create message ret = car.CarState.new_message() - ret.canValid = can_rcv_valid and cam_rcv_valid and self.cp.can_valid + ret.canValid = self.cp.can_valid # speeds ret.vEgo = self.CS.v_ego @@ -547,7 +546,6 @@ class CarInterface(object): events.append(create_event('buttonEnable', [ET.ENABLE])) ret.events = events - ret.canMonoTimes = canMonoTimes # update previous brake/gas pressed self.gas_pressed_prev = ret.gasPressed diff --git a/selfdrive/car/honda/radar_interface.py b/selfdrive/car/honda/radar_interface.py index 94e98cf2c..f8cecd6de 100755 --- a/selfdrive/car/honda/radar_interface.py +++ b/selfdrive/car/honda/radar_interface.py @@ -31,25 +31,30 @@ class RadarInterface(object): # Nidec self.rcp = _create_nidec_can_parser() + self.trigger_msg = 0x445 + self.updated_messages = set() - def update(self): - canMonoTimes = [] - - updated_messages = set() - ret = car.RadarData.new_message() - + def update(self, can_strings): # in Bosch radar and we are only steering for now, so sleep 0.05s to keep # radard at 20Hz and return no points if self.radar_off_can: time.sleep(0.05) - return ret + return car.RadarData.new_message() - while 1: - tm = int(sec_since_boot() * 1e9) - _, vls = self.rcp.update(tm, True) - updated_messages.update(vls) - if 0x445 in updated_messages: - break + tm = int(sec_since_boot() * 1e9) + vls = self.rcp.update_strings(tm, can_strings) + self.updated_messages.update(vls) + + if self.trigger_msg not in self.updated_messages: + return None + + rr = self._update(self.updated_messages) + self.updated_messages.clear() + return rr + + + def _update(self, updated_messages): + ret = car.RadarData.new_message() for ii in updated_messages: cpt = self.rcp.vl[ii] @@ -80,19 +85,7 @@ class RadarInterface(object): if self.radar_wrong_config: errors.append("wrongConfig") ret.errors = errors - ret.canMonoTimes = canMonoTimes ret.points = self.pts.values() return ret - - -if __name__ == "__main__": - class CarParams: - radarOffCan = False - - RI = RadarInterface(CarParams) - while 1: - ret = RI.update() - print(chr(27) + "[2J") - print(ret) diff --git a/selfdrive/car/hyundai/carstate.py b/selfdrive/car/hyundai/carstate.py index 8c900d73f..f993bd2a0 100644 --- a/selfdrive/car/hyundai/carstate.py +++ b/selfdrive/car/hyundai/carstate.py @@ -93,7 +93,7 @@ def get_can_parser(CP): ("SAS11", 100) ] - return CANParser(DBC[CP.carFingerprint]['pt'], signals, checks, 0, timeout=100) + return CANParser(DBC[CP.carFingerprint]['pt'], signals, checks, 0) def get_camera_parser(CP): @@ -119,7 +119,7 @@ def get_camera_parser(CP): checks = [] - return CANParser(DBC[CP.carFingerprint]['pt'], signals, checks, 2, timeout=100) + return CANParser(DBC[CP.carFingerprint]['pt'], signals, checks, 2) class CarState(object): diff --git a/selfdrive/car/hyundai/interface.py b/selfdrive/car/hyundai/interface.py index 67ca2261f..4e1b2e6be 100644 --- a/selfdrive/car/hyundai/interface.py +++ b/selfdrive/car/hyundai/interface.py @@ -151,17 +151,16 @@ class CarInterface(object): return ret # returns a car.CarState - def update(self, c): + def update(self, c, can_strings): # ******************* do can recv ******************* - canMonoTimes = [] - can_rcv_valid, _ = self.cp.update(int(sec_since_boot() * 1e9), True) - cam_rcv_valid, _ = self.cp_cam.update(int(sec_since_boot() * 1e9), False) + self.cp.update_strings(int(sec_since_boot() * 1e9), can_strings) + self.cp_cam.update_strings(int(sec_since_boot() * 1e9), can_strings) self.CS.update(self.cp, self.cp_cam) # create message ret = car.CarState.new_message() - ret.canValid = can_rcv_valid and cam_rcv_valid and self.cp.can_valid # TODO: check cp_cam validity + ret.canValid = self.cp.can_valid # TODO: check cp_cam validity # speeds ret.vEgo = self.CS.v_ego @@ -269,7 +268,6 @@ class CarInterface(object): events.append(create_event('belowSteerSpeed', [ET.WARNING])) ret.events = events - ret.canMonoTimes = canMonoTimes self.gas_pressed_prev = ret.gasPressed self.brake_pressed_prev = ret.brakePressed diff --git a/selfdrive/car/hyundai/radar_interface.py b/selfdrive/car/hyundai/radar_interface.py index 75256683d..1d7772fd3 100644 --- a/selfdrive/car/hyundai/radar_interface.py +++ b/selfdrive/car/hyundai/radar_interface.py @@ -9,16 +9,8 @@ class RadarInterface(object): self.pts = {} self.delay = 0.1 - def update(self): - + def update(self, can_strings): ret = car.RadarData.new_message() time.sleep(0.05) # radard runs on RI updates return ret - -if __name__ == "__main__": - RI = RadarInterface(None) - while 1: - ret = RI.update() - print(chr(27) + "[2J") - print(ret) diff --git a/selfdrive/car/mock/interface.py b/selfdrive/car/mock/interface.py index a18d2bf24..3f47b9b00 100755 --- a/selfdrive/car/mock/interface.py +++ b/selfdrive/car/mock/interface.py @@ -80,7 +80,7 @@ class CarInterface(object): return ret # returns a car.CarState - def update(self, c): + def update(self, c, can_strings): self.rk.keep_time() # get basic data from phone and gps since CAN isn't connected diff --git a/selfdrive/car/mock/radar_interface.py b/selfdrive/car/mock/radar_interface.py index 437bb0538..8e5f7b7fc 100755 --- a/selfdrive/car/mock/radar_interface.py +++ b/selfdrive/car/mock/radar_interface.py @@ -9,15 +9,7 @@ class RadarInterface(object): self.pts = {} self.delay = 0.1 - def update(self): - + def update(self, can_strings): ret = car.RadarData.new_message() time.sleep(0.05) # radard runs on RI updates return ret - -if __name__ == "__main__": - RI = RadarInterface(None) - while 1: - ret = RI.update() - print(chr(27) + "[2J") - print(ret) diff --git a/selfdrive/car/subaru/carstate.py b/selfdrive/car/subaru/carstate.py index 9a9277754..6c5f67826 100644 --- a/selfdrive/car/subaru/carstate.py +++ b/selfdrive/car/subaru/carstate.py @@ -37,7 +37,7 @@ def get_powertrain_can_parser(CP): ("BodyInfo", 10), ] - return CANParser(DBC[CP.carFingerprint]['pt'], signals, checks, 0, timeout=100) + return CANParser(DBC[CP.carFingerprint]['pt'], signals, checks, 0) def get_camera_can_parser(CP): @@ -79,7 +79,7 @@ def get_camera_can_parser(CP): ("ES_DashStatus", 10), ] - return CANParser(DBC[CP.carFingerprint]['pt'], signals, checks, 2, timeout=100) + return CANParser(DBC[CP.carFingerprint]['pt'], signals, checks, 2) class CarState(object): diff --git a/selfdrive/car/subaru/interface.py b/selfdrive/car/subaru/interface.py index e9d9c117f..ad8d1d5a4 100644 --- a/selfdrive/car/subaru/interface.py +++ b/selfdrive/car/subaru/interface.py @@ -94,16 +94,16 @@ class CarInterface(object): return ret # returns a car.CarState - def update(self, c): - can_rcv_valid, _ = self.pt_cp.update(int(sec_since_boot() * 1e9), True) - cam_rcv_valid, _ = self.cam_cp.update(int(sec_since_boot() * 1e9), False) + def update(self, c, can_strings): + self.pt_cp.update_strings(int(sec_since_boot() * 1e9), can_strings) + self.cam_cp.update_strings(int(sec_since_boot() * 1e9), can_strings) self.CS.update(self.pt_cp, self.cam_cp) # create message ret = car.CarState.new_message() - ret.canValid = can_rcv_valid and cam_rcv_valid and self.pt_cp.can_valid and self.cam_cp.can_valid + ret.canValid = self.pt_cp.can_valid and self.cam_cp.can_valid # speeds ret.vEgo = self.CS.v_ego diff --git a/selfdrive/car/subaru/radar_interface.py b/selfdrive/car/subaru/radar_interface.py index 75256683d..0f8108771 100644 --- a/selfdrive/car/subaru/radar_interface.py +++ b/selfdrive/car/subaru/radar_interface.py @@ -9,16 +9,9 @@ class RadarInterface(object): self.pts = {} self.delay = 0.1 - def update(self): + def update(self, can_strings): ret = car.RadarData.new_message() time.sleep(0.05) # radard runs on RI updates return ret - -if __name__ == "__main__": - RI = RadarInterface(None) - while 1: - ret = RI.update() - print(chr(27) + "[2J") - print(ret) diff --git a/selfdrive/car/toyota/carstate.py b/selfdrive/car/toyota/carstate.py index ee7c61d94..40be422db 100644 --- a/selfdrive/car/toyota/carstate.py +++ b/selfdrive/car/toyota/carstate.py @@ -1,7 +1,7 @@ import numpy as np from common.kalman.simple_kalman import KF1D -from selfdrive.can.parser import CANParser from selfdrive.can.can_define import CANDefine +from selfdrive.can.parser import CANParser from selfdrive.config import Conversions as CV from selfdrive.car.toyota.values import CAR, DBC, STEER_THRESHOLD, TSS2_CAR @@ -70,9 +70,10 @@ def get_can_parser(CP): # add gas interceptor reading if we are using it if CP.enableGasInterceptor: signals.append(("INTERCEPTOR_GAS", "GAS_SENSOR", 0)) + signals.append(("INTERCEPTOR_GAS2", "GAS_SENSOR", 0)) checks.append(("GAS_SENSOR", 50)) - return CANParser(DBC[CP.carFingerprint]['pt'], signals, checks, 0, timeout=100) + return CANParser(DBC[CP.carFingerprint]['pt'], signals, checks, 0) def get_cam_can_parser(CP): @@ -82,7 +83,7 @@ def get_cam_can_parser(CP): # use steering message to check if panda is connected to frc checks = [("STEERING_LKA", 42)] - return CANParser(DBC[CP.carFingerprint]['pt'], signals, checks, 2, timeout=100) + return CANParser(DBC[CP.carFingerprint]['pt'], signals, checks, 2) class CarState(object): @@ -118,7 +119,7 @@ class CarState(object): self.brake_pressed = cp.vl["BRAKE_MODULE"]['BRAKE_PRESSED'] if self.CP.enableGasInterceptor: - self.pedal_gas = cp.vl["GAS_SENSOR"]['INTERCEPTOR_GAS'] + self.pedal_gas = (cp.vl["GAS_SENSOR"]['INTERCEPTOR_GAS'] + cp.vl["GAS_SENSOR"]['INTERCEPTOR_GAS2']) / 2. else: self.pedal_gas = cp.vl["GAS_PEDAL"]['GAS_PEDAL'] self.car_gas = self.pedal_gas diff --git a/selfdrive/car/toyota/interface.py b/selfdrive/car/toyota/interface.py index 29abfeb84..5e5cb2c83 100755 --- a/selfdrive/car/toyota/interface.py +++ b/selfdrive/car/toyota/interface.py @@ -9,7 +9,6 @@ from selfdrive.car.toyota.values import ECU, check_ecu_msgs, CAR, NO_STOP_TIMER_ from selfdrive.car import STD_CARGO_KG, scale_rot_inertia, scale_tire_stiffness from selfdrive.swaglog import cloudlog - class CarInterface(object): def __init__(self, CP, CarController): self.CP = CP @@ -175,6 +174,16 @@ class CarInterface(object): ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.6], [0.1]] ret.lateralTuning.pid.kf = 0.00007818594 + elif candidate == CAR.SIENNA: + stop_and_go = True + ret.safetyParam = 73 + ret.wheelbase = 3.03 + ret.steerRatio = 16.0 + tire_stiffness_factor = 0.444 + ret.mass = 4590. * CV.LB_TO_KG + STD_CARGO_KG + ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.3], [0.05]] + ret.lateralTuning.pid.kf = 0.00007818594 + ret.steerRateCost = 1. ret.centerToFront = ret.wheelbase * 0.44 @@ -201,8 +210,8 @@ class CarInterface(object): # steer, gas, brake limitations VS speed ret.steerMaxBP = [16. * CV.KPH_TO_MS, 45. * CV.KPH_TO_MS] # breakpoints at 1 and 40 kph ret.steerMaxV = [1., 1.] # 2/3rd torque allowed above 45 kph - ret.brakeMaxBP = [5., 20.] - ret.brakeMaxV = [1., 0.8] + ret.brakeMaxBP = [0.] + ret.brakeMaxV = [1.] ret.enableCamera = not check_ecu_msgs(fingerprint, ECU.CAM) ret.enableDsu = not check_ecu_msgs(fingerprint, ECU.DSU) @@ -236,22 +245,20 @@ class CarInterface(object): return ret # returns a car.CarState - def update(self, c): + def update(self, c, can_strings): # ******************* do can recv ******************* - canMonoTimes = [] - - can_rcv_valid, _ = self.cp.update(int(sec_since_boot() * 1e9), True) + self.cp.update_strings(int(sec_since_boot() * 1e9), can_strings) # run the cam can update for 10s as we just need to know if the camera is alive if self.frame < 1000: - self.cp_cam.update(int(sec_since_boot() * 1e9), False) + self.cp_cam.update_strings(int(sec_since_boot() * 1e9), can_strings) self.CS.update(self.cp) # create message ret = car.CarState.new_message() - ret.canValid = can_rcv_valid and self.cp.can_valid + ret.canValid = self.cp.can_valid # speeds ret.vEgo = self.CS.v_ego @@ -368,7 +375,6 @@ class CarInterface(object): events.append(create_event('pedalPressed', [ET.PRE_ENABLE])) ret.events = events - ret.canMonoTimes = canMonoTimes self.gas_pressed_prev = ret.gasPressed self.brake_pressed_prev = ret.brakePressed diff --git a/selfdrive/car/toyota/radar_interface.py b/selfdrive/car/toyota/radar_interface.py index c160e751a..4e0a0e809 100755 --- a/selfdrive/car/toyota/radar_interface.py +++ b/selfdrive/car/toyota/radar_interface.py @@ -46,32 +46,36 @@ class RadarInterface(object): self.valid_cnt = {key: 0 for key in self.RADAR_A_MSGS} self.rcp = _create_radar_can_parser(CP.carFingerprint) + self.trigger_msg = self.RADAR_B_MSGS[-1] + self.updated_messages = set() + # No radar dbc for cars without DSU which are not TSS 2.0 # TODO: make a adas dbc file for dsu-less models self.no_radar = CP.carFingerprint in NO_DSU_CAR and CP.carFingerprint not in TSS2_CAR - def update(self): - - ret = car.RadarData.new_message() - + def update(self, can_strings): if self.no_radar: time.sleep(0.05) - return ret + return car.RadarData.new_message() - canMonoTimes = [] - updated_messages = set() - while 1: - tm = int(sec_since_boot() * 1e9) - _, vls = self.rcp.update(tm, True) - updated_messages.update(vls) - if self.RADAR_B_MSGS[-1] in updated_messages: - break + tm = int(sec_since_boot() * 1e9) + vls = self.rcp.update_strings(tm, can_strings) + self.updated_messages.update(vls) + if self.trigger_msg not in self.updated_messages: + return None + + rr = self._update(self.updated_messages) + self.updated_messages.clear() + + return rr + + def _update(self, updated_messages): + ret = car.RadarData.new_message() errors = [] if not self.rcp.can_valid: errors.append("canError") ret.errors = errors - ret.canMonoTimes = canMonoTimes for ii in updated_messages: if ii in self.RADAR_A_MSGS: @@ -105,10 +109,3 @@ class RadarInterface(object): ret.points = self.pts.values() return ret - -if __name__ == "__main__": - RI = RadarInterface(None) - while 1: - ret = RI.update() - print(chr(27) + "[2J") - print(ret) diff --git a/selfdrive/car/toyota/values.py b/selfdrive/car/toyota/values.py index da8b02dcd..df535eab0 100644 --- a/selfdrive/car/toyota/values.py +++ b/selfdrive/car/toyota/values.py @@ -16,6 +16,7 @@ class CAR: RAV4_TSS2 = "TOYOTA RAV4 2019" COROLLA_TSS2 = "TOYOTA COROLLA TSS2 2019" LEXUS_ESH_TSS2 = "LEXUS ES 300H 2019" + SIENNA = "TOYOTA SIENNA XLE 2018" class ECU: @@ -42,23 +43,23 @@ STATIC_MSGS = [ (0x4d3, ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA, CAR.AVALON), 0, 100, '\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, '\xf4\x01\x90\x83\x00\x37'), - (0x128, ECU.DSU, (CAR.HIGHLANDER, CAR.HIGHLANDERH), 1, 3, '\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), 1, 2, '\x00\x00\x00\x46'), - (0x160, ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA, CAR.HIGHLANDER, CAR.HIGHLANDERH, CAR.AVALON), 1, 7, '\x00\x00\x08\x12\x01\x31\x9c\x51'), + (0x128, ECU.DSU, (CAR.HIGHLANDER, CAR.HIGHLANDERH, CAR.SIENNA), 1, 3, '\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), 1, 2, '\x00\x00\x00\x46'), + (0x160, ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA, CAR.HIGHLANDER, CAR.HIGHLANDERH, CAR.AVALON, CAR.SIENNA), 1, 7, '\x00\x00\x08\x12\x01\x31\x9c\x51'), (0x161, ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA, CAR.AVALON), 1, 7, '\x00\x1e\x00\x00\x00\x80\x07'), - (0X161, ECU.DSU, (CAR.HIGHLANDERH, CAR.HIGHLANDER), 1, 7, '\x00\x1e\x00\xd4\x00\x00\x5b'), - (0x283, ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA, CAR.HIGHLANDER, CAR.HIGHLANDERH, CAR.AVALON), 0, 3, '\x00\x00\x00\x00\x00\x00\x8c'), + (0X161, ECU.DSU, (CAR.HIGHLANDERH, CAR.HIGHLANDER, CAR.SIENNA), 1, 7, '\x00\x1e\x00\xd4\x00\x00\x5b'), + (0x283, ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA, CAR.HIGHLANDER, CAR.HIGHLANDERH, CAR.AVALON, CAR.SIENNA), 0, 3, '\x00\x00\x00\x00\x00\x00\x8c'), (0x2E6, ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH), 0, 3, '\xff\xf8\x00\x08\x7f\xe0\x00\x4e'), (0x2E7, ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH), 0, 3, '\xa8\x9c\x31\x9c\x00\x00\x00\x02'), (0x33E, ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH), 0, 20, '\x0f\xff\x26\x40\x00\x1f\x00'), - (0x344, ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA, CAR.HIGHLANDER, CAR.HIGHLANDERH, CAR.AVALON), 0, 5, '\x00\x00\x01\x00\x00\x00\x00\x50'), + (0x344, ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA, CAR.HIGHLANDER, CAR.HIGHLANDERH, CAR.AVALON, CAR.SIENNA), 0, 5, '\x00\x00\x01\x00\x00\x00\x00\x50'), (0x365, ECU.DSU, (CAR.PRIUS, CAR.LEXUS_RXH, CAR.HIGHLANDERH), 0, 20, '\x00\x00\x00\x80\x03\x00\x08'), - (0x365, ECU.DSU, (CAR.RAV4, CAR.RAV4H, CAR.COROLLA, CAR.HIGHLANDER, CAR.AVALON), 0, 20, '\x00\x00\x00\x80\xfc\x00\x08'), + (0x365, ECU.DSU, (CAR.RAV4, CAR.RAV4H, CAR.COROLLA, CAR.HIGHLANDER, CAR.AVALON, CAR.SIENNA), 0, 20, '\x00\x00\x00\x80\xfc\x00\x08'), (0x366, ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.HIGHLANDERH), 0, 20, '\x00\x00\x4d\x82\x40\x02\x00'), - (0x366, ECU.DSU, (CAR.RAV4, CAR.COROLLA, CAR.HIGHLANDER, CAR.AVALON), 0, 20, '\x00\x72\x07\xff\x09\xfe\x00'), + (0x366, ECU.DSU, (CAR.RAV4, CAR.COROLLA, CAR.HIGHLANDER, CAR.AVALON, CAR.SIENNA), 0, 20, '\x00\x72\x07\xff\x09\xfe\x00'), (0x470, ECU.DSU, (CAR.PRIUS, CAR.LEXUS_RXH), 1, 100, '\x00\x00\x02\x7a'), - (0x470, ECU.DSU, (CAR.HIGHLANDER, CAR.HIGHLANDERH, CAR.RAV4H), 1, 100, '\x00\x00\x01\x79'), - (0x4CB, ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA, CAR.HIGHLANDERH, CAR.HIGHLANDER, CAR.AVALON), 0, 100, '\x0c\x00\x00\x00\x00\x00\x00\x00'), + (0x470, ECU.DSU, (CAR.HIGHLANDER, CAR.HIGHLANDERH, CAR.RAV4H, CAR.SIENNA), 1, 100, '\x00\x00\x01\x79'), + (0x4CB, ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA, CAR.HIGHLANDERH, CAR.HIGHLANDER, CAR.AVALON, CAR.SIENNA), 0, 100, '\x0c\x00\x00\x00\x00\x00\x00\x00'), (0x292, ECU.APGS, (CAR.PRIUS), 0, 3, '\x00\x00\x00\x00\x00\x00\x00\x9e'), (0x32E, ECU.APGS, (CAR.PRIUS), 0, 20, '\x00\x00\x00\x00\x00\x00\x00\x00'), @@ -178,6 +179,9 @@ FINGERPRINTS = { { 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 + }], } STEER_THRESHOLD = 100 @@ -198,8 +202,9 @@ DBC = { 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.LEXUS_ESH_TSS2: dbc_dict('toyota_nodsu_pt_generated', 'toyota_tss2_adas'), + CAR.SIENNA: dbc_dict('toyota_sienna_xle_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] TSS2_CAR = [CAR.RAV4_TSS2, CAR.COROLLA_TSS2, CAR.LEXUS_ESH_TSS2] -NO_STOP_TIMER_CAR = [CAR.RAV4H, CAR.HIGHLANDERH, CAR.HIGHLANDER, CAR.RAV4_TSS2, CAR.COROLLA_TSS2, CAR.LEXUS_ESH_TSS2] # no resume button press required +NO_STOP_TIMER_CAR = [CAR.RAV4H, CAR.HIGHLANDERH, CAR.HIGHLANDER, CAR.RAV4_TSS2, CAR.COROLLA_TSS2, CAR.LEXUS_ESH_TSS2, CAR.SIENNA] # no resume button press required diff --git a/selfdrive/common/version.h b/selfdrive/common/version.h index ad486deed..5c21a9db8 100644 --- a/selfdrive/common/version.h +++ b/selfdrive/common/version.h @@ -1 +1 @@ -#define COMMA_VERSION "0.6-release" +#define COMMA_VERSION "0.6.1-release" diff --git a/selfdrive/controls/controlsd.py b/selfdrive/controls/controlsd.py index f1c556ba1..5c5ba2f66 100755 --- a/selfdrive/controls/controlsd.py +++ b/selfdrive/controls/controlsd.py @@ -22,7 +22,7 @@ from selfdrive.controls.lib.latcontrol_pid import LatControlPID from selfdrive.controls.lib.latcontrol_indi import LatControlINDI from selfdrive.controls.lib.alertmanager import AlertManager from selfdrive.controls.lib.vehicle_model import VehicleModel -from selfdrive.controls.lib.driver_monitor import DriverStatus +from selfdrive.controls.lib.driver_monitor import DriverStatus, MAX_TERMINAL_ALERTS from selfdrive.controls.lib.planner import LON_MPC_STEP from selfdrive.locationd.calibration_helpers import Calibration, Filter @@ -49,16 +49,22 @@ def events_to_bytes(events): return ret -def data_sample(CI, CC, sm, 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 - CS = CI.update(CC) + can_strs = messaging.drain_sock_raw(can_sock, wait_for_one=True) + CS = CI.update(CC, can_strs) + + sm.update(0) + events = list(CS.events) enabled = isEnabled(state) - sm.update(0) + # Check for CAN timeout + if not can_strs: + events.append(create_event('canError', [ET.NO_ENTRY, ET.IMMEDIATE_DISABLE])) if sm.updated['thermal']: overtemp = sm['thermal'].thermalStatus >= ThermalStatus.red @@ -73,6 +79,7 @@ def data_sample(CI, CC, sm, cal_status, cal_perc, overtemp, free_space, low_batt if free_space: events.append(create_event('outOfSpace', [ET.NO_ENTRY])) + # Handle calibration if sm.updated['liveCalibration']: cal_status = sm['liveCalibration'].calStatus @@ -102,6 +109,9 @@ def data_sample(CI, CC, sm, cal_status, cal_perc, overtemp, free_space, low_batt if sm.updated['driverMonitoring']: driver_status.get_pose(sm['driverMonitoring'], params) + if driver_status.terminal_alert_cnt >= MAX_TERMINAL_ALERTS: + events.append(create_event("tooDistracted", [ET.NO_ENTRY])) + return CS, events, cal_status, cal_perc, overtemp, free_space, low_battery, mismatch_counter @@ -402,6 +412,7 @@ def controlsd_thread(gctx=None): params = Params() + # Pub Sockets sendcan = messaging.pub_sock(service_list['sendcan'].port) controlsstate = messaging.pub_sock(service_list['controlsState'].port) @@ -414,10 +425,15 @@ def controlsd_thread(gctx=None): passive = params.get("Passive") != "0" sm = messaging.SubMaster(['thermal', 'health', 'liveCalibration', 'driverMonitoring', 'plan', 'pathPlan']) + logcan = messaging.sub_sock(service_list['can'].port) + CI, CP = get_car(logcan, sendcan) + logcan.close() + + # TODO: Use the logcan socket from above, but that will currenly break the tests + can_sock = messaging.sub_sock(service_list['can'].port, timeout=100) CC = car.CarControl.new_message() - CI, CP = get_car(logcan, sendcan) AM = AlertManager() car_recognized = CP.carName != 'mock' @@ -469,7 +485,7 @@ def controlsd_thread(gctx=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, 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 da7e88acb..0b0d5b1d5 100644 --- a/selfdrive/controls/lib/alerts.py +++ b/selfdrive/controls/lib/alerts.py @@ -298,6 +298,13 @@ ALERTS = [ AlertStatus.normal, AlertSize.mid, Priority.LOW, VisualAlert.none, AudibleAlert.chimeError, .4, 2., 3.), + Alert( + "tooDistractedNoEntry", + "openpilot Unavailable", + "Distraction Level Too High", + AlertStatus.normal, AlertSize.mid, + Priority.LOW, VisualAlert.none, AudibleAlert.chimeError, .4, 2., 3.), + # Cancellation alerts causing soft disabling Alert( "overheat", diff --git a/selfdrive/controls/lib/driver_monitor.py b/selfdrive/controls/lib/driver_monitor.py index e813d0b17..d38a115f9 100644 --- a/selfdrive/controls/lib/driver_monitor.py +++ b/selfdrive/controls/lib/driver_monitor.py @@ -14,11 +14,12 @@ _PITCH_WEIGHT = 1.5 # pitch matters a lot more _METRIC_THRESHOLD = 0.4 _PITCH_POS_ALLOWANCE = 0.08 # rad, to not be too sensitive on positive pitch _PITCH_NATURAL_OFFSET = 0.1 # people don't seem to look straight when they drive relaxed, rather a bit up -_YAW_NATURAL_OFFSET = 0.08 # people don't seem to look straight when they drive relaxed, rather a bit to the right (center of car) +_YAW_NATURAL_OFFSET = 0.08 # people don't seem to look straight when they drive relaxed, rather a bit to the right (center of car) _STD_THRESHOLD = 0.1 # above this standard deviation consider the measurement invalid _DISTRACTED_FILTER_TS = 0.25 # 0.6Hz _VARIANCE_FILTER_TS = 20. # 0.008Hz +MAX_TERMINAL_ALERTS = 3 # not allowed to engage after 3 terminal alerts RESIZED_FOCAL = 320.0 H, W, FULL_W = 320, 160, 426 @@ -68,6 +69,7 @@ class DriverStatus(): self.variance_filter = FirstOrderFilter(0., _VARIANCE_FILTER_TS, DT_DMON) self.ts_last_check = 0. self.face_detected = False + self.terminal_alert_cnt = 0 self._set_timers() def _reset_filters(self): @@ -133,6 +135,7 @@ class DriverStatus(): def update(self, events, driver_engaged, ctrl_active, standstill): driver_engaged |= (self.driver_distraction_filter.x < 0.37 and self.monitor_on) + awareness_prev = self.awareness if (driver_engaged and self.awareness > 0.) or not ctrl_active: # always reset if driver is in control (unless we are in red alert state) or op isn't active @@ -144,15 +147,18 @@ class DriverStatus(): self.awareness = max(self.awareness - self.step_change, -0.1) alert = None - if self.awareness <= 0.: + if self.awareness < 0.: # terminal red alert: disengagement required alert = 'driverDistracted' if self.monitor_on else 'driverUnresponsive' + if awareness_prev >= 0.: + self.terminal_alert_cnt += 1 elif self.awareness <= self.threshold_prompt: # prompt orange alert alert = 'promptDriverDistracted' if self.monitor_on else 'promptDriverUnresponsive' elif self.awareness <= self.threshold_pre: # pre green alert alert = 'preDriverDistracted' if self.monitor_on else 'preDriverUnresponsive' + if alert is not None: events.append(create_event(alert, [ET.WARNING])) diff --git a/selfdrive/controls/lib/fcw.py b/selfdrive/controls/lib/fcw.py index f93a72cfc..8180fadeb 100644 --- a/selfdrive/controls/lib/fcw.py +++ b/selfdrive/controls/lib/fcw.py @@ -43,8 +43,10 @@ class FCWChecker(object): ttc = np.minimum(2 * x_lead / (np.sqrt(delta) + v_rel), max_ttc) return ttc - def update(self, mpc_solution, cur_time, v_ego, a_ego, x_lead, v_lead, a_lead, y_lead, vlat_lead, fcw_lead, blinkers): + def update(self, mpc_solution, cur_time, active, v_ego, a_ego, x_lead, v_lead, a_lead, y_lead, vlat_lead, fcw_lead, blinkers): mpc_solution_a = list(mpc_solution[0].a_ego) + a_target = mpc_solution_a[1] + self.last_min_a = min(mpc_solution_a) self.v_lead_max = max(self.v_lead_max, v_lead) @@ -62,8 +64,11 @@ class FCWChecker(object): a_thr = interp(v_lead, _FCW_A_ACT_BP, _FCW_A_ACT_V) a_delta = min(mpc_solution_a[:15]) - min(0.0, a_ego) - fcw_allowed = all(c >= 10 for c in self.counters.values()) - if (self.last_min_a < -3.0 or a_delta < a_thr) and fcw_allowed and self.last_fcw_time + 5.0 < cur_time: + future_fcw_allowed = all(c >= 10 for c in self.counters.values()) + future_fcw = (self.last_min_a < -3.0 or a_delta < a_thr) and future_fcw_allowed + current_fcw = a_target < -3.0 and active + + if (future_fcw or current_fcw) and (self.last_fcw_time + 5.0 < cur_time): self.last_fcw_time = cur_time self.last_fcw_a = self.last_min_a return True diff --git a/selfdrive/controls/lib/planner.py b/selfdrive/controls/lib/planner.py index 9aaec513b..94cc2fc13 100755 --- a/selfdrive/controls/lib/planner.py +++ b/selfdrive/controls/lib/planner.py @@ -201,7 +201,9 @@ class Planner(object): self.fcw_checker.reset_lead(cur_time) blinkers = sm['carState'].leftBlinker or sm['carState'].rightBlinker - fcw = self.fcw_checker.update(self.mpc1.mpc_solution, cur_time, v_ego, sm['carState'].aEgo, + fcw = self.fcw_checker.update(self.mpc1.mpc_solution, cur_time, + sm['controlsState'].active, + v_ego, sm['carState'].aEgo, lead_1.dRel, lead_1.vLead, lead_1.aLeadK, lead_1.yRel, lead_1.vLat, lead_1.fcw, blinkers) and not sm['carState'].brakePressed diff --git a/selfdrive/controls/radard.py b/selfdrive/controls/radard.py index b37ed8f75..afb4ffd2b 100755 --- a/selfdrive/controls/radard.py +++ b/selfdrive/controls/radard.py @@ -26,6 +26,11 @@ DIMSV = 2 XV, SPEEDV = 0, 1 VISION_POINT = -1 +path_x = np.arange(0.0, 140.0, 0.1) # 140 meters is max + +# Time-alignment +rate = 1. / DT_MDL # model and radar are both at 20Hz +v_len = 20 # how many speed data points to remember for t alignment with rdr data class EKFV1D(EKF): def __init__(self): @@ -43,6 +48,185 @@ class EKFV1D(EKF): tfj = tf return tf, tfj +class RadarD(object): + def __init__(self, VM, mocked): + self.VM = VM + self.mocked = mocked + + self.MP = ModelParser() + self.tracks = defaultdict(dict) + + self.last_md_ts = 0 + self.last_controls_state_ts = 0 + + self.active = 0 + self.steer_angle = 0. + self.steer_override = False + + # Kalman filter stuff: + self.ekfv = EKFV1D() + self.speedSensorV = SimpleSensor(XV, 1, 2) + + # v_ego + self.v_ego = 0. + self.v_ego_hist_t = deque([0], maxlen=v_len) + self.v_ego_hist_v = deque([0], maxlen=v_len) + self.v_ego_t_aligned = 0. + + def update(self, frame, delay, sm, rr): + ar_pts = {} + for pt in rr.points: + ar_pts[pt.trackId] = [pt.dRel + RDR_TO_LDR, pt.yRel, pt.vRel, pt.measured] + + if sm.updated['liveParameters']: + self.VM.update_params(sm['liveParameters'].stiffnessFactor, sm['liveParameters'].steerRatio) + + if sm.updated['controlsState']: + self.active = sm['controlsState'].active + self.v_ego = sm['controlsState'].vEgo + self.steer_angle = sm['controlsState'].angleSteers + self.steer_override = sm['controlsState'].steerOverride + + self.v_ego_hist_v.append(self.v_ego) + self.v_ego_hist_t.append(float(frame)/rate) + + self.last_controls_state_ts = sm.logMonoTime['controlsState'] + + if sm.updated['model']: + self.last_md_ts = sm.logMonoTime['model'] + self.MP.update(self.v_ego, sm['model']) + + # run kalman filter only if prob is high enough + if self.MP.lead_prob > 0.7: + reading = self.speedSensorV.read(self.MP.lead_dist, covar=np.matrix(self.MP.lead_var)) + self.ekfv.update_scalar(reading) + self.ekfv.predict(DT_MDL) + + # When changing lanes the distance to the lead car can suddenly change, + # which makes the Kalman filter output large relative acceleration + if self.mocked and abs(self.MP.lead_dist - self.ekfv.state[XV]) > 2.0: + self.ekfv.state[XV] = self.MP.lead_dist + self.ekfv.covar = (np.diag([self.MP.lead_var, self.ekfv.var_init])) + self.ekfv.state[SPEEDV] = 0. + + ar_pts[VISION_POINT] = (float(self.ekfv.state[XV]), np.polyval(self.MP.d_poly, float(self.ekfv.state[XV])), + float(self.ekfv.state[SPEEDV]), False) + else: + self.ekfv.state[XV] = self.MP.lead_dist + self.ekfv.covar = (np.diag([self.MP.lead_var, self.ekfv.var_init])) + self.ekfv.state[SPEEDV] = 0. + + if VISION_POINT in ar_pts: + del ar_pts[VISION_POINT] + + # *** compute the likely path_y *** + if (self.active and not self.steer_override) or self.mocked: + # use path from model (always when mocking as steering is too noisy) + path_y = np.polyval(self.MP.d_poly, path_x) + else: + # use path from steer, set angle_offset to 0 it does not only report the physical offset + path_y = calc_lookahead_offset(self.v_ego, self.steer_angle, path_x, self.VM, angle_offset=sm['liveParameters'].angleOffsetAverage)[0] + + # *** remove missing points from meta data *** + for ids in self.tracks.keys(): + if ids not in ar_pts: + self.tracks.pop(ids, None) + + # *** compute the tracks *** + for ids in ar_pts: + # ignore standalone vision point, unless we are mocking the radar + if ids == VISION_POINT and not self.mocked: + continue + rpt = ar_pts[ids] + + # align v_ego by a fixed time to align it with the radar measurement + cur_time = float(frame)/rate + self.v_ego_t_aligned = np.interp(cur_time - delay, self.v_ego_hist_t, self.v_ego_hist_v) + + d_path = np.sqrt(np.amin((path_x - rpt[0]) ** 2 + (path_y - rpt[1]) ** 2)) + # add sign + d_path *= np.sign(rpt[1] - np.interp(rpt[0], path_x, path_y)) + + # create the track if it doesn't exist or it's a new track + if ids not in self.tracks: + self.tracks[ids] = Track() + self.tracks[ids].update(rpt[0], rpt[1], rpt[2], d_path, self.v_ego_t_aligned, rpt[3], self.steer_override) + + # allow the vision model to remove the stationary flag if distance and rel speed roughly match + if VISION_POINT in ar_pts: + fused_id = None + best_score = NO_FUSION_SCORE + for ids in self.tracks: + dist_to_vision = np.sqrt((0.5*(ar_pts[VISION_POINT][0] - self.tracks[ids].dRel)) ** 2 + (2*(ar_pts[VISION_POINT][1] - self.tracks[ids].yRel)) ** 2) + rel_speed_diff = abs(ar_pts[VISION_POINT][2] - self.tracks[ids].vRel) + self.tracks[ids].update_vision_score(dist_to_vision, rel_speed_diff) + if best_score > self.tracks[ids].vision_score: + fused_id = ids + best_score = self.tracks[ids].vision_score + + if fused_id is not None: + self.tracks[fused_id].vision_cnt += 1 + self.tracks[fused_id].update_vision_fusion() + + if DEBUG: + print("NEW CYCLE") + if VISION_POINT in ar_pts: + print("vision", ar_pts[VISION_POINT]) + + idens = list(self.tracks.keys()) + track_pts = np.array([self.tracks[iden].get_key_for_cluster() for iden in idens]) + + # If we have multiple points, cluster them + if len(track_pts) > 1: + cluster_idxs = cluster_points_centroid(track_pts, 2.5) + clusters = [None] * (max(cluster_idxs) + 1) + + for idx in xrange(len(track_pts)): + cluster_i = cluster_idxs[idx] + if clusters[cluster_i] is None: + clusters[cluster_i] = Cluster() + clusters[cluster_i].add(self.tracks[idens[idx]]) + + elif len(track_pts) == 1: + # TODO: why do we need this? + clusters = [Cluster()] + clusters[0].add(self.tracks[idens[0]]) + else: + clusters = [] + + if DEBUG: + for i in clusters: + print(i) + # *** extract the lead car *** + lead_clusters = [c for c in clusters + if c.is_potential_lead(self.v_ego)] + lead_clusters.sort(key=lambda x: x.dRel) + lead_len = len(lead_clusters) + + # *** extract the second lead from the whole set of leads *** + lead2_clusters = [c for c in lead_clusters + if c.is_potential_lead2(lead_clusters)] + lead2_clusters.sort(key=lambda x: x.dRel) + lead2_len = len(lead2_clusters) + + # *** publish radarState *** + dat = messaging.new_message() + dat.init('radarState') + dat.valid = sm.all_alive_and_valid(service_list=['controlsState']) + dat.radarState.mdMonoTime = self.last_md_ts + dat.radarState.canMonoTimes = list(rr.canMonoTimes) + dat.radarState.radarErrors = list(rr.errors) + dat.radarState.controlsStateMonoTime = self.last_controls_state_ts + if lead_len > 0: + dat.radarState.leadOne = lead_clusters[0].toRadarState() + if lead2_len > 0: + dat.radarState.leadTwo = lead2_clusters[0].toRadarState() + else: + dat.radarState.leadTwo.status = False + else: + dat.radarState.leadOne.status = False + + return dat ## fuses camera and radar data for best lead detection def radard_thread(gctx=None): @@ -59,210 +243,34 @@ def radard_thread(gctx=None): cloudlog.info("radard is importing %s", CP.carName) RadarInterface = importlib.import_module('selfdrive.car.%s.radar_interface' % CP.carName).RadarInterface + can_sock = messaging.sub_sock(service_list['can'].port) sm = messaging.SubMaster(['model', 'controlsState', 'liveParameters']) - # Default parameters - live_parameters = messaging.new_message() - live_parameters.init('liveParameters') - live_parameters.liveParameters.valid = True - live_parameters.liveParameters.steerRatio = CP.steerRatio - live_parameters.liveParameters.stiffnessFactor = 1.0 - - MP = ModelParser() RI = RadarInterface(CP) - last_md_ts = 0 - last_controls_state_ts = 0 - # *** publish radarState and liveTracks radarState = messaging.pub_sock(service_list['radarState'].port) liveTracks = messaging.pub_sock(service_list['liveTracks'].port) - path_x = np.arange(0.0, 140.0, 0.1) # 140 meters is max - - # Time-alignment - rate = 1. / DT_MDL # model and radar are both at 20Hz - v_len = 20 # how many speed data points to remember for t alignment with rdr data - - active = 0 - steer_angle = 0. - steer_override = False - - tracks = defaultdict(dict) - - # Kalman filter stuff: - ekfv = EKFV1D() - speedSensorV = SimpleSensor(XV, 1, 2) - - # v_ego - v_ego = 0. - v_ego_hist_t = deque([0], maxlen=v_len) - v_ego_hist_v = deque([0], maxlen=v_len) - v_ego_t_aligned = 0. - rk = Ratekeeper(rate, print_delay_threshold=None) - while 1: - rr = RI.update() + RD = RadarD(VM, mocked) - ar_pts = {} - for pt in rr.points: - ar_pts[pt.trackId] = [pt.dRel + RDR_TO_LDR, pt.yRel, pt.vRel, pt.measured] + while 1: + can_strings = messaging.drain_sock_raw(can_sock, wait_for_one=True) + rr = RI.update(can_strings) + + if rr is None: + continue sm.update(0) - if sm.updated['liveParameters']: - VM.update_params(sm['liveParameters'].stiffnessFactor, sm['liveParameters'].steerRatio) - - if sm.updated['controlsState']: - active = sm['controlsState'].active - v_ego = sm['controlsState'].vEgo - steer_angle = sm['controlsState'].angleSteers - steer_override = sm['controlsState'].steerOverride - - v_ego_hist_v.append(v_ego) - v_ego_hist_t.append(float(rk.frame)/rate) - - last_controls_state_ts = sm.logMonoTime['controlsState'] - - if sm.updated['model']: - last_md_ts = sm.logMonoTime['model'] - MP.update(v_ego, sm['model']) - - - # run kalman filter only if prob is high enough - if MP.lead_prob > 0.7: - reading = speedSensorV.read(MP.lead_dist, covar=np.matrix(MP.lead_var)) - ekfv.update_scalar(reading) - ekfv.predict(DT_MDL) - - # When changing lanes the distance to the lead car can suddenly change, - # which makes the Kalman filter output large relative acceleration - if mocked and abs(MP.lead_dist - ekfv.state[XV]) > 2.0: - ekfv.state[XV] = MP.lead_dist - ekfv.covar = (np.diag([MP.lead_var, ekfv.var_init])) - ekfv.state[SPEEDV] = 0. - - ar_pts[VISION_POINT] = (float(ekfv.state[XV]), np.polyval(MP.d_poly, float(ekfv.state[XV])), - float(ekfv.state[SPEEDV]), False) - else: - ekfv.state[XV] = MP.lead_dist - ekfv.covar = (np.diag([MP.lead_var, ekfv.var_init])) - ekfv.state[SPEEDV] = 0. - - if VISION_POINT in ar_pts: - del ar_pts[VISION_POINT] - - # *** compute the likely path_y *** - if (active and not steer_override) or mocked: - # use path from model (always when mocking as steering is too noisy) - path_y = np.polyval(MP.d_poly, path_x) - else: - # use path from steer, set angle_offset to 0 it does not only report the physical offset - path_y = calc_lookahead_offset(v_ego, steer_angle, path_x, VM, angle_offset=live_parameters.liveParameters.angleOffsetAverage)[0] - - # *** remove missing points from meta data *** - for ids in tracks.keys(): - if ids not in ar_pts: - tracks.pop(ids, None) - - # *** compute the tracks *** - for ids in ar_pts: - # ignore standalone vision point, unless we are mocking the radar - if ids == VISION_POINT and not mocked: - continue - rpt = ar_pts[ids] - - # align v_ego by a fixed time to align it with the radar measurement - cur_time = float(rk.frame)/rate - v_ego_t_aligned = np.interp(cur_time - RI.delay, v_ego_hist_t, v_ego_hist_v) - - d_path = np.sqrt(np.amin((path_x - rpt[0]) ** 2 + (path_y - rpt[1]) ** 2)) - # add sign - d_path *= np.sign(rpt[1] - np.interp(rpt[0], path_x, path_y)) - - # create the track if it doesn't exist or it's a new track - if ids not in tracks: - tracks[ids] = Track() - tracks[ids].update(rpt[0], rpt[1], rpt[2], d_path, v_ego_t_aligned, rpt[3], steer_override) - - # allow the vision model to remove the stationary flag if distance and rel speed roughly match - if VISION_POINT in ar_pts: - fused_id = None - best_score = NO_FUSION_SCORE - for ids in tracks: - dist_to_vision = np.sqrt((0.5*(ar_pts[VISION_POINT][0] - tracks[ids].dRel)) ** 2 + (2*(ar_pts[VISION_POINT][1] - tracks[ids].yRel)) ** 2) - rel_speed_diff = abs(ar_pts[VISION_POINT][2] - tracks[ids].vRel) - tracks[ids].update_vision_score(dist_to_vision, rel_speed_diff) - if best_score > tracks[ids].vision_score: - fused_id = ids - best_score = tracks[ids].vision_score - - if fused_id is not None: - tracks[fused_id].vision_cnt += 1 - tracks[fused_id].update_vision_fusion() - - if DEBUG: - print("NEW CYCLE") - if VISION_POINT in ar_pts: - print("vision", ar_pts[VISION_POINT]) - - idens = list(tracks.keys()) - track_pts = np.array([tracks[iden].get_key_for_cluster() for iden in idens]) - - # If we have multiple points, cluster them - if len(track_pts) > 1: - cluster_idxs = cluster_points_centroid(track_pts, 2.5) - clusters = [None] * (max(cluster_idxs) + 1) - - for idx in xrange(len(track_pts)): - cluster_i = cluster_idxs[idx] - if clusters[cluster_i] is None: - clusters[cluster_i] = Cluster() - clusters[cluster_i].add(tracks[idens[idx]]) - - elif len(track_pts) == 1: - # TODO: why do we need this? - clusters = [Cluster()] - clusters[0].add(tracks[idens[0]]) - else: - clusters = [] - - if DEBUG: - for i in clusters: - print(i) - # *** extract the lead car *** - lead_clusters = [c for c in clusters - if c.is_potential_lead(v_ego)] - lead_clusters.sort(key=lambda x: x.dRel) - lead_len = len(lead_clusters) - - # *** extract the second lead from the whole set of leads *** - lead2_clusters = [c for c in lead_clusters - if c.is_potential_lead2(lead_clusters)] - lead2_clusters.sort(key=lambda x: x.dRel) - lead2_len = len(lead2_clusters) - - # *** publish radarState *** - dat = messaging.new_message() - dat.init('radarState') - dat.valid = sm.all_alive_and_valid(service_list=['controlsState']) - dat.radarState.mdMonoTime = last_md_ts - dat.radarState.canMonoTimes = list(rr.canMonoTimes) - dat.radarState.radarErrors = list(rr.errors) - dat.radarState.controlsStateMonoTime = last_controls_state_ts - if lead_len > 0: - dat.radarState.leadOne = lead_clusters[0].toRadarState() - if lead2_len > 0: - dat.radarState.leadTwo = lead2_clusters[0].toRadarState() - else: - dat.radarState.leadTwo.status = False - else: - dat.radarState.leadOne.status = False - + dat = RD.update(rk.frame, RI.delay, sm, rr) dat.radarState.cumLagMs = -rk.remaining*1000. + radarState.send(dat.to_bytes()) # *** publish tracks for UI debugging (keep last) *** + tracks = RD.tracks dat = messaging.new_message() dat.init('liveTracks', len(tracks)) diff --git a/selfdrive/locationd/.gitignore b/selfdrive/locationd/.gitignore index 8cdb0d230..6ea757462 100644 --- a/selfdrive/locationd/.gitignore +++ b/selfdrive/locationd/.gitignore @@ -1,3 +1,4 @@ ubloxd ubloxd_test -params_learner \ No newline at end of file +params_learner +paramsd \ No newline at end of file diff --git a/selfdrive/locationd/Makefile b/selfdrive/locationd/Makefile index f7652648e..ff4684768 100644 --- a/selfdrive/locationd/Makefile +++ b/selfdrive/locationd/Makefile @@ -40,11 +40,11 @@ EXTRA_LIBS += -llog -luuid endif .PHONY: all -all: ubloxd params_learner +all: ubloxd paramsd include ../common/cereal.mk -LOC_OBJS = locationd_yawrate.o params_learner.o \ +LOC_OBJS = locationd_yawrate.o params_learner.o paramsd.o \ ../common/swaglog.o \ ../common/params.o \ ../common/util.o \ @@ -71,7 +71,7 @@ liblocationd.so: $(LOC_OBJS) $(ZMQ_SHARED_LIBS) \ $(EXTRA_LIBS) -params_learner: $(LOC_OBJS) +paramsd: $(LOC_OBJS) @echo "[ LINK ] $@" $(CXX) -fPIC -o '$@' $^ \ $(CEREAL_LIBS) \ @@ -115,7 +115,7 @@ ubloxd_test: ubloxd_test.o $(OBJS) .PHONY: clean clean: - rm -f ubloxd params_learner liblocationd.so ubloxd.d ubloxd.o ubloxd_test ubloxd_test.o ubloxd_test.d $(OBJS) $(LOC_OBJS) $(DEPS) + rm -f ubloxd paramsd liblocationd.so ubloxd.d ubloxd.o ubloxd_test ubloxd_test.o ubloxd_test.d $(OBJS) $(LOC_OBJS) $(DEPS) -include $(DEPS) -include $(LOC_DEPS) diff --git a/selfdrive/locationd/locationd_yawrate.cc b/selfdrive/locationd/locationd_yawrate.cc index f03f808ff..ae4b05a71 100644 --- a/selfdrive/locationd/locationd_yawrate.cc +++ b/selfdrive/locationd/locationd_yawrate.cc @@ -1,287 +1,96 @@ #include -#include #include -#include #include #include #include -#include "json11.hpp" -#include "cereal/gen/cpp/log.capnp.h" -#include "common/swaglog.h" -#include "common/messaging.h" -#include "common/params.h" -#include "common/timing.h" -#include "params_learner.h" +#include "locationd_yawrate.h" -const int num_polls = 3; -class Localizer -{ - Eigen::Matrix2d A; - Eigen::Matrix2d I; - Eigen::Matrix2d Q; - Eigen::Matrix2d P; - Eigen::Matrix C_posenet; - Eigen::Matrix C_gyro; +void Localizer::update_state(const Eigen::Matrix &C, const double R, double current_time, double meas) { + double dt = current_time - prev_update_time; + prev_update_time = current_time; + if (dt < 1.0e-9) { + return; + } - double R_gyro; + // x = A * x; + // P = A * P * A.transpose() + dt * Q; + // Simplify because A is unity + P = P + dt * Q; - void update_state(const Eigen::Matrix &C, const double R, double current_time, double meas) { - double dt = current_time - prev_update_time; + double y = meas - C * x; + double S = R + C * P * C.transpose(); + Eigen::Vector2d K = P * C.transpose() * (1.0 / S); + x = x + K * y; + P = (I - K * C) * P; +} + +void Localizer::handle_sensor_events(capnp::List::Reader sensor_events, double current_time) { + for (cereal::SensorEventData::Reader sensor_event : sensor_events){ + if (sensor_event.getType() == 4) { + sensor_data_time = current_time; + + double meas = -sensor_event.getGyro().getV()[0]; + update_state(C_gyro, R_gyro, current_time, meas); + } + } +} + +void Localizer::handle_camera_odometry(cereal::CameraOdometry::Reader camera_odometry, double current_time) { + double R = 250.0 * pow(camera_odometry.getRotStd()[2], 2); + double meas = camera_odometry.getRot()[2]; + update_state(C_posenet, R, current_time, meas); +} + +void Localizer::handle_controls_state(cereal::ControlsState::Reader controls_state, double current_time) { + steering_angle = controls_state.getAngleSteers() * DEGREES_TO_RADIANS; + car_speed = controls_state.getVEgo(); + controls_state_time = current_time; +} + + +Localizer::Localizer() { + A << 1, 0, 0, 1; + I << 1, 0, 0, 1; + + Q << pow(0.1, 2.0), 0, 0, pow(0.005 / 100.0, 2.0); + P << pow(1.0, 2.0), 0, 0, pow(0.05, 2.0); + + C_posenet << 1, 0; + C_gyro << 1, 1; + x << 0, 0; + + R_gyro = pow(0.05, 2.0); +} + +cereal::Event::Which Localizer::handle_log(const unsigned char* msg_dat, size_t msg_size) { + const kj::ArrayPtr view((const capnp::word*)msg_dat, msg_size); + capnp::FlatArrayMessageReader msg(view); + cereal::Event::Reader event = msg.getRoot(); + double current_time = event.getLogMonoTime() / 1.0e9; + + if (prev_update_time < 0) { prev_update_time = current_time; - if (dt < 1.0e-9) { - return; - } - - // x = A * x; - // P = A * P * A.transpose() + dt * Q; - // Simplify because A is unity - P = P + dt * Q; - - double y = meas - C * x; - double S = R + C * P * C.transpose(); - Eigen::Vector2d K = P * C.transpose() * (1.0 / S); - x = x + K * y; - P = (I - K * C) * P; } - void handle_sensor_events(capnp::List::Reader sensor_events, double current_time) { - for (cereal::SensorEventData::Reader sensor_event : sensor_events){ - if (sensor_event.getType() == 4) { - sensor_data_time = current_time; - - double meas = -sensor_event.getGyro().getV()[0]; - update_state(C_gyro, R_gyro, current_time, meas); - } - } - + auto type = event.which(); + switch(type) { + case cereal::Event::CONTROLS_STATE: + handle_controls_state(event.getControlsState(), current_time); + break; + case cereal::Event::CAMERA_ODOMETRY: + handle_camera_odometry(event.getCameraOdometry(), current_time); + break; + case cereal::Event::SENSOR_EVENTS: + handle_sensor_events(event.getSensorEvents(), current_time); + break; + default: + break; } - void handle_camera_odometry(cereal::CameraOdometry::Reader camera_odometry, double current_time) { - double R = 250.0 * pow(camera_odometry.getRotStd()[2], 2); - double meas = camera_odometry.getRot()[2]; - update_state(C_posenet, R, current_time, meas); - } - - void handle_controls_state(cereal::ControlsState::Reader controls_state, double current_time) { - steering_angle = controls_state.getAngleSteers() * DEGREES_TO_RADIANS; - car_speed = controls_state.getVEgo(); - controls_state_time = current_time; - } - - -public: - Eigen::Vector2d x; - double steering_angle = 0; - double car_speed = 0; - double prev_update_time = -1; - double controls_state_time = -1; - double sensor_data_time = -1; - - Localizer() { - A << 1, 0, 0, 1; - I << 1, 0, 0, 1; - - Q << pow(0.1, 2.0), 0, 0, pow(0.005 / 100.0, 2.0); - P << pow(1.0, 2.0), 0, 0, pow(0.05, 2.0); - - C_posenet << 1, 0; - C_gyro << 1, 1; - x << 0, 0; - - R_gyro = pow(0.05, 2.0); - } - - cereal::Event::Which handle_log(const unsigned char* msg_dat, size_t msg_size) { - const kj::ArrayPtr view((const capnp::word*)msg_dat, msg_size); - capnp::FlatArrayMessageReader msg(view); - cereal::Event::Reader event = msg.getRoot(); - double current_time = event.getLogMonoTime() / 1.0e9; - - if (prev_update_time < 0) { - prev_update_time = current_time; - } - - auto type = event.which(); - switch(type) { - case cereal::Event::CONTROLS_STATE: - handle_controls_state(event.getControlsState(), current_time); - break; - case cereal::Event::CAMERA_ODOMETRY: - handle_camera_odometry(event.getCameraOdometry(), current_time); - break; - case cereal::Event::SENSOR_EVENTS: - handle_sensor_events(event.getSensorEvents(), current_time); - break; - default: - break; - } - - return type; - } -}; - - - -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"); - - auto live_parameters_sock = zsock_new_pub("@tcp://*:8064"); - assert(live_parameters_sock); - auto live_parameters_sock_raw = zsock_resolve(live_parameters_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 = sensor_events_sock; - polls[1].events = ZMQ_POLLIN; - polls[2].socket = camera_odometry_sock; - polls[2].events = ZMQ_POLLIN; - - // Read car params - char *value; - size_t value_sz = 0; - - LOGW("waiting for params to set vehicle model"); - while (true) { - read_db_value(NULL, "CarParams", &value, &value_sz); - if (value_sz > 0) break; - usleep(100*1000); - } - LOGW("got %d bytes CarParams", value_sz); - - // make copy due to alignment issues - auto amsg = kj::heapArray((value_sz / sizeof(capnp::word)) + 1); - memcpy(amsg.begin(), value, value_sz); - free(value); - - capnp::FlatArrayMessageReader cmsg(amsg); - cereal::CarParams::Reader car_params = cmsg.getRoot(); - - // Read params from previous run - const int result = read_db_value(NULL, "LiveParameters", &value, &value_sz); - - std::string fingerprint = car_params.getCarFingerprint(); - std::string vin = car_params.getCarVin(); - double sR = car_params.getSteerRatio(); - double x = 1.0; - double ao = 0.0; - - if (result == 0){ - auto str = std::string(value, value_sz); - free(value); - - std::string err; - auto json = json11::Json::parse(str, err); - if (json.is_null() || !err.empty()) { - std::string log = "Error parsing json: " + err; - LOGW(log.c_str()); - } else { - std::string new_fingerprint = json["carFingerprint"].string_value(); - std::string new_vin = json["carVin"].string_value(); - - if (fingerprint == new_fingerprint && vin == new_vin) { - std::string log = "Parameter starting with: " + str; - LOGW(log.c_str()); - - sR = json["steerRatio"].number_value(); - x = json["stiffnessFactor"].number_value(); - ao = json["angleOffsetAverage"].number_value(); - } - } - } - - ParamsLearner learner(car_params, ao, x, sR, 1.0); - - // Main loop - int save_counter = 0; - while (true){ - int ret = zmq_poll(polls, num_polls, 100); - - if (ret == 0){ - continue; - } else if (ret < 0){ - break; - } - - 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)); - - auto which = localizer.handle_log((const unsigned char*)amsg.begin(), amsg.size()); - zmq_msg_close(&msg); - - 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 angle_offset_degrees = RADIANS_TO_DEGREES * learner.ao; - double angle_offset_average_degrees = RADIANS_TO_DEGREES * learner.slow_ao; - - // Send parameters at 10 Hz - if (save_counter % 10 == 0){ - 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[1]); - 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); - - 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(); - write_db_value(NULL, "LiveParameters", out.c_str(), out.length()); - } - } - } - } - } - - zmq_close(controls_state_sock); - zmq_close(sensor_events_sock); - zmq_close(camera_odometry_sock); - zmq_close(live_parameters_sock_raw); - return 0; + return type; } diff --git a/selfdrive/locationd/locationd_yawrate.h b/selfdrive/locationd/locationd_yawrate.h new file mode 100644 index 000000000..323e87de4 --- /dev/null +++ b/selfdrive/locationd/locationd_yawrate.h @@ -0,0 +1,34 @@ +#pragma once + +#include +#include "cereal/gen/cpp/log.capnp.h" + +#define DEGREES_TO_RADIANS 0.017453292519943295 + +class Localizer +{ + Eigen::Matrix2d A; + Eigen::Matrix2d I; + Eigen::Matrix2d Q; + Eigen::Matrix2d P; + Eigen::Matrix C_posenet; + Eigen::Matrix C_gyro; + + double R_gyro; + + void update_state(const Eigen::Matrix &C, const double R, double current_time, double meas); + void handle_sensor_events(capnp::List::Reader sensor_events, double current_time); + void handle_camera_odometry(cereal::CameraOdometry::Reader camera_odometry, double current_time); + void handle_controls_state(cereal::ControlsState::Reader controls_state, double current_time); + +public: + Eigen::Vector2d x; + double steering_angle = 0; + double car_speed = 0; + double prev_update_time = -1; + double controls_state_time = -1; + double sensor_data_time = -1; + + Localizer(); + cereal::Event::Which handle_log(const unsigned char* msg_dat, size_t msg_size); +}; diff --git a/selfdrive/locationd/params_learner.cc b/selfdrive/locationd/params_learner.cc index a150805d8..912abde35 100644 --- a/selfdrive/locationd/params_learner.cc +++ b/selfdrive/locationd/params_learner.cc @@ -2,6 +2,8 @@ #include #include +#include +#include #include "cereal/gen/cpp/log.capnp.h" #include "cereal/gen/cpp/car.capnp.h" #include "params_learner.h" @@ -14,14 +16,15 @@ T clip(const T& n, const T& lower, const T& upper) { } ParamsLearner::ParamsLearner(cereal::CarParams::Reader car_params, - double angle_offset, - double stiffness_factor, - double steer_ratio, - double learning_rate) : - ao(angle_offset * DEGREES_TO_RADIANS), - slow_ao(angle_offset * DEGREES_TO_RADIANS), - x(stiffness_factor), - sR(steer_ratio) { + double angle_offset, + double stiffness_factor, + double steer_ratio, + double learning_rate) : + ao(angle_offset * DEGREES_TO_RADIANS), + slow_ao(angle_offset * DEGREES_TO_RADIANS), + x(stiffness_factor), + sR(steer_ratio) { + cF0 = car_params.getTireStiffnessFront(); cR0 = car_params.getTireStiffnessRear(); @@ -73,3 +76,43 @@ bool ParamsLearner::update(double psi, double u, double sa) { valid = valid && sR < max_sr_th; return valid; } + + +extern "C" { + void *params_learner_init(size_t len, char * params, double angle_offset, double stiffness_factor, double steer_ratio, double learning_rate) { + + auto amsg = kj::heapArray((len / sizeof(capnp::word)) + 1); + memcpy(amsg.begin(), params, len); + + capnp::FlatArrayMessageReader cmsg(amsg); + cereal::CarParams::Reader car_params = cmsg.getRoot(); + + ParamsLearner * p = new ParamsLearner(car_params, angle_offset, stiffness_factor, steer_ratio, learning_rate); + return (void*)p; + } + + bool params_learner_update(void * params_learner, double psi, double u, double sa) { + ParamsLearner * p = (ParamsLearner*) params_learner; + return p->update(psi, u, sa); + } + + double params_learner_get_ao(void * params_learner){ + ParamsLearner * p = (ParamsLearner*) params_learner; + return p->ao; + } + + double params_learner_get_x(void * params_learner){ + ParamsLearner * p = (ParamsLearner*) params_learner; + return p->x; + } + + double params_learner_get_slow_ao(void * params_learner){ + ParamsLearner * p = (ParamsLearner*) params_learner; + return p->slow_ao; + } + + double params_learner_get_sR(void * params_learner){ + ParamsLearner * p = (ParamsLearner*) params_learner; + return p->sR; + } +} diff --git a/selfdrive/locationd/paramsd.cc b/selfdrive/locationd/paramsd.cc new file mode 100644 index 000000000..9fc3ad625 --- /dev/null +++ b/selfdrive/locationd/paramsd.cc @@ -0,0 +1,174 @@ +#include +#include +#include + +#include "locationd_yawrate.h" +#include "cereal/gen/cpp/log.capnp.h" + +#include "common/swaglog.h" +#include "common/messaging.h" +#include "common/params.h" +#include "common/timing.h" +#include "params_learner.h" +#include "json11.hpp" + +const int num_polls = 3; + +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"); + + auto live_parameters_sock = zsock_new_pub("@tcp://*:8064"); + assert(live_parameters_sock); + auto live_parameters_sock_raw = zsock_resolve(live_parameters_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 = sensor_events_sock; + polls[1].events = ZMQ_POLLIN; + polls[2].socket = camera_odometry_sock; + polls[2].events = ZMQ_POLLIN; + + // Read car params + char *value; + size_t value_sz = 0; + + LOGW("waiting for params to set vehicle model"); + while (true) { + read_db_value(NULL, "CarParams", &value, &value_sz); + if (value_sz > 0) break; + usleep(100*1000); + } + LOGW("got %d bytes CarParams", value_sz); + + // make copy due to alignment issues + auto amsg = kj::heapArray((value_sz / sizeof(capnp::word)) + 1); + memcpy(amsg.begin(), value, value_sz); + free(value); + + capnp::FlatArrayMessageReader cmsg(amsg); + cereal::CarParams::Reader car_params = cmsg.getRoot(); + + // Read params from previous run + const int result = read_db_value(NULL, "LiveParameters", &value, &value_sz); + + std::string fingerprint = car_params.getCarFingerprint(); + std::string vin = car_params.getCarVin(); + double sR = car_params.getSteerRatio(); + double x = 1.0; + double ao = 0.0; + + if (result == 0){ + auto str = std::string(value, value_sz); + free(value); + + std::string err; + auto json = json11::Json::parse(str, err); + if (json.is_null() || !err.empty()) { + std::string log = "Error parsing json: " + err; + LOGW(log.c_str()); + } else { + std::string new_fingerprint = json["carFingerprint"].string_value(); + std::string new_vin = json["carVin"].string_value(); + + if (fingerprint == new_fingerprint && vin == new_vin) { + std::string log = "Parameter starting with: " + str; + LOGW(log.c_str()); + + sR = json["steerRatio"].number_value(); + x = json["stiffnessFactor"].number_value(); + ao = json["angleOffsetAverage"].number_value(); + } + } + } + + ParamsLearner learner(car_params, ao, x, sR, 1.0); + + // Main loop + int save_counter = 0; + while (true){ + int ret = zmq_poll(polls, num_polls, 100); + + if (ret == 0){ + continue; + } else if (ret < 0){ + break; + } + + 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)); + + auto which = localizer.handle_log((const unsigned char*)amsg.begin(), amsg.size()); + zmq_msg_close(&msg); + + 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 angle_offset_degrees = RADIANS_TO_DEGREES * learner.ao; + double angle_offset_average_degrees = RADIANS_TO_DEGREES * learner.slow_ao; + + // Send parameters at 10 Hz + if (save_counter % 10 == 0){ + 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[1]); + 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); + + 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(); + write_db_value(NULL, "LiveParameters", out.c_str(), out.length()); + } + } + } + } + } + + zmq_close(controls_state_sock); + zmq_close(sensor_events_sock); + zmq_close(camera_odometry_sock); + zmq_close(live_parameters_sock_raw); + return 0; +} diff --git a/selfdrive/locationd/test/test_params_learner.py b/selfdrive/locationd/test/test_params_learner.py new file mode 100755 index 000000000..e2a6913c0 --- /dev/null +++ b/selfdrive/locationd/test/test_params_learner.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python + +import numpy as np +import unittest + +from selfdrive.car.honda.interface import CarInterface +from selfdrive.car.honda.values import CAR +from selfdrive.controls.lib.vehicle_model import VehicleModel +from selfdrive.locationd.liblocationd_py import liblocationd # pylint: disable=no-name-in-module, import-error + + +class TestParamsLearner(unittest.TestCase): + def setUp(self): + + self.CP = CarInterface.get_params(CAR.CIVIC, {}) + bts = self.CP.to_bytes() + + self.params_learner = liblocationd.params_learner_init(len(bts), bts, 0.0, 1.0, self.CP.steerRatio, 1.0) + + def test_convergence(self): + # Setup vehicle model with wrong parameters + VM_sim = VehicleModel(self.CP) + x_target = 0.75 + sr_target = 14 + ao_target = -1.0 + VM_sim.update_params(x_target, sr_target) + + # Run simulation + times = np.arange(0, 10*3600, 0.01) + angle_offset = np.radians(ao_target) + steering_angles = np.radians(10 * np.sin(2 * np.pi * times / 100.)) + angle_offset + speeds = 10 * np.sin(2 * np.pi * times / 1000.) + 25 + + for i, t in enumerate(times): + u = speeds[i] + sa = steering_angles[i] + psi = VM_sim.yaw_rate(sa - angle_offset, u) + liblocationd.params_learner_update(self.params_learner, psi, u, sa) + + # Verify learned parameters + sr = liblocationd.params_learner_get_sR(self.params_learner) + ao_slow = np.degrees(liblocationd.params_learner_get_slow_ao(self.params_learner)) + x = liblocationd.params_learner_get_x(self.params_learner) + self.assertAlmostEqual(x_target, x, places=1) + self.assertAlmostEqual(ao_target, ao_slow, places=1) + self.assertAlmostEqual(sr_target, sr, places=1) + + + + + +if __name__ == "__main__": + unittest.main() diff --git a/selfdrive/loggerd/uploader.py b/selfdrive/loggerd/uploader.py index 7cad71bf7..0bd2ff18f 100644 --- a/selfdrive/loggerd/uploader.py +++ b/selfdrive/loggerd/uploader.py @@ -168,7 +168,7 @@ class Uploader(object): def do_upload(self, key, fn): try: - url_resp = api_get("v1.2/"+self.dongle_id+"/upload_url/", timeout=2, path=key, access_token=self.access_token) + url_resp = api_get("v1.2/"+self.dongle_id+"/upload_url/", timeout=10, path=key, access_token=self.access_token) url_resp_json = json.loads(url_resp.text) url = url_resp_json['url'] headers = url_resp_json['headers'] @@ -223,7 +223,7 @@ class Uploader(object): try: os.unlink(fn) except OSError: - cloudlog.exception("delete_failed", stat=stat, exc=self.last_exc, key=key, fn=fn, sz=sz) + cloudlog.event("delete_failed", stat=stat, exc=self.last_exc, key=key, fn=fn, sz=sz) success = True else: diff --git a/selfdrive/manager.py b/selfdrive/manager.py index c3be2c094..4e52f2beb 100755 --- a/selfdrive/manager.py +++ b/selfdrive/manager.py @@ -72,12 +72,15 @@ import glob import shutil import hashlib import importlib +import re +import stat import subprocess import traceback from multiprocessing import Process from setproctitle import setproctitle #pylint: disable=no-name-in-module +from common.file_helpers import atomic_write_in_dir_neos from common.params import Params import cereal ThermalStatus = cereal.log.ThermalData.ThermalStatus @@ -109,12 +112,14 @@ managed_processes = { "pandad": "selfdrive.pandad", "ui": ("selfdrive/ui", ["./start.py"]), "calibrationd": "selfdrive.locationd.calibrationd", - "params_learner": ("selfdrive/locationd", ["./params_learner"]), + "paramsd": ("selfdrive/locationd", ["./paramsd"]), "visiond": ("selfdrive/visiond", ["./visiond"]), "sensord": ("selfdrive/sensord", ["./start_sensord.py"]), "gpsd": ("selfdrive/sensord", ["./start_gpsd.py"]), "updated": "selfdrive.updated", - "athena": "selfdrive.athena.athenad", +} +daemon_processes = { + "athenad": "selfdrive.athena.athenad", } android_packages = ("ai.comma.plus.offroad", "ai.comma.plus.frame") @@ -136,7 +141,6 @@ persistent_processes = [ 'uploader', 'ui', 'updated', - 'athena', ] car_started_processes = [ @@ -146,7 +150,7 @@ car_started_processes = [ 'sensord', 'radard', 'calibrationd', - 'params_learner', + 'paramsd', 'visiond', 'proclogd', 'ubloxd', @@ -209,6 +213,29 @@ def start_managed_process(name): running[name] = Process(name=name, target=nativelauncher, args=(pargs, cwd)) running[name].start() +def start_daemon_process(name, params): + proc = daemon_processes[name] + pid_param = name.capitalize() + 'Pid' + pid = params.get(pid_param) + + if pid is not None: + try: + os.kill(int(pid), 0) + # process is running (kill is a poorly-named system call) + return + except OSError: + # process is dead + pass + + cloudlog.info("starting daemon %s" % name) + proc = subprocess.Popen(['python', '-m', proc], + cwd='/', + stdout=open('/dev/null', 'w'), + stderr=open('/dev/null', 'w'), + preexec_fn=os.setpgrp) + + params.put(pid_param, str(proc.pid)) + def prepare_managed_process(p): proc = managed_processes[p] if isinstance(proc, str): @@ -321,6 +348,12 @@ def manager_thread(): # save boot log subprocess.call(["./loggerd", "--bootlog"], cwd=os.path.join(BASEDIR, "selfdrive/loggerd")) + params = Params() + + # start daemon processes + for p in daemon_processes: + start_daemon_process(p, params) + # start persistent processes for p in persistent_processes: start_managed_process(p) @@ -332,7 +365,6 @@ def manager_thread(): if os.getenv("NOBOARD") is None: start_managed_process("pandad") - params = Params() logger_dead = False while 1: @@ -420,10 +452,46 @@ def update_apks(): assert success +def update_ssh(): + ssh_home_dirpath = "/system/comma/home/.ssh/" + auth_keys_path = os.path.join(ssh_home_dirpath, "authorized_keys") + auth_keys_persist_path = os.path.join(ssh_home_dirpath, "authorized_keys.persist") + auth_keys_mode = stat.S_IREAD | stat.S_IWRITE + + params = Params() + github_keys = params.get("GithubSshKeys") or '' + + old_keys = open(auth_keys_path).read() + has_persisted_keys = os.path.exists(auth_keys_persist_path) + if has_persisted_keys: + persisted_keys = open(auth_keys_persist_path).read() + else: + # add host filter + persisted_keys = re.sub(r'^(?!.+?from.+? )(ssh|ecdsa)', 'from="10.0.0.0/8,172.16.0.0/12,192.168.0.0/16" \\1', old_keys, flags=re.MULTILINE) + + new_keys = persisted_keys + '\n' + github_keys + + if has_persisted_keys and new_keys == old_keys and os.stat(auth_keys_path)[stat.ST_MODE] == auth_keys_mode: + # nothing to do - let's avoid remount + return + + try: + subprocess.check_call(["mount", "-o", "rw,remount", "/system"]) + if not has_persisted_keys: + atomic_write_in_dir_neos(auth_keys_persist_path, persisted_keys, mode=auth_keys_mode) + + atomic_write_in_dir_neos(auth_keys_path, new_keys, mode=auth_keys_mode) + finally: + try: + subprocess.check_call(["mount", "-o", "ro,remount", "/system"]) + except: + cloudlog.exception("Failed to remount as read-only") + # this can fail due to "Device busy" - reboot if so + os.system("reboot") + raise RuntimeError + def manager_update(): - if os.path.exists(os.path.join(BASEDIR, "vpn")): - cloudlog.info("installing vpn") - os.system(os.path.join(BASEDIR, "vpn", "install.sh")) + update_ssh() update_apks() def manager_prepare(): diff --git a/selfdrive/messaging.py b/selfdrive/messaging.py index 4e78f66c8..cad7e2e8b 100644 --- a/selfdrive/messaging.py +++ b/selfdrive/messaging.py @@ -16,17 +16,34 @@ def pub_sock(port, addr="*"): sock.bind("tcp://%s:%d" % (addr, port)) return sock -def sub_sock(port, poller=None, addr="127.0.0.1", conflate=False): +def sub_sock(port, poller=None, addr="127.0.0.1", conflate=False, timeout=None): context = zmq.Context.instance() sock = context.socket(zmq.SUB) if conflate: sock.setsockopt(zmq.CONFLATE, 1) sock.connect("tcp://%s:%d" % (addr, port)) sock.setsockopt(zmq.SUBSCRIBE, b"") + + if timeout is not None: + sock.RCVTIMEO = timeout + if poller is not None: poller.register(sock, zmq.POLLIN) return sock +def drain_sock_raw(sock, wait_for_one=False): + ret = [] + while 1: + try: + if wait_for_one and len(ret) == 0: + dat = sock.recv() + else: + dat = sock.recv(zmq.NOBLOCK) + ret.append(dat) + except zmq.error.Again: + break + return ret + def drain_sock(sock, wait_for_one=False): ret = [] while 1: @@ -82,24 +99,29 @@ class SubMaster(): self.valid = {} for s in services: # TODO: get address automatically from service_list - self.sock[s] = sub_sock(service_list[s].port, poller=self.poller, addr=addr, conflate=True) + if addr is not None: + self.sock[s] = sub_sock(service_list[s].port, poller=self.poller, addr=addr, conflate=True) self.freq[s] = service_list[s].frequency data = new_message() data.init(s) self.data[s] = getattr(data, s) - self.logMonoTime[s] = data.logMonoTime + 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) - cur_time = sec_since_boot() - for sock, _ in self.poller.poll(timeout): - msg = recv_one(sock) + for msg in msgs: s = msg.which() self.updated[s] = True self.rcv_time[s] = cur_time diff --git a/selfdrive/registration.py b/selfdrive/registration.py index 9f6899849..f8a084bd3 100644 --- a/selfdrive/registration.py +++ b/selfdrive/registration.py @@ -5,7 +5,7 @@ import struct from datetime import datetime, timedelta from selfdrive.swaglog import cloudlog -from selfdrive.version import version, training_version, get_git_commit, get_git_branch, get_git_remote +from selfdrive.version import version, terms_version, training_version, get_git_commit, get_git_branch, get_git_remote from common.api import api_get from common.params import Params from common.file_helpers import mkdirs_exists_ok @@ -53,6 +53,7 @@ def get_subscriber_info(): def register(): params = Params() params.put("Version", version) + params.put("TermsVersion", terms_version) params.put("TrainingVersion", training_version) params.put("GitCommit", get_git_commit()) params.put("GitBranch", get_git_branch()) diff --git a/selfdrive/test/plant/plant.py b/selfdrive/test/plant/plant.py index e39bafd79..930f83be8 100755 --- a/selfdrive/test/plant/plant.py +++ b/selfdrive/test/plant/plant.py @@ -244,6 +244,7 @@ class Plant(object): 'EPB_STATE', 'BRAKE_HOLD_ACTIVE', 'INTERCEPTOR_GAS', + 'INTERCEPTOR_GAS2', 'IMPERIAL_UNIT', ]) vls = vls_tuple( @@ -276,6 +277,7 @@ class Plant(object): 0, # EPB State 0, # Brake hold 0, # Interceptor feedback + 0, # Interceptor 2 feedback False ) diff --git a/selfdrive/thermald.py b/selfdrive/thermald.py index ef75cfffd..9a29b96fe 100755 --- a/selfdrive/thermald.py +++ b/selfdrive/thermald.py @@ -2,7 +2,7 @@ import os from smbus2 import SMBus from cereal import log -from selfdrive.version import training_version +from selfdrive.version import terms_version, training_version from selfdrive.swaglog import cloudlog import selfdrive.messaging as messaging from selfdrive.services import service_list @@ -216,7 +216,7 @@ def thermald_thread(): ignition = True do_uninstall = params.get("DoUninstall") == "1" - accepted_terms = params.get("HasAcceptedTerms") == "1" + accepted_terms = params.get("HasAcceptedTerms") == terms_version completed_training = params.get("CompletedTrainingVersion") == training_version should_start = ignition diff --git a/selfdrive/version.py b/selfdrive/version.py index 4acc18350..2eb39dc97 100644 --- a/selfdrive/version.py +++ b/selfdrive/version.py @@ -59,6 +59,7 @@ except subprocess.CalledProcessError: dirty = True training_version = "0.1.0" +terms_version = "2" if __name__ == "__main__": print("Dirty: %s" % dirty) diff --git a/selfdrive/visiond/models/driving.cc b/selfdrive/visiond/models/driving.cc index bf5933f42..28876c81b 100644 --- a/selfdrive/visiond/models/driving.cc +++ b/selfdrive/visiond/models/driving.cc @@ -135,7 +135,14 @@ void poly_fit(float *in_pts, float *in_stds, float *out) { 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(); + lhs = lhs * scale.asDiagonal(); + // Solve inplace Eigen::ColPivHouseholderQR > qr(lhs); p = qr.solve(rhs); + + // Apply scale to output + p = p.transpose() * scale.asDiagonal(); }