Revision 282
new network packet definitions
trunk/common/common.py | ||
---|---|---|
26 | 26 |
|
27 | 27 |
keypadTimeout = 31 #in seconds |
28 | 28 |
|
29 |
TT_GET_KEY = 'k' |
|
30 |
TT_SEND_KEY = 's' ############ put this in tooltron.py |
|
31 | 29 |
TT_ACK = 'a' |
32 | 30 |
TT_NACK = 'n' |
33 |
TT_TO = 'f' |
|
34 | 31 |
TT_TIMEOUT = 't' |
35 |
TT_ON = 'o' |
|
32 |
TT_KC = 'x' # A transaction containing a key and a card number |
|
33 |
TT_GRANT = 'q' # Tool access granted |
|
34 |
TT_DENY = 'f' # Tool access denied |
|
36 | 35 |
TT_PING = 'g' |
37 | 36 |
TT_BOOT = 'b' |
38 | 37 |
TT_PROGRAM_MODE = 'p' |
... | ... | |
48 | 47 |
|
49 | 48 |
BAUD_RATE = 9600 |
50 | 49 |
|
50 |
# cardbox id |
|
51 |
CARDBOX_ID = 2 |
|
52 |
|
|
51 | 53 |
#fails until a warning is sent |
52 | 54 |
MAX_TOOL_FAILS = 5 |
53 | 55 |
|
... | ... | |
101 | 103 |
def sendTool(t): |
102 | 104 |
tn = t |
103 | 105 |
print "sending power to tool ID",tn |
104 |
sendMessage(tn, TT_ON, "")
|
|
106 |
sendMessage(tn, TT_GRANT, "")
|
|
105 | 107 |
|
106 |
def sendKeyRequest(): |
|
107 |
print "sending key request" |
|
108 |
retries = 0 |
|
109 |
while retries < TT_MAX_RETRY: |
|
110 |
sendMessage(2, TT_GET_KEY, "") |
|
111 |
if checkAck(2): |
|
112 |
print "got ack for key request" |
|
113 |
return True |
|
114 |
else: |
|
115 |
print "ERROR: failed to get ack from GET_KEY, retrying..." |
|
116 |
retries += 1 |
|
108 |
def sendGrant(): |
|
109 |
print "seding grant to cardbox (",CARDBOX_ID," )" |
|
110 |
sendMessage(CARDBOX_ID, TT_GRANT, "") |
|
117 | 111 |
|
118 |
return False |
|
112 |
def sendDeny(): |
|
113 |
print "seding deny to cardbox (",CARDBOX_ID," )" |
|
114 |
sendMessage(CARDBOX_ID, TT_DENY, "") |
|
119 | 115 |
|
120 | 116 |
def sendAck(toolNum): |
121 | 117 |
print "seding ACK to",toolNum |
... | ... | |
188 | 184 |
print "ERROR: did not get start delimiter: "+str(ord(start)) |
189 | 185 |
return None |
190 | 186 |
|
191 |
def readKey():
|
|
192 |
startTime = time.time()
|
|
193 |
while time.time() - startTime < keypadTimeout:
|
|
194 |
m = readMessage()
|
|
195 |
if m != None:
|
|
196 |
[src, dest, cmd, data] = m
|
|
197 |
if cmd == TT_SEND_KEY:
|
|
198 |
return data[0]
|
|
199 |
elif cmd == TT_TIMEOUT:
|
|
200 |
raise TimeoutException("cardbox sent timeout packet")
|
|
201 |
else:
|
|
202 |
return None
|
|
187 |
#returns [key, carnum] pair
|
|
188 |
def readTransaction():
|
|
189 |
m = readMessage()
|
|
190 |
if m != None:
|
|
191 |
[src, dest, cmd, data] = m
|
|
192 |
if src == CARDBOX_ID and cmd == TT_KC and len(data) >= 2:
|
|
193 |
return data[0], data[1:end]
|
|
194 |
else:
|
|
195 |
print "ERROR: wrong size data from transaction"
|
|
196 |
logMessage("ERROR: got bad packet from cardbox")
|
|
197 |
sendNack(CARDBOX_IDX)
|
|
198 |
return None |
|
203 | 199 |
|
204 |
raise TimeoutException("we timed out waiting for cardbox key") |
|
205 | 200 |
|
206 | 201 |
#returns [src, dest, command] or [] on error |
207 | 202 |
# because of reflection, this will quietly ignore packets send by the server |
trunk/common/tooltron.h | ||
---|---|---|
27 | 27 |
#define SERVER 1 |
28 | 28 |
|
29 | 29 |
// These are the bytes used in the messaage types |
30 |
#define TT_GET_KEY 'k' // Get a key from the keyboard |
|
31 |
#define TT_SEND_KEY 's' // Send a Key back (has 1 extra data packet) |
|
32 | 30 |
#define TT_ACK 'a' // Ack |
33 | 31 |
#define TT_NACK 'n' // Nack |
34 |
#define TT_ON 'o' // Turn the tool on |
|
35 |
#define TT_TO 'f' // State timeout |
|
32 |
#define TT_KC 'x' // A transaction containing a key and a card number |
|
33 |
#define TT_GRANT 'q' // Tool access granted |
|
34 |
#define TT_DENY 'f' // Tool access denied |
|
36 | 35 |
#define TT_TIMEOUT 't' // Packet timeout |
37 | 36 |
#define TT_RESET 'r' // Tool reset request |
38 | 37 |
#define TT_BOOT 'b' // Tool boot message |
... | ... | |
41 | 40 |
#define TT_PING 'g' // Ping command |
42 | 41 |
#define TT_BAD 0 // If there was a packet parsing error |
43 | 42 |
|
43 |
// Depricated commands: |
|
44 |
//#define TT_GET_KEY 'k' // Get a key from the keyboard |
|
45 |
//#define TT_SEND_KEY 's' // Send a Key back (has 1 extra data packet) |
|
46 |
//#define TT_ON 'o' // Turn the tool on |
|
44 | 47 |
|
45 | 48 |
// Number of bytes that the PROGx packets have in the payload |
46 | 49 |
#define MAX_PAYLOAD_SIZE 32 |
Also available in: Unified diff