DCCpp
This is the library version of a program for Arduino to control railroading DCC devices.
PacketRegister.h
1 /**********************************************************************
2 
3 PacketRegister.h
4 COPYRIGHT (c) 2013-2016 Gregg E. Berman
5 
6 Part of DCC++ BASE STATION for the Arduino
7 
8 **********************************************************************/
9 
10 #ifndef PacketRegister_h
11 #define PacketRegister_h
12 
13 #include "Arduino.h"
14 
15 // Define constants used for reading CVs from the Programming Track
16 
17 #define ACK_BASE_COUNT 100
18 #define ACK_SAMPLE_COUNT 500
19 #define ACK_SAMPLE_SMOOTHING 0.2
20 #define ACK_SAMPLE_THRESHOLD DCCpp::ackThreshold
22 struct Packet{
23  byte buf[10];
24  byte nBits;
25 }; // Packet
26 
27 struct Register{
28  Packet packet[2];
29  Packet *activePacket;
30  Packet *updatePacket;
31  void initPackets();
32 }; // Register
33 
36 struct RegisterList{
37  int maxNumRegs;
38  Register *reg;
39  Register **regMap;
40  Register *currentReg;
41  Register *maxLoadedReg;
42  Register *nextReg;
43  Packet *tempPacket;
44 
45 #ifdef USE_ONLY1_INTERRUPT
46  /* how many 58us periods needed for half-cycle (1 for "1", 2 for "0") */
47  byte timerPeriods;
48  /* how many 58us periods are left (at start, 2 for "1", 4 for "0"). */
49  byte timerPeriodsLeft;
50 #endif
51 
52  byte currentBit;
53  byte nRepeat;
54  int *speedTable;
55  static byte idlePacket[];
56  static byte resetPacket[];
57  static byte bitMask[];
58  RegisterList(int);
59  void loadPacket(int, byte *, int, int, int=0) volatile;
60 
61 #ifdef USE_TEXTCOMMAND
62  void setThrottle(const char *) volatile;
63  void setFunction(const char *) volatile;
64  void setAccessory(const char *) volatile;
65  void writeTextPacket(const char *) volatile;
66 #endif
67 
68  int readCVraw(int cv, int callBack, int callBackSub) volatile;
69  int buildBaseAcknowlegde(int inMonitorPin) volatile;
70  bool checkAcknowlegde(int inMonitorPin, int inBase) volatile;
71 
72 #ifdef USE_TEXTCOMMAND
73  int readCV(const char *) volatile;
74  bool writeCVByte(const char *) volatile;
75  bool writeCVBit(const char *) volatile;
76 
77  int readCVmain(const char *) volatile;
78  void writeCVByteMain(const char *) volatile;
79  void writeCVBitMain(const char *s) volatile;
80 #endif
81 
82  byte setAckThreshold(byte inNewValue);
83 
84  void setThrottle(int nReg, int cab, int tSpeed, int tDirection) volatile;
85  void setFunction(int nReg, int cab, int fByte, int eByte) volatile;
86  void setAccessory(int aAdd, int aNum, int activate) volatile;
87  void writeTextPacket(int nReg, byte *b, int nBytes) volatile;
88  int readCV(int cv, int callBack, int callBackSub) volatile;
89  int readCVmain(int cv, int callBack, int callBackSub) volatile;
90  bool writeCVByte(int cv, int bValue, int callBack, int callBackSub) volatile; // prog track
91  bool writeCVBit(int cv, int bNum, int bValue, int callBack, int callBackSub) volatile; // prog track
92  void writeCVByteMain(int cab, int cv, int bvalue) volatile;
93  void writeCVBitMain(int cab, int cv, int bNum, int bValue) volatile;
94 
95 #ifdef DCCPP_DEBUG_MODE
96  void printPacket(int, byte *, int, int) volatile;
97 #endif
98 };
99 
100 #endif