2 ## This file is part of the libsigrokdecode project.
4 ## Copyright (C) 2016 Robert Bosch Car Multimedia GmbH
5 ## Authors: Oleksij Rempel
6 ## <fixed-term.Oleksij.Rempel@de.bosch.com>
7 ## <linux@rempel-privat.de>
9 ## This program is free software; you can redistribute it and/or modify
10 ## it under the terms of the GNU General Public License as published by
11 ## the Free Software Foundation; either version 2 of the License, or
12 ## (at your option) any later version.
15 import sigrokdecode as srd
18 class Decoder(srd.Decoder):
22 longname = 'Bosch SSI32 Protocol'
23 desc = 'Bosch SSI32 Protocol'
28 {'id': 'msgsize', 'desc': 'Message size', 'default': 64},
31 ('ctrl-tx', 'CTRL TX'),
33 ('ctrl-rx', 'CTRL RX'),
37 ('tx', 'TX', (0, 1,)),
38 ('rx', 'RX', (2, 3,)),
42 self.ss_cmd, self.es_cmd = 0, 0
50 self.out_ann = self.register(srd.OUTPUT_ANN)
53 self.put(self.ss_cmd, self.es_cmd, self.out_ann, data)
61 # Only first byte should have ACK data, other 3 bytes
64 self.es_cmd = self.es_array[0]
65 self.putx([1, ['> ACK:0x%02x' % (self.mosi_bytes[0])]])
66 self.putx([3, ['< ACK:0x%02x' % (self.miso_bytes[0])]])
68 def handle_ctrl(self):
70 self.tx_size = self.mosi_bytes[2]
71 self.rx_size = self.miso_bytes[2]
74 mosi = ', DATA:0x' + ''.join(format(x, '02x') for x in self.mosi_bytes[4:self.tx_size + 4])
76 miso = ', DATA:0x' + ''.join(format(x, '02x') for x in self.miso_bytes[4:self.rx_size + 4])
78 self.es_cmd = self.es_array[self.tx_size + 3]
80 ['> CTRL:0x%02x, LUN:0x%02x, SIZE:0x%02x, CRC:0x%02x%s'
81 % (self.mosi_bytes[0], self.mosi_bytes[1],
82 self.mosi_bytes[2], self.mosi_bytes[3], mosi)]])
84 self.es_cmd = self.es_array[self.rx_size + 3]
86 ['< CTRL:0x%02x, LUN:0x%02x, SIZE:0x%02x, CRC:0x%02x%s'
87 % (self.miso_bytes[0], self.miso_bytes[1],
88 self.miso_bytes[2], self.miso_bytes[3], miso)]])
90 def decode(self, ss, es, data):
92 if ptype == 'CS-CHANGE':
96 # Don't care about anything else.
101 self.ss, self.es = ss, es
103 if len(self.mosi_bytes) == 0:
105 self.mosi_bytes.append(mosi)
106 self.miso_bytes.append(miso)
107 self.es_array.append(es)
109 if self.mosi_bytes[0] & 0x80:
110 if len(self.mosi_bytes) < 4:
116 if len(self.mosi_bytes) < self.options['msgsize']: