mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[hal] Notifier: simplify ack API (#8457)
Adding an ack parameter to both set and cancel is cleaner than adding all the set alarm parameters to the ack function. It also provides an ack-and-cancel method.
This commit is contained in:
@@ -74,40 +74,31 @@ public class NotifierJNI extends JNIWrapper {
|
||||
* @param alarmTime the first alarm time (in microseconds)
|
||||
* @param intervalTime the periodic interval time (in microseconds)
|
||||
* @param absolute true if the alarm time is absolute
|
||||
* @param ack true to acknowledge any prior alarm
|
||||
* @see "HAL_SetNotifierAlarm"
|
||||
*/
|
||||
public static native void setNotifierAlarm(
|
||||
int notifierHandle, long alarmTime, long intervalTime, boolean absolute);
|
||||
int notifierHandle, long alarmTime, long intervalTime, boolean absolute, boolean ack);
|
||||
|
||||
/**
|
||||
* Cancels all future notifier alarms for a notifier.
|
||||
*
|
||||
* @param notifierHandle the notifier handle
|
||||
* @param ack true to acknowledge any prior alarm
|
||||
* @see "HAL_CancelNotifierAlarm"
|
||||
*/
|
||||
public static native void cancelNotifierAlarm(int notifierHandle);
|
||||
public static native void cancelNotifierAlarm(int notifierHandle, boolean ack);
|
||||
|
||||
/**
|
||||
* Indicates the notifier alarm has been serviced and optionally sets a new alarm time. This must
|
||||
* be called before waiting for the next alarm.
|
||||
* Indicates the notifier alarm has been serviced. Makes no change to future alarms.
|
||||
*
|
||||
* <p>The alarmTime is an absolute time (using the WPI now() time base) if absolute is true, or
|
||||
* relative to the current time if absolute is false.
|
||||
*
|
||||
* <p>If intervalTime is non-zero, the notifier will alarm periodically following alarmTime at the
|
||||
* given interval.
|
||||
*
|
||||
* <p>If an absolute alarmTime is in the past, the notifier will alarm immediately.
|
||||
* <p>One of setNotifierAlarm (with ack=true), cancelNotifierAlarm (with ack=true), or this
|
||||
* function must be called before waiting for the next alarm.
|
||||
*
|
||||
* @param notifierHandle the notifier handle
|
||||
* @param setAlarm true to set a new alarm time, false to leave the alarm unchanged
|
||||
* @param alarmTime the first alarm time (in microseconds)
|
||||
* @param intervalTime the periodic interval time (in microseconds)
|
||||
* @param absolute true if the alarm time is absolute
|
||||
* @see "HAL_AcknowledgeNotifierAlarm"
|
||||
*/
|
||||
public static native void acknowledgeNotifierAlarm(
|
||||
int notifierHandle, boolean setAlarm, long alarmTime, long intervalTime, boolean absolute);
|
||||
public static native void acknowledgeNotifierAlarm(int notifierHandle);
|
||||
|
||||
/**
|
||||
* Gets the overrun count for a notifier.
|
||||
|
||||
@@ -82,49 +82,45 @@ Java_org_wpilib_hardware_hal_NotifierJNI_destroyNotifier
|
||||
/*
|
||||
* Class: org_wpilib_hardware_hal_NotifierJNI
|
||||
* Method: setNotifierAlarm
|
||||
* Signature: (IJJZ)V
|
||||
* Signature: (IJJZZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_wpilib_hardware_hal_NotifierJNI_setNotifierAlarm
|
||||
(JNIEnv* env, jclass cls, jint notifierHandle, jlong alarmTime,
|
||||
jlong intervalTime, jboolean absolute)
|
||||
jlong intervalTime, jboolean absolute, jboolean ack)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_SetNotifierAlarm((HAL_NotifierHandle)notifierHandle,
|
||||
static_cast<uint64_t>(alarmTime),
|
||||
static_cast<uint64_t>(intervalTime), absolute, &status);
|
||||
HAL_SetNotifierAlarm(
|
||||
(HAL_NotifierHandle)notifierHandle, static_cast<uint64_t>(alarmTime),
|
||||
static_cast<uint64_t>(intervalTime), absolute, ack, &status);
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_wpilib_hardware_hal_NotifierJNI
|
||||
* Method: cancelNotifierAlarm
|
||||
* Signature: (I)V
|
||||
* Signature: (IZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_wpilib_hardware_hal_NotifierJNI_cancelNotifierAlarm
|
||||
(JNIEnv* env, jclass cls, jint notifierHandle)
|
||||
(JNIEnv* env, jclass cls, jint notifierHandle, jboolean ack)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_CancelNotifierAlarm((HAL_NotifierHandle)notifierHandle, &status);
|
||||
HAL_CancelNotifierAlarm((HAL_NotifierHandle)notifierHandle, ack, &status);
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_wpilib_hardware_hal_NotifierJNI
|
||||
* Method: acknowledgeNotifierAlarm
|
||||
* Signature: (IZJJZ)V
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_wpilib_hardware_hal_NotifierJNI_acknowledgeNotifierAlarm
|
||||
(JNIEnv* env, jclass cls, jint notifierHandle, jboolean setAlarm,
|
||||
jlong alarmTime, jlong intervalTime, jboolean absolute)
|
||||
(JNIEnv* env, jclass cls, jint notifierHandle)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_AcknowledgeNotifierAlarm((HAL_NotifierHandle)notifierHandle, setAlarm,
|
||||
static_cast<uint64_t>(alarmTime),
|
||||
static_cast<uint64_t>(intervalTime), absolute,
|
||||
&status);
|
||||
HAL_AcknowledgeNotifierAlarm((HAL_NotifierHandle)notifierHandle, &status);
|
||||
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
@@ -87,44 +87,34 @@ void HAL_DestroyNotifier(HAL_NotifierHandle notifierHandle);
|
||||
* @param[in] alarmTime the first alarm time (in microseconds)
|
||||
* @param[in] intervalTime the periodic interval time (in microseconds)
|
||||
* @param[in] absolute true if the alarm time is absolute
|
||||
* @param[in] ack true to acknowledge any prior alarm
|
||||
* @param[out] status Error status variable. 0 on success.
|
||||
*/
|
||||
void HAL_SetNotifierAlarm(HAL_NotifierHandle notifierHandle, uint64_t alarmTime,
|
||||
uint64_t intervalTime, HAL_Bool absolute,
|
||||
int32_t* status);
|
||||
HAL_Bool ack, int32_t* status);
|
||||
|
||||
/**
|
||||
* Cancels all future notifier alarms for a notifier.
|
||||
*
|
||||
* @param[in] notifierHandle the notifier handle
|
||||
* @param[in] ack true to acknowledge any prior alarm
|
||||
* @param[out] status Error status variable. 0 on success.
|
||||
*/
|
||||
void HAL_CancelNotifierAlarm(HAL_NotifierHandle notifierHandle,
|
||||
void HAL_CancelNotifierAlarm(HAL_NotifierHandle notifierHandle, HAL_Bool ack,
|
||||
int32_t* status);
|
||||
|
||||
/**
|
||||
* Indicates the notifier alarm has been serviced and optionally sets a new
|
||||
* alarm time. This must be called before waiting for the next alarm.
|
||||
* Indicates the notifier alarm has been serviced. Makes no change to future
|
||||
* alarms.
|
||||
*
|
||||
* The alarmTime is an absolute time (using the WPI_Now() time base) if
|
||||
* absolute is true, or relative to the current time if absolute is false.
|
||||
*
|
||||
* If intervalTime is non-zero, the notifier will alarm periodically following
|
||||
* alarmTime at the given interval.
|
||||
*
|
||||
* If an absolute alarmTime is in the past, the notifier will alarm immediately.
|
||||
* One of HAL_SetNotifierAlarm (with ack=true), HAL_CancelNotifierAlarm (with
|
||||
* ack=true), or this function must be called before waiting for the next alarm.
|
||||
*
|
||||
* @param[in] notifierHandle the notifier handle
|
||||
* @param[in] setAlarm true to set a new alarm time, false to leave the
|
||||
* alarm unchanged
|
||||
* @param[in] alarmTime the first alarm time (in microseconds)
|
||||
* @param[in] intervalTime the periodic interval time (in microseconds)
|
||||
* @param[in] absolute true if the alarm time is absolute
|
||||
* @param[out] status Error status variable. 0 on success.
|
||||
*/
|
||||
void HAL_AcknowledgeNotifierAlarm(HAL_NotifierHandle notifierHandle,
|
||||
HAL_Bool setAlarm, uint64_t alarmTime,
|
||||
uint64_t intervalTime, HAL_Bool absolute,
|
||||
int32_t* status);
|
||||
|
||||
/**
|
||||
|
||||
@@ -46,10 +46,6 @@ class NotifierThread : public wpi::util::SafeThread {
|
||||
public:
|
||||
void Main() override;
|
||||
|
||||
void SetAlarm(HAL_NotifierHandle notifierHandle,
|
||||
std::shared_ptr<Notifier>& notifier, uint64_t alarmTime,
|
||||
uint64_t intervalTime, bool absolute, int32_t* status);
|
||||
|
||||
void ProcessAlarms(wpi::util::SmallVectorImpl<HAL_NotifierHandle>* signaled);
|
||||
|
||||
bool m_paused = false;
|
||||
@@ -115,30 +111,6 @@ void NotifierThread::Main() {
|
||||
}
|
||||
}
|
||||
|
||||
void NotifierThread::SetAlarm(HAL_NotifierHandle notifierHandle,
|
||||
std::shared_ptr<Notifier>& notifier,
|
||||
uint64_t alarmTime, uint64_t intervalTime,
|
||||
bool absolute, int32_t* status) {
|
||||
if (!absolute) {
|
||||
alarmTime += HAL_GetFPGATime(status);
|
||||
}
|
||||
|
||||
uint64_t prevWakeup = UINT64_MAX;
|
||||
if (!m_alarmQueue.empty()) {
|
||||
prevWakeup = m_alarmQueue.top().notifier->alarmTime;
|
||||
m_alarmQueue.remove({notifierHandle, notifier});
|
||||
}
|
||||
notifier->alarmTime = alarmTime;
|
||||
notifier->intervalTime = intervalTime;
|
||||
notifier->overrunCount = 0;
|
||||
m_alarmQueue.push({notifierHandle, notifier});
|
||||
|
||||
// wake up notifier thread if needed
|
||||
if (alarmTime < prevWakeup) {
|
||||
m_cond.notify_all();
|
||||
}
|
||||
}
|
||||
|
||||
void NotifierThread::ProcessAlarms(
|
||||
wpi::util::SmallVectorImpl<HAL_NotifierHandle>* signaled) {
|
||||
int32_t status = 0;
|
||||
@@ -278,17 +250,38 @@ void HAL_DestroyNotifier(HAL_NotifierHandle notifierHandle) {
|
||||
|
||||
void HAL_SetNotifierAlarm(HAL_NotifierHandle notifierHandle, uint64_t alarmTime,
|
||||
uint64_t intervalTime, HAL_Bool absolute,
|
||||
int32_t* status) {
|
||||
HAL_Bool ack, int32_t* status) {
|
||||
auto thr = notifierInstance->owner.GetThread();
|
||||
auto notifier = thr->m_handles.Get(notifierHandle);
|
||||
if (!notifier) {
|
||||
return;
|
||||
}
|
||||
thr->SetAlarm(notifierHandle, notifier, alarmTime, intervalTime, absolute,
|
||||
status);
|
||||
|
||||
if (ack) {
|
||||
notifier->handlerSignaled.clear();
|
||||
}
|
||||
|
||||
if (!absolute) {
|
||||
alarmTime += HAL_GetFPGATime(status);
|
||||
}
|
||||
|
||||
uint64_t prevWakeup = UINT64_MAX;
|
||||
if (!thr->m_alarmQueue.empty()) {
|
||||
prevWakeup = thr->m_alarmQueue.top().notifier->alarmTime;
|
||||
thr->m_alarmQueue.remove({notifierHandle, notifier});
|
||||
}
|
||||
notifier->alarmTime = alarmTime;
|
||||
notifier->intervalTime = intervalTime;
|
||||
notifier->overrunCount = 0;
|
||||
thr->m_alarmQueue.push({notifierHandle, notifier});
|
||||
|
||||
// wake up notifier thread if needed
|
||||
if (alarmTime < prevWakeup) {
|
||||
thr->m_cond.notify_all();
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_CancelNotifierAlarm(HAL_NotifierHandle notifierHandle,
|
||||
void HAL_CancelNotifierAlarm(HAL_NotifierHandle notifierHandle, HAL_Bool ack,
|
||||
int32_t* status) {
|
||||
auto thr = notifierInstance->owner.GetThread();
|
||||
auto notifier = thr->m_handles.Get(notifierHandle);
|
||||
@@ -296,14 +289,15 @@ void HAL_CancelNotifierAlarm(HAL_NotifierHandle notifierHandle,
|
||||
return;
|
||||
}
|
||||
|
||||
if (ack) {
|
||||
notifier->handlerSignaled.clear();
|
||||
}
|
||||
|
||||
thr->m_alarmQueue.remove({notifierHandle, notifier});
|
||||
notifier->alarmTime = UINT64_MAX;
|
||||
notifier->handlerSignaled.clear();
|
||||
}
|
||||
|
||||
void HAL_AcknowledgeNotifierAlarm(HAL_NotifierHandle notifierHandle,
|
||||
HAL_Bool setAlarm, uint64_t alarmTime,
|
||||
uint64_t intervalTime, HAL_Bool absolute,
|
||||
int32_t* status) {
|
||||
auto thr = notifierInstance->owner.GetThread();
|
||||
auto notifier = thr->m_handles.Get(notifierHandle);
|
||||
@@ -311,10 +305,6 @@ void HAL_AcknowledgeNotifierAlarm(HAL_NotifierHandle notifierHandle,
|
||||
return;
|
||||
}
|
||||
notifier->handlerSignaled.clear();
|
||||
if (setAlarm) {
|
||||
thr->SetAlarm(notifierHandle, notifier, alarmTime, intervalTime, absolute,
|
||||
status);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t HAL_GetNotifierOverrun(HAL_NotifierHandle notifierHandle,
|
||||
|
||||
@@ -39,10 +39,6 @@ class NotifierThread : public wpi::util::SafeThread {
|
||||
public:
|
||||
void Main() override;
|
||||
|
||||
void SetAlarm(HAL_NotifierHandle notifierHandle,
|
||||
std::shared_ptr<Notifier>& notifier, uint64_t alarmTime,
|
||||
uint64_t intervalTime, bool absolute, int32_t* status);
|
||||
|
||||
void ProcessAlarms();
|
||||
|
||||
UnlimitedHandleResource<HAL_NotifierHandle, Notifier,
|
||||
@@ -101,30 +97,6 @@ void NotifierThread::Main() {
|
||||
}
|
||||
}
|
||||
|
||||
void NotifierThread::SetAlarm(HAL_NotifierHandle notifierHandle,
|
||||
std::shared_ptr<Notifier>& notifier,
|
||||
uint64_t alarmTime, uint64_t intervalTime,
|
||||
bool absolute, int32_t* status) {
|
||||
if (!absolute) {
|
||||
alarmTime += HAL_GetFPGATime(status);
|
||||
}
|
||||
|
||||
uint64_t prevWakeup = UINT64_MAX;
|
||||
if (!m_alarmQueue.empty()) {
|
||||
prevWakeup = m_alarmQueue.top().notifier->alarmTime;
|
||||
m_alarmQueue.remove({notifierHandle, notifier});
|
||||
}
|
||||
notifier->alarmTime = alarmTime;
|
||||
notifier->intervalTime = intervalTime;
|
||||
notifier->overrunCount = 0;
|
||||
m_alarmQueue.push({notifierHandle, notifier});
|
||||
|
||||
// wake up notifier thread if needed
|
||||
if (alarmTime < prevWakeup) {
|
||||
m_cond.notify_all();
|
||||
}
|
||||
}
|
||||
|
||||
void NotifierThread::ProcessAlarms() {
|
||||
int32_t status = 0;
|
||||
uint64_t curTime = HAL_GetFPGATime(&status);
|
||||
@@ -204,17 +176,38 @@ void HAL_DestroyNotifier(HAL_NotifierHandle notifierHandle) {
|
||||
|
||||
void HAL_SetNotifierAlarm(HAL_NotifierHandle notifierHandle, uint64_t alarmTime,
|
||||
uint64_t intervalTime, HAL_Bool absolute,
|
||||
int32_t* status) {
|
||||
HAL_Bool ack, int32_t* status) {
|
||||
auto thr = notifierInstance->owner.GetThread();
|
||||
auto notifier = thr->m_handles.Get(notifierHandle);
|
||||
if (!notifier) {
|
||||
return;
|
||||
}
|
||||
thr->SetAlarm(notifierHandle, notifier, alarmTime, intervalTime, absolute,
|
||||
status);
|
||||
|
||||
if (ack) {
|
||||
notifier->handlerSignaled.clear();
|
||||
}
|
||||
|
||||
if (!absolute) {
|
||||
alarmTime += HAL_GetFPGATime(status);
|
||||
}
|
||||
|
||||
uint64_t prevWakeup = UINT64_MAX;
|
||||
if (!thr->m_alarmQueue.empty()) {
|
||||
prevWakeup = thr->m_alarmQueue.top().notifier->alarmTime;
|
||||
thr->m_alarmQueue.remove({notifierHandle, notifier});
|
||||
}
|
||||
notifier->alarmTime = alarmTime;
|
||||
notifier->intervalTime = intervalTime;
|
||||
notifier->overrunCount = 0;
|
||||
thr->m_alarmQueue.push({notifierHandle, notifier});
|
||||
|
||||
// wake up notifier thread if needed
|
||||
if (alarmTime < prevWakeup) {
|
||||
thr->m_cond.notify_all();
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_CancelNotifierAlarm(HAL_NotifierHandle notifierHandle,
|
||||
void HAL_CancelNotifierAlarm(HAL_NotifierHandle notifierHandle, HAL_Bool ack,
|
||||
int32_t* status) {
|
||||
auto thr = notifierInstance->owner.GetThread();
|
||||
auto notifier = thr->m_handles.Get(notifierHandle);
|
||||
@@ -222,14 +215,15 @@ void HAL_CancelNotifierAlarm(HAL_NotifierHandle notifierHandle,
|
||||
return;
|
||||
}
|
||||
|
||||
if (ack) {
|
||||
notifier->handlerSignaled.clear();
|
||||
}
|
||||
|
||||
thr->m_alarmQueue.remove({notifierHandle, notifier});
|
||||
notifier->alarmTime = UINT64_MAX;
|
||||
notifier->handlerSignaled.clear();
|
||||
}
|
||||
|
||||
void HAL_AcknowledgeNotifierAlarm(HAL_NotifierHandle notifierHandle,
|
||||
HAL_Bool setAlarm, uint64_t alarmTime,
|
||||
uint64_t intervalTime, HAL_Bool absolute,
|
||||
int32_t* status) {
|
||||
auto thr = notifierInstance->owner.GetThread();
|
||||
auto notifier = thr->m_handles.Get(notifierHandle);
|
||||
@@ -237,10 +231,6 @@ void HAL_AcknowledgeNotifierAlarm(HAL_NotifierHandle notifierHandle,
|
||||
return;
|
||||
}
|
||||
notifier->handlerSignaled.clear();
|
||||
if (setAlarm) {
|
||||
thr->SetAlarm(notifierHandle, notifier, alarmTime, intervalTime, absolute,
|
||||
status);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t HAL_GetNotifierOverrun(HAL_NotifierHandle notifierHandle,
|
||||
|
||||
@@ -25,8 +25,6 @@ void TimedRobot::StartCompetition() {
|
||||
std::puts("\n********** Robot program startup complete **********");
|
||||
HAL_ObserveUserProgramStarting();
|
||||
|
||||
bool first = true;
|
||||
|
||||
// Loop forever, calling the appropriate mode-dependent function
|
||||
while (true) {
|
||||
// We don't have to check there's an element in the queue first because
|
||||
@@ -35,16 +33,9 @@ void TimedRobot::StartCompetition() {
|
||||
auto callback = m_callbacks.pop();
|
||||
|
||||
int32_t status = 0;
|
||||
if (first) {
|
||||
first = false;
|
||||
HAL_SetNotifierAlarm(m_notifier, callback.expirationTime.count(), 0, true,
|
||||
&status);
|
||||
WPILIB_CheckErrorStatus(status, "SetNotifierAlarm");
|
||||
} else {
|
||||
HAL_AcknowledgeNotifierAlarm(
|
||||
m_notifier, true, callback.expirationTime.count(), 0, true, &status);
|
||||
WPILIB_CheckErrorStatus(status, "AcknowledgeNotifierAlarm");
|
||||
}
|
||||
HAL_SetNotifierAlarm(m_notifier, callback.expirationTime.count(), 0, true,
|
||||
true, &status);
|
||||
WPILIB_CheckErrorStatus(status, "SetNotifierAlarm");
|
||||
|
||||
if (WPI_WaitForObject(m_notifier) == 0) {
|
||||
break;
|
||||
|
||||
@@ -46,7 +46,7 @@ Notifier::Notifier(std::function<void()> callback) {
|
||||
}
|
||||
|
||||
// Ack notifier
|
||||
HAL_AcknowledgeNotifierAlarm(notifier, false, 0, 0, false, &status);
|
||||
HAL_AcknowledgeNotifierAlarm(notifier, &status);
|
||||
WPILIB_CheckErrorStatus(status, "AcknowledgeNotifier");
|
||||
}
|
||||
});
|
||||
@@ -99,7 +99,7 @@ Notifier::Notifier(int priority, std::function<void()> callback) {
|
||||
}
|
||||
|
||||
// Ack notifier
|
||||
HAL_AcknowledgeNotifierAlarm(notifier, false, 0, 0, false, &status);
|
||||
HAL_AcknowledgeNotifierAlarm(notifier, &status);
|
||||
WPILIB_CheckErrorStatus(status, "AcknowledgeNotifier");
|
||||
}
|
||||
});
|
||||
@@ -144,13 +144,14 @@ void Notifier::SetCallback(std::function<void()> callback) {
|
||||
void Notifier::StartSingle(wpi::units::second_t delay) {
|
||||
int32_t status = 0;
|
||||
HAL_SetNotifierAlarm(m_notifier, static_cast<uint64_t>(delay * 1e6), 0, false,
|
||||
&status);
|
||||
false, &status);
|
||||
}
|
||||
|
||||
void Notifier::StartPeriodic(wpi::units::second_t period) {
|
||||
int32_t status = 0;
|
||||
HAL_SetNotifierAlarm(m_notifier, static_cast<uint64_t>(period * 1e6),
|
||||
static_cast<uint64_t>(period * 1e6), false, &status);
|
||||
static_cast<uint64_t>(period * 1e6), false, false,
|
||||
&status);
|
||||
}
|
||||
|
||||
void Notifier::StartPeriodic(wpi::units::hertz_t frequency) {
|
||||
@@ -159,7 +160,7 @@ void Notifier::StartPeriodic(wpi::units::hertz_t frequency) {
|
||||
|
||||
void Notifier::Stop() {
|
||||
int32_t status = 0;
|
||||
HAL_CancelNotifierAlarm(m_notifier, &status);
|
||||
HAL_CancelNotifierAlarm(m_notifier, false, &status);
|
||||
WPILIB_CheckErrorStatus(status, "CancelNotifierAlarm");
|
||||
}
|
||||
|
||||
|
||||
@@ -75,18 +75,12 @@ void Watchdog::Impl::UpdateAlarm(bool acknowledge) {
|
||||
return;
|
||||
}
|
||||
if (m_watchdogs.empty()) {
|
||||
HAL_CancelNotifierAlarm(notifier, &status);
|
||||
} else if (acknowledge) {
|
||||
HAL_AcknowledgeNotifierAlarm(
|
||||
notifier, true,
|
||||
static_cast<uint64_t>(m_watchdogs.top()->m_expirationTime.value() *
|
||||
1e6),
|
||||
0, true, &status);
|
||||
HAL_CancelNotifierAlarm(notifier, acknowledge, &status);
|
||||
} else {
|
||||
HAL_SetNotifierAlarm(notifier,
|
||||
static_cast<uint64_t>(
|
||||
m_watchdogs.top()->m_expirationTime.value() * 1e6),
|
||||
0, true, &status);
|
||||
0, true, acknowledge, &status);
|
||||
}
|
||||
WPILIB_CheckErrorStatus(status, "updating watchdog notifier alarm");
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ PyNotifier::PyNotifier(std::function<void()> handler) {
|
||||
}
|
||||
|
||||
// Ack notifier
|
||||
HAL_AcknowledgeNotifierAlarm(notifier, false, 0, 0, false, &status);
|
||||
HAL_AcknowledgeNotifierAlarm(notifier, &status);
|
||||
WPILIB_CheckErrorStatus(status, "AcknowledgeNotifier");
|
||||
}
|
||||
} catch (...) {
|
||||
@@ -120,6 +120,7 @@ PyNotifier &PyNotifier::operator=(PyNotifier &&rhs) {
|
||||
void PyNotifier::SetName(std::string_view name) {
|
||||
int32_t status = 0;
|
||||
HAL_SetNotifierName(m_notifier, name, &status);
|
||||
WPILIB_CheckErrorStatus(status, "SetNotifierName");
|
||||
}
|
||||
|
||||
void PyNotifier::SetCallback(std::function<void()> handler) {
|
||||
@@ -130,18 +131,21 @@ void PyNotifier::SetCallback(std::function<void()> handler) {
|
||||
void PyNotifier::StartSingle(wpi::units::second_t delay) {
|
||||
int32_t status = 0;
|
||||
HAL_SetNotifierAlarm(m_notifier, static_cast<uint64_t>(delay * 1e6), 0, false,
|
||||
&status);
|
||||
false, &status);
|
||||
WPILIB_CheckErrorStatus(status, "SetNotifierAlarm");
|
||||
}
|
||||
|
||||
void PyNotifier::StartPeriodic(wpi::units::second_t period) {
|
||||
int32_t status = 0;
|
||||
HAL_SetNotifierAlarm(m_notifier, static_cast<uint64_t>(period * 1e6),
|
||||
static_cast<uint64_t>(period * 1e6), false, &status);
|
||||
static_cast<uint64_t>(period * 1e6), false, false,
|
||||
&status);
|
||||
WPILIB_CheckErrorStatus(status, "SetNotifierAlarm");
|
||||
}
|
||||
|
||||
void PyNotifier::Stop() {
|
||||
int32_t status = 0;
|
||||
HAL_CancelNotifierAlarm(m_notifier, &status);
|
||||
HAL_CancelNotifierAlarm(m_notifier, false, &status);
|
||||
WPILIB_CheckErrorStatus(status, "CancelNotifierAlarm");
|
||||
}
|
||||
|
||||
|
||||
@@ -130,8 +130,6 @@ public class TimedRobot extends IterativeRobotBase {
|
||||
System.out.println("********** Robot program startup complete **********");
|
||||
DriverStationJNI.observeUserProgramStarting();
|
||||
|
||||
boolean first = true;
|
||||
|
||||
// Loop forever, calling the appropriate mode-dependent function
|
||||
while (true) {
|
||||
// We don't have to check there's an element in the queue first because
|
||||
@@ -139,12 +137,7 @@ public class TimedRobot extends IterativeRobotBase {
|
||||
// at the end of the loop.
|
||||
var callback = m_callbacks.poll();
|
||||
|
||||
if (first) {
|
||||
first = false;
|
||||
NotifierJNI.setNotifierAlarm(m_notifier, callback.expirationTime, 0, true);
|
||||
} else {
|
||||
NotifierJNI.acknowledgeNotifierAlarm(m_notifier, true, callback.expirationTime, 0, true);
|
||||
}
|
||||
NotifierJNI.setNotifierAlarm(m_notifier, callback.expirationTime, 0, true, true);
|
||||
|
||||
try {
|
||||
WPIUtilJNI.waitForObject(m_notifier);
|
||||
|
||||
@@ -95,7 +95,7 @@ public class Notifier implements AutoCloseable {
|
||||
}
|
||||
|
||||
// Acknowledge the alarm
|
||||
NotifierJNI.acknowledgeNotifierAlarm(notifier, false, 0, 0, false);
|
||||
NotifierJNI.acknowledgeNotifierAlarm(notifier);
|
||||
}
|
||||
});
|
||||
m_thread.setName("Notifier");
|
||||
@@ -148,7 +148,7 @@ public class Notifier implements AutoCloseable {
|
||||
* @param delay Time in seconds to wait before the callback is called.
|
||||
*/
|
||||
public void startSingle(double delay) {
|
||||
NotifierJNI.setNotifierAlarm(m_notifier.get(), (long) (delay * 1e6), 0, false);
|
||||
NotifierJNI.setNotifierAlarm(m_notifier.get(), (long) (delay * 1e6), 0, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -171,7 +171,7 @@ public class Notifier implements AutoCloseable {
|
||||
*/
|
||||
public void startPeriodic(double period) {
|
||||
long periodMicroS = (long) (period * 1e6);
|
||||
NotifierJNI.setNotifierAlarm(m_notifier.get(), periodMicroS, periodMicroS, false);
|
||||
NotifierJNI.setNotifierAlarm(m_notifier.get(), periodMicroS, periodMicroS, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -205,12 +205,9 @@ public class Notifier implements AutoCloseable {
|
||||
*
|
||||
* <p>No further periodic callbacks will occur. Single invocations will also be cancelled if they
|
||||
* haven't yet occurred.
|
||||
*
|
||||
* <p>If a callback invocation is in progress, this function will block until the callback is
|
||||
* complete.
|
||||
*/
|
||||
public void stop() {
|
||||
NotifierJNI.cancelNotifierAlarm(m_notifier.get());
|
||||
NotifierJNI.cancelNotifierAlarm(m_notifier.get(), false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -225,13 +225,10 @@ public class Watchdog implements Closeable, Comparable<Watchdog> {
|
||||
@SuppressWarnings("resource")
|
||||
private static void updateAlarm(boolean acknowledge) {
|
||||
if (m_watchdogs.isEmpty()) {
|
||||
NotifierJNI.cancelNotifierAlarm(m_notifier);
|
||||
} else if (acknowledge) {
|
||||
NotifierJNI.acknowledgeNotifierAlarm(
|
||||
m_notifier, true, (long) (m_watchdogs.peek().m_expirationTime * 1e6), 0, true);
|
||||
NotifierJNI.cancelNotifierAlarm(m_notifier, acknowledge);
|
||||
} else {
|
||||
NotifierJNI.setNotifierAlarm(
|
||||
m_notifier, (long) (m_watchdogs.peek().m_expirationTime * 1e6), 0, true);
|
||||
m_notifier, (long) (m_watchdogs.peek().m_expirationTime * 1e6), 0, true, acknowledge);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user