ME910 support
Fork of MTS-Cellular by
Test/TestSMS.h@36:948d06b3e23c, 2014-07-23 (annotated)
- Committer:
- Vanger
- Date:
- Wed Jul 23 15:44:54 2014 +0000
- Revision:
- 36:948d06b3e23c
- Parent:
- 35:257eb41405e1
- Child:
- 41:8b9b5098696f
Changed SMS format to only add preceding '+' to UIP radio types in Cellular.cpp, and added case of ERROR to AT+CMGS result.
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() { |
Vanger | 36:948d06b3e23c | 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 | 24:32d29cdfc1fa | 52 | if (radio->setApn(APN) == MTS_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 | 25:817e9d94bfd7 | 58 | |
Vanger | 35:257eb41405e1 | 59 | //For determining when the SIM card is ready |
Vanger | 35:257eb41405e1 | 60 | std::string result; |
Vanger | 35:257eb41405e1 | 61 | for (int i = 0; i < 25; i++) { |
Vanger | 35:257eb41405e1 | 62 | if (i >= 25) { |
Vanger | 35:257eb41405e1 | 63 | Test::assertTrue(false); |
Vanger | 35:257eb41405e1 | 64 | } |
Vanger | 35:257eb41405e1 | 65 | if(radio->sendBasicCommand("AT+CMGD=1,4", 1000) == MTS_SUCCESS) { |
Vanger | 35:257eb41405e1 | 66 | break; |
Vanger | 35:257eb41405e1 | 67 | } |
Vanger | 35:257eb41405e1 | 68 | wait(1); |
Vanger | 35:257eb41405e1 | 69 | } |
Vanger | 35:257eb41405e1 | 70 | |
mfiore | 25:817e9d94bfd7 | 71 | Test::assertTrue(radio->deleteAllReceivedSms() == MTS_SUCCESS); |
mfiore | 25:817e9d94bfd7 | 72 | Test::assertTrue(radio->getReceivedSms().size() == 0); |
mfiore | 17:dee902f7d00e | 73 | Test::end(); |
mfiore | 17:dee902f7d00e | 74 | |
mfiore | 17:dee902f7d00e | 75 | Test::start("Send SMS"); |
mfiore | 17:dee902f7d00e | 76 | logInfo("finding my phone number"); |
mfiore | 17:dee902f7d00e | 77 | while (true) { |
mfiore | 17:dee902f7d00e | 78 | response = radio->sendCommand("AT+CNUM", 1000); |
mfiore | 17:dee902f7d00e | 79 | if (response.find("ERROR") == string::npos && response.find("error") == string::npos) { |
mfiore | 17:dee902f7d00e | 80 | break; |
mfiore | 17:dee902f7d00e | 81 | } |
mfiore | 17:dee902f7d00e | 82 | wait(1); |
mfiore | 17:dee902f7d00e | 83 | } |
Vanger | 35:257eb41405e1 | 84 | //Response doesn't contain "My Number", and thus will always fail |
Vanger | 35:257eb41405e1 | 85 | //Code seems to not be the same for UIP versus EasyIP |
Vanger | 35:257eb41405e1 | 86 | if (response.find("+CNUM:") != string::npos) { |
mfiore | 17:dee902f7d00e | 87 | parts = Text::split(response, ","); |
mfiore | 17:dee902f7d00e | 88 | number = parts[1]; |
mfiore | 17:dee902f7d00e | 89 | size_t fquote = number.find("\""); |
mfiore | 17:dee902f7d00e | 90 | size_t bquote = number.rfind("\""); |
mfiore | 17:dee902f7d00e | 91 | number = number.substr(fquote + 1, bquote - 1); |
Vanger | 35:257eb41405e1 | 92 | logInfo("My phone number: [%s]", number.c_str()); |
mfiore | 17:dee902f7d00e | 93 | } else { |
mfiore | 17:dee902f7d00e | 94 | Test::assertTrue(false); |
mfiore | 17:dee902f7d00e | 95 | } |
mfiore | 17:dee902f7d00e | 96 | |
mfiore | 24:32d29cdfc1fa | 97 | Test::assertTrue(radio->sendSMS(number, smessages[0]) == MTS_SUCCESS); |
mfiore | 24:32d29cdfc1fa | 98 | Test::assertTrue(radio->sendSMS(number, smessages[1]) == MTS_SUCCESS); |
mfiore | 17:dee902f7d00e | 99 | Test::end(); |
mfiore | 17:dee902f7d00e | 100 | |
mfiore | 17:dee902f7d00e | 101 | wait(30); |
mfiore | 17:dee902f7d00e | 102 | |
mfiore | 17:dee902f7d00e | 103 | Test::start("Receive SMS"); |
mfiore | 17:dee902f7d00e | 104 | rmessages = radio->getReceivedSms(); |
mfiore | 17:dee902f7d00e | 105 | Test::assertTrue(rmessages.size() == 2); |
mfiore | 17:dee902f7d00e | 106 | for (int i = 0; i < rmessages.size(); i++) { |
mfiore | 17:dee902f7d00e | 107 | Test::assertTrue(rmessages[i].message == smessages[i]); |
mfiore | 17:dee902f7d00e | 108 | } |
mfiore | 17:dee902f7d00e | 109 | Test::end(); |
mfiore | 17:dee902f7d00e | 110 | |
mfiore | 17:dee902f7d00e | 111 | Test::start("Send another SMS"); |
mfiore | 24:32d29cdfc1fa | 112 | Test::assertTrue(radio->sendSMS(number, smessages[2]) == MTS_SUCCESS); |
mfiore | 17:dee902f7d00e | 113 | Test::end(); |
mfiore | 17:dee902f7d00e | 114 | |
mfiore | 17:dee902f7d00e | 115 | wait(30); |
mfiore | 17:dee902f7d00e | 116 | |
mfiore | 17:dee902f7d00e | 117 | /* the SMS that we haven't "read" yet should not get deleted */ |
mfiore | 17:dee902f7d00e | 118 | Test::start("Delete Read SMS Messages"); |
mfiore | 24:32d29cdfc1fa | 119 | Test::assertTrue(radio->deleteOnlyReceivedReadSms() == MTS_SUCCESS); |
mfiore | 17:dee902f7d00e | 120 | Test::assertTrue(radio->getReceivedSms().size() == 1); |
mfiore | 17:dee902f7d00e | 121 | Test::end(); |
mfiore | 17:dee902f7d00e | 122 | |
mfiore | 17:dee902f7d00e | 123 | Test::start("Receive another SMS"); |
mfiore | 17:dee902f7d00e | 124 | rmessages = radio->getReceivedSms(); |
mfiore | 17:dee902f7d00e | 125 | Test::assertTrue(rmessages.size() == 1); |
mfiore | 17:dee902f7d00e | 126 | Test::assertTrue(rmessages[0].message == smessages[2]); |
mfiore | 17:dee902f7d00e | 127 | Test::end(); |
mfiore | 17:dee902f7d00e | 128 | |
mfiore | 17:dee902f7d00e | 129 | Test::start("Delete All SMS Messages"); |
mfiore | 24:32d29cdfc1fa | 130 | Test::assertTrue(radio->deleteAllReceivedSms() == MTS_SUCCESS); |
mfiore | 17:dee902f7d00e | 131 | Test::assertTrue(radio->getReceivedSms().size() == 0); |
mfiore | 17:dee902f7d00e | 132 | Test::end(); |
mfiore | 17:dee902f7d00e | 133 | } |
mfiore | 17:dee902f7d00e | 134 | |
mfiore | 17:dee902f7d00e | 135 | #endif |