-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
47 lines (40 loc) · 1.69 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import ctypes
import pathlib
#sudo uvicorn main:app --host 0.0.0.0 --port 80 --ssl-keyfile=/etc/letsencrypt/live/spacequest.site/privkey.pem --ssl-certfile=/etc/letsencrypt/live/spacequest.site/fullchain.pemscre
#ssh [email protected]
app = FastAPI()
origins = [
"http://localhost",
"https://localhost:10888",
"https://aprilquest.rogachev-a-v.now.sh"
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
class commonSolution(ctypes.Structure):
_fields_ = [("resultSecondStep", ctypes.c_bool),
("isSolution", ctypes.c_bool ),
("hTurnOnEngineKm", ctypes.c_double),
("engineForceNewtons", ctypes.c_double),
("spacecraftMass", ctypes.c_double),
("deltaT2Sec", ctypes.c_double),
("V2MSec", ctypes.c_double),
("fuelCostKg", ctypes.c_double)]
libname = pathlib.Path().absolute() / "libspacecraft.so"
c_lib = ctypes.CDLL(libname)
c_lib.CommonCalculations.restype = commonSolution
@app.get("/")
async def root():
return {"message": 'API обвязки С++'}
@app.get("/space/{H}/{F}")
async def space(H : float, F: float):
answer = c_lib.CommonCalculations(ctypes.c_double(H), ctypes.c_double(F))
return {"resultSecondStep": answer.resultSecondStep, "isSolution": answer.isSolution,
"hTurnOnEngineKm": answer.hTurnOnEngineKm, "engineForceNewtons": answer.engineForceNewtons,
"spacecraftMass": answer.spacecraftMass, "deltaT2Sec": answer.deltaT2Sec, "V2MSec": answer.V2MSec, "fuelCostKg": answer.fuelCostKg}