|
1 | 1 | import { Dbc, Can } from 'candied'; |
2 | 2 | import { dataStore } from '../lib/DataStore'; |
| 3 | +// Import DBC file as raw text - Vite's ?raw suffix loads file content at build time |
| 4 | +// Note: Files in src/assets/ cannot be fetched via URL, they must be imported |
| 5 | +import dbcFile from '../assets/dbc.dbc?raw'; |
3 | 6 |
|
4 | 7 | // Simple type definitions for our use, align with InfluxDB3 schema for consistency |
5 | 8 | // InfluxDB3 Schema: id -> canId, name -> messageName, signalName, sensorReading, time |
@@ -105,15 +108,20 @@ export async function processTestMessages() { |
105 | 108 | try { |
106 | 109 | console.log('--- Starting CAN Message Processing ---'); |
107 | 110 |
|
108 | | - // Fetch the DBC file content |
109 | | - const dbcResponse = await fetch('/assets/dbc.dbc'); |
110 | | - const dbcText = await dbcResponse.text(); |
| 111 | + // Use imported DBC file |
| 112 | + const dbcText = dbcFile; |
111 | 113 | console.log('DBC file loaded successfully'); |
| 114 | + console.log('DBC file size:', dbcText.length, 'bytes'); |
| 115 | + console.log('First 500 chars of DBC:', dbcText.substring(0, 500)); |
| 116 | + console.log('Number of BO_ lines:', (dbcText.match(/^BO_ /gm) || []).length); |
112 | 117 |
|
113 | 118 | // Create DBC instance and load the content |
114 | 119 | const dbc = new Dbc(); |
115 | 120 | const data = dbc.load(dbcText); // Candied's load() accepts text content directly! |
116 | 121 | console.log('DBC parsed successfully'); |
| 122 | + console.log('Data object:', data); |
| 123 | + console.log('Messages in DBC:', Array.from(data.messages.keys())); |
| 124 | + console.log('Number of messages:', data.messages.size); |
117 | 125 |
|
118 | 126 | // Create a CAN decoder instance |
119 | 127 | const can = new Can(); |
@@ -299,11 +307,14 @@ export function getDbcMessages(dbcData: any): MessageInfo[] { |
299 | 307 |
|
300 | 308 | /** |
301 | 309 | * Create a CAN processing pipeline |
302 | | - * @param dbcPath - Path to the DBC file |
303 | 310 | * @returns Object with methods to process CAN messages |
304 | 311 | */ |
305 | | -export async function createCanProcessor(dbcPath: string): Promise<any> { |
306 | | - const { dbc, data } = await loadDbcFile(dbcPath); |
| 312 | +export async function createCanProcessor(): Promise<any> { |
| 313 | + // Use imported DBC file |
| 314 | + const dbcText = dbcFile; |
| 315 | + |
| 316 | + const dbc = new Dbc(); |
| 317 | + const data = dbc.load(dbcText); |
307 | 318 | const can = new Can(); |
308 | 319 | can.database = data; // Candied uses .database property |
309 | 320 |
|
|
0 commit comments