Exemplo n.º 1
0
void
delete_digi_win(DigiWin *dw)
{
	del_panel (GetPan(dw));
	delwin (GetWin(dw));
	free (dw);
}
void CMainFrame::ChangeWin( int id)
{
	if (GetWin(id) != NULL)
	{
		CPosFrame::ChangeWin(id);
	}
}
Exemplo n.º 3
0
void CGroup::EnableWidget(CWidget *w, bool e)
{
    // Widget not initialized yet? (ignore if the group isn't initialized, since it will initialize the widget later)
    if (e && GetWin() && !w->GetWin())
        RequestUpdate();
    else if (!e && (m_pFocusedWidget == w))
        SetValidWidget(w);
}
Exemplo n.º 4
0
void
digibox(DigiWin *dw)
{
	WINDOW *w = GetWin(dw);

	wborder (w, mapchar(ACS_VLINE), mapchar(ACS_VLINE),
	            mapchar(ACS_HLINE), mapchar(ACS_HLINE),
	            mapchar(ACS_ULCORNER), mapchar(ACS_URCORNER),
	            mapchar(ACS_LLCORNER), mapchar(ACS_LRCORNER));
}
void CInputField::DoDraw()
{
    std::string::iterator first = m_Text.begin(), last;
    utf8::advance(first, m_StartPos, m_Text.end());
    last = first + GetMBLenFromW(std::string(first, m_Text.end()), Width()-2); // -2 for the border and cursor
    
    if (m_cOut)
    {
        TSTLStrSize charn = utf8::distance(first, last);
        AddStr(this, 1, 1, std::string(charn, m_cOut).c_str());
    }
    else
        AddStr(this, 1, 1, std::string(first, last).c_str());
    
    if (Focused())
    {
        std::string::iterator start = m_Text.begin();
        utf8::advance(start, m_StartPos, m_Text.end());
        int cursx = SafeConvert<int>(GetMBWidthFromC(m_Text, start, m_CursorPos)) + 1;
        TUI.LockCursor(GetWX(GetWin()) + cursx, GetWY(GetWin())+1);
    }
}
Exemplo n.º 6
0
void
fillwin(DigiWin *dw, int i)
{
	int y, x, lines1, cols;
	WINDOW *w = GetWin(dw);

	lines1 = GetHeight(dw);
	cols = GetWidth(dw);

	for (y = 0; y < lines1; y++)
		for (x = 0; x < cols; x++)
			if (!((y == (LINES - 1)) && (x == (COLS - 1))))
				mvwaddch (w, y, x, i);
}
Exemplo n.º 7
0
void
erase_win(DigiWin *dw)
{
	int y, x, lines1,  cols;
	WINDOW *w = GetWin(dw);

	lines1 = GetHeight(dw);
	cols = GetWidth(dw);

	for (y = 1; y < lines1 - 1; y++)
		for (x = 1; x < cols - 1; x++)
			if (!((y == (LINES - 1)) && (x == (COLS - 1))))
				mvwaddstr (w, y, x, " ");
}
Exemplo n.º 8
0
void
solidbox(DigiWin *dw)
{
	int y, x;
	WINDOW *w = GetWin(dw);

	wattron (w, make_attr (A_STANDOUT, BLACK, BLUE));
	for (x = 0; x < GetWidth(dw); x++)
	{
		mvwaddch (w, 0, x, ' ');
		mvwaddch (w, GetHeight(dw) - 1, x, ' ');
	}
	for (y = 0; y < GetHeight(dw); y++)
	{
		mvwaddch (w, y, 0, ' ');
		mvwaddch (w, y, GetWidth(dw) - 1, ' ');
	}

	wattroff (w, make_attr (A_STANDOUT, BLACK, BLUE));
}
Exemplo n.º 9
0
void CMenu::Select(const std::string &id)
{
    if (!GetWin())
    {
        // Can't move cursor before being initialized
        m_QueuedSelection = id;
        return;
    }

    TMenuList::iterator line = std::lower_bound(m_MenuList.begin(), m_MenuList.end(), id);

    if ((line != m_MenuList.end()) && (line->id == id))
    {
        TMenuList::iterator cur = m_MenuList.begin() + GetCurrent();
        Move(SafeConvert<int>(std::distance(cur, line)));
        PushEvent(EVENT_DATACHANGED);
    }
    else
        assert(false);
}
Exemplo n.º 10
0
void 
print_channel(struct deviceinfo *unit)
{
	int i = 0, option = EOF, scr_opt = 0;

	int rc;
	fd_set rfds;
	struct timeval tv;
	int max_fd;

	struct digi_node node;
	struct digi_chan chan;
	int port = 0;
	char ttyname[100];


	int d_invokes_capture = 1;   /* 0 if 'D' should invoke "exam_panel" */
	                             /* 1 if 'D' should invoke "scope_panel" */


	WINDOW *chanwin = GetWin(ChanWin);

	/* 
	 * scr_opt is just used to determine which field to 
	 * highlight.
	 */

	show_panel (GetPan(ChanWin));
	update_panels ();
	doupdate ();

	DPAOpenDevice(unit);

	while ((option != 'Q') && (option != 'q') && (option != ESC))
	{

		/* Get port info for current port */
		DPAGetNode(unit, &node);
		DPAGetChannel(unit, &chan, port);

		if (DPAGetPortName(unit, &node, &chan, port, ttyname) == NULL) {
			ttyname[0] = '\0';
		}

		max_fd = 0;
		FD_ZERO(&rfds);
		FD_SET(0, &rfds);

		mvwprintw (chanwin, 1, 2, "Device Description: %-54.54s", node.nd_ps_desc);

		mvwprintw (chanwin, 5, 35, "Name: %-10.10s", ttyname);

		wattrset (chanwin, make_attr (A_BOLD, WHITE, BLACK));

		mvwprintw (chanwin, 5, 56, "Status: %-10.10s",
		           chan.ch_open ? "Open" : "Closed");
		wattrset (chanwin, make_attr (A_NORMAL, WHITE, BLACK));

		if (scr_opt == 1)
		{
			wattrset (chanwin, make_attr (A_REVERSE | A_STANDOUT, WHITE, BLACK));
			mvwprintw (chanwin, 3, 5, "Unit IP Address: %-15.15s", unit->host);
			wattrset (chanwin, make_attr (A_NORMAL, WHITE, BLACK));
			mvwprintw (chanwin, 5, 8, "Port Number : %-2d", port + 1);
		}
		else if (scr_opt == 2)
		{
			wattrset (chanwin, make_attr (A_NORMAL, WHITE, BLACK));
			mvwprintw (chanwin, 3, 5, "Unit IP Address: %-15.15s", unit->host);
			wattrset (chanwin, make_attr (A_REVERSE | A_STANDOUT, WHITE, BLACK));
			mvwprintw (chanwin, 5, 8, "Port Number : %-2d", port + 1);
			wattrset (chanwin, make_attr (A_NORMAL, WHITE, BLACK));
		}
		else
		{
			mvwprintw (chanwin, 3, 5, "Unit IP Address: %-15.15s", unit->host);
			mvwprintw (chanwin, 5, 8, "Port Number : %-2d", port + 1);
		}

		if (!vanilla) wattrset (chanwin, make_attr (A_ALTCHARSET, GREEN, BLACK));
		else wattrset (chanwin, make_attr (A_NORMAL, GREEN, BLACK));

		for (i = 0; i < 62; i++)
			mvwaddch (chanwin, 6, 8 + i, mapchar(ACS_HLINE));
		mvwaddch (chanwin, 6, 7, mapchar(ACS_ULCORNER));
		mvwaddch (chanwin, 6, 70, mapchar(ACS_URCORNER));
		mvwaddch (chanwin, 7, 7, mapchar(ACS_VLINE));
		mvwaddch (chanwin, 7, 70, mapchar(ACS_VLINE));
		mvwaddch (chanwin, 8, 7, mapchar(ACS_VLINE));
		mvwaddch (chanwin, 8, 70, mapchar(ACS_VLINE));

		wattrset (chanwin, make_attr (A_NORMAL, WHITE, BLACK));
		mvwprintw (chanwin, 12, 24, "Signal Active = ");
		wattrset (chanwin, make_attr (A_STANDOUT, WHITE, GREEN));
		waddstr (chanwin, "X");

		wattrset (chanwin, make_attr (A_NORMAL, WHITE, BLACK));
		mvwaddstr (chanwin, 12, 46, "Inactive =");
		wattrset (chanwin, make_attr (A_NORMAL, GREEN, BLACK));
		mvwaddstr (chanwin, 12, 57, "_");
		wattrset (chanwin, make_attr (A_NORMAL, WHITE, BLACK));

		mvwaddstr (chanwin, 8, 13,
				   "Tx:             RTS  CTS  DSR  DCD  DTR  RI  OFC  IFC");
		mvwaddstr (chanwin, 9, 13,
				   "Rx:                                                  ");

		if (!vanilla)
			wattrset (chanwin, make_attr (A_ALTCHARSET, GREEN, BLACK));
		else
			wattrset (chanwin, make_attr (A_NORMAL, GREEN, BLACK));

		mvwaddch (chanwin, 9, 7, mapchar(ACS_VLINE));
		mvwaddch (chanwin, 9, 70, mapchar(ACS_VLINE));
		mvwaddch (chanwin, 10, 7, mapchar(ACS_VLINE));
		mvwaddch (chanwin, 10, 70, mapchar(ACS_VLINE));
		mvwaddch (chanwin, 11, 7, mapchar(ACS_LLCORNER));
		mvwaddch (chanwin, 11, 70, mapchar(ACS_LRCORNER));

		for (i = 0; i < 62; i++)
			mvwaddch (chanwin, 11, 8 + i, mapchar(ACS_HLINE));

		wattrset (chanwin, make_attr (A_NORMAL, GREEN, BLACK));

		mvwprintw (chanwin, 8, 17, "%-10d", chan.ch_txcount);
		mvwprintw (chanwin, 9, 17, "%-10d", chan.ch_rxcount);

		{
			int msigs=6;
			int   mbits[] = { MS_RTS, MS_CTS, MS_DSR, MS_DCD, MS_DTR, MS_RI };
			char *mhstr[] = { "X",    "X",    "X",    "X",    "X",    "X"   };
			char *mlstr[] = { "_",    "_",    "_",    "_",    "_",    "_"   };
			int   mpos[]  = { 30,     35,     40,     45,     50,     55    };
			int sig=0;

			for(sig = 0; sig < msigs; sig++)
			{
				if (chan.ch_s_mstat & mbits[sig])
				{
					wattrset (chanwin, make_attr (A_STANDOUT, WHITE, GREEN));
					mvwprintw (chanwin, 9, mpos[sig], mhstr[sig]);
				}
				else
				{
					wattrset (chanwin, make_attr (A_NORMAL, GREEN, BLACK));
					mvwprintw (chanwin, 9, mpos[sig], mlstr[sig]);
				}
			}
		}
		{
			int events=2;
			int   ebits[] = { EV_OPALL, EV_IPALL };
			char *ehstr[] = { "X",      "X"      };
			char *elstr[] = { "_",      "_"      };
			int   epos[]  = { 59,       64       };
			int ev=0;

			for(ev=0; ev<events; ev++)
			{
				if (chan.ch_s_estat & ebits[ev])
				{
					wattrset (chanwin, make_attr (A_STANDOUT, WHITE, GREEN));
					mvwprintw (chanwin, 9, epos[ev], ehstr[ev]);
				}
				else
				{
					wattrset (chanwin, make_attr (A_NORMAL, GREEN, BLACK));
					mvwprintw (chanwin, 9, epos[ev], elstr[ev]);
				}
			}
		}

		wattrset (chanwin, make_attr (A_BOLD, WHITE, BLACK));
		mvwaddstr (chanwin, 14, 1, "  Input Modes ");
		wattrset (chanwin, make_attr (A_NORMAL, WHITE, BLACK));
		wprintw (chanwin, "                                                           ");
		wmove (chanwin, 14, 15);

		if (chan.ch_s_iflag & IF_IGNBRK)
			wprintw (chanwin, ":IGNBRK");
		if (chan.ch_s_iflag & IF_BRKINT)
			wprintw (chanwin, ":BRKINT");
		if (chan.ch_s_iflag & IF_IGNPAR)
			wprintw (chanwin, ":IGNPAR");
		if (chan.ch_s_iflag & IF_PARMRK)
			wprintw (chanwin, ":PARMRK");
		if (chan.ch_s_iflag & IF_INPCK)
			wprintw (chanwin, ":INPCK");
		if (chan.ch_s_iflag & IF_ISTRIP)
			wprintw (chanwin, ":ISTRIP");
		if (chan.ch_s_iflag & IF_IXON)
			wprintw (chanwin, ":IXON");
		if (chan.ch_s_iflag & IF_IXANY)
			wprintw (chanwin, ":IXANY");
		if (chan.ch_s_iflag & IF_IXOFF)
			wprintw (chanwin, ":IXOFF");
		if (chan.ch_s_xflag & XF_XIXON)
			wprintw (chanwin, ":IXONA");
		if (chan.ch_s_xflag & XF_XTOSS)
			wprintw (chanwin, ":ITOSS");
		if (chan.ch_s_iflag & IF_DOSMODE)
			wprintw (chanwin, ":DOSMODE");

		wprintw (chanwin, ":");
		wattrset (chanwin, make_attr (A_BOLD, WHITE, BLACK));
		mvwprintw (chanwin, 15, 1, " Output Modes ");
		wattrset (chanwin, make_attr (A_NORMAL, WHITE, BLACK));
		wprintw (chanwin, "                                                           ");
		wmove (chanwin, 15, 15);

		if (chan.ch_s_xflag & XF_XCASE)
			wprintw (chanwin, ":XCASE");
		if (chan.ch_s_oflag & OF_OLCUC)
			wprintw (chanwin, ":OLCUC");
		if (chan.ch_s_oflag & OF_ONLCR)
			wprintw (chanwin, ":ONLCR");
		if (chan.ch_s_oflag & OF_OCRNL)
			wprintw (chanwin, ":OCRNL");
		if (chan.ch_s_oflag & OF_ONOCR)
			wprintw (chanwin, ":ONOCR");
		if (chan.ch_s_oflag & OF_ONLRET)
			wprintw (chanwin, ":ONLRET");

		/* TODO -- tab expansion / TABDLY interpretation */

		wprintw (chanwin, ":");
		wattrset (chanwin, make_attr (A_BOLD, WHITE, BLACK));
		mvwprintw (chanwin, 16, 1, "Control Modes ");
		wattrset (chanwin, make_attr (A_NORMAL, WHITE, BLACK));
		/*
		 * clear the field, then write the new one
		 */
		wprintw (chanwin, "                                                              ");
		wmove (chanwin, 16, 15);

		if (chan.ch_open) {
/* Jira RP-77: In early stages of a port open, ch_open is set before ch_s_brate
 * is initialized, which, undetected, causes an arithmetic exception here.
 */
                	if (chan.ch_s_brate)
                		wprintw (chanwin, ":%d Baud", PDIVIDEND / chan.ch_s_brate);
			else
                		wprintw (chanwin, ":?? Baud");

			switch (chan.ch_s_cflag & CF_CSIZE)
			{
			case CF_CS5:
				wprintw (chanwin, ":5 Char Bits");
				break;
			case CF_CS6:
				wprintw (chanwin, ":6 Char Bits");
				break;
			case CF_CS7:
				wprintw (chanwin, ":7 Char Bits");
				break;
			case CF_CS8:
				wprintw (chanwin, ":8 Char Bits");
				break;
			default:
				wprintw (chanwin, ":No Char Bits");
				break;
			}

			if (chan.ch_s_cflag & CF_CSTOPB)
				wprintw (chanwin, ":2 Stop Bits");
			else
				wprintw (chanwin, ":1 Stop Bits");

			if (chan.ch_s_cflag & CF_PARENB)
			{
				if (chan.ch_s_xflag & XF_XPAR)
				{
					if (chan.ch_s_cflag & CF_PARODD)
						wprintw (chanwin, ":Parity Odd");
					else
						wprintw (chanwin, ":Parity Even");
				}
				else
				{
					if (chan.ch_s_cflag & CF_PARODD)
						wprintw (chanwin, ":Parity Space");
					else
						wprintw (chanwin, ":Parity Mark");
				}
			}
			else
			{
				wprintw (chanwin, ":No Parity");
			}
		}
		else {
                	wprintw (chanwin, ":");
		}

		wattrset (GetWin(MainWin), make_attr (A_NORMAL, WHITE, BLUE));

		commandline (clbuf, helpstr, "ESC=Quit", lrudstr,
		             "T=LoopBack", "D=DataMonitor", "^P=Print", NULL);
		mvwprintw (GetWin(MainWin), KEY_LINE, 0, clbuf);

		wattroff (GetWin(MainWin), make_attr (A_NORMAL, WHITE, BLUE));
		wrefresh (GetWin(MainWin));
		wrefresh (chanwin);

		change_term (0, TIMEOUT);

		option = EOF;

		tv.tv_sec = 0;  tv.tv_usec = 500000;
		rc = select( max_fd + 1, &rfds, NULL, NULL, &tv );

		if (rc < 0)
		{
			fprintf (stderr, "FATAL ERROR: select failure.\n");
			EndCurses (-13);
			/* FIXME: This code will not be executed as 
			   EndCurses() calls exit(). */
			exit (-2);
		}
		else if (rc > 0)
		{
			if (FD_ISSET(0, &rfds))
			{
				option = getch();
			}

		}
		else
		{
			scr_opt = 0;
		}

		/*
		 * If the user hasn't selected anything keep doing the 
		 * original screen. 
		 */

		switch (option)
		{
		case EOF:
			break;

		case '':
			scr_opt = 0;
			refresh_screen ();
			break;

#ifdef KEY_LEFT
		case KEY_LEFT:
#endif
		case 'H':
		case 'h':

			port--;
			if (port < 0)
				port = unit->nports - 1;

			scr_opt = 2;
			break;

#ifdef KEY_RIGHT
		case KEY_RIGHT:
#endif
		case 'L':
		case 'l':

			port++;
			if (port >= (int) unit->nports)
				port = 0;

			scr_opt = 2;
			break;

#ifdef KEY_UP
		case KEY_UP:
#endif
		case 'K':
		case 'k':
			{
				int curr_unit = unit->unit_number;
				do {
					curr_unit--;
					if (curr_unit < 0)
						curr_unit = num_devices - 1;
				}
				while (device_info[curr_unit].status != UP);

				unit = &device_info[curr_unit];

				if (port >= (int) unit->nports)
					port = unit->nports - 1;
			}

			scr_opt = 1;
			break;

#ifdef KEY_DOWN
		case KEY_DOWN:
#endif
		case 'J':
		case 'j':
			{
				int curr_unit = unit->unit_number;
				do {
					if (curr_unit < num_devices - 1)
						curr_unit++;
					else
						curr_unit = 0;
				}
				while (device_info[curr_unit].status != UP);

				unit = &device_info[curr_unit];

				if (port >= (int) unit->nports)
					port = unit->nports - 1;

			}

			scr_opt = 1;
			break;

		case 'q':
		case 'Q':
		case ESC:
			hide_panel (GetPan(ChanWin));
			erase_win (ChanWin);
			update_panels ();
			doupdate ();
			scr_opt = 0;
			break;

		case 'T':
		case 't':
			scr_opt = 0;

			hide_panel (GetPan(ChanWin));
			update_panels ();
			doupdate ();

			handle_loopback(unit, &node, &chan, port);

			change_term (0, TIMEOUT);

			show_panel (GetPan(ChanWin));
			update_panels ();
			doupdate ();
			wrefresh (chanwin);
			break;

		case 'D':
		case 'd':
			scr_opt = 0;

			{
				int invoke_one = 1;

				while (invoke_one)
				{
					if (d_invokes_capture)
					{
						invoke_one = handle_scope (unit, &node,  &chan, port);
					}
					else
					{
						invoke_one = handle_exam (unit, &node, port);
					}

					if (invoke_one)
						d_invokes_capture = 1 - d_invokes_capture;
				}
			}

			touchwin (chanwin);
			wrefresh (chanwin);
			update_panels ();
			doupdate ();
			break;


#ifdef KEY_PRINT
		case KEY_PRINT:
#endif
		case '':
			scr_opt = 0;

			screen_save (ChanWin, logfile);
			touchwin (chanwin);
			wrefresh (chanwin);
			update_panels ();
			doupdate ();
			break;

		case KEY_F (1):		   /*  Help info  */
		case '?':
			scr_opt = 0;
			info_screen (dpa_info2, dpa_info2_len, NULL);
			update_panels ();
			doupdate ();
			break;

		default:
			scr_opt = 0;
			mvwprintw (chanwin, 16, 60, "Invalid key");
			wrefresh (chanwin);
			sleep (1);
			mvwprintw (chanwin, 16, 60, "           ");
			wrefresh (chanwin);
			break;
		}						   /* End Case */
	}							   /* End While */
}
Exemplo n.º 11
0
void 
handle_loopback (struct deviceinfo *unit, struct digi_node *node, struct digi_chan *chan, int port)
{
	char full_line[81];

	int i = 0, option = EOF;

	struct termios sv_tios;
	char test_data[TBUFSIZ + 1];
	char read_data[TBUFSIZ + 1];
	char string[200], ttyname[200];

	int r = 3;
	int rwfd;

	WINDOW *lbwin = GetWin(LBWin);

#define TITLE_LINE  1
#define DESC_LINE   2
#define DESC2_LINE  3
#define SEP_LINE    4
#define FIRST_DATA  5
#define SEP2_LINE   15
#define RESULT_LINE 16

	show_panel (GetPan(LBWin));
	update_panels ();
	doupdate ();

	next_result = 0;
	test_cases = 0;
	test_passes = 0;

	if (DPAGetPortName(unit, node, chan, port, ttyname) == NULL) {
		ttyname[0] ='\0';
	}

	while (option == EOF)
	{
		erase_win (LBWin);
		wattrset (lbwin, make_attr (A_BOLD, WHITE, BLUE));
		mvwprintw (lbwin, TITLE_LINE,  1, "%-*.*s", 76, 76, " ");
		mvwprintw (lbwin, RESULT_LINE, 1, "%-*.*s", 76, 76, " ");
		mvwprintw (lbwin, TITLE_LINE, 32, " Loop Back Test ");
		sprintf (full_line, "Tests Executed: %-12d Passed: %-12d Failed: %d",
		         test_cases, test_passes, test_cases - test_passes);
		mvwprintw (lbwin, RESULT_LINE,
		           center(LBWin, strlen(full_line)), full_line);

		sprintf (clbuf, "Unit IP Address: %s       Port #: %d            Name: %s",
		         unit->host, port + 1, ttyname);
		i = strlen (clbuf);
		mvwprintw (GetWin(LBWin), DESC_LINE, 1, "%*s",
		           GetWidth(LBWin) - 2, " ");

		mvwprintw (GetWin(LBWin), DESC2_LINE, 1, "%*s",
		           GetWidth(LBWin) - 2, " ");

		mvwprintw (lbwin, DESC2_LINE, 2, clbuf);

		mvwprintw (lbwin, DESC_LINE, 2, "Device Description: %-*.*s",
		           GetWidth(LBWin) - 2 - 2 - 2 - 20,
		           GetWidth(LBWin) - 2 - 2 - 2 - 20,
		           node->nd_ps_desc);

		if (!vanilla)
			wattrset (lbwin, make_attr (A_ALTCHARSET, CYAN, BLACK));
		else
			wattrset (lbwin, make_attr (A_NORMAL, CYAN, BLACK));

		wmove (lbwin, SEP_LINE, 1);
		for (i = 0; i < 77; i++)
			waddch (lbwin, mapchar(ACS_HLINE));
		mvwaddch (lbwin, SEP_LINE, 0, mapchar(ACS_LTEE));
		mvwaddch (lbwin, SEP_LINE, 77, mapchar(ACS_RTEE));

		wmove (lbwin, SEP2_LINE, 1);
		for (i = 0; i < 77; i++)
			waddch (lbwin, mapchar(ACS_HLINE));
		mvwaddch (lbwin, SEP2_LINE, 0, mapchar(ACS_LTEE));
		mvwaddch (lbwin, SEP2_LINE, 77, mapchar(ACS_RTEE));

		wattrset (lbwin, make_attr (A_NORMAL, WHITE, BLACK));

		wrefresh (lbwin);

		wattrset (GetWin(MainWin), make_attr (A_NORMAL, WHITE, BLUE));
		commandline (clbuf, "Press ANY key to Halt the test", NULL);
		mvwprintw (GetWin(MainWin), KEY_LINE, 0, clbuf);
		wattroff (GetWin(MainWin), make_attr (A_NORMAL, WHITE, BLUE));
		wrefresh (GetWin(MainWin));

		change_term (0, 10);

		option = EOF;
		r = 5;

		if (chan->ch_open) {
			mvwprintw (lbwin, r++, 2, "***** Port is Busy.");
                        wrefresh(lbwin);
			test_cases++;
			sleep(1);
			goto user_input;
		}

		for (i = 0; i < 256; i++) {
			test_data[i] = (char) i;
		}

		test_data[TBUFSIZ]='\0';

		/* Get port name.  Can't run the test without it. */
		if (DPAGetPortName(unit, node, chan, port, ttyname) == NULL) {
                        mvwprintw (lbwin, r++, 2,
                        "***** Loop Back Test Failure. Port has no known tty name");
			test_cases++;
                        wrefresh (lbwin);
			sleep(1);
			goto user_input;
                }

		sprintf(string, "/dev/%s", ttyname);

		if( (rwfd = tty_open(string, &sv_tios )) < 0 ) {
			test_cases++;
			goto user_input;
		}

		tcflush(rwfd, TCIOFLUSH);

                if ((i = test_send (test_data, TBUFSIZ, rwfd)) != 0)
                {
                        mvwprintw (lbwin, r++, 2,
                        "***** Loop Back Test Failure=%d, Sending %d Bytes", i, TBUFSIZ);
                        wrefresh (lbwin);
                        tty_close (rwfd, &sv_tios);
                        test_cases++;
			goto user_input;
                }

                mvwprintw (lbwin, r++, 2, "Loop Back: %d Bytes Sent.", TBUFSIZ);
                wrefresh (lbwin);
                mvwprintw (lbwin, r++, 2, "Loop Back: Receiving %d Bytes.", TBUFSIZ);
                wrefresh (lbwin);

                if ((i = test_recv (read_data, TBUFSIZ, 5, rwfd)) != TBUFSIZ)
                {
                        mvwprintw (lbwin, r++, 2,
                                "***** Loop Back Failure=%d Receiving %d bytes.", i, TBUFSIZ);
                        wrefresh (lbwin);  
                        tty_close (rwfd, &sv_tios);
                        test_cases++;
			goto user_input;
                }


                /* Reset termios as before and close channel */
                tty_close (rwfd, &sv_tios);

                mvwprintw (lbwin, r++, 2, "Loop Back: Verifying %d bytes.", TBUFSIZ);
                wrefresh (lbwin);

                if (memcmp (test_data, read_data, TBUFSIZ))
                {
                        mvwprintw (lbwin, r++, 2,
                                "***** Loop Back Failure Verifying %d Bytes.", TBUFSIZ);
                        mvwprintw (lbwin, r++, 2, "***** Data Incorrectly Transferred.");
                        wrefresh (lbwin);
                        test_cases++;
			goto user_input;
                }
                else
                {
                        mvwprintw (lbwin, r++, 2, "Loop Back: Test Passed.");
                        wrefresh (lbwin);
                        test_cases++;
                        test_passes++;
                }


user_input:

		option = getch();


		/*
		 * If the user hasn't selected anything, loop.
		 * Otherwise, break.
		 */

		switch (option)
		{
		case EOF:
			break;

		case '':
			refresh_screen ();
			option = EOF;
			break;

#ifdef KEY_PRINT
		case KEY_PRINT:
#endif
		case '':
			screen_save (LBWin, logfile);
			touchwin (lbwin);
			wrefresh (lbwin);
			update_panels ();
			doupdate ();
			option = EOF;
			break;

		default:
			break;
		}						   /* End Case */
	}							   /* End While */

	hide_panel (GetPan(LBWin));
	update_panels ();
	doupdate ();
	return;
}
Exemplo n.º 12
0
/*alphabeta pruning,  player.c's core, accurate description is inside the paper*/
static int  alphabeta(NODE **T, int depth, int a, int b, int maximizingPlayer) {


	if (depth == 0 || GetWin(*T)) { //if leaf...

		((*T)->player == MAX) ? ((*T)->value = -GetWin(*T)) : ((*T)->value = GetWin(*T)); //I assign a value to the node, -1 if opponent's win, +1 if AI win
		return (*T)->value;
	}

	if (maximizingPlayer == MAX) { //only if minimizing node

		NODE *tmp;
		unsigned short *v = NULL;
		unsigned int x, count;


		if (!AllocateChildren(T, depth, 0, 0, MIN, NULL)) { //first I allocate 1 child without giving any value, I do this to keep everything in one for-cycle

			printf("\nError");
			exit(0);
		}

		tmp = (*T)->leftchild;
		v = copyv((*T)->transboard); //I take the node's board and...
		for (x = 0, count = 0; x < M*N; x++) { //...I check every possibile move from that certain board state



			if (v[x] != 0) //if it's already occupied it's not an acceptable move so I go on
				continue;

			else {
				v[x] = maximizingPlayer; //I temporarily make a move on the free box (then it'll become empty once again)
				if (count == 0) { //means that I'm working with the first child, hence its address comes from the father and not from the brothers
					tmp->i = x / N; //saving the current move in the node
					tmp->j = x - N*(x / N);
					tmp->transboard = copyv(v); //and also the board
					count++; //increasing count in order not to belong to this case (first child) again
				}

				else { //if I already handled the first child

					if (!AllocateChildren(T, depth, x / N, x - N*(x / N), MIN, copyv(v))) { //I allocate the space for the brothers and their current values (board, i,j etc)

						printf("\nError");
						exit(0);
					}

					tmp = tmp->rightbrothers;
					count++;
				}

				tmp->value = Max(tmp->value, alphabeta(&tmp, depth - 1, a, b, maximizingPlayer == 1 ? 2 : 1)); //recursive call that goes to the other part (minimizing part) of the function (if father is maximizing then the children are minimizing because between father and children the player changes) 

				a = Max(a, tmp->value); //a is the best possible move for player1, so I have to choose the one with highest value
				v[x] = 0;
				if (a >= b) //pruning: if I see that the best possible move for player 1 has the same value of the best possibile move of player 2 I don't need to waste time to find another move nor to allocate more brothers
					break;



			}


		}

		return a;
	}




	else if (maximizingPlayer == MIN) { //same as above, just we're working with minimizing nodes

		NODE *tmp;
		unsigned short *v = NULL;
		unsigned int x, count;


		if (!AllocateChildren(T, depth, 0, 0, MAX, NULL)) {

			printf("\nError");
			exit(0);
		}

		tmp = (*T)->leftchild;
		v = copyv((*T)->transboard);
		for (x = 0, count = 0; x < M*N; x++) { //for every possible move...



			if (v[x] != 0)
				continue;

			else {
				v[x] = maximizingPlayer;
				if (count == 0) {
					tmp->i = x / N;
					tmp->j = x - N*(x / N);
					tmp->transboard = copyv(v);
					count++;
				}

				else {

					if (!AllocateChildren(T, depth, x / N, x - N*(x / N), MAX, copyv(v))) {

						printf("\nError");
						exit(0);
					}

					tmp = tmp->rightbrothers;
					count++;
				}

				tmp->value = Min(tmp->value, alphabeta(&tmp, depth - 1, a, b, maximizingPlayer == 1 ? 2 : 1)); //again, here the recursive call inverts minimizing with maximizing

				b = Min(b, tmp->value); //b instead chooses the minimum value because it has to pick the move that helps player1 less (=best move for player2 = optimal strategy)
				v[x] = 0;
				if (a >= b) //as before
					break;



			}


		}

		return b;
	}


}