You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
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 )
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
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.
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.
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
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.
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Leave a comment: