Skip to content

Commit af6b9ca

Browse files
author
Driver Generator 2
committed
"Update SVM4x driver from SVM4X model version 2.0.0"
1 parent 111d06b commit af6b9ca

29 files changed

+1421
-129
lines changed

.gitlab-ci.yml

Lines changed: 69 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
include: https://gitlab/Sensirion/Python/ci-config-python/raw/master/gitlab-ci-template-v2.yml
1+
include:
2+
- project: Sensirion/Python/ci-config-python
3+
ref: master
4+
file: gitlab-ci-template-v2.yml
5+
26
stages:
37
- prepare
48
- build
59
- deploy
610

11+
variables:
12+
YQ_URL: https://github.com/mikefarah/yq/releases/download/v4.33.3/yq_linux_amd64
13+
714
check_rst_syntax:
815
stage: prepare
916
extends: .check_rst_syntax_v2
@@ -12,29 +19,28 @@ check_editorconfig:
1219
stage: prepare
1320
extends: .check_editorconfig_v2
1421

15-
1622
py3p6_linux_build:
1723
stage: build
1824
extends: .py3p6_linux_build_v2
19-
variables:
20-
PYTEST_ADDOPTS: '-m "not needs_device"'
25+
26+
py3p8_linux_sdist:
27+
stage: build
28+
extends: .py3p8_linux_sdist_v2
2129

2230
py3p8_linux_build:
2331
stage: build
2432
extends: .py3p8_linux_build_v2
25-
variables:
26-
PYTEST_ADDOPTS: '-m "not needs_device"'
27-
2833

2934
py3p8_64bit_win_build:
3035
stage: build
3136
extends: .py3p8_64bit_win_docker_build_v2
32-
variables:
33-
PYTEST_ADDOPTS: '-m "not needs_device"'
3437

3538
build_docs:
3639
stage: build
37-
extends: .build_docs_v2
40+
tags: [ linux, docker ]
41+
image: registry.gitlab.sensirion.lokal/sensirion/docker/docker-python:3.8-20.04-2.11.0
42+
variables:
43+
SPHINXOPTS: "-W --keep-going"
3844
script:
3945
- python setup.py install
4046
- pip install -r docs/requirements.txt
@@ -43,7 +49,7 @@ build_docs:
4349
after_script:
4450
- mv docs/_build/html/ public/ # everything in public/ will get published
4551
artifacts:
46-
paths: [public]
52+
paths: [ public ]
4753
expire_in: 1 week
4854
when: always
4955

@@ -54,7 +60,7 @@ deploy_stable:
5460
extends: .deploy_stable_v2
5561
environment:
5662
name: pypi.org
57-
url: https://pypi.org/project/sensirion_shdlc_svm41/
63+
url: https://pypi.org/project/sensirion_uart_svm4x/
5864
before_script:
5965
- pip install twine~=1.12.1
6066
script:
@@ -65,16 +71,11 @@ deploy_stable:
6571

6672
deploy_docs:
6773
stage: deploy
68-
tags: [linux, docker]
69-
image: registry.gitlab.sensirion.lokal/sensirion/docker/docker-python:3.8-20.04-2.6.0
70-
dependencies: []
71-
only: [master, tags]
74+
tags: [ linux, docker ]
75+
image: registry.gitlab.sensirion.lokal/sensirion/docker/docker-python:3.8-20.04-2.11.0
76+
dependencies: [ build_docs ]
77+
only: [ master, tags ]
7278
script:
73-
- python setup.py install
74-
- pip install -r docs/requirements.txt
75-
- cd docs
76-
- make html
77-
after_script:
7879
- chmod 777 ./ci/set_git_config.sh
7980
- ./ci/set_git_config.sh
8081
- chmod 777 ./ci/checkin_doc.sh
@@ -83,7 +84,52 @@ deploy_docs:
8384
TODO_check:
8485
stage: prepare
8586
image:
86-
name: registry.gitlab.sensirion.lokal/mso-sw/drivers/docker-driver-generator:0.2.0
87+
name: registry.gitlab.sensirion.lokal/mso-sw/drivers/docker-driver-generator:0.2.0
88+
tags: [ linux, docker ]
89+
script:
90+
- '! grep -rnw --exclude=.gitlab-ci.yml --exclude-dir=.git . -e "TODO"'
91+
92+
metadata_check:
93+
stage: prepare
94+
image:
95+
name: registry.gitlab.sensirion.lokal/mso-sw/drivers/docker-driver-generator:0.2.0
8796
tags: [linux, docker]
97+
before_script:
98+
- apt-get -qq update && apt-get -qq install -y wget
99+
- if ! [ -d downloads/ ]; then mkdir downloads; fi
100+
- if ! [ -e downloads/yq ]; then wget --no-verbose $YQ_URL -O downloads/yq; fi
101+
- cp downloads/yq /usr/local/bin/yq && chmod +x /usr/local/bin/yq
88102
script:
89-
- '! grep -rnw --exclude=.gitlab-ci.yml --exclude-dir=.git . -e "TODO"'
103+
# check if metadata.yml exists
104+
- >
105+
if ! [ -f "metadata.yml" ]; then
106+
echo "metadata.yml file not found"
107+
exit 1
108+
fi
109+
# check that dg_status is 'released'
110+
- export DG_STATUS=$(yq ".dg_status.[]" ./metadata.yml)
111+
- >
112+
if [ $DG_STATUS != "released" ]; then
113+
echo "dg_status in metadata.yml has to be 'released', not '$DG_STATUS'"
114+
exit 1
115+
fi
116+
# check that last_generated is not older than timestamp of last non-merge commit (+ 3 minutes)
117+
- export IS_MANUALLY_MODIFIED=$(yq ".is_manually_modified" ./metadata.yml)
118+
- >
119+
if [ $IS_MANUALLY_MODIFIED = false ]; then
120+
export LAST_GENERATED_TS=$(yq ".last_generated" ./metadata.yml)
121+
export LAST_GENERATED_TS_EPOCH=$(date -d "$LAST_GENERATED_TS" +%s)
122+
export LAST_NON_MERGE_COMMIT_TS=$(git log --format=%ad --date=iso-strict --no-merges -1)
123+
export COMMIT_TS_EPOCH=$(date -d "$LAST_NON_MERGE_COMMIT_TS" +%s)
124+
if [ $(($LAST_GENERATED_TS_EPOCH + 180)) -lt $COMMIT_TS_EPOCH ]; then
125+
echo "'last_generated' timestamp in metadata.yml is older than commit timestamp ($LAST_GENERATED_TS vs $LAST_NON_MERGE_COMMIT_TS)"
126+
exit 1
127+
fi
128+
fi
129+
# check that 'is_manually_modified' is set to true if commit is not from driver generator
130+
- export LAST_NON_MERGE_COMMIT_AUTHOR=$(git log --format=%an --no-merges -1)
131+
- >
132+
if ! [ "$LAST_NON_MERGE_COMMIT_AUTHOR" = "Driver Generator 2" ] && [ "$IS_MANUALLY_MODIFIED" = false ]; then
133+
echo "Last commit is not from Driver Generator. Please update 'is_manually_modified' in metadata.yml"
134+
exit 1
135+
fi

CHANGELOG.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ CHANGELOG
33

44
0.1.0
55
:::::
6-
- Initial release of SVM41 SHDLC driver
6+
- Initial release of SVM4X SHDLC driver

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
BSD 3-Clause License
22

3-
Copyright (c) 2022, Sensirion AG
3+
Copyright (c) 2023, Sensirion AG
44
All rights reserved.
55

66
Redistribution and use in source and binary forms, with or without

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include CHANGELOG.rst

README.md

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,54 @@
1-
# Python SHDLC Driver for Sensirion SVM41
1+
# Python UART Driver for Sensirion SVM4X
22

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

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

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

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

11+
unknown
1112

12-
## Development
13+
14+
15+
16+
## Connect the sensor
17+
18+
You can connect your sensor over the provided USB cable.
19+
For special setups check out the sensor pinout in the section below.
20+
21+
<details><summary>Sensor pinout</summary>
22+
<p>
23+
<img src="https://raw.githubusercontent.com/Sensirion/python-uart-svm4x/master/images/svm41-pinout-uart.png"
24+
width="300px" alt="sensor wiring picture">
25+
26+
| *Pin* | *Cable Color* | *Name* | *Description* | *Comments* |
27+
|-------|---------------|:------:|----------------|------------|
28+
| 1 | red | VDD | Supply Voltage | 3.3 or 5V
29+
| 2 | black | GND | Ground |
30+
| 3 | green | RX | UART: Transmission pin for communication |
31+
| 4 | yellow | TX | UART: Receiving pin for communication |
32+
| 5 | blue | SEL | Interface select | Leave floating or pull to VDD to select UART
33+
| 6 | purple | NC | Do not connect |
34+
35+
36+
</p>
37+
</details>
38+
39+
## Documentation & Quickstart
40+
41+
See the [documentation page](https://sensirion.github.io/python-uart-svm4x) for an API description and a
42+
[quickstart](https://sensirion.github.io/python-uart-svm4x/execute-measurements.html) example.
43+
44+
45+
## Contributing
1346

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

2053
### Check coding style
2154

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

37-
### Run tests
38-
39-
Unit tests can be run with [`pytest`](https://pytest.org/):
40-
41-
```bash
42-
pip install -e .[test] # Install requirements
43-
pytest -m "not needs_device" # Run tests without hardware
44-
pytest # Run all tests
45-
pytest -m "needs_device" # Run all tests for SVM41
46-
47-
```
48-
49-
The tests with the marker `needs_device` have following requirements:
50-
51-
- The SVM41 sensor must be connected to a Serial Port of your developement machine.
52-
- Pass the serial port where the sensor is connected with
53-
`--serial-port`, e.g. `pytest --serial-port=COM7`
54-
55-
56-
### Build documentation
57-
58-
The documentation can be built with [Sphinx](http://www.sphinx-doc.org/):
59-
60-
```bash
61-
python setup.py install # Install package
62-
pip install -r docs/requirements.txt # Install requirements
63-
sphinx-versioning build docs docs/_build/html # Build documentation
64-
```
65-
6670
## License
6771

6872
See [LICENSE](LICENSE).

ci/checkin_doc.sh

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,20 @@ set -euv -o pipefail
77
git clone "git@gitlab:${CI_PROJECT_PATH}.git" html
88
cd html
99
git checkout gh-pages
10-
rm empty.txt
10+
rm -f empty.txt
11+
rm -f *.html
12+
rm -f *.js
13+
rm -rf _*
1114
cd ..
12-
mv docs/_build/html/* html/
15+
# make sure to copy .nojekyll
16+
cp -rf public/.[!.]* public/* html
1317
cd html
1418
git add .
15-
git commit -m"Automatic doc update:${CI_COMMIT_SHORT_SHA}"
16-
git push
19+
20+
if git diff-index --quiet HEAD --
21+
then
22+
exit 0
23+
fi
24+
25+
git commit -m"Automatic doc update: ${CI_COMMIT_SHORT_SHA}"
26+
git push

conftest.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
# (c) Copyright 2022 Sensirion AG, Switzerland
33

44
import pytest
5-
from sensirion_shdlc_driver import ShdlcSerialPort, ShdlcConnection
5+
from sensirion_driver_adapters.mocks.mock_shdlc_channel_provider import ShdlcMockPortChannelProvider
6+
from sensirion_driver_adapters.shdlc_adapter.shdlc_serial_channel_provider import ShdlcSerialPortChannelProvider
7+
from sensirion_uart_svm4x.response_provider import Svm4xResponseProvider
68

79

810
def pytest_addoption(parser):
@@ -43,9 +45,11 @@ def pytest_report_header(config):
4345

4446

4547
@pytest.fixture(scope="session")
46-
def shdlc_port(request):
47-
serial_port = _get_serial_port(request.config, validate=True)
48+
def channel_provider(request):
49+
serial_port = _get_serial_port(request.config, validate=False)
4850
serial_bitrate = _get_serial_bitrate(request.config)
49-
with ShdlcSerialPort(serial_port, serial_bitrate) as port:
50-
yield port
51-
51+
if serial_port is not None:
52+
yield ShdlcSerialPortChannelProvider(serial_port=serial_port,
53+
serial_baud_rate=serial_bitrate)
54+
else:
55+
yield ShdlcMockPortChannelProvider(response_provider=Svm4xResponseProvider())

docs/api.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
API Documentation
22
=================
33

4-
SVM41
5-
=====
4+
SVM4X
5+
-----
66

7-
Svm41Device
7+
Svm4xDevice
88
~~~~~~~~~~~
99

1010

11-
.. automodule:: sensirion_shdlc_svm41.device
11+
.. automodule:: sensirion_uart_svm4x.device
1212

1313
Commands
1414
~~~~~~~~
1515

16-
.. automodule:: sensirion_shdlc_svm41.commands
16+
.. automodule:: sensirion_uart_svm4x.commands
1717
:exclude-members: __init__
1818

1919

2020
Result Types
2121
~~~~~~~~~~~~
2222

23-
.. automodule:: sensirion_shdlc_svm41.result_types
23+
.. automodule:: sensirion_uart_svm4x.result_types
2424
:exclude-members: __init__
2525

docs/build-documentation.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Build documentation
2+
===================
3+
4+
The documentation is built with `Sphinx <http://www.sphinx-doc.org>`_:
5+
6+
.. code-block:: bash
7+
8+
python setup.py install # Install package
9+
pip install -r docs/requirements.txt # Install requirements
10+
cd docs # Change to docs folder
11+
make html # Build documentation
12+
13+
14+
The generated documentation is located in docs/_build/html.

0 commit comments

Comments
 (0)