Add HAL specific version of wpi_setError (#2055)

Cleans up error writing, and allows fewer headers to be included in many of the wpilibc cpp files.

This removes all usages of the hal/HAL.h header.
This commit is contained in:
Thad House
2019-11-08 22:53:20 -08:00
committed by Peter Johnson
parent 326aecc9a0
commit 9bcff37b93
84 changed files with 421 additions and 377 deletions

View File

@@ -16,6 +16,9 @@
#include "frc/Base.h"
#include "frc/Error.h"
// Forward declared manually to avoid needing to pull in entire HAL header.
extern "C" const char* HAL_GetErrorMessage(int32_t code);
#define wpi_setErrnoErrorWithContext(context) \
this->SetErrnoError((context), __FILE__, __FUNCTION__, __LINE__)
#define wpi_setErrnoError() wpi_setErrnoErrorWithContext("")
@@ -35,6 +38,22 @@
this->SetErrorRange((code), (min), (max), (req), (context), __FILE__, \
__FUNCTION__, __LINE__); \
} while (0)
#define wpi_setHALError(code) \
do { \
if ((code) != 0) \
this->SetError((code), HAL_GetErrorMessage(code), __FILE__, \
__FUNCTION__, __LINE__); \
} while (0)
#define wpi_setHALErrorWithRange(code, min, max, req) \
do { \
if ((code) != 0) \
this->SetErrorRange((code), (min), (max), (req), \
HAL_GetErrorMessage(code), __FILE__, __FUNCTION__, \
__LINE__); \
} while (0)
#define wpi_setError(code) wpi_setErrorWithContext(code, "")
#define wpi_setStaticErrorWithContext(object, code, context) \
do { \
@@ -43,12 +62,21 @@
} while (0)
#define wpi_setStaticError(object, code) \
wpi_setStaticErrorWithContext(object, code, "")
#define wpi_setGlobalErrorWithContext(code, context) \
do { \
if ((code) != 0) \
::frc::ErrorBase::SetGlobalError((code), (context), __FILE__, \
__FUNCTION__, __LINE__); \
} while (0)
#define wpi_setGlobalHALError(code) \
do { \
if ((code) != 0) \
::frc::ErrorBase::SetGlobalError((code), HAL_GetErrorMessage(code), \
__FILE__, __FUNCTION__, __LINE__); \
} while (0)
#define wpi_setGlobalError(code) wpi_setGlobalErrorWithContext(code, "")
#define wpi_setWPIErrorWithContext(error, context) \
this->SetWPIError(wpi_error_s_##error(), wpi_error_value_##error(), \