草庐IT

canopen开源库canfestival编译、移植、使用

黄忻 2023-04-07 原文

canfestival下载地址:https://hg.beremiz.org/canfestival

一般ubuntu环境编译:

1、./configure --prefix=$PWD/myinstall --can=socket --debug=WAR,MSG
2、make all
遇到python报错解决方法如下:
sudo apt-get install python安装python2
sudo ln -s /usr/bin/python2 /usr/bin/python建立链接
3、sudo make install

板子上交叉编译:

1、./configure --cc=aarch64-linux-gnu-gcc --arch=aarch64 --prefix=$PWD/myinstall --can=socket --debug=WAR,MSG
2、make all
遇到python报错解决方法同上
3、sudo make install
存在can口测试:

1、ifconfig -a查看网口列表,该命令即便can口没打开也会被找到

2、can口关闭、设置、打开:
sudo ifconfig can0 down
sudo ip link set can0 type can bitrate 250000
sudo ifconfig can0 up

3、can0测试:进入编译后得到的可执行文件目录$PWD/myinstall/bin,多个终端执行以下命令,观察现象:

./CANOpenShell load#../lib/libcanfestival_can_socket.so,can0,500k,1,1

没有can口则创建虚拟can口测试:

1、确认安装了环境,不管有没有安装can-utils走一遍总没错:sudo apt install can-utils

2、加载vcan内核模块、创建虚拟CAN接口、将虚拟CAN接口处于在线状态

sudo modprobe vcan

sudo ip link add dev vcan0 type vcan

sudo ip link set up vcan0

3、类似上面步骤多终端执行以下命令:

./CANOpenShell load#../lib/libcanfestival_can_socket.so,vcan0,500k,1,1

一般ubuntu环境移植:

1、win10_64下Canfestival对象字典工具objdictedit运行环境配置:
https://www.python.org/ftp/python/2.7.10/python-2.7.10.amd64.msi下载python-2.7.10.amd64.msi,安装时记得选择Add python.exeto Path,也可以在安装完成之后手动将安装路径添加到系统环境变量中(当然,这个较为麻烦,尽量前一种方式,没找着就反复卸了再装,找到那个选项加上为止)

https://sourceforge.net/projects/wxpython/files/wxPython/2.8.12.1/wxPython2.8-win64-unicode-2.8.12.1-py27.exe/download下载wxPython2.8-win64-unicode-2.8.12.1-py27.exe,一路默认安装下去就行了

解压源码objdictgen目录下的Gnosis_Utils-current.tar.gz,使得该目录下存在gnosis目录

2、使用源码目录下objdictgen目录下的objdictedit.py生成需要的.h和.c文件:

打开objdictedit.py

文件

新建

 选定为上图情形,确认

文件

建立词典

路径自己选,保存

3、弄三个.h和.c的文件,然后弄下Makefile文件,文件名及源码如下:

master.h

#include "canfestival.h"
#include "data.h"
#include <unistd.h>
#include <stdio.h>


INTEGER8 InitCANdevice( char* bus, UNS32 baudrate, UNS8 node );

void MasterNode_heartbeatError(CO_Data* d, UNS8);

UNS8 MasterNode_canSend(Message *);

void MasterNode_initialisation(CO_Data* d);
void MasterNode_preOperational(CO_Data* d);
void MasterNode_operational(CO_Data* d);
void MasterNode_stopped(CO_Data* d);

void MasterNode_post_sync(CO_Data* d);
void MasterNode_post_TPDO(CO_Data* d);
void MasterNode_storeODSubIndex(CO_Data* d, UNS16 wIndex, UNS8 bSubindex);
void MasterNode_post_emcy(CO_Data* d, UNS8 nodeID, UNS16 errCode, UNS8 errReg);

 master.c

#include "MasterNode.h"
#include "master.h"


static UNS8 masterNodeID = 0;

void InitNode(CO_Data* d, UNS32 id)
{
    /* Defining the node Id */
    setNodeId(&MasterNode_Data, masterNodeID);
    /* CAN init */
    setState(&MasterNode_Data, Initialisation);
}

void Exit(CO_Data* d, UNS32 id)
{
    setState(&MasterNode_Data, Stopped);
}

INTEGER8 InitCANdevice(char * bus, UNS32 baudrate, UNS8 node )
{
    char busName[2];
    char baudRate[7];
    s_BOARD board;


    sprintf(baudRate, "%uK", baudrate);
    board.busname = bus;
    board.baudrate = baudRate;

    masterNodeID = node;

    MasterNode_Data.heartbeatError = MasterNode_heartbeatError;
    MasterNode_Data.initialisation = MasterNode_initialisation;
    MasterNode_Data.preOperational = MasterNode_preOperational;
    MasterNode_Data.operational = MasterNode_operational;
    MasterNode_Data.stopped = MasterNode_stopped;
    MasterNode_Data.post_sync = MasterNode_post_sync;
    MasterNode_Data.post_TPDO = MasterNode_post_TPDO;
    MasterNode_Data.storeODSubIndex = MasterNode_storeODSubIndex;
    MasterNode_Data.post_emcy = MasterNode_post_emcy;

    TimerInit();

    if(!canOpen(&board, &MasterNode_Data))
    {
        printf("aInitCANdevice() CAN bus %s opening error, baudrate=%s",board.busname, board.baudrate);
        return -1;
    }


    printf("InitCANdevice(), canOpen() OK, starting timer loop...");

    /* Start timer thread */
    StartTimerLoop(&InitNode);

    /* wait Ctrl-C */
    pause();
    printf("Finishing.");

    /* Stop timer thread */
    StopTimerLoop(&Exit);
    return 0;
}

void MasterNode_heartbeatError(CO_Data* d, UNS8 heartbeatID)
{
    printf("MasterNode_heartbeatError %d", heartbeatID);
}

void MasterNode_initialisation(CO_Data* d )
{
    printf("MasterNode_initialisation");
}


void MasterNode_preOperational(CO_Data* d)
{
    printf("MasterNode_preOperational");

    setState(d, Operational);
}

void MasterNode_operational(CO_Data* d)
{
    printf("MasterNode_operational");
}

void MasterNode_stopped(CO_Data* d)
{
    printf("MasterNode_stopped");
}

void MasterNode_post_sync(CO_Data* d)
{
    printf("MasterNode_post_sync");
}

void MasterNode_post_TPDO(CO_Data* d)
{
    printf("MasterNode_post_TPDO");
}

void MasterNode_storeODSubIndex(CO_Data* d, UNS16 wIndex, UNS8 bSubindex)
{
    /*TODO :
     * - call getODEntry for index and subindex,
     * - save content to file, database, flash, nvram, ...
     *
     * To ease flash organisation, index of variable to store
     * can be established by scanning d->objdict[d->ObjdictSize]
     * for variables to store.
     *
     * */
    printf("MasterNode_storeODSubIndex : %4.4x %2.2xh", wIndex,  bSubindex);
}

void MasterNode_post_emcy(CO_Data* d, UNS8 nodeID, UNS16 errCode, UNS8 errReg)
{
    printf("Slave received EMCY message. Node: %2.2xh  ErrorCode: %4.4x  ErrorRegister: %2.2xh", nodeID, errCode, errReg);
}

main.c

#include "master.h"


 int main(int argc,char **argv)
 {
     char* LibraryPath = (char*)"/home/hx/compile/canfestival-de1fc3261f21/myinstall/lib/libcanfestival_can_socket.so";

     LoadCanDriver(LibraryPath);

     if(InitCANdevice((char*)"vcan0" , 500000,  0x0A) < 0)
     {
         printf("InitCANdevice() failed, exiting.");
         return -1;
     }

     return 0;
 }

Makefile

#编译环境
GXX_C = gcc

#头文件和库
INCLUDES += -I./canfestival/include
INCLUDES += -I./canfestival/include/timers_unix
INCLUDES += -I./canfestival/include/unix
INCLUDES += -I./canfestival/include/AVR
LIBS += -lpthread -lrt -ldl

#.c文件
FILES_C = $(wildcard *.c)
FILES_C += $(wildcard ./canfestival/src/*.c)
FILES_C += $(wildcard ./canfestival/drivers/timers_unix/*.c)
FILES_C += $(wildcard ./canfestival/drivers/unix/*.c)

#.c文件生成的.o文件
FILES_O_C = $(FILES_C:.c=.o)

#目标文件
TARGET = my_canfestival_test

#编译:1、将.c文件编译成.o文件;2、将.o文件编译成目标文件
all:$(TARGET)
$(FILES_O_C):%.o:%.c
	$(GXX_C) -c $< -o $@ $(INCLUDES)
$(TARGET):$(FILES_O_C) $(FILES_O_CPP)
	$(GXX_C) -o $(TARGET) $(FILES_O_C) $(FILES_O_CPP) $(LIBS)
	
#清理:目标文件、.c文件生成的.o文件
clean:
	rm -rf $(TARGET) $(FILES_O_C)

4、拷贝及修改需要的文件、编译

建一个目录canfestival,将源码目录下的drivers、include、src三个目录拷贝进去

make编译

报错:fatal error: avr/io.h: 没有那个文件或目录

修改include/AVR/config.h将选中地方注释或去掉

报错:在函数‘check_and_start_node’中:
dcf.c:(.text+0x61):对‘start_node’未定义的引用

修改src/dcf.c将

选中地方最前面加上static 

类似上面的报错还有一个start_and_seek_node,解决方法同上

5、测试编译出来的my_canfestival_test

main.c文件中的main函数里面用到了编译出来的库,所以记得要填对位置

准备好虚拟vcan0环境

多终端执行./my_canfestival_test看效果

6、清理多余的文件

针对canfestival目录清理多余的文件,最后效果如以下图:

 

 

 

 

 

  

有关canopen开源库canfestival编译、移植、使用的更多相关文章

  1. ruby - 如何使用 Nokogiri 的 xpath 和 at_xpath 方法 - 2

    我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div

  2. ruby - 使用 RubyZip 生成 ZIP 文件时设置压缩级别 - 2

    我有一个Ruby程序,它使用rubyzip压缩XML文件的目录树。gem。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。我在rubyzipdocumentation中找不到一种为创建的ZIP文件指定压缩级别的方法。有人知道如何更改此设置吗?是否有另一个允许指定压缩级别的Ruby库? 最佳答案 这是我通过查看ruby​​zip内部创建的代码。level=Zlib::BEST_COMPRESSIONZip::ZipOutputStream.open(zip_file)do|zip|Dir.glob("**/*")d

  3. ruby - 为什么我可以在 Ruby 中使用 Object#send 访问私有(private)/ protected 方法? - 2

    类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc

  4. ruby-on-rails - 使用 Ruby on Rails 进行自动化测试 - 最佳实践 - 2

    很好奇,就使用ruby​​onrails自动化单元测试而言,你们正在做什么?您是否创建了一个脚本来在cron中运行rake作业并将结果邮寄给您?git中的预提交Hook?只是手动调用?我完全理解测试,但想知道在错误发生之前捕获错误的最佳实践是什么。让我们理所当然地认为测试本身是完美无缺的,并且可以正常工作。下一步是什么以确保他们在正确的时间将可能有害的结果传达给您? 最佳答案 不确定您到底想听什么,但是有几个级别的自动代码库控制:在处理某项功能时,您可以使用类似autotest的内容获得关于哪些有效,哪些无效的即时反馈。要确保您的提

  5. ruby - 在 Ruby 中使用匿名模块 - 2

    假设我做了一个模块如下:m=Module.newdoclassCendend三个问题:除了对m的引用之外,还有什么方法可以访问C和m中的其他内容?我可以在创建匿名模块后为其命名吗(就像我输入“module...”一样)?如何在使用完匿名模块后将其删除,使其定义的常量不再存在? 最佳答案 三个答案:是的,使用ObjectSpace.此代码使c引用你的类(class)C不引用m:c=nilObjectSpace.each_object{|obj|c=objif(Class===objandobj.name=~/::C$/)}当然这取决于

  6. ruby - 使用 ruby​​ 和 savon 的 SOAP 服务 - 2

    我正在尝试使用ruby​​和Savon来使用网络服务。测试服务为http://www.webservicex.net/WS/WSDetails.aspx?WSID=9&CATID=2require'rubygems'require'savon'client=Savon::Client.new"http://www.webservicex.net/stockquote.asmx?WSDL"client.get_quotedo|soap|soap.body={:symbol=>"AAPL"}end返回SOAP异常。检查soap信封,在我看来soap请求没有正确的命名空间。任何人都可以建议我

  7. python - 如何使用 Ruby 或 Python 创建一系列高音调和低音调的蜂鸣声? - 2

    关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。

  8. ruby-on-rails - 'compass watch' 是如何工作的/它是如何与 rails 一起使用的 - 2

    我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t

  9. ruby - 使用 ruby​​ 将 HTML 转换为纯文本并维护结构/格式 - 2

    我想将html转换为纯文本。不过,我不想只删除标签,我想智能地保留尽可能多的格式。为插入换行符标签,检测段落并格式化它们等。输入非常简单,通常是格式良好的html(不是整个文档,只是一堆内容,通常没有anchor或图像)。我可以将几个正则表达式放在一起,让我达到80%,但我认为可能有一些现有的解决方案更智能。 最佳答案 首先,不要尝试为此使用正则表达式。很有可能你会想出一个脆弱/脆弱的解决方案,它会随着HTML的变化而崩溃,或者很难管理和维护。您可以使用Nokogiri快速解析HTML并提取文本:require'nokogiri'h

  10. ruby - 在 64 位 Snow Leopard 上使用 rvm、postgres 9.0、ruby 1.9.2-p136 安装 pg gem 时出现问题 - 2

    我想为Heroku构建一个Rails3应用程序。他们使用Postgres作为他们的数据库,所以我通过MacPorts安装了postgres9.0。现在我需要一个postgresgem并且共识是出于性能原因你想要pggem。但是我对我得到的错误感到非常困惑当我尝试在rvm下通过geminstall安装pg时。我已经非常明确地指定了所有postgres目录的位置可以找到但仍然无法完成安装:$envARCHFLAGS='-archx86_64'geminstallpg--\--with-pg-config=/opt/local/var/db/postgresql90/defaultdb/po

随机推荐