-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain_vr.py
More file actions
109 lines (97 loc) · 3.54 KB
/
Copy pathmain_vr.py
File metadata and controls
109 lines (97 loc) · 3.54 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# !/usr/bin/env python3
# executable - set up paths for import
import os
import sys
# to setup import paths add project root dir to sys.path (with baseVR dir in it)
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))
from baseVR.base_functionality import init_import_paths
init_import_paths()
# all of CoreRatVR can see subdirs 'backend' and 'SHM'
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'backend'))
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'SHM'))
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import uvicorn
from Parameters import Parameters
from backend_proc_endpoints import attach_proc_endpoints
from backend_shm_endpoints import attach_shm_endpoints
from backend_general_endpoints import attach_general_endpoints
from backend_general_endpoints import attach_UI_endpoint
from backend_streamer_endpoints import attach_stream_endpoints
from backend_inspect_endpoints import attach_inspect_endpoints
async def lifespan(app: FastAPI):
print("Initilizing server state, constructing parameters...")
P = Parameters()
app.state.state = {
"procs": {
"por2shm2por_sim": 0,
"por2shm2por": 0,
"log_portenta": 0,
"stream_portenta": 0,
"facecam2shm": 0,
"ttl2cam2shm": 0,
"ttl3cam2shm": 0,
"ttl4cam2shm": 0,
"bodycam2shm": 0,
"stream_facecam": 0,
"log_facecam": 0,
"log_ttl2cam": 0,
"log_ttl3cam": 0,
"log_ttl4cam": 0,
"log_bodycam": 0,
"stream_bodycam": 0,
"log_unity": 0,
"log_unitycam": 0,
"log_ephys": 0,
"unity": 0,
"mxserver": 0,
"scope": 0,
"process_session": 0,
},
"shm": {
P.SHM_NAME_TERM_FLAG: False,
P.SHM_NAME_PARADIGM_RUNNING_FLAG: False,
P.SHM_NAME_BALLVELOCITY: False,
P.SHM_NAME_PORTENTA_OUTPUT: False,
P.SHM_NAME_PORTENTA_INPUT: False,
P.SHM_NAME_UNITY_OUTPUT: False,
P.SHM_NAME_UNITY_INPUT: False,
P.SHM_NAME_FACE_CAM: False,
P.SHM_NAME_TTL2_CAM: False,
P.SHM_NAME_TTL3_CAM: False,
P.SHM_NAME_TTL4_CAM: False,
P.SHM_NAME_BODY_CAM: False,
P.SHM_NAME_UNITY_CAM: False,
},
"initiated": False,
"initiatedInspect": False,
"paradigmRunning": False,
"termflag_shm_interface": None,
"unityinput_shm_interface": None,
"paradigm_running_shm_interface": None,
}
yield # application runs (function pauses here)
print("Experiment Server shutting down.")
def main():
app = FastAPI(lifespan=lifespan)
origins = [
"http://localhost:8000", # Uncomment this if your FastAPI server is running on localhost
"http://localhost:5173", # Allow the Svelte dev server access
# "http://localhost:tld", # Replace "tld" with the top-level domain where your app will be hosted
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
attach_general_endpoints(app)
attach_proc_endpoints(app)
attach_shm_endpoints(app)
attach_stream_endpoints(app)
attach_inspect_endpoints(app)
attach_UI_endpoint(app)
uvicorn.run(app, host="127.0.0.1", port=8000)
if __name__ == "__main__":
main()