def main(self):
     #messageroot = Tk()
     #self.banishRoot()
     #self.root.withdraw()
     while 1:
         #mainloop
         packet = self.getNewPacket()
         try:
             p = fap.Packet(packet)
         except fap.DecodeError:
             gpscompatible = decodeTNC.determineCompatability(packet,self.d710Signs)
             if gpscompatible:
                 latlong = decodeTNC.latlong(packet)
                 self.writetrack("d710",latitude=latlong[1],longitude=latlong[0])
                 print "Added D710 Track"
             else:
                 print "No D-Track Added"
             continue
         except AttributeError:
             print "Error in packet"
             continue
         compatible = self.checkCompatibility(p)
         if compatible:
             self.writetrack("balloon",latitude=p.latitude,longitude=p.longitude,altitude=p.altitude)
             print "Added Balloon Track: "+str(p.src_callsign)
         else:
             print "No B-Track Added"
Example #2
0
 def main(self):
     #messageroot = Tk()
     #self.banishRoot()
     #self.root.withdraw()
     while 1:
         #mainloop
         packet = self.getNewPacket()
         try:
             p = fap.Packet(packet)
         except fap.DecodeError:
             gpscompatible = decodeTNC.determineCompatability(
                 packet, self.d710Signs)
             if gpscompatible:
                 latlong = decodeTNC.latlong(packet)
                 self.writetrack("d710",
                                 latitude=latlong[1],
                                 longitude=latlong[0])
                 print "Added D710 Track"
             else:
                 print "No D-Track Added"
             continue
         except AttributeError:
             print "Error in packet"
             continue
         compatible = self.checkCompatibility(p)
         if compatible:
             self.writetrack("balloon",
                             latitude=p.latitude,
                             longitude=p.longitude,
                             altitude=p.altitude)
             print "Added Balloon Track: " + str(p.src_callsign)
         else:
             print "No B-Track Added"
 def main(self):
     """Main function and loop"""
     ##Uncomment these lines to remove the root window for running without a GUI
     ##    Note, this may be necessary for running on Cygwin or other emulators without Tkinter.
     #messageroot = Tk()
     #self.banishRoot()
     #self.root.withdraw()
     while 1:
         #Main Loop that runs continuously. When mainloop terminates, 
         #     the applicatoin GUI will be freed up for another run
         #For each update cycle, begin by getting a new packet
         packet = self.getNewPacket()
         try:
             #Pass the packet to FAP for parsing (accepts MicE, but not D710)
             p = fap.Packet(packet)
         except fap.DecodeError:
             #A Decode Error will occur whenever FAP is unable to parse the packet
             #In this case, check to see if the packet is a GPRMC or PKWDPOS packet
             gpscompatible = decodeTNC.determineCompatability(packet,self.d710Signs)
             if gpscompatible:
                 #If it is a D710 packet, parse it.
                 latlong = decodeTNC.latlong(packet) #returned as (latitude,longitude)
                 if self.d710checkvar.get()==1:
                     #If we are plotting D710 tracks, Plot it on Google Earth
                     self.writetrack("d710",latitude=latlong[1],longitude=latlong[0],log=True)
                     print "Added D710 Track"
             else:
                 #This will print whenever a corrupted packet or command line is encountered
                 print "No D-Track Added"
             continue
         except AttributeError:
             print "Error in packet"
             continue
         #Check to see if the current packet is being tracked
         compatible = self.checkCompatibility(p)
         if compatible == True:                
             #Packets with True compatibility are Balloon packets
             if self.ballooncheckvar.get()==1:                
                 #Plot the coordinate on Google Earth
                 self.writetrack("balloon",latitude=p.latitude,longitude=p.longitude,altitude=int(p.altitude*3.28084),log=True)
                 print "Added Balloon Track: "+str(p.src_callsign)
                 if self.predictioncheckvar.get()==1:
                     #If predictions are currently enabled, run one now.
                     self.runPrediction()                
         elif compatible == "Chase":
             #Recently added, Chase team tracks for D710's and VX-8R's in Chase vehicles
             #   Note, all incoming coordinates will be plotted on the same line, so only track vehicles in the same convoy
             #   This can also be used in a pinch to track 2 balloons
             self.writetrack(p.src_callsign,latitude=p.latitude,longitude=p.longitude,altitude=int(p.altitude*3.28084),log=True)
             print "Added Chase Team: "+str(p.src_callsign)
         else:
             #This is printed for any callsigns not currently being tracked
             print "No B-Track Added: "+str(p.src_callsign)
         #Dump all print messages to the stdout
         sys.stdout.flush()
Example #4
0
    def _main(self):
        with open(self._filename, "r") as fp:
            while 1:
                if self._playing:
                    new_line = fp.readline()
                    if new_line.startswith("# "):
                        timestamp = int(new_line.split(' ')[1])
                        message = fp.readline()
                        if not message:
                            break
                        to_wait = timestamp - self._current_time
                        if to_wait < 0 or self._current_time == 0:
                            to_wait = 0
                        time.sleep(to_wait // self._speed)
                        self._current_time = timestamp
                        print message

                        # From D710.py:
                        try:
                            # Pass the packet to FAP for parsing (accepts MicE, but not D710)
                            p = fap.Packet(message)
                            if p.altitude:
                                point = helper.Point(time=timestamp, altitude=int(p.altitude * 3.28084),
                                                     latitude=p.latitude, longitude=p.longitude)
                                self._harbor.newPoint(p.src_callsign, point)
                        except fap.DecodeError:
                            # A Decode Error will occur whenever FAP is unable to parse the packet
                            # In this case, check to see if the packet is a GPRMC or PKWDPOS packet
                            gpscompatible = decodeTNC.determineCompatability(message, ["$PKWDPOS", "$GPRMC"])
                            if gpscompatible:
                                # If it is a D710 packet, parse it.
                                latlong = decodeTNC.latlong(message)  # returned as (latitude,longitude)
                                # If we are plotting D710 tracks, Plot it on Google Earth
                                point = helper.Point(time=timestamp, altitude=0, latitude=latlong[1],
                                                     longitude=latlong[0])
                                self._harbor.newPoint("D710", point)
                            continue
                        except AttributeError:
                            print "Error in packet"
                            continue
Example #5
0
    def main(self):
        try:
            savedtime = 0
            if self.localonly == False:
                server = socket.socket()
                server.connect((self.ip, self.port))
            else:
                if os.name == "nt":
                    filepath = os.path.expanduser("~") + "\\tnclogs\\tnc.log"
                    print filepath
                elif os.name == "posix":
                    filepath = os.path.expanduser("~/Documents/tnc.log")
                else:
                    print "UNKNOWN OPERATING SYSTEM. GET A LIFE."
                f = open(filepath)
                savedtime = os.stat(filepath).st_mtime
            print "Successfully Connected"
            while not done:
                incoming = ""
                if self.localonly == True:
                    time = os.stat(filepath).st_mtime
                    print "Initial " + str(time)
                    while time == savedtime:
                        time = os.stat(filepath).st_mtime
                    ##                                        print time
                    savedtime = time
                    f.close()
                    f = open(filepath, "r")
                    print "Retrieving data"
                    # find last line
                    allLines = f.readlines()
                    lastline = allLines[len(allLines) - 1]
                    print lastline
                    try:
                        compatible, listento = decodeTNC.determineCompatability(lastline, self.acceptedSigns)
                        if compatible == True:
                            if "PKWDPOS" in listento:
                                listento = "d710"
                            lon, lat = decodeTNC.latlong(lastline)
                            incoming = {listento: {"latitude": lat, "longitude": lon}}
                            print incoming

                    except TypeError:
                        print "Unsolved TypeError, sucks to be you!"
                ##                                    except TypeError:

                else:
                    incoming = server.recv(1000)
                    if incoming == "":
                        break
                    ##                                print incoming
                    try:
                        incoming = json.loads(incoming)
                    except ValueError:
                        print "BAD JSON"
                        print incoming
                        continue
                    print incoming
                if incoming != "":
                    for sign in self.acceptedSigns:
                        write = False
                        for callsign in incoming:
                            if sign.lower() in callsign.lower():
                                write = True
                                ##                                                        print "Found Balloon Signature"
                                afile = "Balloon Track.kml"
                            elif "d710" in callsign.lower():
                                write = True
                                ##                                                        print "Found D710 Signature"
                                afile = "D710 Track.kml"
                            elif "port change notification" in callsign.lower():
                                newport = incoming[callsign]
                                server.close()
                                print "Closing old port"
                                del (server)
                                server = socket.socket()
                                server.connect((self.ip, newport))
                                print "Opened new port: " + str(newport)
                            if write == True:
                                try:
                                    lat = incoming[callsign]["latitude"]
                                    lon = incoming[callsign]["longitude"]
                                    print lat
                                    print lon
                                    writetoKML.writeonce((str(lon) + "," + str(lat)), afile)
                                except KeyError:
                                    print "No Latitude or Longitude"
                        if write == True:
                            break

        except KeyboardInterrupt:
            if self.localonly != True:
                server.close()
                print "Closed"

        except socket.herror:
            print "Invalid address"
        finally:
            if self.localonly != True:
                server.close()
                print "Closed"
Example #6
0
def main(h, com=None):
    while 1:
        if os.name == "nt":  # NT is the special name for Windows
            # The best way to determine what the port is, is to open Device manager and look under COM
            # comport = raw_input("What is the name of the COM Port? (COM1, etc) ")
            comport = com
            try:
                ser = serial.Serial(comport)
            except IndexError:
                print "Serial Device not connected"  # Again, if this isn't working, make sure its plugged in
            try:
                filepath = os.path.join('tnclogs', 'tnc.log')
                log = open(filepath, "a")
            except IOError:  # This will only ever have problems if the folder defined doesn't exist
                os.mkdir('tnclogs')
                log = open(os.path.join('tnclogs', 'tnc.log'), "a")
            log.close()
        else:
            if os.name != "posix":  # Posix is the special name for Unix (Mac)
                print "Unknown operating system"
            try:
                try:
                    ser = serial.Serial(
                        "/dev/tty.usbserial")  # Which of these works will determine on which drivers you have
                except serial.serialutil.SerialException:
                    ser = serial.Serial(glob("/dev/tty.PL2303-*")[0])
            except:
                print "Error Connecting to Device"  # If you get this, either the device is not responding or is not plugged in
                import sys
                sys.exit()
            filepath = "tnclogs/tnc.log"
            log = open(filepath, "a")  # This opens the log, change it to whichever file you like
            log.close()
        # This will run the main startup sequence, which consists of sending a large amount of gibberish to the D710
        run_d710_tnc_startup(ser)

        try:  # This entire try statement is a complicated way of pulling data
            while 1:  # off of the D710 and attaching a time stamp to it in the file
                log = open(filepath, "a")
                got = ser.read()
                out = ""
                while got != "\r":
                    out += got
                    got = ser.read()
                if out != "":
                    currentTimestamp = "# " + str(int(round(time.time()))) + datetime.datetime.now().strftime(
                        " %a %b %d %H:%M:%S %Z %Y")
                    print currentTimestamp
                    print out
                    log.write(currentTimestamp + "\n")
                    log.write(out + "\n")
                    log.flush()
                    log.close()
                    try:
                        # Pass the packet to FAP for parsing (accepts MicE, but not D710)
                        p = fap.Packet(out)
                        if p.altitude:
                            point = helper.Point(time=currentTimestamp, altitude=int(p.altitude * 3.28084),
                                                 latitude=p.latitude, longitude=p.longitude)
                            h.newPoint(p.src_callsign, point)
                    except fap.DecodeError:
                        # A Decode Error will occur whenever FAP is unable to parse the packet
                        # In this case, check to see if the packet is a GPRMC or PKWDPOS packet
                        gpscompatible = decodeTNC.determineCompatability(out, ["$PKWDPOS", "$GPRMC"])
                        if gpscompatible:
                            # If it is a D710 packet, parse it.
                            latlong = decodeTNC.latlong(out)  # returned as (latitude,longitude)
                            if latlong is None:
                                continue
                            # If we are plotting D710 tracks, Plot it on Google Earth
                            point = helper.Point(time=currentTimestamp, altitude=0, latitude=latlong[1],
                                                 longitude=latlong[0])
                            h.newPoint("D710", point)
                        continue
                    except AttributeError:
                        print "Error in packet"
                        continue

        except serial.SerialException:  # In case off failure, or even a keyboard interrupt, this will shut down the port.
            log.close()
            ser.close()
Example #7
0
 def main(self):
     """Main function and loop"""
     ##Uncomment these lines to remove the root window for running without a GUI
     ##    Note, this may be necessary for running on Cygwin or other emulators without Tkinter.
     #messageroot = Tk()
     #self.banishRoot()
     #self.root.withdraw()
     while 1:
         #Main Loop that runs continuously. When mainloop terminates,
         #     the applicatoin GUI will be freed up for another run
         #For each update cycle, begin by getting a new packet
         packet = self.getNewPacket()
         try:
             #Pass the packet to FAP for parsing (accepts MicE, but not D710)
             p = fap.Packet(packet)
         except fap.DecodeError:
             #A Decode Error will occur whenever FAP is unable to parse the packet
             #In this case, check to see if the packet is a GPRMC or PKWDPOS packet
             gpscompatible = decodeTNC.determineCompatability(
                 packet, self.d710Signs)
             if gpscompatible:
                 #If it is a D710 packet, parse it.
                 latlong = decodeTNC.latlong(
                     packet)  #returned as (latitude,longitude)
                 if self.d710checkvar.get() == 1:
                     #If we are plotting D710 tracks, Plot it on Google Earth
                     self.writetrack("d710",
                                     latitude=latlong[1],
                                     longitude=latlong[0],
                                     log=True)
                     print "Added D710 Track"
             else:
                 #This will print whenever a corrupted packet or command line is encountered
                 print "No D-Track Added"
             continue
         except AttributeError:
             print "Error in packet"
             continue
         #Check to see if the current packet is being tracked
         compatible = self.checkCompatibility(p)
         if compatible == True:
             #Packets with True compatibility are Balloon packets
             if self.ballooncheckvar.get() == 1:
                 #Plot the coordinate on Google Earth
                 self.writetrack("balloon",
                                 latitude=p.latitude,
                                 longitude=p.longitude,
                                 altitude=int(p.altitude * 3.28084),
                                 log=True)
                 print "Added Balloon Track: " + str(p.src_callsign)
                 if self.predictioncheckvar.get() == 1:
                     #If predictions are currently enabled, run one now.
                     self.runPrediction()
         elif compatible == "Chase":
             #Recently added, Chase team tracks for D710's and VX-8R's in Chase vehicles
             #   Note, all incoming coordinates will be plotted on the same line, so only track vehicles in the same convoy
             #   This can also be used in a pinch to track 2 balloons
             self.writetrack(p.src_callsign,
                             latitude=p.latitude,
                             longitude=p.longitude,
                             altitude=int(p.altitude * 3.28084),
                             log=True)
             print "Added Chase Team: " + str(p.src_callsign)
         else:
             #This is printed for any callsigns not currently being tracked
             print "No B-Track Added: " + str(p.src_callsign)
         #Dump all print messages to the stdout
         sys.stdout.flush()