- self.await_prompt()
- return (code, text)
-
- def handle_event(self, code, text):
- pass
-
- def authed_message(self, message):
- if self.challenge == None:
- return message
- crc = do_crc('%c%c'%(self.challenge >> 8, self.challenge & 0xff))
- crc = do_crc(self.secret, crc)
- crc = do_crc(message, crc)
- return message+'|'+('%04x'%crc)
-
- def ping(self):
- self.wfh.write('PING\n')
- (code, string) = self.get_response()
- return (code == '000', code, string)
-
- def vend(self, item):
- if not re.search('^[0-9][0-9]$', item):
- return (False, 'Invalid item requested (%s)'%item)
- self.wfh.write(self.authed_message(('V%s\n'%item)+'\n'))
- (code, string) = self.get_response()
- return (code, string)
-
- def beep(self, duration = None, synchronous = True):
- msg = 'B'
- if synchronous: msg += 'S'
- if duration != None:
- if duration > 255: duration = 255
- if duration < 1: duration = 1
- msg += '%02x'%duration
- self.wfh.write(msg+'\n')
- (code, string) = self.get_response()
- return (code == '500', code, string)
-
- def silence(self, duration = None, synchronous = True):
- msg = 'C'
- if synchronous: msg += 'S'
- if duration != None:
- if duration > 255: duration = 255
- if duration < 1: duration = 1
- msg += '%02x'%duration
- self.wfh.write(msg+'\n')
- (code, string) = self.get_response()
- # FIXME: workaround a bug in rom W. should be just: return (code == '500', code, string)
- return (code == '500' or code == '501', code, string)
-
- def display(self, string):
- if len(string) > 10:
- string = string[0:10]
- self.wfh.write('D'+string+'\n')
- (code, string) = self.get_response()
- return (code == '300', code, string)
+ query = 'SELECT vend_failed(%s)'%id
+ self.db.query(query).getresult()
+
+ def handle_events(self):
+ notifier = self.db.getnotify()
+ while notifier is not None:
+ self.process_requests()
+ notify = self.db.getnotify()
+
+def get_pin(uid):
+ try:
+ info = pwd.getpwuid(uid)
+ except KeyError:
+ return None
+ if info.pw_dir == None: return False
+ pinfile = os.path.join(info.pw_dir, '.pin')
+ try:
+ s = os.stat(pinfile)
+ except OSError:
+ return False
+ if s.st_mode & 077:
+ return None
+ try:
+ f = file(pinfile)
+ except IOError:
+ return None
+ pinstr = f.readline()
+ f.close()
+ if not re.search('^'+'[0-9]'*PIN_LENGTH+'$', pinstr):
+ return None
+ return int(pinstr)
+
+def has_good_pin(uid):
+ return get_pin != None
+
+def verify_user_pin(uid, pin):
+ if get_pin(uid) == pin:
+ info = pwd.getpwuid(uid)
+ return info.pw_name
+ else:
+ return None
+
+def door_open_mode(vending_machine):
+ print "Entering open door mode"
+ v.display("DOOR OPEN")
+ while True:
+ v.wait_for_events(1)
+ while True:
+ e = v.next_event()
+ if e == None: break
+ (event, params) = e
+ if event == DOOR:
+ if params == 1: # door closed
+ v.display("BYE BYE!")
+ time.sleep(1)
+ return