初识canopen的实现CanFestival

编译CanFestival
zengming@jyxtec:~/下载/CanFestival-3-1936110171a2> ./configure --cc=arm-linux-gcc --arch=arm  --os=unix --kerneldir=$HOME/workspace/s3c-linux --prefix=$PWD/myinstall --target=unix --can=socket --timers=unix --debug=WAR,MSG
Host OS: unix
Host arch: arm
Using arm-linux-gcc as a C compiler
Using arm-linux-g++ as a C++ compiler
Using arm-linux-g++ as a linker
Using prefix: /home/zengming/下载/CanFestival-3-1936110171a2/myinstall
No wxWidgets available
Creating Makefile
Creating src/Makefile
Creating drivers/Makefile
Creating objdictgen/Makefile
Creating examples/Makefile
Creating objdictgen/canfestival_config.py
Creating drivers/timers_unix/Makefile
Creating drivers/can_socket/Makefile
Creating drivers/unix/Makefile
Creating examples/CANOpenShell/Makefile
Creating examples/TestMasterSlave/Makefile
Creating examples/TestMasterSlaveLSS/Makefile
Creating examples/SillySlave/Makefile
Creating examples/TestMasterMicroMod/Makefile
Creating examples/test_copcican_linux/Makefile
All done.

上面提示 No wxWidgets available,需要安装
python-wxWidgets-2_9-devel
python-wxWidgets-2_9

再编译
$ make
$ make install
make: ldconfig:命令未找到
make: *** [install] 错误 127
出错了,但是ldconfig确实存在,解决方法:
$ sudo make install
会安装到myinstall中

SDO
    if(useBlockMode) {
        initSDOline(d, line, transNodeId, index, subIndex, SDO_BLOCK_DOWNLOAD_IN_PROGRESS);
        d->transfers[line].objsize = count; // 总大小
    }
    else 
        initSDOline(d, line, transNodeId, index, subIndex, SDO_DOWNLOAD_IN_PROGRESS);
    d->transfers[line].count = count;

SDO_DYNAMIC_BUFFER_ALLOCATION 不开这个宏的话,如果count大于SDO_MAX_LENGTH_TRANSFER,就会溢出,默认是32

SDO_MAX_SIMULTANEOUS_TRANSFERS 限定最大的line数,且不可超过255,因为程序中有循环且下标类型为UNS8(这个是无符号的),默认是4
另外还有一个设置会影响数据流通量,那就是timer的最大值,每一个传输通道都会占用一个timer,默认为32,其应该大于等于line数

initSDOline()
{
    if (state == SDO_DOWNLOAD_IN_PROGRESS       || state == SDO_UPLOAD_IN_PROGRESS ||
        state == SDO_BLOCK_DOWNLOAD_IN_PROGRESS || state == SDO_BLOCK_UPLOAD_IN_PROGRESS){
        StartSDO_TIMER(line)
    }else{
        StopSDO_TIMER(line)
    }
}

在_writeNetworkDict中会调用StartSDO_TIMER(line),
启动相应的timer,并返回这个timer在timers的下标
d->transfers[id].timer = SetAlarm(d,id,&SDOTimeoutAlarm,MS_TO_TIMEVAL(SDO_TIMEOUT_MS),0);  /* SDO_TIMEOUT_MS 默认为3000毫秒 */
如果超时对方无响应,则发送结束信息并结束传输,如果对方
收到对方回复SDO_BSS_INITIATE_DOWNLOAD_RESPONSE 或者SDO_BSS_DOWNLOAD_RESPONSE,会RestartSDO_TIMER(line)
如果是SDO_BSS_INITIATE_DOWNLOAD_RESPONSE 则发送一个block的数据

TimerInit()
    timer_create  
        每段时间调用TimeDispatch(),此函数功能是遍历timers,如果有超时的,就调用相应的call, 这些timers是由SetAlarm()函数来设定的
        IMER_HANDLE SetAlarm(CO_Data* d, UNS32 id, TimerCallback_t callback, TIMEVAL value, TIMEVAL period);

canOpen()
    CreateReceiveTask(&(canports[i]), &canports[i].receiveTask, &canReceiveLoop); 创建一线程,不断读取canbus的数据,然后处理
StartTimerLoop(&Init);
作者:帅得不敢出门 程序员群:31843264

你可能感兴趣的:(初识canopen的实现CanFestival)