Add HALSIM_SetSendError implementation (#1773)

This commit is contained in:
Thad House
2019-07-23 23:55:51 -07:00
committed by Peter Johnson
parent dff58c87f4
commit 48fe54271a

View File

@@ -28,7 +28,7 @@ static wpi::condition_variable* newDSDataAvailableCond;
static wpi::mutex newDSDataAvailableMutex;
static int newDSDataAvailableCounter{0};
static std::atomic_bool isFinalized{false};
static HALSIM_SendErrorHandler sendErrorHandler{nullptr};
static std::atomic<HALSIM_SendErrorHandler> sendErrorHandler{nullptr};
namespace hal {
namespace init {
@@ -42,12 +42,18 @@ void InitializeDriverStation() {
using namespace hal;
extern "C" {
void HALSIM_SetSendError(HALSIM_SendErrorHandler handler) {
sendErrorHandler.store(handler);
}
int32_t HAL_SendError(HAL_Bool isError, int32_t errorCode, HAL_Bool isLVCode,
const char* details, const char* location,
const char* callStack, HAL_Bool printMsg) {
if (sendErrorHandler)
return sendErrorHandler(isError, errorCode, isLVCode, details, location,
callStack, printMsg);
auto errorHandler = sendErrorHandler.load();
if (errorHandler)
return errorHandler(isError, errorCode, isLVCode, details, location,
callStack, printMsg);
// Avoid flooding console by keeping track of previous 5 error
// messages and only printing again if they're longer than 1 second old.
static constexpr int KEEP_MSGS = 5;