Source code for /engineering/SERIAL-TEST/MASTER.CPPOriginal file MASTER.CPP
   1 // --------------------------------------------------------------------------
   2 // --
   3 // -- MASTER - Master for LINE.
   4 // --
   5 // --
   6 // --------------------------------------------------------------------------
   7 
   8 // --------------------------------------------------------------------------
   9 // -- Includes
  10 // --------------------------------------------------------------------------
  11 #include <stdio.h>
  12 #include <stdlib.h>
  13 #include <conio.h>
  14 #include "defines.h"
  15 #include "console.h"
  16 #include "fbuffer.h"
  17 #include "serial.h"
  18 #include "key.h"
  19 
  20 
  21 // --------------------------------------------------------------------------
  22 // -- Defines
  23 // --------------------------------------------------------------------------
  24 
  25 // --- Port window defines ---
  26 #define MPW_PORT1X		1
  27 #define MPW_PORT2X 	    40
  28 #define MPW_PORTY		40
  29 #define MPW_PORT_YSIZE	11
  30 
  31 // --- Primary window defines
  32 #define MPRIW_X		1
  33 #define MPRIW_Y		1
  34 #define MPRIW_YSIZE 38
  35 
  36 #define MPRIW_SEP	39
  37 
  38 
  39 #define GRAYED_COLOR    YELLOW
  40 #define GRAYED_BACK		BLUE
  41 
  42 #define HIGHLITE_COLOR	WHITE
  43 #define HIGHLITE_BACK   GREEN
  44 
  45 #define MFS_X		14
  46 #define MFS_Y		13
  47 #define MMS_X		33
  48 #define MFCS_X		54
  49 
  50 #define PORT_Y		4
  51 #define BPS_X		3
  52 #define STOP_X      11
  53 #define PARITY_X    19
  54 #define BITS_X      29
  55 
  56 // --- Master screen commands ---
  57 enum  MasterScreenCommands {
  58 
  59    MSC_EXIT = (KEY_NO_COMMAND+1),
  60    MSC_GO,
  61    MSC_PORT1_BPS,
  62    MSC_PORT2_BPS,
  63    MSC_PORT1_BITS,
  64    MSC_PORT2_BITS,
  65    MSC_PORT1_SBITS,
  66    MSC_PORT2_SBITS,
  67    MSC_PORT1_PARITY,
  68    MSC_PORT2_PARITY,
  69    MSC_FRAME_UP,
  70    MSC_FRAME_DOWN,
  71    MSC_MODE_UP,
  72    MSC_MODE_DOWN,
  73    MSC_FC_UP,
  74    MSC_FC_DOWN
  75 
  76 };
  77 
  78 // --- Selector states
  79 enum MasterFramingState {
  80 
  81    MFS_SERIAL = 0,
  82    MFS_PPP,
  83    MFS_PCCOM,
  84    MFS_IRLAP
  85 };
  86 #define MFS_LAST_STATE (MFS_IRLAP + 1)
  87 #define MFS_MAX		   MFS_IRLAP
  88 
  89 enum MasterModeState {
  90 
  91    MMS_SNOOP 	= 0,
  92    MMS_INTRUDE
  93 
  94 };
  95 #define MMS_LAST_STATE (MMS_INTRUDE + 1)
  96 #define MMS_MAX		   MMS_INTRUDE
  97 
  98 enum MasterFCState {
  99 
 100    MFCS_NONE	  = 0,
 101    MFCS_HARDWARE
 102 };
 103 #define MFCS_LAST_STATE (MFCS_HARDWARE + 1)
 104 #define MFCS_MAX	    MFCS_HARDWARE
 105 
 106 // --------------------------------------------------------------------------
 107 // -- Definitions
 108 // --------------------------------------------------------------------------
 109 
 110 // --- Port class -----------------------------------------------------------
 111 class  MasterPort : public ConFreeWindow {
 112 
 113    Boolean		  active;
 114 
 115  protected:
 116 
 117    void refreshPortData(void);
 118 
 119  public:
 120 
 121    PortParameters  myParam;
 122 
 123    MasterPort(SS_PORT_T	thisPort);
 124 
 125    void refresh(void) { refreshPortData(); };
 126    void redraw(void);
 127 
 128 };
 129 
 130 
 131 // --- Main screen class ----------------------------------------------------
 132 class MasterScreen {
 133 
 134    // Windows used
 135    MasterPort		port1;
 136    MasterPort		port2;
 137 
 138    ConFreeWindow    primary;
 139 
 140    ConSepLine		separator;
 141 
 142    // Key controler
 143    KeyHandler		keyBoard;
 144 
 145    // Private methods
 146    void  refreshMFS(void);
 147    void  refreshMMS(void);
 148    void  refreshMFCS(void);
 149    void  refreshPort1(void) { port1.refresh(); };
 150    void  refreshPort2(void) { port2.refresh(); };
 151 
 152  public:
 153 
 154    // Current states
 155    MasterFramingState	framingState;
 156    MasterModeState		modeState;
 157    MasterFCState		fcState;
 158 
 159    // Methods
 160    MasterScreen(void);
 161    MasterScreenCommands use(void);
 162 
 163    void refresh(void);
 164 
 165 
 166 };
 167 
 168 // --------------------------------------------------------------------------
 169 // -- Data
 170 // --------------------------------------------------------------------------
 171 
 172 // Helpers
 173 
 174 // --------------------------------------------------------------------------
 175 // -- Data
 176 // --------------------------------------------------------------------------
 177 
 178 // -- Key maps for Master screen
 179 #define 	MASTER_KEY_MAP_SIZE	2
 180 KeyElement  masterKeyMap[MASTER_KEY_MAP_SIZE] = {
 181 
 182    { MSC_EXIT, KEY_ESC    },
 183    { MSC_GO,   KEY_ENTER  }
 184 
 185 };
 186 
 187 #define 	MASTER_KEY_MAP_EXT_SIZE	14
 188 KeyElement  masterKeyMapExt[MASTER_KEY_MAP_EXT_SIZE] = {
 189 
 190    { MSC_PORT1_BPS,		KEY_F1	   },
 191    { MSC_PORT1_SBITS,	KEY_F2	   },
 192    { MSC_PORT1_PARITY,	KEY_F3	   },
 193    { MSC_PORT1_BITS,	KEY_F4	   },
 194    { MSC_PORT2_BPS,		KEY_F5	   },
 195    { MSC_PORT2_SBITS,	KEY_F6	   },
 196    { MSC_PORT2_PARITY,	KEY_F7	   },
 197    { MSC_PORT2_BITS,	KEY_F8	   },
 198    { MSC_FRAME_UP,   	KEY_INS    },
 199    { MSC_FRAME_DOWN,	KEY_DEL    },
 200    { MSC_MODE_UP,   	KEY_HOME   },
 201    { MSC_MODE_DOWN,		KEY_END    },
 202    { MSC_FC_UP,     	KEY_PGUP   },
 203    { MSC_FC_DOWN,		KEY_PGDOWN }
 204 
 205 };
 206 
 207 
 208 // -- Text for various selectors
 209 char	mfsText[4][10] = {
 210 
 211    " SERIAL  ",
 212    " PPP     ",
 213    " pcCOMM  ",
 214    " irLAP   "
 215 };
 216 
 217 char	mmsText[2][12] = {
 218 
 219    "  SNOOP    ",
 220    "  INTRUDE  "
 221 };
 222 
 223 char	mfcsText[2][15] = {
 224 
 225    "   NONE       ",
 226    "   HARDWARE   "
 227 };
 228 
 229 char    portBPSText[5][7] = {
 230 
 231    "   300",
 232    "  2400",
 233    "  9600",
 234    " 19200",
 235    " 38400"
 236 };
 237 
 238 char	portSBITSText[2][7] = {
 239 
 240    "    1 ",
 241    "    2 "
 242 };
 243 
 244 char	portParityText[3][9] = {
 245 
 246    "   NONE ",
 247    "    ODD ",
 248    "   EVEN "
 249 };
 250 
 251 char    portBitsText[3][7] = {
 252 
 253    "    5 ",
 254    "    7 ",
 255    "    8 "
 256 };
 257 
 258 // --------------------------------------------------------------------------
 259 // -- Methods
 260 // --------------------------------------------------------------------------
 261 
 262 // --- port screen class --------------------------------------------------
 263 
 264 // --- Constructor ------------
 265 MasterPort::MasterPort(SS_PORT_T	thisPort) :
 266 			ConFreeWindow(MPW_PORTY, 1+(thisPort*MPW_PORT2X), MPW_PORT_YSIZE )
 267 {
 268 
 269 }
 270 
 271 // --- Do a port refresh ---
 272 void  MasterPort::refreshPortData( void ) {
 273 
 274    int  step;
 275 
 276    // put the BPS first
 277    for (step = 0; step <= SS_BPS_38400; step++) {
 278 	  if (myParam.bpsIs() == step)
 279 		 put(BPS_X, PORT_Y+step, portBPSText[step],
 280 			 HIGHLITE_COLOR, HIGHLITE_BACK);
 281 	  else
 282 		 put(BPS_X, PORT_Y+step, portBPSText[step]);
 283    }
 284 
 285    if (myParam.sBitsIs() == SS_SBITS_1) {
 286 		 put(STOP_X, PORT_Y,   portSBITSText[0],
 287 			 HIGHLITE_COLOR, HIGHLITE_BACK);
 288 		 put(STOP_X, PORT_Y+1, portSBITSText[1]);
 289    } else {
 290 		 put(STOP_X, PORT_Y,   portSBITSText[0]);
 291 		 put(STOP_X, PORT_Y+1, portSBITSText[1],
 292 			 HIGHLITE_COLOR, HIGHLITE_BACK);
 293    }
 294 
 295    for (step = 0; step <= SS_PARITY_EVEN; step++) {
 296 	  if (myParam.parityIs() == step)
 297 		 put(PARITY_X, PORT_Y+step, portParityText[step],
 298 			 HIGHLITE_COLOR, HIGHLITE_BACK);
 299 	  else
 300 		 put(PARITY_X, PORT_Y+step, portParityText[step]);
 301    }
 302 
 303    for (step = 0; step <= SS_BITS_8; step++) {
 304 	  if (myParam.bitsIs() == step)
 305 		 put(BITS_X, PORT_Y+step, portBitsText[step],
 306 			 HIGHLITE_COLOR, HIGHLITE_BACK);
 307 	  else
 308 		 put(BITS_X, PORT_Y+step, portBitsText[step]);
 309    }
 310 
 311 };
 312 
 313 // --- Do a port redraw ---
 314 void MasterPort::redraw(void) {
 315 
 316    reset();
 317    put(1,1,"  PORT 1  (COM1)                      ��  PORT 2  (COM2)");
 318    put(1,2,"                                      ��");
 319    put(1,3,"  �BPSĿ  �STOP�  �PARITY�  �BITS�    ��  �BPSĿ  �STOP�  �PARITY�  �BITS�");
 320    put(1,4,"                                      ��");
 321    put(1,5,"                                      ��");
 322    put(1,6,"          ������                      ��          ������");
 323    put(1,7,"                  ��������  ������    ��                  ��������  ������");
 324    put(1,8,"                                      ��");
 325    put(1,9,"  ������                              ��  ������");
 326    put(1,10,"                                      ��");
 327 }
 328 
 329 // --- Operators ---
 330 
 331 
 332 
 333 // --- master screen class --------------------------------------------------
 334 
 335 // --- Constructor ------------
 336 MasterScreen::MasterScreen(void) :
 337 			  port1(SS_PORT_1),
 338 			  port2(SS_PORT_2),
 339 			  primary(MPRIW_Y, MPRIW_X, MPRIW_YSIZE),
 340 			  separator(MPRIW_SEP, YELLOW, BLUE),
 341 			  keyBoard()						       {
 342 
 343 
 344 
 345    // Setup windows
 346    port1.setTextColor(YELLOW);
 347    port2.setTextColor(YELLOW);
 348    port1.setBackgroundColor(BLUE);
 349    port2.setBackgroundColor(BLUE);
 350 
 351    primary.setTextColor(YELLOW);
 352    primary.setBackgroundColor(BLUE);
 353 
 354    // setup key handler
 355    keyBoard.registerTable( masterKeyMap,    MASTER_KEY_MAP_SIZE,     FALSE);
 356    keyBoard.registerTable( masterKeyMapExt, MASTER_KEY_MAP_EXT_SIZE, TRUE );
 357 
 358    // Init states
 359    framingState = MFS_SERIAL;
 360    modeState    = MMS_SNOOP;
 361    fcState	    = MFCS_NONE;
 362 
 363 
 364 }
 365 
 366 
 367 // --- Use ------------
 368 MasterScreenCommands  MasterScreen::use( void ) {
 369 
 370    MasterScreenCommands     command;
 371    char					    dummy;
 372 
 373    // Reset all the windows
 374    port1.redraw();
 375    port1.refresh();
 376    port2.refresh();
 377    refresh();
 378 
 379    separator.reset();
 380 
 381    // loop on command.
 382    command = keyBoard.get(dummy);
 383    while(command != MSC_EXIT) {
 384 
 385 	  switch (command) {
 386 
 387 		 case  MSC_PORT1_BPS:
 388 			   port1.myParam.bpsNext();
 389 			   port1.refresh();
 390 			   break;
 391 
 392 		 case  MSC_PORT1_SBITS:
 393 			   port1.myParam.sBitsNext();
 394 			   port1.refresh();
 395 			   break;
 396 
 397 		 case  MSC_PORT1_PARITY:
 398 			   port1.myParam.parityNext();
 399 			   port1.refresh();
 400 			   break;
 401 
 402 		 case  MSC_PORT1_BITS:
 403 			   port1.myParam.bitsNext();
 404 			   port1.refresh();
 405 			   break;
 406 
 407 		 case  MSC_PORT2_BPS:
 408 			   port2.myParam.bpsNext();
 409 			   port2.refresh();
 410 			   break;
 411 
 412 		 case  MSC_PORT2_SBITS:
 413 			   port2.myParam.sBitsNext();
 414 			   port2.refresh();
 415 			   break;
 416 
 417 		 case  MSC_PORT2_PARITY:
 418 			   port2.myParam.parityNext();
 419 			   port2.refresh();
 420 			   break;
 421 
 422 		 case  MSC_PORT2_BITS:
 423 			   port2.myParam.bitsNext();
 424 			   port2.refresh();
 425 			   break;
 426 
 427 		 case  MSC_FRAME_DOWN:
 428 			   if (framingState == MFS_MAX)
 429 				  framingState = MFS_SERIAL;
 430 			   else
 431 				  framingState++;
 432 			   refreshMFS();
 433 			   break;
 434 
 435 		 case  MSC_FRAME_UP:
 436 			   if (framingState == MFS_SERIAL)
 437 				  framingState = MFS_MAX;
 438 			   else
 439 				  framingState--;
 440 			   refreshMFS();
 441 			   break;
 442 
 443 		 case  MSC_MODE_DOWN:
 444 		 case  MSC_MODE_UP:
 445 			   if (modeState == MMS_INTRUDE)
 446 				  modeState = MMS_SNOOP;
 447 			   else
 448 				  modeState = MMS_INTRUDE;
 449 			   refreshMMS();
 450 			   break;
 451 
 452 
 453 		 case  MSC_FC_UP:
 454 		 case  MSC_FC_DOWN:
 455 			   if (fcState == MFCS_NONE)
 456 				  fcState = MFCS_HARDWARE;
 457 			   else
 458 				  fcState = MFCS_NONE;
 459 			   refreshMFCS();
 460 			   break;
 461 
 462 
 463 		 case  MSC_GO:
 464 			   return MSC_GO;
 465 
 466 		 case  MSC_EXIT:
 467 			   return MSC_EXIT;
 468 
 469 	  } // end case
 470 
 471 	  command = keyBoard.get(dummy);
 472 
 473    } // end while
 474 
 475    return MSC_EXIT;
 476 }
 477 
 478 
 479 // --- Refresh the master screen ---
 480 void  MasterScreen::refresh(void) {
 481 
 482    // clear
 483    primary.reset();
 484 
 485    // Draw screen
 486    primary.put(1,1,"   DOPPELGANGER");
 487    primary.put(1,4,"   FOR INTERNAL USE ONLY");
 488 
 489    primary.put(13, 9,"���������Ŀ        �����������Ŀ        ��������������Ŀ");
 490    primary.put(13,10,"� FRAMING �        � LINE MODE �        � FLOW CONTROL �");
 491    primary.put(13,11,"�(ins/del)�        � (home/end)�        � (pgup/pgdn)  �");
 492    primary.put(13,12,"���������Ĵ        �����������Ĵ        ��������������Ĵ");
 493    primary.put(13,13,"�         �        �           �        �              �");
 494    primary.put(13,14,"�         �        �           �        �              �");
 495    primary.put(13,15,"�         �        �������������        ����������������");
 496    primary.put(13,16,"�         �");
 497    primary.put(13,17,"�����������");
 498 
 499    // draw selectors
 500    refreshMFS();
 501    refreshMMS();
 502    refreshMFCS();
 503 
 504 }
 505 
 506 
 507 // --- Refresh the Master Framing mode selector ---
 508 void  MasterScreen::refreshMFS(void) {
 509 
 510    for (int step = 0; step < MFS_LAST_STATE; step++) {
 511 
 512 	  if (framingState == step)
 513 		 primary.put(MFS_X, MFS_Y+step, mfsText[step],
 514 					 HIGHLITE_COLOR, HIGHLITE_BACK);
 515 	  else
 516 		 primary.put(MFS_X, MFS_Y+step, mfsText[step]);
 517    }
 518 }
 519 
 520 // --- Refresh the Master mode selector ---
 521 void  MasterScreen::refreshMMS(void) {
 522 
 523    for (int step = 0; step < MMS_LAST_STATE; step++) {
 524 
 525 	  if (modeState == step)
 526 		 primary.put(MMS_X, MFS_Y+step, mmsText[step],
 527 					 HIGHLITE_COLOR, HIGHLITE_BACK);
 528 	  else
 529 		 primary.put(MMS_X, MFS_Y+step, mmsText[step]);
 530    }
 531 }
 532 
 533 // --- Refresh the master flow control selector ---
 534 void  MasterScreen::refreshMFCS(void) {
 535 
 536    for (int step = 0; step < MFCS_LAST_STATE; step++) {
 537 
 538 	  if (fcState == step)
 539 		 primary.put(MFCS_X, MFS_Y+step, mfcsText[step],
 540 					 HIGHLITE_COLOR, HIGHLITE_BACK);
 541 	  else
 542 		 primary.put(MFCS_X, MFS_Y+step, mfcsText[step]);
 543    }
 544 }
 545 
 546 
 547 
 548 
 549 // --------------------------------------------------------------------------
 550 // -- Functions
 551 // --------------------------------------------------------------------------
 552 
 553 // --- Helpers --------------------------------------------------------------
 554 
 555 
 556 // -- Main ------------------------------------------------------------------
 557 void main() {
 558 
 559    // Make the primary screen
 560    Console					thisConsole;
 561    MasterScreen				screen;
 562    MasterScreenCommands     command;
 563 
 564    // Use the mast screen
 565    command = screen.use();
 566    while( command != MSC_EXIT) {
 567 
 568 	  command = screen.use();
 569    }
 570 
 571 }