/*************************************************************************** AtoD.c - description ------------------- begin : Tue Dec 2 2003 copyright : (C) 2003 by NZG email : ngustavson@emacinc.com ***************************************************************************/ /*************************************************************************** * * * 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 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /*! @defgroup AtoD AtoDread - AtoD.c This module is used to build the AtoDread application. AtoD read uses Ncurses to open up a window that displays the current value of all the AtoD ports(Internal and External) in real time. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define ATODNUM INTERNAL_ATOD_NUM +EXTERNAL_ATOD_NUM #define RPCOUNT 1//ncurses rows per counter #define ARGCHECK(num){if(argc<=num){printf("invalid number of arguements\n");help();return -1;}} #define OPENDEV(filed,dev){if((filed = open(dev, O_RDWR))<=0){printf("couldn't open %s\n",dev);return -1;}} #define YSTART 4 #define INTERNAL_X 3 #define DISPX_OFFSET 12 #define INTERNAL_DISP_X DISPX_OFFSET+INTERNAL_X #define EXTERNAL_X INTERNAL_X+DISPX_OFFSET +7 #define EXTERNAL_DISP_X DISPX_OFFSET+EXTERNAL_X //#define GEN_DEBUG /* #undef GENDEBUG #ifdef GEN_DEBUG #define GENDEBUG(fmt, args...) printf(## args) #else #define GENDEBUG(fmt, args...) #endif */ WINDOW *AtoDwindow; static void destroywindow(void) { GENDEBUG("destroying window\n"); delwin(AtoDwindow); endwin(); } static int help(void) { const char *help_table = "********************************************** *AtoDread * *Nathan Z. Gustavson * *Emac.inc * *"__DATE__" * *usage: * *AtoDread device * *ex * *AtoDread /dev/37e12 * **********************************************\n"; printf("%s",help_table); return 0; } //#define LINES //#define COLS static int InitWindow(WINDOW **window) { char channelstring[50]; int channel; char test[50]; //char *stringy = "stringy"; WINDOW *wmain; wmain = initscr(); start_color(); cbreak(); //if((wmain=newwin((RPCOUNT*ATODNUM),50, 0 , 0))==NULL) if((wmain=newwin(LINES,COLS, 0 , 0))==NULL) { GENDEBUG("couldn't create new window\n"); } init_pair(1, COLOR_BLACK, COLOR_GREEN); wattrset(wmain,COLOR_PAIR(1)); wbkgd(wmain,COLOR_PAIR(1)); werase(wmain); box(wmain, ACS_VLINE, ACS_HLINE); //if((internal_swin1 = subwin(win, h-2, sw, by+1, bx+sw-1)) == NULL); mvwaddstr(wmain, 1, 1, "AtoDread press q to exit"); mvwaddstr(wmain, YSTART-1, INTERNAL_X, "Internal AtoD"); mvwaddstr(wmain, YSTART-1, EXTERNAL_X, "External AtoD"); for(channel=0;channelInternal_AD[channel]); if(typemask&ATOD1RESPONSE) mvwprintw(AtoDwindow, RPCOUNT*(channel-INTERNAL_ATOD_NUM)+YSTART, EXTERNAL_DISP_X, "[%x] ",Cop->External_AD[channel - INTERNAL_ATOD_NUM]); //printf("channel %u = %x\r\n",channel,Cop->Internal_AD[channel]); wrefresh(AtoDwindow); typemask = 0; // printf("%x\n",Cop->Digital[port]); } } CopDeviceDestroy(Cop); return 0; } int main(int argc, char **argv) { int fd; //d_t process; ARGCHECK(1); OPENDEV(fd,argv[1]); InitWindow(&AtoDwindow); /* if(0>(process=fork()))//create child process { printf("couldn't fork process, aborting\n"); close(fd); return 0; } */ //if(!process)/*branch off child process*/ display_AtoD(fd); //getchar();/*wait for keypress*/ /*kill the child process*/ GENDEBUG("killing main AtoD thread\n"); //kill(process,SIGKILL); GENDEBUG("main window at %lu\n",(unsigned long)AtoDwindow); /*flush and close the port*/ GENDEBUG("closing %s\n",argv[1]); close(fd); destroywindow(); return 0; }