- No newlines at the end of files.
- No trailing ';' characters.
- Comparison with None: Use 'is None' or 'is not None'.
- Comparison with True/False: Use 'if cond:' or 'if not cond:'.
- Various minor whitespace fixes.
(0x01, 0x02): 'Device locked',
# TODO: Lots more entries.
}
-
self.mosi_bytes = []
self.miso_bytes = []
-
if not self.reached_bit(self.curbit):
continue
self.handle_bit(can_rx)
-
# Even parity over date bits (36-58): DCF77 bit 58.
parity = self.datebits.count(1)
s = 'OK' if ((parity % 2) == 0) else 'INVALID!'
- self.putx([16, ['Date parity: %s' % s, 'DP: %s' %s]])
+ self.putx([16, ['Date parity: %s' % s, 'DP: %s' % s]])
self.datebits = []
else:
raise Exception('Invalid DCF77 bit: %d' % c)
self.state = 'WAIT FOR RISING EDGE'
self.oldval = val
-
##
## This file is part of the libsigrokdecode project.
-##
+##
## Copyright (C) 2012 Uwe Hermann <uwe@hermann-uwe.de>
## Copyright (C) 2013 Matt Ranostay <mranostay@gmail.com>
##
self.putx([0, ['Day of Week: %s' % days_of_week[self.days - 1]]])
def handle_reg_0x04(self, b): # Date
- self.date = bcd2int(b & 0x3f)
+ self.date = bcd2int(b & 0x3f)
self.putx([0, ['Days: %d' % self.date]])
def handle_reg_0x05(self, b): # Month
self.putx([0, ['Months: %d' % self.months]])
def handle_reg_0x06(self, b): # Year
- self.years = bcd2int(b & 0xff) + 2000;
+ self.years = bcd2int(b & 0xff) + 2000
self.putx([0, ['Years: %d' % self.years]])
def handle_reg_0x07(self, b): # Control Register
self.state = 'IDLE'
else:
pass # TODO?
-
else:
if self.cache[i+2] == 0 or self.cache[i+4] == 0:
self.decode_descriptor(i)
-
def metadata(self, key, value):
if key == srd.SRD_CONF_SAMPLERATE:
- self.samplerate = value;
+ self.samplerate = value
def decode(self, ss, es, data):
if not self.samplerate:
continue
# Initialize first self.olddata with the first sample value.
- if self.olddata == None:
+ if self.olddata is None:
self.olddata = data
continue
# Get the smallest distance between two transitions
# and use that to calculate the bitrate/baudrate.
- if self.first_transition == True:
+ if self.first_transition:
self.ss_edge = self.samplenum
self.first_transition = False
else:
b = self.samplenum - self.ss_edge
- if self.bitwidth == None or b < self.bitwidth:
+ if self.bitwidth is None or b < self.bitwidth:
self.bitwidth = b
bitrate = int(float(self.samplerate) / float(b))
self.putx([0, ['%d' % bitrate]])
self.ss_edge = self.samplenum
self.olddata = data
-
# Save current SDA/SCL values for the next round.
self.oldscl, self.oldsda = scl, sda
-
self.stream = -1
else:
pass # Do nothing, only add the I²C packet to our cache.
-
self.packets = []
else:
pass # Do nothing, only add the I²C packet to our cache.
-
# Calculate the sample rate.
samplerate = '?'
- if self.start_sample != None and \
- self.first_sample != None and \
+ if self.start_sample is not None and \
+ self.first_sample is not None and \
self.start_sample > self.first_sample:
samplerate = '%d' % (self.samplesreceived *
self.samplerate / (self.start_sample -
continue
# Only submit the sample, if we received the beginning of it.
- if self.start_sample != None:
+ if self.start_sample is not None:
if not self.wrote_wav_header:
self.put(0, 0, self.out_bin, (0, self.wav_header()))
self.start_sample = self.samplenum
# Save the first sample position.
- if self.first_sample == None:
+ if self.first_sample is None:
self.first_sample = self.samplenum
self.oldws = ws
-
68: ['AV', 'AV'],
}.items())),
}
-
self.state = 'IDLE'
self.old_ir = self.ir
-
55: ['Recording', 'Rec'],
}.items())),
}
-
bit = 0 if edge == 's' else None
self.edges.append(self.samplenum)
- if bit != None:
+ if bit is not None:
self.bits.append([self.samplenum, bit])
if len(self.bits) == 14:
self.reset_decoder_state()
self.old_ir = self.ir
-
# Rising TCK edges always advance the state machine.
self.advance_state_machine(tms)
- if self.first == True:
+ if self.first:
# Save the start sample and item for later (no output yet).
self.ss_item = self.samplenum
self.first = False
self.handle_rising_tck_edge(tdi, tdo, tck, tms)
self.oldtck = tck
-
handle_reg(cmd, val)
if cmd == 'DR TDO': # TODO: Assumes 'DR TDI' comes before 'DR TDO'
self.state = 'IDLE'
-
else:
# self.putx([0, ['Ignoring: %s (data=%s)' % (cmd, databyte)]])
pass
-
if self.state == 'IDLE':
# A valid LPC cycle starts with LFRAME# being asserted (low).
if lframe != 0:
- continue
+ continue
self.ss_block = self.samplenum
self.state = 'GET START'
self.lad = -1
self.handle_get_data(lad, lad_bits)
elif self.state == 'GET TAR2':
self.handle_get_tar2(lad, lad_bits)
-
self.putx([0, ['Temperature conversion status: 0x%02x' % val]])
elif self.state in [s.upper() for s in command.values()]:
self.putx([0, ['TODO \'%s\': 0x%02x' % (self.state, val)]])
-
(0x00, 0x00, 0x5c): 'AT&T Bell Labs',
(0x00, 0x00, 0x5e): 'Symetrix',
(0x00, 0x00, 0x5f): 'MIDI the World',
-
+
(0x00, 0x00, 0x60): 'Desper Products',
(0x00, 0x00, 0x61): 'Micros\'N MIDI',
(0x00, 0x00, 0x62): 'Accordians Intl',
0x7e: 'poly mode off', # mono mode on, all notes off
0x7f: 'poly mode on', # mono mode off, all notes off
}
-
self.handle_syscommon_msg(pdata)
elif self.state == 'HANDLE SYSREALTIME MSG':
self.handle_sysrealtime_msg(pdata)
-
self.putx([1, ['Temperature: %3.2f K' % kelvin]])
self.state = 'IGNORE START REPEAT'
self.data = []
-
self.ss, self.es = ss, es
# If we encountered a known chip command, enter the resp. state.
- if self.state == None:
+ if self.state is None:
self.state = mosi
self.cmdstate = 1
else:
self.putx([24, ['Unknown command: 0x%02x' % mosi]])
self.state = None
-
self.state = 'IDLE'
else:
pass # TODO?
-
0x16: ('RX_PW_P5', 1),
0x17: ('FIFO_STATUS', 1),
0x1c: ('DYNPD', 1),
- 0x1d: ('FEATURE', 1)
+ 0x1d: ('FEATURE', 1),
}
class Decoder(srd.Decoder):
api_version = 2
id = 'nrf24l01'
- name = 'NRF24L01(+)'
+ name = 'nRF24L01(+)'
longname = 'Nordic Semiconductor nRF24L01/nRF24L01+'
- desc = '2.4 GHz transceiver chip.'
+ desc = '2.4GHz transceiver chip.'
license = 'gplv2+'
inputs = ['spi']
outputs = ['nrf24l01']
annotations = (
- # sent from the host to the chip
- ('cmd', 'Commands send to the device.'),
- ('tx-data', 'Payload send to the device.'),
+ # Sent from the host to the chip.
+ ('cmd', 'Commands sent to the device'),
+ ('tx-data', 'Payload sent to the device'),
- # returned by the chip
- ('register', 'Registers read from the device.'),
- ('rx-data', 'Payload read from the device.'),
+ # Returned by the chip.
+ ('register', 'Registers read from the device'),
+ ('rx-data', 'Payload read from the device'),
('warning', 'Warnings'),
)
def next(self):
'''Resets the decoder after a complete command was decoded.'''
- # 'True' for the first byte after CS went low
+ # 'True' for the first byte after CS went low.
self.first = True
- # the current command, and the minimum and maximum number
- # of data bytes to follow
+ # The current command, and the minimum and maximum number
+ # of data bytes to follow.
self.cmd = None
self.min = 0
self.max = 0
- # used to collect the bytes after the command byte
- # (and the start/end sample number)
+ # Used to collect the bytes after the command byte
+ # (and the start/end sample number).
self.mb = []
self.mb_s = -1
self.mb_e = -1
'''Decodes the command byte 'b' at position 'pos' and prepares
the decoding of the following data bytes.'''
c = self.parse_command(b)
- if c == None:
+ if c is None:
self.warn(pos, 'unknown command')
return
self.cmd, self.dat, self.min, self.max = c
if self.cmd in ('W_REGISTER', 'ACTIVATE'):
- # don't output anything now, the command is merged with
- # the data bytes following it
+ # Don't output anything now, the command is merged with
+ # the data bytes following it.
self.mb_s = pos[0]
else:
self.putp(pos, self.ann_cmd, self.format_command())
'''
if type(regid) == int:
- # get the name of the register
+ # Get the name of the register.
if regid not in regs:
self.warn(pos, 'unknown register')
return
-
name = regs[regid][0]
else:
name = regid
- # multi byte register come LSByte first
+ # Multi byte register come LSByte first.
data = reversed(data)
if self.cmd == 'W_REGISTER' and ann == self.ann_cmd:
- # the 'W_REGISTER' command is merged with the following byte(s)
+ # The 'W_REGISTER' command is merged with the following byte(s).
label = '{}: {}'.format(self.format_command(), name)
else:
label = 'Reg. {}'.format(name)
if self.cmd == 'R_REGISTER':
self.decode_register(pos, self.ann_reg,
- self.dat, self.miso_bytes());
+ self.dat, self.miso_bytes())
elif self.cmd == 'W_REGISTER':
self.decode_register(pos, self.ann_cmd,
- self.dat, self.mosi_bytes());
+ self.dat, self.mosi_bytes())
elif self.cmd == 'R_RX_PAYLOAD':
self.decode_mb_data(pos, self.ann_rx,
self.miso_bytes(), 'RX payload', False)
if ptype == 'CS-CHANGE':
if data1 == 0 and data2 == 1:
- # rising edge, the complete command is transmitted, process
- # the bytes that were send after the command byte
+ # Rising edge, the complete command is transmitted, process
+ # the bytes that were send after the command byte.
if self.cmd:
- # check if we got the minimum number of data bytes
- # after the command byte
+ # Check if we got the minimum number of data bytes
+ # after the command byte.
if len(self.mb) < self.min:
self.warn((ss, ss), 'missing data bytes')
elif self.mb:
self.next()
elif ptype == 'DATA':
- mosi = data1
- miso = data2
+ mosi, miso = data1, data2
pos = (ss, es)
- if miso == None or mosi == None:
+ if miso is None or mosi is None:
raise MissingDataError('Both MISO and MOSI pins required.')
if self.first:
self.first = False
- # first MOSI byte is always the command
+ # First MOSI byte is always the command.
self.decode_command(pos, mosi)
- # first MISO byte is always the status register
+ # First MISO byte is always the status register.
self.decode_register(pos, self.ann_reg, 'STATUS', [miso])
else:
if not self.cmd or len(self.mb) >= self.max:
self.warn(pos, 'excess byte')
else:
- # collect the bytes after the command byte
+ # Collect the bytes after the command byte.
if self.mb_s == -1:
self.mb_s = ss
self.mb_e = es
else:
# self.putx([14, ['Ignoring: %s (data=%s)' % (cmd, databyte)]])
pass
-
if (time_min < 0.0000073) or (time_max > 0.000010):
self.putm([1, ['The overdrive mode presence sample time interval ' +
'(%2.1fus-%2.1fus) should be inside (7.3us, 10.0us).'
- % (time_min*1000000, time_max*1000000)]])
+ % (time_min * 1000000, time_max * 1000000)]])
def decode(self, ss, es, data):
if not self.samplerate:
self.handle_host_command(rxtx, self.cmd[rxtx][:-2])
self.cmd[rxtx] = ''
-
self.items.append(item)
self.itemcount += 1
- if self.first == True:
+ if self.first:
# Save the start sample and item for later (no output yet).
self.ss_item = self.samplenum
self.first = False
self.handle_bits(pins[1:])
else:
self.find_clk_edge(pins[0], pins[1:])
-
return
red, green, blue = self.mosi_bytes
- rgb_value = int(red) << 16
- rgb_value |= int(green) << 8
- rgb_value |= int(blue)
+ rgb_value = int(red) << 16 | int(green) << 8 | int(blue)
self.cmd_es = es
self.putx([0, ['#%.6x' % rgb_value]])
self.state = 'IDLE'
else:
pass # TODO?
-
if len(self.read_buf) < 16 + 4:
return
self.cmd_es = self.es
- self.read_buf = self.read_buf[4:] ### TODO: Document or redo.
+ self.read_buf = self.read_buf[4:] # TODO: Document or redo.
self.putx([9, ['CSD: %s' % self.read_buf]])
# TODO: Decode all bits.
self.read_buf = []
handle_response(miso)
self.state = 'IDLE'
-
raise MissingDataError('Either MISO or MOSI (or both) pins required.')
self.find_clk_edge(miso, mosi, clk, cs)
-
self.oldclk = clk
self.oldload = load
self.oldldac = ldac
-
def metadata(self, key, value):
if key == srd.SRD_CONF_SAMPLERATE:
- self.samplerate = value;
+ self.samplerate = value
# The width of one UART bit in number of samples.
self.bit_width = float(self.samplerate) / float(self.options['baudrate'])
# Save current RX/TX values for the next round.
self.oldbit[rxtx] = signal
-
self.bits, self.state = [], 'WAIT FOR SOP'
else:
pass # TODO: Error
-
self.get_bit(sym)
elif self.state == 'GET EOP':
self.get_eop(sym)
-
self.annotate("AUX1 monitoring", aux)
aux = AUX_TYPES[data[0] & 0x0f]
self.annotate("AUX2 monitoring", aux)
-