master/fsm_change.c
changeset 815 002fe9ec778f
parent 813 bfc3f1ab52de
child 986 a486591ba86b
equal deleted inserted replaced
814:a51f857b1b2d 815:002fe9ec778f
   155 
   155 
   156     fsm->take_time = 1;
   156     fsm->take_time = 1;
   157     fsm->old_state = fsm->slave->current_state;
   157     fsm->old_state = fsm->slave->current_state;
   158 
   158 
   159     // write new state to slave
   159     // write new state to slave
   160     ec_datagram_npwr(datagram, slave->station_address, 0x0120, 2);
   160     ec_datagram_fpwr(datagram, slave->station_address, 0x0120, 2);
   161     EC_WRITE_U16(datagram->data, fsm->requested_state);
   161     EC_WRITE_U16(datagram->data, fsm->requested_state);
   162     fsm->retries = EC_FSM_RETRIES;
   162     fsm->retries = EC_FSM_RETRIES;
   163     fsm->state = ec_fsm_change_state_check;
   163     fsm->state = ec_fsm_change_state_check;
   164 }
   164 }
   165 
   165 
   201             ec_datagram_print_wc_error(datagram);
   201             ec_datagram_print_wc_error(datagram);
   202             return;
   202             return;
   203         }
   203         }
   204 
   204 
   205         // repeat writing new state to slave
   205         // repeat writing new state to slave
   206         ec_datagram_npwr(datagram, slave->station_address, 0x0120, 2);
   206         ec_datagram_fpwr(datagram, slave->station_address, 0x0120, 2);
   207         EC_WRITE_U16(datagram->data, fsm->requested_state);
   207         EC_WRITE_U16(datagram->data, fsm->requested_state);
   208         fsm->retries = EC_FSM_RETRIES;
   208         fsm->retries = EC_FSM_RETRIES;
   209         return;
   209         return;
   210     }
   210     }
   211 
   211 
   220     }
   220     }
   221 
   221 
   222     fsm->take_time = 1;
   222     fsm->take_time = 1;
   223 
   223 
   224     // read AL status from slave
   224     // read AL status from slave
   225     ec_datagram_nprd(datagram, slave->station_address, 0x0130, 2);
   225     ec_datagram_fprd(datagram, slave->station_address, 0x0130, 2);
   226     fsm->retries = EC_FSM_RETRIES;
   226     fsm->retries = EC_FSM_RETRIES;
   227     fsm->spontaneous_change = 0;
   227     fsm->spontaneous_change = 0;
   228     fsm->state = ec_fsm_change_state_status;
   228     fsm->state = ec_fsm_change_state_status;
   229 }
   229 }
   230 
   230 
   296         ec_state_string(fsm->requested_state, req_state);
   296         ec_state_string(fsm->requested_state, req_state);
   297 
   297 
   298         EC_ERR("Failed to set %s state, slave %i refused state change (%s).\n",
   298         EC_ERR("Failed to set %s state, slave %i refused state change (%s).\n",
   299                req_state, slave->ring_position, cur_state);
   299                req_state, slave->ring_position, cur_state);
   300         // fetch AL status error code
   300         // fetch AL status error code
   301         ec_datagram_nprd(datagram, slave->station_address, 0x0134, 2);
   301         ec_datagram_fprd(datagram, slave->station_address, 0x0134, 2);
   302         fsm->retries = EC_FSM_RETRIES;
   302         fsm->retries = EC_FSM_RETRIES;
   303         fsm->state = ec_fsm_change_state_code;
   303         fsm->state = ec_fsm_change_state_code;
   304         return;
   304         return;
   305     }
   305     }
   306 
   306 
   316         return;
   316         return;
   317     }
   317     }
   318 
   318 
   319  check_again:
   319  check_again:
   320     // no timeout yet. check again
   320     // no timeout yet. check again
   321     ec_datagram_nprd(datagram, slave->station_address, 0x0130, 2);
   321     ec_datagram_fprd(datagram, slave->station_address, 0x0130, 2);
   322     fsm->retries = EC_FSM_RETRIES;
   322     fsm->retries = EC_FSM_RETRIES;
   323 }
   323 }
   324 
   324 
   325 /*****************************************************************************/
   325 /*****************************************************************************/
   326 
   326 
   415                                    /**< finite state machine */)
   415                                    /**< finite state machine */)
   416 {
   416 {
   417     ec_slave_t *slave = fsm->slave;
   417     ec_slave_t *slave = fsm->slave;
   418     ec_datagram_t *datagram = fsm->datagram;
   418     ec_datagram_t *datagram = fsm->datagram;
   419 
   419 
   420     ec_datagram_npwr(datagram, slave->station_address, 0x0120, 2);
   420     ec_datagram_fpwr(datagram, slave->station_address, 0x0120, 2);
   421     EC_WRITE_U16(datagram->data, slave->current_state);
   421     EC_WRITE_U16(datagram->data, slave->current_state);
   422     fsm->retries = EC_FSM_RETRIES;
   422     fsm->retries = EC_FSM_RETRIES;
   423     fsm->state = ec_fsm_change_state_ack;
   423     fsm->state = ec_fsm_change_state_ack;
   424 }
   424 }
   425 
   425 
   454     }
   454     }
   455 
   455 
   456     fsm->take_time = 1;
   456     fsm->take_time = 1;
   457 
   457 
   458     // read new AL status
   458     // read new AL status
   459     ec_datagram_nprd(datagram, slave->station_address, 0x0130, 2);
   459     ec_datagram_fprd(datagram, slave->station_address, 0x0130, 2);
   460     fsm->retries = EC_FSM_RETRIES;
   460     fsm->retries = EC_FSM_RETRIES;
   461     fsm->state = ec_fsm_change_state_check_ack;
   461     fsm->state = ec_fsm_change_state_check_ack;
   462 }
   462 }
   463 
   463 
   464 /*****************************************************************************/
   464 /*****************************************************************************/
   522                state_str, slave->ring_position);
   522                state_str, slave->ring_position);
   523         return;
   523         return;
   524     }
   524     }
   525 
   525 
   526     // reread new AL status
   526     // reread new AL status
   527     ec_datagram_nprd(datagram, slave->station_address, 0x0130, 2);
   527     ec_datagram_fprd(datagram, slave->station_address, 0x0130, 2);
   528     fsm->retries = EC_FSM_RETRIES;
   528     fsm->retries = EC_FSM_RETRIES;
   529 }
   529 }
   530 
   530 
   531 /*****************************************************************************/
   531 /*****************************************************************************/
   532 
   532