/*@!Encoding:1252*/
includes
{
  
}

//
// Simulation of a Mini-Navigation
//
// Note: Only basic functionality for demonstration is simulated here.
//
variables
{
  // Application phase
  const byte kAppOff      = 0; // no power; no communication
  const byte kAppOn       = 1; // power on
  const byte kAppShutdown = 2; // power on; shutdown started
  byte  gAppPhase = kAppOff;

  // Property: CurrentPosition
  mstimer     tPosition;
  const dword kPositionCycle = 1300; // update cycle for changing position  
}

on start
{  
	// Init service signals  
  $MM::VECTOR::Navigation::Position::longitude = 1234;
  $MM::VECTOR::Navigation::Position::latitude  = 5678;
  $MM::VECTOR::Navigation::Position::altitude = 250;  
  
  AppInit();
}

long CheckNormalOperation()
{
  // Description:
  //   Checks if FBlock is able to process commands
  //   (Maybe used for power simulation later.)
  // Return:
  //   0: failed; 1: Ok

  return (kAppOff != gAppPhase);
}

on timer tPosition
{
  $Position::longitude += 10;
  $Position::latitude += 100;
  $Position::altitude = $Position::altitude - 1 + random(3);

  setTimer(tPosition, kPositionCycle);
}

void AppExit()
{
  // Called on final exit of the application.

  if(gAppPhase == kAppOff)
    return;

  // power off
  gAppPhase = kAppOff;

  cancelTimer(tPosition);
}

on preStop
{
  AppExit();
}

void AppInit()
{
  // Called on first start of the application.
  if(gAppPhase == kAppOn)
    return;

  // application has started now
  gAppPhase = kAppOn;
  
  // set the timer for reporting current position (we drive all the time)
  cancelTimer(tPosition);
  setTimer(tPosition, kPositionCycle);
}
