1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-11-29 10:24:12 +01:00

GSM: Backported library from IDE 1.5.x

Fixes #2343
This commit is contained in:
Cristian Maglie 2014-10-09 23:47:46 +02:00
parent d63350b506
commit afc368b01f
23 changed files with 330 additions and 331 deletions

View File

@ -1,4 +1,9 @@
ARDUINO 1.0.7
[libraries]
* Backported GSM from IDE 1.5.x
ARDUINO 1.0.6 - 2014.09.16
[core]

View File

@ -6,8 +6,8 @@
#define __TOUTMODEMCONFIGURATION__ 5000//equivalent to 30000 because of time in interrupt routine.
#define __TOUTAT__ 1000
char _command_AT[] PROGMEM = "AT";
char _command_CGREG[] PROGMEM = "AT+CGREG?";
const char _command_AT[] PROGMEM = "AT";
const char _command_CGREG[] PROGMEM = "AT+CGREG?";
GSM3ShieldV1AccessProvider::GSM3ShieldV1AccessProvider(bool debug)

View File

@ -12,7 +12,7 @@ int GSM3ShieldV1BaseProvider::ready()
return theGSM3ShieldV1ModemCore.getCommandError();
};
void GSM3ShieldV1BaseProvider::prepareAuxLocate(PROGMEM prog_char str[], char auxLocate[])
void GSM3ShieldV1BaseProvider::prepareAuxLocate(PGM_P str, char auxLocate[])
{
int i=0;
char c;

View File

@ -54,7 +54,7 @@ class GSM3ShieldV1BaseProvider
@param str PROGMEN
@param auxLocate Buffer where to locate strings
*/
void prepareAuxLocate(PROGMEM prog_char str[], char auxLocate[]);
void prepareAuxLocate(PGM_P str, char auxLocate[]);
/** Manages modem response
@param from Initial byte of buffer

View File

@ -1,8 +1,8 @@
#include <GSM3ShieldV1DataNetworkProvider.h>
#include <Arduino.h>
char _command_CGATT[] PROGMEM = "AT+CGATT=";
char _command_SEPARATOR[] PROGMEM = "\",\"";
const char _command_CGATT[] PROGMEM = "AT+CGATT=";
const char _command_SEPARATOR[] PROGMEM = "\",\"";
//Attach GPRS main function.
GSM3_NetworkStatus_t GSM3ShieldV1DataNetworkProvider::attachGPRS(char* apn, char* user_name, char* password, bool synchronous)

View File

@ -75,7 +75,7 @@ void GSM3ShieldV1ModemCore::closeCommand(int code)
}
//Generic command (stored in flash).
void GSM3ShieldV1ModemCore::genericCommand_rq(PROGMEM prog_char str[], bool addCR)
void GSM3ShieldV1ModemCore::genericCommand_rq(PGM_P str, bool addCR)
{
theBuffer().flush();
writePGM(str, addCR);
@ -157,7 +157,7 @@ void GSM3ShieldV1ModemCore::openCommand(GSM3ShieldV1BaseProvider* provider, GSM3
};
size_t GSM3ShieldV1ModemCore::writePGM(PROGMEM prog_char str[], bool CR)
size_t GSM3ShieldV1ModemCore::writePGM(PGM_P str, bool CR)
{
int i=0;
char c;

View File

@ -167,7 +167,7 @@ class GSM3ShieldV1ModemCore : public GSM3SoftSerialMgr, public Print
@param CR Carriadge return adding automatically
@return size
*/
virtual size_t writePGM(PROGMEM prog_char str[], bool CR=true);
virtual size_t writePGM(PGM_P str, bool CR=true);
/** Establish debug mode
@param db Boolean that indicates debug on or off
@ -182,11 +182,11 @@ class GSM3ShieldV1ModemCore : public GSM3SoftSerialMgr, public Print
*/
bool genericParse_rsp(bool& rsp, char* string=0, char* string2=0);
/** Generates a generic AT command request from PROGMEM prog_char buffer
/** Generates a generic AT command request from PROGMEM buffer
@param str Buffer with AT command
@param addCR Carriadge return adding automatically
*/
void genericCommand_rq(PROGMEM prog_char str[], bool addCR=true);
void genericCommand_rq(PGM_P str, bool addCR=true);
/** Generates a generic AT command request from a simple char buffer
@param str Buffer with AT command
@ -194,12 +194,6 @@ class GSM3ShieldV1ModemCore : public GSM3SoftSerialMgr, public Print
*/
void genericCommand_rqc(const char* str, bool addCR=true);
/** Generates a generic AT command request from characters buffer
@param str Buffer with AT command
@param addCR Carriadge return adding automatically
*/
void genericCommand_rq(const char* str, bool addCR=true);
/** Returns the circular buffer
@return circular buffer
*/

View File

@ -69,7 +69,7 @@ String GSM3ShieldV1ModemVerification::getIMEI()
modemResponse.toCharArray(res_to_compare, modemResponse.length());
if(strstr(res_to_compare,"OK") == NULL)
{
return NULL;
return String(NULL);
}
else
{

View File

@ -1,7 +1,7 @@
#include <GSM3ShieldV1MultiClientProvider.h>
#include <GSM3ShieldV1ModemCore.h>
char _command_MultiQISRVC[] PROGMEM = "AT+QISRVC=";
const char _command_MultiQISRVC[] PROGMEM = "AT+QISRVC=";
#define __TOUTFLUSH__ 10000

View File

@ -4,7 +4,7 @@
#define __NCLIENTS_MAX__ 3
char _command_QILOCIP[] PROGMEM = "AT+QILOCIP";
const char _command_QILOCIP[] PROGMEM = "AT+QILOCIP";
GSM3ShieldV1MultiServerProvider::GSM3ShieldV1MultiServerProvider()
{

View File

@ -63,7 +63,7 @@ String GSM3ShieldV1ScanNetworks::getCurrentCarrier()
String final_result = ptr_token;
return final_result;
}else{
return NULL;
return String(NULL);
}
}
@ -82,7 +82,7 @@ String GSM3ShieldV1ScanNetworks::getSignalStrength()
final_result.trim();
return final_result;
}else{
return NULL;
return String(NULL);
}
}

View File

@ -51,10 +51,10 @@ void setup()
// After starting the modem with GSM.begin()
// attach the shield to the GPRS network with the APN, login and password
while(notConnected)
while (notConnected)
{
if((gsmAccess.begin(PINNUMBER)==GSM_READY) &
(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY))
if ((gsmAccess.begin(PINNUMBER) == GSM_READY) &
(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY))
notConnected = false;
else
{
@ -103,7 +103,7 @@ void loop()
client.stop();
// do nothing forevermore:
for(;;)
for (;;)
;
}
}

View File

@ -30,7 +30,7 @@ GSM gsmAccess; // include a 'true' parameter for debug enabled
GSMServer server(80); // port 80 (http default)
// timeout
const unsigned long __TIMEOUT__ = 10*1000;
const unsigned long __TIMEOUT__ = 10 * 1000;
void setup()
{
@ -45,10 +45,10 @@ void setup()
// Start GSM shield
// If your SIM has PIN, pass it as a parameter of begin() in quotes
while(notConnected)
while (notConnected)
{
if((gsmAccess.begin(PINNUMBER)==GSM_READY) &
(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY))
if ((gsmAccess.begin(PINNUMBER) == GSM_READY) &
(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY))
notConnected = false;
else
{
@ -84,7 +84,7 @@ void loop() {
{
Serial.println("Receiving request!");
bool sendResponse = false;
while(char c=client.read()) {
while (char c = client.read()) {
if (c == '\n') sendResponse = true;
}

View File

@ -48,9 +48,9 @@ void setup()
// Start GSM shield
// If your SIM has PIN, pass it as a parameter of begin() in quotes
while(notConnected)
while (notConnected)
{
if(gsmAccess.begin(PINNUMBER)==GSM_READY)
if (gsmAccess.begin(PINNUMBER) == GSM_READY)
notConnected = false;
else
{
@ -87,16 +87,16 @@ void loop()
// Check if the receiving end has picked up the call
if(vcs.voiceCall(charbuffer))
if (vcs.voiceCall(charbuffer))
{
Serial.println("Call Established. Enter line to end");
// Wait for some input from the line
while(Serial.read()!='\n' && (vcs.getvoiceCallStatus()==TALKING));
while (Serial.read() != '\n' && (vcs.getvoiceCallStatus() == TALKING));
// And hang up
vcs.hangCall();
}
Serial.println("Call Finished");
remoteNumber="";
remoteNumber = "";
Serial.println("Enter phone number to call.");
}
else
@ -108,7 +108,7 @@ void loop()
else
{
// add the latest character to the message to send:
if(inChar!='\r')
if (inChar != '\r')
remoteNumber += inChar;
}
}

View File

@ -44,9 +44,9 @@ void setup()
boolean notConnected = true;
// Start GSM connection
while(notConnected)
while (notConnected)
{
if(gsmAccess.begin(PINNUMBER)==GSM_READY)
if (gsmAccess.begin(PINNUMBER) == GSM_READY)
notConnected = false;
else
{
@ -74,14 +74,14 @@ void loop()
// An example of message disposal
// Any messages starting with # should be discarded
if(sms.peek()=='#')
if (sms.peek() == '#')
{
Serial.println("Discarded SMS");
sms.flush();
}
// Read message bytes and print them
while(c=sms.read())
while (c = sms.read())
Serial.print(c);
Serial.println("\nEND OF MESSAGE");

View File

@ -49,9 +49,9 @@ void setup()
// Start GSM shield
// If your SIM has PIN, pass it as a parameter of begin() in quotes
while(notConnected)
while (notConnected)
{
if(gsmAccess.begin(PINNUMBER)==GSM_READY)
if (gsmAccess.begin(PINNUMBER) == GSM_READY)
notConnected = false;
else
{
@ -93,7 +93,7 @@ void loop()
case TALKING: // In this case the call would be established
Serial.println("TALKING. Press enter to hang up.");
while(Serial.read()!='\n')
while (Serial.read() != '\n')
delay(100);
vcs.hangCall();
Serial.println("Hanging up and waiting for the next call.");

View File

@ -45,9 +45,9 @@ void setup()
// Start GSM shield
// If your SIM has PIN, pass it as a parameter of begin() in quotes
while(notConnected)
while (notConnected)
{
if(gsmAccess.begin(PINNUMBER)==GSM_READY)
if (gsmAccess.begin(PINNUMBER) == GSM_READY)
notConnected = false;
else
{
@ -89,7 +89,7 @@ void loop()
int readSerial(char result[])
{
int i = 0;
while(1)
while (1)
{
while (Serial.available() > 0)
{
@ -100,7 +100,7 @@ int readSerial(char result[])
Serial.flush();
return 0;
}
if(inChar!='\r')
if (inChar != '\r')
{
result[i] = inChar;
i++;

View File

@ -60,7 +60,7 @@ void loop()
boolean operationSuccess;
operationSuccess = band.setBand(newBandName);
// Tell the user if the operation was OK
if(operationSuccess)
if (operationSuccess)
{
Serial.println("Success");
}
@ -69,9 +69,9 @@ void loop()
Serial.println("Error while changing band");
}
if(operationSuccess)
if (operationSuccess)
{
while(true);
while (true);
}
}
@ -91,26 +91,26 @@ String askUser()
Serial.println("6 : GSM(850)+E-GSM(900)+DCS(1800)+PCS(1900)");
// Empty the incoming buffer
while(Serial.available())
while (Serial.available())
Serial.read();
// Wait for an answer, just look at the first character
while(!Serial.available());
char c= Serial.read();
if(c=='1')
newBand=GSM_MODE_EGSM;
else if(c=='2')
newBand=GSM_MODE_DCS;
else if(c=='3')
newBand=GSM_MODE_PCS;
else if(c=='4')
newBand=GSM_MODE_EGSM_DCS;
else if(c=='5')
newBand=GSM_MODE_GSM850_PCS;
else if(c=='6')
newBand=GSM_MODE_GSM850_EGSM_DCS_PCS;
while (!Serial.available());
char c = Serial.read();
if (c == '1')
newBand = GSM_MODE_EGSM;
else if (c == '2')
newBand = GSM_MODE_DCS;
else if (c == '3')
newBand = GSM_MODE_PCS;
else if (c == '4')
newBand = GSM_MODE_EGSM_DCS;
else if (c == '5')
newBand = GSM_MODE_GSM850_PCS;
else if (c == '6')
newBand = GSM_MODE_GSM850_EGSM_DCS_PCS;
else
newBand="GSM_MODE_UNDEFINED";
newBand = "GSM_MODE_UNDEFINED";
return newBand;
}

View File

@ -54,9 +54,9 @@ void setup()
// Start GSM shield
// If your SIM has PIN, pass it as a parameter of begin() in quotes
while(notConnected)
while (notConnected)
{
if(gsmAccess.begin(PINNUMBER)==GSM_READY)
if (gsmAccess.begin(PINNUMBER) == GSM_READY)
notConnected = false;
else
{
@ -69,8 +69,8 @@ void setup()
// IMEI, modem unique identifier
Serial.print("Modem IMEI: ");
IMEI = modemTest.getIMEI();
IMEI.replace("\n","");
if(IMEI != NULL)
IMEI.replace("\n", "");
if (IMEI != NULL)
Serial.println(IMEI);
}

View File

@ -44,15 +44,15 @@ void setup()
PINManager.begin();
// check if the SIM have pin lock
while(!auth){
while (!auth) {
int pin_query = PINManager.isPIN();
if(pin_query == 1)
if (pin_query == 1)
{
// if SIM is locked, enter PIN code
Serial.print("Enter PIN code: ");
user_input = readSerial();
// check PIN code
if(PINManager.checkPIN(user_input) == 0)
if (PINManager.checkPIN(user_input) == 0)
{
auth = true;
PINManager.setPINUsed(true);
@ -64,7 +64,7 @@ void setup()
Serial.println("Incorrect PIN. Remember that you have 3 opportunities.");
}
}
else if(pin_query == -1)
else if (pin_query == -1)
{
// PIN code is locked, user must enter PUK code
Serial.println("PIN locked. Enter PUK code: ");
@ -72,7 +72,7 @@ void setup()
Serial.print("Now, enter a new PIN code: ");
user_input = readSerial();
// check PUK code
if(PINManager.checkPUK(puk, user_input) == 0)
if (PINManager.checkPUK(puk, user_input) == 0)
{
auth = true;
PINManager.setPINUsed(true);
@ -84,11 +84,11 @@ void setup()
Serial.println("Incorrect PUK or invalid new PIN. Try again!.");
}
}
else if(pin_query == -2)
else if (pin_query == -2)
{
// the worst case, PIN and PUK are locked
Serial.println("PIN & PUK locked. Use PIN2/PUK2 in a mobile phone.");
while(true);
while (true);
}
else
{
@ -100,16 +100,16 @@ void setup()
// start GSM shield
Serial.print("Checking register in GSM network...");
if(PINManager.checkReg() == 0)
if (PINManager.checkReg() == 0)
Serial.println(oktext);
// if you are connect by roaming
else if(PINManager.checkReg() == 1)
else if (PINManager.checkReg() == 1)
Serial.println("ROAMING " + oktext);
else
{
// error connection
Serial.println(errortext);
while(true);
while (true);
}
}
@ -120,17 +120,17 @@ void loop()
// user_op variables save user option
Serial.println("Choose an option:\n1 - On/Off PIN.");
if(PINManager.getPINUsed())
if (PINManager.getPINUsed())
Serial.println("2 - Change PIN.");
String user_op = readSerial();
if(user_op == "1")
if (user_op == "1")
{
Serial.println("Enter your PIN code:");
user_input = readSerial();
// activate/deactivate PIN lock
PINManager.switchPIN(user_input);
}
else if(user_op == "2" & PINManager.getPINUsed())
else if (user_op == "2" & PINManager.getPINUsed())
{
Serial.println("Enter your actual PIN code:");
String oldPIN = readSerial();
@ -152,7 +152,7 @@ void loop()
String readSerial()
{
String text = "";
while(1)
while (1)
{
while (Serial.available() > 0)
{
@ -161,7 +161,7 @@ String readSerial()
{
return text;
}
if(inChar!='\r')
if (inChar != '\r')
text += inChar;
}
}

View File

@ -59,10 +59,10 @@ void loop()
// start GSM shield
// if your SIM has PIN, pass it as a parameter of begin() in quotes
Serial.print("Connecting GSM network...");
if(gsmAccess.begin(PINNUMBER)!=GSM_READY)
if (gsmAccess.begin(PINNUMBER) != GSM_READY)
{
Serial.println(errortext);
while(true);
while (true);
}
Serial.println(oktext);
@ -85,11 +85,11 @@ void loop()
// attach GPRS
Serial.println("Attaching to GPRS with your APN...");
if(gprsAccess.attachGPRS(apn, login, password)!=GPRS_READY)
if (gprsAccess.attachGPRS(apn, login, password) != GPRS_READY)
{
Serial.println(errortext);
}
else{
else {
Serial.println(oktext);
@ -101,7 +101,7 @@ void loop()
// if user introduced a proxy, asks him for proxy port
int pport;
if(proxy[0] != '\0'){
if (proxy[0] != '\0') {
// read proxy port introduced by user
char proxyport[10];
Serial.print("Enter the proxy port: ");
@ -117,7 +117,7 @@ void loop()
int res_connect;
// if use a proxy, connect with it
if(use_proxy)
if (use_proxy)
res_connect = client.connect(proxy, pport);
else
res_connect = client.connect(url, 80);
@ -128,7 +128,7 @@ void loop()
client.print("GET ");
// if use a proxy, the path is arduino.cc URL
if(use_proxy)
if (use_proxy)
client.print(urlproxy);
else
client.print(path);
@ -145,7 +145,7 @@ void loop()
Serial.print("Receiving response...");
boolean test = true;
while(test)
while (test)
{
// if there are incoming bytes available
// from the server, read and check them
@ -155,11 +155,11 @@ void loop()
response += c;
// cast response obtained from string to char array
char responsechar[response.length()+1];
response.toCharArray(responsechar, response.length()+1);
char responsechar[response.length() + 1];
response.toCharArray(responsechar, response.length() + 1);
// if response includes a "200 OK" substring
if(strstr(responsechar, "200 OK") != NULL){
if (strstr(responsechar, "200 OK") != NULL) {
Serial.println(oktext);
Serial.println("TEST COMPLETE!");
test = false;
@ -184,7 +184,7 @@ void loop()
int readSerial(char result[])
{
int i = 0;
while(1)
while (1)
{
while (Serial.available() > 0)
{
@ -194,7 +194,7 @@ int readSerial(char result[])
result[i] = '\0';
return 0;
}
if(inChar!='\r')
if (inChar != '\r')
{
result[i] = inChar;
i++;

View File

@ -37,7 +37,7 @@ void setup()
// start modem test (reset and check response)
Serial.print("Starting modem test...");
if(modem.begin())
if (modem.begin())
Serial.println("modem.begin() succeeded");
else
Serial.println("ERROR, no modem answer.");
@ -50,7 +50,7 @@ void loop()
IMEI = modem.getIMEI();
// check IMEI response
if(IMEI != NULL)
if (IMEI != NULL)
{
// show IMEI in serial monitor
Serial.println("Modem's IMEI: " + IMEI);
@ -58,7 +58,7 @@ void loop()
Serial.print("Resetting modem...");
modem.begin();
// get and check IMEI one more time
if(modem.getIMEI() != NULL)
if (modem.getIMEI() != NULL)
{
Serial.println("Modem is functoning properly");
}
@ -72,6 +72,6 @@ void loop()
Serial.println("Error: Could not get IMEI");
}
// do nothing:
while(true);
while (true);
}

View File

@ -16,7 +16,7 @@
This example code is part of the public domain
*/
#include <GSM.h>
#include <GSM.h>
// PIN Number
#define PINNUMBER ""
@ -33,7 +33,7 @@ GSM gsmAccess; // include a 'true' parameter for debug enabled
GSMServer server(80); // port 80 (http default)
// timeout
const unsigned long __TIMEOUT__ = 10*1000;
const unsigned long __TIMEOUT__ = 10 * 1000;
void setup()
{
@ -49,10 +49,10 @@ void setup()
// Start GSM shield
// If your SIM has PIN, pass it as a parameter of begin() in quotes
while(!connected)
while (!connected)
{
if((gsmAccess.begin(PINNUMBER)==GSM_READY) &
(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY))
if ((gsmAccess.begin(PINNUMBER) == GSM_READY) &
(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY))
connected = true;
else
{
@ -72,14 +72,14 @@ void setup()
Serial.println(LocalIP);
}
void loop(){
void loop() {
GSMClient client = server.available();
if (client) {
if (client.available()) {
Serial.write(client.read());
}
}
}
}