## 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
}
VDM_ACK = ['REQ', 'ACK', 'NAK', 'BSY']
+class SamplerateError(Exception):
+ pass
+
class Decoder(srd.Decoder):
- api_version = 2
+ api_version = 3
id = 'usb_power_delivery'
name = 'USB PD'
longname = 'USB Power Delivery'
self.putwarn('No start of packet found', 'XXX')
return -1 # No Start Of Packet
- def __init__(self, **kwargs):
+ def __init__(self):
self.samplerate = None
self.idx = 0
self.packet_seq = 0
- self.samplenum = 0
self.previous = 0
- self.oldpins = [0]
self.startsample = None
self.bits = []
self.edges = []
)
def us2samples(self, us):
- if self.samplerate is None:
- raise Exception('Need the samplerate.')
return int(us * self.samplerate / 1000000)
def decode_packet(self):
bitrate = self.samplerate*len(self.bits) / float(es - ss)
self.put(es, ss, self.out_bitrate, int(bitrate))
# Raw binary data (BMC decoded)
- self.put(es, ss, self.out_binary, (0, bytes(self.bits)))
-
- def decode(self, ss, es, data):
- if self.samplerate is None:
- raise Exception('Cannot decode without samplerate.')
- for (self.samplenum, pins) in data:
- # find edges ...
- if self.oldpins == pins:
- continue
+ self.put(es, ss, self.out_binary, [0, bytes(self.bits)])
- self.oldpins, (cc, ) = pins, pins
+ def decode(self):
+ if not self.samplerate:
+ raise SamplerateError('Cannot decode without samplerate.')
+ while True:
+ self.wait({0: 'e'})
# First sample of the packet, just record the start date
if not self.startsample: