Sun, 15 Nov 2015 21:12:11 +0100
Fixed compiling for systems with wiringPi. Improved handling of udp sockets if there is no brewpanel running.
420
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1 | /***************************************************************************** |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
2 | * Copyright (C) 2015 |
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 | #define SLCD_NULL 0x0000 |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
30 | #define SLCD_CLEAR 0x0001 |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
31 | #define SLCD_MCLEAR 0x1fff |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
32 | #define SLCD_HOME 0x0002 |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
33 | #define SLCD_MHOME 0x1ffe |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
34 | #define SLCD_DGRAM 0x0080 |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
35 | #define SLCD_MDGRAM 0x1f80 |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
36 | #define SLCD_DATA 0x0200 |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
37 | #define SLCD_MDATA 0x1e00 |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
38 | #define SLCD_LEDS 0x0400 |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
39 | #define SLCD_MLEDS 0x1c00 |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
40 | #define SLCD_KEYS 0x0800 |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
41 | #define SLCD_MKEYS 0x1800 |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
42 | #define SLCD_MDEV 0xe000 |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
43 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
44 | #define SEND_PORT 6554 |
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 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
47 | 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
|
48 | int sock = -1; |
422
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
420
diff
changeset
|
49 | uint16_t keys = 0x0000; |
420
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 | extern int debug; |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
52 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
53 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
54 | 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
|
55 | { |
422
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
420
diff
changeset
|
56 | socklen_t slen; |
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
420
diff
changeset
|
57 | uint16_t rdat; |
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
420
diff
changeset
|
58 | |
420
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
59 | if (sock == -1) |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
60 | return; |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
61 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
62 | 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
|
63 | 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
|
64 | if (shutdown(sock, SHUT_RDWR)) { |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
65 | 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
|
66 | } |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
67 | sock = -1; |
422
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
420
diff
changeset
|
68 | } else { |
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
420
diff
changeset
|
69 | 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
|
70 | 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
|
71 | 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
|
72 | 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
|
73 | } |
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
|
74 | sock = -1; |
422
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
420
diff
changeset
|
75 | } else { |
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
420
diff
changeset
|
76 | 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
|
77 | if (((rdat & 0x00ff) != keys) && debug) |
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
420
diff
changeset
|
78 | fprintf(stdout, "received keys %04x was %04x\n", rdat & 0x00ff, keys); |
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
420
diff
changeset
|
79 | keys = rdat & 0x00ff; |
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
420
diff
changeset
|
80 | } else { |
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
420
diff
changeset
|
81 | if (debug) |
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
420
diff
changeset
|
82 | fprintf(stdout, "received %04x\n", rdat); |
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
420
diff
changeset
|
83 | } |
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
420
diff
changeset
|
84 | |
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
420
diff
changeset
|
85 | } |
420
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
86 | } |
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 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
89 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
90 | |
422
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
420
diff
changeset
|
91 | void slcdDummy(int fd) |
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
420
diff
changeset
|
92 | { |
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
420
diff
changeset
|
93 | putLCDsocket(fd, SLCD_NULL); |
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
420
diff
changeset
|
94 | } |
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
420
diff
changeset
|
95 | |
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
420
diff
changeset
|
96 | |
420
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
97 | //void slcdHome(int fd) |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
98 | //{ |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
99 | //} |
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 | void slcdClear(int fd) |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
104 | { |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
105 | putLCDsocket(fd, SLCD_CLEAR); |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
106 | putLCDsocket(fd, SLCD_HOME); |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
107 | } |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
108 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
109 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
110 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
111 | //void slcdDisplay(int fd, int state) |
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 | |
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 | //void slcdCursor(int fd, int state) |
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 | //} |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
120 | |
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 | //void slcdCursorBlink(int fd, int state) |
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 | //} |
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 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
128 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
129 | //void slcdSendCommand(int fd, unsigned char command) |
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 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
135 | 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
|
136 | { |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
137 | uint16_t data = SLCD_DGRAM; |
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 | 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
|
140 | putLCDsocket(fd, data); |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
141 | } |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
142 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
143 | |
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 | //void slcdCharDef(int fd, int index, unsigned char data[8]) |
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 | //} |
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 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
150 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
151 | 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
|
152 | { |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
153 | uint16_t data = SLCD_DATA; |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
154 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
155 | data += c & 0x0ff; |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
156 | putLCDsocket(fd, data); |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
157 | } |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
158 | |
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 | 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
|
162 | { |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
163 | while (*string) |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
164 | slcdPutchar(fd, *string++); |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
165 | } |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
166 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
167 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
168 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
169 | //void slcdPrintf(int fd, const char *message, ...) |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
170 | //{ |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
171 | //} |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
172 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
173 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
174 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
175 | /* |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
176 | * 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
|
177 | * 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
|
178 | * 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
|
179 | * 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
|
180 | */ |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
181 | 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
|
182 | { |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
183 | 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
|
184 | 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
|
185 | return -1; |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
186 | } |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
187 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
188 | /* |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
189 | * 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
|
190 | */ |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
191 | 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
|
192 | sendaddr.sin_family = AF_INET; |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
193 | 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
|
194 | 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
|
195 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
196 | 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
|
197 | close(sock); |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
198 | sock = -1; |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
199 | 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
|
200 | return -1; |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
201 | } |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
202 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
203 | 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
|
204 | return 0; |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
205 | } |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
206 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
207 |