Skip to content

Commit

Permalink
added FMS match info in snapshot name
Browse files Browse the repository at this point in the history
added FMS match info in snapshot name

reverted unwanted changes

added data validation

Address review comments
  • Loading branch information
OfirSiboni authored and mcm001 committed Jan 4, 2023
1 parent 326701b commit 9020829
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ public void accept(NetworkTableEvent event) {
}
}

public NetworkTableInstance getNTInst() {
return ntInstance;
}

public void broadcastConnectedStatus() {
TimedTaskManager.getInstance().addOneShotTask(this::broadcastConnectedStatusImpl, 1000L);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@

package org.photonvision.vision.frame.consumer;

import edu.wpi.first.math.MathUtil;
import edu.wpi.first.networktables.IntegerEntry;
import edu.wpi.first.networktables.NetworkTable;
import edu.wpi.first.networktables.NetworkTableEntry;
import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
Expand All @@ -35,8 +37,17 @@ public class FileSaveFrameConsumer implements Consumer<CVMat> {
// Formatters to generate unique, timestamped file names
private static String FILE_PATH = ConfigManager.getInstance().getImageSavePath().toString();
private static String FILE_EXTENSION = ".jpg";

private final NetworkTable fmsTable =
NetworkTablesManager.getInstance().getNTInst().getTable("FMSInfo");

DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
DateFormat tf = new SimpleDateFormat("hhmmssSS");
private final NetworkTableEntry ntMatchNum;
private final NetworkTableEntry ntMatchType;
private final String[] matchTypes = {
"N/A", "P", "Q", "E", "EV"
}; // match type's values from the FMS.
private final String NT_SUFFIX = "SaveImgCmd";
private final String ntEntryName;
private NetworkTable subTable;
Expand All @@ -51,6 +62,8 @@ public FileSaveFrameConsumer(String camNickname, String streamPrefix) {
this.fnamePrefix = camNickname + "_" + streamPrefix;
this.ntEntryName = streamPrefix + NT_SUFFIX;
this.rootTable = NetworkTablesManager.getInstance().kRootTable;
this.ntMatchNum = fmsTable.getEntry("MatchNumber");
this.ntMatchType = fmsTable.getEntry("MatchType");
updateCameraNickname(camNickname);
this.logger = new Logger(FileSaveFrameConsumer.class, this.camNickname, LogGroup.General);
}
Expand All @@ -72,6 +85,8 @@ public void accept(CVMat image) {
+ df.format(now)
+ "T"
+ tf.format(now)
+ "_"
+ getMatchData()
+ FILE_EXTENSION;

// write to file
Expand Down Expand Up @@ -102,4 +117,17 @@ public void updateCameraNickname(String newCameraNickname) {
this.subTable.getEntry(ntEntryName).setInteger(imgSaveCountInternal);
this.entry = subTable.getIntegerTopic(ntEntryName).getEntry(-1); // Default negative
}

private String getMatchData() {
/**
* Returns the match Data collected from the NT. eg : Q58 for qualfication match 58. If not in
* event, returns N/A-0
*/
int matchTypeIndex = (int) ntMatchType.getDouble(0);
matchTypeIndex = MathUtil.clamp(matchTypeIndex, 0, matchTypes.length - 1);

String matchType = matchTypes[matchTypeIndex];
String matchNum = String.valueOf(ntMatchNum.getDouble(0));
return matchType + "-" + matchNum;
}
}

0 comments on commit 9020829

Please sign in to comment.