/* MicroMeter data acquisition software for UNIX (POSIX) by Dan D'Andrea (c) 1999 MicroMeter corporation */ #include #include #include #include #include /* Define device to use and speed */ #define BAUDRATE B300 #define MODEMDEVICE "/dev/ttyS1" /* This is POSIX source */ #define _POSIX_SOURCE 1 /* Begin program */ main() { /* Setup variables */ int fd, danread, logfile, danwrite, g, h, i, commas, cti, presenti, overflowi, usagei; char dan; char ct[10], present[10], usage[10], overflow[10]; struct termios oldtio,newtio; printf("MicroMeter data acquisition software for UNIX\n\r\n\r"); /* Open up the device the MicroMeter is attached to */ fd = open(MODEMDEVICE, O_RDONLY | O_NOCTTY | O_NONBLOCK); if (fd <0) {perror(MODEMDEVICE); exit(-1); } /* save current serial port settings */ tcgetattr(fd,&oldtio); /* clear struct for new port settings */ bzero(&newtio, sizeof(newtio)); /* BAUDRATE: Set bps rate. You could also use cfsetispeed and cfsetospeed. CRTSCTS : output hardware flow control (only used if the cable has all necessary lines. See sect. 7 of Serial-HOWTO) CS8 : 8n1 (8bit,no parity,1 stopbit) CLOCAL : local connection, no modem contol CREAD : enable receiving characters */ newtio.c_cflag = BAUDRATE | CS8 | CREAD | CLOCAL; /* IGNPAR : ignore bytes with parity errors ICRNL : map CR to NL (otherwise a CR input on the other computer will not terminate input) otherwise make device raw (no other input processing) */ newtio.c_iflag = IGNPAR | ICRNL; /* Raw output. */ newtio.c_oflag = 0; /* ICANON : enable canonical input disable all echo functionality, and don't send signals to calling program */ newtio.c_lflag = ICANON; /* now clean the modem line and activate the settings for the port */ tcflush(fd, TCIFLUSH); tcsetattr(fd,TCSANOW,&newtio); /* delete old logfile */ system("rm -f mcap.html"); /* open logfile for output */ logfile = open("mcap.html",O_RDWR | O_CREAT,0); /* create initial HTML data for mcap.html */ write(logfile,"\n",7); write(logfile,"\n",8); write(logfile,"MicroMeter data captured from mcap.c\n",37); write(logfile,"\n",9); write(logfile,"\n",7); /* Start main loop */ while (h < 16) { h++; startover: /* Clear out arrays */ for (g = 0; g <= 10; g++) ct[g] = 0; for (g = 0; g <= 10; g++) present[g] = 0; for (g = 0; g <= 10; g++) usage[g] = 0; for (g = 0; g <= 10; g++) overflow[g] = 0; /* initialize variables */ i = 0; commas = 0; cti = 0; presenti = 0; usagei = 0; overflowi = 0; /* read data from MicroMeter */ while(1) { danread = read(fd,&dan,1); if (danread == 1) { if (dan == '\n') break; if (dan == ',') commas++; else { if (commas == 0) { ct[cti] = dan; cti++; } if (commas == 1) { present[presenti] = dan; presenti++; } if (commas == 2) { usage[usagei] = dan; usagei++; } if (commas == 3) { overflow[overflowi] = dan; overflowi++; } } } } if (commas == 0) goto startover; ct[cti+1] = '\0'; present[presenti+1] = '\0'; usage[usagei+1] = '\0'; overflow[overflowi+1] = '\0'; printf("CT: %s - Present Usage: %s - Usage Over Time: %s - Overflow: %s\n\r",ct,present,usage,overflow); /* Write out HTML */ write(logfile,"

CT: ",7); write(logfile,&ct,strlen(ct)); write(logfile," - Present Usage: ",18); write(logfile,&present,strlen(present)); write(logfile," - Usage Over Time: ",20); write(logfile,&usage,strlen(usage)); write(logfile," - Overflow: ",13); write(logfile,&overflow,strlen(overflow)); write(logfile,"\n",1); } write(logfile,"\n",8); write(logfile,"\n",8); close(logfile); /* restore the old port settings */ tcsetattr(fd,TCSANOW,&oldtio); } /* EOF */ /*'DIS - (C) 1994 - microMETER,Inc. C version 1999*/ #include #include #include #include #include #include #include #include #include #include /*....0....+....0....+....0....+....0....+....0....+....0....+....0....+*/ /* must allow extra byte in all dimensions for null terminator*/ char CMA[2] = ","; char PL1[12] = " "; /*....0....+....0....+....0....+....0....+....0....+....0....+....0....+*/ char PL2[53] = " (C) 1999 - microMETER Corp. - v 1.09L "; char PL3[2] = " "; char PL4[2] = " "; char td[20]; char CRLF[4] = "\n\r"; char str1[30] = " "; char str2[30] = " "; static int istr[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; int C00 = 0; int C01 = 1; int C02 = 2; int C03 = 3; int C04 = 4; int C05 = 5; int C06 = 6; int C07 = 7; int C2 = 7; int C3 = 0; float PRICE = 6.3,SCAL,SCA2,SCA3,KWH;int COL=0; /*'0 blk 1 blu 2 grn 3 cya 4 red 5 mag 6 yel 7 wht*/ char FIL1[10] = "MICRO.DAT" ;int fil1; char FIL2[8] = "CT.DAT" ;int fil2; char FIL3[8] = "CT.CAP" ;int fil3; char FIL4[8] = "CT.RES" ;int fil4; char FIL5[8] = "CT.DTE" ;int fil5; char FIL6[10] = "MICRO.PRT" ;int fil6; char FIL7[11] = "MICRO2.CAP";int fil7; char FIL8[12] = "MICRO.TXT" ;int fil8; char TXT1S[78]; char SBS[78]; char DBS[78]; int SW = 1; float A[16], B[16], C[16], D[16], E[16], F[16], G[16], TA[6], TB[16]; float BK[16], PF[16], LV[16], AA[16], BB[16], EE[16], FF[16], GG[16]; float G2; char *TS[16][30]; char *DTES[16][30]; int i,j,k,a,b,c,d,e; void S780(); void S850(); void S960(); void S590(); //microMETER data acquisition software for UNIX (POSIX) by Dan D'Andrea int fd, danread, danwrite; char dan; int logfile, g, h, commas, cti, presenti, usagei, overflowi; char ct[10], present[10], usage[10], overflow[10]; void readmm(); int argc;char *argv[]; int recl=22; main(argc,argv){ // while(--argc>0) printf((argc>1)?"%s ":"%s\n",++argv); // system("clear"); puts geek in html S780(); i=0;while(i<78){SBS[i]=055;DBS[i]=075;i++;}/*index starts w 0,octal*/ // PL3[1]= 174; printf("%s%s%s%s\n",PL1,PL3,PL2,PL3); //S130: //'RECONCILE LOOP //printf("debug1 \n\r"); S850(); S590(); //OPEN "A", #1, FIL6$ TA[1] = 0; TA[2] = 0; TA[3] = 0; TA[4] = 0; TA[5] = 0; printf("%s\n",TXT1S); //printf("<> microMETER <> - System Summary as of %s",td); printf("../micromtr/mm02 - System Summary as of %s",td); printf(" @%*.*f",5,2,PRICE); printf(" cts/kwh\n"); printf("%s\n",DBS); if (SW == 1) { printf(" # Circuit amps kwh "); printf(" amt %% reset \n");} if (SW == 2) { printf(" # Circuit kw kwh "); printf(" amt %% prev curr \n");} printf("%s\n",SBS); printf("\n"); i=0;while(i<16){ TA[1] = C[i] + TA[1]; TA[2] = A[i] + TA[2]; TA[3] = G[i] + TA[3]; i++; } i=0;while(i<16){ TB[i] = C[i] / (TA[1] + 1E-10) * 100; if(SW == -1){A[i] = A[i] * LV[i] * PF[i] / 1000;} if(SW == 1){printf("%s %*.*f %*.*f %*.*f %*.*f %s\n", TS[i],4,1,A[i],9,1,G[i],10,2,C[i],3,0,TB[i],DTES[i]);} G2 = GG[i] + G[i]; TA[4] = TA[4] + GG[i]; TA[5] = TA[5] + G2; if(SW == -1){printf("%s %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f\n", TS[i],4,1,A[i],9,1,G[i],10,2,C[i],3,0,TB[i],10,1,GG[i], 10,1,G2);} i++; } printf(" totals %*.*f %*.*f %*.*f 100\n", 7,1,TA[2],9,1,TA[3],10,2,TA[1]); /* PRINT "MENU: Enter 0-exit 1-alt display kwh 2-reset 3-setup 4-reconcile" IF LEN(COMMAND$) > 0 THEN REC$ = COMMAND$: GOTO S588 INPUT REC$ S588: IF REC$ = "0" THEN CLOSE : COLOR 7, 0, 0: CLS : SYSTEM IF REC$ = "1" THEN SW = -1 * SW IF REC$ = "2" THEN CLOSE : CHAIN "RESET" IF REC$ = "3" THEN CLOSE : CHAIN "SETUP" IF REC$ = "4" THEN GOSUB S960: CLOSE : GOTO S130 GOTO S130 */ printf("\n\r");/*flush*/ }/*main*/ void S590(){ //'redisplay - unordered files //Using Dan's code in readmm(), but s/b able to do in 1 or 2 lines. fil3=open(FIL3,O_RDONLY,0); fd=fil3; i=0;while(i<16){i++; readmm(); // k=read(fil3,&str1,recl); // j=0;while(j #include #include #include #include #include #include /* baudrate settings are defined in , which is included by */ #define BAUDRATE B300 /* change this definition for the correct port */ #define MODEMDEVICE "/dev/ttyS0" #define _POSIX_SOURCE 1 /* POSIX compliant source */ #define PHONE_NUMBER "atdt8271383\r" #define CL$ "MCAP 1 222222 0........9ABCDEF MATD8271383" /*....0....+....0....+....0....+....0....+....0....+....0....+....0....+*/ /* must allow extra byte in all dimensions for null terminator*/ char CMA[2] = ","; //char PL1[15] = " x=exit "; char PL1[11] = " "; /*....0....+....0....+....0....+....0....+....0....+....0....+....0....+*/ char PL2[53] = " (C) 1999 - microMETER Corp. - v 1.02L "; char PL3[2] = " "; char PL4[2] = " "; char td[20] = "10:20:43 03/25/1999"; char CRLF[4] = "\n\r"; char time_filler[14]=" "; struct tm *timeptr; time_t timer; int i,j,k,x,fil1,fil2; int A,B,C,D; //char itoa(const int *x); char y,SEL[2] = "0"; int fd, danread, danwrite; char dan; struct termios oldtio,newtio; int logfile, g, h, commas, cti, presenti, usagei, overflowi; char ct[10], present[10], usage[10], overflow[10]; void readmm(); main (int argc,char *argv[]){ // int argc;char *argv[]; system("clear"); //printf("\n\r%s",*argv); //strcpy(td,*argv); //printf("\n\r%s",td); while(--argc>0) printf((argc>1)?"%s ":"%s\n",++*argv); /*K&R*/ // PL3[1]= 174; //SEL[1] = "0"; printf("\n\r%s%s%s%s",PL1,PL3,PL2,PL3); printf("\n\rMCAPture program - Enter modem AT commands or"); printf("\n\r x - continue y - repeat dial z - abort"); printf("\n\r"); printf("\n\rMCAPture program - Unit selected = %s",SEL); printf("\n\rPC: time date mM: CT#, B, C, D"); fil1 = open("CT.CAP",O_RDWR | O_CREAT,0); fil2 = open("MICRO2.CAP",O_RDWR | O_CREAT,0); // Open modem device for reading and writing and not as controlling tty // because we don't want to get killed if linenoise sends CTRL-C. fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK ); if (fd <0) {perror(MODEMDEVICE); exit(-1); } tcgetattr(fd,&oldtio); /* save current serial port settings */ bzero(&newtio, sizeof(newtio)); /* clear struct for new port settings*/ newtio.c_cflag = BAUDRATE | CS8 | CREAD | CRTSCTS | CLOCAL; newtio.c_iflag = IGNPAR | ICRNL; newtio.c_oflag = 0; newtio.c_lflag = ICANON; //now clean the modem line and activate the settings for the port tcflush(fd, TCIFLUSH); tcsetattr(fd,TCSANOW,&newtio); danwrite = write(fd,"atm1l3\r",7); sleep(1); danwrite = write(fd,PHONE_NUMBER,strlen(PHONE_NUMBER)); /* determine if connected or not, if not loop dialing sequence */ while(1) { danread = read(fd,&dan,1); if (dan == ',') { /* bypass modem by picking up 1st comma from mM. */ //printf("\n\rConnected to microMETER\n\r"); break; } } k=0; while(k<1) {k=read(fd,&dan,1);} sleep(1); /*discard 1st read*/ tcflush(fd, TCIFLUSH); tcsetattr(fd,TCSANOW,&newtio); i=0; while(i<16){i++; //date logic from MMICAPPG time(&timer); timeptr = localtime(&timer); strftime(td,sizeof(td),"%H:%M:%S %m-%d-%Y",timeptr); readmm(); printf("\n\r%s %u, %u, %u, %u",td,A,B,C,D); write(fil2,&td,19); write(fil2,&CRLF,2); write(fil1,&ct,strlen(ct)); write(fil1,CMA,1); write(fil1,&present,strlen(present));write(fil1,CMA,1); write(fil1,&usage,strlen(usage)); write(fil1,CMA,1); write(fil1,&overflow,strlen(overflow)); write(fil1,"\n",1); } printf("\n\r%s%s%s%s",PL1,PL3,PL2,PL3); close(fil1); close(fil2); /* restore the old port settings */ tcsetattr(fd,TCSANOW,&oldtio); printf("\n\r"); }/*main*/ void readmm(){ h = 0; while (h < 16) {h++; startover: for (g = 0; g <= 10; g++) ct[g] = 0; for (g = 0; g <= 10; g++) present[g] = 0; for (g = 0; g <= 10; g++) usage[g] = 0; for (g = 0; g <= 10; g++) overflow[g] = 0; } commas = 0;cti = 0;presenti = 0;usagei = 0;overflowi = 0; while(1) { danread = read(fd,&dan,1); if (danread == 1) { if (dan == '\n') break; if (dan == ',') commas++; else { if (commas == 0) { ct[cti] = dan; cti++; } if (commas == 1) { present[presenti] = dan; presenti++; } if (commas == 2) { usage[usagei] = dan; usagei++; } if (commas == 3) { overflow[overflowi] = dan; overflowi++; } } } } if (commas == 0) goto startover; ct[cti+1] = '\0'; present[presenti+1] = '\0'; usage[usagei+1] = '\0'; overflow[overflowi+1] = '\0'; A=atoi(ct);B=atoi(present);C=atoi(usage);D=atoi(overflow); } /*readmm*/ #include #include int popup(int row, int col, char *menu[]); char *menu[] = { "Notepad", /* choice 0 */ "Calculator", /* choice 1 */ "cAlendar", /* choice 2 */ "ascii Table", /* choice 3 */ NULL }; /* terminator */ main() { int i, choice; clrscrn(); poscurs(14, 0); for (i = 0; i < 10; i++) printf("abcdefghijklmnopqrstuvwxyz\n"); choice = popup(16, 6, menu); if (choice == -1) printf("\nYou pressed the Esc key\n"); else printf("\nYour choice -> %s\n", menu[choice]); } /***************************************************************************** *PINELLAS PLANT - microMETER, Corp. system * ****************************************************************************** * MMICAPPG.C: Micro Meter Capture Program * * This program captures data from the microMETER, Corp. device * * and writes it into the capture and date-time files. * * * * Files: MMI.HLP - MMI System Help File * * CT.CAP - Data Capture File * * XX.CAP - Simulated Data Capture File * * MICRO2.CAP - Date-Time File * * * * Written By: Jim McClelland * * Date: 06/12/95 * ****************************************************************************** ****************************************************************************** * Change History * ****************************************************************************** * Date By Remarks Ch #* *-------- --- ---------------------------------------------------------- ----* * * *****************************************************************************/ /* Program include files */ #include "gn_attrb.h" #include "gr_color.h" #include "ky_codes.h" #include #include #include #include #include #include /* Runtime library prototypes */ char* an_input(unsigned,unsigned,unsigned,unsigned,char*); int ck_term(int); void ds_buff(unsigned,unsigned,unsigned,unsigned,char*); void ds_clrow(unsigned,unsigned); void ds_ghclr(); void ds_ghset(); void er_geter(char*,char*); void hd_disp(char*,char*,char*,int); void hd_opnod(int); void hd_pgnod(int); int hl_bulhl(char*,int,int*,char*); int hl_gethl(void*,int,int); int in_term(int); int it_break(); void tm_fixwt(unsigned long,int); void tx_gettx(int,int,int,int,char*); void tx_puttx(int,int,int,int,char*); void wt_endwt(char*); void wt_getwt(char*,char*); void wt_term(int,int); /* Local subroutine prototypes */ void comm_recv(); void comm_recv_01(); void comm_setup(); void data_files_open(); void err_display(); void get_data_page_01(); void get_data_01(); void get_data_02(); void get_page(); void get_page_01(); void help_build(); void help_display(); void main_task(); void page_disp(); void page_prep(); void simulate(); void start_up(); void val_page(); void val_page_01(); void wait_display(); void wrap_up(); /* Time structure area */ char time_filler[14] = " "; /* time holding buffer */ struct tm *timeptr; /* date time structure */ time_t timer; /* date time holding area */ /* File definition area */ #include "mmihlpfl.fd" /* help file */ char ct_name[13] = "CT.CAP"; /* capture file */ FILE *ct_file_ptr; char sim_name[13] = "XX.CAP"; /* simulated capture file */ FILE *sim_file_ptr; char mic_name[13] = "MICRO2.CAP"; /* date time file */ FILE *mic_file_ptr; /* Header page titles */ char program_nm[8] = "MMICAPPG"; char company_nm[40] = "microMETER, Corp."; char screen_nm[40] = "CAPTURE PROGRAM"; /* Default working variables */ #define EQ == #define TRUE 1 #define FALSE 0 char blnk_buf[80] = " " " "; int term_key; /* terminator key value */ char key[2]; /* hold the scan and ascii code */ /* Working variables */ #define PORT_MIN 1 /* minimum value for port input */ #define PORT_MAX 5 /* maximum value for port input */ #define NUM_MIN 1 /* min value for number of reads */ #define NUM_MAX 8640 /* max value for number of reads */ int port_input; /* port number input */ int num_read_input; /* number of readings input */ /* Processing flags */ int run_flg; /* run flag */ int help_flg; /* help flag */ int dt_disp_flg = TRUE; /* date time display flag */ int simulation_flg; /* simulation flag */ /* Pointers */ char *in_rec_ptr; /* input receive pointer */ char *in_snd_ptr; /* input send pointer */ /* Comm area */ char dt_buf[50]; /* date time buffer */ char recv_buf[50]; /* receive buffer */ int recv_char; /* receive character */ int addr_tbl[5] = /* comm addresses */ { 0, 0x03f8, 0x02f8, 0x03e8, 0x02e8 }; char disp_com_lit[6][10] = { " ", "COM1 ", "COM2 ", "COM3 ", "COM4 ", "Simulation" }; char disp_num_lit[6] = "Blocks"; /* Uart registers */ int uart_base; /* base address */ int rx_buffer; /* receive buffer */ int base_reg; /* base register */ int int_enable_reg; /* interrupt enable register */ int line_control_reg; /* line control register */ int modem_control_reg; /* modem control register */ int line_status_reg; /* line status register */ /* Page and option control area */ #define NUM_PAGES 3 /* # of pages + 2 */ int max_pages; /* maximum number of pages */ int min_pages = 1; /* minimum number of pages */ int max_optns; /* maximum number of options */ int min_optns = 1; /* minimum number of options */ int page_sub; /* page subscript */ int optn_sub; /* option subscript */ int inp_row; /* data entry row */ int inp_col; /* data entry column */ int inp_size; /* data entry size */ int inp_type; /* data entry type */ /* Number of menu options per input page */ int page_opt[NUM_PAGES] = { 0, 2 }; /* Number of display rows per input page */ int page_dsp[NUM_PAGES] = { 0, 2 }; /* Menu prompts */ int menu_sub; /* menu subscript */ #define MENU_ROW 4 /* # of valid prompts + 2 */ #define MENU_COL 30 /* width of each prompt */ char menu_tbl[MENU_ROW][MENU_COL] = /* menu prompts table */ { "Not used ", "Enter the COM Port Number: ", "Enter the Number of Readings: " }; /* Menu input */ char *inp_ptr; /* data input pointer */ #define INPT_ROW 4 /* # of valid input rows + 2 */ #define INPT_COL 10 /* width of each input */ char inp_tbl[INPT_ROW][INPT_COL] = /* default data input table */ { "Not used ", "1 ", "16 " }; /* Help area */ char help_save[2584]; /* 17 x 76 x 2 */ int help_page; /* page # from help file */ int help_optn; /* option # from help file */ char help_4[80] = " Time Date CT# B C D " " "; char help_5[80] = "-------- ---------- -------------------" "----------------------------------------"; char help_24[80] = ",  move the cursor. " " "; char help_25[80] = "Esc = Exit. " " F10 = Begin."; char help_lit[10] = "F5 = Help."; /* Wait area */ char wait_save[736]; /* 8 x 46 x 2 */ int wait_num; /* wait number */ int wait_max = 0; /* maximum wait number */ char *wait_ptr; /* wait pointer */ #define NUM_WAIT 4 /* (max wait+1) * 2 + 2 */ char wait_tbl[NUM_WAIT][40] = /* wait message table */ { "WARNING - Invalid wait table pointer. ", /* 00 */ "Report this error to the System Owner. " }; /* Error area */ char err_save[1012]; /* 11 x 46 x 2 */ int err_num = 0; /* local error number */ int err_max = 11; /* maximum error number */ #define NUM_ERR 50 /* (max error+1) * 4 + 2 */ char err_tbl[NUM_ERR][40] = /* error message table */ { "Invalid error table pointer. The error ", /* 00 */ "number is outside the valid range. ", "Module Name: err_display ", "Program Name: MMICAPPG.EXE ", " ", /* 01 */ " ", " ", " ", "File not found. ", /* 02 */ " ", "Module Name: ", "File Name: ", "Unable to allocate memory on the heap ", /* 03 */ "using the calloc function. ", "Module Name: ", "Program Name: MMICAPPG.EXE ", "The help file, MMI.HLP, was not found. ", /* 04 */ "Help is disabled until a help file is ", "created for this system. See HELP.TXT ", "for assistance in creating MMI.HLP. ", "The help file, MMI.HLP, does not have a ", /* 05 */ "group with data for MMICAPPG. Help is ", "disabled until a group with data is ", "created. See HELP.TXT for assistance. ", "Invalid page number in the help file, ", /* 06 */ "MMI.HLP, for the group, MMICAPPG. Help ", "is disabled until the page number is ", "corrected. See HELP.TXT for assistance. ", "Invalid option number in the help file, ", /* 07 */ "MMI.HLP, for the group, MMICAPPG. Help ", "is disabled until the option number is ", "corrected. See HELP.TXT for assistance. ", "Data was not found in the help file, ", /* 08 */ "MMI.HLP, for the group, MMICAPPG, for ", "this input field. See HELP.TXT for ", "assistance in creating help messages. ", "Unable to open a new file. ", /* 09 */ " ", "Module Name: ", "File Name: ", "Invalid port number. Please enter: ", /* 10 */ "1 = COM1 2 = COM2 ", "3 = COM3 4 = COM4 ", "5 = Simulate Mode or press Esc. ", "Invalid input for the number of readings", /* 11 */ "Please enter a number between 1 and ", "8640, or press Esc to abort. ", " " }; /***************************************************************************** *Main program. * *****************************************************************************/ void main (int argc, char *argv[]) { /* Turn off the cursor */ cursoff(); /* Get the input parameters */ port_input = atoi(argv[1]); num_read_input = atoi(argv[2]); /* Run the program */ start_up(); main_task(); wrap_up(); } /***************************************************************************** *This subroutine sets intializing parameters. * *****************************************************************************/ void start_up() { /* Check for Control Break */ ctrlbrk(it_break); /* Dispay the default screen */ hd_disp(company_nm,program_nm,screen_nm,dt_disp_flg); /* Get the number of screen display pages */ max_pages = NUM_PAGES - 2; /* Turn off the simulation flag */ simulation_flg = FALSE; /* Clear the run control flag */ run_flg = 0; /* Check the passed parameters */ if ( ((port_input >= PORT_MIN) && (port_input <= PORT_MAX)) && ((num_read_input >= NUM_MIN) && (num_read_input <= NUM_MAX)) ) { run_flg = 1; if (port_input EQ 5) simulation_flg = TRUE; } else /* Since needed, build the help messages */ help_build(); } /***************************************************************************** *This subroutine closes down processing. * *****************************************************************************/ void wrap_up() { /* Clear the page */ ds_clrow(1,25); /* Ensure that the cursor is on */ curson(); } /***************************************************************************** *This subroutine executes the logic of the main processing task. * *****************************************************************************/ void main_task() { /* Display the help lines */ if (run_flg EQ 0) { ds_buff(24,1,80,GR_WHITE,help_24); ds_buff(25,1,80,GR_WHITE,help_25); /* If the help file is ok, display the help literal */ if (help_flg EQ TRUE) ds_buff(24,71,10,GR_WHITE,help_lit); /* Get input values from each page until the Escape or F10 key is pressed */ curson(); page_sub = 1; while ((run_flg != 1) && (run_flg != 2)) get_page(); } /* If F10 pressed, prepare to capture or simulate data */ if (run_flg EQ 1) { /* Set up the display area */ ds_buff(2,1,14,GR_WHITE,blnk_buf); ds_buff(4,1,80,GR_WHITE,help_4); ds_buff(5,1,80,GR_WHITE,help_5); ds_clrow(6,23); ds_buff(24,1,80,GR_BROWN,help_24); ds_buff(25,1,11,GR_WHITE,help_25); ds_buff(25,12,69,GR_BROWN,help_25+11); cursoff(); /* Check for simulation mode */ if (simulation_flg EQ TRUE) simulate(); else { /* Open the data files */ data_files_open(); /* If no errors, setup the comm port */ if (err_num EQ 0) { comm_setup(); /* Capture the data */ comm_recv(); /* When done or aborted, close the data files */ fclose(ct_file_ptr); fclose(mic_file_ptr); } } /* If an error is set, display the error message */ if (err_num != 0) err_display(); else /* Otherwise, sound a beep */ sound(500,2); } } /***************************************************************************** *This subroutine gets each page of data. * *****************************************************************************/ void get_page() { /* Get the first page, unless Escape or F10 is pressed */ if ((run_flg != 1) && (run_flg != 2)) { if (page_sub EQ 1) { run_flg = 0; while(run_flg EQ 0) get_page_01(); } } } /***************************************************************************** *This subroutine gets the first page of data. * *****************************************************************************/ void get_page_01() { /* Prepare the page for display */ page_prep(); /* Display the page */ page_disp(); /* Get the data on page 1 until an Escape, F10, or page key is pressed */ while ((run_flg != 1) && (run_flg != 2) && (run_flg != 3)) get_data_page_01(); /* Check for specific keys */ switch (term_key) { case _PGDN: page_sub ++; break; case _PGUP: page_sub --; break; } /* Adjust the first page control subscript if it is out of range */ if(page_sub < min_pages) page_sub = max_pages; /* Adjust the last page control subscript if it is out of range */ if(page_sub > max_pages) page_sub = min_pages; } /***************************************************************************** *This subroutine validates the input from all pages when F10 is pressed. * *****************************************************************************/ void val_page() { /* Validate page 01 */ val_page_01(); } /***************************************************************************** *This subroutine validates the input from page 1. * *****************************************************************************/ void val_page_01() { /* Clear the error number */ err_num = 0; /* Check each input field */ port_input = atoi(inp_tbl[1]); num_read_input = atoi(inp_tbl[2]); if ((port_input < PORT_MIN) || (port_input > PORT_MAX)) err_num = 10; else { if ((num_read_input < NUM_MIN) || (num_read_input > NUM_MAX)) err_num = 11; else { if (port_input EQ 5) { simulation_flg = TRUE; num_read_input = 16; } } } /* Display the error and clear the run flag if an error is set */ if (err_num != 0) { err_display(); run_flg = 0; } } /***************************************************************************** *This subroutine prepares a page for display. * *****************************************************************************/ void page_prep() { int i; /* loop subscript */ /* Set the menu subscript */ menu_sub = 0; for (i=0; i max_optns) optn_sub = min_optns; } /***************************************************************************** *This subroutine gets the data for field 1. * *****************************************************************************/ void get_data_01() { /* Display the option number */ hd_opnod(optn_sub); /* Get the port number */ in_snd_ptr = inp_tbl[1]; in_rec_ptr = an_input(inp_row,inp_col,inp_size,inp_type,in_snd_ptr); key[0] = *(in_rec_ptr+0); key[1] = *(in_rec_ptr+1); term_key = key[0]*256 + key[1]; memcpy(inp_tbl[1],in_rec_ptr+2,inp_size); port_input = atoi(inp_tbl[1]); ds_buff(inp_row,inp_col,inp_size,GR_WHITE,inp_tbl[1]); /* Set the flag for the special keys */ if ((term_key EQ _F10) || (term_key EQ _ESC) || (term_key EQ _PGDN) || (term_key EQ _PGUP) || (term_key EQ _F5)) run_flg = 4; else { /* Check the input */ if ((port_input < PORT_MIN) || (port_input > PORT_MAX)) { err_num = 10; err_display(); } else { /* Re-display the input in highlight mode */ ds_buff(inp_row,inp_col+8,10,GR_LIGHT_GREEN,disp_com_lit[port_input]); /* Set the flag for a cursor control key */ if ((term_key EQ _DNARROW) || (term_key EQ _UPARROW) || (term_key EQ _ENTER)) run_flg = 5; } } } /***************************************************************************** *This subroutine gets the data for field 2. * *****************************************************************************/ void get_data_02() { /* Display the option number */ hd_opnod(optn_sub); /* Get the number of readings */ in_snd_ptr = inp_tbl[2]; in_rec_ptr = an_input(inp_row,inp_col,inp_size,inp_type,in_snd_ptr); key[0] = *(in_rec_ptr+0); key[1] = *(in_rec_ptr+1); term_key = key[0]*256 + key[1]; memcpy(inp_tbl[2],in_rec_ptr+2,inp_size); num_read_input = atoi(inp_tbl[2]); ds_buff(inp_row,inp_col,inp_size,GR_WHITE,inp_tbl[2]); /* Set the flag for the special keys */ if ((term_key EQ _F10) || (term_key EQ _ESC) || (term_key EQ _PGDN) || (term_key EQ _PGUP) || (term_key EQ _F5)) run_flg = 4; else { /* Check the input */ if ((num_read_input < NUM_MIN) || (num_read_input > NUM_MAX)) { err_num = 11; err_display(); } else { /* Re-display the input in highlight mode */ ds_buff(inp_row,inp_col+8,4,GR_LIGHT_GREEN,inp_tbl[2]); ds_buff(inp_row,inp_col+13,6,GR_LIGHT_GREEN,disp_num_lit); /* Set the flag for a cursor control key */ if ((term_key EQ _DNARROW) || (term_key EQ _UPARROW) || (term_key EQ _ENTER)) run_flg = 5; } } } /***************************************************************************** *This subroutine simulates capturing data from the microMETER, Corp. device. * *****************************************************************************/ void simulate() { unsigned long wait_time = 1000; /* wait time in hund seconds */ int lf = 0x0a; /* line feed */ int i,j,k,l; /* loop values */ /* Initialize variables */ term_key = 0; /* Open the simulation file for reading */ sim_file_ptr = fopen(sim_name,"r"); /* If cannot open, display an error message */ if (sim_file_ptr EQ NULL) { err_num = 9; memcpy(err_tbl[err_num*4]+94,"data_files_open ",26); memcpy(err_tbl[err_num*4]+134,sim_name,12); } else { /* Display 16 lines of data */ j = 0; k = 6; while ((j < num_read_input) && (term_key EQ 0)) { /* Clear the data and date-time buffers */ for (l=0; l<50; l++) { *(dt_buf+l) = 0; *(recv_buf+l) = 0; } /* Get the date and time */ time(&timer); timeptr = localtime(&timer); strftime(dt_buf,sizeof(dt_buf),"%H:%M:%S %m-%d-%Y",timeptr); /* Get a line of data */ i = 0; recv_char = fgetc(sim_file_ptr); while (recv_char != lf) { recv_buf[i] = recv_char; i++; recv_char = fgetc(sim_file_ptr); } /* Display the date-time and capture data */ ds_buff(k,1,19,GR_WHITE,dt_buf); ds_buff(k,22,i,GR_WHITE,recv_buf); /* Increment for the next block */ j++; k++; /* Wait for 10 seconds */ tm_fixwt(wait_time,1); /* Check for the Escape key */ term_key = ck_term(1); if (term_key != _ESC) term_key = 0; } } } /***************************************************************************** *This subroutine opens the data files for writing. * *****************************************************************************/ void data_files_open() { /* Open the capture file as new */ ct_file_ptr = fopen(ct_name,"w"); /* If cannot open as new, display an error message */ if (ct_file_ptr EQ NULL) { err_num = 9; memcpy(err_tbl[err_num*4]+94,"data_files_open ",26); memcpy(err_tbl[err_num*4]+134,ct_name,12); } else { /* Open the data-time file as new */ mic_file_ptr = fopen(mic_name,"w"); /* If cannot open as new, display an error message */ if (mic_file_ptr EQ NULL) { err_num = 9; memcpy(err_tbl[err_num*4]+94,"data_files_open ",26); memcpy(err_tbl[err_num*4]+134,mic_name,12); } } } /***************************************************************************** *This subroutine sets the comm port parameters. * *****************************************************************************/ void comm_setup() { int hex_00 = 0x00; /* comm values */ int hex_0f = 0x0f; int hex_80 = 0x80; int baud_rate_msb = 0x01; /* baud rate, most sig byte */ int baud_rate_lsb = 0x80; /* baud rate, least sig byte */ int n_81 = 0x03; /* no parity, 8 data, 1 stop */ int in_hold; /* hold for port input */ /* Set the port base address */ uart_base = addr_tbl[port_input]; /* Setup the additional uart registers */ rx_buffer = uart_base; base_reg = uart_base; int_enable_reg = uart_base + 1; line_control_reg = uart_base + 3; modem_control_reg = uart_base + 4; line_status_reg = uart_base + 5; /* Turn on the line control register latch bit */ outportb(line_control_reg,hex_80); /* Set the baud rate */ in_hold = inportb(line_control_reg); outportb(line_control_reg,(in_hold | 0x80)); outportb(int_enable_reg,baud_rate_msb); outportb(base_reg,baud_rate_lsb); in_hold = inportb(line_control_reg); outportb(line_control_reg,(in_hold | 0x7f)); /* Set the parity, data bits, and stop bits */ outportb(line_control_reg,n_81); /* Clear the interrupt enable register */ outportb(int_enable_reg,hex_00); } /***************************************************************************** *This subroutine receives data from the selected port. * *****************************************************************************/ void comm_recv() { int lf = 0x0a; /* line feed */ int cr = 0x0d; /* carriage return */ int i,j,k,l; /* loop values */ /* Initialize variables */ term_key = 0; /* Wait for the first line feed */ while ((recv_char != lf) && (term_key EQ 0)) comm_recv_01(); /* Get each buffer until done */ j = 0; k = 6; while ((j < num_read_input) && (term_key EQ 0)) { i = 0; /* Clear the data and date-time buffers */ for (l=0; l<50; l++) { *(dt_buf+l) = 0; *(recv_buf+l) = 0; } /* Get the date and time */ time(&timer); timeptr = localtime(&timer); strftime(dt_buf,sizeof(dt_buf),"%H:%M:%S %m-%d-%Y",timeptr); /* Get the data until a line feed is received */ comm_recv_01(); if (term_key EQ 0) { while ((recv_char != lf) && (term_key EQ 0)) { if (recv_char != cr) { recv_buf[i] = recv_char; i++; } comm_recv_01(); } } /* Display the date-time and capture data */ ds_buff(k,1,19,GR_WHITE,dt_buf); ds_buff(k,22,i,GR_WHITE,recv_buf); /* Prepare the buffers and write the data in the files */ *(recv_buf+i) = lf; fputs(recv_buf,ct_file_ptr); *(dt_buf+19) = lf; fputs(dt_buf,mic_file_ptr); /* Increment for the next block */ j++; k++; if (k EQ 22) { k = 6; ds_clrow(6,21); } } } /***************************************************************************** *This subroutine receives an individual character. * *****************************************************************************/ void comm_recv_01() { int line_status = 0; /* line status value */ int rx_ready = 0x01; /* receive ready mask */ /* Initialize variables */ recv_char = 0; /* Wait for line status reg to indicate that a char is ready to be received */ while ((line_status EQ 0) && (recv_char EQ 0) && (term_key != _ESC)) { line_status = (inportb(line_status_reg) & rx_ready); /* If a character is ready to be read, get it */ if (line_status != 0) { while ((recv_char EQ 0) && (term_key != _ESC)) { recv_char = inportb(rx_buffer); term_key = ck_term(1); } } /* Otherwise, check for an abort */ else term_key = ck_term(1); } } /***************************************************************************** *This subroutine builds the help messages as a linked list in memory. * *****************************************************************************/ void help_build() { /* Build the list */ help_flg = TRUE; help_head = hl_bulhl(program_nm,max_pages,(int*)page_opt,help_name); /* Check for an error from the build process */ if (((int)help_head > 3) && ((int)help_head < 8)) err_num = (int)help_head; /* Display an error message if there are building problems */ if (err_num != 0) { help_flg = FALSE; err_display(); err_num = 0; } } /***************************************************************************** *This subroutine displays help information in a pop up window. * *****************************************************************************/ void help_display() { /* Ghost out lines 23 - 25 */ ds_ghset(); /* Save the original text in the help window area */ tx_gettx(HELP_BEG_ROW,HELP_BEG_COL,HELP_END_COL,HELP_END_ROW,help_save); /* Display the help window */ err_num = hl_gethl(help_head,page_sub,optn_sub); /* Display an error message if help is not found */ if (err_num != 0) { err_num = 8; err_display(); err_num = 0; } /* Wait for a return key to be pressed */ wt_term(_ENTER,1); /* Put the saved text back on the screen */ tx_puttx(HELP_BEG_ROW,HELP_BEG_COL,HELP_END_COL,HELP_END_ROW,help_save); /* Clear lines 23 - 25 */ ds_ghclr(); } /***************************************************************************** *This subroutine displays wait information in a pop up window. * *****************************************************************************/ void wait_display() { /* Ghost out lines 23 - 25 */ ds_ghset(); /* Validate the wait number */ if ((wait_num < 1) || (wait_num > wait_max)) wait_num = 0; /* Display the wait message */ wait_ptr = wait_tbl[wait_num*2]; wt_getwt(wait_save,wait_ptr); } /***************************************************************************** *This subroutine displays error information in a pop up window. * *****************************************************************************/ void err_display() { /* Validate the error number */ if ((err_num < 1) || (err_num > err_max)) { err_num = 0; er_geter(err_save,err_tbl[err_num*4]); err_num = 99; } else /* Display the error message */ er_geter(err_save,err_tbl[err_num*4]); } /***************************************************************************** *PINELLAS PLANT - microMETER, Corp. system * *****************************************************************************/ /* MMIHLPFL.FD - Help File Descriptor */ typedef struct list { char help_pg_no [2]; /* page number */ char help_op_no [2]; /* option number */ char help_msg [70]; /* help message */ char help_filler [6]; /* filler to end of line */ struct list *help_next, *help_prev; } HELP_REC; HELP_REC *help_ptr; HELP_REC *help_head; char help_name[8] = "MMI.HLP"; /* help file name */ FILE *help_file_ptr; /* help file pointer */