示例#1
0
        /// <summary>
        /// Create vendor extended paramters from BitArray
        /// </summary>
        /// <param name="bit_array">BitArray. Input</param>
        /// <param name="cursor">The current bit position to be processed.</param>
        /// <param name="length">Total length of the array</param>
        /// <returns></returns>
        public new static MSG_CUSTOM_MESSAGE DecodeCustomMessage(ref BitArray bit_array, ref int cursor, int length)
        {
            if (cursor >= length)
            {
                return(null);
            }

            int old_cursor = cursor;

            MSG_CUSTOM_MESSAGE msg = MSG_CUSTOM_MESSAGE.FromBitArray(ref bit_array, ref cursor, length);

            if (null != msg)
            {
                string key = msg.VendorID + "-" + msg.SubType;
                if (null != vendorExtensionIDTypeHash)
                {
                    int new_cursor = cursor;

                    try
                    {
                        Type tp = (Type)vendorExtensionIDTypeHash[key];

                        MethodInfo mis = tp.GetMethod("FromBitArray");
                        if (null == mis)
                        {
                            return(null);
                        }

                        cursor = old_cursor;
                        object[] parameters = new object[] { bit_array, cursor, length };

                        object obj = mis.Invoke(null, parameters);
                        cursor = (int)parameters[1];

                        return((MSG_CUSTOM_MESSAGE)obj);
                    }
                    catch
                    {
                        cursor = new_cursor;
                    }
                }

                return(msg);
            }

            return(null);
        }
示例#2
0
        public static MSG_CUSTOM_MESSAGE DecodeCustomMessage(
            ref BitArray bit_array,
            ref int cursor,
            int length)
        {
            if (cursor >= length)
            {
                return((MSG_CUSTOM_MESSAGE)null);
            }
            int num1 = cursor;
            MSG_CUSTOM_MESSAGE msgCustomMessage = MSG_CUSTOM_MESSAGE.FromBitArray(ref bit_array, ref cursor, length);

            if (msgCustomMessage == null)
            {
                return((MSG_CUSTOM_MESSAGE)null);
            }
            string str = msgCustomMessage.VendorID.ToString() + "-" + (object)msgCustomMessage.SubType;

            if (CustomMsgDecodeFactory.vendorExtensionIDTypeHash != null)
            {
                int num2 = cursor;
                try
                {
                    MethodInfo method = ((Type)CustomMsgDecodeFactory.vendorExtensionIDTypeHash[(object)str]).GetMethod("FromBitArray");
                    if (method == null)
                    {
                        return((MSG_CUSTOM_MESSAGE)null);
                    }
                    cursor = num1;
                    object[] parameters = new object[3]
                    {
                        (object)bit_array,
                        (object)cursor,
                        (object)length
                    };
                    object obj = method.Invoke((object)null, parameters);
                    cursor = (int)parameters[1];
                    return((MSG_CUSTOM_MESSAGE)obj);
                }
                catch
                {
                    cursor = num2;
                }
            }
            return(msgCustomMessage);
        }
示例#3
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);
            }
        }