Increase PIR calibration delay time to 40 seconds.

Decrease Ringing duration time when siren in on.

Notify users (recipients) in one function.

Use missedCall function of SimpleGSM to call the user.

Refactoring of SimpleGSM to support call status handling.
parent b5a2bd4b
......@@ -94,7 +94,7 @@ SimpleGSM::sendSMS (const String phoneNumber, const String message)
this->print(F("\"\r"));
if (!this->responseIsReceived("\r\n> ", 4000))
if (!this->responseIsReceived("\r\n> ", 2000))
{
return false;
}
......@@ -119,23 +119,67 @@ SimpleGSM::startCall (const String phoneNumber)
}
bool
SimpleGSM::callRings(const unsigned long timeOut)
SimpleGSM::callIsDialing()
{
this->sendCallStatusCommand();
return this->responseIsReceived("+CLCC: 1,0,2,0,0", 500);
}
bool
SimpleGSM::callIsRinging()
{
this->sendCallStatusCommand();
return this->responseIsReceived("+CLCC: 1,0,3,0,0", 500);
}
void
SimpleGSM::waitOnCallDialing()
{
while (this->callIsDialing()) ;
}
void
SimpleGSM::waitOnCallRinging(const unsigned long duration)
{
const unsigned long previousMillis = millis();
while ((unsigned long) (millis() - previousMillis) < timeOut)
while ((unsigned long) (millis() - previousMillis) < duration)
{
this->print(F("AT+CLCC\r"));
if (!this->callIsRinging())
{
break;
}
}
}
bool
SimpleGSM::missedCall (const String phoneNumber, const unsigned long ringingDuration)
{
if (this->startCall(phoneNumber))
{
this->waitOnCallDialing();
if (this->responseIsReceived("+CLCC: 1,0,3,0,0", 300))
if (this->callIsRinging())
{
return true;
this->waitOnCallRinging(ringingDuration);
}
this->hangCall();
return true;
}
return false;
}
void
SimpleGSM::sendCallStatusCommand()
{
this->print(F("AT+CLCC\r"));
}
bool
SimpleGSM::hangCall ()
{
......
......@@ -18,9 +18,17 @@ class SimpleGSM : public SoftwareSerial
bool sendSMS (const String phoneNumber, const String message);
bool missedCall (const String phoneNumber, const unsigned long ringingDuration);
bool startCall (const String phoneNumber);
bool callRings (const unsigned long timeOut);
bool callIsDialing ();
bool callIsRinging ();
void waitOnCallDialing ();
void waitOnCallRinging (const unsigned long duration);
bool hangCall ();
......@@ -31,6 +39,8 @@ class SimpleGSM : public SoftwareSerial
bool setSMSMode (const byte mode);
void sendCallStatusCommand ();
bool responseIsReceived (char * const pattern, const long timeOut);
static char * OK_RESPONSE_FORMAT;
......
......@@ -21,18 +21,16 @@ const byte BUTTON_PIN = 4;
const byte SIREN_PIN = A0;
const byte LED_PIN = A2;
const unsigned long DELAY_TIME_OF_PIR_SENSOR_CALIBRATION = 30000; // 30 seconds
const unsigned long DELAY_TIME_OF_PIR_SENSOR_CALIBRATION = 40000; // 40 seconds
const unsigned long DELAY_TIME_OF_CRITICAL_SECTION = 15000; // 15 seconds
const unsigned long DELAY_TIME_WHILE_ENABLING_ALARM = 120000; // 2 minutes
const unsigned long DELAY_TIME_BEFORE_READING_SERIAL = 2000; // 2 seconds
const unsigned long DELAY_TIME_OF_RINGING_SIREN = 2400000; // 40 minutes
const unsigned long DELAY_TIME_OF_RINGING_SIREN = 900000; // 15 minutes
const unsigned long DELAY_TIME_OF_LCD_MESSAGE = 2000; // 2 seconds
const unsigned long DELAY_TIME_OF_LED_BLINKING = 2000; // 2 seconds
const unsigned long DELAY_TIME_OF_WAITING_CALL_TO_RING = 20000; // 20 seconds
const unsigned long DELAY_TIME_OF_CALL_RINGING_DURATION = 10000; // 10 seconds
const unsigned long DELAY_TIME_BEFORE_STARTING_NEXT_CALL = 5000; // 5 seconds
const byte NOTIFICATIONS_PER_RECIPIENT = 3;
const byte NOTIFICATIONS_PER_USER = 3;
const String SMS_MESSAGE = "Security";
......@@ -252,13 +250,9 @@ realThreatUpdateOperation ()
{
sirenOn();
printStringWithoutDelay(F("Sending SMSs"));
printStringWithoutDelay(F("Notifying Users"));
smsRecipients();
printStringWithoutDelay(F("Making calls"));
callRecipients();
notifyUsers();
printStringWithoutDelay(F("Waiting police"));
......@@ -603,43 +597,21 @@ rfidCodeExists (const String & rfidCode)
}
void
smsRecipients ()
notifyUsers ()
{
const byte numberOfMobiles = getSystemMobiles().size();
for (byte i = 0; i < NOTIFICATIONS_PER_RECIPIENT; i++)
{
for (byte j = 0; j < numberOfMobiles; j++)
{
const String mobile = getSystemMobiles().get(j);
getSystemGsm().sendSMS(mobile, SMS_MESSAGE);
}
}
}
SimpleGSM & gsm = getSystemGsm();
void
callRecipients ()
{
const byte numberOfMobiles = getSystemMobiles().size();
for (byte i = 0; i < NOTIFICATIONS_PER_RECIPIENT; i++)
for (byte i = 0; i < NOTIFICATIONS_PER_USER; i++)
{
for (byte j = 0; j < numberOfMobiles; j++)
{
const String mobile = getSystemMobiles().get(j);
if (getSystemGsm().startCall(mobile))
{
if (getSystemGsm().callRings(DELAY_TIME_OF_WAITING_CALL_TO_RING))
{
delay(DELAY_TIME_OF_CALL_RINGING_DURATION);
}
gsm.missedCall(mobile, DELAY_TIME_OF_CALL_RINGING_DURATION);
getSystemGsm().hangCall();
delay (DELAY_TIME_BEFORE_STARTING_NEXT_CALL);
}
gsm.sendSMS(mobile, SMS_MESSAGE);
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment