From dc1e568a96d75dc23c36b1de7b8bd80be379009b Mon Sep 17 00:00:00 2001 From: Cole Deck Date: Wed, 27 Mar 2024 20:33:21 -0500 Subject: [PATCH] Add basic cable_map implementation --- compose-search-only.yml | 13 ++++ run.py | 163 +++++++++++++++++++++------------------- search.py | 2 +- 3 files changed, 101 insertions(+), 77 deletions(-) create mode 100644 compose-search-only.yml diff --git a/compose-search-only.yml b/compose-search-only.yml new file mode 100644 index 0000000..5106c70 --- /dev/null +++ b/compose-search-only.yml @@ -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: \ No newline at end of file diff --git a/run.py b/run.py index 9e0f95c..fa42039 100755 --- a/run.py +++ b/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 diff --git a/search.py b/search.py index c4e8c4c..7b5201c 100644 --- a/search.py +++ b/search.py @@ -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