|
@@ -27,7 +27,7 @@ namespace HengshanPaymentTerminal
|
|
|
{
|
|
|
"lang-zh-cn:恒山IC卡终端lang-en-us:HengshanICTerminal"
|
|
|
})]
|
|
|
- public class HengshanPayTermHandler : IEnumerable<IFdcPumpController>, IDeviceHandler<byte[], CardMessageBase>
|
|
|
+ public class HengshanPayTermHandler : IEnumerable<IFdcPumpController>, IDeviceHandler<byte[], CommonMessage>
|
|
|
{
|
|
|
#region Fields
|
|
|
|
|
@@ -37,10 +37,11 @@ namespace HengshanPaymentTerminal
|
|
|
private string pumpSiteNozzleNos;
|
|
|
private string nozzleLogicIds;
|
|
|
|
|
|
- private IContext<byte[], CardMessageBase> _context;
|
|
|
+ private IContext<byte[], CommonMessage> _context;
|
|
|
private List<HengshanPumpHandler> pumpHandlers = new List<HengshanPumpHandler>();
|
|
|
|
|
|
public Queue<CardMessageBase> queue = new Queue<CardMessageBase>();
|
|
|
+ public Queue<CommonMessage> commonQueue = new Queue<CommonMessage>();
|
|
|
private object syncObj = new object();
|
|
|
|
|
|
private ConcurrentDictionary<int, PumpStateHolder> statusDict = new ConcurrentDictionary<int, PumpStateHolder>();
|
|
@@ -157,7 +158,7 @@ namespace HengshanPaymentTerminal
|
|
|
|
|
|
public List<int> AssociatedPumpIds { get; private set; }
|
|
|
|
|
|
- public IContext<byte[], CardMessageBase> Context
|
|
|
+ public IContext<byte[], CommonMessage> Context
|
|
|
{
|
|
|
get { return _context; }
|
|
|
}
|
|
@@ -388,7 +389,7 @@ namespace HengshanPaymentTerminal
|
|
|
|
|
|
#region IHandler implementation
|
|
|
|
|
|
- public void Init(IContext<byte[], CardMessageBase> context)
|
|
|
+ public void Init(IContext<byte[], CommonMessage> context)
|
|
|
{
|
|
|
CommIdentity = context.Processor.Communicator.Identity;
|
|
|
_context = context;
|
|
@@ -396,9 +397,18 @@ namespace HengshanPaymentTerminal
|
|
|
|
|
|
public string CommIdentity { get; private set; }
|
|
|
|
|
|
- public async Task Process(IContext<byte[], CardMessageBase> context)
|
|
|
+ public async Task Process(IContext<byte[], CommonMessage> context)
|
|
|
{
|
|
|
|
|
|
+ switch(context.Incoming.Message.Handle)
|
|
|
+ {
|
|
|
+
|
|
|
+ case 0x55:
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ context.Outgoing.Write(context.Incoming.Message);
|
|
|
}
|
|
|
|
|
|
private void CheckStatus(CheckCmdRequest request)
|
|
@@ -469,12 +479,12 @@ namespace HengshanPaymentTerminal
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void Write(CardMessageBase cardMessage)
|
|
|
+ public void Write(CommonMessage cardMessage)
|
|
|
{
|
|
|
_context.Outgoing.Write(cardMessage);
|
|
|
}
|
|
|
|
|
|
- public async Task<CardMessageBase> WriteAsync(CardMessageBase request, Func<CardMessageBase, CardMessageBase, bool> responseCapture,
|
|
|
+ public async Task<CommonMessage> WriteAsync(CommonMessage request, Func<CommonMessage, CommonMessage, bool> responseCapture,
|
|
|
int timeout)
|
|
|
{
|
|
|
var resp = await _context.Outgoing.WriteAsync(request, responseCapture, timeout);
|
|
@@ -512,7 +522,7 @@ namespace HengshanPaymentTerminal
|
|
|
if (queue.Count > 0)
|
|
|
{
|
|
|
DebugLog($"queue count: {queue.Count}");
|
|
|
- var message = queue.Dequeue();
|
|
|
+ var message = commonQueue.Dequeue();
|
|
|
Write(message);
|
|
|
return true;
|
|
|
}
|
|
@@ -568,6 +578,69 @@ namespace HengshanPaymentTerminal
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
+
|
|
|
+ #region 二维码加油机相关方法
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private static Byte[] RemoveFA(Byte[] input)
|
|
|
+ {
|
|
|
+ List<byte> resultList = new List<byte>();
|
|
|
+
|
|
|
+ for (int i = 0; i < input.Length; i++)
|
|
|
+ {
|
|
|
+ if (i < input.Length - 1 && input[i] == 0xFA && input[i + 1] == 0xFA)
|
|
|
+ {
|
|
|
+ resultList.Add(0xFA);
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ resultList.Add(input[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return resultList.ToArray();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ const ushort CRC_ORDER16 = 16;
|
|
|
+ const ushort CRC_POLYNOM16 = 0x1021;
|
|
|
+ const ushort CRC_CRCINIT16 = 0xFFFF;
|
|
|
+ const ushort CRC_CRCXOR16 = 0x0000;
|
|
|
+ const ushort CRC_MASK = 0xFFFF;
|
|
|
+ const ushort CRC_HIGHEST_BIT = (ushort)(1 << (CRC_ORDER16 - 1));
|
|
|
+ const ushort TGT_CRC_DEFAULT_INIT = 0xFFFF;
|
|
|
+ public static ushort Crc16(byte[] buffer, ushort length)
|
|
|
+ {
|
|
|
+ ushort crc_rc = TGT_CRC_DEFAULT_INIT;
|
|
|
+
|
|
|
+ for (int i = 0; i < length; i++)
|
|
|
+ {
|
|
|
+ byte c = buffer[i];
|
|
|
+ for (ushort j = 0x80; j != 0; j >>= 1)
|
|
|
+ {
|
|
|
+ ushort crc_bit = (ushort)((crc_rc & CRC_HIGHEST_BIT) != 0 ? 1 : 0);
|
|
|
+ crc_rc <<= 1;
|
|
|
+
|
|
|
+ if ((c & j) != 0)
|
|
|
+ {
|
|
|
+ crc_bit = (ushort)((crc_bit == 0) ? 1 : 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (crc_bit != 0)
|
|
|
+ {
|
|
|
+ crc_rc ^= CRC_POLYNOM16;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return (ushort)((crc_rc ^ CRC_CRCXOR16) & CRC_MASK);
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
}
|
|
|
|
|
|
public class HengshanPayTerminalHanlderGroupConfigV1
|