001/* 002 * Copyright (C) Cross The Road Electronics. All rights reserved. 003 * License information can be found in CTRE_LICENSE.txt 004 * For support and suggestions contact support@ctr-electronics.com or file 005 * an issue tracker at https://github.com/CrossTheRoadElec/Phoenix-Releases 006 */ 007package com.ctre.phoenix6; 008 009import com.ctre.phoenix6.jni.SignalLoggerJNI; 010 011 012/** 013 * Static class for controlling the Phoenix 6 signal logger. 014 * <p> 015 * This logs all the signals from the CAN buses into .hoot files. Each file name starts with the 016 * CANivore serial number or "rio" for the roboRIO CAN bus, followed by the timestamp. In the 017 * header of a hoot file, the CANivore name and firmware version are logged in plain text. 018 * <p> 019 * During an FRC match, the log file will be renamed to include the event name, match type, and 020 * match number at the start of the file name. The match type will be 'P' for practice matches, 021 * 'Q' for qualification matches, and 'E' for elimination matches. 022 */ 023public class SignalLogger { 024 025 /** 026 * Sets the destination for logging, restarting logger if the path changed. 027 * <p> 028 * If this is not called or the path is left empty, the default path will be used. The 029 * default path on the roboRIO is a logs folder on the first USB flash drive found, or 030 * /home/lvuser/logs if none is available. The default path on all other platforms is 031 * a logs folder in the current working directory. 032 * <p> 033 * Typical use for this routine is to use a removable USB flash drive for logging. 034 * 035 * @param path Folder path for the log files; path must exist 036 * @return Status of setting the path and restarting the log 037 */ 038 public static StatusCode setPath(String path) { 039 return StatusCode.valueOf(SignalLoggerJNI.JNI_SetLoggerPath(path)); 040 } 041 042 /** 043 * Starts logging status signals. Starts regardless of auto logging status. 044 * <p> 045 * If using a roboRIO 1, we recommend setting the logging path to an external drive 046 * using {@link #setPath} to avoid running out of internal storage space. 047 * <p> 048 * If auto logging is enabled, the log will be stopped at the end of the match. 049 * 050 * @return Status of starting the logger 051 */ 052 public static StatusCode start() { 053 return StatusCode.valueOf(SignalLoggerJNI.JNI_StartLogger()); 054 } 055 056 /** 057 * Stops logging status signals. Stops regardless of auto logging status. 058 * 059 * @return Status of stopping the logger 060 */ 061 public static StatusCode stop() { 062 return StatusCode.valueOf(SignalLoggerJNI.JNI_StopLogger()); 063 } 064 065 /** 066 * Enables or disables auto logging. 067 * <p> 068 * Auto logging is only supported on the roboRIO. When auto logging is enabled, 069 * logging is started at the beginning of an FRC match and stopped at the end. 070 * 071 * @param enable Whether to enable auto logging 072 * @return Status of auto logging enable/disable 073 */ 074 public static StatusCode enableAutoLogging(boolean enable) { 075 return StatusCode.valueOf(SignalLoggerJNI.JNI_EnableAutoLogging(enable)); 076 } 077 078 /** 079 * Writes the raw data bytes to the log file. The data cannot exceed 64 bytes. 080 * 081 * @param name Name of the signal 082 * @param data Raw data bytes 083 * @return Status of writing the data 084 */ 085 public static StatusCode writeRaw(String name, byte[] data) { 086 return writeRaw(name, data, 0); 087 } 088 /** 089 * Writes the raw data bytes to the log file. The data cannot exceed 64 bytes. 090 * 091 * @param name Name of the signal 092 * @param data Raw data bytes 093 * @param latencySeconds Latency of the signal in seconds; this value is subtracted 094 * from the current time to get the timestamp written to the log 095 * @return Status of writing the data 096 */ 097 public static StatusCode writeRaw(String name, byte[] data, double latencySeconds) { 098 return StatusCode.valueOf(SignalLoggerJNI.JNI_WriteRaw(name, data, latencySeconds)); 099 } 100 101 /** 102 * Writes the boolean to the log file. 103 * 104 * @param name Name of the signal 105 * @param value Value to write 106 * @return Status of writing the data 107 */ 108 public static StatusCode writeBoolean(String name, boolean value) { 109 return writeBoolean(name, value, 0); 110 } 111 /** 112 * Writes the boolean to the log file. 113 * 114 * @param name Name of the signal 115 * @param value Value to write 116 * @param latencySeconds Latency of the signal in seconds; this value is subtracted 117 * from the current time to get the timestamp written to the log 118 * @return Status of writing the data 119 */ 120 public static StatusCode writeBoolean(String name, boolean value, double latencySeconds) { 121 return StatusCode.valueOf(SignalLoggerJNI.JNI_WriteBoolean(name, value, latencySeconds)); 122 } 123 124 /** 125 * Writes the integer to the log file. 126 * 127 * @param name Name of the signal 128 * @param value Value to write 129 * @return Status of writing the data 130 */ 131 public static StatusCode writeInteger(String name, long value) { 132 return writeInteger(name, value, ""); 133 } 134 /** 135 * Writes the integer to the log file. 136 * 137 * @param name Name of the signal 138 * @param value Value to write 139 * @param units Units of the signal 140 * @return Status of writing the data 141 */ 142 public static StatusCode writeInteger(String name, long value, String units) { 143 return writeInteger(name, value, units, 0); 144 } 145 /** 146 * Writes the integer to the log file. 147 * 148 * @param name Name of the signal 149 * @param value Value to write 150 * @param units Units of the signal 151 * @param latencySeconds Latency of the signal in seconds; this value is subtracted 152 * from the current time to get the timestamp written to the log 153 * @return Status of writing the data 154 */ 155 public static StatusCode writeInteger(String name, long value, String units, double latencySeconds) { 156 return StatusCode.valueOf(SignalLoggerJNI.JNI_WriteInteger(name, value, units, latencySeconds)); 157 } 158 159 /** 160 * Writes the float to the log file. 161 * 162 * @param name Name of the signal 163 * @param value Value to write 164 * @return Status of writing the data 165 */ 166 public static StatusCode writeFloat(String name, float value) { 167 return writeFloat(name, value, ""); 168 } 169 /** 170 * Writes the float to the log file. 171 * 172 * @param name Name of the signal 173 * @param value Value to write 174 * @param units Units of the signal 175 * @return Status of writing the data 176 */ 177 public static StatusCode writeFloat(String name, float value, String units) { 178 return writeFloat(name, value, units, 0); 179 } 180 /** 181 * Writes the float to the log file. 182 * 183 * @param name Name of the signal 184 * @param value Value to write 185 * @param units Units of the signal 186 * @param latencySeconds Latency of the signal in seconds; this value is subtracted 187 * from the current time to get the timestamp written to the log 188 * @return Status of writing the data 189 */ 190 public static StatusCode writeFloat(String name, float value, String units, double latencySeconds) { 191 return StatusCode.valueOf(SignalLoggerJNI.JNI_WriteFloat(name, value, units, latencySeconds)); 192 } 193 194 /** 195 * Writes the double to the log file. 196 * 197 * @param name Name of the signal 198 * @param value Value to write 199 * @return Status of writing the data 200 */ 201 public static StatusCode writeDouble(String name, double value) { 202 return writeDouble(name, value, ""); 203 } 204 /** 205 * Writes the double to the log file. 206 * 207 * @param name Name of the signal 208 * @param value Value to write 209 * @param units Units of the signal 210 * @return Status of writing the data 211 */ 212 public static StatusCode writeDouble(String name, double value, String units) { 213 return writeDouble(name, value, units, 0); 214 } 215 /** 216 * Writes the double to the log file. 217 * 218 * @param name Name of the signal 219 * @param value Value to write 220 * @param units Units of the signal 221 * @param latencySeconds Latency of the signal in seconds; this value is subtracted 222 * from the current time to get the timestamp written to the log 223 * @return Status of writing the data 224 */ 225 public static StatusCode writeDouble(String name, double value, String units, double latencySeconds) { 226 return StatusCode.valueOf(SignalLoggerJNI.JNI_WriteDouble(name, value, units, latencySeconds)); 227 } 228 229 /** 230 * Writes the string to the log file. The string cannot exceed 64 characters. 231 * 232 * @param name Name of the signal 233 * @param value Value to write 234 * @return Status of writing the data 235 */ 236 public static StatusCode writeString(String name, String value) { 237 return writeString(name, value, 0); 238 } 239 /** 240 * Writes the string to the log file. The string cannot exceed 64 characters. 241 * 242 * @param name Name of the signal 243 * @param value Value to write 244 * @param latencySeconds Latency of the signal in seconds; this value is subtracted 245 * from the current time to get the timestamp written to the log 246 * @return Status of writing the data 247 */ 248 public static StatusCode writeString(String name, String value, double latencySeconds) { 249 return StatusCode.valueOf(SignalLoggerJNI.JNI_WriteString(name, value, latencySeconds)); 250 } 251 252 /** 253 * Writes the array of booleans to the log file. The array cannot exceed 64 elements. 254 * 255 * @param name Name of the signal 256 * @param values Array of values to write 257 * @return Status of writing the data 258 */ 259 public static StatusCode writeBooleanArray(String name, boolean[] values) { 260 return writeBooleanArray(name, values, 0); 261 } 262 /** 263 * Writes the array of booleans to the log file. The array cannot exceed 64 elements. 264 * 265 * @param name Name of the signal 266 * @param values Array of values to write 267 * @param latencySeconds Latency of the signal in seconds; this value is subtracted 268 * from the current time to get the timestamp written to the log 269 * @return Status of writing the data 270 */ 271 public static StatusCode writeBooleanArray(String name, boolean[] values, double latencySeconds) { 272 return StatusCode.valueOf(SignalLoggerJNI.JNI_WriteBooleanArray(name, values, latencySeconds)); 273 } 274 275 /** 276 * Writes the array of integers to the log file. The array cannot exceed 8 elements. 277 * 278 * @param name Name of the signal 279 * @param values Array of values to write 280 * @return Status of writing the data 281 */ 282 public static StatusCode writeIntegerArray(String name, long[] values) { 283 return writeIntegerArray(name, values, ""); 284 } 285 /** 286 * Writes the array of integers to the log file. The array cannot exceed 8 elements. 287 * 288 * @param name Name of the signal 289 * @param values Array of values to write 290 * @param units Units of the signals 291 * @return Status of writing the data 292 */ 293 public static StatusCode writeIntegerArray(String name, long[] values, String units) { 294 return writeIntegerArray(name, values, units, 0); 295 } 296 /** 297 * Writes the array of integers to the log file. The array cannot exceed 8 elements. 298 * 299 * @param name Name of the signal 300 * @param values Array of values to write 301 * @param units Units of the signals 302 * @param latencySeconds Latency of the signal in seconds; this value is subtracted 303 * from the current time to get the timestamp written to the log 304 * @return Status of writing the data 305 */ 306 public static StatusCode writeIntegerArray(String name, long[] values, String units, double latencySeconds) { 307 return StatusCode.valueOf(SignalLoggerJNI.JNI_WriteIntegerArray(name, values, units, latencySeconds)); 308 } 309 310 /** 311 * Writes the array of floats to the log file. The array cannot exceed 16 elements. 312 * 313 * @param name Name of the signal 314 * @param values Array of values to write 315 * @return Status of writing the data 316 */ 317 public static StatusCode writeFloatArray(String name, float[] values) { 318 return writeFloatArray(name, values, ""); 319 } 320 /** 321 * Writes the array of floats to the log file. The array cannot exceed 16 elements. 322 * 323 * @param name Name of the signal 324 * @param values Array of values to write 325 * @param units Units of the signals 326 * @return Status of writing the data 327 */ 328 public static StatusCode writeFloatArray(String name, float[] values, String units) { 329 return writeFloatArray(name, values, units, 0); 330 } 331 /** 332 * Writes the array of floats to the log file. The array cannot exceed 16 elements. 333 * 334 * @param name Name of the signal 335 * @param values Array of values to write 336 * @param units Units of the signals 337 * @param latencySeconds Latency of the signal in seconds; this value is subtracted 338 * from the current time to get the timestamp written to the log 339 * @return Status of writing the data 340 */ 341 public static StatusCode writeFloatArray(String name, float[] values, String units, double latencySeconds) { 342 return StatusCode.valueOf(SignalLoggerJNI.JNI_WriteFloatArray(name, values, units, latencySeconds)); 343 } 344 345 /** 346 * Writes the array of doubles to the log file. The array cannot exceed 8 elements. 347 * 348 * @param name Name of the signal 349 * @param values Array of values to write 350 * @return Status of writing the data 351 */ 352 public static StatusCode writeDoubleArray(String name, double[] values) { 353 return writeDoubleArray(name, values, ""); 354 } 355 /** 356 * Writes the array of doubles to the log file. The array cannot exceed 8 elements. 357 * 358 * @param name Name of the signal 359 * @param values Array of values to write 360 * @param units Units of the signals 361 * @return Status of writing the data 362 */ 363 public static StatusCode writeDoubleArray(String name, double[] values, String units) { 364 return writeDoubleArray(name, values, units, 0); 365 } 366 /** 367 * Writes the array of doubles to the log file. The array cannot exceed 8 elements. 368 * 369 * @param name Name of the signal 370 * @param values Array of values to write 371 * @param units Units of the signals 372 * @param latencySeconds Latency of the signal in seconds; this value is subtracted 373 * from the current time to get the timestamp written to the log 374 * @return Status of writing the data 375 */ 376 public static StatusCode writeDoubleArray(String name, double[] values, String units, double latencySeconds) { 377 return StatusCode.valueOf(SignalLoggerJNI.JNI_WriteDoubleArray(name, values, units, latencySeconds)); 378 } 379}