Exemplo n.º 1
0
        public DNP_Frame(byte[] rawdata)
        {
            dt           = DateTime.Now;
            this.rawdata = rawdata;
            byte[] DLheader = new byte[10];
            for (int i = 0; i < 10; i++)  // rawdata has at least 10 bytes
            {
                DLheader[i] = rawdata[i];
            }
            dataLinkHeader = new DataLink_Header(DLheader);
            int rawdataindex = 10;

            if (rawdata.Length > 10) // rawdata more than 10 bytes (DLH + TH + AH)
            {
                transportHeader = new Transport_Header(rawdata[10]);
                rawdataindex    = 11;
                // Application_Layer Constructor Here
                byte[] APheader = new byte[rawdata.Length - 11];
                for (int i = 0; i < APheader.Length; i++)
                {
                    APheader[i] = rawdata[rawdataindex];
                    rawdataindex++;
                }
                applicationHeader = new Application_Header(this.dataLinkHeader, this.transportHeader, APheader);
            }
        }
Exemplo n.º 2
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[];
        }
Exemplo n.º 3
0
 public DNP_Frame(DataLink_Header DL, Transport_Header TH, Application_Header AP)
 {
     this.dataLinkHeader    = DL;
     this.transportHeader   = TH;
     this.applicationHeader = AP;
 }
Exemplo n.º 4
0
 public DNP_Frame(DataLink_Header DL)
 {
     this.dataLinkHeader = DL;
 }