00001
00002 #ifndef INCLUDED_Config_h
00003 #define INCLUDED_Config_h
00004
00005 #include <vector>
00006 #include <string>
00007 #include "RobotInfo.h"
00008 #include <jpeglib.h>
00009
00010
00011 class Config {
00012 public:
00013
00014 Config(const char* filename)
00015 : wireless(), vision(), main(), behaviors(), controller(), motion(),
00016 worldmodel2(), sound()
00017 { readConfig(filename); }
00018
00019 ~Config() {}
00020
00021
00022 enum section_t {
00023 sec_wireless=0,
00024 sec_vision,
00025 sec_main,
00026 sec_behaviors,
00027 sec_controller,
00028 sec_motion,
00029 sec_worldmodel2,
00030 sec_sound,
00031 sec_invalid
00032 };
00033
00034
00035 struct wireless_config {
00036 int id;
00037
00038 wireless_config () : id(1) {}
00039 } wireless;
00040
00041
00042 struct vision_config {
00043 int white_balance;
00044 int gain;
00045 int shutter_speed;
00046 int resolution;
00047 std::vector<std::string> thresh;
00048 char colors[50];
00049 int rawcam_port;
00050 int rle_port;
00051 int obj_port;
00052 bool restore_image;
00053 J_DCT_METHOD jpeg_dct_method;
00054
00055
00056 enum encoding_t {
00057 ENCODE_COLOR,
00058 ENCODE_SINGLE_CHANNEL,
00059 };
00060 encoding_t rawcam_encoding;
00061 int rawcam_channel;
00062
00063
00064 enum compression_t {
00065 COMPRESS_NONE,
00066 COMPRESS_JPEG,
00067 COMPRESS_RLE
00068 };
00069 compression_t rawcam_compression;
00070
00071 int rawcam_compress_quality;
00072 int rawcam_y_skip;
00073 int rawcam_uv_skip;
00074 int rlecam_skip;
00075 int rlecam_channel;
00076 compression_t rlecam_compression;
00077
00078
00079 vision_config() : white_balance(3), gain(2), shutter_speed(2), resolution(2), thresh(), colors(), rawcam_port(0), rle_port(0), obj_port(0), restore_image(true), jpeg_dct_method(JDCT_IFAST), rawcam_encoding(ENCODE_COLOR), rawcam_channel(0), rawcam_compression(COMPRESS_NONE), rawcam_compress_quality(75), rawcam_y_skip(0), rawcam_uv_skip(0), rlecam_skip(1), rlecam_channel(0), rlecam_compression(COMPRESS_RLE) {}
00080 } vision;
00081
00082
00083 struct main_config {
00084 int console_port;
00085 int stderr_port;
00086 int error_level;
00087 int debug_level;
00088 int verbose_level;
00089 int wsjoints_port;
00090 int wspids_port;
00091 int headControl_port;
00092 int walkControl_port;
00093 int estopControl_port;
00094 int aibo3d_port;
00095 int wmmonitor_port;
00096 bool use_VT100;
00097
00098
00099 main_config()
00100 : console_port(0), stderr_port(0), error_level(0), debug_level(0),
00101 verbose_level(0),wsjoints_port(0),wspids_port(0),headControl_port(0),
00102 walkControl_port(0),estopControl_port(0),aibo3d_port(0),
00103 wmmonitor_port(0), use_VT100(true)
00104 { }
00105 } main;
00106
00107
00108 struct behaviors_config {
00109 } behaviors;
00110
00111
00112 struct controller_config {
00113 int gui_port;
00114 char select_snd[50];
00115 char next_snd[50];
00116 char prev_snd[50];
00117 char read_snd[50];
00118 char cancel_snd[50];
00119 char error_snd[50];
00120
00121
00122 controller_config() : gui_port(0) {
00123 select_snd[0]=next_snd[0]=prev_snd[0]=read_snd[0]=cancel_snd[0]=error_snd[0]='\0';
00124 }
00125 } controller;
00126
00127
00128 struct motion_config {
00129 std::string root;
00130 std::string walk;
00131 char estop_on_snd[50];
00132 char estop_off_snd[50];
00133 float max_head_tilt_speed;
00134 float max_head_pan_speed;
00135 float max_head_roll_speed;
00136
00137
00138 std::string makePath(std::string name) {
00139 if(name[0]=='/')
00140 return name;
00141 if(root[root.size()-1]=='/')
00142 return root+name;
00143 else
00144 return root+"/"+name;
00145 }
00146
00147
00148 motion_config() : root(), walk(), max_head_tilt_speed(0), max_head_pan_speed(0), max_head_roll_speed(0) {
00149 estop_on_snd[0]=estop_off_snd[0]='\0';
00150 max_head_tilt_speed=0;
00151 max_head_pan_speed=0;
00152 max_head_roll_speed=0;
00153 }
00154 } motion;
00155
00156
00157 struct worldmodel2_config {
00158
00159
00160 int dm_port, hm_port, gm_port, fs_port;
00161
00162
00163 worldmodel2_config() : dm_port(0), hm_port(0), gm_port(0), fs_port(0) {}
00164 } worldmodel2;
00165
00166
00167 struct sound_config {
00168 std::string root;
00169 unsigned int volume;
00170 unsigned int sample_rate;
00171 unsigned int sample_bits;
00172 std::vector<std::string> preload;
00173
00174
00175 std::string makePath(std::string name) {
00176 if(name[0]=='/')
00177 return name;
00178 if(root[root.size()-1]=='/')
00179 return root+name;
00180 else
00181 return root+"/"+name;
00182 }
00183
00184
00185 sound_config() : root(), volume(0xF600), sample_rate(0), sample_bits(0), preload() {}
00186 } sound;
00187
00188
00189 void readConfig(const char* filename);
00190
00191 section_t parseSection(const char* key);
00192
00193 void* setValue(section_t section, const char *key, const char *value, bool updated=false);
00194
00195
00196 protected:
00197
00198 bool matchNoCase(const std::string& model, const std::string& pattern);
00199
00200
00201 static bool extractBool(const char* value);
00202 };
00203
00204
00205 extern Config* config;
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218 #endif