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 30
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 
63 #ifdef USE_TEXTCOMMAND
64  int readCV(char *) volatile;
65  void writeCVByte(char *) volatile;
66  void writeCVBit(char *) volatile;
67 
68  int readCVmain(char *) volatile;
69  void writeCVByteMain(char *) volatile;
70  void writeCVBitMain(char *s) volatile;
71 #endif
72 
73  void setThrottle(int nReg, int cab, int tSpeed, int tDirection) volatile;
74  void setFunction(int nReg, int cab, int fByte, int eByte) volatile;
75  void setAccessory(int aAdd, int aNum, int activate) volatile;
76  void writeTextPacket(int nReg, byte *b, int nBytes) volatile;
77  int readCV(int cv, int callBack, int callBackSub) volatile;
78  int readCVmain(int cv, int callBack, int callBackSub) volatile;
79  void writeCVByte(int cv, int bValue, int callBack, int callBackSub) volatile;
80  void writeCVBit(int cv, int bNum, int bValue, int callBack, int callBackSub) volatile;
81  void writeCVByteMain(int cab, int cv, int bvalue) volatile;
82  void writeCVBitMain(int cab, int cv, int bNum, int bValue) volatile;
83 
84 #ifdef DCCPP_DEBUG_MODE
85  void printPacket(int, byte *, int, int) volatile;
86 #endif
87 };
88 
89 #endif
90 #endif