Beispiel #1
0
def header_and_standard_function(housecode, functionCode, dims=0):
  """Return 2 bytes encoding the given housecode, function and number of dims"""
  if not isinstance(functionCode, int):
    functionCode = UNDERSCORED_LOWERCASE_FUNCTION_TO_CODE_MAP[functionCode]
  hi = header(dims, True, False)
  lo = address_or_function_code(housecode, functionCode)
  return utils.bytes_2_str((hi, lo))
Beispiel #2
0
 def get_host():
     """
     消费者获取未爬取的IP地址
     """
     ip_str = DB.redis.blpop(RedisKey.UNFEACH_IP)
     if ip_str is None:
         return None
     ip_str = bytes_2_str(ip_str[1])
     return ip_str
Beispiel #3
0
def encodeClockBytes(housecode, theTime = datetime.datetime.now(), timerPurge=False, clearBatteryTimer=False, clearMonitoredStatus=False):

# From protocol.txt:
#
# For a CM11, the time request from the interface is:	0xa5.
# 
# The PC must then respond with the following transmission
# 
#     Note:  The bit range is backwards from what you'd expect in serial 
#     communications.  Bit 55-48 is actually the first byte transmitted,
#     etc.  To make matters worse, the bit orientation is correct within
#     the bit range, IE bits 4-7 of byte 6 _IS_ the monitored house code.
#     Further, bits 0 and 1 of byte 6 appear to be flipped.  I get a 
#     "monitor status clear" if bit 0 is set.
#     The original docs had bit 23 as part of current hours AND day.
#     DBS Jan 1, 1997
# 
#     Descriptions of bits 0-3 are now correct as shown below.
#     CWS Sep 1, 2002
# 
# Bit range	Description
# 55 to 48	timer download header (0x9b)			(byte 0)
# 47 to 40	Current time (seconds)				(byte 1)
# 39 to 32	Current time (minutes ranging from 0 to 119)    (byte 2)
# 31 to 24	Current time (hours/2, ranging from 0 to 11)	(byte 3)
# 23 to 15	Current year day (MSB is bit 15)		(byte 4+.1)
# 14 to 8		Day mask (SMTWTFS)				(byte 5-.1)
# 7 to 4		Monitored house code				(byte 6...)
# 3		Reserved
# 2		Timer purge flag 		
# 1		Battery timer clear flag
# 0		Monitored status clear flag	
# 
# The CM11a will not respond to any other transmission until its time
# request is satisfied.  Per Buzz Burrowes, sending just the header (0x9b)
# followed by some indeterminate delay of the order of 10 milliseconds
# is sufficient to satisfy the time request without having to modify the
# clock setting. (CWS May 19, 2003)
  
  x10_housecode = HOUSECODE_TO_VALUE_MAP[housecode]
  yearday = int(theTime.strftime("%j"))
  weekday = int(theTime.strftime("%w"))
  daymask = 1 << weekday
  clearFlags = 0
  if timerPurge: clearFlags |= (1 << 2)
  if clearBatteryTimer: clearFlags |= (1 << 1)
  if clearMonitoredStatus: clearFlags |= 1
  return utils.bytes_2_str([theTime.second,
                            theTime.minute + 60 * (theTime.hour & 1),
                            theTime.hour / 2,
                            yearday % 256,
                            ((yearday / 256) << 7) | daymask,
                            (x10_housecode << 4) | clearFlags])
Beispiel #4
0
 def get_range(length):
     """
     从Redis中获取指定个数的未扫描IP
     :param length: 未扫描IP的个数
     :return: 指定个数的未扫描IP地址
     """
     pipe = DB.redis.pipeline()
     pipe.lrange(RedisKey.UNSCAN_IP, 0, length - 1)
     pipe.ltrim(RedisKey.UNSCAN_IP, length, -1)
     result = pipe.execute()
     if result is None:
         return None
     return [bytes_2_str(ip) for ip in result[0]]
Beispiel #5
0
 def testHeaderAndFunction(self):
   self.assertEqual(utils.bytes_2_str((0x86, 0x64)), header_and_standard_function("A", "dim", 16))
Beispiel #6
0
 def testHeaderAndAddress(self):
   self.assertEqual(utils.bytes_2_str((0x4, 0x6E)), header_and_address("A", 2))
Beispiel #7
0
def header_and_address(housecode, address):
  """Return 2 bytes encoding the given housecode and address"""
  hi = header(0, False, False)
  lo = address_or_function_code(housecode, UNITCODE_TO_VALUE_MAP[address])
  return utils.bytes_2_str((hi, lo))