mifarea卡程序mifarea卡程序mifarea卡程序
源代码在线查看: command.c.bak
/****************************************
* command.c *
* Designe by 刘俐训 *
* check and excute command from host *
* last update: 05-01-2007 *
****************************************/
#include "includes.h"
#include "MifarePro.h"
void Command(void)
{
unsigned int len = 0; // 通讯报文长度
unsigned char buf[316]; // 通讯、操作用临时数据缓冲
int limit;
if((len = CommRead(buf, sizeof(buf)-1)) > 0)
{
limit = ParaRead(PARA_LIMIT);
if(limit < 0)
limit = ParaWrite(PARA_LIMIT, 1);
if((limit {
buf[0] = ERRORCMD;
buf[1] = 0xaa;
len = 2;
}
else
{
switch(buf[0]) // buf[0]: cmd target
{
case SEC:
len = SecCommand(buf, len);
break;
case IC_M1:
len = M1Command(buf, len);
break;
case IC_MPRO:
len = MifareProExcute(buf,len);
break;
case IC_SAM1:
case IC_SAM2:
case IC_SAM3:
case IC_USER:
len = TcCommand(buf, len);
break;
case MCU:
len = SysCommand(buf, len);
break;
default:
break;
}
}
if(len > 0)
CommSend(buf, len);
}
}
#if 0
void Connect(unsigned int time)
{
unsigned int starttime;
unsigned char ch;
int i;
unsigned char tar;
bit freading = 0;
starttime = GetTickCount();
while(GetTickCount() - starttime < time)
{
// check serial port
if(ComIBufBytesTell() > 0)
{
// restart timer
starttime = GetTickCount();
// read
ComRead(&ch, 1);
// if ch is a command, do it
// else write ch to tar
}
//if(freading && // ch = read from tar > 0) //这里有一处疑问?
{
}
}
}
#endif