Skip to content

Commit

Permalink
frontend: px4-metadata-fetcher: Board parameters
Browse files Browse the repository at this point in the history
* Add fetch parameters from PX4 board when available in parameters
  fetcher
  • Loading branch information
JoaoMario109 committed Jun 23, 2024
1 parent 0193d0f commit e9df12b
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions core/frontend/src/types/autopilot/px4/metadata-fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import filebrowser from '@/libs/filebrowser'
import { XzReadableStream } from 'xz-decompress'

interface PX4ParametersMetadataValuesItem {
description: string
value: number
Expand Down Expand Up @@ -32,15 +35,29 @@ interface PX4ParametersMetadata {
}

async function fetchPX4MetadataFromBoard(): Promise<PX4ParametersMetadata[]> {
// TODO - Add mav ftp fetch to get parameters.json from board
throw new Error('Not implemented')
const px4ExtrasFolder = await filebrowser.fetchFolder('ardupilot_logs/logs/mavftp/etc/extras', 30000)

const parameterFile = px4ExtrasFolder.items.find((file) => file.name === 'parameters.json.xz')
if (!parameterFile) {
throw new Error('PX4 parameters metadata file not found')
}

const response = await fetch(await filebrowser.singleFileRelativeURL(parameterFile))
if (!response || !response.ok || !response.body) {
throw new Error(`Failed to fetch PX4 parameters metadata: ${response.statusText}`)
}

const decompressedStream = new Response(new XzReadableStream(response.body))

return (await decompressedStream.json()).parameters as PX4ParametersMetadata[]
}

async function fetchPX4Metadata(): Promise<PX4ParametersMetadata[]> {
let metadata
try {
metadata = await fetchPX4MetadataFromBoard()
} catch (e) {
console.error('Falling back to default PX4 Metadata Repository parameters, unable to fetch from board.', e)
metadata = (await import('@/PX4-parameters/master/parameters.json')).parameters
}

Expand Down

0 comments on commit e9df12b

Please sign in to comment.