Beispiel #1
0
/**
 * Common error routines for wpi_assertEqual_impl and wpi_assertNotEqual_impl
 * This should not be called directly; it should only be used by
 * wpi_assertEqual_impl
 * and wpi_assertNotEqual_impl.
 */
void wpi_assertEqual_common_impl(const char *valueA, const char *valueB,
                                 const char *equalityType,
                                 const char *message,
                                 const char *fileName,
                                 uint32_t lineNumber,
                                 const char *funcName) {
  std::stringstream errorStream;

  errorStream << "Assertion \"" << valueA << " " << equalityType << " "
              << valueB << "\" ";
  errorStream << "on line " << lineNumber << " ";
  errorStream << "of " << basename(fileName) << " ";

  if (message[0] != '\0') {
    errorStream << "failed: " << message << std::endl;
  } else {
    errorStream << "failed." << std::endl;
  }

  errorStream << GetStackTrace(3);

  std::string error = errorStream.str();

  // Print the error and send it to the DriverStation
  std::cout << error << std::endl;
  HALSetErrorData(error.c_str(), error.size(), 100);
}
Beispiel #2
0
/**
 * Assert implementation.
 * This allows breakpoints to be set on an assert.
 * The users don't call this, but instead use the wpi_assert macros in
 * Utility.h.
 */
bool wpi_assert_impl(bool conditionValue, const char *conditionText,
                     const char *message, const char *fileName,
                     uint32_t lineNumber, const char *funcName) {
  if (!conditionValue) {
    std::stringstream errorStream;

    errorStream << "Assertion \"" << conditionText << "\" ";
    errorStream << "on line " << lineNumber << " ";
    errorStream << "of " << basename(fileName) << " ";

    if (message[0] != '\0') {
      errorStream << "failed: " << message << std::endl;
    } else {
      errorStream << "failed." << std::endl;
    }

    errorStream << GetStackTrace(2);

    std::string error = errorStream.str();

    // Print the error and send it to the DriverStation
    std::cout << error << std::endl;
    HALSetErrorData(error.c_str(), error.size(), 100);
  }

  return conditionValue;
}
/**
 * Report an error to the DriverStation messages window.
 * The error is also printed to the program console.
 */
void DriverStation::ReportError(std::string error) {
  std::cout << error << std::endl;

  HALControlWord controlWord;
  HALGetControlWord(&controlWord);
  if (controlWord.dsAttached) {
    HALSetErrorData(error.c_str(), error.size(), 0);
  }
}