forked from ec429/3psk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathptt.c
109 lines (99 loc) · 2.05 KB
/
ptt.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
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
104
105
106
107
108
109
/*
3psk - 3-pole Phase Shift Keying
Copyright (c) Edward Cree, 2013
Licensed under the GNU GPL v3+
ptt: Push To Talk control
*/
#include "ptt.h"
#include <stdio.h>
#ifdef WINDOWS
/* dummy definitions - PTT not supported */
int ptt_open(struct ptt_settings *set)
{
if(!set)
return(1);
if(!set->line)
{
fprintf(stderr, "PTT: not configured\n");
return(0);
}
fprintf(stderr, "PTT: not supported on Windows\n");
return(0);
}
int ptt_set(__attribute__((unused)) bool tx, __attribute__((unused)) const struct ptt_settings *set)
{
return(0);
}
int ptt_close(__attribute__((unused)) struct ptt_settings *set)
{
return(0);
}
#else /* !WINDOWS */
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int ptt_open(struct ptt_settings *set)
{
if(!set)
return(1);
if(!set->line)
{
fprintf(stderr, "PTT: not configured\n");
return(0);
}
if(set->devfd>=0)
ptt_close(set);
fprintf(stderr, "PTT: devpath=%s\n", set->devpath);
if(!set->devpath)
{
set->devfd=-1;
return(2);
}
set->devfd=open(set->devpath, O_RDWR | O_NOCTTY | O_NONBLOCK);
fprintf(stderr, "PTT: devfd=%d\n", set->devfd);
if(set->devfd<0)
{
perror("PTT: open");
return(3);
}
// try to clear both lines
int arg=PTT_LINE_BOTH;
if(ioctl(set->devfd, TIOCMBIC, &arg)<0)
perror("PTT: ioctl");
fprintf(stderr, "PTT: initialised Push To Talk\n");
return(0);
}
int ptt_set(bool tx, const struct ptt_settings *set)
{
if(!set)
return(1);
if(!set->line)
return(0);
if(set->devfd<0)
return(2);
/*int current;
if(!ioctl(set->devfd, TIOCMGET, ¤t))
fprintf(stderr, "PTT: Current is %x\n", current);*/
bool ptt=set->inverted?!tx:tx;
//fprintf(stderr, "PTT: Setting %x to %s\n", set->line, ptt?"true":"false");
if(ioctl(set->devfd, ptt?TIOCMBIS:TIOCMBIC, &set->line)<0)
{
perror("PTT: ioctl");
return(3);
}
return(0);
}
int ptt_close(struct ptt_settings *set)
{
if(!set)
return(1);
if(!set->line)
return(0);
ptt_set(false, set); // leave it in RX
if(set->devfd>=0)
close(set->devfd);
set->devfd=-1;
return(0);
}
#endif /* !WINDOWS */