2010-10-12 13:37:41 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2010, Swedish Institute of Computer Science.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. 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.
|
|
|
|
* 3. Neither the name of the Institute 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 INSTITUTE 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 THE INSTITUTE OR 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.
|
|
|
|
*
|
|
|
|
* This file is part of the Contiki operating system.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
* Collect view client code
|
|
|
|
* \author
|
|
|
|
* Adam Dunkels <adam@sics.se>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "contiki.h"
|
|
|
|
#include "net/rime/collect-neighbor.h"
|
2013-12-12 20:50:07 +01:00
|
|
|
#include "net/rime/rime.h"
|
2010-10-12 13:37:41 +02:00
|
|
|
#include "net/rime/timesynch.h"
|
|
|
|
#include "collect-view.h"
|
|
|
|
|
2010-10-24 23:03:52 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
2010-10-12 13:37:41 +02:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-10-19 09:33:47 +02:00
|
|
|
void
|
2010-10-20 17:21:43 +02:00
|
|
|
collect_view_construct_message(struct collect_view_data_msg *msg,
|
2013-12-12 23:58:52 +01:00
|
|
|
const linkaddr_t *parent,
|
2010-10-20 17:21:43 +02:00
|
|
|
uint16_t parent_etx,
|
2010-10-24 23:03:52 +02:00
|
|
|
uint16_t current_rtmetric,
|
2010-10-20 17:21:43 +02:00
|
|
|
uint16_t num_neighbors,
|
|
|
|
uint16_t beacon_interval)
|
2010-10-12 13:37:41 +02:00
|
|
|
{
|
|
|
|
static unsigned long last_cpu, last_lpm, last_transmit, last_listen;
|
|
|
|
unsigned long cpu, lpm, transmit, listen;
|
2010-10-20 17:21:43 +02:00
|
|
|
|
2010-10-12 13:37:41 +02:00
|
|
|
|
2010-10-19 09:33:47 +02:00
|
|
|
msg->len = sizeof(struct collect_view_data_msg) / sizeof(uint16_t);
|
|
|
|
msg->clock = clock_time();
|
2010-10-12 13:37:41 +02:00
|
|
|
#if TIMESYNCH_CONF_ENABLED
|
2010-10-19 09:33:47 +02:00
|
|
|
msg->timesynch_time = timesynch_time();
|
2010-10-12 13:37:41 +02:00
|
|
|
#else /* TIMESYNCH_CONF_ENABLED */
|
2010-10-19 09:33:47 +02:00
|
|
|
msg->timesynch_time = 0;
|
2010-10-12 13:37:41 +02:00
|
|
|
#endif /* TIMESYNCH_CONF_ENABLED */
|
2010-10-19 09:33:47 +02:00
|
|
|
|
2010-10-12 13:37:41 +02:00
|
|
|
energest_flush();
|
2010-10-19 09:33:47 +02:00
|
|
|
|
2010-10-12 13:37:41 +02:00
|
|
|
cpu = energest_type_time(ENERGEST_TYPE_CPU) - last_cpu;
|
|
|
|
lpm = energest_type_time(ENERGEST_TYPE_LPM) - last_lpm;
|
|
|
|
transmit = energest_type_time(ENERGEST_TYPE_TRANSMIT) - last_transmit;
|
|
|
|
listen = energest_type_time(ENERGEST_TYPE_LISTEN) - last_listen;
|
|
|
|
|
|
|
|
/* Make sure that the values are within 16 bits. If they are larger,
|
|
|
|
we scale them down to fit into 16 bits. */
|
|
|
|
while(cpu >= 65536ul || lpm >= 65536ul ||
|
|
|
|
transmit >= 65536ul || listen >= 65536ul) {
|
|
|
|
cpu /= 2;
|
|
|
|
lpm /= 2;
|
|
|
|
transmit /= 2;
|
|
|
|
listen /= 2;
|
|
|
|
}
|
2010-10-19 09:33:47 +02:00
|
|
|
|
|
|
|
msg->cpu = cpu;
|
|
|
|
msg->lpm = lpm;
|
|
|
|
msg->transmit = transmit;
|
|
|
|
msg->listen = listen;
|
2010-10-12 13:37:41 +02:00
|
|
|
|
|
|
|
last_cpu = energest_type_time(ENERGEST_TYPE_CPU);
|
|
|
|
last_lpm = energest_type_time(ENERGEST_TYPE_LPM);
|
|
|
|
last_transmit = energest_type_time(ENERGEST_TYPE_TRANSMIT);
|
|
|
|
last_listen = energest_type_time(ENERGEST_TYPE_LISTEN);
|
|
|
|
|
2013-12-12 23:58:52 +01:00
|
|
|
memcpy(&msg->parent, &parent->u8[LINKADDR_SIZE - 2], 2);
|
2010-10-20 17:21:43 +02:00
|
|
|
msg->parent_etx = parent_etx;
|
2010-10-24 23:03:52 +02:00
|
|
|
msg->current_rtmetric = current_rtmetric;
|
2010-10-20 17:21:43 +02:00
|
|
|
msg->num_neighbors = num_neighbors;
|
|
|
|
msg->beacon_interval = beacon_interval;
|
2010-10-12 13:37:41 +02:00
|
|
|
|
2010-10-19 09:33:47 +02:00
|
|
|
memset(msg->sensors, 0, sizeof(msg->sensors));
|
|
|
|
collect_view_arch_read_sensors(msg);
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|