コード例 #1
0
		public void TestSMaxCommandHolidayWithDateTime()
		{
			var maxSerializer = new MaxSerializer();
			var maxRfAddress = new MaxRfAddress
			{
				Bytes = new byte[] { 0x0f, 0xda, 0xed },
				HumanReadable = "0F-DA-ED"
			};

			var roomId = 1;

			var temperatureAndModeCommand = new STemperatureAndModeMaxCommand
			{
				RfAddress = maxRfAddress,
				RoomId = roomId,
				Temperature = 38,
				Mode = MaxRoomControlMode.Holiday,
				DateUntil = new DateTime(2011, 08, 29),
				TimeUntil = new TimeSpan(2, 0, 0)
			};

			var bytes = maxSerializer.Serialize(temperatureAndModeCommand);
			var base64String = Convert.ToBase64String(bytes);

			Assert.AreEqual("AARAAAAAD9rtAaadCwQ=", base64String);
		}
コード例 #2
0
		public IMaxCommand CreateTemperatureAndModeCommand(MaxRfAddress rfAddress, int roomId)
		{
			return new STemperatureAndModeMaxCommand
			{
				RfAddress = rfAddress,
				RoomId = roomId
			};
		}
コード例 #3
0
		public void TestSMaxCommand()
		{
			var maxSerializer = new MaxSerializer();
			var maxRfAddress = new MaxRfAddress
			{
				Bytes = new byte[] { 0x0f, 0xda, 0xed },
				HumanReadable = "0F-DA-ED"
			};

			var roomId = 1;

			var temperatureAndModeCommand = new STemperatureAndModeMaxCommand
			{
				RfAddress = maxRfAddress,
				RoomId = roomId,
				Temperature = 38,
				Mode = MaxRoomControlMode.Manual
			};

			var bytes = maxSerializer.Serialize(temperatureAndModeCommand);
			var base64String = Convert.ToBase64String(bytes);

			Assert.AreEqual("AARAAAAAD9rtAWY=", base64String);
		}
コード例 #4
0
		public IMaxMessage Parse(string payload)
		{
			var tokenizer = payload.Substring(2).Split(',');
			var index = tokenizer[0];
			var count = tokenizer[1];
			var dataAsString = tokenizer[2];
			var data = Convert.FromBase64String(dataAsString);

			var offset = 2;
			var roomCount = data[offset];
			offset++;

			var rooms = new List<MaxRoom>(roomCount);
			for (var i = 0; i < roomCount; i++)
			{
				var id = (int)data[offset + 0];
				offset++;

				var nameLength = data[offset];
				offset++;

				var name = Encoding.UTF8.GetString(data, offset, nameLength);
				offset += nameLength;

				var groupRfAddress = new MaxRfAddress
				{
					Bytes = data.Skip(offset).Take(3).ToArray(),
					HumanReadable = BitConverter.ToString(data, offset, 3)
				};

				offset += 3;

				var maxRoom = new MaxRoom
				{
					Id = id,
					Name = name,
					GroupRfAddress = groupRfAddress
				};

				rooms.Add(maxRoom);
			}

			int deviceCount = data[offset];
			offset++;

			var devices = new List<MaxDevice>(deviceCount);
			for (var i = 0; i < deviceCount; i++)
			{
				var maxDeviceType = (MaxDeviceType)data[offset];
				offset++;

				var radioAddress = BitConverter.ToString(data, offset, 3);
				offset += 3;
				var serialNumber = Encoding.UTF8.GetString(data, offset, 10);
				offset += 10;

				int nameLength = data[offset];
				offset++;

				var name = Encoding.UTF8.GetString(data, offset, nameLength);
				offset += nameLength;

				var roomId = (int)data[offset];
				offset++;

				var maxRoom = rooms.SingleOrDefault(room => room.Id == roomId);
				var maxDevice = new MaxDevice
				{
					SerialNumber = serialNumber,
					Name = name,
					Type = maxDeviceType,
					RfAddress = radioAddress,
					Room = maxRoom
				};

				maxRoom?.Devices.Add(maxDevice);
				devices.Add(maxDevice);
			}

			return new MMessage
			{
				Rooms = rooms,
				Devices = devices
			};
		}