using Edge.Core.Parser.BinaryParser.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Wayne_Pump_Dart.MessageEntity.Incoming
{
///
/// This transaction is sent by the pump if the status is changed
/// or if the pump receives the command 'RETURN STATUS' or ‘RETURN FILLING INFORMATION’.
///
public class NozzleStatusAndFillingPrice_TransactionData
{
private TransactionData transactionData;
///
/// TRANS + LNG + DATA
///
/// TRANS + LNG + DATA
public NozzleStatusAndFillingPrice_TransactionData(TransactionData transactionData)
{
if (transactionData.TransactionNumber != 0x03)
throw new ArgumentException("NozzleStatusAndFillingPrice_TransactionData must have transaction number 0x03");
this.transactionData = transactionData;
}
public enum NozzleStatus
{
IN = 0x00,
OUT = 0x01
}
///
/// without decimal points
///
public int FillingPrice
{
get
{
var r = this.transactionData.RawData.Take(3).GetBCD();
return r;
}
}
///
/// Gets the nozzle status, key is the nozzle physical id.
///
public KeyValuePair Status
{
get
{
//NOZIO bits 0 - 3 contain selected nozzle number.
//NOZIO bit 4 contains nozzle in/out information.
// 0 = in
// 1 = out
//02H Nozzle 2 selected, nozzle in
//12H Nozzle 2 selected, nozzle out
//10H No nozzle selected, nozzle out. (This is possible for a blending pump.)
var nozzleStateBitMap = this.transactionData.RawData.Skip(3).First();
var nozzleLogicalNumber = nozzleStateBitMap & 0x0F;
var nozzleStatus = (nozzleStateBitMap & 0xF0) >> 4;
return new KeyValuePair(
(byte)nozzleLogicalNumber,
(NozzleStatus)nozzleStatus);
}
}
}
}