Skip to content

Commit bd43b3a

Browse files
MGross21michal-milkowski
authored andcommitted
Refactor protocol version constants
- organized into Protocol class for more consistent file structure - Black Python Formatting
1 parent 04b3937 commit bd43b3a

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

rtde/rtde.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,19 @@
3939

4040

4141
class Command:
42-
RTDE_REQUEST_PROTOCOL_VERSION = ord('V') # V=86
43-
RTDE_GET_URCONTROL_VERSION = ord('v') # v=118
44-
RTDE_TEXT_MESSAGE = ord('M') # M=77
45-
RTDE_DATA_PACKAGE = ord('U') # U=85
46-
RTDE_CONTROL_PACKAGE_SETUP_OUTPUTS = ord('O') # O=79
47-
RTDE_CONTROL_PACKAGE_SETUP_INPUTS = ord('I') # I=73
48-
RTDE_CONTROL_PACKAGE_START = ord('S') # S=83
49-
RTDE_CONTROL_PACKAGE_PAUSE = ord('P') # P=80
42+
RTDE_REQUEST_PROTOCOL_VERSION = ord("V") # V=86
43+
RTDE_GET_URCONTROL_VERSION = ord("v") # v=118
44+
RTDE_TEXT_MESSAGE = ord("M") # M=77
45+
RTDE_DATA_PACKAGE = ord("U") # U=85
46+
RTDE_CONTROL_PACKAGE_SETUP_OUTPUTS = ord("O") # O=79
47+
RTDE_CONTROL_PACKAGE_SETUP_INPUTS = ord("I") # I=73
48+
RTDE_CONTROL_PACKAGE_START = ord("S") # S=83
49+
RTDE_CONTROL_PACKAGE_PAUSE = ord("P") # P=80
5050

5151

52-
RTDE_PROTOCOL_VERSION_1 = 1
53-
RTDE_PROTOCOL_VERSION_2 = 2
52+
class Protocol:
53+
VERSION_1 = 1
54+
VERSION_2 = 2
5455

5556

5657
class ConnectionState:
@@ -82,7 +83,7 @@ def __init__(self, hostname, port=30004):
8283
self.__output_config = None
8384
self.__input_config = {}
8485
self.__skipped_package_count = 0
85-
self.__protocolVersion = RTDE_PROTOCOL_VERSION_1
86+
self.__protocolVersion = Protocol.VERSION_1
8687
self.__warning_counter = {}
8788

8889
def connect(self):
@@ -137,10 +138,10 @@ def get_controller_version(self):
137138

138139
def negotiate_protocol_version(self):
139140
cmd = Command.RTDE_REQUEST_PROTOCOL_VERSION
140-
payload = struct.pack(">H", RTDE_PROTOCOL_VERSION_2)
141+
payload = struct.pack(">H", Protocol.VERSION_2)
141142
success = self.__sendAndReceive(cmd, payload)
142143
if success:
143-
self.__protocolVersion = RTDE_PROTOCOL_VERSION_2
144+
self.__protocolVersion = Protocol.VERSION_2
144145
return success
145146

146147
def send_input_setup(self, variables, types=[]):
@@ -434,7 +435,7 @@ def __unpack_text_message(self, payload):
434435
if len(payload) < 1:
435436
_log.error("RTDE_TEXT_MESSAGE: No payload")
436437
return None
437-
if self.__protocolVersion == RTDE_PROTOCOL_VERSION_1:
438+
if self.__protocolVersion == Protocol.VERSION_1:
438439
msg = serialize.MessageV1.unpack(payload)
439440
else:
440441
msg = serialize.Message.unpack(payload)

0 commit comments

Comments
 (0)