Changeset 8813 for trunk/MagicSoft/Cosy
- Timestamp:
- 01/16/08 14:07:42 (17 years ago)
- Location:
- trunk/MagicSoft/Cosy/candrv
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Cosy/candrv/canopen.cc
r2518 r8813 18 18 ! Author(s): Thomas Bretz <mailto:tbretz@astro.uni-wuerzburg.de>, 2003 19 19 ! 20 ! Copyright: MAGIC Software Development, 2000-200 320 ! Copyright: MAGIC Software Development, 2000-2008 21 21 ! 22 22 ! … … 32 32 #include "canopen.h" 33 33 34 #include <iostream> // cout 35 #include <iomanip> // setw, setfill 34 #include "MLog.h" 35 #include "MLogManip.h" 36 37 #include "interface.h" 36 38 37 39 ClassImp(CanOpen); … … 44 46 // PDO combinations 45 47 // 46 CanOpen::CanOpen( const char *dev, const int baud, MLog &out) : VmodIcan(dev, baud, out)47 { 48 lout<< "- CanOpen initialized." << endl;48 CanOpen::CanOpen() : fInterface(0) 49 { 50 gLog << inf << "- CanOpen initialized." << endl; 49 51 } 50 52 … … 55 57 CanOpen::~CanOpen() 56 58 { 57 lout << "- CanOpen destroyed." << endl; 58 } 59 60 // -------------------------------------------------------------------------- 61 // 62 // This overloads VmodIcan::HandleCanMessage. It is called if a can 59 gLog << inf << "- CanOpen destroyed." << endl; 60 } 61 62 // -------------------------------------------------------------------------- 63 // 64 // Start the interface 65 // 66 void CanOpen::Start() 67 { 68 if (fInterface) 69 fInterface->Start(); 70 } 71 72 // -------------------------------------------------------------------------- 73 // 74 // Stop the interface 75 // 76 void CanOpen::Stop() 77 { 78 if (fInterface) 79 fInterface->Stop(); 80 } 81 82 // -------------------------------------------------------------------------- 83 // 84 // This overloads Interface::HandleCanMessage. It is called if a can 63 85 // message was received with all message relevant data (COBId, data, time) 64 86 // It distributes the data depending on its function code to several … … 69 91 // HandlePDO1/2/3/4:handles received PDOs 70 92 // 71 void CanOpen::HandleCanMessage(WORD_t cobid, BYTE_t *data, timeval_t *tv)93 void CanOpen::HandleCanMessage(WORD_t cobid, const BYTE_t *data, const timeval_t &tv) 72 94 { 73 95 const WORD_t fcode = cobid >> 7; … … 105 127 const WORD_t subidx = data[3]; 106 128 129 cout << "SND NODE: " << (int)node << " " << flush; 107 130 HandleSDO(node, cmd, idx, subidx, dat, tv); 108 131 … … 145 168 // -------------------------------------------------------------------------- 146 169 // 170 // Does a basic message processing and hadles the so called command (cmd) 171 // stamp of the message. This is some kind of message type which is send 172 // by the can interface 173 // 174 void CanOpen::HandleMessage(const Message &msg, const timeval_t &tv) 175 { 176 // 177 // Decode message 178 // 179 const WORD_t desc = msg.data[2]<<8 | msg.data[3]; 180 const BYTE_t rtr = (desc>>4)&1; 181 const BYTE_t len = desc&0xf; 182 const WORD_t cobid = desc>>5; 183 184 switch (msg.cmd) // FROM mican.h 185 { 186 case M_MSG_LOST: 187 cout << "Interface reports: " << dec << (int)msg.data[0] << " msg(s) lost!" << endl; 188 return; 189 190 case M_BCAN_TX_con: /* confirm (+/-) transmission */ 191 cout << "Interface reports: CTXcon=0x35" << endl; 192 cout << "This normally means, that the transmission of the following CAN frame failed:" << hex << endl; 193 cout << "Descr: 0x" << cobid << dec; 194 cout << " Rtr: " << (rtr?"Yes":"No"); 195 cout << " Len: " << (int)len << endl; 196 return; 197 198 case M_BCAN_EVENT_ind: 199 cout << "Interface reports: CEVTind=0x37: " << hex; 200 switch (msg.data[0]) // error indicator 201 { 202 case 0x01: 203 cout << "Error interrup occured" << endl; 204 cout << "This means noisy network normally. Please check the bus termination." << endl; 205 switch (msg.data[1]) // msg type (board depending) 206 { 207 case 2: // SJA1000 208 cout << dec; 209 cout << "ModeReg=" << (int)msg.data[2] << ", "; 210 cout << "StatReg=" << (int)msg.data[3] << ", "; 211 cout << "RxErrCnt=" << (int)msg.data[4] << ", "; 212 cout << "TxErrCnt=" << (int)msg.data[5] << endl; 213 } 214 //FIXME? TerminateApp(); 215 return; 216 case 0x02: 217 cout << "Overrun interrup occured" << endl; 218 return; 219 case 0x04: 220 cout << "Interrupts lost" << endl; 221 return; 222 case 0x08: 223 cout << "Send queue full" << endl; 224 return; 225 case 0x10: 226 cout << "CANbus bus-error" << endl; 227 return; 228 } 229 return; 230 case M_BCAN_RX_ind: 231 // 232 // Message is a message from the Can bus 233 // 234 //cout << "HandleCanMessage " << cobid << endl; 235 HandleCanMessage(cobid, &msg.data[4], tv); 236 return; 237 } 238 239 // 240 // Nothing of the above happened 241 // 242 cout << hex; 243 cout << "Cmd=0x" << (int)msg.cmd << ": "; 244 cout << "Descr: 0x" << cobid << dec; 245 cout << " Rtr: " << (rtr?"Yes":"No"); 246 cout << " Len: " << (int)len << endl; 247 248 cout << "As Raw Data:" << hex << setfill('0'); 249 for (int i=0; i<msg.len; i++) 250 cout << " " << setw(2) << (int)(msg.data[i]) << flush; 251 cout << endl; 252 } 253 254 bool CanOpen::WaitForSdos(WORDS_t ms) 255 { 256 // 0: unlimited 257 // <0: don't do a real wait. 258 if (ms<0) 259 { 260 fSdoList.DelAll(); 261 return true; 262 } 263 264 MTimeout t(ms); 265 while (fSdoList.IsPending() && 266 !StopWaitingForSDO() && 267 !t.HasTimedOut()) 268 usleep(1); 269 270 bool rc = true; 271 if (ms && t.HasTimedOut()) 272 { 273 cout << "WaitForSdos timed out." << endl; 274 rc = false; 275 } 276 /* 277 if (StopWaitingForSDO()) 278 { 279 cout << "WaitForSdos stopped." << endl; 280 rc = false; 281 } 282 */ 283 if ((ms && t.HasTimedOut()) || StopWaitingForSDO()) 284 fSdoList.DelAll(); 285 286 return rc; 287 } 288 289 bool CanOpen::WaitForSdo(BYTE_t node, WORD_t idx, BYTE_t subidx, WORDS_t ms) 290 { 291 // 0: unlimited 292 // <0: don't do a real wait. 293 294 if (ms<0) 295 { 296 fSdoList.Del(node, idx, subidx); 297 return true; 298 } 299 300 MTimeout t(ms); 301 while (fSdoList.IsPending(node, idx, subidx) && 302 !StopWaitingForSDO() && 303 !t.HasTimedOut()) 304 usleep(1); 305 306 bool rc = true; 307 if (ms && t.HasTimedOut()) 308 { 309 cout << "WaitForSdo Node #" << (int)node << " " << idx << "/" << (int)subidx << " timed out." << endl; 310 rc = false; 311 } 312 /* 313 if (StopWaitingForSDO()) 314 { 315 cout << "WaitForSdo Node #" << (int)node << " " << idx << "/" << (int)subidx << " stopped." << endl; 316 rc = false; 317 } 318 */ 319 if ((ms && t.HasTimedOut()) || StopWaitingForSDO()) 320 fSdoList.Del(node, idx, subidx); 321 322 return rc; 323 } 324 325 // -------------------------------------------------------------------------- 326 // 147 327 // Enables can messaged for a given node ID and function code. 148 328 // … … 152 332 return; 153 333 154 EnableCobId(CobId(node, fcode), flag); 334 if (fInterface) 335 fInterface->EnableCobId(CobId(node, fcode), flag); 155 336 } 156 337 … … 260 441 // 261 442 void CanOpen::SendPDO1(BYTE_t node, 262 BYTE_t m0 =0, BYTE_t m1=0, BYTE_t m2=0, BYTE_t m3=0,263 BYTE_t m4 =0, BYTE_t m5=0, BYTE_t m6=0, BYTE_t m7=0)443 BYTE_t m0, BYTE_t m1, BYTE_t m2, BYTE_t m3, 444 BYTE_t m4, BYTE_t m5, BYTE_t m6, BYTE_t m7) 264 445 { 265 446 BYTE_t msg[8] = { m0, m1, m2, m3, m4, m5, m6, m7 }; … … 272 453 // 273 454 void CanOpen::SendPDO2(BYTE_t node, 274 BYTE_t m0 =0, BYTE_t m1=0, BYTE_t m2=0, BYTE_t m3=0,275 BYTE_t m4 =0, BYTE_t m5=0, BYTE_t m6=0, BYTE_t m7=0)455 BYTE_t m0, BYTE_t m1, BYTE_t m2, BYTE_t m3, 456 BYTE_t m4, BYTE_t m5, BYTE_t m6, BYTE_t m7) 276 457 { 277 458 BYTE_t msg[8] = { m0, m1, m2, m3, m4, m5, m6, m7 }; … … 284 465 // 285 466 void CanOpen::SendPDO3(BYTE_t node, 286 BYTE_t m0 =0, BYTE_t m1=0, BYTE_t m2=0, BYTE_t m3=0,287 BYTE_t m4 =0, BYTE_t m5=0, BYTE_t m6=0, BYTE_t m7=0)467 BYTE_t m0, BYTE_t m1, BYTE_t m2, BYTE_t m3, 468 BYTE_t m4, BYTE_t m5, BYTE_t m6, BYTE_t m7) 288 469 { 289 470 BYTE_t msg[8] = { m0, m1, m2, m3, m4, m5, m6, m7 }; … … 296 477 // 297 478 void CanOpen::SendPDO4(BYTE_t node, 298 BYTE_t m0 =0, BYTE_t m1=0, BYTE_t m2=0, BYTE_t m3=0,299 BYTE_t m4 =0, BYTE_t m5=0, BYTE_t m6=0, BYTE_t m7=0)479 BYTE_t m0, BYTE_t m1, BYTE_t m2, BYTE_t m3, 480 BYTE_t m4, BYTE_t m5, BYTE_t m6, BYTE_t m7) 300 481 { 301 482 BYTE_t msg[8] = { m0, m1, m2, m3, m4, m5, m6, m7 }; … … 394 575 // -------------------------------------------------------------------------- 395 576 // 577 // This is IcSendReqBCAN from the Janz software 578 // 579 // /* 580 // * IcSendReqBCAN - Send a CANbus message 581 // * 582 // * Issue request to send a CAN message. <Spec> controls whether to send with 583 // * or without spec/confirmation. 584 // * .CS 585 // * spec action 586 // * 0 send only 587 // * 1 send with confirmation to the host. 588 // * 2 send and echo message to the host. 589 // * 3 send and generate both echo and confirmation. 590 // * .CE 591 // * 592 // * SERVICE: CTXreq, CTXCreq, CTXEreq, CTXCEreq 593 // * 594 // * NOTE: 595 // * Raw ICANOS version of the firmware only. 596 // */ 597 // 598 void CanOpen::SendCanFrame(WORD_t cobid, BYTE_t m[8], BYTE_t rtr) 599 { 600 if (fInterface) 601 fInterface->SendCanFrame(cobid, m, rtr); 602 } 603 604 // -------------------------------------------------------------------------- 605 // 606 // Sends a can frame with the given cobid and the given eight bytes 607 // through the can network 608 // 609 void CanOpen::SendCanFrame(WORD_t cobid, 610 BYTE_t m0, BYTE_t m1, BYTE_t m2, BYTE_t m3, 611 BYTE_t m4, BYTE_t m5, BYTE_t m6, BYTE_t m7) 612 { 613 BYTE_t msg[8] = { m0, m1, m2, m3, m4, m5, m6, m7 }; 614 SendCanFrame(cobid, msg); 615 } 616 617 // -------------------------------------------------------------------------- 618 // 396 619 // Decodes node and function code into a CobId 397 620 // -
trunk/MagicSoft/Cosy/candrv/canopen.h
r8812 r8813 9 9 #include "sdolist.h" 10 10 #endif 11 #ifndef COSY_VmodIcan 12 #include "vmodican.h" 11 12 #ifndef COSY_MTimeout 13 #include "MTimeout.h" 13 14 #endif 14 15 #include "MTimeout.h"16 15 17 16 #ifdef __CINT__ … … 65 64 #define kDontWait (-1) 66 65 67 class CanOpen : public VmodIcan 66 class Interface; 67 68 typedef struct timeval timeval_t; 69 70 class CanOpen 68 71 { 69 72 private: 70 PendingSDOList fSdoList; 73 Interface *fInterface; // Handle to the I/O interface 74 PendingSDOList fSdoList; // List for pending SDOs 75 TCondition fPdoCond[32][4]; // one for every PDO of every node 71 76 72 TCondition fPdoCond[32][4]; // one for every PDO of every node 73 // pthread_cond_t fPdoCond[32][4]; 74 // pthread_mutex_t fPdoMux[32][4]; 77 protected: 78 virtual void Start(); // Start CanOpen communication 79 virtual void Stop(); // Stop CanOpen communcation 75 80 76 void HandleCanMessage(WORD_t cobid, BYTE_t *data, timeval_t *tv); 81 private: 82 // 83 // Handle can objects arrived at the CanOpen interface 84 // 85 virtual void HandleSDO(BYTE_t node, BYTE_t cmd, WORD_t idx, BYTE_t subidx, LWORD_t data, const timeval_t &tv)=0; 86 virtual void HandlePDO1(BYTE_t node, const BYTE_t *data, const timeval_t &tv)=0; 87 virtual void HandlePDO2(BYTE_t node, const BYTE_t *data, const timeval_t &tv)=0; 88 virtual void HandlePDO3(BYTE_t node, const BYTE_t *data, const timeval_t &tv)=0; 89 virtual void HandlePDO4(BYTE_t node, const BYTE_t *data, const timeval_t &tv)=0; 90 virtual void HandleNodeguard(BYTE_t node, const timeval_t &tv)=0; 91 virtual void HandleEmergency(BYTE_t node, const timeval_t &tv)=0; 77 92 78 virtual void HandleSDO(BYTE_t node, BYTE_t cmd, WORD_t idx, BYTE_t subidx, LWORD_t data, timeval_t *tv)=0; 79 virtual void HandlePDO1(BYTE_t node, BYTE_t *data, timeval_t *tv)=0; 80 virtual void HandlePDO2(BYTE_t node, BYTE_t *data, timeval_t *tv)=0; 81 virtual void HandlePDO3(BYTE_t node, BYTE_t *data, timeval_t *tv)=0; 82 virtual void HandlePDO4(BYTE_t node, BYTE_t *data, timeval_t *tv)=0; 83 virtual void HandleNodeguard(BYTE_t node, timeval_t *tv)=0; 84 virtual void HandleEmergency(BYTE_t node, timeval_t *tv)=0; 93 // Handle message arrived at the CanOpen interface and split into can objects 94 virtual void HandleCanMessage(WORD_t cobid, const BYTE_t *data, const timeval_t &tv); 85 95 86 96 public: 87 CanOpen( const char *dev, const int baud, MLog &out=gLog);97 CanOpen(); 88 98 virtual ~CanOpen(); 89 99 100 void SetInterface(Interface *f) { fInterface=f; } // Set Handle to the interface 101 102 // Send a Process Data Object (PDO) to the CanOpen bus 90 103 void SendPDO1(BYTE_t node, BYTE_t data[8]); 91 104 void SendPDO2(BYTE_t node, BYTE_t data[8]); … … 105 118 BYTE_t m4=0, BYTE_t m5=0, BYTE_t m6=0, BYTE_t m7=0); 106 119 120 // Send a Service Data Object (SDO) to a CanOpen device (aka. write parameter) 107 121 void SendSDO(BYTE_t node, WORD_t idx, BYTE_t subidx, BYTE_t val, bool store); 108 122 void SendSDO(BYTE_t node, WORD_t idx, BYTE_t subidx, WORD_t val, bool store); … … 113 127 void SendSDO(BYTE_t node, WORD_t idx, LWORD_t val, bool store) { SendSDO(node, idx, 0, val, store); } 114 128 129 // Send other objects 115 130 void SendNMT(BYTE_t node, BYTE_t cmd); 116 131 void SendNodeguard(BYTE_t node); 117 132 133 // Request a Service Data Object (SDO) from a CanOpen device (aka. read parameter) 118 134 void RequestSDO(BYTE_t node, WORD_t idx, BYTE_t subidx=0); 119 135 120 void EnableCanMsg(BYTE_t node, BYTE_t fcode, int flag=TRUE); 121 136 // Enable interface for pass-through of a kind of can-object 122 137 void EnableSdoRx(BYTE_t node); 123 138 void EnablePdo1Rx(BYTE_t node); … … 128 143 void EnableNodeguard(BYTE_t node); 129 144 145 // Enable interface for pass-through of a can-object 146 void EnableCanMsg(BYTE_t node, BYTE_t fcode, int flag=TRUE); 147 148 // Wait until the next Pdo object has arrived 130 149 void WaitForNextPdo1(BYTE_t node) { node -= 1; fPdoCond[node][0].Wait(); } 131 150 void WaitForNextPdo2(BYTE_t node) { node -= 1; fPdoCond[node][1].Wait(); } … … 133 152 void WaitForNextPdo4(BYTE_t node) { node -= 1; fPdoCond[node][3].Wait(); } 134 153 135 // 136 // This function must 137 // 154 // Wait for arrival of a return to a given Sdo (or all axpected Sdos) 155 bool WaitForSdos(WORDS_t ms=500); 156 bool WaitForSdo(BYTE_t node, WORD_t idx, BYTE_t subidx, WORDS_t ms=500); 157 138 158 virtual int StopWaitingForSDO() const { return FALSE; } 139 159 140 bool WaitForSdos(WORDS_t ms=500) 141 { 142 // 0: unlimited 143 // <0: don't do a real wait. 144 if (ms<0) 145 { 146 fSdoList.DelAll(); 147 return true; 148 } 160 // Low level function to send rawcan frames 161 void SendCanFrame(WORD_t cobid, BYTE_t m[8], BYTE_t rtr=0); 162 void SendCanFrame(WORD_t cobid, 163 BYTE_t m0=0, BYTE_t m1=0, BYTE_t m2=0, BYTE_t m3=0, 164 BYTE_t m4=0, BYTE_t m5=0, BYTE_t m6=0, BYTE_t m7=0); 149 165 150 MTimeout t(ms); 151 while (fSdoList.IsPending() && 152 !StopWaitingForSDO() && 153 !t.HasTimedOut()) 154 usleep(1); 166 // Extract the CanOpen message from the message delivered by the interface 167 void HandleMessage(const Message &msg, const timeval_t &tv); 155 168 156 bool rc = true; 157 if (ms && t.HasTimedOut()) 158 { 159 cout << "WaitForSdos timed out." << endl; 160 rc = false; 161 } 162 /* 163 if (StopWaitingForSDO()) 164 { 165 cout << "WaitForSdos stopped." << endl; 166 rc = false; 167 } 168 */ 169 if ((ms && t.HasTimedOut()) || StopWaitingForSDO()) 170 fSdoList.DelAll(); 171 172 return rc; 173 } 174 175 bool WaitForSdo(BYTE_t node, WORD_t idx, BYTE_t subidx, WORDS_t ms=500) 176 { 177 // 0: unlimited 178 // <0: don't do a real wait. 179 180 if (ms<0) 181 { 182 fSdoList.Del(node, idx, subidx); 183 return true; 184 } 185 186 MTimeout t(ms); 187 while (fSdoList.IsPending(node, idx, subidx) && 188 !StopWaitingForSDO() && 189 !t.HasTimedOut()) 190 usleep(1); 191 192 bool rc = true; 193 if (ms && t.HasTimedOut()) 194 { 195 cout << "WaitForSdo Node #" << (int)node << " " << idx << "/" << (int)subidx << " timed out." << endl; 196 rc = false; 197 } 198 /* 199 if (StopWaitingForSDO()) 200 { 201 cout << "WaitForSdo Node #" << (int)node << " " << idx << "/" << (int)subidx << " stopped." << endl; 202 rc = false; 203 } 204 */ 205 if ((ms && t.HasTimedOut()) || StopWaitingForSDO()) 206 fSdoList.Del(node, idx, subidx); 207 208 return rc; 209 } 210 211 public: 169 // Compile CobId from node and function code 212 170 WORD_t CobId(BYTE_t node, BYTE_t fcode) const; 213 171 -
trunk/MagicSoft/Cosy/candrv/network.cc
r6923 r8813 16 16 ! 17 17 ! 18 ! Author(s): Thomas Bretz <mailto:tbretz@uni-sw.gwdg.de>, 200119 ! 20 ! Copyright: MAGIC Software Development, 2000-200 118 ! Author(s): Thomas Bretz, 2001 <mailto:tbretz@astro.uni-wuerzburg.de> 19 ! 20 ! Copyright: MAGIC Software Development, 2000-2008 21 21 ! 22 22 ! … … 32 32 #include "network.h" 33 33 34 #include <iostream .h> // cout35 #include <iomanip .h> // setw, setfill34 #include <iostream> // cout 35 #include <iomanip> // setw, setfill 36 36 37 37 ClassImp(Network); 38 39 using namespace std; 38 40 39 41 // -------------------------------------------------------------------------- … … 44 46 void Network::Start() 45 47 { 46 lout<< "- Starting network." << endl;47 48 VmodIcan::Start();48 gLog << "- Starting network." << endl; 49 50 CanOpen::Start(); 49 51 InitNodes(); 50 52 51 lout<< "- Network started." << endl;53 gLog << "- Network started." << endl; 52 54 } 53 55 … … 58 60 void Network::Stop() 59 61 { 60 lout<< "- Stopping network." << endl;62 gLog << "- Stopping network." << endl; 61 63 62 64 StopNodes(); 63 VmodIcan::Stop();64 65 lout<< "- Network stopped." << endl;65 CanOpen::Stop(); 66 67 gLog << "- Network stopped." << endl; 66 68 } 67 69 … … 70 72 // Initialize the network, set all nodes to NULL (n/a) 71 73 // 72 Network::Network( const char *dev, const int baud, MLog &out) : CanOpen(dev, baud, out)73 { 74 for (int i=0; i<32; i++)75 fNodes[i] = NULL;76 77 lout<< "- Network initialized." << endl;74 Network::Network() : CanOpen() 75 { 76 memset(fNodes, 0, 32*sizeof(*fNodes)); 77 memset(fNodeInitialized, 0, 32*sizeof(*fNodeInitialized)); 78 79 gLog << "- Network initialized." << endl; 78 80 } 79 81 … … 87 89 // HandleSDOError: Handles error occursion (see CanOpen standard) 88 90 // 89 void Network::HandleSDO(BYTE_t node, BYTE_t cmd, WORD_t idx, BYTE_t subidx, LWORD_t data, timeval_t *tv)91 void Network::HandleSDO(BYTE_t node, BYTE_t cmd, WORD_t idx, BYTE_t subidx, LWORD_t data, const timeval_t &tv) 90 92 { 91 93 if (fNodes[node]) … … 123 125 // Distributes PDO1 messages to the correspoding node calling HandlePDO1 124 126 // 125 void Network::HandlePDO1(BYTE_t node, BYTE_t *data, timeval_t *tv)127 void Network::HandlePDO1(BYTE_t node, const BYTE_t *data, const timeval_t &tv) 126 128 { 127 129 if (!fNodes[node]) … … 141 143 // Distributes PDO2 messages to the correspoding node calling HandlePDO2 142 144 // 143 void Network::HandlePDO2(BYTE_t node, BYTE_t *data, timeval_t *tv)145 void Network::HandlePDO2(BYTE_t node, const BYTE_t *data, const timeval_t &tv) 144 146 { 145 147 if (!fNodes[node]) … … 159 161 // Distributes PDO3 messages to the correspoding node calling HandlePDO3 160 162 // 161 void Network::HandlePDO3(BYTE_t node, BYTE_t *data, timeval_t *tv)163 void Network::HandlePDO3(BYTE_t node, const BYTE_t *data, const timeval_t &tv) 162 164 { 163 165 if (!fNodes[node]) … … 177 179 // Distributes PDO4 messages to the correspoding node calling HandlePDO4 178 180 // 179 void Network::HandlePDO4(BYTE_t node, BYTE_t *data, timeval_t *tv)181 void Network::HandlePDO4(BYTE_t node, const BYTE_t *data, const timeval_t &tv) 180 182 { 181 183 if (!fNodes[node]) … … 196 198 // HandleNodeguard 197 199 // 198 void Network::HandleNodeguard(BYTE_t node, timeval_t *tv)200 void Network::HandleNodeguard(BYTE_t node, const timeval_t &tv) 199 201 { 200 202 if (!fNodes[node]) … … 212 214 // HandleEmergency 213 215 // 214 void Network::HandleEmergency(BYTE_t node, timeval_t *tv)216 void Network::HandleEmergency(BYTE_t node, const timeval_t &tv) 215 217 { 216 218 if (!fNodes[node]) … … 250 252 if (fNodes[i]) 251 253 { 252 lout<< "- Setting up Node #" << dec << i << " (";253 lout<< fNodes[i]->GetNodeName() << ")" << endl;254 gLog << "- Setting up Node #" << dec << i << " ("; 255 gLog << fNodes[i]->GetNodeName() << ")" << endl; 254 256 if (fNodes[i]->InitDevice(this)) 255 257 fNodeInitialized[i] = TRUE; 256 258 else 257 lout<< "- " << fNodes[i]->GetNodeName() << ": InitDevice failed." << endl;259 gLog << "- " << fNodes[i]->GetNodeName() << ": InitDevice failed." << endl; 258 260 } 259 lout<< "- All Nodes setup." << endl;261 gLog << "- All Nodes setup." << endl; 260 262 } 261 263 … … 269 271 if (fNodes[i] && fNodeInitialized[i]) 270 272 { 271 lout<< "- Stopping Node #" << dec << i;272 lout<< " (" << fNodes[i]->GetNodeName() << ")" << endl;273 gLog << "- Stopping Node #" << dec << i; 274 gLog << " (" << fNodes[i]->GetNodeName() << ")" << endl; 273 275 fNodes[i]->StopDevice(); 274 276 } 275 lout<< "- All Nodes stopped." << endl;277 gLog << "- All Nodes stopped." << endl; 276 278 } 277 279 … … 290 292 continue; 291 293 292 lout<< "- Node #" << dec << i << " '" << fNodes[i]->GetNodeName() << "' ";294 gLog << "- Node #" << dec << i << " '" << fNodes[i]->GetNodeName() << "' "; 293 295 294 296 if (fNodes[i]->GetError() <= 0) 295 lout<< "Error occured." << endl;297 gLog << "Error occured." << endl; 296 298 else 297 lout<< "has error #" << fNodes[i]->GetError() << endl;299 gLog << "has error #" << fNodes[i]->GetError() << endl; 298 300 } 299 301 } … … 320 322 continue; 321 323 322 // lout<< "- Node #" << dec << i << " '" << fNodes[i]->GetNodeName();323 // lout<< "' has error #" << fNodes[i]->GetError() << endl;324 //gLog << "- Node #" << dec << i << " '" << fNodes[i]->GetNodeName(); 325 //gLog << "' has error #" << fNodes[i]->GetError() << endl; 324 326 } 325 327 … … 350 352 bool rc = true; 351 353 352 lout<< "- Trying to reboot all Zombies..." << endl;354 gLog << "- Trying to reboot all Zombies..." << endl; 353 355 for (int i=0; i<32; i++) 354 356 if (fNodes[i]) … … 356 358 if (!fNodes[i]->Reboot()) 357 359 { 358 lout<< "- Failed to reboot " << fNodes[i]->GetNodeName() << "." << endl;360 gLog << "- Failed to reboot " << fNodes[i]->GetNodeName() << "." << endl; 359 361 rc = false; 360 362 } 361 363 362 364 if (rc) 363 lout<< "- All Zombies rebooted." << endl;365 gLog << "- All Zombies rebooted." << endl; 364 366 365 367 return rc; -
trunk/MagicSoft/Cosy/candrv/network.h
r6923 r8813 15 15 int fNodeInitialized[32]; 16 16 17 void HandleSDO(BYTE_t node, BYTE_t cmd, WORD_t idx, BYTE_t subidx, LWORD_t data, timeval *tv);18 void HandlePDO1(BYTE_t node, BYTE_t *data, timeval_t *tv);19 void HandlePDO2(BYTE_t node, BYTE_t *data, timeval_t *tv);20 void HandlePDO3(BYTE_t node, BYTE_t *data, timeval_t *tv);21 void HandlePDO4(BYTE_t node, BYTE_t *data, timeval_t *tv);22 void HandleNodeguard(BYTE_t node, timeval_t *tv);23 void HandleEmergency(BYTE_t node, timeval_t *tv);17 void HandleSDO(BYTE_t node, BYTE_t cmd, WORD_t idx, BYTE_t subidx, LWORD_t data, const timeval &tv); 18 void HandlePDO1(BYTE_t node, const BYTE_t *data, const timeval_t &tv); 19 void HandlePDO2(BYTE_t node, const BYTE_t *data, const timeval_t &tv); 20 void HandlePDO3(BYTE_t node, const BYTE_t *data, const timeval_t &tv); 21 void HandlePDO4(BYTE_t node, const BYTE_t *data, const timeval_t &tv); 22 void HandleNodeguard(BYTE_t node, const timeval_t &tv); 23 void HandleEmergency(BYTE_t node, const timeval_t &tv); 24 24 25 25 void InitNodes(); … … 27 27 28 28 public: 29 Network( const char *dev, const int baud, MLog &out=gLog);29 Network(); 30 30 31 31 void SetNode(NodeDrv *drv); … … 34 34 NodeDrv *GetNode(int i) { return fNodes[i]; } 35 35 36 v irtual void Start();37 v irtual void Stop();36 void Start(); 37 void Stop(); 38 38 39 39 void PrintError() const; -
trunk/MagicSoft/Cosy/candrv/nodedrv.cc
r8376 r8813 54 54 #include "MLogManip.h" 55 55 56 #include "MThread.h" 57 56 58 ClassImp(NodeDrv); 57 59 … … 145 147 // it in the 'non-standard' CANOpen communication with the MACS) 146 148 // 147 void NodeDrv::HandleSDOOK(WORD_t idx, BYTE_t subidx, LWORD_t data, timeval_t *tv)149 void NodeDrv::HandleSDOOK(WORD_t idx, BYTE_t subidx, LWORD_t data, const timeval_t &tv) 148 150 { 149 151 const Bool_t gui = lout.IsOutputDeviceEnabled(MLog::eGui); … … 175 177 // Prints the received SDo from this device 176 178 // 177 void NodeDrv::HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, timeval_t *tv)179 void NodeDrv::HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, const timeval_t &tv) 178 180 { 179 181 cout << "SdoRx: Idx=0x"<< hex << idx << "/" << (int)subidx; … … 496 498 : MThread(false), fGuardTime(guard/1000.), fLifeTimeFactor(ltf), fIsCanOpen(canopen), fDrv(drv) { } 497 499 498 void Reset( timeval_t *tv=NULL)500 void Reset(const timeval_t *tv=NULL) 499 501 { 500 502 MTime t; … … 587 589 // guard time times lifetimefactor. 588 590 // 589 void NodeDrv::HandleNodeguard( timeval_t *tv)591 void NodeDrv::HandleNodeguard(const timeval_t &tv) 590 592 { 591 593 if (fGuard) 592 fGuard->Reset( tv);594 fGuard->Reset(&tv); 593 595 } 594 596 -
trunk/MagicSoft/Cosy/candrv/nodedrv.h
r6923 r8813 69 69 void SetZombie(bool stopguard=true); 70 70 71 virtual void HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, timeval_t *tv);72 virtual void HandleSDOOK(WORD_t idx, BYTE_t subidx, LWORD_t data, timeval_t *tv);71 virtual void HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, const timeval_t &tv); 72 virtual void HandleSDOOK(WORD_t idx, BYTE_t subidx, LWORD_t data, const timeval_t &tv); 73 73 virtual void HandleSDOError(LWORD_t data); 74 74 75 virtual void HandlePDO1( BYTE_t *data, timeval_t *tv) {}76 virtual void HandlePDO2( BYTE_t *data, timeval_t *tv) {}77 virtual void HandlePDO3( BYTE_t *data, timeval_t *tv) {}78 virtual void HandlePDO4( BYTE_t *data, timeval_t *tv) {}79 virtual void HandleNodeguard( timeval_t *tv);80 virtual void HandleEmergency( timeval_t *tv) {}75 virtual void HandlePDO1(const BYTE_t *data, const timeval_t &tv) {} 76 virtual void HandlePDO2(const BYTE_t *data, const timeval_t &tv) {} 77 virtual void HandlePDO3(const BYTE_t *data, const timeval_t &tv) {} 78 virtual void HandlePDO4(const BYTE_t *data, const timeval_t &tv) {} 79 virtual void HandleNodeguard(const timeval_t &tv); 80 virtual void HandleEmergency(const timeval_t &tv) {} 81 81 82 82 bool SendPDO1(BYTE_t data[8]);
Note:
See TracChangeset
for help on using the changeset viewer.