Skip to content

Commit

Permalink
Changes to the api and file paths
Browse files Browse the repository at this point in the history
  • Loading branch information
adenjonah committed May 16, 2024
1 parent 3052703 commit 5c0e4b3
Show file tree
Hide file tree
Showing 57 changed files with 189 additions and 951 deletions.
Binary file added server/Images/DCU_Above.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/Images/DCU_Front 2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/Images/DCU_Front.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/Images/Egress1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/Images/Egress2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/Images/Egress3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/Images/Egress4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/Images/Ingress1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/Images/Ingress2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/Images/Ingress3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/Images/Ingress4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/Images/NoVid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/Images/RoverGif.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/Images/ThermalGif 2.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/Images/ThermalGif.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/Images/dog1 2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/Images/dog1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/Images/dog2 2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/Images/dog2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/Images/dog3 2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/Images/dog3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/Images/logo 2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/Images/logo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/Images/rockyard_map_geo.tif
Binary file not shown.
Binary file added server/Images/supplywaste 2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/Images/supplywaste.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 48 additions & 11 deletions server/initdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@

# Paths to the JSON files
DATA_FILE = './server/json_databases/tss_data.json'
PINS_FILE = './server/json_databases/created_pins.json'
PINS_FILE = './server/json_databases/map_pins.json'
BOUNDARY_LINES_FILE = './server/json_databases/boundary_lines.json'
CONFIG_FILE = './server/json_databases/config_keys.json'
INGRESS_FILE = './server/json_databases/ingress_procedures.json'
EGRESS_FILE = './server/json_databases/egress_procedures.json'
INGRESS_EGRESS_FILE = './server/json_databases/ingress_egress_procedures.json'
EQUIPMENT_REPAIR_FILE = './server/json_databases/equipment_repair.json'
ALERTS_FILE = './server/json_databases/alerts.json'
MESSAGES_FILE = './server/json_databases/messages.json'
Expand Down Expand Up @@ -2127,12 +2126,51 @@
"telemetry": {}
}

DEFAULT_INGRESS_PROCEDURES_DATA = {

}

DEFAULT_EGRESS_PROCEDURES_DATA = {

DEFAULT_INGRESS_EGRESS_PROCEDURES_DATA = {
"egress_procedure_list": [
{
"name": "Connect UIA to DCU and start Depress",
"description": "UIA and DCU 1. EV1 and EV2 connect UIA and DCU umbilical\nUIA 2. EV-1, EV-2 PWR - ON\nBOTH DCU 3. BATT - UMB\nUIA 4. DEPRESS PUMP PWR - ON",
"image": "../Images/Egress1.jpg"
},
{
"name": "Prep O2 Tanks",
"description": "UIA 1. OXYGEN O2 VENT - OPEN\nHMD 2. Wait until both Primary and Secondary OXY tanks are < 10psi\nUIA 3. OXYGEN O2 VENT - CLOSE\nBOTH DCU 4. OXY - PRI\nUIA 5. OXYGEN EMU-1, EMU-2 - OPEN\nHMD 6. Wait until EV1 and EV2 Primary O2 tanks > 3000 psi\nUIA 7. OXYGEN EMU-1, EMU-2 - CLOSE\nBOTH DCU 8. OXY - SEC\nUIA 9. OXYGEN EMU-1, EMU-2 - OPEN\nHMD 10. Wait until EV1 and EV2 Secondary O2 tanks > 3000 psi\nUIA 11. OXYGEN EMU-1, EMU-2 - CLOSE\nBOTH DCU 12. OXY - PRI",
"image": "../Images/Egress2.jpg"
},
{
"name": "Prep Water Tanks",
"description": "BOTH DCU 1. PUMP - OPEN\nUIA 2. EV-1, EV-2 WASTE WATER - OPEN\nHMD 3. Wait until water EV1 and EV2 Coolant tank is < 5%\nUIA 4. EV-1, EV-2 WASTE WATER - CLOSE\nUIA 5. EV-1, EV-2 SUPPLY WATER - OPEN\nHMD 6. Wait until water EV1 and EV2 Coolant tank is > 95%\nUIA 7. EV-1, EV-2 SUPPLY WATER - CLOSE\nBOTH DCU 8. PUMP - CLOSESWITCH: UIA OXY VENT -> ON (vents the content of the primary tank)",
"image": "../Images/Egress3.jpg"
},
{
"name": "END Depress, Check Switches and Disconnect",
"description": "HMD 1. Wait until SUIT P, O2 P = 4\nUIA 2. DEPRESS PUMP PWR - OFF\nBOTH DCU 3. BATT - LOCAL\nUIA 9. EV-1, EV-2 PWR - OFF\nBOTH DCU 4. Verify OXY - PRI\nBOTH DCU 5. Verify COMMS - A\nBOTH DCU 6. Verify FAN - PRI\nBOTH DCU 7. Verify PUMP - CLOSE\nBOTH DCU 8. Verify CO2 - A\nUIA and DCU 9. EV1 and EV2 disconnect UIA and DCU umbilical",
"image": "../Images/Egress4.jpg"
}
],
"ingress_procedure_list": [
{
"name": "Connect UIA to DCU and start Depress",
"description": "UIA and DCU \t1. EV1 and EV2 connect UIA and DCU umbilical \nUIA \t2. EV-1, EV-2 EMU PWR - ON\nBOTH DCU \t3. BATT - UMB",
"image": "../Images/Ingress1.jpg"
},
{
"name": "Vent O2 Tanks",
"description": "UIA 1. OXYGEN O2 VENT - OPEN\nHMD 2. Wait until both Primary and Secondary OXY tanks are < 10psi\nUIA 3. OXYGEN O2 VENT - CLOSE",
"image": "../Images/Ingress2.jpg"
},
{
"name": "Empty Water Tanks",
"description": "BOTH DCU 1. PUMP - OPEN\nUIA 2. EV-1, EV-2 WASTE WATER - OPEN\nHMD 3. Wait until water EV1 and EV2 Coolant tank is < 5%\nUIA 4. EV-1, EV-2 WASTE WATER - CLOSE",
"image": "../Images/Ingress3.jpg"
},
{
"name": "Disconnect UIA from DCU",
"description": "UIA 1. EV-1, EV-2 EMU PWR - OFF\nDCU 2. EV1 and EV2 disconnect umbilical",
"image": "../Images/Ingress4.jpg"
}
]
}

DEFAULT_EQUIPMENT_PROCEDURES_DATA = {
Expand Down Expand Up @@ -2320,8 +2358,7 @@ def initialize_database_files():
initialize_file(PINS_FILE, DEFAULT_PINS_DATA)
initialize_file(BOUNDARY_LINES_FILE, DEFAULT_BOUNDARY_LINES_DATA)
initialize_file(DATA_FILE, DEFAULT_DATA_FILE_CONTENT)
initialize_file(INGRESS_FILE, DEFAULT_INGRESS_PROCEDURES_DATA)
initialize_file(EGRESS_FILE, DEFAULT_EGRESS_PROCEDURES_DATA)
initialize_file(INGRESS_EGRESS_FILE, DEFAULT_INGRESS_EGRESS_PROCEDURES_DATA)
initialize_file(EQUIPMENT_REPAIR_FILE, DEFAULT_EQUIPMENT_PROCEDURES_DATA)
initialize_file(ALERTS_FILE, DEFAULT_ALERTS_DATA)
initialize_file(MESSAGES_FILE, DEFAULT_MESSAGES_DATA)
Expand Down
1 change: 1 addition & 0 deletions server/json_databases/ingress_egress_procedures.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"egress_procedure_list": [{"name": "Connect UIA to DCU and start Depress", "description": "UIA and DCU 1. EV1 and EV2 connect UIA and DCU umbilical\nUIA 2. EV-1, EV-2 PWR - ON\nBOTH DCU 3. BATT - UMB\nUIA 4. DEPRESS PUMP PWR - ON", "image": "../Images/Egress1.jpg"}, {"name": "Prep O2 Tanks", "description": "UIA 1. OXYGEN O2 VENT - OPEN\nHMD 2. Wait until both Primary and Secondary OXY tanks are < 10psi\nUIA 3. OXYGEN O2 VENT - CLOSE\nBOTH DCU 4. OXY - PRI\nUIA 5. OXYGEN EMU-1, EMU-2 - OPEN\nHMD 6. Wait until EV1 and EV2 Primary O2 tanks > 3000 psi\nUIA 7. OXYGEN EMU-1, EMU-2 - CLOSE\nBOTH DCU 8. OXY - SEC\nUIA 9. OXYGEN EMU-1, EMU-2 - OPEN\nHMD 10. Wait until EV1 and EV2 Secondary O2 tanks > 3000 psi\nUIA 11. OXYGEN EMU-1, EMU-2 - CLOSE\nBOTH DCU 12. OXY - PRI", "image": "../Images/Egress2.jpg"}, {"name": "Prep Water Tanks", "description": "BOTH DCU 1. PUMP - OPEN\nUIA 2. EV-1, EV-2 WASTE WATER - OPEN\nHMD 3. Wait until water EV1 and EV2 Coolant tank is < 5%\nUIA 4. EV-1, EV-2 WASTE WATER - CLOSE\nUIA 5. EV-1, EV-2 SUPPLY WATER - OPEN\nHMD 6. Wait until water EV1 and EV2 Coolant tank is > 95%\nUIA 7. EV-1, EV-2 SUPPLY WATER - CLOSE\nBOTH DCU 8. PUMP - CLOSESWITCH: UIA OXY VENT -> ON (vents the content of the primary tank)", "image": "../Images/Egress3.jpg"}, {"name": "END Depress, Check Switches and Disconnect", "description": "HMD 1. Wait until SUIT P, O2 P = 4\nUIA 2. DEPRESS PUMP PWR - OFF\nBOTH DCU 3. BATT - LOCAL\nUIA 9. EV-1, EV-2 PWR - OFF\nBOTH DCU 4. Verify OXY - PRI\nBOTH DCU 5. Verify COMMS - A\nBOTH DCU 6. Verify FAN - PRI\nBOTH DCU 7. Verify PUMP - CLOSE\nBOTH DCU 8. Verify CO2 - A\nUIA and DCU 9. EV1 and EV2 disconnect UIA and DCU umbilical", "image": "../Images/Egress4.jpg"}], "ingress_procedure_list": [{"name": "Connect UIA to DCU and start Depress", "description": "UIA and DCU \t1. EV1 and EV2 connect UIA and DCU umbilical \nUIA \t2. EV-1, EV-2 EMU PWR - ON\nBOTH DCU \t3. BATT - UMB", "image": "../Images/Ingress1.jpg"}, {"name": "Vent O2 Tanks", "description": "UIA 1. OXYGEN O2 VENT - OPEN\nHMD 2. Wait until both Primary and Secondary OXY tanks are < 10psi\nUIA 3. OXYGEN O2 VENT - CLOSE", "image": "../Images/Ingress2.jpg"}, {"name": "Empty Water Tanks", "description": "BOTH DCU 1. PUMP - OPEN\nUIA 2. EV-1, EV-2 WASTE WATER - OPEN\nHMD 3. Wait until water EV1 and EV2 Coolant tank is < 5%\nUIA 4. EV-1, EV-2 WASTE WATER - CLOSE", "image": "../Images/Ingress3.jpg"}, {"name": "Disconnect UIA from DCU", "description": "UIA 1. EV-1, EV-2 EMU PWR - OFF\nDCU 2. EV1 and EV2 disconnect umbilical", "image": "../Images/Ingress4.jpg"}]}
1 change: 0 additions & 1 deletion server/json_databases/ingress_procedures.json

This file was deleted.

100 changes: 43 additions & 57 deletions server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@
app = FastAPI()

DATA_FILE = './server/json_databases/tss_data.json'
PINS_FILE = './server/json_databases/created_pins.json'
PINS_FILE = './server/json_databases/map_pins.json'
BOUNDARY_LINES_FILE = './server/json_databases/boundary_lines.json'
CONFIG_FILE = './server/json_databases/config_keys.json'
INGRESS_FILE = './server/json_databases/ingress_procedures.json'
EGRESS_FILE = './server/json_databases/egress_procedures.json'
INGRESS_EGRESS_FILE = './server/json_databases/ingress_egress_procedures.json'
EQUIPMENT_REPAIR_FILE = './server/json_databases/equipment_repair.json'
ALERTS_FILE = './server/json_databases/alerts.json'
MESSAGES_FILE = './server/json_databases/messages.json'

# Load config to get TSS_IP
# TSS Connection
if os.path.exists(CONFIG_FILE):
with open(CONFIG_FILE, 'r') as f:
config_data = json.load(f)
Expand All @@ -40,6 +39,7 @@
allow_headers=["*"],
)

# Get Json
async def fetch_json(url: str):
async with httpx.AsyncClient() as client:
response = await client.get(url)
Expand All @@ -55,25 +55,6 @@ async def startup_event():
task = asyncio.create_task(periodic_fetch_and_store())
await asyncio.sleep(1)

@app.put("/update_config")
async def update_config(request: Request):
new_config = await request.json()
with open(CONFIG_FILE, 'r') as f:
config_data = json.load(f)

config_data.update(new_config)

with open(CONFIG_FILE, 'w') as f:
json.dump(config_data, f)

return {"message": "Config updated successfully"}

@app.get("/config")
async def get_config():
with open(CONFIG_FILE, 'r') as f:
config_data = json.load(f)
return config_data

async def periodic_fetch_and_store():
eva_url = f"http://{tss_ip}/json_data/teams/0/EVA.json"
telemetry_url = f"http://{tss_ip}/json_data/teams/0/TELEMETRY.json"
Expand All @@ -96,7 +77,29 @@ async def periodic_fetch_and_store():
logger.error(f"An error occurred during periodic fetch: {e}")
await asyncio.sleep(1)

@app.get("/data")
# Save new IP or Key
@app.put("/update_config")
async def update_config(request: Request):
new_config = await request.json()
with open(CONFIG_FILE, 'r') as f:
config_data = json.load(f)

config_data.update(new_config)

with open(CONFIG_FILE, 'w') as f:
json.dump(config_data, f)

return {"message": "Config updated successfully"}

# Return keys and IPs
@app.get("/get_config")
async def get_config():
with open(CONFIG_FILE, 'r') as f:
config_data = json.load(f)
return config_data

# Get Telemetry data
@app.get("/get_telemetry_data")
async def read_data():
try:
with open(DATA_FILE, 'r') as f:
Expand All @@ -105,12 +108,7 @@ async def read_data():
except FileNotFoundError:
return {"error": "Data file not found. Please check back later."}

@app.get("/get_mapbox_key")
async def get_mapbox_key():
with open(CONFIG_FILE, 'r') as f:
config = json.load(f)
return {"MAPBOX_KEY": config["MAPBOX_KEY"]}

# 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 with httpx.AsyncClient() as client:
Expand Down Expand Up @@ -150,7 +148,7 @@ class Marker(BaseModel):
lat: float
lng: float

@app.get("/geojson")
@app.get("/get_geojson")
async def get_geojson():
geojson_data = {"type": "FeatureCollection", "features": []}

Expand Down Expand Up @@ -199,34 +197,15 @@ async def add_marker(marker: Marker):

return {"message": "Marker added successfully"}

@app.get("/json_data/{filename}")
async def get_general_json(filename: str):
url = f"http://{tss_ip}/json_data/{filename}"
return await fetch_json(url)

@app.get("/json_data/rocks/RockData.json")
async def get_rock_data():
url = f"http://{tss_ip}/json_data/rocks/RockData.json"
return await fetch_json(url)

@app.get("/json_data/teams/{team_number}/{filename}")
async def get_team_data(team_number: int, filename: str):
if not (0 <= team_number <= 10):
raise HTTPException(status_code=400, detail="Team number must be between 0 and 10")
url = f"http://{tss_ip}/json_data/teams/{team_number}/{filename}"
return await fetch_json(url)

def load_procedures():
if os.path.exists(EQUIPMENT_REPAIR_FILE):
with open(EQUIPMENT_REPAIR_FILE, 'r') as file:
return json.load(file)
else:
raise FileNotFoundError(f"{EQUIPMENT_REPAIR_FILE} not found")

@app.get("/procedure")
# Get sent ER Procedure (Used by HMD)
@app.get("/get_sent_procedure")
async def get_procedure(id: int):
try:
data = load_procedures()
if os.path.exists(EQUIPMENT_REPAIR_FILE):
with open(EQUIPMENT_REPAIR_FILE, 'r') as file:
data = json.load(file)
else:
raise FileNotFoundError(f"{EQUIPMENT_REPAIR_FILE} not found")
procedures = data.get("procedures", [])
except FileNotFoundError as e:
raise HTTPException(status_code=404, detail=str(e))
Expand All @@ -236,3 +215,10 @@ async def get_procedure(id: int):
return procedure
else:
raise HTTPException(status_code=404, detail="Procedure not found")

with open(INGRESS_EGRESS_FILE, 'r') as f:
procedures = json.load(f)

@app.get("/procedures")
def get_procedures():
return procedures
6 changes: 0 additions & 6 deletions src/assets/json_data/COMM.json

This file was deleted.

21 changes: 0 additions & 21 deletions src/assets/json_data/DCU.json

This file was deleted.

8 changes: 0 additions & 8 deletions src/assets/json_data/ERROR.json

This file was deleted.

15 changes: 0 additions & 15 deletions src/assets/json_data/IMU.json

This file was deleted.

8 changes: 0 additions & 8 deletions src/assets/json_data/ROVER.json

This file was deleted.

39 changes: 0 additions & 39 deletions src/assets/json_data/SPEC.json

This file was deleted.

17 changes: 0 additions & 17 deletions src/assets/json_data/TEAMS.json

This file was deleted.

15 changes: 0 additions & 15 deletions src/assets/json_data/UIA.json

This file was deleted.

Loading

0 comments on commit 5c0e4b3

Please sign in to comment.