-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding attempts to readLine and state marker if radio module is unres… #244
Changes from 1 commit
4629038
0653d8d
012e651
9693732
77403c6
2a1968e
91d5b8b
2df5307
d4a6ce5
72fc4f2
71e3d0a
833ec1e
0fc3bc2
d74d17d
fe0c8ab
a0afabf
69ef443
896a8aa
88c81a0
13b554f
8c8cb8c
8ec0a25
a17f5e4
87dacf4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -357,15 +357,21 @@ void TheThingsNetwork::clearReadBuffer() | |
} | ||
} | ||
|
||
size_t TheThingsNetwork::readLine(char *buffer, size_t size) | ||
size_t TheThingsNetwork::readLine(char *buffer, size_t size, uint8_t attempts = 3) // Default timeout value 10s and is set in class initiator | ||
{ | ||
size_t read = 0; | ||
while (read == 0) | ||
while (read == 0 && attempts>0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spacing; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't you be decrementing |
||
{ | ||
read = modemStream->readBytesUntil('\n', buffer, size); | ||
} | ||
buffer[read - 1] = '\0'; // set \r to \0 | ||
return read; | ||
if(attempts<=0){ // If attempts is activated return 0 and set RN state marker | ||
this->radioModuleInvalidState = true; // Inform the application about the radio module is not responsive. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although this is a way to signal, still it requires action from the application. I don't really know if application developers know how to resolve this. The best way to resolve this is to reset the RN module through the reset pin. Would it be a good idea to configure (optionally) the reset pin, and engage a soft reset in the library at this point? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see your valid point. Now a good question is should we let the library handle the reset or give the decision to the application. If the library is resetting the RN module we will need to let the application know so the application can handle this, eg. by re-joining the network. One option could be to soft/hard reset the module every time this error occur, print a debug message with details and raise the flag. In this way we have raised awareness of a problem and tried to resolve it while giving power over the exception handling to the application. readLine is used in:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. However maybe the simple solution is the best. On error exit with debug message and error flag. Then update documentation and make a good example on how to handle the error on application level. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My wording was wrong; I meant hard reset, by using the reset pin. Sending the soft reset command is not going to work as the serial is broken already. And you're right, doing a hard reset in the midst of a join or TX operation, and restoring the state (i.e. joining again) is not going to work either. So I'm good with the signaling to the application. Please rename to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay. I will work on this and come back soon. |
||
return 0; | ||
} | ||
else{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please make spacing consistent around braces and brackets. Also no need for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
buffer[read - 1] = '\0'; // set \r to \0 | ||
return read; | ||
} | ||
} | ||
|
||
size_t TheThingsNetwork::readResponse(uint8_t prefixTable, uint8_t index, char *buffer, size_t size) | ||
|
@@ -417,7 +423,7 @@ void TheThingsNetwork::reset(bool adr) | |
size_t length = readResponse(SYS_TABLE, SYS_RESET, buffer, sizeof(buffer)); | ||
|
||
autoBaud(); | ||
length = readResponse(SYS_TABLE, SYS_TABLE, SYS_GET_VER, buffer, sizeof(buffer)); | ||
length = readResponse(SYS_TABLE, SYS_TABLE, SYS_GET_VER, buffer, sizeof(buffer)); | ||
|
||
// buffer contains "RN2xx3[xx] x.x.x ...", splitting model from version | ||
char *model = strtok(buffer, " "); | ||
|
@@ -436,6 +442,7 @@ void TheThingsNetwork::reset(bool adr) | |
sendMacSet(MAC_ADR, "off"); | ||
} | ||
this->adr = adr; | ||
this->radioModuleInvalidState = false; | ||
} | ||
|
||
void TheThingsNetwork::saveState() | ||
|
@@ -776,8 +783,8 @@ void TheThingsNetwork::configureKR920_923() | |
void TheThingsNetwork::configureIN865_867() | ||
{ | ||
sendMacSet(MAC_ADR, "off"); // TODO: remove when ADR is implemented for this plan | ||
sendMacSet(MAC_RX2, "2 866550000"); // SF10 | ||
sendMacSet(MAC_RX2, "2 866550000"); // SF10 | ||
|
||
// Disable the three default LoRaWAN channels | ||
sendChSet(MAC_CHANNEL_STATUS, 0, "off"); | ||
sendChSet(MAC_CHANNEL_STATUS, 1, "off"); | ||
|
@@ -1035,7 +1042,7 @@ void TheThingsNetwork::sleep(uint32_t mseconds) | |
} | ||
|
||
void TheThingsNetwork::wake() | ||
{ | ||
{ | ||
autoBaud(); | ||
} | ||
|
||
|
@@ -1051,7 +1058,7 @@ void TheThingsNetwork::linkCheck(uint16_t seconds) | |
modemStream->write(buffer); | ||
modemStream->write(SEND_MSG); | ||
debugPrintLn(buffer); | ||
waitForOk(); | ||
waitForOk(); | ||
} | ||
|
||
uint8_t TheThingsNetwork::getLinkCheckGateways() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is it set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
timeout is set in:
arduino-device-lib/src/TheThingsNetwork.cpp
Line 294 in 4629038
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set defaults in the header file