Changeset 1137 for trunk/MagicSoft
- Timestamp:
- 12/21/01 11:38:35 (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Cosy/candrv/vmodican.cc
r1109 r1137 1 /* ======================================================================== *\ 2 ! 3 ! * 4 ! * This file is part of Stesy, the MAGIC Steering System 5 ! * Software. It is distributed to you in the hope that it can be a useful 6 ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes. 7 ! * It is distributed WITHOUT ANY WARRANTY. 8 ! * 9 ! * Permission to use, copy, modify and distribute this software and its 10 ! * documentation for any purpose is hereby granted without fee, 11 ! * provided that the above copyright notice appear in all copies and 12 ! * that both that copyright notice and this permission notice appear 13 ! * in supporting documentation. It is provided "as is" without express 14 ! * or implied warranty. 15 ! * 16 ! 17 ! 18 ! Author(s): Thomas Bretz, 2001 <mailto:tbretz@uni-sw.gwdg.de> 19 ! 20 ! Copyright: MAGIC Software Development, 2000-2001 21 ! 22 ! 23 \* ======================================================================== */ 24 25 /////////////////////////////////////////////////////////////////////// 26 // 27 // VmodIcan 28 // 29 // Class describing the interface to the Janz card in RawCan mode. 30 // 31 /////////////////////////////////////////////////////////////////////// 1 32 #include "vmodican.h" 2 33 … … 13 44 ClassImp(VmodIcan); 14 45 46 // -------------------------------------------------------------------------- 47 // 48 // Prints a CAN Message. 49 // 15 50 void VmodIcan::PrintMsg(Message *m) 16 51 { … … 24 59 } 25 60 61 // -------------------------------------------------------------------------- 62 // 63 // Embedded ioctl-function from C-lib 64 // 26 65 int VmodIcan::Ioctl(int msg, void *arg) 27 66 { … … 29 68 } 30 69 70 // -------------------------------------------------------------------------- 71 // 72 // Enables/Disables the termination. 73 // 31 74 void VmodIcan::SetTermination(int state) /* 0 = off, 1 = on */ 32 75 { … … 54 97 } 55 98 99 // -------------------------------------------------------------------------- 100 // 101 // Receiver Thread. Listener. Listens for incomming messages and processes 102 // these messages through the standard interface: 103 // - therefor overload HandleCanMessge 104 // 56 105 void *VmodIcan::Thread() 57 106 { … … 63 112 struct timeval tv; 64 113 65 //cout << "waiting..." << endl; 66 67 const int n = read(fd, &c, 1); // sleep until message arrive 68 114 // 115 // Sleeps until a message arrives 116 // 117 const int n = read(fd, &c, 1); 118 119 // 120 // read the time for the message as soon as possible 121 // 69 122 gettimeofday(&tv, NULL); 70 123 71 //cout << "read n=" << n << " c=" << (int)c << endl; 72 124 // 125 // if n==0 something strange happened. Stop receiver(?) 126 // 73 127 if (n == 0) 74 128 { … … 77 131 } 78 132 79 switch(c) 133 // 134 // Check for what we received 135 // 136 switch (c) 80 137 { 138 // 139 // Fast message (not used/working) 140 // 81 141 case FAST_QUEUE: 82 142 cout << "--> Fast Queue: " << flush; … … 96 156 break; 97 157 158 // 159 // Plain Can Message to be processed 160 // 98 161 case PLAIN_QUEUE: 99 162 100 163 Message msg; 101 164 165 // 166 // Read the message from the card and process it 167 // 102 168 if (Receive(&msg) < 0) 103 169 return (void *)1; 104 170 105 //cal->PrintMsg(&msg);106 171 HandleMessage(&msg, &tv); 107 172 … … 112 177 } 113 178 179 // -------------------------------------------------------------------------- 180 // 181 // Does a basic message processing and hadles the so called command (cmd) 182 // stamp of the message. This is some kind of message type which is send 183 // by the can interface 184 // 114 185 void VmodIcan::HandleMessage(Message *msg, struct timeval *tv) 115 186 { 187 // 188 // Decode message 189 // 116 190 const WORD_t desc = msg->data[2]<<8 | msg->data[3]; 117 191 const BYTE_t rtr = (desc>>4)&1; … … 158 232 return; 159 233 case M_BCAN_RX_ind: 234 // 235 // Message is a message from the Can bus 236 // 160 237 HandleCanMessage(cobid, &msg->data[4], tv); 161 238 return; 162 239 } 163 240 241 // 242 // Nothing of the above happened 243 // 164 244 cout << hex; 165 245 cout << "Cmd=0x" << (int)msg->cmd << ": "; … … 174 254 } 175 255 256 // -------------------------------------------------------------------------- 257 // 258 // This is can_recv from the Janz software. 259 // 260 // /* can_recv - receive a message from standard interface 261 // * 262 // * This function reads a whole message from the standard host interface of 263 // * a VMOD-ICAN. 264 // * The module is selected by the module number <fd>. 265 // * 266 // * The structure <pm> is filled with the received message. 267 // * 268 // * RETURNS: 269 // * The function returns the number of message received, or -1 when the 270 // * system call failed. 271 // * The return value therefore 0 determines, that no message was available to 272 // * be read: can_recv() does not block in such a case and therefore 273 // * can be used to poll a module for incoming messages. 274 // */ 275 // 176 276 int VmodIcan::Receive(Message *pm) /* receive buffer */ 177 277 { 178 /* can_recv - receive a message from standard interface179 *180 * This function reads a whole message from the standard host interface of181 * a VMOD-ICAN.182 * The module is selected by the module number <fd>.183 *184 * The structure <pm> is filled with the received message.185 *186 * RETURNS:187 * The function returns the number of message received, or -1 when the188 * system call failed.189 * The return value therefore 0 determines, that no message was available to190 * be read: can_recv() does not block in such a case and therefore191 * can be used to poll a module for incoming messages.192 */193 278 194 279 struct dpm_rw_can_desc arg; … … 202 287 } 203 288 289 // -------------------------------------------------------------------------- 290 // 291 // This is can_recv_fast from the Janz software 292 // 293 // /* can_recv_fast - receive a message from layer2 interface 294 // * 295 // * This function reads a FastMessage from the layer2 fast message 296 // * interface of a VMOD-ICAN. 297 // * The module is selected by the file descriptor <fd>. 298 // * 299 // * The structure <pm> is filled with the received message. 300 // * 301 // * RETURNS: 302 // * The function returns -1 when the * system call failed. 303 // * The return value therefore 0 determines, that no message was available to 304 // * be read: can_recv_fast() does not block in such a case and therefore 305 // * can be used to poll a module for incoming messages. 306 // */ 307 // 204 308 int VmodIcan::ReceiveFast(FastMessage *pm) 205 309 { 206 207 /* can_recv_fast - receive a message from layer2 interface208 *209 * This function reads a FastMessage from the layer2 fast message210 * interface of a VMOD-ICAN.211 * The module is selected by the file descriptor <fd>.212 *213 * The structure <pm> is filled with the received message.214 *215 * RETURNS:216 * The function returns -1 when the * system call failed.217 * The return value therefore 0 determines, that no message was available to218 * be read: can_recv_fast() does not block in such a case and therefore219 * can be used to poll a module for incoming messages.220 */221 222 310 struct dpm_write_fast_can_desc arg; 223 311 … … 230 318 } 231 319 232 320 // -------------------------------------------------------------------------- 321 // 322 // This is IcWriteBtrBCAN from the Janz software 323 // 324 // /* IcWriteBtrBCAN - Set bit timing parameters 325 // * 326 // * Set bit timing parameters in CAN controller. May only be used if 327 // * CAN controller is in bus-off state. <btr> stores the bus-timing 328 // * parameters as required by the 82C200 controller. See the description 329 // * of the CBTRreq-service for possible values. 330 // * 331 // * BTR1 is stored in the upper byte of <btr> and BTR0 in the lower. Examples 332 // * are: 333 // * .CS 334 // * Baudrate btr Macro 335 // * 1Mbit 0x2300 BTR_1MB 336 // * 500kBit 0x1c00 BTR_500KB 337 // * 250kBit 0x1c01 BTR_250KB 338 // * 125kBit 0x1c03 BTR_125KB 339 // * 100kBit 0x34c7 BTR_100KB 340 // * 50kBit 0x34cf BTR_50KB 341 // * 20kBit 0x7fcf BTR_20KB 342 // * .CE 343 // * 344 // * SERVICE: CBTRreq 345 // * 346 // * NOTE: 347 // * Raw ICANOS version of the firmware only. 348 // */ 349 // 233 350 void VmodIcan::SetBaudRate(int rate) 234 351 { 235 /* IcWriteBtrBCAN - Set bit timing parameters236 *237 * Set bit timing parameters in CAN controller. May only be used if238 * CAN controller is in bus-off state. <btr> stores the bus-timing239 * parameters as required by the 82C200 controller. See the description240 * of the CBTRreq-service for possible values.241 *242 * BTR1 is stored in the upper byte of <btr> and BTR0 in the lower. Examples243 * are:244 * .CS245 * Baudrate btr Macro246 * 1Mbit 0x2300 BTR_1MB247 * 500kBit 0x1c00 BTR_500KB248 * 250kBit 0x1c01 BTR_250KB249 * 125kBit 0x1c03 BTR_125KB250 * 100kBit 0x34c7 BTR_100KB251 * 50kBit 0x34cf BTR_50KB252 * 20kBit 0x7fcf BTR_20KB253 * .CE254 *255 * SERVICE: CBTRreq256 *257 * NOTE:258 * Raw ICANOS version of the firmware only.259 */260 261 /* create message for vmod-ican */262 352 Message msg; /* buffer for module messages */ 263 353 … … 305 395 } 306 396 307 397 // -------------------------------------------------------------------------- 398 // 399 // This is IcBusOnBCAN from the Janz software 400 // 401 // /* IcBusOnBCAN - switch CANbus controller to bus-on state 402 // * 403 // * Switch CAN controller bus-on. You will need to use this 404 // * function explicitly after you have connected yourself 405 // * to the module with can_open() (or ican_open() under DOS/WINDOWS). 406 // * This is because the module comes up in the bus-off state. 407 // * 408 // * SERVICE: CONreq 409 // * 410 // * NOTE: 411 // * Raw ICANOS version of the firmware only. 412 // */ 413 // 308 414 void VmodIcan::EnableCanBusConnection() 309 415 { 310 /* IcBusOnBCAN - switch CANbus controller to bus-on state311 *312 * Switch CAN controller bus-on. You will need to use this313 * function explicitly after you have connected yourself314 * to the module with can_open() (or ican_open() under DOS/WINDOWS).315 * This is because the module comes up in the bus-off state.316 *317 * SERVICE: CONreq318 *319 * NOTE:320 * Raw ICANOS version of the firmware only.321 */322 416 Message msg; /* buffer for module messages */ 323 417 … … 330 424 } 331 425 426 // -------------------------------------------------------------------------- 427 // 428 // This is ican2_init_fast_canfrom the Janz software 429 // 430 // /* ican2_init_fast_can - initialize fast can access for VMOD-ICAN 431 // * 432 // * By this function, the user may initialize and enable the fast 433 // * host interface (layer2 access) for a VMOD-ICAN module. 434 // * 435 // * The calling application can request <rbuffers> buffer elements in the queue 436 // * that sends data to the host and <wbuffers> buffer elements for the queue 437 // * that transports data to the module. 438 // * 439 // * NOTE: 440 // * Notice that the message filtering on the VMOD-ICAN has to be 441 // * set correctly, so that messages can be received through the fast 442 // * interface. 443 // * 444 // * CAVE AT: 445 // * The <rbuffers> and wbuffers> have no special limit, but the general 446 // * resources of the DPM must not be exceeded. 447 // * For the calculation you need to assume, that 16 buffers in one of the fast 448 // * interface queues take the same DPM space as 1 buffer in the standard 449 // * host interface. 450 // * 451 // * The user must use only one of the functions, either 452 // * ican2_init_fast_can or ican2_init_fast_can_prio 453 // * 454 // * RETURNS: 455 // * Zero if the operation performed successfully, or less than zero on error. 456 // */ 457 // 332 458 int VmodIcan::EnableFastCan(int rbuffers, int wbuffers) 333 459 { 334 /* ican2_init_fast_can - initialize fast can access for VMOD-ICAN335 *336 * By this function, the user may initialize and enable the fast337 * host interface (layer2 access) for a VMOD-ICAN module.338 *339 * The calling application can request <rbuffers> buffer elements in the queue340 * that sends data to the host and <wbuffers> buffer elements for the queue341 * that transports data to the module.342 *343 * NOTE:344 * Notice that the message filtering on the VMOD-ICAN has to be345 * set correctly, so that messages can be received through the fast346 * interface.347 *348 * CAVE AT:349 * The <rbuffers> and wbuffers> have no special limit, but the general350 * resources of the DPM must not be exceeded.351 * For the calculation you need to assume, that 16 buffers in one of the fast352 * interface queues take the same DPM space as 1 buffer in the standard353 * host interface.354 *355 * The user must use only one of the functions, either356 * ican2_init_fast_can or ican2_init_fast_can_prio357 *358 * RETURNS:359 * Zero if the operation performed successfully, or less than zero on error.360 */361 460 struct dpm_fast_can_desc hdp; 362 461 … … 372 471 } 373 472 473 // -------------------------------------------------------------------------- 474 // 475 // This is IcWriteEwlBCAN from the Janz software 476 // 477 // /* IcWriteEwlBCAN - Set error warning limit 478 // * 479 // * Set error warning limit in CAN controller. If this limit is passed, the 480 // * user will get a CEVTind message stating an error interrupt. This type 481 // * of message will also occur if the both error counter again fall below 482 // * this limit. 483 // * 484 // * RESTRICTIONS: 485 // * Will only take effect if CAN controller is in bus-off state. Requires 486 // * an SJA1000 CANbus controller, and will be no-op for 82C200. 487 // * 488 // * SERVICE: CBCONFreq 489 // * 490 // * NOTE: 491 // * Raw ICANOS version of the firmware only. 492 // */ 493 // 374 494 void VmodIcan::DisableCanBusConnection() 375 495 { 376 /* IcWriteEwlBCAN - Set error warning limit377 *378 * Set error warning limit in CAN controller. If this limit is passed, the379 * user will get a CEVTind message stating an error interrupt. This type380 * of message will also occur if the both error counter again fall below381 * this limit.382 *383 * RESTRICTIONS:384 * Will only take effect if CAN controller is in bus-off state. Requires385 * an SJA1000 CANbus controller, and will be no-op for 82C200.386 *387 * SERVICE: CBCONFreq388 *389 * NOTE:390 * Raw ICANOS version of the firmware only.391 */392 496 lout << "- Disconnect from Bus!" << endl; 393 497 … … 400 504 } 401 505 506 // -------------------------------------------------------------------------- 507 // 508 // This is can_close from the Janz software 509 // 510 // /* can_close - close connection to a VMOD-ICAN module 511 // * 512 // * The function can be used to close a connection to a VMOD-ICAN 513 // * that has been established by a can_open() call. 514 // * The module has to be selected by the file descriptor <fd> which was 515 // * obtained when you did the can_open() call. 516 // * 517 // * When you call can_close, all the resources that were used by the driver 518 // * for communication are freed. 519 // * 520 // * The VMOD-ICAN module under question will be reseted, to make sure that 521 // * the communication with the host will stop. That means especially that 522 // * no further interrupt will occur and that the module will not longer be 523 // * active on the CANbus. 524 // * 525 // * RETURNS: N/A 526 // */ 527 // 402 528 void VmodIcan::Close() 403 529 { 404 /* can_close - close connection to a VMOD-ICAN module405 *406 * The function can be used to close a connection to a VMOD-ICAN407 * that has been established by a can_open() call.408 * The module has to be selected by the file descriptor <fd> which was409 * obtained when you did the can_open() call.410 *411 * When you call can_close, all the resources that were used by the driver412 * for communication are freed.413 *414 * The VMOD-ICAN module under question will be reseted, to make sure that415 * the communication with the host will stop. That means especially that416 * no further interrupt will occur and that the module will not longer be417 * active on the CANbus.418 *419 * RETURNS: N/A420 */421 530 lout << "- Close Device!" << endl; 422 531 … … 431 540 } 432 541 542 // -------------------------------------------------------------------------- 543 // 544 // Enable the fifo of the Janz card 545 // Allow VMOD to send messages through the fifo 546 // 433 547 int VmodIcan::EnableFifo() 434 548 { 435 //436 // Allow VMOD to send messages through the fifo437 //438 549 Message msg; /* connect message */ 439 550 … … 448 559 } 449 560 561 // -------------------------------------------------------------------------- 562 // 563 // Reset the module 564 // 450 565 int VmodIcan::Reset() 451 566 { … … 457 572 } 458 573 574 // -------------------------------------------------------------------------- 575 // 576 // This is can_open from the Janz software 577 // 578 // /* can_open - open VMOD-ICAN device 579 // * 580 // * With this function call you open a VMOD-ICAN plugged 581 // * into a MODULbus carrier board for use. The module is 582 // * reseted and then initialized for communication to the host. 583 // * 584 // * A specific module is selected by it's device name (e.g. "/dev/dpm_01"). 585 // */ 586 // 459 587 int VmodIcan::Open(const char *devname) /* pathname of device */ 460 588 { 461 /* can_open - open VMOD-ICAN device 462 * 463 * With this function call you open a VMOD-ICAN plugged 464 * into a MODULbus carrier board for use. The module is 465 * reseted and then initialized for communication to the host. 466 * 467 * A specific module is selected by it's device name (e.g. "/dev/dpm_01"). 468 */ 469 470 fd = open (devname, O_RDONLY, 0); 589 fd = open(devname, O_RDONLY, 0); 471 590 472 591 if (fd < 0) … … 481 600 } 482 601 602 // -------------------------------------------------------------------------- 603 // 604 // This is ican2_select_hostif from the Janz software 605 // 606 // /* ican2_select_hostif - switch standard host interface to new style mode 607 // * 608 // * The routine ican2_select_hostif() can be used to switch a module from 609 // * the standard host interface to the new style mode. The module is selected 610 // * by the module number <fd>. 611 // * 612 // * The calling application can request <rbuffers> buffer for the communication 613 // * queue that sends data to the host and <wbuffers> buffer for the reverse 614 // * communication direction (normal priority queue). By this function the hi- and 615 // * low-prioritized message-queues which sends data to the module are initialized 616 // * to a length of 1. 617 // * 618 // * NOTE: 619 // * To notify the module of the new situation, the driver sends 620 // * a M_NEWHOSTIF message to the module. This is the last message to be 621 // * transfered through the old style host interface. Immediately after 622 // * sending this message, the library is switched to the new style mode. 623 // * Any messages that are sent by the module in this time gap, may be lost. 624 // * It is therefore not recommended to use this function when you wait 625 // * for messages from the module. 626 // * 627 // * The selection of the new host interface is not reversible. It will stay 628 // * until the next reset for the module occurs. This will probably occur 629 // * when you use can_close(). 630 // * 631 // * HINTS: 632 // * When the new style mode is active, no more internal message buffering 633 // * on the module exists. That is whenever the module tries to send something 634 // * and cannot because the queue is full, this message will be dropped. 635 // * Thereby, when enabling the new style host interface you should create 636 // * enough buffers for the queue that sends to the host, to prevent the 637 // * loss of messages. If you loose messages, however you will be indicated 638 // * of that event by a MSGLOST messages (which will not be lost!). 639 // * 640 // * CAVE AT: 641 // * The parameters <rbuffers>, <wbuffers>, <wbuffers_hi> and <wbuffers_low> 642 // * must be greater than 0, less than 128, and the total sum must not 643 // * exceed 236. These parameters aren't checked by the driver! 644 // */ 645 // 483 646 int VmodIcan::StdHost2NewStyle(int rbuffers, int wbuffers, 484 647 int wbuffers_hi, int wbuffers_low) 485 /* buffers in to, from, from_hi, from_low host queue */486 /* ican2_select_hostif - switch standard host interface to new style mode487 *488 * The routine ican2_select_hostif() can be used to switch a module from489 * the standard host interface to the new style mode. The module is selected490 * by the module number <fd>.491 *492 * The calling application can request <rbuffers> buffer for the communication493 * queue that sends data to the host and <wbuffers> buffer for the reverse494 * communication direction (normal priority queue). By this function the hi- and495 * low-prioritized message-queues which sends data to the module are initialized496 * to a length of 1.497 *498 * NOTE:499 * To notify the module of the new situation, the driver sends500 * a M_NEWHOSTIF message to the module. This is the last message to be501 * transfered through the old style host interface. Immediately after502 * sending this message, the library is switched to the new style mode.503 * Any messages that are sent by the module in this time gap, may be lost.504 * It is therefore not recommended to use this function when you wait505 * for messages from the module.506 *507 * The selection of the new host interface is not reversible. It will stay508 * until the next reset for the module occurs. This will probably occur509 * when you use can_close().510 *511 * HINTS:512 * When the new style mode is active, no more internal message buffering513 * on the module exists. That is whenever the module tries to send something514 * and cannot because the queue is full, this message will be dropped.515 * Thereby, when enabling the new style host interface you should create516 * enough buffers for the queue that sends to the host, to prevent the517 * loss of messages. If you loose messages, however you will be indicated518 * of that event by a MSGLOST messages (which will not be lost!).519 *520 * CAVE AT:521 * The parameters <rbuffers>, <wbuffers>, <wbuffers_hi> and <wbuffers_low>522 * must be greater than 0, less than 128, and the total sum must not523 * exceed 236. These parameters aren't checked by the driver!524 */525 648 { 526 649 struct dpm_new_hostif_desc_prio hdp; … … 538 661 } 539 662 663 // -------------------------------------------------------------------------- 664 // 665 // This is can_send_hi from the Janz software 666 // 667 // /* can_send_hi - send message to standard host interface (high priority) 668 // * 669 // * This function performs the same action as can_send(), except it will 670 // * append message <pm> to the highest priority queue of the standard 671 // * host interface. 672 // * 673 // * NOTE: 674 // * Notice that the prioritized issue of the message take effect on the new style 675 // * mode of the standard host interface only. 676 // * 677 // * RETURNS: 678 // * The function returns the number of message send, or -1 when the system 679 // * call failed. 680 // * The return value 0 determines that no message could be send, 681 // * probably because there was no space in the targeted queue. can_send_hi() 682 // * does not block or retry in such a case, so you need to loop explicitly 683 // * until the message is send. 684 // */ 685 // 540 686 int VmodIcan::SendHi(Message *pm) 541 687 { 542 /* can_send_hi - send message to standard host interface (high priority)543 *544 * This function performs the same action as can_send(), except it will545 * append message <pm> to the highest priority queue of the standard546 * host interface.547 *548 * NOTE:549 * Notice that the prioritized issue of the message take effect on the new style550 * mode of the standard host interface only.551 *552 * RETURNS:553 * The function returns the number of message send, or -1 when the system554 * call failed.555 * The return value 0 determines that no message could be send,556 * probably because there was no space in the targeted queue. can_send_hi()557 * does not block or retry in such a case, so you need to loop explicitly558 * until the message is send.559 */560 688 struct dpm_rw_can_desc arg; 561 689 … … 568 696 } 569 697 698 // -------------------------------------------------------------------------- 699 // 700 // This is can_send_low from the Janz software 701 // 702 // /* can_send_low - send message to standard host interface (low priority) 703 // * 704 // * This function performs the same action as can_send(), except it will 705 // * append message <pm> to the lowest priority queue of the standard 706 // * host interface. 707 // * 708 // * NOTE: 709 // * Notice that the prioritized issue of the message take effect on the new 710 // * style mode of the standard host interface only. 711 // * 712 // * RETURNS: 713 // * The function returns the number of message send, or -1 when the system 714 // * call failed. 715 // * The return value 0 determines that no message could be send, 716 // * probably because there was no space in the targeted queue. can_send_low() 717 // * does not block or retry in such a case, so you need to loop explicitly 718 // * until the message is send. 719 // * 720 // */ 570 721 int VmodIcan::SendLo(Message *pm) 571 722 { 572 /* can_send_low - send message to standard host interface (low priority)573 *574 * This function performs the same action as can_send(), except it will575 * append message <pm> to the lowest priority queue of the standard576 * host interface.577 *578 * NOTE:579 * Notice that the prioritized issue of the message take effect on the new580 * style mode of the standard host interface only.581 *582 * RETURNS:583 * The function returns the number of message send, or -1 when the system584 * call failed.585 * The return value 0 determines that no message could be send,586 * probably because there was no space in the targeted queue. can_send_low()587 * does not block or retry in such a case, so you need to loop explicitly588 * until the message is send.589 *590 */591 723 struct dpm_rw_can_desc arg; 592 724 … … 599 731 } 600 732 733 // -------------------------------------------------------------------------- 734 // 735 // This is can_send from the Janz software 736 // 737 // /* can_send - send message to standard host interface (mid priority) 738 // * 739 // * This function sends a complete message to the standard host interface of 740 // * a VMOD-ICAN. 741 // * 742 // * The message <pm> will be queued to the middle prioritized of the three 743 // * queues. 744 // * 745 // * RETURNS: 746 // * The function returns the number of message send, or -1 when the system 747 // * call failed. 748 // * The return value 0 determines that no message could be send, 749 // * probably because there was no space in the targeted queue. can_send() 750 // * does not block or retry in such a case, so you need to loop explicitly 751 // * until the message is send. 752 // */ 753 // 601 754 int VmodIcan::Send(Message *pm) /* file descriptor, message to send */ 602 755 { 603 /* can_send - send message to standard host interface (mid priority)604 *605 * This function sends a complete message to the standard host interface of606 * a VMOD-ICAN.607 *608 * The message <pm> will be queued to the middle prioritized of the three609 * queues.610 *611 * RETURNS:612 * The function returns the number of message send, or -1 when the system613 * call failed.614 * The return value 0 determines that no message could be send,615 * probably because there was no space in the targeted queue. can_send()616 * does not block or retry in such a case, so you need to loop explicitly617 * until the message is send.618 */619 756 struct dpm_rw_can_desc arg; 620 757 … … 627 764 } 628 765 766 // -------------------------------------------------------------------------- 767 // 768 // This is can_fast_send from the Janz software 769 // 770 // /* can_fast_send - send message to fast interface 771 // * 772 // * This function sends a message to the fast host interface (layer-2 773 // * interface) of a VMOD-ICAN. The module is selected by the module number 774 // * <fd>. 775 // * The message to be send will be given in the structure <pm>. 776 // * 777 // * The fast host interface needs to be established before can_fast_send() 778 // * can be used successfully. 779 // * 780 // * RETURNS: 781 // * The function returns 1 if can_fast_send() completed successful. 782 // * Otherwise the return value 0 determines that the message could not be send, 783 // * probably because there was no space in the DPM. The function 784 // * does not block or retry in such a case, so you need to loop explicitly 785 // * until the message is send. 786 // * The function returns -1 when the system-call itself failed. 787 // */ 788 // 629 789 int VmodIcan::Send(FastMessage *pm) /* file descriptor, message to send */ 630 790 { 631 /* can_fast_send - send message to fast interface632 *633 * This function sends a message to the fast host interface (layer-2634 * interface) of a VMOD-ICAN. The module is selected by the module number635 * <fd>.636 * The message to be send will be given in the structure <pm>.637 *638 * The fast host interface needs to be established before can_fast_send()639 * can be used successfully.640 *641 * RETURNS:642 * The function returns 1 if can_fast_send() completed successful.643 * Otherwise the return value 0 determines that the message could not be send,644 * probably because there was no space in the DPM. The function645 * does not block or retry in such a case, so you need to loop explicitly646 * until the message is send.647 * The function returns -1 when the system-call itself failed.648 */649 791 struct dpm_write_fast_can_desc arg; 650 792 … … 659 801 } 660 802 803 // -------------------------------------------------------------------------- 804 // 805 // This is IcSetAfil from the Janz software 806 // 807 // /* 808 // * IcSetAfil - Set software acceptance filter mask 809 // * 810 // * Set software acceptance filtering. 811 // * 812 // * SERVICE: SetAfilMask 813 // */ 814 // 661 815 void VmodIcan::DisableAllCobIds() 662 816 { 663 /* -*-Func-*-664 *665 * IcSetAfil - Set software acceptance filter mask666 *667 * Set software acceptance filtering.668 *669 * SERVICE: SetAfilMask670 */671 817 Message msg; 672 818 … … 685 831 } 686 832 687 833 // -------------------------------------------------------------------------- 834 // 835 // This is IcSetAfil from the Janz software 836 // 837 // /* 838 // * IcSetAfil - Set software acceptance filter mask 839 // * 840 // * Set software acceptance filtering. 841 // * 842 // * SERVICE: SetAfilMask 843 // */ 844 // 688 845 void VmodIcan::EnableCobId(WORD_t cobid, int flag) 689 846 { 690 /* -*-Func-*-691 *692 * IcSetAfil - Set software acceptance filter mask693 *694 * Set software acceptance filtering.695 *696 * SERVICE: SetAfilMask697 *698 * NOTE: This service is available in both version of the firmware: Raw-CAN699 * and CAL.700 */701 847 Message msg; 702 848 … … 713 859 } 714 860 861 // -------------------------------------------------------------------------- 862 // 863 // This is IcSendReqBCAN from the Janz software 864 // 865 // /* 866 // * IcSendReqBCAN - Send a CANbus message 867 // * 868 // * Issue request to send a CAN message. <Spec> controls whether to send with 869 // * or without spec/confirmation. 870 // * .CS 871 // * spec action 872 // * 0 send only 873 // * 1 send with confirmation to the host. 874 // * 2 send and echo message to the host. 875 // * 3 send and generate both echo and confirmation. 876 // * .CE 877 // * 878 // * SERVICE: CTXreq, CTXCreq, CTXEreq, CTXCEreq 879 // * 880 // * NOTE: 881 // * Raw ICANOS version of the firmware only. 882 // */ 883 // 715 884 void VmodIcan::SendCanFrame(WORD_t cobid, BYTE_t m[8]) 716 885 { 717 /* -*-Func-*- 718 * 719 * IcSendReqBCAN - Send a CANbus message 720 * 721 * Issue request to send a CAN message. <Spec> controls whether to send with 722 * or without spec/confirmation. 723 * .CS 724 * spec action 725 * 0 send only 726 * 1 send with confirmation to the host. 727 * 2 send and echo message to the host. 728 * 3 send and generate both echo and confirmation. 729 * .CE 730 * 731 * SERVICE: CTXreq, CTXCreq, CTXEreq, CTXCEreq 732 * 733 * NOTE: 734 * Raw ICANOS version of the firmware only. 735 */ 736 const WORD_t desc = MsgDescr(cobid, 8); 737 738 Message msg; 739 740 msg.cmd = M_BCAN_TX_req; 741 742 msg.len = 12; 743 msg.data[0] = 0; 744 msg.data[1] = 0; 745 msg.data[2] = word_to_msb(desc); 746 msg.data[3] = word_to_lsb(desc); 747 748 memcpy(&msg.data[4], m, 8); 749 750 while (!Send(&msg)); 751 752 /* 753 cout << "0x" << hex << (int)cobid << ": "; 754 for(int i=0; i<10; i++) 755 cout << hex << (int)msg.data[i+2] << " " << flush; 756 cout << endl; 757 cout << "- Message sent." << endl; 758 */ 759 760 } 761 886 const WORD_t desc = MsgDescr(cobid, 8); 887 888 Message msg; 889 890 msg.cmd = M_BCAN_TX_req; 891 892 msg.len = 12; 893 msg.data[0] = 0; 894 msg.data[1] = 0; 895 msg.data[2] = word_to_msb(desc); 896 msg.data[3] = word_to_lsb(desc); 897 898 memcpy(&msg.data[4], m, 8); 899 900 while (!Send(&msg)); 901 } 902 903 // -------------------------------------------------------------------------- 904 // 905 // Constructor. Sets logging. 906 // Set the receiving thread to priority -10 and detached. 907 // 908 // Open the device. 909 // reset the device 910 // Enable the fifo buffers 911 // Set the baud rate to the given rate 912 // Disable passthrough of all cobids (all canbus messages) 913 // and switch the can bus communication on 914 // 762 915 VmodIcan::VmodIcan(const char *dev, const int baud, MLog &out) : Log(out), MThread(false)//: CanDriver(dev, baud) 763 916 { … … 781 934 } 782 935 936 // -------------------------------------------------------------------------- 937 // 938 // Destructor. Stopt the receiver, disables the bus connection and 939 // close the device 940 // 783 941 VmodIcan::~VmodIcan() 784 942 { … … 788 946 } 789 947 948 // -------------------------------------------------------------------------- 949 // 950 // Sends a can frame with the given cobid and the given eight bytes 951 // through the can network 952 // 790 953 void VmodIcan::SendCanFrame(WORD_t cobid, 791 954 BYTE_t m0, BYTE_t m1, BYTE_t m2, BYTE_t m3,
Note:
See TracChangeset
for help on using the changeset viewer.