rc433/send.c

Wed, 07 May 2014 23:01:18 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Wed, 07 May 2014 23:01:18 +0200
changeset 29
ac763b87ee25
parent 25
5e0695f6add5
child 58
e8e7b46b705b
permissions
-rw-r--r--

Improved rc-switch library to be more flexible.

20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /*****************************************************************************
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 * Copyright (C) 2014
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 *
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * Michiel Broek <mbroek at mbse dot eu>
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 *
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 * This file is part of the mbsePi-apps
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 *
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 * This is free software; you can redistribute it and/or modify it
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 * under the terms of the GNU General Public License as published by the
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 * Free Software Foundation; either version 2, or (at your option) any
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 * later version.
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 *
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 * mbsePi-apps is distributed in the hope that it will be useful, but
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 * General Public License for more details.
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 *
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
19 * along with EC-65K; see the file COPYING. If not, write to the Free
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21 *****************************************************************************/
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23 #include "../lib/mbselib.h"
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24 #include "send.h"
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25
23
d820a6f3ec16 Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
26 #ifdef HAVE_WIRINGPI_H
22
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
27
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
28 void help(void)
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
29 {
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
30 fprintf(stdout, "mbsePi-apps send v%s\n\n", VERSION);
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
31 fprintf(stdout, "Usage: send [-t type ] [-f family ] [-g group ] [-d device] [-s state ] [-h]\n");
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
32 fprintf(stdout, " send -t A -g 00001 -d 00001 -s 1\n");
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
33 fprintf(stdout, " send -t B -g 2 -d 2 -s 0\n");
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
34 fprintf(stdout, " send -t C -f c -g 3 -d 3 -s 1\n");
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
35 fprintf(stdout, "\n");
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
36 fprintf(stdout, " send -t E -g A -d 2 -s 0\n");
22
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
37 }
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
38
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
39
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
40
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
41 int isAcode(char *s)
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
42 {
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
43 int i;
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
44
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
45 if (strlen(s) != 5)
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
46 return FALSE;
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
47 for (i = 0; i < 5; i++) {
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
48 if ((s[i] < '0') || (s[i] > '1'))
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
49 return FALSE;
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
50 }
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
51
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
52 return TRUE;
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
53 }
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
54
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
55
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
56
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
57 /*
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
58 * A - char group, char device (2 x 5 binary)
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
59 * B - int system, int unit
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
60 * C - char family, int group, int device
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
61 * D - char group, int device
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
62 */
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
63
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
64 int main(int argc, char *argv[]) {
22
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
65 char buf[127], *endptr;
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
66 int c;
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
67 char cType = '0', *sGroup = NULL, *sDevice = NULL, cFamily = '0', cGroup = '0';
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
68 int iState = -1, iGroup = -1, iDevice = -1;
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
69
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
70 while (1) {
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
71 int option_index = 0;
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
72 static struct option long_options[] = {
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
73 {"device", 1, 0, 'd'},
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
74 {"family", 1, 0, 'f'},
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
75 {"group", 1, 0, 'g'},
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
76 {"help", 0, 0, 'h'},
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
77 {"state", 1, 0, 's'},
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
78 {"type", 1, 0, 't'},
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
79 {0, 0, 0, 0}
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
80 };
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
81
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
82 c = getopt_long(argc, argv, "d:f:g:hs:t:", long_options, &option_index);
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
83 if (c == -1)
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
84 break;
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
85
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
86 switch (c) {
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
87 case 'd': snprintf(buf, 127, "%s", optarg);
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
88 if (cType == 'A') {
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
89 sDevice = xstrcpy(buf);
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
90 } else {
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
91 iDevice = strtol(buf, &endptr, 10);
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
92 }
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
93 break;
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
94 case 'f': snprintf(buf, 127, "%s", optarg);
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
95 if (cType == 'C') {
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
96 cFamily = tolower(buf[0]);
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
97 }
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
98 break;
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
99 case 'g': snprintf(buf, 127, "%s", optarg);
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
100 if (cType == 'A') {
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
101 sGroup = xstrcpy(buf);
29
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
102 } else if (cType == 'E') {
22
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
103 cGroup = toupper(buf[0]);
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
104 } else {
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
105 iGroup = strtol(buf, &endptr, 10);
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
106 }
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
107 break;
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
108 case 'h': help();
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
109 return 1;
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
110 case 's': snprintf(buf, 127, "%s", optarg);
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
111 iState = strtol(buf, &endptr, 10);
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
112 break;
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
113 case 't': snprintf(buf, 127, "%s", optarg);
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
114 cType = toupper(buf[0]);
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
115 break;
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
116 }
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
117 }
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
118
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
119 /*
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
120 * Check all option and combinations
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
121 */
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
122 if ((cType < 'A') || (cType > 'E')) {
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
123 fprintf(stderr, "Type must be A, B, C or E\n");
22
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
124 return 1;
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
125 }
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
126 if ((iState < 0) || (iState > 1)) {
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
127 fprintf(stderr, "State must be 0 or 1\n");
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
128 return 1;
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
129 }
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
130 if (cType == 'A') {
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
131 if (sGroup == NULL) {
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
132 fprintf(stderr, "Group not set\n");
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
133 return 1;
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
134 }
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
135 if (sDevice == NULL) {
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
136 fprintf(stderr, "Device not set\n");
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
137 return 1;
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
138 }
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
139 if (isAcode(sGroup) == FALSE) {
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
140 fprintf(stderr, "Group must be 5 binary digits like 10000\n");
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
141 return 1;
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
142 }
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
143 if (isAcode(sDevice) == FALSE) {
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
144 fprintf(stderr, "Device must be 5 binary digits like 10000\n");
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
145 return 1;
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
146 }
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
147 } else {
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
148 if (iDevice == -1) {
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
149 fprintf(stderr, "Device not set\n");
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
150 return 1;
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
151 }
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
152 }
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
153 if ((cType == 'B') || (cType == 'C')) {
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
154 if (iGroup == -1) {
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
155 fprintf(stderr, "Group not set\n");
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
156 return 1;
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
157 }
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
158 if ((iGroup < 1) || (iGroup > 4)) {
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
159 fprintf(stderr, "Group must be 1..4\n");
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
160 return 1;
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
161 }
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
162 if ((iDevice < 1) || (iDevice > 4)) {
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
163 fprintf(stderr, "Device must be 1..4\n");
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
164 return 1;
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
165 }
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
166 }
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
167 if (cType == 'E') {
22
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
168 if ((iDevice < 1) || (iDevice > 3)) {
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
169 fprintf(stderr, "Device must be 1..3\n");
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
170 return 1;
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
171 }
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
172 if ((cGroup < 'A') || (cGroup > 'D')) {
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
173 fprintf(stderr, "Group must be A..D\n");
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
174 return 1;
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
175 }
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
176 }
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
177 if (cType == 'C') {
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
178 if ((cFamily < 'a') || (cFamily > 'f')) {
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
179 fprintf(stderr, "Family must be a..f\n");
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
180 return 1;
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
181 }
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
182 }
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
183
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
184 /*
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
185 output PIN is hardcoded for testing purposes
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
186 see https://projects.drogon.net/raspberry-pi/wiringpi/pins/
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
187 for pin mapping of the raspberry pi GPIO connector
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
188 */
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
189 int PIN = 0;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
190
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
191 if (wiringPiSetup () )
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
192 return 1;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
193
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
194 enableTransmit(PIN);
22
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
195 switch (cType) {
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
196 case 'A':
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
197 printf("Type A sending group[%s] device[%s] command[%d]\n", sGroup, sDevice, iState);
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
198 toggleTypeA(sGroup, sDevice, iState);
22
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
199 break;
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
200 case 'B':
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
201 printf("Type B sending group[%d] device[%i] command[%i]\n", iGroup, iDevice, iState);
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
202 toggleTypeB(iGroup, iDevice, iState);
22
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
203 break;
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
204 case 'C':
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
205 printf("Type C sending family[%c] group[%d] device[%i] command[%i]\n", cFamily, iGroup, iDevice, iState);
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
206 toggleTypeC(cFamily, iGroup, iDevice, iState);
22
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
207 break;
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
208 case 'E':
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
209 printf("Type E sending group[%c] device[%i] command[%i]\n", cGroup, iDevice, iState);
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
210 toggleTypeE(cGroup, iDevice, iState);
22
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
211 break;
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
212 }
22
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
213 disableTransmit();
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
214
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
215 return 0;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
216 }
23
d820a6f3ec16 Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
217
d820a6f3ec16 Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
218 #else
d820a6f3ec16 Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
219
d820a6f3ec16 Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
220 int main(int argc, char *argv[]) {
d820a6f3ec16 Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
221 fprintf(stderr, "This program does nothing without the wiringPi library\n");
d820a6f3ec16 Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
222 return 0;
d820a6f3ec16 Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
223 }
d820a6f3ec16 Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
224
d820a6f3ec16 Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
225 #endif
d820a6f3ec16 Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
226

mercurial