ME910 support
Fork of MTS-Cellular by
Test/TestSMS.h@21:916ef2da10f1, 2014-06-17 (annotated)
- Committer:
- mfiore
- Date:
- Tue Jun 17 22:02:22 2014 +0000
- Revision:
- 21:916ef2da10f1
- Parent:
- 20:7cc2f55fb16b
- Child:
- 24:32d29cdfc1fa
fix compile error with APN
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mfiore | 17:dee902f7d00e | 1 | #ifndef TESTSMS_H |
mfiore | 17:dee902f7d00e | 2 | #define TESTSMS_H |
mfiore | 17:dee902f7d00e | 3 | |
mfiore | 17:dee902f7d00e | 4 | #include "mtsas.h" |
mfiore | 17:dee902f7d00e | 5 | #include <string> |
mfiore | 17:dee902f7d00e | 6 | #include <vector> |
mfiore | 17:dee902f7d00e | 7 | |
mfiore | 17:dee902f7d00e | 8 | using namespace mts; |
mfiore | 17:dee902f7d00e | 9 | |
mfiore | 17:dee902f7d00e | 10 | class TestSMS : public TestCollection |
mfiore | 17:dee902f7d00e | 11 | { |
mfiore | 17:dee902f7d00e | 12 | public: |
mfiore | 17:dee902f7d00e | 13 | TestSMS(); |
mfiore | 17:dee902f7d00e | 14 | virtual void run(); |
mfiore | 17:dee902f7d00e | 15 | |
mfiore | 17:dee902f7d00e | 16 | private: |
mfiore | 17:dee902f7d00e | 17 | MTSSerialFlowControl* io; |
mfiore | 17:dee902f7d00e | 18 | Cellular* radio; |
mfiore | 17:dee902f7d00e | 19 | }; |
mfiore | 17:dee902f7d00e | 20 | |
mfiore | 20:7cc2f55fb16b | 21 | |
mfiore | 17:dee902f7d00e | 22 | TestSMS::TestSMS() : TestCollection("TestSMS") {} |
mfiore | 17:dee902f7d00e | 23 | |
mfiore | 17:dee902f7d00e | 24 | void TestSMS::run() { |
mfiore | 21:916ef2da10f1 | 25 | const char APN[] = ""; |
mfiore | 21:916ef2da10f1 | 26 | |
mfiore | 17:dee902f7d00e | 27 | string number; |
mfiore | 17:dee902f7d00e | 28 | string response; |
mfiore | 17:dee902f7d00e | 29 | vector<string> parts; |
mfiore | 17:dee902f7d00e | 30 | vector<Cellular::Sms> rmessages; |
mfiore | 17:dee902f7d00e | 31 | vector<string> smessages; |
mfiore | 17:dee902f7d00e | 32 | smessages.push_back("testing SMS 1"); |
mfiore | 17:dee902f7d00e | 33 | smessages.push_back("testing SMS 2"); |
mfiore | 17:dee902f7d00e | 34 | smessages.push_back("This is a longer SMS message. It is the third and final message that will be sent."); |
mfiore | 17:dee902f7d00e | 35 | |
mfiore | 17:dee902f7d00e | 36 | MTSLog::setLogLevel(MTSLog::TRACE_LEVEL); |
mfiore | 17:dee902f7d00e | 37 | |
mfiore | 17:dee902f7d00e | 38 | Test::start("Setup"); |
mfiore | 18:fa0d8120f81f | 39 | io = new MTSSerialFlowControl(D8, D2, D3, D6); |
mfiore | 17:dee902f7d00e | 40 | io->baud(115200); |
mfiore | 17:dee902f7d00e | 41 | radio = CellularFactory::create(io); |
mfiore | 17:dee902f7d00e | 42 | if (! radio) { |
mfiore | 17:dee902f7d00e | 43 | logError("radio is NULL"); |
mfiore | 17:dee902f7d00e | 44 | Test::assertTrue(false); |
mfiore | 17:dee902f7d00e | 45 | } |
mfiore | 18:fa0d8120f81f | 46 | radio->configureSignals(D4, D7, RESET); |
mfiore | 17:dee902f7d00e | 47 | |
mfiore | 17:dee902f7d00e | 48 | for (int i = 0; i < 10; i++) { |
mfiore | 17:dee902f7d00e | 49 | if (i >= 10) { |
mfiore | 17:dee902f7d00e | 50 | Test::assertTrue(false); |
mfiore | 17:dee902f7d00e | 51 | } |
mfiore | 20:7cc2f55fb16b | 52 | if (radio->setApn(APN) == SUCCESS) { |
mfiore | 17:dee902f7d00e | 53 | break; |
mfiore | 17:dee902f7d00e | 54 | } else { |
mfiore | 17:dee902f7d00e | 55 | wait(1); |
mfiore | 17:dee902f7d00e | 56 | } |
mfiore | 17:dee902f7d00e | 57 | } |
mfiore | 17:dee902f7d00e | 58 | Test::end(); |
mfiore | 17:dee902f7d00e | 59 | |
mfiore | 17:dee902f7d00e | 60 | Test::start("Send SMS"); |
mfiore | 17:dee902f7d00e | 61 | logInfo("finding my phone number"); |
mfiore | 17:dee902f7d00e | 62 | while (true) { |
mfiore | 17:dee902f7d00e | 63 | response = radio->sendCommand("AT+CNUM", 1000); |
mfiore | 17:dee902f7d00e | 64 | if (response.find("ERROR") == string::npos && response.find("error") == string::npos) { |
mfiore | 17:dee902f7d00e | 65 | break; |
mfiore | 17:dee902f7d00e | 66 | } |
mfiore | 17:dee902f7d00e | 67 | |
mfiore | 17:dee902f7d00e | 68 | wait(1); |
mfiore | 17:dee902f7d00e | 69 | } |
mfiore | 17:dee902f7d00e | 70 | if (response.find("My Number") != string::npos) { |
mfiore | 17:dee902f7d00e | 71 | parts = Text::split(response, ","); |
mfiore | 17:dee902f7d00e | 72 | number = parts[1]; |
mfiore | 17:dee902f7d00e | 73 | size_t fquote = number.find("\""); |
mfiore | 17:dee902f7d00e | 74 | size_t bquote = number.rfind("\""); |
mfiore | 17:dee902f7d00e | 75 | number = number.substr(fquote + 1, bquote - 1); |
mfiore | 17:dee902f7d00e | 76 | logInfo("my phone number: [%s]", number.c_str()); |
mfiore | 17:dee902f7d00e | 77 | } else { |
mfiore | 17:dee902f7d00e | 78 | Test::assertTrue(false); |
mfiore | 17:dee902f7d00e | 79 | } |
mfiore | 17:dee902f7d00e | 80 | |
mfiore | 17:dee902f7d00e | 81 | Test::assertTrue(radio->sendSMS(number, smessages[0]) == SUCCESS); |
mfiore | 17:dee902f7d00e | 82 | Test::assertTrue(radio->sendSMS(number, smessages[1]) == SUCCESS); |
mfiore | 17:dee902f7d00e | 83 | Test::end(); |
mfiore | 17:dee902f7d00e | 84 | |
mfiore | 17:dee902f7d00e | 85 | wait(30); |
mfiore | 17:dee902f7d00e | 86 | |
mfiore | 17:dee902f7d00e | 87 | Test::start("Receive SMS"); |
mfiore | 17:dee902f7d00e | 88 | rmessages = radio->getReceivedSms(); |
mfiore | 17:dee902f7d00e | 89 | Test::assertTrue(rmessages.size() == 2); |
mfiore | 17:dee902f7d00e | 90 | for (int i = 0; i < rmessages.size(); i++) { |
mfiore | 17:dee902f7d00e | 91 | Test::assertTrue(rmessages[i].message == smessages[i]); |
mfiore | 17:dee902f7d00e | 92 | } |
mfiore | 17:dee902f7d00e | 93 | Test::end(); |
mfiore | 17:dee902f7d00e | 94 | |
mfiore | 17:dee902f7d00e | 95 | Test::start("Send another SMS"); |
mfiore | 17:dee902f7d00e | 96 | Test::assertTrue(radio->sendSMS(number, smessages[2]) == SUCCESS); |
mfiore | 17:dee902f7d00e | 97 | Test::end(); |
mfiore | 17:dee902f7d00e | 98 | |
mfiore | 17:dee902f7d00e | 99 | wait(30); |
mfiore | 17:dee902f7d00e | 100 | |
mfiore | 17:dee902f7d00e | 101 | /* the SMS that we haven't "read" yet should not get deleted */ |
mfiore | 17:dee902f7d00e | 102 | Test::start("Delete Read SMS Messages"); |
mfiore | 17:dee902f7d00e | 103 | Test::assertTrue(radio->deleteOnlyReceivedReadSms() == SUCCESS); |
mfiore | 17:dee902f7d00e | 104 | Test::assertTrue(radio->getReceivedSms().size() == 1); |
mfiore | 17:dee902f7d00e | 105 | Test::end(); |
mfiore | 17:dee902f7d00e | 106 | |
mfiore | 17:dee902f7d00e | 107 | Test::start("Receive another SMS"); |
mfiore | 17:dee902f7d00e | 108 | rmessages = radio->getReceivedSms(); |
mfiore | 17:dee902f7d00e | 109 | Test::assertTrue(rmessages.size() == 1); |
mfiore | 17:dee902f7d00e | 110 | Test::assertTrue(rmessages[0].message == smessages[2]); |
mfiore | 17:dee902f7d00e | 111 | Test::end(); |
mfiore | 17:dee902f7d00e | 112 | |
mfiore | 17:dee902f7d00e | 113 | Test::start("Delete All SMS Messages"); |
mfiore | 17:dee902f7d00e | 114 | Test::assertTrue(radio->deleteAllReceivedSms() == SUCCESS); |
mfiore | 17:dee902f7d00e | 115 | Test::assertTrue(radio->getReceivedSms().size() == 0); |
mfiore | 17:dee902f7d00e | 116 | Test::end(); |
mfiore | 17:dee902f7d00e | 117 | } |
mfiore | 17:dee902f7d00e | 118 | |
mfiore | 17:dee902f7d00e | 119 | #endif |