Vodafone Test Suite

Dependencies:   mbed-rtos mbed HTTPClient VodafoneUSBModem

Tests/Test50.h

Committer:
ashleymills
Date:
2012-08-23
Revision:
4:1f8e079924ba
Parent:
3:28336c2e94e4
Child:
8:6c30647f75d7
Child:
9:3ff68422f4d7

File content as of revision 4:1f8e079924ba:

#pragma once
#include "VodafoneTestCase.h"
class Test50 : public VodafoneTestCase {
   public:
      Test50(VodafoneUSBModem *m) : VodafoneTestCase(m) {
         _smsLen = 32;
         _numberLen = 16;
      }
      
      virtual void setupTest() {
         allocStorage();
      }
      
      virtual bool endTest(bool state) {
         freeStorage();
         return state;
      }
      
      virtual bool runTest() {
         size_t smCount;
         LOG("Getting MSISDN");
         _modem->sendUSSD("*#100#",_ownNumber,_numberLen);
         LOG("Got  MSISDN %s",_ownNumber);
         for(int i=0; i<5; i++) {
            LOG("Creating random string");
            createRandomString(_smsOut,_smsLen);
            LOG("Created: %s",_smsOut);
            if(_modem->sendSM(_ownNumber,_smsOut)==0) {
               LOG("Sent short message");
            }
            bool gotMessage = false;
            while(!gotMessage) {
               if(_modem->getSMCount(&smCount)!=0) {
                  LOG("Faiure getting SM count");
                  return false;
               } else {
                  //LOG("Got SMCount (%d)",smCount);
               }
               
               if(smCount>0) {
                  if(_modem->getSM(_senderNumber,_smsIn,_smsLen)!=0) {
                     LOG("Failure getting SM");
                     return false;
                  }
                  LOG("Got SMS: %s",_smsIn);
                  gotMessage = true;
               }
               Thread::wait(50);
            }
         }
         
         return true;
      }
      
   private:
      void createRandomString(char *target, int len) {
         for(int i=0; i<len; i++) {
            target[i] = 65+rand()%32;
         }
         target[len-1] = 0x00;
      }
      
      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));
      }
      
      void freeStorage() {
         free(_ownNumber);
         free(_senderNumber);
         free(_smsOut);
         free(_smsIn);
      }
      
      char* _ownNumber;
      char* _senderNumber;
      char* _smsOut;
      char* _smsIn;
      int _smsLen;
      int _numberLen;
};