Sat, 17 May 2014 23:06:39 +0200
Prepared unix socket communication
7 | 1 | #ifndef _MBSELIB_H |
2 | #define _MBSELIB_H | |
3 | ||
4 | #include "../config.h" | |
5 | ||
6 | #include <stdlib.h> | |
7 | #include <stdio.h> | |
20
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
8 | #include <stdint.h> |
7 | 9 | #include <string.h> |
10 | #include <ctype.h> | |
11 | #include <sys/types.h> | |
12 | 12 | #include <sys/stat.h> |
32
3bac8fd4173d
Added user log function for program data
Michiel Broek <mbroek@mbse.eu>
parents:
31
diff
changeset
|
13 | #include <sys/time.h> |
3bac8fd4173d
Added user log function for program data
Michiel Broek <mbroek@mbse.eu>
parents:
31
diff
changeset
|
14 | #include <time.h> |
12 | 15 | #include <fcntl.h> |
8
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
16 | #include <syslog.h> |
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
17 | #include <unistd.h> |
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
18 | #include <errno.h> |
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
19 | #include <signal.h> |
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
20 | #include <getopt.h> |
34 | 21 | #include <limits.h> |
40
dafbbd5e9922
Prepared unix socket communication
Michiel Broek <mbroek@mbse.eu>
parents:
34
diff
changeset
|
22 | #include <sys/socket.h> |
dafbbd5e9922
Prepared unix socket communication
Michiel Broek <mbroek@mbse.eu>
parents:
34
diff
changeset
|
23 | #include <sys/un.h> |
dafbbd5e9922
Prepared unix socket communication
Michiel Broek <mbroek@mbse.eu>
parents:
34
diff
changeset
|
24 | #include <poll.h> |
34 | 25 | |
8
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
26 | |
16
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
27 | /* mosquitto */ |
8
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
28 | #include <mosquitto.h> |
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
29 | |
18
3f4823083b9d
wirinPi code is now conditional
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
30 | #ifdef HAVE_WIRINGPI_H |
16
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
31 | /* wiringPi */ |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
32 | #include <wiringPi.h> |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
33 | #include <pcf8574.h> |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
34 | #include <lcd.h> |
7 | 35 | |
18
3f4823083b9d
wirinPi code is now conditional
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
36 | #endif |
3f4823083b9d
wirinPi code is now conditional
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
37 | |
7 | 38 | #define TRUE 1 |
39 | #define FALSE 0 | |
40 | ||
8
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
41 | #define MBSE_SS(x) (x)?(x):"(null)" |
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
42 | |
7 | 43 | /* rdconfig.c */ |
44 | typedef struct _key_list { | |
45 | char *key; | |
46 | int (*prc)(char **); | |
47 | char **dest; | |
48 | } key_list; | |
49 | ||
9
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
50 | typedef struct _w1_therm { |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
51 | struct _w1_therm *next; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
52 | char *master; /* Master for this device */ |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
53 | int bus; /* Reserved for ds2482-800 */ |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
54 | char *name; /* Name of this device */ |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
55 | char *alias; /* Friendly name */ |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
56 | int present; /* 1=present, 0=absent */ |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
57 | int lastval; /* Last valid value */ |
26
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
25
diff
changeset
|
58 | int update; /* Value updated */ |
9
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
59 | } w1_therm; |
7 | 60 | |
24
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
61 | typedef struct _rc_switch { |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
62 | struct _rc_switch *next; |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
63 | char *address; /* Address code */ |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
64 | char *alias; /* Friendly name */ |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
65 | } rc_switch; |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
66 | |
7 | 67 | typedef struct _sys_config { |
9
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
68 | char *name; /* Configuration name */ |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
69 | char *mosq_host; /* mosquitto server hostname */ |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
70 | int mosq_port; /* mosquitto server port */ |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
71 | w1_therm *w1therms; /* 1-wire temp sensors */ |
17
b802305046dc
Tests for wiringPi are now not fatal
Michiel Broek <mbroek@mbse.eu>
parents:
16
diff
changeset
|
72 | #ifdef HAVE_WIRINGPI_H |
b802305046dc
Tests for wiringPi are now not fatal
Michiel Broek <mbroek@mbse.eu>
parents:
16
diff
changeset
|
73 | int lcd_cols; /* LCD display columns */ |
b802305046dc
Tests for wiringPi are now not fatal
Michiel Broek <mbroek@mbse.eu>
parents:
16
diff
changeset
|
74 | int lcd_rows; /* LCD display rows */ |
24
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
75 | int rx433; /* 433 MHz receiver pin */ |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
76 | int tx433; /* 433 MHz transmitter pin */ |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
77 | rc_switch *rcswitch; /* 433 MHz RC Power switches */ |
17
b802305046dc
Tests for wiringPi are now not fatal
Michiel Broek <mbroek@mbse.eu>
parents:
16
diff
changeset
|
78 | #endif |
7 | 79 | } sys_config; |
80 | ||
81 | ||
82 | void killconfig(void); | |
24
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
83 | int rdconfig(char *); |
7 | 84 | |
85 | ||
34 | 86 | /* lock.c */ |
87 | int lockprog(char *); | |
88 | void ulockprog(char *); | |
89 | ||
90 | ||
7 | 91 | /* xutil.c */ |
92 | char *xmalloc(size_t); | |
93 | char *xstrcpy(char *); | |
94 | char *xstrcat(char *, char *); | |
95 | ||
16
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
96 | |
18
3f4823083b9d
wirinPi code is now conditional
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
97 | #ifdef HAVE_WIRINGPI_H |
20
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
98 | |
16
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
99 | /* lcd-pcf8574.c */ |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
100 | // Defines for the pcf8574 Pi LCD interface board |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
101 | #define AF_BASE 100 |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
102 | |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
103 | #define AF_RS (AF_BASE + 0) |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
104 | #define AF_RW (AF_BASE + 1) |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
105 | #define AF_E (AF_BASE + 2) |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
106 | #define AF_BACKLIGHT (AF_BASE + 3) |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
107 | #define AF_DB4 (AF_BASE + 4) |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
108 | #define AF_DB5 (AF_BASE + 5) |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
109 | #define AF_DB6 (AF_BASE + 6) |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
110 | #define AF_DB7 (AF_BASE + 7) |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
111 | |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
112 | void setBacklight (int); |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
113 | int initLCD (int, int); |
40
dafbbd5e9922
Prepared unix socket communication
Michiel Broek <mbroek@mbse.eu>
parents:
34
diff
changeset
|
114 | void mb_lcdPutchar(const int, unsigned char); |
dafbbd5e9922
Prepared unix socket communication
Michiel Broek <mbroek@mbse.eu>
parents:
34
diff
changeset
|
115 | void mb_lcdPuts(const int, const char *); |
dafbbd5e9922
Prepared unix socket communication
Michiel Broek <mbroek@mbse.eu>
parents:
34
diff
changeset
|
116 | void mb_lcdClear(const int); |
16
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
117 | |
20
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
118 | |
32
3bac8fd4173d
Added user log function for program data
Michiel Broek <mbroek@mbse.eu>
parents:
31
diff
changeset
|
119 | /* logger.c */ |
3bac8fd4173d
Added user log function for program data
Michiel Broek <mbroek@mbse.eu>
parents:
31
diff
changeset
|
120 | void logger(char *, char *, char *); |
3bac8fd4173d
Added user log function for program data
Michiel Broek <mbroek@mbse.eu>
parents:
31
diff
changeset
|
121 | |
20
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
122 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
123 | /* rc-switch.c */ |
28
32ed1ea4d0b6
Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents:
26
diff
changeset
|
124 | int toggleSwitch(char *); |
32ed1ea4d0b6
Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents:
26
diff
changeset
|
125 | int toggleTypeA(char *, char *, bool); |
32ed1ea4d0b6
Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents:
26
diff
changeset
|
126 | int toggleTypeB(int, int, bool); |
32ed1ea4d0b6
Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents:
26
diff
changeset
|
127 | int toggleTypeC(char, int, int, bool); |
32ed1ea4d0b6
Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents:
26
diff
changeset
|
128 | int toggleTypeE(char, int, bool); |
20
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
129 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
130 | void enableReceiveIRQ(int interrupt); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
131 | void enableReceive(void); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
132 | void disableReceive(void); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
133 | bool available(void); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
134 | void resetAvailable(void); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
135 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
136 | unsigned long getReceivedValue(void); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
137 | unsigned int getReceivedBitlength(void); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
138 | unsigned int getReceivedDelay(void); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
139 | unsigned int getReceivedProtocol(void); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
140 | unsigned int *getReceivedRawdata(void); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
141 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
142 | void enableTransmit(int); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
143 | void disableTransmit(void); |
29
ac763b87ee25
Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents:
28
diff
changeset
|
144 | |
ac763b87ee25
Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents:
28
diff
changeset
|
145 | char *dec2binWzerofill(unsigned long, unsigned int); |
20
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
146 | |
31
89dd2b691701
Added library code to read DHT11 temperature/humidity sensor
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
147 | |
89dd2b691701
Added library code to read DHT11 temperature/humidity sensor
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
148 | /* dht11.c */ |
89dd2b691701
Added library code to read DHT11 temperature/humidity sensor
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
149 | void dht11Read(void); |
89dd2b691701
Added library code to read DHT11 temperature/humidity sensor
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
150 | void dht11Init(int, int, int); |
89dd2b691701
Added library code to read DHT11 temperature/humidity sensor
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
151 | |
89dd2b691701
Added library code to read DHT11 temperature/humidity sensor
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
152 | |
7 | 153 | #endif |
154 | ||
18
3f4823083b9d
wirinPi code is now conditional
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
155 | |
3f4823083b9d
wirinPi code is now conditional
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
156 | #endif |
3f4823083b9d
wirinPi code is now conditional
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
157 |