Ashley Mills / Mbed 2 deprecated VodafoneTestSuite

Dependencies:   mbed-rtos mbed HTTPClient VodafoneUSBModem

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Test11.h Source File

Test11.h

00001 #pragma once
00002 #include "VodafoneTestCase.h"
00003 
00004 extern const char* gTest11Description;
00005 
00006 class Test11 : public VodafoneTestCase {
00007    public:
00008       Test11(VodafoneUSBModem *m) : VodafoneTestCase(m) {
00009          _smsLen = 32;
00010          _smsMaxSize = 160;     // max size of SMS using 
00011          _numberLen = 16;
00012       }
00013       
00014    private:
00015       
00016       virtual void setupTest() {
00017          allocStorage();
00018       }
00019       
00020       virtual void endTest() {
00021          freeStorage();
00022       }
00023       
00024       virtual bool executeTest() {
00025          LOG(gTest11Description);
00026          int numIterations = 10;
00027          size_t smCount;
00028               
00029          // Clear out the SMS mail box before we run this test.
00030          // loop 3 times with a 1/2 second break in between each
00031          LOG("... Clearing out SMS mail box first");
00032          bool smsCleared = false;
00033          for(int j=0; j<3; j++) {
00034             if(_modem->getSMCount(&smCount)!=0) {
00035                LOG("Failure getting SM count");
00036                return false;
00037             }
00038          
00039             for(int i=0; i<smCount; i++) {
00040                if(_modem->getSM(_senderNumber,_smsJunkBuffer,_smsMaxSize)!=0) {
00041                   LOG("Strange! The SMS count is bigger than zero but I can't fetch the SMS?");
00042                   return false;
00043                }
00044                LOG("Got SMS: %s",_smsJunkBuffer);
00045                LOG("Clearing that out before running the test.");
00046                smsCleared = true;
00047             }
00048             Thread::wait(500);
00049          }
00050          if(!smsCleared) {
00051             LOG("Nothing found to clear out.");
00052          }
00053 
00054          LOG("Getting MSISDN");
00055          _modem->sendUSSD("*#100#",_ownNumber,_numberLen);
00056          LOG("Got  MSISDN %s",_ownNumber);
00057          for(int i=0; i<numIterations; i++) {
00058             createRandomString(_smsOut,_smsLen);
00059             
00060             LOG("Artificially waiting for 2 seconds");
00061             Thread::wait(2000);
00062             LOG("Attempting to send SMS %d of %d",i+1,numIterations);
00063             int tries = 3;
00064             int sent = 0;
00065             while(tries--) { 
00066                if(_modem->sendSM(_ownNumber,_smsOut)==0) {
00067                   sent = 1;
00068                   break;
00069                }
00070                LOG("Error sending short message");
00071             }
00072             
00073             if(!sent) {
00074                LOG("Failure to send SMS after 3 tries, aborting.");
00075                return false;
00076             } else {
00077                LOG("Sent: %s",_smsOut);
00078             }
00079             
00080             
00081             bool gotMessage = false;
00082             Timer t;
00083             t.start();
00084             int msToWait = 60000;
00085             LOG("Waiting %d seconds for response",msToWait/1000);
00086             while(!gotMessage && t.read_ms()<msToWait) {
00087                if(_modem->getSMCount(&smCount)!=0) {
00088                   LOG("Failure getting SM count");
00089                   return false;
00090                }
00091                
00092                if(smCount>0) {
00093                   if(_modem->getSM(_senderNumber,_smsIn,_smsLen)!=0) {
00094                      LOG("Failure getting SM");
00095                      return false;
00096                   }
00097                   LOG("Got SMS: %s after %f seconds.",_smsIn,t.read_ms()/1000.0);
00098                   if(strcmp(_smsIn,_smsOut)!=0) {
00099                      LOG("FAIL: strings did not match");
00100                      return false;
00101                   }
00102                   gotMessage = true;
00103                }
00104                Thread::wait(50);
00105             }
00106             if(!gotMessage) {
00107                LOG("FAIL: timeout on waiting for SMS");
00108                return false;
00109             }
00110          }
00111          
00112          return true;
00113       }
00114       
00115       void createRandomString(char *target, int len) {
00116          for(int i=0; i<len; i++) {
00117             target[i] = 65+rand()%16;
00118          }
00119          target[len-1] = 0x00;
00120       }
00121       
00122       void allocStorage() {
00123          _ownNumber    = (char*)malloc(_numberLen*sizeof(char));
00124          _senderNumber = (char*)malloc(_numberLen*sizeof(char));
00125          _smsOut       = (char*)malloc(_smsLen*sizeof(char));
00126          _smsIn        = (char*)malloc(_smsLen*sizeof(char));
00127          _smsJunkBuffer= (char*)malloc(_smsMaxSize*sizeof(char));
00128       }
00129       
00130       void freeStorage() {
00131          free(_ownNumber);
00132          free(_senderNumber);
00133          free(_smsOut);
00134          free(_smsIn);
00135          free(_smsJunkBuffer);
00136       }
00137       
00138       char* _ownNumber;
00139       char* _senderNumber;
00140       char* _smsOut;
00141       char* _smsIn;
00142       char* _smsJunkBuffer;
00143       int _smsLen;
00144       int _smsMaxSize;
00145       int _numberLen;
00146 };