Dieses Kapitel beschreibt die Programme mit denen die Parameterdateien geladen werden.
Das Programm datus.c sieht wie folgt aus:
/*
** $Id: tr.c,v 1.0
**
** File: datus.c
** Author: H. Schön
**
** Abstract: Konfiguration von PADs der Firma Datus
**
**
#
# Copyright (C) 2000 Heimo Schön <heimo.schoen@gmx.at>
#
# This program 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.
#
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <assert.h>
#include <signal.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>
// -----------------------------------------------------------------------
int inputpid=0;
static int source_fh = 0; // Filehandle
static int input_fh = 0; // Filehandle
static int out_fh = 0; // Filehandle
static int log_fh = 0; // Filehandle
unsigned char stty_buffer[10000];
unsigned char out_buffer[10000];
unsigned char source_buffer[10000];
// -----------------------------------------------------------------------
void p_usage()
{
fprintf(stderr, "\ndatus v0.1 - (C) 2000 by Heimo Schön <heimo.schoen@gmx.at>\n");
fprintf(stderr, "This program is distributed under the terms of GPL.\n\n");
fprintf(stderr, " datus <command-file> <device>\n");
fprintf(stderr, " \n");
fprintf(stderr, " <command-file> filename of a file with\n");
fprintf(stderr, " datus-commads; one command\n");
fprintf(stderr, " in each line\n");
fprintf(stderr, " \n");
fprintf(stderr, " <device> the serial device where datus can\n");
fprintf(stderr, " find the DATUS\n");
fprintf(stderr, " \n");
fprintf(stderr, " example: datus test /dev/ttyW7\n");
fprintf(stderr, " \n");
}
// -----------------------------------------------------------------------
void startinput()
{
unsigned char in_buffer[10000];
int rece = 0;
in_buffer[0] = 0;
if ( ( inputpid = fork() ) == 0 ) {
while (1) {
if ((rece = read(input_fh, in_buffer, 1024)) > 0) {
in_buffer[rece] = 0;
if (log_fh > 0)
write(log_fh, in_buffer, strlen(in_buffer));
fprintf(stdout, "%s", in_buffer);
in_buffer[0] = 0;
}
}
}
fprintf(stdout, "reader forked with pid %d\n", inputpid);
}
// -----------------------------------------------------------------------
void p_io()
{
int rece = 0;
char command[10000];
int com_p = 0;
while ( (rece = read(source_fh, source_buffer, 1)) == 1) {
if (source_buffer[0] == '\n') {
command[com_p] = 0;
if (command[0] != '#') {
sprintf(out_buffer, "%s\r",command);
write(out_fh, out_buffer, strlen(out_buffer));
com_p = 0;
sleep(2);
} else {
command[com_p] = '\n';
command[com_p+1] = 0;
if (log_fh > 0)
write(log_fh, command, strlen(command));
fprintf(stdout, "%s", command);
com_p = 0;
}
} else {
command[com_p] = source_buffer[0];
com_p++;
}
}
}
// -----------------------------------------------------------------------
int main (int argc, char *argv[])
{
if (argc >= 3) {
if (argc == 4)
log_fh = open (argv[3], O_WRONLY);
source_fh = open (argv[1], O_RDONLY);
out_fh = open (argv[2], O_WRONLY);
input_fh = open (argv[2], O_RDONLY);
sprintf(stty_buffer,
"stty 9600 -echo raw < %s ",
argv[2]);
fprintf(stdout,"%s\n",stty_buffer);
system(stty_buffer);
} else
out_fh = 0;
if (out_fh > 0) {
startinput(); // fork the reader process
p_io(); // the command process
kill(inputpid, SIGKILL);
} else {
p_usage();
}
}
Das dazugehörige Makefile finden Sie hier:
#
# Makefile for the datus configuration pakage
#
# Copyright (C) 2000 Heimo Schön <heimo.schoen@gmx.at>
#
# This program 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.
#
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
################# Options and programs for C-Program
CCOPTIONS = -pedantic -Wall -g
RM = rm -f
CP = cp
STRIP = strip
CC = gcc
DEPEND = makedepend
################## Sourcen and Objects für C-Program
OBJS = datus.o
SRCS = datus.c
################## Optionen für sgml-tools
OPT = --charset=latin --language=de --papersize=a4
##################
all: datus datus.stripped datus-howto.html datus-howto.ps datus-howto.txt datus-howto.tgz
sudo chown root.root datus
sudo chmod a+srw datus
sudo chown root.root datus.stripped
sudo chmod a+srw datus.stripped
cp datus-howto.* ~/public_html
datus: $(OBJS)
$(RM) $@
$(CC) -o $@ $(OBJS) $(CCOPTIONS)
datus.stripped: datus
$(CP) $< $@
$(STRIP) $@
strip:: datus.stripped
##################
clean::
$(RM) datus *.o *.html datus-howto.ps datus-howto.tgz datus-howto.txt
depend::
@if [ -n "$(SRCS)" ] ; then set -x;\
$(DEPEND) $(SRCS) ;\
fi
tags:
etags *.c
##################
datus-howto.html: datus-howto.sgml
sgml2html --language=deutsch -s 1 ${OPT} --imagebuttons datus-howto.sgml
datus-howto.ps: datus-howto.sgml
sgml2latex --language=deutsch --output=ps ${OPT} datus-howto.sgml
sgml2latex --language=deutsch --output=dvi ${OPT} datus-howto.sgml
sgml2latex --language=deutsch --output=tex ${OPT} datus-howto.sgml
rm -f texput.log
datus-howto.txt: datus-howto.sgml
sgml2txt --language=deutsch datus-howto.sgml
datus-howto.tgz: datus-howto.sgml
tar cvzf datus-howto.tgz *