From 728254c1fb570ee3764c65eebd7176f9ef0c557b Mon Sep 17 00:00:00 2001 From: klueska Date: Mon, 3 Sep 2007 22:46:35 +0000 Subject: [PATCH] Low Power Sensing Application initial checkin --- .../Base/LowPowerSensingBaseAppC.nc | 78 +++++ .../Base/LowPowerSensingBaseC.nc | 121 ++++++++ apps/tutorials/LowPowerSensing/Base/Makefile | 5 + .../LowPowerSensing/Base/volumes-at45db.xml | 3 + .../LowPowerSensing/Base/volumes-stm25p.xml | 3 + .../LowPowerSensingConstants.h | 53 ++++ .../LowPowerSensing/LowPowerSensingMsgs.h | 69 +++++ .../LowPowerSensingPeriodicSamplerAppC.nc | 73 +++++ .../LowPowerSensingPeriodicSamplerC.nc | 119 +++++++ .../LowPowerSensing/Sampler/Makefile | 5 + .../Sampler/volumes-at45db.xml | 3 + .../Sampler/volumes-stm25p.xml | 3 + .../LowPowerSensing/java/Constants.class | Bin 0 -> 372 bytes .../LowPowerSensing/java/Constants.java | 12 + .../java/LowPowerSensingApp.class | Bin 0 -> 2019 bytes .../java/LowPowerSensingApp.jar | Bin 0 -> 4709 bytes .../java/LowPowerSensingApp.java | 96 ++++++ apps/tutorials/LowPowerSensing/java/Makefile | 31 ++ .../java/SerialRequestSamplesMsg.class | Bin 0 -> 2559 bytes .../java/SerialRequestSamplesMsg.java | 224 ++++++++++++++ .../java/SerialSampleMsg.class | Bin 0 -> 3293 bytes .../LowPowerSensing/java/SerialSampleMsg.java | 290 ++++++++++++++++++ .../sampleLog/GenericSensorSample.h | 53 ++++ .../sampleLog/PeriodicSampleLogger16C.nc | 56 ++++ .../sampleLog/PeriodicSampleLoggerP.nc | 120 ++++++++ .../sampleLog/SampleLogRead.nc | 42 +++ .../sampleLog/SampleLogReaderC.nc | 53 ++++ .../sampleLog/SampleLogReaderP.nc | 78 +++++ .../sampleLog/SampleNxConverter.nc | 42 +++ .../SampleNxConverterC.nc | 57 ++++ .../SamplePeriodicLogC.nc | 68 ++++ .../tmote_onboard_sensors/SensorSample.h | 57 ++++ .../universal_sensors/SampleNxConverterC.nc | 51 +++ .../universal_sensors/SamplePeriodicLogC.nc | 61 ++++ .../universal_sensors/SensorSample.h | 51 +++ 35 files changed, 1977 insertions(+) create mode 100644 apps/tutorials/LowPowerSensing/Base/LowPowerSensingBaseAppC.nc create mode 100644 apps/tutorials/LowPowerSensing/Base/LowPowerSensingBaseC.nc create mode 100644 apps/tutorials/LowPowerSensing/Base/Makefile create mode 100644 apps/tutorials/LowPowerSensing/Base/volumes-at45db.xml create mode 100644 apps/tutorials/LowPowerSensing/Base/volumes-stm25p.xml create mode 100644 apps/tutorials/LowPowerSensing/LowPowerSensingConstants.h create mode 100644 apps/tutorials/LowPowerSensing/LowPowerSensingMsgs.h create mode 100644 apps/tutorials/LowPowerSensing/Sampler/LowPowerSensingPeriodicSamplerAppC.nc create mode 100644 apps/tutorials/LowPowerSensing/Sampler/LowPowerSensingPeriodicSamplerC.nc create mode 100644 apps/tutorials/LowPowerSensing/Sampler/Makefile create mode 100644 apps/tutorials/LowPowerSensing/Sampler/volumes-at45db.xml create mode 100644 apps/tutorials/LowPowerSensing/Sampler/volumes-stm25p.xml create mode 100644 apps/tutorials/LowPowerSensing/java/Constants.class create mode 100644 apps/tutorials/LowPowerSensing/java/Constants.java create mode 100644 apps/tutorials/LowPowerSensing/java/LowPowerSensingApp.class create mode 100644 apps/tutorials/LowPowerSensing/java/LowPowerSensingApp.jar create mode 100644 apps/tutorials/LowPowerSensing/java/LowPowerSensingApp.java create mode 100644 apps/tutorials/LowPowerSensing/java/Makefile create mode 100644 apps/tutorials/LowPowerSensing/java/SerialRequestSamplesMsg.class create mode 100644 apps/tutorials/LowPowerSensing/java/SerialRequestSamplesMsg.java create mode 100644 apps/tutorials/LowPowerSensing/java/SerialSampleMsg.class create mode 100644 apps/tutorials/LowPowerSensing/java/SerialSampleMsg.java create mode 100644 apps/tutorials/LowPowerSensing/sampleLog/GenericSensorSample.h create mode 100644 apps/tutorials/LowPowerSensing/sampleLog/PeriodicSampleLogger16C.nc create mode 100644 apps/tutorials/LowPowerSensing/sampleLog/PeriodicSampleLoggerP.nc create mode 100644 apps/tutorials/LowPowerSensing/sampleLog/SampleLogRead.nc create mode 100644 apps/tutorials/LowPowerSensing/sampleLog/SampleLogReaderC.nc create mode 100644 apps/tutorials/LowPowerSensing/sampleLog/SampleLogReaderP.nc create mode 100644 apps/tutorials/LowPowerSensing/sampleLog/SampleNxConverter.nc create mode 100644 apps/tutorials/LowPowerSensing/tmote_onboard_sensors/SampleNxConverterC.nc create mode 100644 apps/tutorials/LowPowerSensing/tmote_onboard_sensors/SamplePeriodicLogC.nc create mode 100644 apps/tutorials/LowPowerSensing/tmote_onboard_sensors/SensorSample.h create mode 100644 apps/tutorials/LowPowerSensing/universal_sensors/SampleNxConverterC.nc create mode 100644 apps/tutorials/LowPowerSensing/universal_sensors/SamplePeriodicLogC.nc create mode 100644 apps/tutorials/LowPowerSensing/universal_sensors/SensorSample.h diff --git a/apps/tutorials/LowPowerSensing/Base/LowPowerSensingBaseAppC.nc b/apps/tutorials/LowPowerSensing/Base/LowPowerSensingBaseAppC.nc new file mode 100644 index 00000000..4dfd9581 --- /dev/null +++ b/apps/tutorials/LowPowerSensing/Base/LowPowerSensingBaseAppC.nc @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2007 Stanford University. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * - Neither the name of the Stanford University nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD + * UNIVERSITY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @author Kevin Klues + * @date July 24, 2007 + */ + +#include "LowPowerSensingConstants.h" +configuration LowPowerSensingBaseAppC{} +implementation { + components MainC, LowPowerSensingBaseC as App; + components new QueueC(message_t, MSG_QUEUE_SIZE) as Queue; + components LedsC; + MainC.Boot <- App; + App.MsgQueue -> Queue; + App.Leds -> LedsC; + + components SerialActiveMessageC as Serial; + App.SerialAMControl -> Serial; + App.SerialAMPacket -> Serial; + App.SerialPacket -> Serial; + + components ActiveMessageC as Radio; + App.RadioAMControl -> Radio; + App.RadioAMPacket -> Radio; + App.RadioPacket -> Radio; + + components new SerialAMReceiverC(AM_SERIAL_REQUEST_SAMPLES_MSG) as SerialRequestSampleMsgsReceiver; + components new AMSenderC(AM_REQUEST_SAMPLES_MSG) as RadioRequestSampleMsgsSender; + App.SerialRequestSampleMsgsReceive -> SerialRequestSampleMsgsReceiver; + App.RadioRequestSampleMsgsSend -> RadioRequestSampleMsgsSender; + + components new AMReceiverC(AM_SAMPLE_MSG) as RadioSampleMsgReceiver; + components new SerialAMSenderC(AM_SERIAL_SAMPLE_MSG) as SerialSampleMsgSender; + App.RadioSampleMsgReceive -> RadioSampleMsgReceiver; + App.SerialSampleMsgSend -> SerialSampleMsgSender; + +//Nasty hack since no uniform way of prividing LPL support as of yet +#if defined(PLATFORM_TELOSB) || defined(PLATFORM_TMOTE) || defined(PLATFORM_MICAZ) + components CC2420ActiveMessageC as LPLProvider; + App.LPL -> LPLProvider; +#endif + +#if defined(PLATFORM_MICA2) + components CC1000CsmaRadioC as LPLProvider; + App.LPL -> LPLProvider; +#endif +} + diff --git a/apps/tutorials/LowPowerSensing/Base/LowPowerSensingBaseC.nc b/apps/tutorials/LowPowerSensing/Base/LowPowerSensingBaseC.nc new file mode 100644 index 00000000..919b7a6d --- /dev/null +++ b/apps/tutorials/LowPowerSensing/Base/LowPowerSensingBaseC.nc @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2007 Stanford University. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * - Neither the name of the Stanford University nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD + * UNIVERSITY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @author Kevin Klues + * @date July 24, 2007 + */ + +#include "LowPowerSensingConstants.h" +module LowPowerSensingBaseC { + uses { + interface Boot; + interface Queue as MsgQueue; + interface Leds; + interface LowPowerListening as LPL; + + interface SplitControl as SerialAMControl; + interface AMPacket as SerialAMPacket; + interface Packet as SerialPacket; + + interface SplitControl as RadioAMControl; + interface AMPacket as RadioAMPacket; + interface Packet as RadioPacket; + + interface Receive as SerialRequestSampleMsgsReceive; + interface AMSend as RadioRequestSampleMsgsSend; + interface Receive as RadioSampleMsgReceive; + interface AMSend as SerialSampleMsgSend; + } +} +implementation { + bool serialSending; + am_addr_t dest_addr; + message_t request_samples_msg; + message_t sample_msg; + serial_sample_msg_t* sample_msg_payload; + + event void Boot.booted() { + serialSending = FALSE; + sample_msg_payload = (serial_sample_msg_t*)call SerialPacket.getPayload(&sample_msg, NULL); + call RadioAMControl.start(); + } + + event void RadioAMControl.startDone(error_t error) { + call SerialAMControl.start(); + } + + event void SerialAMControl.startDone(error_t error) { + } + + event void RadioAMControl.stopDone(error_t error) { + } + + event void SerialAMControl.stopDone(error_t error) { + } + + event message_t* SerialRequestSampleMsgsReceive.receive(message_t* msg, void* payload, uint8_t len) { + serial_request_samples_msg_t* request_msg = payload; + call Leds.led0On(); + call LPL.setRxSleepInterval(&request_samples_msg, LPL_INTERVAL+100); + call RadioRequestSampleMsgsSend.send(request_msg->addr, &request_samples_msg, sizeof(request_samples_msg_t)); + return msg; + } + + event void RadioRequestSampleMsgsSend.sendDone(message_t* msg, error_t error) { + if(error == SUCCESS) + call Leds.led0Off(); + } + + event message_t* RadioSampleMsgReceive.receive(message_t* msg, void* payload, uint8_t len) { + call Leds.led2Toggle(); + if(call MsgQueue.empty() == FALSE || serialSending == TRUE) + call MsgQueue.enqueue(*msg); + else { + sample_msg_payload->src_addr = call RadioAMPacket.source(msg); + sample_msg_payload->sample = *((nx_sensor_sample_t*)payload); + dest_addr = call SerialAMPacket.destination(msg); + serialSending = TRUE; + call SerialSampleMsgSend.send(dest_addr, &sample_msg, sizeof(*sample_msg_payload)); + } + return msg; + } + + event void SerialSampleMsgSend.sendDone(message_t* msg, error_t error) { + if(call MsgQueue.empty() == FALSE) { + sample_msg = call MsgQueue.dequeue(); + dest_addr = call SerialAMPacket.destination(msg); + call SerialSampleMsgSend.send(dest_addr, &sample_msg, sizeof(serial_sample_msg_t)); + } + else serialSending = FALSE; + } +} + diff --git a/apps/tutorials/LowPowerSensing/Base/Makefile b/apps/tutorials/LowPowerSensing/Base/Makefile new file mode 100644 index 00000000..4e1481a7 --- /dev/null +++ b/apps/tutorials/LowPowerSensing/Base/Makefile @@ -0,0 +1,5 @@ +COMPONENT=LowPowerSensingBaseAppC +CFLAGS += -I.. -I../universal_sensors +CFLAGS += -DCC1K_DEFAULT_FREQ=CC1K_914_077_MHZ + +include $(MAKERULES) diff --git a/apps/tutorials/LowPowerSensing/Base/volumes-at45db.xml b/apps/tutorials/LowPowerSensing/Base/volumes-at45db.xml new file mode 100644 index 00000000..105e58ae --- /dev/null +++ b/apps/tutorials/LowPowerSensing/Base/volumes-at45db.xml @@ -0,0 +1,3 @@ + + + diff --git a/apps/tutorials/LowPowerSensing/Base/volumes-stm25p.xml b/apps/tutorials/LowPowerSensing/Base/volumes-stm25p.xml new file mode 100644 index 00000000..64dfc4c6 --- /dev/null +++ b/apps/tutorials/LowPowerSensing/Base/volumes-stm25p.xml @@ -0,0 +1,3 @@ + + + diff --git a/apps/tutorials/LowPowerSensing/LowPowerSensingConstants.h b/apps/tutorials/LowPowerSensing/LowPowerSensingConstants.h new file mode 100644 index 00000000..a0687f47 --- /dev/null +++ b/apps/tutorials/LowPowerSensing/LowPowerSensingConstants.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2007 Stanford University. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * - Neither the name of the Stanford University nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD + * UNIVERSITY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @author Kevin Klues + * @date July 24, 2007 + */ + +#ifndef LOWPOWERSENSINGCONSTANTS_H +#define LOWPOWERSENSINGCONSTANTS_H + +#ifndef LOWPOWERSENSING_JAVA_MAKEFILE +#include "StorageVolumes.h" +#endif +#include "LowPowerSensingMsgs.h" + +#define LOW_POWER_LISTENING +enum { + LPL_INTERVAL = 2000, + SAMPLING_INTERVAL = 3000, + MSG_QUEUE_SIZE = 50, + BASE_STATION_ADDR = 0, +}; +#endif //LOWPOWERSENSINGCONSTANTS_H + diff --git a/apps/tutorials/LowPowerSensing/LowPowerSensingMsgs.h b/apps/tutorials/LowPowerSensing/LowPowerSensingMsgs.h new file mode 100644 index 00000000..0fcc191d --- /dev/null +++ b/apps/tutorials/LowPowerSensing/LowPowerSensingMsgs.h @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2007 Stanford University. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * - Neither the name of the Stanford University nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD + * UNIVERSITY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @author Kevin Klues + * @date July 24, 2007 + */ + +#ifndef LOWPOWERSENSINGMSGS_H +#define LOWPOWERSENSINGMSGS_H + +#include "message.h" +#include "SensorSample.h" + +enum { + AM_SERIAL_REQUEST_SAMPLES_MSG = 0x92, + AM_REQUEST_SAMPLES_MSG = 0x93, + + AM_SAMPLE_MSG = 0x98, + AM_SERIAL_SAMPLE_MSG = 0x99, +}; + +typedef nx_struct serial_request_samples_msg { + nx_am_addr_t addr; + nx_uint32_t sample_num; +} serial_request_samples_msg_t; + +typedef nx_struct request_samples_msg { +} request_samples_msg_t; + +typedef nx_struct sample_msg { + nx_sensor_sample_t sample; +} sample_msg_t; + +typedef nx_struct serial_sample_msg { + nx_am_addr_t src_addr; + nx_sensor_sample_t sample; +} serial_sample_msg_t; + +#endif //LOWPOWERSENSINGMSGS_H + diff --git a/apps/tutorials/LowPowerSensing/Sampler/LowPowerSensingPeriodicSamplerAppC.nc b/apps/tutorials/LowPowerSensing/Sampler/LowPowerSensingPeriodicSamplerAppC.nc new file mode 100644 index 00000000..4a486842 --- /dev/null +++ b/apps/tutorials/LowPowerSensing/Sampler/LowPowerSensingPeriodicSamplerAppC.nc @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2007 Stanford University. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * - Neither the name of the Stanford University nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD + * UNIVERSITY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @author Kevin Klues + * @date July 24, 2007 + */ + +#include "LowPowerSensingConstants.h" +#include "SensorSample.h" +configuration LowPowerSensingPeriodicSamplerAppC {} +implementation { + components new SamplePeriodicLogC(SAMPLING_INTERVAL, VOLUME_SENSOR_SAMPLES); + components MainC, LowPowerSensingPeriodicSamplerC as App; + components SampleNxConverterC; + MainC.Boot <- App; + App.SampleLogRead -> SamplePeriodicLogC; + App.SampleNxConverter -> SampleNxConverterC; + + components ActiveMessageC; + App.AMControl -> ActiveMessageC; + App.AMPacket -> ActiveMessageC; + App.Packet -> ActiveMessageC; + + components new AMSenderC(AM_SAMPLE_MSG) as SampleSender; + App.SampleSend -> SampleSender; + + components new AMReceiverC(AM_REQUEST_SAMPLES_MSG) as RequestSamplesReceiver; + App.RequestSamplesReceive -> RequestSamplesReceiver; + + components LedsC as LedsC; + App.Leds -> LedsC; + +//Nasty hack since no uniform way of prividing LPL support as of yet +#if defined(PLATFORM_TELOSB) || defined(PLATFORM_TMOTE) || defined(PLATFORM_MICAZ) + components CC2420ActiveMessageC as LPLProvider; + App.LPL -> LPLProvider; +#endif + +#if defined(PLATFORM_MICA2) + components CC1000CsmaRadioC as LPLProvider; + App.LPL -> LPLProvider; +#endif +} + diff --git a/apps/tutorials/LowPowerSensing/Sampler/LowPowerSensingPeriodicSamplerC.nc b/apps/tutorials/LowPowerSensing/Sampler/LowPowerSensingPeriodicSamplerC.nc new file mode 100644 index 00000000..17a1b1ef --- /dev/null +++ b/apps/tutorials/LowPowerSensing/Sampler/LowPowerSensingPeriodicSamplerC.nc @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2007 Stanford University. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * - Neither the name of the Stanford University nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD + * UNIVERSITY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @author Kevin Klues + * @date July 24, 2007 + */ + +#include "LowPowerSensingConstants.h" +#include "SensorSample.h" +module LowPowerSensingPeriodicSamplerC { + uses { + interface Boot; + interface SampleLogRead; + interface SampleNxConverter; + interface Leds; + interface SplitControl as AMControl; + interface AMPacket; + interface Packet; + interface AMSend as SampleSend; + interface Receive as RequestSamplesReceive; + interface LowPowerListening as LPL; + } +} +implementation { + message_t sample_msg; + bool sendBusy = FALSE; + + task void readNextTask(); + task void sendSampleMsgTask(); + + void readNext() { + error_t error = call SampleLogRead.readNext(); + if(error == FAIL) + post readNextTask(); + else if(error == ECANCEL) { + sendBusy = FALSE; + call Leds.led1Toggle(); + } + } + + void sendSampleMsg() { + call LPL.setRxSleepInterval(&sample_msg, 0); + if(call SampleSend.send(BASE_STATION_ADDR, &sample_msg, sizeof(nx_sensor_sample_t)) != SUCCESS) + post sendSampleMsgTask(); + else call Leds.led2On(); + } + + task void readNextTask() { readNext(); } + task void sendSampleMsgTask() { sendSampleMsg(); } + + event void Boot.booted() { + call LPL.setLocalSleepInterval(LPL_INTERVAL); + call AMControl.start(); + } + + event void AMControl.startDone(error_t e) { + if(e != SUCCESS) + call AMControl.start(); + } + + event void AMControl.stopDone(error_t e) { + } + + event void SampleLogRead.readDone(sensor_sample_t* sample, error_t error) { + if(error == SUCCESS) { + nx_sensor_sample_t* nx_sample = call SampleSend.getPayload(&sample_msg); + call SampleNxConverter.copyToNx(nx_sample, sample); + sendSampleMsg(); + } + else post readNextTask(); + } + + event message_t* RequestSamplesReceive.receive(message_t* msg, void* payload, uint8_t len) { + call Leds.led0Toggle(); + if(sendBusy == FALSE) { + sendBusy = TRUE; + readNext(); + } + return msg; + } + + event void SampleSend.sendDone(message_t* msg, error_t error) { + if(error != SUCCESS) + post sendSampleMsgTask(); + else { + call Leds.led2Off(); + readNext(); + } + } +} diff --git a/apps/tutorials/LowPowerSensing/Sampler/Makefile b/apps/tutorials/LowPowerSensing/Sampler/Makefile new file mode 100644 index 00000000..b77d82a6 --- /dev/null +++ b/apps/tutorials/LowPowerSensing/Sampler/Makefile @@ -0,0 +1,5 @@ +COMPONENT=LowPowerSensingPeriodicSamplerAppC +CFLAGS += -I.. -I../sampleLog -I../universal_sensors +CFLAGS += -DCC1K_DEFAULT_FREQ=CC1K_914_077_MHZ + +include $(MAKERULES) diff --git a/apps/tutorials/LowPowerSensing/Sampler/volumes-at45db.xml b/apps/tutorials/LowPowerSensing/Sampler/volumes-at45db.xml new file mode 100644 index 00000000..105e58ae --- /dev/null +++ b/apps/tutorials/LowPowerSensing/Sampler/volumes-at45db.xml @@ -0,0 +1,3 @@ + + + diff --git a/apps/tutorials/LowPowerSensing/Sampler/volumes-stm25p.xml b/apps/tutorials/LowPowerSensing/Sampler/volumes-stm25p.xml new file mode 100644 index 00000000..73ed4855 --- /dev/null +++ b/apps/tutorials/LowPowerSensing/Sampler/volumes-stm25p.xml @@ -0,0 +1,3 @@ + + + diff --git a/apps/tutorials/LowPowerSensing/java/Constants.class b/apps/tutorials/LowPowerSensing/java/Constants.class new file mode 100644 index 0000000000000000000000000000000000000000..d67b9533bec1cacac6523bdd3dd93a8547168749 GIT binary patch literal 372 zcmYk1%}#?*5QWb`3zkw!{deKQow~5mwK1VBHYAkRLRq*Wv=T#ukhI`?xzf1s0bKb+ z#-WL%i#s>pIddj6-@l(<0IqSYK*WKJLm5W|ZR8GvhnYDu1J`;q3DhIB`dPZp!!-B9 zq=-b0-4HsiF`C$xGYl-pGpD{`bF<54^MlQv;qnB}@T{>D7=yvIOo5=<6T1qqCjStm z+c=H$JA!zA;S*~8>?tC&?Kq8`;$#Jq>8meeRCp0RR zpqF|#3Df89c)pAlInE&Ptw0SY{OY`p#3Vpw-a(^cg}J%qtIVw}U*k?*5IWZmPdME$ XP``W!y>0H?U%>t!WWGOQ literal 0 HcmV?d00001 diff --git a/apps/tutorials/LowPowerSensing/java/Constants.java b/apps/tutorials/LowPowerSensing/java/Constants.java new file mode 100644 index 00000000..5798537f --- /dev/null +++ b/apps/tutorials/LowPowerSensing/java/Constants.java @@ -0,0 +1,12 @@ +/** + * This class is automatically generated by ncg. DO NOT EDIT THIS FILE. + * This class includes values of some nesC constants from + * ../LowPowerSensingConstants.h. + */ + +public class Constants { + public static final byte MSG_QUEUE_SIZE = 50; + public static final short SAMPLING_INTERVAL = 3000; + public static final byte BASE_STATION_ADDR = 0; + public static final short LPL_INTERVAL = 2000; +} diff --git a/apps/tutorials/LowPowerSensing/java/LowPowerSensingApp.class b/apps/tutorials/LowPowerSensing/java/LowPowerSensingApp.class new file mode 100644 index 0000000000000000000000000000000000000000..9c1b6c0d7a2f59ae7ba04cf5f44ebbd352f1d762 GIT binary patch literal 2019 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 yBy&~)|3W+2|5FeD>FW0|pJk literal 0 HcmV?d00001 diff --git a/apps/tutorials/LowPowerSensing/java/LowPowerSensingApp.java b/apps/tutorials/LowPowerSensing/java/LowPowerSensingApp.java new file mode 100644 index 00000000..e1d30a60 --- /dev/null +++ b/apps/tutorials/LowPowerSensing/java/LowPowerSensingApp.java @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2007 Stanford University. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * - Neither the name of the Stanford University nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD + * UNIVERSITY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @author Kevin Klues + * @date July 24, 2007 + */ + +import net.tinyos.message.*; +import net.tinyos.util.*; +import java.io.*; +/** +*/ + +public class LowPowerSensingApp implements MessageListener +{ + MoteIF mote; + + /* Main entry point */ + void run() { + mote = new MoteIF(PrintStreamMessenger.err); + mote.registerListener(new SerialSampleMsg(), this); + } + + synchronized public void messageReceived(int dest_addr, Message msg) { + if (msg instanceof SerialSampleMsg) { + System.out.print(msg.toString()); + } + } + + synchronized public void requestSamples(int addr) { + SerialRequestSamplesMsg msg = new SerialRequestSamplesMsg(); + msg.set_addr(addr); + try { + mote.send(MoteIF.TOS_BCAST_ADDR, msg); + } + catch (IOException e) { + System.err.println("Cannot send message to mote"); + } + } + + public static void main(String[] args) { + LowPowerSensingApp me = new LowPowerSensingApp(); + me.run(); + + InputStreamReader cin = new InputStreamReader(System.in); + BufferedReader in = new BufferedReader(cin); + String input = ""; + + System.out.print("Enter 's' to request samples\n"); + System.out.print(">> "); + for(;;) { + try { + input = in.readLine(); + if(input.equals("s")) { + System.out.print("Enter Address: "); + input = in.readLine(); + me.requestSamples(Integer.parseInt(input)); + } + else System.out.println("Invalid Input!!!!: "); + System.out.print(">> "); + } + catch (IOException e) { + System.out.print("Error On Input!!"); + } + } + } +} diff --git a/apps/tutorials/LowPowerSensing/java/Makefile b/apps/tutorials/LowPowerSensing/java/Makefile new file mode 100644 index 00000000..5bf45739 --- /dev/null +++ b/apps/tutorials/LowPowerSensing/java/Makefile @@ -0,0 +1,31 @@ +GEN=SerialRequestSamplesMsg.java SerialSampleMsg.java Constants.java + +SENSOR_DIR = universal_sensors +SENSOR_DEPS = ../$(SENSOR_DIR)/SensorSample.h + +all: LowPowerSensingApp.jar + +LowPowerSensingApp.jar: LowPowerSensingApp.class + jar cf $@ *.class + +SerialRequestSamplesMsg.java: ../LowPowerSensingMsgs.h $(SENSOR_DEPS) + mig -I../$(SENSOR_DIR) -target=null \ +-java-classname=SerialRequestSamplesMsg java ../LowPowerSensingMsgs.h serial_request_samples_msg -o $@ + +SerialSampleMsg.java: ../LowPowerSensingMsgs.h $(SENSOR_DEPS) + mig -I../$(SENSOR_DIR) -target=null \ +-java-classname=SerialSampleMsg java ../LowPowerSensingMsgs.h serial_sample_msg -o $@ + +Constants.java: ../LowPowerSensingConstants.h + ncg -I../$(SENSOR_DIR) -DLOWPOWERSENSING_JAVA_MAKEFILE -target=null \ +-java-classname=Constants java ../LowPowerSensingConstants.h BASE_STATION_ADDR SAMPLING_INTERVAL \ +MSG_QUEUE_SIZE LPL_INTERVAL -o $@ + +LowPowerSensingApp.class: $(wildcard *.java) $(GEN) + javac *.java + +clean: + rm -f *.class $(GEN) + +veryclean: clean + rm LowPowerSensingApp.jar diff --git a/apps/tutorials/LowPowerSensing/java/SerialRequestSamplesMsg.class b/apps/tutorials/LowPowerSensing/java/SerialRequestSamplesMsg.class new file mode 100644 index 0000000000000000000000000000000000000000..02d38e95c630f6c394142e78e0e023eaec6c8ccd GIT binary patch literal 2559 zcma)7&rcgi6#m9GwpkY2Kqw86#*iN@cEOOOKl#yOFo~%R2{tr9Qg^|FwUxc5-gO1- ztx}}+mgbUMuf3#Ft4bzHrAob3y|ky^`ma=dvtI0#!3josv-9Tr=6mzro8iy@Ui=1N z8U+a#u_)nnEQzm#Fw4T+7UqsHNk3M6_((!0Qo^MDSQUgd33qYNk9Fb9_>lEuL-;p^ z`B<3y!fXk%?Zb`_4;U^iC6*U9QrTQOk;yFFPUJGl?F0i$GITGNb;DG3b5ku=xtqfC zGWZtKx$M^6gqS{I@Xl(wX3jIXmGMmm&tf^x8GZ$MC`o(V ziHo^c*@;^YpZKu8!b(c#X3W&|qp}ezal=pxJeIDHGZtjz~VkiJ|vI-0AGGLvZ@~9U(aV0TGDPL1kHC z2#BDZZjZ7e(jT-UbT0HY;&ghYOu1UwT<#2{qG_|Pj8Bkbkiy{|QN6jT zLm4+Q?Zc-sRO~Xi9!fHzc#}bC?qgLpspt9OTGd?JkC&@@-bfto@dHyU>kJ{rYXEOu`>*|?_Y*awUj+N;2CaG_p1j7T+cI1D5o3rbkEx7 zr`8QLkCZBl7Vk34clhB+!}n8lPj5)aqwd&9>SjEVDDo25DFo|6Qip`7Lt2)+bXTcM zFhbA8MY`=SvV#}`b$~UyMDsTs^UE}6qBdkl2{B0wMq?ln@*aaldhnzM*U#jk4iJ8b zH>3w%^r9Pm7Wb;nogl7@R=XoZ?WqIkpwMJn_L@zdq;18H%Rs-$=2~BaNw1Rh8qw%d+2qG|sU7Q0fPG(oS4&9oKgTEcz4G-;FWKbPp-6;vS9lz8Rz( z0-LmYpVqf%b%)j;V4Yr_PE1hW)%$OdM)7mGpOLL|y_T;;xY#*xCgG;&fAXvL`-*V% zM7$FBH6iGcvT;}F1R}z&$a7o>g=*;krZv!S32+N1mqMY&6PH4+6NVnu@LKaaN!Hq9 zbm2P+=dFfJBMlv`yFVq|+YOw!*y867g<65%6Y!mLQ5N;pf3&PP` zYv=1F0sc-9dZ=ySsGV4e@-z?%Q(}Llb2%H}51P$k-o}qnUd0U(g&_RpGt&AOB>YX$ ge9(xd5w)*1TmKO5!v?Myb+{GyFX=Ckt_$)10n{?HAOHXW literal 0 HcmV?d00001 diff --git a/apps/tutorials/LowPowerSensing/java/SerialRequestSamplesMsg.java b/apps/tutorials/LowPowerSensing/java/SerialRequestSamplesMsg.java new file mode 100644 index 00000000..486d2e71 --- /dev/null +++ b/apps/tutorials/LowPowerSensing/java/SerialRequestSamplesMsg.java @@ -0,0 +1,224 @@ +/** + * This class is automatically generated by mig. DO NOT EDIT THIS FILE. + * This class implements a Java interface to the 'SerialRequestSamplesMsg' + * message type. + */ + +public class SerialRequestSamplesMsg extends net.tinyos.message.Message { + + /** The default size of this message type in bytes. */ + public static final int DEFAULT_MESSAGE_SIZE = 6; + + /** The Active Message type associated with this message. */ + public static final int AM_TYPE = 146; + + /** Create a new SerialRequestSamplesMsg of size 6. */ + public SerialRequestSamplesMsg() { + super(DEFAULT_MESSAGE_SIZE); + amTypeSet(AM_TYPE); + } + + /** Create a new SerialRequestSamplesMsg of the given data_length. */ + public SerialRequestSamplesMsg(int data_length) { + super(data_length); + amTypeSet(AM_TYPE); + } + + /** + * Create a new SerialRequestSamplesMsg with the given data_length + * and base offset. + */ + public SerialRequestSamplesMsg(int data_length, int base_offset) { + super(data_length, base_offset); + amTypeSet(AM_TYPE); + } + + /** + * Create a new SerialRequestSamplesMsg using the given byte array + * as backing store. + */ + public SerialRequestSamplesMsg(byte[] data) { + super(data); + amTypeSet(AM_TYPE); + } + + /** + * Create a new SerialRequestSamplesMsg using the given byte array + * as backing store, with the given base offset. + */ + public SerialRequestSamplesMsg(byte[] data, int base_offset) { + super(data, base_offset); + amTypeSet(AM_TYPE); + } + + /** + * Create a new SerialRequestSamplesMsg using the given byte array + * as backing store, with the given base offset and data length. + */ + public SerialRequestSamplesMsg(byte[] data, int base_offset, int data_length) { + super(data, base_offset, data_length); + amTypeSet(AM_TYPE); + } + + /** + * Create a new SerialRequestSamplesMsg embedded in the given message + * at the given base offset. + */ + public SerialRequestSamplesMsg(net.tinyos.message.Message msg, int base_offset) { + super(msg, base_offset, DEFAULT_MESSAGE_SIZE); + amTypeSet(AM_TYPE); + } + + /** + * Create a new SerialRequestSamplesMsg embedded in the given message + * at the given base offset and length. + */ + public SerialRequestSamplesMsg(net.tinyos.message.Message msg, int base_offset, int data_length) { + super(msg, base_offset, data_length); + amTypeSet(AM_TYPE); + } + + /** + /* Return a String representation of this message. Includes the + * message type name and the non-indexed field values. + */ + public String toString() { + String s = "Message \n"; + try { + s += " [addr=0x"+Long.toHexString(get_addr())+"]\n"; + } catch (ArrayIndexOutOfBoundsException aioobe) { /* Skip field */ } + try { + s += " [sample_num=0x"+Long.toHexString(get_sample_num())+"]\n"; + } catch (ArrayIndexOutOfBoundsException aioobe) { /* Skip field */ } + return s; + } + + // Message-type-specific access methods appear below. + + ///////////////////////////////////////////////////////// + // Accessor methods for field: addr + // Field type: int, unsigned + // Offset (bits): 0 + // Size (bits): 16 + ///////////////////////////////////////////////////////// + + /** + * Return whether the field 'addr' is signed (false). + */ + public static boolean isSigned_addr() { + return false; + } + + /** + * Return whether the field 'addr' is an array (false). + */ + public static boolean isArray_addr() { + return false; + } + + /** + * Return the offset (in bytes) of the field 'addr' + */ + public static int offset_addr() { + return (0 / 8); + } + + /** + * Return the offset (in bits) of the field 'addr' + */ + public static int offsetBits_addr() { + return 0; + } + + /** + * Return the value (as a int) of the field 'addr' + */ + public int get_addr() { + return (int)getUIntBEElement(offsetBits_addr(), 16); + } + + /** + * Set the value of the field 'addr' + */ + public void set_addr(int value) { + setUIntBEElement(offsetBits_addr(), 16, value); + } + + /** + * Return the size, in bytes, of the field 'addr' + */ + public static int size_addr() { + return (16 / 8); + } + + /** + * Return the size, in bits, of the field 'addr' + */ + public static int sizeBits_addr() { + return 16; + } + + ///////////////////////////////////////////////////////// + // Accessor methods for field: sample_num + // Field type: long, unsigned + // Offset (bits): 16 + // Size (bits): 32 + ///////////////////////////////////////////////////////// + + /** + * Return whether the field 'sample_num' is signed (false). + */ + public static boolean isSigned_sample_num() { + return false; + } + + /** + * Return whether the field 'sample_num' is an array (false). + */ + public static boolean isArray_sample_num() { + return false; + } + + /** + * Return the offset (in bytes) of the field 'sample_num' + */ + public static int offset_sample_num() { + return (16 / 8); + } + + /** + * Return the offset (in bits) of the field 'sample_num' + */ + public static int offsetBits_sample_num() { + return 16; + } + + /** + * Return the value (as a long) of the field 'sample_num' + */ + public long get_sample_num() { + return (long)getUIntBEElement(offsetBits_sample_num(), 32); + } + + /** + * Set the value of the field 'sample_num' + */ + public void set_sample_num(long value) { + setUIntBEElement(offsetBits_sample_num(), 32, value); + } + + /** + * Return the size, in bytes, of the field 'sample_num' + */ + public static int size_sample_num() { + return (32 / 8); + } + + /** + * Return the size, in bits, of the field 'sample_num' + */ + public static int sizeBits_sample_num() { + return 32; + } + +} diff --git a/apps/tutorials/LowPowerSensing/java/SerialSampleMsg.class b/apps/tutorials/LowPowerSensing/java/SerialSampleMsg.class new file mode 100644 index 0000000000000000000000000000000000000000..da8340ded9273a5ef061e44ab5f9fbb578ad212b GIT binary patch literal 3293 zcma)8&r@4f6#gzhk~9Pe6v~fK8>mW1gkXz5p;gj`HZ_5^p;$`W^p!l~tKlUkFBKfe zU1wal(@ovEa-*YeprfNJ7mn_9<<7srojb?zyDyKt^d)J5nR9c``OZD(JNMj^{QBSb zKLL0V6)(oH>_q@8^3!E0u1IlJinJ7~9$a%{&5I*=TZ-!*tV@R*UTol|2e+j1wi_7_ z?nu4j!Ckp-N|BX9m10YZoD}c4p}BESVBmawY4KWeHIs^`(~B44nRMbtTtFlQy3ZB# zvZ3h4nv$=m?ab99;9g8+R@X1b<@TX~YeCaBZ%bnG<~;Fj&7^vvXWDysp>j!LdKsA zF)<#akTy!1o+HK3RPvs3Uy0@wJr}KN=LPz-a$3vjYBp0YZDy2gwq&xnA>h}_i=~pX zTW9DkY;BcQqfSG@tkKb`KBgJvI-4)|7}WQ;XLniqK&?af$-U!*Q9C(hyO<}uy6BZ{ zfstB%jke)~L>o~h2hF4#^(1;pV9?~yXzd7Hk{5Zb%Bj&lYLja;lE}doSVm3H z+?U-ZFzh60n}!@5ZA+jDMcX=1&#+EiPt8^jK1Rvbk2El{ZQgXDQrc9PG}-e5X|<#& z`LszbRnE=GCiLMXCVhBUijxRQF(pM4iBYRRQ0UDbg1!tH$Hi*N__b}HtA$RPKYj}a8cbkm=}X=>Ba*& z7T7-561owK$Mfp8sxt+1p7C|~*+LGJi=&QD1LK^wV;q)k7{PHo1A!CfF3A0O-F|{Q zA#afKIU;80A-ML0{hob@a33D-q3t_r1fG|A$PwHJ7y8kSqo(hq#+Hi0K+`2peJ8 z&KAC>81^*7&Y8aQ1X-ylI`|Lth9hIg_u*>cJP$V(Shh2!^9z>qEL|mEKb>Wv-7UP& z!-F__v1EErHxJ#)ImOV+481}(K0C|#7pv4C_Ir{);K=$uypcV0_4_Eod+2`f2t9J& zOR)!k@=J82>T&&5+|j4N2CA^ZX2(UoHFKEcjr8$GmT`saRoure*J__lkT|eL+;vQ1 zov01sZW48yxC}nP9sc&1|xk`hF;V5 zDZ20((|NTPrj~Z6^YqV&d##2Gn8^U`e!mm=1%a<0qF&z+H-8A+9&rn`z^xPfkvI-$ zi~bW5{FxBWehWBZ71ql-jrfBs?AMM4_>IUnv1s8ZSy%b;Zr@Xd6=h E1AOLD0{{R3 literal 0 HcmV?d00001 diff --git a/apps/tutorials/LowPowerSensing/java/SerialSampleMsg.java b/apps/tutorials/LowPowerSensing/java/SerialSampleMsg.java new file mode 100644 index 00000000..c290b3df --- /dev/null +++ b/apps/tutorials/LowPowerSensing/java/SerialSampleMsg.java @@ -0,0 +1,290 @@ +/** + * This class is automatically generated by mig. DO NOT EDIT THIS FILE. + * This class implements a Java interface to the 'SerialSampleMsg' + * message type. + */ + +public class SerialSampleMsg extends net.tinyos.message.Message { + + /** The default size of this message type in bytes. */ + public static final int DEFAULT_MESSAGE_SIZE = 8; + + /** The Active Message type associated with this message. */ + public static final int AM_TYPE = 153; + + /** Create a new SerialSampleMsg of size 8. */ + public SerialSampleMsg() { + super(DEFAULT_MESSAGE_SIZE); + amTypeSet(AM_TYPE); + } + + /** Create a new SerialSampleMsg of the given data_length. */ + public SerialSampleMsg(int data_length) { + super(data_length); + amTypeSet(AM_TYPE); + } + + /** + * Create a new SerialSampleMsg with the given data_length + * and base offset. + */ + public SerialSampleMsg(int data_length, int base_offset) { + super(data_length, base_offset); + amTypeSet(AM_TYPE); + } + + /** + * Create a new SerialSampleMsg using the given byte array + * as backing store. + */ + public SerialSampleMsg(byte[] data) { + super(data); + amTypeSet(AM_TYPE); + } + + /** + * Create a new SerialSampleMsg using the given byte array + * as backing store, with the given base offset. + */ + public SerialSampleMsg(byte[] data, int base_offset) { + super(data, base_offset); + amTypeSet(AM_TYPE); + } + + /** + * Create a new SerialSampleMsg using the given byte array + * as backing store, with the given base offset and data length. + */ + public SerialSampleMsg(byte[] data, int base_offset, int data_length) { + super(data, base_offset, data_length); + amTypeSet(AM_TYPE); + } + + /** + * Create a new SerialSampleMsg embedded in the given message + * at the given base offset. + */ + public SerialSampleMsg(net.tinyos.message.Message msg, int base_offset) { + super(msg, base_offset, DEFAULT_MESSAGE_SIZE); + amTypeSet(AM_TYPE); + } + + /** + * Create a new SerialSampleMsg embedded in the given message + * at the given base offset and length. + */ + public SerialSampleMsg(net.tinyos.message.Message msg, int base_offset, int data_length) { + super(msg, base_offset, data_length); + amTypeSet(AM_TYPE); + } + + /** + /* Return a String representation of this message. Includes the + * message type name and the non-indexed field values. + */ + public String toString() { + String s = "Message \n"; + try { + s += " [src_addr=0x"+Long.toHexString(get_src_addr())+"]\n"; + } catch (ArrayIndexOutOfBoundsException aioobe) { /* Skip field */ } + try { + s += " [sample.sample_num=0x"+Long.toHexString(get_sample_sample_num())+"]\n"; + } catch (ArrayIndexOutOfBoundsException aioobe) { /* Skip field */ } + try { + s += " [sample.sin_value=0x"+Long.toHexString(get_sample_sin_value())+"]\n"; + } catch (ArrayIndexOutOfBoundsException aioobe) { /* Skip field */ } + return s; + } + + // Message-type-specific access methods appear below. + + ///////////////////////////////////////////////////////// + // Accessor methods for field: src_addr + // Field type: int + // Offset (bits): 0 + // Size (bits): 16 + ///////////////////////////////////////////////////////// + + /** + * Return whether the field 'src_addr' is signed (false). + */ + public static boolean isSigned_src_addr() { + return false; + } + + /** + * Return whether the field 'src_addr' is an array (false). + */ + public static boolean isArray_src_addr() { + return false; + } + + /** + * Return the offset (in bytes) of the field 'src_addr' + */ + public static int offset_src_addr() { + return (0 / 8); + } + + /** + * Return the offset (in bits) of the field 'src_addr' + */ + public static int offsetBits_src_addr() { + return 0; + } + + /** + * Return the value (as a int) of the field 'src_addr' + */ + public int get_src_addr() { + return (int)getUIntBEElement(offsetBits_src_addr(), 16); + } + + /** + * Set the value of the field 'src_addr' + */ + public void set_src_addr(int value) { + setUIntBEElement(offsetBits_src_addr(), 16, value); + } + + /** + * Return the size, in bytes, of the field 'src_addr' + */ + public static int size_src_addr() { + return (16 / 8); + } + + /** + * Return the size, in bits, of the field 'src_addr' + */ + public static int sizeBits_src_addr() { + return 16; + } + + ///////////////////////////////////////////////////////// + // Accessor methods for field: sample.sample_num + // Field type: long + // Offset (bits): 16 + // Size (bits): 32 + ///////////////////////////////////////////////////////// + + /** + * Return whether the field 'sample.sample_num' is signed (false). + */ + public static boolean isSigned_sample_sample_num() { + return false; + } + + /** + * Return whether the field 'sample.sample_num' is an array (false). + */ + public static boolean isArray_sample_sample_num() { + return false; + } + + /** + * Return the offset (in bytes) of the field 'sample.sample_num' + */ + public static int offset_sample_sample_num() { + return (16 / 8); + } + + /** + * Return the offset (in bits) of the field 'sample.sample_num' + */ + public static int offsetBits_sample_sample_num() { + return 16; + } + + /** + * Return the value (as a long) of the field 'sample.sample_num' + */ + public long get_sample_sample_num() { + return (long)getUIntBEElement(offsetBits_sample_sample_num(), 32); + } + + /** + * Set the value of the field 'sample.sample_num' + */ + public void set_sample_sample_num(long value) { + setUIntBEElement(offsetBits_sample_sample_num(), 32, value); + } + + /** + * Return the size, in bytes, of the field 'sample.sample_num' + */ + public static int size_sample_sample_num() { + return (32 / 8); + } + + /** + * Return the size, in bits, of the field 'sample.sample_num' + */ + public static int sizeBits_sample_sample_num() { + return 32; + } + + ///////////////////////////////////////////////////////// + // Accessor methods for field: sample.sin_value + // Field type: int + // Offset (bits): 48 + // Size (bits): 16 + ///////////////////////////////////////////////////////// + + /** + * Return whether the field 'sample.sin_value' is signed (false). + */ + public static boolean isSigned_sample_sin_value() { + return false; + } + + /** + * Return whether the field 'sample.sin_value' is an array (false). + */ + public static boolean isArray_sample_sin_value() { + return false; + } + + /** + * Return the offset (in bytes) of the field 'sample.sin_value' + */ + public static int offset_sample_sin_value() { + return (48 / 8); + } + + /** + * Return the offset (in bits) of the field 'sample.sin_value' + */ + public static int offsetBits_sample_sin_value() { + return 48; + } + + /** + * Return the value (as a int) of the field 'sample.sin_value' + */ + public int get_sample_sin_value() { + return (int)getUIntBEElement(offsetBits_sample_sin_value(), 16); + } + + /** + * Set the value of the field 'sample.sin_value' + */ + public void set_sample_sin_value(int value) { + setUIntBEElement(offsetBits_sample_sin_value(), 16, value); + } + + /** + * Return the size, in bytes, of the field 'sample.sin_value' + */ + public static int size_sample_sin_value() { + return (16 / 8); + } + + /** + * Return the size, in bits, of the field 'sample.sin_value' + */ + public static int sizeBits_sample_sin_value() { + return 16; + } + +} diff --git a/apps/tutorials/LowPowerSensing/sampleLog/GenericSensorSample.h b/apps/tutorials/LowPowerSensing/sampleLog/GenericSensorSample.h new file mode 100644 index 00000000..d79a1549 --- /dev/null +++ b/apps/tutorials/LowPowerSensing/sampleLog/GenericSensorSample.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2007 Stanford University. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * - Neither the name of the Stanford University nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD + * UNIVERSITY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @author Kevin Klues + * @date July 24, 2007 + */ + +#ifndef GENERICSENSORSAMPLE_H +#define GENERICSENSORSAMPLE_H + +typedef struct generic_sensor_sample { + uint32_t sample_num; + sensor_type_t values[num_sensors]; +} generic_sensor_sample_t; + +typedef union generic_sensor_sample_type_union { + uint8_t u8; + uint16_t u16; + uint32_t u32; + sensor_type_t st; +} generic_sensor_sample_type_union_t; + +#endif //GENERICSENSORSAMPLE_H + diff --git a/apps/tutorials/LowPowerSensing/sampleLog/PeriodicSampleLogger16C.nc b/apps/tutorials/LowPowerSensing/sampleLog/PeriodicSampleLogger16C.nc new file mode 100644 index 00000000..62217258 --- /dev/null +++ b/apps/tutorials/LowPowerSensing/sampleLog/PeriodicSampleLogger16C.nc @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2007 Stanford University. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * - Neither the name of the Stanford University nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD + * UNIVERSITY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @author Kevin Klues + * @date July 24, 2007 + */ + +generic configuration PeriodicSampleLogger16C(uint32_t period, uint8_t num_sensors){ + uses { + interface Boot; + interface LogWrite; + interface Read as Sensor[uint8_t]; + } +} +implementation { + Boot = Logger.Boot; + Sensor = Logger; + + components new PeriodicSampleLoggerP(period, num_sensors, uint16_t) as Logger; + components new TimerMilliC(); + Logger.LogWrite = LogWrite; + Logger.Timer -> TimerMilliC; + + components NoLedsC as LedsC; + Logger.Leds -> LedsC; +} + diff --git a/apps/tutorials/LowPowerSensing/sampleLog/PeriodicSampleLoggerP.nc b/apps/tutorials/LowPowerSensing/sampleLog/PeriodicSampleLoggerP.nc new file mode 100644 index 00000000..23fa83c4 --- /dev/null +++ b/apps/tutorials/LowPowerSensing/sampleLog/PeriodicSampleLoggerP.nc @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2007 Stanford University. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * - Neither the name of the Stanford University nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD + * UNIVERSITY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @author Kevin Klues + * @date July 24, 2007 + */ + +generic module PeriodicSampleLoggerP(uint32_t period_ms, + uint8_t num_sensors, + typedef sensor_type_t) { + uses { + interface Boot; + interface Read as Sensor[uint8_t]; + interface Timer as Timer; + interface LogWrite; + interface Leds; + } +} +implementation { + #include "GenericSensorSample.h" + + generic_sensor_sample_t sample[2]; + generic_sensor_sample_t* current_sample; + uint8_t current_sample_id; + + task void eraseTask(); + task void appendTask(); + + void readSensors() { + int i; + for(i=0; ivalues[i] = val; + call Leds.led1Toggle(); + } + else { + current_sample->values[i] = ((generic_sensor_sample_type_union_t)(0xFFFFFFFF)).st; + call Leds.led2Toggle(); + } + } + + event void LogWrite.appendDone(void* buf, storage_len_t len, bool recordsLost, error_t error){ + if(error != SUCCESS) + post appendTask(); + else ((generic_sensor_sample_t*)buf)->sample_num+=2; + } + event void LogWrite.syncDone(error_t error) {} + default command error_t Sensor.read[uint8_t i]() {return SUCCESS;} +} + diff --git a/apps/tutorials/LowPowerSensing/sampleLog/SampleLogRead.nc b/apps/tutorials/LowPowerSensing/sampleLog/SampleLogRead.nc new file mode 100644 index 00000000..1dd5452f --- /dev/null +++ b/apps/tutorials/LowPowerSensing/sampleLog/SampleLogRead.nc @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2007 Stanford University. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * - Neither the name of the Stanford University nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD + * UNIVERSITY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @author Kevin Klues + * @date July 24, 2007 + */ + +interface SampleLogRead { + command error_t readFirst(); + command error_t readNext(); + event void readDone(sample_type_t* entry, error_t error); +} + diff --git a/apps/tutorials/LowPowerSensing/sampleLog/SampleLogReaderC.nc b/apps/tutorials/LowPowerSensing/sampleLog/SampleLogReaderC.nc new file mode 100644 index 00000000..25d544ed --- /dev/null +++ b/apps/tutorials/LowPowerSensing/sampleLog/SampleLogReaderC.nc @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2007 Stanford University. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * - Neither the name of the Stanford University nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD + * UNIVERSITY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @author Kevin Klues + * @date July 24, 2007 + */ + +generic configuration SampleLogReaderC(typedef sample_type_t) { + provides { + interface SampleLogRead; + } + uses { + interface LogRead; + interface LogWrite; + } +} +implementation { + components new SampleLogReaderP(sample_type_t) as LogReader; + + SampleLogRead = LogReader; + LogReader.LogRead = LogRead; + LogReader.LogWrite = LogWrite; +} + diff --git a/apps/tutorials/LowPowerSensing/sampleLog/SampleLogReaderP.nc b/apps/tutorials/LowPowerSensing/sampleLog/SampleLogReaderP.nc new file mode 100644 index 00000000..3f6886da --- /dev/null +++ b/apps/tutorials/LowPowerSensing/sampleLog/SampleLogReaderP.nc @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2007 Stanford University. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * - Neither the name of the Stanford University nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD + * UNIVERSITY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @author Kevin Klues + * @date July 24, 2007 + */ + +generic module SampleLogReaderP(typedef sample_type_t) { + provides { + interface SampleLogRead; + } + uses { + interface LogRead; + interface LogWrite; + } +} +implementation { + sample_type_t sample; + storage_cookie_t writeLocation; + + command error_t SampleLogRead.readFirst() { + return call LogRead.seek(SEEK_BEGINNING); + } + + command error_t SampleLogRead.readNext() { + atomic writeLocation = call LogWrite.currentOffset(); + if(call LogRead.currentOffset() == writeLocation) + return ECANCEL; + else return call LogRead.read(&sample, sizeof(sample)); + } + + event void LogRead.readDone(void* buf, storage_len_t len, error_t error) { + signal SampleLogRead.readDone((sample_type_t*)buf, error); + } + + event void LogRead.seekDone(error_t error) { + if(error == SUCCESS) { + error = call SampleLogRead.readNext(); + if(error != SUCCESS) + signal SampleLogRead.readDone(&sample, error); + } + else signal SampleLogRead.readDone(&sample, error); + } + event void LogWrite.appendDone(void* buf, storage_len_t len, bool recordsLost, error_t error) {} + event void LogWrite.eraseDone(error_t error) {} + event void LogWrite.syncDone(error_t error) {} + default event void SampleLogRead.readDone(sample_type_t* s, error_t error) {} +} + diff --git a/apps/tutorials/LowPowerSensing/sampleLog/SampleNxConverter.nc b/apps/tutorials/LowPowerSensing/sampleLog/SampleNxConverter.nc new file mode 100644 index 00000000..37154313 --- /dev/null +++ b/apps/tutorials/LowPowerSensing/sampleLog/SampleNxConverter.nc @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2007 Stanford University. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * - Neither the name of the Stanford University nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD + * UNIVERSITY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @author Kevin Klues + * @date July 24, 2007 + */ + +#include "SensorSample.h" +interface SampleNxConverter { + command void copyToNx(nx_sensor_sample_t* dest, sensor_sample_t* src); + command void copyFromNx(sensor_sample_t* dest, nx_sensor_sample_t* src); +} + diff --git a/apps/tutorials/LowPowerSensing/tmote_onboard_sensors/SampleNxConverterC.nc b/apps/tutorials/LowPowerSensing/tmote_onboard_sensors/SampleNxConverterC.nc new file mode 100644 index 00000000..d6c8339d --- /dev/null +++ b/apps/tutorials/LowPowerSensing/tmote_onboard_sensors/SampleNxConverterC.nc @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2007 Stanford University. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * - Neither the name of the Stanford University nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD + * UNIVERSITY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @author Kevin Klues + * @date July 24, 2007 + */ + +#include "SensorSample.h" +module SampleNxConverterC { + provides interface SampleNxConverter; +} +implementation { + command void SampleNxConverter.copyToNx(nx_sensor_sample_t* dest, sensor_sample_t* src) { + dest->sample_num = src->sample_num; + dest->humidity = src->humidity; + dest->temperature = src->temperature; + dest->photo_active = src->photo_active; + dest->total_solar = src->total_solar; + } + command void SampleNxConverter.copyFromNx(sensor_sample_t* dest, nx_sensor_sample_t* src) { + dest->sample_num = src->sample_num; + dest->humidity = src->humidity; + dest->temperature = src->temperature; + dest->photo_active = src->photo_active; + dest->total_solar = src->total_solar; + } +} + diff --git a/apps/tutorials/LowPowerSensing/tmote_onboard_sensors/SamplePeriodicLogC.nc b/apps/tutorials/LowPowerSensing/tmote_onboard_sensors/SamplePeriodicLogC.nc new file mode 100644 index 00000000..5580b5e8 --- /dev/null +++ b/apps/tutorials/LowPowerSensing/tmote_onboard_sensors/SamplePeriodicLogC.nc @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2007 Stanford University. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * - Neither the name of the Stanford University nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD + * UNIVERSITY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @author Kevin Klues + * @date July 24, 2007 + */ + +#include "SensorSample.h" +#include "Storage.h" +generic configuration SamplePeriodicLogC(uint32_t sampling_period, + volume_id_t volume) { + provides{ + interface SampleLogRead; + } +} +implementation { + + //Change sensors based on sensorboard........ + components new PeriodicSampleLogger16C(sampling_period, 4) as PeriodicLogger; + components new SensirionSht11C() as HumidityTempC; + components new HamamatsuS10871TsrC() as PhotoActiveC; + components new HamamatsuS1087ParC() as TotalSolarC; + PeriodicLogger.Sensor[0] -> HumidityTempC.Humidity; + PeriodicLogger.Sensor[1] -> HumidityTempC.Temperature; + PeriodicLogger.Sensor[2] -> PhotoActiveC; + PeriodicLogger.Sensor[3] -> TotalSolarC; + + //Don't change........ just copy + components MainC; + components new LogStorageC(volume, TRUE); + components new SampleLogReaderC(sensor_sample_t) as LogReader; + SampleLogRead = LogReader; + MainC.Boot <- PeriodicLogger; + PeriodicLogger.LogWrite -> LogStorageC; + LogReader.LogRead -> LogStorageC; + LogReader.LogWrite -> LogStorageC; + +} + diff --git a/apps/tutorials/LowPowerSensing/tmote_onboard_sensors/SensorSample.h b/apps/tutorials/LowPowerSensing/tmote_onboard_sensors/SensorSample.h new file mode 100644 index 00000000..45c0e895 --- /dev/null +++ b/apps/tutorials/LowPowerSensing/tmote_onboard_sensors/SensorSample.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2007 Stanford University. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * - Neither the name of the Stanford University nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD + * UNIVERSITY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @author Kevin Klues + * @date July 24, 2007 + */ + +#ifndef SENSORSAMPLE_H +#define SENSORSAMPLE_H + +typedef struct sensor_sample { + uint32_t sample_num; + uint16_t humidity; + uint16_t temperature; + uint16_t photo_active; + uint16_t total_solar; +} sensor_sample_t; + +typedef nx_struct nx_sensor_sample { + nx_uint32_t sample_num; + nx_uint16_t humidity; + nx_uint16_t temperature; + nx_uint16_t photo_active; + nx_uint16_t total_solar; +} nx_sensor_sample_t; + +#endif //SENSORSAMPLE_H + diff --git a/apps/tutorials/LowPowerSensing/universal_sensors/SampleNxConverterC.nc b/apps/tutorials/LowPowerSensing/universal_sensors/SampleNxConverterC.nc new file mode 100644 index 00000000..f9355342 --- /dev/null +++ b/apps/tutorials/LowPowerSensing/universal_sensors/SampleNxConverterC.nc @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2007 Stanford University. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * - Neither the name of the Stanford University nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD + * UNIVERSITY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @author Kevin Klues + * @date July 24, 2007 + */ + +#include "SensorSample.h" +module SampleNxConverterC { + provides interface SampleNxConverter; +} +implementation { + command void SampleNxConverter.copyToNx(nx_sensor_sample_t* dest, sensor_sample_t* src) { + dest->sample_num = src->sample_num; + dest->sin_value = src->sin_value; + } + command void SampleNxConverter.copyFromNx(sensor_sample_t* dest, nx_sensor_sample_t* src) { + dest->sample_num = src->sample_num; + dest->sin_value = src->sin_value; + } +} + diff --git a/apps/tutorials/LowPowerSensing/universal_sensors/SamplePeriodicLogC.nc b/apps/tutorials/LowPowerSensing/universal_sensors/SamplePeriodicLogC.nc new file mode 100644 index 00000000..f131cecb --- /dev/null +++ b/apps/tutorials/LowPowerSensing/universal_sensors/SamplePeriodicLogC.nc @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2007 Stanford University. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * - Neither the name of the Stanford University nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD + * UNIVERSITY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @author Kevin Klues + * @date July 24, 2007 + */ + +#include "SensorSample.h" +#include "Storage.h" +generic configuration SamplePeriodicLogC(uint32_t sampling_period, volume_id_t volume) { + provides{ + interface SampleLogRead; + } +} +implementation { + + //Change sensors based on sensorboard........ + components new PeriodicSampleLogger16C(sampling_period, 1) as PeriodicLogger; + components new SineSensorC(); + PeriodicLogger.Sensor[0] -> SineSensorC; + + //Don't change..... just copy for different sensorboard implementations + components MainC; + components new LogStorageC(volume, TRUE); + components new SampleLogReaderC(sensor_sample_t) as LogReader; + MainC.Boot <- PeriodicLogger; + PeriodicLogger.LogWrite -> LogStorageC; + SampleLogRead = LogReader; + LogReader.LogRead -> LogStorageC; + LogReader.LogWrite -> LogStorageC; +} + diff --git a/apps/tutorials/LowPowerSensing/universal_sensors/SensorSample.h b/apps/tutorials/LowPowerSensing/universal_sensors/SensorSample.h new file mode 100644 index 00000000..8727eabc --- /dev/null +++ b/apps/tutorials/LowPowerSensing/universal_sensors/SensorSample.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2007 Stanford University. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * - Neither the name of the Stanford University nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD + * UNIVERSITY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @author Kevin Klues + * @date July 24, 2007 + */ + +#ifndef SENSORSAMPLE_H +#define SENSORSAMPLE_H + +typedef struct sensor_sample { + uint32_t sample_num; + uint16_t sin_value; +} sensor_sample_t; + +typedef nx_struct nx_sensor_sample { + nx_uint32_t sample_num; + nx_uint16_t sin_value; +} nx_sensor_sample_t; + +#endif //SENSORSAMPLE_H + -- 2.39.2