-
Notifications
You must be signed in to change notification settings - Fork 96
Adding attempts to readLine and state marker if radio module is unres… #244
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
Changes from 16 commits
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,13 +357,19 @@ 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 && attempts--) | ||
{ | ||
read = modemStream->readBytesUntil('\n', buffer, size); | ||
} | ||
if (attempts<=0) | ||
{ // If attempts is activated return 0 and set RN state marker | ||
this->needsHardReset = true; // Inform the application about the radio module is not responsive. | ||
debugPrintLn("No response from RN module."); | ||
return 0; | ||
} | ||
buffer[read - 1] = '\0'; // set \r to \0 | ||
return read; | ||
} | ||
|
@@ -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,17 @@ void TheThingsNetwork::reset(bool adr) | |
sendMacSet(MAC_ADR, "off"); | ||
} | ||
this->adr = adr; | ||
this->needsHardReset = false; | ||
} | ||
|
||
void TheThingsNetwork::resetHard(uint8_t resetPin){ | ||
digitalWrite(resetPin, LOW); | ||
unsigned long time_now = millis(); | ||
int period = 1000; | ||
while(millis() < time_now + period){ | ||
// wait | ||
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. Why not use 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. It was just to make it non-blocking in case the application is using interrupt. The reset function is not time critical. 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. Actually delay() is the better one to use. On some platforms where it is necessary delay() will call yield(), while a while loop will not. 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. Can you implement this @savnik ? |
||
} | ||
digitalWrite(resetPin, HIGH); | ||
savnik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
void TheThingsNetwork::saveState() | ||
|
@@ -776,8 +793,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 +1052,7 @@ void TheThingsNetwork::sleep(uint32_t mseconds) | |
} | ||
|
||
void TheThingsNetwork::wake() | ||
{ | ||
{ | ||
autoBaud(); | ||
} | ||
|
||
|
@@ -1051,7 +1068,7 @@ void TheThingsNetwork::linkCheck(uint16_t seconds) | |
modemStream->write(buffer); | ||
modemStream->write(SEND_MSG); | ||
debugPrintLn(buffer); | ||
waitForOk(); | ||
waitForOk(); | ||
} | ||
|
||
uint8_t TheThingsNetwork::getLinkCheckGateways() | ||
|
Uh oh!
There was an error while loading. Please reload this page.