| | |
| | | from datetime import datetime |
| | | from typing import List |
| | | import numpy as np |
| | | import cv2 |
| | | |
| | | # # add python path of src to sys.path |
| | | # src_path = os.path.join(__file__, *(['..'] * 2)) |
| | |
| | | def decode_CommandsMsg(self,queue): |
| | | |
| | | raise NotImplementedError("NOT IMPLEMENT!") |
| | | |
| | | |
| | | |
| | | def send_logs_tool(logs:List[str], |
| | | logs_queue:queue.Queue, |
| | | source:str, |
| | | routing_key:str): |
| | | |
| | | for i, log in enumerate(logs): |
| | | if log is not None: |
| | | # constract a logs message |
| | | logsMsg = pb.LogsMessage() |
| | | logsMsg.source = source |
| | | logsMsg.timestamp = f"{time.asctime()}" |
| | | logsMsg.context = log |
| | | # convert the proto object to string |
| | | logsMsg_bytes = logsMsg.SerializeToString() |
| | | # add logsmsg to queue |
| | | logs_queue.put([routing_key,logsMsg_bytes]) |
| | | |
| | | |
| | | def send_images_tool(images:List[np.array], |
| | | images_queue:queue.Queue, |
| | | source:str, |
| | | routing_key:str): |
| | | |
| | | # constract a images message |
| | | imagesMsg = pb.ImagesMessage() |
| | | imagesMsg.source = source |
| | | curr_time = datetime.now().strftime('%Y-%m-%d-%H-%M-%S') |
| | | imagesMsg.timestamp = curr_time |
| | | |
| | | for img in images: |
| | | if img is not None: |
| | | success,image_encoded = cv2.imencode(".jpg",img) |
| | | if success: |
| | | image_bytes = image_encoded.tobytes() |
| | | image_length = len(image_bytes) |
| | | # add the encoded image to msg |
| | | image_item = imagesMsg.Image.add() |
| | | image_item.length = image_length |
| | | image_item.data = image_bytes |
| | | |
| | | # converting the pb image msg to bytes |
| | | imageMsg_bytes = imagesMsg.SerializeToString() |
| | | # add the imageMsg to the queue |
| | | images_queue.put([routing_key,imageMsg_bytes]) |
| | | |
| | | |
| | | |
| | | |
| | | |