Skip to content

Commit

Permalink
chirpc: Add CSV export option
Browse files Browse the repository at this point in the history
Pretty straight-forward, this leans on the `to_csv` method of the
`Memory` class to simply dump the content of the memory channels in the
memory map.
  • Loading branch information
sjlongland committed Jan 14, 2023
1 parent 69fde7e commit ec5dbe1
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions chirpc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import csv
import glob
import serial
import os
Expand Down Expand Up @@ -116,6 +117,9 @@ if __name__ == "__main__":
memarg.add_argument("--list-special-mem", action="store_true",
help="List all special memory locations")

memarg.add_argument("--export-csv", action="store_true",
help="Export memory channels to a CSV file")

memarg.add_argument("--raw", action="store_true",
help="Dump raw memory location")

Expand Down Expand Up @@ -255,6 +259,28 @@ if __name__ == "__main__":
print(mem)
sys.exit(0)

if options.export_csv:
if len(args) != 1:
LOG.error("Exactly one file name must be given.")
sys.exit(1)

with open(args[0], "w") as fileobj:
csvwriter = csv.writer(fileobj)

# Write the standard header
csvwriter.writerow(chirp_common.Memory.CSV_FORMAT)

# Write out all memory channels
rf = radio.get_features()
start, end = rf.memory_bounds
for i in range(start, end + 1):
mem = radio.get_memory(i)
# Skip empty channels
if mem.empty:
continue
csvwriter.writerow(mem.to_csv())
sys.exit(0)

if options.copy_mem:
src = parse_memory_number(radio, args)
dst = parse_memory_number(radio, args[1:])
Expand Down

0 comments on commit ec5dbe1

Please sign in to comment.