📄 rstofbb.c
字号:
Prototype in: rstofbb.h
Parameters Passed: startaddrptr - pointer to the start address
stopaddrptr - pointer to the stop address
If stopaddrptr == NULL then
the routine only gets the destination
address
Return Value: TRUE (always)
Remarks: Prompts the User for the start and stop address
*/
int getfbbdestaddress(startaddrptr,stopaddrptr)
unsigned char * startaddrptr;
unsigned char * stopaddrptr;
{
short tempstartaddr;
short tempstopaddr;
short illegaladdr = FALSE;
/*
Use the System Status to determine if address the user selects
is avaible
*/
if (!getsystemstatus())
return(FALSE);
do
{
if (stopaddrptr != NULL)
{
/*
If the user goes to this menu first, reset the illegal
address in the startaddress location
*/
if (*startaddrptr > 30)
*startaddrptr = 1;
printf("\n\rCurrent Start Destination Address is %d\n\r",*startaddrptr);
printf("Enter the Start Destination Address (<ESC> for no change): ");
}
else
{
printf("\n\rCurrent Destination Address is %d\n\r",*startaddrptr);
printf("Enter the new Destination Address (<ESC> for no change): ");
}
if ((tempstartaddr = getnumber()) != ESC_SEL)
{
if ((tempstartaddr < 0) || (tempstartaddr > numfbbaddrs))
{
illegaladdr = TRUE;
printf ("\n\r** ERROR ** illegal address\n\r");
}
else
{
if (fbbsystemstatus[tempstartaddr] & 0x80)
{
illegaladdr = FALSE;
*startaddrptr = tempstartaddr;
}
else
{
illegaladdr = TRUE;
printf("\n\r** ERROR ** address selected is not accessible\n\r");
}
}
}
else
break;
}
while (illegaladdr);
/*
Only get the Stop address info if stopaddrptr exists
*/
if (stopaddrptr != NULL)
{
do
{
printf("\n\r\n\rCurrent Stop Destination Address is %d\n\r",*stopaddrptr);
printf("Enter the Stop Destination Address (<ESC> for no change): ");
if ((tempstopaddr = getnumber()) != ESC_SEL)
{
if ((tempstopaddr <= 0)
|| (tempstopaddr > numfbbaddrs)
|| (tempstopaddr < tempstartaddr))
{
illegaladdr = TRUE;
printf ("\n\r** ERROR ** illegal address\n\r");
}
else
{
if (fbbsystemstatus[tempstartaddr] & 0x80)
{
illegaladdr = FALSE;
*stopaddrptr = tempstopaddr;
}
else
{
illegaladdr = TRUE;
printf("\n\r** ERROR ** address selected is not accessible\n\r");
}
}
}
else
break;
}
while (illegaladdr);
}
return(TRUE);
}
/*
seddatamode Set the FBB Data Mode
Prototype in: rstofbb.h
Parameters Passed: startaddr - 1st address to set the data mode
stopaddr - last address to set the data mode
datamode - POS,ANGLE,MATRIX,etc
Return Value: TRUE if the datamode was set on all the Birds
FALSE otherwise
Remarks: Sends the desired mode to all the Birds in the
start - stop range
*/
int setdatamode(startaddr,stopaddr,datamode)
unsigned char startaddr;
unsigned char stopaddr;
unsigned char datamode;
{
int addr;
unsigned char posorientcmd;
unsigned char temprs232tofbbaddr;
/*
Setup the command
*/
switch(datamode)
{
case POS:
posorientcmd = 'V';
break;
case ANGLE:
posorientcmd = 'W';
break;
case MATRIX:
posorientcmd = 'X';
break;
case QUATER:
posorientcmd = 92;
break;
case POSANGLE:
posorientcmd = 'Y';
break;
case POSMATRIX:
posorientcmd = 'Z';
break;
case POSQUATER:
posorientcmd = ']';
break;
default:
printf("\n\r** ERROR ** illegal data mode in setdatamode\n\r");
return(FALSE);
}
temprs232tofbbaddr = rs232tofbbaddr;
for (addr = startaddr; addr <= stopaddr; addr++)
{
/*
Set the Address
*/
rs232tofbbaddr = addr;
/*
Send the output position command
*/
if (send_serial_cmd(&posorientcmd,1) != 1)
{
printf("\n\r** ERROR ** could not initialize Output Mode of Bird %d\n\r",addr);
rs232tofbbaddr = temprs232tofbbaddr;
return(FALSE);
}
}
rs232tofbbaddr = temprs232tofbbaddr;
return(TRUE);
}
/*
displaymultidata Display Data from Multiple Birds
Prototype in: rstofbb.h
Parameters Passed: datamode - POS,ANGLE,MATRIX,etc
buttonmode - ON,OFF indicates the state of button
output
displayon - TRUE,FALSE
Return Value:
Remarks:
*/
int displaymultidata(datamode, buttonmode, displayon, startaddr,stopaddr,
birddata, datafilestream)
unsigned char datamode;
short buttonmode;
unsigned char displayon;
unsigned char startaddr;
unsigned char stopaddr;
unsigned char * birddata;
FILE * datafilestream;
{
unsigned char addr;
short displaysize;
for (addr = startaddr; addr <= stopaddr; addr++)
{
/*
Display the data only if the device has a receiver
*/
if (!(fbbsystemstatus[addr] & 0x20))
continue;
/*
Get the current button value prior to displaying the data
*/
buttonvalue = multibuttonvalue[addr];
displaysize = displaybirddata((short *)birddata,datamode,buttonmode,
displayon,addr,datafilestream);
/*
compute the new birddata address for the next record
*/
birddata += displaysize * 2 + buttonmode;
/*
If in Group Data Mode, increment past the address
*/
if (fbbgroupdataflg)
birddata += 1; /* increment the pointer */
}
return(TRUE);
}
/*
getmaxrs232tofbbrate Get the Maximum Data Rate for RS232 to FBB command
Prototype in: rstofbb.h
Parameters Passed: none
(assumes the Flock in NOT IN GROUP MODE)
Return Value: TRUE if all goes well
FALSE otherwise
Remarks: Only available to DOS since this module uses
GETTICKS
UNIX user can modify the code to call there system
timer in order to keep track of real time
*/
int getmaxrs232tofbbrate()
{
#ifdef DOS
static unsigned char startaddr = 1;
static unsigned char stopaddr = 0;
unsigned char datamode = 0;
int testtime;
long testcounter;
unsigned long testtimeticks;
unsigned long starttimeticks;
unsigned long currenttimeticks;
unsigned char birddata[25 * 30];
static char * outputmodemenu[] = {"Select the Output Mode:",
"Return to Main Menu",
"Position",
"Angles",
"Matrix",
"Quaternions",
"Position and Angles",
"Position and Matrix",
"Position and Quaternions"};
/*
Ask the User what Data Mode they want
*/
switch (sendmenu(outputmodemenu,8))
{
case ESC_SEL:
case 0:
return(TRUE);
case 1:
datamode = POS;
break;
case 2:
datamode = ANGLE;
break;
case 3:
datamode = MATRIX;
break;
case 4:
datamode = QUATER;
break;
case 5:
datamode = POSANGLE;
break;
case 6:
datamode = POSMATRIX;
break;
case 7:
datamode = POSQUATER;
break;
}
/*
Get the desired addresses
.. preload the stop address with the group size
*/
if (stopaddr == 0)
stopaddr = flocksize;
getfbbdestaddress(&startaddr,&stopaddr);
/*
Set up all the Devices to the Correct Data Mode
*/
if (setdatamode(startaddr, stopaddr, datamode))
{
if ((testtime = getsampletime()) == ESC_SEL)
return(FALSE);
testtimeticks = (unsigned long)(testtime * (1000/TICK_MSECS));
printf("\n\rTest Started...collecting data, please wait\n\r");
putch(BEL);
starttimeticks = GETTICKS;
while ((currenttimeticks = GETTICKS) == starttimeticks);
starttimeticks = currenttimeticks;
testcounter = 0;
while (((currenttimeticks = GETTICKS) - starttimeticks) < testtimeticks)
{
if (!getmultirecords(POINT, OFF, datamode, startaddr, stopaddr, birddata))
{
putch(BEL);
printf ("\n\r** ERROR ** Test Aborted\n\r");
hitkeycontinue();
return(FALSE);
}
testcounter += 1;
}
/*
Indicate the Test Complete to the User
*/
putch(BEL);
printf ("\n\rTest Complete !!\n\r");
printf ("Sample birds %d through %d %ld times in %d seconds...\n\r"
"yielding a maximum data rate of %6.2f samples/sec/Bird\n\r",
startaddr, stopaddr, testcounter, testtime,(float)testcounter/testtime);
}
hitkeycontinue();
return(TRUE);
#endif
#ifdef UNIX
return(FALSE);
#endif
}
/*
getsampletime Get the Sample Time (length of Time) from the User
Prototype in: rstofbb.h
Parameters Passed: void
Return Value: testtime as an integer
Remarks:
*/
int getsampletime()
{
#ifdef UNIX
printf("\n\r** NOTE ** mode not supported under UNIX\n\r");
hitkeycontinue();
return(TRUE);
#endif
#ifdef DOS
int testtimeint;
while(1)
{
printf("\n\rEnter the length of the test in seconds (10 to 100): ");
if ((testtimeint = getnumber()) == ESC_SEL)
return(ESC_SEL);
if ((testtimeint < 10) || (testtimeint > 100))
{
printf("\n\r** ERROR ** illegal time\n\r");
}
else
{
return(testtimeint);
}
}
#endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -