Skip to content

Instantly share code, notes, and snippets.

@mac-zhou
Last active January 24, 2019 07:12
Show Gist options
  • Save mac-zhou/eb9e6247ec9a50a8a9b6eb468149a181 to your computer and use it in GitHub Desktop.
Save mac-zhou/eb9e6247ec9a50a8a9b6eb468149a181 to your computer and use it in GitHub Desktop.
midea air conditioning
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="midea air conditioning">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS TEST</title>
</head>
<body>
<script>
function decimalToHexString(number) {
if (number < 0) {
number = 0xFFFFFFFF + number + 1;
}
return number.toString(16).toUpperCase();
}
function getBit(pBytes, pIndex, pBitIndex) {
return _getBit(pBytes[pIndex], pBitIndex);
}
function getBits(pBytes, pIndex, pBitStartIndex, pBitEndIndex) {
//console.log(pBytes);
return _getBits(pBytes[pIndex], pBitStartIndex, pBitEndIndex);
}
function _getBits(pByte, pStartIndex, pEndIndex) {
//console.log(pByte);
if (pStartIndex > pEndIndex) {
return _getBits(pByte, pEndIndex, pStartIndex);
}
var tempVal = 0x00;
for (var i = pStartIndex; i <= pEndIndex; i++) {
tempVal = tempVal | _getBit(pByte, i) << (i - pStartIndex);
}
return tempVal;
}
function _getBit(pByte, pIndex) {
//console.log((pByte >> pIndex) & 0x01);
return (pByte >> pIndex) & 0x01;
}
pReceiveMessage = [170, 32, 172, 0, 0, 0, 0, 0, 2, 2, 192, 0, 136, 102, 127, 127, 0, 0, 0, 0, 0, 82, 72, 12, 0, 89, 0, 0, 0, 0, 150, 137, 102];
//console.log('len:'+ pReceiveMessage.length);
var receiveMessageBody = pReceiveMessage.slice(10, pReceiveMessage.length - 1);
// console.log('receiveMessageBody:' + receiveMessageBody);
if (receiveMessageBody[0] == 0xC0) {
console.log('MessageBody: ' + receiveMessageBody);
}
settingMode = getBits(receiveMessageBody, 2, 5, 7);
runningState = getBit(receiveMessageBody, 1, 0);
settingTemperature = getBits(receiveMessageBody, 2, 0, 3);
settingTemperature = settingTemperature + 16;
if (settingTemperature > 30) {
settingTemperature = 26;
}
if (settingTemperature < 17) {
settingTemperature = 26;
}
console.log(' 是否开机: ' + runningState + ' 模式: ' + settingMode + ' 温度 ' + settingTemperature);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment