master/fsm_change.c
changeset 738 880c6153101f
parent 713 ae41cadd25b6
child 798 5a58606726f3
equal deleted inserted replaced
737:5a770085161c 738:880c6153101f
    64                         ec_datagram_t *datagram /**< datagram */
    64                         ec_datagram_t *datagram /**< datagram */
    65                         )
    65                         )
    66 {
    66 {
    67     fsm->state = NULL;
    67     fsm->state = NULL;
    68     fsm->datagram = datagram;
    68     fsm->datagram = datagram;
       
    69     fsm->spontaneous_change = 0;
    69 }
    70 }
    70 
    71 
    71 /*****************************************************************************/
    72 /*****************************************************************************/
    72 
    73 
    73 /**
    74 /**
   221     fsm->take_time = 1;
   222     fsm->take_time = 1;
   222 
   223 
   223     // read AL status from slave
   224     // read AL status from slave
   224     ec_datagram_nprd(datagram, slave->station_address, 0x0130, 2);
   225     ec_datagram_nprd(datagram, slave->station_address, 0x0130, 2);
   225     fsm->retries = EC_FSM_RETRIES;
   226     fsm->retries = EC_FSM_RETRIES;
       
   227     fsm->spontaneous_change = 0;
   226     fsm->state = ec_fsm_change_state_status;
   228     fsm->state = ec_fsm_change_state_status;
   227 }
   229 }
   228 
   230 
   229 /*****************************************************************************/
   231 /*****************************************************************************/
   230 
   232 
   279 
   281 
   280         if ((slave->current_state & 0x0F) != (fsm->old_state & 0x0F)) {
   282         if ((slave->current_state & 0x0F) != (fsm->old_state & 0x0F)) {
   281             // Slave spontaneously changed its state just before the new state
   283             // Slave spontaneously changed its state just before the new state
   282             // was written. Accept current state as old state and wait for
   284             // was written. Accept current state as old state and wait for
   283             // state change
   285             // state change
       
   286             fsm->spontaneous_change = 1;
   284             fsm->old_state = slave->current_state;
   287             fsm->old_state = slave->current_state;
   285             EC_WARN("Slave %i changed to %s in the meantime.\n",
   288             EC_WARN("Slave %i changed to %s in the meantime.\n",
   286                     slave->ring_position, cur_state);
   289                     slave->ring_position, cur_state);
   287             goto again;
   290             goto check_again;
   288         }
   291         }
   289 
   292 
   290         // state change error
   293         // state change error
   291 
   294 
   292         slave->error_flag = 1;
   295         slave->error_flag = 1;
   307         // timeout while checking
   310         // timeout while checking
   308         char state_str[EC_STATE_STRING_SIZE];
   311         char state_str[EC_STATE_STRING_SIZE];
   309         ec_state_string(fsm->requested_state, state_str);
   312         ec_state_string(fsm->requested_state, state_str);
   310         fsm->state = ec_fsm_change_state_error;
   313         fsm->state = ec_fsm_change_state_error;
   311         EC_ERR("Timeout while setting state %s on slave %i.\n",
   314         EC_ERR("Timeout while setting state %s on slave %i.\n",
   312                state_str, slave->ring_position);
   315                 state_str, slave->ring_position);
   313         return;
   316         return;
   314     }
   317     }
   315 
   318 
   316  again:
   319  check_again:
   317     // no timeout yet. check again
   320     // no timeout yet. check again
   318     ec_datagram_nprd(datagram, slave->station_address, 0x0130, 2);
   321     ec_datagram_nprd(datagram, slave->station_address, 0x0130, 2);
   319     fsm->retries = EC_FSM_RETRIES;
   322     fsm->retries = EC_FSM_RETRIES;
   320 }
   323 }
   321 
   324