diff --git a/TODO b/TODO index 40a2351dd88699fc61a914d5c800221e08b94da1..139b5aa119ecf49d192a52f3332aeceabe74b981 100644 --- a/TODO +++ b/TODO @@ -8,8 +8,6 @@ $Id$ Version 1.4.0: -* Abort code messages in userspace. -* Repair rcethercat status. * Attach Pdo names from SII or Coe dictionary to Pdos read via CoE. * Update documentation. * Check for possible race condition in jiffy-based frame timeout calculation. @@ -17,10 +15,10 @@ Version 1.4.0: Future issues: * Distributed clocks. -* Allow master requesting when in ORPHANED phase +* Implement user space realtime interface via cdev. * Move master threads, slave handlers and state machines into a user space daemon. -* Implement user space realtime interface via cdev. +* Allow master requesting when in ORPHANED phase * Mailbox protocol handlers. * Mailbox state machine using toggle bits. * Mailbox gateway. diff --git a/configure.ac b/configure.ac index 67126da0df2eb6ff569f8c160c7002f6a1fa4f2e..5c739bda6be072ddd934dbc37b8e9aaa8835c49b 100644 --- a/configure.ac +++ b/configure.ac @@ -503,6 +503,7 @@ AC_CONFIG_FILES([ master/Makefile script/Makefile script/init.d/Makefile + script/init.d/ethercat script/sysconfig/Makefile tool/Makefile ]) diff --git a/script/init.d/Makefile.am b/script/init.d/Makefile.am index a98c43cbb74b8543ed68e4cbe8444eef738d0377..a9af36d834ec8f378dcf141ca0c3d8c80763e486 100644 --- a/script/init.d/Makefile.am +++ b/script/init.d/Makefile.am @@ -35,6 +35,8 @@ initdir = $(sysconfdir)/init.d init_SCRIPTS = ethercat -EXTRA_DIST = ethercat +EXTRA_DIST = ethercat.in + +BUILT_SOURCES = ethercat #------------------------------------------------------------------------------ diff --git a/script/init.d/ethercat b/script/init.d/ethercat.in similarity index 85% rename from script/init.d/ethercat rename to script/init.d/ethercat.in index abd1f98596f07961cf6bf50134a04bb845e6828f..88f88b1d4b315817e5df851d68636387746698c0 100755 --- a/script/init.d/ethercat +++ b/script/init.d/ethercat.in @@ -43,8 +43,8 @@ # Should-Stop: $time ntp # Default-Start: 3 5 # Default-Stop: 0 1 2 6 -# Short-Description: EtherCAT Master -# Description: +# Short-Description: EtherCAT master +# Description: EtherCAT master @VERSION@ ### END INIT INFO #------------------------------------------------------------------------------ @@ -52,6 +52,7 @@ MODPROBE=/sbin/modprobe RMMOD=/sbin/rmmod MODINFO=/sbin/modinfo +ETHERCAT=@prefix@/bin/ethercat #------------------------------------------------------------------------------ @@ -84,43 +85,39 @@ function exit_success() #------------------------------------------------------------------------------ -function exit_running() +function exit_fail() { if [ -r /etc/rc.status ]; then - rc_reset + rc_failed rc_status -v rc_exit else - echo " running" - exit 0 + echo " failed" + exit 1 fi } #------------------------------------------------------------------------------ -function exit_fail() +function print_running() { if [ -r /etc/rc.status ]; then - rc_failed + rc_reset rc_status -v - rc_exit else - echo " failed" - exit 1 + echo " running" fi } #------------------------------------------------------------------------------ -function exit_dead() +function print_dead() { if [ -r /etc/rc.status ]; then rc_failed rc_status -v - rc_exit else echo " dead" - exit 1 fi } @@ -148,7 +145,7 @@ fi case "${1}" in start) - echo -n "Starting EtherCAT master " + echo -n "Starting EtherCAT master @VERSION@" # construct DEVICES and BACKUPS from configuration variables DEVICES="" @@ -200,7 +197,7 @@ start) ;; stop) - echo -n "Shutting down EtherCAT master " + echo -n "Shutting down EtherCAT master @VERSION@" # unload EtherCAT device modules for MODULE in ${DEVICE_MODULES} master; do @@ -232,20 +229,35 @@ restart) ;; status) - echo -n "Checking for EtherCAT " + echo "Checking for EtherCAT master @VERSION@" + + # count masters in configuration file + MASTER_COUNT=0 + while true; do + DEVICE=$(eval echo "\${MASTER${MASTER_COUNT}_DEVICE}") + if [ -z "${DEVICE}" ]; then break; fi + MASTER_COUNT=$(expr ${MASTER_COUNT} + 1) + done - lsmod | grep -q "^ec_master " - MASTERS_RUNNING=$? + RESULT=0 - ! grep -q "(WAITING)" /sys/ethercat/master*/info - MASTERS_IDLE=$? + for i in `seq 0 $(expr ${MASTER_COUNT} - 1)`; do + echo -n "Master${i}" + + # Check if the master is in idle or operation phase + ${ETHERCAT} master --master ${i} 2>/dev/null | \ + grep -qE 'Phase:[[:space:]]*Idle|Phase:[[:space:]]*Operation' + EXITCODE=$? + + if [ ${EXITCODE} -eq 0 ]; then + print_running + else + print_dead + RESULT=1 + fi + done - # master module loaded and masters not waiting for devices? - if [ ${MASTERS_RUNNING} -eq 0 -a ${MASTERS_IDLE} -eq 0 ]; then - exit_running - else - exit_dead - fi + exit ${RESULT} ;; *)