Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/VDM/VDMPP/MSAWconcurPP/     Datei vom 13.4.2020 mit Größe 2 kB image not shown  

Quelle  environment.vdmpp   Sprache: VDM

 

class Environment is subclass of GLOBAL, BaseThread

types 

InputTP   = (Time * seq of inline);

inline  = FOId * int * int * Altitude * Time;
  
FOOut = FOId * Coordinates * Altitude * FOWarning * 
        MinimumSafetyAltitude * Time;
RadarOut = Coordinates * nat1 * RadarWarning * nat *  Time;
  
  
outline = FOOut | RadarOut; 


instance variables 

  io : IO := new IO();
  inlines  : seq of inline  := [];
  outlines : seq of outline := [];

  airspace : [AirSpace] := nil;
  busy : bool := true;
  updating : bool := false;
  simtime : Time;  
operations
  
public Environment : String * nat1 * bool ==> Environment
Environment(fname, p, isP) == 
 (def mk_(-,mk_(timeval,input)) = io.freadval[InputTP](fname) 
  in
    (inlines := input;
     simtime := timeval);
 period := p;
 isPeriodic := isP;    
 );    
      
public setAirSpace : AirSpace ==> ()
setAirSpace(as) ==
  airspace := as;
      
public handleFOWarningEvent : FOId * Coordinates * Altitude * FOWarning * 
                              MinimumSafetyAltitude * Time ==> ()
handleFOWarningEvent(id,coord,alt,warn,msa,t) ==
  outlines := outlines ^ [mk_(id,coord,alt,warn,msa,t)];
 
public handleRadarWarningEvent : Coordinates * nat1 * RadarWarning * nat *  Time ==> ()
handleRadarWarningEvent(coord,range,radWarn,num,pt) ==
  outlines := outlines ^ [mk_(coord,range,radWarn,num,pt)];

public showResult : () ==> ()
showResult() ==
  def - = io.writeval[seq of outline](outlines) in skip;
 

private updateFOs : () ==> ()
updateFOs() ==
 (if len inlines > 0 
  then (dcl curtime : Time := World`timerRef.GetTime(),
        done : bool := false;
        while not done do
          def mk_(id,x,y, altitude,pt) = hd inlines
          in 
            if pt <= curtime 
            then (airspace.updateFO(id,mk_Coordinates(x,y),altitude);
                  inlines := tl inlines; 
                  updating := true;
                  done := len inlines = 0 )
            else done := true
       )
  else busy := false
 );
     

public isFinished : () ==> () 
isFinished() == skip;

public Step: () ==> ()
Step() ==
 (if World`timerRef.GetTime() < simtime
  then(updateFOs();
       if updating
       then updating := false;
      )
  else busy := false; 
 );

sync

mutex(handleFOWarningEvent);
per isFinished => not busy;

mutex(handleRadarWarningEvent);
mutex(handleRadarWarningEvent,handleFOWarningEvent);

--thread
-- (
--  while World`timerRef.GetTime() < simtime do
--   (updateFOs();
              
--    if updating
--    then (World`timerRef.WaitRelative(1);
--          updating := false);
--   );
--  busy := false; 
--  )


end Environment

Messung
CHZG
879810095

¤ Dauer der Verarbeitung: 0.4 Sekunden  (vorverarbeitet am  2026-11-24) ¤

*© Formatika GbR, Deutschland