\begin{vdm_al} ----------------------------------------------- -- Class: Controller -- Description: Controller is main class in -- every independent VeMo unit -----------------------------------------------
-- -- class definition -- class Controller
-- -- instance variables -- instancevariables -- traffic data issued by this controller, that will be passed on -- other controllers. private internalTrafficData : seqof TrafficData := []; invlen internalTrafficData <= Config`TrafficDataKeeptNumber; -- traffic data from other controllers moving in the opposite direction, private externalTrafficData : seqof TrafficData := []; -- this will not be passes on as it makes no sense with the current -- warning types. invlen externalTrafficData <= Config`TrafficDataKeeptNumber;
--keep track of whom we have communicated with. private communicatedWith : seqofnat := []; invlen communicatedWith <= Config`TrafficDataKeeptNumber;
private traffic : Traffic; -- the vehicle the VeMo system Controller is placed in. private vemoVehicle : Vehicle;
public Controller : Vehicle ==> Controller
Controller (vehicle) ==
(
vemoVehicle := vehicle;
traffic := new Traffic();
);
asyncpublic AddOncomingVehicle: VehicleData ==> ()
AddOncomingVehicle(vd) ==
( ifnot traffic.ExistVehicleData(vd) then let v = new Vehicle(vd) in
traffic.AddVehicle(v);
);
public AddTrafficData: nat * seqof TrafficData ==> ()
AddTrafficData(vemoUnitID, data) ==
( --we cant use empty data if data = [] then return;
--did we already exchange information? if vemoUnitID insetelems communicatedWith then return;
--keep track of who we have communicated with iflen communicatedWith < Config`TrafficDataKeeptNumber then
communicatedWith := communicatedWith ^ [vemoUnitID] else
communicatedWith := tl communicatedWith ^ [vemoUnitID];
-- add traffic if(len externalTrafficData < Config`TrafficDataKeeptNumber) then
externalTrafficData := externalTrafficData ^ data else
externalTrafficData := tl externalTrafficData ^ data;
for d in data do
(
World`env.handleEvent("Vehicle: " ^ Printer`natToString(GetVehicleID()) ^ " received " ^ d.ToString());
);
public GetTrafficData: () ==> [seqof TrafficData]
GetTrafficData() == -- deep copy return [ new TrafficData(internalTrafficData(i).GetMessage(),
internalTrafficData(i).GetPosition(),
internalTrafficData(i).GetDirection())
| i insetinds internalTrafficData ];
pure public GetVehicleID : () ==> nat
GetVehicleID()== return vemoVehicle.GetID();
pure public GetPosition : () ==> [Position]
GetPosition() == return vemoVehicle.GetPosition();
pure public GetDirection: () ==> [Types`Direction]
GetDirection() == return vemoVehicle.GetDirection();
public getVehicle : () ==> [Vehicle]
getVehicle() == return vemoVehicle;
public getVehicleDTO : () ==> [VehicleData]
getVehicleDTO() == vemoVehicle.getDTO();
public EnvironmentReady: () ==> ()
EnvironmentReady() == if(canRun = false) then canRun := true;
public Step: () ==> ()
Step() ==
(
vemoVehicle.Move();
--check expired internal data forall td insetelems internalTrafficData do
( if td.Expired() then
( --remove td
internalTrafficData := [internalTrafficData(i)
| i insetinds internalTrafficData
& internalTrafficData(i) <> td];
)
);
--check for lowgrip, and check if already set at position. if vemoVehicle.getLowGrip() = true then
( --The position check will only be relevant if the car has speed 0 if vemoVehicle.GetSpeed() = 0 => notexists data insetelems internalTrafficData
& Position`Compare(data.GetPosition(), GetPosition()) and
data.GetPosition() <> GetPosition()and
data.GetMessage() = <LowGrip> then let lowGripMsg = new TrafficData(<LowGrip>, GetPosition().deepCopy()
, GetDirection()) in
AddInternalTrafficData(lowGripMsg);
);
--check for turnindicator, and check if already set at position. if vemoVehicle.TurnIndicator() = <LEFT> then
( --The position check will only be relevant if the car has speed 0 if vemoVehicle.GetSpeed() = 0 => notexists data insetelems internalTrafficData
& Position`Compare(data.GetPosition(), GetPosition()) and data.GetMessage() = <LeftTurn> then let turnMsg = new TrafficData(<LeftTurn>, GetPosition().deepCopy()
,GetDirection()) in
AddInternalTrafficData(turnMsg);
);
--check for congestion, and check if already set at position. if traffic.Congestion() = true then
( --The position check will only be relevant if the car has speed 0 if vemoVehicle.GetSpeed() = 0 => notexists data insetelems internalTrafficData
& Position`Compare(data.GetPosition(), GetPosition()) and data.GetMessage() = <Congestion> then
( let congMsg = new TrafficData(<Congestion>, GetPosition().deepCopy()
, GetDirection()) in
(
AddInternalTrafficData(congMsg);
)
)
);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.