Ejemplo n.º 1
0
        /// <summary>
        /// Send a  manufacture specific command to a PD.
        /// </summary>
        /// <param name="connectionId">Identify the connection for communicating to the device.</param>
        /// <param name="address">Address assigned to the device.</param>
        /// <param name="manufacturerSpecific">The manufacturer specific data.</param>
        /// <returns>Reply data that is returned after sending the command. There is the possibility of different replies can be returned from PD.</returns>
        public async Task <ReturnReplyData <ManufacturerSpecific> > ManufacturerSpecificCommand(Guid connectionId, byte address,
                                                                                                Model.CommandData.ManufacturerSpecific manufacturerSpecific)
        {
            var reply = await SendCommand(connectionId,
                                          new ManufacturerSpecificCommand(address, manufacturerSpecific)).ConfigureAwait(false);

            return(new ReturnReplyData <ManufacturerSpecific>
            {
                Ack = reply.Type == ReplyType.Ack,
                Nak = reply.Type == ReplyType.Nak ? Nak.ParseData(reply.ExtractReplyData) : null,
                ReplyData = reply.Type == ReplyType.ManufactureSpecific ? ManufacturerSpecific.ParseData(reply.ExtractReplyData) : null
            });
        }
Ejemplo n.º 2
0
        internal static ManufacturerSpecific ParseData(ReadOnlySpan <byte> data)
        {
            var dataArray = data.ToArray();

            if (dataArray.Length < 3)
            {
                throw new Exception("Invalid size for the data");
            }

            var manufacturerSpecificReply = new ManufacturerSpecific
            {
                VendorCode = dataArray.Take(3),
                Data       = dataArray.Length > 3 ? dataArray.Skip(3).ToArray() : null
            };

            return(manufacturerSpecificReply);
        }
Ejemplo n.º 3
0
 public ManufacturerSpecificReplyEventArgs(Guid connectionId, byte address, ManufacturerSpecific manufacturerSpecific)
 {
     ConnectionId         = connectionId;
     Address              = address;
     ManufacturerSpecific = manufacturerSpecific;
 }
Ejemplo n.º 4
0
        internal virtual void OnReplyReceived(Reply reply)
        {
            {
                var handler = ReplyReceived;
                handler?.Invoke(this, new ReplyEventArgs {
                    Reply = reply
                });
            }

            switch (reply.Type)
            {
            case ReplyType.Nak:
            {
                var handler = NakReplyReceived;
                handler?.Invoke(this,
                                new NakReplyEventArgs(reply.ConnectionId, reply.Address,
                                                      Nak.ParseData(reply.ExtractReplyData)));
                break;
            }

            case ReplyType.LocalStatusReport:
            {
                var handler = LocalStatusReportReplyReceived;
                handler?.Invoke(this,
                                new LocalStatusReportReplyEventArgs(reply.ConnectionId, reply.Address,
                                                                    Model.ReplyData.LocalStatus.ParseData(reply.ExtractReplyData)));
                break;
            }

            case ReplyType.InputStatusReport:
            {
                var handler = InputStatusReportReplyReceived;
                handler?.Invoke(this,
                                new InputStatusReportReplyEventArgs(reply.ConnectionId, reply.Address,
                                                                    Model.ReplyData.InputStatus.ParseData(reply.ExtractReplyData)));
                break;
            }

            case ReplyType.OutputStatusReport:
            {
                var handler = OutputStatusReportReplyReceived;
                handler?.Invoke(this,
                                new OutputStatusReportReplyEventArgs(reply.ConnectionId, reply.Address,
                                                                     Model.ReplyData.OutputStatus.ParseData(reply.ExtractReplyData)));
                break;
            }

            case ReplyType.ReaderStatusReport:
            {
                var handler = ReaderStatusReportReplyReceived;
                handler?.Invoke(this,
                                new ReaderStatusReportReplyEventArgs(reply.ConnectionId, reply.Address,
                                                                     Model.ReplyData.ReaderStatus.ParseData(reply.ExtractReplyData)));
                break;
            }

            case ReplyType.RawReaderData:
            {
                var handler = RawCardDataReplyReceived;
                handler?.Invoke(this,
                                new RawCardDataReplyEventArgs(reply.ConnectionId, reply.Address,
                                                              RawCardData.ParseData(reply.ExtractReplyData)));
                break;
            }

            case ReplyType.ManufactureSpecific:
            {
                var handler = ManufacturerSpecificReplyReceived;
                handler?.Invoke(this,
                                new ManufacturerSpecificReplyEventArgs(reply.ConnectionId, reply.Address,
                                                                       ManufacturerSpecific.ParseData(reply.ExtractReplyData)));
                break;
            }

            case ReplyType.ExtendedRead:
            {
                var handler = ExtendedReadReplyReceived;
                handler?.Invoke(this,
                                new ExtendedReadReplyEventArgs(reply.ConnectionId, reply.Address,
                                                               ExtendedRead.ParseData(reply.ExtractReplyData)));
                break;
            }

            case ReplyType.PIVData:
            {
                var handler = PIVDataReplyReceived;
                handler?.Invoke(this,
                                new PIVDataReplyEventArgs(reply.ConnectionId, reply.Address,
                                                          PIVData.ParseData(reply.ExtractReplyData)));
                break;
            }
            }
        }