创建数据包时编译错误 [英] Compile error when creating packet
问题描述
我学习 本 作为TinyOS的教程中,我想尝试一下。我尝试创建包,但它给了我下面的错误。我不知道什么是错。这可能是简单的东西,但我无法弄清楚它是什么。
的#includeTestMsg.h
...
事件无效AMControl.startDone(error_t错误){
如果(错误== SUCCESS){
调用Leds.led0On(); //创建包
TestMsg_t *味精=调用Packet.getPayload(安培;包,的sizeof(TestMsg_t));
msg->节点ID = TOS_NODE_ID;
//
// // TODO在其间这个可以改变
// button_state_t VAL =调用Get.get();
// msg->数据=(VAL == BUTTON_ preSSED?1:0);
//
// //发送数据包
//如果(调用AMSend.send(AM_BROADCAST_ADDR,&安培;包,的sizeof(TestMsg_t))== SUCCESS){
// radioBusy = TRUE;
//}
}其他{
调用AMControl.start();
}
}
...
下面是 TestMsg.h
的#ifndef TEST_MSG_H
#定义TEST_MSG_H的typedef nx_struct _TestMsg {
nx_uint16_t节点ID;
nx_uint8_t数据;
} TestMsg_t;枚举{
AM_RADIO = 6
};#ENDIF / * * TEST_MSG_H /
这里 是它在视频中声明的一部分
错误我明白了这一点:
在文件从/home/advanticsys/ws/TestRadio/src/TestRadioAppC.nc:5包括:
在组件`TestRadioC:
/home/advanticsys/ws/TestRadio/src/TestRadioC.nc:在功能`AMControl.startDone:
/home/advanticsys/ws/TestRadio/src/TestRadioC.nc:43:语法错误之前,'*'
/home/advanticsys/ws/TestRadio/src/TestRadioC.nc:44:'味精'未申报(在一次使用此功能)
/home/advanticsys/ws/TestRadio/src/TestRadioC.nc:44:(每个未声明的标识符报道只有一次
/home/advanticsys/ws/TestRadio/src/TestRadioC.nc:44:每个功能它出现在)。
更新
东西是错的结构和头文件。
的#includeSzar.h
#包括BarType.h模块SzarP {
使用界面引导;
使用接口指示灯;
}实施{ 事件无效Boot.booted(){
// TODO自动生成方法存根
调用Leds.led0On(); Szar_t富;
Szar_t * szar =安培; foo的; BarType_t barVar;
barVar.data = 0;
BarType_t * pBarVar =安培; barVar;
pBarVar->数据= 1; }
}
下面是2头文件。
的#ifndef SZAR_H
#定义SZAR_H的typedef nx_struct _Szar {
nx_uint8_t szar1;
nx_uint16_t szar2;
} Szar_t;#ENDIF / * * SZAR_H /
的#ifndef BAR_TYPE_H
#定义BAR_TYPE_Htypedef结构_BarType {
uint8_t有ID;
uint32_t的数据;
} BarType_t;#ENDIF / * * BAR_TYPE_H /
和错误:
在文件从/home/advanticsys/ws/Szar/src/SzarAppC.nc:6包括:
在组件`SzarP:
/home/advanticsys/ws/Szar/src/SzarP.nc:在功能`Boot.booted:
/home/advanticsys/ws/Szar/src/SzarP.nc:15:'富'之前,语法错误
/home/advanticsys/ws/Szar/src/SzarP.nc:19:`barVar'未申报(在一次使用此功能)
/home/advanticsys/ws/Szar/src/SzarP.nc:19:(每个未声明的标识符报道只有一次
/home/advanticsys/ws/Szar/src/SzarP.nc:19:每个功能它出现在)。
/home/advanticsys/ws/Szar/src/SzarP.nc:20:语法错误之前,'*'
/home/advanticsys/ws/Szar/src/SzarP.nc:21:`pBarVar'未申报(在一次使用此功能)
由于一些奇怪的原因,我必须声明函数外的每个变量,然后它的作品。例如:
布尔radioBusy = FALSE;
message_t包;
TestMsg_t * messageToSend;
button_state_t buttonState;事件无效AMControl.startDone(error_t错误){
如果(错误== SUCCESS){
调用Leds.led0On(); messageToSend =调用Packet.getPayload(安培;包,的sizeof(TestMsg_t));
messageToSend->节点ID = TOS_NODE_ID; // TODO在此期间,这可以改变
buttonState =调用Get.get();
messageToSend->数据=(buttonState == BUTTON_ preSSED?1:0); //发送数据包
如果(调用AMSend.send(AM_BROADCAST_ADDR,&安培;包,的sizeof(TestMsg_t))== SUCCESS){
radioBusy = TRUE;
}
}其他{
调用AMControl.start();
}
}
它还如果我声明我在函数/事件/命令年初变量,而他们之前任何code工作。
I'm studying THIS tutorial for tinyos and I wanted to try it out. I try to create the packet but it gives me the following error. I don't know what's wrong. It is probably something simple but I can't figure out what it is.
#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();
}
}
...
Here is 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 is the part where it is declared in the video
The error I get it this:
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.)
Update
Something is wrong with structs and headers.
#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;
}
}
Here are the 2 header files.
#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 */
And the errors:
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)
For some strange reason I have to declare EVERY variable outside the function, and then it works. Example:
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();
}
}
It also works if I declare my variables at the beginning of the functions/events/commands without any code before them.
这篇关于创建数据包时编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!