mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-22 23:56:13 +01:00
Improved HAL diagnostics
Looptime diagnostic enhanced, and duplicated diagnostic messages removed from DFPlayer class.
This commit is contained in:
parent
302b16547e
commit
e59e07b971
22
IODevice.cpp
22
IODevice.cpp
|
@ -89,24 +89,32 @@ void IODevice::loop() {
|
||||||
// Report loop time if diags enabled
|
// Report loop time if diags enabled
|
||||||
#if defined(DIAG_LOOPTIMES)
|
#if defined(DIAG_LOOPTIMES)
|
||||||
static unsigned long lastMicros = 0;
|
static unsigned long lastMicros = 0;
|
||||||
static unsigned long maxElapsed = 0;
|
// Measure time since loop() method started.
|
||||||
|
unsigned long halElapsed = micros() - currentMicros;
|
||||||
|
// Measure time between loop() method entries.
|
||||||
|
unsigned long elapsed = currentMicros - lastMicros;
|
||||||
|
static unsigned long maxElapsed = 0, maxHalElapsed = 0;
|
||||||
static unsigned long lastOutputTime = 0;
|
static unsigned long lastOutputTime = 0;
|
||||||
|
static unsigned long halTotal = 0, total = 0;
|
||||||
static unsigned long count = 0;
|
static unsigned long count = 0;
|
||||||
const unsigned long interval = (unsigned long)5 * 1000 * 1000; // 5 seconds in microsec
|
const unsigned long interval = (unsigned long)5 * 1000 * 1000; // 5 seconds in microsec
|
||||||
unsigned long elapsed = currentMicros - lastMicros;
|
|
||||||
// Ignore long loop counts while message is still outputting
|
// Ignore long loop counts while message is still outputting
|
||||||
if (currentMicros - lastOutputTime > 3000UL) {
|
if (currentMicros - lastOutputTime > 3000UL) {
|
||||||
if (elapsed > maxElapsed) maxElapsed = elapsed;
|
if (elapsed > maxElapsed) maxElapsed = elapsed;
|
||||||
|
if (halElapsed > maxHalElapsed) maxHalElapsed = halElapsed;
|
||||||
|
halTotal += halElapsed;
|
||||||
|
total += elapsed;
|
||||||
|
count++;
|
||||||
}
|
}
|
||||||
count++;
|
|
||||||
if (currentMicros - lastOutputTime > interval) {
|
if (currentMicros - lastOutputTime > interval) {
|
||||||
if (lastOutputTime > 0)
|
if (lastOutputTime > 0)
|
||||||
LCD(1,F("Loop=%lus,%lus max"), interval/count, maxElapsed);
|
DIAG(F("Loop Total:%lus (%lus max) HAL:%lus (%lus max)"),
|
||||||
maxElapsed = 0;
|
total/count, maxElapsed, halTotal/count, maxHalElapsed);
|
||||||
count = 0;
|
maxElapsed = maxHalElapsed = total = halTotal = count = 0;
|
||||||
lastOutputTime = currentMicros;
|
lastOutputTime = currentMicros;
|
||||||
}
|
}
|
||||||
lastMicros = micros();
|
lastMicros = currentMicros;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,12 +69,14 @@ private:
|
||||||
unsigned long _commandSendTime; // Allows timeout processing
|
unsigned long _commandSendTime; // Allows timeout processing
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DFPlayer(VPIN firstVpin, int nPins, HardwareSerial &serial) {
|
// Constructor
|
||||||
_firstVpin = firstVpin;
|
DFPlayer(VPIN firstVpin, int nPins, HardwareSerial &serial) :
|
||||||
_nPins = nPins;
|
IODevice(firstVpin, nPins),
|
||||||
_serial = &serial;
|
_serial(&serial)
|
||||||
|
{
|
||||||
addDevice(this);
|
addDevice(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void create(VPIN firstVpin, int nPins, HardwareSerial &serial) {
|
static void create(VPIN firstVpin, int nPins, HardwareSerial &serial) {
|
||||||
new DFPlayer(firstVpin, nPins, serial);
|
new DFPlayer(firstVpin, nPins, serial);
|
||||||
}
|
}
|
||||||
|
@ -101,20 +103,25 @@ protected:
|
||||||
|| (_inputIndex >=4 && _inputIndex <= 8))
|
|| (_inputIndex >=4 && _inputIndex <= 8))
|
||||||
_inputIndex++;
|
_inputIndex++;
|
||||||
else if (c==0x06 && _inputIndex==2) {
|
else if (c==0x06 && _inputIndex==2) {
|
||||||
// Valid command prefix, so consider the device online.
|
// Valid message prefix, so consider the device online
|
||||||
_deviceState = DEVSTATE_NORMAL;
|
if (_deviceState==DEVSTATE_INITIALISING) {
|
||||||
#ifdef DIAG_IO
|
_deviceState = DEVSTATE_NORMAL;
|
||||||
_display();
|
#ifdef DIAG_IO
|
||||||
#endif
|
_display();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
_inputIndex++;
|
_inputIndex++;
|
||||||
} else if (c==0xEF && _inputIndex==9) {
|
} else if (c==0xEF && _inputIndex==9) {
|
||||||
// End of play
|
// End of play
|
||||||
#ifdef DIAG_IO
|
if (_playing) {
|
||||||
DIAG(F("DFPlayer: Finished"));
|
#ifdef DIAG_IO
|
||||||
#endif
|
DIAG(F("DFPlayer: Finished"));
|
||||||
_playing = false;
|
#endif
|
||||||
|
_playing = false;
|
||||||
|
}
|
||||||
_inputIndex = 0;
|
_inputIndex = 0;
|
||||||
}
|
} else
|
||||||
|
_inputIndex = 0; // Unrecognised character sequence, start again!
|
||||||
}
|
}
|
||||||
// Check if the initial prompt to device has timed out. Allow 1 second
|
// Check if the initial prompt to device has timed out. Allow 1 second
|
||||||
if (_deviceState == DEVSTATE_INITIALISING && currentMicros - _commandSendTime > 1000000UL) {
|
if (_deviceState == DEVSTATE_INITIALISING && currentMicros - _commandSendTime > 1000000UL) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user