thermferm/server.c

Sun, 18 May 2014 21:27:07 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 18 May 2014 21:27:07 +0200
changeset 42
01b96a24ae7c
child 43
24e731bb2e08
permissions
-rw-r--r--

Corrected missing and obsolete files

/*****************************************************************************
 * Copyright (C) 2008-2014
 *   
 * Michiel Broek <mbroek at mbse dot eu>
 *
 * This file is part of the mbsePi-apps
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2, or (at your option) any
 * later version.
 *
 * mbsePi-apps is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with EC-65K; see the file COPYING.  If not, write to the Free
 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 *****************************************************************************/


#include "../lib/mbselib.h"
#include "server.h"


extern bool		my_shutdown;
extern bool		debug;
extern int		lcdHandle;
extern unsigned char	lcdbuf[MAX_LCDS][20][4];


int			sock = -1;


char *exe_cmd(char *);


char *exe_cmd(char *cmd)
{
    static char obuf[1024];
    int         i;

    if (strncmp(cmd, "lcd", 3) == 0) {
	for (i = 0; i < 20; i++) {
	    obuf[i]    = lcdbuf[lcdHandle][i][0];
	    obuf[i+20] = lcdbuf[lcdHandle][i][1];
	    obuf[i+40] = lcdbuf[lcdHandle][i][2];
	    obuf[i+60] = lcdbuf[lcdHandle][i][3];
	}
	obuf[80] = '\0';
	return obuf;
    }

    return (char *)"ERROR";
}



void do_cmd(char *cmd)
{
    char    buf[1024];
    int     slen, tries = 0;

    if (debug)
	fprintf(stdout, "do_cmd(%s)\n", cmd);

    snprintf(buf, 1024, "%s", exe_cmd(cmd));

    if (debug)
	fprintf(stdout, "do_cmd() reply=\"%s\" len=%d\n", buf, strlen(buf));

    for (;;) {
//	slen = sendto(sock, buf, strlen(buf), 0, (struct sockaddr *)&from, fromlen);

	if (debug)
	    fprintf(stdout, "do_cmd() slen=%d tries=%d %s\n", slen, tries, strerror(errno));
//	if (slen == -1)
//	    syslog(LOG_NOTICE, "do_cmd(): sendto error %d %s", tries, from.sun_path);
	else if (slen != strlen(buf))
	    syslog(LOG_NOTICE, "do_cmd(): send %d of %d bytes, try=%d", slen, strlen(buf), tries);
	else
	    return;
	tries++;
	if (tries == 3)
	    return;
	else
	    sleep(1);
    }
}

mercurial