Skip to content

Commit

Permalink
Convert positive status values to errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
pkubanek committed Nov 3, 2023
1 parent a5398b9 commit 6e1f171
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion include/cRIO/NiStatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions src/LSST/cRIO/NiStatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 6e1f171

Please sign in to comment.