Hi ,
I’m trying to send to a server address some data which is received on UART1.
Therefore i have used the FCM code to retrieve 10 bytes and then initiated a client connection to the peer address using a client to server code. It seems that the process is going well including open beerer , and connection to the peer address. However:
-
It seems that the server side(second sierra’s modem) do not see the client request although on the client it looks like there was a connection.
-
after the connection was failed and the meter function went back to read data , the debugger went down…
See below my code and attached is the log and traces.
Any immidate assitance will be highly appreciated.
Thanks ,
static void evh_bearer( wip_bearer_t b, s8 event, void *ctx) {
if( WIP_BEV_IP_CONNECTED == event)
{
appli_entry_point();
}
}
void appli_entry_point() {
wip_channel_t socket;
wip_debug( "[SAMPLE]: connecting to client %s:%i...\n", PEER_STRADDR, PEER_PORT);
socket = wip_TCPClientCreate( PEER_STRADDR, PEER_PORT, evh, NULL);
iscon = true;
if( ! socket) { wip_debug( "[SAMPLE] Can't connect\n"); return; }
}
static void evh( wip_event_t *ev, void *ctx,ascii *snd_buffer) {
int r;
wip_bearer_t b;
switch( ev->kind) {
case WIP_CEV_OPEN: {
wip_debug ("[SAMPLE] Connection established successfully\n");
iscon = true;
break;
}
case WIP_CEV_READ: {
.
.
.
}
break;
}
case WIP_CEV_WRITE: {
int nwrite;
wip_debug ("[SAMPLE] Can send more data\n");
nwrite = wip_write( ev->channel, snd_buffer + snd_offset,
sizeof( snd_buffer) - snd_offset);
if( nwrite < 0) { wip_debug( "[SAMPLE] write error %i\n", nwrite); return; }
snd_offset += nwrite;
if( snd_offset == sizeof( snd_buffer)) {
wip_debug( "[SAMPLE] Everything has been sent, won't send more.\n");
wip_bearerClose( b );
//adl_atCmdCreate("AT+WIPCLOSE =2,1", NULL, NULL, NULL);
//adl_fcmSwitchV24State(DataMeter_fcmHandle, ADL_FCM_V24_STATE_AT);
meeterRead = true;
AppInitMeter ( );
} else {
wip_debug( "[SAMPLE] Wrote %i bytes. "
"%i bytes left to send in snd_buffer\n",
nwrite, sizeof( snd_buffer) - snd_offset);
}
break;
}
case WIP_CEV_ERROR: {
wip_debug( "[SAMPLE] Error %i on socket. Closing.\n",
ev->content.error.errnum);
wip_close( ev->channel);
meeterRead = true;
iscon = false;
AppInitMeter ( );
break;
}
case WIP_CEV_PEER_CLOSE: {
wip_debug( "[SAMPLE] Connection closed by peer\n");
wip_close( ev->channel);
meeterRead = true;
iscon = false;
AppInitMeter ( );
break;
}
}
}
static void open_and_start_bearer( void) {
int r;
wip_bearer_t b;
r = wip_bearerOpen( &b, "GPRS", evh_bearer, NULL);
ASSERT_OK( r);
r = wip_bearerSetOpts( b, WIP_BOPT_GPRS_APN, GPRS_APN,
WIP_BOPT_LOGIN, GPRS_USER,
WIP_BOPT_PASSWORD, GPRS_PASSWORD,
WIP_BOPT_END);
iscon =TRUE;
TRACE ((1, " wip_bearerSetOpts : %s %s %s", GPRS_APN, GPRS_USER,GPRS_PASSWORD));
ASSERT_OK( r);
r = wip_bearerStart( b);
ASSERT( 0 == r || WIP_BERR_OK_INPROGRESS == r);
}
void appTimerhdlc(u8 TimerId)
{
if (iscon == false )
poll_creg();
}
////rssi handler
bool poll_creg_callback(adl_atResponse_t *Rsp) {
ascii *rsp;
ascii regStateString[3];
s32 regStateInt;
TRACE (( 1, "(poll_creg_callback) Enter." ));
rsp = (ascii *)adl_memGet(Rsp->StrLength);
wm_strRemoveCRLF(rsp, Rsp->StrData, Rsp->StrLength);//"+CSQ: 19,0" rsp[7],rsp[8]
wm_strGetParameterString(regStateString, Rsp->StrData, 2);
regStateInt = wm_atoi(regStateString);
if (( *( rsp +6 ) == '1' ) || ( *( rsp +7 ) > '6 ')&&( *( rsp +6 ) == '2' ) )
{
TRACE (( 1, "(poll_creg_callback) Registered on GPRS network." ));
open_and_start_bearer();
} else {
/* Not ready yet, we'll check again later. Set a one-off timer. */
adl_tmrSubscribe( FALSE, CREG_POLLING_PERIOD, ADL_TMR_TYPE_100MS, appTimerhdlc);
}
return FALSE;
}
////checks the rssi
void poll_creg( void ) {
adl_atCmdCreate( "AT+CSQ", FALSE, poll_creg_callback, "*", NULL);
}
/////meter data hendler : reed data until METER_INPUT_BUFFER_SIZE.Get back to read after conection failed
static bool DataMeter_data_handler(u16 datalength, u8 *data) {
bool bReturnM = TRUE; /* Return value is always true to release the credits*/
/* just dump into a buffer for later processing by the core */
if ( meeterRead == true)
if ((rx_bytes_ser_in + datalength) < METER_INPUT_BUFFER_SIZE)
{
wm_memcpy(&rx_met_buffer[rx_bytes_ser_in], data, datalength);
rx_bytes_ser_in += datalength;
TRACE ((1, "DATAmeter Data Handler: %d %d", datalength, rx_bytes_ser_in));
}
else
{
//bReturnM = FALSE;
meeterRead = false;
rx_bytes_ser_in = 0;
adl_fcmSwitchV24State(DataMeter_fcmHandle, ADL_FCM_V24_STATE_AT);
adl_tmrSubscribe( FALSE, 60, ADL_TMR_TYPE_100MS, appTimerhdlc);
TRACE ((1, "DATAmeter Data Handler: %d %d", datalength, rx_bytes_ser_in));
}
return bReturnM;
}
////meter control hendler
static bool DataMeter_ctrl_handler(u8 event)
{
TRACE((1, "DataMETER_ctrl_handler: %d", event));
switch(event)
{
case ADL_FCM_EVENT_FLOW_OPENNED:
/* Switch to data state */
adl_fcmSwitchV24State(DataMeter_fcmHandle, ADL_FCM_V24_STATE_DATA);
break;
case ADL_FCM_EVENT_V24_DATA_MODE:
TRACE((1, "ADL_FCM_EVENT_V24_DATA_MODE"));
//adl_tmrSubscribe ( FALSE, 10, ADL_TMR_TYPE_100MS, GPIOInit );
break;
case ADL_FCM_EVENT_FLOW_CLOSED:
TRACE((1, "ADL_FCM_EVENT_V24_AT_MODE"));
adl_fcmSwitchV24State(DataMeter_fcmHandle, ADL_FCM_V24_STATE_AT);
break;
}
return TRUE;
}
///starts reading the meter data
void AppInitMeter( void )
{
TRACE (( 1, "Set Serial to preper Meter " ));
if (( meeterRead == true)||(WIP_CEV_PEER_CLOSE)||(WIP_CEV_ERROR)){
/* Open the Data FCM flow on the DATAGPS */
DataMeter_fcmHandle = adl_fcmSubscribe(APP_METER_UART,
(adl_fcmCtrlHdlr_f)DataMeter_ctrl_handler,
(adl_fcmDataHdlr_f)DataMeter_data_handler);
}
}
void adl_main ( adl_InitType_e InitType )
{
int r;
TRACE (( 1, "Embedded Application : Main" ));
r = wip_netInitOpts( WIP_NET_OPT_DEBUG_PORT, WIP_NET_DEBUG_PORT_UART1,
WIP_NET_OPT_END);
AppInitMeter();
}
client_fcm_log_4_1_13.txt (6.77 KB)