예제 #1
0
  public AtrackProtocolDecoder(AtrackProtocol protocol) {
    super(protocol);

    longDate = Context.getConfig().getBoolean(getProtocolName() + ".longDate");

    custom = Context.getConfig().getBoolean(getProtocolName() + ".custom");
    form = Context.getConfig().getString(getProtocolName() + ".form");
    if (form != null) {
      custom = true;
    }
  }
예제 #2
0
  public QueryBuilder setObject(Object object) throws SQLException {

    Method[] methods = object.getClass().getMethods();

    for (Method method : methods) {
      if (method.getName().startsWith("get") && method.getParameterTypes().length == 0) {
        String name = method.getName().substring(3);
        try {
          if (method.getReturnType().equals(boolean.class)) {
            setBoolean(name, (Boolean) method.invoke(object));
          } else if (method.getReturnType().equals(int.class)) {
            setInteger(name, (Integer) method.invoke(object));
          } else if (method.getReturnType().equals(long.class)) {
            setLong(name, (Long) method.invoke(object));
          } else if (method.getReturnType().equals(double.class)) {
            setDouble(name, (Double) method.invoke(object));
          } else if (method.getReturnType().equals(String.class)) {
            setString(name, (String) method.invoke(object));
          } else if (method.getReturnType().equals(Date.class)) {
            setDate(name, (Date) method.invoke(object));
          } else if (method.getReturnType().equals(Map.class)) {
            if (Context.getConfig().getBoolean("database.xml")) {
              setString(name, MiscFormatter.toXmlString((Map) method.invoke(object)));
            } else {
              setString(name, MiscFormatter.toJsonString((Map) method.invoke(object)));
            }
          }
        } catch (IllegalAccessException | InvocationTargetException error) {
          Log.warning(error);
        }
      }
    }

    return this;
  }
  @Override
  protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg)
      throws Exception {

    ChannelBuffer buf = (ChannelBuffer) msg;

    buf.readUnsignedByte(); // marker
    int version = buf.readUnsignedByte();

    String imei;
    if ((version & 0x80) != 0) {
      imei = String.valueOf((buf.readUnsignedInt() << (3 * 8)) | buf.readUnsignedMedium());
    } else {
      imei = String.valueOf(imeiFromUnitId(buf.readUnsignedMedium()));
    }

    buf.readUnsignedShort(); // length

    int selector = DEFAULT_SELECTOR;
    if ((version & 0x40) != 0) {
      selector = buf.readUnsignedMedium();
    }

    Position position = new Position();
    position.setProtocol(getProtocolName());
    if (!identify(imei, channel, remoteAddress)) {
      return null;
    }

    position.setDeviceId(getDeviceId());

    int event = buf.readUnsignedByte();
    position.set(Event.KEY_EVENT, event);
    position.set("event-info", buf.readUnsignedByte());

    if ((selector & 0x0008) != 0) {
      position.setValid((buf.readUnsignedByte() & 0x40) != 0);
    } else {
      return null; // no location data
    }

    if ((selector & 0x0004) != 0) {
      buf.skipBytes(4); // snapshot time
    }

    if ((selector & 0x0008) != 0) {
      position.setTime(new Date(buf.readUnsignedInt() * 1000));
      position.setLatitude(buf.readInt() / 1000000.0);
      position.setLongitude(buf.readInt() / 1000000.0);
      position.set(Event.KEY_SATELLITES, buf.readUnsignedByte());
    }

    if ((selector & 0x0010) != 0) {
      position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
      buf.readUnsignedByte(); // maximum speed
      position.setCourse(buf.readUnsignedByte() * 2.0);
    }

    if ((selector & 0x0040) != 0) {
      position.set(Event.KEY_INPUT, buf.readUnsignedByte());
    }

    if ((selector & 0x0020) != 0) {
      position.set(Event.PREFIX_ADC + 1, buf.readUnsignedShort());
      position.set(Event.PREFIX_ADC + 2, buf.readUnsignedShort());
      position.set(Event.PREFIX_ADC + 3, buf.readUnsignedShort());
      position.set(Event.PREFIX_ADC + 4, buf.readUnsignedShort());
    }

    if ((selector & 0x8000) != 0) {
      position.set(Event.KEY_POWER, buf.readUnsignedShort() / 1000.0);
      position.set(Event.KEY_BATTERY, buf.readUnsignedShort());
    }

    // Pulse rate 1
    if ((selector & 0x10000) != 0) {
      buf.readUnsignedShort();
      buf.readUnsignedInt();
    }

    // Pulse rate 2
    if ((selector & 0x20000) != 0) {
      buf.readUnsignedShort();
      buf.readUnsignedInt();
    }

    if ((selector & 0x0080) != 0) {
      position.set("trip1", buf.readUnsignedInt());
    }

    if ((selector & 0x0100) != 0) {
      position.set("trip2", buf.readUnsignedInt());
    }

    if ((selector & 0x0040) != 0) {
      position.set(Event.KEY_OUTPUT, buf.readUnsignedByte());
    }

    if ((selector & 0x0200) != 0) {
      position.set(
          Event.KEY_RFID, (((long) buf.readUnsignedShort()) << 32) + buf.readUnsignedInt());
    }

    if ((selector & 0x0400) != 0) {
      buf.readUnsignedByte(); // Keypad
    }

    if ((selector & 0x0800) != 0) {
      position.setAltitude(buf.readShort());
    }

    if ((selector & 0x2000) != 0) {
      buf.readUnsignedShort(); // snapshot counter
    }

    if ((selector & 0x4000) != 0) {
      buf.skipBytes(8); // state flags
    }

    if ((selector & 0x80000) != 0) {
      buf.skipBytes(11); // cell info
    }

    if ((selector & 0x1000) != 0) {
      decodeEventData(event, buf);
    }

    if (Context.getConfig().getBoolean(getProtocolName() + ".can")
        && buf.readable()
        && (selector & 0x1000) != 0
        && event == EVENT_DATA) {

      decodeCanData(buf, position);
    }

    return position;
  }
예제 #4
0
 public MotionEventHandler() {
   suppressRepeated = Context.getConfig().getInteger("event.suppressRepeated", 60);
 }