added configuration file support
This commit is contained in:
parent
4558c0f1b2
commit
37e5042808
120
configreader.py
Normal file
120
configreader.py
Normal file
|
@ -0,0 +1,120 @@
|
||||||
|
|
||||||
|
import csv
|
||||||
|
import ConfigParser
|
||||||
|
import tuitest
|
||||||
|
import phoneinterface
|
||||||
|
import fetapdtest
|
||||||
|
|
||||||
|
class ConfigurationReader(object):
|
||||||
|
DEFAULTS = {
|
||||||
|
'gpio_numbering': 'BOARD',
|
||||||
|
'pin_nsa': '11',
|
||||||
|
'pin_nsi': '13',
|
||||||
|
'pin_gabelschalter': '15',
|
||||||
|
'pin_schauzeichen': '12',
|
||||||
|
'pin_wecker_enable': '16',
|
||||||
|
'pin_wecker_a': '18',
|
||||||
|
'pin_wecker_b': '19',
|
||||||
|
|
||||||
|
'default_proxy': ''
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.__cp = ConfigParser.ConfigParser(defaults=ConfigurationReader.DEFAULTS)
|
||||||
|
self.__pinconfig = None
|
||||||
|
self.__dialconfig = None
|
||||||
|
self.__proxyconfigs = None
|
||||||
|
self.__phoneconfig = None
|
||||||
|
|
||||||
|
|
||||||
|
def __get_global_val(self, option):
|
||||||
|
return self.__cp.get('fetapd', option)
|
||||||
|
|
||||||
|
|
||||||
|
def __get_global_val_int(self, option):
|
||||||
|
return int(self.__cp.get('fetapd', option))
|
||||||
|
|
||||||
|
|
||||||
|
def __get_proxy_val(self, proxyname, option):
|
||||||
|
return self.__cp.get('proxy_'+proxyname, option)
|
||||||
|
|
||||||
|
|
||||||
|
def __get_proxy_val_int(self, proxyname, option):
|
||||||
|
return self.__cp.getint('proxy_'+proxyname, option)
|
||||||
|
|
||||||
|
|
||||||
|
def __read_shortcuts(self):
|
||||||
|
fname = self.__get_global_val('shortcuts_file')
|
||||||
|
shortcuts = {}
|
||||||
|
with open(fname, 'r') as csvfile:
|
||||||
|
for row in csv.DictReader(csvfile):
|
||||||
|
print 'row', row
|
||||||
|
shortcuts[row['shortcut']] = row['number']
|
||||||
|
return shortcuts
|
||||||
|
|
||||||
|
|
||||||
|
def read(self, f):
|
||||||
|
self.__cp.read(f)
|
||||||
|
|
||||||
|
print 'pin_nsa:', self.__get_global_val_int('pin_nsa'),
|
||||||
|
self.__pinconfig = tuitest.FeApPinConfiguration(
|
||||||
|
gpio_numbering = self.__get_global_val('gpio_numbering'),
|
||||||
|
pin_nsa = self.__get_global_val_int('pin_nsa'),
|
||||||
|
pin_nsi = self.__get_global_val_int('pin_nsi'),
|
||||||
|
pin_gabelschalter = self.__get_global_val_int('pin_gabelschalter'),
|
||||||
|
pin_schauzeichen = self.__get_global_val_int('pin_schauzeichen'),
|
||||||
|
pin_wecker_enable = self.__get_global_val_int('pin_wecker_enable'),
|
||||||
|
pin_wecker_a = self.__get_global_val_int('pin_wecker_a'),
|
||||||
|
pin_wecker_b = self.__get_global_val_int('pin_wecker_b')
|
||||||
|
)
|
||||||
|
|
||||||
|
self.__dialconfig = fetapdtest.DialConfiguration(
|
||||||
|
self.__get_global_val('dial_timeout'),
|
||||||
|
self.__read_shortcuts(),
|
||||||
|
)
|
||||||
|
|
||||||
|
proxyconfigs = []
|
||||||
|
for secname in self.__cp.sections():
|
||||||
|
if secname.startswith('proxy_'):
|
||||||
|
proxyname = secname[6:]
|
||||||
|
proxyconfig = phoneinterface.PhoneProxyConfiguration(
|
||||||
|
name = proxyname,
|
||||||
|
proxy = self.__get_proxy_val(proxyname, 'proxy'),
|
||||||
|
identity = self.__get_proxy_val(proxyname, 'identity'),
|
||||||
|
username = self.__get_proxy_val(proxyname, 'username'),
|
||||||
|
password = self.__get_proxy_val(proxyname, 'password'),
|
||||||
|
realm = self.__get_proxy_val(proxyname, 'realm'),
|
||||||
|
prefix = self.__get_proxy_val(proxyname, 'prefix')
|
||||||
|
)
|
||||||
|
proxyconfigs.append(proxyconfig)
|
||||||
|
|
||||||
|
self.__phoneconfig = phoneinterface.PhoneConfiguration(
|
||||||
|
sound_device = self.__get_global_val('sound_device'),
|
||||||
|
incoming_timeout = self.__get_global_val_int('incoming_timeout'),
|
||||||
|
linphone_config = self.__get_global_val('linphone_config'),
|
||||||
|
default_proxy = self.__get_global_val('default_proxy'),
|
||||||
|
stun_server = self.__get_global_val('stun_server'),
|
||||||
|
proxies = proxyconfigs
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@property
|
||||||
|
def pinconfig(self):
|
||||||
|
return self.__pinconfig
|
||||||
|
|
||||||
|
|
||||||
|
@property
|
||||||
|
def dialconfig(self):
|
||||||
|
return self.__dialconfig
|
||||||
|
|
||||||
|
|
||||||
|
@property
|
||||||
|
def phoneconfig(self):
|
||||||
|
return self.__phoneconfig
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
34
fetap.ini.example
Normal file
34
fetap.ini.example
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
|
||||||
|
[fetapd]
|
||||||
|
|
||||||
|
sound_device = default:CARD=Set
|
||||||
|
|
||||||
|
gpio_mode = BOARD
|
||||||
|
pin_nsa = 11
|
||||||
|
pin_nsi = 13
|
||||||
|
pin_gabelschalter = 15
|
||||||
|
pin_schauzeichen = 12
|
||||||
|
pin_wecker_enable = 16
|
||||||
|
pin_wecker_a = 18
|
||||||
|
pin_wecker_b = 19
|
||||||
|
|
||||||
|
incoming_timeout = 60
|
||||||
|
dial_timeout = 3
|
||||||
|
|
||||||
|
shortcuts_file = shortcuts.csv
|
||||||
|
linphone_config = linphone.conf
|
||||||
|
|
||||||
|
default_proxy = eventphone
|
||||||
|
|
||||||
|
stun_server = sipgate.de
|
||||||
|
|
||||||
|
[proxy_eventphone]
|
||||||
|
proxy = sip:hg.eventphone.de
|
||||||
|
realm = hg.eventphone.de
|
||||||
|
identity = sip:XXXX@hg.eventphone.de
|
||||||
|
username = XXXX
|
||||||
|
password = ***
|
||||||
|
prefix = 1
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,13 @@ import threading
|
||||||
import Queue as queue
|
import Queue as queue
|
||||||
from phoneinterface import PhoneInterface, PhoneEvent
|
from phoneinterface import PhoneInterface, PhoneEvent
|
||||||
from tuitest import FeApPinConfiguration, FeApUserInterface
|
from tuitest import FeApPinConfiguration, FeApUserInterface
|
||||||
|
import configreader
|
||||||
|
|
||||||
|
|
||||||
|
class DialConfiguration(object):
|
||||||
|
def __init__(self, dial_timeout, shortcuts):
|
||||||
|
self.dial_timeout = dial_timeout
|
||||||
|
self.shortcuts = shortcuts
|
||||||
|
|
||||||
class IllegalEventError(Exception):
|
class IllegalEventError(Exception):
|
||||||
pass
|
pass
|
||||||
|
@ -342,9 +349,11 @@ def phone_cb(event):
|
||||||
c.queue_event('invalid_number')
|
c.queue_event('invalid_number')
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
phone = PhoneInterface(None, '.linphonerc')
|
cfg = configreader.ConfigurationReader()
|
||||||
pinconf = FeApPinConfiguration()
|
cfg.read('fetap.ini')
|
||||||
feap = FeApUserInterface(pinconf)
|
|
||||||
|
phone = PhoneInterface(cfg.phoneconfig)
|
||||||
|
feap = FeApUserInterface(cfg.pinconfig)
|
||||||
c = StateMachineController(phone, feap)
|
c = StateMachineController(phone, feap)
|
||||||
|
|
||||||
feap.add_gabelschalter_callback(gabelschalter_cb)
|
feap.add_gabelschalter_callback(gabelschalter_cb)
|
||||||
|
|
19
linphone.conf
Normal file
19
linphone.conf
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
[sip]
|
||||||
|
register_only_when_network_is_up=1
|
||||||
|
root_ca=/etc/ssl/certs
|
||||||
|
verify_server_certs=1
|
||||||
|
verify_server_cn=1
|
||||||
|
|
||||||
|
[sound]
|
||||||
|
playback_dev_id=ALSA: USB PnP Sound Device
|
||||||
|
ringer_dev_id=ALSA: USB PnP Sound Device
|
||||||
|
capture_dev_id=ALSA: USB PnP Sound Device
|
||||||
|
playback_gain_db=0.000000
|
||||||
|
mic_gain_db=0.000000
|
||||||
|
|
||||||
|
[net]
|
||||||
|
adaptive_rate_control=1
|
||||||
|
firewall_policy=2
|
||||||
|
mtu=0
|
||||||
|
download_bw=0
|
||||||
|
upload_bw=0
|
|
@ -4,22 +4,25 @@ import threading
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
class PhoneProxyConfiguration(object):
|
class PhoneProxyConfiguration(object):
|
||||||
def __init__(self):
|
def __init__(self, name, proxy, identity, username, password, realm,
|
||||||
self.name = 'eventphone'
|
prefix):
|
||||||
self.proxy = 'sip:hg.eventphone.de'
|
self.name = name
|
||||||
self.identity = 'sip:0815@hg.eventphone.de'
|
self.proxy = proxy
|
||||||
self.username = '0815'
|
self.identity = identity
|
||||||
self.password = 'secret'
|
self.username = username
|
||||||
self.realm = 'hg.eventphone.de'
|
self.password = password
|
||||||
|
self.realm = realm
|
||||||
|
self.prefix = prefix
|
||||||
|
|
||||||
class PhoneConfiguration(object):
|
class PhoneConfiguration(object):
|
||||||
def __init__(self):
|
def __init__(self, sound_device, incoming_timeout, linphone_config,
|
||||||
self.sound_device = 'default:CARD=Device'
|
default_proxy, proxies, stun_server):
|
||||||
self.incoming_timeout = 3*60
|
self.sound_device = sound_device
|
||||||
self.linphone_config = 'linphone.conf'
|
self.incoming_timeout = incoming_timeout
|
||||||
self.default_proxy = 'eventphone'
|
self.linphone_config = linphone_config
|
||||||
self.proxies = []
|
self.default_proxy = default_proxy
|
||||||
self.stun_server = 'sipgate.de'
|
self.proxies = proxies
|
||||||
|
self.stun_server = stun_server
|
||||||
|
|
||||||
class PhoneEvent(object):
|
class PhoneEvent(object):
|
||||||
RegInProgress,\
|
RegInProgress,\
|
||||||
|
|
2
shortcuts.csv.sample
Normal file
2
shortcuts.csv.sample
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
shortcut,number
|
||||||
|
0,3474
|
29
tuitest.py
29
tuitest.py
|
@ -5,21 +5,30 @@ import threading
|
||||||
|
|
||||||
|
|
||||||
class FeApPinConfiguration(object):
|
class FeApPinConfiguration(object):
|
||||||
def __init__(self):
|
def __init__(self, gpio_numbering, pin_nsa, pin_nsi, pin_gabelschalter,
|
||||||
self.numbering = gpio.BOARD
|
pin_schauzeichen, pin_wecker_enable, pin_wecker_a,
|
||||||
self.pin_nsa = 11
|
pin_wecker_b):
|
||||||
self.pin_nsi = 13
|
if gpio_numbering == 'BOARD':
|
||||||
self.pin_gabelschalter = 15
|
gpio_numbering = gpio.BOARD
|
||||||
self.pin_schauzeichen = 12
|
elif gpio_numbering == 'BCM':
|
||||||
self.pin_wecker_enable = 16
|
gpio_numbering = gpio.BCM
|
||||||
self.pin_wecker_a = 18
|
else:
|
||||||
self.pin_wecker_b = 19
|
raise ValueError('Illegal gpio numbering: %s' % (gpio_numbering))
|
||||||
|
|
||||||
|
self.gpio_numbering = gpio_numbering
|
||||||
|
self.pin_nsa = pin_nsa
|
||||||
|
self.pin_nsi = pin_nsi
|
||||||
|
self.pin_gabelschalter = pin_gabelschalter
|
||||||
|
self.pin_schauzeichen = pin_schauzeichen
|
||||||
|
self.pin_wecker_enable = pin_wecker_enable
|
||||||
|
self.pin_wecker_a = pin_wecker_a
|
||||||
|
self.pin_wecker_b = pin_wecker_b
|
||||||
|
|
||||||
class FeApUserInterface(object):
|
class FeApUserInterface(object):
|
||||||
def __init__(self, pinconfig):
|
def __init__(self, pinconfig):
|
||||||
self.__pinconfig = pinconfig
|
self.__pinconfig = pinconfig
|
||||||
|
|
||||||
gpio.setmode(self.__pinconfig.numbering)
|
gpio.setmode(self.__pinconfig.gpio_numbering)
|
||||||
gpio.setup(self.__pinconfig.pin_nsa, gpio.IN, gpio.PUD_UP)
|
gpio.setup(self.__pinconfig.pin_nsa, gpio.IN, gpio.PUD_UP)
|
||||||
gpio.setup(self.__pinconfig.pin_nsi, gpio.IN, gpio.PUD_UP)
|
gpio.setup(self.__pinconfig.pin_nsi, gpio.IN, gpio.PUD_UP)
|
||||||
gpio.setup(self.__pinconfig.pin_gabelschalter, gpio.IN, gpio.PUD_UP)
|
gpio.setup(self.__pinconfig.pin_gabelschalter, gpio.IN, gpio.PUD_UP)
|
||||||
|
|
Loading…
Reference in a new issue