⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 receiver.c

📁 MANTIS是由科罗拉多大学开发的传感器网络嵌入式操作系统。 这是mantis的0.9.5版本的源码。
💻 C
字号:
/*  This file is part of MANTIS OS, Operating System for Nymph.  See http://mantis.cs.colorado.edu/  Copyright (C) 2003 University of Colorado, Boulder  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  (See http://www.gnu.org/copyleft/gpl.html)  along with this program; if not, write to the Free Software  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,  USA, or send email to mantis-users@cs.colorado.edu.*//** * File:     receiver.c       * Author:   Charles Gruenwald III - gruenwal@colorado.edu * Date:     12-14-2003 * * Description: receiver will sit in a tight while loop looking for * values received over the radio. Any value it receives it will then * show on the leds and send over the serial line using the uart. It is * to be used with compatable hardware (nymph/mica2). *  */#include "mos.h"#include "led.h"#include "msched.h"#include "printf.h"#include "com.h"#include "command_daemon.h"void receiver();static comBuf temp;void start(void){   mos_thread_new(mos_command_daemon, 196, PRIORITY_NORMAL);   mos_thread_new(receiver, 128, PRIORITY_NORMAL);}void receiver(){   comBuf *recv_pkt;   comBuf *old_buf = &temp;   uint8_t total_pkts = 0;   uint8_t num_pkts_dropped = 0;   bool init = true;      //   printf("Radio tester initialized....\n");   com_mode(IFACE_RADIO,IF_LISTEN);      while(1) {           mos_led_toggle(1);      recv_pkt = com_recv(IFACE_RADIO);           //printf("\nreceived packet %d", recv_pkt->data[0]/recv_pkt->size +1);      //printf(" of size %d", recv_pkt->size);           if(init == true) {	 total_pkts = 0;	 num_pkts_dropped = 0;	 old_buf->data[recv_pkt->size-1] = 255;      }      if(recv_pkt->data[0] != (old_buf->data[recv_pkt->size - 1] + 1) % 256) {	 num_pkts_dropped += 	    (((recv_pkt->data[0]+255) -	      old_buf->data[recv_pkt->size - 1]) % 255) / recv_pkt->size;	 //	printf("dropped packet %d", recv_pkt->data[0]-1);      }      total_pkts++;      if (total_pkts + num_pkts_dropped >= 50 && init == false) {	 printf ("\n%d total packets sent", total_pkts + num_pkts_dropped,		 recv_pkt->size);	 printf ("\n%d packets dropped ",num_pkts_dropped);    	 return;      }           //total_pkts++;          init = false;      com_free_buf (old_buf);      old_buf = recv_pkt;   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -