Esempio n. 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);
        }
Esempio n. 2
0
        public static byte[] LinkResponse(LinkLayer ll_, TransportLayer tl_)
        {
            LinkLayer ll = new LinkLayer();

            ll.LinkData    = tl_.TransportData;
            ll.source      = ll_.destination;
            ll.destination = ll_.source;
            ll.controlByte = ModifyControlByte(ref ll_);
            ll.serialize(ref ll.LinkData);
            return(ll.LinkData);
        }
Esempio n. 3
0
 public static Byte ModifyControlByte(ref LinkLayer ll_)
 {
     //ll_.dir = (byte)((ll_.controlByte & 0x80) >> 7);
     if (ll_.dir == (byte)DIR.MASTER)
     {
         ll_.dir = (byte)DIR.OUTSTATION;
     }
     //ll_.prm = (byte)((ll_.controlByte & 0x40) >> 6);
     if (ll_.prm == (byte)PRM.INITIATED)
     {
         ll_.prm = (byte)PRM.TERMINATED;
     }
     //ll_.fcb = (byte)((ll_.controlByte & 0x20) >> 5);
     if (ll_.fcb == (byte)FCB.set)
     {
         ll_.fcv = (byte)((ll_.controlByte & 0x10) >> 4);
     }
     //ll_.functionCode = (byte)(ll_.controlByte & 0x0F);
     if (ll_.functionCode == (byte)PrimaryFunctionCode.PRI_CONFIRMED_USER_DATA)
     {
         ll_.functionCode = (byte)SecondaryFunctionCode.SEC_ACK;
     }
     return(ll_.GetControlByte(false));
 }