this is the demo code for Seeed Arch GPRS V2.0

Dependencies:   GPRS USBDevice mbed

Fork of Seeed_Arch_GPRS_V2_HelloWorld by wei zou

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*
00002   main.cpp
00003   2013 Copyright (c) Seeed Technology Inc.  All right reserved.
00004 
00005   Author:lawliet zou(lawliet.zou@gmail.com)
00006   2013-7-21
00007 
00008   This library is free software; you can redistribute it and/or
00009   modify it under the terms of the GNU Lesser General Public
00010   License as published by the Free Software Foundation; either
00011   version 2.1 of the License, or (at your option) any later version.
00012 
00013   This library is distributed in the hope that it will be useful,
00014   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016   Lesser General Public License for more details.
00017 
00018   You should have received a copy of the GNU Lesser General Public
00019   License along with this library; if not, write to the Free Software
00020   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00021 */
00022 #include "mbed.h"
00023 #include "string.h"
00024 #include "gprs.h"
00025 #include "USBSerial.h"
00026 
00027 #define SEND_SMS_TEST           0
00028 #define CALL_UP_TEST            0
00029 #define ANSWER_TEST             0
00030 #define READ_SMS_TEST           0
00031 
00032 #define PHONE_NUMBER            "13925257382"
00033 #define PIN_PWR                 P1_2    //power up gprs module
00034 #define PIN_PWR_KEY             P1_7
00035 #define PIN_TX                  P1_27   //Serial tx pin
00036 #define PIN_RX                  P1_26   //Serial rx pin
00037 
00038 USBSerial pc(0x1f00, 0x2012, 0x0001, false);
00039 DigitalOut power(PIN_PWR);
00040 DigitalOut powerKey(PIN_PWR_KEY);
00041 GPRS  gprsTest(PIN_TX, PIN_RX, 115200, PHONE_NUMBER);
00042 
00043 // Called by ISR
00044 void settingsChanged(int baud, int bits, int parity, int stop)
00045 {
00046     const Serial::Parity parityTable[] = {Serial::None, Serial::Odd, Serial::Even, Serial::Forced0, Serial::Forced1};
00047 
00048     if (stop != 2) {
00049         stop = 1;   // stop bit(s) = 1 or 1.5
00050     }
00051 
00052     gprsTest.gprsSerial.baud(baud);
00053     gprsTest.gprsSerial.format(bits, parityTable[parity], stop);
00054 }
00055 
00056 /* power pin: low enable
00057      ___
00058         |___
00059 
00060    powerKey pin: you can also power up by long press the powerKey.
00061 
00062         ___
00063     ___|   |___
00064 
00065 */
00066 void gprsPowerUp(void)
00067 {
00068     power = 1;
00069     wait(2);
00070     power = 0;
00071     wait(2);
00072 
00073     powerKey = 0;
00074     wait(1);
00075     powerKey = 1;
00076     wait(2);
00077     powerKey = 0;
00078     wait(3);
00079 }
00080 
00081 void messageHandle(void)
00082 {
00083     __disable_irq();
00084     int messageType = gprsTest.loopHandle();
00085     if(MESSAGE_RING == messageType) {
00086         gprsTest.answer();
00087     } else if(MESSAGE_SMS == messageType) {
00088         char smsMessage[SMS_MAX_LENGTH];
00089         gprsTest.getSMS(smsMessage);
00090         pc.printf("we get SMS:%s",smsMessage);
00091     }
00092     __enable_irq();
00093 }
00094 
00095 int main(void)
00096 {
00097     pc.attach(settingsChanged);
00098     gprsPowerUp();
00099     wait(10);
00100 
00101     while(0 != gprsTest.init()) {
00102         pc.printf("\ngprs init error\n");
00103         wait(2);
00104     }
00105 
00106 #if SEND_SMS_TEST
00107     pc.printf("send SMS test\n");
00108     gprsTest.sendSMS(PHONE_NUMBER,"hello world"); //define phone number and text
00109 #endif
00110 
00111 #if CALL_UP_TEST
00112     pc.printf("call up test\n");
00113     gprsTest.callUp(PHONE_NUMBER);
00114 #endif
00115 
00116 #if ANSWER_TEST || READ_SMS_TEST
00117     pc.printf("Please give a call or send a message\n");
00118     gprsTest.gprsSerial.attach(&messageHandle);
00119 #endif
00120     while(1) {
00121         wait(1);
00122     }
00123     return 0;
00124 }