1 // --------------------------------------------------------------------------
2 // --
3 // -- WINDOWS - Window handlers.
4 // --
5 // --
6 // --------------------------------------------------------------------------
7
8 // --------------------------------------------------------------------------
9 // -- Includes
10 // --------------------------------------------------------------------------
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <conio.h>
14 #include <alloc.h>
15 #include "defines.h"
16 #include "console.h"
17 #include "logs.h"
18 #include "windows.h"
19
20 // --------------------------------------------------------------------------
21 // -- Definitions
22 // --------------------------------------------------------------------------
23
24 // --- Status window specifics ---------------------
25
26 // --- Screen
27 #define WIN_STS_Y_SIZE 4
28
29 #define WIN_STS_LOG_X 18
30 #define WIN_STS_RXLOG_Y 1
31 #define WIN_STS_TXLOG_Y 2
32 #define WIN_STS_FMLOG_Y 3
33
34 #define WIN_STS_LOGFILE_X 34
35 #define WIN_STS_LOGFRX_Y 1
36 #define WIN_STS_LOGFTX_Y 2
37 #define WIN_STS_LOGFFM_Y 3
38
39 #define WIN_STS_COUNT_X 54
40 #define WIN_STS_RXCNT_Y 1
41 #define WIN_STS_TXCNT_Y 2
42
43 #define WIN_STS_FRXCOUNT_X 57
44 #define WIN_STS_FTXCOUNT_X 74
45 #define WIN_STS_FCOUNT_Y 3
46
47 #define WIN_STS_STOPGO_X 72
48 #define WIN_STS_STOPGO_Y 1
49
50 #define WIN_STS_ALARM_X 2
51 #define WIN_STS_ALARM_Y 4
52
53 #define WIN_STS_COLOR YELLOW
54 #define WIN_STS_COLORB BLUE
55
56 // --- Helper functions
57
58 // --- Status window specifics ---------------------
59
60 // --- Screen
61
62 #define WIN_FRM_COLOR YELLOW
63 #define WIN_FRM_COLORB BLUE
64
65 // --------------------------------------------------------------------------
66 // -- Data
67 // --------------------------------------------------------------------------
68
69 // --- Text for Logging types
70 char winLogStyleText[5][5] = {
71
72 "OFF ",
73 "SNAP",
74 "QUOT",
75 "DUMP",
76 "VERB"
77
78 };
79
80 char *winSTSGoString = "[ GO ]";
81 char *winSTSStopString = "[STOP]";
82
83 // --------------------------------------------------------------------------
84 // -- Methods
85 // --------------------------------------------------------------------------
86
87 // --- Status window -------------------------------------------------------
88
89 // --- Constructor ------------------
90 WinStatus::WinStatus( int yStart ) {
91
92 view = new ConFreeWindow(yStart, CON_START_X, WIN_STS_Y_SIZE);
93
94 view->setTextColor(WIN_STS_COLOR);
95 view->setBackgroundColor(WIN_STS_COLORB);
96
97 reset();
98
99 // DOES NOT REFRESH
100 }
101
102 // --- Destructor -------------------
103 WinStatus::~WinStatus() {
104
105 delete view;
106 }
107
108 // --- Reset values -----------------
109 void WinStatus::reset(void) {
110
111 rxLogName = NULL;
112 txLogName = NULL;
113 frameLogName = NULL;
114
115 rxStyle = LOG_OFF;
116 txStyle = LOG_OFF;
117 frameStyle = LOG_OFF;
118
119 rxCount = 0;
120 txCount = 0;
121 frameRXCount = 0;
122 frameTXCount = 0;
123
124 go = FALSE;
125
126 alarmText = NULL;
127 }
128
129 // --- Refresh the whole window ----
130 void WinStatus::refresh(void) {
131
132 char textBuffer[LINE_BUFFER_SIZE];
133
134 view->reset();
135 view->put(1,1, "-DTE RX� LOGGING � LOG FILE � CNT=");
136 view->put(1,2, "-DTE TX� LOGGING � LOG FILE � CNT=");
137 view->put(1,3, "-FRAME � LOGGING � LOG FILE � RX CNT= � TX CNT=");
138 view->put(1,4, "� �");
139
140 // Fill values
141 view->put(WIN_STS_LOG_X, WIN_STS_RXLOG_Y, winLogStyleText[rxStyle]);
142 view->put(WIN_STS_LOG_X, WIN_STS_TXLOG_Y, winLogStyleText[txStyle]);
143 view->put(WIN_STS_LOG_X, WIN_STS_FMLOG_Y, winLogStyleText[frameStyle]);
144
145 view->put(WIN_STS_LOGFILE_X, WIN_STS_LOGFRX_Y, rxLogName);
146 view->put(WIN_STS_LOGFILE_X, WIN_STS_LOGFTX_Y, txLogName);
147 view->put(WIN_STS_LOGFILE_X, WIN_STS_LOGFFM_Y, frameLogName);
148
149 sprintf(textBuffer, "%09lu", rxCount);
150 view->put(WIN_STS_COUNT_X, WIN_STS_RXCNT_Y, textBuffer);
151 sprintf(textBuffer, "%09lu", txCount);
152 view->put(WIN_STS_COUNT_X, WIN_STS_TXCNT_Y, textBuffer);
153
154 sprintf(textBuffer, "%09lu", frameRXCount);
155 view->put(WIN_STS_FRXCOUNT_X, WIN_STS_FCOUNT_Y, textBuffer);
156 sprintf(textBuffer, "%09lu", frameTXCount);
157 view->put(WIN_STS_FTXCOUNT_X, WIN_STS_FCOUNT_Y, textBuffer);
158
159 if (go)
160 view->put(WIN_STS_STOPGO_X, WIN_STS_STOPGO_Y, winSTSGoString,
161 LIGHTGRAY, GREEN );
162 else
163 view->put(WIN_STS_STOPGO_X, WIN_STS_STOPGO_Y, winSTSStopString,
164 LIGHTGRAY, RED );
165
166 sprintf(textBuffer, "%-78s", alarmText );
167 view->put(WIN_STS_ALARM_X, WIN_STS_ALARM_Y, textBuffer,
168 RED, BLUE);
169 }
170
171 // -- Move the window to a new position. DOES NOT REFRESH
172 void WinStatus::moveTo(int yStart) {
173
174 delete view;
175 view = new ConFreeWindow(yStart, CON_START_X, WIN_STS_Y_SIZE);
176
177 }
178
179
180 // --- Ststus window manipulators ----
181 void WinStatus::setLogRX(LogFileName *rx) {
182 rxLogName = rx;
183 view->put(WIN_STS_LOGFILE_X, WIN_STS_LOGFRX_Y, rxLogName);
184 }
185
186 void WinStatus::setLogTX(LogFileName *tx) {
187 txLogName = tx;
188 view->put(WIN_STS_LOGFILE_X, WIN_STS_LOGFTX_Y, txLogName);
189 }
190
191 void WinStatus::setLogFRAME(LogFileName *frame) {
192 frameLogName = frame;
193 view->put(WIN_STS_LOGFILE_X, WIN_STS_LOGFFM_Y, frameLogName);
194 }
195
196 void WinStatus::showGo(void) {
197 go = TRUE;
198 view->put(WIN_STS_STOPGO_X, WIN_STS_STOPGO_Y, winSTSGoString,
199 LIGHTGRAY, GREEN );
200 }
201
202 void WinStatus::showStop(void) {
203 go = FALSE;
204 view->put(WIN_STS_STOPGO_X, WIN_STS_STOPGO_Y, winSTSStopString,
205 LIGHTGRAY, RED );
206 }
207
208 void WinStatus::incRX(void) {
209 char textBuffer[LINE_BUFFER_SIZE];
210
211 rxCount++;
212 sprintf(textBuffer, "%09lu", rxCount);
213 view->put(WIN_STS_COUNT_X, WIN_STS_RXCNT_Y, textBuffer);
214 }
215
216 void WinStatus::incTX(void) {
217 char textBuffer[LINE_BUFFER_SIZE];
218
219 txCount++;
220 sprintf(textBuffer, "%09lu", txCount);
221 view->put(WIN_STS_COUNT_X, WIN_STS_TXCNT_Y, textBuffer);
222 }
223
224 void WinStatus::incRXFrame(void) {
225 char textBuffer[LINE_BUFFER_SIZE];
226
227 frameRXCount++;
228 sprintf(textBuffer, "%09lu", frameRXCount);
229 view->put(WIN_STS_FRXCOUNT_X, WIN_STS_FCOUNT_Y, textBuffer);
230 }
231
232 void WinStatus::incTXFrame(void) {
233 char textBuffer[LINE_BUFFER_SIZE];
234
235 frameTXCount++;
236 sprintf(textBuffer, "%09lu", frameTXCount);
237 view->put(WIN_STS_FTXCOUNT_X, WIN_STS_FCOUNT_Y, textBuffer);
238 }
239
240 void WinStatus::clearAll(void) {
241
242 clearChars();
243 clearFrames();
244 }
245
246 void WinStatus::clearChars(void) {
247 char textBuffer[LINE_BUFFER_SIZE];
248
249 rxCount = 0;
250 txCount = 0;
251 sprintf(textBuffer, "%09lu", rxCount);
252 view->put(WIN_STS_COUNT_X, WIN_STS_RXCNT_Y, textBuffer);
253 sprintf(textBuffer, "%09lu", txCount);
254 view->put(WIN_STS_COUNT_X, WIN_STS_TXCNT_Y, textBuffer);
255 }
256
257 void WinStatus::clearFrames(void) {
258 char textBuffer[LINE_BUFFER_SIZE];
259
260 frameRXCount = 0;
261 frameTXCount = 0;
262 sprintf(textBuffer, "%09lu", frameRXCount);
263 view->put(WIN_STS_FRXCOUNT_X, WIN_STS_FCOUNT_Y, textBuffer);
264 sprintf(textBuffer, "%09lu", frameTXCount);
265 view->put(WIN_STS_FTXCOUNT_X, WIN_STS_FCOUNT_Y, textBuffer);
266 }
267
268 void WinStatus::showRXStyle(LoggingStyle rx) {
269 rxStyle = rx;
270 view->put(WIN_STS_LOG_X, WIN_STS_RXLOG_Y, winLogStyleText[rxStyle]);
271 }
272
273 void WinStatus::showTXStyle(LoggingStyle tx) {
274 txStyle = tx;
275 view->put(WIN_STS_LOG_X, WIN_STS_TXLOG_Y, winLogStyleText[txStyle]);
276 }
277
278 void WinStatus::showFrameStyle(LoggingStyle frame) {
279 frameStyle = frame;
280 view->put(WIN_STS_LOG_X, WIN_STS_FMLOG_Y, winLogStyleText[frameStyle]);
281 }
282
283 void WinStatus::portAlarm( char *text ) {
284 char textBuffer[LINE_BUFFER_SIZE];
285
286 alarmText = text;
287 sprintf(textBuffer, "%-78s", alarmText );
288 view->put(WIN_STS_ALARM_X, WIN_STS_ALARM_Y, textBuffer,
289 RED, BLUE);
290 }
291
292
293 // --- Frame window -------------------------------------------------------
294
295 // --- Constructor ------------------
296 WinFrame::WinFrame(int startY, int sizeY, int lineBuffers ) {
297
298 ySize = sizeY;
299 view = new ConLBSWindow( startY, sizeY );
300
301 lines = (char *) farmalloc(lineBuffers * LINE_BUFFER_SIZE);
302 startLine = 0;
303 firstVisibleLine = 0;
304 nextLine = 0;
305
306 view->setTextColor(WIN_FRM_COLOR);
307 view->setBackgroundColor(WIN_FRM_COLORB);
308
309 view->reset();
310
311 }
312
313
314 // --- Destructor ------------------
315 WinFrame::~WinFrame() {
316
317 delete view;
318 farfree(lines);
319 }
320
321
322 // --- Dump the lines --------------
323 void WinFrame::flush(void) {
324
325 startLine = 0;
326 firstVisibleLine = 0;
327 nextLine = 0;
328
329 view->reset();
330 }
331
332
333 // --- Refresh the screen ---------
334 void WinFrame::refresh(void) {
335
336
337 view->reset();
338
339
340 }
341
342
343 // ---
344 void WinFrame::moveTo(int startY, int sizeY) {
345
346 }
347
348
349 // ---
350 void WinFrame::post( char *line) {
351
352 }
353
354
355 // ---
356 void WinFrame::scrollUp( void) {
357
358
359 }
360
361
362 // ---
363 void WinFrame::scrollDown(void) {
364
365 }
366
367
368 // --------------------------------------------------------------------------
369 // -- FUNCTIONS
370 // --------------------------------------------------------------------------
|