Examples - Voice message

Top  Previous  Next

//----------------------------------------------------------------------------
// This program allows control of the 8 digital outputs by using
// voice response principle.
//----------------------------------------------------------------------------
INCLUDE rtcu.inc
 
// Next follows all the variables that can be configured via the configuration dialog
VAR_OUTPUT
  connected : BOOL; | Connected to GSM Basestation.
  offhook   : BOOL; | off-hook signal
  outputs   : ARRAY[1..8] OF BOOL; | Outputs we control
END_VAR;
 
VAR
  no     : INT;
  command : INT;
  state   : SINT := 1;
  incoming: gsmIncomingCall;
END_VAR;
 
PROGRAM SetOutput;
 
gsmPower(power:=ON);
 
BEGIN
  // Update Function block
  incoming();
 
  // Indicate if we are connected to a GSM Basestation
  connected := gsmConnected();
 
  CASE state OF
    1: // Waiting for incoming call:
        IF incoming.status > 0 THEN
          DebugMsg(message:="Incoming call, answering");
          gsmAnswer();
           state:=2;
        END_IF;
 
    2: // Select output number:
        voiceTalk(message:="SelOutNo.wav");
        no:=dtmfGetKey(timeout:=5000);
        IF no>=1 AND no<=8 THEN
           state:=3;
          DebugFmt(message:="Output number \1 selected", v1:=no);
        END_IF;
 
    3: // Select on/off:
        voiceTalk(message:="SelOnOff.wav");
        command:=dtmfGetKey(timeout:=5000);
        IF command=0 OR command=1 THEN
           outputs[no]:=BOOL(command);
          DebugFmt(message:="Output number \1 set to \2", v1:=no, v2:=command);
           state:=2;
        ELSIF command=10 THEN
           state:=2;
        END_IF;
  END_CASE;
 
  // Are we still "online":
  offhook := gsmOffHook();
 
  // if the user has terminated the connection we go back
  // to the initial state (waiting for call)
  IF NOT offhook THEN
     state:=1;
  END_IF;
END;
 
END_PROGRAM;