FACT++  1.0
bool EventBuilderWrapper::UpdateDimTempRefClk ( const tuple< Time, array< uint32_t, 40 >, array< int16_t, 160 >> &  dat)
inline

Definition at line 727 of file EventBuilderWrapper.h.

References __attribute__, i, DimDescribedService::setData(), and DimDescribedService::Update().

728  {
729  const auto delay = boost::posix_time::seconds(5);
730 
731  const Time &tm = get<0>(dat);
732 
733  const array<uint32_t,40> &clk = get<1>(dat);
734  const array<int16_t,160> &tmp = get<2>(dat);
735 
736  // --------------- RefClock ---------------
737 
738  // history, add current data to history
739  static list<pair<Time,array<uint32_t,40>>> listclk;
740  listclk.emplace_back(tm, clk);
741 
742  // --------------- Temperatures ---------------
743 
744  // history, add current data to history
745  static list<pair<Time,array<int16_t,160>>> listtmp;
746  listtmp.emplace_back(tm, tmp);
747 
748  // ========== Update dim services once a second =========
749 
750  static Time oldt(boost::date_time::neg_infin);
751  Time newt;
752 
753  if (newt<oldt+delay)
754  return true;
755 
756  oldt = newt;
757 
758  // --------------- RefClock ---------------
759 
760  // remove expired data from history
761  while (1)
762  {
763  auto it=listclk.begin();
764  if (it==listclk.end() || it->first+delay>tm)
765  break;
766  listclk.pop_front();
767  }
768 
769  // Structure for dim service
770  struct Clock
771  {
772  uint16_t num;
773  float val[40];
774  Clock() { memset(this, 0, sizeof(Clock)); }
775  } __attribute__((__packed__));
776 
777  // Calculate average and fll structure
778  vector<uint16_t> clknum(40);
779 
780  Clock avgclk;
781  avgclk.num = listclk.size();
782  for (auto it=listclk.begin(); it!=listclk.end(); it++)
783  for (int i=0; i<40; i++)
784  if (it->second[i]!=UINT32_MAX)
785  {
786  avgclk.val[i] += it->second[i];
787  clknum[i]++;
788  }
789  for (int i=0; i<40; i++)
790  avgclk.val[i] *= 2.048/clknum[i];
791 
792  // Update dim service
793  fDimRefClock.setData(avgclk);
794  fDimRefClock.Update(tm);
795 
796  listclk.clear();
797 
798  // --------------- Temperatures ---------------
799 
800  // remove expired data from history
801  while (1)
802  {
803  auto it=listtmp.begin();
804  if (it==listtmp.end() || it->first+delay>tm)
805  break;
806  listtmp.pop_front();
807  }
808 
809  // Structure for dim service
810  struct Temp
811  {
812  uint16_t num;
813  float val[160];
814  Temp() { memset(this, 0, sizeof(Temp)); }
815  } __attribute__((__packed__));
816 
817  // Calculate average and fll structure
818  vector<uint32_t> tmpnum(160);
819 
820  Temp avgtmp;
821  avgtmp.num = listtmp.size();
822  for (auto it=listtmp.begin(); it!=listtmp.end(); it++)
823  for (int i=0; i<160; i++)
824  if (it->second[i]!=INT16_MIN)
825  {
826  avgtmp.val[i] += it->second[i];
827  tmpnum[i]++;
828  }
829  for (int i=0; i<160; i++)
830  avgtmp.val[i] /= tmpnum[i]*16;
831 
832  // Update dim service
833  fDimTemperature.setData(avgtmp);
835 
836  listtmp.clear();
837 
838  return true;
839  }
struct EventBuilderWrapper::EventData __attribute__((__packed__))
int i
Definition: db_dim_client.c:21
Adds some functionality to boost::posix_time::ptime for our needs.
Definition: Time.h:30
DimDescribedService fDimTemperature
DimDescribedService fDimRefClock
void setData(const void *ptr, size_t sz)

+ Here is the call graph for this function: