Index: /trunk/MagicSoft/Cosy/Changelog
===================================================================
--- /trunk/MagicSoft/Cosy/Changelog	(revision 8862)
+++ /trunk/MagicSoft/Cosy/Changelog	(revision 8863)
@@ -1,5 +1,22 @@
                                                                   -*-*- END -*-*-
 
- 2008/02/13 Thomas Bretz (La Palma)
+ 2008/02/15 Thomas Bretz (La Palma)
+
+   * candrv/network.cc, candrv/nodedrv.h:
+     - changed arguments and contents of HandleSDOError
+
+   * devdrv/macs.[h,cc]:
+     - added status/error handling for DKC status
+
+   * devdrv/shaftencoder.cc:
+     - changed some output
+     - handle all four bytes in case of the position
+
+   * gui/MGCosy.cc:
+     - increased width of shaftencoder labels
+
+
+
+ 2008/02/15 Thomas Bretz (La Palma)
 
    * cosy.cc:
Index: /trunk/MagicSoft/Cosy/candrv/network.cc
===================================================================
--- /trunk/MagicSoft/Cosy/candrv/network.cc	(revision 8862)
+++ /trunk/MagicSoft/Cosy/candrv/network.cc	(revision 8863)
@@ -111,5 +111,5 @@
 
         case kSDO_TX_ERROR:  // error message (instead of 0x60)
-            fNodes[node]->HandleSDOError(data);
+            fNodes[node]->HandleSDOError(idx, subidx);
             return;
         }
Index: /trunk/MagicSoft/Cosy/candrv/nodedrv.cc
===================================================================
--- /trunk/MagicSoft/Cosy/candrv/nodedrv.cc	(revision 8862)
+++ /trunk/MagicSoft/Cosy/candrv/nodedrv.cc	(revision 8863)
@@ -167,8 +167,8 @@
 // Print an error message with the corresponding data from this device.
 //
-void NodeDrv::HandleSDOError(LWORD_t data)
-{
-    gLog << warn << "WARNING - Nodedrv::HandleSDOError: Entry not found in dictionary (data=0x";
-    gLog << hex << setfill('0') << setw(4) << data << ")";
+void NodeDrv::HandleSDOError(WORD_t idx, BYTE_t subidx)
+{
+    gLog << warn << "WARNING - Nodedrv::HandleSDOError: Node #" << dec << (int)fId << ": Entry not found in dictionary (idx=0x";
+    gLog << hex << setfill('0') << setw(4) << idx << "/" << (int)subidx << dec << ")";
     gLog << endl;
 }
Index: /trunk/MagicSoft/Cosy/candrv/nodedrv.h
===================================================================
--- /trunk/MagicSoft/Cosy/candrv/nodedrv.h	(revision 8862)
+++ /trunk/MagicSoft/Cosy/candrv/nodedrv.h	(revision 8863)
@@ -67,5 +67,5 @@
     virtual void HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, const timeval_t &tv);
     virtual void HandleSDOOK(WORD_t idx, BYTE_t subidx, LWORD_t data, const timeval_t &tv);
-    virtual void HandleSDOError(LWORD_t data);
+    virtual void HandleSDOError(WORD_t idx, BYTE_t subidx);
 
     virtual void HandlePDO1(const BYTE_t *data, const timeval_t &tv) {}
Index: /trunk/MagicSoft/Cosy/devdrv/macs.cc
===================================================================
--- /trunk/MagicSoft/Cosy/devdrv/macs.cc	(revision 8862)
+++ /trunk/MagicSoft/Cosy/devdrv/macs.cc	(revision 8863)
@@ -4,5 +4,8 @@
 
 #include "network.h"
+
 #include "MLogManip.h"
+
+#include "MString.h"
 
 ClassImp(Macs);
@@ -42,4 +45,96 @@
 }
 
+TString Macs::EvalStatusDKC(UInt_t stat) const
+{
+    switch (stat)
+    {
+    case 0: return "offline";
+    case 0xa000:
+    case 0xa001:
+    case 0xa002:
+    case 0xa003: return MString::Format("Communication phase %d", stat&0xf);
+    case 0xa010: return "Drive HALT";
+    case 0xa012: return "Control and power section ready for operation";
+    case 0xa013: return "Ready for power on";
+    case 0xa100: return "Drive in Torque mode";
+    case 0xa101: return "Drive in Velocity mode";
+    case 0xa102: return "Position control mode with encoder 1";
+    case 0xa103: return "Position control mode with encoder 2";
+    case 0xa104: return "Lagless position control mode with encoder 1";
+    case 0xa105: return "Lagless position control mode with encoder 2";
+    case 0xa106: return "Drive controlled interpolated positioning with encoder 1";
+    case 0xa107: return "Drive controlled interpolated positioning with encoder 2";
+    case 0xa108: return "Drive controlled interpolated absolute positioning lagless with encoder 1";
+    case 0xa109: return "Drive controlled interpolated absolute positioning lagless with encoder 2";
+    case 0xa146: return "Drive controlled interpolated relative positioning with encoder 1";
+    case 0xa147: return "Drive controlled interpolated relative positioning with encoder 2";
+    case 0xa148: return "Drive controlled interpolated relative positioning lagless with encoder 1";
+    case 0xa149: return "Drive controlled interpolated relative positioning lagless with encoder 2";
+    case 0xa208: return "Jog mode positive";
+    case 0xa218: return "Jog mode negative";
+    case 0xa400: return "Automatic drive check and adjustment";
+    case 0xa401: return "Drive decelerating to standstill";
+    case 0xa800: return "Unknown operation mode";
+    case 0xc217: return "Motor encoder reading error";
+    case 0xc218: return "Shaft encoder reading error";
+    case 0xc220: return "Motor encoder initialization error";
+    case 0xc221: return "Shaft encoder initialization error";
+    case 0xc400: return "Switching to parameter mode";
+    case 0xc500: return "Error reset";
+    case 0xe225: return "Motor overload";
+    case 0xe250: return "Drive overtemp warning";
+    case 0xe251: return "Motor overtemp warning";
+    case 0xe252: return "Bleeder overtemp warning";
+    case 0xe834: return "Emergency-Stop";
+    case 0xe843: return "Positive end-switch activated";
+    case 0xe844: return "Negative end-switch activated";
+    case 0xf218: return "Amplifier overtemp shutdown";
+    case 0xf219: return "Motor overtemp shutdown";
+    case 0xf220: return "Bleeder overload shutdown";
+    case 0xf221: return "Motor temperature surveillance defective";
+    case 0xf224: return "Maximum breaking time exceeded";
+    case 0xf228: return "Excessive control deviation";
+    case 0xf269: return "Error during release of the motor holding brake";
+    case 0xf276: return "Absolute encoder out of allowed window";
+    case 0xf409: return "Bus error on Profibus interface";
+    case 0xf434: return "Emergency-Stop";
+    case 0xf629: return "Positive sw end-switch";
+    case 0xf630: return "Negative sw end-switch";
+    case 0xf634: return "Emergency-Stop";
+    case 0xf643: return "Positive hw end-switch";
+    case 0xf644: return "Negative hw end-switch";
+    case 0xf870: return "24V DC error.";
+    case 0xf878: return "Velocity loop error";
+    }
+    return "unknown";
+}
+
+Bool_t Macs::EvalStatus(LWORD_t val) const
+{
+    const Int_t errnum = val&0xffff;
+    const Int_t errinf = val>>16;
+
+    if (errnum!=0xff)
+        return errnum==0;
+
+    const Int_t type = errinf&0xf000;
+
+    gLog << all << "DKC reports: ";
+
+    switch (type)
+    {
+    case 0xf000: gLog << "ERROR"; break;
+    case 0xe000: gLog << "WARNING"; break;
+    case 0xa000: gLog << "Status"; break;
+    default:     gLog << "Unknown"; break;
+    }
+
+    gLog << " (" << MString::Format("%X", errinf) << "): " << EvalStatusDKC(errinf);
+
+    gLog << (type==0xf000 || type==0xe000 ? "!" : ".") << endl;
+
+    return type==0xa000;
+}
+
 void Macs::HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, const timeval_t &tv)
 {
@@ -52,6 +147,6 @@
         if (subidx!=2)
             return;
-        gLog << inf2 << "- " << GetNodeName() << ": Error[0]=" << dec << val << endl;
-        SetError(val);
+        gLog << inf2 << "- " << GetNodeName() << ": Error[0]=" << hex << val << dec << endl;
+        SetError(EvalStatus(val) ? 0 : val);
         return;
 
@@ -122,10 +217,10 @@
 
     case 0x6002:
-        gLog << inf2 << "- " << GetNodeName() << ": Velocity resolution = " << dec << val << " ticks/min" << endl;
+        gLog << inf2 << "- " << GetNodeName() << ": Velocity resolution = " << dec << val << " (100%)" << endl;
         fVelRes = val;
         return;
 
     case 0x6501:
-        gLog << inf2 << "- " << GetNodeName() << ": Encoder resolution = " << dec << val << " ticks/min" << endl;
+        gLog << inf2 << "- " << GetNodeName() << ": Encoder resolution = " << dec << val << " ticks" << endl;
         fRes = val;
         return;
@@ -362,5 +457,5 @@
     if (fSoftVersion<0x00000045) // 00.69
     {
-        gLog << err << GetNodeName() << " - Software Version too old!" << endl;
+        gLog << err << GetNodeName() << " - Software Version " << 0.01*fSoftVersion << " too old!" << endl;
         SetZombie();
         return;
@@ -471,4 +566,5 @@
     SendSDO(0x2002, vel);     // velocity
     WaitForSdo(0x2002, 0);
+    cout << "SET VEL: " << vel << endl;
 }
 
@@ -477,4 +573,5 @@
     SendSDO(0x2003, 0, acc);  // acceleration
     WaitForSdo(0x2003, 0);
+    cout << "SET ACC: " << acc << endl;
 }
 
@@ -483,4 +580,5 @@
     SendSDO(0x2003, 1, dec);  // acceleration
     WaitForSdo(0x2003, 1);
+    cout << "SET DEC: " << dec << endl;
 }
 
@@ -503,4 +601,5 @@
 {
     SendSDO(0x6004, 1, (LWORD_t)pos);
+    cout << "REL POS: " << (LWORD_t)pos << endl;
 }
 
@@ -508,4 +607,5 @@
 {
     SendSDO(0x6004, 0, (LWORD_t)pos);
+    cout << "ABS POS: " << (LWORD_t)pos << endl;
 }
 
@@ -585,5 +685,13 @@
     LWORDS_t errinf = (data[4]<<24) | (data[5]<<16) | (data[6]<<8) | data[7];
 
-    //
+    // Check if the DKC changed its status message
+    if (errnum==0xff && (errinf&0xf000)<=0xe000)
+    {
+        EvalStatus(errnum, errinf);
+        SetError(0);
+        return;
+    }
+
+    // Check if MACS report error occursion.
     // errnum==0 gives a sudden information that something happened. Now the
     // microcontroller is running inside its interrupt procedure which
@@ -606,5 +714,5 @@
     if (GetError()>0)
     {
-        gLog << warn << GetNodeName() << ": WARNING! Error #" << GetError() << " unhandled (not cleared) by software." << endl;
+        gLog << warn << GetNodeName() << ": WARNING! Previous error #" << GetError() << " unhandled (not cleared) by software." << endl;
 
         //
@@ -724,6 +832,10 @@
         return;
 
+    case 0xff:
+        EvalStatus(errnum, errinf);
+        return;
+
     default:
-        gLog << "Error Nr. " << errnum << ", " << errinf << endl;
+        gLog << "Error Nr. " << dec << errnum << ", " << errinf << endl;
     }
 }
@@ -800,4 +912,9 @@
         DelError();
         return;
+
+    case 0xff:
+        gLog << err << "DKC error! Go and check what is going on!" << endl;
+        DelError();
+        return;
 /*
     case 101:
@@ -870,3 +987,2 @@
     gLog << inf2 << "- " << GetNodeName() << ": Hostguarding stopped." << endl;
 }
-
Index: /trunk/MagicSoft/Cosy/devdrv/macs.h
===================================================================
--- /trunk/MagicSoft/Cosy/devdrv/macs.h	(revision 8862)
+++ /trunk/MagicSoft/Cosy/devdrv/macs.h	(revision 8863)
@@ -37,4 +37,11 @@
     void Init();
     void StopDevice();
+
+    TString EvalStatusDKC(UInt_t stat) const;
+    Bool_t  EvalStatus(LWORD_t val) const;
+    Bool_t  EvalStatus(UInt_t errnum, UInt_t errinf) const
+    {
+        return EvalStatus(errnum|(errinf<<16));
+    }
 
     void HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, const timeval_t &tv);
Index: /trunk/MagicSoft/Cosy/devdrv/shaftencoder.cc
===================================================================
--- /trunk/MagicSoft/Cosy/devdrv/shaftencoder.cc	(revision 8862)
+++ /trunk/MagicSoft/Cosy/devdrv/shaftencoder.cc	(revision 8863)
@@ -92,5 +92,5 @@
 
     case 0x6004:
-        gLog << inf2 << "- Position: " << dec << val << endl;
+        gLog << inf2 << "- Reported position: " << dec << (Int_t)val << endl;
         fPos  = val;
         fTurn = 0;
@@ -237,5 +237,5 @@
     // Decode information, we have a 14bit only
     //
-    LWORDS_t pos  = data[0] | (data[1]<<8) | (data[2]<<16); // | (data[3]<<24);
+    LWORDS_t pos  = data[0] | (data[1]<<8) | (data[2]<<16) | (data[3]<<24);
     BYTE_t   flag = data[4];
 
Index: /trunk/MagicSoft/Cosy/gui/MGCosy.cc
===================================================================
--- /trunk/MagicSoft/Cosy/gui/MGCosy.cc	(revision 8862)
+++ /trunk/MagicSoft/Cosy/gui/MGCosy.cc	(revision 8863)
@@ -165,7 +165,7 @@
     fList->Add(fWeather);
 
-    fLabel1 = new TGLabel(f, "00000"); // Max: 16384
-    fLabel2 = new TGLabel(f, "00000");
-    fLabel3 = new TGLabel(f, "00000");
+    fLabel1 = new TGLabel(f, "00000000"); // Max: 16384
+    fLabel2 = new TGLabel(f, "00000000");
+    fLabel3 = new TGLabel(f, "00000000");
     fLabel1->SetTextJustify(kTextRight);
     fLabel2->SetTextJustify(kTextRight);
