예제 #1
0
def test_start():
	curMode = Startup.Drone.State.connect
	testFail = 0
	xapikey = {"Content-Type":"application/json; charset=utf-8","X-API-Key":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjcmVkZW50aWFsX2lkIjoiY3JlZGVudGlhbHxHTk5nbUxuaTlYM1p3UlRYTU9sMnFmS0o1Z0xLIiwiYXBwbGljYXRpb25faWQiOiJhcHBsaWNhdGlvbnxuOW41QmtZc0JhNkFvM3NBUkpHeXlVYWxZUUVZIiwib3JnYW5pemF0aW9uX2lkIjoiZGV2ZWxvcGVyfDJ6b2JiN3loeGVZNHFrQzNQUngwWkhLTXoyMzgiLCJpYXQiOjE0NzExMjY1NDJ9.v4STUtbJa3uJZFsJLpWZRgUYoyz1X6BxKW8kokerjCg"}

	try:
		#Start GPS
		p = subprocess.Popen(['ps', '-A'], stdout=subprocess.PIPE)
		out, err = p.communicate()
		for line in out.splitlines():
			if 'gpsfake' in line:
				pid = int(line.split(None, 1)[0])
				os.kill(pid, signal.SIGKILL)
			if 'run-fake-gps' in line:
				pid = int(line.split(None, 1)[0])
				os.kill(pid, signal.SIGKILL)
			if 'gpsd' in line:
				pid = int(line.split(None, 1)[0])
				os.kill(pid, signal.SIGKILL)
		subprocess.Popen('./run-fake-gps.sh', shell=True, stderr=subprocess.STDOUT)
		time.sleep(5)
    		#Access GPS
		gpsReady = False
    		gpsd = gps.gps(mode=gps.WATCH_ENABLE)

		while not gpsReady:
			print "Waiting for GPS..."
			# Read the GPS state
			gpsd.next()

			# Wait for GPS lock
			if (gpsd.valid & gps.LATLON_SET) != 0:
				lat = str(gpsd.fix.latitude)
				lon = str(gpsd.fix.longitude)
				alt = str(gpsd.fix.altitude)
				ground_speed = str(gpsd.fix.speed)
				heading = str(gpsd.fix.track)
				gpstime = str(gpsd.fix.time)
				curMode = str(gpsd.fix.mode)
				gpsReady = True #breakout
            
	except socket.error:
    		print "Error: gpsd service does not seem to be running, plug in USB GPS, run fake-gps-data.sh or run set 'test' flag"
    		sys.exit(1)

	barometer = '28.4'
	log_perct = '31.2'
	bogeyid = '37849329'
	drone_mode = "follow-me"
	battery_chrg= '11.2'
	cur_status= "warning"

	print lat
	print lon
	print alt
	print ground_speed
	print heading
	print time

	airconnect = Connect()
	airflight = Flight()
	airtelemetry = Telemetry()
	airconnect.set_Timeout(16)
	airconnect.set_XAPIKey(xapikey)

	Ret = airconnect.connect()

	if Ret:
	
		airconnect.get_SecureToken()
		if Globals.myToken == "":
			testFail = 1

		try:
			flightID = airflight.create_FlightPoint (5,lat,lon,Public.on,Notify.on)
			if len(flightID) != 35:
				testFail = 1
			myPilotID = airflight.get_PilotID()
			if len(myPilotID) != 30:
				testFail = 1
		except:
			print flightID
			print myPilotID
			testFail = 1

		print "Telemetry..."
		testCount = 0
		response = airtelemetry.post_Telemetry(flightID,lat,lon,alt,ground_speed,heading,barometer,cur_status,battery_chrg,drone_mode,bogeyid,log_perct)
		
		if len(response) < 24:		
			testFail = 1
			testCount = 18
			print "No Telemetry..."
		else:
			print response

		while testCount < 18:
			gpsReady = False
			while not gpsReady:
				print "Waiting for GPS..."
				# Read the GPS state
				gpsd.next()

				# Wait for GPS lock
				if (gpsd.valid & gps.LATLON_SET) != 0:
					lat = str(gpsd.fix.latitude)
					lon = str(gpsd.fix.longitude)
					alt = str(gpsd.fix.altitude)
					ground_speed = str(gpsd.fix.speed)
					heading = str(gpsd.fix.track)
					gpstime = str(gpsd.fix.time)
					curMode = str(gpsd.fix.mode)
					gpsReady = True #breakout

			response = airtelemetry.post_Telemetry(flightID,lat,lon,alt,ground_speed,heading,barometer,cur_status,battery_chrg,drone_mode,bogeyid,log_perct)
			testCount += 1			
			if len(response) < 14:		
				testFail = 1
				testCount = 18
				print "No Telemetry..."
			else:
				print response

		Ret = airflight.end_Flight(flightID)
		if Ret == False:
			testFail = 1
		Ret = airflight.delete_Flight(flightID)
		if Ret == False:
			testFail = 1

		try:	
			flightID = airflight.create_FlightPoint (2,lat,lon,Public.on,Notify.on)
		except:
			print "flight creation execption..."	
		flights = airflight.get_FlightList(myPilotID)
		if flights == "":
			testFail = 1
		try:
			airflight.cmd_KillFlights(myPilotID)
		except:
			testFail = 1

	#clean up
	p = subprocess.Popen(['ps', '-A'], stdout=subprocess.PIPE)
	out, err = p.communicate()
	for line in out.splitlines():
		if 'gpsfake' in line:
			pid = int(line.split(None, 1)[0])
			os.kill(pid, signal.SIGKILL)
		if 'run-fake-gps' in line:
			pid = int(line.split(None, 1)[0])
			os.kill(pid, signal.SIGKILL)
		if 'gpsd' in line:
			pid = int(line.split(None, 1)[0])
			os.kill(pid, signal.SIGKILL)
	
	return testFail
예제 #2
0
	#client.subscribe(str(thisSA),0)
	#client.subscribe(str(thisAlert),0)

def on_message(client, userdata, msg):
	print "Alert..."
	print (msg.topic+" " +str(msg.payload))

#client.on_connect = on_connect
#client.on_message = on_message
#client.tls_insecure_set(True)
#client.tls_set("airmap.io.crt",cert_reqs=ssl.CERT_NONE,tls_version=ssl.PROTOCOL_TLSv1_2)
#client.tls_insecure_set(True)

airconnect = Connect()
airstatus = Status()
airflight = Flight()
airconnect.set_Timeout(16)
airconnect.set_XAPIKey(xapikey)

Ret = airconnect.connect()

if Ret:
	if airstatus.get_status(str(lat),str(lon),Weather.on):
		flightStatus = airstatus.get_StatusColor()
		print flightStatus
		maxDistance = airstatus.get_MaxDistance()
		print maxDistance

		statusCode = airstatus.get_StatusCode()
		print statusCode
예제 #3
0
curMode = Startup.Drone.State.connect
test = True
lat = None
lon = None

fileParams = open("params.txt", "r")
if fileParams.mode == 'r':
    xapikeyBuffer = fileParams.readline()  # 1st line is xapikey
    xapikeyBuffer = xapikeyBuffer.rstrip('\n')
    xapikey = ast.literal_eval(xapikeyBuffer)
    myPilotID = fileParams.readline()  # 2nd line is myPilotId
    myPilotID = myPilotID.rstrip('\n')
else:
    print "Pilot Kill Flight Error..."
fileParams.close()

airconnect = Connect()
airflight = Flight()
airconnect.set_Timeout(16)
airconnect.set_XAPIKey(xapikey)

#airconnect.get_boardID()

Ret = airconnect.connect()

if Ret:
    airconnect.get_SecureAuth()

    airflight.get_FlightList(myPilotID)
    airflight.cmd_KillFlights(myPilotID)
예제 #4
0
			# Read the GPS state
			gpsd.next()

			# Wait for GPS lock
			if (gpsd.valid & gps.LATLON_SET) != 0:
				lat = str(gpsd.fix.latitude)
				lon = str(gpsd.fix.longitude)
				gpsReady = True #breakout
            
	except socket.error:
    		print "Error: gpsd service does not seem to be running, plug in USB GPS, run fake-gps-data.sh or run set 'test' flag"
    		sys.exit(1)

airconnect = Connect()
airstatus = Status()
airflight = Flight()
airtelemetry = Telemetry()
airconnect.set_Timeout(16)
airconnect.set_XAPIKey(xapikey)

airconnect.get_boardID()

Ret = airconnect.connect()

if Ret:
	if airstatus.get_status(lat,lon,Weather.on):
		flightStatus = airstatus.get_StatusColor()
		print flightStatus
		maxDistance = airstatus.get_MaxDistance()
		print maxDistance
예제 #5
0
def test_start():

    curMode = Startup.Drone.State.connect
    testFail = 0
    xapikey = {
        "Content-Type":
        "application/json; charset=utf-8",
        "X-API-Key":
        "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjcmVkZW50aWFsX2lkIjoiY3JlZGVudGlhbHxHTk5nbUxuaTlYM1p3UlRYTU9sMnFmS0o1Z0xLIiwiYXBwbGljYXRpb25faWQiOiJhcHBsaWNhdGlvbnxuOW41QmtZc0JhNkFvM3NBUkpHeXlVYWxZUUVZIiwib3JnYW5pemF0aW9uX2lkIjoiZGV2ZWxvcGVyfDJ6b2JiN3loeGVZNHFrQzNQUngwWkhLTXoyMzgiLCJpYXQiOjE0NzExMjY1NDJ9.v4STUtbJa3uJZFsJLpWZRgUYoyz1X6BxKW8kokerjCg"
    }

    lat = '34.013252'
    lon = '-118.499112'
    alt = '101.3'
    ground_speed = '10.8'
    heading = '84.6'
    barometer = '28.4'
    log_perct = '31.2'
    bogeyid = '37849329'
    drone_mode = "follow-me"
    battery_chrg = '11.2'
    cur_status = "warning"

    airconnect = Connect()
    airflight = Flight()
    airconnect.set_Timeout(16)
    airconnect.set_XAPIKey(xapikey)

    Ret = airconnect.connect()

    if Ret:

        airconnect.get_SecureToken()
        if Globals.myToken == "":
            testFail = 1

        flightID = airflight.create_FlightPoint(2, lat, lon, Public.on,
                                                Notify.on)
        if len(flightID) != 35:
            testFail = 1
        myPilotID = airflight.get_PilotID()
        if len(myPilotID) != 30:
            testFail = 1

        Ret = airflight.end_Flight(flightID)
        if Ret == False:
            testFail = 1
        Ret = airflight.delete_Flight(flightID)
        if Ret == False:
            testFail = 1

        flightID = airflight.create_FlightPoint(2, lat, lon, Public.on,
                                                Notify.on)
        if len(flightID) != 35:
            testFail = 1
        Ret = airflight.end_Flight(flightID)
        if Ret == False:
            testFail = 1
        flights = airflight.get_FlightList(myPilotID)
        if flights == "":
            testFail = 1
        try:
            airflight.cmd_KillFlights(myPilotID)
        except:
            testFail = 1

    return testFail