def get_dtc(self): """Returns a list of all pending DTC codes. Each element consists of a 2-tuple: (DTC code (string), Code description (string) )""" dtcLetters = ["P", "C", "B", "U"] r = self.sensor(1)[1] #data dtcNumber = r[0] mil = r[1] DTCCodes = [] print "Number of stored DTC:" + str(dtcNumber) + " MIL: " + str(mil) # get all DTC, 3 per mesg response for i in range(0, ((dtcNumber+2)/3)): self.send(GET_DTC_COMMAND) res = self.get() print "DTC result:" + res for i in range(0, 3): val1 = unhex(res[3+i*6:5+i*6]) val2 = unhex(res[6+i*6:8+i*6]) #get DTC codes from response (3 DTC each 2 bytes) val = (val1<<8)+val2 #DTC val as int if val==0: #skip fill of last packet break DTCStr=dtcLetters[(val&0xC000)>14]+str((val&0x3000)>>12)+str((val&0x0f00)>>8)+str((val&0x00f0)>>4)+str(val&0x000f) DTCCodes.append(["Active",DTCStr]) #read mode 7 self.send(GET_FREEZE_DTC_COMMAND) res = self.get() if res[:7] == "NODATA": #no freeze frame return DTCCodes print "DTC freeze result:" + res for i in range(0, 3): val1 = unhex(res[3+i*6:5+i*6]) val2 = unhex(res[6+i*6:8+i*6]) #get DTC codes from response (3 DTC each 2 bytes) val = (val1<<8)+val2 #DTC val as int if val==0: #skip fill of last packet break DTCStr=dtcLetters[(val&0xC000)>14]+str((val&0x3000)>>12)+str((val&0x0f00)>>8)+str((val&0x00f0)>>4)+str(val&0x000f) DTCCodes.append(["Passive",DTCStr]) return DTCCodes
def transaction_count(self, address=None, defaultBlock='latest'): if address is None: address = self.address params = [str(address), defaultBlock] try: hexcount = self._rpc_post('eth_getTransactionCount', params) if hexcount is not None: count = unhex(hexcount) else: return None logger.debug("Tx count: %s" % count) except Exception as e: logger.info("Failed Tx count, returning None: %s" % e) count = None return count
def abi_data(sig, data): prefix = get_prefix(sig) data_abi = hex2(prefix).rstrip('L') logger.debug("ABI prefix: %s" % data_abi) types = sig.split(':')[1][1:-1].split(',') logger.debug("ABI types: %s" % types) for i, s in enumerate(data): if isinstance(data[i], (str, unicode)) and data[i][:2] == "0x": data[i] = unhex(data[i]) logger.debug("ABI data: %s" % data) data_abi += abi.encode_abi(types, data).encode('hex') logger.debug("ABI encoded: %s" % data_abi) return data_abi
def abi_data(sig, data): prefix = get_prefix(sig) data_abi = hex(prefix).rstrip('L') logger.debug("ABI prefix: %s" % data_abi) types = sig.split(':')[1][1:-1].split(',') logger.debug("ABI types: %s" % types) for i, s in enumerate(data): if isinstance(data[i], (str, unicode)) and data[i][:2] == "0x": data[i] = unhex(data[i]) logger.debug("ABI data: %s" % data) data_abi += abi.encode_abi(types, data).encode('hex') logger.debug("ABI encoded: %s" % data_abi) return data_abi
def abi_data(fun_name, sig, data): types = [] prefix = get_prefix(fun_name, sig) data_abi = hex(prefix).rstrip('L') for i, s in enumerate(sig): if s == 's': types.append('string') elif s == 'a': types.append('int256[]') else: if isinstance(data[i], (str, unicode)) and data[i][:2] == "0x": data[i] = unhex(data[i]) types.append('int256') data_abi += abi.encode_abi(types, data).encode('hex') logger.debug("ABI data: %s" % data_abi) return data_abi
def peer_count(self): return unhex(self._rpc_post('net_peerCount', None))
def number(self): return unhex(self._rpc_post('eth_blockNumber', None))
def is_contract_at(self, address, defaultBlock='latest'): params = [address, defaultBlock] result = self._rpc_post('eth_getCode', params) if result is not None: return unhex(result) != 0 return True
def gasprice(self): result = self._rpc_post('eth_gasPrice', None) logger.debug("Got gas price: %s" % result) if result is not None: return unhex(result) return None
def is_contract_at(self, address, defaultBlock='latest'): params = [address, defaultBlock] result = self._rpc_post('eth_getCode', params) if result is not None: return unhex(result) != 0 return False
def balance_at(self, address, defaultBlock='latest'): params = [address, defaultBlock] balance = self._rpc_post('eth_getBalance', params) if balance is not None: return unhex(balance) return 0