Skip to content

Commit 7783dda

Browse files
committed
Update to v1.1
1 parent bff0a17 commit 7783dda

File tree

4 files changed

+5
-178
lines changed

4 files changed

+5
-178
lines changed

LocoNetKS.cpp

Lines changed: 1 addition & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
||
33
|| @file LocoNetKS.cpp
4-
|| @version 1.0
4+
|| @version 1.1
55
|| @author Michael Zimmermann
66
|| @contact michael.zimmermann.sg@t-online.de
77
||
@@ -92,151 +92,3 @@ LN_STATUS LocoNetClassKS::sendReportSensor(uint16_t Address, uint8_t State)
9292
return LocoNet.send(OPC_INPUT_REP, AddrL, AddrH);
9393
}
9494
//=== end LocoNetClassKS ===
95-
96-
//=== LocoNetFastClockClassKS ===
97-
/* this class is copied from original LocoNetFastClockClass in file loconet.cpp (Version 1.1.13)
98-
* modification is made for new flag "FC_FLAG_NOTIFY_JMRI" (see also commenst "added")
99-
*/
100-
#define FC_FLAG_DCS100_COMPATIBLE_SPEED 0x01
101-
#define FC_FLAG_MINUTE_ROLLOVER_SYNC 0x02
102-
#define FC_FLAG_NOTIFY_FRAC_MINS_TICK 0x04
103-
#define FC_FLAG_NOTIFY_JMRI 0x08 // new for JMRI
104-
#define FC_FRAC_MIN_BASE 0x3FFF
105-
#define FC_FRAC_RESET_HIGH 0x78
106-
#define FC_FRAC_RESET_LOW 0x6D
107-
#define FC_TIMER_TICKS 65 // 65ms ticks
108-
#define FC_TIMER_TICKS_REQ 250 // 250ms waiting for Response to FC Req
109-
110-
void LocoNetFastClockClassKS::init(uint8_t DCS100CompatibleSpeed, uint8_t CorrectDCS100Clock, uint8_t NotifyFracMin)
111-
{
112-
fcState = FC_ST_IDLE;
113-
114-
fcFlags = 0;
115-
if (DCS100CompatibleSpeed)
116-
fcFlags |= FC_FLAG_DCS100_COMPATIBLE_SPEED;
117-
118-
if (CorrectDCS100Clock)
119-
fcFlags |= FC_FLAG_MINUTE_ROLLOVER_SYNC;
120-
121-
if (NotifyFracMin)
122-
fcFlags |= FC_FLAG_NOTIFY_FRAC_MINS_TICK;
123-
}
124-
125-
// new method
126-
void LocoNetFastClockClassKS::initJMRI(uint8_t IsJMRI)
127-
{
128-
fcLastfrac_minsh = 0;
129-
if (IsJMRI)
130-
fcFlags |= FC_FLAG_NOTIFY_JMRI;
131-
}
132-
133-
void LocoNetFastClockClassKS::poll(void)
134-
{
135-
LocoNet.send(OPC_RQ_SL_DATA, FC_SLOT, 0);
136-
}
137-
138-
void LocoNetFastClockClassKS::doNotify(uint8_t Sync)
139-
{
140-
if (notifyFastClock)
141-
notifyFastClock(fcSlotData.clk_rate, fcSlotData.days,
142-
(fcSlotData.hours_24 >= (128 - 24)) ? fcSlotData.hours_24 - (128 - 24) : fcSlotData.hours_24 % 24,
143-
fcSlotData.mins_60 - (127 - 60), Sync);
144-
}
145-
146-
// changed method
147-
void LocoNetFastClockClassKS::processMessage(lnMsg* LnPacket)
148-
{
149-
if ((LnPacket->fc.slot == FC_SLOT) && ((LnPacket->fc.command == OPC_WR_SL_DATA) || (LnPacket->fc.command == OPC_SL_RD_DATA)))
150-
{
151-
if ((LnPacket->fc.clk_cntrl & 0x40)
152-
// +++ added because JMRI is sending 'fc.clk_cntrl = 0x00' (Bit 6 not set)
153-
|| (fcFlags & FC_FLAG_NOTIFY_JMRI))
154-
// added end
155-
{
156-
if (fcState >= FC_ST_REQ_TIME)
157-
{
158-
memcpy(&fcSlotData, &LnPacket->fc, sizeof(fastClockMsg));
159-
// ++ added for JMRI and use in "process66msActions"
160-
fcLastfrac_minsh = fcSlotData.frac_minsh;
161-
// added end
162-
doNotify(1);
163-
164-
if (notifyFastClockFracMins && fcFlags & FC_FLAG_NOTIFY_FRAC_MINS_TICK)
165-
notifyFastClockFracMins(FC_FRAC_MIN_BASE - ((fcSlotData.frac_minsh << 7) + fcSlotData.frac_minsl));
166-
167-
fcState = FC_ST_READY;
168-
}
169-
}
170-
else
171-
fcState = FC_ST_DISABLED;
172-
}
173-
}
174-
175-
// changed method
176-
void LocoNetFastClockClassKS::process66msActions(void)
177-
{
178-
// If we are all initialised and ready then increment accumulators
179-
if (fcState == FC_ST_READY)
180-
{
181-
fcSlotData.frac_minsl += fcSlotData.clk_rate;
182-
if (fcSlotData.frac_minsl & 0x80)
183-
{
184-
fcSlotData.frac_minsl &= ~0x80;
185-
186-
fcSlotData.frac_minsh++;
187-
if ((fcSlotData.frac_minsh & 0x80)
188-
// +++ added because JMRI starts with 'fcSlotData.frac_minsh = 3' instead of FC_FRAC_RESET_HIGH (0x78)
189-
// therefore fcSlotData.frac_minsh is always less than 0x80
190-
// and fcSlotData.frac_minsh comes in maximum up to 10, independant from fcSlotdata.clk_rate
191-
|| ((fcFlags & FC_FLAG_NOTIFY_JMRI) &&
192-
(fcSlotData.frac_minsh > (fcLastfrac_minsh + 6)) &&
193-
(fcSlotData.frac_minsh < (FC_FRAC_RESET_HIGH + (fcFlags & FC_FLAG_DCS100_COMPATIBLE_SPEED)))
194-
)
195-
)
196-
// added end
197-
{
198-
// For the next cycle prime the fraction of a minute accumulators
199-
fcSlotData.frac_minsl = FC_FRAC_RESET_LOW;
200-
201-
// If we are in FC_FLAG_DCS100_COMPATIBLE_SPEED mode we need to run faster
202-
// by reducong the FRAC_MINS duration count by 128
203-
fcSlotData.frac_minsh = FC_FRAC_RESET_HIGH + (fcFlags & FC_FLAG_DCS100_COMPATIBLE_SPEED);
204-
205-
fcSlotData.mins_60++;
206-
if (fcSlotData.mins_60 >= 0x7F)
207-
{
208-
fcSlotData.mins_60 = 127 - 60;
209-
210-
fcSlotData.hours_24++;
211-
if (fcSlotData.hours_24 & 0x80)
212-
{
213-
fcSlotData.hours_24 = 128 - 24;
214-
215-
fcSlotData.days++;
216-
}
217-
}
218-
219-
// We either send a message out onto the LocoNet to change the time,
220-
// which we will also see and act on or just notify our user
221-
// function that our internal time has changed.
222-
if (fcFlags & FC_FLAG_MINUTE_ROLLOVER_SYNC)
223-
{
224-
fcSlotData.command = OPC_WR_SL_DATA;
225-
LocoNet.send((lnMsg*)&fcSlotData);
226-
}
227-
else
228-
doNotify(0);
229-
}
230-
}
231-
232-
if (notifyFastClockFracMins && (fcFlags & FC_FLAG_NOTIFY_FRAC_MINS_TICK))
233-
notifyFastClockFracMins(FC_FRAC_MIN_BASE - ((fcSlotData.frac_minsh << 7) + fcSlotData.frac_minsl));
234-
}
235-
236-
if (fcState == FC_ST_IDLE)
237-
{
238-
LocoNet.send(OPC_RQ_SL_DATA, FC_SLOT, 0);
239-
fcState = FC_ST_REQ_TIME;
240-
}
241-
}
242-
//=== end LocoNetFastClockClassKS ===

LocoNetKS.h

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
22
||
33
|| @file LocoNetKS.h
4-
|| @version 1.0
4+
|| @version 1.1
55
|| @author Michael Zimmermann
66
|| @contact michael.zimmermann.sg@t-online.de
77
||
88
|| @description
9-
|| | additional functions for 'LocoNetClass' and 'LocoNetFastClockClass' from Loconet-Library, published by MRRwA (previously EmbeddedLocoNet)
9+
|| | additional functions for 'LocoNetClass' from Loconet-Library, published by MRRwA (previously EmbeddedLocoNet)
1010
|| #
1111
||
1212
|| @license
@@ -53,26 +53,4 @@ class LocoNetClassKS {
5353

5454
extern LocoNetClassKS LocoNetKS;
5555

56-
class LocoNetFastClockClassKS
57-
{
58-
private:
59-
FC_STATE fcState; // State of the Fast Clock Slave
60-
uint8_t fcFlags; // Storage of the option flags passed into initFastClock()
61-
fastClockMsg fcSlotData; // Primary storage for the Fast Clock slot data
62-
uint8_t fcLastPeriod; // Period of last tick so we can alternate between
63-
uint8_t fcLastfrac_minsh; // new
64-
65-
void doNotify(uint8_t Sync);
66-
67-
public:
68-
void init(uint8_t DCS100CompatibleSpeed, uint8_t CorrectDCS100Clock, uint8_t NotifyFracMin);
69-
void initJMRI(uint8_t IsJMRI); // new
70-
void poll(void);
71-
void processMessage(lnMsg* LnPacket); // modified
72-
void process66msActions(void); // modified
73-
74-
FC_STATE getFastClockState() { return fcState; } // new, used in debug-cases
75-
fastClockMsg getFastClockSlotData() { return fcSlotData; } // new, used in debug-cases
76-
};
77-
7856
#endif

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
This is a simple library with additional functions I missed in the original LocoNET-library for usage with Arduino-platform.<br>
44

5-
In addition, I copied the original LocoNetFastClockClass and modified it.<br>
6-
This was necessary because the original class doesnot work for me during the development of the [Nebenuhr](http://www.github.com/Kruemelbahn/Nebenuhr), a FastClock-Slave which should work with [JMRI](https://www.jmri.org/)<br>
7-
85
Necessary base-library can be found on https://github.com/mrrwa/LocoNet
96

107
Tested on ATmega328.

library.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
name=LocoNetKS
2-
version=1.0
2+
version=1.1
33
author=michael <Kruemelbahn2000@hotmail.de>
44
maintainer=michael <Kruemelbahn2000@hotmail.de>
55
sentence=additional functions for class LocoNet (see http://mrrwa.org/loconet-interface/)
66
paragraph=This library allows extends the interface to the LocoNet-Library
77
category=Communication
8-
url=https://github.com/Kruemelbahn/LocoNetKS
8+
url=http://www.kruemelsoft.privat.t-online.de
99
architectures=avr
1010
depends=LocoNet

0 commit comments

Comments
 (0)