PeakDriverWindowsTrait.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 __PeakDriverWindowsTrait_h__
00041 #define __PeakDriverWindowsTrait_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 CLP1(PEAKOptions,
00053 "Peak CAN Driver",
00054 "pcan,p",
00055 "The baudrate in the form of a value"
00056 "Values:\n"
00057 " Baudrate: \tlegal values are\n"
00058 " 0 = 1 MBit/s\n"
00059 " 1 = 500 kBit/s\n"
00060 " 2 = 250 kBit/s\n"
00061 " 3 = 125 kBit/s\n"
00062 " 4 = 100 kBit/s\n"
00063 " 5 = 50 kBit/s\n"
00064 " 6 = 20 kBit/s\n"
00065 " 7 = 10 kBit/s\n"
00066 " 8 = 5 kBit/s\n"
00067 "(e.g. 2 (default))",
00068 int, baudrate, 2);
00069
00073 class PeakDriverWindowsTrait : public PeakDriverBase {
00074 public:
00075
00077 ~PeakDriverWindowsTrait() {
00078 CAN_Close();
00079 }
00080
00082 void init() {
00083 CLP::config::PEAKOptions::Parameter param;
00084 CLP::config::PEAKOptions::instance().getParameter(param);
00085 if ( (param.baudrate < 0) || (param.baudrate > 8) ) {
00086 ::logging::log::emit< ::logging::Error>()
00087 << "Error: parameter baudrate out of Range"
00088 << ::logging::log::endl;
00089 exit(0);
00090 }
00091
00092 errno = CAN_Init(baudrates[param.baudrate], CAN_INIT_TYPE_EX);
00093 if (errno) {
00094 ::logging::log::emit< ::logging::Error>()
00095 << "CAN_Init() fails" << ::logging::log::endl;
00096 exit(errno);
00097 }
00098 }
00099
00101 DWORD read_mob(MOB &mob) {
00102 return CAN_Read(&mob);
00103 }
00104
00106 DWORD write_mob(MOB &mob) {
00107 return CAN_Write(&mob);
00108 }
00109
00111 DWORD status() {
00112 return CAN_Status();
00113 }
00114
00115 };
00116
00120 typedef PeakDriverWindowsTrait PeakDriverTrait;
00121
00122 }
00123 }
00124 }
00125
00126 #endif
00127