Exemplo n.º 1
0
def initGPS (speed,format):
    
    # Method return value:
    #   -6 = Unknown error
    #   -5 = Incorrect NMEA command response
    #   -4 = No NMEA Command response
    #   -3 = NMEA Command response Checksum fail
    #   -1 = Exception occurred
    #    0 = Finished w/o error
    #   >0 = NMEA Command response error value

    tmpReturn = -1

    try:

        #Init Serial Port Settings
        res = SER2.set_speed(speed,format)
        if not(res == 1):
            return -6

        #Clear NMEA Buffer
        GPSdata.NMEA = SER2.read()
        GPSdata.NMEA = ''

        res = pollNMEA('8',2)
        tmpReturn = res

    except:
        printException("initGPS()")
        tmpReturn = -1
        
    return tmpReturn
Exemplo n.º 2
0
def write_registers(start_reg, *data):
    SER2.send('writing: %02x %r\r\n' % (start_reg, data))

    MDM.send(
        'AT#I2CWR=%d,%d,%02x,%02x,%d\r' %
        (GPIO_SDA, GPIO_SCL, CODEC_ADDR, start_reg, len(data)), 0)
    MDM.send(''.join(hex(x)[2:].zfill(2) for x in data), 0)
    MDM.sendbyte(0x1a, 0)

    return wait_for_response()
Exemplo n.º 3
0
def send(cmd, type, data):
    """Отправить команду для процессора

    Args:
        cmd: Команда
        type: Операция
        data: Данные
    """
    req = pack(cmd, type, data)
    SER2.send(req)
Exemplo n.º 4
0
def send(cmd, type, data):
    """Отправить команду для процессора

    Args:
        cmd: Команда
        type: Операция
        data: Данные
    """
    req = pack(cmd, type, data)
    SER2.send(req)
Exemplo n.º 5
0
def initIO():
    """Инициализация линий ввода-вывода
    """
    SER2.set_speed('115200')
    # 0 - input, 1 - output, 2 - alt
    GPIO.setIOdir(4, 0, 0) # SK1
    GPIO.setIOdir(3, 0, 0) # SK2
    GPIO.setIOdir(6, 0, 1) # RELE1
    GPIO.setIOdir(1, 0, 1) # RELE2
    GPIO.setIOdir(5, 0, 1) # SIM_SELECT
    GPIO.setIOdir(2, 0, 2) # JDR
Exemplo n.º 6
0
def initIO():
    """Инициализация линий ввода-вывода
    """
    SER2.set_speed('115200')
    # 0 - input, 1 - output, 2 - alt
    GPIO.setIOdir(4, 0, 0)  # SK1
    GPIO.setIOdir(3, 0, 0)  # SK2
    GPIO.setIOdir(6, 0, 1)  # RELE1
    GPIO.setIOdir(1, 0, 1)  # RELE2
    GPIO.setIOdir(5, 0, 1)  # SIM_SELECT
    GPIO.setIOdir(2, 0, 2)  # JDR
Exemplo n.º 7
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
Exemplo n.º 8
0
def sendNmeaCmd (inSTR1, inSTR2):

    # Method return value:
    #   -5 = Incorrect NMEA command response
    #   -4 = No NMEA Command response
    #   -3 = NMEA Command response Checksum fail
    #   -1 = Exception occurred
    #    0 = Finished w/o error
    #   >0 = NMEA Command response error value

    # inSTR1 = MS20 NMEA command
    # inSTR2 = MS20 NMEA command data

    tmpReturn = -1

    try:

        #Build NMEA command
        #Calculate NMEA checksum
        y = inSTR1 + inSTR2
        x = calcChecksum (y[1:len(y)])
        #Format NMEA sentence
        y = y + '*' + x + '\r\n'

        #Send NMEA command
        res = SER2.send(y)      

        #Evaluate NMEA command response
        res = getNextSentence(inSTR1, 2)

        print 'NMEA Command Sent: ' + y
        if not(res == 0):
            print 'NMEA Command failed!'
            print '  Return Code: ' + str(res)
            # pass return code back to calling method
            tmpReturn = res
        else:

            tmpReturn = 0

    except:
        printException("sendNmeaCmd()")
        tmpReturn = -1

    return tmpReturn
Exemplo n.º 9
0
def receive(timeout=2):
    """Получить ответ от процессора

    Args:
        timeout: Время ожидания ответа в сек
    Returns:
        Сырые принятые данные
    """
    data = ''
    timer = MOD.secCounter() + timeout
    while (1):
        rcv = SER2.read()
        if (len(rcv) > 0):
            data = data + rcv
            if (data.endswith('\r') or data.endswith('\n')):
                return data
        if (MOD.secCounter() > timer):
            return ''
Exemplo n.º 10
0
def receive(timeout = 2):
    """Получить ответ от процессора

    Args:
        timeout: Время ожидания ответа в сек
    Returns:
        Сырые принятые данные
    """
    data = ''
    timer = MOD.secCounter() + timeout
    while(1):
        rcv = SER2.read()
        if(len(rcv) > 0):
            data = data + rcv
            if(data.endswith('\r') or data.endswith('\n')):
                return data
        if(MOD.secCounter() > timer):
            return ''
Exemplo n.º 11
0
def getNMEA ():
    
    # Method return value:
    #   -1 = Exception occurred
    #    0 = Finished w/o error

    tmpReturn = -1

    try:

        #Build NMEA buffer
        GPSdata.NMEA = GPSdata.NMEA + SER2.read()

        tmpReturn = 0       

    except:
        printException("getNMEA()")
        tmpReturn = -1
        
    return tmpReturn
Exemplo n.º 12
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')
Exemplo n.º 13
0
import SER2
SER2.send('test')
SER2.sendbyte(0x0d)
Exemplo n.º 14
0
import time
import USB0
import SER
import SER2

SER.set_speed('115200', '8N1')
SER2.set_speed('115200', '8N1')

i = 0
print('HOLA\n')
while i < 3:
    time.sleep(1)
    a = USB0.send('TEST\r\n')
    print('HOLA\n')
    b = SER.send('PAULO\n')
    c = SER2.send('BENITO\n')
    i = i + 1

SER.send('END of script\n')
SER2.send('END OF END\n')
Exemplo n.º 15
0
def resetWatchdog():
    gsm.sendAT("AT#ENHRST=1,10", "OK", 5)
    SER2.send('OK\r\n')
Exemplo n.º 16
0
            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')


SER2.set_speed('9600', '8N1')
SER2.send('Starting...\r\n')
try:
    main()
except BaseException, e:
    SER2.send(repr(e))

#
# SER2.set_speed('115200', '8N1')
#
# MDM.send('AT+CMEE=2\n', 0)
# while True:
#     MDM.send('AT+COPS=?\r', 0)
#     MDM.send('AT+CSQ\r', 0)
#     MDM.send('AT+CREG?\r', 0)
#     for line in MDM.read().split('\r\n'):
Exemplo n.º 17
0
                result = ''
                for c in commands:
                    result = result + executeCommand(c)
                sms.sendSms(sms_msg.SmsMessage('0', message.getNumber(), '', result))
                if(CFG.get('SMSDELETEALL') == '0'):
                    sms.deleteSms(message.getId())
        if(CFG.get('SMSDELETEALL') == '1'):
            sms.deleteSms(message.getId())

def resetWatchdog():
    gsm.sendAT("AT#ENHRST=1,10", "OK", 5)
    SER2.send('OK\r\n')

if __name__ == "__main__":
    try:
        SER2.set_speed('9600', '8N1')
        SER2.send('OK\r\n')
        CFG.read()
        print ('Start GSM init\r')
        gsm.init()
        print ('Start SMS init\r')
        sms.init()
        print ('IO init\r')
        initInputs()
        print ('Start main loop\r')
        while(1):
            resetWatchdog()
            smsProcessing()
            ioProcessing()
    except Exception, e:
        print ('Unhandled exception, reboot...\r')