Skip to content

Commit

Permalink
Remove toggle.elf from the automatically built test programs.
Browse files Browse the repository at this point in the history
Add more dependency info.
  • Loading branch information
David Betz authored and David Betz committed Apr 20, 2017
1 parent 69b5eb5 commit 0d30b50
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 50 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ $(OSINT)
CFLAGS+=-I$(OBJDIR)
CPPFLAGS=$(CFLAGS)

all: $(BINDIR)/proploader$(EXT) $(BUILD)/blink-fast.binary $(BUILD)/blink-slow.binary $(BUILD)/toggle.elf
all: $(BINDIR)/proploader$(EXT) $(BUILD)/blink-fast.binary $(BUILD)/blink-slow.binary

ctests: $(BUILD)/toggle.elf

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

Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,16 @@ In addition to a standard C++ toolset you also need to install OpenSpin and have
in your path.

https://github.com/parallaxinc/OpenSpin

To build the Windows version under Linux you will need the MinGW toolchain installed.
Then type:

make CROSS=win32

Output files are placed:

Macintosh: ../proploader-macosx-build/bin
Linux: ../proploader-linux-build/bin
Windows: ../proploader-msys-build/bin

To build the C test programs you also need PropGCC installed an in your path.
42 changes: 31 additions & 11 deletions src/enumcom.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,38 @@ int SerialFind(const char* prefix, int (*check)(const char* port, void* data), v
//printf("Device path: %s\n", pDetData->DevicePath);
//printf("Friendly name: %s\n", fname);
//printf("Description: %s\n", desc);
if ((comx = strrchr(fname, '(')) != NULL)
++comx;
else
comx = fname;
if ((p = strchr(comx, ')')) != NULL)
*p = '\0';
if ((*check)(comx, data) == 0) {
rc = 0;
goto done;
}
}

// handle a friendly name with the device name embedded in the form "(COMnn)"
if ((comx = strstr(fname, "(COM")) != NULL) {
if (isdigit(comx[4])) {
for (p = ++comx + 4; *p != '\0' && *p != ')'; ++p) {
if (!isdigit(*p))
break;
}
if (*p == ')') {
*p = '\0';
if ((*check)(comx, data) == 0) {
rc = 0;
goto done;
}
}
}
}

// handle a friendly name of the form "COMnn"
else if (strncmp(fname, "COM", 3) == 0) {
for (p = fname + 3; *p != '\0'; ++p) {
if (!isdigit(*p))
break;
}
if (*p == '\0') {
if ((*check)(comx, data) == 0) {
rc = 0;
goto done;
}
}
}
}
}
else {
printf("error: SetupDiGetDeviceInterfaceDetail failed. (err=%lx)\n", GetLastError());
Expand Down
6 changes: 6 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ int main(int argc, char *argv[])
sprintf(buf, "/dev/%s-%s", PORT_PREFIX, port);
port = buf;
}
if (strncmp(port, "/dev/tty.", 9) == 0) {
static char buf[64];
sprintf(buf, "/dev/cu.%s", &port[9]);
nmessage(INFO_USING_ALTERNATE_PORT, buf, port);
port = buf;
}
#endif
useSerial = true;
break;
Expand Down
10 changes: 6 additions & 4 deletions src/messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ static const char *infoText[] = {
"Writing '%s' to the SD card",
"%ld bytes remaining ",
"%ld bytes sent ",
"Setting module name to '%s'"
"Setting module name to '%s'",
"Using port %s instead of port %s"
};

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

static void vmessage(const char *fmt, va_list ap, int eol);
Expand Down Expand Up @@ -127,7 +129,7 @@ void nprogress(int code, ...)
{
va_list ap;
va_start(ap, code);
vnmessage(code, messageText(code), ap, '\n');
vnmessage(code, messageText(code), ap, '\r');
va_end(ap);
}

Expand Down
1 change: 1 addition & 0 deletions src/messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ enum {
/* 008 */ INFO_BYTES_REMAINING,
/* 009 */ INFO_BYTES_SENT,
/* 010 */ INFO_SETTING_MODULE_NAME,
/* 011 */ INFO_USING_ALTERNATE_PORT,
MAX_INFO,

MIN_ERROR = 100,
Expand Down
6 changes: 4 additions & 2 deletions src/serialloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ int SerialPropConnection::loadImage(const uint8_t *image, int imageSize, LoadTyp

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

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

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

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

Expand Down
66 changes: 36 additions & 30 deletions src/wifipropconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ int WiFiPropConnection::identify(int *pVersion)

int WiFiPropConnection::loadImage(const uint8_t *image, int imageSize, uint8_t *response, int responseSize)
{
uint8_t buffer[1024], *packet, *p;
uint8_t buffer[1024], *packet, *body;
int hdrCnt, result, cnt;

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

/* find the response body */
p = buffer;
while (cnt >= 4 && (p[0] != '\r' || p[1] != '\n' || p[2] != '\r' || p[3] != '\n')) {
--cnt;
++p;
}

/* make sure we found the \r\n\r\n that terminates the header */
if (cnt < 4)
if (!(body = getBody(buffer, cnt, &cnt)))
return -1;
cnt -= 4;
p += 4;


/* copy the body to the response if it fits */
if (cnt > responseSize)
if (cnt != responseSize)
return -1;
memcpy(response, p, cnt);
memcpy(response, body, cnt);

return 0;
}
Expand Down Expand Up @@ -351,15 +342,15 @@ bool WiFiPropConnection::isOpen()

int WiFiPropConnection::getVersion()
{
uint8_t buffer[1024];
int hdrCnt, result, srcLen;
char *src, *dst;
uint8_t buffer[1024], *body;
int hdrCnt, result, cnt;
char *dst;

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

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

src = (char *)buffer;
srcLen = strlen(src);

while (srcLen >= 4) {
if (src[0] == '\r' && src[1] == '\n' && src[2] == '\r' && src[3] == '\n')
break;
--srcLen;
++src;
}
if (srcLen <= 4) {
if (!(body = getBody(buffer, cnt, &cnt)))
return -1;

if (cnt <= 0) {
message("No version string");
return -1;
}

if (!(dst = (char *)malloc(srcLen - 4 + 1))) {
if (!(dst = (char *)malloc(cnt + 1))) {
nmessage(ERROR_INSUFFICIENT_MEMORY);
return -1;
}

if (m_version)
free(m_version);
strcpy(dst, src + 4);
strncpy(dst, (char *)body, cnt);
body[cnt] = '\0';
m_version = dst;

return 0;
Expand Down Expand Up @@ -559,6 +545,26 @@ int WiFiPropConnection::sendRequest(uint8_t *req, int reqSize, uint8_t *res, int
return cnt;
}

uint8_t *WiFiPropConnection::getBody(uint8_t *msg, int msgSize, int *pBodySize)
{
uint8_t *p = msg;
int cnt = msgSize;

/* find the message body */
while (cnt >= 4 && (p[0] != '\r' || p[1] != '\n' || p[2] != '\r' || p[3] != '\n')) {
--cnt;
++p;
}

/* make sure we found the \r\n\r\n that terminates the header */
if (cnt < 4)
return NULL;

/* return the body */
*pBodySize = cnt - 4;
return p + 4;
}

void WiFiPropConnection::dumpHdr(const uint8_t *buf, int size)
{
int startOfLine = true;
Expand Down
5 changes: 3 additions & 2 deletions src/wifipropconnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#define WIFI_PROGRAM_BAUD_RATE 115200

// timeout used when making an HTTP request or connecting a telnet session
#define CONNECT_TIMEOUT 2000
#define RESPONSE_TIMEOUT 2000
#define CONNECT_TIMEOUT 3000
#define RESPONSE_TIMEOUT 3000
#define DISCOVER_REPLY_TIMEOUT 250
#define DISCOVER_ATTEMPTS 3

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

0 comments on commit 0d30b50

Please sign in to comment.