00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _CANIO_H_
00022 #define _CANIO_H_
00023
00024 #define HAVE_STDINT_H 1
00025
00026 #if HAVE_CONFIG_H
00027 #include <config.h>
00028 #endif
00029 #if HAVE_STDINT_H
00030 #include <stdint.h>
00031 #endif
00032
00033 #include <sys/types.h>
00034 #include <string.h>
00035 #include <stdio.h>
00036 #include <unistd.h>
00037
00038
00039
00040 #ifndef canMSG_STD
00041 #define canMSG_STD 0x0002
00042 #endif
00043
00044
00045 class CanPacket
00046 {
00047 public:
00048 long id;
00049 uint8_t msg[8];
00050 uint32_t dlc;
00051 uint32_t flags;
00052
00053 CanPacket()
00054 {
00055 memset(msg,0,sizeof(msg));
00056
00057 flags = canMSG_STD;
00058 dlc = 8;
00059 }
00060
00061 uint16_t GetSlot(int s) const
00062 {
00063 return (uint16_t) ((msg[s*2] << 8) | (msg[s*2+1]));
00064 }
00065
00066 void PutSlot(const int slot, const uint16_t val)
00067 {
00068 msg[slot*2] = (val >> 8) & 0xFF;
00069 msg[slot*2+1] = val & 0xFF;
00070 }
00071
00072 void PutByte(const int byte, const uint16_t val)
00073 {
00074 msg[byte] = val & 0xFF;
00075 }
00076
00077 char* toString()
00078 {
00079 static char buf[256];
00080 sprintf(buf, "id:%04lX %02X %02X %02X %02X %02X %02X %02X %02X",
00081 id, msg[0], msg[1], msg[2], msg[3], msg[4], msg[5],
00082 msg[6], msg[7]);
00083
00084 return buf;
00085 }
00086 };
00087
00088 #define DUALCAN_NR_CHANNELS 2
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107 class DualCANIO
00108 {
00109 public:
00110 DualCANIO() {}
00111 virtual int Init(long channel_freq) = 0;
00112 virtual int ReadPacket(CanPacket *pkt, int channel) = 0;
00113 virtual int WritePacket(CanPacket &pkt) = 0;
00114 virtual int Shutdown() = 0;
00115 };
00116
00117 #endif