Skip to content

Commit

Permalink
add poetry and all notify (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
svhoy committed Jan 31, 2024
1 parent 2eddd4d commit 5a102b5
Show file tree
Hide file tree
Showing 7 changed files with 792 additions and 19 deletions.
22 changes: 16 additions & 6 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,28 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11"]
python-version: ["3.12","3.11"]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install poetry
run: |
python -m pip install poetry
- name: Config Poetry & Install dependencies
run: |
poetry config virtualenvs.create true
poetry config virtualenvs.in-project true
- name: Define a cache for the virtual environment based on the dependencies lock file
uses: actions/cache@v3
with:
path: ./.venv
key: venv-${{ hashFiles('poetry.lock') }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint
pip install -r requirements.txt
poetry install --no-interaction --no-root
- name: Analysing the code with pylint
run: |
pylint $(git ls-files '*.py')
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.venv/
.vscode/

.mypy_cache
__pycache__/
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12.1
12 changes: 6 additions & 6 deletions apps/sit_gateway/adapter/ble.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ async def on_distance_notification(self, sender: int, data: bytearray):
) # Datatype 15 char[] (c string) and f->float and I->uint32_t and H->uint8_t
msg_type = msg_type_b.decode("utf-8")
state = state_b.decode("utf-8")
# logger.debug("From Handle {} Msg_Type: {}".format(sender, msg_type))
# logger.debug("From Handle {} Sequence: {}".format(sender, sequence))
logger.debug("From Handle {} Msg_Type: {}".format(sender, msg_type))
logger.debug("From Handle {} Sequence: {}".format(sender, sequence))
logger.debug(
"From Handle {} Measurements: {}".format(sender, measurements)
)
# logger.debug("From Handle {} Distance: {}".format(sender, distance))
# logger.debug("From Handle {} NLOS: {}".format(sender, nlos))
# logger.debug("From Handle {} RSSI: {}".format(sender, rssi))
# logger.debug("From Handle {} FPI: {}".format(sender, fpi))
logger.debug("From Handle {} Distance: {}".format(sender, distance))
logger.debug("From Handle {} NLOS: {}".format(sender, nlos))
logger.debug("From Handle {} RSSI: {}".format(sender, rssi))
logger.debug("From Handle {} FPI: {}".format(sender, fpi))
await self._callback(
responder, sequence, measurements, distance, nlos, rssi, fpi
)
Expand Down
18 changes: 14 additions & 4 deletions apps/sit_gateway/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def __init__(self) -> None:

self.test_id = None
self.calibration_id: int = 0
self._distance_notify_tasks = set()

def set_dependencies(self, tg, bus):
self.taskGroup = tg
Expand Down Expand Up @@ -118,23 +119,31 @@ async def start_measurement(
await self.ble_send_json(
"6ba1de6b-3ab6-4d77-9ea1-cb6422720003", command, initiator_device
)
self._distance_notify_task = self.taskGroup.create_task(
self.enable_notify(initiator_device)

# TODO Notify für alle Devices Erstellen und dann in ein Set Speichern
# beachte die Hinweiße hier: https://docs.python.org/3/library/asyncio-task.html#asyncio.create_task
self.taskGroup.create_task(
self.enable_notify(initiator_device),
name="BLE Notify" + initiator_device,
)
for responder in responder_devices:
self.taskGroup.create_task(
self.enable_notify(responder), name="BLE Notify" + responder
)

async def stop_measurement(self):
command = {"type": "measurement_msg", "command": "stop"}
for responder in self.responder_devices:
await self.ble_send_json(
"6ba1de6b-3ab6-4d77-9ea1-cb6422720003", command, responder
)
cancel_task("BLE Notify" + responder)
await self.ble_send_json(
"6ba1de6b-3ab6-4d77-9ea1-cb6422720003",
command,
self.initiator_device,
)
if self._distance_notify_task is not None:
self._distance_notify_task.cancel()
cancel_task("BLE Notify" + self.initiator_device)
self.test_id = None

async def enable_notify(self, initiator_device):
Expand All @@ -152,6 +161,7 @@ async def enable_notify(self, initiator_device):
async def distance_notifcation(
self, responder, sequence, measurement, distance, nlos, rssi, fpi
):
print(f"Test: {distance}")
if self.test_id is not None:
await self.bus.handle(
events.TestMeasurement(
Expand Down
Loading

0 comments on commit 5a102b5

Please sign in to comment.