Vodafone Test Suite
Dependencies: mbed-rtos mbed HTTPClient VodafoneUSBModem
Tests/Test51.h
- Committer:
- donatien
- Date:
- 2012-10-24
- Revision:
- 62:e4a094aabbbc
- Parent:
- 61:4dd870ad7749
- Child:
- 64:ef77cb252ed6
File content as of revision 62:e4a094aabbbc:
#pragma once #include "VodafoneTestCase.h" extern const char* gTest51Description; class Test51 : public VodafoneTestCase { public: Test51(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 = 10, mailBoxSize = 5; size_t smCount, oldSMCount; Timer t; LOG(gTest51Description); // 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("Faiure 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); } if(_modem->sendSM(_ownNumber,_smsOut)!=0) { LOG("Error sending short message"); return false; } else { LOG("Sent %d/%d: \"%s\"",i,smsToSend,_smsOut); } } Thread::wait(5000); // wait for 25 to arrive and then read them as quickly as possible smCount = 0, oldSMCount = 0; t.start(); // wait a maximum of 5 minutes //while(smCount<mailBoxSize&&t.read_ms()<300000) { while(smCount<mailBoxSize&&t.read_ms()<30000) { //Reduce timeout to 30s for now 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"); while(smCount--) { if(_modem->getSM(_senderNumber,_smsIn,_smsLen)!=0) { LOG("Error reading SMS %d",smCount); 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 5 minutes while(smCount<mailBoxSize&&t.read_ms()<300000) { 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"); while(smCount--) { if(_modem->getSM(_senderNumber,_smsIn,_smsLen)!=0) { LOG("Error reading SMS %d",smCount); 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; };