INCLUDE rtcu.inc
VAR
navMsgAck : navMessageReplyReceive;
navMsg : navMessageReceive;
navMsgStatus : navMessageStatusReceive;
navETA : navETAReceive;
navStop : navStopReceive;
navUserID : navUserIDReceive;
navUserStatus : navUserStatusReceive;
nmpButtonRec : nmpButtonPressedReceive;
updProg : nmpUpdateProgressReceive;
gps : gpsFix;
mdtInfo : mdtProfile;
driverInVehicle: BOOL;
END_VAR;
FUNCTION setupNMP : INT;
VAR
rc:INT;
END_VAR;
rc := nmpButtonsDefine(count:=2);
IF rc <> 0 THEN
DebugFmt(message:="Failed to define NMP buttons (nmpButtonsDefine=\1)", v1:=rc);
setupNMP := rc;
RETURN;
END_IF;
rc := nmpButtonCreate(id := 1, weight:= 2, text := "Panic!", visible := TRUE,
enable := TRUE, color := nmpRGBToDint(r:= 16#FF, g := 16#00, b := 16#00));
IF(rc <> 0 ) THEN
DebugFmt(message:="Failed to create panic button (nmpButtonCreate=\1)", v1:=rc);
setupNMP := rc;
RETURN;
END_IF;
IF driverInVehicle THEN
rc := nmpButtonCreate(id := 2, weight:= 3, text := "Exit vehicle", visible := TRUE,
enable := TRUE, color := nmpRGBToDint(r:= 16#66, g := 16#FF, b := 16#66));
ELSE
rc := nmpButtonCreate(id := 2, weight:= 3, text := "Enter vehicle", visible := TRUE,
enable := TRUE, color := nmpRGBToDint(r:= 16#66, g := 16#FF, b := 16#66));
END_IF;
IF(rc <> 0 ) THEN
DebugFmt(message:="Failed to create enter/exit button (nmpButtonCreate=\1)", v1:=rc);
setupNMP := rc;
RETURN;
END_IF;
rc := mdtPower(power := ON);
IF(rc = 0) THEN
DebugMsg(message:="mdt powered on");
mdtInfo();
IF mdtInfo.type > 0 THEN
DebugMsg(message:="MDT connected!");
DebugFmt(message:=" Type=\1",v1:=mdtInfo.type);
DebugFmt(message:=" Ver= \1",v1:=mdtInfo.version);
DebugFmt(message:=" MaxX=\1",v1:=mdtInfo.pos_max_x);
DebugFmt(message:=" MaxY=\1",v1:=mdtInfo.pos_max_y);
END_IF;
ELSE
DebugFmt(message:="Failed to power MDT on (mdtPower=\1)", v1:=rc);
END_IF;
setupNMP:= rc;
END_FUNCTION;
THREAD_BLOCK navMonitor;
VAR
event : INT := 0;
rc : INT;
END_VAR;
WHILE event <> -1 DO
event := navWaitEvent(timeout := -1);
CASE event OF
1:
navMsgAck();
DebugMsg(message := "MON: message reply received");
DebugFmt(message := "MON: -ID=\1", v1 := navMsgAck.ID);
DebugFmt(message := "MON: -reply=\1", v1 := navMsgAck.reply);
2:
navMsg();
DebugMsg(message := "MON: message received");
DebugMsg(message := "MON: -text=" + navMsg.message);
3:
navMsgStatus();
DebugMsg(message := "MON: message status received");
DebugFmt(message := "MON: -ID=\1", v1 := navMsgStatus.ID);
CASE navMsgStatus.status OF
1: DebugMsg(message := "MON: -status=Unread");
2: DebugMsg(message := "MON: -status=Read");
3: DebugMsg(message := "MON: -status=Deleted/Not found");
END_CASE;
4:
navETA();
DebugMsg(message := "MON: ETA received");
DebugFmt(message := "MON: -stop=\1", v1 := navETA.id);
DebugFmt(message := "MON: -distance=\4", v4 := navETA.distance);
DebugFmt(message := "MON: -latitude=\4", v4 := navETA.latitude);
DebugFmt(message := "MON: -longitude=\4", v4 := navETA.longitude);
5:
navStop();
DebugMsg(message := "MON: stop status received");
DebugFmt(message := "MON: -ID=\1", v1 := navStop.ID);
DebugFmt(message := "MON: -index=\1", v1 := navStop.index);
CASE navStop.status OF
1: DebugMsg(message := "MON: -status=Active");
2: DebugMsg(message := "MON: -status=Done");
3: DebugMsg(message := "MON: -status=Inactive - Unread");
4: DebugMsg(message := "MON: -status=Inactive - Read");
5: DebugMsg(message := "MON: -status=Deleted/Not found");
END_CASE;
6:
navUserID();
DebugMsg(message := "MON: user ID received");
DebugMsg(message := "MON: -user=" + navUserID.user);
7:
navUserStatus();
DebugMsg(message := "MON: user status received");
DebugFmt(message := "MON: -status=\1", v1 := navUserStatus.status);
10:
updProg();
IF updProg.ready THEN
DebugMsg(message := "*** Update progress received ***");
DebugFmt(message := "-status=\1", v1 := updProg.status);
DebugFmt(message := "-progress=\1", v1 := updProg.progress);
IF updProg.status = 0 THEN
DebugMsg(message:="Update transferred to NMP");
ELSIF updProg.status = 2 THEN
DebugMsg(message:="Update ready to install");
ELSIF updProg.status < 0 THEN
DebugMsg(message:="Failed to transfer update");
END_IF;
END_IF;
11:
nmpButtonRec();
IF nmpButtonRec.ready THEN
DebugMsg(message := "*** Button Pressed ***");
DebugFmt(message := "-button=\1", v1 := nmpButtonRec.id);
CASE nmpButtonRec.id OF
1:
rc:=nmpButtonFlash(id:=1,flash:=ON,duration:=30,period:=250,
color := nmpRGBToDint(r:=16#FF, g:=16#FF, b:=16#FF));
DebugMsg(message:="!! ALERT !!");
2:
driverInVehicle := NOT driverInVehicle;
IF driverInVehicle THEN
DebugMsg(message:="Driver entered vehicle");
rc := nmpButtonText(id := 2, text := "Exit vehicle");
ELSE
DebugMsg(message:="Driver exited vehicle");
rc := nmpButtonText(id := 2, text := "Enter vehicle");
END_IF;
END_CASE;
END_IF;
129:
DebugMsg(message := "MON: refresh of quick messages received, sending
defaults");
navMessageQuickDefine(id := 1, text := "I have arrived at the destination");
navMessageQuickDefine(id := 2, text := "There are no persons to receive
the packages at destination");
130:
DebugMsg(message := "MON: refresh of message replies received, sending
defaults");
navMessageReplyDefine(id := 1, text := "Yes");
navMessageReplyDefine(id := 2, text := "No");
131:
DebugMsg(message := "MON: refresh of drivers status, sending defaults");
navUserStatusDefine(id := 1, text := "Awaiting new destination");
navUserStatusDefine(id := 2, text := "On the way to a destination");
132:
DebugMsg(message := "MON: navigation device present");
DebugFmt(message := "MON: -serial=" + navDeviceSerial());
IF nmpPresent() THEN
DebugMsg(message := "NMP present");
IF setupNMP() = 0 THEN
DebugMsg(message := "NMP set up");
ELSE
DebugMsg(message := "Failed to set up NMP");
END_IF;
ELSE
DebugMsg(message := "Not an NMP");
END_IF;
133:
DebugMsg(message := "MON: navigation device not present");
ELSE
DebugFmt(message := "MON: unhandled event form device '\1'", v1 := event);
END_CASE;
END_WHILE;
END_THREAD_BLOCK;
THREAD_BLOCK gpsRefresh;
WHILE TRUE DO
gps();
Sleep(delay:=100);
END_WHILE;
END_THREAD_BLOCK;
THREAD_BLOCK mdtMonitor;
VAR
key:INT;
rc:INT;
END_VAR;
WHILE TRUE DO
key := mdtGetKey(timeout := 10000);
CASE key OF
127:
rc:=mdtStandby(enable :=OFF);
DebugFmt(message:="mdtStandby(OFF) = \1", v1:=rc);
rc:=mdtGotoXY(x:=10,y:=5);
DebugFmt(message:="mdtGotoXY() = \1", v1:=rc);
rc:=mdtWrite(message:="Welcome!");
DebugFmt(message:="mdtWrite() = \1", v1:=rc);
126:
rc:=mdtStandby(enable :=ON);
DebugFmt(message:="mdtStandby(ON) = \1", v1:=rc);
END_CASE;
END_WHILE;
END_THREAD_BLOCK;
PROGRAM example;
VAR
navMon : navMonitor;
gpsRefr: gpsRefresh;
mdtMon : mdtMonitor;
rc : INT;
END_VAR;
gpsPower(power:=TRUE);
rc := navOpen(port := 1);
IF rc = 0 THEN
DebugMsg(message := "navigation open");
ELSE
DebugFmt(message := "navigation error (navOpen=\1)", v1 := rc);
END_IF;
rc := nmpPower( power:= ON);
IF rc = 0 THEN
DebugMsg(message := "NMP powered on");
ELSE
DebugFmt(message := "failed to power on NMP (nmpPower=\1)", v1 := rc);
END_IF;
navMon();
gpsRefr();
rc := mdtOpen(port := 1);
mdtMon();
BEGIN
Sleep(delay:=100);
END;
END_PROGRAM;
|