Beispiel #1
0
        static void deserializeDNP3(ref byte[] buffer)
        {
            var sb = new StringBuilder("new byte[] { ");

            for (var i = 0; i < buffer.Length; i++)
            {
                var b = buffer[i];
                sb.Append(b);
                if (i < buffer.Length - 1)
                {
                    sb.Append(", ");
                }
            }
            sb.Append(" }");

            DNP3Simple.LinkLayer ll = new DNP3Simple.LinkLayer();
            ll.deserialize(ref buffer);

            DNP3Simple.TransportLayer tl = new DNP3Simple.TransportLayer();
            tl.deserialize(ref buffer);

            DNP3Simple.ApplicationLayer al = new DNP3Simple.ApplicationLayer();
            al.deserialize(ref buffer);

            Console.WriteLine("DNP3 Application request " + sb.ToString());
            DNP3Response(ll, tl, al, ref buffer);
        }
Beispiel #2
0
        public static void ModifyApplicationHeader(ref ApplicationLayer al_)
        {
            // function code
            if (al_.FunctionCode == (byte)DNP3Simple.FunctionCode.READ)
            {
                al_.FunctionCode = (byte)DNP3Simple.FunctionCode.RESPONSE;
            }
            if (al_.FunctionCode == (byte)DNP3Simple.FunctionCode.WRITE)
            {
                al_.FunctionCode = (byte)DNP3Simple.FunctionCode.RESPONSE;
            }
            if (al_.FunctionCode == (byte)DNP3Simple.FunctionCode.OPERATE)
            {
                al_.FunctionCode = (byte)DNP3Simple.FunctionCode.RESPONSE;
            }
            if (al_.FunctionCode == (byte)DNP3Simple.FunctionCode.DIRECT_OPERATE)
            {
                al_.FunctionCode = (byte)DNP3Simple.FunctionCode.RESPONSE;
            }
            if (al_.FunctionCode == (byte)DNP3Simple.FunctionCode.DIRECT_OPERATE_NR)
            {
                al_.FunctionCode = (byte)DNP3Simple.FunctionCode.UNKNOWN;
            }

            // upgrade the control byte based on the rules, currently keep dummy
            // application code
            al_.FIR = 1;
            al_.FIN = 1;
            al_.CON = 1;
            al_.UNS = 0;
            al_.seq = 1;

            al_.ApplicationControl = al_.GetControlByte();
        }
Beispiel #3
0
 public static void ProcessApplicationHeader(ref ApplicationLayer al_)
 {
     // application code
     al_.FIR = (byte)((al_.ApplicationControl & 0x80) >> 7);
     al_.FIN = (byte)((al_.ApplicationControl & 0x40) >> 6);
     al_.CON = (byte)((al_.ApplicationControl & 0x20) >> 5);
     al_.UNS = (byte)((al_.ApplicationControl & 0x10) >> 4);
     al_.seq = (byte)(al_.ApplicationControl & 0x0F);
 }
Beispiel #4
0
        public static byte[] TransportResponse(TransportLayer tl_, ApplicationLayer al_)
        {
            TransportLayer tl = new TransportLayer();

            tl.TransportData = al_.ApplicationData;
            tl.seq           = (byte)(tl_.seq + 1);
            tl.FIN           = 1;
            tl.FIR           = 1;
            tl.serialize(ref tl.TransportData);
            return(tl.TransportData);
        }
Beispiel #5
0
        public static byte[] ApplicationResponse(ApplicationLayer al_)
        {
            ProcessApplicationHeader(ref al_);

            ModifyApplicationHeader(ref al_);

            // we will send the DNP3 request
            ApplicationLayer al = new ApplicationLayer();

            al.InternalIndications = 0x8000; // Device Restart for READ binary input change REQUEST
            byte[] data = new byte[] { 0x00, 0x00 };
            data[1]               = (byte)(al.InternalIndications & 0xFF);
            data[0]               = (byte)((al.InternalIndications >> 8) & 0xFF);
            al.ApplicationData    = data;
            al.FunctionCode       = al_.FunctionCode;
            al.ApplicationControl = al_.ApplicationControl;
            al.serialize(ref al.ApplicationData);
            return(al.ApplicationData);
        }