-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprotocols.h
171 lines (156 loc) · 3.94 KB
/
protocols.h
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
* protocols.h
*
* parse the runlength encoding of a signal from a remote
*
* Copyright (C) 2019 <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* description of a protocol
*/
struct protocol {
int main[100];
int zero[20];
int one[20];
int max;
};
/*
* status of parsing according to a protocol
*/
struct protocol_status {
int main;
int zero;
int one;
uint32_t encoding;
};
/*
* special values for a sequence: a bit, the end
*/
#define BIT 1,1
#define END 0,0
/*
* initialize a protocol status
*/
void protocol_init(struct protocol_status *status);
/*
* process a value according to a protocol
*/
int protocol_value(int value,
struct protocol *protocol, struct protocol_status *status,
int debug, void callback(uint32_t encoding));
/*
* status variables for a protocol
*/
#define PROTOCOL_VARS(protocol) \
struct protocol_status protocol ## _status; \
struct protocol_status protocol ## inverted_status;
/*
* initialize a protocol and its inverse
*/
#define PROTOCOL_START(protocol) \
protocol_init(& protocol ## _status); \
protocol_init(& protocol ## inverted_status);
/*
* process a value and its inverse according to a protocol
*/
#define PROTOCOL_PROCESS(value, protocol) \
protocol_value(value, \
& protocol ## _protocol, \
& protocol ## _status, \
debug == protocol ## _debug, \
protocol ## _print); \
if (inversion) \
protocol_value(-value, \
& protocol ## _protocol, \
& protocol ## inverted_status, \
debug == protocol ## inverted_debug, \
protocol ## _print);
/*
* values for debugging each protocol and its inversion
*/
enum protocol_debug {
nec_debug = 1,
necinverted_debug,
necrepeat_debug,
necrepeatinverted_debug,
nec2_debug,
nec2inverted_debug,
nec2repeat_debug,
nec2repeatinverted_debug,
sharp_debug,
sharpinverted_debug,
sony12_debug,
sony12inverted_debug,
sony20_debug,
sony20inverted_debug,
rc5_debug,
rc5inverted_debug,
};
/*
* the protocols
*/
enum protocols {
nec,
necrepeat,
nec2,
nec2repeat,
sharp,
sony12,
sony20,
rc5,
};
extern struct protocol nec_protocol;
extern struct protocol necrepeat_protocol;
extern struct protocol nec2_protocol;
extern struct protocol nec2repeat_protocol;
extern struct protocol sharp_protocol;
extern struct protocol sony12_protocol;
extern struct protocol sony20_protocol;
extern struct protocol rc5_protocol;
/*
* print the encoding for each protocol
*/
void nec_print(uint32_t encoding);
void nec2_print(uint32_t encoding);
void necrepeat_print(uint32_t encoding);
void nec2repeat_print(uint32_t encoding);
void sharp_print(uint32_t encoding);
void sony12_print(uint32_t encoding);
void sony20_print(uint32_t encoding);
void rc5_print(uint32_t encoding);
/*
* a key
*/
struct key {
int protocol;
int device;
int subdevice;
int function;
int subfunction;
int repeat;
};
struct key *stringtokey(char *string, char sep, char subsep);
void appendprotocol(char *string, int protocol);
void appendcode(char *string, int code, int sub, char subsep);
char *keytostring(struct key *key, char sep, char subsep);
void printkey(struct key *key);
int keyequal(struct key *a, struct key *b, int comparerepeat);
/*
* parse all protocols and their inverse at the same time
*/
void *protocols_init(int debug);
struct key *protocols_value(int value, void *internal);
int protocols_end(void *internal);