X-Git-Url: https://git.ucc.asn.au/?p=zanchey%2Fdispense2.git;a=blobdiff_plain;f=sql-edition%2Fservers%2FVendServer.py;h=3f806bc72c24ac1ab5cfe5c3e5d5304210d99a50;hp=9221a4dd0d67feb096cca6a68c34ab18e687c10e;hb=3d1168a537169794cb3dda12269dd0d7c00d28d2;hpb=9f0dc95f27bd5cedf601bae506d0c40343be40ee diff --git a/sql-edition/servers/VendServer.py b/sql-edition/servers/VendServer.py index 9221a4d..3f806bc 100755 --- a/sql-edition/servers/VendServer.py +++ b/sql-edition/servers/VendServer.py @@ -1,50 +1,18 @@ #!/usr/bin/python -import sys, os, string, socket, time +import sys, os, string, socket, time, re from popen2 import popen2 from pyPgSQL import PgSQL from LATClient import LATClient - -asynchronous_responses = [ '400', '401', # door open/closed - '610', # switches changed - ] - -class VendingMachine: - def __init__(self, rfh, wfh): - self.rfh = rfh - self.wfh = wfh - self.wfh.write('\n') - self.await_prompt() - - def await_prompt(self): - self.wfh.flush() - state = 0 - s = '' - while state != 3: - s = self.rfh.read(1) - if s == '': raise Exception - if s == '\n' and state == 0: state = 1 - if (s == '#' or s == '%') and state == 1: state = 2 - if s == ' ' and state == 2: state = 3 - - def get_response(self): - self.wfh.flush() - s = '' - while s == '': - s = self.rfh.readline() - if s == '': return None - s = s.strip('\r\n') - return (s[0:3], s[4:]) - - def ping(self): - self.wfh.write('PING\n') - (code, string) = self.get_response() - return code == '000' - +from VendingMachine import VendingMachine if __name__ == '__main__': # Open vending machine via LAT latclient = LATClient(service = 'VEND', password = 'dmscptd') (rfh, wfh) = latclient.get_fh() v = VendingMachine(rfh, wfh) - print v.ping() + print 'PING is', v.ping() + print 'BEEP is', v.beep() + print 'VEND 11 is', v.vend('11') + print 'SILENCE is', v.silence() + print 'DISPLAY is', v.display('GOOD NIGHT')