[136] | 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 <GSM3MobileNetworkProvider.h>
|
---|
| 35 | #include <GSM3MobileMockupProvider.h>
|
---|
| 36 | #include <inttypes.h>
|
---|
| 37 | #include <HardwareSerial.h>
|
---|
| 38 | #include <Arduino.h>
|
---|
| 39 |
|
---|
| 40 |
|
---|
| 41 | GSM3MobileMockupProvider::GSM3MobileMockupProvider()
|
---|
| 42 | {
|
---|
| 43 | lineStatus=IDLE;
|
---|
| 44 | msgExample="Hello#World";
|
---|
| 45 | msgIndex=0;
|
---|
| 46 | };
|
---|
| 47 |
|
---|
| 48 | int GSM3MobileMockupProvider::begin(char* pin)
|
---|
| 49 | {
|
---|
| 50 | Serial.println("GSM3MobileMockupProvider::begin()");
|
---|
| 51 | return 0;
|
---|
| 52 | };
|
---|
| 53 |
|
---|
| 54 | int GSM3MobileMockupProvider::ready()
|
---|
| 55 | {
|
---|
| 56 | Serial.println("GSM3MobileMockupProvider::ready()");
|
---|
| 57 | return 1;
|
---|
| 58 | };
|
---|
| 59 |
|
---|
| 60 | int GSM3MobileMockupProvider::beginSMS(const char* number)
|
---|
| 61 | {
|
---|
| 62 | Serial.println("SM3MobileMockupProvider::beginSMS()");
|
---|
| 63 | return 0;
|
---|
| 64 | };
|
---|
| 65 |
|
---|
| 66 | void GSM3MobileMockupProvider::writeSMS(char c)
|
---|
| 67 | {
|
---|
| 68 | Serial.print(c);
|
---|
| 69 | };
|
---|
| 70 |
|
---|
| 71 | int GSM3MobileMockupProvider::endSMS()
|
---|
| 72 | {
|
---|
| 73 | Serial.println("GSM3MobileMockupProvider::endSMS()");
|
---|
| 74 | };
|
---|
| 75 |
|
---|
| 76 | int GSM3MobileMockupProvider::availableSMS()
|
---|
| 77 | {
|
---|
| 78 | Serial.println("GSM3MobileMockupProvider::availableSMS()");
|
---|
| 79 | return 120;
|
---|
| 80 | };
|
---|
| 81 |
|
---|
| 82 | int GSM3MobileMockupProvider::peek()
|
---|
| 83 | {
|
---|
| 84 | return (int)'H';
|
---|
| 85 | };
|
---|
| 86 |
|
---|
| 87 | int GSM3MobileMockupProvider::remoteSMSNumber(char* number, int nlength)
|
---|
| 88 | {
|
---|
| 89 | if(nlength>=13)
|
---|
| 90 | strcpy(number, "+34630538546");
|
---|
| 91 | return 12;
|
---|
| 92 | };
|
---|
| 93 |
|
---|
| 94 |
|
---|
| 95 | void GSM3MobileMockupProvider::flushSMS()
|
---|
| 96 | {
|
---|
| 97 | Serial.println("GSM3MobileMockupProvider::flushSMS()");
|
---|
| 98 | };
|
---|
| 99 |
|
---|
| 100 | int GSM3MobileMockupProvider::readSMS()
|
---|
| 101 | {
|
---|
| 102 | if(msgExample[msgIndex]==0)
|
---|
| 103 | {
|
---|
| 104 | msgIndex=0;
|
---|
| 105 | return 0;
|
---|
| 106 | }
|
---|
| 107 | else
|
---|
| 108 | {
|
---|
| 109 | msgIndex++;
|
---|
| 110 | return msgExample[msgIndex-1];
|
---|
| 111 | };
|
---|
| 112 | };
|
---|
| 113 |
|
---|
| 114 | int GSM3MobileMockupProvider::connectTCPClient(const char* server, int port, int id_socket)
|
---|
| 115 | {
|
---|
| 116 | Serial.println("GSM3MobileMockupProvider::connectTCPClient()");
|
---|
| 117 | Serial.print(server);Serial.print(":");Serial.print(port);Serial.print("-");Serial.println(id_socket);
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | void GSM3MobileMockupProvider::writeSocket(const uint8_t *buf, size_t size, int id_socket)
|
---|
| 121 | {
|
---|
| 122 | int i;
|
---|
| 123 | for(i=0;i<size;i++)
|
---|
| 124 | Serial.print(buf[i]);
|
---|
| 125 | }
|
---|
| 126 | /* I'm taking this off. We'll reply from the NetworkProvider
|
---|
| 127 | uint8_t GSM3MobileMockupProvider::getStatus(uint8_t socket)
|
---|
| 128 | {
|
---|
| 129 | if((socket>=minSocket())&&(socket<=maxSocket()))
|
---|
| 130 | return 1;
|
---|
| 131 | else
|
---|
| 132 | return 0;
|
---|
| 133 | };
|
---|
| 134 | */
|
---|
| 135 |
|
---|
| 136 | int GSM3MobileMockupProvider::readSocket(uint8_t *buf, size_t size, int idsocket)
|
---|
| 137 | {
|
---|
| 138 | int i;
|
---|
| 139 | int l=strlen(msgExample);
|
---|
| 140 | for(i=0;(i<size)&&(i<l);i++)
|
---|
| 141 | buf[i]=msgExample[i];
|
---|
| 142 | buf[i]=0;
|
---|
| 143 | return i;
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | int GSM3MobileMockupProvider::availableSocket(int idsocket)
|
---|
| 147 | {
|
---|
| 148 | return 1;
|
---|
| 149 | };
|
---|
| 150 |
|
---|
| 151 | int GSM3MobileMockupProvider::readSocket(int idsocket, bool advance)
|
---|
| 152 | {
|
---|
| 153 | char c;
|
---|
| 154 | if(msgExample[msgIndex]==0)
|
---|
| 155 | {
|
---|
| 156 | msgIndex=0;
|
---|
| 157 | return 0;
|
---|
| 158 | }
|
---|
| 159 | else
|
---|
| 160 | {
|
---|
| 161 | c=msgExample[msgIndex];
|
---|
| 162 | if(advance)
|
---|
| 163 | msgIndex++;
|
---|
| 164 | };
|
---|
| 165 | return c;
|
---|
| 166 | };
|
---|
| 167 |
|
---|
| 168 | void GSM3MobileMockupProvider::flushSocket(int idsocket)
|
---|
| 169 | {
|
---|
| 170 | while(readSocket(idsocket));
|
---|
| 171 | };
|
---|
| 172 |
|
---|
| 173 | int GSM3MobileMockupProvider::disconnectTCP(int idsocket)
|
---|
| 174 | {
|
---|
| 175 | Serial.println("GSM3MobileMockupProvider::disconnectTCP()");
|
---|
| 176 | return 1;
|
---|
| 177 | };
|
---|
| 178 |
|
---|
| 179 | int GSM3MobileMockupProvider::connectTCPServer(int port, char* localIP, int* localIPlength)
|
---|
| 180 | {
|
---|
| 181 | Serial.println("GSM3MobileMockupProvider::connectTCPServer()");
|
---|
| 182 | if((localIP!=0)&&(*localIPlength>12))
|
---|
| 183 | strcpy("192.168.1.1", localIP);
|
---|
| 184 | return 1;
|
---|
| 185 | };
|
---|
| 186 |
|
---|
| 187 | bool GSM3MobileMockupProvider::getSocketModemStatus(uint8_t s)
|
---|
| 188 | {
|
---|
| 189 | // Feeling lazy
|
---|
| 190 | return true;
|
---|
| 191 | }
|
---|
| 192 |
|
---|