INCLUDE rtcu.inc
VAR_INPUT
Sensor_L : BOOL;
Sensor_H : BOOL;
Alarm_time : INT;
Doorcontact : BOOL R_EDGE;
Alarm_keyswitch: BOOL;
PhoneNo : STRING;
END_VAR;
VAR_OUTPUT
Out_Heater : BOOL;
Out_Ventilation: BOOL;
Lamp : BOOL:=ON;
Connected : BOOL;
OffHook : BOOL;
END_VAR;
VAR
timer : TON;
send_alarm : R_TRIG;
state : INT := 1;
sms : gsmIncomingSMS;
voicecall : gsmIncomingCall;
END_VAR;
FUNCTION TemperatureControl;
Out_Ventilation := Sensor_H;
Out_Heater := Sensor_L;
timer(trig:= Sensor_L OR Sensor_H);
send_alarm(trig:=timer.q);
IF send_alarm.q THEN
IF Sensor_L THEN
gsmSendSMS(phonenumber:=PhoneNo, message:="Temperature too low");
ELSIF Sensor_H THEN
gsmSendSMS(phonenumber:=PhoneNo, message:="Temperature too high");
END_IF;
END_IF;
END_FUNCTION;
FUNCTION SMSLamp;
VAR
tmpstr : string;
END_VAR;
IF sms.status > 0 THEN
tmpstr:=strRemoveSpaces(str:=sms.message);
IF strCompare(str1:=tmpstr, str2:="ON")=0 THEN
lamp:=ON;
ELSIF strCompare(str1:=tmpstr, str2:="OFF")=0 THEN
lamp:=OFF;
END_IF;
END_IF;
END_FUNCTION;
FUNCTION VoiceLamp;
VAR
key : INT;
END_VAR;
CASE state OF
1:
IF voicecall.status > 0 THEN
gsmAnswer();
state:=2;
END_IF;
2:
voiceTalk(message:="SelOnOff.wav");
key :=dtmfGetKey(timeout:=7000);
IF key=0 OR key=1 THEN
lamp:=BOOL(key);
state:=3;
ELSIF key <> -1 THEN
voiceTalk(message:="Illegal.wav");
END_IF;
3:
voiceTalk(message:="AllDone.wav");
gsmHangup();
state:=1;
END_CASE;
IF NOT gsmOffHook() THEN
state:=1;
END_IF;
END_FUNCTION;
FUNCTION BurglerAlarm;
VAR
j : INT;
END_VAR;
IF Alarm_keyswitch AND Doorcontact THEN
FOR j:=1 TO 3 DO
IF gsmMakeCall(phonenumber:=PhoneNo) THEN
voiceTalk(message:="Burglar.wav");
gsmHangup();
EXIT;
END_IF;
END_FOR;
END_IF;
END_FUNCTION;
PROGRAM greenhouse2;
timer(pt := Alarm_time*60*1000);
gsmPower(power := ON);
BEGIN
timer();
sms();
voicecall();
OffHook := gsmOffHook();
Connected := gsmConnected();
TemperatureControl();
SMSLamp();
VoiceLamp();
BurglerAlarm();
END;
END_PROGRAM;
|