Wed, 24 Apr 2024 20:36:06 +0200
Finished save fermenter uit edit.
420
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1 | /***************************************************************************** |
571
6f8eda55ec2c
Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.
Michiel Broek <mbroek@mbse.eu>
parents:
561
diff
changeset
|
2 | * Copyright (C) 2015-2019 |
420
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
3 | * |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
4 | * Michiel Broek <mbroek at mbse dot eu> |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
5 | * |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
6 | * This file is part of the mbsePi-apps |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
7 | * |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
8 | * This is free software; you can redistribute it and/or modify it |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
9 | * under the terms of the GNU General Public License as published by the |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
10 | * Free Software Foundation; either version 2, or (at your option) any |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
11 | * later version. |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
12 | * |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
13 | * mbsePi-apps is distributed in the hope that it will be useful, but |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
16 | * General Public License for more details. |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
17 | * |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
18 | * You should have received a copy of the GNU General Public License |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
19 | * along with ThermFerm; see the file COPYING. If not, write to the Free |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
20 | * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
21 | *****************************************************************************/ |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
22 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
23 | #include "thermferm.h" |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
24 | #include "slcd.h" |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
25 | #include "futil.h" |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
26 | #include "xutil.h" |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
27 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
28 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
29 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
30 | struct sockaddr_in sendaddr; /* Server send socket */ |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
31 | int sock = -1; |
422
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
420
diff
changeset
|
32 | uint16_t keys = 0x0000; |
426
e54611453d29
Moved global bit defines to config.h
Michiel Broek <mbroek@mbse.eu>
parents:
423
diff
changeset
|
33 | uint16_t leds = 0x0400; /* LED's, buzzer, LCD backlight */ |
427
e8e548922e31
Initial part of LEDs and backlight implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
426
diff
changeset
|
34 | uint16_t oleds = 0x0400; |
420
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
35 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
36 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
37 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
38 | void putLCDsocket(int fd, uint16_t data) |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
39 | { |
561
fcfc3dbe85fa
Versie 0.8.7. Fixed a lot of memory leaks with the aid of valgrind.
Michiel Broek <mbroek@mbse.eu>
parents:
485
diff
changeset
|
40 | socklen_t slen = 0; |
422
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
420
diff
changeset
|
41 | uint16_t rdat; |
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
420
diff
changeset
|
42 | |
420
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
43 | if (sock == -1) |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
44 | return; |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
45 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
46 | if (sendto(sock, &data, sizeof(uint16_t), 0, (struct sockaddr *)&sendaddr, sizeof(sendaddr)) != sizeof(uint16_t)) { |
423
02653162b03b
Fixed compiling for systems with wiringPi. Improved handling of udp sockets if there is no brewpanel running.
Michiel Broek <mbroek@mbse.eu>
parents:
422
diff
changeset
|
47 | syslog(LOG_NOTICE, "Socket %d send failed, closing socket: %s", sock, strerror(errno)); |
420
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
48 | if (shutdown(sock, SHUT_RDWR)) { |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
49 | syslog(LOG_NOTICE, "Can't shutdown socket: %s", strerror(errno)); |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
50 | } |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
51 | sock = -1; |
422
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
420
diff
changeset
|
52 | } else { |
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
420
diff
changeset
|
53 | if (recvfrom(sock, &rdat, sizeof(uint16_t), 0, (struct sockaddr *) &sendaddr, &slen) != sizeof(uint16_t)) { |
423
02653162b03b
Fixed compiling for systems with wiringPi. Improved handling of udp sockets if there is no brewpanel running.
Michiel Broek <mbroek@mbse.eu>
parents:
422
diff
changeset
|
54 | syslog(LOG_NOTICE, "Socket %d recvfrom failed, closing socket: %s", sock, strerror(errno)); |
02653162b03b
Fixed compiling for systems with wiringPi. Improved handling of udp sockets if there is no brewpanel running.
Michiel Broek <mbroek@mbse.eu>
parents:
422
diff
changeset
|
55 | if (shutdown(sock, SHUT_RDWR)) { |
02653162b03b
Fixed compiling for systems with wiringPi. Improved handling of udp sockets if there is no brewpanel running.
Michiel Broek <mbroek@mbse.eu>
parents:
422
diff
changeset
|
56 | syslog(LOG_NOTICE, "Can't shutdown socket: %s", strerror(errno)); |
02653162b03b
Fixed compiling for systems with wiringPi. Improved handling of udp sockets if there is no brewpanel running.
Michiel Broek <mbroek@mbse.eu>
parents:
422
diff
changeset
|
57 | } |
02653162b03b
Fixed compiling for systems with wiringPi. Improved handling of udp sockets if there is no brewpanel running.
Michiel Broek <mbroek@mbse.eu>
parents:
422
diff
changeset
|
58 | sock = -1; |
422
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
420
diff
changeset
|
59 | } else { |
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
420
diff
changeset
|
60 | if ((rdat & SLCD_MKEYS) == SLCD_KEYS) { |
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
420
diff
changeset
|
61 | keys = rdat & 0x00ff; |
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
420
diff
changeset
|
62 | } |
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
420
diff
changeset
|
63 | |
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
420
diff
changeset
|
64 | } |
420
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
65 | } |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
66 | } |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
67 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
68 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
69 | |
422
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
420
diff
changeset
|
70 | void slcdDummy(int fd) |
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
420
diff
changeset
|
71 | { |
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
420
diff
changeset
|
72 | putLCDsocket(fd, SLCD_NULL); |
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
420
diff
changeset
|
73 | } |
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
420
diff
changeset
|
74 | |
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
420
diff
changeset
|
75 | |
426
e54611453d29
Moved global bit defines to config.h
Michiel Broek <mbroek@mbse.eu>
parents:
423
diff
changeset
|
76 | |
e54611453d29
Moved global bit defines to config.h
Michiel Broek <mbroek@mbse.eu>
parents:
423
diff
changeset
|
77 | void slcdLEDs(int fd) |
e54611453d29
Moved global bit defines to config.h
Michiel Broek <mbroek@mbse.eu>
parents:
423
diff
changeset
|
78 | { |
427
e8e548922e31
Initial part of LEDs and backlight implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
426
diff
changeset
|
79 | if (leds != oleds) |
e8e548922e31
Initial part of LEDs and backlight implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
426
diff
changeset
|
80 | putLCDsocket(fd, leds); |
e8e548922e31
Initial part of LEDs and backlight implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
426
diff
changeset
|
81 | oleds = leds; |
426
e54611453d29
Moved global bit defines to config.h
Michiel Broek <mbroek@mbse.eu>
parents:
423
diff
changeset
|
82 | } |
e54611453d29
Moved global bit defines to config.h
Michiel Broek <mbroek@mbse.eu>
parents:
423
diff
changeset
|
83 | |
e54611453d29
Moved global bit defines to config.h
Michiel Broek <mbroek@mbse.eu>
parents:
423
diff
changeset
|
84 | |
420
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
85 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
86 | void slcdClear(int fd) |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
87 | { |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
88 | putLCDsocket(fd, SLCD_CLEAR); |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
89 | putLCDsocket(fd, SLCD_HOME); |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
90 | } |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
91 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
92 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
93 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
94 | void slcdPosition(int fd, int x, int y) |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
95 | { |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
96 | uint16_t data = SLCD_DGRAM; |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
97 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
98 | data += (x & 0x1f) + ((y & 0x03) << 5); |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
99 | putLCDsocket(fd, data); |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
100 | } |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
101 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
102 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
103 | |
485 | 104 | void slcdCharDef(int fd, int idx, unsigned char data[8]) |
484
7362ebd40f26
Use user defined characters for the LCD display just like in Arduino projects.
Michiel Broek <mbroek@mbse.eu>
parents:
427
diff
changeset
|
105 | { |
7362ebd40f26
Use user defined characters for the LCD display just like in Arduino projects.
Michiel Broek <mbroek@mbse.eu>
parents:
427
diff
changeset
|
106 | int i; |
7362ebd40f26
Use user defined characters for the LCD display just like in Arduino projects.
Michiel Broek <mbroek@mbse.eu>
parents:
427
diff
changeset
|
107 | |
485 | 108 | putLCDsocket(fd, SLCD_CGRAM | ((idx & 7) << 3)); |
484
7362ebd40f26
Use user defined characters for the LCD display just like in Arduino projects.
Michiel Broek <mbroek@mbse.eu>
parents:
427
diff
changeset
|
109 | for (i = 0 ; i < 8 ; ++i) |
7362ebd40f26
Use user defined characters for the LCD display just like in Arduino projects.
Michiel Broek <mbroek@mbse.eu>
parents:
427
diff
changeset
|
110 | putLCDsocket(fd, data[i]); |
7362ebd40f26
Use user defined characters for the LCD display just like in Arduino projects.
Michiel Broek <mbroek@mbse.eu>
parents:
427
diff
changeset
|
111 | } |
420
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
112 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
113 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
114 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
115 | void slcdPutchar(int fd, unsigned char c) |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
116 | { |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
117 | uint16_t data = SLCD_DATA; |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
118 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
119 | data += c & 0x0ff; |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
120 | putLCDsocket(fd, data); |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
121 | } |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
122 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
123 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
124 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
125 | void slcdPuts(int fd, const char *string) |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
126 | { |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
127 | while (*string) |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
128 | slcdPutchar(fd, *string++); |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
129 | } |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
130 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
131 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
132 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
133 | /* |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
134 | * Try to setup a udp connection to 127.0.0.1 so we duplicate the panel |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
135 | * display and keys of the real panel. This should fail on a production |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
136 | * system because there should no brewpanel program be running. If it |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
137 | * succeeds, all io will be duplicated over the network. |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
138 | */ |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
139 | int slcdInit(int fd, int cols, int rows) |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
140 | { |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
141 | if ((sock = socket(AF_INET, SOCK_DGRAM /*| SOCK_NONBLOCK */, 0)) < 0) { |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
142 | syslog(LOG_NOTICE, "slcdInit() can't create socket: %s", strerror(errno)); |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
143 | return -1; |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
144 | } |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
145 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
146 | /* |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
147 | * Setup address structure for the server socket. |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
148 | */ |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
149 | memset(&sendaddr, 0, sizeof(struct sockaddr_in)); |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
150 | sendaddr.sin_family = AF_INET; |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
151 | sendaddr.sin_addr.s_addr = inet_addr("127.0.0.1"); |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
152 | sendaddr.sin_port = htons(SEND_PORT); |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
153 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
154 | if (connect(sock, (struct sockaddr *)&sendaddr, sizeof(sendaddr)) < 0) { |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
155 | close(sock); |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
156 | sock = -1; |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
157 | syslog(LOG_NOTICE, "slcdInit() can't bind sendsock %s", strerror(errno)); |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
158 | return -1; |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
159 | } |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
160 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
161 | syslog(LOG_NOTICE, "slcdInit() socket %d to brewpanel is active", sock); |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
162 | return 0; |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
163 | } |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
164 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
165 |