test.sh
1 #!/bin/bash 2 3 rm -f gcode-output 4 5 linuxcnc -r linuxcncrsh-test.ini & 6 7 8 # let linuxcnc come up 9 TOGO=80 10 while [ $TOGO -gt 0 ]; do 11 echo trying to connect to linuxcncrsh TOGO=$TOGO 12 if nc -z localhost 5007; then 13 break 14 fi 15 sleep 0.25 16 TOGO=$(($TOGO - 1)) 17 done 18 if [ $TOGO -eq 0 ]; then 19 echo connection to linuxcncrsh timed out 20 exit 1 21 fi 22 23 # switch back and forth between tool 1 and tool 2 every few MDI calls 24 rm -f expected-gcode-output lots-of-gcode 25 printf "P is %.6f\n" -1 >> expected-gcode-output 26 NUM_MDIS=1 27 NUM_MDIS_LEFT=$NUM_MDIS 28 TOOL=1 29 for i in $(seq 0 1000); do 30 NUM_MDIS_LEFT=$(($NUM_MDIS_LEFT - 1)) 31 if [ $NUM_MDIS_LEFT -eq 0 ]; then 32 echo "set mdi t$TOOL m6" >> lots-of-gcode 33 if [ $TOOL -eq 1 ]; then 34 TOOL=2 35 else 36 TOOL=1 37 fi 38 39 NUM_MDIS=$(($NUM_MDIS + 1)) 40 if [ $NUM_MDIS -gt 10 ]; then 41 NUM_MDIS=1 42 fi 43 44 NUM_MDIS_LEFT=$NUM_MDIS 45 fi 46 echo "set mdi m100 p$i" >> lots-of-gcode 47 printf "P is %.6f\n" $i >> expected-gcode-output 48 done 49 printf "P is %.6f\n" -2 >> expected-gcode-output 50 51 ( 52 echo hello EMC mt 1.0 53 echo set enable EMCTOO 54 55 # ask linuxcncrsh to not read the next command until it's done running 56 # the current one 57 #echo set set_wait done 58 59 echo set mode manual 60 echo set estop off 61 echo set machine on 62 63 echo set mode mdi 64 echo set mdi m100 p-1 65 echo set wait done 66 67 # here comes a big blob 68 dd bs=4096 if=lots-of-gcode 69 70 echo set mdi m100 p-2 71 echo set wait done 72 73 echo shutdown 74 ) | nc localhost 5007 75 76 77 # wait for linuxcnc to finish 78 wait 79 80 exit 0 81