Hi All. I am making the TCP client on Maestro100(Q24). Modem must connect to the server on voice call.
Program working good, but only one day. On the next day connection cannot be established.
static void evh( wip_event_t *ev, void *ctx) {
char snd_buffer[SND_BUFFER_SIZE];
switch( ev->kind) {
case WIP_CEV_OPEN: {
adl_atSendResponse(ADL_AT_RSP,"WIP_CEV_OPEN\r\n");
GPRS_CHANEL_Open=TRUE;
break;
}
case WIP_CEV_READ: {
int nread;
adl_atSendResponse(ADL_AT_RSP,"WIP_CEV_READ\r\n");
nread = wip_read( ev->channel, rcv_buffer ,
sizeof( rcv_buffer));//+ rcv_offset - rcv_offset
if( nread < 0) {
return; }
rcv_offset = nread;
break;
}
case WIP_CEV_WRITE: {
int nwrite;
adl_atSendResponse(ADL_AT_RSP,"WIP_CEV_WRITE\r\n");
GPRS_CanWrite=1;
ConectToGPRSagain=FALSE;
NumOfConnectGPRS=0;
break;
}
case WIP_CEV_ERROR: {
adl_atSendResponse(ADL_AT_RSP,"WIP_CEV_ERROR\r\n");
if (GPRSConnStarted) adl_tmrSubscribe ( FALSE, 1, ADL_TMR_TYPE_100MS, GprsStopConnection);
break;
}
case WIP_CEV_PEER_CLOSE: {
adl_atSendResponse(ADL_AT_RSP,"WIP_CEV_PEER_CLOSE\r\n");
if (GPRSConnStarted) adl_tmrSubscribe ( FALSE, 1, ADL_TMR_TYPE_100MS, GprsStopConnection);
break;
}
}
}
void GprsStopConnection(u8 ID)
{
if (GPRSConnStarted)
{
adl_atSendResponse (ADL_AT_RSP,"GprsStopConnection\r\n");
GPRSConnStarted=FALSE;
if (WipConnects)
{
wip_abort(ev_channel);
wip_close( ev_channel);
}
/* Close the GPRS bearer */
wip_bearerClose(GPRSBearer);
GPRS_CHANEL_Open=FALSE;
GPRS_CanWrite=0;
ComConection=0;
WipConnects=FALSE;
if ((ConectToGPRSagain)&&(NumOfConnectGPRS>0))
{
adl_atSendResponse (ADL_AT_RSP,"ConnectAgain\r\n");
adl_tmrSubscribe ( FALSE, TIME_CONNECT_AGAIN, ADL_TMR_TYPE_100MS, ConnectByTimer );
}
else
{
adl_atSendResponse (ADL_AT_RSP,"!ConnectAgain\r\n");
ModemConnect_Flag=0;
}
}
/* De-initialise the WIP library */
wip_netExit();
}
static void evh_bearer( wip_bearer_t b, s8 event, void *ctx) {
if( WIP_BEV_IP_CONNECTED == event)
{
wip_channel_t socket;
u16 PortNumber;
ascii *a[160];
GPRS_Server_params *My_GPRS_Server=adl_memGet(sizeof(GPRS_Server_params));
adl_atSendResponse(ADL_AT_RSP,"WIP_BEV_IP_CONNECTED");
WipConnects=TRUE;
{
Read_GPRS_Server_fromFlh(My_GPRS_Server);
PortNumber=atoi(My_GPRS_Server->ServerPort);
}
socket = wip_TCPClientCreate( My_GPRS_Server->ServerStrAddr,PortNumber,evh, NULL);
if( ! socket) {
adl_atSendResponse(ADL_AT_RSP,"[SAMPLE] Can't connect\r\n");
}
else
{
adl_atSendResponse(ADL_AT_RSP,"[SAMPLE] connect can be\r\n");
ComConection=1;
}
ev_channel=socket;
adl_memRelease(My_GPRS_Server);
}
else
{
adl_atSendResponse(ADL_AT_RSP,"Evh_bearer_STOP\r\n");
if (GPRSConnStarted) adl_tmrSubscribe ( FALSE, 1, ADL_TMR_TYPE_100MS, GprsStopConnection);
}
}
//Begining GPRS connection
s8 InitConnection(u8 Id)
{
if (full_sim_init)
{
s8 sRet=0;
GPRS_params *My_GPRS=adl_memGet(sizeof(GPRS_params));
adl_atSendResponse(ADL_AT_RSP,"[SAMPLE] full_sim_init==TRUE\r\n");
if (NumOfConnectGPRS>0) adl_atSendResponse (ADL_AT_RSP,"NumOfConnectGPRS>0\r\n");
//sRet = wip_netInitOpts(WIP_NET_OPT_DEBUG_PORT, WIP_NET_DEBUG_PORT_UART1, WIP_NET_OPT_END);
sRet = wip_netInit();
if (sRet==0)
{
adl_atSendResponse(ADL_AT_RSP,"[SAMPLE] wip_netInit OK\r\n");
} else
{
adl_atSendResponse(ADL_AT_RSP,"[SAMPLE] wip_netInit NOK\r\n");
}
// Open the GPRS bearer /
sRet |= wip_bearerOpen( &GPRSBearer, "GPRS", evh_bearer, NULL);
// TRACE((1, "wip_bearerOpen: %d", sRet));
adl_atSendResponse(ADL_AT_RSP,"wip_bearerOpen\r\n");
// Configure the GPRS parameters/
Read_GPRS_fromFlh(My_GPRS);
adl_atSendResponse(ADL_AT_RSP,"Read_GPRS_fromFlh\r\n");
// Configure the GPRS bearer
sRet |= wip_bearerSetOpts ( GPRSBearer,
WIP_BOPT_GPRS_APN, My_GPRS->APN,
WIP_BOPT_LOGIN, My_GPRS->Login,
WIP_BOPT_PASSWORD, My_GPRS->Password,
WIP_BOPT_END);
TRACE((1, "wip_bearerSetOpts: %d", sRet));
adl_memRelease(My_GPRS);
adl_atSendResponse(ADL_AT_RSP,"wip_bearerSetOpts\r\n");
if (sRet)
{
adl_atSendResponse (ADL_AT_RSP, "\r\nConfiguration failed\r\n");
adl_tmrSubscribe ( FALSE, 1, ADL_TMR_TYPE_TICK, GprsStopConnection );
return DOTA_GPRS_ERR_CONFIG_FAILED; // Configuration failed
}
// Start the GPRS connection
sRet = wip_bearerStart ( GPRSBearer );
TRACE((1, "wip_bearerStart: %d", sRet));
GPRSConnStarted=TRUE;
if (sRet == WIP_BERR_OK_INPROGRESS)
{
adl_atSendResponse (ADL_AT_RSP, "\r\nConnection in Progress\r\n");
return OK;
}
if (sRet != OK)
{
adl_atSendResponse (ADL_AT_RSP, "\r\nDOTA_GPRS_ERR_CONN_START_FAILED\r\n");
adl_tmrSubscribe ( FALSE, 1, ADL_TMR_TYPE_TICK, GprsStopConnection );
return DOTA_GPRS_ERR_CONN_START_FAILED; // Connection start procedure failed
}
adl_atSendResponse (ADL_AT_RSP, "[SAMPLE] End GprsStartConnection\r\n");
}
else
adl_atSendResponse(ADL_AT_RSP,"[SAMPLE] full_sim_init==FALSE\r\n");
return TRUE;
}
s8 GprsStartConnection(u8 Id)
{
adl_tmrSubscribe ( FALSE, 1, ADL_TMR_TYPE_TICK,GprsStopConnection);
adl_tmrSubscribe ( FALSE, 2, ADL_TMR_TYPE_TICK,InitConnection);
}
waiting for reply…