-
-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Alastair D'Silva <[email protected]>
- Loading branch information
Showing
12 changed files
with
229 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/bash | ||
# | ||
# configure_gps.sh: script to provide GPS modules with commands | ||
# that are not saved in flash on the module (ie. they must be provided | ||
# each time the module is started). | ||
|
||
|
||
BASEDIR="$(dirname "$0")" | ||
source <( grep -v '^#' "${BASEDIR}"/settings.conf | grep '=' ) #import settings | ||
|
||
if [[ "${receiver}" = "Quectel LC29HBS" ]]; then | ||
speed="${com_port_settings%%:*}" | ||
python3 "${BASEDIR}"/tools/nmea.py --file "${BASEDIR}"/receiver_cfg/LC29HBS_Configure.txt /dev/"${com_port}" "${speed}" 3 | ||
echo Configuring Quectel LC29HBS on /dev/"${com_port}" at speed "${speed}" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#Enable MSM7 messages | ||
$PAIR432,1 | ||
|
||
#Enable Station Reference Message 1005 | ||
$PAIR434,1 | ||
|
||
#Enable Ephemeris messages | ||
$PAIR436,1 | ||
|
||
#Enable NMEA GGA Time, position, and fix related data | ||
$PAIR062,0,1 | ||
|
||
#Enable NMEA GLL Position data: position fix, time of position fix, and status | ||
$PAIR062,1,1 | ||
|
||
#Enable NMEA GSA GPS DOP and active satellites | ||
$PAIR062,2,1 | ||
|
||
#Enable NMEA GSV Satellite information | ||
$PAIR062,3,1 | ||
|
||
#Enable NMEA RMC Position, velocity, and time | ||
$PAIR062,4,1 | ||
|
||
#Enable NMEA VTG Track made good and speed over ground | ||
$PAIR062,5,1 | ||
|
||
#Enable NMEA ZDA UTC day, month, and year, and local time zone offset | ||
$PAIR062,6,1 | ||
|
||
#Enable NMEA GRS GRS range residuals | ||
$PAIR062,7,1 | ||
|
||
#Enable NMEA GST Position error statistics | ||
$PAIR062,8,1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Restore factory defaults | ||
$PQTMRESTOREPAR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#Power off the GNSS | ||
$PAIR003 | ||
|
||
#SLEEP# 1000 | ||
|
||
#Power on the GNSS | ||
$PAIR002 | ||
|
||
#SLEEP# 5000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#Save parameters | ||
$PQTMSAVEPAR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#Crank the baud rate up (Could also go 3000000) | ||
$PAIR864,0,0,921600 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Get the model and firmware version | ||
$PQTMVERNO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import argparse | ||
import serial | ||
import time | ||
|
||
# Function to calculate NMEA checksum | ||
def calculate_nmea_checksum(nmea_sentence): | ||
checksum = 0 | ||
# Iterate through each character after the starting '$' and before '*' | ||
for char in nmea_sentence[1:]: | ||
checksum ^= ord(char) | ||
return f"{nmea_sentence}*{checksum:02X}" | ||
|
||
# Function to append checksum if not provided | ||
def append_checksum_if_missing(nmea_sentence): | ||
if '*' not in nmea_sentence: | ||
# Calculate and append checksum if '*' is missing | ||
return calculate_nmea_checksum(nmea_sentence) | ||
return nmea_sentence | ||
|
||
# Function to handle serial communication | ||
def send_nmea_command(port, speed, timeout, nmea_command, verbose): | ||
# Open serial port | ||
try: | ||
with serial.Serial(port, baudrate=speed, timeout=timeout) as ser: | ||
# Append checksum if missing | ||
nmea_command_with_checksum = append_checksum_if_missing(nmea_command) | ||
|
||
# Write NMEA command to the serial port | ||
ser.write((nmea_command_with_checksum + '\r\n').encode('ascii')) | ||
if verbose: | ||
print(f"Sent command: {nmea_command_with_checksum}") | ||
|
||
# Wait for the response | ||
start_time = time.time() | ||
while time.time() - start_time < timeout: | ||
try: | ||
response = ser.readline().decode('ascii', errors='ignore').strip() | ||
# Process only valid ASCII responses | ||
if response and response.startswith('$'): | ||
if verbose: | ||
print(f"Received response: {response}") | ||
return response | ||
except UnicodeDecodeError as e: | ||
# Skip non-ASCII responses (likely RTCM3 messages) | ||
if verbose: | ||
print(f"Non-ASCII data skipped: {e}") | ||
if verbose: | ||
print("Timeout: No matching response received.") | ||
except serial.SerialException as e: | ||
print(f"Error opening serial port: {e}") | ||
|
||
# Function to read NMEA commands from a file and ignore lines starting with '#' and blank lines | ||
def read_commands_from_file(file_path): | ||
try: | ||
with open(file_path, 'r') as file: | ||
commands = [] | ||
for line in file: | ||
line = line.strip() | ||
# Ignore blank lines and lines starting with '#' | ||
if line and not line.startswith('#') or line.startswith('#SLEEP#'): | ||
commands.append(line) | ||
return commands | ||
except FileNotFoundError: | ||
print(f"Error: File '{file_path}' not found.") | ||
return [] | ||
|
||
# Function to handle the sleep command in the file | ||
def handle_sleep_command(command, verbose): | ||
try: | ||
sleep_time_ms = int(command.split('#SLEEP# ')[1]) | ||
if verbose: | ||
print(f"Sleeping for {sleep_time_ms} ms") | ||
time.sleep(sleep_time_ms / 1000) # Convert to seconds | ||
except (IndexError, ValueError): | ||
print(f"Invalid sleep command format: {command}") | ||
|
||
if __name__ == "__main__": | ||
# Parse command line arguments | ||
parser = argparse.ArgumentParser(description="Send NMEA commands to Quectel LC29H module") | ||
parser.add_argument('port', type=str, help='Serial port to use (e.g., /dev/ttyUSB0 or COM3)') | ||
parser.add_argument('speed', type=int, help='Baud rate (e.g., 9600)') | ||
parser.add_argument('timeout', type=int, help='Timeout in seconds') | ||
parser.add_argument('command', nargs='?', type=str, help='NMEA command to send (optional, overrides file)') | ||
parser.add_argument('--file', type=str, help='File with NMEA commands to send') | ||
parser.add_argument('--verbose', action='store_true', help='Enable verbose output for tracing') | ||
|
||
args = parser.parse_args() | ||
|
||
# Determine which commands to send (from file or argument) | ||
if args.command: | ||
# Send the provided command as an argument | ||
nmea_commands = [args.command] | ||
elif args.file: | ||
# Read commands from the file, ignoring comments and blank lines | ||
nmea_commands = read_commands_from_file(args.file) | ||
else: | ||
print("Error: You must provide either a command or a file containing commands.") | ||
exit(1) | ||
|
||
# Send each NMEA command from the list | ||
for command in nmea_commands: | ||
if command.startswith('#SLEEP#'): | ||
handle_sleep_command(command, args.verbose) | ||
else: | ||
send_nmea_command(args.port, args.speed, args.timeout, command, args.verbose) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[Unit] | ||
Description=Configure GPS | ||
Before=str2str_tcp.service | ||
#After=network-online.target | ||
#Wants=network-online.target | ||
#Requires=network-online.target | ||
|
||
[Service] | ||
Type=oneshot | ||
RemainAfterExit=yes | ||
User={user} | ||
ExecStart={script_path}/configure_gps.sh | ||
Restart=no | ||
ProtectHome=read-only | ||
ProtectSystem=strict | ||
ReadWritePaths={script_path} | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters