ME910 support
Fork of MTS-Cellular by
Test/TestSMS.h@81:6d601e345d0f, 2017-09-07 (annotated)
- Committer:
- pferland
- Date:
- Thu Sep 07 16:11:14 2017 +0000
- Revision:
- 81:6d601e345d0f
- Parent:
- 74:d232ae44d136
Preliminary support for ME910C1
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 | |
mfiore | 17:dee902f7d00e | 26 | string number; |
mfiore | 17:dee902f7d00e | 27 | string response; |
mfiore | 17:dee902f7d00e | 28 | vector<string> parts; |
mfiore | 17:dee902f7d00e | 29 | vector<Cellular::Sms> rmessages; |
mfiore | 17:dee902f7d00e | 30 | vector<string> smessages; |
mfiore | 17:dee902f7d00e | 31 | smessages.push_back("testing SMS 1"); |
mfiore | 17:dee902f7d00e | 32 | smessages.push_back("testing SMS 2"); |
mfiore | 17:dee902f7d00e | 33 | smessages.push_back("This is a longer SMS message. It is the third and final message that will be sent."); |
mfiore | 17:dee902f7d00e | 34 | |
mfiore | 17:dee902f7d00e | 35 | MTSLog::setLogLevel(MTSLog::TRACE_LEVEL); |
mfiore | 17:dee902f7d00e | 36 | |
mfiore | 17:dee902f7d00e | 37 | Test::start("Setup"); |
mfiore | 18:fa0d8120f81f | 38 | io = new MTSSerialFlowControl(D8, D2, D3, D6); |
mfiore | 17:dee902f7d00e | 39 | io->baud(115200); |
mfiore | 17:dee902f7d00e | 40 | radio = CellularFactory::create(io); |
mfiore | 17:dee902f7d00e | 41 | if (! radio) { |
mfiore | 17:dee902f7d00e | 42 | logError("radio is NULL"); |
mfiore | 17:dee902f7d00e | 43 | Test::assertTrue(false); |
mfiore | 17:dee902f7d00e | 44 | } |
mfiore | 18:fa0d8120f81f | 45 | radio->configureSignals(D4, D7, RESET); |
mfiore | 17:dee902f7d00e | 46 | |
mfiore | 17:dee902f7d00e | 47 | for (int i = 0; i < 10; i++) { |
mfiore | 17:dee902f7d00e | 48 | if (i >= 10) { |
mfiore | 17:dee902f7d00e | 49 | Test::assertTrue(false); |
mfiore | 17:dee902f7d00e | 50 | } |
mfiore | 24:32d29cdfc1fa | 51 | if (radio->setApn(APN) == MTS_SUCCESS) { |
mfiore | 17:dee902f7d00e | 52 | break; |
mfiore | 17:dee902f7d00e | 53 | } else { |
mfiore | 17:dee902f7d00e | 54 | wait(1); |
mfiore | 17:dee902f7d00e | 55 | } |
mfiore | 17:dee902f7d00e | 56 | } |
mfiore | 25:817e9d94bfd7 | 57 | |
Vanger | 52:2cb58398a4f9 | 58 | //Wait until the SIM card is ready |
Vanger | 56:43205bd2752a | 59 | while (radio->sendBasicCommand("AT+CMGD=1,4", 3000) != MTS_SUCCESS); |
Vanger | 35:257eb41405e1 | 60 | |
mfiore | 25:817e9d94bfd7 | 61 | Test::assertTrue(radio->deleteAllReceivedSms() == MTS_SUCCESS); |
mfiore | 25:817e9d94bfd7 | 62 | Test::assertTrue(radio->getReceivedSms().size() == 0); |
mfiore | 17:dee902f7d00e | 63 | Test::end(); |
mfiore | 17:dee902f7d00e | 64 | |
Vanger | 48:3f9d82915e83 | 65 | Test::start("Send SMS 1"); |
mfiore | 17:dee902f7d00e | 66 | logInfo("finding my phone number"); |
mfiore | 17:dee902f7d00e | 67 | while (true) { |
mfiore | 17:dee902f7d00e | 68 | response = radio->sendCommand("AT+CNUM", 1000); |
mfiore | 17:dee902f7d00e | 69 | if (response.find("ERROR") == string::npos && response.find("error") == string::npos) { |
mfiore | 17:dee902f7d00e | 70 | break; |
mfiore | 17:dee902f7d00e | 71 | } |
mfiore | 17:dee902f7d00e | 72 | wait(1); |
mfiore | 17:dee902f7d00e | 73 | } |
Vanger | 52:2cb58398a4f9 | 74 | |
Vanger | 52:2cb58398a4f9 | 75 | //Read phone number from radio |
Vanger | 35:257eb41405e1 | 76 | if (response.find("+CNUM:") != string::npos) { |
mfiore | 17:dee902f7d00e | 77 | parts = Text::split(response, ","); |
mfiore | 17:dee902f7d00e | 78 | number = parts[1]; |
mfiore | 17:dee902f7d00e | 79 | size_t fquote = number.find("\""); |
mfiore | 17:dee902f7d00e | 80 | size_t bquote = number.rfind("\""); |
mfiore | 17:dee902f7d00e | 81 | number = number.substr(fquote + 1, bquote - 1); |
Vanger | 35:257eb41405e1 | 82 | logInfo("My phone number: [%s]", number.c_str()); |
mfiore | 17:dee902f7d00e | 83 | } else { |
mfiore | 17:dee902f7d00e | 84 | Test::assertTrue(false); |
mfiore | 17:dee902f7d00e | 85 | } |
mfiore | 17:dee902f7d00e | 86 | |
mfiore | 24:32d29cdfc1fa | 87 | Test::assertTrue(radio->sendSMS(number, smessages[0]) == MTS_SUCCESS); |
Vanger | 48:3f9d82915e83 | 88 | Test::end(); |
Vanger | 48:3f9d82915e83 | 89 | Test::start("Send SMS 2"); |
mfiore | 24:32d29cdfc1fa | 90 | Test::assertTrue(radio->sendSMS(number, smessages[1]) == MTS_SUCCESS); |
mfiore | 17:dee902f7d00e | 91 | Test::end(); |
mfiore | 17:dee902f7d00e | 92 | |
mfiore | 17:dee902f7d00e | 93 | wait(30); |
mfiore | 17:dee902f7d00e | 94 | |
mfiore | 17:dee902f7d00e | 95 | Test::start("Receive SMS"); |
mfiore | 17:dee902f7d00e | 96 | rmessages = radio->getReceivedSms(); |
mfiore | 17:dee902f7d00e | 97 | Test::assertTrue(rmessages.size() == 2); |
mfiore | 17:dee902f7d00e | 98 | for (int i = 0; i < rmessages.size(); i++) { |
mfiore | 17:dee902f7d00e | 99 | Test::assertTrue(rmessages[i].message == smessages[i]); |
mfiore | 17:dee902f7d00e | 100 | } |
mfiore | 17:dee902f7d00e | 101 | Test::end(); |
mfiore | 17:dee902f7d00e | 102 | |
mfiore | 17:dee902f7d00e | 103 | Test::start("Send another SMS"); |
mfiore | 24:32d29cdfc1fa | 104 | Test::assertTrue(radio->sendSMS(number, smessages[2]) == MTS_SUCCESS); |
mfiore | 17:dee902f7d00e | 105 | Test::end(); |
mfiore | 17:dee902f7d00e | 106 | |
mfiore | 17:dee902f7d00e | 107 | wait(30); |
mfiore | 17:dee902f7d00e | 108 | |
mfiore | 17:dee902f7d00e | 109 | /* the SMS that we haven't "read" yet should not get deleted */ |
mfiore | 17:dee902f7d00e | 110 | Test::start("Delete Read SMS Messages"); |
mfiore | 24:32d29cdfc1fa | 111 | Test::assertTrue(radio->deleteOnlyReceivedReadSms() == MTS_SUCCESS); |
mfiore | 17:dee902f7d00e | 112 | Test::assertTrue(radio->getReceivedSms().size() == 1); |
mfiore | 17:dee902f7d00e | 113 | Test::end(); |
mfiore | 17:dee902f7d00e | 114 | |
mfiore | 17:dee902f7d00e | 115 | Test::start("Receive another SMS"); |
mfiore | 17:dee902f7d00e | 116 | rmessages = radio->getReceivedSms(); |
mfiore | 17:dee902f7d00e | 117 | Test::assertTrue(rmessages.size() == 1); |
mfiore | 17:dee902f7d00e | 118 | Test::assertTrue(rmessages[0].message == smessages[2]); |
mfiore | 17:dee902f7d00e | 119 | Test::end(); |
mfiore | 17:dee902f7d00e | 120 | |
mfiore | 17:dee902f7d00e | 121 | Test::start("Delete All SMS Messages"); |
mfiore | 24:32d29cdfc1fa | 122 | Test::assertTrue(radio->deleteAllReceivedSms() == MTS_SUCCESS); |
mfiore | 17:dee902f7d00e | 123 | Test::assertTrue(radio->getReceivedSms().size() == 0); |
mfiore | 17:dee902f7d00e | 124 | Test::end(); |
mfiore | 17:dee902f7d00e | 125 | } |
mfiore | 17:dee902f7d00e | 126 | |
mfiore | 17:dee902f7d00e | 127 | #endif |