Skip to content

Commit

Permalink
works
Browse files Browse the repository at this point in the history
  • Loading branch information
adenjonah committed May 22, 2024
1 parent 8fe120f commit 776b999
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 108 deletions.
2 changes: 1 addition & 1 deletion server/json_databases/DCUUIA.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"timestamp": "2024-05-20T05:50:15.085340", "dcu": {"eva1": {"batt": false, "oxy": true, "comm": false, "fan": true, "pump": false, "co2": false}, "eva2": {"batt": false, "oxy": false, "comm": true, "fan": false, "pump": false, "co2": false}}, "uia": {"eva1_power": false, "eva1_oxy": false, "eva1_water_supply": false, "eva1_water_waste": false, "eva2_power": false, "eva2_oxy": false, "eva2_water_supply": false, "eva2_water_waste": false, "oxy_vent": false, "depress": false}}
{"timestamp": "2024-05-22T02:15:24.677766", "dcu": {"eva1": {"batt": false, "oxy": false, "comm": false, "fan": false, "pump": false, "co2": false}, "eva2": {"batt": false, "oxy": false, "comm": false, "fan": false, "pump": false, "co2": false}}, "uia": {"eva1_power": false, "eva1_oxy": false, "eva1_water_supply": false, "eva1_water_waste": true, "eva2_power": false, "eva2_oxy": false, "eva2_water_supply": true, "eva2_water_waste": false, "oxy_vent": false, "depress": true}}
36 changes: 20 additions & 16 deletions server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@ def initialize_files():
async def startup_event():
initialize_files() # Ensure files are created if they do not exist
initialize_database_files()
scheduler = AsyncIOScheduler()
scheduler.add_job(periodic_fetch_and_store, 'interval', seconds=10) # Adjust the interval as needed
scheduler.start()
task = asyncio.create_task(periodic_fetch_and_store())
await asyncio.sleep(1)

async def periodic_fetch_and_store():
global team_number
Expand All @@ -96,17 +95,22 @@ async def periodic_fetch_and_store():
telemetry_url = f"http://{tss_ip}/json_data/teams/{team_number}/TELEMETRY.json"
dcu_url = f"http://{tss_ip}/json_data/DCU.json"
uia_url = f"http://{tss_ip}/json_data/UIA.json"
warnings_url = f'http://{tss_ip}/json_data/ERROR.json'

while True:
print('running')
try:
# Fetch EVA and telemetry data
eva_data = await fetch_json(eva_url)
telemetry_data = await fetch_json(telemetry_url)
if eva_data and telemetry_data:
warnings_data = await fetch_json(warnings_url)

if eva_data and telemetry_data and warnings_data:
combined_data = {
"timestamp": datetime.now().isoformat(),
"eva": eva_data,
"telemetry": telemetry_data
"telemetry": telemetry_data,
"warnings": warnings_data
}
with open(DATA_FILE, 'w') as f:
json.dump(combined_data, f)
Expand Down Expand Up @@ -137,6 +141,15 @@ async def get_dcu_uia():
else:
raise HTTPException(status_code=404, detail="DCUUIA.json not found")

@app.get("/warnings")
async def get_warnings():
if os.path.exists(DATA_FILE):
with open(DATA_FILE, 'r') as f:
data = json.load(f)
return data['warnings']
else:
raise HTTPException(status_code=404, detail="DCUUIA.json not found")

def utm_to_latlon(easting, northing, zone_number=15, zone_letter='R'):
return utm.to_latlon(easting, northing, zone_number, zone_letter)

Expand Down Expand Up @@ -237,7 +250,7 @@ async def read_data():

# Check Hololens, Server, and TSS Connection
@app.get("/check_connection")
async def check_connection(tss_ip: str = None, holo_ip: str = None, server_ip: str = None):
async def check_connection(tss_ip: str = None, server_ip: str = None):
async with httpx.AsyncClient() as client:
if tss_ip:
try:
Expand All @@ -248,15 +261,6 @@ async def check_connection(tss_ip: str = None, holo_ip: str = None, server_ip: s
return {"status": "no connection", "type": "TSS_IP"}
except Exception:
return {"status": "no connection", "type": "TSS_IP"}
elif holo_ip:
try:
response = await client.get(f"https://{holo_ip}/")
if response.status_code == 200:
return {"status": "connected", "type": "HOLO_IP"}
else:
return {"status": "no connection", "type": "HOLO_IP"}
except Exception:
return {"status": "no connection", "type": "HOLO_IP"}
elif server_ip:
try:
response = await client.get(f"http://{server_ip}/docs")
Expand All @@ -267,7 +271,7 @@ async def check_connection(tss_ip: str = None, holo_ip: str = None, server_ip: s
except Exception:
return {"status": "no connection", "type": "SERVER_IP"}
else:
raise HTTPException(status_code=400, detail="Invalid request, provide either tss_ip, holo_ip, or server_ip")
raise HTTPException(status_code=400, detail="Invalid request, provide either tss_ip or server_ip")

class Marker(BaseModel):
title: str
Expand Down
170 changes: 112 additions & 58 deletions src/components/Navbar.js
Original file line number Diff line number Diff line change
@@ -1,70 +1,124 @@
import React, { useState } from "react";
import React, { useState, useEffect } from "react";
import { NavLink as Link } from "react-router-dom";
import './navbar.css';

// WarningModal Component
const WarningModal = ({ closeModal, isVisible }) => {
return (
<div className={`warning ${isVisible ? '' : 'hidden'}`}>
<div className="warning-modal-content">
<p>This is a warning message!</p>
<button className="warning-acknowledge" onClick={closeModal}>
I Acknowledge
</button>
</div>
</div>
);
};

// Navbar Component
const Navbar = () => {
const [showModal, setShowModal] = useState(false);
const [isVisible, setIsVisible] = useState(true);
const [showModal, setShowModal] = useState(false);
const [isVisible, setIsVisible] = useState(false);
const [warnings, setWarnings] = useState([]);

const openModal = () => {
setShowModal(true);
setIsVisible(true);
};
useEffect(() => {
const fetchWarnings = async () => {
try {
const response = await fetch('http://localhost:8000/warnings');
const data = await response.json();
const activeWarnings = Object.entries(data.error)
.filter(([key, value]) => value)
.map(([key]) => key);

const closeModal = () => {
setIsVisible(false);
setTimeout(() => setShowModal(false), 500); // Wait for the fade-out transition to complete
if (activeWarnings.length > 0) {
setWarnings(activeWarnings);
setShowModal(true);
setIsVisible(true);
}
} catch (error) {
console.error('Error fetching warnings:', error);
}
};

return (
<nav className="Navbar">
<div className="NavMenu">
<img className="img" src={require("./../assets/Images/logo.jpg")} alt="Logo"/>
<h1 id="title">CUITS LMCC 2024</h1>
<Link className="NavLink" to="/Constant" activeStyle={{ color: '#69b3e7' }}>
Constant
</Link>
<Link className="NavLink" to="/Setup" activeStyle={{ color: '#69b3e7' }}>
Setup
</Link>
<Link className="NavLink" to="/Egress" activeStyle={{ color: '#69b3e7' }}>
Egress
</Link>
<Link className="NavLink" to="/Nav" activeStyle={{ color: '#69b3e7' }}>
Nav
</Link>
<Link className="NavLink" to="/Equipment" activeStyle={{ color: '#69b3e7' }}>
Equipment
</Link>
<Link className="NavLink" to="/Rocks" activeStyle={{ color: '#69b3e7' }}>
Rocks
</Link>
<Link className="NavLink" to="/Rover" activeStyle={{ color: '#69b3e7' }}>
Rover
</Link>
<Link className="NavLink" to="/Ingress" activeStyle={{ color: '#69b3e7' }}>
Ingress
</Link>
<button className="warning-btn" onClick={openModal}>Show Warning</button>
{showModal && <WarningModal closeModal={closeModal} isVisible={isVisible} />}
const interval = setInterval(fetchWarnings, 3000); // Fetch warnings every 3 seconds
return () => clearInterval(interval);
}, []);

const closeModal = () => {
setIsVisible(false);
setTimeout(() => setShowModal(false), 500); // Wait for the fade-out transition to complete
};

const getProcedure = (errorType) => {
switch (errorType) {
case 'fan_error':
return (
<>
<p>Fan Error Detected!</p>
<ol>
<li>Swap FAN switch to secondary position</li>
<li>Relay FAN position switch to LMCC</li>
<li>Begin navigation back to airlock</li>
</ol>
</>
);
case 'oxy_error':
return (
<>
<p>Oxygen Error Detected!</p>
<ol>
<li>Swap O2 switch to secondary position</li>
<li>Relay O2 position switch to LMCC</li>
<li>Begin navigation back to airlock</li>
</ol>
</>
);
case 'pump_error':
return (
<>
<p>Abort Procedure Detected!</p>
<ol>
<li>Relay abort mission and return to airlock command to EVs</li>
</ol>
</>
);
default:
return null;
}
};

return (
<nav className="Navbar">
<div className="NavMenu">
<img className="img" src={require("./../assets/Images/logo.jpg")} alt="Logo"/>
<h1 id="title">CUITS LMCC 2024</h1>
<Link className="NavLink" to="/Constant" activeStyle={{ color: '#69b3e7' }}>
Constant
</Link>
<Link className="NavLink" to="/Setup" activeStyle={{ color: '#69b3e7' }}>
Setup
</Link>
<Link className="NavLink" to="/Egress" activeStyle={{ color: '#69b3e7' }}>
Egress
</Link>
<Link className="NavLink" to="/Nav" activeStyle={{ color: '#69b3e7' }}>
Nav
</Link>
<Link className="NavLink" to="/Equipment" activeStyle={{ color: '#69b3e7' }}>
Equipment
</Link>
<Link className="NavLink" to="/Rocks" activeStyle={{ color: '#69b3e7' }}>
Rocks
</Link>
<Link className="NavLink" to="/Rover" activeStyle={{ color: '#69b3e7' }}>
Rover
</Link>
<Link className="NavLink" to="/Ingress" activeStyle={{ color: '#69b3e7' }}>
Ingress
</Link>
{showModal && (
<div className={`warning ${isVisible ? '' : 'hidden'}`}>
<div className="warning-modal-content">
{warnings.map((errorType) => (
<div key={errorType}>
{getProcedure(errorType)}
</div>
))}
<button className="warning-acknowledge" onClick={closeModal}>
I Acknowledge
</button>
</div>
</nav>
);
</div>
)}
</div>
</nav>
);
};

export default Navbar;
23 changes: 20 additions & 3 deletions src/pages/constant/EVData.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
import React from 'react';
import React, { useEffect, useState } from 'react';
import { useGlobal } from '../../components/GlobalContext';
import './constant.css'; // Import CSS file for styling

const EVData = ({ evNumber }) => {
const { allData, error } = useGlobal();
const { error } = useGlobal();
const [allData, setAllData] = useState(null);

useEffect(() => {
const fetchData = async () => {
try {
const response = await fetch('http://localhost:8000/get_telemetry_data');
const data = await response.json();
setAllData(data);
} catch (error) {
console.error('Error fetching data:', error);
}
};

fetchData();
const interval = setInterval(fetchData, 1000); // Fetch data every second
return () => clearInterval(interval); // Clear interval on component unmount
}, []);

if (error) return <div>Error: {error}</div>;
if (!allData.telemetry || !allData.telemetry.telemetry) return <div>Loading...</div>;
if (!allData || !allData.telemetry || !allData.telemetry.telemetry) return <div>Loading...</div>;

const evaData = allData.telemetry.telemetry[`eva${evNumber}`];

Expand Down
2 changes: 1 addition & 1 deletion src/pages/constant/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function Constant() {
};

return (
<GlobalProvider>
<GlobalProvider value={{ telemetryData, hasError }}>
<div className="pagecontainer" id="constantpage">
{telemetryData && !hasError && (
<TopBar
Expand Down
4 changes: 1 addition & 3 deletions src/pages/focus/rover.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ const RoverCamContainer = styled.div`
padding-bottom: 30px;
padding-top: 30px;
`;
const StreamContainer = styled.div`
padding-bottom: 30px;
`;

const MapContainer = styled.div`
flex: 1;
display: flex;
Expand Down
Loading

0 comments on commit 776b999

Please sign in to comment.