Exemple #1
0
    /**
     * 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 for the air quality sensor
    if (check_air_quality(src_addr, len, buf)) {
	debug_->debug("check_air_quality");
        return;
    }



#ifdef CORE_COLLECTOR
        //check if an actuation command
        if (check_led(src_addr, len, buf)) return;
#endif


        if (!is_gateway()) {
            //if not a gateway check only for a GatewayBeaconMsg
            if (check_gateway(src_addr, len, buf)) return;
        } else {
            //if a gateway check the message for readings to report
            //check for a CollectorMsg
            check_collector(src_addr, len, buf);
        }
    }
Exemple #2
0
    /**
     * 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<iSenseCollectorApp, &iSenseCollectorApp::read_environmental_sensors > (REPORTING_INTERVAL * 1000, this, (void*) 0);
        }
        if (!is_gateway()) {
            int16 temp = em_->temp_sensor()->temperature();
            if (temp < 100) {
                send_reading(0xffff, "temperature", temp);
            }
            uint32 lux = em_->light_sensor()->luminance();
            if (lux < 20000) {
                send_reading(0xffff, "light", lux);
            }
        } else {
            int16 temp = em_->temp_sensor()->temperature();
            if (temp < 100) {
                debug_->debug("node::%x temperature %d ", radio_->id(), temp);

            }
            uint32 lux = em_->light_sensor()->luminance();
            if (lux < 20000) {
                debug_->debug("node::%x light %d ", radio_->id(), lux);
            }
        }
    }
Exemple #3
0
 /**
  * Handles a new Pir Event
  * Reports the Reading to the Gateway
  */
 virtual void handle_sensor() {
     //        debug_->debug("pir event");
     if (!is_gateway()) {
         send_reading(0xffff, "pir", 1);
     } else {
         debug_->debug("node::%x pir 1 ", radio_->id());
     }
 }
Exemple #4
0
    /**
     * 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) {
            if (!is_gateway()) {
                send_reading(from, "status", 1);

                send_reading(from, "lqi", nb_.get_lqi(from));
            } else {
                debug_->debug("node::%x,%x status %d ", radio_->id(), from, 1);

            }
        } else if ((event == nb_t::LOST_NB_BIDI) || (event == nb_t::DROPPED_NB)) {
            if (!is_gateway()) {
                send_reading(from, "status", 0);
            } else {
                debug_->debug("node::%x,%x status %d ", radio_->id(), from, 0);
            }
        }
    }
Exemple #5
0
    /**
     * 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<iSenseCollectorApp, &iSenseCollectorApp::read_weather_sensors > (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);
        }
    }
Exemple #6
0
enum nss_status _nss_myhostname_gethostbyname4_r(
                const char *name,
                struct gaih_addrtuple **pat,
                char *buffer, size_t buflen,
                int *errnop, int *h_errnop,
                int32_t *ttlp) {

        struct gaih_addrtuple *r_tuple, *r_tuple_prev = NULL;
        _cleanup_free_ struct local_address *addresses = NULL;
        _cleanup_free_ char *hn = NULL;
        const char *canonical = NULL;
        int n_addresses = 0, lo_ifi;
        uint32_t local_address_ipv4;
        struct local_address *a;
        size_t l, idx, ms;
        char *r_name;
        unsigned n;

        assert(name);
        assert(pat);
        assert(buffer);
        assert(errnop);
        assert(h_errnop);

        if (is_localhost(name)) {
                /* We respond to 'localhost', so that /etc/hosts
                 * is optional */

                canonical = "localhost";
                local_address_ipv4 = htonl(INADDR_LOOPBACK);

        } else if (is_gateway(name)) {

                n_addresses = local_gateways(NULL, 0, AF_UNSPEC, &addresses);
                if (n_addresses <= 0) {
                        *errnop = ENOENT;
                        *h_errnop = HOST_NOT_FOUND;
                        return NSS_STATUS_NOTFOUND;
                }

                canonical = "gateway";

        } else {
                hn = gethostname_malloc();
                if (!hn) {
                        *errnop = ENOMEM;
                        *h_errnop = NO_RECOVERY;
                        return NSS_STATUS_TRYAGAIN;
                }

                /* We respond to our local host name, our our hostname suffixed with a single dot. */
                if (!streq(name, hn) && !streq_ptr(startswith(name, hn), ".")) {
                        *errnop = ENOENT;
                        *h_errnop = HOST_NOT_FOUND;
                        return NSS_STATUS_NOTFOUND;
                }

                n_addresses = local_addresses(NULL, 0, AF_UNSPEC, &addresses);
                if (n_addresses < 0)
                        n_addresses = 0;

                canonical = hn;
                local_address_ipv4 = LOCALADDRESS_IPV4;
        }

        /* If this call fails we fill in 0 as scope. Which is fine */
        lo_ifi = n_addresses <= 0 ? if_nametoindex(LOOPBACK_INTERFACE) : 0;

        l = strlen(canonical);
        ms = ALIGN(l+1) + ALIGN(sizeof(struct gaih_addrtuple)) * (n_addresses > 0 ? n_addresses : 2);
        if (buflen < ms) {
                *errnop = ENOMEM;
                *h_errnop = NO_RECOVERY;
                return NSS_STATUS_TRYAGAIN;
        }

        /* First, fill in hostname */
        r_name = buffer;
        memcpy(r_name, canonical, l+1);
        idx = ALIGN(l+1);

        if (n_addresses <= 0) {
                /* Second, fill in IPv6 tuple */
                r_tuple = (struct gaih_addrtuple*) (buffer + idx);
                r_tuple->next = r_tuple_prev;
                r_tuple->name = r_name;
                r_tuple->family = AF_INET6;
                memcpy(r_tuple->addr, LOCALADDRESS_IPV6, 16);
                r_tuple->scopeid = (uint32_t) lo_ifi;

                idx += ALIGN(sizeof(struct gaih_addrtuple));
                r_tuple_prev = r_tuple;

                /* Third, fill in IPv4 tuple */
                r_tuple = (struct gaih_addrtuple*) (buffer + idx);
                r_tuple->next = r_tuple_prev;
                r_tuple->name = r_name;
                r_tuple->family = AF_INET;
                *(uint32_t*) r_tuple->addr = local_address_ipv4;
                r_tuple->scopeid = (uint32_t) lo_ifi;

                idx += ALIGN(sizeof(struct gaih_addrtuple));
                r_tuple_prev = r_tuple;
        }

        /* Fourth, fill actual addresses in, but in backwards order */
        for (a = addresses + n_addresses - 1, n = 0; (int) n < n_addresses; n++, a--) {
                r_tuple = (struct gaih_addrtuple*) (buffer + idx);
                r_tuple->next = r_tuple_prev;
                r_tuple->name = r_name;
                r_tuple->family = a->family;
                r_tuple->scopeid = a->ifindex;
                memcpy(r_tuple->addr, &a->address, 16);

                idx += ALIGN(sizeof(struct gaih_addrtuple));
                r_tuple_prev = r_tuple;
        }

        /* Verify the size matches */
        assert(idx == ms);

        /* Nscd expects us to store the first record in **pat. */
        if (*pat)
                **pat = *r_tuple_prev;
        else
                *pat = r_tuple_prev;

        if (ttlp)
                *ttlp = 0;

        /* Explicitly reset all error variables */
        *errnop = 0;
        *h_errnop = NETDB_SUCCESS;
        h_errno = 0;

        return NSS_STATUS_SUCCESS;
}
Exemple #7
0
enum nss_status _nss_myhostname_gethostbyname3_r(
                const char *name,
                int af,
                struct hostent *host,
                char *buffer, size_t buflen,
                int *errnop, int *h_errnop,
                int32_t *ttlp,
                char **canonp) {

        _cleanup_free_ struct local_address *addresses = NULL;
        const char *canonical, *additional = NULL;
        _cleanup_free_ char *hn = NULL;
        uint32_t local_address_ipv4 = 0;
        int n_addresses = 0;

        assert(name);
        assert(host);
        assert(buffer);
        assert(errnop);
        assert(h_errnop);

        if (af == AF_UNSPEC)
                af = AF_INET;

        if (af != AF_INET && af != AF_INET6) {
                *errnop = EAFNOSUPPORT;
                *h_errnop = NO_DATA;
                return NSS_STATUS_UNAVAIL;
        }

        if (is_localhost(name)) {
                canonical = "localhost";
                local_address_ipv4 = htonl(INADDR_LOOPBACK);

        } else if (is_gateway(name)) {

                n_addresses = local_gateways(NULL, 0, af, &addresses);
                if (n_addresses <= 0) {
                        *errnop = ENOENT;
                        *h_errnop = HOST_NOT_FOUND;
                        return NSS_STATUS_NOTFOUND;
                }

                canonical = "gateway";

        } else {
                hn = gethostname_malloc();
                if (!hn) {
                        *errnop = ENOMEM;
                        *h_errnop = NO_RECOVERY;
                        return NSS_STATUS_TRYAGAIN;
                }

                if (!streq(name, hn) && !streq_ptr(startswith(name, hn), ".")) {
                        *errnop = ENOENT;
                        *h_errnop = HOST_NOT_FOUND;
                        return NSS_STATUS_NOTFOUND;
                }

                n_addresses = local_addresses(NULL, 0, af, &addresses);
                if (n_addresses < 0)
                        n_addresses = 0;

                canonical = hn;
                additional = n_addresses <= 0 && af == AF_INET6 ? "localhost" : NULL;
                local_address_ipv4 = LOCALADDRESS_IPV4;
        }

        return fill_in_hostent(
                        canonical, additional,
                        af,
                        addresses, n_addresses,
                        local_address_ipv4,
                        host,
                        buffer, buflen,
                        errnop, h_errnop,
                        ttlp,
                        canonp);
}
Exemple #8
0
    /**
     * Initializes the application and the enabled sensor modules.
     * @param value pointer to os
     */
    void init(Os::AppMainParameter& value) {

        ospointer = &value;
        radio_ = &wiselib::FacetProvider<Os, Os::TxRadio>::get_facet(value);
        timer_ = &wiselib::FacetProvider<Os, Os::Timer>::get_facet(value);
        debug_ = &wiselib::FacetProvider<Os, Os::Debug>::get_facet(value);
        debug_->debug("*Boot*");
        uart_ = &wiselib::FacetProvider<Os, Os::Uart>::get_facet(value);
        clock_ = &wiselib::FacetProvider<Os, Os::Clock>::get_facet(value);
#ifdef CORE_COLLECTOR
        cm_ = new isense::CoreModule(value);
#endif
        mygateway_ = 0xffff;

#ifdef WEATHER_COLLECTOR
        init_weather_module(value);
#endif
#ifdef SOLAR_COLLECTOR
        init_solar_module(value);
#endif
#ifdef ENVIRONMENTAL_COLLECTOR
        init_environmental_module(value);
#endif
#ifdef SECURITY_COLLECTOR
        init_security_module(value);
#endif

        radio_->reg_recv_callback<iSenseCollectorApp, &iSenseCollectorApp::receive > (this);
        radio_->set_channel(12);

        uart_->reg_read_callback<iSenseCollectorApp, &iSenseCollectorApp::handle_uart_msg > (this);
        uart_->enable_serial_comm();

#ifdef ND_COLLECTOR
        nb_.init(*radio_, *clock_, *timer_, *debug_, 2000, 16000, 250, 255);
        nb_.enable();
        nb_. reg_event_callback<iSenseCollectorApp, &iSenseCollectorApp::ND_callback > ((uint8) 2, nb_t::NEW_NB | nb_t::NEW_NB_BIDI | nb_t::LOST_NB_BIDI | nb_t::DROPPED_NB, this);
#endif 

#ifdef WEATHER_COLLECTOR
        timer_->set_timer<iSenseCollectorApp, &iSenseCollectorApp::read_weather_sensors > (10000, this, (void*) 0);
#endif
#ifdef SOLAR_COLLECTOR
        debug_->debug("set timer");
        ((isense::Os *) ospointer)->allow_sleep(false);

        ((isense::Os *) ospointer)->allow_doze(false);

        timer_->set_timer<iSenseCollectorApp, &iSenseCollectorApp::read_solar_sensors > (5000, this, (void*) TASK_WAKE);
#else        
#ifdef ENVIRONMENTAL_COLLECTOR
        timer_->set_timer<iSenseCollectorApp, &iSenseCollectorApp::read_environmental_sensors > (10000, this, (void*) 0);
#endif
#endif

#ifdef CORE_COLLECTOR
        send_reading(0xffff, "led", 0);
        cm_->led_off();
#endif
        if (is_gateway()) {
            // register task to be called in a minute for periodic sensor readings
            timer_->set_timer<iSenseCollectorApp, &iSenseCollectorApp::broadcast_gateway > (1000, this, (void*) 0);
            //            timer_->set_timer<Application, &Application::execute > (5000, this, (void*) TASK_TEST);
        }
    }