-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetSettings.cpp
138 lines (126 loc) · 3.62 KB
/
getSettings.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include <fstream>
#include <iostream>
#include <cstdio>
#include <time.h>
#include <ctime>
#include "top.h"
int MAX_LINE=1024;
int numSamples=4;
float minFreq=50;
float maxFreq=100;
int numSteps=2;
float sweepDelay=0;
float gain=1;
int loadSavedSettings(char *fileName, Control& settings);
int readFromAddress(int new_s, char addrloc, int *iVal, double *dVal, int *type, Control& settings){
//we'll be simulating reading from the zynq with reading from a txt file. If we are using xml for settings data, we'll need to add code to handle it but it will be much more convient for accessing data.
char reply[MAX_LINE];
char controlFilename[] = "Control_Settings.txt";
sprintf( reply, "%c", 'f');
send( new_s, reply, strlen(reply), 0);
// loadSavedSettings("Control_Settings.txt", settings);
loadSavedSettings(controlFilename, settings);
char *sendf= new char[MAX_LINE];
switch(addrloc)
{
case 'a': //nsweep
*iVal = settings.nSweep;
printf("Sweep number is %d \n", *iVal);
sprintf( sendf, "%c%d", 'b', *iVal);
*type = 1;
break;
case 'b': //nstep
*iVal = settings.nStep;
printf("Step Number is %d \n", *iVal);
sprintf( sendf, "%c%d", 'b',*iVal);
*type = 2;
numSteps=*iVal;
break;
case 'c': //nSample
*iVal = settings.nSample;
printf("Sample Number %d \n", *iVal);
sprintf( sendf, "%c%d", 'b',*iVal);
*type = 3;
numSamples=*iVal;
break;
case 'd': //dsweeep
*dVal = settings.dSweep;
printf("Sweep Delay is %f \n", *dVal);
sprintf( sendf, "%c%f", 'b',*dVal);
*type = 4;
sweepDelay=*dVal;
break;
case 'e': //minF
*dVal = settings.minF;
printf("Min Frequency is %f \n", *dVal);
sprintf( sendf, "%c%f", 'b',*dVal);
minFreq=*dVal;
*type = 5;
break;
case 'f': //maxF
*dVal = settings.maxF;
printf("Max Frequency is %f \n", *dVal);
sprintf( sendf, "%c%f", 'b',*dVal);
maxFreq=*dVal;
*type = 6;
break;
case 'g': //gain
*dVal = settings.maxF;
printf("Gain is %f \n", *dVal);
sprintf( sendf, "%c%f", 'b',*dVal);
gain=*dVal;
*type = 6;
break;
default:
fprintf(stderr, "%s \n", "Not a valid address");
sprintf( sendf, "%c%s", 'e', "Not a valid address");
send( new_s, sendf,strlen( sendf), 0);
return 0;
}
//Server code to send back response? or do something else?
send( new_s, sendf, strlen( sendf), 0);
sprintf( sendf, "%c", 'f');
send( new_s, sendf, strlen( sendf), 0);
return 1;
}
int loadSavedSettings(char *fileName, Control& settings){
int buf_size = 128;
char pset1[128]; char pset4[128];
char pset2[128]; char pset5[128];
char pset3[128]; char pset6[128];
char pset7[128];
fprintf(stderr, "opening %s \n", fileName);
std::ifstream ifile (fileName, std::ifstream::in );
ifile.getline(pset1, 128);
ifile.getline(pset2, 128);
ifile.getline(pset3, 128);
ifile.getline(pset4, 128);
ifile.getline(pset5, 128);
ifile.getline(pset6, 128);
ifile.getline(pset7, 128);
ifile.close();
settings.C_sweep = pset1;
settings.C_step = pset2;
settings.C_sample = pset3;
settings.C_delay = pset4;
settings.C_min = pset5;
settings.C_max = pset6;
settings.C_gain = pset7;
settings.nSweep = atoi(pset1);
settings.nStep = atoi(pset2);
settings.nSample = atoi(pset3);
settings.dSweep = atof(pset4);
settings.minF = atof(pset5);
settings.maxF = atof(pset6);
settings.gain = atof(pset7);
}