]> sigrok.org Git - libsigrokdecode.git/blobdiff - decoders/onewire_network/pd.py
avr_isp: Add more parts
[libsigrokdecode.git] / decoders / onewire_network / pd.py
index 23402a63ebae8dc86147b0f9a458cfebc8439478..f07110b5c1199d3c4144b88b7b4cf281294148fc 100644 (file)
 ## GNU General Public License for more details.
 ##
 ## You should have received a copy of the GNU General Public License
-## along with this program; if not, write to the Free Software
-## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+## along with this program; if not, see <http://www.gnu.org/licenses/>.
 ##
 
 import sigrokdecode as srd
 
 # Dictionary of ROM commands and their names, next state.
 command = {
-    0x33: ['Read ROM'              , 'GET ROM'   ],
-    0x0f: ['Conditional read ROM'  , 'GET ROM'   ],
-    0xcc: ['Skip ROM'              , 'TRANSPORT' ],
-    0x55: ['Match ROM'             , 'GET ROM'   ],
-    0xf0: ['Search ROM'            , 'SEARCH ROM'],
-    0xec: ['Conditional search ROM', 'SEARCH ROM'],
-    0x3c: ['Overdrive skip ROM'    , 'TRANSPORT' ],
-    0x69: ['Overdrive match ROM'   , 'GET ROM'   ],
+    0x33: ['Read ROM'                  , 'GET ROM'   ],
+    0x0f: ['Conditional read ROM'      , 'GET ROM'   ],
+    0xcc: ['Skip ROM'                  , 'TRANSPORT' ],
+    0x55: ['Match ROM'                 , 'GET ROM'   ],
+    0xf0: ['Search ROM'                , 'SEARCH ROM'],
+    0xec: ['Conditional search ROM'    , 'SEARCH ROM'],
+    0x3c: ['Overdrive skip ROM'        , 'TRANSPORT' ],
+    0x69: ['Overdrive match ROM'       , 'GET ROM'   ],
+    0xa5: ['Resume'                    , 'TRANSPORT' ],
+    0x96: ['DS2408: Disable Test Mode' , 'GET ROM'   ],
 }
 
 class Decoder(srd.Decoder):
-    api_version = 2
+    api_version = 3
     id = 'onewire_network'
     name = '1-Wire network layer'
     longname = '1-Wire serial communication bus (network layer)'
@@ -41,13 +42,17 @@ class Decoder(srd.Decoder):
     license = 'gplv2+'
     inputs = ['onewire_link']
     outputs = ['onewire_network']
+    tags = ['Embedded/industrial']
     annotations = (
-        ('text', 'Human-readable text'),
+        ('text', 'Text'),
     )
 
-    def __init__(self, **kwargs):
-        self.beg = 0
-        self.end = 0
+    def __init__(self):
+        self.reset()
+
+    def reset(self):
+        self.ss_block = 0
+        self.es_block = 0
         self.state = 'COMMAND'
         self.bit_cnt = 0
         self.search = 'P'
@@ -62,11 +67,11 @@ class Decoder(srd.Decoder):
 
     def putx(self, data):
         # Helper function for most annotations.
-        self.put(self.beg, self.end, self.out_ann, data)
+        self.put(self.ss_block, self.es_block, self.out_ann, data)
 
     def puty(self, data):
         # Helper function for most protocol packets.
-        self.put(self.beg, self.end, self.out_python, data)
+        self.put(self.ss_block, self.es_block, self.out_python, data)
 
     def decode(self, ss, es, data):
         code, val = data
@@ -126,20 +131,18 @@ class Decoder(srd.Decoder):
             if self.onewire_collect(8, val, ss, es) == 0:
                 return
             self.putx([0, ['ROM error data: 0x%02x' % self.data]])
-        else:
-            raise Exception('Invalid state: %s' % self.state)
 
     # Data collector.
     def onewire_collect(self, length, val, ss, es):
         # Storing the sample this sequence begins with.
-        if self.bit_cnt == 1:
-            self.beg = ss
+        if self.bit_cnt == 0:
+            self.ss_block = ss
         self.data = self.data & ~(1 << self.bit_cnt) | (val << self.bit_cnt)
         self.bit_cnt += 1
         # Storing the sample this sequence ends with.
         # In case the full length of the sequence is received, return 1.
         if self.bit_cnt == length:
-            self.end = es
+            self.es_block = es
             self.data = self.data & ((1 << length) - 1)
             self.bit_cnt = 0
             return 1
@@ -150,7 +153,7 @@ class Decoder(srd.Decoder):
     def onewire_search(self, length, val, ss, es):
         # Storing the sample this sequence begins with.
         if (self.bit_cnt == 0) and (self.search == 'P'):
-            self.beg = ss
+            self.ss_block = ss
 
         if self.search == 'P':
             # Master receives an original address bit.
@@ -171,7 +174,7 @@ class Decoder(srd.Decoder):
         # Storing the sample this sequence ends with.
         # In case the full length of the sequence is received, return 1.
         if self.bit_cnt == length:
-            self.end = es
+            self.es_block = 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)