Example #1
0
def wait_for_response(timeout=5.0):
    data = ''
    time_max = time.time() + timeout
    while not contains_any(data, 'OK\r', 'ERROR\r') and time.time() < time_max:
        byte = MDM.readbyte()
        if byte != -1:
            data += chr(byte)

    return 'OK\r' in data
Example #2
0
def send_CM(inSTR, connId, timeOut):

    ## TWH - 09/16/2009
    ## Need to determine to timeout for this command

    if len(inSTR) == 0:
        return 1

    try:

        res = MDM.send("AT#SSEND=" + str(connId) + "\r\n", 0)

        # Start timeout counter
        timerA = timers.timer(0)
        timerA.start(timeOut)

        prompt = "\r\n> "

        # Start looking for '\r\n>'
        while 1:

            properties.CMD_BUFFER = properties.CMD_BUFFER + MDM.receive(1)
            pos1 = properties.CMD_BUFFER.find(prompt)  # look for prompt characters
            if pos1 >= 0:
                properties.CMD_BUFFER = (
                    properties.CMD_BUFFER[0:pos1]
                    + properties.CMD_BUFFER[pos1 + len(prompt) : len(properties.CMD_BUFFER)]
                )
                res = MDM.send(inSTR, 0)
                res = MDM.sendbyte(0x1A, 0)

                res = ""
                tmpByte = -1
                while 1:
                    tmpByte = MDM.readbyte()
                    if tmpByte != -1:
                        res = res + tmpByte

                    if res.find("\r\nOK\r\n") >= 0:
                        return 0
                    if timerA.isexpired():
                        return -2

            if timerA.isexpired():
                return -2

    except:
        printException("send_CM()")

    return -3
Example #3
0
def read_registers(start_reg, n):
    SER2.send('reading: %02x %d\r\n' % (start_reg, n))
    MDM.send(
        'AT#I2CRD=%d,%d,%02x,%02x,%d\r' %
        (GPIO_SDA, GPIO_SCL, CODEC_ADDR, start_reg, n), 0)

    data = ''
    time_max = time.time() + 10.0
    while not contains_any(data, 'OK\r', 'ERROR\r') and time.time() < time_max:
        byte = MDM.readbyte()
        if byte != -1:
            data += chr(byte)

    data = data.lstrip()
    if data.startswith('#I2CRD: '):
        return data[8:data.index('\r')]

    return None
Example #4
0
def send_CM(inSTR,connId,timeOut):

    rtnList = [-1,-1]    #[return status,return data]
    # return status:
    #   -2:    Timeout occurred
    #   -1:    Exception occurred
    #    0:    No errors occurred, no return data
    #    1:    No errors occurred, return data

    if (len(inSTR) == 0):
        rtnList[0] = 0
        return rtnList

    try:

        #Define GPRS Settings, MUST change APN String in script for your Carrier Specific setting
        rtnList = ATC.sendAtCmd('AT#SSEND=' + str(connId),'\r\n> ',180)
        if (rtnList[0] == -1) or (rtnList[0] == -2) or rtnList[1] == "ERROR": return rtnList

        res = mySER.send(inSTR,10)
        res = mySER.sendbyte(0x1a,2)

        #Start timeout counter 
        start = time.time()   

        res = ''
        tmpByte = ''
        while True:
            tmpByte = mySER.readbyte()
            if tmpByte > -1:
                res += chr(tmpByte)

            if (res.find('\r\nOK\r\n')>=0):
                rtnList[0] = 0
                break
            if (time.time() - start) > timeOut:
                rtnList[0] = -2
                break

    except:
        print sys.exc_info()
        rtnList[0] = -1

    return rtnList
Example #5
0
def send_CM(inSTR,connId,timeOut):

    if (len(inSTR)==0):
        return 1

    try:

        res = MDM.send('AT#SSEND=' + str(connId) + '\r\n', 0)

        #Start timeout counter        
        timerA = timers.timer(0)
        timerA.start(timeOut)

        prompt = '\r\n> '

        #Start looking for '\r\n>'
        while(1):

            properties.CMD_BUFFER = properties.CMD_BUFFER + MDM.receive(1)      
            pos1 = properties.CMD_BUFFER.find(prompt)   #look for prompt characters
            if (pos1>=0):
                properties.CMD_BUFFER = properties.CMD_BUFFER[0:pos1] + properties.CMD_BUFFER[pos1+len(prompt):len(properties.CMD_BUFFER)]
                res = MDM.send(inSTR, 0)
                res = MDM.sendbyte(0x1a, 0)       

                res = ''
                tmpByte = -1
                while(1):
                    tmpByte = MDM.readbyte()
                    if (tmpByte != -1):
                        res = res + tmpByte

                    if (res.find('\r\nOK\r\n')>=0):
                        return 0
                    if timerA.isexpired():
                        return -2

            if timerA.isexpired():
                return -2

    except:
        printException("send_CM(" + inSTR + "," + connId + "," + timeOut + ")")

    return -3
Example #6
0
def main():
    if config_codec():
        SER2.send('Codec configured\r\n')
    else:
        SER2.send('Cannot configure the codec\r\n')

    data = ''
    while True:
        byte = MDM.readbyte()
        if byte == -1:
            time.sleep(0.1)
            continue

        data += chr(byte)
        if not '\r' in data:
            time.sleep(0.1)
            continue

        line, data = data.split('\r', 2)
        if 'RING' in line:
            SER2.send('ring!!!\r\n')
            accept_call()
        else:
            SER2.send(line + '\r\n')