Problem getting A&D memory data


#1

Hi Everybody.

I am developing an application that make these steps:

  1. Gets a file from a web server (170 Kb)
  2. Stores it in the A&D memory
  3. Gets this data from A&D memory to send it though UART1.

I have a problem in step 3, because I have got to store the file in the A&D memory (I always got OK as a result to adWrite function), but when I try to retrieve the stored info through adInfo function and info.data pointer, I didn’t get the information I wrote, or at least, I don’t know how to get that information. If I print the info.remaining and info.size parameters from adInfo function I get the correct answer.

This is my relevant code:

void Handler_wipHTTP_Status (wip_event_t *ev, void * ctx)
{
	wip_channel_t http_channel;
	u32 ret;
	s32 result;
	s32 i;
	ascii url_dest [70];
	u8 firmwareGPS [10240];
	u8 * GPS_data_Flash;
	u8 data_show [100];
	adl_adState_t State;
	adl_adInfo_t * info;
	
	http_channel = ev -> channel;
	switch (ev->kind)
	{
		case WIP_CEV_OPEN:
			wm_sprintf(url_dest,"GET /gps/phx_1_5_2_bE1.ski HTTP/1.1\r\n");
			wip_write(http_ch,url_dest,37);
   			wip_write(http_ch,"Host: 194.224.225.162\r\n\r\n",25);
   			// Reserved space in the A&D memory
	   		firmgps_adCellHandle = adl_adSubscribe (FLH_ID_FIRMGPS, 204800);
	   		// Reserved space in the RAM memory (100Kb)
	   		firmwareGPS_Write = adl_memGet (102400);
	   		if (firmwareGPS_Write == NULL)
	   			adl_atSendResponse ( ADL_AT_UNS, "\r\nTHERE IS NO MORE RAM MEMORY\r\n");
	   		for (i=0;i<102400;i++)
	   			firmwareGPS_Write [i] = '\0';
   			cont = 0;
			break;
		case WIP_CEV_READ:
			// Reading from web server socket
			while ((ret = wip_read (http_channel,&firmwareGPS,10240)) > 0)
			{
				// Add to total bytes received
				cont = cont + ret;
			}
			wm_sprintf(RspStr,"Received %d bytes\r\n",cont);
			adl_atSendResponse ( ADL_AT_UNS, RspStr);
			if (cont_old == 0)
			{
				// If it is the first block of bytes from the socket
				// we show 100 first bytes that we have received
				for (i = 0; i < 100; i++)
    					data_show [i] = firmwareGPS[i];
				adl_atSendResponse ( ADL_AT_UNS, data_show);
			}
			cont_old = cont;
			if (cont > 102400)
			{
				// If we have reached the RAM space limit, we write our buffer
				// in the A&D memory, release RAM memory and reserved another RAM memory block (100 Kb)
				if ( firmgps_adCellHandle >= OK )
				{
					// We check our buffer before writing to A&D memory
					for (i = 0; i < 100; i++)
    						data_show [i] = (u8) firmwareGPS_Write [i];
					adl_atSendResponse ( ADL_AT_UNS, "\r\nDATA TO WRITE: ");
					adl_atSendResponse ( ADL_AT_UNS, data_show);
					result = adl_adWrite (firmgps_adCellHandle,cont,firmwareGPS_Write);
					wm_sprintf(RspStr,"STORED %d bytes %d\r\n",cont, result);
					adl_atSendResponse ( ADL_AT_UNS, RspStr);
					switch (result)
					{
						case OK:
							adl_atSendResponse ( ADL_AT_UNS, "WRITE OK\r\n");
							break;
						case ADL_RET_ERR_UNKNOWN_HDL:
							adl_atSendResponse ( ADL_AT_UNS, "ADL_RET_ERR_UNKNOWN_HDL\r\n");
							break;
						case ADL_RET_ERR_PARAM:
							adl_atSendResponse ( ADL_AT_UNS, "ADL_RET_ERR_PARAM\r\n");
							break;
						case ADL_RET_ERR_BAD_STATE:
							adl_atSendResponse ( ADL_AT_UNS, "ADL_RET_ERR_BAD_STATE\r\n");
							break;
						case ADL_AD_RET_ERR_OVERFLOW:
							adl_atSendResponse ( ADL_AT_UNS, "ADL_AD_RET_ERR_OVERFLOW\r\n");
							break;
						case ADL_RET_ERR_SERVICE_LOCKED:
							adl_atSendResponse ( ADL_AT_UNS, "ADL_RET_ERR_SERVICE_LOCKED\r\n");
							break;
					}
					// Release RAM buffer
					adl_memRelease (firmwareGPS_Write);
					// Get of a new 100Kb RAM memory block
					firmwareGPS_Write = adl_memGet (128000);
	   				if (firmwareGPS_Write == NULL)
	   					adl_atSendResponse ( ADL_AT_UNS, "\r\nTHERE IS NO MORE RAM MEMORY\r\n");
	   				cont = ret;
				}
			}
			// We add received bytes from web server to our RAM memory buffer
			wm_strcat (firmwareGPS_Write,firmwareGPS);
			break;
		case WIP_CEV_PEER_CLOSE:
			wm_sprintf( RspStr, "\r\n+WIPHTTP_GPS: CLOSING WEB SERVER CONNECTION");
    			adl_atSendResponse ( ADL_AT_UNS, RspStr);
    			// We have received the whole file, close our HTTP connection
			wip_close (http_channel);
			// Storing the 2nd block of 100kb into A&D memory
			// First, we check if we are subscribed to the A&D memory cell
			if ( firmgps_adCellHandle >= OK )
			{
				// Writing data
				result = adl_adWrite (firmgps_adCellHandle,cont, firmwareGPS_Write);
				wm_sprintf(RspStr,"STORED %d bytes %d\r\n",cont, result);
				adl_atSendResponse ( ADL_AT_UNS, RspStr);
				switch (result)
				{
					case OK:
						adl_atSendResponse ( ADL_AT_UNS, "WRITE OK\r\n");
						break;
					case ADL_RET_ERR_UNKNOWN_HDL:
						adl_atSendResponse ( ADL_AT_UNS, "ADL_RET_ERR_UNKNOWN_HDL\r\n");
						break;
					case ADL_RET_ERR_PARAM:
						adl_atSendResponse ( ADL_AT_UNS, "ADL_RET_ERR_PARAM\r\n");
						break;
					case ADL_RET_ERR_BAD_STATE:
						adl_atSendResponse ( ADL_AT_UNS, "ADL_RET_ERR_BAD_STATE\r\n");
						break;
					case ADL_AD_RET_ERR_OVERFLOW:
						adl_atSendResponse ( ADL_AT_UNS, "ADL_AD_RET_ERR_OVERFLOW\r\n");
						break;
					case ADL_RET_ERR_SERVICE_LOCKED:
						adl_atSendResponse ( ADL_AT_UNS, "ADL_RET_ERR_SERVICE_LOCKED\r\n");
						break;
				}
			}
			adl_adFinalise (firmgps_adCellHandle);
			adl_memRelease (firmwareGPS_Write);
			adl_adUnsubscribe (firmgps_adCellHandle);
			// Subscription to get info from A&D
			firmgps_adCellHandle = adl_adSubscribe (FLH_ID_FIRMGPS, 204800);
			adl_adGetState (&State);
			wm_sprintf( RspStr, "\r\n+ADSTATE: %d,%d,%d,%d,%d\r\n",State.deletedmem,State.freemem,State.numdeleted,State.numobjects,State.totalmem);
    		adl_atSendResponse ( ADL_AT_UNS, RspStr);
    		adl_adInfo (firmgps_adCellHandle,info);
			wm_sprintf( RspStr, "\r\n+ADINFO: %d,%d\r\n",info -> size,info -> remaining);
    		adl_atSendResponse ( ADL_AT_UNS, RspStr);
    		adl_atSendResponse ( ADL_AT_UNS, "\r\nTRYING TO GET DATA\r\n");
    		GPS_data_Flash = (u8 * )info -> data;
    		for (i = 0; i < 100; i++)
			{
				wm_sprintf( RspStr, "+INFO_DATA[%d] = %s\r\n",i,(u8) GPS_data_Flash [i]);
				adl_atSendResponse ( ADL_AT_UNS, RspStr);
				//GPS_data_Flash++; 
			}
			adl_adUnsubscribe (firmgps_adCellHandle);
			break;
		case WIP_CEV_ERROR:
			// There was a socket error, closing connection
			wm_sprintf( RspStr, "\r\n+WIPHTTP: ERROR EN SOCKET");
    			adl_atSendResponse ( ADL_AT_UNS, RspStr);
			wip_close (http_channel);
			break;
	}
}

Can someone help me and tell me what I am making wrong?

Thanks a lot.

Raul Serrano


#2

It’s hard to read your code, as it’s lost its layout, and some has been misinterpreted as “smileys” :smiley: :slight_smile: :frowning: :astonished:

You need to use the ‘Code’ button to format the text as code & prevent “smileys” - and use the ‘Preview’ to check it.

See the forum User’s guide:
wavecom.com/modules/movie/sc … m.php?f=24


#3

the first thing i noticed was :

firmwareGPS_Write = adl_memGet (102400);

to my knowledge the adl_memGet() api takes an ‘unsigned short’ (u16),
which can have a maximum value of 65535

Goodluck !


#4

awneil, thanks for your recomendations. It was the first time I post some question.

I have edited my first post and I hope that my code would be more readable now.

openat_newby, I think that there is no problem in the memGet function, because I have read the ADL_User_Guide documentation and I got the definition for that function and it was:

void * adl_memGet (u32 size)

So I can request more that 65536 bytes, if I don’t reach the total available RAM memory. In fact, I requested more than 128Kb in one my first tests and my module reseted at that point everytime.

By the way, I didn’t mentioned that I am using a Q2686H module, firmware 6.61 and OpenAT 4.10

Thanks anyway.

Raul Serrano


#5

Hi, everybody.

After some research and a lot of tests, I have solve my own problem.

The problem was the way I used the info->data pointer. You can not access its content through info->data[i] or *info->data, because that pointer points a place in the flash memory, not in RAM memory, so the solution is to copy the content to RAM memory, using wm_memcpy.

So, changing this code:

for (i = 0; i < 100; i++)
         {
            wm_sprintf( RspStr, "+INFO_DATA[%d] = %s\r\n",i,(u8) GPS_data_Flash [i]);
            adl_atSendResponse ( ADL_AT_UNS, RspStr);
            //GPS_data_Flash++;
         }

to

GPS_data_flash = adl_memGet (129);
GPS_data_flash2 = (u8 *)info -> data;
// We copy 128 bytes from flash memory to RAM.
wm_memcpy (GPS_data_flash,GPS_data_flash2,128);
GPS_data_flash [129] = '\0';
wm_sprintf( RspStr, "+INFO_DATA = %s\r\n",GPS_data_flash);
adl_atSendResponse ( ADL_AT_UNS, RspStr);

And you can move your copy of the info->data pointer (GPS_data_flash2) wherever you want. Don’t move the info->data pointer directly (for example doing info->data++) because the module resets.

I hope this solution helps somebody in the same or similar situation.

Raul Serrano.