Exemple #1
0
        public Message TransactMessage(Message msg, int time_out)
        {
            bool[] bit_array = msg.ToBitArray();
            byte[] data      = Util.ConvertBitArrayToByteArray(bit_array);
            try
            {
                transactEvt = new ManualResetEvent(false);
                Transaction.Send(cI, data);

                msg_id = (int)msg.MSG_ID;

                if (msg.MSG_TYPE != (uint)ENUM_LLRP_MSG_TYPE.CUSTOM_MESSAGE)
                {
                    msg_type = (short)(msg.MSG_TYPE + 10);
                }
                else
                {
                    msg_type = (short)msg.MSG_TYPE;
                }

                if (transactEvt.WaitOne(time_out, false))
                {
                    BitArray bArr;
                    int      length;
                    int      cursor = 0;
                    switch ((ENUM_LLRP_MSG_TYPE)msg_type)
                    {
                    case ENUM_LLRP_MSG_TYPE.GET_READER_CAPABILITIES_RESPONSE:
                    {
                        bArr   = Util.ConvertByteArrayToBitArray(data);
                        length = bArr.Count;
                        MSG_GET_READER_CAPABILITIES_RESPONSE r_msg = MSG_GET_READER_CAPABILITIES_RESPONSE.FromBitArray(ref bArr, ref cursor, length);
                        return(r_msg);
                    }

                    case ENUM_LLRP_MSG_TYPE.ADD_ROSPEC_RESPONSE:
                    {
                        bArr   = Util.ConvertByteArrayToBitArray(data);
                        length = bArr.Count;
                        MSG_ADD_ROSPEC_RESPONSE r_msg = MSG_ADD_ROSPEC_RESPONSE.FromBitArray(ref bArr, ref cursor, length);
                        return(r_msg);
                    }

                    case ENUM_LLRP_MSG_TYPE.DELETE_ROSPEC_RESPONSE:
                    {
                        bArr   = Util.ConvertByteArrayToBitArray(data);
                        length = bArr.Count;
                        MSG_DELETE_ROSPEC_RESPONSE r_msg = MSG_DELETE_ROSPEC_RESPONSE.FromBitArray(ref bArr, ref cursor, length);
                        return(r_msg);
                    }

                    case ENUM_LLRP_MSG_TYPE.START_ROSPEC_RESPONSE:
                    {
                        bArr   = Util.ConvertByteArrayToBitArray(data);
                        length = bArr.Count;
                        MSG_START_ROSPEC_RESPONSE r_msg = MSG_START_ROSPEC_RESPONSE.FromBitArray(ref bArr, ref cursor, length);
                        return(r_msg);
                    }

                    case ENUM_LLRP_MSG_TYPE.STOP_ROSPEC_RESPONSE:
                    {
                        bArr   = Util.ConvertByteArrayToBitArray(data);
                        length = bArr.Count;
                        MSG_STOP_ROSPEC_RESPONSE r_msg = MSG_STOP_ROSPEC_RESPONSE.FromBitArray(ref bArr, ref cursor, length);
                        return(r_msg);
                    }

                    case ENUM_LLRP_MSG_TYPE.ENABLE_ROSPEC_RESPONSE:
                    {
                        bArr   = Util.ConvertByteArrayToBitArray(data);
                        length = bArr.Count;
                        MSG_ENABLE_ROSPEC_RESPONSE r_msg = MSG_ENABLE_ROSPEC_RESPONSE.FromBitArray(ref bArr, ref cursor, length);
                        return(r_msg);
                    }

                    case ENUM_LLRP_MSG_TYPE.DISABLE_ROSPEC_RESPONSE:
                    {
                        bArr   = Util.ConvertByteArrayToBitArray(data);
                        length = bArr.Count;
                        MSG_DISABLE_ROSPEC_RESPONSE r_msg = MSG_DISABLE_ROSPEC_RESPONSE.FromBitArray(ref bArr, ref cursor, length);
                        return(r_msg);
                    }

                    case ENUM_LLRP_MSG_TYPE.GET_ROSPECS_RESPONSE:
                    {
                        bArr   = Util.ConvertByteArrayToBitArray(data);
                        length = bArr.Count;
                        MSG_GET_ROSPECS_RESPONSE r_msg = MSG_GET_ROSPECS_RESPONSE.FromBitArray(ref bArr, ref cursor, length);
                        return(r_msg);
                    }

                    case ENUM_LLRP_MSG_TYPE.ADD_ACCESSSPEC_RESPONSE:
                    {
                        bArr   = Util.ConvertByteArrayToBitArray(data);
                        length = bArr.Count;
                        MSG_ADD_ACCESSSPEC_RESPONSE r_msg = MSG_ADD_ACCESSSPEC_RESPONSE.FromBitArray(ref bArr, ref cursor, length);
                        return(r_msg);
                    }

                    case ENUM_LLRP_MSG_TYPE.DELETE_ACCESSSPEC_RESPONSE:
                    {
                        bArr   = Util.ConvertByteArrayToBitArray(data);
                        length = bArr.Count;
                        MSG_DELETE_ACCESSSPEC_RESPONSE r_msg = MSG_DELETE_ACCESSSPEC_RESPONSE.FromBitArray(ref bArr, ref cursor, length);
                        return(r_msg);
                    }

                    case ENUM_LLRP_MSG_TYPE.ENABLE_ACCESSSPEC_RESPONSE:
                    {
                        bArr   = Util.ConvertByteArrayToBitArray(data);
                        length = bArr.Count;
                        MSG_ENABLE_ACCESSSPEC_RESPONSE r_msg = MSG_ENABLE_ACCESSSPEC_RESPONSE.FromBitArray(ref bArr, ref cursor, length);
                        return(r_msg);
                    }

                    case ENUM_LLRP_MSG_TYPE.DISABLE_ACCESSSPEC_RESPONSE:
                    {
                        bArr   = Util.ConvertByteArrayToBitArray(data);
                        length = bArr.Count;
                        MSG_DISABLE_ACCESSSPEC_RESPONSE r_msg = MSG_DISABLE_ACCESSSPEC_RESPONSE.FromBitArray(ref bArr, ref cursor, length);
                        return(r_msg);
                    }

                    case ENUM_LLRP_MSG_TYPE.GET_ACCESSSPECS_RESPONSE:
                    {
                        bArr   = Util.ConvertByteArrayToBitArray(data);
                        length = bArr.Count;
                        MSG_GET_ACCESSSPECS_RESPONSE r_msg = MSG_GET_ACCESSSPECS_RESPONSE.FromBitArray(ref bArr, ref cursor, length);
                        return(r_msg);
                    }

                    case ENUM_LLRP_MSG_TYPE.GET_READER_CONFIG_RESPONSE:
                    {
                        bArr   = Util.ConvertByteArrayToBitArray(data);
                        length = bArr.Count;
                        MSG_GET_READER_CONFIG_RESPONSE r_msg = MSG_GET_READER_CONFIG_RESPONSE.FromBitArray(ref bArr, ref cursor, length);
                        return(r_msg);
                    }

                    case ENUM_LLRP_MSG_TYPE.SET_READER_CONFIG_RESPONSE:
                    {
                        bArr   = Util.ConvertByteArrayToBitArray(data);
                        length = bArr.Count;
                        MSG_SET_READER_CONFIG_RESPONSE r_msg = MSG_SET_READER_CONFIG_RESPONSE.FromBitArray(ref bArr, ref cursor, length);
                        return(r_msg);
                    }

                    case ENUM_LLRP_MSG_TYPE.CLOSE_CONNECTION_RESPONSE:
                    {
                        bArr   = Util.ConvertByteArrayToBitArray(data);
                        length = bArr.Count;
                        MSG_CLOSE_CONNECTION_RESPONSE r_msg = MSG_CLOSE_CONNECTION_RESPONSE.FromBitArray(ref bArr, ref cursor, length);
                        return(r_msg);
                    }

                    default:
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }
            }
            catch
            {
                throw new Exception("Transaction Failed");
            }
        }
Exemple #2
0
        /// <summary>
        /// Decode Binary LLRP packet to LLRP message object
        /// </summary>
        /// <param name="packet">Binary LLRP packet to be decoded</param>
        /// <param name="msg">LLRP message. output</param>
        public static void Decode(ref byte [] packet, out Message msg)
        {
            LLRP_Envelope env;

            Decode_Envelope(packet, out env);

            BitArray ba     = Util.ConvertByteArrayToBitArray(packet);
            int      cursor = 0;

            switch (env.msg_type)
            {
            case ENUM_LLRP_MSG_TYPE.CUSTOM_MESSAGE:
                msg = MSG_CUSTOM_MESSAGE.FromBitArray(ref ba, ref cursor, (int)(env.msg_len * 8));
                return;

            case ENUM_LLRP_MSG_TYPE.GET_READER_CAPABILITIES:
                msg = MSG_GET_READER_CAPABILITIES.FromBitArray(ref ba, ref cursor, (int)(env.msg_len * 8));
                return;

            case ENUM_LLRP_MSG_TYPE.GET_READER_CAPABILITIES_RESPONSE:
                msg = MSG_GET_READER_CAPABILITIES_RESPONSE.FromBitArray(ref ba, ref cursor, (int)(env.msg_len * 8));
                return;

            case ENUM_LLRP_MSG_TYPE.ADD_ROSPEC:
                msg = MSG_ADD_ROSPEC.FromBitArray(ref ba, ref cursor, (int)(env.msg_len * 8));
                return;

            case ENUM_LLRP_MSG_TYPE.ADD_ROSPEC_RESPONSE:
                msg = MSG_ADD_ROSPEC_RESPONSE.FromBitArray(ref ba, ref cursor, (int)(env.msg_len * 8));
                return;

            case ENUM_LLRP_MSG_TYPE.DELETE_ROSPEC:
                msg = MSG_DELETE_ROSPEC.FromBitArray(ref ba, ref cursor, (int)(env.msg_len * 8));
                return;

            case ENUM_LLRP_MSG_TYPE.DELETE_ROSPEC_RESPONSE:
                msg = MSG_DELETE_ROSPEC_RESPONSE.FromBitArray(ref ba, ref cursor, (int)(env.msg_len * 8));
                return;

            case ENUM_LLRP_MSG_TYPE.START_ROSPEC:
                msg = MSG_START_ROSPEC.FromBitArray(ref ba, ref cursor, (int)(env.msg_len * 8));
                return;

            case ENUM_LLRP_MSG_TYPE.START_ROSPEC_RESPONSE:
                msg = MSG_START_ROSPEC_RESPONSE.FromBitArray(ref ba, ref cursor, (int)(env.msg_len * 8));
                return;

            case ENUM_LLRP_MSG_TYPE.STOP_ROSPEC:
                msg = MSG_STOP_ROSPEC.FromBitArray(ref ba, ref cursor, (int)(env.msg_len * 8));
                return;

            case ENUM_LLRP_MSG_TYPE.STOP_ROSPEC_RESPONSE:
                msg = MSG_STOP_ROSPEC_RESPONSE.FromBitArray(ref ba, ref cursor, (int)(env.msg_len * 8));
                return;

            case ENUM_LLRP_MSG_TYPE.ENABLE_ROSPEC:
                msg = MSG_ENABLE_ROSPEC.FromBitArray(ref ba, ref cursor, (int)(env.msg_len * 8));
                return;

            case ENUM_LLRP_MSG_TYPE.ENABLE_ROSPEC_RESPONSE:
                msg = MSG_ENABLE_ROSPEC_RESPONSE.FromBitArray(ref ba, ref cursor, (int)(env.msg_len * 8));
                return;

            case ENUM_LLRP_MSG_TYPE.DISABLE_ROSPEC:
                msg = MSG_DISABLE_ROSPEC.FromBitArray(ref ba, ref cursor, (int)(env.msg_len * 8));
                return;

            case ENUM_LLRP_MSG_TYPE.DISABLE_ROSPEC_RESPONSE:
                msg = MSG_DISABLE_ROSPEC_RESPONSE.FromBitArray(ref ba, ref cursor, (int)(env.msg_len * 8));
                return;

            case ENUM_LLRP_MSG_TYPE.GET_ROSPECS:
                msg = MSG_GET_ROSPECS.FromBitArray(ref ba, ref cursor, (int)(env.msg_len * 8));
                return;

            case ENUM_LLRP_MSG_TYPE.GET_ROSPECS_RESPONSE:
                msg = MSG_GET_ROSPECS_RESPONSE.FromBitArray(ref ba, ref cursor, (int)(env.msg_len * 8));
                return;

            case ENUM_LLRP_MSG_TYPE.ADD_ACCESSSPEC:
                msg = MSG_ADD_ACCESSSPEC.FromBitArray(ref ba, ref cursor, (int)(env.msg_len * 8));
                return;

            case ENUM_LLRP_MSG_TYPE.ADD_ACCESSSPEC_RESPONSE:
                msg = MSG_ADD_ACCESSSPEC_RESPONSE.FromBitArray(ref ba, ref cursor, (int)(env.msg_len * 8));
                return;

            case ENUM_LLRP_MSG_TYPE.DELETE_ACCESSSPEC:
                msg = MSG_DELETE_ACCESSSPEC.FromBitArray(ref ba, ref cursor, (int)(env.msg_len * 8));
                return;

            case ENUM_LLRP_MSG_TYPE.DELETE_ACCESSSPEC_RESPONSE:
                msg = MSG_DELETE_ACCESSSPEC_RESPONSE.FromBitArray(ref ba, ref cursor, (int)(env.msg_len * 8));
                return;

            case ENUM_LLRP_MSG_TYPE.ENABLE_ACCESSSPEC:
                msg = MSG_ENABLE_ACCESSSPEC.FromBitArray(ref ba, ref cursor, (int)(env.msg_len * 8));
                return;

            case ENUM_LLRP_MSG_TYPE.ENABLE_ACCESSSPEC_RESPONSE:
                msg = MSG_ENABLE_ACCESSSPEC_RESPONSE.FromBitArray(ref ba, ref cursor, (int)(env.msg_len * 8));
                return;

            case ENUM_LLRP_MSG_TYPE.DISABLE_ACCESSSPEC:
                msg = MSG_DISABLE_ACCESSSPEC.FromBitArray(ref ba, ref cursor, (int)(env.msg_len * 8));
                return;

            case ENUM_LLRP_MSG_TYPE.DISABLE_ACCESSSPEC_RESPONSE:
                msg = MSG_DISABLE_ACCESSSPEC_RESPONSE.FromBitArray(ref ba, ref cursor, (int)(env.msg_len * 8));
                return;

            case ENUM_LLRP_MSG_TYPE.GET_ACCESSSPECS:
                msg = MSG_GET_ACCESSSPECS.FromBitArray(ref ba, ref cursor, (int)(env.msg_len * 8));
                return;

            case ENUM_LLRP_MSG_TYPE.GET_ACCESSSPECS_RESPONSE:
                msg = MSG_GET_ACCESSSPECS_RESPONSE.FromBitArray(ref ba, ref cursor, (int)(env.msg_len * 8));
                return;

            case ENUM_LLRP_MSG_TYPE.GET_READER_CONFIG:
                msg = MSG_GET_READER_CONFIG.FromBitArray(ref ba, ref cursor, (int)(env.msg_len * 8));
                return;

            case ENUM_LLRP_MSG_TYPE.GET_READER_CONFIG_RESPONSE:
                msg = MSG_GET_READER_CONFIG_RESPONSE.FromBitArray(ref ba, ref cursor, (int)(env.msg_len * 8));
                return;

            case ENUM_LLRP_MSG_TYPE.SET_READER_CONFIG:
                msg = MSG_SET_READER_CONFIG.FromBitArray(ref ba, ref cursor, (int)(env.msg_len * 8));
                return;

            case ENUM_LLRP_MSG_TYPE.SET_READER_CONFIG_RESPONSE:
                msg = MSG_SET_READER_CONFIG_RESPONSE.FromBitArray(ref ba, ref cursor, (int)(env.msg_len * 8));
                return;

            case ENUM_LLRP_MSG_TYPE.CLOSE_CONNECTION:
                msg = MSG_CLOSE_CONNECTION.FromBitArray(ref ba, ref cursor, (int)(env.msg_len * 8));
                return;

            case ENUM_LLRP_MSG_TYPE.CLOSE_CONNECTION_RESPONSE:
                msg = MSG_CLOSE_CONNECTION_RESPONSE.FromBitArray(ref ba, ref cursor, (int)(env.msg_len * 8));
                return;

            case ENUM_LLRP_MSG_TYPE.GET_REPORT:
                msg = MSG_GET_REPORT.FromBitArray(ref ba, ref cursor, (int)(env.msg_len * 8));
                return;

            case ENUM_LLRP_MSG_TYPE.RO_ACCESS_REPORT:
                msg = MSG_RO_ACCESS_REPORT.FromBitArray(ref ba, ref cursor, (int)(env.msg_len * 8));
                return;

            case ENUM_LLRP_MSG_TYPE.KEEPALIVE:
                msg = MSG_KEEPALIVE.FromBitArray(ref ba, ref cursor, (int)(env.msg_len * 8));
                return;

            case ENUM_LLRP_MSG_TYPE.KEEPALIVE_ACK:
                msg = MSG_KEEPALIVE_ACK.FromBitArray(ref ba, ref cursor, (int)(env.msg_len * 8));
                return;

            case ENUM_LLRP_MSG_TYPE.READER_EVENT_NOTIFICATION:
                msg = MSG_READER_EVENT_NOTIFICATION.FromBitArray(ref ba, ref cursor, (int)(env.msg_len * 8));
                return;

            case ENUM_LLRP_MSG_TYPE.ENABLE_EVENTS_AND_REPORTS:
                msg = MSG_ENABLE_EVENTS_AND_REPORTS.FromBitArray(ref ba, ref cursor, (int)(env.msg_len * 8));
                return;

            case ENUM_LLRP_MSG_TYPE.ERROR_MESSAGE:
                msg = MSG_ERROR_MESSAGE.FromBitArray(ref ba, ref cursor, (int)(env.msg_len * 8));
                return;

            default:
                throw new MalformedPacket("Unrecognized message " + env.msg_type);
            }
        }
Exemple #3
0
        public Message TransactMessage(Message msg, int time_out)
        {
            byte[] byteArray = Util.ConvertBitArrayToByteArray(msg.ToBitArray());
            try
            {
                this.transactEvt = new ManualResetEvent(false);
                Transaction.Send(this.cI, byteArray);
                this.msg_id   = (int)msg.MSG_ID;
                this.msg_type = msg.MSG_TYPE == (ushort)1023 ? (short)msg.MSG_TYPE : (short)((int)msg.MSG_TYPE + 10);
                if (!this.transactEvt.WaitOne(time_out, false))
                {
                    return((Message)null);
                }
                int cursor = 0;
                switch ((ENUM_LLRP_MSG_TYPE)this.msg_type)
                {
                case ENUM_LLRP_MSG_TYPE.CLOSE_CONNECTION_RESPONSE:
                    BitArray bitArray1 = Util.ConvertByteArrayToBitArray(byteArray);
                    int      count1    = bitArray1.Count;
                    return((Message)MSG_CLOSE_CONNECTION_RESPONSE.FromBitArray(ref bitArray1, ref cursor, count1));

                case ENUM_LLRP_MSG_TYPE.GET_READER_CAPABILITIES_RESPONSE:
                    BitArray bitArray2 = Util.ConvertByteArrayToBitArray(byteArray);
                    int      count2    = bitArray2.Count;
                    return((Message)MSG_GET_READER_CAPABILITIES_RESPONSE.FromBitArray(ref bitArray2, ref cursor, count2));

                case ENUM_LLRP_MSG_TYPE.GET_READER_CONFIG_RESPONSE:
                    BitArray bitArray3 = Util.ConvertByteArrayToBitArray(byteArray);
                    int      count3    = bitArray3.Count;
                    return((Message)MSG_GET_READER_CONFIG_RESPONSE.FromBitArray(ref bitArray3, ref cursor, count3));

                case ENUM_LLRP_MSG_TYPE.SET_READER_CONFIG_RESPONSE:
                    BitArray bitArray4 = Util.ConvertByteArrayToBitArray(byteArray);
                    int      count4    = bitArray4.Count;
                    return((Message)MSG_SET_READER_CONFIG_RESPONSE.FromBitArray(ref bitArray4, ref cursor, count4));

                case ENUM_LLRP_MSG_TYPE.ADD_ROSPEC_RESPONSE:
                    BitArray bitArray5 = Util.ConvertByteArrayToBitArray(byteArray);
                    int      count5    = bitArray5.Count;
                    return((Message)MSG_ADD_ROSPEC_RESPONSE.FromBitArray(ref bitArray5, ref cursor, count5));

                case ENUM_LLRP_MSG_TYPE.DELETE_ROSPEC_RESPONSE:
                    BitArray bitArray6 = Util.ConvertByteArrayToBitArray(byteArray);
                    int      count6    = bitArray6.Count;
                    return((Message)MSG_DELETE_ROSPEC_RESPONSE.FromBitArray(ref bitArray6, ref cursor, count6));

                case ENUM_LLRP_MSG_TYPE.START_ROSPEC_RESPONSE:
                    BitArray bitArray7 = Util.ConvertByteArrayToBitArray(byteArray);
                    int      count7    = bitArray7.Count;
                    return((Message)MSG_START_ROSPEC_RESPONSE.FromBitArray(ref bitArray7, ref cursor, count7));

                case ENUM_LLRP_MSG_TYPE.STOP_ROSPEC_RESPONSE:
                    BitArray bitArray8 = Util.ConvertByteArrayToBitArray(byteArray);
                    int      count8    = bitArray8.Count;
                    return((Message)MSG_STOP_ROSPEC_RESPONSE.FromBitArray(ref bitArray8, ref cursor, count8));

                case ENUM_LLRP_MSG_TYPE.ENABLE_ROSPEC_RESPONSE:
                    BitArray bitArray9 = Util.ConvertByteArrayToBitArray(byteArray);
                    int      count9    = bitArray9.Count;
                    return((Message)MSG_ENABLE_ROSPEC_RESPONSE.FromBitArray(ref bitArray9, ref cursor, count9));

                case ENUM_LLRP_MSG_TYPE.DISABLE_ROSPEC_RESPONSE:
                    BitArray bitArray10 = Util.ConvertByteArrayToBitArray(byteArray);
                    int      count10    = bitArray10.Count;
                    return((Message)MSG_DISABLE_ROSPEC_RESPONSE.FromBitArray(ref bitArray10, ref cursor, count10));

                case ENUM_LLRP_MSG_TYPE.GET_ROSPECS_RESPONSE:
                    BitArray bitArray11 = Util.ConvertByteArrayToBitArray(byteArray);
                    int      count11    = bitArray11.Count;
                    return((Message)MSG_GET_ROSPECS_RESPONSE.FromBitArray(ref bitArray11, ref cursor, count11));

                case ENUM_LLRP_MSG_TYPE.ADD_ACCESSSPEC_RESPONSE:
                    BitArray bitArray12 = Util.ConvertByteArrayToBitArray(byteArray);
                    int      count12    = bitArray12.Count;
                    return((Message)MSG_ADD_ACCESSSPEC_RESPONSE.FromBitArray(ref bitArray12, ref cursor, count12));

                case ENUM_LLRP_MSG_TYPE.DELETE_ACCESSSPEC_RESPONSE:
                    BitArray bitArray13 = Util.ConvertByteArrayToBitArray(byteArray);
                    int      count13    = bitArray13.Count;
                    return((Message)MSG_DELETE_ACCESSSPEC_RESPONSE.FromBitArray(ref bitArray13, ref cursor, count13));

                case ENUM_LLRP_MSG_TYPE.ENABLE_ACCESSSPEC_RESPONSE:
                    BitArray bitArray14 = Util.ConvertByteArrayToBitArray(byteArray);
                    int      count14    = bitArray14.Count;
                    return((Message)MSG_ENABLE_ACCESSSPEC_RESPONSE.FromBitArray(ref bitArray14, ref cursor, count14));

                case ENUM_LLRP_MSG_TYPE.DISABLE_ACCESSSPEC_RESPONSE:
                    BitArray bitArray15 = Util.ConvertByteArrayToBitArray(byteArray);
                    int      count15    = bitArray15.Count;
                    return((Message)MSG_DISABLE_ACCESSSPEC_RESPONSE.FromBitArray(ref bitArray15, ref cursor, count15));

                case ENUM_LLRP_MSG_TYPE.GET_ACCESSSPECS_RESPONSE:
                    BitArray bitArray16 = Util.ConvertByteArrayToBitArray(byteArray);
                    int      count16    = bitArray16.Count;
                    return((Message)MSG_GET_ACCESSSPECS_RESPONSE.FromBitArray(ref bitArray16, ref cursor, count16));

                default:
                    return((Message)null);
                }
            }
            catch
            {
                throw new Exception("Transaction Failed");
            }
        }