diff --git a/src/components/development/MAVLinkInspector.vue b/src/components/development/MAVLinkInspector.vue new file mode 100644 index 000000000..62afd082f --- /dev/null +++ b/src/components/development/MAVLinkInspector.vue @@ -0,0 +1,104 @@ + + + diff --git a/src/libs/connection/connection-manager.ts b/src/libs/connection/connection-manager.ts index 5f72f4543..a3210aba8 100644 --- a/src/libs/connection/connection-manager.ts +++ b/src/libs/connection/connection-manager.ts @@ -14,6 +14,7 @@ export class ConnectionManager { // Signals static onMainConnection = new Signal>() static onRead = new Signal() + static onWrite = new Signal() /** * Return the connections available @@ -69,7 +70,9 @@ export class ConnectionManager { } previousConnection?.onRead?.clear() + previousConnection?.onWrite?.clear() connection.onRead.add((data: Uint8Array) => this.onRead.emit_value(data)) + connection.onWrite.add((data: Uint8Array) => this.onWrite.emit_value(data)) ConnectionManager._mainConnection = new WeakRef(connection) // There is no constructor and updating the register is not expensive in this function ConnectionManager.onMainConnection.register_caller( @@ -96,6 +99,7 @@ export class ConnectionManager { */ static write(data: Uint8Array): boolean { ConnectionManager.mainConnection()?.write(data) + ConnectionManager.onWrite.emit_value(data) return true } } diff --git a/src/libs/connection/connection.ts b/src/libs/connection/connection.ts index 562065c0c..b2c321b06 100644 --- a/src/libs/connection/connection.ts +++ b/src/libs/connection/connection.ts @@ -64,6 +64,7 @@ export abstract class Abstract { // Signals public onRead = new Signal() + public onWrite = new Signal() /** * Return the connection uri diff --git a/src/libs/vehicle/ardupilot/ardupilot.ts b/src/libs/vehicle/ardupilot/ardupilot.ts index 2e8269425..63ee867d4 100644 --- a/src/libs/vehicle/ardupilot/ardupilot.ts +++ b/src/libs/vehicle/ardupilot/ardupilot.ts @@ -82,7 +82,8 @@ export abstract class ArduPilotVehicle extends Vehicle.AbstractVehicle extends Vehicle.AbstractVehicle extends Vehicle.AbstractVehicle { diff --git a/src/libs/vehicle/vehicle-factory.ts b/src/libs/vehicle/vehicle-factory.ts index 37b3427f4..b85e2e086 100644 --- a/src/libs/vehicle/vehicle-factory.ts +++ b/src/libs/vehicle/vehicle-factory.ts @@ -44,7 +44,8 @@ export class VehicleFactory { return undefined } - ConnectionManager.onRead.add((message) => vehicle?.onMessage(message)) + ConnectionManager.onRead.add((message) => vehicle?.onIncomingMessage(message)) + ConnectionManager.onWrite.add((message) => vehicle?.onOutgoingMessage(message)) VehicleFactory._vehicles.push(new WeakRef(vehicle)) VehicleFactory.onVehicles.register_caller(this.vehicles) diff --git a/src/libs/vehicle/vehicle.ts b/src/libs/vehicle/vehicle.ts index 5ecf77585..83f46ef7d 100644 --- a/src/libs/vehicle/vehicle.ts +++ b/src/libs/vehicle/vehicle.ts @@ -169,7 +169,8 @@ export abstract class AbstractVehicle { } } - abstract onMessage(message: Uint8Array): void + abstract onIncomingMessage(message: Uint8Array): void + abstract onOutgoingMessage(message: Uint8Array): void abstract arm(): Promise abstract altitude(): Altitude diff --git a/src/stores/mainVehicle.ts b/src/stores/mainVehicle.ts index 19f9b2bf2..506371f42 100644 --- a/src/stores/mainVehicle.ts +++ b/src/stores/mainVehicle.ts @@ -495,7 +495,7 @@ export const useMainVehicleStore = defineStore('main-vehicle', () => { } }, 1000) - mainVehicle.value.onMAVLinkMessage.add(MAVLinkType.HEARTBEAT, (pack: Package) => { + mainVehicle.value.onIncomingMAVLinkMessage.add(MAVLinkType.HEARTBEAT, (pack: Package) => { if (pack.header.component_id != 1) { return } @@ -533,6 +533,20 @@ export const useMainVehicleStore = defineStore('main-vehicle', () => { }) }) + const listenToIncomingMessages = (messageType: string, callback: (pack: Package) => void): void => { + if (!mainVehicle.value) { + throw new Error('No vehicle available to listen for incoming messages.') + } + mainVehicle.value?.onIncomingMAVLinkMessage.add(messageType, callback) + } + + const listenToOutgoingMessages = (messageType: string, callback: (pack: Package) => void): void => { + if (!mainVehicle.value) { + throw new Error('No vehicle available to listen for outgoing messages.') + } + mainVehicle.value?.onOutgoingMAVLinkMessage.add(messageType, callback) + } + // Allow us to set custom commands to be used in the browser // Expert mode watch(mainVehicle, async (newVehicle) => { @@ -618,5 +632,7 @@ export const useMainVehicleStore = defineStore('main-vehicle', () => { genericVariables, availableGenericVariables, registerUsageOfGenericVariable, + listenToIncomingMessages, + listenToOutgoingMessages, } }) diff --git a/src/views/ConfigurationDevelopmentView.vue b/src/views/ConfigurationDevelopmentView.vue index 557a8a5b5..266dcec6b 100644 --- a/src/views/ConfigurationDevelopmentView.vue +++ b/src/views/ConfigurationDevelopmentView.vue @@ -54,6 +54,12 @@ thumb-label="hover" /> + + + +