165 fsm->jiffies_start = datagram->jiffies_sent; |
165 fsm->jiffies_start = datagram->jiffies_sent; |
166 } |
166 } |
167 |
167 |
168 if (datagram->working_counter != 1) { |
168 if (datagram->working_counter != 1) { |
169 if (datagram->jiffies_received - fsm->jiffies_start >= 3 * HZ) { |
169 if (datagram->jiffies_received - fsm->jiffies_start >= 3 * HZ) { |
|
170 char state_str[EC_STATE_STRING_SIZE]; |
|
171 ec_state_string(fsm->requested_state, state_str); |
170 fsm->state = ec_fsm_change_error; |
172 fsm->state = ec_fsm_change_error; |
171 EC_ERR("Failed to set state 0x%02X on slave %i: Slave did not" |
173 EC_ERR("Failed to set state %s on slave %i: Slave did not" |
172 " respond.\n", fsm->requested_state, |
174 " respond.\n", state_str, fsm->slave->ring_position); |
173 fsm->slave->ring_position); |
|
174 return; |
175 return; |
175 } |
176 } |
176 |
177 |
177 // repeat writing new state to slave |
178 // repeat writing new state to slave |
178 ec_datagram_npwr(datagram, slave->station_address, 0x0120, 2); |
179 ec_datagram_npwr(datagram, slave->station_address, 0x0120, 2); |
221 return; |
222 return; |
222 } |
223 } |
223 |
224 |
224 if (slave->current_state & EC_SLAVE_STATE_ACK_ERR) { |
225 if (slave->current_state & EC_SLAVE_STATE_ACK_ERR) { |
225 // state change error |
226 // state change error |
226 EC_ERR("Failed to set state 0x%02X - Slave %i refused state change" |
227 char req_state[EC_STATE_STRING_SIZE], cur_state[EC_STATE_STRING_SIZE]; |
227 " (code 0x%02X)!\n", fsm->requested_state, slave->ring_position, |
228 ec_state_string(fsm->requested_state, req_state); |
228 slave->current_state); |
229 ec_state_string(slave->current_state, cur_state); |
|
230 EC_ERR("Failed to set %s state, slave %i refused state change (%s).\n", |
|
231 req_state, slave->ring_position, cur_state); |
229 // fetch AL status error code |
232 // fetch AL status error code |
230 ec_datagram_nprd(datagram, slave->station_address, 0x0134, 2); |
233 ec_datagram_nprd(datagram, slave->station_address, 0x0134, 2); |
231 ec_master_queue_datagram(fsm->slave->master, datagram); |
234 ec_master_queue_datagram(fsm->slave->master, datagram); |
232 fsm->state = ec_fsm_change_code; |
235 fsm->state = ec_fsm_change_code; |
233 return; |
236 return; |
234 } |
237 } |
235 |
238 |
236 if (datagram->jiffies_received |
239 if (datagram->jiffies_received |
237 - fsm->jiffies_start >= 100 * HZ / 1000) { // 100ms |
240 - fsm->jiffies_start >= 100 * HZ / 1000) { // 100ms |
238 // timeout while checking |
241 // timeout while checking |
239 fsm->state = ec_fsm_change_error; |
242 char state_str[EC_STATE_STRING_SIZE]; |
240 EC_ERR("Timeout while setting state 0x%02X on slave %i.\n", |
243 ec_state_string(fsm->requested_state, state_str); |
241 fsm->requested_state, slave->ring_position); |
244 fsm->state = ec_fsm_change_error; |
|
245 EC_ERR("Timeout while setting state %s on slave %i.\n", |
|
246 state_str, slave->ring_position); |
242 return; |
247 return; |
243 } |
248 } |
244 |
249 |
245 // still old state: check again |
250 // still old state: check again |
246 ec_datagram_nprd(datagram, slave->station_address, 0x0130, 2); |
251 ec_datagram_nprd(datagram, slave->station_address, 0x0130, 2); |
374 } |
379 } |
375 |
380 |
376 slave->current_state = EC_READ_U8(datagram->data); |
381 slave->current_state = EC_READ_U8(datagram->data); |
377 |
382 |
378 if (!(slave->current_state & EC_SLAVE_STATE_ACK_ERR)) { |
383 if (!(slave->current_state & EC_SLAVE_STATE_ACK_ERR)) { |
379 fsm->state = ec_fsm_change_error; |
384 char state_str[EC_STATE_STRING_SIZE]; |
380 EC_INFO("Acknowledged state 0x%02X on slave %i.\n", |
385 ec_state_string(slave->current_state, state_str); |
381 slave->current_state, slave->ring_position); |
386 fsm->state = ec_fsm_change_error; |
|
387 EC_INFO("Acknowledged state %s on slave %i.\n", |
|
388 state_str, slave->ring_position); |
382 return; |
389 return; |
383 } |
390 } |
384 |
391 |
385 if (datagram->jiffies_received |
392 if (datagram->jiffies_received |
386 - fsm->jiffies_start >= 100 * HZ / 1000) { // 100ms |
393 - fsm->jiffies_start >= 100 * HZ / 1000) { // 100ms |
|
394 char state_str[EC_STATE_STRING_SIZE]; |
|
395 ec_state_string(fsm->requested_state, state_str); |
387 // timeout while checking |
396 // timeout while checking |
388 slave->current_state = EC_SLAVE_STATE_UNKNOWN; |
397 slave->current_state = EC_SLAVE_STATE_UNKNOWN; |
389 fsm->state = ec_fsm_change_error; |
398 fsm->state = ec_fsm_change_error; |
390 EC_ERR("Timeout while acknowledging state 0x%02X on slave %i.\n", |
399 EC_ERR("Timeout while acknowledging state %s on slave %i.\n", |
391 fsm->requested_state, slave->ring_position); |
400 state_str, slave->ring_position); |
392 return; |
401 return; |
393 } |
402 } |
394 |
403 |
395 // reread new AL status |
404 // reread new AL status |
396 ec_datagram_nprd(datagram, slave->station_address, 0x0130, 2); |
405 ec_datagram_nprd(datagram, slave->station_address, 0x0130, 2); |