Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years ago.
What's "sendFormated" mean in MDM.cpp?
Hi, my name is david8251
i just learn mbed
but i have a question about "sendFormated" this function in MDM.cpp?
Thank for your attention~
1 Answer
9 years ago.
Generally it helps if you include a link to the file in question since we have no way of telling which file called MDM.cpp you are talking about.
The most obvious MDM.cpp file is for the ublox modem on the C027 board but that's not listed as a board you use in the online system. For that library sendFormated is the equivalent of printf but sending the data over the modem.
The first place to look is in the appropriate MDM.h file, function descriptions are normally in the header file rather than the .cpp file.
Thank you for your apply and It's is C027 board the code is : int MDMParser::sendFormated(const char* format, ...) { char buf[MAX_SIZE]; va_list args; va_start(args, format); int len = vsnprintf(buf,sizeof(buf), format, args); va_end(args); return send(buf, len); }
and i am confused that sendFormated("AT E0\r\n"); why it just a string like printf something ? Is data "AT E0\r\n" or it's just a command ? sending to computer?
posted by 06 Sep 2016From the header file:
/** Write formated date to the physical interface (printf style) \param fmt the format string \param .. variable arguments to be formated \return bytes written */ int sendFormated(const char* format, ...);
It is exactly like printf only sending the data over the modem. If you are sending a fixed string then it's pointless but if you are sending a variable string then it's useful. e.g.
int echomode = 0; sendFormated("AT E%d\r\n",echomode);
Thanks but i see the same like you say just like below(MDM.CPP) : sendFormated("AT E0\r\n"); 、sendFormated("AT+CMEE=2\r\n"); 、sendFormated("AT+IPR=115200\r\n"); Are they pointless? Do they need to type like below sendFormated("AT E %d\r\n",0); 、sendFormated("AT+CMEE=%d\r\n",2); 、sendFormated("AT+IPR=%d\r\n",115200); or they are the same?
posted by 06 Sep 2016sendFormated("AT E0\r\n"); and sendFormated("AT E %d\r\n",0); would have exactly the same end result but the second one will be slower since the string has to be formatted.
send("AT E0\r\n", 7) would also have the same effect but would be faster and use less memory since it avoids any calls to the printf string formatting routines.
The big advantage in sendFormated is that the variables don't have to be constant.
This is exactly the same as printf in normal c code.
posted by 06 Sep 2016