Changeset 8864 for trunk/MagicSoft
- Timestamp:
- 02/17/08 22:39:04 (17 years ago)
- Location:
- trunk/MagicSoft/Cosy
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Cosy/Changelog
r8863 r8864 1 1 -*-*- END -*-*- 2 3 2008/02/17 Thomas Bretz (La Palma) 4 5 * cosy.cc: 6 - enable output device file for log-files 7 - set sps default address to "sps" 8 9 * candrv/canopen.[h,cc]: 10 - added member function HasError to return an error status 11 of the network connection 12 13 * candrv/ethernet.[h,cc]: 14 - improved the way a lost connection is reestablished 15 - added HasConnection to return the connection status 16 17 * candrv/interface.h: 18 - added HasConnection to return the connection status 19 20 * candrv/network.cc: 21 - when setting zombies check also the status of the network 22 23 * candrv/nodedrv.h: 24 - made HasError a bit more fool proof 25 26 * devdrv/macs.[cc.h]: 27 - added some more DKC error codes 28 - improved printed error DKC message 29 - do not treat warnings as errors anymore 30 31 * gui/MGCosy.cc: 32 - the RA in TrackPos and CalibPos is in degrees 33 34 * main/MCosy.cc: 35 - replaced some build-in numbers for the shaftenecoder- 36 resolution by it 37 - fixed a weird error: in one case when checking for errors 38 fMac3 was checked without testing for NULL pointer! 39 40 * tcpip/MTcpIpIO.[h,cc]: 41 - imporved the whole communication stuff again, especially 42 the error handling and reestablishing of connections 43 44 2 45 3 46 2008/02/15 Thomas Bretz (La Palma) -
trunk/MagicSoft/Cosy/candrv/canopen.cc
r8862 r8864 78 78 if (fInterface) 79 79 fInterface->Stop(); 80 } 81 82 bool CanOpen::HasError() const 83 { 84 return fInterface ? !fInterface->HasConnection() : kFALSE; 80 85 } 81 86 -
trunk/MagicSoft/Cosy/candrv/canopen.h
r8813 r8864 78 78 virtual void Start(); // Start CanOpen communication 79 79 virtual void Stop(); // Stop CanOpen communcation 80 81 virtual bool HasError() const; 80 82 81 83 private: -
trunk/MagicSoft/Cosy/candrv/ethernet.cc
r8862 r8864 74 74 // -------------------------------------------------------------------------- 75 75 // 76 voidEthernet::ReadSocket(TSocket &rx)76 Bool_t Ethernet::ReadSocket(TSocket &rx) 77 77 { 78 78 Int_t pos = -1; … … 87 87 while (!IsThreadCanceled()) 88 88 { 89 //TThread::CancelPoint();90 91 89 unsigned char c; 92 90 const Int_t len = rx.RecvRaw(&c, 1); 93 91 94 //TThread::CancelPoint();95 96 92 // No data received (non-blocking mode) 97 93 if (len<0) … … 101 97 } 102 98 103 // Data received with zero length! 99 // Data received with zero length! (Connection lost) 104 100 if (len==0) 105 { 106 gLog << warn << "WARNING - Connection lost (received 0bytes) to " << address << endl; 107 //break; // This break is for TEST PURPOSE FIXME!!! 108 continue; 109 } 101 return kFALSE; 110 102 111 103 // Data received … … 113 105 { 114 106 gLog << err << "Data received from " << address << " is more than one byte!" << endl; 115 break;107 continue; 116 108 } 117 109 … … 121 113 { 122 114 cout << "Data received from " << address << " too long (> " << MSGLEN << ")" << endl; 123 break;115 continue; 124 116 } 125 117 … … 147 139 // String completed 148 140 HandleMessage(msg); 141 142 return kTRUE; 149 143 } 150 } 151 144 145 return kTRUE; 146 } 147 148 /* 149 void Ethernet::ReadSocket(TSocket &rx) 150 { 151 Int_t pos = -1; 152 153 Message msg; 154 msg.cmd = M_BCAN_RX_ind; 155 msg.data[0] = 0; 156 msg.data[1] = 0; 157 158 const TString address = MTcpIpO::GetSocketAddress(rx); 159 160 while (!IsThreadCanceled()) 161 { 162 //TThread::CancelPoint(); 163 164 unsigned char c; 165 const Int_t len = rx.RecvRaw(&c, 1); 166 167 //TThread::CancelPoint(); 168 169 // No data received (non-blocking mode) 170 if (len<0) 171 { 172 usleep(1); 173 continue; 174 } 175 176 // Data received with zero length! 177 if (len==0) 178 { 179 gLog << warn << "WARNING - Connection lost (received 0bytes) to " << address << endl; 180 //break; // This break is for TEST PURPOSE FIXME!!! 181 return; 182 } 183 184 // Data received 185 if (len>1) 186 { 187 gLog << err << "Data received from " << address << " is more than one byte!" << endl; 188 continue; 189 } 190 191 if (pos<0) 192 { 193 if (c>=MSGLEN) 194 { 195 cout << "Data received from " << address << " too long (> " << MSGLEN << ")" << endl; 196 continue; 197 } 198 199 msg.len = c; 200 pos = 2; 201 continue; 202 } 203 204 // if (pos==2 && c==0x0a) 205 // continue; 206 207 msg.data[pos++] = c; 208 if (pos-2<msg.len) 209 continue; 210 211 #ifdef DEBUG 212 cout << "*** RcvdCanFrame len=" << dec << msg.len << ": "; 213 for (int i=0; i<msg.len; i++) 214 cout << "0x" << setfill('0') << setw(2) << hex << (int)((msg.data+2)[i]) << " "; 215 cout << dec << endl; 216 #endif 217 218 pos = -1; 219 220 // String completed 221 HandleMessage(msg); 222 } 223 } 224 */ 152 225 153 226 // -------------------------------------------------------------------------- … … 174 247 // */ 175 248 // 249 #ifdef DEBUG 250 #include <TStopwatch.h> 251 #endif 176 252 void Ethernet::SendCanFrame(WORD_t cobid, BYTE_t m[8], BYTE_t rtr) 177 253 { … … 203 279 #endif 204 280 281 #ifdef DEBUG 282 TStopwatch st; 283 st.Start(); 284 #endif 205 285 MTcpIpO::SendFrame(fTxAddress, fTxPort, (char*)(msg.data+1), msg.len-1); 286 #ifdef DEBUG 287 st.Print(); 288 #endif 206 289 //Send((char*)(msg.data+1), msg.len-1); 207 290 -
trunk/MagicSoft/Cosy/candrv/ethernet.h
r8862 r8864 17 17 18 18 // Send interface based on MTcpIpI 19 voidReadSocket(TSocket &rx);19 Bool_t ReadSocket(TSocket &rx); 20 20 21 21 // Start/stop communication inherited from Interface 22 22 void Start() { RunThread(); } 23 23 void Stop() { CancelThread(); } 24 25 Bool_t HasConnection() const { return IsConnectionEstablished(); } 24 26 25 27 public: -
trunk/MagicSoft/Cosy/candrv/interface.h
r8854 r8864 45 45 virtual void EnableCobId(WORD_t cobid, int flag=TRUE) { } 46 46 47 virtual bool HasConnection() const { return true; } 48 47 49 // Public interface 48 50 void PrintMsg(const Message &m); -
trunk/MagicSoft/Cosy/candrv/network.cc
r8863 r8864 314 314 continue; 315 315 316 if (CanOpen::HasError()) 317 fNodes[i]->SetZombie(); 318 316 319 if (!fNodes[i]->HasError()) 317 320 continue; … … 325 328 //gLog << "' has error #" << fNodes[i]->GetError() << endl; 326 329 } 330 331 if (CanOpen::HasError()) 332 return true; 327 333 328 334 return rc; -
trunk/MagicSoft/Cosy/candrv/nodedrv.h
r8863 r8864 60 60 61 61 int GetError() const { return fError; } 62 bool HasError() const { return fError ; }62 bool HasError() const { return fError!=0; } 63 63 64 64 bool IsZombieNode() const { return fIsZombie; } -
trunk/MagicSoft/Cosy/cosy.cc
r8862 r8864 90 90 const Bool_t kDebugMem = arg.HasOnlyAndRemove("--debug-mem"); 91 91 const Bool_t kDebugThreads = arg.HasOnlyAndRemove("--debug-threads"); 92 const TString sps = arg.GetStringAndRemove("--sps=", " 127.0.0.1");92 const TString sps = arg.GetStringAndRemove("--sps=", "sps"); 93 93 const TString ceco = arg.GetStringAndRemove("--cc=", "ceco"); // ceco 94 94 const TString pointing = arg.GetStringAndRemove("--pointing-model=", "bending2.txt"); // ceco … … 138 138 gLog << inf << "Open automatic logfile: " << name << endl; 139 139 gLog.SetOutputFile(name); 140 gLog.EnableOutputDevice(MLog::eFile); 140 141 } 141 142 -
trunk/MagicSoft/Cosy/devdrv/macs.cc
r8863 r8864 71 71 case 0xa148: return "Drive controlled interpolated relative positioning lagless with encoder 1"; 72 72 case 0xa149: return "Drive controlled interpolated relative positioning lagless with encoder 2"; 73 case 0xa150: return "Drive controlled positioning with encoder 1"; 74 case 0xa151: return "Drive controlled positioning with encoder 2"; 73 75 case 0xa208: return "Jog mode positive"; 74 76 case 0xa218: return "Jog mode negative"; … … 86 88 case 0xe251: return "Motor overtemp warning"; 87 89 case 0xe252: return "Bleeder overtemp warning"; 90 case 0xe257: return "Continous current limit active"; 91 case 0xe264: return "Target position out of numerical range"; 88 92 case 0xe834: return "Emergency-Stop"; 89 93 case 0xe843: return "Positive end-switch activated"; … … 95 99 case 0xf224: return "Maximum breaking time exceeded"; 96 100 case 0xf228: return "Excessive control deviation"; 101 case 0xf250: return "Overflow of target position preset memory"; 97 102 case 0xf269: return "Error during release of the motor holding brake"; 98 103 case 0xf276: return "Absolute encoder out of allowed window"; … … 120 125 const Int_t type = errinf&0xf000; 121 126 122 gLog << all << "DKC reports:";127 gLog << all << MTime(-1) << ": " << GetNodeName() << " DKC "; 123 128 124 129 switch (type) … … 127 132 case 0xe000: gLog << "WARNING"; break; 128 133 case 0xa000: gLog << "Status"; break; 134 case 0xc000: 135 case 0xd000: gLog << "Message"; break; 129 136 default: gLog << "Unknown"; break; 130 137 } … … 134 141 gLog << (type==0xf000 || type==0xe000 ? "!" : ".") << endl; 135 142 136 return type ==0xa000;143 return type!=0xf000; 137 144 } 138 145 … … 148 155 return; 149 156 gLog << inf2 << "- " << GetNodeName() << ": Error[0]=" << hex << val << dec << endl; 150 SetError(EvalStatus(val) ? 0 :val);157 CheckErrorDKC(val); 151 158 return; 152 159 … … 680 687 } 681 688 689 void Macs::CheckErrorDKC(LWORD_t val) 690 { 691 Bool_t rc = EvalStatus(val); 692 SetError(rc ? 0 : val); 693 if (!rc) 694 SetZombie(); 695 } 696 682 697 void Macs::HandlePDO2(const BYTE_t *data, const timeval_t &tv) 683 698 { … … 688 703 if (errnum==0xff && (errinf&0xf000)<=0xe000) 689 704 { 690 EvalStatus(errnum, errinf); 691 SetError(0); 705 CheckErrorDKC(errnum, errinf); 692 706 return; 693 707 } … … 915 929 case 0xff: 916 930 gLog << err << "DKC error! Go and check what is going on!" << endl; 917 DelError();931 //DelError(); 918 932 return; 919 933 /* -
trunk/MagicSoft/Cosy/devdrv/macs.h
r8863 r8864 44 44 return EvalStatus(errnum|(errinf<<16)); 45 45 } 46 void CheckErrorDKC(LWORD_t val); 47 void CheckErrorDKC(UInt_t errnum, UInt_t errinf) 48 { 49 CheckErrorDKC(errnum|(errinf<<16)); 50 } 51 46 52 47 53 void HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, const timeval_t &tv); -
trunk/MagicSoft/Cosy/gui/MGCosy.cc
r8863 r8864 1149 1149 RaDec dest1(xy1.X()*15., xy1.Y()); // xy.X() [h]->[ø] 1150 1150 1151 cout << "TrackPos: " << dest0.Ra() << " h" << dest0.Dec() << "\xb0" << endl;1152 cout << "CalibPos: " << dest1.Ra() << " h" << dest1.Dec() << "\xb0" << endl;1151 cout << "TrackPos: " << dest0.Ra() << "\xb0 " << dest0.Dec() << "\xb0" << endl; 1152 cout << "CalibPos: " << dest1.Ra() << "\xb0 " << dest1.Dec() << "\xb0" << endl; 1153 1153 1154 1154 RaDec dest[2] = { dest0, dest1 }; -
trunk/MagicSoft/Cosy/main/MCosy.cc
r8862 r8864 143 143 // Get the values (FIXME!) 144 144 // 145 int p1 = (fZd1->GetPos()/*+8192*/)%fZd1->GetPhysRes(); 146 int p2 = -(fZd2->GetPos()/*+8192*/)%fZd2->GetPhysRes(); 145 //int p1 = (fZd1->GetPos()+fZd1->GetPhysRes()/2)%fZd1->GetPhysRes(); 146 //int p2 = -(fZd2->GetPos()+fZd2->GetPhysRes()/2)%fZd2->GetPhysRes(); 147 148 int p1 = fZd1->GetPos();//+fZd1->GetPhysRes()/2)%fZd1->GetPhysRes(); 149 int p2 = -fZd2->GetPos();//+fZd2->GetPhysRes()/2)%fZd2->GetPhysRes(); 147 150 148 151 if (fZd1->IsZombieNode()) … … 562 565 fMac1->HandleError(); 563 566 fMac2->HandleError(); 564 fMac3->HandleError(); 567 if (fMac3) 568 fMac3->HandleError(); 565 569 if (HasError() || HasZombie()) 566 570 return false; … … 948 952 gLog << " * Max: " << zmax << "deg " << amax << "deg" << endl; 949 953 950 fMin = fBending.AddOffsets(fMin /TMath::RadToDeg());951 fMax = fBending.AddOffsets(fMax /TMath::RadToDeg());954 fMin = fBending.AddOffsets(fMin*TMath::DegToRad()); 955 fMax = fBending.AddOffsets(fMax*TMath::DegToRad()); 952 956 953 957 gLog << " * Min': " << fMin.Zd()*TMath::RadToDeg() << "deg " << fMin.Az()*TMath::RadToDeg() << "deg" << endl; … … 1628 1632 gLog << inf << "Open Repfile: " << name << endl; 1629 1633 fOutRep = new MLog(name, kTRUE); 1630 *fOutRep << "[Drive Report File]" << endl;1634 *fOutRep << all << "[Drive Report File]" << endl; 1631 1635 *fOutRep << "Version <cvs>" << endl; 1632 1636 *fOutRep << "Date " << MTime(-1) << endl; -
trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.cc
r8862 r8864 2 2 3 3 #include <unistd.h> // usleep 4 5 #include <errno.h> 4 6 5 7 #include <TSocket.h> … … 153 155 } 154 156 155 void MTcpIpIO::ReadSocket(TSocket &rx) 156 { 157 // Clear buffer! 158 char c; 159 // while (fRxSocket->RecvRaw(&c, 1)>0 && !HasStopFlag()) 160 while (rx.RecvRaw(&c, 1)>0 && !IsThreadCanceled()) 161 usleep(1); 162 157 Bool_t MTcpIpIO::ReadSocket(TSocket &rx) 158 { 163 159 TString str; 164 // while (!HasStopFlag()) 160 165 161 while (!IsThreadCanceled()) 166 162 { … … 175 171 } 176 172 177 // Data received with zero length! 173 // Data received with zero length! (Connection lost) 178 174 if (len==0) 179 { 180 // THIS MEANS CONNECTIION LOST!!!! 181 cout << "============> len==0 (CONNECTION LOST?)" << endl; 182 break; // This break is for TEST PURPOSE FIXME!!! 183 continue; 184 } 175 return kFALSE; // This break is for TEST PURPOSE FIXME!!! 185 176 186 177 // Data received … … 202 193 str = ""; 203 194 } 204 } 205 206 //void *MTcpIpIO::Thread() 195 196 return kTRUE; 197 } 198 199 Bool_t MTcpIpI::WaitForData(TSocket &sock) 200 { 201 // No connection established? 202 if (!sock.IsValid()) 203 { 204 gLog << warn << "TSocket invalid on port " << fPortRx << "." << endl; 205 return kFALSE; 206 } 207 208 fConnectionEstablished = kTRUE; 209 210 // Get connection on port fPortRx and redirected 211 while (!IsThreadCanceled()) 212 { 213 // Check for pending data (every ms) 214 switch (sock.Select(TSocket::kRead, 1)) 215 { 216 case kTRUE: // Data pending... go on reading 217 if (!ReadSocket(sock)) 218 { 219 gLog << warn << "WARNING - Connection lost to " << MTcpIpO::GetSocketAddress(sock) << endl; 220 return kFALSE; 221 } 222 223 // *FALLTHROUGH* 224 case kFALSE: // Time out, no data yet, go on waiting 225 226 // Go on waiting for new data 227 continue; 228 229 default: // Error occurance 230 gLog << err << "TSocket::Select returned an error: " << strerror(errno) << endl; 231 return kFALSE; 232 } 233 } 234 return kTRUE; //??? 235 } 236 237 void MTcpIpI::WaitForConnection(TServerSocket &server) 238 { 239 gLog << all << " Wait for connection" << endl; 240 241 while (!IsThreadCanceled()) 242 { 243 gLog << all << "Listening for new connection on port " << fPortRx << "..." << endl; 244 245 // Check for a connection request (reminder: we are in non-blocking mode) 246 TSocket *socket = 0; 247 248 while (!IsThreadCanceled()) 249 { 250 socket = server.Accept(); 251 252 // Accept returned an error 253 if (socket==0) 254 { 255 gLog << err << "Error: TServerSock::Accept on port " << fPortRx << ": " << strerror(errno) << endl; 256 // Since we don't know the type of the error we better shut down the socket 257 return; 258 } 259 260 // No connection request pending 261 if ((Long_t)socket<0) 262 { 263 MThread::Sleep(1000); // Wait a ms 264 continue; 265 } 266 267 // Connection established 268 break; 269 } 270 271 if ((Long_t)socket<=0) 272 return; 273 274 if (!WaitForData(*socket)) 275 fConnectionEstablished = kFALSE; 276 277 delete socket; 278 } 279 } 280 281 Int_t MTcpIpI::Thread() 282 { 283 gLog << inf << "- Starting server listening on port " << fPortRx << "..." << endl; 284 285 while (!IsThreadCanceled()) 286 { 287 TServerSocket *server=new TServerSocket(fPortRx, kTRUE); 288 server->SetOption(kNoBlock, 1); 289 290 while (!IsThreadCanceled() && server->IsValid()) 291 WaitForConnection(*server); 292 293 if (!server->IsValid()) 294 { 295 gLog << err << "ServerSocket on port " << fPortRx << " invalid: "; 296 switch (server->GetErrorCode()) 297 { 298 case 0: gLog << "No error." << endl; break; 299 case -1: gLog << "low level socket() call failed." << endl; break; 300 case -2: gLog << "low level bind() call failed." << endl; break; 301 case -3: gLog << "low level listen() call failed." << endl; break; 302 default: gLog << "Unknown." << endl; break; 303 } 304 } 305 306 delete server; 307 308 MThread::Sleep(5000000); 309 } 310 311 gLog << inf << "- Listening server stopped on port " << fPortRx << "." << endl; 312 313 return 0; 314 } 315 316 /* 207 317 Int_t MTcpIpI::Thread() 208 318 { … … 276 386 gLog << all << "Connection established on port " << fPortRx << "." << endl; 277 387 278 fRxSocket->SetOption(kNoBlock, 1); 388 389 //fRxSocket->SetOption(kNoBlock, 1); 390 391 // Waqit for data 392 while (!IsThreadCanceled()) 393 { 394 switch (fRxSocket->Select(kRead, 1)) 395 { 396 case kTRUE: // Data waiting to be read 397 break; 398 case kFALSE: // time out 399 usleep(10); 400 continue; 401 } 402 403 // ERROR 404 cout << "Error: TRxSocket::Select on port " << fPortRx << "." << endl; 405 406 delete fServSock; 407 delete fRxSocket; 408 fServSock = NULL; 409 fRxSocket = NULL; 410 break; 411 }¨ 412 413 if (!fServSock) 414 continue; 415 416 if (IsThreadCanceled()) 417 { 418 delete fServSock; 419 delete fRxSocket; 420 fServSock = NULL; 421 fRxSocket = NULL; 422 continue; 423 } 279 424 280 425 // ------ IDENTICAL UP TO HERE ------ 281 426 427 // Read and evaluate data 282 428 ReadSocket(*fRxSocket); 283 429 … … 292 438 return 0; 293 439 // return NULL; 294 } 440 }*/ -
trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.h
r8862 r8864 18 18 { 19 19 private: 20 Int_t fPortRx; 20 Int_t fPortRx; 21 Bool_t fConnectionEstablished; 22 23 Bool_t WaitForData(TSocket &sock); 24 void WaitForConnection(TServerSocket &server); 21 25 22 26 Int_t Thread(); 23 27 24 virtual voidReadSocket(TSocket &rx) = 0;28 virtual Bool_t ReadSocket(TSocket &rx) = 0; 25 29 26 30 public: 27 MTcpIpI(Int_t rx) : MThread(Form("MTcpIpI::%d", rx)), fPortRx(rx) { /*RunThread();*/ }31 MTcpIpI(Int_t rx) : MThread(Form("MTcpIpI::%d", rx)), fPortRx(rx), fConnectionEstablished(kFALSE) { /*RunThread();*/ } 28 32 ~MTcpIpI() { CancelThread(); } 33 34 Bool_t IsConnectionEstablished() const { return fConnectionEstablished; } 29 35 }; 30 36 … … 52 58 { 53 59 private: 54 voidReadSocket(TSocket &rx);60 Bool_t ReadSocket(TSocket &rx); 55 61 56 62 public:
Note:
See TracChangeset
for help on using the changeset viewer.