@@ -49,8 +49,13 @@ public abstract class SketchUploader extends SketchCore {
49
49
public final int CONTROL_WRITE_EEPROM = 0x20 ;
50
50
// somewhat redundant
51
51
public final int CONTROL_START_FLASH = 0x40 ;
52
+ // tell what version of uploader is running
53
+ public final int CONTROL_VERSION_QUERY = 0x80 ;
54
+
55
+ // releases with non-backwards compatible change to protocol should rev the version number
56
+ public final int VERSION = 1 ;
52
57
53
- // repsonse /error codes must sync the arduino header file
58
+ // response /error codes must sync the arduino header file
54
59
public final int OK = 1 ;
55
60
public final int START_OVER = 2 ;
56
61
public final int TIMEOUT = 3 ;
@@ -175,19 +180,24 @@ protected void waitForAck(final int ackTimeoutMillis, int id) throws NoAckExcept
175
180
throw new NoAckException ("No ACK from transport device after " + ackTimeoutMillis + "ms" );
176
181
}
177
182
178
- public int [] getStartHeader (int sizeInBytes , int numPages , int bytesPerPage , int timeout ) {
179
- return new int [] {
183
+ public int [] getStartHeader (int sizeInBytes , int numPages , int bytesPerPage , int timeout , int version ) {
184
+ int [] header = new int [] {
180
185
MAGIC_BYTE1 ,
181
186
MAGIC_BYTE2 ,
182
187
CONTROL_PROG_REQUEST ,
183
- 10 , //length of this header
188
+ - 1 , //length set below
184
189
(sizeInBytes >> 8 ) & 0xff ,
185
190
sizeInBytes & 0xff ,
186
191
(numPages >> 8 ) & 0xff ,
187
192
numPages & 0xff ,
188
193
bytesPerPage ,
189
- timeout & 0xff
194
+ timeout & 0xff ,
195
+ version
190
196
};
197
+
198
+ header [3 ] = header .length ;
199
+
200
+ return header ;
191
201
}
192
202
193
203
// TODO consider adding retry bit to header
@@ -196,14 +206,18 @@ public int[] getStartHeader(int sizeInBytes, int numPages, int bytesPerPage, int
196
206
// NOTE if header size is ever changed must also change PROG_DATA_OFFSET in library
197
207
// xbee has error detection built-in but other protocols may need a checksum
198
208
private int [] getHeader (int controlByte , int addressOrSize , int dataLength ) {
199
- return new int [] {
209
+ int [] header = new int [] {
200
210
MAGIC_BYTE1 ,
201
211
MAGIC_BYTE2 ,
202
212
controlByte ,
203
- dataLength + 6 , //length + 6 bytes for header
213
+ - 1 , //set below
204
214
(addressOrSize >> 8 ) & 0xff ,
205
215
addressOrSize & 0xff
206
216
};
217
+
218
+ header [3 ] = dataLength + header .length ;
219
+
220
+ return header ;
207
221
}
208
222
209
223
protected int getPacketId (int [] reply ) {
@@ -264,7 +278,7 @@ public void process(String file, int pageSize, final int ackTimeoutMillis, int a
264
278
open (context );
265
279
266
280
long start = System .currentTimeMillis ();
267
- final int [] startHeader = getStartHeader (sketch .getSize (), sketch .getPages ().size (), sketch .getBytesPerPage (), arduinoTimeoutSec );
281
+ final int [] startHeader = getStartHeader (sketch .getSize (), sketch .getPages ().size (), sketch .getBytesPerPage (), arduinoTimeoutSec , VERSION );
268
282
269
283
System .out .println ("Sending sketch to " + getName () + " radio, size " + sketch .getSize () + " bytes, md5 " + getMd5 (sketch .getProgram ()) + ", number of packets " + sketch .getPages ().size () + ", and " + sketch .getBytesPerPage () + " bytes per packet, header " + toHex (startHeader ));
270
284
0 commit comments