Vodafone Test Suite
Dependencies: mbed-rtos mbed HTTPClient VodafoneUSBModem
Tests/Test11.h@72:0e8e769fcf76, 2013-09-20 (annotated)
- Committer:
- ashleymills
- Date:
- Fri Sep 20 12:36:03 2013 +0000
- Revision:
- 72:0e8e769fcf76
- Parent:
- 69:4fc3b0ad12c7
Updated VodafoneUSBModem to latest version.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ashleymills | 66:6b00a764e549 | 1 | #pragma once |
ashleymills | 66:6b00a764e549 | 2 | #include "VodafoneTestCase.h" |
ashleymills | 66:6b00a764e549 | 3 | |
ashleymills | 66:6b00a764e549 | 4 | extern const char* gTest11Description; |
ashleymills | 66:6b00a764e549 | 5 | |
ashleymills | 66:6b00a764e549 | 6 | class Test11 : public VodafoneTestCase { |
ashleymills | 66:6b00a764e549 | 7 | public: |
ashleymills | 66:6b00a764e549 | 8 | Test11(VodafoneUSBModem *m) : VodafoneTestCase(m) { |
ashleymills | 66:6b00a764e549 | 9 | _smsLen = 32; |
ashleymills | 66:6b00a764e549 | 10 | _smsMaxSize = 160; // max size of SMS using |
ashleymills | 66:6b00a764e549 | 11 | _numberLen = 16; |
ashleymills | 66:6b00a764e549 | 12 | } |
ashleymills | 66:6b00a764e549 | 13 | |
ashleymills | 66:6b00a764e549 | 14 | private: |
ashleymills | 66:6b00a764e549 | 15 | |
ashleymills | 66:6b00a764e549 | 16 | virtual void setupTest() { |
ashleymills | 66:6b00a764e549 | 17 | allocStorage(); |
ashleymills | 66:6b00a764e549 | 18 | } |
ashleymills | 66:6b00a764e549 | 19 | |
ashleymills | 66:6b00a764e549 | 20 | virtual void endTest() { |
ashleymills | 66:6b00a764e549 | 21 | freeStorage(); |
ashleymills | 66:6b00a764e549 | 22 | } |
ashleymills | 66:6b00a764e549 | 23 | |
ashleymills | 66:6b00a764e549 | 24 | virtual bool executeTest() { |
ashleymills | 66:6b00a764e549 | 25 | LOG(gTest11Description); |
ashleymills | 66:6b00a764e549 | 26 | int numIterations = 10; |
ashleymills | 66:6b00a764e549 | 27 | size_t smCount; |
ashleymills | 66:6b00a764e549 | 28 | |
ashleymills | 66:6b00a764e549 | 29 | // Clear out the SMS mail box before we run this test. |
ashleymills | 66:6b00a764e549 | 30 | // loop 3 times with a 1/2 second break in between each |
ashleymills | 66:6b00a764e549 | 31 | LOG("... Clearing out SMS mail box first"); |
ashleymills | 69:4fc3b0ad12c7 | 32 | bool smsCleared = false; |
ashleymills | 66:6b00a764e549 | 33 | for(int j=0; j<3; j++) { |
ashleymills | 66:6b00a764e549 | 34 | if(_modem->getSMCount(&smCount)!=0) { |
ashleymills | 68:2f3ead00ab0a | 35 | LOG("Failure getting SM count"); |
ashleymills | 66:6b00a764e549 | 36 | return false; |
ashleymills | 66:6b00a764e549 | 37 | } |
ashleymills | 66:6b00a764e549 | 38 | |
ashleymills | 66:6b00a764e549 | 39 | for(int i=0; i<smCount; i++) { |
ashleymills | 66:6b00a764e549 | 40 | if(_modem->getSM(_senderNumber,_smsJunkBuffer,_smsMaxSize)!=0) { |
ashleymills | 66:6b00a764e549 | 41 | LOG("Strange! The SMS count is bigger than zero but I can't fetch the SMS?"); |
ashleymills | 66:6b00a764e549 | 42 | return false; |
ashleymills | 66:6b00a764e549 | 43 | } |
ashleymills | 66:6b00a764e549 | 44 | LOG("Got SMS: %s",_smsJunkBuffer); |
ashleymills | 66:6b00a764e549 | 45 | LOG("Clearing that out before running the test."); |
ashleymills | 69:4fc3b0ad12c7 | 46 | smsCleared = true; |
ashleymills | 66:6b00a764e549 | 47 | } |
ashleymills | 66:6b00a764e549 | 48 | Thread::wait(500); |
ashleymills | 66:6b00a764e549 | 49 | } |
ashleymills | 69:4fc3b0ad12c7 | 50 | if(!smsCleared) { |
ashleymills | 69:4fc3b0ad12c7 | 51 | LOG("Nothing found to clear out."); |
ashleymills | 69:4fc3b0ad12c7 | 52 | } |
ashleymills | 66:6b00a764e549 | 53 | |
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 | for(int i=0; i<numIterations; i++) { |
ashleymills | 66:6b00a764e549 | 58 | createRandomString(_smsOut,_smsLen); |
ashleymills | 69:4fc3b0ad12c7 | 59 | |
ashleymills | 69:4fc3b0ad12c7 | 60 | LOG("Artificially waiting for 2 seconds"); |
ashleymills | 69:4fc3b0ad12c7 | 61 | Thread::wait(2000); |
ashleymills | 69:4fc3b0ad12c7 | 62 | LOG("Attempting to send SMS %d of %d",i+1,numIterations); |
ashleymills | 72:0e8e769fcf76 | 63 | int tries = 3; |
ashleymills | 72:0e8e769fcf76 | 64 | int sent = 0; |
ashleymills | 72:0e8e769fcf76 | 65 | while(tries--) { |
ashleymills | 72:0e8e769fcf76 | 66 | if(_modem->sendSM(_ownNumber,_smsOut)==0) { |
ashleymills | 72:0e8e769fcf76 | 67 | sent = 1; |
ashleymills | 72:0e8e769fcf76 | 68 | break; |
ashleymills | 72:0e8e769fcf76 | 69 | } |
ashleymills | 66:6b00a764e549 | 70 | LOG("Error sending short message"); |
ashleymills | 66:6b00a764e549 | 71 | } |
ashleymills | 69:4fc3b0ad12c7 | 72 | |
ashleymills | 72:0e8e769fcf76 | 73 | if(!sent) { |
ashleymills | 72:0e8e769fcf76 | 74 | LOG("Failure to send SMS after 3 tries, aborting."); |
ashleymills | 72:0e8e769fcf76 | 75 | return false; |
ashleymills | 72:0e8e769fcf76 | 76 | } else { |
ashleymills | 72:0e8e769fcf76 | 77 | LOG("Sent: %s",_smsOut); |
ashleymills | 72:0e8e769fcf76 | 78 | } |
ashleymills | 72:0e8e769fcf76 | 79 | |
ashleymills | 69:4fc3b0ad12c7 | 80 | |
ashleymills | 66:6b00a764e549 | 81 | bool gotMessage = false; |
ashleymills | 66:6b00a764e549 | 82 | Timer t; |
ashleymills | 66:6b00a764e549 | 83 | t.start(); |
ashleymills | 72:0e8e769fcf76 | 84 | int msToWait = 60000; |
ashleymills | 69:4fc3b0ad12c7 | 85 | LOG("Waiting %d seconds for response",msToWait/1000); |
ashleymills | 69:4fc3b0ad12c7 | 86 | while(!gotMessage && t.read_ms()<msToWait) { |
ashleymills | 66:6b00a764e549 | 87 | if(_modem->getSMCount(&smCount)!=0) { |
ashleymills | 69:4fc3b0ad12c7 | 88 | LOG("Failure getting SM count"); |
ashleymills | 66:6b00a764e549 | 89 | return false; |
ashleymills | 66:6b00a764e549 | 90 | } |
ashleymills | 66:6b00a764e549 | 91 | |
ashleymills | 66:6b00a764e549 | 92 | if(smCount>0) { |
ashleymills | 66:6b00a764e549 | 93 | if(_modem->getSM(_senderNumber,_smsIn,_smsLen)!=0) { |
ashleymills | 66:6b00a764e549 | 94 | LOG("Failure getting SM"); |
ashleymills | 66:6b00a764e549 | 95 | return false; |
ashleymills | 66:6b00a764e549 | 96 | } |
ashleymills | 69:4fc3b0ad12c7 | 97 | LOG("Got SMS: %s after %f seconds.",_smsIn,t.read_ms()/1000.0); |
ashleymills | 66:6b00a764e549 | 98 | if(strcmp(_smsIn,_smsOut)!=0) { |
ashleymills | 66:6b00a764e549 | 99 | LOG("FAIL: strings did not match"); |
ashleymills | 66:6b00a764e549 | 100 | return false; |
ashleymills | 66:6b00a764e549 | 101 | } |
ashleymills | 66:6b00a764e549 | 102 | gotMessage = true; |
ashleymills | 66:6b00a764e549 | 103 | } |
ashleymills | 66:6b00a764e549 | 104 | Thread::wait(50); |
ashleymills | 66:6b00a764e549 | 105 | } |
ashleymills | 66:6b00a764e549 | 106 | if(!gotMessage) { |
ashleymills | 66:6b00a764e549 | 107 | LOG("FAIL: timeout on waiting for SMS"); |
ashleymills | 66:6b00a764e549 | 108 | return false; |
ashleymills | 66:6b00a764e549 | 109 | } |
ashleymills | 66:6b00a764e549 | 110 | } |
ashleymills | 66:6b00a764e549 | 111 | |
ashleymills | 66:6b00a764e549 | 112 | return true; |
ashleymills | 66:6b00a764e549 | 113 | } |
ashleymills | 66:6b00a764e549 | 114 | |
ashleymills | 66:6b00a764e549 | 115 | void createRandomString(char *target, int len) { |
ashleymills | 66:6b00a764e549 | 116 | for(int i=0; i<len; i++) { |
ashleymills | 66:6b00a764e549 | 117 | target[i] = 65+rand()%16; |
ashleymills | 66:6b00a764e549 | 118 | } |
ashleymills | 66:6b00a764e549 | 119 | target[len-1] = 0x00; |
ashleymills | 66:6b00a764e549 | 120 | } |
ashleymills | 66:6b00a764e549 | 121 | |
ashleymills | 66:6b00a764e549 | 122 | void allocStorage() { |
ashleymills | 66:6b00a764e549 | 123 | _ownNumber = (char*)malloc(_numberLen*sizeof(char)); |
ashleymills | 66:6b00a764e549 | 124 | _senderNumber = (char*)malloc(_numberLen*sizeof(char)); |
ashleymills | 66:6b00a764e549 | 125 | _smsOut = (char*)malloc(_smsLen*sizeof(char)); |
ashleymills | 66:6b00a764e549 | 126 | _smsIn = (char*)malloc(_smsLen*sizeof(char)); |
ashleymills | 66:6b00a764e549 | 127 | _smsJunkBuffer= (char*)malloc(_smsMaxSize*sizeof(char)); |
ashleymills | 66:6b00a764e549 | 128 | } |
ashleymills | 66:6b00a764e549 | 129 | |
ashleymills | 66:6b00a764e549 | 130 | void freeStorage() { |
ashleymills | 66:6b00a764e549 | 131 | free(_ownNumber); |
ashleymills | 66:6b00a764e549 | 132 | free(_senderNumber); |
ashleymills | 66:6b00a764e549 | 133 | free(_smsOut); |
ashleymills | 66:6b00a764e549 | 134 | free(_smsIn); |
ashleymills | 66:6b00a764e549 | 135 | free(_smsJunkBuffer); |
ashleymills | 66:6b00a764e549 | 136 | } |
ashleymills | 66:6b00a764e549 | 137 | |
ashleymills | 66:6b00a764e549 | 138 | char* _ownNumber; |
ashleymills | 66:6b00a764e549 | 139 | char* _senderNumber; |
ashleymills | 66:6b00a764e549 | 140 | char* _smsOut; |
ashleymills | 66:6b00a764e549 | 141 | char* _smsIn; |
ashleymills | 66:6b00a764e549 | 142 | char* _smsJunkBuffer; |
ashleymills | 66:6b00a764e549 | 143 | int _smsLen; |
ashleymills | 66:6b00a764e549 | 144 | int _smsMaxSize; |
ashleymills | 66:6b00a764e549 | 145 | int _numberLen; |
ashleymills | 66:6b00a764e549 | 146 | }; |