-
Notifications
You must be signed in to change notification settings - Fork 0
/
XpressNetMaster.cpp
1264 lines (1177 loc) · 43.6 KB
/
XpressNetMaster.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
*****************************************************************************
* XpressNetMaster.h - library for XpressNet protocoll
* Copyright (c) 08/2016 - 2020 Philipp Gahtow All right reserved.
*
*****************************************************************************
* FUNKTIONS:
*
* Build a XpressNet Master for driving and switch
* Support for Roco LokMaus2 and Multimaus
* Basic support for direct CV programming (read and write)
* Check XOR before packet dekoding
*
* -> Please contact Lenz Inc. for more details about XpressNet.
*
* not yet Supported:
* - Emergency stop a locomotive: 0x92 AddrH AddrL [XOR]
* - Emergency stop a locomotive: 0x91 loco_addr [XOR] (v2)
* - Service Mode: only direct Mode
* - DCC extended accessory command: 0x13 0x01 B+AddrH AddrL
* - DCC FAST CLOCK: 0x01 0xF2 0xF3
* - Command Tunnel: 0x3* ** ** [XOR]
* - BiDi messages: 0x7* ** ** [XOR]
* - Library Entry: 0xE9 0xF1 AddrH AddrL IDX SIZE [NAME][XOR]
* - Set function state: 0xE4 0x2* AddrH AddrL Group [XOR]
*****************************************************************************
*/
// include this library's description file
#include "XpressNetMaster.h"
#if defined(__AVR__)
#include <avr/interrupt.h>
XpressNetMasterClass *XpressNetMasterClass::active_object = 0; //Static
#endif
// Constructor /////////////////////////////////////////////////////////////////
// Function that handles the creation and setup of instances
XpressNetMasterClass::XpressNetMasterClass()
{
// initialize this instance's variables
XNetAdr = 0; //Startaddresse des ersten XNet Device
XNetSlaveMode = 0x00; //Start in MASTER MODE
XNetSlaveInit = true; //if change to Slave Mode make initialize
Railpower = csTrackVoltageOff;
Fahrstufe = Loco128;
XNetBufferSend = 0; //start position to read data from the buffer
XNetBufferSend_data = 0; //position of byte that we are sending
XNetBufferStore = 0; //start position to store data in buffer
for (byte s = 0; s < 32; s++) { //clear busy slots
SlotLokUse[s] = 0xFFFF; //slot is inactiv
}
for (byte b = 0; b < XNetBufferSize; b++) { //clear send buffer
XNetBuffer[b].length = 0x00;
for (byte d = 0; d < XNetBufferMaxData; d++) {
XNetBuffer[b].data[d] = 0x00;
}
}
XNetDataReady = false; //keine Daten empfangen!
XNet_state = XNet_get_callbyte; //set the start state
XNetclear(); //alte Nachricht löschen
XNetMsgBuffer[XNetBufferlength] = 0x00; //reset buffer
XNetCVAdr = 0; //no CV read
XNetCVvalue = 0; //no CV value
}
//******************************************Serial*******************************************
void XpressNetMasterClass::setup(uint8_t FStufen, uint8_t XControl) //Initialisierung Serial
{
Fahrstufe = FStufen;
MAX485_CONTROL = XControl;
#if defined(__AVR__) //Configuration for 8-Bit MCU
// LISTEN_MODE
pinMode(MAX485_CONTROL, OUTPUT);
digitalWrite (MAX485_CONTROL, LOW); //RECEIVE_MODE - SLAVE
//Set up on 62500 Baud
cli(); //disable interrupts while initializing the USART
#if defined(__AVR_ATmega328p__)
UBRRH = 0;
UBRRL = 0x0F;
UCSRA = 0;
UCSRB = (1<<RXEN) | (1<<TXEN) | (1<<RXCIE) | (1<<TXCIE) | (1<<UCSZ2);
UCSRC = (1<<UCSZ1) | (1<<UCSZ0);
#elif defined(SERIAL_PORT_0)
UBRR0H = 0;
UBRR0L = 0x0F;
UCSR0A = 0;
UCSR0B = (1<<RXEN0) | (1<<TXEN0) | (1<<RXCIE0) | (1<<TXCIE0)| (1<<UCSZ02);
UCSR0C = (1<<UCSZ01) | (1<<UCSZ00);
#else
UBRR1H = 0;
UBRR1L = 0x0F;
UCSR1A = 0;
UCSR1B = (1<<RXEN1) | (1<<TXEN1) | (1<<RXCIE1) | (1<<TXCIE1) | (1<<UCSZ12);
UCSR1C = (1<<UCSZ11) | (1<<UCSZ10);
#endif
sei(); // Enable the Global Interrupt Enable flag so that interrupts can be processed
/*
* Enable reception (RXEN = 1).
* Enable transmission (TXEN0 = 1).
* Enable Receive Interrupt (RXCIE = 1).
* Enable Transmit Interrupt (TXCIE = 1).
* Set 9-bit character mode (UCSZ00, UCSZ01, and UCSZ02 together control this,
* But UCSZ00, UCSZ01 are in Register UCSR0C).
*/
active_object = this; //hold Object to call it back in ISR
#else
#define RAW_DATA_MODE
#endif
}
// Public Methods //////////////////////////////////////////////////////////////
// Functions available in Wiring sketches, this library, and other libraries
//*******************************************************************************************
//Daten Auswerten
void XpressNetMasterClass::update(void)
{
//XpressNet State Machine:
switch (XNet_state) {
case XNet_send_callbyte:
//wait until data sending is ready.
break;
case XNet_wait_receive: //wait for client answer, max 120 microsekunden
if (micros() - XSendCount >= XNetTimeUntilNext) { //Timeout?
XNet_state = XNet_get_callbyte;
}
if (XNetMsgBuffer[XNetBufferlength] != 0x00) {
#if defined (XNetDEBUGTime)
XNetSerial.print("Reply after: ");
XNetSerial.println(micros() - XSendCount);
#endif
XNet_state = XNet_receive_data;
XSendCount = micros(); //save time for receive the first byte
}
break;
case XNet_receive_data: //read client data, max 500ms
if (micros() - XSendCount >= XNetTimeReadData) { //Timeout?
XNet_state = XNet_get_callbyte;
XNetclear(); //alte Nachricht löschen
XNetMsgBuffer[XNetBufferlength] = 0x00; //reset buffer
break;
}
if (!XNetDataReady)
break;
#if defined (XNetDEBUGTime)
XNetSerial.print("Paket time: ");
XNetSerial.println(micros() - XSendCount);
#endif
XNetDataReady = false;
if (XNetCheckXOR()) { //Checks the XOR
XNetAnalyseReceived(); //Auswerten der empfangenen Daten
#if defined(RAW_DATA_OUT)
if (RAW_out)
RAW_out(XNetMsg, (XNetMsg[XNetheader] & 0x0F) + 2); //send RAW data
#endif
}
XNetclear(); //alte Nachricht löschen
if (XNetSlaveMode == 0x00) { //MASTER MODE
XNet_state = XNet_send_data;
XNetSendNext(); //start sending out by interrupt
}
else XNet_state = XNet_get_callbyte;
break;
case XNet_send_data:
break;
case XNet_get_callbyte: //address the next client
if (XNetSlaveMode == 0x00) { //MASTER MODE
//we are not sending out more Data, get next CallByte
XNet_state = XNet_send_callbyte;
getNextXNetAdr(); //Send next CallByte
XNetSendNext(); //start sending out by interrupt
}
else {
//count cycles that we run in SLAVE MODE
XNetSlaveMode--; //stay only in SLAVE MODE if we receive CallBytes
XNet_state = XNet_receive_data;
//we need to initialize the SLAVE MODE?
if (XNetSlaveInit) {
XNetSlaveInit = false;
uint8_t Init[] = { 0x00, 0x21, 0x24, 0x05 };
XNetsend(Init, 4); //send initsequence
#if defined (XNetDEBUG)
XNetSerial.print("Slave INIT: ");
XNetSerial.println(XNetSlaveMode);
#endif
}
if (XNetSlaveMode == 0x00) { //we will leave the Slave-Mode?
XNetSlaveInit = true;
XNetMsgBuffer[XNetBufferlength] = 0x00; //clear!
}
}
XSendCount = micros(); //save time for callbyte send!
break;
}
}
//--------------------------------------------------------------------------------------------
//Checks the XOR
bool XpressNetMasterClass::XNetCheckXOR(void) {
byte rxXOR = 0x00; //store the read in XOR
for (byte i = 0; i < ((XNetMsg[XNetheader] & 0x0F) + 2); i++) {
rxXOR = rxXOR ^ XNetMsg[i];
}
if (rxXOR == 0x00) { //XOR is 0x00?
return true;
}
//Übertragungsfehler:
if (XNetSlaveMode == 0x00) { //MASTER MODE
uint8_t ERR[] = {DirectedOps, 0x61, 0x80, 0xE1 };
XNetsend(ERR, 4);
}
return false;
}
//--------------------------------------------------------------------------------------------
//RAW Daten zur Dekodierung einbringen:
#if defined(RAW_DATA_MODE)
void XpressNetMasterClass::RAW_input(byte *dataString, byte byteCount)
{
XNetMsgCallByte = 0x00; //no Call Byte nessesary!
//setzten des Modus:
XNetSlaveMode = 0; //Master-Mode
//kopieren der Nachricht
for (byte i = 0; i < byteCount; i ++) {
XNetMsg[i] = dataString[i];
}
XNetAnalyseReceived;
}
#endif
//--------------------------------------------------------------------------------------------
#if defined(RAW_DATA_IN)
void XpressNetMasterClass::RAW_in(byte *dataString, byte lenCount)
{
getXOR(dataString, lenCount);
XNetsend(dataString, lenCount);
}
#endif
//--------------------------------------------------------------------------------------------
//Daten Auswerten
void XpressNetMasterClass::XNetAnalyseReceived(void) { //work on received data
#if defined (XNetDEBUG)
if (XNetSlaveMode == 0x00) {
XNetSerial.print("MRX: 0x1");
XNetSerial.print(CallByteInquiry, HEX); //MASTER MODE - CallByte 8 Bit only
}
else {
XNetSerial.print("SRX: 0x1");
XNetSerial.print(XNetMsgCallByte, HEX); //SLAVE MODE - CallByte 8 Bit only
}
for (byte i = 0; i < ((XNetMsg[XNetheader] & 0x0F) + 2); i++) {
if (XNetMsg[i] < 0x10)
XNetSerial.print(" 0x0");
else XNetSerial.print(" 0x");
XNetSerial.print(XNetMsg[i], HEX);
}
XNetSerial.println();
#endif
switch (XNetMsg[XNetheader]) {
case 0x21:
if (XNetSlaveMode == 0x00) {
if (XNetMsg[XNetdata1] == 0x24 && XNetMsg[XNetdata2] == 0x05) { //Command station status indication response
/*
Bit 0: =1 - Command station is in emergency off (Nothalt)
Bit 1: =1 - Command station is in emergency stop (Notaus)
Bit 2: Command station-Start mode (0 = manual mode, 1 = automatic mode)
Automatic Mode: All locomotives start at their last known speed each
time the command station is powered up
Manual Mode: All locomotives have a speed of 0 and functions out on
command station power up
Bit 3: = 1 - The command station is in service mode
Bit 4: reserved
Bit 5: reserved
Bit 6: = 1 - The command station is performing a power up.
Bit 7: = 1 - There was a RAM check error in the command station
*/
byte status = 0x01; //csTrackVoltageOff = B1;
switch (Railpower) {
case csNormal: status = 0; break;
case csEmergencyStop: status = 0x01; break;
case csServiceMode: status = 0x08; break;
case csShortCircuit: status = 0x02; break;
}
#if !defined(RAW_DATA_MODE)
uint8_t sendStatus[] = { DirectedOps, 0x62, 0x22, status, 0x00 };
getXOR(sendStatus, 5);
XNetsend(sendStatus, 5);
#endif
}
#if !defined(RAW_DATA_MODE)
if (XNetMsg[XNetdata1] == 0x21 && XNetMsg[XNetdata2] == 0x00) { //Command station softwareversion response
uint8_t sendVersion[] = { DirectedOps, 0x63, 0x21, XNetVersion, XNetID, 0x00 }; //63-21 36 0 74
getXOR(sendVersion, 6);
XNetsend(sendVersion, 6);
}
#endif
if (XNetMsg[XNetdata1] == 0x80 && XNetMsg[XNetdata2] == 0xA1) { //Alles Aus (Notaus)
setPower(csTrackVoltageOff);
}
if (XNetMsg[XNetdata1] == 0x81 && XNetMsg[XNetdata2] == 0xA0) { //Alles An
setPower(csNormal);
}
#if !defined(RAW_DATA_MODE)
if (XNetMsg[XNetdata1] == 0x10 && XNetMsg[XNetdata2] == 0x31) { //Request for Service Mode results
if (XNetCVAdr != 0) {
uint8_t sendStatus[] = { DirectedOps, 0x63, 0x14, XNetCVAdr, XNetCVvalue, 0x00}; //Service Mode response for Direct CV mode
getXOR(sendStatus, 6);
XNetsend(sendStatus, 6);
XNetCVAdr = 0; //reset CV read Adr
XNetCVvalue = 0;//reset CV value
}
else {
// Programming info. "Command station busy"
uint8_t sendStatus[] = { DirectedOps, 0x61, 0x1F, 0x00 };
if (XNetCVvalue == 0xFF) { //"no ACK"
sendStatus[2] = 0x13; //Programming info. "Data byte not found"
XNetCVvalue = 0; //reset error!
}
// Programming info. "Command station ready "
//uint8_t sendStatus[] = { DirectedOps, 0x61, 0x11, 0x00 };
getXOR(sendStatus, 4);
XNetsend(sendStatus, 4);
}
}
#endif
if (SlotLokUse[DirectedOps & 0x1F] == 0xFFFF)
SlotLokUse[DirectedOps & 0x1F] = 0; //mark Slot as activ
//XNetclear(); //alte Nachricht löschen
}
break;
case 0x22: //Start Programming
if (XNetMsg[XNetdata1] == 0x11) { //Register Mode read request (Register Mode)
}
if (XNetMsg[XNetdata1] == 0x14) { //Paged Mode read request (Paged Mode)
}
if (XNetMsg[XNetdata1] == 0x15) { //Direct Mode CV read request (CV mode)
XNetCVAdr = 0; //no CV read
XNetCVvalue = 0; //no CV value
if (notifyXNetDirectReadCV)
notifyXNetDirectReadCV(XNetMsg[XNetdata2]-1); //try to read the CV 1..255
break;
}
unknown(); //unbekannte Anfrage
//XNetclear(); //alte Nachricht löschen
break;
case 0x23:
if (XNetMsg[XNetdata1] == 0x12) { //Register Mode write request (Register Mode)
}
if (XNetMsg[XNetdata1] == 0x16) { //Direct Mode CV write request (CV mode)
XNetCVAdr = 0; //no CV read
XNetCVvalue = 0; //no CV value
if (notifyXNetDirectCV)
notifyXNetDirectCV(XNetMsg[XNetdata2]-1, XNetMsg[XNetdata3]);
break;
}
if (XNetMsg[XNetdata1] == 0x17) { //0x23 0x17 CV DAT[XOR] - Paged Mode write request(Paged mode)
}
#if !defined(RAW_DATA_MODE)
unknown(); //unbekannte Anfrage
//XNetclear();
#endif
break;
case 0xE6: { //POM CV write MultiMaus
if (XNetMsg[XNetdata1] == 0x30) {
uint16_t Adr = ((XNetMsg[XNetdata2] & 0x3F) << 8) + XNetMsg[XNetdata3];
uint16_t CVAdr = ((XNetMsg[XNetdata4] & B11) << 8) + XNetMsg[XNetdata5];
if ((XNetMsg[XNetdata4] & 0xFC) == 0xEC) { //set byte
if (notifyXNetPOMwriteByte)
notifyXNetPOMwriteByte (Adr, CVAdr, XNetMsg[XNetdata6]);
}
if ((XNetMsg[XNetdata4] & 0xFC) == 0xE8) { //set bit
if (notifyXNetPOMwriteBit)
notifyXNetPOMwriteBit (Adr, CVAdr, (XNetMsg[XNetdata6] & 0x0F));
}
}
break; }
case 0x80:
if (XNetMsg[XNetdata1] == 0x80) { //EmStop
setPower(csEmergencyStop);
break;
}
unknown(); //unbekannte Anfrage
//XNetclear(); //alte Nachricht löschen
break;
case 0xE3: {
if (XNetSlaveMode == 0x00) {
switch (XNetMsg[XNetdata1]) {
case 0x00: //Lokdaten anfordern & F0 bis F12 anfordern
if (notifyXNetgiveLocoInfo)
notifyXNetgiveLocoInfo(DirectedOps, word(XNetMsg[XNetdata2] & 0x3F, XNetMsg[XNetdata3]));
break;
case 0x07: { //Funktionsstatus F0 bis F12 anfordern (Funktion ist tastend oder nicht tastend)
//0x07, sonst ist LokMaus2 langsam!
uint8_t LocoFkt[] = { DirectedOps, 0xE3, 0x50, 0x00, 0x00, 0x00 };
getXOR(LocoFkt, 6);
XNetsend(LocoFkt, 6);
break;
}
case 0x08: { //Funktionsstatus F13 bis F28 anfordern (Funktion ist tastend oder nicht tastend)
uint8_t LocoFkt[] = { DirectedOps, 0xE3, 0x51, 0x00, 0x00, 0x00 };
getXOR(LocoFkt, 6);
XNetsend(LocoFkt, 6);
break;
}
case 0x09: //Funktionszustand F13 bis F28 anfordern
if (notifyXNetgiveLocoFunc)
notifyXNetgiveLocoFunc(DirectedOps, word(XNetMsg[XNetdata2] & 0x3F, XNetMsg[XNetdata3]));
break;
case 0xF0: //Lok und Funktionszustand MultiMaus anfordern
if (notifyXNetgiveLocoMM)
notifyXNetgiveLocoMM(DirectedOps, word(XNetMsg[XNetdata2] & 0x3F, XNetMsg[XNetdata3]));
break;
default: unknown(); //unbekannte Anfrage
}
}
//XNetclear(); //alte Nachricht löschen
break;
}
case 0xE4: { //Fahrbefehle
AddBusySlot(DirectedOps, word(XNetMsg[XNetdata2] & 0x3F, XNetMsg[XNetdata3])); //set Busy
if (XNetMsg[XNetdata1] == 0x10) { //14 Fahrstufen
if (notifyXNetLocoDrive14)
notifyXNetLocoDrive14(word(XNetMsg[XNetdata2] & 0x3F, XNetMsg[XNetdata3]), XNetMsg[XNetdata4]);
}
else if (XNetMsg[XNetdata1] == 0x11) { //27 Fahrstufen
if (notifyXNetLocoDrive27)
notifyXNetLocoDrive27(word(XNetMsg[XNetdata2] & 0x3F, XNetMsg[XNetdata3]), XNetMsg[XNetdata4]);
}
else if (XNetMsg[XNetdata1] == 0x12) { //28 Fahrstufen
if (notifyXNetLocoDrive28)
notifyXNetLocoDrive28(word(XNetMsg[XNetdata2] & 0x3F, XNetMsg[XNetdata3]), XNetMsg[XNetdata4]);
}
else if (XNetMsg[XNetdata1] == 0x13) { //128 Fahrstufen
if (notifyXNetLocoDrive128)
notifyXNetLocoDrive128(word(XNetMsg[XNetdata2] & 0x3F, XNetMsg[XNetdata3]), XNetMsg[XNetdata4]);
}
else if (XNetMsg[XNetdata1] == 0x20) { //Funktionsbefehl Gruppe1 0 0 0 F0 F4 F3 F2 F1
if (notifyXNetLocoFunc1)
notifyXNetLocoFunc1(word(XNetMsg[XNetdata2] & 0x3F, XNetMsg[XNetdata3]), XNetMsg[XNetdata4]);
}
else if (XNetMsg[XNetdata1] == 0x21) { //Funktionsbefehl Gruppe2 0000 F8 F7 F6 F5
if (notifyXNetLocoFunc2)
notifyXNetLocoFunc2(word(XNetMsg[XNetdata2] & 0x3F, XNetMsg[XNetdata3]), XNetMsg[XNetdata4]);
}
else if (XNetMsg[XNetdata1] == 0x22) { //Funktionsbefehl Gruppe3 0000 F12 F11 F10 F9
if (notifyXNetLocoFunc3)
notifyXNetLocoFunc3(word(XNetMsg[XNetdata2] & 0x3F, XNetMsg[XNetdata3]), XNetMsg[XNetdata4]);
}
else if (XNetMsg[XNetdata1] == 0x23 || XNetMsg[XNetdata1] == 0xF3) { //Funktionsbefehl Gruppe4 F20-F13
//0xF3 = undocumented command is used when a mulitMAUS is controlling functions f20..f13.
if (notifyXNetLocoFunc4)
notifyXNetLocoFunc4(word(XNetMsg[XNetdata2] & 0x3F, XNetMsg[XNetdata3]), XNetMsg[XNetdata4]);
}
else if (XNetMsg[XNetdata1] == 0x28) { //Funktionsbefehl Gruppe5 F28-F21
if (notifyXNetLocoFunc5)
notifyXNetLocoFunc5(word(XNetMsg[XNetdata2] & 0x3F, XNetMsg[XNetdata3]), XNetMsg[XNetdata4]);
}
else unknown(); //unbekannte Anfrage
break;
}
case 0x42: //Accessory Decoder information request
if (notifyXNetTrntInfo && XNetSlaveMode == 0x00)
notifyXNetTrntInfo(DirectedOps, XNetMsg[XNetdata1], XNetMsg[XNetdata2]);
//XNetclear(); //alte Nachricht löschen
break;
case 0x52: //Accessory Decoder operation request
if (notifyXNetTrnt)
notifyXNetTrnt((XNetMsg[XNetdata1] << 2) | ((XNetMsg[XNetdata2] & B110) >> 1), XNetMsg[XNetdata2]);
//XNetMsg[XNetdata2] = 0000 ABBP
//A = Weichenausgang(Spulenspannung EIN/AUS)
//BB = Adresse des Dekoderport 1..4
//P = Ausgang (Gerade = 0 / Abzweigen = 1)
//XNetclear(); //alte Nachricht löschen
break;
default: //Befehl in Zentrale nicht vorhanden
unknown(); //unbekannte Anfrage
}
if (XNetSlaveMode != 0x00) { //SLAVE-MODE
if (XNetMsgCallByte == GENERAL_BROADCAST) { //Central Station broadcast data
if (XNetMsg[XNetheader] == 0x61) {
if ((XNetMsg[XNetdata1] == 0x01) && (XNetMsg[XNetdata2] == 0x60)) {
// Normal Operation Resumed
Railpower = csNormal;
if (notifyXNetPower)
notifyXNetPower(Railpower);
}
else if ((XNetMsg[XNetdata1] == 0x00) && (XNetMsg[XNetdata2] == 0x61)) {
// Track power off
Railpower = csTrackVoltageOff;
if (notifyXNetPower)
notifyXNetPower(Railpower);
}
else if ((XNetMsg[XNetdata1] == 0x08)) {
// Track Short
Railpower = csShortCircuit;
if (notifyXNetPower)
notifyXNetPower(Railpower);
}
else if ((XNetMsg[XNetdata1] == 0x02) && (XNetMsg[XNetdata2] == 0x63)) {
// Service Mode Entry
Railpower = csServiceMode;
if (notifyXNetPower)
notifyXNetPower(Railpower);
}
}
else if (XNetMsg[XNetheader] == 0x81) {
if ((XNetMsg[XNetdata1] == 0x00) && (XNetMsg[XNetdata2] == 0x81)) {
//Emergency Stop
Railpower = csEmergencyStop;
if (notifyXNetPower)
notifyXNetPower(Railpower);
}
}
else if ((XNetMsg[XNetheader] & 0xF0) == 0x40) {
//Rückmeldung Schaltinformation
byte len = (XNetMsg[XNetheader] & 0x0F) / 2; //each Adr and Data
for (byte i = 1; i <= len; i++) {
notifyXNetFeedback((XNetMsg[XNetheader+(i*2)-1] << 2) | ((XNetMsg[XNetheader+(i*2)] & B110) >> 1), XNetMsg[XNetheader+(i*2)]);
//XNetMsg[XNetdata2] = 0000 ABBP
//A = Weichenausgang(Spulenspannung EIN/AUS)
//BB = Adresse des Dekoderport 1..4
//P = Ausgang (Gerade = 0 / Abzweigen = 1)
}
}
else if (XNetMsg[XNetheader] == 0x05 && XNetMsg[XNetdata1] == 0xF1) {
//DCC FAST CLOCK set request
/* 0x05 0xF1 TCODE1 TCODE2 TCODE3 TCODE4 [XOR]
00mmmmmm TCODE1, mmmmmm = denotes minutes, range 0...59.
100HHHHH TCODE2, HHHHH = denotes hours, range 0...23.
01000www TCODE3, www = denotes day of week, 0=monday, 1=tuesday, a.s.o.
110fffff TCODE4, fffff = denotes speed ratio, range 0..31. (0=stopped)
*/
}
} //Broadcast END
else if (XNetMsgCallByte == ACK_REQ) { //Central Station ask client for ACK?
uint8_t AckSeq[] = {0x00, 0x20, 0x20};
XNetsend (AckSeq, 3);
} //ACK END
else /* if (XNetMsgCallByte == MY_ADDRESS*) */ { //Central Station send data to us?
switch (XNetMsg[XNetheader]) {
case 0x52: // Some other device asked for an accessory change
break;
case 0x61: //Zustand
break;
case 0x62: //Version
if (XNetMsg[XNetdata1] == 0x22) {
switch (XNetMsg[XNetdata2]) {
case 0x00: //csNormal
Railpower = csNormal;
if (notifyXNetPower)
notifyXNetPower(Railpower);
break;
case 0x02: //csTrackVoltageOff
Railpower = csTrackVoltageOff;
if (notifyXNetPower)
notifyXNetPower(Railpower);
break;
case 0x01: //csEmergencyStop
Railpower = csEmergencyStop;
if (notifyXNetPower)
notifyXNetPower(Railpower);
break;
case 0x08: //csServiceMode
Railpower = csServiceMode;
if (notifyXNetPower)
notifyXNetPower(Railpower);
break;
}
uint8_t commandVersionSequence[] = { 0x00, 0x21, 0x21, 0x00};
XNetsend (commandVersionSequence, 4);
}
break;
case 0x63:
break;
case 0xE3: //Antwort abgefrage Funktionen F13-F28
break;
case 0xE4: //Antwort der abgefragen Lok
break;
case 0x42: //Antwort Schaltinformation
break;
case 0xE1: //Err Lok control
break;
} //switch HEADER END
} //MY_ADDRESS END
} //ENDE SLAVE MODE
}
//--------------------------------------------------------------------------------------------
//Befehl in Zentrale nicht vorhanden
void XpressNetMasterClass::unknown(void) //unbekannte Anfrage
{
if (XNetSlaveMode == 0x00) { //MASTER MODE
uint8_t NotIn[] = {DirectedOps, 0x61, 0x82, 0xE3 };
XNetsend(NotIn, 4);
}
}
//--------------------------------------------------------------------------------------------
void XpressNetMasterClass::getNextXNetAdr(void)
{
XNetAdr++; //nächste Adresse im XNet
if (XNetAdr > 31) { //wenn letzte erreicht von Beginn!
//search for used slots to call them more then unused:
while((SlotLokUse[XNetAdr % 32] == 0xFFFF) && (XNetAdr > 31)) { //slot used an loco address?
XNetAdr++;
}
if ((XNetAdr % 32) == 0)
XNetAdr = 1; //start at the beginning
}
/*
AAAAA = XNetAdr % 32 (Slot 1 to 31)
Call Byte Definitions:
Call_Response P11A AAAA
Call_Inquiry P10A AAAA
Call_Request_Ack_From_Device P00A AAAA
Call_Broadcast P110 0000
Call_Transfer_Err P11A AAAA
*/
//Generate byte for the new window:
CallByteInquiry = callByteParity((XNetAdr % 32) | 0x40); // | 0x100; // the address for Call Byte Window
RequestAck = callByteParity((XNetAdr % 32)| 0x00); // | 0x100; // the address for a request acknowlegement sent
DirectedOps = callByteParity((XNetAdr % 32)| 0x60); // | 0x100; // the address when we are sending ops
//Send CallByteInquiry for next Addr:
uint8_t NormalInquiry[] = { CallByteInquiry };
XNetsend(NormalInquiry, 1);
}
//--------------------------------------------------------------------------------------------
//Zustand der Gleisversorgung setzten
void XpressNetMasterClass::setPower(byte Power)
{
switch (Power) {
case csNormal: {
if (XNetSlaveMode == 0x00) { //MASTER MODE
uint8_t NormalPower[] = { GENERAL_BROADCAST, 0x61, 0x01, 0x60 };
XNetsend(NormalPower, 4);
}
else {
uint8_t PowerAn[] = {0x00, 0x21, 0x81, 0xA0 };
XNetsend(PowerAn, 4);
}
break;
}
case csEmergencyStop: {
if (XNetSlaveMode == 0x00) { //MASTER MODE
uint8_t EStopPower[] = { GENERAL_BROADCAST, 0x81, 0x00, 0x81 };
XNetsend(EStopPower, 4);
}
else {
uint8_t EmStop[] = {0x00, 0x80, 0x80 };
XNetsend(EmStop, 3);
}
break;
}
case csTrackVoltageOff: {
if (XNetSlaveMode == 0x00) { //MASTER MODE
uint8_t OffPower[] = { GENERAL_BROADCAST, 0x61, 0x00, 0x61 };
XNetsend(OffPower, 4);
}
else {
uint8_t PowerAus[] = {0x00, 0x21, 0x80, 0xA1 };
XNetsend(PowerAus, 4);
}
break;
}
case csShortCircuit: {
uint8_t ShortPower[] = { GENERAL_BROADCAST, 0x61, 0x08, 0x69 };
XNetsend(ShortPower, 4);
break;
}
case csServiceMode: {
uint8_t ServicePower[] = { GENERAL_BROADCAST, 0x61, 0x02, 0x63 };
XNetsend(ServicePower, 4);
break;
}
}
if (Railpower != Power) {
Railpower = Power; //Save new Power State
if (notifyXNetPower)
notifyXNetPower(Railpower);
}
}
//--------------------------------------------------------------------------------------------
//Rückmeldung verteilen
void XpressNetMasterClass::setBCFeedback(byte data1, byte data2)
{
uint8_t Feedback[] = { GENERAL_BROADCAST, 0x42, data1, data2, 0x00};
XNetsend(Feedback, 5);
}
//--------------------------------------------------------------------------------------------
//Lok in use (Request/Vormerken)
void XpressNetMasterClass::ReqLocoBusy(uint16_t Adr) {
//SetLocoBusyAdr = Adr;
//BusyAdrCount = 0;
//AddBusySlot(0, Adr);
for (byte s = 1; s < 32; s++) {
if (SlotLokUse[s] == Adr) { //if in use from X-Net device -> set busy
SetLocoBusy(callByteParity(s | 0x60), SlotLokUse[s]);
SlotLokUse[s] = 0; //clean slot
}
}
SlotLokUse[0] = Adr;
}
//--------------------------------------------------------------------------------------------
//Lok in use (Busy)
void XpressNetMasterClass::SetLocoBusy(uint8_t UserOps, uint16_t Adr) {
uint8_t LocoInfo[] = { UserOps, 0xE3, 0x40, 0x00, 0x00, 0x00 };
if (Adr > 99) //Xpressnet long addresses (100 to 9999: AH/AL = 0xC064 to 0xE707)
LocoInfo[3] = (Adr >> 8) | 0xC0;
else LocoInfo[3] = Adr >> 8; //short addresses (0 to 99: AH = 0x0000 and AL = 0x0000 to 0x0063)
LocoInfo[4] = Adr & 0xFF;
getXOR(LocoInfo, 6);
XNetsend(LocoInfo, 6);
}
//--------------------------------------------------------------------------------------------
//Lokinfo an XNet Melden
void XpressNetMasterClass::SetLocoInfo(uint8_t UserOps, uint8_t Speed, uint8_t F0, uint8_t F1) {
SetLocoInfo(UserOps, Fahrstufe, Speed, F0, F1);
}
void XpressNetMasterClass::SetLocoInfo(uint8_t UserOps, uint8_t Steps, uint8_t Speed, uint8_t F0, uint8_t F1) {
//0xE4 | 0000 BFFF | RVVV VVVV | 000F FFFF | FFFF FFFF | XOr
// B = 0 free; B = 1 controlled by another Device
// FFF -> 000 = 14; 001 = 27; 010 = 28; 100 = 128
//LokInfo Identification Speed FA FB
byte v = Speed;
if (Steps == Loco28 || Steps == Loco27) {
v = (Speed & 0x0F) << 1; //Speed Bit
v |= (Speed >> 4) & 0x01; //Addition Speed Bit
v |= 0x80 & Speed; //Dir
}
uint8_t LocoInfo[] = {UserOps, 0xE4, Steps, v, F0, F1, 0x00 };
if (SlotLokUse[UserOps & 0x1F] == 0x00) //has Slot a Address?
LocoInfo[2] |= 0x08; //set BUSY
getXOR(LocoInfo, 7);
XNetsend(LocoInfo, 7);
}
//--------------------------------------------------------------------------------------------
//LokFkt an XNet Melden
void XpressNetMasterClass::SetFktStatus(uint8_t UserOps, uint8_t F4, uint8_t F5) {
//F4 = F20-F13
//F5 = F28-F21
uint8_t LocoFkt[] = {UserOps, 0xE3, 0x52, F4, F5, 0x00 };
getXOR(LocoFkt, 6);
XNetsend(LocoFkt, 6);
}
//--------------------------------------------------------------------------------------------
//Lokinfo for MultiMaus
void XpressNetMasterClass::SetLocoInfoMM(uint8_t UserOps, uint8_t Steps, uint8_t Speed, uint8_t F0, uint8_t F1, uint8_t F2, uint8_t F3) {
//E7 0x04=128 Steps||0x0C=128+Busy (Dir,Speed) (F0,F4,F3,F2,F1) F5-F12 F13-F20 0x00 0x00 CRC
byte v = Speed;
if (Steps == Loco28 || Steps == Loco27) {
v = (Speed & 0x0F) << 1; //Speed Bit
v |= (Speed >> 4) & 0x01; //Addition Speed Bit
v |= 0x80 & Speed; //Dir
}
uint8_t LocoInfo[] = {UserOps, 0xE7, /*0x04*/ Steps, v, 0x20, F1, F2, F3, 0x00, 0x00 };
/*ERROR: Steps change form > 99 to 28steps only!!! why?? (This info comes from DCC:"notifyLokAll(..)"*/
LocoInfo[4] |= F0;
getXOR(LocoInfo, 10);
XNetsend(LocoInfo, 10);
}
//--------------------------------------------------------------------------------------------
void XpressNetMasterClass::setSpeed(uint16_t Adr, uint8_t Steps, uint8_t Speed) {
//Locomotive speed and direction operation
// 0xE4 | Ident | AH | AL | RV | XOr
// Ident: 0x10 = F14; 0x11 = F27; 0x12 = F28; 0x13 = F128
// RV = RVVV VVVV Dirction and Speed
byte v = Speed;
if (Steps == Loco28 || Steps == Loco27) {
v = (Speed & 0x0F) << 1; //Speed Bit
v |= (Speed >> 4) & 0x01; //Addition Speed Bit
v |= 0x80 & Speed; //Dir
}
uint8_t LocoInfo[] = {0x00, 0xE4, 0x13, 0x00, 0x00, v, 0x00 }; //default to 128 Steps!
switch (Steps) {
case 14: LocoInfo[2] = 0x10; break;
case 27: LocoInfo[2] = 0x11; break;
case 28: LocoInfo[2] = 0x12; break;
}
if (Adr > 99) //Xpressnet long addresses (100 to 9999: AH/AL = 0xC064 to 0xE707)
LocoInfo[3] = (Adr >> 8) | 0xC0;
else LocoInfo[3] = Adr >> 8; //short addresses (0 to 99: AH = 0x0000 and AL = 0x0000 to 0x0063)
LocoInfo[4] = Adr & 0xFF;
getXOR(LocoInfo, 7);
XNetsend(LocoInfo, 7);
}
//--------------------------------------------------------------------------------------------
//Gruppe 1: 0 0 0 F0 F4 F3 F2 F1
void XpressNetMasterClass::setFunc0to4(uint16_t Adr, uint8_t G1) {
uint8_t LocoInfo[] = {0x00, 0xE4, 0x20, 0x00, 0x00, G1, 0x00 };
if (Adr > 99) //Xpressnet long addresses (100 to 9999: AH/AL = 0xC064 to 0xE707)
LocoInfo[3] = (Adr >> 8) | 0xC0;
else LocoInfo[3] = Adr >> 8; //short addresses (0 to 99: AH = 0x0000 and AL = 0x0000 to 0x0063)
LocoInfo[4] = Adr & 0xFF;
getXOR(LocoInfo, 7);
XNetsend(LocoInfo, 7);
}
//--------------------------------------------------------------------------------------------
//Gruppe 2: 0 0 0 0 F8 F7 F6 F5
void XpressNetMasterClass::setFunc5to8(uint16_t Adr, uint8_t G2) {
uint8_t LocoInfo[] = {0x00, 0xE4, 0x21, 0x00, 0x00, G2, 0x00 };
if (Adr > 99) //Xpressnet long addresses (100 to 9999: AH/AL = 0xC064 to 0xE707)
LocoInfo[3] = (Adr >> 8) | 0xC0;
else LocoInfo[3] = Adr >> 8; //short addresses (0 to 99: AH = 0x0000 and AL = 0x0000 to 0x0063)
LocoInfo[4] = Adr & 0xFF;
getXOR(LocoInfo, 7);
XNetsend(LocoInfo, 7);
}
//--------------------------------------------------------------------------------------------
//Gruppe 3: 0 0 0 0 F12 F11 F10 F9
void XpressNetMasterClass::setFunc9to12(uint16_t Adr, uint8_t G3) {
uint8_t LocoInfo[] = {0x00, 0xE4, 0x22, 0x00, 0x00, G3, 0x00 };
if (Adr > 99) //Xpressnet long addresses (100 to 9999: AH/AL = 0xC064 to 0xE707)
LocoInfo[3] = (Adr >> 8) | 0xC0;
else LocoInfo[3] = Adr >> 8; //short addresses (0 to 99: AH = 0x0000 and AL = 0x0000 to 0x0063)
LocoInfo[4] = Adr & 0xFF;
getXOR(LocoInfo, 7);
XNetsend(LocoInfo, 7);
}
//--------------------------------------------------------------------------------------------
//Gruppe 4: F20 F19 F18 F17 F16 F15 F14 F13
void XpressNetMasterClass::setFunc13to20(uint16_t Adr, uint8_t G4) {
uint8_t LocoInfoMM[] = {0x00, 0xE4, 0xF3, 0x00, 0x00, G4, 0x00 }; //normal: 0x23!
if (Adr > 99) //Xpressnet long addresses (100 to 9999: AH/AL = 0xC064 to 0xE707)
LocoInfoMM[3] = (Adr >> 8) | 0xC0;
else LocoInfoMM[3] = Adr >> 8; //short addresses (0 to 99: AH = 0x0000 and AL = 0x0000 to 0x0063)
LocoInfoMM[4] = Adr & 0xFF;
getXOR(LocoInfoMM, 7);
XNetsend(LocoInfoMM, 7);
LocoInfoMM[0] = 0x00;
LocoInfoMM[1] = 0xE4;
LocoInfoMM[2] = 0x23; //MultiMaus only
LocoInfoMM[3] = Adr >> 8;
LocoInfoMM[4] = Adr & 0xFF;
LocoInfoMM[5] = G4;
getXOR(LocoInfoMM, 7);
XNetsend(LocoInfoMM, 7);
}
//--------------------------------------------------------------------------------------------
//Gruppe 5: F28 F27 F26 F25 F24 F23 F22 F21
void XpressNetMasterClass::setFunc21to28(uint16_t Adr, uint8_t G5) {
uint8_t LocoInfo[] = {0x00, 0xE4, 0x28, 0x00, 0x00, G5, 0x00 };
if (Adr > 99) //Xpressnet long addresses (100 to 9999: AH/AL = 0xC064 to 0xE707)
LocoInfo[3] = (Adr >> 8) | 0xC0;
else LocoInfo[3] = Adr >> 8; //short addresses (0 to 99: AH = 0x0000 and AL = 0x0000 to 0x0063)
LocoInfo[4] = Adr & 0xFF;
getXOR(LocoInfo, 7);
XNetsend(LocoInfo, 7);
}
//--------------------------------------------------------------------------------------------
//check if there are slots with the same loco, set them to busy
void XpressNetMasterClass::SetBusy(uint8_t slot) {
for (byte s = 1; s < 32; s++) {
if ((s != slot) && (SlotLokUse[s] == SlotLokUse[slot])) { //if in other Slot -> set busy
SetLocoBusy(callByteParity(s | 0x60), SlotLokUse[s]);
SlotLokUse[s] = 0; //clean slot that informed as busy & let it activ
}
}
}
//--------------------------------------------------------------------------------------------
//Add loco to slot. Slot 0 is reserved for non XpressNet Device
void XpressNetMasterClass::AddBusySlot(uint8_t UserOps, uint16_t Adr) {
if (Adr == 0 || SlotLokUse[UserOps & 0x1F] == Adr) //skip if already in store!
return;
SlotLokUse[UserOps & 0x1F] = Adr; //store loco that is used
SetBusy(UserOps & 0x1F); //make other busy
}
//--------------------------------------------------------------------------------------------
//TrntPos request return
void XpressNetMasterClass::SetTrntStatus(uint8_t UserOps, uint8_t Address, uint8_t Data) {
if (XNetSlaveMode == 0x00) { //MASTER MODE
// data=ITTN ZZZZ Z=Weichenausgang1+2 (Aktive/Inaktive);
//0x42 AAAA AAAA ITTN ZZZZ
//I = is 1, the switching command requested has not been completed
//TT = turnout group (0-3)
//N = N=0 is the lower nibble, N=1 the upper nibble
//Z3 Z2 Z1 Z0 = (Z1,Z0|Z3,Z2) 01 "left", 10 "right"
uint8_t TrntInfo[] = {UserOps, 0x42, 0x00, 0x00, 0x00 };
TrntInfo[2] = Address;
TrntInfo[3] = Data;
getXOR(TrntInfo, 5);
XNetsend(TrntInfo, 5);
}
}
//--------------------------------------------------------------------------------------------
//Trnt Change position
void XpressNetMasterClass::SetTrntPos(uint16_t Address, uint8_t state, uint8_t active) {
//Accessory Decoder operation request (0x52 | AAAA AAAA | 1000 ABBP | XOr)
//1. Byte = AAAA AAAA -> (Adresse >> 2) - ohne Stupenauswahl
//2. Byte = 1000 ABBP
//A = Weichenausgang(Spulenspannung EIN/AUS)
//BB = Adresse des Dekoderport 1..4
//P = Ausgang (Gerade = 0 / Abzweigen = 1)
uint8_t TrntInfo[] = {0x00, 0x52, 0x00, 0x00, 0x00 };
TrntInfo[2] = Address >> 2;
TrntInfo[3] = 0x80;
TrntInfo[3] |= (Address & 0x03) << 1;
TrntInfo[3] |= (active & 0x01) << 3;
TrntInfo[3] |= state & 0x01;
getXOR(TrntInfo, 5);
XNetsend(TrntInfo, 5);
}
//--------------------------------------------------------------------------------------------
//return a CV data read
void XpressNetMasterClass::setCVReadValue(uint8_t cvAdr, uint8_t value) {
//Save?:
if (cvAdr != 0xFF) {
XNetCVAdr = cvAdr+1;
XNetCVvalue = value;
}
}
//--------------------------------------------------------------------------------------------
//no ACK
void XpressNetMasterClass::setCVNack(void) {
XNetCVAdr = 0;
XNetCVvalue = 0xFF;
}
//--------------------------------------------------------------------------------------------
// send along a bunch of bytes to the Command Station
void XpressNetMasterClass::XNetsend(byte *dataString, byte byteCount) {
#if defined(RAW_DATA_MODE)
if (RAW_output)
RAW_output(dataString, byteCount);
#else
#if defined (XNetDEBUG)
if (byteCount > 1) {
XNetSerial.print("XTX: ");
}
#endif
XNetBuffer[XNetBufferStore].length = byteCount;
for (byte i = 0; i < byteCount; i++) {
XNetBuffer[XNetBufferStore].data[i] = *dataString; //add data to Buffer
dataString++;
#if defined (XNetDEBUG)
if (byteCount > 1) {
if (XNetBuffer[XNetBufferStore].data[i] < 0x10)
XNetSerial.print(" 0x0");
else XNetSerial.print(" 0x");
if (i == 0 && XNetSlaveMode == 0x00) //MASTER-MODE
XNetSerial.print("1");
XNetSerial.print(XNetBuffer[XNetBufferStore].data[i], HEX);
}
#endif
}
XNetBufferStore++;
if (XNetBufferStore >= XNetBufferSize)
XNetBufferStore = 0;