00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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
00060
00061
00062
00063
00064
00065
00066
00067
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
00096
00097
00098 static int InitWindow(WINDOW **window)
00099 {
00100 char channelstring[50];
00101 int channel;
00102 char test[50];
00103
00104 WINDOW *wmain;
00105
00106 wmain = initscr();
00107 start_color();
00108 cbreak();
00109
00110
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
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
00146
00147
00148
00149
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
00167
00168
00169 signal(SIGKILL,SIG_DFL);
00170
00171 GENDEBUG("window at %lu\n",(unsigned long)AtoDwindow);
00172
00173
00174
00175 while(wgetch(AtoDwindow)!='q')
00176 {
00177 for(channel=0;channel<ATODNUM;channel++)
00178 {
00179 E12_AtoD_Req(fd, channel);
00180 while(!(typemask&(ATOD0RESPONSE|ATOD1RESPONSE)))
00181 {
00182 rxnum =read(fd,buffer,sizeof(buffer));
00183 typemask = E12_Packet_Route(Cop,buffer, rxnum);
00184 }
00185
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
00193 wrefresh(AtoDwindow);
00194 typemask = 0;
00195
00196
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
00210
00211 ARGCHECK(1);
00212 OPENDEV(fd,argv[1]);
00213
00214 InitWindow(&AtoDwindow);
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226 display_AtoD(fd);
00227
00228
00229
00230
00231 GENDEBUG("killing main AtoD thread\n");
00232
00233
00234 GENDEBUG("main window at %lu\n",(unsigned long)AtoDwindow);
00235
00236 GENDEBUG("closing %s\n",argv[1]);
00237 close(fd);
00238 destroywindow();
00239 return 0;
00240 }
00241
00242
00243
00244
00245
00246
00247
00248