Skip to content

Commit 0d30b50

Browse files
David BetzDavid Betz
David Betz
authored and
David Betz
committed
Remove toggle.elf from the automatically built test programs.
Add more dependency info.
1 parent 69b5eb5 commit 0d30b50

9 files changed

+103
-50
lines changed

Makefile

+3-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ $(OSINT)
112112
CFLAGS+=-I$(OBJDIR)
113113
CPPFLAGS=$(CFLAGS)
114114

115-
all: $(BINDIR)/proploader$(EXT) $(BUILD)/blink-fast.binary $(BUILD)/blink-slow.binary $(BUILD)/toggle.elf
115+
all: $(BINDIR)/proploader$(EXT) $(BUILD)/blink-fast.binary $(BUILD)/blink-slow.binary
116+
117+
ctests: $(BUILD)/toggle.elf
116118

117119
$(OBJS): $(OBJDIR)/created $(HDRS) $(OBJDIR)/IP_Loader.h Makefile
118120

README.md

+13
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,16 @@ In addition to a standard C++ toolset you also need to install OpenSpin and have
1616
in your path.
1717

1818
https://github.com/parallaxinc/OpenSpin
19+
20+
To build the Windows version under Linux you will need the MinGW toolchain installed.
21+
Then type:
22+
23+
make CROSS=win32
24+
25+
Output files are placed:
26+
27+
Macintosh: ../proploader-macosx-build/bin
28+
Linux: ../proploader-linux-build/bin
29+
Windows: ../proploader-msys-build/bin
30+
31+
To build the C test programs you also need PropGCC installed an in your path.

src/enumcom.c

+31-11
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,38 @@ int SerialFind(const char* prefix, int (*check)(const char* port, void* data), v
104104
//printf("Device path: %s\n", pDetData->DevicePath);
105105
//printf("Friendly name: %s\n", fname);
106106
//printf("Description: %s\n", desc);
107-
if ((comx = strrchr(fname, '(')) != NULL)
108-
++comx;
109-
else
110-
comx = fname;
111-
if ((p = strchr(comx, ')')) != NULL)
112-
*p = '\0';
113-
if ((*check)(comx, data) == 0) {
114-
rc = 0;
115-
goto done;
116-
}
117-
}
118107

108+
// handle a friendly name with the device name embedded in the form "(COMnn)"
109+
if ((comx = strstr(fname, "(COM")) != NULL) {
110+
if (isdigit(comx[4])) {
111+
for (p = ++comx + 4; *p != '\0' && *p != ')'; ++p) {
112+
if (!isdigit(*p))
113+
break;
114+
}
115+
if (*p == ')') {
116+
*p = '\0';
117+
if ((*check)(comx, data) == 0) {
118+
rc = 0;
119+
goto done;
120+
}
121+
}
122+
}
123+
}
124+
125+
// handle a friendly name of the form "COMnn"
126+
else if (strncmp(fname, "COM", 3) == 0) {
127+
for (p = fname + 3; *p != '\0'; ++p) {
128+
if (!isdigit(*p))
129+
break;
130+
}
131+
if (*p == '\0') {
132+
if ((*check)(comx, data) == 0) {
133+
rc = 0;
134+
goto done;
135+
}
136+
}
137+
}
138+
}
119139
}
120140
else {
121141
printf("error: SetupDiGetDeviceInterfaceDetail failed. (err=%lx)\n", GetLastError());

src/main.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,12 @@ int main(int argc, char *argv[])
218218
sprintf(buf, "/dev/%s-%s", PORT_PREFIX, port);
219219
port = buf;
220220
}
221+
if (strncmp(port, "/dev/tty.", 9) == 0) {
222+
static char buf[64];
223+
sprintf(buf, "/dev/cu.%s", &port[9]);
224+
nmessage(INFO_USING_ALTERNATE_PORT, buf, port);
225+
port = buf;
226+
}
221227
#endif
222228
useSerial = true;
223229
break;

src/messages.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ static const char *infoText[] = {
3838
"Writing '%s' to the SD card",
3939
"%ld bytes remaining ",
4040
"%ld bytes sent ",
41-
"Setting module name to '%s'"
41+
"Setting module name to '%s'",
42+
"Using port %s instead of port %s"
4243
};
4344

4445
// message codes 100 and up -- must be in the same order as the ERROR_xxx enum values in messsages.h
@@ -47,7 +48,7 @@ static const char *errorText[] = {
4748
"Invalid address: %s",
4849
"Download failed: %d",
4950
"Can't open file '%s'",
50-
"Propeller not found on port %s",
51+
"Propeller not found on %s",
5152
"Failed to enter terminal mode",
5253
"Unrecognized wi-fi module firmware\n\
5354
Version is %s but expected %s.\n\
@@ -68,7 +69,8 @@ static const char *errorText[] = {
6869
"Internal error",
6970
"Insufficient memory",
7071
"No reset method '%s'",
71-
"Reset failed"
72+
"Reset failed",
73+
"Wrong Propeller version: got %d, expected 1"
7274
};
7375

7476
static void vmessage(const char *fmt, va_list ap, int eol);
@@ -127,7 +129,7 @@ void nprogress(int code, ...)
127129
{
128130
va_list ap;
129131
va_start(ap, code);
130-
vnmessage(code, messageText(code), ap, '\n');
132+
vnmessage(code, messageText(code), ap, '\r');
131133
va_end(ap);
132134
}
133135

src/messages.h

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ enum {
4545
/* 008 */ INFO_BYTES_REMAINING,
4646
/* 009 */ INFO_BYTES_SENT,
4747
/* 010 */ INFO_SETTING_MODULE_NAME,
48+
/* 011 */ INFO_USING_ALTERNATE_PORT,
4849
MAX_INFO,
4950

5051
MIN_ERROR = 100,

src/serialloader.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ int SerialPropConnection::loadImage(const uint8_t *image, int imageSize, LoadTyp
352352

353353
/* verify the handshake response */
354354
if (cnt != sizeof(rxHandshake) + 4 || memcmp(packet2, rxHandshake, sizeof(rxHandshake)) != 0) {
355-
message("Handshake failed");
355+
nmessage(ERROR_PROPELLER_NOT_FOUND, portName());
356356
return -1;
357357
}
358358

@@ -361,7 +361,7 @@ int SerialPropConnection::loadImage(const uint8_t *image, int imageSize, LoadTyp
361361
for (i = sizeof(rxHandshake); i < cnt; ++i)
362362
version = ((version >> 2) & 0x3F) | ((packet2[i] & 0x01) << 6) | ((packet2[i] & 0x20) << 2);
363363
if (version != 1) {
364-
message("Wrong propeller version");
364+
nmessage(ERROR_WRONG_PROPELLER_VERSION, version);
365365
return -1;
366366
}
367367

@@ -376,12 +376,14 @@ int SerialPropConnection::loadImage(const uint8_t *image, int imageSize, LoadTyp
376376
/* check for timeout */
377377
if (cnt <= 0) {
378378
message("Timeout waiting for checksum");
379+
nmessage(ERROR_DOWNLOAD_FAILED);
379380
return -1;
380381
}
381382

382383
/* verify the checksum response */
383384
if (packet2[0] != 0xFE) {
384385
message("Loader checksum failed: expected 0xFE, got %02x", packet2[0]);
386+
nmessage(ERROR_DOWNLOAD_FAILED);
385387
return -1;
386388
}
387389

src/wifipropconnection.cpp

+36-30
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ int WiFiPropConnection::identify(int *pVersion)
9898

9999
int WiFiPropConnection::loadImage(const uint8_t *image, int imageSize, uint8_t *response, int responseSize)
100100
{
101-
uint8_t buffer[1024], *packet, *p;
101+
uint8_t buffer[1024], *packet, *body;
102102
int hdrCnt, result, cnt;
103103

104104
/* use the initial loader baud rate */
@@ -126,22 +126,13 @@ Content-Length: %d\r\n\
126126
}
127127

128128
/* find the response body */
129-
p = buffer;
130-
while (cnt >= 4 && (p[0] != '\r' || p[1] != '\n' || p[2] != '\r' || p[3] != '\n')) {
131-
--cnt;
132-
++p;
133-
}
134-
135-
/* make sure we found the \r\n\r\n that terminates the header */
136-
if (cnt < 4)
129+
if (!(body = getBody(buffer, cnt, &cnt)))
137130
return -1;
138-
cnt -= 4;
139-
p += 4;
140-
131+
141132
/* copy the body to the response if it fits */
142-
if (cnt > responseSize)
133+
if (cnt != responseSize)
143134
return -1;
144-
memcpy(response, p, cnt);
135+
memcpy(response, body, cnt);
145136

146137
return 0;
147138
}
@@ -351,15 +342,15 @@ bool WiFiPropConnection::isOpen()
351342

352343
int WiFiPropConnection::getVersion()
353344
{
354-
uint8_t buffer[1024];
355-
int hdrCnt, result, srcLen;
356-
char *src, *dst;
345+
uint8_t buffer[1024], *body;
346+
int hdrCnt, result, cnt;
347+
char *dst;
357348

358349
hdrCnt = snprintf((char *)buffer, sizeof(buffer), "\
359350
GET /wx/setting?name=version HTTP/1.1\r\n\
360351
\r\n");
361352

362-
if (sendRequest(buffer, hdrCnt, buffer, sizeof(buffer), &result) == -1) {
353+
if ((cnt = sendRequest(buffer, hdrCnt, buffer, sizeof(buffer), &result)) == -1) {
363354
message("Get version failed");
364355
return -1;
365356
}
@@ -368,28 +359,23 @@ GET /wx/setting?name=version HTTP/1.1\r\n\
368359
return -1;
369360
}
370361

371-
src = (char *)buffer;
372-
srcLen = strlen(src);
373-
374-
while (srcLen >= 4) {
375-
if (src[0] == '\r' && src[1] == '\n' && src[2] == '\r' && src[3] == '\n')
376-
break;
377-
--srcLen;
378-
++src;
379-
}
380-
if (srcLen <= 4) {
362+
if (!(body = getBody(buffer, cnt, &cnt)))
363+
return -1;
364+
365+
if (cnt <= 0) {
381366
message("No version string");
382367
return -1;
383368
}
384369

385-
if (!(dst = (char *)malloc(srcLen - 4 + 1))) {
370+
if (!(dst = (char *)malloc(cnt + 1))) {
386371
nmessage(ERROR_INSUFFICIENT_MEMORY);
387372
return -1;
388373
}
389374

390375
if (m_version)
391376
free(m_version);
392-
strcpy(dst, src + 4);
377+
strncpy(dst, (char *)body, cnt);
378+
body[cnt] = '\0';
393379
m_version = dst;
394380

395381
return 0;
@@ -559,6 +545,26 @@ int WiFiPropConnection::sendRequest(uint8_t *req, int reqSize, uint8_t *res, int
559545
return cnt;
560546
}
561547

548+
uint8_t *WiFiPropConnection::getBody(uint8_t *msg, int msgSize, int *pBodySize)
549+
{
550+
uint8_t *p = msg;
551+
int cnt = msgSize;
552+
553+
/* find the message body */
554+
while (cnt >= 4 && (p[0] != '\r' || p[1] != '\n' || p[2] != '\r' || p[3] != '\n')) {
555+
--cnt;
556+
++p;
557+
}
558+
559+
/* make sure we found the \r\n\r\n that terminates the header */
560+
if (cnt < 4)
561+
return NULL;
562+
563+
/* return the body */
564+
*pBodySize = cnt - 4;
565+
return p + 4;
566+
}
567+
562568
void WiFiPropConnection::dumpHdr(const uint8_t *buf, int size)
563569
{
564570
int startOfLine = true;

src/wifipropconnection.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
#define WIFI_PROGRAM_BAUD_RATE 115200
1515

1616
// timeout used when making an HTTP request or connecting a telnet session
17-
#define CONNECT_TIMEOUT 2000
18-
#define RESPONSE_TIMEOUT 2000
17+
#define CONNECT_TIMEOUT 3000
18+
#define RESPONSE_TIMEOUT 3000
1919
#define DISCOVER_REPLY_TIMEOUT 250
2020
#define DISCOVER_ATTEMPTS 3
2121

@@ -60,6 +60,7 @@ class WiFiPropConnection : public PropConnection
6060
static int findModules(bool show, WiFiInfoList &list, int count = -1);
6161
private:
6262
int sendRequest(uint8_t *req, int reqSize, uint8_t *res, int resMax, int *pResult);
63+
static uint8_t *getBody(uint8_t *msg, int msgSize, int *pBodySize);
6364
static void dumpHdr(const uint8_t *buf, int size);
6465
static void dumpResponse(const uint8_t *buf, int size);
6566
char *m_ipaddr;

0 commit comments

Comments
 (0)