Electroskill
April 15th, 2003, 12:31 PM
Hello,
How do I pass the contents of this CbyteArray to this function? I have declared a CbyteArray in Visual C++ the following manner:
CByteArray indmessage;
indmessage.Add(0xf2);
indmessage.Add(i_enter_station);
indmessage.Add(0x00);
indmessage.Add(0x00);
indmessage.Add(0x01);
indmessage.Add(0x00);
indmessage.Add(0x02);
indmessage.Add(0x00);
indmessage.Add(0x03);
indmessage.Add(0x00);
int nnumberofbytes=indmessage.GetSize();
test_crc = calc_crc16(indmessage, 5);
I have a function (referred to in a header file) that consists of the following to compute a CRC-16:
#include "stdafx.h"
WORD calc_crc16(const BYTE* pBuffer, const int nLength)
{
static const WORD CRC16_TABLE[16] =
{
0x0000, 0xCC01, 0xD801, 0x1400,
0xF001, 0x3C00, 0x2800, 0xE401,
0xA001, 0x6C00, 0x7800, 0xB401,
0x5000, 0x9C01, 0x8801, 0x4400
};
register WORD wCrc = 0;
register WORD wTemp;
register int nIndex;
for(nIndex = 0; nIndex < nLength; nIndex++, pBuffer++)
{
/* lower 4 bits */
wTemp = CRC16_TABLE[wCrc & 0x000F];
wCrc = (wCrc >> 4) & 0x0FFF;
wCrc = wCrc ^ wTemp ^ CRC16_TABLE[*pBuffer & 0x000F];
/* upper 4 bits */
wTemp = CRC16_TABLE[wCrc & 0x000F];
wCrc = (wCrc >> 4) & 0x0FFF;
wCrc = wCrc ^ wTemp ^ CRC16_TABLE[(*pBuffer >> 4) & 0x000F];
}
return wCrc;
}
My question is: how do I pass the 10 bytes I added to my CbyteArray to the CRC-16 function so that the function can compute the CRC-16 value of all 10 bytes?
I attempted this:
WORD test_crc = calc_crc16(indmessage, nnumberofbytes);
But obviously, it didn’t work.
Thank you!
Electroskill
How do I pass the contents of this CbyteArray to this function? I have declared a CbyteArray in Visual C++ the following manner:
CByteArray indmessage;
indmessage.Add(0xf2);
indmessage.Add(i_enter_station);
indmessage.Add(0x00);
indmessage.Add(0x00);
indmessage.Add(0x01);
indmessage.Add(0x00);
indmessage.Add(0x02);
indmessage.Add(0x00);
indmessage.Add(0x03);
indmessage.Add(0x00);
int nnumberofbytes=indmessage.GetSize();
test_crc = calc_crc16(indmessage, 5);
I have a function (referred to in a header file) that consists of the following to compute a CRC-16:
#include "stdafx.h"
WORD calc_crc16(const BYTE* pBuffer, const int nLength)
{
static const WORD CRC16_TABLE[16] =
{
0x0000, 0xCC01, 0xD801, 0x1400,
0xF001, 0x3C00, 0x2800, 0xE401,
0xA001, 0x6C00, 0x7800, 0xB401,
0x5000, 0x9C01, 0x8801, 0x4400
};
register WORD wCrc = 0;
register WORD wTemp;
register int nIndex;
for(nIndex = 0; nIndex < nLength; nIndex++, pBuffer++)
{
/* lower 4 bits */
wTemp = CRC16_TABLE[wCrc & 0x000F];
wCrc = (wCrc >> 4) & 0x0FFF;
wCrc = wCrc ^ wTemp ^ CRC16_TABLE[*pBuffer & 0x000F];
/* upper 4 bits */
wTemp = CRC16_TABLE[wCrc & 0x000F];
wCrc = (wCrc >> 4) & 0x0FFF;
wCrc = wCrc ^ wTemp ^ CRC16_TABLE[(*pBuffer >> 4) & 0x000F];
}
return wCrc;
}
My question is: how do I pass the 10 bytes I added to my CbyteArray to the CRC-16 function so that the function can compute the CRC-16 value of all 10 bytes?
I attempted this:
WORD test_crc = calc_crc16(indmessage, nnumberofbytes);
But obviously, it didn’t work.
Thank you!
Electroskill