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

📄 haltcl.c

📁 一个免费的SMART CARD OS系统。
💻 C
字号:
/* ============================================================================   Project Name : jayaCard   Module Name  : proto/hal/simu/haltcl.c   Version : $Id: haltcl.c,v 1.32 2004/04/23 21:33:44 dgil Exp $	Description: T=CL send/receive blocks    The Original Code is jayaCard code.    The Initial Developer of the Original Code is Gilles Dumortier.    Portions created by the Initial Developer are Copyright (C) 2002-2004 the    Initial Developer. All Rights Reserved.    Contributor(s):    This program is free software; you can redistribute it and/or modify    it under the terms of the GNU General Public License as published by    the Free Software Foundation; either version 2 of the License, or    (at your option) any later version.    This program is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    GNU General Public License for more details.    You should have received a copy of the GNU General Public License    along with this program; see http://www.gnu.org/licenses/gpl.html   History Rev	Description   020203 dgil	wrote it from scratch   ============================================================================*/#include "precomp.h"/* =========================================================================	TCL Buffers   ========================================================================= */jbyte	input_tcl[255];jbyte	Iinput_tcl;jbyte	output_tcl[255];jbyte	Ioutput_tcl;#ifdef JAYACFG_CONTACTLESS_BAUDRATE/* =========================================================================	__hal_tcl_setbaudrate()   ========================================================================= */void __hal_tcl_setbaudrate(jbyte baudrate){	/* update the global (NOP) */	tcl_baudrate = baudrate;	simu_baudrate_to_card = baudrate;	simu_baudrate_from_card = baudrate;	LOG1("HAL","__hal_tcl_setbaudrate(0x%.2X)",baudrate);}#endif/* =========================================================================	__hal_tcl_sendinit()   ========================================================================= */void __hal_tcl_sendinit(jbyte by){	// init the CRC	HAL_TCL_INIT_CRC();	// calculate CRC of byte	HAL_TCL_CRC(by);	// prepare to send SYNC	Ioutput_tcl = 0;	// send byte	output_tcl[Ioutput_tcl++] = by;}/* =========================================================================	__hal_tcl_send()	send just a byte   ========================================================================= */void __hal_tcl_send(jbyte by){	// send byte	output_tcl[Ioutput_tcl++] = by;	// calculate CRC of byte	HAL_TCL_CRC(by);}/* =========================================================================	__hal_tcl_sendbuf()	send a buffer of bytes   ========================================================================= */void __hal_tcl_sendbuf(jbyte xdata * buf, jbyte n){	// ToBeImplemented more efficient	LOCAL(jbyte,i);	for (i=0; i<n; i++) __hal_tcl_send(buf[i]);}/* =========================================================================	__hal_tcl_sendgo()   ========================================================================= */void __hal_tcl_sendgo(jbool bWaitSent){	PSIMUMSG	msg;	jresult		res;	// send CRC	output_tcl[Ioutput_tcl++] = HAL_TCL_LOCRC();	output_tcl[Ioutput_tcl++] = HAL_TCL_HICRC();	// send the simumsg	msg = new_simumsg(SIMUMSG_TCL_FRAME,Ioutput_tcl);	if (msg==NULL) {		fprintf(stderr,"__hal_tcl_sendgo(%0d) - can't create simumsg !\n",bWaitSent);		throw THROW_RECONNECT;	}	/* PHIL: XXX check the baudrate stuff */	#ifdef JAYACFG_CONTACTLESS_BAUDRATE	msg->h.param |= (simu_baudrate_from_card << (6+8));	#endif	memcpy(msg->buf,output_tcl,Ioutput_tcl);	res = send_simumsg(socketCard,msg);	if (res!=JY_OK) {		fprintf(stderr,"__hal_tcl_sendgo(%0d) - can't send simumsg !\n",bWaitSent);		throw THROW_RECONNECT;	}	free_simumsg(msg);	if (bWaitSent) HAL_WAIT();}/* =========================================================================	__hal_tcl_receive()   ========================================================================= */jbyte __hal_tcl_receive(jbyte xdata * buf,jbyte n,jbool isRaw){	PSIMUMSG	msg;	jbyte		d;	jresult		res;loop:	res = receive_simumsg(socketCard,&msg);	if (res!=JY_OK) {		fprintf(stderr,"__hal_tcl_receive() - can't receive simumsg !\n");		throw THROW_RECONNECT;	}	if (msg->h.kindof != SIMUMSG_TCL_FRAME) {		__simu_dispatch(msg);		goto loop;	}	/* PHIL: XXX check the baudrate stuff */	#ifdef JAYACFG_CONTACTLESS_BAUDRATE	if ((SIMUMSG_TCL_FRAME_BAUDRATE(msg->h.param) >> (6+8)) != simu_baudrate_to_card) {		LOG2("Simu","expected baudrate = %d  received baudrate = %d !",simu_baudrate_to_card, (SIMUMSG_TCL_FRAME_BAUDRATE(msg->h.param) >> (6+8)));		goto loop;	}	#endif	Iinput_tcl = 0;	memcpy(input_tcl,msg->buf,SIMUMSG_TCL_FRAME_LEN(msg->h.param));	HAL_WAIT();	// --- get number bytes of the received buffer	tcl_cnt = SIMUMSG_TCL_FRAME_LEN(msg->h.param);	free_simumsg(msg);	// check the message size. Too short or too big ?	if (tcl_cnt<3) {		LOG("TCL",".tooshort.");		return 0;	}	if (tcl_cnt>n) {		LOG2("TCL","__hal_tcl_receive - buffer (len=%d) too small for TCL_FRAME (len=%d)", n, tcl_cnt );		return 0;	}	// --- initialisation of CRC module for	HAL_TCL_INIT_CRC();	if (!isRaw) {		/* receive PCB */		tcl_pcb = input_tcl[Iinput_tcl++];		HAL_TCL_CRC(tcl_pcb);		tcl_cnt--;		/* receive CID ? */		if ((tcl_pcb&TCL_MASK_CID)==TCL_MASK_CID) {			tcl_cid = input_tcl[Iinput_tcl++];			HAL_TCL_CRC(tcl_cid);			tcl_cnt--;		}		/* receive NAD ? */		if ((tcl_pcb&TCL_MASK_NAD)==TCL_MASK_NAD) {			tcl_nad = input_tcl[Iinput_tcl++];			HAL_TCL_CRC(tcl_nad);			tcl_cnt--;		}	}	if (tcl_cnt<2) {		LOG1("TCL",".errlen. %d<2",tcl_cnt);		return 0;	}	// --- calculate and store each received byte	for (n=0; n<tcl_cnt-2; n++) {		/* read FIFO */		d = input_tcl[Iinput_tcl++];		/* calculate CRC */		HAL_TCL_CRC(d);		/* store in buffer */		buf[n] = d;	}	// check the CRC	if (input_tcl[Iinput_tcl++] != HAL_TCL_LOCRC()) {		LOG("TCL",".errcrclo.");		return 0;	}	if (input_tcl[Iinput_tcl++] != HAL_TCL_HICRC()) {		LOG("TCL",".errcrchi.");		return 0;	}	return tcl_cnt;}/* =========================================================================	That's all folks !   ========================================================================= */

⌨️ 快捷键说明

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