📄 moteio.cc
字号:
//// MOTEio.cc : MOTENic Support for Diffusion// Authors : Fabio Silva//// Copyright (C) 2000-2002 by the University of Southern California// $Id: MOTEio.cc,v 1.9 2002/06/27 22:04:30 fabio Exp $//// This program is free software; you can redistribute it and/or// modify it under the terms of the GNU General Public License,// version 2, as published by the Free Software Foundation.//// 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.////#include <stdio.h>#include <stdlib.h>#include "MOTEio.hh"MOTEIO::MOTEIO() : DiffusionIO(){ int fd; if ((fd = open(MOTE_NIC_DEVICE_FILE, O_RDWR)) < 0){ DiffPrint(DEBUG_ALWAYS, "Cannot open the Mote-Nic device !\n"); exit(-1); } in_fds_.push_back(fd); out_fds_.push_back(fd); max_in_descriptor_ = fd;}#define MAX_PKT (1 << 14)DiffPacket MOTEIO::recvPacket(int fd){ int tmp[MAX_PKT]; DiffPacket incoming_packet = NULL; int packet_size; int int_psize;/* if ((read(fd, &header[0], sizeof(struct hdr_diff) | RPC_MSG_PEEK)) < 0) { perror("MOTEIO::RecvPacket"); exit(-1); } packet_size = sizeof(struct hdr_diff) + ntohs(DATA_LEN(HDR_DIFF(&header[0]))); incoming_packet = new int [(packet_size / sizeof(int)) + 1]; if (incoming_packet == NULL){ DiffPrint(DEBUG_ALWAYS, "Cannot allocate memory for incoming packet !\n"); exit(-1); } if ((read(fd, incoming_packet, packet_size)) < 0) { perror("MOTEIO::RecvPacket2"); printf("%d\n", fd); exit(-1); }*/ packet_size=read(fd, tmp, sizeof(tmp)); if (packet_size < 0){ perror("MOTEIO::RecvPacket"); exit(-1); } int_psize = (packet_size / sizeof(int)) + 1; incoming_packet = new int [int_psize]; if (incoming_packet == NULL){ fprintf(stderr, "Cannot allocate memory for incoming packet\n"); exit(-1); } memmove(incoming_packet, tmp, packet_size); return incoming_packet;}void MOTEIO::sendPacket(DiffPacket pkt, int len, int dst){ list<int>::iterator itr; for (itr = out_fds_.begin(); itr != out_fds_.end(); ++itr){ if ((write(*itr, pkt, len)) < 0){ DiffPrint(DEBUG_ALWAYS, "MOTEIO::SendPacket"); exit(-1); } else{ DiffPrint(DEBUG_ALWAYS, "Sent something\n"); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -