|
1 /***************************************************************************** |
|
2 * Copyright (C) 2008-2014 |
|
3 * |
|
4 * Michiel Broek <mbroek at mbse dot eu> |
|
5 * |
|
6 * This file is part of the mbsePi-apps |
|
7 * |
|
8 * This is free software; you can redistribute it and/or modify it |
|
9 * under the terms of the GNU General Public License as published by the |
|
10 * Free Software Foundation; either version 2, or (at your option) any |
|
11 * later version. |
|
12 * |
|
13 * mbsePi-apps is distributed in the hope that it will be useful, but |
|
14 * WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
16 * General Public License for more details. |
|
17 * |
|
18 * You should have received a copy of the GNU General Public License |
|
19 * along with EC-65K; see the file COPYING. If not, write to the Free |
|
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
|
21 *****************************************************************************/ |
|
22 |
|
23 |
|
24 #include "../lib/mbselib.h" |
|
25 #include "server.h" |
|
26 |
|
27 |
|
28 extern bool my_shutdown; |
|
29 extern bool debug; |
|
30 extern int lcdHandle; |
|
31 extern unsigned char lcdbuf[MAX_LCDS][20][4]; |
|
32 |
|
33 |
|
34 int sock = -1; |
|
35 |
|
36 |
|
37 char *exe_cmd(char *); |
|
38 |
|
39 |
|
40 char *exe_cmd(char *cmd) |
|
41 { |
|
42 static char obuf[1024]; |
|
43 int i; |
|
44 |
|
45 if (strncmp(cmd, "lcd", 3) == 0) { |
|
46 for (i = 0; i < 20; i++) { |
|
47 obuf[i] = lcdbuf[lcdHandle][i][0]; |
|
48 obuf[i+20] = lcdbuf[lcdHandle][i][1]; |
|
49 obuf[i+40] = lcdbuf[lcdHandle][i][2]; |
|
50 obuf[i+60] = lcdbuf[lcdHandle][i][3]; |
|
51 } |
|
52 obuf[80] = '\0'; |
|
53 return obuf; |
|
54 } |
|
55 |
|
56 return (char *)"ERROR"; |
|
57 } |
|
58 |
|
59 |
|
60 |
|
61 void do_cmd(char *cmd) |
|
62 { |
|
63 char buf[1024]; |
|
64 int slen, tries = 0; |
|
65 |
|
66 if (debug) |
|
67 fprintf(stdout, "do_cmd(%s)\n", cmd); |
|
68 |
|
69 snprintf(buf, 1024, "%s", exe_cmd(cmd)); |
|
70 |
|
71 if (debug) |
|
72 fprintf(stdout, "do_cmd() reply=\"%s\" len=%d\n", buf, strlen(buf)); |
|
73 |
|
74 for (;;) { |
|
75 // slen = sendto(sock, buf, strlen(buf), 0, (struct sockaddr *)&from, fromlen); |
|
76 |
|
77 if (debug) |
|
78 fprintf(stdout, "do_cmd() slen=%d tries=%d %s\n", slen, tries, strerror(errno)); |
|
79 // if (slen == -1) |
|
80 // syslog(LOG_NOTICE, "do_cmd(): sendto error %d %s", tries, from.sun_path); |
|
81 else if (slen != strlen(buf)) |
|
82 syslog(LOG_NOTICE, "do_cmd(): send %d of %d bytes, try=%d", slen, strlen(buf), tries); |
|
83 else |
|
84 return; |
|
85 tries++; |
|
86 if (tries == 3) |
|
87 return; |
|
88 else |
|
89 sleep(1); |
|
90 } |
|
91 } |
|
92 |
|
93 |