示例#1
0
void File_Header_setCrc(File_Header *fHead)
{
	if (fHead == NULL)
		return;

	getCrc16(&(fHead->fileNameLength), sizeof(fHead->fileNameLength), &(fHead->headCrc), NULL);
	getCrc16(fHead->fileName, fHead->fileNameLength * sizeof(fHead->fileName[0]), &(fHead->headCrc), &(fHead->headCrc));
	getCrc16(&(fHead->attr), sizeof(fHead->attr), &(fHead->headCrc), &(fHead->headCrc));
	getCrc16(&(fHead->method), sizeof(fHead->method), &(fHead->headCrc), &(fHead->headCrc));
	getCrc16(&(fHead->fileSize), sizeof(fHead->fileSize), &(fHead->headCrc), &(fHead->headCrc));
	//getCrc16(&(fHead->fileCrc), sizeof(fHead->fileCrc), &(fHead->headCrc), &(fHead->headCrc));
}
示例#2
0
err_type File_Header_checkCrc(const File_Header *fHead)
{
	uint16_t crc;

	if (fHead == NULL)
		return ERR_PARAM_INVALID;

	getCrc16(&(fHead->fileNameLength), sizeof(fHead->fileNameLength), &crc, NULL);
	getCrc16(&(fHead->fileName), fHead->fileNameLength * sizeof(fHead->fileName[0]), &crc, &crc);
	getCrc16(&(fHead->attr), sizeof(fHead->attr), &crc, &crc);
	getCrc16(&(fHead->method), sizeof(fHead->method), &crc, &crc);
	getCrc16(&(fHead->fileSize), sizeof(fHead->fileSize), &crc, &crc);
	//getCrc16(&(fHead->fileCrc), sizeof(fHead->fileCrc), &crc, &crc);

	return (crc == fHead->headCrc) ? ERR_NO : ERR_HEAD_BADCRC;
}
示例#3
0
文件: mb.c 项目: Lexatagan/modbus
MB_ErrorTypeDef sendFrame(uint16_t pduLength)
{
MB_ErrorTypeDef error = MB_ERROR_OK;
uint16_t crc16;
  if (rxState == RX_STATE_IDLE) {
    pSndFrameCur = mbBuffer;
    sndFrameCount = MB_ADDR_LENGTH + pduLength;
    if (sndFrameCount <= MB_SIZE_MAX) {
      crc16 = getCrc16(pSndFrameCur, sndFrameCount);
      *(pSndFrameCur + sndFrameCount++) = (uint8_t)(crc16 & 0xFF);
      *(pSndFrameCur + sndFrameCount++) = (uint8_t)(crc16 >> 8);
      txState = TX_STATE_TMIT;
      UART_enable(false, true);
    }
uint16_t MumbleManager::getMapId(std::string mapName)
{
    uint16_t res = 0;
    if (mapName.size() != 5 || mapName[3] != '-')
    {
        res = getCrc16(mapName);
    }
    else
    {
        mapName = mapName.substr(0, 3) + mapName[4];
        res = CAST_U16(atoi(mapName.c_str()));
    }
    return res;
}
示例#5
0
文件: mb.c 项目: Lexatagan/modbus
MB_ErrorTypeDef receiveFrame(uint8_t *pSlaveAddr, uint8_t **ppPdu, uint16_t *pPduLength)
{
  if ((mbBufferPosition < MB_SIZE_MIN) || (mbBufferPosition > MB_SIZE_MAX)) {
    return MB_ERROR_IOFAIL;
  }

  if (getCrc16(mbBuffer, mbBufferPosition) != 0) {
    return MB_ERROR_IOFAIL;
  }

  *pSlaveAddr = *(mbBuffer + MB_ADDR_OFFSET);
  *pPduLength = mbBufferPosition - MB_CRC_LENGTH - MB_ADDR_LENGTH;
  *ppPdu = mbBuffer + MB_ADDR_LENGTH;
  return MB_ERROR_OK;
}