def __init__(self, micDeviceID=-1, outDeviceID = -1): Thread.__init__(self) self.daemon = True if(False): ProcessBytes.UserProfile = PersonProfile(isInterfaceAsKeyboard) if(isInterfaceAsKeyboard): contents = input() ProcessBytes.UserProfile.AssignContents(contents) self.Talking = MicUDPCommunicator(micDeviceID=micDeviceID, network = network) self.Hearing = SpeakerUDPCommunicator(portNumber=PortNumber, network = network, SpeakerDeviceID = outDeviceID) self.ConnectionStatus = 'idle' self.Run = False self.CallersIP = None self.IP = self.Talking.IPAddress self.callingTone = wave.open('ring.wav', 'rb') self.RingingTone = wave.open('bell.wav', 'rb') self.VideoSender = None self.VideoReciver = None self.enableVideoCalling = enableVideoCalling if(enableVideoCalling): self.VideoSender = WebcamSender() self.VideoReciver = WebcamRemoteReciever(VideoPortNo) self.start() self.fnPrint = None
def CreatePhoneTermianl(): MicUDPCommunicator.printListOfMicDevices() SpeakerUDPCommunicator.printListOfSpeakerDevices() micDeviceID = -1 outDeviceID = -1 global PT PT = PhoneTerminal(micDeviceID, outDeviceID) PT.fnPrint = putStatus sleep(2)
def __init__(self, micDeviceID=-1, outDeviceID=-1): Thread.__init__(self) self.daemon = True if (False): #make true to enable physical key ProcessBytes.UserProfile = PersonProfile(isInterfaceAsKeyboard) if (isInterfaceAsKeyboard): contents = input() ProcessBytes.UserProfile.AssignContents(contents) self.Talking = MicUDPCommunicator(micDeviceID=micDeviceID, network=network) self.Hearing = SpeakerUDPCommunicator(portNumber=PortNumber, network=network, SpeakerDeviceID=outDeviceID) self.ConnectionStatus = 'idle' self.Run = False self.start()
def CreatePhoneTermianl(): MicUDPCommunicator.printListOfMicDevices() SpeakerUDPCommunicator.printListOfSpeakerDevices() micDeviceID = -1 outDeviceID = -1 global PT PT = PhoneTerminal(micDeviceID, outDeviceID) PT.fnPrint = putStatus if (PT.enableVideoCalling): tw = Tkinter.Toplevel() frame = VideoGUI(master=tw, Width=640, Height=480, imageWidth=640, imageHeight=480) frame.startCamera(PT.VideoReciver) frame.pack() tw.after(0, frame.Loop) sleep(2)
class PhoneTerminal(Thread): def __init__(self, micDeviceID=-1, outDeviceID=-1): Thread.__init__(self) self.daemon = True if (False): #make true to enable physical key ProcessBytes.UserProfile = PersonProfile(isInterfaceAsKeyboard) if (isInterfaceAsKeyboard): contents = input() ProcessBytes.UserProfile.AssignContents(contents) self.Talking = MicUDPCommunicator(micDeviceID=micDeviceID, network=network) self.Hearing = SpeakerUDPCommunicator(portNumber=PortNumber, network=network, SpeakerDeviceID=outDeviceID) self.ConnectionStatus = 'idle' self.Run = False self.start() def run(self): print("[Info :] Phone terminal service started") self.Run = True while (self.Run): try: sleep(1) if (self.ConnectionStatus == 'ConnectTo'): print("Hold on") while (self.Hearing.ConnectionEstablished == False): self.sine_tone(440, 1) #print ".", if (self.Run == False): return PacketDetails.Details() sleep(1) print("The client " + str(self.Hearing.callerIP[0]) + " has just connected.. Please start talking") self.Talking.clearBuffer() self.ConnectionStatus = 'Talking' self.WaitTillCallisDisconnected() self.Disconnect() self.ConnectionStatus = 'idle' if (self.ConnectionStatus == 'idle'): if (self.Hearing.callerIP is not None): print(self.Hearing.callerIP) print("Getting a call from " + str(self.Hearing.callerIP[0])) while True: self.sine_tone(440, 3) #print ".", #i, o, e = select.select( [sys.stdin], [], [], 2) i = 1 if (i): print "You picked up phone.." break if (self.Run == False): return PacketDetails.Details() print("The client " + str(self.Hearing.callerIP[0]) + " has just connected..") self.ConnectTo(self.Hearing.callerIP[0]) self.Talking.clearBuffer() self.ConnectionStatus = 'Talking' self.WaitTillCallisDisconnected() self.Disconnect() self.ConnectionStatus = 'idle' if (self.ConnectionStatus == 'Conference'): print("Hold on for participants to join") while (self.Hearing.callerIP is None): #print ".", if (self.Run == False): return sleep(2) PacketDetails.Details() print("The client " + str(self.Hearing.callerIP[0]) + " has just connected.. Please start talking") self.ConnectionStatus = 'Talking' #self.WaitTillCallisDisconnected() #self.LeaveConference(MultiCastGrp, MuliCastPortNo) #self.ConnectionStatus = 'idle' PacketDetails.Details() except KeyboardInterrupt: break def ConnectTo(self, IPAddress): if (self.ConnectionStatus == 'idle'): self.Talking.ConnectTo(IPAddress, PortNumber) self.ConnectionStatus = 'ConnectTo' print("Making connection...") else: print("[Alert :] Please hang up current call") def WaitTillCallisDisconnected(self): while (True): try: sleep(1) if (self.Talking.ConnectionEstablished == False): print("[Info :] You have closed the connection") break if (self.Hearing.ConnectionEstablished == False): print("[Info :] The reciver has disconnected") break if (self.Run == False): break PacketDetails.Details() except KeyboardInterrupt: break def ConnectToConference(self, ConferenceIP, ConferencePortNo): if (self.ConnectionStatus == 'idle'): self.Talking.ConnectToMultiCastGroup(ConferenceIP, ConferencePortNo) self.Hearing.JointMulticastGroup(ConferenceIP, ConferencePortNo) self.ConnectionStatus = 'Conference' else: print("[Alert :] Please hang up current call") def LeaveConference(self, ConferenceIP, ConferencePortNo): self.Hearing.LeaveMulticastGroup() self.Talking.LeaveMulticastGroup() def Disconnect(self): self.Talking.Disconnect() self.Hearing.Disconnect() def CloseTerminal(self): self.Run = False self.Disconnect() self.join() print("[Info :] Phone terminal is shutdown") self.Talking.ShutDownComplete() self.Hearing.ShutDownComplete() def sine_tone(self, frequency, duration, volume=1, sample_rate=22050): n_samples = int(sample_rate * duration) restframes = n_samples % sample_rate s = lambda t: volume * math.sin(2 * math.pi * frequency * t / sample_rate) samples = (int(s(t) * 0x7f + 0x80) for t in xrange(n_samples)) for buf in izip(*[samples] * sample_rate): # write several samples at a time self.Hearing.returnBytes(bytes(bytearray(buf))) # fill remainder of frameset with silence self.Hearing.returnBytes(b'\x80' * restframes)
# fill remainder of frameset with silence self.Hearing.returnBytes(b'\x80' * restframes) def GroupCaller(DialTo, PortNo, micDeviceID=1): caller = PhoneTerminal(micDeviceID) if (True): # try: caller.ConnectToConference(DialTo, PortNo) caller.LeaveConference(DialTo, PortNo) if __name__ == "__main__": MicUDPCommunicator.printListOfMicDevices() SpeakerUDPCommunicator.printListOfSpeakerDevices() micDeviceID = -1 outDeviceID = -1 areYouCaller = False isGroupCall = True caller = PhoneTerminal(micDeviceID, outDeviceID) sleep(2) if (isGroupCall): caller.ConnectToConference(MultiCastGrp, MuliCastPortNo) else: if (areYouCaller): caller.ConnectTo('192.168.1.103')
class PhoneTerminal(Thread): def __init__(self, micDeviceID=-1, outDeviceID = -1): Thread.__init__(self) self.daemon = True if(False): ProcessBytes.UserProfile = PersonProfile(isInterfaceAsKeyboard) if(isInterfaceAsKeyboard): contents = input() ProcessBytes.UserProfile.AssignContents(contents) self.Talking = MicUDPCommunicator(micDeviceID=micDeviceID, network = network) self.Hearing = SpeakerUDPCommunicator(portNumber=PortNumber, network = network, SpeakerDeviceID = outDeviceID) self.ConnectionStatus = 'idle' self.Run = False self.CallersIP = None self.IP = self.Talking.IPAddress self.callingTone = wave.open('ring.wav', 'rb') self.RingingTone = wave.open('bell.wav', 'rb') self.VideoSender = None self.VideoReciver = None self.enableVideoCalling = enableVideoCalling if(enableVideoCalling): self.VideoSender = WebcamSender() self.VideoReciver = WebcamRemoteReciever(VideoPortNo) self.start() self.fnPrint = None def printC(self, message): if(self.fnPrint == None): print(message) else: self.fnPrint(message) print(message) def run(self): print("[Info :] Phone terminal service started") self.Run = True while(self.Run): try: sleep(1) if(self.ConnectionStatus == 'ConnectTo'): self.printC("Hold on") while (self.Hearing.ConnectionEstablished == False): while True: dataTone = self.callingTone.readframes(2048) if(dataTone!=''): self.Hearing.returnBytes(dataTone) else: self.callingTone = wave.open('ring.wav', 'rb') break #print ".", if(self.Run == False): return PacketDetails.Details() if(self.ConnectionStatus=="Disconnect"): break if(self.IsPhysicalKeyConnected()==False): self.printC("[Alert :] Physical key not connected closing the call") self.ConnectionStatus = "Disconnect" break sleep(1) if (self.ConnectionStatus != "Disconnect"): self.printC("The client " + str(self.Hearing.callerIP[0]) + " has just connected.. Please start talking") self.Talking.clearBuffer() self.Hearing.ONReceptionToSpeakers = True if(enableVideoCalling): self.VideoSender.ConnectTo(self.Hearing.callerIP[0], VideoPortNo) self.ConnectionStatus = 'Talking' self.WaitTillCallisDisconnected() else: self.printC("Idle. Make sure physical key is attached to the system") self.Disconnect() sleep(4) self.ConnectionStatus = 'idle' if (self.ConnectionStatus == 'idle'): self.CallersIP = self.Hearing.callerIP if(self.CallersIP is not None): print(self.Hearing.callerIP) self.printC("Getting a call from " + str(self.Hearing.callerIP[0])) self.ConnectionStatus = 'ringing' while self.ConnectionStatus != 'pickup': #self.sine_tone(440, 0.1) while True : dataTone = self.RingingTone.readframes(2048) if (dataTone != ''): self.Hearing.returnBytes(dataTone) else: self.RingingTone = wave.open('bell.wav', 'rb') sleep(2) break #print ".", #i, o, e = select.select( [sys.stdin], [], [], 2) #i = 1 #if (i): # # break # if (self.ConnectionStatus == "Disconnect"): # break if (self.ConnectionStatus == "Disconnect"): break if(self.Run == False): return if(self.IsPhysicalKeyConnected()==False): self.printC("[Alert :] Physical key not connected closing the call") self.ConnectionStatus = "Disconnect" break PacketDetails.Details() sleep(0.05) #print("*") self.printC( "You picked up phone..") if (self.ConnectionStatus != "Disconnect"): self.printC("The client " + str(self.Hearing.callerIP[0]) + " has just connected..") self.Talking.ConnectTo(self.Hearing.callerIP[0], PortNumber) self.Talking.clearBuffer() self.Hearing.ONReceptionToSpeakers = True if(enableVideoCalling): self.VideoSender.ConnectTo(self.Hearing.callerIP[0], VideoPortNo) self.ConnectionStatus = 'Talking' else: self.printC("Idle. Make sure physical key is attached to the system") self.WaitTillCallisDisconnected() self.Disconnect() sleep(4) self.ConnectionStatus = 'idle' self.CallersIP = None if(self.ConnectionStatus == 'Conference'): self.printC("Hold on for participants to join") while (self.Hearing.callerIP is None): #print ".", if(self.Run == False): return if (self.ConnectionStatus == "Disconnect"): break if(self.IsPhysicalKeyConnected()==False): self.printC("[Alert :] Physical key not connected closing the call") self.ConnectionStatus = "Disconnect" break sleep(2) PacketDetails.Details() if (self.ConnectionStatus != "Disconnect"): self.printC("The client " + str(self.Hearing.callerIP[0]) + " has just connected.. Please start talking") self.Hearing.ONReceptionToSpeakers = True self.ConnectionStatus = 'Talking' self.WaitTillCallisDisconnected() else: self.printC("Idle") sleep(2) self.LeaveConference(MultiCastGrp, MuliCastPortNo) self.ConnectionStatus = 'idle. Make sure physical key is attached to the system' PacketDetails.Details() except KeyboardInterrupt: break def IsPhysicalKeyConnected(self): if(UsePhysicalKey ==False): return True self.device = usb.core.find(idVendor=0x16c0 ,idProduct=0x27db) if self.device is not None: return True else: return False def ConnectTo(self, IPAddress): if(self.ConnectionStatus == 'idle' or self.ConnectionStatus == 'pickup'): self.Talking.ConnectTo(IPAddress, PortNumber) self.ConnectionStatus = 'ConnectTo' self.printC("Making connection...") else: self.printC("[Alert :] Please hang up current call") def WaitTillCallisDisconnected(self): while (True): try: sleep(0.1) if (self.Talking.ConnectionEstablished == False) : self.printC("[Info :] You have closed the connection") break if(self.Hearing.ConnectionEstablished == False): self.printC("[Info :] The reciver has disconnected") break if(self.Run == False): break if (self.ConnectionStatus == 'Disconnect'): break if(self.IsPhysicalKeyConnected()==False): self.printC("[Alert :] Physical key not connected closing the call") break PacketDetails.Details() except KeyboardInterrupt: break def ConnectToConference(self, ConferenceIP, ConferencePortNo): if(self.ConnectionStatus == 'idle'): self.Talking.ConnectToMultiCastGroup(ConferenceIP, ConferencePortNo) self.Hearing.JointMulticastGroup(ConferenceIP, ConferencePortNo) self.ConnectionStatus = 'Conference' else: self.printC("[Alert :] Please hang up current call") def LeaveConference(self, ConferenceIP, ConferencePortNo): self.Hearing.LeaveMulticastGroup() self.Talking.LeaveMulticastGroup() def Disconnect(self): self.Talking.Disconnect() self.Hearing.Disconnect() if(enableVideoCalling): self.VideoSender.Disconnect() self.VideoReciver.Disconnect() def CloseTerminal(self): self.Run = False self.Disconnect() self.join() print("[Info :] Phone terminal is shutdown") self.Talking.ShutDownComplete() self.Hearing.ShutDownComplete() def sine_tone(self, frequency, duration, volume=1, sample_rate=48000):#22050): n_samples = int(sample_rate * duration) restframes = n_samples % sample_rate s = lambda t: volume * math.sin(2 * math.pi * frequency * t / sample_rate) samples = (int(s(t) * 0x7f + 0x80) for t in xrange(n_samples)) for buf in izip(*[samples]*sample_rate): # write several samples at a time self.Hearing.returnBytes(bytes(bytearray(buf))) # fill remainder of frameset with silence self.Hearing.returnBytes(b'\x80' * restframes)