Skip to content

Commit

Permalink
Add macro for NIST response bytes
Browse files Browse the repository at this point in the history
Signed-off-by: Sara Damiano <[email protected]>
  • Loading branch information
SRGDamia1 committed Sep 6, 2024
1 parent b1f45a1 commit 5cb504f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/modems/DigiXBeeWifi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,15 +405,15 @@ uint32_t DigiXBeeWifi::getNISTTime(void) {
// Wait up to 5 seconds for a response
if (connectionMade) {
uint32_t start = millis();
while (gsmClient && gsmClient.available() < 4 &&
while (gsmClient && gsmClient.available() < NIST_RESPONSE_BYTES &&
millis() - start < 5000L) {
// wait
}

if (gsmClient.available() >= 4) {
MS_DBG(F("NIST responded after"), millis() - start, F("ms"));
byte response[4] = {0};
gsmClient.read(response, 4);
byte response[NIST_RESPONSE_BYTES] = {0};
gsmClient.read(response, NIST_RESPONSE_BYTES);
gsmClient.stop();
return parseNISTBytes(response);
} else {
Expand Down
13 changes: 8 additions & 5 deletions src/modems/LoggerModemMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -458,13 +458,16 @@
* @brief The port hosting the NIST "time" protocol (37)
*/
#define TIME_PROTOCOL_PORT 37
/**
* @brief The size of the NIST response from the "time" protocol, in bytes.
*/
#define NIST_RESPONSE_BYTES 4

// Try up to 4 NIST IP addresses attempting to get a timestamp from NIST
#if !defined NIST_SERVER_RETRYS || defined(DOXYGEN)
/**
* @brief The number of retry attempts when connecting to the NIST server.
*/
#define NIST_SERVER_RETRYS 4
#define NIST_SERVER_RETRYS 12
#endif // NIST_SERVER_RETRYS

/**
Expand Down Expand Up @@ -511,11 +514,11 @@
gsmClient.available() < NIST_SERVER_RETRYS && \
millis() - start < 5000L) {} \
\
if (gsmClient.available() >= 4) { \
if (gsmClient.available() >= NIST_RESPONSE_BYTES) { \
MS_DBG(F("NIST responded after"), millis() - start, \
F("ms")); \
byte response[4] = {0}; \
gsmClient.read(response, 4); \
byte response[NIST_RESPONSE_BYTES] = {0}; \
gsmClient.read(response, NIST_RESPONSE_BYTES); \
if (gsmClient.connected()) gsmClient.stop(); \
return parseNISTBytes(response); \
} else { \
Expand Down

0 comments on commit 5cb504f

Please sign in to comment.