コード例 #1
0
def sendData(PIN,PO,HO,A,GU,GP,data,ll):
    b = SER.send('\r\nIn sendData...sending\r\n' + data + '\r\n')
    b = SER.send('\r\nHO=\r\n')
    b = SER.send(HO)
    b = SER.send('\r\npO=\r\n')
    b = SER.send(PO)
    b = SER.send('\r\n')
    a = openGPRS(PIN,A,GU,GP)
    a = openSD(HO)
    res = MDM2.send('POST /' + PO + ' HTTP/1.1 Connection: close\r\n', 0)
    res = MDM2.send('HOST: ' + HO + '\r\n', 0)
    res = MDM2.send('User-Agent: Terminal Connect\r\n', 0)
    res = MDM2.send('Content-Type: application/x-www-form-urlencoded\r\n', 0)
    res = MDM2.send('Content-Length: '+ str(ll) +'\r\n\r\n', 0)
    res = MDM2.send(data, 0)
    res = MDM2.send('\r\n\r\n', 0)
    cnt = 20
    res = MDM2.receive(20)
    a = SER.send('\r\nResponse from server ------------------------\r\n')
    while ( (res.find('EOT') == -1) and (cnt > 0) ):
        a = SER.send(res)
        res = MDM2.receive(20)
        cnt = cnt - 1
    a = SER.send(res)
    res = closeCon()
    a = SER.send('\r\nend -----------------------------------------\r\n')
    return res
コード例 #2
0
def checkCon(pin):
    a = SER.send('DEBUG: Now in checkCon...\r\n')
    #print '\r\ncheckCon PIN:',pin
    res = MDM2.send('AT+CREG?\r',0)
    res = MDM2.receive(30)
    b = SER.send('DEBUG: following is result from AT+CREG?\r\n')
    c = SER.send(res);
    if ( (res.find('0,1') > -1)  or (res.find('0,5')  > -1 ) ):
        return 1

    ret = ''
    ret = setPin(pin)
    if ( ret != 1 ):
        GPIO.setIOdir(19,1,1)
        return -1 

    timer = MOD.secCounter() + 120
    while ( (res.find('0,1') == -1)  and  (res.find('0,5')  == -1 ) ):
        res = MDM2.send('AT+CREG?\r',0)
        res = MDM2.receive(20)
        b = SER.send('DEBUG: following is result from AT+CREG?\r\n')
        c = SER.send(res);
        if ( MOD.secCounter() > timer ):
            return -1
        MOD.sleep(50)
    MOD.sleep(20)
    return 1 
コード例 #3
0
ファイル: Main.py プロジェクト: leongersen/afstuderen
def transmitMessage ( message ):

	# If the socket is not open, we'll dial.
	if Module.socketIsSuspended() == 0:

		SER.send('Dail socket, state is: %s\n' % Module.ATcommand('AT#SS=1'))

		if Module.socketDail( Config.API ) == 0:
			SER.send('Failed to open a socket\n')
			return 0

	elif Module.socketResume() == 0:
		SER.send('Failed socket resume\n')

	response = Module.makeRequest(URL, ('[%s]' % message))

	if ( response == 0 ):
		SER.send('Request failed\n')
	else:
		updateSettings(response)

	if ( Module.sendEscapeSequence() == 0 ):
		SER.send('Failed to escape, not in command mode\n')

	return 0
コード例 #4
0
ファイル: SBMMain.py プロジェクト: pkondalu/telit-code
def WriteUploadDataToFile():
	PrintDebug("Writting Data to File")
	InfileHandler = -1
	GlobalVaria.sbmInFileLength1 = 0
	GlobalVaria.SBMBuffer = GlobalVaria.SBMBuffer[2:-1]
	GlobalVaria.SBMBuffer = GlobalVaria.SBMBuffer + '\0'
	GlobalVaria.sbmInFileLength1 = FileSize(GlobalVaria.SBM_DATA_INFILE1)
	if(GlobalVaria.sbmInFileLength1 > 49000):
		if((FileCheck(GlobalVaria.SBM_DATA_INFILE2)== -1) and (FileCheck(GlobalVaria.SBM_DATA_OUTFILE)== 1)):
			rename(GlobalVaria.SBM_DATA_INFILE1,GlobalVaria.SBM_DATA_INFILE2)
			GlobalVaria.sbmInFileLength1 = 0
			GlobalVaria.sbmInFileLength2 = FileSize(GlobalVaria.SBM_DATA_INFILE2)
		else:
			GlobalVaria.InFileLenExceededflag = '1';
			SER.send('\0x02')
			return
	try:
		InfileHandler = open(GlobalVaria.SBM_DATA_INFILE1,'a')
	except IOError:
		SER.send('\x03')
		return 0
	InfileHandler.write(GlobalVaria.SBMBuffer)
	writeedlen = len(GlobalVaria.SBMBuffer)
	GlobalVaria.sbmInFileLength1 = FileSize(GlobalVaria.SBM_DATA_INFILE1)
	GlobalVaria.sbmInFileLength2 = 0
	InfileHandler.close()
	InfileHandler = -1
	PrintDebug("Writting Complated")
コード例 #5
0
ファイル: SBMMain.py プロジェクト: pkondalu/telit-code
def ProcessSBMCommand():
	while(1):
		PrintDebug("SBS Command Process")
		#PrintDebug("Waiting for command")
		# COMMAND_START = 0
		# COMMAND_END = 1
		#if(len(GlobalVaria.UartData) > DATA_LEN):
		#PrintDebug("Data is more than the defined limit")
		#PrintDebug("Wiating on seriel port")
		GlobalVaria.UartData = GlobalVaria.UartData + SER.read()
		PrintDebug(GlobalVaria.UartData)
		startIndex = GlobalVaria.UartData.find('\x02')
		endIndex = GlobalVaria.UartData.find('\x03')
		PrintDebug("Start Index:" + str(startIndex))
		PrintDebug("end Index:" + str(endIndex))
		if(startIndex != -1 and  endIndex!= -1):
			GlobalVaria.SBMBuffer = GlobalVaria.UartData[startIndex:endIndex+1]
			PrintDebug("Command: " + GlobalVaria.SBMBuffer)
			SER.send('\x02')
			FindSbmCmnd(GlobalVaria.SBMBuffer[1])
			GlobalVaria.UartData = GlobalVaria.UartData[endIndex+1:]
			PrintDebug("Remaining:" + GlobalVaria.UartData)
		else:
			SER.send('\0x03')
			break
コード例 #6
0
ファイル: main.py プロジェクト: teleofis/Locker
def calendarProcessing():
    global CALENDAR
    if(CALENDAR > (int(CFG.get('ALIVESMS')) - 1)):
        calendar.writeCalendar(0)
        CALENDAR = 0
        SER.send('Send heartbeat SMS\r')
        sendAlert('Device is alive.')
コード例 #7
0
def transmitMessage(message):

    # If the socket is not open, we'll dial.
    if Module.socketIsSuspended() == 0:

        SER.send('Dail socket, state is: %s\n' % Module.ATcommand('AT#SS=1'))

        if Module.socketDail(Config.API) == 0:
            SER.send('Failed to open a socket\n')
            return 0

    elif Module.socketResume() == 0:
        SER.send('Failed socket resume\n')

    response = Module.makeRequest(URL, ('[%s]' % message))

    if (response == 0):
        SER.send('Request failed\n')
    else:
        updateSettings(response)

    if (Module.sendEscapeSequence() == 0):
        SER.send('Failed to escape, not in command mode\n')

    return 0
コード例 #8
0
def getGPSLocation(type):
    gpsStatus = GPS.getPowerOnOff()
    if gpsStatus == 0:
        GPS.powerOnOff(1)

    gpsStatus = GPS.getPowerOnOff()
    while gpsStatus == 0:
        gpsStatus = GPS.getPowerOnOff()

    GPSResult = GPS.getPosition()
    SER.send(str(GPSResult) + '\r\n')

    Latitude = str(GPSResult).split(',')[0].replace('(', '')
    Latitude = Latitude[0:len(Latitude) - 7] + '.' + Latitude[len(Latitude) -
                                                              7:len(Latitude)]

    Longitude = str(GPSResult).split(',')[2].replace(')', '')
    Longitude = Longitude[0:len(Longitude) -
                          7] + '.' + Longitude[len(Longitude) -
                                               7:len(Longitude)]

    if type == 'Lat':
        GPSResult = Latitude
    elif type == 'Lon':
        GPSResult = Longitude

    return GPSResult
コード例 #9
0
 def __sendRS485Send(self, len, val, crc=0, timeout=1):
     try:
         cmd = 'AT+RS485=SEND,{},{},{}\r'.format(len, val, crc)
         SER.send(cmd, 0)
         res = self.__SER_receive(timeout)
         return self.__parseRS485Send(res)
     except Exception as e:
         if self.__usb_log: USB0.send('FATAL ERROR: {}\r\n'.format(e))
コード例 #10
0
 def __sendRS485Count(self, timeout=1):
     try:
         cmd = 'AT+RS485=COUNT\r'
         SER.send(cmd, 0)
         res = self.__SER_receive(timeout)
         return self.__parseRS485Count(res)
     except Exception as e:
         if self.__usb_log: USB0.send('FATAL ERROR: {}\r\n'.format(e))
コード例 #11
0
 def __sendRS485Flush(self, size=6000, timeout=1):
     try:
         cmd = 'AT+RS485=FLUSH,{}\r'.format(size)
         SER.send(cmd, 0)
         res = self.__SER_receive(timeout)
         return self.__parseRS485Flush(res)
     except Exception as e:
         if self.__usb_log: USB0.send('FATAL ERROR: {}\r\n'.format(e))
コード例 #12
0
 def send(self, msg):
     message = str(MOD.secCounter()) + ' # ' + msg + '\r\n'
     max_len = int(self.config.get('TCP_MAX_LENGTH'))
     print message
     if (self.config.get('DEBUG_SER') == '1'):
         SER.send(message)
     if (self.config.get('DEBUG_TCP') == '1'):
         if ((len(self.tcpLogBuffer) + len(message)) < max_len):
             self.tcpLogBuffer = self.tcpLogBuffer + message
コード例 #13
0
ファイル: debug.py プロジェクト: AnaCaffe/wrx100_old
 def send(self, msg):
     message = str(MOD.secCounter()) + ' # ' + msg + '\r\n'
     max_len = int(self.config.get('TCP_MAX_LENGTH'))
     print message
     if (self.config.get('DEBUG_SER') == '1'):
         SER.send(message)
     if (self.config.get('DEBUG_TCP') == '1'):
         if((len(self.tcpLogBuffer) + len(message)) < max_len):
             self.tcpLogBuffer = self.tcpLogBuffer + message
コード例 #14
0
ファイル: main.py プロジェクト: teleofis/Locker
def ringProcessing():
    ring = gsm.checkRing()
    if(ring != ''):
        SER.send('Ringing with number: %s\r' % (ring))
        if(ring in CFG.getList('WHITE')):
            executeCommand(command.Command('OUT1', '1'))
        else:
            SER.send('Phone is not in Whitelist\r')
#         MOD.sleep(40)
        gsm.hangUp()
コード例 #15
0
ファイル: logger.py プロジェクト: jgrahamc/gaga
def log(m):
    t = util.timestamp()
    d = '%s: %s\r' % (t, m)
    SER.send(d)
    try:
        f = open( log_file, 'a' )
        f.write(d)
        f.close()
    except:
        return
コード例 #16
0
ファイル: logger.py プロジェクト: wal99d/gaga
def log(m):
    t = util.timestamp()
    d = '%s: %s\r' % (t, m)
    SER.send(d)
    try:
        f = open(log_file, 'a')
        f.write(d)
        f.close()
    except:
        return
コード例 #17
0
ファイル: 3004conSMSATRUN.py プロジェクト: jamusategui/zjj
def enviarAT(comando,timeout,respuesta_esp):
 comando_aux=comando
 comando_aux=comando_aux.replace('\n',"(N)")
 comando_aux=comando_aux.replace('\r',"(R)")
 global debug
 if (debug==1):
  SER.send("\r\nout:"+comando_aux)
 res_envio=MDM.send(comando,20)
 res_envio=MDM.send('\r\n',20)
 respuesta=RecibirDesdeModem(timeout,respuesta_esp)
 return respuesta
コード例 #18
0
ファイル: RHandler.py プロジェクト: MrZANE42/car-tracker
def iterateHTTPCmd(comando, parametro, TIMEOUT_CMD, numCheck):
    while( numCheck >= 0):
        numCheck = numCheck - 1
        res  = Helper.sendCmd(comando, parametro, TIMEOUT_CMD)
        SER.send(res + ' ' + comando + '=' + parametro)
        if(res.find('CONNECT') != -1) :
            return 1
        MOD.sleep(TIMEOUT_CMD)
        if(numCheck == 0):
            SER.send(res + ' ' + comando + '=' + parametro)
            return -1
コード例 #19
0
def iterateCmd(comando, parametro, TIMEOUT_CMD, numCheck):
    while (numCheck >= 0):
        numCheck = numCheck - 1
        res = sendCmd(comando, parametro, TIMEOUT_CMD)
        SER.send(res + ' ' + comando + '=' + parametro)
        if (res.find('OK') != -1):
            return 1
        MOD.sleep(TIMEOUT_CMD)
        if (numCheck == 0):
            SER.send(res + ' ' + comando + '=' + parametro)
            return -1
コード例 #20
0
 def set_led(self, color, state, intensity, timeout=1):
     try:
         cmd = 'AT+LED={},{},{}\r'.format(color, state, intensity)
         SER.send(cmd, 0)
         res = self.__SER_receive(timeout)
         if res.find('OK') != -1:
             return (1, )
         else:
             return (0, )
     except Exception as e:
         if self.__usb_log:
             USB0.send('FATAL ERROR: set_led(): {}\r\n'.format(e))
コード例 #21
0
def lastIndexOf(data, text):
    Temp = data.find(text)

    SER.send(str(Temp) + '\r\n')

    while Temp != -1:
        Index = Temp
        Temp = data.find(text, Temp + len(text))

        SER.send('Index = ' + str(Index) + ', Temp = ' + str(Temp) + '\r\n')

    return Index
コード例 #22
0
ファイル: RHandler.py プロジェクト: MrZANE42/car-tracker
def lastIndexOf(data,text) :
    Temp = data.find(text)
    
    SER.send(str(Temp)+'\r\n')
    
    while Temp != -1 :
        Index = Temp
        Temp = data.find(text,Temp + len(text))
        
        SER.send('Index = '+str(Index)+', Temp = '+str(Temp)+'\r\n')   
    
    return Index
コード例 #23
0
ファイル: Chronos.py プロジェクト: gabrielventosa/avl_so
def check_LockFlag():
	#unlocked returns 1
	res = SER.receive(15)
	res = SER.send('GET_LOCK_FLAG\r')
	res = SER.receive(15)

	if(res.find('UNLOCKED' != -1)):
		res = 1
	# locked returns 0
	else:
		res = 0
	return res
コード例 #24
0
ファイル: Main.py プロジェクト: leongersen/afstuderen
def initNetworkRelated ( ):

	# Unlock SIM card by entering PIN;
	Module.unlockSIM()
	SER.send('Done unlockSIM\n')

	if ( Module.attachNetwork( 20 ) == 0 ):
		SER.send('Failed attachNetwork\n')
	SER.send('Done attachNetwork\n')

	if ( Module.connectNetwork( Config.APN ) == 0 ):
		SER.send('Failed connectNetwork\n')
	SER.send('Done connectNetwork\n')
コード例 #25
0
ファイル: main.py プロジェクト: edhana/PythonLaptimer
def init():
    try:
        # Init the module configuration
        command.send_at_command("AT#SELINT=2")
        
        # Set the command mode       
        command.send_at_command("AT&K0")
        
        # Configure GPS speed
        # command.send_at_command("AT$GPSS=57600")
        
    except Exception, err:
        SER.send("Erro ao iniciar o modulo: %s\n"%err)
コード例 #26
0
def initNetworkRelated():

    # Unlock SIM card by entering PIN;
    Module.unlockSIM()
    SER.send('Done unlockSIM\n')

    if (Module.attachNetwork(20) == 0):
        SER.send('Failed attachNetwork\n')
    SER.send('Done attachNetwork\n')

    if (Module.connectNetwork(Config.APN) == 0):
        SER.send('Failed connectNetwork\n')
    SER.send('Done connectNetwork\n')
コード例 #27
0
ファイル: Chronos.py プロジェクト: gabrielventosa/avl_so
def check_PannicFlag():
	res = SER.receive(15)
	res = SER.send('GET_PANNIC_STATUS\r')
	res = SER.receivebyte(20)

	if(res == 97):
		print 
		#nopannic returns 1
		res = 1
	#pannic returns 0
	else:	
		res = 0
	return res
コード例 #28
0
ファイル: SBMMain.py プロジェクト: pkondalu/telit-code
def GetHealthStatus():
	PrintDebug("GetHealthStatus")
	length = 99999
	length = '%05d'%(length)
	StrLeng = '%.05s'%(str(length))
	if(GlobalVaria.simavailable == 0):
		GlobalVaria.SignalStrength = '00'
		GlobalVaria.SignalStrength = '%02s'%(GlobalVaria.SignalStrength)
		GlobalVaria.Gprs_Flag = 0
		GlobalVaria.HttpCon = 0
	GlobalVaria.SignalStrength = '%02s'%(GlobalVaria.SignalStrength)
	tempbuff = '@' + StrLeng + GlobalVaria.SignalStrength + str(GlobalVaria.simavailable) + str(GlobalVaria.Gprs_Flag) + str(GlobalVaria.HttpCon) +'T#' 
	if(len(tempbuff) != 0):
		SER.send("%s" %tempbuff)
コード例 #29
0
ファイル: main.py プロジェクト: teleofis/Locker
def rebootCounterProcessing(delta):
    global REBOOT_COUNTER
    global CALENDAR
    if((delta < 0) or (delta > 100)):
        delta = 5
    REBOOT_COUNTER = REBOOT_COUNTER + delta
    SER.send('Current reboot counter: %d\r' % REBOOT_COUNTER)
    if(REBOOT_COUNTER > int(CFG.get('REBOOTPERIOD'))):
        SER.send('Terminal reboot.\r')
        if(int(CFG.get('ALIVESMS')) > 0):
            CALENDAR = CALENDAR + 1
            calendar.writeCalendar(CALENDAR)
        MOD.sleep(30)
        gsm.reboot()
コード例 #30
0
 def __init__(self, settings):
     self.timer = MOD.secCounter()
     self.settings = settings
     self.settingsByKey = settingsByKey = self.settings.byKey
     SER.set_speed('300')
     #self.charmParsed = settingsByKey['charm']
     self.name = settingsByKey['name']
     self.i = settingsByKey['id']
     self.serverAddr = settingsByKey['serverAddr']
     self.maxLate = settingsByKey['maxlate']
     self.desc = settingsByKey['desc']
     self.charm = settingsByKey['charm']
     self.mainLoop = None
     print self.timer
     # Komendy odpowiedzialne za komunikacje internetową
     SER.setDSR(0)
     SER.setCTS(0)
     SER.setDCD(0)
     self.time = 0
     self.SMS = SMS(self)
     self.ipAddr = ""
     self.getTime()
     atstart = settingsByKey["atstart"]
     if len(atstart): sendATlist(atstart)
     self.maxSMSinMEM = settingsByKey["sms_limit"]
     MDM.send(self.m_init, 10)
     MDM.receive(20)
コード例 #31
0
def openSD(H):
    res = MDM2.send('AT#SD=1,0,80,' + H +',0\r', 0)
    timer = MOD.secCounter() + 30
    while (MOD.secCounter() < timer):
        res = MDM2.receive(10)
        a = SER.send('\r\nDEBUG: Back in openGPRS just did AT#SD=1,0,80....\r\n')
        a = SER.send(H)
        a = SER.send(res)
        if ((res.find('CONNECT') >= 0) ):
            timer = timer - 100
	    b = SER.send('\r\nsuccessfull connect, returning from openSD\r\n')
            return 1
        MOD.sleep(10)
    return -1
コード例 #32
0
def check4Updates(currFile, mode):
    UPDLIST = "updlist.txt"
    res = Helper.connectGPRS()
    if res != -1:
        data = transferFTP('GET', UPDLIST, 0, 0)

        if mode == 'Name':
            returnValue = parser(data, currFile, 'Name')
        else:
            returnValue = parser(data, currFile, 'Size')

        return returnValue
    else:
        SER.send('Error: connectGPRS returned -1\r\n')
        return -1
コード例 #33
0
ファイル: repl.py プロジェクト: kzar/telit-862-python-tools
def check_serial(f, buffer):
  # Wait for serial input
  data = SER.receive(1)
  if data:
    # Echo it
    SER.send(data)
    # Add it to the buffer
    buffer = buffer + data
    # If the message's done send it
    end_index = buffer.find('\r')
    if end_index > -1:
      message = buffer[:end_index + 1]
      buffer = buffer[end_index + 1:]
      f(message)
  return buffer
コード例 #34
0
ファイル: RHandler.py プロジェクト: MrZANE42/car-tracker
def check4Updates(currFile,mode):
	UPDLIST="updlist.txt"
	res = Helper.connectGPRS()
	if res != -1:
		data = transferFTP('GET',UPDLIST,0,0)
		
		if mode == 'Name':
			returnValue = parser(data,currFile,'Name')
		else:
			returnValue = parser(data,currFile,'Size')
		
		return returnValue
	else:
		SER.send('Error: connectGPRS returned -1\r\n')
		return -1
コード例 #35
0
ファイル: SER_HE910.py プロジェクト: JanusRC/Python
def readUART():
    # This function receives data from the DTE

    try:

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

        rtnList[1] = ''
        rtnList[1] = mySER.read()

        if (rtnList[1] == -1):
            return rtnList        
            
        rtnList[0] = 1  

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

    return rtnList
コード例 #36
0
ファイル: SER_HE910.py プロジェクト: JanusRC/Python
def sendUART(inSTR):
    # This function data out to the DTE

    try:

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

        rtnList[1] = ''
        rtnList[1] = mySER.send(str(inSTR))

        if (rtnList[1] == -1):
            return rtnList

        rtnList[0] = 0          

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

    return rtnList
コード例 #37
0
 def __init__(self, api=None, maxPS=512):
     self.api = api
     if api is MDM:
         self.isMDM = 1
         self.isSER = 0
         self.name = "MDM"
         self.send = lambda b: MDM.send(b, 1)
         self.alive = self.MDM_connection_alive
     else:
         self.isSER = 1
         self.isMDM = 0
         self.name = "SER"
         self.limit = 256
         self.alive = lambda: 1
         self.send = lambda b: SER.send(b)
     self.maxPS = maxPS
     self.baudSec = 0
     self.baud = None
     self.isMDM = 0
     self.baudId = "-1"
     self.b = ""
     self.ex = 0
     self.p = 0
     self.c = 0
     self.name = ""
     self.limit = 1024
     self.l = 0
     self.reset = 0
     self.nextInterface = None
コード例 #38
0
 def reset_wdg(self, timeout=1):
     '''Function resets STM32 watchdog timer
     
     :return (tuple):
     '''
     try:
         cmd = 'AT+WDG\r'
         SER.send(cmd, 0)
         res = self.__SER_receive(timeout)
         if res.find('OK') != -1:
             return (1, )
         else:
             return (0, )
     except Exception as e:
         if self.__usb_log:
             USB0.send('FATAL ERROR: reset_wdg(): {}\r\n'.format(e))
コード例 #39
0
 def open(self, speed, bt):
     if (self.lastSpeed != speed) or (self.lastBt != bt):
         rs = SER.set_speed(speed, bt)
         if rs == -1:
             raise Exception, 'Regular. port open failed'
         self.lastBt = bt
         self.lastSpeed = speed
コード例 #40
0
def parser(data, currFile, returnType):
    lastVersionIdx = lastIndexOf(data, 'UPD')

    if lastVersionIdx != -1:
        lastVersionName = data[lastVersionIdx:len(data)].split(',')[0]
        lastVersionSize = data[lastVersionIdx:len(data)].split(',')[1]

        SER.send('Last version name = ' + lastVersionName + '\r\n')
        SER.send('Last version size = ' + lastVersionSize + '\r\n')

        if returnType == 'Name':
            return lastVersionName
        else:
            return lastVersionSize

    else:
        return -1
コード例 #41
0
ファイル: RHandler.py プロジェクト: MrZANE42/car-tracker
def parser(data,currFile,returnType):
	lastVersionIdx = lastIndexOf(data,'UPD')
	
	if lastVersionIdx != -1 :
		lastVersionName = data[lastVersionIdx:len(data)].split(',')[0]
		lastVersionSize = data[lastVersionIdx:len(data)].split(',')[1]
		
		SER.send('Last version name = '+lastVersionName+'\r\n')
		SER.send('Last version size = '+lastVersionSize+'\r\n')
		
		if returnType == 'Name':
			return lastVersionName
		else:
			return lastVersionSize
			
	else :
		return -1
コード例 #42
0
ファイル: 3004conSMSATRUN.py プロジェクト: jamusategui/zjj
def RecibirDesdeModem(timeout,respuesta_esp):
 global debug
 data=""
 while 1:
  nueva_data=MDM.receive(timeout)
  data=data+nueva_data
  respuesta_aux=data
  respuesta_aux=respuesta_aux.replace('\n'," ")
  respuesta_aux=respuesta_aux.replace('\r'," ")
  if (len(nueva_data)==0):
   if (debug==1):
    SER.send("\r\nin (Timeout):"+respuesta_aux)
   return -1
  if (data.find(respuesta_esp)!=-1):
   if (debug==1):
    SER.send("\r\nin (OK):"+respuesta_aux)
   return 1
 return 0
コード例 #43
0
ファイル: repl.py プロジェクト: kzar/telit-862-python-tools
def repl():
  buffer = ''
  while 1:
    buffer = check_serial(lambda s: SER.send(s + '\r\n' +
                                             try_eval(s.strip()) +
                                             '\r\n > '),
                          buffer)
    if buffer.find('+++') > -1:
      break
コード例 #44
0
ファイル: DEBUG_CF.py プロジェクト: JanusRC/Python
def CLS(RUN_MODE):
# This function sends a VT100 Terminal Clear screen message to DB9 Serial Port 

    # Input Parameter Definitions
    #   RUN_MODE:
    #       (0) Don't send clear screen message
    #       (1) Send VT100 clear screen message via DB9 serial port "Script running in Telit module"
    
    try:

        if (RUN_MODE):
            SER.send("\033[2J\r")   #Clear screen
            SER.send("\033[H\r")   #Move cursor to home position        
            
    except:
        printException("CLS()")

    return
コード例 #45
0
 def __SER_receive(self, timeout):
     try:
         res = ''
         start = time.time()
         while (time.time() - start < timeout):
             res = res + SER.read()
         return res
     except Exception as e:
         USB0.send('FATAL ERROR: stm32.__SER_receive(): {}\r\n'.format(e))
コード例 #46
0
ファイル: SBMMain.py プロジェクト: pkondalu/telit-code
def SetRTC():
	PrintDebug("GetRTC")
	tempbuff = [0]* 30
	GlobalVaria.SBMBuffer = GlobalVaria.SBMBuffer[2:-1]
	GlobalVaria.SBMBuffer = GlobalVaria.SBMBuffer + '\0'
	GlobalVaria.DateTime['year'] = GlobalVaria.SBMBuffer[0:2]
	GlobalVaria.DateTime['month'] = GlobalVaria.SBMBuffer[2:4]
	GlobalVaria.DateTime['day'] = GlobalVaria.SBMBuffer[4:6]
	GlobalVaria.DateTime['hour'] = GlobalVaria.SBMBuffer[6:8]
	GlobalVaria.DateTime['min'] = GlobalVaria.SBMBuffer[8:10]
	GlobalVaria.DateTime['sec'] = GlobalVaria.SBMBuffer[10:12]
	tempbuff = "\"" + GlobalVaria.DateTime['day'] + "/"+GlobalVaria.DateTime['month'] + "/"+GlobalVaria.DateTime['year'] + ","+GlobalVaria.DateTime['hour'] + ":"+GlobalVaria.DateTime['min'] + ":"+GlobalVaria.DateTime['sec'] + "+" +"00" + "\""
	command = 'AT+CCLK=' + tempbuff + '\r'
	PrintDebug(command)
	result = ExecuteATCommand(command,"OK",1,120,2)
	if(result == 1):
		SER.send('\x02')
	else:
		SER.send('\x03')
コード例 #47
0
ファイル: 3004conSMSATRUN.py プロジェクト: jamusategui/zjj
def GetLineaDesdeSerial(timeout_seg):
 global debug
 data=""
 nueva_data=""
 nueva_linea=0
 timeout=MOD.secCounter()+timeout_seg
 if (debug==1):
  SER.send("\r\nin Esperando linea desde serial")
 while ((nueva_linea==0) and (MOD.secCounter())):
  nueva_data = SER.read()
  data=data+str(nueva_data)
  if ((data.find('\n')!=-1) or (data.find('\r')!=-1)):
   data=data.replace('\n'," ")
   data=data.replace('\r'," ")
   nueva_linea=1
   if (debug==1):
    SER.send("\r\nin Nueva linea obtenida")
   return data
 return data
コード例 #48
0
 def set_wdg(self, interval, timeout=1):
     '''Function sets internal STM32 watchdog
     
     :param interval (int): value in seconds from 30 to 64800 (18 hours). Value -1 or 0 turns off the watchdog.
     :param res_timeout (float): resposne timeout
     
     :return (tuple):
     '''
     try:
         cmd = 'AT+WDG=SET,{}\r'.format(interval)
         SER.send(cmd, 0)
         res = self.__SER_receive(timeout)
         if res.find('OK') != -1:
             return (1, )
         else:
             return (0, )
     except Exception as e:
         if self.__usb_log:
             USB0.send('FATAL ERROR: set_wdgt(): {}\r\n'.format(e))
コード例 #49
0
ファイル: DEBUG_CF.py プロジェクト: JanusRC/Python
def sendMsg(inSTR1, RUN_MODE):
# This function sends a debug message to print statement or DB9 Serial Port 

    # Input Parameter Definitions
    #   inSTR1: Debug Message
    #   RUN_MODE:
    #       (0) Send message via print statement "Script running in IDE"
    #       (1) Send message via DB9 serial port "Script running in Telit module"
    
    try:

        if (RUN_MODE):
            SER.send(inSTR1)
        else:
            print inSTR1
            
    except:
        printException("sendMsg()")

    return
コード例 #50
0
def setReadsector(line):
    SER.send('Setting readSector to: ')
    SER.send(line)
    SER.send('\n')

    settings = line.split(',')
    Storage.readSector = int(settings[1])
コード例 #51
0
def setup():
    initSettings()

    VOLT = Gauge.getBatteryVoltage()
    SER.send('Voltage: %s\n' % VOLT)

    # Don't start the network on a missing/near-empty battery
    if VOLT > 2500:
        initNetworkRelated()

    SER.send('Starting storage initialization at: %s\n' % MOD.secCounter())
    sector = Storage.initialize()
    SER.send('End at: %s. Sector: %s\n' % (MOD.secCounter(), sector))

    Module.CPUclock(0)  # Clock back to default (@26Mhz)
    SER.send('CPU back down\n')
コード例 #52
0
def enableAndReb(fileToExec, Number, MessageIndex):
    #deleteSMS(MessageIndex)
    SER.send('In Save file' + fileToExec + '\r\n')
    SER.send('After renaming file' + fileToExec + '\r\n')
    NUMBER = Number
    SMSText = "I'm going to reboot, enabling the following file: " + fileToExec
    SER.send("enableAndReb: trying to enable and reboot the module\r\n")
    fileName = '"' + fileToExec + '"'
    res = MDM.read()
    res = Helper.sendCmd('AT#ESCRIPT', fileName, 0)
    res = MDM.receive(30)

    if res.find('OK') != -1:
        MOD.sleep(200)
        text = "script qualified :" + fileName + '\r\n'
        SER.send(text + "\r\n")
        res = sendSMS(NUMBER, SMSText)
        MOD.sleep(200)
        res = MDM.send('AT#REBOOT\r', 0)
        MOD.sleep(200)
        SER.send('rebooting\r\n')
        return 1
    else:
        return -1
コード例 #53
0
 def receive(self, size):
     data = ''
     while (1):
         rcv = SER.read()
         if (len(rcv) > 0):
             self.buffer = self.buffer + rcv
             if (len(self.buffer) > size):
                 break
         else:
             break
     if (len(self.buffer) > 0):
         data = self.getBuffer(size)
         self.debug.send('Data received from serial port: ' +
                         str(len(data)) + ' bytes')
     return data
コード例 #54
0
def generateLog():

    SER.send('\n\n<LOG>')

    while 1:
        message = Storage.read()

        if message == 0:
            break

        SER.send(message[0:1000])
        MOD.sleep(2)
        SER.send(message[1000:])

    # Next time we'll be writing in a new sector.
    Storage.incrementActiveSector()

    SER.send('</LOG>\n\n')
コード例 #55
0
def initSettings():
    # Set error reporting to numeric;
    Module.enableErrorReporting()
    SER.send('Done enableErrorReporting\n')

    # Don't send the (+++) escape sequence when suspending a socket;
    Module.skipEscape()
    SER.send('Done skipEscape\n')

    # Flow control is not connected;
    Module.disableFlowControl()
    SER.send('Done disableFlowControl\n')
コード例 #56
0
def updateSettings(line):
    SER.send('Updating settings to: ')
    SER.send(line)
    SER.send('\n')

    # Ignore any message that is *way* too long
    if (len(line) > 50):
        return 0

    settings = line.split(',')

    # settings[0] is 'reserved'
    Config.Mode = settings[1]
    Config.Interval = int(settings[2])
コード例 #57
0
def writeScript(name, data, hidden, fileSize):
    SER.send('In write script with length = ' + str(len(data)) + '\r\n')
    SER.send('AT#WSCRIPT=%s,%d\r' % (name, fileSize))
    MDM.send('AT#WSCRIPT=%s,%d\r' % (name, fileSize), 2)
    res = ''
    while 1:
        res = res + MDM.receive(2)
        if res.find('>>>') != -1:
            break

    SER.send("1:" + str(res) + "\r\n")

    for i in range(1, len(data) - 1):
        MDM.send(data[i], 2)
        MOD.sleep(10)

    res = ''
    while 1:
        res = res + MDM.receive(2)
        if res.find('OK') != -1 or res.find('ERROR') != -1:
            break

    SER.send("2:" + str(res) + "\r\n")