Add basic cable_map implementation
This commit is contained in:
parent
1ec6d92cfa
commit
dc1e568a96
13
compose-search-only.yml
Normal file
13
compose-search-only.yml
Normal file
@ -0,0 +1,13 @@
|
||||
services:
|
||||
meilisearch:
|
||||
image: "getmeili/meilisearch:v1.6.2"
|
||||
ports:
|
||||
- "7700:7700"
|
||||
environment:
|
||||
MEILI_MASTER_KEY: fluffybunnyrabbit
|
||||
MEILI_NO_ANALYTICS: true
|
||||
volumes:
|
||||
- "meili_data:/meili_data"
|
||||
|
||||
volumes:
|
||||
meili_data:
|
163
run.py
163
run.py
@ -97,7 +97,7 @@ def send_data(type, call, data, client_id="*"):
|
||||
out["data"] = data
|
||||
to_server_queue.put((client_id, json.dumps(out)))
|
||||
|
||||
def start_server_socket():
|
||||
def start_server_socket(cable_list):
|
||||
global jbs
|
||||
"""app = Flask(__name__)
|
||||
|
||||
@ -146,80 +146,90 @@ def start_server_socket():
|
||||
# if we get here, we have a "valid" data packet
|
||||
data = decoded["data"]
|
||||
call = decoded["call"]
|
||||
match decoded["type"]:
|
||||
case "log":
|
||||
fprint("log message")
|
||||
if call == "send":
|
||||
fprint("webapp: " + str(data), sendqueue=to_server_queue)
|
||||
elif call == "request":
|
||||
fprint("")
|
||||
case "cable_map":
|
||||
fprint("cable_map message")
|
||||
if call == "send":
|
||||
fprint("")
|
||||
elif call == "request":
|
||||
fprint("")
|
||||
case "ping":
|
||||
fprint("Pong!!!")
|
||||
# Lucas' notes
|
||||
# Add a ping pong :) response/handler
|
||||
# Add a get cable response/handler
|
||||
# this will tell the robot arm to move
|
||||
# Call for turning off everything
|
||||
# TODO Helper for converting Python Dictionaries to JSON
|
||||
# make function: pythonData --> { { "type": "...", "call": "...", "data": pythonData } }
|
||||
|
||||
# to send: to_server_queue.put(("*", "JSON STRING HERE")) # replace * with UUID of client to send to one specific location
|
||||
|
||||
case "cable_details":
|
||||
fprint("cable_details message")
|
||||
if call == "send":
|
||||
fprint("")
|
||||
elif call == "request":
|
||||
fprint("")
|
||||
dataout = dict()
|
||||
dataout["cables"] = list()
|
||||
print(data)
|
||||
if "part_number" in data:
|
||||
for part in data["part_number"]:
|
||||
#print(part)
|
||||
#print(jbs.get_partnum(part))
|
||||
dataout["cables"].append(jbs.get_partnum(part)["fullspecs"])
|
||||
if "position" in data:
|
||||
for pos in data["position"]:
|
||||
#print(pos)
|
||||
#print(jbs.get_position(str(pos)))
|
||||
dataout["cables"].append(jbs.get_position(str(pos))["fullspecs"])
|
||||
send_data(decoded["type"], "send", dataout, client_id)
|
||||
|
||||
case "cable_search":
|
||||
fprint("cable_search message")
|
||||
if call == "send":
|
||||
fprint("")
|
||||
elif call == "request":
|
||||
fprint("")
|
||||
case "keyboard":
|
||||
fprint("keyboard message")
|
||||
if call == "send":
|
||||
fprint("")
|
||||
elif call == "request":
|
||||
fprint("")
|
||||
if data["enabled"] == True:
|
||||
# todo : send this to client
|
||||
p = Process(target=run_cmd, args=("./keyboard-up.ps1",))
|
||||
p.start()
|
||||
elif data["enabled"] == False:
|
||||
p = Process(target=run_cmd, args=("./keyboard-down.ps1",))
|
||||
p.start()
|
||||
case "machine_settings":
|
||||
fprint("machine_settings message")
|
||||
if call == "send":
|
||||
fprint("")
|
||||
elif call == "request":
|
||||
fprint("")
|
||||
case _:
|
||||
fprint("Unknown/unimplemented data type: " + decoded["type"])
|
||||
try:
|
||||
match decoded["type"]:
|
||||
case "log":
|
||||
fprint("log message")
|
||||
if call == "send":
|
||||
fprint("webapp: " + str(data), sendqueue=to_server_queue)
|
||||
elif call == "request":
|
||||
pass
|
||||
case "cable_map":
|
||||
fprint("cable_map message")
|
||||
if call == "send":
|
||||
pass
|
||||
elif call == "request":
|
||||
tmp = list()
|
||||
for idx in range(len(cable_list)):
|
||||
if cable_list[idx] is not False:
|
||||
tmp1 = {"part_number": cable_list[idx], "position": idx, "name": cable_list[idx], "brand": "Belden", "description": "Blah", "short_description": "Bla"}
|
||||
tmp.append(tmp1)
|
||||
out = {"map": tmp}
|
||||
fprint(out)
|
||||
send_data(decoded["type"], "send", out, client_id)
|
||||
|
||||
case "ping":
|
||||
fprint("Pong!!!")
|
||||
# Lucas' notes
|
||||
# Add a ping pong :) response/handler
|
||||
# Add a get cable response/handler
|
||||
# this will tell the robot arm to move
|
||||
# Call for turning off everything
|
||||
# TODO Helper for converting Python Dictionaries to JSON
|
||||
# make function: pythonData --> { { "type": "...", "call": "...", "data": pythonData } }
|
||||
|
||||
# to send: to_server_queue.put(("*", "JSON STRING HERE")) # replace * with UUID of client to send to one specific location
|
||||
|
||||
case "cable_details":
|
||||
fprint("cable_details message")
|
||||
if call == "send":
|
||||
pass
|
||||
elif call == "request":
|
||||
dataout = dict()
|
||||
dataout["cables"] = list()
|
||||
print(data)
|
||||
if "part_number" in data:
|
||||
for part in data["part_number"]:
|
||||
#print(part)
|
||||
#print(jbs.get_partnum(part))
|
||||
dataout["cables"].append(jbs.get_partnum(part)["fullspecs"])
|
||||
if "position" in data:
|
||||
for pos in data["position"]:
|
||||
#print(pos)
|
||||
#print(jbs.get_position(str(pos)))
|
||||
dataout["cables"].append(jbs.get_position(str(pos))["fullspecs"])
|
||||
send_data(decoded["type"], "send", dataout, client_id)
|
||||
|
||||
case "cable_search":
|
||||
fprint("cable_search message")
|
||||
if call == "send":
|
||||
pass
|
||||
elif call == "request":
|
||||
pass
|
||||
case "keyboard":
|
||||
fprint("keyboard message")
|
||||
if call == "send":
|
||||
pass
|
||||
elif call == "request":
|
||||
pass
|
||||
if data["enabled"] == True:
|
||||
# todo : send this to client
|
||||
p = Process(target=run_cmd, args=("./keyboard-up.ps1",))
|
||||
p.start()
|
||||
elif data["enabled"] == False:
|
||||
p = Process(target=run_cmd, args=("./keyboard-down.ps1",))
|
||||
p.start()
|
||||
case "machine_settings":
|
||||
fprint("machine_settings message")
|
||||
if call == "send":
|
||||
pass
|
||||
elif call == "request":
|
||||
pass
|
||||
case _:
|
||||
fprint("Unknown/unimplemented data type: " + decoded["type"])
|
||||
except Exception as e:
|
||||
fprint(traceback.format_exc())
|
||||
fprint(e)
|
||||
|
||||
|
||||
|
||||
@ -278,8 +288,7 @@ def setup_server(pool):
|
||||
pool.apply_async(ledsys.init, callback=led_start_callback)
|
||||
#pool.apply_async(sensor_control.init, callback=sensor_start_callback)
|
||||
jbs = JukeboxSearch()
|
||||
serverproc = Process(target=start_server_socket)
|
||||
serverproc.start()
|
||||
|
||||
|
||||
|
||||
if led_ready is False:
|
||||
@ -445,6 +454,8 @@ def mainloop_server(pool):
|
||||
|
||||
fprint("All cables added to database.")
|
||||
mode = "Idle"
|
||||
serverproc = Process(target=start_server_socket, args=(cable_list,))
|
||||
serverproc.start()
|
||||
else:
|
||||
# TODO: manual input
|
||||
pass
|
||||
|
@ -6,7 +6,7 @@ from meilisearch.task import TaskInfo
|
||||
from meilisearch.errors import MeilisearchApiError
|
||||
import time
|
||||
|
||||
DEFAULT_URL = "http://meilisearch:7700"
|
||||
DEFAULT_URL = "http://127.0.0.1:7700"
|
||||
DEFAULT_APIKEY = "fluffybunnyrabbit" # I WOULD RECOMMEND SOMETHING MORE SECURE
|
||||
DEFAULT_INDEX = "cables"
|
||||
DEFAULT_FILTERABLE_ATTRS = ["partnum", "uuid", "position"] # default filterable attributes
|
||||
|
Loading…
x
Reference in New Issue
Block a user