onewire: the split of the protocol into layers works now
authorIztok Jeras <iztok.jeras@gmail.com>
Tue, 10 Jul 2012 21:14:35 +0000 (23:14 +0200)
committerIztok Jeras <iztok.jeras@gmail.com>
Sun, 15 Jul 2012 13:02:57 +0000 (15:02 +0200)
configure.ac
decoders/Makefile.am
decoders/onewire_link/Makefile.am
decoders/onewire_link/__init__.py
decoders/onewire_link/onewire_link.py
decoders/onewire_network/Makefile.am
decoders/onewire_network/__init__.py
decoders/onewire_network/onewire_network.py

index e46f2d8fb5b328445a8c84147b0be1f7af79e8cb..768e19bfd95eb9a34581187c5436eb415e7240c1 100644 (file)
@@ -170,7 +170,8 @@ AC_CONFIG_FILES([Makefile
                 decoders/uart_dump/Makefile
                 decoders/usb_signalling/Makefile
                 decoders/usb_protocol/Makefile
                 decoders/uart_dump/Makefile
                 decoders/usb_signalling/Makefile
                 decoders/usb_protocol/Makefile
-                decoders/onewire/Makefile
+                decoders/onewire_link/Makefile
+                decoders/onewire_network/Makefile
                ])
 
 AC_OUTPUT
                ])
 
 AC_OUTPUT
index b7e654e348b4c6e8452553e928859d0070f6414e..82e6b83dede03ce239ef536fcb0065a325dc3976 100644 (file)
@@ -42,5 +42,6 @@ SUBDIRS = \
        uart_dump \
        usb_signalling \
        usb_protocol \
        uart_dump \
        usb_signalling \
        usb_protocol \
-       onewire
+       onewire_link \
+       onewire_network
 
 
index 17b3b0425a1ec02fe4ff4673e34131eb633781da..b043eca77fde0b5c6518b273f2cb2a6849b85bbf 100644 (file)
@@ -18,9 +18,9 @@
 ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 ##
 
 ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 ##
 
-pkgdatadir = $(DECODERS_DIR)/onewire
+pkgdatadir = $(DECODERS_DIR)/onewire_link
 
 
-dist_pkgdata_DATA = __init__.py onewire_link.py onewire_network.py
+dist_pkgdata_DATA = __init__.py onewire_link.py
 
 CLEANFILES = *.pyc
 
 
 CLEANFILES = *.pyc
 
index 0a712ef2bbce3b3ebd946d826394de6b763a46cf..6eaeadd047aecb68a781a34feae28f350bb5541a 100644 (file)
@@ -74,5 +74,3 @@ TODO:
 '''
 
 from .onewire_link    import *
 '''
 
 from .onewire_link    import *
-from .onewire_network import *
-
index 3236f4d9e866ec3d549fc2db09c17630644f3ea9..44bc4f8bd0d0f8a641abb5e800ebda92cdb2d5c4 100644 (file)
@@ -57,8 +57,9 @@ class Decoder(srd.Decoder):
         self.state   = 'WAIT FOR FALLING EDGE'
         self.present = 0
         self.bit     = 0
         self.state   = 'WAIT FOR FALLING EDGE'
         self.present = 0
         self.bit     = 0
+        self.bit_cnt = 0
+        self.command = 0
         self.overdrive = 0
         self.overdrive = 0
-        self.cmd_cnt = 0
         # Event timing variables
         self.fall    = 0
         self.rise    = 0
         # Event timing variables
         self.fall    = 0
         self.rise    = 0
@@ -171,11 +172,11 @@ class Decoder(srd.Decoder):
                     if (self.bit):  self.state = 'WAIT FOR FALLING EDGE'
                     else         :  self.state = 'WAIT FOR RISING EDGE'
                     self.put(self.fall, self.cnt_bit[self.overdrive], self.out_ann, [0, ['BIT: %01x' % self.bit]])
                     if (self.bit):  self.state = 'WAIT FOR FALLING EDGE'
                     else         :  self.state = 'WAIT FOR RISING EDGE'
                     self.put(self.fall, self.cnt_bit[self.overdrive], self.out_ann, [0, ['BIT: %01x' % self.bit]])
-                    self.put(self.out_proto, ['BIT', self.bit])
+                    self.put(self.fall, self.cnt_bit[self.overdrive], self.out_proto, ['BIT', self.bit])
                     # Checking the first command to see if overdrive mode should be entered
                     # Checking the first command to see if overdrive mode should be entered
-                    if   (self.cmd_cnt <= 8):
-                        self.command = self.command | (self.bit << self.cmd_cnt)
-                    elif (self.cmd_cnt == 8):
+                    if   (self.bit_cnt <= 8):
+                        self.command = self.command | (self.bit << self.bit_cnt)
+                    elif (self.bit_cnt == 8):
                         if (self.command in [0x3c, 0x69]):
                             self.put(self.fall, self.cnt_bit[self.overdrive], self.out_ann, [0, ['ENTER OVERDRIVE MODE']])
                     # incrementing the bit counter
                         if (self.command in [0x3c, 0x69]):
                             self.put(self.fall, self.cnt_bit[self.overdrive], self.out_ann, [0, ['ENTER OVERDRIVE MODE']])
                     # incrementing the bit counter
@@ -195,7 +196,7 @@ class Decoder(srd.Decoder):
                         # Exit overdrive mode
                         self.put(self.fall, self.cnt_bit[self.overdrive], self.out_ann, [0, ['EXIT OVERDRIVE MODE']])
                         self.overdrive = 0
                         # Exit overdrive mode
                         self.put(self.fall, self.cnt_bit[self.overdrive], self.out_ann, [0, ['EXIT OVERDRIVE MODE']])
                         self.overdrive = 0
-                        self.cmd_cnt = 0
+                        self.bit_cnt = 0
                         self.command = 0
                     elif ((self.samplenum - self.fall > self.cnt_overdrive_reset) and (self.overdrive)):
                         # Save the sample number for the falling edge.
                         self.command = 0
                     elif ((self.samplenum - self.fall > self.cnt_overdrive_reset) and (self.overdrive)):
                         # Save the sample number for the falling edge.
index 17b3b0425a1ec02fe4ff4673e34131eb633781da..2484987ee6721be94228d2f04be9dd8db18a3a8a 100644 (file)
@@ -18,9 +18,9 @@
 ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 ##
 
 ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 ##
 
-pkgdatadir = $(DECODERS_DIR)/onewire
+pkgdatadir = $(DECODERS_DIR)/onewire_network
 
 
-dist_pkgdata_DATA = __init__.py onewire_link.py onewire_network.py
+dist_pkgdata_DATA = __init__.py onewire_network.py
 
 CLEANFILES = *.pyc
 
 
 CLEANFILES = *.pyc
 
index 0a712ef2bbce3b3ebd946d826394de6b763a46cf..991919fcb658eb1d56221c1beb2a2c648a78c9f2 100644 (file)
@@ -73,6 +73,4 @@ TODO:
 - define output protocol
 '''
 
 - define output protocol
 '''
 
-from .onewire_link    import *
 from .onewire_network import *
 from .onewire_network import *
-
index 836bce980b9c4de10d77ecdb2f25d0d34eb7dd47..5587f974e44c5f9740d43dcfd6fd7edd582ccff4 100644 (file)
@@ -77,14 +77,14 @@ class Decoder(srd.Decoder):
         [code, val] = data
 
         # State machine.
         [code, val] = data
 
         # State machine.
-        if (self.code == "RESET"):
+        if (code == "RESET"):
             self.state = "COMMAND"
             self.search = "P"
             self.bit_cnt = 0
             self.state = "COMMAND"
             self.search = "P"
             self.bit_cnt = 0
-        elif (self.code == "BIT"):
+        elif (code == "BIT"):
             if (self.state == "COMMAND"):
                 # Receiving and decoding a ROM command
             if (self.state == "COMMAND"):
                 # Receiving and decoding a ROM command
-                if (self.onewire_collect(8, val)):
+                if (self.onewire_collect(8, val, ss, es)):
                     self.put(self.net_beg, self.net_end, self.out_ann, [ANN_NETWORK,
                       ['ROM COMMAND: 0x%02x \'%s\'' % (self.data, rom_command[self.data])]])
                     if   (self.data == 0x33):  # READ ROM
                     self.put(self.net_beg, self.net_end, self.out_ann, [ANN_NETWORK,
                       ['ROM COMMAND: 0x%02x \'%s\'' % (self.data, rom_command[self.data])]])
                     if   (self.data == 0x33):  # READ ROM
@@ -106,20 +106,20 @@ class Decoder(srd.Decoder):
             elif (self.state == "GET ROM"):
                 # A 64 bit device address is selected
                 # family code (1B) + serial number (6B) + CRC (1B)
             elif (self.state == "GET ROM"):
                 # A 64 bit device address is selected
                 # family code (1B) + serial number (6B) + CRC (1B)
-                if (self.onewire_collect(64, val)):
+                if (self.onewire_collect(64, val, ss, es)):
                     self.net_rom = self.data & 0xffffffffffffffff
                     self.put(self.net_beg, self.net_end, self.out_ann, [ANN_NETWORK, ['ROM: 0x%016x' % self.net_rom]])
                     self.state = "TRANSPORT"
             elif (self.state == "SEARCH ROM"):
                 # A 64 bit device address is searched for
                 # family code (1B) + serial number (6B) + CRC (1B)
                     self.net_rom = self.data & 0xffffffffffffffff
                     self.put(self.net_beg, self.net_end, self.out_ann, [ANN_NETWORK, ['ROM: 0x%016x' % self.net_rom]])
                     self.state = "TRANSPORT"
             elif (self.state == "SEARCH ROM"):
                 # A 64 bit device address is searched for
                 # family code (1B) + serial number (6B) + CRC (1B)
-                if (self.onewire_search(64)):
+                if (self.onewire_search(64, val, ss, es)):
                     self.net_rom = self.data & 0xffffffffffffffff
                     self.put(self.net_beg, self.net_end, self.out_ann, [ANN_NETWORK, ['ROM: 0x%016x' % self.net_rom]])
                     self.state = "TRANSPORT"
             elif (self.state == "TRANSPORT"):
                 # The transport layer is handled in byte sized units
                     self.net_rom = self.data & 0xffffffffffffffff
                     self.put(self.net_beg, self.net_end, self.out_ann, [ANN_NETWORK, ['ROM: 0x%016x' % self.net_rom]])
                     self.state = "TRANSPORT"
             elif (self.state == "TRANSPORT"):
                 # The transport layer is handled in byte sized units
-                if (self.onewire_collect(8, val)):
+                if (self.onewire_collect(8, val, ss, es)):
                     self.put(self.net_beg, self.net_end, self.out_ann, [ANN_NETWORK  , ['TRANSPORT: 0x%02x' % self.data]])
                     self.put(self.net_beg, self.net_end, self.out_ann, [ANN_TRANSPORT, ['TRANSPORT: 0x%02x' % self.data]])
                     self.put(self.net_beg, self.net_end, self.out_proto, ['transfer', self.data])
                     self.put(self.net_beg, self.net_end, self.out_ann, [ANN_NETWORK  , ['TRANSPORT: 0x%02x' % self.data]])
                     self.put(self.net_beg, self.net_end, self.out_ann, [ANN_TRANSPORT, ['TRANSPORT: 0x%02x' % self.data]])
                     self.put(self.net_beg, self.net_end, self.out_proto, ['transfer', self.data])
@@ -129,16 +129,16 @@ class Decoder(srd.Decoder):
 
 
     # Link/Network layer data collector
 
 
     # Link/Network layer data collector
-    def onewire_collect (self, length, val):
+    def onewire_collect (self, length, val, ss, es):
         # Storing the sampe this sequence begins with
         if (self.bit_cnt == 1):
         # Storing the sampe this sequence begins with
         if (self.bit_cnt == 1):
-            self.net_beg = self.ss
+            self.net_beg = ss
         self.data = self.data & ~(1 << self.bit_cnt) | (val << self.bit_cnt)
         self.bit_cnt  = self.bit_cnt + 1
         # Storing the sampe this sequence ends with
         # In case the full length of the sequence is received, return 1
         if (self.bit_cnt == length):
         self.data = self.data & ~(1 << self.bit_cnt) | (val << self.bit_cnt)
         self.bit_cnt  = self.bit_cnt + 1
         # Storing the sampe this sequence ends with
         # In case the full length of the sequence is received, return 1
         if (self.bit_cnt == length):
-            self.net_end  = self.es
+            self.net_end  = es
             self.data = self.data & ((1<<length)-1)
             self.bit_cnt  = 0
             return (1)
             self.data = self.data & ((1<<length)-1)
             self.bit_cnt  = 0
             return (1)
@@ -146,10 +146,10 @@ class Decoder(srd.Decoder):
             return (0)
 
     # Link/Network layer search collector
             return (0)
 
     # Link/Network layer search collector
-    def onewire_search (self, length):
+    def onewire_search (self, length, val, ss, es):
         # Storing the sampe this sequence begins with
         if ((self.bit_cnt == 0) and (self.search == "P")):
         # Storing the sampe this sequence begins with
         if ((self.bit_cnt == 0) and (self.search == "P")):
-            self.net_beg = self.ss
+            self.net_beg = ss
         # Master receives an original address bit
         if   (self.search == "P"):
           self.data_p = self.data_p & ~(1 << self.bit_cnt) | (val << self.bit_cnt)
         # Master receives an original address bit
         if   (self.search == "P"):
           self.data_p = self.data_p & ~(1 << self.bit_cnt) | (val << self.bit_cnt)
@@ -166,7 +166,7 @@ class Decoder(srd.Decoder):
         # Storing the sampe this sequence ends with
         # In case the full length of the sequence is received, return 1
         if (self.bit_cnt == length):
         # Storing the sampe this sequence ends with
         # In case the full length of the sequence is received, return 1
         if (self.bit_cnt == length):
-            self.net_end = self.es
+            self.net_end = es
             self.data_p = self.data_p & ((1<<length)-1)
             self.data_n = self.data_n & ((1<<length)-1)
             self.data   = self.data   & ((1<<length)-1)
             self.data_p = self.data_p & ((1<<length)-1)
             self.data_n = self.data_n & ((1<<length)-1)
             self.data   = self.data   & ((1<<length)-1)