Пример #1
0
 protected String getStringProperty(Device device, String key, String dft) {
   DCServerConfig dcs =
       (device != null) ? DCServerFactory.getServerConfig(device.getDeviceCode()) : null;
   String prop = null;
   if (dcs != null) {
     prop = dcs.getStringProperty(key, dft);
     Print.logInfo("DCServerConfig property '" + key + "' ==> " + prop);
     if (StringTools.isBlank(prop) && RTConfig.hasProperty(key)) {
       Print.logInfo("(RTConfig property '" + key + "' ==> " + RTConfig.getString(key, "") + ")");
     }
   } else {
     prop = RTConfig.getString(key, dft);
     Print.logInfo("RTConfig property '" + key + "' ==> " + prop);
   }
   return prop;
 }
Пример #2
0
 /** ** Gets the scrambled Base64 alphabet ** @return The scrambled Base64 alphabet */
 private static char[] getBase64Alphabet() {
   if (Base64Alphabet == null) {
     BigInteger seed = RTConfig.getBigInteger(PROP_uriArgScrambleSeed, DefaultScrambleSeed);
     Base64Alphabet = Base64.shuffleAlphabet(seed);
     for (int i = 0; i < Base64Alphabet.length; i++) {
       if (Base64Alphabet[i] == '+') {
         Base64Alphabet[i] = '-';
       } else if (Base64Alphabet[i] == '/') {
         Base64Alphabet[i] = '_';
       }
     }
     // Print.logInfo("Base64 Alpha ["+seed+"]: "+StringTools.toStringValue(Base64Alphabet));
   }
   return Base64Alphabet;
 };
Пример #3
0
  /** ** Main entry point for testing/debugging ** @param argv Comand-line arguments */
  public static void main(String argv[]) {
    RTConfig.setCommandLineArgs(argv);

    /* decode URI argument strings */
    if (RTConfig.hasProperty(ARG_DECODE)) {
      String a = RTConfig.getString(ARG_DECODE, "");
      String s = URIArg.decodeArg(new StringBuffer(), a).toString();
      Print.sysPrintln("ASCII: " + s);
      System.exit(0);
    }

    /* encode Base64 strings */
    if (RTConfig.hasProperty(ARG_ENCODE)) {
      String s = RTConfig.getString(ARG_ENCODE, "");
      String a = URIArg.encodeArg(new StringBuffer(), s).toString();
      Print.sysPrintln("Args: " + a);
      System.exit(0);
    }

    /* RTP decode */
    if (RTConfig.hasProperty(ARG_RTPDEC)) {
      URIArg rtpUrl = new URIArg(RTConfig.getString(ARG_RTPDEC, ""));
      URIArg decUrl = rtpUrl.rtpDecode("rtp");
      Print.sysPrintln("URL: " + decUrl.toString());
      System.exit(0);
    }

    /* RTP encode */
    if (RTConfig.hasProperty(ARG_RTPENC)) {
      URIArg decUrl = new URIArg(RTConfig.getString(ARG_RTPENC, ""));
      URIArg rtpUrl = decUrl.rtpEncode("rtp");
      Print.sysPrintln("URL: " + rtpUrl.toString());
      System.exit(0);
    }

    /* no options */
    usage();
  }
Пример #4
0
  /** ** Main entry point for testing/debugging ** @param argv Comand-line arguments */
  public static void main(String argv[]) {
    RTConfig.setCommandLineArgs(argv);
    String host = RTConfig.getString(ARG_HOST, null);
    int port = RTConfig.getInt(ARG_PORT, 0);

    /* send data */
    if (RTConfig.hasProperty(ARG_SEND)) {
      if (StringTools.isBlank(host)) {
        Print.logError("Target host not specified");
        usage();
      }
      if (port <= 0) {
        Print.logError("Target port not specified");
        usage();
      }
      String dataStr = RTConfig.getString(ARG_SEND, "hello");
      byte data[] =
          dataStr.startsWith("0x") ? StringTools.parseHex(dataStr, null) : dataStr.getBytes();
      ClientSocketThread cst = new ClientSocketThread(host, port);
      try {
        cst.openSocket();
        cst.socketWriteBytes(data);
      } catch (Throwable t) {
        Print.logException("Error", t);
      } finally {
        cst.closeSocket();
      }
      System.exit(0);
    }

    /* receive data */
    if (RTConfig.hasProperty(ARG_RECEIVE)) {
      if (port <= 0) {
        Print.logError("Target port not specified");
        usage();
      }
      if (!StringTools.isBlank(host)) {
        Print.logWarn("Specified 'host' will be ignored");
      }
      Print.logError("Receive not yet implemented ...");
      System.exit(99);
    }

    /* show usage */
    usage();
  }
Пример #5
0
  public boolean insertEventData() {

    /* valid device? */
    if (this.device == null) {
      return false;
    }

    /* debug message */
    if (RTConfig.isDebugMode()) {
      Print.logDebug("Inserting EventData ...\n" + this.toString());
    }

    /* EventData key */
    String acctID = this.device.getAccountID();
    String devID = this.device.getDeviceID();
    long fixtime = this.getTimestamp();
    int statusCode = this.getStatusCode();
    EventData.Key evKey = new EventData.Key(acctID, devID, fixtime, statusCode);
    EventData evdb = evKey.getDBRecord();

    /* set EventData field values */
    if (USE_EVENTDATA_SETVALUE) {
      for (Object fldn : this.fieldValues.getPropertyKeys()) {
        if (fldn.equals(EventData.FLD_timestamp)) {
          continue; // already set above
        } else if (fldn.equals(EventData.FLD_statusCode)) {
          continue; // already set above
        }
        Object fldv = this.fieldValues.getProperty(fldn, null);
        if (fldv != null) {
          evdb.setValue((String) fldn, fldv); // attempts to use "setter" methods
        }
      }
    } else {
      if (this.hasLatitude()) {
        evdb.setLatitude(this.getLatitude());
      }
      if (this.hasLongitude()) {
        evdb.setLongitude(this.getLongitude());
      }
      if (this.hasGpsAge()) {
        evdb.setGpsAge(this.getGpsAge());
      }
      if (this.hasHDOP()) {
        evdb.setHDOP(this.getHDOP());
      }
      if (this.hasSatelliteCount()) {
        evdb.setSatelliteCount(this.getSatelliteCount());
      }
      if (this.hasSpeedKPH()) {
        evdb.setSpeedKPH(this.getSpeedKPH());
      }
      if (this.hasHeading()) {
        evdb.setHeading(this.getHeading());
      }
      if (this.hasAltitude()) {
        evdb.setAltitude(this.getAltitude());
      }
      if (this.hasInputMask()) {
        evdb.setInputMask(this.getInputMask());
      }
      if (this.hasBatteryLevel()) {
        evdb.setBatteryLevel(this.getBatteryLevel());
      }
      if (this.hasSignalStrength()) {
        evdb.setSignalStrength(this.getSignalStrength());
      }
      if (this.hasOdometerKM()) {
        evdb.setOdometerKM(this.getOdometerKM());
      }
      if (this.hasEngineHours()) {
        evdb.setEngineHours(this.getEngineHours());
      }
      if (this.hasPtoHours()) {
        evdb.setPtoHours(this.getPtoHours());
      }
      if (this.hasFuelTotal()) {
        evdb.setFuelTotal(this.getFuelTotal());
      }
      if (this.hasGeozoneID()) {
        evdb.setGeozoneID(this.getGeozoneID());
      }
    }

    /* other fields (if available) */
    if (this.otherValues != null) {
      for (String fldn : this.otherValues.keySet()) {
        if (fldn.equals(EventData.FLD_timestamp)) {
          continue;
        } else if (fldn.equals(EventData.FLD_statusCode)) {
          continue;
        }
        Object fldv = this.otherValues.get(fldn);
        if (fldv != null) {
          evdb.setValue(fldn, fldv); // attempts to use "setter" methods
        }
      }
    }

    /* insert event */
    // this will display an error if it was unable to store the event
    Print.logInfo(
        "Event     : [0x"
            + StringTools.toHexString(statusCode, 16)
            + "] "
            + StatusCodes.GetDescription(statusCode, null));
    this.device.insertEventData(
        evdb); // FLD_lastValidLatitude,FLD_lastValidLongitude,FLD_lastGPSTimestamp,FLD_lastOdometerKM
    this.eventTotalCount++;
    return true;
  }