Vodafone Test Suite

Dependencies:   mbed-rtos mbed HTTPClient VodafoneUSBModem

Files at this revision

API Documentation at this revision

Comitter:
ashleymills
Date:
Wed Aug 22 10:17:54 2012 +0000
Parent:
0:6d8a9f4b2cc6
Child:
2:ea883307d02f
Commit message:
Added basic test framework

Changed in this revision

ExampleTest.h Show annotated file Show diff for this revision Revisions of this file
VodafoneTestCase.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ExampleTest.h	Wed Aug 22 10:17:54 2012 +0000
@@ -0,0 +1,19 @@
+#pragma once
+#include "VodafoneTestCase.h"
+class ExampleTest : public VodafoneTestCase {
+   public: 
+      ExampleTest(VodafoneUSBModem *m) : VodafoneTestCase(m) {
+      }
+   
+      bool runTest() {
+         DBG("Running USSD test 1212");
+         char ussdResponse[64];
+         if(_modem->sendUSSD("*#100#",ussdResponse,64)!=0) {
+            DBG("Error sending USSD");
+            return false;
+         }
+         
+         DBG("Received USSD response: \"%s\"",ussdResponse);
+         return true;
+      }
+};
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/VodafoneTestCase.h	Wed Aug 22 10:17:54 2012 +0000
@@ -0,0 +1,14 @@
+#pragma once
+#include "VodafoneUSBModem.h"
+class VodafoneTestCase {
+   public:
+      VodafoneTestCase(VodafoneUSBModem *m) : _modem(m) {
+         
+      }
+      
+      virtual bool runTest() {}
+      
+   protected:
+      VodafoneUSBModem *_modem;
+      
+};
\ No newline at end of file
--- a/main.cpp	Wed Aug 22 08:48:49 2012 +0000
+++ b/main.cpp	Wed Aug 22 10:17:54 2012 +0000
@@ -1,152 +1,47 @@
-#define __DEBUG__ 4 //Maximum verbosity
-#ifndef __MODULE__
-#define __MODULE__ "net_3g_basic_http_test.cpp"
-#endif
-
-#include "mbed.h"
-#include "socket/bsd_socket.h"
-
-#include "rtos.h"
-
-#include "VodafoneUSBModem.h"
-
-DigitalOut led1(LED1);
-DigitalOut led2(LED2);
-DigitalOut led3(LED3);
-DigitalOut led4(LED4);
-
-extern "C" void HardFault_Handler()
-{
-  error("Hard Fault!\n");
-}
-
-void test(void const*) {
-  VodafoneUSBModem modem;
-  // socket stuff
-  int sockfd;
-  uint16_t port = 3232;
-  struct sockaddr_in serverAddress;
-  struct hostent *server;
-  char urlBuffer[128];
-  int urlBufferLength = 128;
-
-  // declare space for phone number and message storage
-  char numBuffer[20], msgBuffer[512];
-  size_t numSMS; // variable to track number of received messages
-
-  DBG("Hello!");
-  
-  modem.sendUSSD("*#100#", msgBuffer, 512);
-  
-  DBG("ussd: %s",msgBuffer);
-
-
-  int ret = modem.connect("internet","web","web");
- 
-  if (ret == OK) {
-    int count = 30;
-    while(1) {
-        int rssi;
-        LinkMonitor::REGISTRATION_STATE regState;
-        LinkMonitor::BEARER bearer;
-        
-        modem.getLinkState(&rssi, &regState, &bearer);
-        DBG("RSSI: %d dBm; Reg state: %d; Bearer: %d", rssi, regState, bearer);
-
-        DBG("Checking SM count");
-
-        // retrieve the short message count into numSMS
-        if(modem.getSMCount(&numSMS)==OK) {
-            DBG("getSMCount success");
-            DBG("numSMS: %d",numSMS);
-            // check if any short messages have been received
-            if(numSMS>0) {
-                DBG("SM count > 0");
-                // get the oldest short message in the queue
-                if(modem.getSM(numBuffer,msgBuffer,256)==OK) {
-                    DBG("message received");
-                    DBG("num: %s",numBuffer);
-                    DBG("msg: %s",msgBuffer);
-                    
-                    // connect to socket and push message
-                    
-                    // create the socket
-                    if((sockfd=::socket(AF_INET,SOCK_STREAM,0))<0) { DBG("Error opening socket\r\n"); } else { DBG("Socket open\r\n"); }
-                         
-                    // create the socket address
-                    std::memset(&serverAddress, 0, sizeof(struct sockaddr_in));
-                    if((server=::gethostbyname("m2mthings.com"))==NULL)  {
-                         DBG("Error resolving address, setting manually.");
-                         serverAddress.sin_addr.s_addr = inet_addr("109.74.199.96");
-                    } else {
-                         DBG("Address resolved OK");
-                         memcpy((char*)&serverAddress.sin_addr.s_addr, (char*)server->h_addr_list[0], server->h_length);
-                    }
-                    // set server address family
-                    serverAddress.sin_family = AF_INET;
-                    // set server port
-                    serverAddress.sin_port = htons(port);
-         
-                    // do socket connect
-                    DBG("Connecting socket to %s:%d", inet_ntoa(serverAddress.sin_addr), ntohs(serverAddress.sin_port));
-                    if((ret=::connect(sockfd, (const struct sockaddr *)&serverAddress, sizeof(serverAddress)))<0) {
-                         ::close(sockfd);
-                         DBG("Could not connect");
-                    } else {
-                         DBG("Connection OK");
-                    }
-                    
-                    DBG("Sending password");
-                    ::write(sockfd,"hi3h892!",8);
-                    
-                    ret = ::recv(sockfd,urlBuffer,urlBufferLength,0);
-                    if (ret<0) {
-                        DBG("Error receiving ACK.");
-                    } else {
-                        DBG("Received(%d): %s",urlBufferLength,urlBuffer);
-                        modem.sendSM(numBuffer,urlBuffer);
-                    }
-                    
-                    ::close(sockfd);
-    
-
-                }
-            }
-        }
-        // wait 500ms
-        Thread::wait(1000);
-    }
-    
-  }
-  
-  modem.disconnect();
-  DBG("Disconnected");
-
-  while (1) {
-    Thread::wait(100);
-  }
-}
-
-void keepAlive(void const*)
-{
-  while (1)
-  {
-    led1 = !led1;
-    Thread::wait(500);
-    led1 = !led1;
-    Thread::wait(30000);
-  }
-}
-
-
-int main() {
-
-  DBG_INIT();
-  DBG_SET_SPEED(115200);
-  DBG_SET_NEWLINE("\r\n");
-
-  Thread testTask(test, NULL, osPriorityNormal, 1024 * 5);
-  keepAlive(NULL);
-
-  return 0;
+#define __DEBUG__ 4 //Maximum verbosity
+#ifndef __MODULE__
+#define __MODULE__ "net_3g_basic_http_test.cpp"
+#endif
+
+#include "mbed.h"
+#include "socket/bsd_socket.h"
+#include "rtos.h"
+#include "VodafoneUSBModem.h"
+#include "VodafoneTestCase.h"
+#include "ExampleTest.h"
+
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+DigitalOut led4(LED4);
+
+extern "C" void HardFault_Handler() { error("Hard Fault!\n"); }
+
+void test(void const*) {
+  VodafoneUSBModem modem;
+  
+  
+  ExampleTest t(&modem);
+  t.runTest();
+  
+  while(1) {
+     Thread::wait(1000);
+  }
+}
+
+int main() {
+
+  DBG_INIT();
+  DBG_SET_SPEED(115200);
+  DBG_SET_NEWLINE("\r\n");
+
+  Thread testTask(test, NULL, osPriorityNormal, 1024 * 5);
+  // this thread just waits and blinks leds periodically
+  while(1) {
+     led1 = !led1;
+     Thread::wait(500);
+     led1 = !led1;
+     Thread::wait(30000);
+  }
+  return 0;
 }
\ No newline at end of file