1

我正在尝试使用 Rime 和 REST 创建一个充当网关的 ContikiOS 固件。网关必须通过 Rime 网格与其他微尘通信,并且可以通过 REST API 与外部通信。

以下代码是两个默认 Contiki 示例(rest-example/rest-server-example.c 和 rime/example-mesh.c)的组合。因此我包括“rest.h”、“net/rime.h”、“net/rime/mesh.h”。

问题是当我尝试使用以下 makefile 编译此固件时,rime 文件不会包含在 obj_sky 中,并且我在固件中使用的任何 Rime 函数都会出现“未定义引用”错误。但是,当我删除 makefile 中的行和固件代码中引用 REST 的任何代码时,它会编译(并将 rime 文件添加到 obj_sky)。

有没有人知道为什么在添加 rest-http 应用程序后没有添加 rime 以及我可以做些什么来编译它?

谢谢

代码

编译器信息

> make gateway.sky TARGET=sky 
  CC        gateway.c
  CC        ../../platform/sky/./contiki-sky-main.c
  LD        gateway.sky
/usr/lib/gcc/msp430/4.6.3/../../../../msp430/bin/ld: gateway.sky section `.data' will not fit in region `rom'
/usr/lib/gcc/msp430/4.6.3/../../../../msp430/bin/ld: section .vectors loaded at [000000000000ffe0,000000000000ffff] overlaps section .data loaded at [000000000000ff0c,0000000000010037]
/usr/lib/gcc/msp430/4.6.3/../../../../msp430/bin/ld: region `rom' overflowed by 88 bytes
gateway.co: In function `process_thread_init_mesh':
gateway.c:(.text.process_thread_init_mesh+0x10): undefined reference to `mesh_close'
gateway.c:(.text.process_thread_init_mesh+0x26): undefined reference to `mesh_open'
gateway.co: In function `recv':
gateway.c:(.text.recv+0x48): undefined reference to `mesh_send'
gateway.co: In function `enable_handler':
gateway.c:(.text.enable_handler+0x80): undefined reference to `mesh_send'
collect2: ld returned 1 exit status
../../Makefile.include:254: recipe for target 'gateway.sky' failed
Process returned error code 2
make: *** [gateway.sky] Error 1
rm obj_sky/contiki-sky-main.o gateway.co

生成文件

all: gateway mote

ifndef TARGET
TARGET=sky
endif

CONTIKI=../..


WITH_UIP6=1
UIP_CONF_IPV6=1

WITH_COAP = 0

APPS += rest-http

include $(CONTIKI)/Makefile.include

为 REST 编译的行

WITH_UIP6=1
UIP_CONF_IPV6=1

WITH_COAP = 0

APPS += rest-http

网关.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "contiki.h"
#include "contiki-net.h"
#include "rest.h"
#include "net/rime.h"
#include "net/rime/mesh.h"

#if defined (PLATFORM_HAS_LIGHT)
#include "dev/light-sensor.h"
#endif
#if defined (PLATFORM_HAS_BATT)
#include "dev/battery-sensor.h"
#endif
#if defined (PLATFORM_HAS_SHT11)
#include "dev/sht11-sensor.h"
#endif
#if defined (PLATFORM_HAS_LEDS)
#include "dev/leds.h"
#endif

#define DEBUG 1
#if DEBUG
#include <stdio.h>
#define PRINTF(...) printf(__VA_ARGS__)
#define PRINT6ADDR(addr) PRINTF(" %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x ", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_t *)addr)[15])
#define PRINTLLADDR(lladdr) PRINTF(" %02x:%02x:%02x:%02x:%02x:%02x ",(lladdr)->addr[0], (lladdr)->addr[1], (lladdr)->addr[2], (lladdr)->addr[3],(lladdr)->addr[4], (lladdr)->addr[5])
#else
#define PRINTF(...)
#define PRINT6ADDR(addr)
#define PRINTLLADDR(addr)
#endif

#define MESSAGE "Hello"

/*---------------------------------------------------------------------------*/
/*---------------------------------RIME--------------------------------------*/
/*---------------------------------------------------------------------------*/
static struct mesh_conn mesh;

PROCESS(init_mesh, "RIME Mesh");

/*---------------------------------------------------------------------------*/
static void
sent(struct mesh_conn *c)
{
  printf("packet sent\n");
}

static void
timedout(struct mesh_conn *c)
{
  printf("packet timedout\n");
}

static void
recv(struct mesh_conn *c, const rimeaddr_t *from, uint8_t hops)
{
  printf("Data received from %d.%d: %.*s (%d)\n",
     from->u8[0], from->u8[1],
     packetbuf_datalen(), (char *)packetbuf_dataptr(), packetbuf_datalen());

  packetbuf_copyfrom(MESSAGE, strlen(MESSAGE));
  mesh_send(&mesh, from);
}

static void
send(int to, char * msg)
{
    printf("Sending data to %d", to);
    rimeaddr_t addr;
    packetbuf_copyfrom(msg, strlen(msg));
    addr.u8[0] = to;
    addr.u8[1] = 0;
    mesh_send(&mesh, &addr);
}

const static struct mesh_callbacks callbacks = {recv, sent, timedout};
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(init_mesh, ev, data)
{
  PROCESS_EXITHANDLER(mesh_close(&mesh);)
  PROCESS_BEGIN();

  mesh_open(&mesh, 132, &callbacks);
  PROCESS_END();
}
/*---------------------------------------------------------------------------*/
/*----------------------------------REST-------------------------------------*/
/*---------------------------------------------------------------------------*/
RESOURCE(enable, METHOD_GET, "enable");
void
enable_handler(REQUEST* request, RESPONSE* response)
{
    int moteId = 0;
    char moteIdstr[12];
    sprintf(moteIdstr, "%d", moteId);
    char command[20];
    char responseText[255];

    if (rest_get_query_variable(request, "moteId", moteIdstr, 10)) {
    PRINTF("moteId %s\n", moteIdstr);


        send(moteId, command);


        sprintf(responseText,"Command execute for mote %s!\n", moteIdstr);
  } else {
    sprintf(responseText,"Mote not available!\n");
  }


  rest_set_header_content_type(response, TEXT_PLAIN);
  rest_set_response_payload(response, (uint8_t*)responseText, strlen(responseText));
}

PROCESS(gateway_rest, "Gateway Rest");
PROCESS_THREAD(gateway_rest, ev, data)
{
  PROCESS_BEGIN();

#ifdef WITH_COAP
  PRINTF("COAP Server\n");
#else
  PRINTF("HTTP Server\n");
#endif

  rest_init();

  rest_activate_resource(&resource_enable);
  //rest_activate_resource(&resource_disable);

  PROCESS_END();
}

/*---------------*/
AUTOSTART_PROCESSES(&init_mesh, &gateway_rest);

信息

我正在使用 Sky motes 在 Cooja 中编译代码。

4

0 回答 0