def receiveCommand(ser,latitude,longitude):
	logger.debug("__Init__ receiving PCN command function")
	i = 0
	while True:
		try:
			#print 'receive:'
			data = ser.read(300)
			if(len(data)>0):
				commandAnalyzer = CommandAnalyzer(data)
				if (commandAnalyzer.getCommandName() == 'gcounters'):
					commandAnalyzer.printCommandInfo()
					#busClient.service.insertpassengerMAC('unishuttle04', latitude,longitude,str(datetime.datetime.now()),1,2)
					passengerOn = commandAnalyzer.getNumberPassengerOn()
					passengerOff = commandAnalyzer.getNumberPassengerOff()
					if(passengerOn !=0 or passengerOff !=0):
                                                tmpSt = "insert into passengerMAC(host,source,destination,datetime,on,off,lat,lon) values (%s, %s, %s, %s, %s, %s, %s, %s)" % (hostname,commandAnalyzer.getSource(),commandAnalyzer.getDestination(), str(datetime.datetime.now()), str(passengerOn), str(passengerOff), str(globalLatitude), str(globalLongitude))
						print tmpSt
						logger.debug("__PCN receive data__: %s", tmpSt)
						busClient.service.insertpassengerMAC(hostname, globalLongitude, globalLatitude,str(datetime.datetime.now()),1,str(passengerOn))
						busClient.service.insertpassengerMAC(hostname, globalLongitude, globalLatitude,str(datetime.datetime.now()),0,str(passengerOff))
						print 'send reset:',ser.write(PCNCommand.RESET)
		except:
			print 'receive data from pcn failed'
			logger.debug("__PCN receive data__: receive data from pcn failed or cannot send data to server")

		sleep(0.5)
def receiveCommand(ser):
    i = 0
    while True:
        #print 'receive:'
        data = ser.read(300)
        if (len(data) > 0):
            commandAnalyzer = CommandAnalyzer(data)
            if (commandAnalyzer.getCommandName() == 'gcounters'):
                #print 'Got data'
                print 'send reset:', ser.write(PCNCommand.RESET)
                #print	'Got data:'
                #commandAnalyzer.printCommandInfo()
                passengerOn = commandAnalyzer.getNumberPassengerOn()
                passengerOff = commandAnalyzer.getNumberPassengerOff()
                tmpSt = "passenger on: %s , passenger off: %s" % (
                    str(passengerOn), str(passengerOff))
                print tmpSt
                if (passengerOn != 0):
                    #update data to local database
                    writePassengerDataToDB('nan', 'nan', 1, str(passengerOn))

                if (passengerOff != 0):
                    #update data to local database
                    writePassengerDataToDB('nan', 'nan', 0, str(passengerOff))

        sleep(0.5)
    def add(self, command):
        commandAnalyzer = CommandAnalyzer(command)
        commandName = commandAnalyzer.getCommandName()

        if (commandName == 'gcounters'):
            commandAnalyzer.printCommandInfo()
            passengerOn = commandAnalyzer.getNumberPassengerOn()
            passengerOff = commandAnalyzer.getNumberPassengerOff()

            if (passengerOn != 0 or passengerOff != 0):
                stopActivity = StopActivity()
                stopActivity.setSource(commandAnalyzer.getSource())
                stopActivity.setDestination(commandAnalyzer.getDestination())
                stopActivity.setStatus('')
                stopActivity.setDateTime(str(datetime.datetime.now()))
                stopActivity.setPassengerOn(passengerOn)
                stopActivity.setPassengerOff(passengerOff)
                self.stopActivities.append(stopActivity)

                self.length += 1
def receiveCommand(ser,latitude,longitude):
	
	logger.debug("__Init__ receiving PCN command function")
	i = 0
	while True:
		try:
		
			#update stop latitude and longitude
			if(globalSpeed < 1):
				stopLatitude = globalLatitude
				stopLongitude = globalLongitude
						
			#print 'receive:'
			data = ser.read(300)
			if(len(data)>0):
				commandAnalyzer = CommandAnalyzer(data)
				if (commandAnalyzer.getCommandName() == 'gcounters'):
					ser.write(PCNCommand.RESET)
					#commandAnalyzer.printCommandInfo()
					passengerOn = commandAnalyzer.getNumberPassengerOn()
					passengerOff = commandAnalyzer.getNumberPassengerOff()
					
					#if(passengerOn !=0 or passengerOff !=0):
					#tmpSt = "insert into passengerMAC(host,source,destination,datetime,on,off,lat,lon,speed) values (%s, %s, %s, %s, %s, %s, %s, %s, %s)" % (hostname,commandAnalyzer.getSource(),commandAnalyzer.getDestination(), str(datetime.datetime.now()), str(passengerOn), str(passengerOff), str(stopLatitude), str(stopLongitude),str(globalSpeed))
					#print tmpSt
					#logger.debug("__PCN receive data__: %s", tmpSt)
                                               
					if(passengerOn !=0):
						#update data to local database
                                        	writePassengerDataToDB(stopLongitude,stopLatitude,1,str(passengerOn))

					if(passengerOff !=0):
						#update data to local database
                                        	writePassengerDataToDB(stopLongitude,stopLatitude,0,str(passengerOff))
						
						
		except:
			#print 'receive data from pcn failed'
			logger.debug("__PCN receive data__: receive data from pcn failed or cannot save data to local DB")

		sleep(0.5)
示例#5
0
def receiveCommand(ser,latitude,longitude):
	i = 0
	while True:
		try:
			#print 'receive:'
			data = ser.read(300)
			if(len(data)>0):
				commandAnalyzer = CommandAnalyzer(data)
				if (commandAnalyzer.getCommandName() == 'gcounters'):
					commandAnalyzer.printCommandInfo()
					#busClient.service.insertpassengerMAC('unishuttle04', latitude,longitude,str(datetime.datetime.now()),1,2)
					passengerOn = commandAnalyzer.getNumberPassengerOn()
					passengerOff = commandAnalyzer.getNumberPassengerOff()
					if(passengerOn !=0 or passengerOff !=0):
						print 'insert values(source,destination,datetime,on,off,lat,lon)',commandAnalyzer.getSource(),commandAnalyzer.getDestination(), str(datetime.datetime.now()), passengerOn, passengerOff, latitude, longitude
						logger.debug("__PCN receive data__: normal receive data")
						#busClient.service.insertpassengerMAC('unishuttle04', latitude,longitude,str(datetime.datetime.now()),1,passengerOn)
						#busClient.service.insertpassengerMAC('unishuttle04', latitude,longitude,str(datetime.datetime.now()),0,passengerOff)
						print 'send reset:',ser.write(PCNCommand.RESET)
		except:
			print 'receive data from pcn failed'
			logger.debug("__PCN receive data__: receive data from pcn failed")

		sleep(1)