Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields   Related Pages  

AtoD.c

00001 /***************************************************************************
00002                           AtoD.c  -  description
00003                              -------------------
00004     begin                : Tue Dec 2 2003
00005     copyright            : (C) 2003 by NZG
00006     email                : ngustavson@emacinc.com
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00026 #include <stdlib.h>
00027 #include <stdio.h>
00028 #include <string.h>
00029 #include <sys/ioctl.h>
00030 #include <unistd.h>
00031 #include <sys/types.h>
00032 #include <asm/types.h>
00033 #include <sys/stat.h>
00034 #include <fcntl.h>
00035 #include <signal.h>
00036 #include <sched.h>
00037 #include <sys/resource.h>
00038 #include <sys/io.h>
00039 #include <E12user.h>
00040 #include <packet.h>
00041 #include <coprocessor.h>
00042 #include <counter.h>
00043 #include <curses.h>
00044 #define ATODNUM  INTERNAL_ATOD_NUM +EXTERNAL_ATOD_NUM
00045 #define RPCOUNT 1//ncurses rows per counter
00046 #define ARGCHECK(num){if(argc<=num){printf("invalid number of arguements\n");help();return -1;}}
00047 
00048 
00049 #define OPENDEV(filed,dev){if((filed = open(dev, O_RDWR))<=0){printf("couldn't open %s\n",dev);return -1;}}
00050 
00051 #define YSTART 4
00052 #define INTERNAL_X 3
00053 #define DISPX_OFFSET  12
00054 #define INTERNAL_DISP_X  DISPX_OFFSET+INTERNAL_X
00055 
00056 #define EXTERNAL_X  INTERNAL_X+DISPX_OFFSET +7
00057 #define EXTERNAL_DISP_X  DISPX_OFFSET+EXTERNAL_X
00058 
00059 //#define GEN_DEBUG
00060 
00061 /*
00062 #undef GENDEBUG
00063 #ifdef GEN_DEBUG
00064 #define GENDEBUG(fmt, args...) printf(## args)
00065 #else
00066 #define GENDEBUG(fmt, args...)
00067 #endif
00068 */
00069 
00070 WINDOW *AtoDwindow;
00071 static void destroywindow(void)
00072 {
00073 GENDEBUG("destroying window\n");
00074 delwin(AtoDwindow);
00075 endwin();
00076 }
00077 
00078 
00079 static int help(void)
00080 {
00081 const char *help_table = "**********************************************
00082 *AtoDread                                    *
00083 *Nathan Z. Gustavson                         *
00084 *Emac.inc                                    *
00085 *"__DATE__"                                 *
00086 *usage:                                      *
00087 *AtoDread device                             *
00088 *ex                                          *
00089 *AtoDread /dev/37e12                         *
00090 **********************************************\n";
00091 printf("%s",help_table);
00092 return 0;
00093 }
00094 
00095 //#define LINES
00096 //#define COLS
00097 
00098 static int InitWindow(WINDOW **window)
00099 {
00100 char channelstring[50];
00101 int channel;
00102 char test[50];
00103 //char *stringy = "stringy";
00104 WINDOW *wmain;
00105 
00106 wmain = initscr();
00107 start_color();
00108 cbreak();
00109 
00110 //if((wmain=newwin((RPCOUNT*ATODNUM),50, 0 , 0))==NULL)
00111 if((wmain=newwin(LINES,COLS, 0 , 0))==NULL)
00112 {
00113 GENDEBUG("couldn't create new window\n");
00114 }
00115 
00116 init_pair(1, COLOR_BLACK, COLOR_GREEN);
00117 wattrset(wmain,COLOR_PAIR(1));
00118 wbkgd(wmain,COLOR_PAIR(1));
00119 werase(wmain);
00120 box(wmain, ACS_VLINE, ACS_HLINE);
00121 
00122 //if((internal_swin1 = subwin(win, h-2, sw, by+1, bx+sw-1)) == NULL);
00123 
00124 mvwaddstr(wmain, 1, 1, "AtoDread press q to exit");
00125 mvwaddstr(wmain, YSTART-1, INTERNAL_X, "Internal AtoD");
00126 mvwaddstr(wmain, YSTART-1, EXTERNAL_X, "External AtoD");
00127 
00128 for(channel=0;channel<INTERNAL_ATOD_NUM ;channel++)
00129 {
00130 sprintf(channelstring,"channel %u",channel);
00131 mvwaddstr(wmain, RPCOUNT*channel+YSTART, INTERNAL_X, channelstring);
00132 }
00133 
00134 for(channel=0;channel<EXTERNAL_ATOD_NUM ;channel++)
00135 {
00136 sprintf(channelstring,"channel %u",channel);
00137 mvwaddstr(wmain, RPCOUNT*channel+YSTART, EXTERNAL_X, channelstring);
00138 }
00139 
00140 
00141 wrefresh(wmain);
00142 nodelay(wmain,TRUE);
00143 
00144 
00145 //mvwaddstr(wmain, RPCOUNT*16+2, 3, "getchin");
00146 //wrefresh(wmain);
00147 
00148 //sprintf(test,"window at %lu\n",(unsigned long)wmain);
00149 //mvwaddstr(wmain, 0, 3, test);
00150 
00151 *window = wmain;
00152 
00153 return 0;
00154 }
00155 
00156 
00157 
00158 static int display_AtoD(int fd)
00159 {
00160 int channel;
00161 Cop_Data *Cop = CopDeviceCreate(0);
00162 __u32 typemask=0;
00163 int rxnum=0;
00164 char buffer[50];
00165 
00166 //InitWindow(AtoDwindow);
00167 
00168 //atexit(destroywindow);
00169 signal(SIGKILL,SIG_DFL);/*install kill handler if needed*/
00170 
00171 GENDEBUG("window at %lu\n",(unsigned long)AtoDwindow);
00172 
00173 //mvwaddstr(AtoDwindow, RPCOUNT*16+2, 3, "getchin");
00174 //wrefresh(AtoDwindow);
00175 while(wgetch(AtoDwindow)!='q')
00176 {
00177   for(channel=0;channel<ATODNUM;channel++)
00178   {
00179     E12_AtoD_Req(fd, channel);//request data
00180       while(!(typemask&(ATOD0RESPONSE|ATOD1RESPONSE)))
00181         {//disregard any other data
00182           rxnum =read(fd,buffer,sizeof(buffer));//read data
00183           typemask = E12_Packet_Route(Cop,buffer, rxnum);//dig for AtoD data
00184         }
00185 //printf("data returned\n");
00186 if(typemask&ATOD0RESPONSE)
00187   mvwprintw(AtoDwindow, RPCOUNT*channel+YSTART, INTERNAL_DISP_X, "[%x]  ",Cop->Internal_AD[channel]);
00188 
00189 if(typemask&ATOD1RESPONSE)
00190   mvwprintw(AtoDwindow, RPCOUNT*(channel-INTERNAL_ATOD_NUM)+YSTART, EXTERNAL_DISP_X, "[%x]  ",Cop->External_AD[channel - INTERNAL_ATOD_NUM]);
00191 
00192 //printf("channel %u = %x\r\n",channel,Cop->Internal_AD[channel]);
00193 wrefresh(AtoDwindow);
00194 typemask = 0;
00195 
00196  //   printf("%x\n",Cop->Digital[port]);
00197   }
00198 }
00199 CopDeviceDestroy(Cop);
00200 return 0;
00201 }
00202 
00203 
00204 
00205 
00206 int main(int argc, char **argv)
00207 {
00208 int fd;
00209 //d_t process;
00210 
00211 ARGCHECK(1);
00212 OPENDEV(fd,argv[1]);
00213 
00214 InitWindow(&AtoDwindow);
00215 
00216 /*
00217 if(0>(process=fork()))//create child process
00218   {
00219     printf("couldn't fork process, aborting\n");
00220     close(fd);
00221     return 0;
00222   }
00223 */
00224 
00225 //if(!process)/*branch off child process*/
00226   display_AtoD(fd);
00227 
00228 //getchar();/*wait for keypress*/
00229 
00230 /*kill the child process*/
00231 GENDEBUG("killing main AtoD thread\n");
00232 //kill(process,SIGKILL);
00233 
00234 GENDEBUG("main window at %lu\n",(unsigned long)AtoDwindow);
00235 /*flush and close the port*/
00236 GENDEBUG("closing %s\n",argv[1]);
00237 close(fd);
00238 destroywindow();
00239 return 0;
00240 }
00241 
00242 
00243 
00244 
00245 
00246 
00247 
00248 

Generated on Thu Jan 8 09:51:00 2004 for PCM-37e12 by doxygen1.2.15