Exemplo n.º 1
0
            internal static bool TryParse(byte p, out CBusHeader Header)
            {
                var addressType = Convert.ToByte(p & 0x07);

                if (Enum.IsDefined(typeof(CBusHeader_AddressType), addressType))
                {
                    Header = new CBusHeader(CBusHeader_Priority.Lowest_Class4, (CBusHeader_AddressType)addressType);
                }
                else
                {
                    Header = PP;
                }

                return(true);
            }
Exemplo n.º 2
0
 /// <summary>
 /// Multiple commands can bs strung togeather
 /// </summary>
 /// <param name="Header"></param>
 /// <param name="AppAddress"></param>
 /// <param name="Command"></param>
 public CBusLightingCommand(CBusHeader Header, byte AppAddress, params LightingCommand[] Command)
     : this(Header, AppAddress, Command.AsEnumerable())
 {
 }
Exemplo n.º 3
0
 public CBusLightingCommand(CBusHeader Header, byte AppAddress, IEnumerable <LightingCommand> CommandList)
     : base(Header, AppAddress)
 {
     base.ApplicationType = CBusProtcol.ApplicationTypes.LIGHTING;
     this.CommandList     = new List <LightingCommand>(CommandList);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Create a CBus lighting command
 /// </summary>
 /// <param name="Header">Indicates the type of message e.g. Multi or point to point etc..</param>
 /// <param name="AppAddress">Typically 0x38 but can differ</param>
 /// <param name="Command">ON or OFF etc...</param>
 /// <param name="Group"></param>
 public CBusLightingCommand(CBusHeader Header, byte AppAddress, LightingCommand.LightingCommandId Command, byte Group)
     : this(Header, AppAddress, new LightingCommand(Command, Group))
 {
 }
Exemplo n.º 5
0
        internal static bool TryParseCommand(byte[] CommandBytes, int CommandLength, out CBusLightingCommand Command)
        {
            int dataPointer = 0;

            Command = null;
            var lightingCommandList = new List <LightingCommand>();

            CBusHeader header = null;

            //Datapointer=0
            if (!CBusHeader.TryParse(CommandBytes[dataPointer++], out header))
            {
                return(false);
            }



            //Datapointer=1
            var appAddress = CommandBytes[dataPointer++];

            switch (header.AddressType)
            {
            case CBusHeader.CBusHeader_AddressType.Point_To_Multi:
                break;

            case CBusHeader.CBusHeader_AddressType.Point_To_Point:
                //Skip 1 byte address
                dataPointer++;
                break;

            case CBusHeader.CBusHeader_AddressType.Point_To_Point_Multi:
                //Skip 2 byte address
                dataPointer += 2;
                break;
            }


            //Datapointer=3
            if (CommandBytes[dataPointer] != 0x01 && CommandBytes[dataPointer] != 0x00)
            {
                return(false);
            }

            //If this byte 01 then next byte must be 00
            if (CommandBytes[dataPointer++] == 0x01)
            {
                if (CommandBytes[dataPointer++] != 0x00)
                {
                    return(false);
                }
            }



            //Process Contained Commands

            //Subtract 1 as this is the payload length excluding checksum
            if (TryProcessApplicationData(CommandBytes, (CommandLength - 1), lightingCommandList, ref dataPointer))
            {
                Command = new CBusLightingCommand(header, appAddress, lightingCommandList);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// When receiving a command from the wire parse using this method into a CBus Command
        /// </summary>
        /// <param name="CommandBytes"></param>
        /// <param name="Command"></param>
        /// <returns></returns>
        internal static bool TryParse(byte[] CommandBytes, int CommandLength, bool IsShortFormMessage, byte CBusApplicationAddress,
                                      ref int dataPointer, out CBusTriggerCommand Command)
        {
            Command = null;
            var triggerCommandList = new List <TriggerCommand>();

            CBusHeader header;

            CBusHeader.TryParse(CommandBytes[0], out header);

            //As message length includes checksum, where as we just want the payload length
            var messagePayloadLenght = (CommandLength - 1);

            //Process Contained Commands
            while (dataPointer < messagePayloadLenght)
            {
                //Most Significant Bit indicates long or short format comamnd
                if ((CommandBytes[dataPointer] & 0x80) == 0)
                {
                    //Short form command
                    byte group = 0;
                    var  triggerCommandType = TriggerCommand.TriggerCommandId.UNKNOWN;

                    if (!Enum.IsDefined(typeof(TriggerCommand.TriggerCommandId), CommandBytes[dataPointer]))
                    {
                        return(false);
                    }

                    //Lower 3 bites of command
                    //var commandLength = (commandId & 0x07);

                    triggerCommandType = (TriggerCommand.TriggerCommandId)CommandBytes[dataPointer++];
                    group = CommandBytes[dataPointer++];


                    //Add the command
                    switch (triggerCommandType)
                    {
                    case TriggerCommand.TriggerCommandId.EVENT:
                    {
                        var triggerGroup = CommandBytes[dataPointer++];
                        var Action       = CommandBytes[dataPointer++];
                        var cmd          = new TriggerCommand(triggerGroup, Action);
                        triggerCommandList.Add(cmd);
                        break;
                    }

                    //Also contain level parameter
                    case TriggerCommand.TriggerCommandId.TRIGGER_MIN:
                    case TriggerCommand.TriggerCommandId.TRIGGER_MAX:
                    case TriggerCommand.TriggerCommandId.TRIGGER_KILL:
                    {
                        var triggerGroup = CommandBytes[dataPointer++];
                        var cmd          = new TriggerCommand(triggerCommandType, triggerGroup);
                        triggerCommandList.Add(cmd);
                        break;
                    }

                    case TriggerCommand.TriggerCommandId.UNKNOWN:
                    default:
                        return(false);
                    }
                }
                else
                {
                    //Long form command, not implemented
                    break;
                }
            }

            Command = new CBusTriggerCommand(header, CBusApplicationAddress, triggerCommandList);
            return(true);
        }
Exemplo n.º 7
0
 public CBusTriggerCommand(CBusHeader Header, byte AppAddress, IEnumerable <TriggerCommand> CommandList)
     : base(Header, AppAddress)
 {
     base.ApplicationType = CBusProtcol.ApplicationTypes.TRIGGER;
     this.CommandList     = new List <TriggerCommand>(CommandList);
 }
Exemplo n.º 8
0
 static CBusHeader()
 {
     PPM = new CBusHeader(CBusHeader_Priority.Lowest_Class4, CBusHeader_AddressType.Point_To_Point_Multi);
     PM  = new CBusHeader(CBusHeader_Priority.Lowest_Class4, CBusHeader_AddressType.Point_To_Multi);
     PP  = new CBusHeader(CBusHeader_Priority.Lowest_Class4, CBusHeader_AddressType.Point_To_Point);
 }
Exemplo n.º 9
0
        /// <summary>
        /// When receiving a command from the wire parse using this method into a CBus Command
        /// </summary>
        /// <param name="CommandBytes"></param>
        /// <param name="Command"></param>
        /// <returns></returns>
        internal static bool TryParseApplicationId(byte[] CommandBytes, int CommandLength, bool IsMonitoredSALReply, bool IsShortFormMessage, out int SALDataPointer, out byte ApplicationId)
        {
            SALDataPointer = 0;
            ApplicationId  = 0;

            if (IsMonitoredSALReply)
            {
                if (IsShortFormMessage)
                {
                    if (CommandBytes[0] == 0)
                    {
                        //No Bridge, next byte is Application Id
                        ApplicationId  = CommandBytes[1];
                        SALDataPointer = 2;
                    }
                    else
                    {
                        //No Bridge, next byte is Application Id
                        ApplicationId  = CommandBytes[2];
                        SALDataPointer = 3;
                    }
                }
                else
                {
                    if (CommandBytes[0] == 0x05)
                    {
                        ApplicationId = CommandBytes[2];

                        var NumberOfRoutes = CommandBytes[3] / CBusProtcol.ROUTE_HEADER_DIVISOR;

                        SALDataPointer = 3 + NumberOfRoutes;
                        SALDataPointer++;
                    }
                    else
                    {
                        return(false);
                    }
                }

                return(true);
            }
            else
            {
                CBusHeader header;
                if (CBusHeader.TryParse(CommandBytes[0], out header))
                {
                    switch (header.AddressType)
                    {
                    case CBusHeader.CBusHeader_AddressType.Point_To_Point:
                        //NOT suported CAL data only
                        return(false);

                    case CBusHeader.CBusHeader_AddressType.Point_To_Multi:
                        ApplicationId  = CommandBytes[1];
                        SALDataPointer = 2;
                        SALDataPointer++;     //Skip trailing 0
                        break;

                    case CBusHeader.CBusHeader_AddressType.Point_To_Point_Multi:
                    {
                        var firstHopTarget = CommandBytes[1];
                        var NumberOfRoutes = CommandBytes[2] / CBusProtcol.ROUTE_HEADER_DIVISOR;

                        ApplicationId  = CommandBytes[2 + NumberOfRoutes];
                        SALDataPointer = 3 + NumberOfRoutes;
                        SALDataPointer++;
                        break;
                    }

                    default:
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }

                return(true);
            }
        }
Exemplo n.º 10
0
 protected CBusSALCommand(CBusHeader Header, byte ApplicationAddress)
 {
     this.Header             = Header;
     this.ApplicationAddress = ApplicationAddress;
 }