Ignore:
Timestamp:
Apr 8, 2016, 3:40:57 PM (8 years ago)
Author:
Bayard Gildas
Message:

sources reformatted with flair-format-dir script

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/FlairSensorActuator/src/SimuUs.cpp

    r3 r15  
    2929using namespace flair::gui;
    3030
    31 namespace flair
    32 {
    33 namespace sensor
    34 {
     31namespace flair {
     32namespace sensor {
    3533
    36 SimuUs::SimuUs(const FrameworkManager* parent,string name,uint32_t dev_id,uint8_t priority) : Thread(parent,name,priority), UsRangeFinder(parent,name)
    37 {
    38     data_rate=new SpinBox(GetGroupBox()->NewRow(),"data rate"," Hz",1,500,1,50);
     34SimuUs::SimuUs(const FrameworkManager *parent, string name, uint32_t dev_id,
     35               uint8_t priority)
     36    : Thread(parent, name, priority), UsRangeFinder(parent, name) {
     37  data_rate =
     38      new SpinBox(GetGroupBox()->NewRow(), "data rate", " Hz", 1, 500, 1, 50);
    3939
    40     ostringstream dev_name;
    41     dev_name << "simu_us_" << dev_id;
    42     shmem=new SharedMem((Thread*)this,dev_name.str().c_str(),sizeof(float));
     40  ostringstream dev_name;
     41  dev_name << "simu_us_" << dev_id;
     42  shmem = new SharedMem((Thread *)this, dev_name.str().c_str(), sizeof(float));
    4343}
    4444
    45 SimuUs::SimuUs(const IODevice* parent,string name,uint32_t dev_id) : Thread(parent,name,0), UsRangeFinder(parent,name)
    46 {
    47     data_rate=NULL;
     45SimuUs::SimuUs(const IODevice *parent, string name, uint32_t dev_id)
     46    : Thread(parent, name, 0), UsRangeFinder(parent, name) {
     47  data_rate = NULL;
    4848
    49     ostringstream dev_name;
    50     dev_name << "simu_us_" << dev_id;
    51     shmem=new SharedMem((Thread*)this,dev_name.str().c_str(),sizeof(float));
     49  ostringstream dev_name;
     50  dev_name << "simu_us_" << dev_id;
     51  shmem = new SharedMem((Thread *)this, dev_name.str().c_str(), sizeof(float));
    5252}
    5353
    54 SimuUs::~SimuUs()
    55 {
    56     SafeStop();
    57     Join();
     54SimuUs::~SimuUs() {
     55  SafeStop();
     56  Join();
    5857}
    5958
    60 void SimuUs::Run(void)
    61 {
    62     float z;
     59void SimuUs::Run(void) {
     60  float z;
    6361
    64     if(data_rate==NULL)
    65     {
    66         Thread::Err("not applicable for simulation part.\n");
    67         return;
     62  if (data_rate == NULL) {
     63    Thread::Err("not applicable for simulation part.\n");
     64    return;
     65  }
     66
     67  SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
     68
     69  while (!ToBeStopped()) {
     70    WaitPeriod();
     71
     72    shmem->Read((char *)&z, sizeof(float));
     73
     74    if (data_rate->ValueChanged() == true) {
     75      SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
    6876    }
    6977
    70     SetPeriodUS((uint32_t)(1000000./data_rate->Value()));
    71 
    72     while(!ToBeStopped())
    73     {
    74         WaitPeriod();
    75 
    76         shmem->Read((char*)&z,sizeof(float));
    77 
    78         if(data_rate->ValueChanged()==true)
    79         {
    80             SetPeriodUS((uint32_t)(1000000./data_rate->Value()));
    81         }
    82 
    83         output->SetValue(0,0,z);
    84         output->SetDataTime(GetTime());
    85         ProcessUpdate(output);
    86     }
     78    output->SetValue(0, 0, z);
     79    output->SetDataTime(GetTime());
     80    ProcessUpdate(output);
     81  }
    8782}
    8883
Note: See TracChangeset for help on using the changeset viewer.