66 |
69 |
67 . ${ETHERCAT_CONFIG} |
70 . ${ETHERCAT_CONFIG} |
68 |
71 |
69 #------------------------------------------------------------------------------ |
72 #------------------------------------------------------------------------------ |
70 |
73 |
|
74 function exit_success() |
|
75 { |
|
76 if [ -r /etc/rc.status ]; then |
|
77 rc_reset |
|
78 rc_status -v |
|
79 rc_exit |
|
80 else |
|
81 echo " done" |
|
82 exit 0 |
|
83 fi |
|
84 } |
|
85 |
|
86 #------------------------------------------------------------------------------ |
|
87 |
|
88 function exit_running() |
|
89 { |
|
90 if [ -r /etc/rc.status ]; then |
|
91 rc_reset |
|
92 rc_status -v |
|
93 rc_exit |
|
94 else |
|
95 echo " running" |
|
96 exit 0 |
|
97 fi |
|
98 } |
|
99 |
|
100 #------------------------------------------------------------------------------ |
|
101 |
|
102 function exit_fail() |
|
103 { |
|
104 if [ -r /etc/rc.status ]; then |
|
105 rc_failed |
|
106 rc_exit |
|
107 else |
|
108 echo " failed" |
|
109 exit 1 |
|
110 fi |
|
111 } |
|
112 |
|
113 #------------------------------------------------------------------------------ |
|
114 |
71 function parse_mac_address() |
115 function parse_mac_address() |
72 { |
116 { |
73 if [ -z "${1}" ]; then |
117 if [ -z "${1}" ]; then |
74 MAC="" |
118 MAC="" |
75 elif echo ${1} | grep -qE '^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$'; then |
119 elif echo ${1} | grep -qE '^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$'; then |
76 MAC=${1} |
120 MAC=${1} |
77 else |
121 else |
78 echo Invalid MAC address \"${1}\" in ${ETHERCAT_CONFIG} |
122 echo Invalid MAC address \"${1}\" in ${ETHERCAT_CONFIG} |
79 /bin/false |
123 exit_fail |
80 rc_status -v |
|
81 rc_exit |
|
82 fi |
124 fi |
83 } |
125 } |
84 |
126 |
85 #------------------------------------------------------------------------------ |
127 #------------------------------------------------------------------------------ |
86 |
128 |
87 . /etc/rc.status |
129 if [ -r /etc/rc.status ]; then |
88 rc_reset |
130 . /etc/rc.status |
|
131 rc_reset |
|
132 fi |
89 |
133 |
90 case "${1}" in |
134 case "${1}" in |
91 |
135 |
92 start) |
136 start) |
93 echo -n "Starting EtherCAT master " |
137 echo -n "Starting EtherCAT master " |
133 mknod /dev/${XMLDEVICE}0 c ${MAJOR} 0 |
174 mknod /dev/${XMLDEVICE}0 c ${MAJOR} 0 |
134 |
175 |
135 # check for modules to replace |
176 # check for modules to replace |
136 for MODULE in ${DEVICE_MODULES}; do |
177 for MODULE in ${DEVICE_MODULES}; do |
137 ECMODULE=ec_${MODULE} |
178 ECMODULE=ec_${MODULE} |
138 if ! modinfo ${ECMODULE} > /dev/null; then |
179 if ! ${MODINFO} ${ECMODULE} > /dev/null; then |
139 continue |
180 continue # ec_* module not found |
140 fi |
181 fi |
141 if lsmod | grep "^${MODULE} " > /dev/null; then |
182 if lsmod | grep "^${MODULE} " > /dev/null; then |
142 if ! rmmod ${MODULE}; then |
183 if ! ${RMMOD} ${MODULE}; then |
143 /bin/false |
184 exit_fail |
144 rc_status -v |
|
145 rc_exit |
|
146 fi |
185 fi |
147 fi |
186 fi |
148 if ! modprobe ${ECMODULE}; then |
187 if ! ${MODPROBE} ${ECMODULE}; then |
149 modprobe ${MODULE} # try to restore module |
188 ${MODPROBE} ${MODULE} # try to restore module |
150 /bin/false |
189 exit_fail |
151 rc_status -v |
190 fi |
152 rc_exit |
191 done |
153 fi |
192 |
154 done |
193 exit_success |
155 |
|
156 rc_status -v |
|
157 ;; |
194 ;; |
158 |
195 |
159 stop) |
196 stop) |
160 echo -n "Shutting down EtherCAT master " |
197 echo -n "Shutting down EtherCAT master " |
161 |
198 |
162 # unload EtherCAT device modules |
199 # unload EtherCAT device modules |
163 for MODULE in ${DEVICE_MODULES} master; do |
200 for MODULE in ${DEVICE_MODULES} master; do |
164 ECMODULE=ec_${MODULE} |
201 ECMODULE=ec_${MODULE} |
165 if ! lsmod | grep -q "^${ECMODULE} "; then |
202 if ! lsmod | grep -q "^${ECMODULE} "; then |
166 continue |
203 continue # ec_* module not loaded |
167 fi |
204 fi |
168 if ! rmmod ${ECMODULE}; then |
205 if ! ${RMMOD} ${ECMODULE}; then |
169 /bin/false |
206 exit_fail |
170 rc_status -v |
|
171 rc_exit |
|
172 fi; |
207 fi; |
173 done |
208 done |
174 |
209 |
175 # remove device node |
210 # remove device node |
176 rm -f /dev/${XMLDEVICE}0 |
211 rm -f /dev/${XMLDEVICE}0 |
177 |
212 |
178 sleep 1 |
213 sleep 1 |
179 |
214 |
180 # reload previous modules |
215 # reload previous modules |
181 for MODULE in ${DEVICE_MODULES}; do |
216 for MODULE in ${DEVICE_MODULES}; do |
182 if ! modprobe ${MODULE}; then |
217 if ! ${MODPROBE} ${MODULE}; then |
183 echo Warning: Failed to restore ${MODULE}. |
218 echo Warning: Failed to restore ${MODULE}. |
184 fi |
219 fi |
185 done |
220 done |
186 |
221 |
187 rc_status -v |
222 exit_success |
188 ;; |
223 ;; |
189 |
224 |
190 restart) |
225 restart) |
191 $0 stop || exit 1 |
226 $0 stop || exit 1 |
192 sleep 1 |
227 sleep 1 |
193 $0 start |
228 $0 start |
194 rc_status |
|
195 ;; |
229 ;; |
196 |
230 |
197 status) |
231 status) |
198 echo -n "Checking for EtherCAT " |
232 echo -n "Checking for EtherCAT " |
199 |
233 |
202 |
236 |
203 ! grep -q "(WAITING)" /sys/ethercat/master*/info |
237 ! grep -q "(WAITING)" /sys/ethercat/master*/info |
204 MASTERS_IDLE=$? |
238 MASTERS_IDLE=$? |
205 |
239 |
206 # master module loaded and masters not waiting for devices? |
240 # master module loaded and masters not waiting for devices? |
207 test ${MASTERS_RUNNING} -eq 0 -a ${MASTERS_IDLE} -eq 0 |
241 if [ ${MASTERS_RUNNING} -eq 0 -a ${MASTERS_IDLE} -eq 0 ]; then |
208 |
242 exit_running |
209 rc_status -v |
243 else |
|
244 exit_fail |
|
245 fi |
210 ;; |
246 ;; |
211 |
247 |
212 *) |
248 *) |
213 echo "USAGE: $0 {start|stop|restart|status}" |
249 echo "USAGE: $0 {start|stop|restart|status}" |
214 ;; |
250 ;; |
215 |
251 |
216 esac |
252 esac |
217 |
253 |
218 rc_exit |
254 if [ -r /etc/rc.status ]; then |
219 |
255 rc_exit |
220 #------------------------------------------------------------------------------ |
256 else |
|
257 exit 1 |
|
258 fi |
|
259 |
|
260 #------------------------------------------------------------------------------ |