Project

General

Profile

Revision 125

hopefully fixes the multi-swipe bug

View differences:

dustmite.py
1 1
#!/usr/bin/python
2 2

  
3
################################################################################
4
## dustmite.py is the main tooltron server
5
# It connects to the civicrm database of mysql and sends commands to
6
# the cardbox and tools.  It must be connected over usb to the card
7
# reader, and the two arguments specify the devices to use for the
8
# serial communication to the card and tool boxes.
9
#
10
# This script requires the modules seen below, which may not be
11
# present by default
12
#
13
# email bradneuman@gmail.com if you have any questions
14
################################################################################
15

  
16

  
3 17
import re
4 18
import sys
5 19
import serial
......
35 49
    db = MySQLdb.connect(host="roboclub8.frc.ri.cmu.edu", user="tooltron", passwd=pw, db="civicrm")
36 50
    print "connected, now accepting input"
37 51

  
38
#TODO: errors!
39

  
40 52
    cursor = db.cursor()
41 53

  
42 54
    qry = "SELECT tools_6 FROM civicrm_value_roboclub_info_2 WHERE card_number_1 = "
......
45 57
    keypad.flushInput()
46 58
    print keypad
47 59

  
48
    bus = serial.Serial(sys.argv[2], BAUD_RATE, timeout = 10)
60
    bus = serial.Serial(sys.argv[2], BAUD_RATE, timeout = 15)
49 61
    bus.flushInput()
50 62
    print bus
51 63

  
......
88 100

  
89 101

  
90 102
    while True:
91
#TODO: only consider the last valid id so only the last swipe since a button press will work
92 103
        s = raw_input()
93 104
        id = re.search('%([0-9]*)=.*', s)
94 105
        
95 106
        if id != None:
96
            print "-----------\nid# ", id.group(1)
107
            print "\n-----------\nid# ", id.group(1)
97 108

  
98 109

  
99
            print "waiting for key..."
110
            print "sending key request"
100 111
            keypad.write(TT_GET_KEY)
101 112

  
102 113
            cursor.execute(qry + id.group(1))
......
112 123
                        try:
113 124
                            acl.append (tools[t])
114 125
                        except KeyError:
115
                            print "ERROR: could not find key!"
126
                            #this doesn't really matter
127
                            pass
116 128

  
117 129
            print "user has access to:", acl
130

  
118 131
            resp = keypad.read(1)
119 132

  
120 133
            print "request:",resp
......
123 136
            if acl.count(resp) > 0:
124 137
                keypad.write(TT_ACK)
125 138
                sendTool(resp)
126
                print "send tool message..."
139
                print "ACCESS GRANTED"
127 140
                if checkAck(resp):
128 141
                    print "ACK"
129 142
                else:
......
131 144

  
132 145
            else:
133 146
                keypad.write(TT_NACK)
147
                print "ACCESS DENIED!!"
148

  
149
        fflush(stdin)

Also available in: Unified diff