Vodafone Test Suite
Dependencies: mbed-rtos mbed HTTPClient VodafoneUSBModem
Tests/Test12.h@74:e52ac9624f7f, 2014-01-29 (annotated)
- Committer:
- ashleymills
- Date:
- Wed Jan 29 16:34:38 2014 +0000
- Revision:
- 74:e52ac9624f7f
- Parent:
- 72:0e8e769fcf76
Updated dependencies to latest versions.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nherriot | 5:b68400bd0738 | 1 | #pragma once |
nherriot | 5:b68400bd0738 | 2 | #include "VodafoneTestCase.h" |
nherriot | 5:b68400bd0738 | 3 | |
ashleymills | 72:0e8e769fcf76 | 4 | // Test 12: x2 -> Send 25 SMS, wait for recv, read them quickly. |
ashleymills | 66:6b00a764e549 | 5 | extern const char* gTest12Description; |
nherriot | 13:8b69853966f8 | 6 | |
nherriot | 5:b68400bd0738 | 7 | class Test12 : public VodafoneTestCase { |
ashleymills | 66:6b00a764e549 | 8 | public: |
ashleymills | 66:6b00a764e549 | 9 | Test12(VodafoneUSBModem *m) : VodafoneTestCase(m) { |
ashleymills | 66:6b00a764e549 | 10 | _smsLen = 32; |
ashleymills | 66:6b00a764e549 | 11 | _smsMaxSize = 160; // max size of SMS using |
ashleymills | 66:6b00a764e549 | 12 | _numberLen = 16; |
ashleymills | 66:6b00a764e549 | 13 | } |
ashleymills | 44:6d0ac4747f5b | 14 | |
ashleymills | 44:6d0ac4747f5b | 15 | private: |
ashleymills | 66:6b00a764e549 | 16 | |
ashleymills | 66:6b00a764e549 | 17 | virtual void setupTest() { |
ashleymills | 66:6b00a764e549 | 18 | allocStorage(); |
ashleymills | 66:6b00a764e549 | 19 | } |
ashleymills | 66:6b00a764e549 | 20 | |
ashleymills | 66:6b00a764e549 | 21 | virtual void endTest() { |
ashleymills | 66:6b00a764e549 | 22 | freeStorage(); |
ashleymills | 66:6b00a764e549 | 23 | } |
nherriot | 5:b68400bd0738 | 24 | |
ashleymills | 66:6b00a764e549 | 25 | virtual bool executeTest() { |
ashleymills | 66:6b00a764e549 | 26 | // locals |
ashleymills | 66:6b00a764e549 | 27 | int smsToSend = 50, mailBoxSize = 25; |
ashleymills | 72:0e8e769fcf76 | 28 | int tries = 0, sent = 0; |
ashleymills | 66:6b00a764e549 | 29 | size_t smCount, oldSMCount; |
ashleymills | 66:6b00a764e549 | 30 | Timer t; |
ashleymills | 66:6b00a764e549 | 31 | |
ashleymills | 66:6b00a764e549 | 32 | LOG(gTest12Description); |
ashleymills | 66:6b00a764e549 | 33 | |
ashleymills | 66:6b00a764e549 | 34 | // Clear out the SMS mail box before we run this test. |
ashleymills | 66:6b00a764e549 | 35 | // loop 3 times with a 1/2 second break in between each |
ashleymills | 66:6b00a764e549 | 36 | LOG("... Clearing out SMS mail box first"); |
ashleymills | 66:6b00a764e549 | 37 | for(int j=0; j<3; j++) { |
ashleymills | 66:6b00a764e549 | 38 | if(_modem->getSMCount(&smCount)!=0) { |
ashleymills | 72:0e8e769fcf76 | 39 | LOG("Failure getting SM count"); |
ashleymills | 66:6b00a764e549 | 40 | return false; |
ashleymills | 66:6b00a764e549 | 41 | } |
ashleymills | 66:6b00a764e549 | 42 | |
ashleymills | 66:6b00a764e549 | 43 | for(int i=0; i<smCount; i++) { |
ashleymills | 66:6b00a764e549 | 44 | if(_modem->getSM(_senderNumber,_smsJunkBuffer,_smsMaxSize)!=0) { |
ashleymills | 66:6b00a764e549 | 45 | LOG("Strange! The SMS count is bigger than zero but I can't fetch the SMS?"); |
ashleymills | 66:6b00a764e549 | 46 | return false; |
ashleymills | 66:6b00a764e549 | 47 | } |
ashleymills | 66:6b00a764e549 | 48 | LOG("Deleting SMS: \"%s\"",_smsJunkBuffer); |
ashleymills | 66:6b00a764e549 | 49 | } |
ashleymills | 66:6b00a764e549 | 50 | Thread::wait(500); |
ashleymills | 66:6b00a764e549 | 51 | } |
ashleymills | 66:6b00a764e549 | 52 | |
ashleymills | 66:6b00a764e549 | 53 | // get own number |
ashleymills | 66:6b00a764e549 | 54 | LOG("Getting MSISDN"); |
ashleymills | 66:6b00a764e549 | 55 | _modem->sendUSSD("*#100#",_ownNumber,_numberLen); |
ashleymills | 66:6b00a764e549 | 56 | LOG("Got MSISDN %s",_ownNumber); |
ashleymills | 66:6b00a764e549 | 57 | |
ashleymills | 66:6b00a764e549 | 58 | // send 50 SMS to self |
ashleymills | 66:6b00a764e549 | 59 | |
ashleymills | 66:6b00a764e549 | 60 | for(int i=0; i<smsToSend; i++) { |
ashleymills | 66:6b00a764e549 | 61 | if(i<mailBoxSize) { |
ashleymills | 66:6b00a764e549 | 62 | sprintf(_smsOut,"A SMS %d",i); |
ashleymills | 66:6b00a764e549 | 63 | } else { |
ashleymills | 66:6b00a764e549 | 64 | sprintf(_smsOut,"B SMS %d",i); |
ashleymills | 66:6b00a764e549 | 65 | } |
ashleymills | 72:0e8e769fcf76 | 66 | tries = 3; |
ashleymills | 72:0e8e769fcf76 | 67 | sent = 0; |
ashleymills | 72:0e8e769fcf76 | 68 | while(tries--) { |
ashleymills | 72:0e8e769fcf76 | 69 | if(_modem->sendSM(_ownNumber,_smsOut)==0) { |
ashleymills | 72:0e8e769fcf76 | 70 | sent = 1; |
ashleymills | 72:0e8e769fcf76 | 71 | break; |
ashleymills | 72:0e8e769fcf76 | 72 | } |
ashleymills | 72:0e8e769fcf76 | 73 | LOG("Error sending SM, trying again."); |
ashleymills | 72:0e8e769fcf76 | 74 | } |
ashleymills | 72:0e8e769fcf76 | 75 | |
ashleymills | 72:0e8e769fcf76 | 76 | if(!sent) { |
ashleymills | 66:6b00a764e549 | 77 | LOG("Error sending short message"); |
ashleymills | 66:6b00a764e549 | 78 | return false; |
ashleymills | 66:6b00a764e549 | 79 | } else { |
ashleymills | 66:6b00a764e549 | 80 | LOG("Sent %d/%d: \"%s\"",i,smsToSend,_smsOut); |
ashleymills | 66:6b00a764e549 | 81 | } |
ashleymills | 72:0e8e769fcf76 | 82 | Thread::wait(50); |
ashleymills | 66:6b00a764e549 | 83 | } |
ashleymills | 66:6b00a764e549 | 84 | Thread::wait(5000); |
ashleymills | 66:6b00a764e549 | 85 | |
ashleymills | 66:6b00a764e549 | 86 | // wait for 25 to arrive and then read them as quickly as possible |
ashleymills | 66:6b00a764e549 | 87 | smCount = 0, oldSMCount = 0; |
ashleymills | 66:6b00a764e549 | 88 | t.start(); |
ashleymills | 72:0e8e769fcf76 | 89 | LOG("waiting for messages"); |
ashleymills | 72:0e8e769fcf76 | 90 | |
ashleymills | 66:6b00a764e549 | 91 | // wait a maximum of 10 minutes |
ashleymills | 66:6b00a764e549 | 92 | while(smCount<mailBoxSize&&t.read_ms()<600000) { |
ashleymills | 66:6b00a764e549 | 93 | if(_modem->getSMCount(&smCount)!=0) { |
ashleymills | 66:6b00a764e549 | 94 | LOG("Failure getting SM count"); |
ashleymills | 66:6b00a764e549 | 95 | return false; |
ashleymills | 66:6b00a764e549 | 96 | } else { |
ashleymills | 66:6b00a764e549 | 97 | if(smCount!=oldSMCount) { |
ashleymills | 66:6b00a764e549 | 98 | LOG("smCount: %d",smCount); |
ashleymills | 66:6b00a764e549 | 99 | oldSMCount = smCount; |
ashleymills | 66:6b00a764e549 | 100 | } |
nherriot | 5:b68400bd0738 | 101 | } |
ashleymills | 66:6b00a764e549 | 102 | Thread::wait(500); |
ashleymills | 66:6b00a764e549 | 103 | } |
ashleymills | 66:6b00a764e549 | 104 | if(smCount<mailBoxSize) { |
ashleymills | 66:6b00a764e549 | 105 | LOG("Timeout waiting for SMSs, got to %d",smCount); |
ashleymills | 66:6b00a764e549 | 106 | return false; |
ashleymills | 66:6b00a764e549 | 107 | } |
ashleymills | 66:6b00a764e549 | 108 | |
ashleymills | 72:0e8e769fcf76 | 109 | |
ashleymills | 66:6b00a764e549 | 110 | LOG("dumping SMS"); |
ashleymills | 66:6b00a764e549 | 111 | for(int i=0; i<mailBoxSize; i++) { |
ashleymills | 66:6b00a764e549 | 112 | if(_modem->getSM(_senderNumber,_smsIn,_smsLen)!=0) { |
ashleymills | 66:6b00a764e549 | 113 | LOG("Error reading SMS %d",i); |
ashleymills | 66:6b00a764e549 | 114 | return false; |
ashleymills | 66:6b00a764e549 | 115 | } else { |
ashleymills | 66:6b00a764e549 | 116 | LOG("Got SMS: \"%s\" (%s)",_smsIn,_senderNumber); |
ashleymills | 66:6b00a764e549 | 117 | } |
ashleymills | 66:6b00a764e549 | 118 | } |
ashleymills | 66:6b00a764e549 | 119 | |
ashleymills | 66:6b00a764e549 | 120 | // wait for next 25 to arrive and then read them as quickly as possible |
ashleymills | 66:6b00a764e549 | 121 | smCount = 0, oldSMCount = 0; |
ashleymills | 66:6b00a764e549 | 122 | t.start(); |
ashleymills | 66:6b00a764e549 | 123 | // wait a maximum of 10 minutes |
ashleymills | 72:0e8e769fcf76 | 124 | LOG("Waiting for messages"); |
ashleymills | 72:0e8e769fcf76 | 125 | |
ashleymills | 66:6b00a764e549 | 126 | while(smCount<mailBoxSize&&t.read_ms()<600000) { |
ashleymills | 66:6b00a764e549 | 127 | if(_modem->getSMCount(&smCount)!=0) { |
ashleymills | 66:6b00a764e549 | 128 | LOG("Failure getting SM count"); |
ashleymills | 66:6b00a764e549 | 129 | return false; |
ashleymills | 66:6b00a764e549 | 130 | } else { |
ashleymills | 66:6b00a764e549 | 131 | if(smCount!=oldSMCount) { |
ashleymills | 66:6b00a764e549 | 132 | LOG("smCount: %d",smCount); |
ashleymills | 66:6b00a764e549 | 133 | oldSMCount = smCount; |
ashleymills | 66:6b00a764e549 | 134 | } |
ashleymills | 66:6b00a764e549 | 135 | } |
ashleymills | 66:6b00a764e549 | 136 | Thread::wait(500); |
ashleymills | 66:6b00a764e549 | 137 | } |
ashleymills | 66:6b00a764e549 | 138 | if(smCount!=mailBoxSize) { |
ashleymills | 66:6b00a764e549 | 139 | LOG("Timeout waiting for SMSs, got to %d",smCount); |
ashleymills | 66:6b00a764e549 | 140 | return false; |
ashleymills | 66:6b00a764e549 | 141 | } |
ashleymills | 66:6b00a764e549 | 142 | |
ashleymills | 66:6b00a764e549 | 143 | LOG("dumping SMS"); |
ashleymills | 66:6b00a764e549 | 144 | for(int i=0; i<mailBoxSize; i++) { |
ashleymills | 66:6b00a764e549 | 145 | if(_modem->getSM(_senderNumber,_smsIn,_smsLen)!=0) { |
ashleymills | 66:6b00a764e549 | 146 | LOG("Error reading SMS %d",i); |
ashleymills | 66:6b00a764e549 | 147 | return false; |
ashleymills | 66:6b00a764e549 | 148 | } else { |
ashleymills | 66:6b00a764e549 | 149 | LOG("Got SMS: \"%s\" (%s)",_smsIn,_senderNumber); |
ashleymills | 66:6b00a764e549 | 150 | } |
ashleymills | 66:6b00a764e549 | 151 | } |
ashleymills | 66:6b00a764e549 | 152 | |
ashleymills | 66:6b00a764e549 | 153 | return true; |
nherriot | 5:b68400bd0738 | 154 | } |
ashleymills | 66:6b00a764e549 | 155 | |
ashleymills | 66:6b00a764e549 | 156 | void allocStorage() { |
ashleymills | 66:6b00a764e549 | 157 | _ownNumber = (char*)malloc(_numberLen*sizeof(char)); |
ashleymills | 66:6b00a764e549 | 158 | _senderNumber = (char*)malloc(_numberLen*sizeof(char)); |
ashleymills | 66:6b00a764e549 | 159 | _smsOut = (char*)malloc(_smsLen*sizeof(char)); |
ashleymills | 66:6b00a764e549 | 160 | _smsIn = (char*)malloc(_smsLen*sizeof(char)); |
ashleymills | 66:6b00a764e549 | 161 | _smsJunkBuffer= (char*)malloc(_smsMaxSize*sizeof(char)); |
ashleymills | 66:6b00a764e549 | 162 | } |
ashleymills | 66:6b00a764e549 | 163 | |
ashleymills | 66:6b00a764e549 | 164 | void freeStorage() { |
ashleymills | 66:6b00a764e549 | 165 | free(_ownNumber); |
ashleymills | 66:6b00a764e549 | 166 | free(_senderNumber); |
ashleymills | 66:6b00a764e549 | 167 | free(_smsOut); |
ashleymills | 66:6b00a764e549 | 168 | free(_smsIn); |
ashleymills | 66:6b00a764e549 | 169 | free(_smsJunkBuffer); |
ashleymills | 66:6b00a764e549 | 170 | } |
ashleymills | 66:6b00a764e549 | 171 | |
ashleymills | 66:6b00a764e549 | 172 | char* _ownNumber; |
ashleymills | 66:6b00a764e549 | 173 | char* _senderNumber; |
ashleymills | 66:6b00a764e549 | 174 | char* _smsOut; |
ashleymills | 66:6b00a764e549 | 175 | char* _smsIn; |
ashleymills | 66:6b00a764e549 | 176 | char* _smsJunkBuffer; |
ashleymills | 66:6b00a764e549 | 177 | int _smsLen; |
ashleymills | 66:6b00a764e549 | 178 | int _smsMaxSize; |
ashleymills | 66:6b00a764e549 | 179 | int _numberLen; |
ashleymills | 66:6b00a764e549 | 180 | }; |