gpt4 book ai didi

创建数据包时编译错误

转载 作者:行者123 更新时间:2023-11-30 17:38:09 25 4
gpt4 key购买 nike

我正在学习 THIS tinyos 教程,我想尝试一下。我尝试创建数据包,但出现以下错误。我不知道出了什么问题。这可能很简单,但我不知道它是什么。

#include "TestMsg.h"
...
event void AMControl.startDone(error_t error) {
if (error == SUCCESS) {
call Leds.led0On();

//create packet
TestMsg_t* msg = call Packet.getPayload(&packet, sizeof(TestMsg_t));
msg->NodeID = TOS_NODE_ID;
//
// //TODO in the meantime this can change
// button_state_t val = call Get.get();
// msg->Data = ( val == BUTTON_PRESSED ? 1 : 0 );
//
// //send packet
// if (call AMSend.send(AM_BROADCAST_ADDR, &packet, sizeof(TestMsg_t)) == SUCCESS) {
// radioBusy = TRUE;
// }
} else {
call AMControl.start();
}
}
...

这里是TestMsg.h

#ifndef TEST_MSG_H
#define TEST_MSG_H

typedef nx_struct _TestMsg {
nx_uint16_t NodeID;
nx_uint8_t Data;
} TestMsg_t;

enum {
AM_RADIO = 6
};

#endif /* TEST_MSG_H */

Here是视频中声明的部分

我得到的错误是这样的:

In file included from /home/advanticsys/ws/TestRadio/src/TestRadioAppC.nc:5:
In component `TestRadioC':
/home/advanticsys/ws/TestRadio/src/TestRadioC.nc: In function `AMControl.startDone':
/home/advanticsys/ws/TestRadio/src/TestRadioC.nc:43: syntax error before `*'
/home/advanticsys/ws/TestRadio/src/TestRadioC.nc:44: `msg' undeclared (first use in this function)
/home/advanticsys/ws/TestRadio/src/TestRadioC.nc:44: (Each undeclared identifier is reported only once
/home/advanticsys/ws/TestRadio/src/TestRadioC.nc:44: for each function it appears in.)

更新

结构和 header 有问题。

#include "Szar.h"
#include "BarType.h"

module SzarP {
uses interface Boot;
uses interface Leds;
}

implementation {

event void Boot.booted() {
// TODO Auto-generated method stub
call Leds.led0On();

Szar_t foo;
Szar_t *szar = &foo;

BarType_t barVar;
barVar.data = 0;
BarType_t *pBarVar = &barVar;
pBarVar->data = 1;

}
}

这是 2 个头文件。

#ifndef SZAR_H
#define SZAR_H

typedef nx_struct _Szar {
nx_uint8_t szar1;
nx_uint16_t szar2;
} Szar_t;

#endif /* SZAR_H */


#ifndef BAR_TYPE_H
#define BAR_TYPE_H

typedef struct _BarType {
uint8_t id;
uint32_t data;
} BarType_t;

#endif /* BAR_TYPE_H */

以及错误:

In file included from /home/advanticsys/ws/Szar/src/SzarAppC.nc:6:
In component `SzarP':
/home/advanticsys/ws/Szar/src/SzarP.nc: In function `Boot.booted':
/home/advanticsys/ws/Szar/src/SzarP.nc:15: syntax error before `foo'
/home/advanticsys/ws/Szar/src/SzarP.nc:19: `barVar' undeclared (first use in this function)
/home/advanticsys/ws/Szar/src/SzarP.nc:19: (Each undeclared identifier is reported only once
/home/advanticsys/ws/Szar/src/SzarP.nc:19: for each function it appears in.)
/home/advanticsys/ws/Szar/src/SzarP.nc:20: syntax error before `*'
/home/advanticsys/ws/Szar/src/SzarP.nc:21: `pBarVar' undeclared (first use in this function)

最佳答案

出于某种奇怪的原因,我必须在函数外部声明每个变量,然后它才能起作用。示例:

bool radioBusy = FALSE;
message_t packet;
TestMsg_t *messageToSend;
button_state_t buttonState;

event void AMControl.startDone(error_t error) {
if (error == SUCCESS) {
call Leds.led0On();

messageToSend = call Packet.getPayload(&packet, sizeof(TestMsg_t));
messageToSend->NodeID = TOS_NODE_ID;

//TODO in the meantime this can change
buttonState = call Get.get();
messageToSend->Data = ( buttonState == BUTTON_PRESSED ? 1 : 0 );

//send packet
if (call AMSend.send(AM_BROADCAST_ADDR, &packet, sizeof(TestMsg_t)) == SUCCESS) {
radioBusy = TRUE;
}
} else {
call AMControl.start();
}
}

如果我在函数/事件/命令的开头声明变量,并且前面没有任何代码,它也可以工作。

关于创建数据包时编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22200635/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com