private void ParseBuffer()
        {
            BusDataPacket packet      = new BusDataPacket();
            byte          t           = 0;
            byte          currentByte = 0;

            for (int i = 0; i < ReceiveBuffer.Count; i++)
            {
                currentByte = (byte)ReceiveBuffer[i];
                switch (i)
                {
                case 0:
                    packet.SenderType = (DeviceCategories)ReceiveBuffer[i];
                    break;

                case 1:
                    packet.SenderAddress = (byte)ReceiveBuffer[i];
                    break;

                case 2:
                    packet.DestinationType = (DeviceCategories)ReceiveBuffer[i];
                    break;

                case 3:
                    packet.DestinationAddress = (byte)ReceiveBuffer[i];
                    break;

                default:
                    packet.Payload.Add(currentByte);
                    break;
                }
            }
            if (PacketReceivedEvent != null)
            {
                PacketReceivedEvent(this, new PacketReceiverEventArgs(packet));
            }
        }
Exemple #2
0
        public static void bus_PacketReceivedEvent(object sender, EventArgs e)
        {
            PacketReceiverEventArgs EventArgs = (PacketReceiverEventArgs)e;
            BusDataPacket           p         = EventArgs.Packet;

            ExecuteShutterCommand(1, ProtocolCommands.PROTOCOL_CMD_SHUTTER_GET_CURRENT_STATE);
            ExecuteShutterCommand(2, ProtocolCommands.PROTOCOL_CMD_SHUTTER_GET_CURRENT_STATE);
            ExecuteShutterCommand(3, ProtocolCommands.PROTOCOL_CMD_SHUTTER_GET_CURRENT_STATE);
            ExecuteShutterCommand(4, ProtocolCommands.PROTOCOL_CMD_SHUTTER_GET_CURRENT_STATE);

            if (p.Payload.Count != 0)
            {
                switch ((ProtocolCommands)p.Payload[0])
                {
                case ProtocolCommands.PROTOCOL_CMD_SHUTTER_ANS_CURRENT_STATE:

                    string state = ((ShutterState)p.Payload[1]).ToString().Substring(14);

                    tl.LogMessage("SetSwitch", string.Format("Shutter {0}: {1}", p.SenderAddress.ToString(), state));
                    //throw new MethodNotImplementedException("SetSwitch");
                    throw new MethodAccessException("SetSwitch");
                }
            }
        }
 public void CreateHeader(DeviceCategories srcDeviceCategory, byte srcAddress, DeviceCategories destDeviceCategory, byte destAddress)
 {
     txPacket = new BusDataPacket(srcDeviceCategory, srcAddress, destDeviceCategory, destAddress);
 }
 public PacketReceiverEventArgs(BusDataPacket p)
 {
     Packet = p;
 }