Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions gcs/src/components/dashboard/map.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function MapSectionNonMemo({ passedRef, onDragstart, mapId = "dashboard" }) {
}, [gpsData])

useEffect(() => {
setFilteredMissionItems(filterMissionItems(missionItems.mission_items))
setFilteredMissionItems(filterMissionItems(missionItems.missionItems))
}, [missionItems])

useEffect(() => {
Expand Down Expand Up @@ -237,12 +237,12 @@ function MapSectionNonMemo({ passedRef, onDragstart, mapId = "dashboard" }) {
/>
)}

<MissionItems missionItems={missionItems.mission_items} />
<MissionItems missionItems={missionItems.missionItems} />

<FenceItems fenceItems={missionItems.fence_items} />
<FenceItems fenceItems={missionItems.fenceItems} />

{/* Show mission rally point */}
{missionItems.rally_items.map((item, index) => {
{missionItems.rallyItems.map((item, index) => {
return (
<MarkerPin
key={index}
Expand Down
10 changes: 9 additions & 1 deletion gcs/src/components/layout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
selectConnectedToDrone,
} from "../redux/slices/droneConnectionSlice"
import { selectAircraftTypeString } from "../redux/slices/droneInfoSlice"
import { selectShouldFetchAllMissionsOnDashboard } from "../redux/slices/missionSlice"
import {
notificationShown,
selectNotificationQueue,
Expand All @@ -35,6 +36,9 @@ export default function Layout({ children, currentPage }) {
const connectedToDrone = useSelector(selectConnectedToDrone)
const notificationQueue = useSelector(selectNotificationQueue)
const aircraftTypeString = useSelector(selectAircraftTypeString)
const shouldFetchAllMissionsOnDashboard = useSelector(
selectShouldFetchAllMissionsOnDashboard,
)

// Show queued notifications
useEffect(() => {
Expand All @@ -58,8 +62,12 @@ export default function Layout({ children, currentPage }) {
if (!connectedToDrone) return

if (currentPage.toLowerCase() == "dashboard") {
dispatch(emitGetCurrentMissionAll())
dispatch(emitGetHomePosition()) // use actual home position

if (shouldFetchAllMissionsOnDashboard) {
dispatch(emitGetCurrentMissionAll())
}

if (aircraftTypeString === "Plane") {
dispatch(emitGetLoiterRadius())
}
Expand Down
25 changes: 25 additions & 0 deletions gcs/src/helpers/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,28 @@ export function showNotification(title, message) {
...notificationTheme,
})
}

export function showLoadingNotification(title, message) {
const id = notifications.show({
title: title,
message: message,
loading: true,
autoClose: false,
withCloseButton: false,
...notificationTheme,
})

return id
}

export function closeLoadingNotification(id, title, message) {
notifications.update({
id: id,
title: title,
message: message,
loading: false,
autoClose: 2000,
color: tailwindColors.green[600],
...notificationTheme,
})
}
8 changes: 7 additions & 1 deletion gcs/src/redux/middleware/emitters.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import {
emitGetTargetInfo,
emitImportMissionFromFile,
emitWriteCurrentMission,
setShouldFetchAllMissionsOnDashboard,
showDashboardMissionFetchingNotificationThunk,
} from "../slices/missionSlice"
import {
emitRebootAutopilot,
Expand Down Expand Up @@ -70,7 +72,10 @@ export function handleEmitters(socket, store, action) {
},
{
emitter: emitGetCurrentMissionAll,
callback: () => socket.socket.emit("get_current_mission_all"),
callback: () => {
socket.socket.emit("get_current_mission_all")
store.dispatch(showDashboardMissionFetchingNotificationThunk())
},
},
{
emitter: emitSetLoiterRadius,
Expand Down Expand Up @@ -142,6 +147,7 @@ export function handleEmitters(socket, store, action) {
type: action.payload.type,
items: action.payload.items,
})
store.dispatch(setShouldFetchAllMissionsOnDashboard(true))
},
},
{
Expand Down
30 changes: 16 additions & 14 deletions gcs/src/redux/middleware/socketMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import {
// drone actions
import {
emitGetComPorts,
emitGetHomePosition,
emitGetLoiterRadius,
emitIsConnectedToDrone,
emitSetState,
setComPorts,
setConnected,
setConnecting,
Expand Down Expand Up @@ -46,13 +43,15 @@ import {
} from "../slices/droneInfoSlice"
import {
addIdToItem,
closeDashboardMissionFetchingNotificationThunk,
setCurrentMission,
setCurrentMissionItems,
setDrawingFenceItems,
setDrawingMissionItems,
setDrawingRallyItems,
setMissionProgressData,
setMissionProgressModal,
setShouldFetchAllMissionsOnDashboard,
setTargetInfo,
setUnwrittenChanges,
setUpdatePlannedHomePositionFromLoadData,
Expand Down Expand Up @@ -264,19 +263,10 @@ const socketMiddleware = (store) => {
store.dispatch(setConnecting(false))
store.dispatch(setConnectionModal(false))

const currentPage = store.getState().droneConnection.currentPage
store.dispatch(emitSetState(currentPage))

if (["dashboard", "missions"].includes(currentPage)) {
store.dispatch(emitGetHomePosition()) // fetch the actual home position of the drone
if (msg.aircraft_type === 1) {
store.dispatch(emitGetLoiterRadius())
}
}

store.dispatch(setGuidedModePinData({ lat: 0, lon: 0, alt: 0 }))
store.dispatch(setRebootData({}))
store.dispatch(setAutoPilotRebootModalOpen(false))
store.dispatch(setShouldFetchAllMissionsOnDashboard(true))
})

// Link stats
Expand Down Expand Up @@ -412,7 +402,19 @@ const socketMiddleware = (store) => {
socket.socket.on(
MissionSpecificSocketEvents.onCurrentMissionAll,
(msg) => {
store.dispatch(setCurrentMissionItems(msg))
if (!msg.success) {
store.dispatch(queueErrorNotification(msg.message))
} else {
store.dispatch(
setCurrentMissionItems({
missionItems: msg.mission_items,
fenceItems: msg.fence_items,
rallyItems: msg.rally_items,
}),
)
store.dispatch(setShouldFetchAllMissionsOnDashboard(false))
}
store.dispatch(closeDashboardMissionFetchingNotificationThunk())
},
)

Expand Down
52 changes: 48 additions & 4 deletions gcs/src/redux/slices/missionSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { v4 as uuidv4 } from "uuid"
import { coordToInt } from "../../helpers/dataFormatters"
import { isGlobalFrameHomeCommand } from "../../helpers/filterMissions"
import { MAV_FRAME_LIST } from "../../helpers/mavlinkConstants"
import {
closeLoadingNotification,
showLoadingNotification,
} from "../../helpers/notification"

const missionInfoSlice = createSlice({
name: "missionInfo",
Expand All @@ -13,10 +17,9 @@ const missionInfoSlice = createSlice({
seq: 0,
},
currentMissionItems: {
// These should be camelCase etc but its easier to keep it as snake_case
mission_items: [],
fence_items: [],
rally_items: [],
missionItems: [],
fenceItems: [],
rallyItems: [],
},
drawingItems: {
// This is for the missions page, used locally and then will update currentMissionItems on save
Expand Down Expand Up @@ -61,6 +64,8 @@ const missionInfoSlice = createSlice({
gpsCoords: { lat: 0, lng: 0 },
markerId: null,
},
shouldFetchAllMissionsOnDashboard: true, // bool so that the dashboard can refresh its data when switched to if needed
dashboardMissionFetchingNotificationId: null,
},
reducers: {
setCurrentMission: (state, action) => {
Expand Down Expand Up @@ -394,6 +399,15 @@ const missionInfoSlice = createSlice({
position: { x: x, y: y },
}
},
setShouldFetchAllMissionsOnDashboard: (state, action) => {
if (action.payload === state.shouldFetchAllMissionsOnDashboard) return
state.shouldFetchAllMissionsOnDashboard = action.payload
},
setDashboardMissionFetchingNotificationId: (state, action) => {
if (action.payload === state.dashboardMissionFetchingNotificationId)
return
state.dashboardMissionFetchingNotificationId = action.payload
},

// Emits
emitGetTargetInfo: () => {},
Expand Down Expand Up @@ -422,6 +436,10 @@ const missionInfoSlice = createSlice({
selectMissionProgressData: (state) => state.missionProgressData,
selectActiveTab: (state) => state.activeTab,
selectContextMenu: (state) => state.contextMenu,
selectShouldFetchAllMissionsOnDashboard: (state) =>
state.shouldFetchAllMissionsOnDashboard,
selectDashboardMissionFetchingNotificationId: (state) =>
state.dashboardMissionFetchingNotificationId,
},
})

Expand Down Expand Up @@ -491,6 +509,28 @@ export const setPlannedHomePositionToDronesHomePositionThunk =
}
}

export const showDashboardMissionFetchingNotificationThunk =
() => (dispatch) => {
const notificationId = showLoadingNotification(
"Fetching the mission",
"Fetching the mission from the drone",
)
dispatch(setDashboardMissionFetchingNotificationId(notificationId))
}

export const closeDashboardMissionFetchingNotificationThunk =
() => (dispatch, getState) => {
const { dashboardMissionFetchingNotificationId } = getState().missionInfo
if (dashboardMissionFetchingNotificationId) {
closeLoadingNotification(
dashboardMissionFetchingNotificationId,
"Mission fetched",
"Successfully fetched the mission from the drone",
)
}
dispatch(setDashboardMissionFetchingNotificationId(null))
}

export const getFrameKey = (frame) =>
parseInt(
Object.keys(MAV_FRAME_LIST).find((key) => MAV_FRAME_LIST[key] == frame),
Expand Down Expand Up @@ -534,6 +574,8 @@ export const {
selectMissionProgressData,
selectActiveTab,
selectContextMenu,
selectShouldFetchAllMissionsOnDashboard,
selectDashboardMissionFetchingNotificationId,
} = missionInfoSlice.selectors

export const {
Expand Down Expand Up @@ -565,6 +607,8 @@ export const {
emitWriteCurrentMission,
emitImportMissionFromFile,
emitExportMissionToFile,
setShouldFetchAllMissionsOnDashboard,
setDashboardMissionFetchingNotificationId,
emitControlMission,
} = missionInfoSlice.actions

Expand Down
18 changes: 9 additions & 9 deletions radio/app/controllers/missionController.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,22 +135,22 @@ def getCurrentMissionAll(self) -> Response:
rally_items: List[Any] = []

_mission_items = self.getMissionItems(mission_type=TYPE_MISSION)
if not _mission_items.get("success"):
self.drone.logger.warning(_mission_items.get("message"))
else:
if _mission_items.get("success"):
mission_items = _mission_items.get("data", [])
Comment thread
1Blademaster marked this conversation as resolved.
else:
return _mission_items

_fence_items = self.getMissionItems(mission_type=TYPE_FENCE)
if not _fence_items.get("success"):
self.drone.logger.warning(_fence_items.get("message"))
else:
if _fence_items.get("success"):
fence_items = _fence_items.get("data", [])
Comment thread
1Blademaster marked this conversation as resolved.
else:
return _fence_items

_rally_items = self.getMissionItems(mission_type=TYPE_RALLY)
if not _rally_items.get("success"):
self.drone.logger.warning(_rally_items.get("message"))
else:
if _rally_items.get("success"):
rally_items = _rally_items.get("data", [])
Comment thread
1Blademaster marked this conversation as resolved.
else:
return _rally_items

return {
"success": True,
Expand Down
5 changes: 5 additions & 0 deletions radio/app/endpoints/mission.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,18 @@ def getCurrentMissionAll() -> None:

result = droneStatus.drone.missionController.getCurrentMissionAll()

if not result.get("success"):
socketio.emit("current_mission_all", result)
return

data: dict[str, Any] = result.get("data", {})
if not isinstance(data, dict):
data = {}

socketio.emit(
"current_mission_all",
{
"success": True,
"mission_items": data.get("mission_items", []),
"fence_items": data.get("fence_items", []),
"rally_items": data.get("rally_items", []),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"success": true,
"mission_items": [
{
"autocontinue": 1,
Expand Down
Loading