Skip to content

Commit

Permalink
Remove message encoding in wiregrid_tiltsensor agent (#764)
Browse files Browse the repository at this point in the history
* debug the wiregrid_tiltsensor agent

* add argument type in make_parser

* changing argument device to encoded
  • Loading branch information
d-hoshino2626 authored Oct 7, 2024
1 parent 33b1e1d commit e225002
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion socs/agents/wiregrid_tiltsensor/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self, agent, ip, port, sensor_type=None):
self.take_data = False

self.ip = ip
self.port = port
self.port = int(port)
self.sensor_type = sensor_type
self.tiltsensor = connect(self.ip, self.port, self.sensor_type)
self.pm = Pacemaker(2, quantize=True)
Expand Down
2 changes: 1 addition & 1 deletion socs/agents/wiregrid_tiltsensor/drivers/dwl.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def __conn(self, tcp_ip=None, tcp_port=None, timeout=None):
"Aborted DWL._conn() due to no "
"TCP port specified")
elif tcp_ip is not None and tcp_port is not None:
self.ser = mx.Serial_TCPServer((tcp_ip, tcp_port), timeout)
self.ser = mx.Serial_TCPServer((tcp_ip, tcp_port), timeout, encoded=False)
self.tcp_ip = tcp_ip
self.tcp_port = int(tcp_port)
self.using_tcp = True
Expand Down
2 changes: 1 addition & 1 deletion socs/agents/wiregrid_tiltsensor/drivers/sherborne.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def __conn(self, tcp_ip, tcp_port, timeout):
"Aborted Sherborne._conn() due to no TCP IP or "
"TCP port specified")
elif tcp_ip is not None and tcp_port is not None:
self.ser = mx.Serial_TCPServer((tcp_ip, tcp_port), timeout)
self.ser = mx.Serial_TCPServer((tcp_ip, tcp_port), timeout, encoded=False)
self.tcp_ip = tcp_ip
self.tcp_port = int(tcp_port)
self.using_tcp = True
Expand Down
15 changes: 12 additions & 3 deletions socs/common/moxa_serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,14 @@ class Serial_TCPServer(object):
Args:
port (tuple): (IP addr, TCP port)
timeout (float): Timeout for reading from the moxa box
encoded (bool): Encode/decode messages before/after sending/receiving if True.
Send messages unmodified if False. Defaults to True.
"""

def __init__(self, port, timeout=MOXA_DEFAULT_TIMEOUT):
def __init__(self, port, timeout=MOXA_DEFAULT_TIMEOUT, encoded=True):
self.port = port
self.encoded = encoded

self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.setblocking(0)
Expand Down Expand Up @@ -88,7 +91,10 @@ def readexactly(self, n):
pass
# Flush the message out if you got everything
if len(msg) == n:
msg = self.sock.recv(n).decode()
if self.encoded:
msg = self.sock.recv(n).decode()
else:
msg = self.sock.recv(n)
# Otherwise tell nothing and leave the data in the buffer
else:
msg = ''
Expand Down Expand Up @@ -193,7 +199,10 @@ def write(self, msg):
needed.
"""
self.sock.send(msg.encode())
if self.encoded:
self.sock.send(msg.encode())
else:
self.sock.send(msg)

def writeread(self, msg):
self.flushInput()
Expand Down

0 comments on commit e225002

Please sign in to comment.