@@ -100,27 +100,35 @@ def decode(self) -> list[Sample] | dict[str, list[int]] | str:
100100 )
101101
102102 def _parse_bits (self ) -> dict [str , list [int ]]:
103- """Parse bits format to dict of channel→bit sequences."""
103+ """Parse bits format to dict of channel→bit sequences.
104+
105+ Sigrok-cli bits format: "D0:10001\\ nD1:01110\\ n..."
106+ Each line has format "channel_name:bits"
107+
108+ Note: For large sample counts, sigrok-cli wraps bits across multiple
109+ lines with repeated channel names. We accumulate all occurrences.
110+ """
104111 text = self .data .decode ("utf-8" )
105112 lines = [line .strip () for line in text .strip ().split ("\n " ) if line .strip ()]
106113
107- # bits format is just columns of 0/1
108- # TODO: Need to determine channel mapping from somewhere
109- # For now, return as generic numbered channels
110114 result : dict [str , list [int ]] = {}
111115
112116 for line in lines :
113- # Each line might be space/comma separated bits
114- bits = [int (b ) for b in line if b in "01" ]
115- if not result :
116- # Initialize channels
117- for i , bit in enumerate (bits ):
118- result [f"CH{ i } " ] = [bit ]
119- else :
120- # Append to existing channels
121- for i , bit in enumerate (bits ):
122- if f"CH{ i } " in result :
123- result [f"CH{ i } " ].append (bit )
117+ # Bits format: "D0:10001" or "A0:10001"
118+ if ":" in line :
119+ channel_device_name , bits_str = line .split (":" , 1 )
120+ channel_device_name = channel_device_name .strip ()
121+
122+ # Map device name (D0) to user-friendly name (vcc) if available
123+ channel_name = self .channel_map .get (channel_device_name , channel_device_name )
124+
125+ # Parse bits from this line
126+ bits = [int (b ) for b in bits_str if b in "01" ]
127+
128+ # Accumulate bits for this channel (may appear on multiple lines)
129+ if channel_name not in result :
130+ result [channel_name ] = []
131+ result [channel_name ].extend (bits )
124132
125133 return result
126134
0 commit comments