#!/bin/bash # ============================================================================= # gen_channel_map.sh - Build docs/LTC2980_channel_map.csv from settings/*.conf # Version : V1.0.0 # Date : 2026-08-27 # Author : ETWen # ============================================================================= # Runs on the DEV machine, not the DUT. Reads every LTC2980 margin settings # file and flattens CH_VNOM / CH_NET into one CSV: # # Board,CONN,Ch,NetName,Vnom # CB,CONN13,CH0,V5P0_ALW,5.0 # # NC channels keep their literal NC / "-" so the page numbering still lines up # (ch/8 -> CHIPS[] index, ch%8 -> LTC2977 PAGE). Do not filter them out. # # Usage: # tools/gen_channel_map.sh # write docs/LTC2980_channel_map.csv # tools/gen_channel_map.sh - # write to stdout # ============================================================================= set -eu REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)" SET_DIR="${REPO_ROOT}/src/Script_ABC_Blanton/Blanton_Script/LTC2980_Margin_Script/settings" OUT="${1:-${REPO_ROOT}/docs/LTC2980_channel_map.csv}" [ -d "${SET_DIR}" ] || { echo "settings dir not found: ${SET_DIR}" >&2; exit 1; } # 3-argument match(str, regex, array) is a gawk extension. Under mawk it is a # syntax error at best and an empty CSV at worst - fail loudly instead. awk 'BEGIN { if (match("a", /a/, m) != 1) exit 1 }' 2>/dev/null \ || { echo "need gawk (3-arg match); this awk is: $(awk --version 2>&1 | head -1)" >&2; exit 1; } gen() { printf 'Board,CONN,Ch,NetName,Vnom\n' # CB first, then SWB0/SWB1 CONN13..CONN16 - matches the physical walk order. for f in "${SET_DIR}"/Blanton_CB_CONN*.conf \ "${SET_DIR}"/Blanton_SWB0_CONN*.conf \ "${SET_DIR}"/Blanton_SWB1_CONN*.conf ; do [ -f "${f}" ] || continue base="$(basename "${f}" .conf)" # Blanton_SWB0_CONN13 board="$(echo "${base}" | cut -d_ -f2)" # SWB0 conn="$(echo "${base}" | cut -d_ -f3)" # CONN13 # .conf files are LF per .gitattributes, but strip CR anyway - a stray # CR would land inside the net name and travel into the CSV unseen. sed 's/\r$//' "${f}" | awk -v b="${board}" -v c="${conn}" ' match($0, /^CH([0-9]+)_VNOM="([^"]*)"[^"]*CH[0-9]+_NET="([^"]*)"/, m) { printf "%s,%s,CH%s,%s,%s\n", b, c, m[1], m[3], m[2] }' done } if [ "${OUT}" = "-" ]; then gen else gen > "${OUT}" echo "wrote ${OUT} ($(($(wc -l < "${OUT}") - 1)) channels)" fi