Hi Everybody.
I am developing an application that make these steps:
- Gets a file from a web server (170 Kb)
- Stores it in the A&D memory
- 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