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

📄 pc_comm.c

📁 一款收款机C源代码!因为是几年前的代码了
💻 C
📖 第 1 页 / 共 5 页
字号:
	if(Data_Area[15] > 2)
	{
		Send_Error_Info(NOT_MATCH_FORMAT);
		return;
	}
	
	memcpy(refund.desc, (char *)Data_Area, MAX_DESC_LEN);
	refund.price = price;
	refund.flag = Data_Area[15];
	Send_Succeed_Info();
}


/*-----------------------------------------------------------------------*
					Welcome message down-load.
 *-----------------------------------------------------------------------*/
void Do_Wlcm_Msg_Dwn(void)
{
	byte i;
	byte idx;
	char *p;

	if(Data_Len != (1 + MSG_HEAD_LINES*(2+MAX_PRN_LEN*2)/2))
	{
		Send_Error_Info(NOT_MATCH_FORMAT);
		return;
	}
	idx = Data_Area[0];
	if(idx > 1)
	{
		Send_Error_Info(NOT_MATCH_FORMAT);
		return;
	}
	idx *= 3;
	p = (char *)(Data_Area+1);

	for(i = 0; i < MSG_HEAD_LINES/2; i ++)
	{
		memcpy(Wlcm_Msg[i+idx], p, 2+MAX_PRN_LEN*2);
		p += 2+MAX_PRN_LEN*2;
	}
	Send_Succeed_Info();
}


/*-----------------------------------------------------------------------*
					Welcome & Trailer message down-load.
 *-----------------------------------------------------------------------*/
void Do_Botm_Msg_Dwn(void)
{
	byte i;
	byte idx;
	char *p;

	if(Data_Len != (1 + MSG_BTM_LINES*(2+MAX_PRN_LEN*2)/2))
	{
		Send_Error_Info(NOT_MATCH_FORMAT);
		return;
	}
	idx = Data_Area[0];
	if(idx > 1)
	{
		Send_Error_Info(NOT_MATCH_FORMAT);
		return;
	}
	idx *= 3;
	p = (char *)(Data_Area+1);

	for(i = 0; i < MSG_BTM_LINES/2; i ++)
	{
		memcpy(Btm_Msg[i+idx], p, 2+MAX_PRN_LEN*2);
		p += 2+MAX_PRN_LEN*2;
	}
	Send_Succeed_Info();
}


/*-----------------------------------------------------------------------*
					Department parameter down-load.
 *-----------------------------------------------------------------------*/
void Do_Dept_Dwn(void)
{
	byte i;
	byte j;
	byte idx;
	byte tmp;
	long tmp1;
	DEPT_STRU *dept_stru;

	if(Data_Len != (1 + COMM_DEPT_NUM*sizeof(DEPT_STRU)))
	{
		Send_Error_Info(NOT_MATCH_FORMAT);
		return;
	}
	idx = Data_Area[0];
	if((idx > Max_Dept_No) || (idx == 0))
	{
		Send_Error_Info(NOT_MATCH_FORMAT);
		return;
	}
	if(idx > MAX_REL_DEPT_CNT)
	{
		Send_Error_Info(NOT_MATCH_FORMAT);
		return;
	}
	if((idx > Max_Dept_No - COMM_DEPT_NUM + 1) || (COMM_DEPT_NUM > Max_Dept_No))
	{
		/* Judge the data is zero or not, if not all zero, send an error information, Remain. */
	}
	idx --;

	dept_stru = (DEPT_STRU *)(Data_Area+1);
	for(i = 0, j = idx; (i < COMM_DEPT_NUM) && (j < Max_Dept_No); i ++, j ++)
	{
		tmp1 = Bcd2Long(dept_stru[i].Pre_Price, 4);
		if(tmp1 > MAX_DEPT_PRICE)
		{
			Send_Error_Info(NOT_MATCH_FORMAT);
			return;
		}
		#ifdef AUTO_PER			/* Support the department auto percent function */
		tmp1 = Bcd2Long(dept_stru[i].Auto_Per_Rate, 3);
		if(tmp1 > 99999)
		{
			Send_Error_Info(NOT_MATCH_FORMAT);
			return;
		}
		#endif /* End AUTO_PER */
		tmp = dept_stru[i].Attribute[0];
		if((tmp >> 4) > 1)
		{
			Send_Error_Info(NOT_MATCH_FORMAT);
			return;
		}
		if(sysflag->Tax_System == 1)
		{
			if((tmp & 0x0F) >= get_tax_comb())
			{
				Send_Error_Info(NOT_MATCH_FORMAT);
				return;
			}
		}
		else
		{
			if((tmp & 0x0F) > MAX_VAT_NUM)
			{
				Send_Error_Info(NOT_MATCH_FORMAT);
				return;
			}
		}
		tmp = dept_stru[i].Attribute[1];
		if(((tmp>>4) > MAX_HALO_LEN) || ((tmp & 0x0F) > MAX_GROUP_NUM) || ((tmp & 0x0F) == 0))
		{
			Send_Error_Info(NOT_MATCH_FORMAT);
			return;
		}
		tmp = dept_stru[i].Attribute[2];
		#ifdef AUTO_PER			/* Support the auto percent function */
		if((tmp&0x0F) > 1)
		{
			Send_Error_Info(NOT_MATCH_FORMAT);
			return;
		}
		#endif /* End AUTO_PER */
		#ifdef VER_RSNT			/* Support the restaurant function */
		if((tmp>>4) > 1)
		{
			Send_Error_Info(NOT_MATCH_FORMAT);
			return;
		}
		#endif /* End VER_RSNT */
	}

	for(i = 0, j = idx; (i < COMM_DEPT_NUM) && (j < Max_Dept_No); i ++, j ++)
	{
		dept[j].price = Bcd2Long(dept_stru[i].Pre_Price, 4);
		#ifdef AUTO_PER			/* Support the auto percent function */
		dept[j].per_rate = Bcd2Long(dept_stru[i].Auto_Per_Rate, 3);
		dept[j].per_flag = (dept_stru[i].Attribute[2])&0x0F;
		#endif /* End AUTO_PER */
		dept[j].pflag = dept_stru[i].Attribute[0];
		dept[j].group = (dept_stru[i].Attribute[1] & 0x0F);
		dept[j].Hdlo = (dept_stru[i].Attribute[1] >> 4);
		#ifdef VER_RSNT			/* Support the restaurant function */
		dept[j].send_kp_flag = (dept_stru[i].Attribute[2])>>4;
		#endif /* End VER_RSNT */
		memcpy(dept[j].desc, dept_stru[i].Desc, MAX_DESC_LEN_EX+1);
	}

	Send_Succeed_Info();
}

/*-----------------------------------------------------------------------*
					Percent parameter down-load.
 *-----------------------------------------------------------------------*/
void Do_Per_Dwn(void)
{
	byte i;
	byte tmp;
	long rate[3];
	PER_STRU *per_stru;

	if(Data_Len != (MAX_PER_NUM * sizeof(PER_STRU)))
	{
		Send_Error_Info(NOT_MATCH_FORMAT);
		return;
	}
	per_stru = (PER_STRU *)(Data_Area);
	for(i = 0; i < MAX_PER_NUM; i ++)
	{
		rate[i] = Bcd2Long(per_stru[i].Rate, 3);
		if(rate[i] > MAX_PER_VALUE)
		{
			Send_Error_Info(NOT_MATCH_FORMAT);
			return;
		}
		tmp = per_stru[i].Attr;
		if((tmp>>4) > 2)
		{
			Send_Error_Info(NOT_MATCH_FORMAT);
			return;
		}
		if(((tmp & 0x0F) % 2) != ((percent[i].flag) % 2))		/* The attribute of -% and +% is different */
		{
			if((report.Per_Item_Cnt[i] != 0) || (PTD_report.Per_Item_Cnt[i] != 0)
					|| (report.Per_SubTtl_Cnt[i] != 0) || (PTD_report.Per_SubTtl_Cnt[i] != 0))
			{
				Send_Error_Info(REPORT_NOT_VOID);
				return;
			}
		}
	}

	for(i = 0; i < MAX_PER_NUM; i ++)
	{
		percent[i].rate = rate[i];
		percent[i].flag = (per_stru[i].Attr) & 0x0F;
		percent[i].round = (per_stru[i].Attr) >> 4;
		memcpy(percent[i].desc, per_stru[i].Desc, MAX_DESC_LEN);
	}
	Send_Succeed_Info();
}

/*-----------------------------------------------------------------------*
					Ram Logo down-load.
 *-----------------------------------------------------------------------*/
void Do_Ram_Logo_Dwn(void)
{
	byte i;
	byte idx;
	byte tmp;
	word Base;

	if(Data_Len != RAM_LOGO_DWN_SIZE + 1)
	{
		Send_Error_Info(NOT_MATCH_FORMAT);
		return;
	}
	idx = Data_Area[0];
	if(idx >= RAM_LOGO_DWN_TIMES)
	{
		Send_Error_Info(NOT_MATCH_FORMAT);
		return;
	}
	Base = ((word)idx) * RAM_LOGO_DWN_SIZE;

	for(i = 0; i < RAM_LOGO_DWN_SIZE; i ++)
	{
//		RAM_Logo[Base + i] = Data_Area[1 + i];
		tmp = Data_Area[1 + i];
		tmp ^= 0xFF;
		RAM_Logo[Base + i] = tmp;
	}
	Send_Succeed_Info();
}

/*-----------------------------------------------------------------------*
					Single PLU down-load.
 *-----------------------------------------------------------------------*/
void Do_Sngl_PLU_Dwn(void)
{
	int idx;
	int old_posi;
	int new_posi;
	PLU_STRU *plu_stru;

	if(Data_Len != (sizeof(PLU_STRU)+2))
	{
		Send_Error_Info(NOT_MATCH_FORMAT);
		return;
	}
	idx = (int)(*((int *)&Data_Area));				/* Get the PLU index number */
	if((idx > Max_Plu_No) || (idx <= 0))
	{
		Send_Error_Info(NOT_MATCH_FORMAT);
		return;
	}
	idx --;

	plu_stru = (PLU_STRU *)(Data_Area + 2);
	if((plu_stru->Dept_link > Max_Dept_No) || (plu_stru->Dept_link == 0))			/* The PLU linked departmetn is error */
	{
		Send_Error_Info(NOT_MATCH_FORMAT);
		return;
	}
    #ifdef REST_PLU_FUNC
	if (plu_stru->Attribute.mode > 2)
	{
		Send_Error_Info(NOT_MATCH_FORMAT);
		return;
	}
    #endif
	#ifdef SCANNER			/* Support the scanner function */
	if(SC_CmpCode(plu_stru->Bar_Code, plu[idx].barcode) != 0)				/* When the barcode is different */
	{
		if((plu[idx].quantity != 0) || (plu[idx].amount != 0))
		{
			Send_Error_Info(PLU_NOT_BLANK);
			return;
		}
		else
		{
			old_posi = SC_SearchIndex(plu[idx].barcode);
			new_posi = SC_SearchIndex(plu_stru->Bar_Code);
			if(new_posi >= 0)
			{
				Send_Error_Info(SAME_PLU_INDEX);
				return;
			}
			new_posi = -new_posi;
///			if(Length == PLU_RANGE_DWN_LEN)			/* This case will not occur, for the PC side will confine
///																	the single PLU's down-load number within 100 */
///			{
///				Sngl_PLU_Index_Update();
///				SC_UpdateIndex(old_posi,new_posi-1);		/* Update the index table */
///			}
//			OldPosi[Length] = old_posi;
//			NewPosi[Length] = new_posi;
//			Length ++;
			memcpy(plu[idx].barcode, plu_stru->Bar_Code, BAR_BUFF_LEN);
			SC_UpdateIndex(old_posi,new_posi-1);		/* Update the index table */
		}
	}
    #endif /* End SCANNER */
    #ifdef REST_PLU_FUNC
	plu[idx].attr = plu_stru->Attribute;
    #endif
	plu[idx].plink = plu_stru->Dept_link;
	plu[idx].price = Bcd2Long(plu_stru->Pre_Price, 3);
	memcpy(plu[idx].desc, plu_stru->Desc, MAX_DESC_LEN_EX+1);

	Send_Succeed_Info();
//	Sngl_PLU_Index_Bak[Length] = idx;					/* Store the PLU number, while exit the communication,
//																		will update the PLU index table */
}

/*****************************************************************************/
/*-----------------------------------------------------------------------*
					PLU parameter up -load.
 *-----------------------------------------------------------------------*/
void Do_PLU_Up(void)
{
	byte i;
	int j;
	int idx;
	PLU_STRU	*plu_stru;

	if(Data_Len != 2)				/* The data's length must 2 */
	{
		Send_Error_Info(NOT_MATCH_FORMAT);
		return;
	}
	idx = (int)(*((int *)&Data_Area));				/* Get the PLU index number */
	if((idx > (Max_Plu_No/* - COMM_PLU_NUM + 1*/)) || (idx <= 0))
					/* The number of PLU commnication in one time is 10 */
	{
		Send_Error_Info(NOT_MATCH_FORMAT);
		return;
	}
	idx --;

	Send_Buff[0] = PLU_UP;
	Data_Len = COMM_PLU_NUM * sizeof(PLU_STRU);		/* The send data area's length */
	Send_Buff[1] = Data_Len;
	plu_stru = (PLU_STRU *)(Send_Buff+2);
	for(i = 0, j = idx; i < COMM_PLU_NUM; i ++, j ++)		/* Get the data area's data */
	{
		if(j < Max_Plu_No)
		{
			#ifdef SCANNER 		/* Support the scanner function */
			memcpy(plu_stru[i].Bar_Code, plu[j].barcode, BAR_BUFF_LEN);
#endif /* End SCANNER */
			plu_stru[i].Dept_link = plu[j].plink;
            #ifdef REST_PLU_FUNC
			plu_stru[i].Attribute = plu[j].attr;
            #endif
			Long2Bcd(plu_stru[i].Pre_Price, plu[j].price, 3);
			memcpy(plu_stru[i].Desc, plu[j].desc, MAX_DESC_LEN_EX+1);
		}
		else
		{
//			#ifdef SCANNER 		/* Support the scanner function */
//			memset(plu_stru[i].Bar_Code, 0, BAR_BUFF_LEN);
//			#endif /* End SCANNER */
//			plu_stru[i].Attribute = 0;
//			memset(plu_stru[i].Pre_Price, 0, 3);
//			memset(plu_stru[i].Desc, 0, MAX_DESC_LEN);
			memset(&(plu_stru[i]), 0, sizeof(PLU_STRU));
		}
	}
	CalCS(Send_Buff+2, Data_Len, &Check_Sum);
	Send_Buff[2+Data_Len] = Check_Sum;

	Write_Head();			/* Write the head information */
	Wr_Str_Uart(COMM_PORT, Send_Buff, 2+Data_Len+1);
}


#ifdef SCANNER 		/* Support the scanner function */
/*-----------------------------------------------------------------------*
					PLU index table up -load.
 *-----------------------------------------------------------------------*/
void Do_PLU_Idx_Up(void)
{
	byte i;
	int j;
	int idx;
	int *p;

	if(Data_Len != 2)				/* The data's length must 2 */
	{
		Send_Error_Info(NOT_MATCH_FORMAT);
		return;
	}
	idx = (int)(*((int *)&Data_Area));				/* Get the PLU index number */
	if((idx > (Max_Plu_No/* - COMM_PLU_INDEX_NUM + 1*/)) || (idx <= 0))
				/* The number of PLU commnication in one time is 10 */
	{
		Send_Error_Info(NOT_MATCH_FORMAT);
		return;
	}
	idx --;

	Send_Buff[0] = PLU_IDX_UP;
	Data_Len = COMM_PLU_INDEX_NUM * 2;		/* The send data area's length */
	Send_Buff[1] = Data_Len;
	p = (int *)(Send_Buff+2);			/* Get the start of the index number */
	for(i = 0, j = idx; i < COMM_PLU_INDEX_NUM; i ++, j ++)
	{
		if(j < Max_Plu_No)
			p[i] = Sindex[j] + 1;			/* In the PC side, the index table store the first PLU number of 1, not 0 */
		else
			p[i] = 0;
	}
	CalCS((byte *)p, Data_Len, &Check_Sum);
	Send_Buff[2 + Data_Len] = Check_Sum;
	Write_Head();
	Wr_Str_Uart(COMM_PORT, Send_Buff, 2+Data_Len+1);

⌨️ 快捷键说明

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