Skip to content

Commit

Permalink
Change the logic for when to retry at a different baud rate.
Browse files Browse the repository at this point in the history
  • Loading branch information
David Betz authored and David Betz committed Sep 29, 2017
1 parent 65acb6c commit c4205c0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
22 changes: 14 additions & 8 deletions src/fastloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,11 @@ int Loader::fastLoadImageHelper(const uint8_t *image, int imageSize, LoadType lo

/* generate a loader image */
loaderImage = generateInitialLoaderImage(packetID, fastLoaderBaudRate, &loaderImageSize);
if (!loaderImage)
if (!loaderImage) {
message("generateInitialLoaderImage failed");
nerror(ERROR_INTERNAL_CODE_ERROR);
return -1;
}

/* load the second-stage loader using the Propeller ROM protocol */
message("Delivering second-stage loader");
Expand All @@ -200,6 +203,7 @@ int Loader::fastLoadImageHelper(const uint8_t *image, int imageSize, LoadType lo
/* open the transparent serial connection that will be used for the second-stage loader */
if (m_connection->connect() != 0) {
message("Failed to connect to target");
nerror(ERROR_COMMUNICATION_LOST);
return -1;
}

Expand All @@ -212,7 +216,7 @@ int Loader::fastLoadImageHelper(const uint8_t *image, int imageSize, LoadType lo
if ((size = remaining) > m_connection->maxDataSize())
size = m_connection->maxDataSize();
if ((sts = transmitPacket(packetID, image, size, &result)) != 0)
return sts;
return -2;
if (result != packetID - 1) {
message("Unexpected response: expected %d, received %d", packetID - 1, result);
return -2;
Expand Down Expand Up @@ -244,7 +248,7 @@ int Loader::fastLoadImageHelper(const uint8_t *image, int imageSize, LoadType lo
return sts;
if (result != -checksum) {
nmessage(ERROR_RAM_CHECKSUM_FAILED);
return -2;
return -1;
}
packetID = -checksum;

Expand All @@ -254,7 +258,7 @@ int Loader::fastLoadImageHelper(const uint8_t *image, int imageSize, LoadType lo
return sts;
if (result != -checksum*2) {
nmessage(ERROR_EEPROM_CHECKSUM_FAILED);
return -2;
return -1;
}
packetID = -checksum*2;
}
Expand All @@ -266,7 +270,7 @@ int Loader::fastLoadImageHelper(const uint8_t *image, int imageSize, LoadType lo
return sts;
if (result != packetID - 1) {
message("ReadyToLaunch failed: expected %08x, got %08x", packetID - 1, result);
return -2;
return -1;
}
--packetID;

Expand All @@ -291,8 +295,10 @@ int Loader::transmitPacket(int id, const uint8_t *payload, int payloadSize, int
int32_t tag, rtag;

/* build the packet to transmit */
if (!(packet = (uint8_t *)malloc(packetSize)))
if (!(packet = (uint8_t *)malloc(packetSize))) {
nmessage(ERROR_INSUFFICIENT_MEMORY);
return -1;
}
setLong(&packet[0], id);
memcpy(&packet[8], payload, payloadSize);

Expand All @@ -309,7 +315,7 @@ int Loader::transmitPacket(int id, const uint8_t *payload, int payloadSize, int
setLong(&packet[4], tag);
//printf("transmit packet %d - tag %08x, size %d\n", id, tag, packetSize);
if (m_connection->sendData(packet, packetSize) != packetSize) {
message("transmitPacket %d failed - sendData", id);
nmessage(ERROR_INTERNAL_CODE_ERROR);
free(packet);
return -1;
}
Expand Down Expand Up @@ -344,6 +350,6 @@ int Loader::transmitPacket(int id, const uint8_t *payload, int payloadSize, int

/* return timeout */
message("transmitPacket %d failed - timeout", id);
return -2;
return -1;
}

12 changes: 8 additions & 4 deletions src/wifipropconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,16 @@ Content-Length: %d\r\n\
}

/* find the response body */
if (!(body = getBody(buffer, cnt, &cnt)))
return -1;
if (!(body = getBody(buffer, cnt, &cnt))) {
nerror(ERROR_COMMUNICATION_LOST);
return -2;
}

/* copy the body to the response if it fits */
if (cnt != responseSize)
return -1;
if (cnt != responseSize) {
nerror(ERROR_COMMUNICATION_LOST);
return -2;
}
memcpy(response, body, cnt);

return 0;
Expand Down

0 comments on commit c4205c0

Please sign in to comment.