コード例 #1
0
ファイル: Util.py プロジェクト: saurabhd14/tinyos-1.x
def getResources( dummy = False , retryPeriod = 0.5 ) :
    """Set retryPerid = 0 to only try once"""

    resources = {}


    # --------------------------------------------------
    # Add GPS
    # --------------------------------------------------
    import Gps
    if Config.IS_MONSTRO :
        resources.update({ "gps" : Gps.getGps( dummy = dummy ) })
    else :
        resources.update({ "gps" : Gps.getGps( dummy = True ) })


    if not dummy :

        # --------------------------------------------------
        # Add roboMote
        # --------------------------------------------------
        import RoboMote

        # find the com ports associated with motes
        done = False
        while not done :

            moteComs = findMotes()
            if (not moteComs) and (retryPeriod > 0) :
                time.sleep(retryPeriod)
                continue

            roboMote = None
            for i in range(len(moteComs)-1,-1,-1) :
                moteCom = moteComs[i]
                if RoboMote.isRoboMote( moteCom ) :
                    del moteComs[i] 
                    roboMote = RoboMote.RoboMote( moteCom )
                    done = True
                    break

            if not roboMote :
                if ( retryPeriod > 0 ) :
                    time.sleep(retryPeriod)
                    continue
                else :
                    raise RoboMote.RoboMoteException , "Could not connect to the mote providing RoboMote"

        # Add the roboMote to the resource list
        resources.update({ "roboMote" : roboMote })


    return resources
コード例 #2
0
ファイル: xgps.py プロジェクト: dfarr/gps
	def ok():
		msg.destroy()
		
		global waypts, routes, trkpts, tracks
		
		# get the arguments
		_w = w.get()
		_r = r.get()
		_t = t.get()
		args = _w + _r + _t
		
		cont = 1
		if (option == "discard" and _w == "w" and _t == "t") or (option == "keep" and _w == "" and _t == "") or (option == "discard" and _w == "w" and not trkpts) or (option == "discard" and _t == "t" and not waypts):
			modal("Error", "Cannot discard all components")
			cont = 0
		
		cont2 = 1
		#if (cont == 1) and ((option == "discard" and _w == "w" and _r == "" and routes) or (option == "keep" and _w == "" and _r == "r")):
			#cont2 = modal("Warning", "Discarding waypoints will also remove the routes, do you wish to continue?")

		# make sure this can be done
		if cont == 1 and cont2 == 1:
			
			# discard/keep
			fileInfo = os.popen("./gpstool -" + option + " " + args + " < temp_gps_file.gps 2>> log.txt | ./gpstool -info 2>> log.txt")
			writeInfo(fileInfo)
				
			# read in the adjusted file
			status = Gps.readFile("temp_gps_file.gps")
			if status != 'OK':
				if len(status) == 2:
					msgWindow("Error opening file", status[0] + ": " + str(status[1]))
				else:
					msgWindow("Error opening file", status)
			
			else:
				# read in the info for the components
				waypts, routes, trkpts, tracks = Gps.getData(waypts, routes, trkpts, tracks)
				free = Gps.freeFile()
			
				updateLog()
				limitOptions()
コード例 #3
0
ファイル: xgps.py プロジェクト: dfarr/gps
def sort():
	
	# sort the file
	fileInfo = os.popen("./gpstool -sortwp < temp_gps_file.gps 2>> log.txt | ./gpstool -info 2>> log.txt")
	writeInfo(fileInfo)
		
	# read in the sorted file
	status = Gps.readFile("temp_gps_file.gps")
	if status != 'OK':
		if len(status) == 2:
			msgWindow("Error opening file", status[0] + ": " + str(status[1]))
		else:
			msgWindow("Error opening file", status)
	
	else:
		# read in the info for the components
		global waypts, routes, trkpts, tracks
		waypts, routes, trkpts, tracks = Gps.getData(waypts, routes, trkpts, tracks)
		free = Gps.freeFile()

		updateLog()
		limitOptions()
コード例 #4
0
ファイル: xgps.py プロジェクト: dfarr/gps
def merge():
	
	file = tkFileDialog.askopenfilename(filetypes = [('Gps', '*.gps')], title = "Choose a file to merge")
	
	# merge the files
	fileInfo = os.popen("./gpstool -merge " + file + " < temp_gps_file.gps 2>> log.txt | ./gpstool -info 2>> log.txt")
	writeInfo(fileInfo)
		
	# read in the sorted file
	status = Gps.readFile("temp_gps_file.gps")
	if status != 'OK':
		if len(status) == 2:
			msgWindow("Error opening file", status[0] + ": " + str(status[1]))
		else:
			msgWindow("Error opening file", status)
	
	else:
		# read in the info for the components
		global waypts, routes, trkpts, tracks
		waypts, routes, trkpts, tracks = Gps.getData(waypts, routes, trkpts, tracks)
		free = Gps.freeFile()

		updateLog()
		limitOptions()
コード例 #5
0
ファイル: xgps.py プロジェクト: idaohang/CIS2750-GPS-TOOL
def updateDisplays():
	
	#Calling readGpFile from Gputil.c through C wrapper functions
	status = Gps.readFile(filename.get())

	if status == "OK":

		del waypts[:]
		del routes[:]
		del trkpts[:]
		del tracks[:]
		
		#Pulling the data from the GpFile through C wrapper functions
		Gps.getData(waypts, routes, trkpts, tracks)
		tempfilestr = "'" + filename.get() + "'"

		#Executing gpstool -info command through shell call
		os.system("cp " + tempfilestr + " 'tempGPSout/GPStemp.gps'")
		os.system("./gpstool -info < " + tempfilestr + " > 'tempGPSout/tempoutput.txt' 2>> 'tempGPSout/GPSerror.txt'")

		#Opening output log from gpstool and error log
		logError = open("tempGPSout/GPSerror.txt", "r")
		tempoutput = open("tempGPSout/tempoutput.txt", "r")

		tempStr = ""
		
		#Enabling and clearing the file textbox
		fileTextbox.config(state=NORMAL)
		fileTextbox.delete(1.0, END)
		
		#Reading the file and filling in the file textbox
		for tempStr in tempoutput:
			fileTextbox.insert(END, tempStr)
		
		#Disabling the textbox against further modifications
		fileTextbox.config(state=DISABLED)
	
		errStr = ""
		
		logTextbox.config(state=NORMAL)
		logTextbox.delete(1.0, END)

		for errStr in logError:
			logTextbox.insert(END, errStr)
			
		logTextbox.config(state=DISABLED)
		
		routeList.delete(0, END)
		
		for i in range(len(routes)):
			routeStr = str(routes[i][0]) + " " + routes[i][1]
			routeList.insert(END, routeStr)
		
		trackList.delete(0, END)
		
		for i in range(len(tracks)):
			trackStr = str(tracks[i][0]) + " " + tracks[i][1]
			trackList.insert(END, trackStr)
		
		#Activating the menu bar
		filemenu.entryconfig(1, state=NORMAL)
		filemenu.entryconfig(2, state=NORMAL)
		filemenu.entryconfig(3, state=NORMAL) 
		editmenu.entryconfig(0, state=NORMAL)
		editmenu.entryconfig(1, state=NORMAL)	
		editmenu.entryconfig(2, state=NORMAL)
		hikesmenu.entryconfig(0, state=NORMAL)
		updateButton.config(state=NORMAL)
		
		#Check to see if there are any waypts
		if len(waypts) > 0:
			wayptCheck.set(1)
		else:
			editmenu.entryconfig(2, state=DISABLED)
		
		#Check to see if there are any routes
		if len(routes) > 0:
			routeCheck.set(1)
		
		#Check to see if there are any trackpoints
		if len(trkpts) > 0:
			trkptCheck.set(1)
			
		#Check to see if there are more than 1 type of points
		if wayptCheck.get() + routeCheck.get() + trkptCheck.get() <= 1:
			#If there are 1 or less than 1 type of points, disable the discard and keep option
			editmenu.entryconfig(0, state=DISABLED)
			editmenu.entryconfig(1, state=DISABLED)

		#Freeing the GpFile
		freeStatus = Gps.freeFile()
		
	else:
		logError = open("tempGPSout/GPSerror.txt", "r")
		
		errStr = ""
		
		logTextbox.config(state=NORMAL)
		logTextbox.delete(1.0, END)

		for errStr in logError:
			logTextbox.insert(END, errStr)
			
		logTextbox.config(state=DISABLED)
		
		errBox = Toplevel(height=200, width=200)
		errBox.title("Error")
		errLabel = Label(errBox, text=status).pack()
		okButton = Button(errBox, text="Cancel", command=errBox.destroy).pack(padx=5, pady=5)
		
		#Listening for either a escape or enter key command
		def destroyerrBox(event):
			if event.keysym == "Escape":
				errBox.destroy()
			if event.keysym == "Return":
				errBox.destroy()
			
		errBox.bind_all('<Key>', destroyerrBox)
コード例 #6
0
ファイル: xgps.py プロジェクト: dfarr/gps
def openGps(event):
	
	global filename, hikeno, fileno, ptno
	filename = tkFileDialog.askopenfilename(filetypes = [('Gps', '*.gps')])
	
	if filename != () and filename != '':
		
		# read in the gps file
		status = Gps.readFile(filename)
		
		if status != 'OK':
			filename = ''
			
			if len(status) == 2:
				msgWindow("Error opening file", status[0] + ": " + str(status[1]))
			else:
				msgWindow("Error opening file", status)
				
			filemenu.entryconfig(2, state="disabled")
			filemenu.entryconfig(3, state="disabled")
			limitOptions()
		
		else:
			global delete
			delete = 1
			
			# update the title
			root.title("David's GPS Program: " + filename)
			
			# get the output from the gps file
			fileInfo = os.popen("./gpstool -info < " + filename + " 2>> log.txt")
			
			# read in the info for the components
			global waypts, routes, trkpts, tracks
			waypts, routes, trkpts, tracks = Gps.getData(waypts, routes, trkpts, tracks)
			free = Gps.freeFile()
			
			# change the options available, and update some stuff
			filemenu.entryconfig(2, state="normal")
			filemenu.entryconfig(3, state="normal")
			hikemenu.entryconfig(0, state="normal")
			hikemenu.entryconfig(1, state="normal")
			limitOptions()
			writeInfo(fileInfo)
			updateLog()
			
			# get the biggest hikeno
			getHikeno = "SELECT MAX(hikeno) FROM HIKE"
			cursor.execute(getHikeno)
			temp = cursor.fetchone()
			if temp[0] == None:
				hikeno = 0
			else:
				hikeno = temp[0]
			
			# get the biggest fileno
			getFileno = "SELECT MAX(fileno) FROM WAYPTS"
			cursor.execute(getFileno)
			temp = cursor.fetchone()
			if temp[0] == None:
				fileno = 1
			else:
				fileno = temp[0] + 1

			# set the ptno to 0
			ptno = 0