Skip to content

Commit 452287f

Browse files
committed
Refactor DBC file loading to use import instead of fetch
Replaced dynamic fetching of the DBC file with direct import using Vite's ?raw loader. Updated WebSocketService and canProcessor to use the new approach.
1 parent 4903e23 commit 452287f

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

pecan/Frontend/pecan-live-dashboard/src/services/WebSocketService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export class WebSocketService {
1111
async initialize() {
1212
// Initialize CAN processor
1313
try {
14-
this.processor = await createCanProcessor('/assets/dbc.dbc');
14+
this.processor = await createCanProcessor();
1515
console.log('CAN processor initialized');
1616
} catch (error) {
1717
console.error('Failed to initialize CAN processor:', error);

pecan/Frontend/pecan-live-dashboard/src/utils/canProcessor.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { Dbc, Can } from 'candied';
22
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';
36

47
// Simple type definitions for our use, align with InfluxDB3 schema for consistency
58
// InfluxDB3 Schema: id -> canId, name -> messageName, signalName, sensorReading, time
@@ -105,15 +108,20 @@ export async function processTestMessages() {
105108
try {
106109
console.log('--- Starting CAN Message Processing ---');
107110

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;
111113
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);
112117

113118
// Create DBC instance and load the content
114119
const dbc = new Dbc();
115120
const data = dbc.load(dbcText); // Candied's load() accepts text content directly!
116121
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);
117125

118126
// Create a CAN decoder instance
119127
const can = new Can();
@@ -299,11 +307,14 @@ export function getDbcMessages(dbcData: any): MessageInfo[] {
299307

300308
/**
301309
* Create a CAN processing pipeline
302-
* @param dbcPath - Path to the DBC file
303310
* @returns Object with methods to process CAN messages
304311
*/
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);
307318
const can = new Can();
308319
can.database = data; // Candied uses .database property
309320

0 commit comments

Comments
 (0)