From 2dcfc0c37ae66b2b04b7159ab634242fc7f893c2 Mon Sep 17 00:00:00 2001 From: Gabor Vasarhelyi Date: Fri, 6 Mar 2026 11:26:45 +0100 Subject: [PATCH 1/2] fix: use UAV-TEST and UAV-CALIB on component test and calibration instead of generic OBJ-CMD --- src/features/uavs/UAVTestsPanel.jsx | 14 ++-- src/flockwave/builders.ts | 42 ++++++++++++ src/flockwave/messages.ts | 100 ++++++++++++++++++++++++++++ 3 files changed, 149 insertions(+), 7 deletions(-) diff --git a/src/features/uavs/UAVTestsPanel.jsx b/src/features/uavs/UAVTestsPanel.jsx index 75a98c50b..8b12bc01b 100644 --- a/src/features/uavs/UAVTestsPanel.jsx +++ b/src/features/uavs/UAVTestsPanel.jsx @@ -121,13 +121,13 @@ const UAVTestButton = ({ const [lastExecutionState, execute] = useAsyncFn(async () => { lastExecutedUavIdRef.current = uavId; - // TODO(ntamas): use the proper UAV-TEST messages designated for this - await messageHub.sendCommandRequest( - { - uavId, - command: type === 'test' ? 'test' : 'calib', - args: [String(component)], - }, + await ( + type === 'calib' + ? messageHub.sendComponentCalibrationRequest + : messageHub.sendComponentTestRequest + ).call( + messageHub, + { uavId, component }, { onProgress: (progress) => progressHandler(uavId, progress), timeout } ); return true; diff --git a/src/flockwave/builders.ts b/src/flockwave/builders.ts index af392c99e..f74048b8b 100644 --- a/src/flockwave/builders.ts +++ b/src/flockwave/builders.ts @@ -7,6 +7,8 @@ import type { Request_OBJCMD, Request_PRMSET, Request_PRMSETMANY, + Request_UAVCALIB, + Request_UAVTEST, } from '@skybrush/flockwave-spec'; import arrify from 'arrify'; @@ -157,3 +159,43 @@ export function createBulkParameterUploadRequest( parameters, }; } + +/** + * Creates an UAV-CALIB (component calibration) message + * + * @param uavIds IDs of the UAVs to send the request to + * @param component the component to calibrate + * @return the message + */ +export function createComponentCalibrationRequest( + uavIds: ObjectIDs, + component: string, +): Request_UAVCALIB { + const result: Request_UAVCALIB = { + type: 'UAV-CALIB', + ids: uavIds, + component, + }; + + return result; +} + +/** + * Creates an UAV-TEST (component test) message + * + * @param uavIds IDs of the UAVs to send the request to + * @param component the component to test + * @return the message + */ +export function createComponentTestRequest( + uavIds: ObjectIDs, + component: string, +): Request_UAVTEST { + const result: Request_UAVTEST = { + type: 'UAV-TEST', + ids: uavIds, + component, + }; + + return result; +} diff --git a/src/flockwave/messages.ts b/src/flockwave/messages.ts index ca9a30b5f..88b4ca050 100644 --- a/src/flockwave/messages.ts +++ b/src/flockwave/messages.ts @@ -24,6 +24,8 @@ import pTimeout from 'p-timeout'; import { createCancellationRequest, createCommandRequest, + createComponentCalibrationRequest, + createComponentTestRequest, createResumeRequest, } from './builders'; import { createOperationExecutor, type OperationExecutor } from './operations'; @@ -1443,6 +1445,104 @@ export default class MessageHub { ); } + /** + * Sends a Flockwave component calibration request (UAV-CALIB) with the given + * body and returns a promise that resolves or rejects when one of the following + * events happen: + * + * + * + * @param request.uavId ID of the UAV to send the request to + * @param request.component the component to calibrate + * @param options additional options to forward to the + * `handleMultiAsyncResponseForSingleId()` method of the + * AsyncOperationManager. Typical keys to use are `cancelToken`, + * `onProgress`, `timeout` and `noThrow`. + * @return a promise that resolves to the response of the UAV + * to the command or errors out in case of execution errors and + * timeouts. + */ + async sendComponentCalibrationRequest( + request: { + uavId: string; + component: string; + }, + options: AsyncResponseHandlerOptions + ): Promise { + const { uavId, component } = request; + const message = createComponentCalibrationRequest([uavId], component); + const response = await this.sendMessage(message); + return this._asyncOperationManager.handleMultiAsyncResponseForSingleId( + response, + uavId, + options + ); + } + + /** + * Sends a Flockwave component test request (UAV-TEST) with the given + * body and returns a promise that resolves or rejects when one of the following + * events happen: + * + * + * + * @param request.uavId ID of the UAV to send the request to + * @param request.component the component to calibrate + * @param options additional options to forward to the + * `handleMultiAsyncResponseForSingleId()` method of the + * AsyncOperationManager. Typical keys to use are `cancelToken`, + * `onProgress`, `timeout` and `noThrow`. + * @return a promise that resolves to the response of the UAV + * to the command or errors out in case of execution errors and + * timeouts. + */ + async sendComponentTestRequest( + request: { + uavId: string; + component: string; + }, + options: AsyncResponseHandlerOptions + ): Promise { + const { uavId, component } = request; + const message = createComponentTestRequest([uavId], component); + const response = await this.sendMessage(message); + return this._asyncOperationManager.handleMultiAsyncResponseForSingleId( + response, + uavId, + options + ); + } + /** * Sends a Flockwave message with the given body and then return a promise * that resolves when the server responds to the message. From 117e33006ff4511b9d3a4ed67ba6b638d6fda776 Mon Sep 17 00:00:00 2001 From: Gabor Vasarhelyi Date: Mon, 9 Mar 2026 09:54:26 +0100 Subject: [PATCH 2/2] chore: format with Prettier --- src/flockwave/builders.ts | 4 ++-- src/flockwave/messages.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/flockwave/builders.ts b/src/flockwave/builders.ts index f74048b8b..bcc7c5ecf 100644 --- a/src/flockwave/builders.ts +++ b/src/flockwave/builders.ts @@ -169,7 +169,7 @@ export function createBulkParameterUploadRequest( */ export function createComponentCalibrationRequest( uavIds: ObjectIDs, - component: string, + component: string ): Request_UAVCALIB { const result: Request_UAVCALIB = { type: 'UAV-CALIB', @@ -189,7 +189,7 @@ export function createComponentCalibrationRequest( */ export function createComponentTestRequest( uavIds: ObjectIDs, - component: string, + component: string ): Request_UAVTEST { const result: Request_UAVTEST = { type: 'UAV-TEST', diff --git a/src/flockwave/messages.ts b/src/flockwave/messages.ts index 88b4ca050..beacc66c6 100644 --- a/src/flockwave/messages.ts +++ b/src/flockwave/messages.ts @@ -1446,7 +1446,7 @@ export default class MessageHub { } /** - * Sends a Flockwave component calibration request (UAV-CALIB) with the given + * Sends a Flockwave component calibration request (UAV-CALIB) with the given * body and returns a promise that resolves or rejects when one of the following * events happen: * @@ -1495,7 +1495,7 @@ export default class MessageHub { } /** - * Sends a Flockwave component test request (UAV-TEST) with the given + * Sends a Flockwave component test request (UAV-TEST) with the given * body and returns a promise that resolves or rejects when one of the following * events happen: *