def on_reg_state(self): if self.semaphore: if self.account.info().reg_status >= 200: logger(LOG_ERR, 'SCK registration status ' + str(self.account.info().reg_status) + ' ' + self.account.info().reg_reason) self.semaphore.release()
def make_call(uri): try: logger(log_info, "SCK (" + uri + ")") call = acc.make_call(uri, VeCallCallback()) return call except pj.Error, e: logger(log_err, "SCK " + str(e)) return None
def on_reg_state(self): if self.semaphore: if self.account.info().reg_status >= 200: logger( LOG_ERR, 'SCK registration status ' + str(self.account.info().reg_status) + ' ' + self.account.info().reg_reason) self.semaphore.release()
def make_call(uri): try: logger(LOG_INFO, "SCK ("+uri+")") call = acc.make_call(uri, CallCallback()) return call except pj.Error, message: logger(LOG_ERR, "SCK " + str(message)) return None
def make_call(uri): try: logger(log_info, "SCK ("+uri+")") call = acc.make_call(uri, VeCallCallback()) return call except pj.Error, e: logger(log_err, "SCK " + str(e)) return None
def make_call(uri): try: logger(LOG_INFO, "SCK (" + uri + ")") call = acc.make_call(uri, CallCallback()) return call except pj.Error, message: logger(LOG_ERR, "SCK " + str(message)) return None
def on_reg_state(self): if self.sem: if self.account.info().reg_status >= 200: logger( log_err, 'SCK registration status ' + str(self.account.info().reg_status) + ' ' + self.account.info().reg_reason) self.sem.release()
def read_ports(ports): port = {} try: for key, gpio in ports.iteritems(): port[key] = key, _read_port_value(gpio + '/value') return port except: logger(log_err, 'SCK GPIO Read Error') return None
def read_input(ports): port = {} try: for key, gpio in ports.iteritems(): port[key] = key, _read_port_value(gpio + '/value') return port except: logger(LOG_ERR, 'SCK GPIO Read Error') return None
def on_reg_state(self): if self.sem: if self.account.info().reg_status >= 200: logger(log_err, 'SCK registration status ' + str(self.account.info().reg_status) + ' ' + self.account.info().reg_reason ) self.sem.release()
def on_incoming_call(self, call): # TODO A lot of stuff, call handling mainly and logging also logger(LOG_INFO, "SCK Incoming call from " + call.info().remote_uri) global current_call # TODO global tone # tone = VeTone().ring_start() current_call = call call_cb = CallCallback(current_call) current_call.set_callback(call_cb) current_call.answer(200)
def get_speedial(): speedial = None try: ext1 = config.get("speedial", "ext1") ext2 = config.get("speedial", "ext2") ext3 = config.get("speedial", "ext3") ext4 = config.get("speedial", "ext4") ext5 = config.get("speedial", "ext5") speedial = dict([('ext1', ext1), ('ext2', ext2), ('ext3', ext3), ('ext4', ext4), ('ext5', ext5)]) return speedial except: logger(log_err, "SCK Can't Load Speed Dial Extensions")
def get_ports(): try: config = ConfigParser.ConfigParser() config.readfp(open('exports.ini')) #TODO It could be a RawConfigParser to get the whole dictionary from cfg return dict([('siren', config.get('features', 'sirena')), ('local_audio', config.get('features', 'llave')), ('button_1', config.get('features', 'boton1')), ('button_2', config.get('features', 'boton2')), ('button_3', config.get('features', 'boton3')), ('button_4', config.get('features', 'boton4')), ('button_5', config.get('features', 'boton5'))]) except: logger(LOG_ERR, 'SCK GPIO Expansion Ports Config Error') return None
def get_ports(): try: config = ConfigParser.ConfigParser() config.readfp(open('exports.ini')) #TODO It could be a RawConfigParser to get the whole dictionary from cfg return dict([ ('siren', config.get('features', 'sirena')), ('local_audio', config.get('features', 'llave')), ('button_1', config.get('features', 'boton1')), ('button_2', config.get('features', 'boton2')), ('button_3', config.get('features', 'boton3')), ('button_4', config.get('features', 'boton4')), ('button_5', config.get('features', 'boton5')) ]) except: logger(log_err, 'SCK GPIO Expansion Ports Config Error') return None
def get_audiocfg(): audiocfg = None try: master = config.get("audio", "master") pcm = config.get("audio", "pcm") capture = config.get("audio", "capture") cap_idx = config.get("audio", "cap_idx") input_src = config.get("audio", "input_src") in_idx = config.get("audio", "in_idx") mic = config.get("audio", "mic") mic_boost = config.get("audio", "mic_boost") audiocfg = dict([('master',master), ('pcm',pcm), ('capture',capture), ('cap_idx',cap_idx), ('input_src',input_src), ('in_idx',in_idx), ('mic',mic), ('mic_boost',mic_boost)]) return audiocfg except: logger(log_err,"SCK Config Audio Error.")
def get_audiocfg(): audiocfg = None try: master = config.get("audio", "master") pcm = config.get("audio", "pcm") capture = config.get("audio", "capture") cap_idx = config.get("audio", "cap_idx") input_src = config.get("audio", "input_src") in_idx = config.get("audio", "in_idx") mic = config.get("audio", "mic") mic_boost = config.get("audio", "mic_boost") audiocfg = dict([('master', master), ('pcm', pcm), ('capture', capture), ('cap_idx', cap_idx), ('input_src', input_src), ('in_idx', in_idx), ('mic', mic), ('mic_boost', mic_boost)]) return audiocfg except: logger(log_err, "SCK Config Audio Error.")
def get_sipcfg(): sipcfg = None logger(log_info, "SCK Trying to register in PBX") try: ext = config.get("sip", "ext") srv = config.get("sip", "srv") pwd = config.get("sip", "passwd") sipcfg = dict([('ext', ext), ('srv', srv), ('pwd', pwd)]) logger(log_info, "SCK SIP Account Credentials, " + ext + "@" + srv) return sipcfg except: logger(log_err, "SCK Error while reading SIP Auth Credentials")
def on_state(self): global current_call logger(LOG_INFO, "SCK Call is " + self.call.info().state_text) logger(LOG_INFO, "SCK Last code = " + str(self.call.info().last_code)) logger(LOG_INFO, "SCK (" + self.call.info().last_reason + ")") global call_state call_state = self.call.info().state # global tone if call_state == pj.CallState.EARLY: # tone = VeTone().ring_start() pass elif call_state == pj.CallState.DISCONNECTED: # VeTone().ring_stop(tone) current_call = None
# Start the library lib.start() if sipcfg == None: # Create local/user-less account acc = lib.create_account_for_transport(transport) else: # Register on PBX acc = lib.create_account( pj.AccountConfig(sipcfg['srv'], sipcfg['ext'], sipcfg['pwd'])) # Set the account call back acc_cb = VeAccountCallback(acc) acc.set_callback(acc_cb) acc_cb.wait() # Global variables ve_local_audio = False ve_call = None # main loop main_loop() # We're done, shutdown the library lib.destroy() lib = None sys.exit(0) except pj.Error, e: logger(log_err, "SCK Exception: " + str(e)) lib.destroy() lib = None sys.exit(1)
def main_loop(): logger(LOG_INFO, "SCK Ready!") while True: try: # Read input operation in_value = read_input() # Special options are handled by *,-,+ and / characters if in_value == "*": # TODO * enable local audio logger(LOG_INFO, "SCK Toggle Local MIC") elif in_value == "+": # TODO Test only option, do not use it for real services! logger(LOG_INFO, "SCK Dialing TEST") #make_call("sip:[email protected]") elif in_value == "-": # TODO reserved logger(LOG_INFO, "SCK - Action Reserved") elif in_value == "/": # Exit manually logger(LOG_INFO, "SCK Exit on user request!") return elif in_value in DIGITS: # Only the PC version takes the whole range of digits as input if _hardware == 'pc': for speed, ext in speedial.iteritems(): getattr(ve_speedial, 'ext'+in_value)(ext) else: logger(LOG_INFO, u'SCK trying to dial with digits in an unsupported hardware') elif in_value in PINOUT: if _hardware == 'cb2': for speed, ext in speedial.iteritems(): getattr(ve_speedial, in_value)(ext) else: logger(LOG_INFO, u'SCK trying to dial with GPIO in an unsupported hardware') else: logger(LOG_ERR, 'SCK Invalid input ' + in_value) except ValueError: logger(LOG_INFO, "SCK Exception, this is weird!") continue
def log_cb(level, str, len): logger(LOG_INFO, "PJSUA " + str)
import threading from syslog import syslog as logger from syslog import LOG_INFO from syslog import LOG_ERR import config # Global stuff FLAVORS = ['pc', 'cb2', 'ct'] DIGITS = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] PINOUT = ['ext1', 'ext2', 'ext3', 'ext4', 'ext5', 'siren', 'spk'] LOG_LEVEL = 3 call_in_progress = None # Detect hardware, supported flavors are PC, Cubieboard 2 and Cubietruck _hardware = config.get_flavor() logger(LOG_INFO, u'SCK Running with ' + _hardware + ' settings') if _hardware in FLAVORS: if _hardware == 'pc': import getchar as in_interface elif _hardware == 'cb2': import wiringcb as in_interface elif _hardware == 'ct': import gpio_api as in_interface read_input = in_interface.read_input() else: logger(LOG_ERR, u'SCK does not support the hardware') sys.exit(1) # Logging callback def log_cb(level, str, len):
logger(LOG_ERR, 'SCK Failed to detect flavor') def get_sipcfg(): try: return dict(config.items('sip')) except: logger(LOG_ERR, "SCK Error while reading SIP Auth Credentials") def get_speedial(): try: return dict(config.items('speedial')) except: logger(LOG_ERR, "SCK Can't Load Speed Dial Extensions") try: config = ConfigParser.RawConfigParser() #config.readfp(open('config.ini')) config.read([ os.path.expanduser('~/.config/sck/config.ini'), os.path.dirname(os.path.realpath(__file__)) + '/config.ini', os.path.expanduser('/etc/sck/config.ini') ]) except: logger(LOG_ERR, "SCK General Config Exception,")
def get_flavor(): try: return config.get('default','flavor') except: logger(log_err, 'SCK Failed to detect falvor')
def get_speedial(): try: return dict(config.items('speedial')) except: logger(LOG_ERR, "SCK Can't Load Speed Dial Extensions")
def get_sipcfg(): try: return dict(config.items('sip')) except: logger(LOG_ERR, "SCK Error while reading SIP Auth Credentials")
def get_flavor(): try: return config.get('default', 'flavor') except: logger(LOG_ERR, 'SCK Failed to detect flavor')
def log_cb(level, str, len): logger(log_info,"PJSUA " + str), logger(log_info, "SCK Ready!")
def ext9(self, ext): global call_in_progress if call_in_progress is None: logger(LOG_INFO, 'SCK Dialing TODO') call_in_progress = make_call('sip:' + ext + '@' + sipcfg['srv'])
except: logger(log_err, "SCK Error while reading SIP Auth Credentials") def get_speedial(): speedial = None try: ext1 = config.get("speedial", "ext1") ext2 = config.get("speedial", "ext2") ext3 = config.get("speedial", "ext3") ext4 = config.get("speedial", "ext4") ext5 = config.get("speedial", "ext5") speedial = dict([('ext1', ext1), ('ext2', ext2), ('ext3', ext3), ('ext4', ext4), ('ext5', ext5)]) return speedial except: logger(log_err, "SCK Can't Load Speed Dial Extensions") try: config = ConfigParser.RawConfigParser() config.read([os.path.expanduser('/etc/sck/config.ini'), os.path.expanduser('~/sck/config.ini'), os.path.dirname(os.path.realpath(__file__)) + '/config.ini', 'config.ini'] ) except: logger(log_err, "SCK General Config Exception,")
def log_cb(level, str, len): logger(log_info, "PJSUA " + str), logger(log_info, "SCK Ready!")
def main_loop(): logger(LOG_INFO, "SCK Ready!") while True: try: # Read input operation in_value = read_input() # Special options are handled by *,-,+ and / characters if in_value == "*": # TODO * enable local audio logger(LOG_INFO, "SCK Toggle Local MIC") elif in_value == "+": # TODO Test only option, do not use it for real services! logger(LOG_INFO, "SCK Dialing TEST") #make_call("sip:[email protected]") elif in_value == "-": # TODO reserved logger(LOG_INFO, "SCK - Action Reserved") elif in_value == "/": # Exit manually logger(LOG_INFO, "SCK Exit on user request!") return elif in_value in DIGITS: # Only the PC version takes the whole range of digits as input if _hardware == 'pc': for speed, ext in speedial.iteritems(): getattr(ve_speedial, 'ext' + in_value)(ext) else: logger( LOG_INFO, u'SCK trying to dial with digits in an unsupported hardware' ) elif in_value in PINOUT: if _hardware == 'cb2': for speed, ext in speedial.iteritems(): getattr(ve_speedial, in_value)(ext) else: logger( LOG_INFO, u'SCK trying to dial with GPIO in an unsupported hardware' ) else: logger(LOG_ERR, 'SCK Invalid input ' + in_value) except ValueError: logger(LOG_INFO, "SCK Exception, this is weird!") continue
def main_loop(): while True: try: # Read only one character from standard input getch = gc._Getch() choice = getch() # Special options are handled by *,-,+ and / characters if choice == "*": # * enable local audio logger(log_info, "SCK Toggle Local MIC") # TODO elif choice == "+": # Test only option, do not use it for real services! logger(log_info, "SCK Dialing TEST") make_call("sip:[email protected]") elif choice == "-": # TODO reserved logger(log_info, "SCK - Action Reserved") elif choice == "/": # Exit manually logger(log_info, "SCK Exit on user request!") return else: for extension in speedial: # TODO FIX this, so ugly hack if extension == "ext1": make_call('sip:' + speedial['ext1'] + '@' + sipcfg['srv']) logger(log_info, "SCK Dialing " + extension) elif extension == "ext2": make_call('sip:' + speedial['ext2'] + '@' + sipcfg['srv']) logger(log_info, "SCK Dialing " + extension) elif extension == "ext3": make_call('sip:' + speedial['ext3'] + '@' + sipcfg['srv']) logger(log_info, "SCK Dialing " + extension) elif extension == "ext4": make_call('sip:' + speedial['ext4'] + '@' + sipcfg['srv']) logger(log_info, "SCK Dialing " + extension) elif extension == "ext5": make_call('sip:' + speedial['ext5'] + '@' + sipcfg['srv']) logger(log_info, "SCK Dialing " + extension) except ValueError: logger(log_info, "SCK Exception, this is weird!") continue
if sipcfg == None: # Create local/user-less account acc = lib.create_account_for_transport(transport) else: # Register on PBX acc = lib.create_account( pj.AccountConfig(sipcfg['srv'], sipcfg['ext'], sipcfg['pwd']) ) # Set the account call back acc_cb = VeAccountCallback(acc) acc.set_callback(acc_cb) acc_cb.wait() # Global variables ve_local_audio = False ve_call = None # main loop main_loop() # We're done, shutdown the library lib.destroy() lib = None sys.exit(0) except pj.Error, e: logger(log_err, "SCK Exception: " + str(e)) lib.destroy() lib = None sys.exit(1)
master = config.get("audio", "master") pcm = config.get("audio", "pcm") capture = config.get("audio", "capture") cap_idx = config.get("audio", "cap_idx") input_src = config.get("audio", "input_src") in_idx = config.get("audio", "in_idx") mic = config.get("audio", "mic") mic_boost = config.get("audio", "mic_boost") audiocfg = dict([('master', master), ('pcm', pcm), ('capture', capture), ('cap_idx', cap_idx), ('input_src', input_src), ('in_idx', in_idx), ('mic', mic), ('mic_boost', mic_boost)]) return audiocfg except: logger(log_err, "SCK Config Audio Error.") try: config = ConfigParser.RawConfigParser() config.read([ os.path.expanduser('~/settings/config.ini'), os.path.expanduser('~/.veconfig.ini'), os.path.dirname(os.path.realpath(__file__)) + '/config.ini', os.path.expanduser('~/sauron-com-kit/ve-phone/config.ini'), 'config.ini' ]) except: logger(log_err, "SCK General Config Exception,")
except: logger(LOG_ERR, 'SCK Failed to detect flavor') def get_sipcfg(): try: return dict(config.items('sip')) except: logger(LOG_ERR, "SCK Error while reading SIP Auth Credentials") def get_speedial(): try: return dict(config.items('speedial')) except: logger(LOG_ERR, "SCK Can't Load Speed Dial Extensions") try: config = ConfigParser.RawConfigParser() config.readfp(open('config.ini')) config.read([os.path.expanduser('/etc/sck/config.ini'), os.path.expanduser('~/sck/config.ini'), os.path.dirname(os.path.realpath(__file__)) + '/config.ini'] ) except: logger(LOG_ERR, "SCK General Config Exception,")