From 1bc34ed0c5245afc517753d74e7747db5475b5c7 Mon Sep 17 00:00:00 2001 From: Sander Datema Date: Sat, 27 Jun 2020 21:29:19 +0200 Subject: [PATCH] Revert auto formatting --- Python/src/xpc.py | 110 +++++++++++++++++++++++----------------------- 1 file changed, 54 insertions(+), 56 deletions(-) diff --git a/Python/src/xpc.py b/Python/src/xpc.py index 7a6f926..4bbf640 100644 --- a/Python/src/xpc.py +++ b/Python/src/xpc.py @@ -1,22 +1,20 @@ import socket import struct - class XPlaneConnect(object): - """XPlaneConnect (XPC) facilitates communication to and from the XPCPlugin.""" - + '''XPlaneConnect (XPC) facilitates communication to and from the XPCPlugin.''' socket = None # Basic Functions - def __init__(self, xpHost="localhost", xpPort=49009, port=0, timeout=100): - """Sets up a new connection to an X-Plane Connect plugin running in X-Plane. + def __init__(self, xpHost = 'localhost', xpPort = 49009, port = 0, timeout = 100): + '''Sets up a new connection to an X-Plane Connect plugin running in X-Plane. Args: xpHost: The hostname of the machine running X-Plane. xpPort: The port on which the XPC plugin is listening. Usually 49007. port: The port which will be used to send and receive data. timeout: The period (in milliseconds) after which read attempts will fail. - """ + ''' # Validate parameters xpIP = None @@ -53,59 +51,59 @@ class XPlaneConnect(object): self.close() def close(self): - """Closes the specified connection and releases resources associated with it.""" + '''Closes the specified connection and releases resources associated with it.''' if self.socket is not None: self.socket.close() self.socket = None def sendUDP(self, buffer): - """Sends a message over the underlying UDP socket.""" + '''Sends a message over the underlying UDP socket.''' # Preconditions - if len(buffer) == 0: + if(len(buffer) == 0): raise ValueError("sendUDP: buffer is empty.") self.socket.sendto(buffer, 0, self.xpDst) def readUDP(self): - """Reads a message from the underlying UDP socket.""" + '''Reads a message from the underlying UDP socket.''' return self.socket.recv(16384) # Configuration def setCONN(self, port): - """Sets the port on which the client sends and receives data. + '''Sets the port on which the client sends and receives data. Args: port: The new port to use. - """ - # Validate parameters + ''' + #Validate parameters if port < 0 or port > 65535: raise ValueError("The specified port is not a valid port number.") - # Send command + #Send command buffer = struct.pack("<4sxH", "CONN", port) self.sendUDP(buffer) - # Rebind socket + #Rebind socket clientAddr = ("0.0.0.0", port) - timeout = self.socket.gettimeout() - self.socket.close() + timeout = self.socket.gettimeout(); + self.socket.close(); self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) self.socket.bind(clientAddr) self.socket.settimeout(timeout) - # Read response + #Read response buffer = self.socket.recv(1024) def pauseSim(self, pause): - """Pauses or un-pauses the physics simulation engine in X-Plane. + '''Pauses or un-pauses the physics simulation engine in X-Plane. Args: pause: True to pause the simulation for all a/c; False to resume for all a/c. 2 to switch the status for all a/c. 100:119 to pause a/c 0:19. 200:219 to resume a/c 0:19 - """ + ''' pause = int(pause) - if pause < 0 or (pause > 2 and pause < 100) or (pause > 119 and pause < 200) or pause > 219: + if pause < 0 or (pause > 2 and pause < 100) or (pause > 119 and pause < 200) or pause > 219 : raise ValueError("Invalid argument for pause command.") buffer = struct.pack("<4sxB", "SIMU", pause) @@ -113,30 +111,30 @@ class XPlaneConnect(object): # X-Plane UDP Data def readDATA(self): - """Reads X-Plane data. + '''Reads X-Plane data. Returns: A 2 dimensional array containing 0 or more rows of data. Each array in the result will have 9 elements, the first of which is the row number which that array represents data for, and the rest of which are the data elements in that row. - """ - buffer = self.readUDP() + ''' + buffer = self.readUDP(); if len(buffer) < 6: return None rows = (len(buffer) - 5) / 36 data = [] for i in range(rows): - data.append(struct.unpack_from("9f", buffer, 5 + 36 * i)) + data.append(struct.unpack_from("9f", buffer, 5 + 36*i)) return data def sendDATA(self, data): - """Sends X-Plane data over the underlying UDP socket. + '''Sends X-Plane data over the underlying UDP socket. Args: data: An array of values representing data rows to be set. Each array in `data` should have 9 elements, the first of which is a row number in the range (0-134), and the rest of which are the values to set for that data row. - """ + ''' if len(data) > 134: raise ValueError("Too many rows in data.") @@ -148,12 +146,12 @@ class XPlaneConnect(object): self.sendUDP(buffer) # Position - def getPOSI(self, ac=0): - """Gets position information for the specified aircraft. + def getPOSI(self, ac = 0): + '''Gets position information for the specified aircraft. Args: ac: The aircraft to set the control surfaces of. 0 is the main/player aircraft. - """ + ''' # Send request buffer = struct.pack("<4sxB", "GETP", ac) self.sendUDP(buffer) @@ -170,8 +168,8 @@ class XPlaneConnect(object): # Drop the header & ac from the return value return result[2:] - def sendPOSI(self, values, ac=0): - """Sets position information on the specified aircraft. + def sendPOSI(self, values, ac = 0): + '''Sets position information on the specified aircraft. Args: values: The position values to set. `values` is a array containing up to @@ -186,7 +184,7 @@ class XPlaneConnect(object): * True Heading (deg) * Gear (0=up, 1=down) ac: The aircraft to set the control surfaces of. 0 is the main/player aircraft. - """ + ''' # Preconditions if len(values) < 1 or len(values) > 7: raise ValueError("Must have between 0 and 7 items in values.") @@ -206,12 +204,12 @@ class XPlaneConnect(object): self.sendUDP(buffer) # Controls - def getCTRL(self, ac=0): - """Gets the control surface information for the specified aircraft. + def getCTRL(self, ac = 0): + '''Gets the control surface information for the specified aircraft. Args: ac: The aircraft to set the control surfaces of. 0 is the main/player aircraft. - """ + ''' # Send request buffer = struct.pack("<4sxB", "GETC", ac) self.sendUDP(buffer) @@ -226,11 +224,11 @@ class XPlaneConnect(object): raise ValueError("Unexpected header: " + result[0]) # Drop the header from the return value - result = result[1:7] + result[8:] + result =result[1:7] + result[8:] return result - def sendCTRL(self, values, ac=0): - """Sets control surface information on the specified aircraft. + def sendCTRL(self, values, ac = 0): + '''Sets control surface information on the specified aircraft. Args: values: The control surface values to set. `values` is a array containing up to @@ -245,7 +243,7 @@ class XPlaneConnect(object): * Flaps [0, 1] * Speedbrakes [-0.5, 1.5] ac: The aircraft to set the control surfaces of. 0 is the main/player aircraft. - """ + ''' # Preconditions if len(values) < 1 or len(values) > 7: raise ValueError("Must have between 0 and 6 items in values.") @@ -272,21 +270,21 @@ class XPlaneConnect(object): # DREF Manipulation def sendDREF(self, dref, values): - """Sets the specified dataref to the specified value. + '''Sets the specified dataref to the specified value. Args: dref: The name of the datarefs to set. values: Either a scalar value or a sequence of values. - """ + ''' self.sendDREFs([dref], [values]) def sendDREFs(self, drefs, values): - """Sets the specified datarefs to the specified values. + '''Sets the specified datarefs to the specified values. Args: drefs: A list of names of the datarefs to set. values: A list of scalar or vector values to set. - """ + ''' if len(drefs) != len(values): raise ValueError("drefs and values must have the same number of elements.") @@ -314,24 +312,24 @@ class XPlaneConnect(object): self.sendUDP(buffer) def getDREF(self, dref): - """Gets the value of an X-Plane dataref. + '''Gets the value of an X-Plane dataref. Args: dref: The name of the dataref to get. Returns: A sequence of data representing the values of the requested dataref. - """ + ''' return self.getDREFs([dref])[0] def getDREFs(self, drefs): - """Gets the value of one or more X-Plane datarefs. + '''Gets the value of one or more X-Plane datarefs. Args: drefs: The names of the datarefs to get. Returns: A multidimensional sequence of data representing the values of the requested datarefs. - """ + ''' # Send request buffer = struct.pack("<4sxB", "GETD", len(drefs)) for dref in drefs: @@ -354,8 +352,8 @@ class XPlaneConnect(object): return result # Drawing - def sendTEXT(self, msg, x=-1, y=-1): - """Sets a message that X-Plane will display on the screen. + def sendTEXT(self, msg, x = -1, y = -1): + '''Sets a message that X-Plane will display on the screen. Args: msg: The string to display on the screen @@ -365,7 +363,7 @@ class XPlaneConnect(object): y: The distance in pixels from the bottom edge of the screen to display the message. A value of -1 indicates that the default vertical position should be used. - """ + ''' if y < -1: raise ValueError("y must be greater than or equal to -1.") @@ -377,12 +375,12 @@ class XPlaneConnect(object): self.sendUDP(buffer) def sendVIEW(self, view): - """Sets the camera view in X-Plane + '''Sets the camera view in X-Plane Args: view: The view to use. The ViewType class provides named constants for known views. - """ + ''' # Preconditions if view < ViewType.Forwards or view > ViewType.FullscreenNoHud: raise ValueError("Unknown view command.") @@ -394,7 +392,7 @@ class XPlaneConnect(object): self.sendUDP(buffer) def sendWYPT(self, op, points): - """Adds, removes, or clears waypoints. Waypoints are three dimensional points on or + '''Adds, removes, or clears waypoints. Waypoints are three dimensional points on or above the Earth's surface that are represented visually in the simulator. Each point consists of a latitude and longitude expressed in fractional degrees and an altitude expressed as meters above sea level. @@ -404,7 +402,7 @@ class XPlaneConnect(object): `2` to remove waypoints, and `3` to clear all waypoints. points: A sequence of floating point values representing latitude, longitude, and altitude triples. The length of this array should always be divisible by 3. - """ + ''' if op < 1 or op > 3: raise ValueError("Invalid operation specified.") if len(points) % 3 != 0: @@ -438,7 +436,7 @@ class XPlaneConnect(object): # Send self.sendUDP(buffer) - + class ViewType(object): Forwards = 73 Down = 74