give example to use GPRS Shield library
Fork of GPRS_Shield_Test by
Diff: main.cpp
- Revision:
- 3:e07b56b8b637
- Parent:
- 2:3b735ebe88b0
- Child:
- 4:f7f516572a4a
--- a/main.cpp Mon Nov 18 07:48:07 2013 +0000 +++ b/main.cpp Mon Feb 10 02:00:50 2014 +0000 @@ -1,47 +1,80 @@ +/* + main.cpp + 2013 Copyright (c) Seeed Technology Inc. All right reserved. + + Author:lawliet zou(lawliet.zou@gmail.com) + 2014-02-08 + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ #include "mbed.h" -#include "string.h" #include "gprs.h" -#define SERIAL_DEBUG 0 -#define SEND_SMS_TEST 0 + +//#define SEEEDUINO_ARCH +#define SEEEDUINO_ARCH_PRO + +#if defined(SEEEDUINO_ARCH) +#define GPRS_TX_PIN P0_19 +#define GPRS_RX_PIN P0_18 +#elif defined(SEEEDUINO_ARCH_PRO) +#define GPRS_TX_PIN P4_28 +#define GPRS_RX_PIN P4_29 +#else +#define GPRS_TX_PIN P0_19 +#define GPRS_RX_PIN P0_18 +#endif + +#define SEND_SMS_TEST 1 #define CALL_UP_TEST 0 #define ANSWER_TEST 0 #define READ_SMS_TEST 0 -#define TCP_TEST 0 -#define IP_ADDRSS "42.96.164.52" -#define PORT "80" +#define BAUD_RATE 19200 // Baud rate of GPRS Shield +#define PHONE_NUMBER "159****4951" -GPRS gprsTest(P0_19, P0_18, 115200, "10086"); +GPRS gprsTest(GPRS_TX_PIN, GPRS_RX_PIN, BAUD_RATE, PHONE_NUMBER); int main(void) { - if(0 != gprsTest.init()) { - return -1; + while(0 != gprsTest.init()) { + wait(2); } #if SEND_SMS_TEST - gprsTest.sendSMS("10086","hello,lawliet"); //define phone number and text + gprsTest.sendSMS(PHONE_NUMBER,"hello world"); //define phone number and text #endif #if CALL_UP_TEST - gprsTest.callUp("10086"); + gprsTest.callUp(PHONE_NUMBER); #endif #if ANSWER_TEST || READ_SMS_TEST - gprsTest.loop(0); -#endif - -#if TCP_TEST - gprsTest.connectTCP(IP_ADDRSS,PORT); - gprsTest.sendTCPData("hello,lawliet test"); -#endif - -#if SERIAL_DEBUG - gprsTest.serialDebug(USBTX,USBRX); + while(1) { + int messageType = gprsTest.loopHandle(); + if(MESSAGE_RING == messageType) { + gprsTest.answer(); + } else if(MESSAGE_SMS == messageType) { + char smsMessage[SMS_MAX_LENGTH]; + gprsTest.getSMS(smsMessage); + } + } #endif return 0; } +