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 #include <stdlib.h>
00036 #include <float.h>
00037 #include <math.h>
00038 #include <sys/time.h>
00039 #include <time.h>
00040 #include <pthread.h>
00041
00042 #include "sensing.h"
00043 #include "sensix.h"
00044 #include "sense_impl.h"
00045
00046 using namespace sensix;
00047 using namespace sensix::sensing;
00048
00049
00050 static pthread_mutex_t seq_mutex = PTHREAD_MUTEX_INITIALIZER;
00051 static unsigned int SEQUENCE = 0;
00052 #define MAX_SEQ 16777215
00053
00054
00055 FunctorImpl::FunctorImpl(FunctorList *subfs) : Functor()
00056 {
00057 id = INVALID;
00058 subs = subfs;
00059 data_set = new Series();
00060 errs = new ErrorList();
00061
00062 pthread_mutex_lock(&seq_mutex);
00063 seq_num = SEQUENCE;
00064 SEQUENCE++;
00065 if (SEQUENCE == MAX_SEQ)
00066 SEQUENCE = 0;
00067 pthread_mutex_unlock(&seq_mutex);
00068 }
00069
00070 FunctorImpl::FunctorImpl() : Functor()
00071 {
00072 id = INVALID;
00073 subs = new FunctorList();
00074 data_set = new Series();
00075 errs = new ErrorList();
00076
00077 pthread_mutex_lock(&seq_mutex);
00078 seq_num = SEQUENCE;
00079 SEQUENCE++;
00080 if (SEQUENCE == MAX_SEQ)
00081 SEQUENCE = 0;
00082 pthread_mutex_unlock(&seq_mutex);
00083 }
00084
00085 FunctorImpl::FunctorImpl(FunctorList *subfs, unsigned int seq) : Functor()
00086 {
00087 id = INVALID;
00088 subs = subfs;
00089 data_set = new Series();
00090 errs = new ErrorList();
00091 seq_num = seq;
00092 }
00093
00094 FunctorImpl::FunctorImpl(unsigned int seq) : Functor()
00095 {
00096 id = INVALID;
00097 subs = new FunctorList();
00098 data_set = new Series();
00099 errs = new ErrorList();
00100 seq_num = seq;
00101 }
00102
00103
00104
00105 uint8_t FunctorImpl::identifier()
00106 {
00107 return id;
00108 }
00109
00110 unsigned int FunctorImpl::sequencer()
00111 {
00112 return seq_num;
00113 }
00114
00115 Series* FunctorImpl::results()
00116 {
00117 return data_set;
00118 }
00119
00120 void FunctorImpl::results(Series &data)
00121 {
00122 Series *tmp = data_set;
00123 data_set = &data;
00124 delete tmp;
00125 }
00126
00127 ErrorList* FunctorImpl::errors()
00128 {
00129 return errs;
00130 }
00131
00132 void FunctorImpl::errors(ErrorList &e)
00133 {
00134 ErrorList *tmp = errs;
00135 errs = &e;
00136 delete tmp;
00137 }
00138
00139 uint8_t FunctorImpl::priority()
00140 {
00141 return importance;
00142 }
00143
00144 void FunctorImpl::priority(uint8_t p)
00145 {
00146 importance = p;
00147 }
00148
00149 FunctorList* FunctorImpl::subfunctors()
00150 {
00151 return subs;
00152 }
00153
00154 void FunctorImpl::subfunctors(FunctorList &fs)
00155 {
00156 FunctorList *tmp = subs;
00157 subs = &fs;
00158 delete tmp;
00159 }
00160
00161 char *FunctorImpl::asString()
00162 {
00163 return CORBA::string_dup("functor(invalid)");
00164 }
00165
00166
00167
00168 SensoryImpl::SensoryImpl(uint8_t l, uint8_t s, FunctorList *subfs) : Sensory()
00169 {
00170 delegate = new FunctorImpl(subfs);
00171 h_level = l;
00172 sense = s;
00173 }
00174
00175 SensoryImpl::SensoryImpl(uint8_t l, uint8_t s) : Sensory()
00176 {
00177 delegate = new FunctorImpl();
00178 h_level = l;
00179 sense = s;
00180 }
00181
00182 SensoryImpl::SensoryImpl(FunctorList *subfs) : Sensory()
00183 {
00184 delegate = new FunctorImpl(subfs);
00185 h_level = INVALID;
00186 sense = INVALID;
00187 }
00188
00189 SensoryImpl::SensoryImpl() : Sensory()
00190 {
00191 delegate = new FunctorImpl();
00192 h_level = INVALID;
00193 sense = INVALID;
00194 }
00195
00196 SensoryImpl::SensoryImpl(uint8_t l, uint8_t s, FunctorList *subfs,
00197 unsigned int seq) : Sensory()
00198 {
00199 delegate = new FunctorImpl(subfs, seq);
00200 h_level = l;
00201 sense = s;
00202 }
00203
00204 SensoryImpl::SensoryImpl(uint8_t l, uint8_t s, unsigned int seq) : Sensory()
00205 {
00206 delegate = new FunctorImpl(seq);
00207 h_level = l;
00208 sense = s;
00209 }
00210
00211
00212 uint8_t SensoryImpl::level()
00213 {
00214 return h_level;
00215 }
00216
00217 uint8_t SensoryImpl::sensor()
00218 {
00219 return sense;
00220 }
00221
00222 unsigned long long SensoryImpl::timeused()
00223 {
00224 return time;
00225 }
00226
00227 void SensoryImpl::timeused(unsigned long long t)
00228 {
00229 time = t;
00230 }
00231
00232 double SensoryImpl::energyused()
00233 {
00234 return energy;
00235 }
00236
00237 void SensoryImpl::energyused(double e)
00238 {
00239 energy = e;
00240 }
00241
00242 char *SensoryImpl::asString()
00243 {
00244 return delegate->asString();
00245 }
00246
00247 uint8_t SensoryImpl::identifier()
00248 {
00249 return delegate->identifier();
00250 }
00251
00252 unsigned int SensoryImpl::sequencer()
00253 {
00254 return delegate->sequencer();
00255 }
00256
00257 Series *SensoryImpl::results()
00258 {
00259 return delegate->results();
00260 }
00261
00262 void SensoryImpl::results(Series &data)
00263 {
00264 delegate->results(data);
00265 }
00266
00267 ErrorList *SensoryImpl::errors()
00268 {
00269 return delegate->errors();
00270 }
00271
00272 void SensoryImpl::errors(ErrorList &e)
00273 {
00274 delegate->errors(e);
00275 }
00276
00277 uint8_t SensoryImpl::priority()
00278 {
00279 return delegate->priority();
00280 }
00281
00282 void SensoryImpl::priority(uint8_t p)
00283 {
00284 delegate->priority();
00285 }
00286
00287 FunctorList *SensoryImpl::subfunctors()
00288 {
00289 return delegate->subfunctors();
00290 }
00291
00292 void SensoryImpl::subfunctors(FunctorList &fs)
00293 {
00294 delegate->subfunctors(fs);
00295 }
00296
00297
00298
00299 CollectionImpl::CollectionImpl(uint8_t l, Sensory_ptr s) : Collection()
00300 {
00301 FunctorList *array = new FunctorList();
00302 array->length(1);
00303 (*array)[0] = s;
00304 delegate = new SensoryImpl(l, s->sensor(), array);
00305 sensory = s;
00306 data = new Series();
00307 }
00308
00309 CollectionImpl::CollectionImpl(Sensory_ptr s) : Collection()
00310 {
00311 FunctorList *array = new FunctorList();
00312 array->length(1);
00313 (*array)[0] = s;
00314 delegate = new SensoryImpl(array);
00315 sensory = s;
00316 data = new Series();
00317 }
00318
00319 CollectionImpl::CollectionImpl(uint8_t l, Sensory_ptr s, unsigned int seq) :
00320 Collection()
00321 {
00322 FunctorList *array = new FunctorList();
00323 array->length(1);
00324 (*array)[0] = s;
00325 delegate = new SensoryImpl(l, s->sensor(), array, seq);
00326 sensory = s;
00327 data = new Series();
00328 }
00329
00330
00331 Sensory_ptr CollectionImpl::sense()
00332 {
00333 return sensory;
00334 }
00335
00336 void CollectionImpl::sense(Sensory_ptr s)
00337 {
00338 if (s != NULL)
00339 sensory = s;
00340 }
00341
00342 uint8_t CollectionImpl::sensor()
00343 {
00344 return sensory->sensor();
00345 }
00346
00347 unsigned long long CollectionImpl::timeused()
00348 {
00349 return sensory->timeused();
00350 }
00351
00352 double CollectionImpl::energyused()
00353 {
00354 return sensory->energyused();
00355 }
00356
00357 uint8_t CollectionImpl::priority()
00358 {
00359 return sensory->priority();
00360 }
00361
00362 void CollectionImpl::priority(uint8_t p)
00363 {
00364 sensory->priority(p);
00365 }
00366
00367 Series* CollectionImpl::results()
00368 {
00369 return data;
00370 }
00371
00372 void CollectionImpl::results(Series &d)
00373 {
00374 unsigned int pos = data->length();
00375 data->length(pos + d.length());
00376 for (unsigned int i = 0; i < d.length(); i++)
00377 (*data)[pos + i] = d[i];
00378 }
00379
00380 ErrorList* CollectionImpl::errors()
00381 {
00382 return sensory->errors();
00383 }
00384
00385
00386 char *CollectionImpl::asString()
00387 {
00388 return delegate->asString();
00389 }
00390
00391 uint8_t CollectionImpl::identifier()
00392 {
00393 return delegate->identifier();
00394 }
00395
00396 unsigned int CollectionImpl::sequencer()
00397 {
00398 return delegate->sequencer();
00399 }
00400
00401 uint8_t CollectionImpl::level()
00402 {
00403 return delegate->level();
00404 }
00405
00406 FunctorList *CollectionImpl::subfunctors()
00407 {
00408 return delegate->subfunctors();
00409 }
00410
00411 void CollectionImpl::subfunctors(FunctorList &fs)
00412 {
00413 delegate->subfunctors(fs);
00414 }
00415
00416
00417
00418 AggregateImpl::AggregateImpl(char *n, uint8_t l, CollectionList *c) :
00419 Aggregate()
00420 {
00421 delegate = new SensoryImpl(l, INVALID, (FunctorList*)c);
00422 name = n;
00423 series = c;
00424 }
00425
00426 AggregateImpl::AggregateImpl(char *n, CollectionList *c) : Aggregate()
00427 {
00428 delegate = new SensoryImpl((FunctorList*)c);
00429 name = n;
00430 series = c;
00431 }
00432
00433 AggregateImpl::AggregateImpl(char *n, uint8_t l, CollectionList *c,
00434 unsigned int seq) : Aggregate()
00435 {
00436 delegate = new SensoryImpl(l, INVALID, (FunctorList*)c, seq);
00437 name = n;
00438 series = c;
00439 }
00440
00441
00442 SensoryList* AggregateImpl::senses()
00443 {
00444 unsigned int num = series->length();
00445 SensoryList *array = new SensoryList();
00446 array->length(num);
00447 for (unsigned int i = 0; i < num; i++) {
00448 Collection *c = (*series)[i];
00449 Sensory_ptr s = c->sense();
00450 (*array)[i] = s;
00451 }
00452 return array;
00453 }
00454
00455 CollectionList* AggregateImpl::collectors()
00456 {
00457 return series;
00458 }
00459
00460 void AggregateImpl::collectors(CollectionList *c)
00461 {
00462 series = c;
00463 }
00464
00465 Sensory_ptr AggregateImpl::sense()
00466 {
00467 Collection *c = (*series)[0];
00468 return c->sense();
00469 }
00470
00471 uint8_t AggregateImpl::sensor()
00472 {
00473 return INVALID;
00474 }
00475
00476 unsigned long long AggregateImpl::timeused()
00477 {
00478 unsigned long long max = 0;
00479 for (unsigned int i = 0; i < series->length(); i++) {
00480 Collection *c = (*series)[i];
00481 if (c->timeused() > max)
00482 max = c->timeused();
00483 }
00484 return max;
00485 }
00486
00487 double AggregateImpl::energyused()
00488 {
00489 double sum = 0.0;
00490 for (unsigned int i = 0; i < series->length(); i++) {
00491 Collection *c = (*series)[i];
00492 sum += c->energyused();
00493 }
00494 return sum;
00495 }
00496
00497 uint8_t AggregateImpl::priority()
00498 {
00499 uint8_t max = 0;
00500 for (unsigned int i = 0; i < series->length(); i++) {
00501 Collection *c = (*series)[i];
00502 if (c->priority() > max)
00503 max = c->priority();
00504 }
00505 return max;
00506 }
00507
00508 void AggregateImpl::priority(uint8_t p)
00509 {
00510 for (unsigned int i = 0; i < series->length(); i++) {
00511 Collection *c = (*series)[i];
00512 c->priority(p);
00513 }
00514 }
00515
00516 ErrorList* AggregateImpl::errors()
00517 {
00518 unsigned int num = 0, pos = 0;
00519 for (unsigned int i = 0; i < series->length(); i++) {
00520 Collection *c = (*series)[i];
00521 if (c->errors() != NULL)
00522 num += c->errors()->length();
00523 }
00524 ErrorList *e = new ErrorList();
00525 e->length(num);
00526 for (unsigned int i = 0; i < series->length(); i++) {
00527 Collection *c = (*series)[i];
00528 if (c->errors() != NULL && c->errors()->length() > 0) {
00529 for (unsigned int j = 0; j < c->errors()->length(); j++) {
00530 ErrorList *el = c->errors();
00531 (*e)[pos] = (*el)[j];
00532 pos++;
00533 }
00534 }
00535 }
00536 return e;
00537 }
00538
00539 char *AggregateImpl::asString()
00540 {
00541 char str[2048], lvl[64];
00542
00543 memset(lvl, 0, 64);
00544 memset(str, 0, 512);
00545 sprintf(str, "%s(", name);
00546 if (delegate->level() != INVALID) {
00547 sprintf(lvl, "level=%u,", delegate->level());
00548 strcat(str, lvl);
00549 }
00550
00551 for (unsigned int i = 0; i < series->length(); i ++) {
00552 Collection *c = (*series)[i];
00553 char *s_str = c->asString();
00554 strcat(str, s_str);
00555 CORBA::string_free(s_str);
00556 if (i < series->length() - 1)
00557 strcat(str, "&&");
00558 }
00559 strcat(str, ")");
00560
00561 return CORBA::string_dup(str);
00562 }
00563
00564
00565 uint8_t AggregateImpl::identifier()
00566 {
00567 return delegate->identifier();
00568 }
00569
00570 unsigned int AggregateImpl::sequencer()
00571 {
00572 return delegate->sequencer();
00573 }
00574
00575 uint8_t AggregateImpl::level()
00576 {
00577 return delegate->level();
00578 }
00579
00580 Series* AggregateImpl::results()
00581 {
00582 return delegate->results();
00583 }
00584
00585 void AggregateImpl::results(Series &d)
00586 {
00587 delegate->results(d);
00588 }
00589
00590 FunctorList *AggregateImpl::subfunctors()
00591 {
00592 return delegate->subfunctors();
00593 }
00594
00595 void AggregateImpl::subfunctors(FunctorList &fs)
00596 {
00597 delegate->subfunctors(fs);
00598 }
00599
00600
00601
00602 SenseImpl::SenseImpl(uint8_t l, uint8_t s, double r) : Sense()
00603 {
00604 delegate = new SensoryImpl(l, s);
00605 hz = r;
00606 }
00607
00608 SenseImpl::SenseImpl(uint8_t s, double r) : Sense()
00609 {
00610 delegate = new SensoryImpl(INVALID, s);
00611 hz = r;
00612 }
00613
00614 SenseImpl::SenseImpl(uint8_t l, uint8_t s) : Sense()
00615 {
00616 delegate = new SensoryImpl(l, s);
00617 hz = 0.0;
00618 }
00619
00620 SenseImpl::SenseImpl(uint8_t s) : Sense()
00621 {
00622 delegate = new SensoryImpl(INVALID, s);
00623 hz = 0.0;
00624 }
00625
00626 SenseImpl::SenseImpl(uint8_t l, uint8_t s, double r, unsigned int seq) : Sense()
00627 {
00628 delegate = new SensoryImpl(l, s, seq);
00629 hz = r;
00630 }
00631
00632
00633 double SenseImpl::rate()
00634 {
00635 return hz;
00636 }
00637
00638 void SenseImpl::rate(double r)
00639 {
00640 hz = r;
00641 }
00642
00643 uint8_t SenseImpl::identifier()
00644 {
00645 return ALPHA;
00646 }
00647
00648 char *SenseImpl::asString()
00649 {
00650 char str[2048], lvl[64], snsr[64], rt[64];
00651
00652 memset(rt, 0, 64);
00653 memset(snsr, 0, 64);
00654 memset(lvl, 0, 64);
00655 memset(str, 0, 512);
00656
00657 sprintf(str, "Sense(");
00658 if (delegate->level() != INVALID) {
00659 sprintf(lvl, "level=%u,", delegate->level());
00660 strcat(str, lvl);
00661 }
00662
00663 strcat(str, "sensor=");
00664 capabilityToString(snsr, delegate->sensor());
00665 strcat(str, snsr);
00666
00667 if (hz > 0.0) {
00668 sprintf(rt, ",rate=%lf", hz);
00669 strcat(str, rt);
00670 }
00671 strcat(str, ")");
00672
00673 return CORBA::string_dup(str);
00674 }
00675
00676
00677 unsigned int SenseImpl::sequencer()
00678 {
00679 return delegate->sequencer();
00680 }
00681
00682 uint8_t SenseImpl::level()
00683 {
00684 return delegate->level();
00685 }
00686
00687 unsigned long long SenseImpl::timeused()
00688 {
00689 return delegate->timeused();
00690 }
00691
00692 void SenseImpl::timeused(unsigned long long t)
00693 {
00694 delegate->timeused(t);
00695 }
00696
00697 double SenseImpl::energyused()
00698 {
00699 return delegate->energyused();
00700 }
00701
00702 void SenseImpl::energyused(double e)
00703 {
00704 delegate->energyused(e);
00705 }
00706
00707 Series* SenseImpl::results()
00708 {
00709 return delegate->results();
00710 }
00711
00712 void SenseImpl::results(Series &d)
00713 {
00714 delegate->results(d);
00715 }
00716
00717 uint8_t SenseImpl::priority()
00718 {
00719 return delegate->priority();
00720 }
00721
00722 void SenseImpl::priority(uint8_t p)
00723 {
00724 delegate->priority(p);
00725 }
00726
00727 ErrorList* SenseImpl::errors()
00728 {
00729 return delegate->errors();
00730 }
00731
00732 void SenseImpl::errors(ErrorList &e)
00733 {
00734 delegate->errors(e);
00735 }
00736
00737
00738
00739 PeakSenseImpl::PeakSenseImpl(uint8_t l, uint8_t s, double r,
00740 double th, bool hi) : PeakSense()
00741 {
00742 delegate = new SenseImpl(l, s, r);
00743 if (hi) {
00744 threshold_h = th;
00745 threshold_l = -(DBL_MAX);
00746 }
00747 else {
00748 threshold_h = DBL_MAX;
00749 threshold_l = th;
00750 }
00751 }
00752
00753 PeakSenseImpl::PeakSenseImpl(uint8_t l, uint8_t s, double r,
00754 double th, double tl) : PeakSense()
00755 {
00756 delegate = new SenseImpl(l, s, r);
00757 threshold_h = th;
00758 threshold_l = tl;
00759 }
00760
00761 PeakSenseImpl::PeakSenseImpl(uint8_t s, double r,
00762 double th, bool hi) : PeakSense()
00763 {
00764 delegate = new SenseImpl(s, r);
00765 if (hi) {
00766 threshold_h = th;
00767 threshold_l = -(DBL_MAX);
00768 }
00769 else {
00770 threshold_h = DBL_MAX;
00771 threshold_l = th;
00772 }
00773 }
00774
00775 PeakSenseImpl::PeakSenseImpl(uint8_t s, double r,
00776 double th, double tl) : PeakSense()
00777 {
00778 delegate = new SenseImpl(s, r);
00779 threshold_h = th;
00780 threshold_l = tl;
00781 }
00782
00783 PeakSenseImpl::PeakSenseImpl(uint8_t l, uint8_t s,
00784 double th, bool hi) : PeakSense()
00785 {
00786 delegate = new SenseImpl(l, s);
00787 if (hi) {
00788 threshold_h = th;
00789 threshold_l = -(DBL_MAX);
00790 }
00791 else {
00792 threshold_h = DBL_MAX;
00793 threshold_l = th;
00794 }
00795 }
00796
00797 PeakSenseImpl::PeakSenseImpl(uint8_t l, uint8_t s,
00798 double th, double tl) : PeakSense()
00799 {
00800 delegate = new SenseImpl(l, s);
00801 threshold_h = th;
00802 threshold_l = tl;
00803 }
00804
00805 PeakSenseImpl::PeakSenseImpl(uint8_t s, double th, bool hi) : PeakSense()
00806 {
00807 delegate = new SenseImpl(s);
00808 if (hi) {
00809 threshold_h = th;
00810 threshold_l = -(DBL_MAX);
00811 }
00812 else {
00813 threshold_h = DBL_MAX;
00814 threshold_l = th;
00815 }
00816 }
00817
00818 PeakSenseImpl::PeakSenseImpl(uint8_t s, double th, double tl) : PeakSense()
00819 {
00820 delegate = new SenseImpl(s);
00821 threshold_h = th;
00822 threshold_l = tl;
00823 }
00824
00825 PeakSenseImpl::PeakSenseImpl(uint8_t l, uint8_t s, double r,
00826 double th, double tl,
00827 unsigned int seq) : PeakSense()
00828 {
00829 delegate = new SenseImpl(l, s, r, seq);
00830 threshold_h = th;
00831 threshold_l = tl;
00832 }
00833
00834
00835 double PeakSenseImpl::highthreshold()
00836 {
00837 return threshold_h;
00838 }
00839
00840 void PeakSenseImpl::highthreshold(double h)
00841 {
00842 threshold_h = h;
00843 }
00844
00845 double PeakSenseImpl::lowthreshold()
00846 {
00847 return threshold_l;
00848 }
00849
00850 void PeakSenseImpl::lowthreshold(double l)
00851 {
00852 threshold_l = l;
00853 }
00854
00855 uint8_t PeakSenseImpl::identifier()
00856 {
00857 return BETA;
00858 }
00859
00860 char *PeakSenseImpl::asString()
00861 {
00862 char str[2048], lvl[64], snsr[64], rt[64], hth[64], lth[64];
00863
00864 memset(lth, 0, 64);
00865 memset(hth, 0, 64);
00866 memset(rt, 0, 64);
00867 memset(snsr, 0, 64);
00868 memset(lvl, 0, 64);
00869 memset(str, 0, 512);
00870
00871 sprintf(str, "PeakSense(");
00872 if (delegate->level() != INVALID) {
00873 sprintf(lvl, "level=%u,", delegate->level());
00874 strcat(str, lvl);
00875 }
00876
00877 strcat(str, "sensor=");
00878 capabilityToString(snsr, delegate->sensor());
00879 strcat(str, snsr);
00880
00881 if (delegate->rate() > 0.0) {
00882 sprintf(rt, ",rate=%lf", delegate->rate());
00883 strcat(str, rt);
00884 }
00885
00886 if (threshold_h != DBL_MAX) {
00887 sprintf(hth, ",high threshold=%lf", threshold_h);
00888 strcat(str, hth);
00889 }
00890 if (threshold_l != -(DBL_MAX)) {
00891 sprintf(lth, ",low threshold=%lf", threshold_l);
00892 strcat(str, lth);
00893 }
00894 strcat(str, ")");
00895
00896 return CORBA::string_dup(str);
00897 }
00898
00899
00900 double PeakSenseImpl::rate()
00901 {
00902 return delegate->rate();
00903 }
00904
00905 void PeakSenseImpl::rate(double r)
00906 {
00907 delegate->rate(r);
00908 }
00909
00910 unsigned int PeakSenseImpl::sequencer()
00911 {
00912 return delegate->sequencer();
00913 }
00914
00915 uint8_t PeakSenseImpl::level()
00916 {
00917 return delegate->level();
00918 }
00919
00920 unsigned long long PeakSenseImpl::timeused()
00921 {
00922 return delegate->timeused();
00923 }
00924
00925 void PeakSenseImpl::timeused(unsigned long long t)
00926 {
00927 delegate->timeused(t);
00928 }
00929
00930 double PeakSenseImpl::energyused()
00931 {
00932 return delegate->energyused();
00933 }
00934
00935 void PeakSenseImpl::energyused(double e)
00936 {
00937 delegate->energyused(e);
00938 }
00939
00940 Series* PeakSenseImpl::results()
00941 {
00942 return delegate->results();
00943 }
00944
00945 void PeakSenseImpl::results(Series &data)
00946 {
00947 Data *d = &(data[0]);
00948 double val = 0.0;
00949 if (isIntegerData(d->_d()))
00950 val = d->iresult();
00951 else if (isFloatingPointData(d->_d()))
00952 val = d->fresult();
00953 if (val > threshold_l && val < threshold_h)
00954 delegate->results(data);
00955 }
00956
00957 uint8_t PeakSenseImpl::priority()
00958 {
00959 return delegate->priority();
00960 }
00961
00962 void PeakSenseImpl::priority(uint8_t p)
00963 {
00964 delegate->priority(p);
00965 }
00966
00967 ErrorList* PeakSenseImpl::errors()
00968 {
00969 return delegate->errors();
00970 }
00971
00972 void PeakSenseImpl::errors(ErrorList &e)
00973 {
00974 delegate->errors(e);
00975 }
00976
00977 FunctorList *PeakSenseImpl::subfunctors()
00978 {
00979 return delegate->subfunctors();
00980 }
00981
00982 void PeakSenseImpl::subfunctors(FunctorList &fs)
00983 {
00984 delegate->subfunctors(fs);
00985 }
00986
00987
00988
00989 TimeSeriesImpl::TimeSeriesImpl(uint8_t l, Sensory_ptr s,
00990 unsigned long long t) : TimeSeries()
00991 {
00992 delegate = new CollectionImpl(l, s);
00993 time = t;
00994 }
00995
00996 TimeSeriesImpl::TimeSeriesImpl(Sensory_ptr s,
00997 unsigned long long t) : TimeSeries()
00998 {
00999 delegate = new CollectionImpl(s);
01000 time = t;
01001 }
01002
01003 TimeSeriesImpl::TimeSeriesImpl(uint8_t l, Sensory_ptr s, unsigned long long t,
01004 unsigned int seq) : TimeSeries()
01005 {
01006 delegate = new CollectionImpl(l, s, seq);
01007 time = t;
01008 }
01009
01010
01011 unsigned long long TimeSeriesImpl::duration()
01012 {
01013 return time;
01014 }
01015
01016 void TimeSeriesImpl::duration(unsigned long long t)
01017 {
01018 time = t;
01019 }
01020
01021 uint8_t TimeSeriesImpl::identifier()
01022 {
01023 return THETA;
01024 }
01025
01026 char *TimeSeriesImpl::asString()
01027 {
01028 char str[2048], lvl[64], dur[64], *sub;
01029
01030 memset(dur, 0, 64);
01031 memset(lvl, 0, 64);
01032 memset(str, 0, 512);
01033
01034 sprintf(str, "TimeSeries(");
01035 if (delegate->level() != INVALID) {
01036 sprintf(lvl, "level=%u,", delegate->level());
01037 strcat(str, lvl);
01038 }
01039
01040 sprintf(dur, "duration=%Lu,", time);
01041 strcat(str, dur);
01042
01043 sub = delegate->sense()->asString();
01044 strcat(str, sub);
01045 CORBA::string_free(sub);
01046 strcat(str, ")");
01047
01048 return CORBA::string_dup(str);
01049 }
01050
01051
01052 unsigned int TimeSeriesImpl::sequencer()
01053 {
01054 return delegate->sequencer();
01055 }
01056
01057 uint8_t TimeSeriesImpl::level()
01058 {
01059 return delegate->level();
01060 }
01061
01062 Sensory_ptr TimeSeriesImpl::sense()
01063 {
01064 return delegate->sense();
01065 }
01066
01067 void TimeSeriesImpl::sense(Sensory_ptr s)
01068 {
01069 delegate->sense(s);
01070 }
01071
01072 uint8_t TimeSeriesImpl::sensor()
01073 {
01074 return delegate->sensor();
01075 }
01076
01077 unsigned long long TimeSeriesImpl::timeused()
01078 {
01079 return delegate->timeused();
01080 }
01081
01082 void TimeSeriesImpl::timeused(unsigned long long t)
01083 {
01084 delegate->timeused(t);
01085 }
01086
01087 double TimeSeriesImpl::energyused()
01088 {
01089 return delegate->energyused();
01090 }
01091
01092 void TimeSeriesImpl::energyused(double e)
01093 {
01094 delegate->energyused(e);
01095 }
01096
01097 Series* TimeSeriesImpl::results()
01098 {
01099 return delegate->results();
01100 }
01101
01102 void TimeSeriesImpl::results(Series &data)
01103 {
01104 delegate->results(data);
01105 }
01106
01107 uint8_t TimeSeriesImpl::priority()
01108 {
01109 return delegate->priority();
01110 }
01111
01112 void TimeSeriesImpl::priority(uint8_t p)
01113 {
01114 delegate->priority(p);
01115 }
01116
01117 ErrorList* TimeSeriesImpl::errors()
01118 {
01119 return delegate->errors();
01120 }
01121
01122 void TimeSeriesImpl::errors(ErrorList &e)
01123 {
01124 delegate->errors(e);
01125 }
01126
01127 FunctorList *TimeSeriesImpl::subfunctors()
01128 {
01129 return delegate->subfunctors();
01130 }
01131
01132 void TimeSeriesImpl::subfunctors(FunctorList &fs)
01133 {
01134 delegate->subfunctors(fs);
01135 }
01136
01137
01138
01139 SpatialSeriesImpl::SpatialSeriesImpl(uint8_t l, Sensory_ptr s, double angle,
01140 double dist) : SpatialSeries()
01141 {
01142 delegate = new CollectionImpl(l, s);
01143 centirads = angle;
01144 dist_cm = dist;
01145 }
01146
01147 SpatialSeriesImpl::SpatialSeriesImpl(Sensory_ptr s, double angle,
01148 double dist) : SpatialSeries()
01149 {
01150 delegate = new CollectionImpl(s);
01151 centirads = angle;
01152 dist_cm = dist;
01153 }
01154
01155 SpatialSeriesImpl::SpatialSeriesImpl(uint8_t l, Sensory_ptr s) : SpatialSeries()
01156 {
01157 delegate = new CollectionImpl(l, s);
01158 centirads = -1.0;
01159 dist_cm = -1.0;
01160 }
01161
01162 SpatialSeriesImpl::SpatialSeriesImpl(Sensory_ptr s) : SpatialSeries()
01163 {
01164 delegate = new CollectionImpl(s);
01165 centirads = -1.0;
01166 dist_cm = -1.0;
01167 }
01168
01169 SpatialSeriesImpl::SpatialSeriesImpl(uint8_t l, Sensory_ptr s, double angle,
01170 double dist,
01171 unsigned int seq) : SpatialSeries()
01172 {
01173 delegate = new CollectionImpl(l, s, seq);
01174 centirads = angle;
01175 dist_cm = dist;
01176 }
01177
01178
01179 double SpatialSeriesImpl::distance()
01180 {
01181 return dist_cm;
01182 }
01183
01184 void SpatialSeriesImpl::distance(double d)
01185 {
01186 dist_cm = d;
01187 }
01188
01189 double SpatialSeriesImpl::angle()
01190 {
01191 return centirads;
01192 }
01193
01194 void SpatialSeriesImpl::angle(double a)
01195 {
01196 centirads = a;
01197 }
01198
01199 uint8_t SpatialSeriesImpl::identifier()
01200 {
01201 return PSI;
01202 }
01203
01204 char *SpatialSeriesImpl::asString()
01205 {
01206 char str[2048], lvl[64], a[64], d[64], *sub;
01207
01208 memset(d, 0, 64);
01209 memset(a, 0, 64);
01210 memset(lvl, 0, 64);
01211 memset(str, 0, 512);
01212
01213 sprintf(str, "SpatialSeries(");
01214 if (delegate->level() != INVALID) {
01215 sprintf(lvl, "level=%u,", delegate->level());
01216 strcat(str, lvl);
01217 }
01218
01219 if (centirads > 0.0) {
01220 sprintf(a, "angle=%lf,", centirads);
01221 strcat(str, a);
01222 }
01223 if (dist_cm > 0.0) {
01224 sprintf(d, "distance=%lf,", dist_cm);
01225 strcat(str, d);
01226 }
01227
01228 sub = delegate->sense()->asString();
01229 strcat(str, sub);
01230 CORBA::string_free(sub);
01231 strcat(str, ")");
01232
01233 return CORBA::string_dup(str);
01234 }
01235
01236
01237 unsigned int SpatialSeriesImpl::sequencer()
01238 {
01239 return delegate->sequencer();
01240 }
01241
01242 uint8_t SpatialSeriesImpl::level()
01243 {
01244 return delegate->level();
01245 }
01246
01247 Sensory_ptr SpatialSeriesImpl::sense()
01248 {
01249 return delegate->sense();
01250 }
01251
01252 void SpatialSeriesImpl::sense(Sensory_ptr s)
01253 {
01254 delegate->sense(s);
01255 }
01256
01257 uint8_t SpatialSeriesImpl::sensor()
01258 {
01259 return delegate->sensor();
01260 }
01261
01262 unsigned long long SpatialSeriesImpl::timeused()
01263 {
01264 return delegate->timeused();
01265 }
01266
01267 void SpatialSeriesImpl::timeused(unsigned long long t)
01268 {
01269 delegate->timeused(t);
01270 }
01271
01272 double SpatialSeriesImpl::energyused()
01273 {
01274 return delegate->energyused();
01275 }
01276
01277 void SpatialSeriesImpl::energyused(double e)
01278 {
01279 delegate->energyused(e);
01280 }
01281
01282 Series* SpatialSeriesImpl::results()
01283 {
01284 return delegate->results();
01285 }
01286
01287 void SpatialSeriesImpl::results(Series &data)
01288 {
01289 delegate->results(data);
01290 }
01291
01292 uint8_t SpatialSeriesImpl::priority()
01293 {
01294 return delegate->priority();
01295 }
01296
01297 void SpatialSeriesImpl::priority(uint8_t p)
01298 {
01299 delegate->priority(p);
01300 }
01301
01302 ErrorList* SpatialSeriesImpl::errors()
01303 {
01304 return delegate->errors();
01305 }
01306
01307 void SpatialSeriesImpl::errors(ErrorList &e)
01308 {
01309 delegate->errors(e);
01310 }
01311
01312 FunctorList *SpatialSeriesImpl::subfunctors()
01313 {
01314 return delegate->subfunctors();
01315 }
01316
01317 void SpatialSeriesImpl::subfunctors(FunctorList &fs)
01318 {
01319 delegate->subfunctors(fs);
01320 }
01321
01322
01323
01324 ReciteImpl::ReciteImpl(uint8_t l, CollectionList *c) : Recite()
01325 {
01326 delegate = new AggregateImpl((char*)"Recite", l, c);
01327 }
01328
01329 ReciteImpl::ReciteImpl(CollectionList *c) : Recite()
01330 {
01331 delegate = new AggregateImpl((char*)"Recite", c);
01332 }
01333
01334 ReciteImpl::ReciteImpl(uint8_t l, CollectionList *c,
01335 unsigned int seq) : Recite()
01336 {
01337 delegate = new AggregateImpl((char*)"Recite", l, c, seq);
01338 }
01339
01340
01341 uint8_t ReciteImpl::identifier()
01342 {
01343 return IOTA;
01344 }
01345
01346 Series* ReciteImpl::results()
01347 {
01348 unsigned int count = 0, pos = 0;
01349 unsigned int num = delegate->collectors()->length();
01350 for (unsigned int i = 0; i < num; i++) {
01351 Collection *c = (*(delegate->collectors()))[i];
01352 count += c->results()->length();
01353 }
01354 Series *array = new Series();
01355 array->length(count);
01356 for (unsigned int i = 0; i < num; i++) {
01357 Collection *c = (*(delegate->collectors()))[i];
01358 if (c->results() != NULL && c->results()->length() > 0) {
01359 for (unsigned int j = 0; j < c->results()->length(); j++) {
01360 Series *s = c->results();
01361 (*array)[pos] = (*s)[j];
01362 pos++;
01363 }
01364 }
01365 }
01366 return array;
01367 }
01368
01369
01370 char *ReciteImpl::asString()
01371 {
01372 return delegate->asString();
01373 }
01374
01375 unsigned int ReciteImpl::sequencer()
01376 {
01377 return delegate->sequencer();
01378 }
01379
01380 uint8_t ReciteImpl::level()
01381 {
01382 return delegate->level();
01383 }
01384
01385 CollectionList* ReciteImpl::collectors()
01386 {
01387 return delegate->collectors();
01388 }
01389
01390 void ReciteImpl::collectors(CollectionList *c)
01391 {
01392 delegate->collectors(c);
01393 }
01394
01395 SensoryList* ReciteImpl::senses()
01396 {
01397 return delegate->senses();
01398 }
01399
01400 Sensory_ptr ReciteImpl::sense()
01401 {
01402 return delegate->sense();
01403 }
01404
01405 void ReciteImpl::sense(Sensory_ptr s)
01406 {
01407 delegate->sense(s);
01408 }
01409
01410 uint8_t ReciteImpl::sensor()
01411 {
01412 return delegate->sensor();
01413 }
01414
01415 unsigned long long ReciteImpl::timeused()
01416 {
01417 return delegate->timeused();
01418 }
01419
01420 void ReciteImpl::timeused(unsigned long long t)
01421 {
01422 delegate->timeused(t);
01423 }
01424
01425 double ReciteImpl::energyused()
01426 {
01427 return delegate->energyused();
01428 }
01429
01430 void ReciteImpl::energyused(double e)
01431 {
01432 delegate->energyused(e);
01433 }
01434
01435 uint8_t ReciteImpl::priority()
01436 {
01437 return delegate->priority();
01438 }
01439
01440 void ReciteImpl::priority(uint8_t p)
01441 {
01442 delegate->priority(p);
01443 }
01444
01445 ErrorList* ReciteImpl::errors()
01446 {
01447 return delegate->errors();
01448 }
01449
01450 void ReciteImpl::errors(ErrorList &e)
01451 {
01452 delegate->errors(e);
01453 }
01454
01455 FunctorList *ReciteImpl::subfunctors()
01456 {
01457 return delegate->subfunctors();
01458 }
01459
01460 void ReciteImpl::subfunctors(FunctorList &fs)
01461 {
01462 delegate->subfunctors(fs);
01463 }
01464
01465
01466
01467 SumImpl::SumImpl(uint8_t l, CollectionList *c) : Sum()
01468 {
01469 delegate = new AggregateImpl((char*)"Sum", l, c);
01470 }
01471
01472 SumImpl::SumImpl(CollectionList *c) : Sum()
01473 {
01474 delegate = new AggregateImpl((char*)"Sum", c);
01475 }
01476
01477 SumImpl::SumImpl(uint8_t l, CollectionList *c, unsigned int seq) : Sum()
01478 {
01479 delegate = new AggregateImpl((char*)"Sum", l, c, seq);
01480 }
01481
01482
01483 uint8_t SumImpl::identifier()
01484 {
01485 return SUMMA;
01486 }
01487
01488 Data* SumImpl::getResult(unsigned int idx)
01489 {
01490 double value = 0.0;
01491 Collection *c = (*(delegate->collectors()))[idx];
01492 Series *s = c->results();
01493 for (unsigned int i = 0; i < s->length(); i++) {
01494 Data *d = &((*s)[i]);
01495 if (isIntegerData(d->_d()))
01496 value += d->iresult();
01497 else if (isFloatingPointData(d->_d()))
01498 value += d->fresult();
01499 }
01500
01501 Data* ret = new Data();
01502 ret->fresult(value);
01503 return ret;
01504 }
01505
01506 Series* SumImpl::results()
01507 {
01508 unsigned int num = delegate->collectors()->length();
01509 Series *array = new Series();
01510 array->length(num);
01511 for (unsigned int i = 0; i < num; i++)
01512 (*array)[i] = *(getResult(i));
01513
01514 return array;
01515 }
01516
01517
01518 char *SumImpl::asString()
01519 {
01520 return delegate->asString();
01521 }
01522
01523 unsigned int SumImpl::sequencer()
01524 {
01525 return delegate->sequencer();
01526 }
01527
01528 uint8_t SumImpl::level()
01529 {
01530 return delegate->level();
01531 }
01532
01533 CollectionList* SumImpl::collectors()
01534 {
01535 return delegate->collectors();
01536 }
01537
01538 void SumImpl::collectors(CollectionList *c)
01539 {
01540 delegate->collectors(c);
01541 }
01542
01543 SensoryList* SumImpl::senses()
01544 {
01545 return delegate->senses();
01546 }
01547
01548 Sensory_ptr SumImpl::sense()
01549 {
01550 return delegate->sense();
01551 }
01552
01553 void SumImpl::sense(Sensory_ptr s)
01554 {
01555 delegate->sense(s);
01556 }
01557
01558 uint8_t SumImpl::sensor()
01559 {
01560 return delegate->sensor();
01561 }
01562
01563 unsigned long long SumImpl::timeused()
01564 {
01565 return delegate->timeused();
01566 }
01567
01568 void SumImpl::timeused(unsigned long long t)
01569 {
01570 delegate->timeused(t);
01571 }
01572
01573 double SumImpl::energyused()
01574 {
01575 return delegate->energyused();
01576 }
01577
01578 void SumImpl::energyused(double e)
01579 {
01580 delegate->energyused(e);
01581 }
01582
01583 uint8_t SumImpl::priority()
01584 {
01585 return delegate->priority();
01586 }
01587
01588 void SumImpl::priority(uint8_t p)
01589 {
01590 delegate->priority(p);
01591 }
01592
01593 ErrorList* SumImpl::errors()
01594 {
01595 return delegate->errors();
01596 }
01597
01598 void SumImpl::errors(ErrorList &e)
01599 {
01600 delegate->errors(e);
01601 }
01602
01603 FunctorList *SumImpl::subfunctors()
01604 {
01605 return delegate->subfunctors();
01606 }
01607
01608 void SumImpl::subfunctors(FunctorList &fs)
01609 {
01610 delegate->subfunctors(fs);
01611 }
01612
01613
01614
01615 DeltaImpl::DeltaImpl(uint8_t l, CollectionList *c) : Delta()
01616 {
01617 delegate = new AggregateImpl((char*)"Delta", l, c);
01618 }
01619
01620 DeltaImpl::DeltaImpl(CollectionList *c) : Delta()
01621 {
01622 delegate = new AggregateImpl((char*)"Delta", c);
01623 }
01624
01625 DeltaImpl::DeltaImpl(uint8_t l, CollectionList *c, unsigned int seq) : Delta()
01626 {
01627 delegate = new AggregateImpl((char*)"Delta", l, c, seq);
01628 }
01629
01630
01631 uint8_t DeltaImpl::identifier()
01632 {
01633 return DELTA;
01634 }
01635
01636 Data* DeltaImpl::getResult(unsigned int idx)
01637 {
01638 double min = DBL_MAX, max = -(DBL_MAX);
01639 double value = 0.0;
01640 Collection *c = (*(delegate->collectors()))[idx];
01641 Series *s = c->results();
01642 for (unsigned int i = 0; i < s->length(); i++) {
01643 Data *d = &((*s)[i]);
01644 if (isIntegerData(d->_d())) {
01645 if (d->iresult() > max)
01646 max = d->iresult();
01647 if (d->iresult() < min)
01648 min = d->iresult();
01649 }
01650 else if (isFloatingPointData(d->_d())) {
01651 if (d->fresult() > max)
01652 max = d->fresult();
01653 if (d->fresult() < min)
01654 min = d->fresult();
01655 }
01656 }
01657 value = max - min;
01658
01659 Data* ret = new Data();
01660 ret->fresult(value);
01661 return ret;
01662 }
01663
01664 Series* DeltaImpl::results()
01665 {
01666 unsigned int num = delegate->collectors()->length();
01667 Series *array = new Series();
01668 array->length(num);
01669 for (unsigned int i = 0; i < num; i++)
01670 (*array)[i] = *(getResult(i));
01671
01672 return array;
01673 }
01674
01675
01676 char *DeltaImpl::asString()
01677 {
01678 return delegate->asString();
01679 }
01680
01681 unsigned int DeltaImpl::sequencer()
01682 {
01683 return delegate->sequencer();
01684 }
01685
01686 uint8_t DeltaImpl::level()
01687 {
01688 return delegate->level();
01689 }
01690
01691 CollectionList* DeltaImpl::collectors()
01692 {
01693 return delegate->collectors();
01694 }
01695
01696 void DeltaImpl::collectors(CollectionList *c)
01697 {
01698 delegate->collectors(c);
01699 }
01700
01701 SensoryList* DeltaImpl::senses()
01702 {
01703 return delegate->senses();
01704 }
01705
01706 Sensory_ptr DeltaImpl::sense()
01707 {
01708 return delegate->sense();
01709 }
01710
01711 void DeltaImpl::sense(Sensory_ptr s)
01712 {
01713 delegate->sense(s);
01714 }
01715
01716 uint8_t DeltaImpl::sensor()
01717 {
01718 return delegate->sensor();
01719 }
01720
01721 unsigned long long DeltaImpl::timeused()
01722 {
01723 return delegate->timeused();
01724 }
01725
01726 void DeltaImpl::timeused(unsigned long long t)
01727 {
01728 delegate->timeused(t);
01729 }
01730
01731 double DeltaImpl::energyused()
01732 {
01733 return delegate->energyused();
01734 }
01735
01736 void DeltaImpl::energyused(double e)
01737 {
01738 delegate->energyused(e);
01739 }
01740
01741 uint8_t DeltaImpl::priority()
01742 {
01743 return delegate->priority();
01744 }
01745
01746 void DeltaImpl::priority(uint8_t p)
01747 {
01748 delegate->priority(p);
01749 }
01750
01751 ErrorList* DeltaImpl::errors()
01752 {
01753 return delegate->errors();
01754 }
01755
01756 void DeltaImpl::errors(ErrorList &e)
01757 {
01758 delegate->errors(e);
01759 }
01760
01761 FunctorList *DeltaImpl::subfunctors()
01762 {
01763 return delegate->subfunctors();
01764 }
01765
01766 void DeltaImpl::subfunctors(FunctorList &fs)
01767 {
01768 delegate->subfunctors(fs);
01769 }
01770
01771
01772
01773 MeanImpl::MeanImpl(uint8_t l, CollectionList *c) : Mean()
01774 {
01775 delegate = new AggregateImpl((char*)"Mean", l, c);
01776 }
01777
01778 MeanImpl::MeanImpl(CollectionList *c) : Mean()
01779 {
01780 delegate = new AggregateImpl((char*)"Mean", c);
01781 }
01782
01783 MeanImpl::MeanImpl(uint8_t l, CollectionList *c, unsigned int seq) : Mean()
01784 {
01785 delegate = new AggregateImpl((char*)"Mean", l, c, seq);
01786 }
01787
01788
01789 uint8_t MeanImpl::identifier()
01790 {
01791 return BARX;
01792 }
01793
01794 Data* MeanImpl::getResult(unsigned int idx)
01795 {
01796 double value = 0.0;
01797 Collection *c = (*(delegate->collectors()))[idx];
01798 Series *s = c->results();
01799 for (unsigned int i = 0; i < s->length(); i++) {
01800 Data *d = &((*s)[i]);
01801 if (isIntegerData(d->_d()))
01802 value += d->iresult();
01803 else if (isFloatingPointData(d->_d()))
01804 value += d->fresult();
01805 }
01806 value /= s->length();
01807
01808 Data* ret = new Data();
01809 ret->fresult(value);
01810 return ret;
01811 }
01812
01813 Series* MeanImpl::results()
01814 {
01815 unsigned int num = delegate->collectors()->length();
01816 Series *array = new Series();
01817 array->length(num);
01818 for (unsigned int i = 0; i < num; i++)
01819 (*array)[i] = *(getResult(i));
01820
01821 return array;
01822 }
01823
01824
01825 char *MeanImpl::asString()
01826 {
01827 return delegate->asString();
01828 }
01829
01830 unsigned int MeanImpl::sequencer()
01831 {
01832 return delegate->sequencer();
01833 }
01834
01835 uint8_t MeanImpl::level()
01836 {
01837 return delegate->level();
01838 }
01839
01840 CollectionList* MeanImpl::collectors()
01841 {
01842 return delegate->collectors();
01843 }
01844
01845 void MeanImpl::collectors(CollectionList *c)
01846 {
01847 delegate->collectors(c);
01848 }
01849
01850 SensoryList* MeanImpl::senses()
01851 {
01852 return delegate->senses();
01853 }
01854
01855 Sensory_ptr MeanImpl::sense()
01856 {
01857 return delegate->sense();
01858 }
01859
01860 void MeanImpl::sense(Sensory_ptr s)
01861 {
01862 delegate->sense(s);
01863 }
01864
01865 uint8_t MeanImpl::sensor()
01866 {
01867 return delegate->sensor();
01868 }
01869
01870 unsigned long long MeanImpl::timeused()
01871 {
01872 return delegate->timeused();
01873 }
01874
01875 void MeanImpl::timeused(unsigned long long t)
01876 {
01877 delegate->timeused(t);
01878 }
01879
01880 double MeanImpl::energyused()
01881 {
01882 return delegate->energyused();
01883 }
01884
01885 void MeanImpl::energyused(double e)
01886 {
01887 delegate->energyused(e);
01888 }
01889
01890 uint8_t MeanImpl::priority()
01891 {
01892 return delegate->priority();
01893 }
01894
01895 void MeanImpl::priority(uint8_t p)
01896 {
01897 delegate->priority(p);
01898 }
01899
01900 ErrorList* MeanImpl::errors()
01901 {
01902 return delegate->errors();
01903 }
01904
01905 void MeanImpl::errors(ErrorList &e)
01906 {
01907 delegate->errors(e);
01908 }
01909
01910 FunctorList *MeanImpl::subfunctors()
01911 {
01912 return delegate->subfunctors();
01913 }
01914
01915 void MeanImpl::subfunctors(FunctorList &fs)
01916 {
01917 delegate->subfunctors(fs);
01918 }
01919
01920
01921
01922 SigmaImpl::SigmaImpl(uint8_t l, CollectionList *c) : Sigma()
01923 {
01924 delegate = new AggregateImpl((char*)"Sigma", l, c);
01925 }
01926
01927 SigmaImpl::SigmaImpl(CollectionList *c) : Sigma()
01928 {
01929 delegate = new AggregateImpl((char*)"Sigma", c);
01930 }
01931
01932 SigmaImpl::SigmaImpl(uint8_t l, CollectionList *c, unsigned int seq) : Sigma()
01933 {
01934 delegate = new AggregateImpl((char*)"Sigma", l, c, seq);
01935 }
01936
01937
01938 uint8_t SigmaImpl::identifier()
01939 {
01940 return SIGMA;
01941 }
01942
01943 Data* SigmaImpl::getResult(unsigned int idx)
01944 {
01945 double avg = 0.0;
01946 double value = 0.0;
01947 Collection *c = (*(delegate->collectors()))[idx];
01948 Series *s = c->results();
01949 for (unsigned int i = 0; i < s->length(); i++) {
01950 Data *d = &((*s)[i]);
01951 if (isIntegerData(d->_d()))
01952 avg += d->iresult();
01953 else if (isFloatingPointData(d->_d()))
01954 avg += d->fresult();
01955 }
01956 avg /= s->length();
01957 for (unsigned int i = 0; i < s->length(); i++) {
01958 Data *d = &((*s)[i]);
01959 double dev = 0.0;
01960 if (isIntegerData(d->_d()))
01961 dev = d->iresult() - avg;
01962 else if (isFloatingPointData(d->_d()))
01963 dev = d->fresult() - avg;
01964 value += (dev * dev);
01965 }
01966 value /= (s->length() - 1);
01967 value = sqrt(value);
01968
01969 Data* ret = new Data();
01970 ret->fresult(value);
01971 return ret;
01972 }
01973
01974 Series* SigmaImpl::results()
01975 {
01976 unsigned int num = delegate->collectors()->length();
01977 Series *array = new Series();
01978 array->length(num);
01979 for (unsigned int i = 0; i < num; i++)
01980 (*array)[i] = *(getResult(i));
01981
01982 return array;
01983 }
01984
01985
01986 char *SigmaImpl::asString()
01987 {
01988 return delegate->asString();
01989 }
01990
01991 unsigned int SigmaImpl::sequencer()
01992 {
01993 return delegate->sequencer();
01994 }
01995
01996 uint8_t SigmaImpl::level()
01997 {
01998 return delegate->level();
01999 }
02000
02001 CollectionList* SigmaImpl::collectors()
02002 {
02003 return delegate->collectors();
02004 }
02005
02006 void SigmaImpl::collectors(CollectionList *c)
02007 {
02008 delegate->collectors(c);
02009 }
02010
02011 SensoryList* SigmaImpl::senses()
02012 {
02013 return delegate->senses();
02014 }
02015
02016 Sensory_ptr SigmaImpl::sense()
02017 {
02018 return delegate->sense();
02019 }
02020
02021 void SigmaImpl::sense(Sensory_ptr s)
02022 {
02023 delegate->sense(s);
02024 }
02025
02026 uint8_t SigmaImpl::sensor()
02027 {
02028 return delegate->sensor();
02029 }
02030
02031 unsigned long long SigmaImpl::timeused()
02032 {
02033 return delegate->timeused();
02034 }
02035
02036 void SigmaImpl::timeused(unsigned long long t)
02037 {
02038 delegate->timeused(t);
02039 }
02040
02041 double SigmaImpl::energyused()
02042 {
02043 return delegate->energyused();
02044 }
02045
02046 void SigmaImpl::energyused(double e)
02047 {
02048 delegate->energyused(e);
02049 }
02050
02051 uint8_t SigmaImpl::priority()
02052 {
02053 return delegate->priority();
02054 }
02055
02056 void SigmaImpl::priority(uint8_t p)
02057 {
02058 delegate->priority(p);
02059 }
02060
02061 ErrorList* SigmaImpl::errors()
02062 {
02063 return delegate->errors();
02064 }
02065
02066 void SigmaImpl::errors(ErrorList &e)
02067 {
02068 delegate->errors(e);
02069 }
02070
02071 FunctorList *SigmaImpl::subfunctors()
02072 {
02073 return delegate->subfunctors();
02074 }
02075
02076 void SigmaImpl::subfunctors(FunctorList &fs)
02077 {
02078 delegate->subfunctors(fs);
02079 }
02080
02081
02082
02083 LambdaImpl::LambdaImpl(uint8_t l, CollectionList *c) : Lambda()
02084 {
02085 delegate = new AggregateImpl((char*)"Lambda", l, c);
02086 }
02087
02088 LambdaImpl::LambdaImpl(CollectionList *c) : Lambda()
02089 {
02090 delegate = new AggregateImpl((char*)"Lambda", c);
02091 }
02092
02093 LambdaImpl::LambdaImpl(uint8_t l, CollectionList *c, unsigned int seq) : Lambda()
02094 {
02095 delegate = new AggregateImpl((char*)"Lambda", l, c, seq);
02096 }
02097
02098
02099 uint8_t LambdaImpl::identifier()
02100 {
02101 return LAMBDA;
02102 }
02103
02104 char *LambdaImpl::code()
02105 {
02106 return script;
02107 }
02108
02109 void LambdaImpl::code(char *s)
02110 {
02111 char *tmp = script;
02112 script = s;
02113 CORBA::string_free(tmp);
02114 }
02115
02116 double LambdaImpl::doScript(double previous, double measure)
02117 {
02118
02119 return measure;
02120 }
02121
02122 Data* LambdaImpl::getResult(unsigned int idx)
02123 {
02124 double value = 0.0;
02125 Collection *c = (*(delegate->collectors()))[idx];
02126 Series *s = c->results();
02127 for (unsigned int i = 0; i < s->length(); i++) {
02128 Data *d = &((*s)[i]);
02129 if (isIntegerData(d->_d()))
02130 value = doScript(value, d->iresult());
02131 else if (isFloatingPointData(d->_d()))
02132 value = doScript(value, d->fresult());
02133 }
02134
02135 Data* ret = new Data();
02136 ret->fresult(value);
02137 return ret;
02138 }
02139
02140 Series* LambdaImpl::results()
02141 {
02142 unsigned int num = delegate->collectors()->length();
02143 Series *array = new Series();
02144 array->length(num);
02145 for (unsigned int i = 0; i < num; i++)
02146 (*array)[i] = *(getResult(i));
02147
02148 return array;
02149 }
02150
02151
02152 char *LambdaImpl::asString()
02153 {
02154 return delegate->asString();
02155 }
02156
02157 unsigned int LambdaImpl::sequencer()
02158 {
02159 return delegate->sequencer();
02160 }
02161
02162 uint8_t LambdaImpl::level()
02163 {
02164 return delegate->level();
02165 }
02166
02167 CollectionList* LambdaImpl::collectors()
02168 {
02169 return delegate->collectors();
02170 }
02171
02172 void LambdaImpl::collectors(CollectionList *c)
02173 {
02174 delegate->collectors(c);
02175 }
02176
02177 SensoryList* LambdaImpl::senses()
02178 {
02179 return delegate->senses();
02180 }
02181
02182 Sensory_ptr LambdaImpl::sense()
02183 {
02184 return delegate->sense();
02185 }
02186
02187 void LambdaImpl::sense(Sensory_ptr s)
02188 {
02189 delegate->sense(s);
02190 }
02191
02192 uint8_t LambdaImpl::sensor()
02193 {
02194 return delegate->sensor();
02195 }
02196
02197 unsigned long long LambdaImpl::timeused()
02198 {
02199 return delegate->timeused();
02200 }
02201
02202 void LambdaImpl::timeused(unsigned long long t)
02203 {
02204 delegate->timeused(t);
02205 }
02206
02207 double LambdaImpl::energyused()
02208 {
02209 return delegate->energyused();
02210 }
02211
02212 void LambdaImpl::energyused(double e)
02213 {
02214 delegate->energyused(e);
02215 }
02216
02217 uint8_t LambdaImpl::priority()
02218 {
02219 return delegate->priority();
02220 }
02221
02222 void LambdaImpl::priority(uint8_t p)
02223 {
02224 delegate->priority(p);
02225 }
02226
02227 ErrorList* LambdaImpl::errors()
02228 {
02229 return delegate->errors();
02230 }
02231
02232 void LambdaImpl::errors(ErrorList &e)
02233 {
02234 delegate->errors(e);
02235 }
02236
02237 FunctorList *LambdaImpl::subfunctors()
02238 {
02239 return delegate->subfunctors();
02240 }
02241
02242 void LambdaImpl::subfunctors(FunctorList &fs)
02243 {
02244 delegate->subfunctors(fs);
02245 }
02246
02247
02248
02249 LocationImpl::LocationImpl(double latitude, double longitude,
02250 double altitude) : Location()
02251 {
02252 struct timeval tv;
02253 have_device = false;
02254 lat = latitude;
02255 lon = longitude;
02256 alt = altitude;
02257 gettimeofday(&tv, NULL);
02258 now = (tv.tv_sec * 1000000) + tv.tv_usec;
02259 }
02260
02261
02262 uint8_t LocationImpl::identifier()
02263 {
02264 return GPS;
02265 }
02266
02267 double LocationImpl::latitude()
02268 {
02269 getGPS();
02270 return lat;
02271 }
02272
02273 double LocationImpl::longitude()
02274 {
02275 getGPS();
02276 return lon;
02277 }
02278
02279 double LocationImpl::altitude()
02280 {
02281 getGPS();
02282 return alt;
02283 }
02284
02285 unsigned long long LocationImpl::time()
02286 {
02287 getGPS();
02288 return now;
02289 }
02290
02291 void LocationImpl::getGPS()
02292 {
02293 struct timeval tv;
02294 gettimeofday(&tv, NULL);
02295 now = (tv.tv_sec * 1000000) + tv.tv_usec;
02296 }
02297
02298 void LocationImpl::acquire(Functor_ptr f)
02299 {
02300 getGPS();
02301 Series *array = new Series();
02302 array->length(4);
02303 (*array)[0].fresult(lat);
02304 (*array)[0].fresult(lon);
02305 (*array)[0].fresult(alt);
02306 (*array)[0].iresult(now);
02307 f->results(*array);
02308 }
02309
02310
02311
02312 PowerImpl::PowerImpl() : Power()
02313 {
02314 have_device = false;
02315 starting_energy = getBattery();
02316 }
02317
02318 uint8_t PowerImpl::identifier()
02319 {
02320 return BATTERY;
02321 }
02322
02323 double PowerImpl::ratio()
02324 {
02325 energy_now = getBattery();
02326 return energy_now / starting_energy;
02327 }
02328
02329 double PowerImpl::getBattery()
02330 {
02331 return 1.0;
02332 }
02333
02334 void PowerImpl::acquire(Functor_ptr f)
02335 {
02336 Series *array = new Series();
02337 array->length(1);
02338 (*array)[0].fresult(ratio());
02339 f->results(*array);
02340 }