Index: trunk/MagicSoft/Cosy/Changelog
===================================================================
--- trunk/MagicSoft/Cosy/Changelog	(revision 8861)
+++ trunk/MagicSoft/Cosy/Changelog	(revision 8862)
@@ -1,3 +1,50 @@
                                                                   -*-*- END -*-*-
+
+ 2008/02/13 Thomas Bretz (La Palma)
+
+   * cosy.cc:
+     - added debug-env command line options
+     - added config command line option
+     - added command line options for the ip-addresses
+     - read in an MEnv
+
+   * candrv/canopen.cc:
+     - commented an obsolete output
+
+   * candrv/ethernet.[h,cc]:
+     - changed some cout to gLog stream
+     - impoved output
+     - added some some DEBUG precompiler ifs
+
+   * candrv/interface.cc:
+     - fixed an if: fReceiver instead of !fReceiver
+
+   * candrv/network.cc:
+     - fixed some problems with hex/dec output
+
+   * devdrv/shaftencoder.[h,cc]:
+     - decode all bytes in PDO2
+     - devide by fTicks instead of a fixed number
+     - improved some comments
+
+   * main/MCosy.[h,cc]:
+     - removed the arbitrary offset in GetSePos
+       (FIXME: This needs to become an option in the rc-file)
+     - take an MEnv instead of a local TEnv
+     - improved output
+     - get name for pointing model as argument
+
+   * tcpip/MCeCoCom.h, tcpip/MDriveCom.h:
+     - get ip-address as argument
+
+   * tcpip/MTcpIpIO.[h,cc]:
+     - added GetSocketAddress functions
+     - changed some cout to gLog
+     - improved output
+
+   * videodev/MVideo.[h,cc]:
+     - added an argument to Ioctl to suppress an expected error
+
+
 
  2008/02/12 Thomas Bretz (La Palma)
Index: trunk/MagicSoft/Cosy/candrv/canopen.cc
===================================================================
--- trunk/MagicSoft/Cosy/candrv/canopen.cc	(revision 8861)
+++ trunk/MagicSoft/Cosy/candrv/canopen.cc	(revision 8862)
@@ -88,6 +88,6 @@
 // In case of a PDO the conditional semaphore corresponding to this PDO
 // is raised (WaitForNextPDO)
-//  HandleSDO:       handles a SDO message
-//  HandlePDO1/2/3/4:handles received PDOs
+//  HandleSDO:        handles a SDO message
+//  HandlePDO1/2/3/4: handles received PDOs
 //
 void CanOpen::HandleCanMessage(WORD_t cobid, const BYTE_t *data, const timeval_t &tv)
@@ -127,5 +127,5 @@
             const WORD_t  subidx = data[3];
 
-            cout << "SND NODE: " << (int)node << " " << flush;
+            //cout << "SDO_rx: node=" << (int)node << hex << " cmd=0x" << (int)cmd << " idx=0x" << idx << " subidx=0x" << subidx << dec << endl;
             HandleSDO(node, cmd, idx, subidx, dat, tv);
 
Index: trunk/MagicSoft/Cosy/candrv/ethernet.cc
===================================================================
--- trunk/MagicSoft/Cosy/candrv/ethernet.cc	(revision 8861)
+++ trunk/MagicSoft/Cosy/candrv/ethernet.cc	(revision 8862)
@@ -39,4 +39,6 @@
 ClassImp(Ethernet);
 
+#undef DEBUG
+
 using namespace std;
 
@@ -54,5 +56,5 @@
 //
 Ethernet::Ethernet(const char *addr, const int tx, const int rx, CanOpen *receiver)
-    : MTcpIpI(rx), Interface(receiver), fTxAddress(addr), fTxPort(tx)
+    : MTcpIpI(rx),/* MTcpIpO(addr, tx),*/ Interface(receiver), fTxAddress(addr), fTxPort(tx)
 {
     gLog << inf2 << "- Ethernet initialized." << endl;
@@ -81,4 +83,6 @@
     msg.data[1] = 0;
 
+    const TString address = MTcpIpO::GetSocketAddress(rx);
+
     while (!IsThreadCanceled())
     {
@@ -100,7 +104,6 @@
         if (len==0)
         {
-            // THIS MEANS CONNECTIION LOST!!!!
-            cout << "============> LEN==0 (CONNECTION LOST?)" << endl;
-            break; // This break is for TEST PURPOSE FIXME!!!
+            gLog << warn << "WARNING - Connection lost (received 0bytes) to " << address << endl;
+            //break; // This break is for TEST PURPOSE FIXME!!!
             continue;
         }
@@ -109,5 +112,5 @@
         if (len>1)
         {
-            cout << "Data too long!!!" << endl;
+            gLog << err << "Data received from " << address << " is more than one byte!" << endl;
             break;
         }
@@ -117,5 +120,5 @@
             if (c>=MSGLEN)
             {
-                cout << "Received data too long (> " << MSGLEN << ")" << endl;
+                cout << "Data received from " << address << " too long (> " << MSGLEN << ")" << endl;
                 break;
             }
@@ -133,8 +136,10 @@
             continue;
 
+#ifdef DEBUG
         cout << "*** RcvdCanFrame len=" << dec << msg.len << ": ";
         for (int i=0; i<msg.len; i++)
             cout << "0x" << setfill('0') << setw(2) << hex << (int)((msg.data+2)[i]) << " ";
-        cout << endl;
+        cout << dec << endl;
+#endif
 
         pos = -1;
@@ -192,9 +197,12 @@
     */
 
+#ifdef DEBUG
     // FIXME: MUST BECOME NON-BLOCKING!!!!!
-    cout << "*** Send CanFrame over IP" << endl;
+    cout << "*** Send CanFrame over IP " << endl;
     // FIXME: MUST BECOME NON-BLOCKING!!!!!
+#endif
 
     MTcpIpO::SendFrame(fTxAddress, fTxPort, (char*)(msg.data+1), msg.len-1);
+    //Send((char*)(msg.data+1), msg.len-1);
 
     /*
Index: trunk/MagicSoft/Cosy/candrv/ethernet.h
===================================================================
--- trunk/MagicSoft/Cosy/candrv/ethernet.h	(revision 8861)
+++ trunk/MagicSoft/Cosy/candrv/ethernet.h	(revision 8862)
@@ -10,5 +10,5 @@
 #endif
 
-class Ethernet : public MTcpIpI, public Interface
+class Ethernet : public MTcpIpI, /*public MTcpIpO,*/ public Interface
 {
 private:
Index: trunk/MagicSoft/Cosy/candrv/interface.cc
===================================================================
--- trunk/MagicSoft/Cosy/candrv/interface.cc	(revision 8861)
+++ trunk/MagicSoft/Cosy/candrv/interface.cc	(revision 8862)
@@ -56,5 +56,5 @@
 void Interface::HandleMessage(const Message &msg) const
 {
-    if (fReceiver)
+    if (!fReceiver)
         return;
 
Index: trunk/MagicSoft/Cosy/candrv/network.cc
===================================================================
--- trunk/MagicSoft/Cosy/candrv/network.cc	(revision 8861)
+++ trunk/MagicSoft/Cosy/candrv/network.cc	(revision 8862)
@@ -132,5 +132,5 @@
         for (int i=0; i<8; i++)
             gLog << " 0x" << (int)data[i];
-        gLog << endl;
+        gLog << dec << endl;
         return;
     }
@@ -150,5 +150,5 @@
         for (int i=0; i<8; i++)
             gLog << " 0x" << (int)data[i];
-        gLog << endl;
+        gLog << dec << endl;
         return;
     }
@@ -168,5 +168,5 @@
         for (int i=0; i<8; i++)
             gLog << " 0x" << (int)data[i];
-        gLog << endl;
+        gLog << dec << endl;
         return;
     }
@@ -186,5 +186,5 @@
         for (int i=0; i<8; i++)
             gLog << " 0x" << (int)data[i];
-        gLog << endl;
+        gLog << dec << endl;
         return;
     }
Index: trunk/MagicSoft/Cosy/cosy.cc
===================================================================
--- trunk/MagicSoft/Cosy/cosy.cc	(revision 8861)
+++ trunk/MagicSoft/Cosy/cosy.cc	(revision 8862)
@@ -10,4 +10,5 @@
 #include "vmodican.h"
 
+#include "MEnv.h"
 #include "MArgs.h"
 #include "MCosy.h"
@@ -50,5 +51,11 @@
     gLog << " Options:" << endl;
     gLog.Usage();
+    gLog << "   --debug-env=0             Disable debugging setting resources <default>" << endl;
+    gLog << "   --debug-env[=1]           Display untouched resources after program execution" << endl;
+    gLog << "   --debug-env=2             Display untouched resources after eventloop setup" << endl;
+    gLog << "   --debug-env=3             Debug setting resources from resource file and command line" << endl;
+    gLog << "   --debug-mem               Debug memory usage" << endl << endl;
     gLog << "   --debug-threads           Debug threads" << endl << endl;
+    gLog << "   --rc=Name:option          Set or overwrite a resource of the resource file." << endl << endl;
     gLog << "   --version, -V             Show startup message with version number" << endl;
     gLog << "   -?, -h, --help            This help" << endl << endl;
@@ -80,7 +87,13 @@
     }
 
-    const Int_t  channel       = arg.GetIntAndRemove("--channel=", 0);
-    const Bool_t kDebugMem     = arg.HasOnlyAndRemove("--debug-mem");
-    const Bool_t kDebugThreads = arg.HasOnlyAndRemove("--debug-threads");
+    const Int_t   channel       = arg.GetIntAndRemove("--channel=", 0);
+    const Bool_t  kDebugMem     = arg.HasOnlyAndRemove("--debug-mem");
+    const Bool_t  kDebugThreads = arg.HasOnlyAndRemove("--debug-threads");
+    const TString sps           = arg.GetStringAndRemove("--sps=", "127.0.0.1");
+    const TString ceco          = arg.GetStringAndRemove("--cc=", "ceco"); // ceco
+    const TString pointing      = arg.GetStringAndRemove("--pointing-model=", "bending2.txt"); // ceco
+    const TString kConfig       = arg.GetStringAndRemove("--config=", ".cosyrc"); // ceco
+    Int_t  kDebugEnv = arg.HasOnlyAndRemove("--debug-env") ? 1 : 0;
+    kDebugEnv = arg.GetIntAndRemove("--debug-env=", kDebugEnv);
 
     //
@@ -93,5 +106,5 @@
         return 2;
     }
-/*
+
     //
     // Now we access/read the resource file. This will remove all
@@ -108,5 +121,5 @@
     if (!env.TakeEnv(arg, kDebugEnv>2))
         return 0xfd;
-*/
+
     //
     // check for the right usage of the program (number of options)
@@ -178,12 +191,17 @@
         }
 */
-    MCosy *cosy = new MCosy();
-
-    Interface *interface = new Ethernet("127.0.0.1", 5357, 5358, cosy);
+    MCosy *cosy = new MCosy(env, ceco, pointing);
+
+    Interface *interface = new Ethernet(sps, 5357, 5358, cosy);
     // Interface *interface = new VmodIcan(cosy, "/dev/dpm_00", 125);
 
     gLog << all << "- Starting MCosy." << endl;
 
-    cosy->Start();
+    cosy->Start(env);
+
+    // FIXME: Is this the right position?
+    if (kDebugEnv>0)
+        env.PrintUntouched();
+
 
     MStarguider *client=0;
Index: trunk/MagicSoft/Cosy/devdrv/shaftencoder.cc
===================================================================
--- trunk/MagicSoft/Cosy/devdrv/shaftencoder.cc	(revision 8861)
+++ trunk/MagicSoft/Cosy/devdrv/shaftencoder.cc	(revision 8862)
@@ -278,5 +278,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);
 
     fVel = data[4] | (data[5]<<8);
@@ -465,6 +465,6 @@
         return;
 
-    fPos  = pre%16384;
-    fTurn = pre/16384;
+    fPos  = pre%fTicks;
+    fTurn = pre/fTicks;
     fDirChangedPos = fPos;
     fOffset = fMotor ? fMotor->GetPdoPos() : 0;
Index: trunk/MagicSoft/Cosy/devdrv/shaftencoder.h
===================================================================
--- trunk/MagicSoft/Cosy/devdrv/shaftencoder.h	(revision 8861)
+++ trunk/MagicSoft/Cosy/devdrv/shaftencoder.h	(revision 8862)
@@ -22,5 +22,5 @@
     WORDS_t  fAcc;   // ticks per 25ms^2
     WORDS_t  fTurn;  // Number of turn
-    LWORD_t  fTicks; // Number of ticks per turn
+    LWORD_t  fTicks; // Number of ticks per revolution (resolution)
     WORD_t   fTurns; // Number of possible turns
 
Index: trunk/MagicSoft/Cosy/main/MCosy.cc
===================================================================
--- trunk/MagicSoft/Cosy/main/MCosy.cc	(revision 8861)
+++ trunk/MagicSoft/Cosy/main/MCosy.cc	(revision 8862)
@@ -16,4 +16,5 @@
 #include "MLogManip.h"
 
+#include "MEnv.h"
 #include "MTime.h"
 #include "MPointing.h"
@@ -140,8 +141,8 @@
 
     //
-    // Get the values
-    //
-    int p1 =  (fZd1->GetPos()+8192)%16384;
-    int p2 = -(fZd2->GetPos()+8192)%16384;
+    // Get the values          (FIXME!)
+    //
+    int p1 =  (fZd1->GetPos()/*+8192*/)%fZd1->GetPhysRes();
+    int p2 = -(fZd2->GetPos()/*+8192*/)%fZd2->GetPhysRes();
 
     if (fZd1->IsZombieNode())
@@ -930,10 +931,6 @@
 }
 
-void MCosy::ReadConfig()
-{
-    gLog << inf2 << "Reading configuration file..." << flush;
-    TEnv env(".cosyrc");
-    gLog << "done." << endl;
-
+void MCosy::ReadConfig(MEnv &env)
+{
     gLog << inf2 << "Reading telescope range..." << flush;
     const Double_t amin = env.GetValue("Az_Min[deg]", -95.0);
@@ -946,16 +943,15 @@
     gLog << "done." << endl;
 
-    gLog << all << " * Min:  " << zmin << "deg  " << amin << "deg" << endl;
-    gLog << all << " * Max:  " << zmax << "deg  " << amax << "deg" << endl;
+    gLog << all << flush;
+
+    gLog << " * Min:  " << zmin << "deg  " << amin << "deg" << endl;
+    gLog << " * Max:  " << zmax << "deg  " << amax << "deg" << endl;
 
     fMin = fBending.AddOffsets(fMin/TMath::RadToDeg());
     fMax = fBending.AddOffsets(fMax/TMath::RadToDeg());
 
-    gLog << all << " * Min': " << fMin.Zd()*TMath::RadToDeg() << "deg  " << fMin.Az()*TMath::RadToDeg() << "deg" << endl;
-    gLog << all << " * Max': " << fMax.Zd()*TMath::RadToDeg() << "deg  " << fMax.Az()*TMath::RadToDeg() << "deg" << endl;
-
-    gLog << inf2 << "Reading gear ratios..." << flush;
-//    kGear.X(env.GetValue("Zd_GearRatio[U_mot/U_tel]", 1000.0));
-//    kGear.Y(env.GetValue("Az_GearRatio[U_mot/U_tel]", 1000.0));
+    gLog << " * Min': " << fMin.Zd()*TMath::RadToDeg() << "deg  " << fMin.Az()*TMath::RadToDeg() << "deg" << endl;
+    gLog << " * Max': " << fMax.Zd()*TMath::RadToDeg() << "deg  " << fMax.Az()*TMath::RadToDeg() << "deg" << endl;
+
     kGear.Set(env.GetValue("Zd_GearRatio[U_mot/U_tel]", 1000.0),
               env.GetValue("Az_GearRatio[U_mot/U_tel]", 1000.0));
@@ -975,7 +971,13 @@
     kResRE.Set(x,y);
 
-    x = zd1 ? fZd1->GetPhysRes() : (zd2 ? fZd2->GetPhysRes() : env.GetValue("Zd_ResSE[se/U_mot]", 16384));
-    y = az  ? fAz->GetPhysRes() : env.GetValue("Az_ResSE[se/U_mot]", 16384);
+    gLog << " * Az RE resolution: " << x << " re/U_mot" << endl;
+    gLog << " * Zd RE resolution: " << y << " re/U_mot" << endl;
+
+    x = zd1 ? fZd1->GetPhysRes() : (zd2 ? fZd2->GetPhysRes() : env.GetValue("Zd_ResSE[se/U_tel]", 16384));
+    y = az  ? fAz->GetPhysRes() : env.GetValue("Az_ResSE[se/U_tel]", 16384);
     kResSE.Set(x,y);
+
+    gLog << " * Az SE resolution: " << x << " se/U_tel" << endl;
+    gLog << " * Zd SE resolution: " << y << " se/U_tel" << endl;
 
     /*
@@ -1019,9 +1021,7 @@
 //    kGearTot = kResRE*kGear;
 
-    gLog << "done." << endl;
-
-    gLog << all;
-    gLog << " * Setting Gear Ratios:" << endl;
-    gLog << "   --------------------" << endl;
+//    gLog << all;
+//    gLog << " * Setting Gear Ratios:" << endl;
+ //   gLog << "   --------------------" << endl;
     gLog << " *  X: " << kGear.X() << "*" << kResRE.X()/4 << "/" << kResSE.X() << "=4*" << kGearTot.X() << "/" << kResSE.X() << endl;
     gLog << " *  Y: " << kGear.Y() << "*" << kResRE.Y()/4 << "/" << kResSE.Y() << "=4*" << kGearTot.Y() << "/" << kResSE.Y() << endl;
@@ -1065,4 +1065,6 @@
 
     gLog << inf2 << "Starting Shaftencoder Test..." << endl;
+
+    gLog << err << "Build in values!!!" << endl;
 
     while (fBackground==kBgdSeTest)
@@ -1434,5 +1436,5 @@
 // turn on the gui update
 //
-void MCosy::Start()
+void MCosy::Start(MEnv &env)
 {
     // Don't call this function twice!
@@ -1441,5 +1443,5 @@
     CheckForError();
 
-    ReadConfig();
+    ReadConfig(env);
 
     gLog << inf << "- Starting TX Thread." << endl;
@@ -1610,5 +1612,5 @@
 }
 
-MCosy::MCosy()
+MCosy::MCosy(MEnv &env, const char *addr, const char *pointing)
 : Network(), fObservatory(MObservatory::kMagic1), fStarguider(NULL),
 fZd1(0), fZd2(0), fAz(0), fMac1(0), fMac2(0), fMac3(0),
@@ -1616,5 +1618,4 @@
 fOutTp(0), fOutRep(0)
 {
-    TEnv env(".cosyrc");
     const Int_t id1 = env.GetValue("Az_Id-MAC1", 1); //1
     const Int_t id2 = env.GetValue("Az_Id-MAC2", 2); //2
@@ -1637,6 +1638,10 @@
     {
     case 0:
-        gLog << "<<Standard mode>>" << endl;*/
-        fBending.Load("bending.txt");
+    gLog << "<<Standard mode>>" << endl;*/
+        gLog << all << "Reading pointing model from " << pointing << "..." << endl;
+        if (fBending.Load(pointing))
+            gLog << all << "Reading pointing model from " << pointing << " successfull." << endl;
+        else
+            gLog << err << "ERROR - Reading pointing model from " << pointing << endl;
         Constructor(id1, id2, id3, id4, id5, id6);/*
         break;
@@ -1651,4 +1656,5 @@
     }
 */
+
     gLog.SetOutputGui(fWin->GetLog(), kTRUE);
 
@@ -1657,5 +1663,5 @@
     fAz->SetDisplay(fWin->GetLabel1());
 
-    fCom = new MDriveCom(this, fOutRep);
+    fCom = new MDriveCom(this, addr, fOutRep);
 //    fCom->Start();
 }
Index: trunk/MagicSoft/Cosy/main/MCosy.h
===================================================================
--- trunk/MagicSoft/Cosy/main/MCosy.h	(revision 8861)
+++ trunk/MagicSoft/Cosy/main/MCosy.h	(revision 8862)
@@ -52,4 +52,5 @@
 class MStarguider;
 class MDriveCom;
+class MEnv;
 
 class MTTalk : public MThread
@@ -173,13 +174,15 @@
     //void ConstructorDemo();
 
-    void ReadConfig();
+    void ReadConfig(MEnv &env);
 
     bool CheckNetwork();
 
+    void Start() { }
+
 public:
-    MCosy();
+    MCosy(MEnv &env, const char *addr, const char *pointing);
     ~MCosy();
 
-    void Start();
+    void Start(MEnv &env);
     void Stop();
 
Index: trunk/MagicSoft/Cosy/tcpip/MCeCoCom.h
===================================================================
--- trunk/MagicSoft/Cosy/tcpip/MCeCoCom.h	(revision 8861)
+++ trunk/MagicSoft/Cosy/tcpip/MCeCoCom.h	(revision 8862)
@@ -48,6 +48,6 @@
 
 public:
-    MCeCoCom(MLog *out)
-        : MTcpIpIO("ceco", 7304, 7404), fOut(out), fStatus(0), fComStat(kNoCmdReceived),
+    MCeCoCom(const char *addr, MLog *out)
+        : MTcpIpIO(addr, 7304, 7404), fOut(out), fStatus(0), fComStat(kNoCmdReceived),
         fHumidity(0), fTemperature(0), fWindSpeed(0), fSolarRadiation(-1),
         fAlarmCounter(0)
Index: trunk/MagicSoft/Cosy/tcpip/MDriveCom.h
===================================================================
--- trunk/MagicSoft/Cosy/tcpip/MDriveCom.h	(revision 8861)
+++ trunk/MagicSoft/Cosy/tcpip/MDriveCom.h	(revision 8862)
@@ -41,5 +41,5 @@
     };
 
-    MDriveCom(MsgQueue *q, MLog *out) : MCeCoCom(out), fQueue(q) {}
+    MDriveCom(MsgQueue *q, const char *addr, MLog *out) : MCeCoCom(addr, out), fQueue(q) {}
 
     bool SendReport(UInt_t stat, RaDec rd, ZdAz so, ZdAz is, ZdAz er);
Index: trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.cc
===================================================================
--- trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.cc	(revision 8861)
+++ trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.cc	(revision 8862)
@@ -8,4 +8,6 @@
 #include "MLog.h"
 #include "MLogManip.h"
+
+#include "MString.h"
 
 #undef DEBUG
@@ -55,9 +57,26 @@
 }
 
+TString MTcpIpO::GetSocketAddress(const TSocket &s)
+{
+    if (!s.IsValid())
+        return "n/a";
+
+    const TInetAddress &a = s.GetInetAddress();
+    if (!a.IsValid())
+        return "undefined";
+
+    return MString::Format("%s:%d", a.GetHostAddress(), a.GetPort());
+}
+
+TString MTcpIpO::GetSocketAddress() const
+{
+    return GetSocketAddress(*fTxSocket);
+}
+
 bool MTcpIpO::SendFrame(TSocket &tx, const char *msg, int len)
 {
     if (!tx.IsValid())
     {
-        //cout << "*!* Transmit socket invalid!" << endl;
+        //gLog << warn << "WARNING - No transmission to " << GetSocketAddress(tx) << " possible." << endl;
         return false;
     }
@@ -66,5 +85,5 @@
     if (l<0)
     {
-        cout << "ERROR - Sending Message" << endl;
+        gLog << err << "ERROR - Sending TCP/IP frame to " << GetSocketAddress(tx) << endl;
         return false;
     }
@@ -72,5 +91,5 @@
     if (l!=len)
     {
-        cout << "Send wrong number (" << l << ") of Bytes." << endl;
+        gLog << err << "ERROR - Sent wrong number (" << l << ") of bytes to " << GetSocketAddress(tx) << endl;
         return false;
     }
@@ -86,23 +105,24 @@
 {
     //    R__LOCKGUARD2(myMutex);
-
+#ifdef DEBUG
     cout << "Connecting to " << addr << ":" << port << endl;
+#endif
 
     // FIXME: Set tx-socket to nonblocking?
     TSocket tx(addr, port);
-    //    return SendFrame(tx, msg, len);
-
+    return SendFrame(tx, msg, len);
+/*
     if (!tx.IsValid())
     {
-        //cout << "*!* Transmit socket invalid!" << endl;
-        return false;
-    }
-
-    cout << "Sending to " << addr << ":" << port << endl;
+        gLog << warn << "WARNING - No transmission to " << addr << ":" << port << " possible." << endl;
+        return false;
+    }
+
+    gLog << dbg << "Sending to " << addr << ":" << port << endl;
 
     const Int_t l = tx.SendRaw(msg, len, kDontBlock);
     if (l<0)
     {
-        cout << "ERROR - Sending Message" << endl;
+        gLog << err << "ERROR - Sending TCP/IP frame to " << addr << ":" << port << endl;
         return false;
     }
@@ -110,5 +130,5 @@
     if (l!=len)
     {
-        cout << "Send wrong number (" << l << ") of Bytes." << endl;
+        gLog << err << "ERROR - Sent wrong number (" << l << ") of bytes to " << addr << ":" << port << endl;
         return false;
     }
@@ -119,4 +139,5 @@
 
     return true;
+    */
 }
 
@@ -188,4 +209,10 @@
     gLog << inf << "- Starting receiver on port " << fPortRx << "..." << endl;
 
+//    if (fPortRx==7404)
+//    {
+//        gLog << err << "CeCo communication skipped." << endl;
+//        return 0;
+//    }
+
     TServerSocket *fServSock=NULL;
     TSocket       *fRxSocket=NULL;
@@ -197,12 +224,12 @@
         if (!fServSock->IsValid())
         {
-            cout << "ServerSocket on port " << fPortRx << " invalid: ";
+            gLog << err << "ServerSocket on port " << fPortRx << " invalid: ";
             switch (fServSock->GetErrorCode())
             {
-            case  0: cout << "No error." << endl; break;
-            case -1: cout << "low level socket() call failed." << endl; break;
-            case -2: cout << "low level bind() call failed." << endl; break;
-            case -3: cout << "low level listen() call failed." << endl; break;
-            default: cout << "Unknown." << endl; break;
+            case  0: gLog << "No error." << endl; break;
+            case -1: gLog << "low level socket() call failed." << endl; break;
+            case -2: gLog << "low level bind() call failed." << endl; break;
+            case -3: gLog << "low level listen() call failed." << endl; break;
+            default: gLog << "Unknown." << endl; break;
             }
             delete fServSock;
@@ -214,5 +241,5 @@
         fServSock->SetOption(kNoBlock, 1);
 
-        cout << "Waiting for connection on port " << fPortRx << "..." << endl;
+        gLog << all << "Waiting for connection on port " << fPortRx << "..." << endl;
 //        while (!HasStopFlag() && (Long_t)fRxSocket<=0)
         while (!IsThreadCanceled() && (Long_t)fRxSocket<=0)
@@ -247,5 +274,5 @@
         }
 
-        cout << "Connection established on port " << fPortRx << "." << endl;
+        gLog << all << "Connection established on port " << fPortRx << "." << endl;
 
         fRxSocket->SetOption(kNoBlock, 1);
Index: trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.h
===================================================================
--- trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.h	(revision 8861)
+++ trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.h	(revision 8862)
@@ -40,8 +40,10 @@
     ~MTcpIpO();
 
-    static bool SendFrame(TSocket &tx, const char *msg, int len);
-    static bool SendFrame(const char *addr, int port, const char *msg, int len);
+    static TString GetSocketAddress(const TSocket &s);
+    static bool    SendFrame(TSocket &tx, const char *msg, int len);
+    static bool    SendFrame(const char *addr, int port, const char *msg, int len);
 
-    bool Send(const char *msg, int len);
+    TString GetSocketAddress() const;
+    bool    Send(const char *msg, int len);
 };
 
Index: trunk/MagicSoft/Cosy/videodev/MVideo.cc
===================================================================
--- trunk/MagicSoft/Cosy/videodev/MVideo.cc	(revision 8861)
+++ trunk/MagicSoft/Cosy/videodev/MVideo.cc	(revision 8862)
@@ -101,5 +101,5 @@
 // Mapper around ioctl for easier access to the device
 //
-int MVideo::Ioctl(int req, void *opt, bool allowirq) const
+int MVideo::Ioctl(int req, void *opt, bool allowirq, bool force) const
 {
     if (fFileDesc<0)
@@ -129,6 +129,9 @@
         }
 
-        gLog << err << "ERROR - MVideo::Ioctl 0x" << hex << req << ": errno=" << dec << errno << " - ";
-        gLog << strerror(errno) << " (rc=" << rc << ")" << endl;
+        if (!force)
+        {
+            gLog << err << "ERROR - MVideo::Ioctl 0x" << hex << req << ": errno=" << dec << errno << " - ";
+            gLog << strerror(errno) << " (rc=" << rc << ")" << endl;
+        }
         return rc;
     }
@@ -186,5 +189,5 @@
     while (1)
     {
-        if (Ioctl (VIDIOC_QUERYCTRL, &qctrl)==-1)
+        if (Ioctl(VIDIOC_QUERYCTRL, &qctrl, true, true)==-1)
             break;
 
@@ -769,5 +772,5 @@
 void MVideo::Print() const
 {
-    gLog << all;
+    gLog << all << dec;
 
     gLog << "Device " << fPath << " " << (IsOpen()?"open":"closed") << "." << endl;
@@ -818,5 +821,5 @@
     gLog  << dec << endl;
 
-    gLog << "Controls:" << endl;
+    gLog << inf2 << "Controls:" << endl;
     fControls.Print();
 }
Index: trunk/MagicSoft/Cosy/videodev/MVideo.h
===================================================================
--- trunk/MagicSoft/Cosy/videodev/MVideo.h	(revision 8861)
+++ trunk/MagicSoft/Cosy/videodev/MVideo.h	(revision 8862)
@@ -62,5 +62,5 @@
 
 private:
-    int Ioctl(int req, void *opt, bool allowirq=true) const;
+    int Ioctl(int req, void *opt, bool allowirq=true, bool force=false) const;
 
     void Reset();
