⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 birdcmds.c

📁 一个C语言写的读入位置跟踪器数据的源程序
💻 C
📖 第 1 页 / 共 5 页
字号:
    {
	case 0:
	    rate_cdata = 'Q';
	    break;

	case 1:
	    rate_cdata = 'R';
	    break;

	case 2:
	    rate_cdata = 'S';
	    break;

	case 3:
	    rate_cdata = 'T';
	    break;

	case ESC_SEL:
	    return(ESC_SEL);
    }

    /*
	Send of the 1 char
    */
    if (send_serial_cmd(&rate_cdata,1) != 1)
	return(FALSE);

    printf("Report Rate Sent to Bird\n\r");
    hitkeycontinue();

    return(TRUE);
}

/*
    bird_sleepwake  -   Implements the Sleep ('G') or Wake ('F') command

    Prototype in:       birdcmds.h

    Parameters Passed:  void

    Return Value:       TRUE if successful
			FALSE if unsuccessfull
			ESC_SEL if user selects ESC

    Remarks:            prompts the user for Sleep or Wake and send the
			corresponding command to the Bird
*/
int bird_sleepwake()
{
    static char * sleepwake_menuptr[] =
				 {"Enter Selection:",
				  "Sleep",
				  "FBB Run/Wake"};

    unsigned char sleepwake_cdata;

    /*
	Get the User selection
    */
    switch (sendmenu(sleepwake_menuptr,2))
    {
	case 0:
	    sleepwake_cdata = 'G';
	    break;

	case 1:
	    sleepwake_cdata = 'F';
	    break;

	case ESC_SEL:
	    return(ESC_SEL);
    }

    /*
	Send the command
    */
    if (send_serial_cmd(&sleepwake_cdata,1) != 1)
	return(FALSE);

    printf("Sent the Sleep/Wake Command to the Bird\n\r");
    return(TRUE);
}

/*
    bird_mousebuttons   -   Implements the M and N mouse button commands

    Prototype in:       birdcmds.h

    Parameters Passed:  void

    Return Value:       0, if buttonmode if off
			1, if buttonmode is on, 'M'
			ESC_SEL, if the user selected ESC_SEL

    Remarks:            sends down the button mode to the Bird and allows
			the user to view the Button state.
*/
int bird_mousebuttons()
{
    static unsigned char button_cdata[] = {'M',0};  /* button command */
    unsigned buttonchar;                /* buffer for button value */
    short buttonmode;
    short tempchar;

    /*
	Ask if they want the Button Commands to aways be sent
    */
    buttonmode = 0;     /* assume button mode off */
    if (askyesno("Do you want the Button Byte added to the End of Data Stream"))
	buttonmode = 1;

    button_cdata[1] = (unsigned char) buttonmode;

    /*
	Send Button Command
    */
    if (send_serial_cmd(button_cdata,2) != 2)   /* send the button cmd */
	return(ESC_SEL);                        /* can't return FALSE */

    /*
	See if the User wants to display the button now
	if in 'N' mode
    */
    if (askyesno("\n\rDisplay Button Value Now "))
    {
	printf("\n\rHit a key to stop printing the button value\n\r");

	while (!ckkbhit())
	{
	    /*
		Send Read Button Command
	    */
	    if (send_serial_cmd((unsigned char *)"N",1) != 1)
	    {
		printf("Could not send Button Read Command\n\r");
		hitkeycontinue();
		return(buttonmode);
	    }

	    /*
		Get button byte
	    */
	    if ((tempchar = waitforchar()) < 0)
	    {
		printf("Could not read button byte\n\r");
		hitkeycontinue();
		return(buttonmode);
	    }

	    buttonchar = tempchar;
	    printf("Button = %d\n\r",buttonchar);
	}
	clearkey();
    }

    return(buttonmode);
}

/*
    bird_xonxoff        - Implements the XON / XOFF commands

    Prototype in:       birdcmds.h

    Parameters Passed:  void

    Return Value:       TRUE if sent XON or XOFF
			FALSE if could not send the command
			ESC_SEL if the User selected ESC

    Remarks:            sends down the XON or XOFF command to the BIRD
*/
int bird_xonxoff()
{
    unsigned char birdflowcmd;
    static char * xonxoffmenu[] = {"Select Flow Command:",
				   "XON",
				   "XOFF"};
    /*
	Ask the user which they want, XON or XOFF
    */
    switch (sendmenu(xonxoffmenu,2))
    {
	case 0:
	     birdflowcmd = XON;
	     break;

	case 1:
	     birdflowcmd = XOFF;
	     break;

	case ESC_SEL:
	     return(ESC_SEL);
    }

    /*
	Send the command to the Bird
    */
    if (send_serial_cmd(&birdflowcmd,1) != 1)
       return(FALSE);

    printf("Sent the XON/XOFF command to the Bird\n\r");

    hitkeycontinue();

    return(TRUE);
}
/*
    bird_changevalue    - Implements the Change Value Commmand

    Prototype in:       birdcmds.h

    Parameters Passed:  void

    Return Value:       TRUE if Command was sent to the Bird
			FALSE if could not send the command
			ESC_SEL if the User selected ESC

    Remarks:            Routine queries the user for the PARAMETER to change
			and sends down the new information to the Bird
*/
int bird_changevalue()
{
    short temprs232tofbbaddr;
    short answer;
    short menusel;
    unsigned short i,j;
    short invalid;
    short cmdsize = 0;
    unsigned short * dcfiltervalue;
    char ** dcfiltermsg;
    float floatvalue;
    char floatstring[80];
    static unsigned char birdchangevaluecmd[] = {'P',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    static char * changevaluemenu[] = {"Select Parameter to Change:",
				       "Previous Menu",
				       "Maximum Range Scaling",
				       "Filter ON/OFF Status",
				       "Filter Const - Alpha_Min",
				       "Bird Measurement Rate",
				       "Disable/Enable Data Ready Output",
				       "Change Data Ready Character",
				       "Set ON ERROR Mask",
				       "Filter Const - Vm",
				       "Filter Const - Alpha_Max",
				       "Block/Allow Sudden Output Changes",
				       "XYZ Reference Frame",
				       "Set FBB Host Delay",
				       "Set FBB Configuration",
				       "Set FBB ARMed",
				       "Enable/Disable Group Data Mode",
				       "FBB Auto Config - 1 Trans/N Rec"};

    static char * rangemenu[] = {"Select Scaling Range:",
				 "36 inch range",
				 "72 inch range"};

    static char * errormaskmenu[] = {"Select Error Mask Mode:",
				     "Fatal Errors are Blinked Forever",
				     "Fatal Errors are Blinked Once",
				     "Fatal and Warning Errors are NOT Blinked"};

    static char * configmodemenu[] = {"FBB Configuration Mode:",
				      "Standalone",
				      "1 Transmitter, N Receivers"};

    static char * bird_dcfiltermsg[] = {"0 to 12 inches",
				   "12 to 15 inches",
				   "15 to 19 inches",
				   "19 to 24 inches",
				   "24 to 30 inches",
				   "30 to 38 inches",
				   "38+ inches"};
    static unsigned short bird_dcfiltervalue[] = {2,6,26,99,396,1615,6460};

    static char * erc_dcfiltermsg[] = {"0 to 35 inches",
				   "35 to 49 inches",
				   "49 to 63 inches",
				   "63 to 79 inches",
				   "79 to 96 inches",
				   "96 to 116 inches",
				   "116+ inches"};

    static unsigned short erc_dcfiltervalue[] = {2,2,2,45,90,180,360};

    static unsigned short fbbdevices = 0;

    static unsigned short fbbdependents = 0;

    /*
	Store the rs232tofbbaddr
    */
    temprs232tofbbaddr = rs232tofbbaddr;

    /*
	Initialize the Parameter Bytes
    */
    birdchangevaluecmd[2] = 0;
    birdchangevaluecmd[3] = 0;

    /*
	Setup to use either the 6DFOB parameters or the ERC parameters
    */
    if (posk == POSK144)
    {
       dcfiltervalue = erc_dcfiltervalue;
       dcfiltermsg = erc_dcfiltermsg;
    }
    else
    {
       dcfiltervalue = bird_dcfiltervalue;
       dcfiltermsg = bird_dcfiltermsg;
    }

    /*
	Get the Number of FBB Addrs
    */
    if (getaddrmode() == 0)
	return(FALSE);

    /*
	Send the Menu to the Screen and take appropriate action
    */
    menusel = sendmenu(changevaluemenu,17);
    switch (menusel)
    {
	case ESC_SEL:
	case 0:     /* return */
	     return(ESC_SEL);

	case 1:     /* Range Scale */
	     /*
		 Set the Parameter number and command size
	     */
	     birdchangevaluecmd[1] = 3;
	     cmdsize = 4;

	     /*
		 Now fill the command with the Scale, 0 for 36" or 1 for 72"
	     */
	     switch(sendmenu(rangemenu,2))
	     {
		case 0: /* 36" */
		    birdchangevaluecmd[2] = 0x00;
		    posk = POSK36;
		    break;
		case 1: /* 72" */
		    birdchangevaluecmd[2] = 0x01;
		    posk = POSK72;
		    break;
		case ESC_SEL:
		    return(ESC_SEL);
	     }
	     break;

	case 2:    /* Filter ON/OFF Status */
	     /*
		 Set the Parameter number and the command size
	     */
	     birdchangevaluecmd[1] = 4;
	     cmdsize = 4;

	     /*
		 Ask the user to 'fill in the bits'...filter ON/OFF selection
	     */
	     if ((answer = askyesno("\n\rDo you want the AC Narrow Notch filter OFF")) == TRUE)
		 birdchangevaluecmd[2] = 4;
	     else if (answer == ESC_SEL)
		 return(ESC_SEL);


	     if ((answer = askyesno("\n\rDo you want the AC Wide Notch OFF")) == TRUE)
		birdchangevaluecmd[2] += 2;
	     else if (answer == ESC_SEL)
		 return(ESC_SEL);

	     if ((answer = askyesno("\n\rDo you want the DC filter OFF")) == TRUE)
		birdchangevaluecmd[2] += 1;
	     else if (answer == ESC_SEL)
		 return(ESC_SEL);

	     break;

	case 3:    /* Filter Constant Table - Alpha Min */
	     /*
		 Set the Parameter number and the command size
	     */
	     birdchangevaluecmd[1] = 5;
	     cmdsize = 16;         

	     /*
		 Set all 7 table entries
	     */
	     for (i=0; i < 7; i++)
	     {
		 /*
		     Get the Filter Value from the User..with validation
		     0 to 0.99996
		 */
		 do
		 {
		     invalid = FALSE;
		     printf ("For range %s, \n\rInput the New Filter Value (0 to 0.99996): ",
			  dcfiltermsg[i]);
		     if (getfloatstring(floatstring) != NULL)
			 floatvalue = atof(floatstring);
		     else
			 return(ESC_SEL);

		     /*
			 Validate the number
		     */
		     if ((floatvalue < 0.0) || (floatvalue >= 1.00))
		     {
			 invalid = TRUE;
			 printf("** ERROR ** invalid value\n\r");
		     }
		 }
		 while(invalid);

		 /*
		    Convert float to word 0 to 32767 and store in the command
		 */
		 j =  (unsigned)(floatvalue * FTW);
		 *(unsigned char *)&birdchangevaluecmd[2 + (i*2)] =
		    j & 0xff;
		 *(unsigned char *)&birdchangevaluecmd[2 + (i*2) + 1] =
		    ((j & 0xff00) >> 8);

	     }
	     break;

	case 4:    /* Measurement Rate */
	     /*
		Get the CPU crstal freq
	     */
	     if (!getcrystalfreq())
		 return(FALSE);

	     /*
		 Set the Parameter number and the command size
	     */
	     birdchangevaluecmd[1] = 6;
	     cmdsize = 4;

	     printf("**NOTE** do not reduce measurement frequency if the Bird\n\r        is synchronized to the CRT\n\r");

	     /*
		 Get the Measurement frequency from the User
	     */
	     do
	     {
		 printf ("Input the desired measurement frequency (14 to 144 Hz): ");

		 invalid = FALSE;
		 if (getfloatstring(floatstring) != NULL)
		     floatvalue = atof(floatstring);
		 else
		     return(ESC_SEL);
		 /*
		     Validate the number
		 */
		 if ((floatvalue < 14.0) || (floatvalue > 144.0))
		 {
		     invalid = TRUE;
		     printf("** ERROR ** invalid value\n\r");
		 }
	     }
	     while(invalid);

	     /*
		convert to transmitter time counts
	     */
	     i = (unsigned)(((crystalfreq/8.0)*1000.0)*
			  (((1000.0/floatvalue)-0.3)/4.0));

	     *(unsigned char *)&birdchangevaluecmd[2] = (unsigned char) (i & 0xff);
	     *(unsigned char *)&birdchangevaluecmd[3] = (unsigned char) ((i & 0xff00) >> 8);
	     break;

	case 5:    /* Disable/Enable Data Ready Output */

	     /*
		 Set the Parameter number and the command size
	     */
	     birdchangevaluecmd[1] = 8;
	     cmdsize = 3;

	     /*
		 Ask the User if they want to Enable the Data Output
		 Character
	     */
	     birdchangevaluecmd[2] = FALSE;
	     if ((answer = askyesno("Do you want Data Ready Output enabled")) == YES)
		  birdchangevaluecmd[2] = TRUE;
	     else if (answer == ESC_SEL)
		  return(ESC_SEL);

	     break;

	case 6:    /* Change Data Ready Character */

	     /*
		 Set the Parameter number and the command size
	     */
	     birdchangevaluecmd[1] = 9;
	     cmdsize = 3;

	     /*
		 Ask the User for the Data Ready Character to Send
	     */
	     do
	     {
		 invalid = FALSE;
		 printf("\n\rEnter the desired data ready character in decimal (0-255): ");
		 if (((answer = getnumber()) < 0) || (answer > 255))
		 {
		    invalid = TRUE;
		    printf("\n\r** ERROR ** invalid entry, please try again\n\r");
		    hitkeycontinue();
		 }

		 birdchangevaluecmd[2] = (unsigned char) answer;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -