Skip to content
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

Prevent infinite loop on one time run #106

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion sources/inverter-cli/inverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ bool cInverter::query(const char *cmd, int replysize) {
void cInverter::poll() {
int n,j;
extern const int qpiri, qpiws, qmod, qpigs;
extern const bool runOnce;

while (true) {

Expand Down Expand Up @@ -198,8 +199,12 @@ void cInverter::poll() {
ups_qpiws_changed = true;
}
}

sleep(5);
// leave after delay to let main thread printout data
if (runOnce) {
ups_leave = true;
exit(0);
}
}
}

Expand Down
15 changes: 7 additions & 8 deletions sources/inverter-cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

bool debugFlag = false;
bool runOnce = false;
bool ups_leave = false;

cInverter *ups = NULL;

Expand Down Expand Up @@ -278,16 +279,14 @@ int main(int argc, char* argv[]) {
// Delete reply string so we can update with new data when polled again...
delete reply1;
delete reply2;

if(runOnce) {
// Do once and exit instead of loop endlessly
lprintf("INVERTER: All queries complete, exiting loop.");
exit(0);
}
}
}

} else if (ups_leave) {
// If not reading response of oneshot run, exit instead of loop endlessly
lprintf("INVERTER: All queries complete, exiting loop.");
exit(0);
}
sleep(1);

}

if (ups)
Expand Down
2 changes: 2 additions & 0 deletions sources/inverter-cli/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "inverter.h"

extern bool debugFlag;
extern bool ups_leave;

extern atomic_bool ups_data_changed;

extern atomic_bool ups_status_changed;
Expand Down