Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mavlink: Don't log "unconnected" error too frequently #1581

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/libs/communication/mavlink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { MavComponent, MAVLinkType } from '../connection/m2r/messages/mavlink2re
import { type Message } from '../connection/m2r/messages/mavlink2rest-message'
import { MavlinkManualControlState } from '../joystick/protocols/mavlink-manual-control'

let lastTimeLoggedConnectionError = new Date(0)

/**
* Send a mavlink message
* @param {MavMessage} message
Expand All @@ -22,7 +24,10 @@ export const sendMavlinkMessage = (message: MavMessage): void => {
try {
ConnectionManager.write(textEncoder.encode(JSON.stringify(pack)))
} catch (error) {
// Don't log the error if it's too frequent
if (Date.now() < lastTimeLoggedConnectionError.getTime() + 10000) return
console.error('Error sending MAVLink message:', error)
lastTimeLoggedConnectionError = new Date()
}
}

Expand Down
Loading