PeakDriverLinuxTrait.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #ifndef __PeakDriverLinuxTrait_h__
00041 #define __PeakDriverLinuxTrait_h__
00042
00043 #include "debug.h"
00044
00045 #include "devices/nic/can/peak/PeakDriverBase.h"
00046 #include "util/CommandLineParameterGenerator.h"
00047
00048 namespace device {
00049 namespace nic {
00050 namespace CAN {
00051
00052 CLP2(PEAKOptions,
00053 "Peak CAN Driver",
00054 "pcan,p",
00055 "The device that is used and the baudrate in the form of device:baudrate"
00056 "Values:\n"
00057 " Device: \tdevice that has to be used\n"
00058 " Baudrate: \tlegal values are\n"
00059 " 0 = 1 MBit/s\n"
00060 " 1 = 500 kBit/s\n"
00061 " 2 = 250 kBit/s\n"
00062 " 3 = 125 kBit/s\n"
00063 " 4 = 100 kBit/s\n"
00064 " 5 = 50 kBit/s\n"
00065 " 6 = 20 kBit/s\n"
00066 " 7 = 10 kBit/s\n"
00067 " 8 = 5 kBit/s\n"
00068 "(e.g. /dev/pcan32:2 (default))",
00069 std::string, device, "/dev/pcan32",
00070 int, baudrate, 2);
00071
00075 class PeakDriverLinuxTrait : public PeakDriverBase {
00077 HANDLE handle;
00078 public:
00079
00081 ~PeakDriverLinuxTrait() {
00082 CAN_Close(handle);
00083 }
00084
00086 void init() {
00087 CLP::config::PEAKOptions::Parameter param;
00088 CLP::config::PEAKOptions::instance().getParameter(param);
00089 if ( (param.baudrate < 0) || (param.baudrate > 8) ) {
00090 ::logging::log::emit< ::logging::Error>()
00091 << "Error: parameter baudrate out of Range"
00092 << ::logging::log::endl;
00093 exit(0);
00094 }
00095
00096 errno = 0;
00097
00098
00099
00100 handle = LINUX_CAN_Open(param.device.c_str(), O_RDWR);
00101 if (!handle) {
00102 ::logging::log::emit< ::logging::Error>()
00103 << "can't open CAN device " << param.device.c_str()
00104 << ::logging::log::endl;
00105 exit(errno);
00106 }
00107
00108 errno = CAN_Init(handle, baudrates[param.baudrate], CAN_INIT_TYPE_EX);
00109 if (errno) {
00110 ::logging::log::emit< ::logging::Error>()
00111 << "CAN_Init() fails"
00112 << ::logging::log::endl;
00113 exit(errno);
00114 }
00115 }
00116
00118 DWORD read_mob(MOB &mob) {
00119 return CAN_Read(handle, &mob);
00120 }
00121
00123 DWORD write_mob(MOB &mob) {
00124 return CAN_Write(handle, &mob);
00125 }
00126
00128 DWORD status() {
00129 return CAN_Status(handle);
00130 }
00131
00132 };
00133
00137 typedef PeakDriverLinuxTrait PeakDriverTrait;
00138
00139 }
00140 }
00141 }
00142
00143 #endif
00144