示例#1
0
 def writeInt(self, db, index, data):
     self.connect()
     offset = index // 8
     tmpdata = bytearray(data.to_bytes(2, byteorder='big', signed=True))
     lg.debug("writeInt DB: {}, offset: {}, BinData: {}, Int: {}".format(db, offset, "b'" + (bin(tmpdata[0])[2:]).rjust(8, '0') \
                                                                        + ' ' +  (bin(tmpdata[1])[2:]).rjust(8, '0') + "'", data))
     self.__client.db_write(db, offset, tmpdata)
     self.closeConnection()
示例#2
0
 def __getWriteOffset(self, room, pos=None, diffPos=None):
     offset = self.__rooms.index(room.lower()) * self.__writeOffset
     if diffPos:
         if diffPos not in self.__temperatureDiffPos:
             ValueError("unbekante Temperaturveränderung.")
         offset += self.__temperatureDiffPos.index(diffPos.lower())
     lg.debug("room: {}, type: {}, WriteOffset: {}".format(
         room, pos, offset))
     return offset
示例#3
0
 def readInt(self, db, index):
     self.connect()
     offset = index // 8
     tmp = self.__client.db_read(db, offset, 2)
     tmpInt = int.from_bytes(tmp, byteorder='big', signed=True)
     lg.debug("readInt DB: {}, offset: {}, BinData: {}, Int: {}".format(db, offset, "b'" + (bin(tmp[0])[2:]).rjust(8, '0') \
                                                                        + ' ' +  (bin(tmp[1])[2:]).rjust(8, '0') + "'", tmpInt))
     return tmpInt
     self.closeConnection()
示例#4
0
 def clearBit(self, db, index):
     self.connect()
     offset = index // 8
     pos = index % 8
     mask = ~(1 << pos)
     tmpData = (self.__client.db_read(db, offset, 1)[0] & mask)
     lg.debug("Write DB: {}, Byte: {}, Data: {}".format(
         db, offset, bin(tmpData)))
     self.__client.db_write(db, offset, bytearray([tmpData]))
     self.closeConnection()
示例#5
0
 def readBit(self, db, index):
     self.connect()
     offset = index // 8
     pos = index % 8
     tmpdata = self.__client.db_read(db, offset, 1)[0]
     tmpret = (tmpdata & 1 << pos) >> pos
     lg.debug("Read DB: {}, Byte: {}, Bit: {}, Data: {}".format(
         db, offset, pos, tmpret))
     return tmpret
     self.closeConnection()
示例#6
0
 def __getReadOffset(self, room, pos=None, diffPos=None):
     offset = self.__rooms.index(room.lower()) * self.__readOffset
     if pos:
         if pos not in self.__temperaturePos:
             ValueError("unbekante Temperaturart.")
         offset += self.__temperaturePos.index(
             pos.lower()) * 8 * 2  # 8 * 2 = bitlength for int
     if diffPos:
         if diffPos not in self.__temperatureDiffPos:
             ValueError("unbekante Temperaturveränderung.")
         offset += self.__temperatureDiffPos.index(diffPos.lower())
     lg.debug("room: {}, type: {}, ReadOffset: {}".format(
         room, pos, offset))
     return offset
示例#7
0
 def __getWriteOffset(self, room, pos):
     offset = self.__rooms.index(room.lower()) * self.__writeOffset
     offset += self.__lightPos.index(pos.lower())
     lg.debug("room: {}, type: {}, WriteOffset: {}".format(
         room, pos, offset))
     return offset