Exemple #1
0
        /// <summary>
        /// 处理空调数据
        /// </summary>
        /// <param name="num">在线数</param>
        /// <param name="index">索引</param>
        /// <param name="data">数据</param>
        /// <param name="type">传感器类型</param>
        /// <returns></returns>
        private int ProcessAir(int num, int index, byte[] data, int type)
        {
            for (int i = 0; i < num; i++)
            {
                AirConditioning airConditioning = new AirConditioning();
                airConditioning.Id = Convert.ToString(data[index++], 16);
                byte height = data[index++];
                airConditioning.State  = ((height >> 7) & 0x01) == 1 ? StateType.StateOpen : StateType.StateClose;
                airConditioning.IsOpen = airConditioning.State == StateType.StateOpen;
                byte low = data[index++];
                if (height == 0 && low == 0)
                {
                    airConditioning.Online = StateType.Offline;
                }
                else
                {
                    airConditioning.Online = StateType.Online;
                }
                airConditioning.IsOpen = height >> 7 == 1;
                int model = height >> 4;
                switch (model)
                {
                case 0:
                    airConditioning.Model = "自动";
                    break;

                case 1:
                    airConditioning.Model = "制冷";
                    break;

                case 2:
                    airConditioning.Model = "除湿";
                    break;

                case 3:
                    airConditioning.Model = "送风";
                    break;

                case 4:
                    airConditioning.Model = "制热";
                    break;
                }
                airConditioning.Speed     = (height >> 2) & 3;
                airConditioning.SweepWind = height >> 1 == 1 ? "扫风" : "不扫风";
                float val = (0x0f & low);
                airConditioning.Value        = val + 16 + "℃";
                airConditioning.Name         = "空调";
                airConditioning.Controllable = true;
                airConditioning.Type         = type;
                Sensors.Add(airConditioning);
            }
            return(index);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            var tv = new TV();
            var airConditioning = new AirConditioning();

            var tvOnCommand     = new TvOnCommand(tv);
            var airStartCommand = new AirConditioningStartCommand(airConditioning, 21d);

            var pult = new Pult
            {
                BlueBtnCommand = tvOnCommand,
                RedBtnCommand  = airStartCommand
            };

            pult.BlueBtnPress();
            pult.RedButtonPress();

            Console.ReadKey();
        }
 public AirConditioningStartCommand(AirConditioning airConditioning, double temperature)
 {
     _airConditioning = airConditioning;
     _temperature     = temperature;
 }