From ad216f21fa5f8b8d0c0b202e3a7e734245b1dc72 Mon Sep 17 00:00:00 2001 From: Cole Deck Date: Tue, 26 Mar 2024 18:41:59 -0500 Subject: [PATCH 01/11] Implement cable_details call --- read_datasheet.py | 2 +- run.py | 186 ++++++++++++++++++++++++-------------------- search.py | 11 ++- websocket_test.html | 2 +- 4 files changed, 109 insertions(+), 92 deletions(-) diff --git a/read_datasheet.py b/read_datasheet.py index 757ab2a..0d89a59 100755 --- a/read_datasheet.py +++ b/read_datasheet.py @@ -301,7 +301,7 @@ def parse(filename, output_dir, partnum, dstype): output_table["id"] = id #output_table["position"] = id #output_table["brand"] = brand - output_table["fullspecs"] = tables + output_table["fullspecs"] = {"partnum": partnum, "id": id, **tables} output_table["searchspecs"] = {"partnum": partnum, **flatten(tables)} output_table["searchspecs"]["id"] = id diff --git a/run.py b/run.py index 10924c9..d1aec1c 100755 --- a/run.py +++ b/run.py @@ -90,7 +90,15 @@ def wait_for(val, name): while val is False: sleep(0.1) +def send_data(type, call, data, client_id="*"): + out = dict() + out["type"] = type + out["call"] = call + out["data"] = data + to_server_queue.put((client_id, json.dumps(out))) + def start_server_socket(): + global jbs """app = Flask(__name__) @app.route('/report_ip', methods=['POST']) @@ -122,92 +130,99 @@ def start_server_socket(): # Message handler try: decoded = json.loads(message) - if "type" not in decoded: - fprint("Missing \"type\" field.") - continue - if "call" not in decoded: - fprint("Missing \"call\" field.") - continue - if "data" not in decoded: - fprint("Missing \"data\" field.") - continue - - # 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("") - - 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"]) - - except: fprint("Non-JSON message recieved") continue + if "type" not in decoded: + fprint("Missing \"type\" field.") + continue + if "call" not in decoded: + fprint("Missing \"call\" field.") + continue + if "data" not in decoded: + fprint("Missing \"data\" field.") + continue + # 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"]) + + + + sleep(0.001) # Sleep to prevent tight loop @@ -262,6 +277,7 @@ def setup_server(pool): ledsys = LEDSystem() 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() @@ -293,7 +309,7 @@ def setup_server(pool): fprint("Arm initialized.", sendqueue=to_server_queue) - jbs = JukeboxSearch() + return True @@ -391,7 +407,7 @@ def mainloop_server(pool): "BLRA500P" ] cable_list = tmp - pool.apply_async(get_specs.get_multi, (tmp, 0.5), callback=cable_search_callback) + pool.apply_async(get_specs.get_multi, (tmp, 0.3), callback=cable_search_callback) mode = "Parsing" fprint("All cables scanned. Finding & parsing datasheets...") if mode == "Parsing": @@ -423,6 +439,8 @@ def mainloop_server(pool): specs = json.load(f) searchdata["fullspecs"] = specs jbs.add_document(searchdata) + #sleep(0.5) + #print(jbs.get_position("1")) fprint("All cables added to database.") mode = "Idle" diff --git a/search.py b/search.py index e031ce9..d7bb76b 100644 --- a/search.py +++ b/search.py @@ -70,11 +70,10 @@ class JukeboxSearch: :param filterables: List of all filterable attributes""" - existing_filterables = self.idxref.get_filterable_attributes() - if len(set(existing_filterables).difference(set(filterables))) > 0: - taskref = self.idxref.update_filterable_attributes(filterables) - - self.client.wait_for_task(taskref.index_uid) + #existing_filterables = self.idxref.get_filterable_attributes() + #if len(set(existing_filterables).difference(set(filterables))) > 0: + taskref = self.idxref.update_filterable_attributes(filterables) + #self.client.wait_for_task(taskref.index_uid) def search(self, query: str, filters: str = None): """Execute a search query on the Meilisearch index. @@ -95,7 +94,7 @@ class JukeboxSearch: :returns: A dict containing the results; If no results found, an empty dict.""" q = self.search("", filter) if q["estimatedTotalHits"] != 0: - return ["hits"][0] + return q["hits"][0] else: return dict() diff --git a/websocket_test.html b/websocket_test.html index c6489bc..ab65944 100644 --- a/websocket_test.html +++ b/websocket_test.html @@ -81,7 +81,7 @@ socket.send(message); console.log('Message sent', message); } - setInterval(ping, 1500); + //setInterval(ping, 1500); // setInterval(() => { // updateServiceStatus('serviceA', 'down'); From 19ce3285967be5d10394de27386716ed64471e29 Mon Sep 17 00:00:00 2001 From: Cole Deck Date: Wed, 27 Mar 2024 17:49:02 -0500 Subject: [PATCH 02/11] Correctly parse results from get_specs --- get_specs.py | 4 +++ run.py | 69 ++++++++++++++++++++++++++-------------------------- 2 files changed, 39 insertions(+), 34 deletions(-) diff --git a/get_specs.py b/get_specs.py index 455df59..4e183dd 100755 --- a/get_specs.py +++ b/get_specs.py @@ -344,9 +344,13 @@ def get_multi(partnums, delay=0.25, dir="cables/", cache=True, bar=None): fprint("Using cached hi-res part image for " + partnum) out = __use_cached_datasheet(partnum, path, output_dir, dstype) returnval = [partnum, dstype, False, out] + actualpartnums.append(returnval) return True for fullpartnum in partnums: + if fullpartnum is False: + actualpartnums.append(False) + continue if fullpartnum[0:2] == "BL": # catalog.belden.com entry partnum = fullpartnum[2:] dstype = "Belden" diff --git a/run.py b/run.py index d1aec1c..65b0ce4 100755 --- a/run.py +++ b/run.py @@ -182,13 +182,13 @@ def start_server_socket(): print(data) if "part_number" in data: for part in data["part_number"]: - print(part) - print(jbs.get_partnum(part)) + #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))) + #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) @@ -354,9 +354,12 @@ def mainloop_server(pool): elif camera_ready: fprint("Adding cable to list...") global scan_value - if scan_value.find("bldn.app/") > -1: + if scan_value is False: + cable_list.append(scan_value) + elif scan_value.find("bldn.app/") > -1: scan_value = scan_value[scan_value.find("bldn.app/")+9:] - cable_list.append((counter, scan_value)) + else: + cable_list.append(scan_value) fprint(scan_value) #pool.apply_async(arm.return cable, callback=arm_start_callback) arm_state = "RETURN" @@ -370,19 +373,8 @@ def mainloop_server(pool): pass else: # scanned everything - tmp = list() - for cable in cable_list: - tmp.append(cable[1]) - tmp = [ # Actual cables in Jukebox - - "AW86104CY", - "AW3050", - "AW6714", - "AW1172C", - "AWFIT-221-1_4", - "BLTF-1LF-006-RS5", "BLTF-SD9-006-RI5", "BLTT-SLG-024-HTN", @@ -404,9 +396,16 @@ def mainloop_server(pool): "BL8760", "BL6300UE", "BL6300FE", - "BLRA500P" + "BLRA500P", + "AW86104CY", + "AW3050", + "AW6714", + "AW1172C", + "AWFIT-221-1_4" ] - cable_list = tmp + while len(tmp) < 54: + tmp.append(False) # must have 54 entries + cable_list = tmp # remove for real demo pool.apply_async(get_specs.get_multi, (tmp, 0.3), callback=cable_search_callback) mode = "Parsing" fprint("All cables scanned. Finding & parsing datasheets...") @@ -419,26 +418,28 @@ def mainloop_server(pool): # done global parse_res success, partnums = parse_res - #partnums = list() - # debug - #success = True + for idx in range(len(partnums)): + if partnums[idx] is not False: + cable_list[idx] = partnums[idx][0].replace("/", "_") + else: + cable_list[idx] = False - #cable_list = list(range(len(partnums))) + print(partnums) if success: # easy mode fprint("All cables inventoried and parsed.") - for x in range(len(cable_list)): - #cable_list[x] = (cable_list[x][0], partnums[x]) - cable_list[x] = (x, cable_list[x]) fprint("Adding to database...") - for idx,partnum in cable_list: - with open("cables/" + partnum[2:] + "/search.json", "rb") as f: - searchdata = json.load(f) - searchdata["position"] = idx - with open("cables/" + partnum[2:] + "/specs.json", "rb") as f: - specs = json.load(f) - searchdata["fullspecs"] = specs - jbs.add_document(searchdata) + for idx in range(len(cable_list)): + partnum = cable_list[idx] + if partnum is not False: + with open("cables/" + partnum + "/search.json", "rb") as f: + searchdata = json.load(f) + searchdata["position"] = idx + with open("cables/" + partnum + "/specs.json", "rb") as f: + specs = json.load(f) + searchdata["fullspecs"] = specs + searchdata["fullspecs"]["position"] = idx + jbs.add_document(searchdata) #sleep(0.5) #print(jbs.get_position("1")) From efbda23c386aba3cfe8e375608eaf936cf69d2bc Mon Sep 17 00:00:00 2001 From: Cole Deck Date: Wed, 27 Mar 2024 18:53:50 -0500 Subject: [PATCH 03/11] Fix docker runtime support --- Dockerfile | 6 +++--- compose.yml | 12 ++++++++++++ run.py | 11 +++++++++-- search.py | 2 +- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index a465d74..5a0d059 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,11 +3,11 @@ FROM python:3.11-slim # Get runtime dependencies # glx for OpenCV, ghostscript for datasheet PDF rendering, zbar for barcode scanning, git for cloning repos RUN apt-get update && apt-get install -y libgl1-mesa-glx ghostscript libzbar0 git && apt-get clean && rm -rf /var/lib/apt/lists -COPY *.py *.yml *.sh *.txt *.html static templates ./ +COPY requirements.txt ./ #COPY config-server.yml config.yml RUN pip3 install -r requirements.txt - -CMD ["python3", "run.py"] +COPY *.py *.yml *.sh *.txt *.html static templates ./ +CMD ["sh", "-c", "python3 run.py"] EXPOSE 5000 EXPOSE 8000 EXPOSE 9000 diff --git a/compose.yml b/compose.yml index 51434a5..6632ee7 100644 --- a/compose.yml +++ b/compose.yml @@ -8,6 +8,18 @@ services: MEILI_NO_ANALYTICS: true volumes: - "meili_data:/meili_data" + + jukebox-software: + build: . + init: true + ports: + - "5000:5000" + - "8000:8000" + - "9000:9000" + environment: + - PYTHONUNBUFFERED=1 + depends_on: + - meilisearch volumes: meili_data: \ No newline at end of file diff --git a/run.py b/run.py index 65b0ce4..9e0f95c 100755 --- a/run.py +++ b/run.py @@ -26,7 +26,7 @@ import json import process_video import search from search import JukeboxSearch - +#multiprocessing.set_start_method('spawn', True) config = None @@ -581,7 +581,7 @@ if __name__ == "__main__": with open('config.yml', 'r') as fileread: #global config config = yaml.safe_load(fileread) - + fprint("Config loaded.") with Manager() as manager: fprint("Spawning threads...") pool = LoggingPool(processes=10) @@ -602,5 +602,12 @@ if __name__ == "__main__": fprint("Entering main loop...") while(keeprunning): mainloop_server(pool) + else: + fprint("Mode unspecified - assuming server") + fprint("Starting in server mode.") + if setup_server(pool): + fprint("Entering main loop...") + while(keeprunning): + mainloop_server(pool) diff --git a/search.py b/search.py index d7bb76b..c4e8c4c 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://localhost:7700" +DEFAULT_URL = "http://meilisearch:7700" DEFAULT_APIKEY = "fluffybunnyrabbit" # I WOULD RECOMMEND SOMETHING MORE SECURE DEFAULT_INDEX = "cables" DEFAULT_FILTERABLE_ATTRS = ["partnum", "uuid", "position"] # default filterable attributes From 5016b4e99f92b3c34f2619f7a96c143ce1b86452 Mon Sep 17 00:00:00 2001 From: Cole Deck Date: Thu, 28 Mar 2024 00:44:35 +0000 Subject: [PATCH 04/11] Update compose.yml --- compose.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/compose.yml b/compose.yml index 6632ee7..2a85d3e 100644 --- a/compose.yml +++ b/compose.yml @@ -20,6 +20,11 @@ services: - PYTHONUNBUFFERED=1 depends_on: - meilisearch + + jukebox-web: + build: jukebox-web + ports: + - "3000:3000" volumes: meili_data: \ No newline at end of file From 64bb50f055149874d0d4786b8e2574e82bf9a7f4 Mon Sep 17 00:00:00 2001 From: Cole Deck Date: Thu, 28 Mar 2024 00:44:57 +0000 Subject: [PATCH 05/11] Add setup-alpine-vm.sh --- setup-alpine-vm.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 setup-alpine-vm.sh diff --git a/setup-alpine-vm.sh b/setup-alpine-vm.sh new file mode 100644 index 0000000..3c84edf --- /dev/null +++ b/setup-alpine-vm.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +# This script must run as root! + +echo "https://dl-cdn.alpinelinux.org/alpine/latest-stable/main +https://dl-cdn.alpinelinux.org/alpine/latest-stable/community" > /etc/apk/repositories + +apk upgrade +apk add git docker docker-cli-compose + +rc-update add docker +service docker start + +git clone https://git.myitr.org/Jukebox/jukebox-software +cd jukebox-software +git submodule init +git submodule update From 672507f498afa0f2cc4c235a3c1c933e100e3a0e Mon Sep 17 00:00:00 2001 From: Cole Deck Date: Wed, 27 Mar 2024 19:46:45 -0500 Subject: [PATCH 06/11] Add jukebox web --- .gitmodules | 3 +++ jukebox-web | 1 + 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 jukebox-web diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..02a4c94 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "jukebox-web"] + path = jukebox-web + url = https://git.myitr.org/Jukebox/jukebox-web diff --git a/jukebox-web b/jukebox-web new file mode 160000 index 0000000..5b03f1c --- /dev/null +++ b/jukebox-web @@ -0,0 +1 @@ +Subproject commit 5b03f1c65aa7e9514db300538b631d73b0e95e92 From e21ded46f10b6d5a090a6e9699d85f8d8c0ee895 Mon Sep 17 00:00:00 2001 From: Cole Deck Date: Wed, 27 Mar 2024 19:47:17 -0500 Subject: [PATCH 07/11] Update juekbox-web --- jukebox-web | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jukebox-web b/jukebox-web index 5b03f1c..f3d8ec0 160000 --- a/jukebox-web +++ b/jukebox-web @@ -1 +1 @@ -Subproject commit 5b03f1c65aa7e9514db300538b631d73b0e95e92 +Subproject commit f3d8ec0cc421cb8f8b7bb4b30339f3663f70b297 From 1ec6d92cfa2d082e0135bec77ca6b32a0fe20e91 Mon Sep 17 00:00:00 2001 From: Cole Deck Date: Wed, 27 Mar 2024 19:50:01 -0500 Subject: [PATCH 08/11] Deploy docker containers --- setup-alpine-vm.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/setup-alpine-vm.sh b/setup-alpine-vm.sh index 3c84edf..c0accb2 100644 --- a/setup-alpine-vm.sh +++ b/setup-alpine-vm.sh @@ -15,3 +15,6 @@ git clone https://git.myitr.org/Jukebox/jukebox-software cd jukebox-software git submodule init git submodule update + +docker compose build +docker compose up -d \ No newline at end of file From dc1e568a96d75dc23c36b1de7b8bd80be379009b Mon Sep 17 00:00:00 2001 From: Cole Deck Date: Wed, 27 Mar 2024 20:33:21 -0500 Subject: [PATCH 09/11] 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 From 4dd6f7649a7ddcf73c56a023935dce53ea7e11c2 Mon Sep 17 00:00:00 2001 From: Cole Deck Date: Wed, 27 Mar 2024 20:40:20 -0500 Subject: [PATCH 10/11] Implement cable_search --- run.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/run.py b/run.py index fa42039..3658360 100755 --- a/run.py +++ b/run.py @@ -205,7 +205,12 @@ def start_server_socket(cable_list): if call == "send": pass elif call == "request": - pass + results = jbs.search(data["string"])["hits"] + dataout = dict() + dataout["cables"] = list() + for result in results: + dataout["cables"].append(result["fullspecs"]) + send_data(decoded["type"], "send", dataout, client_id) case "keyboard": fprint("keyboard message") if call == "send": From 5edd7f45921b61a27747f27a1c3be29ad4807088 Mon Sep 17 00:00:00 2001 From: Cole Deck Date: Wed, 27 Mar 2024 20:41:07 -0500 Subject: [PATCH 11/11] Remove extraneous `pass` --- run.py | 1 - 1 file changed, 1 deletion(-) diff --git a/run.py b/run.py index 3658360..be09c92 100755 --- a/run.py +++ b/run.py @@ -216,7 +216,6 @@ def start_server_socket(cable_list): 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",))