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 #ifdef ARDUINO_ARCH_AVR
15 
16 // Define constants used for reading CVs from the Programming Track
17 
18 #define ACK_BASE_COUNT 100
19 #define ACK_SAMPLE_COUNT 500
20 #define ACK_SAMPLE_SMOOTHING 0.2
21 #define ACK_SAMPLE_THRESHOLD DCCpp::ackThreshold
23 struct Packet{
24  byte buf[10];
25  byte nBits;
26 }; // Packet
27 
28 struct Register{
29  Packet packet[2];
30  Packet *activePacket;
31  Packet *updatePacket;
32  void initPackets();
33 }; // Register
34 
37 struct RegisterList{
38  int maxNumRegs;
39  Register *reg;
40  Register **regMap;
41  Register *currentReg;
42  Register *maxLoadedReg;
43  Register *nextReg;
44  Packet *tempPacket;
45  byte currentBit;
46  byte nRepeat;
47  int *speedTable;
48  static byte idlePacket[];
49  static byte resetPacket[];
50  static byte bitMask[];
51  RegisterList(int);
52  void loadPacket(int, byte *, int, int, int=0) volatile;
53 
54 #ifdef USE_TEXTCOMMAND
55  void setThrottle(char *) volatile;
56  void setFunction(char *) volatile;
57  void setAccessory(char *) volatile;
58  void writeTextPacket(char *) volatile;
59 #endif
60 
61  int readCVraw(int cv, int callBack, int callBackSub) volatile;
62  int buildBaseAcknowlegde(int inMonitorPin) volatile;
63  int checkAcknowlegde(int inMonitorPin, int inBase) volatile;
64 
65 #ifdef USE_TEXTCOMMAND
66  int readCV(char *) volatile;
67  void writeCVByte(char *) volatile;
68  void writeCVBit(char *) volatile;
69 
70  int readCVmain(char *) volatile;
71  void writeCVByteMain(char *) volatile;
72  void writeCVBitMain(char *s) volatile;
73 #endif
74 
75  byte setAckThreshold(byte inNewValue);
76 
77  void setThrottle(int nReg, int cab, int tSpeed, int tDirection) volatile;
78  void setFunction(int nReg, int cab, int fByte, int eByte) volatile;
79  void setAccessory(int aAdd, int aNum, int activate) volatile;
80  void writeTextPacket(int nReg, byte *b, int nBytes) volatile;
81  int readCV(int cv, int callBack, int callBackSub) volatile;
82  int readCVmain(int cv, int callBack, int callBackSub) volatile;
83  void writeCVByte(int cv, int bValue, int callBack, int callBackSub) volatile; // prog track
84  void writeCVBit(int cv, int bNum, int bValue, int callBack, int callBackSub) volatile; // prog track
85  void writeCVByteMain(int cab, int cv, int bvalue) volatile;
86  void writeCVBitMain(int cab, int cv, int bNum, int bValue) volatile;
87 
88 #ifdef DCCPP_DEBUG_MODE
89  void printPacket(int, byte *, int, int) volatile;
90 #endif
91 };
92 
93 #endif
94 #endif