boardYP.c
2 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#define Port 23
int Sockfd;
typedef struct {
char filename[256];
char result_filename[256];
char sender[30];
char pwd[256];
int pass;
} Info;
void Receivedone()
{
close(Sockfd);
printf("\n Program done\n");
exit(0);
}
main(int argc, char* argv[])
{
int newSockfd, hostAddrLen, n;
struct sockaddr_in hostAddr, boardAddr;
Info info;
signal(SIGINT, Receivedone); // 종료 signal
if((Sockfd = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
perror("socket");
exit(1);
}
bzero((char*)&boardAddr, sizeof(boardAddr));
boardAddr.sin_family = PF_INET;
boardAddr.sin_addr.s_addr = htonl(INADDR_ANY);
boardAddr.sin_port = htons(Port);
if(bind(Sockfd, (struct sockaddr*)&boardAddr, sizeof(boardAddr)) < 0) {
perror("bind");
exit(1);
}
listen(Sockfd, 5);
printf("\nReceive waiting\n\n");
hostAddrLen = sizeof(hostAddr);
while(1) {
info.pass = 0;
char path[256] = "~/Vitis-AI/vitis_ai_library/samples/yolov3/test_jpeg_yolov3 yolov3_bdd ";
char scp[256] = "scp ";
newSockfd = accept(Sockfd, (struct sockaddr*)&hostAddr, &hostAddrLen);
if(newSockfd < 0) {
perror("accept");
exit(1);
}
if((n = read(newSockfd, (char*)&info, sizeof(info))) < 0) {
perror("read");
exit(1);
}
printf("Start yolo : %s\n", info.filename);
strcat(path, info.filename);
if(system(path)) { // yolo 실행
perror("system");
exit(1);
}
// scp 명령어 만들기
strcat(scp, info.result_filename);
strcat(scp, " ");
strcat(scp, info.sender);
strcat(scp, ":");
strcat(scp, info.pwd);
printf("%s\n", scp);
if(system(scp)) { // scp 명령어 실행
perror("system");
exit(1);
}
info.pass = 1;
if(write(newSockfd, (char*)&info, sizeof(info)) < 0) {
perror("write");
exit(1);
}
printf("\nSuccess\n=========================================================\n\n");
close(newSockfd);
}
}