using Edge.Core.IndustryStandardInterface.Pump.Fdc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Edge.Core.IndustryStandardInterface.Pump
{
///
/// Implements this interface indicates the class have the ability to control the physical
/// pump and expose the controller interface by following Fdc pattern.
///
public interface IFdcPumpController //: IDeviceController
{
event EventHandler OnStateChange;
event EventHandler OnCurrentFuellingStatusChange;
///
/// will be called once Fdc server starting.
/// Fdc server will pass in necessary parameters via this function to each FdcPumpController.
///
///
void OnFdcServerInit(Dictionary parameters);
string Name { get; }
///
/// Gets the Identification of the pump for the system. Is the logical number of the pump.
/// e.g.: A site may have 4 physical pumps, each physical pump have 2 sides(fuelling point), then it's the
/// pump id from 1 to 8.
/// Then may have the model of physical pump with 6 nozzels, 3 for each side, but each side may grouped into 2 fuelling points,
/// the first fuelling point in one side contains 1 nozzel, while the second contains 2 nozzels, so in this case,
/// this physical pump actually have 4 fuelling points, also means this physical pump should have 4 pump ids.
///
int PumpId { get; }
///
/// Gets the internal identification of the fuelling position.
/// Most likely it'll be only used in binary protocol parsing level.
/// At least for Wayne pump, it can configed an internal address for each fuelling position via physical pump main board,
/// this Id is critical for the case of multiple Pumps connected into one ComPort.
/// If a device didn't have to check binary message with this id, then put any value for it.
///
int PumpPhysicalId { get; }
IEnumerable Nozzles { get; }
///
/// Gets the money/amount digits.
/// the Money/amount value read from pump is always an int value, need convert with this digits settings to readable format.
///
int AmountDecimalDigits { get; }
///
/// Gets the volume digits
///
int VolumeDecimalDigits { get; }
///
/// price digits typically not the same with Amount digits
///
int PriceDecimalDigits { get; }
int VolumeTotalizerDecimalDigits { get; }
Task QueryStatusAsync();
///
///
///
/// MoneyTotalizer:VolumnTotalizer
Task> QueryTotalizerAsync(byte logicalNozzleId);
//string QueryConfiguration();
Task SuspendFuellingAsync();
Task ResumeFuellingAsync();
Task ChangeFuelPriceAsync(int newPriceWithoutDecimalPoint, byte logicalNozzleId);
Task AuthorizeAsync(byte logicalNozzleId);
Task UnAuthorizeAsync(byte logicalNozzleId);
Task AuthorizeWithAmountAsync(int moneyAmountWithoutDecimalPoint, byte logicalNozzleId);
Task AuthorizeWithVolumeAsync(int volumnWithoutDecimalPoint, byte logicalNozzleId);
///
/// 凑整
///
/// expecting fueling to this amount, value is without decimal point
///
Task FuelingRoundUpByAmountAsync(int amount);
///
/// 凑整
///
/// expecting fueling to this volum, value is without decimal point
///
Task FuelingRoundUpByVolumeAsync(int volume);
///
/// lock a nozzle for not allow it for fueling
///
///
///
Task LockNozzleAsync(byte logicalNozzleId);
///
/// unlock a locked nozzle
///
///
///
Task UnlockNozzleAsync(byte logicalNozzleId);
}
///
/// 每把逻辑枪代表着能加出某个油品的虚拟枪。
/// 大多数情况下逻辑枪数==物理枪数。
/// 存在一把物理枪可以加出三种油的情况,这种情况下,即为三把逻辑枪,但共用一个Physical Id.
///
public class LogicalNozzle
{
private LogicalNozzle() { }
///
///
///
/// the pump(FuelPoint) id of this nozzle is hosted
///
/// must >=1
///
public LogicalNozzle(int pumpId, byte physicalId, byte logicalId, int? realPriceOnPhysicalPump)
{
if (logicalId < 1) throw new ArgumentException("Nozzle logical id must be >=1");
this.PumpId = pumpId;
this.RealPriceOnPhysicalPump = realPriceOnPhysicalPump;
this.PhysicalId = physicalId;
this.LogicalId = logicalId;
}
public int PumpId { get; }
///
/// nozzle PhysicalId should be assgined at hardware level for a physical pump.
/// so it's device dependent, can be confirmed in Pump comm protocol doc.
/// like in Ifsf protocol, physical id for a nozzle is from 0x11 - 0x18.
/// like in Wayne dart protocol, physical id for na nozzle is from 1 - 8.
/// a physical nozzle may have multiple fuel products assgined(blending).
/// most likely it will repeat in each individual pump.
///
public byte PhysicalId { get; }
///
/// Gets or sets the logical id for a nozzle, value must range from 1 to N.
/// in LiteFcc, we follow the rule of, that you face to a FuelPoint,
/// the most left side nozzle is always logicalId 1,
/// and the nozzle right to it, it's 2, and then 3...
///
public byte LogicalId { get; }
///
/// Gets or sets the real price which read from physical pump, without decimal points.
/// some pumps can get price when first time FC connected to it, but some are not.
/// So it may null though the physical pump side price is set (have not read by FC).
/// So it may diff from the FC side value(by a failure in price change request, and that value will be saved into db)
///
///
public int? RealPriceOnPhysicalPump { get; set; }
///
/// Gets or sets the expecting price which set from FC side, without decimal points.
/// FC side could change the pump price (via price change request), this value will send to physical
/// pump and finally saved into FC db.
/// but this does NOT gurantee the consistent since the comm between the FC and pump may fail.
///
public int? ExpectingPriceOnFcSide { get; set; }
///
/// Gets or sets the vol totalizer value for this nozzle, without decimal points.
///
public int? VolumeTotalizer { get; set; }
public LogicalDeviceState? LogicalState { get; set; }
}
public class FdcTransactionDoneEventArg : System.EventArgs
{
public FdcTransactionDoneEventArg(FdcTransaction transaction)
{
this.Transaction = transaction;
}
public FdcTransaction Transaction { get; private set; }
}
public class FdcTransaction
{
public LogicalNozzle Nozzle { get; set; }
///
/// without decimal points
///
public int Amount { get; set; }
///
/// without decimal points
///
public int Volumn { get; set; }
///
/// without decimal points
///
public int Price { get; set; }
public int Barcode { get; set; }
///
/// Gets or set the seq number which typically generated on phsyical pump side for
/// unique a trx, for most pumps, the number will be rotate and reused after a period of time,
/// this is fine since FDC server side check the duplication only by a short time period range,
/// not the full range scan.
/// for some pumps, it didn't have this value at all, then need generate one in FC pump handler side,
/// an unique value is requried.
///
public int SequenceNumberGeneratedOnPhysicalPump { get; set; }
///
/// the money amount totalizer value after this new trx done, without decimal points.
/// the trx from a pump may not carry on amount totalizer value, it device dependent.
///
public int? AmountTotalizer { get; set; }
///
/// the volume amount totalizer value after this new trx done, without decimal points.
/// the trx from a pump may not carry on volume totalizer value, it device dependent.
///
public int? VolumeTotalizer { get; set; }
///
/// Gets or sets if the fueling transaction still on going.
/// True for transaction is done, False for on going.
///
public bool Finished { get; set; }
///
/// Gets or sets the start time of this fuel trx.
/// leave it null will set it to: (SaleEndTime - x minutues), the default x is 3 and could be changed in future in FdcServerApp.
///
public DateTime? SaleStartTime { get; set; }
///
/// Gets or sets the end time of this fuel trx.
/// leave it null will set it to DateTime.Now in FdcServerApp.
///
public DateTime? SaleEndTime { get; set; }
}
}