小编Par*_*des的帖子

如何在Contiki OS中的运行时执行其他二进制文件?

我试图制作一个在Contiki OS上运行的传感器,以执行新的二进制文件并替换当前的二进制文件(如果发生事件)。

我正在使用Cooja模拟器和Sky note,并且将二进制文件上传到节点的Coffee文件系统中(使用Cooja脚本),我想执行hello-world.ce

要编译我将动态加载模块的当前程序(reboot.c),我使用了以下命令:

  1. 使TARGET =天空干净CLEAN =符号。
  2. 使reboot.sky TARGET = sky
  3. 使CORE = reboot.sky TARGET = sky reboot.sky

对于将要加载的hello-world,我使用了:

  1. 使TARGET = sky hello-world.ce

这是我试图执行hello-world的代码(reboot.c)的一部分

#include "contiki.h"
#include "core/loader/elfloader.h"
#include "cfs/cfs.h"

PROCESS(hello_world_process, "Reboot process");
AUTOSTART_PROCESSES(&hello_world_process);
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(hello_world_process, ev, data)
{
    PROCESS_BEGIN();

    int i;
    int binFile,ret;

    elfloader_init();

    binFile=cfs_open("hello-world.ce",CFS_READ);
    printf("cfs_open:%d\n",binFile); //returns 0 so the file is opened

    ret=elfloader_load(binFile);
    cfs_close(binFile);
    printf("loader returned: %d\n",ret); //returns 0 ->meaning everything is ok

    if(ret == ELFLOADER_OK){
        printf("elf OK\n");
        for(i=0; elfloader_autostart_processes[i] != NULL; i++) {
            printf("exec: starting process …
Run Code Online (Sandbox Code Playgroud)

c elf contiki

9
推荐指数
1
解决办法
169
查看次数

标签 统计

c ×1

contiki ×1

elf ×1