Skip to content

Commit bb4bd59

Browse files
committed
Connect test CAN processing to DataStore and notify on retention changes
1 parent 544381c commit bb4bd59

3 files changed

Lines changed: 28 additions & 7 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ downloads/
1515
eggs/
1616
.eggs/
1717
lib/
18+
!pecan/Frontend/pecan-live-dashboard/src/lib/
1819
lib64/
1920
parts/
2021
sdist/

pecan/Frontend/pecan-live-dashboard/src/lib/DataStore.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ class DataStore {
5757
public static getInstance(retentionWindowMs?: number): DataStore {
5858
if (!DataStore.instance) {
5959
DataStore.instance = new DataStore(retentionWindowMs);
60+
} else if (typeof retentionWindowMs === 'number') {
61+
DataStore.instance.setRetentionWindow(retentionWindowMs);
6062
}
6163
return DataStore.instance;
6264
}
@@ -267,12 +269,19 @@ class DataStore {
267269
* @param windowMs - New retention window in milliseconds
268270
*/
269271
public setRetentionWindow(windowMs: number): void {
272+
if (windowMs === this.retentionWindowMs) {
273+
return;
274+
}
275+
270276
this.retentionWindowMs = windowMs;
271-
277+
272278
// Prune all messages with new window
273279
for (const msgID of this.buffer.keys()) {
274280
this.pruneOldSamples(msgID);
275281
}
282+
283+
// Notify subscribers since data might have been pruned
284+
this.notifyAll();
276285
}
277286

278287
/**

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Dbc, Can } from 'candied';
2+
import { dataStore } from '../lib/DataStore';
23

34
// Simple type definitions for our use, align with InfluxDB3 schema for consistency
45
// InfluxDB3 Schema: id -> canId, name -> messageName, signalName, sensorReading, time
@@ -103,7 +104,7 @@ const testMessages = testMessagesRaw.map(line => {
103104
export async function processTestMessages() {
104105
try {
105106
console.log('--- Starting CAN Message Processing ---');
106-
107+
107108
// Fetch the DBC file content
108109
const dbcResponse = await fetch('/assets/dbc.dbc');
109110
const dbcText = await dbcResponse.text();
@@ -122,17 +123,17 @@ export async function processTestMessages() {
122123
for (const testMsg of testMessages) {
123124
// Create a CAN frame from the message ID and data
124125
const frame = can.createFrame(testMsg.canId, testMsg.data);
125-
126+
126127
// Decode the frame using the DBC definitions
127128
const decoded = can.decode(frame);
128-
129+
129130
if (decoded) {
130131
console.log(`\nTime: ${testMsg.time}, Message ID: ${testMsg.canId} (${decoded.name})`);
131-
132+
132133
// Candied uses boundSignals property (not signals)
133134
if (decoded.boundSignals && decoded.boundSignals instanceof Map) {
134135
const signals: { [key: string]: any } = {};
135-
136+
136137
decoded.boundSignals.forEach((signal, signalName) => {
137138
const parsed = parsePhysValue(signal.physValue);
138139
signals[signalName] = {
@@ -141,8 +142,18 @@ export async function processTestMessages() {
141142
// rawValue: signal.rawValue
142143
};
143144
});
144-
145+
145146
console.log('Signals:', signals);
147+
148+
dataStore.ingestMessage({
149+
msgID: testMsg.canId.toString(),
150+
messageName: decoded.name || `CAN_${testMsg.canId}`,
151+
data: signals,
152+
rawData: testMsg.data
153+
.map((byte) => byte.toString(16).padStart(2, '0').toUpperCase())
154+
.join(' '),
155+
timestamp: testMsg.time,
156+
});
146157
} else {
147158
console.log('No signals found in decoded message');
148159
}

0 commit comments

Comments
 (0)