Пример #1
0
  private long getExpectedCrcValue(InputStream is) {
    byte crcBytes[] = new byte[4];
    long retval = -1;

    /*
     **  Read the CRC bytes from the byte stream.
     */
    try {
      is.read(crcBytes, 0, 4);
    } catch (IOException ioe1) {
      //  The file may be corrupt.
      // ^^FQ8=CRC could not be created from download
      AqLog.getInstance().info("^^FQ8", ioe1);
      return -1;
    }

    try {
      ByteDecoder crcBd = new ByteDecoder(crcBytes);
      retval = crcBd.readLong(4);
      envelopeCrc = retval;
      // ^^FQv=enlop crc =
      System.out.println("^^FQv" + envelopeCrc);
    } catch (IOException ioe2) {
      // ^^FQ9=Error intrepreting CRC
      AqLog.getInstance().error("^^FQ9", ioe2);
    }
    return retval;
  }
Пример #2
0
  public boolean getData(String outputFileName, boolean saveCRC) {
    // ^^FQB=entering Envelope.getData()
    AqLog.getInstance().debug("^^FQB:" + outputFileName);

    OutputStream os = null;

    /*
     **  Create an output file based on the name.
     */
    try {
      os = AqFileUtils.openFileOutputStream(outputFileName, false);

    } catch (Exception e) {
      //  The file may be corrupt.
      // ^^FQ3=File could not be extracted from download.  fileName:
      AqLog.getInstance().info("^^FQ3 " + outputFileName);
      return false;
    }

    boolean retval = false;
    if (null != os) {
      retval = getData(os);
      if (saveCRC) {
        ByteEncoder be = new ByteEncoder();
        int icrc = (int) (this.getEnvelopeCrc() & 0xffffffff);
        be.writeSignedInt(4, (icrc));
        byte[] bcrc = be.getContent();
        try {
          os.write(bcrc, 0, 4);
          os.flush();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
      // ^^FQF=closed GF os:
      AqFileUtils.closeStream("^^FQF" + outputFileName, os);
    }
    return retval;
  }
Пример #3
0
  /**
   * This should get optimized out on an A1 OBU build. This method is used by the tools in order to
   * build test envelopes used in test cases. It may also be used in the build process to combine a
   * .jad envelope .jar envelope within a single larger envelope
   *
   * @param tag The identifier 'tag' used to the envelope being built.
   * @param is The input stream which will become the envelope's payload
   * @param os The output stream where the envelope will be written. The contents of the output
   *     stream will contain payload size, tag, payload, payload CRC32.
   * @return <code>true</code> Envelope was constructed successfully, <code>
   * 		false</code> the envelope construction failed.
   */
  public static boolean buildEnvelope(int tag, InputStream is, OutputStream os) {
    boolean retval = false;

    // sanity check
    if ((null == is) || (null == os) || (tag < 0) || (tag > 250)) return false;

    byte buf[] = new byte[BLOCK_SIZE];
    int n = 0;
    CRC32 crc = new CRC32();

    try {
      int sz = is.available();
      ByteEncoder be = new ByteEncoder();
      be.writeInt(4, sz);
      be.writeInt(1, tag);
      os.write(be.getContent());

      while (n >= 0) {
        n = is.read(buf);
        if (n > 0) {
          crc.update(buf, 0, n);
          os.write(buf, 0, n);
        }
      }

      be = new ByteEncoder();
      be.writeLong(4, crc.getValue());
      os.write(be.getContent());
      retval = true;
      crc = null;
    } catch (Exception e) {
      // ^^FQG=Unable to build envelope
      AqLog.getInstance().error("^^FQG", e);
    }
    return retval;
  }
  /**
   * Add a SnapshotSummary row read form the DB to a AqVperfData object. After all SnapshotSummaries
   * are added IN ORDER for a given shift The vPerf is fully re-constructed.
   *
   * @param shiftId The shift Id that was consumed from the Original SnapshotSummaryUploadRequest
   *     and stored in the SnapshotSummarytable
   * @param seq_num The seq_num that was consumed from the Original SnapshotSummaryUploadRequest and
   *     stored in the SnapshotSummarytable
   * @param isLast The isLast indicator that was consumed from the Original
   *     SnapshotSummaryUploadRequest and stored in the SnapshotSummarytable
   * @param vperf_vsn The vperf_vsn that was consumed from the Original SnapshotSummaryUploadRequest
   *     and stored in the SnapshotSummarytable
   * @param summaryData byte array, or maybe inputStream? This should be some entity which contains
   *     the rest of the remaing data that was received in the SnapshotSummaryUploadRequest message
   *     and wasn't consumed.
   */
  public void addSnapshotSummary(
      String shiftId, int seq_num, boolean isLast, int vperf_vsn, byte[] summaryData)
      throws AqErrorException {
    if (seq_num != (lastSummaryProcessed + 1)) {
      System.out.println("seq_num,lastSummaryProcessed: " + seq_num + "," + lastSummaryProcessed);
      throw new AqErrorException("seq_num out of order");
    } else if (isLastBlockProcessed) {
      throw new AqErrorException("last block already processed");
    } else {
      try {
        CfmsVperfByteDecoder bd = new CfmsVperfByteDecoder(summaryData);
        CfmsVperfByteDecoder shiftPeriodBd;
        bd.setCfmsProtocolVersion(vperf_vsn);

        int magic = bd.readInt(4);
        if (SNAPSHOT_SUMMARY_MAGIC != magic) {
          throw new AqErrorException("Invalid magic number for snapshot summary");
        }
        int vPerfVsn = bd.readInt(1);
        AqLog.getInstance().debug("gotvPerfVsn: " + vPerfVsn);

        int shiftPeriodIvmsBreakTime = bd.readInt(4);
        AqLog.getInstance().debug("got shiftPeriodIvmsBreakTime:" + shiftPeriodIvmsBreakTime);

        int shiftPeriodNetricSz = bd.readInt(2);
        AqLog.getInstance().debug("got shiftPeriodNetricSz:" + shiftPeriodNetricSz);

        byte[] shiftPeriodMetrics = bd.readBytes(shiftPeriodNetricSz);
        AqLog.getInstance().debug("got shiftPeriodMetrics: " + shiftPeriodMetrics);

        // Read operational events
        int shiftPeriodNumOperationalEvents = bd.readInt(2);
        AqLog.getInstance()
            .debug("got shiftPeriodNumOperationalEvents:" + shiftPeriodNumOperationalEvents);

        int shiftPeriodOperationalEvtSz = bd.readInt(2);
        AqLog.getInstance()
            .debug("got shiftPeriodOperationalEvtSz: " + shiftPeriodOperationalEvtSz);

        byte[] shiftPeriodOperationalEvents = null;
        AqLog.getInstance()
            .debug("got shiftPeriodOperationalEvents: " + shiftPeriodOperationalEvents);

        if (shiftPeriodOperationalEvtSz > 0)
          shiftPeriodOperationalEvents = bd.readBytes(shiftPeriodOperationalEvtSz);
        AqLog.getInstance()
            .debug("got shiftPeriodOperationalEvents: " + shiftPeriodOperationalEvents);

        // Read health events
        int shiftPeriodNumHealthEvents = bd.readInt(2);
        AqLog.getInstance().debug("got shiftPeriodNumHealthEvents: " + shiftPeriodNumHealthEvents);

        int shiftPeriodHealthEvtSz = bd.readInt(2);
        AqLog.getInstance().debug("got shiftPeriodHealthEvtSz: " + shiftPeriodHealthEvtSz);

        byte[] shiftPeriodHealthEvents = null;

        if (shiftPeriodHealthEvtSz > 0)
          shiftPeriodHealthEvents = bd.readBytes(shiftPeriodHealthEvtSz);
        AqLog.getInstance().debug("got shiftPeriodHealthEvents: " + shiftPeriodHealthEvents);

        BitDecoder bits = new BitDecoder(bd.readBytes(1));

        /* int reserved = */ bits.readInt(7);
        boolean isLastShiftPeriod = bits.readBoolean();
        AqLog.getInstance().debug("got isLastShiftPeriod: " + isLastShiftPeriod);

        if (isLastShiftPeriod) {
          // Read CFMS config manifest
          cfmsConfigManifest = new CfmsConfigManifest(false);
          cfmsConfigManifest.decodePackedData(bd);
          AqLog.getInstance().debug("got cfmsConfigManifest: " + cfmsConfigManifest);
          AqLog.getInstance()
              .debug(
                  "mfstVsn,ObuSwVsn,tspCfgVsn,coreVsn,gfSetVsn,fmsVsn: "
                      + cfmsConfigManifest.getCfgManifestVersion()
                      + ","
                      + cfmsConfigManifest.getObuSwVersion()
                      + ","
                      + cfmsConfigManifest.getTspConfigVersion()
                      + ","
                      + cfmsConfigManifest.getCoreVersion()
                      + ","
                      + cfmsConfigManifest.getGeoFenceSetVersion()
                      + ","
                      + cfmsConfigManifest.getFmsVersion());

          // read the FMS source
          fmsSource = bd.readShortString();
          AqLog.getInstance().debug("got fmsSource: " + fmsSource);

          // read the next service distance
          try {
            nextServiceDistance = bd.checkedReadInt(3);
          } catch (Exception e) {
            nextServiceDistance = 99999;
          }
          AqLog.getInstance().debug("got nextServiceDistance: " + nextServiceDistance);

          // read logon
          int logonEventSz = bd.readInt(1);
          AqLog.getInstance().debug("got logonEventSz: " + logonEventSz);

          byte[] logonEventData = bd.readBytes(logonEventSz);
          CfmsVperfByteDecoder logonBd = new CfmsVperfByteDecoder(logonEventData);
          logonBd.setCfmsProtocolVersion(vPerfVsn);
          logonEvent = readShiftEventFromCfmsVperfByteDecoder(logonBd);
          if (null != logonEvent) vPerf.addLogonEvent(logonEvent);
          AqLog.getInstance().debug("got logonEvent: " + logonEvent);

          // read logoff
          int logoffEventSz = bd.readInt(1);
          byte[] logoffEventData = bd.readBytes(logoffEventSz);
          CfmsVperfByteDecoder logoffBd = new CfmsVperfByteDecoder(logoffEventData);
          logoffBd.setCfmsProtocolVersion(vPerfVsn);
          logoffEvent = readShiftEventFromCfmsVperfByteDecoder(logoffBd);
          AqLog.getInstance().debug("got logoffEvent: " + logoffEvent);

          cfmsUploadRequestTransId = bd.readLong(8);
          AqLog.getInstance().debug("got cfmsUploadRequestTransId: " + cfmsUploadRequestTransId);

          healthReportUploadRequestTransId = bd.readLong(8);
          AqLog.getInstance()
              .debug("got healthReportUploadRequestTransId: " + healthReportUploadRequestTransId);

          healthLogonStatus = bd.readInt(1);
          AqLog.getInstance().debug("got healthLogonStatus: " + healthLogonStatus);
          healthProcessorStatus = bd.readInt(2);
          AqLog.getInstance().debug("got healthProcessorStatus: " + healthProcessorStatus);

          healthMinRam = bd.readInt(2);
          AqLog.getInstance().debug("got healthMinRam: " + healthMinRam);
          healthAvgRam = bd.readInt(2);
          AqLog.getInstance().debug("got healthAvgRam: " + healthAvgRam);
          healthBatteryAndDtcoStats = bd.readInt(1);
          AqLog.getInstance().debug("got healthBatteryAndDtcoStats: " + healthBatteryAndDtcoStats);
          healthFmsStatus = bd.readInt(2);
          AqLog.getInstance().debug("got healthFmsStatus: " + healthFmsStatus);
          healthFmsErrorCount = bd.readInt(2);
          AqLog.getInstance().debug("got healthFmsErrorCount: " + healthFmsErrorCount);
        }

        // Sanity check the API call parameters against what is inside the SnapshoSummaryRequest
        // Decode the components
        shiftPeriodBd = new CfmsVperfByteDecoder(shiftPeriodMetrics);
        shiftPeriodBd.setCfmsProtocolVersion(vPerfVsn);
        AqShiftPeriod sp = new AqShiftPeriod();
        sp.decodePackedData(shiftPeriodBd);

        // Make sure that all reported values for shiftId match
        if (null == this.shiftId) {
          this.shiftId = new String(shiftId);
        } else if ((null == shiftId) || (!this.shiftId.equals(shiftId))) {
          throw new AqErrorException("integrety mismatch");
        }

        if ((vPerfVsn != vperf_vsn)
            || (isLastShiftPeriod != isLast)
            || (seq_num != sp.getSequenceNum())) {
          throw new AqErrorException("integrety mismatch");
        }

        // TODO would it be better to add protected method for this?  then make shift period private
        // member
        vPerf.shiftPeriods[seq_num - 1] = sp;
        this.ivmsAccumulatedBreakTime += shiftPeriodIvmsBreakTime;

        if (null != shiftPeriodOperationalEvents) {
          CfmsVperfByteDecoder opEventsBd = new CfmsVperfByteDecoder(shiftPeriodOperationalEvents);
          opEventsBd.setCfmsProtocolVersion(vPerfVsn);
          int i;
          for (i = 0; i < shiftPeriodNumOperationalEvents; i++) {
            AqShiftEvent evt = readShiftEventFromCfmsVperfByteDecoder(opEventsBd);
            if (null != evt) vPerf.addOperationalEvent(evt);
          }
        }

        // This will only be true during the last shift period ...
        // make sure it is the last event recorded for the shift to
        // match current event listing order
        if (null != logoffEvent) vPerf.addOperationalEvent(logoffEvent);

        this.totalNumHealthEvents += shiftPeriodNumHealthEvents;
        if (null != shiftPeriodHealthEvents) {
          healthReportEventBytes.write(shiftPeriodHealthEvents);
        }

        this.lastSummaryProcessed = seq_num;
      } catch (Exception e) {
        AqLog.getInstance().error("Unable to decode SnapshotSummaryRequest payload", e);
        throw new AqErrorException("Unable to decode SnapshotSummaryRequest payload");
      }
    }
  }
Пример #5
0
  // TODO: ALLEN VALIDATE
  public boolean getData(OutputStream os) {
    int bytesRead = 0;
    int bytesRemain = 0;
    int bytesToRead = 0;
    byte[] buffer = new byte[BLOCK_SIZE];

    bytesRemain = size;
    // ^^FQC=Stage2 bytesRemain:
    AqLog.getInstance().debug("^^FQC " + bytesRemain);

    do {
      if (bytesRemain < BLOCK_SIZE) {
        bytesToRead = bytesRemain;
      } else {
        bytesToRead = BLOCK_SIZE;
      }

      try {
        bytesRead = is.read(buffer, 0, bytesToRead);
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      if (bytesRead > 0) {
        bytesRemain -= bytesRead;

        /*
         **  Perform the CRC
         */
        crc.update(buffer, 0, bytesRead);

        /*
         ** Write to the output file.
         */
        try {
          os.write(buffer, 0, bytesRead);
          os.flush();
        } catch (IOException ioe2) {
          //  The file may be corrupt.
          // ^^FQ6=File could not be created from download.  fileName:
          AqLog.getInstance().info("^^FQ6 ");
          return false;
        }
      }

      if ((lastBytesRemain - bytesRemain) >= 2048) {
        // ^^FQA=Stage 2 BytesRemain:
        AqLog.getInstance().debug("^^FQA " + bytesRemain);
        lastBytesRemain = bytesRemain;
      }

    } while ((bytesRemain > 0) && (bytesRead >= 0));

    // read the CRC from the stream
    boolean retval = true;
    if (getExpectedCrcValue(is) != crc.getValue()) {
      retval = false;
    }

    // ^^FQ1=Stage2: BytesRead,bytesRemain,expectedCrc,actualCrc,retval
    AqLog.getInstance()
        .info(
            "^^FQ1 "
                + bytesRead
                + ","
                + bytesRemain
                + ","
                + this.getEnvelopeCrc()
                + ","
                + crc.getValue()
                + ","
                + retval);
    return retval;
  }