From 8c602753433b389bdefcdae0a3bb399cc4a6deaf Mon Sep 17 00:00:00 2001 From: Rafael Araujo Lehmkuhl Date: Wed, 21 Feb 2024 14:28:25 -0300 Subject: [PATCH 1/2] sensors-logging: Use `setTimeout` instead of `setInterval` on log routine This allows for changing the log interval during a log. --- src/libs/sensors-logging.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/libs/sensors-logging.ts b/src/libs/sensors-logging.ts index 95166602c..559f76c19 100644 --- a/src/libs/sensors-logging.ts +++ b/src/libs/sensors-logging.ts @@ -70,7 +70,7 @@ export type CockpitStandardLog = CockpitStandardLogPoint[] * Manager logging vehicle data and others */ class DataLogger { - currentLoggerInterval: ReturnType | undefined = undefined + shouldBeLogging = false currentCockpitLog: CockpitStandardLog = [] variablesBeingUsed: DatalogVariable[] = [] selectedVariablesToShow = useStorage('cockpit-datalogger-overlay-variables', []) @@ -85,6 +85,8 @@ class DataLogger { return } + this.shouldBeLogging = true + const vehicleStore = useMainVehicleStore() const cockpitLogsDB = localforage.createInstance({ driver: localforage.INDEXEDDB, @@ -98,7 +100,7 @@ class DataLogger { const fileName = `Cockpit (${format(initialTime, 'LLL dd, yyyy - HH꞉mm꞉ss O')}).clog` this.currentCockpitLog = [] - this.currentLoggerInterval = setInterval(async () => { + const logRoutine = async (): Promise => { const timeNow = new Date() const secondsNow = differenceInSeconds(timeNow, initialTime) @@ -127,7 +129,13 @@ class DataLogger { }) await cockpitLogsDB.setItem(fileName, this.currentCockpitLog) - }, interval) + + if (this.shouldBeLogging) { + setTimeout(logRoutine, this.logInterval.value) + } + } + + logRoutine() } /** @@ -139,7 +147,7 @@ class DataLogger { return } - clearInterval(this.currentLoggerInterval) + this.shouldBeLogging = false } /** @@ -147,7 +155,7 @@ class DataLogger { * @returns {boolean} */ logging(): boolean { - return this.currentLoggerInterval !== undefined + return this.shouldBeLogging } /** From 5d8327ef26ac1a8e06d8d967d5e52d9618cd4124 Mon Sep 17 00:00:00 2001 From: Rafael Araujo Lehmkuhl Date: Wed, 21 Feb 2024 14:28:25 -0300 Subject: [PATCH 2/2] sensors-logging: Allow changing the interval between log points --- src/libs/sensors-logging.ts | 30 +++++++++++++++++++++++++++-- src/views/ConfigurationLogsView.vue | 29 ++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/src/libs/sensors-logging.ts b/src/libs/sensors-logging.ts index 559f76c19..576dc5946 100644 --- a/src/libs/sensors-logging.ts +++ b/src/libs/sensors-logging.ts @@ -74,12 +74,12 @@ class DataLogger { currentCockpitLog: CockpitStandardLog = [] variablesBeingUsed: DatalogVariable[] = [] selectedVariablesToShow = useStorage('cockpit-datalogger-overlay-variables', []) + logInterval = useStorage('cockpit-datalogger-log-interval', 1000) /** * Start an intervaled logging - * @param {number} interval - The time to wait between two logs */ - startLogging(interval = 1000): void { + startLogging(): void { if (this.logging()) { Swal.fire({ title: 'Error', text: 'A log is already being generated.', icon: 'error', timer: 3000 }) return @@ -158,6 +158,32 @@ class DataLogger { return this.shouldBeLogging } + /** + * Set the interval between log points + * @param {number} interval The interval in milliseconds. Default is 1000 and minimum is 1 + */ + setInterval(interval: number): void { + if (interval < 1) { + Swal.fire({ text: 'Minimum log interval is 1 millisecond (1000 Hz).', icon: 'error' }) + return + } + + this.logInterval.value = interval + } + + /** + * Set the frequency of log points + * @param {number} frequency The frequency in hertz. Default is 1 Hz, minimum is 0.1 Hz and maximum is 1000 Hz + */ + setFrequency(frequency: number): void { + if (frequency > 1000 || frequency < 0.1) { + Swal.fire({ text: 'Log frequency should stay between 0.1 Hz and 1000 Hz.', icon: 'error' }) + return + } + + this.setInterval(1000 / frequency) + } + /** * Update state of a given variable * @param {DatalogVariable} variable - Name of the variable being updated diff --git a/src/views/ConfigurationLogsView.vue b/src/views/ConfigurationLogsView.vue index 38955329a..6efbe183a 100644 --- a/src/views/ConfigurationLogsView.vue +++ b/src/views/ConfigurationLogsView.vue @@ -12,12 +12,41 @@ :value="variable" > +

Frequency of the telemetry log

+ + Values between 1 and 100Hz are more common and can be set with the slider. + + + You can go as low as 0.1 Hz and as far as 1000 Hz using the text input. + +
+ + + + +