Changeset 10031
- Timestamp:
- 10/21/10 16:16:52 (14 years ago)
- Location:
- trunk/Cosy
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cosy/Changelog
r10026 r10031 31 31 * */Makefile, Makefile*: 32 32 - removed necessity of defining OSTYPE 33 34 * Makefile.rules: 35 - replaced cvs by svn 36 37 * tpoint/TPointGui.cc: 38 - included stdlib.h 39 40 * devdrv/dkc.[h,cc]: 41 - added five-byte error massages from IndraDrive 42 + for errnum and errinf are no coded with 1+5 byte 43 instead of 2+4 44 - added UPS information to PDO3, consequently changed fStatusPDO3 45 from BYTE_t to WORD_t 46 + fixed in the SPS that the armed status was not transmitted in the 47 correct byte 48 - adapted inline functions accordingly 49 50 * cosy.cc: 51 - added a debug line to see when the gui is up 52 - removed receiver port from instantiation of Ethernet 53 54 * candrv/ethernet.[h,cc]: 55 - replaced bidirectional Tcp/Ip sockets by an unidirectional one, 56 thus only one party (cosy) connects (to the SPS) 57 - removed dependancy on MTcpIpI and replaced by new class MTcpIpOI 58 - removed obsolete fTxAddress and fTxPort 59 - only start thread if it is not already running to prevent parallel 60 connection attempts on the same socket 61 + IsConnectionstablished is not evaluated yet 62 63 * tcpip/MTcpIpIO.[h,cc]: 64 - removed empty destructor of MTcpIpIO 65 - changed typical reconnection time from 30s to 3s. This seems 66 more reasonably adapted to human behaviour 67 - added new class MTcpIpOI which is a bi-directional communication 68 channel via TCP/IP 69 70 * main/MCosy.cc: 71 - correctly propagate the pdo3 status 33 72 34 73 -
trunk/Cosy/candrv/ethernet.cc
r9439 r10031 55 55 // and switch the can bus communication on 56 56 // 57 Ethernet::Ethernet(const char *addr, const int tx, const int rx,CanOpen *receiver)58 : MTcpIp I(rx), /*MTcpIpO(addr, tx),*/ Interface(receiver), fTxAddress(addr), fTxPort(tx)57 Ethernet::Ethernet(const char *addr, const int tx, CanOpen *receiver) 58 : MTcpIpOI(addr, tx), Interface(receiver) 59 59 { 60 60 gLog << inf2 << "- Ethernet initialized." << endl; … … 68 68 Ethernet::~Ethernet() 69 69 { 70 MTcpIpI::CancelThread();70 CancelThread(); 71 71 gLog << inf2 << "- Ethernet stopped." << endl; 72 72 } … … 79 79 80 80 Message msg; 81 msg.len = 0; 81 82 msg.cmd = M_BCAN_RX_ind; 82 83 msg.data[0] = 0; 83 84 msg.data[1] = 0; 84 85 85 const TString address = MTcpIpO::GetSocketAddress(rx);86 87 while (! MTcpIpI::IsThreadCanceled())86 const TString address = GetSocketAddress(rx); 87 88 while (!IsThreadCanceled()) 88 89 { 89 90 unsigned char c; … … 280 281 st.Start(); 281 282 #endif 282 MTcpIpO::SendFrame(fTxAddress, fTxPort, (char*)(msg.data+1), msg.len-1); 283 // Send((char*)(msg.data+1), msg.len-1); 283 284 Send((char*)(msg.data+1), msg.len-1); 285 284 286 #ifdef DEBUG 285 287 st.Print(); 286 288 #endif 287 //Send((char*)(msg.data+1), msg.len-1); 288 289 /* 290 const WORD_t desc = MsgDescr(cobid, 8, rtr); 291 292 Message msg; 293 294 msg.cmd = M_BCAN_TX_req; 295 296 msg.len = 12; 297 msg.data[0] = 0; 298 msg.data[1] = 0; 299 msg.data[2] = word_to_msb(desc); 300 msg.data[3] = word_to_lsb(desc); 301 302 memcpy(&msg.data[4], m, 8); 303 304 while (!Send(&msg));*/ 305 } 289 } -
trunk/Cosy/candrv/ethernet.h
r9439 r10031 10 10 #endif 11 11 12 class Ethernet : public MTcpIp I, /*public MTcpIpO,*/public Interface12 class Ethernet : public MTcpIpOI, public Interface 13 13 { 14 14 private: 15 TString fTxAddress;16 Int_t fTxPort;17 18 15 // Send interface based on MTcpIpI 19 16 Bool_t ReadSocket(TSocket &rx); 20 17 21 18 // Start/stop communication inherited from Interface 22 void Start() { MTcpIpI::RunThread(); } 23 void Stop() { MTcpIpI::CancelThread(); } 24 25 Bool_t HasConnection() const { return MTcpIpI::IsConnectionEstablished(); } 19 void Start() { if (!IsThreadRunning()) RunThread(); } 20 void Stop() { CancelThread(); } 26 21 27 22 public: 28 Ethernet(const char *addr, const int tx, const int rx,CanOpen *receiver);23 Ethernet(const char *addr, const int tx, CanOpen *receiver); 29 24 virtual ~Ethernet(); 30 25 -
trunk/Cosy/cosy.cc
r9443 r10031 253 253 com->SetMsgQueue(cosy); 254 254 255 Interface *interface = new Ethernet(sps, 5357, 5358,cosy);255 Interface *interface = new Ethernet(sps, 5357, cosy); 256 256 // Interface *interface = new VmodIcan(cosy, "/dev/dpm_00", 125); 257 257 … … 259 259 260 260 cosy->Start(env); 261 262 gLog << all << "- MCosy started." << endl; 261 263 262 264 // FIXME: Is this the right position? -
trunk/Cosy/tcpip/MTcpIpIO.cc
r9582 r10031 67 67 } 68 68 69 MTcpIpIO::~MTcpIpIO()70 {71 }72 73 69 TString MTcpIpO::GetSocketAddress(const TSocket &s) 74 70 { … … 192 188 193 189 MThread::Sleep(wait); // Wait a ms 194 if (wait<30000000) // 30s 190 if (wait<3000000) // 3s 191 wait *= 2; 192 } 193 194 return 1; 195 } 196 197 Int_t MTcpIpOI::Thread() 198 { 199 fConnectionEstablished = kFALSE; 200 201 const TInetAddress &a = fTxSocket->GetInetAddress(); 202 if (!a.IsValid()) 203 { 204 gLog << err << "- MTcpIpOI::Thread - ERROR: Send socket address invalid." << endl; 205 return 0; 206 } 207 208 gLog << inf << "- MTcpIpOI::Thread created connecting to " << a.GetHostAddress() << ":" << fPortTx << endl; 209 210 Int_t wait = 1000; /// Wait a ms 211 212 MTimeout timeout(fTimeout); 213 214 while (!IsThreadCanceled()) 215 { 216 if (fTxSocket->IsValid()) 217 { 218 fConnectionEstablished = kTRUE; 219 fTimeout = 1000; 220 221 // Get connection on port fPortRx and redirected 222 // Check for pending data (every ms) 223 switch (fTxSocket->Select(TSocket::kRead, 1)) 224 { 225 case kTRUE: // Data pending... go on reading 226 if (!ReadSocket(*fTxSocket)) 227 { 228 gLog << warn << MTime(-1) << " WARNING - Connection lost to " << MTcpIpO::GetSocketAddress(*fTxSocket) << endl; 229 fTxSocket->Close(); 230 continue; 231 } 232 timeout.Start(fTimeout); 233 continue; 234 235 case kFALSE: // Time out, no data yet, go on waiting 236 if (timeout.HasTimedOut()) 237 { 238 gLog << warn << MTime(-1) << " WARNING - Connection to " << MTcpIpO::GetSocketAddress(*fTxSocket) << " timed out after " << fTimeout << "ms." << endl; 239 fTxSocket->Close(); 240 continue; 241 } 242 continue; 243 244 default: // Error occurance 245 gLog << err << "TSocket::Select returned an error: " << strerror(errno) << endl; 246 fTxSocket->Close(); 247 continue; 248 } 249 } 250 251 fConnectionEstablished = kFALSE; 252 253 #ifdef DEBUG 254 cout << "- Reopen send socket to " << a.GetHostAddress() << ":" << fPortTx << endl; 255 #endif 256 257 fMutex.Lock(); 258 259 delete fTxSocket; 260 261 fTxSocket = new TSocket(a.GetHostAddress(), fPortTx); 262 fTxSocket->SetOption(kNoBlock, 1); 263 264 fMutex.UnLock(); 265 266 timeout.Start(fTimeout); 267 268 if (fTxSocket->IsValid()) 269 continue; 270 271 MThread::Sleep(wait); // Wait a ms 272 if (wait<3000000) // 3s 195 273 wait *= 2; 196 274 } -
trunk/Cosy/tcpip/MTcpIpIO.h
r9582 r10031 46 46 class MTcpIpO : public MThread 47 47 { 48 pr ivate:48 protected: 49 49 TSocket *fTxSocket; 50 50 TMutex fMutex; … … 73 73 public: 74 74 MTcpIpIO(const char *addr, Int_t tx, Int_t rx, UInt_t timeout=5000); 75 ~MTcpIpIO();76 75 77 76 virtual bool InterpreteStr(TString str); 78 77 }; 79 78 79 class MTcpIpOI : public MTcpIpO 80 { 81 private: 82 Int_t Thread(); 83 virtual Bool_t ReadSocket(TSocket &rx) = 0; 84 85 Bool_t fConnectionEstablished; 86 Int_t fTimeout; // [ms] Timeout to listen for data to be received 87 public: 88 MTcpIpOI(const char *addr, Int_t tx, UInt_t timeout=5000) : MTcpIpO(addr, tx), fConnectionEstablished(kFALSE), fTimeout(timeout) { } 89 90 Bool_t IsConnectionEstablished() const { return fConnectionEstablished; } 91 }; 92 80 93 #endif
Note:
See TracChangeset
for help on using the changeset viewer.