A&D using Basic OpenAT

Hi all,
I’m trying to use Basic Open AT API to access A&D data.

All these functions works fine to me:

wm_adSpaceState()
wm_adFormat()
wm_adAllocate()
wm_adRetrieve()
wm_adFinalise()
wm_adResume()
wm_adDelete()
wm_adInfo()
wm_adStats()

BUT this one does not work:

wm_adWrite()

When I call it, the function returns 249 (dec). Can anyone explains this to me ?

I also wrote a small program using ADL in order to write to A&D and it works.
The program I wrote in Basic OpenAT in order to deal with A&D can READ the A&D written with my ADL application.

Manuals (Basic Development Guide for Open AT v3.10 – revision 012 – date December 2005) does not discourage the usage of wm_adWrite() function…

Can anyone help me ?

Thx in advance, Carlo

P.S. I’m using Wavecom module Q2501B and Muse 3.10

Moderator …

none from wavecom can give me an answer ?

Is it something happening to me only ???

:confused: :confused: :confused:

Hi Carlo,
When the return value (249) is returned by wm_adWrite () API, does the data gets correctly written to A&D memory. I mean, are you able to read the data written using wm_adWrite (which returns 249).
If you are able to do so, then check if you are getting the return value of wm_adWrite () in a variable of type s32 only.

If no, then could you please post your code which is giving the problem (at least some part of it).

Regards,
Open AT Fan.

Hi Open AT Fan,

here is a small program that recreates always (at least on my system) an error ( -7 --> FFFFFFF9 -> WM_AD_OVERFLOW ) when writing to an A&D cell. Please note that the error DOES NOT OCCOUR THE FIRST TIME (when the cell ID does not exist and has to be created).

THIS IS SOMETHING SLIGHTLY different from the previous problem description (rc=249) I made, BUT it shows clearly that something is not going on very well.
The program tries to get the handle of the cell 1123: if any error, create it.
Then it it writes a string into cell using wm_adWrite. If the cell does not exist, create it and write. Everything works fine.
If the cell exists, the wm_adWrite function return -7 (out of memory ???) and this make no much sense to me.

Even if I converted all the job I made using the ADL stuff, please do not hesitate to tell me if I made blatant error or misunderstanding.

ThanX again for your help,
Carlo.

#include "wm_types.h"
#include "wm_apm.h"

/***************************************************************************/
/*  Mandatory variables                                                    */
/*-------------------------------------------------------------------------*/
/*  wm_apmCustomStack                                                      */
/*  wm_apmCustomStackSize                                                  */
/*-------------------------------------------------------------------------*/
/***************************************************************************/
#define wm_apmCustomStackSize   1024
u32 wm_apmCustomStack[ wm_apmCustomStackSize / 4 ];

#define MY_TIMER_ID			23
#define MY_TIMER_VALUE		50					// 5 seconds

char *WriteBuf = "This is the data to write ";
u32   WriteBufLen;

#ifdef __DEBUG_APP__
	#define			MYDEBUG(_X_)			MyDebug _X_
#else
	#define			MYDEBUG(_X_)
#endif // __DEBUG_APP__

/***************************************************************************/
/*  Local variables                                                        */
/***************************************************************************/
#ifdef __DEBUG_APP__
	static char DbgBuf[256];
#endif // __DEBUG_APP__

/***************************************************************************/
/*  Functions prototypes                                                   */
/***************************************************************************/
void Handle_WM_OS_TIMER_Msg ( wm_apmMsg_t * pMessage );

#ifdef __DEBUG_APP__

	void  MyDebug ( s8 Level, const char *Format, ... )
	{
		va_list	args;
		u16		Len;
	
		wm_memset( DbgBuf, 0, sizeof( DbgBuf ) );
		va_start( args, Format );
		Len = wm_vsprintf( DbgBuf, Format, args );

		wm_strcat( DbgBuf, "\r\n" );
		Len += 3;
		wm_atSendUnsolicitedExternalApp( Len, DbgBuf );

	//	++Len;
	//	wm_atSendRspExternalApp( Len, DbgBuf );

	//	wm_osDebugTrace( (u8)Level, DbgBuf );

	}

#endif // __DEBUG_APP__

s32 wm_apmAppliInit ( wm_apmInitType_e InitType )
{
    s32 sRc;
	
    MYDEBUG(( 1, "Embedded Application Task Init" ));
    sRc = wm_osStartTimer( MY_TIMER_ID, FALSE,  MY_TIMER_VALUE );
    MYDEBUG(( 1, "wm_osStartTimer(ID=%d, value=%d) rc=%d",
              MY_TIMER_ID, MY_TIMER_VALUE, sRc ));
    WriteBufLen = wm_strlen( WriteBuf );
    return OK;
}

s32 wm_apmAppliParser ( wm_apmMsg_t * pMessage )
{
    switch ( pMessage->MsgTyp )
    {
        case WM_OS_TIMER:
            MYDEBUG(( 1, "Parser: WM_OS_TIMER" ));
            Handle_WM_OS_TIMER_Msg( pMessage );
            break;
        case WM_AT_RESPONSE:
            MYDEBUG(( 1, "Parser: WM_AT_RESPONSE" ));
            break;
        case WM_AT_UNSOLICITED:
            MYDEBUG(( 1, "Parser: WM_AT_UNSOLICITED" ));
            break;
        case WM_AT_INTERMEDIATE:
            MYDEBUG(( 1, "Parser: WM_AT_INTERMEDIATE" ));
            break;
        case WM_AT_CMD_PRE_PARSER:
            MYDEBUG(( 1, "Parser: WM_AT_CMD_PRE_PARSER" ));
            break;
        case WM_AT_RSP_PRE_PARSER:
            MYDEBUG(( 1, "Parser: WM_AT_RSP_PRE_PARSER" ));
            break;
        case WM_OS_RELEASE_MEMORY:
            MYDEBUG(( 1, "Parser: WM_OS_RELEASE_MEMORY" ));
            break;
        case WM_FCM_RECEIVE_BLOCK:
            MYDEBUG(( 1, "Parser: WM_FCM_RECEIVE_BLOCK" ));
            break;
        case WM_FCM_OPEN_FLOW:
            MYDEBUG(( 1, "Parser: WM_FCM_OPEN_FLOW" ));
            break;
        case WM_FCM_CLOSE_FLOW:
            MYDEBUG(( 1, "Parser: WM_FCM_CLOSE_FLOW" ));
            break;
        case WM_FCM_RESUME_DATA_FLOW:
            MYDEBUG(( 1, "Parser: M_FCM_RESUME_DATA_FLOW" ));
            break;
        case WM_IO_SERIAL_SWITCH_STATE_RSP:
            MYDEBUG(( 1, "Parser: WM_IO_SERIAL_SWITCH_STATE_RSP" ));
            break;
        case WM_IO_UPDATE_INFO:
            MYDEBUG(( 1, "Parser: WM_IO_UPDATE_INFO" ));
            break;
        case WM_IO_PORT_UPDATE_INFO:
            MYDEBUG(( 1, "Parser: WM_IO_PORT_UPDATE_INFO" ));
            break;
        default :
            MYDEBUG(( 1, "Parser: Unknown Message Type" ));
            break;
  
    } /* switch (pMessage->MsgTyp) */
  
    return OK;
}

/***************************************************************************/
/*  Mandatory variables                                                    */
/*-------------------------------------------------------------------------*/
/*  wm_apmTask                                                             */
/*-------------------------------------------------------------------------*/
/***************************************************************************/
const wm_apmTask_t wm_apmTask[] =
{
	{ wm_apmCustomStackSize, wm_apmCustomStack, wm_apmAppliInit, wm_apmAppliParser },
	{ 0, (u32 *)NULL, NULL, NULL },		
	{ 0, (u32 *)NULL, NULL, NULL }		
};

void Handle_WM_OS_TIMER_Msg ( wm_apmMsg_t * pMessage )
{
    wm_adHandle_t Handle;
    s32 sRc;
    u32 CellID = 1123,
        Size   = 102400;
		
    if ( pMessage->Body.OSTimer.Ident == MY_TIMER_ID )
    {
       MYDEBUG(( 1, "OUR TIMER TIMER EXPIRED!!!" ));
       sRc = wm_adRetrieve( CellID, &Handle );
       MYDEBUG(( 1, "wm_adRetrieve( Cell ID=%u ) rc=%d", CellID, sRc ));
       if ( sRc < OK )
       { // suppose it does not exist 
          sRc = wm_adAllocate( CellID, Size, &Handle );
          MYDEBUG(( 1, "wm_adAllocate( Cell ID=%u, Size=%u ) rc=%d",
                    CellID, Size, sRc ));
       }

       if ( sRc >= OK )
       {
          sRc = wm_adWrite( &Handle, WriteBufLen, WriteBuf );
          MYDEBUG(( 1, "wm_adWrite( Cell ID=%u, Len=%u Data='%s' ) rc=%d",
                    CellID, WriteBufLen, WriteBuf, sRc ));
       }
       else
          MYDEBUG(( 1, "*** UNABLE TO RETRIEVE A&D STORAGE ***" ));
    }
    else
    {
       MYDEBUG(( 1, "WARNING: unknown Timer ID received (%d)",
                 pMessage->Body.OSTimer.Ident ));
    }
}

Hi cbeghelli,

  1. After writing to the cell, please try to finalize the cell by using wm_adFinalize API.
  2. When your application starts again, (after module reset), please check if the cell already exists. If it exists, and you still want to write something to it, first delete the cell, then subscribe to it again and then write and finalize it.

Now read from the cell.
Hope this should help.
In case, this does not help, the you can format your A&D storage memory using wm_adFormat () API. You can also consider the option of recompacting the A&D storage memory after writing successfully into the cell (so that there is no fragmentation of A&D memory which might be the cause of problem).

Best Regards,
Open AT Fan.

Hi Open AT Fan,
Thanx to your answer that makes me thinking about the action of finalizing the cell, I continue invatigating about A&D storage.

I finally find a solution: if the cella already exist, just call the wm_adResume() function.

Very very very …

Damn : one month of job thrown through the window converting my application from BASIC OPEN AT to --> ADL :frowning: :frowning: :frowning:

However,
thank you very much for your help and your support.

Carlo