tools: Fix expected CSV field count in gonk-plot
The current CSV format added an extra field at the end for when GPIO
assert events occur. The plot script did not take this into account
and was logging error lines. This updates plot.py to the expected 24
fields per line.
Also added minor README adjustments added for clarity.
Change-Id: I08319e39adc7a7e133425470ce7d31f9417831ac
Reviewed-on: https://pigweed-review.googlesource.com/c/gonk/+/238424
Reviewed-by: Akira Baruah <akirabaruah@google.com>
Commit-Queue: Anthony DiGirolamo <tonymd@google.com>
Lint: Lint 🤖 <android-build-ayeaye@system.gserviceaccount.com>
diff --git a/README.md b/README.md
index 1a16e1e..e0515de 100644
--- a/README.md
+++ b/README.md
@@ -4,6 +4,10 @@
## Getting Started
+> **NOTE:** If you are using a `gonk_tools.zip` bundle follow the instructions in
+> the `//tools` directory:
+> https://pigweed.googlesource.com/gonk/+/refs/heads/main/tools/
+
1. Clone the repo
```sh
diff --git a/tools/README.md b/tools/README.md
index 79a9396..312e13c 100644
--- a/tools/README.md
+++ b/tools/README.md
@@ -25,14 +25,13 @@
### Logging
-By default two log files are created:
+By default these log files are created:
- Host log messages are set to: `--logfile gonk-host-log.txt`
- Device (logs from Gonk) are set to: `--device-logfile gonk-device-log.txt`
-- CSV output is set to: `--logfile gonk-csv-log.txt`
+- CSV output is set to: `--csv-logfile gonk-csv-log.txt`
-You can add ADC json output with the `--json-logfile gonk-device-logs.json`
-option.
+Optionally you can add ADC json output with `--json-logfile gonk-device-logs.json`
That will produce a json lines file with each line corresponding to one ADC
measurement event. For example:
@@ -66,7 +65,7 @@
### Start Logging ADC Measurements
```sh
-./python-venv/bin/gonk --log-to-stderr --bitstream-file DEFAULT
+gonk --log-to-stderr --bitstream-file DEFAULT
```
This will provision the FPGA and begin logging ADC measurements.
@@ -167,3 +166,11 @@
Pressing Enter again will resume continuous reading.
Ctrl-C will exit the gonk app.
+
+4. Plot the csv data from `gonk-csv-log.txt` with:
+
+ ```sh
+ gonk-plot -i gonk-csv-log.txt -o plot.svg
+ ```
+
+ Omit the svg output option to start an interactive matplotlib window.
diff --git a/tools/gonk_tools/plot.py b/tools/gonk_tools/plot.py
index e84b76d..ee47e6c 100644
--- a/tools/gonk_tools/plot.py
+++ b/tools/gonk_tools/plot.py
@@ -82,15 +82,21 @@
vshunt_values.append([])
power_values.append([])
+ # CSV Fields in order:
+ csv_field_count = 1 # For host timestamp
+ csv_field_count += 1 # For delta microseconds
+ csv_field_count += ADC_COUNT * 3 # Voltage, current, and power for each ADC
+ csv_field_count += 1 # For 'Header pin assert' string at the end
+
with input_csv.open() as f:
current_time = datetime.now()
for line in f.readlines():
parts = [line.strip() for line in line.split(',')]
- if len(parts) != ADC_COUNT * 3 + 2:
- _LOG.error('Unexpected number of CSV fields: %i', len(parts))
- _LOG.error('Fields: %s', parts)
- _LOG.error('Line: "%s"', line)
+ if len(parts) != csv_field_count:
+ _LOG.warning('Unexpected number of CSV fields: %i', len(parts))
+ _LOG.warning('Fields: %s', parts)
+ _LOG.warning('Line: "%s"', line)
# Extract the host timestamp
dtstr = parts[0]
@@ -115,6 +121,10 @@
current = list(float(i) for i in parts[index : index + ADC_COUNT])
index += ADC_COUNT
power = list(float(i) for i in parts[index : index + ADC_COUNT])
+ index += 1
+
+ # TODO(tonymd): Plot GPIO events somehow.
+ _gpio_assert = parts[index]
for i, voltage in enumerate(voltages):
vbus_values[i].append(voltage)