Exemplo n.º 1
0
 def _resp_process(self, diag_resp):
     if diag_resp is None:
         raise UdsResponseError(
             color.format('Diag Request not response',
                          fg='red',
                          attrs='bold'))
     elif not diag_resp.IsPositiveResponse:
         raise UdsResponseError(
             color.format('Diag Request negative response[%02X]' %
                          (diag_resp.NRC),
                          fg='red',
                          attrs='bold'))
Exemplo n.º 2
0
    def _did_print(self, did, Data):
        obj = self.get(did, None)
        indent = 4
        if obj:
            cprint("%s" % (obj['DidName']), fg='green', attrs='bold')
            for dt in obj['DataList']:
                if dt['ObjType'] == 'Raw':
                    rv_str, pv_str = self._did_format(dt, Data)
                    print_list = []
                    print_list.append(' ' * indent)
                    print_list.append(
                        color.format(dt['Name'], fg='green', attrs='bold'))
                    print_list.append('-')
                    print_list.append(
                        color.format(rv_str, fg='blue', attrs='bold'))
                    print_list.append('-')
                    print_list.append(
                        color.format(pv_str, fg='yellow', attrs='bold'))
                    print_list.append(' ')
                    print_list.append(
                        color.format(dt['Unit'], fg='green', attrs='bold'))
                    print(''.join(print_list))

                elif dt['ObjType'] == 'BitField':
                    s_byte = dt['StartBit'] // 8
                    e_byte = s_byte + (dt['MaxBitSize'] // 8)
                    rv_str, pv_str = self._did_format(dt, Data)
                    SubData = Data[s_byte:e_byte]
                    print_list = []
                    print_list.append(' ' * indent)
                    print_list.append(
                        color.format(dt['Name'], fg='green', attrs='bold'))
                    print_list.append('-')
                    print_list.append(
                        color.format(rv_str, fg='blue', attrs='bold'))
                    print_list.append('-')
                    print_list.append(
                        color.format(pv_str, fg='yellow', attrs='bold'))
                    print_list.append(' ')
                    print_list.append(
                        color.format(dt['Unit'], fg='green', attrs='bold'))
                    print(''.join(print_list))
                    indent += 4
                    for pk in dt['PackList']:
                        rv_str, pv_str = self._did_bitFieldFormat(pk, SubData)
                        print_list = []
                        print_list.append(' ' * indent)
                        print_list.append(
                            color.format(dt['Name'], fg='green', attrs='bold'))
                        print_list.append('-')
                        print_list.append(
                            color.format(rv_str, fg='blue', attrs='bold'))
                        print_list.append('-')
                        print_list.append(
                            color.format(pv_str, fg='yellow', attrs='bold'))
                        print_list.append(' ')
                        print_list.append(
                            color.format(dt['Unit'], fg='green', attrs='bold'))
                        print(''.join(print_list))
                    indent -= 4
                else:
                    cprint('%s-%s' % (' '.join(['%02X' % (x)
                                                for x in Data]), ''.join(
                                                    [chr(x) for x in Data])),
                           fg='green',
                           attrs='bold')
        else:
            cprint('%s-%s' %
                   (' '.join(['%02X' % (x)
                              for x in Data]), ''.join([chr(x)
                                                        for x in Data])),
                   fg='green',
                   attrs='bold')