Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ Captured on a ZT703S running OpenOSC. The Bode screens replay a recorded twin-T
for a stable reading) and Auto (holds every new stable reading)
- Statistics, trend chart and CSV logging. MIN, MAX and AVG stay visible during OL. Accumulation
resumes with the next valid reading in the same measurement context, including after an AUTO
range change. A function change, REL and **Reset statistics** start a new period.
range change (its first, false reading is skipped, as on the screen). A function change, REL and **Reset statistics** start a new period.
An OL reading breaks the live trend curve.
**MENU → Display → Statistics** shows the current reading in large digits with MIN/MAX/AVG below it.
It is offered only while the **Statistics** setting is off; with it on, Primary already shows them.
Expand All @@ -289,10 +289,10 @@ Captured on a ZT703S running OpenOSC. The Bode screens replay a recorded twin-T
`/openosc/LOGS`. See [DMM session logging](docs/DMM_SESSION_LOGGING.md)
- Ampere-hour counter in DC current (A and mA): the signed charge since the function was selected,
shown as mAh or Ah beside the range. It counts while the readings are valid and arrive at most 2 s
apart (an overload, the meter's own HOLD or REL, a lost or corrupted reading, or a longer gap pauses
it, with nothing estimated for the missing time). Manual HOLD and REL change only the display. A
confirmed switch to another function or entering the multimeter screen resets it; a range change or
a repeated selection of the same function keeps it.
apart (an overload, the meter's own HOLD or REL, the first reading after an AUTO range change, a lost
or corrupted reading, or a longer gap pauses it, with nothing estimated for the missing time). Manual
HOLD and REL change only the display. A confirmed switch to another function or entering the
multimeter screen resets it; a range change or a repeated selection of the same function keeps it.
- Large 72/80 px reading when the bar graph and statistics are off
- Bar graph labels follow the active range in measurement units. The 2.5 V range runs from 0 to 2.5 V
in 0.5 V steps. Each notch extends below the bar and lines up with its scale value. The analog dial
Expand Down
4 changes: 3 additions & 1 deletion docs/DMM_SESSION_LOGGING.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ records, and **Estimate** shows the most the chosen duration can write.

A session measures the function shown when it starts. V and mV of the same coupling (DC or AC) count as
the same measurement, as do A and mA, because their values are recorded in SI units. A range change
keeps the session.
keeps the session. The readings the screen skips (the false reading at an AUTO range change, the two
after an overload in Ω) are not recorded either. The per-packet CSV log (`DMMnnnnn.CSV`) keeps them,
except a thermocouple's: it holds the converted temperatures and skips that reading too.

- The local **HOLD** and **REL** change only the screen. The session keeps recording the live readings,
without the REL offset.
Expand Down
3 changes: 2 additions & 1 deletion include/openosc/measurement/dmm/charge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ enum class Function : unsigned; // function.hpp
// consecutive DC current readings of one function, both valid and at most MaximumGapUs apart, adds
// their mean current times its length (the trapezoid rule). Any other packet ends the run: an
// overload, no reading, AC, another function, a packet of an unconfirmed selection, the DMM's own
// HOLD or REL (their values are not the current), or a gap longer than MaximumGapUs; so does every
// HOLD or REL (their values are not the current), the first reading after an AUTO range change (a
// false value, Session's RangeSettle), or a gap longer than MaximumGapUs; so does every
// known loss of readings, however short (interrupt(): a UART error or restart, a rejected or
// undecodable packet, readings expired): no current is assumed where none was read, and the charge
// stays. Only a confirmed packet of another function or input resets it, and leaving or entering the
Expand Down
27 changes: 25 additions & 2 deletions include/openosc/measurement/dmm/session.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,27 @@ class OverloadSettle {
private:
unsigned left_ = 0;
};
// The chip's first reading after it changes the range itself (AUTO) is wrong: 0 V, or the old digits at
// the new range's scale (23.03 V stepping 2.2 -> 4.5 V), seen at the 2.5 V and the 25 mA switches on the
// bench. That reading, the first in another range of the same function (Ranges::current) as the chip
// sends it (a thermocouple's millivolts, not the temperature), is not shown, as an overload's settling,
// and not integrated by the charge, in HOLD too. Only a usable number or an overload tells the range: a
// placeholder ("--.--") is passed through and leaves what RangeSettle knows untouched, so a range change
// across a placeholder still drops the first number after it.
// The switching reading sometimes comes flagged MANUAL, so AUTO on the reading before it counts as well
// as on the reading itself: a range changed in MANUAL is the user's and is shown at once, while leaving
// or entering AUTO drops one reading when that also changes the range. An overload is always shown, and
// never two in a row: a signal that keeps the chip switching shows its readings rather than freezing on
// an old one.
class RangeSettle {
public:
bool skip(const Result &result); // True: this reading is not shown.
void clear() { index_ = function_ = ~0U; automatic_ = skipped_ = current_ = false; }
private:
unsigned index_ = ~0U, function_ = ~0U; // function_, current_: what index_ is a range of.
// automatic_: the last reading that told the range (a number or an overload) was in AUTO.
bool automatic_ = false, skipped_ = false, current_ = false;
};
class Session {
public:
bool accept(const uint8_t *packet, size_t bytes, uint64_t timestampUs, bool functionPending = false);
Expand All @@ -147,7 +168,7 @@ class Session {
// Readings before nowUs are stale (an activation, a resume): the charge's run ends there too.
void expire(uint64_t nowUs) { freshFromUs_ = nowUs; charge_.interrupt(); }
// The last packet as decoded: its function, range, HOLD and REL flags for the commands, and the
// raw stream (log, serial output). Settling readings (OverloadSettle) are here too.
// raw stream (log, serial output). Settling readings (OverloadSettle, RangeSettle) are here too.
const Result &latest() const { return latest_; }
const Result &live() const { return shown_; }
const TemperatureSettings &temperatureSettings() const { return temperatureSettings_; }
Expand Down Expand Up @@ -192,7 +213,8 @@ class Session {
const Statistics &statistics() const { return stats_; }
const History &history() const { return history_; }
const RelativeReading &relative() const { return relative_; }
// The DC current's ampere-hour counter (ChargeCounter): fed by every decoded packet, HOLD or not;
// The DC current's ampere-hour counter (ChargeCounter): fed by every decoded packet, HOLD or not, except
// the first reading after an AUTO range change (RangeSettle), which ends its run;
// reset by a confirmed packet of another function and by entering or leaving the DMM (resetCharge,
// DataAccess and the controller); interruptCharge: readings were lost (UART, framing), the charge stays.
const ChargeCounter &charge() const { return charge_; }
Expand Down Expand Up @@ -258,6 +280,7 @@ class Session {
Result latest_, shown_, held_;
uint8_t raw_[18]{}, rawBytes_ = 0; // Packet::Bytes.
OverloadSettle settle_;
RangeSettle rangeSettle_;
HoldDetector detector_;
Statistics stats_;
History history_;
Expand Down
9 changes: 6 additions & 3 deletions src/instrument/poll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,12 @@ void DataAccess::poll(uint32_t now) {
watchdog_.packet(timeUs_);
if (meter_.accept(packet, sizeof packet, timeUs_, dmm_.functionPending(meter_.latest()))) {
reportMeterStatus(meter_.latest().primary.status);
const auto &reading = meter_.live().primary.quantity == Quantity::Temperature ? meter_.live() : meter_.latest();
if (logger_.active()) logger_.append(reading, meter_.userHeld());
session_.observe(reading, meterFunction(), thermocoupleType());
const auto &live = meter_.live();
// The DMM log keeps the raw packets (a temperature as converted in live(), so not a dropped one).
if (logger_.active()) logger_.append(live.primary.quantity == Quantity::Temperature ? live : meter_.latest(), meter_.userHeld());
// The session log takes only a reading that passed the range and overload settling: a dropped
// packet leaves live() at the reading before.
if (live.sequence == meter_.latest().sequence) session_.observe(live, meterFunction(), thermocoupleType());
}
}
meter_.service(timeUs_); // The hold mode's countdown and freshness, with or without packets.
Expand Down
36 changes: 31 additions & 5 deletions src/measurement/dmm/session.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
#include "openosc/measurement/dmm/session.hpp"
#include "openosc/measurement/dmm/function.hpp"
#include "openosc/measurement/dmm/ranges.hpp"
#include "openosc/data/decimal.hpp"
#include <algorithm>
#include <cmath>
#include <iterator>
#include <limits>

namespace openosc::dmm {
bool RangeSettle::skip(const Result &result) {
if (!result.primary.valid() && result.primary.status != DataStatus::Overload) return false; // A placeholder says nothing of the range.
// Ranges compare within one function and input, tracked here: the session's own context stays frozen
// under HOLD, while a function selected then must not take its first range for a change.
const auto function = Functions::identify(result);
if (function != Function::Unknown && (unsigned(function) != function_ || result.currentInput != current_)) {
clear();
function_ = unsigned(function); current_ = result.currentInput;
}
unsigned index = ~0U;
if (!Ranges::current(result, &index)) index = ~0U;
const bool switched = (automatic_ || result.range == RangeMode::Auto) && result.primary.status != DataStatus::Overload &&
index != ~0U && index_ != ~0U && index != index_ && !skipped_;
index_ = index;
automatic_ = result.range == RangeMode::Auto;
skipped_ = switched;
return switched;
}
namespace {
Result asTemperature(const Result &packet, const TemperatureSettings &settings, bool thermocouple,
std::optional<int16_t> mcuJunction) {
Expand Down Expand Up @@ -170,7 +189,7 @@ bool History::column(unsigned index, uint64_t endUs, Column &output) const {
}
void Session::reselect() {
resetStatistics(); // The charge stays: only a confirmed packet of another function resets it.
settle_.clear();
settle_.clear(); rangeSettle_.clear();
detector_.reselect(); // The old function's snapshot and window go with the selection.
awaiting_ = false;
}
Expand Down Expand Up @@ -205,13 +224,20 @@ bool Session::accept(const uint8_t *packet, size_t bytes, uint64_t timestampUs,
const bool known = function != Function::Unknown;
const bool functionChanged = known && function_ != ~0U && (unsigned(function) != function_ || candidate.currentInput != functionCurrent_);
const bool settles = (known && function == awaited_) || timestampUs >= awaitUntilUs_;
// After an overload in Ohm, two readings are not shown, and after an AUTO range change one: nothing
// below sees them (display, hold mode, statistics, trend). Under HOLD the overload settling waits, as
// the factory decodes nothing then.
if (functionChanged) settle_.clear(); // The range settle follows the function itself (RangeSettle::skip).
// The range settle sees every packet, HOLD or not, to know the range the next one comes from.
const bool settling = !userHold_ && !candidate.packetHold;
const bool overloadSettles = settling && settle_.skip(candidate), rangeSettles = rangeSettle_.skip(latest_);
// A range change's false reading is no current either, in HOLD too: the charge's run pauses there,
// nothing estimated.
if (rangeSettles) { charge_.interrupt(); return true; }
// The charge reads the packet itself: the manual HOLD, the hold modes and the local REL only change
// what is shown. A selection not yet confirmed is not integrated.
charge_.observe(candidate, timestampUs, !awaiting_ || settles);
// After an overload in Ohm, two readings are not shown: nothing below sees them (display, hold
// mode, statistics, trend). Under HOLD the settling waits, as the factory decodes nothing then.
if (functionChanged) settle_.clear();
if (!userHold_ && !candidate.packetHold && settle_.skip(candidate)) return true;
if (overloadSettles) return true;
shown_ = candidate;
detector_.observe(candidate, {relative_.active() && !functionChanged, candidate.packetHold,
functionPending || (awaiting_ && !settles)});
Expand Down