Giter Club home page Giter Club logo

bosch-control-panel-cc880p's Issues

Update the control panel to use the checksum as presented below

from typing import Tuple

data = [
   (0x16, bytes([0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01])), # 0
   (0x16, bytes([0x0C, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01])), # 1
   (0x17, bytes([0x0C, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01])), # 2
   (0x19, bytes([0x0C, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01])), # 3
   (0x19, bytes([0x0C, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01])), # 4
   (0x1b, bytes([0x0C, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01])), # 5
   (0x1c, bytes([0x0C, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01])), # 6
   (0x1c, bytes([0x0C, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01])), # 7
   (0x1d, bytes([0x0C, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01])), # 8
   (0x1f, bytes([0x0C, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01])), # 9
   (0x2f, bytes([0x0C, 0x1A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01])), # #
   (0x31, bytes([0x0C, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01])), # *
   
   (0x17, bytes([0x0C, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02])), # 11
   (0x19, bytes([0x0C, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03])), # 111
   (0x19, bytes([0x0C, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x04])), # 1111
   (0x1D, bytes([0x0C, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x04])), # 2222
   (0x18, bytes([0x0C, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02])), # 12
   (0x18, bytes([0x0C, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02])), # 21
   (0x1B, bytes([0x0C, 0x02, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02])), # 23
   (0x1B, bytes([0x0C, 0x03, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02])), # 32
   (0x1A, bytes([0x0C, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02])), # 13
   (0x1D, bytes([0x0C, 0x01, 0x02, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03])), # 123
   (0x4D, bytes([0x0C, 0x1B, 0x00, 0x1A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03])), # *0#
   (0x22, bytes([0x0C, 0x05, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02])), # 56
   
   (0x7B, bytes([0x01, 0x00, 0x00, 0x00, 0x21, 0x43, 0xFF, 0x0F, 0x00, 0x00])), # Request Status Zone1 + Zone2 + Zone8
   (0x1C, bytes([0x0E, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])), # Siren On
   (0x1D, bytes([0x0E, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])), # Siren Off
]

def odd_parity(n: int) -> bool:
   y = n ^ (n >> 1)
   y = y ^ (y >> 2)
   y = y ^ (y >> 4)
   y = y ^ (y >> 8)
   y = y ^ (y >> 16)

   if (y & 1):
       return True
   return False

def parities(data: bytes) -> Tuple[int, int]:
   odds = 0
   evens = 0
   for d in data:
       if odd_parity(d):
           odds += 1
       else:
           evens += 1

   return odds, evens

def evens(data: bytes) -> int:
   _, evens = parities(data)
   return evens

def odds(data: bytes) -> int:
   odds, _ = parities(data)
   return odds

def sum_bytes(data: bytes) -> int:
   return sum(data)

def checksum(data: bytes) -> int:
   return (sum(data) + evens(data)) & 0xFF


def main():
   for d in data:
       c = checksum(d[1])
       print("Expected: " + hex(d[0]) + " Calculated: " + hex(c))
       assert d[0] == c

if __name__ == "__main__":
   main()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.