Update sim/sensor_utils.py
Browse filesmove from msgpack to json for consistency
- sim/sensor_utils.py +5 -6
sim/sensor_utils.py
CHANGED
|
@@ -1,11 +1,10 @@
|
|
| 1 |
"""Standalone sensor utilities for camera image publishing via ZMQ"""
|
| 2 |
import base64
|
|
|
|
| 3 |
from dataclasses import dataclass
|
| 4 |
from typing import Any, Dict
|
| 5 |
|
| 6 |
import cv2
|
| 7 |
-
import msgpack
|
| 8 |
-
import msgpack_numpy as m
|
| 9 |
import numpy as np
|
| 10 |
import zmq
|
| 11 |
|
|
@@ -66,8 +65,8 @@ class SensorServer:
|
|
| 66 |
|
| 67 |
def send_message(self, data: Dict[str, Any]):
|
| 68 |
try:
|
| 69 |
-
|
| 70 |
-
self.socket.
|
| 71 |
except zmq.Again:
|
| 72 |
self.message_dropped += 1
|
| 73 |
print(f"[Warning] message dropped: {self.message_dropped}")
|
|
@@ -95,8 +94,8 @@ class SensorClient:
|
|
| 95 |
self.context.term()
|
| 96 |
|
| 97 |
def receive_message(self):
|
| 98 |
-
|
| 99 |
-
return
|
| 100 |
|
| 101 |
|
| 102 |
class ImageUtils:
|
|
|
|
| 1 |
"""Standalone sensor utilities for camera image publishing via ZMQ"""
|
| 2 |
import base64
|
| 3 |
+
import json
|
| 4 |
from dataclasses import dataclass
|
| 5 |
from typing import Any, Dict
|
| 6 |
|
| 7 |
import cv2
|
|
|
|
|
|
|
| 8 |
import numpy as np
|
| 9 |
import zmq
|
| 10 |
|
|
|
|
| 65 |
|
| 66 |
def send_message(self, data: Dict[str, Any]):
|
| 67 |
try:
|
| 68 |
+
json_str = json.dumps(data)
|
| 69 |
+
self.socket.send_string(json_str, flags=zmq.NOBLOCK)
|
| 70 |
except zmq.Again:
|
| 71 |
self.message_dropped += 1
|
| 72 |
print(f"[Warning] message dropped: {self.message_dropped}")
|
|
|
|
| 94 |
self.context.term()
|
| 95 |
|
| 96 |
def receive_message(self):
|
| 97 |
+
json_str = self.socket.recv_string()
|
| 98 |
+
return json.loads(json_str)
|
| 99 |
|
| 100 |
|
| 101 |
class ImageUtils:
|