Index: /trunk/MagicSoft/Cosy/candrv/vmodican.cc
===================================================================
--- /trunk/MagicSoft/Cosy/candrv/vmodican.cc	(revision 1136)
+++ /trunk/MagicSoft/Cosy/candrv/vmodican.cc	(revision 1137)
@@ -1,2 +1,33 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of Stesy, the MAGIC Steering System
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Thomas Bretz, 2001 <mailto:tbretz@uni-sw.gwdg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2001
+!
+!
+\* ======================================================================== */
+
+///////////////////////////////////////////////////////////////////////
+//
+// VmodIcan
+//
+// Class describing the interface to the Janz card in RawCan mode.
+//
+///////////////////////////////////////////////////////////////////////
 #include "vmodican.h"
 
@@ -13,4 +44,8 @@
 ClassImp(VmodIcan);
 
+// --------------------------------------------------------------------------
+//
+// Prints a CAN Message.
+//
 void VmodIcan::PrintMsg(Message *m)
 {
@@ -24,4 +59,8 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Embedded ioctl-function from C-lib
+//
 int VmodIcan::Ioctl(int msg, void *arg)
 {
@@ -29,4 +68,8 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Enables/Disables the termination.
+//
 void VmodIcan::SetTermination(int state)  /* 0 = off, 1 = on */
 {
@@ -54,4 +97,10 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Receiver Thread. Listener. Listens for incomming messages and processes
+// these messages through the standard interface:
+//  - therefor overload HandleCanMessge
+//
 void *VmodIcan::Thread()
 {
@@ -63,12 +112,17 @@
         struct timeval tv;
 
-        //cout << "waiting..." << endl;
-
-        const int n = read(fd, &c, 1); // sleep until message arrive
-
+        //
+        // Sleeps until a message arrives
+        //
+        const int n = read(fd, &c, 1);
+
+        //
+        // read the time for the message as soon as possible
+        //
         gettimeofday(&tv, NULL);
 
-        //cout << "read n=" << n << " c=" << (int)c << endl;
-
+        //
+        // if n==0 something strange happened. Stop receiver(?)
+        //
         if (n == 0)
         {
@@ -77,6 +131,12 @@
         }
 
-        switch(c)
+        //
+        // Check for what we received
+        //
+        switch (c)
         {
+        //
+        // Fast message (not used/working)
+        //
         case FAST_QUEUE:
             cout << "--> Fast Queue:  " << flush;
@@ -96,12 +156,17 @@
             break;
 
+        //
+        // Plain Can Message to be processed
+        //
         case PLAIN_QUEUE:
 
             Message msg;
 
+            //
+            // Read the message from the card and process it
+            //
             if (Receive(&msg) < 0)
                 return (void *)1;
 
-            //cal->PrintMsg(&msg);
             HandleMessage(&msg, &tv);
 
@@ -112,6 +177,15 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Does a basic message processing and hadles the so called command (cmd)
+// stamp of the message. This is some kind of message type which is send
+// by the can interface
+//
 void VmodIcan::HandleMessage(Message *msg, struct timeval *tv)
 {
+    //
+    // Decode message
+    //
     const WORD_t desc  = msg->data[2]<<8 | msg->data[3];
     const BYTE_t rtr   = (desc>>4)&1;
@@ -158,8 +232,14 @@
         return;
     case M_BCAN_RX_ind:
+        //
+        // Message is a message from the Can bus
+        //
         HandleCanMessage(cobid, &msg->data[4], tv);
         return;
     }
 
+    //
+    // Nothing of the above happened
+    //
     cout << hex;
     cout << "Cmd=0x"    << (int)msg->cmd << ":  ";
@@ -174,21 +254,26 @@
 }
 
+// --------------------------------------------------------------------------
+//
+//  This is can_recv from the Janz software.
+//
+//  /* can_recv - receive a message from standard interface
+//   *
+//   * This function reads a whole message from the standard host interface of
+//   * a VMOD-ICAN.
+//   * The module is selected by the module number <fd>.
+//   *
+//   * The structure <pm> is filled with the received message.
+//   *
+//   * RETURNS:
+//   * The function returns the number of message received, or -1 when the
+//   * system call failed.
+//   * The return value therefore 0 determines, that no message was available to
+//   * be read: can_recv() does not block in such a case and therefore
+//   * can be used to poll a module for incoming messages.
+//   */
+//
 int VmodIcan::Receive(Message *pm) /* receive buffer */
 {
-    /* can_recv - receive a message from standard interface
-     *
-     * This function reads a whole message from the standard host interface of
-     * a VMOD-ICAN.
-     * The module is selected by the module number <fd>.
-     *
-     * The structure <pm> is filled with the received message.
-     *
-     * RETURNS:
-     * The function returns the number of message received, or -1 when the
-     * system call failed.
-     * The return value therefore 0 determines, that no message was available to
-     * be read: can_recv() does not block in such a case and therefore
-     * can be used to poll a module for incoming messages.
-     */
 
     struct dpm_rw_can_desc arg;
@@ -202,22 +287,25 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// This is can_recv_fast from the Janz software
+//
+//  /* can_recv_fast - receive a message from layer2 interface
+//   *
+//   * This function reads a FastMessage from the layer2 fast message
+//   * interface of a VMOD-ICAN.
+//   * The module is selected by the file descriptor <fd>.
+//   *
+//   * The structure <pm> is filled with the received message.
+//   *
+//   * RETURNS:
+//   * The function returns -1 when the * system call failed.
+//   * The return value therefore 0 determines, that no message was available to
+//   * be read: can_recv_fast() does not block in such a case and therefore
+//   * can be used to poll a module for incoming messages.
+//   */
+//
 int VmodIcan::ReceiveFast(FastMessage *pm)
 {
-
-    /* can_recv_fast - receive a message from layer2 interface
-     *
-     * This function reads a FastMessage from the layer2 fast message
-     * interface of a VMOD-ICAN.
-     * The module is selected by the file descriptor <fd>.
-     *
-     * The structure <pm> is filled with the received message.
-     *
-     * RETURNS:
-     * The function returns -1 when the * system call failed.
-     * The return value therefore 0 determines, that no message was available to
-     * be read: can_recv_fast() does not block in such a case and therefore
-     * can be used to poll a module for incoming messages.
-     */
-
     struct dpm_write_fast_can_desc arg;
 
@@ -230,34 +318,36 @@
 }
 
-
+// --------------------------------------------------------------------------
+//
+// This is IcWriteBtrBCAN from the Janz software
+//
+//  /* IcWriteBtrBCAN - Set bit timing parameters
+//   *
+//   * Set bit timing parameters in CAN controller. May only be used if
+//   * CAN controller is in bus-off state. <btr> stores the bus-timing
+//   * parameters as required by the 82C200 controller. See the description
+//   * of the CBTRreq-service for possible values.
+//   *
+//   * BTR1 is stored in the upper byte of <btr> and BTR0 in the lower. Examples
+//   * are:
+//   * .CS
+//   *     Baudrate   btr       Macro
+//   *       1Mbit    0x2300    BTR_1MB
+//   *     500kBit    0x1c00    BTR_500KB
+//   *     250kBit    0x1c01    BTR_250KB
+//   *     125kBit    0x1c03    BTR_125KB
+//   *     100kBit    0x34c7    BTR_100KB
+//   *      50kBit    0x34cf    BTR_50KB
+//   *      20kBit    0x7fcf    BTR_20KB
+//   * .CE
+//   *
+//   * SERVICE: CBTRreq
+//   *
+//   * NOTE:
+//   * Raw ICANOS version of the firmware only.
+//   */
+//
 void VmodIcan::SetBaudRate(int rate)
 {
-    /* IcWriteBtrBCAN - Set bit timing parameters
-     *
-     * Set bit timing parameters in CAN controller. May only be used if
-     * CAN controller is in bus-off state. <btr> stores the bus-timing
-     * parameters as required by the 82C200 controller. See the description
-     * of the CBTRreq-service for possible values.
-     *
-     * BTR1 is stored in the upper byte of <btr> and BTR0 in the lower. Examples
-     * are:
-     * .CS
-     *     Baudrate   btr       Macro
-     *       1Mbit    0x2300    BTR_1MB
-     *     500kBit    0x1c00    BTR_500KB
-     *     250kBit    0x1c01    BTR_250KB
-     *     125kBit    0x1c03    BTR_125KB
-     *     100kBit    0x34c7    BTR_100KB
-     *      50kBit    0x34cf    BTR_50KB
-     *      20kBit    0x7fcf    BTR_20KB
-     * .CE
-     *
-     * SERVICE: CBTRreq
-     *
-     * NOTE:
-     * Raw ICANOS version of the firmware only.
-     */
-
-    /* create message for vmod-ican */
     Message msg;  /* buffer for module messages */
 
@@ -305,19 +395,23 @@
 }
 
-
+// --------------------------------------------------------------------------
+//
+// This is IcBusOnBCAN from the Janz software
+//
+//  /* IcBusOnBCAN - switch CANbus controller to bus-on state
+//   *
+//   * Switch CAN controller bus-on. You will need to use this
+//   * function explicitly after you have connected yourself
+//   * to the module with can_open() (or ican_open() under DOS/WINDOWS).
+//   * This is because the module comes up in the bus-off state.
+//   *
+//   * SERVICE: CONreq
+//   *
+//   * NOTE:
+//   * Raw ICANOS version of the firmware only.
+//   */
+//
 void VmodIcan::EnableCanBusConnection()
 {
-    /* IcBusOnBCAN - switch CANbus controller to bus-on state
-     *
-     * Switch CAN controller bus-on. You will need to use this
-     * function explicitly after you have connected yourself
-     * to the module with can_open() (or ican_open() under DOS/WINDOWS).
-     * This is because the module comes up in the bus-off state.
-     *
-     * SERVICE: CONreq
-     *
-     * NOTE:
-     * Raw ICANOS version of the firmware only.
-     */
     Message msg;                  /* buffer for module messages */
 
@@ -330,33 +424,38 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// This is ican2_init_fast_canfrom the Janz software
+//
+//  /* ican2_init_fast_can - initialize fast can access for VMOD-ICAN
+//   *
+//   * By this function, the user may initialize and enable the fast
+//   * host interface (layer2 access) for a VMOD-ICAN module.
+//   *
+//   * The calling application can request <rbuffers> buffer elements in the queue
+//   * that sends data to the host and <wbuffers> buffer elements for the queue
+//   * that transports data to the module.
+//   *
+//   * NOTE:
+//   * Notice that the message filtering on the VMOD-ICAN has to be
+//   * set correctly, so that messages can be received through the fast
+//   * interface.
+//   *
+//   * CAVE AT:
+//   * The <rbuffers> and wbuffers> have no special limit, but the general
+//   * resources of the DPM must not be exceeded.
+//   * For the calculation you need to assume, that 16 buffers in one of the fast
+//   * interface queues take the same DPM space as 1 buffer in the standard
+//   * host interface.
+//   *
+//   * The user must use only one of the functions, either
+//   * ican2_init_fast_can or ican2_init_fast_can_prio
+//   *
+//   * RETURNS:
+//   * Zero if the operation performed successfully, or less than zero on error.
+//   */
+//
 int VmodIcan::EnableFastCan(int rbuffers, int wbuffers)
 {
-    /* ican2_init_fast_can - initialize fast can access for VMOD-ICAN
-     *
-     * By this function, the user may initialize and enable the fast
-     * host interface (layer2 access) for a VMOD-ICAN module.
-     *
-     * The calling application can request <rbuffers> buffer elements in the queue
-     * that sends data to the host and <wbuffers> buffer elements for the queue
-     * that transports data to the module.
-     *
-     * NOTE:
-     * Notice that the message filtering on the VMOD-ICAN has to be
-     * set correctly, so that messages can be received through the fast
-     * interface.
-     *
-     * CAVE AT:
-     * The <rbuffers> and wbuffers> have no special limit, but the general
-     * resources of the DPM must not be exceeded.
-     * For the calculation you need to assume, that 16 buffers in one of the fast
-     * interface queues take the same DPM space as 1 buffer in the standard
-     * host interface.
-     *
-     * The user must use only one of the functions, either
-     * ican2_init_fast_can or ican2_init_fast_can_prio
-     *
-     * RETURNS:
-     * Zero if the operation performed successfully, or less than zero on error.
-     */
     struct dpm_fast_can_desc hdp;
 
@@ -372,22 +471,27 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// This is IcWriteEwlBCAN from the Janz software
+//
+//  /* IcWriteEwlBCAN - Set error warning limit
+//   *
+//   * Set error warning limit in CAN controller. If this limit is passed, the
+//   * user will get a CEVTind message stating an error interrupt. This type
+//   * of message will also occur if the both error counter again fall below
+//   * this limit.
+//   *
+//   * RESTRICTIONS:
+//   * Will only take effect if CAN controller is in bus-off state. Requires
+//   * an SJA1000 CANbus controller, and will be no-op for 82C200.
+//   *
+//   * SERVICE: CBCONFreq
+//   *
+//   * NOTE:
+//   * Raw ICANOS version of the firmware only.
+//   */
+//
 void VmodIcan::DisableCanBusConnection()
 {
-    /* IcWriteEwlBCAN - Set error warning limit
-     *
-     * Set error warning limit in CAN controller. If this limit is passed, the
-     * user will get a CEVTind message stating an error interrupt. This type
-     * of message will also occur if the both error counter again fall below
-     * this limit.
-     *
-     * RESTRICTIONS:
-     * Will only take effect if CAN controller is in bus-off state. Requires
-     * an SJA1000 CANbus controller, and will be no-op for 82C200.
-     *
-     * SERVICE: CBCONFreq
-     *
-     * NOTE:
-     * Raw ICANOS version of the firmware only.
-     */
     lout << "- Disconnect from Bus!" << endl;
 
@@ -400,23 +504,28 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// This is can_close from the Janz software
+//
+//  /* can_close - close connection to a VMOD-ICAN module
+//   *
+//   * The function can be used to close a connection to a VMOD-ICAN
+//   * that has been established by a can_open() call.
+//   * The module has to be selected by the file descriptor <fd> which was
+//   * obtained when you did the can_open() call.
+//   *
+//   * When you call can_close, all the resources that were used by the driver
+//   * for communication are freed.
+//   *
+//   * The VMOD-ICAN module under question will be reseted, to make sure that
+//   * the communication with the host will stop. That means especially that
+//   * no further interrupt will occur and that the module will not longer be
+//   * active on the CANbus.
+//   *
+//   * RETURNS: N/A
+//   */
+//
 void VmodIcan::Close()
 {
-    /* can_close - close connection to a VMOD-ICAN module
-     *
-      * The function can be used to close a connection to a VMOD-ICAN
-     * that has been established by a can_open() call.
-     * The module has to be selected by the file descriptor <fd> which was
-     * obtained when you did the can_open() call.
-     *
-     * When you call can_close, all the resources that were used by the driver
-     * for communication are freed.
-     *
-     * The VMOD-ICAN module under question will be reseted, to make sure that
-     * the communication with the host will stop. That means especially that
-     * no further interrupt will occur and that the module will not longer be
-     * active on the CANbus.
-     *
-     * RETURNS: N/A
-     */
     lout << "- Close Device!" << endl;
 
@@ -431,9 +540,11 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Enable the fifo of the Janz card
+// Allow VMOD to send messages through the fifo
+//
 int VmodIcan::EnableFifo()
 {
-    //
-    // Allow VMOD to send messages through the fifo
-    //
     Message msg; /* connect message */
 
@@ -448,4 +559,8 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Reset the module
+//
 int VmodIcan::Reset()
 {
@@ -457,16 +572,20 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// This is can_open from the Janz software
+//
+//  /* can_open - open VMOD-ICAN device
+//   *
+//   * With this function call you open a VMOD-ICAN plugged
+//   * into a MODULbus carrier board for use. The module is
+//   * reseted and then initialized for communication to the host.
+//   *
+//   * A specific module is selected by it's device name (e.g. "/dev/dpm_01").
+//   */
+//
 int VmodIcan::Open(const char *devname)          /* pathname of device */
 {
-    /* can_open - open VMOD-ICAN device
-     *
-     * With this function call you open a VMOD-ICAN plugged
-     * into a MODULbus carrier board for use. The module is
-     * reseted and then initialized for communication to the host.
-     *
-     * A specific module is selected by it's device name (e.g. "/dev/dpm_01").
-     */
-
-    fd = open (devname, O_RDONLY, 0);
+    fd = open(devname, O_RDONLY, 0);
 
     if (fd < 0)
@@ -481,46 +600,50 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// This is ican2_select_hostif from the Janz software
+//
+//  /* ican2_select_hostif - switch standard host interface to new style mode
+//   *
+//   * The routine ican2_select_hostif() can be used to switch a module from
+//   * the standard host interface to the new style mode. The module is selected
+//   * by the module number <fd>.
+//   *
+//   * The calling application can request <rbuffers> buffer for the communication
+//   * queue that sends data to the host and <wbuffers> buffer for the reverse
+//   * communication direction (normal priority queue). By this function the hi- and
+//   * low-prioritized message-queues which sends data to the module are initialized
+//   * to a length of 1.
+//   *
+//   * NOTE:
+//   * To notify the module of the new situation, the driver sends
+//   * a M_NEWHOSTIF message to the module. This is the last message to be
+//   * transfered through the old style host interface. Immediately after
+//   * sending this message, the library is switched to the new style mode.
+//   * Any messages that are sent by the module in this time gap, may be lost.
+//   * It is therefore not recommended to use this function when you wait
+//   * for messages from the module.
+//   *
+//   * The selection of the new host interface is not reversible. It will stay
+//   * until the next reset for the module occurs. This will probably occur
+//   * when you use can_close().
+//   *
+//   * HINTS:
+//   * When the new style mode is active, no more internal message buffering
+//   * on the module exists. That is whenever the module tries to send something
+//   * and cannot because the queue is full, this message will be dropped.
+//   * Thereby, when enabling the new style host interface you should create
+//   * enough buffers for the queue that sends to the host, to prevent the
+//   * loss of messages. If you loose messages, however you will be indicated
+//   * of that event by a MSGLOST messages (which will not be lost!).
+//   *
+//   * CAVE AT:
+//   * The parameters <rbuffers>, <wbuffers>, <wbuffers_hi> and <wbuffers_low>
+//   * must be greater than 0, less than 128, and the total sum must not
+//   * exceed 236. These parameters aren't checked by the driver!
+//   */
+//
 int VmodIcan::StdHost2NewStyle(int rbuffers, int wbuffers,
                                int wbuffers_hi, int wbuffers_low)
-/* buffers in to, from, from_hi, from_low host queue */
-/* ican2_select_hostif - switch standard host interface to new style mode
- *
- * The routine ican2_select_hostif() can be used to switch a module from
- * the standard host interface to the new style mode. The module is selected
- * by the module number <fd>.
- *
- * The calling application can request <rbuffers> buffer for the communication
- * queue that sends data to the host and <wbuffers> buffer for the reverse
- * communication direction (normal priority queue). By this function the hi- and
- * low-prioritized message-queues which sends data to the module are initialized
- * to a length of 1.
- *
- * NOTE:
- * To notify the module of the new situation, the driver sends
- * a M_NEWHOSTIF message to the module. This is the last message to be
- * transfered through the old style host interface. Immediately after
- * sending this message, the library is switched to the new style mode.
- * Any messages that are sent by the module in this time gap, may be lost.
- * It is therefore not recommended to use this function when you wait
- * for messages from the module.
- *
- * The selection of the new host interface is not reversible. It will stay
- * until the next reset for the module occurs. This will probably occur
- * when you use can_close().
- *
- * HINTS:
- * When the new style mode is active, no more internal message buffering
- * on the module exists. That is whenever the module tries to send something
- * and cannot because the queue is full, this message will be dropped.
- * Thereby, when enabling the new style host interface you should create
- * enough buffers for the queue that sends to the host, to prevent the
- * loss of messages. If you loose messages, however you will be indicated
- * of that event by a MSGLOST messages (which will not be lost!).
- *
- * CAVE AT:
- * The parameters <rbuffers>, <wbuffers>, <wbuffers_hi> and <wbuffers_low>
- * must be greater than 0, less than 128, and the total sum must not
- * exceed 236. These parameters aren't checked by the driver!
- */
 {
     struct dpm_new_hostif_desc_prio hdp;
@@ -538,24 +661,29 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// This is can_send_hi from the Janz software
+//
+//  /* can_send_hi - send message to standard host interface (high priority)
+//   *
+//   * This function performs the same action as can_send(), except it will
+//   * append message <pm> to the highest priority queue of the standard
+//   * host interface.
+//   *
+//   * NOTE:
+//   * Notice that the prioritized issue of the message take effect on the new style
+//   * mode of the standard host interface only.
+//   *
+//   * RETURNS:
+//   * The function returns the number of message send, or -1 when the system
+//   * call failed.
+//   * The return value 0 determines that no message could be send,
+//   * probably because there was no space in the targeted queue. can_send_hi()
+//   * does not block or retry in such a case, so you need to loop explicitly
+//   * until the message is send.
+//   */
+//
 int VmodIcan::SendHi(Message *pm)
 {
-    /* can_send_hi - send message to standard host interface (high priority)
-     *
-     * This function performs the same action as can_send(), except it will
-     * append message <pm> to the highest priority queue of the standard
-     * host interface.
-     *
-     * NOTE:
-     * Notice that the prioritized issue of the message take effect on the new style
-     * mode of the standard host interface only.
-     *
-     * RETURNS:
-     * The function returns the number of message send, or -1 when the system
-     * call failed.
-     * The return value 0 determines that no message could be send,
-     * probably because there was no space in the targeted queue. can_send_hi()
-     * does not block or retry in such a case, so you need to loop explicitly
-     * until the message is send.
-     */
     struct dpm_rw_can_desc arg;
 
@@ -568,25 +696,29 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// This is can_send_low from the Janz software
+//
+//  /* can_send_low - send message to standard host interface (low priority)
+//   *
+//   * This function performs the same action as can_send(), except it will
+//   * append message <pm> to the lowest priority queue of the standard
+//   * host interface.
+//   *
+//   * NOTE:
+//   * Notice that the prioritized issue of the message take effect on the new
+//   * style mode of the standard host interface only.
+//   *
+//   * RETURNS:
+//   * The function returns the number of message send, or -1 when the system
+//   * call failed.
+//   * The return value 0 determines that no message could be send,
+//   * probably because there was no space in the targeted queue. can_send_low()
+//   * does not block or retry in such a case, so you need to loop explicitly
+//   * until the message is send.
+//   *
+//   */
 int VmodIcan::SendLo(Message *pm)
 {
-    /* can_send_low - send message to standard host interface (low priority)
-     *
-     * This function performs the same action as can_send(), except it will
-     * append message <pm> to the lowest priority queue of the standard
-     * host interface.
-     *
-     * NOTE:
-     * Notice that the prioritized issue of the message take effect on the new
-     * style mode of the standard host interface only.
-     *
-     * RETURNS:
-     * The function returns the number of message send, or -1 when the system
-     * call failed.
-     * The return value 0 determines that no message could be send,
-     * probably because there was no space in the targeted queue. can_send_low()
-     * does not block or retry in such a case, so you need to loop explicitly
-     * until the message is send.
-     *
-     */
     struct dpm_rw_can_desc arg;
 
@@ -599,22 +731,27 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// This is can_send from the Janz software
+//
+//  /* can_send - send message to standard host interface (mid priority)
+//   *
+//   * This function sends a complete message to the standard host interface of
+//   * a VMOD-ICAN.
+//   *
+//   * The message <pm> will be queued to the middle prioritized of the three
+//   * queues.
+//   *
+//   * RETURNS:
+//   * The function returns the number of message send, or -1 when the system
+//   * call failed.
+//   * The return value 0 determines that no message could be send,
+//   * probably because there was no space in the targeted queue. can_send()
+//   * does not block or retry in such a case, so you need to loop explicitly
+//   * until the message is send.
+//   */
+//
 int VmodIcan::Send(Message *pm) /* file descriptor, message to send */
 {
-    /* can_send - send message to standard host interface (mid priority)
-     *
-     * This function sends a complete message to the standard host interface of
-     * a VMOD-ICAN.
-     *
-     * The message <pm> will be queued to the middle prioritized of the three
-     * queues.
-     *
-     * RETURNS:
-     * The function returns the number of message send, or -1 when the system
-     * call failed.
-     * The return value 0 determines that no message could be send,
-     * probably because there was no space in the targeted queue. can_send()
-     * does not block or retry in such a case, so you need to loop explicitly
-     * until the message is send.
-     */
     struct dpm_rw_can_desc arg;
 
@@ -627,24 +764,29 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// This is can_fast_send from the Janz software
+//
+//  /* can_fast_send - send message to fast interface
+//   *
+//   * This function sends a message to the fast host interface (layer-2
+//   * interface) of a VMOD-ICAN. The module is selected by the module number
+//   * <fd>.
+//   * The message to be send will be given in the structure <pm>.
+//   *
+//   * The fast host interface needs to be established before can_fast_send()
+//   * can be used successfully.
+//   *
+//   * RETURNS:
+//   * The function returns 1 if can_fast_send() completed successful.
+//   * Otherwise the return value 0 determines that the message could not be send,
+//   * probably because there was no space in the DPM. The function
+//   * does not block or retry in such a case, so you need to loop explicitly
+//   * until the message is send.
+//   * The function returns -1 when the system-call itself failed.
+//   */
+//
 int VmodIcan::Send(FastMessage *pm) /* file descriptor, message to send */
 {
-    /* can_fast_send - send message to fast interface
-     *
-     * This function sends a message to the fast host interface (layer-2
-     * interface) of a VMOD-ICAN. The module is selected by the module number
-     * <fd>.
-     * The message to be send will be given in the structure <pm>.
-     *
-     * The fast host interface needs to be established before can_fast_send()
-     * can be used successfully.
-     *
-     * RETURNS:
-     * The function returns 1 if can_fast_send() completed successful.
-     * Otherwise the return value 0 determines that the message could not be send,
-     * probably because there was no space in the DPM. The function
-     * does not block or retry in such a case, so you need to loop explicitly
-     * until the message is send.
-     * The function returns -1 when the system-call itself failed.
-     */
     struct dpm_write_fast_can_desc arg;
 
@@ -659,14 +801,18 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// This is IcSetAfil from the Janz software
+//
+//  /*
+//   * IcSetAfil - Set software acceptance filter mask
+//   *
+//   * Set software acceptance filtering.
+//   *
+//   * SERVICE: SetAfilMask
+//   */
+//
 void VmodIcan::DisableAllCobIds()
 {
-    /* -*-Func-*-
-     *
-     * IcSetAfil - Set software acceptance filter mask
-     *
-     * Set software acceptance filtering.
-     *
-     * SERVICE: SetAfilMask
-     */
     Message msg;
 
@@ -685,18 +831,18 @@
 }
 
-
+// --------------------------------------------------------------------------
+//
+// This is IcSetAfil from the Janz software
+//
+//  /*
+//   * IcSetAfil - Set software acceptance filter mask
+//   *
+//   * Set software acceptance filtering.
+//   *
+//   * SERVICE: SetAfilMask
+//   */
+//
 void VmodIcan::EnableCobId(WORD_t cobid, int flag)
 {
-    /* -*-Func-*-
-     *
-     * IcSetAfil - Set software acceptance filter mask
-     *
-     * Set software acceptance filtering.
-     *
-     * SERVICE: SetAfilMask
-     *
-     * NOTE: This service is available in both version of the firmware: Raw-CAN
-     * and CAL.
-     */
     Message msg;
 
@@ -713,51 +859,58 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// This is IcSendReqBCAN from the Janz software
+//
+//  /*
+//   * IcSendReqBCAN - Send a CANbus message
+//   *
+//   * Issue request to send a CAN message. <Spec> controls whether to send with
+//   * or without spec/confirmation.
+//   * .CS
+//   *    spec     action
+//   *      0      send only
+//   *      1      send with confirmation to the host.
+//   *      2      send and echo message to the host.
+//   *      3      send and generate both echo and confirmation.
+//   * .CE
+//   *
+//   * SERVICE: CTXreq, CTXCreq, CTXEreq, CTXCEreq
+//   *
+//   * NOTE:
+//   * Raw ICANOS version of the firmware only.
+//   */
+//
 void VmodIcan::SendCanFrame(WORD_t cobid, BYTE_t m[8])
 {
-       /* -*-Func-*-
-         *
-         * IcSendReqBCAN - Send a CANbus message
-         *
-         * Issue request to send a CAN message. <Spec> controls whether to send with
-         * or without spec/confirmation.
-         * .CS
-         *    spec     action
-         *      0      send only
-         *      1      send with confirmation to the host.
-         *      2      send and echo message to the host.
-         *      3      send and generate both echo and confirmation.
-         * .CE
-         *
-         * SERVICE: CTXreq, CTXCreq, CTXEreq, CTXCEreq
-         *
-         * NOTE:
-         * Raw ICANOS version of the firmware only.
-         */
-        const WORD_t desc = MsgDescr(cobid, 8);
-
-        Message msg;
-
-	msg.cmd = M_BCAN_TX_req;
-
-        msg.len = 12;
-	msg.data[0]  = 0;
-	msg.data[1]  = 0;
-	msg.data[2]  = word_to_msb(desc);
-        msg.data[3]  = word_to_lsb(desc);
-
-	memcpy(&msg.data[4], m, 8);
-
-        while (!Send(&msg));
-
-        /*
-        cout << "0x" << hex << (int)cobid << ": ";
-        for(int i=0; i<10; i++)
-            cout << hex << (int)msg.data[i+2] << " " << flush;
-        cout << endl;
-        cout << "- Message sent." << endl;
-        */
-
-}
-
+    const WORD_t desc = MsgDescr(cobid, 8);
+
+    Message msg;
+
+    msg.cmd = M_BCAN_TX_req;
+
+    msg.len = 12;
+    msg.data[0]  = 0;
+    msg.data[1]  = 0;
+    msg.data[2]  = word_to_msb(desc);
+    msg.data[3]  = word_to_lsb(desc);
+
+    memcpy(&msg.data[4], m, 8);
+
+    while (!Send(&msg));
+}
+
+// --------------------------------------------------------------------------
+//
+// Constructor. Sets logging.
+//  Set the receiving thread to priority -10 and detached.
+//
+//  Open the device.
+//  reset the device
+//  Enable the fifo buffers
+//  Set the baud rate to the given rate
+//  Disable passthrough of all cobids (all canbus messages)
+//  and switch the can bus communication on
+//
 VmodIcan::VmodIcan(const char *dev, const int baud, MLog &out) : Log(out), MThread(false)//: CanDriver(dev, baud)
 {
@@ -781,4 +934,9 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Destructor. Stopt the receiver, disables the bus connection and
+// close the device
+//
 VmodIcan::~VmodIcan()
 {
@@ -788,4 +946,9 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Sends a can frame with the given cobid and the given eight bytes
+// through the can network
+//
 void VmodIcan::SendCanFrame(WORD_t cobid,
                             BYTE_t m0, BYTE_t m1, BYTE_t m2, BYTE_t m3,
