code: def _checksum(self, msg):
          
          def carry_around_add(a, b):
              c = a + b
              return (c & 0xffff) + (c >> 16)
  
          s = 0
          for i in range(0, len(msg), 2):
              w = (msg[i] << 8) + msg[i + 1]
              s = carry_around_add(s, w)
          s = ~s & 0xffff
  
          return s
docs: Calculate the checksum of a packet.
  
          This is inspired by a response on StackOverflow here:
          https://stackoverflow.com/a/1769267/7242672
  
          Thank you to StackOverflow user Jason Orendorff.