00001
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef _SIM_PHENOMENA_H_
00036 #define _SIM_PHENOMENA_H_
00037
00038 #include <iostream>
00039 #include <vector>
00040
00041
00042
00043 extern "C" {
00044 enum {
00045 TOS_ADC_PHOTO_PORT = 1,
00046 TOS_ADC_TEMP_PORT = 2,
00047 TOS_ADC_MIC_PORT = 3,
00048 TOS_ADC_ACCEL_X_PORT = 4,
00049 TOS_ADC_ACCEL_Y_PORT = 5,
00050 TOS_ADC_MAG_X_PORT = 6,
00051
00052 TOS_ADC_MAG_Y_PORT = 8,
00053 };
00054 }
00055
00056
00057 enum Phenom {
00058 NONE,
00059
00060 AMBSOUND, AMBLIGHT, AMBTEMP, AMBRAD,
00061
00062 SOUND, LIGHT, ACCEL_X, ACCEL_Y, MAG_X, MAG_Y, RAD,
00063
00064 STARTSOUND, STARTLIGHT, STARTTEMP, STARTRAD,
00065 STARTACCEL_X, STARTACCEL_Y, STARTMAG_X, STARTMAG_Y,
00066
00067 Phenom_MIN = NONE,
00068 Phenom_MAX = STARTMAG_Y,
00069 Phenom_SIZE = (Phenom_MAX - Phenom_MIN),
00070 };
00071
00072 inline Phenom &operator++(Phenom &p)
00073 {
00074 return p = Phenom(p + 1);
00075 }
00076
00077 inline Phenom &operator++(Phenom &p, int)
00078 {
00079 return p = Phenom(p + 1);
00080 }
00081
00082 static const char* phenoms[] = {
00083 "None",
00084 "Ambient Sound", "Ambient Light", "Ambient Temperature", "Ambient Radiation",
00085 "Sound", "Light", "Vibration", "Vibration",
00086 "Magnetic Flux", "Magnetic Flux", "Radiation",
00087
00088 "Default Sound", "Default Light", "Default Temperature", "Default Radiation",
00089 "Default Vibration", "Default Vibration",
00090 "Default Magnetic Flux", "Default Magnetic Flux",
00091 };
00092
00093 static const unsigned char tossim_ports[] = {
00094 -1,
00095 TOS_ADC_MIC_PORT, TOS_ADC_PHOTO_PORT, TOS_ADC_TEMP_PORT, 44,
00096 TOS_ADC_MIC_PORT, TOS_ADC_PHOTO_PORT,
00097 TOS_ADC_ACCEL_X_PORT, TOS_ADC_ACCEL_Y_PORT,
00098 TOS_ADC_MAG_X_PORT, TOS_ADC_MAG_Y_PORT, 44,
00099 TOS_ADC_MIC_PORT, TOS_ADC_PHOTO_PORT, TOS_ADC_TEMP_PORT, 44,
00100 TOS_ADC_ACCEL_X_PORT, TOS_ADC_ACCEL_Y_PORT,
00101 TOS_ADC_MAG_X_PORT, TOS_ADC_MAG_Y_PORT,
00102 };
00103
00104
00105 static double distance(double x1, double y1, double x2, double y2)
00106 {
00107 double x_diff = x1 - x2;
00108 double y_diff = y1 - y2;
00109 return sqrt((x_diff * x_diff) + (y_diff * y_diff));
00110 }
00111
00112
00113 class Phenomenon {
00114 protected:
00115 const Phenom _type;
00116 const std::string _string;
00117 const std::string _color;
00118 const bool _ambient;
00119 unsigned short _sample_rate;
00120 bool _global;
00121 int style;
00122
00123 public:
00124 Phenomenon(Phenom t=NONE, std::string s=phenoms[NONE],
00125 std::string c="white", bool amb=false, bool glob=false);
00126 virtual ~Phenomenon() {};
00127 bool isGlobal() { return _global; };
00128 const char* toString(bool cfg=false);
00129 Phenom getType() { return _type; };
00130 unsigned short getRate() { return _sample_rate; };
00131 void setRate(unsigned short rate) { _sample_rate = rate; };
00132 const char* getColor() { return _color.c_str(); };
00133 bool isAmbient() { return _ambient; };
00134 virtual double fadeRate(double dist) {
00135 return (1.0 / (4.0 * M_PI * dist * dist));
00136 };
00137 virtual double fadeDistance(double strength) {
00138 return sqrt(strength / (4 * M_PI)) + 1.0;
00139 };
00140 virtual void toOutput(FILE *stream, unsigned long long time,
00141 unsigned short node, unsigned short strength,
00142 int x1, int y1, int x2, int y2);
00143 static Phenomenon* PhenomenonFactory(Phenom t);
00144 };
00145
00146
00147
00148 class SensorData {
00149 public:
00150 SensorData(Phenom t, int x, int y, SensorData *n=NULL);
00151 SensorData(Phenom t, char* line, SensorData *n);
00152 bool operator==(const SensorData &other);
00153 bool operator!=(const SensorData &other);
00154 bool operator<(const SensorData &other) const;
00155 const char* toString(bool cfg=false);
00156 unsigned int distanceTo(const SensorData &other);
00157
00158 Phenomenon *source;
00159 unsigned int x, y;
00160 int strength;
00161 bool on_path;
00162 unsigned long long time;
00163 unsigned long speed;
00164 SensorData *prev;
00165 };
00166
00167
00168 int compute_adc(const char* scenario, const char* network, const char* adc);
00169 int read_scenario(FILE *file, std::vector<SensorData> &data);
00170
00171
00172
00173 class Sound : public Phenomenon {
00174 public:
00175 Sound(Phenom t=SOUND, std::string s=phenoms[SOUND], bool global=false);
00176 double fadeRate(double dist);
00177 double fadeDistance(double strength);
00178 };
00179
00180
00181 class Light : public Phenomenon {
00182 public:
00183 Light(Phenom t=LIGHT, std::string s=phenoms[LIGHT], bool global=false);
00184 };
00185
00186
00187 class Accel : public Phenomenon {
00188 public:
00189 Accel(Phenom t=ACCEL_X, std::string s=phenoms[ACCEL_X], bool global=false);
00190 double fadeRate(double dist);
00191 double fadeDistance(double strength);
00192 void toOutput(FILE *stream, unsigned long long time,
00193 unsigned short node, unsigned short strength,
00194 int x1, int y1, int x2, int y2);
00195 };
00196
00197
00198 class Mag : public Phenomenon {
00199 public:
00200 Mag(Phenom t=MAG_X, std::string s=phenoms[MAG_X], bool global=false);
00201 void toOutput(FILE *stream, unsigned long long time,
00202 unsigned short node, unsigned short strength,
00203 int x1, int y1, int x2, int y2);
00204 };
00205
00206
00207 class Rad : public Phenomenon {
00208 public:
00209 Rad(Phenom t=RAD, std::string s=phenoms[RAD], bool global=false);
00210 };
00211
00212
00213 class AmbientPhenomenon : public Phenomenon {
00214 protected:
00215 const unsigned int _range;
00216
00217 public:
00218 AmbientPhenomenon(Phenom t=NONE, std::string s=phenoms[NONE],
00219 unsigned int i=0, std::string c="white", bool g=false);
00220 virtual double fadeRate(double dist) { return 1.0; };
00221 virtual double fadeDistance(double stren) { return _range; };
00222 unsigned int getRange() { return _range; };
00223 };
00224
00225
00226 class AmbientSound : public AmbientPhenomenon {
00227 public:
00228 AmbientSound(Phenom t=AMBSOUND, std::string s=phenoms[AMBSOUND],
00229 unsigned int i=250);
00230 };
00231
00232
00233 class AmbientLight : public AmbientPhenomenon {
00234 public:
00235 AmbientLight(Phenom t=AMBLIGHT, std::string s=phenoms[AMBLIGHT],
00236 unsigned int i=200);
00237 };
00238
00239
00240 class AmbientTemp : public AmbientPhenomenon {
00241 public:
00242 AmbientTemp(Phenom t=AMBTEMP, std::string s=phenoms[AMBTEMP],
00243 unsigned int i=300, bool g=false);
00244 };
00245
00246
00247 class AmbientRad : public AmbientPhenomenon {
00248 public:
00249 AmbientRad(Phenom t=AMBRAD, std::string s=phenoms[AMBRAD],
00250 unsigned int i=150);
00251 };
00252
00253
00254 #endif // _SIM_PHENOMENA_H_