summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArda2011-07-12 05:05:07 +0200
committerArda2011-07-12 05:05:07 +0200
commit6070053d66baaaa6681ea00bcd2435eccfb6fe26 (patch)
tree0f1108428ba185987972e460b3f36b2c801ab636
parenti hope this will work (diff)
downloadgsm-selftest-6070053d66baaaa6681ea00bcd2435eccfb6fe26.tar.gz
gsm-selftest-6070053d66baaaa6681ea00bcd2435eccfb6fe26.tar.xz
gsm-selftest-6070053d66baaaa6681ea00bcd2435eccfb6fe26.zip
Better working code for landlineCall. Still needs improvements.
-rw-r--r--notFinishedCode/landlineCall.py137
1 files changed, 37 insertions, 100 deletions
diff --git a/notFinishedCode/landlineCall.py b/notFinishedCode/landlineCall.py
index f86799b..7fa6625 100644
--- a/notFinishedCode/landlineCall.py
+++ b/notFinishedCode/landlineCall.py
@@ -1,29 +1,23 @@
import sys
import pjsua as pj
-import socket
import time
-#import classServer
-
from time import sleep
from datetime import datetime
import string
-
-stop ="false"
server = "sipgate.de"
username = "1289459"
password = "MMW9AX"
+number = "01726831773"
LOG_LEVEL=2
current_call = None
-success = ""
-num = "01726831773"
-
+userInput = ""
# Logging callback
def log_cb(level, str, len):
- print str, "Landline log"
+ print str, "landlineCall Logging"
# Callback to receive events from account
@@ -45,36 +39,27 @@ class MyCallCallback(pj.CallCallback):
# Notification when call state has changed
def on_state(self):
global current_call
- global success
-
- if self.call.info().state_text <> "DISCONNCTED":
- if self.call.info().state_text == "CONNECTING":
- print "CONNECTING CALL"
- #print "isine opo:", self.call.info().state_text
- print "CALL CONFIRMED and ESTABLISH", self.call.info().state_text
- sleep(5)
- current_call.hangup()
- success = "true"
-# server.sendData(success)
- else:
- sleep(1)
- #print ""
- if self.call.info().last_reason <> "":
+ if self.call.info().state == pj.CallState.CALLING:
+ print "TRYING TO CALL"
+
+ if self.call.info().state == pj.CallState.CONNECTING:
+ print "CONNECTING"
+
+ if self.call.info().state == pj.CallState.EARLY:
+ print "CALLEE IS RINGING"
- if self.call.info().last_reason == "Busy Here":
-
- print "Destination Number is Busy or offline"
- print ""
- success = "false"
-# server.sendData(success)
-
-
- #print self.call.info().state_text
+ if self.call.info().state == pj.CallState.CONFIRMED:
+ print "CALL CONFIRMED"
+ sleep(5)
+ current_call.hangup()
+
+ if self.call.info().last_code == 486:
+ print "CALLEE IS BUSY"
- if self.call.info().state == pj.CallState.DISCONNECTED:
- current_call = None
- print 'Current call Disconnected'
+ if self.call.info().state == pj.CallState.DISCONNECTED:
+ current_call = None
+ print "CURRENT CALL DISCONNECTED"
def make_call(uri):
@@ -87,89 +72,41 @@ def make_call(uri):
return None
-
-
lib = pj.Lib()
-while stop <> "true":
+lib.init(log_cfg = pj.LogConfig(level=LOG_LEVEL, callback=log_cb))
+transport = lib.create_transport(pj.TransportType.UDP, pj.TransportConfig(0))
+lib.start()
+lib.set_null_snd_dev()
+print "You want to call then."
- lib.init(log_cfg = pj.LogConfig(level=LOG_LEVEL, callback=log_cb))
- transport = lib.create_transport(pj.TransportType.UDP, pj.TransportConfig(0))
-
- print "\nListening on", transport.info().host,
- print "port", transport.info().port, "\n"
- lib.start()
- lib.set_null_snd_dev()
-
- # open socket connection and connect to the controller
-# server = classServer.ServerHandler(50097)
-# tried = server.openSocket()
-
-# if server.error != 'No error':
-# print server.error
-# if server.error == '[Errno 98] Address already in use':
-# print 'one should try to kill the port'
-# print server.killPort()
-# server.closeConection()
+while userInput <> "quit":
try:
acc_cfg = pj.AccountConfig(server,username,password)
acc = lib.create_account(acc_cfg, cb=MyAccountCallback())
-
-
- if acc.info().reg_status < 700:
-
- my_sip_uri = "sip:" + transport.info().host + ":" + str(transport.info().port)
-
-# server.sendData('I am ready')#send message to controller
-# print "here:", server.connected
- while 1:
- try:
- data = "start" # waiting mode, until receiver start message or terminate message
- if data == "start": # if receiver start message, handler start to call destination
-
- while 1:
-
-# num = server.receiveData() # waiting destination number
- if num <> "":
-
- number = "sip:"+num+"@sipgate.de"
- current_call = make_call(number)
- break
-
- if data == "terminated": # will terminate the handler if controller send terminate message
- stop = "true"
- break
-
- except ValueError:
- print "error when sending message"
- server.closeConnection()
- del server
-
- server.closeConnection()
- del server
+ if acc.info().reg_status < 700:
+ numberToCall = "sip:"+number+"@"+server
+ current_call = make_call(numberToCall)
+ sleep(15)
else:
- Regis_status= "Bad"
- print "error when register"
-
+ print "REGISTRATION ERROR"
lib.destroy()
lib = None
acc = None
-
-
- server.closeConnection()
- del server
+
except ValueError:
print "Exception: " + str(e)
-print "Goodbye"
+ userInput = sys.stdin.readline().rstrip("\r\n")
+
+print "Deleting library and account info..."
sleep(3)
acc.delete()
lib.destroy()
-server.closeConnection()
-del server
lib = None
acc = None
+print "Deleting was successful!"