From 370ad5ac85232e79b3c953417c29ba86611e2d09 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Tue, 14 Apr 2020 18:33:49 +0200 Subject: [PATCH 01/42] add descriptor unit test --- test/module/test_descriptor.py | 61 ++++++++++++++++++++++++++++++++++ test/pytest.ini | 2 +- test/test_config.yaml | 9 +++++ 3 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 test/module/test_descriptor.py diff --git a/test/module/test_descriptor.py b/test/module/test_descriptor.py new file mode 100644 index 0000000..c064170 --- /dev/null +++ b/test/module/test_descriptor.py @@ -0,0 +1,61 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +"""! + ____ ____ ______ __ __ __ _____ + / __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ / + / __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ < + / /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / ___/ / +/_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ /____/ + German BOS Information Script + by Bastian Schroll + +@file: test_descriptor.py +@date: 14.04.2020 +@author: Bastian Schroll +@description: Unittests for BOSWatch. File have to run as "pytest" unittest +""" +# problem of the pytest fixtures +# pylint: disable=redefined-outer-name +import logging +import pytest +from boswatch.utils import paths + +from boswatch.configYaml import ConfigYAML +from boswatch.packet import Packet +from module.descriptor import BoswatchModule as Descriptor + + +def setup_method(method): + logging.debug("[TEST] %s.%s", method.__module__, method.__name__) + + +@pytest.fixture +def makeDescriptor(): + config = ConfigYAML() + assert config.loadConfigFile(paths.TEST_PATH + "test_config.yaml") is True + descriptor = Descriptor(config.get("descriptor_test")) + return descriptor + + +@pytest.fixture +def makePacket(): + packet = Packet() + return packet + + +def test_descriptorFoundFirst(makeDescriptor, makePacket): + makePacket.set("tone", "12345") + makePacket = makeDescriptor.doWork(makePacket) + assert makePacket.get("description") == "Test 12345" + + +def test_descriptorFoundSecond(makeDescriptor, makePacket): + makePacket.set("tone", "23456") + makePacket = makeDescriptor.doWork(makePacket) + assert makePacket.get("description") == "Test 23456" + + +def test_descriptorNotFound(makeDescriptor, makePacket): + makePacket.set("tone", "99999") + makePacket = makeDescriptor.doWork(makePacket) + assert makePacket.get("description") == "99999" diff --git a/test/pytest.ini b/test/pytest.ini index 6e8fc02..e5d4311 100644 --- a/test/pytest.ini +++ b/test/pytest.ini @@ -8,7 +8,7 @@ # by Bastian Schroll [pytest] -addopts = -v --pep8 --flakes --cov=boswatch/ --cov-report=term-missing --log-level=CRITICAL +addopts = -v --pep8 --flakes --cov=boswatch/ --cov=module/ --cov plugin/ --cov-report=term-missing --log-level=CRITICAL # classic or progress console_output_style = progress diff --git a/test/test_config.yaml b/test/test_config.yaml index 6840f26..f20f454 100644 --- a/test/test_config.yaml +++ b/test/test_config.yaml @@ -30,3 +30,12 @@ list1: - two - three - string1 + +descriptor_test: + - scanField: tone + descrField: description + descriptions: + - for: 12345 + add: Test 12345 + - for: 23456 + add: Test 23456 \ No newline at end of file From e5141c186d3dfad983eac9c3fb6ea420a0507f4e Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Tue, 14 Apr 2020 18:47:12 +0200 Subject: [PATCH 02/42] add comments --- test/module/test_descriptor.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/module/test_descriptor.py b/test/module/test_descriptor.py index c064170..6309e79 100644 --- a/test/module/test_descriptor.py +++ b/test/module/test_descriptor.py @@ -31,6 +31,7 @@ def setup_method(method): @pytest.fixture def makeDescriptor(): + """!Build a descriptor object with loaded configuration""" config = ConfigYAML() assert config.loadConfigFile(paths.TEST_PATH + "test_config.yaml") is True descriptor = Descriptor(config.get("descriptor_test")) @@ -39,23 +40,27 @@ def makeDescriptor(): @pytest.fixture def makePacket(): + """!Build a BW Packet object""" packet = Packet() return packet def test_descriptorFoundFirst(makeDescriptor, makePacket): + """!Run descriptor on the first entry in list""" makePacket.set("tone", "12345") makePacket = makeDescriptor.doWork(makePacket) assert makePacket.get("description") == "Test 12345" def test_descriptorFoundSecond(makeDescriptor, makePacket): + """!Run descriptor on the second entry in list""" makePacket.set("tone", "23456") makePacket = makeDescriptor.doWork(makePacket) assert makePacket.get("description") == "Test 23456" def test_descriptorNotFound(makeDescriptor, makePacket): + """!Run descriptor on a non existent field""" makePacket.set("tone", "99999") makePacket = makeDescriptor.doWork(makePacket) assert makePacket.get("description") == "99999" From 7ee5df0616c01ac6ee99b3deb5ddd5cba00ff6e6 Mon Sep 17 00:00:00 2001 From: Jan Speller Date: Tue, 14 Apr 2020 22:17:53 +0200 Subject: [PATCH 03/42] fix docu zvei->tone --- docu/docs/modul/descriptor.md | 2 +- docu/docs/modul/regex_filter.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docu/docs/modul/descriptor.md b/docu/docs/modul/descriptor.md index a472b0f..73cdc50 100644 --- a/docu/docs/modul/descriptor.md +++ b/docu/docs/modul/descriptor.md @@ -34,7 +34,7 @@ Informationen zum Aufbau eines [BOSWatch Pakets](../develop/packet.md) - type: module res: descriptor config: - - scanField: zvei + - scanField: tone descrField: description wildcard: "{DESCR}" descriptions: diff --git a/docu/docs/modul/regex_filter.md b/docu/docs/modul/regex_filter.md index 77e0a1d..9e69db2 100644 --- a/docu/docs/modul/regex_filter.md +++ b/docu/docs/modul/regex_filter.md @@ -43,7 +43,7 @@ Vereinfacht kann man sagen, dass einzelnen Router ODER-verknüpft und die jeweil config: - name: "Zvei filter" checks: - - field: zvei + - field: tone regex: "65[0-9]{3}" # all zvei with starting 65 - name: "FMS Stat 3" checks: From 806a3d866921deb10c819fbc68e6eda758196419 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Wed, 15 Apr 2020 08:35:00 +0200 Subject: [PATCH 04/42] add non existent field test --- test/module/test_descriptor.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/module/test_descriptor.py b/test/module/test_descriptor.py index 6309e79..67cd4e3 100644 --- a/test/module/test_descriptor.py +++ b/test/module/test_descriptor.py @@ -60,7 +60,13 @@ def test_descriptorFoundSecond(makeDescriptor, makePacket): def test_descriptorNotFound(makeDescriptor, makePacket): - """!Run descriptor on a non existent field""" + """!Run descriptor no matching data found""" makePacket.set("tone", "99999") makePacket = makeDescriptor.doWork(makePacket) assert makePacket.get("description") == "99999" + + +def test_descriptorScanFieldNotAvailable(makeDescriptor, makePacket): + """!Run descriptor on a non existent scanField""" + makePacket = makeDescriptor.doWork(makePacket) + assert makePacket.get("description") == None \ No newline at end of file From 61819cda0879761255d66461934fec5daa458ea1 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Wed, 15 Apr 2020 08:52:44 +0200 Subject: [PATCH 05/42] little fix --- test/module/test_descriptor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/module/test_descriptor.py b/test/module/test_descriptor.py index 67cd4e3..48bb2eb 100644 --- a/test/module/test_descriptor.py +++ b/test/module/test_descriptor.py @@ -69,4 +69,4 @@ def test_descriptorNotFound(makeDescriptor, makePacket): def test_descriptorScanFieldNotAvailable(makeDescriptor, makePacket): """!Run descriptor on a non existent scanField""" makePacket = makeDescriptor.doWork(makePacket) - assert makePacket.get("description") == None \ No newline at end of file + assert makePacket.get("description") is None \ No newline at end of file From 8e4dba28e3480384c7139fd43aa0b29aef06ba5b Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Wed, 15 Apr 2020 09:24:02 +0200 Subject: [PATCH 06/42] PEP8 new line at end --- test/module/test_descriptor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/module/test_descriptor.py b/test/module/test_descriptor.py index 48bb2eb..c2d63a2 100644 --- a/test/module/test_descriptor.py +++ b/test/module/test_descriptor.py @@ -69,4 +69,4 @@ def test_descriptorNotFound(makeDescriptor, makePacket): def test_descriptorScanFieldNotAvailable(makeDescriptor, makePacket): """!Run descriptor on a non existent scanField""" makePacket = makeDescriptor.doWork(makePacket) - assert makePacket.get("description") is None \ No newline at end of file + assert makePacket.get("description") is None From 79b66a8668b94403ed4878d3ca8e095f13763e9f Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Fri, 17 Apr 2020 09:44:00 +0200 Subject: [PATCH 07/42] add basic docs build workflow --- .github/workflows/build_docs.yml | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .github/workflows/build_docs.yml diff --git a/.github/workflows/build_docs.yml b/.github/workflows/build_docs.yml new file mode 100644 index 0000000..7634d46 --- /dev/null +++ b/.github/workflows/build_docs.yml @@ -0,0 +1,33 @@ +name: build_docs + +#on: push +on: [push, pull_request] + branches: + - master + - develop + paths: + - 'docu/**' + +jobs: + + build_docs: + name: Build documentation + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v1 + + - name: Build doxygen + uses: mattnotmitt/doxygen-action@v1 + with: + working-directory: './' + doxyfile-path: 'docu/doxygen.ini' + + - name: Build mkdocs + run: | + python -m pip install --upgrade pip + pip install mkdocs + mkdocs build -f docu/mkdocs.yml + + - name: Upload to docs-server From 61a61d1f25e87b3059938aeb1d6d0fb3ec414af3 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Fri, 17 Apr 2020 09:55:40 +0200 Subject: [PATCH 08/42] basic test --- .github/workflows/build_docs.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/build_docs.yml b/.github/workflows/build_docs.yml index 7634d46..a7f438b 100644 --- a/.github/workflows/build_docs.yml +++ b/.github/workflows/build_docs.yml @@ -1,12 +1,6 @@ name: build_docs -#on: push on: [push, pull_request] - branches: - - master - - develop - paths: - - 'docu/**' jobs: From 195215ac464dc515d7d73ea8ddc536a5a3ffe087 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Fri, 17 Apr 2020 09:56:31 +0200 Subject: [PATCH 09/42] add missing run --- .github/workflows/build_docs.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build_docs.yml b/.github/workflows/build_docs.yml index a7f438b..8ed2b59 100644 --- a/.github/workflows/build_docs.yml +++ b/.github/workflows/build_docs.yml @@ -25,3 +25,4 @@ jobs: mkdocs build -f docu/mkdocs.yml - name: Upload to docs-server + run: echo 'test' From 2767b6f60301cc2397ba55d98bff5e55363ea642 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Fri, 17 Apr 2020 09:58:17 +0200 Subject: [PATCH 10/42] fix mkdocs call --- .github/workflows/build_docs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_docs.yml b/.github/workflows/build_docs.yml index 8ed2b59..51e1c62 100644 --- a/.github/workflows/build_docs.yml +++ b/.github/workflows/build_docs.yml @@ -22,7 +22,7 @@ jobs: run: | python -m pip install --upgrade pip pip install mkdocs - mkdocs build -f docu/mkdocs.yml + python -m mkdocs build -f docu/mkdocs.yml - name: Upload to docs-server run: echo 'test' From 985820540dfc8ed2800ca84c9c3c4a222010fdd6 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Fri, 17 Apr 2020 10:13:24 +0200 Subject: [PATCH 11/42] add SCP upload --- .github/workflows/build_docs.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build_docs.yml b/.github/workflows/build_docs.yml index 51e1c62..984e59a 100644 --- a/.github/workflows/build_docs.yml +++ b/.github/workflows/build_docs.yml @@ -25,4 +25,11 @@ jobs: python -m mkdocs build -f docu/mkdocs.yml - name: Upload to docs-server - run: echo 'test' + uses: appleboy/scp-action@master + with: + host: ${{ secrets.SCP_HOST }} + port: ${{ secrets.SCP_PORT }} + username: ${{ secrets.SCP_USERNAME }} + password: ${{ secrets.SCP_PASSWORD }} + source: "docu/site/**" + target: ${{ secrets.SCP_TARGET_PATH }} \ No newline at end of file From 4170e31355a67b91284bf8d525f718af7834c6fe Mon Sep 17 00:00:00 2001 From: Schrolli91 Date: Fri, 17 Apr 2020 23:17:27 +0200 Subject: [PATCH 12/42] update workflow --- .github/workflows/build_docs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_docs.yml b/.github/workflows/build_docs.yml index 984e59a..0270ece 100644 --- a/.github/workflows/build_docs.yml +++ b/.github/workflows/build_docs.yml @@ -1,6 +1,6 @@ name: build_docs -on: [push, pull_request] +on: [push] jobs: From b2beafe190484f5b1ef9712f48150c7e3cc67069 Mon Sep 17 00:00:00 2001 From: Schrolli91 Date: Fri, 17 Apr 2020 23:19:16 +0200 Subject: [PATCH 13/42] test --- docu/docs/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docu/docs/index.md b/docu/docs/index.md index 114a3a5..7401f93 100644 --- a/docu/docs/index.md +++ b/docu/docs/index.md @@ -1,4 +1,4 @@ -#
BOSWatch 3
+#
BOSWatch 3 test
---
From 6b0724baf5e17cf1336f0e60c57577346e8cf41d Mon Sep 17 00:00:00 2001 From: Schrolli91 Date: Fri, 17 Apr 2020 23:22:09 +0200 Subject: [PATCH 14/42] test --- docu/docs/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docu/docs/index.md b/docu/docs/index.md index 7401f93..114a3a5 100644 --- a/docu/docs/index.md +++ b/docu/docs/index.md @@ -1,4 +1,4 @@ -#
BOSWatch 3 test
+#
BOSWatch 3
---
From 72c795562b6224d8038763ecb95cbe6fdef65107 Mon Sep 17 00:00:00 2001 From: Schrolli91 Date: Fri, 17 Apr 2020 23:26:09 +0200 Subject: [PATCH 15/42] add strip_components --- .github/workflows/build_docs.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build_docs.yml b/.github/workflows/build_docs.yml index 0270ece..dccc187 100644 --- a/.github/workflows/build_docs.yml +++ b/.github/workflows/build_docs.yml @@ -32,4 +32,5 @@ jobs: username: ${{ secrets.SCP_USERNAME }} password: ${{ secrets.SCP_PASSWORD }} source: "docu/site/**" - target: ${{ secrets.SCP_TARGET_PATH }} \ No newline at end of file + target: ${{ secrets.SCP_TARGET_PATH }} + strip_components: 2 \ No newline at end of file From 85b7cb34685a73cbbcb2c086c93d212dbd4e7526 Mon Sep 17 00:00:00 2001 From: Schrolli91 Date: Fri, 17 Apr 2020 23:38:14 +0200 Subject: [PATCH 16/42] add py 3.8 for tests --- .github/workflows/run_pytest.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/run_pytest.yml b/.github/workflows/run_pytest.yml index 1b12138..cd60fa9 100644 --- a/.github/workflows/run_pytest.yml +++ b/.github/workflows/run_pytest.yml @@ -9,22 +9,27 @@ jobs: max-parallel: 3 matrix: os: [ubuntu-latest] - python-version: [3.5, 3.6, 3.7] + python-version: [3.5, 3.6, 3.7, 3.8] runs-on: ${{matrix.os}} + steps: - uses: actions/checkout@v1 + - name: Set up Python ${{matrix.python-version}} at ${{matrix.os}} uses: actions/setup-python@v1 with: python-version: ${{matrix.python-version}} + - name: Install dependencies run: | python -m pip install --upgrade pip pip install -r requirements.txt mkdir log/ + - name: Test with pytest run: | pytest -c 'test/pytest.ini' + - name: Save artifacts uses: actions/upload-artifact@master with: From af2fa094a05e2a2603407de3aace1297903b7fd3 Mon Sep 17 00:00:00 2001 From: Schrolli91 Date: Fri, 17 Apr 2020 23:40:43 +0200 Subject: [PATCH 17/42] remove max parallel --- .github/workflows/run_pytest.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/run_pytest.yml b/.github/workflows/run_pytest.yml index cd60fa9..30b9fe5 100644 --- a/.github/workflows/run_pytest.yml +++ b/.github/workflows/run_pytest.yml @@ -6,7 +6,6 @@ jobs: build: strategy: - max-parallel: 3 matrix: os: [ubuntu-latest] python-version: [3.5, 3.6, 3.7, 3.8] @@ -29,7 +28,7 @@ jobs: - name: Test with pytest run: | pytest -c 'test/pytest.ini' - + - name: Save artifacts uses: actions/upload-artifact@master with: From 940075ed85d0c6cff2beffd206a031041046e791 Mon Sep 17 00:00:00 2001 From: Jan Speller Date: Tue, 14 Apr 2020 22:34:17 +0200 Subject: [PATCH 18/42] Add Fix for descriptor --- module/descriptor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/descriptor.py b/module/descriptor.py index 77a28f8..f14f153 100644 --- a/module/descriptor.py +++ b/module/descriptor.py @@ -42,10 +42,10 @@ class BoswatchModule(ModuleBase): @param bwPacket: A BOSWatch packet instance""" for descriptor in self.config: + bwPacket.set(descriptor.get("descrField"), bwPacket.get(descriptor.get("scanField"))) for description in descriptor.get("descriptions"): if not bwPacket.get(descriptor.get("scanField")): break # scanField is not available in this packet - bwPacket.set(descriptor.get("descrField"), description.get("for")) if str(description.get("for")) == bwPacket.get(descriptor.get("scanField")): logging.debug("Description '%s' added in packet field '%s'", description.get("add"), descriptor.get("descrField")) From bfa9b0b3ceec08871c2cf3dfe9a9a241209aebc2 Mon Sep 17 00:00:00 2001 From: Jan Speller Date: Sat, 18 Apr 2020 14:09:59 +0200 Subject: [PATCH 19/42] return bwpacket if scanField is None --- module/descriptor.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/module/descriptor.py b/module/descriptor.py index f14f153..b470c83 100644 --- a/module/descriptor.py +++ b/module/descriptor.py @@ -42,6 +42,8 @@ class BoswatchModule(ModuleBase): @param bwPacket: A BOSWatch packet instance""" for descriptor in self.config: + if bwPacket.get(descriptor.get("scanField")) is None: + return bwPacket bwPacket.set(descriptor.get("descrField"), bwPacket.get(descriptor.get("scanField"))) for description in descriptor.get("descriptions"): if not bwPacket.get(descriptor.get("scanField")): From fde99396b8cdc1a742aaa4bd61f0c7d98e0046e2 Mon Sep 17 00:00:00 2001 From: Jan Speller Date: Sat, 18 Apr 2020 14:14:56 +0200 Subject: [PATCH 20/42] fix error --- module/descriptor.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/module/descriptor.py b/module/descriptor.py index b470c83..cf17530 100644 --- a/module/descriptor.py +++ b/module/descriptor.py @@ -42,12 +42,10 @@ class BoswatchModule(ModuleBase): @param bwPacket: A BOSWatch packet instance""" for descriptor in self.config: - if bwPacket.get(descriptor.get("scanField")) is None: - return bwPacket + if not bwPacket.get(descriptor.get("scanField")): + break # scanField is not available in this packet bwPacket.set(descriptor.get("descrField"), bwPacket.get(descriptor.get("scanField"))) for description in descriptor.get("descriptions"): - if not bwPacket.get(descriptor.get("scanField")): - break # scanField is not available in this packet if str(description.get("for")) == bwPacket.get(descriptor.get("scanField")): logging.debug("Description '%s' added in packet field '%s'", description.get("add"), descriptor.get("descrField")) From 1680490ca14edf9cfaac7c9eed38a9c1ac549bfe Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Sat, 18 Apr 2020 15:18:30 +0200 Subject: [PATCH 21/42] Update .github/workflows/build_docs.yml Co-Authored-By: Jan Speller --- .github/workflows/build_docs.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_docs.yml b/.github/workflows/build_docs.yml index dccc187..dfb0de3 100644 --- a/.github/workflows/build_docs.yml +++ b/.github/workflows/build_docs.yml @@ -1,6 +1,9 @@ name: build_docs -on: [push] +on: + push: + branches: + - master jobs: @@ -33,4 +36,4 @@ jobs: password: ${{ secrets.SCP_PASSWORD }} source: "docu/site/**" target: ${{ secrets.SCP_TARGET_PATH }} - strip_components: 2 \ No newline at end of file + strip_components: 2 From c2aab648c806003b034656aa77ed763c71c7ad88 Mon Sep 17 00:00:00 2001 From: kirschbaump Date: Mon, 20 Apr 2020 08:18:29 +0200 Subject: [PATCH 22/42] Neue InputSource - LineIn (#38) * Line-In input Source - code * bugfix * Docs * code cleanup * cleanup * code cleanup * Update docu/docs/config.md Co-Authored-By: Jan Speller * fixes Co-authored-by: Jan Speller --- boswatch/inputSource/lineInInput.py | 76 +++++++++++++++++++++++++++++ bw_client.py | 3 ++ config/client.yaml | 6 ++- docu/docs/config.md | 52 +++++++++++++++++++- 4 files changed, 134 insertions(+), 3 deletions(-) create mode 100644 boswatch/inputSource/lineInInput.py diff --git a/boswatch/inputSource/lineInInput.py b/boswatch/inputSource/lineInInput.py new file mode 100644 index 0000000..602f31d --- /dev/null +++ b/boswatch/inputSource/lineInInput.py @@ -0,0 +1,76 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +"""! + ____ ____ ______ __ __ __ _____ + / __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ / + / __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ < + / /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / ___/ / +/_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ /____/ + German BOS Information Script + by Bastian Schroll + +@file: lienInInput.py +@date: 18.04.2020 +@author: Philipp von Kirschbaum +@description: Input source for line-in with alsa +""" +import logging +from boswatch.utils import paths +from boswatch.processManager import ProcessManager +from boswatch.inputSource.inputBase import InputBase + +logging.debug("- %s loaded", __name__) + + +class LineInInput(InputBase): + """!Class for the line-in input source""" + + def _runThread(self, dataQueue, lineInConfig, decoderConfig): + lineInProc = None + mmProc = None + try: + lineInProc = ProcessManager("arecord") + lineInProc.addArgument("-q ") # supress any other outputs + lineInProc.addArgument("-f S16_LE") # set output format (16bit) + lineInProc.addArgument("-r 22050") # set output sampling rate (22050Hz) + lineInProc.addArgument("-D plughw:" + + str(lineInConfig.get("card", default="1")) + + "," + + str(lineInConfig.get("device", default="0"))) # device id + lineInProc.setStderr(open(paths.LOG_PATH + "asla.log", "a")) + lineInProc.start() + + mmProc = ProcessManager(str(lineInConfig.get("mmPath", default="multimon-ng")), textMode=True) + if decoderConfig.get("fms", default=0): + mmProc.addArgument("-a FMSFSK") + if decoderConfig.get("zvei", default=0): + mmProc.addArgument("-a ZVEI1") + if decoderConfig.get("poc512", default=0): + mmProc.addArgument("-a POCSAG512") + if decoderConfig.get("poc1200", default=0): + mmProc.addArgument("-a POCSAG1200") + if decoderConfig.get("poc2400", default=0): + mmProc.addArgument("-a POCSAG2400") + mmProc.addArgument("-f alpha") + mmProc.addArgument("-t raw -") + mmProc.setStdin(lineInProc.stdout) + mmProc.setStderr(open(paths.LOG_PATH + "multimon-ng.log", "a")) + mmProc.start() + + logging.info("start decoding") + while self._isRunning: + if not lineInProc.isRunning: + logging.warning("asla was down - try to restart") + lineInProc.start() + elif not mmProc.isRunning: + logging.warning("multimon was down - try to restart") + mmProc.start() + elif lineInProc.isRunning and mmProc.isRunning: + line = mmProc.readline() + if line: + self.addToQueue(line) + except: + logging.exception("error in lineIn input routine") + finally: + mmProc.stop() + lineInProc.stop() diff --git a/bw_client.py b/bw_client.py index 69b953b..3abe98c 100644 --- a/bw_client.py +++ b/bw_client.py @@ -50,6 +50,7 @@ from boswatch.decoder.decoder import Decoder from boswatch.utils import header from boswatch.utils import misc from boswatch.inputSource.sdrInput import SdrInput +from boswatch.inputSource.lineInInput import LineInInput header.logoToLog() header.infoToLog() @@ -88,6 +89,8 @@ try: logging.debug("loading input source: %s", bwConfig.get("client", "inputSource")) if bwConfig.get("client", "inputSource") == "sdr": inputSource = SdrInput(inputQueue, bwConfig.get("inputSource", "sdr"), bwConfig.get("decoder")) + elif bwConfig.get("client", "inputSource") == "lineIn": + inputSource = LineInInput(inputQueue, bwConfig.get("inputSource", "lineIn"), bwConfig.get("decoder")) else: logging.fatal("Invalid input source: %s", bwConfig.get("client", "inputSource")) exit(1) diff --git a/config/client.yaml b/config/client.yaml index 6821a3a..e93f92f 100644 --- a/config/client.yaml +++ b/config/client.yaml @@ -9,7 +9,7 @@ client: name: BW3 Client # name of the BW3 Client instance - inputSource: sdr # atm only 'sdr' is possible + inputSource: sdr # name of the input source('sdr' or 'lineIn') useBroadcast: no # use broadcast to find server automatically reconnectDelay: 3 # time in seconds to delay reconnect try sendTries: 3 # how often should tried to send a packet @@ -28,6 +28,10 @@ inputSource: gain: 100 rtlPath: /usr/bin/rtl_fm mmPath: /opt/multimon/multimon-ng + lineIn: + card: 1 + device: 0 + mmPath: /opt/multimon/multimon-ng decoder: fms: yes diff --git a/docu/docs/config.md b/docu/docs/config.md index 3a327f5..b0b1177 100644 --- a/docu/docs/config.md +++ b/docu/docs/config.md @@ -11,7 +11,7 @@ zwingend in die Konfiguration eingetragen werden. |Feld|Beschreibung|Default| |----|------------|-------| |name|Name zur Identifizierung der Client Instanz|| -|inputSource|Art der zu nutzenden Input Quelle (aktuell nur `sdr`)|sdr| +|inputSource|Art der zu nutzenden Input Quelle (`sdr` oder `lineIn`)|| |useBroadcast|Verbindungsdaten per [Broadcast](information/broadcast.md) beziehen|no| |reconnectDelay|Verzögerung für erneuten Verbindungsversuch zum Server|3| |sendTries|Anzahl der Sendeversuche eines Pakets|3| @@ -36,7 +36,7 @@ server: --- ### `inputSource:` -Aktuell gibt es nur `sdr:` als Input Quelle +Es gibt die Auswahl zwischen `sdr` oder `lineIn` als Input Quelle #### `sdr:` |Feld|Beschreibung|Default| @@ -62,6 +62,54 @@ inputSource: mmPath: /opt/multimon/multimon-ng ``` +#### `lineIn:` +|Feld|Beschreibung|Default| +|----|------------|-------| +|device|die device Id der Soundkarte|1| +|mmPath|Pfad zur multimon-ng Binary|multimon-ng| + +**Device herausfinden** +Durch eingabe des Befehls `aplay -l` werden alle Soundkarten ausgegeben. Das schaut ungefähr so aus: +```console +**** List of PLAYBACK Hardware Devices **** +card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA] + Subdevices: 7/7 + Subdevice #0: subdevice #0 + Subdevice #1: subdevice #1 + Subdevice #2: subdevice #2 + Subdevice #3: subdevice #3 + Subdevice #4: subdevice #4 + Subdevice #5: subdevice #5 + Subdevice #6: subdevice #6 +card 0: ALSA [bcm2835 ALSA], device 1: bcm2835 IEC958/HDMI [bcm2835 IEC958/HDMI] + Subdevices: 1/1 + Subdevice #0: subdevice #0 +card 0: ALSA [bcm2835 ALSA], device 2: bcm2835 IEC958/HDMI1 [bcm2835 IEC958/HDMI1] + Subdevices: 1/1 + Subdevice #0: subdevice #0 +card 1: Device [C-Media USB Audio Device], device 0: USB Audio [USB Audio] + Subdevices: 1/1 + Subdevice #0: subdevice #0 +``` + +Wir betrachten das letzte Gerät: `card 1: Device [C-Media USB Audio Device], device 0: USB Audio [USB Audio]` + +In dem Fall ist das letzte Gerät - `card 1` - unsere USB-Audio Schnittstelle die wir verwenden wollen. +In der Konfiguration wird das Feld `card` nun auf den Wert 1 gesetzt. + +Nach dem Typ der Soundkarte steht das device, in diesem Fall `device 0`. +In der Konfiguration wird das Feld `device` nun auf den Wert 0 gesetzt. + +**Beispiel:** +```yaml +inputSource: + ... + lineIn: + card: 1 + device: 0 + mmPath: /opt/multimon/multimon-ng +``` + --- ### `decoder:` |Feld|Beschreibung|Default| From ca81d86a1eed5e56aa68234e02e4cae08118233c Mon Sep 17 00:00:00 2001 From: Jan Speller Date: Fri, 1 May 2020 13:58:36 +0200 Subject: [PATCH 23/42] add source for telegram.py --- plugin/.telegram.py.swp | Bin 0 -> 12288 bytes plugin/telegram.py | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 plugin/.telegram.py.swp diff --git a/plugin/.telegram.py.swp b/plugin/.telegram.py.swp new file mode 100644 index 0000000000000000000000000000000000000000..a9e0d2601811df772dab77a4e744a59c48373d17 GIT binary patch literal 12288 zcmeHNO>7)B6n6RlOF=~l36OZ12z8cjcGHxWDr!(jT1rv>M3S~ZU~y)=yQ9pGr!(H9 zTSai85<(n%L0o|oHzeRfIdGyE1V|h~>H!W&AbPF@pFKaBP0}c7;ZQM-zVVFx{QUgc z@7YN_KXU5GG1_0-&5#~q?Bc+uZ=8Ab33gdB7Kg(3MWkysOsU-P%rpB&HWGX*6|A>B z6^T&B^~uwFhNomC>Y?9lc|lzXU$i3LsfE3b6qR))10@4nW1y>=!}|wj_l)i~K00I# z(!)Dux2B_%E*U5pC>bajC>bajC>bajC>bajxTP6T;WqX*MsQm?ii2ssZB?FrmRZR_ z$w0|K$w0|K$w0|K$w0|K$w0|K$w0|K$-phh0CySt3wFPv{{Vph|4*l5_~SvwegeJ+ zE&`{4$AMqAGxia%2pk8F0egVQ00vwcVC-k$JKz)GW8ghN0y}`)fZrZq>{sAx;1ci^ z@FB1Wbb(o*0$jeIv2TITfD6DrU@!0paP>ae4SWM!0QLgc?q%#t;0vG!w1ES_-}j&| z;1aM1JO^C68@2)O08au}?_%s-;0&-G`29}U3_+6sAP|o77CqHl$D$dpBis{R*mGQ{B^fRJ$L8?R8(t9WSTY;%u4>E3J1^XRGGgI3 zYx7doG|`PtLayz!xoUXsxXzEbRZ`-d8t=rd71E1DdO=g#)^s{ksSZ+-EZRkhivET} zq=mDoq(zVC6PC}Eih7BqO{|4P33&n51MCIuO|MmJ31wSJRcuws6;0mt)%a_#rxOl? zX*_8W@+cOkJ>PYB8 z$|V`ltEUbfA@1|2!(a`aUlg9{tC}l-Y55Q}hdQm}0<*zFAeRE#j4O;8o?{i+suv1d zRBDYzz&oPRsDOWKrCOw;OL`^h_ez-0V-o$#<2vST#;k%rXf0dy(wpdc3!YlEY*XI) zFPpX2V+$5t-)psyPJP~cR61Pg0IFT0=)FFQRo4~cc&TEw1-N==K4sAFmxX&(<2eCZQwpVhW_9<1!G$;qBH>P`?-ilLgrhk=;?z||ovK($aYU^Qa zE^@PM#Qov>2=MSd=T#M)+9!duXjt#N|w4fBb_TQ{7mh zgJe44RgRB%9K((cOiXM_n$(g^Gmx#26;86jq_i+S852;Skvx_kwkT=DCX&umrRX@!SdZIbB)e3Y0KHt<&4fCKmGn{&Z4xnu!Q899J zsmyXBV2mT(2U?oOXrmJbgmz57>hj`Kf0>lMWVyB@t3ew*<%3vD!%q*x-SzKJV`Q%W V>Jm0ISntMBeI8fsLpZGr*gt5>VR--m literal 0 HcmV?d00001 diff --git a/plugin/telegram.py b/plugin/telegram.py index 5dea41f..15536ff 100644 --- a/plugin/telegram.py +++ b/plugin/telegram.py @@ -1,3 +1,4 @@ +??? from here until ???END lines may have been inserted/deleted #!/usr/bin/python # -*- coding: utf-8 -*- """! @@ -64,3 +65,21 @@ class BoswatchPlugin(PluginBase): logging.exception("Error while sending Telegram Message") except Exception as e: logging.exception("Unknown Error while sending Telegram Message: " + str(type(e).__name__) + ": " + str(e)) + + def zvei(self, bwPacket): + """!Called on ZVEI alarm + @param bwPacket: bwPacket instance""" + msg = self.parseWildcards(self.config.get("message")) + for chatId in self.config.get("chatIds", default=[]): + try: + # Send Message via Telegram + logging.info("Sending message to " + chatId) + self.bot.send_message(chat_id=chatId, text=msg) + except Unauthorized: + logging.exception("Error while sending Telegram Message, please Check your api-key") + except (TimedOut, NetworkError): + logging.exception("Error while sending Telegram Message, please Check your connectivity") + except (BadRequest, TelegramError): + logging.exception("Error while sending Telegram Message") + except Exception as e: + logging.exception("Unknown Error while sending Telegram Message: " + str(type(e).__name__) + ": " + str(e)) From fd9307dd0343d24aee99b79fdbcee2de78009a9d Mon Sep 17 00:00:00 2001 From: Jan Speller Date: Fri, 1 May 2020 14:00:16 +0200 Subject: [PATCH 24/42] fix telegram.py --- plugin/telegram.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugin/telegram.py b/plugin/telegram.py index 15536ff..f783e72 100644 --- a/plugin/telegram.py +++ b/plugin/telegram.py @@ -1,4 +1,3 @@ -??? from here until ???END lines may have been inserted/deleted #!/usr/bin/python # -*- coding: utf-8 -*- """! From 456efc111687e4d87e443893e4dc59bf21421434 Mon Sep 17 00:00:00 2001 From: Schrolli91 Date: Fri, 1 May 2020 23:52:19 +0200 Subject: [PATCH 25/42] update telegram plugin --- plugin/.telegram.py.swp | Bin 12288 -> 0 bytes plugin/telegram.py | 74 ++++++++++++++++++++++++++-------------- 2 files changed, 49 insertions(+), 25 deletions(-) delete mode 100644 plugin/.telegram.py.swp diff --git a/plugin/.telegram.py.swp b/plugin/.telegram.py.swp deleted file mode 100644 index a9e0d2601811df772dab77a4e744a59c48373d17..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeHNO>7)B6n6RlOF=~l36OZ12z8cjcGHxWDr!(jT1rv>M3S~ZU~y)=yQ9pGr!(H9 zTSai85<(n%L0o|oHzeRfIdGyE1V|h~>H!W&AbPF@pFKaBP0}c7;ZQM-zVVFx{QUgc z@7YN_KXU5GG1_0-&5#~q?Bc+uZ=8Ab33gdB7Kg(3MWkysOsU-P%rpB&HWGX*6|A>B z6^T&B^~uwFhNomC>Y?9lc|lzXU$i3LsfE3b6qR))10@4nW1y>=!}|wj_l)i~K00I# z(!)Dux2B_%E*U5pC>bajC>bajC>bajC>bajxTP6T;WqX*MsQm?ii2ssZB?FrmRZR_ z$w0|K$w0|K$w0|K$w0|K$w0|K$w0|K$-phh0CySt3wFPv{{Vph|4*l5_~SvwegeJ+ zE&`{4$AMqAGxia%2pk8F0egVQ00vwcVC-k$JKz)GW8ghN0y}`)fZrZq>{sAx;1ci^ z@FB1Wbb(o*0$jeIv2TITfD6DrU@!0paP>ae4SWM!0QLgc?q%#t;0vG!w1ES_-}j&| z;1aM1JO^C68@2)O08au}?_%s-;0&-G`29}U3_+6sAP|o77CqHl$D$dpBis{R*mGQ{B^fRJ$L8?R8(t9WSTY;%u4>E3J1^XRGGgI3 zYx7doG|`PtLayz!xoUXsxXzEbRZ`-d8t=rd71E1DdO=g#)^s{ksSZ+-EZRkhivET} zq=mDoq(zVC6PC}Eih7BqO{|4P33&n51MCIuO|MmJ31wSJRcuws6;0mt)%a_#rxOl? zX*_8W@+cOkJ>PYB8 z$|V`ltEUbfA@1|2!(a`aUlg9{tC}l-Y55Q}hdQm}0<*zFAeRE#j4O;8o?{i+suv1d zRBDYzz&oPRsDOWKrCOw;OL`^h_ez-0V-o$#<2vST#;k%rXf0dy(wpdc3!YlEY*XI) zFPpX2V+$5t-)psyPJP~cR61Pg0IFT0=)FFQRo4~cc&TEw1-N==K4sAFmxX&(<2eCZQwpVhW_9<1!G$;qBH>P`?-ilLgrhk=;?z||ovK($aYU^Qa zE^@PM#Qov>2=MSd=T#M)+9!duXjt#N|w4fBb_TQ{7mh zgJe44RgRB%9K((cOiXM_n$(g^Gmx#26;86jq_i+S852;Skvx_kwkT=DCX&umrRX@!SdZIbB)e3Y0KHt<&4fCKmGn{&Z4xnu!Q899J zsmyXBV2mT(2U?oOXrmJbgmz57>hj`Kf0>lMWVyB@t3ew*<%3vD!%q*x-SzKJV`Q%W V>Jm0ISntMBeI8fsLpZGr*gt5>VR--m diff --git a/plugin/telegram.py b/plugin/telegram.py index f783e72..900754b 100644 --- a/plugin/telegram.py +++ b/plugin/telegram.py @@ -35,45 +35,69 @@ class BoswatchPlugin(PluginBase): def onLoad(self): """!Called by import of the plugin""" - self.bot = telegram.Bot(token=self.config.get("botToken", default="")) + self.bot = telegram.Bot(token=self.config.get("botToken")) + + def fms(self, bwPacket): + """!Called on FMS alarm + + @param bwPacket: bwPacket instance + Remove if not implemented""" + msg = self.parseWildcards(self.config.get("message_fms", default="{FMS}")) + _sendMessage(msg) def pocsag(self, bwPacket): """!Called on POCSAG alarm - @param bwPacket: bwPacket instance""" - msg = self.parseWildcards(self.config.get("message")) + @param bwPacket: bwPacket instance + Remove if not implemented""" + msg = self.parseWildcards(self.config.get("message_pocsag", default="{RIC}({SRIC})\n{MSG}")) + self._sendMessage(msg) + if bwPacket.get("lat") is not None and bwPacket.get("lon") is not None: logging.debug("Found coordinates in packet") (lat, lon) = (bwPacket.get("lat"), bwPacket.get("lon")) - - for chatId in self.config.get("chatIds", default=[]): - try: - # Send Message via Telegram - logging.info("Sending message to " + chatId) - self.bot.send_message(chat_id=chatId, text=msg) - - # Send Location via Telegram if lat and lon are defined - if lat is not None and lon is not None: - logging.info("Sending location to " + chatId) - self.bot.sendLocation(chat_id=chatId, latitude=lat, longitude=lon) - except Unauthorized: - logging.exception("Error while sending Telegram Message, please Check your api-key") - except (TimedOut, NetworkError): - logging.exception("Error while sending Telegram Message, please Check your connectivity") - except (BadRequest, TelegramError): - logging.exception("Error while sending Telegram Message") - except Exception as e: - logging.exception("Unknown Error while sending Telegram Message: " + str(type(e).__name__) + ": " + str(e)) + self._sendMessage(lat, lon) def zvei(self, bwPacket): """!Called on ZVEI alarm - @param bwPacket: bwPacket instance""" - msg = self.parseWildcards(self.config.get("message")) + + @param bwPacket: bwPacket instance + Remove if not implemented""" + msg = self.parseWildcards(self.config.get("message_zvei", default="{TONE}")) + _sendMessage(msg) + + def msg(self, bwPacket): + """!Called on MSG packet + + @param bwPacket: bwPacket instance + Remove if not implemented""" + msg = self.parseWildcards(self.config.get("message_msg")) + _sendMessage(msg) + + def _sendMessage(self, message): for chatId in self.config.get("chatIds", default=[]): try: # Send Message via Telegram logging.info("Sending message to " + chatId) - self.bot.send_message(chat_id=chatId, text=msg) + self.bot.send_message(chat_id=chatId, text=message) + + except Unauthorized: + logging.exception("Error while sending Telegram Message, please Check your api-key") + except (TimedOut, NetworkError): + logging.exception("Error while sending Telegram Message, please Check your connectivity") + except (BadRequest, TelegramError): + logging.exception("Error while sending Telegram Message") + except Exception as e: + logging.exception("Unknown Error while sending Telegram Message: " + str(type(e).__name__) + ": " + str(e)) + + def _sendLocation(self, lat, lon): + for chatId in self.config.get("chatIds", default=[]): + try: + # Send Location via Telegram + if lat is not None and lon is not None: + logging.info("Sending location to " + chatId) + self.bot.sendLocation(chat_id=chatId, latitude=lat, longitude=lon) + except Unauthorized: logging.exception("Error while sending Telegram Message, please Check your api-key") except (TimedOut, NetworkError): From c94938dd3d9d51bd691f27abbad164e0e7f46453 Mon Sep 17 00:00:00 2001 From: Schrolli91 Date: Fri, 1 May 2020 23:52:38 +0200 Subject: [PATCH 26/42] update docs --- docu/docs/plugin/telegram.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/docu/docs/plugin/telegram.md b/docu/docs/plugin/telegram.md index c072556..92319d2 100644 --- a/docu/docs/plugin/telegram.md +++ b/docu/docs/plugin/telegram.md @@ -6,7 +6,10 @@ Mit diesem Plugin ist es moeglich, Telegram-Nachrichten für POCSAG-Alarmierunge Außerdem werden Locations versendet, wenn die Felder `lat` und `lon` im Paket definiert sind. (beispielsweise durch das [Geocoding](../modul/geocoding.md) Modul) ## Unterstütze Alarmtypen +- Fms - Pocsag +- Zvei +- Msg ## Resource `telegram` @@ -15,9 +18,12 @@ Außerdem werden Locations versendet, wenn die Felder `lat` und `lon` im Paket d |Feld|Beschreibung|Default| |----|------------|-------| -|message|Format der Nachricht|| |botToken|Der Api-Key des Telegram-Bots|| |chatIds|Liste mit Chat-Ids der Empfängers / der Emfänger-Gruppen|| +|message_fms|Format der Nachricht für FMS|`{FMS}`| +|message_pocsag|Format der Nachricht für Pocsag|`{RIC}({SRIC})\n{MSG}`| +|message_zvei|Format der Nachricht für ZVEI|`{TONE}`| +|message_msg|Format der Nachricht für MSG|| **Beispiel:** ```yaml @@ -25,7 +31,7 @@ Außerdem werden Locations versendet, wenn die Felder `lat` und `lon` im Paket d name: Telegram Plugin res: telegram config: - message: "{RIC}({SRIC})\n{MSG}" + message_pocsag: "{RIC}({SRIC})\n{MSG}" botToken: "BOT_TOKEN" chatIds: - "CHAT_ID" @@ -33,7 +39,7 @@ Außerdem werden Locations versendet, wenn die Felder `lat` und `lon` im Paket d --- ## Modul Abhängigkeiten -Aus dem Modul [Geocoding](../modul/geocoding.md) (optional): +Aus dem Modul [Geocoding](../modul/geocoding.md) (optional/nur POCSAG): - `lat` - `lon` From e05b81e5d77f69920a6895d16134c2434add12e6 Mon Sep 17 00:00:00 2001 From: Schrolli91 Date: Fri, 1 May 2020 23:56:29 +0200 Subject: [PATCH 27/42] bugfix --- plugin/telegram.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin/telegram.py b/plugin/telegram.py index 900754b..1707d2c 100644 --- a/plugin/telegram.py +++ b/plugin/telegram.py @@ -43,7 +43,7 @@ class BoswatchPlugin(PluginBase): @param bwPacket: bwPacket instance Remove if not implemented""" msg = self.parseWildcards(self.config.get("message_fms", default="{FMS}")) - _sendMessage(msg) + self._sendMessage(msg) def pocsag(self, bwPacket): """!Called on POCSAG alarm @@ -64,7 +64,7 @@ class BoswatchPlugin(PluginBase): @param bwPacket: bwPacket instance Remove if not implemented""" msg = self.parseWildcards(self.config.get("message_zvei", default="{TONE}")) - _sendMessage(msg) + self._sendMessage(msg) def msg(self, bwPacket): """!Called on MSG packet @@ -72,7 +72,7 @@ class BoswatchPlugin(PluginBase): @param bwPacket: bwPacket instance Remove if not implemented""" msg = self.parseWildcards(self.config.get("message_msg")) - _sendMessage(msg) + self._sendMessage(msg) def _sendMessage(self, message): for chatId in self.config.get("chatIds", default=[]): From f79554f4153f85bf83a55f6db5c03465bb64d0b2 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Wed, 6 May 2020 07:41:52 +0200 Subject: [PATCH 28/42] Update plugin/telegram.py Co-authored-by: Jan Speller --- plugin/telegram.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugin/telegram.py b/plugin/telegram.py index 1707d2c..ec043ea 100644 --- a/plugin/telegram.py +++ b/plugin/telegram.py @@ -40,8 +40,7 @@ class BoswatchPlugin(PluginBase): def fms(self, bwPacket): """!Called on FMS alarm - @param bwPacket: bwPacket instance - Remove if not implemented""" + @param bwPacket: bwPacket instance""" msg = self.parseWildcards(self.config.get("message_fms", default="{FMS}")) self._sendMessage(msg) From 689d81565bba621bf2e9dd5e83af583383e2effa Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Wed, 6 May 2020 07:42:04 +0200 Subject: [PATCH 29/42] Update plugin/telegram.py Co-authored-by: Jan Speller --- plugin/telegram.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugin/telegram.py b/plugin/telegram.py index ec043ea..5d6f44a 100644 --- a/plugin/telegram.py +++ b/plugin/telegram.py @@ -47,8 +47,7 @@ class BoswatchPlugin(PluginBase): def pocsag(self, bwPacket): """!Called on POCSAG alarm - @param bwPacket: bwPacket instance - Remove if not implemented""" + @param bwPacket: bwPacket instance""" msg = self.parseWildcards(self.config.get("message_pocsag", default="{RIC}({SRIC})\n{MSG}")) self._sendMessage(msg) From 6b0488ed1b9c285be59ddea85bcafd140b382779 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Wed, 6 May 2020 07:42:11 +0200 Subject: [PATCH 30/42] Update plugin/telegram.py Co-authored-by: Jan Speller --- plugin/telegram.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugin/telegram.py b/plugin/telegram.py index 5d6f44a..3a6322e 100644 --- a/plugin/telegram.py +++ b/plugin/telegram.py @@ -67,8 +67,7 @@ class BoswatchPlugin(PluginBase): def msg(self, bwPacket): """!Called on MSG packet - @param bwPacket: bwPacket instance - Remove if not implemented""" + @param bwPacket: bwPacket instance""" msg = self.parseWildcards(self.config.get("message_msg")) self._sendMessage(msg) From e4852be0e718144d97070542b27735528531813e Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Wed, 6 May 2020 07:42:20 +0200 Subject: [PATCH 31/42] Update plugin/telegram.py Co-authored-by: Jan Speller --- plugin/telegram.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugin/telegram.py b/plugin/telegram.py index 3a6322e..46018d9 100644 --- a/plugin/telegram.py +++ b/plugin/telegram.py @@ -59,8 +59,7 @@ class BoswatchPlugin(PluginBase): def zvei(self, bwPacket): """!Called on ZVEI alarm - @param bwPacket: bwPacket instance - Remove if not implemented""" + @param bwPacket: bwPacket instance""" msg = self.parseWildcards(self.config.get("message_zvei", default="{TONE}")) self._sendMessage(msg) From 687a11719aa606cebd6173fde971533656bf1477 Mon Sep 17 00:00:00 2001 From: Jan Speller Date: Sun, 7 Jun 2020 22:56:29 +0200 Subject: [PATCH 32/42] fix usage of port in server --- bw_server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bw_server.py b/bw_server.py index d84c8d1..ed600b4 100644 --- a/bw_server.py +++ b/bw_server.py @@ -86,7 +86,7 @@ try: incomingQueue = queue.Queue() bwServer = TCPServer(incomingQueue) - if bwServer.start(): + if bwServer.start(port=bwConfig.get('server', 'port', default=8080)): while 1: if incomingQueue.empty(): # pause only when no data From c3ccc11b5de0da39981f7d2f9a80667c0de6773f Mon Sep 17 00:00:00 2001 From: B-Watch Date: Wed, 24 Jun 2020 21:38:11 +0200 Subject: [PATCH 33/42] FR #42 - added config for Char-set mm --- boswatch/inputSource/lineInInput.py | 2 ++ boswatch/inputSource/sdrInput.py | 2 ++ config/client.yaml | 2 ++ docu/docs/config.md | 4 ++++ 4 files changed, 10 insertions(+) diff --git a/boswatch/inputSource/lineInInput.py b/boswatch/inputSource/lineInInput.py index 602f31d..c8016bc 100644 --- a/boswatch/inputSource/lineInInput.py +++ b/boswatch/inputSource/lineInInput.py @@ -51,6 +51,8 @@ class LineInInput(InputBase): mmProc.addArgument("-a POCSAG1200") if decoderConfig.get("poc2400", default=0): mmProc.addArgument("-a POCSAG2400") + if lineInConfig.get("mmChar"): + mmProc.addArgument("-C " + str(lineInConfig.get("mmChar"))) mmProc.addArgument("-f alpha") mmProc.addArgument("-t raw -") mmProc.setStdin(lineInProc.stdout) diff --git a/boswatch/inputSource/sdrInput.py b/boswatch/inputSource/sdrInput.py index 8f9ce1e..ed79116 100644 --- a/boswatch/inputSource/sdrInput.py +++ b/boswatch/inputSource/sdrInput.py @@ -52,6 +52,8 @@ class SdrInput(InputBase): mmProc.addArgument("-a POCSAG1200") if decoderConfig.get("poc2400", default=0): mmProc.addArgument("-a POCSAG2400") + if lineInConfig.get("mmChar"): + mmProc.addArgument("-C " + str(lineInConfig.get("mmChar"))) mmProc.addArgument("-f alpha") mmProc.addArgument("-t raw -") mmProc.setStdin(sdrProc.stdout) diff --git a/config/client.yaml b/config/client.yaml index e93f92f..2b2a736 100644 --- a/config/client.yaml +++ b/config/client.yaml @@ -28,10 +28,12 @@ inputSource: gain: 100 rtlPath: /usr/bin/rtl_fm mmPath: /opt/multimon/multimon-ng + mmChar: DE lineIn: card: 1 device: 0 mmPath: /opt/multimon/multimon-ng + mmChar: DE decoder: fms: yes diff --git a/docu/docs/config.md b/docu/docs/config.md index b0b1177..dc9c237 100644 --- a/docu/docs/config.md +++ b/docu/docs/config.md @@ -48,6 +48,7 @@ Es gibt die Auswahl zwischen `sdr` oder `lineIn` als Input Quelle |gain|Verstärkung des Eingangssignals|100| |rtlPath|Pfad zur rtl_fm Binary|rtl_fm| |mmPath|Pfad zur multimon-ng Binary|multimon-ng| +|mmChar|multimon-ng Char-Set|| **Beispiel:** ```yaml @@ -60,6 +61,7 @@ inputSource: gain: 100 rtlPath: /usr/bin/rtl-fm mmPath: /opt/multimon/multimon-ng + mmChar: DE ``` #### `lineIn:` @@ -67,6 +69,7 @@ inputSource: |----|------------|-------| |device|die device Id der Soundkarte|1| |mmPath|Pfad zur multimon-ng Binary|multimon-ng| +|mmChar|multimon-ng Char-Set|| **Device herausfinden** Durch eingabe des Befehls `aplay -l` werden alle Soundkarten ausgegeben. Das schaut ungefähr so aus: @@ -108,6 +111,7 @@ inputSource: card: 1 device: 0 mmPath: /opt/multimon/multimon-ng + mmChar: DE ``` --- From 8fbccd8169cb1e37d8c41f49871ddf15e20bdc94 Mon Sep 17 00:00:00 2001 From: B-Watch Date: Wed, 24 Jun 2020 21:48:20 +0200 Subject: [PATCH 34/42] fixed trailing spaces --- boswatch/inputSource/sdrInput.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boswatch/inputSource/sdrInput.py b/boswatch/inputSource/sdrInput.py index ed79116..95fecd9 100644 --- a/boswatch/inputSource/sdrInput.py +++ b/boswatch/inputSource/sdrInput.py @@ -53,7 +53,7 @@ class SdrInput(InputBase): if decoderConfig.get("poc2400", default=0): mmProc.addArgument("-a POCSAG2400") if lineInConfig.get("mmChar"): - mmProc.addArgument("-C " + str(lineInConfig.get("mmChar"))) + mmProc.addArgument("-C " + str(lineInConfig.get("mmChar"))) mmProc.addArgument("-f alpha") mmProc.addArgument("-t raw -") mmProc.setStdin(sdrProc.stdout) From e6f588a06c1f5a48449e191d496b852044b375c3 Mon Sep 17 00:00:00 2001 From: B-Watch Date: Wed, 24 Jun 2020 21:57:14 +0200 Subject: [PATCH 35/42] fixed copy an paste error --- boswatch/inputSource/sdrInput.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/boswatch/inputSource/sdrInput.py b/boswatch/inputSource/sdrInput.py index 95fecd9..6dcb278 100644 --- a/boswatch/inputSource/sdrInput.py +++ b/boswatch/inputSource/sdrInput.py @@ -52,8 +52,8 @@ class SdrInput(InputBase): mmProc.addArgument("-a POCSAG1200") if decoderConfig.get("poc2400", default=0): mmProc.addArgument("-a POCSAG2400") - if lineInConfig.get("mmChar"): - mmProc.addArgument("-C " + str(lineInConfig.get("mmChar"))) + if sdrConfig.get("mmChar"): + mmProc.addArgument("-C " + str(sdrConfig.get("mmChar"))) mmProc.addArgument("-f alpha") mmProc.addArgument("-t raw -") mmProc.setStdin(sdrProc.stdout) From 23ae9b9aa01ad3c5a6e8390909df928633aa7479 Mon Sep 17 00:00:00 2001 From: b-watch <67390066+b-watch@users.noreply.github.com> Date: Sun, 28 Jun 2020 21:02:14 +0200 Subject: [PATCH 36/42] Added default description for mmChar --- docu/docs/config.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docu/docs/config.md b/docu/docs/config.md index dc9c237..4f9d45f 100644 --- a/docu/docs/config.md +++ b/docu/docs/config.md @@ -48,7 +48,7 @@ Es gibt die Auswahl zwischen `sdr` oder `lineIn` als Input Quelle |gain|Verstärkung des Eingangssignals|100| |rtlPath|Pfad zur rtl_fm Binary|rtl_fm| |mmPath|Pfad zur multimon-ng Binary|multimon-ng| -|mmChar|multimon-ng Char-Set|| +|mmChar|multimon-ng Char-Set|deaktiviert| **Beispiel:** ```yaml From 117ea5347ec5ee25176666e4041112fd818e0217 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Mon, 29 Jun 2020 07:21:33 +0200 Subject: [PATCH 37/42] Update config.md --- docu/docs/config.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docu/docs/config.md b/docu/docs/config.md index 4f9d45f..fc666b8 100644 --- a/docu/docs/config.md +++ b/docu/docs/config.md @@ -48,7 +48,7 @@ Es gibt die Auswahl zwischen `sdr` oder `lineIn` als Input Quelle |gain|Verstärkung des Eingangssignals|100| |rtlPath|Pfad zur rtl_fm Binary|rtl_fm| |mmPath|Pfad zur multimon-ng Binary|multimon-ng| -|mmChar|multimon-ng Char-Set|deaktiviert| +|mmChar|multimon-ng Char-Set|not set| **Beispiel:** ```yaml From df4ffaac533da5e01057e8bc4c9215afe8a5d398 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Mon, 29 Jun 2020 07:25:24 +0200 Subject: [PATCH 38/42] Update config.md --- docu/docs/config.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docu/docs/config.md b/docu/docs/config.md index fc666b8..a5598a2 100644 --- a/docu/docs/config.md +++ b/docu/docs/config.md @@ -69,7 +69,7 @@ inputSource: |----|------------|-------| |device|die device Id der Soundkarte|1| |mmPath|Pfad zur multimon-ng Binary|multimon-ng| -|mmChar|multimon-ng Char-Set|| +|mmChar|multimon-ng Char-Set|not set| **Device herausfinden** Durch eingabe des Befehls `aplay -l` werden alle Soundkarten ausgegeben. Das schaut ungefähr so aus: From 7f35d0592e927289cbfb8247bf50c9af599b2e78 Mon Sep 17 00:00:00 2001 From: B-Watch Date: Mon, 29 Jun 2020 21:11:07 +0200 Subject: [PATCH 39/42] Added PulseAudio as Source --- boswatch/inputSource/pulseaudioInput.py | 77 +++++++++++++++++++++++++ bw_client.py | 3 + docu/docs/config.md | 30 +++++++++- 3 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 boswatch/inputSource/pulseaudioInput.py diff --git a/boswatch/inputSource/pulseaudioInput.py b/boswatch/inputSource/pulseaudioInput.py new file mode 100644 index 0000000..39957a6 --- /dev/null +++ b/boswatch/inputSource/pulseaudioInput.py @@ -0,0 +1,77 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +"""! + ____ ____ ______ __ __ __ _____ + / __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ / + / __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ < + / /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / ___/ / +/_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ /____/ + German BOS Information Script + by Bastian Schroll + +@file: pulseaudioInput.py +@date: 18.04.2020, 29.06.2020 +@author: Philipp von Kirschbaum, b-watch +@description: Input source for PulseAudio +""" +import logging +from boswatch.utils import paths +from boswatch.processManager import ProcessManager +from boswatch.inputSource.inputBase import InputBase + +logging.debug("- %s loaded", __name__) + + +class PulseAudioInput(InputBase): + """!Class for the PulseAudio input source""" + + def _runThread(self, dataQueue, PulseAudioConfig, decoderConfig): + PulseAudioProc = None + mmProc = None + try: + PulseAudioProc = ProcessManager("parec") + PulseAudioProc.addArgument("--channels=1") # supress any other outputs + PulseAudioProc.addArgument("--format=s16le") # set output format (16bit) + PulseAudioProc.addArgument("--rate=22050") # set output sampling rate (22050Hz) + PulseAudioProc.addArgument("--device=" + + str(PulseAudioConfig.get("device", default="boswatch")) + + ".monitor") # sink name + PulseAudioProc.setStderr(open(paths.LOG_PATH + "pulseaudio.log", "a")) + PulseAudioProc.start() + + mmProc = ProcessManager(str(PulseAudioConfig.get("mmPath", default="multimon-ng")), textMode=True) + if decoderConfig.get("fms", default=0): + mmProc.addArgument("-a FMSFSK") + if decoderConfig.get("zvei", default=0): + mmProc.addArgument("-a ZVEI1") + if decoderConfig.get("poc512", default=0): + mmProc.addArgument("-a POCSAG512") + if decoderConfig.get("poc1200", default=0): + mmProc.addArgument("-a POCSAG1200") + if decoderConfig.get("poc2400", default=0): + mmProc.addArgument("-a POCSAG2400") + if PulseAudioConfig.get("mmChar"): + mmProc.addArgument("-C " + str(PulseAudioConfig.get("mmChar"))) + mmProc.addArgument("-f alpha") + mmProc.addArgument("-t raw -") + mmProc.setStdin(PulseAudioProc.stdout) + mmProc.setStderr(open(paths.LOG_PATH + "multimon-ng.log", "a")) + mmProc.start() + + logging.info("start decoding") + while self._isRunning: + if not PulseAudioProc.isRunning: + logging.warning("asla was down - try to restart") + PulseAudioProc.start() + elif not mmProc.isRunning: + logging.warning("multimon was down - try to restart") + mmProc.start() + elif PulseAudioProc.isRunning and mmProc.isRunning: + line = mmProc.readline() + if line: + self.addToQueue(line) + except: + logging.exception("error in PulseAudio input routine") + finally: + mmProc.stop() + PulseAudioProc.stop() diff --git a/bw_client.py b/bw_client.py index 3abe98c..560f05b 100644 --- a/bw_client.py +++ b/bw_client.py @@ -51,6 +51,7 @@ from boswatch.utils import header from boswatch.utils import misc from boswatch.inputSource.sdrInput import SdrInput from boswatch.inputSource.lineInInput import LineInInput +from boswatch.inputSource.pulseaudioInput import PulseAudioInput header.logoToLog() header.infoToLog() @@ -91,6 +92,8 @@ try: inputSource = SdrInput(inputQueue, bwConfig.get("inputSource", "sdr"), bwConfig.get("decoder")) elif bwConfig.get("client", "inputSource") == "lineIn": inputSource = LineInInput(inputQueue, bwConfig.get("inputSource", "lineIn"), bwConfig.get("decoder")) + elif bwConfig.get("client", "inputSource") == "PulseAudio": + inputSource = PulseAudioInput(inputQueue, bwConfig.get("inputSource", "PulseAudio"), bwConfig.get("decoder")) else: logging.fatal("Invalid input source: %s", bwConfig.get("client", "inputSource")) exit(1) diff --git a/docu/docs/config.md b/docu/docs/config.md index a5598a2..c5d38b6 100644 --- a/docu/docs/config.md +++ b/docu/docs/config.md @@ -11,7 +11,7 @@ zwingend in die Konfiguration eingetragen werden. |Feld|Beschreibung|Default| |----|------------|-------| |name|Name zur Identifizierung der Client Instanz|| -|inputSource|Art der zu nutzenden Input Quelle (`sdr` oder `lineIn`)|| +|inputSource|Art der zu nutzenden Input Quelle (`sdr`, `lineIn` oder `PulseAudio`)|| |useBroadcast|Verbindungsdaten per [Broadcast](information/broadcast.md) beziehen|no| |reconnectDelay|Verzögerung für erneuten Verbindungsversuch zum Server|3| |sendTries|Anzahl der Sendeversuche eines Pakets|3| @@ -36,7 +36,7 @@ server: --- ### `inputSource:` -Es gibt die Auswahl zwischen `sdr` oder `lineIn` als Input Quelle +Es gibt die Auswahl zwischen `sdr`, `lineIn` oder `PulseAudio` als Input Quelle #### `sdr:` |Feld|Beschreibung|Default| @@ -114,6 +114,32 @@ inputSource: mmChar: DE ``` +#### `PulseAudio:` +|Feld|Beschreibung|Default| +|----|------------|-------| +|device|Der Sinks-Name der Quelle|boswatch| +|mmPath|Pfad zur multimon-ng Binary|multimon-ng| +|mmChar|multimon-ng Char-Set|not set| + + +**Device herausfinden** +Durch eingabe des Befehls `pacmd list-sinks | grep name:` werden alle Sinks ausgegeben. Beispiel: +```console +bash-5.0# pacmd list-sinks | grep name: + name: +``` + +In der Konfiguration wird das Feld `device` nun auf den den Namen des gewünschten Sinks gesetzt (ohne spitze Klammern, <>). + +**Beispiel:** +```yaml +inputSource: + ... + PulseAudio: + device: boswatch + mmPath: /opt/multimon/multimon-ng + mmChar: DE +``` --- ### `decoder:` |Feld|Beschreibung|Default| From 5457cbfd3ef59e84f2063327e937dba1c8b64355 Mon Sep 17 00:00:00 2001 From: B-Watch Date: Wed, 1 Jul 2020 11:45:13 +0200 Subject: [PATCH 40/42] changed log output --- boswatch/inputSource/pulseaudioInput.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boswatch/inputSource/pulseaudioInput.py b/boswatch/inputSource/pulseaudioInput.py index 39957a6..5d955db 100644 --- a/boswatch/inputSource/pulseaudioInput.py +++ b/boswatch/inputSource/pulseaudioInput.py @@ -61,7 +61,7 @@ class PulseAudioInput(InputBase): logging.info("start decoding") while self._isRunning: if not PulseAudioProc.isRunning: - logging.warning("asla was down - try to restart") + logging.warning("PulseAudio was down - try to restart") PulseAudioProc.start() elif not mmProc.isRunning: logging.warning("multimon was down - try to restart") From 5b3f1c3bd1b8b4553942e36fb0129c8ea2126fed Mon Sep 17 00:00:00 2001 From: B-Watch Date: Mon, 6 Jul 2020 09:48:27 +0200 Subject: [PATCH 41/42] additional documentation for inputsource --- docu/docs/config.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docu/docs/config.md b/docu/docs/config.md index c5d38b6..97823f4 100644 --- a/docu/docs/config.md +++ b/docu/docs/config.md @@ -36,7 +36,10 @@ server: --- ### `inputSource:` -Es gibt die Auswahl zwischen `sdr`, `lineIn` oder `PulseAudio` als Input Quelle +Es gibt die Auswahl zwischen `sdr`, `lineIn` oder `PulseAudio` als Input Quelle. +Mit `sdr` wird direkt per **rtl_sdr** die zu empfangende Frequenz an Multimon-NG weitergereicht. +Mit `lineIn` wird eine Quelle die (per **ALSA**) direkt an die Soundkarte angeschlossen ist an Multimon-NG weitergereicht. +Mit `PulseAudio` wird ein PulseAudio-Sink an Multimon-NG weitergereicht, z.B. in Kombination mit [RTLSDR-Airband](https://github.com/szpajder/RTLSDR-Airband) und/oder Docker. #### `sdr:` |Feld|Beschreibung|Default| From 89d16793b26c6d77443f12b4a29dacc800cd8772 Mon Sep 17 00:00:00 2001 From: B-Watch Date: Thu, 9 Jul 2020 15:27:04 +0200 Subject: [PATCH 42/42] Fixed Typo --- module/template_module.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/template_module.py b/module/template_module.py index 2cb6eb1..2fe0568 100644 --- a/module/template_module.py +++ b/module/template_module.py @@ -25,7 +25,7 @@ from module.moduleBase import ModuleBase logging.debug("- %s loaded", __name__) -class BoswatchModul(ModuleBase): +class BoswatchModule(ModuleBase): """!Description of the Module""" def __init__(self, config): """!Do not change anything here!"""