Главная страница


ru.unix

 
 - RU.UNIX ----------------------------------------------------------------------
 From : Konstantin Katuev                    2:5020/400     23 Aug 2001  02:27:32
 To : All
 Subject : Re: Log ATC(com-port) -> file
 -------------------------------------------------------------------------------- 
 
 
 Hi,
 
 Vadym ANTSUT wrote:
 
 >
 > Привет АЛЛ!
 > Может кто зает как реализовать такую вещь!
 > Есть АТС которая выдает на ком порт свою статистику. Есть фря и есть
 
 желание
 
 > зделать онлайн статистику кто, куда кому и скока звонил.
 > Как заставить писать в файл то, что ему говорит АТС (подключеная к компу
 
 на
 
 > ком-порт). Или может где то есть такие вещи (под Вынь32 есть точно)
 > Спасибо!
 
 Когда-то сделал я вот такую примитвную штучку... Точно работает под
 Солярисом и Линуксом... Можно брать и править под свои нужды.
 
 Константин
 
 === Cut here ===
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <errno.h>
 #include <termios.h>
 #include <signal.h>
 
 int fd=0;
 int lfd=0;
 int n=0;
 
 void hooker(int sig) {
    char c;
    printf("\nComLoger: terminating signal received...");
 
    /* Get characters from port until NewLine is received. */
    while(1) {
         n=read(fd,&c,1);
         write(lfd,&c,1);
         if ( c == '\n' ) break;
    }
    printf("Cleanup done!\n");
    close(fd);
    close(lfd);
    exit(0);
 }
 
 main(int argc, char **argv) {
 pid_t pid;
 char devfile[20],logfile[80];
 char buf[82];
 struct termios options;
 
         printf("\n Com port logger v.0.0 by K.S.Katuev");
         printf("\n Copyright 1997 Far-Eastern Bank\n");
 
         strcpy(devfile,"/dev/tty03");
         strcpy(logfile,"/phone.calls");
 
         switch(argc) {
         case 3:
                 strcpy(devfile,argv[2]);
         case 2:
                 strcpy(logfile,argv[1]);
         case 1:
                 break;
         default:
                 printf("\nUsage: plc [[logfile] device]\n");
                 exit(1);
         }
         printf("\nDevice file: %s",devfile);
         printf("\n   Log file: %s\n",logfile);
 
         /* Make DAEMON */
 
         /* If executed from rc.d do not daemonize */
         if (getppid() == 1) goto NoDaemon;
 
         /* fork child process */
         if ( (pid=fork()) < 0 ) {
            printf("\nfork error...\n");
            exit(1);
         }
         else {
            /* parent exit */
            if (pid>0) exit(0);
         }
 
         /* detach from terminal */
         if (setsid()<0) {
            printf("\nsetsid() failed. Exiting.\n");
            exit(1);
         }
 
 NoDaemon:
         lfd=open(logfile, O_RDWR | O_NONBLOCK | O_CREAT | O_APPEND );
         if ( fd < 0 ) {
                 printf("\nError opening log file: %s\n",logfile);
                 exit(1);
         }
 
         fd=open(devfile, O_RDWR | O_NOCTTY | O_NDELAY );
         if ( fd < 0 ) {
                 printf("\nError opening serial device:\n");
                 exit(1);
         }
 
         n = fcntl(fd,F_GETFL,0);
         fcntl(fd,F_SETFL,n & ~O_NDELAY);
 
         tcgetattr(fd,&options);
         cfsetispeed(&options,B9600);
         cfsetospeed(&options,B9600);
         options.c_cflag |= (CLOCAL | CREAD);
         options.c_cflag &= ~PARENB;
         options.c_cflag &= ~CSTOPB;
         options.c_cflag &= ~CSIZE;
         options.c_cflag |= CS8;
         options.c_lflag = 0;
         options.c_iflag = IGNBRK;
         options.c_oflag = 0;
         options.c_cc[VMIN]=0;
         options.c_cc[VTIME]=10;
         tcsetattr(fd,TCSANOW,&options);
 
    signal(SIGTERM,hooker);
    signal(SIGINT,hooker);
 
    while(1) {
         n=read(fd,buf,80);
         write(lfd,buf,n);
    }
 
 /* this code is unreachable :-) */
 close(fd);
 }
 === End ===
 --
 --- ifmail v.2.15dev5
  * Origin: Far-Eastern Bank (2:5020/400)
 
 

Вернуться к списку тем, сортированных по: возрастание даты  уменьшение даты  тема  автор 

 Тема:    Автор:    Дата:  
 Log ATC(com-port) -> file   Vadym ANTSUT   22 Aug 2001 20:44:32 
 Re: Log ATC(com-port) -> file   Stepan Koltsov   22 Aug 2001 21:04:41 
 Re: Log ATC(com-port) -> file   Stepan Koltsov   22 Aug 2001 21:08:44 
 Re: Log ATC(com-port) -> file   Dmitry Glazov   22 Aug 2001 21:28:57 
 Re: Log ATC(com-port) -> file   Konstantin Katuev   23 Aug 2001 02:27:32 
Архивное /ru.unix/35901b2ff598.html, оценка 3 из 5, голосов 10
Яндекс.Метрика
Valid HTML 4.01 Transitional