[Firebug-cvs] fireboard/beta/fireworks/apps/DataCollection DataCollection.h,1.3,1.4 DataCollectionM.
Brought to you by:
doolin
From: Karthik D. <da...@us...> - 2005-08-31 08:40:39
|
Update of /cvsroot/firebug/fireboard/beta/fireworks/apps/DataCollection In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24268 Modified Files: DataCollection.h DataCollectionM.nc Log Message: New communication scheme working. Now send calibration only once every so often Index: DataCollectionM.nc =================================================================== RCS file: /cvsroot/firebug/fireboard/beta/fireworks/apps/DataCollection/DataCollectionM.nc,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** DataCollectionM.nc 29 Aug 2005 22:45:36 -0000 1.4 --- DataCollectionM.nc 31 Aug 2005 08:40:31 -0000 1.5 *************** *** 42,46 **** enum { // HUMIDITYCALIBRATION, ! PRESSURECALIBRATION=1, HUMIDITY, TEMPERATURE, --- 42,47 ---- enum { // HUMIDITYCALIBRATION, ! PRESSURECALIBRATION=0, ! SENDCALIBRATION, HUMIDITY, TEMPERATURE, *************** *** 50,55 **** IVOLT, PRESSURE, ! SEND, ! SENDCALIBRATION }; --- 51,55 ---- IVOLT, PRESSURE, ! SEND }; *************** *** 74,78 **** uint8_t sending; // sending=1 => data; sending=2 => calibration ! int timer_rate; int timer_ticks; /*********************************************************************** --- 74,79 ---- uint8_t sending; // sending=1 => data; sending=2 => calibration ! uint8_t counter; // Do calibration and send it every 256 times ! uint8_t csendcounter; // And we send calibration thrice, just for safety int timer_ticks; /*********************************************************************** *************** *** 81,85 **** static void initialize() { - timer_rate = INITIAL_TIMER_RATE; atomic sendBusy = FALSE; sleeping = FALSE; --- 82,85 ---- *************** *** 88,93 **** rebroadcast_adc_packet = FALSE; focused = FALSE; ! sending = 1; ! // Sensor initialization state = PRESSURECALIBRATION; --- 88,93 ---- rebroadcast_adc_packet = FALSE; focused = FALSE; ! csendcounter = 0; ! counter = 0; // Sensor initialization state = PRESSURECALIBRATION; *************** *** 106,109 **** --- 106,110 ---- DataCollectionMsg *pReading; uint16_t Len; + uint8_t oldsending; dbg(DBG_USR1, "DataCollectionM: Sending sensor reading\n"); *************** *** 120,125 **** sendBusy = TRUE; ! if ((call Send.send(&dataBuffer,sizeof(DataCollectionMsg))) != SUCCESS) atomic sendBusy = FALSE; } } --- 121,130 ---- sendBusy = TRUE; ! oldsending=sending; ! sending=1; ! if ((call Send.send(&dataBuffer,sizeof(DataCollectionMsg))) != SUCCESS) { atomic sendBusy = FALSE; + sending=oldsending; + } } } *************** *** 154,158 **** call HumidityError.enable(); call TemperatureError.enable(); ! randomtimer = (call Random.rand() & 0xfff) + 1; call Timer.start(TIMER_ONE_SHOT, randomtimer); return SUCCESS; --- 159,163 ---- call HumidityError.enable(); call TemperatureError.enable(); ! randomtimer = (call Random.rand() & 0x2710) + 1; call Timer.start(TIMER_ONE_SHOT, randomtimer); return SUCCESS; *************** *** 184,194 **** --- 189,233 ---- event result_t Timer.fired() { + CalibrationMsg *cReading; + uint8_t i; + uint16_t Len; + uint8_t oldsending=0; + switch(state) { case PRESSURECALIBRATION: call PressureCalibration.getData(); break; + case SENDCALIBRATION: + if(!sendBusy) { + dbg(DBG_USR2, "DataCollectionM: output complete 0x%x\n", success); + if ((cReading = (CalibrationMsg *)call Send.getBuffer(&calibrationBuffer,&Len)) != NULL) { + cReading->type = CALIBRATION; + cReading->src = TOS_LOCAL_ADDRESS; + cReading->parentaddr = call RouteControl.getParent(); + for(i=0;i<4;i++) + cReading->calibration[i]=cal[i]; + cReading->seq_no = seqno++; + + call Leds.set(SENDCALIBRATION); + atomic sendBusy = TRUE; + oldsending=sending; + sending=2; + csendcounter++; + if ((call Send.send(&calibrationBuffer,sizeof(CalibrationMsg))) != SUCCESS) { + atomic sendBusy = FALSE; + sending=oldsending; + csendcounter--; + } + } + } + else { + call Timer.start(TIMER_ONE_SHOT, INTERSTATE_INTERVAL); + } + break; + case HUMIDITY: call Humidity.getData(); break; + case TEMPERATURE: call Temperature.getData(); *************** *** 218,222 **** break; default: ! // call Timer.start(TIMER_ONE_SHOT, 10000); } return SUCCESS; --- 257,261 ---- break; default: ! // call Timer.start(TIMER_ONE_SHOT, INTERSTATE_INTERVAL00); } return SUCCESS; *************** *** 226,232 **** atomic cal[word-1] = value; if(word >= 4) { ! state = HUMIDITY; ! call Leds.set(HUMIDITY); ! call Timer.start(TIMER_ONE_SHOT, 100); } --- 265,271 ---- atomic cal[word-1] = value; if(word >= 4) { ! state = SENDCALIBRATION; ! call Leds.set(SENDCALIBRATION); ! call Timer.start(TIMER_ONE_SHOT, INTERSTATE_INTERVAL); } *************** *** 236,240 **** async event result_t Humidity.dataReady(uint16_t data) { atomic humidity = data; ! call Timer.start(TIMER_ONE_SHOT, 100); state = TEMPERATURE; call Leds.set(TEMPERATURE); --- 275,279 ---- async event result_t Humidity.dataReady(uint16_t data) { atomic humidity = data; ! call Timer.start(TIMER_ONE_SHOT, INTERSTATE_INTERVAL); state = TEMPERATURE; call Leds.set(TEMPERATURE); *************** *** 244,248 **** event result_t HumidityError.error(uint8_t token) { atomic humidity = 0; ! call Timer.start(TIMER_ONE_SHOT, 100); state = HUMIDITY; call Leds.set(HUMIDITY); --- 283,287 ---- event result_t HumidityError.error(uint8_t token) { atomic humidity = 0; ! call Timer.start(TIMER_ONE_SHOT, INTERSTATE_INTERVAL); state = HUMIDITY; call Leds.set(HUMIDITY); *************** *** 252,256 **** async event result_t Temperature.dataReady(uint16_t data) { atomic temperature = data; ! call Timer.start(TIMER_ONE_SHOT, 100); state = ITEMP; call Leds.set(ITEMP); --- 291,295 ---- async event result_t Temperature.dataReady(uint16_t data) { atomic temperature = data; ! call Timer.start(TIMER_ONE_SHOT, INTERSTATE_INTERVAL); state = ITEMP; call Leds.set(ITEMP); *************** *** 260,264 **** event result_t TemperatureError.error(uint8_t token) { atomic temperature = 0; ! call Timer.start(TIMER_ONE_SHOT, 100); state = TEMPERATURE; call Leds.set(TEMPERATURE); --- 299,303 ---- event result_t TemperatureError.error(uint8_t token) { atomic temperature = 0; ! call Timer.start(TIMER_ONE_SHOT, INTERSTATE_INTERVAL); state = TEMPERATURE; call Leds.set(TEMPERATURE); *************** *** 299,303 **** async event result_t InternalVoltage.dataReady(uint16_t data) { atomic ivolt = data; ! call Timer.start(TIMER_ONE_SHOT, 100); state = PRESSURE; call Leds.set(PRESSURE); --- 338,342 ---- async event result_t InternalVoltage.dataReady(uint16_t data) { atomic ivolt = data; ! call Timer.start(TIMER_ONE_SHOT, INTERSTATE_INTERVAL); state = PRESSURE; call Leds.set(PRESSURE); *************** *** 307,311 **** async event result_t Pressure.dataReady(uint16_t reading) { atomic pressure = reading; ! call Timer.start(TIMER_ONE_SHOT, 100); state = SEND; call Leds.set(SEND); --- 346,350 ---- async event result_t Pressure.dataReady(uint16_t reading) { atomic pressure = reading; ! call Timer.start(TIMER_ONE_SHOT, INTERSTATE_INTERVAL); state = SEND; call Leds.set(SEND); *************** *** 315,350 **** event result_t Send.sendDone(TOS_MsgPtr pMsg, result_t success) { - - CalibrationMsg *cReading; - uint8_t i; - uint16_t Len; - - atomic sendBusy = FALSE; - dbg(DBG_USR2, "DataCollectionM: output complete 0x%x\n", success); if(sending == 1) { ! sending = 2; ! if ((cReading = (CalibrationMsg *)call Send.getBuffer(&calibrationBuffer,&Len)) != NULL) { ! cReading->type = CALIBRATION; ! cReading->src = TOS_LOCAL_ADDRESS; ! cReading->parentaddr = call RouteControl.getParent(); ! for(i=0;i<4;i++) ! cReading->calibration[i]=cal[i]; ! cReading->seq_no = seqno++; ! ! call Leds.set(SENDCALIBRATION); ! atomic sendBusy = TRUE; ! if ((call Send.send(&calibrationBuffer,sizeof(CalibrationMsg))) != SUCCESS) ! atomic sendBusy = FALSE; } } ! else if(sending == 2) { ! state = PRESSURECALIBRATION; ! sending = 1; ! // call Leds.set(PRESSURECALIBRATION); ! call Timer.start(TIMER_ONE_SHOT, 1000); ! return SUCCESS; } } } - --- 354,382 ---- event result_t Send.sendDone(TOS_MsgPtr pMsg, result_t success) { if(sending == 1) { ! /* Just sent sensor data */ ! counter ++; ! if(counter%20 == 0) { ! state = PRESSURECALIBRATION; } + else { + state = HUMIDITY; + } + call Timer.start(TIMER_ONE_SHOT, SAMPLING_RATE); } ! else { ! /* Just sent calibration data */ ! if(csendcounter < 3) { ! state = PRESSURECALIBRATION; ! } ! else { ! state = HUMIDITY; ! csendcounter = 0; ! } ! call Timer.start(TIMER_ONE_SHOT, INTERSTATE_INTERVAL); } + sendBusy = FALSE; + return SUCCESS; } } Index: DataCollection.h =================================================================== RCS file: /cvsroot/firebug/fireboard/beta/fireworks/apps/DataCollection/DataCollection.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** DataCollection.h 29 Aug 2005 22:45:36 -0000 1.3 --- DataCollection.h 31 Aug 2005 08:40:31 -0000 1.4 *************** *** 1,8 **** int INITIAL_TIMER_RATE = 2048; - int FOCUS_TIMER_RATE = 1000; - int FOCUS_NOTME_TIMER_RATE = 1000; - - - enum { --- 1,5 ---- + int SAMPLING_RATE=1024; // Every ten seconds + int INTERSTATE_INTERVAL=100; // 100ms int INITIAL_TIMER_RATE = 2048; enum { |