1from __future__
import print_function
10from click
import echo, style, secho
15 if lDesign
in [defs.kDesignMaster, defs.kDesignBoreas,
16 defs.kDesignOuroboros, defs.kDesignOuroborosSim]:
17 lClockSource = defs.kFreeRun
18 elif lDesign
in [defs.kDesignEndpoint, defs.kDesignChronos,
19 defs.kDesignHades, defs.kDesignCharon]:
20 lClockSource = defs.kInput1
21 elif lDesign == defs.kDesignFanout:
22 if lBoard == defs.kBoardFIB:
23 lClockSource = defs.kInput0
24 elif lBoard == defs.kBoardPC059:
25 lClockSource = defs.kInput1
26 elif lDesign
in [defs.kDesignGaia, defs.kDesignKerberos]:
27 lClockSource = defs.kInput0
33 '''debugging helper, hooks debugger to running interpreter process'''
36 pid = os.spawnvp(os.P_NOWAIT,
37 debugger, [debugger,
'-q',
'python', str(os.getpid())])
44 os.waitpid( pid, os.WNOHANG )
51 """A parameter that works similar to :data:`click.INT` but restricts
52 the value to fit into a range. The default behavior is to fail if the
53 value falls outside the range, but it can also be silently clamped
54 between the two edges.
56 See :ref:`ranges` for an example.
58 name =
'integer range'
60 def __init__(self, min=None, max=None, clamp=False):
67 if type(value) == str:
68 if value.startswith(
'0x'):
70 elif value.startswith(
'0o'):
72 elif value.startswith(
'0b'):
80 if self.
min is not None and rv < self.
min:
82 if self.
max is not None and rv > self.
max:
84 if self.
min is not None and rv < self.
min or \
85 self.
max is not None and rv > self.
max:
87 self.fail(
'%s is bigger than the maximum valid value '
88 '%s.' % (rv, self.
max), param, ctx)
89 elif self.
max is None:
90 self.fail(
'%s is smaller than the minimum valid value '
91 '%s.' % (rv, self.
min), param, ctx)
93 self.fail(
'%s is not in the valid range of %s to %s.'
94 % (rv, self.
min, self.
max), param, ctx)
98 return 'IntRange(%r, %r)' % (self.
min, self.
max)
105 lConnectionList = aConnectionPaths.split(
';')
106 for i,c
in enumerate(lConnectionList):
107 if re.match(
'^\w+://.*', c)
is None:
108 lConnectionList[i] =
'file://'+c
109 return ';'.join(lConnectionList)
115 root_ctx = ctx.find_root()
117 return [k
for k
in devs
if incomplete
in k]
124 lValues = { n:aNode.getNode(n).read()
for n
in aNode.getNodes() }
127 aNode.getClient().dispatch()
135 Reset subnodes of aNode to aValue
137 lValues = { n:aNode.getNode(n).write(aValue)
for n
in aNode.getNodes() }
139 aNode.getClient().dispatch()
145 debugging helper, hooks debugger to running interpreter process
149 pid = os.spawnvp(os.P_NOWAIT,
150 debugger, [debugger,
'-q',
'python', str(os.getpid())])
157 os.waitpid( pid, os.WNOHANG )
165 lDevices = ctx.obj.mConnectionManager.getDevices()
166 if value
not in lDevices:
167 raise click.BadParameter(
168 'Device must be one of '+
169 ', '.join([
"'"+lId+
"'" for lId
in lDevices])
177 lDevices = ctx.obj.mConnectionManager.getDevices()
179 return [k
for k
in lDevices
if incomplete
in k]
187 return value.split(
',')
192 if value.startswith(
'0x'):
194 elif value.startswith(
'0o'):
196 elif value.startswith(
'0b'):
200 return int(value, base)
211 for item
in value.split(sep):
212 nums = item.split(dash)
220 click.ClickException(
'Invalid interval '+item)
221 numbers.extend(list(range(i,j+1)))
223 click.ClickException(
'Malformed option (comma separated list expected): {}'.format(value))
231 echo ( format_reg_table(aRegs, aHeader, sort) )
236 echo ( formatDictTable(aDict, aHdr, aSort, aFmtr) )
248 nrows = max(len(l1), len(l2));
250 l1 += [
''] * (nrows - len(l1))
251 l2 += [
''] * (nrows - len(l2))
252 fmt =
'\'{:<%d}\' \'{:<%d}\'' % (col1, col2)
253 for c1,c2
in zip(l1, l2):
258kReEscapeAnsi = re.compile(
r'(\x9B|\x1B\[)[0-?]*[ -/]*[@-~]')
261 return kReEscapeAnsi.sub(
'', line)
266 ts = int(aRawTStamp[0]) + int((aRawTStamp[1]) << 32)
268 lSubSec = ts % clock_frequency_hz
269 lSecFromEpoch = ts / clock_frequency_hz
271 return time.strftime(
"%a, %d %b %Y %H:%M:%S +0000", time.localtime(lSecFromEpoch))
277 return int(aRawTStamp[0]) + int((aRawTStamp[1]) << 32)
283 aState = aState.value()
284 return '{} ({})'.format(defs.kEpStates[aState], hex(aState))
if aState
in defs.kEpStates
else hex(aState)
301 def handler(signum, frame):
305 signal.signal(self.
sig, handler)
326 if (value & (1 << (n_bits - 1))) != 0:
327 value = value - (1 << n_bits)