N-sim
Emulation and simulation of
Wireless Sensor Networks



   Home


   Project Page


   Download


   CVS



   Installation


   Configuration


   Plug-ins




 Hosted by
SourceForge.net Logo

/home/brennan/n-sim/Vaike/linux/system-addons/networking/sensor_self.c

Go to the documentation of this file.
00001 
00014 /*
00015  * Copyright 2007. Los Alamos National Security, LLC. This material
00016  * was produced under U.S. Government contract DE-AC52-06NA25396 for
00017  * Los Alamos National Laboratory (LANL), which is operated by Los
00018  * Alamos National Security, LLC, for the Department of Energy. The
00019  * U.S. Government has rights to use, reproduce, and distribute this
00020  * software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY,
00021  * LLC, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LEGAL
00022  * LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified to
00023  * produce derivative works, such modified software should be clearly
00024  * marked, so as not to confuse it with the version available from LANL.
00025  *
00026  * Additionally, this program is free software; you can redistribute
00027  * it and/or modify it under the terms of the GNU General Public
00028  * License as published by the Free Software Foundation; version 2 of
00029  * the License. Accordingly, this program is distributed in the hope
00030  * it will be useful, but WITHOUT ANY WARRANTY; without even the
00031  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00032  * PURPOSE. See the GNU General Public License for more details.
00033  */
00034 
00035 #include <stdio.h>
00036 #include <string.h>
00037 #include <unistd.h>
00038 #include <syslog.h>
00039 
00040 #include "sensor_self.h"
00041 #include "mesh_link.h"
00042 
00043 
00044 
00045 double get_discharge_rate(self_t *self)
00046 {
00047   double rate = -1.0;
00048   char buf[self->battery.buf_size], *string;
00049   FILE *bat = fopen(self->battery.file, "r");
00050 
00051   while (fgets(buf, self->battery.buf_size, bat) != NULL) {
00052     if ((string = strstr(buf, self->battery.parse_string)) != NULL) {
00053       if (sscanf(string, "%lf", &rate) > 0)
00054         break;
00055     }
00056   }
00057   return rate;
00058 }
00059 
00060 
00061 void init_self(self_t *self)
00062 {
00063   self->interface = NULL;  /* must be supplied */
00064   memset(self->mac_addr, 0x00, MAC_ADDR_LEN); /* derived from name */
00065 
00066   memset(self->ip_addr, 0, NET_ADDR_LEN);
00067   strncpy(self->broadcast, "255.255.255.255", NET_ADDR_LEN);
00068   strncpy(self->netmask, "255.255.255.0", NET_ADDR_LEN);
00069 
00070   self->battery_enabled = 0;
00071   strcpy(self->battery.file, "/proc/acpi/battery/BAT0/state");
00072   self->battery.buf_size = 1024;
00073   strcpy(self->battery.parse_string, "present rate: ");
00074 
00075   self->latitude = self->longitude = self->altitude = 0.0;
00076 
00077   self->neighbors.root = NULL;
00078   self->n_iter = NULL;
00079 
00080   self->isa_gateway = 0;
00081   self->shutdown = 0;
00082 }
00083 
00084 
00085 size_t max_ctl_size(self_t *self)
00086 {
00087   size_t max = 0;
00088   protocol_t *p_iter = self->protocols;
00089   analysis_t *a_iter = self->analyses;
00090 
00091   while (p_iter != NULL) {
00092     if (p_iter->ctl_size > max)
00093       max = p_iter->ctl_size;
00094     p_iter = p_iter->next;
00095   }
00096   while (a_iter != NULL) {
00097     if (a_iter->ctl_size > max)
00098       max = a_iter->ctl_size;
00099     a_iter = a_iter->next;
00100   }
00101   return max;
00102 }


© 2007, Los Alamos National Security, LLC.