Thread: [Firebug-cvs] fireboard/beta/fireworks/apps/DataCollection Calibration.h,NONE,1.1 DataCollection.h,N
Brought to you by:
doolin
Update of /cvsroot/firebug/fireboard/beta/fireworks/apps/DataCollection In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32407 Modified Files: Makefile Added Files: Calibration.h DataCollection.h DataCollectionM.nc Removed Files: Surge.h Surge.nc SurgeCmd.h SurgeM.nc Log Message: Rewrote DataCollection tinyos module --- SurgeM.nc DELETED --- Index: Makefile =================================================================== RCS file: /cvsroot/firebug/fireboard/beta/fireworks/apps/DataCollection/Makefile,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Makefile 28 Aug 2005 09:17:26 -0000 1.1 --- Makefile 28 Aug 2005 20:03:47 -0000 1.2 *************** *** 4,8 **** TINYOS_NP ?= BNP ! COMPONENT=Surge include ${MAKERULES} --- 4,8 ---- TINYOS_NP ?= BNP ! COMPONENT=DataCollection include ${MAKERULES} --- NEW FILE: DataCollectionM.nc --- includes DataCollection; includes Calibration; /* * Data gather application */ module DataCollectionM { provides { interface StdControl; } uses { // interface ADC; interface SplitControl as HumidityControl; interface SplitControl as PressureControl; interface ADC as Humidity; interface ADC as Temperature; // interface ADC as TSR; // interface ADC as PAR; // interface ADC as InternalTemperature; interface ADC as InternalVoltage; interface ADC as Pressure; interface ADCError as HumidityError; interface ADCError as TemperatureError; interface Calibration as PressureCalibration; interface Timer; interface Leds; interface CC2420Control; interface MacControl; interface Send; interface RouteControl; interface Random; } } implementation { enum { // HUMIDITYCALIBRATION, PRESSURECALIBRATION, HUMIDITY, TEMPERATURE, // TSRSENSOR, // PARSENSOR, // ITEMP, IVOLT, PRESSURE, SEND }; norace uint16_t humidity, temperature, tsr, par, itemp, ivolt, pressure; norace uint16_t cal[4]; norace int state; enum { TIMER_GETADC_COUNT = 1, // Timer ticks for ADC TIMER_CHIRP_COUNT = 10, // Timer on/off chirp count }; bool sleeping; // application command state bool focused; bool rebroadcast_adc_packet; TOS_Msg gMsgBuffer; norace uint16_t gSensorData; // protected by gfSendBusy flag uint32_t seqno; bool initTimer; bool gfSendBusy; int timer_rate; int timer_ticks; /*********************************************************************** * Initialization ***********************************************************************/ static void initialize() { timer_rate = INITIAL_TIMER_RATE; atomic gfSendBusy = FALSE; sleeping = FALSE; seqno = 0; initTimer = TRUE; rebroadcast_adc_packet = FALSE; focused = FALSE; // Sensor initialization state = PRESSURECALIBRATION; } task void SendData() { DataCollectionMsg *pReading; CalibrationMsg *cReading; uint16_t Len; uint8_t i; dbg(DBG_USR1, "DataCollectionM: Sending sensor reading\n"); if ((pReading = (DataCollectionMsg *)call Send.getBuffer(&gMsgBuffer,&Len)) != NULL) { pReading->type = SENSORREADING; pReading->src = TOS_LOCAL_ADDRESS; pReading->parentaddr = call RouteControl.getParent(); pReading->humidity = humidity; pReading->temperature = temperature; // pReading->itemp = itemp; pReading->ivolt = ivolt; pReading->pressure = pressure; pReading->seq_no = seqno; #ifdef MHOP_LEDS call Leds.redOn(); #endif if ((call Send.send(&gMsgBuffer,sizeof(DataCollectionMsg))) != SUCCESS) atomic gfSendBusy = FALSE; } if ((cReading = (CalibrationMsg *)call Send.getBuffer(&gMsgBuffer,&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++; #ifdef MHOP_LEDS call Leds.redOn(); #endif if ((call Send.send(&gMsgBuffer,sizeof(DataCollectionMsg))) != SUCCESS) atomic gfSendBusy = FALSE; } } command result_t StdControl.init() { initialize(); call HumidityControl.init(); call PressureControl.init(); return SUCCESS; } event result_t HumidityControl.initDone() { return SUCCESS; } event result_t PressureControl.initDone() { return SUCCESS; } command result_t StdControl.start() { call CC2420Control.SetRFPower(15); call MacControl.enableAck(); call HumidityControl.start(); call PressureControl.start(); return SUCCESS; } event result_t HumidityControl.startDone() { uint16_t randomtimer; call HumidityError.enable(); call TemperatureError.enable(); randomtimer = (call Random.rand() & 0xfff) + 1; call Timer.start(TIMER_ONE_SHOT, randomtimer); return SUCCESS; } event result_t PressureControl.startDone() { return SUCCESS; } command result_t StdControl.stop() { call HumidityControl.stop(); call PressureControl.stop(); return call Timer.stop(); } event result_t HumidityControl.stopDone() { call HumidityError.disable(); call TemperatureError.disable(); return SUCCESS; } event result_t PressureControl.stopDone() { return SUCCESS; } event result_t PressureCalibration.dataReady(char word, uint16_t value) { atomic cal[word-1] = value; if(word >= 4) { state = HUMIDITY; } return SUCCESS; } /*********************************************************************** * Commands and events ***********************************************************************/ event result_t Timer.fired() { // set a timeout in case a task post fails (rare) call Timer.start(TIMER_ONE_SHOT, 100); switch(state) { case PRESSURECALIBRATION: call PressureCalibration.getData(); case HUMIDITY: call Humidity.getData(); break; case TEMPERATURE: call Temperature.getData(); break; /* case TSRSENSOR: call TSR.getData(); break; case PARSENSOR: call PAR.getData(); break; case ITEMP: call InternalTemperature.getData(); break; */ case IVOLT: call InternalVoltage.getData(); break; case PRESSURE: call Pressure.getData(); break; case SEND: post SendData(); break; default: call Timer.start(TIMER_ONE_SHOT, 10000); } return SUCCESS; } async event result_t Humidity.dataReady(uint16_t data) { humidity = data; call Timer.start(TIMER_ONE_SHOT, 10); state = TEMPERATURE; return SUCCESS; } event result_t HumidityError.error(uint8_t token) { humidity = 0; call Timer.start(TIMER_ONE_SHOT, 10); state = HUMIDITY; return SUCCESS; } async event result_t Temperature.dataReady(uint16_t data) { temperature = data; call Timer.start(TIMER_ONE_SHOT, 10); state = IVOLT; return SUCCESS; } event result_t TemperatureError.error(uint8_t token) { temperature = 0; call Timer.start(TIMER_ONE_SHOT, 10); state = TEMPERATURE; return SUCCESS; } /* async event result_t TSR.dataReady(uint16_t data) { tsr = data; call Timer.start(TIMER_ONE_SHOT, 10); state = PARSENSOR; return SUCCESS; } async event result_t PAR.dataReady(uint16_t data) { par = data; call Timer.start(TIMER_ONE_SHOT, 10); state = ITEMP; return SUCCESS; } async event result_t InternalTemperature.dataReady(uint16_t data) { itemp = data; call Timer.start(TIMER_ONE_SHOT, 10); state = IVOLT; return SUCCESS; } */ async event result_t InternalVoltage.dataReady(uint16_t data) { ivolt = data; call Timer.start(TIMER_ONE_SHOT, 10); state = PRESSURE; return SUCCESS; } async event result_t Pressure.dataReady(uint16_t reading) { atomic pressure = reading; call Timer.start(TIMER_ONE_SHOT, 10); state = SEND; return SUCCESS; } event result_t Send.sendDone(TOS_MsgPtr pMsg, result_t success) { dbg(DBG_USR2, "DataCollectionM: output complete 0x%x\n", success); #ifdef MHOP_LEDS call Leds.redOff(); #endif atomic gfSendBusy = FALSE; return SUCCESS; } } --- Surge.nc DELETED --- --- SurgeCmd.h DELETED --- --- NEW FILE: DataCollection.h --- int INITIAL_TIMER_RATE = 2048; int FOCUS_TIMER_RATE = 1000; int FOCUS_NOTME_TIMER_RATE = 1000; enum { SENSORREADING = 0, CALIBRATION }; typedef struct DataCollectionMsg { uint16_t src; uint16_t type; uint16_t humidity; uint16_t temperature; // uint16_t tsr; // uint16_t par; // uint16_t itemp; uint16_t ivolt; uint16_t pressure; uint16_t parentaddr; uint32_t seq_no; } DataCollectionMsg; enum { AM_DATACOLLECTIONMSG = 17 }; --- NEW FILE: Calibration.h --- typedef struct CalibrationMsg { uint16_t type; uint16_t src; uint16_t parentaddr; uint16_t calibration[4]; uint16_t seq_no; } CalibrationMsg; enum { AM_CALIBRATIONMSG = 18 }; --- Surge.h DELETED --- |