Skip to content

Commit

Permalink
Merge pull request #114 from ymorin-orange/yem/its-vehicle
Browse files Browse the repository at this point in the history
python/its-vehicle: new client
  • Loading branch information
ymorin-orange authored May 23, 2024
2 parents d5c63d1 + b2705ae commit 67d8f75
Show file tree
Hide file tree
Showing 17 changed files with 1,417 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/python_its-quadkeys.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
cd python/its-quadkeys
python -m pip install --upgrade pip
pip install black wheel
pip install -r requirements.txt
- name: Run black
run: |
cd python/its-quadkeys
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/python_its-vehicle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Python its-vehicle

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up python 3.10
uses: actions/setup-python@v2
with:
python-version: "3.10"
- name: Install dependencies
run: |
cd python/its-vehicle
python -m pip install --upgrade pip
pip install black wheel
- name: Run black
run: |
cd python/its-vehicle
black --diff --check .
- name: Run package creation
run: |
cd python/its-vehicle
python setup.py bdist_wheel
- name: Archive package
uses: actions/upload-artifact@v2
with:
name: its_vehicle
path: python/its-vehicle/dist
20 changes: 18 additions & 2 deletions python/its-quadkeys/its_quadkeys/quadkeys.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import collections
import itertools
import json
import pygeotile.tile


class QuadKey(str):
Expand All @@ -18,16 +19,31 @@ class QuadKey(str):
# A QuadKey is immutable, and its hash is actually used, so
# we make sure any operation on a QuadKey does not mutate it.

def __init__(self, quadkey: QuadKey | str = "0", *, separator: str = ""):
def __init__(
self,
quadkey: QuadKey | tuple[float, float, int] | str = "0",
*,
separator: str = "",
):
"""
Create a new QuadKey
quadkey: the string representation of the quadkey
quadkey: can be one of:
- another QuadKey
- the string representation of the quadkey
- the latitude, longitude, and depth, represented as a tuple(float, float, int)
separator: the string which is used to separate the quadkey levels
"""
super().__init__()
if type(quadkey) is QuadKey:
quadkey = str(quadkey)
elif type(quadkey) is tuple:
lat, lon, depth = quadkey
quadkey = pygeotile.tile.Tile.for_latitude_longitude(
lat,
lon,
depth,
).quad_tree
if type(quadkey) is not str:
raise TypeError(
f"cannot create a QuadKey from a {type(quadkey)}={quadkey!s}"
Expand Down
8 changes: 8 additions & 0 deletions python/its-quadkeys/quadkeys-test
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ def test_quadkey():
)
print(f"OK")

print(f"QuadKey from lat/lon/depth: ", end="", flush=True)
qk = its_quadkeys.QuadKey((43.63516355648167, 1.3744570239910097, 22))
if qk.to_str("/") != "1/2/0/2/2/2/0/2/1/3/3/3/1/0/3/0/0/0/3/3/2/1":
raise FailedError(
f"[43.63516355648167, 1.3744570239910097, 22] => '{qk.to_str('')}'"
)
print(f"OK")


def test_quadzone():
"""
Expand Down
1 change: 1 addition & 0 deletions python/its-quadkeys/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pygeotile==1.0.6
4 changes: 3 additions & 1 deletion python/its-quadkeys/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@
"the [JSon](https://www.json.org) [ETSI](https://www.etsi.org/committee/its) specification transcription.",
license="MIT",
platforms="LINUX",
install_requires=[],
install_requires=[
"pygeotile==1.0.6",
],
)
102 changes: 102 additions & 0 deletions python/its-vehicle/its-vehicle.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Unless otherwise noted, all units are standard unit, i.e. distances
# are in meters, latitudes and longitudes in degrees, times in seconds
# and frequencies in hertz, etc...
# Sections and keys that are commented out are optional (have a default)
# while sections and keys that are not commented out are mandatory.

[general]
# Instance ID (universally unique)
instance-id = ID

# Type of ITS messages to send
# - CAM
# - VAM (not implemented)
# - CPM (not implemented)
type = CAM

# Frequency to send ITS messages
report-freq = FREQ

# How to mirror the main broker; only useful if broker.mirror:host is defined
# - with mirror-self==true:
# when sending a message to broker.main, do not send it to broker.mirror;
# when receiving our messages back from broker.main, mirror them to
# broker.mirror.
# - with mirror-self==false (the default):
# when sending a message to broker.main, send it to broker.mirror; when
# receiving our messages back from broker.main, ignore them.
# mirror-self = BOOL

# Prefix for topics to publish on; must end with a slash, e.g.:
# - /
# - root/
# - /root/
# - deep/prefix/
# - /deep/prefix/
topic-pub-prefix = PREFIX/

# Prefix for topics to subscribe on (see topic-pub-prefix, above)
# Note: this is also the prefix used to publish on the mirror broker
# when mirror-self==false
topic-sub-prefix = PREFIX/

# Depth of the quadkeys to generate for MQTT topics
depth = DEPTH

# Types of ITS messages to subscribe to, space separated
messages = cam cpm denm

# Depth of the quadkeys to subscribe to, for each type of message above
depth-sub-cam = DEPTH
depth-sub-cpm = DEPTH
depth-sub-denm = DEPTH

# Speeds thresholds to lower the subscription level; each threshold
# decreases the subscrption depth by one; set as many thresdholds as
# needed, at least one, separated by a space
speed-thresholds = SPEED[ SPEED [...]]

[tracking]
# Length of message ID, in bytes
id-length = INT

[broker.main]
# There are two way to connect to the MQTT broker:
# - TCP/IP: set host and port, and not socket-path
# - a UNIX socket: set socket-path, not host and port
# Hostname or IP of the MQTT broker to connect to
host = HOSTNAME
# Port of the MQTT broker; default: 1883
# port = PORT
# Path of the UNIX socket
# socket-path = PATH

# Username and password to authenticate with against the broker;
# leave username empty or unset for no authentication, and leave
# password empty or unset for no password.
# username = USERNAME
# password = PASSWORD

# Client ID to connect as; default: general:instance_id
# client-id = ID

[broker.mirror]
# See broker.main, above, for descriptions
# If neither host nor socket-path are set, no mirroring is done
# host = HOST
# port = PORT
# socket-path = PATH
# username = USERNAME
# password = PASSWORD
# client-id = ID

[gpsd]
# Host and port gpsd listens on; defaults: 127.0.0.1, 2947
# host = HOST
# port = PORT
# How long to keep the last measurement when no new one comes (e.g. when
# in a tunnel...); default: 2.0
# persistence = SEC
# Type of heuristic to gather messages, either "order" or "timestamp";
# "order" is almost always the most sensible (see code), default: "order"
# heuristic = TYPE
Empty file.
Loading

0 comments on commit 67d8f75

Please sign in to comment.