Ejemplo n.º 1
0
 private static KnxTelegramPayload ParseConnectResponse(KnxTelegramHeader arg1, byte[] arg2)
 {
     if (arg2.Length < 8)
     {
         throw new ArgumentException(string.Format("Supplied buffer smaller than required size ({0})", arg2.Length));
     }
     return(new KnxConnectResponse(arg2[6], (KnxConnectResponse.StatusCodes)arg2[7]));
 }
Ejemplo n.º 2
0
 private static KnxTelegramPayload ParseTunnelingAcknowledge(KnxTelegramHeader arg1, byte[] arg2)
 {
     if (arg2.Length < 8)
     {
         throw new ArgumentException(string.Format("Supplied buffer smaller than required size ({0})", arg2.Length));
     }
     return(new KnxTunnelingAcknowledge(arg2[7], arg2[8]));
 }
Ejemplo n.º 3
0
 internal static KnxTelegramPayload ParseKnxTelegram(KnxTelegramHeader header, byte[] buffer)
 {
     if (!PayloadFactories.ContainsKey(header.ServiceType))
     {
         throw new ArgumentException(string.Format("Do not know how to deserialize service type:  {0}", header.ServiceType));
     }
     return(PayloadFactories[header.ServiceType](header, buffer));
 }
Ejemplo n.º 4
0
 public static void Serialize(KnxTelegramHeader knxTelegramHeader, MemoryStream stream)
 {
     stream.WriteByte(knxTelegramHeader.HeaderLength);
     stream.WriteByte(knxTelegramHeader.ProtocolVersion);
     stream.WriteByte((byte)(knxTelegramHeader.ServiceType >> 8));
     stream.WriteByte((byte)(knxTelegramHeader.ServiceType & 255));
     stream.WriteByte((byte)(knxTelegramHeader.TotalLength >> 8));
     stream.WriteByte((byte)(knxTelegramHeader.TotalLength & 255));
 }
Ejemplo n.º 5
0
        public static void Serialize(KnxTunnelingAcknowledge knxTunnelingAcknowledge, MemoryStream memoryStream)
        {
            memoryStream.SetLength(0);
            memoryStream.Seek(6, SeekOrigin.Begin);
            SerializeCommonConnectionHeader(knxTunnelingAcknowledge.ChannelId, knxTunnelingAcknowledge.SequenceNumber, memoryStream);
            memoryStream.Seek(0, SeekOrigin.Begin);
            var header = new KnxTelegramHeader(6, 0x10, 0x421, (ushort)memoryStream.Length);

            Serialize(header, memoryStream);
        }
Ejemplo n.º 6
0
        public static void Serialize(KnxConnectionStateRequest knxConnectionStateRequest, MemoryStream stream)
        {
            stream.SetLength(0);
            stream.Seek(6, SeekOrigin.Begin);
            stream.WriteByte(knxConnectionStateRequest.ChannelId);
            stream.WriteByte(0);
            Serialize(knxConnectionStateRequest.EndPoint, stream);
            stream.Seek(0, SeekOrigin.Begin);
            var header = new KnxTelegramHeader(6, 0x10, 0x207, (ushort)stream.Length);

            Serialize(header, stream);
        }
Ejemplo n.º 7
0
        private static KnxTelegramPayload ParseTunnelingRequest(KnxTelegramHeader arg1, byte[] arg2)
        {
            var dataLength = arg2[18] & 15;
            var cemiFrame  = new CemiFrame(
                (CemiFrame.MessageCodes)arg2[10],
                (CemiFrame.Control1Flags)arg2[12],
                (CemiFrame.Control2Flags)arg2[13],
                IndividualAddress.FromUShort((ushort)((arg2[14] << 8) + arg2[15])),
                GroupAddress.FromUShort((ushort)((arg2[16] << 8) + arg2[17])),
                arg2[18],
                (ushort)((arg2[19] << 8) + arg2[20]), new ArraySegment <byte>(arg2, 21, dataLength == 0 ? 0 : dataLength - 1)); // protect against unknown datagrams with datalength = 0

            return(new KnxTunnelingRequest(arg2[7], arg2[8], cemiFrame));
        }
Ejemplo n.º 8
0
        internal static KnxTelegramHeader ParseKnxTelegramHeader(byte[] buffer)
        {
            if (buffer.Length < 6)
            {
                throw new ArgumentException(string.Format("Supplied buffer smaller than required header size ({0})", buffer.Length));
            }
            var knxTelegram = new KnxTelegramHeader(buffer[0], buffer[1], ToUInt16(buffer, 2), ToUInt16(buffer, 4));

            if (knxTelegram.HeaderLength != 6)
            {
                throw new ArgumentException(string.Format("Header length is not 6 but {0}", knxTelegram.HeaderLength));
            }
            if (knxTelegram.ProtocolVersion != 0x10)
            {
                throw new ArgumentException(string.Format("ProtocolVersion is not 0x10 but {0}", knxTelegram.ProtocolVersion));
            }
            return(knxTelegram);
        }
Ejemplo n.º 9
0
 public KnxTelegram(KnxTelegramHeader knxTelegramHeader, KnxTelegramPayload knxTelegramPayload)
 {
     KnxTelegramHeader  = knxTelegramHeader;
     KnxTelegramPayload = knxTelegramPayload;
 }