Menu

PeakDriverBase.h

Go to the documentation of this file.
00001 /*******************************************************************************
00002  *
00003  * Copyright (c) 2008-2010 Michael Schulze <mschulze@ivs.cs.uni-magdeburg.de>
00004  * All rights reserved.
00005  *
00006  *    Redistribution and use in source and binary forms, with or without
00007  *    modification, are permitted provided that the following conditions
00008  *    are met:
00009  *
00010  *    * Redistributions of source code must retain the above copyright
00011  *      notice, this list of conditions and the following disclaimer.
00012  *
00013  *    * Redistributions in binary form must reproduce the above copyright
00014  *      notice, this list of conditions and the following disclaimer in
00015  *      the documentation and/or other materials provided with the
00016  *      distribution.
00017  *
00018  *    * Neither the name of the copyright holders nor the names of
00019  *      contributors may be used to endorse or promote products derived
00020  *      from this software without specific prior written permission.
00021  *
00022  *
00023  *    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
00024  *    IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
00025  *    TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00026  *    PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00027  *    OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00028  *    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00029  *    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00030  *    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00031  *    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00032  *    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00033  *    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034  *
00035  *
00036  * $Id$
00037  *
00038  ******************************************************************************/
00039 
00040 #ifndef __PeakDriverBase_h__
00041 #define __PeakDriverBase_h__
00042 
00043 #if defined(LINUX)
00044     #include <errno.h>
00045     #include <fcntl.h>    // O_RDWR
00046     #include <libpcan.h>
00047 
00048 #elif defined(WIN32)
00049     #include <windows.h>
00050     #if defined(PEAKUSB)
00051         #include "Pcan_usb.h"
00052     #elif defined(PEAKPCI)
00053         #include "Pcan_pci.h"
00054     #else
00055         #error "You have to define either PEAKUSB or PEAKPCI to choose the used Peak driver"
00056     #endif
00057 
00058 #else
00059     #error "PEAK driver within FAMOUSO not support on that platform"
00060 #endif
00061 
00062 #include "mw/nl/can/canID_LE_PC.h"
00063 
00064 namespace device {
00065     namespace nic {
00066         namespace CAN {
00067 
00071             struct PeakDriverBase {
00072 
00076                 class MOB : public TPCANMsg {
00077                     public:
00082                         typedef famouso::mw::nl::CAN::detail::ID <
00083                                     famouso::mw::nl::CAN::detail::famouso_CAN_ID_LE_PC
00084                                 > IDType;
00085 
00087                         void extended() {
00088                             MSGTYPE = MSGTYPE_EXTENDED;
00089                         }
00090 
00092                         IDType& id() {
00093                             return *reinterpret_cast<IDType*>(&ID);
00094                         }
00095 
00097                         uint8_t& len() {
00098                             return LEN;
00099                         }
00100 
00102                         void len(uint8_t l) {
00103                             LEN = l;
00104                         }
00105 
00107                         uint8_t *data() {
00108                             return DATA;
00109                         }
00110 
00112                         explicit MOB() {
00113                             ID = 0;
00114                         }
00115                 };
00116             };
00117 
00122             const uint16_t baudrates[] = { CAN_BAUD_1M,
00123                                            CAN_BAUD_500K,
00124                                            CAN_BAUD_250K,
00125                                            CAN_BAUD_125K,
00126                                            CAN_BAUD_100K,
00127                                            CAN_BAUD_50K,
00128                                            CAN_BAUD_20K,
00129                                            CAN_BAUD_10K,
00130                                            CAN_BAUD_5K
00131                                          };
00132 
00133         } /* namespace CAN */
00134     } /* namespace nic */
00135 } /* namespace device */
00136 
00137 #endif
00138