Only for clarify my problem I add my “C” software routine
;----------------------------
State Machine
;----------------------------
switch (StatusSocket)
{
case 0:
if (StartSocketTimer==0)
{
app_socket_done=0;
StatusSocket++;
}
break;
case 1:
ABCC_AddCmdSeq( anb_asSocket, CbfSocketDone );
if (app_socket_done)
{
app_socket_done=0;
StatusSocket++;
}
break;
case 2:
ABCC_AddCmdSeq( anb_asSocketBind, CbfSocketDone );
if (app_socket_done)
{
app_socket_done=0;
StatusSocket++;
}
break;
case 3:
ABCC_AddCmdSeq( anb_asSocketListen, CbfSocketDone );
if (app_socket_done)
{
app_socket_done=0;
StartSocketTimer=5;
StatusSocket++;
}
break;
case 4:
if (StartSocketTimer==0)
{
ABCC_AddCmdSeq( anb_asSocketAccept, NULL );
StatusSocket++;
}
break;
case 5:
if (AcceptOK)
{
AcceptOK=0;
StatusSocket=10;
}
else if (anb_bSendSocketError==6)
{
Nop();
Nop();
StartSocketTimer=5;
StatusSocket–;
}
else
{
Nop();
}
break;
etc…
.
.
.
/*------------------------------------------------------------------------------
** Creates an Socket.
**------------------------------------------------------------------------------
** Arguments:
** psMsg - Message to send to ABCC.
**
** Returns:
** ABCC_CmdSeqCmdStatusType - Response for command callback.
**------------------------------------------------------------------------------
/
static ABCC_CmdSeqCmdStatusType CreateSocketCmd( ABP_MsgType psMsg )
{
ABCC_SetMsgHeader( psMsg,
ABP_OBJ_NUM_SOC,
0,
0, // 00h SOCK_STREAM, NON-BLOCKING (TCP)
3, // 03h CREATE
0,
ABCC_GetNewSourceId() );
return( ABCC_SEND_COMMAND );
}
/*------------------------------------------------------------------------------
** Processes a response to a CreateSocketCmd. Reads in and stores the new
** Socket instance number that was generated by the CreateSocketCmd.
**------------------------------------------------------------------------------
** Arguments:
** psMsg - Message received from the ABCC.
**
** Returns:
** ABCC_CmdSeqCmdStatusType - Response for command callback.
*------------------------------------------------------------------------------
/
static ABCC_CmdSeqRespStatusType HandleCreateSocketRsp( ABP_MsgType psMsg )
{
if( ABCC_VerifyMessage( psMsg ) == ABCC_EC_NO_ERROR )
{
/
** Successfully created a socket
** Store the created socket
*/
ABCC_GetMsgData16( psMsg, &anb_socket_Instance, 0 );
return( ABCC_EXEC_NEXT_COMMAND );
}
/*
** Something went wrong
/
return( ABCC_RESP_ABORT_SEQ );
}
/------------------------------------------------------------------------------
** Builds the command for setting the Bind Socket.
**
** This function is a part of a command sequence.
**------------------------------------------------------------------------------
/
static ABCC_CmdSeqCmdStatusType BindSocketCmd( ABP_MsgType psMsg )
{
ABCC_SetMsgHeader( psMsg,
ABP_OBJ_NUM_SOC,
anb_socket_Instance,
0, // Port number
16, // 10h BIND
0,
ABCC_GetNewSourceId() );
return( ABCC_SEND_COMMAND );
}
/*------------------------------------------------------------------------------
** Processes a response to a BindSocketCmd. Reads in and stores the Port number
**
**------------------------------------------------------------------------------
** Arguments:
** psMsg - Message received from the ABCC.
**
** Returns:
** ABCC_CmdSeqCmdStatusType - Response for command callback.
*------------------------------------------------------------------------------
/
static ABCC_CmdSeqRespStatusType HandleBindSocketRsp( ABP_MsgType psMsg )
{
if( ABCC_VerifyMessage( psMsg ) == ABCC_EC_NO_ERROR )
{
/
** Successfully port binded
** Store the port
*/
anb_socket_port=ABCC_GetMsgCmdExt( psMsg );
SocketPort= anb_socket_port;
return( ABCC_EXEC_NEXT_COMMAND );
}
/*
** Something went wrong
*/
return( ABCC_RESP_ABORT_SEQ );
}
/*------------------------------------------------------------------------------
** Builds the command for setting the Socket listen.
**
** This function is a part of a command sequence.
**------------------------------------------------------------------------------
/
static ABCC_CmdSeqCmdStatusType ListenSocketCmd( ABP_MsgType psMsg )
{
ABCC_SetMsgHeader( psMsg,
ABP_OBJ_NUM_SOC,
anb_socket_Instance,
0, //
18, // 12h LISTEN
0,
ABCC_GetNewSourceId() );
return( ABCC_SEND_COMMAND );
}
/*------------------------------------------------------------------------------
** Processes a response to a ListenSocketCmd.
**------------------------------------------------------------------------------
** Arguments:
** psMsg - Message received from the ABCC.
**
** Returns:
** ABCC_CmdSeqCmdStatusType - Response for command callback.
*------------------------------------------------------------------------------
/
static ABCC_CmdSeqRespStatusType HandleListenSocketRsp( ABP_MsgType psMsg )
{
if( ABCC_VerifyMessage( psMsg ) == ABCC_EC_NO_ERROR )
{
/
** Successfully port listen
**
*/
return( ABCC_EXEC_NEXT_COMMAND );
}
/*
** Something went wrong
*/
//return( ABCC_RESP_ABORT_SEQ );
return( ABCC_RESP_EWOULDBLOCK );
}
/*------------------------------------------------------------------------------
** Builds the command for setting the Accept Socket.
**------------------------------------------------------------------------------
/
static ABCC_CmdSeqCmdStatusType AcceptSocketCmd( ABP_MsgType psMsg )
{
ABCC_SetMsgHeader( psMsg,
ABP_OBJ_NUM_SOC,
anb_socket_Instance, //
0,
19, // 13h ACCEPT
0,
ABCC_GetNewSourceId() );
SocketSourceID=ABCC_GetMsgSourceId( psMsg );
return( ABCC_SEND_COMMAND );
}
/*------------------------------------------------------------------------------
** Processes a response to a AcceptSocketCmd. Reads in and stores the
** new Istance, IP number, Port number
**------------------------------------------------------------------------------
** Arguments:
** psMsg - Message received from the ABCC.
**
** Returns:
** ABCC_CmdSeqCmdStatusType - Response for command callback.
*------------------------------------------------------------------------------
/
static ABCC_CmdSeqRespStatusType HandleAcceptSocketRsp( ABP_MsgType psMsg )
{
if( ABCC_VerifyMessage( psMsg ) == ABCC_EC_NO_ERROR )
{
/
** Successfully port Accept
**
*/
ABCC_GetMsgData16( psMsg, &anb_newsocket_Instance, 0 );
ABCC_GetMsgData8( psMsg, &anb_socket_IP_Byte4, 2);
ABCC_GetMsgData8( psMsg, &anb_socket_IP_Byte3, 3);
ABCC_GetMsgData8( psMsg, &anb_socket_IP_Byte2, 4);
ABCC_GetMsgData8( psMsg, &anb_socket_IP_Byte1, 5);
ABCC_GetMsgData16( psMsg, &anb_newsocket_port, 6 );
AcceptOK= 1;
return( ABCC_EXEC_NEXT_COMMAND );
}
/*
** Something went wrong
*/
anb_bSendSocketError = ABCC_GetErrorCode2( psMsg );
return( ABCC_RESP_ABORT_SEQ );
}
Thank’s in advance who can help me