Skip to content

Commit ba6a7d6

Browse files
committed
more docs
Signed-off-by: Sara Damiano <sdamiano@stroudcenter.org>
1 parent 61577bf commit ba6a7d6

File tree

2 files changed

+124
-14
lines changed

2 files changed

+124
-14
lines changed

src/LoggerBase.cpp

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2140,9 +2140,10 @@ inline uint16_t Logger::serzQueuedFlushFile() {
21402140
MS_DEEP_DBG(F("seQFF opened "), tempFn);
21412141
}
21422142

2143-
// Get the length of the line being read
2143+
// Get the length of the last line that was deserialized
21442144
num_char = strlen(deszq_line);
2145-
// If there is data in the line being read, copy it to the new temp file
2145+
// If there is data in the last deserialized line, copy it to the new temp
2146+
// file
21462147
if (num_char) { // Test could be min size, but this unknown
21472148
MS_DBG(F("seQFF Last POST Failed "), deszq_line);
21482149
retNum = tgtoutFile.write(deszq_line, num_char);
@@ -2154,7 +2155,9 @@ inline uint16_t Logger::serzQueuedFlushFile() {
21542155

21552156
MS_DBG(F("seQFF cpy lines across"));
21562157
// While still able to read lines from the queue file, copy them to the new
2157-
// temp file
2158+
// temp file. This will proceed from the last point of entry to the file,
2159+
// not from the beginning, so only lines after the last one read will be
2160+
// transferred.
21582161
while (0 <
21592162
(num_char = serzQueuedFile.fgets(deszq_line, QUEFILE_MAX_LINE))) {
21602163
#if defined(USE_PS_modularSensorsNetwork)
@@ -2166,21 +2169,24 @@ inline uint16_t Logger::serzQueuedFlushFile() {
21662169
*/
21672170
postLogLine((MAX_NUMBER_SENDERS + 1), HTTPSTATUS_NC_903);
21682171
num_skipped++;
2169-
} else
2172+
} else {
21702173
#endif // USE_PS_modularSensorsNetwork
2171-
{
21722174

21732175
retNum = tgtoutFile.write(deszq_line, num_char);
21742176
// Squelch last char LF
21752177
deszq_line[sizeof(deszq_line) - 1] = 0;
21762178
MS_DBG(deszq_line);
2177-
if (retNum != num_char) {
2179+
if (retNum != num_char) { // If the number of characters read and
2180+
// written don't match
21782181
PRINTOUT(F("seQFF tgtoutFile write3 err"), num_char, retNum);
21792182
// sd1_Err("seQFF write4");
21802183
break;
21812184
}
2185+
// add one to the total number of lines in the file
21822186
num_lines++;
2187+
#if defined(USE_PS_modularSensorsNetwork)
21832188
}
2189+
#endif // USE_PS_modularSensorsNetwork
21842190
}
21852191
if (num_skipped) {
21862192
PRINTOUT(F("seQFF sendQueue Size "), _sendQueueSz_num, F(",queued"),
@@ -2197,8 +2203,9 @@ inline uint16_t Logger::serzQueuedFlushFile() {
21972203
}
21982204
}
21992205

2206+
// rename the old queue file to the deletable queue name
22002207
retBool = serzQueuedFile.rename(queDelFn);
2201-
if (!retBool) {
2208+
if (!retBool) { // If rename fails, reboot
22022209
PRINTOUT(F("seQFF REBOOT rename1 err"), queDelFn);
22032210
// Problem - unrecoverable, so reboot
22042211
retBool = serzQueuedFile.close();
@@ -2210,6 +2217,7 @@ inline uint16_t Logger::serzQueuedFlushFile() {
22102217
} else {
22112218
MS_DBG(F("seQFF cleanup rename "), serzQueuedFn, F("to"), queDelFn);
22122219

2220+
// close the original queue file
22132221
retBool = serzQueuedFile.close();
22142222
if (!retBool) {
22152223
sd1_Err("seQFF serzQueuedFile.close2 err");
@@ -2218,14 +2226,17 @@ inline uint16_t Logger::serzQueuedFlushFile() {
22182226
MS_DEEP_DBG(F("seQFF close serzQueuedFile"));
22192227
}
22202228

2229+
// rename the new temporary file to the proper queue file name
22212230
retBool = tgtoutFile.rename(serzQueuedFn);
22222231
if (!retBool) {
22232232
sd1_Err("seQFF tgtoutFile.rename err");
2233+
// return the number of lines copied from one file to the next
22242234
return num_lines;
22252235
} else {
22262236
MS_DEEP_DBG(F("seQFF rename "), tempFn, F("to"), serzQueuedFn);
22272237
}
22282238

2239+
// close the renamed temporary file
22292240
retBool = tgtoutFile.close();
22302241
if (!retBool) {
22312242
sd1_Err("seQFF tgtoutFile.close1 err");
@@ -2235,6 +2246,7 @@ inline uint16_t Logger::serzQueuedFlushFile() {
22352246
}
22362247
}
22372248

2249+
// return the number of lines copied from one file to the next
22382250
return num_lines;
22392251
} // serzQueuedFlushFile
22402252

@@ -2307,6 +2319,8 @@ char* Logger::deszFind(const char* in_line, char caller_id) {
23072319
bool Logger::deszRdelStart() {
23082320
deszLinesRead = 0;
23092321

2322+
// Reset the pointer for the next character to the start of the pointer for
2323+
// the whole line
23102324
deszq_nextChar = deszq_line;
23112325
// Open - RD & WR. WR needed to be able to delete when complete.
23122326
if (!serzRdelFile.open(serzRdelFn_str, (O_RDWR | O_CREAT))) {
@@ -2321,6 +2335,8 @@ bool Logger::deszRdelStart() {
23212335
bool Logger::deszQueuedStart() {
23222336
deszLinesRead = 0;
23232337

2338+
// Reset the pointer for the next character to the start of the pointer for
2339+
// the whole line
23242340
deszq_nextChar = deszq_line;
23252341
// Open - RD & WR. WR needed to be able to delete when complete.
23262342
// Expect serzQueuedFn to be setup in serzQueuedStart
@@ -2414,7 +2430,7 @@ bool Logger::deszqNextCh(void) {
24142430
// Found end of line
24152431
MS_DBG(F("dSRN unexpected EOL "));
24162432
return false;
2417-
} else if (NULL == nextCharEnd) {
2433+
} else if (nullptr == nextCharEnd) {
24182434
// Found <value>EOF ~ nextSr_sz is valid
24192435
deszq_nextCharSz -= 1; // take off turds <LF>
24202436
MS_DEEP_DBG(F("dSRN info "), deszq_nextCharSz, " '", deszq_nextChar,

src/LoggerBase.h

Lines changed: 100 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,8 +1499,12 @@ class Logger {
14991499
* @brief A character buffer holding the current line being deserialized
15001500
* (read) from the queue file.
15011501
*/
1502-
char deszq_line[QUEFILE_MAX_LINE] = "";
1503-
uint16_t desz_pending_records = 0;
1502+
char deszq_line[QUEFILE_MAX_LINE] = "";
1503+
/**
1504+
* @brief The number of records that have been added to the data queue
1505+
* files.
1506+
*/
1507+
uint16_t desz_pending_records = 0;
15041508

15051509
// Qu SdFat/sd1_card_fatfs connects to Physical pins or File/logFile or
15061510
// keep to LFN - capitals https://en.wikipedia.org/wiki/8.3_filename
@@ -1512,21 +1516,85 @@ class Logger {
15121516
#endif // MS_LOGGERBASE_POSTS
15131517

15141518
// que Readings DELAYed (RDEL) ~ serialize/deserialize
1515-
File serzRdelFile;
1519+
/**
1520+
* @brief File reference to the read-delayed file.
1521+
*
1522+
* The read-delayed file is for records that have never been published at
1523+
* all, they're simply in storage waiting their first publishing attempt.
1524+
*/
1525+
File serzRdelFile;
1526+
/**
1527+
* @brief String filename of the read-delayed file.
1528+
*
1529+
* The read-delayed file is for records that have never been published at
1530+
* all, they're simply in storage waiting their first publishing attempt.
1531+
*/
15161532
const char* serzRdelFn_str = "RDELAY.TXT";
15171533

15181534
// QUEueD for reliable delivery
15191535
// first POST didn't suceed to serialize/deserialize
15201536
// Potentially multiple versions of files based on dataPublisher[]
1537+
1538+
/**
1539+
* @brief File reference to the queued data file.
1540+
*
1541+
* The queue file is for data that has already had one publication attempt,
1542+
* which failed due to lack of internet connection or unsuccessful
1543+
* serialize/deserialize.
1544+
*
1545+
* Potentially multiple queue files based on the number of data publishers
1546+
* attached to the logger.
1547+
*/
15211548
File serzQueuedFile;
1549+
/**
1550+
* @brief The buffer size needed for the file name of the
1551+
* Logger::serzQueuedFile.
1552+
*/
15221553
#define FN_BUFFER_SZ 13
1523-
char serzQueuedFn[FN_BUFFER_SZ] = "";
1524-
const char* serzQueuedFn_str = "QUE"; // begin of name, keep 8.3
1554+
1555+
/**
1556+
* @brief Character string holding the string filename for the queue for the
1557+
* current data publisher.
1558+
*
1559+
* The queue file is for data that has already had one publication
1560+
* attempt, which failed due to lack of internet connection or
1561+
* unsuccessful serialize/deserialize.
1562+
*
1563+
* Potentially multiple queue files based on the number of data
1564+
* publishers attached to the logger.
1565+
*
1566+
* The filename will be a concatenation of the Logger::serzQueuedFn_str and
1567+
* the uniqueId.
1568+
*/
1569+
char serzQueuedFn[FN_BUFFER_SZ] = "";
1570+
/**
1571+
* @brief The beginning of the filename for the queue files.
1572+
*/
1573+
const char* serzQueuedFn_str = "QUE"; // begin of name, keep 8.3
15251574

15261575

15271576
// perform a serialize to RdelFile
1577+
/**
1578+
* @brief Open the [read-delayed file](@ref Logger::serzRdelFile) and
1579+
* write a line to it.
1580+
*
1581+
* The line will have the timestamp, a status code of zero, and the logged
1582+
* data values separated by commas.
1583+
*
1584+
* @return *true* The file was successfully opened.
1585+
* @return *false* There was an error in opening the file.
1586+
*/
15281587
bool serzRdel_Line(void);
15291588
// Uses serzRdelFn_str, File serzRdelFile
1589+
/**
1590+
* @brief Opens the read-delayed file on the SD-card.
1591+
*
1592+
* Also sets the pointer for the next character to be read to the start of
1593+
* the buffer for the next line.
1594+
*
1595+
* @return *true* The file was successfully opened.
1596+
* @return *false* There was an error in opening the file.
1597+
*/
15301598
bool deszRdelStart();
15311599

15321600
/**
@@ -1544,6 +1612,14 @@ class Logger {
15441612
*/
15451613
char* deszFind(const char* in_line, char caller_id);
15461614
#define deszRdelLine() deszLine(&serzRdelFile)
1615+
/**
1616+
* @brief Closes the read-delayed file (Logger::serzRdelFile) and deletes it
1617+
* if requested.
1618+
*
1619+
* @param deleteFile True to delete the read-delay file after closing it.
1620+
* @return *true* The file was successfully closed.
1621+
* @return *false* There was an error in closing the file.
1622+
*/
15471623
bool deszRdelClose(bool deleteFile = false);
15481624

15491625
/**
@@ -1569,8 +1645,26 @@ class Logger {
15691645
*/
15701646
bool deszQueuedStart(void);
15711647
#define deszQueuedLine() deszLine(&serzQueuedFile)
1648+
/**
1649+
* @brief "Flushes" the queued data file by writing all lines from the
1650+
* current position forward to a new temporary file, deleting the old queue
1651+
* file, and renaming the temporary file to the original queue file name.
1652+
* This has the effect of removing all lines from the queue file prior to
1653+
* the current read point within the queue file.
1654+
*
1655+
* @return *uint16_t* The number of lines available in the new queue file.
1656+
*/
15721657
uint16_t serzQueuedFlushFile();
1573-
bool serzQueuedCloseFile(bool action);
1658+
/**
1659+
* @brief Close the queue file and flush it if requested.
1660+
*
1661+
* @param flush Whether or not to flush the queue file using
1662+
* Logger::serzQueuedFlushFile.
1663+
*
1664+
* @return *true* The file was successfully closed.
1665+
* @return *false* There was an error in closing the file.
1666+
*/
1667+
bool serzQueuedCloseFile(bool flush);
15741668
/*
15751669
bool deszQueuedCleanup(bool debug = false);
15761670
*/

0 commit comments

Comments
 (0)