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 #ifndef PCAN_CONTROLLER_HPP
00031 #define PCAN_CONTROLLER_HPP
00032
00033 #include "CAN.hpp"
00034 #include "CANControllerInterface.hpp"
00035 #include "CANBusInterface.hpp"
00036 #include "CANMessage.hpp"
00037
00038 #include <rtt/NonPeriodicActivity.hpp>
00039
00040 #include <libpcan.h>
00041
00042 namespace RTT
00043 {
00044 namespace CAN
00045 {
00053 class PCANController
00054 : public CANControllerInterface
00055 , public NonPeriodicActivity
00056 {
00057 public:
00078 PCANController(int priority,
00079 unsigned int minor=0,
00080 WORD bitrate=CAN_BAUD_500K,
00081 int CANMsgType=CAN_INIT_TYPE_EX);
00082
00083 virtual ~PCANController();
00084
00085
00086 bool initialize();
00087 void loop();
00088 bool breakLoop();
00089 void finalize();
00090
00091
00092 virtual void addBus( unsigned int chan, CANBusInterface* _bus);
00093 virtual void process(const CANMessage* msg);
00094 virtual unsigned int nodeId() const;
00095 bool readFromBuffer( CANMessage& msg);
00096 bool writeToBuffer(const CANMessage * msg);
00097
00098
00099 DWORD status() const;
00100
00101
00102 HANDLE handle() const;
00103
00104 protected:
00105
00106
00107 #define PCAN_CHANNEL_MAX 1
00108 static PCANController* controller[PCAN_CHANNEL_MAX];
00109
00110 HANDLE _handle;
00111 DWORD _status;
00112 WORD _bitrate;
00113 int _CANMsgType;
00114
00115 int _channel;
00116
00117 CANBusInterface * _bus;
00118 CANMessage _CANMsg;
00119
00120 unsigned int total_recv;
00121 unsigned int total_trns;
00122 unsigned int failed_recv;
00123 unsigned int failed_trns;
00124
00125 bool exit;
00126 };
00127 }
00128 }
00129
00130 #endif
00131
00132