static void DB_check_rpt()
{	
	uint8 index = MT + 1;
	uint16 temp;
	uint32 temp32;
	sendbuf[index++] = MDB_CHECK_RPT;
	sendbuf[index++] = MDB_getBillStatus();
	temp = MDB_getBillErrNo();
	sendbuf[index++] = HUINT16(temp);
	sendbuf[index++] = LUINT16(temp);

	temp32 = MDB_getBillRecvAmount();
	sendbuf[index++] = H0UINT32(temp32);
	sendbuf[index++] = H1UINT32(temp32);
	sendbuf[index++] = L0UINT32(temp32);
	sendbuf[index++] = L1UINT32(temp32);
	
	temp32 = MDB_getBillRemainAmount();
	sendbuf[index++] = H0UINT32(temp32);
	sendbuf[index++] = H1UINT32(temp32);
	sendbuf[index++] = L0UINT32(temp32);
	sendbuf[index++] = L1UINT32(temp32);
	
	//硬币器
	sendbuf[index++] = MDB_getCoinStatus();
	temp = MDB_getCoinErrNo();
	sendbuf[index++] = HUINT16(temp);
	sendbuf[index++] = LUINT16(temp);
	
	temp32 = MDB_getCoinRecvAmount();
	sendbuf[index++] = H0UINT32(temp32);
	sendbuf[index++] = H1UINT32(temp32);
	sendbuf[index++] = L0UINT32(temp32);
	sendbuf[index++] = L1UINT32(temp32);
	
	temp32 = MDB_getCoinRemainAmount();
	sendbuf[index++] = H0UINT32(temp32);
	sendbuf[index++] = H1UINT32(temp32);
	sendbuf[index++] = L0UINT32(temp32);
	sendbuf[index++] = L1UINT32(temp32);
	
	
	DB_package(DB_MT_CHECK_RPT,index);
	DB_uart1Send();
	
	
	
}
示例#2
0
/*********************************************************************************************************
** Function name:       WriteLogDetailAPI
** Descriptions:        将明细日志写到flash中
** input parameters:    
** output parameters:   无
** Returned value:      无
*********************************************************************************************************/
void WriteLogDetailAPI(uint16_t	LogDetailPage)
{
	uint8_t *tp1,i,buf[512];
	uint16_t crc,len;

	tp1 = (uint8_t *) &LogParaDetail;//交易数据记录	
	
	if(sizeof(LogParaDetail) > 500)
	{
		Trace("sizeof(LogPara) is %d  > 500\r\n",sizeof(LogPara));
		return ;
	}
	len = sizeof(LogParaDetail);
	memcpy(buf,tp1,len);
	crc = CrcCheck(buf,len);
	buf[len] = HUINT16(crc);
	buf[len + 1] = LUINT16(crc);
	buf[len + 2] = 0xE1;//总交易记录写入flash 标志
	AT45DBWritePage(LogDetailPage,buf);
	Trace("TradeNum=%d\r\n",LogParaDetail.TradeNum);
	for(i = 0;i < 24 ; )
	{
		Trace("ColumnNo=%c%c%c\r\n ",LogParaDetail.ColumnNo[i],LogParaDetail.ColumnNo[i+1],LogParaDetail.ColumnNo[i+2]);
		i+=3;
		OSTimeDly(20);
	}
	//PrintLogDetailAPI();
	OSTimeDly(OS_TICKS_PER_SEC/100);
	
	memset(&LogParaDetail,0,sizeof(LogParaDetail));
}
/*********************************************************************************************************
** Function name:       saveDetailTradeInfo
** Descriptions:        保存详细交易记录
** input parameters:    无
** output parameters:   无
** Returned value:      无
*********************************************************************************************************/
void saveDetailTradeInfo(void)
{
	unsigned short addr = 0;
	unsigned short len,crc;
	unsigned char buf[ADD_TRADE_PAGE_LEN] = {0};
	//确定交易页号
	if(stTotalTrade.tradePageNo < TRADE_MAX_PAGE)
		stTotalTrade.tradePageNo++;
	else
		stTotalTrade.tradePageNo = 1;
	RTCReadTime(&stDetailTradeInfo.tradeTime);
	addr = ADD_TRADE_INFO + stTotalTrade.tradePageNo * ADD_TRADE_PAGE_LEN;	
	len = sizeof(stDetailTradeInfo);
	memcpy(buf,(void *)&stDetailTradeInfo,len);
	crc = CrcCheck(buf,len);
	buf[len + 0] = HUINT16(crc);
	buf[len + 1] = LUINT16(crc);
	saveFlash(addr,buf,ADD_TRADE_PAGE_LEN);

	//清本次交易数据信息
	memset((void *)&stDetailTradeInfo,0,sizeof(stDetailTradeInfo));
	
	
	
}
示例#4
0
/*********************************************************************************************************
** Function name:       WriteLogAPI
** Descriptions:        将区域交易记录,总交易记录写到flash中
** input parameters:    
** output parameters:   无
** Returned value:      无
*********************************************************************************************************/
void WriteLogAPI(void)
{
	uint8_t *tp2,buf[512];
	uint16_t crc,len;

	tp2 = (uint8_t *) &LogPara;//交易数据记录	
	/*
	crc = CrcCheck(tp2,sizeof(LogPara)-2);
	LogPara.CrcCheck[0] = crc/256;
	LogPara.CrcCheck[1] = crc%256; */
	//Trace("\r\n logcrc=%d,%x,%x",sizeof(LogPara)-2,LogPara.CrcCheck[0],LogPara.CrcCheck[1]);
	//changed by yoc 2013.9.11
	if(sizeof(LogPara) > 500)
	{
		Trace("sizeof(LogPara) is %d  > 500\r\n",sizeof(LogPara));
		return ;
	}
	len = sizeof(LogPara);
	memcpy(buf,tp2,len);
	crc = CrcCheck(buf,len);
	buf[len] = HUINT16(crc);
	buf[len + 1] = LUINT16(crc);
	buf[len + 2] = 0xE0;//区域交易记录写入flash标志
	AT45DBWritePage(4040,buf);
	//Trace("LogPara write ...\r\n");
}
示例#5
0
uint8 FS_package(FS_MSG *msg)
{
	uint8 *buf = msg->buf;
	uint16 len = 0,crc;
	len = msg->dataLen;
	buf[0] = DLE;
	buf[1] = STX;
	buf[2] = HUINT16(len);
	buf[3] = LUINT16(len);
	
	len += 4;
	buf[len++] = DLE;
	buf[len++] = ETX;
	crc = FS_crc(&buf[2],len - 2);
	buf[len++] = LUINT16(crc);
	buf[len++] = HUINT16(crc);
	msg->len = len;
	return 1;
}
示例#6
0
void LOG_writeId(ST_MAC_SN *macSn)
{
	uint8_t buf[512] = {0},len;
	uint16_t crc;
	unsigned char i;
	len = sizeof(macSn->id);
	for(i = 0;i < len;i++){
		buf[i] = macSn->id[i];
	}
	crc = CrcCheck(buf,len);
	buf[len] = HUINT16(crc);
	buf[len + 1] = LUINT16(crc);
	buf[len + 2] = 0xEA;//区域交易记录写入flash标志
	AT45DBWritePage(PAGE_MAC_SN,buf);
}
/*********************************************************************************************************
** Function name:       save_data
** Descriptions:        保存信息
** input parameters:    ptr:写入flash的数据指针,
						len 写入长度 最大长度不超过240字节
						addr写入的起始地址
** output parameters:   无
** Returned value:     0 失败   1成功
*********************************************************************************************************/
static unsigned char  save_data(void *ptr,unsigned short len,unsigned short addr)
{
	unsigned short crc;
	unsigned char buf[256] = {0};//256字节 分8次存储
	if(!ptr || !len || (len > 240))
		return 0;
	
	memcpy(buf,ptr,len);
	crc = CrcCheck(buf,len);
	buf[len + 0] = HUINT16(crc);
	buf[len + 1] = LUINT16(crc);
	len += 2;
	saveFlash(addr,buf,256);	
	return 1;

}
/*********************************************************************************************************
** Function name:       bill_recycler_enable
** Descriptions:        循环斗使能
** input parameters:    无
** output parameters:   无
** Returned value:      无
*********************************************************************************************************/
uint8 bill_recycler_enable(uint16 en)
{
	uint8 wdata[20] = {0x00},res,index = 0,i;
	wdata[index++] = 0x04;//type
	
	wdata[index++] = HUINT16(en);
	wdata[index++] = LUINT16(en);
	for(i = 0;i < 16;i++){
		if(en & (0x01U << i)){
			wdata[index++] = 0x03;
		}
		else{
			wdata[index++] = 0x00;
		}
	}
   	res = bill_send(MDB_BILL_EXPANSION,wdata,19);	
	return res;
}
/*********************************************************************************************************
** Function name:       saveSystemParaFromFlash
** Descriptions:        将系统参数保存到flash中  4个字节存
** input parameters:    
** output parameters:   无
** Returned value:      无
*********************************************************************************************************/
unsigned char saveSystemParaFromFlash()
{
	unsigned char buf[256] = {0};
	unsigned short len = 0,crc;
	
	memcpy(&buf[len],stDevValue.BillValue,8 * 4);//纸币器通道面值
	len += 8 * 4;	
	memcpy(&buf[len],stDevValue.CoinValue,8 * 4);//硬币器通道面值
	len += 8 * 4;
	memcpy(&buf[len],stDevValue.HpValue,HOPPER_NUMS * 4);//hopper通道面值
	len += HOPPER_NUMS * 4;
	memcpy(&buf[len],(unsigned char *)&SYSPara,sizeof(SYSPara));
	len += sizeof(SYSPara);
	crc = CrcCheck(buf,len);
	buf[len + 0] = HUINT16(crc);
	buf[len + 1] = LUINT16(crc);
	
	return saveFlash(ADD_SYSTEM_PARA,buf,len + 2);
	
}
static void DB_hp_payout_rpt(void)
{
	uint8 in = MT + 1,out = MT + 2;
	uint8 addr;
	uint16 nums,changed = 0;
	
	addr = recvbuf[out++];
	nums = INTEG16(recvbuf[out+0],recvbuf[out+1]);
	
	if(MDB_getCoinDispenser() == COIN_DISPENSER_HOPPER){
		changed = HP_payout_by_no(addr,nums);
	}
	else{
		changed = 0;
	}
	
	sendbuf[in++] = MDB_HP_PAYOUT_RPT;
	sendbuf[in++] = addr;
	sendbuf[in++] =	HUINT16(changed);
	sendbuf[in++] =	LUINT16(changed);
	DB_package(DB_MT_ACTION_RPT,in);
	DB_uart1Send();
	
}
/*********************************************************************************************************
** Function name:     	DB_bill_info_rpt
** Descriptions:	      
** input parameters:    无
** output parameters:   无
** Returned value:      无
*********************************************************************************************************/
static void DB_bill_info_rpt()
{	
	uint8 index = MT + 1,i;
	sendbuf[index++] = MDB_BILL_INFO_RPT;
	sendbuf[index++] = stMdb.bill_type;
	
	if(MDB_getBillAcceptor() == BILL_ACCEPTOR_MDB){
		//code
		for(i = 0;i < 3;i++){
			sendbuf[index++] = (uint8)stBill.id.manuCode[i];
		}
		//sn
		for(i = 0;i < 12;i++){
			sendbuf[index++] = (uint8)stBill.id.sn[i];
		}
		//mode
		for(i = 0;i < 12;i++){
			sendbuf[index++] = (uint8)stBill.id.model[i];
		}
		//ver
		sendbuf[index++] = stBill.id.softVer[0];
		sendbuf[index++] = stBill.id.softVer[1];
		//capacity
		sendbuf[index++] = HUINT16(stBill.setup.stkCapacity);
		sendbuf[index++] = LUINT16(stBill.setup.stkCapacity);
		//ch_r
		for(i = 0;i < 16;i++){
			sendbuf[index++] = pcEncodAmount(stBill.setup.ch[i]);
		}
		//ch_d
		for(i = 0;i < 16;i++){
			sendbuf[index++] = pcEncodAmount(stBill.recycler.ch[i]);
		}
	}
	else{
		//code
		for(i = 0;i < 3;i++){
			sendbuf[index++] = 0;
		}
		//sn
		for(i = 0;i < 12;i++){
			sendbuf[index++] = 0;
		}
		//mode
		for(i = 0;i < 12;i++){
			sendbuf[index++] = 0;
		}
		//ver
		sendbuf[index++] = 0;
		sendbuf[index++] = 0;
		//capacity
		sendbuf[index++] = 0;
		sendbuf[index++] = 0;
		//ch_r
		for(i = 0;i < 16;i++){
			sendbuf[index++] = 0;
		}
		//ch_d
		for(i = 0;i < 16;i++){
			sendbuf[index++] = 0;
		}
	}
	DB_package(DB_MT_CHECK_RPT,index);
	DB_uart1Send();
}
示例#12
0
/*********************************************************************************************************
** Function name:     	HP_send
** Descriptions:	    EVB通讯
** input parameters:    Chl:选择通道;Head:包头;Sn:序列号;Type:消息类别;Addr:设备地址;Data:数据;
** output parameters:   *ACK:应答包
** Returned value:      1:收到应答;0:未收到应答即通讯失败
*********************************************************************************************************/
uint8 HP_send(uint8 addr,uint8 cmd,uint16 data)
{
	uint8 index = 0,i,ch,len,crc;
	memset((void *)recvbuf,0,sizeof(recvbuf));
	
	sn[addr] = (cmd == HP_PAYOUT) ? sn[addr] + 1: sn[addr]; //更新sn
	
	sendbuf[index++] = 0xED;
	sendbuf[index++] = 0x08; //len
	sendbuf[index++] = sn[addr];
	sendbuf[index++] = cmd;
	sendbuf[index++] = addr;
	sendbuf[index++] = LUINT16(data);
	sendbuf[index++] = HUINT16(data);
	sendbuf[index++] = XorCheck((uint8 *)sendbuf,7);
	
	uart3_clr_buf();
	//发送数据禁止切换任务
	OSSchedLock();
	Uart3PutStr((uint8 *)sendbuf,8);
	OSSchedUnlock();
	
	#ifdef DEBUG_HOPPER
	print_hopper("HP-SEND[%d]:",index);
	for(i = 0;i < index;i++){
		print_hopper("%02x ",sendbuf[i]);
	}
	print_hopper("\r\n");
	#endif
	
	index = 0;
	Timer.hopper_recv_timeout = 100;
	while(Timer.hopper_recv_timeout){ //1000ms内收到ACK,否则超时
		if(Uart3BuffIsNotEmpty() == 1){
			ch = Uart3GetCh();
			if(index == 0){
				if(ch == 0xFD){
					recvbuf[index++] = ch;
				}
			}
			else if(index == 1){
				len = ch;
				recvbuf[index++] = ch;
			}
			else if(index >= (len - 1)){
				recvbuf[index++] = ch;
				crc = XorCheck((uint8 *)recvbuf,len - 1);
				if(crc == ch){
#ifdef DEBUG_HOPPER
					print_hopper("HP-RECV[%d]:",recvbuf[1]);
					for(i = 0;i < recvbuf[1];i++){
						print_hopper("%02x ",recvbuf[i]);
					}
					print_hopper("\r\n");
#endif
					return 1;
				}
			}
			else{
				recvbuf[index++] = ch;
			}
		}
		else{
			msleep(20);
		}
	}
	return 0;
}
示例#13
0
uint8 BT_send(uint8 cmd,uint8 cabinet,uint8 arg,uint8 *rdata)
{
    uint8 buf[24] = {0},len = 0,ret,rbuf[64] = {0};
    uint16 crc;
	uint32 ms;
	#ifdef BENTO_DEBUG
	uint8 i;
	#endif
	
	buf[len++] = BT_HEAD;
	buf[len++] = 0x07;
	buf[len++] = cabinet - 1;
	buf[len++] = cmd;
	buf[len++] = cabinet - 1;
	buf[len++] = cabinet - 1;//0x08;
	buf[len++] = arg;//0x00;	
	crc = CrcCheck(buf,len);
	buf[len++] = HUINT16(crc);
	buf[len++] = LUINT16(crc);
	#ifdef BENTO_DEBUG
	print_bento("BT-Send[%d]:",len);
	for(i = 0;i < len;i++){
		print_bento("%02x ",buf[i]);
	}
	print_bento("\r\n");
	#endif
	
	uartClear();
	uartPutStr(buf,len);
	ms = (cmd == BT_TYPE_CHECK) ?  1000: 2000;
	ret = BT_recv(rbuf,&len,ms);
	
	#ifdef BENTO_DEBUG
	print_bento("BT-Recv[%d]:",len);
	for(i = 0;i < len;i++){
		print_bento("%02x ",rbuf[i]);
	}
	print_bento("\r\n");
	#endif
	if(ret == 1){
		if(cmd == BT_TYPE_OPEN){
			if(rbuf[3] == BT_TYPE_OPEN_ACK){
				return 1;
			}
		}
		else if(cmd == BT_TYPE_CHECK){
			if(rbuf[3] == BT_TYPE_CHECK_ACK){
				if(rdata != NULL){
					memcpy(rdata,rbuf,rbuf[1]);
				}
				return 1;
			}
		}
		else if(cmd == BT_TYPE_LIGHT){
			if(rbuf[3] == BT_TYPE_LIGHT_ACK)
				return 1;
			else
				return 0;
		}
		else if(cmd == BT_TYPE_HOT){
			if(rbuf[3] == BT_TYPE_HOT_ACK)
				return 1;
			else
				return 0;
		}
		else if(cmd == BT_TYPE_COOL){
			if(rbuf[3] == BT_TYPE_COOL_ACK)
				return 1;
			else
				return 0;
		}
	}
	return 0;
}
示例#14
0
//driver级别,主窗口
unsigned char FS_poll(void)
{
	static unsigned char ch;
	static unsigned int in = 0;
	unsigned char *buf = (unsigned char *)fsRecvMsg.buf;
	static unsigned int textLen = 0;
	static unsigned short crc;

	switch(flowStatus){
		case FS_STATUS_IDLE:
			if(FS_getChar(&ch) == 1){
				print_fs("ch = %x ******************************\r\n",ch);
			}
			break;
		case FS_STATUS_SEND_REQ:
			if(request != FS_REQ_IDLE){ //上位机有请求命令
				print_fs("FS-----request == %d\r\n\r\n",request);
				FS_clearUart();
				memset(fsRecvMsg.buf,0,sizeof(fsRecvMsg.buf));
				FS_sendCmd(FS_TYPE_REQUEST);
				FS_setFlow(FS_STATUS_SEND_READY);
				//FS_setReqTimer(2000);
			}
			break;
		case FS_STATUS_SEND_READY:
			if(FS_recvCmd() == ACK){ 
				FS_sendUart(fsSendMsg.buf,fsSendMsg.len); //发送命令 还没实现
				FS_setFlow(FS_STATUS_SEND);
			}
			#if 0
			else{
				ch == FS_getReqTimer();
				if(ch == 1){
					FS_setFlow(FS_STATUS_SEND_REQ);
					msleep(1000);
				}
				else if(ch == 2){ //超时太多
					FS_setFlow(FS_STATUS_ERR);
				}
			}
			#endif
			break;
		case FS_STATUS_SEND:
			if(FS_recvCmd() == ACK){ 
				FS_setFlow(FS_STATUS_RECV_ENQ);
			}
			break;
		case FS_STATUS_RECV_ENQ:
			if(FS_recvCmd() == ENQ){ 
				FS_sendCmd(FS_TYPE_ACK);
				FS_setFlow(FS_STATUS_RECV_DATA);
				in = 0;
			}
			break;
		case FS_STATUS_RECV_DATA:
			if(FS_getChar(&ch) == 1){
				buf[in++] = ch;
				if(in == 1){ //DLE
					textLen = 0;
				}
				else if(in == 2){ //STX
					if(buf[0] != DLE || buf[1] != STX){ //不是 STX重新接收
						in = 0;
					}
				}
				else if(in == 3){
					textLen = ch;
				}
				else if(in == 4){
					textLen = textLen * 256 + ch;
					//print_fs("LEN=%x .....[%x %x %x %x]\r\n",textLen,buf[0],buf[1],buf[2],buf[3]);
				}
				else {
					if(in >= (textLen + 8)){ //接收数据完成
						crc = FS_crc(&buf[2],in - 4);
						print_fs("--------Crc[%x %x] vs FS_crc[%x %x]------\r\n",buf[in - 2],buf[in - 1],HUINT16(crc),LUINT16(crc));
						if(buf[in - 2] == LUINT16(crc) && buf[in - 1] == HUINT16(crc)){
							//如果校验成功 则需要回应ACK 一旦回应ACK FS56不再重复发送
							FS_sendCmd(FS_TYPE_ACK);
							FS_setFlow(FS_STATUS_IDLE);
							print_fs("\r\n=====================Over====================================\r\n\r\n\r\n");
						}
						in = 0;
					}
				}
			}
			break;
		case FS_STATUS_ERR:break;
		default:FS_setFlow(FS_STATUS_IDLE);break;
	}

	return 1;
}