📄 birdmain.c
字号:
case 1: /* Bird Output Test */
birdoutputtest();
break;
case 2: /* Bird Echo Test */
birdechotest();
break;
case 3: /* Host Data Read Test */
hostreadtest();
break;
case 4: /* Host Data Read Block Test */
hostreadblocktest();
break;
}
}
return(TRUE);
}
int birdoutputtest()
{
short i;
short rxchar;
unsigned char charbuf[5];
/*
Display data read from the Bird until a key is hit
*/
while (!ckkbhit())
{
/*
Get the 4 byte response.. first, clear the buffer
*/
clear_rx();
for (i=0; i < 4 ; i++)
{
rxchar = waitforchar();
if (rxchar < 0)
{
printf("** ERROR ** could not read data from the Bird\n\r");
hitkeycontinue();
return(FALSE);
}
/*
Store the char
*/
charbuf[i] = rxchar;
}
/*
Display the String to the console..first append the NULL termination
*/
charbuf[4] = 0;
printf("%s",charbuf);
}
clearkey();
return(TRUE);
}
int birdechotest()
{
short rxchar;
unsigned char txchar;
short echochar;
/*
Allow the user to type any character and the Bird will echo the
character ...ESC will end the Echo
*/
printf("\n\rEnter Character to echo from the keyboard, <ESC> to quit\n\n\r");
while((echochar = getkey()) != ESC)
{
/*
Display the character input from the keypad
*/
putchar(echochar);
/*
Send the input char to the Bird
*/
txchar = echochar;
send_serial_cmd(&txchar,1);
/*
Get the 1 received character .. hopefully
*/
rxchar = waitforchar();
if (rxchar < 0)
{
printf("** ERROR ** could not read data from the Bird\n\r");
hitkeycontinue();
return(FALSE);
}
/*
Display the character
*/
putchar(rxchar);
}
return(TRUE);
}
int hostreadtest()
{
short rxchar;
/*
Allow the user to type any character and the Bird
will output numbers 0 - 255 ...ESC will end the Test
*/
printf("\n\rHit any key for next Output Char, <ESC> to quit\n\n\r");
clear_rx();
while((getkey()) != ESC)
{
/*
Send the char to the Bird
*/
send_serial_cmd((unsigned char *)" ",1);
/*
Get the 1 received character .. hopefully
*/
rxchar = waitforchar();
if (rxchar < 0)
{
printf("** ERROR ** could not read data from the Bird\n\r");
hitkeycontinue();
return(FALSE);
}
/*
Display the character as a decimal number on the screen
*/
printf("Bird Output: %d\n\r", rxchar);
}
return(TRUE);
}
int hostreadblocktest()
{
short i;
short rxchar[256];
/*
Allow the user to type any character and the Bird
will output numbers 0 - 255 ...ESC will end the Test
*/
printf("\n\rHit any key for next Output Block, <ESC> to quit\n\n\r");
clear_rx();
while((getkey()) != ESC)
{
/*
Send the char to the Bird
*/
send_serial_cmd((unsigned char *)" ",1);
/*
Get the 256 received characters
*/
for (i=0; i<256 ; i++)
{
rxchar[i] = waitforchar();
if (rxchar[i] < 0)
{
printf("** ERROR ** could not read data from the Bird\n\r");
hitkeycontinue();
return(FALSE);
}
}
/*
Display the block as a decimal numbers on the screen
*/
printf("\n\n\rBird Output: %d", rxchar[0]);
for(i=1; i<256; i++)
printf(",%d", rxchar[i]);
}
return(TRUE);
}
/*
nextmastercmd - Next Master Command
Prototype in: birdmain.c
Parameters Passed: void
Return Value: TRUE if command sent OK
FALSE if command could not be sent
ESCSEL if the user selected ESC
Remarks:
*/
int nextmastercmd()
{
unsigned char rs232cmd;
int nextmaster;
char * nextmasterques = "\n\rEnter the NEXT Master address (1 - 14): ";
printf ("%s",nextmasterques);
while ((nextmaster = getnumber()) != ESC_SEL)
{
if ((nextmaster > 0) && (nextmaster < 15))
{
rs232cmd = (unsigned char) nextmaster + '0';
if (send_serial_cmd(&rs232cmd,1) != 1)
{
printf("** ERROR ** could not send the NEXTMASTER command\n\r");
hitkeycontinue();
return(FALSE);
}
else
{
return(TRUE);
}
}
else
{
printf("** ERROR ** invalid address\n\r");
printf ("%s",nextmasterques);
}
}
return(TRUE);
}
/*
nextxmtrcmd - Next Transmitter Command
Prototype in: birdmain.c
Parameters Passed: void
Return Value: TRUE if command sent OK
FALSE if command could not be sent
ESCSEL if the user selected ESC
Remarks:
*/
int nextxmtrcmd()
{
unsigned char rs232cmd[2];
int nextxmtraddr;
int nextxmtrnum = 0;
char * nextxmtrques1 = "\n\rEnter the NEXT TRANSMITTER address (1-14): ";
char * nextxmtrques2 = "\n\rEnter the NEXT TRANSMITTER number (0-3): ";
/*
Get the System Status because we will need to which device
has a transmitter
*/
if (!getsystemstatus())
return(FALSE);
printf ("%s",nextxmtrques1);
while ((nextxmtraddr = getnumber()) != ESC_SEL)
{
if ((nextxmtraddr > 0) && (nextxmtraddr < 15))
{
if (fbbsystemstatus[nextxmtraddr] & 0x0f)
{
rs232cmd[0] = '0';
rs232cmd[1] = (unsigned char) nextxmtraddr << 4;
break;
}
else
{
printf("** ERROR ** transmitter not available at that address\n\r");
printf ("%s",nextxmtrques1);
}
}
else
{
printf("** ERROR ** invalid address\n\r");
printf ("%s",nextxmtrques1);
}
}
if (nextxmtraddr == ESC_SEL)
return(ESC_SEL);
/*
Only ask for the transmitter number if the device is an ERC
*/
if (fbbsystemstatus[nextxmtraddr] & 0x10)
{
printf ("%s",nextxmtrques2);
while ((nextxmtrnum = getnumber()) != ESC_SEL)
{
if ((nextxmtrnum >= 0) && (nextxmtrnum <= 3))
{
if (!(fbbsystemstatus[nextxmtraddr] & (0x1 << nextxmtrnum)))
{
printf("** ERROR ** ERT selection not available at that address\n\r");
printf ("%s",nextxmtrques2);
}
else
{
/*
Else the Transmitter number OK so load it
*/
rs232cmd[1] |= (unsigned char) nextxmtrnum;
break;
}
}
else
{
printf("** ERROR ** invalid xmtr number\n\r");
printf ("%s",nextxmtrques2);
}
}
}
if (nextxmtrnum == ESC_SEL)
return(ESC_SEL);
if (send_serial_cmd(rs232cmd,2) != 2)
{
printf("** ERROR ** could not send the NEXT XMTR command\n\r");
hitkeycontinue();
return(FALSE);
}
printf("..NEXT XMTR command sent\n\r");
hitkeycontinue();
return(TRUE);
}
/*
setxmtrtype SET XMTR TYPE
Prototype in: birdmain.c
Parameters Passed: void
Return Value: ESC_SEL if the user selected ESC
Remarks: sets the posk global to POSK36 if Flock is
selected or POSK144 if the ER Controller is
selected
*/
int setxmtrtype()
{
short xmtrtype;
static char * xmtrtype_menuptr [] =
{"Select Transmitter Type:",
"Short Range Transmitter",
"Extended Range Transmitter"};
/*
Let the user select Transmitter type
*/
if ((xmtrtype = sendmenu(xmtrtype_menuptr,2)) == ESC_SEL)
return(ESC_SEL);
/*
Setup Scaling for 36" if choice 0
*/
if (xmtrtype == 0)
posk = POSK36;
/*
Setup Scaling for 144" if choice 1
*/
if (xmtrtype == 1)
posk = POSK144;
return(TRUE);
}
/*
get_output_mode - Get Output Mode
Prototype in: birdmain.h
Parameters Passed: void
Return Value: outputmode = POINT, CONTINUOUS, or STREAM
if mode is selected or ESC_SEL if ESC is selected
Remarks: prompts the user to enter the outputmode from the
bird.
*/
int get_output_mode()
{
int mode;
short menuselects;
static char * outputmode_menuptr [] =
{"Data Output Modes:",
"Point Mode",
"Continuous Point Mode",
"Stream Mode"};
/*
Only POINT or Continuous mode when using Multi devices in RS232
to FBB mode and not in the Group Mode
*/
menuselects = 3;
if ((displaymultidataflg) && (!fbbgroupdataflg))
menuselects = 2;
/*
Put up the Menu and get the selection
*/
if ((mode = sendmenu(outputmode_menuptr,menuselects)) == ESC_SEL)
return(ESC_SEL);
/*
Close the Data file if already open
*/
if (datafilestream)
fclose(datafilestream);
/*
Ask the User if they want to save data to a File
*/
if (askyesno("\nDo you want to save the data to an ASCII file"))
{
printf("\n\r\n\rCurrent data file name is <%s>\n\r",datafilename);
if (askyesno("...Do you want to change the file name"))
{
printf("\n\rEnter the Filename: ");
scanf("%s",datafilename);
}
if ((datafilestream = fopen(datafilename,"wt")) == NULL)
{
printf("** ERROR ** could not open the data file\n\r");
hitkeycontinue();
}
}
printf("\n\r");
return(mode); /* return the value selected */
}
/*
serialinit - Serial Port Initialization
Prototype in: birdmain.h
Parameters Passed: void
Return Value: TRUE if successful
FALSE if unsuccessful
Remarks: Routine prompts the user for the serial port
configuration parameters of COM1 or COM2 and
tries to configure the port via configserialport()
*/
int serialinit()
{
short menusel;
static char * serialhdr =
"****************************************************************************\n\r\
* ASCENSION TECHNOLOGY CORPORATION - Serial Port Configuration *\n\r\
****************************************************************************\n\r\n";
static char * serialmenu[] =
{"Serial Port Options:",
"No Change",
"115200",
"57600",
"38400",
"19200",
"9600",
"4800",
"2400",
"COM1",
"COM2"};
/*
Clear the Screen and Put up a Header
*/
CLEARSCREEN;
sendmenuhdr(serialhdr);
/*
Save the Serial configuration, if not already saved
*/
if (!serialconfigsaved)
{
if (!saveserialconfig())
{
printf("** NOTE ** could not save current serial port configuration\n\r\n\r");
hitkeycontinue();
}
else
{
serialconfigsaved = TRUE;
}
}
/*
Query the User for the Serial Port configuration
*/
do
{
/*
Display Current Configuration
*/
printf("\n\rCurrent Serial Port Configuration: \n\r\t %s at %ld Baud\n\r",
sys_com_port[comport],baud);
/*
Get menu selection
*/
if ((menusel = sendmenu(serialmenu,10)) <= 0) /* ESC or no change */
{
/*
Configure the Serial Port Hardware
*/
if (!configserialport())
{
printf("** Error Initializing Serial Port **\n\r");
hitkeycontinue();
return(FALSE);
}
return(TRUE); /* all set...go home */
}
if (menusel < 8) /* if Baud rate change */
{
/*
Store the New Baud Rate
*/
baud = baudratetable[menusel-1];
/*
Store the New Baud in Bits ..get from the table which
was created using the sgtty.h OR termio.h system
include file
*/
if ((baudspeedbits = baudspeedbittable[menusel-1]) == -1)
{
printf("\n\r** ERROR ** baud rate not supported\n\r");
baud = 9600L; /* setup baud to legal value */
hitkeycontinue();
}
}
/*
Must be a Com Port Change
*/
if (menusel == 8) /* if Com 1 port Change */
{
restoreserialconfig();
comport = COM1; /* set the new port # */
if (!saveserialconfig())
return(FALSE);
}
if (menusel == 9) /* if Com 2 port Change */
{
restoreserialconfig();
comport = COM2; /* set the new port # */
if (!saveserialconfig())
return(FALSE);
}
}
while(TRUE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -