📄 birdcmds.c
字号:
case 3: /* Display Pickup Values*/
/*
Get the Crystal Frequency
*/
if (!getcrystalfreq())
return(FALSE);
/*
Set the Sync Type
*/
birdcrtsynccmd[1] = 255;
/*
Stay in a Loop displaying the Pickup Values
*/
do
{
if (send_serial_cmd(birdcrtsynccmd,2) != 2)
return(FALSE);
/*
Get the 4 byte response response
*/
for (i=0; i<4; i++)
{
rxchar = waitforchar();
parameter[i] = rxchar;
if (rxchar < 0)
{
printf("** ERROR ** could not read data back from the Bird\n\r");
hitkeycontinue();
return(FALSE);
}
}
/*
Display the Retrace Voltage
*/
i = *(unsigned char *) ¶meter[0] +
((*(unsigned char *) ¶meter[1]) << 8);
printf ("%6.4f ", (float)((float)i * 5.0/32768.0));
/*
Compute the Retrace Rate if the count is not = 0
...then display
*/
i = *(unsigned char *)¶meter[2] +
((*(unsigned char *)¶meter[3]) << 8);
if (i != 0)
printf (" %6.2f\n\r",
(float)((125000.0 * crystalfreq)/(unsigned short)i)/2);
else
printf (" 00.00\n\r");
}
while (!ckkbhit()); /* Stay in the loop until a key is hit */
clearkey(); /* clear the keyboard */
/*
Set the Sync Type to OFF
*/
birdcrtsynccmd[1] = 0;
/*
Send the Command
*/
if (send_serial_cmd(birdcrtsynccmd,2) != 2)
return(FALSE);
break;
case ESC_SEL:
return(ESC_SEL);
}
hitkeycontinue();
return(TRUE);
}
/*
showfbbconfig Display the FBB Configuration
Prototype in: cmdutil.h
Parameters Passed: void
Return Value: void
Remarks: Displays the FBB Configuration information pointed
to by fbbconfig
*/
void showfbbconfig(fbbconfig)
unsigned char * fbbconfig;
{
short i;
short j;
short active;
switch (fbbconfig[0])
{
case 0:
printf("\n\rFBB Bird configured for Stand Alone Operation\n\r");
break;
case 1:
printf("\n\rFBB Bird configured for 1 Transmitter/N Receiver Operation\n\r");
break;
default:
printf("** ERROR ** invalid FBB Configuration Mode\n\r");
}
hitkeycontinue();
printf("\n\rFBB Devices..");
for (i=1;i<=numfbbaddrs;i++)
{
printf("\n\rDevice at FBB address %d is ", i);
if (i < 15)
{
j = *(unsigned char *)&fbbconfig[1] +
((*(unsigned char *)&fbbconfig[2]) << 8);
active = ((0x1 << i) & j);
}
else
{
j = *(unsigned char *)&fbbconfig[5] +
((*(unsigned char *)&fbbconfig[6]) << 8);
active = ((0x1 << i-15) & j);
}
if (active)
printf("RUNNING");
else
printf("NOT RUNNING");
if (i == 20) /* Don't let the info run off the screen */
hitkeycontinue();
}
hitkeycontinue();
printf("\n\rFBB Dependents..");
for (i=1;i<=14;i++)
{
printf("\n\rDevice at FBB address %d is ", i);
j = *(unsigned char *)&fbbconfig[3] +
((*(unsigned char *)&fbbconfig[4]) <<8);
if ((0x1 << i) & j)
printf("DEPENDENT");
else
printf("NOT DEPENDENT");
}
}
/* return number of samples taken*/
int getsamples(samplesize,mean,stddev,pk_pk,maximum,minimum)
int samplesize;
double mean[];
double stddev[];
double pk_pk[];
double maximum[];
double minimum[];
{
short i;
int index;
unsigned char temprs232tofbbaddr;
short birddata[14];
unsigned char posorientcmd;
unsigned char datasize;
int wfc;
double floatdata[6], sx[6], sx2[6];
short outputmode = CONTINUOUS;
short buttonmode = 0;
short cmdsize=0;
static unsigned char birdchangevaluecmd[] = {'P',0,0,0,0,0};
/* make sure not in FBB group mode - add later */
/* no button mode */
/* initualize mean[] and stddev[] */
for (index=0; index<6; index++) {
mean[index]=0; stddev[index]=0;
sx[index]=0; sx2[index]=0;
maximum[index]=-9999; minimum[index]=9999;
}
/*
send the mode Command (ie. POSANGLES)
*/
posorientcmd = 'Y';
datasize = 6;
if (send_serial_cmd(&posorientcmd,1) != 1) return(0);
/*
enable data ready char, only to master
*/
temprs232tofbbaddr = rs232tofbbaddr;
rs232tofbbaddr = 0; /* to master */
birdchangevaluecmd[1] = 8;
birdchangevaluecmd[2] = 1;
cmdsize = 3;
if (send_serial_cmd(birdchangevaluecmd,cmdsize) != cmdsize) {
printf("\n\r * problem sending data ready char enable *");
rs232tofbbaddr = temprs232tofbbaddr;
return(0);
}
rs232tofbbaddr = temprs232tofbbaddr;
/*
wait 5 cycles for filters to settle
*/
for (index=0; index<5; index++)
do /* wait for data ready char from master */
wfc = waitforchar();
while ( wfc != data_ready_char );
for (index=0; index<samplesize; index++)
{
printf("\r %3d ",index+1);
/*
wait for data ready char from master before taking record from bird
*/
do
wfc = waitforchar(); /* timed out at low measurement speed (14-16 Hz) */
while ( wfc != data_ready_char );
/*
request a new point from bird
*/
if (send_serial_cmd((unsigned char *)"B",1) != 1) /* get another set of points */
{
/*
disable data ready char from master, error exit
*/
birdchangevaluecmd[1] = 8;
birdchangevaluecmd[2] = 0;
cmdsize = 3;
if (send_serial_cmd(birdchangevaluecmd,cmdsize) != cmdsize)
printf("\n\r * problem sending data ready char disable *");
return(0); /* return done if errors */
}
/*
get the data NOW
*/
if (!readbirddata(birddata,datasize,outputmode,buttonmode)) {
/*
disable data ready char, error exit
*/
temprs232tofbbaddr = rs232tofbbaddr;
rs232tofbbaddr = 0; /* to master */
birdchangevaluecmd[1] = 8;
birdchangevaluecmd[2] = 0;
cmdsize = 3;
if (send_serial_cmd(birdchangevaluecmd,cmdsize) != cmdsize)
printf("\n\r * problem sending data ready char disable *");
rs232tofbbaddr = temprs232tofbbaddr;
return(0); /* return done if errors */
}
for (i=0;i<6;i++) {
if (i<3) floatdata[i] = (double)(birddata[i] * posk);
else floatdata[i] = (double)(birddata[i] * ANGK);
sx[i]+=floatdata[i];
sx2[i]+= (floatdata[i]*floatdata[i]);
if (floatdata[i]<minimum[i]) minimum[i]=floatdata[i];
if (floatdata[i]>maximum[i]) maximum[i]=floatdata[i];
}
}
/* finish calculating the mean and Stddev */
for (index=0; index<6; index++) {
double temp;
mean[index] = sx[index]/(double)samplesize;
temp= sx2[index]/(double)samplesize - mean[index]*mean[index];
stddev[index] = sqrt(fabs(temp));
pk_pk[index]=maximum[index]-minimum[index];
}
/*
disable data ready char from master, pior to normal exit
*/
temprs232tofbbaddr = rs232tofbbaddr;
rs232tofbbaddr = 0; /* to master */
birdchangevaluecmd[1] = 8;
birdchangevaluecmd[2] = 0;
cmdsize = 3;
if (send_serial_cmd(birdchangevaluecmd,cmdsize) != cmdsize) {
printf("\n\r * problem sending data ready char disable *");
rs232tofbbaddr = temprs232tofbbaddr;
return(0);
}
rs232tofbbaddr = temprs232tofbbaddr;
return(samplesize);
}
void printsamples(int samplesize, double mean[], double stddev[],
double pk_pk[], double maximum[], double minimum[])
{
int index;
printf("\r X Y Z Az El Roll\t\t%4d samples\n",samplesize);
for (index=0; index<6; index++) printf("%7.2lf\t",mean[index]);
printf("\tMean\n\r");
for (index=0; index<6; index++) printf("%7.2lf\t",maximum[index]);
printf("\tMax\n\r");
for (index=0; index<6; index++) printf("%7.2lf\t",minimum[index]);
printf("\tMin\n\r");
for (index=0; index<6; index++) printf("%7.2lf\t",pk_pk[index]);
printf("\tPeak to Peak\n\r");
for (index=0; index<6; index++) printf("%7.2lf\t",stddev[index]);
printf("\tStd Deviation\n\r");
printf("\n\n");
/* hitkeycontinue(); */
}
void clearbuff() { /* clear serial buffer function */
short rxchar;
do
rxchar = get_serial_char();
while ( rxchar != NODATAAVAIL );
}
void getsamplesoverrange(int samplesize) {
float start, end, step, temp, present;
unsigned char temprs232tofbbaddr;
int stepnumber, index;
double mean[6], stddev[6], pk_pk[6];
double maximum[6], minimum[6], noise;
unsigned short i, el;
unsigned short xmtr_time_cnt;
float xtime;
short cmdsize=0;
static unsigned char birdchangevaluecmd[] = {'P',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
/*
Get the CPU crstal freq from master
*/
clearbuff();
temprs232tofbbaddr = rs232tofbbaddr;
rs232tofbbaddr = 0; /* to master */
if (!getcrystalfreq()) {
printf("\n\r * problem getting crystal frequency *");
return;
}
rs232tofbbaddr = temprs232tofbbaddr;
printf("\n\r Crystal Frequency is: %4.1f\n",crystalfreq);
start=getfloat("\n What starting frequency (14-144 Hz):",14,144);
end=getfloat(" What ending frequency (14-144 Hz):",14,144);
if (start==end) {
printf("Start value and End value can not be the same.");
hitkeycontinue();
return;
}
if (start>end) {
temp=start; start=end; end=temp;
}
do {
step=getfloat(" What step frequency (positive number):",0,144);
} while (step<=0);
printf("\n\n\rMeasurement rate at START of scan in Measurments/sec %6.2f.",start);
printf("\n\rMeasurement rate at END of scan %6.2f.",end);
printf("\n\rScan step size in measurments/sec %6.2f",step);
/*
get the average receiver position for display
*/
printf("\n\n\r");
getsamples(100,mean,stddev,pk_pk,maximum,minimum);
printf("\rRECEIVER LOCATION\n\tX\tY\tZ\tAz\tEL\tROLL");
printf("\n\r %6.2lf %6.2lf %6.2lf %7.2lf %7.2lf %7.2lf",
mean[0],mean[1],mean[2],mean[3],mean[4],mean[5]);
if (abs(mean[4])<45.0) {
/* EL below 45 degrees, use average Euler angle statistics */
el=0;
printf("\n\n\rSpeed Xtime Xmtr_Time_Cnt Avg Euler Pk-Pk\n");
} else {
el=1;
printf("\n\n\r* NOTE * because Euler elevation was larger then 45 degrees, only ");
printf("\n\relevation Peak to Peak will be displayed.");
printf("\n\n\rSpeed Xtime Xmtr_Time_Cnt EL Pk-Pk\n");
}
stepnumber = (int) ( (end-start)/step );
for (present=start,index=0; index<=stepnumber; index++) {
/*
Check to see if user is tire of waiting
*/
if (ckkbhit()) {
printf("\n\n\r ** Keyboard break ** \n");
break;
}
/*
set measurement rate
*/
/*
Set the Parameter number and the command size
*/
birdchangevaluecmd[1] = 6;
cmdsize = 4;
/*
convert to transmitter time counts
*/
i = (unsigned)(((crystalfreq/8.0)*1000.0)*
(((1000.0/present)-0.3)/4.0));
*(unsigned char *)&birdchangevaluecmd[2] = (unsigned char) (i & 0xff);
*(unsigned char *)&birdchangevaluecmd[3] = (unsigned char) ((i & 0xff00) >> 8);
xmtr_time_cnt = i;
xtime = xmtr_time_cnt*(8.0/crystalfreq)/1000.0;
/*
Send the new measurement speed Command to the Master unit
*/
temprs232tofbbaddr = rs232tofbbaddr;
rs232tofbbaddr = 0; /* to master */
if (send_serial_cmd(birdchangevaluecmd,cmdsize) != cmdsize) {
printf("\n\r * problem setting new measurement rate *");
rs232tofbbaddr = temprs232tofbbaddr;
return;
}
rs232tofbbaddr = temprs232tofbbaddr;
if (getsamples(samplesize,mean,stddev,pk_pk,maximum,minimum)!=samplesize)
return;
if (el==0) noise = (pk_pk[3]+pk_pk[4]+pk_pk[5])/3.0;
else noise = pk_pk[4];
printf("\r%5.1lf %6.3f %10u %5.2lf\n",present,xtime,xmtr_time_cnt,noise);
present+=step;
if (present>end) present=end;
}
hitkeycontinue();
}
/*
getbirdstatistics - aquire data and take noise statistics
Prototype in: birdcmds.h
Parameters Passed: void
Return Value: void
Remarks: Being developed.
*/
void getbirdstatistics(){
int samplesize;
int answer;
double mean[6],stddev[6],pk_pk[6],maximum[6],minimum[6];
static char * birdstatmenu[] = {"Select Statistics option:",
"Return to main menu",
"Change sample number",
"Take POS/ANGLE samples",
"Take samples over a range"};
samplesize=500;
printf("\n\r** Reminder **");
printf("\n\rIf you have a multiple receiver system and using one RS232 to");
printf("\n\rthe master, then you must use the RS232 to FBB command to select");
printf("\n\rthe receiver you want noise statistics from.");
printf("\n\rTake receiver out of BUTTON mode and GROUP mode.");
printf("\n\rTo get statistics at measurement rates above 110 Hz, the baud rate");
printf("\n\rmust be at least 38400.\n");
while (1) { /* loop forever */
printf("\n\rDefault sample number: %4d\n",samplesize);
/*
Find out what the user wants to do ...
*/
switch (sendmenu(birdstatmenu,4))
{
case 0: /* return to main menu */
return;
case 1: /* specify sample size */
do {
printf ("\n\rEnter the number of samples for statistics: ");
if ((answer = getnumber()) == ESC_SEL) break;
if (answer<3)
printf("\n\r number must be greater then 3 (or ESC key)");
} while (answer < 3) ;
samplesize=answer;
break;
case 2: /* take samples pos/angles */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -