-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAnalysis_Server.py
More file actions
50 lines (45 loc) · 1.72 KB
/
Copy pathAnalysis_Server.py
File metadata and controls
50 lines (45 loc) · 1.72 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
import argparse
import sys
import json
import ASDP_Core as asdp
def run_server(url):
# Start the ASDP analysis server with the given URL.
status, server = asdp.JSONStringSender.Create(url)
if status != asdp.Status.OKAY:
print("Failed to start server:", asdp.ErrorMessage(status))
# Here is where the analysis would run, producing JSON objects to send.
# They must match the ASDP specification.
# Here we produce some examples, one second apart.
message = {
"camID": 1,
"Time": [0, 0],
"Name": "MyObjectName",
"Loc": [0.5, 0.5], # Center of the image
"Class": [{"Type": "ASDP_drone", "Chance": 0.9, "IFF": "foe"}]
}
for t in range(5):
message["Time"] = [t, 0]
json_message = json.dumps(message)
status = server.Send(json_message)
if status != asdp.Status.OKAY:
print("Failed to send message:", asdp.ErrorMessage(status))
else:
print("Sent message at time", t)
def parse_args():
parser = argparse.ArgumentParser(
description="Run the ASDP analysis server. Provide a single URL argument for the server transport."
)
parser.add_argument(
"url",
metavar="URL",
help="URL to use for the server (e.g. tcp://localhost:10103, file://deleteme.json)"
)
return parser.parse_args()
# Parse when executed as script and expose SERVER_URL for the rest of the module
if __name__ == "__main__" or "pytest" not in sys.modules:
args = parse_args()
SERVER_URL = args.url
run_server(SERVER_URL)
else:
# When imported as a module, default to None; callers can pass URL explicitly.
SERVER_URL = None