From 98071602c32694d98b02c22aa8018879212d3ae4 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Fri, 12 Mar 2021 22:12:13 +0100 Subject: [PATCH] Bugfix: Transmit packages of size MAX_PACKET_SIZE (5) as well --- DCC.cpp | 8 ++++++++ DCCWaveform.cpp | 3 ++- DCCWaveform.h | 6 +++--- version.h | 4 +++- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/DCC.cpp b/DCC.cpp index 854f9b2..e6b3c64 100644 --- a/DCC.cpp +++ b/DCC.cpp @@ -198,6 +198,10 @@ void DCC::setAccessory(int address, byte number, bool activate) { DCCWaveform::mainTrack.schedulePacket(b, 2, 4); // Repeat the packet four times } +// +// writeCVByteMain: Write a byte with PoM on main. This writes +// the 5 byte sized packet to implement this DCC function +// void DCC::writeCVByteMain(int cab, int cv, byte bValue) { byte b[5]; byte nB = 0; @@ -212,6 +216,10 @@ void DCC::writeCVByteMain(int cab, int cv, byte bValue) { DCCWaveform::mainTrack.schedulePacket(b, nB, 4); } +// +// writeCVBitMain: Write a bit of a byte with PoM on main. This writes +// the 5 byte sized packet to implement this DCC function +// void DCC::writeCVBitMain(int cab, int cv, byte bNum, bool bValue) { byte b[5]; byte nB = 0; diff --git a/DCCWaveform.cpp b/DCCWaveform.cpp index c7baa9f..8da4e0c 100644 --- a/DCCWaveform.cpp +++ b/DCCWaveform.cpp @@ -256,7 +256,7 @@ void DCCWaveform::interrupt2() { // Wait until there is no packet pending, then make this pending void DCCWaveform::schedulePacket(const byte buffer[], byte byteCount, byte repeats) { - if (byteCount >= MAX_PACKET_SIZE) return; // allow for chksum + if (byteCount > MAX_PACKET_SIZE) return; // allow for chksum while (packetPending); byte checksum = 0; @@ -264,6 +264,7 @@ void DCCWaveform::schedulePacket(const byte buffer[], byte byteCount, byte repea checksum ^= buffer[b]; pendingPacket[b] = buffer[b]; } + // buffer is MAX_PACKET_SIZE but pendingPacket is one bigger pendingPacket[byteCount] = checksum; pendingLength = byteCount + 1; pendingRepeats = repeats; diff --git a/DCCWaveform.h b/DCCWaveform.h index aad63ae..db6c7f7 100644 --- a/DCCWaveform.h +++ b/DCCWaveform.h @@ -29,7 +29,7 @@ const int POWER_SAMPLE_OVERLOAD_WAIT = 20; // Number of preamble bits. const int PREAMBLE_BITS_MAIN = 16; const int PREAMBLE_BITS_PROG = 22; -const byte MAX_PACKET_SIZE = 5; // NMRA standard exrtended packets +const byte MAX_PACKET_SIZE = 5; // NMRA standard extended packets, payload size WITHOUT checksum. // The WAVE_STATE enum is deliberately numbered because a change of order would be catastrophic // to the transform array. @@ -119,7 +119,7 @@ class DCCWaveform { bool isMainTrack; MotorDriver* motorDriver; // Transmission controller - byte transmitPacket[MAX_PACKET_SIZE]; // packet being transmitted + byte transmitPacket[MAX_PACKET_SIZE+1]; // +1 for checksum byte transmitLength; byte transmitRepeats; // remaining repeats of transmission byte remainingPreambles; @@ -127,7 +127,7 @@ class DCCWaveform { byte bits_sent; // 0-8 (yes 9 bits) sent for current byte byte bytes_sent; // number of bytes sent from transmitPacket WAVE_STATE state; // wave generator state machine - byte pendingPacket[MAX_PACKET_SIZE]; + byte pendingPacket[MAX_PACKET_SIZE+1]; // +1 for checksum byte pendingLength; byte pendingRepeats; int lastCurrent; diff --git a/version.h b/version.h index 97b082c..64ef071 100644 --- a/version.h +++ b/version.h @@ -3,7 +3,9 @@ #include "StringFormatter.h" -#define VERSION "3.0.5" +#define VERSION "3.0.6" +// 3.0.6 Includes: +// Fix Bug that did not let us transmit 5 byte sized packets like PoM // 3.0.5 Includes: // Fix Fn Key startup with loco ID and fix state change for F16-28 // 3.0.4 Includes: