Пример #1
0
 public static void main(String argv[]) {
   RTConfig.setCommandLineArgs(argv);
   InitJ1587DescriptionProvider();
   RTProperties cmdLineProps = RTConfig.getCommandLineProperties();
   long fault = EncodeFault(cmdLineProps);
   Print.sysPrintln("Fault : " + fault + " [0x" + StringTools.toHexString(fault) + "]");
   Print.sysPrintln("String: " + GetPropertyString(fault));
   Print.sysPrintln("Desc  : " + GetFaultDescription(fault, null));
 }
 public static String getErrorDescription(int errCode) {
   switch (errCode) {
     case NAK_OK:
       return "OK";
     case NAK_ID_INVALID:
       return "Invalid unique ID";
     case NAK_ACCOUNT_INVALID:
       return "Invalid account ID";
     case NAK_ACCOUNT_INACTIVE:
       return "Account inactive";
     case NAK_ACCOUNT_ERROR:
       return "Account error";
     case NAK_DEVICE_INVALID:
       return "Invalid device ID";
     case NAK_DEVICE_INACTIVE:
       return "Device inactive";
     case NAK_DEVICE_ERROR:
       return "Device error";
     case NAK_EXCESSIVE_CONNECTIONS:
       return "Excessive connections";
     case NAK_PACKET_HEADER:
       return "Invalid packet header";
     case NAK_PACKET_TYPE:
       return "Invalid packet type";
     case NAK_PACKET_LENGTH:
       return "Invalid packet length";
     case NAK_PACKET_PAYLOAD:
       return "Invalid packet payload";
     case NAK_PACKET_ENCODING:
       return "Unsupported packet encoding";
     case NAK_PACKET_CHECKSUM:
       return "Invalid packet checksum";
     case NAK_BLOCK_CHECKSUM:
       return "Invalid block checksum";
     case NAK_PROTOCOL_ERROR:
       return "Protocol error";
     case NAK_FORMAT_DEFINITION_INVALID:
       return "Invalid custom format definition";
     case NAK_FORMAT_NOT_SUPPORTED:
       return "Custom formats not supported";
     case NAK_FORMAT_NOT_RECOGNIZED:
       return "Custom format not recognized";
     case NAK_EXCESSIVE_EVENTS:
       return "Excessive events";
     case NAK_DUPLICATE_EVENT:
       return "Duplicate event";
     case NAK_EVENT_ERROR:
       return "Event error";
     default:
       return "Unknown [" + StringTools.toHexString(errCode, 16) + "]";
   }
 }
Пример #3
0
  /**
   * ** Gets the Description and/or converts the specified binary value to a String ** @param
   * errCode The error code ** @param inclDesc True to include the description, false to omit
   * ** @param errData The binary payload data ** @param tz A TimeZone used convert any dates
   * encountered ** @return The Description and/or value String representation
   */
  public static String getStringValue(int errCode, boolean inclDesc, byte errData[], TimeZone tz) {
    Payload payload = ((errData != null) && (errData.length > 0)) ? new Payload(errData) : null;
    StringBuffer sb = new StringBuffer();
    switch (errCode) {
      case ERROR_PACKET_HEADER:
        if (inclDesc) {
          sb.append("Invalid packet header");
          if (payload != null) {
            sb.append(": ");
          }
        }
        if (payload != null) {
          String h = StringTools.toHexString(payload.readLong(1, 0L), 8);
          String t = StringTools.toHexString(payload.readLong(1, 0L), 8);
          sb.append("0x" + h + t);
        }
        return sb.toString();
      case ERROR_PACKET_TYPE:
        if (inclDesc) {
          sb.append("Invalid packet type");
          if (payload != null) {
            sb.append(": ");
          }
        }
        if (payload != null) {
          String h = StringTools.toHexString(payload.readLong(1, 0L), 8);
          String t = StringTools.toHexString(payload.readLong(1, 0L), 8);
          sb.append("0x" + h + t);
        }
        return sb.toString();
      case ERROR_PACKET_LENGTH:
        if (inclDesc) {
          sb.append("Invalid packet length");
          if (payload != null) {
            sb.append(": ");
          }
        }
        if (payload != null) {
          String h = StringTools.toHexString(payload.readLong(1, 0L), 8);
          String t = StringTools.toHexString(payload.readLong(1, 0L), 8);
          sb.append("0x" + h + t);
        }
        return sb.toString();
      case ERROR_PACKET_ENCODING:
        if (inclDesc) {
          sb.append("Unsupported packet encoding");
          if (payload != null) {
            sb.append(": ");
          }
        }
        if (payload != null) {
          String h = StringTools.toHexString(payload.readLong(1, 0L), 8);
          String t = StringTools.toHexString(payload.readLong(1, 0L), 8);
          sb.append("0x" + h + t);
        }
        return sb.toString();
      case ERROR_PACKET_PAYLOAD:
        if (inclDesc) {
          sb.append("Invalid packet payload");
          if (payload != null) {
            sb.append(": ");
          }
        }
        if (payload != null) {
          String h = StringTools.toHexString(payload.readLong(1, 0L), 8);
          String t = StringTools.toHexString(payload.readLong(1, 0L), 8);
          sb.append("0x" + h + t);
        }
        return sb.toString();
      case ERROR_PACKET_CHECKSUM:
        if (inclDesc) {
          sb.append("Invalid checksum");
          if (payload != null) {
            sb.append(": ");
          }
        }
        if (payload != null) {
          String h = StringTools.toHexString(payload.readLong(1, 0L), 8);
          String t = StringTools.toHexString(payload.readLong(1, 0L), 8);
          sb.append("0x" + h + t);
        }
        return sb.toString();
      case ERROR_PACKET_ACK:
        if (inclDesc) {
          sb.append("Invalid ACL sequence");
          if (payload != null) {
            sb.append(": ");
          }
        }
        if (payload != null) {
          String h = StringTools.toHexString(payload.readLong(1, 0L), 8);
          String t = StringTools.toHexString(payload.readLong(1, 0L), 8);
          sb.append("0x" + h + t);
        }
        return sb.toString();
      case ERROR_PROTOCOL_ERROR:
        if (inclDesc) {
          sb.append("Protocol error");
          if (payload != null) {
            sb.append(": ");
          }
        }
        if (payload != null) {
          String h = StringTools.toHexString(payload.readLong(1, 0L), 8);
          String t = StringTools.toHexString(payload.readLong(1, 0L), 8);
          sb.append("0x" + h + t);
        }
        return sb.toString();
      case ERROR_PROPERTY_READ_ONLY:
        if (inclDesc) {
          sb.append("Property is read-only");
          if (payload != null) {
            sb.append(": ");
          }
        }
        if (payload != null) {
          String p = StringTools.toHexString(payload.readLong(2, 0L), 16);
          sb.append("0x" + p);
        }
        return sb.toString();
      case ERROR_PROPERTY_WRITE_ONLY:
        if (inclDesc) {
          sb.append("Property is write-only");
          if (payload != null) {
            sb.append(": ");
          }
        }
        if (payload != null) {
          String p = StringTools.toHexString(payload.readLong(2, 0L), 16);
          sb.append("0x" + p);
        }
        return sb.toString();
      case ERROR_PROPERTY_INVALID_ID:
        if (inclDesc) {
          sb.append("Invalid/Unrecognized property key");
          if (payload != null) {
            sb.append(": ");
          }
        }
        if (payload != null) {
          String p = StringTools.toHexString(payload.readLong(2, 0L), 16);
          sb.append("0x" + p);
        }
        return sb.toString();
      case ERROR_PROPERTY_INVALID_VALUE:
        if (inclDesc) {
          sb.append("Invalid property value");
          if (payload != null) {
            sb.append(": ");
          }
        }
        if (payload != null) {
          String p = StringTools.toHexString(payload.readLong(2, 0L), 16);
          sb.append("0x" + p);
        }
        return sb.toString();
      case ERROR_PROPERTY_UNKNOWN_ERROR:
        if (inclDesc) {
          sb.append("Unknown property error");
          if (payload != null) {
            sb.append(": ");
          }
        }
        if (payload != null) {
          String p = StringTools.toHexString(payload.readLong(2, 0L), 16);
          sb.append("0x" + p);
        }
        return sb.toString();
      case ERROR_COMMAND_INVALID:
        if (inclDesc) {
          sb.append("Invalid/Unsupported command");
          if (payload != null) {
            sb.append(": ");
          }
        }
        if (payload != null) {
          String c = StringTools.toHexString(payload.readLong(2, 0L), 16);
          sb.append("0x" + c);
        }
        return sb.toString();
      case ERROR_COMMAND_ERROR:
        if (inclDesc) {
          sb.append("Command error");
          if (payload != null) {
            sb.append(": ");
          }
        }
        if (payload != null) {
          String c = StringTools.toHexString(payload.readLong(2, 0L), 16);
          String e = StringTools.toHexString(payload.readLong(2, 0L), 16);
          sb.append("cmd=0x" + c + ", err=0x" + e);
          int dlen = payload.getAvailableReadLength();
          if (dlen > 0) {
            String d = StringTools.toHexString(payload.readBytes(dlen));
            sb.append(", data=0x" + d);
          }
        }
        return sb.toString();
      case ERROR_UPLOAD_TYPE:
        if (inclDesc) {
          sb.append("Invalid upload type");
        }
        return sb.toString();
      case ERROR_UPLOAD_PACKET:
        if (inclDesc) {
          sb.append("Invalid upload packet");
        }
        return sb.toString();
      case ERROR_UPLOAD_LENGTH:
        if (inclDesc) {
          sb.append("Invalid upload length");
        }
        return sb.toString();
      case ERROR_UPLOAD_OFFSET_OVERLAP:
        if (inclDesc) {
          sb.append("Upload offset overlap");
        }
        return sb.toString();
      case ERROR_UPLOAD_OFFSET_GAP:
        if (inclDesc) {
          sb.append("Upload offset gap");
        }
        return sb.toString();
      case ERROR_UPLOAD_OFFSET_OVERFLOW:
        if (inclDesc) {
          sb.append("Upload offset overflow");
        }
        return sb.toString();
      case ERROR_UPLOAD_FILE_NAME:
        if (inclDesc) {
          sb.append("Invalid uploaded filename");
        }
        return sb.toString();
      case ERROR_UPLOAD_CHECKSUM:
        if (inclDesc) {
          sb.append("Invalid uploaded checksum");
        }
        return sb.toString();
      case ERROR_UPLOAD_SAVE:
        if (inclDesc) {
          sb.append("Unable to save uploaded file");
          if (payload != null) {
            sb.append(": ");
          }
        }
        if (payload != null) {
          int dlen = payload.getAvailableReadLength();
          String d = StringTools.toHexString(payload.readBytes(dlen));
          sb.append("0x" + d);
        }
        return sb.toString();
      case ERROR_UPLOAD_HOST:
        if (inclDesc) {
          sb.append("Invalid/unspecified upload host:port");
        }
        return sb.toString();
      case ERROR_UPLOAD_SERVER_ERROR:
        if (inclDesc) {
          sb.append("Server indicated upload error");
        }
        return sb.toString();
      case ERROR_GPS_EXPIRED:
        if (inclDesc) {
          sb.append("GPS Expired");
          if (payload != null) {
            sb.append(": ");
          }
        }
        if (payload != null) {
          long lastFix = payload.readLong(4, 0L);
          sb.append("lastFix=");
          if (lastFix <= 0L) {
            sb.append("never"); // i18n
          } else if (tz != null) {
            DateTime dt = new DateTime(lastFix, tz);
            sb.append(dt.format("yyyy/MM/dd,HH:mm:ss")); // i18n
          } else {
            sb.append(lastFix);
          }
        }
        return sb.toString();
      case ERROR_GPS_FAILURE:
        if (inclDesc) {
          sb.append("GPS Failure");
          if (payload != null) {
            sb.append(": ");
          }
        }
        if (payload != null) {
          long lastFix = payload.readLong(4, 0L);
          sb.append("lastFix=");
          if (lastFix <= 0L) {
            sb.append("never"); // i18n
          } else if (tz != null) {
            DateTime dt = new DateTime(lastFix, tz);
            sb.append(dt.format("yyyy/MM/dd,HH:mm:ss")); // i18n
          } else {
            sb.append(lastFix);
          }
          int dlen = payload.getAvailableReadLength();
          if (dlen > 0) {
            String d = StringTools.toHexString(payload.readBytes(dlen));
            sb.append(" data=0x" + d);
          }
        }
        return sb.toString();
      case ERROR_OUT_OF_MEMORY:
        if (inclDesc) {
          sb.append("Out-Of-Memory error");
        }
        return sb.toString();
    }

    /* internal error */
    if ((errCode >= ERROR_INTERNAL_ERROR_00) && (errCode <= ERROR_INTERNAL_ERROR_0F)) {
      if (inclDesc) {
        sb.append("Internal error");
        if (payload != null) {
          sb.append(": ");
        }
      }
      if (payload != null) {
        int dlen = payload.getAvailableReadLength();
        String d = StringTools.toHexString(payload.readBytes(dlen));
        sb.append("0x" + d);
      }
      return sb.toString();
    }

    /* unknown */
    if (inclDesc) {
      sb.append("Unknown[0x").append(StringTools.toHexString(errCode, 16)).append("]");
      if (payload != null) {
        sb.append(": ");
      }
    }
    if (payload != null) {
      int dlen = payload.getAvailableReadLength();
      String d = StringTools.toHexString(payload.readBytes(dlen));
      sb.append("0x" + d);
    }
    return sb.toString();
  }
Пример #4
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;
  }
Пример #5
0
 public String toString() {
   return "0x" + StringTools.toHexString(this.getFaultCode());
 }