Announcement

Collapse
No announcement yet.

CRC-8-Bit

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • John Schexnaydre
    replied
    A quick copy, paste, compile and it would appear that all is working as needed. Thank you every so much!

    At 64 YO I haven't done any math that cannot be done on a four banger calculator in way to many years. I never would have decoded the diagram to come up with the polynomial generated mask (Even looking at the code I'm not sure what's going on )

    Thanks again!

    John

    Leave a comment:


  • John Schexnaydre
    replied
    From here it looks like what I need. I was just looking for a step in the right direction, and here I have code!

    I'm out of the office most of Tue, but will try it as soon as I can on return.

    Again many Thanks!

    John

    Leave a comment:


  • Paul Dixon
    replied
    John,
    that circuit was vital to the solution. It doesn't implement the CRC is the same way usually described.

    Try this code, it's written to show how to do it rather than for speed. It appears to do what you want.

    Paul.
    Code:
    #COMPILE EXE
    #DIM ALL
    
    FUNCTION PBMAIN () AS LONG
    
    LOCAL crc AS BYTE
    LOCAL inValue AS QUAD
    LOCAL bitcount AS LONG
    LOCAL NewBit AS LONG
    LOCAL mask AS LONG
    LOCAL MAC AS QUAD
    LOCAL human AS STRING
    
    
    MAC=&h78100BFFE3    'your MAC address
    'MAC=&h00ACD8945F
    
    'polynomial is X^8 + X^7 + X^4 + X^3 + X +1
    'which equals this:  1*x^8 + 1*x^7 + 0*x^6 + 0*x^5 + 1*x^4 + 1*x^3 + 0*x^2 + 1*x^1 + 1*x^0
    '                    1       1       0       0       1       1       0       1       1      which gives the mask
    mask = &b110011011
    
    inValue = MAC
    crc = &hffffffff          'set to all ones as required
    
    
    'shift in MSB first
    FOR bitcount=1 TO 40
        NewBit = BIT(inValue,39) XOR BIT(crc,7)   'bit 39 is the most significant bit
                                                  'bit 7 is the crc msb (remember bits are numbered from 0, not 1)
        SHIFT LEFT inValue,1       'shift up the input value one bit
        
        IF NewBit = 1 THEN
            'need to xor stuff
            SHIFT LEFT crc,1           'shift up the current crc
            crc = crc XOR mask         'invert those bits that need it
            
        ELSE
            SHIFT LEFT crc,1           'shift up the current crc
            
        END IF
                
    NEXT
    
    PRINT "CRC is ";HEX$(crc),crc
    
    
    '"human readable form"
    human = RIGHT$("0000000000"+TRIM$(STR$(MAC AND &h0FFFFFFFF)),10)
    human = LEFT$(human,5)+"-"+RIGHT$(human,5)
    human = RIGHT$("000"+TRIM$(STR$(MAC \&h100000000)),3)+ "-" + human + "-"+ RIGHT$("000"+TRIM$(STR$(crc)),3)
    
    PRINT "human readable form is ";human
    
                   WAITKEY$
    END FUNCTION

    Leave a comment:


  • John Schexnaydre
    replied
    shift register circuit

    Image
    Attached Files

    Leave a comment:


  • John Schexnaydre
    replied
    Thanks for the replies.

    I put into my post all the information I have. Sorry.
    There is a drawing of the shift register circuit, but I'm not sure it will help.
    I will post in on Monday.

    I have requested more details from the equipment manufacturer, but as a third party, I'm not sure if I will even hear back or not.

    Thanks again!

    John

    Leave a comment:


  • Paul Dixon
    replied
    John,
    nor the converting of the MAC to a readable format
    It looks like this code does that.. but you'll have to add the CRC to the end when you find it.
    Code:
    FUNCTION PBMAIN () AS LONG
    
    LOCAL MAC AS QUAD
    LOCAL human AS STRING
    
    MAC=&h78100BFFE3    'your MAC address
    MAC=&h00ACD8945F
            
    human = RIGHT$("0000000000"+TRIM$(STR$(MAC AND &h0FFFFFFFF)),10)
    human = LEFT$(human,5)+"-"+RIGHT$(human,5)
    human = RIGHT$("000"+TRIM$(STR$(MAC \&h100000000)),3)+ "-" + human
    
    PRINT "human readable form is ";human
    
    WAITKEY$
    END FUNCTION
    It would help if you could provide a link to a description of how the CRC is supposed to be generated.

    Paul.

    Leave a comment:


  • Wayne Diamond
    replied
    John that's somewhat vague information ... checksums (even if only 8 bits) need to be 100% accurate - that is afterall their purpose, so nothing can be left to chance/guesses. I think you're going to have to submit more detailed information about the checksum algorithm if you want anybody to be able to help you

    Leave a comment:


  • John Schexnaydre
    started a topic CRC-8-Bit

    CRC-8-Bit

    I am working on a new interface that has a piece within it that I have no experience. I am posting here in the hope that one of you with experience in this area can point me in the right direction.

    Basically I’m working on calculating a CRC for a MAC address. The documentation is not very clear and I have completed an internet search on the subject. I have found many online CRC calculators and much source code, but none seems to be what I need. In the PowerBASIC forums I found several nice 32 CRC but do not understand the theory well enough to modify.

    This is a key description of doing the calculation:

    The unit address has an 8 bit checksum. The checksum is calculated over the 40 bit unit using CRC with the generator polynomial,

    G(X)= X^8 + X^7 + X^4 + X^3 + X +1.

    The CRC is calculated using a shift register circuit. The register is first preset to all ones. Then the 40-bit unit address is shifted into the circuit most significant bit first. After the last (least significant) bit is shifted into the circuit, the value within the 8-bit circuit is the CRC of the address.

    Examples:
    Code:
    MAC              	Human Readable format
    78100BFFE3  		120-02692-21859-211
    00ACD8945F              000-28998-74911-239

    The last 3 digits of the readable format is the CRC as far as I can tell.
    I have not had any luck calculating the CRC nor the converting of the MAC to a readable format. The shifting makes no sense to me. It would seem that you would have the same results just putting the last 8 bits into the register. Something else going on I’m sure.

    Thanks
    John
Working...
X