Skip to content

Commit

Permalink
extra_configs!
Browse files Browse the repository at this point in the history
  • Loading branch information
maxime-desroches committed Sep 28, 2024
1 parent a8561f1 commit 4e5ca9d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 67 deletions.
6 changes: 5 additions & 1 deletion SConscript
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import os
import subprocess

EXTRA_SAFETY_CONFIGS = os.environ.get("EXTRA_SAFETY_CONFIGS", "")
def extra_safety_configs(): return EXTRA_SAFETY_CONFIGS
Export('extra_safety_configs')

PREFIX = "arm-none-eabi-"
BUILDER = "DEV"

common_flags = []
common_flags = ["-DEXTRA_SAFETY_CONFIGS" if extra_safety_configs() else ""]

panda_root = Dir('.')

Expand Down Expand Up @@ -84,6 +87,7 @@ def build_project(project_name, project, extra_flags):
'..',
panda_root,
f"{panda_root}/board/",
extra_safety_configs(),
]

env = Environment(
Expand Down
69 changes: 5 additions & 64 deletions board/safety.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,55 +6,16 @@
// include the safety policies.
#include "safety/safety_defaults.h"
#include "safety/safety_elm327.h"
#ifdef SAFETY_IMPLEMENTATIONS
#include "safety/safety_honda.h"
#include "safety/safety_toyota.h"
#include "safety/safety_tesla.h"
#include "safety/safety_gm.h"
#include "safety/safety_ford.h"
#include "safety/safety_hyundai.h"
#include "safety/safety_chrysler.h"
#include "safety/safety_subaru.h"
#include "safety/safety_subaru_preglobal.h"
#include "safety/safety_mazda.h"
#include "safety/safety_nissan.h"
#include "safety/safety_volkswagen_mqb.h"
#include "safety/safety_volkswagen_pq.h"
#include "safety/safety_body.h"

// CAN-FD only safety modes
#ifdef CANFD
#include "safety/safety_hyundai_canfd.h"
#endif
#ifdef EXTRA_SAFETY_CONFIGS
#include "extra_safety_configs.h"
#endif

// from cereal.car.CarParams.SafetyModel
// defaults safety modes
#define SAFETY_SILENT 0U
#define SAFETY_HONDA_NIDEC 1U
#define SAFETY_TOYOTA 2U
#define SAFETY_ELM327 3U
#define SAFETY_GM 4U
#define SAFETY_HONDA_BOSCH_GIRAFFE 5U
#define SAFETY_FORD 6U
#define SAFETY_HYUNDAI 8U
#define SAFETY_CHRYSLER 9U
#define SAFETY_TESLA 10U
#define SAFETY_SUBARU 11U
#define SAFETY_MAZDA 13U
#define SAFETY_NISSAN 14U
#define SAFETY_VOLKSWAGEN_MQB 15U
#define SAFETY_ALLOUTPUT 17U
#define SAFETY_GM_ASCM 18U
#define SAFETY_NOOUTPUT 19U
#define SAFETY_HONDA_BOSCH 20U
#define SAFETY_VOLKSWAGEN_PQ 21U
#define SAFETY_SUBARU_PREGLOBAL 22U
#define SAFETY_HYUNDAI_LEGACY 23U
#define SAFETY_HYUNDAI_COMMUNITY 24U
#define SAFETY_STELLANTIS 25U
#define SAFETY_FAW 26U
#define SAFETY_BODY 27U
#define SAFETY_HYUNDAI_CANFD 28U

const int MAX_WRONG_COUNTERS = 5;

Expand Down Expand Up @@ -294,28 +255,8 @@ int set_safety_hooks(uint16_t mode, uint16_t param) {
#ifdef ALLOW_DEBUG
{SAFETY_ALLOUTPUT, &alloutput_hooks},
#endif
#ifdef SAFETY_IMPLEMENTATIONS
{SAFETY_HONDA_NIDEC, &honda_nidec_hooks},
{SAFETY_TOYOTA, &toyota_hooks},
{SAFETY_GM, &gm_hooks},
{SAFETY_HONDA_BOSCH, &honda_bosch_hooks},
{SAFETY_HYUNDAI, &hyundai_hooks},
{SAFETY_CHRYSLER, &chrysler_hooks},
{SAFETY_SUBARU, &subaru_hooks},
{SAFETY_VOLKSWAGEN_MQB, &volkswagen_mqb_hooks},
{SAFETY_NISSAN, &nissan_hooks},
{SAFETY_HYUNDAI_LEGACY, &hyundai_legacy_hooks},
{SAFETY_MAZDA, &mazda_hooks},
{SAFETY_BODY, &body_hooks},
{SAFETY_FORD, &ford_hooks},
#ifdef CANFD
{SAFETY_HYUNDAI_CANFD, &hyundai_canfd_hooks},
#endif
#ifdef ALLOW_DEBUG
{SAFETY_TESLA, &tesla_hooks},
{SAFETY_SUBARU_PREGLOBAL, &subaru_preglobal_hooks},
{SAFETY_VOLKSWAGEN_PQ, &volkswagen_pq_hooks},
#endif
#ifdef EXTRA_SAFETY_CONFIGS
GET_EXTRA_SAFETY_HOOKS
#endif
};

Expand Down
5 changes: 4 additions & 1 deletion tests/libpanda/SConscript
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import platform

Import('extra_safety_configs')

CC = 'gcc'
system = platform.system()
if system == 'Darwin':
Expand All @@ -15,8 +17,9 @@ env = Environment(
'-std=gnu11',
'-Wfatal-errors',
'-Wno-pointer-to-int-cast',
'-DEXTRA_SAFETY_CONFIGS' if extra_safety_configs() else '',
],
CPPPATH=[".", "../../board/"],
CPPPATH=[".", "../../board/", extra_safety_configs()],
)
if system == "Darwin":
env.PrependENVPath('PATH', '/opt/homebrew/bin')
Expand Down
2 changes: 1 addition & 1 deletion tests/libpanda/safety_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ int get_angle_meas_max(void){

// ***** car specific helpers *****

#ifdef SAFETY_IMPLEMENTATIONS
#ifdef EXTRA_SAFEY_CONFIGS
void set_honda_alt_brake_msg(bool c){
honda_alt_brake_msg = c;
}
Expand Down

0 comments on commit 4e5ca9d

Please sign in to comment.