Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/TheThingsNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,12 @@ void TheThingsNetwork::clearReadBuffer()
}
}

size_t TheThingsNetwork::readLine(char *buffer, size_t size)
size_t TheThingsNetwork::readLine(char *buffer, size_t size, uint8_t attempts)
{
size_t read = 0;
while (read == 0)
while (read == 0 && attempts > 0)
{
attempts--;
read = modemStream->readBytesUntil('\n', buffer, size);
}
buffer[read - 1] = '\0'; // set \r to \0
Expand Down Expand Up @@ -434,7 +435,6 @@ void TheThingsNetwork::saveState()
sendCommand(MAC_TABLE, MAC_SAVE, false);
modemStream->write(SEND_MSG);
debugPrintLn();
waitForOk();
}

void TheThingsNetwork::onMessage(void (*cb)(const uint8_t *payload, size_t size, port_t port))
Expand Down Expand Up @@ -587,6 +587,11 @@ void TheThingsNetwork::showStatus()
{
readResponse(SYS_TABLE, SYS_TABLE, SYS_GET_HWEUI, buffer, sizeof(buffer));
debugPrintIndex(SHOW_EUI, buffer);
if (strlen(buffer) < 16)
{
debugPrintMessage(ERR_MESSAGE, ERR_UNEXPECTED_RESPONSE);
return;
}
readResponse(SYS_TABLE, SYS_TABLE, SYS_GET_VDD, buffer, sizeof(buffer));
debugPrintIndex(SHOW_BATTERY, buffer);
readResponse(MAC_TABLE, MAC_GET_SET_TABLE, MAC_APPEUI, buffer, sizeof(buffer));
Expand Down
2 changes: 1 addition & 1 deletion src/TheThingsNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class TheThingsNetwork
void (*messageCallback)(const uint8_t *payload, size_t size, port_t port);

void clearReadBuffer();
size_t readLine(char *buffer, size_t size);
size_t readLine(char *buffer, size_t size, uint8_t attempts = 10);
size_t readResponse(uint8_t prefixTable, uint8_t indexTable, uint8_t index, char *buffer, size_t size);
size_t readResponse(uint8_t table, uint8_t index, char *buffer, size_t size);

Expand Down