📄 cmd.c
字号:
#include "includes.h"
/****************************************************************************
* Function: void GetCommand(void)
*
* Takes characters from keyboard or an open command file, also echoing to
* the command line of the display. Assembles the commands into cb[], the
* edit buffer. At the end of a command, sets the flag cbready, which
* indicates to the caller that the command processor should be called. This
* procedure also processes function keys by setting variables which control
* the TDisplay task.
*
* Input: None.
*
* Output: None.
*
* Return Value: None.
****************************************************************************/
static int FakeKey;
void GetCommand(void)
{
logical validcharacter;
int character;
ANOTHERKEY:
validcharacter = FALSE;
if(kbhit())
{
character = GetKey();
validcharacter = TRUE;
if(character==ALTX)
QuitGpsBuilder();
}
else if(FakeKey)
{
character = FakeKey;
FakeKey = 0;
validcharacter = TRUE;
}
else if(CmdFileNesting)
{
character = fgetc(CmdFile[CmdFileNesting-1]);
if(character==EOF)
{
fclose(CmdFile[CmdFileNesting--]);
if(cmdmode==COMMAND)
{
/* User terminated the command file with EOF instead of CR. */
character = 13;
validcharacter = TRUE;
}
}
else
{
cmdmode = COMMAND; /* In command mode when reading from file. */
character = toupper(character);
validcharacter = TRUE;
}
}
if(validcharacter==FALSE)
return;
switch(character)
{
case PGUP_KEY:
EraseDisplay = TRUE;
HelpPage--;
AlmPage--;
EphPage--;
Activate("TDisplay");
break;
case PGDN_KEY:
EraseDisplay = TRUE;
HelpPage++;
AlmPage++;
EphPage++;
Activate("TDisplay");
break;
case F1_KEY:
EraseDisplay = TRUE;
DisplayFunc = DISPLAY_F1;
HelpPage = 0;
if(cmdmode==DISPLAY)
{
/* Bring up a command prompt when the user accesses the
Help/Command Menu display. */
cmdmode = COMMAND;
ClearToEndOfLine(1,25);
cbindex = 0;
cb[cbindex] = 0;
OutputCharacter(1,25,'>');
}
Activate("TDisplay");
break;
case F2_KEY:
EraseDisplay = TRUE;
DisplayFunc = DISPLAY_F2;
Activate("TDisplay");
break;
case F3_KEY:
EraseDisplay = TRUE;
DisplayFunc = DISPLAY_F3;
Activate("TDisplay");
break;
case F4_KEY:
EraseDisplay = TRUE;
DisplayFunc = DISPLAY_F4;
Activate("TDisplay");
break;
case F5_KEY:
EraseDisplay = TRUE;
DisplayFunc = DISPLAY_F5;
Activate("TDisplay");
break;
case F6_KEY:
EraseDisplay = TRUE;
DisplayFunc = DISPLAY_F6;
Activate("TDisplay");
break;
case F7_KEY:
EraseDisplay = TRUE;
DisplayFunc = DISPLAY_F7;
Activate("TDisplay");
break;
case F8_KEY:
EraseDisplay = TRUE;
DisplayFunc = DISPLAY_F8;
Activate("TDisplay");
break;
case F9_KEY:
EraseDisplay = TRUE;
DisplayFunc = DISPLAY_F9;
Activate("TDisplay");
break;
case F10_KEY:
EraseDisplay = TRUE;
DisplayFunc = DISPLAY_F10;
Activate("TDisplay");
break;
case F11_KEY:
EraseDisplay = TRUE;
AlmPage = 0;
DisplayFunc = DISPLAY_F11;
Activate("TDisplay");
break;
case F12_KEY:
EraseDisplay = TRUE;
EphPage = 0;
DisplayFunc=DISPLAY_F12;
Activate("TDisplay");
break;
case ESC:
/* ESC. If not in command mode, generate a prompt and enter
commandmode. If already in command mode, cancel any command
entry which is in progress and restart the command. */
cmdmode = COMMAND;
ClearToEndOfLine(1,25);
cbindex = 0;
cb[cbindex] = 0;
OutputCharacter(1,25,'>');
break;
case 0:
case 13:
case '\n':
/* ENTER/New Line/End of String. No action unless a command is
in progress. */
if(cmdmode==COMMAND)
{
cbready = 1;
cmdmode = DISPLAY;
ClearToEndOfLine(1,25);
}
break;
case RUBOUT:
case LFAR_KEY:
/* Backspace. If at the very beginning of a command, get out
of command mode. */
if(cbindex==0)
{
cmdmode = DISPLAY;
ClearToEndOfLine(1,25);
}
else /* Remove the last character from the command buffer. */
{
OutputCharacter(cbindex+1,25,' ');
cb[--cbindex] = 0;
}
break;
default:
/* All other characters. */
if(character==TAB) /* Whitespace to spaces. */
character=' ';
if(cmdmode==COMMAND)
{
/* Append the character to the editing buffer. */
cb[cbindex++] = character;
cb[cbindex] = 0;
OutputCharacter(cbindex+1,25,character);
if(cbindex>=78)
{
WarningMessage("Too many characters in command");
cbindex = 0;
cb[cbindex] = 0;
cmdmode = DISPLAY;
}
}
break;
}
/* Continue reading command characters (up to the end of a command) if
we are taking inputs from a command file. */
if(CmdFileNesting && cbready==0)
goto ANOTHERKEY;
}
/****************************************************************************
* Function: void ProcessCommand(void)
*
* If the first two characters of the command line match a recognized command,
* do command-dependent processing and return to the caller. If the command is
* not recognized, display an error message. The caller resets the command
* buffer to an empty state after this procedure returns.
*
* Input: None.
*
* Output: None.
*
* Return Value: None.
****************************************************************************/
void ProcessCommand(void)
{
int itemp,i,satellite,channel;
double dtemp,OscErr;
unsigned long ltemp,ltemp2;
char cc1,cc2,buff[90];
navstatestruc N;
clockmodelstruc CLK;
cbready = 0;
cc1 = cb[0];
if(cc1==0) return;
cc2 = cb[1];
/* AA - Altitude Aiding.
Toggle software between using and not using altitude aiding */
if(cc1=='A' && cc2=='A')
{
AltitudeAided = (AltitudeAided==FALSE)? TRUE:FALSE;
return;
}
/* AC x - All Channels.
Assigns satellite x to all active channels. Only works when the
software is in TrackMode 2 (SELECT_SATELLITES). */
if(cc1=='A' && cc2=='C')
{
if(TrackMode==SELECT_SATELLITES)
{
sscanf(cb,"AC %d",&satellite);
if(satellite>=1 && satellite<=32)
{
AzimuthElevationAndDoppler(satellite-1);
for(channel=0;channel<ActiveChannels;channel++)
svsel[channel] = satellite;
}
else
WarningMessage("SV must be between 1 and 32");
}
else
{
sprintf(buff,"Must be in Track Mode %1.1d to use this command",
SELECT_SATELLITES);
WarningMessage(buff);
}
return;
}
/* BR x y - Beacon Rate.
Tune to differential beacon at x kHz and y bps. */
if(cc1=='B' && cc2=='R')
{
i=2;
while(TRUE)
{
if(cb[i]==0) break;
if(isdigit(cb[i])) break;
i++;
}
PROTECT++;
BeacFreq = atof(&cb[i]);
PROTECT--;
while(TRUE)
{
if(cb[i]==0)
break;
if(!(isdigit(cb[i])||(cb[i]=='.')))
break;
i++;
}
while(TRUE)
{
if(cb[i]==0)
break;
if(isdigit(cb[i]))
break;
i++;
}
BeacBaud = atoi(&cb[i]);
if(BeacBaud!=25 && BeacBaud!=50 && BeacBaud!=100 && BeacBaud!=200)
BeacBaud=100;
if(DisplayFunc==6)
EraseDisplay=1;
if(BeacPort)
{
/* Tune external beacon receiver using the MX-50R binary
interface protocol. The unusual hex numbers are the ASCII
codes used in the interface protocol. */
switch(BeacBaud)
{
case 25:
itemp=0xD4;
break;
case 50:
itemp=0xD5;
break;
case 200:
itemp=0xD7;
break;
case 100:
default:
itemp=0xD6; /* 100 bps is the default */
break;
}
WriteSerial(itemp); /* Select MSK bit rate command */
/* Protect the following code region because 1) we are accessing
a shared non-atomic variable, and 2) we want to send out an
indivisible sequence of bytes to the beacon receiver */
PROTECT++; /* For accessing a shared non-atomic variable */
/* Get the 12-bit frequency, which is in units of 100 Hz */
itemp = ((unsigned)(BeacFreq*10.0+0.5))&0xFFF;
WriteSerial(0xCE); /* Frequency select... */
WriteSerial(0xC0+(itemp>>6)); /* Frequency, 0xC0 + six MSB */
WriteSerial(0xC0+(itemp&0x3F));/* Frequency, 0xC0 + six LSB */
PROTECT--;
}
else
{
WarningMessage("Must first assign serial port COMn: to "
"beacon rcvr (DC n command)");
}
return;
}
/* CF filename - Command File.
Process the commands contained in the file "filename". */
if(cc1=='C' && cc2=='F')
{
if(CmdFileNesting<MaxCmdFileNesting)
{
i=2;
while(TRUE)
{
if(i>=80 || cb[i]==0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -