Vodafone Test Suite
Dependencies: mbed-rtos mbed HTTPClient VodafoneUSBModem
Tests/Test12.h
- Committer:
- ashleymills
- Date:
- 2014-01-29
- Revision:
- 74:e52ac9624f7f
- Parent:
- 72:0e8e769fcf76
File content as of revision 74:e52ac9624f7f:
#pragma once #include "VodafoneTestCase.h" // Test 12: x2 -> Send 25 SMS, wait for recv, read them quickly. extern const char* gTest12Description; class Test12 : public VodafoneTestCase { public: Test12(VodafoneUSBModem *m) : VodafoneTestCase(m) { _smsLen = 32; _smsMaxSize = 160; // max size of SMS using _numberLen = 16; } private: virtual void setupTest() { allocStorage(); } virtual void endTest() { freeStorage(); } virtual bool executeTest() { // locals int smsToSend = 50, mailBoxSize = 25; int tries = 0, sent = 0; size_t smCount, oldSMCount; Timer t; LOG(gTest12Description); // Clear out the SMS mail box before we run this test. // loop 3 times with a 1/2 second break in between each LOG("... Clearing out SMS mail box first"); for(int j=0; j<3; j++) { if(_modem->getSMCount(&smCount)!=0) { LOG("Failure getting SM count"); return false; } for(int i=0; i<smCount; i++) { if(_modem->getSM(_senderNumber,_smsJunkBuffer,_smsMaxSize)!=0) { LOG("Strange! The SMS count is bigger than zero but I can't fetch the SMS?"); return false; } LOG("Deleting SMS: \"%s\"",_smsJunkBuffer); } Thread::wait(500); } // get own number LOG("Getting MSISDN"); _modem->sendUSSD("*#100#",_ownNumber,_numberLen); LOG("Got MSISDN %s",_ownNumber); // send 50 SMS to self for(int i=0; i<smsToSend; i++) { if(i<mailBoxSize) { sprintf(_smsOut,"A SMS %d",i); } else { sprintf(_smsOut,"B SMS %d",i); } tries = 3; sent = 0; while(tries--) { if(_modem->sendSM(_ownNumber,_smsOut)==0) { sent = 1; break; } LOG("Error sending SM, trying again."); } if(!sent) { LOG("Error sending short message"); return false; } else { LOG("Sent %d/%d: \"%s\"",i,smsToSend,_smsOut); } Thread::wait(50); } Thread::wait(5000); // wait for 25 to arrive and then read them as quickly as possible smCount = 0, oldSMCount = 0; t.start(); LOG("waiting for messages"); // wait a maximum of 10 minutes while(smCount<mailBoxSize&&t.read_ms()<600000) { if(_modem->getSMCount(&smCount)!=0) { LOG("Failure getting SM count"); return false; } else { if(smCount!=oldSMCount) { LOG("smCount: %d",smCount); oldSMCount = smCount; } } Thread::wait(500); } if(smCount<mailBoxSize) { LOG("Timeout waiting for SMSs, got to %d",smCount); return false; } LOG("dumping SMS"); for(int i=0; i<mailBoxSize; i++) { if(_modem->getSM(_senderNumber,_smsIn,_smsLen)!=0) { LOG("Error reading SMS %d",i); return false; } else { LOG("Got SMS: \"%s\" (%s)",_smsIn,_senderNumber); } } // wait for next 25 to arrive and then read them as quickly as possible smCount = 0, oldSMCount = 0; t.start(); // wait a maximum of 10 minutes LOG("Waiting for messages"); while(smCount<mailBoxSize&&t.read_ms()<600000) { if(_modem->getSMCount(&smCount)!=0) { LOG("Failure getting SM count"); return false; } else { if(smCount!=oldSMCount) { LOG("smCount: %d",smCount); oldSMCount = smCount; } } Thread::wait(500); } if(smCount!=mailBoxSize) { LOG("Timeout waiting for SMSs, got to %d",smCount); return false; } LOG("dumping SMS"); for(int i=0; i<mailBoxSize; i++) { if(_modem->getSM(_senderNumber,_smsIn,_smsLen)!=0) { LOG("Error reading SMS %d",i); return false; } else { LOG("Got SMS: \"%s\" (%s)",_smsIn,_senderNumber); } } return true; } void allocStorage() { _ownNumber = (char*)malloc(_numberLen*sizeof(char)); _senderNumber = (char*)malloc(_numberLen*sizeof(char)); _smsOut = (char*)malloc(_smsLen*sizeof(char)); _smsIn = (char*)malloc(_smsLen*sizeof(char)); _smsJunkBuffer= (char*)malloc(_smsMaxSize*sizeof(char)); } void freeStorage() { free(_ownNumber); free(_senderNumber); free(_smsOut); free(_smsIn); free(_smsJunkBuffer); } char* _ownNumber; char* _senderNumber; char* _smsOut; char* _smsIn; char* _smsJunkBuffer; int _smsLen; int _smsMaxSize; int _numberLen; };