📄 autorf.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: autorf.c * Written: Robert Havlik and Brianna Bethel * date: 05/09/04 *///This program preforms statistics and analysis of //collected radio data in file form#include <stdio.h>#include <stdlib.h>#include <string.h>#include <time.h>#include <inttypes.h>#include "config.h"#include "msched.h"#include "led.h"#include "uart.h"#include "com.h"#include "serial.h"#define UART1 1#define UART0 0void tests(void);void ApplySettings(int, int, int, int, int, int, int);void base_receive(int, char FileName[24]);void Distance_Test(void);void Frequency_Test(void);void getStats(void);void Packet_Size_Test(void);void packet_to_string(comBuf *packet, char *thestring);void start(void){#ifdef PLATFORM_LINUX mos_thread_new(tests, 10240, PRIORITY_NORMAL);#endif} #ifdef PLATFORM_LINUXvoid tests(){ char FileName[24]; char datain[16]; char environment[16]; char string1[16]; char string2[16]; char string3[16]; int j=0, k=0, i=0; int numsamples; int referenceStart=33; int frequency; int choice; int power; int powerrecv; char tmpstrng[64]; char *pointer2 = tmpstrng; size_t eye; struct tm tim; time_t now; comBuf *packet; comBuf to_print; printf("\n\n"); printf("Welcome to the MANTIS AutoRF Radio Test Suite\n"); printf("\n"); printf("1) Distance Performance Analysis\n"); printf("2) Frequency Performance\n"); //The following functions are still in development /* printf("3) Frequency Interference\n"); printf("4) Packet Size Test\n"); printf("5) RSSI Test\n\n"); */ printf("Enter number of test to run:\n"); packet = com_recv(IFACE_TERMINAL); if(packet != NULL) { packet_to_string(packet, pointer2); choice = atoi(tmpstrng); com_free_buf(packet); } if(choice==1) { Distance_Test(); tests(); } else if(choice==2) { Frequency_Test(); tests(); } else if(choice==4) { Packet_Size_Test(); tests(); } else return;}void packet_to_string(comBuf *packet, char *thestring){ int counter =0; int packetsize; packetsize= packet->size; packet->size =0; while(counter<packetsize) { thestring[counter]= packet->data[packet->size++]; counter = counter +1; } thestring[counter]= '\0';}void Distance_Test(){ float distances[100]={1}; float temp=1; float adistance; double difference; int j=0, k=0; char datain[16]; char environment[16]; int numsamples; int referenceStart=33; int frequency; int choice=1; int power; int powerrecv; char presskey; size_t eye; struct tm tim; time_t now; int c; int testtmp; char tmpstrng[64]; comBuf *packet; char numstrng[12]; int i=0; int distind =0; char *pointer = tmpstrng; printf("Enter distances to test in meters (separated by spaces and end with a zero):\n"); packet = com_recv(IFACE_TERMINAL); packet_to_string(packet, pointer); while(testtmp != 48) //48 is zero in ascii { testtmp= tmpstrng[i]; while(testtmp != 32) { numstrng[k]=testtmp; k = k+1; i = i+1; testtmp = tmpstrng[i]; } k=0; i = i+1; adistance= atoi(numstrng); distances[distind] = adistance; distind = distind+1; testtmp = tmpstrng[i]; } com_free_buf(packet); printf("Enter type of environment:\n"); packet= com_recv(IFACE_TERMINAL); if(packet != NULL) { packet_to_string(packet, environment); com_free_buf(packet); } printf("Enter Number of samples at each distance:\n"); packet= com_recv(IFACE_TERMINAL); if(packet != NULL) { packet_to_string(packet, pointer); numsamples=atoi(tmpstrng); com_free_buf(packet); } printf("Enter Fixed frequency for testing (index 1-30, type 0 for list):\n"); packet= com_recv(IFACE_TERMINAL); if(packet != NULL) { packet_to_string(packet, pointer); frequency = atoi(tmpstrng); com_free_buf(packet); } printf("Enter Desired Power Setting (0-255) for SENDER:\n"); packet= com_recv(IFACE_TERMINAL); if(packet != NULL) { packet_to_string(packet, pointer); power = atoi(tmpstrng); com_free_buf(packet); } printf("Enter Desired Power Setting (0-255) for RECEIVER:\n"); packet= com_recv(IFACE_TERMINAL); if(packet != NULL) { packet_to_string(packet, pointer); powerrecv = atoi(tmpstrng); com_free_buf(packet); } //TODO: An accept for these options ApplySettings(numsamples,frequency,power, powerrecv, choice, 0, 0); while(distances[k]>0 && k<100) { char DistancePath[75]="../../../../../src/apps/AutoRF/1/"; char FileName[24]= {0}; now = time(NULL); tim = *(localtime(&now)); eye = strftime(FileName, 24, "%m%d%y%H%M%S",&tim); strcat(FileName, ".txt"); FILE *masterfile; masterfile = fopen("../../../../../src/apps/AutoRF/1/Master1","a"); fprintf(masterfile, "%s\n", FileName); fclose(masterfile); strcat(DistancePath, FileName); FILE *current; current = fopen(DistancePath, "w"); fprintf(current, "%s\n", environment); fprintf(current, "%f\n", distances[k]); fprintf(current, "%d\n", numsamples); fprintf(current, "%d\n", frequency); //TODO: implement a look up table to get real value in Hertz index corresponds to fprintf(current, "%d\n", power); fprintf(current, "%d\n", powerrecv); fclose(current); printf("Place units %f meters appart, press any number to continue (type something)\n\n", distances[k]); int temp = 0; while(temp == 0) { packet= com_recv(IFACE_TERMINAL); if(packet != NULL) { packet_to_string(packet, pointer); temp = atoi(tmpstrng); com_free_buf(packet); } } com_free_buf(packet); printf("Be sure the receiving unit is connected to the serial port,\n"); printf("then turn on the receiving unit first and then the sending unit.\n"); base_receive(numsamples, DistancePath); k=k+1; } printf("You have completed Distance Analysis\n"); return;}void Frequency_Test(){ char FrequencyPath[75]="../../../../../src/apps/AutoRF/2/"; char environment[16]; char FileName[24]; int numsamples; int referenceStart=33; int frequency; int choice=2; int power; int powerrecv; float distance; int k=0; size_t eye; struct tm tim; time_t now; int c; comBuf *packet; char tmpstrng[64]; char *pointer = tmpstrng; printf("Enter the Distance Between the Nodes:\n"); packet= com_recv(IFACE_TERMINAL); if(packet != NULL) { packet_to_string(packet, pointer); distance = atoi(tmpstrng); com_free_buf(packet); } printf("Enter type of environment:\n"); packet= com_recv(IFACE_TERMINAL); if(packet != NULL) { packet_to_string(packet, environment); com_free_buf(packet); } printf("Enter Number of samples to take at each frequency:\n"); packet= com_recv(IFACE_TERMINAL); if(packet != NULL) { packet_to_string(packet, pointer); numsamples = atoi(tmpstrng); com_free_buf(packet); } printf("Enter Desired Power Setting (0-255) for SENDER:\n"); packet= com_recv(IFACE_TERMINAL); if(packet != NULL) { packet_to_string(packet, pointer); power = atoi(tmpstrng); com_free_buf(packet); } printf("Enter Desired Power Setting (0-255) for RECEIVER:\n"); packet= com_recv(IFACE_TERMINAL); if(packet != NULL) { packet_to_string(packet, pointer); powerrecv = atoi(tmpstrng); com_free_buf(packet); } //TODO: an accept for these options ApplySettings(numsamples,frequency,power, powerrecv, choice, 0, 0); now = time(NULL); tim = *(localtime(&now)); eye = strftime(FileName, 24, "%m%d%y%H%M%S",&tim); strcat(FileName, ".txt"); FILE *masterfile; masterfile = fopen("../../../../../src/apps/AutoRF/2/Master2","a"); fprintf(masterfile, "%s\n", FileName); fclose(masterfile); strcat(FrequencyPath, FileName); FILE *current; current = fopen(FrequencyPath, "w"); frequency = 0; //put frequency to be zero in the header part=varrying fprintf(current, "%s\n", environment); fprintf(current, "%f\n", distance); fprintf(current, "%d\n", numsamples); fprintf(current, "%d\n", frequency); fprintf(current, "%d\n", power); fprintf(current, "%d\n", powerrecv); fclose(current); printf("The settings are now applied. In another shell, make the send and recv\n"); printf("programs by typing make && mos_shell generator.srec and make && mos_shell receiver.srec \n\n"); printf("Be sure the receiving unit is connected to the serial port,\n"); printf(" then turn on the receiving unit first and then the sending unit.\n"); base_receive(numsamples,FrequencyPath); return;}void Packet_Size_Test(void){ char DistancePath[75]="../../../../../src/apps/AutoRF/4/"; float distances[100]={0}; float temp=1; double difference; int j=0, k=0; char FileName[24]; char datain[16]; char environment[16]; int numsamples; int referenceStart=33; int frequency; int choice=1; int power; int powerrecv; char presskey; size_t eye; struct tm tim; time_t now; int c; int startpkt=8; int endpkt=16; int testtmp=1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -