Exemplo n.º 1
0
def Reset(Con):
    Con.flush();
    Con.write("ATZ\r\n");
    readline.read(Con,"\r\n");
    readline.read(Con,"\r\n");
    if readline.read(Con,"\r\n") == 'OK': return(Con.flush());
    raise pyDCPU.ModuleError("Unable to reset mobile-phone.");
Exemplo n.º 2
0
def SendSMS(Con, Dest, Msg):
    logger = logging.getLogger("pyDCPU");
    sms = GSMSMS.PDUSMS(Dest,Msg);
    data = sms.SMSToHex();

    if not data: raise Exception("No data given to send!");
    logger.debug("SMSPDU(hex): %s"%data);
    Con.write("AT+CMGS=%i\r%s\x1A"%(int(len(data)/2),data));
    logger.debug("SMS \"%s\" send..."%Msg);
    readline.read(Con,"\r\n"); #get echo
    readline.read(Con,"\r\n");
    tmp = readline.read(Con,"\r\n");
    logger.debug("Phone returned: %s"%str(tmp));
    if not 0 == tmp.find('+CMGS:'):
        raise Exception("Error while send sms \"%s\" to %s."%(tmp,Dest));
    return(True);
Exemplo n.º 3
0
def GetModel(Con):
    Con.write('AT+CGMM\r\n');
    readline.read(Con,"\r\n");      # get echo
    s = readline.read(Con,"\r\n");
    if s == 'ERROR': raise pyDCPU.ModuleError("Mobilephone returned error.");
    readline.read(Con,"\r\n");      # get empty line;
    if not readline.read(Con,"\r\n") == 'OK':
        raise pyDCPU.ModuleError("Mobile-phone returned ERROR.");
    return(s);
Exemplo n.º 4
0
def GetManufacturer(Con):
    Con.write('AT+CGMI\r\n');
    readline.read(Con,"\r\n");      # get echo
    s = readline.read(Con,"\r\n");
    if s == 'ERROR': raise pyDCPU.ModuleError("Mobile-phone returned error!");
    readline.read(Con,"\r\n");      # read empty line
    if not readline.read(Con,"\r\n") == 'OK':
        raise pyDCPU.ModuleError("Mobile-phone returned error!");
    return(s);
Exemplo n.º 5
0
def GetBattery(Con):
    Con.write('AT+CBC\r\n');
    readline.read(Con,"\r\n");      # get echo
    tmp = readline.read(Con,"\r\n");
    if tmp == 'ERROR': raise pyDCPU.ModuleError("Mobile-phone returned error.");
    readline.read(Con,"\r\n");      # read empty line
    if not readline.read(Con,"\r\n") == 'OK':
        raise pyDCPU.ModuleError("Mobile-phone returned error");
    tq = tmp.split(' ')[1];
    q = tq.split(',')[1];
    return(q);
Exemplo n.º 6
0
def GetNetwork(Con):
    Con.write('AT+CREG?\r\n');
    readline.read(Con,"\r\n");      # get echo
    tmp = readline.read(Con,"\r\n");
    if tmp == 'ERROR': raise pyDCPU.ModuleError("MobilePhone returned error!");
    readline.read(Con,"\r\n");      # read empty line;
    if not readline.read(Con,"\r\n") == 'OK':
        raise pyDCPU.ModuleError("Mobile phone returned error.");
    tq = tmp.split(' ');
    if len(tq)>1: q = tq[1].split(',');
    else: raise pyDCPU.ModuleError("Mobilephone returned mad format!");
    return(q);
Exemplo n.º 7
0
def GetServiceCenter(Con):
    Con.flush();
    Con.write('AT+CSCA?\r\n');
    readline.read(Con,"\r\n");          # get echo ...
    tmp = readline.read(Con,"\r\n");
    if tmp == 'ERROR': raise pyDCPU.ModuleError("Mobile-phone returned ERROR.");
    readline.read(Con,"\r\n");          # read empty line
    if not readline.read(Con,"\r\n") == 'OK':
        raise pyDCPU.ModuleError("Mobile-phone returned ERROR.");
    if -1 == tmp.find('"'): raise pyDCPU.ModuleError("Mad format returned by mobile-phone!");
    sc = tmp.split('"')[1];
    return("\"%s\""%sc);