⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ns1reader.java

📁 这是一款基于PlaceLab软件开发的导航系统中间件的客户端程序.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            // source            int source_id = readInt(in, buff, "encounter source id");             pos += LittleEndianConsts.INT_SIZE;            enc.setSource( Encounter.Source.getSourceFor( source_id ) );                        if ( ! Encounter.Source.NONE.equals( enc.getSource() ) ) {              double lat = readDouble(in, buff, "encounter lat");              pos += LittleEndianConsts.DOUBLE_SIZE;              enc.setLat( lat );                            double lon = readDouble(in, buff, "encounter long");              pos += LittleEndianConsts.DOUBLE_SIZE;              enc.setLon( lon );                            double alt = readDouble(in, buff, "encounter alt");              pos += LittleEndianConsts.DOUBLE_SIZE;              enc.setAlt( alt );                            // sat count              int satc = readInt(in, buff, "encounter sat count");              pos += LittleEndianConsts.INT_SIZE;              enc.setSatCount( satc );                            double speed = readDouble(in, buff, "encounter speed");              pos += LittleEndianConsts.DOUBLE_SIZE;              enc.setSpeed( speed );                            double track = readDouble(in, buff, "encounter track");              pos += LittleEndianConsts.DOUBLE_SIZE;              enc.setTrack( track );                            double var = readDouble(in, buff, "encounter variation");              pos += LittleEndianConsts.DOUBLE_SIZE;              enc.setVariation( var );                            double hdop = readDouble(in, buff, "encounter hdop");              pos += LittleEndianConsts.DOUBLE_SIZE;              enc.setHdop( hdop );            }                      if ( ( enc.getSignal() == MIN_DBM ) && ( prevsig == MIN_DBM ) ) {              continue;                                   }                        prevsig = enc.getSignal();                        if ( ( enc.getLat() != 0 ) && ( enc.getLon() != 0 ) &&                  ( enc.getLat() == ap.getBestLat() ) && ( enc.getLon() == ap.getBestLon() ) ) {              if ( ap.getBestGnr() < ( enc.getSignal() - enc.getNoise() ) ) {                ap.setBestGnr( enc.getSignal() - enc.getNoise() );              }            }                      ap.addEncounter( enc );            encount--;          }                  }              if ( version >= 4 ) {          // read the name           StringInfo nameInfo = readString(in, buff, "name");          String name = nameInfo.str;          pos += nameInfo.bytes_read;          ap.setName( name );        }              if ( version >= 7 ) {          // channels          int mask = readInt(in, buff, "ap low channel mask");          pos += LittleEndianConsts.INT_SIZE;          long channels = mask;                    mask = readInt(in, buff, "ap high channel mask");           pos += LittleEndianConsts.INT_SIZE;                    channels |= (mask << 32);                    ap.setChannels( channels );                     int lastchan = readInt(in, buff, "ap last channel");           pos += LittleEndianConsts.INT_SIZE;          ap.setLastChannel( lastchan );        }                if ( version >= 8 ) {          // ip addr          int ipaddr = readInt(in, buff, "ap IP");          pos += LittleEndianConsts.INT_SIZE;          // throw it away.        }                if ( version >= 11 ) {            //  min_sig, max_noise, rate, ip_subnet, ip_mask            int min_sig = readInt(in, buff, "min sig");            pos += LittleEndianConsts.INT_SIZE;            // throw it away.                        int other_max_noise = readInt(in, buff, "max noise");            pos += LittleEndianConsts.INT_SIZE;            // throw it away.            int data_rate = readInt(in, buff, "data rate"); // in 100kbps units            pos += LittleEndianConsts.INT_SIZE;            // throw it away.                        int ip_sub = readInt(in, buff, "ip subnet");            pos += LittleEndianConsts.INT_SIZE;            // throw it away.            int ip_mask = readInt(in, buff, "ip mask");            pos += LittleEndianConsts.INT_SIZE;            // throw it away.                    }                if ( version >= 12 ) {            int ap_flags = readInt(in, buff, "ap flags");            pos += LittleEndianConsts.INT_SIZE;            // throw it away.                        // some extra data.            int info_elem_len = readInt(in, buff, "802.11 info elements len");            pos += LittleEndianConsts.INT_SIZE;            // eat the 802.11 information elements:            for ( long n = info_elem_len; n > 0 ; ) {                long lrv = in.skip( n );                if ( lrv > 0 ) {                    n -= lrv;                 } else {                    throw new DataFormatException("couldn't read 802.11 info elements, got "+                                                  rv+" of "+info_elem_len);                }            }        }                        ns1.addAP( ap );        count--;      }    } catch ( DataFormatException ex ) {      err.setError( true );      err.setReason( ex.toString() );      err.setOffset( pos );    }    return ns1;  }  /**   * read a CArchive short from in.   * will always consume LittleEndianConsts.SHORT_SIZE bytes.   *   * @param in the stream to read from   * @param buff the buffer to use for reading   * @param name the name of the field for excepting   * @return a short   * @throws IOException for problems with in   * @throws DataFormatException if an short cannot be read.   */  private static short readShort( InputStream in, byte[] buff, String name)     throws IOException, DataFormatException {    int rv = in.read( buff, 0, LittleEndianConsts.SHORT_SIZE );    if ( rv != LittleEndianConsts.SHORT_SIZE ) {      throw new DataFormatException("couldn't read "+name+", got "+rv+" of "+LittleEndianConsts.SHORT_SIZE);    }    return LittleEndian.getShort( buff, 0 );  }    /**   * read a CArchive int from in.   * will always consume LittleEndianConsts.INT_SIZE bytes.   *   * @param in the stream to read from   * @param buff the buffer to use for reading   * @param name the name of the field for excepting   * @return an int   * @throws IOException for problems with in   * @throws DataFormatException if an int cannot be read.   */  private static int readInt( InputStream in, byte[] buff, String name)     throws IOException, DataFormatException {    int rv = in.read( buff, 0, LittleEndianConsts.INT_SIZE );    if ( rv != LittleEndianConsts.INT_SIZE ) {      throw new DataFormatException("couldn't read "+name+", got "+rv+" of "+LittleEndianConsts.INT_SIZE);    }    return LittleEndian.getInt( buff, 0 );  }  /**   * read a CArchive double from in.   * will always consume LittleEndianConsts.DOUBLE_SIZE bytes.   *   * @param in the stream to read from   * @param buff the buffer to use for reading   * @param name the name of the field for excepting   * @return a double    * @throws IOException for problems with in   * @throws DataFormatException if a double cannot be read.   */  private static double readDouble( InputStream in, byte[] buff, String name)    throws IOException, DataFormatException {    int rv = in.read( buff, 0, LittleEndianConsts.DOUBLE_SIZE );    if ( rv != LittleEndianConsts.DOUBLE_SIZE ) {      throw new DataFormatException("couldn't read "+name+", got "+rv+" of "+LittleEndianConsts.DOUBLE_SIZE);    }    return LittleEndian.getDouble( buff, 0 );  }  /**   * read a CArchive String from in.   * @param in the stream to read from   * @param buff the buffer to use for reading   * @param name the name of the field for excepting   * @return a StringInfo with the string and count of bytes consumed.   * @throws IOException for problems with in   * @throws DataFormatException if a String cannot be read.   */  private static StringInfo readString(InputStream in, byte[] buff, String name)     throws IOException, DataFormatException {    int len = in.read();    String result = null;    int rv = -1;    int offset = 0;    if ( 255 == len ) { // wide string indicator?      short bom = readShort( in, buff, name );      String enc = "UTF-16LE";      if        ( (short)0xfffe == bom ) {         enc = "UTF-16LE";      } else if ( (short)0xfeff == bom ) {         enc = "UTF-16BE";      } else {         throw new DataFormatException( "unknown byte order mark:" + bom );      }            len = in.read(); // length in chars      len *= 2;        // 2 byte encoding      offset = 4;      // 4 bytes lost to indicator, byte order and length.            rv = in.read( buff, 0, len );      if ( rv != len ) {        throw new DataFormatException("couldn't read "+name+" (wrong len, wanted "+len+", read"+rv+")");      }      result = new String(buff, 0, rv, "UTF-16LE");        } else {       offset = 1; // 1 byte lost to length      rv = in.read( buff, 0, len );      if ( rv != len ) {        throw new DataFormatException("couldn't read "+name+" (wrong len, wanted "+len+", read"+rv+")");      }            result = new String(buff, 0, rv, "ISO-8859-1");    }    return new StringInfo( result, rv + offset );  }    /** additional information on strings read in. */  static class StringInfo {     /** the string read in */     final String str;     /** the number of bytes consumed reading in str. */     final int bytes_read;     /**      * build a StringInfo.      * @param string the string      * @param byte_count the byte count     */     StringInfo( String string, int byte_count ) {        str = string;        bytes_read = byte_count;     }  }  /**   * From org.apache.soap.encoding.Hex   * [Private] Convert the specified value (0 .. 15) to the corresponding   * hexadecimal digit.   *   * @param value Value to be converted   */  private static char convertDigit(int value) {        value &= 0x0f;    if (value >= 10)      return ((char) (value - 10 + 'a'));    else      return ((char) (value + '0'));  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -