Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. #include <GSM.h>
  2.  
  3. // PIN Number
  4. #define PINNUMBER ""
  5.  
  6. // initialize the library instance
  7. GSM gsmAccess; // include a 'true' parameter for debug enabled
  8. GSMVoiceCall vcs;
  9.  
  10. char numtel[20]; // buffer for the incoming call
  11.  
  12. void setup()
  13. {
  14. // initialize serial communications
  15. Serial.begin(9600);
  16. Serial.println("Receive Voice Call");
  17.  
  18. // connection state
  19. boolean notConnected = true;
  20.  
  21. // Start GSM shield
  22. // If your SIM has PIN, pass it as a parameter of begin() in quotes
  23. while(notConnected)
  24. {
  25. if(gsmAccess.begin(PINNUMBER)==GSM_READY)
  26. notConnected = false;
  27. else
  28. {
  29. Serial.println("Not connected");
  30. delay(1000);
  31. }
  32. }
  33.  
  34. //Enable dtmf
  35. theGSM3ShieldV1ModemCore.genericCommand_rqc("AT+QTONEDET=1", true); // Send command
  36. delay(1000); // Wait for response
  37. bool resp;
  38. theGSM3ShieldV1ModemCore.genericParse_rsp(resp);
  39. if(resp){
  40. Serial.println("DTMF Enabled");
  41. }else{
  42. Serial.println("DTMF NOT Enabled");
  43. }
  44.  
  45.  
  46. // This makes sure the modem notifies correctly incoming events
  47. vcs.hangCall();
  48.  
  49. Serial.println("Waiting Call");
  50. }
  51.  
  52. void loop()
  53. {
  54. // Check the status of the voice call
  55. switch (vcs.getvoiceCallStatus())
  56. {
  57. case IDLE_CALL: // Nothing is happening
  58.  
  59. break;
  60.  
  61. case CALLING: // This should never happen, as we are not placing a call
  62.  
  63. Serial.println("CALLING");
  64. break;
  65.  
  66. case RECEIVINGCALL: // Yes! Someone is calling us
  67.  
  68. Serial.println("RECEIVING CALL");
  69.  
  70. // Retrieve the calling number
  71. vcs.retrieveCallingNumber(numtel, 20);
  72.  
  73. // Print the calling number
  74. Serial.print("Number:");
  75. Serial.println(numtel);
  76.  
  77. // Answer the call, establish the call
  78. vcs.answerCall();
  79. break;
  80.  
  81. case TALKING: // In this case the call would be established
  82.  
  83. Serial.println("TALKING. Enter line to interrupt.");
  84. uint8_t charToneSum = 0;
  85. const char* strToneSearch = "QTONEDET: ";
  86. uint8_t len = strlen(strToneSearch);
  87.  
  88. while(Serial.read()!='\n'){
  89. int toneNum = detectTone(&charToneSum , len, strToneSearch);
  90. if(toneNum != -1){
  91. charToneSum = 0;
  92. Serial.print("Tone detected:");Serial.println(toneNum);
  93. }
  94. delay(100);
  95. }
  96.  
  97. vcs.hangCall();
  98. Serial.println("HANG. Waiting Call.");
  99. break;
  100. }
  101. delay(1000);
  102. }
  103.  
  104. int detectTone(uint8_t* sum , uint8_t len, const char* strSearch){
  105. char c = theGSM3ShieldV1ModemCore.theBuffer().read();
  106. *sum = (c==strSearch[*sum]) ? *sum+1 : 0;
  107. if(*sum == len){
  108. char cc[2];
  109. cc[0] = (char)theGSM3ShieldV1ModemCore.theBuffer().read();
  110. cc[1] = (char)theGSM3ShieldV1ModemCore.theBuffer().read();
  111. int n;
  112. n = atoi(cc);
  113. return n -48;
  114. }
  115. return -1;
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement