C for Dumby, how to pass a variable to a response handler


#1

Hello,
I would like to pass an additional variable to a response handler. I have achieved this with a global variable which is sort-of uncool!? eg

x=99;
adl_atCmdSend(temp50,(adl_atRspHandler_t)ATresponseH,"*",NULL);
}
/*-------------------------------------------------------------------------*/
s16 ATresponseH(adl_atResponse_t *paras){
int r;

	r=paras->RspID;
                x=x+1;

I would like to do like this… I changed the syntax to the way it seems logical to me but this does not work

adl_atCmdSend(temp50,ATresponseH(adl_atRspHandler_t,x),"*",NULL);
}
/*-------------------------------------------------------------------------*/
s16 ATresponseH(adl_atResponse_t *paras,u8 x){
int r;

	r=paras->RspID;
                x=x+1;
...

How to do this properly?


#2

Why do you think that the global variable is “uncool” :question:

It is the classic way to pass information between the “main” loop and an interrupt handler in microcontroller systems…

Instead of making the variable global, you could provide “getter” and “setter” functions, if you prefer…

Specifically for sending an additional parameter to an AT Command’s Response Handler, there is an API function which provides an additional “context” parameter…


#3

Uncool … well I come from using micros with memory constraints, so for efficiency of memory use better to use locals? 2 bytes Irrelevant here really I guess!
What is the API function for passing additional information? Thanks


#4

So you should be familiar with using globals to communicate between your ISRs and your “main loop”, then?

Yes - but clearly useless for communication between modules!

adl_atCmdSendExt