# Path: util/hextools.py
# def bytes2hex(bytes, separator=""):
# def hex2bytes(hex):
# def bytes2string(bytes):
# def bytes(x):
# def hex(x):
# def string(x):
# def le_int_bytes(i):
# def be_int_bytes(i):
# def strip(str):
#     def __init__(self, lst, nb):
#     def __iter__(self):
#     def next(self):
# def le_u32(val):
# def u32(val):
# def be_u16(val):
# def le_int(lst):
# def be_int(lst):
# def all_FF(msg):
# def pathstring(path):
# def decode_BCD(data=[]):
# def encode_BCD(data=[]):
# def test():
# class chunks:


import sys,os.path
import logging
import inspect
import os
import shlex
import smartcard
import subprocess
import threading
import time
import zerorpc
import zmq
from optparse import OptionParser
from smartcard.Exceptions import CardConnectionException
from util import hextools
    def close(self):
        if self.proc:
            subprocess.Popen.terminate(self.proc)

class PollSimThread(threading.Thread):
    def __init__(self, pyscardRpc, index, pollRate=400):
        threading.Thread.__init__(self)
        self.pyscardRpc = pyscardRpc
        self.index = index
        self.pollRate = pollRate
        self.poll = False
        self.startTime = 0
        self.lastUpdate = 0
        self.pattern = 0
        threading.Thread.setName(self, 'PollSimThread')
        self.__lock = threading.Lock()

    def run(self):
        self.__lock.acquire()
        self.poll = True

        while (self.poll):
            self.startTime = time.time()
            if self.startTime - self.lastUpdate > (self.pollRate / 1000.0 - 0.1):
                try:
                    sw1 = self.pyscardRpc.c_transmit(hextools.hex2bytes(POLL_STATUS_PATTERN[self.pattern]),
                                                     self.index)[1]
                    if sw1 != 0x90 and self.pattern < (len(POLL_STATUS_PATTERN) - 1):
                        # Use different pattern e.g. 2G status.
                        self.pattern += 1

# Path: util/hextools.py
# def bytes2hex(bytes, separator=""):
# def hex2bytes(hex):
# def bytes2string(bytes):
# def bytes(x):
# def hex(x):
# def string(x):
# def le_int_bytes(i):
# def be_int_bytes(i):
# def strip(str):
#     def __init__(self, lst, nb):
#     def __iter__(self):
#     def next(self):
# def le_u32(val):
# def u32(val):
# def be_u16(val):
# def le_int(lst):
# def be_int(lst):
# def all_FF(msg):
# def pathstring(path):
# def decode_BCD(data=[]):
# def encode_BCD(data=[]):
# def test():
# class chunks:


# Path: sim/pyscard_rpc_ctrl.py
import sys,os.path
import logging
import inspect
import os
import shlex
import smartcard
import subprocess
import threading
import time
import zerorpc
import zmq
from optparse import OptionParser
from smartcard.Exceptions import CardConnectionException
from util import hextools

    def close(self):
        if self.proc:
            subprocess.Popen.terminate(self.proc)

class PollSimThread(threading.Thread):
    def __init__(self, pyscardRpc, index, pollRate=400):
        threading.Thread.__init__(self)
        self.pyscardRpc = pyscardRpc
        self.index = index
        self.pollRate = pollRate
        self.poll = False
        self.startTime = 0
        self.lastUpdate = 0
        self.pattern = 0
        threading.Thread.setName(self, 'PollSimThread')
        self.__lock = threading.Lock()

    def run(self):
        self.__lock.acquire()
        self.poll = True

        while (self.poll):
            self.startTime = time.time()
            if self.startTime - self.lastUpdate > (self.pollRate / 1000.0 - 0.1):
                try:
                    sw1 = self.pyscardRpc.c_transmit(hextools.hex2bytes(POLL_STATUS_PATTERN[self.pattern]),
                                                     self.index)[1]
                    if sw1 != 0x90 and self.pattern < (len(POLL_STATUS_PATTERN) - 1):
                        # Use different pattern e.g. 2G status.
                        self.pattern += 1

                except: