#!/usr/bin/python2 import pyaudio import socket from threading import Thread import sysv_ipc import sharedmem_utils import conf # SharedMemory segments to control the activity of the program. Stop when needed. convo_shm = sysv_ipc.SharedMemory(sharedmem_utils.key_convo); convostatus = sharedmem_utils.read_from_memory(convo_shm); frames = [] # Receive UDP data and add them to frames # If compression was used, decrypt it here before adding to frames def udpStream(CHUNK): global frames; global convo_shm global convostatus udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) udp.bind((conf.localhost, conf.commport)) while convostatus != 'stop': soundData, addr = udp.recvfrom(CHUNK * CHANNELS * 2) frames.append(soundData) convostatus = sharedmem_utils.read_from_memory(convo_shm); udp.close()
offhookparams = urllib.urlencode({'device_id': conf.device_id, 'hookstatus': 'offhook'}) onhookparams = urllib.urlencode({'device_id': conf.device_id, 'hookstatus': 'onhook'}) headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"} # SharedMemory segments offhook_shm = sysv_ipc.SharedMemory(sharedmem_utils.key_offhook); inccall_shm = sysv_ipc.SharedMemory(sharedmem_utils.key_inccall); tone_shm = sysv_ipc.SharedMemory(sharedmem_utils.key_tone); dtmf_shm = sysv_ipc.SharedMemory(sharedmem_utils.key_dtmf); convo_shm = sysv_ipc.SharedMemory(sharedmem_utils.key_convo); calls_shm = sysv_ipc.SharedMemory(sharedmem_utils.key_calls); endip_shm = sysv_ipc.SharedMemory(sharedmem_utils.key_endip); # SharedMemory Control. Statuses. # Some of these are not needed. offhookstatus = sharedmem_utils.read_from_memory(offhook_shm); inccallstatus = sharedmem_utils.read_from_memory(inccall_shm); tonestatus = sharedmem_utils.read_from_memory(tone_shm); dtmfstatus = sharedmem_utils.read_from_memory(dtmf_shm); callsstatus = sharedmem_utils.read_from_memory(calls_shm); endip = sharedmem_utils.read_from_memory(endip_shm); log.write("offhook has declared all variables\n"); log.write("offhook is entering loop\n"); offcount = 0 oncount = 0 phone_shm = sysv_ipc.SharedMemory(sharedmem_utils.key_phone);
# For SharedMemory import sysv_ipc # For Keys and functions for shared memory import sharedmem_utils # For Device and Server confs import conf # SharedMemory segments offhook_shm = sysv_ipc.SharedMemory(sharedmem_utils.key_offhook) endip_shm = sysv_ipc.SharedMemory(sharedmem_utils.key_endip) convo_shm = sysv_ipc.SharedMemory(sharedmem_utils.key_convo) # The values (statuses) in the shared memory segments endip = sharedmem_utils.read_from_memory(endip_shm) offhookstatus = sharedmem_utils.read_from_memory(offhook_shm) # Create a UDP socket that is non-blocking, waiting for the hangup message sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.bind((conf.localhost, conf.callport)) sock.setblocking(0) hangup = False # Wait for hangup, until hungup or phone is replaced on hook while hangup != True and offhookstatus != 'onhook': offhookstatus = sharedmem_utils.read_from_memory(offhook_shm) try: data, addr = sock.recvfrom(10) print "received message:", data
#!/usr/bin/python2 import sys import pyaudio import time import socket # For SharedMemory functions import sysv_ipc import sharedmem_utils import conf convo_shm = sysv_ipc.SharedMemory(sharedmem_utils.key_convo) endip_shm = sysv_ipc.SharedMemory(sharedmem_utils.key_endip) convostatus = sharedmem_utils.read_from_memory(convo_shm) endip = sharedmem_utils.read_from_memory(endip_shm) sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) CHUNK = 8192 FORMAT = pyaudio.paInt16 CHANNELS = 1 RATE = 44100 RECORD_SECONDS = 5 p = pyaudio.PyAudio() stream = p.open(format=FORMAT, channels=CHANNELS, rate=RATE, input=True,
#!/usr/bin/python2 ## TODO we can check for offhook status as condition for start and stop, instead of seperate state variables from time import sleep import os import httplib, urllib import socket # For shared memory import sysv_ipc # Keys and functions for shared memory import sharedmem_utils # Device and Server Confs import conf phone_shm = sysv_ipc.SharedMemory(sharedmem_utils.key_phone) phone_status = sharedmem_utils.read_from_memory(phone_shm) print "phone status was : ", phone_status sharedmem_utils.write_to_memory(phone_shm, "offhook") print "phone status is : ", "offhook"