Commit d4930dda authored by Jean-Claude BAU's avatar Jean-Claude BAU

WR handshake improvements

- In case of handshake failure due to the reception of an unexpected
message, execute the same procedure executed in case of time-out. The
behavior will be more coherent.
- better diagnostics
parent f283f0e2
......@@ -39,8 +39,10 @@ int wr_calibrated(struct pp_instance *ppi, void *buf, int len, int new_state)
else if ((wrMsgId == WR_MODE_ON) &&
(wrp->wrMode == WR_SLAVE)) {
wrp->next_state = WRS_WR_LINK_ON;
} else
wrp->next_state = WRS_IDLE; // Unexpected msg: abort handshake
} else {
pp_diag(ppi, ext, 1, "WR: Invalid msgId(%d) received. CALIBRATE/WR_MODE_ON was expected\n",wrMsgId);
wr_handshake_fail(ppi);
}
return 0;
}
......@@ -50,8 +52,8 @@ int wr_calibrated(struct pp_instance *ppi, void *buf, int len, int new_state)
int rms=pp_next_delay_1(ppi, wrTmoIdx);
if ( rms<=(wrp->wrStateRetry*WR_TMO_MS)) {
if ( !rms ) {
wr_handshake_fail(ppi);
pp_diag(ppi, time, 1, "timeout expired: "WR_TMO_NAME"\n");
wr_handshake_fail(ppi);
return 0; /* non-wr already */
}
if (wr_handshake_retry(ppi))
......
......@@ -31,9 +31,12 @@ int wr_locked(struct pp_instance *ppi, void *buf, int len, int new_state)
MsgSignaling wrsig_msg;
if ( msg_unpack_wrsig(ppi, buf, &wrsig_msg, &wrMsgId) ) {
wrp->next_state= wrMsgId == CALIBRATE ?
WRS_RESP_CALIB_REQ :
WRS_IDLE;
if ( wrMsgId == CALIBRATE ) {
wrp->next_state= WRS_RESP_CALIB_REQ;
} else {
pp_diag(ppi, ext, 1, "WR: Invalid msgId(%d) received. CALIBRATE was expected\n",wrMsgId);
wr_handshake_fail(ppi);
}
return 0;
}
}
......@@ -42,8 +45,8 @@ int wr_locked(struct pp_instance *ppi, void *buf, int len, int new_state)
int rms=pp_next_delay_1(ppi, wrTmoIdx);
if ( rms<=(wrp->wrStateRetry*WR_TMO_MS)) {
if ( !rms ) {
wr_handshake_fail(ppi);
pp_diag(ppi, time, 1, "timeout expired: "WR_TMO_NAME"\n");
wr_handshake_fail(ppi);
return 0; /* non-wr already */
}
if (wr_handshake_retry(ppi))
......
......@@ -31,9 +31,12 @@ int wr_m_lock(struct pp_instance *ppi, void *buf, int len, int new_state)
MsgSignaling wrsig_msg;
if ( msg_unpack_wrsig(ppi, buf, &wrsig_msg,&wrMsgId) ) {
wrp->next_state = wrMsgId == LOCKED ?
WRS_CALIBRATION :
WRS_IDLE;
if (wrMsgId == LOCKED) {
wrp->next_state = WRS_CALIBRATION;
} else {
pp_diag(ppi, ext, 1, "WR: Invalid msgId(%d) received. LOCKED was expected\n",wrMsgId);
wr_handshake_fail(ppi);
}
return 0;
}
}
......@@ -42,8 +45,8 @@ int wr_m_lock(struct pp_instance *ppi, void *buf, int len, int new_state)
int rms=pp_next_delay_1(ppi, wrTmoIdx);
if ( rms<=(wrp->wrStateRetry*WR_TMO_MS)) {
if ( !rms ) {
wr_handshake_fail(ppi);
pp_diag(ppi, time, 1, "timeout expired: "WR_TMO_NAME"\n");
wr_handshake_fail(ppi);
return 0; /* non-wr already */
}
if (wr_handshake_retry(ppi))
......
......@@ -33,9 +33,12 @@ int wr_present(struct pp_instance *ppi, void *buf, int len, int new_state)
MsgSignaling wrsig_msg;
if ( msg_unpack_wrsig(ppi, buf, &wrsig_msg, &wrMsgId) ) {
wrp->next_state = wrMsgId == LOCK ?
WRS_S_LOCK :
WRS_IDLE;
if ( wrMsgId == LOCK ) {
wrp->next_state = WRS_S_LOCK;
} else {
pp_diag(ppi, ext, 1, "WR: Invalid msgId(%d) received. LOCK was expected\n",wrMsgId);
wr_handshake_fail(ppi);
}
return 0;
}
}
......@@ -44,8 +47,8 @@ int wr_present(struct pp_instance *ppi, void *buf, int len, int new_state)
int rms=pp_next_delay_1(ppi, wrTmoIdx);
if (rms<=(wrp->wrStateRetry*WR_TMO_MS)) {
if (!rms) {
wr_handshake_fail(ppi);
pp_diag(ppi, time, 1, "timeout expired: "WR_TMO_NAME"\n");
wr_handshake_fail(ppi);
return 0; /* non-wr already */
}
if (wr_handshake_retry(ppi))
......
......@@ -26,17 +26,19 @@ int wr_resp_calib_req(struct pp_instance *ppi, void *buf, int len, int new_state
if ( msg_unpack_wrsig(ppi, buf, &wrsig_msg, &wrMsgId) ) {
if ( wrMsgId == CALIBRATED) {
/* Update servo */
wr_servo_ext_t *se =WRE_SRV(ppi);
/* Update servo */
wr_servo_ext_t *se =WRE_SRV(ppi);
fixedDelta_to_pp_time(wrp->otherNodeDeltaTx,&se->delta_txm);
fixedDelta_to_pp_time(wrp->otherNodeDeltaRx,&se->delta_rxm);
fixedDelta_to_pp_time(wrp->otherNodeDeltaTx,&se->delta_txm);
fixedDelta_to_pp_time(wrp->otherNodeDeltaRx,&se->delta_rxm);
wrp->next_state = (wrp->wrMode == WR_MASTER) ?
WRS_WR_LINK_ON :
WRS_CALIBRATION;
} else
wrp->next_state = WRS_IDLE;
wrp->next_state = (wrp->wrMode == WR_MASTER) ?
WRS_WR_LINK_ON :
WRS_CALIBRATION;
} else {
pp_diag(ppi, ext, 1, "WR: Invalid msgId(%d) received. CALIBRATED was expected\n",wrMsgId);
wr_handshake_fail(ppi);
}
return 0;
}
}
......@@ -45,8 +47,8 @@ int wr_resp_calib_req(struct pp_instance *ppi, void *buf, int len, int new_state
int rms=pp_next_delay_1(ppi, wrTmoIdx);
if ( rms<=(wrp->wrStateRetry*WR_TMO_MS)) {
if ( !rms ) {
wr_handshake_fail(ppi);
pp_diag(ppi, time, 1, "timeout expired: "WR_TMO_NAME"\n");
wr_handshake_fail(ppi);
return 0; /* non-wr already */
}
wr_handshake_retry(ppi);
......
......@@ -33,8 +33,8 @@ int wr_s_lock(struct pp_instance *ppi, void *buf, int len, int new_state)
if ( rms<=(wrp->wrStateRetry*WR_TMO_MS)) {
WRH_OPER()->locking_disable(ppi);
if ( rms==0 ) {
wr_handshake_fail(ppi);
pp_diag(ppi, time, 1, "timeout expired: "WR_TMO_NAME"\n");
wr_handshake_fail(ppi);
return 0; /* non-wr already */
}
if (wr_handshake_retry(ppi))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment