VTI Instruments Corp.
340
EX1629 Onboard Memory
{
printf("%02X ", pkt[i]);
}
printf("\n");
return;
}
CRC Checking
The CRC check function is called to calculate a CRC16 for the written data and the read data on
the DS2431. Here is the code for, and a brief explanation of, this function:
unsigned int CRCcalc(uint8_t *pkt, int offset, int len)
{
int i,j,k;
uint8_t byte;
unsigned int r = 0;
for (k = (offset-1); k < (( len)-1) ; k++) {
//CRC16 CALCULATION
byte = pkt[k];
for(i=0;i!=8;byte>>=1,i++)
{
j=(byte^r)&1;
r>>=1;
if(j)
r^=0xa001;
}
}
r = ( ((r & 0x00FF) << 8) | ((r & 0xFF00) >> 8)); //bit-swapping
for endian-ness
r = (uint16_t)~r; //inverting to match MLAN
printf("CRC16: %02X\n", r);
return r;
}
The function first calculates a normal CRC16 and then does a bit-shift operation to swap the top
and bottom halves of the CRC bytes (due to platform endian-ness) before inverting the CRC.
This is what the MLAN bus master will return to us on a little-endian host computer, like an x86
CPU (Intel or AMD): a byte-swapped, inverted CRC16. This way, the CRC16 value can be
visually compared instead of having to do bitwise operations on what the MLAN device gives us.
Version Information
The last function which has not yet been discussed is the REPEATER_TEST function. The
purpose of this function is to query the MLAN command repeater inside the EX1629 and retrieve
several items of data from it, including the version of the MLAN protocol it implements and the
vendor identification string.
NOTE
The version and vendor strings will both come back as null-terminated strings of hexadecimal
digits, as the same PrintPacket function is used to print them as is used for the rest of the packets.
For reference, the ML100 MLAN version string should appear as 4D 4C 31 30 30 00.
Содержание EX1629
Страница 310: ...VTI Instruments Corp 310 EX1629 Command Set...
Страница 342: ...VTI Instruments Corp 342 EX1629 Onboard Memory...