I think there are a few things wrong, but take it all with a grain'o'salt...
The problem that you actually describe can probably be easily fixed
with a cast. Since packet_ptr is a TOS_MSG* and bufferPtr is an int*:
packet_ptr = (TOS_MsgPtr) bufferPtr;
However...that ain't gonna fix what you really want fixed...
First, you never set bufferPtr to point to anything.
But you do have this assignment:
bufferPtr[p] = this_data;
which will just crash because bufferPtr is not initialized and
is probably 0 and trying to set integer #p, counting from address
zero will usually do bad things. (For the full explanation look
up arrays in a C programming book).
What you want to do is something like this:
int buf[100]; // or whatever length you want,
// this is the actual storage buffer
bufferPtr = buf; // now bufferPtr points to the beginning of buf
Then you can do your assignment as above which will put "this_data"
into integer location "p" in buf. In fact these two constructs will
be equivalent:
buf[p] = data;
bufferPtr[p] = data;
and even, for extra credit:
bufferPtr+p = data;
Further, given the structure of your program, I don't think you ever want
to change bufferPtr, so you could just use buf everywhere and eliminate
a variable complication.
Second, when sending the message, what you want to do is stick the buffered
integers into the "data" portion of the TOS_Msg packet. Not make it the
whole message, which is what you do in the offending line:
packet_ptr = bufferPtr;
Instead do something like this. Copy your integers into TOS_Msg.data:
memcpy( packet_ptr->data, bufferPtr, sizeof(Tos_Msg.data) );
--I can't remember the order of the arguments off hand, or if that
sizeof thing actually gives the number of bytes in the message data
field, and you want the number of bytes actually used in your buffer
not the data length anyway, so you will need to do a little double
thinking -- better you than me...
Then you can call:
call SendMsg.send( TOS_BCAST_ADDR, maxdata, packet_ptr );
Well, except that I think your "maxdata" is a count of integers and
the send() function wants a count of bytes, so some multiplication
is probably in order. And you need to set the msg.type as well...
And while rummaging around, it appears that you reset packet_ptr
in sendDone() for no good reason: packet_ptr = msg;
It probably works ok because msg is probably the original
TOS_Msg packet; that you started with, but it's more variable foo
than necessary I think.
You should look at the Oscilloscope apps for an example of doing
the data aggregation you want. You've got a couple extra layers of
code and you may need a double buffer scheme like O'scope.
see what happens when I am avoiding useful work?
MS
Gary Pan wrote:
I am using mda300 and micaz. I want to store the sampling data from one
of the analog channels to a small buffer, then send them at once.
I followed the example from tinyos tutorial 8 Data logging application.
Instead of calling LoggerWrite.append in task writeTask(), I use
SendMsg.send command. I think I have the interfaces wire thing correct.
But I got warning message when I compile the code: */assignment from the
incompatible pointer type/* since I revised the task as following
task void send_radio_msg()
{
packet_ptr = bufferPtr;
call SendMsg.send( TOS_BCAST_ADDR, maxdata, packet_ptr );
}
But I don't how to fix the problem and I did not receive any data. But
the Leds was blinking which means is sampling the channel. It seems that
it posting task uncorrectly.
I post my code below. Please take a look and give me some advise. Thanks
includes sensorboard;
module RadioMDA300M
{
provides interface StdControl;
uses
{
interface Leds;
interface StdControl as SamplerControl;
interface Sample;
interface StdControl as CommControl;
interface SendMsg;
interface ReceiveMsg;
// MicaZ Platform Control
#ifdef PLATFORM_MICAZ
interface CC2420Control;
#endif
}
}
implementation
{
#define ANALOG_SAMPLING_TIME 1
#define DIGITAL_SAMPLING_TIME 100
#define MISC_SAMPLING_TIME 110
enum {
maxdata = 8 // buffer size
};
// declare module static variables here
char head; // index to the head of the circular buffer
int *bufferPtr;
int i;
// Message Buffers
TOS_Msg packet;
TOS_MsgPtr packet_ptr;
/* **********************************************************
* COMMANDS Command to initialize the component
* *********************************************************/
command result_t StdControl.init()
{
// Initialize the Leds, Radio, and Sampler
call Leds.init();
call CommControl.init();
call SamplerControl.init();
atomic
{
// Set pointer to the TOS message
packet_ptr = &packet;
head = 0;
}
return SUCCESS;
}
// Command to start the component and clock
// Also setup timer and sampling
command result_t StdControl.start()
{
// Start the Radio and Sampler
call CommControl.start();
call SamplerControl.start();
// Set the MicaZ radio strength
#ifdef PLATFORM_MICAZ
call CC2420Control.SetRFPower(15);
#endif
call
Sample.getSample(1,ANALOG,ANALOG_SAMPLING_TIME,SAMPLER_DEFAULT |
EXCITATION_25);
call Leds.greenOn(); // Turn on the green Led - READY
return SUCCESS;
}
// Command to stop the component
command result_t StdControl.stop()
{
call SamplerControl.stop();
// call CommControl.stop();
return SUCCESS;
}
/* **********************************************************
* TASKS Task to send Radio message
* *********************************************************/
task void send_radio_msg()
{
packet_ptr = bufferPtr;
call SendMsg.send( TOS_BCAST_ADDR, maxdata, packet_ptr );
}
/* **********************************************************
* EVENTS // Event for Radio message transmittion completed
* *********************************************************/
event result_t SendMsg.sendDone( TOS_MsgPtr msg, result_t success )
{
packet_ptr = msg;
call Leds.yellowOff(); // Turn off the yellow Led - RADIO SEND DONE
return SUCCESS;
}
// Event for Radio message received --> NO HANDLING
event TOS_MsgPtr ReceiveMsg.receive( TOS_MsgPtr data )
{ return data; }
/* **********************************************************
* SAMPLING DATAREADY EVENT
* *********************************************************/
event result_t Sample.dataReady(uint8_t channel,uint8_t
channelType,uint16_t this_data){
atomic {
int p = head;
switch ( channel )
{
case 1:
bufferPtr[p] = this_data;
call Leds.redToggle();
break;
// case 2:
// bufferPtr[p] = this_data;
// call Leds.yellowToggle();
// break;
// case 3:
// bufferPtr[p] = this_data;
// call Leds.redToggle();
// break;
// case 7:
// bufferPtr[p] = this_data;
// call Leds.yellowToggle();
// break;
default:
break;
}
if (i==1) { call Sample.stop(0); }
else { i--; }
head = (p+1);
if (head == maxdata) head = 0;
if (head == 0) { post send_radio_msg(); }
}
return SUCCESS;
}
}
------------------------------------------------------------------------
Don't be flakey. Get Yahoo! Mail for Mobile
<http://us.rd.yahoo.com/evt=43909/*http://mobile.yahoo.com/mail> and
always stay connected
<http://us.rd.yahoo.com/evt=43909/*http://mobile.yahoo.com/mail> to
friends.
------------------------------------------------------------------------
_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help