Skip to content
Snippets Groups Projects
Commit 9c991ec6 authored by Alejandro Lopez Gestoso's avatar Alejandro Lopez Gestoso
Browse files

Added a new test for the CAN class

parent 8b870cd2
No related branches found
No related tags found
No related merge requests found
#include "eventserver.h"
#include "threadserver.h"
#include "commexceptions.h"
#include "can.h"
#include <stdio.h>
#include <unistd.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <linux/can/raw.h>
#include <linux/can.h>
const std::string can_dev="slcan0";
int main(int argc,char *argv[])
{
CEventServer *event_server=CEventServer::instance();
std::list<std::string> events;
CCAN can_port("can_port");
CCAN can_port2("can_port2");
unsigned char data[8];
unsigned int can_id;
int i=0,len;
int event_id;
events.push_back(can_port.get_new_frame_event_id());
events.push_back(can_port2.get_new_frame_event_id());
try{
can_port.open(can_dev);
can_port2.open(can_dev);
unsigned short int can_filter = (unsigned short int)(7 << 4);
can_port.add_id_filter(can_filter, 0x0f0, false);
can_filter = (unsigned short int)(1 << 4);
can_port2.add_id_filter(can_filter, 0x0f0, false);
while(1)
{
event_id = event_server->wait_first(events);
if (event_id == 0)
{
can_port.read_frame(&can_id,data,&len);
std::cout << " " << can_dev << " " << std::uppercase << std::hex <<(int)can_id << std::dec << " [" <<(int)len << "] ";
for(i=0;i<len;i++)
std::cout << std::uppercase << std::setw(2) << std::setfill('0') << std::hex << (int)data[i] << " ";
std::cout << std::dec << std::endl;
}
else if (event_id == 1)
{
can_port2.read_frame(&can_id,data,&len);
std::cout << " " << can_dev << " " << std::uppercase << std::hex <<(int)can_id << std::dec << " [" <<(int)len << "] ";
for(i=0;i<len;i++)
std::cout << std::uppercase << std::setw(2) << std::setfill('0') << std::hex << (int)data[i] << " ";
std::cout << std::dec << std::endl;
}
}
}catch(CCommException &e){
std::cout << e.what() << std::endl;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment