How to use the udsoncan.Filesize function in udsoncan

To help you get started, we’ve selected a few udsoncan examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pylessard / python-udsoncan / test / client / test_request_file_transfer.py View on Github external
def _test_add_file_extra_bytes_response_zero_padding_not_ok(self):
        self.udsclient.config['tolerate_zero_padding'] = False
        with self.assertRaises(InvalidResponseException):
            self.udsclient.add_file("my_file.txt", dfi= DataFormatIdentifier(compression=5, encryption=2), filesize = Filesize(uncompressed=0x222, compressed=0x111, width=4))
github pylessard / python-udsoncan / test / client / test_request_file_transfer.py View on Github external
def _test_replace_file_extra_bytes_response(self):
        with self.assertRaises(InvalidResponseException):
            self.udsclient.replace_file("my_file.txt", dfi= DataFormatIdentifier(compression=5, encryption=2), filesize = Filesize(uncompressed=0x222, compressed=0x111, width=4))              
github pylessard / python-udsoncan / test / client / test_request_file_transfer.py View on Github external
def _test_add_file_extra_bytes_response(self):
        with self.assertRaises(InvalidResponseException):
            self.udsclient.add_file("my_file.txt", dfi= DataFormatIdentifier(compression=5, encryption=2), filesize = Filesize(uncompressed=0x222, compressed=0x111, width=4))
github pylessard / python-udsoncan / test / client / test_request_file_transfer.py View on Github external
def _test_add_file_success(self):
        response = self.udsclient.add_file("my_file.txt", dfi= DataFormatIdentifier(compression=5, encryption=2), filesize = Filesize(uncompressed=0x222, compressed=0x111, width=4))
        self.assertTrue(response.valid)
        self.assertTrue(response.positive)
        self.assertEqual(response.service_data.moop_echo, 1)
        self.assertEqual(response.service_data.max_length, 0xabcd)
        self.assertEqual(response.service_data.dfi.compression, 5)
        self.assertEqual(response.service_data.dfi.encryption, 2)
        self.assertIsNone(response.service_data.filesize)     # No filesize info when doing AddFile. Only for ReadFile
        self.assertIsNone(response.service_data.dirinfo_length)
github pylessard / python-udsoncan / test / client / test_request_file_transfer.py View on Github external
def _test_replace_file_negative_response(self):
        with self.assertRaises(NegativeResponseException):
            self.udsclient.replace_file("my_file.txt", dfi= DataFormatIdentifier(compression=5, encryption=2), filesize = Filesize(uncompressed=0x222, compressed=0x111, width=4))
github pylessard / python-udsoncan / test / client / test_request_file_transfer.py View on Github external
def _test_replace_file_success(self):
        response = self.udsclient.replace_file("my_file.txt", dfi= DataFormatIdentifier(compression=5, encryption=2), filesize = Filesize(uncompressed=0x222, compressed=0x111, width=4))
        self.assertTrue(response.valid)
        self.assertTrue(response.positive)
        self.assertEqual(response.service_data.moop_echo, 3)
        self.assertEqual(response.service_data.max_length, 0xabcd)
        self.assertEqual(response.service_data.dfi.compression, 5)
        self.assertEqual(response.service_data.dfi.encryption, 2)
        self.assertIsNone(response.service_data.filesize)     # No filesize info when doing AddFile. Only for ReadFile
        self.assertIsNone(response.service_data.dirinfo_length)
github pylessard / python-udsoncan / udsoncan / services / RequestFileTransfer.py View on Github external
if len(response.data) < cursor+fsodipl:
                    raise InvalidResponseException(response, 'Missing or incomplete fileSizeCompressed in received response')

                todecode = bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00')
                for i in range(1,lfid+1):
                    todecode[-i] = response.data[cursor+fsodipl-i]
                compressed_size = struct.unpack('>q', todecode)[0]
                cursor += fsodipl
            else:
                compressed_size = None

        if has_uncompressed_filesize and response.service_data.moop_echo == cls.ModeOfOperation.ReadDir:
            response.service_data.dirinfo_length = uncompressed_size
        else:
            if has_uncompressed_filesize or has_compressed_filesize:
                response.service_data.filesize=Filesize(uncompressed = uncompressed_size, compressed=compressed_size)

        if len(response.data) > cursor:
            if response.data[cursor:] == b'\x00' * (len(response.data) - cursor) and tolerate_zero_padding:
                pass
            else:
                raise InvalidResponseException(response, 'Response payload has extra data that has no meaning')

        response.service_data = response.service_data
github pylessard / python-udsoncan / udsoncan / services / RequestFileTransfer.py View on Github external
use_dfi = moop in [cls.ModeOfOperation.AddFile, cls.ModeOfOperation.ReplaceFile, cls.ModeOfOperation.ReadFile]
        use_filesize = moop in [cls.ModeOfOperation.AddFile, cls.ModeOfOperation.ReplaceFile]
       
        if use_dfi:
            dfi = cls.normalize_data_format_identifier(dfi)
        else:
            if dfi is not None:
                raise ValueError('DataFormatIdentifier is not needed with ModeOfOperation=%d' % moop)
        
        if use_filesize:  
            if filesize is None:
                raise ValueError('A filesize must be given for this mode of operation')

            if isinstance(filesize, int):
                filesize = Filesize(filesize)

            if not isinstance(filesize, Filesize):
                raise ValueError('Given filesize must be a valid Filesize object or an integer') 

            if filesize.uncompressed is None:
                raise ValueError('Filesize needs at least an Uncompressed file size')

            if filesize.compressed is None:
                filesize = Filesize(uncompressed=filesize.uncompressed, compressed=filesize.uncompressed, width=filesize.get_width())
        else:
            if filesize is not None:
                raise ValueError('Filesize is not needed with ModeOfOperation=%d' % moop)               

        data = moop.to_bytes(1, 'big')
        data += len(path_ascii).to_bytes(2, 'big')
        data += path_ascii
github pylessard / python-udsoncan / udsoncan / services / RequestFileTransfer.py View on Github external
if use_filesize:  
            if filesize is None:
                raise ValueError('A filesize must be given for this mode of operation')

            if isinstance(filesize, int):
                filesize = Filesize(filesize)

            if not isinstance(filesize, Filesize):
                raise ValueError('Given filesize must be a valid Filesize object or an integer') 

            if filesize.uncompressed is None:
                raise ValueError('Filesize needs at least an Uncompressed file size')

            if filesize.compressed is None:
                filesize = Filesize(uncompressed=filesize.uncompressed, compressed=filesize.uncompressed, width=filesize.get_width())
        else:
            if filesize is not None:
                raise ValueError('Filesize is not needed with ModeOfOperation=%d' % moop)               

        data = moop.to_bytes(1, 'big')
        data += len(path_ascii).to_bytes(2, 'big')
        data += path_ascii
        if use_dfi:
            data += dfi.get_byte()
        if use_filesize:
            data += filesize.get_width().to_bytes(1, 'big')
            data += filesize.get_uncompressed_bytes()
            data += filesize.get_compressed_bytes()

        request = Request(cls, data=data)
        return request