FCM on GPRS Flow

hello,

first sorry for my bad english.

I’m new at OpenAT and I spend few weeks reading documentations and trying some sample Applications.

I’m using an Evaluationboard with a Wireless CPU Q2687 with 663 Verion of Firmware.
The OS-Version is 4.21
I’m also using the Wip-Plugin Verion 3.10.2030

I’m writting my programcode in Ecipse with an gcc Compiler, as it comes as standard IDE with the SDK.

My aim is to establish a GPRS Connection and to subscribe to FCM on GPRS, so that I can receive incoming data to check them.
If there is coming some special data, other functions should be executed.

But at first I’ve got a problem with the FCM-Service and GPRS.

I trying to establish an GPRS Connection.
This works I think, but when I subscribe to the FCM with GPRS as Port I get some strange behavior.

And there is something else I’m bit confused about.
In the Target Monitoring Tool I get some Traces all beginning with “[GPRS]” which I’ve not written in my Code.
Are this standard Traces from the OS?

When I subscribe to the FCM-Service using GPRS Port, I’ve got the "FLOW OPENED’ - Event from my FCM-Control-Handler
but immediately after this I’ve got the “FLOW CLOSED”-Event.
Thereafter the GPRS Connection is closed, without any reason as far as I can see.

This is the way I tried:

-> First I’m subscribing to the SIM-Service

->when I get the event “ADL_SIM_EVENT_FULL_INIT” I subscribe to the GPRS-Service using the function ‘adl_gprsSubscribe’
then I’m sending the AT-Command “AT+CGATT=1” using ‘atCmdCreate’, because I want to attach to the GPRS-Network.
(I’m unable to find an equal function for this, so I can’t avoid using ‘CmdCreate’).

-> then when I receive the Event “ADL_GPRS_EVENT_ME_ATTACH” I’m starting an IP-Bearer using wip-function ‘wip_bearerOpen’.
then I set the Options for GPRS like APN and so on.
and at the end I start the Bearer with the command ‘wipbearerStart’

-> on the Event “ADL_GPRS_EVENT_ACTIVATE_OK” from my GPRS-Eventhandler I’m subscribing to the FCM on GPRS Port

-> when I get the “Event WIP_BEV_IP_CONNECTED” from my GPRS-Bearer-Handler I created an TCP-Client Socket using ‘wip_TCPClientCreate’

-> At last I get the “WIP_CEV_OPEN” Event

#include "adl_global.h"
#include "wip_bearer.h"
#include "wip.h"


/***************************************************************************/
/*  Mandatory variables                                                    */
/*-------------------------------------------------------------------------*/
/*  wm_apmCustomStackSize                                                  */
/*-------------------------------------------------------------------------*/
/***************************************************************************/
const u16 wm_apmCustomStackSize = 1024;


/***************************************************************************/
/*  Local variables                                                        */
/***************************************************************************/
static wip_bearer_t myBearer;
static wip_channel_t TcpSocket;


/***************************************************************************/
/*  Prototypes                                                             						*/
/***************************************************************************/
static void myHandler (wip_bearer_t *br, s8 event, void *context);
static void Sim_Handler (u8 Event);
static void GPRS_Attach();
static s8 GprsHandler (u16 Event, u8 Cid);
static bool GprsCtrlHandler (adl_fcmEvent_e Event);
static bool GprsDataHandler( u16 DataLen, u8 *Data);
static bool CmdResponseHandler (adl_atResponse_t*paras);
static void TCP_Event_Handler (wip_event_t *event, void *ctx);

/***************************************************************************/
/*  Local functions     						                                                      */
/***************************************************************************/
static void GPRS_Bearer_Handler (wip_bearer_t *br, s8 event, void *context)
{
    s8 Ret;
	
    switch(event)
    {
        case WIP_BEV_CONN_FAILED:
        case WIP_BEV_IP_CONNECTED:
            adl_atSendResponse(ADL_AT_PORT_TYPE(ADL_PORT_UART1,ADL_AT_UNS), "\n IP Connected \n");
            TRACE((1,"GPRS-Bearer-Handler: %d", event));
            
            // TCP Client Socket create
            TcpSocket = wip_TCPClientCreate ("IPAdress",Port, TCP_Event_Handler,NULL);
                TRACE((1,"TcpSocket: %d", TcpSocket));
                
        case WIP_BEV_IP_DISCONNECTED:
        case WIP_BEV_STOPPED:
            adl_atSendResponse(ADL_AT_PORT_TYPE(ADL_PORT_UART1,ADL_AT_UNS), "\n IP Disconnected \n");
            TRACE((1,"GPRS-Bearer-Handler: %d", event));
    }
}

static void TCP_Event_Handler (wip_event_t *event, void *ctx)
{
    switch (event->kind)
    {
        case WIP_CEV_OPEN:
        {
            adl_atSendResponse(ADL_AT_PORT_TYPE(ADL_PORT_UART1,ADL_AT_UNS), "\n Connection established successfully \n");
        }
        break;       
    }    
    TRACE ((1, "TCP-client Socket Event: %d", event->kind));   
}

static void Sim_Handler (u8 Event)
{
    s8 Ret;
    
    switch(Event)
    {   
        case ADL_SIM_EVENT_FULL_INIT:
        {
            TRACE((1,"Sim full initialize"));
            adl_atSendResponse(ADL_AT_PORT_TYPE(ADL_PORT_UART1,ADL_AT_UNS), "\n Sim full initialized \n");
            
             //GPRS-Event Subscribe
            Ret = adl_gprsSubscribe (GprsHandler);
                TRACE((1, "GPRS-Event-Subscription Return: %d", Ret));
                
            //Attach to GPRS
            adl_atCmdCreate("AT+CGATT=1", ADL_AT_PORT_TYPE (ADL_PORT_UART1,FALSE),CmdResponseHandler,NULL);          
        }   
        case ADL_SIM_EVENT_PIN_OK:
        {
           TRACE ((1,"PIN ok"));
        }
        break;
    }
    TRACE((1,"Sim-Handler Event: %d", Event));
}

static bool CmdResponseHandler (adl_atResponse_t*paras)
{    
    return TRUE;
}


static void GPRS_Attach()
{
    s8 Ret;
    //GPRS Bearer
    
    //open Bearer
    Ret = wip_bearerOpen(&myBearer, "GPRS", GPRS_Bearer_Handler, NULL);
        TRACE((1, "Bearer Open Return: %d", Ret));

   //set GPRS Connection Parameters 
            wip_bearerSetOpts (myBearer,
                                       WIP_BOPT_GPRS_APN, "APN",
                                       WIP_BOPT_LOGIN, "Username",
                                       WIP_BOPT_PASSWORD, "PW",
                                       WIP_BOPT_END);                       
    //Start
    Ret = wip_bearerStart (myBearer);
        TRACE((1, "Bearer Start Return: %d", Ret));
}

static s8 GprsHandler (u16 Event, u8 Cid)
{
    s8 FcmGprs;
    s8 Ret;
    
    switch (Event)
    {
        case ADL_GPRS_EVENT_ME_ATTACH:
        {              
                
            GPRS_Attach();
            
            adl_atSendResponse(ADL_AT_PORT_TYPE(ADL_PORT_UART1,ADL_AT_UNS), "\n GPRS Event Me Attach \n");
            
        }
        break;   
        case ADL_GPRS_EVENT_ACTIVATE_OK:
        {    
            
            Ret = adl_fcmSubscribe(ADL_PORT_GPRS_BASE, GprsCtrlHandler, GprsDataHandler);
                TRACE((1,"FCM-GPRS-Subscription: %d", Ret));
                 
            adl_atSendResponse(ADL_AT_PORT_TYPE(ADL_PORT_UART1,ADL_AT_UNS), "\n GPRS Event Activate OK \n");
        }
        break;
    }
    TRACE (( 1, "GPRS-Event-Handler: %d", Event));
}

static bool GprsCtrlHandler (adl_fcmEvent_e Event)
{
    switch (Event)
    {
        case ADL_FCM_EVENT_FLOW_OPENNED:
        {
            adl_atSendResponse(ADL_AT_PORT_TYPE(ADL_PORT_UART1,ADL_AT_UNS), "\n GPRS-Flow successfully opened \n");
            TRACE((1,"GPRS-Flow successfully opened"));
            
        }
    }
    TRACE((1, "FCM-GPRS-Flow-Control Event: %d", Event));
	return TRUE;
}

static bool GprsDataHandler( u16 DataLen, u8 *Data)
{
    adl_atSendResponse(ADL_AT_PORT_TYPE(ADL_PORT_UART1,ADL_AT_UNS), "\n GPRS-DataHandler executed \n");
	
    return TRUE;
}
           
/***************************************************************************/
/*  Function   : adl_main                                                  */
/*-------------------------------------------------------------------------*/
/*  Object     : Customer application initialisation                       */
/*                                                                         */
/*-------------------------------------------------------------------------*/
/*  Variable Name     |IN |OUT|GLB|  Utilisation                           */
/*--------------------+---+---+---+----------------------------------------*/
/*  InitType          |   |   |   |  Application start mode reason         */
/*--------------------+---+---+---+----------------------------------------*/
/***************************************************************************/
void adl_main ( adl_InitType_e InitType )
{
    TRACE (( 1, "Embedded Application : Main" ));
   
    s32 SimSubs;

    SimSubs = adl_simSubscribe(Sim_Handler, "0000");
        TRACE((1, "Sim Subscription Return: %d", SimSubs));

    //TCP/IP Stack init
     s8 TCPIPRet;
     TCPIPRet = wip_netInit();
        TRACE((1, "wip_netInit: %d", TCPIPRet));    
}

There is maybe something wrong in this code, or I use the function and Eventhandler in a wrong order or something else.

I’m very thankful for any help.
Thank you for spending time reading my post.

Kind regards
HW