void CallTask(uint32_t rtc) { uint8_t pdu2uniBuf[256]; uint16_t smsLen = 0; if(VoiceCallTask_GetPhase() == INCOMING_CALL) { if(atCmdCallParser.getIncomingNumber && locationSms.flag != SMS_NEW_MSG ) { addrSendToUserFlag = 1; atCmdCallParser.autoAnswer = 1; getAddrFlag = 1; askAddrCnt = 0; smsLen =sprintf((char *)pdu2uniBuf,"%s!\nhttp://maps.google.com/maps?q=%.6f,%.6f",smsCallReportLocation,lastGpsInfo.lat,lastGpsInfo.lon); smsLen = utf8s_to_ucs2s((int16_t *)locationAskSmsBuf,pdu2uniBuf); big2litel_endian((uint16_t *)locationAskSmsBuf,unilen((uint16_t *)locationAskSmsBuf)); smsLen *= 2; if(ComparePhoneNumber((char *)atCmdCallParser.incomingCallPhoneNo,(char *)sysCfg.userPhone) != NULL) { Sms_SendMsg(&locationSms,sysCfg.userPhone,(uint8_t *)locationAskSmsBuf,smsLen,SMS_PDU16_MODE,30000,3); } else return; } } }
/********************************************************** Method checks status of call(incoming or active) and makes authorization with specified SIM positions range phone_number: a pointer where the tel. number string of current call will be placed so the space for the phone number string must be reserved - see example first_authorized_pos: initial SIM phonebook position where the authorization process starts last_authorized_pos: last SIM phonebook position where the authorization process finishes Note(important): ================ In case first_authorized_pos=0 and also last_authorized_pos=0 the received incoming phone number is NOT authorized at all, so every incoming is considered as authorized (CALL_INCOM_VOICE_NOT_AUTH is returned) return: CALL_NONE - no call activity CALL_INCOM_VOICE_AUTH - incoming voice - authorized CALL_INCOM_VOICE_NOT_AUTH - incoming voice - not authorized CALL_ACTIVE_VOICE - active voice CALL_INCOM_DATA_AUTH - incoming data call - authorized CALL_INCOM_DATA_NOT_AUTH - incoming data call - not authorized CALL_ACTIVE_DATA - active data call CALL_NO_RESPONSE - no response to the AT command CALL_COMM_LINE_BUSY - comm line is not free **********************************************************/ byte GSM::CallStatusWithAuth(char *phone_number, byte first_authorized_pos, byte last_authorized_pos) { byte ret_val = CALL_NONE; byte search_phone_num = 0; byte i; byte status; char *p_char; char *p_char1; phone_number[0] = 0x00; // no phonr number so far if (CLS_FREE != GetCommLineStatus()) return (CALL_COMM_LINE_BUSY); SetCommLineStatus(CLS_ATCMD); Serial.println(F("AT+CLCC")); // 5 sec. for initial comm tmout // and max. 1500 msec. for inter character timeout RxInit(5000, 1500, 1, 1); // wait response is finished do { if (IsStringReceived("OK\r\n")) { // perfect - we have some response, but what: // there is either NO call: // <CR><LF>OK<CR><LF> // or there is at least 1 call // +CLCC: 1,1,4,0,0,"+420XXXXXXXXX",145<CR><LF> // <CR><LF>OK<CR><LF> status = RX_FINISHED; break; // so finish receiving immediately and let's go to // to check response } status = IsRxFinished(); } while (status == RX_NOT_FINISHED); // generate tmout 30msec. before next AT command delay(30); if (status == RX_FINISHED) { // something was received but what was received? // example: //+CLCC: 1,1,4,0,0,"+420XXXXXXXXX",145 // --------------------------------------------- if(IsStringReceived("+CLCC: 1,1,4,0,0")) { // incoming VOICE call - not authorized so far // ------------------------------------------- search_phone_num = 1; ret_val = CALL_INCOM_VOICE_NOT_AUTH; } else if(IsStringReceived("+CLCC: 1,1,4,1,0")) { // incoming DATA call - not authorized so far // ------------------------------------------ search_phone_num = 1; ret_val = CALL_INCOM_DATA_NOT_AUTH; } else if(IsStringReceived("+CLCC: 1,0,0,0,0")) { // active VOICE call - GSM is caller // ---------------------------------- search_phone_num = 1; ret_val = CALL_ACTIVE_VOICE; } else if(IsStringReceived("+CLCC: 1,1,0,0,0")) { // active VOICE call - GSM is listener // ----------------------------------- search_phone_num = 1; ret_val = CALL_ACTIVE_VOICE; } else if(IsStringReceived("+CLCC: 1,1,0,1,0")) { // active DATA call - GSM is listener // ---------------------------------- search_phone_num = 1; ret_val = CALL_ACTIVE_DATA; } else if(IsStringReceived("+CLCC:")){ // other string is not important for us - e.g. GSM module activate call // etc. // IMPORTANT - each +CLCC:xx response has also at the end // string <CR><LF>OK<CR><LF> ret_val = CALL_OTHERS; } else if(IsStringReceived("OK")){ // only "OK" => there is NO call activity // -------------------------------------- ret_val = CALL_NONE; } // now we will search phone num string if (search_phone_num) { // extract phone number string // --------------------------- p_char = strchr((char *)(comm_buf),'"'); p_char1 = p_char+1; // we are on the first phone number character p_char = strchr((char *)(p_char1),'"'); if (p_char != NULL) { *p_char = 0; // end of string strcpy(phone_number, (char *)(p_char1)); } if ( (ret_val == CALL_INCOM_VOICE_NOT_AUTH) || (ret_val == CALL_INCOM_DATA_NOT_AUTH)) { if ((first_authorized_pos == 0) && (last_authorized_pos == 0)) { // authorization is not required => it means authorization is OK // ------------------------------------------------------------- if (ret_val == CALL_INCOM_VOICE_NOT_AUTH) ret_val = CALL_INCOM_VOICE_AUTH; else ret_val = CALL_INCOM_DATA_AUTH; } else { // make authorization // ------------------ SetCommLineStatus(CLS_FREE); for (i = first_authorized_pos; i <= last_authorized_pos; i++) { if (ComparePhoneNumber(i, phone_number)) { // phone numbers are identical // authorization is OK // --------------------------- if (ret_val == CALL_INCOM_VOICE_NOT_AUTH) ret_val = CALL_INCOM_VOICE_AUTH; else ret_val = CALL_INCOM_DATA_AUTH; break; // and finish authorization } } } } } } else { // nothing was received (RX_TMOUT_ERR) // ----------------------------------- ret_val = CALL_NO_RESPONSE; } SetCommLineStatus(CLS_FREE); return (ret_val); }
void AlarmTask(uint32_t rtc) { uint16_t wchar; uint8_t smsLen; static uint32_t time; if(time != rtc) { time = rtc; if(ACC_IS_ON) accOffTime = 180; //3min else if(accOffTime) accOffTime--; } if(accOffTime) { alarmFlag &= ~CAR_ALARM_HOLD_IN_4SEC_FLAG; alarmFlag &= ~MICROWAVE_ALARM_FLAG; alarmFlag &= ~MILEAGE_REMIND_FLAG; alarmFlag &= ~ACC_OFF_3MIN_FLAG; alarmFlag &= ~SPEED_ALARM_FLAG; } else { /*Car Alarm*/ if(carAlarmHoldU22Sms.flag != SMS_NEW_MSG && carAlarmHoldU23Sms.flag != SMS_NEW_MSG && carAlarmHoldU24Sms.flag != SMS_NEW_MSG && alarmFlag & CAR_ALARM_HOLD_IN_4SEC_FLAG ) { alarmFlag &= ~CAR_ALARM_HOLD_IN_4SEC_FLAG; alarmAlarmSentTimes++; smsLen = ConverBig5_Unicode((uint16_t *)carAlarmHoldSmsBuf,smsChinese_CarAlarmWarning); sprintf((char *)pdu2uniBuf,"!\nhttp://maps.google.com/maps?q=%.8f,%.8f\n",lastGpsInfo.lat,lastGpsInfo.lon); smsLen += ConverASCII_Unicode(&carAlarmHoldSmsBuf[smsLen*2],pdu2uniBuf); smsLen *= 2; //sprintf((char *)&carAlarmHoldSmsBuf,"Car Alarm the status changed more than 4 second: http://maps.google.com/maps?q=%.8f,%.8f\n",lastGpsInfo.lat,lastGpsInfo.lon); Sms_SendMsg(&carAlarmHoldU22Sms,sysCfg.u22Phone,(uint8_t *)carAlarmHoldSmsBuf,smsLen,SMS_PDU_MODE,30000,3); if(ComparePhoneNumber((char *)sysCfg.u22Phone,(char *)sysCfg.u23Phone) == NULL) { Sms_SendMsg(&carAlarmHoldU23Sms,sysCfg.u23Phone,(uint8_t *)carAlarmHoldSmsBuf,smsLen,SMS_PDU_MODE,30000,3); VoiceCallTask_StartCall(sysCfg.u23Phone,14); } if(ComparePhoneNumber((char *)sysCfg.u22Phone,(char *)sysCfg.u24Phone) == NULL) Sms_SendMsg(&carAlarmHoldU24Sms,sysCfg.u24Phone,(uint8_t *)carAlarmHoldSmsBuf,smsLen,SMS_PDU_MODE,30000,3); } /*Car accident (G-Sensor more than 2G) */ /*Microwave detect Alarm*/ if(microwaveU22Sms.flag != SMS_NEW_MSG && microwaveU25Sms.flag != SMS_NEW_MSG && alarmFlag & MICROWAVE_ALARM_FLAG ) { alarmFlag &= ~MICROWAVE_ALARM_FLAG; smsLen = ConverBig5_Unicode((uint16_t *)microwaveSmsBuf,smsChinese_MicrowaveAlarmWarning); sprintf((char *)pdu2uniBuf,"!\nhttp://maps.google.com/maps?q=%.8f,%.8f\n",lastGpsInfo.lat,lastGpsInfo.lon); smsLen += ConverASCII_Unicode(µwaveSmsBuf[smsLen*2],pdu2uniBuf); smsLen *= 2; //sprintf((char *)µwaveSmsBuf,"Microwave: http://maps.google.com/maps?q=%.8f,%.8f\n",lastGpsInfo.lat,lastGpsInfo.lon); Sms_SendMsg(µwaveU22Sms,sysCfg.u22Phone,(uint8_t *)microwaveSmsBuf,smsLen,SMS_PDU_MODE,30000,3); if(ComparePhoneNumber((char *)sysCfg.u22Phone,(char *)sysCfg.u24Phone) == NULL) Sms_SendMsg(µwaveU25Sms,sysCfg.u25Phone,(uint8_t *)microwaveSmsBuf,smsLen,SMS_PDU_MODE,30000,3); VoiceCallTask_StartCall(sysCfg.u23Phone,14); } /*Inspection mileage Remind*/ if( mileageRemindU23Sms.flag != SMS_NEW_MSG && mileageRemindU36Sms.flag != SMS_NEW_MSG && alarmFlag & MILEAGE_REMIND_FLAG ) { alarmFlag &= ~MILEAGE_REMIND_FLAG; sprintf((char *)mileageRemindSmsBuf,"Mileage Remind: http://maps.google.com/maps?q=%.8f,%.8f\n",lastGpsInfo.lat,lastGpsInfo.lon); Sms_SendMsg(&mileageRemindU23Sms,sysCfg.u23Phone,(uint8_t *)mileageRemindSmsBuf,smsLen,SMS_PDU_MODE,30000,3); if(ComparePhoneNumber((char *)sysCfg.u23Phone,(char *)sysCfg.u36Phone) == NULL) Sms_SendMsg(&mileageRemindU36Sms,sysCfg.u36Phone,(uint8_t *)mileageRemindSmsBuf,smsLen,SMS_PDU_MODE,30000,3); } /*ACC OFF 3 minutes*/ if( accOffU23Sms.flag != SMS_NEW_MSG && accOffU30Sms.flag != SMS_NEW_MSG && accOffU31Sms.flag != SMS_NEW_MSG && accOffU36Sms.flag != SMS_NEW_MSG && alarmFlag & ACC_OFF_3MIN_FLAG ) { alarmFlag &= ~ACC_OFF_3MIN_FLAG; sprintf((char *)accOffSmsBuf,"ACC OFF: http://maps.google.com/maps?q=%.8f,%.8f\n",lastGpsInfo.lat,lastGpsInfo.lon); Sms_SendMsg(&accOffU23Sms,sysCfg.u23Phone,(uint8_t *)accOffSmsBuf,smsLen,SMS_PDU_MODE,30000,3); if(ComparePhoneNumber((char *)sysCfg.u23Phone,(char *)sysCfg.u30Phone) == NULL) Sms_SendMsg(&accOffU30Sms,sysCfg.u30Phone,(uint8_t *)accOffSmsBuf,smsLen,SMS_PDU_MODE,30000,3); if(ComparePhoneNumber((char *)sysCfg.u23Phone,(char *)sysCfg.u36Phone) == NULL) Sms_SendMsg(&accOffU31Sms,sysCfg.u31Phone,(uint8_t *)accOffSmsBuf,smsLen,SMS_PDU_MODE,30000,3); if(ComparePhoneNumber((char *)sysCfg.u23Phone,(char *)sysCfg.u36Phone) == NULL) Sms_SendMsg(&accOffU36Sms,sysCfg.u36Phone,(uint8_t *)accOffSmsBuf,smsLen,SMS_PDU_MODE,30000,3); } /*Speed Alarm*/ if( speedAlarmU23Sms.flag != SMS_NEW_MSG && speedAlarmU24Sms.flag != SMS_NEW_MSG && alarmFlag & SPEED_ALARM_FLAG ) { alarmFlag &= ~SPEED_ALARM_FLAG; sprintf((char *)speedAlarmSmsBuf,"Speed Alarm: http://maps.google.com/maps?q=%.8f,%.8f\n",lastGpsInfo.lat,lastGpsInfo.lon); Sms_SendMsg(&speedAlarmU23Sms,sysCfg.u23Phone,(uint8_t *)speedAlarmSmsBuf,smsLen,SMS_PDU_MODE,30000,3); if(ComparePhoneNumber((char *)sysCfg.u23Phone,(char *)sysCfg.u24Phone) == NULL) Sms_SendMsg(&speedAlarmU24Sms,sysCfg.u30Phone,(uint8_t *)speedAlarmSmsBuf,smsLen,SMS_PDU_MODE,30000,3); } } /*SOS Alarm (4second)*/ if(sosU26Sms.flag != SMS_NEW_MSG && sosU27Sms.flag != SMS_NEW_MSG && sosU28Sms.flag != SMS_NEW_MSG && alarmFlag & SOS_ALARM_FLAG ) { alarmFlag &= ~SOS_ALARM_FLAG; sosAlarmSentTimes++; smsLen = ConverBig5_Unicode((uint16_t *)sosSmsBuf,smsChinese_HelpHelp); sprintf((char *)pdu2uniBuf,"!\nhttp://maps.google.com/maps?q=%.8f,%.8f\n",lastGpsInfo.lat,lastGpsInfo.lon); smsLen += ConverASCII_Unicode(&sosSmsBuf[smsLen*2],pdu2uniBuf); Sms_SendMsg(&sosU26Sms,sysCfg.u26Phone,(uint8_t *)sosSmsBuf,smsLen*2,SMS_PDU_MODE,30000,3); if(ComparePhoneNumber((char *)sysCfg.u26Phone,(char *)sysCfg.u27Phone) == NULL) Sms_SendMsg(&sosU27Sms,sysCfg.u27Phone,(uint8_t *)sosSmsBuf,smsLen*2,SMS_PDU_MODE,30000,3); if(ComparePhoneNumber((char *)sysCfg.u26Phone,(char *)sysCfg.u28Phone) == NULL) Sms_SendMsg(&sosU28Sms,sysCfg.u28Phone,(uint8_t *)sosSmsBuf,smsLen*2,SMS_PDU_MODE,30000,3); } /*Daily Report*/ if( dailyReportU23Sms.flag != SMS_NEW_MSG && dailyReportU30Sms.flag != SMS_NEW_MSG && dailyReportU31Sms.flag != SMS_NEW_MSG && dailyReportU36Sms.flag != SMS_NEW_MSG && alarmFlag & DAILY_ALARM_FLAG ) { alarmFlag &= ~DAILY_ALARM_FLAG; sprintf((char *)dailyReportSmsBuf,"Daily Report: http://maps.google.com/maps?q=%.8f,%.8f\n",lastGpsInfo.lat,lastGpsInfo.lon); Sms_SendMsg(&dailyReportU23Sms,sysCfg.u23Phone,(uint8_t *)dailyReportSmsBuf,smsLen,SMS_PDU_MODE,30000,3); if(ComparePhoneNumber((char *)sysCfg.u23Phone,(char *)sysCfg.u30Phone) == NULL) Sms_SendMsg(&dailyReportU30Sms,sysCfg.u30Phone,(uint8_t *)dailyReportSmsBuf,smsLen,SMS_PDU_MODE,30000,3); if(ComparePhoneNumber((char *)sysCfg.u23Phone,(char *)sysCfg.u31Phone) == NULL) Sms_SendMsg(&dailyReportU31Sms,sysCfg.u31Phone,(uint8_t *)dailyReportSmsBuf,smsLen,SMS_PDU_MODE,30000,3); if(ComparePhoneNumber((char *)sysCfg.u23Phone,(char *)sysCfg.u36Phone) == NULL) Sms_SendMsg(&dailyReportU36Sms,sysCfg.u36Phone,(uint8_t *)dailyReportSmsBuf,smsLen,SMS_PDU_MODE,30000,3); } /*Inspection Time Remind*/ if( timeRemindU23Sms.flag != SMS_NEW_MSG && timeRemindU36Sms.flag != SMS_NEW_MSG && alarmFlag & TIME_REMIND_FLAG ) { alarmFlag &= ~TIME_REMIND_FLAG; sprintf((char *)batterySmsBuf,"Time Remind: http://maps.google.com/maps?q=%.8f,%.8f\n",lastGpsInfo.lat,lastGpsInfo.lon); Sms_SendMsg(&timeRemindU23Sms,sysCfg.u23Phone,(uint8_t *)timeRemindSmsBuf,smsLen,SMS_PDU_MODE,30000,3); if(ComparePhoneNumber((char *)sysCfg.u23Phone,(char *)sysCfg.u36Phone) == NULL) Sms_SendMsg(&timeRemindU36Sms,sysCfg.u36Phone,(uint8_t *)timeRemindSmsBuf,smsLen,SMS_PDU_MODE,30000,3); } /*Car Battery Low Alarm (10.5V)*/ if(ADC1_10_Value < 9.5 && ADC_Updated && powerU23Sms.flag != SMS_NEW_MSG && powerU24Sms.flag != SMS_NEW_MSG && ((alarmFlag & POWER_ALARM_FLAG) == 0) ) { alarmFlag |= POWER_ALARM_FLAG; smsLen = ConverBig5_Unicode((uint16_t *)powerSmsBuf,smsChinese_LowPowerPleaseCheckBattery); sprintf((char *)pdu2uniBuf,"!\nhttp://maps.google.com/maps?q=%.8f,%.8f\n",lastGpsInfo.lat,lastGpsInfo.lon); smsLen += ConverASCII_Unicode(&powerSmsBuf[smsLen*2],pdu2uniBuf); smsLen *= 2; //sprintf((char *)&powerSmsBuf,"Low power: http://maps.google.com/maps?q=%.8f,%.8f\n",lastGpsInfo.lat,lastGpsInfo.lon); Sms_SendMsg(&powerU23Sms,sysCfg.u23Phone,(uint8_t *)powerSmsBuf,smsLen,SMS_PDU_MODE,30000,3); if(ComparePhoneNumber((char *)sysCfg.u23Phone,(char *)sysCfg.u24Phone) == NULL) Sms_SendMsg(&powerU24Sms,sysCfg.u24Phone,(uint8_t *)powerSmsBuf,smsLen,SMS_PDU_MODE,30000,3); } else if(ADC1_10_Value > 11.0 && ADC_Updated) { alarmFlag &= ~POWER_ALARM_FLAG; } /*internal Backup Battery Low Alarm (3.6V)*/ if(ADC1_11_Value < 3.6 && ADC_Updated && batteryU23Sms.flag != SMS_NEW_MSG && batteryU24Sms.flag != SMS_NEW_MSG && ((alarmFlag & BATTERY_ALARM_FLAG) == 0) ) { alarmFlag |= BATTERY_ALARM_FLAG; smsLen = ConverBig5_Unicode((uint16_t *)batterySmsBuf,smsChinese_BackupBatteryLowPower); sprintf((char *)pdu2uniBuf,"!\nhttp://maps.google.com/maps?q=%.8f,%.8f\n",lastGpsInfo.lat,lastGpsInfo.lon); smsLen += ConverASCII_Unicode(&batterySmsBuf[smsLen*2],pdu2uniBuf); smsLen *= 2; //sprintf((char *)&batterySmsBuf,"Battery Low: http://maps.google.com/maps?q=%.8f,%.8f\n",lastGpsInfo.lat,lastGpsInfo.lon); Sms_SendMsg(&batteryU23Sms,sysCfg.u23Phone,(uint8_t *)batterySmsBuf,smsLen,SMS_PDU_MODE,30000,3); Sms_SendMsg(&batteryU24Sms,sysCfg.u24Phone,(uint8_t *)batterySmsBuf,smsLen,SMS_PDU_MODE,30000,3); } else if(ADC1_11_Value >= 3.7 && ADC_Updated) { alarmFlag &= ~BATTERY_ALARM_FLAG; } }