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

📄 main.c

📁 这是一个语音源代码
💻 C
字号:
#include <string.h>
#include <stdio.h>

#include "Target\44blib.h"
#include "Target\44b.h"
#include "iisdmatest\iis.h"




void * function[][2]=
{
		(void *)Record_Iis,		"Test Recording and  Playing  ",
	0,0
};                                                               //这个函数做什么?

void Isr_Init(void)
{
	rINTCON=0x5;	      //Non-vectored,IRQ enable,FIQ disable //
	rINTMOD=0x0;	      //All=IRQ mode//
	//rINTMSK=~(BIT_EINT0 | BIT_GLOBAL);	//开(不屏蔽)0中断源
}
void Main(void)
{
	char aa;
	int i;
	int sock_fd,new_fd;                  /*sock_fd,new_fd是套接字描述*/
  char filename[20];                    /*存放要传送文件的文件名*/
  struct sockaddr_in my_addr;           /*服务器的地址结构体*/
  struct sockaddr_in their_addr;        /*主机的地址结构体*/
  int sin_size;
  FILE *fp;
  char szsendbuf[1024],head[8];          /*发送数据缓冲区大小为1K*/
  int nsize, allsize=0;;
  int *phead=head+4;

	Port_Init();
	Uart_Init(0,115200);
  Isr_Init();
	Led_Display(0xf);
	Delay(0);
	Beep(0x1);
	Uart_Select(0); //Select UART0//
	Uart_Printf("\n*************************************************************************");
	Beep(0x0);
	Uart_Printf("\n*                     -S3C44B0X+uda1341音频实验-                     *");
	Uart_Printf("\n*                          Version 1.01                                 *");    
	Uart_Printf("\n*                    By:Morningsword@sohu.com                      *");
	Uart_Printf("\n*             UART Config--COM:115.2kbps,8Bit,NP,UART0                  *");
	Uart_Printf("\n*------------------Begin to Start Record&Play test,OK? (Y/N)--------------------*");
	Led_Display(0x0);
	aa= Uart_Getch();     //等待并从串口中得到一个字符
	if((aa=='Y')||(aa=='y'))
	while(1)
	{
			i=0;
			Uart_Printf("\n");
			while(1)
			{   //display menu
				Uart_Printf("%2d:%s",i+1,function[i][1]);
				i++;
				if((int)(function[i][0])==0)
				{
					Uart_Printf("\n");
					break;
				}
				if((i%4)==0)
					Uart_Printf("\n");
			}
			Uart_Printf("\nSelect the function to test?");
			i=Uart_GetIntNum();
			i=i-1;
			Uart_Printf("\n");
			if(i>=0 && (i<(sizeof(function)/8)) )   //sizeof是求字节数运算符
				( (void (*)(void)) (function[i][0]) )();
				/*create socket*/
				if((sock_fd=socket(AF_INET,SOCK_STREAM,0))= = ?1)    /*建立流式套接字描述符*/
					{	perror("socket");
						exit(1);
						}
/*服务器结构体的地址赋初值*/
my_addr.sin_family=AF_INET;  
my_addr.sin_port=htons(MYPORT);              /*服务器的端口号3000*/
my_addr.sin_addr.s_addr=INADDR_ANY;
bzero(&(my_addr.sin_zero),8);                   /*填充0,凑齐长度*/

if(bind(sock_fd,(struct sockaddr*)&my_addr,sizeof(struct sockaddr))= = ?1)  /*绑定*/
{	perror("bindB");                          /*绑定失败*/
exit(1);
}
if(listen(sock_fd,BACKLOG)= = ?1)             /*监听端口是否有请求*/
{	perror("listen");                          /*监听失败*/
exit(1);
}

while(1)
{  sin_size=sizeof(struct sockaddr_in);
   if ((new_fd=accept(sock_fd,(struct sockaddr *)&their_addr,&sin_size))== ?1)
   {		perror("accept");
    		continue;
    }
  	printf("server:got connection from %s\n",inet_ntoa(their_addr.sin_addr));
read(new_fd,filename,20);                /*从端口读文件名*/
printf("%s\n",filename);

if((fp=fopen(filename,"r"))==NULL)      /*打开文件*/
  	{	printf("Can't find the file");
     	exit(1) ;
  	}
nsize=1024;
allsize=0;
/*每次从文件读取1024个字节发送出去,若读出少于1024个字节,则认为已到达文件末尾*/
while(nsize = = 1024)  
{		bzero(szsendbuf,1024);                 /*清空缓冲区*/
	/*从文件中读取并发送到缓冲区,填写通信头的数据长度*/
nsize = *phead = fread(szsendbuf,1,1024,fp);
	write(new_fd,head,8);                 /*发送协议头*/
	nsize =write(new_fd,szsendbuf,nsize);    /*发送数据*/
	allsize+=nsize;                       /*统计发送字节数*/
if(allsize)	                           /*每发送一次,打印当前发送信息*/
    printf("now size:%d  this time %d  times:%d\n",allsize,nsize,allsize/1024);
	if(nsize <= 0)                        /*若发送完毕,退出*/
{    printf("Can't send data!\n");
     return 0;
}
}
close(new_fd);
fclose(fp);
}
close(sock_fd);
return 0;


	}
	
}

⌨️ 快捷键说明

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