From b5ecf4c1b3fe8bf97736b4ba9a5a453241df3802 Mon Sep 17 00:00:00 2001 From: Piotr Rogowski Date: Wed, 1 Nov 2023 20:23:41 +0100 Subject: [PATCH] Add DBC view (#180) --- .vscode/settings.json | 2 + docs/07-Advanced-Features/CAN.mdx | 28 ++++- global.d.ts | 3 + package-lock.json | 79 ++++++++++++++ package.json | 2 + src/components/DbcViewer.tsx | 95 +++++++++++++++++ src/data/FOME_CAN_verbose.dbc | 170 ++++++++++++++++++++++++++++++ 7 files changed, 376 insertions(+), 3 deletions(-) create mode 100644 global.d.ts create mode 100644 src/components/DbcViewer.tsx create mode 100644 src/data/FOME_CAN_verbose.dbc diff --git a/.vscode/settings.json b/.vscode/settings.json index be4f065..1f3e90d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -26,6 +26,7 @@ "DFCO", "dyno", "easyops", + "endianess", "FOME", "footwell", "GPPMW", @@ -43,6 +44,7 @@ "pinout", "Polygonus", "powerband", + "Pulsewidth", "pushrod", "rehype", "standardised", diff --git a/docs/07-Advanced-Features/CAN.mdx b/docs/07-Advanced-Features/CAN.mdx index 8cdb0cc..66b20c0 100644 --- a/docs/07-Advanced-Features/CAN.mdx +++ b/docs/07-Advanced-Features/CAN.mdx @@ -1,8 +1,30 @@ +import DbcViewer from '@site/src/components/DbcViewer'; + # CAN -## What is CANBUS? +## What is CAN and CANBUS? + +**CAN** (Controller Area Network) is a robust vehicle bus standard designed to facilitate communication among various components without a host computer. It is used in many modern cars, and is a great way to get data from the car to the **ECU**. It is also a great way to get data from the **ECU** to other devices, such as a dash, or a data logger. + +**CANBUS / CAN bus**, or Controller Area Network Bus, refers to the physical medium (wires and connections) through which the CAN protocol operates. It's the network of interconnected CAN devices within a vehicle or industrial setup. + +## DBC + +A **DBC** (Database Container) file is a standard file format used in the context of Controller Area Network (CAN) networks. It contains information about messages and signals that can be transmitted over a CAN network. + +In a **DBC** file: + +- Messages represent specific packets of data sent over the CAN network, each identified by a unique ID. + +- Signals are individual pieces of data within messages, specifying the data's name, start bit, length, endianess, and other attributes. Signals can represent information such as vehicle speed, engine RPM, or sensor readings. + +## FOME's DBC file + +:::info SOURCE + +[FOME-Tech/fome-fw/blob/master/firmware/controllers/can/rusEFI_CAN_verbose.dbc](https://github.com/FOME-Tech/fome-fw/blob/master/firmware/controllers/can/rusEFI_CAN_verbose.dbc) -CANBUS is a communication protocol that allows devices to talk to each other. +::: -It is used in many modern cars, and is a great way to get data from the car to the ECU. It is also a great way to get data from the ECU to other devices, such as a dash, or a data logger. + diff --git a/global.d.ts b/global.d.ts new file mode 100644 index 0000000..6fc023f --- /dev/null +++ b/global.d.ts @@ -0,0 +1,3 @@ +declare module '*.txt'; +declare module '*.html'; +declare module '*.dbc'; diff --git a/package-lock.json b/package-lock.json index a34c4b6..2d65608 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "@docusaurus/preset-classic": "^3.0.0", "@easyops-cn/docusaurus-search-local": "^0.36.0", "@mdx-js/react": "^3.0.0", + "candied": "^2.2.0", "clsx": "^2.0.0", "prism-react-renderer": "^2.1.0", "react": "^18.2.0", @@ -28,6 +29,7 @@ "@tsconfig/docusaurus": "^2.0.2", "@types/node": "^20.8.10", "docusaurus-prince-pdf": "^1.2.1", + "raw-loader": "^4.0.2", "typescript": "^5.2.2" }, "engines": { @@ -6653,6 +6655,14 @@ "node": ">= 6" } }, + "node_modules/candied": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/candied/-/candied-2.2.0.tgz", + "integrity": "sha512-r2C6Ekh7nF8TbgLFL94r1SMWijiYKS8MBw6yb99FKVXvpa8OeH15WgRwV6PfPKENVAsMFQP0YU6SqemkUrWmXQ==", + "dependencies": { + "candied": "^2.1.0" + } + }, "node_modules/caniuse-api": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/caniuse-api/-/caniuse-api-3.0.0.tgz", @@ -14837,6 +14847,75 @@ "node": ">= 0.8" } }, + "node_modules/raw-loader": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/raw-loader/-/raw-loader-4.0.2.tgz", + "integrity": "sha512-ZnScIV3ag9A4wPX/ZayxL/jZH+euYb6FcUinPcgiQW0+UBtEv0O6Q3lGd3cqJ+GHH+rksEv3Pj99oxJ3u3VIKA==", + "dev": true, + "dependencies": { + "loader-utils": "^2.0.0", + "schema-utils": "^3.0.0" + }, + "engines": { + "node": ">= 10.13.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/webpack" + }, + "peerDependencies": { + "webpack": "^4.0.0 || ^5.0.0" + } + }, + "node_modules/raw-loader/node_modules/ajv": { + "version": "6.12.6", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", + "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", + "dev": true, + "dependencies": { + "fast-deep-equal": "^3.1.1", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/raw-loader/node_modules/ajv-keywords": { + "version": "3.5.2", + "resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-3.5.2.tgz", + "integrity": "sha512-5p6WTN0DdTGVQk6VjcEju19IgaHudalcfabD7yhDGeA6bcQnmL+CpveLJq/3hvfwd1aof6L386Ougkx6RfyMIQ==", + "dev": true, + "peerDependencies": { + "ajv": "^6.9.1" + } + }, + "node_modules/raw-loader/node_modules/json-schema-traverse": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", + "dev": true + }, + "node_modules/raw-loader/node_modules/schema-utils": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-3.3.0.tgz", + "integrity": "sha512-pN/yOAvcC+5rQ5nERGuwrjLlYvLTbCibnZ1I7B1LaiAz9BRBlE9GMgE/eqV30P7aJQUf7Ddimy/RsbYO/GrVGg==", + "dev": true, + "dependencies": { + "@types/json-schema": "^7.0.8", + "ajv": "^6.12.5", + "ajv-keywords": "^3.5.2" + }, + "engines": { + "node": ">= 10.13.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/webpack" + } + }, "node_modules/rc": { "version": "1.2.8", "resolved": "https://registry.npmjs.org/rc/-/rc-1.2.8.tgz", diff --git a/package.json b/package.json index abe1ef5..5b5d9e8 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "@docusaurus/preset-classic": "^3.0.0", "@easyops-cn/docusaurus-search-local": "^0.36.0", "@mdx-js/react": "^3.0.0", + "candied": "^2.2.0", "clsx": "^2.0.0", "prism-react-renderer": "^2.1.0", "react": "^18.2.0", @@ -43,6 +44,7 @@ "@tsconfig/docusaurus": "^2.0.2", "@types/node": "^20.8.10", "docusaurus-prince-pdf": "^1.2.1", + "raw-loader": "^4.0.2", "typescript": "^5.2.2" }, "browserslist": { diff --git a/src/components/DbcViewer.tsx b/src/components/DbcViewer.tsx new file mode 100644 index 0000000..b8b3292 --- /dev/null +++ b/src/components/DbcViewer.tsx @@ -0,0 +1,95 @@ +import { Dbc } from 'candied'; +import { DbcData } from 'candied/lib/dbc/Dbc'; +import { dbcReader } from 'candied/lib/filesystem/DbcWebFs'; +import { useEffect, useState } from 'react'; + +import fomeDbcFileRaw from '!!raw-loader!../data/FOME_CAN_verbose.dbc'; + +const DbcViewer = () => { + const [dbcData, setDbcData] = useState(null); + + useEffect(() => { + const dbc = new Dbc(); + + dbcReader(new File([fomeDbcFileRaw], 'file.dbc'), (content) => { + const data = dbc.load(content); + setDbcData(data); + }); + }, []); + + if (!dbcData) { + return Loading; + } + + return ( +
+ {Array.from(dbcData.messages.values()) + .sort((a, b) => Number(a.id) - Number(b.id)) + .map((message) => ( +
+

Message {message.name}

+ + + + + + + + + + + + + + + + + + + +
NameCAN IDDLCSending NodeDescription
{message.name}{message.id}{message.dlc}{message.sendingNode}{message.description}
+ +

Signals

+ + + + + + + + + + + + + + + + + + {Array.from(message.signals.values()).map((signal) => ( + + + + + + + + + + + + + + ))} + +
NameTypeFormatStartLengthFactorOffsetMinMaxUnitDescription
{signal.name}{signal.dataType}{signal.endian}{signal.startBit}{signal.length}{signal.factor}{signal.offset}{signal.min}{signal.max}{signal.unit}{signal.description}
+ +
+
+ ))} +
+ ); +}; + +export default DbcViewer; diff --git a/src/data/FOME_CAN_verbose.dbc b/src/data/FOME_CAN_verbose.dbc new file mode 100644 index 0000000..d322da5 --- /dev/null +++ b/src/data/FOME_CAN_verbose.dbc @@ -0,0 +1,170 @@ +VERSION "HIPBNYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY/4/%%%/4/'%**4YYY///" + + +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_ + +BS_: + +BU_: + + +BO_ 3221225472 VECTOR__INDEPENDENT_SIG_MSG: 0 Vector__XXX + SG_ AFR : 7|16@0+ (0.001,0) [0|0] "AFR" Vector__XXX + SG_ VVTPos : 24|16@1- (0.02,0) [0|0] "deg" Vector__XXX + SG_ NewSignal_0010 : 24|8@1+ (1,0) [0|0] "" Vector__XXX + SG_ NewSignal_0009 : 16|8@1+ (1,0) [0|0] "" Vector__XXX + SG_ NewSignal_0008 : 8|8@1+ (1,0) [0|0] "" Vector__XXX + SG_ NewSignal_0015 : 8|8@1+ (1,0) [0|0] "" Vector__XXX + SG_ NewSignal_0016 : 16|8@1+ (1,0) [0|0] "" Vector__XXX + SG_ NewSignal_0024 : 0|8@1+ (1,0) [0|0] "" Vector__XXX + +BO_ 512 BASE0: 8 Vector__XXX + SG_ WarningCounter : 0|16@1+ (1,0) [0|0] "" Vector__XXX + SG_ LastError : 16|16@1+ (1,0) [0|0] "" Vector__XXX + SG_ RevLimAct : 32|1@1+ (1,0) [0|0] "" Vector__XXX + SG_ MainRelayAct : 33|1@1+ (1,0) [0|0] "" Vector__XXX + SG_ FuelPumpAct : 34|1@1+ (1,0) [0|0] "" Vector__XXX + SG_ CELAct : 35|1@1+ (1,0) [0|0] "" Vector__XXX + SG_ EGOHeatAct : 36|1@1+ (1,0) [0|0] "" Vector__XXX + SG_ LambdaProtectAct : 37|1@1+ (1,0) [0|0] "" Vector__XXX + SG_ CurrentGear : 40|8@1+ (1,0) [0|0] "" Vector__XXX + SG_ DistanceTraveled : 48|16@1+ (0.1,0) [0|6553.5] "km" Vector__XXX + SG_ Fan : 38|1@1+ (1,0) [0|0] "" Vector__XXX + SG_ Fan2 : 39|1@1+ (1,0) [0|0] "" Vector__XXX + +BO_ 513 BASE1: 8 Vector__XXX + SG_ RPM : 0|16@1+ (1,0) [0|0] "RPM" Vector__XXX + SG_ IgnitionTiming : 16|16@1- (0.02,0) [0|0] "deg" Vector__XXX + SG_ InjDuty : 32|8@1+ (0.5,0) [0|100] "%" Vector__XXX + SG_ IgnDuty : 40|8@1+ (0.5,0) [0|100] "%" Vector__XXX + SG_ VehicleSpeed : 48|8@1+ (1,0) [0|255] "kph" Vector__XXX + SG_ FlexPct : 56|8@1+ (1,0) [0|100] "%" Vector__XXX + +BO_ 514 BASE2: 8 Vector__XXX + SG_ PPS : 0|16@1- (0.01,0) [0|100] "%" Vector__XXX + SG_ TPS1 : 16|16@1- (0.01,0) [0|100] "%" Vector__XXX + SG_ TPS2 : 32|16@1- (0.01,0) [0|100] "%" Vector__XXX + SG_ Wastegate : 48|16@1- (0.01,0) [0|100] "%" Vector__XXX + +BO_ 515 BASE3: 8 Vector__XXX + SG_ MAP : 0|16@1+ (0.03333333,0) [0|0] "kPa" Vector__XXX + SG_ CoolantTemp : 16|8@1+ (1,-40) [-40|200] "deg C" Vector__XXX + SG_ IntakeTemp : 24|8@1+ (1,-40) [-40|200] "deg C" Vector__XXX + SG_ AUX1Temp : 32|8@1+ (1,-40) [-40|200] "deg C" Vector__XXX + SG_ AUX2Temp : 40|8@1+ (1,-40) [-40|200] "deg C" Vector__XXX + SG_ MCUTemp : 48|8@1+ (1,-40) [-40|100] "deg C" Vector__XXX + SG_ FuelLevel : 56|8@1+ (0.5,0) [0|0] "%" Vector__XXX + +BO_ 516 BASE4: 8 Vector__XXX + SG_ OilPress : 16|16@1+ (0.03333333,0) [0|0] "kPa" Vector__XXX + SG_ OilTemperature : 32|8@1+ (1,-40) [-40|215] "deg C" Vector__XXX + SG_ FuelTemperature : 40|8@1+ (1,-40) [-40|215] "deg C" Vector__XXX + SG_ BattVolt : 48|16@1+ (0.001,0) [0|25] "mV" Vector__XXX + +BO_ 517 BASE5: 8 Vector__XXX + SG_ CylAM : 0|16@1+ (1,0) [0|0] "mg" Vector__XXX + SG_ EstMAF : 16|16@1+ (0.01,0) [0|0] "kg/h" Vector__XXX + SG_ InjPW : 32|16@1+ (0.003333333,0) [0|0] "ms" Vector__XXX + SG_ KnockCt : 48|16@1+ (1,0) [0|0] "count" Vector__XXX + +BO_ 518 BASE6: 8 Vector__XXX + SG_ FuelUsed : 0|16@1+ (1,0) [0|0] "g" Vector__XXX + SG_ FuelFlow : 16|16@1+ (0.005,0) [0|327] "g/s" Vector__XXX + SG_ FuelTrim1 : 32|16@1+ (0.01,0) [-50|50] "%" Vector__XXX + SG_ FuelTrim2 : 48|16@1+ (0.01,0) [-50|50] "%" Vector__XXX + +BO_ 519 BASE7: 8 Vector__XXX + SG_ Lam1 : 0|16@1+ (0.0001,0) [0|2] "lambda" Vector__XXX + SG_ Lam2 : 16|16@1+ (0.0001,0) [0|2] "lambda" Vector__XXX + SG_ FpLow : 32|16@1+ (0.03333333,0) [0|0] "kPa" Vector__XXX + SG_ FpHigh : 48|16@1+ (0.1,0) [0|0] "bar" Vector__XXX + +BO_ 520 BASE8: 8 Vector__XXX + SG_ Cam1I : 0|8@1- (1,0) [-100|100] "deg" Vector__XXX + SG_ Cam1Itar : 8|8@1- (1,0) [-100|100] "deg" Vector__XXX + SG_ Cam1E : 16|8@1- (1,0) [-100|100] "deg" Vector__XXX + SG_ Cam1Etar : 24|8@1- (1,0) [-100|100] "deg" Vector__XXX + SG_ Cam2I : 32|8@1- (1,0) [-100|100] "deg" Vector__XXX + SG_ Cam2Itar : 40|8@1- (1,0) [-100|100] "deg" Vector__XXX + SG_ Cam2E : 48|8@1- (1,0) [-100|100] "deg" Vector__XXX + SG_ Cam2Etar : 56|8@1- (1,0) [-100|100] "deg" Vector__XXX + + +CM_ SG_ 3221225472 AFR "Current AFR Reading +"; +CM_ SG_ 3221225472 VVTPos "Current VVT Position Reading"; +CM_ SG_ 512 WarningCounter "Total warnings since ECU start time"; +CM_ SG_ 512 LastError "Last error code"; +CM_ SG_ 512 RevLimAct "RPM Limiter Active"; +CM_ SG_ 512 MainRelayAct "Main Relay Active"; +CM_ SG_ 512 FuelPumpAct "Fuel Pump Output Active"; +CM_ SG_ 512 CELAct "Check Engine Light Active"; +CM_ SG_ 512 EGOHeatAct "EGO Heater Commanded On"; +CM_ SG_ 512 LambdaProtectAct "Lambda protection active (fault detected)"; +CM_ SG_ 512 CurrentGear "Current detected gear. 0 means neutral, 1 means first, etc."; +CM_ SG_ 512 DistanceTraveled "Distance traveled since reset"; +CM_ SG_ 513 RPM "Current RPM"; +CM_ SG_ 513 IgnitionTiming "Current Ignition Timing. Positive is advance."; +CM_ SG_ 513 InjDuty "Injection Duty +"; +CM_ SG_ 513 IgnDuty "Ignition Duty"; +CM_ SG_ 513 VehicleSpeed "Current Vehicle Speed"; +CM_ SG_ 513 FlexPct "Ethanol percent"; +CM_ BO_ 514 "Throttle positions"; +CM_ SG_ 514 PPS "Current Accelerator Pedal Position +"; +CM_ SG_ 514 TPS1 "Throttle Body 1 Position"; +CM_ SG_ 514 TPS2 "Throttle Body 2 Position"; +CM_ SG_ 514 Wastegate "Wastegate actuator position"; +CM_ SG_ 515 MAP "Current MAP Reading"; +CM_ SG_ 515 CoolantTemp "Current Coolant Temperature Reading"; +CM_ SG_ 515 IntakeTemp "Current Intake Air Temperature"; +CM_ SG_ 515 AUX1Temp "Current Aux1 Temperature"; +CM_ SG_ 515 AUX2Temp "Current Aux2 Temperature"; +CM_ SG_ 515 MCUTemp "Current MCU Temperature"; +CM_ SG_ 515 FuelLevel "Current Fuel Level"; +CM_ SG_ 516 OilPress "Current Oil Pressure Reading"; +CM_ SG_ 516 BattVolt "Current Battery Voltage Reading"; +CM_ SG_ 517 CylAM "Current Estimated Cylinder Airmass"; +CM_ SG_ 517 EstMAF "Current Estimated Total Airflow +"; +CM_ SG_ 517 InjPW "Current Commanded Injector Pulsewidth"; +CM_ SG_ 517 KnockCt "Knock detection counter"; +CM_ SG_ 518 FuelUsed "Total fuel consumed"; +CM_ SG_ 518 FuelFlow "Fuel flow rate"; +CM_ SG_ 518 FuelTrim1 "Fuel trim bank 1"; +CM_ SG_ 518 FuelTrim2 "Fuel trim bank 2"; +CM_ BO_ 519 "Fueling"; +CM_ SG_ 519 Lam1 "Lambda sensor 1"; +CM_ SG_ 519 Lam2 "Lambda sensor 2"; +CM_ SG_ 519 FpLow "Fuel pressure - low sensor"; +CM_ SG_ 519 FpHigh "Fuel pressure - high (GDI) sensor"; +CM_ BO_ 520 "Cams"; +CM_ SG_ 520 Cam1I "Cam bank 1 intake actual"; +CM_ SG_ 520 Cam1Itar "Cam bank 1 intake target"; +CM_ SG_ 520 Cam1E "Cam bank 1 exhaust actual"; +CM_ SG_ 520 Cam1Etar "Cam bank 1 exhaust target"; +CM_ SG_ 520 Cam2I "Cam bank 2 intake actual"; +CM_ SG_ 520 Cam2Itar "Cam bank 2 intake target"; +CM_ SG_ 520 Cam2E "Cam bank 2 exhaust actual"; +CM_ SG_ 520 Cam2Etar "Cam bank 2 exhaust target";