package com.tado.utils.BusSniffer; public class crcBruteTest { public static final int[] istRoomTemp = {0x00, 0x00}; //static final int[] newTemp = {0x00, 0xe4}; public static final int oldTempDay = 0x00; public static final int oldTempN = 0x00; //static final int newTempDay = 0x28; //static final int newTempN = 0x22; public static int oldCRC = 0xfa; public static int oldMode = 0x00; /*public static void main(String[] args) { oldCRC = changeRoomTemp(istRoomTemp, newTemp, (byte) oldCRC); oldCRC = changeSetTemp(oldTempDay, oldTempN, newTempDay, newTempN, (byte) oldCRC); oldCRC = changeMode((byte)0x00,(byte) 0x06, (byte) oldCRC); System.out.print(String.format("0x%02X ", oldCRC)); }*/ public static int changeSetTemp(int oldTempDay, int oldTempN, int newTempDay, int newTempN, byte oldCRC){ int crc; int oldCRCNormal = oldCRC & 0xff; int tempDiffDay = (oldTempDay^newTempDay) & 0xff; int tempDiffN = (oldTempN^newTempN) & 0xff; // first calc new CRC for Day temperature if((tempDiffDay & 0x03) != 0x03){ if((tempDiffDay & 0x01) == 0x01) oldCRCNormal ^= 0x40; if((tempDiffDay & 0x02) == 0x02) oldCRCNormal ^= 0x40; } if((tempDiffDay & 0x04) == 0x04) oldCRCNormal ^= 0x80; for (int i = 0; i < 5; i++) { if(((tempDiffDay >> (3 + i)) & 0x01) == 0x01) oldCRCNormal ^= (0x19 << i); } // then calculate the new crc for the night temperature if((tempDiffN & 0x01) == 0x01) oldCRCNormal ^= 0x20; if((tempDiffN & 0x02) == 0x02) oldCRCNormal ^= 0x80; for (int i = 0; i < 6; i++) { if(((tempDiffN >> (2 + i)) & 0x01) == 0x01) oldCRCNormal ^= (0x19 << i); } // quick fix for the problem, when the difference between the day and night // temperatures is less than 10 and it is of kind x.5 //if(newTempN <= 0x14 ) if(((newTempDay ^ newTempN) & 0x01) == 0x01) oldCRCNormal ^= 0x60; crc = oldCRCNormal; return crc & 0xff; } public static int changeRoomTemp(int[] oldTemp, int[] newTemp, byte oldCRC){ int crc; int oldCrcNormal = oldCRC & 0xff; int[] tempDiff = new int[oldTemp.length]; tempDiff[0] = ((oldTemp[0]^newTemp[0]) & 0xff); tempDiff[1] = ((oldTemp[1]^newTemp[1]) & 0xff); // first we make MSB oldCrcNormal ^= (tempDiff[0] << 2); // now LSB from IST_TEMP oldCrcNormal ^= (tempDiff[1] << 3); for (int i = 0; i < 3; i++) { if(((tempDiff[1] >> (5 + i)) & 0x01) == 0x01) oldCrcNormal ^= (0x19 << i); } crc = oldCrcNormal; return crc & 0xff; } public static int changeMode(byte oldMode, byte newMode, byte oldCRC){ int crc; int modeDiff; int oldCrcNormal = oldCRC & 0xff; modeDiff = (oldMode ^ newMode) & 0xff; if((modeDiff & 0x01) == 0x01){ oldCrcNormal ^= 0x80; } for (int i = 0; i < 7; i++) { if(((modeDiff >> (i+1)) & 0x01) == 0x01) oldCrcNormal ^= (0x19 << i); } crc = oldCrcNormal; return crc & 0xff; } }