Skip to content

Commit

Permalink
core: frontend: serial bridges: disable and warn users if a port is i…
Browse files Browse the repository at this point in the history
…n use by the autopilot
  • Loading branch information
Williangalvani committed Dec 8, 2023
1 parent ddd705c commit c5ff713
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
32 changes: 24 additions & 8 deletions core/frontend/src/components/bridges/BridgeCreationDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
:loading="updating_serial_ports"
item-text="name"
:item-value="(item) => item.by_path ? item.by_path : item.name"
:item-disabled="(item) => item.current_user !== null"
dense
>
<template #item="{ item }">
Expand All @@ -36,6 +37,16 @@
<v-list-item-content dense>
<v-list-item-title md-1>
Device: {{ item.name }}
<v-chip
v-if="item.current_user"
class="ma-2 pl-2 pr-2"
color="red"
pill
x-small
text-color="white"
>
In use by {{ item.current_user }}
</v-chip>
</v-list-item-title>
<v-list-item-subtitle class="text-wrap">
Path: {{ item.by_path ? item.by_path : item.name }}
Expand Down Expand Up @@ -115,8 +126,10 @@
import { formatDistanceToNow } from 'date-fns'
import Vue from 'vue'
import * as AutopilotManager from '@/components/autopilot/AutopilotManagerUpdater'
import DevicePathHelper from '@/components/common/DevicePathHelper.vue'
import Notifier from '@/libs/notifier'
import autopilot from '@/store/autopilot_manager'
import bridget from '@/store/bridget'
import system_information from '@/store/system-information'
import { Baudrate } from '@/types/common'
Expand Down Expand Up @@ -172,17 +185,17 @@ export default Vue.extend({
},
available_serial_ports(): SerialPortInfo[] {
const system_serial_ports: SerialPortInfo[] | undefined = system_information.serial?.ports
if (system_serial_ports === undefined || system_serial_ports.isEmpty()) {
return bridget.available_serial_ports.map((port) => ({
name: port,
by_path: port,
by_path_created_ms_ago: null,
udev_properties: null,
}))
if (!system_serial_ports) {
return []
}
return system_serial_ports
.filter((serial_info) => bridget.available_serial_ports.includes(serial_info.name))
.map((serial_info) => ({
...serial_info,
current_user: autopilot.autopilot_serials.some(
(serial) => serial.endpoint === serial_info.name,
) ? 'autopilot' : null,
}))
},
bridge_mode(): string {
switch (this.bridge.ip) {
Expand All @@ -204,6 +217,9 @@ export default Vue.extend({
return this.updating_serial_ports ? 'Fetching available serial ports...' : 'Serial port'
},
},
async mounted() {
await AutopilotManager.fetchAutopilotSerialConfiguration()
},
methods: {
create_time_ago(ms_time: number): string {
const time_now = new Date().valueOf()
Expand Down
2 changes: 2 additions & 0 deletions core/frontend/src/types/system-information/serial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export interface SerialPortInfo {
by_path_created_ms_ago: number | null
// Udev information from the device
udev_properties: JSONValue | null,
// Is the port in use? by whom?
current_user: string | null,
}

/** Base structure that provides serial port information */
Expand Down

0 comments on commit c5ff713

Please sign in to comment.