Browse Source

Merge pull request #26 from AlexIII/master

crtp
v_master
Sara Damiano 5 years ago
committed by GitHub
parent
commit
7d6aba266c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 89 additions and 235 deletions
  1. +9
    -2
      examples/AllFunctions/AllFunctions.ino
  2. +0
    -2
      src/TinyGsmClientA6.h
  3. +1
    -29
      src/TinyGsmClientBG96.h
  4. +0
    -2
      src/TinyGsmClientESP8266.h
  5. +0
    -2
      src/TinyGsmClientM590.h
  6. +1
    -30
      src/TinyGsmClientM95.h
  7. +1
    -30
      src/TinyGsmClientMC60.h
  8. +1
    -33
      src/TinyGsmClientSIM5360.h
  9. +1
    -30
      src/TinyGsmClientSIM7000.h
  10. +1
    -33
      src/TinyGsmClientSIM7600.h
  11. +1
    -31
      src/TinyGsmClientSIM800.h
  12. +0
    -2
      src/TinyGsmClientSIM808.h
  13. +0
    -2
      src/TinyGsmClientSaraR4.h
  14. +0
    -2
      src/TinyGsmClientSequansMonarch.h
  15. +0
    -2
      src/TinyGsmClientUBLOX.h
  16. +0
    -3
      src/TinyGsmClientXBee.h
  17. +73
    -0
      src/TinyGsmCommon.h

+ 9
- 2
examples/AllFunctions/AllFunctions.ino View File

@ -239,8 +239,15 @@ void loop() {
DBG("SMS:", res ? "OK" : "fail"); DBG("SMS:", res ? "OK" : "fail");
// This is only supported on SIMxxx series // This is only supported on SIMxxx series
res = modem.sendSMS_UTF16(SMS_TARGET, u"Привіііт!", 9);
DBG("UTF16 SMS:", res ? "OK" : "fail");
res = modem.sendSMS_UTF8_begin(SMS_TARGET);
if(res) {
auto stream = modem.sendSMS_UTF8_stream();
stream.print(F("Привіііт! Print number: "));
stream.print(595);
res = modem.sendSMS_UTF8_end();
}
DBG("UTF8 SMS:", res ? "OK" : "fail");
#endif #endif
#if TINY_GSM_TEST_CALL && defined(CALL_TARGET) #if TINY_GSM_TEST_CALL && defined(CALL_TARGET)


+ 0
- 2
src/TinyGsmClientA6.h View File

@ -123,8 +123,6 @@ public:
memset(sockets, 0, sizeof(sockets)); memset(sockets, 0, sizeof(sockets));
} }
virtual ~TinyGsmA6() {}
/* /*
* Basic functions * Basic functions
*/ */


+ 1
- 29
src/TinyGsmClientBG96.h View File

@ -40,7 +40,7 @@ enum RegStatus {
}; };
class TinyGsmBG96
class TinyGsmBG96: public TinyGsmUTFSMS<TinyGsmBG96>
{ {
public: public:
@ -146,7 +146,6 @@ public:
{ {
memset(sockets, 0, sizeof(sockets)); memset(sockets, 0, sizeof(sockets));
} }
virtual ~TinyGsmBG96() {}
/* /*
* Basic functions * Basic functions
@ -416,33 +415,6 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK()
return waitResponse(60000L) == 1; return waitResponse(60000L) == 1;
} }
bool sendSMS_UTF16(const String& number, const void* text, size_t len) {
sendAT(GF("+CMGF=1"));
waitResponse();
sendAT(GF("+CSCS=\"HEX\""));
waitResponse();
sendAT(GF("+CSMP=17,167,0,8"));
waitResponse();
sendAT(GF("+CMGS=\""), number, GF("\""));
if (waitResponse(GF(">")) != 1) {
return false;
}
uint16_t* t = (uint16_t*)text;
for (size_t i=0; i<len; i++) {
uint8_t c = t[i] >> 8;
if (c < 0x10) { stream.print('0'); }
stream.print(c, HEX);
c = t[i] & 0xFF;
if (c < 0x10) { stream.print('0'); }
stream.print(c, HEX);
}
stream.write((char)0x1A);
stream.flush();
return waitResponse(60000L) == 1;
}
/* /*
* Location functions * Location functions


+ 0
- 2
src/TinyGsmClientESP8266.h View File

@ -141,8 +141,6 @@ public:
memset(sockets, 0, sizeof(sockets)); memset(sockets, 0, sizeof(sockets));
} }
virtual ~TinyGsmESP8266() {}
/* /*
* Basic functions * Basic functions
*/ */


+ 0
- 2
src/TinyGsmClientM590.h View File

@ -121,8 +121,6 @@ public:
memset(sockets, 0, sizeof(sockets)); memset(sockets, 0, sizeof(sockets));
} }
virtual ~TinyGsmM590() {}
/* /*
* Basic functions * Basic functions
*/ */


+ 1
- 30
src/TinyGsmClientM95.h View File

@ -40,7 +40,7 @@ enum RegStatus {
}; };
class TinyGsmM95
class TinyGsmM95: public TinyGsmUTFSMS<TinyGsmM95>
{ {
public: public:
@ -143,8 +143,6 @@ public:
memset(sockets, 0, sizeof(sockets)); memset(sockets, 0, sizeof(sockets));
} }
virtual ~TinyGsmM95() {}
/* /*
* Basic functions * Basic functions
*/ */
@ -479,33 +477,6 @@ TINY_GSM_MODEM_GET_GPRS_IP_CONNECTED()
return waitResponse(60000L) == 1; return waitResponse(60000L) == 1;
} }
bool sendSMS_UTF16(const String& number, const void* text, size_t len) {
sendAT(GF("+CMGF=1"));
waitResponse();
sendAT(GF("+CSCS=\"HEX\""));
waitResponse();
sendAT(GF("+CSMP=17,167,0,8"));
waitResponse();
sendAT(GF("+CMGS=\""), number, GF("\""));
if (waitResponse(GF(">")) != 1) {
return false;
}
uint16_t* t = (uint16_t*)text;
for (size_t i=0; i<len; i++) {
uint8_t c = t[i] >> 8;
if (c < 0x10) { stream.print('0'); }
stream.print(c, HEX);
c = t[i] & 0xFF;
if (c < 0x10) { stream.print('0'); }
stream.print(c, HEX);
}
stream.write((char)0x1A);
stream.flush();
return waitResponse(60000L) == 1;
}
/** Delete all SMS */ /** Delete all SMS */
bool deleteAllSMS() { bool deleteAllSMS() {
sendAT(GF("+QMGDA=6")); sendAT(GF("+QMGDA=6"));


+ 1
- 30
src/TinyGsmClientMC60.h View File

@ -44,7 +44,7 @@ enum RegStatus {
}; };
class TinyGsmMC60
class TinyGsmMC60: public TinyGsmUTFSMS<TinyGsmMC60>
{ {
public: public:
@ -147,8 +147,6 @@ public:
memset(sockets, 0, sizeof(sockets)); memset(sockets, 0, sizeof(sockets));
} }
virtual ~TinyGsmMC60() {}
/* /*
* Basic functions * Basic functions
*/ */
@ -460,33 +458,6 @@ TINY_GSM_MODEM_GET_GPRS_IP_CONNECTED()
return waitResponse(60000L) == 1; return waitResponse(60000L) == 1;
} }
bool sendSMS_UTF16(const String& number, const void* text, size_t len) {
sendAT(GF("+CMGF=1"));
waitResponse();
sendAT(GF("+CSCS=\"HEX\""));
waitResponse();
sendAT(GF("+CSMP=17,167,0,8"));
waitResponse();
sendAT(GF("+CMGS=\""), number, GF("\""));
if (waitResponse(GF(">")) != 1) {
return false;
}
uint16_t* t = (uint16_t*)text;
for (size_t i=0; i<len; i++) {
uint8_t c = t[i] >> 8;
if (c < 0x10) { stream.print('0'); }
stream.print(c, HEX);
c = t[i] & 0xFF;
if (c < 0x10) { stream.print('0'); }
stream.print(c, HEX);
}
stream.write((char)0x1A);
stream.flush();
return waitResponse(60000L) == 1;
}
/** Delete all SMS */ /** Delete all SMS */
bool deleteAllSMS() { bool deleteAllSMS() {
sendAT(GF("+QMGDA=6")); sendAT(GF("+QMGDA=6"));


+ 1
- 33
src/TinyGsmClientSIM5360.h View File

@ -45,7 +45,7 @@ enum TinyGSMDateTimeFormat {
DATE_DATE = 2 DATE_DATE = 2
}; };
class TinyGsmSim5360
class TinyGsmSim5360: public TinyGsmUTFSMS<TinyGsmSim5360>
{ {
public: public:
@ -130,8 +130,6 @@ public:
memset(sockets, 0, sizeof(sockets)); memset(sockets, 0, sizeof(sockets));
} }
virtual ~TinyGsmSim5360(){}
/* /*
* Basic functions * Basic functions
*/ */
@ -522,36 +520,6 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK()
return waitResponse(60000L) == 1; return waitResponse(60000L) == 1;
} }
bool sendSMS_UTF16(const String& number, const void* text, size_t len) {
// Select message format (1=text)
sendAT(GF("+CMGF=1"));
waitResponse();
// Select TE character set
sendAT(GF("+CSCS=\"HEX\""));
waitResponse();
// Set text mode parameters
sendAT(GF("+CSMP=17,167,0,8"));
waitResponse();
// Send the message
sendAT(GF("+CMGS=\""), number, GF("\""));
if (waitResponse(GF(">")) != 1) {
return false;
}
uint16_t* t = (uint16_t*)text;
for (size_t i=0; i<len; i++) {
uint8_t c = t[i] >> 8;
if (c < 0x10) { stream.print('0'); }
stream.print(c, HEX);
c = t[i] & 0xFF;
if (c < 0x10) { stream.print('0'); }
stream.print(c, HEX);
}
stream.write((char)0x1A);
stream.flush();
return waitResponse(60000L) == 1;
}
/* /*
* Location functions * Location functions


+ 1
- 30
src/TinyGsmClientSIM7000.h View File

@ -45,7 +45,7 @@ enum TinyGSMDateTimeFormat {
DATE_DATE = 2 DATE_DATE = 2
}; };
class TinyGsmSim7000
class TinyGsmSim7000: public TinyGsmUTFSMS<TinyGsmSim7000>
{ {
public: public:
@ -154,8 +154,6 @@ public:
memset(sockets, 0, sizeof(sockets)); memset(sockets, 0, sizeof(sockets));
} }
virtual ~TinyGsmSim7000() {}
/* /*
* Basic functions * Basic functions
*/ */
@ -564,33 +562,6 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK()
return waitResponse(60000L) == 1; return waitResponse(60000L) == 1;
} }
bool sendSMS_UTF16(const String& number, const void* text, size_t len) {
sendAT(GF("+CMGF=1"));
waitResponse();
sendAT(GF("+CSCS=\"HEX\""));
waitResponse();
sendAT(GF("+CSMP=17,167,0,8"));
waitResponse();
sendAT(GF("+CMGS=\""), number, GF("\""));
if (waitResponse(GF(">")) != 1) {
return false;
}
uint16_t* t = (uint16_t*)text;
for (size_t i=0; i<len; i++) {
uint8_t c = t[i] >> 8;
if (c < 0x10) { stream.print('0'); }
stream.print(c, HEX);
c = t[i] & 0xFF;
if (c < 0x10) { stream.print('0'); }
stream.print(c, HEX);
}
stream.write((char)0x1A);
stream.flush();
return waitResponse(60000L) == 1;
}
/* /*
* Location functions * Location functions


+ 1
- 33
src/TinyGsmClientSIM7600.h View File

@ -45,7 +45,7 @@ enum TinyGSMDateTimeFormat {
DATE_DATE = 2 DATE_DATE = 2
}; };
class TinyGsmSim7600
class TinyGsmSim7600: public TinyGsmUTFSMS<TinyGsmSim7600>
{ {
public: public:
@ -130,8 +130,6 @@ public:
memset(sockets, 0, sizeof(sockets)); memset(sockets, 0, sizeof(sockets));
} }
virtual ~TinyGsmSim7600(){}
/* /*
* Basic functions * Basic functions
*/ */
@ -498,36 +496,6 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK()
return waitResponse(60000L) == 1; return waitResponse(60000L) == 1;
} }
bool sendSMS_UTF16(const String& number, const void* text, size_t len) {
// Select message format (1=text)
sendAT(GF("+CMGF=1"));
waitResponse();
// Select TE character set
sendAT(GF("+CSCS=\"HEX\""));
waitResponse();
// Set text mode parameters
sendAT(GF("+CSMP=17,167,0,8"));
waitResponse();
// Send the message
sendAT(GF("+CMGS=\""), number, GF("\""));
if (waitResponse(GF(">")) != 1) {
return false;
}
uint16_t* t = (uint16_t*)text;
for (size_t i=0; i<len; i++) {
uint8_t c = t[i] >> 8;
if (c < 0x10) { stream.print('0'); }
stream.print(c, HEX);
c = t[i] & 0xFF;
if (c < 0x10) { stream.print('0'); }
stream.print(c, HEX);
}
stream.write((char)0x1A);
stream.flush();
return waitResponse(60000L) == 1;
}
/* /*
* Location functions * Location functions


+ 1
- 31
src/TinyGsmClientSIM800.h View File

@ -46,7 +46,7 @@ enum TinyGSMDateTimeFormat {
DATE_DATE = 2 DATE_DATE = 2
}; };
class TinyGsmSim800
class TinyGsmSim800 : public TinyGsmUTFSMS<TinyGsmSim800>
{ {
public: public:
@ -153,8 +153,6 @@ public:
memset(sockets, 0, sizeof(sockets)); memset(sockets, 0, sizeof(sockets));
} }
virtual ~TinyGsmSim800() {}
/* /*
* Basic functions * Basic functions
*/ */
@ -597,34 +595,6 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK()
return waitResponse(60000L) == 1; return waitResponse(60000L) == 1;
} }
bool sendSMS_UTF16(const String& number, const void* text, size_t len) {
sendAT(GF("+CMGF=1"));
waitResponse();
sendAT(GF("+CSCS=\"HEX\""));
waitResponse();
sendAT(GF("+CSMP=17,167,0,8"));
waitResponse();
sendAT(GF("+CMGS=\""), number, GF("\""));
if (waitResponse(GF(">")) != 1) {
return false;
}
uint16_t* t = (uint16_t*)text;
for (size_t i=0; i<len; i++) {
uint8_t c = t[i] >> 8;
if (c < 0x10) { stream.print('0'); }
stream.print(c, HEX);
c = t[i] & 0xFF;
if (c < 0x10) { stream.print('0'); }
stream.print(c, HEX);
}
stream.write((char)0x1A);
stream.flush();
return waitResponse(60000L) == 1;
}
/* /*
* Location functions * Location functions
*/ */


+ 0
- 2
src/TinyGsmClientSIM808.h View File

@ -22,8 +22,6 @@ public:
: TinyGsmSim800(stream) : TinyGsmSim800(stream)
{} {}
virtual ~TinyGsmSim808(){}
/* /*
* GPS location functions * GPS location functions
*/ */


+ 0
- 2
src/TinyGsmClientSaraR4.h View File

@ -202,8 +202,6 @@ public:
memset(sockets, 0, sizeof(sockets)); memset(sockets, 0, sizeof(sockets));
} }
virtual ~TinyGsmSaraR4(){}
/* /*
* Basic functions * Basic functions
*/ */


+ 0
- 2
src/TinyGsmClientSequansMonarch.h View File

@ -179,8 +179,6 @@ public:
memset(sockets, 0, sizeof(sockets)); memset(sockets, 0, sizeof(sockets));
} }
virtual ~TinyGsmSequansMonarch() {}
/* /*
* Basic functions * Basic functions
*/ */


+ 0
- 2
src/TinyGsmClientUBLOX.h View File

@ -164,8 +164,6 @@ public:
memset(sockets, 0, sizeof(sockets)); memset(sockets, 0, sizeof(sockets));
} }
virtual ~TinyGsmUBLOX() {}
/* /*
* Basic functions * Basic functions
*/ */


+ 0
- 3
src/TinyGsmClientXBee.h View File

@ -287,9 +287,6 @@ public:
inCommandMode = false; inCommandMode = false;
memset(sockets, 0, sizeof(sockets)); memset(sockets, 0, sizeof(sockets));
} }
virtual ~TinyGsmXBee() {}
/* /*
* Basic functions * Basic functions
*/ */


+ 73
- 0
src/TinyGsmCommon.h View File

@ -645,4 +645,77 @@ String TinyGsmDecodeHex16bit(String &instr) {
} }
//Common methods for UTF8/UTF16 SMS.
//Supported by: BG96, M95, MC60, SIM5360, SIM7000, SIM7600, SIM800
template<class T>
class TinyGsmUTFSMS {
public:
class UTF8Print : public Print {
public:
UTF8Print(Print& p) : p(p) {}
virtual size_t write(const uint8_t c) override {
if(prv < 0xC0) {
if(c < 0xC0) printHex(c);
prv = c;
} else {
uint16_t v = uint16_t(prv)<<8 | c;
v -= (v>>8 == 0xD0)? 0xCC80 : 0xCD40;
printHex(v);
prv = 0;
}
return 1;
}
private:
Print& p;
uint8_t prv = 0;
void printHex(const uint16_t v) {
uint8_t c = v >> 8;
if (c < 0x10) p.print('0');
p.print(c, HEX);
c = v & 0xFF;
if (c < 0x10) p.print('0');
p.print(c, HEX);
}
};
bool sendSMS_UTF8_begin(const char* const number) {
static_cast<T*>(this)->sendAT(GF("+CMGF=1"));
static_cast<T*>(this)->waitResponse();
static_cast<T*>(this)->sendAT(GF("+CSCS=\"HEX\""));
static_cast<T*>(this)->waitResponse();
static_cast<T*>(this)->sendAT(GF("+CSMP=17,167,0,8"));
static_cast<T*>(this)->waitResponse();
static_cast<T*>(this)->sendAT(GF("+CMGS=\""), number, GF("\""));
return static_cast<T*>(this)->waitResponse(GF(">")) == 1;
}
bool sendSMS_UTF8_end() {
static_cast<T*>(this)->stream.write((char)0x1A);
static_cast<T*>(this)->stream.flush();
return static_cast<T*>(this)->waitResponse(60000L) == 1;
}
UTF8Print sendSMS_UTF8_stream() {
return UTF8Print(static_cast<T*>(this)->stream);
}
bool sendSMS_UTF16(const char* const number, const void* text, size_t len) {
if (!sendSMS_UTF8_begin(number)) {
return false;
}
uint16_t* t = (uint16_t*)text;
for (size_t i=0; i<len; i++) {
uint8_t c = t[i] >> 8;
if (c < 0x10) { static_cast<T*>(this)->stream.print('0'); }
static_cast<T*>(this)->stream.print(c, HEX);
c = t[i] & 0xFF;
if (c < 0x10) { static_cast<T*>(this)->stream.print('0'); }
static_cast<T*>(this)->stream.print(c, HEX);
}
return sendSMS_UTF8_end();
}
};
#endif #endif

Loading…
Cancel
Save