Detected Iteration Above Threshold in Unit Time. Check if Frequency (iteration count in Unit time) above Threshold. CATION. max interval is 0xfff0: 65,520ms. max iter threshold is 0xffff. (threfore, using 131KB with span[0xffff].)
DetectFreqAboveTH.cpp
- Committer:
- AkinoriHashimoto
- Date:
- 2015-10-09
- Revision:
- 1:6ab4e8504d60
- Parent:
- 0:7672973d6bed
File content as of revision 1:6ab4e8504d60:
#include "DetectFreqAboveTH.h" //extern DigitalOut led[]; DetectFreqAboveTH::DetectFreqAboveTH(int time_ms, int iter) { // led[0]= 1; unitTime= time_ms; iterThreshold= iter; span= new unsigned short[iter]; //init for(id= 0; id < iterThreshold; id++) span[id]= 0xffff; this->timer.start(true); id= 0; // led[1]= 1; } DetectFreqAboveTH::~DetectFreqAboveTH() { delete [] span; } bool DetectFreqAboveTH::chkAbove() { int tmpSpan= this->timer.read_ms(); //reset if(tmpSpan > 0xfff0) // 65,520ms. tmpSpan= 0xffff; span[id]= tmpSpan; id++; id %= iterThreshold; if(tmpSpan == 0xffff) return false; unsigned int sum= 0, tmp; for(int i= 0; i < iterThreshold; i++) { tmp= span[i]; if(tmp == 0xffff) // under threshold iter count. return false; sum += tmp; if(sum >= unitTime) return false; } // sumが単位時間未満なので、発生回数(/単位時間)は閾値以上。 return true; } // EOF