Support setting frequency via serial
To set the frequency, connect via serial and enter e.g.,:
F1M
followed by enter/return to set the frequency to 1000000Hz (1MHz)
Frequency can be set as a whole number, a whole number of kHz, or a
whole number of MHz. The commands are case insensitive. So all
the following set the frequency to 1MHz:
F1000000
F1000k
F1M
No validation is performed and nonsensical things can be requested,
so for example if you enter the nonsensical "F9MMM", you get
"GPS Initialized to output RF at 3800301568" This specific number
results from overflow of integer arithmetic and is also way out of
spec for the board, since the actual value requested is around 3.8GHz.
This commit is contained in:
parent
c241ed1444
commit
16df1ad584
1 changed files with 34 additions and 0 deletions
|
|
@ -15,6 +15,8 @@ SoftwareSerial gpsPort(2, 3); // RX, TX
|
|||
#define FIXOut 4 //Pin Out at IDC. Indicator for GPS Lock on pin 4
|
||||
#define LDO_Enable A3 //GPS Voltage regulator Enable on pin A3
|
||||
boolean GPSOK, passthrough;
|
||||
int state; // serial command state machine
|
||||
uint32_t freq; // Frequency in Hz commanded via serial
|
||||
#define softwareversion "1.05" //Version of this program, sent to serialport at startup
|
||||
NMEAGPS gps; // This parses the GPS characters
|
||||
gps_fix fix; // This holds on to the latest values
|
||||
|
|
@ -91,6 +93,37 @@ void handle_serial() {
|
|||
Serial.println(F("Entering passthrough mode -- reset microcontroller to return to normal mode\n"));
|
||||
passthrough = true;
|
||||
}
|
||||
else if(c == 'F' || c == 'f') {
|
||||
Serial.print(F("Frequency?"));
|
||||
state = 1; freq = 0;
|
||||
}
|
||||
else if(state == 1) {
|
||||
if(c >= '0' && c <= '9') {
|
||||
Serial.write(c);
|
||||
freq = freq * 10 + c - '0';
|
||||
} else if (c == 'M' || c == 'm') {
|
||||
Serial.write(c);
|
||||
freq *= 1000000lu;
|
||||
} else if (c == 'K' || c == 'k') {
|
||||
Serial.write(c);
|
||||
freq *= 1000lu;
|
||||
} else if (c == '\n' || c == '\r') {
|
||||
Serial.println(F(""));
|
||||
if (setGPS_OutputFreq(freq)) {
|
||||
Serial.print ("GPS Initialized to output RF at " );
|
||||
Serial.println (freq);
|
||||
Serial.println ("Initialization is complete.");
|
||||
Serial.println ("");
|
||||
GPSOK = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println (F("Error! Could not program GPS!"));
|
||||
GPSOK = false;
|
||||
}
|
||||
state = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -105,6 +138,7 @@ void loop()
|
|||
if(Serial.available()) {
|
||||
handle_serial();
|
||||
}
|
||||
if(state != 0) return;
|
||||
while (gps.available( gpsPort )) {
|
||||
fix = gps.read();
|
||||
if (fix.valid.location && fix.valid.date && fix.valid.time)
|
||||
|
|
|
|||
Loading…
Reference in a new issue