2015-03-08 42 views
0

如何解決這個錯誤:編譯例如,mesh.c半自助旅遊旅行社

undefined reference to button sensor 

在半自助旅遊旅行社使用Micaz微塵編譯example-mesh.c什麼時候?

這裏是我的代碼我在mote輸出窗口中運行模擬只有3條消息發送,其餘是「數據包超時」我怎麼能解決這個問題發送消息基於定時器的價值?

#include "contiki.h" 
 
#include "net/rime.h" 
 
#include "net/rime/mesh.h" 
 

 
#include "contiki-conf.h" 
 
#include "sys/etimer.h" 
 
#include "sys/process.h" 
 
#include "sys/ctimer.h" 
 

 

 
#include "dev/leds.h" 
 

 
#include <stdio.h> 
 
#include <string.h> 
 

 

 
#define MESSAGE "Hello" 
 

 
static struct mesh_conn mesh; 
 
/*---------------------------------------------------------------------------*/ 
 
PROCESS(example_mesh_process, "Mesh example"); 
 
AUTOSTART_PROCESSES(&example_mesh_process); 
 
/*---------------------------------------------------------------------------*/ 
 
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", 
 
\t from->u8[0], from->u8[1], 
 
\t packetbuf_datalen(), (char *)packetbuf_dataptr(), packetbuf_datalen()); 
 

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

 
const static struct mesh_callbacks callbacks = {recv, sent, timedout}; 
 
/*---------------------------------------------------------------------------*/ 
 
PROCESS_THREAD(example_mesh_process, ev, data) 
 
{ 
 

 
    static struct etimer et; 
 

 
    PROCESS_EXITHANDLER(mesh_close(&mesh);) 
 

 
    PROCESS_BEGIN(); 
 

 
    mesh_open(&mesh, 132, &callbacks); 
 

 
    
 

 
    while(1) { 
 
    rimeaddr_t addr; 
 
etimer_set(&et, 5 * CLOCK_SECOND); 
 
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); 
 
etimer_reset(&et); 
 

 
    
 
    /* Send a message to node number 1. */ 
 
    
 
    packetbuf_copyfrom(MESSAGE, strlen(MESSAGE)); 
 
    addr.u8[0] = 1; 
 
    addr.u8[1] = 0; 
 
    mesh_send(&mesh, &addr); 
 
} 
 
    PROCESS_END(); 
 
} 
 
/*---------------------------------------------------------------------------*/

+0

歡迎來到StackOverflow!你的問題中的兩個句子基本上具有相同的內容,但作爲讀者,我仍然只對你想要做什麼以及什麼是問題有一個粗略的概念。你可能想用更多的信息來更新你的問題,但是一定要先閱讀[如何提出一個好問題](http://stackoverflow.com/help/how-to-ask)。 – 2015-03-08 19:15:35

+0

並非所有Contiki應用程序都適用於所有平臺。你真的需要使用'micaz'嗎?這是古老的。 – kfx 2015-03-08 19:21:06

+0

是的,我需要模擬使用Micaz,但是編譯時給我一個編譯錯誤「underfined button_sensor」我該如何克服這個問題@kfx – 2015-03-08 22:11:48

回答

0

據我知道Micaz微塵不具有一個按鈕,因此參照button_sensor傳感器無效。

該示例旨在每次按下按鈕時發送消息,因此如果您希望此示例正常工作,則需要重寫示例以基於定時器值發送消息。

+0

如何重寫基於定時器值發送消息的示例? @Johan Bregell – 2015-03-11 02:21:26

+0

刪除鏈接到按鈕傳感器的代碼,例如行#44和#90。 然後,我會查看_examples/ipv6/simple-udp-rpl/broadcast-example.c_文件以瞭解如何執行定期事件。 @AmrMagdy – 2015-03-11 08:31:32

+0

可否請您爲我寫,我寫了但它不起作用@Johan Bregell – 2015-03-13 15:20:08

0

這就是我要寫的。但是,此節點依賴於需要接受消息的另一個節點!

#include "contiki.h" 
#include "net/rime.h" 
#include "net/rime/mesh.h" 

#include <stdio.h> 
#include <string.h> 


#define MESSAGE "Hello" 

static struct mesh_conn mesh; 
/*---------------------------------------------------------------------------*/ 
PROCESS(example_mesh_process, "Mesh example"); 
AUTOSTART_PROCESSES(&example_mesh_process); 
/*---------------------------------------------------------------------------*/ 
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); 
} 

const static struct mesh_callbacks callbacks = {recv, sent, timedout}; 
/*---------------------------------------------------------------------------*/ 
PROCESS_THREAD(example_mesh_process, ev, data) 
{ 
    static struct etimer et; 

    PROCESS_EXITHANDLER(mesh_close(&mesh);) 
    PROCESS_BEGIN(); 

    mesh_open(&mesh, 132, &callbacks); 

    while(1) { 
    linkaddr_t addr; 
    etimer_set(&et, 5 * CLOCK_SECOND); 
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); 

    /* Send a message to node number 1. */ 

    packetbuf_copyfrom(MESSAGE, strlen(MESSAGE)); 
    addr.u8[0] = 1; 
    addr.u8[1] = 0; 
    mesh_send(&mesh, &addr); 
    } 
    PROCESS_END(); 
} 
/*---------------------------------------------------------------------------*/ 
+0

使用該代碼後,它仍然沒有工作mote輸出窗口給我「數據包超時」@Johan Bregell – 2015-03-19 00:23:06

+0

所以喲你顯然正在等待上帝爲你解決這個問題!但爲了幫助您,我需要了解您的節點設置和網絡配置! – 2015-03-19 08:04:50

+0

如何獲取節點設置和網絡配置@Johan Bregell – 2015-03-19 14:58:22