From 6ea31d949b38c709b3494682a5bae3dad7ebc416 Mon Sep 17 00:00:00 2001 From: amaxilat Date: Sat, 19 May 2012 10:57:03 +0300 Subject: [PATCH] commenting applications --- Doxyfile | 2 +- TelosB/collector/src/collector.cpp | 100 ++++-- doc/pages/mainpage.dox | 42 +++ iSense/{ => Makefiles}/Makefile | 0 iSense/{ => Makefiles}/Makefile.contiki | 0 iSense/{ => Makefiles}/Makefile.feuerware | 0 iSense/{ => Makefiles}/Makefile.isense | 0 iSense/{ => Makefiles}/Makefile.isense5148 | 0 iSense/{ => Makefiles}/Makefile.local | 0 iSense/{ => Makefiles}/Makefile.lorien | 0 iSense/{ => Makefiles}/Makefile.pc | 0 iSense/{ => Makefiles}/Makefile.scw | 0 iSense/{ => Makefiles}/Makefile.shawn | 0 iSense/{ => Makefiles}/Makefile.template | 0 iSense/{ => Makefiles}/Makefile.tinyos.gnode | 0 iSense/{ => Makefiles}/Makefile.tinyos.micaz | 0 iSense/{ => Makefiles}/Makefile.tinyos.telosb | 0 iSense/{ => Makefiles}/Makefile.tinyos.tossim | 0 iSense/{ => Makefiles}/Makefile.trisos | 0 iSense/collector/Makefile | 2 +- iSense/collector/collector.cpp | 297 +++++++++++------- iSense/isense_test/Makefile | 2 +- iSense/isense_test/collector_message.h | 246 --------------- iSense/isense_test/sensor_test.cpp | 48 +-- messages/collector_message.h | 246 --------------- messages/collector_message_new.h | 119 ++++--- messages/gateway_beacon_message.h | 62 ++++ 27 files changed, 461 insertions(+), 705 deletions(-) create mode 100644 doc/pages/mainpage.dox rename iSense/{ => Makefiles}/Makefile (100%) rename iSense/{ => Makefiles}/Makefile.contiki (100%) rename iSense/{ => Makefiles}/Makefile.feuerware (100%) rename iSense/{ => Makefiles}/Makefile.isense (100%) rename iSense/{ => Makefiles}/Makefile.isense5148 (100%) rename iSense/{ => Makefiles}/Makefile.local (100%) rename iSense/{ => Makefiles}/Makefile.lorien (100%) rename iSense/{ => Makefiles}/Makefile.pc (100%) rename iSense/{ => Makefiles}/Makefile.scw (100%) rename iSense/{ => Makefiles}/Makefile.shawn (100%) rename iSense/{ => Makefiles}/Makefile.template (100%) rename iSense/{ => Makefiles}/Makefile.tinyos.gnode (100%) rename iSense/{ => Makefiles}/Makefile.tinyos.micaz (100%) rename iSense/{ => Makefiles}/Makefile.tinyos.telosb (100%) rename iSense/{ => Makefiles}/Makefile.tinyos.tossim (100%) rename iSense/{ => Makefiles}/Makefile.trisos (100%) delete mode 100644 iSense/isense_test/collector_message.h delete mode 100644 messages/collector_message.h create mode 100644 messages/gateway_beacon_message.h diff --git a/Doxyfile b/Doxyfile index 6d2767e..ce09cf4 100644 --- a/Doxyfile +++ b/Doxyfile @@ -581,7 +581,7 @@ WARN_LOGFILE = # directories like "/usr/src/myproject". Separate the files or directories # with spaces. -INPUT = iSense TelosB +INPUT = ./ # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is diff --git a/TelosB/collector/src/collector.cpp b/TelosB/collector/src/collector.cpp index 59e93e8..8eaac9d 100644 --- a/TelosB/collector/src/collector.cpp +++ b/TelosB/collector/src/collector.cpp @@ -31,7 +31,15 @@ using namespace isense; -class iSenseDemoApplication : +/** + * An application that collects periodically readings + * from + * + * TelosB : Light,Infrared,Humidity and Temperature sensors + * and reports them to the + * Uberdust Backend + */ +class TelosBCollectorApp : public isense::Application, public isense::Receiver, public isense::Sender, @@ -40,32 +48,68 @@ public isense::TimeoutHandler, public isense::ButtonHandler, public isense::UartPacketHandler { public: - iSenseDemoApplication(isense::Os& os); - - ~iSenseDemoApplication(); - - ///From isense::Application + /** + * Constructor + * @param os a pointer to the os + */ + TelosBCollectorApp(isense::Os& os); + + /** + * Destructor + */ + ~TelosBCollectorApp(); + + /** + * Boot function executed when device is powered + */ void boot(void); - ///From isense::ButtonHandler + /** + * Executed when a button is pressed + * @param button the button pressed + */ void button_down(uint8 button); - ///From isense::ButtonHandler + /** + * Executed when a button is released + * @param button the button released + */ void button_up(uint8 button); - ///From isense::Receiver + /** + * Called when a new message is received. + * @param len length of the payload received + * @param buf a buffer containing the payload + * @param src_addr the source of the payload + * @param dest_addr the destination of the payload + * @param signal_strength the strenght of the received signal + * @param signal_quality the quality of the received signal + * @param seq_no sequence number of the message + * @param interface id of the radio received from + * @param time the time of the receive event + */ void receive(uint8 len, const uint8 * buf, ISENSE_RADIO_ADDR_TYPE src_addr, ISENSE_RADIO_ADDR_TYPE dest_addr, uint16 signal_strength, uint16 signal_quality, uint8 seq_no, uint8 interface, Time time); - ///From isense::Sender void confirm(uint8 state, uint8 tries, isense::Time time); - ///From isense::Task + /** + * Executed preriodically to report new readings to the backend + * @param userdata unused + */ void execute(void* userdata); - ///From isense::TimeoutHandler + /** + * unused + * @param userdata unused + */ void timeout(void* userdata); - ///From isense::UartPacketHandler + /** + * Handler for uart messages + * @param type the type of the message + * @param buf the buffer containing the data + * @param length the size of the payload + */ void handle_uart_packet(uint8 type, uint8* buf, uint8 length); private: @@ -74,22 +118,22 @@ public isense::UartPacketHandler { //---------------------------------------------------------------------------- -iSenseDemoApplication:: -iSenseDemoApplication(isense::Os& os) +TelosBCollectorApp:: +TelosBCollectorApp(isense::Os& os) : isense::Application(os), telos(NULL) { } //---------------------------------------------------------------------------- -iSenseDemoApplication:: -~iSenseDemoApplication() { +TelosBCollectorApp:: +~TelosBCollectorApp() { } //---------------------------------------------------------------------------- void -iSenseDemoApplication:: +TelosBCollectorApp:: handle_uart_packet(uint8 type, uint8 * mess, uint8 length) { } @@ -97,7 +141,7 @@ handle_uart_packet(uint8 type, uint8 * mess, uint8 length) { //---------------------------------------------------------------------------- void -iSenseDemoApplication:: +TelosBCollectorApp:: boot(void) { os().debug("App::boot "); @@ -110,7 +154,7 @@ boot(void) { os().debug("my id is %x", os().id()); -// telos->add_button_handler(this); + // telos->add_button_handler(this); os().add_task_in(Time(5, 0), this, NULL); @@ -124,14 +168,14 @@ boot(void) { //---------------------------------------------------------------------------- void -iSenseDemoApplication:: +TelosBCollectorApp:: button_down(uint8 button) { telos->led_on(0); os().debug("BUTTON"); } void -iSenseDemoApplication:: +TelosBCollectorApp:: button_up(uint8 button) { telos->led_off(0); } @@ -139,7 +183,7 @@ button_up(uint8 button) { //---------------------------------------------------------------------------- void -iSenseDemoApplication:: +TelosBCollectorApp:: execute(void* userdata) { telos->led_on(1); @@ -149,7 +193,7 @@ execute(void* userdata) { int16 light = telos->light(); int16 inflight = telos->infrared(); - os().debug("node::%x temperature %d ", os().id(), temp/10); + os().debug("node::%x temperature %d ", os().id(), temp / 10); os().debug("node::%x humidity %d ", os().id(), humid); os().debug("node::%x ir %d ", os().id(), inflight); os().debug("node::%x light %d ", os().id(), light); @@ -161,21 +205,21 @@ execute(void* userdata) { //---------------------------------------------------------------------------- void -iSenseDemoApplication:: +TelosBCollectorApp:: receive(uint8 len, const uint8* buf, ISENSE_RADIO_ADDR_TYPE src_addr, ISENSE_RADIO_ADDR_TYPE dest_addr, uint16 signal_strength, uint16 signal_quality, uint8 seq_no, uint8 interface, Time time) { } //---------------------------------------------------------------------------- void -iSenseDemoApplication:: +TelosBCollectorApp:: confirm(uint8 state, uint8 tries, isense::Time time) { } //---------------------------------------------------------------------------- void -iSenseDemoApplication:: +TelosBCollectorApp:: timeout(void* userdata) { } @@ -184,7 +228,7 @@ timeout(void* userdata) { /** */ isense::Application * application_factory(isense::Os & os) { - return new iSenseDemoApplication(os); + return new TelosBCollectorApp(os); } diff --git a/doc/pages/mainpage.dox b/doc/pages/mainpage.dox new file mode 100644 index 0000000..30a0556 --- /dev/null +++ b/doc/pages/mainpage.dox @@ -0,0 +1,42 @@ +/** \mainpage Uberudst - sensorApps + +\section main_intro Introduction + +\section isense iSense Applications + +For the iSense platform we use Wiselib a library for applications to achieve connectivity and between gateway and Wireless devices. All gateway devices operate as intermediates and deliver to the back-end the sensor readings of the wireless devices. + +A new Wiselib message is defined and used to report back the Sensor Readings. Each sensor type uses a different SensorID field in the message header, followed by the SensorValue that may be of a variable size. + +\subsection isense_env Environmental Module + +\subsection isense_pir Security Module + +\subsection isense_weather Weather Module + +\subsection wsn Wireless Network statistics gathering +A second applications responsible for detecting the connectivity between the iSense Sensors also operates simultaneously and reports in the same way network changes ( Bidirectional Link Up and Down ). + +\section telosb TelosB Applications + +The TelosB application (see here) uses the iSense for TelosB Operating System. + + +\section arduino Arduino Applications + +\section more More Info +More information are available on UberdustWiki +*/ diff --git a/iSense/Makefile b/iSense/Makefiles/Makefile similarity index 100% rename from iSense/Makefile rename to iSense/Makefiles/Makefile diff --git a/iSense/Makefile.contiki b/iSense/Makefiles/Makefile.contiki similarity index 100% rename from iSense/Makefile.contiki rename to iSense/Makefiles/Makefile.contiki diff --git a/iSense/Makefile.feuerware b/iSense/Makefiles/Makefile.feuerware similarity index 100% rename from iSense/Makefile.feuerware rename to iSense/Makefiles/Makefile.feuerware diff --git a/iSense/Makefile.isense b/iSense/Makefiles/Makefile.isense similarity index 100% rename from iSense/Makefile.isense rename to iSense/Makefiles/Makefile.isense diff --git a/iSense/Makefile.isense5148 b/iSense/Makefiles/Makefile.isense5148 similarity index 100% rename from iSense/Makefile.isense5148 rename to iSense/Makefiles/Makefile.isense5148 diff --git a/iSense/Makefile.local b/iSense/Makefiles/Makefile.local similarity index 100% rename from iSense/Makefile.local rename to iSense/Makefiles/Makefile.local diff --git a/iSense/Makefile.lorien b/iSense/Makefiles/Makefile.lorien similarity index 100% rename from iSense/Makefile.lorien rename to iSense/Makefiles/Makefile.lorien diff --git a/iSense/Makefile.pc b/iSense/Makefiles/Makefile.pc similarity index 100% rename from iSense/Makefile.pc rename to iSense/Makefiles/Makefile.pc diff --git a/iSense/Makefile.scw b/iSense/Makefiles/Makefile.scw similarity index 100% rename from iSense/Makefile.scw rename to iSense/Makefiles/Makefile.scw diff --git a/iSense/Makefile.shawn b/iSense/Makefiles/Makefile.shawn similarity index 100% rename from iSense/Makefile.shawn rename to iSense/Makefiles/Makefile.shawn diff --git a/iSense/Makefile.template b/iSense/Makefiles/Makefile.template similarity index 100% rename from iSense/Makefile.template rename to iSense/Makefiles/Makefile.template diff --git a/iSense/Makefile.tinyos.gnode b/iSense/Makefiles/Makefile.tinyos.gnode similarity index 100% rename from iSense/Makefile.tinyos.gnode rename to iSense/Makefiles/Makefile.tinyos.gnode diff --git a/iSense/Makefile.tinyos.micaz b/iSense/Makefiles/Makefile.tinyos.micaz similarity index 100% rename from iSense/Makefile.tinyos.micaz rename to iSense/Makefiles/Makefile.tinyos.micaz diff --git a/iSense/Makefile.tinyos.telosb b/iSense/Makefiles/Makefile.tinyos.telosb similarity index 100% rename from iSense/Makefile.tinyos.telosb rename to iSense/Makefiles/Makefile.tinyos.telosb diff --git a/iSense/Makefile.tinyos.tossim b/iSense/Makefiles/Makefile.tinyos.tossim similarity index 100% rename from iSense/Makefile.tinyos.tossim rename to iSense/Makefiles/Makefile.tinyos.tossim diff --git a/iSense/Makefile.trisos b/iSense/Makefiles/Makefile.trisos similarity index 100% rename from iSense/Makefile.trisos rename to iSense/Makefiles/Makefile.trisos diff --git a/iSense/collector/Makefile b/iSense/collector/Makefile index 0b0f6e0..5d3891e 100644 --- a/iSense/collector/Makefile +++ b/iSense/collector/Makefile @@ -15,4 +15,4 @@ all: isense export APP_SRC=collector.cpp export BIN_OUT=collector -include ../Makefile +include ../Makefiles/Makefile diff --git a/iSense/collector/collector.cpp b/iSense/collector/collector.cpp index 27ffa7e..e343358 100644 --- a/iSense/collector/collector.cpp +++ b/iSense/collector/collector.cpp @@ -3,24 +3,39 @@ #include "util/pstl/map_static_vector.h" #include "util/pstl/static_string.h" -//ISENSE SENSORS +#undef WEATHER_COLLECTOR +#undef ENVIRONMENTAL_COLLECTOR +#undef SECURITY_COLLECTOR + +//Uncomment to enable the isense module +#define ENVIRONMENTAL_COLLECTOR +#define SECURITY_COLLECTOR +//#define WEATHER_COLLECTOR + #include +#ifdef ENVIRONMENTAL_COLLECTOR #include #include #include +#endif +#ifdef SECURITY_COLLECTOR #include +#endif +#ifdef WEATHER_COLLECTOR #include +#endif typedef wiselib::OSMODEL Os; -//ND +//neighbor discovery algorithm #include "algorithms/neighbor_discovery/echo.h" typedef wiselib::Echo nb_t; -//MESSAGE_TYPES +//reporting message #include "../../messages/collector_message_new.h" typedef wiselib::CollectorMsg collectorMsg_t; -typedef wiselib::BroadcastMsg broadcastMsg_t; +#include "../../messages/gateway_beacon_message.h" +typedef wiselib::GatewayBeaconMsg broadcastMsg_t; //TYPEDEFS typedef Os::TxRadio::node_id_t node_id_t; @@ -35,52 +50,63 @@ typedef Os::TxRadio::block_data_t block_data_t; #define TASK_TEST 5 #define REVISION 4 +//defines every how many seconds new readings will be reported to the gateway #define REPORTING_INTERVAL 180 -#undef WEATHER_MODULE -#undef ENVIRONMENTAL_MODULE -#undef SECURITY_MODULE -//#define WEATHER_MODULE -#define ENVIRONMENTAL_MODULE -#define SECURITY_MODULE - -class Application +/** + * A wiselib application that collects periodically readings + * from + * + * iSense : Environmental, Security, Weather sensors + * and reports them to the + * Uberdust Backend + * Also collects Link Readings (Neighbor Discovery and Lqis). + */ +class iSenseCollectorApp : public isense::SensorHandler, public isense::Int8DataHandler, public isense::Uint32DataHandler { public: - virtual uint16_t application_id() { + /** + * Returns a unique application id. + * @return the id of the current application + */ + uint16_t application_id() { return 1; } - virtual uint8_t software_revision(void) { + /** + * Returns the current version of the application + * @return the current version + */ + uint8_t software_revision(void) { return REVISION; } //-------------------------------------------------------------- /** - * unused in this context + * Accelerometer sensor, unused in this app * @param value */ void handle_uint32_data(uint32 value) { //nothing } - //-------------------------------------------------------------- - /** - * unused in this context + * Accelerometer sensor, unused in this app * @param value */ void handle_int8_data(int8 value) { //nothing } + //-------------------------------------------------------------- + /** - * boot function + * Initializes the application and the enabled sensor modules. * @param value pointer to os */ void init(Os::AppMainParameter& value) { @@ -96,51 +122,84 @@ public isense::Uint32DataHandler { mygateway_ = 0xffff; -#ifdef WEATHER_MODULE +#ifdef WEATHER_COLLECTOR init_weather_module(value); #endif -#ifdef ENVIRONMENTAL_MODULE +#ifdef ENVIRONMENTAL_COLLECTOR init_environmental_module(value); #endif -#ifdef SECURITY_MODULE +#ifdef SECURITY_COLLECTOR init_security_module(value); #endif - - - - radio_->reg_recv_callback (this); + radio_->reg_recv_callback (this); radio_->set_channel(12); - uart_->reg_read_callback (this); + uart_->reg_read_callback (this); uart_->enable_serial_comm(); - // debug_->debug("INIT "); - nb_.init(*radio_, *clock_, *timer_, *debug_, 2000, 16000, 250, 255); nb_.enable(); - nb_. reg_event_callback ((uint8) 2, nb_t::NEW_NB | nb_t::NEW_NB_BIDI | nb_t::LOST_NB_BIDI | nb_t::DROPPED_NB, this); + nb_. reg_event_callback ((uint8) 2, nb_t::NEW_NB | nb_t::NEW_NB_BIDI | nb_t::LOST_NB_BIDI | nb_t::DROPPED_NB, this); -#ifdef WEATHER_MODULE - timer_->set_timer (10000, this, (void*) 0); +#ifdef WEATHER_COLLECTOR + timer_->set_timer (10000, this, (void*) 0); #endif -#ifdef ENVIRONMENTAL_MODULE - timer_->set_timer (10000, this, (void*) 0); +#ifdef ENVIRONMENTAL_COLLECTOR + timer_->set_timer (10000, this, (void*) 0); #endif if (is_gateway()) { // register task to be called in a minute for periodic sensor readings - timer_->set_timer (1000, this, (void*) 0); + timer_->set_timer (1000, this, (void*) 0); // timer_->set_timer (5000, this, (void*) TASK_TEST); } } + // -------------------------------------------------------------------- +#ifdef WEATHER_COLLECTOR + /** + * Initializes the Weather Sensor Module + * @param value pointer to os + */ void init_weather_module(Os::AppMainParameter& value) { ms_ = new isense::Ms55xx(value); + } + + /** + * Reads sensor values from the Weather Sensor Module + * and reports them to the Gateway node + * @param userdata unused, required for wiselib + */ + void read_weather_sensors(void* userdata) { + // Get the Temperature and Luminance from sensors and debug them + if (radio_->id() != 0xddba) { + timer_->set_timer (REPORTING_INTERVAL * 1000, this, (void*) 0); + } + + ms_ = new isense::Ms55xx(*ospointer); + ms_->reset(); + + int16 temp = ms_->get_temperature(); + int16 bpressure = ms_->read_pressure(); + if (!is_gateway()) { + send_reading(0xffff, "temperature", temp / 10); + send_reading(0xffff, "barometricpressure", bpressure / 10); + } else { + debug_->debug("node::%x temperature %d ", radio_->id(), temp / 10); + debug_->debug("node::%x barometricpressure %d ", radio_->id(), bpressure / 10); + } } +#endif +#ifdef ENVIRONMENTAL_COLLECTOR + + /** + * Initializes the Environmental Sensor Module + * @param value pointer to os + */ void init_environmental_module(Os::AppMainParameter& value) { em_ = new isense::EnvironmentModule(value); if (em_ != NULL) { @@ -155,39 +214,19 @@ public isense::Uint32DataHandler { debug_->debug("em temp"); } } - - } - - void init_security_module(Os::AppMainParameter& value) { - pir_ = new isense::PirSensor(value); - pir_->set_sensor_handler(this); - pir_->set_pir_sensor_int_interval(2000); - if (pir_->enable()) { - pir_sensor_ = true; - debug_->debug("id::%x em pir", radio_->id()); - } - - // accelerometer_ = new isense::LisAccelerometer(value); - // if (accelerometer_ != NULL) { - // accelerometer_->set_mode(MODE_THRESHOLD); - // accelerometer_->set_threshold(25); - // accelerometer_->set_handler(this); - // accelerometer_->enable(); - // } } /** - * Periodically read sensor values and report them - * @param userdata unused + * Reads sensor values from the Environmental Sensor Module + * and reports them to the Gateway node + * @param userdata unused, required for wiselib */ void read_environmental_sensors(void* userdata) { // Get the Temperature and Luminance from sensors and debug them if (radio_->id() != 0xddba) { - timer_->set_timer (REPORTING_INTERVAL * 1000, this, (void*) 0); + timer_->set_timer (REPORTING_INTERVAL * 1000, this, (void*) 0); } - if (!is_gateway()) { - int16 temp = em_->temp_sensor()->temperature(); if (temp < 100) { send_reading(0xffff, "temperature", temp); @@ -196,7 +235,6 @@ public isense::Uint32DataHandler { if (lux < 20000) { send_reading(0xffff, "light", lux); } - } else { int16 temp = em_->temp_sensor()->temperature(); if (temp < 100) { @@ -207,53 +245,54 @@ public isense::Uint32DataHandler { if (lux < 20000) { debug_->debug("node::%x light %d ", radio_->id(), lux); } - - } - } +#endif + +#ifdef SECURITY_COLLECTOR + /** - * Periodically read sensor values from weather module and report them - * @param userdata unused + * Initializes the Security Sensor Module + * @param value pointer to os */ - void read_weather_sensors(void* userdata) { - // Get the Temperature and Luminance from sensors and debug them - if (radio_->id() != 0xddba) { - timer_->set_timer (REPORTING_INTERVAL * 1000, this, (void*) 0); + void init_security_module(Os::AppMainParameter& value) { + pir_ = new isense::PirSensor(value); + pir_->set_sensor_handler(this); + pir_->set_pir_sensor_int_interval(2000); + if (pir_->enable()) { + pir_sensor_ = true; + debug_->debug("id::%x em pir", radio_->id()); } - ms_ = new isense::Ms55xx(*ospointer); - ms_->reset(); - - - int16 temp = ms_->get_temperature(); - int16 bpressure = ms_->read_pressure(); - if (!is_gateway()) { - send_reading(0xffff, "temperature", temp / 10); - - send_reading(0xffff, "barometricpressure", bpressure / 10); - } else { - debug_->debug("node::%x temperature %d ", radio_->id(), temp / 10); - debug_->debug("node::%x barometricpressure %d ", radio_->id(), bpressure / 10); - } + // accelerometer_ = new isense::LisAccelerometer(value); + // if (accelerometer_ != NULL) { + // accelerometer_->set_mode(MODE_THRESHOLD); + // accelerometer_->set_threshold(25); + // accelerometer_->set_handler(this); + // accelerometer_->enable(); + // } } +#endif /** - * Periodically broadcasts the gateway node message beacon - * @param userdata TASK to perform + * Broadcasts the Gateway Beacon + * Used from Gateway nodes to let other devices know him + * forward messages to the backend through him + * @param userdata unused, required for wiselib */ - void broadcast_gateway(void* value) { + void broadcast_gateway(void* userdata) { // debug_->debug("broadcast_gateway"); broadcastMsg_t msg; radio_->send(0xffff, msg.length(), (block_data_t*) & msg); - timer_->set_timer (20 * 1000, this, (void*) 0); + timer_->set_timer (20 * 1000, this, (void*) 0); } protected: /** - * Handles a new sensor reading + * Handles a new Pir Event + * Reports the Reading to the Gateway */ virtual void handle_sensor() { // debug_->debug("pir event"); @@ -265,11 +304,11 @@ public isense::Uint32DataHandler { } /** - * Handles a new neighborhood event - * @param event event type - * @param from neighbor id - * @param len unused - * @param data unused + * Handles a new Neighborhood Event + * @param event event type {NB,NBB,NBL,NBD} + * @param from the node_id of the other side of the link + * @param len unused, concerns the beacon payloads + * @param data unused, concerns the beacon payloads */ void ND_callback(uint8 event, uint16 from, uint8 len, uint8 * data) { if (event == nb_t::NEW_NB_BIDI) { @@ -291,9 +330,10 @@ public isense::Uint32DataHandler { } /** - * Handle a new uart event - * @param len payload length - * @param mess payload buffer + * Handle a new Uart Event + * Used to forward Commands from Uberdust to the WSN + * @param len the length of the payload and node id to forward the command + * @param mess the buffer containing the payload and the node id as {Node_id,payload} */ void handle_uart_msg(Os::Uart::size_t len, Os::Uart::block_data_t *mess) { node_id_t node; @@ -312,33 +352,43 @@ public isense::Uint32DataHandler { } /** - * Handle a new incoming message - * @param src_addr - * @param len - * @param buf + * Handle a new Received Message + * @param src_addr the source of the message + * @param len the length of the message + * @param buf the data of the message */ void receive(node_id_t src_addr, Os::TxRadio::size_t len, block_data_t * buf) { // debug_payload((uint8_t*) buf, len, src_addr); + + //check if an actuation command if (check_led(src_addr, len, buf)) return; + if (!is_gateway()) { - //Executed by nonGateway nodes + //if not a gateway check only for a GatewayBeaconMsg if (check_gateway(src_addr, len, buf)) return; } else { - //Executed by Gateway nodes - if ((radio_->id() == 0x1ccd) && (src_addr == 0x42f)) { - debug_->debug("case1"); - return; - } + //if a gateway check the message for readings to report + + //check for the air quality sensor if (check_air_quality(src_addr, len, buf)) { debug_->debug("check_air_quality"); return; } + //check for a CollectorMsg check_collector(src_addr, len, buf); } } + /** + * Checks the incoming payload for a Command message. + * If the Payload is a Command message, swithces the led according to the message + * @param src_addr the source of the message + * @param len the length of the payload + * @param buf the contents of the payload + * @return true if it was the Command message + */ bool check_led(node_id_t src_addr, Os::TxRadio::size_t len, block_data_t * buf) { if (buf[0] == 0x7f && buf[1] == 0x69 && buf[2] == 0x70 && buf[3] == 0x1) { if (buf[4] == 0x1) { @@ -356,6 +406,14 @@ public isense::Uint32DataHandler { return false; } + /** + * Checks the incoming payload for a GatewayBeaconMsg. + * If the Payload is a GatewayBeaconMsg, replaces the old gateway with the new one + * @param src_addr the source of the message + * @param len the length of the payload + * @param buf the contents of the payload + * @return true if it was the GatewayBeaconMsg + */ bool check_gateway(node_id_t src_addr, Os::TxRadio::size_t len, block_data_t * buf) { if ((len == 10) && (buf[0] == 0)) { bool sGmsg = true; @@ -371,6 +429,14 @@ public isense::Uint32DataHandler { return false; } + /** + * Checks the incoming payload for an AirQualityMsg. + * If the Payload is a AirQualityMsg, and reports it to the backend + * @param src_addr the source of the message + * @param len the length of the payload + * @param buf the contents of the payload + * @return true if it was the AirQualityMsg + */ bool check_air_quality(node_id_t src_addr, Os::TxRadio::size_t len, block_data_t * buf) { if ((src_addr == 0x2c41) && (buf[0] == 0x43) && (0x9979 == radio_->id())) { uint8 mess[len]; @@ -389,6 +455,14 @@ public isense::Uint32DataHandler { return false; } + /** + * Checks the incoming payload for a CollectorMsg. + * If the Payload is a CollectorMsg, and reports it to the backend + * @param src_addr the source of the message + * @param len the length of the payload + * @param buf the contents of the payload + * @return true if it was the CollectorMsg + */ void check_collector(node_id_t src_addr, Os::TxRadio::size_t len, block_data_t * buf) { collectorMsg_t * mess = (collectorMsg_t *) buf; @@ -405,7 +479,6 @@ public isense::Uint32DataHandler { } } - private: void send_reading(node_id_t destination, const char * capability, int value) { @@ -480,10 +553,16 @@ public isense::Uint32DataHandler { nb_t nb_; bool pir_sensor_; Os::AppMainParameter* ospointer; +#ifdef ENVIRONMENTAL_COLLECTOR isense::EnvironmentModule* em_; - // isense::LisAccelerometer* accelerometer_; +#endif +#ifdef SECURITY_COLLECTOR isense::PirSensor* pir_; + // isense::LisAccelerometer* accelerometer_; +#endif +#ifdef WEATHER_COLLECTOR isense::Ms55xx* ms_; +#endif isense::CoreModule* cm_; Os::TxRadio::self_pointer_t radio_; @@ -494,7 +573,7 @@ public isense::Uint32DataHandler { }; -wiselib::WiselibApplication application; +wiselib::WiselibApplication application; // -------------------------------------------------------------------------- void application_main(Os::AppMainParameter& value) { diff --git a/iSense/isense_test/Makefile b/iSense/isense_test/Makefile index 9fe16aa..0fb3fa2 100644 --- a/iSense/isense_test/Makefile +++ b/iSense/isense_test/Makefile @@ -15,4 +15,4 @@ all: isense export APP_SRC=sensor_test.cpp export BIN_OUT=sensor_test -include ../Makefile +include ../Makefiles/Makefile diff --git a/iSense/isense_test/collector_message.h b/iSense/isense_test/collector_message.h deleted file mode 100644 index 0dd963c..0000000 --- a/iSense/isense_test/collector_message.h +++ /dev/null @@ -1,246 +0,0 @@ -/* - * File: collector_msg.h - * Author: Amaxilatis - */ - -#ifndef COLLECTOR_MSG_H -#define COLLECTOR_MSG_H - -namespace wiselib { - - template - < typename OsModel_P, typename Radio_P> - class CollectorMsg { - public: - typedef OsModel_P OsModel; - typedef Radio_P Radio; - - typedef typename Radio::node_id_t node_id_t; - typedef typename Radio::size_t size_t; - typedef typename Radio::block_data_t block_data_t; - typedef typename Radio::message_id_t message_id_t; - // message ids - - enum { - COLLECTOR_MSG_TYPE = 102, - TEMPERATURE = 0, - LIGHT = 1, - INFRARED = 2, - HUMIDITY = 3, - CO = 4, - CO2 = 5, - CH4 = 6, - PIR = 7, - CHARGE = 8, - ACCELEROMETER = 9, - LINK_UP = 10, - BPRESSURE = 11, - LINK_DOWN = 12, - CHAIR = 13, - ROOMLIGHTS = 14, - TEMPERATURE_ARDUINO = 16, - - TTEST = 99, - DESCRIPTION = 100 - }; - - enum { - SITTING = 1, - NOSITTING = 0, - ZONE_1 = 0x1, - ZONE_2 = 0x2, - ZONE_3 = 0x3, - ZONE_4 = 0x4 - }; - - enum data_positions { - MSG_ID_POS = 0, // message id position inside the message [uint8] - COLLECTOR_ID_POS = 1, - PAYLOAD_POS = 2 - }; - - // -------------------------------------------------------------------- - - CollectorMsg() { - set_msg_id(COLLECTOR_MSG_TYPE); - }; - // -------------------------------------------------------------------- - - ~CollectorMsg() { - }; - - // get the message id - - inline message_id_t msg_id() { - return buffer[MSG_ID_POS]; - - }; - // -------------------------------------------------------------------- - - // set the message id - - inline void set_msg_id(message_id_t id) { - write (buffer + MSG_ID_POS, id); - }; - - // get the collector id - - inline message_id_t collector_type_id() { - return buffer[COLLECTOR_ID_POS]; - }; - // -------------------------------------------------------------------- - - // set the collector id - - inline void set_collector_type_id(message_id_t id) { - write (buffer + COLLECTOR_ID_POS, id); - }; - - inline uint8_t observed_sensors() { - return buffer[COLLECTOR_ID_POS + 1]; - }; - - inline uint8_t * payload() { - return buffer + PAYLOAD_POS; - }; - - inline int16 get_int16() { - return read (buffer + PAYLOAD_POS); - }; - - inline uint16 get_uint16() { - return read (buffer + PAYLOAD_POS); - }; - - inline uint32 get_uint32() { - return read (buffer + PAYLOAD_POS); - }; - - inline node_id_t link_from() { - return read (buffer + PAYLOAD_POS); - }; - - inline node_id_t link_to() { - return read (buffer + PAYLOAD_POS + sizeof (node_id_t)); - }; - - inline uint8_t buffer_size() { - return PAYLOAD_POS + payload_size(); - }; - - inline uint8_t get_uint8() { - return buffer[PAYLOAD_POS]; - } - - //actually the 1st byte but need the 4th to fix endianness - - inline uint8_t get_zone() { - return buffer[PAYLOAD_POS + 3]; - } - - //actually the 2nd byte but need the 3rd to fix endianness - - inline uint8_t get_status() { - return buffer[PAYLOAD_POS + 2]; - } - - uint8_t payload_size() { - - if (buffer[COLLECTOR_ID_POS] == TEMPERATURE) { - return sizeof (int16); - } else if (buffer[COLLECTOR_ID_POS] == LIGHT) { - return sizeof (uint32); - } else if (buffer[COLLECTOR_ID_POS] == INFRARED) { - return sizeof (uint32); - } else if (buffer[COLLECTOR_ID_POS] == HUMIDITY) { - return sizeof (uint16); - } else if (buffer[COLLECTOR_ID_POS] == CO) { - return sizeof (uint32); - } else if (buffer[COLLECTOR_ID_POS] == CO2) { - return sizeof (uint32); - } else if (buffer[COLLECTOR_ID_POS] == CH4) { - return sizeof (uint32); - } else if (buffer[COLLECTOR_ID_POS] == PIR) { - return sizeof (uint8_t); - } else if (buffer[COLLECTOR_ID_POS] == CHARGE) { - return sizeof (uint32); - } else if (buffer[COLLECTOR_ID_POS] == ACCELEROMETER) { - return sizeof (uint32); - } else if (buffer[COLLECTOR_ID_POS] == LINK_UP) { - return 2 * sizeof (node_id_t); - } else if (buffer[COLLECTOR_ID_POS] == LINK_DOWN) { - return 2 * sizeof (node_id_t); - } else if (buffer[COLLECTOR_ID_POS] == BPRESSURE) { - return sizeof (uint16); - } else { - return 0; - } - - }; - - void set_humidity(uint16 * buf) { - memcpy(buffer + PAYLOAD_POS, buf, sizeof (uint16)); - } - - void set_temperature(int16 *buf) { - memcpy(buffer + PAYLOAD_POS, buf, sizeof (int16)); - }; - - void set_bpressure(uint16 *buf) { - memcpy(buffer + PAYLOAD_POS, buf, sizeof (uint16)); - }; - - void set_light(uint32 *buf) { - memcpy(buffer + PAYLOAD_POS, buf, sizeof (uint32)); - }; - - void set_infrared(uint32 *buf) { - memcpy(buffer + PAYLOAD_POS, buf, sizeof (uint32)); - }; - - void set_charge(uint32 *buf) { - memcpy(buffer + PAYLOAD_POS, buf, sizeof (uint32)); - }; - - void set_link(node_id_t from, node_id_t to) { - write (buffer + PAYLOAD_POS, from); - write (buffer + PAYLOAD_POS + sizeof (node_id_t), to); - }; - - void set_pir_event(uint8_t *buf) { - memcpy(buffer + PAYLOAD_POS, buf, sizeof (uint8_t)); - } - - private: - block_data_t buffer[Radio::MAX_MESSAGE_LENGTH]; // buffer for the message data - }; - - template - < typename OsModel_P, typename Radio_P> - class BroadcastMsg { - public: - typedef typename Radio_P::size_t size_t; - typedef typename OsModel_P::block_data_t block_data_t; - // -------------------------------------------------------------------- - - BroadcastMsg() { - for (int i = 0; i < 10; i++) { - buffer[i] = i; - } - } - - size_t length() { - return 10; - } - - private: - block_data_t buffer[10]; // buffer for the message data - - }; - -} - -#endif /* ECHOMSG_H */ - - - diff --git a/iSense/isense_test/sensor_test.cpp b/iSense/isense_test/sensor_test.cpp index 94403e8..26f4033 100644 --- a/iSense/isense_test/sensor_test.cpp +++ b/iSense/isense_test/sensor_test.cpp @@ -3,36 +3,29 @@ #include "util/pstl/map_static_vector.h" #include "util/pstl/static_string.h" -//ISENSE SENSORS +//used to blink the led #include -#include -#include -#include -#include - typedef wiselib::OSMODEL Os; -//MESSAGE_TYPES -#include "./collector_message.h" +//messages used to report a reading and receive the GatewayBeacons +#include "../../messages/collector_message_new.h" typedef wiselib::CollectorMsg collectorMsg_t; -typedef wiselib::BroadcastMsg broadcastMsg_t; +#include "../../messages/gateway_beacon_message.h" +typedef wiselib::GatewayBeaconMsg broadcastMsg_t; + //TYPEDEFS typedef Os::TxRadio::node_id_t node_id_t; typedef Os::TxRadio::block_data_t block_data_t; //EVENT IDS -#define TASK_SLEEP 1 -#define TASK_WAKE 2 #define TASK_READ_SENSORS 2 -#define TASK_SET_LIGHT_THRESHOLD 3 -#define TASK_BROADCAST_GATEWAY 4 -#define TASK_TEST 5 + #define REPORTING_INTERVAL 60 -class Application { +class iSenseTestApp { public: //-------------------------------------------------------------- @@ -75,12 +68,12 @@ class Application { - radio_->reg_recv_callback (this); + radio_->reg_recv_callback (this); radio_->set_channel(12); - timer_->set_timer (10000, this, (void*) TASK_READ_SENSORS); + timer_->set_timer (10000, this, (void*) TASK_READ_SENSORS); } // -------------------------------------------------------------------- @@ -93,10 +86,8 @@ class Application { // Get the Temperature and Luminance from sensors and debug them if ((long) userdata == TASK_READ_SENSORS) { - timer_->set_timer (REPORTING_INTERVAL * 1000, this, (void*) TASK_READ_SENSORS); - collectorMsg_t mess; - mess.set_collector_type_id(collectorMsg_t::TTEST); - radio_->send(mygateway_, mess.buffer_size(), (uint8*) & mess); + timer_->set_timer (REPORTING_INTERVAL * 1000, this, (void*) TASK_READ_SENSORS); + send_reading(0xffff, "test", 1); } } @@ -157,7 +148,18 @@ class Application { debug_->debug("%s", buffer); } - + void send_reading(node_id_t destination, const char * capability, int value) { + collectorMsg_t mess; + mess.set_source(radio_->id()); + mess.set_target(destination); + char temp_string[30]; + sprintf(temp_string, "%s", capability); + mess.set_capability(temp_string); + sprintf(temp_string, "%d", value); + mess.set_value(temp_string); + debug_->debug("Contains bidi %s -> %s ", mess.capability(), mess.value()); + radio_->send(mygateway_, mess.length(), (uint8*) & mess); + } node_id_t mygateway_; bool led; @@ -172,7 +174,7 @@ class Application { }; -wiselib::WiselibApplication application; +wiselib::WiselibApplication application; // -------------------------------------------------------------------------- void application_main(Os::AppMainParameter& value) { diff --git a/messages/collector_message.h b/messages/collector_message.h deleted file mode 100644 index 0dd963c..0000000 --- a/messages/collector_message.h +++ /dev/null @@ -1,246 +0,0 @@ -/* - * File: collector_msg.h - * Author: Amaxilatis - */ - -#ifndef COLLECTOR_MSG_H -#define COLLECTOR_MSG_H - -namespace wiselib { - - template - < typename OsModel_P, typename Radio_P> - class CollectorMsg { - public: - typedef OsModel_P OsModel; - typedef Radio_P Radio; - - typedef typename Radio::node_id_t node_id_t; - typedef typename Radio::size_t size_t; - typedef typename Radio::block_data_t block_data_t; - typedef typename Radio::message_id_t message_id_t; - // message ids - - enum { - COLLECTOR_MSG_TYPE = 102, - TEMPERATURE = 0, - LIGHT = 1, - INFRARED = 2, - HUMIDITY = 3, - CO = 4, - CO2 = 5, - CH4 = 6, - PIR = 7, - CHARGE = 8, - ACCELEROMETER = 9, - LINK_UP = 10, - BPRESSURE = 11, - LINK_DOWN = 12, - CHAIR = 13, - ROOMLIGHTS = 14, - TEMPERATURE_ARDUINO = 16, - - TTEST = 99, - DESCRIPTION = 100 - }; - - enum { - SITTING = 1, - NOSITTING = 0, - ZONE_1 = 0x1, - ZONE_2 = 0x2, - ZONE_3 = 0x3, - ZONE_4 = 0x4 - }; - - enum data_positions { - MSG_ID_POS = 0, // message id position inside the message [uint8] - COLLECTOR_ID_POS = 1, - PAYLOAD_POS = 2 - }; - - // -------------------------------------------------------------------- - - CollectorMsg() { - set_msg_id(COLLECTOR_MSG_TYPE); - }; - // -------------------------------------------------------------------- - - ~CollectorMsg() { - }; - - // get the message id - - inline message_id_t msg_id() { - return buffer[MSG_ID_POS]; - - }; - // -------------------------------------------------------------------- - - // set the message id - - inline void set_msg_id(message_id_t id) { - write (buffer + MSG_ID_POS, id); - }; - - // get the collector id - - inline message_id_t collector_type_id() { - return buffer[COLLECTOR_ID_POS]; - }; - // -------------------------------------------------------------------- - - // set the collector id - - inline void set_collector_type_id(message_id_t id) { - write (buffer + COLLECTOR_ID_POS, id); - }; - - inline uint8_t observed_sensors() { - return buffer[COLLECTOR_ID_POS + 1]; - }; - - inline uint8_t * payload() { - return buffer + PAYLOAD_POS; - }; - - inline int16 get_int16() { - return read (buffer + PAYLOAD_POS); - }; - - inline uint16 get_uint16() { - return read (buffer + PAYLOAD_POS); - }; - - inline uint32 get_uint32() { - return read (buffer + PAYLOAD_POS); - }; - - inline node_id_t link_from() { - return read (buffer + PAYLOAD_POS); - }; - - inline node_id_t link_to() { - return read (buffer + PAYLOAD_POS + sizeof (node_id_t)); - }; - - inline uint8_t buffer_size() { - return PAYLOAD_POS + payload_size(); - }; - - inline uint8_t get_uint8() { - return buffer[PAYLOAD_POS]; - } - - //actually the 1st byte but need the 4th to fix endianness - - inline uint8_t get_zone() { - return buffer[PAYLOAD_POS + 3]; - } - - //actually the 2nd byte but need the 3rd to fix endianness - - inline uint8_t get_status() { - return buffer[PAYLOAD_POS + 2]; - } - - uint8_t payload_size() { - - if (buffer[COLLECTOR_ID_POS] == TEMPERATURE) { - return sizeof (int16); - } else if (buffer[COLLECTOR_ID_POS] == LIGHT) { - return sizeof (uint32); - } else if (buffer[COLLECTOR_ID_POS] == INFRARED) { - return sizeof (uint32); - } else if (buffer[COLLECTOR_ID_POS] == HUMIDITY) { - return sizeof (uint16); - } else if (buffer[COLLECTOR_ID_POS] == CO) { - return sizeof (uint32); - } else if (buffer[COLLECTOR_ID_POS] == CO2) { - return sizeof (uint32); - } else if (buffer[COLLECTOR_ID_POS] == CH4) { - return sizeof (uint32); - } else if (buffer[COLLECTOR_ID_POS] == PIR) { - return sizeof (uint8_t); - } else if (buffer[COLLECTOR_ID_POS] == CHARGE) { - return sizeof (uint32); - } else if (buffer[COLLECTOR_ID_POS] == ACCELEROMETER) { - return sizeof (uint32); - } else if (buffer[COLLECTOR_ID_POS] == LINK_UP) { - return 2 * sizeof (node_id_t); - } else if (buffer[COLLECTOR_ID_POS] == LINK_DOWN) { - return 2 * sizeof (node_id_t); - } else if (buffer[COLLECTOR_ID_POS] == BPRESSURE) { - return sizeof (uint16); - } else { - return 0; - } - - }; - - void set_humidity(uint16 * buf) { - memcpy(buffer + PAYLOAD_POS, buf, sizeof (uint16)); - } - - void set_temperature(int16 *buf) { - memcpy(buffer + PAYLOAD_POS, buf, sizeof (int16)); - }; - - void set_bpressure(uint16 *buf) { - memcpy(buffer + PAYLOAD_POS, buf, sizeof (uint16)); - }; - - void set_light(uint32 *buf) { - memcpy(buffer + PAYLOAD_POS, buf, sizeof (uint32)); - }; - - void set_infrared(uint32 *buf) { - memcpy(buffer + PAYLOAD_POS, buf, sizeof (uint32)); - }; - - void set_charge(uint32 *buf) { - memcpy(buffer + PAYLOAD_POS, buf, sizeof (uint32)); - }; - - void set_link(node_id_t from, node_id_t to) { - write (buffer + PAYLOAD_POS, from); - write (buffer + PAYLOAD_POS + sizeof (node_id_t), to); - }; - - void set_pir_event(uint8_t *buf) { - memcpy(buffer + PAYLOAD_POS, buf, sizeof (uint8_t)); - } - - private: - block_data_t buffer[Radio::MAX_MESSAGE_LENGTH]; // buffer for the message data - }; - - template - < typename OsModel_P, typename Radio_P> - class BroadcastMsg { - public: - typedef typename Radio_P::size_t size_t; - typedef typename OsModel_P::block_data_t block_data_t; - // -------------------------------------------------------------------- - - BroadcastMsg() { - for (int i = 0; i < 10; i++) { - buffer[i] = i; - } - } - - size_t length() { - return 10; - } - - private: - block_data_t buffer[10]; // buffer for the message data - - }; - -} - -#endif /* ECHOMSG_H */ - - - diff --git a/messages/collector_message_new.h b/messages/collector_message_new.h index fc158c8..80fae88 100644 --- a/messages/collector_message_new.h +++ b/messages/collector_message_new.h @@ -1,51 +1,85 @@ /* - * File: collector_msg.h - * Author: Amaxilatis + * File: collector_message_new.h + * Author: amaxilat */ #ifndef COLLECTOR_MSG_NEW_H #define COLLECTOR_MSG_NEW_H +/** + * The Wiselib is an algorithms library for networked embedded devices. + * It contains various algorithm classes (for instance, localization or routing) + * that can be compiled for several platforms such as iSense or Contiki, + * or the sensor network simulator Shawn. It is completely written in C++, + * and uses templates in the same way as Boost and CGAL. This makes it possible + * to write generic and platform independent code that is very efficiently + * compiled for the various platforms. + */ namespace wiselib { - template - < typename OsModel_P, typename Radio_P> - class CollectorMsg { + /** + * A Wiselib Message class for using reporting new Readings to the backend + * Contains a MessageID, the sender node id , the 2nd node id for link readings, + * the capability (as a string) and the value of the reading (as a string) + */ + template < typename OsModel_P, typename Radio_P> class CollectorMsg { public: + /** + * The type of the Wiselib Os + */ typedef OsModel_P OsModel; + /** + * The type of the Wiselib Radio + */ typedef Radio_P Radio; - + /** + * The type of the Wiselib node ids + */ typedef typename Radio::node_id_t node_id_t; + /** + * The type of the Wiselib size + */ typedef typename Radio::size_t size_t; + /** + * The type of the Wiselib block of data + */ typedef typename Radio::block_data_t block_data_t; + /** + * The type of the Wiselib message ids + */ typedef typename Radio::message_id_t message_id_t; // message ids + /** + * contains the Wiselib + * + * Unique Message ID for Collector messages + */ enum { COLLECTOR_MSG_TYPE = 103, }; - enum data_positions { - MSG_ID_POS = 3, // message id position inside the message [uint8] - CAPABILITY_LEN_POS = 4, - VALUE_LEN_POS = 5, - SOURCE_NODE = 6, - TARGET_NODE = 8, - CAPABILITY_STR_POS = 10 - }; - // -------------------------------------------------------------------- + /** + * Default constructor + * Initializes the + * mkSense + * prefix and the message id, source and target address + */ CollectorMsg() { - buffer[0]=0x7f; - buffer[1]=0x69; - buffer[2]=0x70; + buffer[0] = 0x7f; + buffer[1] = 0x69; + buffer[2] = 0x70; set_msg_id(COLLECTOR_MSG_TYPE); set_source(0xffff); set_target(0xffff); }; // -------------------------------------------------------------------- + /** + * Destructor + */ ~CollectorMsg() { }; @@ -68,16 +102,16 @@ namespace wiselib { // -------------------------------------------------------------------- /** - * Get the capability reported. - * @return a char array containing the capability name. + * Get the sender node id. + * @return the node id as a node_id_t. */ inline node_id_t source() { return read (buffer + SOURCE_NODE); }; /** - * Sets the capabity of the message. - * @param capability_ the capability as a char * + * Sets the sender id to the given id. + * @param source_ the id of the source node */ inline void set_source(node_id_t source_) { write (buffer + SOURCE_NODE, source_); @@ -86,16 +120,16 @@ namespace wiselib { // -------------------------------------------------------------------- /** - * Get the capability reported. - * @return a char array containing the capability name. + * Get the target node id. + * @return the node id as a node_id_t. */ inline node_id_t target() { return read (buffer + TARGET_NODE); }; /** - * Sets the capabity of the message. - * @param capability_ the capability as a char * + * Sets the target id to the given id. + * @param target_ the id of the target node */ inline void set_target(node_id_t target_) { write (buffer + TARGET_NODE, target_); @@ -150,6 +184,15 @@ namespace wiselib { private: + enum data_positions { + MSG_ID_POS = 3, // message id position inside the message [uint8] + CAPABILITY_LEN_POS = 4, + VALUE_LEN_POS = 5, + SOURCE_NODE = 6, + TARGET_NODE = 8, + CAPABILITY_STR_POS = 10 + }; + /** * Length of the contained capability. * @return the length as unit8_t. @@ -168,30 +211,6 @@ namespace wiselib { block_data_t buffer[Radio::MAX_MESSAGE_LENGTH]; // buffer for the message data }; - - template - - class BroadcastMsg { - public: - typedef typename Radio_P::size_t size_t; - typedef typename OsModel_P::block_data_t block_data_t; - // -------------------------------------------------------------------- - - BroadcastMsg() { - for (int i = 0; i < 10; i++) { - buffer[i] = i; - } - } - - size_t length() { - return 10; - } - - private: - block_data_t buffer[10]; // buffer for the message data - - }; - } #endif /* COLLECTOR_MSG_NEW_H */ diff --git a/messages/gateway_beacon_message.h b/messages/gateway_beacon_message.h new file mode 100644 index 0000000..251c8de --- /dev/null +++ b/messages/gateway_beacon_message.h @@ -0,0 +1,62 @@ +/* + * File: gateway_beacon_message.h + * Author: amaxilat + */ + +#ifndef GATEWAY_BEACON_MESSAGE_H +#define GATEWAY_BEACON_MESSAGE_H + +/** + * The Wiselib is an algorithms library for networked embedded devices. + * It contains various algorithm classes (for instance, localization or routing) + * that can be compiled for several platforms such as iSense or Contiki, + * or the sensor network simulator Shawn. It is completely written in C++, + * and uses templates in the same way as Boost and CGAL. This makes it possible + * to write generic and platform independent code that is very efficiently + * compiled for the various platforms. + */ +namespace wiselib { + + /** + * A Wiselib Message class for using declaring the existence of a Gateway + */ + template class GatewayBeaconMsg { + public: + /** + * The type of the Wiselib size + */ + typedef typename Radio_P::size_t size_t; + /** + * The type of the Wiselib block of data + */ + typedef typename OsModel_P::block_data_t block_data_t; + // -------------------------------------------------------------------- + + /** + * Constructor that sets the contents of the message to the beacon contents + */ + GatewayBeaconMsg() { + for (int i = 0; i < 10; i++) { + buffer[i] = i; + } + } + + /** + * Gives the length of the message to send. + * @return the length of the message buffer. + */ + size_t length() { + return 10; + } + + private: + block_data_t buffer[10]; // buffer for the message data + + }; + +} + +#endif /* GATEWAY_BEACON_MESSAGE_H */ + + +