Exemplo n.º 1
0
 def isValidBin(binFile) :
     rv = False ;
     if PSFile.getSize(binFile) == 128*1024 :
         b = ''.join([chr(x) for x in PSFile.readBytes(binFile)]) ;
         crc = (~(binascii.crc32(reverseBit(b)))) & 0xffffffff
         if crc == 0x0 :
             rv = True ;
         else :
             print >> sys.stderr, 'Error CRC=%s' % hex(crc) ;
     return rv ;
Exemplo n.º 2
0
 def doHex2Bin(hexFile, binFile) :
     '''
     Convert Hex file to a 128KB Binary file that includes a 32-bit CRC in the topmost 4 bytes.
     This code is based on 'Figure 21 provides an example of how to calculate the CRC32 value.' from ins11681-11_500_series_z-wave_chip_programming_mode.pdf
     '''
     rv = False ;
     if PSFile.isExist(hexFile) :
         b = PSZwave.loadZwaveHex(hexFile) ;
         #Write to bin file
         PSFile.writeBytes(binFile, b) ;
         rv = True ;
     else :
         raise IOError('Not Exists %s' % hexFile) ;
     return rv ;
Exemplo n.º 3
0
        else :
            raise IOError('Not Exists %s' % hexFile) ;
        return rv ;
    @staticmethod
    def isValidBin(binFile) :
        rv = False ;
        if PSFile.getSize(binFile) == 128*1024 :
            b = ''.join([chr(x) for x in PSFile.readBytes(binFile)]) ;
            crc = (~(binascii.crc32(reverseBit(b)))) & 0xffffffff
            if crc == 0x0 :
                rv = True ;
            else :
                print >> sys.stderr, 'Error CRC=%s' % hex(crc) ;
        return rv ;

if __name__ == '__main__' :
    nvm = PSFile.readBytes('test.bin', 256) ;
    crc = PSZwave.doNvmCrc16(nvm) ;
    print hex(crc) ;
    PSFile.writeBytes('test.crc', nvm) ;
    PSFile.writeBytes('test.crc2', nvm, length=2, offset=0x7E) ;

    PSZwave.doHex2Bin('MultiSensor_Battery_slave_enhanced_232_OTA_ZW050x_EU_BOOTLOADER.hex', 'Multi.bin') ;
    try :
        PSZwave.doHex2Bin('MultiSensor_Battery_slave_enhanced_232_OTA_ZW050x_EU_BOOTLOADER.hex2', 'Multi.bin2') ;
    except IOError :
        pass ;

    print PSZwave.isValidBin('Multi.bin') ;
    print PSZwave.isValidBin('MultiSensor.bin') ;