Exemplo n.º 1
0
        /// <summary>
        /// Creates an APDU from an existing buffer building a database of fields as contained inside the APDU
        /// </summary>
        /// <param name="buffer">The buffer to scan to search the fields.</param>
        public CAPDU(byte[] buffer)
        {
            int offset = 0;

            // get message ID
            ID = new CAPDUID(buffer, offset, ref offset);
            if (0 != ID.Value)
            {
                // Get the bitmap
                Bitmap = new CBitmap(buffer, offset, ref offset);
                if (Bitmap.IsSet)
                {
                    // arrived here we can process the fields described inside the bitmap
                    CFields fields = new CFields();

                    // offset now points to the beginning of the fields - WE ONLY CONSIDER BITMAP1 as bitmap2 fields are not described in the dictionary
                    for (int field = 2; field <= 0xFF && 0 < buffer.Length - offset; field++)
                    {
                        if (Bitmap.IsBitSet(field))
                        {
                            // create and retrieve field
                            //CField fg = fields.GetField(field);
                            //CField f = new CField(fg.ID, fg.Type, fg.Minlen, fg.Maxlen);
                            CField f = fields.GetField(field);
                            if (f.SetData(buffer, offset, out offset))
                            {
                                // save the field inside the list of fields
                                try
                                {
                                    AddField(f);
                                }
                                catch (Exception ex)
                                {
                                    CLog.AddException(MethodBase.GetCurrentMethod().Name, ex, "CHAMP: " + field);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Creates an empty APDU with an ID
 /// </summary>
 public CAPDU(short msgid)
 {
     ID = new CAPDUID(msgid);
 }