Index: trunk/MagicSoft/Cosy/devdrv/macs.cc
===================================================================
--- trunk/MagicSoft/Cosy/devdrv/macs.cc	(revision 8811)
+++ trunk/MagicSoft/Cosy/devdrv/macs.cc	(revision 8835)
@@ -1,5 +1,4 @@
 #include "macs.h"
 
-#include <iostream>
 #include <sys/time.h>   // timeval->tv_sec
 
@@ -29,6 +28,6 @@
 */
 
-Macs::Macs(const BYTE_t nodeid, const char *name, MLog &out)
-    : NodeDrv(nodeid, name, out), fMacId(2*nodeid+1),
+Macs::Macs(const BYTE_t nodeid, const char *name)
+    : NodeDrv(nodeid, name), fMacId(2*nodeid+1),
     fPos(0), fPdoPos(0), fPosActive(0), fRpmActive(0),
     fStatusPdo3(0xff)
@@ -53,10 +52,10 @@
         if (subidx!=2)
             return;
-        lout << "- " << GetNodeName() << ": Error[0]=" << dec << val << endl;
+        gLog << inf2 << "- " << GetNodeName() << ": Error[0]=" << dec << val << endl;
         SetError(val);
         return;
 
     case 0x100a:
-        lout << "- " << GetNodeName() << ": Using Software Version V" << dec << (int)(val>>16) << "." << (int)(val&0xff) << endl;
+        gLog << inf2 << "- " << GetNodeName() << ": Using Software Version V" << dec << (int)(val>>16) << "." << (int)(val&0xff) << endl;
         fSoftVersion = val;
         return;
@@ -68,13 +67,13 @@
 
     case 0x100c:
-        lout << "- " << GetNodeName() << ": Guard time:" << dec << val << endl;
+        gLog << inf2 << "- " << GetNodeName() << ": Guard time:" << dec << val << endl;
         return;
 
     case 0x100d:
-        lout << "- " << GetNodeName() << ": Life time factor:" << dec << val << endl;
+        gLog << inf2 << "- " << GetNodeName() << ": Life time factor:" << dec << val << endl;
         return;
 
     case 0x2002:
-        cout << GetNodeName() << ": Current velocity: " << dec << val << endl;
+        gLog << inf2 << GetNodeName() << ": Current velocity: " << dec << val << endl;
         fVel = val;
         return;
@@ -123,15 +122,18 @@
 
     case 0x6002:
-        lout << "- " << GetNodeName() << ": Velocity resolution = " << dec << val << " ticks/min" << endl;
+        gLog << inf2 << "- " << GetNodeName() << ": Velocity resolution = " << dec << val << " ticks/min" << endl;
         fVelRes = val;
         return;
 
     case 0x6501:
-        lout << "- " << GetNodeName() << ": Encoder resolution = " << dec << val << " ticks/min" << endl;
+        gLog << inf2 << "- " << GetNodeName() << ": Encoder resolution = " << dec << val << " ticks/min" << endl;
         fRes = val;
         return;
     }
-    cout << "Macs: SDO, idx=0x"<< hex << idx << "/" << (int)subidx;
-    cout << ", val=0x"<<val<<endl;
+
+    NodeDrv::HandleSDO(idx, subidx, val, tv);
+
+//    cout << "Macs: SDO, idx=0x"<< hex << idx << "/" << (int)subidx;
+//    cout << ", val=0x"<<val<<endl;
 }
 
@@ -154,5 +156,5 @@
         case 1:
             //lout << ddev(MLog::eGui);
-            lout << "- " << GetNodeName() << ": State of node set." << endl;
+            gLog << inf2 << "- " << GetNodeName() << ": State of node set." << endl;
             //lout << edev(MLog::eGui);
             return;
@@ -165,5 +167,5 @@
         case 0:
             //lout << ddev(MLog::eGui);
-            lout << "- " << GetNodeName() << ": Guard time set." << endl;
+            gLog << inf2 << "- " << GetNodeName() << ": Guard time set." << endl;
             //lout << edev(MLog::eGui);
             return;
@@ -176,5 +178,5 @@
         case 0:
             //lout << ddev(MLog::eGui);
-            lout << "- " << GetNodeName() << ": Life time factor set." << endl;
+            gLog << inf2 << "- " << GetNodeName() << ": Life time factor set." << endl;
             //lout << edev(MLog::eGui);
             return;
@@ -187,5 +189,5 @@
         case 1:
             //lout << ddev(MLog::eGui);
-            lout << "- " << GetNodeName() << ": Status of PDO1 set." << endl;
+            gLog << inf2 << "- " << GetNodeName() << ": Status of PDO1 set." << endl;
             //lout << edev(MLog::eGui);
             return;
@@ -198,5 +200,5 @@
         case 0:
             //lout << ddev(MLog::eGui);
-            lout << "- " << GetNodeName() << ": Velocity set." << endl;
+            gLog << inf2 << "- " << GetNodeName() << ": Velocity set." << endl;
             //lout << edev(MLog::eGui);
             return;
@@ -209,10 +211,10 @@
         case 0:
             //lout << ddev(MLog::eGui);
-            lout << "- " << GetNodeName() << ": Acceleration set." << endl;
+            gLog << inf2 << "- " << GetNodeName() << ": Acceleration set." << endl;
             //lout << edev(MLog::eGui);
             return;
         case 1:
             //lout << ddev(MLog::eGui);
-            lout << "- " << GetNodeName() << ": Deceleration set." << endl;
+            gLog << inf2 << "- " << GetNodeName() << ": Deceleration set." << endl;
             //lout << edev(MLog::eGui);
             return;
@@ -225,5 +227,5 @@
         case 0:
             //lout << ddev(MLog::eGui);
-            lout << "- " << GetNodeName() << ": RPM mode switched." << endl;
+            gLog << inf2 << "- " << GetNodeName() << ": RPM mode switched." << endl;
             //lout << edev(MLog::eGui);
             return;
@@ -245,5 +247,5 @@
     case 0x6000:
         //lout << ddev(MLog::eGui);
-        lout << "- " << GetNodeName() << ": Rotation direction set." << endl;
+        gLog << inf2 << "- " << GetNodeName() << ": Rotation direction set." << endl;
         //lout << edev(MLog::eGui);
         return;
@@ -251,5 +253,5 @@
     case 0x6002:
         //lout << ddev(MLog::eGui);
-        lout << "- " << GetNodeName() << ": Velocitz resolution set." << endl;
+        gLog << inf2 << "- " << GetNodeName() << ": Velocitz resolution set." << endl;
         //lout << edev(MLog::eGui);
         return;
@@ -260,5 +262,5 @@
         case 0:
             //lout << ddev(MLog::eGui);
-            lout << "- " << GetNodeName() << ": Absolute positioning started." << endl;
+            gLog << inf2 << "- " << GetNodeName() << ": Absolute positioning started." << endl;
             //lout << edev(MLog::eGui);
             return;
@@ -266,5 +268,5 @@
         case 1:
             //lout << ddev(MLog::eGui);
-            lout << "- " << GetNodeName() << ": Relative positioning started." << endl;
+            gLog << inf2 << "- " << GetNodeName() << ": Relative positioning started." << endl;
             //lout << edev(MLog::eGui);
             return;
@@ -277,5 +279,5 @@
         case 0:
             //lout << ddev(MLog::eGui);
-            lout << "- " << GetNodeName() << ": Absolute positioning started." << endl;
+            gLog << inf2 << "- " << GetNodeName() << ": Absolute positioning started." << endl;
             //lout << edev(MLog::eGui);
             return;
@@ -283,5 +285,5 @@
         case 1:
             //lout << ddev(MLog::eGui);
-            lout << "- " << GetNodeName() << ": Relative positioning started." << endl;
+            gLog << inf2 << "- " << GetNodeName() << ": Relative positioning started." << endl;
             //lout << edev(MLog::eGui);
             return;
@@ -296,5 +298,5 @@
 void Macs::ReqVelRes()
 {
-    lout << "- " << GetNodeName() << ": Requesting velocity resolution (velres, 0x6002)." << endl;
+    gLog << inf2 << "- " << GetNodeName() << ": Requesting velocity resolution (velres, 0x6002)." << endl;
     RequestSDO(0x6002);
     WaitForSdo(0x6002);
@@ -303,5 +305,5 @@
 void Macs::ReqRes()
 {
-    lout << "- " << GetNodeName() << ": Requesting encoder resolution (res, 0x6501)." << endl;
+    gLog << inf2 << "- " << GetNodeName() << ": Requesting encoder resolution (res, 0x6501)." << endl;
     RequestSDO(0x6501);
     WaitForSdo(0x6501);
@@ -310,5 +312,5 @@
 void Macs::SetPDO1On(BYTE_t flag)
 {
-    lout << "- " << GetNodeName() << ": " << (flag?"Enable":"Disable") << " PDO1." << endl;
+    gLog << inf2 << "- " << GetNodeName() << ": " << (flag?"Enable":"Disable") << " PDO1." << endl;
     SendSDO(0x1800, 1, (LWORD_t)(flag?0:1)<<31); 
     WaitForSdo(0x1800, 1);           
@@ -322,5 +324,5 @@
     // After this the MACS will react on real movement commands.
     //
-    lout << "- " << GetNodeName() << ": Starting Node." << endl;
+    gLog << inf2 << "- " << GetNodeName() << ": Starting Node." << endl;
     SendSDO(0x1000, 1, (LWORD_t)1);
     WaitForSdo(0x1000, 1);
@@ -339,10 +341,10 @@
     // error list)
     //
-    lout << "- " << GetNodeName() << ": Requesting Error[0]." << endl;
+    gLog << inf2 << "- " << GetNodeName() << ": Requesting Error[0]." << endl;
     RequestSDO(0x1003, 2);
     WaitForSdo(0x1003, 2);
     if (HasError())
     {
-        lout << "Macs::Init: " << GetNodeName() << " has error --> ZOMBIE!" << endl;
+        gLog << err << "Macs::Init: " << GetNodeName() << " has error --> ZOMBIE!" << endl;
         SetZombie();
     }
@@ -353,5 +355,5 @@
     StopGuarding();
 
-    lout << "- " << GetNodeName() << ": Requesting Mac Software Version." << endl;
+    gLog << inf2 << "- " << GetNodeName() << ": Requesting Mac Software Version." << endl;
     RequestSDO(0x100a);
     WaitForSdo(0x100a);
@@ -360,5 +362,5 @@
     if (fSoftVersion<0x00000045) // 00.69
     {
-        lout << GetNodeName() << " - Software Version too old!" << endl;
+        gLog << err << GetNodeName() << " - Software Version too old!" << endl;
         SetZombie();
         return;
@@ -431,5 +433,5 @@
 void Macs::ReqPos()
 {
-    lout << "- " << GetNodeName() << ": Requesting Position." << endl;
+    gLog << inf2 << "- " << GetNodeName() << ": Requesting Position." << endl;
     RequestSDO(0x6004);
     WaitForSdo(0x6004);
@@ -438,5 +440,5 @@
 void Macs::ReqVel()
 {
-    lout << "- " << GetNodeName() << ": Requesting Velocity." << endl;
+    gLog << inf2 << "- " << GetNodeName() << ": Requesting Velocity." << endl;
     RequestSDO(0x2002);
     WaitForSdo(0x2002);
@@ -523,5 +525,5 @@
     // or by a positioning command (POSA, ...)
     //
-    lout << "- " << GetNodeName() << ": Starting RPM Sync Mode." << endl;
+    gLog << inf2 << "- " << GetNodeName() << ": Starting RPM Sync Mode." << endl;
     SendSDO(0x3007, 0, string('s', 'y', 'n', 'c'));
     WaitForSdo(0x3007, 0);
@@ -534,5 +536,5 @@
     // or by a positioning command (POSA, ...)
     //
-    lout << "- " << GetNodeName() << ": Starting Position Sync Mode." << endl;
+    gLog << inf2 << "- " << GetNodeName() << ": Starting Position Sync Mode." << endl;
     SendSDO(0x3007, 1, string('s', 'y', 'n', 'c'));
     WaitForSdo(0x3007, 1);
@@ -591,6 +593,6 @@
     if (!errnum)
     {
-        lout << "- " << GetNodeName() << ": reports Error occursion." << endl;
-        lout << "Macs::HandlePDO2: " << GetNodeName() << " --> ZOMBIE!" << endl;
+        gLog << err << "- " << GetNodeName() << ": reports Error occursion." << endl;
+        gLog << "Macs::HandlePDO2: " << GetNodeName() << " --> ZOMBIE!" << endl;
         SetZombie();
         SetError(-1);
@@ -604,5 +606,5 @@
     if (GetError()>0)
     {
-        lout << GetNodeName() << ": WARNING! Error #" << GetError() << " unhandled (not cleared) by software." << endl;
+        gLog << warn << GetNodeName() << ": WARNING! Error #" << GetError() << " unhandled (not cleared) by software." << endl;
 
         //
@@ -615,12 +617,12 @@
     SetError(errnum);
 
-    lout << GetNodeName() << " reports: ";
+    gLog << err << GetNodeName() << " reports: ";
     switch (errnum)
     {
     case 3:
-        lout << "Axis does not existing." << endl;
+        gLog << "Axis does not existing." << endl;
         return;
     case 5:
-        lout << "Error not cleared (while trying to move axis)" << endl;
+        gLog << "Error not cleared (while trying to move axis)" << endl;
         return;
     case 6:
@@ -630,16 +632,16 @@
         // from reporting this error a thousands of times.
         //
-        lout << "Home position not the first positioning command." << endl;
+        gLog << "Home position not the first positioning command." << endl;
         SetError(0);
         return;
     case 8:
-        lout << "Control deviation overflow." << endl;
+        gLog << "Control deviation overflow." << endl;
         return;
     case 9:
-        lout << "Zero index not found." << endl;
+        gLog << "Zero index not found." << endl;
         return;
     case 10:
-        lout << "Unknown command, syntax error." << endl;
-        lout << "Please recompile and reload program." << endl;
+        gLog << "Unknown command, syntax error." << endl;
+        gLog << "Please recompile and reload program." << endl;
         return;
     case 11:
@@ -648,71 +650,71 @@
         {
         case -1:
-            lout << "Negative";
+            gLog << "Negative";
             break;
         case 1:
-            lout << "Positive";
+            gLog << "Positive";
             break;
         default:
-            lout << "-unknown-";
+            gLog << "-unknown-";
         }
         switch (errnum)
         {
         case 11:
-            lout << " software";
+            gLog << " software";
             break;
         case 25:
-            lout << " hardware";
+            gLog << " hardware";
             break;
         }
-        lout << " endswitch activated." << endl;
+        gLog << " endswitch activated." << endl;
         return;
     case 12:
-        lout << "Wrong parameter number used in SET command." << endl;
+        gLog << "Wrong parameter number used in SET command." << endl;
         return;
     case 14:
-        lout << " Too many LOOP calls." << endl;
+        gLog << " Too many LOOP calls." << endl;
         return;
     case 16:
-        lout << "Parameter in EEPROM broken (means: EEPROM broken, or saving not finished)" << endl;
-        lout << "Please use APOSS to 'Reset' the MACS and reload the parameters." << endl;
+        gLog << "Parameter in EEPROM broken (means: EEPROM broken, or saving not finished)" << endl;
+        gLog << "Please use APOSS to 'Reset' the MACS and reload the parameters." << endl;
         return;
     case 17:
-        lout << "Program in EEPROM broken (means: EEPROM broken, or saving not finished)" << endl;
-        lout << "Please use APOSS to delete all Programs restore the programs." << endl;
+        gLog << "Program in EEPROM broken (means: EEPROM broken, or saving not finished)" << endl;
+        gLog << "Please use APOSS to delete all Programs restore the programs." << endl;
         return;
     case 18:
-        lout << "Reset by CPU (reset called by Watch-dog cause of CPU halted)" << endl;
-        lout << "Possible reasons: short under-/overvoltage or shortcut." << endl;
+        gLog << "Reset by CPU (reset called by Watch-dog cause of CPU halted)" << endl;
+        gLog << "Possible reasons: short under-/overvoltage or shortcut." << endl;
         return;
     case 19:
-        lout << "User break (autostart program stopped by user)" << endl;
+        gLog << "User break (autostart program stopped by user)" << endl;
         return;
     case 51:
-        lout << "Too many (>=10) GOSUB calls." << endl;
+        gLog << "Too many (>=10) GOSUB calls." << endl;
         return;
     case 52:
-        lout << "Too many RETURN calls." << endl;
+        gLog << "Too many RETURN calls." << endl;
         return;
     case 62:
-        lout << "Error veryfiing EEPROM after access (Try again savaing parameters or program)" << endl;
+        gLog << "Error veryfiing EEPROM after access (Try again savaing parameters or program)" << endl;
         return;
     case 70:
-        lout << "Error in DIM call (call to DIM doesn't fit existing DIM call)" << endl;
+        gLog << "Error in DIM call (call to DIM doesn't fit existing DIM call)" << endl;
         return;
     case 71:
-        lout << "Array out of bound." << endl;
+        gLog << "Array out of bound." << endl;
         return;
     case 79:
-        lout << "Timeout waiting for index (WAITNDX)." << endl;
+        gLog << "Timeout waiting for index (WAITNDX)." << endl;
         return;
     case 84:
-        lout << "Too many (>12) ON TIME calls." << endl;
+        gLog << "Too many (>12) ON TIME calls." << endl;
         return;
     case 87:
-        lout << "Out of memory for variables - Check APOSS predifined number of" << endl;
-        lout << "variables and try deleting the array by doing a 'Reset' from APOSS." << endl;
+        gLog << "Out of memory for variables - Check APOSS predifined number of" << endl;
+        gLog << "variables and try deleting the array by doing a 'Reset' from APOSS." << endl;
         return;
     case 89:
-        lout << "CAN I/O error (REOPEN=" << dec << errinf << " " << (errinf==0?"OK":"ERR") << ")" << endl;
+        gLog << "CAN I/O error (REOPEN=" << dec << errinf << " " << (errinf==0?"OK":"ERR") << ")" << endl;
         return;
 
@@ -723,5 +725,5 @@
 
     default:
-        lout << "Error Nr. " << errnum << ", " << errinf << endl;
+        gLog << "Error Nr. " << errnum << ", " << errinf << endl;
     }
 }
@@ -737,5 +739,5 @@
     time.Now();
 
-    lout << time << ": " << GetNodeName() << " - PDO3 = ";
+    gLog << inf << time << ": " << GetNodeName() << " - PDO3 = ";
     const Bool_t ready = data[3]&0x01;
     const Bool_t fuse  = data[3]&0x02;
@@ -745,12 +747,12 @@
     const Bool_t rf    = data[3]&0x20;
     const Bool_t brake = data[3]&0x40;
-    if (ready) lout << "DKC-Ready ";
-    if (fuse)  lout << "FuseOk ";
-    if (emcy)  lout << "EmcyOk ";
-    if (vltg)  lout << "OvervoltOk ";
-    if (mode)  lout << "SwitchToManualMode ";
-    if (rf)    lout << "RF ";
-    if (brake) lout << "BrakeOpen ";
-    lout << endl;
+    if (ready) gLog << "DKC-Ready ";
+    if (fuse)  gLog << "FuseOk ";
+    if (emcy)  gLog << "EmcyOk ";
+    if (vltg)  gLog << "OvervoltOk ";
+    if (mode)  gLog << "SwitchToManualMode ";
+    if (rf)    gLog << "RF ";
+    if (brake) gLog << "BrakeOpen ";
+    gLog << endl;
 
     fStatusPdo3 = data[3];
@@ -780,5 +782,5 @@
     // we can go on working 'as usual' Eg. Initialize a Display Update
     //
-    cout << GetNodeName() << " Handling Error #" << dec << GetError() << endl;
+    gLog << inf << GetNodeName() << " Handling Error #" << dec << GetError() << endl;
     switch (GetError())
     {
@@ -787,10 +789,10 @@
     case   9: // zero idx
     case  84: // ON TIME
-        lout << "- " << GetNodeName() << ": Cannot handle error #" << GetError() << endl;
+        gLog << "- " << GetNodeName() << ": Cannot handle error #" << GetError() << endl;
         return;
 
     case 11:  // software endswitch
     case 25:  // hardware endswitch
-        lout << "- " << GetNodeName() << ": Cannot handle error 'Endswitch!'" << endl;
+        gLog << "- " << GetNodeName() << ": Cannot handle error 'Endswitch!'" << endl;
         return;
 
@@ -805,5 +807,5 @@
         */
     default:
-        lout << "- " << GetNodeName() << ": Cannot handle error #" << GetError() << endl;
+        gLog << "- " << GetNodeName() << ": Cannot handle error #" << GetError() << endl;
  
     }
@@ -850,6 +852,6 @@
     WaitForSdo(0x100d);
 
-    lout << "- " << GetNodeName() << ": Hostguarding started (" << dec;
-    lout << GetLifeTimeFactor() << "*" << GetGuardTime() << "ms)" << endl;
+    gLog << inf2 << "- " << GetNodeName() << ": Hostguarding started (" << dec;
+    gLog << GetLifeTimeFactor() << "*" << GetGuardTime() << "ms)" << endl;
 }
 
@@ -866,5 +868,5 @@
     WaitForSdo(0x100d);
 
-    lout << "- " << GetNodeName() << ": Hostguarding stopped." << endl;
-}
-
+    gLog << inf2 << "- " << GetNodeName() << ": Hostguarding stopped." << endl;
+}
+
