-
Notifications
You must be signed in to change notification settings - Fork 20
/
DCCPacketQueue.h
77 lines (63 loc) · 1.82 KB
/
DCCPacketQueue.h
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
#ifndef __DCCPACKETQUEUE_H__
#define __DCCPACKETQUEUE_H__
#include "Arduino.h"
/**
* A FIFO queue for holding DCC packets, implemented as a circular buffer.
* Copyright 2010 D.E. Goodman-Wilson
* TODO
**/
#include "DCCPacket.h"
class DCCPacketQueue
{
public: //protected:
DCCPacket *queue;
byte read_pos;
byte write_pos;
byte size;
byte written; //how many cells have valid data? used for determining full status.
public:
DCCPacketQueue(void);
virtual void setup(byte);
~DCCPacketQueue(void)
{
free(queue);
}
virtual inline bool isFull(void)
{
return (written == size);
}
virtual inline bool isEmpty(void)
{
return (written == 0);
}
virtual inline bool notEmpty(void)
{
return (written > 0);
}
virtual inline bool notRepeat(unsigned int address)
{
return (address != queue[read_pos].getAddress());
}
//void printQueue(void);
virtual bool insertPacket(DCCPacket *packet); //makes a local copy, does not take over memory management!
virtual bool readPacket(DCCPacket *packet); //does not hand off memory management of packet. used immediately.
bool forget(uint16_t address, uint8_t address_kind);
void clear(void);
};
//A queue that, when a packet is read, puts that packet back in the queue if it requires repeating.
class DCCRepeatQueue: public DCCPacketQueue
{
public:
DCCRepeatQueue(void);
//void setup(byte length);
bool insertPacket(DCCPacket *packet);
bool readPacket(DCCPacket *packet);
};
//A queue that repeats the topmost packet as many times as is indicated by the packet before moving on
class DCCEmergencyQueue: public DCCPacketQueue
{
public:
DCCEmergencyQueue(void);
bool readPacket(DCCPacket *packet);
};
#endif //__DCCPACKETQUEUE_H__