Esempio n. 1
0
 /** ** Main client thread loop */
 public void run() {
   this.setRunStatus(THREAD_RUNNING);
   this.threadStarted();
   try {
     this.openSocket();
     this.inputThread = new InputThread(this.socket, this.readTimeout, this.ioThreadLock);
     this.outputThread = new OutputThread(this.socket, this.ioThreadLock);
     this.inputThread.start();
     this.outputThread.start();
     synchronized (this.ioThreadLock) {
       while (this.inputThread.isRunning() || this.outputThread.isRunning()) {
         try {
           this.ioThreadLock.wait();
         } catch (Throwable t) {
         }
       }
     }
   } catch (NoRouteToHostException nrthe) {
     Print.logInfo("Client:ControlThread - Unable to reach " + this.host + ":" + this.port);
     nrthe.printStackTrace();
   } catch (Throwable t) {
     Print.logInfo("Client:ControlThread - " + t);
     t.printStackTrace();
   } finally {
     this.closeSocket();
   }
   this.setRunStatus(THREAD_STOPPED);
   this.threadStopped();
 }
Esempio n. 2
0
 private static void usage() {
   Print.logInfo("Usage:");
   Print.logInfo("  java ... " + ClientSocketThread.class.getName() + " {options}");
   Print.logInfo("'Send' Options:");
   Print.logInfo("  -host=<host>    The destination host");
   Print.logInfo("  -port=<port>    The destination port");
   Print.logInfo("  -send=<data>    The data to send (prefix with '0x' for hex data)");
   Print.logInfo("'Receive' Options (not yet implemented):");
   Print.logInfo("  -port=<port>    The port on which to listen for incoming data");
   Print.logInfo("  -recv           Set to 'receive' mode");
   System.exit(1);
 }
Esempio n. 3
0
 protected DCServerFactory.ResultCode sendEmail(
     String frEmail, String toEmail, String subj, String body) {
   if (StringTools.isBlank(frEmail)) {
     Print.logError("'From' Email address not specified");
     return DCServerFactory.ResultCode.TRANSMIT_FAIL;
   } else if (StringTools.isBlank(toEmail) || !CommandPacketHandler.validateAddress(toEmail)) {
     Print.logError("'To' SMS Email address invalid, or not specified");
     return DCServerFactory.ResultCode.TRANSMIT_FAIL;
   } else if (StringTools.isBlank(subj) && StringTools.isBlank(body)) {
     Print.logError("Command string not specified");
     return DCServerFactory.ResultCode.INVALID_ARG;
   } else {
     try {
       Print.logInfo("SMS email: to <" + toEmail + ">");
       Print.logDebug("  From   : " + frEmail);
       Print.logDebug("  To     : " + toEmail);
       Print.logDebug("  Subject: " + subj);
       Print.logDebug("  Message: " + body);
       SendMail.send(frEmail, toEmail, null, null, subj, body, null);
       return DCServerFactory.ResultCode.SUCCESS;
     } catch (Throwable t) { // NoClassDefFoundException, ClassNotFoundException
       // this will fail if JavaMail support for SendMail is not available.
       Print.logWarn("SendMail error: " + t);
       return DCServerFactory.ResultCode.TRANSMIT_FAIL;
     }
   }
 }
Esempio n. 4
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;
 }
Esempio n. 5
0
  /* start UDP listener */
  private ServerSocketThread _startUDP(int port) throws Throwable {
    ServerSocketThread sst = null;

    /* create server socket */
    try {
      sst = new ServerSocketThread(ServerSocketThread.createDatagramSocket(port));
    } catch (Throwable t) { // trap any server exception
      Print.logException("ServerSocket error", t);
      throw t;
    }

    /* initialize */
    sst.setTextPackets(Constants.ASCII_PACKETS);
    sst.setBackspaceChar(null); // no backspaces allowed
    sst.setLineTerminatorChar(Constants.ASCII_LINE_TERMINATOR);
    sst.setIgnoreChar(Constants.ASCII_IGNORE_CHARS);
    sst.setMaximumPacketLength(Constants.MAX_PACKET_LENGTH);
    sst.setMinimumPacketLength(Constants.MIN_PACKET_LENGTH);
    sst.setIdleTimeout(TrackServer.udpTimeout_idle);
    sst.setPacketTimeout(TrackServer.udpTimeout_packet);
    sst.setSessionTimeout(TrackServer.udpTimeout_session);
    sst.setTerminateOnTimeout(Constants.TERMINATE_ON_TIMEOUT);
    sst.setClientPacketHandlerClass(TrackClientPacketHandler.class);

    /* start thread */
    Print.logInfo(
        "Starting UDP listener thread on port "
            + port
            + " [timeout="
            + sst.getSessionTimeout()
            + "ms] ...");
    sst.start();
    this.udpThread.add(sst);
    return sst;
  }
Esempio n. 6
0
    public void run() {
      String command = null;
      Print.logInfo("Client:OutputThread started");

      while (true) {

        /* wait for commands */
        synchronized (this.cmdList) {
          while ((this.cmdList.size() <= 0) && (getRunStatus() == THREAD_RUNNING)) {
            try {
              this.cmdList.wait(5000L);
            } catch (Throwable t) {
              /*ignore*/
            }
          }
          if (getRunStatus() != THREAD_RUNNING) {
            break;
          }
          command = this.cmdList.remove(0).toString();
        }

        /* send commands */
        try {
          ClientSocketThread.socketWriteLine(this.socket, command);
        } catch (Throwable t) {
          Print.logError("Client:OutputThread - " + t);
          t.printStackTrace();
          break;
        }
      }

      if (getRunStatus() == THREAD_RUNNING) {
        Print.logWarn("Client:OutputThread stopped due to error");
      } else {
        Print.logInfo("Client:OutputThread stopped");
      }

      synchronized (this.threadLock) {
        this.isRunning = false;
        Print.logInfo("Client:OutputThread stopped");
        this.threadLock.notify();
      }
    }
Esempio n. 7
0
 private static void usage() {
   Print.logInfo("Usage:");
   Print.logInfo("  java ... " + URIArg.class.getName() + " {options}");
   Print.logInfo("Options:");
   Print.logInfo("  -encode=<ASCII>    Encode ASCII string to URL argument string");
   Print.logInfo("  -decode=<args>     Decode URL argument string to ASCII");
   Print.logInfo("  -rtpEnc=<url>      RTP Encode URL [key = 'rtp']");
   Print.logInfo("  -rtpDec=<url>      RTP Decode URL [key = 'rtp']");
   System.exit(1);
 }
Esempio n. 8
0
  /* start TCP listener */
  private void _startTCP(int port) throws Throwable {
    ServerSocketThread sst = null;

    /* create server socket */
    try {
      sst = new ServerSocketThread(port);
    } catch (Throwable t) { // trap any server exception
      Print.logException("ServerSocket error", t);
      throw t;
    }

    /* initialize */
    sst.setTextPackets(Constants.ASCII_PACKETS);
    sst.setBackspaceChar(null); // no backspaces allowed
    sst.setLineTerminatorChar(Constants.ASCII_LINE_TERMINATOR);
    sst.setIgnoreChar(Constants.ASCII_IGNORE_CHARS);
    sst.setMaximumPacketLength(Constants.MAX_PACKET_LENGTH);
    sst.setMinimumPacketLength(Constants.MIN_PACKET_LENGTH);
    sst.setIdleTimeout(TrackServer.tcpTimeout_idle); // time between packets
    sst.setPacketTimeout(
        TrackServer.tcpTimeout_packet); // time from start of packet to packet completion
    sst.setSessionTimeout(TrackServer.tcpTimeout_session); // time for entire session
    sst.setTerminateOnTimeout(Constants.TERMINATE_ON_TIMEOUT);
    sst.setClientPacketHandlerClass(TrackClientPacketHandler.class);
    sst.setLingerTimeoutSec(Constants.LINGER_ON_CLOSE_SEC);

    /* start thread */
    Print.logInfo(
        "Starting TCP listener thread on port "
            + port
            + " [timeout="
            + sst.getSessionTimeout()
            + "ms] ...");
    sst.start();
    this.tcpThread.add(sst);
  }
Esempio n. 9
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;
  }