rc433/sniffer.c

Mon, 05 May 2014 10:33:26 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Mon, 05 May 2014 10:33:26 +0200
changeset 23
d820a6f3ec16
parent 20
f7f9463cdefd
child 58
e8e7b46b705b
permissions
-rw-r--r--

Added more conditional compile switches

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 "sniffer.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: 20
diff changeset
26 #ifdef HAVE_WIRINGPI_H
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28 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
29
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30 // 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
31 // 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
32 // for more information.
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
33 int PIN = 2;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
34
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35 if (wiringPiSetup() == -1)
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
36 return 0;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38 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
39
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40 while(1) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
41
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42 if (available()) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43 unsigned long value = getReceivedValue();
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
45 if (value == 0) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46 printf("Unknown encoding\n");
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
47 } else {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48 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
49 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
50 resetAvailable();
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
52 } else {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
53 /*
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
54 * Don't hog the CPU
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
55 */
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
56 delay(10);
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
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
60 exit(0);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
61 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
62
23
d820a6f3ec16 Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
63 #else
d820a6f3ec16 Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
64
d820a6f3ec16 Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
65 int main(int argc, char *argv[]) {
d820a6f3ec16 Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
66 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
67 return 0;
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
d820a6f3ec16 Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
70 #endif
d820a6f3ec16 Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
71

mercurial