Guest User

Untitled

a guest
Sep 5th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.61 KB | None | 0 0
  1. /*
  2. This is a Beta version.
  3. last modified 18/08/2012.
  4.  
  5. This library is based on one developed by Arduino Labs
  6. and it is modified to preserve the compability
  7. with the Arduino's product.
  8.  
  9. The library is modified to use the GSM Shield,
  10. developed by www.open-electronics.org
  11. (http://www.open-electronics.org/arduino-gsm-shield/)
  12. and based on SIM900 chip,
  13. with the same commands of Arduino Shield,
  14. based on QuectelM10 chip.
  15. */
  16.  
  17. #include "GSM.h"
  18. #include "WideTextFinder.h"
  19.  
  20. //De-comment this two lines below if you have the
  21. //first version of GSM GPRS Shield
  22. //#define _GSM_TXPIN_ 4
  23. //#define _GSM_RXPIN_ 5
  24.  
  25. //De-comment this two lines below if you have the
  26. //second version og GSM GPRS Shield
  27. #define _GSM_TXPIN_ 7
  28. #define _GSM_RXPIN_ 8
  29.  
  30.  
  31. #ifdef UNO
  32. GSM::GSM():_cell(_GSM_TXPIN_,_GSM_RXPIN_),_tf(_cell, 10),_status(IDLE){
  33. };
  34. #endif
  35. #ifdef MEGA
  36. GSM::GSM(){
  37. _cell.begin(9600);
  38. };
  39. #endif
  40.  
  41.  
  42. int GSM::begin(long baud_rate){
  43. #ifdef UNO
  44. if (baud_rate==115200){
  45. Serial.println("Don't use baudrate 115200 with Software Serial.\nAutomatically changed at 9600.");
  46. baud_rate=9600;
  47. }
  48. #endif
  49. int response=-1;
  50. int cont=0;
  51. boolean norep=true;
  52. boolean turnedON=false;
  53. SetCommLineStatus(CLS_ATCMD);
  54. _cell.begin(baud_rate);
  55. p_comm_buf = &comm_buf[0];
  56. setStatus(IDLE);
  57.  
  58. // if no-reply we turn to turn on the module
  59. for (cont=0; cont<3; cont++){
  60. if (AT_RESP_ERR_NO_RESP == SendATCmdWaitResp("AT", 500, 100, "OK", 5)&&!turnedON) { //check power
  61. // there is no response => turn on the module
  62. #ifdef DEBUG_ON
  63. Serial.println("DB:NO RESP");
  64. #endif
  65. // generate turn on pulse
  66. digitalWrite(GSM_ON, HIGH);
  67. delay(1200);
  68. digitalWrite(GSM_ON, LOW);
  69. delay(10000);
  70. WaitResp(1000, 1000);
  71. }
  72. else{
  73. #ifdef DEBUG_ON
  74. Serial.println("DB:ELSE");
  75. #endif
  76. WaitResp(1000, 1000);
  77. }
  78. }
  79.  
  80.  
  81. if (AT_RESP_OK == SendATCmdWaitResp("AT", 500, 100, "OK", 5)){
  82. #ifdef DEBUG_ON
  83. Serial.println(F("DB:CORRECT BR"));
  84. #endif
  85. turnedON=true;
  86. norep=false;
  87. }
  88.  
  89.  
  90. if (AT_RESP_ERR_DIF_RESP == SendATCmdWaitResp("AT", 500, 100, "OK", 5)&&!turnedON){ //check OK
  91. #ifdef DEBUG_ON
  92. Serial.println(F("DB:AUTO BAUD RATE"));
  93. #endif
  94. for (int i=0;i<8;i++){
  95. switch (i) {
  96. case 0:
  97. _cell.begin(1200);
  98. break;
  99.  
  100. case 1:
  101. _cell.begin(2400);
  102. break;
  103.  
  104. case 2:
  105. _cell.begin(4800);
  106. break;
  107.  
  108. case 3:
  109. _cell.begin(9600);
  110. break;
  111.  
  112. case 4:
  113. _cell.begin(19200);
  114. break;
  115.  
  116. case 5:
  117. _cell.begin(38400);
  118. break;
  119.  
  120. case 6:
  121. _cell.begin(57600);
  122. break;
  123.  
  124. case 7:
  125. _cell.begin(115200);
  126. break;
  127.  
  128. // if nothing else matches, do the default
  129. // default is optional
  130. }
  131.  
  132. delay(100);
  133.  
  134. #ifdef DEBUG_PRINT
  135. // parameter 0 - because module is off so it is not necessary
  136. // to send finish AT<CR> here
  137. DebugPrint("DEBUG: Stringa ", 0);
  138. DebugPrint(buff, 0);
  139. #endif
  140.  
  141.  
  142. if (AT_RESP_OK == SendATCmdWaitResp("AT", 500, 100, "OK", 5)){
  143. #ifdef DEBUG_ON
  144. Serial.println(F("DB:FOUND PREV BR"));
  145. #endif
  146. _cell.print(F("AT+IPR="));
  147. _cell.print(baud_rate);
  148. _cell.print("\r"); // send <CR>
  149. delay(500);
  150. _cell.begin(baud_rate);
  151. delay(100);
  152. if (AT_RESP_OK == SendATCmdWaitResp("AT", 500, 100, "OK", 5)){
  153. #ifdef DEBUG_ON
  154. Serial.println("DB:OK BR");
  155. #endif
  156. }
  157. turnedON=true;
  158. break;
  159. }
  160. #ifdef DEBUG_ON
  161. Serial.println("DB:NO BR");
  162. #endif
  163. }
  164. // communication line is not used yet = free
  165. SetCommLineStatus(CLS_FREE);
  166. // pointer is initialized to the first item of comm. buffer
  167. p_comm_buf = &comm_buf[0];
  168. }
  169.  
  170. if(norep==true&&!turnedON){
  171. Serial.println(F("Trying to force the baud-rate to 9600\n"));
  172. for (int i=0;i<8;i++){
  173. switch (i) {
  174. case 0:
  175. _cell.begin(1200);
  176. delay(1000);
  177. Serial.println(F("1200"));
  178. _cell.print(F("AT+IPR=9600\r"));
  179. delay(1000);
  180. _cell.begin(9600);
  181. delay(1000);
  182. SendATCmdWaitResp("AT", 500, 100, "OK", 5);
  183. delay(1000);
  184. WaitResp(1000,1000);
  185. break;
  186.  
  187. case 1:
  188. _cell.begin(2400);
  189. delay(1000);
  190. Serial.println(F("2400"));
  191. _cell.print(F("AT+IPR=9600\r"));
  192. delay(1000);
  193. _cell.begin(9600);
  194. delay(1000);
  195. SendATCmdWaitResp("AT", 500, 100, "OK", 5);
  196. delay(1000);
  197. WaitResp(1000,1000);
  198. break;
  199.  
  200. case 2:
  201. _cell.begin(4800);
  202. delay(1000);
  203. Serial.println(F("4800"));
  204. _cell.print(F("AT+IPR=9600\r"));
  205. delay(1000);
  206. _cell.begin(9600);
  207. delay(1000);
  208. SendATCmdWaitResp("AT", 500, 100, "OK", 5);
  209. delay(1000);
  210. WaitResp(1000,1000);
  211. break;
  212.  
  213. case 3:
  214. _cell.begin(9600);
  215. delay(1000);
  216. Serial.println(F("9600"));
  217. _cell.print(F("AT+IPR=9600\r"));
  218. delay(1000);
  219. _cell.begin(9600);
  220. delay(1000);
  221. SendATCmdWaitResp("AT", 500, 100, "OK", 5);
  222. delay(1000);
  223. WaitResp(1000,1000);
  224. break;
  225.  
  226. case 4:
  227. _cell.begin(19200);
  228. delay(1000);
  229. Serial.println(F("19200"));
  230. _cell.print(F("AT+IPR=9600\r"));
  231. delay(1000);
  232. _cell.begin(9600);
  233. delay(1000);
  234. SendATCmdWaitResp("AT", 500, 100, "OK", 5);
  235. delay(1000);
  236. WaitResp(1000,1000);
  237. break;
  238.  
  239. case 5:
  240. _cell.begin(38400);
  241. delay(1000);
  242. Serial.println(F("38400"));
  243. _cell.print(F("AT+IPR=9600\r"));
  244. delay(1000);
  245. _cell.begin(9600);
  246. delay(1000);
  247. SendATCmdWaitResp("AT", 500, 100, "OK", 5);
  248. delay(1000);
  249. WaitResp(1000,1000);
  250. break;
  251.  
  252. case 6:
  253. _cell.begin(57600);
  254. delay(1000);
  255. Serial.println(F("57600"));
  256. _cell.print(F("AT+IPR=9600\r"));
  257. delay(1000);
  258. _cell.begin(9600);
  259. delay(1000);
  260. SendATCmdWaitResp("AT", 500, 100, "OK", 5);
  261. delay(1000);
  262. WaitResp(1000,1000);
  263. break;
  264.  
  265. case 7:
  266. _cell.begin(115200);
  267. delay(1000);
  268. Serial.println(F("115200"));
  269. _cell.print(F("AT+IPR=9600\r"));
  270. delay(1000);
  271. _cell.begin(9600);
  272. delay(1000);
  273. SendATCmdWaitResp("AT", 500, 100, "OK", 5);
  274. delay(1000);
  275. WaitResp(1000,1000);
  276. break;
  277. }
  278. }
  279.  
  280. Serial.println(F("ERROR: SIM900 doesn't answer. Check power and serial pins in GSM.cpp"));
  281. digitalWrite(GSM_ON, HIGH);
  282. delay(1200);
  283. digitalWrite(GSM_ON, LOW);
  284. delay(10000);
  285. return 0;
  286. }
  287.  
  288. SetCommLineStatus(CLS_FREE);
  289.  
  290. if(turnedON){
  291. WaitResp(50, 50);
  292. InitParam(PARAM_SET_0);
  293. InitParam(PARAM_SET_1);//configure the module
  294. Echo(0); //enable AT echo
  295. setStatus(READY);
  296. return(1);
  297.  
  298. }
  299. else{
  300. //just to try to fix some problems with 115200 baudrate
  301. _cell.begin(115200);
  302. delay(1000);
  303. _cell.print(F("AT+IPR="));
  304. _cell.print(baud_rate);
  305. _cell.print("\r"); // send <CR>
  306. return(0);
  307. }
  308. }
  309.  
  310.  
  311. void GSM::InitParam(byte group){
  312. switch (group) {
  313. case PARAM_SET_0:
  314. // check comm line
  315. //if (CLS_FREE != GetCommLineStatus()) return;
  316.  
  317. SetCommLineStatus(CLS_ATCMD);
  318. // Reset to the factory settings
  319. SendATCmdWaitResp("AT&F", 1000, 50, "OK", 5);
  320. // switch off echo
  321. SendATCmdWaitResp("ATE0", 500, 50, "OK", 5);
  322. // setup fixed baud rate
  323. //SendATCmdWaitResp("AT+IPR=9600", 500, 50, "OK", 5);
  324. // setup mode
  325. //SendATCmdWaitResp("AT#SELINT=1", 500, 50, "OK", 5);
  326. // Switch ON User LED - just as signalization we are here
  327. //SendATCmdWaitResp("AT#GPIO=8,1,1", 500, 50, "OK", 5);
  328. // Sets GPIO9 as an input = user button
  329. //SendATCmdWaitResp("AT#GPIO=9,0,0", 500, 50, "OK", 5);
  330. // allow audio amplifier control
  331. //SendATCmdWaitResp("AT#GPIO=5,0,2", 500, 50, "OK", 5);
  332. // Switch OFF User LED- just as signalization we are finished
  333. //SendATCmdWaitResp("AT#GPIO=8,0,1", 500, 50, "OK", 5);
  334. SetCommLineStatus(CLS_FREE);
  335. break;
  336.  
  337. case PARAM_SET_1:
  338. // check comm line
  339. //if (CLS_FREE != GetCommLineStatus()) return;
  340. SetCommLineStatus(CLS_ATCMD);
  341. // Request calling line identification
  342. SendATCmdWaitResp(F("AT+CLIP=1"), 500, 50, "OK", 5);
  343. // Mobile Equipment Error Code
  344. SendATCmdWaitResp(F("AT+CMEE=0"), 500, 50, "OK", 5);
  345. // Echo canceller enabled
  346. //SendATCmdWaitResp("AT#SHFEC=1", 500, 50, "OK", 5);
  347. // Ringer tone select (0 to 32)
  348. //SendATCmdWaitResp("AT#SRS=26,0", 500, 50, "OK", 5);
  349. // Microphone gain (0 to 7) - response here sometimes takes
  350. // more than 500msec. so 1000msec. is more safety
  351. //SendATCmdWaitResp("AT#HFMICG=7", 1000, 50, "OK", 5);
  352. // set the SMS mode to text
  353. SendATCmdWaitResp(F("AT+CMGF=1"), 500, 50, "OK", 5);
  354. // Auto answer after first ring enabled
  355. // auto answer is not used
  356. //SendATCmdWaitResp("ATS0=1", 500, 50, "OK", 5);
  357. // select ringer path to handsfree
  358. //SendATCmdWaitResp("AT#SRP=1", 500, 50, "OK", 5);
  359. // select ringer sound level
  360. //SendATCmdWaitResp("AT+CRSL=2", 500, 50, "OK", 5);
  361. // we must release comm line because SetSpeakerVolume()
  362. // checks comm line if it is free
  363. SetCommLineStatus(CLS_FREE);
  364. // select speaker volume (0 to 14)
  365. //SetSpeakerVolume(9);
  366. // init SMS storage
  367. InitSMSMemory();
  368. // select phonebook memory storage
  369. SendATCmdWaitResp(F("AT+CPBS=\"SM\""), 1000, 50, "OK", 5);
  370. SendATCmdWaitResp(F("AT+CIPSHUT"), 500, 50, "SHUT OK", 5);
  371. break;
  372. }
  373. }
  374.  
  375. byte GSM::WaitResp(uint16_t start_comm_tmout, uint16_t max_interchar_tmout,
  376. char const *expected_resp_string)
  377. {
  378. byte status;
  379. byte ret_val;
  380.  
  381. RxInit(start_comm_tmout, max_interchar_tmout);
  382. // wait until response is not finished
  383. do {
  384. status = IsRxFinished();
  385. } while (status == RX_NOT_FINISHED);
  386.  
  387. if (status == RX_FINISHED) {
  388. // something was received but what was received?
  389. // ---------------------------------------------
  390.  
  391. if(IsStringReceived(expected_resp_string)) {
  392. // expected string was received
  393. // ----------------------------
  394. ret_val = RX_FINISHED_STR_RECV;
  395. }
  396. else {
  397. ret_val = RX_FINISHED_STR_NOT_RECV;
  398. }
  399. }
  400. else {
  401. // nothing was received
  402. // --------------------
  403. ret_val = RX_TMOUT_ERR;
  404. }
  405. return (ret_val);
  406. }
  407.  
  408.  
  409. /**********************************************************
  410. Method sends AT command and waits for response
  411.  
  412. return:
  413. AT_RESP_ERR_NO_RESP = -1, // no response received
  414. AT_RESP_ERR_DIF_RESP = 0, // response_string is different from the response
  415. AT_RESP_OK = 1, // response_string was included in the response
  416. **********************************************************/
  417. char GSM::SendATCmdWaitResp(char const *AT_cmd_string,
  418. uint16_t start_comm_tmout, uint16_t max_interchar_tmout,
  419. char const *response_string,
  420. byte no_of_attempts)
  421. {
  422. byte status;
  423. char ret_val = AT_RESP_ERR_NO_RESP;
  424. byte i;
  425.  
  426. for (i = 0; i < no_of_attempts; i++) {
  427. // delay 500 msec. before sending next repeated AT command
  428. // so if we have no_of_attempts=1 tmout will not occurred
  429. if (i > 0) delay(500);
  430.  
  431. _cell.println(AT_cmd_string);
  432. status = WaitResp(start_comm_tmout, max_interchar_tmout);
  433. if (status == RX_FINISHED) {
  434. // something was received but what was received?
  435. // ---------------------------------------------
  436. if(IsStringReceived(response_string)) {
  437. ret_val = AT_RESP_OK;
  438. break; // response is OK => finish
  439. }
  440. else ret_val = AT_RESP_ERR_DIF_RESP;
  441. }
  442. else {
  443. // nothing was received
  444. // --------------------
  445. ret_val = AT_RESP_ERR_NO_RESP;
  446. }
  447.  
  448. }
  449.  
  450. WaitResp(1000, 5000);
  451. return (ret_val);
  452. }
  453.  
  454.  
  455. /**********************************************************
  456. Method sends AT command and waits for response
  457.  
  458. return:
  459. AT_RESP_ERR_NO_RESP = -1, // no response received
  460. AT_RESP_ERR_DIF_RESP = 0, // response_string is different from the response
  461. AT_RESP_OK = 1, // response_string was included in the response
  462. **********************************************************/
  463. char GSM::SendATCmdWaitResp(const __FlashStringHelper *AT_cmd_string,
  464. uint16_t start_comm_tmout, uint16_t max_interchar_tmout,
  465. char const *response_string,
  466. byte no_of_attempts)
  467. {
  468. byte status;
  469. char ret_val = AT_RESP_ERR_NO_RESP;
  470. byte i;
  471.  
  472. for (i = 0; i < no_of_attempts; i++) {
  473. // delay 500 msec. before sending next repeated AT command
  474. // so if we have no_of_attempts=1 tmout will not occurred
  475. if (i > 0) delay(500);
  476.  
  477. _cell.println(AT_cmd_string);
  478. status = WaitResp(start_comm_tmout, max_interchar_tmout);
  479. if (status == RX_FINISHED) {
  480. // something was received but what was received?
  481. // ---------------------------------------------
  482. if(IsStringReceived(response_string)) {
  483. ret_val = AT_RESP_OK;
  484. break; // response is OK => finish
  485. }
  486. else ret_val = AT_RESP_ERR_DIF_RESP;
  487. }
  488. else {
  489. // nothing was received
  490. // --------------------
  491. ret_val = AT_RESP_ERR_NO_RESP;
  492. }
  493.  
  494. }
  495.  
  496. return (ret_val);
  497. }
  498.  
  499. byte GSM::WaitResp(uint16_t start_comm_tmout, uint16_t max_interchar_tmout)
  500. {
  501. byte status;
  502.  
  503. RxInit(start_comm_tmout, max_interchar_tmout);
  504. // wait until response is not finished
  505. do {
  506. status = IsRxFinished();
  507. } while (status == RX_NOT_FINISHED);
  508. return (status);
  509. }
  510.  
  511. byte GSM::IsRxFinished(void)
  512. {
  513. byte num_of_bytes;
  514. byte ret_val = RX_NOT_FINISHED; // default not finished
  515.  
  516. // Rx state machine
  517. // ----------------
  518.  
  519. if (rx_state == RX_NOT_STARTED) {
  520. // Reception is not started yet - check tmout
  521. if (!_cell.available()) {
  522. // still no character received => check timeout
  523. /*
  524. #ifdef DEBUG_GSMRX
  525.  
  526. DebugPrint("\r\nDEBUG: reception timeout", 0);
  527. Serial.print((unsigned long)(millis() - prev_time));
  528. DebugPrint("\r\nDEBUG: start_reception_tmout\r\n", 0);
  529. Serial.print(start_reception_tmout);
  530.  
  531.  
  532. #endif
  533. */
  534. if ((unsigned long)(millis() - prev_time) >= start_reception_tmout) {
  535. // timeout elapsed => GSM module didn't start with response
  536. // so communication is takes as finished
  537. /*
  538. #ifdef DEBUG_GSMRX
  539. DebugPrint("\r\nDEBUG: RECEPTION TIMEOUT", 0);
  540. #endif
  541. */
  542. comm_buf[comm_buf_len] = 0x00;
  543. ret_val = RX_TMOUT_ERR;
  544. }
  545. }
  546. else {
  547. // at least one character received => so init inter-character
  548. // counting process again and go to the next state
  549. prev_time = millis(); // init tmout for inter-character space
  550. rx_state = RX_ALREADY_STARTED;
  551. }
  552. }
  553.  
  554. if (rx_state == RX_ALREADY_STARTED) {
  555. // Reception already started
  556. // check new received bytes
  557. // only in case we have place in the buffer
  558. num_of_bytes = _cell.available();
  559. // if there are some received bytes postpone the timeout
  560. if (num_of_bytes) prev_time = millis();
  561.  
  562. // read all received bytes
  563. while (num_of_bytes) {
  564. num_of_bytes--;
  565. if (comm_buf_len < COMM_BUF_LEN) {
  566. // we have still place in the GSM internal comm. buffer =>
  567. // move available bytes from circular buffer
  568. // to the rx buffer
  569. *p_comm_buf = _cell.read();
  570.  
  571. p_comm_buf++;
  572. comm_buf_len++;
  573. comm_buf[comm_buf_len] = 0x00; // and finish currently received characters
  574. // so after each character we have
  575. // valid string finished by the 0x00
  576. }
  577. else {
  578. // comm buffer is full, other incoming characters
  579. // will be discarded
  580. // but despite of we have no place for other characters
  581. // we still must to wait until
  582. // inter-character tmout is reached
  583.  
  584. // so just readout character from circular RS232 buffer
  585. // to find out when communication id finished(no more characters
  586. // are received in inter-char timeout)
  587. _cell.read();
  588. }
  589. }
  590.  
  591. // finally check the inter-character timeout
  592. /*
  593. #ifdef DEBUG_GSMRX
  594.  
  595. DebugPrint("\r\nDEBUG: intercharacter", 0);
  596. < Serial.print((unsigned long)(millis() - prev_time));
  597. DebugPrint("\r\nDEBUG: interchar_tmout\r\n", 0);
  598. Serial.print(interchar_tmout);
  599.  
  600.  
  601. #endif
  602. */
  603. if ((unsigned long)(millis() - prev_time) >= interchar_tmout) {
  604. // timeout between received character was reached
  605. // reception is finished
  606. // ---------------------------------------------
  607.  
  608. /*
  609. #ifdef DEBUG_GSMRX
  610.  
  611. DebugPrint("\r\nDEBUG: OVER INTER TIMEOUT", 0);
  612. #endif
  613. */
  614. comm_buf[comm_buf_len] = 0x00; // for sure finish string again
  615. // but it is not necessary
  616. ret_val = RX_FINISHED;
  617. }
  618. }
  619.  
  620.  
  621. return (ret_val);
  622. }
  623.  
  624. /**********************************************************
  625. Method checks received bytes
  626.  
  627. compare_string - pointer to the string which should be find
  628.  
  629. return: 0 - string was NOT received
  630. 1 - string was received
  631. **********************************************************/
  632. byte GSM::IsStringReceived(char const *compare_string)
  633. {
  634. char *ch;
  635. byte ret_val = 0;
  636.  
  637. if(comm_buf_len) {
  638. /*
  639. #ifdef DEBUG_GSMRX
  640. DebugPrint("DEBUG: Compare the string: \r\n", 0);
  641. for (int i=0; i<comm_buf_len; i++){
  642. Serial.print(byte(comm_buf[i]));
  643. }
  644.  
  645. DebugPrint("\r\nDEBUG: with the string: \r\n", 0);
  646. Serial.print(compare_string);
  647. DebugPrint("\r\n", 0);
  648. #endif
  649. */
  650. #ifdef DEBUG_ON
  651. Serial.print("ATT: ");
  652. Serial.println(compare_string);
  653. Serial.print("RIC: ");
  654. Serial.println((char *)comm_buf);
  655. #endif
  656. ch = strstr((char *)comm_buf, compare_string);
  657. if (ch != NULL) {
  658. ret_val = 1;
  659. /*#ifdef DEBUG_PRINT
  660. DebugPrint("\r\nDEBUG: expected string was received\r\n", 0);
  661. #endif
  662. */
  663. }
  664. else
  665. {
  666.  
  667. /*#ifdef DEBUG_PRINT
  668. DebugPrint("\r\nDEBUG: expected string was NOT received\r\n", 0);
  669. #endif
  670. */
  671. }
  672. }
  673. else{
  674. #ifdef DEBUG_ON
  675. Serial.print("ATT: ");
  676. Serial.println(compare_string);
  677. Serial.print("RIC: NO STRING RCVD");
  678. #endif
  679. }
  680.  
  681. return (ret_val);
  682. }
  683.  
  684.  
  685. void GSM::RxInit(uint16_t start_comm_tmout, uint16_t max_interchar_tmout)
  686. {
  687. rx_state = RX_NOT_STARTED;
  688. start_reception_tmout = start_comm_tmout;
  689. interchar_tmout = max_interchar_tmout;
  690. prev_time = millis();
  691. comm_buf[0] = 0x00; // end of string
  692. p_comm_buf = &comm_buf[0];
  693. comm_buf_len = 0;
  694. _cell.flush(); // erase rx circular buffer
  695. }
  696.  
  697. void GSM::Echo(byte state)
  698. {
  699. if (state == 0 or state == 1)
  700. {
  701. SetCommLineStatus(CLS_ATCMD);
  702.  
  703. _cell.print("ATE");
  704. _cell.print((int)state);
  705. _cell.print("\r");
  706. delay(500);
  707. SetCommLineStatus(CLS_FREE);
  708. }
  709. }
  710.  
  711. char GSM::InitSMSMemory(void)
  712. {
  713. char ret_val = -1;
  714.  
  715. if (CLS_FREE != GetCommLineStatus()) return (ret_val);
  716. SetCommLineStatus(CLS_ATCMD);
  717. ret_val = 0; // not initialized yet
  718.  
  719. // Disable messages about new SMS from the GSM module
  720. SendATCmdWaitResp("AT+CNMI=2,0", 1000, 50, "OK", 2);
  721.  
  722. // send AT command to init memory for SMS in the SIM card
  723. // response:
  724. // +CPMS: <usedr>,<totalr>,<usedw>,<totalw>,<useds>,<totals>
  725. if (AT_RESP_OK == SendATCmdWaitResp("AT+CPMS=\"SM\",\"SM\",\"SM\"", 1000, 1000, "+CPMS:", 10)) {
  726. ret_val = 1;
  727. }
  728. else ret_val = 0;
  729.  
  730. SetCommLineStatus(CLS_FREE);
  731. return (ret_val);
  732. }
  733.  
  734. int GSM::isIP(const char* cadena)
  735. {
  736. int i;
  737. for (i=0; i<strlen(cadena); i++)
  738. if (!(cadena[i]=='.' || ( cadena[i]>=48 && cadena[i] <=57)))
  739. return 0;
  740. return 1;
  741. }
Add Comment
Please, Sign In to add comment