[Tinyos-help] a strange error
Michiel Konstapel
m.konstapel at sownet.nl
Tue Mar 11 06:45:26 PDT 2008
In ANSI C, you are only allowed to declare local variables at the start of a block, right after an opening curly brace.
So,
...
{
int a;
<statement>
}
is valid, and
...
{
<statement>
int a;
}
is not.
That means that you'll either have to move the statement "Counter++" down:
...
else {
radio_test_msg_t* rcm = (radio_test_msg_t*)call Packet.getPayload(&packet, NULL);
Counter++;
...
or declare your variable first, followed by the statements in the original order:
...
else {
radio_test_msg_t* rcm;
Counter++;
rcm = (radio_test_msg_t*)call Packet.getPayload(&packet, NULL);
...
Regards,
Michiel
-----Original Message-----
From: tinyos-help-bounces at millennium.berkeley.edu on behalf of weiping SONG
Sent: Tue 3/11/2008 1:32 PM
To: tinyos-help at millennium.berkeley.edu
Subject: [Tinyos-help] a strange error
Hi all,
I faced a strange error this morning as following:
I could not compile my TestRadioAppC.nc if I put "Counter++;" before
radio_test_mag_t in TestRadioC.nc...
---------------------------------------------------------------------
event void TimerRadio.fired() {
// Counter++;
if (locked) {
return;
}
else {
Counter++;
radio_test_msg_t* rcm = (radio_test_msg_t*)call Packet.getPayload(&packet, NULL);
if (call Packet.maxPayloadLength() < sizeof(radio_test_msg_t)) {
return;
}
rcm->voltage = InVoltage;
rcm->count = Counter;
rcm->temp = 0;
if (call AMSend.send(AM_BROADCAST_ADDR, &packet, sizeof(radio_test_msg_t)) == SUCCESS) {
locked = TRUE;
}
}
}
----------------------------------------------------------------------------------------------------------
[realtime at m1-02 TestRadio]$ make telosb
mkdir -p build/telosb
compiling TestRadioAppC to a telosb binary
ncc -o build/telosb/main.exe -Os -O -mdisable-hwmul -Wall -Wshadow -DDEF_TOS_AM_GROUP=0x7d -Wnesc-all -target=telosb -fnesc-cfile=build/telosb/app.c -board= -DIDENT_PROGRAM_NAME=\"TestRadioAppC\" -DIDENT_USER_ID=\"realtime\" -DIDENT_HOSTNAME=\"m1-02.ucc.ie\" -DIDENT_USER_HASH=0x69427c28L -DIDENT_UNIX_TIME=0x47d67976L -DIDENT_UID_HASH=0xc8fd72abL TestRadioAppC.nc -lm
In file included from TestRadioAppC.nc:13:
In component `TestRadioC':
TestRadioC.nc: In function `TimerRadio.fired':
TestRadioC.nc:47: syntax error before `*'
TestRadioC.nc:52: `rcm' undeclared (first use in this function)
TestRadioC.nc:52: (Each undeclared identifier is reported only once
TestRadioC.nc:52: for each function it appears in.)
make: *** [exe0] Error 1
[realtime at m1-02 TestRadio]$
----------------------------------------------------------------------------------------------------------------------------------
But it worked well if I put "Counter++;" in the first line of the event.
I do not understand why, can some one help me?
Regards,
Weiping Song
_______________________________________________
Tinyos-help mailing list
Tinyos-help at millennium.berkeley.edu
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://www.millennium.berkeley.edu/pipermail/tinyos-help/attachments/20080311/f4e39f6a/attachment-0001.html
More information about the Tinyos-help
mailing list