001// Copyright (c) FIRST and other WPILib contributors.
002// Open Source Software; you can modify and/or share it under the terms of
003// the WPILib BSD license file in the root directory of this project.
004
005package edu.wpi.first.util.datalog;
006
007import java.nio.ByteBuffer;
008
009/** Log raw byte array values. */
010public class RawLogEntry extends DataLogEntry {
011  /** The data type for raw values. */
012  public static final String kDataType = "raw";
013
014  /**
015   * Constructs a raw log entry.
016   *
017   * @param log datalog
018   * @param name name of the entry
019   * @param metadata metadata
020   * @param type Data type
021   * @param timestamp entry creation timestamp (0=now)
022   */
023  public RawLogEntry(DataLog log, String name, String metadata, String type, long timestamp) {
024    super(log, name, type, metadata, timestamp);
025  }
026
027  /**
028   * Constructs a raw log entry.
029   *
030   * @param log datalog
031   * @param name name of the entry
032   * @param metadata metadata
033   * @param type Data type
034   */
035  public RawLogEntry(DataLog log, String name, String metadata, String type) {
036    this(log, name, metadata, type, 0);
037  }
038
039  /**
040   * Constructs a raw log entry.
041   *
042   * @param log datalog
043   * @param name name of the entry
044   * @param metadata metadata
045   * @param timestamp entry creation timestamp (0=now)
046   */
047  public RawLogEntry(DataLog log, String name, String metadata, long timestamp) {
048    this(log, name, metadata, kDataType, timestamp);
049  }
050
051  /**
052   * Constructs a raw log entry.
053   *
054   * @param log datalog
055   * @param name name of the entry
056   * @param metadata metadata
057   */
058  public RawLogEntry(DataLog log, String name, String metadata) {
059    this(log, name, metadata, 0);
060  }
061
062  /**
063   * Constructs a raw log entry.
064   *
065   * @param log datalog
066   * @param name name of the entry
067   * @param timestamp entry creation timestamp (0=now)
068   */
069  public RawLogEntry(DataLog log, String name, long timestamp) {
070    this(log, name, "", timestamp);
071  }
072
073  /**
074   * Constructs a raw log entry.
075   *
076   * @param log datalog
077   * @param name name of the entry
078   */
079  public RawLogEntry(DataLog log, String name) {
080    this(log, name, 0);
081  }
082
083  /**
084   * Appends a record to the log.
085   *
086   * @param value Value to record; will send entire array contents
087   * @param timestamp Time stamp (0 to indicate now)
088   */
089  public void append(byte[] value, long timestamp) {
090    m_log.appendRaw(m_entry, value, timestamp);
091  }
092
093  /**
094   * Appends a record to the log.
095   *
096   * @param value Value to record; will send entire array contents
097   */
098  public void append(byte[] value) {
099    append(value, 0);
100  }
101
102  /**
103   * Appends a record to the log.
104   *
105   * @param value Data to record
106   * @param start Start position of data (in byte array)
107   * @param len Length of data (must be less than or equal to value.length - offset)
108   * @param timestamp Time stamp (0 to indicate now)
109   */
110  public void append(byte[] value, int start, int len, long timestamp) {
111    m_log.appendRaw(m_entry, value, start, len, timestamp);
112  }
113
114  /**
115   * Appends a record to the log.
116   *
117   * @param value Data to record
118   * @param start Start position of data (in byte array)
119   * @param len Length of data (must be less than or equal to value.length - offset)
120   */
121  public void append(byte[] value, int start, int len) {
122    append(value, start, len, 0);
123  }
124
125  /**
126   * Appends a record to the log.
127   *
128   * @param value Data to record; will send from value.position() to value.capacity()
129   * @param timestamp Time stamp (0 to indicate now)
130   */
131  public void append(ByteBuffer value, long timestamp) {
132    m_log.appendRaw(m_entry, value, timestamp);
133  }
134
135  /**
136   * Appends a record to the log.
137   *
138   * @param value Data to record; will send from value.position() to value.capacity()
139   */
140  public void append(ByteBuffer value) {
141    append(value, 0);
142  }
143
144  /**
145   * Appends a record to the log.
146   *
147   * @param value Data to record
148   * @param start Start position of data (in value buffer)
149   * @param len Length of data (must be less than or equal to value.length - offset)
150   * @param timestamp Time stamp (0 to indicate now)
151   */
152  public void append(ByteBuffer value, int start, int len, long timestamp) {
153    m_log.appendRaw(m_entry, value, start, len, timestamp);
154  }
155
156  /**
157   * Appends a record to the log.
158   *
159   * @param value Data to record
160   * @param start Start position of data (in value buffer)
161   * @param len Length of data (must be less than or equal to value.length - offset)
162   */
163  public void append(ByteBuffer value, int start, int len) {
164    append(value, start, len, 0);
165  }
166}