A library for talking to Multi-Tech's Cellular SocketModem Devices.

Dependents:   M2X_dev axeda_wrapper_dev MTS_M2x_Example1 MTS_Cellular_Connect_Example ... more

Revision:
62:83ccef1e94db
Parent:
56:e5e5351f14b3
Child:
68:c490e4a51778
--- a/cellular/Cellular.h	Fri Dec 20 20:29:10 2013 +0000
+++ b/cellular/Cellular.h	Fri Dec 20 23:12:00 2013 +0000
@@ -45,52 +45,17 @@
 * cellular radio is 115200 bps.
 *
 * The following set of example code demonstrates how to send and receive configuration and
-* status AT commands with the radio:
+* status AT commands with the radio, create a data connection and test it:
 * @code
 * #include "mbed.h"
 * #include "Cellular.h"
 * #include "MTSSerialFlowControl.h"
 *
+* using namespace mts;
+* 
 * main() {
 *   //Wait for radio to boot up
-*   wait(20);
-*
-*   //Setup serial interface to radio
-*   MTSSerialFlowControl* serial = new MTSSerialFlowControl(PTD3, PTD2, PTA12, PTC8);
-*   serial->baud(115200);
-*
-*   //Setup Cellular class
-*   Cellular* cellular = Cellular::getInstance();
-*   cellualr->init(serial);
-*
-*   //Run status and configuration commands
-*   printf("Start Status and Configuration Example\n\r");
-*   printf("test: %s\n\r", Cellular::getCodeNames(cellular->test()));
-*   printf("Phone Number: %s\n\r", cellular->getPhoneNumber());
-*   printf("Signal Strength: %d\n\r", cellular->getSignalStrength());
-*   printf("Registration State: %s\n\r", Cellular::getRegistrationNames(cellular->getRegistration()));
-*   printf("Send Basic Command (AT): %s\n\r", Cellular::getCodeNames(cellular->sendBasicCommand("AT", 1000)));
-*   printf("Send Command (AT+CSQ): %s\n\r", sendCommand("AT+CSQ", 1000));
-*
-*   printf("End Program\n\r");
-* }
-* @endcode
-*
-* The following set of example code demonstrates how process SMS messages:
-* @code
-* #include "mbed.h"
-* @endcode
-*
-* The following set of example code demonstrates how to setup and verify a cellular data
-* connection:
-* @code
-* #include "mbed.h"
-* #include "Cellular.h"
-* #include "MTSSerialFlowControl.h"
-*
-* main() {
-*   //Wait for radio to boot up
-*   wait(20);
+*   wait(30);
 *
 *   //Setup serial interface to radio
 *   MTSSerialFlowControl* serial = new MTSSerialFlowControl(PTD3, PTD2, PTA12, PTC8);
@@ -100,17 +65,24 @@
 *   Cellular* cellular = Cellular::getInstance();
 *   cellular->init(serial);
 *
+*   //Run status and configuration commands
+*   printf("Start Status and Configuration Commands\n\r");
+*   printf("Test: %s\n\r", Cellular::getCodeNames(cellular->test()).c_str());
+*   printf("Signal Strength: %d\n\r", cellular->getSignalStrength());
+*   printf("Registration State: %s\n\r", Cellular::getRegistrationNames(cellular->getRegistration()).c_str());
+*   printf("Send Basic Command (AT): %s\n\r", Cellular::getCodeNames(cellular->sendBasicCommand("AT", 1000)).c_str());
+*   printf("Send Command (AT+CSQ): %s\n\r", cellular->sendCommand("AT+CSQ", 1000).c_str());
+* 
 *   //Start Test
-*   printf("Start Network Connectivity Example\n\r");
-*   printf("test: %s\n\r", CodeNames[cellular->test()]);
-*   printf("Set APN: %s\n\r", CodeNames[cellular->setApn("wap.cingular")]) //Use APN from service provider!!!
+*   printf("Start Network Connectivity Test\n\r");
+*   printf("Set APN: %s\n\r", cellular->getCodeNames(cellular->setApn("wap.cingular")).c_str()); //Use APN from service provider!!!
 *
 *   //Setup a data connection
 *   printf("Attempting to Connect\n\r");
 *   while (cellular->connect()) {
 *       wait(1);
 *   }
-*   printf("Connected to Network!\n\r");
+*   printf("Connected to the Network!\n\r");
 *
 *   //Try pinging default server "8.8.8.8"
 *   printf("Ping Valid: %s\n\r", cellular->ping() ? "true" : "false");
@@ -119,10 +91,136 @@
 * }
 * @endcode
 *
+* The following set of example code demonstrates how process SMS messages:
+* @code
+* #include "mbed.h"
+* #include "Cellular.h"
+* #include "MTSSerialFlowControl.h"
+*
+* using namespace mts;
+* 
+* main() {
+*   //Wait for radio to boot up
+*   wait(30);
+*
+*   //Setup serial interface to radio
+*   MTSSerialFlowControl* serial = new MTSSerialFlowControl(PTD3, PTD2, PTA12, PTC8);
+*   serial->baud(115200);
+*
+*   //Setup Cellular class
+*   Cellular* cellular = Cellular::getInstance();
+*   cellular->init(serial);
+* 
+*   //Start test
+*   printf("Test: %s\n\r", Cellular::getCodeNames(cellular->test()).c_str());
+*   
+*   //Send SMS Message
+*   Cellular::Code code;
+*   std::string sMsg("Hello from Multi-Tech MBED!");
+*   std::string sPhoneNum("16128675309"); //Put your phone number here or leave Jenny's...
+*    
+*   printf("Sending message [%s] to [%s]\r\n", sMsg.c_str(), sPhoneNum.c_str());
+*   code = cellular->sendSMS(sPhoneNum, sMsg);
+*    
+*   if(code != Cellular::CELL_OK) {
+*       printf("Error during SMS send [%s]\r\n", Cellular::getCodeNames(code).c_str());
+*   } else {
+*       printf("Success!\r\n");
+*   }
+* 
+*   //Try and receive SMS messages
+*   //To determine your radio's phone number send yourself an SMS and check the received #
+*   printf("Checking Received Messages\r\n");
+*   std::vector<Cellular::Sms> vSms = cellular->getReceivedSms();
+*   printf("\r\n");
+*   for(unsigned int i = 0; i < vSms.size(); i++) {
+*       printf("[%d][%s][%s][%s]\r\n", i, vSms[i].timestamp.c_str(), 
+*               vSms[i].phoneNumber.c_str(), vSms[i].message.c_str());
+*   }
+*   printf("End Program\n\r");
+* }
+* @endcode
+*
 * The following set of example code demonstrates how to setup and use a TCP socket connection
 * using the native commands from this class:
 * @code
 * #include "mbed.h"
+* #include "Cellular.h"
+* #include "MTSSerialFlowControl.h"
+*
+* using namespace mts;
+* 
+* main() {
+*   //Define connection parameters
+*   Cellular::Code code;
+*   const int TEST_PORT = 7000;
+*   //const std::string TEST_SERVER("204.26.122.5"); 
+*   const std::string TEST_SERVER("ws://echo.websocket.org");
+*
+*   //Wait for radio to boot up
+*   wait(30);
+*
+*   //Setup serial interface to radio
+*   MTSSerialFlowControl* serial = new MTSSerialFlowControl(PTD3, PTD2, PTA12, PTC8);
+*   serial->baud(115200);
+*
+*   //Setup Cellular class
+*   Cellular* cellular = Cellular::getInstance();
+*   cellular->init(serial);
+* 
+*   //Start test
+*   printf("Test: %s\n\r", Cellular::getCodeNames(cellular->test()).c_str());
+* 
+*   printf("Setting APN\r\n");
+*   code = cellular->setApn("wap.cingular"); // Use from your service provider
+*   if(code == Cellular::CELL_OK) {
+*       printf("Success!\r\n");
+*   } else {
+*       printf("Error during APN setup [%s]\r\n", cellular->getCodeNames(code).c_str());
+*   }
+*
+*   printf("Signal Strength: %d\n\r", cellular->getSignalStrength());
+*   printf("Registration State: %s\n\r", Cellular::getRegistrationNames(cellular->getRegistration()).c_str());
+*
+*   //Setup a data connection
+*   printf("Attempting to Connect\n\r");
+*   while (cellular->connect()) {
+*       wait(1);
+*   }
+*   printf("Connected to the Network!\n\r"); 
+*   
+*   printf("Opening a TCP Socket\r\n");
+*   if(cellular->open(TEST_SERVER, TEST_PORT, IPStack::TCP)) {
+*       printf("Success!\r\n");   
+*   } else {
+*       printf("Error during TCP socket open [%s:%d]\r\n", TEST_SERVER.c_str(), TEST_PORT);
+*   }
+*     
+*   printf("Writing to socket\r\n");
+*   char data[] = "My Test Echo Message!!!";
+*   int bytesWritten = cellular->write(data, sizeof(data), 10000);
+*   if(bytesWritten == sizeof(data)) {
+*       printf("Successfully wrote message!\r\n");
+*   } else {
+*       printf("Failed to write message!\r\n");   
+*   }
+*    
+*   printf("Waiting 5 seconds\r\n");
+*   wait(5);
+*
+*   printf("Reading from socket for 10 seconds\r\n");
+*   char response[sizeof(data)];
+*   int bytesRead = cellular->read(response, sizeof(data), 10000);
+*   printf("READ: [%d] [%s]\r\n", bytesRead, response);
+* 
+*   printf("Closing socket\r\n");
+*   cellular->close();
+* 
+*   printf("Disconnecting\r\n");
+*   cellular->disconnect();
+* 
+*   printf("End Program\n\r");
+* }
 * @endcode
 *
 * The following set of example code demonstrates how to setup and use a TCP socket connection