Weiter Zurück Inhalt

7. automatic configuring

7.1 Overview

In the following chapters you find a small C-Program for auto configure the APD-2. There is also the Makefile the startscript and the inputscript which is read from the C-program rad.c.

7.2 rad.c

/* 
* rad.c
*
* input parser for PAD-configuration scripts
* ==========================================
*
#
# Copyright (C) 1999 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, "  \n");
  fprintf(stderr, "  rad <command-file> <device>\n");
  fprintf(stderr, "  \n");
  fprintf(stderr, "       <command-file> filename of a file with\n");
  fprintf(stderr, "                      PAD-parameters; one command\n");
  fprintf(stderr, "                      in each line\n");
  fprintf(stderr, "  \n");
  fprintf(stderr, "       <device>       the serial device where rad can\n");
  fprintf(stderr, "                      find the PAD\n");
  fprintf(stderr, "  \n");
  fprintf(stderr, "  example:  rad 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();
  }  
}
     

7.3 Makefile

The following listing should be copied into a file named Makefile. Afterwards you can type make clean ; make all ; make strip

      LDOPTIONS = -pedantic -Wall -g -DYY_SKIP_YYWRAP


                    OBJS = rad.o
                    SRCS = rad.c

all:    rad
        sudo chown root rad
        sudo chmod a+srw rad
 
rad:  $(OBJS) $(DEPLIBS)
        $(RM) $@
        $(CC) -o $@ $(LDENTRY)  $(OBJS) $(LDOPTIONS)  $(LIBS) $(LDLIBS) $(EXTRA_LOAD_FLAGS)

rad.stripped: rad
        $(CP) $< $@
        $(STRIP) $@

strip:: rad.stripped

clean::
        $(RM) rad *.o

depend::
        @if [ -n "$(SRCS)" ] ; then set -x;\
        $(DEPEND) $(DEPENDFLAGS) $(SRCS) ;\
        fi
     

7.4 configuration script makerad

Copy the following lines into a file named makerad. Dont´t forget to chmod the script: chmod a+x makerad

#! /bin/bash
#
# makerad - configuring a RAD-PAD
#
# Copyright (C) 1999 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.
#

if [ $1 ] ; then
  if [ -e /dev/$1 ] ; then
    echo Send DATUS config to device /dev/$1
    export DATDEV=/dev/$1

        rad rad.cmd $DATDEV | tee rad.log

  else
    echo Could not find device /dev/$1
    echo "    example : $0 ttyS0"
  fi;
fi;
     

7.5 Parameterscript

Here you can find the complete Parameterscript for configuring the APD-2. Check if you didn´t delete blank lines in the following file. The blank lines are very importent, because they generate a single CARIAGE-RETURN for navigating in the PAD-Menues. After the configuration is finished you have no connection to the configuration menue. You have to reset the APD-2 and to connect it to the testapplication.

#
# commandfile for configuring a RAD - PAD
#
# Copyright (C) 1999 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.
#
#
# Switching the PAD to Configuration Mode
C0

1
#
# =========================================
#
# Configuring the X.25 Link
3
3
# Par 18 to 3 = Lowest incoming LCN = 3
18
3
# Par 14 to 16 = assume PVC down on sync
#14
#16
# save it
s



#
#
# =========================================
#
# Making the PVC configuration
5
# add PVC 
1
# add PVC 1
1
# local PVC
1
# Line (channel) 2
1
2
# Link (channel) 1
2
1
# LCN logical channel number 1
3
1
# save and back again
s



#
#
#
# add PVC 
1
# add PVC 2
2
# local PVC
1
# Line (channel) 3
1
3
# Link (channel) 1
2
1
# LCN logical channel number 1
3
2
# save and back again
s






#
#
# =========================================
#
# back to config menue
1
# Update Profile 2
2
3
2
# Par 4 auf 1
4
2
# Par 5 auf 0
5
0
# Par 7 auf 0
7
0
# Par 11 auf 15
11
15
# Par 12 auf 0
12
0
# Par 110 auf 1
#110
#1
# save and out
s






#
#
# =========================================
#
# load channel 2 and 3 with Profile 2
#
# back to config menue
1
# load channel 2 with Profile 2
1
3
2
1
2
# save and out
s







# back to config menue
1
# load channel 3 with Profile 2
1
3
3
1
2
# save and out
s






# Action done
#
# =========================================
     


Weiter Zurück Inhalt