示例#1
0
        private void Running(double deltaT)
        {
            //Utilities.LogMessage("Entering:  TransferPump.Running", Utilities.LogType.Info, SMSettings.VerboseLogging);
            // 1.  Calculate amount to move based on flow rate and time delta
            //double deltaAmt = deltaT * FlowRate * PumpRatio;
            double deltaAmt = deltaT * FlowRate * PumpRatio;

            // 2.  Determine if move amount exceeds remaining amount in tank(s) or total amout to move.
            deltaAmt = deltaAmt > FromRemaining ? FromRemaining : deltaAmt + AmtPumped > PumpAmount ? PumpAmount - AmtPumped : deltaAmt;

            if (PumpType != TypePump.Dump)
            {
                deltaAmt = deltaAmt > ToCapacityRemaining ? ToCapacityRemaining : deltaAmt;
            }


            if (deltaAmt > SMSettings.Tolerance)
            {
                double deltaCharge = deltaAmt * SMSettings.FlowCost;
                // 3.  Drain Charge
                if (ConsumeCharge(deltaCharge))
                {
                    // 4.  Get list of From parts & Pump Resource
                    RunPumpCycle(deltaAmt);
                }
                else
                {
                    // 5.  Report Lack of charge and turn off pump
                    PumpStatus = PumpState.Stop;
                }
            }
        }
示例#2
0
        /// <summary>
        /// Executes a Pump Cycle.
        /// A pump cycle is the amount moved in a single update event.
        /// </summary>
        /// <param name="cycleAmount"></param>
        internal void RunPumpCycle(double cycleAmount)
        {
            //Utilities.LogMessage("Entering:  TransferPump.RunPumpCycle", Utilities.LogType.Info, SMSettings.VerboseLogging);
            // If a Transfer, lets validate From pump amount can be pumped. (and To if needed)
            if (PumpType != TypePump.Dump)
            {
                double maxAmount = CalcMaxPumpAmt(FromParts, ToParts, new List <string> {
                    Resource
                });
                if (cycleAmount > maxAmount)
                {
                    cycleAmount = maxAmount;
                }
            }

            // From Parts.  used by Dump and Transfer.
            DrainParts(cycleAmount);

            // To Parts (increment)
            if (PumpType != TypePump.Dump)
            {
                FillParts(cycleAmount);
            }
            // -------------------------------------------------------------------
            if (IsComplete)
            {
                PumpStatus = PumpState.Stop;
            }
            //Utilities.LogMessage(string.Format("Exiting:  TransferPump.RunPumpCycle.  PumpStatus = {0}", PumpStatus), Utilities.LogType.Info, SMSettings.VerboseLogging);
        }
示例#3
0
    private void MoveLever()
    {
        //within movement range
        if (movementLever.parent.localEulerAngles.x >= 330 || movementLever.parent.localEulerAngles.x <= 30)
        {
            if (vrinput == 0)
            {
                timer += Time.unscaledDeltaTime;
            }
            else if (!coroutineStarted && vrinput != 0)
            {
                if (pumpState == PumpState.IDLE)
                {
                    pumpState = PumpState.GRABBED;
                }
                var force = vrinput * Time.fixedDeltaTime * speedModifier;
                modifier += Mathf.Abs(force);
                //movementLever.Rotate(Vector3.right, force);
                timer  = 0.0f;
                input += Mathf.Abs(force) * modifier / 100;
                if (input > 19f)
                {
                    input = 19f;
                }
            }
            if (timer >= 1.0f)
            {
                pumpState = PumpState.IDLE;
            }
        }


        if (movementLever.parent.localEulerAngles.x > 15 && movementLever.parent.localEulerAngles.x < 180)
        {
            if (!coroutineStarted && pumpState != PumpState.UP)
            {
                StartCoroutine(WaitForInput(false));
            }

            //if (movementLever.localEulerAngles.x > 15)
            //    movementLever.localRotation = Quaternion.Euler(14.99f, 0, 0);
            //TODO: UI
            //Debug.Log("GO DOWN");
        }
        if (movementLever.parent.localEulerAngles.x < 345 && movementLever.parent.localEulerAngles.x > 180)
        {
            //if (movementLever.localEulerAngles.x < 345)
            //    movementLever.localRotation = Quaternion.Euler(345.01f, 0, 0);

            if (!coroutineStarted && pumpState != PumpState.DOWN)
            {
                StartCoroutine(WaitForInput(true));
            }

            //TODO: UI
            //Debug.Log("GO UP");
            //movementLever.localRotation.SetEulerAngles(14.99f, 0, 0);
        }
    }
示例#4
0
 public void LiftNozzle()
 {
     if (CurrentPumpState != PumpState.Holstered)
     {
         throw new PumpException("Cannot lift - Pump is not holstered.");
     }
     _state = PumpState.Unholstered;
 }
示例#5
0
        public void ReplaceNozzle()
        {
            if (CurrentPumpState != PumpState.Unholstered)
            {
                throw new PumpException("Cannot replace - Pump is not unholstered");
            }

            _state = PumpState.Holstered;
        }
示例#6
0
 public Pump(decimal price, float flowRatePerSecond, int updateMs)
 {
     _pricePerLitre     = price;
     _state             = PumpState.Holstered;
     _flowRatePerSecond = flowRatePerSecond;
     _timer             = new Timer();
     _timer.Elapsed    += new ElapsedEventHandler(OnTimedEvent);
     _timer.Interval    = updateMs;
     _timer.Enabled     = false;
 }
示例#7
0
        public void StopDispensing()
        {
            if (CurrentPumpState != PumpState.Dispensing)
            {
                throw new PumpException("Cannot stop dispensing - Pump is not dispensing.");
            }

            _state         = PumpState.Holstered;
            _timer.Enabled = false;
            TriggerDispenseEvent(DateTime.Now - _startTime);
        }
示例#8
0
        public void StartDispensing()
        {
            if (CurrentPumpState != PumpState.Unholstered)
            {
                throw new PumpException("Cannot start dispensing - Pump is not unholstered.");
            }

            _state         = PumpState.Dispensing;
            _timer.Enabled = true;
            _startTime     = DateTime.Now;
        }
示例#9
0
        private string GetPumpStateText(PumpState state)
        {
            if (state == PumpState.Stop)
            {
                return("停止");
            }
            if (state == PumpState.Running)
            {
                return("运行");
            }

            throw new ArgumentException(state.ToString());
        }
示例#10
0
    //private void OnDrawGizmos()
    //{
    //    Gizmos.color = Color.yellow;
    //    Gizmos.DrawSphere(myRigidbody.worldCenterOfMass, 0.01f);
    //}

    private IEnumerator WaitForInput(bool positive)
    {
        if (positive)
        {
            pumpState = PumpState.DOWN;
        }
        else
        {
            pumpState = PumpState.UP;
        }
        coroutineStarted = true;
        var timer = 0.0f;

        while (timer < 1.0f)
        {
            if (positive)
            {
                if (vrinput > 0)
                {
                    SoundManager.instance.PlaySingle("choose");
                    modifier++;
                    coroutineStarted = false;
                    if (modifier > 100)
                    {
                        modifier = 100;
                    }

                    yield break;
                }
            }
            else
            {
                if (vrinput < 0)
                {
                    SoundManager.instance.PlaySingle("choose");
                    modifier++;
                    if (modifier > 100)
                    {
                        modifier = 100;
                    }
                    coroutineStarted = false;
                    yield break;
                }
            }
            timer += Time.unscaledDeltaTime;
            yield return(null);
        }

        modifier         = 20;
        coroutineStarted = false;
    }
示例#11
0
        private void pump_DispenseUpdated(object sender, DispenseEventArgs e)
        {
            _price    = _pump.PricePerLitre.ToString();
            _state    = _pump.CurrentPumpState;
            _cost     = e.Cost.ToString();
            _quantity = e.Quantity.ToString();

            if (InvokeRequired)
            {
                // after we've done all the processing,
                this.Invoke(new MethodInvoker(delegate {
                    UpdateLabels();
                }));
            }
        }
示例#12
0
    public void SetState(PumpState state)
    {
        switch (state)
        {
        case PumpState.Work:
            anim.SetTrigger("Work");
            break;

        case PumpState.Reset:
            anim.SetTrigger("Reset");
            break;

        default:
            break;
        }
    }
示例#13
0
        public void Monitor(EngineRoomServiceDB erdb, List <Message> messages, bool returnEventsOnly)
        {
            if (!Enabled)
            {
                return;
            }

            EngineRoomServiceDB.LogEventType let = EngineRoomServiceDB.LogEventType.INFO;
            String  desc = null;
            Message msg  = null;

            PumpState pumpState = StateOfPump;

            if (IsOn && DateTime.Now.Subtract(LastOn).TotalSeconds > MaxOnDuration)
            {
                StateOfPump = PumpState.ON_TOO_LONG;
            }
            else
            {
                StateOfPump = IsOn ? PumpState.ON : PumpState.OFF;
            }

            switch (StateOfPump)
            {
            case PumpState.ON_TOO_LONG:
                let  = EngineRoomServiceDB.LogEventType.WARNING;
                desc = String.Format("Pump is: {0}", StateOfPump);
                msg  = BBAlarmsService.AlarmsMessageSchema.AlertAlarmStateChange(ID, BBAlarmsService.AlarmState.CRITICAL, desc);
                break;

            case PumpState.ON:
            case PumpState.OFF:
                let  = StateOfPump == PumpState.ON ? EngineRoomServiceDB.LogEventType.ON: EngineRoomServiceDB.LogEventType.OFF;
                desc = String.Format("Pump is: {0}", StateOfPump);
                msg  = BBAlarmsService.AlarmsMessageSchema.AlertAlarmStateChange(ID, BBAlarmsService.AlarmState.OFF, desc);
                break;
            }
            if (msg != null && (pumpState != StateOfPump || !returnEventsOnly))
            {
                messages.Add(msg);
                if (returnEventsOnly)
                {
                    erdb.LogEvent(let, ID, desc);
                }
            }
        }
示例#14
0
        /// <summary>
        /// this method manages the pumps line
        /// switch statement checks the state of a pump and
        /// if the pump is empty it dequeues a vehicle from the line, changes the state to busy and starts timer (fueling time)
        /// if the state is busy then it returns with no action
        /// with ended state it records all information needed for the counters, calls method RecordTransactions() and changes state back to empty
        /// </summary>
        public void PumpManager()
        {
            switch (pState)
            {
            case PumpState.Empty:
            default:
                try
                {
                    if (Program.vehicleLine.Count() > 0)
                    {
                        pState  = PumpState.Busy; // change state of a pump to busy
                        current = Program.vehicleLine.First();
                        Program.vehicleLine.Remove(current);
                        double workTime = current.HowMuchFuelNeeded() / SPEED; // fuel time
                        vehicleName      = current.GetType().Name;
                        Stats.ToDispense = current.HowMuchFuelNeeded();
                        fType            = current.fuelType;
                        current.vState   = Vehicle.State.Fueling;
                        PumpTimer(workTime);
                        Utils.refresh = true;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error: {0}", ex.ToString());
                }
                break;

            case PumpState.Busy:
                break;

            case PumpState.Ended:
                FuelCounters();
                Stats.TotalEarned += Stats.ToDispense * Stats.price;
                Stats.Commission  += 0.01 * Stats.TotalEarned;
                RecordTransactions();
                Stats.VehiclesServiced++;
                pState        = PumpState.Empty;
                Utils.refresh = true;
                break;
            }
        }
示例#15
0
        public static PumpState GetStatePump(string Input)
        {
            PumpState retval = PumpState.NotUsed;

            if (Input == "0")
            {
                retval = PumpState.NotUsed;
            }
            if (Input == "1")
            {
                retval = PumpState.Ready;
            }
            if (Input == "2")
            {
                retval = PumpState.Running;
            }
            if (Input == "3")
            {
                retval = PumpState.Error;
            }
            return(retval);
        }
示例#16
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="bytes"></param>
        /// <returns></returns>
        public override object ConvertToObject(byte[] bytes)
        {
            byte b = bytes[0];

            PumpStateCollection pss = new PumpStateCollection();
            PumpState ps = new PumpState(PumpTypeEnum.CyclePump, 1, GetPumpStateEnum(b, 0));
            pss.Add(ps);

            ps = new PumpState(PumpTypeEnum.CyclePump,2,GetPumpStateEnum(b,1));
            pss.Add(ps);

            ps = new PumpState(PumpTypeEnum.CyclePump,3,GetPumpStateEnum(b,2));
            pss.Add(ps);

            ps = new PumpState(PumpTypeEnum.RecruitPump,1,GetPumpStateEnum(b,3));
            pss.Add(ps);

            ps = new PumpState(PumpTypeEnum.RecruitPump,2,GetPumpStateEnum(b,4));
            pss.Add(ps);

            return pss;
        }
示例#17
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="bytes"></param>
        /// <returns></returns>
        override public object ConvertToObject(byte[] bytes)
        {
            byte b = bytes[0];

            PumpStateCollection pss = new PumpStateCollection();
            PumpState           ps  = new PumpState(PumpTypeEnum.CyclePump, 1, GetPumpStateEnum(b, 0));

            pss.Add(ps);

            ps = new PumpState(PumpTypeEnum.CyclePump, 2, GetPumpStateEnum(b, 1));
            pss.Add(ps);

            ps = new PumpState(PumpTypeEnum.CyclePump, 3, GetPumpStateEnum(b, 2));
            pss.Add(ps);

            ps = new PumpState(PumpTypeEnum.RecruitPump, 1, GetPumpStateEnum(b, 3));
            pss.Add(ps);

            ps = new PumpState(PumpTypeEnum.RecruitPump, 2, GetPumpStateEnum(b, 4));
            pss.Add(ps);

            return(pss);
        }
示例#18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ps"></param>
        /// <returns></returns>
        int GetIndex(PumpState ps)
        {
            // cycle NO - idx
            // 1 - 0
            // 2 - 1
            // 3 - 2

            // recruit NO - idx
            // 1 - 3
            // 2 - 4
            if (ps.PumpTypeEnum == PumpTypeEnum.CyclePump)
            {
                Debug.Assert(ps.PumpNO >= 1 && ps.PumpNO <= 3,
                             "cyclepump NO must in [1, 3] : " + ps.PumpNO);
                return(ps.PumpNO - 1);
            }
            if (ps.PumpTypeEnum == PumpTypeEnum.RecruitPump)
            {
                Debug.Assert(ps.PumpNO >= 1 && ps.PumpNO <= 2,
                             "recruitpump NO must in [1, 2] : " + ps.PumpNO);
                return(ps.PumpNO + 2);
            }
            throw new ArgumentException("invalid pumpstate: " + ps.PumpTypeEnum + " " + ps.PumpNO);
        }
示例#19
0
        void UpdateLabels()
        {
            _state = _pump.CurrentPumpState;
            switch (_state)
            {
            case (PumpState.Holstered):
                UpdateButtons(true, false, false, false);
                break;

            case (PumpState.Unholstered):
                UpdateButtons(false, true, true, true);
                break;

            case (PumpState.Dispensing):
                UpdateButtons(false, false, true, false);
                break;
            }
            ;

            lblPumpState.Text     = _state.ToString();
            lblPricePerLitre.Text = _price;
            lblCost.Text          = _cost;
            lblQuantity.Text      = _quantity;
        }
示例#20
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="ps"></param>
        /// <returns></returns>
        int GetIndex(PumpState ps)
        {
            // cycle NO - idx
            // 1 - 0
            // 2 - 1
            // 3 - 2

            // recruit NO - idx
            // 1 - 3
            // 2 - 4
            if (ps.PumpTypeEnum == PumpTypeEnum.CyclePump)
            {
                Debug.Assert(ps.PumpNO >= 1 && ps.PumpNO <= 3,
                    "cyclepump NO must in [1, 3] : " + ps.PumpNO);
                return ps.PumpNO - 1;
            }
            if (ps.PumpTypeEnum == PumpTypeEnum.RecruitPump)
            {
                Debug.Assert(ps.PumpNO >= 1 && ps.PumpNO <= 2,
                    "recruitpump NO must in [1, 2] : " + ps.PumpNO);
                return ps.PumpNO + 2;
            }
            throw new ArgumentException("invalid pumpstate: " + ps.PumpTypeEnum + " " + ps.PumpNO);
        }
示例#21
0
 public void Abort()
 {
     PumpStatus = PumpState.Stop;
 }
        /// <summary>
        /// Executes a Pump Cycle.  
        /// A pump cycle is the amount moved in a single update event.
        /// </summary>
        /// <param name="cycleAmount"></param>
        internal void RunPumpCycle(double cycleAmount)
        {
            //Utilities.LogMessage("Entering:  TransferPump.RunPumpCycle", Utilities.LogType.Info, SMSettings.VerboseLogging);
              // If a Transfer, lets validate From pump amount can be pumped. (and To if needed)
              if (PumpType != TypePump.Dump)
              {
            double maxAmount = CalcMaxPumpAmt(FromParts, ToParts, new List<string> {Resource});
            if (cycleAmount > maxAmount) cycleAmount = maxAmount;
              }

              // From Parts.  used by Dump and Transfer.
              DrainParts(cycleAmount);

              // To Parts (increment)
              if (PumpType != TypePump.Dump)
              {
            FillParts(cycleAmount);
              }
              // -------------------------------------------------------------------
              if (IsComplete)
            PumpStatus = PumpState.Stop;
              //Utilities.LogMessage(string.Format("Exiting:  TransferPump.RunPumpCycle.  PumpStatus = {0}", PumpStatus), Utilities.LogType.Info, SMSettings.VerboseLogging);
        }
        private void Running(double deltaT)
        {
            //Utilities.LogMessage("Entering:  TransferPump.Running", Utilities.LogType.Info, SMSettings.VerboseLogging);
              // 1.  Calculate amount to move based on flow rate and time delta
              double deltaAmt = deltaT*FlowRate*PumpRatio;

              // 2.  Determine if move amount exceeds remaining amount in tank(s)
              deltaAmt = deltaAmt > FromRemaining ? FromRemaining : deltaAmt;
              if (PumpType != TypePump.Dump)
            deltaAmt = deltaAmt > ToCapacityRemaining ? ToCapacityRemaining : deltaAmt;

              if (deltaAmt > SMSettings.Tolerance)
              {
            double deltaCharge = deltaAmt*SMSettings.FlowCost;
            // 3.  Drain Charge
            if (ConsumeCharge(deltaCharge))
            {
              // 4.  Get list of From parts & Pump Resource
              RunPumpCycle(deltaAmt);
            }
            else
            {
              // 5.  Report Lack of charge and turn off pump
              PumpStatus = PumpState.Stop;
            }
              }
        }
示例#24
0
 // event that manages the timer
 private void PumpBusy(object sender, ElapsedEventArgs e)
 {
     pState = PumpState.Ended;
 }
示例#25
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="ps"></param>
 /// <returns></returns>
 private byte GetValue(PumpState ps)
 {
     return((byte)System.Math.Pow(2, GetIndex(ps)));
 }
示例#26
0
 public Pump(int id, PumpState state)
 {
     this.ID = id;
     this.State = state;
     this.Hoses = new List<Hose>();
 }
示例#27
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="ps"></param>
 /// <returns></returns>
 private byte GetValue(PumpState ps)
 {
     return (byte)System.Math.Pow(2, GetIndex(ps));
 }
示例#28
0
 public void SetPumpState(PumpState pumpState)
 {
     _stationInformation.SetPumpState(pumpState);
 }
示例#29
0
 public virtual void SetClosed()
 {
     CurrentState = PumpState.Closed;
 }
示例#30
0
 public virtual void SetOpen()
 {
     CurrentState = PumpState.Open;
     //TODO Which is which?
 }
 public void Abort()
 {
     PumpStatus = PumpState.Stop;
 }