123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- using Edge.Core.Processor;
- using Edge.Core.IndustryStandardInterface.Pump;
- using HengShan_Pump_TQC_IFSF.MessageEntity;
- using HengShan_Pump_TQC_IFSF.MessageEntity.Incoming;
- using HengShan_Pump_TQC_IFSF.MessageEntity.Outgoing;
- using Edge.Core.Parser.BinaryParser.Util;
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Xml;
- using Wayne.FDCPOSLibrary;
- using Timer = System.Timers.Timer;
- namespace HengShan_Pump_TQC_IFSF
- {
- public class PetroChinaSilentPumpHandler : PumpHandler
- {
- /// <summary>
- ///
- /// </summary>
- /// <param name="pumpId"></param>
- /// <param name="ifsfFuelPointId">range from 0x21 to 0x24</param>
- /// <param name="recipientSubnet">used to locate the remote tqc pump, must a value different from FC</param>
- /// <param name="recipientNode">used to locate the remote tqc pump</param>
- /// <param name="nozzlesXmlConfiguration"></param>
- public PetroChinaSilentPumpHandler(PumpGroupHandler parent, int pumpId, byte ifsfFuelPointId, byte recipientSubnet, byte recipientNode, string nozzlesXmlConfiguration, Func<byte> msgTokenGenerator)
- : base(parent, pumpId, ifsfFuelPointId, recipientSubnet, recipientNode, nozzlesXmlConfiguration, msgTokenGenerator)
- {
- //sample of nozzlesXmlConfiguration
- // <Pump id='3'>
- // <Nozzles>
- // <Nozzle logicalId='1' physicalId='1' ifsfLogicalNozzleId="0x11"/>
- // <Nozzle logicalId='2' physicalId='2' ifsfLogicalNozzleId="0x12"/>
- // </Nozzles>
- // </Pump>
- }
- public override Task Process(IContext<byte[], IfsfMessageBase> context)
- {
- this.context = context;
- //if (context.Incoming.Message is IfsfMessage ifsfMsg
- // && ifsfMsg.MessageType == MessageType.IFSF_MESSAGE_TYPE_UNSOLICITED_ACK)
- //{
- // //logger.Debug("PumpHandlerSilent with ifsfFpId 0x" + base.ifsfFuelPointId.ToHexLogString() + " will ack the Ack requried event!");
- // context.Outgoing.Write(
- // new AcknowledgeMessage(
- // ifsfMsg.OriginatorSubnet,
- // ifsfMsg.OriginatorNode,
- // PumpGroupHandler.originatorSubnet, PumpGroupHandler.originatorNode,
- // ifsfMsg.MessageToken,
- // ifsfMsg.DatabaseId,
- // MessageAcknowledgeStatus.ACK_PositiveAcknowledgeDataReceived
- // ));
- //}
- switch (context.Incoming.Message)
- {
- case FuellingPointDb_FpRunningTransaction_Event fpRunningTrxEvent:
- {
- logger.Debug("Pump " + this.pumpId + ", fpRunningTrxEvent ifsf FpId: 0x" + fpRunningTrxEvent.TargetFuelPointId.ToHexLogString()
- + ", CurAmt and CurVol(no decimal points): " + fpRunningTrxEvent.CurrentAmount
- + " - " + fpRunningTrxEvent.CurrentVolume);
- var operatingNozzle = this.nozzles.First(f => f.LogicalId == this.currentCallingNozzleLogicalId);
- //fire fuelling progress.
- base.FireOnCurrentFuellingStatusChangeEvent(new FdcTransaction()
- {
- Nozzle = operatingNozzle,
- Amount = fpRunningTrxEvent.CurrentAmount,
- Volumn = fpRunningTrxEvent.CurrentVolume,
- Price = 0,
- Finished = false,
- });
- break;
- }
- case FuellingTrxDb_TransactionBufferStatus_Answer trxBufferStatusAnswer:
- {
- //if (trxBufferStatusAnswer.State.HasValue
- // && trxBufferStatusAnswer.State == FuellingTrxDb_TransactionBufferStatus_Event.TransactionState.PAYABLE)
- //{
- logger.Debug("Pump " + this.pumpId + ", received a Payable trx from TQC with Vol and Amount(without decimal points): "
- + trxBufferStatusAnswer.Volume + " - " + trxBufferStatusAnswer.Amount
- + ", sequenceNo.: " + trxBufferStatusAnswer.TransactionSeqNumber);
- var operatingNozzle = this.nozzles.First(f => f.LogicalId == this.currentCallingNozzleLogicalId);
- base.FireOnCurrentFuellingStatusChangeEvent(new FdcTransaction()
- {
- Nozzle = operatingNozzle,
- Amount = trxBufferStatusAnswer.Amount,
- Volumn = trxBufferStatusAnswer.Volume,
- Price = int.Parse(trxBufferStatusAnswer.Price ?? "0"),
- SequenceNumberGeneratedOnPhysicalPump = trxBufferStatusAnswer.TransactionSeqNumber,
- VolumeTotalizer = Convert.ToInt32(trxBufferStatusAnswer.VolumeTotalizerAfterTrx ?? 0 * Math.Pow(10, this.VolumeTotalizerDecimalDigits)),
- Finished = true,
- });
- //}
- break;
- }
- case FuellingTrxDb_TransactionBufferStatus_Event trx_done_evt:
- {
- // mute this event to base which will popup a new fdc fuel trx by this event.
- // for this project, FuellingTrxDb_TransactionBufferStatus_Answer is the one used for popup fdc fuel trx.
- return Task.CompletedTask;
- }
- default:
- base.Process(context);
- break;
- }
- return Task.CompletedTask;
- }
- public override void HandleFpStatusChange(FuellingPointStatus newStatus, LogicalNozzle stateChangedNozzle)
- {
- switch (newStatus)
- {
- case FuellingPointStatus.Idle:
- {
- if (this.lastLogicalDeviceState != LogicalDeviceState.FDC_READY)
- {
- this.lastLogicalDeviceState = LogicalDeviceState.FDC_READY;
- this.FireOnStateChangeEvent(LogicalDeviceState.FDC_READY, stateChangedNozzle);
- }
- break;
- }
- case FuellingPointStatus.CALLING:
- {
- if (this.lastLogicalDeviceState != LogicalDeviceState.FDC_CALLING)
- {
- this.lastLogicalDeviceState = LogicalDeviceState.FDC_CALLING;
- this.FireOnStateChangeEvent(LogicalDeviceState.FDC_CALLING, stateChangedNozzle);
- }
- break;
- }
- case FuellingPointStatus.AUTHORISED:
- {
- if (this.lastLogicalDeviceState != LogicalDeviceState.FDC_AUTHORISED)
- {
- this.lastLogicalDeviceState = LogicalDeviceState.FDC_AUTHORISED;
- this.FireOnStateChangeEvent(LogicalDeviceState.FDC_AUTHORISED, stateChangedNozzle);
- }
- break;
- }
- case FuellingPointStatus.STARTED:
- {
- if (this.lastLogicalDeviceState != LogicalDeviceState.FDC_STARTED)
- {
- this.lastLogicalDeviceState = LogicalDeviceState.FDC_STARTED;
- this.FireOnStateChangeEvent(LogicalDeviceState.FDC_STARTED, stateChangedNozzle);
- }
- break;
- }
- case FuellingPointStatus.FUELLING:
- {
- if (this.lastLogicalDeviceState != LogicalDeviceState.FDC_FUELLING)
- {
- this.lastLogicalDeviceState = LogicalDeviceState.FDC_FUELLING;
- this.FireOnStateChangeEvent(LogicalDeviceState.FDC_FUELLING, stateChangedNozzle);
- }
- break;
- }
- case FuellingPointStatus.Inoperative:
- {
- if (this.lastLogicalDeviceState != LogicalDeviceState.FDC_OFFLINE)
- {
- this.lastLogicalDeviceState = LogicalDeviceState.FDC_OFFLINE;
- this.FireOnStateChangeEvent(LogicalDeviceState.FDC_OFFLINE, stateChangedNozzle);
- }
- break;
- }
- case FuellingPointStatus.Closed:
- {
- if (this.lastLogicalDeviceState != LogicalDeviceState.FDC_CLOSED)
- {
- this.lastLogicalDeviceState = LogicalDeviceState.FDC_CLOSED;
- this.FireOnStateChangeEvent(LogicalDeviceState.FDC_CLOSED, stateChangedNozzle);
- }
- break;
- }
- }
- }
- public override async Task<LogicalDeviceState> QueryStatusAsync()
- {
- return await Task.FromResult(base.lastLogicalDeviceState);
- }
- public override async Task<bool> AuthorizeAsync(byte logicalNozzleId)
- {
- return false;
- }
- public override async Task<bool> AuthorizeWithAmountAsync(int moneyAmountWithoutDecimalPoint, byte logicalNozzleId)
- {
- return false;
- }
- public override async Task<bool> AuthorizeWithVolumeAsync(int volumnWithoutDecimalPoint, byte logicalNozzleId)
- {
- return false;
- }
- public override async Task<bool> ChangeFuelPriceAsync(int newPriceWithoutDecimalPoint, byte logicalNozzleId)
- {
- return false;
- }
- public override async Task<bool> FuelingRoundUpByAmountAsync(int amount)
- {
- return false;
- }
- public override async Task<bool> FuelingRoundUpByVolumeAsync(int volume)
- {
- return false;
- }
- public override async Task<System.Tuple<int, int>> QueryTotalizerAsync(byte logicalNozzleId)
- {
- return new System.Tuple<int, int>(-1, -1);
- }
- }
- }
|