|
发表于 2014-8-30 09:07:34
|
显示全部楼层
现在的问题是一直执行图片中的 case eYM_INIT 和 case eYM_RECE_HEAD_PACKET: 并通过if中的break 跳出循环。
if (IS_TIMEOUT_1MS(eTimYModem, NAK_TIMEOUT)) //若等待超时
{
YmodemSendChar(CRC16, &stat, &sErrorCount); //发送 'C'
Print("\r\n ");
stat = eYM_INIT;
break;
}
int YmodemReceive(char *pRece, int *sReceLen, char *pData, int *sResLen)
{
int cRes = YM_VOIDER;
static eYM_STAT stat= eYM_INIT; //当前状态
static char affirmCount = 0; //确认次数
static int iNumber = 0; //数据包编号
static int sErrorCount = 0; //错误包次数
s8 cTmp = 0;
switch (stat)
{
case eYM_INIT:
iNumber = 0;
sErrorCount = 0;
affirmCount = 0;
stat = eYM_RECE_HEAD_PACKET;
IS_TIMEOUT_1MS(eTimYModem, 0); //清超时计数器
Print("\r\n waite");
break;
case eYM_RECE_HEAD_PACKET: //这个地方需注意 NAK_TIMEOUT
//YmodemSendChar(CRC16, &stat, &sErrorCount); //发送 'C'
if (IS_TIMEOUT_1MS(eTimYModem, NAK_TIMEOUT)) //若等待超时
{
YmodemSendChar(CRC16, &stat, &sErrorCount); //发送 'C'
Print("\r\n ");
stat = eYM_INIT;
break;
}
if (*sReceLen == 0)
break;
cTmp = ReceivePacket(pRece, *sReceLen, pData, sResLen, iNumber & 0xFF);
Print("\r\n Incoming header files ");
*sReceLen = 0; //读完数据后,允许接收新数据
switch (cTmp)
{
case TRUE: //接收正确
//下行代码由pData[PACKET_HEADER] 改为pData[PACKET_HEADER-1]
if (pData[PACKET_HEADER] == 0) //无文件发送
{
stat = eYM_END;
Print("\r\n no file ");
}
else
{
stat = eYM_RECE_DATA_START; //有文件发送
cRes = YM_FILE_INFO; //返回接收头文件
Print("\r\n YES");
//////////////////////////////////////////////////////////////////
//while(!IS_TIMEOUT_1MS(eTimYModem, 100));
//////////////////////////////////////////////////////////////////
iNumber++;
affirmCount = 0;
// printf("\r\n 有文件发送,正准备发送数据");
}
break;
case 0: //接收到结束标志
if (affirmCount)
{
iNumber = 0;
//while(!IS_TIMEOUT_1MS(eTimYModem, 50));
YmodemSendChar(ACK, &stat, &sErrorCount); //正确应答
Print("\r\nThe end of the ACK ");
}
else
{
//while(!IS_TIMEOUT_1MS(eTimYModem, 50));
YmodemSendChar(NAK, &stat, &sErrorCount); //错误应答 二次确认
Print("\r\n NAK");
//while(!IS_TIMEOUT_1MS(eTimYModem, 50));
}
affirmCount++;
break;
default: //接收数据有误
affirmCount = 0;
YmodemSendChar(NAK, &stat, &sErrorCount); //错误应答
Print("\r\n NAK NAK");
break;
}
IS_TIMEOUT_1MS(eTimYModem, 0); //清超时计数器
break;
case eYM_RECE_DATA_START:
stat = eYM_RECE_DATA;
YmodemSendChar(ACK, &stat, &sErrorCount); //正确应答
YmodemSendChar(CRC16, &stat, &sErrorCount); //发送 'C'
Print("\r\n Begin to receive data");
break;
case eYM_RECE_DATA:
if (IS_TIMEOUT_1MS(eTimYModem, NAK_TIMEOUT)) //若等待超时
{
stat = eYM_END;
break;
}
if (*sReceLen == 0)
break;
cTmp = ReceivePacket(pRece, *sReceLen, pData, sResLen, iNumber & 0xFF);
*sReceLen = 0; //读完数据后,允许接收新数据
switch (cTmp)
{
case TRUE: //接收正确
cRes = YM_FILE_DATA; //返回接收数据正确
iNumber++; //
affirmCount = 0;
YmodemSendChar(ACK, &stat, &sErrorCount); //正确应答
Print("\r\n ACK");
break;
case 0: //接收到结束标志
if (affirmCount)
{
iNumber = 0;
stat = eYM_RECE_HEAD_PACKET;
while(!IS_TIMEOUT_1MS(eTimYModem, 50));
YmodemSendChar(ACK, &stat, &sErrorCount); //正确应答
Print("\r\nThe end of the ACK NUM ");
}
else
{
while(!IS_TIMEOUT_1MS(eTimYModem, 50));
YmodemSendChar(NAK, &stat, &sErrorCount); //错误应答
Print("\r\nThe end of the NAK ");
}
affirmCount++;
break;
default: //接收数据有误
affirmCount = 0;
YmodemSendChar(NAK, &stat, &sErrorCount); //错误应答
break;
}
IS_TIMEOUT_1MS(eTimYModem, 0); //清超时计数器
break;
case eYM_END:
YmodemSendChar(ACK, &stat, &sErrorCount); //中止
Print("\r\n suspend ACK");
YmodemSendChar(CA, &stat, &sErrorCount); //中止
Print("\r\n suspend ACK");
YmodemSendChar(CA, &stat, &sErrorCount); //中止
Print("\r\n suspend ACK");
cRes = YM_EXIT;
stat = eYM_INIT;
break;
}
return cRes;
}
|
|