Just in case some of you need more information on the program i have written
for the sampling, I have posted my code as belows:
Sensor.nc
------------------------------------
includes sensorboardApp;
configuration Sensor {
// this module does not provide any interface
}
implementation
{
components Main, SensorM, LedsC, TimerC, MicC, LFlashC, GenericComm;
Main.StdControl -> SensorM;
Main.StdControl -> TimerC;
Main.StdControl -> GenericComm;
SensorM.MicControl -> MicC;
SensorM.Mic -> MicC;
SensorM.MicADC ->MicC;
//Wiring for flash
SensorM.LFlash -> LFlashC;
SensorM.ReceiveFetchMsg -> GenericComm.ReceiveMsg[86];
SensorM.SendFetchMsg -> GenericComm.SendMsg[87];
SensorM.Leds -> LedsC;
SensorM.Timer -> TimerC.Timer[unique("Timer")];
--------------------------------------------------------
SensorM.nc
--------------------------------------------------------
includes sensorboard;
module SensorM {
provides {
interface StdControl;
}
uses {
// Mic
interface StdControl as MicControl;
interface Mic;
interface ADC as MicADC;
//Flash
interface LFlash;
interface ReceiveMsg as ReceiveFetchMsg;
interface SendMsg as SendFetchMsg;
interface Timer;
interface Leds;
}
}
implementation {
enum { START, BUSY};
enum { SENSOR_ID = 0, PACKET_ID, NODE_ID=2, RSVD,
MIC = 10 };
#define MSG_LEN 6
#define TIMER_PERIOD 2
#define SLEEP_LENGTH 5000
norace uint8_t state;
uint8_t * pagePtr;
uint16_t page, index;
uint32_t count = 0;
TOS_Msg msg_buf_flash, fetch_msg;
TOS_MsgPtr msg_flash;
bool stop;
/****************************************************************************
* Task to write to flash
****************************************************************************/
task void write_flash_msg() {
msg_flash->data[SENSOR_ID] = SENSOR_BOARD_ID;
msg_flash->data[PACKET_ID] = 1;
msg_flash->data[NODE_ID] = TOS_LOCAL_ADDRESS;
msg_flash->data[RSVD] = 0;
msg_flash->addr = TOS_BCAST_ADDR;
msg_flash->type = 0;
msg_flash->length = MSG_LEN;
msg_flash->group = TOS_AM_GROUP;
atomic state = START;
call LFlash.log(msg_flash->data, MSG_LEN);
return;
}
/* **********************************************************
* TASKS
* *********************************************************/
task void sendPage(){
uint8_t amount;
amount = 256 - index;
if (256 - index > 29) amount = 6;
memcpy(fetch_msg.data,(pagePtr+index),amount);
call SendFetchMsg.send(TOS_BCAST_ADDR,amount,&fetch_msg);
}
task void sendEOF(){
// Send an error "message"
memset(fetch_msg.data,'?',6);
call SendFetchMsg.send(TOS_BCAST_ADDR,6,&fetch_msg);
}
/****************************************************************************
* Initialize the component.
****************************************************************************/
command result_t StdControl.init() {
atomic {
msg_flash = &msg_buf_flash;
}
// usart1 is also connected to external serial flash
// set usart1 lines to correct state
TOSH_MAKE_FLASH_OUT_OUTPUT(); //tx output
TOSH_MAKE_FLASH_CLK_OUTPUT(); //usart clk
call Leds.init();
call LFlash.init();
stop = FALSE;
call MicControl.init();
call Mic.muxSel(1); // Set the mux so that raw microhpone output is
selected
call Mic.gainAdjust(64); // Set the gain of the microphone.
return SUCCESS;
}
/****************************************************************************
* Start the component. Start the clock.
****************************************************************************/
command result_t StdControl.start()
{
atomic state = START;
call Timer.start(TIMER_ONE_SHOT, TIMER_PERIOD);
return SUCCESS;
}
/****************************************************************************
* Stop the component.
*
****************************************************************************/
command result_t StdControl.stop() {
return SUCCESS;
}
/****************************************************************************
* Measure Mic
****************************************************************************/
event result_t Timer.fired() {
uint8_t l_state;
call Leds.redToggle();
atomic l_state = state;
if (l_state==BUSY)
return SUCCESS; //don't overrun buffers
switch (l_state) {
case START:
atomic state = BUSY;
call MicControl.start();
call MicADC.getData(); // get Mic data
break;
case BUSY:
default:
break;
}
return SUCCESS;
}
/****************************************************************************
* MicroPhone ADC data ready
*****************************************************************************/
async event result_t MicADC.dataReady(uint16_t data) {
msg_flash->data[MIC] = data & 0xff;
msg_flash->data[MIC+1] = data >> 8;
post write_flash_msg();
return SUCCESS;
}
/* **********************************************************
* EVENTS
* *********************************************************/
event result_t SendFetchMsg.sendDone( TOS_MsgPtr sent, result_t rslt){
return SUCCESS;
}
event TOS_MsgPtr ReceiveFetchMsg.receive(TOS_MsgPtr m){
if (stop) return m;
//Extract the requested page from the message
memcpy(&page,m->data,2);
// If the requested page is 9999, clear flash
if (page == 9999)
{
// Turn on all LEDs - CLEARING FLASH
call Leds.yellowOn();
call Leds.redOn();
call Leds.greenOn();
call LFlash.clear();
stop = TRUE;
return m;
}
// Otherwise, retrieve the requested page from Flash
memcpy(&index,m->data+2,2);
call LFlash.get(page);
return m;
}
event void LFlash.clearDone(){
call Timer.start(TIMER_ONE_SHOT,TIMER_PERIOD);
}
/* **********************************************************
* LFLASH EVENTS
* *********************************************************/
event void LFlash.logDone( result_t rslt )
{
if( rslt == SUCCESS ){
count++;
if (count==2000){
call Leds.yellowOff();
call Leds.redOff();
call Leds.greenOff();
count=0;
call Timer.start(TIMER_ONE_SHOT, SLEEP_LENGTH);
}
else{
// Toggle green LED - FLASH WRITE DONE
call Leds.greenToggle();
call Timer.start(TIMER_ONE_SHOT, TIMER_PERIOD);
}
}
else{
stop = TRUE;
call Leds.yellowOn();
call Leds.greenOff();
}
}
event void LFlash.getDone( uint8_t * pageBytePtr ){
pagePtr = pageBytePtr;
if (pagePtr != NULL) post sendPage();
else post sendEOF();
}
}
As you can see from the above, i can write the data to the Flash memory. But
i have no idea on how to extract it. Also, i would actually prefer a way
whereby the data could be transmitted wirelessly to the base node instead of
using a C or Java program to extract the data through the programmer board.
I have tried to send the data wirelessly but i am unable to receive anything
so far. Could anyone have a look at my code and tell me what i need to
change/add to make it able to transmit the stored data?
Thanks and regards.
Amit.
Institute of Infocomm Research.
_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help