summaryrefslogtreecommitdiffstats
path: root/admin/lib/proto.py
diff options
context:
space:
mode:
Diffstat (limited to 'admin/lib/proto.py')
-rw-r--r--admin/lib/proto.py24
1 files changed, 18 insertions, 6 deletions
diff --git a/admin/lib/proto.py b/admin/lib/proto.py
index 16c0ae3..8ceb8d8 100644
--- a/admin/lib/proto.py
+++ b/admin/lib/proto.py
@@ -2,6 +2,8 @@ from time import sleep
from sys import stderr
import serial
+import socket
+import ssl
from command import Command
import options
@@ -14,20 +16,30 @@ class Proto(object):
kwa.update(options.serial)
kwa.update(kwargs)
url = url or options.url
- self.fd = serial.serial_for_url(url, **kwa)
+ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ sock.settimeout(20)
+ print ('wrapping..')
+ ctx = ssl.create_default_context()
+ self.sock = ssl.wrap_socket(sock)
+ print ('connecting')
+ self.sock.connect((url, 443))
+ self.sock.settimeout(60)
+ print ('done')
+
+ self.fd = self.sock.makefile()
+ #self.fd = serial.serial_for_url(url, **kwa)
sleep(options.init_sleep)
- self.fd.flushInput()
- self.fd.flushOutput()
+ ##self.fd.flushInput()
+ #self.fd.flushOutput()
print >> stderr, 'Serial port ready'
def send(self, command):
cmd = str(command) + '\n'
print cmd
for i in cmd:
- sleep(0.02)
- self.fd.write(i)
+ self.sock.send(i)
def recv(self):
line = self.fd.readline()
- print line
+ print (line)
if line[0] != '$':
return self.recv()
cmd = Command.from_str(line)