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

Satellite trajectory integration #35

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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: 7 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
"@types/node": "^16.11.66",
"@types/react": "^18.0.21",
"@types/react-dom": "^18.0.6",
"fast-json-patch": "^3.1.1",
"plotly.js": "^2.26.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-plotly.js": "^2.6.0",
"react-scripts": "^5.0.1",
"typescript": "^4.8.4",
"web-vitals": "^2.1.4"
Expand All @@ -24,7 +27,7 @@
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"lint" : "eslint --ext .js,.jsx,.ts,.tsx --fix src/"
"lint": "eslint --ext .js,.jsx,.ts,.tsx --fix src/"
},
"eslintConfig": {
"extends": [
Expand All @@ -43,5 +46,8 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@types/react-plotly.js": "^2.6.0"
}
}
30 changes: 28 additions & 2 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,40 @@
import React from 'react';
import Plot from 'react-plotly.js';
import './App.css';

import Home from './pages/Home'

import { useWebsocket } from './Websocket';

const App: React.FC = () => {

const state = useWebsocket();

return (
<div className="App">
<Home/>
{/* <p>hello</p> */}
{state === undefined && <p>State not yet initialised</p>}
{state && <p>{`${JSON.stringify(state)}`}</p>}
{<Home/>}
{<Plot
data={[
{
x: [0, 90, 180, 270],
y: [45, 30, -15, 30],
type: 'scatter',
mode: 'markers',
// marker: {color: 'red'},
},
// {type:'bar', x:[1, 2, 3], y:[2, 5, 3]},
]}
layout={{
xaxis: {range: [0, 360]},
yaxis: {range: [-90, 90]},
width:720, height: 480,
title: 'A fancy plot',
}}
/>}
</div>
);
}
export default App;
export default App;
6 changes: 6 additions & 0 deletions frontend/src/Groundstation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface MockGroundStation {
// whatever else might be needed ig
name: string,
location: string,
orientation: Map<Number, Number>,
}
77 changes: 77 additions & 0 deletions frontend/src/State.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
export interface State {
stations: Map<string, GroundStation>;
current_satellite: Satellite;
backend_status: BackendStatus;
}

export interface Satellite {
tle: string,
name: string,
norad_id: number,
ind_designator: string,
}

export interface BackendStatus {
lib_state: string,
cpu: number,
mem: number,
client_list: Array<string>,
}

export enum GroundStationStatus {
OFFLINE,
IDLE,
TRACKING,
OVERHEAT,
FAULT,
}

export enum AntennaType {
HELICAL,
DIPOLE,
YAGI,
PARABOLIC,
PATCH,
}

export enum GSKinematics {
STATIC,
AZ,
AZEL,
}

export interface GPSPosition {
latitude: String,
longitude: String,
altitude: String,
valid: boolean,
}

export interface GroundStation {
name: String,
location: GPSPosition,
orientation: PolarPoint,
signal_strength: number,
status: GroundStationStatus,
freq_response: [number, number],
antenna_type: AntennaType,
kinematics: GSKinematics,
}

export interface PolarPoint {
az: number,
el: number,
}

/// Actions

export interface UpdateStation {
name: String,
status: GroundStation,
}

export interface SelectSatellite {
satellite: Satellite,
}

export type StateAction = UpdateStation | SelectSatellite;
93 changes: 93 additions & 0 deletions frontend/src/Websocket.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { useEffect, useState } from "react";
import {State, StateAction} from "./State"
import {applyPatch, Operation} from "fast-json-patch"
interface Patch {
type: "Patch";
ops: Operation[]; // from fast-json-patch
}

interface Full {
type: "Full";
state: State;
}

type ServerMessage = Patch | Full;

let websocket: WebSocket | undefined;
let state: State | undefined;

const setupWebsocket = (onStateUpdate: (state: State) => void) => {
const uri = "ws://127.0.0.1:3333/ws";
const connection = new WebSocket(uri);
console.log(`connecting to websocket: ${uri}`);

connection.onopen = () => {
console.log("opened websocket");
websocket = connection;
};

connection.onclose = (reason) => {
websocket = undefined;

if (reason.code !== 1000 && reason.code !== 1001) {
console.log("closed websocket");

setTimeout(() => {
setupWebsocket(onStateUpdate);
}, 500);
}
};

connection.onerror = (error) => {
console.error("Error with websocket:", error);
connection.close();
}

connection.onmessage = (message) => {
const msg = JSON.parse(message.data) as ServerMessage;

switch (msg.type) {
case "Patch": {
if (state !== undefined) {
let {newDocument: newState} = applyPatch(state, msg.ops, false, false);

onStateUpdate(newState);
state = newState;
}
break;
}

case "Full" : {
onStateUpdate(msg.state);
state = msg.state;
break;
}
}
}
};

export const useWebsocket = () => {
let [state, updateState] = useState<State>();

useEffect(() => {
setupWebsocket((msg) => {
updateState(msg);
});

// the destructor needed by react apprently?
// Apparently only executed at program's end
return () => {
if (websocket) {
websocket.close(1000);
}
};
}, []);

return state;
}

export const sendAction = (action: StateAction): void => {
if (websocket) {
websocket.send(JSON.stringify(action));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
// Segment responsible for displaying information about the targeted satellite
// Matt

import React from 'react';
import {useEffect} from 'react';

Check warning on line 5 in frontend/src/components/EncounterSub/EncounterInfo/EncounterInfo.tsx

View workflow job for this annotation

GitHub Actions / React Lint

'useEffect' is defined but never used
import { Grid, Table, TableBody, TableCell, TableContainer, TableRow, Typography } from "@mui/material"
import { n2yo_radio_passes, n2yo_visual_passes } from '../../../types/n2yotypes';
import UTCtoD from '../../../logic/utility';



interface EncounterInfoProps {
vp: n2yo_visual_passes,
rp: n2yo_radio_passes
Expand Down
11 changes: 7 additions & 4 deletions frontend/src/logic/backend_req.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Matt Rossouw (omeh-a)
// 05/2022

import { gps_pos, backend_status } from "../types/hardwareTypes";

Check warning on line 5 in frontend/src/logic/backend_req.ts

View workflow job for this annotation

GitHub Actions / React Lint

'backend_status' is defined but never used
import { n2yo_get_radio_passes, n2yo_get_visual_passes, n2yo_positions, n2yo_whats_up } from "../types/n2yotypes";

// Parameters set by frontend to communicate with backend
Expand Down Expand Up @@ -61,8 +61,11 @@
}

// Get backend status
export async function getStatus() : Promise<backend_status> {
return await fetch(`http://127.0.0.1:${port}/status`)
.then(res => res.json())
.then(res => {return res as backend_status})
export async function getStatus() {
/*
return await fetch(`http://127.0.0.1:${port}/status`)
.then(res => res.json())
.then(res => {return res as backend_status})
//*/
return null
}
2 changes: 1 addition & 1 deletion frontend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
"jsx": "preserve"
},
"include": [
"src"
Expand Down
26 changes: 23 additions & 3 deletions orch-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,29 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
axum = { version = "0.6", features = ["ws"] }
axum = { version = "^0.6", features = ["ws"] }
futures = "0.3"
json-patch = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde = { version = "^1.0", features = ["derive"] }
serde_json = "*"
tokio = { version = "1.27", features = ["full"] }
serial = "0.4.0"
serialport = "4.2.1"

nyx-space = "1.1.2"
sgp4 = "1.2.2"
parse-tle = "0.1.0"

# reqwest = "0.11.20" # for when we want to move to async requests
ureq = { version = "*", features = ["json"] }

nalgebra = "0.32.3"

# if we wanted to have
plotters = "0.3"
# plotters-cairo = "*"

# because this package is super slow to run if not compiled
# in release mode
[profile.dev.package.nyx-space]
opt-level = 3
Loading
Loading