Пример #1
0
def send(cmd, type, data):
    """Отправить команду для процессора

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

    Args:
        cmd: Команда
        type: Операция
        data: Данные
    """
    req = pack(cmd, type, data)
    SER2.send(req)
Пример #3
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()
Пример #4
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
Пример #5
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
Пример #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')
Пример #7
0
import SER2
SER2.send('test')
SER2.sendbyte(0x0d)
Пример #8
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')
Пример #9
0
        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'):
#         if line and line != 'OK':
Пример #10
0
def resetWatchdog():
    gsm.sendAT("AT#ENHRST=1,10", "OK", 5)
    SER2.send('OK\r\n')
Пример #11
0
                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')
        gsm.reboot()