From 1dc0134d1d86927b2cc0ade055e9f9cd3482745b Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Fri, 21 Jun 2024 04:34:13 -0700 Subject: [PATCH] Fix build warnings for examples (#37) * address build warnings * revise use of header in ncurses interrupt example * send timestamp to sender * fix renewAddress() usage --- RF24Gateway.cpp | 5 +- examples/ncurses/RF24Gateway_ncurses.cpp | 16 ++---- .../ncursesInt/RF24Gateway_ncursesInt.cpp | 53 ++++++++----------- 3 files changed, 31 insertions(+), 43 deletions(-) diff --git a/RF24Gateway.cpp b/RF24Gateway.cpp index 62e4952..fd8aedf 100644 --- a/RF24Gateway.cpp +++ b/RF24Gateway.cpp @@ -417,6 +417,7 @@ struct in_addr ESBGateway::getLocalIP() int family, s, n; char host[NI_MAXHOST]; struct in_addr myNet; + memset(&myNet, 0, sizeof(myNet)); getifaddrs(&ifap); for (ifa = ifap, n = 0; ifa != NULL; ifa = ifa->ifa_next, n++) { @@ -682,14 +683,14 @@ template void ESBGateway::printPayload(std::string buffer, std::string debugMsg) { } - +*/ /*************************************************************************************** template void ESBGateway::printPayload(char* buffer, int nread, std::string debugMsg) { } - +*/ /***************************************************************************************/ template diff --git a/examples/ncurses/RF24Gateway_ncurses.cpp b/examples/ncurses/RF24Gateway_ncurses.cpp index 7e0f360..7cff9e9 100644 --- a/examples/ncurses/RF24Gateway_ncurses.cpp +++ b/examples/ncurses/RF24Gateway_ncurses.cpp @@ -372,9 +372,7 @@ void drawTopology() for (int j = 0; j < mesh.addrListTop; j++) { if (mesh.addrList[j].address == i) { - int y = 0; - int x = 0; - getyx(connPad, y, x); + int x = getcurx(connPad); if (x > connPadmaxX - 77) { wprintw(connPad, "\n"); } @@ -394,9 +392,7 @@ void drawTopology() for (int j = 0; j < mesh.addrListTop; j++) { if (mesh.addrList[j].address == i) { - int y = 0; - int x = 0; - getyx(connPad, y, x); + int x = getcurx(connPad); if (x > connPadmaxX - 77) { wprintw(connPad, "\n"); } @@ -416,9 +412,7 @@ void drawTopology() for (int j = 0; j < mesh.addrListTop; j++) { if (mesh.addrList[j].address == i) { - int y = 0; - int x = 0; - getyx(connPad, y, x); + int x = getcurx(connPad); if (x > connPadmaxX - 77) { wprintw(connPad, "\n"); } @@ -664,7 +658,7 @@ void drawRF24Pad() wprintw(rf24Pad, "TX Packets: %u\n", ok); wprintw(rf24Pad, "TX Drops: %u\n", fail); #endif - wprintw(rf24Pad, "RX Packets(user): %u\n", networkPacketsRX); + wprintw(rf24Pad, "RX Packets(user): %lu\n", networkPacketsRX); if (padSelection == 1) { @@ -711,7 +705,7 @@ void drawConnPad() fnd = line.find_last_of(" ", fnd - 2); unsigned findEnd = line.find(" mark="); line = line.substr(fnd, findEnd - fnd); - mvwprintw(connPad, ctr++, 0, "%d %s\n", lCtr++, line.c_str()); + mvwprintw(connPad, ctr++, 0, "%ld %s\n", lCtr++, line.c_str()); if (ctr > maxX - 15) { diff --git a/examples/ncursesInt/RF24Gateway_ncursesInt.cpp b/examples/ncursesInt/RF24Gateway_ncursesInt.cpp index 3f87b5c..fb450d5 100644 --- a/examples/ncursesInt/RF24Gateway_ncursesInt.cpp +++ b/examples/ncursesInt/RF24Gateway_ncursesInt.cpp @@ -164,8 +164,10 @@ int main() wclear(renewPad); mvwprintw(renewPad, 0, 0, "*Renewing Address*"); prefresh(renewPad, 0, 0, 3, 26, 4, 55); - if ((ok = mesh.renewAddress())) + ok = mesh.renewAddress() != MESH_DEFAULT_ADDRESS; + if (ok) { + ok = true; wclear(renewPad); prefresh(renewPad, 0, 0, 3, 26, 4, 55); } @@ -182,29 +184,26 @@ int main() { ++networkPacketsRX; RF24NetworkHeader header; - // un-needed variables // size_t size = network.peek(header); // uint8_t buf[size]; + network.read(header, /*buf*/ 0, /*size*/ 0); // pop the RX payload from network.queue - if (header.type == 1) // header.type is uninitialized + // send a timestamp to master + struct timeStruct { - struct timeStruct - { - uint8_t hr; - uint8_t min; - } myTime; - - time_t mTime; - time(&mTime); - struct tm* tm = localtime(&mTime); - - myTime.hr = tm->tm_hour; - myTime.min = tm->tm_min; - RF24NetworkHeader hdr(header.from_node, 1); - network.write(hdr, &myTime, sizeof(myTime)); - } - network.read(header, 0, 0); + uint8_t hr; + uint8_t min; + } myTime; + + time_t mTime; + time(&mTime); + struct tm* tm = localtime(&mTime); + + myTime.hr = tm->tm_hour; + myTime.min = tm->tm_min; + RF24NetworkHeader hdr(header.from_node, 1); + network.write(hdr, &myTime, sizeof(myTime)); } } else @@ -400,9 +399,7 @@ void drawTopology() for (int j = 0; j < mesh.addrListTop; j++) { if (mesh.addrList[j].address == i) { - int y = 0; - int x = 0; - getyx(connPad, y, x); + int x = getcurx(connPad); if (x > connPadmaxX - 77) { wprintw(connPad, "\n"); } @@ -422,9 +419,7 @@ void drawTopology() for (int j = 0; j < mesh.addrListTop; j++) { if (mesh.addrList[j].address == i) { - int y = 0; - int x = 0; - getyx(connPad, y, x); + int x = getcurx(connPad); if (x > connPadmaxX - 77) { wprintw(connPad, "\n"); } @@ -444,9 +439,7 @@ void drawTopology() for (int j = 0; j < mesh.addrListTop; j++) { if (mesh.addrList[j].address == i) { - int y = 0; - int x = 0; - getyx(connPad, y, x); + int x = getcurx(connPad); if (x > connPadmaxX - 77) { wprintw(connPad, "\n"); } @@ -694,7 +687,7 @@ void drawRF24Pad() wprintw(rf24Pad, "TX Packets(sys): %u\n", ok); wprintw(rf24Pad, "TX Drops: %u\n", fail); #endif - wprintw(rf24Pad, "RX Packets(user): %u\n", networkPacketsRX); + wprintw(rf24Pad, "RX Packets(user): %lu\n", networkPacketsRX); if (gw.fifoCleared) { ++fifoClears; @@ -747,7 +740,7 @@ void drawConnPad() fnd = line.find_last_of(" ", fnd - 2); unsigned findEnd = line.find(" mark="); line = line.substr(fnd, findEnd - fnd); - mvwprintw(connPad, ctr++, 0, "%d %s\n", lCtr++, line.c_str()); + mvwprintw(connPad, ctr++, 0, "%ld %s\n", lCtr++, line.c_str()); if (ctr > maxX - 15) {