[175] | 1 | /*
|
---|
| 2 | This file is part of the GSM3 communications library for Arduino
|
---|
| 3 | -- Multi-transport communications platform
|
---|
| 4 | -- Fully asynchronous
|
---|
| 5 | -- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
|
---|
| 6 | -- Voice calls
|
---|
| 7 | -- SMS
|
---|
| 8 | -- TCP/IP connections
|
---|
| 9 | -- HTTP basic clients
|
---|
| 10 |
|
---|
| 11 | This library has been developed by Telefónica Digital - PDI -
|
---|
| 12 | - Physical Internet Lab, as part as its collaboration with
|
---|
| 13 | Arduino and the Open Hardware Community.
|
---|
| 14 |
|
---|
| 15 | September-December 2012
|
---|
| 16 |
|
---|
| 17 | This library is free software; you can redistribute it and/or
|
---|
| 18 | modify it under the terms of the GNU Lesser General Public
|
---|
| 19 | License as published by the Free Software Foundation; either
|
---|
| 20 | version 2.1 of the License, or (at your option) any later version.
|
---|
| 21 |
|
---|
| 22 | This library is distributed in the hope that it will be useful,
|
---|
| 23 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 25 | Lesser General Public License for more details.
|
---|
| 26 |
|
---|
| 27 | You should have received a copy of the GNU Lesser General Public
|
---|
| 28 | License along with this library; if not, write to the Free Software
|
---|
| 29 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
---|
| 30 |
|
---|
| 31 | The latest version of this library can always be found at
|
---|
| 32 | https://github.com/BlueVia/Official-Arduino
|
---|
| 33 | */
|
---|
| 34 | #include <GSM3ShieldV1DirectModemProvider.h>
|
---|
| 35 | #include <GSM3ShieldV1ModemCore.h>
|
---|
| 36 | #include <HardwareSerial.h>
|
---|
| 37 | #include <Arduino.h>
|
---|
| 38 |
|
---|
| 39 | #define __RESETPIN__ 7
|
---|
| 40 |
|
---|
| 41 | //Constructor
|
---|
| 42 | GSM3ShieldV1DirectModemProvider::GSM3ShieldV1DirectModemProvider(bool t)
|
---|
| 43 | {
|
---|
| 44 | trace=t;
|
---|
| 45 | };
|
---|
| 46 |
|
---|
| 47 | void GSM3ShieldV1DirectModemProvider::begin()
|
---|
| 48 | {
|
---|
| 49 | theGSM3ShieldV1ModemCore.gss.begin(9600);
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | void GSM3ShieldV1DirectModemProvider::restartModem()
|
---|
| 53 | {
|
---|
| 54 | pinMode(__RESETPIN__, OUTPUT);
|
---|
| 55 | digitalWrite(__RESETPIN__, HIGH);
|
---|
| 56 | delay(12000);
|
---|
| 57 | digitalWrite(__RESETPIN__, LOW);
|
---|
| 58 | delay(1000);
|
---|
| 59 |
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | //To enable the debug process
|
---|
| 63 | void GSM3ShieldV1DirectModemProvider::connect()
|
---|
| 64 | {
|
---|
| 65 | theGSM3ShieldV1ModemCore.registerActiveProvider(this);
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | //To disable the debug process
|
---|
| 69 | void GSM3ShieldV1DirectModemProvider::disconnect()
|
---|
| 70 | {
|
---|
| 71 | theGSM3ShieldV1ModemCore.registerActiveProvider(0);
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | //Write to the modem by means of SoftSerial
|
---|
| 75 | size_t GSM3ShieldV1DirectModemProvider::write(uint8_t c)
|
---|
| 76 | {
|
---|
| 77 | theGSM3ShieldV1ModemCore.write(c);
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | //Detect if data to be read
|
---|
| 81 | int/*bool*/ GSM3ShieldV1DirectModemProvider::available()
|
---|
| 82 | {
|
---|
| 83 | if (theGSM3ShieldV1ModemCore.gss.cb.peek(1)) return 1;
|
---|
| 84 | else return 0;
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | //Read data
|
---|
| 88 | int/*char*/ GSM3ShieldV1DirectModemProvider::read()
|
---|
| 89 | {
|
---|
| 90 | int dataRead;
|
---|
| 91 | dataRead = theGSM3ShieldV1ModemCore.gss.cb.read();
|
---|
| 92 | //In case last char in xof mode.
|
---|
| 93 | if (!(theGSM3ShieldV1ModemCore.gss.cb.peek(0))) {
|
---|
| 94 | theGSM3ShieldV1ModemCore.gss.spaceAvailable();
|
---|
| 95 | delay(100);
|
---|
| 96 | }
|
---|
| 97 | return dataRead;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | //Peek data
|
---|
| 101 | int/*char*/ GSM3ShieldV1DirectModemProvider::peek()
|
---|
| 102 | {
|
---|
| 103 | return theGSM3ShieldV1ModemCore.gss.cb.peek(0);
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | //Flush data
|
---|
| 107 | void GSM3ShieldV1DirectModemProvider::flush()
|
---|
| 108 | {
|
---|
| 109 | return theGSM3ShieldV1ModemCore.gss.cb.flush();
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | String GSM3ShieldV1DirectModemProvider::writeModemCommand(String ATcommand, int responseDelay)
|
---|
| 113 | {
|
---|
| 114 |
|
---|
| 115 | if(trace)
|
---|
| 116 | SerialUSB.println(ATcommand);
|
---|
| 117 |
|
---|
| 118 | // Flush other texts
|
---|
| 119 | flush();
|
---|
| 120 |
|
---|
| 121 | //Enter debug mode.
|
---|
| 122 | connect();
|
---|
| 123 | //Send the AT command.
|
---|
| 124 | println(ATcommand);
|
---|
| 125 |
|
---|
| 126 | delay(responseDelay);
|
---|
| 127 |
|
---|
| 128 | //Get response data from modem.
|
---|
| 129 | String result = "";
|
---|
| 130 | if(trace)
|
---|
| 131 | theGSM3ShieldV1ModemCore.gss.cb.debugBuffer();
|
---|
| 132 |
|
---|
| 133 | while (available())
|
---|
| 134 | {
|
---|
| 135 | char c = read();
|
---|
| 136 | result += c;
|
---|
| 137 | }
|
---|
| 138 | if(trace)
|
---|
| 139 | SerialUSB.println(result);
|
---|
| 140 | //Leave the debug mode.
|
---|
| 141 | disconnect();
|
---|
| 142 | return result;
|
---|
| 143 | }
|
---|