From 6e1f17167a91faf701996adfe6acd3c28a013733 Mon Sep 17 00:00:00 2001 From: Petr Kubanek Date: Fri, 3 Nov 2023 11:01:47 +0100 Subject: [PATCH] Convert positive status values to errors. --- include/cRIO/NiStatus.h | 3 ++- src/LSST/cRIO/NiStatus.cpp | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/include/cRIO/NiStatus.h b/include/cRIO/NiStatus.h index 22c11977..5711c8f3 100644 --- a/include/cRIO/NiStatus.h +++ b/include/cRIO/NiStatus.h @@ -40,7 +40,8 @@ namespace cRIO { const char* NiStatus(int32_t status); /** - * Log NiFpga call error. + * Log NiFpga call error. If status is positive, it is converted to negative + * number, to represent an error. * * @param msg additional message (can be __PRETTY_FUNCTION__) * @param status NiFpga returned status diff --git a/src/LSST/cRIO/NiStatus.cpp b/src/LSST/cRIO/NiStatus.cpp index f1505849..ab741982 100644 --- a/src/LSST/cRIO/NiStatus.cpp +++ b/src/LSST/cRIO/NiStatus.cpp @@ -32,6 +32,12 @@ struct NiErrors { const char *desc; }; +// those values are from NI documentation: +// https://www.ni.com/docs/en-US/bundle/fpga-interface-c-api-ref/page/capi/errors.html +// +// However, Ni functions return positive numbers on errors. Hence NiStatus +// function does the conversion of positive numbers to negative. + NiErrors errors[] = { {0, "NiFpga_Status_Success: No errors or warnings"}, {-50400, "NiFpga_Status_FifoTimeout: The timeout expired before the FIFO operation could complete"}, @@ -195,6 +201,9 @@ NiErrors errors[] = { {0, nullptr}}; const char *NiStatus(int32_t status) { + if (status > 0) { + status = -status; + } for (NiErrors *err = errors; err->desc != nullptr; err++) { if (err->status == status) return err->desc; }