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 <janspeller1@gmail.com>

* fixes

Co-authored-by: Jan Speller <janspeller1@gmail.com>
This commit is contained in:
kirschbaump 2020-04-20 08:18:29 +02:00 committed by GitHub
parent 9463bc1eec
commit c2aab648c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 134 additions and 3 deletions

View file

@ -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()

View file

@ -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)

View file

@ -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

View file

@ -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|