Skip to content

Commit 7cd47c4

Browse files
ardupilot: Add variables from non-main sources to the Data Lake
Today, we completely ignore data comming from sources with systemIDs different from the main one and component IDs different than 1. This PR reads the messages from those systems and create Data Lake variables for them, so the user can use it on VGIs, Plotters and other components.
1 parent d99565b commit 7cd47c4

1 file changed

Lines changed: 42 additions & 29 deletions

File tree

src/libs/vehicle/mavlink/vehicle.ts

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -315,39 +315,13 @@ export abstract class MAVLinkVehicle<Modes> extends Vehicle.AbstractVehicle<Mode
315315
const { system_id, component_id } = mavlink_message.header
316316

317317
if (system_id !== this.currentSystemId || component_id !== 1) {
318+
const sourcePaths = ['mavlink', 'ardupilot', `system=${system_id}`, `component=${component_id}`]
319+
this.addPackageVariablesToDataLake(mavlink_message, sourcePaths)
318320
return
319321
}
320322

321-
const messageType = mavlink_message.message.type
322-
323323
// Inject variables from the MAVLink messages into the DataLake
324-
if (['NAMED_VALUE_FLOAT', 'NAMED_VALUE_INT'].includes(messageType)) {
325-
// Special handling for NAMED_VALUE_FLOAT/NAMED_VALUE_INT messages
326-
const name = (mavlink_message.message.name as string[]).join('').replace(/\0/g, '')
327-
const path = `${messageType}/${name}`
328-
if (getDataLakeVariableInfo(path) === undefined) {
329-
createDataLakeVariable({ id: path, name: path, type: 'number' })
330-
}
331-
setDataLakeVariableData(path, mavlink_message.message.value)
332-
333-
// Create duplicated variables for legacy purposes (that was how they were stored in the old generic-variables system)
334-
const oldVariablePath = mavlink_message.message.name.join('').replaceAll('\x00', '')
335-
if (getDataLakeVariableInfo(oldVariablePath) === undefined) {
336-
createDataLakeVariable({ id: oldVariablePath, name: oldVariablePath, type: 'number' })
337-
}
338-
setDataLakeVariableData(oldVariablePath, mavlink_message.message.value)
339-
} else {
340-
// For all other messages, use the flattener
341-
const flattened = flattenData(mavlink_message.message)
342-
flattened.forEach(({ path, value }) => {
343-
if (value === null) return
344-
if (typeof value !== 'string' && typeof value !== 'number') return
345-
if (getDataLakeVariableInfo(path) === undefined) {
346-
createDataLakeVariable({ id: path, name: path, type: typeof value === 'string' ? 'string' : 'number' })
347-
}
348-
setDataLakeVariableData(path, value)
349-
})
350-
}
324+
this.addPackageVariablesToDataLake(mavlink_message)
351325

352326
// Update our internal messages
353327
this._messages.set(mavlink_message.message.type, { ...mavlink_message.message, epoch: new Date().getTime() })
@@ -1368,4 +1342,43 @@ export abstract class MAVLinkVehicle<Modes> extends Vehicle.AbstractVehicle<Mode
13681342
}
13691343
})
13701344
}
1345+
1346+
/**
1347+
* Inject variable(s) from the MAVLink package into the DataLake
1348+
* @param { Package } mavlinkPackage
1349+
* @param { string[] } sourcePaths Array of sequential path strings that will be joined to form the prefix of the variable path
1350+
*/
1351+
private addPackageVariablesToDataLake(mavlinkPackage: Package, sourcePaths?: string[]): void {
1352+
const messageType = mavlinkPackage.message.type
1353+
const prefix = sourcePaths ? `${sourcePaths.join('/')}/` : ''
1354+
1355+
// Inject variables from the MAVLink messages into the DataLake
1356+
if (['NAMED_VALUE_FLOAT', 'NAMED_VALUE_INT'].includes(messageType)) {
1357+
// Special handling for NAMED_VALUE_FLOAT/NAMED_VALUE_INT messages
1358+
const name = (mavlinkPackage.message.name as string[]).join('').replace(/\0/g, '')
1359+
const path = `${prefix}${messageType}/${name}`
1360+
if (getDataLakeVariableInfo(path) === undefined) {
1361+
createDataLakeVariable({ id: path, name: path, type: 'number' })
1362+
}
1363+
setDataLakeVariableData(path, mavlinkPackage.message.value)
1364+
1365+
// Create duplicated variables for legacy purposes (that was how they were stored in the old generic-variables system)
1366+
const oldVariablePath = `${prefix}${mavlinkPackage.message.name.join('').replaceAll('\x00', '')}`
1367+
if (getDataLakeVariableInfo(oldVariablePath) === undefined) {
1368+
createDataLakeVariable({ id: oldVariablePath, name: oldVariablePath, type: 'number' })
1369+
}
1370+
setDataLakeVariableData(oldVariablePath, mavlinkPackage.message.value)
1371+
} else {
1372+
// For all other messages, use the flattener
1373+
const flattened = flattenData(mavlinkPackage.message)
1374+
flattened.forEach(({ path, value }) => {
1375+
if (value === null) return
1376+
if (typeof value !== 'string' && typeof value !== 'number') return
1377+
if (getDataLakeVariableInfo(path) === undefined) {
1378+
createDataLakeVariable({ id: path, name: path, type: typeof value === 'string' ? 'string' : 'number' })
1379+
}
1380+
setDataLakeVariableData(path, value)
1381+
})
1382+
}
1383+
}
13711384
}

0 commit comments

Comments
 (0)