示例#1
0
 public ClimateController(ClimateMode currentState)
 {
     CurrentMode            = currentState;
     _temperatureController = new TemperatureController(currentState.Temperature);
     _humidityController    = new HumidityController(currentState.Humidity);
 }
示例#2
0
 public void Add(string name, ClimateMode climateMode)
 {
     _climateModes.Add(name, climateMode);
 }
        public byte[] GeneratePacket(ILoggerService logger)
        {
            var data = new byte[] { 0x23, 0xCB, 0x26, 0x01, 0x00, 0x20, 0x08, 0x06, 0x30, 0x45, 0x67, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x1F };

            logger.Log(LogLevelEnum.Verbose, "");

            data[(int)Index.Power] = (byte)PowerMode;
            logger.Log(LogLevelEnum.Verbose, $"PWR: {DisplayByte(data[(int) Index.Power])}");
            logger.Log(LogLevelEnum.Verbose, "");

            data[(int)Index.ClimateAndISee] = (byte)((byte)ClimateMode | (byte)IseeMode);
            logger.Log(LogLevelEnum.Verbose, $"CLI: {DisplayByte((byte)ClimateMode)}");
            logger.Log(LogLevelEnum.Verbose, $"SEE: {DisplayByte((byte)IseeMode)}");
            logger.Log(LogLevelEnum.Verbose, $"CLS: {DisplayByte(data[(int)Index.ClimateAndISee])}");
            logger.Log(LogLevelEnum.Verbose, "");

            data[(int)Index.Temperature] = (byte)(Math.Max(MIN_TEMP, Math.Min(MAX_TEMP, Temperature)) - 16);
            logger.Log(LogLevelEnum.Verbose, $"TMP: {DisplayByte(data[(int)Index.Temperature])} (asked: {Temperature})");
            logger.Log(LogLevelEnum.Verbose, "");

            data[(int)Index.ClimateAndHorizontalVanne] = (byte)(ClimateMode.Version2() | (byte)VanneHorizontalMode);
            logger.Log(LogLevelEnum.Verbose, $"CLI: {DisplayByte(ClimateMode.Version2())}");
            logger.Log(LogLevelEnum.Verbose, $"HOR: {DisplayByte((byte)VanneHorizontalMode)}");
            logger.Log(LogLevelEnum.Verbose, $"CLH: {DisplayByte(data[(int)Index.ClimateAndHorizontalVanne])}");
            logger.Log(LogLevelEnum.Verbose, "");

            data[(int)Index.FanAndVerticalVanne] = (byte)((byte)FanMode | (byte)VanneVerticalMode);
            logger.Log(LogLevelEnum.Verbose, $"FAN: {DisplayByte(data[(int)Index.FanAndVerticalVanne])}");
            logger.Log(LogLevelEnum.Verbose, "");

            data[(int)Index.Clock] = TimeByte(DateTime.Now);
            logger.Log(LogLevelEnum.Verbose, $"CLK: {DisplayByte(data[(int)Index.Clock])}");
            logger.Log(LogLevelEnum.Verbose, "");

            data[(int)Index.EndTime] = TimeByte(EndTime);
            logger.Log(LogLevelEnum.Verbose, $"ETI: {DisplayByte(data[(int)Index.EndTime])} {EndTime:HH:mm}");
            logger.Log(LogLevelEnum.Verbose, "");

            data[(int)Index.StartTime] = TimeByte(StartTime);
            logger.Log(LogLevelEnum.Verbose, $"STI: {DisplayByte(data[(int)Index.StartTime])} {StartTime:HH:mm}");
            logger.Log(LogLevelEnum.Verbose, "");

            ModeTimeControlEnum timeControl;

            if (EndTime != null && StartTime != null)
            {
                timeControl = ModeTimeControlEnum.ControlBoth;
            }
            else if (EndTime != null)
            {
                timeControl = ModeTimeControlEnum.ControlEnd;
            }
            else if (StartTime != null)
            {
                timeControl = ModeTimeControlEnum.ControlStart;
            }
            else
            {
                timeControl = ModeTimeControlEnum.NoTimeControl;
            }
            data[(int)Index.TimeControlAndArea] = (byte)((byte)timeControl | (byte)AreaMode);
            logger.Log(LogLevelEnum.Verbose, $"TIC: {DisplayByte((byte)timeControl)}");
            logger.Log(LogLevelEnum.Verbose, $"AEA: {DisplayByte((byte)AreaMode)}");
            logger.Log(LogLevelEnum.Verbose, $"TCA: {DisplayByte(data[(int)Index.TimeControlAndArea])}");
            logger.Log(LogLevelEnum.Verbose, "");


            data[(int)Index.PowerfulMode] = (byte)Powerful;
            logger.Log(LogLevelEnum.Verbose, $"FUL: {DisplayByte(data[(int)Index.PowerfulMode])}");
            logger.Log(LogLevelEnum.Verbose, "");

            // CRC is a simple bits addition
            // sum every bytes but the last one
            data[(int)Index.Crc] = (byte)(data.Reverse().Skip(1).Select(x => (int)x).Sum() % (MaxMask + 1));
            logger.Log(LogLevelEnum.Verbose, $"CRC: {DisplayByte(data[(int)Index.Crc])}");
            logger.Log(LogLevelEnum.Verbose, "");

            return(data);
        }