Skip to content

Commit

Permalink
make it work for WBO too!
Browse files Browse the repository at this point in the history
  • Loading branch information
mck1117 committed Dec 9, 2024
1 parent b5562c3 commit 48ee208
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 13 deletions.
12 changes: 6 additions & 6 deletions firmware/controllers/sensors/wideband_state.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
struct_no_prefix wideband_state_s
uint8_t faultCode;WBO: Fault code
uint8_t faultCode;Fault code

uint8_t heaterDuty;WBO: Heater duty;"%", 1, 0, 0, 100, 0
uint8_t pumpDuty;WBO: Pump duty;"%", 1, 0, 0, 100, 0
uint8_t heaterDuty;Heater duty;"%", 1, 0, 0, 100, 0
uint8_t pumpDuty;Pump duty;"%", 1, 0, 0, 100, 0

uint16_t tempC;WBO: Temperature;"C", 1, 0, 500, 1000, 0
uint16_t autoscale nernstVoltage;WBO: Nernst Voltage;"V", 0.001, 0, 0, 1, 3
uint16_t esr;WBO: ESR;"ohm", 1, 0, 0, 10000, 0
uint16_t tempC;Temperature;"C", 1, 0, 500, 1000, 0
uint16_t autoscale nernstVoltage;Nernst Voltage;"V", 0.001, 0, 0, 1, 3
uint16_t esr;ESR;"ohm", 1, 0, 0, 10000, 0
end_struct
2 changes: 1 addition & 1 deletion firmware/integration/LiveData.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Usages:

- name: wideband_state
folder: controllers/sensors/
# output_name: [ "wb1", "wb2" ]
output_name: [ "WBO 1", "WBO 2" ]

- name: dc_motors
folder: controllers/actuators
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
import java.io.PrintStream;

public class DatalogVisitor extends OutputChannelVisitorBase {
private static void writeDatalogName(PrintStream ps, String name, String comment) {
public DatalogVisitor(String nameReplace) {
super(nameReplace);
}

private void writeDatalogName(PrintStream ps, String name, String comment) {
ps.print(buildDatalogName(name, comment));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
import java.io.PrintStream;

public class OutputChannelVisitor extends OutputChannelVisitorBase {
public OutputChannelVisitor(String nameReplace) {
super(nameReplace);
}

@Override
public void visit(EnumLayout e, PrintStream ps, StructNamePrefixer prefixer, int offsetAdd, int[] arrayDims) {
// Output an enum as a scalar, since there's no TS support for enum output channels
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@
import java.io.PrintStream;

public class OutputChannelVisitorBase extends ILayoutVisitor {
public static String buildDatalogName(String name, String comment) {
String text = (comment == null || comment.isEmpty()) ? name : comment;
protected final NameReplacer nameReplacer;

public OutputChannelVisitorBase(String nameReplace) {
this.nameReplacer = new NameReplacer(nameReplace);
}

public String buildDatalogName(String name, String comment) {
String text = (comment == null || comment.isEmpty()) ? name : nameReplacer.replace(comment);

// Delete anything after a newline
return text.split("\\\\n")[0];
Expand All @@ -27,4 +33,20 @@ public void visit(StructLayout struct, PrintStream ps, StructNamePrefixer prefix
throw new IllegalStateException("Output channels don't support multi dimension arrays");
}
}

protected class NameReplacer {
public final String name;

public NameReplacer(String name) {
this.name = name;
}

public String replace(String input) {
if (name == null || name.isEmpty()) {
return input;
}

return name + ": " + input;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ public void writeOutputChannels(ParseState parser, String namePrefix) {
StructNamePrefixer prefixer = new StructNamePrefixer('_');

if (namePrefix != null) {
prefixer.push(namePrefix);
prefixer.push(namePrefix.replace(" ", "_"));
}

OutputChannelVisitor v = new OutputChannelVisitor();
OutputChannelVisitor v = new OutputChannelVisitor(namePrefix);
sl.visit(v, ps, prefixer, cumulativeSize, new int[0]);

DatalogVisitor dlv = new DatalogVisitor();
DatalogVisitor dlv = new DatalogVisitor(namePrefix);
sl.visit(dlv, psDatalog, prefixer, cumulativeSize, new int[0]);

cumulativeSize += sl.getSize();
Expand Down

0 comments on commit 48ee208

Please sign in to comment.