@@ -31,10 +31,6 @@ class ROT2Prog:
3131 _pulses_per_degree = 1
3232
3333 _limits_lock = Lock ()
34- _min_az = 0.0
35- _max_az = 360.0
36- _min_el = 0.0
37- _max_el = 180.0
3834
3935 def __init__ (self , port , timeout = 5 ):
4036 """Creates object and opens serial connection.
@@ -60,15 +56,15 @@ def __init__(self, port, timeout = 5):
6056 # set the limits to default values
6157 self .set_limits ()
6258
63- def _send_command (self , cmd ):
59+ def _send_command (self , command_packet ):
6460 """Sends a command packet.
6561
6662 Args:
67- cmd (list of int): Command packet queued.
63+ command_packet (list of int): Command packet queued.
6864 """
69- self ._ser .write (bytearray (cmd ))
70- self ._log .debug ('Command packet sent: ' + str (cmd ))
71-
65+ self ._ser .write (bytearray (command_packet ))
66+ self ._log .debug ('Command packet sent: ' + str (list ( map ( hex , list ( command_packet ))) ))
67+
7268 def _recv_response (self ):
7369 """Receives a response packet.
7470
@@ -83,14 +79,13 @@ def _recv_response(self):
8379 response_packet = list (self ._ser .read (12 ))
8480
8581 # attempt to receive 12 bytes, the length of response packet
86- if len (response_packet ) == 0 :
87- raise ReadTimeout ('response timed out' )
88- elif len (response_packet ) != 12 :
89- self ._log .debug ('Response packet received: ' + str (list (response_packet )))
90- raise PacketError ('incomplete response packet' )
82+ self ._log .debug ('Response packet received: ' + str (list (map (hex , list (response_packet )))))
83+ if len (response_packet ) != 12 :
84+ if len (response_packet ) == 0 :
85+ raise ReadTimeout ('Response timed out' )
86+ else :
87+ raise PacketError ('Incomplete response packet' )
9188 else :
92- self ._log .debug ('Response packet received: ' + str (list (response_packet )))
93-
9489 # convert from byte values
9590 az = (response_packet [1 ] * 100 ) + (response_packet [2 ] * 10 ) + response_packet [3 ] + (response_packet [4 ] / 10.0 ) - 360.0
9691 el = (response_packet [6 ] * 100 ) + (response_packet [7 ] * 10 ) + response_packet [8 ] + (response_packet [9 ] / 10.0 ) - 360.0
@@ -156,9 +151,9 @@ def set(self, az, el):
156151
157152 with self ._limits_lock :
158153 if az > self ._max_az or az < self ._min_az :
159- raise ValueError ('Azimuth of ' + str (az ) + '° is out of range: [' + str (self ._min_az ) + '°, ' + str (self ._max_az ) + '°]' )
154+ raise ValueError ('Azimuth of ' + str (az ) + '° is out of range [' + str (self ._min_az ) + '°, ' + str (self ._max_az ) + '°]' )
160155 if el > self ._max_el or el < self ._min_el :
161- raise ValueError ('Elevation of ' + str (el ) + '° is out of range: [' + str (self ._min_el ) + '°, ' + str (self ._max_el ) + '°]' )
156+ raise ValueError ('Elevation of ' + str (el ) + '° is out of range [' + str (self ._min_el ) + '°, ' + str (self ._max_el ) + '°]' )
162157
163158 self ._log .debug ('Set command queued' )
164159 self ._log .debug ('-> Azimuth: ' + str (az ) + '°' )
@@ -178,9 +173,9 @@ def set(self, az, el):
178173 # build command
179174 cmd = [
180175 0x57 ,
181- int (H [- 4 ]), int (H [- 3 ]), int (H [- 2 ]), int (H [- 1 ]),
176+ int (H [- 4 ]) + 0x30 , int (H [- 3 ]) + 0x30 , int (H [- 2 ]) + 0x30 , int (H [- 1 ]) + 0x30 ,
182177 resolution ,
183- int (V [- 4 ]), int (V [- 3 ]), int (V [- 2 ]), int (V [- 1 ]),
178+ int (V [- 4 ]) + 0x30 , int (V [- 3 ]) + 0x30 , int (V [- 2 ]) + 0x30 , int (V [- 1 ]) + 0x30 ,
184179 resolution ,
185180 0x2f ,
186181 0x20 ]
@@ -265,45 +260,43 @@ def _run(self):
265260 """
266261 while self ._keep_running :
267262 command_packet = list (self ._ser .read (13 ))
263+ self ._log .debug ('Command packet received: ' + str (list (map (hex , list (command_packet )))))
268264 if len (command_packet ) != 13 :
269- self ._log .debug ('Command packet received: ' + str (command_packet ))
270265 self ._log .critical ('Incomplete command packet' )
271266 else :
272- self ._log .debug ('Command packet received: ' + str (command_packet ))
273-
274267 K = command_packet [11 ]
275268
276269 if K in [0x0F , 0x1F ]:
277270 if K == 0x0F :
278- self ._log .info ('Stop command received' )
271+ self ._log .debug ('Stop command received' )
279272 elif K == 0x1F :
280- self ._log .info ('Status command received' )
273+ self ._log .debug ('Status command received' )
281274
282275 # convert to byte values
283276 H = "00000" + str (round (float (self ._az + 360 ), 1 ))
284277 V = "00000" + str (round (float (self ._el + 360 ), 1 ))
285278
286- rsp = [
279+ response_packet = [
287280 0x57 ,
288281 int (H [- 5 ]), int (H [- 4 ]), int (H [- 3 ]), int (H [- 1 ]),
289282 self ._pulses_per_degree ,
290283 int (V [- 5 ]), int (V [- 4 ]), int (V [- 3 ]), int (V [- 1 ]),
291284 self ._pulses_per_degree ,
292285 0x20 ]
293286
294- self ._log .info ('Response queued' )
295- self ._log .info ('-> Azimuth: ' + str (self ._az ) + '°' )
296- self ._log .info ('-> Elevation: ' + str (self ._el ) + '°' )
297- self ._log .info ('-> PH: ' + str (self ._pulses_per_degree ))
298- self ._log .info ('-> PV: ' + str (self ._pulses_per_degree ))
287+ self ._log .debug ('Response queued' )
288+ self ._log .debug ('-> Azimuth: ' + str (self ._az ) + '°' )
289+ self ._log .debug ('-> Elevation: ' + str (self ._el ) + '°' )
290+ self ._log .debug ('-> PH: ' + hex (self ._pulses_per_degree ))
291+ self ._log .debug ('-> PV: ' + hex (self ._pulses_per_degree ))
299292
300- self ._ser .write (bytearray (rsp ))
293+ self ._ser .write (bytearray (response_packet ))
301294
302- self ._log .debug ('Response packet sent: ' + str (rsp ))
295+ self ._log .debug ('Response packet sent: ' + str (list ( map ( hex , list ( response_packet ))) ))
303296 elif K == 0x2F :
304297 # convert from ascii characters
305- H = (command_packet [1 ] * 1000 ) + (command_packet [2 ] * 100 ) + (command_packet [3 ] * 10 ) + command_packet [4 ]
306- V = (command_packet [6 ] * 1000 ) + (command_packet [7 ] * 100 ) + (command_packet [8 ] * 10 ) + command_packet [9 ]
298+ H = (( command_packet [1 ] - 0x30 ) * 1000 ) + (( command_packet [2 ] - 0x30 ) * 100 ) + (( command_packet [3 ] - 0x30 ) * 10 ) + ( command_packet [4 ] - 0x30 )
299+ V = (( command_packet [6 ] - 0x30 ) * 1000 ) + (( command_packet [7 ] - 0x30 ) * 100 ) + (( command_packet [8 ] - 0x30 ) * 10 ) + ( command_packet [9 ] - 0x30 )
307300
308301 # decode with resolution
309302 self ._az = H / self ._pulses_per_degree - 360.0
@@ -312,9 +305,9 @@ def _run(self):
312305 self ._az = float (round (self ._az , 1 ))
313306 self ._el = float (round (self ._el , 1 ))
314307
315- self ._log .info ('Set command received' )
316- self ._log .info ('-> Azimuth: ' + str (self ._az ) + '°' )
317- self ._log .info ('-> Elevation: ' + str (self ._el ) + '°' )
308+ self ._log .debug ('Set command received' )
309+ self ._log .debug ('-> Azimuth: ' + str (self ._az ) + '°' )
310+ self ._log .debug ('-> Elevation: ' + str (self ._el ) + '°' )
318311 else :
319312 self ._log .error ('Invalid command received (K = ' + str (hex (K )) + ')' )
320313
0 commit comments