Example #1
0
 bool IsOdd()       const { return GetBit(0) == 1; }
Example #2
0
// 填充要打印的缓区
// 参数:( Col:开始填充的列, Data:要填充的数据 ,Font:字体,ValidCol:字符宽中有效的列数(一般为8的倍数,但有24X12的字符时,就是12列了)
unsigned short FillPoints (unsigned short Col, unsigned char xdata *Data, unsigned short RowBytes, unsigned short ColBytes, unsigned short ValidCol, unsigned char Double) {
	unsigned short StartRow;
	unsigned short LocalCol;
	struct stPrintPointBuff *pPPBuff; 
	pPPBuff = &PrintLines[WritePrintLineIdx];

	// 从第几行开始
	StartRow = 48 - RowBytes*8;
	if (Double) {
		StartRow -= RowBytes*8;
		for (; StartRow < 48; StartRow += 2) {
			for (LocalCol = 0; LocalCol < ValidCol; LocalCol++) {
				if (GetBit(Data, LocalCol)) {
					SetBit (pPPBuff->Buff[StartRow], Col + (LocalCol*2));		
					SetBit (pPPBuff->Buff[StartRow+1], Col + (LocalCol*2));	
					SetBit (pPPBuff->Buff[StartRow], Col + (LocalCol*2) + 1);					
					SetBit (pPPBuff->Buff[StartRow+1], Col + (LocalCol*2) + 1);
				}
			}
			Data += ColBytes;
		}

		return Col + ValidCol*2;
	} else {
		// 开始位置是8的整数倍,不用按位赋值
		if (Col%8 == 0) {
			for (; StartRow < 48; StartRow++) {
				memcpy (&pPPBuff->Buff[StartRow][Col/8], Data, ColBytes);
				Data += ColBytes;
			}
		} else {
			if (ValidCol == 8) {
				unsigned short VD;
				for (; StartRow < 48; StartRow++) {
					VD = Data[0];
					VD <<= 4;
					*(unsigned short*)&pPPBuff->Buff[StartRow][Col/8] |= VD;
					Data += ColBytes;
				}
			}
			if (ValidCol == 12) {
				unsigned short VD;
				for (; StartRow < 48; StartRow++) {
					VD = Data[0]<<8|Data[1];
					VD >>= 4;
					*(unsigned short*)&pPPBuff->Buff[StartRow][Col/8] |= VD;
					Data += ColBytes;
				}
			} else {			
				unsigned short VD;
				for (; StartRow < 48; StartRow++) {
					VD = Data[0]<<8|Data[1];
					VD >>= 4;
					*(unsigned short*)&pPPBuff->Buff[StartRow][Col/8] |= VD;
					VD = Data[1]<<8|Data[2];
					VD <<= 4;
					*(unsigned short*)&pPPBuff->Buff[StartRow][Col/8+2] |= VD;
					Data += ColBytes;
				}
			}
		}
Example #3
0
/****************************************************************
** 功    能:退货拆包
** 输入参数:
**        ptMsgRule       报文规则
**        ptData          ISO结构指针
** 输出参数:
**        ptApp           app结构
** 返 回 值:
**        SUCC            处理成功
**        FAIL            处理失败
** 作    者:
**        fengwei
** 日    期:
**        2013/06/13
** 调用说明:
**
** 修改日志:
****************************************************************/
int RefundUnpack(MsgRule *ptMsgRule, T_App *ptApp, ISO_data *ptData)
{
	char    szTmpBuf[512+1];
    char    szTmpBuf2[512+1];
	int     iRet;

	/* 2域 主账号 */
	memset(szTmpBuf, 0, sizeof(szTmpBuf));
	iRet = GetBit(ptMsgRule, ptData, PAN, szTmpBuf);
	if(iRet < 0 || iRet > 19)
	{
        WriteLog(ERROR, "交易类型[%d]应到报文第[%d]域拆解失败iRet:[%d]!",
                 ptApp->iTransType, PAN, iRet);

		strcpy(ptApp->szRetCode, ERR_DATA_FORMAT);

		return FAIL;
	}
	strcpy(ptApp->szPan, szTmpBuf);

    /* 4域 交易金额 */
	memset(szTmpBuf, 0, sizeof(szTmpBuf));
	iRet = GetBit(ptMsgRule, ptData, AMOUNT, szTmpBuf);
	if(iRet != 12)
	{
        WriteLog(ERROR, "交易类型[%d]应到报文第[%d]域拆解失败iRet:[%d]!",
                 ptApp->iTransType, AMOUNT, iRet);

		strcpy(ptApp->szRetCode, ERR_DATA_FORMAT);

		return FAIL;
	}
    strcpy(ptApp->szAmount, szTmpBuf);

	/* 11域 流水号 */
	memset(szTmpBuf, 0, sizeof(szTmpBuf));
	iRet = GetBit(ptMsgRule, ptData, POS_TRACE, szTmpBuf);
	if(iRet != 6)
	{
        WriteLog(ERROR, "交易类型[%d]应到报文第[%d]域拆解失败iRet:[%d]!",
                 ptApp->iTransType, POS_TRACE, iRet);

		strcpy(ptApp->szRetCode, ERR_DATA_FORMAT);

		return FAIL;
	}
	ptApp->lSysTrace = atol(szTmpBuf);

	/* 12域 交易时间 */
	memset(szTmpBuf, 0, sizeof(szTmpBuf));
	iRet = GetBit(ptMsgRule, ptData, LOCAL_TIME, szTmpBuf);
	if(iRet == 6)
	{
		strcpy(ptApp->szHostTime, szTmpBuf);
	}
	else
	{
       	GetSysTime(ptApp->szHostTime);
   	}

	/* 13域 交易日期 */
	memset(szTmpBuf, 0, sizeof(szTmpBuf));
    GetSysDate(ptApp->szHostDate);
	iRet = GetBit(ptMsgRule, ptData, LOCAL_DATE, szTmpBuf);
	if(iRet == 4)
	{
	    strcpy(ptApp->szHostDate+4, szTmpBuf);
    }
	
	/* 14域 有效期 */
	memset(szTmpBuf, 0, sizeof(szTmpBuf));
	iRet = GetBit(ptMsgRule, ptData, EXPIRY, szTmpBuf);
	if(iRet == 4)
	{
		strcpy(ptApp->szExpireDate, szTmpBuf);
	}

    /* 15域 清算日期 */
	memset(szTmpBuf, 0, sizeof(szTmpBuf));
	iRet = GetBit(ptMsgRule, ptData, SETTLE_DATE, szTmpBuf);
	if(iRet != 4)
	{
        WriteLog(ERROR, "交易类型[%d]应到报文第[%d]域拆解失败iRet:[%d]!",
                 ptApp->iTransType, SETTLE_DATE, iRet);

		strcpy(ptApp->szRetCode, ERR_DATA_FORMAT);

		return FAIL;
	}
	strcpy(ptApp->szSettleDate, szTmpBuf);

	/* 25域 服务点条件码 */
	/* 已解析 */

	/* 32域 受理方标识码 */
	memset(szTmpBuf, 0, sizeof(szTmpBuf));
	iRet = GetBit(ptMsgRule, ptData, ACQUIRER_ID, szTmpBuf);
    if(iRet > 11 || iRet < 1)
	{
        WriteLog(ERROR, "交易类型[%d]应到报文第[%d]域拆解失败iRet:[%d]!",
                 ptApp->iTransType, ACQUIRER_ID, iRet);

		strcpy(ptApp->szRetCode, ERR_DATA_FORMAT);

		return FAIL;
	}

	/* 37域 检索参考号 后六位是凭证号 */
	memset(szTmpBuf, 0, sizeof(szTmpBuf));
	iRet = GetBit(ptMsgRule, ptData, RETR_NUM, szTmpBuf);
	if(iRet != 12)
	{
        WriteLog(ERROR, "交易类型[%d]应到报文第[%d]域拆解失败iRet:[%d]!",
                 ptApp->iTransType, RETR_NUM, iRet);

		strcpy(ptApp->szRetCode, ERR_DATA_FORMAT);

		return FAIL;
	}
    sprintf(ptApp->szRetriRefNum, "%12.12s", szTmpBuf);

    /* 39域 响应码 */
    memset(szTmpBuf, 0, sizeof(szTmpBuf));
    iRet = GetBit(ptMsgRule, ptData, RET_CODE, szTmpBuf);
	if(iRet != 2)
	{
        WriteLog(ERROR, "交易类型[%d]应到报文第[%d]域拆解失败iRet:[%d]!",
                 ptApp->iTransType, RET_CODE, iRet);

		strcpy(ptApp->szRetCode, ERR_DATA_FORMAT);

		return FAIL;
	}
	strcpy(ptApp->szHostRetCode, szTmpBuf);

	/* 41域 终端号 */
    memset(szTmpBuf, 0, sizeof(szTmpBuf));
	iRet = GetBit(ptMsgRule, ptData, POS_ID, szTmpBuf);
	if(iRet != 8)
	{
        WriteLog(ERROR, "交易类型[%d]应到报文第[%d]域拆解失败iRet:[%d]!",
                 ptApp->iTransType, POS_ID, iRet);

		strcpy(ptApp->szRetCode, ERR_DATA_FORMAT);

		return FAIL;
	}
    strcpy(ptApp->szPosNo, szTmpBuf);

	/* 42域 商户号 */
    memset(szTmpBuf, 0, sizeof(szTmpBuf));
	iRet = GetBit(ptMsgRule, ptData, CUSTOM_ID, szTmpBuf);
	if(iRet != 15)
	{
        WriteLog(ERROR, "交易类型[%d]应到报文第[%d]域拆解失败iRet:[%d]!",
                 ptApp->iTransType, CUSTOM_ID, iRet);

		strcpy(ptApp->szRetCode, ERR_DATA_FORMAT);

		return FAIL;
	}
    strcpy(ptApp->szShopNo, szTmpBuf);

	/* 60.2域 批次号 */
	memset(szTmpBuf, 0, sizeof(szTmpBuf));
	iRet = GetBit(ptMsgRule, ptData, FIELD60, szTmpBuf);
    if(iRet < 1 || iRet > 11)
	{
        WriteLog(ERROR, "交易类型[%d]应到报文第[%d]域拆解失败iRet:[%d]!",
                 ptApp->iTransType, FIELD60, iRet);

        strcpy(ptApp->szRetCode, ERR_DATA_FORMAT);

        return FAIL;
	}
	memset(szTmpBuf2, 0, sizeof(szTmpBuf2));
	memcpy(szTmpBuf2, szTmpBuf+2, 6);
	ptApp->lBatchNo = atol(szTmpBuf2);

	return SUCC;
}
Example #4
0
 bool IsEven()      const { return GetBit(0) == 0; }
Example #5
0
void SetBit(DWord& _SrcDWord, Byte _Bit, Byte _Val){
  if (GetBit(_SrcDWord, _Bit)!=_Val){
    if (_Val) _SrcDWord+=_Val<<_Bit;
    else _SrcDWord-=_Val<<_Bit;
  }
}
Example #6
0
void SetBit(Byte& _SrcByte, Byte _Bit, Byte _Val){
  if (GetBit(_SrcByte, _Bit)!=_Val){
    if (_Val) _SrcByte+=_Val<<_Bit;
    else _SrcByte-=_Val<<_Bit;
  }
}
Example #7
0
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   R e a d O T B I m a g e                                                   %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  ReadOTBImage() reads a on-the-air (level 0) bitmap and returns it.  It
%  allocates the memory necessary for the new Image structure and returns a
%  pointer to the new image.
%
%  The format of the ReadOTBImage method is:
%
%      Image *ReadOTBImage(const ImageInfo *image_info,ExceptionInfo *exception)
%
%  A description of each parameter follows:
%
%    o image_info: the image info.
%
%    o exception: return any errors or warnings in this structure.
%
%
*/
static Image *ReadOTBImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
#define GetBit(a,i) (((a) >> (i)) & 1L)

  Image
    *image;

  int
    byte;

  MagickBooleanType
    status;

  register ssize_t
    x;

  register Quantum
    *q;

  ssize_t
    y;

  unsigned char
    bit,
    info,
    depth;

  /*
    Open image file.
  */
  assert(image_info != (const ImageInfo *) NULL);
  assert(image_info->signature == MagickSignature);
  if (image_info->debug != MagickFalse)
    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
      image_info->filename);
  assert(exception != (ExceptionInfo *) NULL);
  assert(exception->signature == MagickSignature);
  image=AcquireImage(image_info,exception);
  status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
  if (status == MagickFalse)
    {
      image=DestroyImageList(image);
      return((Image *) NULL);
    }
  /*
    Initialize image structure.
  */
  info=(unsigned char) ReadBlobByte(image);
  if (GetBit(info,4) == 0)
    {
      image->columns=(size_t) ReadBlobByte(image);
      image->rows=(size_t) ReadBlobByte(image);
    }
  else
    {
      image->columns=(size_t) ReadBlobMSBShort(image);
      image->rows=(size_t) ReadBlobMSBShort(image);
    }
  if ((image->columns == 0) || (image->rows == 0))
    ThrowReaderException(CorruptImageError,"ImproperImageHeader");
  depth=(unsigned char) ReadBlobByte(image);
  if (depth != 1)
    ThrowReaderException(CoderError,"OnlyLevelZerofilesSupported");
  if (AcquireImageColormap(image,2,exception) == MagickFalse)
    ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
  if (image_info->ping != MagickFalse)
    {
      (void) CloseBlob(image);
      return(GetFirstImageInList(image));
    }
  /*
    Convert bi-level image to pixel packets.
  */
  for (y=0; y < (ssize_t) image->rows; y++)
  {
    q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
    if (q == (Quantum *) NULL)
      break;
    bit=0;
    byte=0;
    for (x=0; x < (ssize_t) image->columns; x++)
    {
      if (bit == 0)
        {
          byte=ReadBlobByte(image);
          if (byte == EOF)
            ThrowReaderException(CorruptImageError,"CorruptImage");
        }
      SetPixelIndex(image,(byte & (0x01 << (7-bit))) ? 0x00 : 0x01,q);
      bit++;
      if (bit == 8)
        bit=0;
      q+=GetPixelChannels(image);
    }
    if (SyncAuthenticPixels(image,exception) == MagickFalse)
      break;
    if (image->previous == (Image *) NULL)
      {
        status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
                image->rows);
        if (status == MagickFalse)
          break;
      }
  }
  (void) SyncImage(image,exception);
  if (EOFBlob(image) != MagickFalse)
    ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
      image->filename);
  (void) CloseBlob(image);
  return(GetFirstImageInList(image));
}
Example #8
0
void uart_putc(const char c)
{
	while (!GetBit(UCSR0A, UDRE0))
		; // wait until buffer free
	UDR0 = c;
}
Example #9
0
void Util::PrintBit(uint64_t x) {
  for (uint64_t i = 0; i < 64; ++i){
    std::cout << GetBit(x, i);
  }
  std::cout << std::endl;
}