Vodafone Test Suite

Dependencies:   mbed-rtos mbed HTTPClient VodafoneUSBModem

Committer:
ashleymills
Date:
Fri Aug 24 10:42:44 2012 +0000
Revision:
9:3ff68422f4d7
Parent:
4:1f8e079924ba
Child:
10:65ee3973594e
Merge

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ashleymills 3:28336c2e94e4 1 #pragma once
ashleymills 4:1f8e079924ba 2 #include "VodafoneTestCase.h"
ashleymills 3:28336c2e94e4 3 class Test50 : public VodafoneTestCase {
ashleymills 3:28336c2e94e4 4 public:
ashleymills 3:28336c2e94e4 5 Test50(VodafoneUSBModem *m) : VodafoneTestCase(m) {
ashleymills 4:1f8e079924ba 6 _smsLen = 32;
ashleymills 4:1f8e079924ba 7 _numberLen = 16;
ashleymills 4:1f8e079924ba 8 }
ashleymills 4:1f8e079924ba 9
ashleymills 4:1f8e079924ba 10 virtual void setupTest() {
ashleymills 4:1f8e079924ba 11 allocStorage();
ashleymills 4:1f8e079924ba 12 }
ashleymills 4:1f8e079924ba 13
ashleymills 4:1f8e079924ba 14 virtual bool endTest(bool state) {
ashleymills 4:1f8e079924ba 15 freeStorage();
ashleymills 4:1f8e079924ba 16 return state;
ashleymills 3:28336c2e94e4 17 }
ashleymills 3:28336c2e94e4 18
ashleymills 3:28336c2e94e4 19 virtual bool runTest() {
ashleymills 9:3ff68422f4d7 20 int numIterations = 10;
ashleymills 4:1f8e079924ba 21 size_t smCount;
ashleymills 4:1f8e079924ba 22 LOG("Getting MSISDN");
ashleymills 4:1f8e079924ba 23 _modem->sendUSSD("*#100#",_ownNumber,_numberLen);
ashleymills 4:1f8e079924ba 24 LOG("Got MSISDN %s",_ownNumber);
ashleymills 9:3ff68422f4d7 25 for(int i=0; i<numIterations; i++) {
ashleymills 4:1f8e079924ba 26 createRandomString(_smsOut,_smsLen);
ashleymills 4:1f8e079924ba 27 LOG("Created: %s",_smsOut);
ashleymills 9:3ff68422f4d7 28 if(_modem->sendSM(_ownNumber,_smsOut)!=0) {
ashleymills 9:3ff68422f4d7 29 LOG("Error sending short message");
ashleymills 4:1f8e079924ba 30 }
ashleymills 4:1f8e079924ba 31 bool gotMessage = false;
ashleymills 4:1f8e079924ba 32 while(!gotMessage) {
ashleymills 4:1f8e079924ba 33 if(_modem->getSMCount(&smCount)!=0) {
ashleymills 4:1f8e079924ba 34 LOG("Faiure getting SM count");
ashleymills 4:1f8e079924ba 35 return false;
ashleymills 4:1f8e079924ba 36 }
ashleymills 4:1f8e079924ba 37
ashleymills 4:1f8e079924ba 38 if(smCount>0) {
ashleymills 4:1f8e079924ba 39 if(_modem->getSM(_senderNumber,_smsIn,_smsLen)!=0) {
ashleymills 4:1f8e079924ba 40 LOG("Failure getting SM");
ashleymills 4:1f8e079924ba 41 return false;
ashleymills 4:1f8e079924ba 42 }
ashleymills 4:1f8e079924ba 43 LOG("Got SMS: %s",_smsIn);
ashleymills 9:3ff68422f4d7 44 if(strcmp(_smsIn,_smsOut)!=0) {
ashleymills 9:3ff68422f4d7 45 LOG("FAIL: strings did not match");
ashleymills 9:3ff68422f4d7 46 return false;
ashleymills 9:3ff68422f4d7 47 }
ashleymills 4:1f8e079924ba 48 gotMessage = true;
ashleymills 4:1f8e079924ba 49 }
ashleymills 4:1f8e079924ba 50 Thread::wait(50);
ashleymills 4:1f8e079924ba 51 }
ashleymills 4:1f8e079924ba 52 }
ashleymills 3:28336c2e94e4 53
ashleymills 4:1f8e079924ba 54 return true;
ashleymills 3:28336c2e94e4 55 }
ashleymills 3:28336c2e94e4 56
ashleymills 4:1f8e079924ba 57 private:
ashleymills 4:1f8e079924ba 58 void createRandomString(char *target, int len) {
ashleymills 4:1f8e079924ba 59 for(int i=0; i<len; i++) {
ashleymills 9:3ff68422f4d7 60 target[i] = 65+rand()%16;
ashleymills 4:1f8e079924ba 61 }
ashleymills 4:1f8e079924ba 62 target[len-1] = 0x00;
ashleymills 4:1f8e079924ba 63 }
ashleymills 4:1f8e079924ba 64
ashleymills 4:1f8e079924ba 65 void allocStorage() {
ashleymills 4:1f8e079924ba 66 _ownNumber = (char*)malloc(_numberLen*sizeof(char));
ashleymills 4:1f8e079924ba 67 _senderNumber = (char*)malloc(_numberLen*sizeof(char));
ashleymills 4:1f8e079924ba 68 _smsOut = (char*)malloc(_smsLen*sizeof(char));
ashleymills 4:1f8e079924ba 69 _smsIn = (char*)malloc(_smsLen*sizeof(char));
ashleymills 4:1f8e079924ba 70 }
ashleymills 3:28336c2e94e4 71
ashleymills 4:1f8e079924ba 72 void freeStorage() {
ashleymills 4:1f8e079924ba 73 free(_ownNumber);
ashleymills 4:1f8e079924ba 74 free(_senderNumber);
ashleymills 4:1f8e079924ba 75 free(_smsOut);
ashleymills 4:1f8e079924ba 76 free(_smsIn);
ashleymills 4:1f8e079924ba 77 }
ashleymills 4:1f8e079924ba 78
ashleymills 4:1f8e079924ba 79 char* _ownNumber;
ashleymills 4:1f8e079924ba 80 char* _senderNumber;
ashleymills 4:1f8e079924ba 81 char* _smsOut;
ashleymills 4:1f8e079924ba 82 char* _smsIn;
ashleymills 4:1f8e079924ba 83 int _smsLen;
ashleymills 4:1f8e079924ba 84 int _numberLen;
ashleymills 3:28336c2e94e4 85 };