@@ -16,7 +16,7 @@ class ROT2Prog:
1616 min_el (float): Minimum elevation angle.
1717 """
1818
19- _log = None
19+ _log = logging . getLogger ( __name__ )
2020 _ser = None
2121 _resolution = 1
2222
@@ -32,8 +32,6 @@ def __init__(self, port, timeout = 5):
3232 port (str): Name of serial port to connect to.
3333 timeout (int, optional): Worst case response time of the controller.
3434 """
35- self ._log = logging .getLogger (__name__ )
36-
3735 # open serial port
3836 while (self ._ser is None ):
3937 try :
@@ -49,7 +47,7 @@ def __init__(self, port, timeout = 5):
4947 self ._log .error ('Connection to serial port failed, retrying in ' + str (timeout ) + ' seconds...' )
5048 time .sleep (timeout )
5149
52- self ._log .info ('ROT2Prog interface opened on ' + str (self ._ser .name ) + ' \n ' )
50+ self ._log .info ('ROT2Prog interface opened on ' + str (self ._ser .name ))
5351
5452 # get resolution from controller
5553 self .status ()
@@ -63,13 +61,13 @@ def __del__(self):
6361 def _help (self ):
6462 """Displays a help message for standalone commands.
6563 """
66- print ('\n ##############################' )
64+ print ('##############################' )
6765 print ('# ROT2Prog Interface Commands' )
6866 print ('##############################' )
6967 print ('# stop' )
7068 print ('# status' )
7169 print ('# set [azimuth] [elevation]' )
72- print ('##############################\n ' )
70+ print ('##############################' )
7371
7472 def _send_command (self , cmd ):
7573 """Sends a command packet.
@@ -79,7 +77,7 @@ def _send_command(self, cmd):
7977 """
8078 self ._ser .flush ()
8179 self ._ser .write (bytearray (cmd ))
82- self ._log .debug ('Command packet sent: ' + str (cmd ) + ' \n ' )
80+ self ._log .debug ('Command packet sent: ' + str (cmd ))
8381
8482 def _recv_response (self ):
8583 """Receives a response packet.
@@ -93,12 +91,12 @@ def _recv_response(self):
9391 # attempt to receive 12 bytes (length of response packet)
9492 if (len (response_packet ) != 12 ):
9593 if (len (response_packet ) == 0 ):
96- self ._log .error ('Response timed out\n ' )
94+ self ._log .error ('Response timed out' )
9795 else :
98- self ._log .error ('Invalid response packet\n ' )
96+ self ._log .error ('Invalid response packet' )
9997 return [0 , 0 ]
10098 else :
101- self ._log .debug ('Response packet received: ' + str (list (response_packet )) + ' \n ' )
99+ self ._log .debug ('Response packet received: ' + str (list (response_packet )))
102100
103101 # convert from byte values
104102 az = (response_packet [1 ] * 100 ) + (response_packet [2 ] * 10 ) + response_packet [3 ] + (response_packet [4 ] / 10 ) - 360.0
@@ -109,7 +107,7 @@ def _recv_response(self):
109107 # check resolution value
110108 valid_resolution = [0x1 , 0x2 , 0x4 ]
111109 if (PH != PV or PH not in valid_resolution ):
112- self ._log .error ('Invalid controller resolution [PH = ' + str (hex (PH )) + ', PV = ' + str (hex (PV )) + ']\n ' )
110+ self ._log .error ('Invalid controller resolution [PH = ' + str (hex (PH )) + ', PV = ' + str (hex (PV )) + ']' )
113111 else :
114112 self ._resolution = PH
115113
@@ -120,7 +118,7 @@ def _recv_response(self):
120118 self ._log .info ('# Elevation: ' + str (round (float (el ), 2 )))
121119 self ._log .info ('# PH: ' + str (PH ))
122120 self ._log .info ('# PV: ' + str (PV ))
123- self ._log .info ('##############################\n ' )
121+ self ._log .info ('##############################' )
124122
125123 return [az , el ]
126124
@@ -132,7 +130,7 @@ def status(self):
132130 """
133131 self ._log .info ('##############################' )
134132 self ._log .info ('# STATUS COMMAND' )
135- self ._log .info ('##############################\n ' )
133+ self ._log .info ('##############################' )
136134
137135 cmd = [0x57 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x1f , 0x20 ]
138136 self ._send_command (cmd )
@@ -146,7 +144,7 @@ def stop(self):
146144 """
147145 self ._log .info ('##############################' )
148146 self ._log .info ('# STOP COMMAND' )
149- self ._log .info ('##############################\n ' )
147+ self ._log .info ('##############################' )
150148
151149 cmd = [0x57 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x0f , 0x20 ]
152150 self ._send_command (cmd )
@@ -181,7 +179,7 @@ def set(self, az, el):
181179 self ._log .info ('##############################' )
182180 self ._log .info ('# Azimuth: ' + str (round (float (az ), 2 )))
183181 self ._log .info ('# Elevation: ' + str (round (float (el ), 2 )))
184- self ._log .info ('##############################\n ' )
182+ self ._log .info ('##############################' )
185183
186184 # encode with resolution
187185 H = int (self ._resolution * (float (az ) + 360 ))
@@ -246,7 +244,7 @@ def __init__(self, port, resolution):
246244 time .sleep (self ._retry )
247245
248246 self ._resolution = resolution
249- self ._log .info ('ROT2Prog simulation interface opened on ' + str (self ._ser .name ) + ' \n ' )
247+ self ._log .info ('ROT2Prog simulation interface opened on ' + str (self ._ser .name ))
250248
251249 # start daemon thread to communicate on serial port
252250 Thread (target = self .run , daemon = True ).start ()
@@ -262,19 +260,19 @@ def run(self):
262260 """
263261 while self ._keep_running :
264262 command_packet = list (self ._ser .read (13 ))
265- self ._log .debug ('Command packet received: ' + str (command_packet ) + ' \n ' )
263+ self ._log .debug ('Command packet received: ' + str (command_packet ))
266264
267265 K = command_packet [11 ]
268266
269267 if K in [0x0F , 0x1F ]:
270268 if K == 0x0F :
271269 self ._log .info ('##############################' )
272270 self ._log .info ('# STOP COMMAND' )
273- self ._log .info ('##############################\n ' )
271+ self ._log .info ('##############################' )
274272 elif K == 0x1F :
275273 self ._log .info ('##############################' )
276274 self ._log .info ('# STATUS COMMAND' )
277- self ._log .info ('##############################\n ' )
275+ self ._log .info ('##############################' )
278276
279277 # convert to byte values
280278 H = "000" + str (round (float (self .az + 360 ), 1 ))
@@ -295,12 +293,12 @@ def run(self):
295293 self ._log .info ('# Elevation: ' + str (float (self .el )))
296294 self ._log .info ('# PH: ' + str (self ._resolution ))
297295 self ._log .info ('# PV: ' + str (self ._resolution ))
298- self ._log .info ('##############################\n ' )
296+ self ._log .info ('##############################' )
299297
300298 self ._ser .flush ()
301299 self ._ser .write (bytearray (rsp ))
302300
303- self ._log .debug ('Response packet sent: ' + str (rsp ) + ' \n ' )
301+ self ._log .debug ('Response packet sent: ' + str (rsp ))
304302 elif K == 0x2F :
305303 # convert from ascii characters
306304 H = (command_packet [1 ] * 1000 ) + (command_packet [2 ] * 100 ) + (command_packet [3 ] * 10 ) + command_packet [4 ]
@@ -315,9 +313,9 @@ def run(self):
315313 self ._log .info ('##############################' )
316314 self ._log .info ('# Azimuth: ' + str (self .az ))
317315 self ._log .info ('# Elevation: ' + str (self .el ))
318- self ._log .info ('##############################\n ' )
316+ self ._log .info ('##############################' )
319317 else :
320- self ._log .error ('Invalid command received [K = ' + str (hex (K )) + ']\n ' )
318+ self ._log .error ('Invalid command received [K = ' + str (hex (K )) + ']' )
321319
322320 def stop (self ):
323321 """Stops the daemon thread running the simulator.
0 commit comments