Examples - GNSS Mobile (simple)

Top  Previous  Next

//-----------------------------------------------------------------------------
// GNSS Mobile.vpl, created 2002-05-30 09:30
//
// Small application that shows how to obtain GNSS positions from the external 
// GNSS receiver on the RTCU product. The program will show in the debug window
// (typically in the simulator) the current distance and bearing to Logic IO in 
// Denmark. If an SMS text message is sent to the RTCU device, it will respond 
// back to the senders phone with the current distance/bearing to Logic IO
// 
// Please note that the LED1/2 indicator on the RTCU will be:
//   green if connected to Cellular net but NO valid GNSS position
//   red if GNSS position valid but NOT connected to Cellular net
//   orange (green and red)  if connected to Cellular net and valid GNSS position
//-----------------------------------------------------------------------------
INCLUDE rtcu.inc
 
VAR_OUTPUT
   cellularConnect   : BOOL; | Indicates that the Cellular is connected to a basestation (Green)
   gnssValid         : BOOL; | Indicates that a position fix has been obtained (Red)
END_VAR;
 
PROGRAM GNSS_Example;
VAR
   sms      : gsmIncomingSMS;
   gnss     : gpsFix;
   gc       : gpsDistanceX;
   str      : STRING;
   awaitFix : BOOL;
END_VAR;
   // Turn on power to the GNSS receiver
   gpsPower(power:=TRUE);
   // Turn on power to the Cellular module
   gsmPower(power:=TRUE);
BEGIN
   // Update function block
   sms();
   // Update GNSS data
   gnss();
   // If we got a valid fix from the GNSS
   IF gnss.mode > 1 THEN
      // Calculate distance and bearing to Logic IO in Denmark
      gc(latitude1:=55513078, longitude1:=9510530, latitude2:=gnss.latitude, longitude2:=gnss.longitude);
      // Build string with information   
      str := strFormat(format:="Distance to Logic IO=\4.\3 KM, bearing=\2 deg", v4:=gc.distance/1000, v3:=int(gc.distance mod 1000), v2:=gc.bearing);
      DebugMsg(message:=str);
   END_IF;
 
   // If we receive a SMS message, we want the next GNSS position that is valid
   IF sms.status>0 THEN
      awaitFix:=TRUE;
   END_IF;
   
   // If we are waiting for next valid GNSS position, and GNSS position is valid,
   IF awaitFix AND gnss.mode > 1 THEN
      awaitFix := FALSE;
      // Send an SMS with the position
      gsmSendSMS(phonenumber:=sms.phonenumber, message:=str);
   END_IF;
   
   // Indicate on LED (green part) if we are connected to a Cellular basestation
   cellularConnect := gsmConnected();
   // Indicate on LED (red part) if valid GNSS position
   gnssValid := gnss.mode > 1;
END;
 
END_PROGRAM;