private unsafe void CCT_AddChecksum(int idx) { ushort num = 0; switch (bChecksumType) { case CHECKSUMTYPE.CHK8BIT: { for (int i = 0; i < msgTxLen[idx]; i++) { num = (ushort)(num + cct_tx[idx][i]); } num = (byte)(-num); cct_tx[idx][msgTxLen[idx]++] = (byte)(num & 0xFF); break; } case CHECKSUMTYPE.CRC16BIT: fixed(byte *pC = cct_tx[idx]) { fixed(byte *pC2 = &cct_tx[idx][3]) { num = CCtalkUtilityDll.crcCalculation(2, pC, 0); num = CCtalkUtilityDll.crcCalculation(msgTxLen[idx] - 3, pC2, num); } } cct_tx[idx][msgTxLen[idx]++] = (byte)((num & 0xFF00) >> 8); cct_tx[idx][2] = (byte)(num & 0xFF); break; } }
private unsafe ushort CCT_VerifyChecksum(int nBytes) { ushort num = 0; switch (bChecksumType) { case CHECKSUMTYPE.CHK8BIT: { for (int i = 0; i < nBytes; i++) { num = (ushort)(num + cct_rx[i]); } return(num); } case CHECKSUMTYPE.CRC16BIT: { byte[] array = new byte[2] { cct_rx[nBytes - 1], cct_rx[2] }; fixed(byte *pC = cct_rx) { fixed(byte *pC2 = &cct_rx[3]) { fixed(byte *pC3 = array) { num = CCtalkUtilityDll.crcCalculation(2, pC, 0); num = CCtalkUtilityDll.crcCalculation(nBytes - 3, pC2, num); num = CCtalkUtilityDll.crcCalculation(2, pC3, num); } } } return(num); } default: return(num); } }