Ejemplo n.º 1
0
def spibuildtable(conn, spidtable, prt=False):

    cursG = conn.cursor()  # set the cursor for searching the devices
    # get all the devices with SPIDER
    cursG.execute(
        "select id, flarmid, registration from TRKDEVICES where devicetype = 'SPID' and active = 1; "
    )
    for rowg in cursG.fetchall(
    ):  # look for that registration on the OGN database

        ident = rowg[0]  # registration to report
        flarmid = rowg[1]  # Flarm id to be linked
        registration = rowg[2]  # registration id to be linked
        if flarmid == None or flarmid == '':  # if flarmid is not provided
            # get it from the registration
            flarmid = getflarmid(conn, registration)
        else:
            chkflarmid(flarmid)
        if flarmid == "NOREG":  # in case of no registration on the DDBa
            flarmid = getognflarmid(registration)

        spidtable[ident] = flarmid  # substitute the id by the Flarmid
    if prt:
        print("SPIDtable:", spidtable)
    return (spidtable)
Ejemplo n.º 2
0
def skylaprspush(datafix, conn, prt=False):

    for fix in datafix['skylpos']:  # for each fix on the dict
        idpn = fix['pilotname']  # extract the information
        dte = fix['date']
        hora = fix['time']
        station = config.location_name
        latitude = fix['Lat']
        longitude = fix['Long']
        altitude = fix['altitude']
        speed = fix['speed']
        course = fix['course']
        roclimb = fix['roc']
        rot = 0
        sensitivity = 0
        gps = fix['GPS']
        uniqueid = str(fix["UnitID"])
        dist = fix['dist']
        extpos = fix['extpos']
        gliderreg = fix['gliderreg']
        flarmid = getflarmid(conn, gliderreg)
        # build the APRS message
        lat = deg2dmslat(abs(latitude))
        if latitude > 0:
            lat += 'N'
        else:
            lat += 'S'
        lon = deg2dmslon(abs(longitude))
        if longitude > 0:
            lon += 'E'
        else:
            lon += 'W'

        ccc = "%03d" % int(course)
        sss = "%03d" % int(speed)
        aprsmsg = flarmid+">OGSKYL,qAS,SKYLINES:/" + \
            hora+'h'+lat+"/"+lon+"'"+ccc+"/"+sss+"/"
        if altitude > 0:
            aprsmsg += "A=%06d" % int(altitude * 3.28084)
        aprsmsg += " id" + uniqueid + " %+04dfpm " % (int(roclimb)) + " \n"
        print("APRSMSG: ", aprsmsg)
        config.SOCK_FILE.write(aprsmsg)
        config.SOCK_FILE.flush()

    return (True)
Ejemplo n.º 3
0
def ogntbuildtable(
    conn,
    ognttable,
    prt=False
):  # conn is the DB connection id, ogntable is where to return the pairs table

    oldtable = ognttable.copy()  # have a copy of it
    auxtable = {}  # the aux table to know the registrations
    cursG = conn.cursor()  # set the cursor for searching the devices
    # get all the devices with OGN tracker
    cursG.execute(
        "select id, flarmid, registration from TRKDEVICES where devicetype = 'OGNT' and active = 1; "
    )
    for rowg in cursG.fetchall(
    ):  # look for that registration on the OGN database

        ogntid = rowg[0].upper()  # OGN tracker ID
        flarmid = rowg[1].upper()  # Flarmid id to be linked
        registration = rowg[2]  # registration id to be linked
        if prt:
            print("OGNTtable:", ogntid, flarmid, registration)
        if flarmid in (None, ''):  # if flarmid is not provided
            # get it from the registration
            flarmid = getflarmid(conn, registration)
        else:
            chkflarmid(flarmid)

        ognttable[ogntid] = flarmid

        # check that the registration is on the table - sanity check
        o = getognreg(ogntid)
        if o == "NOreg":
            o = 'NoregO'
        # check that the registration is on the table - sanity checka
        f = getognreg(flarmid)
        if f == "NOreg":
            f = 'NoregF'
        auxtable[o] = f

    unmatched_item = set(oldtable.items()) ^ set(ognttable.items())
    if len(unmatched_item) != 0 and prt:
        print("OGNTtable:", ognttable)
        print("OGNTtable:", auxtable)
    return (ognttable)
Ejemplo n.º 4
0
def skylstoreitindb(datafix, curs, conn):  # store the fix into the database

    for fix in datafix['skylpos']:  # for each fix on the dict
        idpn = fix['pilotname']  # extract the information
        dte = fix['date']
        hora = fix['time']
        station = config.location_name
        latitude = fix['Lat']
        longitude = fix['Long']
        altitude = fix['altitude']
        speed = fix['speed']
        course = fix['course']
        roclimb = fix['roc']
        rot = 0
        sensitivity = 0
        gps = fix['GPS']
        uniqueid = str(fix["UnitID"])
        dist = fix['dist']
        extpos = fix['extpos']
        gliderreg = fix['gliderreg']
        flarmid = getflarmid(conn, gliderreg)
        addcmd = "insert into OGNDATA values ('" + flarmid + "','" + dte + "','" + hora + "','" + station + "'," + str(latitude) + "," + str(longitude) + "," + str(altitude) + "," + str(speed) + "," + \
            str(course) + "," + str(roclimb) + "," + str(rot) + "," + str(sensitivity) + \
            ",'" + gps + "','" + uniqueid + "'," + \
            str(dist) + ",'" + extpos + "', 'SKYL' ) "
        try:  # store it on the DDBB
            #print addcmd
            curs.execute(addcmd)
        except MySQLdb.Error as e:
            try:
                print(">>>MySQL Error [%d]: %s" % (e.args[0], e.args[1]))
            except IndexError:
                print(">>>MySQL Error: %s" % str(e))
                print(">>>MySQL error:", addcmd, idpn)
            return (False)  # indicate that we have errors
    conn.commit()  # commit the DB updates
    return (True)  # indicate that we have success
Ejemplo n.º 5
0
def lt24findpos(ttime, conn, once, prt=False, store=True, aprspush=False):

    flarmids = {}			        # list of flarm ids
    curs = conn.cursor()                        # set the cursor for storing the fixes
    cursG = conn.cursor()                       # set the cursor for searching the devices
    userList = ''
    lt24pos = {"lt24pos": []}                   # init the dict
    # get all the devices with LT24
    cursG.execute(
        "select id, registration, active, flarmid from TRKDEVICES where devicetype = 'LT24' ; ")
    for rowg in cursG.fetchall(): 	        # look for that registration on the OGN database

        reg = rowg[0]		                # registration to report
        registration = rowg[1]                  # Glider registration EC-???
        active = rowg[2]		        # if active or not
        flarmid = rowg[3]		        # flarmid
        if active == 0:
            continue                            # if not active, just ignore it
            # build the userlist to call to the LT24 server
        if flarmid == None or flarmid == '': 	# if flarmid is not provided
            # get it from the registration
            flarmid = getflarmid(conn, registration)
        else:
            chkflarmid(flarmid)

        userList += reg		                # build the user list
        userList += ","		                # separated by comas
        flarmids[reg] = flarmid                 # add flarmid to the list

    if len(userList) == 0:
        userList = "NONE"
        now = datetime.utcnow()
        # number of second until beginning of the day of 1-1-1970
        td = now-datetime(1970, 1, 1)
        return (int(td.total_seconds()))
    else:
        userList = userList.rstrip(',')         # clear the last comma
        # request for the time being, just the last position of the glider
    req = "op/2//detailLevel/-1/userList/"+userList  # the URL request to LT24
    jsondata = lt24req(req)		        # get the JSON data from the lt24 server
    pos = json.loads(jsondata)                  # convert JSON to dictionary
    if prt:
        print(json.dumps(pos, indent=4))        # convert JSON to dictionary
    if 'result' in pos:
        result = pos["result"]                  # get the result part
    else:
        now = datetime.utcnow()
        # number of second until beginning of the day of 1-1-1970
        td = now-datetime(1970, 1, 1)
        return (int(td.total_seconds()))

    k = list(result.keys())		        # get the key or track id
    jsondata = result[str(k[0])] 	        # only the first track
    if once:			                # only the very first time
        lt24addpos(jsondata, lt24pos, ttime, userList, flarmid)                # find the gliders since TTIME
    # get now all the fixes/tracks
    sync = lt24gettrackpoints(lt24pos, ttime, userList, flarmids)
    if prt:
        print(lt24pos)
    if store:
        lt24storeitindb(lt24pos, curs, conn)    # and store it on the DDBB
    if aprspush:
        lt24aprspush(lt24pos, prt)		# and push the data to the OGN APRS

    if sync == 0:			        # just in case of not tracks at all, built the current time
        now = datetime.utcnow()
        # number of second until beginning of the day of 1-1-1970
        td = now-datetime(1970, 1, 1)
        sync = int(td.total_seconds())          # as an integer
    return (sync+1)			        # return TTIME for next call
Ejemplo n.º 6
0
def inreachfindpos(ttime, conn, prt=False, store=True, aprspush=False):

    foundone = False  # asume no found
    curs = conn.cursor()  # set the cursor for storing the fixes
    cursG = conn.cursor()  # set the cursor for searching the devices
    # get all the devices with INRE
    cursG.execute(
        "select id, spotid as inreachid, spotpasswd as inreachpasswd, active, flarmid, registration from TRKDEVICES where devicetype = 'INRE'; "
    )
    for rowg in cursG.fetchall(
    ):  # look for that registration on the OGN database

        reg = rowg[0]  # registration to report
        inreachID = rowg[1]  # INREach
        inreachpasswd = rowg[2]  # InReach password
        active = rowg[3]  # if active or not
        flarmid = rowg[4]  # Flamd id to be linked
        registration = rowg[5]  # registration id to be linked
        if active == 0:
            continue  # if not active, just ignore it
        if flarmid == None or flarmid == '':  # if flarmid is not provided
            # get it from the registration
            flarmid = getflarmid(conn, registration)
        else:
            chkflarmid(flarmid)

            # build the URL to call to the InReach server
        if ttime == 0:
            url = "http://inreach.garmin.com/feed/share/" + inreachID
        else:
            # get the date in ISO format to be used on the URL
            tt = datetime.utcfromtimestamp(ttime)
            ts = tt.isoformat()
            url = "http://inreach.garmin.com/feed/share/" + \
                inreachID+"?d1="+str(ts)
        if prt:
            print(url)
        print(url)
        inreachpos = {"inreachpos": []}  # init the dict
        # get the KML data from the InReach server
        kml = inreachgetapidata(url)
        if kml == ' ':
            return -1  # return error
        if prt:  # if we require printing the raw data
            print("KML ===>", kml)  # print the KML data
            # find the gliders since TTIME
        found = inreachgetaircraftpos(kml,
                                      inreachpos,
                                      ttime,
                                      reg,
                                      flarmid,
                                      prt=prt)
        if found:
            foundone = True
        if prt:
            print(inreachpos)
        if store:
            # and store it on the DDBB
            inreachstoreitindb(inreachpos, curs, conn)
        if aprspush:
            inreachaprspush(inreachpos, prt)  # and push the data into the APRS

    if foundone:
        now = datetime.utcnow()
        # number of second until beginning of the day of 1-1-1970
        td = now - datetime(1970, 1, 1)
        ts = int(td.total_seconds())  # as an integer
        return (ts)  # return TTIME for next call
    else:
        return (ttime)  # keep old value
Ejemplo n.º 7
0
def spotfindpos(ttime, conn, prt=False, store=True, aprspush=False):
    foundone = False  # asume no found
    if conn:
        curs = conn.cursor()  # set the cursor for storing the fixes
        cursG = conn.cursor()  # set the cursor for searching the devices
        # get all the devices with SPOT
        cursG.execute(
            "select id, spotid, spotpasswd, active, flarmid, registration from TRKDEVICES where devicetype = 'SPOT'; "
        )
        for rowg in cursG.fetchall(
        ):  # look for that registration on the OGN database

            reg = rowg[0]  # registration to report
            spotID = rowg[1]  # SPOTID
            spotpasswd = rowg[2]  # SPOTID password
            active = rowg[3]  # if active or not
            flarmid = rowg[4]  # Flamd id to be linked
            registration = rowg[5]  # registration id to be linked
            if active == 0:
                continue  # if not active, just ignore it
            if flarmid == None or flarmid == '':  # if flarmid is not provided
                # get it from the registration
                flarmid = getflarmid(conn, registration)
            else:
                chkflarmid(flarmid)
            if flarmid == "NOREG":  # in case of no registration on the DDBa
                flarmid = getognflarmid(registration)
            if flarmid == "NOFlarm":  # in case of no registration on the DDB
                print(">>>> Reg", reg, "spotID", spotID, "FlarmID", flarmid,
                      "Registration", registration, "<<<<<<\n")
                flarmid = registration  # just print warning and use the registration
            jsondata = spotgetdata(spotID, spotpasswd, prt)
            # find the gliders since TTIME
            spotpos = {"spotpos": []}  # init the dict
            found = spotgetaircraftpos(jsondata,
                                       spotpos,
                                       ttime,
                                       reg,
                                       flarmid,
                                       prt=False)
            if found:
                foundone = True
            if prt:
                print(spotpos)
            if store:
                spotstoreitindb(spotpos, curs,
                                conn)  # and store it on the DDBB
            if aprspush:
                spotaprspush(spotpos, prt)  # and push the data into the APRS
    else:
        devdvt = []
        n = get_by_dvt(devdvt, "S")
        if n > 0:
            for dev in devdvt:
                if (dev['tracked'] == 'N' or dev['identified'] == 'N'
                        or dev['device_active'] == 'N'
                        or dev['aircraft_active'] == 'N'):
                    continue  # nothing to do
                spotID = dev['device_id']
                if 'device_password' in dev:
                    spotpasswd = dev['device_password']
                else:
                    spotpasswd = ''  # no password support yet
                registration = dev['registration']
                aprsid = dev['device_aprsid']  # APRS ID assigned
                reg = aprsid
                flarmid = getognflarmid(
                    registration
                )  # get the flarmid for ogn ddb in case of device match
                if flarmid == "NOFlarm":  # in case of no registration on the DDB
                    print(">>>> Reg", aprsid, "spotID", spotID, "FlarmID",
                          flarmid, "Registration", registration, "<<<<<<\n")
                    flarmid = aprsid  # just print warning and use the registration

                jsondata = spotgetdata(spotID, spotpasswd, prt)
                spotpos = {"spotpos": []}  # init the dict
                found = spotgetaircraftpos(jsondata,
                                           spotpos,
                                           ttime,
                                           reg,
                                           flarmid,
                                           prt=False)
                if found:
                    foundone = True
                if prt:
                    print(spotpos)
                if aprspush:
                    spotaprspush(spotpos,
                                 prt)  # and push the data into the APRS
    if foundone:
        now = datetime.utcnow()
        # number of second until beginning of the day of 1-1-1970
        td = now - datetime(1970, 1, 1)
        ts = int(td.total_seconds())  # as an integer
        return (ts)  # return TTIME for next call
    else:
        return (ttime)  # keep old value
Ejemplo n.º 8
0
def captfindpos(ttime, conn, prt=False, store=True, aprspush=False):

    onefound = False
    captLOGIN = config.CAPTURSlogin  # login of the control capture account
    captPASSWD = config.CAPTURSpasswd
    curs = conn.cursor()  # set the cursor for storing the fixes
    cursG = conn.cursor()  # set the cursor for searching the devices
    # get all the devices with CAPT
    cursG.execute(
        "select id, active, flarmid, registration from TRKDEVICES where devicetype = 'CAPT'; "
    )
    rowgall = cursG.fetchall(
    )  # look for that registration on the OGN databasea
    for rowg in rowgall:

        captID = rowg[0].lstrip()  # registration to report
        active = rowg[1]  # if active or not
        flarmid = rowg[2]  # Flamd id to be linked
        registration = rowg[3]  # registration id to be linked
        if active == 0:
            continue  # if not active, just ignore it
        if flarmid == None or flarmid == '':  # if flarmid is not provided
            # get it from the registration
            flarmid = getflarmid(conn, registration)
        else:
            chkflarmid(flarmid)

            # build the URL to call to the CAPTURS server
# http://api.capturs.com/device/1AC32E/position/from/1484053861/to/1484917861/limit/1?login=myLogin&password=myPassword
        url = "http://api.capturs.com/device/"+captID+"/position/from/" + \
            str(ttime)+"?login="******"&password="******"URL:", url)
        captpos = {"captpos": []}  # init the dict
        # get the JSON data from the CAPT server
        jsondata = captgetapidata(url)
        if prt:  # if we require printing the raw data
            j = json.dumps(jsondata, indent=4)  # convert JSON to dictionary
            print(j)
            # find the gliders since TTIME
        found = captgetaircraftpos(jsondata,
                                   captpos,
                                   ttime,
                                   captID,
                                   flarmid,
                                   prt=False)
        if found:
            onefound = True
        if prt:
            print(captpos)
        if store:
            captstoreitindb(captpos, curs, conn)  # and store it on the DDBB
        if aprspush:
            captaprspush(captpos, prt=prt)  # and push the date thru the APRS

    if onefound:
        now = datetime.utcnow()
        # number of second until beginning of the day of 1-1-1970
        td = now - datetime(1970, 1, 1)
        ts = int(td.total_seconds())  # as an integer
        return (ts)  # return TTIME for next call
    else:
        return (ttime)  # if not found, just return the same time