Commits

Alex Hixon committed 1225e31

Change name to console tool.

Comments (0)

Files changed (2)

+class MessageType:
+    MOVE_THROTTLE = 1
+    MOVE_RUDDER = 2
+    MOVE_ELEVATOR = 3
+    
+    NOOP = 4
+    RESET = 5
+    
+    PROPELLER_ON = 6
+    PROPELLER_OFF = 7
+    
+    VERSION = 8
+    
+    SUCCESS = 0
+    FAILURE = 1
+    UNKNOWN = 2
+
+def get_ret (id):
+    if id == MessageType.SUCCESS:
+        return "Success"
+    elif id == MessageType.FAILURE:
+        return "Failure"
+    elif id == MessageType.UNKNOWN:
+        return "Unknown"
+    else:
+        return "code %d" % id
+
+import serial
+
+baud=19200
+#port="/dev/ttyUSB1"
+port="COM3"
+
+print "Opening %s (%d baud)..." % (port, baud)
+
+device = serial.Serial (port, baud)
+
+"""print "Opened! Flushing IO..."
+
+device.flushInput()
+device.flushOutput()"""
+
+device.write(MessageType.VERSION)
+version = device.readline()
+
+motd = device.readline()
+
+print "Device uses version", version
+print "Ready for commands!"
+
+try:
+    while True:
+        act = raw_input("(T)hrottle, (r)udder, (e)levator, re(s)et or [q]uit? ").strip().lower()
+        if len(act) == 0 or act[0] == "q":
+            # default, quit
+            break
+        
+        if act[0] == "s":
+            device.write(ord(MessageType.RESET))
+            status = ord(device.read())
+            print "Return code:", get_ret(status)
+            continue
+        
+        if act[0] != "t" and act[0] != "r" and act[0] != "e":
+            continue
+        
+        deg = -1
+        while True:
+            if act[0] == "t":
+                deg = raw_input("New speed (0 = full anticlockwise, 90 = zero, 180 = full clockwise)? ").strip()
+            else:
+                deg = raw_input("New position (between 0 and 180 degrees)? ").strip()
+                
+            try:
+                deg = int(deg)
+                if deg < 0 or deg > 180:
+                    raise
+                break
+            except:
+                print "Please enter a number between 0 and 180."
+        
+        if act[0] == "t":
+            device.write (chr(MessageType.MOVE_THROTTLE))
+        elif act[0] == "r":
+            device.write (chr(MessageType.MOVE_RUDDER))
+        elif act[0] == "e":
+            device.write (chr(MessageType.MOVE_ELEVATOR))
+        
+        # Now, put out the actual movement amount as unsigned int in one byte (will be < 255)
+        device.write(chr(deg))
+        status = ord(device.read())
+        print "Return code:", get_ret(status)
+except Exception, e:
+    print e
+
+print "Closing..."
+device.close()
+print "All done!"

test.py

-class MessageType:
-    MOVE_THROTTLE = 1
-    MOVE_RUDDER = 2
-    MOVE_ELEVATOR = 3
-    
-    NOOP = 4
-    RESET = 5
-    
-    PROPELLER_ON = 6
-    PROPELLER_OFF = 7
-    
-    VERSION = 8
-    
-    SUCCESS = 0
-    FAILURE = 1
-    UNKNOWN = 2
-
-def get_ret (id):
-    if id == MessageType.SUCCESS:
-        return "Success"
-    elif id == MessageType.FAILURE:
-        return "Failure"
-    elif id == MessageType.UNKNOWN:
-        return "Unknown"
-    else:
-        return "code %d" % id
-
-import serial
-
-baud=19200
-#port="/dev/ttyUSB1"
-port="COM3"
-
-print "Opening %s (%d baud)..." % (port, baud)
-
-device = serial.Serial (port, baud)
-
-"""print "Opened! Flushing IO..."
-
-device.flushInput()
-device.flushOutput()"""
-
-device.write(MessageType.VERSION)
-version = device.readline()
-
-motd = device.readline()
-
-print "Device uses version", version
-print "Ready for commands!"
-
-try:
-    while True:
-        act = raw_input("(T)hrottle, (r)udder, (e)levator, re(s)et or [q]uit? ").strip().lower()
-        if len(act) == 0 or act[0] == "q":
-            # default, quit
-            break
-        
-        if act[0] == "s":
-            device.write(ord(MessageType.RESET))
-            status = ord(device.read())
-            print "Return code:", get_ret(status)
-            continue
-        
-        if act[0] != "t" and act[0] != "r" and act[0] != "e":
-            continue
-        
-        deg = -1
-        while True:
-            if act[0] == "t":
-                deg = raw_input("New speed (0 = full anticlockwise, 90 = zero, 180 = full clockwise)? ").strip()
-            else:
-                deg = raw_input("New position (between 0 and 180 degrees)? ").strip()
-                
-            try:
-                deg = int(deg)
-                if deg < 0 or deg > 180:
-                    raise
-                break
-            except:
-                print "Please enter a number between 0 and 180."
-        
-        if act[0] == "t":
-            device.write (chr(MessageType.MOVE_THROTTLE))
-        elif act[0] == "r":
-            device.write (chr(MessageType.MOVE_RUDDER))
-        elif act[0] == "e":
-            device.write (chr(MessageType.MOVE_ELEVATOR))
-        
-        # Now, put out the actual movement amount as unsigned int in one byte (will be < 255)
-        device.write(chr(deg))
-        status = ord(device.read())
-        print "Return code:", get_ret(status)
-except Exception, e:
-    print e
-
-print "Closing..."
-device.close()
-print "All done!"