1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2025-04-21 20:41:19 +02:00

Compare commits

..

4 Commits

Author SHA1 Message Date
Asbelos
2fb0f4fb1b DCC setTime packet 2025-01-02 11:01:46 +00:00
Asbelos
90571146e1 Merge branch 'devel' into devel-railcom2 2024-12-30 15:20:31 +00:00
Harald Barth
818240b349 version tag 2024-12-28 15:46:32 +01:00
Harald Barth
3c725afab4 Less confusion and simpler code around the RCN213 defines 2024-12-28 15:45:27 +01:00
9 changed files with 54 additions and 14 deletions

View File

@ -185,6 +185,9 @@ void CommandDistributor::setClockTime(int16_t clocktime, int8_t clockrate, byte
{ {
case 1: case 1:
if (clocktime != lastclocktime){ if (clocktime != lastclocktime){
auto difference = clocktime - lastclocktime;
if (difference<0) difference+=1440;
DCC::setTime(clocktime,clockrate,difference>2);
// CAH. DIAG removed because LCD does it anyway. // CAH. DIAG removed because LCD does it anyway.
LCD(6,F("Clk Time:%d Sp %d"), clocktime, clockrate); LCD(6,F("Clk Time:%d Sp %d"), clocktime, clockrate);
// look for an event for this time // look for an event for this time

38
DCC.cpp
View File

@ -371,6 +371,44 @@ whole range of the 11 bits sent to track.
return true; return true;
} }
bool DCC::setTime(uint16_t minutes,uint8_t speed, bool suddenChange) {
/* see rcn-122
5 Global commands
These commands are sent and begin exclusively with a broadcast address 0
always with {synchronous bits} 0 0000-0000 and end with the checksum
... PPPPPPPP 1. Therefore, only the bytes of the commands and not that of
shown below whole package shown. The commands can be used by vehicle and
accessory decoders alike.
5.1 Time command
This command is four bytes long and has the format:
1100-0001 CCxx-xxxx xxxx-xxxxx xxxx-xxxx
CC indicates what data is transmitted in the packet:
CC = 00 Model Time
1100-0001 00MM-MMMM WWWH-HHHH U0BB-BBBB with:
MMMMMM = Minutes, Value range: 0..59
WWW = Day of the Week, Value range: 0 = Monday, 1 = Tuesday, 2 = Wednesday,
3 = Thursday, 4 = Friday, 5 = Saturday, 6 = Sunday, 7 = Weekday
is not supported.
HHHHH = Hours, value range: 0..23
U =
Update, i.e. the time has changed suddenly, e.g. by a new one timetable to start.
Up to 4 can occur per sudden change commands can be marked like this.
BBBBBB = Acceleration factor, value range 0..63. An acceleration factor of 0 means the
model clock has been stopped, a factor of 1 corresponds to real time, at 2 the
clock runs twice as fast, at three times as fast as real time, etc.
*/
if (minutes>=1440 || speed>63 ) return false;
byte b[5];
b[0]=0; // broadcast address
b[1]=0b11000001; // 1100-0001 (model time)
b[2]=minutes % 60 ; // MM
b[3]= 0b11100000 | (minutes/60); // 111H-HHHH weekday not supported
b[4]= (suddenChange ? 0b10000000 : 0) | speed;
DCCWaveform::mainTrack.schedulePacket(b, sizeof(b), 2);
return true;
}
// //
// writeCVByteMain: Write a byte with PoM on main. This writes // writeCVByteMain: Write a byte with PoM on main. This writes
// the 5 byte sized packet to implement this DCC function // the 5 byte sized packet to implement this DCC function

1
DCC.h
View File

@ -77,6 +77,7 @@ public:
static void setAccessory(int address, byte port, bool gate, byte onoff = 2); static void setAccessory(int address, byte port, bool gate, byte onoff = 2);
static bool setExtendedAccessory(int16_t address, int16_t value, byte repeats=3); static bool setExtendedAccessory(int16_t address, int16_t value, byte repeats=3);
static bool writeTextPacket(byte *b, int nBytes); static bool writeTextPacket(byte *b, int nBytes);
static bool setTime(uint16_t minutes,uint8_t speed, bool suddenChange);
// ACKable progtrack calls bitresults callback 0,0 or -1, cv returns value or -1 // ACKable progtrack calls bitresults callback 0,0 or -1, cv returns value or -1
static void readCV(int16_t cv, ACK_CALLBACK callback); static void readCV(int16_t cv, ACK_CALLBACK callback);

View File

@ -402,7 +402,8 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream)
|| (p[activep] > 1) || (p[activep] < 0) // invalid activate 0|1 || (p[activep] > 1) || (p[activep] < 0) // invalid activate 0|1
) break; ) break;
// Honour the configuration option (config.h) which allows the <a> command to be reversed // Honour the configuration option (config.h) which allows the <a> command to be reversed
#ifdef DCC_ACCESSORY_COMMAND_REVERSE // Because of earlier confusion we need to do the same thing under both defines
#if defined(DCC_ACCESSORY_COMMAND_REVERSE) || defined(DCC_ACCESSORY_RCN_213)
DCC::setAccessory(address, subaddress,p[activep]==0,onoff); DCC::setAccessory(address, subaddress,p[activep]==0,onoff);
#else #else
DCC::setAccessory(address, subaddress,p[activep]==1,onoff); DCC::setAccessory(address, subaddress,p[activep]==1,onoff);

View File

@ -1 +1 @@
#define GITHUB_SHA "devel-railcom2-202409282036Z" #define GITHUB_SHA "devel-202412281446Z"

View File

@ -312,12 +312,6 @@
* *
*************************************************************************************/ *************************************************************************************/
#if defined(DCC_TURNOUTS_RCN_213)
const bool DCCTurnout::rcn213Compliant = true;
#else
const bool DCCTurnout::rcn213Compliant = false;
#endif
// DCCTurnoutData contains data specific to this subclass that is // DCCTurnoutData contains data specific to this subclass that is
// written to EEPROM when the turnout is saved. // written to EEPROM when the turnout is saved.
struct DCCTurnoutData { struct DCCTurnoutData {
@ -385,7 +379,10 @@
// DCC++ Classic behaviour is that Throw writes a 1 in the packet, // DCC++ Classic behaviour is that Throw writes a 1 in the packet,
// and Close writes a 0. // and Close writes a 0.
// RCN-213 specifies that Throw is 0 and Close is 1. // RCN-213 specifies that Throw is 0 and Close is 1.
DCC::setAccessory(_dccTurnoutData.address, _dccTurnoutData.subAddress, close ^ !rcn213Compliant); #if defined(DCC_TURNOUTS_RCN_213)
close = !close;
#endif
DCC::setAccessory(_dccTurnoutData.address, _dccTurnoutData.subAddress, close);
return true; return true;
} }

View File

@ -245,8 +245,6 @@ public:
// Load a VPIN turnout definition from EEPROM. The common Turnout data has already been read at this point. // Load a VPIN turnout definition from EEPROM. The common Turnout data has already been read at this point.
static Turnout *load(struct TurnoutData *turnoutData); static Turnout *load(struct TurnoutData *turnoutData);
void print(Print *stream) override; void print(Print *stream) override;
// Flag whether DCC Accessory packets are to contain 1=close/0=throw(RCN-213) or 1=throw/0-close (DCC++ Classic)
static const bool rcn213Compliant;
protected: protected:
bool setClosedInternal(bool close) override; bool setClosedInternal(bool close) override;

View File

@ -269,9 +269,10 @@ The configuration file for DCC-EX Command Station
// over DCC++. This #define likewise inverts the behaviour of the <a> command // over DCC++. This #define likewise inverts the behaviour of the <a> command
// for triggering DCC Accessory Decoders, so that <a addr subaddr 0> generates a // for triggering DCC Accessory Decoders, so that <a addr subaddr 0> generates a
// DCC packet with D=1 (close turnout) and <a addr subaddr 1> generates D=0 // DCC packet with D=1 (close turnout) and <a addr subaddr 1> generates D=0
// (throw turnout). // (throw turnout). This is the same as DCC_ACCESSORY_COMMAND_REVERSE
//#define DCC_ACCESSORY_RCN_213 //#define DCC_ACCESSORY_RCN_213
//
// HANDLING MULTIPLE SERIAL THROTTLES // HANDLING MULTIPLE SERIAL THROTTLES
// The command station always operates with the default Serial port. // The command station always operates with the default Serial port.
// Diagnostics are only emitted on the default serial port and not broadcast. // Diagnostics are only emitted on the default serial port and not broadcast.

View File

@ -3,7 +3,8 @@
#include "StringFormatter.h" #include "StringFormatter.h"
#define VERSION "5.2.93" #define VERSION "5.2.94"
// 5.2.94 - Bugfix: Less confusion and simpler code around the RCN213 defines
// 5.2.93 - Bugfix ESP32: clear progTrackSyncMain (join flag) when prog track is removed // 5.2.93 - Bugfix ESP32: clear progTrackSyncMain (join flag) when prog track is removed
// 5.2.92 - Bugfix: FADE power off fix, EXRAIL power diagnostic fix. // 5.2.92 - Bugfix: FADE power off fix, EXRAIL power diagnostic fix.
// 5.2.91 - Bugfix: Neopixel I2C overlap check // 5.2.91 - Bugfix: Neopixel I2C overlap check