Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 4:69df63eeb91e, committed 2017-03-14
- Comitter:
- quicksand
- Date:
- Tue Mar 14 14:54:35 2017 +0000
- Parent:
- 3:4da15d6e1429
- Child:
- 5:ca670603d63d
- Commit message:
- Updated the function that sends out the SIGFOX command to be more robust.
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon May 02 12:04:13 2016 +0000
+++ b/main.cpp Tue Mar 14 14:54:35 2017 +0000
@@ -93,7 +93,6 @@
/* TX data over Sigfox */
void txData (uint8_t btn)
{
-
float tAvg;
char command[32];
sensor.Sense();
@@ -142,8 +141,13 @@
/* Timeout for response of the modem */
Timeout tmout;
ser_timeout = false;
- /* Buffer for incoming data */
- char responsebuffer[6];
+ // check if ok or error is received
+ char * readyString = "OK";
+ char * readyStringPtr;
+ readyStringPtr = readyString;
+ char * errorString = "ERROR";
+ char * errorStringPtr;
+ errorStringPtr = errorString;
/* Flag to set when we get 'OK' response */
bool ok = false;
bool error = false;
@@ -151,22 +155,24 @@
modem.printf(command);
/* Newline to activate command */
modem.printf("\n");
- /* Wait untill serial feedback, max 3 seconds before timeout */
- tmout.attach(&sertmout, 3.0);
- while(!modem.readable()&& ser_timeout == false);
- while(!ok && !ser_timeout && !error) {
- if(modem.readable()) {
- for(int i = 0; i < 5; i++) {
- responsebuffer[i] = responsebuffer[i+1];
+ /* Wait untill serial feedback, max 10 seconds before timeout */
+ tmout.attach(&sertmout, 10.0);
+ int c;
+ while(!ser_timeout && !ok && !error)
+ if(modem.readable())
+ while (((c = modem.getc()) > 0) && !ser_timeout && !ok && !error) {
+ if ( (char)c == *readyStringPtr ) readyStringPtr++;
+ else readyStringPtr = readyString;
+ if ( *readyStringPtr == 0 ) {
+ ok = true;
+ }
+ if ( (char)c == *errorStringPtr ) errorStringPtr++;
+ else errorStringPtr = errorString;
+ if ( *errorStringPtr == 0 ) {
+ error = true;
+ }
}
- responsebuffer[5] = modem.getc();
- if(responsebuffer[0] == '\r' && responsebuffer[1] == '\n' && responsebuffer[2] == 'O' && responsebuffer[3] == 'K' && responsebuffer[4] == '\r' && responsebuffer[5] == '\n' ) {
- ok = true;
- } else if(responsebuffer[0] == '\r' && responsebuffer[1] == '\n' && responsebuffer[2] == 'E' && responsebuffer[3] == 'R' && responsebuffer[4] == 'R' && responsebuffer[5] == 'O' ) {
- error = true;
- }
- }
- }
tmout.detach();
- return ok;
+ if(ser_timeout) return false;
+ else return ok;
}
\ No newline at end of file
QW SIGFOX Development Kit