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.
Dependencies: mbed-rtos mbed HTTPClient VodafoneUSBModem
Test12.h
00001 #pragma once 00002 #include "VodafoneTestCase.h" 00003 00004 // Test 12: x2 -> Send 25 SMS, wait for recv, read them quickly. 00005 extern const char* gTest12Description; 00006 00007 class Test12 : public VodafoneTestCase { 00008 public: 00009 Test12(VodafoneUSBModem *m) : VodafoneTestCase(m) { 00010 _smsLen = 32; 00011 _smsMaxSize = 160; // max size of SMS using 00012 _numberLen = 16; 00013 } 00014 00015 private: 00016 00017 virtual void setupTest() { 00018 allocStorage(); 00019 } 00020 00021 virtual void endTest() { 00022 freeStorage(); 00023 } 00024 00025 virtual bool executeTest() { 00026 // locals 00027 int smsToSend = 50, mailBoxSize = 25; 00028 int tries = 0, sent = 0; 00029 size_t smCount, oldSMCount; 00030 Timer t; 00031 00032 LOG(gTest12Description); 00033 00034 // Clear out the SMS mail box before we run this test. 00035 // loop 3 times with a 1/2 second break in between each 00036 LOG("... Clearing out SMS mail box first"); 00037 for(int j=0; j<3; j++) { 00038 if(_modem->getSMCount(&smCount)!=0) { 00039 LOG("Failure getting SM count"); 00040 return false; 00041 } 00042 00043 for(int i=0; i<smCount; i++) { 00044 if(_modem->getSM(_senderNumber,_smsJunkBuffer,_smsMaxSize)!=0) { 00045 LOG("Strange! The SMS count is bigger than zero but I can't fetch the SMS?"); 00046 return false; 00047 } 00048 LOG("Deleting SMS: \"%s\"",_smsJunkBuffer); 00049 } 00050 Thread::wait(500); 00051 } 00052 00053 // get own number 00054 LOG("Getting MSISDN"); 00055 _modem->sendUSSD("*#100#",_ownNumber,_numberLen); 00056 LOG("Got MSISDN %s",_ownNumber); 00057 00058 // send 50 SMS to self 00059 00060 for(int i=0; i<smsToSend; i++) { 00061 if(i<mailBoxSize) { 00062 sprintf(_smsOut,"A SMS %d",i); 00063 } else { 00064 sprintf(_smsOut,"B SMS %d",i); 00065 } 00066 tries = 3; 00067 sent = 0; 00068 while(tries--) { 00069 if(_modem->sendSM(_ownNumber,_smsOut)==0) { 00070 sent = 1; 00071 break; 00072 } 00073 LOG("Error sending SM, trying again."); 00074 } 00075 00076 if(!sent) { 00077 LOG("Error sending short message"); 00078 return false; 00079 } else { 00080 LOG("Sent %d/%d: \"%s\"",i,smsToSend,_smsOut); 00081 } 00082 Thread::wait(50); 00083 } 00084 Thread::wait(5000); 00085 00086 // wait for 25 to arrive and then read them as quickly as possible 00087 smCount = 0, oldSMCount = 0; 00088 t.start(); 00089 LOG("waiting for messages"); 00090 00091 // wait a maximum of 10 minutes 00092 while(smCount<mailBoxSize&&t.read_ms()<600000) { 00093 if(_modem->getSMCount(&smCount)!=0) { 00094 LOG("Failure getting SM count"); 00095 return false; 00096 } else { 00097 if(smCount!=oldSMCount) { 00098 LOG("smCount: %d",smCount); 00099 oldSMCount = smCount; 00100 } 00101 } 00102 Thread::wait(500); 00103 } 00104 if(smCount<mailBoxSize) { 00105 LOG("Timeout waiting for SMSs, got to %d",smCount); 00106 return false; 00107 } 00108 00109 00110 LOG("dumping SMS"); 00111 for(int i=0; i<mailBoxSize; i++) { 00112 if(_modem->getSM(_senderNumber,_smsIn,_smsLen)!=0) { 00113 LOG("Error reading SMS %d",i); 00114 return false; 00115 } else { 00116 LOG("Got SMS: \"%s\" (%s)",_smsIn,_senderNumber); 00117 } 00118 } 00119 00120 // wait for next 25 to arrive and then read them as quickly as possible 00121 smCount = 0, oldSMCount = 0; 00122 t.start(); 00123 // wait a maximum of 10 minutes 00124 LOG("Waiting for messages"); 00125 00126 while(smCount<mailBoxSize&&t.read_ms()<600000) { 00127 if(_modem->getSMCount(&smCount)!=0) { 00128 LOG("Failure getting SM count"); 00129 return false; 00130 } else { 00131 if(smCount!=oldSMCount) { 00132 LOG("smCount: %d",smCount); 00133 oldSMCount = smCount; 00134 } 00135 } 00136 Thread::wait(500); 00137 } 00138 if(smCount!=mailBoxSize) { 00139 LOG("Timeout waiting for SMSs, got to %d",smCount); 00140 return false; 00141 } 00142 00143 LOG("dumping SMS"); 00144 for(int i=0; i<mailBoxSize; i++) { 00145 if(_modem->getSM(_senderNumber,_smsIn,_smsLen)!=0) { 00146 LOG("Error reading SMS %d",i); 00147 return false; 00148 } else { 00149 LOG("Got SMS: \"%s\" (%s)",_smsIn,_senderNumber); 00150 } 00151 } 00152 00153 return true; 00154 } 00155 00156 void allocStorage() { 00157 _ownNumber = (char*)malloc(_numberLen*sizeof(char)); 00158 _senderNumber = (char*)malloc(_numberLen*sizeof(char)); 00159 _smsOut = (char*)malloc(_smsLen*sizeof(char)); 00160 _smsIn = (char*)malloc(_smsLen*sizeof(char)); 00161 _smsJunkBuffer= (char*)malloc(_smsMaxSize*sizeof(char)); 00162 } 00163 00164 void freeStorage() { 00165 free(_ownNumber); 00166 free(_senderNumber); 00167 free(_smsOut); 00168 free(_smsIn); 00169 free(_smsJunkBuffer); 00170 } 00171 00172 char* _ownNumber; 00173 char* _senderNumber; 00174 char* _smsOut; 00175 char* _smsIn; 00176 char* _smsJunkBuffer; 00177 int _smsLen; 00178 int _smsMaxSize; 00179 int _numberLen; 00180 };
Generated on Sun Jul 17 2022 01:04:13 by
1.7.2