46 * Debian ships v2.0.3, on Slackware we have 2.4.0 and there |
47 * Debian ships v2.0.3, on Slackware we have 2.4.0 and there |
47 * are lots of changes in the api. |
48 * are lots of changes in the api. |
48 */ |
49 */ |
49 #define MAX_MESSAGE_QUEUE 512 |
50 #define MAX_MESSAGE_QUEUE 512 |
50 |
51 |
|
52 #define WS_INBUF 2048 |
|
53 |
|
54 |
51 /* |
55 /* |
52 * one of these created for each message |
56 * one of these created for each message |
53 */ |
57 */ |
54 struct a_message { |
58 struct a_message { |
55 void *payload; /* is malloc'd */ |
59 void *payload; /* is malloc'd */ |
64 |
68 |
65 static int callback_ws(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len) |
69 static int callback_ws(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len) |
66 { |
70 { |
67 struct per_session_data__lws_mirror *pss = (struct per_session_data__lws_mirror *)user; |
71 struct per_session_data__lws_mirror *pss = (struct per_session_data__lws_mirror *)user; |
68 int n, m; |
72 int n, m; |
69 char buf[513]; |
73 char buf[WS_INBUF + 1]; |
70 |
74 |
71 switch (reason) { |
75 switch (reason) { |
72 |
76 |
73 case LWS_CALLBACK_ESTABLISHED: { |
77 case LWS_CALLBACK_ESTABLISHED: { |
74 ws_clients++; |
78 ws_clients++; |
114 case LWS_CALLBACK_RECEIVE: |
118 case LWS_CALLBACK_RECEIVE: |
115 |
119 |
116 memcpy(buf, in, len); |
120 memcpy(buf, in, len); |
117 buf[len] = '\0'; |
121 buf[len] = '\0'; |
118 syslog(LOG_NOTICE, "ws: reveived %ld bytes %s", len, buf); |
122 syslog(LOG_NOTICE, "ws: reveived %ld bytes %s", len, buf); |
119 if (strncmp(buf, (char *)"{\"device\":\"co2meters\",", 22) == 0) { |
123 if (strncmp(buf, (char *)"{\"device\":\"fermenters\",", 23) == 0) { |
|
124 fermenter_ws_receive(buf); |
|
125 } else if (strncmp(buf, (char *)"{\"device\":\"co2meters\",", 22) == 0) { |
120 co2meter_ws_receive(buf); |
126 co2meter_ws_receive(buf); |
121 } |
127 } |
122 |
128 |
123 break; |
129 break; |
124 |
130 |
135 } |
141 } |
136 |
142 |
137 |
143 |
138 |
144 |
139 static struct lws_protocols protocols[] = { |
145 static struct lws_protocols protocols[] = { |
140 { "bmsd-protocol", callback_ws, sizeof(struct per_session_data__lws_mirror), 512 }, |
146 { "bmsd-protocol", callback_ws, sizeof(struct per_session_data__lws_mirror), WS_INBUF }, |
141 { NULL, NULL, 0, 0 } /* terminator */ |
147 { NULL, NULL, 0, 0 } /* terminator */ |
142 }; |
148 }; |
143 |
149 |
144 |
150 |
145 /* |
151 /* |