Permalink
Browse files

De nuevo, los cambios de syvic y el que metieron en la web...

  • Loading branch information...
1 parent e92b1f4 commit 476c67a5b9069aa07bca72b639243468dafb1bc0 @zorzano zorzano committed Sep 30, 2011
Showing with 192 additions and 48 deletions.
  1. +14 −0 GSM.cpp
  2. +8 −2 GSM.h
  3. +91 −24 QuectelM10.cpp
  4. +9 −2 QuectelM10.h
  5. +8 −1 WideTextFinder.cpp
  6. +4 −0 WideTextFinder.h
  7. +51 −17 inetGSM.cpp
  8. +7 −2 inetGSM.h
View
14 GSM.cpp
@@ -35,6 +35,16 @@ int GSM::write(const char* str)
return 0;
}
+int GSM::isIP(const char* cadena)
+{
+ int i;
+ for (i=0; i<strlen(cadena); i++)
+ if (!(cadena[i]=='.' || ( cadena[i]>=48 && cadena[i] <=57)))
+ return 0;
+ return 1;
+}
+
+
int GSM::start(char* pin){return 0;};
int GSM::shutdown(){return 0;};
int GSM::sendSMS(const char* to, const char* msg){return 0;};
@@ -51,6 +61,10 @@ boolean GSM::availableSMS(){return false;};
boolean GSM::readSMS(char* msg, int msglength, char* number, int nlength){return false;};
boolean GSM::readCall(char* number, int nlength){return false;};
boolean GSM::call(char* number, unsigned int milliseconds){return false;};
+int GSM::setPIN(char *pin){return 0;};
+int GSM::getCCI(char* cci){return 0;};
+int GSM::getIMEI(char* imei){return 0;};
+
View
10 GSM.h
@@ -21,6 +21,8 @@ class GSM
NewSoftSerial _cell;
WideTextFinder _tf;
inline void setStatus(GSM_st_e status) { _status = status; }
+ virtual int setPIN(char *pin);
+ int isIP(const char* cadena);
public:
GSM();
@@ -29,6 +31,9 @@ class GSM
virtual int restart(char* pin=0);
virtual int start(char* pin=0);
virtual int shutdown();
+ virtual int getCCI(char* cci);
+ virtual int getIMEI(char* imei);
+
virtual int sendSMS(const char* to, const char* msg);
virtual boolean availableSMS();
virtual boolean readSMS(char* msg, int msglength, char* number, int nlength);
@@ -41,10 +46,11 @@ class GSM
virtual int connectTCPServer(int port);
virtual boolean connectedClient();
virtual int readCellData(int &mcc, int &mnc, long &lac, long &cellid);
- int write(uint8_t c);
- int write(const char* str);
+ virtual int write(uint8_t c);
+ virtual int write(const char* str);
virtual int write(const uint8_t* buffer, size_t sz);
virtual int read(char* result, int resultlength);
+
};
View
@@ -60,7 +60,7 @@ int QuectelM10::configandwait(char* pin)
_cell << "AT+CGREG?" << _BYTE(cr) << endl;
//Se espera la unsolicited response de registered to network.
- if (_tf.find("+CGREG: 0,1"))
+ if (_tf.find("+CGREG: 0,5")) // CHANGE!!!!
{
setStatus(READY);
@@ -182,8 +182,8 @@ int QuectelM10::attachGPRS(char* domain, char* dom1, char* dom2)
delay(200);
//Use domain name as the address to stablish a TCP session.
- // _cell << "AT+QIDNSIP=1" << _BYTE(cr) << endl;
- _cell << "AT+QIDNSIP=0" << _BYTE(cr) << endl;
+ _cell << "AT+QIDNSIP=1" << _BYTE(cr) << endl;
+ // _cell << "AT+QIDNSIP=0" << _BYTE(cr) << endl;
//Expect "OK". ATTENTION, RETURNS ERROR BUT IT DOES NOT MATTER!!!!
if(!_tf.find("OK")) ;//return 0;
@@ -210,13 +210,13 @@ int QuectelM10::attachGPRS(char* domain, char* dom1, char* dom2)
}
else
{
- setStatus(ATTACHED);
- delay(1000);
- return 1;
+ //setStatus(ATTACHED);
+ //delay(1000);
+ //return 1;
// In this case we dont know the modem mental position
- //setStatus(ERROR);
- //return 0;
+ setStatus(ERROR);
+ return 0;
}
}
@@ -392,7 +392,8 @@ int QuectelM10::read(char* result, int resultlength)
_tf.setTimeout(3);
// Not well. This way we read whatever comes in one second. If a CLOSED
// comes, we have spent a lot of time
- charget=_tf.getString("","",result, resultlength);
+ charget=_tf.getString("","",result, resultlength);
+
/*if(strtok(result, "CLOSED")) // whatever chain the Q10 returns...
{
// TODO: use strtok to delete from the chain everything from CLOSED
@@ -428,37 +429,30 @@ int QuectelM10::read(char* result, int resultlength)
return 1;
}
-boolean QuectelM10::availableSMS(){return false;};
boolean QuectelM10::readSMS(char* msg, int msglength, char* number, int nlength)
{
- int index;
+ long index;
if (getStatus()==IDLE)
return false;
- _tf.setTimeout(0);
+ _tf.setTimeout(_GSM_DATA_TOUT_);
_cell.flush();
- _cell << "AT+CMGL=\"REC UNREAD\",1" << endl;
+ _cell << "AT+CMGL=\"REC UNREAD\",1" << endl;
if(_tf.find("+CMGL: "))
{
- _tf.getString("", "\"", msg, msglength);
-
index=_tf.getValue();
- if(_tf.find("\"+"))
- {
- _tf.getString("", "\"", number, nlength);
- };
- if(_tf.find("\n"))
- {
- _tf.getString("", "\nOK", msg, msglength);
- };
+ _tf.getString("\"+", "\"", number, nlength);
+ _tf.getString("\n", "\nOK", msg, msglength);
_cell << "AT+CMGD=" << index << endl;
+ _tf.find("OK");
return true;
};
return false;
};
+
boolean QuectelM10::readCall(char* number, int nlength)
{
int index;
@@ -506,7 +500,6 @@ int QuectelM10::setPIN(char *pin)
//AT command to set PIN.
_cell << "AT+CPIN=" << pin << _BYTE(cr) << endl; // Establecemos el pin
- //_cell << "AT+CPIN=6104" << _BYTE(cr) << endl; // Establecemos el pin
//Expect "OK".
if(!_tf.find("OK"))
@@ -515,3 +508,77 @@ int QuectelM10::setPIN(char *pin)
return 1;
}
+int QuectelM10::write(uint8_t c)
+{
+ if ((getStatus() == TCPCONNECTEDCLIENT) ||(getStatus() == TCPCONNECTEDSERVER) )
+ return write(&c, 1);
+ else
+ return 0;
+}
+
+int QuectelM10::write(const char* str)
+{
+ if ((getStatus() == TCPCONNECTEDCLIENT) ||(getStatus() == TCPCONNECTEDSERVER) )
+ return write((const uint8_t*)str, strlen(str));
+ else
+ return 0;
+}
+
+int QuectelM10::changeNSIPmode(char mode) ///SYVV
+{
+ _tf.setTimeout(_TCP_CONNECTION_TOUT_);
+
+ //if (getStatus()!=ATTACHED)
+ // return 0;
+
+ _cell.flush();
+
+ _cell << "AT+QIDNSIP=" << mode << _BYTE(cr) << endl;
+
+ if(!_tf.find("OK")) return 0;
+
+ return 1;
+}
+
+int QuectelM10::getCCI(char *cci)
+{
+ //Status must be READY
+ if((getStatus() != READY))
+ return 2;
+
+ _tf.setTimeout(_GSM_DATA_TOUT_); //Timeout for expecting modem responses.
+
+ _cell.flush();
+
+ //AT command to get CCID.
+ _cell << "AT+QCCID" << _BYTE(cr) << endl; // Establecemos el pin
+
+ //Read response from modem
+ _tf.getString("AT+QCCID\r\r\r\n","\r\n",cci, 21);
+
+ //Expect "OK".
+ if(!_tf.find("OK"))
+ return 0;
+ else
+ return 1;
+}
+
+int QuectelM10::getIMEI(char *imei)
+{
+
+ _tf.setTimeout(_GSM_DATA_TOUT_); //Timeout for expecting modem responses.
+
+ _cell.flush();
+
+ //AT command to get IMEI.
+ _cell << "AT+GSN" << _BYTE(cr) << endl;
+
+ //Read response from modem
+ _tf.getString("AT+GSN\r\r\r\n","\r\n",imei, 15);
+
+ //Expect "OK".
+ if(!_tf.find("OK"))
+ return 0;
+ else
+ return 1;
+}
View
@@ -8,16 +8,20 @@ class QuectelM10 : public virtual GSM
private:
int configandwait(char* pin);
+ int setPIN(char *pin);
+ int changeNSIPmode(char);
public:
QuectelM10();
~QuectelM10();
int start(char* pin=0);
int restart(char* pin=0);
int shutdown();
+ int getCCI(char* cci);
+ int getIMEI(char* imei);
+
int sendSMS(const char* to, const char* msg);
int attachGPRS(char* domain, char* dom1, char* dom2);
- boolean availableSMS();
boolean readSMS(char* msg, int msglength, char* number, int nlength);
boolean readCall(char* number, int nlength);
boolean call(char* number, unsigned int milliseconds);
@@ -27,9 +31,12 @@ class QuectelM10 : public virtual GSM
int connectTCPServer(int port);
boolean connectedClient();
int write(const uint8_t* buffer, size_t sz);
+ int write(uint8_t c);
+ int write(const char* str);
+
int read(char* result, int resultlength);
int readCellData(int &mcc, int &mnc, long &lac, long &cellid);
- int setPIN(char *pin);
+
};
extern QuectelM10 gsm;
View
@@ -15,7 +15,8 @@
if (nSerialStream->available() > 0)
{
r=nSerialStream->read();
- Serial.print(r);
+ if(debug)
+ Serial.print(r);
return r;
}
}
@@ -30,6 +31,12 @@
nSerialStream(&stream)
{
this->timeout = timeout * 1000L;
+ debug=true;
+ }
+
+ void WideTextFinder::setDebug(boolean d)
+ {
+ debug=d;
}
// public methods
View
@@ -11,13 +11,17 @@ class WideTextFinder {
unsigned long timeout; // number of seconds to wait for the next char before aborting read
unsigned long startMillis; // used for timeout measurement
+ boolean debug;
char read(); // private function to read from the stream
public:
// constructor:
// default timeout is 5 seconds
WideTextFinder(NewSoftSerial &stream, int timeout = 5); // Ethernet constructor
+
+ // Manage debug
+ void setDebug(boolean d);
// find methods - these seek through the data but do not return anything
// they are useful to skip past unwanted data
Oops, something went wrong.

0 comments on commit 476c67a

Please sign in to comment.