Generate audible notification for network connection when resuming device from a suspend state

Version 1

    Verified Product Versions

    Wavelink Naurtech CETerm 5.7

    When a device is resuming from suspend, the network connection may not be available immediately. This script generates an audible notification for a successful network connection when a device resumes from a suspend.

     

    This sample script is split into various functions for clarity so the flow should be obvious. Here is a summary:

    When the device resumes from a suspended state, it triggers the global OnWakeup handler. This handler calls the function RFWakeupSoundStart which creates a timer. The reason for starting a timer is becasue we have no knowledge of how long the network initialization will take and become available for use. The timer handler RFWakeupSoundOnTimer is called asynchronously and it checks the network signal strength for availability. If found, it plays a WAV file by calling the funtion RFWakeupSoundPlay and then resets the timer. If the network signal strength is not detected, the timer is resumed and the process is iterated.

     

     

    /* RFSoundOnConnect */

     

    // Global control variables

    var RFWakeupSoundTimerID = 0;

    var RFWakeupSoundContinue = 0;

    var RFWakeupSoundInterval = 200;    // milliseconds

    var RFWakeupSoundCountMaximum = 50; // 50*200 = 10 seconds

    var RFWakeupSoundCount = 0;

     

     

    function OnWakeup()

    {

      // Start with wakeup event

      RFWakeupSoundStart();

    }

     

    // Function to start RF check

    function RFWakeupSoundStart()

    {

      if (!RFWakeupSoundContinue)

      {

        RFWakeupSoundContinue = 1;

        if (RFWakeupSoundTimerID != 0)

        {

          // Stop and clear any previous check

          CETerm.ClearTimeout( RFWakeupSoundTimerID );

          RFWakeupSoundTimerID = 0;

        }

        RFWakeupSoundCount = 0;

     

        // Schedule first RF check

        RFWakeupSoundTimerID = CETerm.SetTimeout( "RFWakeupSoundOnTimer();", RFWakeupSoundInterval );

      }

    }

     

     

    // Function to stop check (unused)

    function RFWakeupSoundStop()

    {

      if (RFWakeupSoundContinue)

      {

        RFWakeupSoundContinue = 0;

        if (RFWakeupSoundTimerID != 0)

        {

          CETerm.ClearTimeout( RFWakeupSoundTimerID );

          RFWakeupSoundTimerID = 0;

        }

      }

    }

     

     

    // Function to check RF and notify user

    function RFWakeupSoundOnTimer()

    {

      RFWakeupSoundTimerID = 0;

      RFWakeupSoundCount++;

     

     

      // Get and check info

      var rfStatus = CETerm.GetProperty( "device.rf.status" );

      //var rfStrength = CETerm.GetProperty( "device.rf.strength" );

     

     

      if (rfStatus > 0)

      {

        // RF detected

        // Delayed playsound, increase delay for WEP if needed

        CETerm.SetTimeout( "RFWakeupSoundPlay();", 100 );

        RFWakeupSoundContinue = 0;

      }

      else if (RFWakeupSoundCount > RFWakeupSoundCountMaximum)

      {

        // Failed to get RF, play different tone

        // Comment out next line if no failure message wanted.

        OS.Alert(" Failed to detect RF signal.  Return to coverage area." );

        RFWakeupSoundContinue = 0;

      }

     

     

      if (RFWakeupSoundContinue)

      {

        if (!(RFWakeupSoundCount % 5))

        {

          // Comment out next line if no "tick" sound wanted during check.

          CETerm.PlaySound( "MenuPop" );

        }

     

     

        // Schedule next RF check

        RFWakeupSoundTimerID = CETerm.SetTimeout( "RFWakeupSoundOnTimer();", RFWakeupSoundInterval );

      }

    }

     

     

    function RFWakeupSoundPlay()

    {

      // Select any .wav file on device for notification.

      CETerm.PlaySound( "infbeg" );

    }