⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 prntmain.c

📁 基于ARM与μCOS-II的嵌入式操作系统实现针式和热敏微型打印程序.
💻 C
📖 第 1 页 / 共 3 页
字号:



#include "intfBsp.h"
#include "intfPrnt.h"
#include "prntMain.h"
#include "prntProc.h"


/*------------------ ----全局变量定义-- ----------------------*/
UINT1 g_ucprntHeatTime = 0; 				/* 热敏打印加热时间调节  		  */
UINT1 g_ucprntLinePrinted = 0;				/* 穿孔打印已成功打印行数         */
UINT2 g_usTSPrintedLine = 0;				/* 热敏打印已成功打印点行数       */
UINT1 g_ucPaperType = 0 ; 					/* 打印票据类型(0不定长;1定长)   */
UINT1 g_ucPrinterLineSpace = 32;			/* 热敏打印行间距 */
UINT1 g_ucMsgBuffer[2];   					/* 打印任务消息缓冲区(状态、行数) */
/*------------------ ----静态全局变量定义-- ------------------*/
static UINT1 s_ucPrntTaskState = NOTASK;   	/* 打印任务当前状态(0 空闲;1 打印 */
static UINT1 s_ucPrntRecPowoffMsg = 0;		/* 接收关机消息打印任务状态(0空闲;1打印)*/
static UINT1 s_ucPrntEquipState = 0;		/* 打印机设备当前状态(0 未启用;1 被启用)*/
//static UINT1 s_ucprntTSDataBuffer[255];     /* 热敏处理打印数据缓冲 */
//static UINT1 s_ucprntDataBuffDataIn;	    /* 热敏处理数据索引指针 */ 

static UINT1 s_ucprntTSDataBuffer[512];     /* 热敏处理打印数据缓冲 */
static UINT2 s_ucprntDataBuffDataIn;	    /* 热敏处理数据索引指针 */ 
/*------------------------------------------------------------*/
static msgStruct  PrntResMsg; 				/* 消息体 */
/* 打印中文测试页 */
const UINT1 *ChineseCardPrintChar[] =
{
	(UINT1 *)"名称:电子交易卡",
	(UINT1 *)"面额:50.00",
	(UINT1 *)"有效期:2006/12/30",
	(UINT1 *)"密码:217942 931140 4",
	(UINT1 *)"卡序号:706561165688425",
	(UINT1 *)"交易序号:000031315-02-0001",
	(UINT1 *)"交易时间:2006/12/12 11:19",
	(UINT1 *)"广告:欢迎使用! 由于网络带宽限制网络不可避免诱发时延网络时延将影响基于互联网控制系统得动态性能甚至导致系统不稳定"
};
/* 打印英文测试页 */
const UINT1 *EnglishCardPrintChar[] =
{
	(UINT1 *)"Name:E-trade Card",
	(UINT1 *)"Value:50.00",
	(UINT1 *)"Valid Date:12/30/2006",
	(UINT1 *)"217942 931140 4",//Password
	(UINT1 *)"Serial No.:706561165688425",
	(UINT1 *)"Trade No.:000031315-02-0001",
	(UINT1 *)"Trade Time:12/12/2006 11:19",
	(UINT1 *)"Advertisement:welcome! Due to the bandwidth constraint, the network inevitably induces time delay in Networked control system, which will affect the performance of control systems such as degradation and system destabilization."
};

/*
*******************************************************
*
* 函数名:prntInit
*
* 功  能:打印模块初始化函数
*
* 输  入:无
*
* 输  出:无
*
* 返  回:SUCCESS 成功
*
*******************************************************
*/
INT1 prntInit (void)
{
	mem_set(g_ucMsgBuffer, 0 , sizeof(g_ucMsgBuffer));
	
	return SUCCESS;
}

/*
********************************************************
*
* 函数名:prntPrintDrInit
*
* 功  能:根据硬件口线状态判定打印机芯类型,执行打印模块
* 		  底层初始化函数
*
* 输  入:无
*
* 输  出:无
*
* 返  回:SUCCESS 成功
*
********************************************************
*/
INT1 prntPrintDrInit(void)
{
	UINT1 ucprntHeatTime;
	UINT1 ucprntHitTime;

	if (PRINTER_TYPE)
	{
		/* 读取打印效果调节参数 */
		ET_mntnReadParaValue(ID_MNTN_DOT_PRNT_EFFECT, &g_ucprntAdjustLevel);
		if (g_ucprntAdjustLevel > 6)
		{
			g_ucprntAdjustLevel = 4;
		}
		ET_mntnReadParaValue(ID_MNTN_DOT_PRNT_HIT_TIME, &ucprntHitTime);
		/* 初始化打印机芯操作 */
		bspDotPrntInit();
	}
	else
	{
		/* 读取热敏加热时间参数 */
		ET_mntnReadParaValue(ID_MNTN_THERMAL_HEAT_TIME, &ucprntHeatTime);
		if ((ucprntHeatTime >= 30) && (ucprntHeatTime <= 180))
		{
			/* 设置打印加热时间 */
			g_ucprntHeatTime = ucprntHeatTime/ADJUST_TIMER_SCALE; 
		}
		else
		{
			/* 默认打印加热时间38ms */	
			g_ucprntHeatTime = HEAT_TIME_DEFAULT/ADJUST_TIMER_SCALE;/* 默认打印加热时间38ms */					
		}
		/* 初始化打印机芯操作 */
		ET_mntnSetAppParaAddr(ETRADE_PARA_ADDR + 0x100);
		ET_mntnReadParaValue(ID_ETRADE_THERM_PRNT_BM, &g_ucPaperType);
		bspTSPrntInit();
	}
	return SUCCESS;
}

/*
*********************************************************
*
* 函数名:ET_prntOpen
*
* 功  能:启用打印机设备, 业务模块在成功启用打印机设备后,
*		  才能调用ET_prntWrite函数执行打印操作;
*
* 输  入:s_ucPrntEquipState
*
* 输  出:无
*
* 返  回: = 0  启用打印机设备成功,返回标识符cFd
*		    -1	启用打印机设备失败
**********************************************************
*/
INT1 ET_prntOpen (void) 
{
	INT1 cFd;

	OSSchedLock();/* 禁止任务切换 */
	if (!s_ucPrntEquipState)
	{
		/* 置起占用打印机设备标志位 */
		s_ucPrntEquipState = 1;
		cFd = SUCCESS;
	}
	else
	{
		cFd = FAULT;
	}
	OSSchedUnlock();/* 启动任务切换 */
	
	return cFd;
}

/*
***********************************************************
*
* 函数名:ET_prntClose
*
* 功  能:停用打印机设备,业务模块在调用ET_prntWrite函数执行
*		  打印操作完毕,调用此函数,释放对打印机的使用权。
*
* 输  入:无
*
* 输  出:s_ucPrntEquipState
*
* 返  回:SUCCESS   停用打印设备操作成功 
*		  FAULT		停用打印设备操作失败
*
***********************************************************
*/
INT1 ET_prntClose (INT1  cFd) 
{
	if (cFd == SUCCESS)
	{
		/* 释放占用打印机设备标志位 */
		s_ucPrntEquipState = 0;
	}
	else
	{
		return FAULT;
	}
	
	return SUCCESS;
}

/*
***********************************************************
*
* 函数名:ET_prntWrite
*
* 功  能:基本打印接口函数。由平台打印模块提供给业务模块调用
*		  的打印功能函数。调用打印函数业务模块需提供打印参数、
*		  打印数据缓存、打印数据长度等信息。
*			
* 输  入:g_ucprntLinePrinted
*         g_usTSPrintedLine
*
* 输  出:无
*
* 返  回: 
*		  g_ucprinterState  打印机状态(如下表所示)
*		  |7位|6位|5位|4位|3位 |2位 |1位 |0位 |	
*		  |空 |空 |空 |忙 |掉电|高温|故障|缺纸|
*
***********************************************************
*/
INT1 ET_prntWrite
(			
	const PrntPara *_prntPara,	/* [in]打印参数指针 */
	UINT1 *_pData,		        /* [in]打印数据指针 */
	UINT2 _usLength		        /* 待打印数据长度   */
)
{
	UINT1 ucTemp;
	
	/* 指针、数据参数合法性检查 */
	if ((_prntPara== NULL)||(_usLength == 0))
	{
		return FAULT;
	}
	if (!PRINTER_TYPE)
	{
		/* 热敏打印温度过高状态自恢复处理 */
		bspTSPrntDetectTemp();
	}
	/* 专用打印前查询打印机状态使用 */
	if ((_pData[0] == 0x05)&&(_usLength == 1))
	{
		return g_ucprntState;
	}
	ucTemp = g_ucprntState;
	if (ucTemp&0x10)        /* 打印模块任务忙 */
	{
		return g_ucprntState;
	}
	g_ucprntState |= PRNTBUSY;	/* 打印模块忙0x10 */
	/* 设置业务模块打印参数 */
	prntSetPrinterPara(_prntPara);
	/* 向打印任务发送票据打印消息 */
	PrntResMsg.id  =  MSG_PRNT_DATA_PRNT;
	PrntResMsg.len = _usLength;
	PrntResMsg.p   = _pData;
	PrntResMsg.sign = 1;
	OSQPost(pPrntQEvent, (void *)&PrntResMsg);	
	
	return SUCCESS;
}

/*
***********************************************************
*
* 函数名:ET_prntGetState
*
* 功 能: 获取当前打印机状态信息
*
* 输 入:无
*
* 输 出:无
*
* 返 回: g_ucprntState  打印机状态(如下表所示)
*		 |7位|6位|5位|4位|3位 |2位 |1位 |0位 |	
*		 |空 |空 |空 |忙 |掉电|高温|故障|缺纸|
*			
***********************************************************
*/
UINT1  ET_prntGetState (void) 
{
	if (!PRINTER_TYPE)
	{
		/* 热敏打印温度过高状态自恢复处理 */
		bspTSPrntDetectTemp();
	}
	return g_ucprntState;
}

/*
**********************************************************
*
* 函数名:prntMain
*
* 功  能:打印模块任务主函数,主要处理消息,调用打印
*         接口函数实现打印操作
*
* 输  入:无
*
* 输  出:无
*
* 返  回:无
*
**********************************************************
*/
void  prntMainTask
(
	void * _pData 		 /* [in] 任务参数输入*/
)
{
	UINT1 ucErr;		 /* 错误代码 */
	UINT1 ucRet;
	UINT2 usUserId;
	msgStruct  *PrntMsg; /* 消息体 */
	PrntPara PrntParam;

	prntInit();

	//prntTSPrintEnglishTest();
	
	while(1)
	{
		PrntMsg  = (msgStruct *)OSQPend(pPrntQEvent, 0, &ucErr); /* 没有接收到消息就挂起 */
		if ((UINT4)PrntMsg < RAM_START_ADDR)  /* 直接传消息 */
		{
			mem_cpy((UINT1 *)&usUserId, (UINT1 *)&PrntMsg, 2);
		}
		else
		{
			usUserId = PrntMsg->id;
		}

		switch(usUserId)
		{
			case MSG_PRNT_DATA_PRNT:	 	/* 业务票据打印消息处理 */
				s_ucPrntTaskState = PRINTING;	
				if (PRINTER_TYPE) /* 穿孔机芯 */
				{
					ucRet = prntDotPrintData (PrntMsg->p, PrntMsg->len);
				}
				else
				{				
					ucRet = prntTSPrintData (PrntMsg->p, PrntMsg->len);
				}
				PrntMsg->sign = 0;
				/* 处理打印结果信息,并向业务发送打印结果消息 */
				prntDealPrintResult(prntGetAppID(&PrntParam));
				if (s_ucPrntRecPowoffMsg)
				{
					prntDealPowerOff();
					s_ucPrntRecPowoffMsg = 0;
				}		
				break;
				
			case MSG_PRNT_PRNT_DATA_MNTN:		/* 打印汉字库 */
				s_ucPrntTaskState = PRINTING;
				if (PRINTER_TYPE)
				{
					prntDotPrintHZlib(PrntMsg->p, PrntMsg->len);
				}
				else
				{
					prntTSPrintHZlib(PrntMsg->p, PrntMsg->len);
				}
				prntSendMsgToMntn();
				PrntMsg->sign = 0;
				if (s_ucPrntRecPowoffMsg)
				{
					prntDealPowerOff();
					s_ucPrntRecPowoffMsg = 0;
				}
				break;
				 
			case MSG_PRNT_CUTOFF_SYSC:			/* 系统掉电消息 */
			case MSG_PRNT_POWOFF_SYSC:			/* 系统关机消息 */
				/* 如果在打印过程中接收到系统关机、掉电消息,
				则打印完毕后执行相应操作 */
				if (s_ucPrntTaskState == NOTASK)
				{
					prntDealPowerOff();
				}
				else
				{
					s_ucPrntRecPowoffMsg = 1;
				}
				break;
			
			default:
				break;
		}
		s_ucPrntTaskState = NOTASK;
	}
	return;
}

/*
***********************************************************
*
* 函数名:prntGetAppID
*
* 功  能:获取业务应用ID
*
* 输  入:无
*
* 输  出:无
*
* 返  回:ucID-业务应用ID
*			
***********************************************************
*/
UINT1 prntGetAppID
(
	const PrntPara* _pPrntPar /* [in]打印参数指针 */
)
{
	UINT1 ucID;
	/* 请求打印操作的业务应用ID */ 
	ucID = _pPrntPar->ucAppID; 

	return ucID;
}

/*
**********************************************************
*
* 函数名:prntDealPrintResult
*
* 功  能:处理打印结果
*
* 输  入:g_ucprntLinePrinted
*		  g_usTSPrintedLine
*		  g_ucprntState
*
* 输  出:无
*
* 返  回:cRet
*
**********************************************************
*/
INT1 prntDealPrintResult
(
   UINT1  _ucAppID         /* 应用ID */
)
{
	UINT1 cRet;
	OS_EVENT	*pQEvent;
	/* 处理返回已成功打印行数 */
	if (PRINTER_TYPE)
	{
		g_ucMsgBuffer[0] = g_ucprntLinePrinted;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -