1 package info.mikethomas.fahview.v6project.model;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 import info.mikethomas.fahview.v6project.utilities.QueueReader;
25 import java.util.logging.Level;
26 import java.util.logging.Logger;
27
28
29
30
31
32
33
34 public class QueueImpl implements Queue {
35
36 private int version;
37 private int current;
38 private QueueIndexImpl[] index;
39 private int pfract;
40 private int punits;
41 private int drate;
42 private int dunits;
43 private int urate;
44 private int uunits;
45 private int sent;
46 private byte[] z7156;
47
48 private QueueReader reader;
49
50
51
52
53
54
55 public QueueImpl(QueueReader reader) {
56 this.reader = reader;
57 update();
58 }
59
60
61 @Override
62 public int getVersion() {
63 return version;
64 }
65
66
67 @Override
68 public int getCurrent() {
69 return current;
70 }
71
72
73 @Override
74 public QueueIndexImpl getQueueIndex(int index) {
75 return this.index[index];
76 }
77
78
79 @Override
80 public int getPfract() {
81 return pfract;
82 }
83
84
85 @Override
86 public int getPunits() {
87 return punits;
88 }
89
90
91 @Override
92 public int getDrate() {
93 return drate;
94 }
95
96
97 @Override
98 public int getDunits() {
99 return dunits;
100 }
101
102
103 @Override
104 public int getUrate() {
105 return urate;
106 }
107
108
109 @Override
110 public int getUunits() {
111 return uunits;
112 }
113
114
115 @Override
116 public int getSent() {
117 return sent;
118 }
119
120
121
122
123 protected void setVersion() {
124 version = (int) reader.readLEUInt(VERSION_POS, VERSION_LENGTH);
125 }
126
127
128
129
130 protected void setCurrent() {
131 current = (int) reader.readLEUInt(CURRENT_POS, CURRENT_LENGTH);
132 }
133
134
135
136
137 protected void setIndex() {
138 try {
139 index = new QueueIndexImpl[10];
140 index[0] = new QueueIndexImpl(0, reader);
141 index[1] = new QueueIndexImpl(1, reader);
142 index[2] = new QueueIndexImpl(2, reader);
143 index[3] = new QueueIndexImpl(3, reader);
144 index[4] = new QueueIndexImpl(4, reader);
145 index[5] = new QueueIndexImpl(5, reader);
146 index[6] = new QueueIndexImpl(6, reader);
147 index[7] = new QueueIndexImpl(7, reader);
148 index[8] = new QueueIndexImpl(8, reader);
149 index[9] = new QueueIndexImpl(9, reader);
150 }
151 catch (InstantiationException ex) {
152 Logger.getLogger(QueueImpl.class.getName()).log(Level.SEVERE, null, ex);
153 }
154 }
155
156
157
158
159 protected void setPfract() {
160 pfract = (int) reader.readLEUInt(PFRACT_POS, PFRACT_LENGTH);
161 }
162
163
164
165
166 protected void setPunits() {
167 punits = (int) reader.readLEUInt(PUNITS_POS, PUNITS_LENGTH);
168 }
169
170
171
172
173 protected void setDrate() {
174 drate = (int) reader.readLEUInt(DRATE_POS, DRATE_LENGTH);
175 }
176
177
178
179
180 protected void setDunits() {
181 dunits = (int) reader.readLEUInt(DUNITS_POS, DUNITS_LENGTH);
182 }
183
184
185
186
187 protected void setUrate() {
188 urate = (int) reader.readLEUInt(URATE_POS, URATE_LENGTH);
189 }
190
191
192
193
194 protected void setUunits() {
195 uunits = (int) reader.readLEUInt(UUNITS_POS, UUNITS_LENGTH);
196 }
197
198
199
200
201 protected void setSent() {
202 sent = (int) reader.readLEUInt(SENT_POS, SENT_LENGTH);
203 }
204
205
206
207
208 protected void setZ7156() {
209 z7156 = reader.read(Z7156_POS, Z7156_LENGTH);
210 boolean notZero = false;
211 for (int i = 0; i < z7156.length; i++) {
212 if (z7156[i] != 0) {
213 notZero = true;
214 }
215 }
216 if (notZero) {
217 System.err.println("WARNING: Z7156 is not all zero");
218 }
219 }
220
221
222
223
224
225
226 @Override
227 public String toString() {
228 String result = "";
229 result += "queue.version\t" + getVersion();
230 result += "\nqueue.current\t" + getCurrent();
231 result += "\n" + getQueueIndex(0);
232 result += "\n" + getQueueIndex(1);
233 result += "\n" + getQueueIndex(2);
234 result += "\n" + getQueueIndex(3);
235 result += "\n" + getQueueIndex(4);
236 result += "\n" + getQueueIndex(5);
237 result += "\n" + getQueueIndex(6);
238 result += "\n" + getQueueIndex(7);
239 result += "\n" + getQueueIndex(8);
240 result += "\n" + getQueueIndex(9);
241 result += "\nqueue.pfract\t" + getPfract();
242 result += "\nqueue.punits\t" + getPunits();
243 result += "\nqueue.drate\t" + getDrate();
244 result += "\nqueue.dunits\t" + getDunits();
245 result += "\nqueue.urate\t" + getUrate();
246 result += "\nqueue.uunits\t" + getUunits();
247 result += "\nqueue.sent\t" + getSent();
248 return result;
249 }
250
251
252 @Override
253 public final void update() {
254 setVersion();
255 setCurrent();
256 setIndex();
257 setPfract();
258 setPunits();
259 setDrate();
260 setDunits();
261 setUrate();
262 setUunits();
263 setSent();
264 setZ7156();
265 }
266 }