📄 aodv.cc
字号:
/* * Player - One Hell of a Robot Server * Copyright (C) 2000 * Brian Gerkey, Kasper Stoy, Richard Vaughan, & Andrew Howard * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *//* Desc: Driver for getting signal strengths for AODV ah-hoc network software. * Author: Andrew Howard ahoward@usc.edu * Date: 26 Nov 2002 * $Id: aodv.cc,v 1.1 2002/11/29 17:08:27 gerkey Exp $ */#include <errno.h>#include <stdio.h>#include <string.h>#include <netinet/in.h>#include <device.h>#include <configfile.h>#include <playertime.h>#include <drivertable.h>#include <player.h>extern PlayerTime *GlobalTime;#define AODV_INFO_FILE "/proc/aodv/route_table"class Aodv : public CDevice{ public: Aodv(char *interface, ConfigFile *cf, int section); // Initialize driver public: virtual int Setup(); // Finalize driver public: virtual int Shutdown(); // Get the current readings public: virtual size_t GetData(void*,unsigned char *, size_t maxsize, uint32_t *timestamp_sec, uint32_t *timestamp_usec); // File handle for the /proc file system entry protected: FILE *file;};// Instantiate driver for given interfaceCDevice * Aodv_Init(char *interface, ConfigFile *cf, int section){ if(strcmp(interface, PLAYER_WIFI_STRING)) { PLAYER_ERROR1("driver \"linuxwifi\" does not support interface \"%s\"\n", interface); return NULL; } else { return ((CDevice*)(new Aodv(interface, cf, section))); }}// Register driver typevoid Aodv_Register(DriverTable *table){ table->AddDriver("aodv", PLAYER_READ_MODE, Aodv_Init); return;}// ConstructorAodv::Aodv(char *interface, ConfigFile *cf, int section) : CDevice(0, 0, 0, 1){ return;}// Initialize driverint Aodv::Setup(){ // Just open the file this->file = fopen(AODV_INFO_FILE, "r"); if (this->file == NULL) { PLAYER_ERROR2("unable to open [%s]; error [%s]", AODV_INFO_FILE, strerror(errno)); return -1; } return 0;}// Finalize driverint Aodv::Shutdown(){ fclose(this->file); return 0;}// Get new datasize_t Aodv::GetData(void* client,unsigned char *dest, size_t maxsize, uint32_t *timestamp_sec, uint32_t *timestamp_usec){ int n, link_count; player_wifi_link_t *link; player_wifi_data_t data; char ip[16], next_ip[16]; int seq, hop; int qual, level, noise; struct timeval curr; // Rewind to start of file rewind(this->file); // Skip header for (n = 0; n < 5;) if (fgetc(this->file) == '\n') n++; link_count = 0; while (TRUE) { n = fscanf(this->file, " %16s %d %d %16s ( %d ) ", ip, &seq, &hop, next_ip, &level); if (n == EOF) break; if (n < 5) continue; qual = 0; noise = 0; printf("aodv %s : %d\n", ip, level); link = data.links + link_count++; strncpy(link->ip, ip, sizeof(link->ip)); link->link = htons(qual); link->level = htons(level); link->noise = htons(noise); } data.link_count = htons(link_count); // Copy data to the server's buffer assert(sizeof(data) < maxsize); memcpy(dest, &data, sizeof(data)); // Set the data timestamp GlobalTime->GetTime(&curr); *timestamp_sec = curr.tv_sec; *timestamp_usec = curr.tv_usec; return (sizeof(data));}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -