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

📄 lb_cm.c

📁 中国石油二期加油站IC系统后台通讯软件
💻 C
📖 第 1 页 / 共 3 页
字号:
	Data fileBuf[10];

	if((fd = fopen( path, "r" )) == NULL)
	{
		SPutMsg(msg);
		RXLOGERROR(0, 0, 0, "ERROR");
		RETVALUE(RFAILED);
	}


	while(!feof(fd))
	{
		/* modify by shang 2002-7-23 18:52:57 */
#if 0 /* last code */

		bufLen = fread( fileBuf, sizeof( char ), 1, fd);
		if(ferror(fd))
		{
			SPutMsg(msg);
			RETVALUE(RFAILED);
		}

		SAddPstMsgMult(fileBuf, bufLen, msg);

#else /* new code */
		bufLen = fread(fileBuf, sizeof( char ), 1, fd);
		if(bufLen == 0)
		{
			break;
		}
		if(fileBuf[0] == '\n')
		{
			continue;
		}

		bufLen = fread(&fileBuf[1], sizeof( char ), 1, fd);
		if(bufLen == 0)
		{
			break;
		}
		if(fileBuf[1] == '\n')
		{
			fileBuf[1] = fileBuf[0];
			fileBuf[0] = 0;
		}
		key = LBCMATOHEX(fileBuf, 0, 1) + LBCMATOHEX(fileBuf, 1, 0);

		SAddPstMsg(key, msg);

#endif /* end modify */

		/* modify by shang is over 2002-7-23 18:52:57*/
	}

	RETVALUE(ROK);
}





ScCommCb_s * findScComm(U8 gunId)
{
	EquCfgEntry_s * entry;

	entry = (EquCfgEntry_s *)cmLListFirst(&rxCb.pEquCfgList);
	while(NULLP != entry)
	{
		if(entry->entry.gunId == gunId)
		{
			break;
		}
		entry = (EquCfgEntry_s *)cmLListNext(&rxCb.pEquCfgList);
	}
	if(entry == NULLP)
	{
		RETVALUE(NULLP);
	}
	RETVALUE(entry->scCommCb);
}

EquCfgEntry_s * findEqu(U8 gunId)
{
	EquCfgEntry_s * entry;

	entry = (EquCfgEntry_s *)cmLListFirst(&rxCb.pEquCfgList);
	while(NULLP != entry)
	{
		if(entry->entry.gunId == gunId)
		{
			RETVALUE(entry);
		}
		entry = (EquCfgEntry_s *)cmLListNext(&rxCb.pEquCfgList);
	}
	RETVALUE(NULLP);
}


U32 lbCmAsc2Int(U8 asc)
{
	switch(asc)
	{
	case '0':
	case '1':
	case '2':
	case '3':
	case '4':
	case '5':
	case '6':
	case '7':
	case '8':
	case '9':
		RETVALUE(asc - '0');
	case 'a':
	case 'A':
		RETVALUE(10);

	case 'b':
	case 'B':
		RETVALUE(11);
	case 'c':
	case 'C':
		RETVALUE(12);

	case 'd':
	case 'D':
		RETVALUE(13);

	case 'e':
	case 'E':
		RETVALUE(14);

	case 'f':
	case 'F':
		RETVALUE(15);

	}
	RETVALUE(0);
}


S16 findFirstCmdNodeByChannel(U8 chId, CmdMsg_s ** ret_cmd)
{
	TranCb_s * tran ;
	RxCmdEntry_s * entry;
	CmdMsg_s * cmdNode = NULLP;
	entry = (RxCmdEntry_s *)cmLListFirst(&rxCb.rqstList);
	if(NULLP == entry)
	{
		RETVALUE(RFAILED);
	}
	tran = (TranCb_s *)cmLListFirst(&entry->tranList);
	while(NULLP != tran)
	{
		cmdNode = (CmdMsg_s *)cmLListFirst(&tran->cmdLst);
		if(cmdNode != NULLP && cmdNode->chId == chId)
		{
			break;
		}
		cmdNode = NULLP;
		tran = (TranCb_s *)cmLListNext(&entry->tranList);
	}
	if(cmdNode == NULLP)
	{
		RETVALUE(RFAILED);
	}
	* ret_cmd = cmdNode;
	RETVALUE(ROK);
}

S16 findCmdNodByCode(U8 cmdCode, CmdMsg_s ** ret_cmd)
{
	TranCb_s * tran ;
	RxCmdEntry_s * entry;
	CmdMsg_s * cmdNode = NULLP;
	entry = (RxCmdEntry_s *)cmLListFirst(&rxCb.rqstList);
	if(NULLP == entry)
	{
		RETVALUE(RFAILED);
	}
	tran = (TranCb_s *)cmLListFirst(&entry->tranList);
	while(NULLP != tran)
	{
		cmdNode = (CmdMsg_s *)cmLListFirst(&tran->cmdLst);
		if(cmdNode != NULLP && cmdNode->msgCode == cmdCode)
		{
			*ret_cmd = cmdNode;
			RETVALUE(ROK);
		}
		tran = (TranCb_s *)cmLListNext(&entry->tranList);
	}
	RETVALUE(RFAILED);
}

S16 findFirstCmdNode(CmdMsg_s ** ret_cmd)
{
	TranCb_s * tran;
	GETFIRSTTRAN(tran);
	*ret_cmd = (CmdMsg_s *)cmLListFirst(&tran->cmdLst);
	if(*ret_cmd == NULLP)
	{
		RETVALUE(RFAILED);
	}
	RETVALUE(ROK);
}

S16 segScMsg(Data * buf, MsgLen len, Data ** ret_buf, MsgLen * ret_len)
{
	Bool start = FALSE;
	S32 i;
	*ret_len = 0;
	for(i = 0; i < (len); i++)
	{
		if(buf[i] == 0xaa && buf[i+1] == 0x55 && start == FALSE)
		{
			start = TRUE;
			*ret_buf = &buf[i];
			*ret_len = i;
		}
		else if(buf[i] == 0xaa && buf[i+1] == 0x55 && start == TRUE)
		{
			*ret_len = i - *ret_len;
			break;
		}
	}
	if(i == (len) && start == FALSE)
	{
		*ret_buf = NULLP;
		*ret_len = 0;
	}
	else
	{
		*ret_len  = i - *ret_len;
	}
	RETVALUE(ROK);
}

S16 lbCmSetPrice(Time_s * time, PriceEntry_s * price)
{
	PriceFormat_s format;
	fpos_t pos;
	U32 i;
	FILE * file;

	file = fopen(PRICE_FILE_NAME, "rb");
	fread(&format, 1, sizeof(PriceFormat_s), file);
	fclose(file);
	for(i = 0 ; i < OILTYPE_NUM; i++)
	{
		if(format.price[i].oilType == price->oilType)
		{
			memcpy(&format.price[i], price, sizeof(PriceEntry_s));
			break;
		}
	}

	file = fopen(PRICE_FILE_NAME, "wb");
	fwrite(&format, 1, sizeof(PriceFormat_s), file);
	fclose(file);
	RETVALUE(ROK);
}

S16 lbCmGetPriceByOilType(U8 oilType, U16 * ret_price, Time_s * time)
{
	FILE * file;
	PriceFormat_s format;
	U32 i;

	file = fopen(PRICE_FILE_NAME, "rb");
	if(file == NULLP)
	{
		RXLOGERROR(0, 0, 0 , "ERROR");
		RETVALUE(RFAILED);
	}
	fread(&format, 1, sizeof(PriceFormat_s), file);
	fclose(file);

	for(i = 0 ; i < OILTYPE_NUM; i++)
	{
		if(oilType == format.price[i].oilType)
		{
			*ret_price = format.price[i].price;
			memcpy(time, &format.time, sizeof(Time_s));
			break;

		}
	}
	if(i == OILTYPE_NUM)
	{
		RETVALUE(RFAILED);
	}
	RETVALUE(ROK);

}

S16 lbWriteLog(Txt * s)
{
	FILE * file;
	Txt fileName[128];
	DateTime t;

	SGetDateTime(&t);
	sprintf(fileName, "d:/rx_log/20%02d%02d%02d.txt", t.year, t.month, t.day);

	file = fopen(fileName, "a+");
	if(file == NULLP)
	{
		file = fopen(fileName, "w+");
		if( file == NULLP)
		{
			RETVALUE(RFAILED);
		}
	}

	fwrite(s, 1, strlen(s) + 1, file);

	fclose(file);

	RETVALUE(ROK);
}

S16 lbScLog(ScCommCb_s * scCommCb, CmdMsg_s * cmd)
{
	Data buf[2048];
	DateTime t;
	MsgLen len, idx;
	Data key;
	FILE * file;
	Txt fileName[12];

	if(cmd == NULLP || scCommCb == NULLP || cmd->msg == NULLP)
	{
		RETVALUE(RFAILED);
	}
	buf[0] = 0;

	switch(cmd->msgCode)
	{
	case 0xa0:
/*
		sprintf(buf, "%s 查询状态---->", buf);
		SFndLenMsg(cmd->msg, &len);
		idx = 0;
		while(len--)
		{
			SExamMsg(&key, cmd->msg, idx++);
			sprintf(buf, "%s %02x", buf, key); 
		}
*/
		RETVALUE(ROK);
	case 0xa1:
		sprintf(buf, "%s 读累计->", buf);
		SFndLenMsg(cmd->msg, &len);
		idx = 0;
		while(len--)
		{
			SExamMsg(&key, cmd->msg, idx++);
			sprintf(buf, "%s %02x", buf, key); 
		}
		break;
	case 0xa3:
		sprintf(buf, "%s 读卡序列->", buf);
		SFndLenMsg(cmd->msg, &len);
		idx = 0;
		while(len--)
		{
			SExamMsg(&key, cmd->msg, idx++);
			sprintf(buf, "%s %02x", buf, key); 
		}
		break;
	case 0xa5:
		sprintf(buf, "%s 读卡信息->", buf);
		SFndLenMsg(cmd->msg, &len);
		idx = 0;
		while(len--)
		{
			SExamMsg(&key, cmd->msg, idx++);
			sprintf(buf, "%s %02x", buf, key); 
		}
		break;

	case 0xB2:
		sprintf(buf, "%s 授权->", buf);
		SFndLenMsg(cmd->msg, &len);
		idx = 0;
		while(len--)
		{
			SExamMsg(&key, cmd->msg, idx++);
			sprintf(buf, "%s %02x", buf, key); 
		}
		break;

	case 0xB3:
		sprintf(buf, "%s 结束加油->", buf);
		SFndLenMsg(cmd->msg, &len);
		idx = 0;
		while(len--)
		{
			SExamMsg(&key, cmd->msg, idx++);
			sprintf(buf, "%s %02x", buf, key); 
		}
		break;
	case 0xB4:
		sprintf(buf, "%s 关班->", buf);
		SFndLenMsg(cmd->msg, &len);
		idx = 0;
		while(len--)
		{
			SExamMsg(&key, cmd->msg, idx++);
			sprintf(buf, "%s %02x", buf, key); 
		}
		break;
	case 0xB5:
		sprintf(buf, "%s 结束全部->", buf);
		SFndLenMsg(cmd->msg, &len);
		idx = 0;
		while(len--)
		{
			SExamMsg(&key, cmd->msg, idx++);
			sprintf(buf, "%s %02x", buf, key); 
		}
		break;
	case 0xB6:
		sprintf(buf, "%s 暂停->", buf);
		SFndLenMsg(cmd->msg, &len);
		idx = 0;
		while(len--)
		{
			SExamMsg(&key, cmd->msg, idx++);
			sprintf(buf, "%s %02x", buf, key); 
		}
		break;
	case 0xB7:
		sprintf(buf, "%s 恢复->", buf);
		SFndLenMsg(cmd->msg, &len);
		idx = 0;
		while(len--)
		{
			SExamMsg(&key, cmd->msg, idx++);
			sprintf(buf, "%s %02x", buf, key); 
		}
		break;
	case 0xC0:
		sprintf(buf, "%s 读单价->", buf);
		SFndLenMsg(cmd->msg, &len);
		idx = 0;
		while(len--)
		{
			SExamMsg(&key, cmd->msg, idx++);
			sprintf(buf, "%s %02x", buf, key); 
		}
		break;
	case 0xC1:
		sprintf(buf, "%s 写单价->", buf);
		SFndLenMsg(cmd->msg, &len);
		idx = 0;
		while(len--)
		{
			SExamMsg(&key, cmd->msg, idx++);
			sprintf(buf, "%s %02x", buf, key); 
		}
		break;
	case 0xC4:
		sprintf(buf, "%s 读油品->", buf);
		SFndLenMsg(cmd->msg, &len);
		idx = 0;
		while(len--)
		{
			SExamMsg(&key, cmd->msg, idx++);
			sprintf(buf, "%s %02x", buf, key); 
		}
		break;
	case 0xC5:
		sprintf(buf, "%s 下发油品->", buf);
		SFndLenMsg(cmd->msg, &len);
		idx = 0;
		while(len--)
		{
			SExamMsg(&key, cmd->msg, idx++);
			sprintf(buf, "%s %02x", buf, key); 
		}
		break;
	case 0xD0:
		sprintf(buf, "%s 执行情况->", buf);
		SFndLenMsg(cmd->msg, &len);
		idx = 0;
		while(len--)
		{
			SExamMsg(&key, cmd->msg, idx++);
			sprintf(buf, "%s %02x", buf, key); 
		}
		break;
	case 0xD1:
		sprintf(buf, "%s 写配置->", buf);
		SFndLenMsg(cmd->msg, &len);
		idx = 0;
		while(len--)
		{
			SExamMsg(&key, cmd->msg, idx++);
			sprintf(buf, "%s %02x", buf, key); 
		}
		break;
	case 0xD2:
//		sprintf(buf, "%s 下发黑名单->", buf);
		RETVALUE(ROK);

	case 0xD3:
		sprintf(buf, "%s 下灰记录->", buf);
		SFndLenMsg(cmd->msg, &len);
		idx = 0;
		while(len--)
		{
			SExamMsg(&key, cmd->msg, idx++);
			sprintf(buf, "%s %02x", buf, key); 
		}
		break;
	case 0xD4:
		sprintf(buf, "%s 下定点名单->", buf);
		SFndLenMsg(cmd->msg, &len);
		idx = 0;
		while(len--)
		{
			SExamMsg(&key, cmd->msg, idx++);
			sprintf(buf, "%s %02x", buf, key); 
		}
		break;
	case 0xD5:
		sprintf(buf, "%s 解灰->", buf);
		SFndLenMsg(cmd->msg, &len);
		idx = 0;
		while(len--)
		{
			SExamMsg(&key, cmd->msg, idx++);
			sprintf(buf, "%s %02x", buf, key); 
		}
		break;
	case 0xD6:
		sprintf(buf, "%s 上传记录->", buf);
		SFndLenMsg(cmd->msg, &len);
		idx = 0;
		while(len--)
		{
			SExamMsg(&key, cmd->msg, idx++);
			sprintf(buf, "%s %02x", buf, key); 
		}
		break;
	case 0xD7:
		sprintf(buf, "%s 上传灰记录->", buf);
		SFndLenMsg(cmd->msg, &len);
		idx = 0;
		while(len--)
		{
			SExamMsg(&key, cmd->msg, idx++);
			sprintf(buf, "%s %02x", buf, key); 
		}
		break;
	case 0xD8:
		sprintf(buf, "%s 校准时间->", buf);
		SFndLenMsg(cmd->msg, &len);
		idx = 0;
		while(len--)
		{
			SExamMsg(&key, cmd->msg, idx++);
			sprintf(buf, "%s %02x", buf, key); 
		}
		break;
	case 0xDA:
		sprintf(buf, "%s 取历史记录->", buf);
		SFndLenMsg(cmd->msg, &len);
		idx = 0;
		while(len--)
		{
			SExamMsg(&key, cmd->msg, idx++);
			sprintf(buf, "%s %02x", buf, key); 
		}
		break;
	case 0xe0:
//		sprintf(buf, "%s REPEAT->", buf);
		SFndLenMsg(cmd->msg, &len);
		idx = 0;
		while(len--)
		{
			SExamMsg(&key, cmd->msg, idx++);
			sprintf(buf, "%s %02x", buf, key); 
		}
		break;
	}
	sprintf(buf, "%s\n", buf);

	LBLOG(buf, 0, 0);

	RETVALUE(ROK);
}

S16 LBLOG(Txt * s, Data * data, MsgLen len) 
{
	U8 buf[1024];
	U32 i;
	DateTime t;

	SGetDateTime(&t);
	sprintf(buf, "%02d:%02d:%02d", t.hour, t.min, t.sec);

	sprintf(buf, "%s %s ",buf, s);
	for(i = 0 ; i < len; i++)
	{
		sprintf(buf, "%s %02x", buf, *data++);
	}
	sprintf(buf, "%s\n", buf);
	lbWriteLog(buf);
	RETVALUE(ROK);
}



/******************* modify histroy list *******************
001. create at: 2002-7-1 22:26:27 by Shangyaohui

****************** modify histroy list end ****************/



⌨️ 快捷键说明

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