18 #include <yarp/dev/ControlBoardInterfaces.h>
19 #include <yarp/dev/PolyDriver.h>
20 #include <yarp/dev/CanBusInterface.h>
21 #include <yarp/os/Time.h>
22 #include <yarp/sig/Vector.h>
23 #include <yarp/os/PeriodicThread.h>
30 using namespace yarp::sig;
31 using namespace yarp::os;
47 ICanBufferFactory *iBufferFactory;
48 CanBuffer messageBuffer;
49 unsigned long int cnt;
53 unsigned int messages, readMessages;
56 signed int position[2];
57 signed short speed[2];
60 signed short sin_frequency[2];
61 signed short sin_amplitude[2];
62 signed short dutyCycle[2];
63 signed short torque[2];
64 signed short commut[2];
66 unsigned short unsigned_gaugeData[6];
67 signed short signed_gaugeData[6];
68 signed short dataBuffer[6];
75 for(
int i=0; i<6; i++)
77 unsigned_gaugeData[i] = 0;
78 signed_gaugeData[i] = 0;
82 for(
int i=0; i<2; i++)
103 prop.put(
"device",
"ecan");
105 prop.put(
"CanTxTimeout", 500);
106 prop.put(
"CanRxTimeout", 500);
107 prop.put(
"CanDeviceNum", 0);
115 if (!driver.isValid())
117 fprintf(stderr,
"Error opening PolyDriver check parameters\n");
121 driver.view(iCanBus);
122 driver.view(iBufferFactory);
125 if (!iCanBus->canSetBaudRate(0))
126 fprintf(stderr,
"Error setting baud rate\n");
129 iCanBus->canIdAdd(0x12A);
130 iCanBus->canIdAdd(0x12B);
134 fp = fopen(
"output.dat",
"w");
141 bool res=iCanBus->canRead(messageBuffer, messages, &readMessages);
144 for(
int i=0; i<readMessages; i++)
167 if (messageBuffer[i].getId() == 0x12B)
169 sin_frequency[0] = (messageBuffer[i].getData()[1]<<8) | messageBuffer[i].getData()[0];
170 sin_amplitude[0] = (messageBuffer[i].getData()[3]<<8) | messageBuffer[i].getData()[2];
171 dutyCycle[0] = (messageBuffer[i].getData()[5]<<8) | messageBuffer[i].getData()[4];
174 if (messageBuffer[i].getId() == 0x12A)
176 position[0] = (messageBuffer[i].getData()[1]<<8) | messageBuffer[i].getData()[0];
177 speed[0] = (messageBuffer[i].getData()[3]<<8) | messageBuffer[i].getData()[2];
178 pid[0] = (messageBuffer[i].getData()[5]<<8) | messageBuffer[i].getData()[4];
179 torque[0] = (messageBuffer[i].getData()[7]<<8) | messageBuffer[i].getData()[6];
188 if(
log_start)
fprintf(
fp,
"%d %d %d %d %d %d %d %d\n",cnt,sin_frequency[0],sin_amplitude[0],position[0],speed[0],pid[0],torque[0],dutyCycle[0]);
190 if ((cnt % 500) == 0)
192 fprintf(stdout,
"%d %d %d %d %d %d %d %d\n",cnt,sin_frequency[0],sin_amplitude[0],position[0],speed[0],pid[0],torque[0],dutyCycle[0]);
242 iBufferFactory->destroyBuffer(messageBuffer);
SnifferThread(int r=SNIFFER_THREAD_RATE)
int main(int argc, char *argv[])
const int SNIFFER_THREAD_RATE
const int localBufferSize
const int CAN_DRIVER_BUFFER_SIZE
Copyright (C) 2008 RobotCub Consortium.
static struct bpf_program fp