📄 placelabstumblerlogspotter.java
字号:
if (m==null) { if (!beaconsAvailable && prevGPSMeas != null) { return new StumblerMeasurement(prevGPSMeas.getTimestamp(), prevGPSMeas.getPosition()); } else { return null; } } /* the measurement is either a GPSMeasurement or a BeaconMeasurement */ if (m instanceof BeaconMeasurement) { BeaconMeasurement meas = (BeaconMeasurement) m; Coordinate pos; if (prevGPSMeas != null) { if (useThresholding) { pos = (meas.getTimestamp() - prevGPSMeas.getTimestamp() > gpsThreshold ? Types.newCoordinate() : prevGPSMeas.getPosition()); } else { pos = prevGPSMeas.getPosition(); prevGPSMeas = null; } } else { pos = Types.newCoordinate(); } beaconsAvailable = true; return new StumblerMeasurement(meas.getTimestamp(), pos, meas.getReadings()); } else { GPSMeasurement gpsMeas = (GPSMeasurement) m; if (beaconsAvailable==true) { // there were beacons available between this GPS reading and the previous one beaconsAvailable = false; prevGPSMeas = gpsMeas; return getThresholdedMeasurement(useThresholding); } else { // there were no beacons available between this GPS reading // and the previous one prevGPSMeas = gpsMeas; return new StumblerMeasurement(prevGPSMeas.getTimestamp(), prevGPSMeas.getPosition()); } } } private Coordinate interpolateGPS(long thisTimestamp) { if (prevGPSMeas==null) return Types.newCoordinate(); if (nextGPSMeas==null) return prevGPSMeas.getPosition().createClone(); double frac = ((double)(thisTimestamp - prevGPSMeas.getTimestamp()))/ ((double)(nextGPSMeas.getTimestamp()-prevGPSMeas.getTimestamp())); double lat = ((TwoDCoordinate)prevGPSMeas.getPosition()).getLatitude() + frac * (((TwoDCoordinate) nextGPSMeas.getPosition()).getLatitude() - ((TwoDCoordinate) prevGPSMeas.getPosition()).getLatitude()); double lon = ((TwoDCoordinate)prevGPSMeas.getPosition()).getLongitude() + frac * (((TwoDCoordinate) nextGPSMeas.getPosition()).getLongitude() - ((TwoDCoordinate) prevGPSMeas.getPosition()).getLongitude()); return new TwoDCoordinate(lat, lon); } private Measurement getInterpolatedMeasurement() { if (cache.isEmpty()) { gatherReadingsForInterpolation(); if (cache.isEmpty()) return null; GPSMeasurement saved = prevGPSMeas; if (prevGPSMeas==null && nextGPSMeas==null) { Measurement first = (Measurement)cache.elementAt(0); if (first instanceof GPSMeasurement) { prevGPSMeas = (GPSMeasurement) first; cache.removeElementAt(0); } } else { prevGPSMeas = nextGPSMeas; } Measurement last = (Measurement)cache.elementAt(cache.size() - 1); if (last instanceof GPSMeasurement) { nextGPSMeas = (GPSMeasurement) last; cache.removeElementAt(cache.size() - 1); } else { /* extrapolate from the previous pair of GPS readings */ GPSMeasurement tmp = prevGPSMeas; prevGPSMeas = saved; nextGPSMeas = new GPSMeasurement(last.getTimestamp(), interpolateGPS(last.getTimestamp())); prevGPSMeas = tmp; } if (cache.isEmpty()) { // there were no BeaconMeasurements in between these two GPS measurements return new StumblerMeasurement(prevGPSMeas.getTimestamp(), prevGPSMeas.getPosition()); } } /* grab the next BeaconMeasurement from the cache */ BeaconMeasurement meas = (BeaconMeasurement)cache.elementAt(0); cache.removeElementAt(0); Coordinate pos = interpolateGPS(meas.getTimestamp()); return new StumblerMeasurement(meas.getTimestamp(), pos, meas.getReadings()); } private void gatherReadingsForInterpolation() { /* cache everything until the next GPS line */ while (true) { Measurement m = null; try { m = getNextMeasurement(); } catch (SpotterException ex) { ex.printStackTrace(); continue; } if (m==null) return; if (m instanceof GPSMeasurement && (prevGPSMeas != null || nextGPSMeas != null || !cache.isEmpty())) { cache.addElement(m); return; } cache.addElement(m); } } public static boolean isValidFile(String file) { try { InputStream is = new FileInputStream(file); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line = br.readLine(); br.close(); is.close(); int version = LogWriter.getLogVersion(line); if(version >= 2) { // log versions 2 and greater have a preamble on the // first line, all others have data on the first line return true; } else { return false; } } catch (IOException ex) { return false; } } // This main will convert a placelab log format into netwstumbler's old // format public static void main(String args[]) { Cmdline.parse(args); String log = Cmdline.getArg("log"); String out = Cmdline.getArg("outputfile"); try { PlacelabStumblerLogSpotter ps = new PlacelabStumblerLogSpotter(Cmdline.getArg("log")); String outputfile = Cmdline.getArg("outputfile"); PrintWriter pw = (outputfile != null ? new PrintWriter(new BufferedWriter(new FileWriter(outputfile,false))) : new PrintWriter(System.out)); try { ps.open(); } catch (SpotterException e1) { e1.printStackTrace(); return; } boolean headerPrinted = false; Calendar c = Calendar.getInstance(new SimpleTimeZone(0, "GMT")); while (true) { StumblerMeasurement sm=null; try { sm = (StumblerMeasurement)ps.getMeasurement(); } catch (SpotterException e2) { e2.printStackTrace(); continue; } if(sm == null) { break; } Logger.println(Integer.toString(sm.numberOfReadings()), Logger.HIGH); for (int i = 0; i < sm.numberOfReadings(); i++) { WiFiReading wr = (WiFiReading)sm.getReading(i); Date d = new Date(sm.getTimestamp()); c.setTime(d); if (!headerPrinted) { headerPrinted = true; pw.println("# $Creator: Network Stumbler Version 0.3.30"); pw.println("# $Format: wi-scan with extensions"); pw.println("# Latitude\tLongitude\t( SSID )\tType\t( BSSID )\tTime (GMT)\t[ SNR Sig Noise ]\t# ( Name )\tFlags\tChannelbits\tBcnIntvl"); pw.println("# $DateGMT: " + c.get(Calendar.YEAR) + "-" + blah(c.get(Calendar.MONTH) + 1) + "-" + blah(c.get(Calendar.DAY_OF_MONTH))); } String sss; if (wr.getRssi() == 0) { sss = "[ 0 0 0]"; } else { sss = "[ 10 " + (-wr.getRssi()) + " " + ((-wr.getRssi())-10) + " ]"; } pw.println( //((TwoDCoordinate)sm.getPosition()).getLatitudeAsString() // + "\t" + //((TwoDCoordinate)sm.getPosition()).getLongitudeAsString() // + "\t" + jingoLat(((TwoDCoordinate)sm.getPosition()).getLatitude()) + "\t" + jingoLon(((TwoDCoordinate)sm.getPosition()).getLongitude()) + "\t" + "( " + wr.getSsid() + " )" + "\t" + (wr.getIsInfrastructure() ? "BBS" : "adhoc") + "\t( " + wr.getBssid() + " )" + "\t" + blah(c.get(Calendar.HOUR_OF_DAY)) + ":" + blah(c.get(Calendar.MINUTE)) + ":" + blah(c.get(Calendar.SECOND)) + " (GMT)" + "\t" + sss + "\t" + "# ( )" + "\t" + "0051" + "\t" + "0040" + "\t" + "0");// N 55.8614150 W 4.2486717 ( bcwgroup ) BBS ( 00:41:05:cc:8d:9f ) 08:40:40// (GMT) [ 0 0 0 ] # ( ) 0051 0040 0 } pw.flush(); } } catch (IOException e) { System.err.println("error: " + e.getMessage()); } } public static String jingoLat(double d) { if(Double.isNaN(d)) { return "N " + "0.0"; } if (d < 0) { return "S " + NumUtil.doubleToString(-d, 7); } else { return "N " + NumUtil.doubleToString(d, 7); } } public static String jingoLon(double d) { if(Double.isNaN(d)) { return "E " + "0.0"; } if (d < 0) { return "W " + NumUtil.doubleToString(-d, 7); } else { return "E " + NumUtil.doubleToString(d, 7); } } public static String blah(int i) { if (i >=10) { return "" + i; } else { return "0" + i; } } public static void testmain(String args[]) throws SpotterException { PlacelabStumblerLogSpotter s = new PlacelabStumblerLogSpotter("/home/yatin/tmp/seattle.log"); s.setGPSMethod(GPS_THRESHOLD, 2000); s.open(); for (int i=0; i < 3; i++) { StumblerMeasurement m = (StumblerMeasurement)s.getMeasurement(); System.out.println("Measurement "+(i+1)+" has "+m.numberOfReadings()+" readings"); } s.close(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -