#!/bin/bash # # SN-L00 Autorouting Script using Freerouting # # Usage: # ./autoroute.sh # Uses default paths # ./autoroute.sh input.dsn # Custom input file # ./autoroute.sh input.dsn output.ses # # Prerequisites: # 1. Export DSN from KiCad: File → Export → Specctra DSN # 2. Java runtime installed # # After running: # Import the .ses file in KiCad: File → Import → Specctra Session # set -e SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_DIR="$(dirname "$SCRIPT_DIR")" FREEROUTING_JAR="${FREEROUTING_JAR:-/tmp/freerouting.jar}" FREEROUTING_URL="https://github.com/freerouting/freerouting/releases/download/v2.0.1/freerouting-2.0.1.jar" # Default input/output paths DSN_FILE="${1:-$PROJECT_DIR/SN-L00.dsn}" SES_FILE="${2:-${DSN_FILE%.dsn}.ses}" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color echo -e "${GREEN}SN-L00 Autorouting Script${NC}" echo "==========================================" # Check for Java if ! command -v java &> /dev/null; then echo -e "${RED}Error: Java is not installed${NC}" echo "Install with: sudo apt install default-jre" exit 1 fi # Download Freerouting if not present if [[ ! -f "$FREEROUTING_JAR" ]]; then echo -e "${YELLOW}Downloading Freerouting...${NC}" curl -sL -o "$FREEROUTING_JAR" "$FREEROUTING_URL" echo -e "${GREEN}Downloaded to $FREEROUTING_JAR${NC}" fi # Check for input DSN file if [[ ! -f "$DSN_FILE" ]]; then echo -e "${RED}Error: DSN file not found: $DSN_FILE${NC}" echo "" echo "To create the DSN file:" echo " 1. Open SN-L00.kicad_pcb in KiCad" echo " 2. File → Export → Specctra DSN" echo " 3. Save as: $DSN_FILE" echo "" echo "Then run this script again." exit 1 fi echo "Input: $DSN_FILE" echo "Output: $SES_FILE" echo "" # Run Freerouting in batch mode echo -e "${YELLOW}Running Freerouting (this may take a while)...${NC}" echo "" # Freerouting command-line options: # -de : Design input file (DSN) # -do : Design output file (SES) # -mp : Max routing passes (default: unlimited) # -mt : Max time in minutes (optional) # -oit : Order of routing: inside to outside # -us : Use saved rules from DSN file java -jar "$FREEROUTING_JAR" \ -de "$DSN_FILE" \ -do "$SES_FILE" \ -mp 100 \ -oit \ 2>&1 | while IFS= read -r line; do # Filter and display progress if [[ "$line" == *"Pass"* ]] || [[ "$line" == *"route"* ]] || [[ "$line" == *"via"* ]]; then echo " $line" fi done # Check if output was created if [[ -f "$SES_FILE" ]]; then echo "" echo -e "${GREEN}Routing complete!${NC}" echo "" echo "Output saved to: $SES_FILE" echo "" echo "Next steps:" echo " 1. Open SN-L00.kicad_pcb in KiCad" echo " 2. File → Import → Specctra Session" echo " 3. Select: $SES_FILE" echo " 4. Press 'B' to fill copper zones" echo " 5. Run DRC: Inspect → Design Rules Checker" else echo -e "${RED}Error: Routing failed - no output file created${NC}" echo "Try running Freerouting interactively:" echo " java -jar $FREEROUTING_JAR" exit 1 fi