#!/bin/bash source="$1" # laser settings height="Z6.5" rate="F372" pwm="S24000" list=`grep -A100 "^exit" "$0" | grep "^T" ` nl=$'\n'; vt=$'\v' n=0; part=0 error="none" echo "" date if [ -z "$1" ]; then tmp="${0%/*}" cd "$tmp" source=`ls -t *.nc | grep -v "MOD" | head -1 ` if [ -z "$source" ]; then echo "No file" exit else source="$tmp/$source" fi fi echo "Processing $source" file="${source%.*}MOD.${source##*.}" head="${source%.*}MOD-$part-head.${source##*.}" filep="$head" rm -rf "${source%.*}MOD-*" state="none" on="G0${nl}M03 S0${nl}M0 ; Switch to LASER" off="G0${nl}M04 S0${nl}M0 ; Switch to SPINDLE" pause="M05 S0${nl}M09$nl" date "+(%+)%n(${source##*/})%n(1)%n(2)%n(3)%n(4)%n(5)%n(6)%n(7)%n(8)%n(9)" > "$head" cp "$head" "$file" head -1 "$file" while read -r line; do let n=n+1 if [[ "x$line" =~ "M0 ;T" ]]; then tool=`echo "$line" | cut -d";" -f2` line="$pause$line $tmp" case "a$tool" in aT99*) tool="T990" line="$line$nl$on" state="laser" ;; aT98*) tool="T980" line="$line$nl$off" state="skip" ;; *) line="$line$nl$off" state="spindle" ;; esac tmp=`echo "$list" | grep "$tool" | cut -f2 ` if [ -z "$tmp" ]; then # if tool code is not in the list at the end of this file error="$error$nl[$tool] $line" tmp="TOOL?" fi echo "$tail" >> "$filep" let part=part+1 it=`echo "$tmp" | tr " /" "_%" ` filep="${source%.*}MOD-$part-$tool-$it.${source##*.}" cp "$head" "$filep" tail="$pause${nl}M02 ${nl}(END $tool $tmp)" printf "\nLine: $n $line $state\n" else if [ "x$state" == "xlaser" ]; then if [[ $line =~ S ]]; then nline=`echo "$line" | sed -e "s/S[0-9.]*/$pwm/g"`"$nl$height$rate$nl" line="$nline" fi if [[ $line =~ Z ]]; then nline=`echo "$line" | sed -e "s/Z[0-9.-]*/$height/g"` line="$nline" fi if [[ $line =~ F ]]; then nline=`echo "$line" | sed -e "s/F[0-9.]*/$rate/g"` line="$nline" fi fi fi echo "$line " >> "$filep" if [ "x$state" != "xskip" ]; then echo "$line " >> "$file" fi done < "$source" echo "$tail" >> "$filep" line=`wc -l "$file"` tmp=`date "+( END lines =$line @ %+ )" ` echo "$pause$tmp" >> "$file" # tail -10 "$file" echo "${nl}Unknown Tools: $error $nl" exit T101 1/8 Ball T102 1/8 End T111 1/16 Ball T112 1/16 End T121 1/32 Ball T122 1/32 End T201 1/4 End T202 1/4 Ball T205 1/4 End T301 90 Vee T302 60 Vee T970 60V0.3 Eng T980 Skip T990 Laser