예제 #1
0
파일: base.py 프로젝트: bverdu/onDemand
 def get_id(self):
     try:
         self.command_id += 1
         return intToByte(self.command_id)
     except ValueError:
         self.command_id = 1
         return intToByte(1)
예제 #2
0
파일: api.py 프로젝트: bverdu/onDemand
    def fill(self, byte):
        """
        fill: byte -> None

        Adds the given raw byte to this APIFrame. If this APIFrame is marked
        as escaped and this byte is an escape byte, the next byte in a call
        to fill() will be unescaped.
        """

        if self._unescape_next_byte:
            byte = intToByte(byteToInt(byte) ^ 0x20)
            self._unescape_next_byte = False
        elif self.escaped and byte == Frame.ESCAPE_BYTE:
            self._unescape_next_byte = True
            return
        self.raw_data += intToByte(byteToInt(byte))
예제 #3
0
 def moduleDisplay(self, address):
     self.__write("0101a%0.2X\r" % address)
     x = self.__addressList[address][0]
     y = self.__addressList[address][1]
     for i in range(y, y + 4):
         for j in range(x, x + 4):
             self.__write(util.intToByte(self.__colorArray[i][j]))
예제 #4
0
	def moduleDisplay(self, address):
		self.__write("0101a%0.2X\r"%address)
		x = self.__addressList[address][0]
		y = self.__addressList[address][1]
		for i in range(y,y+4):
			for j in range(x,x+4):
				self.__write(util.intToByte(self.__colorArray[i][j]))
예제 #5
0
    def fill(self, byte):
        """
        fill: byte -> None

        Adds the given raw byte to this APIFrame. If this APIFrame is marked
        as escaped and this byte is an escape byte, the next byte in a call
        to fill() will be unescaped.
        """

        if self._unescape_next_byte:
            byte = intToByte(byteToInt(byte) ^ 0x20)
            self._unescape_next_byte = False
        elif self.escaped and byte == Frame.ESCAPE_BYTE:
            self._unescape_next_byte = True
            return
        self.raw_data += intToByte(byteToInt(byte))
예제 #6
0
파일: api.py 프로젝트: bverdu/onDemand
    def escape(data):
        """
        escape: byte string -> byte string

        When a 'special' byte is encountered in the given data string,
        it is preceded by an escape byte and XORed with 0x20.
        """

        escaped_data = b""
        for byte in data:
            if intToByte(byteToInt(byte)) in Frame.ESCAPE_BYTES:
                escaped_data += Frame.ESCAPE_BYTE
                escaped_data += intToByte(0x20 ^ byteToInt(byte))
            else:
                escaped_data += intToByte(byteToInt(byte))

        return escaped_data
예제 #7
0
 def __fullDisplay(self):
     self.__write("01%0.2Xa01\r" % self.__nbModules)
     for i in range(1, self.__nbModules + 1):
         x = self.__addressList[i][0]
         y = self.__addressList[i][1]
         for i in range(y, y + 4):
             for j in range(x, x + 4):
                 self.__write(util.intToByte(self.__colorArray[i][j]))
예제 #8
0
	def __fullDisplay(self):
		self.__write("01%0.2Xa01\r"%self.__nbModules)
		for i in range (1, self.__nbModules + 1):
			x = self.__addressList[i][0]
			y = self.__addressList[i][1]
			for i in range(y,y+4):
				for j in range(x,x+4):
					self.__write(util.intToByte(self.__colorArray[i][j]))
예제 #9
0
    def escape(data):
        """
        escape: byte string -> byte string

        When a 'special' byte is encountered in the given data string,
        it is preceded by an escape byte and XORed with 0x20.
        """

        escaped_data = b""
        for byte in data:
            if intToByte(byteToInt(byte)) in Frame.ESCAPE_BYTES:
                escaped_data += Frame.ESCAPE_BYTE
                escaped_data += intToByte(0x20 ^ byteToInt(byte))
            else:
                escaped_data += intToByte(byteToInt(byte))

        return escaped_data
예제 #10
0
파일: api.py 프로젝트: bverdu/onDemand
    def checksum(self):
        """
        checksum: None -> single checksum byte

        checksum adds all bytes of the binary, unescaped data in the
        frame, saves the last byte of the result, and subtracts it from
        0xFF. The final result is the checksum
        """
        total = 0

        # Add together all bytes
        for byte in self.data:
            total += byteToInt(byte)

        # Only keep the last byte
        total = total & 0xFF

        return intToByte(0xFF - total)
예제 #11
0
    def checksum(self):
        """
        checksum: None -> single checksum byte

        checksum adds all bytes of the binary, unescaped data in the
        frame, saves the last byte of the result, and subtracts it from
        0xFF. The final result is the checksum
        """
        total = 0

        # Add together all bytes
        for byte in self.data:
            total += byteToInt(byte)

        # Only keep the last byte
        total = total & 0xFF

        return intToByte(0xFF - total)