printf support for cmd executor
This commit is contained in:
parent
739f682dee
commit
9e9fa047f7
@ -62,8 +62,13 @@ ReturnValue_t CommandExecutor::close() {
|
|||||||
|
|
||||||
void CommandExecutor::printLastError(std::string funcName) const {
|
void CommandExecutor::printLastError(std::string funcName) const {
|
||||||
if(lastError != 0) {
|
if(lastError != 0) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << funcName << " pclose failed with code " <<
|
sif::error << funcName << " pclose failed with code " <<
|
||||||
lastError << ": " << strerror(lastError) << std::endl;
|
lastError << ": " << strerror(lastError) << std::endl;
|
||||||
|
#else
|
||||||
|
sif::printError("%s pclose failed with code %d: %s", funcName, lastError,
|
||||||
|
strerror(lastError));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,15 +103,23 @@ ReturnValue_t CommandExecutor::check(bool& bytesRead) {
|
|||||||
ssize_t readBytes = read(currentFd, readVec.data(), readVec.size());
|
ssize_t readBytes = read(currentFd, readVec.data(), readVec.size());
|
||||||
if(readBytes == 0) {
|
if(readBytes == 0) {
|
||||||
// Should not happen
|
// Should not happen
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::warning << "CommandExecutor::check: "
|
sif::warning << "CommandExecutor::check: "
|
||||||
"No bytes read after poll event.." << std::endl;
|
"No bytes read after poll event.." << std::endl;
|
||||||
|
#else
|
||||||
|
sif::printWarning("CommandExecutor::check: No bytes read after poll event..\n");
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if(readBytes > 0) {
|
else if(readBytes > 0) {
|
||||||
bytesRead = true;
|
bytesRead = true;
|
||||||
if(printOutput) {
|
if(printOutput) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
// It is assumed the command output is line terminated
|
// It is assumed the command output is line terminated
|
||||||
sif::info << currentCmd << " | " << readVec.data();
|
sif::info << currentCmd << " | " << readVec.data();
|
||||||
|
#else
|
||||||
|
sif::printInfo("%s | %s", currentCmd, readVec.data());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
if(ringBuffer != nullptr) {
|
if(ringBuffer != nullptr) {
|
||||||
ringBuffer->writeData(reinterpret_cast<const uint8_t*>(
|
ringBuffer->writeData(reinterpret_cast<const uint8_t*>(
|
||||||
@ -120,17 +133,25 @@ ReturnValue_t CommandExecutor::check(bool& bytesRead) {
|
|||||||
return BYTES_READ;
|
return BYTES_READ;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
// Should also not happen
|
// Should also not happen
|
||||||
sif::warning << "CommandExecutor::check: Error " << errno << ": " <<
|
sif::warning << "CommandExecutor::check: Error " << errno << ": " <<
|
||||||
strerror(errno) << std::endl;
|
strerror(errno) << std::endl;
|
||||||
|
#else
|
||||||
|
sif::printWarning("CommandExecutor::check: Error %d: %s\n", errno, strerror(errno));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(waiter.revents & POLLERR) {
|
else if(waiter.revents & POLLERR) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::warning << "CommandExecuter::check: Poll error" << std::endl;
|
sif::warning << "CommandExecuter::check: Poll error" << std::endl;
|
||||||
|
#else
|
||||||
|
sif::printWarning("CommandExecuter::check: Poll error\n");
|
||||||
|
#endif
|
||||||
return COMMAND_ERROR;
|
return COMMAND_ERROR;
|
||||||
}
|
}
|
||||||
else if(waiter.revents & POLLHUP) {
|
else if(waiter.revents & POLLHUP) {
|
||||||
int result = pclose(currentCmdFile);
|
result = pclose(currentCmdFile);
|
||||||
if(result != 0) {
|
if(result != 0) {
|
||||||
lastError = result;
|
lastError = result;
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
@ -165,7 +186,11 @@ ReturnValue_t CommandExecutor::executeBlocking() {
|
|||||||
while(fgets(readVec.data(), readVec.size(), currentCmdFile) != nullptr) {
|
while(fgets(readVec.data(), readVec.size(), currentCmdFile) != nullptr) {
|
||||||
std::string output(readVec.data());
|
std::string output(readVec.data());
|
||||||
if(printOutput) {
|
if(printOutput) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::info << currentCmd << " | " << output;
|
sif::info << currentCmd << " | " << output;
|
||||||
|
#else
|
||||||
|
sif::printInfo("%s | %s", currentCmd, output);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
if(ringBuffer != nullptr) {
|
if(ringBuffer != nullptr) {
|
||||||
ringBuffer->writeData(reinterpret_cast<const uint8_t*>(output.data()), output.size());
|
ringBuffer->writeData(reinterpret_cast<const uint8_t*>(output.data()), output.size());
|
||||||
|
Loading…
Reference in New Issue
Block a user