Homepage Demos Overview Downloads Tutorials Reference
Credits
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Search

Config.cc

Go to the documentation of this file.
00001 #include <Shared/Config.h>
00002 #include <stdio.h>
00003 #include <string>
00004 #include <ctype.h>
00005 
00006 Config* config=NULL;
00007 
00008 void Config::readConfig(const char* filename) {
00009   FILE* fp = fopen(filename, "r");
00010   char buf[80], key[30], value[50];
00011   section_t section=sec_invalid;
00012   if (fp==NULL) return; // ALTODO
00013   
00014   while (fscanf(fp,"%79[^\n]\n", buf)!=EOF) {
00015     if (sscanf(buf,"[%29[^]]",key)>0) {
00016       if (strncasecmp(key,"wireless",29)==0) {
00017         section=sec_wireless;
00018       } else if (strncasecmp(key,"vision",29)==0) {
00019         section=sec_vision;
00020       } else if (strncasecmp(key,"main",29)==0) {
00021         section=sec_main;
00022       } else if (strncasecmp(key,"behaviors",29)==0) {
00023         section=sec_behaviors;
00024       } else if (strncasecmp(key,"controller",29)==0) {
00025         section=sec_controller;
00026       } else if (strncasecmp(key,"motion",29)==0) {
00027         section=sec_motion;
00028       } else if (strncasecmp(key,"worldmodel2",29)==0) {
00029         section=sec_worldmodel2;
00030       } else if (strncasecmp(key,"sound",29)==0) {
00031         section=sec_sound;
00032       } else {
00033         section=sec_invalid;
00034       }
00035     } else if (sscanf(buf,"%29[^=]=%49s",key,value)>1) {
00036       switch (section) {
00037       case sec_wireless:
00038         if (strncasecmp(key,"id",29)==0) {
00039           wireless.id=atoi(value);
00040         }
00041         break;
00042       case sec_vision:
00043         if (strncasecmp(key,"white_balance",29)==0) {
00044           if (strncasecmp(value,"indoor",49)==0) {
00045             vision.white_balance=1;
00046           } else if (strncasecmp(value,"flourescent",49)==0) {
00047             vision.white_balance=3;
00048           } else if (strncasecmp(value,"outdoor",49)==0) {
00049             vision.white_balance=2;
00050           }
00051         } else if (strncasecmp(key,"gain",29)==0) {
00052           if (strncasecmp(value,"low",49)==0) {
00053             vision.gain=1;
00054           } else if (strncasecmp(value,"mid",49)==0) {
00055             vision.gain=2;
00056           } else if (strncasecmp(value,"high",49)==0) {
00057             vision.gain=3;
00058           }
00059         } else if (strncasecmp(key,"shutter_speed",29)==0) {
00060           if (strncasecmp(value,"slow",49)==0) {
00061             vision.shutter_speed=1;
00062           } else if (strncasecmp(value,"mid",49)==0) {
00063             vision.shutter_speed=2;
00064           } else if (strncasecmp(value,"fast",49)==0) {
00065             vision.shutter_speed=3;
00066           }
00067         } else if (strncasecmp(key,"resolution",29)==0) {
00068           if (strncasecmp(value,"full",49)==0) {
00069             vision.resolution=1;
00070           } else if (strncasecmp(value,"half",49)==0) {
00071             vision.resolution=2;
00072           } else if (strncasecmp(value,"quarter",49)==0) {
00073             vision.resolution=3;
00074           }
00075         } else if (strncasecmp(key,"thresh",29)==0) {
00076           strncpy(vision.thresh,value,49);
00077         } else if (strncasecmp(key,"colors",29)==0) {
00078           strncpy(vision.colors,value,49);
00079         } else if (strncasecmp(key,"raw_port",29)==0) {
00080           vision.raw_port=atoi(value);
00081         } else if (strncasecmp(key,"rle_port",29)==0) {
00082           vision.rle_port=atoi(value);
00083         } else if (strncasecmp(key,"obj_port",29)==0) {
00084           vision.obj_port=atoi(value);
00085         }
00086         break;
00087       case sec_main:
00088         if (strncasecmp(key,"console_port",29)==0) {
00089           main.console_port=atoi(value);
00090         } else if (strncasecmp(key,"stderr_port",29)==0) {
00091           main.stderr_port=atoi(value);
00092         } else if (strncasecmp(key,"error_level",29)==0) {
00093           main.error_level=atoi(value);
00094         } else if (strncasecmp(key,"debug_level",29)==0) {
00095           main.debug_level=atoi(value);
00096         } else if (strncasecmp(key,"verbose_level",29)==0) {
00097           main.verbose_level=atoi(value);
00098         } else if (strncasecmp(key,"wsjoints_port",29)==0) {
00099           main.wsjoints_port=atoi(value);
00100         } else if (strncasecmp(key,"wspids_port",29)==0) {
00101           main.wspids_port=atoi(value);
00102         } else if (strncasecmp(key,"headControl_port",29)==0) {
00103           main.headControl_port=atoi(value);
00104         } else if (strncasecmp(key,"walkControl_port",29)==0) {
00105           main.walkControl_port=atoi(value);
00106         } else if (strncasecmp(key,"estopControl_port",29)==0) {
00107           main.estopControl_port=atoi(value);
00108         } else if (strncasecmp(key,"aibo3d_port",29)==0) {
00109           main.aibo3d_port=atoi(value);
00110         } else if (strncasecmp(key,"use_VT100",29)==0) {
00111           main.use_VT100=extractBool(value);
00112         }
00113         break;
00114       case sec_behaviors:
00115         break;
00116       case sec_controller:
00117         if (strncasecmp(key,"gui_port",29)==0)
00118           controller.gui_port = atoi(value);
00119         else if (strncasecmp(key,"select_snd",29)==0)
00120           strncpy(controller.select_snd,value,49);
00121         else if (strncasecmp(key,"next_snd",29)==0)
00122           strncpy(controller.next_snd,value,49);
00123         else if (strncasecmp(key,"prev_snd",29)==0)
00124           strncpy(controller.prev_snd,value,49);
00125         else if (strncasecmp(key,"read_snd",29)==0)
00126           strncpy(controller.read_snd,value,49);
00127         else if (strncasecmp(key,"cancel_snd",29)==0)
00128           strncpy(controller.cancel_snd,value,49);
00129         break;
00130       case sec_motion:
00131         if (strncasecmp(key,"root",29)==0)
00132           motion.root=value;
00133         else if (strncasecmp(key,"estop_on_snd",29)==0)
00134           strncpy(motion.estop_on_snd,value,49);
00135         else if (strncasecmp(key,"estop_off_snd",29)==0)
00136           strncpy(motion.estop_off_snd,value,49);
00137         break;
00138       case sec_worldmodel2:
00139         if (strncasecmp(key,"dm_port",29)==0)
00140           worldmodel2.dm_port = atoi(value);
00141         else if (strncasecmp(key,"hm_port",29)==0)
00142           worldmodel2.hm_port = atoi(value);
00143         else if (strncasecmp(key,"gm_port",29)==0)
00144           worldmodel2.gm_port = atoi(value);
00145         else if (strncasecmp(key,"fs_port",29)==0)
00146           worldmodel2.fs_port = atoi(value);
00147         break;
00148       case sec_sound:
00149         if (strncasecmp(key,"root",29)==0)
00150           sound.root=value;
00151         else if (strncasecmp(key,"sample_rate",29)==0)
00152           sound.sample_rate = atoi(value);
00153         else if (strncasecmp(key,"sample_bits",29)==0)
00154           sound.sample_bits = atoi(value);
00155         else if (strncasecmp(key,"preload",29)==0)
00156           sound.preload.push_back(value);
00157         break;
00158       default:
00159         break;
00160       }
00161     }
00162   }
00163   fclose(fp);
00164 }
00165 
00166 bool Config::extractBool(const char * value) {
00167   int i=0;
00168   while(isspace(value[i])) i++;
00169   if(strncasecmp(&value[i],"t",29)==0)
00170     return true;
00171   else if(strncasecmp(&value[i],"f",29)==0)
00172     return false;
00173   else if(strncasecmp(&value[i],"true",29)==0)
00174     return true;
00175   else if(strncasecmp(&value[i],"false",29)==0)
00176     return false;
00177   else if(strncasecmp(&value[i],"y",29)==0)
00178     return true;
00179   else if(strncasecmp(&value[i],"n",29)==0)
00180     return false;
00181   else if(strncasecmp(&value[i],"yes",29)==0)
00182     return true;
00183   else if(strncasecmp(&value[i],"no",29)==0)
00184     return false;
00185   else
00186     return atoi(value);
00187 }
00188 
00189 /*! @file
00190  * @brief Implements Config, which provides global access to system configuration information
00191  * @author alokl (Creator)
00192  *
00193  * $Author: ejt $
00194  * $Name: tekkotsu-1_4_1 $
00195  * $Revision: 1.14 $
00196  * $State: Exp $
00197  * $Date: 2003/07/07 04:32:47 $
00198  */
00199 

Tekkotsu v1.4
Generated Sat Jul 19 00:06:29 2003 by Doxygen 1.3.2