Skip to content

Commit

Permalink
"Update SVM4x driver from SVM4X model version 2.0.0"
Browse files Browse the repository at this point in the history
  • Loading branch information
Driver Generator 2 committed Oct 19, 2023
1 parent 111d06b commit af6b9ca
Show file tree
Hide file tree
Showing 29 changed files with 1,421 additions and 129 deletions.
92 changes: 69 additions & 23 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
include: https://gitlab/Sensirion/Python/ci-config-python/raw/master/gitlab-ci-template-v2.yml
include:
- project: Sensirion/Python/ci-config-python
ref: master
file: gitlab-ci-template-v2.yml

stages:
- prepare
- build
- deploy

variables:
YQ_URL: https://github.com/mikefarah/yq/releases/download/v4.33.3/yq_linux_amd64

check_rst_syntax:
stage: prepare
extends: .check_rst_syntax_v2
Expand All @@ -12,29 +19,28 @@ check_editorconfig:
stage: prepare
extends: .check_editorconfig_v2


py3p6_linux_build:
stage: build
extends: .py3p6_linux_build_v2
variables:
PYTEST_ADDOPTS: '-m "not needs_device"'

py3p8_linux_sdist:
stage: build
extends: .py3p8_linux_sdist_v2

py3p8_linux_build:
stage: build
extends: .py3p8_linux_build_v2
variables:
PYTEST_ADDOPTS: '-m "not needs_device"'


py3p8_64bit_win_build:
stage: build
extends: .py3p8_64bit_win_docker_build_v2
variables:
PYTEST_ADDOPTS: '-m "not needs_device"'

build_docs:
stage: build
extends: .build_docs_v2
tags: [ linux, docker ]
image: registry.gitlab.sensirion.lokal/sensirion/docker/docker-python:3.8-20.04-2.11.0
variables:
SPHINXOPTS: "-W --keep-going"
script:
- python setup.py install
- pip install -r docs/requirements.txt
Expand All @@ -43,7 +49,7 @@ build_docs:
after_script:
- mv docs/_build/html/ public/ # everything in public/ will get published
artifacts:
paths: [public]
paths: [ public ]
expire_in: 1 week
when: always

Expand All @@ -54,7 +60,7 @@ deploy_stable:
extends: .deploy_stable_v2
environment:
name: pypi.org
url: https://pypi.org/project/sensirion_shdlc_svm41/
url: https://pypi.org/project/sensirion_uart_svm4x/
before_script:
- pip install twine~=1.12.1
script:
Expand All @@ -65,16 +71,11 @@ deploy_stable:

deploy_docs:
stage: deploy
tags: [linux, docker]
image: registry.gitlab.sensirion.lokal/sensirion/docker/docker-python:3.8-20.04-2.6.0
dependencies: []
only: [master, tags]
tags: [ linux, docker ]
image: registry.gitlab.sensirion.lokal/sensirion/docker/docker-python:3.8-20.04-2.11.0
dependencies: [ build_docs ]
only: [ master, tags ]
script:
- python setup.py install
- pip install -r docs/requirements.txt
- cd docs
- make html
after_script:
- chmod 777 ./ci/set_git_config.sh
- ./ci/set_git_config.sh
- chmod 777 ./ci/checkin_doc.sh
Expand All @@ -83,7 +84,52 @@ deploy_docs:
TODO_check:
stage: prepare
image:
name: registry.gitlab.sensirion.lokal/mso-sw/drivers/docker-driver-generator:0.2.0
name: registry.gitlab.sensirion.lokal/mso-sw/drivers/docker-driver-generator:0.2.0
tags: [ linux, docker ]
script:
- '! grep -rnw --exclude=.gitlab-ci.yml --exclude-dir=.git . -e "TODO"'

metadata_check:
stage: prepare
image:
name: registry.gitlab.sensirion.lokal/mso-sw/drivers/docker-driver-generator:0.2.0
tags: [linux, docker]
before_script:
- apt-get -qq update && apt-get -qq install -y wget
- if ! [ -d downloads/ ]; then mkdir downloads; fi
- if ! [ -e downloads/yq ]; then wget --no-verbose $YQ_URL -O downloads/yq; fi
- cp downloads/yq /usr/local/bin/yq && chmod +x /usr/local/bin/yq
script:
- '! grep -rnw --exclude=.gitlab-ci.yml --exclude-dir=.git . -e "TODO"'
# check if metadata.yml exists
- >
if ! [ -f "metadata.yml" ]; then
echo "metadata.yml file not found"
exit 1
fi
# check that dg_status is 'released'
- export DG_STATUS=$(yq ".dg_status.[]" ./metadata.yml)
- >
if [ $DG_STATUS != "released" ]; then
echo "dg_status in metadata.yml has to be 'released', not '$DG_STATUS'"
exit 1
fi
# check that last_generated is not older than timestamp of last non-merge commit (+ 3 minutes)
- export IS_MANUALLY_MODIFIED=$(yq ".is_manually_modified" ./metadata.yml)
- >
if [ $IS_MANUALLY_MODIFIED = false ]; then
export LAST_GENERATED_TS=$(yq ".last_generated" ./metadata.yml)
export LAST_GENERATED_TS_EPOCH=$(date -d "$LAST_GENERATED_TS" +%s)
export LAST_NON_MERGE_COMMIT_TS=$(git log --format=%ad --date=iso-strict --no-merges -1)
export COMMIT_TS_EPOCH=$(date -d "$LAST_NON_MERGE_COMMIT_TS" +%s)
if [ $(($LAST_GENERATED_TS_EPOCH + 180)) -lt $COMMIT_TS_EPOCH ]; then
echo "'last_generated' timestamp in metadata.yml is older than commit timestamp ($LAST_GENERATED_TS vs $LAST_NON_MERGE_COMMIT_TS)"
exit 1
fi
fi
# check that 'is_manually_modified' is set to true if commit is not from driver generator
- export LAST_NON_MERGE_COMMIT_AUTHOR=$(git log --format=%an --no-merges -1)
- >
if ! [ "$LAST_NON_MERGE_COMMIT_AUTHOR" = "Driver Generator 2" ] && [ "$IS_MANUALLY_MODIFIED" = false ]; then
echo "Last commit is not from Driver Generator. Please update 'is_manually_modified' in metadata.yml"
exit 1
fi
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ CHANGELOG

0.1.0
:::::
- Initial release of SVM41 SHDLC driver
- Initial release of SVM4X SHDLC driver
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3-Clause License

Copyright (c) 2022, Sensirion AG
Copyright (c) 2023, Sensirion AG
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include CHANGELOG.rst
76 changes: 40 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,54 @@
# Python SHDLC Driver for Sensirion SVM41
# Python UART Driver for Sensirion SVM4X

This repository contains the Python driver to communicate with a Sensirion SVM41 sensor over UART using the SHDLC protocol.
This repository contains the Python driver to communicate with a Sensirion SVM4X sensor over UART using the SHDLC protocol.

<img src="https://raw.githubusercontent.com/Sensirion/python-uart-svm4x/master/images/svm4x.png"
width="300px" alt="SVM4X picture">

## Usage
Click [here](https://www.sensirion.com/my-sgp-ek/) to learn more about the Sensirion SVM4X sensor.

See user manual at
[https://sensirion.github.io](https://sensirion.github.io/python-uart-svm41).

unknown

## Development



## Connect the sensor

You can connect your sensor over the provided USB cable.
For special setups check out the sensor pinout in the section below.

<details><summary>Sensor pinout</summary>
<p>
<img src="https://raw.githubusercontent.com/Sensirion/python-uart-svm4x/master/images/svm41-pinout-uart.png"
width="300px" alt="sensor wiring picture">

| *Pin* | *Cable Color* | *Name* | *Description* | *Comments* |
|-------|---------------|:------:|----------------|------------|
| 1 | red | VDD | Supply Voltage | 3.3 or 5V
| 2 | black | GND | Ground |
| 3 | green | RX | UART: Transmission pin for communication |
| 4 | yellow | TX | UART: Receiving pin for communication |
| 5 | blue | SEL | Interface select | Leave floating or pull to VDD to select UART
| 6 | purple | NC | Do not connect |


</p>
</details>

## Documentation & Quickstart

See the [documentation page](https://sensirion.github.io/python-uart-svm4x) for an API description and a
[quickstart](https://sensirion.github.io/python-uart-svm4x/execute-measurements.html) example.


## Contributing

We develop and test this driver using our company internal tools (version
control, continuous integration, code review etc.) and automatically
synchronize the `master` branch with GitHub. But this doesn't mean that we
don't respond to issues or don't accept pull requests on GitHub. In fact,
you're very welcome to open issues or create pull requests :)
you're very welcome to open issues or create pull requests :-)

### Check coding style

Expand All @@ -34,35 +67,6 @@ pip install editorconfig-checker==2.0.3 # Install requirements
editorconfig-checker # Run check
```

### Run tests

Unit tests can be run with [`pytest`](https://pytest.org/):

```bash
pip install -e .[test] # Install requirements
pytest -m "not needs_device" # Run tests without hardware
pytest # Run all tests
pytest -m "needs_device" # Run all tests for SVM41

```

The tests with the marker `needs_device` have following requirements:

- The SVM41 sensor must be connected to a Serial Port of your developement machine.
- Pass the serial port where the sensor is connected with
`--serial-port`, e.g. `pytest --serial-port=COM7`


### Build documentation

The documentation can be built with [Sphinx](http://www.sphinx-doc.org/):

```bash
python setup.py install # Install package
pip install -r docs/requirements.txt # Install requirements
sphinx-versioning build docs docs/_build/html # Build documentation
```

## License

See [LICENSE](LICENSE).
18 changes: 14 additions & 4 deletions ci/checkin_doc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,20 @@ set -euv -o pipefail
git clone "git@gitlab:${CI_PROJECT_PATH}.git" html
cd html
git checkout gh-pages
rm empty.txt
rm -f empty.txt
rm -f *.html
rm -f *.js
rm -rf _*
cd ..
mv docs/_build/html/* html/
# make sure to copy .nojekyll
cp -rf public/.[!.]* public/* html
cd html
git add .
git commit -m"Automatic doc update:${CI_COMMIT_SHORT_SHA}"
git push

if git diff-index --quiet HEAD --
then
exit 0
fi

git commit -m"Automatic doc update: ${CI_COMMIT_SHORT_SHA}"
git push
16 changes: 10 additions & 6 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
# (c) Copyright 2022 Sensirion AG, Switzerland

import pytest
from sensirion_shdlc_driver import ShdlcSerialPort, ShdlcConnection
from sensirion_driver_adapters.mocks.mock_shdlc_channel_provider import ShdlcMockPortChannelProvider
from sensirion_driver_adapters.shdlc_adapter.shdlc_serial_channel_provider import ShdlcSerialPortChannelProvider
from sensirion_uart_svm4x.response_provider import Svm4xResponseProvider


def pytest_addoption(parser):
Expand Down Expand Up @@ -43,9 +45,11 @@ def pytest_report_header(config):


@pytest.fixture(scope="session")
def shdlc_port(request):
serial_port = _get_serial_port(request.config, validate=True)
def channel_provider(request):
serial_port = _get_serial_port(request.config, validate=False)
serial_bitrate = _get_serial_bitrate(request.config)
with ShdlcSerialPort(serial_port, serial_bitrate) as port:
yield port

if serial_port is not None:
yield ShdlcSerialPortChannelProvider(serial_port=serial_port,
serial_baud_rate=serial_bitrate)
else:
yield ShdlcMockPortChannelProvider(response_provider=Svm4xResponseProvider())
12 changes: 6 additions & 6 deletions docs/api.rst
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
API Documentation
=================

SVM41
=====
SVM4X
-----

Svm41Device
Svm4xDevice
~~~~~~~~~~~


.. automodule:: sensirion_shdlc_svm41.device
.. automodule:: sensirion_uart_svm4x.device

Commands
~~~~~~~~

.. automodule:: sensirion_shdlc_svm41.commands
.. automodule:: sensirion_uart_svm4x.commands
:exclude-members: __init__


Result Types
~~~~~~~~~~~~

.. automodule:: sensirion_shdlc_svm41.result_types
.. automodule:: sensirion_uart_svm4x.result_types
:exclude-members: __init__

14 changes: 14 additions & 0 deletions docs/build-documentation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Build documentation
===================

The documentation is built with `Sphinx <http://www.sphinx-doc.org>`_:

.. code-block:: bash
python setup.py install # Install package
pip install -r docs/requirements.txt # Install requirements
cd docs # Change to docs folder
make html # Build documentation
The generated documentation is located in docs/_build/html.
Loading

0 comments on commit af6b9ca

Please sign in to comment.