📄 bsptsprnt.c
字号:
s_ucTSDoubleHigh = 1;
/* 单行打印数据中间含有倍高处理,其他字模需做下对齐调整 */
for ( k = 0; k <= s_ucprntHoriByte; k ++)
{
for (j = 0; j < 24; j ++)/* 移位字模24点阵高度 */
{
g_ucprntPrintLineBuffer[24 + s_usprntDotLine + j][k] = g_ucprntPrintLineBuffer[s_usprntDotLine + j][k];
g_ucprntPrintLineBuffer[s_usprntDotLine + j][k] = 0;
}
}
i ++;
break;
case 0x15: /* 取消倍高打印命令 */
s_ucTSDoubleHigh = 0;
if (s_ucTSRequestDoubleHigh)
{
s_usprntDotLine += 24;/* 移位字模24点阵高度 */
}
i ++;
break;
case 0x0a: /* 打印换行命令 */
case 0x0d:
if ((_pData[i] == 0x0a) && (_pData[i-1] == 0x0d))
{
i ++;
}
else
{
if ((g_ucPrntChoiceLang)&&(s_ucTSprntDataBuffDataIn > 0))/* 阿拉伯语或英语 */
{
guiGetArabVarCode(s_ucTSprntDataBuffer,s_ucRevBuffer,FALSE);
mem_set(s_ucRevBuffer,0,LINEASCIINUM);
bspTSPrntArabAutoNewLine(_ucLineSpace,_ucStartPos);/* 处理本行最后一个未处理单词字模 */
}
s_ucNumInWord = 0;
ucRet = bspTSPrntDealState(_ucLineSpace);
if (ucRet == ENABLE_DEAL_DATA)
{
if (s_ucTSRequestDoubleHigh)
{
uiStepCount += 24; /* 单行打印含有倍高处理字节 */
}
bspTSPrntChangeLine (_ucLineSpace, _ucStartPos);
bspTSPrntEraseLineBuffer(_ucLineSpace);
uiStepCount += _ucLineSpace;
/* 采用默认打印起始位置 */
bspTSPrntSetIntPos (_ucStartPos);
bspTSPrntDetectTemp();
i++;
}
}
break;
case 0xff: /* 绝对坐标定位命令 */
ucBeginPlace = _pData[i + 1];
bspTSPrntSetIntPos(ucBeginPlace); /* 更新打印横坐标 */
if (8*_pData[i + 2] > uiStepCount)
{
uiStepTempCount = 8*_pData[i + 2] - uiStepCount;/* 需要进纸点行数 */
}
else
{
uiStepTempCount = 0;
}
uiStepCount = 8*_pData[i + 2];
ucfPrnt = bspTSPrntGoToYCoordinates(uiStepTempCount, _ucLineSpace, ucfPrnt);
i += 3;
break;
case 0x1d: /* 走纸到打印切纸位置命令 */
if (_pData[i + 1] == 0x56)
{
i += 2;
g_ucMarkCutPaper = 1; /* 置起走纸到打印切纸位置标志 */
}
else
{
i += 1;
}
break;
case 0x1b: /* 打印行间距和位图打印命令 */
if (_pData[i + 1] == 0x2A)
{
/* 标准位图打印处理函数 */
bspTSPrntBitMap(&_pData[i + 5],_pData[i + 2],3*(_pData[i + 3] + 256*_pData[i + 4]));
i = i + 5 + 3*(_pData[i + 3] + 256*_pData[i + 4]);
}
else if (_pData[i + 1] == 0x33)
{
/* 设置纵向打印行间距(备用命令) */
_ucLineSpace = _pData[i + 2];
i += 3;
}
else if (_pData[i + 1] == 0x66)
{
/* 设置加热时间,但是参数在之前打印数据结束才有效 */
ucSetHeatTime = _pData[i + 2];
/* 置起阻止热敏打印解析数据标志 */
ucEnableDealData = 0;
i += 3;
}
else
{
i ++;
}
break;
default:
if (2 == g_ucPrntChoiceLang)/* 英语 */
{
ucParseData[0] = _pData[i];
str_cat(s_ucTSprntDataBuffer,ucParseData);
s_ucTSprntDataBuffDataIn ++;
if (_pData[i] == 0x20)/* 单词结束 */
{
bspTSPrntArabAutoNewLine(_ucLineSpace,_ucStartPos);
}
i ++;
}
else if (1 == g_ucPrntChoiceLang)/* 阿拉伯语 */
{
ucParseData[0] = _pData[i];
str_cat(s_ucRevBuffer,ucParseData);
s_ucTSprntDataBuffDataIn ++;
s_ucNumInWord ++;
if (_pData[i] == 0x20)/* 单词结束 */
{
s_ucNumInWord = 0;
}
if (s_ucMaxASClen == s_ucTSprntDataBuffDataIn) /*当前行存空间满*/
{
if (_pData[i] == 0x20)/* 单词结束 */
{
/*处理阿拉伯文后头的ASCII*/
bspTSPrntArabAndASCDeal();
str_cat(s_ucTSprntDataBuffer,s_ucRevBuffer);
mem_set(s_ucRevBuffer,0,LINEASCIINUM);
bspTSPrntArabAutoNewLine(_ucLineSpace,_ucStartPos);
}
else
{
s_ucTSprntDataBuffDataIn -= s_ucNumInWord;
/*缓存单词*/
mem_cpy(s_ucWordPlus, (s_ucRevBuffer + s_ucTSprntDataBuffDataIn), s_ucNumInWord);
mem_set((s_ucRevBuffer + s_ucTSprntDataBuffDataIn), 0, s_ucNumInWord);
/*处理阿拉伯文后头的ASCII*/
bspTSPrntArabAndASCDeal();
str_cat(s_ucTSprntDataBuffer,s_ucRevBuffer);
mem_set(s_ucRevBuffer,0,LINEASCIINUM);
bspTSPrntArabAutoNewLine(_ucLineSpace,_ucStartPos);
/*不完整单词到新的缓冲区*/
mem_cpy(s_ucRevBuffer, s_ucWordPlus, s_ucNumInWord);
s_ucTSprntDataBuffDataIn = s_ucNumInWord;
}
}
i ++;
}
else
{
/* 解析待打印字模数据 */
Ret = bspTSPrntFillBuffer (&_pData[i], 0,_ucLineSpace, _ucStartPos);
if (Ret != TS_DEAL_DATA)
{
if (_pData[i] <= 0x7f)
{
i ++; /* ASCII字符打印 */
}
else
{
i += 2;/* 中文打印 */
}
}
}
break;
}
}
if (ucfPrnt)
{
if ((s_usprntDotLineDealed >= _ucLineSpace)||((i >= _usLength)&&(s_usprntDotLineDealed > 0)))
{
//bspUart0Write((UINT1 *)"2", 1);
ucfPrnt = 0;
TS_POWER_ON();
bspTSPrntISTRInit();
//bspUart0Write((UINT1 *)"3", 1);
}
if ((!ucEnableDealData)&&(ucfPrnt))
{
/* 票据第一行数据之前需要设置加热时间,置起允许热敏解析数据标志 */
ucEnableDealData = 1;
g_ucprntHeatTime = ucSetHeatTime/ADJUST_TIMER_SCALE;
s_ucprntStepTime = (g_ucprntHeatTime + 4/ADJUST_TIMER_SCALE)/4 ;/* 打印走步时间 */
}
}
if (s_ucOverFlowPrinted) /* 处理数据比打印慢处理流程 */
{
if (!ucEnableDealData)
{
/* 置起允许解析打印数据标志,打印过程中接收到设置加热时间命令,此时停止解析数据,待先
前处理数据打印完毕,再解析数据并按照新设置加热时间打印票据 */
ucEnableDealData = 1;
g_ucprntHeatTime = ucSetHeatTime/ADJUST_TIMER_SCALE;
s_ucprntStepTime = (g_ucprntHeatTime + 4/ADJUST_TIMER_SCALE)/4 ;/* 打印走步时间 */
bspTSprntSetISRTimer(s_ucprntStepTime);
}
else
{
ucRet = bspTSPrntCheckState(_ucLineSpace);
if ((i >= _usLength)||(ENABLE_PRNT_DATA == ucRet))
{
s_ucOverFlowPrinted = 0;
s_ucprntPrintEnable = 1;
s_ucTSSendOneLine = 1;
OPERATE_LAT;
}
}
}
}while((s_usTSprntLinePrinted != s_usprntDotLineDealed)||(i < _usLength));
bspTSPrntSetEndState();
/* 打印完毕仍然黑标信号,并且已打印行数低于黑标信号计数值 */
if ((g_usTSPrintedLine <= g_usPrntBMCounter)&&(!BLACK_SENSOR))
{
g_usTSPrintedLine = 0;
}
return;
}
/*
*****************************************************
*
* 函数名:bspTSPrntGoToYCoordinates
*
* 功 能:热敏打印进纸到绝对纵坐标
*
* 输 入:s_usprntDotLineDealed
*
* 输 出:g_ucprntPrintLineBuffer
* s_usprntDotLine
*
* 返 回:ucfPrnt-是否允许打印标志
*
*****************************************************
*/
UINT1 bspTSPrntGoToYCoordinates
(
UINT2 _usDotLine, /* 进纸点行数 */
UINT1 _ucLineSpace, /* 打印行间距 */
UINT1 _ucEnablePrnt /*当前是否允许打印标志(0允许 1禁止)*/
)
{
UINT1 i,j;
UINT1 ucRet = 0;
UINT1 ucfPrnt;
ucfPrnt = _ucEnablePrnt;
if (_usDotLine == 0)
{
/* 同一纵坐标下不同横坐标定位 */
s_usprntDotLine = s_usprntDotLineDealed;
}
else
{
/* 不同绝对纵坐标打印定位 */
do
{
ucRet = bspTSPrntDealState(_ucLineSpace);
if (ucRet == ENABLE_DEAL_DATA)
{
for (i = 0; i < _ucLineSpace; i ++)
{
if (!_usDotLine)
{
break;
}
INC(s_usprntDotLineDealed,DOTLINE_LIMIT);
for (j = 0; j < TS_ONE_LINE_BYTE; j ++)
{
g_ucprntPrintLineBuffer[s_usprntDotLineDealed][j] = 0;
}
_usDotLine --;
}
if (ucfPrnt) /* 防止未执行打印之前,黑标定位纵坐标过大,导致死循环 */
{
ucfPrnt = 0;
TS_POWER_ON();
bspTSPrntISTRInit();
}
}
}while (_usDotLine > 0);
s_usprntDotLine = s_usprntDotLineDealed;
bspTSPrntEraseLineBuffer(_ucLineSpace);
}
return ucfPrnt;
}
/*
*****************************************************
*
* 函数名:bspTSPrntBitMap
*
* 功 能:热敏打印机位图打印处理
*
* 输 入:s_usprntDotLine
* s_ucprntHoriByte
* s_ucprntBitInByte
* s_usprntHoriPosition
*
* 输 出:g_ucprntPrintLineBuffer
*
* 返 回:N/A
*
*****************************************************
*/
INT1 bspTSPrntBitMap
(
UINT1* _pBuffer, /* [in]存放位图数据缓存首地址 */
UINT1 _ucSelBitMap, /* 选择位图标志(32-24点单密度;33-24点双密度)*/
UINT2 _usLength /* 打印位图数据长度 */
)
{
UINT1 i,j,k;
UINT1 ucReadOneByte;
UINT1 ucDealOneBit;
UINT1 ucDotLinePos;
UINT1 ucSelBitMap;
if (_ucSelBitMap == 0x20)
{
ucSelBitMap = 1;/* 24点单密度打印 */
}
else if (_ucSelBitMap == 0x21)
{
ucSelBitMap = 0;/* 24点双密度打印 */
}
else
{
return FAULT;
}
ucDotLinePos = s_usprntDotLine; /* 保存起始打印行位置(增加1个字符字模后,回到初始位置) */
for (i = 0; i < _usLength; i ++)
{
ucReadOneByte = *(_pBuffer + i); /* 从缓冲区读取1字节 */
for (j = 0; j < 8; j ++) /* 将字模单字节移位处理存取打印缓冲区 */
{
ucDealOneBit = ucReadOneByte >> 7;
ucReadOneByte = ucReadOneByte << 1;
if (ucDealOneBit) /* 字模移位处理 */
{
g_ucprntPrintLineBuffer[s_usprntDotLine][s_ucprntHoriByte] |= s_ucprntBitInByte;
if (ucSelBitMap)
{
s_ucprntBitInByte = (s_ucprntBitInByte >> 1);
if (s_ucprntBitInByte == 0)
{
s_ucprntBitInByte = 0x80;
s_ucprntHoriByte ++;
}
g_ucprntPrintLineBuffer[s_usprntDotLine][s_ucprntHoriByte] |= s_ucprntBitInByte;
s_ucprntBitInByte = (s_ucprntBitInByte << 1);
}
INC(s_usprntDotLine, DOTLINE_LIMIT);
}
else
{
INC(s_usprntDotLine, DOTLINE_LIMIT);
}
}
if (i % 3 == 2)
{
s_ucprntBitInByte = (s_ucprntBitInByte >> 1);
if (ucSelBitMap)
{
/* 如果单密度位图打印,由于字模变宽移位处理字节中位数执行向右和向左移位,
故不需要进位判断 */
s_ucprntBitInByte = (s_ucprntBitInByte >> 1);
}
if (s_ucprntBitInByte == 0)
{
s_ucprntBitInByte = 0x80;
s_ucprntHoriByte ++;
}
s_usprntDotLine = ucDotLinePos;
}
}
/* 横向水平打印起始位置调整 */
k = (ucSelBitMap + 1)*(_usLength / 3);
for (i = 0; i < k; i ++)
{
s_usprntHoriPosition ++; /* 一行已处理的点数(单行最大384点) */
}
return SUCCESS;
}
/*
*****************************************************
*
* 函数名:bspTSPrntArabAutoNewLine
*
* 功 能:阿拉伯语以单词为单位自动换行函数
*
* 输 入:s_ucTSDoubleWidth
* s_ucTSprntDataBuffer
* s_usprntHoriPosition
*
* 输 出:g_ucprntPrintLineBuffer
*
* 返 回:N/A
*
*****************************************************
*/
void bspTSPrntArabAutoNewLine
(
UINT1 _ucLineSpace, /* 热敏打印行间距 */
UINT1 _ucStartPos /* 热敏打印确定横向起始位置(精确mm) */
)
{
UINT1 ucRet = 0;
if ((s_usprntHoriPosition + (s_ucTSDoubleWidth + 1)*ASCII_LENGTH*str_len(s_ucTSprntDataBuffer)) > ONE_LINE_DOT)
{
do
{
/* 判断能否换行,并完成换行操作 */
ucRet = bspTSPrntDealState(_ucLineSpace);
if (ucRet)/* 剩余缓存空间足以保存下一行的处理数据 */
{
bspTSPrntChangeLine (_ucLineSpace, _ucStartPos);
bspTSPrntEraseLineBuffer(_ucLineSpace);
bspTSPrntArabParseData(_ucLineSpace, _ucStartPos);
}
}while(s_ucTSprntDataBuffDataIn > 0);
}
else
{
bspTSPrntArabParseData(_ucLineSpace, _ucStartPos);
}
return;
}
/*
*****************************************************
*
* 函数名:bspTSPrntArabParseData
*
* 功 能:阿拉伯语单词字模解析与处理
*
* 输 入:s_ucTSprntDataBuffDataIn
* s_ucTSprntDataBuffer
*
* 输 出:无
*
* 返 回:N/A
*
*****************************************************
*/
void bspTSPrntArabParseData
(
UINT1 _ucLineSpace, /* 热敏打印行间距 */
UINT1 _ucStartPos /* 热敏打印确定横向起始位置(精确mm) */
)
{
UINT1 i;
for (i = 0; i < s_ucTSprntDataBuffDataIn; i ++)
{
/* 解析待打印字模数据 */
bspTSPrntFillBuffer (&s_ucTSprntDataBuffer[i], 0, _ucLineSpace, _ucStartPos);
}
s_ucTSprntDataBuffDataIn = 0;
mem_set(s_ucTSprntDataBuffer, 0, str_len(s_ucTSprntDataBuffer));
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -