示例#1
0
        /// <summary>
        /// Figures out how big this message needs to be.
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static int SizeOfMessage(PowerLineModemMessage.Message message, PowerLineModemMessage sending)
        {
            switch (message)
            {
            case PowerLineModemMessage.Message.StandardMessageReceived:
                return(9);

            case PowerLineModemMessage.Message.ExtendedMessageReceived:
                return(23);

            case PowerLineModemMessage.Message.GetImConfiguration:
                return(GetConfiguration.ResponseSize);

            case PowerLineModemMessage.Message.GetImInfo:
                return(GetInfo.ResponseSize);

            case PowerLineModemMessage.Message.AllLinkRecordResponse:
                return(AllLinkRecordResponse.ResponseSize);

            case PowerLineModemMessage.Message.SendInsteonMessage:
                if (sending != null)
                {
                    StandardMessage standard = (StandardMessage)sending;
                    if (standard.Packet.Flags.ExtendedMessage)
                    {
                        return(ExtendedMessage.ResponseSize);
                    }
                    return(StandardMessage.ResponseSize);
                }
                return(0);

            default:
                return(BasicMessage.ResponseSize);
            }
            return(0);
        }
 /// <summary>
 /// Sends the specified direct message and waits for a response.
 /// </summary>
 /// <param name="packet">Packet to send</param>
 /// <param name="response">The response from the device</param>
 /// <returns>the result of the call</returns>
 public PowerLineModemMessage.MessageResponse SendDirectInsteonPacket(InsteonPacket packet, out InsteonPacket response)
 {
     // Only one packet at a time.
     lock (this)
     {
         if (packet.Flags.MessageType != InsteonPacket.InsteonFlags.MessageTypeEnum.Direct)
         {
             response = null;
             return PowerLineModemMessage.MessageResponse.Invalid;
         }
         // Send only one direct packet at a time.
         PowerLineModemMessage.MessageResponse messageResponse;
         StandardMessage message = new StandardMessage(PowerLineModemMessage.Message.SendInsteonMessage, packet);
         this.sendingPacket = packet;
         messageResponse = port.SendCommand(message);
         if (messageResponse == PowerLineModemMessage.MessageResponse.Ack)
         {
             // We should get an ack back for this message.
             if (this.linkingEvent.WaitOne(5000))
             {
                 // See if we got back an ack or nack.
                 if (this.receivedPacket.Flags.MessageType == InsteonPacket.InsteonFlags.MessageTypeEnum.NackDirect)
                 {
                     messageResponse = PowerLineModemMessage.MessageResponse.Nack;
                 }
                 response = this.receivedPacket;
             }
             else
             {
                 response = null;
                 return PowerLineModemMessage.MessageResponse.Unknown;
             }
         }
         else
         {
             response = null;
         }
         return messageResponse;
     }
 }