-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'Knio:master' into trimble
- Loading branch information
Showing
33 changed files
with
1,663 additions
and
135 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,2 @@ | ||
[run] | ||
relative_files = True |
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,54 @@ | ||
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python | ||
|
||
name: pynmea2 | ||
on: | ||
push: | ||
branches: ["master"] | ||
pull_request: | ||
branches: ["master"] | ||
|
||
jobs: | ||
test: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
python: ["3"] | ||
os: ["ubuntu-latest"] | ||
include: | ||
- {python: "3.8", os: "ubuntu-22.04"} | ||
- {python: "3.9", os: "ubuntu-22.04"} | ||
- {python: "3.10", os: "ubuntu-22.04"} | ||
- {python: "3.11", os: "ubuntu-22.04"} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python ${{ matrix.python }} | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: ${{ matrix.python }} | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
python -m pip install pytest | ||
python -m pip install flake8 | ||
python -m pip install importlib_metadata | ||
- name: Lint with flake8 | ||
run: | | ||
# stop the build if there are Python syntax errors or undefined names | ||
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | ||
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=80 --statistics | ||
- name: Build and test | ||
run: | | ||
python setup.py sdist --formats=zip | ||
pip install dist/pynmea2*.zip | ||
pytest | ||
- name: Coveralls | ||
env: | ||
COVERAGE_RCFILE: ".github/workflows/.coveragerc" | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
python -m pip install "coverage" | ||
python -m pip install "coveralls" | ||
coverage run --source=pynmea2 -m pytest | ||
python -m coveralls --service=github || true |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,6 +1,11 @@ | ||
|
||
test: | ||
py.test | ||
|
||
publish: | ||
python setup.py sdist upload | ||
test: | ||
python2 -m pytest . | ||
python3 -m pytest . | ||
|
||
publish: test | ||
rm dist/ -r | ||
python3 setup.py sdist | ||
python3 setup.py bdist_wheel | ||
python3 -m twine upload dist/* | ||
|
||
.PHONY: test publish |
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,5 @@ | ||
$GPGGA,184353.07,1929.045,S,02410.506,E,1,04,2.6,100.00,M,-33.9,M,,0000*6D | ||
$GPRTE,2,1,c,0,PBRCPK,PBRTO,PTELGR,PPLAND,PYAMBU,PPFAIR,PWARRN,PMORTL,PLISMR*73 | ||
$GPR00,A,B,C*29 | ||
foobar | ||
$IIMWV,271.0,R,000.2,N,A*3B |
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,103 @@ | ||
''' | ||
Convert a NMEA ascii log file into a GPX file | ||
''' | ||
|
||
import argparse | ||
import datetime | ||
import logging | ||
import pathlib | ||
import re | ||
import xml.dom.minidom | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
try: | ||
import pynmea2 | ||
except ImportError: | ||
import sys | ||
import pathlib | ||
p = pathlib.Path(__file__).parent.parent | ||
sys.path.append(str(p)) | ||
log.info(sys.path) | ||
import pynmea2 | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter) | ||
parser.add_argument('nmea_file') | ||
|
||
args = parser.parse_args() | ||
nmea_file = pathlib.Path(args.nmea_file) | ||
|
||
if m := re.match(r'^(\d{2})(\d{2})(\d{2})', nmea_file.name): | ||
date = datetime.date(year=2000 + int(m.group(1)), month=int(m.group(2)), day=int(m.group(3))) | ||
log.debug('date parsed from filename: %r', date) | ||
else: | ||
date = None | ||
|
||
author = 'https://github.com/Knio/pynmea2' | ||
doc = xml.dom.minidom.Document() | ||
doc.appendChild(root := doc.createElement('gpx')) | ||
root.setAttribute('xmlns', "http://www.topografix.com/GPX/1/1") | ||
root.setAttribute('version', "1.1") | ||
root.setAttribute('creator', author) | ||
root.setAttribute('xmlns', "http://www.topografix.com/GPX/1/1") | ||
root.setAttribute('xmlns:xsi', "http://www.w3.org/2001/XMLSchema-instance") | ||
root.setAttribute('xsi:schemaLocation', "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd") | ||
|
||
root.appendChild(meta := doc.createElement('metadata')) | ||
root.appendChild(trk := doc.createElement('trk')) | ||
meta.appendChild(meta_name := doc.createElement('name')) | ||
meta.appendChild(meta_author := doc.createElement('author')) | ||
trk.appendChild(trk_name := doc.createElement('name')) | ||
trk.appendChild(trkseg := doc.createElement('trkseg')) | ||
meta_name.appendChild(doc.createTextNode(nmea_file.name)) | ||
trk_name. appendChild(doc.createTextNode(nmea_file.name)) | ||
meta_author.appendChild(author_link := doc.createElement('link')) | ||
author_link.setAttribute('href', author) | ||
author_link.appendChild(author_text := doc.createElement('text')) | ||
author_link.appendChild(author_type := doc.createElement('type')) | ||
author_text.appendChild(doc.createTextNode('Pynmea2')) | ||
author_type.appendChild(doc.createTextNode('text/html')) | ||
|
||
for line in open(args.nmea_file): | ||
try: | ||
msg = pynmea2.parse(line) | ||
except Exception as e: | ||
log.warning('Couldn\'t parse line: %r', e) | ||
continue | ||
|
||
if not (hasattr(msg, 'latitude') and hasattr(msg, 'longitude')): | ||
continue | ||
|
||
# if not hasattr(msg, 'altitude'): | ||
# continue | ||
|
||
trkseg.appendChild(trkpt := doc.createElement('trkpt')) | ||
|
||
trkpt.setAttribute('lat', f'{msg.latitude:.6f}') | ||
trkpt.setAttribute('lon', f'{msg.longitude:.6f}') | ||
if hasattr(msg, 'altitude'): | ||
trkpt.appendChild(ele := doc.createElement('ele')) | ||
ele.appendChild(doc.createTextNode(f'{msg.altitude:.3f}')) | ||
|
||
# TODO try msg.datetime | ||
|
||
if date: | ||
trkpt.appendChild(time := doc.createElement('time')) | ||
dt = datetime.datetime.combine(date, msg.timestamp) | ||
dts = dt.isoformat(timespec='milliseconds').replace('+00:00', 'Z') | ||
time.appendChild(doc.createTextNode(dts)) | ||
|
||
xml_data = doc.toprettyxml( | ||
indent=' ', | ||
newl='\n', | ||
encoding='utf8', | ||
).decode('utf8') | ||
print(xml_data) | ||
|
||
|
||
|
||
if __name__ == '__main__': | ||
logging.basicConfig(level=logging.DEBUG) | ||
main() |
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,11 @@ | ||
import pynmea2 | ||
|
||
file = open('examples/data.log', encoding='utf-8') | ||
|
||
for line in file.readlines(): | ||
try: | ||
msg = pynmea2.parse(line) | ||
print(repr(msg)) | ||
except pynmea2.ParseError as e: | ||
print('Parse error: {}'.format(e)) | ||
continue |
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,20 @@ | ||
import io | ||
|
||
import pynmea2 | ||
import serial | ||
|
||
|
||
ser = serial.Serial('/dev/ttyS1', 9600, timeout=5.0) | ||
sio = io.TextIOWrapper(io.BufferedRWPair(ser, ser)) | ||
|
||
while 1: | ||
try: | ||
line = sio.readline() | ||
msg = pynmea2.parse(line) | ||
print(repr(msg)) | ||
except serial.SerialException as e: | ||
print('Device error: {}'.format(e)) | ||
break | ||
except pynmea2.ParseError as e: | ||
print('Parse error: {}'.format(e)) | ||
continue |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.