-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Started doing frontend refactor in relation to backend websocket. JIR…
…A: GNS-42
- Loading branch information
1 parent
7547781
commit d8a1a04
Showing
6 changed files
with
147 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
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, | ||
} | ||
|
||
//export type StateAction = GPSPosition | GroundStation | AntennaType; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import {State} 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 (todo !== undefined) { | ||
let {newDocument: newState} = applyPatch(todo, msg.ops, false, fals) | ||
} | ||
break; | ||
} | ||
|
||
case "Full" : { | ||
|
||
break; | ||
} | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters