[136] | 1 | #include <GSM3ShieldV1VoiceProvider.h>
|
---|
| 2 | #include <Arduino.h>
|
---|
| 3 |
|
---|
| 4 | GSM3ShieldV1VoiceProvider::GSM3ShieldV1VoiceProvider()
|
---|
| 5 | {
|
---|
| 6 | phonelength=0;
|
---|
| 7 | theGSM3MobileVoiceProvider=this;
|
---|
| 8 | }
|
---|
| 9 |
|
---|
| 10 | void GSM3ShieldV1VoiceProvider::initialize()
|
---|
| 11 | {
|
---|
| 12 | theGSM3ShieldV1ModemCore.registerUMProvider(this);
|
---|
| 13 | }
|
---|
| 14 |
|
---|
| 15 | //Voice Call main function.
|
---|
| 16 | int GSM3ShieldV1VoiceProvider::voiceCall(const char* to)
|
---|
| 17 | {
|
---|
| 18 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("ATD"),false);
|
---|
| 19 | theGSM3ShieldV1ModemCore.print(to);
|
---|
| 20 | theGSM3ShieldV1ModemCore.print(";\r");
|
---|
| 21 | setvoiceCallStatus(CALLING);
|
---|
| 22 | return 1;
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | //Retrieve calling number main function.
|
---|
| 26 | int GSM3ShieldV1VoiceProvider::retrieveCallingNumber (char* buffer, int bufsize)
|
---|
| 27 | {
|
---|
| 28 | theGSM3ShieldV1ModemCore.setPhoneNumber(buffer);
|
---|
| 29 | phonelength = bufsize;
|
---|
| 30 | theGSM3ShieldV1ModemCore.setCommandError(0);
|
---|
| 31 | theGSM3ShieldV1ModemCore.setCommandCounter(1);
|
---|
| 32 | theGSM3ShieldV1ModemCore.openCommand(this,RETRIEVECALLINGNUMBER);
|
---|
| 33 | retrieveCallingNumberContinue();
|
---|
| 34 | return theGSM3ShieldV1ModemCore.getCommandError();
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | //Retrieve calling number Continue function.
|
---|
| 38 | void GSM3ShieldV1VoiceProvider::retrieveCallingNumberContinue()
|
---|
| 39 | {
|
---|
| 40 | // 1: AT+CLCC
|
---|
| 41 | // 2: Receive +CLCC: 1,1,4,0,0,"num",129,""
|
---|
| 42 | // This implementation really does not care much if the modem aswers trash to CMGL
|
---|
| 43 | bool resp;
|
---|
| 44 | //int msglength_aux;
|
---|
| 45 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) {
|
---|
| 46 | case 1:
|
---|
| 47 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+CLCC"));
|
---|
| 48 | theGSM3ShieldV1ModemCore.setCommandCounter(2);
|
---|
| 49 | break;
|
---|
| 50 | case 2:
|
---|
| 51 | if(parseCLCC(theGSM3ShieldV1ModemCore.getPhoneNumber(), phonelength))
|
---|
| 52 | {
|
---|
| 53 | theGSM3ShieldV1ModemCore.closeCommand(1);
|
---|
| 54 | }
|
---|
| 55 | break;
|
---|
| 56 | }
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | //CLCC parse.
|
---|
| 60 | bool GSM3ShieldV1VoiceProvider::parseCLCC(char* number, int nlength)
|
---|
| 61 | {
|
---|
| 62 | theGSM3ShieldV1ModemCore.theBuffer().extractSubstring("+CLCC: 1,1,4,0,0,\"","\"", number, nlength);
|
---|
| 63 | theGSM3ShieldV1ModemCore.theBuffer().flush();
|
---|
| 64 | return true;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | //Answer Call main function.
|
---|
| 68 | int GSM3ShieldV1VoiceProvider::answerCall()
|
---|
| 69 | {
|
---|
| 70 | theGSM3ShieldV1ModemCore.setCommandError(0);
|
---|
| 71 | theGSM3ShieldV1ModemCore.setCommandCounter(1);
|
---|
| 72 | theGSM3ShieldV1ModemCore.openCommand(this,ANSWERCALL);
|
---|
| 73 | answerCallContinue();
|
---|
| 74 | return theGSM3ShieldV1ModemCore.getCommandError();
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | //Answer Call continue function.
|
---|
| 78 | void GSM3ShieldV1VoiceProvider::answerCallContinue()
|
---|
| 79 | {
|
---|
| 80 | // 1: ATA
|
---|
| 81 | // 2: Waiting for OK
|
---|
| 82 |
|
---|
| 83 | // This implementation really does not care much if the modem aswers trash to CMGL
|
---|
| 84 | bool resp;
|
---|
| 85 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) {
|
---|
| 86 | case 1:
|
---|
| 87 | // ATA ;
|
---|
| 88 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("ATA"));
|
---|
| 89 | theGSM3ShieldV1ModemCore.setCommandCounter(2);
|
---|
| 90 | break;
|
---|
| 91 | case 2:
|
---|
| 92 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
|
---|
| 93 | {
|
---|
| 94 | setvoiceCallStatus(TALKING);
|
---|
| 95 | if (resp) theGSM3ShieldV1ModemCore.closeCommand(1);
|
---|
| 96 | else theGSM3ShieldV1ModemCore.closeCommand(3);
|
---|
| 97 | }
|
---|
| 98 | break;
|
---|
| 99 | }
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | //Hang Call main function.
|
---|
| 103 | int GSM3ShieldV1VoiceProvider::hangCall()
|
---|
| 104 | {
|
---|
| 105 | theGSM3ShieldV1ModemCore.setCommandError(0);
|
---|
| 106 | theGSM3ShieldV1ModemCore.setCommandCounter(1);
|
---|
| 107 | theGSM3ShieldV1ModemCore.openCommand(this,HANGCALL);
|
---|
| 108 | hangCallContinue();
|
---|
| 109 | return theGSM3ShieldV1ModemCore.getCommandError();
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | //Hang Call continue function.
|
---|
| 113 | void GSM3ShieldV1VoiceProvider::hangCallContinue()
|
---|
| 114 | {
|
---|
| 115 | // 1: ATH
|
---|
| 116 | // 2: Waiting for OK
|
---|
| 117 |
|
---|
| 118 | bool resp;
|
---|
| 119 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) {
|
---|
| 120 | case 1:
|
---|
| 121 | //ATH
|
---|
| 122 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("ATH"));
|
---|
| 123 | theGSM3ShieldV1ModemCore.setCommandCounter(2);
|
---|
| 124 | break;
|
---|
| 125 | case 2:
|
---|
| 126 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
|
---|
| 127 | {
|
---|
| 128 | setvoiceCallStatus(IDLE_CALL);
|
---|
| 129 | if (resp) theGSM3ShieldV1ModemCore.closeCommand(1);
|
---|
| 130 | else theGSM3ShieldV1ModemCore.closeCommand(3);
|
---|
| 131 | }
|
---|
| 132 | break;
|
---|
| 133 | }
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | //Response management.
|
---|
| 137 | void GSM3ShieldV1VoiceProvider::manageResponse(byte from, byte to)
|
---|
| 138 | {
|
---|
| 139 | switch(theGSM3ShieldV1ModemCore.getOngoingCommand())
|
---|
| 140 | {
|
---|
| 141 | case ANSWERCALL:
|
---|
| 142 | answerCallContinue();
|
---|
| 143 | break;
|
---|
| 144 | case HANGCALL:
|
---|
| 145 | hangCallContinue();
|
---|
| 146 | break;
|
---|
| 147 | case RETRIEVECALLINGNUMBER:
|
---|
| 148 | retrieveCallingNumberContinue();
|
---|
| 149 | break;
|
---|
| 150 |
|
---|
| 151 | }
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | //URC recognize.
|
---|
| 155 | bool GSM3ShieldV1VoiceProvider::recognizeUnsolicitedEvent(byte oldTail)
|
---|
| 156 | {
|
---|
| 157 |
|
---|
| 158 | int nlength;
|
---|
| 159 | char auxLocate [15];
|
---|
| 160 | //RING.
|
---|
| 161 | prepareAuxLocate(PSTR("RING"), auxLocate);
|
---|
| 162 | if(theGSM3ShieldV1ModemCore.theBuffer().locate(auxLocate))
|
---|
| 163 | {
|
---|
| 164 | // RING
|
---|
| 165 | setvoiceCallStatus(RECEIVINGCALL);
|
---|
| 166 | theGSM3ShieldV1ModemCore.theBuffer().flush();
|
---|
| 167 | return true;
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 | //CALL ACEPTED.
|
---|
| 171 | prepareAuxLocate(PSTR("+COLP:"), auxLocate);
|
---|
| 172 | if(theGSM3ShieldV1ModemCore.theBuffer().locate(auxLocate))
|
---|
| 173 | {
|
---|
| 174 | //DEBUG
|
---|
| 175 | //Serial.println("Call Accepted.");
|
---|
| 176 | setvoiceCallStatus(TALKING);
|
---|
| 177 | theGSM3ShieldV1ModemCore.theBuffer().flush();
|
---|
| 178 | return true;
|
---|
| 179 | }
|
---|
| 180 |
|
---|
| 181 | //NO CARRIER.
|
---|
| 182 | prepareAuxLocate(PSTR("NO CARRIER"), auxLocate);
|
---|
| 183 | if(theGSM3ShieldV1ModemCore.theBuffer().locate(auxLocate))
|
---|
| 184 | {
|
---|
| 185 | //DEBUG
|
---|
| 186 | //Serial.println("NO CARRIER received.");
|
---|
| 187 | setvoiceCallStatus(IDLE_CALL);
|
---|
| 188 | theGSM3ShieldV1ModemCore.theBuffer().flush();
|
---|
| 189 | return true;
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | //BUSY.
|
---|
| 193 | prepareAuxLocate(PSTR("BUSY"), auxLocate);
|
---|
| 194 | if(theGSM3ShieldV1ModemCore.theBuffer().locate(auxLocate))
|
---|
| 195 | {
|
---|
| 196 | //DEBUG
|
---|
| 197 | //Serial.println("BUSY received.");
|
---|
| 198 | setvoiceCallStatus(IDLE_CALL);
|
---|
| 199 | theGSM3ShieldV1ModemCore.theBuffer().flush();
|
---|
| 200 | return true;
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | //CALL RECEPTION.
|
---|
| 204 | prepareAuxLocate(PSTR("+CLIP:"), auxLocate);
|
---|
| 205 | if(theGSM3ShieldV1ModemCore.theBuffer().locate(auxLocate))
|
---|
| 206 | {
|
---|
| 207 | theGSM3ShieldV1ModemCore.theBuffer().flush();
|
---|
| 208 | setvoiceCallStatus(RECEIVINGCALL);
|
---|
| 209 | return true;
|
---|
| 210 | }
|
---|
| 211 |
|
---|
| 212 | return false;
|
---|
| 213 | }
|
---|
| 214 |
|
---|
| 215 |
|
---|