работает с перемычкой на 1МГц 2%
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
bool Measurement::start(float hz, float duty, float tolerance, uint32_t timeMs,
|
||||
uint8_t repeats, uint8_t settleCycles) {
|
||||
if (!task_ && xTaskCreate(taskEntry, "optical-rx", 4096, this, 4, &task_) != pdPASS) return false;
|
||||
expectedHz_ = static_cast<uint32_t>(hz + 0.5f);
|
||||
if (!expectedHz_ || !timeMs || !repeats || repeats > 10 ||
|
||||
!makePeriodLimits(expectedHz_, duty, tolerance, receiver_.tickHz(), limits_) ||
|
||||
@@ -15,7 +16,20 @@ bool Measurement::start(float hz, float duty, float tolerance, uint32_t timeMs,
|
||||
currentRepeat_ = 0;
|
||||
expectedPeriodMs_ = static_cast<uint32_t>((1000ULL + expectedHz_ - 1U) / expectedHz_);
|
||||
if (!expectedPeriodMs_) expectedPeriodMs_ = 1;
|
||||
state_ = MeasureState::SETTLING; return true;
|
||||
state_ = MeasureState::SETTLING;
|
||||
xTaskNotifyGive(task_);
|
||||
return true;
|
||||
}
|
||||
|
||||
void Measurement::taskEntry(void *context) {
|
||||
static_cast<Measurement *>(context)->taskLoop();
|
||||
}
|
||||
|
||||
void Measurement::taskLoop() {
|
||||
for (;;) {
|
||||
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
|
||||
while (state_ == MeasureState::SETTLING || state_ == MeasureState::RUNNING) processOnce();
|
||||
}
|
||||
}
|
||||
|
||||
void Measurement::fail(FailReason reason) {
|
||||
@@ -25,25 +39,25 @@ void Measurement::fail(FailReason reason) {
|
||||
|
||||
void Measurement::completeWindow() {
|
||||
receiver_.stop();
|
||||
stats_.lostItems += receiver_.takeDroppedItems();
|
||||
stats_.droppedItems += receiver_.takeDroppedItems();
|
||||
if (receiver_.overflowed()) { fail(FailReason::GLITCH); return; }
|
||||
for (uint8_t i = 0; i < repeats_; ++i) if (!repeatPeriods_[i]) {
|
||||
fail(FailReason::TOO_FEW_PERIODS); return;
|
||||
}
|
||||
if (stats_.lostItems && stats_.reason == FailReason::NONE) stats_.reason = FailReason::DATA_LOST;
|
||||
state_ = MeasureState::PASS;
|
||||
}
|
||||
|
||||
MeasureState Measurement::update() {
|
||||
MeasureState Measurement::processOnce() {
|
||||
if (state_ != MeasureState::SETTLING && state_ != MeasureState::RUNNING) return state_;
|
||||
if (receiver_.overflowed()) { fail(FailReason::GLITCH); return state_; }
|
||||
bool receivedPeriod = false;
|
||||
for (;;) {
|
||||
const size_t periodCount = receiver_.readPeriods(periodBatch_, PERIOD_BATCH_SIZE);
|
||||
stats_.lostItems += receiver_.takeDroppedItems();
|
||||
const size_t periodCount = receiver_.readPeriods(periodBatch_, PERIOD_BATCH_SIZE, pdMS_TO_TICKS(2));
|
||||
stats_.droppedItems += receiver_.takeDroppedItems();
|
||||
if (!periodCount) break;
|
||||
receivedPeriod = true;
|
||||
for (size_t periodIndex = 0; periodIndex < periodCount; ++periodIndex) {
|
||||
if (state_ != MeasureState::SETTLING && state_ != MeasureState::RUNNING) return state_;
|
||||
const PulsePeriod &period = periodBatch_[periodIndex];
|
||||
if (state_ == MeasureState::SETTLING) {
|
||||
if (settleLeft_) --settleLeft_;
|
||||
@@ -86,4 +100,6 @@ MeasureState Measurement::update() {
|
||||
return state_;
|
||||
}
|
||||
|
||||
MeasureState Measurement::update() { return state_; }
|
||||
|
||||
void Measurement::abort() { if (state_ == MeasureState::SETTLING || state_ == MeasureState::RUNNING) fail(FailReason::ABORTED); }
|
||||
|
||||
Reference in New Issue
Block a user