summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUwe Hermann <uwe@hermann-uwe.de>2014-08-16 21:17:32 +0200
committerUwe Hermann <uwe@hermann-uwe.de>2014-08-16 21:37:21 +0200
commit53908ef10d1c5e3d77c3551703fa1633303b9242 (patch)
tree8a19506f80e631654de08efb0ad733d0d4359a25
parent903e9b14c84400579e0d786b7a96e9e587b5849b (diff)
downloadlibsigrokdecode-53908ef10d1c5e3d77c3551703fa1633303b9242.tar.gz
libsigrokdecode-53908ef10d1c5e3d77c3551703fa1633303b9242.zip
ds1307: Refactoring and cleanups.
-rw-r--r--decoders/ds1307/pd.py47
1 files changed, 19 insertions, 28 deletions
diff --git a/decoders/ds1307/pd.py b/decoders/ds1307/pd.py
index 2447af5..d9aa3d5 100644
--- a/decoders/ds1307/pd.py
+++ b/decoders/ds1307/pd.py
@@ -175,6 +175,20 @@ class Decoder(srd.Decoder):
self.putd(7, 0, [8, ['RAM', 'R']])
self.putd(7, 0, [23, ['SRAM: 0x%02X' % b, '0x%02X' % b]])
+ def output_datetime(self, cls, rw):
+ # TODO: Handle read/write of only parts of these items.
+ d = '%s, %02d.%02d.%4d %02d:%02d:%02d' % (
+ days_of_week[self.days - 1], self.date, self.months,
+ self.years, self.hours, self.minutes, self.seconds)
+ self.put(self.block_start_sample, self.es, self.out_ann,
+ [cls, ['%s date/time: %s' % (rw, d)]])
+
+ def handle_reg(self, b):
+ r = self.reg if self.reg < 8 else 0x3f
+ fn = getattr(self, 'handle_reg_0x%02x' % r)
+ fn(b)
+ self.reg += 1
+
def decode(self, ss, es, data):
cmd, databyte = data
@@ -207,48 +221,25 @@ class Decoder(srd.Decoder):
self.reg = databyte
self.state = 'WRITE RTC REGS'
elif self.state == 'WRITE RTC REGS':
- # If we see a Repeated Start here, it's probably an RTC read.
+ # If we see a Repeated Start here, it's an RTC read.
if cmd == 'START REPEAT':
self.state = 'READ RTC REGS'
return
# Otherwise: Get data bytes until a STOP condition occurs.
if cmd == 'DATA WRITE':
- r = self.reg if self.reg < 8 else 0x3f
- handle_reg = getattr(self, 'handle_reg_0x%02x' % r)
- handle_reg(databyte)
- self.reg += 1
- # TODO: Check for NACK!
+ self.handle_reg(databyte)
elif cmd == 'STOP':
- # TODO: Handle read/write of only parts of these items.
- d = '%s, %02d.%02d.%4d %02d:%02d:%02d' % (
- days_of_week[self.days - 1], self.date, self.months,
- self.years, self.hours, self.minutes, self.seconds)
- self.put(self.block_start_sample, es, self.out_ann,
- [25, ['Written date/time: %s' % d]])
+ self.output_datetime(25, 'Written')
self.state = 'IDLE'
- else:
- pass # TODO
elif self.state == 'READ RTC REGS':
# Wait for an address read operation.
# TODO: We should only handle packets to the RTC slave (0x68).
if cmd == 'ADDRESS READ':
self.state = 'READ RTC REGS2'
return
- else:
- pass # TODO
elif self.state == 'READ RTC REGS2':
if cmd == 'DATA READ':
- r = self.reg if self.reg < 8 else 0x3f
- handle_reg = getattr(self, 'handle_reg_0x%02x' % r)
- handle_reg(databyte)
- self.reg += 1
- # TODO: Check for NACK!
+ self.handle_reg(databyte)
elif cmd == 'STOP':
- d = '%s, %02d.%02d.%4d %02d:%02d:%02d' % (
- days_of_week[self.days - 1], self.date, self.months,
- self.years, self.hours, self.minutes, self.seconds)
- self.put(self.block_start_sample, es, self.out_ann,
- [24, ['Read date/time: %s' % d]])
+ self.output_datetime(24, 'Read')
self.state = 'IDLE'
- else:
- pass # TODO?