Exemplo n.º 1
1
        public void Parse()
        {
            // number of bytes used for lengthIndicator
            int pos = 2; // !!!! Should read param for Length Indicator if inclusive/exclusive and how many bytes and what format

            // Parse Header - 5 is the header length (tpdu) we should know from header defintion how many bytes is the header
            msgHeader = new isoHeader(requestBuffer.Skip(pos).Take(5).ToArray());
            pos += 5;

            // get the message type
            if (this.fieldList[0].lengthType == LengthType.FIXED)
            {
                // should be removed - it keeps field data on dialect definition
                fieldList[0].setValueBYTE(requestBuffer.Skip(pos).Take(fieldList[0].getLength()).ToArray());

                // increase position in message buffer
                pos = pos + fieldList[0].getLength();
            }

            // The bitmap may be transmitted as 8 bytes of binary data or as 16 hexadecimal characters 0-9, A-F in the ASCII
            // or EBCDIC character sets.

            msgBitmap = new isoBitmap(requestBuffer.Skip(pos).Take(fieldList[1].getLength()).ToArray());

            fieldList[1].setValueBYTE(requestBuffer.Skip(pos).Take(fieldList[1].getLength()).ToArray());

            pos += fieldList[1].getLength();

            // for each bit that exists get its value based on its definition

            for (int i = 2; i < this.msgDialect.getTotalFields(); i++)
            {

                if (msgBitmap.bitIsSet(i))
                {

                    if (fieldList[i].lengthType == LengthType.FIXED)
                    {
                        fieldList[i].setValueBYTE(requestBuffer.Skip(pos).Take(fieldList[i].getLength()).ToArray());
                        pos += fieldList[i].getLength();
                    }
                    else if (fieldList[i].lengthType == LengthType.LLVAR && fieldList[i].fieldType == FieldType.Z && fieldList[i].lengthEncoding == EncodingType.BCD)
                    {
                        int fieldLength;
                        Int32.TryParse(ConvHelper.bytes2hex(requestBuffer, 1, pos), out fieldLength);
                        int padLen = fieldLength % 2;
                        fieldLength = padLen + (fieldLength / 2);
                        pos += 1;
                        fieldList[i].setValueBYTE(requestBuffer.Skip(pos).Take(fieldLength).ToArray());
                        pos += fieldLength;
                    }
                    else if (fieldList[i].lengthType == LengthType.LLVAR && fieldList[i].lengthEncoding == EncodingType.BCD)
                    {
                        int fieldLength;
                        Int32.TryParse(ConvHelper.bytes2hex(requestBuffer, 1, pos), out fieldLength);
                        pos += 1;
                        if (fieldList[i].fieldType == FieldType.N)
                        {
                            fieldList[i].setValueBYTE(requestBuffer.Skip(pos).Take(fieldLength / 2).ToArray());
                            pos += fieldLength / 2;
                        }
                        else
                        {
                            fieldList[i].setValueBYTE(requestBuffer.Skip(pos).Take(fieldLength).ToArray());
                            pos += fieldLength;
                        }
                    }
                    else if ((fieldList[i].lengthType == LengthType.LLLVAR) && fieldList[i].lengthEncoding == EncodingType.BCD)
                    {
                        int fieldLength;
                        Int32.TryParse(ConvHelper.bytes2hex(requestBuffer, 2, pos), out fieldLength);
                        pos += 2;

                        if (fieldList[i].fieldType == FieldType.N)
                        {
                            fieldList[i].setValueBYTE(requestBuffer.Skip(pos).Take(fieldLength).ToArray());
                            pos += fieldLength / 2;
                        }
                        else
                        {
                            fieldList[i].setValueBYTE(requestBuffer.Skip(pos).Take(fieldLength).ToArray());
                            pos += fieldLength;
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        private List<isoField> fieldList; // iso fields with their values

        #endregion Fields

        #region Constructors

        public isoMessage(byte[] buffer, int bufLen)
        {
            fieldList       = new List<isoField>();

            requestBuffer   = buffer;

            bufLength       = bufLen;

            msgDialect      = new isoDialect(68);

            responseBuffer  = new byte[] { 0 };

            f63v            = String.Empty;

            msgBitmap       = new isoBitmap();

            msgHeader       = new isoHeader();

            // dialect initialized so initialize fields

            for (int i = 0; i < msgDialect.getTotalFields(); i++)
            {
                isoField nIsoField = new isoField();
                fieldList.Add(nIsoField);
                this.fieldList[i].number = i;
                this.fieldList[i].name           = msgDialect.fieldList[i].name;
                this.fieldList[i].fieldEncoding  = msgDialect.fieldList[i].fieldEncoding;
                this.fieldList[i].fieldType      = msgDialect.fieldList[i].fieldType;
                this.fieldList[i].length         = msgDialect.fieldList[i].fixedLength;
                this.fieldList[i].lengthType     = msgDialect.fieldList[i].lengthType;
                this.fieldList[i].description    = msgDialect.fieldList[i].description;
                this.fieldList[i].lengthEncoding = msgDialect.fieldList[i].lengthEncoding;
            }
        }