Skip to content

Commit

Permalink
fixing deserialization of temperature values < 9
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Chuchma authored and Pavel Chuchma committed Jul 18, 2023
1 parent 0c3e94a commit ece3ba0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 25 deletions.
12 changes: 4 additions & 8 deletions doc/Samsung-HVAC-buscontrol.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,17 @@ This command is an information request. The bytes in the command are all zeroes,

| Data byte | Settings |
| :---: | :--- |
| 1 | bit 5-0 : set temperature - 9 |
| | bit 6 : always set to '1' ? |
| 2 | bit 5-0 : room temperature - 9 |
| | bit 6 : always set to '1' ? |
| 3 | bit 5-0 : output air temperature - 9 |
| | bit 6 : always set to '1' ? |
| 1 | bit 6-0 : set temperature + 55 |
| 2 | bit 6-0 : room temperature + 55 |
| 3 | bit 5-0 : output air temperature + 55 |
| 4 | <p>bit 2-0 : fan speed<br>0 = auto<br>2 = low<br>4 = medium<br>5 = high</p> |
| | <p>bit 7-3 : blade swing<br>1A = swing up/down<br>1F = blade swing off</p> |
| 5 | <p>bit 3-0 : 1 = wired control<br>2 = remote control</p> |
| | bit 4 : 1 = defrost on |
| | <p>bit 7 : 0 = power is off<br>1 = power in on</p> |
| 6 | bit 4 : 1 = filter needs cleaning |
| 7 | 0 |
| 8 | bit 5-0 : another temperature - 9 |
| | bit 6 : always set to '1' ? |
| 8 | bit 6-0 : another temperature + 55 |

### Command 53

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.chuma.hvaccontroller.device.OperatingMode;

public class Get52ResponsePacket extends AbstractPacket {
public static final int MASK_TEMPERATURE = 0x3F;
public static final int MASK_TEMPERATURE = 0x7F;
public static final int MASK_FAN_SPEED = 0x07;
public static final int MASK_ON = 0x80;
public static final int MASK_MODE_AUTO = 0x20;
Expand Down Expand Up @@ -73,7 +73,7 @@ public int getAir2Temperature() {
}

private int decodeTemperature(int byteIndex) {
return (packetData.data[byteIndex] & MASK_TEMPERATURE) + 9;
return (packetData.data[byteIndex] & MASK_TEMPERATURE) - 55;
}

public boolean isOn() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.chuma.hvaccontroller.packet.Get54ResponsePacket;
import org.chuma.hvaccontroller.packet.Get64ResponsePacket;
import org.chuma.hvaccontroller.packet.Packet;
import org.chuma.hvaccontroller.packet.PacketData;
import org.chuma.hvaccontroller.packet.PacketFactory;
import org.chuma.hvaccontroller.packet.SetPacketResponse;

Expand Down Expand Up @@ -69,7 +70,7 @@ public void parsePackets() throws Exception {
}
{
// 3 = {Get52ResponsePacket@2108} "0x20->0x84 tgtTemp:23;roomTemp:25;airTemp:25;fan:SPEED_1;on:0 auto:0 defrost:1 mode:HEAT;air2Temp:25"
Get52ResponsePacket p = (Get52ResponsePacket)packets[3];
Get52ResponsePacket p = (Get52ResponsePacket) packets[3];
Assert.assertEquals(23, p.getTargetTemperature());
Assert.assertEquals(25, p.getRoomTemperature());
Assert.assertEquals(25, p.getAirTemperature());
Expand All @@ -82,7 +83,7 @@ public void parsePackets() throws Exception {
}
{
// 180 = {Get52ResponsePacket@2400} "0x20->0x84 tgtTemp:24;roomTemp:25;airTemp:25;fan:AUTO;on:1 auto:1 defrost:0 mode:COOL;air2Temp:25"
Get52ResponsePacket p = (Get52ResponsePacket)packets[180];
Get52ResponsePacket p = (Get52ResponsePacket) packets[180];
Assert.assertEquals(24, p.getTargetTemperature());
Assert.assertEquals(25, p.getRoomTemperature());
Assert.assertEquals(25, p.getAirTemperature());
Expand All @@ -95,7 +96,7 @@ public void parsePackets() throws Exception {
}
{
// 270 = {Get52ResponsePacket@2092} "0x20->0x84 tgtTemp:24;roomTemp:24;airTemp:24;fan:SPEED_3;on:1 auto:0 defrost:0 mode:FAN;air2Temp:24"
Get52ResponsePacket p = (Get52ResponsePacket)packets[270];
Get52ResponsePacket p = (Get52ResponsePacket) packets[270];
Assert.assertEquals(24, p.getAirTemperature());
Assert.assertEquals(24, p.getTargetTemperature());
Assert.assertEquals(FanSpeed.SPEED_3, p.getFanSpeed());
Expand All @@ -106,7 +107,7 @@ public void parsePackets() throws Exception {
}
{
// 333 = {Get52ResponsePacket@2093} "0x20->0x84 tgtTemp:25;roomTemp:23;airTemp:24;fan:SPEED_1;on:1 auto:0 defrost:0 mode:HEAT;air2Temp:24"
Get52ResponsePacket p = (Get52ResponsePacket)packets[333];
Get52ResponsePacket p = (Get52ResponsePacket) packets[333];
Assert.assertEquals(25, p.getTargetTemperature());
Assert.assertEquals(24, p.getAirTemperature());
Assert.assertEquals(24, p.getAir2Temperature());
Expand All @@ -118,7 +119,7 @@ public void parsePackets() throws Exception {
}
{
// 513 = {Get52ResponsePacket@2094} "0x20->0x84 tgtTemp:25;roomTemp:22;airTemp:22;fan:SPEED_1;on:0 auto:0 defrost:0 mode:HEAT;air2Temp:22"
Get52ResponsePacket p = (Get52ResponsePacket)packets[513];
Get52ResponsePacket p = (Get52ResponsePacket) packets[513];
Assert.assertEquals(22, p.getAirTemperature());
Assert.assertEquals(25, p.getTargetTemperature());
Assert.assertEquals(FanSpeed.SPEED_1, p.getFanSpeed());
Expand All @@ -128,37 +129,37 @@ public void parsePackets() throws Exception {
}
{
// 321 = {Get53ResponsePacket@2095} "0x20->0x84 ;;;;sleep:0;;;mode:HEAT;"
Get53ResponsePacket p = (Get53ResponsePacket)packets[321];
Get53ResponsePacket p = (Get53ResponsePacket) packets[321];
Assert.assertEquals(OperatingMode.HEAT, p.getMode());
Assert.assertFalse(p.isSleepMode());
}
{
// 390 = {Get53ResponsePacket@2096} "0x20->0x84 ;;;;sleep:1;;;mode:HEAT;"
Get53ResponsePacket p = (Get53ResponsePacket)packets[390];
Get53ResponsePacket p = (Get53ResponsePacket) packets[390];
Assert.assertEquals(OperatingMode.HEAT, p.getMode());
Assert.assertTrue(p.isSleepMode());
}
{
// 393 = {Get54ResponsePacket@2097} "0x20->0x84 ;quite:0 bladePos:1"
Get54ResponsePacket p = (Get54ResponsePacket)packets[393];
Get54ResponsePacket p = (Get54ResponsePacket) packets[393];
Assert.assertFalse(p.isQuite());
Assert.assertEquals(1, p.getBladePosition());
}
{
// 357 = {Get54ResponsePacket@2098} "0x20->0x84 ;quite:1 bladePos:1"
Get54ResponsePacket p = (Get54ResponsePacket)packets[357];
Get54ResponsePacket p = (Get54ResponsePacket) packets[357];
Assert.assertTrue(p.isQuite());
Assert.assertEquals(1, p.getBladePosition());
}
{
// 324 = {Get54ResponsePacket@2742} "0x20->0x84 ;quite:0 bladePos:2"
Get54ResponsePacket p = (Get54ResponsePacket)packets[324];
Get54ResponsePacket p = (Get54ResponsePacket) packets[324];
Assert.assertFalse(p.isQuite());
Assert.assertEquals(2, p.getBladePosition());
}
{
// 348 = {SetPacketResponse@2099} "0x20->0x84 sleep:0;;temp:25 fan:SPEED_1;mode:HEAT;on:1;;quite:1;"
SetPacketResponse p = (SetPacketResponse)packets[348];
SetPacketResponse p = (SetPacketResponse) packets[348];
Assert.assertFalse(p.isSleep());
Assert.assertEquals(25, p.getTargetTemperature());
Assert.assertEquals(FanSpeed.SPEED_1, p.getFanSpeed());
Expand All @@ -168,21 +169,33 @@ public void parsePackets() throws Exception {
}
{
// 387 = {SetPacketResponse@2100} "0x20->0x84 sleep:1;;temp:25 fan:SPEED_1;mode:HEAT;on:1;;quite:0;"
SetPacketResponse p = (SetPacketResponse)packets[387];
SetPacketResponse p = (SetPacketResponse) packets[387];
Assert.assertTrue(p.isSleep());
Assert.assertFalse(p.isQuite());
}
{
// 378 = {Get64ResponsePacket@2793} "0x20->0x84 ;;unitTemp:22.80"
Get64ResponsePacket p = (Get64ResponsePacket)packets[378];
Get64ResponsePacket p = (Get64ResponsePacket) packets[378];
Assert.assertEquals(22.80, p.getUnitTemperature(), 0.001);
}
{
// 27 = {Get64ResponsePacket@2132} "0x20->0x84 ;;unitTemp:25.60"
Get64ResponsePacket p = (Get64ResponsePacket)packets[27];
Get64ResponsePacket p = (Get64ResponsePacket) packets[27];
Assert.assertEquals(25.60, p.getUnitTemperature(), 0.001);
}
pr.stop();
}
}
}

@Test
public void parseLowTemperaturePacket() throws Exception {
{
Get52ResponsePacket p = (Get52ResponsePacket) PacketFactory.Deserialize(new PacketData(new int[]{50, 32, 132, 82, 78, 80, 64, 253, 130, 12, 0, 64, 155, 52}, 100));
Assert.assertEquals("0x20->0x84 tgtTemp:23;roomTemp:25;airTemp:9;fan:SPEED_3;on:1 auto:0 defrost:0 mode:COOL;air2Temp:9", p.toString());
}
{
Get52ResponsePacket p = (Get52ResponsePacket) PacketFactory.Deserialize(new PacketData(new int[]{50, 32, 132, 82, 78, 79, 63, 253, 130, 12, 0, 63, 132, 52}, 100));
Assert.assertEquals("0x20->0x84 tgtTemp:23;roomTemp:24;airTemp:8;fan:SPEED_3;on:1 auto:0 defrost:0 mode:COOL;air2Temp:8", p.toString());
}
}
}

0 comments on commit ece3ba0

Please sign in to comment.