Usage of A&D memory

Hi,
Can anyone tell me the exact usage of A&D memory? Can it be used only for storing .dwl files before installation or can it be used to store normal data and retrieve later? I have this Qn. as i didnt find a adl_adread() command. It would be Gr8 if get sample application to get the exact size of A&D memory available and how to allocate memory, write, and read data.
I also need the steps involved in doing the same as i got the error “ADL_RET_ERR_UNKNOWN_HDL” when i tried to subscribe for the cell and write data.

Regards,
S. Vanee

Hi Vanee,
Step by step:

Of course you can use it for normal data, the “D” means data. Limitations:
[]When you access for writing at a cell of this memory the ADL, gives you access to the end of the cell. So the best way to change something already written is: delete, recompact, create a and write.
[
]Because of this kind of writing management, the most usefull ways of using it are .dwl storage and datalogging.

Yeah… This is always confusing the first time you work with A&D. You must use adl_adInfo(). In the adl_adInfo structure you have a pointer (*data) to the data stored (DO NOT USE THIS POINTER FOR WRITTING, I’ve never tried but gcc would not like that, sure!!).

First you must subscribe the cell (always, even if it has already been created), use the s32 returned by adl_adSubscribe to evaluate the subscription (check the documentation). If it’s >=0 use the returned value for cell operation (adl_adWrite, adl_adInfo…). If you do this I have never had a “ADL_RET_ERR_UNKNOWN_HDL” as response.

Thank you very much. Let me check it out!

Regards,
S. Vanee

It’s working fine. But, is it not possible to append data to already written data using adl_adwrite()?

Regards,
S. Vanee

If you do not finalize the cell you can append data to the end of the cell with adl_adWrite command. What you can’t do is to change already written data.

Best Regards,
Tom

Hi,
I did a simple adl_adwrite operation twice before reading the content and this is what i got:

Data Written: Hello World
Write Successful

Data Written: 1223445445677778658668678
Write Successful

Read Successful

Data Read: Hello World
Size of Data: 11
Memory Available: 851696
Memory Size: 60
Memory is getting allocated. But, why is the data not retrieved?

Is the NUL also being written…?

There’s no NUL. The data i write are “Hello World” and “1223445445677778658668678”. But, only “Hello World” is read. But, if you see “Memory Size: 60”. It should have been only 30 if only the first write was successful.
Also, what’s the difference between writting data in flash and A&D memory? which is the better way to store and retrieve data frequently?

If you write as strings in:

And also read as strings, and print them with TRACE:

You have the characters until the first string terminator ‘\0’ (that’s the awneil’s question reason). How do you print the size? With strlen?

Anyway, which was the response to the second call to adl_adWrite?

Im having the exact same problem.
i use code like this

ascii TEXTOMEMORIA[200];
wm_sprintf(TEXTOMEMORIA,":Proyecto Wavecom");
	TEXTOMEMORIA[wm_strlen(TEXTOMEMORIA)]='\0';
		if(adStorage_WriteMem(TEXTOMEMORIA,wm_strlen(TEXTOMEMORIA),1)>0)
		{
			TRACE((1,"[main.c][ad_Handler]:adStorage_WriteMem OK"));
		}

I really dont know what im doing wrong!. Thanks!!

How do you know it’s the exact same problem, since the original problem was never really clearly defined?

You need to post a complete piece of code that shows exactly what you’re doing, and exactly what results you’re getting.

What does your adStorage_WriteMem function actually do?

The code to write is this.

int  adStorage_WriteMem(ascii *BufferWrMem,int BufferWrMemLenght,int CELLID)
{
TRACE((1,"[wav_adStorage.c][adStorage_WriteMem]:Inside adStorage_WriteMem"));

if(CELLID>=0)
	{
	TRACE((1,"[wav_adStorage.c][adStorage_WriteMem]:adl_adSubscribe OK"));

	s32 respuesta=adl_adInfo(adStorage_SuscribeCELLHandler[CELLID],&adStorage_Info);

					switch(respuesta)
						{
							case OK:								//on success
							TRACE((1,"[wav_adStorage.c][adStorage_WriteMem]:adl_adInfo OK"));
							TRACE((1,"[wav_adStorage.c][adStorage_WriteMem]: Espacio disponible para escribir %d",adStorage_Info.remaining));

										s32 WriteAnswer;
										WriteAnswer=adl_adWrite(adStorage_SuscribeCELLHandler[CELLID],BufferWrMemLenght,BufferWrMem);
										TRACE((1,"Valor de WriteAnswer %d",WriteAnswer));
										switch(WriteAnswer)
											{
											case		OK: 							//on success
											TRACE((1,"[wav_adStorage.c][adStorage_WriteMem]:adStorage_WriteMem OK"));
											return BufferWrMemLenght;
											break;

											 case	ADL_RET_ERR_UNKNOWN_HDL:	//if the handle was not subscribed
											 TRACE((1,"[wav_adStorage.c][adStorage_WriteMem]:ADL_RET_ERR_UNKNOWN_HDL"));
											 return -1;
												 break;


											 case	ADL_RET_ERR_PARAM:			//on parameter error
												 TRACE((1,"[wav_adStorage.c][adStorage_WriteMem]:ADL_RET_ERR_PARAM"));
												return -1;
												 break;


											 case	ADL_RET_ERR_BAD_STATE:		//if the cell is finalized
												 TRACE((1,"[wav_adStorage.c][adStorage_WriteMem]:ADL_RET_ERR_BAD_STATE"));
											   	return -1;
												 break;


											 case	ADL_AD_RET_ERR_OVERFLOW:	//if the write operation exceeds the cell size
												 TRACE((1,"[wav_adStorage.c][adStorage_WriteMem]:ADL_AD_RET_ERR_OVERFLOW"));
												return -1;
												 break;


											 case	ADL_RET_ERR_SERVICE_LOCKED: 	//if the function was called from a low level interrupt handler (the function is forbidden in this context)
												 TRACE((1,"[wav_adStorage.c][adStorage_WriteMem]:ADL_RET_ERR_SERVICE_LOCKED"));
												return -1;
												 break;
											  }
							return FALSE;
							break;

							case ADL_RET_ERR_PARAM:
							TRACE((1,"[wav_adStorage.c][adStorage_WriteMem]:ADL_RET_ERR_PARAM"));
							return FALSE;
							break;

							case ADL_RET_ERR_UNKNOWN_HDL: 	//if the handle was not subscribed
								TRACE((1,"[wav_adStorage.c][adStorage_WriteMem]:ADL_RET_ERR_UNKNOWN_HDL"));
								return FALSE;

							break;

							case ADL_RET_ERR_BAD_STATE:		//if the required cell is a not finalized or an undefined size
								TRACE((1,"[wav_adStorage.c][adStorage_WriteMem]:ADL_RET_ERR_BAD_STATE"));
								return FALSE;

							break;

							case ADL_RET_ERR_SERVICE_LOCKED:	//if the function was called from a low level interrupt handler (the function is forbidden in this context)
								TRACE((1,"[wav_adStorage.c][adStorage_WriteMem]:ADL_RET_ERR_SERVICE_LOCKED"));
								return FALSE;

							break;
						}


	}
else
	{
	return -1;
	}

return 0;
}

The read code is this.
When i read the data i read always the same thus i write in the memory and the free space is always less than before.

Thanks!!

bool adStorage_ReadMem(ascii *BufferRdMem,int CELLID)
{
TRACE((1,"[wav_adStorage.c][adStorage_ReadMem]:Inside adStorage_ReadMem"));
if(CELLID>=0)
	{
    	TRACE((1,"[wav_adStorage.c][adStorage_SuscribeCELLHandler]:sadl_adSubscribe OK"));
		s32 respuesta=adl_adInfo(adStorage_SuscribeCELLHandler[CELLID],&adStorage_Info);

		switch(respuesta)
			{
				case OK:								//on success
				TRACE((1,"[wav_adStorage.c][adStorage_ReadMem]:adl_adInfo OK"));
				TRACE((1,"[wav_adStorage.c][adStorage_ReadMem]: Espacio disponible para escribir %d",adStorage_Info.remaining));
				ascii datoaux[200];
		
				BufferRdMem= (ascii*)(adStorage_Info.data);
				TRACE((1,BufferRdMem));
				return TRUE;
				break;
		
				case ADL_RET_ERR_PARAM:
				TRACE((1,"[wav_adStorage.c][adStorage_ReadMem]:ADL_RET_ERR_PARAM"));
				return FALSE;
				break;
		
				case ADL_RET_ERR_UNKNOWN_HDL:	//if the handle was not subscribed
					TRACE((1,"[wav_adStorage.c][adStorage_ReadMem]:ADL_RET_ERR_UNKNOWN_HDL"));
					return FALSE;
		
				break;
		
				case ADL_RET_ERR_BAD_STATE: 	//if the required cell is a not finalized or an undefined size
					TRACE((1,"[wav_adStorage.c][adStorage_ReadMem]:ADL_RET_ERR_BAD_STATE"));
					return FALSE;
		
				break;
		
				case ADL_RET_ERR_SERVICE_LOCKED:	//if the function was called from a low level interrupt handler (the function is forbidden in this context)
					TRACE((1,"[wav_adStorage.c][adStorage_ReadMem]:ADL_RET_ERR_SERVICE_LOCKED"));
					return FALSE;
		
				break;
			}
	}
return FALSE;
}