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 and
always stay connected to friends.
_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help