Cellular library for MTS Socket Modem Arduino Shield devices from Multi-Tech Systems

Dependents:   mtsas mtsas mtsas mtsas

Revision:
17:dee902f7d00e
Child:
18:fa0d8120f81f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Test/TestSMS.h	Thu Jun 05 17:29:32 2014 +0000
@@ -0,0 +1,116 @@
+#ifndef TESTSMS_H
+#define TESTSMS_H
+
+#include "mtsas.h"
+#include <string>
+#include <vector>
+
+using namespace mts;
+
+class TestSMS : public TestCollection
+{
+public:
+    TestSMS();
+    virtual void run();
+    
+private:
+    MTSSerialFlowControl* io;
+    Cellular* radio;
+};
+
+TestSMS::TestSMS() : TestCollection("TestSMS") {}
+
+void TestSMS::run() {
+    string number;
+    string response;
+    vector<string> parts;
+    vector<Cellular::Sms> rmessages;
+    vector<string> smessages;
+    smessages.push_back("testing SMS 1");
+    smessages.push_back("testing SMS 2");
+    smessages.push_back("This is a longer SMS message.  It is the third and final message that will be sent.");
+    
+    MTSLog::setLogLevel(MTSLog::TRACE_LEVEL);
+    
+    Test::start("Setup");
+    io = new MTSSerialFlowControl(PTD3, PTD2, PTA12, PTC8);
+    io->baud(115200);
+    radio = CellularFactory::create(io);
+    if (! radio) {
+        logError("radio is NULL");
+        Test::assertTrue(false);
+    }
+    radio->configureSignals(PTA4, PTC9, PTA20);
+    
+    for (int i = 0; i < 10; i++) {
+        if (i >= 10) {
+            Test::assertTrue(false);
+        }
+        if (radio->setApn("wap.cingular") == SUCCESS) {
+            break;
+        } else {
+            wait(1);
+        }
+    }
+    Test::end();
+    
+    Test::start("Send SMS");
+    logInfo("finding my phone number");
+    while (true) {
+        response = radio->sendCommand("AT+CNUM", 1000);
+        if (response.find("ERROR") == string::npos && response.find("error") == string::npos) {
+            break;
+        }
+        
+        wait(1);
+    }
+    if (response.find("My Number") != string::npos) {
+        parts = Text::split(response, ",");
+        number = parts[1];
+        size_t fquote = number.find("\"");
+        size_t bquote = number.rfind("\"");
+        number = number.substr(fquote + 1, bquote - 1);
+        logInfo("my phone number: [%s]", number.c_str());
+    } else {
+        Test::assertTrue(false);
+    }
+    
+    Test::assertTrue(radio->sendSMS(number, smessages[0]) == SUCCESS);
+    Test::assertTrue(radio->sendSMS(number, smessages[1]) == SUCCESS);
+    Test::end();
+    
+    wait(30);
+    
+    Test::start("Receive SMS");
+    rmessages = radio->getReceivedSms();
+    Test::assertTrue(rmessages.size() == 2);
+    for (int i = 0; i < rmessages.size(); i++) {
+        Test::assertTrue(rmessages[i].message == smessages[i]);
+    }
+    Test::end();
+    
+    Test::start("Send another SMS");
+    Test::assertTrue(radio->sendSMS(number, smessages[2]) == SUCCESS);
+    Test::end();
+    
+    wait(30);
+    
+    /* the SMS that we haven't "read" yet should not get deleted */
+    Test::start("Delete Read SMS Messages");
+    Test::assertTrue(radio->deleteOnlyReceivedReadSms() == SUCCESS);
+    Test::assertTrue(radio->getReceivedSms().size() == 1);
+    Test::end();
+    
+    Test::start("Receive another SMS");
+    rmessages = radio->getReceivedSms();
+    Test::assertTrue(rmessages.size() == 1);
+    Test::assertTrue(rmessages[0].message == smessages[2]);
+    Test::end();
+    
+    Test::start("Delete All SMS Messages");
+    Test::assertTrue(radio->deleteAllReceivedSms() == SUCCESS);
+    Test::assertTrue(radio->getReceivedSms().size() == 0);
+    Test::end();
+}
+
+#endif
\ No newline at end of file