Esempio n. 1
0
        public Application_Header(DataLink_Header DL, Transport_Header TH, byte [] rawdata)
        {
            this.DataLink  = DL;
            this.Transport = TH;
            this.rawdata   = rawdata;
            this.pullCRC();

            this.ApplicationControl = new ApplicationControl(this.Userdata[0]);
            this.FunctionCode       = this.Userdata[1];
            this.FunctionName       = getFunctionName(this.FunctionCode);

            int userdataindex = 2;                 // index for the next data that have to manage

            if (this.DataLink.Control.DIR == true) //REQ HEADER
            {
                userdataindex = 2;
            }
            else if (this.FunctionCode != 0)                       //RES HEADER
            {
                this.IIN      = new IIN(Userdata[2], Userdata[3]); // IIN data |--MSB--||--LSB--|
                userdataindex = 4;
            }

            //still have data
            while (userdataindex < this.Userdata.Length)
            {
                byte      objtemp = Userdata[userdataindex];
                byte      vartemp = Userdata[userdataindex + 1];
                Qualifier qtemp   = new Qualifier(Userdata[userdataindex + 2]);
                userdataindex += 3;  //  for Object + Var + Qualifier total 3 bytes
                int    rangesizetemp = qtemp.getRangeSize();
                byte[] rangetemp     = new byte[rangesizetemp];
                for (int i = 0; i < rangetemp.Length; i++)
                {
                    rangetemp[i] = Userdata[userdataindex];
                    userdataindex++;
                }

                // Construct Object Header
                Object_Header OH        = new Object_Header(objtemp, vartemp, qtemp, rangetemp);
                int           osizetemp = OH.getTotalSize();
                byte []       datatemp  = new byte[osizetemp];
                for (int i = 0; i < datatemp.Length; i++)
                {
                    datatemp[i] = Userdata[userdataindex];
                    userdataindex++;
                }

                //Construct Object Field
                Object_Field otemp = new Object_Field(OH, datatemp);
                ObjectList.Add(otemp);
                //this.Object[objectindex] = new Object_Field(OH, datatemp);
            }
            this.Object = new Object_Field[ObjectList.Count];
            this.Object = ObjectList.ToArray(typeof(Object_Field)) as Object_Field[];
        }
Esempio n. 2
0
        public Object_Field(Object_Header OH, byte [] userdata)
        {
            this.ObjectHeader = OH;

            int userdataindex = 0; // index for running userdata to be Class's attributes

            this.DataSize = this.ObjectHeader.getDataSize();

            //check index size
            this.IndexSize   = this.ObjectHeader.Qualifier.getIndexSize();
            this.isSizeIndex = this.ObjectHeader.Qualifier.getIndexType();
            uint Ocount = this.ObjectHeader.getObjectQuantity(); // get object quantity of byte
            int  Count  = this.ObjectHeader.getObjectCount();    // get object count

            //---------------------------- Data Object--------------------------------------//
            if (this.DataSize == 0x81) // Object is bit
            {
                this.Obj = new ObjectData[Count];
                byte Oindex      = 0;            // Object Array Index
                uint tempaddress = this.ObjectHeader.Start;
                for (int i = 0; i < Ocount; i++) // loop = amount of total bytes
                {
                    uint indextemp = 0;
                    bool hasIndex  = false;
                    //byte[] datatemp = new byte[Ocount];
                    for (int k = 0; (k < 8) && (Oindex < Count); k++, Oindex++) // loop 8 times for every bits in 1 byte
                    {
                        byte[] datatemp = new byte[1];
                        datatemp[0]  = (byte)(userdata[userdataindex] >> k); //shift k bit
                        datatemp[0] &= 0x01;                                 // Check LSB 0 or 1
                        Obj[Oindex]  = new ObjectData(this.ObjectHeader.ObjectGroup, this.ObjectHeader.ObjectVariation,
                                                      indextemp, tempaddress, datatemp, hasIndex, true);
                        tempaddress++;
                    }
                    userdataindex++;
                }
            }
            else // Object is byte
            {
                Obj = new ObjectData[Ocount];

                if (this.ObjectHeader.Qualifier.Qcode != 6 && this.DataSize != 100) // if Q-code isn't 6 and has data
                {
                    //Ocount = this.getObjectQuantity();
                    if (IndexSize > 0)  //object has index
                    {
                        for (int i = 0; i < Obj.Length; i++)
                        {
                            uint indextemp = 0;
                            //uint tempaddress = 0;
                            bool   hasIndex = true;
                            byte[] datatemp = new byte[this.DataSize];
                            for (int j = 0; j < IndexSize; j++) // loop for combine index data
                            {
                                indextemp += (uint)(userdata[userdataindex] << (8 * j));
                                userdataindex++;
                            }
                            for (int k = 0; k < this.DataSize; k++)
                            {
                                datatemp[k] = userdata[userdataindex];
                                userdataindex++;
                            }
                            Obj[i] = new ObjectData(this.ObjectHeader.ObjectGroup, this.ObjectHeader.ObjectVariation,
                                                    indextemp, indextemp, datatemp, hasIndex);
                        }
                    }
                    else //object has no index
                    {
                        uint tempaddress = this.ObjectHeader.Start;;
                        uint indextemp   = 0;
                        bool hasIndex    = false;
                        for (int i = 0; i < Obj.Length; i++)
                        {
                            byte[] datatemp = new byte[this.DataSize];
                            for (int k = 0; k < this.DataSize; k++)
                            {
                                datatemp[k] = userdata[userdataindex];
                                userdataindex++;
                            }
                            Obj[i] = new ObjectData(this.ObjectHeader.ObjectGroup, this.ObjectHeader.ObjectVariation,
                                                    indextemp, tempaddress, datatemp, hasIndex);
                            tempaddress++;
                        }
                    }
                }
            }
            //--------------------------------------------------------------------------------//
        }