抱歉,您的浏览器无法访问本站
本页面需要浏览器支持(启用)JavaScript
了解详情 >

靖待的技术博客

小清新IT旅程 | 为中华之崛起而读书

配图

大三认真学技术打开新世界,常叹为何不早入技术门!
I have learned technology to my best in my junior time,and I feel I should step into the technological world earlier!

奈何大三事务多,惟愿考研考上给我又几年自学的机会……更认真地对待技术! Too busy in the junior,may I can gain another several years to learn in the postgraduate stage.I will be more hard-working! 这一年,接触git、css、html,前端知识,尝试java,这学期又选了数据库sql,嵌入式系统Linux,还学了好用的工具Labview,这学期选的课都很实用!只是知识需要消化……

This year,I get to know git,css,html and fore-end knowledge,try java,and chose sql,linux and labview this semester,which are practical nowadays!Indeed,it takes time to understand them deeply.
一直想了解Linux,无从下手,最后还是在课堂上被老师带着走入了linux的世界。
Always want to know something about linux,but I just have no idea about it.Luckliy,I become to see you finally,linux.

2016.6.22更新 Update 一要点

昨天考完了嵌入式系统实验考试,get一个简单的要点:
I got a small but esstenial point in my linux exam,
armv4l-unknown-linux-gcc -o 开发板上的编译 winSCP’s compiler
gcc -o 虚拟机上的编译 VM’s compiler
分清两种编译器。Please make sure your compiler is right.
考试内容是开发板与虚拟机通信。开发板是client,虚拟机是server.(和之前的记录是相反的)
My exam is VM communicate with winSCP.The winCSP is client,and the VM is server.

2016.6.14更新 Update 基础实验 熟悉Linux开发环境 Basic experiment Be familiar with Linux development environment

熟悉Linux开发环境,学会基于S3C2410的Linux开发环境的配置和使用。使用Linux的armv4l-unknown-linux-gcc编译,使用基于NFS方式的下载调试,了解嵌入式开发的基本过程。
Be familiar with Linux development environment and learn configuration of Linux development environment based on S3C2410.Use compile of armv41-unknown-linux-gcc,use download and debug based on NFS mode,to learn the embedded development process.

实验步骤 Experiment steps

1、建立工作目录 Create work directory
2、编写程序源代码 Write code
3、编写Makefile Write makefile
4、编译应用程序 Compile program
5、下载调试 Download and debug

重难点 Important point

Makefile文件定义了一系列的规则,它指明了哪些文件需要编译,哪些文件需要先编译,哪些文件需要重新编译等等更为复杂的命令。使用它带来的好处就是自动编译,你只需要敲一个“make”命令整个工程就可以实现自动编译。
Makefile definite a series of rules,and it shows which files need compile,which first to be compiled,and which need recompile.The benefit is a simple “make” can finish automatic compilation.

mount -t nfs -o nolock 192.168.0.56:/arm2410cl /host //超级终端中执行 carried out under the super terminal
注意:IP地址需要根据宿主PC机的实际情况修改成对应arm2410cl目录。
Attention:IP should be changed according to the real condition.

编译、修改程序都是在宿主机(本地PC机)上进行,不能在超级终端下进行。
Compile and modify the program both in the host (local PC), and it can not be carried out under the super terminal.

课堂笔记备忘

服务器与客户端通信

虚拟机上(地址192.168.1.12)VM:
cd /arm2410cl/
cd exp
cd basic
cd server(先把server.c和client.c拷入对应文件夹下 into right files)
ls
gcc -o client client.c //编译compile
armv41-unkown-linux-gcc -o server server.c //编译compile
注意:修改了源文件记得要编译,保存还不够。
Attention:It is vital to compile,not just save file.

./client
123456

开发板(地址192.168.1.121)winSCP:
ifconfig eth0 192.168.1.121
mount -t nfs -o nolock 192.168.1.12:/arm2410c1 /host (挂载mount)
cd /host
cd exp
cd basic
cd server
ls
(可以ping 192.168.1.12检查一下是否连通 test if it is linked.)
./server
123456

exit退出连接

程序只能是客户端向服务端发送信息,不能反过来。
Information can only be sent to the server from client which can’t be reversed because of the program setting.

原程序Original program:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
int main()
{
char buffer[BUFFER_SIZE];
struct sockaddr_in client_addr;
socklen_t length;
int conn;
int len;
//int fork_id;
///定义sockfd
int server_sockfd = socket(AF_INET,SOCK_STREAM, 0);

///定义sockaddr_in
struct sockaddr_in server_sockaddr;
server_sockaddr.sin_family = AF_INET;
server_sockaddr.sin_port = htons(MYPORT);
server_sockaddr.sin_addr.s_addr = htonl(INADDR_ANY);

///bind,成功返回0,出错返回-1
if(bind(server_sockfd,(struct sockaddr *)&server_sockaddr,sizeof(server_sockaddr))==-1)
{
perror("bind");
exit(1);
}

///listen,成功返回0,出错返回-1
if(listen(server_sockfd,QUEUE) == -1)
{
perror("listen");
exit(1);
}

///客户端套接字

length = sizeof(client_addr);

///成功返回非负描述字,出错返回-1
//while(1)
//{
conn = accept(server_sockfd, (struct sockaddr*)&client_addr, &length);
if(conn<0)
{
perror("connect");
exit(1);
}
fork_id=fork();
if(fork_id==0)
{
while(1)
{
memset(buffer,0,sizeof(buffer));
len = recv(conn, buffer, sizeof(buffer),0);
if(strcmp(buffer,"exit\n")==0)
break;
fputs(buffer, stdout);
send(conn, buffer, len, 0);
}
close(conn);
close(server_sockfd);
return(0);//新程序去掉了这一行
//exit(0);
}
/*else
{

}
}*/
}

原程序是一个服务器只能挂载一个客户端。 The original program is a server which can only mount one client.
程序修改了下,使一个服务器可以挂载两个客户端(可以构建聊天系统)。 After modifing program,it can mount two clients(which can create a chat system).
要先连接服务器,再连接客户端。 Connect the server first,then connect the client.

rm server 删除server文件 delete server file
两端ps -a看一下是否退出。 use"ps -a" to see if the system exits.

挂载驱动 Mount the drive

在开发板上winSCP:
mount -t nfs -o nolock 192.168.1.12:/arm2410cl /host
cd host
cd exp
cd basic
cd pwm_motor
lsmod pwm_ad.o
cd pwm_AD
insmod pwm_ad.o
//rmmod pwm_ad.o 删除
cd pwm_test
./test_dcm_main

虚拟机上VM:
cd pwm_motor
cd pwm_test
make clean
make
cd …
cd pwm_test

附录 客户端和服务器程序 Appendix Client.c & Server.c

server.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/shm.h>

#define MYPORT 8887
#define QUEUE 20
#define BUFFER_SIZE 1024

int main()
{
char buffer[BUFFER_SIZE];
struct sockaddr_in client_addr;
socklen_t length;
int conn;
int len;
///定义sockfd
int server_sockfd = socket(AF_INET,SOCK_STREAM, 0);

///定义sockaddr_in
struct sockaddr_in server_sockaddr;
server_sockaddr.sin_family = AF_INET;
server_sockaddr.sin_port = htons(MYPORT);
server_sockaddr.sin_addr.s_addr = htonl(INADDR_ANY);

///bind,成功返回0,出错返回-1
if(bind(server_sockfd,(struct sockaddr *)&server_sockaddr,sizeof(server_sockaddr))==-1)
{
perror("bind");
exit(1);
}

///listen,成功返回0,出错返回-1
if(listen(server_sockfd,QUEUE) == -1)
{
perror("listen");
exit(1);
}

///客户端套接字

length = sizeof(client_addr);

///成功返回非负描述字,出错返回-1
conn = accept(server_sockfd, (struct sockaddr*)&client_addr, &length);
if(conn<0)
{
perror("connect");
exit(1);
}

while(1)
{
memset(buffer,0,sizeof(buffer));
len = recv(conn, buffer, sizeof(buffer),0);
if(strcmp(buffer,"exit\n")==0)
break;
fputs(buffer, stdout);
send(conn, buffer, len, 0);
}
close(conn);
close(server_sockfd);
return 0;
}

client.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
 #include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/shm.h>

#define MYPORT 8887
#define BUFFER_SIZE 1024

int main()
{
///定义sockfd
int sock_cli = socket(AF_INET,SOCK_STREAM, 0);

///定义sockaddr_in
struct sockaddr_in servaddr;
memset(&servaddr, 0, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(MYPORT); ///服务器端口
servaddr.sin_addr.s_addr = inet_addr("192.168.1.12"); ///服务器ip

///连接服务器,成功返回0,错误返回-1
if (connect(sock_cli, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0)
{
perror("connect");
exit(1);
}

char sendbuf[BUFFER_SIZE];
char recvbuf[BUFFER_SIZE];
while (fgets(sendbuf, sizeof(sendbuf), stdin) != NULL)
{
send(sock_cli, sendbuf, strlen(sendbuf),0); ///发送
if(strcmp(sendbuf,"exit\n")==0)
break;
recv(sock_cli, recvbuf, sizeof(recvbuf),0); ///接收
fputs(recvbuf, stdout);

memset(sendbuf, 0, sizeof(sendbuf));
memset(recvbuf, 0, sizeof(recvbuf));
}

close(sock_cli);
return 0;
}

评论