// Set channel configuration from the config file on the SD card void readConfigFromFile(){ char line[LINE_SIZE+1]; /* Line Buffer */ int32_t i = 0; int32_t iVal = 0; char cVal = 0; float fVal = 0; /* Attempt to open config file, error if the file does not exist */ if(f_open(&config, "config.txt", FA_OPEN_EXISTING | FA_READ) != FR_OK){ error(ERROR_READ_CONFIG); } /* Read lines to get to update Date/Time */ getNonBlankLine(line,2); if (line[0] == 'Y' || line[0] == 'y') { /* Update Date and Time - 4 Lines */ getNonBlankLine(line,1); /* Line is now the date/time string in YYYY-MM-DD HH:MM:SS */ setTime(line); /* Read lines to get to update config */ getNonBlankLine(line,1); } else { getNonBlankLine(line,3); } if (line[0] == 'Y' || line[0] == 'y') { /* Update Config - */ getNonBlankLine(line,1); /* Line is now the user header */ endAtNewline(line); memcpy(daq.user_comment, line, 101); getNonBlankLine(line,1); /* Line is now Output Voltage */ sscanf(line, " %f", &fVal); daq.mv_out = (int32_t)(fVal * 1000); getNonBlankLine(line,1); /* Line is now Sample Rate */ sscanf(line, " %d", &iVal); daq.sample_rate = (int32_t)iVal; getNonBlankLine(line,1); /* Line is now trigger delay */ sscanf(line, " %d", &iVal); daq.trigger_delay = iVal; getNonBlankLine(line,1); /* Line is now data mode */ if (line[0] == 'R' || line[0] == 'r') { daq.data_type = READABLE; } else if (line[0] == 'B' || line[0] == 'b') { daq.data_type = BINARY; } else { error(ERROR_READ_CONFIG); } for (i = 0; i<MAX_CHAN; i++) { getNonBlankLine(line,1); /* Channel Config */ /* CH Enabled */ sscanf(line + countToColon(line), " %c", &cVal); if (cVal == 'Y' || cVal == 'y') { daq.channel[i].enable = true; } else if (cVal == 'N' || cVal == 'n') { daq.channel[i].enable = false; } else { error(ERROR_READ_CONFIG); } getNonBlankLine(line,0); /* CH Range */ sscanf(line + countToColon(line), " %c", &cVal); if (cVal == '5'){ daq.channel[i].range = V5; } else if (cVal == '2') { daq.channel[i].range = V24; } else { error(ERROR_READ_CONFIG); } getNonBlankLine(line, 0); /* CH Units */ endAtNewline(line); memcpy(daq.channel[i].unit_name, line + countToColon(line)+1, 9); getNonBlankLine(line, 0); /* CH Units/Volt */ sscanf(line + countToColon(line), " %f", &fVal); daq.channel[i].units_per_volt = floatToDecFloat(fVal); getNonBlankLine(line,0); /* CH Zero Offset */ sscanf(line + countToColon(line), " %f", &fVal); daq.channel[i].offset_uV = floatToFix(fVal*1000000); } /* Read lines to get to update calibration */ getNonBlankLine(line,1); } else { /* Move to next section if no update config */ getNonBlankLine(line,29); } if (line[0] == 'Y' || line[0] == 'y') { /* Update Calibration - 18 Lines (Maybe) */ for (i = 0; i<MAX_CHAN;i++) { getNonBlankLine(line,1); /* 5V Zero Offset */ sscanf(line + countToColon(line), " %f", &fVal); daq.channel[i].v5_zero_offset = floatToFix(fVal); getNonBlankLine(line,0); /* 5V Volt/LSB */ sscanf(line + countToColon(line), " %f", &fVal); daq.channel[i].v5_uV_per_LSB = floatToFix(fVal*1000000); getNonBlankLine(line,0); /* 24V Zero Offset */ sscanf(line + countToColon(line), " %f", &fVal); daq.channel[i].v24_zero_offset = floatToFix(fVal); getNonBlankLine(line,0); /* 24V Volt/LSB */ sscanf(line + countToColon(line), " %f", &fVal); daq.channel[i].v24_uV_per_LSB = floatToFix(fVal*1000000); } } /* Close config file */ f_close(&config); /* Run ConfigCheck After Reading */ daq_configCheck(); }
/* load the sequence struct with comment line and bases */ SeqStructPtr getSeq(char *fname) { SeqStructPtr newSeqP; Boolean endOfSeq; char c; if (endOfFile) return ((SeqStructPtr )0); /* bombproofing */ /* malloc a new seq */ if (! (newSeqP = (SeqStructPtr )malloc(sizeof(SeqStruct)) ) ) { fprintf(stderr,"unable to malloc() memory for sequence.\n"); exit(1); } /* clear mem */ memset( (void *)newSeqP, '\0', sizeof(SeqStruct)); /* pick up description line */ if (! getNonBlankLine(newSeqP->descStr) ) { free(newSeqP); return ((SeqStructPtr )0); } /* did it start correctly ? */ if (newSeqP->descStr[0] != '>') { fprintf(stderr,"format error in input file: missing '>'\n"); exit(1); } endOfSeq = False; while ((!endOfFile) && (!endOfSeq)) { if (getChar(&c)) { if (c == '>') { /* hit new sequence */ endOfSeq = True; putCharBack(c); } else if (((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z')))/* bogus test, chris */ /* have nucleotide */ newSeqP->seqStr[newSeqP->seqLen++] = toupper(c); else if ((c != '\n') && (c != ' ') && (c != '\t')) { /* wierd shit in file. bail. */ fprintf(stderr,"bad char in sequence, file %s: %c\n",fname,c); exit(1); } } } if (! newSeqP->seqLen) { fprintf(stderr,"? Null sequence encountered in file %s (ignored)\n",fname); fprintf(stderr," %s\n", newSeqP->descStr); free(newSeqP); return ((SeqStructPtr )0); } return(newSeqP); } /* getSeq */