def test_start():
    curMode = Startup.Drone.State.connect
    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"
    testFail = 0

    airconnect = Connect()
    airstatus = Status()
    thisAdvisory = Advisory()
    airconnect.set_Timeout(16)
    airconnect.set_XAPIKey(xapikey)

    Ret = airconnect.connect()

    if Ret:
        if airstatus.get_status(lat, lon, Weather.on):
            if airstatus.get_StatusColor() != thisAdvisory.Color.Colors.yellow:
                testFail = 1
            if airstatus.get_MaxDistance() != 0:
                testFail = 1
            if airstatus.get_StatusCode() != airstatus.get_StatusCode():
                testFail = 1
            if airstatus.cmd_ProcessAdvisories() != True:
                testFail = 1
            Advisories = airstatus.get_Advisories()
            try:
                xIndex = 0
                while True:
                    thisAdvisory = Advisories[xIndex]
                    xIndex += 1
            except:
                print "Finished Advisory Print Task..."

            if xIndex != 9:
                print "..............................."
                testFail = 1
    else:
        testFail = 1

    return testFail
示例#2
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
	thisSA = "uav/traffic/sa/"+flightID
	thisAlert = "uav/traffic/alert/"+flightID
	#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()
示例#4
0
		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)
				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()
示例#5
0
def test_start():
    curMode = Startup.Drone.State.connect
    testFail = 0
    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)

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

    try:
        airconnect = Connect()
    except:
        print "Test: Fail No Connection..."
        testFail = 1

    try:
        Ret = airconnect.get_boardID()
    except:
        print "Test: Fail Could Not Retrieve Board ID..."
        testFail = 1

    if Ret == False:
        print "Test: Fail No Board ID Found..."
        testFail = 1

    Ret = airconnect.connect()

    if Ret != 1:
        print "Test: Fail Bad Connection Return..."
        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
示例#6
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