Revision: 9043
          http://playerstage.svn.sourceforge.net/playerstage/?rev=9043&view=rev
Author:   jpgr87
Date:     2011-05-12 02:08:59 +0000 (Thu, 12 May 2011)

Log Message:
-----------
Applied patch #3296942: diocmd clk signal generation ability

Modified Paths:
--------------
    code/player/trunk/server/drivers/shell/diocmd.cc

Modified: code/player/trunk/server/drivers/shell/diocmd.cc
===================================================================
--- code/player/trunk/server/drivers/shell/diocmd.cc    2011-04-11 22:16:54 UTC 
(rev 9042)
+++ code/player/trunk/server/drivers/shell/diocmd.cc    2011-05-12 02:08:59 UTC 
(rev 9043)
@@ -57,10 +57,19 @@
 - read_only (integer)
   - Default: 1
   - If set to 1, received commands will not change the state
+- wait_on_normal (double)
+  - Default: 0.0 (no effect)
+  - Wait time in secs.
+- wait_on_opposite (double)
+  - Default: 0.0 (no effect)
+  - Wait time in secs.
 - sleep_nsec (integer)
   - Default: 100000000 (10 sends per second)
   - timespec value for nanosleep()
 
+When wait_on_normal and wait_on_opposite options are given,
+this driver acts as a clock signal source.
+
 @par Example
 
 @verbatim
@@ -84,6 +93,8 @@
 #include <pthread.h>
 #include <libplayercore/playercore.h>
 
+#define EPS 0.000000000000001
+
 class DioCmd : public ThreadedDriver
 {
   public:
@@ -110,9 +121,12 @@
     uint32_t bits;
     uint32_t bits_count;
     int read_only;
+    double wait_on_normal;
+    double wait_on_opposite;
     int sleep_nsec;
     uint32_t state;
     uint32_t state_count;
+    int opposite;
 };
 
 
////////////////////////////////////////////////////////////////////////////////
@@ -131,9 +145,12 @@
   this->bits = 0;
   this->bits_count = 0;
   this->read_only = 0;
+  this->wait_on_normal = 0.0;
+  this->wait_on_opposite = 0.0;
   this->sleep_nsec = 0;
   this->state = 0;
   this->state_count = 0;
+  this->opposite = 0;
   if (cf->ReadDeviceAddr(&(this->provided_dio_addr), section, "provides",
                          PLAYER_DIO_CODE, -1, NULL))
   {
@@ -192,6 +209,20 @@
   this->state = this->bits;
   this->state_count = this->bits_count;
   this->read_only = cf->ReadInt(section, "read_only", 1);
+  this->wait_on_normal = cf->ReadFloat(section, "wait_on_normal", 0.0);
+  if (this->wait_on_normal < 0.0)
+  {
+    PLAYER_ERROR("Invalid wait_on_normal value");
+    this->SetError(-1);
+    return;
+  }
+  this->wait_on_opposite = cf->ReadFloat(section, "wait_on_opposite", 0.0);
+  if (this->wait_on_opposite < 0.0)
+  {
+    PLAYER_ERROR("Invalid wait_on_opposite value");
+    this->SetError(-1);
+    return;
+  }
   this->sleep_nsec = cf->ReadInt(section, "sleep_nsec", 100000000);
   if ((this->sleep_nsec) <= 0)
   {
@@ -236,14 +267,20 @@
 
 
////////////////////////////////////////////////////////////////////////////////
 // Main function for device thread
-void DioCmd::Main() 
+void DioCmd::Main()
 {
   struct timespec tspec;
   player_dio_cmd_t dio_cmd;
   player_dio_data_t dio_data;
+  double last_time = 0.0;
+  double d = 0.0;
+  uint32_t tmp;
+  int i;
 
   this->state = this->bits;
   this->state_count = this->bits_count;
+  this->opposite = 0;
+  GlobalTime->GetTimeDouble(&last_time);
   for (;;)
   {
     // Test if we are supposed to cancel
@@ -255,6 +292,22 @@
     // Test if we are supposed to cancel
     pthread_testcancel();
 
+    if (((this->wait_on_normal) > EPS) && ((this->wait_on_opposite) > EPS))
+    {
+      GlobalTime->GetTimeDouble(&d);
+      if (((d - last_time) + EPS) >= ((this->opposite) ? 
(this->wait_on_opposite) : (this->wait_on_normal)))
+      {
+        tmp = 1;
+        for (i = 0; i < static_cast<int>(this->state_count); i++)
+        {
+          this->state ^= tmp;
+          tmp <<= 1;
+        }
+        last_time = d;
+        (this->opposite) = (!(this->opposite));
+      }
+    }
+
     if (this->use_dio)
     {
       memset(&dio_cmd, 0, sizeof dio_cmd);
@@ -324,6 +377,7 @@
     if (!dio_cmd) return -1;
     this->state = dio_cmd->digout;
     this->state_count = dio_cmd->count;
+    this->opposite = 0;
     return 0;
   }
   return -1;


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Achieve unprecedented app performance and reliability
What every C/C++ and Fortran developer should know.
Learn how Intel has extended the reach of its next-generation tools
to help boost performance applications - inlcuding clusters.
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to