Index: /trunk/MagicSoft/Cosy/Changelog
===================================================================
--- /trunk/MagicSoft/Cosy/Changelog	(revision 8869)
+++ /trunk/MagicSoft/Cosy/Changelog	(revision 8870)
@@ -1,3 +1,14 @@
                                                                   -*-*- END -*-*-
+
+ 2008/02/22 Thomas Bretz (La Palma)
+
+   * aposs/Magic.m:
+     - added a trigger on the falling and rising edge of the door-lock
+       switch which will stop the telescope and refuse any movement 
+       command
+     - changed version number from 0.69 to 0.70
+     - move the arbitrary factor 4 from cosy to aposs
+
+
 
  2008/02/21 Thomas Bretz (La Palma)
Index: /trunk/MagicSoft/Cosy/aposs/Magic.m
===================================================================
--- /trunk/MagicSoft/Cosy/aposs/Magic.m	(revision 8869)
+++ /trunk/MagicSoft/Cosy/aposs/Magic.m	(revision 8870)
@@ -10,7 +10,13 @@
 /*                                                                         */
 kVERSION    = 0   /*                                                       */
-kSUBVERSION = 69  /*                                                       */
+kSUBVERSION = 70  /*                                                       */
 /*                                                                         */
 /*  HISTORY:                                                               */
+/*                                                                         */
+/*   * V0.70:                                                              */
+/*       - Implemented switch off of motor in case of Input 6 has a        */
+/*         falling edge                                                    */
+/*       - moved the arbitrary factor 4 for the tracking speed from        */
+/*         cosy to here                                                    */
 /*                                                                         */
 /*   * V0.69:                                                              */
@@ -323,4 +329,7 @@
 kIoModule = 4*256                    
 
+ON INT -(kIoModule+6) GOSUB DOOR_STATUS_CHANGED
+ON INT  (kIoModule+6) GOSUB DOOR_STATUS_CHANGED
+
 /*-------------------------------------------------------------------------*/
 /* Init                                                                    */
@@ -337,5 +346,5 @@
    canlo = 1
 
-	 brake = 0
+   brake = 0
    RF    = 0     
    
@@ -354,8 +363,16 @@
          emcy  = in (kIoModule+2)
          vltg  = in (kIoModule+3)
-         mode  = in (kIoModule+4)   
+         mode  = in (kIoModule+4)
+         door  = in (kIoModule+6)
          ready = in 1
 
-         if (ready==0) and (RF==1) then
+         if (door==0) then
+            preop = kTRUE
+         endif
+
+         if (preop==kTRUE) then
+            print "Door open!"
+            gosub reset
+         elseif (ready==0) and (RF==1) then
             print "DKC not ready, but RF set... setting RF=AH=0!"
             gosub reset
@@ -465,6 +482,14 @@
       PRINT "Setting Idx:", idx, "/", subidx, " to ", sdoval
 */
-      if (idx==0x1000 and subidx==1 and sdoval==1) then
-         preop = kFALSE
+      if (idx==0x1000 and subidx==1) then
+         if (sdoval==1) then
+            if (door==0) then
+               canlo = 1
+            else
+               preop = kFALSE
+            endif
+         elseif
+            preop = kTRUE
+         endif
       elseif (idx==0x1003 and subidx==0 and sdoval==0) then
          i = 9
@@ -558,5 +583,6 @@
             endif
          elseif (subidx == 1) then
-            CVEL sdoval
+            /* It is unclear where this arbitraty factor comes from */
+            CVEL sdoval/4
          endif 
       elseif (idx == 0x3007) then
@@ -696,5 +722,5 @@
          sdoval = AXEND
       elseif (idx == 0x2002) then
-         sdoval = AVEL
+         sdoval = AVEL*4
       elseif (idx == 0x2003) then
          if (subidx==0) then
@@ -784,5 +810,12 @@
 /*-------------------------------------------------------------------------*/
    SUBPROG PROC_PDO1
-      CANOUT pdo1 AXEND APOS
+      CANOUT pdo1 (AXEND|(preop<<9)) APOS
+   RETURN
+
+/*-------------------------------------------------------------------------*/
+/* FENCE OPENED                                                            */
+/*-------------------------------------------------------------------------*/
+   SUBPROG DOOR_STATUS_CHANGED
+      preop = kTRUE
    RETURN
 
Index: /trunk/MagicSoft/Cosy/devdrv/macs.cc
===================================================================
--- /trunk/MagicSoft/Cosy/devdrv/macs.cc	(revision 8869)
+++ /trunk/MagicSoft/Cosy/devdrv/macs.cc	(revision 8870)
@@ -486,5 +486,5 @@
     // FIXME! Not statically linked!
     //if (fSoftVersion<0x00000044) // 00.68
-    if (fSoftVersion<0x00000045) // 00.69
+    if (fSoftVersion<0x00000046) // 00.69
     {
         gLog << err << GetNodeName() << " - Software Version " << 0.01*fSoftVersion << " too old!" << endl;
@@ -515,5 +515,5 @@
 
     // REMOVE THIS AND LET CC START THE NODE
-    StartNode();
+    // StartNode();
 
     gLog << inf2 << "- " << GetNodeName() << ": Checking armed status." << endl;
Index: /trunk/MagicSoft/Cosy/main/MStarguider.cc
===================================================================
--- /trunk/MagicSoft/Cosy/main/MStarguider.cc	(revision 8869)
+++ /trunk/MagicSoft/Cosy/main/MStarguider.cc	(revision 8870)
@@ -616,4 +616,5 @@
     //fClient.ExitLoop();
     //    cout << "FIXME: ExitLoop not called!!!!!!" << endl;
+    fGetter->ExitLoop();
     gSystem->ExitLoop();
 }
@@ -2023,8 +2024,9 @@
             if (fCosy)
             {
-                MDriveCom &com = *fCosy->GetDriveCom();
-                com.SendStargReport(fStatus, fD, fSao->GetZdAz(),
-                                    sgcenter, numstars, rc, bright,
-                                    time.GetMjd(), 0, 0);    // Report
+                MDriveCom *com = fCosy->GetDriveCom();
+                if (com)
+                    com->SendStargReport(fStatus, fD, fSao->GetZdAz(),
+                                         sgcenter, numstars, rc, bright,
+                                         time.GetMjd(), 0, 0);    // Report
             }
 
