예제 #1
0
# 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
        if data == "hangup" and str(addr) == endip:
            hangup = True
            sharedmem_utils.write_to_memory(convo_shm, 'stop')

    except socket.error:
        "do nothing"

sock.close()
예제 #2
0
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, "onhook")
print "phone status is  : ", "onhook"
"""
convo_shm = sysv_ipc.SharedMemory(sharedmem_utils.key_convo);

convostatus = sharedmem_utils.read_from_memory(convo_shm);
print "convostatus ", convostatus
sharedmem_utils.write_to_memory(convo_shm, 'stop');
convostatus = sharedmem_utils.read_from_memory(convo_shm);
print "convostatus ", convostatus
"""
예제 #3
0
log.write("offhook is entering loop\n");

offcount = 0
oncount = 0

while True:
	# Only perform the actions once, hence the offhookstatus
	if (GPIO.input(pins.OFFHOOK) == True):
                print "here"
                offcount += 1
                oncount = 0
                if (offhookstatus != 'offhook' and offcount > 1):
                        log.write("phone is now offhook\n");
                        print "phone is off hook";
                        # Phone has become off hook
                        sharedmem_utils.write_to_memory(offhook_shm, 'offhook');
                        offhookstatus = 'offhook';

                        # Notify the server that the phone has become off hook
                        conn = httplib.HTTPConnection(conf.server_ip)
                        conn.request("POST", conf.setoffhook_url, offhookparams, headers)
        		response = conn.getresponse()
                	print response.status, response.reason

                        # Stop checking for incoming calls.
                        # The status will be changed to wait, when dialing is complete
        		sharedmem_utils.write_to_memory(inccall_shm, 'stop');

                	callsstatus = sharedmem_utils.read_from_memory(calls_shm);
                        if(callsstatus != 'calling'):
                                log.write("ringing call, offhook, call pickup operation\n");
예제 #4
0
rsock.bind((conf.localhost, conf.callport))
rsock.setblocking(0)

log.write("declared all variables\n")
log.write("starting loop now\n")

while inccallstatus != 'stop':
    try:
        data, addr = rsock.recvfrom(10)
        if (data == 'calling'):
            log.write("incoming call" + str(addr) + "\n")
            # Ring the phone
            # sharedmem_utils.write_to_memory(ringphone_shm, 'start');
            # os.system(conf.path_ringphone);
            print "Address ", addr, " is calling"
            sharedmem_utils.write_to_memory(calls_shm, 'calling')
            sharedmem_utils.write_to_memory(endip_shm, addr[0])

        elif (data == 'cancel'):
            sharedmem_utils.write_to_memory(convo_shm, 'stop')
            sharedmem_utils.write_to_memory(calls_shm, 'nocalls')
            sharedmem_utils.write_to_memory(endip_shm, 'none')

    except socket.error:
        "do nothing"
    inccallstatus = sharedmem_utils.read_from_memory(inccall_shm)
    sleep(1)

log.write("sending ack\n")

# The phone is off hook at this point
#dtmfstatus = 'run';

log.write("started to check for DTMF. initialised sharedmem and pins")

# Check for DTMF until timeout or explicit stop

while int(time.time()) < timeout and dtmfstatus != 'stop':
    # On DTMF input, Interrupt pin will be high for a moment
    # At that moment, save the bit values.
    # If any digit was pressed, the ringing tone stops
    if (GPIO.input(pins.DTMF_INTR) == True):
        digits.append((GPIO.input(pins.DTMF_BIT0), GPIO.input(pins.DTMF_BIT1),
                       GPIO.input(pins.DTMF_BIT2), GPIO.input(pins.DTMF_BIT3)))

        timeout = int(time.time()) + 6
        sharedmem_utils.write_to_memory(tone_shm, 'stop')
        time.sleep(0.5)
    dtmfstatus = sharedmem_utils.read_from_memory(dtmf_shm)

print(digits)
log.write("digits were obtained as : " + str(digits))

if (dtmfstatus != 'stop'):
    # No number was dialed
    if (len(digits) == 0):
        log.write("no number was dialled")
        # Stop the Dial tone
        sharedmem_utils.write_to_memory(tone_shm, 'stop')
        time.sleep(0.5)
        # Play Timeout Tone
        sharedmem_utils.write_to_memory(tone_shm, 'run')
예제 #6
0
    inccall_shm = sysv_ipc.SharedMemory(sharedmem_utils.key_inccall)
try:
    calls_shm = sysv_ipc.SharedMemory(sharedmem_utils.key_calls,
                                      sysv_ipc.IPC_CREX)
except sysv_ipc.ExistentialError:
    calls_shm = sysv_ipc.SharedMemory(sharedmem_utils.key_calls)
try:
    ringphone_shm = sysv_ipc.SharedMemory(sharedmem_utils.key_ringphone,
                                          sysv_ipc.IPC_CREX)
except sysv_ipc.ExistentialError:
    ringphone_shm = sysv_ipc.SharedMemory(sharedmem_utils.key_ringphone)
try:
    phone_shm = sysv_ipc.SharedMemory(sharedmem_utils.key_phone,
                                      sysv_ipc.IPC_CREX)
except sysv_ipc.ExistentialError:
    phone_shm = sysv_ipc.SharedMemory(sharedmem_utils.key_phone)

# Initialize the Shared Memory to specific values
sharedmem_utils.write_to_memory(tone_shm, 'stop')
sharedmem_utils.write_to_memory(offhook_shm, 'onhook')
sharedmem_utils.write_to_memory(endip_shm, '')
sharedmem_utils.write_to_memory(convo_shm, 'stop')
sharedmem_utils.write_to_memory(dtmf_shm, 'stop')
sharedmem_utils.write_to_memory(inccall_shm, 'start')
sharedmem_utils.write_to_memory(calls_shm, 'nocalls')
sharedmem_utils.write_to_memory(ringphone_shm, 'stop')
sharedmem_utils.write_to_memory(phone_shm, 'onhook')

# Start the Off Hook detection program, and the Incoming Call Handler Program
#os.system(defaults.path_inccall);
예제 #7
0
rsock.bind((conf.localhost, conf.callport))
rsock.setblocking(0)

log.write("declared all variables\n")
log.write("starting loop now\n")

while inccallstatus != 'stop':
    try:
        data, addr = rsock.recvfrom(10)
        if (data == 'calling'):
            log.write("incoming call" + str(addr) + "\n")
            # Ring the phone
            # sharedmem_utils.write_to_memory(ringphone_shm, 'start');
            # os.system(conf.path_ringphone);
            print "Address ", addr, " is calling"
            sharedmem_utils.write_to_memory(calls_shm, 'calling')
            sharedmem_utils.write_to_memory(endip_shm, addr)

        elif (data == 'hangup'):
            sharedmem_utils.write_to_memory(convo_shm, 'stop')
    except socket.error:
        "do nothing"
    inccallstatus = sharedmem_utils.read_from_memory(inccall_shm)
    sleep(1)

log.write("sending ack\n")

# The phone is off hook at this point
# Stop ringing the phone
#sharedmem_utils.write_to_memory(ringphone_shm, 'stop');