brewpanel/sockio.c

Wed, 12 May 2021 21:17:59 +0200

author
Michiel Broek
date
Wed, 12 May 2021 21:17:59 +0200
changeset 611
732d482f47c8
parent 443
6b80a37fdf8d
child 637
21e542c15832
permissions
-rw-r--r--

Improved logging if wiringpi failed.

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 * mbsePi-apps 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 mbsePi-apps; 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 "brewpanel.h"
428
d64c4c1edd78 Fixed parameters pasing between different layers.
Michiel Broek <mbroek@mbse.eu>
parents: 427
diff changeset
24 #include "sdlgui.h"
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25 #include "slcd.h"
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26 #include "futil.h"
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27 #include "sockio.h"
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 #ifdef HAVE_SDL_SDL_H
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
31
422
13502d0dda65 The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents: 420
diff changeset
32 int sock = -1; /* Unix datagram socket */
13502d0dda65 The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents: 420
diff changeset
33 struct sockaddr_in servaddr; /* Server socket address */
13502d0dda65 The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents: 420
diff changeset
34 uint16_t keys = SLCD_KEYS; /* Pressed keys bits */
431
b3895cd6edd3 Finished optional paneltype. Fixed all debug flags.
Michiel Broek <mbroek@mbse.eu>
parents: 428
diff changeset
35 extern int debug;
420
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
428
d64c4c1edd78 Fixed parameters pasing between different layers.
Michiel Broek <mbroek@mbse.eu>
parents: 427
diff changeset
38 void socket_recv(SGOBJ *dlg)
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39 {
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40 uint16_t data;
443
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 431
diff changeset
41 unsigned char cgdata[8];
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42 struct sockaddr_in clntaddr;
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43 socklen_t clntlen = sizeof(clntaddr);
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44 ssize_t recv_len;
443
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 431
diff changeset
45 int i, index, fd = 0, my_error;
420
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 recv_len = recvfrom(sock, &data, sizeof(uint16_t), MSG_DONTWAIT, (struct sockaddr *)&clntaddr, &clntlen);
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48 if (recv_len == sizeof(uint16_t)) {
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49 /*
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
50 * Get device from data
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51 */
422
13502d0dda65 The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents: 420
diff changeset
52 fd = (data & SLCD_MDEV) >> 13;
431
b3895cd6edd3 Finished optional paneltype. Fixed all debug flags.
Michiel Broek <mbroek@mbse.eu>
parents: 428
diff changeset
53 if (fd && debug)
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
54 fprintf(stdout, "Device %d ", fd);
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
55 if ((data & SLCD_MCLEAR) == SLCD_CLEAR) {
428
d64c4c1edd78 Fixed parameters pasing between different layers.
Michiel Broek <mbroek@mbse.eu>
parents: 427
diff changeset
56 slcdClear(dlg, fd);
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
57 } else if ((data & SLCD_MHOME) == SLCD_HOME) {
428
d64c4c1edd78 Fixed parameters pasing between different layers.
Michiel Broek <mbroek@mbse.eu>
parents: 427
diff changeset
58 slcdHome(dlg, fd);
443
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 431
diff changeset
59 } else if ((data & SLCD_MCGRAM) == SLCD_CGRAM) {
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 431
diff changeset
60 index = (data & 0x038) >> 3;
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 431
diff changeset
61 for (i = 0; i < 8; i++) {
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 431
diff changeset
62 /*
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 431
diff changeset
63 * Reply with the current keyboard state. Looks too early but the very last reply
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 431
diff changeset
64 * will be sent at the end of this function and we need to take 8 data words.
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 431
diff changeset
65 */
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 431
diff changeset
66 if (sendto(sock, &keys, sizeof(uint16_t), MSG_DONTWAIT, (struct sockaddr *) &clntaddr, clntlen) == -1) {
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 431
diff changeset
67 syslog(LOG_NOTICE, "socket_recv() sendto error: %s", strerror(errno));
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 431
diff changeset
68 }
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 431
diff changeset
69 recv_len = recvfrom(sock, &data, sizeof(uint16_t), 0, (struct sockaddr *)&clntaddr, &clntlen);
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 431
diff changeset
70 cgdata[i] = data & 0x00ff;
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 431
diff changeset
71 }
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 431
diff changeset
72 fprintf(stdout, "Got new CGRAM index=%d, %02x %02x %02x %02x %02x %02x %02x %02x\n", index,
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 431
diff changeset
73 cgdata[0], cgdata[1], cgdata[2], cgdata[3], cgdata[4], cgdata[5], cgdata[6], cgdata[7]);
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 431
diff changeset
74 slcdCharDef(dlg, fd, index, cgdata);
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
75 } else if ((data & SLCD_MDGRAM) == SLCD_DGRAM) {
428
d64c4c1edd78 Fixed parameters pasing between different layers.
Michiel Broek <mbroek@mbse.eu>
parents: 427
diff changeset
76 slcdPosition(dlg, fd, data & 0x001f, (data & 0x0060) >> 5);
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
77 } else if ((data & 0xfe00) == SLCD_DATA) {
428
d64c4c1edd78 Fixed parameters pasing between different layers.
Michiel Broek <mbroek@mbse.eu>
parents: 427
diff changeset
78 slcdPutchar(dlg, fd, data & 0x00ff);
427
e8e548922e31 Initial part of LEDs and backlight implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 426
diff changeset
79 } else if ((data & SLCD_MLEDS) == SLCD_LEDS) {
431
b3895cd6edd3 Finished optional paneltype. Fixed all debug flags.
Michiel Broek <mbroek@mbse.eu>
parents: 428
diff changeset
80 if (debug)
b3895cd6edd3 Finished optional paneltype. Fixed all debug flags.
Michiel Broek <mbroek@mbse.eu>
parents: 428
diff changeset
81 fprintf(stdout, "socket_recv leds fd=%d bits=%02x\n", fd, (data & 0x00ff));
428
d64c4c1edd78 Fixed parameters pasing between different layers.
Michiel Broek <mbroek@mbse.eu>
parents: 427
diff changeset
82 slcdBacklight(dlg, fd, data & SLED_LCD);
d64c4c1edd78 Fixed parameters pasing between different layers.
Michiel Broek <mbroek@mbse.eu>
parents: 427
diff changeset
83 slcdLED(dlg, fd, SGLEDGREEN, data & SLED_TFLED);
d64c4c1edd78 Fixed parameters pasing between different layers.
Michiel Broek <mbroek@mbse.eu>
parents: 427
diff changeset
84 slcdLED(dlg, fd, SGLEDRED, data & SLED_HLTH);
d64c4c1edd78 Fixed parameters pasing between different layers.
Michiel Broek <mbroek@mbse.eu>
parents: 427
diff changeset
85 slcdLED(dlg, fd, SGLEDBLUE, data & SLED_MLTH);
d64c4c1edd78 Fixed parameters pasing between different layers.
Michiel Broek <mbroek@mbse.eu>
parents: 427
diff changeset
86 slcdLED(dlg, fd, SGLEDYELLOW, data & SLED_MLTP);
427
e8e548922e31 Initial part of LEDs and backlight implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 426
diff changeset
87
422
13502d0dda65 The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents: 420
diff changeset
88 } else if (data != 0x0000) {
431
b3895cd6edd3 Finished optional paneltype. Fixed all debug flags.
Michiel Broek <mbroek@mbse.eu>
parents: 428
diff changeset
89 if (debug)
b3895cd6edd3 Finished optional paneltype. Fixed all debug flags.
Michiel Broek <mbroek@mbse.eu>
parents: 428
diff changeset
90 fprintf(stdout, "socket_recv got %04x\n", data);
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
91 }
422
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 /*
13502d0dda65 The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents: 420
diff changeset
94 * Reply with the current keys state
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 if (sendto(sock, &keys, sizeof(uint16_t), MSG_DONTWAIT, (struct sockaddr *) &clntaddr, clntlen) == -1) {
431
b3895cd6edd3 Finished optional paneltype. Fixed all debug flags.
Michiel Broek <mbroek@mbse.eu>
parents: 428
diff changeset
97 syslog(LOG_NOTICE, "socket_recv() sendto error: %s", strerror(errno));
422
13502d0dda65 The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents: 420
diff changeset
98 }
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
99 } else if (recv_len < 0) {
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
100 my_error = errno;
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
101 if (my_error != EAGAIN) {
431
b3895cd6edd3 Finished optional paneltype. Fixed all debug flags.
Michiel Broek <mbroek@mbse.eu>
parents: 428
diff changeset
102 syslog(LOG_NOTICE, "socket_recv() error: %s", strerror(my_error));
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
103 }
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
104 } else {
431
b3895cd6edd3 Finished optional paneltype. Fixed all debug flags.
Michiel Broek <mbroek@mbse.eu>
parents: 428
diff changeset
105 syslog(LOG_NOTICE, "socket_recv() unknown len=%d", (int)recv_len);
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
106 }
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 int socket_connect(void)
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 int s;
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 s = socket(AF_INET, SOCK_DGRAM, 0);
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
116 if (s == -1) {
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
117 syslog(LOG_NOTICE, "socket_connect() can't create: %s", strerror(errno));
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
118 return -1;
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 * 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
123 */
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
124 memset(&servaddr, 0, sizeof(servaddr));
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
125 servaddr.sin_family = AF_INET;
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
126 servaddr.sin_port = htons(6554);
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
127 servaddr.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
128
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
129 if (bind(s, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) {
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
130 close(s);
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
131 syslog(LOG_NOTICE, "socket_connect() can't bind socket: %s", strerror(errno));
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
132 return -1;
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 syslog(LOG_NOTICE, "socket_connect() using socket %d", s);
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
136 sock = s;
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
137 return sock;
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
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 #endif

mercurial