Revision 208 trunk/programmer/netprog.py
| netprog.py (revision 208) | ||
|---|---|---|
| 4 | 4 |
|
| 5 | 5 |
TT_BOOT = 'b' |
| 6 | 6 |
TT_PROGRAM_MODE = 'p' |
| 7 |
TT_ACK = 'a' |
|
| 8 |
TT_NACK = 'n' |
|
| 7 |
TT_ACK = 'a' |
|
| 8 |
TT_NACK = 'n' |
|
| 9 | 9 |
TT_BAD = 0 |
| 10 | 10 |
TT_PROGD = 'd' |
| 11 |
TT_RESET = 'r' |
|
| 11 | 12 |
|
| 13 |
MAX_PROG_SIZE = 1024-32 |
|
| 14 |
|
|
| 12 | 15 |
DUMB_SERIAL = 0 |
| 13 | 16 |
|
| 14 | 17 |
BAUD_RATE = 9600 |
| ... | ... | |
| 19 | 22 |
print "usage: netprog.py /path/to/bus/device toolnum binaryfile" |
| 20 | 23 |
exit(1) |
| 21 | 24 |
|
| 22 |
#for testing, tool number 3 |
|
| 25 |
#for testing, tool number 3 hardcoded |
|
| 23 | 26 |
class dumbBus (serial.Serial): |
| 24 | 27 |
def __init__(self): |
| 25 | 28 |
self.step = 0 |
| ... | ... | |
| 47 | 50 |
bus = dumbBus() |
| 48 | 51 |
|
| 49 | 52 |
bus.flushInput() |
| 50 |
print bus |
|
| 51 | 53 |
|
| 52 | 54 |
def printMsg(msg): |
| 53 | 55 |
if len(msg) < 5: |
| ... | ... | |
| 142 | 144 |
flen = fin.tell() |
| 143 | 145 |
fin.seek(0,0) |
| 144 | 146 |
|
| 147 |
if flen > MAX_PROG_SIZE: |
|
| 148 |
print "Program too Large!" |
|
| 149 |
print "prog size:",flen |
|
| 150 |
print "max size:",MAX_PROG_SIZE |
|
| 151 |
exit(-1) |
|
| 152 |
|
|
| 153 |
print "prog size:",flen |
|
| 154 |
|
|
| 155 |
print "sending RESET" |
|
| 156 |
sendCommand(toolID, TT_RESET) |
|
| 157 |
|
|
| 145 | 158 |
print "waiting for boot packet..." |
| 146 | 159 |
while readPacket() != TT_BOOT: |
| 147 | 160 |
print "Didn't get a boot packet, bailing out" |
| 148 | 161 |
exit(-4) |
| 149 | 162 |
|
| 150 |
sendProgram(toolID, flen) |
|
| 151 |
r = readPacket() |
|
| 152 |
if r != TT_ACK: |
|
| 153 |
print "ERROR: tool did not ACK!!! got", r |
|
| 154 |
exit(-1) |
|
| 163 |
r = 0 |
|
| 164 |
while r != TT_ACK: |
|
| 165 |
sendProgram(toolID, flen) |
|
| 166 |
r = readPacket() |
|
| 167 |
if r == TT_NACK: |
|
| 168 |
print "WARNING: got NACK, trying again" |
|
| 169 |
if r == TT_BOOT: |
|
| 170 |
print "ERROR: got stray boot packet" |
|
| 171 |
#TODO: restart the whole state machine after the boot packet |
|
| 172 |
exit(-2) |
|
| 173 |
if r != TT_ACK: |
|
| 174 |
print "ERROR: got another packet:",r |
|
| 175 |
exit(-1) |
|
| 155 | 176 |
|
| 156 | 177 |
print 'sending data', |
| 157 | 178 |
sys.stdout.flush() |
| ... | ... | |
| 159 | 180 |
data = fin.read(MAX_DATA_LEN) |
| 160 | 181 |
#print data |
| 161 | 182 |
#print '-------------------' |
| 162 |
|
|
| 163 |
sendData(toolID, data) |
|
| 164 |
if readPacket() != TT_ACK: |
|
| 165 |
print "last data packet not ACK'd!!" |
|
| 183 |
if len(data) == 0: |
|
| 166 | 184 |
break |
| 167 | 185 |
|
| 186 |
r = 0 |
|
| 187 |
while r != TT_ACK: |
|
| 188 |
sendData(toolID, data) |
|
| 189 |
r = readPacket() |
|
| 190 |
if r == TT_NACK: |
|
| 191 |
print "WARNING: got NACK, trying again" |
|
| 192 |
if r == TT_BOOT: |
|
| 193 |
print "ERROR: got stray boot packet" |
|
| 194 |
#TODO: restart the whole state machine after the boot packet |
|
| 195 |
exit(-2) |
|
| 196 |
if r != TT_ACK: |
|
| 197 |
print "ERROR: got another packet:",r |
|
| 198 |
exit(-1) |
|
| 199 |
|
|
| 168 | 200 |
if len(data) < MAX_DATA_LEN: |
| 169 | 201 |
break |
Also available in: Unified diff