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

📄 rstofbb.c

📁 一个C语言写的读入位置跟踪器数据的源程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************
*****************************************************************************

    rstofbb.c       RS232 to FBB C Commands

    written for:    Ascension Technology Corporation
		    PO Box 527
		    Burlington, Vermont  05402

		    802-655-7879

    written by:     Jeff Finkelstein

    Modification History:
       4/22/92   jf.. POSK36 changed to posk, posk declared external
       6/16/92   jf.. modified angle output format to 0.1 degree resol.
       8/17/92   jf.. modified for Group Data Mode
       10/3/92   jf.. fixed bug in POS/MATRIX display
       10/12/92  jf.. fixed bug in Group Data Mode Display of Info
       1/27/92   jf.. integrated with CBIRD
       7/7/93    jf.. updated to allow the display of button data from
		      multiple units in both the RS232 PASS through mode
		      and Group Mode
       10/20/93  jf.. modified to use GETTICKS

	   <<<< Copyright 1992 Ascension Technology Corporation >>>>
*****************************************************************************
****************************************************************************/

#include <stdio.h>          /* general I/O */
#include "asctech.h"        /* Ascension Technology definitions */
#include "compiler.h"       /* Compiler Specific Header */
#include "menu.h"           /* Ascension Technology Menu Routines */
#include "serial.h"         /* Ascension Technology Serial Port Routines */
#include "cmdutil.h"
#include "pctimer.h"
#include "rstofbb.h"

/*
    Define Externals
*/
extern float posk;
extern unsigned char fbbgroupdataflg;
extern FILE * datafilestream;
extern short flocksize;
extern short numfbbaddrs;
extern short numfbbrcvrs;
extern short buttonvalue;
extern unsigned char fbbsystemstatus[];


/*
    Define Globals
*/
unsigned char displayliststartaddr = 1;
unsigned char displayliststopaddr = 0;
unsigned char displaymultidataflg = FALSE;
unsigned char rs232tofbbstartaddr = 99; /* start with an illegal address */
unsigned char screencleared = FALSE;
unsigned char multibuttonvalue[30];     /* holds the buttonvalue for each unit */



/*
    rs232tofbbcmd       RS232 to FBB Command

    Prototype in:       rstofbb.h

    Parameters Passed:  void

    Return Value:       TRUE if command sent OK
			FALSE if command could not be sent
			ESC_SEL if the user selected ESC

    Remarks:
*/
int rs232tofbbcmd()
{
    int answer;
    printf ("\n\rIf enabled, the RS232 TO FBB Command will be used for all commands other\n\rthen the data display commands...\n\r");

    if ((answer = askyesno("\n\rDo you want to enable the RS232 TO FBB Command")) == ESC_SEL)
    {
	return (ESC_SEL);
    }
    else
    {
	/*
	    Shut off the Command if the user answer NO
	*/
	if (answer == FALSE)
	{
	    rs232tofbbaddr = 0;     /* The Zero Address indicates not used */
	    return (FALSE);
	}
    }

    /*
	Get the Destination Addresses
    */
    getfbbdestaddress(&rs232tofbbstartaddr,NULL);

    /*
	Store for serial communications
    */
    rs232tofbbaddr = rs232tofbbstartaddr;

    return(TRUE);
}

/*
    getmultibirddata    Get Data from Multiple Birds

    Prototype in:       rstofbb.h

    Parameters Passed:  outputmode - POINT, CONTINUOUS, STREAM
			datamode   - POS, ANGLE, MATRIX, etc.
			displayon  - TRUE, FALSE
			buttonmode - ON, OFF
			(global) displayliststartaddr - 1st address in
				 the group to retrieve data from
			(global) displayliststopaddr - last address in
				 the group to retrieve data from

    Return Value:       TRUE if command executed OK
			FALSE otherwise

    Remarks:            Get data from a group of Birds using the ind
			the datamode specified
*/
int getmultibirddata(outputmode,datamode,displayon,buttonmode)
short outputmode;
unsigned char datamode;
unsigned char displayon;
short buttonmode;
{
    unsigned char startaddr;
    unsigned char stopaddr;
    short chr;
    unsigned char birddata[25 * 30];
    unsigned char firsttime = TRUE;

    /*
	Get the System Status from the Flock in Group Mode to assure
	that we get data from the correct number of receivers
    */
    if (fbbgroupdataflg)
    {
	if (!getsystemstatus())
	    return(FALSE);
    }

    /*
	Set All the Birds into the correct Data Output Mode
    */
    startaddr = displayliststartaddr;
    stopaddr = displayliststopaddr;

    if (!setdatamode(startaddr, stopaddr, datamode))
	return(FALSE);

    /*
	Now Get Data from all the Birds
    */
    screencleared = FALSE;

    while (TRUE)
    {
	/*
	   Display from on the Top of Screen
	*/
	if (!screencleared)
	{
	   CLEARSCREEN;
	   screencleared = TRUE;
	}

	/*
	   Move Cursor to the Top of the Screen
	*/
	SETTEXTPOS(1,1);

	/*
	    Put up a User Message
	*/
	if (!fbbgroupdataflg)
	   printf ("Data from Flock... (Hit Any Key to Quit) \n\n\r");
	else
	   printf ("Group Data from Flock... (Hit Any Key to Quit) \n\n\r");

	/*
	     Send the User a Prompt if in Point mode
	*/
	switch  (outputmode)
	{
	    case POINT:
		printf ("Hit the 'B' Key to read Bird data...\n\r");
		while (!ckkbhit());               /* wait for a key */
		chr = getkey();                   /* get the character */
		if ((chr != 'B') && (chr != 'b')) /* check if a B or b */
		   return(TRUE);
		break;

	    case CONTINUOUS:

		if (ckkbhit())
		{
		   clearkey();
		   SETTEXTPOS(1,numfbbrcvrs+4);
		   hitkeycontinue();
		   return(TRUE);
		}
		break;

	    case STREAM:
		if (firsttime)
		{
		   send_serial_cmd((unsigned char *)"@",1);     /* START streaming */
		   firsttime = FALSE;
		}

		if (ckkbhit())
		{
		   clearkey();
		   send_serial_cmd((unsigned char *)"B",1);     /* stop streaming, via Point cmd */
		   if (phaseerror_count)       /* inform the user of phase errors */
		   {
					    printf("*NOTE* %d Phase Errors have occured\n\r",phaseerror_count);
		   }
		   SETTEXTPOS(1,numfbbrcvrs+4);
		   hitkeycontinue();
		   return(TRUE);
		}
		break;

	    default:
		printf("\n\r** ERROR ** mode not currently supported\n\r");
		hitkeycontinue();
		return(FALSE);
	}

	/*
	    Get and Display the Data from all the Birds
	*/
	if (getmultirecords(outputmode, buttonmode, datamode, startaddr, stopaddr, birddata))
	{
	    displaymultidata(datamode, buttonmode, displayon,
			     startaddr,stopaddr, birddata,
			     datafilestream);
	}
	else
	{
	    return(FALSE);
	}
    }
}

/*
    getmultirecords     Get Multiple Records

    Prototype in:       rstofbb.h

    Parameters Passed:  datamode - POS,ANGLE,MATRIX,etc
			buttonmode - ON/OFF
			startaddr - 1st FBB address to collect data from
			stopaddr - last FBB address to collect data from
			(global) fbbgroupdataflg - TRUE or FALSE, indicating the state
				 group mode

    Return Value:       TRUE if all went well
			FALSE otherwise

    Remarks:
*/
int getmultirecords(outputmode, buttonmode, datamode, startaddr, stopaddr, birddata)
short outputmode;
short buttonmode;
unsigned char datamode;
unsigned char startaddr;
unsigned char stopaddr;
unsigned char * birddata;
{
    short datasize;
    short numrecords = 0;
    unsigned char addr = 0;
    unsigned char temprs232tofbbaddr;
    unsigned char birdcmd;

    /*
	Save the Global rs232tofbbaddr in a temp
    */
    birdcmd = (unsigned char) 'B';        /* POINT data mode */
    temprs232tofbbaddr = rs232tofbbaddr;


    switch (datamode)
    {
	case POS:  /* position */
	     datasize = 3;
	     break;

	case ANGLE:  /* angles */
	     datasize = 3;
	     break;

	case MATRIX:  /* matrix */
	     datasize = 9;
	     break;

	case POSANGLE:  /* position/angles */
	     datasize = 6;
	     break;

	case POSMATRIX:  /* position/matrix */
	     datasize = 12;
	     break;

	case QUATER:     /* quaternions */
	     datasize = 4;
	     break;

	case POSQUATER:  /* position and quaternions */
	     datasize = 7;
	     break;

	default:
	     printf("\n\r** ERROR ** illegal datamode in getmultirecord\n\r");
	     rs232tofbbaddr = temprs232tofbbaddr;
	     return(FALSE);
    }

    /*
       If the Bird is NOT in the Group Data Mode
    */
    if (!fbbgroupdataflg)
    {
	/*
	    Now Get the Data for each device
	*/
	for (addr = startaddr; addr <= stopaddr; addr++)
	{
	    /*
		Only Get data from devices with receivers
	    */
	    if (!(fbbsystemstatus[addr] & 0x20))
		continue;

	    /*
		Set the FBB Address
	    */
	    rs232tofbbaddr = addr;

	    /*
		Send the POINT command
	    */
	    if (send_serial_cmd(&birdcmd,1) != 1)
	    {
		printf("\n\r** ERROR ** could not send Point command to Bird at address %d\n\r",addr);
		rs232tofbbaddr = temprs232tofbbaddr;
		return(FALSE);
	    }
	    else
	    {
		if (!readbirddata((short *)birddata, datasize, POINT, buttonmode))
		{
		    printf("\n\r** ERROR ** could not get information from Bird at address %d\n\r",addr);
		    rs232tofbbaddr = temprs232tofbbaddr;
		    return(FALSE);
		}
		else
		{
		    birddata += (datasize * 2) + buttonmode;

		    /*
			Save the Button Value for Each Address
		    */
		    multibuttonvalue[addr] = buttonvalue;
		}
	    }
	}
    }
    else /* The Bird is in the Group Data Mode */
    {
	/*
	    Shut off the rs232 to fbb command..temporarily
	*/
	rs232tofbbaddr = 0;

	/*
	    Send the output position command
	*/
	if (outputmode != STREAM)
	{
	    if (send_serial_cmd(&birdcmd,1) != 1)
	    {
		printf("\n\r** ERROR ** could not send Point command to Bird at address %d\n\r",addr);
		rs232tofbbaddr = temprs232tofbbaddr;
		return(FALSE);
	    }
	}

	/*
	    Do for all the address ..
	    Only Get Data from the devices with Receivers
	    ..so offset the number of records
	*/
	while (numrecords++ < numfbbrcvrs)
	{
	    if (!readbirddata((short *)birddata, datasize, POINT, buttonmode))
	    {
		printf("\n\r** ERROR ** could not get information from Bird %d\n\r",addr);
		rs232tofbbaddr = temprs232tofbbaddr;
		return(FALSE);
	    }
	    else
	    {
		/*
		    Add in the extra address char (GROUP MODE)
		    Note that datasize was in WORDs
		*/
		birddata += (datasize * 2) + 1 + buttonmode;

		/*
		    Save the Button Value for Each Address
		*/
		multibuttonvalue[numrecords] = buttonvalue;
	    }
	}
    }

    rs232tofbbaddr = temprs232tofbbaddr;
    return(TRUE);
}


/*
    getfbbdestaddress   Get the FBB Destination Addresses

⌨️ 快捷键说明

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