Flying Sea Glider / Mbed 2 deprecated 2019_10may_firstflight_jcw_nosd

Dependencies:   mbed MODSERIAL FATFileSystem

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ConfigFileIO.cpp Source File

ConfigFileIO.cpp

00001 #include "ConfigFileIO.hpp"
00002 #include "StaticDefs.hpp"
00003 
00004 //configuration file io, both to read, set, and save
00005 
00006 ConfigFileIO::ConfigFileIO() {
00007 }    
00008 
00009 void ConfigFileIO::saveBattData(float batt_p_gain, float batt_i_gain, float batt_d_gain, int batt_zeroOffset, float batt_filter_freq, float batt_deadband) {       
00010     ConfigFile write_Batt_txt;   //write to the config file
00011     
00012     char PGain_buffer[128];
00013     sprintf(PGain_buffer,"# configuration file for battery mover parameters\n\n#Gains\nPGain");
00014     
00015     char string_pgain[128];  
00016     sprintf(string_pgain, "%f", batt_p_gain);
00017     write_Batt_txt.setValue(PGain_buffer, string_pgain);
00018     
00019     char string_igain[128];  
00020     sprintf(string_igain, "%f", batt_i_gain);
00021     write_Batt_txt.setValue("IGain", string_igain);
00022     
00023     char string_dgain[128];  
00024     sprintf(string_dgain, "%f", batt_d_gain);
00025     write_Batt_txt.setValue("DGain", string_dgain);
00026       
00027     char string_zeroCounts[128];  
00028     sprintf(string_zeroCounts, "%d", batt_zeroOffset);      
00029     write_Batt_txt.setValue("\n#string pot parameters\nzeroCounts", string_zeroCounts);
00030     
00031     //modified this from hard-coded values to set to whatever is in the file on startup
00032     char string_batt_travel_limit[128];
00033     sprintf(string_batt_travel_limit, "%f", batt().getTravelLimit());
00034     write_Batt_txt.setValue("PistonTravelLimit", string_batt_travel_limit);
00035     
00036     write_Batt_txt.setValue("slope", "0.12176");
00037     
00038     char string_filter_freq[128];  
00039     sprintf(string_filter_freq, "%f", batt_filter_freq);
00040     write_Batt_txt.setValue("filterWn", string_filter_freq);
00041     
00042     char string_deadband[128];  
00043     sprintf(string_deadband, "%f", batt_deadband);
00044     write_Batt_txt.setValue("deadband", string_deadband);
00045 
00046     //SAVE THE DATA!
00047     xbee().printf("Saving BATTERY MOVER PID data!");
00048     
00049     if (!write_Batt_txt.write("/local/batt.txt")) {
00050         xbee().printf("\n\rERROR: (SAVE)Failure to write batt.txt file.");
00051     }
00052     else {
00053         xbee().printf("\n\rFile batt.txt successful written.\n\r");
00054     }  
00055 }
00056 int ConfigFileIO::load_StartTime() {
00057    ConfigFile cfg;
00058    int count = 0;
00059    if (!cfg.read("/local/time.txt")) {
00060             error("File Read Error");
00061     }
00062     char value[BUFSIZ];  
00063     if (cfg.getValue("TimeStamp", &value[0] , sizeof(value))) {
00064         // bce().setControllerP(atoi(value));
00065         mbedLogger().setLogTime(atol(value)); 
00066         count++;
00067     }  
00068     return count;
00069 }
00070 void ConfigFileIO::saveLogVersData(int logversion,  int diagversion) {       
00071     ConfigFile write_logvers_txt;   //write to the config file
00072         
00073     char string_log[128];  
00074     sprintf(string_log, "%d", logversion);
00075     write_logvers_txt.setValue("LogFileVers",  string_log);
00076     
00077     char string_diag[128];  
00078     sprintf(string_diag, "%i", diagversion);
00079     write_logvers_txt.setValue("DiagFileVers", string_diag);
00080     
00081     
00082     
00083     //SAVE THE DATA!
00084     xbee().printf("Saving logfile version numbers !");
00085     
00086     if (!write_logvers_txt.write("/local/logvers.txt")) {
00087         xbee().printf("\n\rERROR: (SAVE)Failure to write logvers.txt file.");
00088     }
00089     else {
00090         xbee().printf("\n\rFile logvvrs.txt successful written.\n\r");
00091     }  
00092 }
00093 
00094 void ConfigFileIO::savePitchData(float pitch_p_gain, float pitch_i_gain, float pitch_d_gain, float pitch_zeroOffset, float pitch_filter_freq, float pitch_deadband) {   
00095     ConfigFile write_pitch_txt;   //write to the config file
00096     
00097     char PGain_buffer[128];
00098     sprintf(PGain_buffer,"# pitch outer loop parameters\n\n#Gains\nPGain");
00099     
00100     char string_pgain[128];  
00101     sprintf(string_pgain, "%f", pitch_p_gain);
00102     write_pitch_txt.setValue(PGain_buffer, string_pgain);
00103     
00104     char string_igain[128];  
00105     sprintf(string_igain, "%f", pitch_i_gain);
00106     write_pitch_txt.setValue("IGain", string_igain);
00107     
00108     char string_dgain[128];  
00109     sprintf(string_dgain, "%f", pitch_d_gain);
00110     write_pitch_txt.setValue("DGain", string_dgain);
00111     
00112     char string_filter_freq[128];  
00113     sprintf(string_filter_freq, "%f", pitch_filter_freq);       
00114     write_pitch_txt.setValue("\n#Pitch sensor filter parameters\nfilterWn", string_filter_freq);
00115     
00116     char string_deadband[128];
00117     sprintf(string_deadband, "%f", pitch_deadband);
00118     write_pitch_txt.setValue("deadband", string_deadband);
00119     
00120     char string_zeroOffset[128];
00121     sprintf(string_zeroOffset, "%f", pitch_zeroOffset);
00122     //bce setting was 41 mm during LASR experiments
00123     write_pitch_txt.setValue("\n#Offset for neutral (default: 41)\nzeroOffset", string_zeroOffset);
00124     
00125     //SAVE THE DATA!
00126     xbee().printf("Saving Buoyancy Engine Neutral Buoyancy Positions!");
00127     
00128     if (!write_pitch_txt.write("/local/pitch.txt")) {
00129         xbee().printf("\n\rERROR: (SAVE)Failure to write depth.txt file.");
00130     }
00131     else {
00132         xbee().printf("\n\rFile pitch.txt successful written.\n\r");
00133     } 
00134 }
00135 
00136 void ConfigFileIO::saveBCEData(float bce_p_gain, float bce_i_gain, float bce_d_gain, int bce_zeroOffset, float bce_filter_freq, float bce_deadband) {       
00137     ConfigFile write_BCE_txt;   //write to the config file
00138     
00139     char PGain_buffer[128];
00140     sprintf(PGain_buffer,"# configuration file for BCE parameters\n\n#Gains\nPGain");
00141     
00142     char string_pgain[128];  
00143     sprintf(string_pgain, "%f", bce_p_gain);
00144     write_BCE_txt.setValue(PGain_buffer, string_pgain);
00145     
00146     char string_igain[128];  
00147     sprintf(string_igain, "%f", bce_i_gain);
00148     write_BCE_txt.setValue("IGain", string_igain);
00149     
00150     char string_dgain[128];  
00151     sprintf(string_dgain, "%f", bce_d_gain);
00152     write_BCE_txt.setValue("DGain", string_dgain);
00153     
00154     char string_zeroCounts[128];
00155     sprintf(string_zeroCounts, "%d", bce_zeroOffset);
00156     write_BCE_txt.setValue("\n#string pot parameters\nzeroCounts", string_zeroCounts);
00157     
00158     //modified this from hard-coded values to set to whatever is in the file on startup
00159     char string_bce_travel_limit[128];
00160     sprintf(string_bce_travel_limit, "%f", batt().getTravelLimit());
00161     write_BCE_txt.setValue("PistonTravelLimit", string_bce_travel_limit);
00162     
00163     write_BCE_txt.setValue("slope", "0.12176");
00164     
00165     char string_filter_freq[128];  
00166     sprintf(string_filter_freq, "%f", bce_filter_freq);
00167     write_BCE_txt.setValue("filterWn", string_filter_freq);
00168     
00169     char string_deadband[128];  
00170     sprintf(string_deadband, "%f", bce_deadband);
00171     write_BCE_txt.setValue("deadband", string_deadband);
00172 
00173     //SAVE THE DATA!
00174     xbee().printf("Saving BCE PID data!");
00175     
00176     if (!write_BCE_txt.write("/local/bce.txt")) {
00177         xbee().printf("\n\rERROR: (SAVE)Failure to write bce.txt file.");
00178     }
00179     else {
00180         xbee().printf("\n\rFile bce.txt successful written.\n\r");
00181     } 
00182 }
00183 
00184 void ConfigFileIO::saveDepthData(float depth_p_gain, float depth_i_gain, float depth_d_gain, float depth_zeroOffset, float depth_filter_freq, float depth_deadband) {       
00185     ConfigFile write_depth_txt;   //write to the config file
00186     
00187     char PGain_buffer[128];
00188     sprintf(PGain_buffer,"# depth outer loop parameters\n\n#Gains\nPGain");
00189     
00190     char string_pgain[128];  
00191     sprintf(string_pgain, "%f", depth_p_gain);
00192     write_depth_txt.setValue(PGain_buffer, string_pgain);
00193     
00194     char string_igain[128];  
00195     sprintf(string_igain, "%f", depth_i_gain);
00196     write_depth_txt.setValue("IGain", string_igain);
00197     
00198     char string_dgain[128];  
00199     sprintf(string_dgain, "%f", depth_d_gain);
00200     write_depth_txt.setValue("DGain", string_dgain);
00201     
00202     char string_filter_freq[128];
00203     sprintf(string_filter_freq, "%f", depth_filter_freq);
00204     write_depth_txt.setValue("\n#Depth sensor filter parameters\nfilterWn", string_filter_freq);
00205     
00206     char string_deadband[128];
00207     sprintf(string_deadband, "%f", depth_deadband);
00208     write_depth_txt.setValue("deadband", string_deadband);
00209     
00210     char string_zeroOffset[128];
00211     sprintf(string_zeroOffset, "%f", depth_zeroOffset);
00212     //bce setting was 240 mm during LASR experiments
00213     write_depth_txt.setValue("\n#Offset for neutral (default: 240)\nzeroOffset", string_zeroOffset);
00214     
00215     //SAVE THE DATA!
00216     xbee().printf("Saving Buoyancy Engine Neutral Buoyancy Positions!");
00217     
00218     if (!write_depth_txt.write("/local/depth.txt")) {
00219         xbee().printf("\n\rERROR: (SAVE)Failure to write depth.txt file.");
00220     }
00221     else {
00222         xbee().printf("\n\rFile depth.txt successful written.\n\r");
00223     } 
00224 }
00225 
00226 //write rudder (servo driver) file rudder.txt
00227 void ConfigFileIO::saveRudderData(float setMinDeg, float setMaxDeg, float setCenterPWM, float setMinPWM, float setMaxPWM) {
00228     ConfigFile rudder_txt;
00229     
00230     char header[128];
00231     sprintf(header,"# rudder (servo) inner loop (heading outer loop uses this)");
00232     
00233     char string_min_deg[128];  
00234     sprintf(string_min_deg, "%f", setMinDeg);
00235     rudder_txt.setValue("setMinDeg", string_min_deg);
00236     
00237     char string_max_deg[128];  
00238     sprintf(string_max_deg, "%f", setMaxDeg);
00239     rudder_txt.setValue("setMaxDeg", string_max_deg);
00240     
00241     char string_ctr_pwm[128];  
00242     sprintf(string_ctr_pwm, "%f", setCenterPWM);
00243     rudder_txt.setValue("setCenterPWM", string_ctr_pwm);
00244     
00245     char string_min_pwm[128];  
00246     sprintf(string_min_pwm, "%f", setMinPWM);
00247     rudder_txt.setValue("setMinPWM", string_min_pwm);
00248     
00249     char string_max_pwm[128];  
00250     sprintf(string_max_pwm, "%f", setMaxPWM);
00251     rudder_txt.setValue("setMaxPWM", string_max_pwm);
00252 
00253     //SAVE THE DATA!
00254     xbee().printf("Saving RUDDER DATA!");
00255     
00256     if (!rudder_txt.write("/local/rudder.txt")) {
00257         xbee().printf("\n\rERROR: (SAVE)Failure to write rudder.txt file.");
00258     }
00259     else {
00260         xbee().printf("\n\rFile rudder.txt successful written.\n\r");
00261     } 
00262 }
00263 
00264 int ConfigFileIO::load_BCE_config() {
00265     ConfigFile cfg;
00266     int count = 0;
00267     if (!cfg.read("/local/bce.txt")) {
00268             error("File Read Error");
00269     }
00270     char value[BUFSIZ];
00271  
00272     if (cfg.getValue("PGain", &value[0] , sizeof(value))) {
00273         bce().setControllerP(atof(value));
00274         count++;
00275     }
00276     if (cfg.getValue("IGain", &value[0] ,sizeof(value))) {
00277         bce().setControllerI(atof(value));
00278         count++;
00279     }
00280     if (cfg.getValue("DGain", &value[0] , sizeof(value))) {
00281         bce().setControllerD(atof(value));
00282         count++;
00283     }
00284     if (cfg.getValue("zeroCounts", &value[0],sizeof(value))) {
00285         bce().setZeroCounts(atoi(value));
00286         count++;
00287     }
00288     if (cfg.getValue("PistonTravelLimit", &value[0], sizeof(value))) {
00289         bce().setTravelLimit(atof(value));
00290         count++;
00291     }
00292     if (cfg.getValue("slope", &value[0], sizeof(value))) {
00293         bce().setPotSlope(atof(value));
00294         count++;
00295     }
00296     if (cfg.getValue("filterWn", &value[0], sizeof(value))) {
00297         bce().setFilterFrequency(atof(value));
00298         count++;
00299     }
00300     if (cfg.getValue("deadband", &value[0], sizeof(value))) {
00301         bce().setDeadband(atof(value));
00302         count++;
00303     }
00304     
00305     return count;     
00306 }
00307 
00308 //write to heading.txt
00309 void ConfigFileIO::saveHeadingData(float heading_p_gain, float heading_i_gain, float heading_d_gain, float heading_zeroOffset, float heading_filter_freq, float heading_deadband) {
00310     ConfigFile heading_txt;
00311     
00312     char PGain_buffer[128];
00313     sprintf(PGain_buffer,"# HEADING (rudder outer loop) parameters\n\n#Gains\nPGain");
00314     
00315     //convert input numbers into text and save them to text file
00316     char string_pgain[128];  
00317     sprintf(string_pgain, "%f", heading_p_gain);
00318     heading_txt.setValue(PGain_buffer, string_pgain);
00319     
00320     char string_igain[128];  
00321     sprintf(string_igain, "%f", heading_i_gain);
00322     heading_txt.setValue("IGain", string_igain);
00323     
00324     char string_dgain[128];  
00325     sprintf(string_dgain, "%f", heading_d_gain);
00326     heading_txt.setValue("DGain", string_dgain);
00327 
00328     char string_heading_freq[128];
00329     sprintf(string_heading_freq, "%f", heading_filter_freq);
00330     heading_txt.setValue("\n# HEADING sensor filter parameters\nfilterWn", string_heading_freq);
00331     
00332     char string_heading_db[128];
00333     sprintf(string_heading_db, "%f", heading_deadband);
00334     heading_txt.setValue("deadband",string_heading_db);
00335     
00336     char string_zeroOffset[128];
00337     sprintf(string_zeroOffset, "%f", heading_zeroOffset);
00338     heading_txt.setValue("\n#HEADING offset\nzeroOffset", string_zeroOffset);
00339     
00340     //SAVE THE DATA!
00341     xbee().printf("(ConfigFileIO) Saving HEADING parameters!");
00342     
00343     if (!heading_txt.write("/local/heading.txt")) {
00344         xbee().printf("\n\rERROR: (SAVE) Failure to write heading.txt file.");
00345     }
00346     else {
00347         xbee().printf("\n\rFile heading.txt successful written.\n\r");
00348     } 
00349 }
00350 int ConfigFileIO::load_LogVers_config(int print_diag) { // I could copy this mode to read one line of a leg_mission file. One line or multiple lines?
00351     ConfigFile cfg;
00352     int count = 0;
00353     int version = 0;
00354     if (!cfg.read("/local/logvers.txt")) {   //   "/local/leg_mission.txt"
00355             error("Lognames version file logvers.txt  File Read Error");
00356     }
00357     char value[BUFSIZ]; //  chang
00358  
00359     
00360     if (cfg.getValue("LogFileVers", &value[0] , sizeof(value))) {
00361         version = atoi(value);  
00362         char buf[256];
00363         sprintf(buf, "LOG%03d.csv", version);
00364         logFilesStruct.logFileName = buf;
00365         logFilesStruct.logversion = version;
00366         count++;
00367     }
00368     if (cfg.getValue("DiagFileVers", &value[0] , sizeof(value))) {
00369         version = atoi(value);  
00370         char buf[256];
00371         
00372         sprintf(buf, "in configfileIO: diag file version number is %d\n", version);
00373         if(print_diag == 1) {mbedLogger().appendDiagFile(buf,3);}
00374         //  buf[256]= {0};
00375         sprintf(buf, "in ConfigFileIO:   diag file string is DIAG%03d.txt\n", version);
00376         if(print_diag == 1) {mbedLogger().appendDiagFile(buf,3);}
00377         // buf[256]= {0};
00378         sprintf(buf, "DIAG%03d.txt", version);
00379         logFilesStruct.diagFileName = buf;
00380         logFilesStruct.diagversion = version;
00381         sprintf(buf, "in ConfigFileIO:   diag info pulled from struct:  filename = %s  diagvernum = %d\n", logFilesStruct.diagFileName,
00382              logFilesStruct.diagversion);
00383         if(print_diag==1)  {mbedLogger().appendDiagFile(buf,3);}
00384         count++;
00385     }
00386     return count;
00387 }
00388 int ConfigFileIO::load_setneutral_status() { 
00389     ConfigFile cfg;
00390     int count = 0;
00391     int setval = 0;
00392     int bce_mm = 240;
00393     int batt_mm = 40;
00394     if (!cfg.read("/local/neutral.txt")) {   
00395        error("setneutral file neutral.txt  File Read Error");
00396        //  set values in struct to defaults??
00397     }
00398     char value[BUFSIZ];
00399  
00400     
00401     if (cfg.getValue("neutral_set", &value[0] , sizeof(value))) {
00402         setval = atoi(value);  
00403         neutralStruct.setval = setval;
00404         count++;
00405     }
00406     if (cfg.getValue("bce_neutral_mm", &value[0] , sizeof(value))) {
00407         bce_mm = atoi(value);  
00408         char buf[256];
00409         sprintf(buf, "in configfileIO: bce_neutral_mm  is %d\n", bce_mm);
00410         mbedLogger().appendDiagFile(buf,3);
00411         //  buf[256]= {0};
00412         neutralStruct.bce_neutral_mm = bce_mm;
00413         count++;
00414     }
00415     if (cfg.getValue("batt_neutral_mm", &value[0] , sizeof(value))) {
00416         batt_mm = atoi(value);  
00417         char buf[256];
00418         sprintf(buf, "in configfileIO: batt_neutral_mm  is %d\n", batt_mm);
00419         mbedLogger().appendDiagFile(buf,3);
00420         //  buf[256]= {0};
00421         neutralStruct.batt_neutral_mm = batt_mm;
00422         count++;
00423     }
00424     return count;
00425 }
00426 void ConfigFileIO::saveNeutralStatus(int setval, int bce_neutral_mm, int batt_neutral_mm) {
00427     ConfigFile neutral_txt;    
00428        
00429     //convert input numbers into text and save them to text file
00430     char string_setval[128];  
00431     sprintf(string_setval, "%d", setval);
00432     neutral_txt.setValue("# Neutral set status and values\nneutral_set", string_setval);
00433     
00434     char string_bce[128];  
00435     sprintf(string_bce, "%d", bce_neutral_mm);
00436     neutral_txt.setValue("bce_neutral_mm", string_bce);
00437     
00438     char string_batt[128];  
00439     sprintf(string_batt, "%d", batt_neutral_mm);
00440     neutral_txt.setValue("batt_neutral_mm", string_batt);
00441 
00442         
00443     //SAVE THE DATA!    also put the data insto the neutral struct
00444     neutralStruct.batt_neutral_mm = batt_neutral_mm; 
00445     neutralStruct.bce_neutral_mm = bce_neutral_mm;
00446     neutralStruct.setval = setval;
00447     xbee().printf("(ConfigFileIO) Saving neutral set status  parameters!");
00448     
00449     if (!neutral_txt.write("/local/neutral.txt")) {
00450         xbee().printf("\n\rERROR: (SAVE) Failure to write neutral.txt file.");
00451     }
00452     else {
00453         xbee().printf("\n\rFile neutral.txt successful written.\n\r");
00454     }  
00455 }
00456 int ConfigFileIO::load_BATT_config() { // I could copy this mode to read one line of a leg_mission file. One line or multiple lines?
00457     ConfigFile cfg;
00458     int count = 0;
00459     if (!cfg.read("/local/batt.txt")) {   //   "/local/leg_mission.txt"
00460             error("BATT File Read Error");
00461     }
00462     char value[BUFSIZ];
00463  
00464     
00465     if (cfg.getValue("PGain", &value[0] , sizeof(value))) {
00466         batt().setControllerP(atof(value));  // but I want values in a legStructLoaded, not a function
00467         count++;
00468     }
00469     if (cfg.getValue("IGain", &value[0] ,sizeof(value))) {
00470         batt().setControllerI(atof(value));
00471         count++;
00472     }
00473     if (cfg.getValue("DGain", &value[0] , sizeof(value))) {
00474         batt().setControllerD(atof(value));
00475         count++;
00476     }
00477     if (cfg.getValue("zeroCounts", &value[0],sizeof(value))) {
00478         batt().setZeroCounts(atoi(value));
00479         count++;
00480     }
00481     if (cfg.getValue("PistonTravelLimit", &value[0], sizeof(value))) {
00482         batt().setTravelLimit(atof(value));
00483         count++;
00484     }
00485     if (cfg.getValue("slope", &value[0], sizeof(value))) {
00486         batt().setPotSlope(atof(value));
00487         count++;
00488     }
00489     if (cfg.getValue("filterWn", &value[0], sizeof(value))) {
00490         batt().setFilterFrequency(atof(value));
00491         count++;
00492     }
00493     if (cfg.getValue("deadband", &value[0], sizeof(value))) {
00494         batt().setDeadband(atof(value));
00495         count++;
00496     }
00497     
00498     return count;     
00499 }
00500 void ConfigFileIO::report_still_inverted( float roll_value, int yotime) {
00501      ConfigFile still_inverted;
00502       
00503       char string_yotime[128];  
00504     sprintf(string_yotime, "%d", yotime);
00505     still_inverted.setValue("# Still Inverted after START_SWIM yo timeout timeout\n yo_time", string_yotime);
00506     
00507     char string_roll[128];  
00508     sprintf(string_roll, "%f", roll_value);
00509     still_inverted.setValue("inverted_roll_value", string_roll);
00510     
00511             
00512     //SAVE THE DATA!   
00513     
00514     xbee().printf("(ConfigFileIO) Saving still_inverted status after start_swim timeout!");
00515     
00516     if (!still_inverted.write("/local/inverted.txt")) {  // I assume this will build a new file if one is not already there
00517         xbee().printf("\n\rERROR: (SAVE) Failure to write inverted.txt file.");
00518     }
00519     else {
00520         xbee().printf("\n\rFile inverted.txt  written.\n\r");  // raspberry Pi will need to delete this file on finding it
00521     } 
00522      
00523     }
00524 void ConfigFileIO::report_no_neutral_found(int bce_last_pos, int batt_last_pos) {  // this will tell the Raspberry Pi that neutral was not found -- BAD
00525     ConfigFile no_neutral;    
00526        int setval = 0;
00527     //convert input numbers into text and save them to text file
00528     char string_setval[128];  
00529     sprintf(string_setval, "%d", setval);
00530     no_neutral.setValue("# Find_Neutral  success or failure\nneutral_found", string_setval);
00531     
00532     char string_batt[128];  
00533     sprintf(string_batt, "%d", batt_last_pos);
00534     no_neutral.setValue("batt_last_position", string_batt);
00535     
00536     sprintf(string_batt, "%d", bce_last_pos);
00537     no_neutral.setValue("bce_last_position", string_batt);
00538     
00539         
00540     //SAVE THE DATA!    also put the data insto the neutral struct
00541     
00542     xbee().printf("(ConfigFileIO) Saving find_neutral failure status!");
00543     
00544     if (!no_neutral.write("/local/no_float.txt")) {  // I assume this will build a new file if one is not already there
00545         xbee().printf("\n\rERROR: (SAVE) Failure to write no_float.txt file.");
00546     }
00547     else {
00548         xbee().printf("\n\rFile no_float.txt  written.\n\r");
00549     } 
00550 }
00551 void ConfigFileIO::save_FinalTime() {
00552     ConfigFile timefile_txt;
00553     int last_time;
00554     char header[128];
00555     sprintf(header,"# Timestamp at last moment before closing shop\n");
00556 
00557     char string_end_time[128];  
00558     last_time = mbedLogger().getSystemTime(); 
00559     sprintf(string_end_time, "%d", last_time);
00560     timefile_txt.setValue("TimeStamp", string_end_time);
00561     
00562     
00563     //SAVE THE DATA!
00564     xbee().printf("Saving timestamp value!");
00565     
00566     if (!timefile_txt.write("/local/newtime.txt")) {
00567         xbee().printf("\n\rERROR: (SAVE)Failure to write time.txt file.");
00568         }
00569 else {
00570         xbee().printf("\n\rFile newtime.txt successfully written.\n\r");
00571     } 
00572 }
00573 int ConfigFileIO::load_DEPTH_config() {
00574     ConfigFile cfg;
00575     int count = 0;
00576     if (!cfg.read("/local/depth.txt")) {
00577             error("DEPTH File Read Error");
00578     }
00579     char value[BUFSIZ];
00580     
00581     if (cfg.getValue("PGain", &value[0] , sizeof(value))) {
00582         depthLoop().setControllerP(atof(value));
00583         count++;
00584     }
00585     if (cfg.getValue("IGain", &value[0] ,sizeof(value))) {
00586         depthLoop().setControllerI(atof(value));
00587         count++;
00588     }
00589     if (cfg.getValue("DGain", &value[0] , sizeof(value))) {
00590         depthLoop().setControllerD(atof(value));
00591         count++;
00592     }
00593     if (cfg.getValue("filterWn", &value[0], sizeof(value))) {
00594         depthLoop().setFilterFrequency(atof(value));
00595         count++;
00596     }
00597     if (cfg.getValue("deadband", &value[0], sizeof(value))) {
00598         depthLoop().setDeadband(atof(value));
00599         count++;
00600     }
00601     if (cfg.getValue("zeroOffset", &value[0], sizeof(value))) {
00602         depthLoop().setOutputOffset(atof(value));
00603         count++;
00604     }    
00605     return count;
00606 }
00607 
00608 int ConfigFileIO::load_PITCH_config() {
00609     ConfigFile cfg;
00610     int count = 0;
00611     if (!cfg.read("/local/pitch.txt")){
00612             error("PITCH File Read Error");
00613     }
00614     char value[BUFSIZ];
00615     
00616     if (cfg.getValue("PGain", &value[0] , sizeof(value))) {
00617         pitchLoop().setControllerP(atof(value));
00618         count++;
00619     }
00620     if (cfg.getValue("IGain", &value[0] ,sizeof(value))) {
00621         pitchLoop().setControllerI(atof(value));
00622         count++;
00623     }
00624     if (cfg.getValue("DGain", &value[0] , sizeof(value))) {
00625         pitchLoop().setControllerD(atof(value));
00626         count++;
00627     }
00628     if (cfg.getValue("filterWn", &value[0], sizeof(value))) {
00629         pitchLoop().setFilterFrequency(atof(value));
00630         count++;
00631     }
00632     if (cfg.getValue("deadband", &value[0], sizeof(value))) {
00633         pitchLoop().setDeadband(atof(value));
00634         count++;
00635     }
00636     
00637     if (cfg.getValue("zeroOffset", &value[0], sizeof(value))) {
00638         pitchLoop().setOutputOffset(atof(value));
00639         count++;
00640     }     
00641     return count;
00642 }
00643 
00644 int ConfigFileIO::load_HEADING_config() {
00645     ConfigFile cfg;
00646     int count = 0;
00647     if (!cfg.read("/local/heading.txt")){
00648             error("HEADING File Read Error");
00649     }
00650     char value[BUFSIZ];
00651     
00652     if (cfg.getValue("PGain", &value[0] , sizeof(value))) {
00653         headingLoop().setControllerP(atof(value));
00654         count++;
00655     }
00656     if (cfg.getValue("IGain", &value[0] ,sizeof(value))) {
00657         headingLoop().setControllerI(atof(value));
00658         count++;
00659     }
00660     if (cfg.getValue("DGain", &value[0] , sizeof(value))) {
00661         headingLoop().setControllerD(atof(value));
00662         count++;
00663     }
00664     if (cfg.getValue("filterWn", &value[0], sizeof(value))) {
00665         headingLoop().setFilterFrequency(atof(value));
00666         count++;
00667     }
00668     if (cfg.getValue("deadband", &value[0], sizeof(value))) {
00669         headingLoop().setDeadband(atof(value));
00670         count++;
00671     }
00672     
00673     if (cfg.getValue("zeroOffset", &value[0], sizeof(value))) {
00674         headingLoop().setOutputOffset(atof(value));
00675         count++;
00676     }     
00677     return count;
00678 }
00679 
00680 int ConfigFileIO::load_RUDDER_config() {
00681     ConfigFile cfg;
00682     int count = 0;
00683     if (!cfg.read("/local/rudder.txt")){
00684             error("RUDDER File Read Error");
00685     }
00686     char value[BUFSIZ];
00687     
00688     //float values below
00689     if (cfg.getValue("setMinDeg", &value[0] , sizeof(value))) {
00690         rudder().setMinDeg(atof(value));
00691         count++;
00692     }
00693     if (cfg.getValue("setMaxDeg", &value[0] ,sizeof(value))) {
00694         rudder().setMaxDeg(atof(value));
00695         count++;
00696     }
00697     
00698     //integer values below
00699     if (cfg.getValue("setCenterPWM", &value[0] , sizeof(value))) {
00700         rudder().setCenterPWM(atof(value));
00701         count++;
00702     }
00703     if (cfg.getValue("setMinPWM", &value[0], sizeof(value))) {
00704         rudder().setMinPWM(atof(value));
00705         count++;
00706     }
00707     if (cfg.getValue("setMaxPWM", &value[0], sizeof(value))) {
00708         rudder().setMaxPWM(atof(value));
00709         count++;
00710     }
00711     return count;
00712 }