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.
Fork of MTS-Cellular by
TestSMS.h
00001 #ifndef TESTSMS_H 00002 #define TESTSMS_H 00003 00004 #include "mtsas.h" 00005 #include <string> 00006 #include <vector> 00007 00008 using namespace mts; 00009 00010 class TestSMS : public TestCollection 00011 { 00012 public: 00013 TestSMS(); 00014 virtual void run(); 00015 00016 private: 00017 MTSSerialFlowControl* io; 00018 Cellular* radio; 00019 }; 00020 00021 00022 TestSMS::TestSMS() : TestCollection("TestSMS") {} 00023 00024 void TestSMS::run() { 00025 00026 string number; 00027 string response; 00028 vector<string> parts; 00029 vector<Cellular::Sms> rmessages; 00030 vector<string> smessages; 00031 smessages.push_back("testing SMS 1"); 00032 smessages.push_back("testing SMS 2"); 00033 smessages.push_back("This is a longer SMS message. It is the third and final message that will be sent."); 00034 00035 MTSLog::setLogLevel(MTSLog::TRACE_LEVEL); 00036 00037 Test::start("Setup"); 00038 io = new MTSSerialFlowControl(D8, D2, D3, D6); 00039 io->baud(115200); 00040 radio = CellularFactory::create(io); 00041 if (! radio) { 00042 logError("radio is NULL"); 00043 Test::assertTrue(false); 00044 } 00045 radio->configureSignals(D4, D7, RESET); 00046 00047 for (int i = 0; i < 10; i++) { 00048 if (i >= 10) { 00049 Test::assertTrue(false); 00050 } 00051 if (radio->setApn(APN) == MTS_SUCCESS) { 00052 break; 00053 } else { 00054 wait(1); 00055 } 00056 } 00057 00058 //Wait until the SIM card is ready 00059 while (radio->sendBasicCommand("AT+CMGD=1,4", 3000) != MTS_SUCCESS); 00060 00061 Test::assertTrue(radio->deleteAllReceivedSms() == MTS_SUCCESS); 00062 Test::assertTrue(radio->getReceivedSms().size() == 0); 00063 Test::end(); 00064 00065 Test::start("Send SMS 1"); 00066 logInfo("finding my phone number"); 00067 while (true) { 00068 response = radio->sendCommand("AT+CNUM", 1000); 00069 if (response.find("ERROR") == string::npos && response.find("error") == string::npos) { 00070 break; 00071 } 00072 wait(1); 00073 } 00074 00075 //Read phone number from radio 00076 if (response.find("+CNUM:") != string::npos) { 00077 parts = Text::split(response, ","); 00078 number = parts[1]; 00079 size_t fquote = number.find("\""); 00080 size_t bquote = number.rfind("\""); 00081 number = number.substr(fquote + 1, bquote - 1); 00082 logInfo("My phone number: [%s]", number.c_str()); 00083 } else { 00084 Test::assertTrue(false); 00085 } 00086 00087 Test::assertTrue(radio->sendSMS(number, smessages[0]) == MTS_SUCCESS); 00088 Test::end(); 00089 Test::start("Send SMS 2"); 00090 Test::assertTrue(radio->sendSMS(number, smessages[1]) == MTS_SUCCESS); 00091 Test::end(); 00092 00093 wait(30); 00094 00095 Test::start("Receive SMS"); 00096 rmessages = radio->getReceivedSms(); 00097 Test::assertTrue(rmessages.size() == 2); 00098 for (int i = 0; i < rmessages.size(); i++) { 00099 Test::assertTrue(rmessages[i].message == smessages[i]); 00100 } 00101 Test::end(); 00102 00103 Test::start("Send another SMS"); 00104 Test::assertTrue(radio->sendSMS(number, smessages[2]) == MTS_SUCCESS); 00105 Test::end(); 00106 00107 wait(30); 00108 00109 /* the SMS that we haven't "read" yet should not get deleted */ 00110 Test::start("Delete Read SMS Messages"); 00111 Test::assertTrue(radio->deleteOnlyReceivedReadSms() == MTS_SUCCESS); 00112 Test::assertTrue(radio->getReceivedSms().size() == 1); 00113 Test::end(); 00114 00115 Test::start("Receive another SMS"); 00116 rmessages = radio->getReceivedSms(); 00117 Test::assertTrue(rmessages.size() == 1); 00118 Test::assertTrue(rmessages[0].message == smessages[2]); 00119 Test::end(); 00120 00121 Test::start("Delete All SMS Messages"); 00122 Test::assertTrue(radio->deleteAllReceivedSms() == MTS_SUCCESS); 00123 Test::assertTrue(radio->getReceivedSms().size() == 0); 00124 Test::end(); 00125 } 00126 00127 #endif
Generated on Wed Jul 13 2022 08:05:41 by
1.7.2
