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 30
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  byte currentBit;
45  byte nRepeat;
46  int *speedTable;
47  static byte idlePacket[];
48  static byte resetPacket[];
49  static byte bitMask[];
50  RegisterList(int);
51  void loadPacket(int, byte *, int, int, int=0) volatile;
52 
53 #ifdef USE_TEXTCOMMAND
54  void setThrottle(char *) volatile;
55  void setFunction(char *) volatile;
56  void setAccessory(char *) volatile;
57  void writeTextPacket(char *) volatile;
58 #endif
59 
60  int readCVraw(int cv, int callBack, int callBackSub, bool FromProg) volatile;
61 
62 #ifdef USE_TEXTCOMMAND
63  void readCV(char *) volatile;
64  void writeCVByte(char *) volatile;
65  void writeCVBit(char *) volatile;
66 
67  int readCVmain(char *) volatile;
68  void writeCVByteMain(char *) volatile;
69  void writeCVBitMain(char *s) volatile;
70 #endif
71 
72  void setThrottle(int nReg, int cab, int tSpeed, int tDirection) volatile;
73  void setFunction(int nReg, int cab, int fByte, int eByte) volatile;
74  void setAccessory(int aAdd, int aNum, int activate) volatile;
75  void writeTextPacket(int nReg, byte *b, int nBytes) volatile;
76  void readCV(int cv, int callBack, int callBackSub) volatile;
77  int readCVmain(int cv, int callBack, int callBackSub) volatile;
78  void writeCVByte(int cv, int bValue, int callBack, int callBackSub) volatile;
79  void writeCVBit(int cv, int bNum, int bValue, int callBack, int callBackSub) volatile;
80  void writeCVByteMain(int cab, int cv, int bvalue) volatile;
81  void writeCVBitMain(int cab, int cv, int bNum, int bValue) volatile;
82 
83 #ifdef DCCPP_DEBUG_MODE
84  void printPacket(int, byte *, int, int) volatile;
85 #endif
86 };
87 
88 #endif