Skip to content

Commit 90457ac

Browse files
committed
Added version to start header. Remote sends back wrong version. Need to implement version query
1 parent 57c42b4 commit 90457ac

File tree

6 files changed

+32
-151
lines changed

6 files changed

+32
-151
lines changed

arduino/library/RemoteUploader/RemoteUploader.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,11 @@ int RemoteUploader::process(uint8_t packet[]) {
644644
getDebugSerial()->println("Received start packet");
645645
#endif
646646

647+
if (packet[] != VERSION) {
648+
// TODO send the version number
649+
return WRONG_VERSION_ERROR;
650+
}
651+
647652
if (inProgramming) {
648653
// ok. we'll reset
649654
}

arduino/library/RemoteUploader/RemoteUploader.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
// Must also enable a DEBUG when using this. With atmega328/168 you would need to use SoftSerial
4242
#define VERBOSE false
4343

44+
// indicates compatibility with host program
45+
#define VERSION 1
46+
4447
// The remaining config should be fine for vast majority of cases
4548

4649
// Default optiboot speed for 5V Arduinos
@@ -100,6 +103,7 @@
100103
#define NOBOOTLOADER_ERROR 8
101104
#define VERIFY_PAGE_ERROR 9
102105
#define ADDRESS_SKIP_ERROR 0xa
106+
#define WRONG_VERSION_ERROR 0xb
103107

104108
// STK CONSTANTS
105109
#define STK_OK 0x10

java/src/main/java/com/rapplogic/aru/uploader/SketchUploader.java

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,13 @@ public abstract class SketchUploader extends SketchCore {
4949
public final int CONTROL_WRITE_EEPROM = 0x20;
5050
// somewhat redundant
5151
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;
5257

53-
// repsonse/error codes must sync the arduino header file
58+
// response/error codes must sync the arduino header file
5459
public final int OK = 1;
5560
public final int START_OVER = 2;
5661
public final int TIMEOUT = 3;
@@ -175,19 +180,24 @@ protected void waitForAck(final int ackTimeoutMillis, int id) throws NoAckExcept
175180
throw new NoAckException("No ACK from transport device after " + ackTimeoutMillis + "ms");
176181
}
177182

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[] {
180185
MAGIC_BYTE1,
181186
MAGIC_BYTE2,
182187
CONTROL_PROG_REQUEST,
183-
10, //length of this header
188+
-1, //length set below
184189
(sizeInBytes >> 8) & 0xff,
185190
sizeInBytes & 0xff,
186191
(numPages >> 8) & 0xff,
187192
numPages & 0xff,
188193
bytesPerPage,
189-
timeout & 0xff
194+
timeout & 0xff,
195+
version
190196
};
197+
198+
header[3] = header.length;
199+
200+
return header;
191201
}
192202

193203
// TODO consider adding retry bit to header
@@ -196,14 +206,18 @@ public int[] getStartHeader(int sizeInBytes, int numPages, int bytesPerPage, int
196206
// NOTE if header size is ever changed must also change PROG_DATA_OFFSET in library
197207
// xbee has error detection built-in but other protocols may need a checksum
198208
private int[] getHeader(int controlByte, int addressOrSize, int dataLength) {
199-
return new int[] {
209+
int[] header = new int[] {
200210
MAGIC_BYTE1,
201211
MAGIC_BYTE2,
202212
controlByte,
203-
dataLength + 6, //length + 6 bytes for header
213+
-1, //set below
204214
(addressOrSize >> 8) & 0xff,
205215
addressOrSize & 0xff
206216
};
217+
218+
header[3] = dataLength + header.length;
219+
220+
return header;
207221
}
208222

209223
protected int getPacketId(int[] reply) {
@@ -264,7 +278,7 @@ public void process(String file, int pageSize, final int ackTimeoutMillis, int a
264278
open(context);
265279

266280
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);
268282

269283
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));
270284

java/src/main/java/com/rapplogic/aru/uploader/wifi/WifiSketchUploader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ private void runFromCmdLine(String[] args) throws org.apache.commons.cli.ParseEx
250250

251251
/**
252252
* ex
253-
ceylon:arduino-remote-uploader-1.0-SNAPSHOT andrew$ ./wifi-uploader.sh -d --host 192.168.1.115 --port 1111 -s ../../../resources/BlinkSlow.cpp.hex
253+
ceylon:arduino-remote-uploader-1.0-SNAPSHOT andrew$ ./wifi-uploader.sh --host 192.168.1.115 --port 1111 -s ../../../resources/BlinkSlow.cpp.hex
254254
Sending sketch to wifi radio, size 1102 bytes, md5 8e7a58576bdc732d3f9708dab9aea5b9, number of packets 43, and 26 bytes per packet, header ef,ac,10,a,4,4e,0,2b,1a,3c
255255
Sending page 1 of 43, with address 0, length 32, packet ef,ac,20,20,0,0,c,94,61,0,c,94,7e,0,c,94,7e,0,c,94,7e,0,c,94,7e,0,c,94,7e,0,c,94
256256
Sending page 2 of 43, with address 26, length 32, packet ef,ac,20,20,0,1a,7e,0,c,94,7e,0,c,94,7e,0,c,94,7e,0,c,94,7e,0,c,94,7e,0,c,94,7e,0

resources/BlinkFast.cpp.hex

Lines changed: 0 additions & 71 deletions
This file was deleted.

resources/BlinkSlow.cpp.hex

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)