Index: trunk/MagicSoft/Cosy/Changelog
===================================================================
--- trunk/MagicSoft/Cosy/Changelog	(revision 1958)
+++ trunk/MagicSoft/Cosy/Changelog	(revision 1959)
@@ -1,3 +1,21 @@
                                                                   -*-*- END -*-*-
+ 2003/04/13 - Thomas Bretz
+
+   * base/timer.cc:
+     - added cast to _suseconds_t
+   
+   * candrv/nodedrv.cc:
+     - set starting timeout
+   
+   * devdrv/macs.cc:
+     - after requsting error[0] check Zombie-status
+     - Software version 0.66 --> 0.68
+     - added all known MACS error messages
+
+   * gui/MGStarguider.cc, videodev/Filter.[h,cc]:
+     - added stretching of the picture
+
+
+
  2003/04/12 - Thomas Bretz
 
Index: trunk/MagicSoft/Cosy/base/timer.cc
===================================================================
--- trunk/MagicSoft/Cosy/base/timer.cc	(revision 1958)
+++ trunk/MagicSoft/Cosy/base/timer.cc	(revision 1959)
@@ -30,5 +30,5 @@
 {
     tv->tv_sec  = fSecs;
-    tv->tv_usec = fMs;
+    tv->tv_usec = (__suseconds_t)fMs;
 }
 
Index: trunk/MagicSoft/Cosy/candrv/nodedrv.cc
===================================================================
--- trunk/MagicSoft/Cosy/candrv/nodedrv.cc	(revision 1958)
+++ trunk/MagicSoft/Cosy/candrv/nodedrv.cc	(revision 1959)
@@ -501,6 +501,7 @@
     fTimeout->Reset();
 
-//    Timer t;
-//    fTimeoutTime = t.Now() + (fGuardTime*fLifeTimeFactor/1000.);
+    Timer t;
+    fTimeoutTime = t.Now() + (fGuardTime*fLifeTimeFactor/1000.);
+    //cout << GetNodeName() << ": " << fmod(fTimeoutTime*10000, 10000)/10 << endl;
 
     fTimeout->TurnOn();
@@ -583,5 +584,5 @@
     if (now > fTimeoutTime)
     {
-        cout << "==out==> " << fmod(now*1000, 10000)/10 << " > " << fmod(fTimeoutTime*10000, 10000)/10 << endl;
+        cout << GetNodeName() << ": " << "==out==> " << fmod(now*1000, 10000)/10 << " > " << fmod(fTimeoutTime*10000, 10000)/10 << endl;
         //cout << "ERROR - " << GetNodeName() << " didn't respond in timeout window." << endl;
         //lout << "ERROR - " << GetNodeName() << " didn't respond in timeout window." << endl;
@@ -609,4 +610,5 @@
     Timer t(tv);
     fTimeoutTime = t + (fGuardTime*fLifeTimeFactor/1000.);
+    //cout << GetNodeName() << ": " << fmod(fTimeoutTime*10000, 10000)/10 << endl;
 }
 
Index: trunk/MagicSoft/Cosy/devdrv/macs.cc
===================================================================
--- trunk/MagicSoft/Cosy/devdrv/macs.cc	(revision 1958)
+++ trunk/MagicSoft/Cosy/devdrv/macs.cc	(revision 1959)
@@ -44,4 +44,6 @@
 void Macs::HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, timeval_t *tv)
 {
+  // cout << "SdoRx: Idx=0x"<< hex << idx << "/" << (int)subidx;
+  // cout << ", val=0x" << val << endl;
     switch (idx)
     {
@@ -127,4 +129,5 @@
 void Macs::HandleSDOOK(WORD_t idx, BYTE_t subidx, timeval_t *tv)
 {
+//    cout << "Node #" << dec << (int)GetId() << ": Sdo=" << hex << idx  << "/" << (int)subidx << " set." << endl;
     switch (idx)
     {
@@ -201,5 +204,4 @@
 }
 
-
 void Macs::ReqVelRes()
 {
@@ -243,4 +245,6 @@
         SetZombie();
     }
+    if (IsZombieNode())
+        return;
 
     StopHostGuarding();
@@ -252,9 +256,6 @@
     RequestSDO(0x100a);
     WaitForSdo(0x100a);
-    if (IsZombieNode())
-        return;
-
     // FIXME! Not statically linked!
-    if (fSoftVersion<0x00000042) // 00.66
+    if (fSoftVersion<0x00000044) // 00.68
     {
         lout << GetNodeName() << " - Software Version too old!" << endl;
@@ -272,10 +273,4 @@
     WaitForSdo(0x3000);
 
-//    SetHome(250000);
-
-//    lout << "- Requesting SDO 0x2001 of " << (int)GetId() << endl;
-//    RequestSDO(0x2001);
-//    WaitForSdo(0x2001);
-
     SetPDO1On(FALSE); // this is a workaround for the Macs
     SetPDO1On(TRUE);
@@ -283,6 +278,6 @@
     SetNoWait(TRUE);
 
-    //    StartGuarding(500, 2);
-    //    StartHostGuarding();
+//    StartGuarding(250, 4);
+//    StartHostGuarding();
 }
 
@@ -301,4 +296,7 @@
 
     SetNoWait(FALSE);
+
+    StopHostGuarding();
+    StopGuarding();
 
     //
@@ -506,4 +504,10 @@
     switch (errnum)
     {
+    case 3:
+        lout << "Axis does not existing." << endl;
+        return;
+    case 5:
+        lout << "Error not cleared (while trying to move axis)" << endl;
+        return;
     case 6:
         //
@@ -515,13 +519,14 @@
         SetError(0);
         return;
-
     case 8:
         lout << "Control deviation overflow." << endl;
         return;
-
     case 9:
         lout << "Zero index not found." << endl;
         return;
-
+    case 10:
+        lout << "Unknown command, syntax error." << endl;
+        lout << "Please recompile and reload program." << endl;
+        return;
     case 11:
     case 25:
@@ -540,18 +545,60 @@
         {
         case 11:
-            lout << " software endswitch activated." << endl;
+            lout << " software";
             break;
         case 25:
-            lout << " hardware endswitch activated." << endl;
+            lout << " hardware";
             break;
         }
-        return;
-
+        lout << " endswitch activated." << endl;
+        return;
+    case 12:
+        lout << "Wrong parameter number used in SET command." << endl;
+        return;
+    case 14:
+        lout << " 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;
+        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;
+        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;
+        return;
+    case 19:
+        lout << "User break (autostart program stopped by user)" << endl;
+        return;
+    case 51:
+        lout << "Too many (>=10) GOSUB calls." << endl;
+        return;
+    case 52:
+        lout << "Too many RETURN calls." << endl;
+        return;
+    case 62:
+        lout << "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;
+        return;
     case 71:
         lout << "Array out of bound." << endl;
         return;
-
+    case 79:
+        lout << "Timeout waiting for index (WAITNDX)." << endl;
+        return;
     case 84:
         lout << "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;
+        return;
+    case 89:
+        lout << "CAN I/O error (REOPEN=" << dec << errinf << " " << (errinf==0?"OK":"ERR") << ")" << endl;
         return;
 
Index: trunk/MagicSoft/Cosy/gui/MGStarguider.cc
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGStarguider.cc	(revision 1958)
+++ trunk/MagicSoft/Cosy/gui/MGStarguider.cc	(revision 1959)
@@ -56,4 +56,5 @@
     IDM_kPNG,
     IDM_kOnce,
+    IDM_kStretch,
     IDM_kUseFileRaDec,
     IDM_kContinous,
@@ -204,5 +205,7 @@
     fDisplay->AddEntry("Sao &Catalog", IDM_kCatalog);
     fDisplay->AddEntry("Starguider",   IDM_kStarguider);
+    fDisplay->AddEntry("Stretch",      IDM_kStretch);
     fDisplay->DisableEntry(IDM_kStarguider);
+    fDisplay->CheckEntry(IDM_kStretch);
     fDisplay->Associate(this);
     fList->Add(fDisplay);
@@ -637,4 +640,5 @@
             case IDM_kStarguider:
                 Toggle(fDisplay, IDM_kStarguider);
+                gSystem->Unlink("tracking_error.txt");
                 return kTRUE;
 
@@ -648,4 +652,8 @@
                     fDisplay->DisableEntry(IDM_kStarguider);
                 }
+                return kTRUE;
+
+            case IDM_kStretch:
+                Toggle(fDisplay, IDM_kStretch);
                 return kTRUE;
 
@@ -928,5 +936,5 @@
     pos1 -= pos0;
 
-    ofstream fout2("tracking_error.txt");
+    ofstream fout2("tracking_error.txt", ios::app);
     fout2 << setprecision(10) << fSao->GetMjd()-52000 << " " << -pos1.Alt() << " " << pos1.Az() << endl;
 
@@ -1017,9 +1025,12 @@
         return;
 
-    cout << "Img: " << n << endl;
+    //cout << "Img: " << n << endl;
 
     byte c[768*576];
     for (int i=0; i<768*576; i++)
         c[i] = (byte)(myimg[i]/fIntRate+.5);
+
+    if (fDisplay->IsEntryChecked(IDM_kStretch))
+        Filter::Stretch(c);
 
     if (!fWritePictures->IsEntryEnabled(IDM_kStart) &&
Index: trunk/MagicSoft/Cosy/videodev/Filter.cc
===================================================================
--- trunk/MagicSoft/Cosy/videodev/Filter.cc	(revision 1958)
+++ trunk/MagicSoft/Cosy/videodev/Filter.cc	(revision 1959)
@@ -203,2 +203,18 @@
 }
 
+void Filter::Stretch(byte *img)
+{
+    const int offset = 10;
+
+    int max;
+    int min;
+
+    /*const float mean =*/Mean(img, offset, &min, &max);
+
+    for (int x=0; x<768; x++)
+        for (int y=0; y<576; y++)
+        {
+            img[y*768+x] -= min;
+            img[y*768+x] *= 255/(max-min);
+        }
+}
Index: trunk/MagicSoft/Cosy/videodev/Filter.h
===================================================================
--- trunk/MagicSoft/Cosy/videodev/Filter.h	(revision 1958)
+++ trunk/MagicSoft/Cosy/videodev/Filter.h	(revision 1959)
@@ -29,4 +29,5 @@
 public:
     static void Execute(byte *img);
+    static void Stretch(byte *img);
 
     ClassDef(Filter, 0)
