Hi,

    I am a 4th Year Student in the University of Colombo School of Computing 
Sri Lanka. I am doing a Sensor Application for my 4 th Year Individual Project.

So i tried to sample the Light Sensor data into EEPROM and then read them 
continuously. 

I could verify that the data is written to the EEPROM correctly. But when i 
read the data continuously:
    it gives the first data packet always.
    
So can you please look into my following code and
 tell me what is the wrong with it??


/**
* This will store 4 packets in it's EEPROM and try to send 4 packets 
continuously.
* Then try to Sense again.
**/
//WriteLightToEEPROMReadM.nc
includes EEPROM;
includes MoteMsg;
module WriteLightToEEPROMReadM
{
provides interface StdControl;
uses{
interface StdControl as CommControl;
interface StdControl as RequestCommControl;
interface StdControl as SensorControl;
interface StdControl as EEPROMControl;
interface StdControl as SounderControl;
interface Timer as Timer;
interface ADC;
interface EEPROMWrite as EEPROMWrite;
interface EEPROMRead as EEPROMRead;
interface SendMsg as DataSend;
//interface ReceiveMsg as DataReceive;
interface SendMsg as RequestSend;
interface ReceiveMsg as RequestReceive;
interface Leds;
 
}
}
implementation
{
enum{
maxdata = 8
};
char head;
uint8_t currentBuffer;
int *bufferPtr[2];
int data[maxdata*2];
short nsamples;
short ntimes;
uint16_t curWriteLine , curReadLine;
result_t write_result;
TOS_Msg data_msg , request_msg;
bool send_pending;
bool eeprom_read_pending;
bool request_pending;
command result_t StdControl.init()
{
atomic{
head = 0;
currentBuffer=0;
bufferPtr[0]=(&data[0]);
bufferPtr[1]=(&data[8]);
nsamples=32;
ntimes = 8;
}
curWriteLine = EEPROM_LOGGER_APPEND_START;
curReadLine = EEPROM_LOGGER_APPEND_START;
send_pending = FALSE;
eeprom_read_pending = FALSE;
request_pending = FALSE;
 
call CommControl.init();
call RequestCommControl.init();
call SounderControl.init();
return rcombine3(call EEPROMControl.init() , call SensorControl.init() , call 
Leds.init());
}
command result_t StdControl.start()
{
 
call CommControl.start();
call RequestCommControl.start();
call Timer.start(TIMER_REPEAT , 500);
return rcombine(call EEPROMControl.start() , call SensorControl.start());
}
command result_t StdControl.stop()
{
call CommControl.stop();
call RequestCommControl.stop();
call SounderControl.stop();
return rcombine(call EEPROMControl.stop() , call SensorControl.stop());
}
task void writeToEEPROM()
{
char* ptr;
atomic
{
ptr=(char*)data[currentBuffer];
currentBuffer^=0x01;
}
if (call EEPROMWrite.startWrite() == SUCCESS)
{
if (call EEPROMWrite.write(curWriteLine, ptr) == FAIL) 
{
call EEPROMWrite.endWrite();
}
call Leds.yellowToggle(); // Writes to the EEPROM correctly.
write_result = SUCCESS;
}
}
task void readFromEEPROM()
{
//call EEPROMRead.read(curReadLine, buffer);
if(!eeprom_read_pending)
if(call EEPROMRead.read(curReadLine, ((struct EEPROMMsg *)data_msg.data)->log))
{
eeprom_read_pending = TRUE;
}
}
 
task void makeRequest()
{
struct RequestMsg *request = (struct RequestMsg * )request_msg.data;
result_t status = FAIL;
 
if(!request_pending)
{
/**
uint16_t sourceMoteID; uint8_t type; uint8_t sendDone;
uint16_t packetNumber; uint8_t noOfPackets; uint16_t npackets; 
uint16_t token; uint8_t confirm; uint8_t channel; 
**/
call Leds.init(); 
atomic{
request->sourceMoteID = TOS_LOCAL_ADDRESS;
}
request->type = 0;
request->sendDone = 0;
request->packetNumber = 0;
request->noOfPackets = 0;
request->npackets = 0;
request->token = 0;
request->confirm = 0;
request->channel = 0;
if(call RequestSend.send(TOS_BCAST_ADDR , (sizeof(struct RequestMsg)) , 
&request_msg))
{
request_pending = TRUE;
status = SUCCESS; 
}
}
}
task void sendData()
{
struct EEPROMMsg *pack=(struct EEPROMMsg *)data_msg.data;
if(!send_pending)
{
ntimes--;
atomic
{
pack->sourceMoteID = TOS_LOCAL_ADDRESS;
}
if(call DataSend.send(TOS_BCAST_ADDR , sizeof(struct EEPROMMsg ) ,&data_msg ))
{
call Leds.greenToggle();
}
}
}
event result_t DataSend.sendDone(TOS_MsgPtr pmsg , result_t status)
{
send_pending = FALSE;
if(ntimes == 0)
{
call SounderControl.start();
nsamples=32;
ntimes = 8;
call Timer.start(TIMER_REPEAT , 500);
//post makeRequest();
}
else{
call Leds.redToggle();
eeprom_read_pending = FALSE;
post readFromEEPROM();
}
return status;
}
 
event result_t RequestSend.sendDone(TOS_MsgPtr pmsg , result_t status)
{
request_pending = FALSE;
return status;
}
event TOS_MsgPtr RequestReceive.receive(TOS_MsgPtr pmsg)
{
struct RequestMsg *rmsg=(struct RequestMsg *)pmsg->data;
// You can put this confirmation Msg in a Buffer and Pase the Pointer to use it 
for analysis in the future works.
if(rmsg->confirm == TOS_LOCAL_ADDRESS)
{
call SounderControl.stop();
post readFromEEPROM();
}
return pmsg; 
}
 
 
event result_t Timer.fired()
{
nsamples--;
if(nsamples == 0){
call Timer.stop();
post makeRequest(); 
}
call Leds.redToggle();
call ADC.getData();
return SUCCESS;
} 
async event result_t ADC.dataReady(uint16_t this_data)
{
atomic
{
int p=head;
bufferPtr[currentBuffer][p]=this_data;
head=(p+1);
if(head==maxdata) head = 0;
if(head==0){
post writeToEEPROM();
}
}
return SUCCESS;
}
event result_t EEPROMWrite.writeDone(uint8_t *buffer) 
{
write_result = call EEPROMWrite.endWrite();
return SUCCESS;
}
event result_t EEPROMWrite.endWriteDone(result_t success) 
{
if (success == SUCCESS) 
{
curWriteLine++;
if (curWriteLine == EEPROM_LOGGER_APPEND_END)
curWriteLine = EEPROM_LOGGER_APPEND_START;
}
return write_result;
}
event result_t EEPROMRead.readDone(uint8_t *buffer, result_t success) 
{
if (success == SUCCESS) 
{
curReadLine++;
if (curReadLine == EEPROM_LOGGER_APPEND_END) 
{
curReadLine = EEPROM_LOGGER_APPEND_START;
}
}
eeprom_read_pending = FALSE; 
post sendData();
return success;
}
 
}

I have wired the above Module as follows:
//WriteLightToEEPROMRead.nc
includes MoteMsg;
includes EEPROM;
configuration WriteLightToEEPROMRead
{
}
implementation 
{
// components Main, MoteSenseM, TimerC, Logger, Photo, RequestRead , 
BusEEPROMRead , LedsC;
components Main, WriteLightToEEPROMReadM , TimerC , Photo , EEPROM , LedsC , 
Sounder
, GenericComm as Comm , GenericComm as RequestComm;
 
Main.StdControl -> WriteLightToEEPROMReadM.StdControl;
WriteLightToEEPROMReadM.CommControl -> Comm;
WriteLightToEEPROMReadM.RequestCommControl ->RequestComm;
WriteLightToEEPROMReadM.SensorControl -> Photo;
WriteLightToEEPROMReadM.EEPROMControl -> EEPROM;
WriteLightToEEPROMReadM.Timer -> TimerC.Timer[unique("Timer")]; 
WriteLightToEEPROMReadM.ADC -> Photo;
WriteLightToEEPROMReadM.EEPROMWrite -> EEPROM.EEPROMWrite[42];
WriteLightToEEPROMReadM.EEPROMRead -> EEPROM;
WriteLightToEEPROMReadM.DataSend -> Comm.SendMsg[AM_EEPROMMSG];
//WriteLightToEEPROMReadM.DataReceive -> Comm.ReceiveMsg[AM_EEPROMMSG];
WriteLightToEEPROMReadM.RequestSend -> RequestComm.SendMsg[AM_REQUESTMSG];
WriteLightToEEPROMReadM.RequestReceive -> RequestComm.ReceiveMsg[AM_REQUESTMSG];
WriteLightToEEPROMReadM.Leds -> LedsC;
WriteLightToEEPROMReadM.SounderControl -> Sounder;
}



And I am using a Header File:

 
 
enum {
AM_EEPROMMSG=9 ,
AM_REQUESTMSG=20
};
typedef struct EEPROMMsg{
uint16_t sourceMoteID;
uint8_t log[16];
}EEPROMMsg;
 
struct RequestMsg
{
uint16_t sourceMoteID; //Mote ID
uint8_t type; //Specify Data Motes and Traveler Motes, just for Testing purposes
uint8_t sendDone; // If all packets has been sent already: then this must be 1. 
Else =0
uint16_t packetNumber; // The number of Packets in the Mote which must be 
Transmitted
uint8_t noOfPackets; // The Total Number of packets to be send by the Mote.
uint16_t npackets; // This will defined by the Base Station according to its 
Prioritization 
// algorithm (Like ReturnRequestNumber 4 , 8 , 16)
uint16_t token; // This will be assigned a value when the Request Queue buffer 
gets Full. 
// It says the Mote to Query again after a specific period of Time.
uint8_t confirm; // Base will assign the correct SourceID to be send the Data.
uint8_t channel; // Not define a specific task up to now.
};
/**
uint16_t sourceMoteID; uint8_t type; uint8_t sendDone;
uint16_t packetNumber; uint8_t noOfPackets; uint16_t npackets; 
uint16_t token; uint8_t confirm; uint8_t channel; 
**/


Thank You!
Regards,
Bandara.
(The Happy is the Goal!)


 
____________________________________________________________________________________
Don't pick lemons.
See all the new 2007 cars at Yahoo! Autos.
http://autos.yahoo.com/new_cars.html 
_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to