rc433/sniffer.c

Sun, 31 Aug 2014 17:51:04 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 31 Aug 2014 17:51:04 +0200
changeset 272
f436d826de4b
parent 58
e8e7b46b705b
permissions
-rw-r--r--

Added Heater and Cooler delay edit fields. Added more checks on entered data in the units edit screen.

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
58
e8e7b46b705b Fixed compilation without wiringpi
Michiel Broek <mbroek@mbse.eu>
parents: 23
diff changeset
23 #include "rc433.h"
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24
23
d820a6f3ec16 Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
25 #ifdef HAVE_WIRINGPI_H
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27 int main(int argc, char *argv[]) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29 // This pin is not the first pin on the RPi GPIO header!
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30 // Consult 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
31 // for more information.
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
32 int PIN = 2;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
33
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
34 if (wiringPiSetup() == -1)
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35 return 0;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
36
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37 enableReceiveIRQ(PIN); // Receiver on inerrupt 0 => that is pin #2
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39 while(1) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
41 if (available()) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42 unsigned long value = getReceivedValue();
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44 if (value == 0) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
45 printf("Unknown encoding\n");
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46 } else {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
47 printf("Protocol %d received 0x%lx\n", getReceivedProtocol(), value);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49 resetAvailable();
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
50
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51 } else {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
52 /*
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
53 * Don't hog the CPU
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
54 */
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
55 delay(10);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
56 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
57 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
58
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
59 exit(0);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
60 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
61
23
d820a6f3ec16 Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
62 #else
d820a6f3ec16 Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
63
d820a6f3ec16 Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
64 int main(int argc, char *argv[]) {
d820a6f3ec16 Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
65 fprintf(stderr, "This program does nothing without the wiringPi library\n");
d820a6f3ec16 Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
66 return 0;
d820a6f3ec16 Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
67 }
d820a6f3ec16 Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
68
d820a6f3ec16 Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
69 #endif
d820a6f3ec16 Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
70

mercurial