| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- using Edge.Core.Parser.BinaryParser.MessageEntity;
- using Edge.Core.Parser.BinaryParser.Attributes;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Edge.Core.Parser.BinaryParser.Util;
- namespace Wayne_Pump_Dart.MessageEntity
- {
- public enum ControlCharacter
- {
- POLL = 0x20,
- DATA = 0x30,
- ACK = 0xC0,
- NAK = 0x50,
- EOT = 0x70,
- AckPoll = 0xE0,
- }
- public class MessageBase : MessageTemplateBase
- {
- /// <summary>
- /// physical pump side address, must range from 0x50 to 0x6F
- /// </summary>
- [Format(1, EncodingType.BIN, -9999)]
- [Range(0x50, 0x6F, "Wayne Dart pump address must be range from {1} to {2}, but actual is {0}")]
- public byte Adrs { get; set; }
- [Format(1, EncodingType.BIN, -9950)]
- public byte CtrlCharAndBlockSeqNoRaw { get; set; }
- /// <summary>
- /// high 4 bits of ControlCharacterAndBlockSeqNumberRaw.
- /// </summary>
- public ControlCharacter ControlCharacter
- {
- get
- {
- var r = Enum.ToObject(typeof(ControlCharacter),
- CtrlCharAndBlockSeqNoRaw & 0xF0);
- return (ControlCharacter)r;
- }
- set
- {
- this.CtrlCharAndBlockSeqNoRaw =
- this.CtrlCharAndBlockSeqNoRaw.SetBit(4, 7, (int)value >> 4);
- }
- }
- /// <summary>
- /// from low 4 bits of ControlCharacterAndBlockSeqNumberRaw, range from 0x00 to 0x0F.
- /// </summary>
- public byte BlockSeqNumber
- {
- get
- {
- return (byte)(CtrlCharAndBlockSeqNoRaw & 0x0F);
- }
- set
- {
- this.CtrlCharAndBlockSeqNoRaw =
- this.CtrlCharAndBlockSeqNoRaw.SetBit(0, 3, (int)value);
- }
- }
- [EnumerableFormat("%cascade", -9920)]
- public List<TransactionData> TransactionDatas { get; set; }
- //[EnumerableFormat(4, 9999)]
- //public virtual List<byte> CRC_ETX_SF { get; set; }
- public override string ToLogString()
- {
- if (this.ControlCharacter == ControlCharacter.EOT)
- return "EOT(Adrs: 0x" + this.Adrs.ToString("X").PadLeft(2, '0') + ", SeqNo: 0x" + this.BlockSeqNumber.ToString("X").PadLeft(2, '0') + ")";
- else if (this.ControlCharacter == ControlCharacter.ACK)
- return "ACK(Adrs: 0x" + this.Adrs.ToString("X").PadLeft(2, '0') + ", SeqNo: 0x" + this.BlockSeqNumber.ToString("X").PadLeft(2, '0') + ")";
- else
- return base.ToLogString();
- }
- }
- public class TransactionData : IFormattable
- {
- [Format(1, EncodingType.BIN, -9999)]
- public byte TransactionNumber { get; set; }
- [Format(1, EncodingType.BIN, -9990)]
- public int Length { get; set; }
- [EnumerableFormat("Length", -9950)]
- public List<byte> RawData { get; set; }
- public string ToString(string format, IFormatProvider formatProvider)
- {
- /* these TransactioNumber have different meanings for
- request and response, here the implementation is only
- for response(from pump to FC) */
- // Pump status
- if (this.TransactionNumber == 1)
- {
- switch (this.RawData.First())
- {
- case 0: return "PUMP NOT PROGRAMMED";
- case 1: return "RESET";
- case 2: return "AUTHORIZED";
- case 4: return "FILLING";
- case 5: return "FILLING COMPLETED";
- case 6: return "MAX AMOUNT/VOLUME REACHED";
- case 7: return "SWITCHED OFF";
- case 8: return "SUSPENDED";
- }
- }
- // Filled volume and amount
- else if (this.TransactionNumber == 2)
- {
- return "Filled volume and amount";
- }
- // Nozzle status and filling price
- else if (this.TransactionNumber == 3)
- {
- return "Nozzle status and filling price";
- }
- // Total Counters
- else if (this.TransactionNumber == 0x65)
- {
- return "Total Counters";
- }
- return "";
- }
- }
- }
|