char RecivePcBuf[30];
char Filename[30];
char temp_data[30];
int i;
unsigned short usBytesRead;
char g_cTmpBuf[30];
//int flag_Cmd;
char SendPc[100];
FRESULT fresult;
unsigned char FROK;
char *temp;
//File_Name[0]='\0';
temp_data[0]=0;
RecivePcBuf[0]=0;
g_cTmpBuf[0]=0;
strcpy(RecivePcBuf,p);
//RecivePcBuf=p;
RecivePcBuf[len]='\0';
if ((RecivePcBuf[0]=='l')&&(RecivePcBuf[1]=='s'))
{
//FROK=tcp_write(pcb,"su",strlen("su"),0);
SendPc[0]=0;
fresult = f_opendir(&g_sDirObject, g_cCwdBuf);
//
// Check for error and return if there is a problem.
//
if(fresult != FR_OK)
{
UARTprintf("openirfail!");
return(fresult);
}
for(;;)
{
//
// Read an entry from the directory.
//
fresult = f_readdir(&g_sDirObject, &g_sFileInfo);
//
// Check for error and return if there is a problem.
//
if(fresult != FR_OK)
{
UARTprintf("readdirfail!");
return(fresult);
}
//
// If the file name is blank, then this is the end of the
// listing.
//
if(!g_sFileInfo.fname[0])
{
UARTprintf("blankname!");
break;
}
//
// If the attribue is directory, then increment the directory count.
//
if(g_sFileInfo.fattrib & AM_DIR)
{
strcat(SendPc,"D---- ");
}
else
{
if (g_sFileInfo.fattrib & AM_ARC)
{
strcat(SendPc,"----A ");
}
}
strcat(SendPc,g_sFileInfo.fname);
strcat(SendPc,"\0");
}
strcat(SendPc,"\0");
UARTprintf(SendPc);
FROK=tcp_write(pcb,SendPc,strlen(SendPc),0);
if (FROK!=ERR_OK)
{
UARTprintf("lstcpfail");
return 0;
}
FROK=tcp_output(pcb);
if (FROK!=ERR_OK)
{
return 0;
}
}
这个串口输出UARTprintf(SendPc)正常,tcp_write()死活没反应啊,我以前可以的啊
tBoolean deal_rpcdata_new(char *p,int len,struct tcp_pcb *pcb)
{
char RecivePcBuf[1024];
char File_Name[30];
char temp_data[30];
char *i;
unsigned short usBytesRead;
char g_cTmpBuf[PATH_BUF_SIZE];
// int flag_Cmd;
char SendPc[100];
FRESULT fresult;
unsigned char FROK;
SendPc[0]='\0';
File_Name[0]='\0';
temp_data[0]='\0';
strncpy(RecivePcBuf,p,len);
RecivePcBuf[len]='\0';
// when the command is "ls" or "cd"
//
if ((RecivePcBuf[0]=='l')&&(RecivePcBuf[1]=='s'))
{
//tcp_write(pcb,RecivePcBuf,strlen(RecivePcBuf),0);
fresult = f_opendir(&g_sDirObject, g_cCwdBuf);
//
// Check for error and return if there is a problem.
//
if(fresult != FR_OK)
{
UARTprintf("openirfail!");
return(fresult);
}
for(;;)
{
//
// Read an entry from the directory.
//
fresult = f_readdir(&g_sDirObject, &g_sFileInfo);
//
// Check for error and return if there is a problem.
//
if(fresult != FR_OK)
{
UARTprintf("readdirfail!");
return(fresult);
}
//
// If the file name is blank, then this is the end of the
// listing.
//
if(!g_sFileInfo.fname[0])
{
UARTprintf("blankname!");
break;
}
//
// If the attribue is directory, then increment the directory count.
//
if(g_sFileInfo.fattrib & AM_DIR)
{
strcat(SendPc,"D---- ");
}
else
{
if (g_sFileInfo.fattrib & AM_ARC)
{
strcat(SendPc,"----A ");
}
}
strcat(SendPc,g_sFileInfo.fname);
strcat(SendPc,"\r\n");
}
FROK=tcp_write(pcb,SendPc,strlen(SendPc),0);
if (FROK!=ERR_OK)
{
UARTprintf("lstcpfail");
return 0;
}
FROK=tcp_output(pcb);
if (FROK!=ERR_OK)
{
return 0;
}
}
else
{
if((RecivePcBuf[0]=='c')&&(RecivePcBuf[1]=='a')&&(RecivePcBuf[2]=='t'))
{
// tcp_write(pcb,RecivePcBuf,strlen(RecivePcBuf),0);
File_Name[0]=0;
strncpy(File_Name,p+3,len-3);
File_Name[len-3]='\0';
g_cTmpBuf[0]='\0';
//
// Copy the current path to the temporary buffer so it can be manipulated.
//
// strcpy(g_cTmpBuf, g_cCwdBuf);
//
// If not already at the root level, then append a separator.
//
// if(strcmp("/", g_cCwdBuf))
// {
// strcat(g_cTmpBuf, "/");
// }
strcpy(g_cTmpBuf,"/");
// strcat(g_cTmpBuf,"/");
strcat(g_cTmpBuf, File_Name);
strcat(g_cTmpBuf, ".txt");
//
// Now finally, append the file name to result in a fully specified file.
//
//
// Open the file for reading.
//
fresult = f_open(&g_sFileObject, g_cTmpBuf, FA_READ);
//
// If there was some problem opening the file, then return
// an error.
//
if(fresult != FR_OK)
{
UARTprintf("fileopenfail!");
FROK=tcp_write(pcb,i,strlen(i),0);
if (FROK!=ERR_OK)
{
return 0;
}
FROK=tcp_output(pcb);
if (FROK!=ERR_OK)
{
return 0;
}
return(fresult);
}
//f_lseek(&g_sFileObject,0);
//
// Enter a loop to repeatedly read data from the file and display it,
// until the end of the file is reached.
//
do
{
// Read a block of data from the file. Read as much as can fit
// in the temporary buffer, including a space for the trailing null.
//
fresult = f_read(&g_sFileObject, temp_data,strlen(temp_data)-1,&usBytesRead);
//
// If there was an error reading, then print a newline and
// return the error to the user.
//
if(fresult != FR_OK)
{
UARTprintf("filereadfail");
FROK=tcp_write(pcb,"fail to read!\r\n",strlen("fail to read!\r\n"),0);
if (FROK!=ERR_OK)
{
return 0;
}
FROK=tcp_output(pcb);
if (FROK!=ERR_OK)
{
return 0;
}
return(fresult);
}
//
// Null terminate the last block that was read to make it a
// null terminated string that can be used with printf.
//
temp_data[usBytesRead] = 0;
//
FROK=tcp_write(pcb,temp_data,strlen(temp_data),0);
if (FROK!=ERR_OK)
{
UARTprintf("cattcpfail!");
return 0;
}
FROK=tcp_output(pcb);
if (FROK!=ERR_OK)
{
return 0;
}
// Continue reading until less than the full number of bytes are
// read. That means the end of the buffer was reached.
//
}
while(usBytesRead == strlen(g_cTmpBuf)-1);
f_close(&g_sFileObject);
}
else
{
UARTprintf("wrongcommand");
FROK=tcp_write(pcb,"wrong command!\r\n",strlen("wrong command!\r\n"),0);
if (FROK!=ERR_OK)
{
return 0;
}
FROK=tcp_output(pcb);
if (FROK!=ERR_OK)
{
return 0;
}
}
}
return (1);
}
static err_t tcp_Client_recv(void *arg, struct tcp_pcb *pcb,struct pbuf *p,err_t err){ //unsigned int len; char RecivePcBuf[1024]; strncpy(RecivePcBuf,p->payload,p->len); RecivePcBuf[p->len]='\0'; tcp_recved (pcb,p->len); if(p != NULL) {// tcp_write(pcb,p->payload,p->len,0); deal_rpcdata_new(RecivePcBuf,p->len,pcb); pbuf_free(p); /* 释放该TCP段 */ tcp_recved (pcb,p->len); } else { tcp_write(pcb,"empty command!\r\n",strlen("empty command!\r\n"),0); } // tcp_close(pcb); /* 关闭这个连接 */ err = ERR_OK; return err;}