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: #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,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)