-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
86 lines (64 loc) · 1.81 KB
/
main.c
File metadata and controls
86 lines (64 loc) · 1.81 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
#include "byteStuffing.h"
#include "app.h"
int main(int argc, char** argv)
{
int opcao;
int port = 0;
int tamanho = 1024;
if(atoi(argv[1]) == 0)
if(argc < 3)
{
printf("Too few arguments! Usage: msg << 1, 0 >> << file_path >> \nPress Enter to exit...");
getchar();
exit(1);
}
do{
printf("0 - ");
if(atoi(argv[1])== 0) printf("Enviar ");
else if(atoi(argv[1]) == 1) printf("Receber ");
printf("ficheiro (default: pinguim.gif)\n");
printf("1 - Definir baudrate (default:B38400) \n");
printf("2 - Definir timeout (default: 3)\n");
printf("3 - Definir numero de tentativas de retransmissao (default: 3)\n");
printf("4 - Definir porta (default: 0)\n");
if(atoi(argv[1]) == 0)
printf("5 - Definir tamanho de trama (default: 1024)\n");
scanf("%d", &opcao);
switch(opcao)
{
case 1:
printf("\nBAUDRATE: ");
scanf("%d", &baud);
break;
case 2:
printf("\nTIMEOUT (s): ");
scanf("%d", &timeout);
break;
case 3:
printf("\nNUMERO DE TENTATIVAS: ");
scanf("%d", &tries);
break;
case 4:
printf("\nPORTA (0,1,2...): ");
scanf("%d", &port);
break;
case 5:
if(atoi(argv[1]) == 0)
{
printf("\nTAMANHO: ");
scanf("%d", &tamanho);
}
break;
}
}while(opcao != 0);
llopen(port,atoi(argv[1]));
if ((atoi(argv[1])) == 0) appSender(argv[2], tamanho);
if ((atoi(argv[1])) == 1) appReceiver();
printf("\nTERMINATING COMMUNICATIONS\n");
if (llclose(atoi(argv[1])) == 0)
{
printf("Timed out %d times\n",nTimeouts);
printf("Works!\n");
}
return 0;
}